]> git.proxmox.com Git - qemu.git/blame - hw/a9mpcore.c
tcg-s390: Fix merge error in tgen_brcond
[qemu.git] / hw / a9mpcore.c
CommitLineData
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"
b12080cd 12
845769fc 13typedef struct A9MPPrivState {
ddd76165 14 SysBusDevice busdev;
b12080cd 15 uint32_t num_cpu;
b12080cd
PM
16 MemoryRegion container;
17 DeviceState *mptimer;
cde4577f 18 DeviceState *wdt;
ddd76165 19 DeviceState *gic;
353575f0 20 DeviceState *scu;
a32134aa 21 uint32_t num_irq;
845769fc 22} A9MPPrivState;
b12080cd 23
ddd76165
PM
24static void a9mp_priv_set_irq(void *opaque, int irq, int level)
25{
845769fc 26 A9MPPrivState *s = (A9MPPrivState *)opaque;
ddd76165
PM
27 qemu_set_irq(qdev_get_gpio_in(s->gic, irq), level);
28}
29
b12080cd
PM
30static int a9mp_priv_init(SysBusDevice *dev)
31{
845769fc 32 A9MPPrivState *s = FROM_SYSBUS(A9MPPrivState, dev);
353575f0 33 SysBusDevice *timerbusdev, *wdtbusdev, *gicbusdev, *scubusdev;
b12080cd
PM
34 int i;
35
ddd76165
PM
36 s->gic = qdev_create(NULL, "arm_gic");
37 qdev_prop_set_uint32(s->gic, "num-cpu", s->num_cpu);
38 qdev_prop_set_uint32(s->gic, "num-irq", s->num_irq);
39 qdev_init_nofail(s->gic);
1356b98d 40 gicbusdev = SYS_BUS_DEVICE(s->gic);
ddd76165
PM
41
42 /* Pass through outbound IRQ lines from the GIC */
43 sysbus_pass_irq(dev, gicbusdev);
44
45 /* Pass through inbound GPIO lines to the GIC */
46 qdev_init_gpio_in(&s->busdev.qdev, a9mp_priv_set_irq, s->num_irq - 32);
b12080cd 47
353575f0
PC
48 s->scu = qdev_create(NULL, "a9-scu");
49 qdev_prop_set_uint32(s->scu, "num-cpu", s->num_cpu);
50 qdev_init_nofail(s->scu);
51 scubusdev = SYS_BUS_DEVICE(s->scu);
52
b12080cd
PM
53 s->mptimer = qdev_create(NULL, "arm_mptimer");
54 qdev_prop_set_uint32(s->mptimer, "num-cpu", s->num_cpu);
55 qdev_init_nofail(s->mptimer);
cde4577f
PC
56 timerbusdev = SYS_BUS_DEVICE(s->mptimer);
57
58 s->wdt = qdev_create(NULL, "arm_mptimer");
59 qdev_prop_set_uint32(s->wdt, "num-cpu", s->num_cpu);
60 qdev_init_nofail(s->wdt);
61 wdtbusdev = SYS_BUS_DEVICE(s->wdt);
b12080cd
PM
62
63 /* Memory map (addresses are offsets from PERIPHBASE):
64 * 0x0000-0x00ff -- Snoop Control Unit
65 * 0x0100-0x01ff -- GIC CPU interface
66 * 0x0200-0x02ff -- Global Timer
67 * 0x0300-0x05ff -- nothing
68 * 0x0600-0x06ff -- private timers and watchdogs
69 * 0x0700-0x0fff -- nothing
70 * 0x1000-0x1fff -- GIC Distributor
71 *
72 * We should implement the global timer but don't currently do so.
73 */
74 memory_region_init(&s->container, "a9mp-priv-container", 0x2000);
353575f0
PC
75 memory_region_add_subregion(&s->container, 0,
76 sysbus_mmio_get_region(scubusdev, 0));
b12080cd 77 /* GIC CPU interface */
ddd76165
PM
78 memory_region_add_subregion(&s->container, 0x100,
79 sysbus_mmio_get_region(gicbusdev, 1));
b12080cd
PM
80 /* Note that the A9 exposes only the "timer/watchdog for this core"
81 * memory region, not the "timer/watchdog for core X" ones 11MPcore has.
82 */
83 memory_region_add_subregion(&s->container, 0x600,
cde4577f 84 sysbus_mmio_get_region(timerbusdev, 0));
b12080cd 85 memory_region_add_subregion(&s->container, 0x620,
cde4577f 86 sysbus_mmio_get_region(wdtbusdev, 0));
ddd76165
PM
87 memory_region_add_subregion(&s->container, 0x1000,
88 sysbus_mmio_get_region(gicbusdev, 0));
b12080cd
PM
89
90 sysbus_init_mmio(dev, &s->container);
91
ddd76165
PM
92 /* Wire up the interrupt from each watchdog and timer.
93 * For each core the timer is PPI 29 and the watchdog PPI 30.
94 */
95 for (i = 0; i < s->num_cpu; i++) {
96 int ppibase = (s->num_irq - 32) + i * 32;
cde4577f 97 sysbus_connect_irq(timerbusdev, i,
ddd76165 98 qdev_get_gpio_in(s->gic, ppibase + 29));
cde4577f 99 sysbus_connect_irq(wdtbusdev, i,
ddd76165 100 qdev_get_gpio_in(s->gic, ppibase + 30));
b12080cd
PM
101 }
102 return 0;
103}
104
39bffca2 105static Property a9mp_priv_properties[] = {
845769fc 106 DEFINE_PROP_UINT32("num-cpu", A9MPPrivState, num_cpu, 1),
39bffca2
AL
107 /* The Cortex-A9MP may have anything from 0 to 224 external interrupt
108 * IRQ lines (with another 32 internal). We default to 64+32, which
109 * is the number provided by the Cortex-A9MP test chip in the
110 * Realview PBX-A9 and Versatile Express A9 development boards.
111 * Other boards may differ and should set this property appropriately.
112 */
845769fc 113 DEFINE_PROP_UINT32("num-irq", A9MPPrivState, num_irq, 96),
39bffca2
AL
114 DEFINE_PROP_END_OF_LIST(),
115};
116
999e12bb
AL
117static void a9mp_priv_class_init(ObjectClass *klass, void *data)
118{
39bffca2 119 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb
AL
120 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
121
122 k->init = a9mp_priv_init;
39bffca2 123 dc->props = a9mp_priv_properties;
999e12bb
AL
124}
125
8c43a6f0 126static const TypeInfo a9mp_priv_info = {
39bffca2
AL
127 .name = "a9mpcore_priv",
128 .parent = TYPE_SYS_BUS_DEVICE,
845769fc 129 .instance_size = sizeof(A9MPPrivState),
39bffca2 130 .class_init = a9mp_priv_class_init,
f7c70325
PB
131};
132
83f7d43a 133static void a9mp_register_types(void)
f7c70325 134{
39bffca2 135 type_register_static(&a9mp_priv_info);
f7c70325
PB
136}
137
83f7d43a 138type_init(a9mp_register_types)