Skip to content

Commit c8e008e

Browse files
committed
Merge branches 'acpica' and 'acpi-scan'
* acpica: ACPI / osl: Remove deprecated acpi_get_table_with_size()/early_acpi_os_unmap_memory() ACPI / osl: Remove acpi_get_table_with_size()/early_acpi_os_unmap_memory() users ACPICA: Tables: Allow FADT to be customized with virtual address ACPICA: Tables: Back port acpi_get_table_with_size() and early_acpi_os_unmap_memory() from Linux kernel * acpi-scan: ACPI: do not warn if _BQC does not exist
3 parents 7ae123e + 8d3523f + 7020bcb commit c8e008e

22 files changed

Lines changed: 224 additions & 125 deletions

File tree

‎arch/arm64/include/asm/acpi.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
/* Basic configuration for ACPI */
3131
#ifdef CONFIG_ACPI
32-
/* ACPI table mapping after acpi_gbl_permanent_mmap is set */
32+
/* ACPI table mapping after acpi_permanent_mmap is set */
3333
static inline void __iomem *acpi_os_ioremap(acpi_physical_address phys,
3434
acpi_size size)
3535
{

‎arch/arm64/kernel/acpi.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,13 @@ static int __init acpi_fadt_sanity_check(void)
132132
struct acpi_table_header *table;
133133
struct acpi_table_fadt *fadt;
134134
acpi_status status;
135-
acpi_size tbl_size;
136135
int ret = 0;
137136

138137
/*
139138
* FADT is required on arm64; retrieve it to check its presence
140139
* and carry out revision and ACPI HW reduced compliancy tests
141140
*/
142-
status = acpi_get_table_with_size(ACPI_SIG_FADT, 0, &table, &tbl_size);
141+
status = acpi_get_table(ACPI_SIG_FADT, 0, &table);
143142
if (ACPI_FAILURE(status)) {
144143
const char *msg = acpi_format_exception(status);
145144

@@ -170,10 +169,10 @@ static int __init acpi_fadt_sanity_check(void)
170169

171170
out:
172171
/*
173-
* acpi_get_table_with_size() creates FADT table mapping that
172+
* acpi_get_table() creates FADT table mapping that
174173
* should be released after parsing and before resuming boot
175174
*/
176-
early_acpi_os_unmap_memory(table, tbl_size);
175+
acpi_put_table(table);
177176
return ret;
178177
}
179178

‎drivers/acpi/acpica/actables.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc,
166166

167167
acpi_status acpi_tb_parse_root_table(acpi_physical_address rsdp_address);
168168

169+
acpi_status
170+
acpi_tb_get_table(struct acpi_table_desc *table_desc,
171+
struct acpi_table_header **out_table);
172+
173+
void acpi_tb_put_table(struct acpi_table_desc *table_desc);
174+
169175
/*
170176
* tbxfload
171177
*/

‎drivers/acpi/acpica/tbfadt.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ void acpi_tb_parse_fadt(void)
311311
{
312312
u32 length;
313313
struct acpi_table_header *table;
314+
struct acpi_table_desc *fadt_desc;
315+
acpi_status status;
314316

315317
/*
316318
* The FADT has multiple versions with different lengths,
@@ -319,14 +321,12 @@ void acpi_tb_parse_fadt(void)
319321
* Get a local copy of the FADT and convert it to a common format
320322
* Map entire FADT, assumed to be smaller than one page.
321323
*/
322-
length = acpi_gbl_root_table_list.tables[acpi_gbl_fadt_index].length;
323-
324-
table =
325-
acpi_os_map_memory(acpi_gbl_root_table_list.
326-
tables[acpi_gbl_fadt_index].address, length);
327-
if (!table) {
324+
fadt_desc = &acpi_gbl_root_table_list.tables[acpi_gbl_fadt_index];
325+
status = acpi_tb_get_table(fadt_desc, &table);
326+
if (ACPI_FAILURE(status)) {
328327
return;
329328
}
329+
length = fadt_desc->length;
330330

331331
/*
332332
* Validate the FADT checksum before we copy the table. Ignore
@@ -340,7 +340,7 @@ void acpi_tb_parse_fadt(void)
340340

341341
/* All done with the real FADT, unmap it */
342342

343-
acpi_os_unmap_memory(table, length);
343+
acpi_tb_put_table(fadt_desc);
344344

345345
/* Obtain the DSDT and FACS tables via their addresses within the FADT */
346346

‎drivers/acpi/acpica/tbutils.c‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,88 @@ acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
381381
acpi_os_unmap_memory(table, length);
382382
return_ACPI_STATUS(AE_OK);
383383
}
384+
385+
/*******************************************************************************
386+
*
387+
* FUNCTION: acpi_tb_get_table
388+
*
389+
* PARAMETERS: table_desc - Table descriptor
390+
* out_table - Where the pointer to the table is returned
391+
*
392+
* RETURN: Status and pointer to the requested table
393+
*
394+
* DESCRIPTION: Increase a reference to a table descriptor and return the
395+
* validated table pointer.
396+
* If the table descriptor is an entry of the root table list,
397+
* this API must be invoked with ACPI_MTX_TABLES acquired.
398+
*
399+
******************************************************************************/
400+
401+
acpi_status
402+
acpi_tb_get_table(struct acpi_table_desc *table_desc,
403+
struct acpi_table_header **out_table)
404+
{
405+
acpi_status status;
406+
407+
ACPI_FUNCTION_TRACE(acpi_tb_get_table);
408+
409+
if (table_desc->validation_count == 0) {
410+
411+
/* Table need to be "VALIDATED" */
412+
413+
status = acpi_tb_validate_table(table_desc);
414+
if (ACPI_FAILURE(status)) {
415+
return_ACPI_STATUS(status);
416+
}
417+
}
418+
419+
table_desc->validation_count++;
420+
if (table_desc->validation_count == 0) {
421+
ACPI_ERROR((AE_INFO,
422+
"Table %p, Validation count is zero after increment\n",
423+
table_desc));
424+
table_desc->validation_count--;
425+
return_ACPI_STATUS(AE_LIMIT);
426+
}
427+
428+
*out_table = table_desc->pointer;
429+
return_ACPI_STATUS(AE_OK);
430+
}
431+
432+
/*******************************************************************************
433+
*
434+
* FUNCTION: acpi_tb_put_table
435+
*
436+
* PARAMETERS: table_desc - Table descriptor
437+
*
438+
* RETURN: None
439+
*
440+
* DESCRIPTION: Decrease a reference to a table descriptor and release the
441+
* validated table pointer if no references.
442+
* If the table descriptor is an entry of the root table list,
443+
* this API must be invoked with ACPI_MTX_TABLES acquired.
444+
*
445+
******************************************************************************/
446+
447+
void acpi_tb_put_table(struct acpi_table_desc *table_desc)
448+
{
449+
450+
ACPI_FUNCTION_TRACE(acpi_tb_put_table);
451+
452+
if (table_desc->validation_count == 0) {
453+
ACPI_WARNING((AE_INFO,
454+
"Table %p, Validation count is zero before decrement\n",
455+
table_desc));
456+
return_VOID;
457+
}
458+
table_desc->validation_count--;
459+
460+
if (table_desc->validation_count == 0) {
461+
462+
/* Table need to be "INVALIDATED" */
463+
464+
acpi_tb_invalidate_table(table_desc);
465+
}
466+
467+
return_VOID;
468+
}

‎drivers/acpi/acpica/tbxface.c‎

Lines changed: 82 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ ACPI_EXPORT_SYMBOL(acpi_get_table_header)
282282

283283
/*******************************************************************************
284284
*
285-
* FUNCTION: acpi_get_table_with_size
285+
* FUNCTION: acpi_get_table
286286
*
287287
* PARAMETERS: signature - ACPI signature of needed table
288288
* instance - Which instance (for SSDTs)
@@ -292,74 +292,110 @@ ACPI_EXPORT_SYMBOL(acpi_get_table_header)
292292
*
293293
* DESCRIPTION: Finds and verifies an ACPI table. Table must be in the
294294
* RSDT/XSDT.
295+
* Note that an early stage acpi_get_table() call must be paired
296+
* with an early stage acpi_put_table() call. otherwise the table
297+
* pointer mapped by the early stage mapping implementation may be
298+
* erroneously unmapped by the late stage unmapping implementation
299+
* in an acpi_put_table() invoked during the late stage.
295300
*
296301
******************************************************************************/
297302
acpi_status
298-
acpi_get_table_with_size(char *signature,
299-
u32 instance, struct acpi_table_header **out_table,
300-
acpi_size *tbl_size)
303+
acpi_get_table(char *signature,
304+
u32 instance, struct acpi_table_header ** out_table)
301305
{
302306
u32 i;
303307
u32 j;
304-
acpi_status status;
308+
acpi_status status = AE_NOT_FOUND;
309+
struct acpi_table_desc *table_desc;
305310

306311
/* Parameter validation */
307312

308313
if (!signature || !out_table) {
309314
return (AE_BAD_PARAMETER);
310315
}
311316

317+
/*
318+
* Note that the following line is required by some OSPMs, they only
319+
* check if the returned table is NULL instead of the returned status
320+
* to determined if this function is succeeded.
321+
*/
322+
*out_table = NULL;
323+
324+
(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
325+
312326
/* Walk the root table list */
313327

314328
for (i = 0, j = 0; i < acpi_gbl_root_table_list.current_table_count;
315329
i++) {
316-
if (!ACPI_COMPARE_NAME
317-
(&(acpi_gbl_root_table_list.tables[i].signature),
318-
signature)) {
330+
table_desc = &acpi_gbl_root_table_list.tables[i];
331+
332+
if (!ACPI_COMPARE_NAME(&table_desc->signature, signature)) {
319333
continue;
320334
}
321335

322336
if (++j < instance) {
323337
continue;
324338
}
325339

326-
status =
327-
acpi_tb_validate_table(&acpi_gbl_root_table_list.tables[i]);
328-
if (ACPI_SUCCESS(status)) {
329-
*out_table = acpi_gbl_root_table_list.tables[i].pointer;
330-
*tbl_size = acpi_gbl_root_table_list.tables[i].length;
331-
}
332-
333-
if (!acpi_gbl_permanent_mmap) {
334-
acpi_gbl_root_table_list.tables[i].pointer = NULL;
335-
}
336-
337-
return (status);
340+
status = acpi_tb_get_table(table_desc, out_table);
341+
break;
338342
}
339343

340-
return (AE_NOT_FOUND);
344+
(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
345+
return (status);
341346
}
342347

343-
ACPI_EXPORT_SYMBOL(acpi_get_table_with_size)
348+
ACPI_EXPORT_SYMBOL(acpi_get_table)
344349

345-
acpi_status
346-
acpi_get_table(char *signature,
347-
u32 instance, struct acpi_table_header **out_table)
350+
/*******************************************************************************
351+
*
352+
* FUNCTION: acpi_put_table
353+
*
354+
* PARAMETERS: table - The pointer to the table
355+
*
356+
* RETURN: None
357+
*
358+
* DESCRIPTION: Release a table returned by acpi_get_table() and its clones.
359+
* Note that it is not safe if this function was invoked after an
360+
* uninstallation happened to the original table descriptor.
361+
* Currently there is no OSPMs' requirement to handle such
362+
* situations.
363+
*
364+
******************************************************************************/
365+
void acpi_put_table(struct acpi_table_header *table)
348366
{
349-
acpi_size tbl_size;
367+
u32 i;
368+
struct acpi_table_desc *table_desc;
369+
370+
ACPI_FUNCTION_TRACE(acpi_put_table);
371+
372+
(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
373+
374+
/* Walk the root table list */
375+
376+
for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
377+
table_desc = &acpi_gbl_root_table_list.tables[i];
350378

351-
return acpi_get_table_with_size(signature,
352-
instance, out_table, &tbl_size);
379+
if (table_desc->pointer != table) {
380+
continue;
381+
}
382+
383+
acpi_tb_put_table(table_desc);
384+
break;
385+
}
386+
387+
(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
388+
return_VOID;
353389
}
354390

355-
ACPI_EXPORT_SYMBOL(acpi_get_table)
391+
ACPI_EXPORT_SYMBOL(acpi_put_table)
356392

357393
/*******************************************************************************
358394
*
359395
* FUNCTION: acpi_get_table_by_index
360396
*
361397
* PARAMETERS: table_index - Table index
362-
* table - Where the pointer to the table is returned
398+
* out_table - Where the pointer to the table is returned
363399
*
364400
* RETURN: Status and pointer to the requested table
365401
*
@@ -368,43 +404,41 @@ ACPI_EXPORT_SYMBOL(acpi_get_table)
368404
*
369405
******************************************************************************/
370406
acpi_status
371-
acpi_get_table_by_index(u32 table_index, struct acpi_table_header **table)
407+
acpi_get_table_by_index(u32 table_index, struct acpi_table_header **out_table)
372408
{
373409
acpi_status status;
374410

375411
ACPI_FUNCTION_TRACE(acpi_get_table_by_index);
376412

377413
/* Parameter validation */
378414

379-
if (!table) {
415+
if (!out_table) {
380416
return_ACPI_STATUS(AE_BAD_PARAMETER);
381417
}
382418

419+
/*
420+
* Note that the following line is required by some OSPMs, they only
421+
* check if the returned table is NULL instead of the returned status
422+
* to determined if this function is succeeded.
423+
*/
424+
*out_table = NULL;
425+
383426
(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
384427

385428
/* Validate index */
386429

387430
if (table_index >= acpi_gbl_root_table_list.current_table_count) {
388-
(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
389-
return_ACPI_STATUS(AE_BAD_PARAMETER);
431+
status = AE_BAD_PARAMETER;
432+
goto unlock_and_exit;
390433
}
391434

392-
if (!acpi_gbl_root_table_list.tables[table_index].pointer) {
393-
394-
/* Table is not mapped, map it */
435+
status =
436+
acpi_tb_get_table(&acpi_gbl_root_table_list.tables[table_index],
437+
out_table);
395438

396-
status =
397-
acpi_tb_validate_table(&acpi_gbl_root_table_list.
398-
tables[table_index]);
399-
if (ACPI_FAILURE(status)) {
400-
(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
401-
return_ACPI_STATUS(status);
402-
}
403-
}
404-
405-
*table = acpi_gbl_root_table_list.tables[table_index].pointer;
439+
unlock_and_exit:
406440
(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
407-
return_ACPI_STATUS(AE_OK);
441+
return_ACPI_STATUS(status);
408442
}
409443

410444
ACPI_EXPORT_SYMBOL(acpi_get_table_by_index)

‎drivers/acpi/bus.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ void __init acpi_early_init(void)
974974
if (!acpi_strict)
975975
acpi_gbl_enable_interpreter_slack = TRUE;
976976

977-
acpi_gbl_permanent_mmap = 1;
977+
acpi_permanent_mmap = true;
978978

979979
/*
980980
* If the machine falls into the DMI check table,

0 commit comments

Comments
 (0)