diff mbox series

[2/7] arm: Move nRF51 machine state to dedicated header

Message ID 20180811090836.4024-3-contrib@steffen-goertz.de
State New
Headers show
Series arm: Instantiation of nRF51 SOC and bbc:microbit devices | expand

Commit Message

Steffen Görtz Aug. 11, 2018, 9:08 a.m. UTC
The machine state will be used to host the SOC
and board level devices like the LED matrix and
devices to handle to pushbuttons A and B.

Signed-off-by: Steffen Görtz <contrib@steffen-goertz.de>
---
 hw/arm/microbit.c         | 38 ++++++++++++++++++++++++--------------
 include/hw/arm/microbit.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 14 deletions(-)
 create mode 100644 include/hw/arm/microbit.h

Comments

Peter Maydell Aug. 16, 2018, 2:58 p.m. UTC | #1
On 11 August 2018 at 10:08, Steffen Görtz <contrib@steffen-goertz.de> wrote:
> The machine state will be used to host the SOC
> and board level devices like the LED matrix and
> devices to handle to pushbuttons A and B.
>
> Signed-off-by: Steffen Görtz <contrib@steffen-goertz.de>
> ---
>  hw/arm/microbit.c         | 38 ++++++++++++++++++++++++--------------
>  include/hw/arm/microbit.h | 29 +++++++++++++++++++++++++++++
>  2 files changed, 53 insertions(+), 14 deletions(-)
>  create mode 100644 include/hw/arm/microbit.h

These changes should be squashed into Joel's initial
patch creating the machine, as per discussion on that patch.

I don't think we really need a separate header file,
unless there's something I'm missing because I haven't yet
read later patches in the series.

thanks
-- PMM
diff mbox series

Patch

diff --git a/hw/arm/microbit.c b/hw/arm/microbit.c
index 467cfbda23..8f3c446f52 100644
--- a/hw/arm/microbit.c
+++ b/hw/arm/microbit.c
@@ -14,22 +14,11 @@ 
 #include "hw/arm/arm.h"
 #include "exec/address-spaces.h"
 
-#include "hw/arm/nrf51_soc.h"
-
-typedef struct {
-    MachineState parent;
-
-    NRF51State nrf51;
-} MICROBITMachineState;
-
-#define TYPE_MICROBIT_MACHINE "microbit"
-
-#define MICROBIT_MACHINE(obj) \
-    OBJECT_CHECK(MICROBITMachineState, obj, TYPE_MICROBIT_MACHINE)
+#include "hw/arm/microbit.h"
 
 static void microbit_init(MachineState *machine)
 {
-    MICROBITMachineState *s = g_new(MICROBITMachineState, 1);
+    MicrobitMachineState *s = MICROBIT_MACHINE(machine);
     MemoryRegion *system_memory = get_system_memory();
     Object *soc;
 
@@ -45,10 +34,31 @@  static void microbit_init(MachineState *machine)
             NRF51_SOC(soc)->flash_size);
 }
 
+
 static void microbit_machine_init(MachineClass *mc)
 {
     mc->desc = "BBC micro:bit";
     mc->init = microbit_init;
     mc->max_cpus = 1;
 }
-DEFINE_MACHINE("microbit", microbit_machine_init);
+
+static void microbit_machine_init_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    microbit_machine_init(mc);
+}
+
+static const TypeInfo microbit_machine_info = {
+    .name       = TYPE_MICROBIT_MACHINE,
+    .parent     = TYPE_MACHINE,
+    .instance_size = sizeof(MicrobitMachineState),
+    .class_init = microbit_machine_init_class_init,
+};
+
+static void microbit_machine_types(void)
+{
+    type_register_static(&microbit_machine_info);
+}
+
+type_init(microbit_machine_types)
+
diff --git a/include/hw/arm/microbit.h b/include/hw/arm/microbit.h
new file mode 100644
index 0000000000..89f0c6bc07
--- /dev/null
+++ b/include/hw/arm/microbit.h
@@ -0,0 +1,29 @@ 
+/*
+ * BBC micro:bit machine
+ *
+ * Copyright 2018 Joel Stanley <joel@jms.id.au>
+ * Copyright 2018 Steffen Görtz <contrib@steffen-goertz.de>
+ *
+ * This code is licensed under the GPL version 2 or later.  See
+ * the COPYING file in the top-level directory.
+ */
+#ifndef MICROBIT_H
+#define MICROBIT_H
+
+#include "qemu/osdep.h"
+#include "hw/qdev-core.h"
+#include "hw/arm/nrf51_soc.h"
+#include "hw/display/led_matrix.h"
+
+#define TYPE_MICROBIT_MACHINE       MACHINE_TYPE_NAME("microbit")
+#define MICROBIT_MACHINE(obj) \
+    OBJECT_CHECK(MicrobitMachineState, (obj), TYPE_MICROBIT_MACHINE)
+
+typedef struct MicrobitMachineState {
+    /*< private >*/
+    MachineState parent_obj;
+
+    NRF51State nrf51;
+} MicrobitMachineState;
+
+#endif