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 - 2022, 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 
acpi_tb_fix_string(char * string,acpi_size length)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
acpi_tb_cleanup_table_header(struct acpi_table_header * out_header,struct acpi_table_header * header)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
acpi_tb_print_table_header(acpi_physical_address address,struct acpi_table_header * header)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 	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(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(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 {
125 		/* Standard ACPI table with full common header */
126 
127 		acpi_tb_cleanup_table_header(&local_header, header);
128 
129 		ACPI_INFO(("%-4.4s 0x%8.8X%8.8X"
130 			   " %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)",
131 			   local_header.signature, ACPI_FORMAT_UINT64(address),
132 			   local_header.length, local_header.revision,
133 			   local_header.oem_id, local_header.oem_table_id,
134 			   local_header.oem_revision,
135 			   local_header.asl_compiler_id,
136 			   local_header.asl_compiler_revision));
137 	}
138 }
139