qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC 0/2] ahci: Make ich9-ahci migratable
@ 2011-12-23 14:55 Andreas Färber
  2011-12-23 14:55 ` [Qemu-devel] [RFC 1/2] ahci: Refactor ports as a fixed-size array for VMState Andreas Färber
  2011-12-23 14:55 ` [Qemu-devel] [RFC 2/2] ahci: Add migration support for ICH9 Andreas Färber
  0 siblings, 2 replies; 3+ messages in thread
From: Andreas Färber @ 2011-12-23 14:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Mark Langsdorf, Juan Quintela, mjt, Alexander Graf,
	brogers, Andreas Färber

Hello,

Since mjt asked about it, I'm posting a first draft of AHCI migration support
I recently pieced together. Some more pressing issues came up, including
ide-cd being broken with AHCI, so that I have hardly tested this yet.

The initial issue was that the ports were dynamically allocated in ich.c
and I did not find prior art dealing with that in VMState. I therefore
took the easy path of converting it to a statically-sized array, which is
a bit wasteful of course. Better suggestions welcome.

The second part then is a mostly mechanical addition of fields and structs
to VMState, possibly still incomplete.

Happy Holidays,

Andreas

Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Juan Quintela <quintela@redhat.com>

Cc: Alexander Graf <agraf@suse.de>
Cc: Michael Tokarev <mjt@tls.msk.ru>
Cc: Mark Langsdorf <mark.langsdorf@calxeda.com>

Andreas Färber (2):
  ahci: Refactor ports as a fixed-size array for VMState
  ahci: Add migration support for ICH9

 hw/ide/ahci.c |   44 ++++++++++++++++++++++++++++++++++++++++++--
 hw/ide/ahci.h |   12 +++++++++++-
 hw/ide/ich.c  |   11 ++++++++---
 3 files changed, 61 insertions(+), 6 deletions(-)

-- 
1.7.7

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

* [Qemu-devel] [RFC 1/2] ahci: Refactor ports as a fixed-size array for VMState
  2011-12-23 14:55 [Qemu-devel] [RFC 0/2] ahci: Make ich9-ahci migratable Andreas Färber
@ 2011-12-23 14:55 ` Andreas Färber
  2011-12-23 14:55 ` [Qemu-devel] [RFC 2/2] ahci: Add migration support for ICH9 Andreas Färber
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Färber @ 2011-12-23 14:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Juan Quintela, mjt, Alexander Graf, brogers,
	Andreas Färber

It seems, VMState cannot handle a dynamically allocated array of
structs at this time.

Change AHCIState to use an AHCIDevice array of size AHCI_MAX_PORTS.
Of those 32, only 6 are being used for ich9.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Juan Quintela <quintela@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Alexander Graf <agraf@suse.de>
---
 hw/ide/ahci.c |    3 +--
 hw/ide/ahci.h |    2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 0af201d..51cb48b 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -1168,7 +1168,7 @@ void ahci_init(AHCIState *s, DeviceState *qdev, int ports)
     int i;
 
     s->ports = ports;
-    s->dev = g_malloc0(sizeof(AHCIDevice) * ports);
+    memset(s->dev, 0, sizeof(AHCIDevice) * ports);
     ahci_reg_init(s);
     /* XXX BAR size should be 1k, but that breaks, so bump it to 4k for now */
     memory_region_init_io(&s->mem, &ahci_mem_ops, s, "ahci", AHCI_MEM_BAR_SIZE);
@@ -1194,7 +1194,6 @@ void ahci_uninit(AHCIState *s)
 {
     memory_region_destroy(&s->mem);
     memory_region_destroy(&s->idp);
-    g_free(s->dev);
 }
 
 void ahci_reset(void *opaque)
diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h
index b223d2c..4df7c2b 100644
--- a/hw/ide/ahci.h
+++ b/hw/ide/ahci.h
@@ -291,7 +291,7 @@ struct AHCIDevice {
 };
 
 typedef struct AHCIState {
-    AHCIDevice *dev;
+    AHCIDevice dev[AHCI_MAX_PORTS];
     AHCIControlRegs control_regs;
     MemoryRegion mem;
     MemoryRegion idp;       /* Index-Data Pair I/O port space */
-- 
1.7.7

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

* [Qemu-devel] [RFC 2/2] ahci: Add migration support for ICH9
  2011-12-23 14:55 [Qemu-devel] [RFC 0/2] ahci: Make ich9-ahci migratable Andreas Färber
  2011-12-23 14:55 ` [Qemu-devel] [RFC 1/2] ahci: Refactor ports as a fixed-size array for VMState Andreas Färber
@ 2011-12-23 14:55 ` Andreas Färber
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Färber @ 2011-12-23 14:55 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Alexander Graf, mjt, Andreas Färber, brogers

Introduce generic vmstate_ahci and VMSTATE_AHCI macro.
Resolve name conflict and hook it up for ich9-ahci.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Alexander Graf <agraf@suse.de>
---
 hw/ide/ahci.c |   41 +++++++++++++++++++++++++++++++++++++++++
 hw/ide/ahci.h |   10 ++++++++++
 hw/ide/ich.c  |   11 ++++++++---
 3 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 51cb48b..7d1415b 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -1213,3 +1213,44 @@ void ahci_reset(void *opaque)
         ahci_reset_port(&d->ahci, i);
     }
 }
