qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/4] sPAPRMachineState cleanups
@ 2015-05-07  3:57 David Gibson
  2015-05-07  3:57 ` [Qemu-devel] [PATCH 1/4] spapr: Merge sPAPREnvironment into sPAPRMachineState David Gibson
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: David Gibson @ 2015-05-07  3:57 UTC (permalink / raw)
  To: qemu-ppc, qemu-devel
  Cc: lvivier, thuth, aik, mdroth, agraf, bharata, afaerber,
	David Gibson

This series makes some cleanups to the structures tracking overall
machine state for spapr (-machine pseries).  First the old
sPAPREnvironment structure (which predates the generic MachineState
structure) is merged into a spapr specific subclass of MachineState.
Then some obsolete fields are cleaned up.

If I receive a review or two, with nothing terribly wrong, I'll merge
this into the spapr-next branch.

David Gibson (4):
  spapr: Merge sPAPREnvironment into sPAPRMachineState
  spapr: Remove obsolete ram_limit field from sPAPRMachineState
  spapr: Remove obsolete entry_point field from sPAPRMachineState
  spapr: Add sPAPRMachineClass

 hw/char/spapr_vty.c         |  14 +-
 hw/intc/xics.c              |  42 +++---
 hw/intc/xics_kvm.c          |   2 +-
 hw/net/spapr_llan.c         |  20 +--
 hw/nvram/spapr_nvram.c      |   8 +-
 hw/ppc/spapr.c              | 339 +++++++++++++++++++++-----------------------
 hw/ppc/spapr_events.c       |  37 ++---
 hw/ppc/spapr_hcall.c        |  45 +++---
 hw/ppc/spapr_iommu.c        |   8 +-
 hw/ppc/spapr_pci.c          |  91 ++++++------
 hw/ppc/spapr_rtas.c         |  66 ++++-----
 hw/ppc/spapr_rtc.c          |  12 +-
 hw/ppc/spapr_vio.c          |  31 ++--
 include/hw/pci-host/spapr.h |  12 +-
 include/hw/ppc/spapr.h      |  51 +++++--
 include/hw/ppc/spapr_vio.h  |   6 +-
 16 files changed, 407 insertions(+), 377 deletions(-)

-- 
2.1.0

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH 1/4] spapr: Merge sPAPREnvironment into sPAPRMachineState
  2015-05-07  3:57 [Qemu-devel] [PATCH 0/4] sPAPRMachineState cleanups David Gibson
@ 2015-05-07  3:57 ` David Gibson
  2015-05-07  8:13   ` Thomas Huth
  2015-05-07  3:57 ` [Qemu-devel] [PATCH 2/4] spapr: Remove obsolete ram_limit field from sPAPRMachineState David Gibson
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: David Gibson @ 2015-05-07  3:57 UTC (permalink / raw)
  To: qemu-ppc, qemu-devel
  Cc: lvivier, thuth, aik, mdroth, agraf, bharata, afaerber,
	David Gibson

The code for -machine pseries maintains a global sPAPREnvironment structure
which keeps track of general state information about the guest platform.
This predates the existence of the MachineState structure, but performs
basically the same function.

Now that we have the generic MachineState, fold sPAPREnvironment into
sPAPRMachineState, the pseries specific subclass of MachineState.

This is mostly a matter of search and replace, although a few places which
relied on the global spapr variable are changed to find the structure via
qdev_get_machine().

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/char/spapr_vty.c         |  14 +-
 hw/intc/xics.c              |  42 +++---
 hw/intc/xics_kvm.c          |   2 +-
 hw/net/spapr_llan.c         |  20 +--
 hw/nvram/spapr_nvram.c      |   8 +-
 hw/ppc/spapr.c              | 339 +++++++++++++++++++++-----------------------
 hw/ppc/spapr_events.c       |  37 ++---
 hw/ppc/spapr_hcall.c        |  44 +++---
 hw/ppc/spapr_iommu.c        |   8 +-
 hw/ppc/spapr_pci.c          |  91 ++++++------
 hw/ppc/spapr_rtas.c         |  66 ++++-----
 hw/ppc/spapr_rtc.c          |  12 +-
 hw/ppc/spapr_vio.c          |  31 ++--
 include/hw/pci-host/spapr.h |  12 +-
 include/hw/ppc/spapr.h      |  33 +++--
 include/hw/ppc/spapr_vio.h  |   6 +-
 16 files changed, 391 insertions(+), 374 deletions(-)

diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c
index 4e464bd..5a27740 100644
--- a/hw/char/spapr_vty.c
+++ b/hw/char/spapr_vty.c
@@ -74,7 +74,7 @@ static void spapr_vty_realize(VIOsPAPRDevice *sdev, Error **errp)
 }
 
 /* Forward declaration */
-static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                     target_ulong opcode, target_ulong *args)
 {
     target_ulong reg = args[0];
@@ -84,7 +84,7 @@ static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     VIOsPAPRDevice *sdev;
     uint8_t buf[16];
 
-    sdev = vty_lookup(spapr, reg);
+    sdev = vty_lookup(sm, reg);
     if (!sdev) {
         return H_PARAMETER;
     }
@@ -101,7 +101,7 @@ static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-static target_ulong h_get_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_get_term_char(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                     target_ulong opcode, target_ulong *args)
 {
     target_ulong reg = args[0];
@@ -111,7 +111,7 @@ static target_ulong h_get_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     VIOsPAPRDevice *sdev;
     uint8_t buf[16];
 
-    sdev = vty_lookup(spapr, reg);
+    sdev = vty_lookup(sm, reg);
     if (!sdev) {
         return H_PARAMETER;
     }
@@ -214,18 +214,18 @@ VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus)
     return selected;
 }
 
-VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
+VIOsPAPRDevice *vty_lookup(sPAPRMachineState *sm, target_ulong reg)
 {
     VIOsPAPRDevice *sdev;
 
-    sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
+    sdev = spapr_vio_find_by_reg(sm->vio_bus, reg);
     if (!sdev && reg == 0) {
         /* Hack for kernel early debug, which always specifies reg==0.
          * We search all VIO devices, and grab the vty with the lowest
          * reg.  This attempts to mimic existing PowerVM behaviour
          * (early debug does work there, despite having no vty with
          * reg==0. */
-        return spapr_vty_get_default(spapr->vio_bus);
+        return spapr_vty_get_default(sm->vio_bus);
     }
 
     return sdev;
diff --git a/hw/intc/xics.c b/hw/intc/xics.c
index 0fd2a84..dc058e0 100644
--- a/hw/intc/xics.c
+++ b/hw/intc/xics.c
@@ -806,45 +806,45 @@ void xics_free(XICSState *icp, int irq, int num)
  * Guest interfaces
  */
 
-static target_ulong h_cppr(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_cppr(PowerPCCPU *cpu, sPAPRMachineState *sm,
                            target_ulong opcode, target_ulong *args)
 {
     CPUState *cs = CPU(cpu);
     target_ulong cppr = args[0];
 
-    icp_set_cppr(spapr->icp, cs->cpu_index, cppr);
+    icp_set_cppr(sm->icp, cs->cpu_index, cppr);
     return H_SUCCESS;
 }
 
-static target_ulong h_ipi(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_ipi(PowerPCCPU *cpu, sPAPRMachineState *sm,
                           target_ulong opcode, target_ulong *args)
 {
     target_ulong server = get_cpu_index_by_dt_id(args[0]);
     target_ulong mfrr = args[1];
 
-    if (server >= spapr->icp->nr_servers) {
+    if (server >= sm->icp->nr_servers) {
         return H_PARAMETER;
     }
 
-    icp_set_mfrr(spapr->icp, server, mfrr);
+    icp_set_mfrr(sm->icp, server, mfrr);
     return H_SUCCESS;
 }
 
-static target_ulong h_xirr(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_xirr(PowerPCCPU *cpu, sPAPRMachineState *sm,
                            target_ulong opcode, target_ulong *args)
 {
     CPUState *cs = CPU(cpu);
-    uint32_t xirr = icp_accept(spapr->icp->ss + cs->cpu_index);
+    uint32_t xirr = icp_accept(sm->icp->ss + cs->cpu_index);
 
     args[0] = xirr;
     return H_SUCCESS;
 }
 
-static target_ulong h_xirr_x(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_xirr_x(PowerPCCPU *cpu, sPAPRMachineState *sm,
                              target_ulong opcode, target_ulong *args)
 {
     CPUState *cs = CPU(cpu);
-    ICPState *ss = &spapr->icp->ss[cs->cpu_index];
+    ICPState *ss = &sm->icp->ss[cs->cpu_index];
     uint32_t xirr = icp_accept(ss);
 
     args[0] = xirr;
@@ -852,21 +852,21 @@ static target_ulong h_xirr_x(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-static target_ulong h_eoi(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_eoi(PowerPCCPU *cpu, sPAPRMachineState *sm,
                           target_ulong opcode, target_ulong *args)
 {
     CPUState *cs = CPU(cpu);
     target_ulong xirr = args[0];
 
-    icp_eoi(spapr->icp, cs->cpu_index, xirr);
+    icp_eoi(sm->icp, cs->cpu_index, xirr);
     return H_SUCCESS;
 }
 
-static target_ulong h_ipoll(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_ipoll(PowerPCCPU *cpu, sPAPRMachineState *sm,
                             target_ulong opcode, target_ulong *args)
 {
     CPUState *cs = CPU(cpu);
-    ICPState *ss = &spapr->icp->ss[cs->cpu_index];
+    ICPState *ss = &sm->icp->ss[cs->cpu_index];
 
     args[0] = ss->xirr;
     args[1] = ss->mfrr;
@@ -874,12 +874,12 @@ static target_ulong h_ipoll(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-static void rtas_set_xive(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_set_xive(PowerPCCPU *cpu, sPAPRMachineState *sm,
                           uint32_t token,
                           uint32_t nargs, target_ulong args,
                           uint32_t nret, target_ulong rets)
 {
-    ICSState *ics = spapr->icp->ics;
+    ICSState *ics = sm->icp->ics;
     uint32_t nr, server, priority;
 
     if ((nargs != 3) || (nret != 1)) {
@@ -902,12 +902,12 @@ static void rtas_set_xive(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
 }
 
-static void rtas_get_xive(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_get_xive(PowerPCCPU *cpu, sPAPRMachineState *sm,
                           uint32_t token,
                           uint32_t nargs, target_ulong args,
                           uint32_t nret, target_ulong rets)
 {
-    ICSState *ics = spapr->icp->ics;
+    ICSState *ics = sm->icp->ics;
     uint32_t nr;
 
     if ((nargs != 1) || (nret != 3)) {
@@ -927,12 +927,12 @@ static void rtas_get_xive(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     rtas_st(rets, 2, ics->irqs[nr - ics->offset].priority);
 }
 
-static void rtas_int_off(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_int_off(PowerPCCPU *cpu, sPAPRMachineState *sm,
                          uint32_t token,
                          uint32_t nargs, target_ulong args,
                          uint32_t nret, target_ulong rets)
 {
-    ICSState *ics = spapr->icp->ics;
+    ICSState *ics = sm->icp->ics;
     uint32_t nr;
 
     if ((nargs != 1) || (nret != 1)) {
@@ -953,12 +953,12 @@ static void rtas_int_off(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
 }
 
-static void rtas_int_on(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_int_on(PowerPCCPU *cpu, sPAPRMachineState *sm,
                         uint32_t token,
                         uint32_t nargs, target_ulong args,
                         uint32_t nret, target_ulong rets)
 {
-    ICSState *ics = spapr->icp->ics;
+    ICSState *ics = sm->icp->ics;
     uint32_t nr;
 
     if ((nargs != 1) || (nret != 1)) {
diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c
index c15453f..fbaf1f5 100644
--- a/hw/intc/xics_kvm.c
+++ b/hw/intc/xics_kvm.c
@@ -368,7 +368,7 @@ static void xics_kvm_set_nr_servers(XICSState *icp, uint32_t nr_servers,
     }
 }
 
-static void rtas_dummy(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_dummy(PowerPCCPU *cpu, sPAPRMachineState *sm,
                        uint32_t token,
                        uint32_t nargs, target_ulong args,
                        uint32_t nret, target_ulong rets)
diff --git a/hw/net/spapr_llan.c b/hw/net/spapr_llan.c
index 2dd5ec1..9f023e3 100644
--- a/hw/net/spapr_llan.c
+++ b/hw/net/spapr_llan.c
@@ -284,7 +284,7 @@ static int check_bd(VIOsPAPRVLANDevice *dev, vlan_bd_t bd,
 }
 
 static target_ulong h_register_logical_lan(PowerPCCPU *cpu,
-                                           sPAPREnvironment *spapr,
+                                           sPAPRMachineState *sm,
                                            target_ulong opcode,
                                            target_ulong *args)
 {
@@ -292,7 +292,7 @@ static target_ulong h_register_logical_lan(PowerPCCPU *cpu,
     target_ulong buf_list = args[1];
     target_ulong rec_queue = args[2];
     target_ulong filter_list = args[3];
-    VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
+    VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(sm->vio_bus, reg);
     VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
     vlan_bd_t filter_list_bd;
 
@@ -349,11 +349,11 @@ static target_ulong h_register_logical_lan(PowerPCCPU *cpu,
 }
 
 
-static target_ulong h_free_logical_lan(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_free_logical_lan(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                        target_ulong opcode, target_ulong *args)
 {
     target_ulong reg = args[0];
-    VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
+    VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(sm->vio_bus, reg);
     VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
 
     if (!dev) {
@@ -371,13 +371,13 @@ static target_ulong h_free_logical_lan(PowerPCCPU *cpu, sPAPREnvironment *spapr,
 }
 
 static target_ulong h_add_logical_lan_buffer(PowerPCCPU *cpu,
-                                             sPAPREnvironment *spapr,
+                                             sPAPRMachineState *sm,
                                              target_ulong opcode,
                                              target_ulong *args)
 {
     target_ulong reg = args[0];
     target_ulong buf = args[1];
-    VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
+    VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(sm->vio_bus, reg);
     VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
     vlan_bd_t bd;
 
@@ -421,13 +421,13 @@ static target_ulong h_add_logical_lan_buffer(PowerPCCPU *cpu,
     return H_SUCCESS;
 }
 
-static target_ulong h_send_logical_lan(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_send_logical_lan(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                        target_ulong opcode, target_ulong *args)
 {
     target_ulong reg = args[0];
     target_ulong *bufs = args + 1;
     target_ulong continue_token = args[7];
-    VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
+    VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(sm->vio_bus, reg);
     VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
     unsigned total_len;
     uint8_t *lbuf, *p;
@@ -490,11 +490,11 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-static target_ulong h_multicast_ctrl(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_multicast_ctrl(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                      target_ulong opcode, target_ulong *args)
 {
     target_ulong reg = args[0];
-    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
+    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(sm->vio_bus, reg);
 
     if (!dev) {
         return H_PARAMETER;
diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
index 11332d1..9b97704 100644
--- a/hw/nvram/spapr_nvram.c
+++ b/hw/nvram/spapr_nvram.c
@@ -45,12 +45,12 @@ typedef struct sPAPRNVRAM {
 #define DEFAULT_NVRAM_SIZE 65536
 #define MAX_NVRAM_SIZE 1048576
 
-static void rtas_nvram_fetch(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_nvram_fetch(PowerPCCPU *cpu, sPAPRMachineState *sm,
                              uint32_t token, uint32_t nargs,
                              target_ulong args,
                              uint32_t nret, target_ulong rets)
 {
-    sPAPRNVRAM *nvram = spapr->nvram;
+    sPAPRNVRAM *nvram = sm->nvram;
     hwaddr offset, buffer, len;
     void *membuf;
 
@@ -86,12 +86,12 @@ static void rtas_nvram_fetch(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     rtas_st(rets, 1, len);
 }
 
-static void rtas_nvram_store(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_nvram_store(PowerPCCPU *cpu, sPAPRMachineState *sm,
                              uint32_t token, uint32_t nargs,
                              target_ulong args,
                              uint32_t nret, target_ulong rets)
 {
-    sPAPRNVRAM *nvram = spapr->nvram;
+    sPAPRNVRAM *nvram = sm->nvram;
     hwaddr offset, buffer, len;
     int alen;
     void *membuf;
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index f815068..601c41b 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -88,26 +88,9 @@
 
 #define PHANDLE_XICP            0x00001111
 
-#define HTAB_SIZE(spapr)        (1ULL << ((spapr)->htab_shift))
+#define HTAB_SIZE(sm)           (1ULL << ((sm)->htab_shift))
 
-typedef struct sPAPRMachineState sPAPRMachineState;
-
-#define TYPE_SPAPR_MACHINE      "spapr-machine"
-#define SPAPR_MACHINE(obj) \
-    OBJECT_CHECK(sPAPRMachineState, (obj), TYPE_SPAPR_MACHINE)
-
-/**
- * sPAPRMachineState:
- */
-struct sPAPRMachineState {
-    /*< private >*/
-    MachineState parent_obj;
-
-    /*< public >*/
-    char *kvm_type;
-};
-
-sPAPREnvironment *spapr;
+sPAPRMachineState *sm;
 
 static XICSState *try_create_xics(const char *type, int nr_servers,
                                   int nr_irqs, Error **errp)
@@ -184,13 +167,13 @@ static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu,
     return ret;
 }
 
-static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
+static int spapr_fixup_cpu_dt(void *fdt, sPAPRMachineState *sm)
 {
     int ret = 0, offset, cpus_offset;
     CPUState *cs;
     char cpu_model[32];
     int smt = kvmppc_smt_threads();
-    uint32_t pft_size_prop[] = {0, cpu_to_be32(spapr->htab_shift)};
+    uint32_t pft_size_prop[] = {0, cpu_to_be32(sm->htab_shift)};
 
     CPU_FOREACH(cs) {
         PowerPCCPU *cpu = POWERPC_CPU(cs);
@@ -604,7 +587,8 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,
     return fdt;
 }
 
-int spapr_h_cas_compose_response(target_ulong addr, target_ulong size)
+int spapr_h_cas_compose_response(sPAPRMachineState *sm,
+                                 target_ulong addr, target_ulong size)
 {
     void *fdt, *fdt_skel;
     sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };
@@ -622,7 +606,7 @@ int spapr_h_cas_compose_response(target_ulong addr, target_ulong size)
     g_free(fdt_skel);
 
     /* Fix skeleton up */
-    _FDT((spapr_fixup_cpu_dt(fdt, spapr)));
+    _FDT((spapr_fixup_cpu_dt(fdt, sm)));
 
     /* Pack resulting tree */
     _FDT((fdt_pack(fdt)));
@@ -665,7 +649,7 @@ static void spapr_populate_memory_node(void *fdt, int nodeid, hwaddr start,
                       sizeof(associativity))));
 }
 
-static int spapr_populate_memory(sPAPREnvironment *spapr, void *fdt)
+static int spapr_populate_memory(sPAPRMachineState *sm, void *fdt)
 {
     hwaddr mem_start, node_size;
     int i, nb_nodes = nb_numa_nodes;
@@ -693,9 +677,9 @@ static int spapr_populate_memory(sPAPREnvironment *spapr, void *fdt)
         }
         if (!mem_start) {
             /* ppc_spapr_init() checks for rma_size <= node0_size already */
-            spapr_populate_memory_node(fdt, i, 0, spapr->rma_size);
-            mem_start += spapr->rma_size;
-            node_size -= spapr->rma_size;
+            spapr_populate_memory_node(fdt, i, 0, sm->rma_size);
+            mem_start += sm->rma_size;
+            node_size -= sm->rma_size;
         }
         for ( ; node_size; ) {
             hwaddr sizetmp = pow2floor(node_size);
@@ -714,7 +698,7 @@ static int spapr_populate_memory(sPAPREnvironment *spapr, void *fdt)
     return 0;
 }
 
-static void spapr_finalize_fdt(sPAPREnvironment *spapr,
+static void spapr_finalize_fdt(sPAPRMachineState *sm,
                                hwaddr fdt_addr,
                                hwaddr rtas_addr,
                                hwaddr rtas_size)
@@ -730,21 +714,21 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,
     fdt = g_malloc(FDT_MAX_SIZE);
 
     /* open out the base tree into a temp buffer for the final tweaks */
-    _FDT((fdt_open_into(spapr->fdt_skel, fdt, FDT_MAX_SIZE)));
+    _FDT((fdt_open_into(sm->fdt_skel, fdt, FDT_MAX_SIZE)));
 
-    ret = spapr_populate_memory(spapr, fdt);
+    ret = spapr_populate_memory(sm, fdt);
     if (ret < 0) {
         fprintf(stderr, "couldn't setup memory nodes in fdt\n");
         exit(1);
     }
 
-    ret = spapr_populate_vdevice(spapr->vio_bus, fdt);
+    ret = spapr_populate_vdevice(sm->vio_bus, fdt);
     if (ret < 0) {
         fprintf(stderr, "couldn't setup vio devices in fdt\n");
         exit(1);
     }
 
-    QLIST_FOREACH(phb, &spapr->phbs, list) {
+    QLIST_FOREACH(phb, &sm->phbs, list) {
         ret = spapr_populate_pci_dt(phb, PHANDLE_XICP, fdt);
     }
 
@@ -760,7 +744,7 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,
     }
 
     /* Advertise NUMA via ibm,associativity */
-    ret = spapr_fixup_cpu_dt(fdt, spapr);
+    ret = spapr_fixup_cpu_dt(fdt, sm);
     if (ret < 0) {
         fprintf(stderr, "Couldn't finalize CPU device tree properties\n");
     }
@@ -789,8 +773,8 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,
         fdt_setprop_string(fdt, offset, "qemu,boot-device", boot_device);
     }
 
-    if (!spapr->has_graphics) {
-        spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
+    if (!sm->has_graphics) {
+        spapr_populate_chosen_stdout(fdt, sm->vio_bus);
     }
 
     _FDT((fdt_pack(fdt)));
@@ -830,7 +814,7 @@ static void emulate_spapr_hypercall(PowerPCCPU *cpu)
 #define CLEAN_HPTE(_hpte)  ((*(uint64_t *)(_hpte)) &= tswap64(~HPTE64_V_HPTE_DIRTY))
 #define DIRTY_HPTE(_hpte)  ((*(uint64_t *)(_hpte)) |= tswap64(HPTE64_V_HPTE_DIRTY))
 
-static void spapr_reset_htab(sPAPREnvironment *spapr)
+static void spapr_reset_htab(sPAPRMachineState *sm)
 {
     long shift;
     int index;
@@ -839,35 +823,35 @@ static void spapr_reset_htab(sPAPREnvironment *spapr)
      * later we should probably make it scale to the size of guest
      * RAM */
 
-    shift = kvmppc_reset_htab(spapr->htab_shift);
+    shift = kvmppc_reset_htab(sm->htab_shift);
 
     if (shift > 0) {
         /* Kernel handles htab, we don't need to allocate one */
-        spapr->htab_shift = shift;
+        sm->htab_shift = shift;
         kvmppc_kern_htab = true;
 
         /* Tell readers to update their file descriptor */
-        if (spapr->htab_fd >= 0) {
-            spapr->htab_fd_stale = true;
+        if (sm->htab_fd >= 0) {
+            sm->htab_fd_stale = true;
         }
     } else {
-        if (!spapr->htab) {
+        if (!sm->htab) {
             /* Allocate an htab if we don't yet have one */
-            spapr->htab = qemu_memalign(HTAB_SIZE(spapr), HTAB_SIZE(spapr));
+            sm->htab = qemu_memalign(HTAB_SIZE(sm), HTAB_SIZE(sm));
         }
 
         /* And clear it */
-        memset(spapr->htab, 0, HTAB_SIZE(spapr));
+        memset(sm->htab, 0, HTAB_SIZE(sm));
 
-        for (index = 0; index < HTAB_SIZE(spapr) / HASH_PTE_SIZE_64; index++) {
-            DIRTY_HPTE(HPTE(spapr->htab, index));
+        for (index = 0; index < HTAB_SIZE(sm) / HASH_PTE_SIZE_64; index++) {
+            DIRTY_HPTE(HPTE(sm->htab, index));
         }
     }
 
     /* Update the RMA size if necessary */
-    if (spapr->vrma_adjust) {
-        spapr->rma_size = kvmppc_rma_size(spapr_node0_size(),
-                                          spapr->htab_shift);
+    if (sm->vrma_adjust) {
+        sm->rma_size = kvmppc_rma_size(spapr_node0_size(),
+                                          sm->htab_shift);
     }
 }
 
@@ -889,22 +873,22 @@ static int find_unknown_sysbus_device(SysBusDevice *sbdev, void *opaque)
 }
 
 /*
- * A guest reset will cause spapr->htab_fd to become stale if being used.
+ * A guest reset will cause sm->htab_fd to become stale if being used.
  * Reopen the file descriptor to make sure the whole HTAB is properly read.
  */
-static int spapr_check_htab_fd(sPAPREnvironment *spapr)
+static int spapr_check_htab_fd(sPAPRMachineState *sm)
 {
     int rc = 0;
 
-    if (spapr->htab_fd_stale) {
-        close(spapr->htab_fd);
-        spapr->htab_fd = kvmppc_get_htab_fd(false);
-        if (spapr->htab_fd < 0) {
+    if (sm->htab_fd_stale) {
+        close(sm->htab_fd);
+        sm->htab_fd = kvmppc_get_htab_fd(false);
+        if (sm->htab_fd < 0) {
             error_report("Unable to open fd for reading hash table from KVM: "
                          "%s", strerror(errno));
             rc = -1;
         }
-        spapr->htab_fd_stale = false;
+        sm->htab_fd_stale = false;
     }
 
     return rc;
@@ -912,6 +896,7 @@ static int spapr_check_htab_fd(sPAPREnvironment *spapr)
 
 static void ppc_spapr_reset(void)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
     PowerPCCPU *first_ppc_cpu;
     uint32_t rtas_limit;
 
@@ -919,7 +904,7 @@ static void ppc_spapr_reset(void)
     foreach_dynamic_sysbus_device(find_unknown_sysbus_device, NULL);
 
     /* Reset the hash table & recalc the RMA */
-    spapr_reset_htab(spapr);
+    spapr_reset_htab(sm);
 
     qemu_devices_reset();
 
@@ -928,29 +913,28 @@ static void ppc_spapr_reset(void)
      * or just below 2GB, whichever is lowere, so that it can be
      * processed with 32-bit real mode code if necessary
      */
-    rtas_limit = MIN(spapr->rma_size, RTAS_MAX_ADDR);
-    spapr->rtas_addr = rtas_limit - RTAS_MAX_SIZE;
-    spapr->fdt_addr = spapr->rtas_addr - FDT_MAX_SIZE;
+    rtas_limit = MIN(sm->rma_size, RTAS_MAX_ADDR);
+    sm->rtas_addr = rtas_limit - RTAS_MAX_SIZE;
+    sm->fdt_addr = sm->rtas_addr - FDT_MAX_SIZE;
 
     /* Load the fdt */
-    spapr_finalize_fdt(spapr, spapr->fdt_addr, spapr->rtas_addr,
-                       spapr->rtas_size);
+    spapr_finalize_fdt(sm, sm->fdt_addr, sm->rtas_addr, sm->rtas_size);
 
     /* Copy RTAS over */
-    cpu_physical_memory_write(spapr->rtas_addr, spapr->rtas_blob,
-                              spapr->rtas_size);
+    cpu_physical_memory_write(sm->rtas_addr, sm->rtas_blob, sm->rtas_size);
 
     /* Set up the entry state */
     first_ppc_cpu = POWERPC_CPU(first_cpu);
-    first_ppc_cpu->env.gpr[3] = spapr->fdt_addr;
+    first_ppc_cpu->env.gpr[3] = sm->fdt_addr;
     first_ppc_cpu->env.gpr[5] = 0;
     first_cpu->halted = 0;
-    first_ppc_cpu->env.nip = spapr->entry_point;
+    first_ppc_cpu->env.nip = sm->entry_point;
 
 }
 
 static void spapr_cpu_reset(void *opaque)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
     PowerPCCPU *cpu = opaque;
     CPUState *cs = CPU(cpu);
     CPUPPCState *env = &cpu->env;
@@ -964,7 +948,7 @@ static void spapr_cpu_reset(void *opaque)
 
     env->spr[SPR_HIOR] = 0;
 
-    env->external_htab = (uint8_t *)spapr->htab;
+    env->external_htab = (uint8_t *)sm->htab;
     if (kvm_enabled() && !env->external_htab) {
         /*
          * HV KVM, set external_htab to 1 so our ppc_hash64_load_hpte*
@@ -979,14 +963,14 @@ static void spapr_cpu_reset(void *opaque)
      * We have 8 hpte per group, and each hpte is 16 bytes.
      * ie have 128 bytes per hpte entry.
      */
-    env->htab_mask = (1ULL << ((spapr)->htab_shift - 7)) - 1;
-    env->spr[SPR_SDR1] = (target_ulong)(uintptr_t)spapr->htab |
-        (spapr->htab_shift - 18);
+    env->htab_mask = (1ULL << (sm->htab_shift - 7)) - 1;
+    env->spr[SPR_SDR1] = (target_ulong)(uintptr_t)sm->htab |
+        (sm->htab_shift - 18);
 }
 
-static void spapr_create_nvram(sPAPREnvironment *spapr)
+static void spapr_create_nvram(sPAPRMachineState *sm)
 {
-    DeviceState *dev = qdev_create(&spapr->vio_bus->bus, "spapr-nvram");
+    DeviceState *dev = qdev_create(&sm->vio_bus->bus, "spapr-nvram");
     DriveInfo *dinfo = drive_get(IF_PFLASH, 0, 0);
 
     if (dinfo) {
@@ -995,18 +979,18 @@ static void spapr_create_nvram(sPAPREnvironment *spapr)
 
     qdev_init_nofail(dev);
 
-    spapr->nvram = (struct sPAPRNVRAM *)dev;
+    sm->nvram = (struct sPAPRNVRAM *)dev;
 }
 
-static void spapr_rtc_create(sPAPREnvironment *spapr)
+static void spapr_rtc_create(sPAPRMachineState *sm)
 {
     DeviceState *dev = qdev_create(NULL, TYPE_SPAPR_RTC);
 
     qdev_init_nofail(dev);
-    spapr->rtc = dev;
+    sm->rtc = dev;
 
     object_property_add_alias(qdev_get_machine(), "rtc-time",
-                              OBJECT(spapr->rtc), "date", NULL);
+                              OBJECT(sm->rtc), "date", NULL);
 }
 
 /* Returns whether we want to use VGA or not */
@@ -1028,7 +1012,7 @@ static int spapr_vga_init(PCIBus *pci_bus)
 
 static int spapr_post_load(void *opaque, int version_id)
 {
-    sPAPREnvironment *spapr = (sPAPREnvironment *)opaque;
+    sPAPRMachineState *sm = (sPAPRMachineState *)opaque;
     int err = 0;
 
     /* In earlier versions, there was no separate qdev for the PAPR
@@ -1036,7 +1020,7 @@ static int spapr_post_load(void *opaque, int version_id)
      * So when migrating from those versions, poke the incoming offset
      * value into the RTC device */
     if (version_id < 3) {
-        err = spapr_rtc_import_offset(spapr->rtc, spapr->rtc_offset);
+        err = spapr_rtc_import_offset(sm->rtc, sm->rtc_offset);
     }
 
     return err;
@@ -1057,29 +1041,29 @@ static const VMStateDescription vmstate_spapr = {
         VMSTATE_UNUSED_BUFFER(version_before_3, 0, 4),
 
         /* RTC offset */
-        VMSTATE_UINT64_TEST(rtc_offset, sPAPREnvironment, version_before_3),
+        VMSTATE_UINT64_TEST(rtc_offset, sPAPRMachineState, version_before_3),
 
-        VMSTATE_PPC_TIMEBASE_V(tb, sPAPREnvironment, 2),
+        VMSTATE_PPC_TIMEBASE_V(tb, sPAPRMachineState, 2),
         VMSTATE_END_OF_LIST()
     },
 };
 
 static int htab_save_setup(QEMUFile *f, void *opaque)
 {
-    sPAPREnvironment *spapr = opaque;
+    sPAPRMachineState *sm = opaque;
 
     /* "Iteration" header */
-    qemu_put_be32(f, spapr->htab_shift);
+    qemu_put_be32(f, sm->htab_shift);
 
-    if (spapr->htab) {
-        spapr->htab_save_index = 0;
-        spapr->htab_first_pass = true;
+    if (sm->htab) {
+        sm->htab_save_index = 0;
+        sm->htab_first_pass = true;
     } else {
         assert(kvm_enabled());
 
-        spapr->htab_fd = kvmppc_get_htab_fd(false);
-        spapr->htab_fd_stale = false;
-        if (spapr->htab_fd < 0) {
+        sm->htab_fd = kvmppc_get_htab_fd(false);
+        sm->htab_fd_stale = false;
+        if (sm->htab_fd < 0) {
             fprintf(stderr, "Unable to open fd for reading hash table from KVM: %s\n",
                     strerror(errno));
             return -1;
@@ -1090,31 +1074,31 @@ static int htab_save_setup(QEMUFile *f, void *opaque)
     return 0;
 }
 
-static void htab_save_first_pass(QEMUFile *f, sPAPREnvironment *spapr,
+static void htab_save_first_pass(QEMUFile *f, sPAPRMachineState *sm,
                                  int64_t max_ns)
 {
-    int htabslots = HTAB_SIZE(spapr) / HASH_PTE_SIZE_64;
-    int index = spapr->htab_save_index;
+    int htabslots = HTAB_SIZE(sm) / HASH_PTE_SIZE_64;
+    int index = sm->htab_save_index;
     int64_t starttime = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
 
-    assert(spapr->htab_first_pass);
+    assert(sm->htab_first_pass);
 
     do {
         int chunkstart;
 
         /* Consume invalid HPTEs */
         while ((index < htabslots)
-               && !HPTE_VALID(HPTE(spapr->htab, index))) {
+               && !HPTE_VALID(HPTE(sm->htab, index))) {
             index++;
-            CLEAN_HPTE(HPTE(spapr->htab, index));
+            CLEAN_HPTE(HPTE(sm->htab, index));
         }
 
         /* Consume valid HPTEs */
         chunkstart = index;
         while ((index < htabslots) && (index - chunkstart < USHRT_MAX)
-               && HPTE_VALID(HPTE(spapr->htab, index))) {
+               && HPTE_VALID(HPTE(sm->htab, index))) {
             index++;
-            CLEAN_HPTE(HPTE(spapr->htab, index));
+            CLEAN_HPTE(HPTE(sm->htab, index));
         }
 
         if (index > chunkstart) {
@@ -1123,7 +1107,7 @@ static void htab_save_first_pass(QEMUFile *f, sPAPREnvironment *spapr,
             qemu_put_be32(f, chunkstart);
             qemu_put_be16(f, n_valid);
             qemu_put_be16(f, 0);
-            qemu_put_buffer(f, HPTE(spapr->htab, chunkstart),
+            qemu_put_buffer(f, HPTE(sm->htab, chunkstart),
                             HASH_PTE_SIZE_64 * n_valid);
 
             if ((qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - starttime) > max_ns) {
@@ -1135,28 +1119,28 @@ static void htab_save_first_pass(QEMUFile *f, sPAPREnvironment *spapr,
     if (index >= htabslots) {
         assert(index == htabslots);
         index = 0;
-        spapr->htab_first_pass = false;
+        sm->htab_first_pass = false;
     }
-    spapr->htab_save_index = index;
+    sm->htab_save_index = index;
 }
 
-static int htab_save_later_pass(QEMUFile *f, sPAPREnvironment *spapr,
+static int htab_save_later_pass(QEMUFile *f, sPAPRMachineState *sm,
                                 int64_t max_ns)
 {
     bool final = max_ns < 0;
-    int htabslots = HTAB_SIZE(spapr) / HASH_PTE_SIZE_64;
+    int htabslots = HTAB_SIZE(sm) / HASH_PTE_SIZE_64;
     int examined = 0, sent = 0;
-    int index = spapr->htab_save_index;
+    int index = sm->htab_save_index;
     int64_t starttime = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
 
-    assert(!spapr->htab_first_pass);
+    assert(!sm->htab_first_pass);
 
     do {
         int chunkstart, invalidstart;
 
         /* Consume non-dirty HPTEs */
         while ((index < htabslots)
-               && !HPTE_DIRTY(HPTE(spapr->htab, index))) {
+               && !HPTE_DIRTY(HPTE(sm->htab, index))) {
             index++;
             examined++;
         }
@@ -1164,9 +1148,9 @@ static int htab_save_later_pass(QEMUFile *f, sPAPREnvironment *spapr,
         chunkstart = index;
         /* Consume valid dirty HPTEs */
         while ((index < htabslots) && (index - chunkstart < USHRT_MAX)
-               && HPTE_DIRTY(HPTE(spapr->htab, index))
-               && HPTE_VALID(HPTE(spapr->htab, index))) {
-            CLEAN_HPTE(HPTE(spapr->htab, index));
+               && HPTE_DIRTY(HPTE(sm->htab, index))
+               && HPTE_VALID(HPTE(sm->htab, index))) {
+            CLEAN_HPTE(HPTE(sm->htab, index));
             index++;
             examined++;
         }
@@ -1174,9 +1158,9 @@ static int htab_save_later_pass(QEMUFile *f, sPAPREnvironment *spapr,
         invalidstart = index;
         /* Consume invalid dirty HPTEs */
         while ((index < htabslots) && (index - invalidstart < USHRT_MAX)
-               && HPTE_DIRTY(HPTE(spapr->htab, index))
-               && !HPTE_VALID(HPTE(spapr->htab, index))) {
-            CLEAN_HPTE(HPTE(spapr->htab, index));
+               && HPTE_DIRTY(HPTE(sm->htab, index))
+               && !HPTE_VALID(HPTE(sm->htab, index))) {
+            CLEAN_HPTE(HPTE(sm->htab, index));
             index++;
             examined++;
         }
@@ -1188,7 +1172,7 @@ static int htab_save_later_pass(QEMUFile *f, sPAPREnvironment *spapr,
             qemu_put_be32(f, chunkstart);
             qemu_put_be16(f, n_valid);
             qemu_put_be16(f, n_invalid);
-            qemu_put_buffer(f, HPTE(spapr->htab, chunkstart),
+            qemu_put_buffer(f, HPTE(sm->htab, chunkstart),
                             HASH_PTE_SIZE_64 * n_valid);
             sent += index - chunkstart;
 
@@ -1212,7 +1196,7 @@ static int htab_save_later_pass(QEMUFile *f, sPAPREnvironment *spapr,
         index = 0;
     }
 
-    spapr->htab_save_index = index;
+    sm->htab_save_index = index;
 
     return (examined >= htabslots) && (sent == 0) ? 1 : 0;
 }
@@ -1222,29 +1206,29 @@ static int htab_save_later_pass(QEMUFile *f, sPAPREnvironment *spapr,
 
 static int htab_save_iterate(QEMUFile *f, void *opaque)
 {
-    sPAPREnvironment *spapr = opaque;
+    sPAPRMachineState *sm = opaque;
     int rc = 0;
 
     /* Iteration header */
     qemu_put_be32(f, 0);
 
-    if (!spapr->htab) {
+    if (!sm->htab) {
         assert(kvm_enabled());
 
-        rc = spapr_check_htab_fd(spapr);
+        rc = spapr_check_htab_fd(sm);
         if (rc < 0) {
             return rc;
         }
 
-        rc = kvmppc_save_htab(f, spapr->htab_fd,
+        rc = kvmppc_save_htab(f, sm->htab_fd,
                               MAX_KVM_BUF_SIZE, MAX_ITERATION_NS);
         if (rc < 0) {
             return rc;
         }
-    } else  if (spapr->htab_first_pass) {
-        htab_save_first_pass(f, spapr, MAX_ITERATION_NS);
+    } else  if (sm->htab_first_pass) {
+        htab_save_first_pass(f, sm, MAX_ITERATION_NS);
     } else {
-        rc = htab_save_later_pass(f, spapr, MAX_ITERATION_NS);
+        rc = htab_save_later_pass(f, sm, MAX_ITERATION_NS);
     }
 
     /* End marker */
@@ -1257,29 +1241,29 @@ static int htab_save_iterate(QEMUFile *f, void *opaque)
 
 static int htab_save_complete(QEMUFile *f, void *opaque)
 {
-    sPAPREnvironment *spapr = opaque;
+    sPAPRMachineState *sm = opaque;
 
     /* Iteration header */
     qemu_put_be32(f, 0);
 
-    if (!spapr->htab) {
+    if (!sm->htab) {
         int rc;
 
         assert(kvm_enabled());
 
-        rc = spapr_check_htab_fd(spapr);
+        rc = spapr_check_htab_fd(sm);
         if (rc < 0) {
             return rc;
         }
 
-        rc = kvmppc_save_htab(f, spapr->htab_fd, MAX_KVM_BUF_SIZE, -1);
+        rc = kvmppc_save_htab(f, sm->htab_fd, MAX_KVM_BUF_SIZE, -1);
         if (rc < 0) {
             return rc;
         }
-        close(spapr->htab_fd);
-        spapr->htab_fd = -1;
+        close(sm->htab_fd);
+        sm->htab_fd = -1;
     } else {
-        htab_save_later_pass(f, spapr, -1);
+        htab_save_later_pass(f, sm, -1);
     }
 
     /* End marker */
@@ -1292,7 +1276,7 @@ static int htab_save_complete(QEMUFile *f, void *opaque)
 
 static int htab_load(QEMUFile *f, void *opaque, int version_id)
 {
-    sPAPREnvironment *spapr = opaque;
+    sPAPRMachineState *sm = opaque;
     uint32_t section_hdr;
     int fd = -1;
 
@@ -1305,13 +1289,13 @@ static int htab_load(QEMUFile *f, void *opaque, int version_id)
 
     if (section_hdr) {
         /* First section, just the hash shift */
-        if (spapr->htab_shift != section_hdr) {
+        if (sm->htab_shift != section_hdr) {
             return -EINVAL;
         }
         return 0;
     }
 
-    if (!spapr->htab) {
+    if (!sm->htab) {
         assert(kvm_enabled());
 
         fd = kvmppc_get_htab_fd(true);
@@ -1335,21 +1319,21 @@ static int htab_load(QEMUFile *f, void *opaque, int version_id)
         }
 
         if ((index + n_valid + n_invalid) >
-            (HTAB_SIZE(spapr) / HASH_PTE_SIZE_64)) {
+            (HTAB_SIZE(sm) / HASH_PTE_SIZE_64)) {
             /* Bad index in stream */
             fprintf(stderr, "htab_load() bad index %d (%hd+%hd entries) "
                     "in htab stream (htab_shift=%d)\n", index, n_valid, n_invalid,
-                    spapr->htab_shift);
+                    sm->htab_shift);
             return -EINVAL;
         }
 
-        if (spapr->htab) {
+        if (sm->htab) {
             if (n_valid) {
-                qemu_get_buffer(f, HPTE(spapr->htab, index),
+                qemu_get_buffer(f, HPTE(sm->htab, index),
                                 HASH_PTE_SIZE_64 * n_valid);
             }
             if (n_invalid) {
-                memset(HPTE(spapr->htab, index + n_valid), 0,
+                memset(HPTE(sm->htab, index + n_valid), 0,
                        HASH_PTE_SIZE_64 * n_invalid);
             }
         } else {
@@ -1364,7 +1348,7 @@ static int htab_load(QEMUFile *f, void *opaque, int version_id)
         }
     }
 
-    if (!spapr->htab) {
+    if (!sm->htab) {
         assert(fd >= 0);
         close(fd);
     }
@@ -1389,6 +1373,7 @@ static void spapr_boot_set(void *opaque, const char *boot_device,
 /* pSeries LPAR / sPAPR hardware init */
 static void ppc_spapr_init(MachineState *machine)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(machine);
     ram_addr_t ram_size = machine->ram_size;
     const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
@@ -1412,8 +1397,7 @@ static void ppc_spapr_init(MachineState *machine)
 
     msi_supported = true;
 
-    spapr = g_malloc0(sizeof(*spapr));
-    QLIST_INIT(&spapr->phbs);
+    QLIST_INIT(&sm->phbs);
 
     cpu_ppc_hypercall = emulate_spapr_hypercall;
 
@@ -1426,9 +1410,9 @@ static void ppc_spapr_init(MachineState *machine)
     }
 
     if (rma_alloc_size && (rma_alloc_size < node0_size)) {
-        spapr->rma_size = rma_alloc_size;
+        sm->rma_size = rma_alloc_size;
     } else {
-        spapr->rma_size = node0_size;
+        sm->rma_size = node0_size;
 
         /* With KVM, we don't actually know whether KVM supports an
          * unbounded RMA (PR KVM) or is limited by the hash table size
@@ -1440,33 +1424,33 @@ static void ppc_spapr_init(MachineState *machine)
          * isn't determined yet.
          */
         if (kvm_enabled()) {
-            spapr->vrma_adjust = 1;
-            spapr->rma_size = MIN(spapr->rma_size, 0x10000000);
+            sm->vrma_adjust = 1;
+            sm->rma_size = MIN(sm->rma_size, 0x10000000);
         }
     }
 
-    if (spapr->rma_size > node0_size) {
+    if (sm->rma_size > node0_size) {
         fprintf(stderr, "Error: Numa node 0 has to span the RMA (%#08"HWADDR_PRIx")\n",
-                spapr->rma_size);
+                sm->rma_size);
         exit(1);
     }
 
     /* Setup a load limit for the ramdisk leaving room for SLOF and FDT */
-    load_limit = MIN(spapr->rma_size, RTAS_MAX_ADDR) - FW_OVERHEAD;
+    load_limit = MIN(sm->rma_size, RTAS_MAX_ADDR) - FW_OVERHEAD;
 
     /* We aim for a hash table of size 1/128 the size of RAM.  The
      * normal rule of thumb is 1/64 the size of RAM, but that's much
      * more than needed for the Linux guests we support. */
-    spapr->htab_shift = 18; /* Minimum architected size */
-    while (spapr->htab_shift <= 46) {
-        if ((1ULL << (spapr->htab_shift + 7)) >= ram_size) {
+    sm->htab_shift = 18; /* Minimum architected size */
+    while (sm->htab_shift <= 46) {
+        if ((1ULL << (sm->htab_shift + 7)) >= ram_size) {
             break;
         }
-        spapr->htab_shift++;
+        sm->htab_shift++;
     }
 
     /* Set up Interrupt Controller before we create the VCPUs */
-    spapr->icp = xics_system_init(machine,
+    sm->icp = xics_system_init(machine,
                                   smp_cpus * kvmppc_smt_threads() / smp_threads,
                                   XICS_IRQS);
 
@@ -1501,7 +1485,7 @@ static void ppc_spapr_init(MachineState *machine)
             }
         }
 
-        xics_cpu_setup(spapr->icp, cpu);
+        xics_cpu_setup(sm->icp, cpu);
 
         qemu_register_reset(spapr_cpu_reset, cpu);
     }
@@ -1512,9 +1496,9 @@ static void ppc_spapr_init(MachineState *machine)
     }
 
     /* allocate RAM */
-    spapr->ram_limit = ram_size;
+    sm->ram_limit = ram_size;
     memory_region_allocate_system_memory(ram, NULL, "ppc_spapr.ram",
-                                         spapr->ram_limit);
+                                         sm->ram_limit);
     memory_region_add_subregion(sysmem, 0, ram);
 
     if (rma_alloc_size && rma) {
@@ -1530,41 +1514,41 @@ static void ppc_spapr_init(MachineState *machine)
         error_report("Could not find LPAR rtas '%s'", "spapr-rtas.bin");
         exit(1);
     }
-    spapr->rtas_size = get_image_size(filename);
-    spapr->rtas_blob = g_malloc(spapr->rtas_size);
-    if (load_image_size(filename, spapr->rtas_blob, spapr->rtas_size) < 0) {
+    sm->rtas_size = get_image_size(filename);
+    sm->rtas_blob = g_malloc(sm->rtas_size);
+    if (load_image_size(filename, sm->rtas_blob, sm->rtas_size) < 0) {
         error_report("Could not load LPAR rtas '%s'", filename);
         exit(1);
     }
-    if (spapr->rtas_size > RTAS_MAX_SIZE) {
+    if (sm->rtas_size > RTAS_MAX_SIZE) {
         error_report("RTAS too big ! 0x%zx bytes (max is 0x%x)",
-                     (size_t)spapr->rtas_size, RTAS_MAX_SIZE);
+                     (size_t)sm->rtas_size, RTAS_MAX_SIZE);
         exit(1);
     }
     g_free(filename);
 
     /* Set up EPOW events infrastructure */
-    spapr_events_init(spapr);
+    spapr_events_init(sm);
 
     /* Set up the RTC RTAS interfaces */
-    spapr_rtc_create(spapr);
+    spapr_rtc_create(sm);
 
     /* Set up VIO bus */
-    spapr->vio_bus = spapr_vio_bus_init();
+    sm->vio_bus = spapr_vio_bus_init();
 
     for (i = 0; i < MAX_SERIAL_PORTS; i++) {
         if (serial_hds[i]) {
-            spapr_vty_create(spapr->vio_bus, serial_hds[i]);
+            spapr_vty_create(sm->vio_bus, serial_hds[i]);
         }
     }
 
     /* We always have at least the nvram device on VIO */
-    spapr_create_nvram(spapr);
+    spapr_create_nvram(sm);
 
     /* Set up PCI */
     spapr_pci_rtas_init();
 
-    phb = spapr_create_phb(spapr, 0);
+    phb = spapr_create_phb(sm, 0);
 
     for (i = 0; i < nb_nics; i++) {
         NICInfo *nd = &nd_table[i];
@@ -1574,26 +1558,26 @@ static void ppc_spapr_init(MachineState *machine)
         }
 
         if (strcmp(nd->model, "ibmveth") == 0) {
-            spapr_vlan_create(spapr->vio_bus, nd);
+            spapr_vlan_create(sm->vio_bus, nd);
         } else {
             pci_nic_init_nofail(&nd_table[i], phb->bus, nd->model, NULL);
         }
     }
 
     for (i = 0; i <= drive_get_max_bus(IF_SCSI); i++) {
-        spapr_vscsi_create(spapr->vio_bus);
+        spapr_vscsi_create(sm->vio_bus);
     }
 
     /* Graphics */
     if (spapr_vga_init(phb->bus)) {
-        spapr->has_graphics = true;
+        sm->has_graphics = true;
         machine->usb |= defaults_enabled() && !machine->usb_disabled;
     }
 
     if (machine->usb) {
         pci_create_simple(phb->bus, -1, "pci-ohci");
 
-        if (spapr->has_graphics) {
+        if (sm->has_graphics) {
             USBBus *usb_bus = usb_bus_find(-1);
 
             usb_create_simple(usb_bus, "usb-kbd");
@@ -1601,7 +1585,7 @@ static void ppc_spapr_init(MachineState *machine)
         }
     }
 
-    if (spapr->rma_size < (MIN_RMA_SLOF << 20)) {
+    if (sm->rma_size < (MIN_RMA_SLOF << 20)) {
         fprintf(stderr, "qemu: pSeries SLOF firmware requires >= "
                 "%ldM guest RMA (Real Mode Area memory)\n", MIN_RMA_SLOF);
         exit(1);
@@ -1658,24 +1642,27 @@ static void ppc_spapr_init(MachineState *machine)
     }
     g_free(filename);
 
-    spapr->entry_point = 0x100;
+    sm->entry_point = 0x100;
 
-    vmstate_register(NULL, 0, &vmstate_spapr, spapr);
+    /* FIXME: Should register thigs through the MachineState's qdev
+     * interface, this is a legacy from the sPAPREnvironment structure
+     * which predated MachineState but had a similar function */
+    vmstate_register(NULL, 0, &vmstate_spapr, sm);
     register_savevm_live(NULL, "spapr/htab", -1, 1,
-                         &savevm_htab_handlers, spapr);
+                         &savevm_htab_handlers, sm);
 
     /* Prepare the device tree */
-    spapr->fdt_skel = spapr_create_fdt_skel(initrd_base, initrd_size,
+    sm->fdt_skel = spapr_create_fdt_skel(initrd_base, initrd_size,
                                             kernel_size, kernel_le,
                                             kernel_cmdline,
-                                            spapr->check_exception_irq);
-    assert(spapr->fdt_skel != NULL);
+                                            sm->check_exception_irq);
+    assert(sm->fdt_skel != NULL);
 
     /* used by RTAS */
-    QTAILQ_INIT(&spapr->ccs_list);
-    qemu_register_reset(spapr_ccs_reset_hook, spapr);
+    QTAILQ_INIT(&sm->ccs_list);
+    qemu_register_reset(spapr_ccs_reset_hook, sm);
 
-    qemu_register_boot_set(spapr_boot_set, spapr);
+    qemu_register_boot_set(spapr_boot_set, sm);
 }
 
 static int spapr_kvm_type(const char *vm_type)
diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c
index fda9e35..82c5458 100644
--- a/hw/ppc/spapr_events.c
+++ b/hw/ppc/spapr_events.c
@@ -238,18 +238,20 @@ void spapr_events_fdt_skel(void *fdt, uint32_t check_exception_irq)
 
 static void rtas_event_log_queue(int log_type, void *data, bool exception)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
     sPAPREventLogEntry *entry = g_new(sPAPREventLogEntry, 1);
 
     g_assert(data);
     entry->log_type = log_type;
     entry->exception = exception;
     entry->data = data;
-    QTAILQ_INSERT_TAIL(&spapr->pending_events, entry, next);
+    QTAILQ_INSERT_TAIL(&sm->pending_events, entry, next);
 }
 
 static sPAPREventLogEntry *rtas_event_log_dequeue(uint32_t event_mask,
                                                   bool exception)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
     sPAPREventLogEntry *entry = NULL;
 
     /* we only queue EPOW events atm. */
@@ -257,7 +259,7 @@ static sPAPREventLogEntry *rtas_event_log_dequeue(uint32_t event_mask,
         return NULL;
     }
 
-    QTAILQ_FOREACH(entry, &spapr->pending_events, next) {
+    QTAILQ_FOREACH(entry, &sm->pending_events, next) {
         if (entry->exception != exception) {
             continue;
         }
@@ -270,7 +272,7 @@ static sPAPREventLogEntry *rtas_event_log_dequeue(uint32_t event_mask,
     }
 
     if (entry) {
-        QTAILQ_REMOVE(&spapr->pending_events, entry, next);
+        QTAILQ_REMOVE(&sm->pending_events, entry, next);
     }
 
     return entry;
@@ -278,6 +280,7 @@ static sPAPREventLogEntry *rtas_event_log_dequeue(uint32_t event_mask,
 
 static bool rtas_event_log_contains(uint32_t event_mask, bool exception)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
     sPAPREventLogEntry *entry = NULL;
 
     /* we only queue EPOW events atm. */
@@ -285,7 +288,7 @@ static bool rtas_event_log_contains(uint32_t event_mask, bool exception)
         return false;
     }
 
-    QTAILQ_FOREACH(entry, &spapr->pending_events, next) {
+    QTAILQ_FOREACH(entry, &sm->pending_events, next) {
         if (entry->exception != exception) {
             continue;
         }
@@ -314,13 +317,14 @@ static void spapr_init_v6hdr(struct rtas_event_log_v6 *v6hdr)
 static void spapr_init_maina(struct rtas_event_log_v6_maina *maina,
                              int section_count)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
     struct tm tm;
     int year;
 
     maina->hdr.section_id = cpu_to_be16(RTAS_LOG_V6_SECTION_ID_MAINA);
     maina->hdr.section_length = cpu_to_be16(sizeof(*maina));
     /* FIXME: section version, subtype and creator id? */
-    spapr_rtc_read(spapr->rtc, &tm, NULL);
+    spapr_rtc_read(sm->rtc, &tm, NULL);
     year = tm.tm_year + 1900;
     maina->creation_date = cpu_to_be32((to_bcd(year / 100) << 24)
                                        | (to_bcd(year % 100) << 16)
@@ -336,7 +340,7 @@ static void spapr_init_maina(struct rtas_event_log_v6_maina *maina,
 
 static void spapr_powerdown_req(Notifier *n, void *opaque)
 {
-    sPAPREnvironment *spapr = container_of(n, sPAPREnvironment, epow_notifier);
+    sPAPRMachineState *sm = container_of(n, sPAPRMachineState, epow_notifier);
     struct rtas_error_log *hdr;
     struct rtas_event_log_v6 *v6hdr;
     struct rtas_event_log_v6_maina *maina;
@@ -379,11 +383,12 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)
 
     rtas_event_log_queue(RTAS_LOG_TYPE_EPOW, new_epow, true);
 
-    qemu_irq_pulse(xics_get_qirq(spapr->icp, spapr->check_exception_irq));
+    qemu_irq_pulse(xics_get_qirq(sm->icp, sm->check_exception_irq));
 }
 
 static void spapr_hotplug_req_event(sPAPRDRConnector *drc, uint8_t hp_action)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
     struct hp_log_full *new_hp;
     struct rtas_error_log *hdr;
     struct rtas_event_log_v6 *v6hdr;
@@ -440,7 +445,7 @@ static void spapr_hotplug_req_event(sPAPRDRConnector *drc, uint8_t hp_action)
 
     rtas_event_log_queue(RTAS_LOG_TYPE_HOTPLUG, new_hp, true);
 
-    qemu_irq_pulse(xics_get_qirq(spapr->icp, spapr->check_exception_irq));
+    qemu_irq_pulse(xics_get_qirq(sm->icp, sm->check_exception_irq));
 }
 
 void spapr_hotplug_req_add_event(sPAPRDRConnector *drc)
@@ -453,7 +458,7 @@ void spapr_hotplug_req_remove_event(sPAPRDRConnector *drc)
     spapr_hotplug_req_event(drc, RTAS_LOG_V6_HP_ACTION_REMOVE);
 }
 
-static void check_exception(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void check_exception(PowerPCCPU *cpu, sPAPRMachineState *sm,
                             uint32_t token, uint32_t nargs,
                             target_ulong args,
                             uint32_t nret, target_ulong rets)
@@ -499,7 +504,7 @@ static void check_exception(PowerPCCPU *cpu, sPAPREnvironment *spapr,
      * interrupts.
      */
     if (rtas_event_log_contains(mask, true)) {
-        qemu_irq_pulse(xics_get_qirq(spapr->icp, spapr->check_exception_irq));
+        qemu_irq_pulse(xics_get_qirq(sm->icp, sm->check_exception_irq));
     }
 
     return;
@@ -508,7 +513,7 @@ out_no_events:
     rtas_st(rets, 0, RTAS_OUT_NO_ERRORS_FOUND);
 }
 
-static void event_scan(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void event_scan(PowerPCCPU *cpu, sPAPRMachineState *sm,
                        uint32_t token, uint32_t nargs,
                        target_ulong args,
                        uint32_t nret, target_ulong rets)
@@ -548,12 +553,12 @@ out_no_events:
     rtas_st(rets, 0, RTAS_OUT_NO_ERRORS_FOUND);
 }
 
-void spapr_events_init(sPAPREnvironment *spapr)
+void spapr_events_init(sPAPRMachineState *sm)
 {
-    QTAILQ_INIT(&spapr->pending_events);
-    spapr->check_exception_irq = xics_alloc(spapr->icp, 0, 0, false);
-    spapr->epow_notifier.notify = spapr_powerdown_req;
-    qemu_register_powerdown_notifier(&spapr->epow_notifier);
+    QTAILQ_INIT(&sm->pending_events);
+    sm->check_exception_irq = xics_alloc(sm->icp, 0, 0, false);
+    sm->epow_notifier.notify = spapr_powerdown_req;
+    qemu_register_powerdown_notifier(&sm->epow_notifier);
     spapr_rtas_register(RTAS_CHECK_EXCEPTION, "check-exception",
                         check_exception);
     spapr_rtas_register(RTAS_EVENT_SCAN, "event-scan", event_scan);
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 4f76f1c..bf4b05a 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -84,7 +84,7 @@ static inline bool valid_pte_index(CPUPPCState *env, target_ulong pte_index)
     return true;
 }
 
-static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_enter(PowerPCCPU *cpu, sPAPRMachineState *sm,
                             target_ulong opcode, target_ulong *args)
 {
     CPUPPCState *env = &cpu->env;
@@ -118,7 +118,7 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr,
 
     raddr = (ptel & HPTE64_R_RPN) & ~((1ULL << page_shift) - 1);
 
-    if (raddr < spapr->ram_limit) {
+    if (raddr < sm->ram_limit) {
         /* Regular RAM - should have WIMG=0010 */
         if ((ptel & HPTE64_R_WIMG) != HPTE64_R_M) {
             return H_PARAMETER;
@@ -205,7 +205,7 @@ static RemoveResult remove_hpte(CPUPPCState *env, target_ulong ptex,
     return REMOVE_SUCCESS;
 }
 
-static target_ulong h_remove(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_remove(PowerPCCPU *cpu, sPAPRMachineState *sm,
                              target_ulong opcode, target_ulong *args)
 {
     CPUPPCState *env = &cpu->env;
@@ -252,7 +252,7 @@ static target_ulong h_remove(PowerPCCPU *cpu, sPAPREnvironment *spapr,
 
 #define H_BULK_REMOVE_MAX_BATCH        4
 
-static target_ulong h_bulk_remove(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_bulk_remove(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                   target_ulong opcode, target_ulong *args)
 {
     CPUPPCState *env = &cpu->env;
@@ -299,7 +299,7 @@ static target_ulong h_bulk_remove(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_protect(PowerPCCPU *cpu, sPAPRMachineState *sm,
                               target_ulong opcode, target_ulong *args)
 {
     CPUPPCState *env = &cpu->env;
@@ -337,7 +337,7 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-static target_ulong h_read(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_read(PowerPCCPU *cpu, sPAPRMachineState *sm,
                            target_ulong opcode, target_ulong *args)
 {
     CPUPPCState *env = &cpu->env;
@@ -367,7 +367,7 @@ static target_ulong h_read(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-static target_ulong h_set_dabr(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_set_dabr(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                target_ulong opcode, target_ulong *args)
 {
     /* FIXME: actually implement this */
@@ -506,7 +506,7 @@ static target_ulong deregister_dtl(CPUPPCState *env, target_ulong addr)
     return H_SUCCESS;
 }
 
-static target_ulong h_register_vpa(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_register_vpa(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                    target_ulong opcode, target_ulong *args)
 {
     target_ulong flags = args[0];
@@ -551,7 +551,7 @@ static target_ulong h_register_vpa(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return ret;
 }
 
-static target_ulong h_cede(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_cede(PowerPCCPU *cpu, sPAPRMachineState *sm,
                            target_ulong opcode, target_ulong *args)
 {
     CPUPPCState *env = &cpu->env;
@@ -567,7 +567,7 @@ static target_ulong h_cede(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-static target_ulong h_rtas(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_rtas(PowerPCCPU *cpu, sPAPRMachineState *sm,
                            target_ulong opcode, target_ulong *args)
 {
     target_ulong rtas_r3 = args[0];
@@ -575,11 +575,11 @@ static target_ulong h_rtas(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     uint32_t nargs = rtas_ld(rtas_r3, 1);
     uint32_t nret = rtas_ld(rtas_r3, 2);
 
-    return spapr_rtas_call(cpu, spapr, token, nargs, rtas_r3 + 12,
+    return spapr_rtas_call(cpu, sm, token, nargs, rtas_r3 + 12,
                            nret, rtas_r3 + 12 + 4*nargs);
 }
 
-static target_ulong h_logical_load(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_logical_load(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                    target_ulong opcode, target_ulong *args)
 {
     CPUState *cs = CPU(cpu);
@@ -603,7 +603,7 @@ static target_ulong h_logical_load(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_PARAMETER;
 }
 
-static target_ulong h_logical_store(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_logical_store(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                     target_ulong opcode, target_ulong *args)
 {
     CPUState *cs = CPU(cpu);
@@ -629,7 +629,7 @@ static target_ulong h_logical_store(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_PARAMETER;
 }
 
-static target_ulong h_logical_memop(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_logical_memop(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                     target_ulong opcode, target_ulong *args)
 {
     CPUState *cs = CPU(cpu);
@@ -698,14 +698,14 @@ static target_ulong h_logical_memop(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-static target_ulong h_logical_icbi(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_logical_icbi(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                    target_ulong opcode, target_ulong *args)
 {
     /* Nothing to do on emulation, KVM will trap this in the kernel */
     return H_SUCCESS;
 }
 
-static target_ulong h_logical_dcbf(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_logical_dcbf(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                    target_ulong opcode, target_ulong *args)
 {
     /* Nothing to do on emulation, KVM will trap this in the kernel */
@@ -788,7 +788,7 @@ static target_ulong h_set_mode_resource_addr_trans_mode(PowerPCCPU *cpu,
     return H_SUCCESS;
 }
 
-static target_ulong h_set_mode(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_set_mode(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                target_ulong opcode, target_ulong *args)
 {
     target_ulong resource = args[1];
@@ -828,7 +828,7 @@ static void do_set_compat(void *arg)
     ((cpuver) == CPU_POWERPC_LOGICAL_2_07) ? 2070 : 0)
 
 static target_ulong h_client_architecture_support(PowerPCCPU *cpu_,
-                                                  sPAPREnvironment *spapr,
+                                                  sPAPRMachineState *sm,
                                                   target_ulong opcode,
                                                   target_ulong *args)
 {
@@ -921,7 +921,7 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu_,
         return H_SUCCESS;
     }
 
-    if (spapr_h_cas_compose_response(args[1], args[2])) {
+    if (spapr_h_cas_compose_response(sm, args[1], args[2])) {
         qemu_system_reset_request();
     }
 
@@ -952,19 +952,21 @@ void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn)
 target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,
                              target_ulong *args)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
+
     if ((opcode <= MAX_HCALL_OPCODE)
         && ((opcode & 0x3) == 0)) {
         spapr_hcall_fn fn = papr_hypercall_table[opcode / 4];
 
         if (fn) {
-            return fn(cpu, spapr, opcode, args);
+            return fn(cpu, sm, opcode, args);
         }
     } else if ((opcode >= KVMPPC_HCALL_BASE) &&
                (opcode <= KVMPPC_HCALL_MAX)) {
         spapr_hcall_fn fn = kvmppc_hypercall_table[opcode - KVMPPC_HCALL_BASE];
 
         if (fn) {
-            return fn(cpu, spapr, opcode, args);
+            return fn(cpu, sm, opcode, args);
         }
     }
 
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index 8cd9dba..5fe90c5 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -240,7 +240,7 @@ static target_ulong put_tce_emu(sPAPRTCETable *tcet, target_ulong ioba,
 }
 
 static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
-                                       sPAPREnvironment *spapr,
+                                       sPAPRMachineState *sm,
                                        target_ulong opcode, target_ulong *args)
 {
     int i;
@@ -287,7 +287,7 @@ static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
     return ret;
 }
 
-static target_ulong h_stuff_tce(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_stuff_tce(PowerPCCPU *cpu, sPAPRMachineState *sm,
                               target_ulong opcode, target_ulong *args)
 {
     int i;
@@ -326,7 +326,7 @@ static target_ulong h_stuff_tce(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return ret;
 }
 
-static target_ulong h_put_tce(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_put_tce(PowerPCCPU *cpu, sPAPRMachineState *sm,
                               target_ulong opcode, target_ulong *args)
 {
     target_ulong liobn = args[0];
@@ -367,7 +367,7 @@ static target_ulong get_tce_emu(sPAPRTCETable *tcet, target_ulong ioba,
     return H_SUCCESS;
 }
 
-static target_ulong h_get_tce(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_get_tce(PowerPCCPU *cpu, sPAPRMachineState *sm,
                               target_ulong opcode, target_ulong *args)
 {
     target_ulong liobn = args[0];
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 4df3a33..b6b5065 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -58,11 +58,11 @@
         }                                                          \
     } while (0)
 
-sPAPRPHBState *spapr_pci_find_phb(sPAPREnvironment *spapr, uint64_t buid)
+sPAPRPHBState *spapr_pci_find_phb(sPAPRMachineState *sm, uint64_t buid)
 {
     sPAPRPHBState *sphb;
 
-    QLIST_FOREACH(sphb, &spapr->phbs, list) {
+    QLIST_FOREACH(sphb, &sm->phbs, list) {
         if (sphb->buid != buid) {
             continue;
         }
@@ -72,10 +72,10 @@ sPAPRPHBState *spapr_pci_find_phb(sPAPREnvironment *spapr, uint64_t buid)
     return NULL;
 }
 
-PCIDevice *spapr_pci_find_dev(sPAPREnvironment *spapr, uint64_t buid,
+PCIDevice *spapr_pci_find_dev(sPAPRMachineState *sm, uint64_t buid,
                               uint32_t config_addr)
 {
-    sPAPRPHBState *sphb = spapr_pci_find_phb(spapr, buid);
+    sPAPRPHBState *sphb = spapr_pci_find_phb(sm, buid);
     PCIHostState *phb = PCI_HOST_BRIDGE(sphb);
     int bus_num = (config_addr >> 16) & 0xFF;
     int devfn = (config_addr >> 8) & 0xFF;
@@ -93,7 +93,7 @@ static uint32_t rtas_pci_cfgaddr(uint32_t arg)
     return ((arg >> 20) & 0xf00) | (arg & 0xff);
 }
 
-static void finish_read_pci_config(sPAPREnvironment *spapr, uint64_t buid,
+static void finish_read_pci_config(sPAPRMachineState *sm, uint64_t buid,
                                    uint32_t addr, uint32_t size,
                                    target_ulong rets)
 {
@@ -106,7 +106,7 @@ static void finish_read_pci_config(sPAPREnvironment *spapr, uint64_t buid,
         return;
     }
 
-    pci_dev = spapr_pci_find_dev(spapr, buid, addr);
+    pci_dev = spapr_pci_find_dev(sm, buid, addr);
     addr = rtas_pci_cfgaddr(addr);
 
     if (!pci_dev || (addr % size) || (addr >= pci_config_size(pci_dev))) {
@@ -123,7 +123,7 @@ static void finish_read_pci_config(sPAPREnvironment *spapr, uint64_t buid,
     rtas_st(rets, 1, val);
 }
 
-static void rtas_ibm_read_pci_config(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_ibm_read_pci_config(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                      uint32_t token, uint32_t nargs,
                                      target_ulong args,
                                      uint32_t nret, target_ulong rets)
@@ -140,10 +140,10 @@ static void rtas_ibm_read_pci_config(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     size = rtas_ld(args, 3);
     addr = rtas_ld(args, 0);
 
-    finish_read_pci_config(spapr, buid, addr, size, rets);
+    finish_read_pci_config(sm, buid, addr, size, rets);
 }
 
-static void rtas_read_pci_config(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_read_pci_config(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                  uint32_t token, uint32_t nargs,
                                  target_ulong args,
                                  uint32_t nret, target_ulong rets)
@@ -158,10 +158,10 @@ static void rtas_read_pci_config(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     size = rtas_ld(args, 1);
     addr = rtas_ld(args, 0);
 
-    finish_read_pci_config(spapr, 0, addr, size, rets);
+    finish_read_pci_config(sm, 0, addr, size, rets);
 }
 
-static void finish_write_pci_config(sPAPREnvironment *spapr, uint64_t buid,
+static void finish_write_pci_config(sPAPRMachineState *sm, uint64_t buid,
                                     uint32_t addr, uint32_t size,
                                     uint32_t val, target_ulong rets)
 {
@@ -173,7 +173,7 @@ static void finish_write_pci_config(sPAPREnvironment *spapr, uint64_t buid,
         return;
     }
 
-    pci_dev = spapr_pci_find_dev(spapr, buid, addr);
+    pci_dev = spapr_pci_find_dev(sm, buid, addr);
     addr = rtas_pci_cfgaddr(addr);
 
     if (!pci_dev || (addr % size) || (addr >= pci_config_size(pci_dev))) {
@@ -189,7 +189,7 @@ static void finish_write_pci_config(sPAPREnvironment *spapr, uint64_t buid,
     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
 }
 
-static void rtas_ibm_write_pci_config(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_ibm_write_pci_config(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                       uint32_t token, uint32_t nargs,
                                       target_ulong args,
                                       uint32_t nret, target_ulong rets)
@@ -207,10 +207,10 @@ static void rtas_ibm_write_pci_config(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     size = rtas_ld(args, 3);
     addr = rtas_ld(args, 0);
 
-    finish_write_pci_config(spapr, buid, addr, size, val, rets);
+    finish_write_pci_config(sm, buid, addr, size, val, rets);
 }
 
-static void rtas_write_pci_config(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_write_pci_config(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                   uint32_t token, uint32_t nargs,
                                   target_ulong args,
                                   uint32_t nret, target_ulong rets)
@@ -227,7 +227,7 @@ static void rtas_write_pci_config(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     size = rtas_ld(args, 1);
     addr = rtas_ld(args, 0);
 
-    finish_write_pci_config(spapr, 0, addr, size, val, rets);
+    finish_write_pci_config(sm, 0, addr, size, val, rets);
 }
 
 /*
@@ -259,7 +259,7 @@ static void spapr_msi_setmsg(PCIDevice *pdev, hwaddr addr, bool msix,
     }
 }
 
-static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                 uint32_t token, uint32_t nargs,
                                 target_ulong args, uint32_t nret,
                                 target_ulong rets)
@@ -291,9 +291,9 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     }
 
     /* Fins sPAPRPHBState */
-    phb = spapr_pci_find_phb(spapr, buid);
+    phb = spapr_pci_find_phb(sm, buid);
     if (phb) {
-        pdev = spapr_pci_find_dev(spapr, buid, config_addr);
+        pdev = spapr_pci_find_dev(sm, buid, config_addr);
     }
     if (!phb || !pdev) {
         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
@@ -309,7 +309,7 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPREnvironment *spapr,
             return;
         }
 
-        xics_free(spapr->icp, msi->first_irq, msi->num);
+        xics_free(sm->icp, msi->first_irq, msi->num);
         if (msi_present(pdev)) {
             spapr_msi_setmsg(pdev, 0, false, 0, num);
         }
@@ -347,7 +347,7 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     }
 
     /* Allocate MSIs */
-    irq = xics_alloc_block(spapr->icp, 0, req_num, false,
+    irq = xics_alloc_block(sm->icp, 0, req_num, false,
                            ret_intr_type == RTAS_TYPE_MSI);
     if (!irq) {
         error_report("Cannot allocate MSIs for device %x", config_addr);
@@ -377,7 +377,7 @@ out:
 }
 
 static void rtas_ibm_query_interrupt_source_number(PowerPCCPU *cpu,
-                                                   sPAPREnvironment *spapr,
+                                                   sPAPRMachineState *sm,
                                                    uint32_t token,
                                                    uint32_t nargs,
                                                    target_ulong args,
@@ -392,9 +392,9 @@ static void rtas_ibm_query_interrupt_source_number(PowerPCCPU *cpu,
     spapr_pci_msi *msi;
 
     /* Find sPAPRPHBState */
-    phb = spapr_pci_find_phb(spapr, buid);
+    phb = spapr_pci_find_phb(sm, buid);
     if (phb) {
-        pdev = spapr_pci_find_dev(spapr, buid, config_addr);
+        pdev = spapr_pci_find_dev(sm, buid, config_addr);
     }
     if (!phb || !pdev) {
         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
@@ -418,7 +418,7 @@ static void rtas_ibm_query_interrupt_source_number(PowerPCCPU *cpu,
 }
 
 static void rtas_ibm_set_eeh_option(PowerPCCPU *cpu,
-                                    sPAPREnvironment *spapr,
+                                    sPAPRMachineState *sm,
                                     uint32_t token, uint32_t nargs,
                                     target_ulong args, uint32_t nret,
                                     target_ulong rets)
@@ -437,7 +437,7 @@ static void rtas_ibm_set_eeh_option(PowerPCCPU *cpu,
     addr = rtas_ld(args, 0);
     option = rtas_ld(args, 3);
 
-    sphb = spapr_pci_find_phb(spapr, buid);
+    sphb = spapr_pci_find_phb(sm, buid);
     if (!sphb) {
         goto param_error_exit;
     }
@@ -456,7 +456,7 @@ param_error_exit:
 }
 
 static void rtas_ibm_get_config_addr_info2(PowerPCCPU *cpu,
-                                           sPAPREnvironment *spapr,
+                                           sPAPRMachineState *sm,
                                            uint32_t token, uint32_t nargs,
                                            target_ulong args, uint32_t nret,
                                            target_ulong rets)
@@ -472,7 +472,7 @@ static void rtas_ibm_get_config_addr_info2(PowerPCCPU *cpu,
     }
 
     buid = ((uint64_t)rtas_ld(args, 1) << 32) | rtas_ld(args, 2);
-    sphb = spapr_pci_find_phb(spapr, buid);
+    sphb = spapr_pci_find_phb(sm, buid);
     if (!sphb) {
         goto param_error_exit;
     }
@@ -490,7 +490,7 @@ static void rtas_ibm_get_config_addr_info2(PowerPCCPU *cpu,
     switch (option) {
     case RTAS_GET_PE_ADDR:
         addr = rtas_ld(args, 0);
-        pdev = spapr_pci_find_dev(spapr, buid, addr);
+        pdev = spapr_pci_find_dev(sm, buid, addr);
         if (!pdev) {
             goto param_error_exit;
         }
@@ -512,7 +512,7 @@ param_error_exit:
 }
 
 static void rtas_ibm_read_slot_reset_state2(PowerPCCPU *cpu,
-                                            sPAPREnvironment *spapr,
+                                            sPAPRMachineState *sm,
                                             uint32_t token, uint32_t nargs,
                                             target_ulong args, uint32_t nret,
                                             target_ulong rets)
@@ -527,7 +527,7 @@ static void rtas_ibm_read_slot_reset_state2(PowerPCCPU *cpu,
     }
 
     buid = ((uint64_t)rtas_ld(args, 1) << 32) | rtas_ld(args, 2);
-    sphb = spapr_pci_find_phb(spapr, buid);
+    sphb = spapr_pci_find_phb(sm, buid);
     if (!sphb) {
         goto param_error_exit;
     }
@@ -556,7 +556,7 @@ param_error_exit:
 }
 
 static void rtas_ibm_set_slot_reset(PowerPCCPU *cpu,
-                                    sPAPREnvironment *spapr,
+                                    sPAPRMachineState *sm,
                                     uint32_t token, uint32_t nargs,
                                     target_ulong args, uint32_t nret,
                                     target_ulong rets)
@@ -573,7 +573,7 @@ static void rtas_ibm_set_slot_reset(PowerPCCPU *cpu,
 
     buid = ((uint64_t)rtas_ld(args, 1) << 32) | rtas_ld(args, 2);
     option = rtas_ld(args, 3);
-    sphb = spapr_pci_find_phb(spapr, buid);
+    sphb = spapr_pci_find_phb(sm, buid);
     if (!sphb) {
         goto param_error_exit;
     }
@@ -592,7 +592,7 @@ param_error_exit:
 }
 
 static void rtas_ibm_configure_pe(PowerPCCPU *cpu,
-                                  sPAPREnvironment *spapr,
+                                  sPAPRMachineState *sm,
                                   uint32_t token, uint32_t nargs,
                                   target_ulong args, uint32_t nret,
                                   target_ulong rets)
@@ -607,7 +607,7 @@ static void rtas_ibm_configure_pe(PowerPCCPU *cpu,
     }
 
     buid = ((uint64_t)rtas_ld(args, 1) << 32) | rtas_ld(args, 2);
-    sphb = spapr_pci_find_phb(spapr, buid);
+    sphb = spapr_pci_find_phb(sm, buid);
     if (!sphb) {
         goto param_error_exit;
     }
@@ -627,7 +627,7 @@ param_error_exit:
 
 /* To support it later */
 static void rtas_ibm_slot_error_detail(PowerPCCPU *cpu,
-                                       sPAPREnvironment *spapr,
+                                       sPAPRMachineState *sm,
                                        uint32_t token, uint32_t nargs,
                                        target_ulong args, uint32_t nret,
                                        target_ulong rets)
@@ -642,7 +642,7 @@ static void rtas_ibm_slot_error_detail(PowerPCCPU *cpu,
     }
 
     buid = ((uint64_t)rtas_ld(args, 1) << 32) | rtas_ld(args, 2);
-    sphb = spapr_pci_find_phb(spapr, buid);
+    sphb = spapr_pci_find_phb(sm, buid);
     if (!sphb) {
         goto param_error_exit;
     }
@@ -718,11 +718,12 @@ static PCIINTxRoute spapr_route_intx_pin_to_irq(void *opaque, int pin)
 static void spapr_msi_write(void *opaque, hwaddr addr,
                             uint64_t data, unsigned size)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
     uint32_t irq = data;
 
     trace_spapr_pci_msi_write(addr, data, irq);
 
-    qemu_irq_pulse(xics_get_qirq(spapr->icp, irq));
+    qemu_irq_pulse(xics_get_qirq(sm->icp, irq));
 }
 
 static const MemoryRegionOps spapr_msi_ops = {
@@ -1110,6 +1111,7 @@ static void spapr_phb_hot_unplug_child(HotplugHandler *plug_handler,
 
 static void spapr_phb_realize(DeviceState *dev, Error **errp)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
     SysBusDevice *s = SYS_BUS_DEVICE(dev);
     sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(s);
     PCIHostState *phb = PCI_HOST_BRIDGE(s);
@@ -1165,7 +1167,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    if (spapr_pci_find_phb(spapr, sphb->buid)) {
+    if (spapr_pci_find_phb(sm, sphb->buid)) {
         error_setg(errp, "PCI host bridges must have unique BUIDs");
         return;
     }
@@ -1234,7 +1236,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
     }
 #endif
 
-    memory_region_init_io(&sphb->msiwindow, NULL, &spapr_msi_ops, spapr,
+    memory_region_init_io(&sphb->msiwindow, NULL, &spapr_msi_ops, sm,
                           "msi", msi_window_size);
     memory_region_add_subregion(&sphb->iommu_root, SPAPR_PCI_MSI_WINDOW,
                                 &sphb->msiwindow);
@@ -1243,13 +1245,13 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
 
     pci_bus_set_route_irq_fn(bus, spapr_route_intx_pin_to_irq);
 
-    QLIST_INSERT_HEAD(&spapr->phbs, sphb, list);
+    QLIST_INSERT_HEAD(&sm->phbs, sphb, list);
 
     /* Initialize the LSI table */
     for (i = 0; i < PCI_NUM_PINS; i++) {
         uint32_t irq;
 
-        irq = xics_alloc_block(spapr->icp, 0, 1, true, false);
+        irq = xics_alloc_block(sm->icp, 0, 1, true, false);
         if (!irq) {
             error_setg(errp, "spapr_allocate_lsi failed");
             return;
@@ -1464,7 +1466,7 @@ static const TypeInfo spapr_phb_info = {
     }
 };
 
-PCIHostState *spapr_create_phb(sPAPREnvironment *spapr, int index)
+PCIHostState *spapr_create_phb(sPAPRMachineState *sm, int index)
 {
     DeviceState *dev;
 
@@ -1631,6 +1633,7 @@ static int spapr_switch_one_vga(DeviceState *dev, void *opaque)
 
 void spapr_pci_switch_vga(bool big_endian)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
     sPAPRPHBState *sphb;
 
     /*
@@ -1638,7 +1641,7 @@ void spapr_pci_switch_vga(bool big_endian)
      * the endianness of the VGA controller when changing the guest
      * interrupt mode
      */
-    QLIST_FOREACH(sphb, &spapr->phbs, list) {
+    QLIST_FOREACH(sphb, &sm->phbs, list) {
         BusState *bus = &PCI_HOST_BRIDGE(sphb)->bus->qbus;
         qbus_walk_children(bus, spapr_switch_one_vga, NULL, NULL, NULL,
                            &big_endian);
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index fa28d43..e886f0e 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -47,12 +47,12 @@
     do { } while (0)
 #endif
 
-static sPAPRConfigureConnectorState *spapr_ccs_find(sPAPREnvironment *spapr,
+static sPAPRConfigureConnectorState *spapr_ccs_find(sPAPRMachineState *sm,
                                                     uint32_t drc_index)
 {
     sPAPRConfigureConnectorState *ccs = NULL;
 
-    QTAILQ_FOREACH(ccs, &spapr->ccs_list, next) {
+    QTAILQ_FOREACH(ccs, &sm->ccs_list, next) {
         if (ccs->drc_index == drc_index) {
             break;
         }
@@ -61,37 +61,37 @@ static sPAPRConfigureConnectorState *spapr_ccs_find(sPAPREnvironment *spapr,
     return ccs;
 }
 
-static void spapr_ccs_add(sPAPREnvironment *spapr,
+static void spapr_ccs_add(sPAPRMachineState *sm,
                           sPAPRConfigureConnectorState *ccs)
 {
-    g_assert(!spapr_ccs_find(spapr, ccs->drc_index));
-    QTAILQ_INSERT_HEAD(&spapr->ccs_list, ccs, next);
+    g_assert(!spapr_ccs_find(sm, ccs->drc_index));
+    QTAILQ_INSERT_HEAD(&sm->ccs_list, ccs, next);
 }
 
-static void spapr_ccs_remove(sPAPREnvironment *spapr,
+static void spapr_ccs_remove(sPAPRMachineState *sm,
                              sPAPRConfigureConnectorState *ccs)
 {
-    QTAILQ_REMOVE(&spapr->ccs_list, ccs, next);
+    QTAILQ_REMOVE(&sm->ccs_list, ccs, next);
     g_free(ccs);
 }
 
 void spapr_ccs_reset_hook(void *opaque)
 {
-    sPAPREnvironment *spapr = opaque;
+    sPAPRMachineState *sm = opaque;
     sPAPRConfigureConnectorState *ccs, *ccs_tmp;
 
-    QTAILQ_FOREACH_SAFE(ccs, &spapr->ccs_list, next, ccs_tmp) {
-        spapr_ccs_remove(spapr, ccs);
+    QTAILQ_FOREACH_SAFE(ccs, &sm->ccs_list, next, ccs_tmp) {
+        spapr_ccs_remove(sm, ccs);
     }
 }
 
-static void rtas_display_character(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_display_character(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                    uint32_t token, uint32_t nargs,
                                    target_ulong args,
                                    uint32_t nret, target_ulong rets)
 {
     uint8_t c = rtas_ld(args, 0);
-    VIOsPAPRDevice *sdev = vty_lookup(spapr, 0);
+    VIOsPAPRDevice *sdev = vty_lookup(sm, 0);
 
     if (!sdev) {
         rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
@@ -101,7 +101,7 @@ static void rtas_display_character(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     }
 }
 
-static void rtas_power_off(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_power_off(PowerPCCPU *cpu, sPAPRMachineState *sm,
                            uint32_t token, uint32_t nargs, target_ulong args,
                            uint32_t nret, target_ulong rets)
 {
@@ -113,7 +113,7 @@ static void rtas_power_off(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
 }
 
-static void rtas_system_reboot(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_system_reboot(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                uint32_t token, uint32_t nargs,
                                target_ulong args,
                                uint32_t nret, target_ulong rets)
@@ -127,7 +127,7 @@ static void rtas_system_reboot(PowerPCCPU *cpu, sPAPREnvironment *spapr,
 }
 
 static void rtas_query_cpu_stopped_state(PowerPCCPU *cpu_,
-                                         sPAPREnvironment *spapr,
+                                         sPAPRMachineState *sm,
                                          uint32_t token, uint32_t nargs,
                                          target_ulong args,
                                          uint32_t nret, target_ulong rets)
@@ -157,7 +157,7 @@ static void rtas_query_cpu_stopped_state(PowerPCCPU *cpu_,
     rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
 }
 
-static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr,
+static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *sm,
                            uint32_t token, uint32_t nargs,
                            target_ulong args,
                            uint32_t nret, target_ulong rets)
@@ -204,7 +204,7 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr,
     rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
 }
 
-static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *sm,
                            uint32_t token, uint32_t nargs,
                            target_ulong args,
                            uint32_t nret, target_ulong rets)
@@ -227,7 +227,7 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr,
 }
 
 static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,
-                                          sPAPREnvironment *spapr,
+                                          sPAPRMachineState *sm,
                                           uint32_t token, uint32_t nargs,
                                           target_ulong args,
                                           uint32_t nret, target_ulong rets)
@@ -262,7 +262,7 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,
 }
 
 static void rtas_ibm_set_system_parameter(PowerPCCPU *cpu,
-                                          sPAPREnvironment *spapr,
+                                          sPAPRMachineState *sm,
                                           uint32_t token, uint32_t nargs,
                                           target_ulong args,
                                           uint32_t nret, target_ulong rets)
@@ -282,7 +282,7 @@ static void rtas_ibm_set_system_parameter(PowerPCCPU *cpu,
 }
 
 static void rtas_ibm_os_term(PowerPCCPU *cpu,
-                            sPAPREnvironment *spapr,
+                            sPAPRMachineState *sm,
                             uint32_t token, uint32_t nargs,
                             target_ulong args,
                             uint32_t nret, target_ulong rets)
@@ -294,7 +294,7 @@ static void rtas_ibm_os_term(PowerPCCPU *cpu,
     rtas_st(rets, 0, ret);
 }
 
-static void rtas_set_power_level(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_set_power_level(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                  uint32_t token, uint32_t nargs,
                                  target_ulong args, uint32_t nret,
                                  target_ulong rets)
@@ -319,7 +319,7 @@ static void rtas_set_power_level(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     rtas_st(rets, 1, 100);
 }
 
-static void rtas_get_power_level(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_get_power_level(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                   uint32_t token, uint32_t nargs,
                                   target_ulong args, uint32_t nret,
                                   target_ulong rets)
@@ -356,7 +356,7 @@ static bool sensor_type_is_dr(uint32_t sensor_type)
     return false;
 }
 
-static void rtas_set_indicator(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_set_indicator(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                uint32_t token, uint32_t nargs,
                                target_ulong args, uint32_t nret,
                                target_ulong rets)
@@ -399,10 +399,10 @@ static void rtas_set_indicator(PowerPCCPU *cpu, sPAPREnvironment *spapr,
          * the FDT is no longer valid)
          */
         if (sensor_state == SPAPR_DR_ISOLATION_STATE_ISOLATED) {
-            sPAPRConfigureConnectorState *ccs = spapr_ccs_find(spapr,
+            sPAPRConfigureConnectorState *ccs = spapr_ccs_find(sm,
                                                                sensor_index);
             if (ccs) {
-                spapr_ccs_remove(spapr, ccs);
+                spapr_ccs_remove(sm, ccs);
             }
         }
         drck->set_isolation_state(drc, sensor_state);
@@ -427,7 +427,7 @@ out_unimplemented:
     rtas_st(rets, 0, RTAS_OUT_NOT_SUPPORTED);
 }
 
-static void rtas_get_sensor_state(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_get_sensor_state(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                   uint32_t token, uint32_t nargs,
                                   target_ulong args, uint32_t nret,
                                   target_ulong rets)
@@ -481,7 +481,7 @@ static void rtas_get_sensor_state(PowerPCCPU *cpu, sPAPREnvironment *spapr,
 #define CC_WA_LEN 4096
 
 static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
-                                         sPAPREnvironment *spapr,
+                                         sPAPRMachineState *sm,
                                          uint32_t token, uint32_t nargs,
                                          target_ulong args, uint32_t nret,
                                          target_ulong rets)
@@ -515,12 +515,12 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
     drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
     fdt = drck->get_fdt(drc, NULL);
 
-    ccs = spapr_ccs_find(spapr, drc_index);
+    ccs = spapr_ccs_find(sm, drc_index);
     if (!ccs) {
         ccs = g_new0(sPAPRConfigureConnectorState, 1);
         (void)drck->get_fdt(drc, &ccs->fdt_offset);
         ccs->drc_index = drc_index;
-        spapr_ccs_add(spapr, ccs);
+        spapr_ccs_add(sm, ccs);
     }
 
     do {
@@ -550,7 +550,7 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
                  * the state anymore
                  */
                 drck->set_configured(drc);
-                spapr_ccs_remove(spapr, ccs);
+                spapr_ccs_remove(sm, ccs);
                 ccs = NULL;
                 resp = SPAPR_DR_CC_RESPONSE_SUCCESS;
             } else {
@@ -601,7 +601,7 @@ static struct rtas_call {
     spapr_rtas_fn fn;
 } rtas_table[RTAS_TOKEN_MAX - RTAS_TOKEN_BASE];
 
-target_ulong spapr_rtas_call(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+target_ulong spapr_rtas_call(PowerPCCPU *cpu, sPAPRMachineState *sm,
                              uint32_t token, uint32_t nargs, target_ulong args,
                              uint32_t nret, target_ulong rets)
 {
@@ -609,7 +609,7 @@ target_ulong spapr_rtas_call(PowerPCCPU *cpu, sPAPREnvironment *spapr,
         struct rtas_call *call = rtas_table + (token - RTAS_TOKEN_BASE);
 
         if (call->fn) {
-            call->fn(cpu, spapr, token, nargs, args, nret, rets);
+            call->fn(cpu, sm, token, nargs, args, nret, rets);
             return H_SUCCESS;
         }
     }
@@ -619,7 +619,7 @@ target_ulong spapr_rtas_call(PowerPCCPU *cpu, sPAPREnvironment *spapr,
      * machines) without looking it up in the device tree.  This
      * special case makes this work */
     if (token == 0xa) {
-        rtas_display_character(cpu, spapr, 0xa, nargs, args, nret, rets);
+        rtas_display_character(cpu, sm, 0xa, nargs, args, nret, rets);
         return H_SUCCESS;
     }
 
diff --git a/hw/ppc/spapr_rtc.c b/hw/ppc/spapr_rtc.c
index 83eb7c1..3adfa93 100644
--- a/hw/ppc/spapr_rtc.c
+++ b/hw/ppc/spapr_rtc.c
@@ -77,7 +77,7 @@ int spapr_rtc_import_offset(DeviceState *dev, int64_t legacy_offset)
     return 0;
 }
 
-static void rtas_get_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_get_time_of_day(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                  uint32_t token, uint32_t nargs,
                                  target_ulong args,
                                  uint32_t nret, target_ulong rets)
@@ -90,12 +90,12 @@ static void rtas_get_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr,
         return;
     }
 
-    if (!spapr->rtc) {
+    if (!sm->rtc) {
         rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
         return;
     }
 
-    spapr_rtc_read(spapr->rtc, &tm, &ns);
+    spapr_rtc_read(sm->rtc, &tm, &ns);
 
     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
     rtas_st(rets, 1, tm.tm_year + 1900);
@@ -107,7 +107,7 @@ static void rtas_get_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     rtas_st(rets, 7, ns);
 }
 
-static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                  uint32_t token, uint32_t nargs,
                                  target_ulong args,
                                  uint32_t nret, target_ulong rets)
@@ -122,7 +122,7 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr,
         return;
     }
 
-    if (!spapr->rtc) {
+    if (!sm->rtc) {
         rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
         return;
     }
@@ -143,7 +143,7 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     /* Generate a monitor event for the change */
     qapi_event_send_rtc_change(qemu_timedate_diff(&tm), &error_abort);
 
-    rtc = SPAPR_RTC(spapr->rtc);
+    rtc = SPAPR_RTC(sm->rtc);
 
     host_ns = qemu_clock_get_ns(rtc_clock);
 
diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
index 174033d..2891cd2 100644
--- a/hw/ppc/spapr_vio.c
+++ b/hw/ppc/spapr_vio.c
@@ -161,13 +161,13 @@ static int vio_make_devnode(VIOsPAPRDevice *dev,
 /*
  * CRQ handling
  */
-static target_ulong h_reg_crq(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_reg_crq(PowerPCCPU *cpu, sPAPRMachineState *sm,
                               target_ulong opcode, target_ulong *args)
 {
     target_ulong reg = args[0];
     target_ulong queue_addr = args[1];
     target_ulong queue_len = args[2];
-    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
+    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(sm->vio_bus, reg);
 
     if (!dev) {
         hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
@@ -219,11 +219,11 @@ static target_ulong free_crq(VIOsPAPRDevice *dev)
     return H_SUCCESS;
 }
 
-static target_ulong h_free_crq(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_free_crq(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                target_ulong opcode, target_ulong *args)
 {
     target_ulong reg = args[0];
-    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
+    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(sm->vio_bus, reg);
 
     if (!dev) {
         hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
@@ -233,13 +233,13 @@ static target_ulong h_free_crq(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return free_crq(dev);
 }
 
-static target_ulong h_send_crq(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_send_crq(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                target_ulong opcode, target_ulong *args)
 {
     target_ulong reg = args[0];
     target_ulong msg_hi = args[1];
     target_ulong msg_lo = args[2];
-    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
+    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(sm->vio_bus, reg);
     uint64_t crq_mangle[2];
 
     if (!dev) {
@@ -256,11 +256,11 @@ static target_ulong h_send_crq(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_HARDWARE;
 }
 
-static target_ulong h_enable_crq(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_enable_crq(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                  target_ulong opcode, target_ulong *args)
 {
     target_ulong reg = args[0];
-    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
+    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(sm->vio_bus, reg);
 
     if (!dev) {
         hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
@@ -334,12 +334,12 @@ void spapr_vio_set_bypass(VIOsPAPRDevice *dev, bool bypass)
     dev->tcet->bypass = bypass;
 }
 
-static void rtas_set_tce_bypass(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_set_tce_bypass(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                 uint32_t token,
                                 uint32_t nargs, target_ulong args,
                                 uint32_t nret, target_ulong rets)
 {
-    VIOsPAPRBus *bus = spapr->vio_bus;
+    VIOsPAPRBus *bus = sm->vio_bus;
     VIOsPAPRDevice *dev;
     uint32_t unit, enable;
 
@@ -365,12 +365,12 @@ static void rtas_set_tce_bypass(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
 }
 
-static void rtas_quiesce(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static void rtas_quiesce(PowerPCCPU *cpu, sPAPRMachineState *sm,
                          uint32_t token,
                          uint32_t nargs, target_ulong args,
                          uint32_t nret, target_ulong rets)
 {
-    VIOsPAPRBus *bus = spapr->vio_bus;
+    VIOsPAPRBus *bus = sm->vio_bus;
     BusChild *kid;
     VIOsPAPRDevice *dev = NULL;
 
@@ -427,6 +427,7 @@ static void spapr_vio_busdev_reset(DeviceState *qdev)
 
 static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp)
 {
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
     VIOsPAPRDevice *dev = (VIOsPAPRDevice *)qdev;
     VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
     char *id;
@@ -462,7 +463,7 @@ static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp)
         dev->qdev.id = id;
     }
 
-    dev->irq = xics_alloc(spapr->icp, 0, dev->irq, false);
+    dev->irq = xics_alloc(sm->icp, 0, dev->irq, false);
     if (!dev->irq) {
         error_setg(errp, "can't allocate IRQ");
         return;
@@ -492,13 +493,13 @@ static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp)
     pc->realize(dev, errp);
 }
 
-static target_ulong h_vio_signal(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+static target_ulong h_vio_signal(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                  target_ulong opcode,
                                  target_ulong *args)
 {
     target_ulong reg = args[0];
     target_ulong mode = args[1];
-    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
+    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(sm->vio_bus, reg);
     VIOsPAPRDeviceClass *pc;
 
     if (!dev) {
diff --git a/include/hw/pci-host/spapr.h b/include/hw/pci-host/spapr.h
index 9dca388..f07e8a2 100644
--- a/include/hw/pci-host/spapr.h
+++ b/include/hw/pci-host/spapr.h
@@ -119,21 +119,23 @@ struct sPAPRPHBVFIOState {
 
 static inline qemu_irq spapr_phb_lsi_qirq(struct sPAPRPHBState *phb, int pin)
 {
-    return xics_get_qirq(spapr->icp, phb->lsi_table[pin].irq);
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
+
+    return xics_get_qirq(sm->icp, phb->lsi_table[pin].irq);
 }
 
-PCIHostState *spapr_create_phb(sPAPREnvironment *spapr, int index);
+PCIHostState *spapr_create_phb(sPAPRMachineState *sm, int index);
 
 int spapr_populate_pci_dt(sPAPRPHBState *phb,
                           uint32_t xics_phandle,
                           void *fdt);
 
-void spapr_pci_msi_init(sPAPREnvironment *spapr, hwaddr addr);
+void spapr_pci_msi_init(sPAPRMachineState *sm, hwaddr addr);
 
 void spapr_pci_rtas_init(void);
 
-sPAPRPHBState *spapr_pci_find_phb(sPAPREnvironment *spapr, uint64_t buid);
-PCIDevice *spapr_pci_find_dev(sPAPREnvironment *spapr, uint64_t buid,
+sPAPRPHBState *spapr_pci_find_phb(sPAPRMachineState *sm, uint64_t buid);
+PCIDevice *spapr_pci_find_dev(sPAPRMachineState *sm, uint64_t buid,
                               uint32_t config_addr);
 
 #endif /* __HW_SPAPR_PCI_H__ */
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 7b4b1bb..c3652aa 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -2,6 +2,7 @@
 #define __HW_SPAPR_H__
 
 #include "sysemu/dma.h"
+#include "hw/boards.h"
 #include "hw/ppc/xics.h"
 #include "hw/ppc/spapr_drc.h"
 
@@ -13,7 +14,19 @@ typedef struct sPAPREventLogEntry sPAPREventLogEntry;
 
 #define HPTE64_V_HPTE_DIRTY     0x0000000000000040ULL
 
-typedef struct sPAPREnvironment {
+typedef struct sPAPRMachineState sPAPRMachineState;
+
+#define TYPE_SPAPR_MACHINE      "spapr-machine"
+#define SPAPR_MACHINE(obj) \
+    OBJECT_CHECK(sPAPRMachineState, (obj), TYPE_SPAPR_MACHINE)
+
+/**
+ * sPAPRMachineState:
+ */
+struct sPAPRMachineState {
+    /*< private >*/
+    MachineState parent_obj;
+
     struct VIOsPAPRBus *vio_bus;
     QLIST_HEAD(, sPAPRPHBState) phbs;
     struct sPAPRNVRAM *nvram;
@@ -46,7 +59,10 @@ typedef struct sPAPREnvironment {
 
     /* RTAS state */
     QTAILQ_HEAD(, sPAPRConfigureConnectorState) ccs_list;
-} sPAPREnvironment;
+
+    /*< public >*/
+    char *kvm_type;
+};
 
 #define H_SUCCESS         0
 #define H_BUSY            1        /* Hardware busy -- retry later */
@@ -319,8 +335,6 @@ typedef struct sPAPREnvironment {
 #define KVMPPC_H_CAS            (KVMPPC_HCALL_BASE + 0x2)
 #define KVMPPC_HCALL_MAX        KVMPPC_H_CAS
 
-extern sPAPREnvironment *spapr;
-
 typedef struct sPAPRDeviceTreeUpdateHeader {
     uint32_t version_id;
 } sPAPRDeviceTreeUpdateHeader;
@@ -335,7 +349,7 @@ typedef struct sPAPRDeviceTreeUpdateHeader {
     do { } while (0)
 #endif
 
-typedef target_ulong (*spapr_hcall_fn)(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+typedef target_ulong (*spapr_hcall_fn)(PowerPCCPU *cpu, sPAPRMachineState *sm,
                                        target_ulong opcode,
                                        target_ulong *args);
 
@@ -490,12 +504,12 @@ static inline void rtas_st_buffer(target_ulong phys, target_ulong phys_len,
     rtas_st_buffer_direct(phys + 2, phys_len - 2, buffer, buffer_len);
 }
 
-typedef void (*spapr_rtas_fn)(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+typedef void (*spapr_rtas_fn)(PowerPCCPU *cpu, sPAPRMachineState *sm,
                               uint32_t token,
                               uint32_t nargs, target_ulong args,
                               uint32_t nret, target_ulong rets);
 void spapr_rtas_register(int token, const char *name, spapr_rtas_fn fn);
-target_ulong spapr_rtas_call(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+target_ulong spapr_rtas_call(PowerPCCPU *cpu, sPAPRMachineState *sm,
                              uint32_t token, uint32_t nargs, target_ulong args,
                              uint32_t nret, target_ulong rets);
 int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,
@@ -546,9 +560,10 @@ struct sPAPREventLogEntry {
     QTAILQ_ENTRY(sPAPREventLogEntry) next;
 };
 
-void spapr_events_init(sPAPREnvironment *spapr);
+void spapr_events_init(sPAPRMachineState *sm);
 void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq);
-int spapr_h_cas_compose_response(target_ulong addr, target_ulong size);
+int spapr_h_cas_compose_response(sPAPRMachineState *sm,
+                                 target_ulong addr, target_ulong size);
 sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn,
                                    uint64_t bus_offset,
                                    uint32_t page_shift,
diff --git a/include/hw/ppc/spapr_vio.h b/include/hw/ppc/spapr_vio.h
index f95016a..c41e848 100644
--- a/include/hw/ppc/spapr_vio.h
+++ b/include/hw/ppc/spapr_vio.h
@@ -88,7 +88,9 @@ extern int spapr_vio_signal(VIOsPAPRDevice *dev, target_ulong mode);
 
 static inline qemu_irq spapr_vio_qirq(VIOsPAPRDevice *dev)
 {
-    return xics_get_qirq(spapr->icp, dev->irq);
+    sPAPRMachineState *sm = SPAPR_MACHINE(qdev_get_machine());
+
+    return xics_get_qirq(sm->icp, dev->irq);
 }
 
 static inline bool spapr_vio_dma_valid(VIOsPAPRDevice *dev, uint64_t taddr,
@@ -126,7 +128,7 @@ static inline int spapr_vio_dma_set(VIOsPAPRDevice *dev, uint64_t taddr,
 
 int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq);
 
-VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg);
+VIOsPAPRDevice *vty_lookup(sPAPRMachineState *sm, target_ulong reg);
 void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len);
 void spapr_vty_create(VIOsPAPRBus *bus, CharDriverState *chardev);
 void spapr_vlan_create(VIOsPAPRBus *bus, NICInfo *nd);
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH 2/4] spapr: Remove obsolete ram_limit field from sPAPRMachineState
  2015-05-07  3:57 [Qemu-devel] [PATCH 0/4] sPAPRMachineState cleanups David Gibson
  2015-05-07  3:57 ` [Qemu-devel] [PATCH 1/4] spapr: Merge sPAPREnvironment into sPAPRMachineState David Gibson
@ 2015-05-07  3:57 ` David Gibson
  2015-05-07  4:12   ` Alexey Kardashevskiy
  2015-05-07  3:57 ` [Qemu-devel] [PATCH 3/4] spapr: Remove obsolete entry_point " David Gibson
  2015-05-07  3:57 ` [Qemu-devel] [PATCH 4/4] spapr: Add sPAPRMachineClass David Gibson
  3 siblings, 1 reply; 12+ messages in thread
From: David Gibson @ 2015-05-07  3:57 UTC (permalink / raw)
  To: qemu-ppc, qemu-devel
  Cc: lvivier, thuth, aik, mdroth, agraf, bharata, afaerber,
	David Gibson

The ram_limit field was imported from sPAPREnvironment where it predates
the machine's ram size being available generically from machine->ram_size.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/ppc/spapr.c         | 3 +--
 hw/ppc/spapr_hcall.c   | 3 ++-
 include/hw/ppc/spapr.h | 1 -
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 601c41b..1123358 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1496,9 +1496,8 @@ static void ppc_spapr_init(MachineState *machine)
     }
 
     /* allocate RAM */
-    sm->ram_limit = ram_size;
     memory_region_allocate_system_memory(ram, NULL, "ppc_spapr.ram",
-                                         sm->ram_limit);
+                                         machine->ram_size);
     memory_region_add_subregion(sysmem, 0, ram);
 
     if (rma_alloc_size && rma) {
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index bf4b05a..e52983a 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -87,6 +87,7 @@ static inline bool valid_pte_index(CPUPPCState *env, target_ulong pte_index)
 static target_ulong h_enter(PowerPCCPU *cpu, sPAPRMachineState *sm,
                             target_ulong opcode, target_ulong *args)
 {
+    MachineState *machine = MACHINE(sm);
     CPUPPCState *env = &cpu->env;
     target_ulong flags = args[0];
     target_ulong pte_index = args[1];
@@ -118,7 +119,7 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPRMachineState *sm,
 
     raddr = (ptel & HPTE64_R_RPN) & ~((1ULL << page_shift) - 1);
 
-    if (raddr < sm->ram_limit) {
+    if (raddr < machine->ram_size) {
         /* Regular RAM - should have WIMG=0010 */
         if ((ptel & HPTE64_R_WIMG) != HPTE64_R_M) {
             return H_PARAMETER;
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index c3652aa..9e7cf0f 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -33,7 +33,6 @@ struct sPAPRMachineState {
     XICSState *icp;
     DeviceState *rtc;
 
-    hwaddr ram_limit;
     void *htab;
     uint32_t htab_shift;
     hwaddr rma_size;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH 3/4] spapr: Remove obsolete entry_point field from sPAPRMachineState
  2015-05-07  3:57 [Qemu-devel] [PATCH 0/4] sPAPRMachineState cleanups David Gibson
  2015-05-07  3:57 ` [Qemu-devel] [PATCH 1/4] spapr: Merge sPAPREnvironment into sPAPRMachineState David Gibson
  2015-05-07  3:57 ` [Qemu-devel] [PATCH 2/4] spapr: Remove obsolete ram_limit field from sPAPRMachineState David Gibson
@ 2015-05-07  3:57 ` David Gibson
  2015-05-07  4:50   ` Bharata B Rao
  2015-05-07  3:57 ` [Qemu-devel] [PATCH 4/4] spapr: Add sPAPRMachineClass David Gibson
  3 siblings, 1 reply; 12+ messages in thread
From: David Gibson @ 2015-05-07  3:57 UTC (permalink / raw)
  To: qemu-ppc, qemu-devel
  Cc: lvivier, thuth, aik, mdroth, agraf, bharata, afaerber,
	David Gibson

The sPAPRMachineState structure includes an entry_point field containing
the initial PC value for starting the machine, even though this always has
the value 0x100.

I think this is a hangover from very early versions which bypassed the
firmware when using -kernel.  In any case it has no function now, so remove
it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/ppc/spapr.c         | 4 +---
 include/hw/ppc/spapr.h | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 1123358..c4c7a07 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -928,7 +928,7 @@ static void ppc_spapr_reset(void)
     first_ppc_cpu->env.gpr[3] = sm->fdt_addr;
     first_ppc_cpu->env.gpr[5] = 0;
     first_cpu->halted = 0;
-    first_ppc_cpu->env.nip = sm->entry_point;
+    first_ppc_cpu->env.nip = SPAPR_ENTRY_POINT;
 
 }
 
@@ -1641,8 +1641,6 @@ static void ppc_spapr_init(MachineState *machine)
     }
     g_free(filename);
 
-    sm->entry_point = 0x100;
-
     /* FIXME: Should register thigs through the MachineState's qdev
      * interface, this is a legacy from the sPAPREnvironment structure
      * which predated MachineState but had a similar function */
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 9e7cf0f..108ff45 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -13,6 +13,7 @@ typedef struct sPAPRConfigureConnectorState sPAPRConfigureConnectorState;
 typedef struct sPAPREventLogEntry sPAPREventLogEntry;
 
 #define HPTE64_V_HPTE_DIRTY     0x0000000000000040ULL
+#define SPAPR_ENTRY_POINT	0x100
 
 typedef struct sPAPRMachineState sPAPRMachineState;
 
@@ -41,7 +42,6 @@ struct sPAPRMachineState {
     ssize_t rtas_size;
     void *rtas_blob;
     void *fdt_skel;
-    target_ulong entry_point;
     uint64_t rtc_offset; /* Now used only during incoming migration */
     struct PPCTimebase tb;
     bool has_graphics;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH 4/4] spapr: Add sPAPRMachineClass
  2015-05-07  3:57 [Qemu-devel] [PATCH 0/4] sPAPRMachineState cleanups David Gibson
                   ` (2 preceding siblings ...)
  2015-05-07  3:57 ` [Qemu-devel] [PATCH 3/4] spapr: Remove obsolete entry_point " David Gibson
@ 2015-05-07  3:57 ` David Gibson
  3 siblings, 0 replies; 12+ messages in thread
From: David Gibson @ 2015-05-07  3:57 UTC (permalink / raw)
  To: qemu-ppc, qemu-devel
  Cc: lvivier, thuth, aik, mdroth, agraf, bharata, afaerber,
	David Gibson

Currently although we have an sPAPRMachineState descended from MachineState
we don't have an sPAPRMAchineClass descended from MachineClass.  So far it
hasn't been needed, but several upcoming features are going to want it,
so this patch creates a stub implementation.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/ppc/spapr.c         |  1 +
 include/hw/ppc/spapr.h | 15 +++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index c4c7a07..deebca9 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1804,6 +1804,7 @@ static const TypeInfo spapr_machine_info = {
     .abstract      = true,
     .instance_size = sizeof(sPAPRMachineState),
     .instance_init = spapr_machine_initfn,
+    .class_size    = sizeof(sPAPRMachineClass),
     .class_init    = spapr_machine_class_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_FW_PATH_PROVIDER },
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 108ff45..f83167e 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -15,11 +15,26 @@ typedef struct sPAPREventLogEntry sPAPREventLogEntry;
 #define HPTE64_V_HPTE_DIRTY     0x0000000000000040ULL
 #define SPAPR_ENTRY_POINT	0x100
 
+typedef struct sPAPRMachineClass sPAPRMachineClass;
 typedef struct sPAPRMachineState sPAPRMachineState;
 
 #define TYPE_SPAPR_MACHINE      "spapr-machine"
 #define SPAPR_MACHINE(obj) \
     OBJECT_CHECK(sPAPRMachineState, (obj), TYPE_SPAPR_MACHINE)
+#define SPAPR_MACHINE_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(sPAPRMachineClass, obj, TYPE_SPAPR_MACHINE)
+#define SPAPR_MACHINE_CLASS(klass) \
+    OBJECT_CLASS_CHECK(sPAPRMachineClass, klass, TYPE_SPAPR_MACHINE)
+
+/**
+ * sPAPRMachineClass:
+ */
+struct sPAPRMachineClass {
+    /*< private >*/
+    MachineClass parent_class;
+
+    /*< public >*/
+};
 
 /**
  * sPAPRMachineState:
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 2/4] spapr: Remove obsolete ram_limit field from sPAPRMachineState
  2015-05-07  3:57 ` [Qemu-devel] [PATCH 2/4] spapr: Remove obsolete ram_limit field from sPAPRMachineState David Gibson
@ 2015-05-07  4:12   ` Alexey Kardashevskiy
  2015-05-07  4:40     ` David Gibson
  2015-05-26  1:23     ` David Gibson
  0 siblings, 2 replies; 12+ messages in thread
From: Alexey Kardashevskiy @ 2015-05-07  4:12 UTC (permalink / raw)
  To: David Gibson, qemu-ppc, qemu-devel
  Cc: lvivier, thuth, mdroth, agraf, bharata, afaerber

On 05/07/2015 01:57 PM, David Gibson wrote:
> The ram_limit field was imported from sPAPREnvironment where it predates
> the machine's ram size being available generically from machine->ram_size.
>
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>   hw/ppc/spapr.c         | 3 +--
>   hw/ppc/spapr_hcall.c   | 3 ++-
>   include/hw/ppc/spapr.h | 1 -
>   3 files changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 601c41b..1123358 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1496,9 +1496,8 @@ static void ppc_spapr_init(MachineState *machine)
>       }
>
>       /* allocate RAM */
> -    sm->ram_limit = ram_size;



I had to look at the code to realize that ram_size is local and it can 
actually be removed.



>       memory_region_allocate_system_memory(ram, NULL, "ppc_spapr.ram",
> -                                         sm->ram_limit);
> +                                         machine->ram_size);
>       memory_region_add_subregion(sysmem, 0, ram);
>
>       if (rma_alloc_size && rma) {
> diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
> index bf4b05a..e52983a 100644
> --- a/hw/ppc/spapr_hcall.c
> +++ b/hw/ppc/spapr_hcall.c
> @@ -87,6 +87,7 @@ static inline bool valid_pte_index(CPUPPCState *env, target_ulong pte_index)
>   static target_ulong h_enter(PowerPCCPU *cpu, sPAPRMachineState *sm,
>                               target_ulong opcode, target_ulong *args)
>   {
> +    MachineState *machine = MACHINE(sm);
>       CPUPPCState *env = &cpu->env;
>       target_ulong flags = args[0];
>       target_ulong pte_index = args[1];
> @@ -118,7 +119,7 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPRMachineState *sm,
>
>       raddr = (ptel & HPTE64_R_RPN) & ~((1ULL << page_shift) - 1);
>
> -    if (raddr < sm->ram_limit) {
> +    if (raddr < machine->ram_size) {
>           /* Regular RAM - should have WIMG=0010 */
>           if ((ptel & HPTE64_R_WIMG) != HPTE64_R_M) {
>               return H_PARAMETER;
> diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
> index c3652aa..9e7cf0f 100644
> --- a/include/hw/ppc/spapr.h
> +++ b/include/hw/ppc/spapr.h
> @@ -33,7 +33,6 @@ struct sPAPRMachineState {
>       XICSState *icp;
>       DeviceState *rtc;
>
> -    hwaddr ram_limit;
>       void *htab;
>       uint32_t htab_shift;
>       hwaddr rma_size;
>


-- 
Alexey

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 2/4] spapr: Remove obsolete ram_limit field from sPAPRMachineState
  2015-05-07  4:12   ` Alexey Kardashevskiy
@ 2015-05-07  4:40     ` David Gibson
  2015-05-26  1:23     ` David Gibson
  1 sibling, 0 replies; 12+ messages in thread
From: David Gibson @ 2015-05-07  4:40 UTC (permalink / raw)
  To: Alexey Kardashevskiy
  Cc: lvivier, thuth, mdroth, qemu-devel, agraf, qemu-ppc, bharata,
	afaerber

[-- Attachment #1: Type: text/plain, Size: 2975 bytes --]

On Thu, May 07, 2015 at 02:12:58PM +1000, Alexey Kardashevskiy wrote:
> On 05/07/2015 01:57 PM, David Gibson wrote:
> >The ram_limit field was imported from sPAPREnvironment where it predates
> >the machine's ram size being available generically from machine->ram_size.
> >
> >Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> >---
> >  hw/ppc/spapr.c         | 3 +--
> >  hw/ppc/spapr_hcall.c   | 3 ++-
> >  include/hw/ppc/spapr.h | 1 -
> >  3 files changed, 3 insertions(+), 4 deletions(-)
> >
> >diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> >index 601c41b..1123358 100644
> >--- a/hw/ppc/spapr.c
> >+++ b/hw/ppc/spapr.c
> >@@ -1496,9 +1496,8 @@ static void ppc_spapr_init(MachineState *machine)
> >      }
> >
> >      /* allocate RAM */
> >-    sm->ram_limit = ram_size;
> 
> 
> 
> I had to look at the code to realize that ram_size is local and it can
> actually be removed.

Urgh.. it's actually worse than that.  There's a global that's
shadowed by the local.  ppc_spapr_init() uses the local,
spapr_populate_memory() uses the global.
> 
> 
> 
> >      memory_region_allocate_system_memory(ram, NULL, "ppc_spapr.ram",
> >-                                         sm->ram_limit);
> >+                                         machine->ram_size);
> >      memory_region_add_subregion(sysmem, 0, ram);
> >
> >      if (rma_alloc_size && rma) {
> >diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
> >index bf4b05a..e52983a 100644
> >--- a/hw/ppc/spapr_hcall.c
> >+++ b/hw/ppc/spapr_hcall.c
> >@@ -87,6 +87,7 @@ static inline bool valid_pte_index(CPUPPCState *env, target_ulong pte_index)
> >  static target_ulong h_enter(PowerPCCPU *cpu, sPAPRMachineState *sm,
> >                              target_ulong opcode, target_ulong *args)
> >  {
> >+    MachineState *machine = MACHINE(sm);
> >      CPUPPCState *env = &cpu->env;
> >      target_ulong flags = args[0];
> >      target_ulong pte_index = args[1];
> >@@ -118,7 +119,7 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPRMachineState *sm,
> >
> >      raddr = (ptel & HPTE64_R_RPN) & ~((1ULL << page_shift) - 1);
> >
> >-    if (raddr < sm->ram_limit) {
> >+    if (raddr < machine->ram_size) {
> >          /* Regular RAM - should have WIMG=0010 */
> >          if ((ptel & HPTE64_R_WIMG) != HPTE64_R_M) {
> >              return H_PARAMETER;
> >diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
> >index c3652aa..9e7cf0f 100644
> >--- a/include/hw/ppc/spapr.h
> >+++ b/include/hw/ppc/spapr.h
> >@@ -33,7 +33,6 @@ struct sPAPRMachineState {
> >      XICSState *icp;
> >      DeviceState *rtc;
> >
> >-    hwaddr ram_limit;
> >      void *htab;
> >      uint32_t htab_shift;
> >      hwaddr rma_size;
> >
> 
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 3/4] spapr: Remove obsolete entry_point field from sPAPRMachineState
  2015-05-07  3:57 ` [Qemu-devel] [PATCH 3/4] spapr: Remove obsolete entry_point " David Gibson
@ 2015-05-07  4:50   ` Bharata B Rao
  2015-05-26  1:39     ` David Gibson
  0 siblings, 1 reply; 12+ messages in thread
From: Bharata B Rao @ 2015-05-07  4:50 UTC (permalink / raw)
  To: David Gibson
  Cc: lvivier, thuth, mdroth, aik, qemu-devel, agraf, qemu-ppc,
	afaerber

On Thu, May 07, 2015 at 01:57:03PM +1000, David Gibson wrote:
> The sPAPRMachineState structure includes an entry_point field containing
> the initial PC value for starting the machine, even though this always has
> the value 0x100.
> 
> I think this is a hangover from very early versions which bypassed the
> firmware when using -kernel.  In any case it has no function now, so remove
> it.
> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>  hw/ppc/spapr.c         | 4 +---
>  include/hw/ppc/spapr.h | 2 +-
>  2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 1123358..c4c7a07 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -928,7 +928,7 @@ static void ppc_spapr_reset(void)
>      first_ppc_cpu->env.gpr[3] = sm->fdt_addr;
>      first_ppc_cpu->env.gpr[5] = 0;
>      first_cpu->halted = 0;
> -    first_ppc_cpu->env.nip = sm->entry_point;
> +    first_ppc_cpu->env.nip = SPAPR_ENTRY_POINT;
> 
>  }
> 
> @@ -1641,8 +1641,6 @@ static void ppc_spapr_init(MachineState *machine)
>      }
>      g_free(filename);
> 
> -    sm->entry_point = 0x100;
> -
>      /* FIXME: Should register thigs through the MachineState's qdev
>       * interface, this is a legacy from the sPAPREnvironment structure
>       * which predated MachineState but had a similar function */
> diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
> index 9e7cf0f..108ff45 100644
> --- a/include/hw/ppc/spapr.h
> +++ b/include/hw/ppc/spapr.h
> @@ -13,6 +13,7 @@ typedef struct sPAPRConfigureConnectorState sPAPRConfigureConnectorState;
>  typedef struct sPAPREventLogEntry sPAPREventLogEntry;
> 
>  #define HPTE64_V_HPTE_DIRTY     0x0000000000000040ULL
> +#define SPAPR_ENTRY_POINT	0x100

checkpatch.pl complains about the use of tab here.

Other than that I did a quick compile and VM boot test, things look ok.

Regards,
Bharata.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] spapr: Merge sPAPREnvironment into sPAPRMachineState
  2015-05-07  3:57 ` [Qemu-devel] [PATCH 1/4] spapr: Merge sPAPREnvironment into sPAPRMachineState David Gibson
@ 2015-05-07  8:13   ` Thomas Huth
  2015-05-26  1:14     ` David Gibson
  0 siblings, 1 reply; 12+ messages in thread
From: Thomas Huth @ 2015-05-07  8:13 UTC (permalink / raw)
  To: David Gibson
  Cc: lvivier, mdroth, aik, qemu-devel, agraf, qemu-ppc, bharata,
	afaerber

On Thu,  7 May 2015 13:57:01 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:

> The code for -machine pseries maintains a global sPAPREnvironment structure
> which keeps track of general state information about the guest platform.
> This predates the existence of the MachineState structure, but performs
> basically the same function.
> 
> Now that we have the generic MachineState, fold sPAPREnvironment into
> sPAPRMachineState, the pseries specific subclass of MachineState.
> 
> This is mostly a matter of search and replace, although a few places which
> relied on the global spapr variable are changed to find the structure via
> qdev_get_machine().
> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>  hw/char/spapr_vty.c         |  14 +-
>  hw/intc/xics.c              |  42 +++---
>  hw/intc/xics_kvm.c          |   2 +-
>  hw/net/spapr_llan.c         |  20 +--
>  hw/nvram/spapr_nvram.c      |   8 +-
>  hw/ppc/spapr.c              | 339 +++++++++++++++++++++-----------------------
>  hw/ppc/spapr_events.c       |  37 ++---
>  hw/ppc/spapr_hcall.c        |  44 +++---
>  hw/ppc/spapr_iommu.c        |   8 +-
>  hw/ppc/spapr_pci.c          |  91 ++++++------
>  hw/ppc/spapr_rtas.c         |  66 ++++-----
>  hw/ppc/spapr_rtc.c          |  12 +-
>  hw/ppc/spapr_vio.c          |  31 ++--
>  include/hw/pci-host/spapr.h |  12 +-
>  include/hw/ppc/spapr.h      |  33 +++--
>  include/hw/ppc/spapr_vio.h  |   6 +-
>  16 files changed, 391 insertions(+), 374 deletions(-)
> 
> diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c
> index 4e464bd..5a27740 100644
> --- a/hw/char/spapr_vty.c
> +++ b/hw/char/spapr_vty.c
> @@ -74,7 +74,7 @@ static void spapr_vty_realize(VIOsPAPRDevice *sdev, Error **errp)
>  }
>  
>  /* Forward declaration */
> -static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr,
> +static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPRMachineState *sm,
>                                      target_ulong opcode, target_ulong *args)

Phew, this patch is really hugh, ... mainly just because of the
renaming. Could you maybe keep the "spapr" as parameter name everywhere
instead of "sm"? (i.e. use "sPAPRMachineState *spapr" as parameter?)
That should IMHO be fine, too, and it would decrease the size of the
patch drastically. (And it likely does not break other patches so badly
which are currently pending)

 Thomas

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] spapr: Merge sPAPREnvironment into sPAPRMachineState
  2015-05-07  8:13   ` Thomas Huth
@ 2015-05-26  1:14     ` David Gibson
  0 siblings, 0 replies; 12+ messages in thread
From: David Gibson @ 2015-05-26  1:14 UTC (permalink / raw)
  To: Thomas Huth
  Cc: lvivier, mdroth, aik, qemu-devel, agraf, qemu-ppc, bharata,
	afaerber

[-- Attachment #1: Type: text/plain, Size: 2871 bytes --]

On Thu, May 07, 2015 at 10:13:43AM +0200, Thomas Huth wrote:
> On Thu,  7 May 2015 13:57:01 +1000
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > The code for -machine pseries maintains a global sPAPREnvironment structure
> > which keeps track of general state information about the guest platform.
> > This predates the existence of the MachineState structure, but performs
> > basically the same function.
> > 
> > Now that we have the generic MachineState, fold sPAPREnvironment into
> > sPAPRMachineState, the pseries specific subclass of MachineState.
> > 
> > This is mostly a matter of search and replace, although a few places which
> > relied on the global spapr variable are changed to find the structure via
> > qdev_get_machine().
> > 
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> >  hw/char/spapr_vty.c         |  14 +-
> >  hw/intc/xics.c              |  42 +++---
> >  hw/intc/xics_kvm.c          |   2 +-
> >  hw/net/spapr_llan.c         |  20 +--
> >  hw/nvram/spapr_nvram.c      |   8 +-
> >  hw/ppc/spapr.c              | 339 +++++++++++++++++++++-----------------------
> >  hw/ppc/spapr_events.c       |  37 ++---
> >  hw/ppc/spapr_hcall.c        |  44 +++---
> >  hw/ppc/spapr_iommu.c        |   8 +-
> >  hw/ppc/spapr_pci.c          |  91 ++++++------
> >  hw/ppc/spapr_rtas.c         |  66 ++++-----
> >  hw/ppc/spapr_rtc.c          |  12 +-
> >  hw/ppc/spapr_vio.c          |  31 ++--
> >  include/hw/pci-host/spapr.h |  12 +-
> >  include/hw/ppc/spapr.h      |  33 +++--
> >  include/hw/ppc/spapr_vio.h  |   6 +-
> >  16 files changed, 391 insertions(+), 374 deletions(-)
> > 
> > diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c
> > index 4e464bd..5a27740 100644
> > --- a/hw/char/spapr_vty.c
> > +++ b/hw/char/spapr_vty.c
> > @@ -74,7 +74,7 @@ static void spapr_vty_realize(VIOsPAPRDevice *sdev, Error **errp)
> >  }
> >  
> >  /* Forward declaration */
> > -static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr,
> > +static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPRMachineState *sm,
> >                                      target_ulong opcode, target_ulong *args)
> 
> Phew, this patch is really hugh, ... mainly just because of the
> renaming. Could you maybe keep the "spapr" as parameter name everywhere
> instead of "sm"? (i.e. use "sPAPRMachineState *spapr" as parameter?)
> That should IMHO be fine, too, and it would decrease the size of the
> patch drastically. (And it likely does not break other patches so badly
> which are currently pending)

Good call.  I'll respin without the extraneous renames.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 2/4] spapr: Remove obsolete ram_limit field from sPAPRMachineState
  2015-05-07  4:12   ` Alexey Kardashevskiy
  2015-05-07  4:40     ` David Gibson
@ 2015-05-26  1:23     ` David Gibson
  1 sibling, 0 replies; 12+ messages in thread
From: David Gibson @ 2015-05-26  1:23 UTC (permalink / raw)
  To: Alexey Kardashevskiy
  Cc: lvivier, thuth, mdroth, qemu-devel, agraf, qemu-ppc, bharata,
	afaerber

[-- Attachment #1: Type: text/plain, Size: 1310 bytes --]

On Thu, May 07, 2015 at 02:12:58PM +1000, Alexey Kardashevskiy wrote:
> On 05/07/2015 01:57 PM, David Gibson wrote:
> >The ram_limit field was imported from sPAPREnvironment where it predates
> >the machine's ram size being available generically from machine->ram_size.
> >
> >Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> >---
> >  hw/ppc/spapr.c         | 3 +--
> >  hw/ppc/spapr_hcall.c   | 3 ++-
> >  include/hw/ppc/spapr.h | 1 -
> >  3 files changed, 3 insertions(+), 4 deletions(-)
> >
> >diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> >index 601c41b..1123358 100644
> >--- a/hw/ppc/spapr.c
> >+++ b/hw/ppc/spapr.c
> >@@ -1496,9 +1496,8 @@ static void ppc_spapr_init(MachineState *machine)
> >      }
> >
> >      /* allocate RAM */
> >-    sm->ram_limit = ram_size;
> 
> 
> 
> I had to look at the code to realize that ram_size is local and it can
> actually be removed.

Actually.. it's worse than that.  There's both a global and this local
which was masking it.  Luckily the local had the same value, but it's
still nasty.

Respin will clean this up better.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 3/4] spapr: Remove obsolete entry_point field from sPAPRMachineState
  2015-05-07  4:50   ` Bharata B Rao
@ 2015-05-26  1:39     ` David Gibson
  0 siblings, 0 replies; 12+ messages in thread
From: David Gibson @ 2015-05-26  1:39 UTC (permalink / raw)
  To: Bharata B Rao
  Cc: lvivier, thuth, mdroth, aik, qemu-devel, agraf, qemu-ppc,
	afaerber

[-- Attachment #1: Type: text/plain, Size: 2340 bytes --]

On Thu, May 07, 2015 at 10:20:03AM +0530, Bharata B Rao wrote:
> On Thu, May 07, 2015 at 01:57:03PM +1000, David Gibson wrote:
> > The sPAPRMachineState structure includes an entry_point field containing
> > the initial PC value for starting the machine, even though this always has
> > the value 0x100.
> > 
> > I think this is a hangover from very early versions which bypassed the
> > firmware when using -kernel.  In any case it has no function now, so remove
> > it.
> > 
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> >  hw/ppc/spapr.c         | 4 +---
> >  include/hw/ppc/spapr.h | 2 +-
> >  2 files changed, 2 insertions(+), 4 deletions(-)
> > 
> > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> > index 1123358..c4c7a07 100644
> > --- a/hw/ppc/spapr.c
> > +++ b/hw/ppc/spapr.c
> > @@ -928,7 +928,7 @@ static void ppc_spapr_reset(void)
> >      first_ppc_cpu->env.gpr[3] = sm->fdt_addr;
> >      first_ppc_cpu->env.gpr[5] = 0;
> >      first_cpu->halted = 0;
> > -    first_ppc_cpu->env.nip = sm->entry_point;
> > +    first_ppc_cpu->env.nip = SPAPR_ENTRY_POINT;
> > 
> >  }
> > 
> > @@ -1641,8 +1641,6 @@ static void ppc_spapr_init(MachineState *machine)
> >      }
> >      g_free(filename);
> > 
> > -    sm->entry_point = 0x100;
> > -
> >      /* FIXME: Should register thigs through the MachineState's qdev
> >       * interface, this is a legacy from the sPAPREnvironment structure
> >       * which predated MachineState but had a similar function */
> > diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
> > index 9e7cf0f..108ff45 100644
> > --- a/include/hw/ppc/spapr.h
> > +++ b/include/hw/ppc/spapr.h
> > @@ -13,6 +13,7 @@ typedef struct sPAPRConfigureConnectorState sPAPRConfigureConnectorState;
> >  typedef struct sPAPREventLogEntry sPAPREventLogEntry;
> > 
> >  #define HPTE64_V_HPTE_DIRTY     0x0000000000000040ULL
> > +#define SPAPR_ENTRY_POINT	0x100
> 
> checkpatch.pl complains about the use of tab here.

Thanks, fixed.

> Other than that I did a quick compile and VM boot test, things look ok.
> 
> Regards,
> Bharata.
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-05-26  2:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-07  3:57 [Qemu-devel] [PATCH 0/4] sPAPRMachineState cleanups David Gibson
2015-05-07  3:57 ` [Qemu-devel] [PATCH 1/4] spapr: Merge sPAPREnvironment into sPAPRMachineState David Gibson
2015-05-07  8:13   ` Thomas Huth
2015-05-26  1:14     ` David Gibson
2015-05-07  3:57 ` [Qemu-devel] [PATCH 2/4] spapr: Remove obsolete ram_limit field from sPAPRMachineState David Gibson
2015-05-07  4:12   ` Alexey Kardashevskiy
2015-05-07  4:40     ` David Gibson
2015-05-26  1:23     ` David Gibson
2015-05-07  3:57 ` [Qemu-devel] [PATCH 3/4] spapr: Remove obsolete entry_point " David Gibson
2015-05-07  4:50   ` Bharata B Rao
2015-05-26  1:39     ` David Gibson
2015-05-07  3:57 ` [Qemu-devel] [PATCH 4/4] spapr: Add sPAPRMachineClass David Gibson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).