Print this page
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/debugger/dbmethod.c
+++ new/usr/src/common/acpica/components/debugger/dbmethod.c
1 1 /*******************************************************************************
2 2 *
3 3 * Module Name: dbmethod - Debug commands for control methods
4 4 *
5 5 ******************************************************************************/
6 6
7 7 /*
8 - * Copyright (C) 2000 - 2011, Intel Corp.
8 + * Copyright (C) 2000 - 2013, Intel Corp.
9 9 * All rights reserved.
10 10 *
11 11 * Redistribution and use in source and binary forms, with or without
12 12 * modification, are permitted provided that the following conditions
13 13 * are met:
14 14 * 1. Redistributions of source code must retain the above copyright
15 15 * notice, this list of conditions, and the following disclaimer,
16 16 * without modification.
17 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 18 * substantially similar to the "NO WARRANTY" disclaimer below
19 19 * ("Disclaimer") and any redistribution must be conditioned upon
20 20 * including a substantially similar Disclaimer requirement for further
21 21 * binary redistribution.
22 22 * 3. Neither the names of the above-listed copyright holders nor the names
23 23 * of any contributors may be used to endorse or promote products derived
24 24 * from this software without specific prior written permission.
25 25 *
26 26 * Alternatively, this software may be distributed under the terms of the
27 27 * GNU General Public License ("GPL") version 2 as published by the Free
28 28 * Software Foundation.
29 29 *
30 30 * NO WARRANTY
31 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 41 * POSSIBILITY OF SUCH DAMAGES.
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
42 42 */
43 43
44 44
45 45 #include "acpi.h"
46 46 #include "accommon.h"
47 47 #include "acdispat.h"
48 48 #include "acnamesp.h"
49 49 #include "acdebug.h"
50 50 #include "acdisasm.h"
51 51 #include "acparser.h"
52 +#include "acpredef.h"
52 53
53 54
54 55 #ifdef ACPI_DEBUGGER
55 56
56 57 #define _COMPONENT ACPI_CA_DEBUGGER
57 58 ACPI_MODULE_NAME ("dbmethod")
58 59
59 60
60 61 /* Local prototypes */
61 62
62 63 static ACPI_STATUS
63 64 AcpiDbWalkForExecute (
64 65 ACPI_HANDLE ObjHandle,
65 66 UINT32 NestingLevel,
66 67 void *Context,
67 68 void **ReturnValue);
68 69
69 70
70 71 /*******************************************************************************
71 72 *
72 73 * FUNCTION: AcpiDbSetMethodBreakpoint
73 74 *
74 75 * PARAMETERS: Location - AML offset of breakpoint
75 76 * WalkState - Current walk info
76 77 * Op - Current Op (from parse walk)
77 78 *
78 79 * RETURN: None
79 80 *
80 81 * DESCRIPTION: Set a breakpoint in a control method at the specified
81 82 * AML offset
82 83 *
83 84 ******************************************************************************/
84 85
85 86 void
86 87 AcpiDbSetMethodBreakpoint (
87 88 char *Location,
88 89 ACPI_WALK_STATE *WalkState,
89 90 ACPI_PARSE_OBJECT *Op)
90 91 {
91 92 UINT32 Address;
92 93
93 94
94 95 if (!Op)
95 96 {
96 97 AcpiOsPrintf ("There is no method currently executing\n");
97 98 return;
98 99 }
99 100
100 101 /* Get and verify the breakpoint address */
101 102
102 103 Address = ACPI_STRTOUL (Location, NULL, 16);
103 104 if (Address <= Op->Common.AmlOffset)
104 105 {
105 106 AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
106 107 Address, Op->Common.AmlOffset);
107 108 }
108 109
109 110 /* Save breakpoint in current walk */
110 111
111 112 WalkState->UserBreakpoint = Address;
112 113 AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
113 114 }
114 115
115 116
116 117 /*******************************************************************************
117 118 *
118 119 * FUNCTION: AcpiDbSetMethodCallBreakpoint
119 120 *
120 121 * PARAMETERS: Op - Current Op (from parse walk)
121 122 *
122 123 * RETURN: None
123 124 *
124 125 * DESCRIPTION: Set a breakpoint in a control method at the specified
125 126 * AML offset
126 127 *
127 128 ******************************************************************************/
128 129
129 130 void
130 131 AcpiDbSetMethodCallBreakpoint (
131 132 ACPI_PARSE_OBJECT *Op)
132 133 {
133 134
134 135
135 136 if (!Op)
136 137 {
137 138 AcpiOsPrintf ("There is no method currently executing\n");
138 139 return;
139 140 }
140 141
141 142 AcpiGbl_StepToNextCall = TRUE;
142 143 }
143 144
144 145
145 146 /*******************************************************************************
146 147 *
147 148 * FUNCTION: AcpiDbSetMethodData
148 149 *
149 150 * PARAMETERS: TypeArg - L for local, A for argument
150 151 * IndexArg - which one
151 152 * ValueArg - Value to set.
152 153 *
153 154 * RETURN: None
154 155 *
155 156 * DESCRIPTION: Set a local or argument for the running control method.
156 157 * NOTE: only object supported is Number.
157 158 *
158 159 ******************************************************************************/
159 160
160 161 void
161 162 AcpiDbSetMethodData (
162 163 char *TypeArg,
163 164 char *IndexArg,
164 165 char *ValueArg)
165 166 {
166 167 char Type;
167 168 UINT32 Index;
168 169 UINT32 Value;
169 170 ACPI_WALK_STATE *WalkState;
170 171 ACPI_OPERAND_OBJECT *ObjDesc;
171 172 ACPI_STATUS Status;
172 173 ACPI_NAMESPACE_NODE *Node;
173 174
174 175
175 176 /* Validate TypeArg */
176 177
177 178 AcpiUtStrupr (TypeArg);
178 179 Type = TypeArg[0];
179 180 if ((Type != 'L') &&
180 181 (Type != 'A') &&
181 182 (Type != 'N'))
182 183 {
183 184 AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
184 185 return;
185 186 }
186 187
187 188 Value = ACPI_STRTOUL (ValueArg, NULL, 16);
188 189
189 190 if (Type == 'N')
190 191 {
191 192 Node = AcpiDbConvertToNode (IndexArg);
192 193 if (Node->Type != ACPI_TYPE_INTEGER)
193 194 {
194 195 AcpiOsPrintf ("Can only set Integer nodes\n");
195 196 return;
196 197 }
197 198 ObjDesc = Node->Object;
198 199 ObjDesc->Integer.Value = Value;
199 200 return;
200 201 }
201 202
202 203 /* Get the index and value */
203 204
204 205 Index = ACPI_STRTOUL (IndexArg, NULL, 16);
205 206
206 207 WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
207 208 if (!WalkState)
208 209 {
209 210 AcpiOsPrintf ("There is no method currently executing\n");
210 211 return;
211 212 }
212 213
213 214 /* Create and initialize the new object */
214 215
215 216 ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
216 217 if (!ObjDesc)
217 218 {
218 219 AcpiOsPrintf ("Could not create an internal object\n");
219 220 return;
220 221 }
221 222
222 223 /* Store the new object into the target */
223 224
224 225 switch (Type)
225 226 {
226 227 case 'A':
227 228
228 229 /* Set a method argument */
229 230
230 231 if (Index > ACPI_METHOD_MAX_ARG)
231 232 {
232 233 AcpiOsPrintf ("Arg%u - Invalid argument name\n", Index);
233 234 goto Cleanup;
234 235 }
235 236
236 237 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG, Index, ObjDesc,
237 238 WalkState);
238 239 if (ACPI_FAILURE (Status))
239 240 {
240 241 goto Cleanup;
241 242 }
242 243
243 244 ObjDesc = WalkState->Arguments[Index].Object;
244 245
245 246 AcpiOsPrintf ("Arg%u: ", Index);
246 247 AcpiDmDisplayInternalObject (ObjDesc, WalkState);
247 248 break;
248 249
249 250 case 'L':
250 251
251 252 /* Set a method local */
252 253
253 254 if (Index > ACPI_METHOD_MAX_LOCAL)
254 255 {
255 256 AcpiOsPrintf ("Local%u - Invalid local variable name\n", Index);
256 257 goto Cleanup;
257 258 }
258 259
259 260 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL, Index, ObjDesc,
260 261 WalkState);
261 262 if (ACPI_FAILURE (Status))
262 263 {
↓ open down ↓ |
201 lines elided |
↑ open up ↑ |
263 264 goto Cleanup;
264 265 }
265 266
266 267 ObjDesc = WalkState->LocalVariables[Index].Object;
267 268
268 269 AcpiOsPrintf ("Local%u: ", Index);
269 270 AcpiDmDisplayInternalObject (ObjDesc, WalkState);
270 271 break;
271 272
272 273 default:
274 +
273 275 break;
274 276 }
275 277
276 278 Cleanup:
277 279 AcpiUtRemoveReference (ObjDesc);
278 280 }
279 281
280 282
281 283 /*******************************************************************************
282 284 *
283 285 * FUNCTION: AcpiDbDisassembleAml
284 286 *
285 287 * PARAMETERS: Statements - Number of statements to disassemble
286 288 * Op - Current Op (from parse walk)
287 289 *
288 290 * RETURN: None
289 291 *
290 292 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
291 293 * of statements specified.
292 294 *
293 295 ******************************************************************************/
294 296
295 297 void
296 298 AcpiDbDisassembleAml (
297 299 char *Statements,
298 300 ACPI_PARSE_OBJECT *Op)
299 301 {
300 302 UINT32 NumStatements = 8;
301 303
302 304
303 305 if (!Op)
304 306 {
305 307 AcpiOsPrintf ("There is no method currently executing\n");
306 308 return;
307 309 }
308 310
309 311 if (Statements)
310 312 {
311 313 NumStatements = ACPI_STRTOUL (Statements, NULL, 0);
312 314 }
313 315
314 316 AcpiDmDisassemble (NULL, Op, NumStatements);
315 317 }
316 318
317 319
318 320 /*******************************************************************************
319 321 *
320 322 * FUNCTION: AcpiDbDisassembleMethod
321 323 *
322 324 * PARAMETERS: Name - Name of control method
323 325 *
324 326 * RETURN: None
325 327 *
326 328 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
327 329 * of statements specified.
328 330 *
329 331 ******************************************************************************/
330 332
331 333 ACPI_STATUS
332 334 AcpiDbDisassembleMethod (
333 335 char *Name)
334 336 {
335 337 ACPI_STATUS Status;
336 338 ACPI_PARSE_OBJECT *Op;
337 339 ACPI_WALK_STATE *WalkState;
↓ open down ↓ |
55 lines elided |
↑ open up ↑ |
338 340 ACPI_OPERAND_OBJECT *ObjDesc;
339 341 ACPI_NAMESPACE_NODE *Method;
340 342
341 343
342 344 Method = AcpiDbConvertToNode (Name);
343 345 if (!Method)
344 346 {
345 347 return (AE_BAD_PARAMETER);
346 348 }
347 349
350 + if (Method->Type != ACPI_TYPE_METHOD)
351 + {
352 + ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
353 + Name, AcpiUtGetTypeName (Method->Type)));
354 + return (AE_BAD_PARAMETER);
355 + }
356 +
348 357 ObjDesc = Method->Object;
349 358
350 359 Op = AcpiPsCreateScopeOp ();
351 360 if (!Op)
352 361 {
353 362 return (AE_NO_MEMORY);
354 363 }
355 364
356 365 /* Create and initialize a new walk state */
357 366
358 367 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
359 368 if (!WalkState)
360 369 {
361 370 return (AE_NO_MEMORY);
362 371 }
363 372
364 373 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
365 - ObjDesc->Method.AmlStart,
366 - ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
374 + ObjDesc->Method.AmlStart,
375 + ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
367 376 if (ACPI_FAILURE (Status))
368 377 {
369 378 return (Status);
370 379 }
371 380
372 - /* Parse the AML */
381 + Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
382 + WalkState->OwnerId = ObjDesc->Method.OwnerId;
373 383
384 + /* Push start scope on scope stack and make it current */
385 +
386 + Status = AcpiDsScopeStackPush (Method,
387 + Method->Type, WalkState);
388 + if (ACPI_FAILURE (Status))
389 + {
390 + return (Status);
391 + }
392 +
393 + /* Parse the entire method AML including deferred operators */
394 +
374 395 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
375 396 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
397 +
376 398 Status = AcpiPsParseAml (WalkState);
399 + (void) AcpiDmParseDeferredOps (Op);
377 400
401 + /* Now we can disassemble the method */
402 +
403 + AcpiGbl_DbOpt_verbose = FALSE;
378 404 AcpiDmDisassemble (NULL, Op, 0);
405 + AcpiGbl_DbOpt_verbose = TRUE;
406 +
379 407 AcpiPsDeleteParseTree (Op);
408 +
409 + /* Method cleanup */
410 +
411 + AcpiNsDeleteNamespaceSubtree (Method);
412 + AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
413 + AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
380 414 return (AE_OK);
381 415 }
382 416
383 417
384 418 /*******************************************************************************
385 419 *
386 420 * FUNCTION: AcpiDbWalkForExecute
387 421 *
388 422 * PARAMETERS: Callback from WalkNamespace
389 423 *
390 424 * RETURN: Status
391 425 *
392 426 * DESCRIPTION: Batch execution module. Currently only executes predefined
393 427 * ACPI names.
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
394 428 *
395 429 ******************************************************************************/
396 430
397 431 static ACPI_STATUS
398 432 AcpiDbWalkForExecute (
399 433 ACPI_HANDLE ObjHandle,
400 434 UINT32 NestingLevel,
401 435 void *Context,
402 436 void **ReturnValue)
403 437 {
404 - ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
405 - ACPI_EXECUTE_WALK *Info = (ACPI_EXECUTE_WALK *) Context;
406 - ACPI_BUFFER ReturnObj;
407 - ACPI_STATUS Status;
408 - char *Pathname;
409 - UINT32 i;
410 - ACPI_DEVICE_INFO *ObjInfo;
411 - ACPI_OBJECT_LIST ParamObjects;
412 - ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];
413 - const ACPI_PREDEFINED_INFO *Predefined;
438 + ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
439 + ACPI_DB_EXECUTE_WALK *Info = (ACPI_DB_EXECUTE_WALK *) Context;
440 + char *Pathname;
441 + const ACPI_PREDEFINED_INFO *Predefined;
442 + ACPI_DEVICE_INFO *ObjInfo;
443 + ACPI_OBJECT_LIST ParamObjects;
444 + ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];
445 + ACPI_OBJECT *ThisParam;
446 + ACPI_BUFFER ReturnObj;
447 + ACPI_STATUS Status;
448 + UINT16 ArgTypeList;
449 + UINT8 ArgCount;
450 + UINT8 ArgType;
451 + UINT32 i;
414 452
415 453
416 - Predefined = AcpiNsCheckForPredefinedName (Node);
454 + /* The name must be a predefined ACPI name */
455 +
456 + Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
417 457 if (!Predefined)
418 458 {
419 459 return (AE_OK);
420 460 }
421 461
422 462 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
423 463 {
424 464 return (AE_OK);
425 465 }
426 466
427 467 Pathname = AcpiNsGetExternalPathname (Node);
428 468 if (!Pathname)
429 469 {
430 470 return (AE_OK);
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
431 471 }
432 472
433 473 /* Get the object info for number of method parameters */
434 474
435 475 Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
436 476 if (ACPI_FAILURE (Status))
437 477 {
438 478 return (Status);
439 479 }
440 480
481 + ParamObjects.Count = 0;
441 482 ParamObjects.Pointer = NULL;
442 - ParamObjects.Count = 0;
443 483
444 484 if (ObjInfo->Type == ACPI_TYPE_METHOD)
445 485 {
446 - /* Setup default parameters */
486 + /* Setup default parameters (with proper types) */
447 487
448 - for (i = 0; i < ObjInfo->ParamCount; i++)
488 + ArgTypeList = Predefined->Info.ArgumentList;
489 + ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList);
490 +
491 + /*
492 + * Setup the ACPI-required number of arguments, regardless of what
493 + * the actual method defines. If there is a difference, then the
494 + * method is wrong and a warning will be issued during execution.
495 + */
496 + ThisParam = Params;
497 + for (i = 0; i < ArgCount; i++)
449 498 {
450 - Params[i].Type = ACPI_TYPE_INTEGER;
451 - Params[i].Integer.Value = 1;
499 + ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList);
500 + ThisParam->Type = ArgType;
501 +
502 + switch (ArgType)
503 + {
504 + case ACPI_TYPE_INTEGER:
505 +
506 + ThisParam->Integer.Value = 1;
507 + break;
508 +
509 + case ACPI_TYPE_STRING:
510 +
511 + ThisParam->String.Pointer = "This is the default argument string";
512 + ThisParam->String.Length = ACPI_STRLEN (ThisParam->String.Pointer);
513 + break;
514 +
515 + case ACPI_TYPE_BUFFER:
516 +
517 + ThisParam->Buffer.Pointer = (UINT8 *) Params; /* just a garbage buffer */
518 + ThisParam->Buffer.Length = 48;
519 + break;
520 +
521 + case ACPI_TYPE_PACKAGE:
522 +
523 + ThisParam->Package.Elements = NULL;
524 + ThisParam->Package.Count = 0;
525 + break;
526 +
527 + default:
528 +
529 + AcpiOsPrintf ("%s: Unsupported argument type: %u\n",
530 + Pathname, ArgType);
531 + break;
532 + }
533 +
534 + ThisParam++;
452 535 }
453 536
454 - ParamObjects.Pointer = Params;
455 - ParamObjects.Count = ObjInfo->ParamCount;
537 + ParamObjects.Count = ArgCount;
538 + ParamObjects.Pointer = Params;
456 539 }
457 540
458 541 ACPI_FREE (ObjInfo);
459 542 ReturnObj.Pointer = NULL;
460 543 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
461 544
462 545 /* Do the actual method execution */
463 546
464 547 AcpiGbl_MethodExecuting = TRUE;
465 548
466 549 Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
467 550
468 551 AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
469 552 AcpiGbl_MethodExecuting = FALSE;
470 553 ACPI_FREE (Pathname);
471 554
472 555 /* Ignore status from method execution */
473 556
474 557 Status = AE_OK;
475 558
476 559 /* Update count, check if we have executed enough methods */
477 560
478 561 Info->Count++;
479 562 if (Info->Count >= Info->MaxCount)
480 563 {
481 564 Status = AE_CTRL_TERMINATE;
482 565 }
483 566
484 567 return (Status);
485 568 }
486 569
487 570
488 571 /*******************************************************************************
489 572 *
490 573 * FUNCTION: AcpiDbBatchExecute
491 574 *
492 575 * PARAMETERS: CountArg - Max number of methods to execute
493 576 *
494 577 * RETURN: None
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
495 578 *
496 579 * DESCRIPTION: Namespace batch execution. Execute predefined names in the
497 580 * namespace, up to the max count, if specified.
498 581 *
499 582 ******************************************************************************/
500 583
501 584 void
502 585 AcpiDbBatchExecute (
503 586 char *CountArg)
504 587 {
505 - ACPI_EXECUTE_WALK Info;
588 + ACPI_DB_EXECUTE_WALK Info;
506 589
507 590
508 591 Info.Count = 0;
509 592 Info.MaxCount = ACPI_UINT32_MAX;
510 593
511 594 if (CountArg)
512 595 {
513 596 Info.MaxCount = ACPI_STRTOUL (CountArg, NULL, 0);
514 597 }
515 598
516 599
517 600 /* Search all nodes in namespace */
518 601
519 602 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
520 603 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
521 604
522 - AcpiOsPrintf ("Executed %u predefined names in the namespace\n", Info.Count);
605 + AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count);
523 606 }
524 607
525 608 #endif /* ACPI_DEBUGGER */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX