From 08ccc1f56cc70c4116abac3d1cbe392b867d10bf Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 11 Sep 2025 08:59:40 +0200 Subject: ioport: Add resource check helpers Add resource_overlaps() and resource_contains() helpers. Code copied from kernel source. Signed-off-by: Patrice Chotard Reviewed-by: Patrick Delaunay --- include/linux/ioport.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include/linux') diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 85288c3729a..c12a7f70ad7 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -135,6 +135,22 @@ static inline unsigned long resource_type(const struct resource *res) return res->flags & IORESOURCE_TYPE_BITS; } +/* True iff r1 completely contains r2 */ +static inline bool resource_contains(struct resource *r1, struct resource *r2) +{ + if (resource_type(r1) != resource_type(r2)) + return false; + if (r1->flags & IORESOURCE_UNSET || r2->flags & IORESOURCE_UNSET) + return false; + return r1->start <= r2->start && r1->end >= r2->end; +} + +/* True if any part of r1 overlaps r2 */ +static inline bool resource_overlaps(struct resource *r1, struct resource *r2) +{ + return r1->start <= r2->end && r1->end >= r2->start; +} + /* Convenience shorthand with allocation */ #define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0) #define __request_mem_region(start,n,name, excl) __request_region(&iomem_resource, (start), (n), (name), excl) -- cgit v1.2.3 From 70ae44f3713427be5368d0829b97cafbd01ef1f5 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 22 Sep 2025 14:29:22 +0200 Subject: linux/kernel.h: Update upper_NN_bits() and lower_NN_bits() macros Synchronize upper_NN_bits() and lower_NN_bits() macros with Linux 6.16 commit 118d777c4cb4 ("wordpart.h: Add REPEAT_BYTE_U32()"). This fixes the lower_32_bits() macros and assures it works with 64bit systems correctly. This also adds 16bit variants of these macros, which will be used by the Airoha PHY driver. Signed-off-by: Marek Vasut Reviewed-by: Tom Rini --- include/linux/kernel.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'include/linux') diff --git a/include/linux/kernel.h b/include/linux/kernel.h index e0443ecac84..44a639a5e4e 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -111,7 +111,19 @@ * lower_32_bits - return bits 0-31 of a number * @n: the number we're accessing */ -#define lower_32_bits(n) ((u32)(n)) +#define lower_32_bits(n) ((u32)((n) & 0xffffffff)) + +/** + * upper_16_bits - return bits 16-31 of a number + * @n: the number we're accessing + */ +#define upper_16_bits(n) ((u16)((n) >> 16)) + +/** + * lower_16_bits - return bits 0-15 of a number + * @n: the number we're accessing + */ +#define lower_16_bits(n) ((u16)((n) & 0xffff)) /* * abs() handles unsigned and signed longs, ints, shorts and chars. For all -- cgit v1.2.3