scsi: move dinfo to SCSIDevice
[qemu-kvm/amd-iommu.git] / hw / scsi.h
blob788c4591738aea8ef58f458c370e753c405e3a78
1 #ifndef QEMU_HW_SCSI_H
2 #define QEMU_HW_SCSI_H
4 #include "qdev.h"
5 #include "block.h"
7 #define SCSI_CMD_BUF_SIZE 16
9 /* scsi-disk.c */
10 enum scsi_reason {
11 SCSI_REASON_DONE, /* Command complete. */
12 SCSI_REASON_DATA /* Transfer complete, more data required. */
15 typedef struct SCSIBus SCSIBus;
16 typedef struct SCSIDevice SCSIDevice;
17 typedef struct SCSIDeviceInfo SCSIDeviceInfo;
18 typedef void (*scsi_completionfn)(SCSIBus *bus, int reason, uint32_t tag,
19 uint32_t arg);
21 enum SCSIXferMode {
22 SCSI_XFER_NONE, /* TEST_UNIT_READY, ... */
23 SCSI_XFER_FROM_DEV, /* READ, INQUIRY, MODE_SENSE, ... */
24 SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */
27 typedef struct SCSISense {
28 uint8_t key;
29 } SCSISense;
31 typedef struct SCSIRequest {
32 SCSIBus *bus;
33 SCSIDevice *dev;
34 uint32_t tag;
35 uint32_t lun;
36 struct {
37 uint8_t buf[SCSI_CMD_BUF_SIZE];
38 int len;
39 size_t xfer;
40 uint64_t lba;
41 enum SCSIXferMode mode;
42 } cmd;
43 BlockDriverAIOCB *aiocb;
44 QTAILQ_ENTRY(SCSIRequest) next;
45 } SCSIRequest;
47 struct SCSIDevice
49 DeviceState qdev;
50 uint32_t id;
51 DriveInfo *dinfo;
52 SCSIDeviceInfo *info;
53 QTAILQ_HEAD(, SCSIRequest) requests;
54 int blocksize;
55 int type;
56 struct SCSISense sense;
59 /* cdrom.c */
60 int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
61 int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
63 /* scsi-bus.c */
64 typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
65 struct SCSIDeviceInfo {
66 DeviceInfo qdev;
67 scsi_qdev_initfn init;
68 void (*destroy)(SCSIDevice *s);
69 int32_t (*send_command)(SCSIDevice *s, uint32_t tag, uint8_t *buf,
70 int lun);
71 void (*read_data)(SCSIDevice *s, uint32_t tag);
72 int (*write_data)(SCSIDevice *s, uint32_t tag);
73 void (*cancel_io)(SCSIDevice *s, uint32_t tag);
74 uint8_t *(*get_buf)(SCSIDevice *s, uint32_t tag);
77 typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
78 int unit);
79 struct SCSIBus {
80 BusState qbus;
81 int busnr;
83 int tcq, ndev;
84 scsi_completionfn complete;
86 SCSIDevice *devs[8];
89 void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
90 scsi_completionfn complete);
91 void scsi_qdev_register(SCSIDeviceInfo *info);
93 static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
95 return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
98 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit);
99 void scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
101 void scsi_dev_clear_sense(SCSIDevice *dev);
102 void scsi_dev_set_sense(SCSIDevice *dev, uint8_t key);
104 SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun);
105 SCSIRequest *scsi_req_find(SCSIDevice *d, uint32_t tag);
106 void scsi_req_free(SCSIRequest *req);
108 int scsi_req_parse(SCSIRequest *req, uint8_t *buf);
110 #endif