qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Jan Tomko <jtomko@redhat.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Laszlo Ersek <lersek@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>, John Snow <jsnow@redhat.com>,
	Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PULL 08/13] hw/i386/pc: reflect any FDC @ ioport 0x3f0 in the CMOS
Date: Tue, 7 Jul 2015 15:40:26 +0300	[thread overview]
Message-ID: <1436272760-29611-9-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1436272760-29611-1-git-send-email-mst@redhat.com>

From: Laszlo Ersek <lersek@redhat.com>

With the pc-q35-2.4 machine type, if the user creates an ISA FDC manually:

  -device isa-fdc,driveA=drive-fdc0-0-0 \
  -drive file=...,if=none,id=drive-fdc0-0-0,format=raw

then the board-default FDC will be skipped, and only the explicitly
requested FDC will exist. qtree-wise, this is correct; however such an FDC
is currently not registered in the CMOS, because that code is only reached
for the board-default FDC.

The pc_cmos_init_late() one-shot reset handler -- one-shot because the
CMOS is not reprogrammed during warm reset -- should search for any ISA
FDC devices, created implicitly (by board code) or explicitly, and set the
CMOS accordingly to the ISA FDC(s) with iobase=0x3f0:

- if there is no such FDC, report both drives absent,
- if there is exactly one such FDC, report its drives in the CMOS,
- if there are more than one such FDCs, then pick one (it is not specified
  which one), and print a warning about the ambiguity.

Cc: Jan Tomko <jtomko@redhat.com>
Cc: John Snow <jsnow@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Reported-by: Jan Tomko <jtomko@redhat.com>
Suggested-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/pc.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 55 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 6f1b137..09635cd 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -334,6 +334,41 @@ typedef struct pc_cmos_init_late_arg {
     BusState *idebus[2];
 } pc_cmos_init_late_arg;
 
+typedef struct check_fdc_state {
+    ISADevice *floppy;
+    bool multiple;
+} CheckFdcState;
+
+static int check_fdc(Object *obj, void *opaque)
+{
+    CheckFdcState *state = opaque;
+    Object *fdc;
+    uint32_t iobase;
+    Error *local_err = NULL;
+
+    fdc = object_dynamic_cast(obj, TYPE_ISA_FDC);
+    if (!fdc) {
+        return 0;
+    }
+
+    iobase = object_property_get_int(obj, "iobase", &local_err);
+    if (local_err || iobase != 0x3f0) {
+        error_free(local_err);
+        return 0;
+    }
+
+    if (state->floppy) {
+        state->multiple = true;
+    } else {
+        state->floppy = ISA_DEVICE(obj);
+    }
+    return 0;
+}
+
+static const char * const fdc_container_path[] = {
+    "/unattached", "/peripheral", "/peripheral-anon"
+};
+
 static void pc_cmos_init_late(void *opaque)
 {
     pc_cmos_init_late_arg *arg = opaque;
@@ -342,6 +377,8 @@ static void pc_cmos_init_late(void *opaque)
     int8_t heads, sectors;
     int val;
     int i, trans;
+    Object *container;
+    CheckFdcState state = { 0 };
 
     val = 0;
     if (ide_get_geometry(arg->idebus[0], 0,
@@ -371,6 +408,23 @@ static void pc_cmos_init_late(void *opaque)
     }
     rtc_set_memory(s, 0x39, val);
 
+    /*
+     * Locate the FDC at IO address 0x3f0, and configure the CMOS registers
+     * accordingly.
+     */
+    for (i = 0; i < ARRAY_SIZE(fdc_container_path); i++) {
+        container = container_get(qdev_get_machine(), fdc_container_path[i]);
+        object_child_foreach(container, check_fdc, &state);
+    }
+
+    if (state.multiple) {
+        error_report("warning: multiple floppy disk controllers with "
+                     "iobase=0x3f0 have been found;\n"
+                     "the one being picked for CMOS setup might not reflect "
+                     "your intent");
+    }
+    pc_cmos_init_floppy(s, state.floppy);
+
     qemu_unregister_reset(pc_cmos_init_late, opaque);
 }
 
@@ -440,9 +494,8 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
     val |= 0x02; /* FPU is there */
     val |= 0x04; /* PS/2 mouse installed */
     rtc_set_memory(s, REG_EQUIPMENT_BYTE, val);
-    pc_cmos_init_floppy(s, floppy);
 
-    /* hard drives */
+    /* hard drives and FDC */
     arg.rtc_state = s;
     arg.idebus[0] = idebus0;
     arg.idebus[1] = idebus1;
-- 
MST

  parent reply	other threads:[~2015-07-07 12:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-07 12:40 [Qemu-devel] [PULL 00/13] pc,virtio,pci: fixes and updates Michael S. Tsirkin
2015-07-07 12:40 ` [Qemu-devel] [PULL 01/13] dataplane: fix cross-endian issues Michael S. Tsirkin
2015-07-07 12:40 ` [Qemu-devel] [PULL 02/13] Revert "dataplane: allow virtio-1 devices" Michael S. Tsirkin
2015-07-07 12:40 ` [Qemu-devel] [PULL 03/13] acpi: split out ICH ACPI support Michael S. Tsirkin
2015-07-07 12:40 ` [Qemu-devel] [PULL 04/13] ich9: add TCO interface emulation Michael S. Tsirkin
2015-07-07 12:40 ` [Qemu-devel] [PULL 05/13] tests: add testcase for TCO watchdog emulation Michael S. Tsirkin
2015-07-07 12:40 ` [Qemu-devel] [PULL 06/13] ich9: implement strap SPKR pin logic Michael S. Tsirkin
2015-07-07 12:40 ` [Qemu-devel] [PULL 07/13] hw/i386/pc: factor out pc_cmos_init_floppy() Michael S. Tsirkin
2015-07-07 12:40 ` Michael S. Tsirkin [this message]
2015-07-07 12:40 ` [Qemu-devel] [PULL 09/13] hw/i386/pc: don't carry FDC from pc_basic_device_init() to pc_cmos_init() Michael S. Tsirkin
2015-07-07 12:40 ` [Qemu-devel] [PULL 10/13] virtio_net: reuse constants from linux Michael S. Tsirkin
2015-07-07 12:40 ` [Qemu-devel] [PULL 11/13] pci_regs.h: import " Michael S. Tsirkin
2015-07-07 12:40 ` [Qemu-devel] [PULL 12/13] pcie: Set the "link active" in the link status register Michael S. Tsirkin
2015-07-07 12:40 ` [Qemu-devel] [PULL 13/13] virtio: define virtio_pci_cfg_cap in header Michael S. Tsirkin
2015-07-07 16:18 ` [Qemu-devel] [PULL 00/13] pc,virtio,pci: fixes and updates Peter Maydell

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=1436272760-29611-9-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=armbru@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=jtomko@redhat.com \
    --cc=lersek@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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).