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 VirtIOBlockReq
;
55 VirtIODevice parent_obj
;
58 struct VirtIOBlockReq
*rq
; /* protected by rq_lock */
60 unsigned short sector_mask
;
62 VMChangeStateEntry
*change
;
63 bool ioeventfd_disabled
;
64 bool ioeventfd_started
;
65 bool ioeventfd_starting
;
66 bool ioeventfd_stopping
;
69 * The AioContext for each virtqueue. The BlockDriverState will use the
70 * first element as its AioContext.
72 AioContext
**vq_aio_context
;
74 uint64_t host_features
;
76 BlockRAMRegistrar blk_ram_registrar
;
79 typedef struct VirtIOBlockReq
{
80 VirtQueueElement elem
;
84 IOVDiscardUndo inhdr_undo
;
85 IOVDiscardUndo outhdr_undo
;
86 struct virtio_blk_inhdr
*in
;
87 struct virtio_blk_outhdr out
;
90 struct VirtIOBlockReq
*next
;
91 struct VirtIOBlockReq
*mr_next
;
95 #define VIRTIO_BLK_MAX_MERGE_REQS 32
97 typedef struct MultiReqBuffer
{
98 VirtIOBlockReq
*reqs
[VIRTIO_BLK_MAX_MERGE_REQS
];
99 unsigned int num_reqs
;
103 void virtio_blk_handle_vq(VirtIOBlock
*s
, VirtQueue
*vq
);