dswstate.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. /******************************************************************************
  2. *
  3. * Module Name: dswstate - Dispatcher parse tree walk management routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, R. Byron Moore
  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. #ifdef ACPI_OBSOLETE_FUNCTIONS
  50. acpi_status
  51. acpi_ds_result_insert(void *object,
  52. u32 index, struct acpi_walk_state *walk_state);
  53. acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state *walk_state);
  54. acpi_status
  55. acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
  56. struct acpi_walk_state *walk_state);
  57. void *acpi_ds_obj_stack_get_value(u32 index,
  58. struct acpi_walk_state *walk_state);
  59. #endif
  60. #ifdef ACPI_FUTURE_USAGE
  61. /*******************************************************************************
  62. *
  63. * FUNCTION: acpi_ds_result_remove
  64. *
  65. * PARAMETERS: Object - Where to return the popped object
  66. * Index - Where to extract the object
  67. * walk_state - Current Walk state
  68. *
  69. * RETURN: Status
  70. *
  71. * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
  72. * other words, this is a FIFO.
  73. *
  74. ******************************************************************************/
  75. acpi_status
  76. acpi_ds_result_remove(union acpi_operand_object **object,
  77. u32 index, struct acpi_walk_state *walk_state)
  78. {
  79. union acpi_generic_state *state;
  80. ACPI_FUNCTION_NAME("ds_result_remove");
  81. state = walk_state->results;
  82. if (!state) {
  83. ACPI_ERROR((AE_INFO, "No result object pushed! State=%p",
  84. walk_state));
  85. return (AE_NOT_EXIST);
  86. }
  87. if (index >= ACPI_OBJ_MAX_OPERAND) {
  88. ACPI_ERROR((AE_INFO,
  89. "Index out of range: %X State=%p Num=%X",
  90. index, walk_state, state->results.num_results));
  91. }
  92. /* Check for a valid result object */
  93. if (!state->results.obj_desc[index]) {
  94. ACPI_ERROR((AE_INFO,
  95. "Null operand! State=%p #Ops=%X, Index=%X",
  96. walk_state, state->results.num_results, index));
  97. return (AE_AML_NO_RETURN_VALUE);
  98. }
  99. /* Remove the object */
  100. state->results.num_results--;
  101. *object = state->results.obj_desc[index];
  102. state->results.obj_desc[index] = NULL;
  103. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  104. "Obj=%p [%s] Index=%X State=%p Num=%X\n",
  105. *object,
  106. (*object) ? acpi_ut_get_object_type_name(*object) :
  107. "NULL", index, walk_state,
  108. state->results.num_results));
  109. return (AE_OK);
  110. }
  111. #endif /* ACPI_FUTURE_USAGE */
  112. /*******************************************************************************
  113. *
  114. * FUNCTION: acpi_ds_result_pop
  115. *
  116. * PARAMETERS: Object - Where to return the popped object
  117. * walk_state - Current Walk state
  118. *
  119. * RETURN: Status
  120. *
  121. * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
  122. * other words, this is a FIFO.
  123. *
  124. ******************************************************************************/
  125. acpi_status
  126. acpi_ds_result_pop(union acpi_operand_object ** object,
  127. struct acpi_walk_state * walk_state)
  128. {
  129. acpi_native_uint index;
  130. union acpi_generic_state *state;
  131. ACPI_FUNCTION_NAME("ds_result_pop");
  132. state = walk_state->results;
  133. if (!state) {
  134. return (AE_OK);
  135. }
  136. if (!state->results.num_results) {
  137. ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p",
  138. walk_state));
  139. return (AE_AML_NO_RETURN_VALUE);
  140. }
  141. /* Remove top element */
  142. state->results.num_results--;
  143. for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) {
  144. /* Check for a valid result object */
  145. if (state->results.obj_desc[index - 1]) {
  146. *object = state->results.obj_desc[index - 1];
  147. state->results.obj_desc[index - 1] = NULL;
  148. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  149. "Obj=%p [%s] Index=%X State=%p Num=%X\n",
  150. *object,
  151. (*object) ?
  152. acpi_ut_get_object_type_name(*object)
  153. : "NULL", (u32) index - 1, walk_state,
  154. state->results.num_results));
  155. return (AE_OK);
  156. }
  157. }
  158. ACPI_ERROR((AE_INFO, "No result objects! State=%p", walk_state));
  159. return (AE_AML_NO_RETURN_VALUE);
  160. }
  161. /*******************************************************************************
  162. *
  163. * FUNCTION: acpi_ds_result_pop_from_bottom
  164. *
  165. * PARAMETERS: Object - Where to return the popped object
  166. * walk_state - Current Walk state
  167. *
  168. * RETURN: Status
  169. *
  170. * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
  171. * other words, this is a FIFO.
  172. *
  173. ******************************************************************************/
  174. acpi_status
  175. acpi_ds_result_pop_from_bottom(union acpi_operand_object ** object,
  176. struct acpi_walk_state * walk_state)
  177. {
  178. acpi_native_uint index;
  179. union acpi_generic_state *state;
  180. ACPI_FUNCTION_NAME("ds_result_pop_from_bottom");
  181. state = walk_state->results;
  182. if (!state) {
  183. ACPI_ERROR((AE_INFO,
  184. "No result object pushed! State=%p", walk_state));
  185. return (AE_NOT_EXIST);
  186. }
  187. if (!state->results.num_results) {
  188. ACPI_ERROR((AE_INFO, "No result objects! State=%p",
  189. walk_state));
  190. return (AE_AML_NO_RETURN_VALUE);
  191. }
  192. /* Remove Bottom element */
  193. *object = state->results.obj_desc[0];
  194. /* Push entire stack down one element */
  195. for (index = 0; index < state->results.num_results; index++) {
  196. state->results.obj_desc[index] =
  197. state->results.obj_desc[index + 1];
  198. }
  199. state->results.num_results--;
  200. /* Check for a valid result object */
  201. if (!*object) {
  202. ACPI_ERROR((AE_INFO,
  203. "Null operand! State=%p #Ops=%X Index=%X",
  204. walk_state, state->results.num_results,
  205. (u32) index));
  206. return (AE_AML_NO_RETURN_VALUE);
  207. }
  208. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Results=%p State=%p\n",
  209. *object,
  210. (*object) ? acpi_ut_get_object_type_name(*object) :
  211. "NULL", state, walk_state));
  212. return (AE_OK);
  213. }
  214. /*******************************************************************************
  215. *
  216. * FUNCTION: acpi_ds_result_push
  217. *
  218. * PARAMETERS: Object - Where to return the popped object
  219. * walk_state - Current Walk state
  220. *
  221. * RETURN: Status
  222. *
  223. * DESCRIPTION: Push an object onto the current result stack
  224. *
  225. ******************************************************************************/
  226. acpi_status
  227. acpi_ds_result_push(union acpi_operand_object * object,
  228. struct acpi_walk_state * walk_state)
  229. {
  230. union acpi_generic_state *state;
  231. ACPI_FUNCTION_NAME("ds_result_push");
  232. state = walk_state->results;
  233. if (!state) {
  234. ACPI_ERROR((AE_INFO, "No result stack frame during push"));
  235. return (AE_AML_INTERNAL);
  236. }
  237. if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) {
  238. ACPI_ERROR((AE_INFO,
  239. "Result stack overflow: Obj=%p State=%p Num=%X",
  240. object, walk_state, state->results.num_results));
  241. return (AE_STACK_OVERFLOW);
  242. }
  243. if (!object) {
  244. ACPI_ERROR((AE_INFO,
  245. "Null Object! Obj=%p State=%p Num=%X",
  246. object, walk_state, state->results.num_results));
  247. return (AE_BAD_PARAMETER);
  248. }
  249. state->results.obj_desc[state->results.num_results] = object;
  250. state->results.num_results++;
  251. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
  252. object,
  253. object ?
  254. acpi_ut_get_object_type_name((union
  255. acpi_operand_object *)
  256. object) : "NULL",
  257. walk_state, state->results.num_results,
  258. walk_state->current_result));
  259. return (AE_OK);
  260. }
  261. /*******************************************************************************
  262. *
  263. * FUNCTION: acpi_ds_result_stack_push
  264. *
  265. * PARAMETERS: walk_state - Current Walk state
  266. *
  267. * RETURN: Status
  268. *
  269. * DESCRIPTION: Push an object onto the walk_state result stack.
  270. *
  271. ******************************************************************************/
  272. acpi_status acpi_ds_result_stack_push(struct acpi_walk_state * walk_state)
  273. {
  274. union acpi_generic_state *state;
  275. ACPI_FUNCTION_NAME("ds_result_stack_push");
  276. state = acpi_ut_create_generic_state();
  277. if (!state) {
  278. return (AE_NO_MEMORY);
  279. }
  280. state->common.data_type = ACPI_DESC_TYPE_STATE_RESULT;
  281. acpi_ut_push_generic_state(&walk_state->results, state);
  282. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
  283. state, walk_state));
  284. return (AE_OK);
  285. }
  286. /*******************************************************************************
  287. *
  288. * FUNCTION: acpi_ds_result_stack_pop
  289. *
  290. * PARAMETERS: walk_state - Current Walk state
  291. *
  292. * RETURN: Status
  293. *
  294. * DESCRIPTION: Pop an object off of the walk_state result stack.
  295. *
  296. ******************************************************************************/
  297. acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state * walk_state)
  298. {
  299. union acpi_generic_state *state;
  300. ACPI_FUNCTION_NAME("ds_result_stack_pop");
  301. /* Check for stack underflow */
  302. if (walk_state->results == NULL) {
  303. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Underflow - State=%p\n",
  304. walk_state));
  305. return (AE_AML_NO_OPERAND);
  306. }
  307. state = acpi_ut_pop_generic_state(&walk_state->results);
  308. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  309. "Result=%p remaining_results=%X State=%p\n",
  310. state, state->results.num_results, walk_state));
  311. acpi_ut_delete_generic_state(state);
  312. return (AE_OK);
  313. }
  314. /*******************************************************************************
  315. *
  316. * FUNCTION: acpi_ds_obj_stack_push
  317. *
  318. * PARAMETERS: Object - Object to push
  319. * walk_state - Current Walk state
  320. *
  321. * RETURN: Status
  322. *
  323. * DESCRIPTION: Push an object onto this walk's object/operand stack
  324. *
  325. ******************************************************************************/
  326. acpi_status
  327. acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state)
  328. {
  329. ACPI_FUNCTION_NAME("ds_obj_stack_push");
  330. /* Check for stack overflow */
  331. if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
  332. ACPI_ERROR((AE_INFO,
  333. "Object stack overflow! Obj=%p State=%p #Ops=%X",
  334. object, walk_state, walk_state->num_operands));
  335. return (AE_STACK_OVERFLOW);
  336. }
  337. /* Put the object onto the stack */
  338. walk_state->operands[walk_state->num_operands] = object;
  339. walk_state->num_operands++;
  340. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
  341. object,
  342. acpi_ut_get_object_type_name((union
  343. acpi_operand_object *)
  344. object), walk_state,
  345. walk_state->num_operands));
  346. return (AE_OK);
  347. }
  348. /*******************************************************************************
  349. *
  350. * FUNCTION: acpi_ds_obj_stack_pop
  351. *
  352. * PARAMETERS: pop_count - Number of objects/entries to pop
  353. * walk_state - Current Walk state
  354. *
  355. * RETURN: Status
  356. *
  357. * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
  358. * deleted by this routine.
  359. *
  360. ******************************************************************************/
  361. acpi_status
  362. acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
  363. {
  364. u32 i;
  365. ACPI_FUNCTION_NAME("ds_obj_stack_pop");
  366. for (i = 0; i < pop_count; i++) {
  367. /* Check for stack underflow */
  368. if (walk_state->num_operands == 0) {
  369. ACPI_ERROR((AE_INFO,
  370. "Object stack underflow! Count=%X State=%p #Ops=%X",
  371. pop_count, walk_state,
  372. walk_state->num_operands));
  373. return (AE_STACK_UNDERFLOW);
  374. }
  375. /* Just set the stack entry to null */
  376. walk_state->num_operands--;
  377. walk_state->operands[walk_state->num_operands] = NULL;
  378. }
  379. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
  380. pop_count, walk_state, walk_state->num_operands));
  381. return (AE_OK);
  382. }
  383. /*******************************************************************************
  384. *
  385. * FUNCTION: acpi_ds_obj_stack_pop_and_delete
  386. *
  387. * PARAMETERS: pop_count - Number of objects/entries to pop
  388. * walk_state - Current Walk state
  389. *
  390. * RETURN: Status
  391. *
  392. * DESCRIPTION: Pop this walk's object stack and delete each object that is
  393. * popped off.
  394. *
  395. ******************************************************************************/
  396. acpi_status
  397. acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
  398. struct acpi_walk_state * walk_state)
  399. {
  400. u32 i;
  401. union acpi_operand_object *obj_desc;
  402. ACPI_FUNCTION_NAME("ds_obj_stack_pop_and_delete");
  403. for (i = 0; i < pop_count; i++) {
  404. /* Check for stack underflow */
  405. if (walk_state->num_operands == 0) {
  406. ACPI_ERROR((AE_INFO,
  407. "Object stack underflow! Count=%X State=%p #Ops=%X",
  408. pop_count, walk_state,
  409. walk_state->num_operands));
  410. return (AE_STACK_UNDERFLOW);
  411. }
  412. /* Pop the stack and delete an object if present in this stack entry */
  413. walk_state->num_operands--;
  414. obj_desc = walk_state->operands[walk_state->num_operands];
  415. if (obj_desc) {
  416. acpi_ut_remove_reference(walk_state->
  417. operands[walk_state->
  418. num_operands]);
  419. walk_state->operands[walk_state->num_operands] = NULL;
  420. }
  421. }
  422. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
  423. pop_count, walk_state, walk_state->num_operands));
  424. return (AE_OK);
  425. }
  426. /*******************************************************************************
  427. *
  428. * FUNCTION: acpi_ds_get_current_walk_state
  429. *
  430. * PARAMETERS: Thread - Get current active state for this Thread
  431. *
  432. * RETURN: Pointer to the current walk state
  433. *
  434. * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
  435. * walk state.)
  436. *
  437. ******************************************************************************/
  438. struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
  439. *thread)
  440. {
  441. ACPI_FUNCTION_NAME("ds_get_current_walk_state");
  442. if (!thread) {
  443. return (NULL);
  444. }
  445. ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current walk_state %p\n",
  446. thread->walk_state_list));
  447. return (thread->walk_state_list);
  448. }
  449. /*******************************************************************************
  450. *
  451. * FUNCTION: acpi_ds_push_walk_state
  452. *
  453. * PARAMETERS: walk_state - State to push
  454. * Thread - Thread state object
  455. *
  456. * RETURN: None
  457. *
  458. * DESCRIPTION: Place the Thread state at the head of the state list.
  459. *
  460. ******************************************************************************/
  461. void
  462. acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
  463. struct acpi_thread_state *thread)
  464. {
  465. ACPI_FUNCTION_TRACE("ds_push_walk_state");
  466. walk_state->next = thread->walk_state_list;
  467. thread->walk_state_list = walk_state;
  468. return_VOID;
  469. }
  470. /*******************************************************************************
  471. *
  472. * FUNCTION: acpi_ds_pop_walk_state
  473. *
  474. * PARAMETERS: Thread - Current thread state
  475. *
  476. * RETURN: A walk_state object popped from the thread's stack
  477. *
  478. * DESCRIPTION: Remove and return the walkstate object that is at the head of
  479. * the walk stack for the given walk list. NULL indicates that
  480. * the list is empty.
  481. *
  482. ******************************************************************************/
  483. struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
  484. {
  485. struct acpi_walk_state *walk_state;
  486. ACPI_FUNCTION_TRACE("ds_pop_walk_state");
  487. walk_state = thread->walk_state_list;
  488. if (walk_state) {
  489. /* Next walk state becomes the current walk state */
  490. thread->walk_state_list = walk_state->next;
  491. /*
  492. * Don't clear the NEXT field, this serves as an indicator
  493. * that there is a parent WALK STATE
  494. * Do Not: walk_state->Next = NULL;
  495. */
  496. }
  497. return_PTR(walk_state);
  498. }
  499. /*******************************************************************************
  500. *
  501. * FUNCTION: acpi_ds_create_walk_state
  502. *
  503. * PARAMETERS: owner_id - ID for object creation
  504. * Origin - Starting point for this walk
  505. * mth_desc - Method object
  506. * Thread - Current thread state
  507. *
  508. * RETURN: Pointer to the new walk state.
  509. *
  510. * DESCRIPTION: Allocate and initialize a new walk state. The current walk
  511. * state is set to this new state.
  512. *
  513. ******************************************************************************/
  514. struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id,
  515. union acpi_parse_object
  516. *origin,
  517. union acpi_operand_object
  518. *mth_desc,
  519. struct acpi_thread_state
  520. *thread)
  521. {
  522. struct acpi_walk_state *walk_state;
  523. acpi_status status;
  524. ACPI_FUNCTION_TRACE("ds_create_walk_state");
  525. walk_state = ACPI_MEM_CALLOCATE(sizeof(struct acpi_walk_state));
  526. if (!walk_state) {
  527. return_PTR(NULL);
  528. }
  529. walk_state->data_type = ACPI_DESC_TYPE_WALK;
  530. walk_state->owner_id = owner_id;
  531. walk_state->origin = origin;
  532. walk_state->method_desc = mth_desc;
  533. walk_state->thread = thread;
  534. walk_state->parser_state.start_op = origin;
  535. /* Init the method args/local */
  536. #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
  537. acpi_ds_method_data_init(walk_state);
  538. #endif
  539. /* Create an initial result stack entry */
  540. status = acpi_ds_result_stack_push(walk_state);
  541. if (ACPI_FAILURE(status)) {
  542. ACPI_MEM_FREE(walk_state);
  543. return_PTR(NULL);
  544. }
  545. /* Put the new state at the head of the walk list */
  546. if (thread) {
  547. acpi_ds_push_walk_state(walk_state, thread);
  548. }
  549. return_PTR(walk_state);
  550. }
  551. /*******************************************************************************
  552. *
  553. * FUNCTION: acpi_ds_init_aml_walk
  554. *
  555. * PARAMETERS: walk_state - New state to be initialized
  556. * Op - Current parse op
  557. * method_node - Control method NS node, if any
  558. * aml_start - Start of AML
  559. * aml_length - Length of AML
  560. * Info - Method info block (params, etc.)
  561. * pass_number - 1, 2, or 3
  562. *
  563. * RETURN: Status
  564. *
  565. * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
  566. *
  567. ******************************************************************************/
  568. acpi_status
  569. acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
  570. union acpi_parse_object *op,
  571. struct acpi_namespace_node *method_node,
  572. u8 * aml_start,
  573. u32 aml_length,
  574. struct acpi_parameter_info *info, u8 pass_number)
  575. {
  576. acpi_status status;
  577. struct acpi_parse_state *parser_state = &walk_state->parser_state;
  578. union acpi_parse_object *extra_op;
  579. ACPI_FUNCTION_TRACE("ds_init_aml_walk");
  580. walk_state->parser_state.aml =
  581. walk_state->parser_state.aml_start = aml_start;
  582. walk_state->parser_state.aml_end =
  583. walk_state->parser_state.pkg_end = aml_start + aml_length;
  584. /* The next_op of the next_walk will be the beginning of the method */
  585. walk_state->next_op = NULL;
  586. walk_state->pass_number = pass_number;
  587. if (info) {
  588. if (info->parameter_type == ACPI_PARAM_GPE) {
  589. walk_state->gpe_event_info =
  590. ACPI_CAST_PTR(struct acpi_gpe_event_info,
  591. info->parameters);
  592. } else {
  593. walk_state->params = info->parameters;
  594. walk_state->caller_return_desc = &info->return_object;
  595. }
  596. }
  597. status = acpi_ps_init_scope(&walk_state->parser_state, op);
  598. if (ACPI_FAILURE(status)) {
  599. return_ACPI_STATUS(status);
  600. }
  601. if (method_node) {
  602. walk_state->parser_state.start_node = method_node;
  603. walk_state->walk_type = ACPI_WALK_METHOD;
  604. walk_state->method_node = method_node;
  605. walk_state->method_desc =
  606. acpi_ns_get_attached_object(method_node);
  607. /* Push start scope on scope stack and make it current */
  608. status =
  609. acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD,
  610. walk_state);
  611. if (ACPI_FAILURE(status)) {
  612. return_ACPI_STATUS(status);
  613. }
  614. /* Init the method arguments */
  615. status = acpi_ds_method_data_init_args(walk_state->params,
  616. ACPI_METHOD_NUM_ARGS,
  617. walk_state);
  618. if (ACPI_FAILURE(status)) {
  619. return_ACPI_STATUS(status);
  620. }
  621. } else {
  622. /*
  623. * Setup the current scope.
  624. * Find a Named Op that has a namespace node associated with it.
  625. * search upwards from this Op. Current scope is the first
  626. * Op with a namespace node.
  627. */
  628. extra_op = parser_state->start_op;
  629. while (extra_op && !extra_op->common.node) {
  630. extra_op = extra_op->common.parent;
  631. }
  632. if (!extra_op) {
  633. parser_state->start_node = NULL;
  634. } else {
  635. parser_state->start_node = extra_op->common.node;
  636. }
  637. if (parser_state->start_node) {
  638. /* Push start scope on scope stack and make it current */
  639. status =
  640. acpi_ds_scope_stack_push(parser_state->start_node,
  641. parser_state->start_node->
  642. type, walk_state);
  643. if (ACPI_FAILURE(status)) {
  644. return_ACPI_STATUS(status);
  645. }
  646. }
  647. }
  648. status = acpi_ds_init_callbacks(walk_state, pass_number);
  649. return_ACPI_STATUS(status);
  650. }
  651. /*******************************************************************************
  652. *
  653. * FUNCTION: acpi_ds_delete_walk_state
  654. *
  655. * PARAMETERS: walk_state - State to delete
  656. *
  657. * RETURN: Status
  658. *
  659. * DESCRIPTION: Delete a walk state including all internal data structures
  660. *
  661. ******************************************************************************/
  662. void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
  663. {
  664. union acpi_generic_state *state;
  665. ACPI_FUNCTION_TRACE_PTR("ds_delete_walk_state", walk_state);
  666. if (!walk_state) {
  667. return;
  668. }
  669. if (walk_state->data_type != ACPI_DESC_TYPE_WALK) {
  670. ACPI_ERROR((AE_INFO, "%p is not a valid walk state",
  671. walk_state));
  672. return;
  673. }
  674. if (walk_state->parser_state.scope) {
  675. ACPI_ERROR((AE_INFO, "%p walk still has a scope list",
  676. walk_state));
  677. }
  678. /* Always must free any linked control states */
  679. while (walk_state->control_state) {
  680. state = walk_state->control_state;
  681. walk_state->control_state = state->common.next;
  682. acpi_ut_delete_generic_state(state);
  683. }
  684. /* Always must free any linked parse states */
  685. while (walk_state->scope_info) {
  686. state = walk_state->scope_info;
  687. walk_state->scope_info = state->common.next;
  688. acpi_ut_delete_generic_state(state);
  689. }
  690. /* Always must free any stacked result states */
  691. while (walk_state->results) {
  692. state = walk_state->results;
  693. walk_state->results = state->common.next;
  694. acpi_ut_delete_generic_state(state);
  695. }
  696. ACPI_MEM_FREE(walk_state);
  697. return_VOID;
  698. }
  699. #ifdef ACPI_OBSOLETE_FUNCTIONS
  700. /*******************************************************************************
  701. *
  702. * FUNCTION: acpi_ds_result_insert
  703. *
  704. * PARAMETERS: Object - Object to push
  705. * Index - Where to insert the object
  706. * walk_state - Current Walk state
  707. *
  708. * RETURN: Status
  709. *
  710. * DESCRIPTION: Insert an object onto this walk's result stack
  711. *
  712. ******************************************************************************/
  713. acpi_status
  714. acpi_ds_result_insert(void *object,
  715. u32 index, struct acpi_walk_state *walk_state)
  716. {
  717. union acpi_generic_state *state;
  718. ACPI_FUNCTION_NAME("ds_result_insert");
  719. state = walk_state->results;
  720. if (!state) {
  721. ACPI_ERROR((AE_INFO, "No result object pushed! State=%p",
  722. walk_state));
  723. return (AE_NOT_EXIST);
  724. }
  725. if (index >= ACPI_OBJ_NUM_OPERANDS) {
  726. ACPI_ERROR((AE_INFO,
  727. "Index out of range: %X Obj=%p State=%p Num=%X",
  728. index, object, walk_state,
  729. state->results.num_results));
  730. return (AE_BAD_PARAMETER);
  731. }
  732. if (!object) {
  733. ACPI_ERROR((AE_INFO,
  734. "Null Object! Index=%X Obj=%p State=%p Num=%X",
  735. index, object, walk_state,
  736. state->results.num_results));
  737. return (AE_BAD_PARAMETER);
  738. }
  739. state->results.obj_desc[index] = object;
  740. state->results.num_results++;
  741. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  742. "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
  743. object,
  744. object ?
  745. acpi_ut_get_object_type_name((union
  746. acpi_operand_object *)
  747. object) : "NULL",
  748. walk_state, state->results.num_results,
  749. walk_state->current_result));
  750. return (AE_OK);
  751. }
  752. /*******************************************************************************
  753. *
  754. * FUNCTION: acpi_ds_obj_stack_delete_all
  755. *
  756. * PARAMETERS: walk_state - Current Walk state
  757. *
  758. * RETURN: Status
  759. *
  760. * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
  761. * Should be used with great care, if at all!
  762. *
  763. ******************************************************************************/
  764. acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state * walk_state)
  765. {
  766. u32 i;
  767. ACPI_FUNCTION_TRACE_PTR("ds_obj_stack_delete_all", walk_state);
  768. /* The stack size is configurable, but fixed */
  769. for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
  770. if (walk_state->operands[i]) {
  771. acpi_ut_remove_reference(walk_state->operands[i]);
  772. walk_state->operands[i] = NULL;
  773. }
  774. }
  775. return_ACPI_STATUS(AE_OK);
  776. }
  777. /*******************************************************************************
  778. *
  779. * FUNCTION: acpi_ds_obj_stack_pop_object
  780. *
  781. * PARAMETERS: Object - Where to return the popped object
  782. * walk_state - Current Walk state
  783. *
  784. * RETURN: Status
  785. *
  786. * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
  787. * deleted by this routine.
  788. *
  789. ******************************************************************************/
  790. acpi_status
  791. acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
  792. struct acpi_walk_state *walk_state)
  793. {
  794. ACPI_FUNCTION_NAME("ds_obj_stack_pop_object");
  795. /* Check for stack underflow */
  796. if (walk_state->num_operands == 0) {
  797. ACPI_ERROR((AE_INFO,
  798. "Missing operand/stack empty! State=%p #Ops=%X",
  799. walk_state, walk_state->num_operands));
  800. *object = NULL;
  801. return (AE_AML_NO_OPERAND);
  802. }
  803. /* Pop the stack */
  804. walk_state->num_operands--;
  805. /* Check for a valid operand */
  806. if (!walk_state->operands[walk_state->num_operands]) {
  807. ACPI_ERROR((AE_INFO,
  808. "Null operand! State=%p #Ops=%X",
  809. walk_state, walk_state->num_operands));
  810. *object = NULL;
  811. return (AE_AML_NO_OPERAND);
  812. }
  813. /* Get operand and set stack entry to null */
  814. *object = walk_state->operands[walk_state->num_operands];
  815. walk_state->operands[walk_state->num_operands] = NULL;
  816. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
  817. *object, acpi_ut_get_object_type_name(*object),
  818. walk_state, walk_state->num_operands));
  819. return (AE_OK);
  820. }
  821. /*******************************************************************************
  822. *
  823. * FUNCTION: acpi_ds_obj_stack_get_value
  824. *
  825. * PARAMETERS: Index - Stack index whose value is desired. Based
  826. * on the top of the stack (index=0 == top)
  827. * walk_state - Current Walk state
  828. *
  829. * RETURN: Pointer to the requested operand
  830. *
  831. * DESCRIPTION: Retrieve an object from this walk's operand stack. Index must
  832. * be within the range of the current stack pointer.
  833. *
  834. ******************************************************************************/
  835. void *acpi_ds_obj_stack_get_value(u32 index, struct acpi_walk_state *walk_state)
  836. {
  837. ACPI_FUNCTION_TRACE_PTR("ds_obj_stack_get_value", walk_state);
  838. /* Can't do it if the stack is empty */
  839. if (walk_state->num_operands == 0) {
  840. return_PTR(NULL);
  841. }
  842. /* or if the index is past the top of the stack */
  843. if (index > (walk_state->num_operands - (u32) 1)) {
  844. return_PTR(NULL);
  845. }
  846. return_PTR(walk_state->
  847. operands[(acpi_native_uint) (walk_state->num_operands - 1) -
  848. index]);
  849. }
  850. #endif