dswstate.c 29 KB

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