xref: /freebsd/sys/contrib/dev/acpica/components/tables/tbprint.c (revision c6db8143eda5c775467145ac73e8ebec47afdd8f)
1 /******************************************************************************
2  *
3  * Module Name: tbprint - Table output utilities
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2014, 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 MERCHANTIBILITY 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 #define __TBPRINT_C__
45 
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/actables.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 (!ACPI_IS_PRINT (*String))
90         {
91             *String = '?';
92         }
93         String++;
94         Length--;
95     }
96 }
97 
98 
99 /*******************************************************************************
100  *
101  * FUNCTION:    AcpiTbCleanupTableHeader
102  *
103  * PARAMETERS:  OutHeader           - Where the cleaned header is returned
104  *              Header              - Input ACPI table header
105  *
106  * RETURN:      Returns the cleaned header in OutHeader
107  *
108  * DESCRIPTION: Copy the table header and ensure that all "string" fields in
109  *              the header consist of printable characters.
110  *
111  ******************************************************************************/
112 
113 static void
114 AcpiTbCleanupTableHeader (
115     ACPI_TABLE_HEADER       *OutHeader,
116     ACPI_TABLE_HEADER       *Header)
117 {
118 
119     ACPI_MEMCPY (OutHeader, Header, sizeof (ACPI_TABLE_HEADER));
120 
121     AcpiTbFixString (OutHeader->Signature, ACPI_NAME_SIZE);
122     AcpiTbFixString (OutHeader->OemId, ACPI_OEM_ID_SIZE);
123     AcpiTbFixString (OutHeader->OemTableId, ACPI_OEM_TABLE_ID_SIZE);
124     AcpiTbFixString (OutHeader->AslCompilerId, ACPI_NAME_SIZE);
125 }
126 
127 
128 /*******************************************************************************
129  *
130  * FUNCTION:    AcpiTbPrintTableHeader
131  *
132  * PARAMETERS:  Address             - Table physical address
133  *              Header              - Table header
134  *
135  * RETURN:      None
136  *
137  * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
138  *
139  ******************************************************************************/
140 
141 void
142 AcpiTbPrintTableHeader (
143     ACPI_PHYSICAL_ADDRESS   Address,
144     ACPI_TABLE_HEADER       *Header)
145 {
146     ACPI_TABLE_HEADER       LocalHeader;
147 
148 
149     /*
150      * The reason that we use ACPI_PRINTF_UINT and ACPI_FORMAT_TO_UINT is to
151      * support both 32-bit and 64-bit hosts/addresses in a consistent manner.
152      * The %p specifier does not emit uniform output on all hosts. On some,
153      * leading zeros are not supported.
154      */
155     if (ACPI_COMPARE_NAME (Header->Signature, ACPI_SIG_FACS))
156     {
157         /* FACS only has signature and length fields */
158 
159         ACPI_INFO ((AE_INFO, "%-4.4s " ACPI_PRINTF_UINT " %06X",
160             Header->Signature, ACPI_FORMAT_TO_UINT (Address),
161             Header->Length));
162     }
163     else if (ACPI_VALIDATE_RSDP_SIG (Header->Signature))
164     {
165         /* RSDP has no common fields */
166 
167         ACPI_MEMCPY (LocalHeader.OemId,
168             ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->OemId, ACPI_OEM_ID_SIZE);
169         AcpiTbFixString (LocalHeader.OemId, ACPI_OEM_ID_SIZE);
170 
171         ACPI_INFO ((AE_INFO, "RSDP " ACPI_PRINTF_UINT " %06X (v%.2d %-6.6s)",
172             ACPI_FORMAT_TO_UINT (Address),
173             (ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision > 0) ?
174                 ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Length : 20,
175             ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision,
176             LocalHeader.OemId));
177     }
178     else
179     {
180         /* Standard ACPI table with full common header */
181 
182         AcpiTbCleanupTableHeader (&LocalHeader, Header);
183 
184         ACPI_INFO ((AE_INFO,
185             "%-4.4s " ACPI_PRINTF_UINT
186             " %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)",
187             LocalHeader.Signature, ACPI_FORMAT_TO_UINT (Address),
188             LocalHeader.Length, LocalHeader.Revision, LocalHeader.OemId,
189             LocalHeader.OemTableId, LocalHeader.OemRevision,
190             LocalHeader.AslCompilerId, LocalHeader.AslCompilerRevision));
191     }
192 }
193 
194 
195 /*******************************************************************************
196  *
197  * FUNCTION:    AcpiTbValidateChecksum
198  *
199  * PARAMETERS:  Table               - ACPI table to verify
200  *              Length              - Length of entire table
201  *
202  * RETURN:      Status
203  *
204  * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
205  *              exception on bad checksum.
206  *
207  ******************************************************************************/
208 
209 ACPI_STATUS
210 AcpiTbVerifyChecksum (
211     ACPI_TABLE_HEADER       *Table,
212     UINT32                  Length)
213 {
214     UINT8                   Checksum;
215 
216 
217     /*
218      * FACS/S3PT:
219      * They are the odd tables, have no standard ACPI header and no checksum
220      */
221 
222     if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_S3PT) ||
223         ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_FACS))
224     {
225         return (AE_OK);
226     }
227 
228     /* Compute the checksum on the table */
229 
230     Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Length);
231 
232     /* Checksum ok? (should be zero) */
233 
234     if (Checksum)
235     {
236         ACPI_BIOS_WARNING ((AE_INFO,
237             "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
238             "should be 0x%2.2X",
239             Table->Signature, Table->Checksum,
240             (UINT8) (Table->Checksum - Checksum)));
241 
242 #if (ACPI_CHECKSUM_ABORT)
243         return (AE_BAD_CHECKSUM);
244 #endif
245     }
246 
247     return (AE_OK);
248 }
249 
250 
251 /*******************************************************************************
252  *
253  * FUNCTION:    AcpiTbChecksum
254  *
255  * PARAMETERS:  Buffer          - Pointer to memory region to be checked
256  *              Length          - Length of this memory region
257  *
258  * RETURN:      Checksum (UINT8)
259  *
260  * DESCRIPTION: Calculates circular checksum of memory region.
261  *
262  ******************************************************************************/
263 
264 UINT8
265 AcpiTbChecksum (
266     UINT8                   *Buffer,
267     UINT32                  Length)
268 {
269     UINT8                   Sum = 0;
270     UINT8                   *End = Buffer + Length;
271 
272 
273     while (Buffer < End)
274     {
275         Sum = (UINT8) (Sum + *(Buffer++));
276     }
277 
278     return (Sum);
279 }
280