Skip to content

Commit 2d03e46

Browse files
committed
ACPI: Add a context argument for table parsing handlers
In preparation for drivers reusing the core table parsing infrastructure, arrange for handlers to take a context argument. This allows driver table parsing to wrap ACPI table entries in driver-specific data. The first consumer of this infrastructure is the CEDT parsing that happens in the cxl_acpi driver, add a conditional (CONFIG_ACPI_TABLE_LIB=y) export of a acpi_table_parse_cedt() helper for this case. Cc: "Rafael J. Wysocki" <[email protected]> Cc: Len Brown <[email protected]> Tested-by: Alison Schofield <[email protected]> Reviewed-by: Alison Schofield <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Link: https://lore.kernel.org/r/163553710257.2509508.14310494417463866020.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent ad2f639 commit 2d03e46

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

drivers/acpi/tables.c

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,22 @@ acpi_get_subtable_type(char *id)
277277
return ACPI_SUBTABLE_COMMON;
278278
}
279279

280+
static __init_or_acpilib bool has_handler(struct acpi_subtable_proc *proc)
281+
{
282+
return proc->handler || proc->handler_arg;
283+
}
284+
285+
static __init_or_acpilib int call_handler(struct acpi_subtable_proc *proc,
286+
union acpi_subtable_headers *hdr,
287+
unsigned long end)
288+
{
289+
if (proc->handler)
290+
return proc->handler(hdr, end);
291+
if (proc->handler_arg)
292+
return proc->handler_arg(hdr, proc->arg, end);
293+
return -EINVAL;
294+
}
295+
280296
/**
281297
* acpi_parse_entries_array - for each proc_num find a suitable subtable
282298
*
@@ -327,8 +343,9 @@ static int __init_or_acpilib acpi_parse_entries_array(
327343
for (i = 0; i < proc_num; i++) {
328344
if (acpi_get_entry_type(&entry) != proc[i].id)
329345
continue;
330-
if (!proc[i].handler ||
331-
(!errs && proc[i].handler(entry.hdr, table_end))) {
346+
if (!has_handler(&proc[i]) ||
347+
(!errs &&
348+
call_handler(&proc[i], entry.hdr, table_end))) {
332349
errs++;
333350
continue;
334351
}
@@ -394,21 +411,41 @@ int __init_or_acpilib acpi_table_parse_entries_array(
394411
return count;
395412
}
396413

397-
int __init acpi_table_parse_entries(char *id,
398-
unsigned long table_size,
399-
int entry_id,
400-
acpi_tbl_entry_handler handler,
401-
unsigned int max_entries)
414+
static int __init_or_acpilib __acpi_table_parse_entries(
415+
char *id, unsigned long table_size, int entry_id,
416+
acpi_tbl_entry_handler handler, acpi_tbl_entry_handler_arg handler_arg,
417+
void *arg, unsigned int max_entries)
402418
{
403419
struct acpi_subtable_proc proc = {
404420
.id = entry_id,
405421
.handler = handler,
422+
.handler_arg = handler_arg,
423+
.arg = arg,
406424
};
407425

408426
return acpi_table_parse_entries_array(id, table_size, &proc, 1,
409427
max_entries);
410428
}
411429

430+
int __init_or_acpilib
431+
acpi_table_parse_cedt(enum acpi_cedt_type id,
432+
acpi_tbl_entry_handler_arg handler_arg, void *arg)
433+
{
434+
return __acpi_table_parse_entries(ACPI_SIG_CEDT,
435+
sizeof(struct acpi_table_cedt), id,
436+
NULL, handler_arg, arg, 0);
437+
}
438+
EXPORT_SYMBOL_ACPI_LIB(acpi_table_parse_cedt);
439+
440+
int __init acpi_table_parse_entries(char *id, unsigned long table_size,
441+
int entry_id,
442+
acpi_tbl_entry_handler handler,
443+
unsigned int max_entries)
444+
{
445+
return __acpi_table_parse_entries(id, table_size, entry_id, handler,
446+
NULL, NULL, max_entries);
447+
}
448+
412449
int __init acpi_table_parse_madt(enum acpi_madt_type id,
413450
acpi_tbl_entry_handler handler, unsigned int max_entries)
414451
{

include/linux/acpi.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ typedef int (*acpi_tbl_table_handler)(struct acpi_table_header *table);
141141
typedef int (*acpi_tbl_entry_handler)(union acpi_subtable_headers *header,
142142
const unsigned long end);
143143

144+
typedef int (*acpi_tbl_entry_handler_arg)(union acpi_subtable_headers *header,
145+
void *arg, const unsigned long end);
146+
144147
/* Debugger support */
145148

146149
struct acpi_debugger_ops {
@@ -217,6 +220,8 @@ static inline int acpi_debugger_notify_command_complete(void)
217220
struct acpi_subtable_proc {
218221
int id;
219222
acpi_tbl_entry_handler handler;
223+
acpi_tbl_entry_handler_arg handler_arg;
224+
void *arg;
220225
int count;
221226
};
222227

@@ -235,9 +240,11 @@ void acpi_table_init_complete (void);
235240
int acpi_table_init (void);
236241

237242
#ifdef CONFIG_ACPI_TABLE_LIB
243+
#define EXPORT_SYMBOL_ACPI_LIB(x) EXPORT_SYMBOL_NS_GPL(x, ACPI)
238244
#define __init_or_acpilib
239245
#define __initdata_or_acpilib
240246
#else
247+
#define EXPORT_SYMBOL_ACPI_LIB(x)
241248
#define __init_or_acpilib __init
242249
#define __initdata_or_acpilib __initdata
243250
#endif
@@ -252,6 +259,10 @@ int __init_or_acpilib acpi_table_parse_entries_array(char *id,
252259
int acpi_table_parse_madt(enum acpi_madt_type id,
253260
acpi_tbl_entry_handler handler,
254261
unsigned int max_entries);
262+
int __init_or_acpilib
263+
acpi_table_parse_cedt(enum acpi_cedt_type id,
264+
acpi_tbl_entry_handler_arg handler_arg, void *arg);
265+
255266
int acpi_parse_mcfg (struct acpi_table_header *header);
256267
void acpi_table_print_madt_entry (struct acpi_subtable_header *madt);
257268

0 commit comments

Comments
 (0)