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