Write cmos hd data for ide drives using -device parm
PATCH v2 1/1 Write cmos hd data for ide drives using -device parm
When specifying ide devices using -device, the cmos information which the bios depends on is not written. This patch generalizes the cmos hd data setting for the existing code path and adds the ability to call that code on a per machine, per ide drive basis.
This is important for older guests, such as Windows XP, and Windows Server 2003.
I needed to add an id to the IDEBus structure since there wasn't a way to identify whether an ide bus was primary or secondary in the lower level code.
v2:Fixed same issue for isapc machine type (previous patch addressed pc machine types only). Additionally, the bus naming needed to be fixed in the isa case to be able to reference the secondary ide bus in -device nomenclature.
Bruce
hw/ide/internal.h | 3 +- hw/ide/isa.c | 8 +++++- hw/ide/piix.c | 6 +++- hw/ide/qdev.c | 13 +++++++--- hw/pc.c | 68 ++++++++++++++++++++++++++++++++---------------------- sysemu.h | 1 vl.c | 6 ++++ 7 files changed, 71 insertions(+), 34 deletions(-)
hw/ide/internal.h +2 -1
@@ -450,6 +450,7 @@ struct IDEBus {IDEState ifs[2 ];uint8_t unit;uint8_t cmd; +uint8_t id;qemu_irq irq; };
@@ -565,7 +566,7 @@ void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,void ide_init_ioport (IDEBus *bus,int iobase,int iobase2);/* hw/ide/qdev.c */ -void ide_bus_new (IDEBus *idebus,DeviceState *dev); +void ide_bus_new (IDEBus *idebus,DeviceState *dev,const char *name);IDEDevice *ide_create_drive (IDEBus *bus,int unit,DriveInfo *drive);#endif /* HW_IDE_INTERNAL_H */
hw/ide/isa.c +7 -1
@@ -67,7 +67,13 @@ static int isa_ide_initfn(ISADevice *dev) {ISAIDEState *s =DO_UPCAST (ISAIDEState, dev, dev); -ide_bus_new (&s->bus, &s->dev.qdev); +if (s->iobase ==0x1f0 ) { +ide_bus_new (&s->bus, &s->dev.qdev,"ide.0" ); + s->bus.id =0 ; + }else { +ide_bus_new (&s->bus, &s->dev.qdev,"ide.1" ); + s->bus.id =1 ; + }ide_init_ioport (&s->bus, s->iobase, s->iobase2);isa_init_irq (dev, &s->irq, s->isairq);ide_init2 (&s->bus,NULL ,NULL , s->irq);
hw/ide/piix.c +4 -2
@@ -131,11 +131,13 @@ static int pci_piix_ide_initfn(PCIIDEState *d)vmstate_register (0 , &vmstate_ide_pci, d); -ide_bus_new (&d->bus[0 ], &d->dev.qdev); -ide_bus_new (&d->bus[1 ], &d->dev.qdev); +ide_bus_new (&d->bus[0 ], &d->dev.qdev,NULL ); +ide_bus_new (&d->bus[1 ], &d->dev.qdev,NULL );ide_init_ioport (&d->bus[0 ],0x1f0 ,0x3f6 );ide_init_ioport (&d->bus[1 ],0x170 ,0x376 ); + d->bus[0 ].id =0 ; + d->bus[1 ].id =1 ;ide_init2 (&d->bus[0 ],NULL ,NULL ,isa_reserve_irq (14 ));ide_init2 (&d->bus[1 ],NULL ,NULL ,isa_reserve_irq (15 ));return 0 ;
hw/ide/qdev.c +10 -3
@@ -29,9 +29,9 @@ static struct BusInfo ide_bus_info = { .size = sizeof(IDEBus), }; -void ide_bus_new (IDEBus *idebus,DeviceState *dev) +void ide_bus_new (IDEBus *idebus,DeviceState *dev,const char *name) { -qbus_create_inplace (&idebus->qbus, &ide_bus_info, dev,NULL ); +qbus_create_inplace (&idebus->qbus, &ide_bus_info, dev, name); }static int ide_qdev_init (DeviceState *qdev,DeviceInfo *base)
@@ -39,6 +39,7 @@ static int ide_qdev_init(DeviceState *qdev, DeviceInfo *base)IDEDevice *dev =DO_UPCAST (IDEDevice, qdev, qdev);IDEDeviceInfo *info =DO_UPCAST (IDEDeviceInfo, qdev, base);IDEBus *bus =DO_UPCAST (IDEBus, qbus, qdev->parent_bus); +int i;if (!dev->conf.dinfo) {fprintf (stderr,"%s: no drive specified\n" , qdev->info->name);
@@ -65,7 +66,13 @@ static int ide_qdev_init(DeviceState *qdev, DeviceInfo *base)default : goto err; } -return info->init (dev); + dev->dinfo->bus = bus->id; + dev->dinfo->unit = dev->unit; + i = info->init (dev); +if (i >=0 ) { +machine_ide_finalize (dev->dinfo); + } +return i; err:return -1 ;
hw/pc.c +41 -27
90 lines not on this page · raw message
sysemu.h +1 -0
@@ -242,5 +242,6 @@ void usb_info(Monitor *mon);void rtc_change_mon_event (struct tm *tm);void register_devices (void ); +extern void (*machine_ide_finalize)(DriveInfo *dinfo);#endif
vl.c +6 -0
@@ -228,6 +228,7 @@ int ctrl_grab = 0;unsigned int nb_prom_envs =0 ;const char *prom_envs[MAX_PROM_ENVS ];int boot_menu; +void (*machine_ide_finalize)(DriveInfo *dinfo);int nb_numa_nodes;uint64_t node_mem[MAX_NODES ];
@@ -269,6 +270,10 @@ static struct { { .driver = "vmware-svga", .flag = &default_vga }, }; +static void default_ide_finalize (DriveInfo *dinfo) +{ +} +static int default_driver_check (QemuOpts *opts,void *opaque) {const char *driver =qemu_opt_get (opts,"driver" );
@@ -2615,6 +2620,7 @@ int main(int argc, char **argv, char **envp)module_call_init (MODULE_INIT_MACHINE ); machine =find_default_machine (); + machine_ide_finalize = default_ide_finalize; cpu_model =NULL ; initrd_filename =NULL ; ram_size =0 ;
Hi,
Quoted 4 lines
When specifying ide devices using -device, the cmos information which the bios depends on is not written. This patch generalizes the cmos hd data setting for the existing code path and adds the ability to call that code on a per machine, per ide drive basis.
Hmm.
With -device and thus alot of device setup happening after QEMUMachine->init() I think it would be very useful to have QEMUMachine->init_late(). There are a bunch of machine specific jobs which need to be done after all devices have been plugged into the machine.
Setting up cmos is one of them.
i440fx_init_memory_mappings() could be moved there, which would allow to add vga cards via -device.
And I'm pretty sure there are more use cases. fw_cfg maybe?
Comments?
cheers,
Gerd
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Gerd Hoffmann
Hi,
Quoted 4 lines
When specifying ide devices using -device, the cmos information which the bios depends on is not written. This patch generalizes the cmos hd data setting for the existing code path and adds the ability to call that code on a per machine, per ide drive basis.
Hmm.
With -device and thus alot of device setup happening after
QEMUMachine->init()I think it would be very useful to haveQEMUMachine->init_late(). There are a bunch of machine specific jobs which need to be done after all devices have been plugged into the machine.Setting up cmos is one of them.
i440fx_init_memory_mappings()could be moved there, which would allow to add vga cards via -device.
Quoted 6 lines
And I'm pretty sure there are more use cases.
fw_cfgmaybe?Comments?
cheers,
Gerd
Not much traffic on this thread ;-)
I can see the usefulness of an init_late() to generalize post device setup issues.
I assume then that you didn't have any other issues with my patch, other than general code structure concerns?
Bruce
Hi,
Quoted 1 line
Not much traffic on this thread ;-)
Indeed ;)
Quoted 2 lines
I can see the usefulness of an
init_late()to generalize post device setup issues.
I assume then that you didn't have any other issues with my patch, other than general code structure concerns?
Yes, that is the major one. I think it is much saner to just have a init_late() and collect everything there instead of creating a new hook each time you figure you need one.
I think this also allows to make the ide changes less intrusive as all the cmos setup logic stays local to pc.c. pc.c can simply keep a pointer to the DeviceState structs of the ide interface(s) created in pc_init1(). pc_init_late() then can check which drives are plugged in and update cmos accordingly.
cheers,
Gerd
Quoted 4 lines · Gerd Hoffmann
Hi,
Quoted 1 line
Not much traffic on this thread ;-)
Quoted 8 lines
Indeed ;)
Quoted 2 lines
I can see the usefulness of an
init_late()to generalize post device setup issues.
I assume then that you didn't have any other issues with my patch, other than general code structure concerns?Yes, that is the major one. I think it is much saner to just have a
init_late()and collect everything there instead of creating a new hook each time you figure you need one.I think this also allows to make the ide changes less intrusive as all the cmos setup logic stays local to
pc.c.pc.ccan simply keep a pointer to the DeviceState structs of the ide interface(s) created inpc_init1().pc_init_late()then can check which drives are plugged in and update cmos accordingly.
I'd personally prefer to see some sort of registration mechanism. Something notifier based.
Regards,
Anthony Liguori
Quoted 6 lines
cheers,
Gerd