]>
Commit | Line | Data |
---|---|---|
6e02c38d AL |
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 | ||
2a6a4076 MA |
14 | #ifndef QEMU_VIRTIO_BLK_H |
15 | #define QEMU_VIRTIO_BLK_H | |
6e02c38d | 16 | |
907eb3e5 | 17 | #include "standard-headers/linux/virtio_blk.h" |
0d09e41a PB |
18 | #include "hw/virtio/virtio.h" |
19 | #include "hw/block/block.h" | |
48ff2692 | 20 | #include "sysemu/iothread.h" |
4be74634 | 21 | #include "sysemu/block-backend.h" |
db1015e9 | 22 | #include "qom/object.h" |
6e02c38d | 23 | |
f574fa8b | 24 | #define TYPE_VIRTIO_BLK "virtio-blk-device" |
db1015e9 | 25 | typedef struct VirtIOBlock VirtIOBlock; |
1c028ddf FK |
26 | #define VIRTIO_BLK(obj) \ |
27 | OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK) | |
28 | ||
8b91408b | 29 | /* This is the last element of the write scatter-gather list */ |
6e02c38d AL |
30 | struct virtio_blk_inhdr |
31 | { | |
32 | unsigned char status; | |
33 | }; | |
34 | ||
9445e1e1 SH |
35 | #define VIRTIO_BLK_AUTO_NUM_QUEUES UINT16_MAX |
36 | ||
12c5674b PB |
37 | struct VirtIOBlkConf |
38 | { | |
39 | BlockConf conf; | |
48ff2692 | 40 | IOThread *iothread; |
12c5674b | 41 | char *serial; |
c99495ac | 42 | uint32_t request_merging; |
84419863 | 43 | uint16_t num_queues; |
6040aedd | 44 | uint16_t queue_size; |
1bf8a989 | 45 | bool seg_max_adjust; |
37b06f8d SG |
46 | uint32_t max_discard_sectors; |
47 | uint32_t max_write_zeroes_sectors; | |
5f258577 | 48 | bool x_enable_wce_if_config_wce; |
12c5674b PB |
49 | }; |
50 | ||
0d09e41a PB |
51 | struct VirtIOBlockDataPlane; |
52 | ||
bf4bd461 | 53 | struct VirtIOBlockReq; |
db1015e9 | 54 | struct VirtIOBlock { |
1cc91b7d | 55 | VirtIODevice parent_obj; |
4be74634 | 56 | BlockBackend *blk; |
f1b24e84 FK |
57 | void *rq; |
58 | QEMUBH *bh; | |
2a30307f | 59 | VirtIOBlkConf conf; |
f1b24e84 | 60 | unsigned short sector_mask; |
ef5bc962 | 61 | bool original_wce; |
f1b24e84 | 62 | VMChangeStateEntry *change; |
eb41cf78 | 63 | bool dataplane_disabled; |
2906cddf | 64 | bool dataplane_started; |
0d09e41a | 65 | struct VirtIOBlockDataPlane *dataplane; |
bbe8bd4d | 66 | uint64_t host_features; |
20764be0 | 67 | size_t config_size; |
db1015e9 | 68 | }; |
f1b24e84 | 69 | |
09f64587 | 70 | typedef struct VirtIOBlockReq { |
6aa46d8f | 71 | VirtQueueElement elem; |
95f7142a | 72 | int64_t sector_num; |
09f64587 | 73 | VirtIOBlock *dev; |
edaffd9f | 74 | VirtQueue *vq; |
09f64587 | 75 | struct virtio_blk_inhdr *in; |
827805a2 | 76 | struct virtio_blk_outhdr out; |
09f64587 | 77 | QEMUIOVector qiov; |
2a6cdd6d | 78 | size_t in_len; |
09f64587 | 79 | struct VirtIOBlockReq *next; |
95f7142a | 80 | struct VirtIOBlockReq *mr_next; |
09f64587 FZ |
81 | BlockAcctCookie acct; |
82 | } VirtIOBlockReq; | |
83 | ||
95f7142a PL |
84 | #define VIRTIO_BLK_MAX_MERGE_REQS 32 |
85 | ||
86 | typedef struct MultiReqBuffer { | |
87 | VirtIOBlockReq *reqs[VIRTIO_BLK_MAX_MERGE_REQS]; | |
88 | unsigned int num_reqs; | |
89 | bool is_write; | |
90 | } MultiReqBuffer; | |
91 | ||
07931698 | 92 | bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq); |
49b44549 | 93 | void virtio_blk_process_queued_requests(VirtIOBlock *s, bool is_bh); |
8a2fad57 | 94 | |
6e02c38d | 95 | #endif |