blob: e2f8e2f6da80190719422b9fcfba56da307bba31 [file] [log] [blame]
Daniil Tatianind9cf55a2022-09-06 10:31:08 +03001/*
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 */
27static 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 Li4f736652023-05-08 13:19:13 +080032 {.flags = 1ULL << VIRTIO_BLK_F_ZONED,
33 .end = endof(struct virtio_blk_config, zoned)},
Daniil Tatianind9cf55a2022-09-06 10:31:08 +030034 {}
35};
36
37const 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};