Skip to content

Commit 814dff9

Browse files
committed
cxl/test: Mock acpi_table_parse_cedt()
Now that cxl_acpi has been converted to use the core ACPI CEDT sub-table parser, update cxl_test to inject CFMWS and CHBS data directly into cxl_acpi's handlers. Cc: Alison Schofield <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Link: https://lore.kernel.org/r/163553711363.2509508.17428994087868269952.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent f4ce1f7 commit 814dff9

File tree

5 files changed

+61
-48
lines changed

5 files changed

+61
-48
lines changed

drivers/cxl/acpi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ static int add_host_bridge_uport(struct device *match, void *arg)
283283
}
284284

285285
struct cxl_chbs_context {
286+
struct device *dev;
286287
unsigned long long uid;
287288
resource_size_t chbcr;
288289
};
@@ -327,6 +328,7 @@ static int add_host_bridge_dport(struct device *match, void *arg)
327328
}
328329

329330
ctx = (struct cxl_chbs_context) {
331+
.dev = host,
330332
.uid = uid,
331333
};
332334
acpi_table_parse_cedt(ACPI_CEDT_TYPE_CHBS, cxl_get_chbcr, &ctx);

tools/testing/cxl/Kbuild

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
2+
ldflags-y += --wrap=acpi_table_parse_cedt
23
ldflags-y += --wrap=is_acpi_device_node
3-
ldflags-y += --wrap=acpi_get_table
4-
ldflags-y += --wrap=acpi_put_table
54
ldflags-y += --wrap=acpi_evaluate_integer
65
ldflags-y += --wrap=acpi_pci_find_root
76
ldflags-y += --wrap=pci_walk_bus

tools/testing/cxl/test/cxl.c

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ static struct {
182182
},
183183
};
184184

