From patchwork Thu Jan 27 12:29:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 80664 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 ozlabs.org (Postfix) with ESMTPS id E2830B7125 for ; Thu, 27 Jan 2011 23:37:11 +1100 (EST) Received: from localhost ([127.0.0.1]:41223 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PiR61-0002F4-2l for incoming@patchwork.ozlabs.org; Thu, 27 Jan 2011 07:37:05 -0500 Received: from [140.186.70.92] (port=52892 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PiQyY-0006tV-TP for qemu-devel@nongnu.org; Thu, 27 Jan 2011 07:29:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PiQyW-0007fF-P3 for qemu-devel@nongnu.org; Thu, 27 Jan 2011 07:29:22 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:58227) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PiQyV-0007e7-TV for qemu-devel@nongnu.org; Thu, 27 Jan 2011 07:29:20 -0500 Received: from blackfin.pond.sub.org (p5B32BFB4.dip.t-dialin.net [91.50.191.180]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 01030276FD9; Thu, 27 Jan 2011 13:29:16 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 5B4B1EC; Thu, 27 Jan 2011 13:29:16 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 27 Jan 2011 13:29:09 +0100 Message-Id: <1296131356-27257-3-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1296131356-27257-1-git-send-email-armbru@redhat.com> References: <1296131356-27257-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: kwolf@redhat.com, stefanha@gmail.com Subject: [Qemu-devel] [PATCH 02/10] blockdev: New drive_get_next(), replacing qdev_init_bdrv() 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 qdev_init_bdrv() doesn't belong into qdev.c; it's about drives, not qdevs. Rename to drive_get_next, move to blockdev.c, drop the bogus DeviceState argument, and return DriveInfo instead of BlockDriverState. Signed-off-by: Markus Armbruster --- blockdev.c | 10 ++++++++++ blockdev.h | 1 + hw/pl181.c | 7 ++++--- hw/qdev.c | 14 -------------- hw/qdev.h | 2 -- hw/ssi-sd.c | 7 ++++--- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/blockdev.c b/blockdev.c index f7f591f..883117a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -93,6 +93,16 @@ int drive_get_max_bus(BlockInterfaceType type) return max_bus; } +/* Get a block device. This should only be used for single-drive devices + (e.g. SD/Floppy/MTD). Multi-disk devices (scsi/ide) should use the + appropriate bus. */ +DriveInfo *drive_get_next(BlockInterfaceType type) +{ + static int next_block_unit[IF_COUNT]; + + return drive_get(type, 0, next_block_unit[type]++); +} + DriveInfo *drive_get_by_blockdev(BlockDriverState *bs) { DriveInfo *dinfo; diff --git a/blockdev.h b/blockdev.h index 4536b5c..5c2144c 100644 --- a/blockdev.h +++ b/blockdev.h @@ -36,6 +36,7 @@ struct DriveInfo { DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit); int drive_get_max_bus(BlockInterfaceType type); +DriveInfo *drive_get_next(BlockInterfaceType type); void drive_uninit(DriveInfo *dinfo); DriveInfo *drive_get_by_blockdev(BlockDriverState *bs); diff --git a/hw/pl181.c b/hw/pl181.c index 3e5f92f..36d9d02 100644 --- a/hw/pl181.c +++ b/hw/pl181.c @@ -7,6 +7,7 @@ * This code is licenced under the GPL. */ +#include "blockdev.h" #include "sysbus.h" #include "sd.h" @@ -449,15 +450,15 @@ static int pl181_init(SysBusDevice *dev) { int iomemtype; pl181_state *s = FROM_SYSBUS(pl181_state, dev); - BlockDriverState *bd; + DriveInfo *dinfo; iomemtype = cpu_register_io_memory(pl181_readfn, pl181_writefn, s, DEVICE_NATIVE_ENDIAN); sysbus_init_mmio(dev, 0x1000, iomemtype); sysbus_init_irq(dev, &s->irq[0]); sysbus_init_irq(dev, &s->irq[1]); - bd = qdev_init_bdrv(&dev->qdev, IF_SD); - s->card = sd_init(bd, 0); + dinfo = drive_get_next(IF_SD); + s->card = sd_init(dinfo ? dinfo->bdrv : NULL, 0); qemu_register_reset(pl181_reset, s); pl181_reset(s); /* ??? Save/restore. */ diff --git a/hw/qdev.c b/hw/qdev.c index 5b8d374..0c94fb2 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -458,20 +458,6 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd) } } -static int next_block_unit[IF_COUNT]; - -/* Get a block device. This should only be used for single-drive devices - (e.g. SD/Floppy/MTD). Multi-disk devices (scsi/ide) should use the - appropriate bus. */ -BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type) -{ - int unit = next_block_unit[type]++; - DriveInfo *dinfo; - - dinfo = drive_get(type, 0, unit); - return dinfo ? dinfo->bdrv : NULL; -} - BusState *qdev_get_child_bus(DeviceState *dev, const char *name) { BusState *bus; diff --git a/hw/qdev.h b/hw/qdev.h index e520aaa..9808f85 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -137,8 +137,6 @@ bool qdev_machine_modified(void); qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); -BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type); - BusState *qdev_get_child_bus(DeviceState *dev, const char *name); /*** Device API. ***/ diff --git a/hw/ssi-sd.c b/hw/ssi-sd.c index a1a63b2..fb4b649 100644 --- a/hw/ssi-sd.c +++ b/hw/ssi-sd.c @@ -7,6 +7,7 @@ * This code is licenced under the GNU GPL v2. */ +#include "blockdev.h" #include "ssi.h" #include "sd.h" @@ -231,11 +232,11 @@ static int ssi_sd_load(QEMUFile *f, void *opaque, int version_id) static int ssi_sd_init(SSISlave *dev) { ssi_sd_state *s = FROM_SSI_SLAVE(ssi_sd_state, dev); - BlockDriverState *bs; + DriveInfo *dinfo; s->mode = SSI_SD_CMD; - bs = qdev_init_bdrv(&dev->qdev, IF_SD); - s->sd = sd_init(bs, 1); + dinfo = drive_get_next(IF_SD); + s->sd = sd_init(dinfo ? dinfo->bdrv : NULL, 1); register_savevm(&dev->qdev, "ssi_sd", -1, 1, ssi_sd_save, ssi_sd_load, s); return 0; }