Update ACPICA to 20150818.
[haiku.git] / src / add-ons / kernel / bus_managers / acpi / acpica / components / executer / exdebug.c
blob00ec43f46353380d138ad0e1da08ceda17366f35
1 /******************************************************************************
3 * Module Name: exdebug - Support for stores to the AML Debug Object
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #include "acpi.h"
117 #include "accommon.h"
118 #include "acnamesp.h"
119 #include "acinterp.h"
120 #include "acparser.h"
123 #define _COMPONENT ACPI_EXECUTER
124 ACPI_MODULE_NAME ("exdebug")
127 static ACPI_OPERAND_OBJECT *AcpiGbl_TraceMethodObject = NULL;
129 /* Local prototypes */
131 #ifdef ACPI_DEBUG_OUTPUT
132 static const char *
133 AcpiExGetTraceEventName (
134 ACPI_TRACE_EVENT_TYPE Type);
135 #endif
138 #ifndef ACPI_NO_ERROR_MESSAGES
139 /*******************************************************************************
141 * FUNCTION: AcpiExDoDebugObject
143 * PARAMETERS: SourceDesc - Object to be output to "Debug Object"
144 * Level - Indentation level (used for packages)
145 * Index - Current package element, zero if not pkg
147 * RETURN: None
149 * DESCRIPTION: Handles stores to the AML Debug Object. For example:
150 * Store(INT1, Debug)
152 * This function is not compiled if ACPI_NO_ERROR_MESSAGES is set.
154 * This function is only enabled if AcpiGbl_EnableAmlDebugObject is set, or
155 * if ACPI_LV_DEBUG_OBJECT is set in the AcpiDbgLevel. Thus, in the normal
156 * operational case, stores to the debug object are ignored but can be easily
157 * enabled if necessary.
159 ******************************************************************************/
161 void
162 AcpiExDoDebugObject (
163 ACPI_OPERAND_OBJECT *SourceDesc,
164 UINT32 Level,
165 UINT32 Index)
167 UINT32 i;
168 UINT32 Timer;
169 ACPI_OPERAND_OBJECT *ObjectDesc;
170 UINT32 Value;
173 ACPI_FUNCTION_TRACE_PTR (ExDoDebugObject, SourceDesc);
176 /* Output must be enabled via the DebugObject global or the DbgLevel */
178 if (!AcpiGbl_EnableAmlDebugObject &&
179 !(AcpiDbgLevel & ACPI_LV_DEBUG_OBJECT))
181 return_VOID;
185 * We will emit the current timer value (in microseconds) with each
186 * debug output. Only need the lower 26 bits. This allows for 67
187 * million microseconds or 67 seconds before rollover.
189 Timer = ((UINT32) AcpiOsGetTimer () / 10); /* (100 nanoseconds to microseconds) */
190 Timer &= 0x03FFFFFF;
193 * Print line header as long as we are not in the middle of an
194 * object display
196 if (!((Level > 0) && Index == 0))
198 AcpiOsPrintf ("[ACPI Debug %.8u] %*s", Timer, Level, " ");
201 /* Display the index for package output only */
203 if (Index > 0)
205 AcpiOsPrintf ("(%.2u) ", Index-1);
208 if (!SourceDesc)
210 AcpiOsPrintf ("[Null Object]\n");
211 return_VOID;
214 if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND)
216 AcpiOsPrintf ("%s ", AcpiUtGetObjectTypeName (SourceDesc));
218 if (!AcpiUtValidInternalObject (SourceDesc))
220 AcpiOsPrintf ("%p, Invalid Internal Object!\n", SourceDesc);
221 return_VOID;
224 else if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
226 AcpiOsPrintf ("%s: %p\n",
227 AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) SourceDesc)->Type),
228 SourceDesc);
229 return_VOID;
231 else
233 return_VOID;
236 /* SourceDesc is of type ACPI_DESC_TYPE_OPERAND */
238 switch (SourceDesc->Common.Type)
240 case ACPI_TYPE_INTEGER:
242 /* Output correct integer width */
244 if (AcpiGbl_IntegerByteWidth == 4)
246 AcpiOsPrintf ("0x%8.8X\n",
247 (UINT32) SourceDesc->Integer.Value);
249 else
251 AcpiOsPrintf ("0x%8.8X%8.8X\n",
252 ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value));
254 break;
256 case ACPI_TYPE_BUFFER:
258 AcpiOsPrintf ("[0x%.2X]\n", (UINT32) SourceDesc->Buffer.Length);
259 AcpiUtDumpBuffer (SourceDesc->Buffer.Pointer,
260 (SourceDesc->Buffer.Length < 256) ?
261 SourceDesc->Buffer.Length : 256, DB_BYTE_DISPLAY, 0);
262 break;
264 case ACPI_TYPE_STRING:
266 AcpiOsPrintf ("[0x%.2X] \"%s\"\n",
267 SourceDesc->String.Length, SourceDesc->String.Pointer);
268 break;
270 case ACPI_TYPE_PACKAGE:
272 AcpiOsPrintf ("[Contains 0x%.2X Elements]\n",
273 SourceDesc->Package.Count);
275 /* Output the entire contents of the package */
277 for (i = 0; i < SourceDesc->Package.Count; i++)
279 AcpiExDoDebugObject (SourceDesc->Package.Elements[i],
280 Level+4, i+1);
282 break;
284 case ACPI_TYPE_LOCAL_REFERENCE:
286 AcpiOsPrintf ("[%s] ", AcpiUtGetReferenceName (SourceDesc));
288 /* Decode the reference */
290 switch (SourceDesc->Reference.Class)
292 case ACPI_REFCLASS_INDEX:
294 AcpiOsPrintf ("0x%X\n", SourceDesc->Reference.Value);
295 break;
297 case ACPI_REFCLASS_TABLE:
299 /* Case for DdbHandle */
301 AcpiOsPrintf ("Table Index 0x%X\n", SourceDesc->Reference.Value);
302 return_VOID;
304 default:
306 break;
309 AcpiOsPrintf (" ");
311 /* Check for valid node first, then valid object */
313 if (SourceDesc->Reference.Node)
315 if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Node) !=
316 ACPI_DESC_TYPE_NAMED)
318 AcpiOsPrintf (" %p - Not a valid namespace node\n",
319 SourceDesc->Reference.Node);
321 else
323 AcpiOsPrintf ("Node %p [%4.4s] ", SourceDesc->Reference.Node,
324 (SourceDesc->Reference.Node)->Name.Ascii);
326 switch ((SourceDesc->Reference.Node)->Type)
328 /* These types have no attached object */
330 case ACPI_TYPE_DEVICE:
331 AcpiOsPrintf ("Device\n");
332 break;
334 case ACPI_TYPE_THERMAL:
335 AcpiOsPrintf ("Thermal Zone\n");
336 break;
338 default:
340 AcpiExDoDebugObject ((SourceDesc->Reference.Node)->Object,
341 Level+4, 0);
342 break;
346 else if (SourceDesc->Reference.Object)
348 if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Object) ==
349 ACPI_DESC_TYPE_NAMED)
351 AcpiExDoDebugObject (((ACPI_NAMESPACE_NODE *)
352 SourceDesc->Reference.Object)->Object,
353 Level+4, 0);
355 else
357 ObjectDesc = SourceDesc->Reference.Object;
358 Value = SourceDesc->Reference.Value;
360 switch (ObjectDesc->Common.Type)
362 case ACPI_TYPE_BUFFER:
364 AcpiOsPrintf ("Buffer[%u] = 0x%2.2X\n",
365 Value, *SourceDesc->Reference.IndexPointer);
366 break;
368 case ACPI_TYPE_STRING:
370 AcpiOsPrintf ("String[%u] = \"%c\" (0x%2.2X)\n",
371 Value, *SourceDesc->Reference.IndexPointer,
372 *SourceDesc->Reference.IndexPointer);
373 break;
375 case ACPI_TYPE_PACKAGE:
377 AcpiOsPrintf ("Package[%u] = ", Value);
378 AcpiExDoDebugObject (*SourceDesc->Reference.Where,
379 Level+4, 0);
380 break;
382 default:
384 AcpiOsPrintf ("Unknown Reference object type %X\n",
385 ObjectDesc->Common.Type);
386 break;
390 break;
392 default:
394 AcpiOsPrintf ("%p\n", SourceDesc);
395 break;
398 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
399 return_VOID;
401 #endif
404 /*******************************************************************************
406 * FUNCTION: AcpiExInterpreterTraceEnabled
408 * PARAMETERS: Name - Whether method name should be matched,
409 * this should be checked before starting
410 * the tracer
412 * RETURN: TRUE if interpreter trace is enabled.
414 * DESCRIPTION: Check whether interpreter trace is enabled
416 ******************************************************************************/
418 static BOOLEAN
419 AcpiExInterpreterTraceEnabled (
420 char *Name)
423 /* Check if tracing is enabled */
425 if (!(AcpiGbl_TraceFlags & ACPI_TRACE_ENABLED))
427 return (FALSE);
431 * Check if tracing is filtered:
433 * 1. If the tracer is started, AcpiGbl_TraceMethodObject should have
434 * been filled by the trace starter
435 * 2. If the tracer is not started, AcpiGbl_TraceMethodName should be
436 * matched if it is specified
437 * 3. If the tracer is oneshot style, AcpiGbl_TraceMethodName should
438 * not be cleared by the trace stopper during the first match
440 if (AcpiGbl_TraceMethodObject)
442 return (TRUE);
444 if (Name &&
445 (AcpiGbl_TraceMethodName &&
446 strcmp (AcpiGbl_TraceMethodName, Name)))
448 return (FALSE);
450 if ((AcpiGbl_TraceFlags & ACPI_TRACE_ONESHOT) &&
451 !AcpiGbl_TraceMethodName)
453 return (FALSE);
456 return (TRUE);
460 /*******************************************************************************
462 * FUNCTION: AcpiExGetTraceEventName
464 * PARAMETERS: Type - Trace event type
466 * RETURN: Trace event name.
468 * DESCRIPTION: Used to obtain the full trace event name.
470 ******************************************************************************/
472 #ifdef ACPI_DEBUG_OUTPUT
474 static const char *
475 AcpiExGetTraceEventName (
476 ACPI_TRACE_EVENT_TYPE Type)
478 switch (Type)
480 case ACPI_TRACE_AML_METHOD:
482 return "Method";
484 case ACPI_TRACE_AML_OPCODE:
486 return "Opcode";
488 case ACPI_TRACE_AML_REGION:
490 return "Region";
492 default:
494 return "";
498 #endif
501 /*******************************************************************************
503 * FUNCTION: AcpiExTracePoint
505 * PARAMETERS: Type - Trace event type
506 * Begin - TRUE if before execution
507 * Aml - Executed AML address
508 * Pathname - Object path
510 * RETURN: None
512 * DESCRIPTION: Internal interpreter execution trace.
514 ******************************************************************************/
516 void
517 AcpiExTracePoint (
518 ACPI_TRACE_EVENT_TYPE Type,
519 BOOLEAN Begin,
520 UINT8 *Aml,
521 char *Pathname)
524 ACPI_FUNCTION_NAME (ExTracePoint);
527 if (Pathname)
529 ACPI_DEBUG_PRINT ((ACPI_DB_TRACE_POINT,
530 "%s %s [0x%p:%s] execution.\n",
531 AcpiExGetTraceEventName (Type), Begin ? "Begin" : "End",
532 Aml, Pathname));
534 else
536 ACPI_DEBUG_PRINT ((ACPI_DB_TRACE_POINT,
537 "%s %s [0x%p] execution.\n",
538 AcpiExGetTraceEventName (Type), Begin ? "Begin" : "End",
539 Aml));
544 /*******************************************************************************
546 * FUNCTION: AcpiExStartTraceMethod
548 * PARAMETERS: MethodNode - Node of the method
549 * ObjDesc - The method object
550 * WalkState - current state, NULL if not yet executing
551 * a method.
553 * RETURN: None
555 * DESCRIPTION: Start control method execution trace
557 ******************************************************************************/
559 void
560 AcpiExStartTraceMethod (
561 ACPI_NAMESPACE_NODE *MethodNode,
562 ACPI_OPERAND_OBJECT *ObjDesc,
563 ACPI_WALK_STATE *WalkState)
565 ACPI_STATUS Status;
566 char *Pathname = NULL;
567 BOOLEAN Enabled = FALSE;
570 ACPI_FUNCTION_NAME (ExStartTraceMethod);
573 if (MethodNode)
575 Pathname = AcpiNsGetNormalizedPathname (MethodNode, TRUE);
578 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
579 if (ACPI_FAILURE (Status))
581 goto Exit;
584 Enabled = AcpiExInterpreterTraceEnabled (Pathname);
585 if (Enabled && !AcpiGbl_TraceMethodObject)
587 AcpiGbl_TraceMethodObject = ObjDesc;
588 AcpiGbl_OriginalDbgLevel = AcpiDbgLevel;
589 AcpiGbl_OriginalDbgLayer = AcpiDbgLayer;
590 AcpiDbgLevel = ACPI_TRACE_LEVEL_ALL;
591 AcpiDbgLayer = ACPI_TRACE_LAYER_ALL;
593 if (AcpiGbl_TraceDbgLevel)
595 AcpiDbgLevel = AcpiGbl_TraceDbgLevel;
597 if (AcpiGbl_TraceDbgLayer)
599 AcpiDbgLayer = AcpiGbl_TraceDbgLayer;
602 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
604 Exit:
605 if (Enabled)
607 ACPI_TRACE_POINT (ACPI_TRACE_AML_METHOD, TRUE,
608 ObjDesc ? ObjDesc->Method.AmlStart : NULL, Pathname);
610 if (Pathname)
612 ACPI_FREE (Pathname);
617 /*******************************************************************************
619 * FUNCTION: AcpiExStopTraceMethod
621 * PARAMETERS: MethodNode - Node of the method
622 * ObjDesc - The method object
623 * WalkState - current state, NULL if not yet executing
624 * a method.
626 * RETURN: None
628 * DESCRIPTION: Stop control method execution trace
630 ******************************************************************************/
632 void
633 AcpiExStopTraceMethod (
634 ACPI_NAMESPACE_NODE *MethodNode,
635 ACPI_OPERAND_OBJECT *ObjDesc,
636 ACPI_WALK_STATE *WalkState)
638 ACPI_STATUS Status;
639 char *Pathname = NULL;
640 BOOLEAN Enabled;
643 ACPI_FUNCTION_NAME (ExStopTraceMethod);
646 if (MethodNode)
648 Pathname = AcpiNsGetNormalizedPathname (MethodNode, TRUE);
651 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
652 if (ACPI_FAILURE (Status))
654 goto ExitPath;
657 Enabled = AcpiExInterpreterTraceEnabled (NULL);
659 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
661 if (Enabled)
663 ACPI_TRACE_POINT (ACPI_TRACE_AML_METHOD, FALSE,
664 ObjDesc ? ObjDesc->Method.AmlStart : NULL, Pathname);
667 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
668 if (ACPI_FAILURE (Status))
670 goto ExitPath;
673 /* Check whether the tracer should be stopped */
675 if (AcpiGbl_TraceMethodObject == ObjDesc)
677 /* Disable further tracing if type is one-shot */
679 if (AcpiGbl_TraceFlags & ACPI_TRACE_ONESHOT)
681 AcpiGbl_TraceMethodName = NULL;
684 AcpiDbgLevel = AcpiGbl_OriginalDbgLevel;
685 AcpiDbgLayer = AcpiGbl_OriginalDbgLayer;
686 AcpiGbl_TraceMethodObject = NULL;
689 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
691 ExitPath:
692 if (Pathname)
694 ACPI_FREE (Pathname);
699 /*******************************************************************************
701 * FUNCTION: AcpiExStartTraceOpcode
703 * PARAMETERS: Op - The parser opcode object
704 * WalkState - current state, NULL if not yet executing
705 * a method.
707 * RETURN: None
709 * DESCRIPTION: Start opcode execution trace
711 ******************************************************************************/
713 void
714 AcpiExStartTraceOpcode (
715 ACPI_PARSE_OBJECT *Op,
716 ACPI_WALK_STATE *WalkState)
719 ACPI_FUNCTION_NAME (ExStartTraceOpcode);
722 if (AcpiExInterpreterTraceEnabled (NULL) &&
723 (AcpiGbl_TraceFlags & ACPI_TRACE_OPCODE))
725 ACPI_TRACE_POINT (ACPI_TRACE_AML_OPCODE, TRUE,
726 Op->Common.Aml, Op->Common.AmlOpName);
731 /*******************************************************************************
733 * FUNCTION: AcpiExStopTraceOpcode
735 * PARAMETERS: Op - The parser opcode object
736 * WalkState - current state, NULL if not yet executing
737 * a method.
739 * RETURN: None
741 * DESCRIPTION: Stop opcode execution trace
743 ******************************************************************************/
745 void
746 AcpiExStopTraceOpcode (
747 ACPI_PARSE_OBJECT *Op,
748 ACPI_WALK_STATE *WalkState)
751 ACPI_FUNCTION_NAME (ExStopTraceOpcode);
754 if (AcpiExInterpreterTraceEnabled (NULL) &&
755 (AcpiGbl_TraceFlags & ACPI_TRACE_OPCODE))
757 ACPI_TRACE_POINT (ACPI_TRACE_AML_OPCODE, FALSE,
758 Op->Common.Aml, Op->Common.AmlOpName);