dswstate.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /******************************************************************************
  2. *
  3. * Module Name: dswstate - Dispatcher parse tree walk management routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acparser.h"
  45. #include "acdispat.h"
  46. #include "acnamesp.h"
  47. #define _COMPONENT ACPI_DISPATCHER
  48. ACPI_MODULE_NAME("dswstate")
  49. /* Local prototypes */
  50. static acpi_status
  51. acpi_ds_result_stack_push(struct acpi_walk_state *walk_state);
  52. static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state);
  53. /*******************************************************************************
  54. *
  55. * FUNCTION: acpi_ds_result_pop
  56. *
  57. * PARAMETERS: object - Where to return the popped object
  58. * walk_state - Current Walk state
  59. *
  60. * RETURN: Status
  61. *
  62. * DESCRIPTION: Pop an object off the top of this walk's result stack
  63. *
  64. ******************************************************************************/
  65. acpi_status
  66. acpi_ds_result_pop(union acpi_operand_object **object,
  67. struct acpi_walk_state *walk_state)
  68. {
  69. u32 index;
  70. union acpi_generic_state *state;
  71. acpi_status status;
  72. ACPI_FUNCTION_NAME(ds_result_pop);
  73. state = walk_state->results;
  74. /* Incorrect state of result stack */
  75. if (state && !walk_state->result_count) {
  76. ACPI_ERROR((AE_INFO, "No results on result stack"));
  77. return (AE_AML_INTERNAL);
  78. }
  79. if (!state && walk_state->result_count) {
  80. ACPI_ERROR((AE_INFO, "No result state for result stack"));
  81. return (AE_AML_INTERNAL);
  82. }
  83. /* Empty result stack */
  84. if (!state) {
  85. ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p",
  86. walk_state));
  87. return (AE_AML_NO_RETURN_VALUE);
  88. }
  89. /* Return object of the top element and clean that top element result stack */
  90. walk_state->result_count--;
  91. index = (u32)walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM;
  92. *object = state->results.obj_desc[index];
  93. if (!*object) {
  94. ACPI_ERROR((AE_INFO,
  95. "No result objects on result stack, State=%p",
  96. walk_state));
  97. return (AE_AML_NO_RETURN_VALUE);
  98. }
  99. state->results.obj_desc[index] = NULL;
  100. if (index == 0) {
  101. status = acpi_ds_result_stack_pop(walk_state);
  102. if (ACPI_FAILURE(status)) {
  103. return (status);
  104. }
  105. }
  106. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  107. "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object,
  108. acpi_ut_get_object_type_name(*object),
  109. index, walk_state, walk_state->result_count));
  110. return (AE_OK);
  111. }
  112. /*******************************************************************************
  113. *
  114. * FUNCTION: acpi_ds_result_push
  115. *
  116. * PARAMETERS: object - Where to return the popped object
  117. * walk_state - Current Walk state
  118. *
  119. * RETURN: Status
  120. *
  121. * DESCRIPTION: Push an object onto the current result stack
  122. *
  123. ******************************************************************************/
  124. acpi_status
  125. acpi_ds_result_push(union acpi_operand_object * object,
  126. struct acpi_walk_state * walk_state)
  127. {
  128. union acpi_generic_state *state;
  129. acpi_status status;
  130. u32 index;
  131. ACPI_FUNCTION_NAME(ds_result_push);
  132. if (walk_state->result_count > walk_state->result_size) {
  133. ACPI_ERROR((AE_INFO, "Result stack is full"));
  134. return (AE_AML_INTERNAL);
  135. } else if (walk_state->result_count == walk_state->result_size) {
  136. /* Extend the result stack */
  137. status = acpi_ds_result_stack_push(walk_state);
  138. if (ACPI_FAILURE(status)) {
  139. ACPI_ERROR((AE_INFO,
  140. "Failed to extend the result stack"));
  141. return (status);
  142. }
  143. }
  144. if (!(walk_state->result_count < walk_state->result_size)) {
  145. ACPI_ERROR((AE_INFO, "No free elements in result stack"));
  146. return (AE_AML_INTERNAL);
  147. }
  148. state = walk_state->results;
  149. if (!state) {
  150. ACPI_ERROR((AE_INFO, "No result stack frame during push"));
  151. return (AE_AML_INTERNAL);
  152. }
  153. if (!object) {
  154. ACPI_ERROR((AE_INFO,
  155. "Null Object! Obj=%p State=%p Num=%u",
  156. object, walk_state, walk_state->result_count));
  157. return (AE_BAD_PARAMETER);
  158. }
  159. /* Assign the address of object to the top free element of result stack */
  160. index = (u32)walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM;
  161. state->results.obj_desc[index] = object;
  162. walk_state->result_count++;
  163. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
  164. object,
  165. acpi_ut_get_object_type_name((union
  166. acpi_operand_object *)
  167. object), walk_state,
  168. walk_state->result_count,
  169. walk_state->current_result));
  170. return (AE_OK);
  171. }
  172. /*******************************************************************************
  173. *
  174. * FUNCTION: acpi_ds_result_stack_push
  175. *
  176. * PARAMETERS: walk_state - Current Walk state
  177. *
  178. * RETURN: Status
  179. *
  180. * DESCRIPTION: Push an object onto the walk_state result stack
  181. *
  182. ******************************************************************************/
  183. static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *walk_state)
  184. {
  185. union acpi_generic_state *state;
  186. ACPI_FUNCTION_NAME(ds_result_stack_push);
  187. /* Check for stack overflow */
  188. if (((u32) walk_state->result_size + ACPI_RESULTS_FRAME_OBJ_NUM) >
  189. ACPI_RESULTS_OBJ_NUM_MAX) {
  190. ACPI_ERROR((AE_INFO, "Result stack overflow: State=%p Num=%u",
  191. walk_state, walk_state->result_size));
  192. return (AE_STACK_OVERFLOW);
  193. }
  194. state = acpi_ut_create_generic_state();
  195. if (!state) {
  196. return (AE_NO_MEMORY);
  197. }
  198. state->common.descriptor_type = ACPI_DESC_TYPE_STATE_RESULT;
  199. acpi_ut_push_generic_state(&walk_state->results, state);
  200. /* Increase the length of the result stack by the length of frame */
  201. walk_state->result_size += ACPI_RESULTS_FRAME_OBJ_NUM;
  202. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
  203. state, walk_state));
  204. return (AE_OK);
  205. }
  206. /*******************************************************************************
  207. *
  208. * FUNCTION: acpi_ds_result_stack_pop
  209. *
  210. * PARAMETERS: walk_state - Current Walk state
  211. *
  212. * RETURN: Status
  213. *
  214. * DESCRIPTION: Pop an object off of the walk_state result stack
  215. *
  216. ******************************************************************************/
  217. static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state)
  218. {
  219. union acpi_generic_state *state;
  220. ACPI_FUNCTION_NAME(ds_result_stack_pop);
  221. /* Check for stack underflow */
  222. if (walk_state->results == NULL) {
  223. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  224. "Result stack underflow - State=%p\n",
  225. walk_state));
  226. return (AE_AML_NO_OPERAND);
  227. }
  228. if (walk_state->result_size < ACPI_RESULTS_FRAME_OBJ_NUM) {
  229. ACPI_ERROR((AE_INFO, "Insufficient result stack size"));
  230. return (AE_AML_INTERNAL);
  231. }
  232. state = acpi_ut_pop_generic_state(&walk_state->results);
  233. acpi_ut_delete_generic_state(state);
  234. /* Decrease the length of result stack by the length of frame */
  235. walk_state->result_size -= ACPI_RESULTS_FRAME_OBJ_NUM;
  236. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  237. "Result=%p RemainingResults=%X State=%p\n",
  238. state, walk_state->result_count, walk_state));
  239. return (AE_OK);
  240. }
  241. /*******************************************************************************
  242. *
  243. * FUNCTION: acpi_ds_obj_stack_push
  244. *
  245. * PARAMETERS: object - Object to push
  246. * walk_state - Current Walk state
  247. *
  248. * RETURN: Status
  249. *
  250. * DESCRIPTION: Push an object onto this walk's object/operand stack
  251. *
  252. ******************************************************************************/
  253. acpi_status
  254. acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state)
  255. {
  256. ACPI_FUNCTION_NAME(ds_obj_stack_push);
  257. /* Check for stack overflow */
  258. if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
  259. ACPI_ERROR((AE_INFO,
  260. "Object stack overflow! Obj=%p State=%p #Ops=%u",
  261. object, walk_state, walk_state->num_operands));
  262. return (AE_STACK_OVERFLOW);
  263. }
  264. /* Put the object onto the stack */
  265. walk_state->operands[walk_state->operand_index] = object;
  266. walk_state->num_operands++;
  267. /* For the usual order of filling the operand stack */
  268. walk_state->operand_index++;
  269. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
  270. object,
  271. acpi_ut_get_object_type_name((union
  272. acpi_operand_object *)
  273. object), walk_state,
  274. walk_state->num_operands));
  275. return (AE_OK);
  276. }
  277. /*******************************************************************************
  278. *
  279. * FUNCTION: acpi_ds_obj_stack_pop
  280. *
  281. * PARAMETERS: pop_count - Number of objects/entries to pop
  282. * walk_state - Current Walk state
  283. *
  284. * RETURN: Status
  285. *
  286. * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
  287. * deleted by this routine.
  288. *
  289. ******************************************************************************/
  290. acpi_status
  291. acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
  292. {
  293. u32 i;
  294. ACPI_FUNCTION_NAME(ds_obj_stack_pop);
  295. for (i = 0; i < pop_count; i++) {
  296. /* Check for stack underflow */
  297. if (walk_state->num_operands == 0) {
  298. ACPI_ERROR((AE_INFO,
  299. "Object stack underflow! Count=%X State=%p #Ops=%u",
  300. pop_count, walk_state,
  301. walk_state->num_operands));
  302. return (AE_STACK_UNDERFLOW);
  303. }
  304. /* Just set the stack entry to null */
  305. walk_state->num_operands--;
  306. walk_state->operands[walk_state->num_operands] = NULL;
  307. }
  308. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n",
  309. pop_count, walk_state, walk_state->num_operands));
  310. return (AE_OK);
  311. }
  312. /*******************************************************************************
  313. *
  314. * FUNCTION: acpi_ds_obj_stack_pop_and_delete
  315. *
  316. * PARAMETERS: pop_count - Number of objects/entries to pop
  317. * walk_state - Current Walk state
  318. *
  319. * RETURN: Status
  320. *
  321. * DESCRIPTION: Pop this walk's object stack and delete each object that is
  322. * popped off.
  323. *
  324. ******************************************************************************/
  325. void
  326. acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
  327. struct acpi_walk_state *walk_state)
  328. {
  329. s32 i;
  330. union acpi_operand_object *obj_desc;
  331. ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete);
  332. if (pop_count == 0) {
  333. return;
  334. }
  335. for (i = (s32) pop_count - 1; i >= 0; i--) {
  336. if (walk_state->num_operands == 0) {
  337. return;
  338. }
  339. /* Pop the stack and delete an object if present in this stack entry */
  340. walk_state->num_operands--;
  341. obj_desc = walk_state->operands[i];
  342. if (obj_desc) {
  343. acpi_ut_remove_reference(walk_state->operands[i]);
  344. walk_state->operands[i] = NULL;
  345. }
  346. }
  347. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
  348. pop_count, walk_state, walk_state->num_operands));
  349. }
  350. /*******************************************************************************
  351. *
  352. * FUNCTION: acpi_ds_get_current_walk_state
  353. *
  354. * PARAMETERS: thread - Get current active state for this Thread
  355. *
  356. * RETURN: Pointer to the current walk state
  357. *
  358. * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
  359. * walk state.)
  360. *
  361. ******************************************************************************/
  362. struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
  363. *thread)
  364. {
  365. ACPI_FUNCTION_NAME(ds_get_current_walk_state);
  366. if (!thread) {
  367. return (NULL);
  368. }
  369. ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current WalkState %p\n",
  370. thread->walk_state_list));
  371. return (thread->walk_state_list);
  372. }
  373. /*******************************************************************************
  374. *
  375. * FUNCTION: acpi_ds_push_walk_state
  376. *
  377. * PARAMETERS: walk_state - State to push
  378. * thread - Thread state object
  379. *
  380. * RETURN: None
  381. *
  382. * DESCRIPTION: Place the Thread state at the head of the state list
  383. *
  384. ******************************************************************************/
  385. void
  386. acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
  387. struct acpi_thread_state *thread)
  388. {
  389. ACPI_FUNCTION_TRACE(ds_push_walk_state);
  390. walk_state->next = thread->walk_state_list;
  391. thread->walk_state_list = walk_state;
  392. return_VOID;
  393. }
  394. /*******************************************************************************
  395. *
  396. * FUNCTION: acpi_ds_pop_walk_state
  397. *
  398. * PARAMETERS: thread - Current thread state
  399. *
  400. * RETURN: A walk_state object popped from the thread's stack
  401. *
  402. * DESCRIPTION: Remove and return the walkstate object that is at the head of
  403. * the walk stack for the given walk list. NULL indicates that
  404. * the list is empty.
  405. *
  406. ******************************************************************************/
  407. struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
  408. {
  409. struct acpi_walk_state *walk_state;
  410. ACPI_FUNCTION_TRACE(ds_pop_walk_state);
  411. walk_state = thread->walk_state_list;
  412. if (walk_state) {
  413. /* Next walk state becomes the current walk state */
  414. thread->walk_state_list = walk_state->next;
  415. /*
  416. * Don't clear the NEXT field, this serves as an indicator
  417. * that there is a parent WALK STATE
  418. * Do Not: walk_state->Next = NULL;
  419. */
  420. }
  421. return_PTR(walk_state);
  422. }
  423. /*******************************************************************************
  424. *
  425. * FUNCTION: acpi_ds_create_walk_state
  426. *
  427. * PARAMETERS: owner_id - ID for object creation
  428. * origin - Starting point for this walk
  429. * method_desc - Method object
  430. * thread - Current thread state
  431. *
  432. * RETURN: Pointer to the new walk state.
  433. *
  434. * DESCRIPTION: Allocate and initialize a new walk state. The current walk
  435. * state is set to this new state.
  436. *
  437. ******************************************************************************/
  438. struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id,
  439. union acpi_parse_object
  440. *origin,
  441. union acpi_operand_object
  442. *method_desc,
  443. struct acpi_thread_state
  444. *thread)
  445. {
  446. struct acpi_walk_state *walk_state;
  447. ACPI_FUNCTION_TRACE(ds_create_walk_state);
  448. walk_state = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_walk_state));
  449. if (!walk_state) {
  450. return_PTR(NULL);
  451. }
  452. walk_state->descriptor_type = ACPI_DESC_TYPE_WALK;
  453. walk_state->method_desc = method_desc;
  454. walk_state->owner_id = owner_id;
  455. walk_state->origin = origin;
  456. walk_state->thread = thread;
  457. walk_state->parser_state.start_op = origin;
  458. /* Init the method args/local */
  459. #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
  460. acpi_ds_method_data_init(walk_state);
  461. #endif
  462. /* Put the new state at the head of the walk list */
  463. if (thread) {
  464. acpi_ds_push_walk_state(walk_state, thread);
  465. }
  466. return_PTR(walk_state);
  467. }
  468. /*******************************************************************************
  469. *
  470. * FUNCTION: acpi_ds_init_aml_walk
  471. *
  472. * PARAMETERS: walk_state - New state to be initialized
  473. * op - Current parse op
  474. * method_node - Control method NS node, if any
  475. * aml_start - Start of AML
  476. * aml_length - Length of AML
  477. * info - Method info block (params, etc.)
  478. * pass_number - 1, 2, or 3
  479. *
  480. * RETURN: Status
  481. *
  482. * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
  483. *
  484. ******************************************************************************/
  485. acpi_status
  486. acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
  487. union acpi_parse_object *op,
  488. struct acpi_namespace_node *method_node,
  489. u8 * aml_start,
  490. u32 aml_length,
  491. struct acpi_evaluate_info *info, u8 pass_number)
  492. {
  493. acpi_status status;
  494. struct acpi_parse_state *parser_state = &walk_state->parser_state;
  495. union acpi_parse_object *extra_op;
  496. ACPI_FUNCTION_TRACE(ds_init_aml_walk);
  497. walk_state->parser_state.aml =
  498. walk_state->parser_state.aml_start = aml_start;
  499. walk_state->parser_state.aml_end =
  500. walk_state->parser_state.pkg_end = aml_start + aml_length;
  501. /* The next_op of the next_walk will be the beginning of the method */
  502. walk_state->next_op = NULL;
  503. walk_state->pass_number = pass_number;
  504. if (info) {
  505. walk_state->params = info->parameters;
  506. walk_state->caller_return_desc = &info->return_object;
  507. }
  508. status = acpi_ps_init_scope(&walk_state->parser_state, op);
  509. if (ACPI_FAILURE(status)) {
  510. return_ACPI_STATUS(status);
  511. }
  512. if (method_node) {
  513. walk_state->parser_state.start_node = method_node;
  514. walk_state->walk_type = ACPI_WALK_METHOD;
  515. walk_state->method_node = method_node;
  516. walk_state->method_desc =
  517. acpi_ns_get_attached_object(method_node);
  518. /* Push start scope on scope stack and make it current */
  519. status =
  520. acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD,
  521. walk_state);
  522. if (ACPI_FAILURE(status)) {
  523. return_ACPI_STATUS(status);
  524. }
  525. /* Init the method arguments */
  526. status = acpi_ds_method_data_init_args(walk_state->params,
  527. ACPI_METHOD_NUM_ARGS,
  528. walk_state);
  529. if (ACPI_FAILURE(status)) {
  530. return_ACPI_STATUS(status);
  531. }
  532. } else {
  533. /*
  534. * Setup the current scope.
  535. * Find a Named Op that has a namespace node associated with it.
  536. * search upwards from this Op. Current scope is the first
  537. * Op with a namespace node.
  538. */
  539. extra_op = parser_state->start_op;
  540. while (extra_op && !extra_op->common.node) {
  541. extra_op = extra_op->common.parent;
  542. }
  543. if (!extra_op) {
  544. parser_state->start_node = NULL;
  545. } else {
  546. parser_state->start_node = extra_op->common.node;
  547. }
  548. if (parser_state->start_node) {
  549. /* Push start scope on scope stack and make it current */
  550. status =
  551. acpi_ds_scope_stack_push(parser_state->start_node,
  552. parser_state->start_node->
  553. type, walk_state);
  554. if (ACPI_FAILURE(status)) {
  555. return_ACPI_STATUS(status);
  556. }
  557. }
  558. }
  559. status = acpi_ds_init_callbacks(walk_state, pass_number);
  560. return_ACPI_STATUS(status);
  561. }
  562. /*******************************************************************************
  563. *
  564. * FUNCTION: acpi_ds_delete_walk_state
  565. *
  566. * PARAMETERS: walk_state - State to delete
  567. *
  568. * RETURN: Status
  569. *
  570. * DESCRIPTION: Delete a walk state including all internal data structures
  571. *
  572. ******************************************************************************/
  573. void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
  574. {
  575. union acpi_generic_state *state;
  576. ACPI_FUNCTION_TRACE_PTR(ds_delete_walk_state, walk_state);
  577. if (!walk_state) {
  578. return_VOID;
  579. }
  580. if (walk_state->descriptor_type != ACPI_DESC_TYPE_WALK) {
  581. ACPI_ERROR((AE_INFO, "%p is not a valid walk state",
  582. walk_state));
  583. return_VOID;
  584. }
  585. /* There should not be any open scopes */
  586. if (walk_state->parser_state.scope) {
  587. ACPI_ERROR((AE_INFO, "%p walk still has a scope list",
  588. walk_state));
  589. acpi_ps_cleanup_scope(&walk_state->parser_state);
  590. }
  591. /* Always must free any linked control states */
  592. while (walk_state->control_state) {
  593. state = walk_state->control_state;
  594. walk_state->control_state = state->common.next;
  595. acpi_ut_delete_generic_state(state);
  596. }
  597. /* Always must free any linked parse states */
  598. while (walk_state->scope_info) {
  599. state = walk_state->scope_info;
  600. walk_state->scope_info = state->common.next;
  601. acpi_ut_delete_generic_state(state);
  602. }
  603. /* Always must free any stacked result states */
  604. while (walk_state->results) {
  605. state = walk_state->results;
  606. walk_state->results = state->common.next;
  607. acpi_ut_delete_generic_state(state);
  608. }
  609. ACPI_FREE(walk_state);
  610. return_VOID;
  611. }