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