2 * Calxeda Highbank SoC emulation
4 * Copyright (c) 2010-2012 Calxeda
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2 or later, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "qemu/datadir.h"
22 #include "qapi/error.h"
23 #include "hw/sysbus.h"
24 #include "migration/vmstate.h"
25 #include "hw/arm/boot.h"
26 #include "hw/loader.h"
28 #include "sysemu/runstate.h"
29 #include "sysemu/sysemu.h"
30 #include "hw/boards.h"
31 #include "qemu/error-report.h"
32 #include "hw/char/pl011.h"
33 #include "hw/ide/ahci.h"
34 #include "hw/cpu/a9mpcore.h"
35 #include "hw/cpu/a15mpcore.h"
37 #include "qom/object.h"
39 #include "target/arm/cpu-qom.h"
41 #define SMP_BOOT_ADDR 0x100
42 #define SMP_BOOT_REG 0x40
43 #define MPCORE_PERIPHBASE 0xfff10000
45 #define MVBAR_ADDR 0x200
46 #define BOARD_SETUP_ADDR (MVBAR_ADDR + 8 * sizeof(uint32_t))
52 #define NUM_REGS 0x200
53 static void hb_regs_write(void *opaque
, hwaddr offset
,
54 uint64_t value
, unsigned size
)
56 uint32_t *regs
= opaque
;
58 if (offset
== 0xf00) {
59 if (value
== 1 || value
== 2) {
60 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET
);
61 } else if (value
== 3) {
62 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN
);
66 if (offset
/ 4 >= NUM_REGS
) {
67 qemu_log_mask(LOG_GUEST_ERROR
,
68 "highbank: bad write offset 0x%" HWADDR_PRIx
"\n", offset
);
71 regs
[offset
/ 4] = value
;
74 static uint64_t hb_regs_read(void *opaque
, hwaddr offset
,
78 uint32_t *regs
= opaque
;
80 if (offset
/ 4 >= NUM_REGS
) {
81 qemu_log_mask(LOG_GUEST_ERROR
,
82 "highbank: bad read offset 0x%" HWADDR_PRIx
"\n", offset
);
85 value
= regs
[offset
/ 4];
87 if ((offset
== 0x100) || (offset
== 0x108) || (offset
== 0x10C)) {
94 static const MemoryRegionOps hb_mem_ops
= {
96 .write
= hb_regs_write
,
97 .endianness
= DEVICE_NATIVE_ENDIAN
,
100 #define TYPE_HIGHBANK_REGISTERS "highbank-regs"
101 OBJECT_DECLARE_SIMPLE_TYPE(HighbankRegsState
, HIGHBANK_REGISTERS
)
103 struct HighbankRegsState
{
105 SysBusDevice parent_obj
;
109 uint32_t regs
[NUM_REGS
];
112 static const VMStateDescription vmstate_highbank_regs
= {
113 .name
= "highbank-regs",
115 .minimum_version_id
= 0,
116 .fields
= (const VMStateField
[]) {
117 VMSTATE_UINT32_ARRAY(regs
, HighbankRegsState
, NUM_REGS
),
118 VMSTATE_END_OF_LIST(),
122 static void highbank_regs_reset(DeviceState
*dev
)
124 HighbankRegsState
*s
= HIGHBANK_REGISTERS(dev
);
126 s
->regs
[0x40] = 0x05F20121;
128 s
->regs
[0x42] = 0x05F30121;
129 s
->regs
[0x43] = 0x05F40121;
132 static void highbank_regs_init(Object
*obj
)
134 HighbankRegsState
*s
= HIGHBANK_REGISTERS(obj
);
135 SysBusDevice
*dev
= SYS_BUS_DEVICE(obj
);
137 memory_region_init_io(&s
->iomem
, obj
, &hb_mem_ops
, s
->regs
,
138 "highbank_regs", 0x1000);
139 sysbus_init_mmio(dev
, &s
->iomem
);
142 static void highbank_regs_class_init(ObjectClass
*klass
, void *data
)
144 DeviceClass
*dc
= DEVICE_CLASS(klass
);
146 dc
->desc
= "Calxeda Highbank registers";
147 dc
->vmsd
= &vmstate_highbank_regs
;
148 dc
->reset
= highbank_regs_reset
;
151 static const TypeInfo highbank_regs_info
= {
152 .name
= TYPE_HIGHBANK_REGISTERS
,
153 .parent
= TYPE_SYS_BUS_DEVICE
,
154 .instance_size
= sizeof(HighbankRegsState
),
155 .instance_init
= highbank_regs_init
,
156 .class_init
= highbank_regs_class_init
,
159 static void highbank_regs_register_types(void)
161 type_register_static(&highbank_regs_info
);
164 type_init(highbank_regs_register_types
)
166 static struct arm_boot_info highbank_binfo
;
173 /* ram_size must be set to match the upper bound of memory in the
174 * device tree (linux/arch/arm/boot/dts/highbank.dts), which is
175 * normally 0xff900000 or -m 4089. When running this board on a
176 * 32-bit host, set the reg value of memory to 0xf7ff00000 in the
177 * device tree and pass -m 2047 to QEMU.
179 static void calxeda_init(MachineState
*machine
, enum cxmachines machine_id
)
181 DeviceState
*dev
= NULL
;
182 SysBusDevice
*busdev
;
185 unsigned int smp_cpus
= machine
->smp
.cpus
;
188 qemu_irq cpu_virq
[4];
189 qemu_irq cpu_vfiq
[4];
190 MemoryRegion
*sysram
;
191 MemoryRegion
*sysmem
;
192 char *sysboot_filename
;
194 switch (machine_id
) {
195 case CALXEDA_HIGHBANK
:
196 machine
->cpu_type
= ARM_CPU_TYPE_NAME("cortex-a9");
199 machine
->cpu_type
= ARM_CPU_TYPE_NAME("cortex-a15");
205 for (n
= 0; n
< smp_cpus
; n
++) {
209 cpuobj
= object_new(machine
->cpu_type
);
210 cpu
= ARM_CPU(cpuobj
);
212 object_property_set_int(cpuobj
, "psci-conduit", QEMU_PSCI_CONDUIT_SMC
,
215 if (object_property_find(cpuobj
, "reset-cbar")) {
216 object_property_set_int(cpuobj
, "reset-cbar", MPCORE_PERIPHBASE
,
219 qdev_realize(DEVICE(cpuobj
), NULL
, &error_fatal
);
220 cpu_irq
[n
] = qdev_get_gpio_in(DEVICE(cpu
), ARM_CPU_IRQ
);
221 cpu_fiq
[n
] = qdev_get_gpio_in(DEVICE(cpu
), ARM_CPU_FIQ
);
222 cpu_virq
[n
] = qdev_get_gpio_in(DEVICE(cpu
), ARM_CPU_VIRQ
);
223 cpu_vfiq
[n
] = qdev_get_gpio_in(DEVICE(cpu
), ARM_CPU_VFIQ
);
226 sysmem
= get_system_memory();
227 /* SDRAM at address zero. */
228 memory_region_add_subregion(sysmem
, 0, machine
->ram
);
230 sysram
= g_new(MemoryRegion
, 1);
231 memory_region_init_ram(sysram
, NULL
, "highbank.sysram", 0x8000,
233 memory_region_add_subregion(sysmem
, 0xfff88000, sysram
);
234 if (machine
->firmware
!= NULL
) {
235 sysboot_filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, machine
->firmware
);
236 if (sysboot_filename
!= NULL
) {
237 if (load_image_targphys(sysboot_filename
, 0xfff88000, 0x8000) < 0) {
238 error_report("Unable to load %s", machine
->firmware
);
241 g_free(sysboot_filename
);
243 error_report("Unable to find %s", machine
->firmware
);
248 switch (machine_id
) {
249 case CALXEDA_HIGHBANK
:
250 dev
= qdev_new("l2x0");
251 busdev
= SYS_BUS_DEVICE(dev
);
252 sysbus_realize_and_unref(busdev
, &error_fatal
);
253 sysbus_mmio_map(busdev
, 0, 0xfff12000);
255 dev
= qdev_new(TYPE_A9MPCORE_PRIV
);
258 dev
= qdev_new(TYPE_A15MPCORE_PRIV
);
261 qdev_prop_set_uint32(dev
, "num-cpu", smp_cpus
);
262 qdev_prop_set_uint32(dev
, "num-irq", NIRQ_GIC
);
263 busdev
= SYS_BUS_DEVICE(dev
);
264 sysbus_realize_and_unref(busdev
, &error_fatal
);
265 sysbus_mmio_map(busdev
, 0, MPCORE_PERIPHBASE
);
266 for (n
= 0; n
< smp_cpus
; n
++) {
267 sysbus_connect_irq(busdev
, n
, cpu_irq
[n
]);
268 sysbus_connect_irq(busdev
, n
+ smp_cpus
, cpu_fiq
[n
]);
269 sysbus_connect_irq(busdev
, n
+ 2 * smp_cpus
, cpu_virq
[n
]);
270 sysbus_connect_irq(busdev
, n
+ 3 * smp_cpus
, cpu_vfiq
[n
]);
273 for (n
= 0; n
< 128; n
++) {
274 pic
[n
] = qdev_get_gpio_in(dev
, n
);
277 dev
= qdev_new("sp804");
278 qdev_prop_set_uint32(dev
, "freq0", 150000000);
279 qdev_prop_set_uint32(dev
, "freq1", 150000000);
280 busdev
= SYS_BUS_DEVICE(dev
);
281 sysbus_realize_and_unref(busdev
, &error_fatal
);
282 sysbus_mmio_map(busdev
, 0, 0xfff34000);
283 sysbus_connect_irq(busdev
, 0, pic
[18]);
284 pl011_create(0xfff36000, pic
[20], serial_hd(0));
286 dev
= qdev_new(TYPE_HIGHBANK_REGISTERS
);
287 busdev
= SYS_BUS_DEVICE(dev
);
288 sysbus_realize_and_unref(busdev
, &error_fatal
);
289 sysbus_mmio_map(busdev
, 0, 0xfff3c000);
291 sysbus_create_simple("pl061", 0xfff30000, pic
[14]);
292 sysbus_create_simple("pl061", 0xfff31000, pic
[15]);
293 sysbus_create_simple("pl061", 0xfff32000, pic
[16]);
294 sysbus_create_simple("pl061", 0xfff33000, pic
[17]);
295 sysbus_create_simple("pl031", 0xfff35000, pic
[19]);
296 sysbus_create_simple("pl022", 0xfff39000, pic
[23]);
298 sysbus_create_simple(TYPE_SYSBUS_AHCI
, 0xffe08000, pic
[83]);
300 if (nd_table
[0].used
) {
301 qemu_check_nic_model(&nd_table
[0], "xgmac");
302 dev
= qdev_new("xgmac");
303 qdev_set_nic_properties(dev
, &nd_table
[0]);
304 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
305 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, 0xfff50000);
306 sysbus_connect_irq(SYS_BUS_DEVICE(dev
), 0, pic
[77]);
307 sysbus_connect_irq(SYS_BUS_DEVICE(dev
), 1, pic
[78]);
308 sysbus_connect_irq(SYS_BUS_DEVICE(dev
), 2, pic
[79]);
310 qemu_check_nic_model(&nd_table
[1], "xgmac");
311 dev
= qdev_new("xgmac");
312 qdev_set_nic_properties(dev
, &nd_table
[1]);
313 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
314 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, 0xfff51000);
315 sysbus_connect_irq(SYS_BUS_DEVICE(dev
), 0, pic
[80]);
316 sysbus_connect_irq(SYS_BUS_DEVICE(dev
), 1, pic
[81]);
317 sysbus_connect_irq(SYS_BUS_DEVICE(dev
), 2, pic
[82]);
320 /* TODO create and connect IDE devices for ide_drive_get() */
322 highbank_binfo
.ram_size
= machine
->ram_size
;
323 /* highbank requires a dtb in order to boot, and the dtb will override
324 * the board ID. The following value is ignored, so set it to -1 to be
325 * clear that the value is meaningless.
327 highbank_binfo
.board_id
= -1;
328 highbank_binfo
.loader_start
= 0;
329 highbank_binfo
.board_setup_addr
= BOARD_SETUP_ADDR
;
330 highbank_binfo
.psci_conduit
= QEMU_PSCI_CONDUIT_SMC
;
332 arm_load_kernel(ARM_CPU(first_cpu
), machine
, &highbank_binfo
);
335 static void highbank_init(MachineState
*machine
)
337 calxeda_init(machine
, CALXEDA_HIGHBANK
);
340 static void midway_init(MachineState
*machine
)
342 calxeda_init(machine
, CALXEDA_MIDWAY
);
345 static void highbank_class_init(ObjectClass
*oc
, void *data
)
347 MachineClass
*mc
= MACHINE_CLASS(oc
);
349 mc
->desc
= "Calxeda Highbank (ECX-1000)";
350 mc
->init
= highbank_init
;
351 mc
->block_default_type
= IF_IDE
;
352 mc
->units_per_default_bus
= 1;
354 mc
->ignore_memory_transaction_failures
= true;
355 mc
->default_ram_id
= "highbank.dram";
358 static const TypeInfo highbank_type
= {
359 .name
= MACHINE_TYPE_NAME("highbank"),
360 .parent
= TYPE_MACHINE
,
361 .class_init
= highbank_class_init
,
364 static void midway_class_init(ObjectClass
*oc
, void *data
)
366 MachineClass
*mc
= MACHINE_CLASS(oc
);
368 mc
->desc
= "Calxeda Midway (ECX-2000)";
369 mc
->init
= midway_init
;
370 mc
->block_default_type
= IF_IDE
;
371 mc
->units_per_default_bus
= 1;
373 mc
->ignore_memory_transaction_failures
= true;
374 mc
->default_ram_id
= "highbank.dram";
377 static const TypeInfo midway_type
= {
378 .name
= MACHINE_TYPE_NAME("midway"),
379 .parent
= TYPE_MACHINE
,
380 .class_init
= midway_class_init
,
383 static void calxeda_machines_init(void)
385 type_register_static(&highbank_type
);
386 type_register_static(&midway_type
);
389 type_init(calxeda_machines_init
)