From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aCTvD-00088Z-Bi for qemu-devel@nongnu.org; Fri, 25 Dec 2015 10:04:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aCTvC-0000at-8O for qemu-devel@nongnu.org; Fri, 25 Dec 2015 10:04:47 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:42471 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aCTvB-0000Z3-NE for qemu-devel@nongnu.org; Fri, 25 Dec 2015 10:04:46 -0500 From: Roman Kagan Date: Fri, 25 Dec 2015 18:04:09 +0300 Message-Id: <1451055852-30910-2-git-send-email-rkagan@virtuozzo.com> In-Reply-To: <1451055852-30910-1-git-send-email-rkagan@virtuozzo.com> References: <1451055852-30910-1-git-send-email-rkagan@virtuozzo.com> Subject: [Qemu-devel] [PATCH v4 1/4] i386/pc: expose identifying the floppy controller List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , qemu-stable@nongnu.org, Roman Kagan , Paolo Bonzini , Igor Mammedov , John Snow , Richard Henderson Factor out and expose the function to locate the floppy controller in the system. It will be useful when dynamically populating the relevant objects in the ACPI tables. Signed-off-by: Roman Kagan Cc: "Michael S. Tsirkin" Cc: Eduardo Habkost Cc: Igor Mammedov Cc: John Snow Cc: Kevin Wolf Cc: Paolo Bonzini Cc: Richard Henderson Cc: qemu-block@nongnu.org Cc: qemu-stable@nongnu.org --- changes since v3: - split out into a separate patch to faciliate review hw/i386/pc.c | 44 ++++++++++++++++++++++++++------------------ include/hw/i386/pc.h | 2 ++ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 459260b..c36b8cf 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -360,6 +360,31 @@ static const char * const fdc_container_path[] = { "/unattached", "/peripheral", "/peripheral-anon" }; +/* + * Locate the FDC at IO address 0x3f0, in order to configure the CMOS registers + * and ACPI objects. + */ +ISADevice *pc_find_fdc0(void) +{ + int i; + Object *container; + CheckFdcState state = { 0 }; + + 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"); + } + + return state.floppy; +} + static void pc_cmos_init_late(void *opaque) { pc_cmos_init_late_arg *arg = opaque; @@ -368,8 +393,6 @@ 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, @@ -399,22 +422,7 @@ 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); + pc_cmos_init_floppy(s, pc_find_fdc0()); qemu_unregister_reset(pc_cmos_init_late, opaque); } diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index b0d6283..8122229 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -267,6 +267,8 @@ typedef void (*cpu_set_smm_t)(int smm, void *arg); void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name); +ISADevice *pc_find_fdc0(void); + /* acpi_piix.c */ I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, -- 2.5.0