aboutsummaryrefslogtreecommitdiff
path: root/sim/ppc/hw_pic.c
blob: 3203f8c687b81d22a6474a5738c23280e77d4d1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* ICU device: icu@<address>

   <address> : read - processor nr
   <address> : write - interrupt processor nr
   <address> + 4 : read - nr processors

   Single byte registers that control a simple ICU.

   Illustrates passing of events to parent device. Passing of
   interrupts to an interrupt destination. */


static unsigned
icu_io_read_buffer_callback(device *me,
			    void *dest,
			    int space,
			    unsigned_word addr,
			    unsigned nr_bytes,
			    cpu *processor,
			    unsigned_word cia)
{
  memset(dest, 0, nr_bytes);
  switch (addr & 4) {
  case 0:
    *(unsigned_1*)dest = cpu_nr(processor);
    break;
  case 4:
    *(unsigned_1*)dest =
      device_find_integer_property(me, "/openprom/options/smp");
    break;
  }
  return nr_bytes;
}


static unsigned
icu_io_write_buffer_callback(device *me,
			     const void *source,
			     int space,
			     unsigned_word addr,
			     unsigned nr_bytes,
			     cpu *processor,
			     unsigned_word cia)
{
  unsigned_1 val = H2T_1(*(unsigned_1*)source);
  /* tell the parent device that the interrupt lines have changed.
     For this fake ICU.  The interrupt lines just indicate the cpu to
     interrupt next */
  device_interrupt_event(me,
			 val, /*my_port*/
			 val, /*val*/
			 processor, cia);
  return nr_bytes;
}

static void
icu_do_interrupt(event_queue *queue,
		 void *data)
{
  cpu *target = (cpu*)data;
  /* try to interrupt the processor.  If the attempt fails, try again
     on the next tick */
  if (!external_interrupt(target))
    event_queue_schedule(queue, 1, icu_do_interrupt, target);
}


static void
icu_interrupt_event_callback(device *me,
			     int my_port,
			     device *source,
			     int source_port,
			     int level,
			     cpu *processor,
			     unsigned_word cia)
{
  /* the interrupt controller can't interrupt a cpu at any time.
     Rather it must synchronize with the system clock before
     performing an interrupt on the given processor */
  psim *system = cpu_system(processor);
  cpu *target = psim_cpu(system, my_port);
  if (target != NULL) {
    event_queue *events = cpu_event_queue(target);
    event_queue_schedule(events, 1, icu_do_interrupt, target);
  }
}

static device_callbacks const icu_callbacks = {
  { generic_device_init_address, },
  { NULL, }, /* address */
  { icu_io_read_buffer_callback,
    icu_io_write_buffer_callback, },
  { NULL, }, /* DMA */
  { icu_interrupt_event_callback, },
  { NULL, }, /* unit */
};