From patchwork Thu May 10 20:08:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 158381 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 18B9FB6FA3 for ; Fri, 11 May 2012 06:09:14 +1000 (EST) Received: from localhost ([::1]:51711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSZfj-0002iF-OH for incoming@patchwork.ozlabs.org; Thu, 10 May 2012 16:09:11 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSZfJ-0002Ch-De for qemu-devel@nongnu.org; Thu, 10 May 2012 16:08:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSZfH-0003pm-3U for qemu-devel@nongnu.org; Thu, 10 May 2012 16:08:44 -0400 Received: from thoth.sbs.de ([192.35.17.2]:19638) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSZfG-0003pH-PE for qemu-devel@nongnu.org; Thu, 10 May 2012 16:08:43 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.13.6/8.13.6) with ESMTP id q4AK8eXS023642; Thu, 10 May 2012 22:08:40 +0200 Received: from mchn199C.mchp.siemens.de ([139.22.49.57]) by mail1.siemens.de (8.13.6/8.13.6) with SMTP id q4AK8Tfn009061; Thu, 10 May 2012 22:08:39 +0200 From: Jan Kiszka To: "Michael S. Tsirkin" Date: Thu, 10 May 2012 17:08:20 -0300 Message-Id: <8ff2b34407a51fd38d15ee8e019a3b7e53c21795.1336680504.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.35.17.2 Cc: qemu-devel , Alexander Graf Subject: [Qemu-devel] [PATCH v2 04/10] ahci: Clean up reset functions 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 Properly register reset functions via the device class. CC: Alexander Graf Signed-off-by: Jan Kiszka --- hw/ide/ahci.c | 25 +++++++++++++++---------- hw/ide/ahci.h | 2 +- hw/ide/ich.c | 10 ++++------ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index a883a92..e992d76 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -339,7 +339,7 @@ static void ahci_mem_write(void *opaque, target_phys_addr_t addr, case HOST_CTL: /* R/W */ if (val & HOST_CTL_RESET) { DPRINTF(-1, "HBA Reset\n"); - ahci_reset(container_of(s, AHCIPCIState, ahci)); + ahci_reset(s); } else { s->control_regs.ghc = (val & 0x3) | HOST_CTL_AHCI_EN; ahci_check_irq(s); @@ -1149,21 +1149,20 @@ void ahci_uninit(AHCIState *s) g_free(s->dev); } -void ahci_reset(void *opaque) +void ahci_reset(AHCIState *s) { - struct AHCIPCIState *d = opaque; AHCIPortRegs *pr; int i; - d->ahci.control_regs.irqstatus = 0; - d->ahci.control_regs.ghc = 0; + s->control_regs.irqstatus = 0; + s->control_regs.ghc = 0; - for (i = 0; i < d->ahci.ports; i++) { - pr = &d->ahci.dev[i].port_regs; + for (i = 0; i < s->ports; i++) { + pr = &s->dev[i].port_regs; pr->irq_stat = 0; pr->irq_mask = 0; pr->scr_ctl = 0; - ahci_reset_port(&d->ahci, i); + ahci_reset_port(s, i); } } @@ -1178,6 +1177,13 @@ static const VMStateDescription vmstate_sysbus_ahci = { .unmigratable = 1, }; +static void sysbus_ahci_reset(DeviceState *dev) +{ + SysbusAHCIState *s = DO_UPCAST(SysbusAHCIState, busdev.qdev, dev); + + ahci_reset(&s->ahci); +} + static int sysbus_ahci_init(SysBusDevice *dev) { SysbusAHCIState *s = FROM_SYSBUS(SysbusAHCIState, dev); @@ -1185,8 +1191,6 @@ static int sysbus_ahci_init(SysBusDevice *dev) sysbus_init_mmio(dev, &s->ahci.mem); sysbus_init_irq(dev, &s->ahci.irq); - - qemu_register_reset(ahci_reset, &s->ahci); return 0; } @@ -1203,6 +1207,7 @@ static void sysbus_ahci_class_init(ObjectClass *klass, void *data) sbc->init = sysbus_ahci_init; dc->vmsd = &vmstate_sysbus_ahci; dc->props = sysbus_ahci_properties; + dc->reset = sysbus_ahci_reset; } static TypeInfo sysbus_ahci_info = { diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h index b223d2c..ec1b6a5 100644 --- a/hw/ide/ahci.h +++ b/hw/ide/ahci.h @@ -332,6 +332,6 @@ typedef struct NCQFrame { void ahci_init(AHCIState *s, DeviceState *qdev, int ports); void ahci_uninit(AHCIState *s); -void ahci_reset(void *opaque); +void ahci_reset(AHCIState *s); #endif /* HW_IDE_AHCI_H */ diff --git a/hw/ide/ich.c b/hw/ide/ich.c index 242254e..e7026bb 100644 --- a/hw/ide/ich.c +++ b/hw/ide/ich.c @@ -84,12 +84,12 @@ static const VMStateDescription vmstate_ahci = { .unmigratable = 1, }; -static void pci_ich9_reset(void *opaque) +static void pci_ich9_reset(DeviceState *dev) { - struct AHCIPCIState *d = opaque; + struct AHCIPCIState *d = DO_UPCAST(struct AHCIPCIState, card.qdev, dev); msi_reset(&d->card); - ahci_reset(opaque); + ahci_reset(&d->ahci); } static int pci_ich9_ahci_init(PCIDevice *dev) @@ -110,8 +110,6 @@ static int pci_ich9_ahci_init(PCIDevice *dev) /* XXX Software should program this register */ d->card.config[0x90] = 1 << 6; /* Address Map Register - AHCI mode */ - qemu_register_reset(pci_ich9_reset, d); - msi_init(dev, 0x50, 1, true, false); d->ahci.irq = d->card.irq[0]; @@ -141,7 +139,6 @@ static int pci_ich9_uninit(PCIDevice *dev) d = DO_UPCAST(struct AHCIPCIState, card, dev); msi_uninit(dev); - qemu_unregister_reset(pci_ich9_reset, d); ahci_uninit(&d->ahci); return 0; @@ -167,6 +164,7 @@ static void ich_ahci_class_init(ObjectClass *klass, void *data) k->revision = 0x02; k->class_id = PCI_CLASS_STORAGE_SATA; dc->vmsd = &vmstate_ahci; + dc->reset = pci_ich9_reset; } static TypeInfo ich_ahci_info = {