Merge tag 'fbdev-for-6.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/deller...
[linux-block.git] / include / linux / range.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
27811d8c
YL
2#ifndef _LINUX_RANGE_H
3#define _LINUX_RANGE_H
a4574f63 4#include <linux/types.h>
27811d8c
YL
5
6struct range {
7 u64 start;
8 u64 end;
9};
10
a4574f63
DW
11static inline u64 range_len(const struct range *range)
12{
13 return range->end - range->start + 1;
14}
15
93c177fd
DW
16static inline bool range_contains(struct range *r1, struct range *r2)
17{
18 return r1->start <= r2->start && r1->end >= r2->end;
19}
20
27811d8c
YL
21int add_range(struct range *range, int az, int nr_range,
22 u64 start, u64 end);
23
24
25int add_range_with_merge(struct range *range, int az, int nr_range,
26 u64 start, u64 end);
27
28void subtract_range(struct range *range, int az, u64 start, u64 end);
29
30int clean_sort_range(struct range *range, int az);
31
32void sort_range(struct range *range, int nr_range);
33
9ad3f2c7
YL
34#define MAX_RESOURCE ((resource_size_t)~0)
35static inline resource_size_t cap_resource(u64 val)
36{
37 if (val > MAX_RESOURCE)
38 return MAX_RESOURCE;
39
40 return val;
41}
27811d8c 42#endif