Skip to contentSkip to conversation

Write cmos hd data for ide drives using -device parm

PATCH Superseded Bruce Rogers 1 participant 1 message Apr 10, 2010

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

Bruce

 hw/ide/internal.h |    1  
 hw/ide/piix.c     |    2 + 
 hw/ide/qdev.c     |    9 ++++++- 
 hw/pc.c           |   68 ++++++++++++++++++++++++++++++++---------------------- 
 sysemu.h          |    1  
 vl.c              |    6 ++++ 
 6 files changed, 59 insertions(+), 28 deletions(-) 
hw/ide/internal.h +1 -0
index 027029e..b04232c 100644 
@@ -450,6 +450,7 @@ struct IDEBus { 
     IDEState ifs[2]; 
     uint8_t unit; 
     uint8_t cmd; 
+    uint8_t id; 
     qemu_irq irq; 
 }; 
  
hw/ide/piix.c +2 -0
index 295a93d..f62aadb 100644 
@@ -136,6 +136,8 @@ static int pci_piix_ide_initfn(PCIIDEState *d) 
     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 +8 -1
index b18693d..632eccd 100644 
@@ -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
index d0effa0..564d477 100644 
@@ -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
index ea79ac4..8ab3349 100644 
@@ -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]; 
@@ -275,6 +276,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"); 
@@ -2624,6 +2629,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;