dswstate.c 30 KB

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