1
1

psparse.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. /******************************************************************************
  2. *
  3. * Module Name: psparse - Parser top level AML parse routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2019, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. /*
  43. * Parse the AML and build an operation tree as most interpreters,
  44. * like Perl, do. Parsing is done by hand rather than with a YACC
  45. * generated parser to tightly constrain stack and dynamic memory
  46. * usage. At the same time, parsing is kept flexible and the code
  47. * fairly compact by parsing based on a list of AML opcode
  48. * templates in AmlOpInfo[]
  49. */
  50. #include "acpi.h"
  51. #include "accommon.h"
  52. #include "acparser.h"
  53. #include "acdispat.h"
  54. #include "amlcode.h"
  55. #include "acinterp.h"
  56. #include "acnamesp.h"
  57. #define _COMPONENT ACPI_PARSER
  58. ACPI_MODULE_NAME ("psparse")
  59. /*******************************************************************************
  60. *
  61. * FUNCTION: AcpiPsGetOpcodeSize
  62. *
  63. * PARAMETERS: Opcode - An AML opcode
  64. *
  65. * RETURN: Size of the opcode, in bytes (1 or 2)
  66. *
  67. * DESCRIPTION: Get the size of the current opcode.
  68. *
  69. ******************************************************************************/
  70. UINT32
  71. AcpiPsGetOpcodeSize (
  72. UINT32 Opcode)
  73. {
  74. /* Extended (2-byte) opcode if > 255 */
  75. if (Opcode > 0x00FF)
  76. {
  77. return (2);
  78. }
  79. /* Otherwise, just a single byte opcode */
  80. return (1);
  81. }
  82. /*******************************************************************************
  83. *
  84. * FUNCTION: AcpiPsPeekOpcode
  85. *
  86. * PARAMETERS: ParserState - A parser state object
  87. *
  88. * RETURN: Next AML opcode
  89. *
  90. * DESCRIPTION: Get next AML opcode (without incrementing AML pointer)
  91. *
  92. ******************************************************************************/
  93. UINT16
  94. AcpiPsPeekOpcode (
  95. ACPI_PARSE_STATE *ParserState)
  96. {
  97. UINT8 *Aml;
  98. UINT16 Opcode;
  99. Aml = ParserState->Aml;
  100. Opcode = (UINT16) ACPI_GET8 (Aml);
  101. if (Opcode == AML_EXTENDED_PREFIX)
  102. {
  103. /* Extended opcode, get the second opcode byte */
  104. Aml++;
  105. Opcode = (UINT16) ((Opcode << 8) | ACPI_GET8 (Aml));
  106. }
  107. return (Opcode);
  108. }
  109. /*******************************************************************************
  110. *
  111. * FUNCTION: AcpiPsCompleteThisOp
  112. *
  113. * PARAMETERS: WalkState - Current State
  114. * Op - Op to complete
  115. *
  116. * RETURN: Status
  117. *
  118. * DESCRIPTION: Perform any cleanup at the completion of an Op.
  119. *
  120. ******************************************************************************/
  121. ACPI_STATUS
  122. AcpiPsCompleteThisOp (
  123. ACPI_WALK_STATE *WalkState,
  124. ACPI_PARSE_OBJECT *Op)
  125. {
  126. ACPI_PARSE_OBJECT *Prev;
  127. ACPI_PARSE_OBJECT *Next;
  128. const ACPI_OPCODE_INFO *ParentInfo;
  129. ACPI_PARSE_OBJECT *ReplacementOp = NULL;
  130. ACPI_STATUS Status = AE_OK;
  131. ACPI_FUNCTION_TRACE_PTR (PsCompleteThisOp, Op);
  132. /* Check for null Op, can happen if AML code is corrupt */
  133. if (!Op)
  134. {
  135. return_ACPI_STATUS (AE_OK); /* OK for now */
  136. }
  137. AcpiExStopTraceOpcode (Op, WalkState);
  138. /* Delete this op and the subtree below it if asked to */
  139. if (((WalkState->ParseFlags & ACPI_PARSE_TREE_MASK) != ACPI_PARSE_DELETE_TREE) ||
  140. (WalkState->OpInfo->Class == AML_CLASS_ARGUMENT))
  141. {
  142. return_ACPI_STATUS (AE_OK);
  143. }
  144. /* Make sure that we only delete this subtree */
  145. if (Op->Common.Parent)
  146. {
  147. Prev = Op->Common.Parent->Common.Value.Arg;
  148. if (!Prev)
  149. {
  150. /* Nothing more to do */
  151. goto Cleanup;
  152. }
  153. /*
  154. * Check if we need to replace the operator and its subtree
  155. * with a return value op (placeholder op)
  156. */
  157. ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode);
  158. switch (ParentInfo->Class)
  159. {
  160. case AML_CLASS_CONTROL:
  161. break;
  162. case AML_CLASS_CREATE:
  163. /*
  164. * These opcodes contain TermArg operands. The current
  165. * op must be replaced by a placeholder return op
  166. */
  167. ReplacementOp = AcpiPsAllocOp (
  168. AML_INT_RETURN_VALUE_OP, Op->Common.Aml);
  169. if (!ReplacementOp)
  170. {
  171. Status = AE_NO_MEMORY;
  172. }
  173. break;
  174. case AML_CLASS_NAMED_OBJECT:
  175. /*
  176. * These opcodes contain TermArg operands. The current
  177. * op must be replaced by a placeholder return op
  178. */
  179. if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP) ||
  180. (Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP) ||
  181. (Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP) ||
  182. (Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
  183. (Op->Common.Parent->Common.AmlOpcode == AML_BANK_FIELD_OP) ||
  184. (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
  185. {
  186. ReplacementOp = AcpiPsAllocOp (
  187. AML_INT_RETURN_VALUE_OP, Op->Common.Aml);
  188. if (!ReplacementOp)
  189. {
  190. Status = AE_NO_MEMORY;
  191. }
  192. }
  193. else if ((Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) &&
  194. (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2))
  195. {
  196. if ((Op->Common.AmlOpcode == AML_BUFFER_OP) ||
  197. (Op->Common.AmlOpcode == AML_PACKAGE_OP) ||
  198. (Op->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
  199. {
  200. ReplacementOp = AcpiPsAllocOp (Op->Common.AmlOpcode,
  201. Op->Common.Aml);
  202. if (!ReplacementOp)
  203. {
  204. Status = AE_NO_MEMORY;
  205. }
  206. else
  207. {
  208. ReplacementOp->Named.Data = Op->Named.Data;
  209. ReplacementOp->Named.Length = Op->Named.Length;
  210. }
  211. }
  212. }
  213. break;
  214. default:
  215. ReplacementOp = AcpiPsAllocOp (
  216. AML_INT_RETURN_VALUE_OP, Op->Common.Aml);
  217. if (!ReplacementOp)
  218. {
  219. Status = AE_NO_MEMORY;
  220. }
  221. }
  222. /* We must unlink this op from the parent tree */
  223. if (Prev == Op)
  224. {
  225. /* This op is the first in the list */
  226. if (ReplacementOp)
  227. {
  228. ReplacementOp->Common.Parent = Op->Common.Parent;
  229. ReplacementOp->Common.Value.Arg = NULL;
  230. ReplacementOp->Common.Node = Op->Common.Node;
  231. Op->Common.Parent->Common.Value.Arg = ReplacementOp;
  232. ReplacementOp->Common.Next = Op->Common.Next;
  233. }
  234. else
  235. {
  236. Op->Common.Parent->Common.Value.Arg = Op->Common.Next;
  237. }
  238. }
  239. /* Search the parent list */
  240. else while (Prev)
  241. {
  242. /* Traverse all siblings in the parent's argument list */
  243. Next = Prev->Common.Next;
  244. if (Next == Op)
  245. {
  246. if (ReplacementOp)
  247. {
  248. ReplacementOp->Common.Parent = Op->Common.Parent;
  249. ReplacementOp->Common.Value.Arg = NULL;
  250. ReplacementOp->Common.Node = Op->Common.Node;
  251. Prev->Common.Next = ReplacementOp;
  252. ReplacementOp->Common.Next = Op->Common.Next;
  253. Next = NULL;
  254. }
  255. else
  256. {
  257. Prev->Common.Next = Op->Common.Next;
  258. Next = NULL;
  259. }
  260. }
  261. Prev = Next;
  262. }
  263. }
  264. Cleanup:
  265. /* Now we can actually delete the subtree rooted at Op */
  266. AcpiPsDeleteParseTree (Op);
  267. return_ACPI_STATUS (Status);
  268. }
  269. /*******************************************************************************
  270. *
  271. * FUNCTION: AcpiPsNextParseState
  272. *
  273. * PARAMETERS: WalkState - Current state
  274. * Op - Current parse op
  275. * CallbackStatus - Status from previous operation
  276. *
  277. * RETURN: Status
  278. *
  279. * DESCRIPTION: Update the parser state based upon the return exception from
  280. * the parser callback.
  281. *
  282. ******************************************************************************/
  283. ACPI_STATUS
  284. AcpiPsNextParseState (
  285. ACPI_WALK_STATE *WalkState,
  286. ACPI_PARSE_OBJECT *Op,
  287. ACPI_STATUS CallbackStatus)
  288. {
  289. ACPI_PARSE_STATE *ParserState = &WalkState->ParserState;
  290. ACPI_STATUS Status = AE_CTRL_PENDING;
  291. ACPI_FUNCTION_TRACE_PTR (PsNextParseState, Op);
  292. switch (CallbackStatus)
  293. {
  294. case AE_CTRL_TERMINATE:
  295. /*
  296. * A control method was terminated via a RETURN statement.
  297. * The walk of this method is complete.
  298. */
  299. ParserState->Aml = ParserState->AmlEnd;
  300. Status = AE_CTRL_TERMINATE;
  301. break;
  302. case AE_CTRL_BREAK:
  303. ParserState->Aml = WalkState->AmlLastWhile;
  304. WalkState->ControlState->Common.Value = FALSE;
  305. Status = AE_CTRL_BREAK;
  306. break;
  307. case AE_CTRL_CONTINUE:
  308. ParserState->Aml = WalkState->AmlLastWhile;
  309. Status = AE_CTRL_CONTINUE;
  310. break;
  311. case AE_CTRL_PENDING:
  312. ParserState->Aml = WalkState->AmlLastWhile;
  313. break;
  314. #if 0
  315. case AE_CTRL_SKIP:
  316. ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd;
  317. Status = AE_OK;
  318. break;
  319. #endif
  320. case AE_CTRL_TRUE:
  321. /*
  322. * Predicate of an IF was true, and we are at the matching ELSE.
  323. * Just close out this package
  324. */
  325. ParserState->Aml = AcpiPsGetNextPackageEnd (ParserState);
  326. Status = AE_CTRL_PENDING;
  327. break;
  328. case AE_CTRL_FALSE:
  329. /*
  330. * Either an IF/WHILE Predicate was false or we encountered a BREAK
  331. * opcode. In both cases, we do not execute the rest of the
  332. * package; We simply close out the parent (finishing the walk of
  333. * this branch of the tree) and continue execution at the parent
  334. * level.
  335. */
  336. ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd;
  337. /* In the case of a BREAK, just force a predicate (if any) to FALSE */
  338. WalkState->ControlState->Common.Value = FALSE;
  339. Status = AE_CTRL_END;
  340. break;
  341. case AE_CTRL_TRANSFER:
  342. /* A method call (invocation) -- transfer control */
  343. Status = AE_CTRL_TRANSFER;
  344. WalkState->PrevOp = Op;
  345. WalkState->MethodCallOp = Op;
  346. WalkState->MethodCallNode = (Op->Common.Value.Arg)->Common.Node;
  347. /* Will return value (if any) be used by the caller? */
  348. WalkState->ReturnUsed = AcpiDsIsResultUsed (Op, WalkState);
  349. break;
  350. default:
  351. Status = CallbackStatus;
  352. if ((CallbackStatus & AE_CODE_MASK) == AE_CODE_CONTROL)
  353. {
  354. Status = AE_OK;
  355. }
  356. break;
  357. }
  358. return_ACPI_STATUS (Status);
  359. }
  360. /*******************************************************************************
  361. *
  362. * FUNCTION: AcpiPsParseAml
  363. *
  364. * PARAMETERS: WalkState - Current state
  365. *
  366. *
  367. * RETURN: Status
  368. *
  369. * DESCRIPTION: Parse raw AML and return a tree of ops
  370. *
  371. ******************************************************************************/
  372. ACPI_STATUS
  373. AcpiPsParseAml (
  374. ACPI_WALK_STATE *WalkState)
  375. {
  376. ACPI_STATUS Status;
  377. ACPI_THREAD_STATE *Thread;
  378. ACPI_THREAD_STATE *PrevWalkList = AcpiGbl_CurrentWalkList;
  379. ACPI_WALK_STATE *PreviousWalkState;
  380. ACPI_FUNCTION_TRACE (PsParseAml);
  381. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  382. "Entered with WalkState=%p Aml=%p size=%X\n",
  383. WalkState, WalkState->ParserState.Aml,
  384. WalkState->ParserState.AmlSize));
  385. if (!WalkState->ParserState.Aml)
  386. {
  387. return_ACPI_STATUS (AE_BAD_ADDRESS);
  388. }
  389. /* Create and initialize a new thread state */
  390. Thread = AcpiUtCreateThreadState ();
  391. if (!Thread)
  392. {
  393. if (WalkState->MethodDesc)
  394. {
  395. /* Executing a control method - additional cleanup */
  396. AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
  397. }
  398. AcpiDsDeleteWalkState (WalkState);
  399. return_ACPI_STATUS (AE_NO_MEMORY);
  400. }
  401. WalkState->Thread = Thread;
  402. /*
  403. * If executing a method, the starting SyncLevel is this method's
  404. * SyncLevel
  405. */
  406. if (WalkState->MethodDesc)
  407. {
  408. WalkState->Thread->CurrentSyncLevel =
  409. WalkState->MethodDesc->Method.SyncLevel;
  410. }
  411. AcpiDsPushWalkState (WalkState, Thread);
  412. /*
  413. * This global allows the AML debugger to get a handle to the currently
  414. * executing control method.
  415. */
  416. AcpiGbl_CurrentWalkList = Thread;
  417. /*
  418. * Execute the walk loop as long as there is a valid Walk State. This
  419. * handles nested control method invocations without recursion.
  420. */
  421. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "State=%p\n", WalkState));
  422. Status = AE_OK;
  423. while (WalkState)
  424. {
  425. if (ACPI_SUCCESS (Status))
  426. {
  427. /*
  428. * The ParseLoop executes AML until the method terminates
  429. * or calls another method.
  430. */
  431. Status = AcpiPsParseLoop (WalkState);
  432. }
  433. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  434. "Completed one call to walk loop, %s State=%p\n",
  435. AcpiFormatException (Status), WalkState));
  436. if (WalkState->MethodPathname && WalkState->MethodIsNested)
  437. {
  438. /* Optional object evaluation log */
  439. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EVALUATION, "%-26s: %*s%s\n",
  440. " Exit nested method",
  441. (WalkState->MethodNestingDepth + 1) * 3, " ",
  442. &WalkState->MethodPathname[1]));
  443. ACPI_FREE (WalkState->MethodPathname);
  444. WalkState->MethodIsNested = FALSE;
  445. }
  446. if (Status == AE_CTRL_TRANSFER)
  447. {
  448. /*
  449. * A method call was detected.
  450. * Transfer control to the called control method
  451. */
  452. Status = AcpiDsCallControlMethod (Thread, WalkState, NULL);
  453. if (ACPI_FAILURE (Status))
  454. {
  455. Status = AcpiDsMethodError (Status, WalkState);
  456. }
  457. /*
  458. * If the transfer to the new method method call worked
  459. *, a new walk state was created -- get it
  460. */
  461. WalkState = AcpiDsGetCurrentWalkState (Thread);
  462. continue;
  463. }
  464. else if (Status == AE_CTRL_TERMINATE)
  465. {
  466. Status = AE_OK;
  467. }
  468. else if ((Status != AE_OK) && (WalkState->MethodDesc))
  469. {
  470. /* Either the method parse or actual execution failed */
  471. AcpiExExitInterpreter ();
  472. if (Status == AE_ABORT_METHOD)
  473. {
  474. AcpiNsPrintNodePathname (
  475. WalkState->MethodNode, "Aborting method");
  476. AcpiOsPrintf ("\n");
  477. }
  478. else
  479. {
  480. ACPI_ERROR_METHOD ("Aborting method",
  481. WalkState->MethodNode, NULL, Status);
  482. }
  483. AcpiExEnterInterpreter ();
  484. /* Check for possible multi-thread reentrancy problem */
  485. if ((Status == AE_ALREADY_EXISTS) &&
  486. (!(WalkState->MethodDesc->Method.InfoFlags &
  487. ACPI_METHOD_SERIALIZED)))
  488. {
  489. /*
  490. * Method is not serialized and tried to create an object
  491. * twice. The probable cause is that the method cannot
  492. * handle reentrancy. Mark as "pending serialized" now, and
  493. * then mark "serialized" when the last thread exits.
  494. */
  495. WalkState->MethodDesc->Method.InfoFlags |=
  496. ACPI_METHOD_SERIALIZED_PENDING;
  497. }
  498. }
  499. /* We are done with this walk, move on to the parent if any */
  500. WalkState = AcpiDsPopWalkState (Thread);
  501. /* Reset the current scope to the beginning of scope stack */
  502. AcpiDsScopeStackClear (WalkState);
  503. /*
  504. * If we just returned from the execution of a control method or if we
  505. * encountered an error during the method parse phase, there's lots of
  506. * cleanup to do
  507. */
  508. if (((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) ==
  509. ACPI_PARSE_EXECUTE &&
  510. !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL)) ||
  511. (ACPI_FAILURE (Status)))
  512. {
  513. AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
  514. }
  515. /* Delete this walk state and all linked control states */
  516. AcpiPsCleanupScope (&WalkState->ParserState);
  517. PreviousWalkState = WalkState;
  518. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  519. "ReturnValue=%p, ImplicitValue=%p State=%p\n",
  520. WalkState->ReturnDesc, WalkState->ImplicitReturnObj, WalkState));
  521. /* Check if we have restarted a preempted walk */
  522. WalkState = AcpiDsGetCurrentWalkState (Thread);
  523. if (WalkState)
  524. {
  525. if (ACPI_SUCCESS (Status))
  526. {
  527. /*
  528. * There is another walk state, restart it.
  529. * If the method return value is not used by the parent,
  530. * The object is deleted
  531. */
  532. if (!PreviousWalkState->ReturnDesc)
  533. {
  534. /*
  535. * In slack mode execution, if there is no return value
  536. * we should implicitly return zero (0) as a default value.
  537. */
  538. if (AcpiGbl_EnableInterpreterSlack &&
  539. !PreviousWalkState->ImplicitReturnObj)
  540. {
  541. PreviousWalkState->ImplicitReturnObj =
  542. AcpiUtCreateIntegerObject ((UINT64) 0);
  543. if (!PreviousWalkState->ImplicitReturnObj)
  544. {
  545. return_ACPI_STATUS (AE_NO_MEMORY);
  546. }
  547. }
  548. /* Restart the calling control method */
  549. Status = AcpiDsRestartControlMethod (WalkState,
  550. PreviousWalkState->ImplicitReturnObj);
  551. }
  552. else
  553. {
  554. /*
  555. * We have a valid return value, delete any implicit
  556. * return value.
  557. */
  558. AcpiDsClearImplicitReturn (PreviousWalkState);
  559. Status = AcpiDsRestartControlMethod (WalkState,
  560. PreviousWalkState->ReturnDesc);
  561. }
  562. if (ACPI_SUCCESS (Status))
  563. {
  564. WalkState->WalkType |= ACPI_WALK_METHOD_RESTART;
  565. }
  566. }
  567. else
  568. {
  569. /* On error, delete any return object or implicit return */
  570. AcpiUtRemoveReference (PreviousWalkState->ReturnDesc);
  571. AcpiDsClearImplicitReturn (PreviousWalkState);
  572. }
  573. }
  574. /*
  575. * Just completed a 1st-level method, save the final internal return
  576. * value (if any)
  577. */
  578. else if (PreviousWalkState->CallerReturnDesc)
  579. {
  580. if (PreviousWalkState->ImplicitReturnObj)
  581. {
  582. *(PreviousWalkState->CallerReturnDesc) =
  583. PreviousWalkState->ImplicitReturnObj;
  584. }
  585. else
  586. {
  587. /* NULL if no return value */
  588. *(PreviousWalkState->CallerReturnDesc) =
  589. PreviousWalkState->ReturnDesc;
  590. }
  591. }
  592. else
  593. {
  594. if (PreviousWalkState->ReturnDesc)
  595. {
  596. /* Caller doesn't want it, must delete it */
  597. AcpiUtRemoveReference (PreviousWalkState->ReturnDesc);
  598. }
  599. if (PreviousWalkState->ImplicitReturnObj)
  600. {
  601. /* Caller doesn't want it, must delete it */
  602. AcpiUtRemoveReference (PreviousWalkState->ImplicitReturnObj);
  603. }
  604. }
  605. AcpiDsDeleteWalkState (PreviousWalkState);
  606. }
  607. /* Normal exit */
  608. AcpiExReleaseAllMutexes (Thread);
  609. AcpiUtDeleteGenericState (ACPI_CAST_PTR (ACPI_GENERIC_STATE, Thread));
  610. AcpiGbl_CurrentWalkList = PrevWalkList;
  611. return_ACPI_STATUS (Status);
  612. }