185+
struct acpi_cedt_cfmws *mock_cfmws[4] = {
186+
[0] = &mock_cedt.cfmws0.cfmws,
187+
[1] = &mock_cedt.cfmws1.cfmws,
188+
[2] = &mock_cedt.cfmws2.cfmws,
189+
[3] = &mock_cedt.cfmws3.cfmws,
190+
};
191+
185192
struct cxl_mock_res {
186193
struct list_head list;
187194
struct range range;
@@ -232,12 +239,6 @@ static struct cxl_mock_res *alloc_mock_res(resource_size_t size)
232239

233240
static int populate_cedt(void)
234241
{
235-
struct acpi_cedt_cfmws *cfmws[4] = {
236-
[0] = &mock_cedt.cfmws0.cfmws,
237-
[1] = &mock_cedt.cfmws1.cfmws,
238-
[2] = &mock_cedt.cfmws2.cfmws,
239-
[3] = &mock_cedt.cfmws3.cfmws,
240-
};
241242
struct cxl_mock_res *res;
242243
int i;
243244

@@ -257,8 +258,8 @@ static int populate_cedt(void)
257258
chbs->length = size;
258259
}
259260

260-
for (i = 0; i < ARRAY_SIZE(cfmws); i++) {
261-
struct acpi_cedt_cfmws *window = cfmws[i];
261+
for (i = 0; i < ARRAY_SIZE(mock_cfmws); i++) {
262+
struct acpi_cedt_cfmws *window = mock_cfmws[i];
262263

263264
res = alloc_mock_res(window->window_size);
264265
if (!res)
@@ -269,21 +270,44 @@ static int populate_cedt(void)
269270
return 0;
270271
}
271272

272-
static acpi_status mock_acpi_get_table(char *signature, u32 instance,
273-
struct acpi_table_header **out_table)
273+
/*
274+
* WARNING, this hack assumes the format of 'struct
275+
* cxl_cfmws_context' and 'struct cxl_chbs_context' share the property that
276+
* the first struct member is the device being probed by the cxl_acpi
277+
* driver.
278+
*/
279+
struct cxl_cedt_context {
280+
struct device *dev;
281+
};
282+
283+
static int mock_acpi_table_parse_cedt(enum acpi_cedt_type id,
284+
acpi_tbl_entry_handler_arg handler_arg,
285+
void *arg)
274286
{
275-
if (instance < U32_MAX || strcmp(signature, ACPI_SIG_CEDT) != 0)
276-
return acpi_get_table(signature, instance, out_table);
287+
struct cxl_cedt_context *ctx = arg;
288+
struct device *dev = ctx->dev;
289+
union acpi_subtable_headers *h;
290+
unsigned long end;
291+
int i;
277292

278-
*out_table = (struct acpi_table_header *) &mock_cedt;
279-
return AE_OK;
280-
}
293+
if (dev != &cxl_acpi->dev)
294+
return acpi_table_parse_cedt(id, handler_arg, arg);
281295

282-
static void mock_acpi_put_table(struct acpi_table_header *table)
283-
{
284-
if (table == (struct acpi_table_header *) &mock_cedt)
285-
return;
286-
acpi_put_table(table);
296+
if (id == ACPI_CEDT_TYPE_CHBS)
297+
for (i = 0; i < ARRAY_SIZE(mock_cedt.chbs); i++) {
298+
h = (union acpi_subtable_headers *)&mock_cedt.chbs[i];
299+
end = (unsigned long)&mock_cedt.chbs[i + 1];
300+
handler_arg(h, arg, end);
301+
}
302+
303+
if (id == ACPI_CEDT_TYPE_CFMWS)
304+
for (i = 0; i < ARRAY_SIZE(mock_cfmws); i++) {
305+
h = (union acpi_subtable_headers *) mock_cfmws[i];
306+
end = (unsigned long) h + mock_cfmws[i]->header.length;
307+
handler_arg(h, arg, end);
308+
}
309+
310+
return 0;
287311
}
288312

289313
static bool is_mock_bridge(struct device *dev)
@@ -388,8 +412,7 @@ static struct cxl_mock_ops cxl_mock_ops = {
388412
.is_mock_port = is_mock_port,
389413
.is_mock_dev = is_mock_dev,
390414
.mock_port = mock_cxl_root_port,
391-
.acpi_get_table = mock_acpi_get_table,
392-
.acpi_put_table = mock_acpi_put_table,
415+
.acpi_table_parse_cedt = mock_acpi_table_parse_cedt,
393416
.acpi_evaluate_integer = mock_acpi_evaluate_integer,
394417
.acpi_pci_find_root = mock_acpi_pci_find_root,
395418
.list = LIST_HEAD_INIT(cxl_mock_ops.list),
@@ -574,3 +597,4 @@ static __exit void cxl_test_exit(void)
574597
module_init(cxl_test_init);
575598
module_exit(cxl_test_exit);
576599
MODULE_LICENSE("GPL v2");
600+
MODULE_IMPORT_NS(ACPI);

tools/testing/cxl/test/mock.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,23 @@ bool __wrap_is_acpi_device_node(const struct fwnode_handle *fwnode)
5858
}
5959
EXPORT_SYMBOL(__wrap_is_acpi_device_node);
6060

61-
acpi_status __wrap_acpi_get_table(char *signature, u32 instance,
62-
struct acpi_table_header **out_table)
61+
int __wrap_acpi_table_parse_cedt(enum acpi_cedt_type id,
62+
acpi_tbl_entry_handler_arg handler_arg,
63+
void *arg)
6364
{
64-
int index;
65+
int index, rc;
6566
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
66-
acpi_status status;
6767

6868
if (ops)
69-
status = ops->acpi_get_table(signature, instance, out_table);
69+
rc = ops->acpi_table_parse_cedt(id, handler_arg, arg);
7070
else
71-
status = acpi_get_table(signature, instance, out_table);
71+
rc = acpi_table_parse_cedt(id, handler_arg, arg);
7272

7373
put_cxl_mock_ops(index);
7474

75-
return status;
76-
}
77-
EXPORT_SYMBOL(__wrap_acpi_get_table);
78-
79-
void __wrap_acpi_put_table(struct acpi_table_header *table)
80-
{
81-
int index;
82-
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
83-
84-
if (ops)
85-
ops->acpi_put_table(table);
86-
else
87-
acpi_put_table(table);
88-
put_cxl_mock_ops(index);
75+
return rc;
8976
}
90-
EXPORT_SYMBOL(__wrap_acpi_put_table);
77+
EXPORT_SYMBOL_NS_GPL(__wrap_acpi_table_parse_cedt, ACPI);
9178

9279
acpi_status __wrap_acpi_evaluate_integer(acpi_handle handle,
9380
acpi_string pathname,
@@ -169,3 +156,4 @@ __wrap_nvdimm_bus_register(struct device *dev,
169156
EXPORT_SYMBOL_GPL(__wrap_nvdimm_bus_register);
170157

171158
MODULE_LICENSE("GPL v2");
159+
MODULE_IMPORT_NS(ACPI);

tools/testing/cxl/test/mock.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
struct cxl_mock_ops {
77
struct list_head list;
88
bool (*is_mock_adev)(struct acpi_device *dev);
9-
acpi_status (*acpi_get_table)(char *signature, u32 instance,
10-
struct acpi_table_header **out_table);
11-
void (*acpi_put_table)(struct acpi_table_header *table);
9+
int (*acpi_table_parse_cedt)(enum acpi_cedt_type id,
10+
acpi_tbl_entry_handler_arg handler_arg,
11+
void *arg);
1212
bool (*is_mock_bridge)(struct device *dev);
1313
acpi_status (*acpi_evaluate_integer)(acpi_handle handle,
1414
acpi_string pathname,

0 commit comments

Comments
 (0)