dbexec.c revision 1.17.4.2 1 1.1 jruoho /*******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: dbexec - debugger control method execution
4 1.1 jruoho *
5 1.1 jruoho ******************************************************************************/
6 1.1 jruoho
7 1.3 jruoho /*
8 1.17.4.2 thorpej * Copyright (C) 2000 - 2021, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.3 jruoho * Redistribution and use in source and binary forms, with or without
12 1.3 jruoho * modification, are permitted provided that the following conditions
13 1.3 jruoho * are met:
14 1.3 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.3 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.3 jruoho * without modification.
17 1.3 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.3 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.3 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.3 jruoho * including a substantially similar Disclaimer requirement for further
21 1.3 jruoho * binary redistribution.
22 1.3 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.3 jruoho * of any contributors may be used to endorse or promote products derived
24 1.3 jruoho * from this software without specific prior written permission.
25 1.3 jruoho *
26 1.3 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.3 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.3 jruoho * Software Foundation.
29 1.3 jruoho *
30 1.3 jruoho * NO WARRANTY
31 1.3 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.3 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.17.4.2 thorpej * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 1.3 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.3 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.3 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.3 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.3 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.3 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.3 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.3 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.3 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "acpi.h"
45 1.1 jruoho #include "accommon.h"
46 1.1 jruoho #include "acdebug.h"
47 1.1 jruoho #include "acnamesp.h"
48 1.1 jruoho
49 1.1 jruoho
50 1.1 jruoho #define _COMPONENT ACPI_CA_DEBUGGER
51 1.1 jruoho ACPI_MODULE_NAME ("dbexec")
52 1.1 jruoho
53 1.1 jruoho
54 1.4 jruoho static ACPI_DB_METHOD_INFO AcpiGbl_DbMethodInfo;
55 1.1 jruoho
56 1.1 jruoho /* Local prototypes */
57 1.1 jruoho
58 1.1 jruoho static ACPI_STATUS
59 1.1 jruoho AcpiDbExecuteMethod (
60 1.1 jruoho ACPI_DB_METHOD_INFO *Info,
61 1.1 jruoho ACPI_BUFFER *ReturnObj);
62 1.1 jruoho
63 1.5 christos static ACPI_STATUS
64 1.1 jruoho AcpiDbExecuteSetup (
65 1.1 jruoho ACPI_DB_METHOD_INFO *Info);
66 1.1 jruoho
67 1.1 jruoho static UINT32
68 1.1 jruoho AcpiDbGetOutstandingAllocations (
69 1.1 jruoho void);
70 1.1 jruoho
71 1.1 jruoho static void ACPI_SYSTEM_XFACE
72 1.1 jruoho AcpiDbMethodThread (
73 1.1 jruoho void *Context);
74 1.1 jruoho
75 1.1 jruoho static ACPI_STATUS
76 1.1 jruoho AcpiDbExecutionWalk (
77 1.1 jruoho ACPI_HANDLE ObjHandle,
78 1.1 jruoho UINT32 NestingLevel,
79 1.1 jruoho void *Context,
80 1.1 jruoho void **ReturnValue);
81 1.1 jruoho
82 1.14 christos static void ACPI_SYSTEM_XFACE
83 1.14 christos AcpiDbSingleExecutionThread (
84 1.14 christos void *Context);
85 1.14 christos
86 1.4 jruoho
87 1.4 jruoho /*******************************************************************************
88 1.4 jruoho *
89 1.4 jruoho * FUNCTION: AcpiDbDeleteObjects
90 1.4 jruoho *
91 1.4 jruoho * PARAMETERS: Count - Count of objects in the list
92 1.4 jruoho * Objects - Array of ACPI_OBJECTs to be deleted
93 1.4 jruoho *
94 1.4 jruoho * RETURN: None
95 1.4 jruoho *
96 1.4 jruoho * DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested
97 1.4 jruoho * packages via recursion.
98 1.4 jruoho *
99 1.4 jruoho ******************************************************************************/
100 1.4 jruoho
101 1.5 christos void
102 1.4 jruoho AcpiDbDeleteObjects (
103 1.4 jruoho UINT32 Count,
104 1.4 jruoho ACPI_OBJECT *Objects)
105 1.4 jruoho {
106 1.4 jruoho UINT32 i;
107 1.4 jruoho
108 1.4 jruoho
109 1.4 jruoho for (i = 0; i < Count; i++)
110 1.4 jruoho {
111 1.4 jruoho switch (Objects[i].Type)
112 1.4 jruoho {
113 1.4 jruoho case ACPI_TYPE_BUFFER:
114 1.5 christos
115 1.4 jruoho ACPI_FREE (Objects[i].Buffer.Pointer);
116 1.4 jruoho break;
117 1.4 jruoho
118 1.4 jruoho case ACPI_TYPE_PACKAGE:
119 1.4 jruoho
120 1.4 jruoho /* Recursive call to delete package elements */
121 1.4 jruoho
122 1.4 jruoho AcpiDbDeleteObjects (Objects[i].Package.Count,
123 1.4 jruoho Objects[i].Package.Elements);
124 1.4 jruoho
125 1.4 jruoho /* Free the elements array */
126 1.4 jruoho
127 1.4 jruoho ACPI_FREE (Objects[i].Package.Elements);
128 1.4 jruoho break;
129 1.4 jruoho
130 1.4 jruoho default:
131 1.5 christos
132 1.4 jruoho break;
133 1.4 jruoho }
134 1.4 jruoho }
135 1.4 jruoho }
136 1.4 jruoho
137 1.1 jruoho
138 1.1 jruoho /*******************************************************************************
139 1.1 jruoho *
140 1.1 jruoho * FUNCTION: AcpiDbExecuteMethod
141 1.1 jruoho *
142 1.1 jruoho * PARAMETERS: Info - Valid info segment
143 1.1 jruoho * ReturnObj - Where to put return object
144 1.1 jruoho *
145 1.1 jruoho * RETURN: Status
146 1.1 jruoho *
147 1.17.4.1 thorpej * DESCRIPTION: Execute a control method. Used to evaluate objects via the
148 1.17.4.1 thorpej * "EXECUTE" or "EVALUATE" commands.
149 1.1 jruoho *
150 1.1 jruoho ******************************************************************************/
151 1.1 jruoho
152 1.1 jruoho static ACPI_STATUS
153 1.1 jruoho AcpiDbExecuteMethod (
154 1.1 jruoho ACPI_DB_METHOD_INFO *Info,
155 1.1 jruoho ACPI_BUFFER *ReturnObj)
156 1.1 jruoho {
157 1.1 jruoho ACPI_STATUS Status;
158 1.1 jruoho ACPI_OBJECT_LIST ParamObjects;
159 1.5 christos ACPI_OBJECT Params[ACPI_DEBUGGER_MAX_ARGS + 1];
160 1.1 jruoho UINT32 i;
161 1.1 jruoho
162 1.1 jruoho
163 1.3 jruoho ACPI_FUNCTION_TRACE (DbExecuteMethod);
164 1.3 jruoho
165 1.3 jruoho
166 1.1 jruoho if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel)
167 1.1 jruoho {
168 1.1 jruoho AcpiOsPrintf ("Warning: debug output is not enabled!\n");
169 1.1 jruoho }
170 1.1 jruoho
171 1.5 christos ParamObjects.Count = 0;
172 1.5 christos ParamObjects.Pointer = NULL;
173 1.1 jruoho
174 1.5 christos /* Pass through any command-line arguments */
175 1.1 jruoho
176 1.5 christos if (Info->Args && Info->Args[0])
177 1.1 jruoho {
178 1.5 christos /* Get arguments passed on the command line */
179 1.4 jruoho
180 1.5 christos for (i = 0; (Info->Args[i] && *(Info->Args[i])); i++)
181 1.1 jruoho {
182 1.5 christos /* Convert input string (token) to an actual ACPI_OBJECT */
183 1.1 jruoho
184 1.5 christos Status = AcpiDbConvertToObject (Info->Types[i],
185 1.5 christos Info->Args[i], &Params[i]);
186 1.5 christos if (ACPI_FAILURE (Status))
187 1.1 jruoho {
188 1.5 christos ACPI_EXCEPTION ((AE_INFO, Status,
189 1.5 christos "While parsing method arguments"));
190 1.5 christos goto Cleanup;
191 1.1 jruoho }
192 1.4 jruoho }
193 1.1 jruoho
194 1.5 christos ParamObjects.Count = i;
195 1.4 jruoho ParamObjects.Pointer = Params;
196 1.1 jruoho }
197 1.1 jruoho
198 1.1 jruoho /* Prepare for a return object of arbitrary size */
199 1.1 jruoho
200 1.1 jruoho ReturnObj->Pointer = AcpiGbl_DbBuffer;
201 1.1 jruoho ReturnObj->Length = ACPI_DEBUG_BUFFER_SIZE;
202 1.1 jruoho
203 1.1 jruoho /* Do the actual method execution */
204 1.1 jruoho
205 1.1 jruoho AcpiGbl_MethodExecuting = TRUE;
206 1.5 christos Status = AcpiEvaluateObject (NULL, Info->Pathname,
207 1.5 christos &ParamObjects, ReturnObj);
208 1.1 jruoho
209 1.1 jruoho AcpiGbl_CmSingleStep = FALSE;
210 1.1 jruoho AcpiGbl_MethodExecuting = FALSE;
211 1.1 jruoho
212 1.3 jruoho if (ACPI_FAILURE (Status))
213 1.3 jruoho {
214 1.13 christos if ((Status == AE_ABORT_METHOD) || AcpiGbl_AbortMethod)
215 1.13 christos {
216 1.13 christos /* Clear the abort and fall back to the debugger prompt */
217 1.13 christos
218 1.13 christos ACPI_EXCEPTION ((AE_INFO, Status,
219 1.13 christos "Aborting top-level method"));
220 1.13 christos
221 1.13 christos AcpiGbl_AbortMethod = FALSE;
222 1.13 christos Status = AE_OK;
223 1.13 christos goto Cleanup;
224 1.13 christos }
225 1.13 christos
226 1.3 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
227 1.16 christos "while executing %s from AML Debugger", Info->Pathname));
228 1.3 jruoho
229 1.3 jruoho if (Status == AE_BUFFER_OVERFLOW)
230 1.3 jruoho {
231 1.3 jruoho ACPI_ERROR ((AE_INFO,
232 1.16 christos "Possible buffer overflow within AML Debugger "
233 1.10 christos "buffer (size 0x%X needed 0x%X)",
234 1.3 jruoho ACPI_DEBUG_BUFFER_SIZE, (UINT32) ReturnObj->Length));
235 1.3 jruoho }
236 1.3 jruoho }
237 1.3 jruoho
238 1.4 jruoho Cleanup:
239 1.5 christos AcpiDbDeleteObjects (ParamObjects.Count, Params);
240 1.3 jruoho return_ACPI_STATUS (Status);
241 1.1 jruoho }
242 1.1 jruoho
243 1.1 jruoho
244 1.1 jruoho /*******************************************************************************
245 1.1 jruoho *
246 1.1 jruoho * FUNCTION: AcpiDbExecuteSetup
247 1.1 jruoho *
248 1.1 jruoho * PARAMETERS: Info - Valid method info
249 1.1 jruoho *
250 1.1 jruoho * RETURN: None
251 1.1 jruoho *
252 1.1 jruoho * DESCRIPTION: Setup info segment prior to method execution
253 1.1 jruoho *
254 1.1 jruoho ******************************************************************************/
255 1.1 jruoho
256 1.5 christos static ACPI_STATUS
257 1.1 jruoho AcpiDbExecuteSetup (
258 1.1 jruoho ACPI_DB_METHOD_INFO *Info)
259 1.1 jruoho {
260 1.5 christos ACPI_STATUS Status;
261 1.5 christos
262 1.5 christos
263 1.5 christos ACPI_FUNCTION_NAME (DbExecuteSetup);
264 1.5 christos
265 1.1 jruoho
266 1.14 christos /* Concatenate the current scope to the supplied name */
267 1.1 jruoho
268 1.1 jruoho Info->Pathname[0] = 0;
269 1.1 jruoho if ((Info->Name[0] != '\\') &&
270 1.1 jruoho (Info->Name[0] != '/'))
271 1.1 jruoho {
272 1.5 christos if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname),
273 1.5 christos AcpiGbl_DbScopeBuf))
274 1.5 christos {
275 1.5 christos Status = AE_BUFFER_OVERFLOW;
276 1.5 christos goto ErrorExit;
277 1.5 christos }
278 1.5 christos }
279 1.5 christos
280 1.5 christos if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname),
281 1.5 christos Info->Name))
282 1.5 christos {
283 1.5 christos Status = AE_BUFFER_OVERFLOW;
284 1.5 christos goto ErrorExit;
285 1.1 jruoho }
286 1.1 jruoho
287 1.1 jruoho AcpiDbPrepNamestring (Info->Pathname);
288 1.1 jruoho
289 1.1 jruoho AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
290 1.5 christos AcpiOsPrintf ("Evaluating %s\n", Info->Pathname);
291 1.1 jruoho
292 1.1 jruoho if (Info->Flags & EX_SINGLE_STEP)
293 1.1 jruoho {
294 1.1 jruoho AcpiGbl_CmSingleStep = TRUE;
295 1.1 jruoho AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
296 1.1 jruoho }
297 1.1 jruoho
298 1.1 jruoho else
299 1.1 jruoho {
300 1.1 jruoho /* No single step, allow redirection to a file */
301 1.1 jruoho
302 1.1 jruoho AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
303 1.1 jruoho }
304 1.5 christos
305 1.5 christos return (AE_OK);
306 1.5 christos
307 1.5 christos ErrorExit:
308 1.5 christos
309 1.5 christos ACPI_EXCEPTION ((AE_INFO, Status, "During setup for method execution"));
310 1.5 christos return (Status);
311 1.1 jruoho }
312 1.1 jruoho
313 1.1 jruoho
314 1.1 jruoho #ifdef ACPI_DBG_TRACK_ALLOCATIONS
315 1.1 jruoho UINT32
316 1.1 jruoho AcpiDbGetCacheInfo (
317 1.1 jruoho ACPI_MEMORY_LIST *Cache)
318 1.1 jruoho {
319 1.1 jruoho
320 1.1 jruoho return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth);
321 1.1 jruoho }
322 1.1 jruoho #endif
323 1.1 jruoho
324 1.1 jruoho /*******************************************************************************
325 1.1 jruoho *
326 1.1 jruoho * FUNCTION: AcpiDbGetOutstandingAllocations
327 1.1 jruoho *
328 1.1 jruoho * PARAMETERS: None
329 1.1 jruoho *
330 1.1 jruoho * RETURN: Current global allocation count minus cache entries
331 1.1 jruoho *
332 1.1 jruoho * DESCRIPTION: Determine the current number of "outstanding" allocations --
333 1.1 jruoho * those allocations that have not been freed and also are not
334 1.1 jruoho * in one of the various object caches.
335 1.1 jruoho *
336 1.1 jruoho ******************************************************************************/
337 1.1 jruoho
338 1.6 christos #ifdef ACPI_DEBUG_OUTPUT
339 1.1 jruoho static UINT32
340 1.1 jruoho AcpiDbGetOutstandingAllocations (
341 1.1 jruoho void)
342 1.1 jruoho {
343 1.1 jruoho UINT32 Outstanding = 0;
344 1.1 jruoho
345 1.1 jruoho #ifdef ACPI_DBG_TRACK_ALLOCATIONS
346 1.1 jruoho
347 1.1 jruoho Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache);
348 1.1 jruoho Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache);
349 1.1 jruoho Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache);
350 1.1 jruoho Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache);
351 1.1 jruoho #endif
352 1.1 jruoho
353 1.1 jruoho return (Outstanding);
354 1.1 jruoho }
355 1.6 christos #endif
356 1.1 jruoho
357 1.1 jruoho
358 1.1 jruoho /*******************************************************************************
359 1.1 jruoho *
360 1.1 jruoho * FUNCTION: AcpiDbExecutionWalk
361 1.1 jruoho *
362 1.1 jruoho * PARAMETERS: WALK_CALLBACK
363 1.1 jruoho *
364 1.1 jruoho * RETURN: Status
365 1.1 jruoho *
366 1.5 christos * DESCRIPTION: Execute a control method. Name is relative to the current
367 1.1 jruoho * scope.
368 1.1 jruoho *
369 1.1 jruoho ******************************************************************************/
370 1.1 jruoho
371 1.1 jruoho static ACPI_STATUS
372 1.1 jruoho AcpiDbExecutionWalk (
373 1.1 jruoho ACPI_HANDLE ObjHandle,
374 1.1 jruoho UINT32 NestingLevel,
375 1.1 jruoho void *Context,
376 1.1 jruoho void **ReturnValue)
377 1.1 jruoho {
378 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
379 1.1 jruoho ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
380 1.1 jruoho ACPI_BUFFER ReturnObj;
381 1.1 jruoho ACPI_STATUS Status;
382 1.1 jruoho
383 1.1 jruoho
384 1.1 jruoho ObjDesc = AcpiNsGetAttachedObject (Node);
385 1.1 jruoho if (ObjDesc->Method.ParamCount)
386 1.1 jruoho {
387 1.1 jruoho return (AE_OK);
388 1.1 jruoho }
389 1.1 jruoho
390 1.1 jruoho ReturnObj.Pointer = NULL;
391 1.1 jruoho ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
392 1.1 jruoho
393 1.5 christos AcpiNsPrintNodePathname (Node, "Evaluating");
394 1.1 jruoho
395 1.1 jruoho /* Do the actual method execution */
396 1.1 jruoho
397 1.1 jruoho AcpiOsPrintf ("\n");
398 1.1 jruoho AcpiGbl_MethodExecuting = TRUE;
399 1.1 jruoho
400 1.1 jruoho Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj);
401 1.1 jruoho
402 1.17.4.1 thorpej AcpiGbl_MethodExecuting = FALSE;
403 1.17.4.1 thorpej
404 1.10 christos AcpiOsPrintf ("Evaluation of [%4.4s] returned %s\n",
405 1.10 christos AcpiUtGetNodeName (Node),
406 1.10 christos AcpiFormatException (Status));
407 1.10 christos
408 1.1 jruoho return (AE_OK);
409 1.1 jruoho }
410 1.1 jruoho
411 1.1 jruoho
412 1.1 jruoho /*******************************************************************************
413 1.1 jruoho *
414 1.1 jruoho * FUNCTION: AcpiDbExecute
415 1.1 jruoho *
416 1.1 jruoho * PARAMETERS: Name - Name of method to execute
417 1.1 jruoho * Args - Parameters to the method
418 1.10 christos * Types -
419 1.1 jruoho * Flags - single step/no single step
420 1.1 jruoho *
421 1.1 jruoho * RETURN: None
422 1.1 jruoho *
423 1.5 christos * DESCRIPTION: Execute a control method. Name is relative to the current
424 1.17.4.1 thorpej * scope. Function used for the "EXECUTE", "EVALUATE", and
425 1.17.4.1 thorpej * "ALL" commands
426 1.1 jruoho *
427 1.1 jruoho ******************************************************************************/
428 1.1 jruoho
429 1.1 jruoho void
430 1.1 jruoho AcpiDbExecute (
431 1.1 jruoho char *Name,
432 1.1 jruoho char **Args,
433 1.4 jruoho ACPI_OBJECT_TYPE *Types,
434 1.1 jruoho UINT32 Flags)
435 1.1 jruoho {
436 1.1 jruoho ACPI_STATUS Status;
437 1.1 jruoho ACPI_BUFFER ReturnObj;
438 1.1 jruoho char *NameString;
439 1.1 jruoho
440 1.1 jruoho #ifdef ACPI_DEBUG_OUTPUT
441 1.1 jruoho UINT32 PreviousAllocations;
442 1.1 jruoho UINT32 Allocations;
443 1.10 christos #endif
444 1.1 jruoho
445 1.1 jruoho
446 1.10 christos /*
447 1.10 christos * Allow one execution to be performed by debugger or single step
448 1.10 christos * execution will be dead locked by the interpreter mutexes.
449 1.10 christos */
450 1.10 christos if (AcpiGbl_MethodExecuting)
451 1.10 christos {
452 1.10 christos AcpiOsPrintf ("Only one debugger execution is allowed.\n");
453 1.10 christos return;
454 1.10 christos }
455 1.10 christos
456 1.10 christos #ifdef ACPI_DEBUG_OUTPUT
457 1.1 jruoho /* Memory allocation tracking */
458 1.1 jruoho
459 1.1 jruoho PreviousAllocations = AcpiDbGetOutstandingAllocations ();
460 1.1 jruoho #endif
461 1.1 jruoho
462 1.1 jruoho if (*Name == '*')
463 1.1 jruoho {
464 1.1 jruoho (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
465 1.10 christos ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL);
466 1.1 jruoho return;
467 1.1 jruoho }
468 1.11 christos
469 1.17.4.1 thorpej if ((Flags & EX_ALL) && (strlen (Name) > 4))
470 1.17.4.1 thorpej {
471 1.17.4.1 thorpej AcpiOsPrintf ("Input name (%s) must be a 4-char NameSeg\n", Name);
472 1.17.4.1 thorpej return;
473 1.17.4.1 thorpej }
474 1.17.4.1 thorpej
475 1.11 christos NameString = ACPI_ALLOCATE (strlen (Name) + 1);
476 1.11 christos if (!NameString)
477 1.1 jruoho {
478 1.11 christos return;
479 1.11 christos }
480 1.1 jruoho
481 1.11 christos memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
482 1.11 christos strcpy (NameString, Name);
483 1.11 christos AcpiUtStrupr (NameString);
484 1.1 jruoho
485 1.11 christos /* Subcommand to Execute all predefined names in the namespace */
486 1.1 jruoho
487 1.11 christos if (!strncmp (NameString, "PREDEF", 6))
488 1.11 christos {
489 1.11 christos AcpiDbEvaluatePredefinedNames ();
490 1.11 christos ACPI_FREE (NameString);
491 1.11 christos return;
492 1.11 christos }
493 1.1 jruoho
494 1.17.4.1 thorpej /* Command (ALL <nameseg>) to execute all methods of a particular name */
495 1.5 christos
496 1.17.4.1 thorpej else if (Flags & EX_ALL)
497 1.17.4.1 thorpej {
498 1.17.4.1 thorpej AcpiGbl_DbMethodInfo.Name = NameString;
499 1.17.4.1 thorpej ReturnObj.Pointer = NULL;
500 1.17.4.1 thorpej ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
501 1.17.4.1 thorpej AcpiDbEvaluateAll (NameString);
502 1.17.4.1 thorpej ACPI_FREE (NameString);
503 1.17.4.1 thorpej return;
504 1.17.4.1 thorpej }
505 1.17.4.1 thorpej else
506 1.17.4.1 thorpej {
507 1.17.4.1 thorpej AcpiGbl_DbMethodInfo.Name = NameString;
508 1.17.4.1 thorpej AcpiGbl_DbMethodInfo.Args = Args;
509 1.17.4.1 thorpej AcpiGbl_DbMethodInfo.Types = Types;
510 1.17.4.1 thorpej AcpiGbl_DbMethodInfo.Flags = Flags;
511 1.17.4.1 thorpej
512 1.17.4.1 thorpej ReturnObj.Pointer = NULL;
513 1.17.4.1 thorpej ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
514 1.17.4.1 thorpej }
515 1.5 christos
516 1.11 christos Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
517 1.11 christos if (ACPI_FAILURE (Status))
518 1.11 christos {
519 1.1 jruoho ACPI_FREE (NameString);
520 1.11 christos return;
521 1.11 christos }
522 1.11 christos
523 1.11 christos /* Get the NS node, determines existence also */
524 1.11 christos
525 1.11 christos Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
526 1.11 christos &AcpiGbl_DbMethodInfo.Method);
527 1.11 christos if (ACPI_SUCCESS (Status))
528 1.11 christos {
529 1.11 christos Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo,
530 1.11 christos &ReturnObj);
531 1.1 jruoho }
532 1.11 christos ACPI_FREE (NameString);
533 1.1 jruoho
534 1.1 jruoho /*
535 1.1 jruoho * Allow any handlers in separate threads to complete.
536 1.1 jruoho * (Such as Notify handlers invoked from AML executed above).
537 1.1 jruoho */
538 1.1 jruoho AcpiOsSleep ((UINT64) 10);
539 1.1 jruoho
540 1.1 jruoho #ifdef ACPI_DEBUG_OUTPUT
541 1.1 jruoho
542 1.1 jruoho /* Memory allocation tracking */
543 1.1 jruoho
544 1.1 jruoho Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
545 1.1 jruoho
546 1.1 jruoho AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
547 1.1 jruoho
548 1.1 jruoho if (Allocations > 0)
549 1.1 jruoho {
550 1.10 christos AcpiOsPrintf (
551 1.10 christos "0x%X Outstanding allocations after evaluation of %s\n",
552 1.10 christos Allocations, AcpiGbl_DbMethodInfo.Pathname);
553 1.1 jruoho }
554 1.1 jruoho #endif
555 1.1 jruoho
556 1.1 jruoho if (ACPI_FAILURE (Status))
557 1.1 jruoho {
558 1.5 christos AcpiOsPrintf ("Evaluation of %s failed with status %s\n",
559 1.10 christos AcpiGbl_DbMethodInfo.Pathname,
560 1.10 christos AcpiFormatException (Status));
561 1.1 jruoho }
562 1.1 jruoho else
563 1.1 jruoho {
564 1.1 jruoho /* Display a return object, if any */
565 1.1 jruoho
566 1.1 jruoho if (ReturnObj.Length)
567 1.1 jruoho {
568 1.5 christos AcpiOsPrintf (
569 1.10 christos "Evaluation of %s returned object %p, "
570 1.10 christos "external buffer length %X\n",
571 1.1 jruoho AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
572 1.1 jruoho (UINT32) ReturnObj.Length);
573 1.10 christos
574 1.1 jruoho AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
575 1.17.4.1 thorpej AcpiOsPrintf ("\n");
576 1.5 christos
577 1.5 christos /* Dump a _PLD buffer if present */
578 1.5 christos
579 1.16 christos if (ACPI_COMPARE_NAMESEG ((ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
580 1.10 christos AcpiGbl_DbMethodInfo.Method)->Name.Ascii),
581 1.10 christos METHOD_NAME__PLD))
582 1.5 christos {
583 1.5 christos AcpiDbDumpPldBuffer (ReturnObj.Pointer);
584 1.5 christos }
585 1.1 jruoho }
586 1.1 jruoho else
587 1.1 jruoho {
588 1.5 christos AcpiOsPrintf ("No object was returned from evaluation of %s\n",
589 1.1 jruoho AcpiGbl_DbMethodInfo.Pathname);
590 1.1 jruoho }
591 1.1 jruoho }
592 1.1 jruoho
593 1.1 jruoho AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
594 1.1 jruoho }
595 1.1 jruoho
596 1.1 jruoho
597 1.1 jruoho /*******************************************************************************
598 1.1 jruoho *
599 1.1 jruoho * FUNCTION: AcpiDbMethodThread
600 1.1 jruoho *
601 1.1 jruoho * PARAMETERS: Context - Execution info segment
602 1.1 jruoho *
603 1.1 jruoho * RETURN: None
604 1.1 jruoho *
605 1.5 christos * DESCRIPTION: Debugger execute thread. Waits for a command line, then
606 1.1 jruoho * simply dispatches it.
607 1.1 jruoho *
608 1.1 jruoho ******************************************************************************/
609 1.1 jruoho
610 1.1 jruoho static void ACPI_SYSTEM_XFACE
611 1.1 jruoho AcpiDbMethodThread (
612 1.1 jruoho void *Context)
613 1.1 jruoho {
614 1.1 jruoho ACPI_STATUS Status;
615 1.1 jruoho ACPI_DB_METHOD_INFO *Info = Context;
616 1.1 jruoho ACPI_DB_METHOD_INFO LocalInfo;
617 1.1 jruoho UINT32 i;
618 1.1 jruoho UINT8 Allow;
619 1.1 jruoho ACPI_BUFFER ReturnObj;
620 1.1 jruoho
621 1.1 jruoho
622 1.1 jruoho /*
623 1.1 jruoho * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments.
624 1.1 jruoho * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads
625 1.1 jruoho * concurrently.
626 1.1 jruoho *
627 1.1 jruoho * Note: The arguments we are passing are used by the ASL test suite
628 1.1 jruoho * (aslts). Do not change them without updating the tests.
629 1.1 jruoho */
630 1.1 jruoho (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER);
631 1.1 jruoho
632 1.1 jruoho if (Info->InitArgs)
633 1.1 jruoho {
634 1.10 christos AcpiDbUint32ToHexString (Info->NumCreated,
635 1.10 christos Info->IndexOfThreadStr);
636 1.10 christos AcpiDbUint32ToHexString ((UINT32) AcpiOsGetThreadId (),
637 1.10 christos Info->IdOfThreadStr);
638 1.1 jruoho }
639 1.1 jruoho
640 1.1 jruoho if (Info->Threads && (Info->NumCreated < Info->NumThreads))
641 1.1 jruoho {
642 1.3 jruoho Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId();
643 1.1 jruoho }
644 1.1 jruoho
645 1.1 jruoho LocalInfo = *Info;
646 1.1 jruoho LocalInfo.Args = LocalInfo.Arguments;
647 1.1 jruoho LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr;
648 1.1 jruoho LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr;
649 1.1 jruoho LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr;
650 1.1 jruoho LocalInfo.Arguments[3] = NULL;
651 1.1 jruoho
652 1.4 jruoho LocalInfo.Types = LocalInfo.ArgTypes;
653 1.4 jruoho
654 1.1 jruoho (void) AcpiOsSignalSemaphore (Info->InfoGate, 1);
655 1.1 jruoho
656 1.1 jruoho for (i = 0; i < Info->NumLoops; i++)
657 1.1 jruoho {
658 1.1 jruoho Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj);
659 1.1 jruoho if (ACPI_FAILURE (Status))
660 1.1 jruoho {
661 1.5 christos AcpiOsPrintf ("%s During evaluation of %s at iteration %X\n",
662 1.1 jruoho AcpiFormatException (Status), Info->Pathname, i);
663 1.1 jruoho if (Status == AE_ABORT_METHOD)
664 1.1 jruoho {
665 1.1 jruoho break;
666 1.1 jruoho }
667 1.1 jruoho }
668 1.1 jruoho
669 1.1 jruoho #if 0
670 1.1 jruoho if ((i % 100) == 0)
671 1.1 jruoho {
672 1.10 christos AcpiOsPrintf ("%u loops, Thread 0x%x\n",
673 1.10 christos i, AcpiOsGetThreadId ());
674 1.1 jruoho }
675 1.1 jruoho
676 1.1 jruoho if (ReturnObj.Length)
677 1.1 jruoho {
678 1.5 christos AcpiOsPrintf ("Evaluation of %s returned object %p Buflen %X\n",
679 1.10 christos Info->Pathname, ReturnObj.Pointer,
680 1.10 christos (UINT32) ReturnObj.Length);
681 1.1 jruoho AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
682 1.1 jruoho }
683 1.1 jruoho #endif
684 1.1 jruoho }
685 1.1 jruoho
686 1.1 jruoho /* Signal our completion */
687 1.1 jruoho
688 1.1 jruoho Allow = 0;
689 1.10 christos (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate,
690 1.10 christos 1, ACPI_WAIT_FOREVER);
691 1.1 jruoho Info->NumCompleted++;
692 1.1 jruoho
693 1.1 jruoho if (Info->NumCompleted == Info->NumThreads)
694 1.1 jruoho {
695 1.1 jruoho /* Do signal for main thread once only */
696 1.1 jruoho Allow = 1;
697 1.1 jruoho }
698 1.1 jruoho
699 1.1 jruoho (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1);
700 1.1 jruoho
701 1.1 jruoho if (Allow)
702 1.1 jruoho {
703 1.1 jruoho Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1);
704 1.1 jruoho if (ACPI_FAILURE (Status))
705 1.1 jruoho {
706 1.10 christos AcpiOsPrintf (
707 1.10 christos "Could not signal debugger thread sync semaphore, %s\n",
708 1.1 jruoho AcpiFormatException (Status));
709 1.1 jruoho }
710 1.1 jruoho }
711 1.1 jruoho }
712 1.1 jruoho
713 1.1 jruoho
714 1.1 jruoho /*******************************************************************************
715 1.1 jruoho *
716 1.14 christos * FUNCTION: AcpiDbSingleExecutionThread
717 1.14 christos *
718 1.14 christos * PARAMETERS: Context - Method info struct
719 1.14 christos *
720 1.14 christos * RETURN: None
721 1.14 christos *
722 1.14 christos * DESCRIPTION: Create one thread and execute a method
723 1.14 christos *
724 1.14 christos ******************************************************************************/
725 1.14 christos
726 1.14 christos static void ACPI_SYSTEM_XFACE
727 1.14 christos AcpiDbSingleExecutionThread (
728 1.14 christos void *Context)
729 1.14 christos {
730 1.14 christos ACPI_DB_METHOD_INFO *Info = Context;
731 1.14 christos ACPI_STATUS Status;
732 1.14 christos ACPI_BUFFER ReturnObj;
733 1.14 christos
734 1.14 christos
735 1.14 christos AcpiOsPrintf ("\n");
736 1.14 christos
737 1.14 christos Status = AcpiDbExecuteMethod (Info, &ReturnObj);
738 1.14 christos if (ACPI_FAILURE (Status))
739 1.14 christos {
740 1.14 christos AcpiOsPrintf ("%s During evaluation of %s\n",
741 1.14 christos AcpiFormatException (Status), Info->Pathname);
742 1.14 christos return;
743 1.14 christos }
744 1.14 christos
745 1.14 christos /* Display a return object, if any */
746 1.14 christos
747 1.14 christos if (ReturnObj.Length)
748 1.14 christos {
749 1.14 christos AcpiOsPrintf ("Evaluation of %s returned object %p, "
750 1.14 christos "external buffer length %X\n",
751 1.14 christos AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
752 1.14 christos (UINT32) ReturnObj.Length);
753 1.14 christos
754 1.14 christos AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
755 1.14 christos }
756 1.14 christos
757 1.14 christos AcpiOsPrintf ("\nBackground thread completed\n%c ",
758 1.14 christos ACPI_DEBUGGER_COMMAND_PROMPT);
759 1.14 christos }
760 1.14 christos
761 1.14 christos
762 1.14 christos /*******************************************************************************
763 1.14 christos *
764 1.14 christos * FUNCTION: AcpiDbCreateExecutionThread
765 1.14 christos *
766 1.14 christos * PARAMETERS: MethodNameArg - Control method to execute
767 1.14 christos * Arguments - Array of arguments to the method
768 1.14 christos * Types - Corresponding array of object types
769 1.14 christos *
770 1.14 christos * RETURN: None
771 1.14 christos *
772 1.14 christos * DESCRIPTION: Create a single thread to evaluate a namespace object. Handles
773 1.14 christos * arguments passed on command line for control methods.
774 1.14 christos *
775 1.14 christos ******************************************************************************/
776 1.14 christos
777 1.14 christos void
778 1.14 christos AcpiDbCreateExecutionThread (
779 1.14 christos char *MethodNameArg,
780 1.14 christos char **Arguments,
781 1.14 christos ACPI_OBJECT_TYPE *Types)
782 1.14 christos {
783 1.14 christos ACPI_STATUS Status;
784 1.14 christos UINT32 i;
785 1.14 christos
786 1.14 christos
787 1.14 christos memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
788 1.14 christos AcpiGbl_DbMethodInfo.Name = MethodNameArg;
789 1.14 christos AcpiGbl_DbMethodInfo.InitArgs = 1;
790 1.14 christos AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
791 1.14 christos AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes;
792 1.14 christos
793 1.14 christos /* Setup method arguments, up to 7 (0-6) */
794 1.14 christos
795 1.14 christos for (i = 0; (i < ACPI_METHOD_NUM_ARGS) && *Arguments; i++)
796 1.14 christos {
797 1.14 christos AcpiGbl_DbMethodInfo.Arguments[i] = *Arguments;
798 1.14 christos Arguments++;
799 1.14 christos
800 1.14 christos AcpiGbl_DbMethodInfo.ArgTypes[i] = *Types;
801 1.14 christos Types++;
802 1.14 christos }
803 1.14 christos
804 1.14 christos Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
805 1.14 christos if (ACPI_FAILURE (Status))
806 1.14 christos {
807 1.14 christos return;
808 1.14 christos }
809 1.14 christos
810 1.14 christos /* Get the NS node, determines existence also */
811 1.14 christos
812 1.14 christos Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
813 1.14 christos &AcpiGbl_DbMethodInfo.Method);
814 1.14 christos if (ACPI_FAILURE (Status))
815 1.14 christos {
816 1.14 christos AcpiOsPrintf ("%s Could not get handle for %s\n",
817 1.14 christos AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname);
818 1.14 christos return;
819 1.14 christos }
820 1.14 christos
821 1.14 christos Status = AcpiOsExecute (OSL_DEBUGGER_EXEC_THREAD,
822 1.14 christos AcpiDbSingleExecutionThread, &AcpiGbl_DbMethodInfo);
823 1.14 christos if (ACPI_FAILURE (Status))
824 1.14 christos {
825 1.14 christos return;
826 1.14 christos }
827 1.14 christos
828 1.14 christos AcpiOsPrintf ("\nBackground thread started\n");
829 1.14 christos }
830 1.14 christos
831 1.14 christos
832 1.14 christos /*******************************************************************************
833 1.14 christos *
834 1.1 jruoho * FUNCTION: AcpiDbCreateExecutionThreads
835 1.1 jruoho *
836 1.1 jruoho * PARAMETERS: NumThreadsArg - Number of threads to create
837 1.1 jruoho * NumLoopsArg - Loop count for the thread(s)
838 1.1 jruoho * MethodNameArg - Control method to execute
839 1.1 jruoho *
840 1.1 jruoho * RETURN: None
841 1.1 jruoho *
842 1.1 jruoho * DESCRIPTION: Create threads to execute method(s)
843 1.1 jruoho *
844 1.1 jruoho ******************************************************************************/
845 1.1 jruoho
846 1.1 jruoho void
847 1.1 jruoho AcpiDbCreateExecutionThreads (
848 1.1 jruoho char *NumThreadsArg,
849 1.1 jruoho char *NumLoopsArg,
850 1.1 jruoho char *MethodNameArg)
851 1.1 jruoho {
852 1.1 jruoho ACPI_STATUS Status;
853 1.1 jruoho UINT32 NumThreads;
854 1.1 jruoho UINT32 NumLoops;
855 1.1 jruoho UINT32 i;
856 1.1 jruoho UINT32 Size;
857 1.1 jruoho ACPI_MUTEX MainThreadGate;
858 1.1 jruoho ACPI_MUTEX ThreadCompleteGate;
859 1.1 jruoho ACPI_MUTEX InfoGate;
860 1.1 jruoho
861 1.1 jruoho
862 1.1 jruoho /* Get the arguments */
863 1.1 jruoho
864 1.9 christos NumThreads = strtoul (NumThreadsArg, NULL, 0);
865 1.10 christos NumLoops = strtoul (NumLoopsArg, NULL, 0);
866 1.1 jruoho
867 1.1 jruoho if (!NumThreads || !NumLoops)
868 1.1 jruoho {
869 1.1 jruoho AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
870 1.1 jruoho NumThreads, NumLoops);
871 1.1 jruoho return;
872 1.1 jruoho }
873 1.1 jruoho
874 1.1 jruoho /*
875 1.1 jruoho * Create the semaphore for synchronization of
876 1.1 jruoho * the created threads with the main thread.
877 1.1 jruoho */
878 1.1 jruoho Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate);
879 1.1 jruoho if (ACPI_FAILURE (Status))
880 1.1 jruoho {
881 1.10 christos AcpiOsPrintf ("Could not create semaphore for "
882 1.10 christos "synchronization with the main thread, %s\n",
883 1.1 jruoho AcpiFormatException (Status));
884 1.1 jruoho return;
885 1.1 jruoho }
886 1.1 jruoho
887 1.1 jruoho /*
888 1.1 jruoho * Create the semaphore for synchronization
889 1.1 jruoho * between the created threads.
890 1.1 jruoho */
891 1.1 jruoho Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate);
892 1.1 jruoho if (ACPI_FAILURE (Status))
893 1.1 jruoho {
894 1.10 christos AcpiOsPrintf ("Could not create semaphore for "
895 1.10 christos "synchronization between the created threads, %s\n",
896 1.1 jruoho AcpiFormatException (Status));
897 1.10 christos
898 1.1 jruoho (void) AcpiOsDeleteSemaphore (MainThreadGate);
899 1.1 jruoho return;
900 1.1 jruoho }
901 1.1 jruoho
902 1.1 jruoho Status = AcpiOsCreateSemaphore (1, 1, &InfoGate);
903 1.1 jruoho if (ACPI_FAILURE (Status))
904 1.1 jruoho {
905 1.10 christos AcpiOsPrintf ("Could not create semaphore for "
906 1.10 christos "synchronization of AcpiGbl_DbMethodInfo, %s\n",
907 1.1 jruoho AcpiFormatException (Status));
908 1.10 christos
909 1.1 jruoho (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
910 1.1 jruoho (void) AcpiOsDeleteSemaphore (MainThreadGate);
911 1.1 jruoho return;
912 1.1 jruoho }
913 1.1 jruoho
914 1.9 christos memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
915 1.1 jruoho
916 1.1 jruoho /* Array to store IDs of threads */
917 1.1 jruoho
918 1.1 jruoho AcpiGbl_DbMethodInfo.NumThreads = NumThreads;
919 1.3 jruoho Size = sizeof (ACPI_THREAD_ID) * AcpiGbl_DbMethodInfo.NumThreads;
920 1.10 christos
921 1.3 jruoho AcpiGbl_DbMethodInfo.Threads = AcpiOsAllocate (Size);
922 1.1 jruoho if (AcpiGbl_DbMethodInfo.Threads == NULL)
923 1.1 jruoho {
924 1.1 jruoho AcpiOsPrintf ("No memory for thread IDs array\n");
925 1.1 jruoho (void) AcpiOsDeleteSemaphore (MainThreadGate);
926 1.1 jruoho (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
927 1.1 jruoho (void) AcpiOsDeleteSemaphore (InfoGate);
928 1.1 jruoho return;
929 1.1 jruoho }
930 1.9 christos memset (AcpiGbl_DbMethodInfo.Threads, 0, Size);
931 1.1 jruoho
932 1.1 jruoho /* Setup the context to be passed to each thread */
933 1.1 jruoho
934 1.1 jruoho AcpiGbl_DbMethodInfo.Name = MethodNameArg;
935 1.1 jruoho AcpiGbl_DbMethodInfo.Flags = 0;
936 1.1 jruoho AcpiGbl_DbMethodInfo.NumLoops = NumLoops;
937 1.1 jruoho AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate;
938 1.1 jruoho AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate;
939 1.1 jruoho AcpiGbl_DbMethodInfo.InfoGate = InfoGate;
940 1.1 jruoho
941 1.1 jruoho /* Init arguments to be passed to method */
942 1.1 jruoho
943 1.1 jruoho AcpiGbl_DbMethodInfo.InitArgs = 1;
944 1.1 jruoho AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
945 1.1 jruoho AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr;
946 1.1 jruoho AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr;
947 1.1 jruoho AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr;
948 1.1 jruoho AcpiGbl_DbMethodInfo.Arguments[3] = NULL;
949 1.4 jruoho
950 1.4 jruoho AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes;
951 1.4 jruoho AcpiGbl_DbMethodInfo.ArgTypes[0] = ACPI_TYPE_INTEGER;
952 1.4 jruoho AcpiGbl_DbMethodInfo.ArgTypes[1] = ACPI_TYPE_INTEGER;
953 1.4 jruoho AcpiGbl_DbMethodInfo.ArgTypes[2] = ACPI_TYPE_INTEGER;
954 1.4 jruoho
955 1.5 christos AcpiDbUint32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr);
956 1.1 jruoho
957 1.5 christos Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
958 1.5 christos if (ACPI_FAILURE (Status))
959 1.5 christos {
960 1.5 christos goto CleanupAndExit;
961 1.5 christos }
962 1.5 christos
963 1.5 christos /* Get the NS node, determines existence also */
964 1.5 christos
965 1.5 christos Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
966 1.5 christos &AcpiGbl_DbMethodInfo.Method);
967 1.5 christos if (ACPI_FAILURE (Status))
968 1.5 christos {
969 1.5 christos AcpiOsPrintf ("%s Could not get handle for %s\n",
970 1.5 christos AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname);
971 1.5 christos goto CleanupAndExit;
972 1.5 christos }
973 1.1 jruoho
974 1.1 jruoho /* Create the threads */
975 1.1 jruoho
976 1.1 jruoho AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
977 1.1 jruoho NumThreads, NumLoops);
978 1.1 jruoho
979 1.1 jruoho for (i = 0; i < (NumThreads); i++)
980 1.1 jruoho {
981 1.10 christos Status = AcpiOsExecute (OSL_DEBUGGER_EXEC_THREAD, AcpiDbMethodThread,
982 1.1 jruoho &AcpiGbl_DbMethodInfo);
983 1.1 jruoho if (ACPI_FAILURE (Status))
984 1.1 jruoho {
985 1.1 jruoho break;
986 1.1 jruoho }
987 1.1 jruoho }
988 1.1 jruoho
989 1.1 jruoho /* Wait for all threads to complete */
990 1.1 jruoho
991 1.1 jruoho (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER);
992 1.1 jruoho
993 1.1 jruoho AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
994 1.1 jruoho AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads);
995 1.1 jruoho AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
996 1.1 jruoho
997 1.5 christos CleanupAndExit:
998 1.5 christos
999 1.1 jruoho /* Cleanup and exit */
1000 1.1 jruoho
1001 1.1 jruoho (void) AcpiOsDeleteSemaphore (MainThreadGate);
1002 1.1 jruoho (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
1003 1.1 jruoho (void) AcpiOsDeleteSemaphore (InfoGate);
1004 1.1 jruoho
1005 1.1 jruoho AcpiOsFree (AcpiGbl_DbMethodInfo.Threads);
1006 1.1 jruoho AcpiGbl_DbMethodInfo.Threads = NULL;
1007 1.1 jruoho }
1008