In CXL subsystem, many functions need to check an address availability
by checking if the resource range contains the address. Providing a new
helper function resource_contains_addr() to check if the resource range
contains the input address.
Suggested-by: Alison Schofield <alison.schofield@intel.com>
Signed-off-by: Li Ming <ming.li@zohomail.com>
Tested-by: Shiju Jose <shiju.jose@huawei.com>
---
drivers/cxl/core/core.h | 1 +
drivers/cxl/core/hdm.c | 8 ++++++++
2 files changed, 9 insertions(+)
diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h
index 29b61828a847..3798e9047175 100644
--- a/drivers/cxl/core/core.h
+++ b/drivers/cxl/core/core.h
@@ -80,6 +80,7 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, u64 size);
int cxl_dpa_free(struct cxl_endpoint_decoder *cxled);
resource_size_t cxl_dpa_size(struct cxl_endpoint_decoder *cxled);
resource_size_t cxl_dpa_resource_start(struct cxl_endpoint_decoder *cxled);
+bool resource_contains_addr(const struct resource *res, const resource_size_t addr);
enum cxl_rcrb {
CXL_RCRB_DOWNSTREAM,
diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
index ab1007495f6b..701a6a3baa6a 100644
--- a/drivers/cxl/core/hdm.c
+++ b/drivers/cxl/core/hdm.c
@@ -547,6 +547,14 @@ resource_size_t cxl_dpa_resource_start(struct cxl_endpoint_decoder *cxled)
return base;
}
+bool resource_contains_addr(const struct resource *res, const resource_size_t addr)
+{
+ if (res->flags & IORESOURCE_MEM)
+ return res->start <= addr && addr <= res->end;
+
+ return false;
+}
+
int cxl_dpa_free(struct cxl_endpoint_decoder *cxled)
{
struct cxl_port *port = cxled_to_port(cxled);
--
2.34.1
On Tue, Jul 08, 2025 at 01:15:34PM +0800, Li Ming wrote: > In CXL subsystem, many functions need to check an address availability > by checking if the resource range contains the address. Providing a new > helper function resource_contains_addr() to check if the resource range > contains the input address. with the cxl_ prefix added to the new helper, you can add: Reviewed-by: Alison Schofield <alison.schofield@intel.com> --snip
On Tue, Jul 08, 2025 at 01:15:34PM +0800, Li Ming wrote: > In CXL subsystem, many functions need to check an address availability > by checking if the resource range contains the address. Providing a new > helper function resource_contains_addr() to check if the resource range > contains the input address. ... > +bool resource_contains_addr(const struct resource *res, const resource_size_t addr); Right, the problem is that it collides with the resource namespace. Please, add a prefix. bool cxl_resource_contains_addr(const struct resource *res, const resource_size_t addr); ... > +bool resource_contains_addr(const struct resource *res, const resource_size_t addr) > +{ > + if (res->flags & IORESOURCE_MEM) resource_type() ? > + return res->start <= addr && addr <= res->end; > + > + return false; I still think using DEFINE_RES_MEM() with resource_contains() is a better approach. > +} -- With Best Regards, Andy Shevchenko
On 7/8/2025 9:20 PM, Andy Shevchenko wrote: > On Tue, Jul 08, 2025 at 01:15:34PM +0800, Li Ming wrote: >> In CXL subsystem, many functions need to check an address availability >> by checking if the resource range contains the address. Providing a new >> helper function resource_contains_addr() to check if the resource range >> contains the input address. > ... > >> +bool resource_contains_addr(const struct resource *res, const resource_size_t addr); > Right, the problem is that it collides with the resource namespace. Please, add a prefix. > > bool cxl_resource_contains_addr(const struct resource *res, const resource_size_t addr); > > ... > >> +bool resource_contains_addr(const struct resource *res, const resource_size_t addr) >> +{ >> + if (res->flags & IORESOURCE_MEM) > resource_type() ? > >> + return res->start <= addr && addr <= res->end; >> + >> + return false; > I still think using DEFINE_RES_MEM() with resource_contains() is a better > approach. Will do all you mentioned, thanks Ming
© 2016 - 2025 Red Hat, Inc.