4
* Copyright IBM, Corp. 2007
7
* Anthony Liguori <aliguori@us.ibm.com>
9
* This work is licensed under the terms of the GNU GPL, version 2. See
10
* the COPYING file in the top-level directory.
14
#ifndef _QEMU_VIRTIO_BLK_H
15
#define _QEMU_VIRTIO_BLK_H
17
#include "hw/virtio/virtio.h"
18
#include "hw/block/block.h"
20
#define TYPE_VIRTIO_BLK "virtio-blk-device"
21
#define VIRTIO_BLK(obj) \
22
OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK)
24
/* from Linux's linux/virtio_blk.h */
26
/* The ID for virtio_block */
27
#define VIRTIO_ID_BLOCK 2
30
#define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
31
#define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
32
#define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
33
#define VIRTIO_BLK_F_GEOMETRY 4 /* Indicates support of legacy geometry */
34
#define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
35
#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
36
#define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
37
/* #define VIRTIO_BLK_F_IDENTIFY 8 ATA IDENTIFY supported, DEPRECATED */
38
#define VIRTIO_BLK_F_WCE 9 /* write cache enabled */
39
#define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
40
#define VIRTIO_BLK_F_CONFIG_WCE 11 /* write cache configurable */
42
#define VIRTIO_BLK_ID_BYTES 20 /* ID string length */
44
struct virtio_blk_config
53
uint8_t physical_block_exp;
54
uint8_t alignment_offset;
60
/* These two define direction. */
61
#define VIRTIO_BLK_T_IN 0
62
#define VIRTIO_BLK_T_OUT 1
64
/* This bit says it's a scsi command, not an actual read or write. */
65
#define VIRTIO_BLK_T_SCSI_CMD 2
67
/* Flush the volatile write cache */
68
#define VIRTIO_BLK_T_FLUSH 4
70
/* return the device ID string */
71
#define VIRTIO_BLK_T_GET_ID 8
73
/* Barrier before this op. */
74
#define VIRTIO_BLK_T_BARRIER 0x80000000
76
/* This is the first element of the read scatter-gather list. */
77
struct virtio_blk_outhdr
83
/* Sector (ie. 512 byte offset) */
87
#define VIRTIO_BLK_S_OK 0
88
#define VIRTIO_BLK_S_IOERR 1
89
#define VIRTIO_BLK_S_UNSUPP 2
91
/* This is the last element of the write scatter-gather list */
92
struct virtio_blk_inhdr
97
/* SCSI pass-through header */
98
struct virtio_scsi_inhdr
115
struct VirtIOBlockDataPlane;
117
typedef struct VirtIOBlock {
118
VirtIODevice parent_obj;
119
BlockDriverState *bs;
125
unsigned short sector_mask;
126
VMChangeStateEntry *change;
127
#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
128
Notifier migration_state_notifier;
129
struct VirtIOBlockDataPlane *dataplane;
133
#define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
134
DEFINE_VIRTIO_COMMON_FEATURES(_state, _field)
137
#define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field) \
138
DEFINE_BLOCK_PROPERTIES(_state, _field.conf), \
139
DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf), \
140
DEFINE_PROP_STRING("serial", _state, _field.serial), \
141
DEFINE_PROP_BIT("config-wce", _state, _field.config_wce, 0, true), \
142
DEFINE_PROP_BIT("scsi", _state, _field.scsi, 0, true)
144
#define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field) \
145
DEFINE_BLOCK_PROPERTIES(_state, _field.conf), \
146
DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf), \
147
DEFINE_PROP_STRING("serial", _state, _field.serial), \
148
DEFINE_PROP_BIT("config-wce", _state, _field.config_wce, 0, true)
149
#endif /* __linux__ */
151
void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk);