2 * Cortex-A9MPCore internal peripheral emulation.
4 * Copyright (c) 2009 CodeSourcery.
5 * Copyright (c) 2011 Linaro Limited.
6 * Written by Paul Brook, Peter Maydell.
8 * This code is licensed under the GPL.
13 /* Configuration for arm_gic.c:
14 * max number of CPUs, how to ID current CPU
19 gic_get_current_cpu(void)
21 return cpu_single_env
->cpu_index
;
26 /* A9MP private memory region. */
28 typedef struct a9mp_priv_state
{
32 uint32_t old_timer_status
[8];
35 MemoryRegion scu_iomem
;
36 MemoryRegion ptimer_iomem
;
37 MemoryRegion container
;
42 static uint64_t a9_scu_read(void *opaque
, target_phys_addr_t offset
,
45 a9mp_priv_state
*s
= (a9mp_priv_state
*)opaque
;
47 case 0x00: /* Control */
48 return s
->scu_control
;
49 case 0x04: /* Configuration */
50 return (((1 << s
->num_cpu
) - 1) << 4) | (s
->num_cpu
- 1);
51 case 0x08: /* CPU Power Status */
53 case 0x09: /* CPU status. */
54 return s
->scu_status
>> 8;
55 case 0x0a: /* CPU status. */
56 return s
->scu_status
>> 16;
57 case 0x0b: /* CPU status. */
58 return s
->scu_status
>> 24;
59 case 0x0c: /* Invalidate All Registers In Secure State */
61 case 0x40: /* Filtering Start Address Register */
62 case 0x44: /* Filtering End Address Register */
63 /* RAZ/WI, like an implementation with only one AXI master */
65 case 0x50: /* SCU Access Control Register */
66 case 0x54: /* SCU Non-secure Access Control Register */
67 /* unimplemented, fall through */
73 static void a9_scu_write(void *opaque
, target_phys_addr_t offset
,
74 uint64_t value
, unsigned size
)
76 a9mp_priv_state
*s
= (a9mp_priv_state
*)opaque
;
90 fprintf(stderr
, "Invalid size %u in write to a9 scu register %x\n",
96 case 0x00: /* Control */
97 s
->scu_control
= value
& 1;
99 case 0x4: /* Configuration: RO */
101 case 0x08: case 0x09: case 0x0A: case 0x0B: /* Power Control */
102 shift
= (offset
- 0x8) * 8;
103 s
->scu_status
&= ~(mask
<< shift
);
104 s
->scu_status
|= ((value
& mask
) << shift
);
106 case 0x0c: /* Invalidate All Registers In Secure State */
107 /* no-op as we do not implement caches */
109 case 0x40: /* Filtering Start Address Register */
110 case 0x44: /* Filtering End Address Register */
111 /* RAZ/WI, like an implementation with only one AXI master */
113 case 0x50: /* SCU Access Control Register */
114 case 0x54: /* SCU Non-secure Access Control Register */
115 /* unimplemented, fall through */
121 static const MemoryRegionOps a9_scu_ops
= {
123 .write
= a9_scu_write
,
124 .endianness
= DEVICE_NATIVE_ENDIAN
,
127 static void a9mpcore_timer_irq_handler(void *opaque
, int irq
, int level
)
129 a9mp_priv_state
*s
= (a9mp_priv_state
*)opaque
;
130 if (level
&& !s
->old_timer_status
[irq
]) {
131 gic_set_pending_private(&s
->gic
, irq
>> 1, 29 + (irq
& 1));
133 s
->old_timer_status
[irq
] = level
;
136 static void a9mp_priv_reset(DeviceState
*dev
)
138 a9mp_priv_state
*s
= FROM_SYSBUSGIC(a9mp_priv_state
, sysbus_from_qdev(dev
));
141 for (i
= 0; i
< ARRAY_SIZE(s
->old_timer_status
); i
++) {
142 s
->old_timer_status
[i
] = 0;
146 static int a9mp_priv_init(SysBusDevice
*dev
)
148 a9mp_priv_state
*s
= FROM_SYSBUSGIC(a9mp_priv_state
, dev
);
149 SysBusDevice
*busdev
;
152 if (s
->num_cpu
> NCPU
) {
153 hw_error("a9mp_priv_init: num-cpu may not be more than %d\n", NCPU
);
156 gic_init(&s
->gic
, s
->num_cpu
, s
->num_irq
);
158 s
->mptimer
= qdev_create(NULL
, "arm_mptimer");
159 qdev_prop_set_uint32(s
->mptimer
, "num-cpu", s
->num_cpu
);
160 qdev_init_nofail(s
->mptimer
);
161 busdev
= sysbus_from_qdev(s
->mptimer
);
163 /* Memory map (addresses are offsets from PERIPHBASE):
164 * 0x0000-0x00ff -- Snoop Control Unit
165 * 0x0100-0x01ff -- GIC CPU interface
166 * 0x0200-0x02ff -- Global Timer
167 * 0x0300-0x05ff -- nothing
168 * 0x0600-0x06ff -- private timers and watchdogs
169 * 0x0700-0x0fff -- nothing
170 * 0x1000-0x1fff -- GIC Distributor
172 * We should implement the global timer but don't currently do so.
174 memory_region_init(&s
->container
, "a9mp-priv-container", 0x2000);
175 memory_region_init_io(&s
->scu_iomem
, &a9_scu_ops
, s
, "a9mp-scu", 0x100);
176 memory_region_add_subregion(&s
->container
, 0, &s
->scu_iomem
);
177 /* GIC CPU interface */
178 memory_region_add_subregion(&s
->container
, 0x100, &s
->gic
.cpuiomem
[0]);
179 /* Note that the A9 exposes only the "timer/watchdog for this core"
180 * memory region, not the "timer/watchdog for core X" ones 11MPcore has.
182 memory_region_add_subregion(&s
->container
, 0x600,
183 sysbus_mmio_get_region(busdev
, 0));
184 memory_region_add_subregion(&s
->container
, 0x620,
185 sysbus_mmio_get_region(busdev
, 1));
186 memory_region_add_subregion(&s
->container
, 0x1000, &s
->gic
.iomem
);
188 sysbus_init_mmio(dev
, &s
->container
);
190 /* Wire up the interrupt from each watchdog and timer. */
191 s
->timer_irq
= qemu_allocate_irqs(a9mpcore_timer_irq_handler
,
192 s
, (s
->num_cpu
+ 1) * 2);
193 for (i
= 0; i
< s
->num_cpu
* 2; i
++) {
194 sysbus_connect_irq(busdev
, i
, s
->timer_irq
[i
]);
199 static const VMStateDescription vmstate_a9mp_priv
= {
200 .name
= "a9mpcore_priv",
202 .minimum_version_id
= 1,
203 .fields
= (VMStateField
[]) {
204 VMSTATE_UINT32(scu_control
, a9mp_priv_state
),
205 VMSTATE_UINT32_ARRAY(old_timer_status
, a9mp_priv_state
, 8),
206 VMSTATE_UINT32_V(scu_status
, a9mp_priv_state
, 2),
207 VMSTATE_END_OF_LIST()
211 static SysBusDeviceInfo a9mp_priv_info
= {
212 .init
= a9mp_priv_init
,
213 .qdev
.name
= "a9mpcore_priv",
214 .qdev
.size
= sizeof(a9mp_priv_state
),
215 .qdev
.vmsd
= &vmstate_a9mp_priv
,
216 .qdev
.reset
= a9mp_priv_reset
,
217 .qdev
.props
= (Property
[]) {
218 DEFINE_PROP_UINT32("num-cpu", a9mp_priv_state
, num_cpu
, 1),
219 /* The Cortex-A9MP may have anything from 0 to 224 external interrupt
220 * IRQ lines (with another 32 internal). We default to 64+32, which
221 * is the number provided by the Cortex-A9MP test chip in the
222 * Realview PBX-A9 and Versatile Express A9 development boards.
223 * Other boards may differ and should set this property appropriately.
225 DEFINE_PROP_UINT32("num-irq", a9mp_priv_state
, num_irq
, 96),
226 DEFINE_PROP_END_OF_LIST(),
230 static void a9mp_register_devices(void)
232 sysbus_register_withprop(&a9mp_priv_info
);
235 device_init(a9mp_register_devices
)