Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / include / linux / range.h
blobd7f98e1285d757b525e4c3f704276eabb99a5516
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_RANGE_H
3 #define _LINUX_RANGE_H
4 #include <linux/types.h>
6 struct range {
7 u64 start;
8 u64 end;
9 };
11 static inline u64 range_len(const struct range *range)
13 return range->end - range->start + 1;
16 /* True if r1 completely contains r2 */
17 static inline bool range_contains(const struct range *r1,
18 const struct range *r2)
20 return r1->start <= r2->start && r1->end >= r2->end;
23 /* True if any part of r1 overlaps r2 */
24 static inline bool range_overlaps(const struct range *r1,
25 const struct range *r2)
27 return r1->start <= r2->end && r1->end >= r2->start;
30 int add_range(struct range *range, int az, int nr_range,
31 u64 start, u64 end);
34 int add_range_with_merge(struct range *range, int az, int nr_range,
35 u64 start, u64 end);
37 void subtract_range(struct range *range, int az, u64 start, u64 end);
39 int clean_sort_range(struct range *range, int az);
41 void sort_range(struct range *range, int nr_range);
43 #define DEFINE_RANGE(_start, _end) \
44 (struct range) { \
45 .start = (_start), \
46 .end = (_end), \
49 #endif