xref: /openbmc/qemu/include/hw/virtio/virtio-blk.h (revision d177892d)
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 #include "qom/object.h"
23 
24 #define TYPE_VIRTIO_BLK "virtio-blk-device"
25 OBJECT_DECLARE_SIMPLE_TYPE(VirtIOBlock, 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 #define VIRTIO_BLK_AUTO_NUM_QUEUES UINT16_MAX
34 
35 struct VirtIOBlkConf
36 {
37     BlockConf conf;
38     IOThread *iothread;
39     char *serial;
40     uint32_t request_merging;
41     uint16_t num_queues;
42     uint16_t queue_size;
43     bool seg_max_adjust;
44     bool report_discard_granularity;
45     uint32_t max_discard_sectors;
46     uint32_t max_write_zeroes_sectors;
47     bool x_enable_wce_if_config_wce;
48 };
49 
50 struct VirtIOBlockDataPlane;
51 
52 struct VirtIOBlockReq;
53 struct VirtIOBlock {
54     VirtIODevice parent_obj;
55     BlockBackend *blk;
56     void *rq;
57     QEMUBH *bh;
58     VirtIOBlkConf conf;
59     unsigned short sector_mask;
60     bool original_wce;
61     VMChangeStateEntry *change;
62     bool dataplane_disabled;
63     bool dataplane_started;
64     struct VirtIOBlockDataPlane *dataplane;
65     uint64_t host_features;
66     size_t config_size;
67 };
68 
69 typedef struct VirtIOBlockReq {
70     VirtQueueElement elem;
71     int64_t sector_num;
72     VirtIOBlock *dev;
73     VirtQueue *vq;
74     IOVDiscardUndo inhdr_undo;
75     IOVDiscardUndo outhdr_undo;
76     struct virtio_blk_inhdr *in;
77     struct virtio_blk_outhdr out;
78     QEMUIOVector qiov;
79     size_t in_len;
80     struct VirtIOBlockReq *next;
81     struct VirtIOBlockReq *mr_next;
82     BlockAcctCookie acct;
83 } VirtIOBlockReq;
84 
85 #define VIRTIO_BLK_MAX_MERGE_REQS 32
86 
87 typedef struct MultiReqBuffer {
88     VirtIOBlockReq *reqs[VIRTIO_BLK_MAX_MERGE_REQS];
89     unsigned int num_reqs;
90     bool is_write;
91 } MultiReqBuffer;
92 
93 bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq);
94 void virtio_blk_process_queued_requests(VirtIOBlock *s, bool is_bh);
95 
96 #endif
97