}
}
- /* Add virtio block devices */
- if (pci_enabled) {
- int unit_id = 0;
-
- while ((dinfo = drive_get(IF_VIRTIO, 0, unit_id)) != NULL) {
- pci_dev = pci_create("virtio-blk-pci",
- dinfo->devaddr);
- qdev_init(&pci_dev->qdev);
- unit_id++;
- }
- }
-
/* Add virtio balloon device */
if (pci_enabled && virtio_balloon) {
pci_dev = pci_create("virtio-balloon-pci", virtio_balloon_devaddr);
break;
case IF_VIRTIO:
dev = pci_create("virtio-blk-pci", devaddr);
+ qdev_prop_set_drive(&dev->qdev, "drive", dinfo);
break;
default:
dev = NULL;
{
unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
PCIBus *pcibus;
- PCIDevice *pci_dev;
CPUState *env;
uint64_t elf_entry;
uint64_t elf_lowaddr;
target_ulong dt_base = 0;
void *fdt;
int i;
- DriveInfo *dinfo;
/* Setup CPU. */
env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model);
if (pcibus) {
- int unit_id = 0;
-
- /* Add virtio block devices. */
- while ((dinfo = drive_get(IF_VIRTIO, 0, unit_id)) != NULL) {
- pci_dev = pci_create("virtio-blk-pci", dinfo->devaddr);
- qdev_init(&pci_dev->qdev);
- unit_id++;
- }
-
/* Add virtio console devices */
for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
if (virtcon_hds[i]) {
const char *cpu_model)
{
PCIBus *pci_bus;
- PCIDevice *pci_dev;
CPUState *env;
uint64_t elf_entry;
uint64_t elf_lowaddr;
unsigned int pci_irq_nrs[4] = {1, 2, 3, 4};
qemu_irq *irqs, *mpic, *pci_irqs;
SerialState * serial[2];
- DriveInfo *dinfo;
/* Setup CPU */
env = cpu_ppc_init("e500v2_v30");
isa_mmio_init(MPC8544_PCI_IO, MPC8544_PCI_IOLEN);
if (pci_bus) {
- int unit_id = 0;
-
- /* Add virtio block devices. */
- while ((dinfo = drive_get(IF_VIRTIO, 0, unit_id)) != NULL) {
- pci_dev = pci_create("virtio-blk-pci", dinfo->devaddr);
- qdev_init(&pci_dev->qdev);
- unit_id++;
- }
-
/* Register network interfaces. */
for (i = 0; i < nb_nics; i++) {
pci_nic_init(&nd_table[i], "virtio", NULL);
return 0;
}
-VirtIODevice *virtio_blk_init(DeviceState *dev)
+VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo)
{
VirtIOBlock *s;
int cylinders, heads, secs;
static int virtio_blk_id;
- BlockDriverState *bs;
char *ps;
s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
sizeof(struct virtio_blk_config),
sizeof(VirtIOBlock));
- bs = qdev_init_bdrv(dev, IF_VIRTIO);
s->vdev.get_config = virtio_blk_update_config;
s->vdev.get_features = virtio_blk_get_features;
s->vdev.reset = virtio_blk_reset;
- s->bs = bs;
+ s->bs = dinfo->bdrv;
s->rq = NULL;
- if (strlen(ps = (char *)drive_get_serial(bs)))
+ if (strlen(ps = (char *)drive_get_serial(s->bs)))
strncpy(s->serial_str, ps, sizeof(s->serial_str));
else
snprintf(s->serial_str, sizeof(s->serial_str), "0");
- bs->private = dev;
+ s->bs->private = dev;
bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
bdrv_set_geometry_hint(s->bs, cylinders, heads, secs);
#include "virtio.h"
#include "pci.h"
-//#include "sysemu.h"
+#include "sysemu.h"
#include "msix.h"
#include "net.h"
uint32_t addr;
uint32_t class_code;
uint32_t nvectors;
+ DriveInfo *dinfo;
} VirtIOPCIProxy;
/* virtio device */
proxy->class_code != PCI_CLASS_STORAGE_OTHER)
proxy->class_code = PCI_CLASS_STORAGE_SCSI;
- vdev = virtio_blk_init(&pci_dev->qdev);
+ if (!proxy->dinfo) {
+ fprintf(stderr, "drive property not set\n");
+ }
+ vdev = virtio_blk_init(&pci_dev->qdev, proxy->dinfo);
virtio_init_pci(proxy, vdev,
PCI_VENDOR_ID_REDHAT_QUMRANET,
PCI_DEVICE_ID_VIRTIO_BLOCK,
.name = "class",
.info = &qdev_prop_hex32,
.offset = offsetof(VirtIOPCIProxy, class_code),
+ },{
+ .name = "drive",
+ .info = &qdev_prop_drive,
+ .offset = offsetof(VirtIOPCIProxy, dinfo),
},
{/* end of list */}
},
#include "hw.h"
#include "qdev.h"
+#include "sysemu.h"
/* from Linux's linux/virtio_config.h */
void *opaque);
/* Base devices. */
-VirtIODevice *virtio_blk_init(DeviceState *dev);
+VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo);
VirtIODevice *virtio_net_init(DeviceState *dev);
VirtIODevice *virtio_console_init(DeviceState *dev);
VirtIODevice *virtio_balloon_init(DeviceState *dev);
break;
case IF_PFLASH:
case IF_MTD:
- case IF_VIRTIO:
case IF_NONE:
break;
+ case IF_VIRTIO:
+ /* add virtio block device */
+ opts = qemu_opts_create(&qemu_device_opts, NULL, 0);
+ qemu_opt_set(opts, "driver", "virtio-blk-pci");
+ qemu_opt_set(opts, "drive", dinfo->id);
+ if (devaddr)
+ qemu_opt_set(opts, "addr", devaddr);
+ break;
case IF_COUNT:
abort();
}