xref: /reactos/drivers/bus/acpi/acpica/tables/tbprint.c (revision 5140a990)
1 /******************************************************************************
2  *
3  * Module Name: tbprint - Table output utilities
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2022, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43 
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "actables.h"
47 #include "acdisasm.h"
48 #include "acutils.h"
49 
50 #define _COMPONENT          ACPI_TABLES
51         ACPI_MODULE_NAME    ("tbprint")
52 
53 
54 /* Local prototypes */
55 
56 static void
57 AcpiTbFixString (
58     char                    *String,
59     ACPI_SIZE               Length);
60 
61 static void
62 AcpiTbCleanupTableHeader (
63     ACPI_TABLE_HEADER       *OutHeader,
64     ACPI_TABLE_HEADER       *Header);
65 
66 
67 /*******************************************************************************
68  *
69  * FUNCTION:    AcpiTbFixString
70  *
71  * PARAMETERS:  String              - String to be repaired
72  *              Length              - Maximum length
73  *
74  * RETURN:      None
75  *
76  * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
77  *              with a question mark '?'.
78  *
79  ******************************************************************************/
80 
81 static void
82 AcpiTbFixString (
83     char                    *String,
84     ACPI_SIZE               Length)
85 {
86 
87     while (Length && *String)
88     {
89         if (!isprint ((int) (UINT8) *String))
90         {
91             *String = '?';
92         }
93 
94         String++;
95         Length--;
96     }
97 }
98 
99 
100 /*******************************************************************************
101  *
102  * FUNCTION:    AcpiTbCleanupTableHeader
103  *
104  * PARAMETERS:  OutHeader           - Where the cleaned header is returned
105  *              Header              - Input ACPI table header
106  *
107  * RETURN:      Returns the cleaned header in OutHeader
108  *
109  * DESCRIPTION: Copy the table header and ensure that all "string" fields in
110  *              the header consist of printable characters.
111  *
112  ******************************************************************************/
113 
114 static void
115 AcpiTbCleanupTableHeader (
116     ACPI_TABLE_HEADER       *OutHeader,
117     ACPI_TABLE_HEADER       *Header)
118 {
119 
120     memcpy (OutHeader, Header, sizeof (ACPI_TABLE_HEADER));
121 
122     AcpiTbFixString (OutHeader->Signature, ACPI_NAMESEG_SIZE);
123     AcpiTbFixString (OutHeader->OemId, ACPI_OEM_ID_SIZE);
124     AcpiTbFixString (OutHeader->OemTableId, ACPI_OEM_TABLE_ID_SIZE);
125     AcpiTbFixString (OutHeader->AslCompilerId, ACPI_NAMESEG_SIZE);
126 }
127 
128 
129 /*******************************************************************************
130  *
131  * FUNCTION:    AcpiTbPrintTableHeader
132  *
133  * PARAMETERS:  Address             - Table physical address
134  *              Header              - Table header
135  *
136  * RETURN:      None
137  *
138  * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
139  *
140  ******************************************************************************/
141 
142 void
143 AcpiTbPrintTableHeader (
144     ACPI_PHYSICAL_ADDRESS   Address,
145     ACPI_TABLE_HEADER       *Header)
146 {
147     ACPI_TABLE_HEADER       LocalHeader;
148 
149 
150     if (ACPI_COMPARE_NAMESEG (Header->Signature, ACPI_SIG_FACS))
151     {
152         /* FACS only has signature and length fields */
153 
154         ACPI_INFO (("%-4.4s 0x%8.8X%8.8X %06X",
155             Header->Signature, ACPI_FORMAT_UINT64 (Address),
156             Header->Length));
157     }
158     else if (ACPI_VALIDATE_RSDP_SIG (ACPI_CAST_PTR (ACPI_TABLE_RSDP,
159         Header)->Signature))
160     {
161         /* RSDP has no common fields */
162 
163         memcpy (LocalHeader.OemId, ACPI_CAST_PTR (ACPI_TABLE_RSDP,
164             Header)->OemId, ACPI_OEM_ID_SIZE);
165         AcpiTbFixString (LocalHeader.OemId, ACPI_OEM_ID_SIZE);
166 
167         ACPI_INFO (("RSDP 0x%8.8X%8.8X %06X (v%.2d %-6.6s)",
168             ACPI_FORMAT_UINT64 (Address),
169             (ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision > 0) ?
170                 ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Length : 20,
171             ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision,
172             LocalHeader.OemId));
173     }
174     else
175     {
176         /* Standard ACPI table with full common header */
177 
178         AcpiTbCleanupTableHeader (&LocalHeader, Header);
179 
180         ACPI_INFO ((
181             "%-4.4s 0x%8.8X%8.8X"
182             " %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)",
183             LocalHeader.Signature, ACPI_FORMAT_UINT64 (Address),
184             LocalHeader.Length, LocalHeader.Revision, LocalHeader.OemId,
185             LocalHeader.OemTableId, LocalHeader.OemRevision,
186             LocalHeader.AslCompilerId, LocalHeader.AslCompilerRevision));
187     }
188 }
189 
190