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 "qom/object.h"
24 #define TYPE_VIRTIO_BLK "virtio-blk-device"
25 OBJECT_DECLARE_SIMPLE_TYPE(VirtIOBlock
, VIRTIO_BLK
)
27 /* This is the last element of the write scatter-gather list */
28 struct virtio_blk_inhdr
33 #define VIRTIO_BLK_AUTO_NUM_QUEUES UINT16_MAX
40 uint32_t request_merging
;
44 uint32_t max_discard_sectors
;
45 uint32_t max_write_zeroes_sectors
;
46 bool x_enable_wce_if_config_wce
;
49 struct VirtIOBlockDataPlane
;
51 struct VirtIOBlockReq
;
53 VirtIODevice parent_obj
;
58 unsigned short sector_mask
;
60 VMChangeStateEntry
*change
;
61 bool dataplane_disabled
;
62 bool dataplane_started
;
63 struct VirtIOBlockDataPlane
*dataplane
;
64 uint64_t host_features
;
68 typedef struct VirtIOBlockReq
{
69 VirtQueueElement elem
;
73 IOVDiscardUndo inhdr_undo
;
74 IOVDiscardUndo outhdr_undo
;
75 struct virtio_blk_inhdr
*in
;
76 struct virtio_blk_outhdr out
;
79 struct VirtIOBlockReq
*next
;
80 struct VirtIOBlockReq
*mr_next
;
84 #define VIRTIO_BLK_MAX_MERGE_REQS 32
86 typedef struct MultiReqBuffer
{
87 VirtIOBlockReq
*reqs
[VIRTIO_BLK_MAX_MERGE_REQS
];
88 unsigned int num_reqs
;
92 bool virtio_blk_handle_vq(VirtIOBlock
*s
, VirtQueue
*vq
);
93 void virtio_blk_process_queued_requests(VirtIOBlock
*s
, bool is_bh
);