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