~bdrung/qemu-kvm/caps-lock-key-up-event

« back to all changes in this revision

Viewing changes to debian/patches/fix-CMOS-info-for-drives-defined-with--device.patch

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2010-09-15 19:48:15 UTC
  • Revision ID: james.westby@ubuntu.com-20100915194815-b2viq8zxorqqt2wa
Tags: 0.12.5+noroms-0ubuntu6
debian/fix-CMOS-info-for-drives-defined-with--device.patch: make sure
the CMOS knows about the correct geometry so Windows XP installs
properly. (LP: #586175)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 
 
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
 
11
@@ -75,8 +75,8 @@
 
12
     return 0;
 
13
 };
 
14
 
 
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)
 
19
 {
 
20
     ISADevice *dev;
 
21
     ISAIDEState *s;
 
22
@@ -86,14 +86,14 @@
 
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)
 
26
-        return -1;
 
27
+        return NULL;
 
28
 
 
29
     s = DO_UPCAST(ISAIDEState, dev, dev);
 
30
     if (hd0)
 
31
         ide_create_drive(&s->bus, 0, hd0);
 
32
     if (hd1)
 
33
         ide_create_drive(&s->bus, 1, hd1);
 
34
-    return 0;
 
35
+    return dev;
 
36
 }
 
37
 
 
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
 
42
@@ -158,22 +158,24 @@
 
43
 
 
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)
 
48
 {
 
49
     PCIDevice *dev;
 
50
 
 
51
     dev = pci_create_simple(bus, devfn, "piix3-ide");
 
52
     pci_ide_create_devs(dev, hd_table);
 
53
+    return dev;
 
54
 }
 
55
 
 
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)
 
60
 {
 
61
     PCIDevice *dev;
 
62
 
 
63
     dev = pci_create_simple(bus, devfn, "piix4-ide");
 
64
     pci_ide_create_devs(dev, hd_table);
 
65
+    return dev;
 
66
 }
 
67
 
 
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
 
72
@@ -90,6 +90,13 @@
 
73
     return DO_UPCAST(IDEDevice, qdev, dev);
 
74
 }
 
75
 
 
76
+void ide_get_bs(BlockDriverState *bs[], BusState *qbus)
 
77
+{
 
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;
 
81
+}
 
82
+
 
83
 /* --------------------------------- */
 
84
 
 
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
 
89
@@ -1,17 +1,18 @@
 
90
 #ifndef HW_IDE_H
 
91
 #define HW_IDE_H
 
92
 
 
93
-#include "qdev.h"
 
94
+#include "isa.h"
 
95
+#include "pci.h"
 
96
 
 
97
 /* ide-isa.c */
 
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);
 
102
 
 
103
 /* ide-pci.c */
 
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);
 
110
 
 
111
 /* ide-macio.c */
 
112
 int pmac_ide_init (DriveInfo **hd_table, qemu_irq irq,
 
113
@@ -22,4 +23,6 @@
 
114
                     qemu_irq irq, int shift,
 
115
                     DriveInfo *hd0, DriveInfo *hd1);
 
116
 
 
117
+void ide_get_bs(BlockDriverState *bs[], BusState *qbus);
 
118
+
 
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
 
123
@@ -24,6 +24,7 @@
 
124
 #include "hw.h"
 
125
 #include "pc.h"
 
126
 #include "fdc.h"
 
127
+#include "ide.h"
 
128
 #include "pci.h"
 
129
 #include "vmware_vga.h"
 
130
 #include "usb-uhci.h"
 
131
@@ -251,15 +252,66 @@
 
132
     return(0);
 
133
 }
 
134
 
 
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;
 
139
+
 
140
+static void pc_cmos_init_late(void *opaque)
 
141
+{
 
142
+    pc_cmos_init_late_arg *arg = opaque;
 
143
+    RTCState *s = rtc_state;
 
144
+    int val;
 
145
+    BlockDriverState *hd_table[4];
 
146
+    int i;
 
147
+
 
148
+    ide_get_bs(hd_table, arg->idebus0);
 
149
+    ide_get_bs(hd_table + 2, arg->idebus1);
 
150
+
 
151
+    rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0));
 
152
+    if (hd_table[0])
 
153
+        cmos_init_hd(0x19, 0x1b, hd_table[0]);
 
154
+    if (hd_table[1])
 
155
+        cmos_init_hd(0x1a, 0x24, hd_table[1]);
 
156
+
 
157
+    val = 0;
 
158
+    for (i = 0; i < 4; i++) {
 
159
+        if (hd_table[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, &sectors);
 
168
+                if (cylinders <= 1024 && heads <= 16 && sectors <= 63) {
 
169
+                    /* No translation. */
 
170
+                    translation = 0;
 
171
+                } else {
 
172
+                    /* LBA translation. */
 
173
+                    translation = 1;
 
174
+                }
 
175
+            } else {
 
176
+                translation--;
 
177
+            }
 
178
+            val |= translation << (i * 2);
 
179
+        }
 
180
+    }
 
181
+    rtc_set_memory(s, 0x39, val);
 
182
+
 
183
+    qemu_unregister_reset(pc_cmos_init_late, opaque);
 
184
+}
 
185
+
 
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)
 
190
 {
 
191
     RTCState *s = rtc_state;
 
192
     int nbds, bds[3] = { 0, };
 
193
     int val;
 
194
     int fd0, fd1, nb;
 
195
     int i;
 
196
+    static pc_cmos_init_late_arg arg;
 
197
 
 
198
     /* various important CMOS locations needed by PC/Bochs bios */
 
199
 
 
200
@@ -342,37 +394,9 @@
 
201
 
 
202
     /* hard drives */
 
203
 
 
204
-    rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0));
 
205
-    if (hd_table[0])
 
206
-        cmos_init_hd(0x19, 0x1b, hd_table[0]->bdrv);
 
207
-    if (hd_table[1])
 
208
-        cmos_init_hd(0x1a, 0x24, hd_table[1]->bdrv);
 
209
-
 
210
-    val = 0;
 
211
-    for (i = 0; i < 4; i++) {
 
212
-        if (hd_table[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, &sectors);
 
221
-                if (cylinders <= 1024 && heads <= 16 && sectors <= 63) {
 
222
-                    /* No translation. */
 
223
-                    translation = 0;
 
224
-                } else {
 
225
-                    /* LBA translation. */
 
226
-                    translation = 1;
 
227
-                }
 
228
-            } else {
 
229
-                translation--;
 
230
-            }
 
231
-            val |= translation << (i * 2);
 
232
-        }
 
233
-    }
 
234
-    rtc_set_memory(s, 0x39, val);
 
235
+    arg.idebus0 = idebus0;
 
236
+    arg.idebus1 = idebus1;
 
237
+    qemu_register_reset(pc_cmos_init_late, &arg);
 
238
 }
 
239
 
 
240
 void ioport_set_a20(int enable)
 
241
@@ -1013,6 +1037,7 @@
 
242
     qemu_irq *i8259;
 
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];
 
247
     void *fw_cfg;
 
248
 
 
249
@@ -1222,11 +1247,16 @@
 
250
     }
 
251
 
 
252
     if (pci_enabled) {
 
253
-        pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
 
254
+        PCIDevice *dev;
 
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");
 
258
     } else {
 
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]);
 
262
+            ISADevice *dev;
 
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");
 
266
         }
 
267
     }
 
268
 
 
269
@@ -1241,7 +1271,8 @@
 
270
     }
 
271
     floppy_controller = fdctrl_init_isa(fd);
 
272
 
 
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]);
 
276
 
 
277
     if (pci_enabled && usb_enabled) {
 
278
         usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);