xref: /openbmc/qemu/hw/block/virtio-blk-common.c (revision 7d87775f)
1 /*
2  * Virtio Block Device common helpers
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 #include "qemu/osdep.h"
14 
15 #include "standard-headers/linux/virtio_blk.h"
16 #include "hw/virtio/virtio.h"
17 #include "hw/virtio/virtio-blk-common.h"
18 
19 /* Config size before the discard support (hide associated config fields) */
20 #define VIRTIO_BLK_CFG_SIZE offsetof(struct virtio_blk_config, \
21                                      max_discard_sectors)
22 
23 /*
24  * Starting from the discard feature, we can use this array to properly
25  * set the config size depending on the features enabled.
26  */
27 static const VirtIOFeature feature_sizes[] = {
28     {.flags = 1ULL << VIRTIO_BLK_F_DISCARD,
29      .end = endof(struct virtio_blk_config, discard_sector_alignment)},
30     {.flags = 1ULL << VIRTIO_BLK_F_WRITE_ZEROES,
31      .end = endof(struct virtio_blk_config, write_zeroes_may_unmap)},
32     {.flags = 1ULL << VIRTIO_BLK_F_ZONED,
33      .end = endof(struct virtio_blk_config, zoned)},
34     {}
35 };
36 
37 const VirtIOConfigSizeParams virtio_blk_cfg_size_params = {
38     .min_size = VIRTIO_BLK_CFG_SIZE,
39     .max_size = sizeof(struct virtio_blk_config),
40     .feature_sizes = feature_sizes
41 };
42