| 1 |
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
| 2 |
/****************************************************************************** |
| 3 |
* |
| 4 |
* Module Name: tbprint - Table output utilities |
| 5 |
* |
| 6 |
* Copyright (C) 2000 - 2025, Intel Corp. |
| 7 |
* |
| 8 |
*****************************************************************************/ |
| 9 |
|
| 10 |
#include <acpi/acpi.h> |
| 11 |
#include "accommon.h" |
| 12 |
#include "actables.h" |
| 13 |
#include "acutils.h" |
| 14 |
|
| 15 |
#define _COMPONENT ACPI_TABLES |
| 16 |
ACPI_MODULE_NAME("tbprint") |
| 17 |
|
| 18 |
/* Local prototypes */ |
| 19 |
static void acpi_tb_fix_string(char *string, acpi_size length); |
| 20 |
|
| 21 |
static void |
| 22 |
acpi_tb_cleanup_table_header(struct acpi_table_header *out_header, |
| 23 |
struct acpi_table_header *header); |
| 24 |
|
| 25 |
/******************************************************************************* |
| 26 |
* |
| 27 |
* FUNCTION: acpi_tb_fix_string |
| 28 |
* |
| 29 |
* PARAMETERS: string - String to be repaired |
| 30 |
* length - Maximum length |
| 31 |
* |
| 32 |
* RETURN: None |
| 33 |
* |
| 34 |
* DESCRIPTION: Replace every non-printable or non-ascii byte in the string |
| 35 |
* with a question mark '?'. |
| 36 |
* |
| 37 |
******************************************************************************/ |
| 38 |
|
| 39 |
static void acpi_tb_fix_string(char *string, acpi_size length) |
| 40 |
{ |
| 41 |
|
| 42 |
while (length && *string) { |
| 43 |
if (!isprint((int)(u8)*string)) { |
| 44 |
*string = '?'; |
| 45 |
} |
| 46 |
|
| 47 |
string++; |
| 48 |
length--; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
/******************************************************************************* |
| 53 |
* |
| 54 |
* FUNCTION: acpi_tb_cleanup_table_header |
| 55 |
* |
| 56 |
* PARAMETERS: out_header - Where the cleaned header is returned |
| 57 |
* header - Input ACPI table header |
| 58 |
* |
| 59 |
* RETURN: Returns the cleaned header in out_header |
| 60 |
* |
| 61 |
* DESCRIPTION: Copy the table header and ensure that all "string" fields in |
| 62 |
* the header consist of printable characters. |
| 63 |
* |
| 64 |
******************************************************************************/ |
| 65 |
|
| 66 |
static void |
| 67 |
acpi_tb_cleanup_table_header(struct acpi_table_header *out_header, |
| 68 |
struct acpi_table_header *header) |
| 69 |
{ |
| 70 |
|
| 71 |
memcpy(out_header, header, sizeof(struct acpi_table_header)); |
| 72 |
|
| 73 |
acpi_tb_fix_string(out_header->signature, ACPI_NAMESEG_SIZE); |
| 74 |
acpi_tb_fix_string(out_header->oem_id, ACPI_OEM_ID_SIZE); |
| 75 |
acpi_tb_fix_string(out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE); |
| 76 |
acpi_tb_fix_string(out_header->asl_compiler_id, ACPI_NAMESEG_SIZE); |
| 77 |
} |
| 78 |
|
| 79 |
/******************************************************************************* |
| 80 |
* |
| 81 |
* FUNCTION: acpi_tb_print_table_header |
| 82 |
* |
| 83 |
* PARAMETERS: address - Table physical address |
| 84 |
* header - Table header |
| 85 |
* |
| 86 |
* RETURN: None |
| 87 |
* |
| 88 |
* DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP. |
| 89 |
* |
| 90 |
******************************************************************************/ |
| 91 |
|
| 92 |
void |
| 93 |
acpi_tb_print_table_header(acpi_physical_address address, |
| 94 |
struct acpi_table_header *header) |
| 95 |
{ |
| 96 |
struct acpi_table_header local_header; |
| 97 |
|
| 98 |
#pragma GCC diagnostic push |
| 99 |
#if defined(__GNUC__) && __GNUC__ >= 11 |
| 100 |
#pragma GCC diagnostic ignored "-Wstringop-overread" |
| 101 |
#endif |
| 102 |
|
| 103 |
if (ACPI_COMPARE_NAMESEG(header->signature, ACPI_SIG_FACS)) { |
| 104 |
|
| 105 |
/* FACS only has signature and length fields */ |
| 106 |
|
| 107 |
ACPI_INFO(("%-4.4s 0x%8.8X%8.8X %06X", |
| 108 |
header->signature, ACPI_FORMAT_UINT64(address), |
| 109 |
header->length)); |
| 110 |
} else if (ACPI_VALIDATE_RSDP_SIG(ACPI_CAST_PTR(struct acpi_table_rsdp, |
| 111 |
header)->signature)) { |
| 112 |
|
| 113 |
/* RSDP has no common fields */ |
| 114 |
|
| 115 |
memcpy(local_header.oem_id, |
| 116 |
ACPI_CAST_PTR(struct acpi_table_rsdp, header)->oem_id, |
| 117 |
ACPI_OEM_ID_SIZE); |
| 118 |
acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE); |
| 119 |
|
| 120 |
ACPI_INFO(("RSDP 0x%8.8X%8.8X %06X (v%.2d %-6.6s)", |
| 121 |
ACPI_FORMAT_UINT64(address), |
| 122 |
(ACPI_CAST_PTR(struct acpi_table_rsdp, header)-> |
| 123 |
revision > |
| 124 |
0) ? ACPI_CAST_PTR(struct acpi_table_rsdp, |
| 125 |
header)->length : 20, |
| 126 |
ACPI_CAST_PTR(struct acpi_table_rsdp, |
| 127 |
header)->revision, |
| 128 |
local_header.oem_id)); |
| 129 |
} else if (acpi_gbl_CDAT && !acpi_ut_valid_nameseg(header->signature)) { |
| 130 |
|
| 131 |
/* CDAT does not use the common ACPI table header */ |
| 132 |
|
| 133 |
ACPI_INFO(("%-4.4s 0x%8.8X%8.8X %06X", |
| 134 |
ACPI_SIG_CDAT, ACPI_FORMAT_UINT64(address), |
| 135 |
ACPI_CAST_PTR(struct acpi_table_cdat, |
| 136 |
header)->length)); |
| 137 |
} else { |
| 138 |
/* Standard ACPI table with full common header */ |
| 139 |
|
| 140 |
acpi_tb_cleanup_table_header(&local_header, header); |
| 141 |
|
| 142 |
ACPI_INFO(("%-4.4s 0x%8.8X%8.8X" |
| 143 |
" %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)", |
| 144 |
local_header.signature, ACPI_FORMAT_UINT64(address), |
| 145 |
local_header.length, local_header.revision, |
| 146 |
local_header.oem_id, local_header.oem_table_id, |
| 147 |
local_header.oem_revision, |
| 148 |
local_header.asl_compiler_id, |
| 149 |
local_header.asl_compiler_revision)); |
| 150 |
} |
| 151 |
#pragma GCC diagnostic pop |
| 152 |
} |