]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/virtio/virtio-blk.h
Merge tag 'pull-target-arm-20240126' of https://git.linaro.org/people/pmaydell/qemu...
[mirror_qemu.git] / include / hw / virtio / virtio-blk.h
CommitLineData
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"
baf42268 22#include "sysemu/block-ram-registrar.h"
db1015e9 23#include "qom/object.h"
b6948ab0 24#include "qapi/qapi-types-virtio.h"
6e02c38d 25
f574fa8b 26#define TYPE_VIRTIO_BLK "virtio-blk-device"
8063396b 27OBJECT_DECLARE_SIMPLE_TYPE(VirtIOBlock, VIRTIO_BLK)
1c028ddf 28
8b91408b 29/* This is the last element of the write scatter-gather list */
6e02c38d
AL
30struct virtio_blk_inhdr
31{
32 unsigned char status;
33};
34
9445e1e1
SH
35#define VIRTIO_BLK_AUTO_NUM_QUEUES UINT16_MAX
36
12c5674b
PB
37struct VirtIOBlkConf
38{
39 BlockConf conf;
48ff2692 40 IOThread *iothread;
b6948ab0 41 IOThreadVirtQueueMappingList *iothread_vq_mapping_list;
12c5674b 42 char *serial;
c99495ac 43 uint32_t request_merging;
84419863 44 uint16_t num_queues;
6040aedd 45 uint16_t queue_size;
1bf8a989 46 bool seg_max_adjust;
fb0b154c 47 bool report_discard_granularity;
37b06f8d
SG
48 uint32_t max_discard_sectors;
49 uint32_t max_write_zeroes_sectors;
5f258577 50 bool x_enable_wce_if_config_wce;
12c5674b
PB
51};
52
bf4bd461 53struct VirtIOBlockReq;
db1015e9 54struct VirtIOBlock {
1cc91b7d 55 VirtIODevice parent_obj;
4be74634 56 BlockBackend *blk;
9c67f33f
SH
57 QemuMutex rq_lock;
58 void *rq; /* protected by rq_lock */
2a30307f 59 VirtIOBlkConf conf;
f1b24e84 60 unsigned short sector_mask;
ef5bc962 61 bool original_wce;
f1b24e84 62 VMChangeStateEntry *change;
3cdaf3dd
SH
63 bool ioeventfd_disabled;
64 bool ioeventfd_started;
65 bool ioeventfd_starting;
66 bool ioeventfd_stopping;
3bcc17f0
SH
67
68 /*
69 * The AioContext for each virtqueue. The BlockDriverState will use the
70 * first element as its AioContext.
71 */
72 AioContext **vq_aio_context;
73
bbe8bd4d 74 uint64_t host_features;
20764be0 75 size_t config_size;
baf42268 76 BlockRAMRegistrar blk_ram_registrar;
db1015e9 77};
f1b24e84 78
09f64587 79typedef struct VirtIOBlockReq {
6aa46d8f 80 VirtQueueElement elem;
95f7142a 81 int64_t sector_num;
09f64587 82 VirtIOBlock *dev;
edaffd9f 83 VirtQueue *vq;
7bd04a04
SH
84 IOVDiscardUndo inhdr_undo;
85 IOVDiscardUndo outhdr_undo;
09f64587 86 struct virtio_blk_inhdr *in;
827805a2 87 struct virtio_blk_outhdr out;
09f64587 88 QEMUIOVector qiov;
2a6cdd6d 89 size_t in_len;
09f64587 90 struct VirtIOBlockReq *next;
95f7142a 91 struct VirtIOBlockReq *mr_next;
09f64587
FZ
92 BlockAcctCookie acct;
93} VirtIOBlockReq;
94
95f7142a
PL
95#define VIRTIO_BLK_MAX_MERGE_REQS 32
96
97typedef struct MultiReqBuffer {
98 VirtIOBlockReq *reqs[VIRTIO_BLK_MAX_MERGE_REQS];
99 unsigned int num_reqs;
100 bool is_write;
101} MultiReqBuffer;
102
186b9691 103void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq);
8a2fad57 104
6e02c38d 105#endif