dmtbdump.c revision 1.15 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: dmtbdump - Dump ACPI data tables that contain no AML code
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.2 christos /*
8 1.14 christos * Copyright (C) 2000 - 2022, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.2 christos * Redistribution and use in source and binary forms, with or without
12 1.2 christos * modification, are permitted provided that the following conditions
13 1.2 christos * are met:
14 1.2 christos * 1. Redistributions of source code must retain the above copyright
15 1.2 christos * notice, this list of conditions, and the following disclaimer,
16 1.2 christos * without modification.
17 1.2 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.2 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.2 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.2 christos * including a substantially similar Disclaimer requirement for further
21 1.2 christos * binary redistribution.
22 1.2 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.2 christos * of any contributors may be used to endorse or promote products derived
24 1.2 christos * from this software without specific prior written permission.
25 1.2 christos *
26 1.2 christos * Alternatively, this software may be distributed under the terms of the
27 1.2 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.2 christos * Software Foundation.
29 1.2 christos *
30 1.2 christos * NO WARRANTY
31 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.2 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.13 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 1.2 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.2 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.2 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.2 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.2 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.2 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.2 christos */
43 1.1 jruoho
44 1.1 jruoho #include "acpi.h"
45 1.1 jruoho #include "accommon.h"
46 1.1 jruoho #include "acdisasm.h"
47 1.1 jruoho #include "actables.h"
48 1.1 jruoho
49 1.1 jruoho /* This module used for application-level code only */
50 1.1 jruoho
51 1.1 jruoho #define _COMPONENT ACPI_CA_DISASSEMBLER
52 1.1 jruoho ACPI_MODULE_NAME ("dmtbdump")
53 1.1 jruoho
54 1.1 jruoho
55 1.7 christos /* Local prototypes */
56 1.2 christos
57 1.7 christos static void
58 1.7 christos AcpiDmValidateFadtLength (
59 1.7 christos UINT32 Revision,
60 1.7 christos UINT32 Length);
61 1.2 christos
62 1.2 christos
63 1.2 christos /*******************************************************************************
64 1.2 christos *
65 1.2 christos * FUNCTION: AcpiDmDumpBuffer
66 1.2 christos *
67 1.2 christos * PARAMETERS: Table - ACPI Table or subtable
68 1.2 christos * BufferOffset - Offset of buffer from Table above
69 1.2 christos * Length - Length of the buffer
70 1.2 christos * AbsoluteOffset - Offset of buffer in the main ACPI table
71 1.2 christos * Header - Name of the buffer field (printed on the
72 1.2 christos * first line only.)
73 1.2 christos *
74 1.2 christos * RETURN: None
75 1.2 christos *
76 1.2 christos * DESCRIPTION: Format the contents of an arbitrary length data buffer (in the
77 1.2 christos * disassembler output format.)
78 1.2 christos *
79 1.2 christos ******************************************************************************/
80 1.2 christos
81 1.2 christos void
82 1.2 christos AcpiDmDumpBuffer (
83 1.2 christos void *Table,
84 1.2 christos UINT32 BufferOffset,
85 1.2 christos UINT32 Length,
86 1.2 christos UINT32 AbsoluteOffset,
87 1.3 christos char *Header)
88 1.2 christos {
89 1.2 christos UINT8 *Buffer;
90 1.2 christos UINT32 i;
91 1.2 christos
92 1.2 christos
93 1.2 christos if (!Length)
94 1.2 christos {
95 1.2 christos return;
96 1.2 christos }
97 1.2 christos
98 1.2 christos Buffer = ACPI_CAST_PTR (UINT8, Table) + BufferOffset;
99 1.2 christos i = 0;
100 1.2 christos
101 1.2 christos while (i < Length)
102 1.2 christos {
103 1.2 christos if (!(i % 16))
104 1.2 christos {
105 1.3 christos /* Insert a backslash - line continuation character */
106 1.3 christos
107 1.3 christos if (Length > 16)
108 1.2 christos {
109 1.2 christos AcpiOsPrintf ("\\\n ");
110 1.2 christos }
111 1.2 christos }
112 1.2 christos
113 1.2 christos AcpiOsPrintf ("%.02X ", *Buffer);
114 1.2 christos i++;
115 1.2 christos Buffer++;
116 1.2 christos AbsoluteOffset++;
117 1.2 christos }
118 1.2 christos
119 1.2 christos AcpiOsPrintf ("\n");
120 1.2 christos }
121 1.2 christos
122 1.2 christos
123 1.1 jruoho /*******************************************************************************
124 1.1 jruoho *
125 1.3 christos * FUNCTION: AcpiDmDumpUnicode
126 1.3 christos *
127 1.3 christos * PARAMETERS: Table - ACPI Table or subtable
128 1.3 christos * BufferOffset - Offset of buffer from Table above
129 1.3 christos * ByteLength - Length of the buffer
130 1.3 christos *
131 1.3 christos * RETURN: None
132 1.3 christos *
133 1.3 christos * DESCRIPTION: Validate and dump the contents of a buffer that contains
134 1.3 christos * unicode data. The output is a standard ASCII string. If it
135 1.3 christos * appears that the data is not unicode, the buffer is dumped
136 1.3 christos * as hex characters.
137 1.3 christos *
138 1.3 christos ******************************************************************************/
139 1.3 christos
140 1.3 christos void
141 1.3 christos AcpiDmDumpUnicode (
142 1.3 christos void *Table,
143 1.3 christos UINT32 BufferOffset,
144 1.3 christos UINT32 ByteLength)
145 1.3 christos {
146 1.3 christos UINT8 *Buffer;
147 1.3 christos UINT32 Length;
148 1.3 christos UINT32 i;
149 1.3 christos
150 1.3 christos
151 1.3 christos Buffer = ((UINT8 *) Table) + BufferOffset;
152 1.3 christos Length = ByteLength - 2; /* Last two bytes are the null terminator */
153 1.3 christos
154 1.3 christos /* Ensure all low bytes are entirely printable ASCII */
155 1.3 christos
156 1.3 christos for (i = 0; i < Length; i += 2)
157 1.3 christos {
158 1.3 christos if (!isprint (Buffer[i]))
159 1.3 christos {
160 1.3 christos goto DumpRawBuffer;
161 1.3 christos }
162 1.3 christos }
163 1.3 christos
164 1.3 christos /* Ensure all high bytes are zero */
165 1.3 christos
166 1.3 christos for (i = 1; i < Length; i += 2)
167 1.3 christos {
168 1.3 christos if (Buffer[i])
169 1.3 christos {
170 1.3 christos goto DumpRawBuffer;
171 1.3 christos }
172 1.3 christos }
173 1.3 christos
174 1.3 christos /* Dump the buffer as a normal string */
175 1.3 christos
176 1.3 christos AcpiOsPrintf ("\"");
177 1.3 christos for (i = 0; i < Length; i += 2)
178 1.3 christos {
179 1.3 christos AcpiOsPrintf ("%c", Buffer[i]);
180 1.3 christos }
181 1.4 christos
182 1.3 christos AcpiOsPrintf ("\"\n");
183 1.3 christos return;
184 1.3 christos
185 1.3 christos DumpRawBuffer:
186 1.3 christos AcpiDmDumpBuffer (Table, BufferOffset, ByteLength,
187 1.3 christos BufferOffset, NULL);
188 1.3 christos AcpiOsPrintf ("\n");
189 1.3 christos }
190 1.3 christos
191 1.3 christos
192 1.3 christos /*******************************************************************************
193 1.3 christos *
194 1.1 jruoho * FUNCTION: AcpiDmDumpRsdp
195 1.1 jruoho *
196 1.1 jruoho * PARAMETERS: Table - A RSDP
197 1.1 jruoho *
198 1.2 christos * RETURN: Length of the table (there is not always a length field,
199 1.2 christos * use revision or length if available (ACPI 2.0+))
200 1.1 jruoho *
201 1.1 jruoho * DESCRIPTION: Format the contents of a RSDP
202 1.1 jruoho *
203 1.1 jruoho ******************************************************************************/
204 1.1 jruoho
205 1.1 jruoho UINT32
206 1.1 jruoho AcpiDmDumpRsdp (
207 1.1 jruoho ACPI_TABLE_HEADER *Table)
208 1.1 jruoho {
209 1.2 christos ACPI_TABLE_RSDP *Rsdp = ACPI_CAST_PTR (ACPI_TABLE_RSDP, Table);
210 1.2 christos UINT32 Length = sizeof (ACPI_RSDP_COMMON);
211 1.2 christos UINT8 Checksum;
212 1.3 christos ACPI_STATUS Status;
213 1.1 jruoho
214 1.1 jruoho
215 1.1 jruoho /* Dump the common ACPI 1.0 portion */
216 1.1 jruoho
217 1.3 christos Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoRsdp1);
218 1.3 christos if (ACPI_FAILURE (Status))
219 1.3 christos {
220 1.3 christos return (Length);
221 1.3 christos }
222 1.1 jruoho
223 1.2 christos /* Validate the first checksum */
224 1.2 christos
225 1.15 christos Checksum = AcpiUtGenerateChecksum (Rsdp, sizeof (ACPI_RSDP_COMMON),
226 1.4 christos Rsdp->Checksum);
227 1.2 christos if (Checksum != Rsdp->Checksum)
228 1.2 christos {
229 1.2 christos AcpiOsPrintf ("/* Incorrect Checksum above, should be 0x%2.2X */\n",
230 1.2 christos Checksum);
231 1.2 christos }
232 1.2 christos
233 1.2 christos /* The RSDP for ACPI 2.0+ contains more data and has a Length field */
234 1.1 jruoho
235 1.2 christos if (Rsdp->Revision > 0)
236 1.1 jruoho {
237 1.2 christos Length = Rsdp->Length;
238 1.3 christos Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoRsdp2);
239 1.3 christos if (ACPI_FAILURE (Status))
240 1.3 christos {
241 1.3 christos return (Length);
242 1.3 christos }
243 1.2 christos
244 1.2 christos /* Validate the extended checksum over entire RSDP */
245 1.2 christos
246 1.15 christos Checksum = AcpiUtGenerateChecksum (Rsdp, sizeof (ACPI_TABLE_RSDP),
247 1.4 christos Rsdp->ExtendedChecksum);
248 1.2 christos if (Checksum != Rsdp->ExtendedChecksum)
249 1.2 christos {
250 1.2 christos AcpiOsPrintf (
251 1.2 christos "/* Incorrect Extended Checksum above, should be 0x%2.2X */\n",
252 1.2 christos Checksum);
253 1.2 christos }
254 1.1 jruoho }
255 1.1 jruoho
256 1.1 jruoho return (Length);
257 1.1 jruoho }
258 1.1 jruoho
259 1.1 jruoho
260 1.1 jruoho /*******************************************************************************
261 1.1 jruoho *
262 1.1 jruoho * FUNCTION: AcpiDmDumpRsdt
263 1.1 jruoho *
264 1.1 jruoho * PARAMETERS: Table - A RSDT
265 1.1 jruoho *
266 1.1 jruoho * RETURN: None
267 1.1 jruoho *
268 1.1 jruoho * DESCRIPTION: Format the contents of a RSDT
269 1.1 jruoho *
270 1.1 jruoho ******************************************************************************/
271 1.1 jruoho
272 1.1 jruoho void
273 1.1 jruoho AcpiDmDumpRsdt (
274 1.1 jruoho ACPI_TABLE_HEADER *Table)
275 1.1 jruoho {
276 1.1 jruoho UINT32 *Array;
277 1.1 jruoho UINT32 Entries;
278 1.1 jruoho UINT32 Offset;
279 1.1 jruoho UINT32 i;
280 1.1 jruoho
281 1.1 jruoho
282 1.1 jruoho /* Point to start of table pointer array */
283 1.1 jruoho
284 1.1 jruoho Array = ACPI_CAST_PTR (ACPI_TABLE_RSDT, Table)->TableOffsetEntry;
285 1.1 jruoho Offset = sizeof (ACPI_TABLE_HEADER);
286 1.1 jruoho
287 1.1 jruoho /* RSDT uses 32-bit pointers */
288 1.1 jruoho
289 1.1 jruoho Entries = (Table->Length - sizeof (ACPI_TABLE_HEADER)) / sizeof (UINT32);
290 1.1 jruoho
291 1.1 jruoho for (i = 0; i < Entries; i++)
292 1.1 jruoho {
293 1.1 jruoho AcpiDmLineHeader2 (Offset, sizeof (UINT32), "ACPI Table Address", i);
294 1.1 jruoho AcpiOsPrintf ("%8.8X\n", Array[i]);
295 1.1 jruoho Offset += sizeof (UINT32);
296 1.1 jruoho }
297 1.1 jruoho }
298 1.1 jruoho
299 1.1 jruoho
300 1.1 jruoho /*******************************************************************************
301 1.1 jruoho *
302 1.1 jruoho * FUNCTION: AcpiDmDumpXsdt
303 1.1 jruoho *
304 1.1 jruoho * PARAMETERS: Table - A XSDT
305 1.1 jruoho *
306 1.1 jruoho * RETURN: None
307 1.1 jruoho *
308 1.1 jruoho * DESCRIPTION: Format the contents of a XSDT
309 1.1 jruoho *
310 1.1 jruoho ******************************************************************************/
311 1.1 jruoho
312 1.1 jruoho void
313 1.1 jruoho AcpiDmDumpXsdt (
314 1.1 jruoho ACPI_TABLE_HEADER *Table)
315 1.1 jruoho {
316 1.1 jruoho UINT64 *Array;
317 1.1 jruoho UINT32 Entries;
318 1.1 jruoho UINT32 Offset;
319 1.1 jruoho UINT32 i;
320 1.1 jruoho
321 1.1 jruoho
322 1.1 jruoho /* Point to start of table pointer array */
323 1.1 jruoho
324 1.1 jruoho Array = ACPI_CAST_PTR (ACPI_TABLE_XSDT, Table)->TableOffsetEntry;
325 1.1 jruoho Offset = sizeof (ACPI_TABLE_HEADER);
326 1.1 jruoho
327 1.1 jruoho /* XSDT uses 64-bit pointers */
328 1.1 jruoho
329 1.1 jruoho Entries = (Table->Length - sizeof (ACPI_TABLE_HEADER)) / sizeof (UINT64);
330 1.1 jruoho
331 1.1 jruoho for (i = 0; i < Entries; i++)
332 1.1 jruoho {
333 1.1 jruoho AcpiDmLineHeader2 (Offset, sizeof (UINT64), "ACPI Table Address", i);
334 1.1 jruoho AcpiOsPrintf ("%8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Array[i]));
335 1.1 jruoho Offset += sizeof (UINT64);
336 1.1 jruoho }
337 1.1 jruoho }
338 1.1 jruoho
339 1.1 jruoho
340 1.1 jruoho /*******************************************************************************
341 1.1 jruoho *
342 1.1 jruoho * FUNCTION: AcpiDmDumpFadt
343 1.1 jruoho *
344 1.1 jruoho * PARAMETERS: Table - A FADT
345 1.1 jruoho *
346 1.1 jruoho * RETURN: None
347 1.1 jruoho *
348 1.1 jruoho * DESCRIPTION: Format the contents of a FADT
349 1.1 jruoho *
350 1.2 christos * NOTE: We cannot depend on the FADT version to indicate the actual
351 1.2 christos * contents of the FADT because of BIOS bugs. The table length
352 1.2 christos * is the only reliable indicator.
353 1.2 christos *
354 1.1 jruoho ******************************************************************************/
355 1.1 jruoho
356 1.1 jruoho void
357 1.1 jruoho AcpiDmDumpFadt (
358 1.1 jruoho ACPI_TABLE_HEADER *Table)
359 1.1 jruoho {
360 1.3 christos ACPI_STATUS Status;
361 1.6 christos
362 1.3 christos
363 1.7 christos /* Always dump the minimum FADT revision 1 fields (ACPI 1.0) */
364 1.1 jruoho
365 1.7 christos Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
366 1.7 christos AcpiDmTableInfoFadt1);
367 1.7 christos if (ACPI_FAILURE (Status))
368 1.3 christos {
369 1.3 christos return;
370 1.3 christos }
371 1.1 jruoho
372 1.7 christos /* Check for FADT revision 2 fields (ACPI 1.0B MS extensions) */
373 1.7 christos
374 1.7 christos if ((Table->Length > ACPI_FADT_V1_SIZE) &&
375 1.7 christos (Table->Length <= ACPI_FADT_V2_SIZE))
376 1.6 christos {
377 1.7 christos Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
378 1.7 christos AcpiDmTableInfoFadt2);
379 1.7 christos if (ACPI_FAILURE (Status))
380 1.3 christos {
381 1.7 christos return;
382 1.3 christos }
383 1.1 jruoho }
384 1.1 jruoho
385 1.7 christos /* Check for FADT revision 3/4 fields and up (ACPI 2.0+ extended data) */
386 1.7 christos
387 1.7 christos else if (Table->Length > ACPI_FADT_V2_SIZE)
388 1.1 jruoho {
389 1.7 christos Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
390 1.7 christos AcpiDmTableInfoFadt3);
391 1.7 christos if (ACPI_FAILURE (Status))
392 1.3 christos {
393 1.7 christos return;
394 1.3 christos }
395 1.2 christos
396 1.7 christos /* Check for FADT revision 5 fields and up (ACPI 5.0+) */
397 1.2 christos
398 1.7 christos if (Table->Length > ACPI_FADT_V3_SIZE)
399 1.2 christos {
400 1.7 christos Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
401 1.7 christos AcpiDmTableInfoFadt5);
402 1.7 christos if (ACPI_FAILURE (Status))
403 1.7 christos {
404 1.7 christos return;
405 1.7 christos }
406 1.3 christos }
407 1.3 christos
408 1.7 christos /* Check for FADT revision 6 fields and up (ACPI 6.0+) */
409 1.7 christos
410 1.7 christos if (Table->Length > ACPI_FADT_V3_SIZE)
411 1.3 christos {
412 1.7 christos Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
413 1.7 christos AcpiDmTableInfoFadt6);
414 1.7 christos if (ACPI_FAILURE (Status))
415 1.7 christos {
416 1.7 christos return;
417 1.7 christos }
418 1.2 christos }
419 1.1 jruoho }
420 1.1 jruoho
421 1.7 christos /* Validate various fields in the FADT, including length */
422 1.1 jruoho
423 1.1 jruoho AcpiTbCreateLocalFadt (Table, Table->Length);
424 1.7 christos
425 1.7 christos /* Validate FADT length against the revision */
426 1.7 christos
427 1.7 christos AcpiDmValidateFadtLength (Table->Revision, Table->Length);
428 1.7 christos }
429 1.7 christos
430 1.7 christos
431 1.7 christos /*******************************************************************************
432 1.7 christos *
433 1.7 christos * FUNCTION: AcpiDmValidateFadtLength
434 1.7 christos *
435 1.7 christos * PARAMETERS: Revision - FADT revision (Header->Revision)
436 1.7 christos * Length - FADT length (Header->Length
437 1.7 christos *
438 1.7 christos * RETURN: None
439 1.7 christos *
440 1.7 christos * DESCRIPTION: Check the FADT revision against the expected table length for
441 1.7 christos * that revision. Issue a warning if the length is not what was
442 1.7 christos * expected. This seems to be such a common BIOS bug that the
443 1.7 christos * FADT revision has been rendered virtually meaningless.
444 1.7 christos *
445 1.7 christos ******************************************************************************/
446 1.7 christos
447 1.7 christos static void
448 1.7 christos AcpiDmValidateFadtLength (
449 1.7 christos UINT32 Revision,
450 1.7 christos UINT32 Length)
451 1.7 christos {
452 1.7 christos UINT32 ExpectedLength;
453 1.7 christos
454 1.7 christos
455 1.7 christos switch (Revision)
456 1.7 christos {
457 1.7 christos case 0:
458 1.7 christos
459 1.7 christos AcpiOsPrintf ("// ACPI Warning: Invalid FADT revision: 0\n");
460 1.7 christos return;
461 1.7 christos
462 1.7 christos case 1:
463 1.7 christos
464 1.7 christos ExpectedLength = ACPI_FADT_V1_SIZE;
465 1.7 christos break;
466 1.7 christos
467 1.7 christos case 2:
468 1.7 christos
469 1.7 christos ExpectedLength = ACPI_FADT_V2_SIZE;
470 1.7 christos break;
471 1.7 christos
472 1.7 christos case 3:
473 1.7 christos case 4:
474 1.7 christos
475 1.7 christos ExpectedLength = ACPI_FADT_V3_SIZE;
476 1.7 christos break;
477 1.7 christos
478 1.7 christos case 5:
479 1.7 christos
480 1.7 christos ExpectedLength = ACPI_FADT_V5_SIZE;
481 1.7 christos break;
482 1.7 christos
483 1.7 christos default:
484 1.7 christos
485 1.7 christos return;
486 1.7 christos }
487 1.7 christos
488 1.7 christos if (Length == ExpectedLength)
489 1.7 christos {
490 1.7 christos return;
491 1.7 christos }
492 1.7 christos
493 1.7 christos AcpiOsPrintf (
494 1.7 christos "\n// ACPI Warning: FADT revision %X does not match length: "
495 1.7 christos "found %X expected %X\n",
496 1.7 christos Revision, Length, ExpectedLength);
497 1.1 jruoho }
498