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