qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Isaku Yamahata <yamahata@valinux.co.jp>
To: Juan Quintela <quintela@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 08/58] vmstate: be able to store/save a pci device from a pointer
Date: Fri, 25 Feb 2011 11:47:12 +0900	[thread overview]
Message-ID: <20110225024712.GF31001@valinux.co.jp> (raw)
In-Reply-To: <cf1dd44ceabdfbdeed3b0edc2244376ea80edee5.1298569508.git.quintela@redhat.com>

On Thu, Feb 24, 2011 at 06:57:05PM +0100, Juan Quintela wrote:
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  hw/hw.h |    8 ++++++++
>  1 files changed, 8 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/hw.h b/hw/hw.h
> index 0dfc053..f874dd0 100644
> --- a/hw/hw.h
> +++ b/hw/hw.h
> @@ -609,6 +609,14 @@ extern const VMStateDescription vmstate_pci_device;
>      .offset     = vmstate_offset_value(_state, _field, PCIDevice),   \
>  }
> 
> +#define VMSTATE_PCI_DEVICE_POINTER(_field, _state) {                 \
> +    .name       = (stringify(_field)),                               \
> +    .size       = sizeof(PCIDevice),                                 \
> +    .vmsd       = &vmstate_pci_device,                               \
> +    .flags      = VMS_STRUCT|VMS_POINTER,                            \
> +    .offset     = vmstate_offset_pointer(_state, _field, PCIDevice), \
> +}
> +
>  extern const VMStateDescription vmstate_pcie_device;
> 
>  #define VMSTATE_PCIE_DEVICE(_field, _state) {                        \
> -- 
> 1.7.4

There are only two users and it would be better to embedded PCIDevice
Something like this. I did only compile test.

thanks,

