qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: qemu-devel@nongnu.org, lersek@redhat.com
Cc: John Snow <jsnow@redhat.com>, Jan Tomko <jtomko@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [RFC 2/2] hw/i386/pc: reflect an explicitly created, sole FDC in the CMOS
Date: Sat, 20 Jun 2015 04:43:48 +0200	[thread overview]
Message-ID: <1434768228-9167-3-git-send-email-lersek@redhat.com> (raw)
In-Reply-To: <1434768228-9167-1-git-send-email-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 a single,
explicitly created ISA FDC device, if there has been no board default, and
reprogram the CMOS if found.

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>
---
 hw/i386/pc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 1ca0cdd..47a3082 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -333,8 +333,30 @@ static void pc_cmos_init_floppy(ISADevice *rtc_state, ISADevice *floppy)
 typedef struct pc_cmos_init_late_arg {
     ISADevice *rtc_state;
     BusState *idebus[2];
+    ISADevice *board_floppy;
 } 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;
+
+    fdc = object_dynamic_cast(obj, TYPE_ISA_FDC);
+    if (fdc) {
+        if (state->floppy) {
+            state->multiple = true;
+        } else {
+            state->floppy = ISA_DEVICE(obj);
+        }
+    }
+    return 0;
+}
+
 static void pc_cmos_init_late(void *opaque)
 {
     pc_cmos_init_late_arg *arg = opaque;
@@ -372,6 +394,29 @@ static void pc_cmos_init_late(void *opaque)
     }
     rtc_set_memory(s, 0x39, val);
 
+    /*
+     * If the board initialization code created no FDC, but exactly one FDC has
+     * been created since then explicitly, then we configure the CMOS registers
+     * now, in accordance with that one FDC.
+     */
+    if (arg->board_floppy == NULL) {
+        static const char * const paths[] = { "/peripheral",
+            "/peripheral-anon", NULL };
+        const char * const * path;
+        CheckFdcState state = { 0 };
+
+        for (path = paths; *path; ++path) {
+            Object *container;
+
+            container = container_get(qdev_get_machine(), *path);
+            object_child_foreach(container, check_fdc, &state);
+        }
+
+        if (state.floppy && !state.multiple) {
+            pc_cmos_init_floppy(s, state.floppy);
+        }
+    }
+
     qemu_unregister_reset(pc_cmos_init_late, opaque);
 }
 
@@ -447,6 +492,7 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
     arg.rtc_state = s;
     arg.idebus[0] = idebus0;
     arg.idebus[1] = idebus1;
+    arg.board_floppy = floppy;
     qemu_register_reset(pc_cmos_init_late, &arg);
 }
 
-- 
1.8.3.1

  parent reply	other threads:[~2015-06-20  2:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-20  2:43 [Qemu-devel] [RFC 0/2] update CMOS for single hand-created ISA-FDC Laszlo Ersek
2015-06-20  2:43 ` [Qemu-devel] [RFC 1/2] hw/i386/pc: factor out pc_cmos_init_floppy() Laszlo Ersek
2015-06-20  2:43 ` Laszlo Ersek [this message]
2015-06-20  9:54   ` [Qemu-devel] [RFC 2/2] hw/i386/pc: reflect an explicitly created, sole FDC in the CMOS Markus Armbruster
2015-06-22 11:01 ` [Qemu-devel] [RFC 0/2] update CMOS for single hand-created ISA-FDC Ján Tomko

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=1434768228-9167-3-git-send-email-lersek@redhat.com \
    --to=lersek@redhat.com \
    --cc=armbru@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=jtomko@redhat.com \
    --cc=pbonzini@redhat.com \
    --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).