Skip to content

Commit 12b3d69

Browse files
Robert Richterdavejiang
authored andcommitted
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] [ dj: Remove core/acpi.o from tools/testing/cxl/Kbuild ] [ dj: Add kdoc for cxlrd->cache_size ] Cc: Dave Jiang <[email protected]> Signed-off-by: Robert Richter <[email protected]> Reviewed-by: Alison Schofield <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Dave Jiang <[email protected]>
1 parent bdf2d9f commit 12b3d69

File tree

7 files changed

+62
-21
lines changed

7 files changed

+62
-21
lines changed

drivers/cxl/acpi.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,63 @@ static int add_or_reset_cxl_resource(struct resource *parent, struct resource *r
335335
return rc;
336336
}
337337

338+
static int cxl_acpi_set_cache_size(struct cxl_root_decoder *cxlrd)
339+
{
340+
struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld;
341+
struct range *hpa = &cxld->hpa_range;
342+
resource_size_t size = range_len(hpa);
343+
resource_size_t start = hpa->start;
344+
resource_size_t cache_size;
345+
struct resource res;
346+
int nid, rc;
347+
348+
res = DEFINE_RES(start, size, 0);
349+
nid = phys_to_target_node(start);
350+
351+
rc = hmat_get_extended_linear_cache_size(&res, nid, &cache_size);
352+
if (rc)
353+
return rc;
354+
355+
/*
356+
* The cache range is expected to be within the CFMWS.
357+
* Currently there is only support cache_size == cxl_size. CXL
358+
* size is then half of the total CFMWS window size.
359+
*/
360+
size = size >> 1;
361+
if (cache_size && size != cache_size) {
362+
dev_warn(&cxld->dev,
363+
"Extended Linear Cache size %pa != CXL size %pa. No Support!",
364+
&cache_size, &size);
365+
return -ENXIO;
366+
}
367+
368+
cxlrd->cache_size = cache_size;
369+
370+
return 0;
371+
}
372+
373+
static void cxl_setup_extended_linear_cache(struct cxl_root_decoder *cxlrd)
374+
{
375+
int rc;
376+
377+
rc = cxl_acpi_set_cache_size(cxlrd);
378+
if (!rc)
379+
return;
380+
381+
if (rc != -EOPNOTSUPP) {
382+
/*
383+
* Failing to support extended linear cache region resize does not
384+
* prevent the region from functioning. Only causes cxl list showing
385+
* incorrect region size.
386+
*/
387+
dev_warn(cxlrd->cxlsd.cxld.dev.parent,
388+
"Extended linear cache calculation failed rc:%d\n", rc);
389+
}
390+
391+
/* Ignoring return code */
392+
cxlrd->cache_size = 0;
393+
}
394+
338395
DEFINE_FREE(put_cxlrd, struct cxl_root_decoder *,
339396
if (!IS_ERR_OR_NULL(_T)) put_device(&_T->cxlsd.cxld.dev))
340397
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,
394451
ig = CXL_DECODER_MIN_GRANULARITY;
395452
cxld->interleave_granularity = ig;
396453

454+
cxl_setup_extended_linear_cache(cxlrd);
455+
397456
if (cfmws->interleave_arithmetic == ACPI_CEDT_CFMWS_ARITHMETIC_XOR) {
398457
if (ways != 1 && ways != 3) {
399458
cxims_ctx = (struct cxl_cxims_context) {

drivers/cxl/core/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ cxl_core-y += hdm.o
1515
cxl_core-y += pmu.o
1616
cxl_core-y += cdat.o
1717
cxl_core-y += ras.o
18-
cxl_core-y += acpi.o
1918
cxl_core-$(CONFIG_TRACING) += trace.o
2019
cxl_core-$(CONFIG_CXL_REGION) += region.o
2120
cxl_core-$(CONFIG_CXL_MCE) += mce.o

drivers/cxl/core/acpi.c

Lines changed: 0 additions & 11 deletions
This file was deleted.

drivers/cxl/core/core.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,
121121
int cxl_ras_init(void);
122122
void cxl_ras_exit(void);
123123
int cxl_gpf_port_setup(struct cxl_dport *dport);
124-
int cxl_acpi_get_extended_linear_cache_size(struct resource *backing_res,
125-
int nid, resource_size_t *size);
126124

127125
#ifdef CONFIG_CXL_FEATURES
128126
struct cxl_feat_entry *

drivers/cxl/core/region.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,15 +3282,10 @@ static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr,
32823282
{
32833283
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
32843284
struct cxl_region_params *p = &cxlr->params;
3285-
int nid = phys_to_target_node(res->start);
32863285
resource_size_t size = resource_size(res);
32873286
resource_size_t cache_size, start;
3288-
int rc;
3289-
3290-
rc = cxl_acpi_get_extended_linear_cache_size(res, nid, &cache_size);
3291-
if (rc)
3292-
return rc;
32933287

3288+
cache_size = cxlrd->cache_size;
32943289
if (!cache_size)
32953290
return 0;
32963291

drivers/cxl/cxl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ typedef u64 (*cxl_hpa_to_spa_fn)(struct cxl_root_decoder *cxlrd, u64 hpa);
423423
/**
424424
* struct cxl_root_decoder - Static platform CXL address decoder
425425
* @res: host / parent resource for region allocations
426+
* @cache_size: extended linear cache size if exists, otherwise zero.
426427
* @region_id: region id for next region provisioning event
427428
* @hpa_to_spa: translate CXL host-physical-address to Platform system-physical-address
428429
* @platform_data: platform specific configuration data
@@ -432,6 +433,7 @@ typedef u64 (*cxl_hpa_to_spa_fn)(struct cxl_root_decoder *cxlrd, u64 hpa);
432433
*/
433434
struct cxl_root_decoder {
434435
struct resource *res;
436+
resource_size_t cache_size;
435437
atomic_t region_id;
436438
cxl_hpa_to_spa_fn hpa_to_spa;
437439
void *platform_data;

tools/testing/cxl/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ cxl_core-y += $(CXL_CORE_SRC)/hdm.o
6262
cxl_core-y += $(CXL_CORE_SRC)/pmu.o
6363
cxl_core-y += $(CXL_CORE_SRC)/cdat.o
6464
cxl_core-y += $(CXL_CORE_SRC)/ras.o
65-
cxl_core-y += $(CXL_CORE_SRC)/acpi.o
6665
cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o
6766
cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o
6867
cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.o

0 commit comments

Comments
 (0)