Skip to content

Commit 9b3fedd

Browse files
lukaszanrafaeljw
authored andcommitted
ACPI / tables: Add acpi_subtable_proc to ACPI table parsers
ACPI subtable parsing needs to be extended to allow two or more handlers to be run in the same ACPI table walk, thus adding acpi_subtable_proc structure which stores () ACPI table id () handler that processes table () counter how many items has been processed and passing it to acpi_parse_entries_array() and acpi_table_parse_entries_array(). This is needed to fix CPU enumeration when APIC/X2APIC entries are interleaved. Signed-off-by: Lukasz Anaczkowski <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Tested-by: Marc Zyngier <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 6ff33f3 commit 9b3fedd

File tree

2 files changed

+91
-21
lines changed

2 files changed

+91
-21
lines changed

drivers/acpi/tables.c

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,39 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
210210
}
211211
}
212212

213-
int __init
214-
acpi_parse_entries(char *id, unsigned long table_size,
215-
acpi_tbl_entry_handler handler,
213+
/**
214+
* acpi_parse_entries_array - for each proc_num find a suitable subtable
215+
*
216+
* @id: table id (for debugging purposes)
217+
* @table_size: single entry size
218+
* @table_header: where does the table start?
219+
* @proc: array of acpi_subtable_proc struct containing entry id
220+
* and associated handler with it
221+
* @proc_num: how big proc is?
222+
* @max_entries: how many entries can we process?
223+
*
224+
* For each proc_num find a subtable with proc->id and run proc->handler
225+
* on it. Assumption is that there's only single handler for particular
226+
* entry id.
227+
*
228+
* On success returns sum of all matching entries for all proc handlers.
229+
* Otherwise, -ENODEV or -EINVAL is returned.
230+
*/
231+
static int __init
232+
acpi_parse_entries_array(char *id, unsigned long table_size,
216233
struct acpi_table_header *table_header,
217-
int entry_id, unsigned int max_entries)
234+
struct acpi_subtable_proc *proc, int proc_num,
235+
unsigned int max_entries)
218236
{
219237
struct acpi_subtable_header *entry;
220-
int count = 0;
221238
unsigned long table_end;
239+
int count = 0;
240+
int i;
222241

223242
if (acpi_disabled)
224243
return -ENODEV;
225244

226-
if (!id || !handler)
245+
if (!id)
227246
return -EINVAL;
228247

229248
if (!table_size)
@@ -243,20 +262,27 @@ acpi_parse_entries(char *id, unsigned long table_size,
243262

244263
while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
245264
table_end) {
246-
if (entry->type == entry_id
247-
&& (!max_entries || count < max_entries)) {
248-
if (handler(entry, table_end))
265+
if (max_entries && count >= max_entries)
266+
break;
267+
268+
for (i = 0; i < proc_num; i++) {
269+
if (entry->type != proc[i].id)
270+
continue;
271+
if (!proc->handler || proc[i].handler(entry, table_end))
249272
return -EINVAL;
250273

251-
count++;
274+
proc->count++;
275+
break;
252276
}
277+
if (i != proc_num)
278+
count++;
253279

254280
/*
255281
* If entry->length is 0, break from this loop to avoid
256282
* infinite loop.
257283
*/
258284
if (entry->length == 0) {
259-
pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
285+
pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, proc->id);
260286
return -EINVAL;
261287
}
262288

@@ -266,17 +292,32 @@ acpi_parse_entries(char *id, unsigned long table_size,
266292

267293
if (max_entries && count > max_entries) {
268294
pr_warn("[%4.4s:0x%02x] ignored %i entries of %i found\n",
269-
id, entry_id, count - max_entries, count);
295+
id, proc->id, count - max_entries, count);
270296
}
271297

272298
return count;
273299
}
274300

275301
int __init
276-
acpi_table_parse_entries(char *id,
302+
acpi_parse_entries(char *id,
303+
unsigned long table_size,
304+
acpi_tbl_entry_handler handler,
305+
struct acpi_table_header *table_header,
306+
int entry_id, unsigned int max_entries)
307+
{
308+
struct acpi_subtable_proc proc = {
309+
.id = entry_id,
310+
.handler = handler,
311+
};
312+
313+
return acpi_parse_entries_array(id, table_size, table_header,
314+
&proc, 1, max_entries);
315+
}
316+
317+
int __init
318+
acpi_table_parse_entries_array(char *id,
277319
unsigned long table_size,
278-
int entry_id,
279-
acpi_tbl_entry_handler handler,
320+
struct acpi_subtable_proc *proc, int proc_num,
280321
unsigned int max_entries)
281322
{
282323
struct acpi_table_header *table_header = NULL;
@@ -287,7 +328,7 @@ acpi_table_parse_entries(char *id,
287328
if (acpi_disabled)
288329
return -ENODEV;
289330

290-
if (!id || !handler)
331+
if (!id)
291332
return -EINVAL;
292333

293334
if (!strncmp(id, ACPI_SIG_MADT, 4))
@@ -299,13 +340,29 @@ acpi_table_parse_entries(char *id,
299340
return -ENODEV;
300341
}
301342

302-
count = acpi_parse_entries(id, table_size, handler, table_header,
303-
entry_id, max_entries);
343+
count = acpi_parse_entries_array(id, table_size, table_header,
344+
proc, proc_num, max_entries);
304345

305346
early_acpi_os_unmap_memory((char *)table_header, tbl_size);
306347
return count;
307348
}
308349

350+
int __init
351+
acpi_table_parse_entries(char *id,
352+
unsigned long table_size,
353+
int entry_id,
354+
acpi_tbl_entry_handler handler,
355+
unsigned int max_entries)
356+
{
357+
struct acpi_subtable_proc proc = {
358+
.id = entry_id,
359+
.handler = handler,
360+
};
361+
362+
return acpi_table_parse_entries_array(id, table_size, &proc, 1,
363+
max_entries);
364+
}
365+
309366
int __init
310367
acpi_table_parse_madt(enum acpi_madt_type id,
311368
acpi_tbl_entry_handler handler, unsigned int max_entries)

include/linux/acpi.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ static inline void acpi_initrd_override(void *data, size_t size)
131131
(!entry) || (unsigned long)entry + sizeof(*entry) > end || \
132132
((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
133133

134+
struct acpi_subtable_proc {
135+
int id;
136+
acpi_tbl_entry_handler handler;
137+
int count;
138+
};
139+
134140
char * __acpi_map_table (unsigned long phys_addr, unsigned long size);
135141
void __acpi_unmap_table(char *map, unsigned long size);
136142
int early_acpi_boot_init(void);
@@ -146,9 +152,16 @@ int __init acpi_parse_entries(char *id, unsigned long table_size,
146152
struct acpi_table_header *table_header,
147153
int entry_id, unsigned int max_entries);
148154
int __init acpi_table_parse_entries(char *id, unsigned long table_size,
149-
int entry_id,
150-
acpi_tbl_entry_handler handler,
151-
unsigned int max_entries);
155+
int entry_id,
156+
acpi_tbl_entry_handler handler,
157+
unsigned int max_entries);
158+
int __init acpi_table_parse_entries(char *id, unsigned long table_size,
159+
int entry_id,
160+
acpi_tbl_entry_handler handler,
161+
unsigned int max_entries);
162+
int __init acpi_table_parse_entries_array(char *id, unsigned long table_size,
163+
struct acpi_subtable_proc *proc, int proc_num,
164+
unsigned int max_entries);
152165
int acpi_table_parse_madt(enum acpi_madt_type id,
153166
acpi_tbl_entry_handler handler,
154167
unsigned int max_entries);

0 commit comments

Comments
 (0)