root / hw / scsi.h @ cfdc1bb0
History | View | Annotate | Download (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 |
|
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 |
|
29 |
typedef struct SCSIRequest { |
30 |
SCSIBus *bus; |
31 |
SCSIDevice *dev; |
32 |
uint32_t tag; |
33 |
uint32_t lun; |
34 |
uint32_t status; |
35 |
struct {
|
36 |
uint8_t buf[SCSI_CMD_BUF_SIZE]; |
37 |
int len;
|
38 |
size_t xfer; |
39 |
uint64_t lba; |
40 |
enum SCSIXferMode mode;
|
41 |
} cmd; |
42 |
BlockDriverAIOCB *aiocb; |
43 |
bool enqueued;
|
44 |
QTAILQ_ENTRY(SCSIRequest) next; |
45 |
} SCSIRequest; |
46 |
|
47 |
struct SCSIDevice
|
48 |
{ |
49 |
DeviceState qdev; |
50 |
uint32_t id; |
51 |
BlockConf conf; |
52 |
SCSIDeviceInfo *info; |
53 |
QTAILQ_HEAD(, SCSIRequest) requests; |
54 |
int blocksize;
|
55 |
int type;
|
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 |
struct SCSIBusOps {
|
77 |
void (*complete)(SCSIBus *bus, int reason, uint32_t tag, uint32_t arg); |
78 |
}; |
79 |
|
80 |
struct SCSIBus {
|
81 |
BusState qbus; |
82 |
int busnr;
|
83 |
|
84 |
int tcq, ndev;
|
85 |
const SCSIBusOps *ops;
|
86 |
|
87 |
SCSIDevice *devs[MAX_SCSI_DEVS]; |
88 |
}; |
89 |
|
90 |
void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev, |
91 |
const SCSIBusOps *ops);
|
92 |
void scsi_qdev_register(SCSIDeviceInfo *info);
|
93 |
|
94 |
static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) |
95 |
{ |
96 |
return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
|
97 |
} |
98 |
|
99 |
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, |
100 |
int unit, bool removable); |
101 |
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
|
102 |
|
103 |
SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun); |
104 |
SCSIRequest *scsi_req_find(SCSIDevice *d, uint32_t tag); |
105 |
void scsi_req_free(SCSIRequest *req);
|
106 |
|
107 |
int scsi_req_parse(SCSIRequest *req, uint8_t *buf);
|
108 |
void scsi_req_print(SCSIRequest *req);
|
109 |
void scsi_req_data(SCSIRequest *req, int len); |
110 |
void scsi_req_complete(SCSIRequest *req);
|
111 |
|
112 |
#endif
|