1 /*******************************************************************************
3 * Module Name: dbutils - AML debugger utilities
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2017, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acnamesp.h>
47 #include <contrib/dev/acpica/include/acdebug.h>
50 #define _COMPONENT ACPI_CA_DEBUGGER
51 ACPI_MODULE_NAME ("dbutils")
54 /* Local prototypes */
56 #ifdef ACPI_OBSOLETE_FUNCTIONS
58 AcpiDbSecondPassParse (
59 ACPI_PARSE_OBJECT *Root);
67 /*******************************************************************************
69 * FUNCTION: AcpiDbMatchArgument
71 * PARAMETERS: UserArgument - User command line
72 * Arguments - Array of commands to match against
74 * RETURN: Index into command array or ACPI_TYPE_NOT_FOUND if not found
76 * DESCRIPTION: Search command array for a command match
78 ******************************************************************************/
83 ACPI_DB_ARGUMENT_INFO *Arguments)
88 if (!UserArgument || UserArgument[0] == 0)
90 return (ACPI_TYPE_NOT_FOUND);
93 for (i = 0; Arguments[i].Name; i++)
96 ACPI_CAST_PTR (char, Arguments[i].Name),
97 ACPI_CAST_PTR (char, UserArgument)) == Arguments[i].Name)
103 /* Argument not recognized */
105 return (ACPI_TYPE_NOT_FOUND);
109 /*******************************************************************************
111 * FUNCTION: AcpiDbSetOutputDestination
113 * PARAMETERS: OutputFlags - Current flags word
117 * DESCRIPTION: Set the current destination for debugger output. Also sets
118 * the debug output level accordingly.
120 ******************************************************************************/
123 AcpiDbSetOutputDestination (
127 AcpiGbl_DbOutputFlags = (UINT8) OutputFlags;
129 if ((OutputFlags & ACPI_DB_REDIRECTABLE_OUTPUT) &&
130 AcpiGbl_DbOutputToFile)
132 AcpiDbgLevel = AcpiGbl_DbDebugLevel;
136 AcpiDbgLevel = AcpiGbl_DbConsoleDebugLevel;
141 /*******************************************************************************
143 * FUNCTION: AcpiDbDumpExternalObject
145 * PARAMETERS: ObjDesc - External ACPI object to dump
146 * Level - Nesting level.
150 * DESCRIPTION: Dump the contents of an ACPI external object
152 ******************************************************************************/
155 AcpiDbDumpExternalObject (
156 ACPI_OBJECT *ObjDesc,
164 AcpiOsPrintf ("[Null Object]\n");
168 for (i = 0; i < Level; i++)
173 switch (ObjDesc->Type)
177 AcpiOsPrintf ("[Null Object] (Type=0)\n");
180 case ACPI_TYPE_INTEGER:
182 AcpiOsPrintf ("[Integer] = %8.8X%8.8X\n",
183 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
186 case ACPI_TYPE_STRING:
188 AcpiOsPrintf ("[String] Length %.2X = ", ObjDesc->String.Length);
189 AcpiUtPrintString (ObjDesc->String.Pointer, ACPI_UINT8_MAX);
193 case ACPI_TYPE_BUFFER:
195 AcpiOsPrintf ("[Buffer] Length %.2X = ", ObjDesc->Buffer.Length);
196 if (ObjDesc->Buffer.Length)
198 if (ObjDesc->Buffer.Length > 16)
203 AcpiUtDebugDumpBuffer (
204 ACPI_CAST_PTR (UINT8, ObjDesc->Buffer.Pointer),
205 ObjDesc->Buffer.Length, DB_BYTE_DISPLAY, _COMPONENT);
213 case ACPI_TYPE_PACKAGE:
215 AcpiOsPrintf ("[Package] Contains %u Elements:\n",
216 ObjDesc->Package.Count);
218 for (i = 0; i < ObjDesc->Package.Count; i++)
220 AcpiDbDumpExternalObject (
221 &ObjDesc->Package.Elements[i], Level+1);
225 case ACPI_TYPE_LOCAL_REFERENCE:
227 AcpiOsPrintf ("[Object Reference] = ");
228 AcpiDbDisplayInternalObject (ObjDesc->Reference.Handle, NULL);
231 case ACPI_TYPE_PROCESSOR:
233 AcpiOsPrintf ("[Processor]\n");
236 case ACPI_TYPE_POWER:
238 AcpiOsPrintf ("[Power Resource]\n");
243 AcpiOsPrintf ("[Unknown Type] %X\n", ObjDesc->Type);
249 /*******************************************************************************
251 * FUNCTION: AcpiDbPrepNamestring
253 * PARAMETERS: Name - String to prepare
257 * DESCRIPTION: Translate all forward slashes and dots to backslashes.
259 ******************************************************************************/
262 AcpiDbPrepNamestring (
273 /* Convert a leading forward slash to a backslash */
280 /* Ignore a leading backslash, this is the root prefix */
282 if (ACPI_IS_ROOT_PREFIX (*Name))
287 /* Convert all slash path separators to dots */
291 if ((*Name == '/') ||
302 /*******************************************************************************
304 * FUNCTION: AcpiDbLocalNsLookup
306 * PARAMETERS: Name - Name to lookup
308 * RETURN: Pointer to a namespace node, null on failure
310 * DESCRIPTION: Lookup a name in the ACPI namespace
312 * Note: Currently begins search from the root. Could be enhanced to use
313 * the current prefix (scope) node as the search beginning point.
315 ******************************************************************************/
317 ACPI_NAMESPACE_NODE *
318 AcpiDbLocalNsLookup (
323 ACPI_NAMESPACE_NODE *Node = NULL;
326 AcpiDbPrepNamestring (Name);
328 /* Build an internal namestring */
330 Status = AcpiNsInternalizeName (Name, &InternalPath);
331 if (ACPI_FAILURE (Status))
333 AcpiOsPrintf ("Invalid namestring: %s\n", Name);
339 * (Uses root node as the search starting point)
341 Status = AcpiNsLookup (NULL, InternalPath, ACPI_TYPE_ANY,
342 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE,
344 if (ACPI_FAILURE (Status))
346 AcpiOsPrintf ("Could not locate name: %s, %s\n",
347 Name, AcpiFormatException (Status));
350 ACPI_FREE (InternalPath);
355 /*******************************************************************************
357 * FUNCTION: AcpiDbUint32ToHexString
359 * PARAMETERS: Value - The value to be converted to string
360 * Buffer - Buffer for result (not less than 11 bytes)
364 * DESCRIPTION: Convert the unsigned 32-bit value to the hexadecimal image
366 * NOTE: It is the caller's responsibility to ensure that the length of buffer
369 ******************************************************************************/
372 AcpiDbUint32ToHexString (
381 strcpy (Buffer, "0");
387 for (i = 7; i >= 0; i--)
389 Buffer[i] = AcpiGbl_UpperHexDigits [Value & 0x0F];
395 #ifdef ACPI_OBSOLETE_FUNCTIONS
396 /*******************************************************************************
398 * FUNCTION: AcpiDbSecondPassParse
400 * PARAMETERS: Root - Root of the parse tree
404 * DESCRIPTION: Second pass parse of the ACPI tables. We need to wait until
405 * second pass to parse the control methods
407 ******************************************************************************/
410 AcpiDbSecondPassParse (
411 ACPI_PARSE_OBJECT *Root)
413 ACPI_PARSE_OBJECT *Op = Root;
414 ACPI_PARSE_OBJECT *Method;
415 ACPI_PARSE_OBJECT *SearchOp;
416 ACPI_PARSE_OBJECT *StartOp;
417 ACPI_STATUS Status = AE_OK;
418 UINT32 BaseAmlOffset;
419 ACPI_WALK_STATE *WalkState;
422 ACPI_FUNCTION_ENTRY ();
425 AcpiOsPrintf ("Pass two parse ....\n");
429 if (Op->Common.AmlOpcode == AML_METHOD_OP)
433 /* Create a new walk state for the parse */
435 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
438 return (AE_NO_MEMORY);
441 /* Init the Walk State */
443 WalkState->ParserState.Aml =
444 WalkState->ParserState.AmlStart = Method->Named.Data;
445 WalkState->ParserState.AmlEnd =
446 WalkState->ParserState.PkgEnd = Method->Named.Data +
447 Method->Named.Length;
448 WalkState->ParserState.StartScope = Op;
450 WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
451 WalkState->AscendingCallback = AcpiDsLoad1EndOp;
453 /* Perform the AML parse */
455 Status = AcpiPsParseAml (WalkState);
457 BaseAmlOffset = (Method->Common.Value.Arg)->Common.AmlOffset + 1;
458 StartOp = (Method->Common.Value.Arg)->Common.Next;
463 SearchOp->Common.AmlOffset += BaseAmlOffset;
464 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
468 if (Op->Common.AmlOpcode == AML_REGION_OP)
470 /* TBD: [Investigate] this isn't quite the right thing to do! */
473 * Method = (ACPI_DEFERRED_OP *) Op;
474 * Status = AcpiPsParseAml (Op, Method->Body, Method->BodyLength);
478 if (ACPI_FAILURE (Status))
483 Op = AcpiPsGetDepthNext (Root, Op);
490 /*******************************************************************************
492 * FUNCTION: AcpiDbDumpBuffer
494 * PARAMETERS: Address - Pointer to the buffer
498 * DESCRIPTION: Print a portion of a buffer
500 ******************************************************************************/
507 AcpiOsPrintf ("\nLocation %X:\n", Address);
509 AcpiDbgLevel |= ACPI_LV_TABLES;
510 AcpiUtDebugDumpBuffer (ACPI_TO_POINTER (Address), 64, DB_BYTE_DISPLAY,