]>
Commit | Line | Data |
---|---|---|
1e37607b GH |
1 | #ifndef QEMU_HW_SCSI_H |
2 | #define QEMU_HW_SCSI_H | |
43b443b6 GH |
3 | |
4 | #include "qdev.h" | |
4c41d2ef | 5 | #include "block.h" |
622b520f | 6 | #include "blockdev.h" |
428c149b | 7 | #include "block_int.h" |
43b443b6 | 8 | |
29362ebe GH |
9 | #define SCSI_CMD_BUF_SIZE 16 |
10 | ||
43b443b6 GH |
11 | /* scsi-disk.c */ |
12 | enum scsi_reason { | |
13 | SCSI_REASON_DONE, /* Command complete. */ | |
14 | SCSI_REASON_DATA /* Transfer complete, more data required. */ | |
15 | }; | |
16 | ||
17 | typedef struct SCSIBus SCSIBus; | |
18 | typedef struct SCSIDevice SCSIDevice; | |
19 | typedef struct SCSIDeviceInfo SCSIDeviceInfo; | |
20 | typedef void (*scsi_completionfn)(SCSIBus *bus, int reason, uint32_t tag, | |
21 | uint32_t arg); | |
22 | ||
97a06435 GH |
23 | enum SCSIXferMode { |
24 | SCSI_XFER_NONE, /* TEST_UNIT_READY, ... */ | |
25 | SCSI_XFER_FROM_DEV, /* READ, INQUIRY, MODE_SENSE, ... */ | |
26 | SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */ | |
27 | }; | |
28 | ||
4c41d2ef GH |
29 | typedef struct SCSIRequest { |
30 | SCSIBus *bus; | |
31 | SCSIDevice *dev; | |
32 | uint32_t tag; | |
89b08ae1 | 33 | uint32_t lun; |
ed3a34a3 | 34 | uint32_t status; |
29362ebe GH |
35 | struct { |
36 | uint8_t buf[SCSI_CMD_BUF_SIZE]; | |
37 | int len; | |
2ec749cb GH |
38 | size_t xfer; |
39 | uint64_t lba; | |
97a06435 | 40 | enum SCSIXferMode mode; |
29362ebe | 41 | } cmd; |
4c41d2ef | 42 | BlockDriverAIOCB *aiocb; |
e8637c90 | 43 | bool enqueued; |
9af99d98 | 44 | QTAILQ_ENTRY(SCSIRequest) next; |
4c41d2ef GH |
45 | } SCSIRequest; |
46 | ||
43b443b6 GH |
47 | struct SCSIDevice |
48 | { | |
49 | DeviceState qdev; | |
50 | uint32_t id; | |
428c149b | 51 | BlockConf conf; |
43b443b6 | 52 | SCSIDeviceInfo *info; |
9af99d98 | 53 | QTAILQ_HEAD(, SCSIRequest) requests; |
b07995e3 | 54 | int blocksize; |
91376656 | 55 | int type; |
43b443b6 GH |
56 | }; |
57 | ||
58 | /* cdrom.c */ | |
59 | int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track); | |
60 | int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num); | |
61 | ||
62 | /* scsi-bus.c */ | |
63 | typedef int (*scsi_qdev_initfn)(SCSIDevice *dev); | |
64 | struct SCSIDeviceInfo { | |
65 | DeviceInfo qdev; | |
66 | scsi_qdev_initfn init; | |
67 | void (*destroy)(SCSIDevice *s); | |
68 | int32_t (*send_command)(SCSIDevice *s, uint32_t tag, uint8_t *buf, | |
69 | int lun); | |
70 | void (*read_data)(SCSIDevice *s, uint32_t tag); | |
71 | int (*write_data)(SCSIDevice *s, uint32_t tag); | |
72 | void (*cancel_io)(SCSIDevice *s, uint32_t tag); | |
73 | uint8_t *(*get_buf)(SCSIDevice *s, uint32_t tag); | |
74 | }; | |
75 | ||
76 | typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv, | |
77 | int unit); | |
78 | struct SCSIBus { | |
79 | BusState qbus; | |
80 | int busnr; | |
81 | ||
82 | int tcq, ndev; | |
83 | scsi_completionfn complete; | |
84 | ||
622b520f | 85 | SCSIDevice *devs[MAX_SCSI_DEVS]; |
43b443b6 GH |
86 | }; |
87 | ||
88 | void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev, | |
89 | scsi_completionfn complete); | |
90 | void scsi_qdev_register(SCSIDeviceInfo *info); | |
91 | ||
92 | static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) | |
93 | { | |
94 | return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus); | |
95 | } | |
96 | ||
f8b6cc00 | 97 | SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, int unit); |
fa66b909 | 98 | int scsi_bus_legacy_handle_cmdline(SCSIBus *bus); |
43b443b6 | 99 | |
89b08ae1 GH |
100 | SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun); |
101 | SCSIRequest *scsi_req_find(SCSIDevice *d, uint32_t tag); | |
102 | void scsi_req_free(SCSIRequest *req); | |
37659e51 | 103 | |
2ec749cb | 104 | int scsi_req_parse(SCSIRequest *req, uint8_t *buf); |
ec766865 | 105 | void scsi_req_print(SCSIRequest *req); |
ed3a34a3 | 106 | void scsi_req_complete(SCSIRequest *req); |
89b08ae1 | 107 | |
43b443b6 | 108 | #endif |