diff options
author | Michael S. Tsirkin <mst@redhat.com> | 2014-11-27 14:19:02 -0500 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2014-12-09 05:05:23 -0500 |
commit | d4024af56f7c6cdb7e721994204fb07b2cda8be9 (patch) | |
tree | ad4b88708d07b9e0bab862d31d8e39cfd4e8ef85 | |
parent | b2776bf7149bddd1f4161f14f79520f17fc1d71d (diff) |
virtio: add low-level APIs for feature bits
Add low level APIs to test/set/clear feature bits.
For use by transports, to make it easier to
write code independent of feature bit array format.
Note: APIs is prefixed with __ and has _bit suffix
to stress its low level nature. It's for use by transports only:
drivers should use virtio_has_feature and never need to set/clear
features.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
-rw-r--r-- | include/linux/virtio_config.h | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 7f4ef66873ef..d8e28a2a5738 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h | |||
@@ -77,11 +77,47 @@ void virtio_check_driver_offered_feature(const struct virtio_device *vdev, | |||
77 | unsigned int fbit); | 77 | unsigned int fbit); |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * virtio_has_feature - helper to determine if this device has this feature. | 80 | * __virtio_test_bit - helper to test feature bits. For use by transports. |
81 | * Devices should normally use virtio_has_feature, | ||
82 | * which includes more checks. | ||
81 | * @vdev: the device | 83 | * @vdev: the device |
82 | * @fbit: the feature bit | 84 | * @fbit: the feature bit |
83 | */ | 85 | */ |
84 | static inline bool virtio_has_feature(const struct virtio_device *vdev, | 86 | static inline bool __virtio_test_bit(const struct virtio_device *vdev, |
87 | unsigned int fbit) | ||
88 | { | ||
89 | /* Did you forget to fix assumptions on max features? */ | ||
90 | if (__builtin_constant_p(fbit)) | ||
91 | BUILD_BUG_ON(fbit >= 32); | ||
92 | else | ||
93 | BUG_ON(fbit >= 32); | ||
94 | |||
95 | return test_bit(fbit, vdev->features); | ||
96 | } | ||
97 | |||
98 | /** | ||
99 | * __virtio_set_bit - helper to set feature bits. For use by transports. | ||
100 | * @vdev: the device | ||
101 | * @fbit: the feature bit | ||
102 | */ | ||
103 | static inline void __virtio_set_bit(struct virtio_device *vdev, | ||
104 | unsigned int fbit) | ||
105 | { | ||
106 | /* Did you forget to fix assumptions on max features? */ | ||
107 | if (__builtin_constant_p(fbit)) | ||
108 | BUILD_BUG_ON(fbit >= 32); | ||
109 | else | ||
110 | BUG_ON(fbit >= 32); | ||
111 | |||
112 | set_bit(fbit, vdev->features); | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * __virtio_clear_bit - helper to clear feature bits. For use by transports. | ||
117 | * @vdev: the device | ||
118 | * @fbit: the feature bit | ||
119 | */ | ||
120 | static inline void __virtio_clear_bit(struct virtio_device *vdev, | ||
85 | unsigned int fbit) | 121 | unsigned int fbit) |
86 | { | 122 | { |
87 | /* Did you forget to fix assumptions on max features? */ | 123 | /* Did you forget to fix assumptions on max features? */ |
@@ -90,10 +126,21 @@ static inline bool virtio_has_feature(const struct virtio_device *vdev, | |||
90 | else | 126 | else |
91 | BUG_ON(fbit >= 32); | 127 | BUG_ON(fbit >= 32); |
92 | 128 | ||
129 | clear_bit(fbit, vdev->features); | ||
130 | } | ||
131 | |||
132 | /** | ||
133 | * virtio_has_feature - helper to determine if this device has this feature. | ||
134 | * @vdev: the device | ||
135 | * @fbit: the feature bit | ||
136 | */ | ||
137 | static inline bool virtio_has_feature(const struct virtio_device *vdev, | ||
138 | unsigned int fbit) | ||
139 | { | ||
93 | if (fbit < VIRTIO_TRANSPORT_F_START) | 140 | if (fbit < VIRTIO_TRANSPORT_F_START) |
94 | virtio_check_driver_offered_feature(vdev, fbit); | 141 | virtio_check_driver_offered_feature(vdev, fbit); |
95 | 142 | ||
96 | return test_bit(fbit, vdev->features); | 143 | return __virtio_test_bit(vdev, fbit); |
97 | } | 144 | } |
98 | 145 | ||
99 | static inline | 146 | static inline |