1d9cf55a8SDaniil Tatianin /* 2d9cf55a8SDaniil Tatianin * Virtio Block Device common helpers 3d9cf55a8SDaniil Tatianin * 4d9cf55a8SDaniil Tatianin * Copyright IBM, Corp. 2007 5d9cf55a8SDaniil Tatianin * 6d9cf55a8SDaniil Tatianin * Authors: 7d9cf55a8SDaniil Tatianin * Anthony Liguori <aliguori@us.ibm.com> 8d9cf55a8SDaniil Tatianin * 9d9cf55a8SDaniil Tatianin * This work is licensed under the terms of the GNU GPL, version 2. See 10d9cf55a8SDaniil Tatianin * the COPYING file in the top-level directory. 11d9cf55a8SDaniil Tatianin */ 12d9cf55a8SDaniil Tatianin 13d9cf55a8SDaniil Tatianin #include "qemu/osdep.h" 14d9cf55a8SDaniil Tatianin 15d9cf55a8SDaniil Tatianin #include "standard-headers/linux/virtio_blk.h" 16d9cf55a8SDaniil Tatianin #include "hw/virtio/virtio.h" 17d9cf55a8SDaniil Tatianin #include "hw/virtio/virtio-blk-common.h" 18d9cf55a8SDaniil Tatianin 19d9cf55a8SDaniil Tatianin /* Config size before the discard support (hide associated config fields) */ 20d9cf55a8SDaniil Tatianin #define VIRTIO_BLK_CFG_SIZE offsetof(struct virtio_blk_config, \ 21d9cf55a8SDaniil Tatianin max_discard_sectors) 22d9cf55a8SDaniil Tatianin 23d9cf55a8SDaniil Tatianin /* 24d9cf55a8SDaniil Tatianin * Starting from the discard feature, we can use this array to properly 25d9cf55a8SDaniil Tatianin * set the config size depending on the features enabled. 26d9cf55a8SDaniil Tatianin */ 27d9cf55a8SDaniil Tatianin static const VirtIOFeature feature_sizes[] = { 28d9cf55a8SDaniil Tatianin {.flags = 1ULL << VIRTIO_BLK_F_DISCARD, 29d9cf55a8SDaniil Tatianin .end = endof(struct virtio_blk_config, discard_sector_alignment)}, 30d9cf55a8SDaniil Tatianin {.flags = 1ULL << VIRTIO_BLK_F_WRITE_ZEROES, 31d9cf55a8SDaniil Tatianin .end = endof(struct virtio_blk_config, write_zeroes_may_unmap)}, 32*4f736650SSam Li {.flags = 1ULL << VIRTIO_BLK_F_ZONED, 33*4f736650SSam Li .end = endof(struct virtio_blk_config, zoned)}, 34d9cf55a8SDaniil Tatianin {} 35d9cf55a8SDaniil Tatianin }; 36d9cf55a8SDaniil Tatianin 37d9cf55a8SDaniil Tatianin const VirtIOConfigSizeParams virtio_blk_cfg_size_params = { 38d9cf55a8SDaniil Tatianin .min_size = VIRTIO_BLK_CFG_SIZE, 39d9cf55a8SDaniil Tatianin .max_size = sizeof(struct virtio_blk_config), 40d9cf55a8SDaniil Tatianin .feature_sizes = feature_sizes 41d9cf55a8SDaniil Tatianin }; 42