From patchwork Tue Jun 14 02:37:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 100264 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 89DDBB6FB7 for ; Tue, 14 Jun 2011 14:10:56 +1000 (EST) Received: from localhost ([::1]:35943 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QWKxo-0004pC-K3 for incoming@patchwork.ozlabs.org; Tue, 14 Jun 2011 00:10:52 -0400 Received: from eggs.gnu.org ([140.186.70.92]:57310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QWJW7-0006uV-Ck for qemu-devel@nongnu.org; Mon, 13 Jun 2011 22:38:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QWJW5-0006jA-BN for qemu-devel@nongnu.org; Mon, 13 Jun 2011 22:38:11 -0400 Received: from fmmailgate01.web.de ([217.72.192.221]:51380) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QWJW4-0006iZ-Du for qemu-devel@nongnu.org; Mon, 13 Jun 2011 22:38:08 -0400 Received: from smtp03.web.de ( [172.20.0.65]) by fmmailgate01.web.de (Postfix) with ESMTP id CBCA019186877; Tue, 14 Jun 2011 04:38:07 +0200 (CEST) Received: from [87.173.124.240] (helo=af.local) by smtp03.web.de with asmtp (WEB.DE 4.110 #2) id 1QWJW3-0000Aw-00; Tue, 14 Jun 2011 04:38:07 +0200 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Tue, 14 Jun 2011 04:37:50 +0200 Message-Id: <1308019077-61957-17-git-send-email-andreas.faerber@web.de> X-Mailer: git-send-email 1.7.5.3 In-Reply-To: <1308019077-61957-16-git-send-email-andreas.faerber@web.de> References: <1308019077-61957-1-git-send-email-andreas.faerber@web.de> <1308019077-61957-2-git-send-email-andreas.faerber@web.de> <1308019077-61957-3-git-send-email-andreas.faerber@web.de> <1308019077-61957-4-git-send-email-andreas.faerber@web.de> <1308019077-61957-5-git-send-email-andreas.faerber@web.de> <1308019077-61957-6-git-send-email-andreas.faerber@web.de> <1308019077-61957-7-git-send-email-andreas.faerber@web.de> <1308019077-61957-8-git-send-email-andreas.faerber@web.de> <1308019077-61957-9-git-send-email-andreas.faerber@web.de> <1308019077-61957-10-git-send-email-andreas.faerber@web.de> <1308019077-61957-11-git-send-email-andreas.faerber@web.de> <1308019077-61957-12-git-send-email-andreas.faerber@web.de> <1308019077-61957-13-git-send-email-andreas.faerber@web.de> <1308019077-61957-14-git-send-email-andreas.faerber@web.de> <1308019077-61957-15-git-send-email-andreas.faerber@web.de> <1308019077-61957-16-git-send-email-andreas.faerber@web.de> MIME-Version: 1.0 X-Sender: Andreas.Faerber@web.de X-Provags-ID: V01U2FsdGVkX1/uIGsab3uTqvovnwVqjLgfVN71qenjjHP7YePa FPfFavmmJMr6TRpM/XiDrnJ3OpVC/+vlkDtGHeaxgPRfjPDqYm qytUInRbTnoWjIfk/nlw== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 217.72.192.221 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , Juan Quintela , Gerd Hoffmann , Markus Armbruster Subject: [Qemu-devel] [RFC v5 16/23] fdc: Implement ISA state callbacks 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 Add "enabled" qdev property, and implement enable and disable callbacks. Incorporate ISA VMState as well as I/O base and IRQ as subsection, and implement pre_load and post_load callbacks. Cc: Gerd Hoffmann Cc: Markus Armbruster Cc: Juan Quintela Signed-off-by: Andreas Färber --- hw/fdc.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 88 insertions(+), 3 deletions(-) diff --git a/hw/fdc.c b/hw/fdc.c index f4e3e0d..778fb58 100644 --- a/hw/fdc.c +++ b/hw/fdc.c @@ -431,6 +431,8 @@ typedef struct FDCtrlISABus { struct FDCtrl state; int32_t bootindexA; int32_t bootindexB; + uint32_t initial_iobase; + uint32_t initial_irq; } FDCtrlISABus; static uint32_t fdctrl_read (void *opaque, uint32_t reg) @@ -1894,11 +1896,10 @@ static int fdctrl_init_common(FDCtrl *fdctrl) return fdctrl_connect_drives(fdctrl); } -static int isabus_fdc_init1(ISADevice *dev) +static int isabus_fdc_enable(ISADevice *dev) { FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev); FDCtrl *fdctrl = &isa->state; - int ret; register_ioport_read(isa->iobase + 0x01, 5, 1, &fdctrl_read_port, fdctrl); @@ -1912,7 +1913,58 @@ static int isabus_fdc_init1(ISADevice *dev) isa_init_ioport(dev, isa->iobase + 7); isa_init_irq(&isa->busdev, &fdctrl->irq, isa->irq); + + return 0; +} + +static int isabus_fdc_disable(ISADevice *dev) +{ + FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev); + FDCtrl *fdctrl = &isa->state; + + isa_discard_ioport_range(dev, isa->iobase + 0x07, 1); + isa_discard_ioport_range(dev, isa->iobase + 0x01, 5); + isa_unassign_ioport(isa->iobase + 7, 1); + isa_unassign_ioport(isa->iobase, 6); + + isa_uninit_irq(&isa->busdev, &fdctrl->irq, isa->irq); + fdctrl->irq = NULL; + + return 0; +} + +static int isabus_fdc_pre_load(void *opaque) +{ + FDCtrlISABus *s = opaque; + + isa_set_state(&s->busdev, false); + return 0; +} + +static int isabus_fdc_post_load(void *opaque, int version_id) +{ + FDCtrlISABus *s = opaque; + ISADevice *dev = &s->busdev; + + if (dev->enabled) { + isabus_fdc_enable(dev); + } + return 0; +} + +static int isabus_fdc_init1(ISADevice *dev) +{ + FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev); + FDCtrl *fdctrl = &isa->state; + int ret; + + isa->initial_iobase = isa->iobase; + isa->initial_irq = isa->irq; + fdctrl->dma_chann = isa->dma; + if (dev->enabled) { + isabus_fdc_enable(dev); + } qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 2); ret = fdctrl_init_common(fdctrl); @@ -1960,18 +2012,50 @@ static int sun4m_fdc_init1(SysBusDevice *dev) return fdctrl_init_common(fdctrl); } +static bool isabus_fdc_isaconfig_needed(void *opaque) +{ + FDCtrlISABus *s = opaque; + + return isa_vmstate_needed(&s->busdev) || + s->initial_iobase != s->iobase || + s->initial_irq != s->irq; +} + +static const VMStateDescription vmstate_isa_fdc_isaconfig = { + .name = "fdc/isa-config", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField []) { + VMSTATE_ISA_DEVICE(busdev, FDCtrlISABus), + VMSTATE_UINT32(iobase, FDCtrlISABus), + VMSTATE_UINT32(irq, FDCtrlISABus), + VMSTATE_END_OF_LIST() + }, +}; + static const VMStateDescription vmstate_isa_fdc ={ .name = "fdc", .version_id = 2, .minimum_version_id = 2, + .pre_load = isabus_fdc_pre_load, + .post_load = isabus_fdc_post_load, .fields = (VMStateField []) { VMSTATE_STRUCT(state, FDCtrlISABus, 0, vmstate_fdc, FDCtrl), VMSTATE_END_OF_LIST() - } + }, + .subsections = (VMStateSubsection []) { + { + .vmsd = &vmstate_isa_fdc_isaconfig, + .needed = isabus_fdc_isaconfig_needed, + }, { + } + }, }; static ISADeviceInfo isa_fdc_info = { .init = isabus_fdc_init1, + .enable = isabus_fdc_enable, + .disable = isabus_fdc_disable, .qdev.name = "isa-fdc", .qdev.fw_name = "fdc", .qdev.size = sizeof(FDCtrlISABus), @@ -1986,6 +2070,7 @@ static ISADeviceInfo isa_fdc_info = { DEFINE_PROP_DRIVE("driveB", FDCtrlISABus, state.drives[1].bs), DEFINE_PROP_INT32("bootindexA", FDCtrlISABus, bootindexA, -1), DEFINE_PROP_INT32("bootindexB", FDCtrlISABus, bootindexB, -1), + DEFINE_PROP_BOOL("enabled", FDCtrlISABus, busdev.enabled, true), DEFINE_PROP_END_OF_LIST(), }, };