dbexec.c revision 1.3.2.2 1 1.3.2.2 bouyer /*******************************************************************************
2 1.3.2.2 bouyer *
3 1.3.2.2 bouyer * Module Name: dbexec - debugger control method execution
4 1.3.2.2 bouyer *
5 1.3.2.2 bouyer ******************************************************************************/
6 1.3.2.2 bouyer
7 1.3.2.2 bouyer /*
8 1.3.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.3.2.2 bouyer * All rights reserved.
10 1.3.2.2 bouyer *
11 1.3.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.3.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.3.2.2 bouyer * are met:
14 1.3.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.3.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.3.2.2 bouyer * without modification.
17 1.3.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.3.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.3.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.3.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.3.2.2 bouyer * binary redistribution.
22 1.3.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.3.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.3.2.2 bouyer * from this software without specific prior written permission.
25 1.3.2.2 bouyer *
26 1.3.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.3.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.3.2.2 bouyer * Software Foundation.
29 1.3.2.2 bouyer *
30 1.3.2.2 bouyer * NO WARRANTY
31 1.3.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.3.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.3.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.3.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.3.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.3.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.3.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.3.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.3.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.3.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.3.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.3.2.2 bouyer */
43 1.3.2.2 bouyer
44 1.3.2.2 bouyer
45 1.3.2.2 bouyer #include "acpi.h"
46 1.3.2.2 bouyer #include "accommon.h"
47 1.3.2.2 bouyer #include "acdebug.h"
48 1.3.2.2 bouyer #include "acnamesp.h"
49 1.3.2.2 bouyer
50 1.3.2.2 bouyer #ifdef ACPI_DEBUGGER
51 1.3.2.2 bouyer
52 1.3.2.2 bouyer #define _COMPONENT ACPI_CA_DEBUGGER
53 1.3.2.2 bouyer ACPI_MODULE_NAME ("dbexec")
54 1.3.2.2 bouyer
55 1.3.2.2 bouyer
56 1.3.2.2 bouyer static ACPI_DB_METHOD_INFO AcpiGbl_DbMethodInfo;
57 1.3.2.2 bouyer
58 1.3.2.2 bouyer /* Local prototypes */
59 1.3.2.2 bouyer
60 1.3.2.2 bouyer static ACPI_STATUS
61 1.3.2.2 bouyer AcpiDbExecuteMethod (
62 1.3.2.2 bouyer ACPI_DB_METHOD_INFO *Info,
63 1.3.2.2 bouyer ACPI_BUFFER *ReturnObj);
64 1.3.2.2 bouyer
65 1.3.2.2 bouyer static void
66 1.3.2.2 bouyer AcpiDbExecuteSetup (
67 1.3.2.2 bouyer ACPI_DB_METHOD_INFO *Info);
68 1.3.2.2 bouyer
69 1.3.2.2 bouyer static UINT32
70 1.3.2.2 bouyer AcpiDbGetOutstandingAllocations (
71 1.3.2.2 bouyer void);
72 1.3.2.2 bouyer
73 1.3.2.2 bouyer static void ACPI_SYSTEM_XFACE
74 1.3.2.2 bouyer AcpiDbMethodThread (
75 1.3.2.2 bouyer void *Context);
76 1.3.2.2 bouyer
77 1.3.2.2 bouyer static ACPI_STATUS
78 1.3.2.2 bouyer AcpiDbExecutionWalk (
79 1.3.2.2 bouyer ACPI_HANDLE ObjHandle,
80 1.3.2.2 bouyer UINT32 NestingLevel,
81 1.3.2.2 bouyer void *Context,
82 1.3.2.2 bouyer void **ReturnValue);
83 1.3.2.2 bouyer
84 1.3.2.2 bouyer
85 1.3.2.2 bouyer /*******************************************************************************
86 1.3.2.2 bouyer *
87 1.3.2.2 bouyer * FUNCTION: AcpiDbExecuteMethod
88 1.3.2.2 bouyer *
89 1.3.2.2 bouyer * PARAMETERS: Info - Valid info segment
90 1.3.2.2 bouyer * ReturnObj - Where to put return object
91 1.3.2.2 bouyer *
92 1.3.2.2 bouyer * RETURN: Status
93 1.3.2.2 bouyer *
94 1.3.2.2 bouyer * DESCRIPTION: Execute a control method.
95 1.3.2.2 bouyer *
96 1.3.2.2 bouyer ******************************************************************************/
97 1.3.2.2 bouyer
98 1.3.2.2 bouyer static ACPI_STATUS
99 1.3.2.2 bouyer AcpiDbExecuteMethod (
100 1.3.2.2 bouyer ACPI_DB_METHOD_INFO *Info,
101 1.3.2.2 bouyer ACPI_BUFFER *ReturnObj)
102 1.3.2.2 bouyer {
103 1.3.2.2 bouyer ACPI_STATUS Status;
104 1.3.2.2 bouyer ACPI_OBJECT_LIST ParamObjects;
105 1.3.2.2 bouyer ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];
106 1.3.2.2 bouyer ACPI_HANDLE Handle;
107 1.3.2.2 bouyer UINT32 i;
108 1.3.2.2 bouyer ACPI_DEVICE_INFO *ObjInfo;
109 1.3.2.2 bouyer
110 1.3.2.2 bouyer
111 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (DbExecuteMethod);
112 1.3.2.2 bouyer
113 1.3.2.2 bouyer
114 1.3.2.2 bouyer if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel)
115 1.3.2.2 bouyer {
116 1.3.2.2 bouyer AcpiOsPrintf ("Warning: debug output is not enabled!\n");
117 1.3.2.2 bouyer }
118 1.3.2.2 bouyer
119 1.3.2.2 bouyer /* Get the NS node, determines existence also */
120 1.3.2.2 bouyer
121 1.3.2.2 bouyer Status = AcpiGetHandle (NULL, Info->Pathname, &Handle);
122 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
123 1.3.2.2 bouyer {
124 1.3.2.2 bouyer return_ACPI_STATUS (Status);
125 1.3.2.2 bouyer }
126 1.3.2.2 bouyer
127 1.3.2.2 bouyer /* Get the object info for number of method parameters */
128 1.3.2.2 bouyer
129 1.3.2.2 bouyer Status = AcpiGetObjectInfo (Handle, &ObjInfo);
130 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
131 1.3.2.2 bouyer {
132 1.3.2.2 bouyer return_ACPI_STATUS (Status);
133 1.3.2.2 bouyer }
134 1.3.2.2 bouyer
135 1.3.2.2 bouyer ParamObjects.Pointer = NULL;
136 1.3.2.2 bouyer ParamObjects.Count = 0;
137 1.3.2.2 bouyer
138 1.3.2.2 bouyer if (ObjInfo->Type == ACPI_TYPE_METHOD)
139 1.3.2.2 bouyer {
140 1.3.2.2 bouyer /* Are there arguments to the method? */
141 1.3.2.2 bouyer
142 1.3.2.2 bouyer if (Info->Args && Info->Args[0])
143 1.3.2.2 bouyer {
144 1.3.2.2 bouyer for (i = 0; Info->Args[i] &&
145 1.3.2.2 bouyer (i < ACPI_METHOD_NUM_ARGS) &&
146 1.3.2.2 bouyer (i < ObjInfo->ParamCount);
147 1.3.2.2 bouyer i++)
148 1.3.2.2 bouyer {
149 1.3.2.2 bouyer Params[i].Type = ACPI_TYPE_INTEGER;
150 1.3.2.2 bouyer Params[i].Integer.Value = ACPI_STRTOUL (Info->Args[i], NULL, 16);
151 1.3.2.2 bouyer }
152 1.3.2.2 bouyer
153 1.3.2.2 bouyer ParamObjects.Pointer = Params;
154 1.3.2.2 bouyer ParamObjects.Count = i;
155 1.3.2.2 bouyer }
156 1.3.2.2 bouyer else
157 1.3.2.2 bouyer {
158 1.3.2.2 bouyer /* Setup default parameters */
159 1.3.2.2 bouyer
160 1.3.2.2 bouyer for (i = 0; i < ObjInfo->ParamCount; i++)
161 1.3.2.2 bouyer {
162 1.3.2.2 bouyer switch (i)
163 1.3.2.2 bouyer {
164 1.3.2.2 bouyer case 0:
165 1.3.2.2 bouyer
166 1.3.2.2 bouyer Params[0].Type = ACPI_TYPE_INTEGER;
167 1.3.2.2 bouyer Params[0].Integer.Value = 0x01020304;
168 1.3.2.2 bouyer break;
169 1.3.2.2 bouyer
170 1.3.2.2 bouyer case 1:
171 1.3.2.2 bouyer
172 1.3.2.2 bouyer Params[1].Type = ACPI_TYPE_STRING;
173 1.3.2.2 bouyer Params[1].String.Length = 12;
174 1.3.2.2 bouyer Params[1].String.Pointer = __UNCONST("AML Debugger");
175 1.3.2.2 bouyer break;
176 1.3.2.2 bouyer
177 1.3.2.2 bouyer default:
178 1.3.2.2 bouyer
179 1.3.2.2 bouyer Params[i].Type = ACPI_TYPE_INTEGER;
180 1.3.2.2 bouyer Params[i].Integer.Value = i * (UINT64) 0x1000;
181 1.3.2.2 bouyer break;
182 1.3.2.2 bouyer }
183 1.3.2.2 bouyer }
184 1.3.2.2 bouyer
185 1.3.2.2 bouyer ParamObjects.Pointer = Params;
186 1.3.2.2 bouyer ParamObjects.Count = ObjInfo->ParamCount;
187 1.3.2.2 bouyer }
188 1.3.2.2 bouyer }
189 1.3.2.2 bouyer
190 1.3.2.2 bouyer ACPI_FREE (ObjInfo);
191 1.3.2.2 bouyer
192 1.3.2.2 bouyer /* Prepare for a return object of arbitrary size */
193 1.3.2.2 bouyer
194 1.3.2.2 bouyer ReturnObj->Pointer = AcpiGbl_DbBuffer;
195 1.3.2.2 bouyer ReturnObj->Length = ACPI_DEBUG_BUFFER_SIZE;
196 1.3.2.2 bouyer
197 1.3.2.2 bouyer /* Do the actual method execution */
198 1.3.2.2 bouyer
199 1.3.2.2 bouyer AcpiGbl_MethodExecuting = TRUE;
200 1.3.2.2 bouyer Status = AcpiEvaluateObject (NULL,
201 1.3.2.2 bouyer Info->Pathname, &ParamObjects, ReturnObj);
202 1.3.2.2 bouyer
203 1.3.2.2 bouyer AcpiGbl_CmSingleStep = FALSE;
204 1.3.2.2 bouyer AcpiGbl_MethodExecuting = FALSE;
205 1.3.2.2 bouyer
206 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
207 1.3.2.2 bouyer {
208 1.3.2.2 bouyer ACPI_EXCEPTION ((AE_INFO, Status,
209 1.3.2.2 bouyer "while executing %s from debugger", Info->Pathname));
210 1.3.2.2 bouyer
211 1.3.2.2 bouyer if (Status == AE_BUFFER_OVERFLOW)
212 1.3.2.2 bouyer {
213 1.3.2.2 bouyer ACPI_ERROR ((AE_INFO,
214 1.3.2.2 bouyer "Possible overflow of internal debugger buffer (size 0x%X needed 0x%X)",
215 1.3.2.2 bouyer ACPI_DEBUG_BUFFER_SIZE, (UINT32) ReturnObj->Length));
216 1.3.2.2 bouyer }
217 1.3.2.2 bouyer }
218 1.3.2.2 bouyer
219 1.3.2.2 bouyer return_ACPI_STATUS (Status);
220 1.3.2.2 bouyer }
221 1.3.2.2 bouyer
222 1.3.2.2 bouyer
223 1.3.2.2 bouyer /*******************************************************************************
224 1.3.2.2 bouyer *
225 1.3.2.2 bouyer * FUNCTION: AcpiDbExecuteSetup
226 1.3.2.2 bouyer *
227 1.3.2.2 bouyer * PARAMETERS: Info - Valid method info
228 1.3.2.2 bouyer *
229 1.3.2.2 bouyer * RETURN: None
230 1.3.2.2 bouyer *
231 1.3.2.2 bouyer * DESCRIPTION: Setup info segment prior to method execution
232 1.3.2.2 bouyer *
233 1.3.2.2 bouyer ******************************************************************************/
234 1.3.2.2 bouyer
235 1.3.2.2 bouyer static void
236 1.3.2.2 bouyer AcpiDbExecuteSetup (
237 1.3.2.2 bouyer ACPI_DB_METHOD_INFO *Info)
238 1.3.2.2 bouyer {
239 1.3.2.2 bouyer
240 1.3.2.2 bouyer /* Catenate the current scope to the supplied name */
241 1.3.2.2 bouyer
242 1.3.2.2 bouyer Info->Pathname[0] = 0;
243 1.3.2.2 bouyer if ((Info->Name[0] != '\\') &&
244 1.3.2.2 bouyer (Info->Name[0] != '/'))
245 1.3.2.2 bouyer {
246 1.3.2.2 bouyer ACPI_STRCAT (Info->Pathname, AcpiGbl_DbScopeBuf);
247 1.3.2.2 bouyer }
248 1.3.2.2 bouyer
249 1.3.2.2 bouyer ACPI_STRCAT (Info->Pathname, Info->Name);
250 1.3.2.2 bouyer AcpiDbPrepNamestring (Info->Pathname);
251 1.3.2.2 bouyer
252 1.3.2.2 bouyer AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
253 1.3.2.2 bouyer AcpiOsPrintf ("Executing %s\n", Info->Pathname);
254 1.3.2.2 bouyer
255 1.3.2.2 bouyer if (Info->Flags & EX_SINGLE_STEP)
256 1.3.2.2 bouyer {
257 1.3.2.2 bouyer AcpiGbl_CmSingleStep = TRUE;
258 1.3.2.2 bouyer AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
259 1.3.2.2 bouyer }
260 1.3.2.2 bouyer
261 1.3.2.2 bouyer else
262 1.3.2.2 bouyer {
263 1.3.2.2 bouyer /* No single step, allow redirection to a file */
264 1.3.2.2 bouyer
265 1.3.2.2 bouyer AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
266 1.3.2.2 bouyer }
267 1.3.2.2 bouyer }
268 1.3.2.2 bouyer
269 1.3.2.2 bouyer
270 1.3.2.2 bouyer #ifdef ACPI_DBG_TRACK_ALLOCATIONS
271 1.3.2.2 bouyer UINT32
272 1.3.2.2 bouyer AcpiDbGetCacheInfo (
273 1.3.2.2 bouyer ACPI_MEMORY_LIST *Cache)
274 1.3.2.2 bouyer {
275 1.3.2.2 bouyer
276 1.3.2.2 bouyer return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth);
277 1.3.2.2 bouyer }
278 1.3.2.2 bouyer #endif
279 1.3.2.2 bouyer
280 1.3.2.2 bouyer /*******************************************************************************
281 1.3.2.2 bouyer *
282 1.3.2.2 bouyer * FUNCTION: AcpiDbGetOutstandingAllocations
283 1.3.2.2 bouyer *
284 1.3.2.2 bouyer * PARAMETERS: None
285 1.3.2.2 bouyer *
286 1.3.2.2 bouyer * RETURN: Current global allocation count minus cache entries
287 1.3.2.2 bouyer *
288 1.3.2.2 bouyer * DESCRIPTION: Determine the current number of "outstanding" allocations --
289 1.3.2.2 bouyer * those allocations that have not been freed and also are not
290 1.3.2.2 bouyer * in one of the various object caches.
291 1.3.2.2 bouyer *
292 1.3.2.2 bouyer ******************************************************************************/
293 1.3.2.2 bouyer
294 1.3.2.2 bouyer static UINT32
295 1.3.2.2 bouyer AcpiDbGetOutstandingAllocations (
296 1.3.2.2 bouyer void)
297 1.3.2.2 bouyer {
298 1.3.2.2 bouyer UINT32 Outstanding = 0;
299 1.3.2.2 bouyer
300 1.3.2.2 bouyer #ifdef ACPI_DBG_TRACK_ALLOCATIONS
301 1.3.2.2 bouyer
302 1.3.2.2 bouyer Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache);
303 1.3.2.2 bouyer Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache);
304 1.3.2.2 bouyer Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache);
305 1.3.2.2 bouyer Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache);
306 1.3.2.2 bouyer #endif
307 1.3.2.2 bouyer
308 1.3.2.2 bouyer return (Outstanding);
309 1.3.2.2 bouyer }
310 1.3.2.2 bouyer
311 1.3.2.2 bouyer
312 1.3.2.2 bouyer /*******************************************************************************
313 1.3.2.2 bouyer *
314 1.3.2.2 bouyer * FUNCTION: AcpiDbExecutionWalk
315 1.3.2.2 bouyer *
316 1.3.2.2 bouyer * PARAMETERS: WALK_CALLBACK
317 1.3.2.2 bouyer *
318 1.3.2.2 bouyer * RETURN: Status
319 1.3.2.2 bouyer *
320 1.3.2.2 bouyer * DESCRIPTION: Execute a control method. Name is relative to the current
321 1.3.2.2 bouyer * scope.
322 1.3.2.2 bouyer *
323 1.3.2.2 bouyer ******************************************************************************/
324 1.3.2.2 bouyer
325 1.3.2.2 bouyer static ACPI_STATUS
326 1.3.2.2 bouyer AcpiDbExecutionWalk (
327 1.3.2.2 bouyer ACPI_HANDLE ObjHandle,
328 1.3.2.2 bouyer UINT32 NestingLevel,
329 1.3.2.2 bouyer void *Context,
330 1.3.2.2 bouyer void **ReturnValue)
331 1.3.2.2 bouyer {
332 1.3.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc;
333 1.3.2.2 bouyer ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
334 1.3.2.2 bouyer ACPI_BUFFER ReturnObj;
335 1.3.2.2 bouyer ACPI_STATUS Status;
336 1.3.2.2 bouyer
337 1.3.2.2 bouyer
338 1.3.2.2 bouyer ObjDesc = AcpiNsGetAttachedObject (Node);
339 1.3.2.2 bouyer if (ObjDesc->Method.ParamCount)
340 1.3.2.2 bouyer {
341 1.3.2.2 bouyer return (AE_OK);
342 1.3.2.2 bouyer }
343 1.3.2.2 bouyer
344 1.3.2.2 bouyer ReturnObj.Pointer = NULL;
345 1.3.2.2 bouyer ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
346 1.3.2.2 bouyer
347 1.3.2.2 bouyer AcpiNsPrintNodePathname (Node, "Execute");
348 1.3.2.2 bouyer
349 1.3.2.2 bouyer /* Do the actual method execution */
350 1.3.2.2 bouyer
351 1.3.2.2 bouyer AcpiOsPrintf ("\n");
352 1.3.2.2 bouyer AcpiGbl_MethodExecuting = TRUE;
353 1.3.2.2 bouyer
354 1.3.2.2 bouyer Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj);
355 1.3.2.2 bouyer
356 1.3.2.2 bouyer AcpiOsPrintf ("[%4.4s] returned %s\n", AcpiUtGetNodeName (Node),
357 1.3.2.2 bouyer AcpiFormatException (Status));
358 1.3.2.2 bouyer AcpiGbl_MethodExecuting = FALSE;
359 1.3.2.2 bouyer
360 1.3.2.2 bouyer return (AE_OK);
361 1.3.2.2 bouyer }
362 1.3.2.2 bouyer
363 1.3.2.2 bouyer
364 1.3.2.2 bouyer /*******************************************************************************
365 1.3.2.2 bouyer *
366 1.3.2.2 bouyer * FUNCTION: AcpiDbExecute
367 1.3.2.2 bouyer *
368 1.3.2.2 bouyer * PARAMETERS: Name - Name of method to execute
369 1.3.2.2 bouyer * Args - Parameters to the method
370 1.3.2.2 bouyer * Flags - single step/no single step
371 1.3.2.2 bouyer *
372 1.3.2.2 bouyer * RETURN: None
373 1.3.2.2 bouyer *
374 1.3.2.2 bouyer * DESCRIPTION: Execute a control method. Name is relative to the current
375 1.3.2.2 bouyer * scope.
376 1.3.2.2 bouyer *
377 1.3.2.2 bouyer ******************************************************************************/
378 1.3.2.2 bouyer
379 1.3.2.2 bouyer void
380 1.3.2.2 bouyer AcpiDbExecute (
381 1.3.2.2 bouyer char *Name,
382 1.3.2.2 bouyer char **Args,
383 1.3.2.2 bouyer UINT32 Flags)
384 1.3.2.2 bouyer {
385 1.3.2.2 bouyer ACPI_STATUS Status;
386 1.3.2.2 bouyer ACPI_BUFFER ReturnObj;
387 1.3.2.2 bouyer char *NameString;
388 1.3.2.2 bouyer
389 1.3.2.2 bouyer
390 1.3.2.2 bouyer #ifdef ACPI_DEBUG_OUTPUT
391 1.3.2.2 bouyer UINT32 PreviousAllocations;
392 1.3.2.2 bouyer UINT32 Allocations;
393 1.3.2.2 bouyer
394 1.3.2.2 bouyer
395 1.3.2.2 bouyer /* Memory allocation tracking */
396 1.3.2.2 bouyer
397 1.3.2.2 bouyer PreviousAllocations = AcpiDbGetOutstandingAllocations ();
398 1.3.2.2 bouyer #endif
399 1.3.2.2 bouyer
400 1.3.2.2 bouyer if (*Name == '*')
401 1.3.2.2 bouyer {
402 1.3.2.2 bouyer (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
403 1.3.2.2 bouyer ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL);
404 1.3.2.2 bouyer return;
405 1.3.2.2 bouyer }
406 1.3.2.2 bouyer else
407 1.3.2.2 bouyer {
408 1.3.2.2 bouyer NameString = ACPI_ALLOCATE (ACPI_STRLEN (Name) + 1);
409 1.3.2.2 bouyer if (!NameString)
410 1.3.2.2 bouyer {
411 1.3.2.2 bouyer return;
412 1.3.2.2 bouyer }
413 1.3.2.2 bouyer
414 1.3.2.2 bouyer ACPI_MEMSET (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
415 1.3.2.2 bouyer
416 1.3.2.2 bouyer ACPI_STRCPY (NameString, Name);
417 1.3.2.2 bouyer AcpiUtStrupr (NameString);
418 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Name = NameString;
419 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Args = Args;
420 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Flags = Flags;
421 1.3.2.2 bouyer
422 1.3.2.2 bouyer ReturnObj.Pointer = NULL;
423 1.3.2.2 bouyer ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
424 1.3.2.2 bouyer
425 1.3.2.2 bouyer AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
426 1.3.2.2 bouyer Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo, &ReturnObj);
427 1.3.2.2 bouyer ACPI_FREE (NameString);
428 1.3.2.2 bouyer }
429 1.3.2.2 bouyer
430 1.3.2.2 bouyer /*
431 1.3.2.2 bouyer * Allow any handlers in separate threads to complete.
432 1.3.2.2 bouyer * (Such as Notify handlers invoked from AML executed above).
433 1.3.2.2 bouyer */
434 1.3.2.2 bouyer AcpiOsSleep ((UINT64) 10);
435 1.3.2.2 bouyer
436 1.3.2.2 bouyer
437 1.3.2.2 bouyer #ifdef ACPI_DEBUG_OUTPUT
438 1.3.2.2 bouyer
439 1.3.2.2 bouyer /* Memory allocation tracking */
440 1.3.2.2 bouyer
441 1.3.2.2 bouyer Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
442 1.3.2.2 bouyer
443 1.3.2.2 bouyer AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
444 1.3.2.2 bouyer
445 1.3.2.2 bouyer if (Allocations > 0)
446 1.3.2.2 bouyer {
447 1.3.2.2 bouyer AcpiOsPrintf ("Outstanding: 0x%X allocations after execution\n",
448 1.3.2.2 bouyer Allocations);
449 1.3.2.2 bouyer }
450 1.3.2.2 bouyer #endif
451 1.3.2.2 bouyer
452 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
453 1.3.2.2 bouyer {
454 1.3.2.2 bouyer AcpiOsPrintf ("Execution of %s failed with status %s\n",
455 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Pathname, AcpiFormatException (Status));
456 1.3.2.2 bouyer }
457 1.3.2.2 bouyer else
458 1.3.2.2 bouyer {
459 1.3.2.2 bouyer /* Display a return object, if any */
460 1.3.2.2 bouyer
461 1.3.2.2 bouyer if (ReturnObj.Length)
462 1.3.2.2 bouyer {
463 1.3.2.2 bouyer AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n",
464 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
465 1.3.2.2 bouyer (UINT32) ReturnObj.Length);
466 1.3.2.2 bouyer AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
467 1.3.2.2 bouyer }
468 1.3.2.2 bouyer else
469 1.3.2.2 bouyer {
470 1.3.2.2 bouyer AcpiOsPrintf ("No return object from execution of %s\n",
471 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Pathname);
472 1.3.2.2 bouyer }
473 1.3.2.2 bouyer }
474 1.3.2.2 bouyer
475 1.3.2.2 bouyer AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
476 1.3.2.2 bouyer }
477 1.3.2.2 bouyer
478 1.3.2.2 bouyer
479 1.3.2.2 bouyer /*******************************************************************************
480 1.3.2.2 bouyer *
481 1.3.2.2 bouyer * FUNCTION: AcpiDbMethodThread
482 1.3.2.2 bouyer *
483 1.3.2.2 bouyer * PARAMETERS: Context - Execution info segment
484 1.3.2.2 bouyer *
485 1.3.2.2 bouyer * RETURN: None
486 1.3.2.2 bouyer *
487 1.3.2.2 bouyer * DESCRIPTION: Debugger execute thread. Waits for a command line, then
488 1.3.2.2 bouyer * simply dispatches it.
489 1.3.2.2 bouyer *
490 1.3.2.2 bouyer ******************************************************************************/
491 1.3.2.2 bouyer
492 1.3.2.2 bouyer static void ACPI_SYSTEM_XFACE
493 1.3.2.2 bouyer AcpiDbMethodThread (
494 1.3.2.2 bouyer void *Context)
495 1.3.2.2 bouyer {
496 1.3.2.2 bouyer ACPI_STATUS Status;
497 1.3.2.2 bouyer ACPI_DB_METHOD_INFO *Info = Context;
498 1.3.2.2 bouyer ACPI_DB_METHOD_INFO LocalInfo;
499 1.3.2.2 bouyer UINT32 i;
500 1.3.2.2 bouyer UINT8 Allow;
501 1.3.2.2 bouyer ACPI_BUFFER ReturnObj;
502 1.3.2.2 bouyer
503 1.3.2.2 bouyer
504 1.3.2.2 bouyer /*
505 1.3.2.2 bouyer * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments.
506 1.3.2.2 bouyer * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads
507 1.3.2.2 bouyer * concurrently.
508 1.3.2.2 bouyer *
509 1.3.2.2 bouyer * Note: The arguments we are passing are used by the ASL test suite
510 1.3.2.2 bouyer * (aslts). Do not change them without updating the tests.
511 1.3.2.2 bouyer */
512 1.3.2.2 bouyer (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER);
513 1.3.2.2 bouyer
514 1.3.2.2 bouyer if (Info->InitArgs)
515 1.3.2.2 bouyer {
516 1.3.2.2 bouyer AcpiDbUInt32ToHexString (Info->NumCreated, Info->IndexOfThreadStr);
517 1.3.2.2 bouyer AcpiDbUInt32ToHexString ((UINT32) AcpiOsGetThreadId (), Info->IdOfThreadStr);
518 1.3.2.2 bouyer }
519 1.3.2.2 bouyer
520 1.3.2.2 bouyer if (Info->Threads && (Info->NumCreated < Info->NumThreads))
521 1.3.2.2 bouyer {
522 1.3.2.2 bouyer Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId();
523 1.3.2.2 bouyer }
524 1.3.2.2 bouyer
525 1.3.2.2 bouyer LocalInfo = *Info;
526 1.3.2.2 bouyer LocalInfo.Args = LocalInfo.Arguments;
527 1.3.2.2 bouyer LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr;
528 1.3.2.2 bouyer LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr;
529 1.3.2.2 bouyer LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr;
530 1.3.2.2 bouyer LocalInfo.Arguments[3] = NULL;
531 1.3.2.2 bouyer
532 1.3.2.2 bouyer (void) AcpiOsSignalSemaphore (Info->InfoGate, 1);
533 1.3.2.2 bouyer
534 1.3.2.2 bouyer for (i = 0; i < Info->NumLoops; i++)
535 1.3.2.2 bouyer {
536 1.3.2.2 bouyer Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj);
537 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
538 1.3.2.2 bouyer {
539 1.3.2.2 bouyer AcpiOsPrintf ("%s During execution of %s at iteration %X\n",
540 1.3.2.2 bouyer AcpiFormatException (Status), Info->Pathname, i);
541 1.3.2.2 bouyer if (Status == AE_ABORT_METHOD)
542 1.3.2.2 bouyer {
543 1.3.2.2 bouyer break;
544 1.3.2.2 bouyer }
545 1.3.2.2 bouyer }
546 1.3.2.2 bouyer
547 1.3.2.2 bouyer #if 0
548 1.3.2.2 bouyer if ((i % 100) == 0)
549 1.3.2.2 bouyer {
550 1.3.2.2 bouyer AcpiOsPrintf ("%u executions, Thread 0x%x\n", i, AcpiOsGetThreadId ());
551 1.3.2.2 bouyer }
552 1.3.2.2 bouyer
553 1.3.2.2 bouyer if (ReturnObj.Length)
554 1.3.2.2 bouyer {
555 1.3.2.2 bouyer AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n",
556 1.3.2.2 bouyer Info->Pathname, ReturnObj.Pointer, (UINT32) ReturnObj.Length);
557 1.3.2.2 bouyer AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
558 1.3.2.2 bouyer }
559 1.3.2.2 bouyer #endif
560 1.3.2.2 bouyer }
561 1.3.2.2 bouyer
562 1.3.2.2 bouyer /* Signal our completion */
563 1.3.2.2 bouyer
564 1.3.2.2 bouyer Allow = 0;
565 1.3.2.2 bouyer (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate, 1, ACPI_WAIT_FOREVER);
566 1.3.2.2 bouyer Info->NumCompleted++;
567 1.3.2.2 bouyer
568 1.3.2.2 bouyer if (Info->NumCompleted == Info->NumThreads)
569 1.3.2.2 bouyer {
570 1.3.2.2 bouyer /* Do signal for main thread once only */
571 1.3.2.2 bouyer Allow = 1;
572 1.3.2.2 bouyer }
573 1.3.2.2 bouyer
574 1.3.2.2 bouyer (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1);
575 1.3.2.2 bouyer
576 1.3.2.2 bouyer if (Allow)
577 1.3.2.2 bouyer {
578 1.3.2.2 bouyer Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1);
579 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
580 1.3.2.2 bouyer {
581 1.3.2.2 bouyer AcpiOsPrintf ("Could not signal debugger thread sync semaphore, %s\n",
582 1.3.2.2 bouyer AcpiFormatException (Status));
583 1.3.2.2 bouyer }
584 1.3.2.2 bouyer }
585 1.3.2.2 bouyer }
586 1.3.2.2 bouyer
587 1.3.2.2 bouyer
588 1.3.2.2 bouyer /*******************************************************************************
589 1.3.2.2 bouyer *
590 1.3.2.2 bouyer * FUNCTION: AcpiDbCreateExecutionThreads
591 1.3.2.2 bouyer *
592 1.3.2.2 bouyer * PARAMETERS: NumThreadsArg - Number of threads to create
593 1.3.2.2 bouyer * NumLoopsArg - Loop count for the thread(s)
594 1.3.2.2 bouyer * MethodNameArg - Control method to execute
595 1.3.2.2 bouyer *
596 1.3.2.2 bouyer * RETURN: None
597 1.3.2.2 bouyer *
598 1.3.2.2 bouyer * DESCRIPTION: Create threads to execute method(s)
599 1.3.2.2 bouyer *
600 1.3.2.2 bouyer ******************************************************************************/
601 1.3.2.2 bouyer
602 1.3.2.2 bouyer void
603 1.3.2.2 bouyer AcpiDbCreateExecutionThreads (
604 1.3.2.2 bouyer char *NumThreadsArg,
605 1.3.2.2 bouyer char *NumLoopsArg,
606 1.3.2.2 bouyer char *MethodNameArg)
607 1.3.2.2 bouyer {
608 1.3.2.2 bouyer ACPI_STATUS Status;
609 1.3.2.2 bouyer UINT32 NumThreads;
610 1.3.2.2 bouyer UINT32 NumLoops;
611 1.3.2.2 bouyer UINT32 i;
612 1.3.2.2 bouyer UINT32 Size;
613 1.3.2.2 bouyer ACPI_MUTEX MainThreadGate;
614 1.3.2.2 bouyer ACPI_MUTEX ThreadCompleteGate;
615 1.3.2.2 bouyer ACPI_MUTEX InfoGate;
616 1.3.2.2 bouyer
617 1.3.2.2 bouyer
618 1.3.2.2 bouyer /* Get the arguments */
619 1.3.2.2 bouyer
620 1.3.2.2 bouyer NumThreads = ACPI_STRTOUL (NumThreadsArg, NULL, 0);
621 1.3.2.2 bouyer NumLoops = ACPI_STRTOUL (NumLoopsArg, NULL, 0);
622 1.3.2.2 bouyer
623 1.3.2.2 bouyer if (!NumThreads || !NumLoops)
624 1.3.2.2 bouyer {
625 1.3.2.2 bouyer AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
626 1.3.2.2 bouyer NumThreads, NumLoops);
627 1.3.2.2 bouyer return;
628 1.3.2.2 bouyer }
629 1.3.2.2 bouyer
630 1.3.2.2 bouyer /*
631 1.3.2.2 bouyer * Create the semaphore for synchronization of
632 1.3.2.2 bouyer * the created threads with the main thread.
633 1.3.2.2 bouyer */
634 1.3.2.2 bouyer Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate);
635 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
636 1.3.2.2 bouyer {
637 1.3.2.2 bouyer AcpiOsPrintf ("Could not create semaphore for synchronization with the main thread, %s\n",
638 1.3.2.2 bouyer AcpiFormatException (Status));
639 1.3.2.2 bouyer return;
640 1.3.2.2 bouyer }
641 1.3.2.2 bouyer
642 1.3.2.2 bouyer /*
643 1.3.2.2 bouyer * Create the semaphore for synchronization
644 1.3.2.2 bouyer * between the created threads.
645 1.3.2.2 bouyer */
646 1.3.2.2 bouyer Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate);
647 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
648 1.3.2.2 bouyer {
649 1.3.2.2 bouyer AcpiOsPrintf ("Could not create semaphore for synchronization between the created threads, %s\n",
650 1.3.2.2 bouyer AcpiFormatException (Status));
651 1.3.2.2 bouyer (void) AcpiOsDeleteSemaphore (MainThreadGate);
652 1.3.2.2 bouyer return;
653 1.3.2.2 bouyer }
654 1.3.2.2 bouyer
655 1.3.2.2 bouyer Status = AcpiOsCreateSemaphore (1, 1, &InfoGate);
656 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
657 1.3.2.2 bouyer {
658 1.3.2.2 bouyer AcpiOsPrintf ("Could not create semaphore for synchronization of AcpiGbl_DbMethodInfo, %s\n",
659 1.3.2.2 bouyer AcpiFormatException (Status));
660 1.3.2.2 bouyer (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
661 1.3.2.2 bouyer (void) AcpiOsDeleteSemaphore (MainThreadGate);
662 1.3.2.2 bouyer return;
663 1.3.2.2 bouyer }
664 1.3.2.2 bouyer
665 1.3.2.2 bouyer ACPI_MEMSET (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
666 1.3.2.2 bouyer
667 1.3.2.2 bouyer /* Array to store IDs of threads */
668 1.3.2.2 bouyer
669 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.NumThreads = NumThreads;
670 1.3.2.2 bouyer Size = sizeof (ACPI_THREAD_ID) * AcpiGbl_DbMethodInfo.NumThreads;
671 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Threads = AcpiOsAllocate (Size);
672 1.3.2.2 bouyer if (AcpiGbl_DbMethodInfo.Threads == NULL)
673 1.3.2.2 bouyer {
674 1.3.2.2 bouyer AcpiOsPrintf ("No memory for thread IDs array\n");
675 1.3.2.2 bouyer (void) AcpiOsDeleteSemaphore (MainThreadGate);
676 1.3.2.2 bouyer (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
677 1.3.2.2 bouyer (void) AcpiOsDeleteSemaphore (InfoGate);
678 1.3.2.2 bouyer return;
679 1.3.2.2 bouyer }
680 1.3.2.2 bouyer ACPI_MEMSET (AcpiGbl_DbMethodInfo.Threads, 0, Size);
681 1.3.2.2 bouyer
682 1.3.2.2 bouyer /* Setup the context to be passed to each thread */
683 1.3.2.2 bouyer
684 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Name = MethodNameArg;
685 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Flags = 0;
686 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.NumLoops = NumLoops;
687 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate;
688 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate;
689 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.InfoGate = InfoGate;
690 1.3.2.2 bouyer
691 1.3.2.2 bouyer /* Init arguments to be passed to method */
692 1.3.2.2 bouyer
693 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.InitArgs = 1;
694 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
695 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr;
696 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr;
697 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr;
698 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Arguments[3] = NULL;
699 1.3.2.2 bouyer AcpiDbUInt32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr);
700 1.3.2.2 bouyer
701 1.3.2.2 bouyer AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
702 1.3.2.2 bouyer
703 1.3.2.2 bouyer /* Create the threads */
704 1.3.2.2 bouyer
705 1.3.2.2 bouyer AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
706 1.3.2.2 bouyer NumThreads, NumLoops);
707 1.3.2.2 bouyer
708 1.3.2.2 bouyer for (i = 0; i < (NumThreads); i++)
709 1.3.2.2 bouyer {
710 1.3.2.2 bouyer Status = AcpiOsExecute (OSL_DEBUGGER_THREAD, AcpiDbMethodThread,
711 1.3.2.2 bouyer &AcpiGbl_DbMethodInfo);
712 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
713 1.3.2.2 bouyer {
714 1.3.2.2 bouyer break;
715 1.3.2.2 bouyer }
716 1.3.2.2 bouyer }
717 1.3.2.2 bouyer
718 1.3.2.2 bouyer /* Wait for all threads to complete */
719 1.3.2.2 bouyer
720 1.3.2.2 bouyer (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER);
721 1.3.2.2 bouyer
722 1.3.2.2 bouyer AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
723 1.3.2.2 bouyer AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads);
724 1.3.2.2 bouyer AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
725 1.3.2.2 bouyer
726 1.3.2.2 bouyer /* Cleanup and exit */
727 1.3.2.2 bouyer
728 1.3.2.2 bouyer (void) AcpiOsDeleteSemaphore (MainThreadGate);
729 1.3.2.2 bouyer (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
730 1.3.2.2 bouyer (void) AcpiOsDeleteSemaphore (InfoGate);
731 1.3.2.2 bouyer
732 1.3.2.2 bouyer AcpiOsFree (AcpiGbl_DbMethodInfo.Threads);
733 1.3.2.2 bouyer AcpiGbl_DbMethodInfo.Threads = NULL;
734 1.3.2.2 bouyer }
735 1.3.2.2 bouyer
736 1.3.2.2 bouyer #endif /* ACPI_DEBUGGER */
737 1.3.2.2 bouyer
738 1.3.2.2 bouyer
739