dswstate.c 21 KB

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