Skip to content

Commit

Permalink
blockdev: New drive_get_next(), replacing qdev_init_bdrv()
Browse files Browse the repository at this point in the history
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 <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
Markus Armbruster authored and kevmw committed Jan 31, 2011
1 parent 1869a65 commit 1383997
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
10 changes: 10 additions & 0 deletions blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions blockdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 4 additions & 3 deletions hw/pl181.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* This code is licenced under the GPL.
*/

#include "blockdev.h"
#include "sysbus.h"
#include "sd.h"

Expand Down Expand Up @@ -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. */
Expand Down
14 changes: 0 additions & 14 deletions hw/qdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions hw/qdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. ***/
Expand Down
7 changes: 4 additions & 3 deletions hw/ssi-sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* This code is licenced under the GNU GPL v2.
*/

#include "blockdev.h"
#include "ssi.h"
#include "sd.h"

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 1383997

Please sign in to comment.