| 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 *, | 
|---|
| 23 | struct acpi_table_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 | (struct acpi_table_header *, | 
|---|
| 68 | struct acpi_table_header *) | 
|---|
| 69 | { | 
|---|
| 70 |  | 
|---|
| 71 | memcpy(to: out_header, from: header, len: sizeof(struct acpi_table_header)); | 
|---|
| 72 |  | 
|---|
| 73 | acpi_tb_fix_string(string: out_header->signature, ACPI_NAMESEG_SIZE); | 
|---|
| 74 | acpi_tb_fix_string(string: out_header->oem_id, ACPI_OEM_ID_SIZE); | 
|---|
| 75 | acpi_tb_fix_string(string: out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE); | 
|---|
| 76 | acpi_tb_fix_string(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_physical_address address, | 
|---|
| 94 | struct acpi_table_header *) | 
|---|
| 95 | { | 
|---|
| 96 | struct acpi_table_header ; | 
|---|
| 97 |  | 
|---|
| 98 | if (ACPI_COMPARE_NAMESEG(header->signature, ACPI_SIG_FACS)) { | 
|---|
| 99 |  | 
|---|
| 100 | /* FACS only has signature and length fields */ | 
|---|
| 101 |  | 
|---|
| 102 | ACPI_INFO(( "%-4.4s 0x%8.8X%8.8X %06X", | 
|---|
| 103 | header->signature, ACPI_FORMAT_UINT64(address), | 
|---|
| 104 | header->length)); | 
|---|
| 105 | } else if (ACPI_VALIDATE_RSDP_SIG(ACPI_CAST_PTR(struct acpi_table_rsdp, | 
|---|
| 106 | header)->signature)) { | 
|---|
| 107 |  | 
|---|
| 108 | /* RSDP has no common fields */ | 
|---|
| 109 |  | 
|---|
| 110 | memcpy(to: local_header.oem_id, | 
|---|
| 111 | ACPI_CAST_PTR(struct acpi_table_rsdp, header)->oem_id, | 
|---|
| 112 | ACPI_OEM_ID_SIZE); | 
|---|
| 113 | acpi_tb_fix_string(string: local_header.oem_id, ACPI_OEM_ID_SIZE); | 
|---|
| 114 |  | 
|---|
| 115 | ACPI_INFO(( "RSDP 0x%8.8X%8.8X %06X (v%.2d %-6.6s)", | 
|---|
| 116 | ACPI_FORMAT_UINT64(address), | 
|---|
| 117 | (ACPI_CAST_PTR(struct acpi_table_rsdp, header)-> | 
|---|
| 118 | revision > | 
|---|
| 119 | 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp, | 
|---|
| 120 | header)->length : 20, | 
|---|
| 121 | ACPI_CAST_PTR(struct acpi_table_rsdp, | 
|---|
| 122 | header)->revision, | 
|---|
| 123 | local_header.oem_id)); | 
|---|
| 124 | } else if (acpi_gbl_CDAT && !acpi_ut_valid_nameseg(signature: header->signature)) { | 
|---|
| 125 |  | 
|---|
| 126 | /* CDAT does not use the common ACPI table header */ | 
|---|
| 127 |  | 
|---|
| 128 | ACPI_INFO(( "%-4.4s 0x%8.8X%8.8X %06X", | 
|---|
| 129 | ACPI_SIG_CDAT, ACPI_FORMAT_UINT64(address), | 
|---|
| 130 | ACPI_CAST_PTR(struct acpi_table_cdat, | 
|---|
| 131 | header)->length)); | 
|---|
| 132 | } else { | 
|---|
| 133 | /* Standard ACPI table with full common header */ | 
|---|
| 134 |  | 
|---|
| 135 | acpi_tb_cleanup_table_header(out_header: &local_header, header); | 
|---|
| 136 |  | 
|---|
| 137 | ACPI_INFO(( "%-4.4s 0x%8.8X%8.8X" | 
|---|
| 138 | " %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)", | 
|---|
| 139 | local_header.signature, ACPI_FORMAT_UINT64(address), | 
|---|
| 140 | local_header.length, local_header.revision, | 
|---|
| 141 | local_header.oem_id, local_header.oem_table_id, | 
|---|
| 142 | local_header.oem_revision, | 
|---|
| 143 | local_header.asl_compiler_id, | 
|---|
| 144 | local_header.asl_compiler_revision)); | 
|---|
| 145 | } | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|