dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / uts / intel / io / acpica / executer / extrace.c
blob6f8a707ae417f81046b773e467aad482eb97bc66
1 /******************************************************************************
3 * Module Name: extrace - Support for interpreter execution tracing
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 "acpi.h"
45 #include "accommon.h"
46 #include "acnamesp.h"
47 #include "acinterp.h"
50 #define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME ("extrace")
54 static ACPI_OPERAND_OBJECT *AcpiGbl_TraceMethodObject = NULL;
56 /* Local prototypes */
58 #ifdef ACPI_DEBUG_OUTPUT
59 static const char *
60 AcpiExGetTraceEventName (
61 ACPI_TRACE_EVENT_TYPE Type);
62 #endif
65 /*******************************************************************************
67 * FUNCTION: AcpiExInterpreterTraceEnabled
69 * PARAMETERS: Name - Whether method name should be matched,
70 * this should be checked before starting
71 * the tracer
73 * RETURN: TRUE if interpreter trace is enabled.
75 * DESCRIPTION: Check whether interpreter trace is enabled
77 ******************************************************************************/
79 static BOOLEAN
80 AcpiExInterpreterTraceEnabled (
81 char *Name)
84 /* Check if tracing is enabled */
86 if (!(AcpiGbl_TraceFlags & ACPI_TRACE_ENABLED))
88 return (FALSE);
92 * Check if tracing is filtered:
94 * 1. If the tracer is started, AcpiGbl_TraceMethodObject should have
95 * been filled by the trace starter
96 * 2. If the tracer is not started, AcpiGbl_TraceMethodName should be
97 * matched if it is specified
98 * 3. If the tracer is oneshot style, AcpiGbl_TraceMethodName should
99 * not be cleared by the trace stopper during the first match
101 if (AcpiGbl_TraceMethodObject)
103 return (TRUE);
106 if (Name &&
107 (AcpiGbl_TraceMethodName &&
108 strcmp (AcpiGbl_TraceMethodName, Name)))
110 return (FALSE);
113 if ((AcpiGbl_TraceFlags & ACPI_TRACE_ONESHOT) &&
114 !AcpiGbl_TraceMethodName)
116 return (FALSE);
119 return (TRUE);
123 /*******************************************************************************
125 * FUNCTION: AcpiExGetTraceEventName
127 * PARAMETERS: Type - Trace event type
129 * RETURN: Trace event name.
131 * DESCRIPTION: Used to obtain the full trace event name.
133 ******************************************************************************/
135 #ifdef ACPI_DEBUG_OUTPUT
137 static const char *
138 AcpiExGetTraceEventName (
139 ACPI_TRACE_EVENT_TYPE Type)
142 switch (Type)
144 case ACPI_TRACE_AML_METHOD:
146 return "Method";
148 case ACPI_TRACE_AML_OPCODE:
150 return "Opcode";
152 case ACPI_TRACE_AML_REGION:
154 return "Region";
156 default:
158 return "";
162 #endif
165 /*******************************************************************************
167 * FUNCTION: AcpiExTracePoint
169 * PARAMETERS: Type - Trace event type
170 * Begin - TRUE if before execution
171 * Aml - Executed AML address
172 * Pathname - Object path
174 * RETURN: None
176 * DESCRIPTION: Internal interpreter execution trace.
178 ******************************************************************************/
180 void
181 AcpiExTracePoint (
182 ACPI_TRACE_EVENT_TYPE Type,
183 BOOLEAN Begin,
184 UINT8 *Aml,
185 char *Pathname)
188 ACPI_FUNCTION_NAME (ExTracePoint);
191 if (Pathname)
193 ACPI_DEBUG_PRINT ((ACPI_DB_TRACE_POINT,
194 "%s %s [0x%p:%s] execution.\n",
195 AcpiExGetTraceEventName (Type), Begin ? "Begin" : "End",
196 Aml, Pathname));
198 else
200 ACPI_DEBUG_PRINT ((ACPI_DB_TRACE_POINT,
201 "%s %s [0x%p] execution.\n",
202 AcpiExGetTraceEventName (Type), Begin ? "Begin" : "End",
203 Aml));
208 /*******************************************************************************
210 * FUNCTION: AcpiExStartTraceMethod
212 * PARAMETERS: MethodNode - Node of the method
213 * ObjDesc - The method object
214 * WalkState - current state, NULL if not yet executing
215 * a method.
217 * RETURN: None
219 * DESCRIPTION: Start control method execution trace
221 ******************************************************************************/
223 void
224 AcpiExStartTraceMethod (
225 ACPI_NAMESPACE_NODE *MethodNode,
226 ACPI_OPERAND_OBJECT *ObjDesc,
227 ACPI_WALK_STATE *WalkState)
229 ACPI_STATUS Status;
230 char *Pathname = NULL;
231 BOOLEAN Enabled = FALSE;
234 ACPI_FUNCTION_NAME (ExStartTraceMethod);
237 if (MethodNode)
239 Pathname = AcpiNsGetNormalizedPathname (MethodNode, TRUE);
242 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
243 if (ACPI_FAILURE (Status))
245 goto Exit;
248 Enabled = AcpiExInterpreterTraceEnabled (Pathname);
249 if (Enabled && !AcpiGbl_TraceMethodObject)
251 AcpiGbl_TraceMethodObject = ObjDesc;
252 AcpiGbl_OriginalDbgLevel = AcpiDbgLevel;
253 AcpiGbl_OriginalDbgLayer = AcpiDbgLayer;
254 AcpiDbgLevel = ACPI_TRACE_LEVEL_ALL;
255 AcpiDbgLayer = ACPI_TRACE_LAYER_ALL;
257 if (AcpiGbl_TraceDbgLevel)
259 AcpiDbgLevel = AcpiGbl_TraceDbgLevel;
262 if (AcpiGbl_TraceDbgLayer)
264 AcpiDbgLayer = AcpiGbl_TraceDbgLayer;
268 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
270 Exit:
271 if (Enabled)
273 ACPI_TRACE_POINT (ACPI_TRACE_AML_METHOD, TRUE,
274 ObjDesc ? ObjDesc->Method.AmlStart : NULL, Pathname);
277 if (Pathname)
279 ACPI_FREE (Pathname);
284 /*******************************************************************************
286 * FUNCTION: AcpiExStopTraceMethod
288 * PARAMETERS: MethodNode - Node of the method
289 * ObjDesc - The method object
290 * WalkState - current state, NULL if not yet executing
291 * a method.
293 * RETURN: None
295 * DESCRIPTION: Stop control method execution trace
297 ******************************************************************************/
299 void
300 AcpiExStopTraceMethod (
301 ACPI_NAMESPACE_NODE *MethodNode,
302 ACPI_OPERAND_OBJECT *ObjDesc,
303 ACPI_WALK_STATE *WalkState)
305 ACPI_STATUS Status;
306 char *Pathname = NULL;
307 BOOLEAN Enabled;
310 ACPI_FUNCTION_NAME (ExStopTraceMethod);
313 if (MethodNode)
315 Pathname = AcpiNsGetNormalizedPathname (MethodNode, TRUE);
318 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
319 if (ACPI_FAILURE (Status))
321 goto ExitPath;
324 Enabled = AcpiExInterpreterTraceEnabled (NULL);
326 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
328 if (Enabled)
330 ACPI_TRACE_POINT (ACPI_TRACE_AML_METHOD, FALSE,
331 ObjDesc ? ObjDesc->Method.AmlStart : NULL, Pathname);
334 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
335 if (ACPI_FAILURE (Status))
337 goto ExitPath;
340 /* Check whether the tracer should be stopped */
342 if (AcpiGbl_TraceMethodObject == ObjDesc)
344 /* Disable further tracing if type is one-shot */
346 if (AcpiGbl_TraceFlags & ACPI_TRACE_ONESHOT)
348 AcpiGbl_TraceMethodName = NULL;
351 AcpiDbgLevel = AcpiGbl_OriginalDbgLevel;
352 AcpiDbgLayer = AcpiGbl_OriginalDbgLayer;
353 AcpiGbl_TraceMethodObject = NULL;
356 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
358 ExitPath:
359 if (Pathname)
361 ACPI_FREE (Pathname);
366 /*******************************************************************************
368 * FUNCTION: AcpiExStartTraceOpcode
370 * PARAMETERS: Op - The parser opcode object
371 * WalkState - current state, NULL if not yet executing
372 * a method.
374 * RETURN: None
376 * DESCRIPTION: Start opcode execution trace
378 ******************************************************************************/
380 void
381 AcpiExStartTraceOpcode (
382 ACPI_PARSE_OBJECT *Op,
383 ACPI_WALK_STATE *WalkState)
386 ACPI_FUNCTION_NAME (ExStartTraceOpcode);
389 if (AcpiExInterpreterTraceEnabled (NULL) &&
390 (AcpiGbl_TraceFlags & ACPI_TRACE_OPCODE))
392 ACPI_TRACE_POINT (ACPI_TRACE_AML_OPCODE, TRUE,
393 Op->Common.Aml, Op->Common.AmlOpName);
398 /*******************************************************************************
400 * FUNCTION: AcpiExStopTraceOpcode
402 * PARAMETERS: Op - The parser opcode object
403 * WalkState - current state, NULL if not yet executing
404 * a method.
406 * RETURN: None
408 * DESCRIPTION: Stop opcode execution trace
410 ******************************************************************************/
412 void
413 AcpiExStopTraceOpcode (
414 ACPI_PARSE_OBJECT *Op,
415 ACPI_WALK_STATE *WalkState)
418 ACPI_FUNCTION_NAME (ExStopTraceOpcode);
421 if (AcpiExInterpreterTraceEnabled (NULL) &&
422 (AcpiGbl_TraceFlags & ACPI_TRACE_OPCODE))
424 ACPI_TRACE_POINT (ACPI_TRACE_AML_OPCODE, FALSE,
425 Op->Common.Aml, Op->Common.AmlOpName);