root / hw / scsi.h @ 94d3f98a
History | View | Annotate | Download (3.3 kB)
1 |
#ifndef QEMU_HW_SCSI_H
|
---|---|
2 |
#define QEMU_HW_SCSI_H
|
3 |
|
4 |
#include "qdev.h" |
5 |
#include "block.h" |
6 |
#include "block_int.h" |
7 |
|
8 |
#define MAX_SCSI_DEVS 255 |
9 |
|
10 |
#define SCSI_CMD_BUF_SIZE 16 |
11 |
|
12 |
/* scsi-disk.c */
|
13 |
enum scsi_reason {
|
14 |
SCSI_REASON_DONE, /* Command complete. */
|
15 |
SCSI_REASON_DATA /* Transfer complete, more data required. */
|
16 |
}; |
17 |
|
18 |
typedef struct SCSIBus SCSIBus; |
19 |
typedef struct SCSIBusOps SCSIBusOps; |
20 |
typedef struct SCSIDevice SCSIDevice; |
21 |
typedef struct SCSIDeviceInfo SCSIDeviceInfo; |
22 |
typedef struct SCSIRequest SCSIRequest; |
23 |
|
24 |
enum SCSIXferMode {
|
25 |
SCSI_XFER_NONE, /* TEST_UNIT_READY, ... */
|
26 |
SCSI_XFER_FROM_DEV, /* READ, INQUIRY, MODE_SENSE, ... */
|
27 |
SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */
|
28 |
}; |
29 |
|
30 |
struct SCSIRequest {
|
31 |
SCSIBus *bus; |
32 |
SCSIDevice *dev; |
33 |
uint32_t refcount; |
34 |
uint32_t tag; |
35 |
uint32_t lun; |
36 |
uint32_t status; |
37 |
struct {
|
38 |
uint8_t buf[SCSI_CMD_BUF_SIZE]; |
39 |
int len;
|
40 |
size_t xfer; |
41 |
uint64_t lba; |
42 |
enum SCSIXferMode mode;
|
43 |
} cmd; |
44 |
BlockDriverAIOCB *aiocb; |
45 |
bool enqueued;
|
46 |
QTAILQ_ENTRY(SCSIRequest) next; |
47 |
}; |
48 |
|
49 |
struct SCSIDevice
|
50 |
{ |
51 |
DeviceState qdev; |
52 |
uint32_t id; |
53 |
BlockConf conf; |
54 |
SCSIDeviceInfo *info; |
55 |
QTAILQ_HEAD(, SCSIRequest) requests; |
56 |
int blocksize;
|
57 |
int type;
|
58 |
}; |
59 |
|
60 |
/* cdrom.c */
|
61 |
int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track); |
62 |
int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num); |
63 |
|
64 |
/* scsi-bus.c */
|
65 |
typedef int (*scsi_qdev_initfn)(SCSIDevice *dev); |
66 |
struct SCSIDeviceInfo {
|
67 |
DeviceInfo qdev; |
68 |
scsi_qdev_initfn init; |
69 |
void (*destroy)(SCSIDevice *s);
|
70 |
SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun); |
71 |
void (*free_req)(SCSIRequest *req);
|
72 |
int32_t (*send_command)(SCSIRequest *req, uint8_t *buf); |
73 |
void (*read_data)(SCSIRequest *req);
|
74 |
int (*write_data)(SCSIRequest *req);
|
75 |
void (*cancel_io)(SCSIRequest *req);
|
76 |
uint8_t *(*get_buf)(SCSIRequest *req); |
77 |
}; |
78 |
|
79 |
struct SCSIBusOps {
|
80 |
void (*complete)(SCSIRequest *req, int reason, uint32_t arg); |
81 |
void (*cancel)(SCSIRequest *req);
|
82 |
}; |
83 |
|
84 |
struct SCSIBus {
|
85 |
BusState qbus; |
86 |
int busnr;
|
87 |
|
88 |
int tcq, ndev;
|
89 |
const SCSIBusOps *ops;
|
90 |
|
91 |
SCSIDevice *devs[MAX_SCSI_DEVS]; |
92 |
}; |
93 |
|
94 |
void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev, |
95 |
const SCSIBusOps *ops);
|
96 |
void scsi_qdev_register(SCSIDeviceInfo *info);
|
97 |
|
98 |
static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) |
99 |
{ |
100 |
return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
|
101 |
} |
102 |
|
103 |
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, |
104 |
int unit, bool removable); |
105 |
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
|
106 |
|
107 |
SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun); |
108 |
void scsi_req_enqueue(SCSIRequest *req);
|
109 |
void scsi_req_free(SCSIRequest *req);
|
110 |
void scsi_req_dequeue(SCSIRequest *req);
|
111 |
SCSIRequest *scsi_req_ref(SCSIRequest *req); |
112 |
void scsi_req_unref(SCSIRequest *req);
|
113 |
|
114 |
int scsi_req_parse(SCSIRequest *req, uint8_t *buf);
|
115 |
void scsi_req_print(SCSIRequest *req);
|
116 |
void scsi_req_data(SCSIRequest *req, int len); |
117 |
void scsi_req_complete(SCSIRequest *req);
|
118 |
void scsi_req_abort(SCSIRequest *req, int status); |
119 |
void scsi_req_cancel(SCSIRequest *req);
|
120 |
void scsi_device_purge_requests(SCSIDevice *sdev);
|
121 |
|
122 |
#endif
|