From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 20/23] pc: Fix CMOS info for drives defined with -device
Date: Fri, 2 Jul 2010 18:38:29 +0200 [thread overview]
Message-ID: <1278088712-12302-21-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1278088712-12302-1-git-send-email-kwolf@redhat.com>
From: Markus Armbruster <armbru@redhat.com>
Drives defined with -drive if=ide get get created along with the IDE
controller, inside machine->init(). That's before cmos_init().
Drives defined with -device get created during generic device init.
That's after cmos_init(). Because of that, CMOS has no information on
them (type, geometry, translation). Older versions of Windows such as
XP reportedly choke on that.
Split off the part of CMOS initialization that needs to know about
-device devices, and turn it into a reset handler, so it runs after
device creation.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide.h | 2 +
hw/ide/qdev.c | 7 ++++
hw/pc.c | 94 +++++++++++++++++++++++++++++++++++---------------------
hw/pc.h | 3 +-
hw/pc_piix.c | 16 +++++++---
5 files changed, 81 insertions(+), 41 deletions(-)
diff --git a/hw/ide.h b/hw/ide.h
index 82b3c11..2b5ae7c 100644
--- a/hw/ide.h
+++ b/hw/ide.h
@@ -24,4 +24,6 @@ void mmio_ide_init (target_phys_addr_t membase, target_phys_addr_t membase2,
qemu_irq irq, int shift,
DriveInfo *hd0, DriveInfo *hd1);
+void ide_get_bs(BlockDriverState *bs[], BusState *qbus);
+
#endif /* HW_IDE_H */
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index b34c473..2977a16 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -88,6 +88,13 @@ IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive)
return DO_UPCAST(IDEDevice, qdev, dev);
}
+void ide_get_bs(BlockDriverState *bs[], BusState *qbus)
+{
+ IDEBus *bus = DO_UPCAST(IDEBus, qbus, qbus);
+ bs[0] = bus->master ? bus->master->conf.bs : NULL;
+ bs[1] = bus->slave ? bus->slave->conf.bs : NULL;
+}
+
/* --------------------------------- */
typedef struct IDEDrive {
diff --git a/hw/pc.c b/hw/pc.c
index 25ebafa..b577fb1 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -25,6 +25,7 @@
#include "pc.h"
#include "apic.h"
#include "fdc.h"
+#include "ide.h"
#include "pci.h"
#include "vmware_vga.h"
#include "monitor.h"
@@ -275,14 +276,65 @@ static int pc_boot_set(void *opaque, const char *boot_device)
return set_boot_dev(opaque, boot_device, 0);
}
-/* hd_table must contain 4 block drivers */
+typedef struct pc_cmos_init_late_arg {
+ ISADevice *rtc_state;
+ BusState *idebus0, *idebus1;
+} pc_cmos_init_late_arg;
+
+static void pc_cmos_init_late(void *opaque)
+{
+ pc_cmos_init_late_arg *arg = opaque;
+ ISADevice *s = arg->rtc_state;
+ int val;
+ BlockDriverState *hd_table[4];
+ int i;
+
+ ide_get_bs(hd_table, arg->idebus0);
+ ide_get_bs(hd_table + 2, arg->idebus1);
+
+ rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0));
+ if (hd_table[0])
+ cmos_init_hd(0x19, 0x1b, hd_table[0], s);
+ if (hd_table[1])
+ cmos_init_hd(0x1a, 0x24, hd_table[1], s);
+
+ val = 0;
+ for (i = 0; i < 4; i++) {
+ if (hd_table[i]) {
+ int cylinders, heads, sectors, translation;
+ /* NOTE: bdrv_get_geometry_hint() returns the physical
+ geometry. It is always such that: 1 <= sects <= 63, 1
+ <= heads <= 16, 1 <= cylinders <= 16383. The BIOS
+ geometry can be different if a translation is done. */
+ translation = bdrv_get_translation_hint(hd_table[i]);
+ if (translation == BIOS_ATA_TRANSLATION_AUTO) {
+ bdrv_get_geometry_hint(hd_table[i], &cylinders, &heads, §ors);
+ if (cylinders <= 1024 && heads <= 16 && sectors <= 63) {
+ /* No translation. */
+ translation = 0;
+ } else {
+ /* LBA translation. */
+ translation = 1;
+ }
+ } else {
+ translation--;
+ }
+ val |= translation << (i * 2);
+ }
+ }
+ rtc_set_memory(s, 0x39, val);
+
+ qemu_unregister_reset(pc_cmos_init_late, opaque);
+}
+
void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
- const char *boot_device, DriveInfo **hd_table,
+ const char *boot_device,
+ BusState *idebus0, BusState *idebus1,
FDCtrl *floppy_controller, ISADevice *s)
{
int val;
int fd0, fd1, nb;
- int i;
+ static pc_cmos_init_late_arg arg;
/* various important CMOS locations needed by PC/Bochs bios */
@@ -351,38 +403,10 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
rtc_set_memory(s, REG_EQUIPMENT_BYTE, val);
/* hard drives */
-
- rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0));
- if (hd_table[0])
- cmos_init_hd(0x19, 0x1b, hd_table[0]->bdrv, s);
- if (hd_table[1])
- cmos_init_hd(0x1a, 0x24, hd_table[1]->bdrv, s);
-
- val = 0;
- for (i = 0; i < 4; i++) {
- if (hd_table[i]) {
- int cylinders, heads, sectors, translation;
- /* NOTE: bdrv_get_geometry_hint() returns the physical
- geometry. It is always such that: 1 <= sects <= 63, 1
- <= heads <= 16, 1 <= cylinders <= 16383. The BIOS
- geometry can be different if a translation is done. */
- translation = bdrv_get_translation_hint(hd_table[i]->bdrv);
- if (translation == BIOS_ATA_TRANSLATION_AUTO) {
- bdrv_get_geometry_hint(hd_table[i]->bdrv, &cylinders, &heads, §ors);
- if (cylinders <= 1024 && heads <= 16 && sectors <= 63) {
- /* No translation. */
- translation = 0;
- } else {
- /* LBA translation. */
- translation = 1;
- }
- } else {
- translation--;
- }
- val |= translation << (i * 2);
- }
- }
- rtc_set_memory(s, 0x39, val);
+ arg.rtc_state = s;
+ arg.idebus0 = idebus0;
+ arg.idebus1 = idebus1;
+ qemu_register_reset(pc_cmos_init_late, &arg);
}
static void handle_a20_line_change(void *opaque, int irq, int level)
diff --git a/hw/pc.h b/hw/pc.h
index ccfd7ad..63b0249 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -104,7 +104,8 @@ void pc_init_ne2k_isa(NICInfo *nd);
void pc_audio_init (PCIBus *pci_bus, qemu_irq *pic);
#endif
void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
- const char *boot_device, DriveInfo **hd_table,
+ const char *boot_device,
+ BusState *ide0, BusState *ide1,
FDCtrl *floppy_controller, ISADevice *s);
void pc_pci_device_init(PCIBus *pci_bus);
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index f670fd7..519e8a5 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -79,6 +79,7 @@ static void pc_init1(ram_addr_t ram_size,
IsaIrqState *isa_irq_state;
DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
FDCtrl *floppy_controller;
+ BusState *idebus[MAX_IDE_BUS];
ISADevice *rtc_state;
pc_cpus_init(cpu_model);
@@ -132,18 +133,23 @@ static void pc_init1(ram_addr_t ram_size,
}
if (pci_enabled) {
- pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
+ PCIDevice *dev;
+ dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
+ idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
+ idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
} else {
for(i = 0; i < MAX_IDE_BUS; i++) {
- isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
- hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
+ ISADevice *dev;
+ dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
+ hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
+ idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
}
}
pc_audio_init(pci_enabled ? pci_bus : NULL, isa_irq);
- pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device, hd,
- floppy_controller, rtc_state);
+ pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
+ idebus[0], idebus[1], floppy_controller, rtc_state);
if (pci_enabled && usb_enabled) {
usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
--
1.6.6.1
next prev parent reply other threads:[~2010-07-02 16:39 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-02 16:38 [Qemu-devel] [PULL 00/23] Block patches Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 01/23] qcow2: Fix error handling during metadata preallocation Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 02/23] block: allow filenames with colons again for host devices Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 03/23] scsi: scsi_bus_legacy_handle_cmdline() can fail, fix callers Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 04/23] ide: Make it explicit that ide_create_drive() can't fail Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 05/23] blockdev: Remove drive_get_serial() Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 06/23] Don't reset bs->is_temporary in bdrv_open_common Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 07/23] blockdev: New drive_get_by_blockdev() Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 08/23] blockdev: Clean up automatic drive deletion Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 09/23] qdev: Decouple qdev_prop_drive from DriveInfo Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 10/23] blockdev: drive_get_by_id() is no longer used, remove Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 11/23] block: Catch attempt to attach multiple devices to a blockdev Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 12/23] qemu-option: New qemu_opts_reset() Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 13/23] blkdebug: Fix set_state_opts definition Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 14/23] blkdebug: Free QemuOpts after having read the config Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 15/23] blkdebug: Initialize state as 1 Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 16/23] savevm: Survive hot-unplug of snapshot device Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 17/23] block: Clean up bdrv_snapshots() Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 18/23] block: Fix virtual media change for if=none Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 19/23] ide: Make PIIX and ISA IDE init functions return the qdev Kevin Wolf
2010-07-02 16:38 ` Kevin Wolf [this message]
2010-07-02 16:38 ` [Qemu-devel] [PATCH 21/23] qemu-img: avoid calling exit(1) to release resources properly Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 22/23] block: Fix early failure in multiwrite Kevin Wolf
2010-07-02 16:38 ` [Qemu-devel] [PATCH 23/23] block: Handle multiwrite errors only when all requests have completed Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1278088712-12302-21-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).