diff --git a/hw/ppc4xx_pci.c b/hw/ppc4xx_pci.c
index f62f1f9..fc76cf7 100644
--- a/hw/ppc4xx_pci.c
+++ b/hw/ppc4xx_pci.c
@@ -48,11 +48,11 @@ struct PCITargetMap {
 #define PPC4xx_PCI_NR_PTMS 2
 
 struct PPC4xxPCIState {
+    PCIDevice pci_dev;
     struct PCIMasterMap pmm[PPC4xx_PCI_NR_PMMS];
     struct PCITargetMap ptm[PPC4xx_PCI_NR_PTMS];
 
     PCIHostState pci_state;
-    PCIDevice *pci_dev;
 };
 typedef struct PPC4xxPCIState PPC4xxPCIState;
 
@@ -290,7 +290,7 @@ static void ppc4xx_pci_save(QEMUFile *f, void *opaque)
     PPC4xxPCIState *controller = opaque;
     int i;
 
-    pci_device_save(controller->pci_dev, f);
+    pci_device_save(&controller->pci_dev, f);
 
     for (i = 0; i < PPC4xx_PCI_NR_PMMS; i++) {
         qemu_put_be32s(f, &controller->pmm[i].la);
@@ -313,7 +313,7 @@ static int ppc4xx_pci_load(QEMUFile *f, void *opaque, int version_id)
     if (version_id != 1)
         return -EINVAL;
 
-    pci_device_load(controller->pci_dev, f);
+    pci_device_load(&controller->pci_dev, f);
 
     for (i = 0; i < PPC4xx_PCI_NR_PMMS; i++) {
         qemu_get_be32s(f, &controller->pmm[i].la);
@@ -337,22 +337,22 @@ PCIBus *ppc4xx_pci_init(CPUState *env, qemu_irq pci_irqs[4],
                         target_phys_addr_t special_cycle,
                         target_phys_addr_t registers)
 {
+    PCIBus *pci_bus;
+    PCIDevice *pci_dev;
     PPC4xxPCIState *controller;
     int index;
     static int ppc4xx_pci_id;
     uint8_t *pci_conf;
 
-    controller = qemu_mallocz(sizeof(PPC4xxPCIState));
+    pci_bus = pci_register_bus(NULL, "pci",
+                               ppc4xx_pci_set_irq, ppc4xx_pci_map_irq,
+                               pci_irqs, 0, 4);
 
-    controller->pci_state.bus = pci_register_bus(NULL, "pci",
-                                                 ppc4xx_pci_set_irq,
-                                                 ppc4xx_pci_map_irq,
-                                                 pci_irqs, 0, 4);
+    pci_dev = pci_register_device(pci_bus, "host bridge",
+                                  sizeof(PPC4xxPCIState), 0, NULL, NULL);
+    controller = DO_UPCAST(PPC4xxPCIState, pci_dev, pci_dev);
 
-    controller->pci_dev = pci_register_device(controller->pci_state.bus,
-                                              "host bridge", sizeof(PCIDevice),
-                                              0, NULL, NULL);
-    pci_conf = controller->pci_dev->config;
+    pci_conf = controller->pci_dev.config;
     pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_IBM);
     pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_IBM_440GX);
     pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_OTHER);
@@ -381,7 +381,7 @@ PCIBus *ppc4xx_pci_init(CPUState *env, qemu_irq pci_irqs[4],
     qemu_register_reset(ppc4xx_pci_reset, controller);
 
     /* XXX load/save code not tested. */
-    register_savevm(&controller->pci_dev->qdev, "ppc4xx_pci", ppc4xx_pci_id++,
+    register_savevm(&controller->pci_dev.qdev, "ppc4xx_pci", ppc4xx_pci_id++,
                     1, ppc4xx_pci_save, ppc4xx_pci_load, controller);
 
     return controller->pci_state.bus;
diff --git a/hw/ppce500_pci.c b/hw/ppce500_pci.c
index 11edd03..eb88a59 100644
--- a/hw/ppce500_pci.c
+++ b/hw/ppce500_pci.c
@@ -73,11 +73,11 @@ struct pci_inbound {
 };
 
 struct PPCE500PCIState {
+    PCIDevice pci_dev;
     struct pci_outbound pob[PPCE500_PCI_NR_POBS];
     struct pci_inbound pib[PPCE500_PCI_NR_PIBS];
     uint32_t gasket_time;
     PCIHostState pci_state;
-    PCIDevice *pci_dev;
 };
 
 typedef struct PPCE500PCIState PPCE500PCIState;
@@ -221,7 +221,7 @@ static void ppce500_pci_save(QEMUFile *f, void *opaque)
     PPCE500PCIState *controller = opaque;
     int i;
 
-    pci_device_save(controller->pci_dev, f);
+    pci_device_save(&controller->pci_dev, f);
 
     for (i = 0; i < PPCE500_PCI_NR_POBS; i++) {
         qemu_put_be32s(f, &controller->pob[i].potar);
@@ -247,7 +247,7 @@ static int ppce500_pci_load(QEMUFile *f, void *opaque, int version_id)
     if (version_id != 1)
         return -EINVAL;
 
-    pci_device_load(controller->pci_dev, f);
+    pci_device_load(&controller->pci_dev, f);
 
     for (i = 0; i < PPCE500_PCI_NR_POBS; i++) {
         qemu_get_be32s(f, &controller->pob[i].potar);
@@ -269,28 +269,24 @@ static int ppce500_pci_load(QEMUFile *f, void *opaque, int version_id)
 
 PCIBus *ppce500_pci_init(qemu_irq pci_irqs[4], target_phys_addr_t registers)
 {
+    PCIBus *pci_bus;
     PPCE500PCIState *controller;
     PCIDevice *d;
     int index;
     static int ppce500_pci_id;
 
-    controller = qemu_mallocz(sizeof(PPCE500PCIState));
-
-    controller->pci_state.bus = pci_register_bus(NULL, "pci",
-                                                 mpc85xx_pci_set_irq,
-                                                 mpc85xx_pci_map_irq,
-                                                 pci_irqs, PCI_DEVFN(0x11, 0),
-                                                 4);
-    d = pci_register_device(controller->pci_state.bus,
-                            "host bridge", sizeof(PCIDevice),
+    pci_bus = pci_register_bus(NULL, "pci",
+                               mpc85xx_pci_set_irq, mpc85xx_pci_map_irq,
+                               pci_irqs, PCI_DEVFN(0x11, 0), 4);
+    d = pci_register_device(pci_bus, "host bridge", sizeof(PPCE500PCIState),
                             0, NULL, NULL);
+    controller = DO_UPCAST(PPCE500PCIState, pci_dev, d);
+    controller->pci_state.bus = pci_bus;
 
     pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_FREESCALE);
     pci_config_set_device_id(d->config, PCI_DEVICE_ID_MPC8533E);
     pci_config_set_class(d->config, PCI_CLASS_PROCESSOR_POWERPC);
 
-    controller->pci_dev = d;
-
     /* CFGADDR */
     index = pci_host_conf_register_mmio(&controller->pci_state,
                                         DEVICE_BIG_ENDIAN);


-- 
yamahata

  reply	other threads:[~2011-02-25  2:47 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-24 17:56 [Qemu-devel] [PATCH 00/58] VMState: Port several non-pc devices Juan Quintela
2011-02-24 17:56 ` [Qemu-devel] [PATCH 01/58] vmstate: add VMSTATE_UINT32_EQUAL Juan Quintela
2011-02-24 17:56 ` [Qemu-devel] [PATCH 02/58] vmstate: Fix varrays with uint8 indexes Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 03/58] vmstate: add UINT32 VARRAYS Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 04/58] vmstate: add VMSTATE_STRUCT_VARRAY_INT32 Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 05/58] vmstate: add VMSTATE_INT64_ARRAY Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 06/58] vmstate: add VMSTATE_STRUCT_VARRAY_UINT32 Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 07/58] vmstate: Add a way to send a partial array Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 08/58] vmstate: be able to store/save a pci device from a pointer Juan Quintela
2011-02-25  2:47   ` Isaku Yamahata [this message]
2011-02-24 17:57 ` [Qemu-devel] [PATCH 09/58] vmstate: move timers to use test instead of version Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 10/58] vmstate: port adb_kbd Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 11/58] vmstate: port adb_mouse Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 12/58] vmstate: port ads7846 Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 13/58] vmstate: port m48t59 Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 14/58] vmstate: port mipsnet Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 15/58] vmstate: port arm sp804 Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 16/58] vmstate: port arm_timer Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 17/58] vmstate: port sysborg_timer Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 18/58] vmstate: port pmtimer Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 19/58] vmstate: port syborg_rtc Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 20/58] vmstate: port pxa2xx_pic Juan Quintela
2011-03-03 14:24   ` andrzej zaborowski
2011-03-09 11:42     ` [Qemu-devel] " Juan Quintela
2011-03-10  4:44       ` andrzej zaborowski
2011-02-24 17:57 ` [Qemu-devel] [PATCH 21/58] vmstate: port pxa2xx_keypad Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 22/58] vmstate: port pl011 Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 23/58] vmstate: port armv7m nvic Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 24/58] vmstate: port stellaris i2c Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 25/58] vmstate: port stellaris ssi bus Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 26/58] vmstate: port stellaris sys Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 27/58] vmstate: port pl022 ssp Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 28/58] vmstate: port heathrow_pic Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 29/58] vmstate: port cuda Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 30/58] vmstate: port stellaris gptm Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 31/58] vmstate: port pxa2xx_i2s Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 32/58] vmstate: port pxa2xx_cm Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 33/58] vmstate: port pxa2xx_mm Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 34/58] vmstate: port pxa2xx_pm Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 35/58] vmstate: port pxa2xx_rtc Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 36/58] vmstate: port ppce500_pci Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 37/58] vmstate: port ppc4xx_pci Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 38/58] vmstate: port syborg_pointer Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 39/58] vmstate: port stellaris_adc Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 40/58] vmstate: port syborg_serial Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 41/58] vmstate: port syborg_keyboard Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 42/58] vmstate: port stellaris gamepad Juan Quintela
2011-02-26 10:56   ` Blue Swirl
2011-02-26 14:12     ` [Qemu-devel] " Juan Quintela
2011-02-26 16:32       ` Blue Swirl
2011-02-24 17:57 ` [Qemu-devel] [PATCH 43/58] vmstate: stellaris use unused for placeholder entries Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 44/58] pxa2xx_dma: make req array static Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 45/58] vmstate: port pxa2xx_dma Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 46/58] pxa2xx_lcd: name anonymous struct Juan Quintela
2011-02-26 10:06   ` Blue Swirl
2011-02-24 17:57 ` [Qemu-devel] [PATCH 47/58] pxa2xx_lcd: up field is used as a bool and migrated as an uint8_t Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 48/58] vmstate: port pxa2xx_lcdc Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 49/58] max111x: input field is only used as uint8_t Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 50/58] vmstate: port max111x Juan Quintela
2011-02-26 10:16   ` Blue Swirl
2011-02-24 17:57 ` [Qemu-devel] [PATCH 51/58] nand: pin values are uint8_t Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 52/58] vmstate: port nand Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 53/58] mac_nvram: size is a size, no need to be a target dependent type Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 54/58] vmstate: port mac_nvram Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 55/58] piix4: create PIIX4State Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 56/58] vmstate: port piix4 Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 57/58] mac_dbdma: create DBDMAState instead of passing one array around Juan Quintela
2011-02-24 17:57 ` [Qemu-devel] [PATCH 58/58] vmstate: port mac_dbdma Juan Quintela
2011-02-26  9:45   ` Blue Swirl
2011-02-26 11:10 ` [Qemu-devel] [PATCH 00/58] VMState: Port several non-pc devices Blue Swirl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110225024712.GF31001@valinux.co.jp \
    --to=yamahata@valinux.co.jp \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).