]> git.proxmox.com Git - qemu.git/blame - hw/scsi.h
scsi: create common SCSIRequest structure.
[qemu.git] / hw / scsi.h
CommitLineData
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"
43b443b6
GH
6
7/* scsi-disk.c */
8enum scsi_reason {
9 SCSI_REASON_DONE, /* Command complete. */
10 SCSI_REASON_DATA /* Transfer complete, more data required. */
11};
12
13typedef struct SCSIBus SCSIBus;
14typedef struct SCSIDevice SCSIDevice;
15typedef struct SCSIDeviceInfo SCSIDeviceInfo;
16typedef void (*scsi_completionfn)(SCSIBus *bus, int reason, uint32_t tag,
17 uint32_t arg);
18
4c41d2ef
GH
19typedef struct SCSIRequest {
20 SCSIBus *bus;
21 SCSIDevice *dev;
22 uint32_t tag;
23 BlockDriverAIOCB *aiocb;
24} SCSIRequest;
25
43b443b6
GH
26struct SCSIDevice
27{
28 DeviceState qdev;
29 uint32_t id;
30 SCSIDeviceInfo *info;
31};
32
33/* cdrom.c */
34int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
35int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
36
37/* scsi-bus.c */
38typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
39struct SCSIDeviceInfo {
40 DeviceInfo qdev;
41 scsi_qdev_initfn init;
42 void (*destroy)(SCSIDevice *s);
43 int32_t (*send_command)(SCSIDevice *s, uint32_t tag, uint8_t *buf,
44 int lun);
45 void (*read_data)(SCSIDevice *s, uint32_t tag);
46 int (*write_data)(SCSIDevice *s, uint32_t tag);
47 void (*cancel_io)(SCSIDevice *s, uint32_t tag);
48 uint8_t *(*get_buf)(SCSIDevice *s, uint32_t tag);
49};
50
51typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
52 int unit);
53struct SCSIBus {
54 BusState qbus;
55 int busnr;
56
57 int tcq, ndev;
58 scsi_completionfn complete;
59
60 SCSIDevice *devs[8];
61};
62
63void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
64 scsi_completionfn complete);
65void scsi_qdev_register(SCSIDeviceInfo *info);
66
67static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
68{
69 return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
70}
71
72SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit);
73void scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
74
75#endif