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 #include "sysemu/block-ram-registrar.h" 23 #include "qom/object.h" 24 #include "qapi/qapi-types-virtio.h" 25 26 #define TYPE_VIRTIO_BLK "virtio-blk-device" 27 OBJECT_DECLARE_SIMPLE_TYPE(VirtIOBlock, VIRTIO_BLK) 28 29 /* This is the last element of the write scatter-gather list */ 30 struct virtio_blk_inhdr 31 { 32 unsigned char status; 33 }; 34 35 #define VIRTIO_BLK_AUTO_NUM_QUEUES UINT16_MAX 36 37 struct VirtIOBlkConf 38 { 39 BlockConf conf; 40 IOThread *iothread; 41 IOThreadVirtQueueMappingList *iothread_vq_mapping_list; 42 char *serial; 43 uint32_t request_merging; 44 uint16_t num_queues; 45 uint16_t queue_size; 46 bool seg_max_adjust; 47 bool report_discard_granularity; 48 uint32_t max_discard_sectors; 49 uint32_t max_write_zeroes_sectors; 50 bool x_enable_wce_if_config_wce; 51 }; 52 53 struct VirtIOBlockDataPlane; 54 55 struct VirtIOBlockReq; 56 struct VirtIOBlock { 57 VirtIODevice parent_obj; 58 BlockBackend *blk; 59 QemuMutex rq_lock; 60 void *rq; /* protected by rq_lock */ 61 VirtIOBlkConf conf; 62 unsigned short sector_mask; 63 bool original_wce; 64 VMChangeStateEntry *change; 65 bool dataplane_disabled; 66 bool dataplane_started; 67 struct VirtIOBlockDataPlane *dataplane; 68 uint64_t host_features; 69 size_t config_size; 70 BlockRAMRegistrar blk_ram_registrar; 71 }; 72 73 typedef struct VirtIOBlockReq { 74 VirtQueueElement elem; 75 int64_t sector_num; 76 VirtIOBlock *dev; 77 VirtQueue *vq; 78 IOVDiscardUndo inhdr_undo; 79 IOVDiscardUndo outhdr_undo; 80 struct virtio_blk_inhdr *in; 81 struct virtio_blk_outhdr out; 82 QEMUIOVector qiov; 83 size_t in_len; 84 struct VirtIOBlockReq *next; 85 struct VirtIOBlockReq *mr_next; 86 BlockAcctCookie acct; 87 } VirtIOBlockReq; 88 89 #define VIRTIO_BLK_MAX_MERGE_REQS 32 90 91 typedef struct MultiReqBuffer { 92 VirtIOBlockReq *reqs[VIRTIO_BLK_MAX_MERGE_REQS]; 93 unsigned int num_reqs; 94 bool is_write; 95 } MultiReqBuffer; 96 97 void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq); 98 99 #endif 100