]>
Commit | Line | Data |
---|---|---|
f7c70325 PB |
1 | /* |
2 | * Cortex-A9MPCore internal peripheral emulation. | |
3 | * | |
4 | * Copyright (c) 2009 CodeSourcery. | |
b12080cd PM |
5 | * Copyright (c) 2011 Linaro Limited. |
6 | * Written by Paul Brook, Peter Maydell. | |
f7c70325 | 7 | * |
8e31bf38 | 8 | * This code is licensed under the GPL. |
f7c70325 PB |
9 | */ |
10 | ||
83c9f4ca | 11 | #include "hw/sysbus.h" |
9b5f952b | 12 | #include "hw/intc/arm_gic.h" |
b12080cd | 13 | |
5126fec7 AF |
14 | #define TYPE_A9MPCORE_PRIV "a9mpcore_priv" |
15 | #define A9MPCORE_PRIV(obj) \ | |
16 | OBJECT_CHECK(A9MPPrivState, (obj), TYPE_A9MPCORE_PRIV) | |
17 | ||
845769fc | 18 | typedef struct A9MPPrivState { |
5126fec7 AF |
19 | /*< private >*/ |
20 | SysBusDevice parent_obj; | |
21 | /*< public >*/ | |
22 | ||
b12080cd | 23 | uint32_t num_cpu; |
b12080cd PM |
24 | MemoryRegion container; |
25 | DeviceState *mptimer; | |
cde4577f | 26 | DeviceState *wdt; |
353575f0 | 27 | DeviceState *scu; |
a32134aa | 28 | uint32_t num_irq; |
9b5f952b AF |
29 | |
30 | GICState gic; | |
845769fc | 31 | } A9MPPrivState; |
b12080cd | 32 | |
ddd76165 PM |
33 | static void a9mp_priv_set_irq(void *opaque, int irq, int level) |
34 | { | |
845769fc | 35 | A9MPPrivState *s = (A9MPPrivState *)opaque; |
9b5f952b AF |
36 | |
37 | qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level); | |
ddd76165 PM |
38 | } |
39 | ||
753bc6e9 AF |
40 | static void a9mp_priv_initfn(Object *obj) |
41 | { | |
42 | A9MPPrivState *s = A9MPCORE_PRIV(obj); | |
43 | ||
44 | memory_region_init(&s->container, obj, "a9mp-priv-container", 0x2000); | |
45 | sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->container); | |
9b5f952b AF |
46 | |
47 | object_initialize(&s->gic, sizeof(s->gic), TYPE_ARM_GIC); | |
48 | qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default()); | |
753bc6e9 AF |
49 | } |
50 | ||
b12080cd PM |
51 | static int a9mp_priv_init(SysBusDevice *dev) |
52 | { | |
5126fec7 | 53 | A9MPPrivState *s = A9MPCORE_PRIV(dev); |
9b5f952b | 54 | DeviceState *gicdev; |
353575f0 | 55 | SysBusDevice *timerbusdev, *wdtbusdev, *gicbusdev, *scubusdev; |
b12080cd PM |
56 | int i; |
57 | ||
9b5f952b AF |
58 | gicdev = DEVICE(&s->gic); |
59 | qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu); | |
60 | qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq); | |
61 | qdev_init_nofail(gicdev); | |
62 | gicbusdev = SYS_BUS_DEVICE(&s->gic); | |
ddd76165 PM |
63 | |
64 | /* Pass through outbound IRQ lines from the GIC */ | |
65 | sysbus_pass_irq(dev, gicbusdev); | |
66 | ||
67 | /* Pass through inbound GPIO lines to the GIC */ | |
5126fec7 | 68 | qdev_init_gpio_in(DEVICE(dev), a9mp_priv_set_irq, s->num_irq - 32); |
b12080cd | 69 | |
353575f0 PC |
70 | s->scu = qdev_create(NULL, "a9-scu"); |
71 | qdev_prop_set_uint32(s->scu, "num-cpu", s->num_cpu); | |
72 | qdev_init_nofail(s->scu); | |
73 | scubusdev = SYS_BUS_DEVICE(s->scu); | |
74 | ||
b12080cd PM |
75 | s->mptimer = qdev_create(NULL, "arm_mptimer"); |
76 | qdev_prop_set_uint32(s->mptimer, "num-cpu", s->num_cpu); | |
77 | qdev_init_nofail(s->mptimer); | |
cde4577f PC |
78 | timerbusdev = SYS_BUS_DEVICE(s->mptimer); |
79 | ||
80 | s->wdt = qdev_create(NULL, "arm_mptimer"); | |
81 | qdev_prop_set_uint32(s->wdt, "num-cpu", s->num_cpu); | |
82 | qdev_init_nofail(s->wdt); | |
83 | wdtbusdev = SYS_BUS_DEVICE(s->wdt); | |
b12080cd PM |
84 | |
85 | /* Memory map (addresses are offsets from PERIPHBASE): | |
86 | * 0x0000-0x00ff -- Snoop Control Unit | |
87 | * 0x0100-0x01ff -- GIC CPU interface | |
88 | * 0x0200-0x02ff -- Global Timer | |
89 | * 0x0300-0x05ff -- nothing | |
90 | * 0x0600-0x06ff -- private timers and watchdogs | |
91 | * 0x0700-0x0fff -- nothing | |
92 | * 0x1000-0x1fff -- GIC Distributor | |
93 | * | |
94 | * We should implement the global timer but don't currently do so. | |
95 | */ | |
353575f0 PC |
96 | memory_region_add_subregion(&s->container, 0, |
97 | sysbus_mmio_get_region(scubusdev, 0)); | |
b12080cd | 98 | /* GIC CPU interface */ |
ddd76165 PM |
99 | memory_region_add_subregion(&s->container, 0x100, |
100 | sysbus_mmio_get_region(gicbusdev, 1)); | |
b12080cd PM |
101 | /* Note that the A9 exposes only the "timer/watchdog for this core" |
102 | * memory region, not the "timer/watchdog for core X" ones 11MPcore has. | |
103 | */ | |
104 | memory_region_add_subregion(&s->container, 0x600, | |
cde4577f | 105 | sysbus_mmio_get_region(timerbusdev, 0)); |
b12080cd | 106 | memory_region_add_subregion(&s->container, 0x620, |
cde4577f | 107 | sysbus_mmio_get_region(wdtbusdev, 0)); |
ddd76165 PM |
108 | memory_region_add_subregion(&s->container, 0x1000, |
109 | sysbus_mmio_get_region(gicbusdev, 0)); | |
b12080cd | 110 | |
ddd76165 PM |
111 | /* Wire up the interrupt from each watchdog and timer. |
112 | * For each core the timer is PPI 29 and the watchdog PPI 30. | |
113 | */ | |
114 | for (i = 0; i < s->num_cpu; i++) { | |
115 | int ppibase = (s->num_irq - 32) + i * 32; | |
cde4577f | 116 | sysbus_connect_irq(timerbusdev, i, |
9b5f952b | 117 | qdev_get_gpio_in(gicdev, ppibase + 29)); |
cde4577f | 118 | sysbus_connect_irq(wdtbusdev, i, |
9b5f952b | 119 | qdev_get_gpio_in(gicdev, ppibase + 30)); |
b12080cd PM |
120 | } |
121 | return 0; | |
122 | } | |
123 | ||
39bffca2 | 124 | static Property a9mp_priv_properties[] = { |
845769fc | 125 | DEFINE_PROP_UINT32("num-cpu", A9MPPrivState, num_cpu, 1), |
39bffca2 AL |
126 | /* The Cortex-A9MP may have anything from 0 to 224 external interrupt |
127 | * IRQ lines (with another 32 internal). We default to 64+32, which | |
128 | * is the number provided by the Cortex-A9MP test chip in the | |
129 | * Realview PBX-A9 and Versatile Express A9 development boards. | |
130 | * Other boards may differ and should set this property appropriately. | |
131 | */ | |
845769fc | 132 | DEFINE_PROP_UINT32("num-irq", A9MPPrivState, num_irq, 96), |
39bffca2 AL |
133 | DEFINE_PROP_END_OF_LIST(), |
134 | }; | |
135 | ||
999e12bb AL |
136 | static void a9mp_priv_class_init(ObjectClass *klass, void *data) |
137 | { | |
39bffca2 | 138 | DeviceClass *dc = DEVICE_CLASS(klass); |
999e12bb AL |
139 | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
140 | ||
141 | k->init = a9mp_priv_init; | |
39bffca2 | 142 | dc->props = a9mp_priv_properties; |
999e12bb AL |
143 | } |
144 | ||
8c43a6f0 | 145 | static const TypeInfo a9mp_priv_info = { |
5126fec7 | 146 | .name = TYPE_A9MPCORE_PRIV, |
39bffca2 | 147 | .parent = TYPE_SYS_BUS_DEVICE, |
845769fc | 148 | .instance_size = sizeof(A9MPPrivState), |
753bc6e9 | 149 | .instance_init = a9mp_priv_initfn, |
39bffca2 | 150 | .class_init = a9mp_priv_class_init, |
f7c70325 PB |
151 | }; |
152 | ||
83f7d43a | 153 | static void a9mp_register_types(void) |
f7c70325 | 154 | { |
39bffca2 | 155 | type_register_static(&a9mp_priv_info); |
f7c70325 PB |
156 | } |
157 | ||
83f7d43a | 158 | type_init(a9mp_register_types) |