+
+const VMStateDescription vmstate_ahci_device = {
+    .name = "ahci port",
+    .version_id = 1,
+    .fields = (VMStateField []) {
+        VMSTATE_IDE_BUS(port, AHCIDevice),
+        VMSTATE_UINT32(port_state, AHCIDevice),
+        VMSTATE_UINT32(finished, AHCIDevice),
+        VMSTATE_UINT32(port_regs.lst_addr, AHCIDevice),
+        VMSTATE_UINT32(port_regs.lst_addr_hi, AHCIDevice),
+        VMSTATE_UINT32(port_regs.fis_addr, AHCIDevice),
+        VMSTATE_UINT32(port_regs.fis_addr_hi, AHCIDevice),
+        VMSTATE_UINT32(port_regs.irq_stat, AHCIDevice),
+        VMSTATE_UINT32(port_regs.irq_mask, AHCIDevice),
+        VMSTATE_UINT32(port_regs.cmd, AHCIDevice),
+        VMSTATE_UINT32(port_regs.tfdata, AHCIDevice),
+        VMSTATE_UINT32(port_regs.sig, AHCIDevice),
+        VMSTATE_UINT32(port_regs.scr_stat, AHCIDevice),
+        VMSTATE_UINT32(port_regs.scr_ctl, AHCIDevice),
+        VMSTATE_UINT32(port_regs.scr_err, AHCIDevice),
+        VMSTATE_UINT32(port_regs.scr_act, AHCIDevice),
+        VMSTATE_UINT32(port_regs.cmd_issue, AHCIDevice),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
+const VMStateDescription vmstate_ahci = {
+    .name = "ahci",
+    .version_id = 1,
+    .fields = (VMStateField []) {
+        VMSTATE_STRUCT_ARRAY(dev, AHCIState, AHCI_MAX_PORTS, 0,
+                             vmstate_ahci_device, AHCIDevice),
+        VMSTATE_UINT32(control_regs.cap, AHCIState),
+        VMSTATE_UINT32(control_regs.ghc, AHCIState),
+        VMSTATE_UINT32(control_regs.irqstatus, AHCIState),
+        VMSTATE_UINT32(control_regs.impl, AHCIState),
+        VMSTATE_UINT32(control_regs.version, AHCIState),
+        VMSTATE_UINT32(idp_index, AHCIState),
+        VMSTATE_END_OF_LIST()
+    },
+};
diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h
index 4df7c2b..56ee621 100644
--- a/hw/ide/ahci.h
+++ b/hw/ide/ahci.h
@@ -306,6 +306,16 @@ typedef struct AHCIPCIState {
     AHCIState ahci;
 } AHCIPCIState;
 
+extern const VMStateDescription vmstate_ahci;
+
+#define VMSTATE_AHCI(_field, _state) {                               \
+    .name       = (stringify(_field)),                               \
+    .size       = sizeof(AHCIState),                                 \
+    .vmsd       = &vmstate_ahci,                                     \
+    .flags      = VMS_STRUCT,                                        \
+    .offset     = vmstate_offset_value(_state, _field, AHCIState),   \
+}
+
 typedef struct NCQFrame {
     uint8_t fis_type;
     uint8_t c;
diff --git a/hw/ide/ich.c b/hw/ide/ich.c
index 3f7510f..851b6a9 100644
--- a/hw/ide/ich.c
+++ b/hw/ide/ich.c
@@ -79,9 +79,14 @@
 #define ICH9_IDP_INDEX          0x10
 #define ICH9_IDP_INDEX_LOG2     0x04
 
-static const VMStateDescription vmstate_ahci = {
+static const VMStateDescription vmstate_ich9_ahci = {
     .name = "ahci",
-    .unmigratable = 1,
+    .version_id = 1,
+    .fields = (VMStateField []) {
+        VMSTATE_PCI_DEVICE(card, AHCIPCIState),
+        VMSTATE_AHCI(ahci, AHCIPCIState),
+        VMSTATE_END_OF_LIST()
+    },
 };
 
 static int pci_ich9_ahci_init(PCIDevice *dev)
@@ -151,7 +156,7 @@ static PCIDeviceInfo ich_ahci_info[] = {
         .qdev.name    = "ich9-ahci",
         .qdev.alias   = "ahci",
         .qdev.size    = sizeof(AHCIPCIState),
-        .qdev.vmsd    = &vmstate_ahci,
+        .qdev.vmsd    = &vmstate_ich9_ahci,
         .init         = pci_ich9_ahci_init,
         .exit         = pci_ich9_uninit,
         .config_write = pci_ich9_write_config,
-- 
1.7.7

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

end of thread, other threads:[~2011-12-23 14:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-23 14:55 [Qemu-devel] [RFC 0/2] ahci: Make ich9-ahci migratable Andreas Färber
2011-12-23 14:55 ` [Qemu-devel] [RFC 1/2] ahci: Refactor ports as a fixed-size array for VMState Andreas Färber
2011-12-23 14:55 ` [Qemu-devel] [RFC 2/2] ahci: Add migration support for ICH9 Andreas Färber

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).