From patchwork Sat Jun 20 02:43:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 486967 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 920C41401AF for ; Sat, 20 Jun 2015 12:44:32 +1000 (AEST) Received: from localhost ([::1]:60511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z68li-0001Lq-On for incoming@patchwork.ozlabs.org; Fri, 19 Jun 2015 22:44:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36514) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z68lI-0000fL-65 for qemu-devel@nongnu.org; Fri, 19 Jun 2015 22:44:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z68lF-0002FO-W6 for qemu-devel@nongnu.org; Fri, 19 Jun 2015 22:44:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45207) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z68lF-0002EV-OH for qemu-devel@nongnu.org; Fri, 19 Jun 2015 22:44:01 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 56A6F46791F for ; Sat, 20 Jun 2015 02:44:01 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com ([10.10.116.46]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5K2hsex029472; Fri, 19 Jun 2015 22:43:59 -0400 From: Laszlo Ersek To: qemu-devel@nongnu.org, lersek@redhat.com Date: Sat, 20 Jun 2015 04:43:48 +0200 Message-Id: <1434768228-9167-3-git-send-email-lersek@redhat.com> In-Reply-To: <1434768228-9167-1-git-send-email-lersek@redhat.com> References: <1434768228-9167-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: John Snow , Jan Tomko , Markus Armbruster , Paolo Bonzini Subject: [Qemu-devel] [RFC 2/2] hw/i386/pc: reflect an explicitly created, sole FDC in the CMOS X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Cc: John Snow Cc: Markus Armbruster Cc: Paolo Bonzini Reported-by: Jan Tomko Suggested-by: Markus Armbruster Signed-off-by: Laszlo Ersek --- 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); }