dswstate.c 21 KB

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