xref: /openbmc/qemu/include/hw/virtio/virtio-blk.h (revision 02e5d7d7)
1 /*
2  * Virtio Block Device
3  *
4  * Copyright IBM, Corp. 2007
5  *
6  * Authors:
7  *  Anthony Liguori   <aliguori@us.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  *
12  */
13 
14 #ifndef QEMU_VIRTIO_BLK_H
15 #define QEMU_VIRTIO_BLK_H
16 
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 
23 #define TYPE_VIRTIO_BLK "virtio-blk-device"
24 #define VIRTIO_BLK(obj) \
25         OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK)
26 
27 /* This is the last element of the write scatter-gather list */
28 struct virtio_blk_inhdr
29 {
30     unsigned char status;
31 };
32 
33 struct VirtIOBlkConf
34 {
35     BlockConf conf;
36     IOThread *iothread;
37     char *serial;
38     uint32_t request_merging;
39     uint16_t num_queues;
40     uint16_t queue_size;
41     bool seg_max_adjust;
42     uint32_t max_discard_sectors;
43     uint32_t max_write_zeroes_sectors;
44     bool x_enable_wce_if_config_wce;
45 };
46 
47 struct VirtIOBlockDataPlane;
48 
49 struct VirtIOBlockReq;
50 typedef struct VirtIOBlock {
51     VirtIODevice parent_obj;
52     BlockBackend *blk;
53     void *rq;
54     QEMUBH *bh;
55     VirtIOBlkConf conf;
56     unsigned short sector_mask;
57     bool original_wce;
58     VMChangeStateEntry *change;
59     bool dataplane_disabled;
60     bool dataplane_started;
61     struct VirtIOBlockDataPlane *dataplane;
62     uint64_t host_features;
63     size_t config_size;
64 } VirtIOBlock;
65 
66 typedef struct VirtIOBlockReq {
67     VirtQueueElement elem;
68     int64_t sector_num;
69     VirtIOBlock *dev;
70     VirtQueue *vq;
71     struct virtio_blk_inhdr *in;
72     struct virtio_blk_outhdr out;
73     QEMUIOVector qiov;
74     size_t in_len;
75     struct VirtIOBlockReq *next;
76     struct VirtIOBlockReq *mr_next;
77     BlockAcctCookie acct;
78 } VirtIOBlockReq;
79 
80 #define VIRTIO_BLK_MAX_MERGE_REQS 32
81 
82 typedef struct MultiReqBuffer {
83     VirtIOBlockReq *reqs[VIRTIO_BLK_MAX_MERGE_REQS];
84     unsigned int num_reqs;
85     bool is_write;
86 } MultiReqBuffer;
87 
88 bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq);
89 void virtio_blk_process_queued_requests(VirtIOBlock *s, bool is_bh);
90 
91 #endif
92