1
Description: make sure the CMOS knows about the correct geometry so
2
Windows XP installs properly.
3
Origin: backport, http://git.qemu.org/qemu.git/commit/?id=c0897e0cb94e83ec1098867b81870e4f51f225b9
4
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579166
5
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=588739
6
Bug-Ubuntu: https://bugs.edge.launchpad.net/ubuntu/+source/qemu-kvm/+bug/586175
8
diff -Nur qemu-kvm-0.12.5+noroms/hw/ide/isa.c qemu-kvm-0.12.5+noroms.new/hw/ide/isa.c
9
--- qemu-kvm-0.12.5+noroms/hw/ide/isa.c 2010-07-26 20:43:53.000000000 -0400
10
+++ qemu-kvm-0.12.5+noroms.new/hw/ide/isa.c 2010-09-15 20:22:37.000000000 -0400
15
-int isa_ide_init(int iobase, int iobase2, int isairq,
16
- DriveInfo *hd0, DriveInfo *hd1)
17
+ISADevice *isa_ide_init(int iobase, int iobase2, int isairq,
18
+ DriveInfo *hd0, DriveInfo *hd1)
23
qdev_prop_set_uint32(&dev->qdev, "iobase2", iobase2);
24
qdev_prop_set_uint32(&dev->qdev, "irq", isairq);
25
if (qdev_init(&dev->qdev) < 0)
29
s = DO_UPCAST(ISAIDEState, dev, dev);
31
ide_create_drive(&s->bus, 0, hd0);
33
ide_create_drive(&s->bus, 1, hd1);
38
static ISADeviceInfo isa_ide_info = {
39
diff -Nur qemu-kvm-0.12.5+noroms/hw/ide/piix.c qemu-kvm-0.12.5+noroms.new/hw/ide/piix.c
40
--- qemu-kvm-0.12.5+noroms/hw/ide/piix.c 2010-07-26 20:43:53.000000000 -0400
41
+++ qemu-kvm-0.12.5+noroms.new/hw/ide/piix.c 2010-09-15 20:22:37.000000000 -0400
44
/* hd_table must contain 4 block drivers */
45
/* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
46
-void pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
47
+PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
51
dev = pci_create_simple(bus, devfn, "piix3-ide");
52
pci_ide_create_devs(dev, hd_table);
56
/* hd_table must contain 4 block drivers */
57
/* NOTE: for the PIIX4, the IRQs and IOports are hardcoded */
58
-void pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
59
+PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
63
dev = pci_create_simple(bus, devfn, "piix4-ide");
64
pci_ide_create_devs(dev, hd_table);
68
static PCIDeviceInfo piix_ide_info[] = {
69
diff -Nur qemu-kvm-0.12.5+noroms/hw/ide/qdev.c qemu-kvm-0.12.5+noroms.new/hw/ide/qdev.c
70
--- qemu-kvm-0.12.5+noroms/hw/ide/qdev.c 2010-07-26 20:43:53.000000000 -0400
71
+++ qemu-kvm-0.12.5+noroms.new/hw/ide/qdev.c 2010-09-15 20:22:37.000000000 -0400
73
return DO_UPCAST(IDEDevice, qdev, dev);
76
+void ide_get_bs(BlockDriverState *bs[], BusState *qbus)
78
+ IDEBus *bus = DO_UPCAST(IDEBus, qbus, qbus);
79
+ bs[0] = bus->master ? bus->master->dinfo->bdrv : NULL;
80
+ bs[1] = bus->slave ? bus->slave->dinfo->bdrv : NULL;
83
/* --------------------------------- */
85
typedef struct IDEDrive {
86
diff -Nur qemu-kvm-0.12.5+noroms/hw/ide.h qemu-kvm-0.12.5+noroms.new/hw/ide.h
87
--- qemu-kvm-0.12.5+noroms/hw/ide.h 2010-07-26 20:43:53.000000000 -0400
88
+++ qemu-kvm-0.12.5+noroms.new/hw/ide.h 2010-09-15 20:22:37.000000000 -0400
98
-int isa_ide_init(int iobase, int iobase2, int isairq,
99
- DriveInfo *hd0, DriveInfo *hd1);
100
+ISADevice *isa_ide_init(int iobase, int iobase2, int isairq,
101
+ DriveInfo *hd0, DriveInfo *hd1);
104
void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
105
int secondary_ide_enabled);
106
-void pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
107
-void pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
108
+PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
109
+PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
112
int pmac_ide_init (DriveInfo **hd_table, qemu_irq irq,
114
qemu_irq irq, int shift,
115
DriveInfo *hd0, DriveInfo *hd1);
117
+void ide_get_bs(BlockDriverState *bs[], BusState *qbus);
119
#endif /* HW_IDE_H */
120
diff -Nur qemu-kvm-0.12.5+noroms/hw/pc.c qemu-kvm-0.12.5+noroms.new/hw/pc.c
121
--- qemu-kvm-0.12.5+noroms/hw/pc.c 2010-09-15 20:22:28.000000000 -0400
122
+++ qemu-kvm-0.12.5+noroms.new/hw/pc.c 2010-09-15 20:22:37.000000000 -0400
129
#include "vmware_vga.h"
130
#include "usb-uhci.h"
131
@@ -251,15 +252,66 @@
135
-/* hd_table must contain 4 block drivers */
136
+typedef struct pc_cmos_init_late_arg {
137
+ BusState *idebus0, *idebus1;
138
+} pc_cmos_init_late_arg;
140
+static void pc_cmos_init_late(void *opaque)
142
+ pc_cmos_init_late_arg *arg = opaque;
143
+ RTCState *s = rtc_state;
145
+ BlockDriverState *hd_table[4];
148
+ ide_get_bs(hd_table, arg->idebus0);
149
+ ide_get_bs(hd_table + 2, arg->idebus1);
151
+ rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0));
153
+ cmos_init_hd(0x19, 0x1b, hd_table[0]);
155
+ cmos_init_hd(0x1a, 0x24, hd_table[1]);
158
+ for (i = 0; i < 4; i++) {
160
+ int cylinders, heads, sectors, translation;
161
+ /* NOTE: bdrv_get_geometry_hint() returns the physical
162
+ geometry. It is always such that: 1 <= sects <= 63, 1
163
+ <= heads <= 16, 1 <= cylinders <= 16383. The BIOS
164
+ geometry can be different if a translation is done. */
165
+ translation = bdrv_get_translation_hint(hd_table[i]);
166
+ if (translation == BIOS_ATA_TRANSLATION_AUTO) {
167
+ bdrv_get_geometry_hint(hd_table[i], &cylinders, &heads, §ors);
168
+ if (cylinders <= 1024 && heads <= 16 && sectors <= 63) {
169
+ /* No translation. */
172
+ /* LBA translation. */
178
+ val |= translation << (i * 2);
181
+ rtc_set_memory(s, 0x39, val);
183
+ qemu_unregister_reset(pc_cmos_init_late, opaque);
186
static void cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
187
- const char *boot_device, DriveInfo **hd_table)
188
+ const char *boot_device,
189
+ BusState *idebus0, BusState *idebus1)
191
RTCState *s = rtc_state;
192
int nbds, bds[3] = { 0, };
196
+ static pc_cmos_init_late_arg arg;
198
/* various important CMOS locations needed by PC/Bochs bios */
204
- rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0));
206
- cmos_init_hd(0x19, 0x1b, hd_table[0]->bdrv);
208
- cmos_init_hd(0x1a, 0x24, hd_table[1]->bdrv);
211
- for (i = 0; i < 4; i++) {
213
- int cylinders, heads, sectors, translation;
214
- /* NOTE: bdrv_get_geometry_hint() returns the physical
215
- geometry. It is always such that: 1 <= sects <= 63, 1
216
- <= heads <= 16, 1 <= cylinders <= 16383. The BIOS
217
- geometry can be different if a translation is done. */
218
- translation = bdrv_get_translation_hint(hd_table[i]->bdrv);
219
- if (translation == BIOS_ATA_TRANSLATION_AUTO) {
220
- bdrv_get_geometry_hint(hd_table[i]->bdrv, &cylinders, &heads, §ors);
221
- if (cylinders <= 1024 && heads <= 16 && sectors <= 63) {
222
- /* No translation. */
225
- /* LBA translation. */
231
- val |= translation << (i * 2);
234
- rtc_set_memory(s, 0x39, val);
235
+ arg.idebus0 = idebus0;
236
+ arg.idebus1 = idebus1;
237
+ qemu_register_reset(pc_cmos_init_late, &arg);
240
void ioport_set_a20(int enable)
241
@@ -1013,6 +1037,7 @@
243
IsaIrqState *isa_irq_state;
244
DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
245
+ BusState *idebus[MAX_IDE_BUS];
246
DriveInfo *fd[MAX_FD];
249
@@ -1222,11 +1247,16 @@
253
- pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
255
+ dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
256
+ idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
257
+ idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
259
for(i = 0; i < MAX_IDE_BUS; i++) {
260
- isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
261
- hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
263
+ dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
264
+ hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
265
+ idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
269
@@ -1241,7 +1271,8 @@
271
floppy_controller = fdctrl_init_isa(fd);
273
- cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device, hd);
274
+ cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
275
+ idebus[0], idebus[1]);
277
if (pci_enabled && usb_enabled) {
278
usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);