]> git.proxmox.com Git - qemu.git/blob - hw/virtio-blk.h
virtio-blk: cleanup: init and exit functions.
[qemu.git] / hw / virtio-blk.h
1 /*
2 * Virtio Block Device
3 *
4 * Copyright IBM, Corp. 2007
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 */
13
14 #ifndef _QEMU_VIRTIO_BLK_H
15 #define _QEMU_VIRTIO_BLK_H
16
17 #include "hw/virtio.h"
18 #include "hw/block-common.h"
19 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
20 #include "dataplane/virtio-blk.h"
21 #endif
22
23 #define TYPE_VIRTIO_BLK "virtio-blk"
24 #define VIRTIO_BLK(obj) \
25 OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK)
26
27 /* from Linux's linux/virtio_blk.h */
28
29 /* The ID for virtio_block */
30 #define VIRTIO_ID_BLOCK 2
31
32 /* Feature bits */
33 #define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
34 #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
35 #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
36 #define VIRTIO_BLK_F_GEOMETRY 4 /* Indicates support of legacy geometry */
37 #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
38 #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
39 #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
40 /* #define VIRTIO_BLK_F_IDENTIFY 8 ATA IDENTIFY supported, DEPRECATED */
41 #define VIRTIO_BLK_F_WCE 9 /* write cache enabled */
42 #define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
43 #define VIRTIO_BLK_F_CONFIG_WCE 11 /* write cache configurable */
44
45 #define VIRTIO_BLK_ID_BYTES 20 /* ID string length */
46
47 struct virtio_blk_config
48 {
49 uint64_t capacity;
50 uint32_t size_max;
51 uint32_t seg_max;
52 uint16_t cylinders;
53 uint8_t heads;
54 uint8_t sectors;
55 uint32_t blk_size;
56 uint8_t physical_block_exp;
57 uint8_t alignment_offset;
58 uint16_t min_io_size;
59 uint32_t opt_io_size;
60 uint8_t wce;
61 } QEMU_PACKED;
62
63 /* These two define direction. */
64 #define VIRTIO_BLK_T_IN 0
65 #define VIRTIO_BLK_T_OUT 1
66
67 /* This bit says it's a scsi command, not an actual read or write. */
68 #define VIRTIO_BLK_T_SCSI_CMD 2
69
70 /* Flush the volatile write cache */
71 #define VIRTIO_BLK_T_FLUSH 4
72
73 /* return the device ID string */
74 #define VIRTIO_BLK_T_GET_ID 8
75
76 /* Barrier before this op. */
77 #define VIRTIO_BLK_T_BARRIER 0x80000000
78
79 /* This is the first element of the read scatter-gather list. */
80 struct virtio_blk_outhdr
81 {
82 /* VIRTIO_BLK_T* */
83 uint32_t type;
84 /* io priority. */
85 uint32_t ioprio;
86 /* Sector (ie. 512 byte offset) */
87 uint64_t sector;
88 };
89
90 #define VIRTIO_BLK_S_OK 0
91 #define VIRTIO_BLK_S_IOERR 1
92 #define VIRTIO_BLK_S_UNSUPP 2
93
94 /* This is the last element of the write scatter-gather list */
95 struct virtio_blk_inhdr
96 {
97 unsigned char status;
98 };
99
100 /* SCSI pass-through header */
101 struct virtio_scsi_inhdr
102 {
103 uint32_t errors;
104 uint32_t data_len;
105 uint32_t sense_len;
106 uint32_t residual;
107 };
108
109 struct VirtIOBlkConf
110 {
111 BlockConf conf;
112 char *serial;
113 uint32_t scsi;
114 uint32_t config_wce;
115 uint32_t data_plane;
116 };
117
118 typedef struct VirtIOBlock {
119 VirtIODevice vdev;
120 BlockDriverState *bs;
121 VirtQueue *vq;
122 void *rq;
123 QEMUBH *bh;
124 BlockConf *conf;
125 VirtIOBlkConf blk;
126 unsigned short sector_mask;
127 DeviceState *qdev;
128 VMChangeStateEntry *change;
129 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
130 VirtIOBlockDataPlane *dataplane;
131 #endif
132 } VirtIOBlock;
133
134 #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
135 DEFINE_VIRTIO_COMMON_FEATURES(_state, _field)
136
137 #ifdef __linux__
138 #define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field) \
139 DEFINE_BLOCK_PROPERTIES(_state, _field.conf), \
140 DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf), \
141 DEFINE_PROP_STRING("serial", _state, _field.serial), \
142 DEFINE_PROP_BIT("config-wce", _state, _field.config_wce, 0, true), \
143 DEFINE_PROP_BIT("scsi", _state, _field.scsi, 0, true)
144 #else
145 #define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field) \
146 DEFINE_BLOCK_PROPERTIES(_state, _field.conf), \
147 DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf), \
148 DEFINE_PROP_STRING("serial", _state, _field.serial), \
149 DEFINE_PROP_BIT("config-wce", _state, _field.config_wce, 0, true)
150 #endif /* __linux__ */
151
152 void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk);
153
154 #endif