From patchwork Mon Sep 14 15:49:22 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 33591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id E342BB7C0A for ; Tue, 15 Sep 2009 02:07:48 +1000 (EST) Received: from localhost ([127.0.0.1]:59083 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MnE5i-0007k5-5y for incoming@patchwork.ozlabs.org; Mon, 14 Sep 2009 12:07:46 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MnDoF-0004gX-E0 for qemu-devel@nongnu.org; Mon, 14 Sep 2009 11:49:43 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MnDoA-0004b7-NG for qemu-devel@nongnu.org; Mon, 14 Sep 2009 11:49:41 -0400 Received: from [199.232.76.173] (port=54820 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MnDo9-0004an-Ag for qemu-devel@nongnu.org; Mon, 14 Sep 2009 11:49:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15311) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MnDo8-0007W7-Ri for qemu-devel@nongnu.org; Mon, 14 Sep 2009 11:49:37 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8EFnZWM028363 for ; Mon, 14 Sep 2009 11:49:36 -0400 Received: from zweiblum.home.kraxel.org (vpn1-5-94.ams2.redhat.com [10.36.5.94]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n8EFnU03016965; Mon, 14 Sep 2009 11:49:31 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 56E4C700E4; Mon, 14 Sep 2009 17:49:25 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 14 Sep 2009 17:49:22 +0200 Message-Id: <1252943364-32705-8-git-send-email-kraxel@redhat.com> In-Reply-To: <1252943364-32705-1-git-send-email-kraxel@redhat.com> References: <1252943364-32705-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 7/9] ide/isa: convert to qdev. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Gerd Hoffmann --- hw/ide.h | 4 +- hw/ide/isa.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++------- hw/mips_r4k.c | 2 +- hw/pc.c | 3 +- hw/ppc_prep.c | 2 +- 5 files changed, 58 insertions(+), 14 deletions(-) diff --git a/hw/ide.h b/hw/ide.h index e0a508b..0e7d540 100644 --- a/hw/ide.h +++ b/hw/ide.h @@ -4,8 +4,8 @@ #include "qdev.h" /* ide-isa.c */ -void isa_ide_init(int iobase, int iobase2, qemu_irq irq, - DriveInfo *hd0, DriveInfo *hd1); +int isa_ide_init(int iobase, int iobase2, int isairq, + DriveInfo *hd0, DriveInfo *hd1); /* ide-pci.c */ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table, diff --git a/hw/ide/isa.c b/hw/ide/isa.c index ec2d6fb..d2fe0c0 100644 --- a/hw/ide/isa.c +++ b/hw/ide/isa.c @@ -24,6 +24,7 @@ */ #include #include +#include #include "block.h" #include "block_int.h" #include "sysemu.h" @@ -35,7 +36,12 @@ /* ISA IDE definitions */ typedef struct ISAIDEState { - IDEBus *bus; + ISADevice dev; + IDEBus *bus; + uint32_t iobase; + uint32_t iobase2; + uint32_t isairq; + qemu_irq irq; } ISAIDEState; static void isa_ide_save(QEMUFile* f, void *opaque) @@ -57,15 +63,54 @@ static int isa_ide_load(QEMUFile* f, void *opaque, int version_id) return 0; } -void isa_ide_init(int iobase, int iobase2, qemu_irq irq, - DriveInfo *hd0, DriveInfo *hd1) +static int isa_ide_initfn(ISADevice *dev) { + ISAIDEState *s = DO_UPCAST(ISAIDEState, dev, dev); + + s->bus = ide_bus_new(&s->dev.qdev); + ide_init_ioport(s->bus, s->iobase, s->iobase2); + isa_init_irq(dev, &s->irq, s->isairq); + ide_init2(s->bus, NULL, NULL, s->irq); + register_savevm("isa-ide", 0, 3, isa_ide_save, isa_ide_load, s); + return 0; +}; + +int isa_ide_init(int iobase, int iobase2, int isairq, + DriveInfo *hd0, DriveInfo *hd1) +{ + ISADevice *dev; ISAIDEState *s; - s = qemu_mallocz(sizeof(*s)); - s->bus = qemu_mallocz(sizeof(IDEBus)); + dev = isa_create("isa-ide"); + qdev_prop_set_uint32(&dev->qdev, "iobase", iobase); + qdev_prop_set_uint32(&dev->qdev, "iobase2", iobase2); + qdev_prop_set_uint32(&dev->qdev, "irq", isairq); + if (qdev_init(&dev->qdev) != 0) + return -1; - ide_init2(s->bus, hd0, hd1, irq); - ide_init_ioport(s->bus, iobase, iobase2); - register_savevm("isa-ide", 0, 3, isa_ide_save, isa_ide_load, s); + s = DO_UPCAST(ISAIDEState, dev, dev); + if (hd0) + ide_create_drive(s->bus, 0, hd0); + if (hd1) + ide_create_drive(s->bus, 1, hd1); + return 0; +} + +static ISADeviceInfo isa_ide_info = { + .qdev.name = "isa-ide", + .qdev.size = sizeof(ISAIDEState), + .init = isa_ide_initfn, + .qdev.props = (Property[]) { + DEFINE_PROP_HEX32("iobase", ISAIDEState, iobase, 0x1f0), + DEFINE_PROP_HEX32("iobase2", ISAIDEState, iobase2, 0x3f6), + DEFINE_PROP_UINT32("irq", ISAIDEState, isairq, 14), + DEFINE_PROP_END_OF_LIST(), + }, +}; + +static void isa_ide_register_devices(void) +{ + isa_qdev_register(&isa_ide_info); } + +device_init(isa_ide_register_devices) diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c index d801417..fcc7fed 100644 --- a/hw/mips_r4k.c +++ b/hw/mips_r4k.c @@ -274,7 +274,7 @@ void mips_r4k_init (ram_addr_t ram_size, } for(i = 0; i < MAX_IDE_BUS; i++) - isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]], + isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i], hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]); diff --git a/hw/pc.c b/hw/pc.c index bb78f0b..58de372 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -1366,8 +1366,7 @@ static void pc_init1(ram_addr_t ram_size, pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1); } else { for(i = 0; i < MAX_IDE_BUS; i++) { - isa_ide_init(ide_iobase[i], ide_iobase2[i], - isa_reserve_irq(ide_irq[i]), + isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i], hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]); } } diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c index 1930146..6001c86 100644 --- a/hw/ppc_prep.c +++ b/hw/ppc_prep.c @@ -707,7 +707,7 @@ static void ppc_prep_init (ram_addr_t ram_size, } for(i = 0; i < MAX_IDE_BUS; i++) { - isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]], + isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i], hd[2 * i], hd[2 * i + 1]); }