7 static struct BusInfo scsi_bus_info
= {
9 .size
= sizeof(SCSIBus
),
10 .props
= (Property
[]) {
11 DEFINE_PROP_UINT32("scsi-id", SCSIDevice
, id
, -1),
12 DEFINE_PROP_END_OF_LIST(),
15 static int next_scsi_bus
;
17 /* Create a scsi bus, and attach devices to it. */
18 SCSIBus
*scsi_bus_new(DeviceState
*host
, int tcq
, int ndev
,
19 scsi_completionfn complete
)
23 bus
= FROM_QBUS(SCSIBus
, qbus_create(&scsi_bus_info
, host
, NULL
));
24 bus
->busnr
= next_scsi_bus
++;
27 bus
->complete
= complete
;
31 static int scsi_qdev_init(DeviceState
*qdev
, DeviceInfo
*base
)
33 SCSIDevice
*dev
= DO_UPCAST(SCSIDevice
, qdev
, qdev
);
34 SCSIDeviceInfo
*info
= DO_UPCAST(SCSIDeviceInfo
, qdev
, base
);
35 SCSIBus
*bus
= DO_UPCAST(SCSIBus
, qbus
, dev
->qdev
.parent_bus
);
38 for (dev
->id
= 0; dev
->id
< bus
->ndev
; dev
->id
++) {
39 if (bus
->devs
[dev
->id
] == NULL
)
43 if (dev
->id
>= bus
->ndev
) {
44 qemu_error("bad scsi device id: %d\n", dev
->id
);
48 if (bus
->devs
[dev
->id
]) {
49 bus
->devs
[dev
->id
]->info
->destroy(bus
->devs
[dev
->id
]);
51 bus
->devs
[dev
->id
] = dev
;
54 return dev
->info
->init(dev
);
60 void scsi_qdev_register(SCSIDeviceInfo
*info
)
62 info
->qdev
.bus_info
= &scsi_bus_info
;
63 info
->qdev
.init
= scsi_qdev_init
;
64 qdev_register(&info
->qdev
);
67 /* handle legacy '-drive if=scsi,...' cmd line args */
68 SCSIDevice
*scsi_bus_legacy_add_drive(SCSIBus
*bus
, DriveInfo
*dinfo
, int unit
)
73 driver
= bdrv_is_sg(dinfo
->bdrv
) ? "scsi-generic" : "scsi-disk";
74 dev
= qdev_create(&bus
->qbus
, driver
);
75 qdev_prop_set_uint32(dev
, "scsi-id", unit
);
76 qdev_prop_set_drive(dev
, "drive", dinfo
);
78 return DO_UPCAST(SCSIDevice
, qdev
, dev
);
81 void scsi_bus_legacy_handle_cmdline(SCSIBus
*bus
)
86 for (unit
= 0; unit
< MAX_SCSI_DEVS
; unit
++) {
87 dinfo
= drive_get(IF_SCSI
, bus
->busnr
, unit
);
91 scsi_bus_legacy_add_drive(bus
, dinfo
, unit
);