xref: /openbmc/qemu/include/hw/virtio/virtio-blk.h (revision 22e3284f)
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     uint32_t max_discard_sectors;
42     uint32_t max_write_zeroes_sectors;
43 };
44 
45 struct VirtIOBlockDataPlane;
46 
47 struct VirtIOBlockReq;
48 typedef struct VirtIOBlock {
49     VirtIODevice parent_obj;
50     BlockBackend *blk;
51     void *rq;
52     QEMUBH *bh;
53     VirtIOBlkConf conf;
54     unsigned short sector_mask;
55     bool original_wce;
56     VMChangeStateEntry *change;
57     bool dataplane_disabled;
58     bool dataplane_started;
59     struct VirtIOBlockDataPlane *dataplane;
60     uint64_t host_features;
61     size_t config_size;
62 } VirtIOBlock;
63 
64 typedef struct VirtIOBlockReq {
65     VirtQueueElement elem;
66     int64_t sector_num;
67     VirtIOBlock *dev;
68     VirtQueue *vq;
69     struct virtio_blk_inhdr *in;
70     struct virtio_blk_outhdr out;
71     QEMUIOVector qiov;
72     size_t in_len;
73     struct VirtIOBlockReq *next;
74     struct VirtIOBlockReq *mr_next;
75     BlockAcctCookie acct;
76 } VirtIOBlockReq;
77 
78 #define VIRTIO_BLK_MAX_MERGE_REQS 32
79 
80 typedef struct MultiReqBuffer {
81     VirtIOBlockReq *reqs[VIRTIO_BLK_MAX_MERGE_REQS];
82     unsigned int num_reqs;
83     bool is_write;
84 } MultiReqBuffer;
85 
86 bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq);
87 
88 #endif
89