1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef LINUX_VIRTIO_CONFIG_H
3 #define LINUX_VIRTIO_CONFIG_H
4 #include <linux/virtio_byteorder.h>
5 #include <linux/virtio.h>
6 #include <uapi/linux/virtio_config.h>
8 struct virtio_config_ops {
9 int (*disable_vq_and_reset)(struct virtqueue *vq);
10 int (*enable_vq_after_reset)(struct virtqueue *vq);
14 * __virtio_test_bit - helper to test feature bits. For use by transports.
15 * Devices should normally use virtio_has_feature,
16 * which includes more checks.
18 * @fbit: the feature bit
20 static inline bool __virtio_test_bit(const struct virtio_device *vdev,
23 return vdev->features & (1ULL << fbit);
27 * __virtio_set_bit - helper to set feature bits. For use by transports.
29 * @fbit: the feature bit
31 static inline void __virtio_set_bit(struct virtio_device *vdev,
34 vdev->features |= (1ULL << fbit);
38 * __virtio_clear_bit - helper to clear feature bits. For use by transports.
40 * @fbit: the feature bit
42 static inline void __virtio_clear_bit(struct virtio_device *vdev,
45 vdev->features &= ~(1ULL << fbit);
48 #define virtio_has_feature(dev, feature) \
49 (__virtio_test_bit((dev), feature))
52 * virtio_has_dma_quirk - determine whether this device has the DMA quirk
55 static inline bool virtio_has_dma_quirk(const struct virtio_device *vdev)
58 * Note the reverse polarity of the quirk feature (compared to most
59 * other features), this is for compatibility with legacy systems.
61 return !virtio_has_feature(vdev, VIRTIO_F_ACCESS_PLATFORM);
64 static inline bool virtio_is_little_endian(struct virtio_device *vdev)
66 return virtio_has_feature(vdev, VIRTIO_F_VERSION_1) ||
67 virtio_legacy_is_little_endian();
70 /* Memory accessors */
71 static inline u16 virtio16_to_cpu(struct virtio_device *vdev, __virtio16 val)
73 return __virtio16_to_cpu(virtio_is_little_endian(vdev), val);
76 static inline __virtio16 cpu_to_virtio16(struct virtio_device *vdev, u16 val)
78 return __cpu_to_virtio16(virtio_is_little_endian(vdev), val);
81 static inline u32 virtio32_to_cpu(struct virtio_device *vdev, __virtio32 val)
83 return __virtio32_to_cpu(virtio_is_little_endian(vdev), val);
86 static inline __virtio32 cpu_to_virtio32(struct virtio_device *vdev, u32 val)
88 return __cpu_to_virtio32(virtio_is_little_endian(vdev), val);
91 static inline u64 virtio64_to_cpu(struct virtio_device *vdev, __virtio64 val)
93 return __virtio64_to_cpu(virtio_is_little_endian(vdev), val);
96 static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
98 return __cpu_to_virtio64(virtio_is_little_endian(vdev), val);