at v6.18-rc5 1.1 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef _LINUX_RANGE_H 3#define _LINUX_RANGE_H 4#include <linux/types.h> 5 6struct range { 7 u64 start; 8 u64 end; 9}; 10 11static inline u64 range_len(const struct range *range) 12{ 13 return range->end - range->start + 1; 14} 15 16/* True if r1 completely contains r2 */ 17static inline bool range_contains(const struct range *r1, 18 const struct range *r2) 19{ 20 return r1->start <= r2->start && r1->end >= r2->end; 21} 22 23/* True if any part of r1 overlaps r2 */ 24static inline bool range_overlaps(const struct range *r1, 25 const struct range *r2) 26{ 27 return r1->start <= r2->end && r1->end >= r2->start; 28} 29 30int add_range(struct range *range, int az, int nr_range, 31 u64 start, u64 end); 32 33 34int add_range_with_merge(struct range *range, int az, int nr_range, 35 u64 start, u64 end); 36 37void subtract_range(struct range *range, int az, u64 start, u64 end); 38 39int clean_sort_range(struct range *range, int az); 40 41void sort_range(struct range *range, int nr_range); 42 43#define DEFINE_RANGE(_start, _end) \ 44(struct range) { \ 45 .start = (_start), \ 46 .end = (_end), \ 47 } 48 49#endif