1 /*******************************************************************************
3 * Module Name: dbutils - AML debugger utilities
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2015, 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>
48 #include <contrib/dev/acpica/include/acdisasm.h>
53 #define _COMPONENT ACPI_CA_DEBUGGER
54 ACPI_MODULE_NAME ("dbutils")
56 /* Local prototypes */
58 #ifdef ACPI_OBSOLETE_FUNCTIONS
60 AcpiDbSecondPassParse (
61 ACPI_PARSE_OBJECT *Root);
68 static char *Converter = "0123456789ABCDEF";
71 /*******************************************************************************
73 * FUNCTION: AcpiDbMatchArgument
75 * PARAMETERS: UserArgument - User command line
76 * Arguments - Array of commands to match against
78 * RETURN: Index into command array or ACPI_TYPE_NOT_FOUND if not found
80 * DESCRIPTION: Search command array for a command match
82 ******************************************************************************/
87 ACPI_DB_ARGUMENT_INFO *Arguments)
92 if (!UserArgument || UserArgument[0] == 0)
94 return (ACPI_TYPE_NOT_FOUND);
97 for (i = 0; Arguments[i].Name; i++)
99 if (ACPI_STRSTR (Arguments[i].Name, UserArgument) == Arguments[i].Name)
105 /* Argument not recognized */
107 return (ACPI_TYPE_NOT_FOUND);
111 /*******************************************************************************
113 * FUNCTION: AcpiDbSetOutputDestination
115 * PARAMETERS: OutputFlags - Current flags word
119 * DESCRIPTION: Set the current destination for debugger output. Also sets
120 * the debug output level accordingly.
122 ******************************************************************************/
125 AcpiDbSetOutputDestination (
129 AcpiGbl_DbOutputFlags = (UINT8) OutputFlags;
131 if ((OutputFlags & ACPI_DB_REDIRECTABLE_OUTPUT) && AcpiGbl_DbOutputToFile)
133 AcpiDbgLevel = AcpiGbl_DbDebugLevel;
137 AcpiDbgLevel = AcpiGbl_DbConsoleDebugLevel;
142 /*******************************************************************************
144 * FUNCTION: AcpiDbDumpExternalObject
146 * PARAMETERS: ObjDesc - External ACPI object to dump
147 * Level - Nesting level.
151 * DESCRIPTION: Dump the contents of an ACPI external object
153 ******************************************************************************/
156 AcpiDbDumpExternalObject (
157 ACPI_OBJECT *ObjDesc,
165 AcpiOsPrintf ("[Null Object]\n");
169 for (i = 0; i < Level; i++)
174 switch (ObjDesc->Type)
178 AcpiOsPrintf ("[Null Object] (Type=0)\n");
181 case ACPI_TYPE_INTEGER:
183 AcpiOsPrintf ("[Integer] = %8.8X%8.8X\n",
184 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
187 case ACPI_TYPE_STRING:
189 AcpiOsPrintf ("[String] Length %.2X = ", ObjDesc->String.Length);
190 AcpiUtPrintString (ObjDesc->String.Pointer, ACPI_UINT8_MAX);
194 case ACPI_TYPE_BUFFER:
196 AcpiOsPrintf ("[Buffer] Length %.2X = ", ObjDesc->Buffer.Length);
197 if (ObjDesc->Buffer.Length)
199 if (ObjDesc->Buffer.Length > 16)
203 AcpiUtDebugDumpBuffer (ACPI_CAST_PTR (UINT8, ObjDesc->Buffer.Pointer),
204 ObjDesc->Buffer.Length, DB_BYTE_DISPLAY, _COMPONENT);
212 case ACPI_TYPE_PACKAGE:
214 AcpiOsPrintf ("[Package] Contains %u Elements:\n",
215 ObjDesc->Package.Count);
217 for (i = 0; i < ObjDesc->Package.Count; i++)
219 AcpiDbDumpExternalObject (&ObjDesc->Package.Elements[i], Level+1);
223 case ACPI_TYPE_LOCAL_REFERENCE:
225 AcpiOsPrintf ("[Object Reference] = ");
226 AcpiDmDisplayInternalObject (ObjDesc->Reference.Handle, NULL);
229 case ACPI_TYPE_PROCESSOR:
231 AcpiOsPrintf ("[Processor]\n");
234 case ACPI_TYPE_POWER:
236 AcpiOsPrintf ("[Power Resource]\n");
241 AcpiOsPrintf ("[Unknown Type] %X\n", ObjDesc->Type);
247 /*******************************************************************************
249 * FUNCTION: AcpiDbPrepNamestring
251 * PARAMETERS: Name - String to prepare
255 * DESCRIPTION: Translate all forward slashes and dots to backslashes.
257 ******************************************************************************/
260 AcpiDbPrepNamestring (
271 /* Convert a leading forward slash to a backslash */
278 /* Ignore a leading backslash, this is the root prefix */
280 if (ACPI_IS_ROOT_PREFIX (*Name))
285 /* Convert all slash path separators to dots */
289 if ((*Name == '/') ||
300 /*******************************************************************************
302 * FUNCTION: AcpiDbLocalNsLookup
304 * PARAMETERS: Name - Name to lookup
306 * RETURN: Pointer to a namespace node, null on failure
308 * DESCRIPTION: Lookup a name in the ACPI namespace
310 * Note: Currently begins search from the root. Could be enhanced to use
311 * the current prefix (scope) node as the search beginning point.
313 ******************************************************************************/
315 ACPI_NAMESPACE_NODE *
316 AcpiDbLocalNsLookup (
321 ACPI_NAMESPACE_NODE *Node = NULL;
324 AcpiDbPrepNamestring (Name);
326 /* Build an internal namestring */
328 Status = AcpiNsInternalizeName (Name, &InternalPath);
329 if (ACPI_FAILURE (Status))
331 AcpiOsPrintf ("Invalid namestring: %s\n", Name);
337 * (Uses root node as the search starting point)
339 Status = AcpiNsLookup (NULL, InternalPath, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
340 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
341 if (ACPI_FAILURE (Status))
343 AcpiOsPrintf ("Could not locate name: %s, %s\n",
344 Name, AcpiFormatException (Status));
347 ACPI_FREE (InternalPath);
352 /*******************************************************************************
354 * FUNCTION: AcpiDbUint32ToHexString
356 * PARAMETERS: Value - The value to be converted to string
357 * Buffer - Buffer for result (not less than 11 bytes)
361 * DESCRIPTION: Convert the unsigned 32-bit value to the hexadecimal image
363 * NOTE: It is the caller's responsibility to ensure that the length of buffer
366 ******************************************************************************/
369 AcpiDbUint32ToHexString (
378 ACPI_STRCPY (Buffer, "0");
384 for (i = 7; i >= 0; i--)
386 Buffer[i] = Converter [Value & 0x0F];
392 #ifdef ACPI_OBSOLETE_FUNCTIONS
393 /*******************************************************************************
395 * FUNCTION: AcpiDbSecondPassParse
397 * PARAMETERS: Root - Root of the parse tree
401 * DESCRIPTION: Second pass parse of the ACPI tables. We need to wait until
402 * second pass to parse the control methods
404 ******************************************************************************/
407 AcpiDbSecondPassParse (
408 ACPI_PARSE_OBJECT *Root)
410 ACPI_PARSE_OBJECT *Op = Root;
411 ACPI_PARSE_OBJECT *Method;
412 ACPI_PARSE_OBJECT *SearchOp;
413 ACPI_PARSE_OBJECT *StartOp;
414 ACPI_STATUS Status = AE_OK;
415 UINT32 BaseAmlOffset;
416 ACPI_WALK_STATE *WalkState;
419 ACPI_FUNCTION_ENTRY ();
422 AcpiOsPrintf ("Pass two parse ....\n");
426 if (Op->Common.AmlOpcode == AML_METHOD_OP)
430 /* Create a new walk state for the parse */
432 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
435 return (AE_NO_MEMORY);
438 /* Init the Walk State */
440 WalkState->ParserState.Aml =
441 WalkState->ParserState.AmlStart = Method->Named.Data;
442 WalkState->ParserState.AmlEnd =
443 WalkState->ParserState.PkgEnd = Method->Named.Data +
444 Method->Named.Length;
445 WalkState->ParserState.StartScope = Op;
447 WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
448 WalkState->AscendingCallback = AcpiDsLoad1EndOp;
450 /* Perform the AML parse */
452 Status = AcpiPsParseAml (WalkState);
454 BaseAmlOffset = (Method->Common.Value.Arg)->Common.AmlOffset + 1;
455 StartOp = (Method->Common.Value.Arg)->Common.Next;
460 SearchOp->Common.AmlOffset += BaseAmlOffset;
461 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
465 if (Op->Common.AmlOpcode == AML_REGION_OP)
467 /* TBD: [Investigate] this isn't quite the right thing to do! */
470 * Method = (ACPI_DEFERRED_OP *) Op;
471 * Status = AcpiPsParseAml (Op, Method->Body, Method->BodyLength);
475 if (ACPI_FAILURE (Status))
480 Op = AcpiPsGetDepthNext (Root, Op);
487 /*******************************************************************************
489 * FUNCTION: AcpiDbDumpBuffer
491 * PARAMETERS: Address - Pointer to the buffer
495 * DESCRIPTION: Print a portion of a buffer
497 ******************************************************************************/
504 AcpiOsPrintf ("\nLocation %X:\n", Address);
506 AcpiDbgLevel |= ACPI_LV_TABLES;
507 AcpiUtDebugDumpBuffer (ACPI_TO_POINTER (Address), 64, DB_BYTE_DISPLAY,
512 #endif /* ACPI_DEBUGGER */