dsmethod.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /******************************************************************************
  2. *
  3. * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
  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/amlcode.h>
  45. #include <acpi/acdispat.h>
  46. #include <acpi/acinterp.h>
  47. #include <acpi/acnamesp.h>
  48. #include <acpi/acdisasm.h>
  49. #define _COMPONENT ACPI_DISPATCHER
  50. ACPI_MODULE_NAME("dsmethod")
  51. /*******************************************************************************
  52. *
  53. * FUNCTION: acpi_ds_method_error
  54. *
  55. * PARAMETERS: Status - Execution status
  56. * walk_state - Current state
  57. *
  58. * RETURN: Status
  59. *
  60. * DESCRIPTION: Called on method error. Invoke the global exception handler if
  61. * present, dump the method data if the disassembler is configured
  62. *
  63. * Note: Allows the exception handler to change the status code
  64. *
  65. ******************************************************************************/
  66. acpi_status
  67. acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state)
  68. {
  69. ACPI_FUNCTION_ENTRY();
  70. /* Ignore AE_OK and control exception codes */
  71. if (ACPI_SUCCESS(status) || (status & AE_CODE_CONTROL)) {
  72. return (status);
  73. }
  74. /* Invoke the global exception handler */
  75. if (acpi_gbl_exception_handler) {
  76. /* Exit the interpreter, allow handler to execute methods */
  77. acpi_ex_exit_interpreter();
  78. /*
  79. * Handler can map the exception code to anything it wants, including
  80. * AE_OK, in which case the executing method will not be aborted.
  81. */
  82. status = acpi_gbl_exception_handler(status,
  83. walk_state->method_node ?
  84. walk_state->method_node->
  85. name.integer : 0,
  86. walk_state->opcode,
  87. walk_state->aml_offset,
  88. NULL);
  89. (void)acpi_ex_enter_interpreter();
  90. }
  91. #ifdef ACPI_DISASSEMBLER
  92. if (ACPI_FAILURE(status)) {
  93. /* Display method locals/args if disassembler is present */
  94. acpi_dm_dump_method_info(status, walk_state, walk_state->op);
  95. }
  96. #endif
  97. return (status);
  98. }
  99. /*******************************************************************************
  100. *
  101. * FUNCTION: acpi_ds_begin_method_execution
  102. *
  103. * PARAMETERS: method_node - Node of the method
  104. * obj_desc - The method object
  105. * calling_method_node - Caller of this method (if non-null)
  106. *
  107. * RETURN: Status
  108. *
  109. * DESCRIPTION: Prepare a method for execution. Parses the method if necessary,
  110. * increments the thread count, and waits at the method semaphore
  111. * for clearance to execute.
  112. *
  113. ******************************************************************************/
  114. acpi_status
  115. acpi_ds_begin_method_execution(struct acpi_namespace_node * method_node,
  116. union acpi_operand_object * obj_desc,
  117. struct acpi_namespace_node * calling_method_node)
  118. {
  119. acpi_status status = AE_OK;
  120. ACPI_FUNCTION_TRACE_PTR(ds_begin_method_execution, method_node);
  121. if (!method_node) {
  122. return_ACPI_STATUS(AE_NULL_ENTRY);
  123. }
  124. /* Prevent wraparound of thread count */
  125. if (obj_desc->method.thread_count == ACPI_UINT8_MAX) {
  126. ACPI_ERROR((AE_INFO,
  127. "Method reached maximum reentrancy limit (255)"));
  128. return_ACPI_STATUS(AE_AML_METHOD_LIMIT);
  129. }
  130. /*
  131. * If there is a concurrency limit on this method, we need to
  132. * obtain a unit from the method semaphore.
  133. */
  134. if (obj_desc->method.semaphore) {
  135. /*
  136. * Allow recursive method calls, up to the reentrancy/concurrency
  137. * limit imposed by the SERIALIZED rule and the sync_level method
  138. * parameter.
  139. *
  140. * The point of this code is to avoid permanently blocking a
  141. * thread that is making recursive method calls.
  142. */
  143. if (method_node == calling_method_node) {
  144. if (obj_desc->method.thread_count >=
  145. obj_desc->method.concurrency) {
  146. return_ACPI_STATUS(AE_AML_METHOD_LIMIT);
  147. }
  148. }
  149. /*
  150. * Get a unit from the method semaphore. This releases the
  151. * interpreter if we block (then reacquires it)
  152. */
  153. status =
  154. acpi_ex_system_wait_semaphore(obj_desc->method.semaphore,
  155. ACPI_WAIT_FOREVER);
  156. if (ACPI_FAILURE(status)) {
  157. return_ACPI_STATUS(status);
  158. }
  159. }
  160. /*
  161. * Allocate an Owner ID for this method, only if this is the first thread
  162. * to begin concurrent execution. We only need one owner_id, even if the
  163. * method is invoked recursively.
  164. */
  165. if (!obj_desc->method.owner_id) {
  166. status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);
  167. if (ACPI_FAILURE(status)) {
  168. goto cleanup;
  169. }
  170. }
  171. /*
  172. * Increment the method parse tree thread count since it has been
  173. * reentered one more time (even if it is the same thread)
  174. */
  175. obj_desc->method.thread_count++;
  176. return_ACPI_STATUS(status);
  177. cleanup:
  178. /* On error, must signal the method semaphore if present */
  179. if (obj_desc->method.semaphore) {
  180. (void)acpi_os_signal_semaphore(obj_desc->method.semaphore, 1);
  181. }
  182. return_ACPI_STATUS(status);
  183. }
  184. /*******************************************************************************
  185. *
  186. * FUNCTION: acpi_ds_call_control_method
  187. *
  188. * PARAMETERS: Thread - Info for this thread
  189. * this_walk_state - Current walk state
  190. * Op - Current Op to be walked
  191. *
  192. * RETURN: Status
  193. *
  194. * DESCRIPTION: Transfer execution to a called control method
  195. *
  196. ******************************************************************************/
  197. acpi_status
  198. acpi_ds_call_control_method(struct acpi_thread_state *thread,
  199. struct acpi_walk_state *this_walk_state,
  200. union acpi_parse_object *op)
  201. {
  202. acpi_status status;
  203. struct acpi_namespace_node *method_node;
  204. struct acpi_walk_state *next_walk_state = NULL;
  205. union acpi_operand_object *obj_desc;
  206. struct acpi_evaluate_info *info;
  207. u32 i;
  208. ACPI_FUNCTION_TRACE_PTR(ds_call_control_method, this_walk_state);
  209. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  210. "Execute method %p, currentstate=%p\n",
  211. this_walk_state->prev_op, this_walk_state));
  212. /*
  213. * Get the namespace entry for the control method we are about to call
  214. */
  215. method_node = this_walk_state->method_call_node;
  216. if (!method_node) {
  217. return_ACPI_STATUS(AE_NULL_ENTRY);
  218. }
  219. obj_desc = acpi_ns_get_attached_object(method_node);
  220. if (!obj_desc) {
  221. return_ACPI_STATUS(AE_NULL_OBJECT);
  222. }
  223. /* Init for new method, possibly wait on concurrency semaphore */
  224. status = acpi_ds_begin_method_execution(method_node, obj_desc,
  225. this_walk_state->method_node);
  226. if (ACPI_FAILURE(status)) {
  227. return_ACPI_STATUS(status);
  228. }
  229. /*
  230. * 1) Parse the method. All "normal" methods are parsed for each execution.
  231. * Internal methods (_OSI, etc.) do not require parsing.
  232. */
  233. if (!(obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY)) {
  234. /* Create a new walk state for the parse */
  235. next_walk_state =
  236. acpi_ds_create_walk_state(obj_desc->method.owner_id, op,
  237. obj_desc, NULL);
  238. if (!next_walk_state) {
  239. status = AE_NO_MEMORY;
  240. goto cleanup;
  241. }
  242. /* Create and init a parse tree root */
  243. op = acpi_ps_create_scope_op();
  244. if (!op) {
  245. status = AE_NO_MEMORY;
  246. goto cleanup;
  247. }
  248. status = acpi_ds_init_aml_walk(next_walk_state, op, method_node,
  249. obj_desc->method.aml_start,
  250. obj_desc->method.aml_length,
  251. NULL, 1);
  252. if (ACPI_FAILURE(status)) {
  253. acpi_ps_delete_parse_tree(op);
  254. goto cleanup;
  255. }
  256. /* Begin AML parse (deletes next_walk_state) */
  257. status = acpi_ps_parse_aml(next_walk_state);
  258. acpi_ps_delete_parse_tree(op);
  259. if (ACPI_FAILURE(status)) {
  260. goto cleanup;
  261. }
  262. }
  263. /* 2) Begin method execution. Create a new walk state */
  264. next_walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id,
  265. NULL, obj_desc, thread);
  266. if (!next_walk_state) {
  267. status = AE_NO_MEMORY;
  268. goto cleanup;
  269. }
  270. /*
  271. * The resolved arguments were put on the previous walk state's operand
  272. * stack. Operands on the previous walk state stack always
  273. * start at index 0. Also, null terminate the list of arguments
  274. */
  275. this_walk_state->operands[this_walk_state->num_operands] = NULL;
  276. /*
  277. * Allocate and initialize the evaluation information block
  278. * TBD: this is somewhat inefficient, should change interface to
  279. * ds_init_aml_walk. For now, keeps this struct off the CPU stack
  280. */
  281. info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  282. if (!info) {
  283. return_ACPI_STATUS(AE_NO_MEMORY);
  284. }
  285. info->parameters = &this_walk_state->operands[0];
  286. info->parameter_type = ACPI_PARAM_ARGS;
  287. status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node,
  288. obj_desc->method.aml_start,
  289. obj_desc->method.aml_length, info, 3);
  290. ACPI_FREE(info);
  291. if (ACPI_FAILURE(status)) {
  292. goto cleanup;
  293. }
  294. /*
  295. * Delete the operands on the previous walkstate operand stack
  296. * (they were copied to new objects)
  297. */
  298. for (i = 0; i < obj_desc->method.param_count; i++) {
  299. acpi_ut_remove_reference(this_walk_state->operands[i]);
  300. this_walk_state->operands[i] = NULL;
  301. }
  302. /* Clear the operand stack */
  303. this_walk_state->num_operands = 0;
  304. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  305. "Starting nested execution, newstate=%p\n",
  306. next_walk_state));
  307. /* Invoke an internal method if necessary */
  308. if (obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY) {
  309. status = obj_desc->method.implementation(next_walk_state);
  310. }
  311. return_ACPI_STATUS(status);
  312. cleanup:
  313. /* On error, we must terminate the method properly */
  314. acpi_ds_terminate_control_method(obj_desc, next_walk_state);
  315. if (next_walk_state) {
  316. acpi_ds_delete_walk_state(next_walk_state);
  317. }
  318. return_ACPI_STATUS(status);
  319. }
  320. /*******************************************************************************
  321. *
  322. * FUNCTION: acpi_ds_restart_control_method
  323. *
  324. * PARAMETERS: walk_state - State for preempted method (caller)
  325. * return_desc - Return value from the called method
  326. *
  327. * RETURN: Status
  328. *
  329. * DESCRIPTION: Restart a method that was preempted by another (nested) method
  330. * invocation. Handle the return value (if any) from the callee.
  331. *
  332. ******************************************************************************/
  333. acpi_status
  334. acpi_ds_restart_control_method(struct acpi_walk_state *walk_state,
  335. union acpi_operand_object *return_desc)
  336. {
  337. acpi_status status;
  338. int same_as_implicit_return;
  339. ACPI_FUNCTION_TRACE_PTR(ds_restart_control_method, walk_state);
  340. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  341. "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
  342. (char *)&walk_state->method_node->name,
  343. walk_state->method_call_op, return_desc));
  344. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  345. " ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
  346. walk_state->return_used,
  347. walk_state->results, walk_state));
  348. /* Did the called method return a value? */
  349. if (return_desc) {
  350. /* Is the implicit return object the same as the return desc? */
  351. same_as_implicit_return =
  352. (walk_state->implicit_return_obj == return_desc);
  353. /* Are we actually going to use the return value? */
  354. if (walk_state->return_used) {
  355. /* Save the return value from the previous method */
  356. status = acpi_ds_result_push(return_desc, walk_state);
  357. if (ACPI_FAILURE(status)) {
  358. acpi_ut_remove_reference(return_desc);
  359. return_ACPI_STATUS(status);
  360. }
  361. /*
  362. * Save as THIS method's return value in case it is returned
  363. * immediately to yet another method
  364. */
  365. walk_state->return_desc = return_desc;
  366. }
  367. /*
  368. * The following code is the optional support for the so-called
  369. * "implicit return". Some AML code assumes that the last value of the
  370. * method is "implicitly" returned to the caller, in the absence of an
  371. * explicit return value.
  372. *
  373. * Just save the last result of the method as the return value.
  374. *
  375. * NOTE: this is optional because the ASL language does not actually
  376. * support this behavior.
  377. */
  378. else if (!acpi_ds_do_implicit_return
  379. (return_desc, walk_state, FALSE)
  380. || same_as_implicit_return) {
  381. /*
  382. * Delete the return value if it will not be used by the
  383. * calling method or remove one reference if the explicit return
  384. * is the same as the implicit return value.
  385. */
  386. acpi_ut_remove_reference(return_desc);
  387. }
  388. }
  389. return_ACPI_STATUS(AE_OK);
  390. }
  391. /*******************************************************************************
  392. *
  393. * FUNCTION: acpi_ds_terminate_control_method
  394. *
  395. * PARAMETERS: method_desc - Method object
  396. * walk_state - State associated with the method
  397. *
  398. * RETURN: None
  399. *
  400. * DESCRIPTION: Terminate a control method. Delete everything that the method
  401. * created, delete all locals and arguments, and delete the parse
  402. * tree if requested.
  403. *
  404. ******************************************************************************/
  405. void
  406. acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
  407. struct acpi_walk_state *walk_state)
  408. {
  409. struct acpi_namespace_node *method_node;
  410. acpi_status status;
  411. ACPI_FUNCTION_TRACE_PTR(ds_terminate_control_method, walk_state);
  412. /* method_desc is required, walk_state is optional */
  413. if (!method_desc) {
  414. return_VOID;
  415. }
  416. if (walk_state) {
  417. /* Delete all arguments and locals */
  418. acpi_ds_method_data_delete_all(walk_state);
  419. }
  420. /*
  421. * Lock the parser while we terminate this method.
  422. * If this is the last thread executing the method,
  423. * we have additional cleanup to perform
  424. */
  425. status = acpi_ut_acquire_mutex(ACPI_MTX_CONTROL_METHOD);
  426. if (ACPI_FAILURE(status)) {
  427. return_VOID;
  428. }
  429. /* Signal completion of the execution of this method if necessary */
  430. if (method_desc->method.semaphore) {
  431. status =
  432. acpi_os_signal_semaphore(method_desc->method.semaphore, 1);
  433. if (ACPI_FAILURE(status)) {
  434. /* Ignore error and continue */
  435. ACPI_EXCEPTION((AE_INFO, status,
  436. "Could not signal method semaphore"));
  437. }
  438. }
  439. if (walk_state) {
  440. /*
  441. * Delete any objects created by this method during execution.
  442. * The method Node is stored in the walk state
  443. */
  444. method_node = walk_state->method_node;
  445. /* Lock namespace for possible update */
  446. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  447. if (ACPI_FAILURE(status)) {
  448. goto exit;
  449. }
  450. /*
  451. * Delete any namespace entries created immediately underneath
  452. * the method
  453. */
  454. if (method_node && method_node->child) {
  455. acpi_ns_delete_namespace_subtree(method_node);
  456. }
  457. /*
  458. * Delete any namespace entries created anywhere else within
  459. * the namespace by the execution of this method
  460. */
  461. acpi_ns_delete_namespace_by_owner(method_desc->method.owner_id);
  462. status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  463. }
  464. /* Decrement the thread count on the method */
  465. if (method_desc->method.thread_count) {
  466. method_desc->method.thread_count--;
  467. } else {
  468. ACPI_ERROR((AE_INFO, "Invalid zero thread count in method"));
  469. }
  470. /* Are there any other threads currently executing this method? */
  471. if (method_desc->method.thread_count) {
  472. /*
  473. * Additional threads. Do not release the owner_id in this case,
  474. * we immediately reuse it for the next thread executing this method
  475. */
  476. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  477. "*** Completed execution of one thread, %d threads remaining\n",
  478. method_desc->method.thread_count));
  479. } else {
  480. /* This is the only executing thread for this method */
  481. /*
  482. * Support to dynamically change a method from not_serialized to
  483. * Serialized if it appears that the method is incorrectly written and
  484. * does not support multiple thread execution. The best example of this
  485. * is if such a method creates namespace objects and blocks. A second
  486. * thread will fail with an AE_ALREADY_EXISTS exception
  487. *
  488. * This code is here because we must wait until the last thread exits
  489. * before creating the synchronization semaphore.
  490. */
  491. if ((method_desc->method.concurrency == 1) &&
  492. (!method_desc->method.semaphore)) {
  493. status = acpi_os_create_semaphore(1, 1,
  494. &method_desc->method.
  495. semaphore);
  496. }
  497. /* No more threads, we can free the owner_id */
  498. acpi_ut_release_owner_id(&method_desc->method.owner_id);
  499. }
  500. exit:
  501. (void)acpi_ut_release_mutex(ACPI_MTX_CONTROL_METHOD);
  502. return_VOID;
  503. }
  504. #ifdef ACPI_INIT_PARSE_METHODS
  505. /*
  506. * Note 11/2005: Removed this code to parse all methods during table
  507. * load because it causes problems if there are any errors during the
  508. * parse. Also, it seems like overkill and we probably don't want to
  509. * abort a table load because of an issue with a single method.
  510. */
  511. /*******************************************************************************
  512. *
  513. * FUNCTION: acpi_ds_parse_method
  514. *
  515. * PARAMETERS: Node - Method node
  516. *
  517. * RETURN: Status
  518. *
  519. * DESCRIPTION: Parse the AML that is associated with the method.
  520. *
  521. * MUTEX: Assumes parser is locked
  522. *
  523. ******************************************************************************/
  524. acpi_status acpi_ds_parse_method(struct acpi_namespace_node *node)
  525. {
  526. acpi_status status;
  527. union acpi_operand_object *obj_desc;
  528. union acpi_parse_object *op;
  529. struct acpi_walk_state *walk_state;
  530. ACPI_FUNCTION_TRACE_PTR(ds_parse_method, node);
  531. /* Parameter Validation */
  532. if (!node) {
  533. return_ACPI_STATUS(AE_NULL_ENTRY);
  534. }
  535. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  536. "**** Parsing [%4.4s] **** NamedObj=%p\n",
  537. acpi_ut_get_node_name(node), node));
  538. /* Extract the method object from the method Node */
  539. obj_desc = acpi_ns_get_attached_object(node);
  540. if (!obj_desc) {
  541. return_ACPI_STATUS(AE_NULL_OBJECT);
  542. }
  543. /* Create a mutex for the method if there is a concurrency limit */
  544. if ((obj_desc->method.concurrency != ACPI_INFINITE_CONCURRENCY) &&
  545. (!obj_desc->method.semaphore)) {
  546. status = acpi_os_create_semaphore(obj_desc->method.concurrency,
  547. obj_desc->method.concurrency,
  548. &obj_desc->method.semaphore);
  549. if (ACPI_FAILURE(status)) {
  550. return_ACPI_STATUS(status);
  551. }
  552. }
  553. /*
  554. * Allocate a new parser op to be the root of the parsed
  555. * method tree
  556. */
  557. op = acpi_ps_alloc_op(AML_METHOD_OP);
  558. if (!op) {
  559. return_ACPI_STATUS(AE_NO_MEMORY);
  560. }
  561. /* Init new op with the method name and pointer back to the Node */
  562. acpi_ps_set_name(op, node->name.integer);
  563. op->common.node = node;
  564. /*
  565. * Get a new owner_id for objects created by this method. Namespace
  566. * objects (such as Operation Regions) can be created during the
  567. * first pass parse.
  568. */
  569. status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);
  570. if (ACPI_FAILURE(status)) {
  571. goto cleanup;
  572. }
  573. /* Create and initialize a new walk state */
  574. walk_state =
  575. acpi_ds_create_walk_state(obj_desc->method.owner_id, NULL, NULL,
  576. NULL);
  577. if (!walk_state) {
  578. status = AE_NO_MEMORY;
  579. goto cleanup2;
  580. }
  581. status = acpi_ds_init_aml_walk(walk_state, op, node,
  582. obj_desc->method.aml_start,
  583. obj_desc->method.aml_length, NULL, 1);
  584. if (ACPI_FAILURE(status)) {
  585. acpi_ds_delete_walk_state(walk_state);
  586. goto cleanup2;
  587. }
  588. /*
  589. * Parse the method, first pass
  590. *
  591. * The first pass load is where newly declared named objects are added into
  592. * the namespace. Actual evaluation of the named objects (what would be
  593. * called a "second pass") happens during the actual execution of the
  594. * method so that operands to the named objects can take on dynamic
  595. * run-time values.
  596. */
  597. status = acpi_ps_parse_aml(walk_state);
  598. if (ACPI_FAILURE(status)) {
  599. goto cleanup2;
  600. }
  601. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  602. "**** [%4.4s] Parsed **** NamedObj=%p Op=%p\n",
  603. acpi_ut_get_node_name(node), node, op));
  604. /*
  605. * Delete the parse tree. We simply re-parse the method for every
  606. * execution since there isn't much overhead (compared to keeping lots
  607. * of parse trees around)
  608. */
  609. acpi_ns_delete_namespace_subtree(node);
  610. acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id);
  611. cleanup2:
  612. acpi_ut_release_owner_id(&obj_desc->method.owner_id);
  613. cleanup:
  614. acpi_ps_delete_parse_tree(op);
  615. return_ACPI_STATUS(status);
  616. }
  617. #endif