vmstate: Add pre/post_save() hooks
[qemu] / hw / scsi-disk.h
1 #ifndef SCSI_DISK_H
2 #define SCSI_DISK_H
3
4 #include "qdev.h"
5
6 /* scsi-disk.c */
7 enum scsi_reason {
8     SCSI_REASON_DONE, /* Command complete.  */
9     SCSI_REASON_DATA  /* Transfer complete, more data required.  */
10 };
11
12 typedef struct SCSIBus SCSIBus;
13 typedef struct SCSIDevice SCSIDevice;
14 typedef struct SCSIDeviceInfo SCSIDeviceInfo;
15 typedef void (*scsi_completionfn)(SCSIBus *bus, int reason, uint32_t tag,
16                                   uint32_t arg);
17
18 struct SCSIDevice
19 {
20     DeviceState qdev;
21     uint32_t id;
22     SCSIDeviceInfo *info;
23 };
24
25 /* cdrom.c */
26 int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
27 int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
28
29 /* scsi-bus.c */
30 typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
31 struct SCSIDeviceInfo {
32     DeviceInfo qdev;
33     scsi_qdev_initfn init;
34     void (*destroy)(SCSIDevice *s);
35     int32_t (*send_command)(SCSIDevice *s, uint32_t tag, uint8_t *buf,
36                             int lun);
37     void (*read_data)(SCSIDevice *s, uint32_t tag);
38     int (*write_data)(SCSIDevice *s, uint32_t tag);
39     void (*cancel_io)(SCSIDevice *s, uint32_t tag);
40     uint8_t *(*get_buf)(SCSIDevice *s, uint32_t tag);
41 };
42
43 typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
44               int unit);
45 struct SCSIBus {
46     BusState qbus;
47     int busnr;
48
49     int tcq, ndev;
50     scsi_completionfn complete;
51
52     SCSIDevice *devs[8];
53 };
54
55 SCSIBus *scsi_bus_new(DeviceState *host, int tcq, int ndev,
56                       scsi_completionfn complete);
57 void scsi_qdev_register(SCSIDeviceInfo *info);
58
59 static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
60 {
61     return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
62 }
63
64 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit);
65 void scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
66
67 #endif