Daniil Tatianin | d9cf55a | 2022-09-06 10:31:08 +0300 | [diff] [blame] | 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)}, |
Sam Li | 4f73665 | 2023-05-08 13:19:13 +0800 | [diff] [blame] | 32 | {.flags = 1ULL << VIRTIO_BLK_F_ZONED, |
| 33 | .end = endof(struct virtio_blk_config, zoned)}, |
Daniil Tatianin | d9cf55a | 2022-09-06 10:31:08 +0300 | [diff] [blame] | 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 | }; |