1*cb565728SJerry Jelinek /******************************************************************************
2*cb565728SJerry Jelinek *
3*cb565728SJerry Jelinek * Module Name: utbuffer - Buffer dump routines
4*cb565728SJerry Jelinek *
5*cb565728SJerry Jelinek *****************************************************************************/
6*cb565728SJerry Jelinek
7*cb565728SJerry Jelinek /*
8*cb565728SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp.
9*cb565728SJerry Jelinek * All rights reserved.
10*cb565728SJerry Jelinek *
11*cb565728SJerry Jelinek * Redistribution and use in source and binary forms, with or without
12*cb565728SJerry Jelinek * modification, are permitted provided that the following conditions
13*cb565728SJerry Jelinek * are met:
14*cb565728SJerry Jelinek * 1. Redistributions of source code must retain the above copyright
15*cb565728SJerry Jelinek * notice, this list of conditions, and the following disclaimer,
16*cb565728SJerry Jelinek * without modification.
17*cb565728SJerry Jelinek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*cb565728SJerry Jelinek * substantially similar to the "NO WARRANTY" disclaimer below
19*cb565728SJerry Jelinek * ("Disclaimer") and any redistribution must be conditioned upon
20*cb565728SJerry Jelinek * including a substantially similar Disclaimer requirement for further
21*cb565728SJerry Jelinek * binary redistribution.
22*cb565728SJerry Jelinek * 3. Neither the names of the above-listed copyright holders nor the names
23*cb565728SJerry Jelinek * of any contributors may be used to endorse or promote products derived
24*cb565728SJerry Jelinek * from this software without specific prior written permission.
25*cb565728SJerry Jelinek *
26*cb565728SJerry Jelinek * Alternatively, this software may be distributed under the terms of the
27*cb565728SJerry Jelinek * GNU General Public License ("GPL") version 2 as published by the Free
28*cb565728SJerry Jelinek * Software Foundation.
29*cb565728SJerry Jelinek *
30*cb565728SJerry Jelinek * NO WARRANTY
31*cb565728SJerry Jelinek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*cb565728SJerry Jelinek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*cb565728SJerry Jelinek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*cb565728SJerry Jelinek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*cb565728SJerry Jelinek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*cb565728SJerry Jelinek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*cb565728SJerry Jelinek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*cb565728SJerry Jelinek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*cb565728SJerry Jelinek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*cb565728SJerry Jelinek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*cb565728SJerry Jelinek * POSSIBILITY OF SUCH DAMAGES.
42*cb565728SJerry Jelinek */
43*cb565728SJerry Jelinek
44*cb565728SJerry Jelinek #include "acpi.h"
45*cb565728SJerry Jelinek #include "accommon.h"
46*cb565728SJerry Jelinek
47*cb565728SJerry Jelinek #define _COMPONENT ACPI_UTILITIES
48*cb565728SJerry Jelinek ACPI_MODULE_NAME ("utbuffer")
49*cb565728SJerry Jelinek
50*cb565728SJerry Jelinek
51*cb565728SJerry Jelinek /*******************************************************************************
52*cb565728SJerry Jelinek *
53*cb565728SJerry Jelinek * FUNCTION: AcpiUtDumpBuffer
54*cb565728SJerry Jelinek *
55*cb565728SJerry Jelinek * PARAMETERS: Buffer - Buffer to dump
56*cb565728SJerry Jelinek * Count - Amount to dump, in bytes
57*cb565728SJerry Jelinek * Display - BYTE, WORD, DWORD, or QWORD display:
58*cb565728SJerry Jelinek * DB_BYTE_DISPLAY
59*cb565728SJerry Jelinek * DB_WORD_DISPLAY
60*cb565728SJerry Jelinek * DB_DWORD_DISPLAY
61*cb565728SJerry Jelinek * DB_QWORD_DISPLAY
62*cb565728SJerry Jelinek * BaseOffset - Beginning buffer offset (display only)
63*cb565728SJerry Jelinek *
64*cb565728SJerry Jelinek * RETURN: None
65*cb565728SJerry Jelinek *
66*cb565728SJerry Jelinek * DESCRIPTION: Generic dump buffer in both hex and ascii.
67*cb565728SJerry Jelinek *
68*cb565728SJerry Jelinek ******************************************************************************/
69*cb565728SJerry Jelinek
70*cb565728SJerry Jelinek void
AcpiUtDumpBuffer(UINT8 * Buffer,UINT32 Count,UINT32 Display,UINT32 BaseOffset)71*cb565728SJerry Jelinek AcpiUtDumpBuffer (
72*cb565728SJerry Jelinek UINT8 *Buffer,
73*cb565728SJerry Jelinek UINT32 Count,
74*cb565728SJerry Jelinek UINT32 Display,
75*cb565728SJerry Jelinek UINT32 BaseOffset)
76*cb565728SJerry Jelinek {
77*cb565728SJerry Jelinek UINT32 i = 0;
78*cb565728SJerry Jelinek UINT32 j;
79*cb565728SJerry Jelinek UINT32 Temp32;
80*cb565728SJerry Jelinek UINT8 BufChar;
81*cb565728SJerry Jelinek
82*cb565728SJerry Jelinek
83*cb565728SJerry Jelinek if (!Buffer)
84*cb565728SJerry Jelinek {
85*cb565728SJerry Jelinek AcpiOsPrintf ("Null Buffer Pointer in DumpBuffer!\n");
86*cb565728SJerry Jelinek return;
87*cb565728SJerry Jelinek }
88*cb565728SJerry Jelinek
89*cb565728SJerry Jelinek if ((Count < 4) || (Count & 0x01))
90*cb565728SJerry Jelinek {
91*cb565728SJerry Jelinek Display = DB_BYTE_DISPLAY;
92*cb565728SJerry Jelinek }
93*cb565728SJerry Jelinek
94*cb565728SJerry Jelinek /* Nasty little dump buffer routine! */
95*cb565728SJerry Jelinek
96*cb565728SJerry Jelinek while (i < Count)
97*cb565728SJerry Jelinek {
98*cb565728SJerry Jelinek /* Print current offset */
99*cb565728SJerry Jelinek
100*cb565728SJerry Jelinek AcpiOsPrintf ("%7.4X: ", (BaseOffset + i));
101*cb565728SJerry Jelinek
102*cb565728SJerry Jelinek /* Print 16 hex chars */
103*cb565728SJerry Jelinek
104*cb565728SJerry Jelinek for (j = 0; j < 16;)
105*cb565728SJerry Jelinek {
106*cb565728SJerry Jelinek if (i + j >= Count)
107*cb565728SJerry Jelinek {
108*cb565728SJerry Jelinek /* Dump fill spaces */
109*cb565728SJerry Jelinek
110*cb565728SJerry Jelinek AcpiOsPrintf ("%*s", ((Display * 2) + 1), " ");
111*cb565728SJerry Jelinek j += Display;
112*cb565728SJerry Jelinek continue;
113*cb565728SJerry Jelinek }
114*cb565728SJerry Jelinek
115*cb565728SJerry Jelinek switch (Display)
116*cb565728SJerry Jelinek {
117*cb565728SJerry Jelinek case DB_BYTE_DISPLAY:
118*cb565728SJerry Jelinek default: /* Default is BYTE display */
119*cb565728SJerry Jelinek
120*cb565728SJerry Jelinek AcpiOsPrintf ("%02X ", Buffer[(ACPI_SIZE) i + j]);
121*cb565728SJerry Jelinek break;
122*cb565728SJerry Jelinek
123*cb565728SJerry Jelinek case DB_WORD_DISPLAY:
124*cb565728SJerry Jelinek
125*cb565728SJerry Jelinek ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
126*cb565728SJerry Jelinek AcpiOsPrintf ("%04X ", Temp32);
127*cb565728SJerry Jelinek break;
128*cb565728SJerry Jelinek
129*cb565728SJerry Jelinek case DB_DWORD_DISPLAY:
130*cb565728SJerry Jelinek
131*cb565728SJerry Jelinek ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
132*cb565728SJerry Jelinek AcpiOsPrintf ("%08X ", Temp32);
133*cb565728SJerry Jelinek break;
134*cb565728SJerry Jelinek
135*cb565728SJerry Jelinek case DB_QWORD_DISPLAY:
136*cb565728SJerry Jelinek
137*cb565728SJerry Jelinek ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
138*cb565728SJerry Jelinek AcpiOsPrintf ("%08X", Temp32);
139*cb565728SJerry Jelinek
140*cb565728SJerry Jelinek ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
141*cb565728SJerry Jelinek AcpiOsPrintf ("%08X ", Temp32);
142*cb565728SJerry Jelinek break;
143*cb565728SJerry Jelinek }
144*cb565728SJerry Jelinek
145*cb565728SJerry Jelinek j += Display;
146*cb565728SJerry Jelinek }
147*cb565728SJerry Jelinek
148*cb565728SJerry Jelinek /*
149*cb565728SJerry Jelinek * Print the ASCII equivalent characters but watch out for the bad
150*cb565728SJerry Jelinek * unprintable ones (printable chars are 0x20 through 0x7E)
151*cb565728SJerry Jelinek */
152*cb565728SJerry Jelinek AcpiOsPrintf (" ");
153*cb565728SJerry Jelinek for (j = 0; j < 16; j++)
154*cb565728SJerry Jelinek {
155*cb565728SJerry Jelinek if (i + j >= Count)
156*cb565728SJerry Jelinek {
157*cb565728SJerry Jelinek AcpiOsPrintf ("\n");
158*cb565728SJerry Jelinek return;
159*cb565728SJerry Jelinek }
160*cb565728SJerry Jelinek
161*cb565728SJerry Jelinek /*
162*cb565728SJerry Jelinek * Add comment characters so rest of line is ignored when
163*cb565728SJerry Jelinek * compiled
164*cb565728SJerry Jelinek */
165*cb565728SJerry Jelinek if (j == 0)
166*cb565728SJerry Jelinek {
167*cb565728SJerry Jelinek AcpiOsPrintf ("// ");
168*cb565728SJerry Jelinek }
169*cb565728SJerry Jelinek
170*cb565728SJerry Jelinek BufChar = Buffer[(ACPI_SIZE) i + j];
171*cb565728SJerry Jelinek if (isprint (BufChar))
172*cb565728SJerry Jelinek {
173*cb565728SJerry Jelinek AcpiOsPrintf ("%c", BufChar);
174*cb565728SJerry Jelinek }
175*cb565728SJerry Jelinek else
176*cb565728SJerry Jelinek {
177*cb565728SJerry Jelinek AcpiOsPrintf (".");
178*cb565728SJerry Jelinek }
179*cb565728SJerry Jelinek }
180*cb565728SJerry Jelinek
181*cb565728SJerry Jelinek /* Done with that line. */
182*cb565728SJerry Jelinek
183*cb565728SJerry Jelinek AcpiOsPrintf ("\n");
184*cb565728SJerry Jelinek i += 16;
185*cb565728SJerry Jelinek }
186*cb565728SJerry Jelinek
187*cb565728SJerry Jelinek return;
188*cb565728SJerry Jelinek }
189*cb565728SJerry Jelinek
190*cb565728SJerry Jelinek
191*cb565728SJerry Jelinek /*******************************************************************************
192*cb565728SJerry Jelinek *
193*cb565728SJerry Jelinek * FUNCTION: AcpiUtDebugDumpBuffer
194*cb565728SJerry Jelinek *
195*cb565728SJerry Jelinek * PARAMETERS: Buffer - Buffer to dump
196*cb565728SJerry Jelinek * Count - Amount to dump, in bytes
197*cb565728SJerry Jelinek * Display - BYTE, WORD, DWORD, or QWORD display:
198*cb565728SJerry Jelinek * DB_BYTE_DISPLAY
199*cb565728SJerry Jelinek * DB_WORD_DISPLAY
200*cb565728SJerry Jelinek * DB_DWORD_DISPLAY
201*cb565728SJerry Jelinek * DB_QWORD_DISPLAY
202*cb565728SJerry Jelinek * ComponentID - Caller's component ID
203*cb565728SJerry Jelinek *
204*cb565728SJerry Jelinek * RETURN: None
205*cb565728SJerry Jelinek *
206*cb565728SJerry Jelinek * DESCRIPTION: Generic dump buffer in both hex and ascii.
207*cb565728SJerry Jelinek *
208*cb565728SJerry Jelinek ******************************************************************************/
209*cb565728SJerry Jelinek
210*cb565728SJerry Jelinek void
AcpiUtDebugDumpBuffer(UINT8 * Buffer,UINT32 Count,UINT32 Display,UINT32 ComponentId)211*cb565728SJerry Jelinek AcpiUtDebugDumpBuffer (
212*cb565728SJerry Jelinek UINT8 *Buffer,
213*cb565728SJerry Jelinek UINT32 Count,
214*cb565728SJerry Jelinek UINT32 Display,
215*cb565728SJerry Jelinek UINT32 ComponentId)
216*cb565728SJerry Jelinek {
217*cb565728SJerry Jelinek
218*cb565728SJerry Jelinek /* Only dump the buffer if tracing is enabled */
219*cb565728SJerry Jelinek
220*cb565728SJerry Jelinek if (!((ACPI_LV_TABLES & AcpiDbgLevel) &&
221*cb565728SJerry Jelinek (ComponentId & AcpiDbgLayer)))
222*cb565728SJerry Jelinek {
223*cb565728SJerry Jelinek return;
224*cb565728SJerry Jelinek }
225*cb565728SJerry Jelinek
226*cb565728SJerry Jelinek AcpiUtDumpBuffer (Buffer, Count, Display, 0);
227*cb565728SJerry Jelinek }
228*cb565728SJerry Jelinek
229*cb565728SJerry Jelinek
230*cb565728SJerry Jelinek #ifdef ACPI_APPLICATION
231*cb565728SJerry Jelinek /*******************************************************************************
232*cb565728SJerry Jelinek *
233*cb565728SJerry Jelinek * FUNCTION: AcpiUtDumpBufferToFile
234*cb565728SJerry Jelinek *
235*cb565728SJerry Jelinek * PARAMETERS: File - File descriptor
236*cb565728SJerry Jelinek * Buffer - Buffer to dump
237*cb565728SJerry Jelinek * Count - Amount to dump, in bytes
238*cb565728SJerry Jelinek * Display - BYTE, WORD, DWORD, or QWORD display:
239*cb565728SJerry Jelinek * DB_BYTE_DISPLAY
240*cb565728SJerry Jelinek * DB_WORD_DISPLAY
241*cb565728SJerry Jelinek * DB_DWORD_DISPLAY
242*cb565728SJerry Jelinek * DB_QWORD_DISPLAY
243*cb565728SJerry Jelinek * BaseOffset - Beginning buffer offset (display only)
244*cb565728SJerry Jelinek *
245*cb565728SJerry Jelinek * RETURN: None
246*cb565728SJerry Jelinek *
247*cb565728SJerry Jelinek * DESCRIPTION: Generic dump buffer in both hex and ascii to a file.
248*cb565728SJerry Jelinek *
249*cb565728SJerry Jelinek ******************************************************************************/
250*cb565728SJerry Jelinek
251*cb565728SJerry Jelinek void
AcpiUtDumpBufferToFile(ACPI_FILE File,UINT8 * Buffer,UINT32 Count,UINT32 Display,UINT32 BaseOffset)252*cb565728SJerry Jelinek AcpiUtDumpBufferToFile (
253*cb565728SJerry Jelinek ACPI_FILE File,
254*cb565728SJerry Jelinek UINT8 *Buffer,
255*cb565728SJerry Jelinek UINT32 Count,
256*cb565728SJerry Jelinek UINT32 Display,
257*cb565728SJerry Jelinek UINT32 BaseOffset)
258*cb565728SJerry Jelinek {
259*cb565728SJerry Jelinek UINT32 i = 0;
260*cb565728SJerry Jelinek UINT32 j;
261*cb565728SJerry Jelinek UINT32 Temp32;
262*cb565728SJerry Jelinek UINT8 BufChar;
263*cb565728SJerry Jelinek
264*cb565728SJerry Jelinek
265*cb565728SJerry Jelinek if (!Buffer)
266*cb565728SJerry Jelinek {
267*cb565728SJerry Jelinek AcpiUtFilePrintf (File, "Null Buffer Pointer in DumpBuffer!\n");
268*cb565728SJerry Jelinek return;
269*cb565728SJerry Jelinek }
270*cb565728SJerry Jelinek
271*cb565728SJerry Jelinek if ((Count < 4) || (Count & 0x01))
272*cb565728SJerry Jelinek {
273*cb565728SJerry Jelinek Display = DB_BYTE_DISPLAY;
274*cb565728SJerry Jelinek }
275*cb565728SJerry Jelinek
276*cb565728SJerry Jelinek /* Nasty little dump buffer routine! */
277*cb565728SJerry Jelinek
278*cb565728SJerry Jelinek while (i < Count)
279*cb565728SJerry Jelinek {
280*cb565728SJerry Jelinek /* Print current offset */
281*cb565728SJerry Jelinek
282*cb565728SJerry Jelinek AcpiUtFilePrintf (File, "%7.4X: ", (BaseOffset + i));
283*cb565728SJerry Jelinek
284*cb565728SJerry Jelinek /* Print 16 hex chars */
285*cb565728SJerry Jelinek
286*cb565728SJerry Jelinek for (j = 0; j < 16;)
287*cb565728SJerry Jelinek {
288*cb565728SJerry Jelinek if (i + j >= Count)
289*cb565728SJerry Jelinek {
290*cb565728SJerry Jelinek /* Dump fill spaces */
291*cb565728SJerry Jelinek
292*cb565728SJerry Jelinek AcpiUtFilePrintf (File, "%*s", ((Display * 2) + 1), " ");
293*cb565728SJerry Jelinek j += Display;
294*cb565728SJerry Jelinek continue;
295*cb565728SJerry Jelinek }
296*cb565728SJerry Jelinek
297*cb565728SJerry Jelinek switch (Display)
298*cb565728SJerry Jelinek {
299*cb565728SJerry Jelinek case DB_BYTE_DISPLAY:
300*cb565728SJerry Jelinek default: /* Default is BYTE display */
301*cb565728SJerry Jelinek
302*cb565728SJerry Jelinek AcpiUtFilePrintf (File, "%02X ", Buffer[(ACPI_SIZE) i + j]);
303*cb565728SJerry Jelinek break;
304*cb565728SJerry Jelinek
305*cb565728SJerry Jelinek case DB_WORD_DISPLAY:
306*cb565728SJerry Jelinek
307*cb565728SJerry Jelinek ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
308*cb565728SJerry Jelinek AcpiUtFilePrintf (File, "%04X ", Temp32);
309*cb565728SJerry Jelinek break;
310*cb565728SJerry Jelinek
311*cb565728SJerry Jelinek case DB_DWORD_DISPLAY:
312*cb565728SJerry Jelinek
313*cb565728SJerry Jelinek ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
314*cb565728SJerry Jelinek AcpiUtFilePrintf (File, "%08X ", Temp32);
315*cb565728SJerry Jelinek break;
316*cb565728SJerry Jelinek
317*cb565728SJerry Jelinek case DB_QWORD_DISPLAY:
318*cb565728SJerry Jelinek
319*cb565728SJerry Jelinek ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
320*cb565728SJerry Jelinek AcpiUtFilePrintf (File, "%08X", Temp32);
321*cb565728SJerry Jelinek
322*cb565728SJerry Jelinek ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
323*cb565728SJerry Jelinek AcpiUtFilePrintf (File, "%08X ", Temp32);
324*cb565728SJerry Jelinek break;
325*cb565728SJerry Jelinek }
326*cb565728SJerry Jelinek
327*cb565728SJerry Jelinek j += Display;
328*cb565728SJerry Jelinek }
329*cb565728SJerry Jelinek
330*cb565728SJerry Jelinek /*
331*cb565728SJerry Jelinek * Print the ASCII equivalent characters but watch out for the bad
332*cb565728SJerry Jelinek * unprintable ones (printable chars are 0x20 through 0x7E)
333*cb565728SJerry Jelinek */
334*cb565728SJerry Jelinek AcpiUtFilePrintf (File, " ");
335*cb565728SJerry Jelinek for (j = 0; j < 16; j++)
336*cb565728SJerry Jelinek {
337*cb565728SJerry Jelinek if (i + j >= Count)
338*cb565728SJerry Jelinek {
339*cb565728SJerry Jelinek AcpiUtFilePrintf (File, "\n");
340*cb565728SJerry Jelinek return;
341*cb565728SJerry Jelinek }
342*cb565728SJerry Jelinek
343*cb565728SJerry Jelinek BufChar = Buffer[(ACPI_SIZE) i + j];
344*cb565728SJerry Jelinek if (isprint (BufChar))
345*cb565728SJerry Jelinek {
346*cb565728SJerry Jelinek AcpiUtFilePrintf (File, "%c", BufChar);
347*cb565728SJerry Jelinek }
348*cb565728SJerry Jelinek else
349*cb565728SJerry Jelinek {
350*cb565728SJerry Jelinek AcpiUtFilePrintf (File, ".");
351*cb565728SJerry Jelinek }
352*cb565728SJerry Jelinek }
353*cb565728SJerry Jelinek
354*cb565728SJerry Jelinek /* Done with that line. */
355*cb565728SJerry Jelinek
356*cb565728SJerry Jelinek AcpiUtFilePrintf (File, "\n");
357*cb565728SJerry Jelinek i += 16;
358*cb565728SJerry Jelinek }
359*cb565728SJerry Jelinek
360*cb565728SJerry Jelinek return;
361*cb565728SJerry Jelinek }
362*cb565728SJerry Jelinek #endif
363