ahci: Make ich9-ahci migratable
cover ahci: Make ich9-ahci migratable
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
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(-)
Signature · 1 line
1.7.7
RFC 1/2 ahci: Refactor ports as a fixed-size array for VMState
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.
--- hw/ide/ahci.c | 3 +-- hw/ide/ahci.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)
hw/ide/ahci.c +1 -2
@@ -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)
hw/ide/ahci.h +1 -1
@@ -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 */
Signature · 1 line
1.7.7
RFC 2/2 ahci: Add migration support for ICH9
In reply to Andreas FärberIntroduce generic vmstate_ahci and VMSTATE_AHCI macro. Resolve name conflict and hook it up for ich9-ahci.
--- hw/ide/ahci.c | 41 +++++++++++++++++++++++++++++++++++++++++ hw/ide/ahci.h | 10 ++++++++++ hw/ide/ich.c | 11 ++++++++--- 3 files changed, 59 insertions(+), 3 deletions(-)
hw/ide/ahci.c +41 -0
@@ -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 () + }, +};
hw/ide/ahci.h +10 -0
@@ -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;
hw/ide/ich.c +8 -3
@@ -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,
Signature · 1 line
1.7.7