cxl: Remove core/acpi.c and cxl core dependency on ACPI
Dave Jiang
maintainerPATCH v3 1/1 cxl: Remove core/acpi.c and cxl core dependency on ACPI
It was a mistake to introduce core/acpi.c and putting ACPI dependency on cxl_core when adding the extended linear cache support. Add a callback in the cxl_root_decoder to retrieve the extended linear cache size from ACPI via the cxl_acpi driver.
---
v3:
- Remove commit log paragraph on adding extra dev parameter. (Jonathan)
- Add device ref put. (Jonathan)
- Adjust var declaration. (Jonathan)
- Move callback assignment to same group. (Jonathan)
--- drivers/cxl/acpi.c | 13 +++++++++++- drivers/cxl/core/Makefile | 1 - drivers/cxl/core/acpi.c | 11 ---------- drivers/cxl/core/core.h | 2 -- drivers/cxl/core/port.c | 5 ++++- drivers/cxl/core/region.c | 5 ++++- drivers/cxl/cxl.h | 10 ++++++++- tools/testing/cxl/Kbuild | 2 +- tools/testing/cxl/test/cxl.c | 40 +++++++++++++++++++++++++++++++++++ tools/testing/cxl/test/mock.c | 19 +++++++++++++++++ tools/testing/cxl/test/mock.h | 3 +++ 11 files changed, 92 insertions(+), 19 deletions(-) delete mode 100644 drivers/cxl/core/acpi.c
drivers/cxl/acpi.c +12 -1
@@ -335,6 +335,17 @@ static int add_or_reset_cxl_resource(struct resource *parent, struct resource *rreturn rc; } +static int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, +int nid, +resource_size_t *size) +{ +return hmat_get_extended_linear_cache_size (backing_res, nid, size); +} + +static const struct cxl_rd_ops acpi_rd_ops = { + .get_extended_linear_cache_size = cxl_acpi_get_extended_linear_cache_size, +}; + DEFINE_FREE(put_cxlrd, struct cxl_root_decoder *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->cxlsd.cxld.dev)) DEFINE_FREE(del_cxl_resource, struct resource *, if (_T) del_cxl_resource(_T))
@@ -373,7 +384,7 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws,return rc; struct cxl_root_decoder *cxlrd __free(put_cxlrd) = -cxl_root_decoder_alloc (root_port, ways); +cxl_root_decoder_alloc (root_port, ways, &acpi_rd_ops);if (IS_ERR (cxlrd))return PTR_ERR (cxlrd);
drivers/cxl/core/Makefile +0 -1
@@ -15,7 +15,6 @@ cxl_core-y += hdm.o cxl_core-y += pmu.o cxl_core-y += cdat.o cxl_core-y += ras.o -cxl_core-y += acpi.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o cxl_core-$(CONFIG_CXL_MCE) += mce.o
drivers/cxl/core/acpi.c deleted +0 -11
@@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* Copyright(c) 2024 Intel Corporation. All rights reserved. */ -#include <linux/acpi.h> -#include "cxl.h" -#include "core.h" - -int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, -int nid,resource_size_t *size) -{ -return hmat_get_extended_linear_cache_size (backing_res, nid, size); -}
drivers/cxl/core/core.h +0 -2
@@ -120,8 +120,6 @@ int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,int cxl_ras_init (void );void cxl_ras_exit (void );int cxl_gpf_port_setup (struct cxl_dport *dport); -int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, -int nid,resource_size_t *size);#ifdef CONFIG_CXL_FEATURES struct cxl_feat_entry *
drivers/cxl/core/port.c +4 -1
@@ -1793,6 +1793,7 @@ static int cxl_switch_decoder_init(struct cxl_port *port,* cxl_root_decoder_alloc - Allocate a root level decoder * @port: owning CXL root of this decoder * @nr_targets: static number of downstream targets +* @ops: root decoder callback operations * * Return: A new cxl decoder to be registered by cxl_decoder_add(). A * 'CXL root' decoder is one that decodes from a top-level / static platform
@@ -1800,7 +1801,8 @@ static int cxl_switch_decoder_init(struct cxl_port *port,* topology. */ struct cxl_root_decoder *cxl_root_decoder_alloc (struct cxl_port *port, -unsigned int nr_targets) +unsigned int nr_targets, +const struct cxl_rd_ops *ops) {struct cxl_root_decoder *cxlrd;struct cxl_switch_decoder *cxlsd;
@@ -1839,6 +1841,7 @@ struct cxl_root_decoder *cxl_root_decoder_alloc(struct cxl_port *port,atomic_set (&cxlrd->region_id, rc); cxlrd->qos_class =CXL_QOS_CLASS_INVALID ; + cxlrd->ops = ops;return cxlrd; }EXPORT_SYMBOL_NS_GPL (cxl_root_decoder_alloc,"CXL" );
drivers/cxl/core/region.c +4 -1
@@ -3287,7 +3287,10 @@ static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr,resource_size_t cache_size, start;int rc; - rc =cxl_acpi_get_extended_linear_cache_size (res, nid, &cache_size); +if (!cxlrd->ops || !cxlrd->ops->get_extended_linear_cache_size) +return -EOPNOTSUPP ; + + rc = cxlrd->ops->get_extended_linear_cache_size (res, nid, &cache_size);if (rc)return rc;
drivers/cxl/cxl.h +9 -1
@@ -420,6 +420,11 @@ struct cxl_switch_decoder {struct cxl_root_decoder ;typedef u64 (*cxl_hpa_to_spa_fn )(struct cxl_root_decoder *cxlrd,u64 hpa); +struct cxl_rd_ops { +int (*get_extended_linear_cache_size)(struct resource *backing_res, +int nid,resource_size_t *size); +}; +/** * struct cxl_root_decoder - Static platform CXL address decoder * @res: host / parent resource for region allocations
@@ -428,6 +433,7 @@ typedef u64 (*cxl_hpa_to_spa_fn)(struct cxl_root_decoder *cxlrd, u64 hpa);* @platform_data: platform specific configuration data * @range_lock: sync region autodiscovery by address range * @qos_class: QoS performance class cookie +* @ops: root decoder specific operations * @cxlsd: base cxl switch decoder */ struct cxl_root_decoder {
@@ -437,6 +443,7 @@ struct cxl_root_decoder {void *platform_data;struct mutex range_lock;int qos_class; +const struct cxl_rd_ops *ops;struct cxl_switch_decoder cxlsd; };
@@ -775,7 +782,8 @@ bool is_root_decoder(struct device *dev);bool is_switch_decoder (struct device *dev);bool is_endpoint_decoder (struct device *dev);struct cxl_root_decoder *cxl_root_decoder_alloc (struct cxl_port *port, -unsigned int nr_targets); +unsigned int nr_targets, +const struct cxl_rd_ops *ops);struct cxl_switch_decoder *cxl_switch_decoder_alloc (struct cxl_port *port,unsigned int nr_targets);int cxl_decoder_add (struct cxl_decoder *cxld,int *target_map);
tools/testing/cxl/Kbuild +1 -1
@@ -15,6 +15,7 @@ ldflags-y += --wrap=devm_cxl_add_rch_dport ldflags-y += --wrap=cxl_rcd_component_reg_phys ldflags-y += --wrap=cxl_endpoint_parse_cdat ldflags-y += --wrap=cxl_dport_init_ras_reporting +ldflags-y += --wrap=hmat_get_extended_linear_cache_size DRIVERS := ../../../drivers CXL_SRC := $(DRIVERS)/cxl
@@ -62,7 +63,6 @@ cxl_core-y += $(CXL_CORE_SRC)/hdm.o cxl_core-y += $(CXL_CORE_SRC)/pmu.o cxl_core-y += $(CXL_CORE_SRC)/cdat.o cxl_core-y += $(CXL_CORE_SRC)/ras.o -cxl_core-y += $(CXL_CORE_SRC)/acpi.o cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.o
tools/testing/cxl/test/cxl.c +40 -0
@@ -470,6 +470,44 @@ struct cxl_cedt_context {struct device *dev; }; +static int match_root_decoder_by_range (struct device *dev,const void *data) +{ +struct cxl_root_decoder *cxlrd; +const struct range *r2 = data; +const struct range *r1; + +if (!is_root_decoder (dev)) +return 0 ; + + cxlrd =to_cxl_root_decoder (dev); + r1 = &cxlrd->cxlsd.cxld.hpa_range; +return range_contains (r1, r2); +} + +static int mock_hmat_get_extended_linear_cache_size (struct resource *backing_res, +int nid,resource_size_t *size) +{ +struct range backing_range = { + .start = backing_res->start, + .end = backing_res->end, + }; +struct cxl_decoder *cxld; +struct cxl_port *port; + + struct device *dev __free(put_device) = +bus_find_device (&cxl_bus_type,NULL , &backing_range, + match_root_decoder_by_range); +if (!dev) +return -ENODEV ; + + cxld =to_cxl_decoder (dev); + port =to_cxl_port (cxld->dev.parent); +if (is_mock_dev (port->uport_dev)) +return -EOPNOTSUPP ; + +return hmat_get_extended_linear_cache_size (backing_res, nid, size); +} +static int mock_acpi_table_parse_cedt (enum acpi_cedt_type id,acpi_tbl_entry_handler_arg handler_arg,void *arg)
@@ -1039,6 +1077,8 @@ static struct cxl_mock_ops cxl_mock_ops = { .devm_cxl_add_passthrough_decoder = mock_cxl_add_passthrough_decoder, .devm_cxl_enumerate_decoders = mock_cxl_enumerate_decoders, .cxl_endpoint_parse_cdat = mock_cxl_endpoint_parse_cdat, + .hmat_get_extended_linear_cache_size = + mock_hmat_get_extended_linear_cache_size, .list = LIST_HEAD_INIT(cxl_mock_ops.list), };
tools/testing/cxl/test/mock.c +19 -0
@@ -78,6 +78,25 @@ int __wrap_acpi_table_parse_cedt(enum acpi_cedt_type id, }EXPORT_SYMBOL_NS_GPL (__wrap_acpi_table_parse_cedt,"ACPI" ); +int __wrap_hmat_get_extended_linear_cache_size (struct resource *res, +int nid, +resource_size_t *size) +{ +int index; +struct cxl_mock_ops *ops =get_cxl_mock_ops (&index); +int rc; + +if (ops) + rc = ops->hmat_get_extended_linear_cache_size (res, nid, size); +else + rc =hmat_get_extended_linear_cache_size (res, nid, size); + +put_cxl_mock_ops (index); + +return rc; +} +EXPORT_SYMBOL_NS_GPL (__wrap_hmat_get_extended_linear_cache_size,"CXL" ); + acpi_status __wrap_acpi_evaluate_integer(acpi_handle handle, acpi_string pathname, struct acpi_object_list *arguments,
tools/testing/cxl/test/mock.h +3 -0
@@ -26,6 +26,9 @@ struct cxl_mock_ops {int (*devm_cxl_enumerate_decoders)(struct cxl_hdm *hdm,struct cxl_endpoint_dvsec_info *info);void (*cxl_endpoint_parse_cdat)(struct cxl_port *port); +int (*hmat_get_extended_linear_cache_size)(struct resource *backing_res, +int nid, +resource_size_t *size); };void register_cxl_mock_ops (struct cxl_mock_ops *ops);
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
Signature · 1 line
2.49.0
Quoted 6 lines · On Tue, 10 Jun 2025 10:29:38 -0700 Dave Jiang <[email protected]> wrote:
It was a mistake to introduce
core/acpi.cand putting ACPI dependency oncxl_corewhen adding the extended linear cache support. Add a callback in thecxl_root_decoderto retrieve the extended linear cache size from ACPI via thecxl_acpidriver.Signed-off-by Dave Jiang <[email protected]>
LGTM
Quoted 4 lines · Dave Jiang
It was a mistake to introduce
core/acpi.cand putting ACPI dependency oncxl_corewhen adding the extended linear cache support. Add a callback in thecxl_root_decoderto retrieve the extended linear cache size from ACPI via thecxl_acpidriver.
I see the introduction of struct cxl_rd_ops and am wondering why
the other existing root decoder callback is not added to that
new grouping...
* @hpa_to_spa: translate CXL host-physical-address to Platform system-physical-address
Seems it can join that _ops group with some updates at the call site. BTW - another root decoder callback is in the works for the inverse spa_to_hpa, so that'll join your ops group too.
If you don't want to do that now, or it's not a fit, you can add:
Otherwise, I'll review and tag a v4.
Quoted 311 lines
Signed-off-by Dave Jiang <[email protected]>---
v3:
- Remove commit log paragraph on adding extra dev parameter. (Jonathan)
- Add device ref put. (Jonathan)
- Adjust var declaration. (Jonathan)
- Move callback assignment to same group. (Jonathan)--- drivers/cxl/acpi.c | 13 +++++++++++- drivers/cxl/core/Makefile | 1 - drivers/cxl/core/acpi.c | 11 ---------- drivers/cxl/core/core.h | 2 -- drivers/cxl/core/port.c | 5 ++++- drivers/cxl/core/region.c | 5 ++++- drivers/cxl/cxl.h | 10 ++++++++- tools/testing/cxl/Kbuild | 2 +- tools/testing/cxl/test/cxl.c | 40 +++++++++++++++++++++++++++++++++++ tools/testing/cxl/test/mock.c | 19 +++++++++++++++++ tools/testing/cxl/test/mock.h | 3 +++ 11 files changed, 92 insertions(+), 19 deletions(-) delete mode 100644 drivers/cxl/core/acpi.cdrivers/cxl/acpi.c +12
-1@@ -335,6 +335,17 @@ static int add_or_reset_cxl_resource(struct resource *parent, struct resource *rreturn rc; } +static int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, +int nid, +resource_size_t *size) +{ +return hmat_get_extended_linear_cache_size (backing_res, nid, size); +} + +static const struct cxl_rd_ops acpi_rd_ops = { + .get_extended_linear_cache_size = cxl_acpi_get_extended_linear_cache_size, +}; + DEFINE_FREE(put_cxlrd, struct cxl_root_decoder *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->cxlsd.cxld.dev)) DEFINE_FREE(del_cxl_resource, struct resource *, if (_T) del_cxl_resource(_T))@@ -373,7 +384,7 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws,return rc; struct cxl_root_decoder *cxlrd __free(put_cxlrd) = -cxl_root_decoder_alloc (root_port, ways); +cxl_root_decoder_alloc (root_port, ways, &acpi_rd_ops);if (IS_ERR (cxlrd))return PTR_ERR (cxlrd);drivers/cxl/core/Makefile +0
-1@@ -15,7 +15,6 @@ cxl_core-y += hdm.o cxl_core-y += pmu.o cxl_core-y += cdat.o cxl_core-y += ras.o -cxl_core-y += acpi.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o cxl_core-$(CONFIG_CXL_MCE) += mce.odrivers/cxl/core/acpi.c deleted +0
-11@@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* Copyright(c) 2024 Intel Corporation. All rights reserved. */ -#include <linux/acpi.h> -#include "cxl.h" -#include "core.h" - -int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, -int nid,resource_size_t *size) -{ -return hmat_get_extended_linear_cache_size (backing_res, nid, size); -}drivers/cxl/core/core.h +0
-2@@ -120,8 +120,6 @@ int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,int cxl_ras_init (void );void cxl_ras_exit (void );int cxl_gpf_port_setup (struct cxl_dport *dport); -int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, -int nid,resource_size_t *size);#ifdef CONFIG_CXL_FEATURES struct cxl_feat_entry *drivers/cxl/core/port.c +4
-1@@ -1793,6 +1793,7 @@ static int cxl_switch_decoder_init(struct cxl_port *port,* cxl_root_decoder_alloc - Allocate a root level decoder * @port: owning CXL root of this decoder * @nr_targets: static number of downstream targets +* @ops: root decoder callback operations * * Return: A new cxl decoder to be registered by cxl_decoder_add(). A * 'CXL root' decoder is one that decodes from a top-level / static platform @@ -1800,7 +1801,8 @@ static int cxl_switch_decoder_init(struct cxl_port *port,* topology. */ struct cxl_root_decoder *cxl_root_decoder_alloc (struct cxl_port *port, -unsigned int nr_targets) +unsigned int nr_targets, +const struct cxl_rd_ops *ops) {struct cxl_root_decoder *cxlrd;struct cxl_switch_decoder *cxlsd;@@ -1839,6 +1841,7 @@ struct cxl_root_decoder *cxl_root_decoder_alloc(struct cxl_port *port,atomic_set (&cxlrd->region_id, rc); cxlrd->qos_class =CXL_QOS_CLASS_INVALID ; + cxlrd->ops = ops;return cxlrd; }EXPORT_SYMBOL_NS_GPL (cxl_root_decoder_alloc,"CXL" );drivers/cxl/core/region.c +4
-1@@ -3287,7 +3287,10 @@ static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr,resource_size_t cache_size, start;int rc; - rc =cxl_acpi_get_extended_linear_cache_size (res, nid, &cache_size); +if (!cxlrd->ops || !cxlrd->ops->get_extended_linear_cache_size) +return -EOPNOTSUPP ; + + rc = cxlrd->ops->get_extended_linear_cache_size (res, nid, &cache_size);if (rc)return rc;drivers/cxl/cxl.h +9
-1@@ -420,6 +420,11 @@ struct cxl_switch_decoder {struct cxl_root_decoder ;typedef u64 (*cxl_hpa_to_spa_fn )(struct cxl_root_decoder *cxlrd,u64 hpa); +struct cxl_rd_ops { +int (*get_extended_linear_cache_size)(struct resource *backing_res, +int nid,resource_size_t *size); +}; +/** * struct cxl_root_decoder - Static platform CXL address decoder * @res: host / parent resource for region allocations @@ -428,6 +433,7 @@ typedef u64 (*cxl_hpa_to_spa_fn)(struct cxl_root_decoder *cxlrd, u64 hpa);* @platform_data: platform specific configuration data * @range_lock: sync region autodiscovery by address range * @qos_class: QoS performance class cookie +* @ops: root decoder specific operations * @cxlsd: base cxl switch decoder */ struct cxl_root_decoder {@@ -437,6 +443,7 @@ struct cxl_root_decoder {void *platform_data;struct mutex range_lock;int qos_class; +const struct cxl_rd_ops *ops;struct cxl_switch_decoder cxlsd; };@@ -775,7 +782,8 @@ bool is_root_decoder(struct device *dev);bool is_switch_decoder (struct device *dev);bool is_endpoint_decoder (struct device *dev);struct cxl_root_decoder *cxl_root_decoder_alloc (struct cxl_port *port, -unsigned int nr_targets); +unsigned int nr_targets, +const struct cxl_rd_ops *ops);struct cxl_switch_decoder *cxl_switch_decoder_alloc (struct cxl_port *port,unsigned int nr_targets);int cxl_decoder_add (struct cxl_decoder *cxld,int *target_map);tools/testing/cxl/Kbuild +1
-1@@ -15,6 +15,7 @@ ldflags-y += --wrap=devm_cxl_add_rch_dport ldflags-y += --wrap=cxl_rcd_component_reg_phys ldflags-y += --wrap=cxl_endpoint_parse_cdat ldflags-y += --wrap=cxl_dport_init_ras_reporting +ldflags-y += --wrap=hmat_get_extended_linear_cache_size DRIVERS := ../../../drivers CXL_SRC := $(DRIVERS)/cxl@@ -62,7 +63,6 @@ cxl_core-y += $(CXL_CORE_SRC)/hdm.o cxl_core-y += $(CXL_CORE_SRC)/pmu.o cxl_core-y += $(CXL_CORE_SRC)/cdat.o cxl_core-y += $(CXL_CORE_SRC)/ras.o -cxl_core-y += $(CXL_CORE_SRC)/acpi.o cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.otools/testing/cxl/test/cxl.c +40
-0@@ -470,6 +470,44 @@ struct cxl_cedt_context {struct device *dev; }; +static int match_root_decoder_by_range (struct device *dev,const void *data) +{ +struct cxl_root_decoder *cxlrd; +const struct range *r2 = data; +const struct range *r1; + +if (!is_root_decoder (dev)) +return 0 ; + + cxlrd =to_cxl_root_decoder (dev); + r1 = &cxlrd->cxlsd.cxld.hpa_range; +return range_contains (r1, r2); +} + +static int mock_hmat_get_extended_linear_cache_size (struct resource *backing_res, +int nid,resource_size_t *size) +{ +struct range backing_range = { + .start = backing_res->start, + .end = backing_res->end, + }; +struct cxl_decoder *cxld; +struct cxl_port *port; + + struct device *dev __free(put_device) = +bus_find_device (&cxl_bus_type,NULL , &backing_range, + match_root_decoder_by_range); +if (!dev) +return -ENODEV ; + + cxld =to_cxl_decoder (dev); + port =to_cxl_port (cxld->dev.parent); +if (is_mock_dev (port->uport_dev)) +return -EOPNOTSUPP ; + +return hmat_get_extended_linear_cache_size (backing_res, nid, size); +} +static int mock_acpi_table_parse_cedt (enum acpi_cedt_type id,acpi_tbl_entry_handler_arg handler_arg,void *arg)@@ -1039,6 +1077,8 @@ static struct cxl_mock_ops cxl_mock_ops = { .devm_cxl_add_passthrough_decoder = mock_cxl_add_passthrough_decoder, .devm_cxl_enumerate_decoders = mock_cxl_enumerate_decoders, .cxl_endpoint_parse_cdat = mock_cxl_endpoint_parse_cdat, + .hmat_get_extended_linear_cache_size = + mock_hmat_get_extended_linear_cache_size, .list = LIST_HEAD_INIT(cxl_mock_ops.list), };tools/testing/cxl/test/mock.c +19
-0@@ -78,6 +78,25 @@ int __wrap_acpi_table_parse_cedt(enum acpi_cedt_type id, }EXPORT_SYMBOL_NS_GPL (__wrap_acpi_table_parse_cedt,"ACPI" ); +int __wrap_hmat_get_extended_linear_cache_size (struct resource *res, +int nid, +resource_size_t *size) +{ +int index; +struct cxl_mock_ops *ops =get_cxl_mock_ops (&index); +int rc; + +if (ops) + rc = ops->hmat_get_extended_linear_cache_size (res, nid, size); +else + rc =hmat_get_extended_linear_cache_size (res, nid, size); + +put_cxl_mock_ops (index); + +return rc; +} +EXPORT_SYMBOL_NS_GPL (__wrap_hmat_get_extended_linear_cache_size,"CXL" ); + acpi_status __wrap_acpi_evaluate_integer(acpi_handle handle, acpi_string pathname, struct acpi_object_list *arguments,tools/testing/cxl/test/mock.h +3
-0@@ -26,6 +26,9 @@ struct cxl_mock_ops {int (*devm_cxl_enumerate_decoders)(struct cxl_hdm *hdm,struct cxl_endpoint_dvsec_info *info);void (*cxl_endpoint_parse_cdat)(struct cxl_port *port); +int (*hmat_get_extended_linear_cache_size)(struct resource *backing_res, +int nid, +resource_size_t *size); };void register_cxl_mock_ops (struct cxl_mock_ops *ops);base-commit:
19272b37aa4f83ca52bdf9c16d5d81bdd1354494Signature · 1 line
2.49.0
Dave Jiang
maintainerQuoted 6 lines · Alison Schofield
Quoted 4 lines · Dave Jiang
It was a mistake to introduce
core/acpi.cand putting ACPI dependency oncxl_corewhen adding the extended linear cache support. Add a callback in thecxl_root_decoderto retrieve the extended linear cache size from ACPI via thecxl_acpidriver.
Quoted 8 lines
I see the introduction of struct
cxl_rd_opsand am wondering why
the other existing root decoder callback is not added to that
new grouping...
* @hpa_to_spa: translate CXL host-physical-address to Platform system-physical-addressSeems it can join that
_opsgroup with some updates at the call site. BTW - another root decoder callback is in the works for the inversespa_to_hpa, so that'll join your ops group too.
Will create a follow on patch for this.
DJ
Quoted 317 lines
If you don't want to do that now, or it's not a fit, you can add:
Reviewed-by Alison Schofield <[email protected]>Otherwise, I'll review and tag a v4.
Quoted 311 lines
Signed-off-by Dave Jiang <[email protected]>---
v3:
- Remove commit log paragraph on adding extra dev parameter. (Jonathan)
- Add device ref put. (Jonathan)
- Adjust var declaration. (Jonathan)
- Move callback assignment to same group. (Jonathan)--- drivers/cxl/acpi.c | 13 +++++++++++- drivers/cxl/core/Makefile | 1 - drivers/cxl/core/acpi.c | 11 ---------- drivers/cxl/core/core.h | 2 -- drivers/cxl/core/port.c | 5 ++++- drivers/cxl/core/region.c | 5 ++++- drivers/cxl/cxl.h | 10 ++++++++- tools/testing/cxl/Kbuild | 2 +- tools/testing/cxl/test/cxl.c | 40 +++++++++++++++++++++++++++++++++++ tools/testing/cxl/test/mock.c | 19 +++++++++++++++++ tools/testing/cxl/test/mock.h | 3 +++ 11 files changed, 92 insertions(+), 19 deletions(-) delete mode 100644 drivers/cxl/core/acpi.cdrivers/cxl/acpi.c +12
-1@@ -335,6 +335,17 @@ static int add_or_reset_cxl_resource(struct resource *parent, struct resource *rreturn rc; } +static int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, +int nid, +resource_size_t *size) +{ +return hmat_get_extended_linear_cache_size (backing_res, nid, size); +} + +static const struct cxl_rd_ops acpi_rd_ops = { + .get_extended_linear_cache_size = cxl_acpi_get_extended_linear_cache_size, +}; + DEFINE_FREE(put_cxlrd, struct cxl_root_decoder *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->cxlsd.cxld.dev)) DEFINE_FREE(del_cxl_resource, struct resource *, if (_T) del_cxl_resource(_T))@@ -373,7 +384,7 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws,return rc; struct cxl_root_decoder *cxlrd __free(put_cxlrd) = -cxl_root_decoder_alloc (root_port, ways); +cxl_root_decoder_alloc (root_port, ways, &acpi_rd_ops);if (IS_ERR (cxlrd))return PTR_ERR (cxlrd);drivers/cxl/core/Makefile +0
-1@@ -15,7 +15,6 @@ cxl_core-y += hdm.o cxl_core-y += pmu.o cxl_core-y += cdat.o cxl_core-y += ras.o -cxl_core-y += acpi.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o cxl_core-$(CONFIG_CXL_MCE) += mce.odrivers/cxl/core/acpi.c deleted +0
-11@@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* Copyright(c) 2024 Intel Corporation. All rights reserved. */ -#include <linux/acpi.h> -#include "cxl.h" -#include "core.h" - -int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, -int nid,resource_size_t *size) -{ -return hmat_get_extended_linear_cache_size (backing_res, nid, size); -}drivers/cxl/core/core.h +0
-2@@ -120,8 +120,6 @@ int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,int cxl_ras_init (void );void cxl_ras_exit (void );int cxl_gpf_port_setup (struct cxl_dport *dport); -int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, -int nid,resource_size_t *size);#ifdef CONFIG_CXL_FEATURES struct cxl_feat_entry *drivers/cxl/core/port.c +4
-1@@ -1793,6 +1793,7 @@ static int cxl_switch_decoder_init(struct cxl_port *port,* cxl_root_decoder_alloc - Allocate a root level decoder * @port: owning CXL root of this decoder * @nr_targets: static number of downstream targets +* @ops: root decoder callback operations * * Return: A new cxl decoder to be registered by cxl_decoder_add(). A * 'CXL root' decoder is one that decodes from a top-level / static platform @@ -1800,7 +1801,8 @@ static int cxl_switch_decoder_init(struct cxl_port *port,* topology. */ struct cxl_root_decoder *cxl_root_decoder_alloc (struct cxl_port *port, -unsigned int nr_targets) +unsigned int nr_targets, +const struct cxl_rd_ops *ops) {struct cxl_root_decoder *cxlrd;struct cxl_switch_decoder *cxlsd;@@ -1839,6 +1841,7 @@ struct cxl_root_decoder *cxl_root_decoder_alloc(struct cxl_port *port,atomic_set (&cxlrd->region_id, rc); cxlrd->qos_class =CXL_QOS_CLASS_INVALID ; + cxlrd->ops = ops;return cxlrd; }EXPORT_SYMBOL_NS_GPL (cxl_root_decoder_alloc,"CXL" );drivers/cxl/core/region.c +4
-1@@ -3287,7 +3287,10 @@ static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr,resource_size_t cache_size, start;int rc; - rc =cxl_acpi_get_extended_linear_cache_size (res, nid, &cache_size); +if (!cxlrd->ops || !cxlrd->ops->get_extended_linear_cache_size) +return -EOPNOTSUPP ; + + rc = cxlrd->ops->get_extended_linear_cache_size (res, nid, &cache_size);if (rc)return rc;drivers/cxl/cxl.h +9
-1@@ -420,6 +420,11 @@ struct cxl_switch_decoder {struct cxl_root_decoder ;typedef u64 (*cxl_hpa_to_spa_fn )(struct cxl_root_decoder *cxlrd,u64 hpa); +struct cxl_rd_ops { +int (*get_extended_linear_cache_size)(struct resource *backing_res, +int nid,resource_size_t *size); +}; +/** * struct cxl_root_decoder - Static platform CXL address decoder * @res: host / parent resource for region allocations @@ -428,6 +433,7 @@ typedef u64 (*cxl_hpa_to_spa_fn)(struct cxl_root_decoder *cxlrd, u64 hpa);* @platform_data: platform specific configuration data * @range_lock: sync region autodiscovery by address range * @qos_class: QoS performance class cookie +* @ops: root decoder specific operations * @cxlsd: base cxl switch decoder */ struct cxl_root_decoder {@@ -437,6 +443,7 @@ struct cxl_root_decoder {void *platform_data;struct mutex range_lock;int qos_class; +const struct cxl_rd_ops *ops;struct cxl_switch_decoder cxlsd; };@@ -775,7 +782,8 @@ bool is_root_decoder(struct device *dev);bool is_switch_decoder (struct device *dev);bool is_endpoint_decoder (struct device *dev);struct cxl_root_decoder *cxl_root_decoder_alloc (struct cxl_port *port, -unsigned int nr_targets); +unsigned int nr_targets, +const struct cxl_rd_ops *ops);struct cxl_switch_decoder *cxl_switch_decoder_alloc (struct cxl_port *port,unsigned int nr_targets);int cxl_decoder_add (struct cxl_decoder *cxld,int *target_map);tools/testing/cxl/Kbuild +1
-1@@ -15,6 +15,7 @@ ldflags-y += --wrap=devm_cxl_add_rch_dport ldflags-y += --wrap=cxl_rcd_component_reg_phys ldflags-y += --wrap=cxl_endpoint_parse_cdat ldflags-y += --wrap=cxl_dport_init_ras_reporting +ldflags-y += --wrap=hmat_get_extended_linear_cache_size DRIVERS := ../../../drivers CXL_SRC := $(DRIVERS)/cxl@@ -62,7 +63,6 @@ cxl_core-y += $(CXL_CORE_SRC)/hdm.o cxl_core-y += $(CXL_CORE_SRC)/pmu.o cxl_core-y += $(CXL_CORE_SRC)/cdat.o cxl_core-y += $(CXL_CORE_SRC)/ras.o -cxl_core-y += $(CXL_CORE_SRC)/acpi.o cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.otools/testing/cxl/test/cxl.c +40
-0@@ -470,6 +470,44 @@ struct cxl_cedt_context {struct device *dev; }; +static int match_root_decoder_by_range (struct device *dev,const void *data) +{ +struct cxl_root_decoder *cxlrd; +const struct range *r2 = data; +const struct range *r1; + +if (!is_root_decoder (dev)) +return 0 ; + + cxlrd =to_cxl_root_decoder (dev); + r1 = &cxlrd->cxlsd.cxld.hpa_range; +return range_contains (r1, r2); +} + +static int mock_hmat_get_extended_linear_cache_size (struct resource *backing_res, +int nid,resource_size_t *size) +{ +struct range backing_range = { + .start = backing_res->start, + .end = backing_res->end, + }; +struct cxl_decoder *cxld; +struct cxl_port *port; + + struct device *dev __free(put_device) = +bus_find_device (&cxl_bus_type,NULL , &backing_range, + match_root_decoder_by_range); +if (!dev) +return -ENODEV ; + + cxld =to_cxl_decoder (dev); + port =to_cxl_port (cxld->dev.parent); +if (is_mock_dev (port->uport_dev)) +return -EOPNOTSUPP ; + +return hmat_get_extended_linear_cache_size (backing_res, nid, size); +} +static int mock_acpi_table_parse_cedt (enum acpi_cedt_type id,acpi_tbl_entry_handler_arg handler_arg,void *arg)@@ -1039,6 +1077,8 @@ static struct cxl_mock_ops cxl_mock_ops = { .devm_cxl_add_passthrough_decoder = mock_cxl_add_passthrough_decoder, .devm_cxl_enumerate_decoders = mock_cxl_enumerate_decoders, .cxl_endpoint_parse_cdat = mock_cxl_endpoint_parse_cdat, + .hmat_get_extended_linear_cache_size = + mock_hmat_get_extended_linear_cache_size, .list = LIST_HEAD_INIT(cxl_mock_ops.list), };tools/testing/cxl/test/mock.c +19
-0@@ -78,6 +78,25 @@ int __wrap_acpi_table_parse_cedt(enum acpi_cedt_type id, }EXPORT_SYMBOL_NS_GPL (__wrap_acpi_table_parse_cedt,"ACPI" ); +int __wrap_hmat_get_extended_linear_cache_size (struct resource *res, +int nid, +resource_size_t *size) +{ +int index; +struct cxl_mock_ops *ops =get_cxl_mock_ops (&index); +int rc; + +if (ops) + rc = ops->hmat_get_extended_linear_cache_size (res, nid, size); +else + rc =hmat_get_extended_linear_cache_size (res, nid, size); + +put_cxl_mock_ops (index); + +return rc; +} +EXPORT_SYMBOL_NS_GPL (__wrap_hmat_get_extended_linear_cache_size,"CXL" ); + acpi_status __wrap_acpi_evaluate_integer(acpi_handle handle, acpi_string pathname, struct acpi_object_list *arguments,tools/testing/cxl/test/mock.h +3
-0@@ -26,6 +26,9 @@ struct cxl_mock_ops {int (*devm_cxl_enumerate_decoders)(struct cxl_hdm *hdm,struct cxl_endpoint_dvsec_info *info);void (*cxl_endpoint_parse_cdat)(struct cxl_port *port); +int (*hmat_get_extended_linear_cache_size)(struct resource *backing_res, +int nid, +resource_size_t *size); };void register_cxl_mock_ops (struct cxl_mock_ops *ops);base-commit:
19272b37aa4f83ca52bdf9c16d5d81bdd1354494Signature · 1 line
2.49.0
Quoted 6 lines · Dave Jiang
It was a mistake to introduce
core/acpi.cand putting ACPI dependency oncxl_corewhen adding the extended linear cache support. Add a callback in thecxl_root_decoderto retrieve the extended linear cache size from ACPI via thecxl_acpidriver.Signed-off-by Dave Jiang <[email protected]>
Applied to cxl/next1a45e1cd694fdf2d2a22e3c70a6917ff39fe77ab
Quoted 306 lines
---
v3:
- Remove commit log paragraph on adding extra dev parameter. (Jonathan)
- Add device ref put. (Jonathan)
- Adjust var declaration. (Jonathan)
- Move callback assignment to same group. (Jonathan)--- drivers/cxl/acpi.c | 13 +++++++++++- drivers/cxl/core/Makefile | 1 - drivers/cxl/core/acpi.c | 11 ---------- drivers/cxl/core/core.h | 2 -- drivers/cxl/core/port.c | 5 ++++- drivers/cxl/core/region.c | 5 ++++- drivers/cxl/cxl.h | 10 ++++++++- tools/testing/cxl/Kbuild | 2 +- tools/testing/cxl/test/cxl.c | 40 +++++++++++++++++++++++++++++++++++ tools/testing/cxl/test/mock.c | 19 +++++++++++++++++ tools/testing/cxl/test/mock.h | 3 +++ 11 files changed, 92 insertions(+), 19 deletions(-) delete mode 100644 drivers/cxl/core/acpi.cdrivers/cxl/acpi.c +12
-1@@ -335,6 +335,17 @@ static int add_or_reset_cxl_resource(struct resource *parent, struct resource *rreturn rc; } +static int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, +int nid, +resource_size_t *size) +{ +return hmat_get_extended_linear_cache_size (backing_res, nid, size); +} + +static const struct cxl_rd_ops acpi_rd_ops = { + .get_extended_linear_cache_size = cxl_acpi_get_extended_linear_cache_size, +}; + DEFINE_FREE(put_cxlrd, struct cxl_root_decoder *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->cxlsd.cxld.dev)) DEFINE_FREE(del_cxl_resource, struct resource *, if (_T) del_cxl_resource(_T))@@ -373,7 +384,7 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws,return rc; struct cxl_root_decoder *cxlrd __free(put_cxlrd) = -cxl_root_decoder_alloc (root_port, ways); +cxl_root_decoder_alloc (root_port, ways, &acpi_rd_ops);if (IS_ERR (cxlrd))return PTR_ERR (cxlrd);drivers/cxl/core/Makefile +0
-1@@ -15,7 +15,6 @@ cxl_core-y += hdm.o cxl_core-y += pmu.o cxl_core-y += cdat.o cxl_core-y += ras.o -cxl_core-y += acpi.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o cxl_core-$(CONFIG_CXL_MCE) += mce.odrivers/cxl/core/acpi.c deleted +0
-11@@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* Copyright(c) 2024 Intel Corporation. All rights reserved. */ -#include <linux/acpi.h> -#include "cxl.h" -#include "core.h" - -int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, -int nid,resource_size_t *size) -{ -return hmat_get_extended_linear_cache_size (backing_res, nid, size); -}drivers/cxl/core/core.h +0
-2@@ -120,8 +120,6 @@ int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,int cxl_ras_init (void );void cxl_ras_exit (void );int cxl_gpf_port_setup (struct cxl_dport *dport); -int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, -int nid,resource_size_t *size);#ifdef CONFIG_CXL_FEATURES struct cxl_feat_entry *drivers/cxl/core/port.c +4
-1@@ -1793,6 +1793,7 @@ static int cxl_switch_decoder_init(struct cxl_port *port,* cxl_root_decoder_alloc - Allocate a root level decoder * @port: owning CXL root of this decoder * @nr_targets: static number of downstream targets +* @ops: root decoder callback operations * * Return: A new cxl decoder to be registered by cxl_decoder_add(). A * 'CXL root' decoder is one that decodes from a top-level / static platform @@ -1800,7 +1801,8 @@ static int cxl_switch_decoder_init(struct cxl_port *port,* topology. */ struct cxl_root_decoder *cxl_root_decoder_alloc (struct cxl_port *port, -unsigned int nr_targets) +unsigned int nr_targets, +const struct cxl_rd_ops *ops) {struct cxl_root_decoder *cxlrd;struct cxl_switch_decoder *cxlsd;@@ -1839,6 +1841,7 @@ struct cxl_root_decoder *cxl_root_decoder_alloc(struct cxl_port *port,atomic_set (&cxlrd->region_id, rc); cxlrd->qos_class =CXL_QOS_CLASS_INVALID ; + cxlrd->ops = ops;return cxlrd; }EXPORT_SYMBOL_NS_GPL (cxl_root_decoder_alloc,"CXL" );drivers/cxl/core/region.c +4
-1@@ -3287,7 +3287,10 @@ static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr,resource_size_t cache_size, start;int rc; - rc =cxl_acpi_get_extended_linear_cache_size (res, nid, &cache_size); +if (!cxlrd->ops || !cxlrd->ops->get_extended_linear_cache_size) +return -EOPNOTSUPP ; + + rc = cxlrd->ops->get_extended_linear_cache_size (res, nid, &cache_size);if (rc)return rc;drivers/cxl/cxl.h +9
-1@@ -420,6 +420,11 @@ struct cxl_switch_decoder {struct cxl_root_decoder ;typedef u64 (*cxl_hpa_to_spa_fn )(struct cxl_root_decoder *cxlrd,u64 hpa); +struct cxl_rd_ops { +int (*get_extended_linear_cache_size)(struct resource *backing_res, +int nid,resource_size_t *size); +}; +/** * struct cxl_root_decoder - Static platform CXL address decoder * @res: host / parent resource for region allocations @@ -428,6 +433,7 @@ typedef u64 (*cxl_hpa_to_spa_fn)(struct cxl_root_decoder *cxlrd, u64 hpa);* @platform_data: platform specific configuration data * @range_lock: sync region autodiscovery by address range * @qos_class: QoS performance class cookie +* @ops: root decoder specific operations * @cxlsd: base cxl switch decoder */ struct cxl_root_decoder {@@ -437,6 +443,7 @@ struct cxl_root_decoder {void *platform_data;struct mutex range_lock;int qos_class; +const struct cxl_rd_ops *ops;struct cxl_switch_decoder cxlsd; };@@ -775,7 +782,8 @@ bool is_root_decoder(struct device *dev);bool is_switch_decoder (struct device *dev);bool is_endpoint_decoder (struct device *dev);struct cxl_root_decoder *cxl_root_decoder_alloc (struct cxl_port *port, -unsigned int nr_targets); +unsigned int nr_targets, +const struct cxl_rd_ops *ops);struct cxl_switch_decoder *cxl_switch_decoder_alloc (struct cxl_port *port,unsigned int nr_targets);int cxl_decoder_add (struct cxl_decoder *cxld,int *target_map);tools/testing/cxl/Kbuild +1
-1@@ -15,6 +15,7 @@ ldflags-y += --wrap=devm_cxl_add_rch_dport ldflags-y += --wrap=cxl_rcd_component_reg_phys ldflags-y += --wrap=cxl_endpoint_parse_cdat ldflags-y += --wrap=cxl_dport_init_ras_reporting +ldflags-y += --wrap=hmat_get_extended_linear_cache_size DRIVERS := ../../../drivers CXL_SRC := $(DRIVERS)/cxl@@ -62,7 +63,6 @@ cxl_core-y += $(CXL_CORE_SRC)/hdm.o cxl_core-y += $(CXL_CORE_SRC)/pmu.o cxl_core-y += $(CXL_CORE_SRC)/cdat.o cxl_core-y += $(CXL_CORE_SRC)/ras.o -cxl_core-y += $(CXL_CORE_SRC)/acpi.o cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.otools/testing/cxl/test/cxl.c +40
-0@@ -470,6 +470,44 @@ struct cxl_cedt_context {struct device *dev; }; +static int match_root_decoder_by_range (struct device *dev,const void *data) +{ +struct cxl_root_decoder *cxlrd; +const struct range *r2 = data; +const struct range *r1; + +if (!is_root_decoder (dev)) +return 0 ; + + cxlrd =to_cxl_root_decoder (dev); + r1 = &cxlrd->cxlsd.cxld.hpa_range; +return range_contains (r1, r2); +} + +static int mock_hmat_get_extended_linear_cache_size (struct resource *backing_res, +int nid,resource_size_t *size) +{ +struct range backing_range = { + .start = backing_res->start, + .end = backing_res->end, + }; +struct cxl_decoder *cxld; +struct cxl_port *port; + + struct device *dev __free(put_device) = +bus_find_device (&cxl_bus_type,NULL , &backing_range, + match_root_decoder_by_range); +if (!dev) +return -ENODEV ; + + cxld =to_cxl_decoder (dev); + port =to_cxl_port (cxld->dev.parent); +if (is_mock_dev (port->uport_dev)) +return -EOPNOTSUPP ; + +return hmat_get_extended_linear_cache_size (backing_res, nid, size); +} +static int mock_acpi_table_parse_cedt (enum acpi_cedt_type id,acpi_tbl_entry_handler_arg handler_arg,void *arg)@@ -1039,6 +1077,8 @@ static struct cxl_mock_ops cxl_mock_ops = { .devm_cxl_add_passthrough_decoder = mock_cxl_add_passthrough_decoder, .devm_cxl_enumerate_decoders = mock_cxl_enumerate_decoders, .cxl_endpoint_parse_cdat = mock_cxl_endpoint_parse_cdat, + .hmat_get_extended_linear_cache_size = + mock_hmat_get_extended_linear_cache_size, .list = LIST_HEAD_INIT(cxl_mock_ops.list), };tools/testing/cxl/test/mock.c +19
-0@@ -78,6 +78,25 @@ int __wrap_acpi_table_parse_cedt(enum acpi_cedt_type id, }EXPORT_SYMBOL_NS_GPL (__wrap_acpi_table_parse_cedt,"ACPI" ); +int __wrap_hmat_get_extended_linear_cache_size (struct resource *res, +int nid, +resource_size_t *size) +{ +int index; +struct cxl_mock_ops *ops =get_cxl_mock_ops (&index); +int rc; + +if (ops) + rc = ops->hmat_get_extended_linear_cache_size (res, nid, size); +else + rc =hmat_get_extended_linear_cache_size (res, nid, size); + +put_cxl_mock_ops (index); + +return rc; +} +EXPORT_SYMBOL_NS_GPL (__wrap_hmat_get_extended_linear_cache_size,"CXL" ); + acpi_status __wrap_acpi_evaluate_integer(acpi_handle handle, acpi_string pathname, struct acpi_object_list *arguments,tools/testing/cxl/test/mock.h +3
-0@@ -26,6 +26,9 @@ struct cxl_mock_ops {int (*devm_cxl_enumerate_decoders)(struct cxl_hdm *hdm,struct cxl_endpoint_dvsec_info *info);void (*cxl_endpoint_parse_cdat)(struct cxl_port *port); +int (*hmat_get_extended_linear_cache_size)(struct resource *backing_res, +int nid, +resource_size_t *size); };void register_cxl_mock_ops (struct cxl_mock_ops *ops);base-commit:
19272b37aa4f83ca52bdf9c16d5d81bdd1354494
PATCH 1/1 cxl: Remove core/acpi.c and cxl core dependency on ACPI
Hi Dave,
Quoted 8 lines · Dave Jiang
Quoted 5 lines · Dave Jiang
It was a mistake to introduce
core/acpi.cand putting ACPI dependency oncxl_corewhen adding the extended linear cache support. Add a callback in thecxl_root_decoderto retrieve the extended linear cache size from ACPI via thecxl_acpidriver.
Quoted 4 lines
Quoted 1 line
Signed-off-by Dave Jiang <[email protected]>Applied to cxl/next
1a45e1cd694fdf2d2a22e3c70a6917ff39fe77ab
I am sorry to come back to this patch that late in the process. While rebasing my current region rework and address translation patches I came across your patch and realized that I have a much more simpler rework of that in my patch queue. I extracted that patch below from my series I am working on. Could you take a look at it? The changes are less intrusive and part of my rework required for address translation. If it looks good to you and during review, I rather prefer to replace your patch with this one. Note that I have follow on patches that reduce more code and remove the cxl_extended_linear_cache_resize() function entirely.
Patch below bases on:
ac0fe6a57317 cxl: make cxl_bus_type constant
Many thanks,
-Robert
From fd3f1f5b33313bb10a2e51861031015ac48a8cd1 Mon Sep 17 00:00:00 2001
From: Robert Richter <[email protected]>
Date: Fri, 11 Jul 2025 11:56:56 +0200
Subject: [PATCH] cxl: Remove core/acpi.c and cxl core dependency on ACPI
From Dave [1]:
"""
It was a mistake to introduce core/acpi.c and putting ACPI dependency on cxl_core when adding the extended linear cache support.
"""
Current implementation calls hmat_get_extended_linear_cache_size() of the ACPI subsystem. That external reference causes issue running cxl_test as there is no way to "mock" that function and ignore it when using cxl test.
Instead of working around that using cxlrd ops and extensively expanding cxl_test code [1], just move HMAT calls out of the core module to cxl_acpi. Implement this by adding a @cache_size member to struct cxl_root_decoder. During initialization the cache size is determined and added to the root decoder object in cxl_acpi. Later on in cxl_core the cache_size parameter is used to setup extended linear caching.
[1] https://patch.msgid.link/[email protected]
--- drivers/cxl/acpi.c | 59 +++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/Makefile | 1 - drivers/cxl/core/acpi.c | 11 -------- drivers/cxl/core/core.h | 2 -- drivers/cxl/core/region.c | 7 +---- drivers/cxl/cxl.h | 1 + 6 files changed, 61 insertions(+), 20 deletions(-) delete mode 100644 drivers/cxl/core/acpi.c
drivers/cxl/acpi.c +59 -0
@@ -335,6 +335,63 @@ static int add_or_reset_cxl_resource(struct resource *parent, struct resource *rreturn rc; } +static int cxl_acpi_set_cache_size (struct cxl_root_decoder *cxlrd) +{ +struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld; +struct range *hpa = &cxld->hpa_range; +resource_size_t size =range_len (hpa); +resource_size_t start = hpa->start; +resource_size_t cache_size; +struct resource res; +int nid, rc; + + res =DEFINE_RES (start, size,0 ); + nid =phys_to_target_node (start); + + rc =hmat_get_extended_linear_cache_size (&res, nid, &cache_size); +if (rc) +return rc; + +/* +* The cache range is expected to be within the CFMWS. +* Currently there is only support cache_size == cxl_size. CXL +* size is then half of the total CFMWS window size. +*/ + size = size >>1 ; +if (cache_size && size != cache_size) { +dev_warn (&cxld->dev, +"Extended Linear Cache size %pa != CXL size %pa. No Support!" , + &cache_size, &size); +return -ENXIO ; + } + + cxlrd->cache_size = cache_size; + +return 0 ; +} + +static void cxl_setup_extended_linear_cache (struct cxl_root_decoder *cxlrd) +{ +int rc; + + rc =cxl_acpi_set_cache_size (cxlrd); +if (!rc) +return ; + +if (rc != -EOPNOTSUPP ) { +/* +* Failing to support extended linear cache region resize does not +* prevent the region from functioning. Only causes cxl list showing +* incorrect region size. +*/ +dev_warn (cxlrd->cxlsd.cxld.dev.parent, +"Extended linear cache calculation failed rc:%d\n" , rc); + } + +/* Ignoring return code */ + cxlrd->cache_size =0 ; +} + DEFINE_FREE(put_cxlrd, struct cxl_root_decoder *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->cxlsd.cxld.dev)) DEFINE_FREE(del_cxl_resource, struct resource *, if (_T) del_cxl_resource(_T))
@@ -394,6 +451,8 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws, ig =CXL_DECODER_MIN_GRANULARITY ; cxld->interleave_granularity = ig; +cxl_setup_extended_linear_cache (cxlrd); +if (cfmws->interleave_arithmetic ==ACPI_CEDT_CFMWS_ARITHMETIC_XOR ) {if (ways !=1 && ways !=3 ) { cxims_ctx = (struct cxl_cxims_context) {
drivers/cxl/core/Makefile +0 -1
@@ -15,7 +15,6 @@ cxl_core-y += hdm.o cxl_core-y += pmu.o cxl_core-y += cdat.o cxl_core-y += ras.o -cxl_core-y += acpi.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o cxl_core-$(CONFIG_CXL_MCE) += mce.o
drivers/cxl/core/acpi.c deleted +0 -11
@@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* Copyright(c) 2024 Intel Corporation. All rights reserved. */ -#include <linux/acpi.h> -#include "cxl.h" -#include "core.h" - -int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, -int nid,resource_size_t *size) -{ -return hmat_get_extended_linear_cache_size (backing_res, nid, size); -}
drivers/cxl/core/core.h +0 -2
@@ -120,8 +120,6 @@ int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,int cxl_ras_init (void );void cxl_ras_exit (void );int cxl_gpf_port_setup (struct cxl_dport *dport); -int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, -int nid,resource_size_t *size);#ifdef CONFIG_CXL_FEATURES struct cxl_feat_entry *
drivers/cxl/core/region.c +1 -6
@@ -3282,15 +3282,10 @@ static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr, {struct cxl_root_decoder *cxlrd =to_cxl_root_decoder (cxlr->dev.parent);struct cxl_region_params *p = &cxlr->params; -int nid =phys_to_target_node (res->start);resource_size_t size =resource_size (res);resource_size_t cache_size, start; -int rc; - - rc =cxl_acpi_get_extended_linear_cache_size (res, nid, &cache_size); -if (rc) -return rc; + cache_size = cxlrd->cache_size;if (!cache_size)return 0 ;
drivers/cxl/cxl.h +1 -0
@@ -432,6 +432,7 @@ typedef u64 (*cxl_hpa_to_spa_fn)(struct cxl_root_decoder *cxlrd, u64 hpa);*/ struct cxl_root_decoder {struct resource *res; +resource_size_t cache_size;atomic_t region_id;cxl_hpa_to_spa_fn hpa_to_spa;void *platform_data;
Signature · 1 line
2.39.5
Dave Jiang
maintainerQuoted 27 lines · Robert Richter
Hi Dave,
Quoted 8 lines · Dave Jiang
Quoted 5 lines · Dave Jiang
It was a mistake to introduce
core/acpi.cand putting ACPI dependency oncxl_corewhen adding the extended linear cache support. Add a callback in thecxl_root_decoderto retrieve the extended linear cache size from ACPI via thecxl_acpidriver.Quoted 4 lines
Quoted 1 line
Signed-off-by Dave Jiang <[email protected]>Applied to cxl/next
1a45e1cd694fdf2d2a22e3c70a6917ff39fe77abI am sorry to come back to this patch that late in the process. While rebasing my current region rework and address translation patches I came across your patch and realized that I have a much more simpler rework of that in my patch queue. I extracted that patch below from my series I am working on. Could you take a look at it? The changes are less intrusive and part of my rework required for address translation. If it looks good to you and during review, I rather prefer to replace your patch with this one. Note that I have follow on patches that reduce more code and remove the
cxl_extended_linear_cache_resize()function entirely.
Quoted 3 lines
Patch below bases on:
ac0fe6a57317cxl: makecxl_bus_typeconstant
Hi Robert. I do like the simplicity of this. So lets go with that. Can you please post your patch directly to the mailing list as a stand alone? I'll drop my patch from cxl/next. We still should refactor the hpa_to_spa callback function into the cxl_rd_ops struct though. But that is a much smaller change.
DJ
Quoted 199 lines
Many thanks,
-Robert
From
fd3f1f5b33313bb10a2e51861031015ac48a8cd1Mon Sep 17 00:00:00 2001
From: Robert Richter <[email protected]>
Date: Fri, 11 Jul 2025 11:56:56 +0200
Subject: [PATCH] cxl: Removecore/acpi.cand cxl core dependency on ACPIFrom Dave [1]:
"""
It was a mistake to introducecore/acpi.cand putting ACPI dependency oncxl_corewhen adding the extended linear cache support.
"""Current implementation calls
hmat_get_extended_linear_cache_size()of the ACPI subsystem. That external reference causes issue runningcxl_testas there is no way to "mock" that function and ignore it when using cxl test.Instead of working around that using cxlrd ops and extensively expanding
cxl_testcode [1], just move HMAT calls out of the core module tocxl_acpi. Implement this by adding a @cache_size member to structcxl_root_decoder. During initialization the cache size is determined and added to the root decoder object incxl_acpi. Later on incxl_corethecache_sizeparameter is used to setup extended linear caching.[1] https://patch.msgid.link/[email protected]
Cc Dave Jiang <[email protected]>Signed-off-by Robert Richter <[email protected]>--- drivers/cxl/acpi.c | 59 +++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/Makefile | 1 - drivers/cxl/core/acpi.c | 11 -------- drivers/cxl/core/core.h | 2 -- drivers/cxl/core/region.c | 7 +---- drivers/cxl/cxl.h | 1 + 6 files changed, 61 insertions(+), 20 deletions(-) delete mode 100644 drivers/cxl/core/acpi.cdrivers/cxl/acpi.c +59
-0@@ -335,6 +335,63 @@ static int add_or_reset_cxl_resource(struct resource *parent, struct resource *rreturn rc; } +static int cxl_acpi_set_cache_size (struct cxl_root_decoder *cxlrd) +{ +struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld; +struct range *hpa = &cxld->hpa_range; +resource_size_t size =range_len (hpa); +resource_size_t start = hpa->start; +resource_size_t cache_size; +struct resource res; +int nid, rc; + + res =DEFINE_RES (start, size,0 ); + nid =phys_to_target_node (start); + + rc =hmat_get_extended_linear_cache_size (&res, nid, &cache_size); +if (rc) +return rc; + +/* +* The cache range is expected to be within the CFMWS. +* Currently there is only support cache_size == cxl_size. CXL +* size is then half of the total CFMWS window size. +*/ + size = size >>1 ; +if (cache_size && size != cache_size) { +dev_warn (&cxld->dev, +"Extended Linear Cache size %pa != CXL size %pa. No Support!" , + &cache_size, &size); +return -ENXIO ; + } + + cxlrd->cache_size = cache_size; + +return 0 ; +} + +static void cxl_setup_extended_linear_cache (struct cxl_root_decoder *cxlrd) +{ +int rc; + + rc =cxl_acpi_set_cache_size (cxlrd); +if (!rc) +return ; + +if (rc != -EOPNOTSUPP ) { +/* +* Failing to support extended linear cache region resize does not +* prevent the region from functioning. Only causes cxl list showing +* incorrect region size. +*/ +dev_warn (cxlrd->cxlsd.cxld.dev.parent, +"Extended linear cache calculation failed rc:%d\n" , rc); + } + +/* Ignoring return code */ + cxlrd->cache_size =0 ; +} + DEFINE_FREE(put_cxlrd, struct cxl_root_decoder *, if (!IS_ERR_OR_NULL(_T)) put_device(&_T->cxlsd.cxld.dev)) DEFINE_FREE(del_cxl_resource, struct resource *, if (_T) del_cxl_resource(_T))@@ -394,6 +451,8 @@ static int __cxl_parse_cfmws(struct acpi_cedt_cfmws *cfmws, ig =CXL_DECODER_MIN_GRANULARITY ; cxld->interleave_granularity = ig; +cxl_setup_extended_linear_cache (cxlrd); +if (cfmws->interleave_arithmetic ==ACPI_CEDT_CFMWS_ARITHMETIC_XOR ) {if (ways !=1 && ways !=3 ) { cxims_ctx = (struct cxl_cxims_context) {drivers/cxl/core/Makefile +0
-1@@ -15,7 +15,6 @@ cxl_core-y += hdm.o cxl_core-y += pmu.o cxl_core-y += cdat.o cxl_core-y += ras.o -cxl_core-y += acpi.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o cxl_core-$(CONFIG_CXL_MCE) += mce.odrivers/cxl/core/acpi.c deleted +0
-11@@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* Copyright(c) 2024 Intel Corporation. All rights reserved. */ -#include <linux/acpi.h> -#include "cxl.h" -#include "core.h" - -int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, -int nid,resource_size_t *size) -{ -return hmat_get_extended_linear_cache_size (backing_res, nid, size); -}drivers/cxl/core/core.h +0
-2@@ -120,8 +120,6 @@ int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,int cxl_ras_init (void );void cxl_ras_exit (void );int cxl_gpf_port_setup (struct cxl_dport *dport); -int cxl_acpi_get_extended_linear_cache_size (struct resource *backing_res, -int nid,resource_size_t *size);#ifdef CONFIG_CXL_FEATURES struct cxl_feat_entry *drivers/cxl/core/region.c +1
-6@@ -3282,15 +3282,10 @@ static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr, {struct cxl_root_decoder *cxlrd =to_cxl_root_decoder (cxlr->dev.parent);struct cxl_region_params *p = &cxlr->params; -int nid =phys_to_target_node (res->start);resource_size_t size =resource_size (res);resource_size_t cache_size, start; -int rc; - - rc =cxl_acpi_get_extended_linear_cache_size (res, nid, &cache_size); -if (rc) -return rc; + cache_size = cxlrd->cache_size;if (!cache_size)return 0 ;drivers/cxl/cxl.h +1
-0@@ -432,6 +432,7 @@ typedef u64 (*cxl_hpa_to_spa_fn)(struct cxl_root_decoder *cxlrd, u64 hpa);*/ struct cxl_root_decoder {struct resource *res; +resource_size_t cache_size;atomic_t region_id;cxl_hpa_to_spa_fn hpa_to_spa;void *platform_data;
Quoted 4 lines · Dave Jiang
Quoted 2 lines · Robert Richter
Patch below bases on:
Quoted 8 lines
Quoted 1 line
ac0fe6a57317cxl: makecxl_bus_typeconstantHi Robert. I do like the simplicity of this. So lets go with that. Can you please post your patch directly to the mailing list as a stand alone? I'll drop my patch from cxl/next. We still should refactor the
hpa_to_spacallback function into thecxl_rd_opsstruct though. But that is a much smaller change.
Just sent it, thanks for the quick reply.
-Robert