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