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"
23 #define TYPE_VIRTIO_BLK "virtio-blk-device"
24 #define VIRTIO_BLK(obj) \
25 OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK)
27 /* This is the last element of the write scatter-gather list */
28 struct virtio_blk_inhdr
40 uint32_t request_merging
;
44 struct VirtIOBlockDataPlane
;
46 struct VirtIOBlockReq
;
47 typedef struct VirtIOBlock
{
48 VirtIODevice parent_obj
;
54 unsigned short sector_mask
;
56 VMChangeStateEntry
*change
;
57 bool dataplane_disabled
;
58 bool dataplane_started
;
59 struct VirtIOBlockDataPlane
*dataplane
;
62 typedef struct VirtIOBlockReq
{
63 VirtQueueElement elem
;
67 struct virtio_blk_inhdr
*in
;
68 struct virtio_blk_outhdr out
;
71 struct VirtIOBlockReq
*next
;
72 struct VirtIOBlockReq
*mr_next
;
76 #define VIRTIO_BLK_MAX_MERGE_REQS 32
78 typedef struct MultiReqBuffer
{
79 VirtIOBlockReq
*reqs
[VIRTIO_BLK_MAX_MERGE_REQS
];
80 unsigned int num_reqs
;
84 void virtio_blk_init_request(VirtIOBlock
*s
, VirtQueue
*vq
,
86 void virtio_blk_free_request(VirtIOBlockReq
*req
);
88 void virtio_blk_handle_request(VirtIOBlockReq
*req
, MultiReqBuffer
*mrb
);
90 void virtio_blk_submit_multireq(BlockBackend
*blk
, MultiReqBuffer
*mrb
);
92 void virtio_blk_handle_vq(VirtIOBlock
*s
, VirtQueue
*vq
);