1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #include <linux/virtio_byteorder.h> 3 #include <linux/virtio.h> 4 #include <uapi/linux/virtio_config.h> 5 6 struct virtio_config_ops { 7 int (*disable_vq_and_reset)(struct virtqueue *vq); 8 int (*enable_vq_after_reset)(struct virtqueue *vq); 9 }; 10 11 /* 12 * __virtio_test_bit - helper to test feature bits. For use by transports. 13 * Devices should normally use virtio_has_feature, 14 * which includes more checks. 15 * @vdev: the device 16 * @fbit: the feature bit 17 */ 18 static inline bool __virtio_test_bit(const struct virtio_device *vdev, 19 unsigned int fbit) 20 { 21 return vdev->features & (1ULL << fbit); 22 } 23 24 /** 25 * __virtio_set_bit - helper to set feature bits. For use by transports. 26 * @vdev: the device 27 * @fbit: the feature bit 28 */ 29 static inline void __virtio_set_bit(struct virtio_device *vdev, 30 unsigned int fbit) 31 { 32 vdev->features |= (1ULL << fbit); 33 } 34 35 /** 36 * __virtio_clear_bit - helper to clear feature bits. For use by transports. 37 * @vdev: the device 38 * @fbit: the feature bit 39 */ 40 static inline void __virtio_clear_bit(struct virtio_device *vdev, 41 unsigned int fbit) 42 { 43 vdev->features &= ~(1ULL << fbit); 44 } 45 46 #define virtio_has_feature(dev, feature) \ 47 (__virtio_test_bit((dev), feature)) 48 49 /** 50 * virtio_has_dma_quirk - determine whether this device has the DMA quirk 51 * @vdev: the device 52 */ 53 static inline bool virtio_has_dma_quirk(const struct virtio_device *vdev) 54 { 55 /* 56 * Note the reverse polarity of the quirk feature (compared to most 57 * other features), this is for compatibility with legacy systems. 58 */ 59 return !virtio_has_feature(vdev, VIRTIO_F_ACCESS_PLATFORM); 60 } 61 62 static inline bool virtio_is_little_endian(struct virtio_device *vdev) 63 { 64 return virtio_has_feature(vdev, VIRTIO_F_VERSION_1) || 65 virtio_legacy_is_little_endian(); 66 } 67 68 /* Memory accessors */ 69 static inline u16 virtio16_to_cpu(struct virtio_device *vdev, __virtio16 val) 70 { 71 return __virtio16_to_cpu(virtio_is_little_endian(vdev), val); 72 } 73 74 static inline __virtio16 cpu_to_virtio16(struct virtio_device *vdev, u16 val) 75 { 76 return __cpu_to_virtio16(virtio_is_little_endian(vdev), val); 77 } 78 79 static inline u32 virtio32_to_cpu(struct virtio_device *vdev, __virtio32 val) 80 { 81 return __virtio32_to_cpu(virtio_is_little_endian(vdev), val); 82 } 83 84 static inline __virtio32 cpu_to_virtio32(struct virtio_device *vdev, u32 val) 85 { 86 return __cpu_to_virtio32(virtio_is_little_endian(vdev), val); 87 } 88 89 static inline u64 virtio64_to_cpu(struct virtio_device *vdev, __virtio64 val) 90 { 91 return __virtio64_to_cpu(virtio_is_little_endian(vdev), val); 92 } 93 94 static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val) 95 { 96 return __cpu_to_virtio64(virtio_is_little_endian(vdev), val); 97 } 98