1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_RANGE_H
3 #define _LINUX_RANGE_H
4 #include <linux/types.h>
5
6 struct range {
7 u64 start;
8 u64 end;
9 };
10
range_len(const struct range * range)11 static inline u64 range_len(const struct range *range)
12 {
13 return range->end - range->start + 1;
14 }
15
16 int add_range(struct range *range, int az, int nr_range,
17 u64 start, u64 end);
18
19
20 int add_range_with_merge(struct range *range, int az, int nr_range,
21 u64 start, u64 end);
22
23 void subtract_range(struct range *range, int az, u64 start, u64 end);
24
25 int clean_sort_range(struct range *range, int az);
26
27 void sort_range(struct range *range, int nr_range);
28
29 #define MAX_RESOURCE ((resource_size_t)~0)
cap_resource(u64 val)30 static inline resource_size_t cap_resource(u64 val)
31 {
32 if (val > MAX_RESOURCE)
33 return MAX_RESOURCE;
34
35 return val;
36 }
37 #endif
38