xref: /openbmc/qemu/hw/arm/microbit.c (revision 966f2ec3)
1 /*
2  * BBC micro:bit machine
3  * http://tech.microbit.org/hardware/
4  *
5  * Copyright 2018 Joel Stanley <joel@jms.id.au>
6  *
7  * This code is licensed under the GPL version 2 or later.  See
8  * the COPYING file in the top-level directory.
9  */
10 
11 #include "qemu/osdep.h"
12 #include "qapi/error.h"
13 #include "hw/boards.h"
14 #include "hw/arm/arm.h"
15 #include "exec/address-spaces.h"
16 
17 #include "hw/arm/nrf51_soc.h"
18 
19 typedef struct {
20     MachineState parent;
21 
22     NRF51State nrf51;
23 } MicrobitMachineState;
24 
25 #define TYPE_MICROBIT_MACHINE MACHINE_TYPE_NAME("microbit")
26 
27 #define MICROBIT_MACHINE(obj) \
28     OBJECT_CHECK(MicrobitMachineState, obj, TYPE_MICROBIT_MACHINE)
29 
30 static void microbit_init(MachineState *machine)
31 {
32     MicrobitMachineState *s = MICROBIT_MACHINE(machine);
33     MemoryRegion *system_memory = get_system_memory();
34     Object *soc = OBJECT(&s->nrf51);
35 
36     sysbus_init_child_obj(OBJECT(machine), "nrf51", soc, sizeof(s->nrf51),
37                           TYPE_NRF51_SOC);
38     object_property_set_link(soc, OBJECT(system_memory), "memory",
39                              &error_fatal);
40     object_property_set_bool(soc, true, "realized", &error_fatal);
41 
42     armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
43                        NRF51_SOC(soc)->flash_size);
44 }
45 
46 static void microbit_machine_class_init(ObjectClass *oc, void *data)
47 {
48     MachineClass *mc = MACHINE_CLASS(oc);
49 
50     mc->desc = "BBC micro:bit";
51     mc->init = microbit_init;
52     mc->max_cpus = 1;
53 }
54 
55 static const TypeInfo microbit_info = {
56     .name = TYPE_MICROBIT_MACHINE,
57     .parent = TYPE_MACHINE,
58     .instance_size = sizeof(MicrobitMachineState),
59     .class_init = microbit_machine_class_init,
60 };
61 
62 static void microbit_machine_init(void)
63 {
64     type_register_static(&microbit_info);
65 }
66 
67 type_init(microbit_machine_init);
68