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 "standard-headers/linux/virtio_blk.h"
18 #include "hw/virtio/virtio.h"
19 #include "hw/block/block.h"
20 #include "sysemu/iothread.h"
21 #include "sysemu/block-backend.h"
22 #include "sysemu/block-ram-registrar.h"
23 #include "qom/object.h"
24 #include "qapi/qapi-types-virtio.h"
26 #define TYPE_VIRTIO_BLK "virtio-blk-device"
27 OBJECT_DECLARE_SIMPLE_TYPE(VirtIOBlock
, VIRTIO_BLK
)
29 /* This is the last element of the write scatter-gather list */
30 struct virtio_blk_inhdr
35 #define VIRTIO_BLK_AUTO_NUM_QUEUES UINT16_MAX
41 IOThreadVirtQueueMappingList
*iothread_vq_mapping_list
;
43 uint32_t request_merging
;
47 bool report_discard_granularity
;
48 uint32_t max_discard_sectors
;
49 uint32_t max_write_zeroes_sectors
;
50 bool x_enable_wce_if_config_wce
;
53 struct VirtIOBlockDataPlane
;
55 struct VirtIOBlockReq
;
57 VirtIODevice parent_obj
;
60 void *rq
; /* protected by rq_lock */
62 unsigned short sector_mask
;
64 VMChangeStateEntry
*change
;
65 bool dataplane_disabled
;
66 bool dataplane_started
;
67 struct VirtIOBlockDataPlane
*dataplane
;
68 uint64_t host_features
;
70 BlockRAMRegistrar blk_ram_registrar
;
73 typedef struct VirtIOBlockReq
{
74 VirtQueueElement elem
;
78 IOVDiscardUndo inhdr_undo
;
79 IOVDiscardUndo outhdr_undo
;
80 struct virtio_blk_inhdr
*in
;
81 struct virtio_blk_outhdr out
;
84 struct VirtIOBlockReq
*next
;
85 struct VirtIOBlockReq
*mr_next
;
89 #define VIRTIO_BLK_MAX_MERGE_REQS 32
91 typedef struct MultiReqBuffer
{
92 VirtIOBlockReq
*reqs
[VIRTIO_BLK_MAX_MERGE_REQS
];
93 unsigned int num_reqs
;
97 void virtio_blk_handle_vq(VirtIOBlock
*s
, VirtQueue
*vq
);