dswload.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. /******************************************************************************
  2. *
  3. * Module Name: dswload - Dispatcher namespace load callbacks
  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/amlcode.h>
  45. #include <acpi/acdispat.h>
  46. #include <acpi/acinterp.h>
  47. #include <acpi/acnamesp.h>
  48. #include <acpi/acevents.h>
  49. #ifdef _ACPI_ASL_COMPILER
  50. #include <acpi/acdisasm.h>
  51. #endif
  52. #define _COMPONENT ACPI_DISPATCHER
  53. ACPI_MODULE_NAME ("dswload")
  54. /*******************************************************************************
  55. *
  56. * FUNCTION: acpi_ds_init_callbacks
  57. *
  58. * PARAMETERS: walk_state - Current state of the parse tree walk
  59. * pass_number - 1, 2, or 3
  60. *
  61. * RETURN: Status
  62. *
  63. * DESCRIPTION: Init walk state callbacks
  64. *
  65. ******************************************************************************/
  66. acpi_status
  67. acpi_ds_init_callbacks (
  68. struct acpi_walk_state *walk_state,
  69. u32 pass_number)
  70. {
  71. switch (pass_number) {
  72. case 1:
  73. walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE;
  74. walk_state->descending_callback = acpi_ds_load1_begin_op;
  75. walk_state->ascending_callback = acpi_ds_load1_end_op;
  76. break;
  77. case 2:
  78. walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE;
  79. walk_state->descending_callback = acpi_ds_load2_begin_op;
  80. walk_state->ascending_callback = acpi_ds_load2_end_op;
  81. break;
  82. case 3:
  83. #ifndef ACPI_NO_METHOD_EXECUTION
  84. walk_state->parse_flags |= ACPI_PARSE_EXECUTE | ACPI_PARSE_DELETE_TREE;
  85. walk_state->descending_callback = acpi_ds_exec_begin_op;
  86. walk_state->ascending_callback = acpi_ds_exec_end_op;
  87. #endif
  88. break;
  89. default:
  90. return (AE_BAD_PARAMETER);
  91. }
  92. return (AE_OK);
  93. }
  94. /*******************************************************************************
  95. *
  96. * FUNCTION: acpi_ds_load1_begin_op
  97. *
  98. * PARAMETERS: walk_state - Current state of the parse tree walk
  99. * Op - Op that has been just been reached in the
  100. * walk; Arguments have not been evaluated yet.
  101. *
  102. * RETURN: Status
  103. *
  104. * DESCRIPTION: Descending callback used during the loading of ACPI tables.
  105. *
  106. ******************************************************************************/
  107. acpi_status
  108. acpi_ds_load1_begin_op (
  109. struct acpi_walk_state *walk_state,
  110. union acpi_parse_object **out_op)
  111. {
  112. union acpi_parse_object *op;
  113. struct acpi_namespace_node *node;
  114. acpi_status status;
  115. acpi_object_type object_type;
  116. char *path;
  117. u32 flags;
  118. ACPI_FUNCTION_NAME ("ds_load1_begin_op");
  119. op = walk_state->op;
  120. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op, walk_state));
  121. /* We are only interested in opcodes that have an associated name */
  122. if (op) {
  123. if (!(walk_state->op_info->flags & AML_NAMED)) {
  124. #if 0
  125. if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
  126. (walk_state->op_info->class == AML_CLASS_CONTROL)) {
  127. acpi_os_printf ("\n\n***EXECUTABLE OPCODE %s***\n\n", walk_state->op_info->name);
  128. *out_op = op;
  129. return (AE_CTRL_SKIP);
  130. }
  131. #endif
  132. *out_op = op;
  133. return (AE_OK);
  134. }
  135. /* Check if this object has already been installed in the namespace */
  136. if (op->common.node) {
  137. *out_op = op;
  138. return (AE_OK);
  139. }
  140. }
  141. path = acpi_ps_get_next_namestring (&walk_state->parser_state);
  142. /* Map the raw opcode into an internal object type */
  143. object_type = walk_state->op_info->object_type;
  144. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  145. "State=%p Op=%p [%s]\n", walk_state, op, acpi_ut_get_type_name (object_type)));
  146. switch (walk_state->opcode) {
  147. case AML_SCOPE_OP:
  148. /*
  149. * The target name of the Scope() operator must exist at this point so
  150. * that we can actually open the scope to enter new names underneath it.
  151. * Allow search-to-root for single namesegs.
  152. */
  153. status = acpi_ns_lookup (walk_state->scope_info, path, object_type,
  154. ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node));
  155. #ifdef _ACPI_ASL_COMPILER
  156. if (status == AE_NOT_FOUND) {
  157. /*
  158. * Table disassembly:
  159. * Target of Scope() not found. Generate an External for it, and
  160. * insert the name into the namespace.
  161. */
  162. acpi_dm_add_to_external_list (path);
  163. status = acpi_ns_lookup (walk_state->scope_info, path, object_type,
  164. ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, walk_state, &(node));
  165. }
  166. #endif
  167. if (ACPI_FAILURE (status)) {
  168. ACPI_REPORT_NSERROR (path, status);
  169. return (status);
  170. }
  171. /*
  172. * Check to make sure that the target is
  173. * one of the opcodes that actually opens a scope
  174. */
  175. switch (node->type) {
  176. case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
  177. case ACPI_TYPE_DEVICE:
  178. case ACPI_TYPE_POWER:
  179. case ACPI_TYPE_PROCESSOR:
  180. case ACPI_TYPE_THERMAL:
  181. /* These are acceptable types */
  182. break;
  183. case ACPI_TYPE_INTEGER:
  184. case ACPI_TYPE_STRING:
  185. case ACPI_TYPE_BUFFER:
  186. /*
  187. * These types we will allow, but we will change the type. This
  188. * enables some existing code of the form:
  189. *
  190. * Name (DEB, 0)
  191. * Scope (DEB) { ... }
  192. *
  193. * Note: silently change the type here. On the second pass, we will report a warning
  194. */
  195. ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
  196. path, acpi_ut_get_type_name (node->type)));
  197. node->type = ACPI_TYPE_ANY;
  198. walk_state->scope_info->common.value = ACPI_TYPE_ANY;
  199. break;
  200. default:
  201. /* All other types are an error */
  202. ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)\n",
  203. acpi_ut_get_type_name (node->type), path));
  204. return (AE_AML_OPERAND_TYPE);
  205. }
  206. break;
  207. default:
  208. /*
  209. * For all other named opcodes, we will enter the name into the namespace.
  210. *
  211. * Setup the search flags.
  212. * Since we are entering a name into the namespace, we do not want to
  213. * enable the search-to-root upsearch.
  214. *
  215. * There are only two conditions where it is acceptable that the name
  216. * already exists:
  217. * 1) the Scope() operator can reopen a scoping object that was
  218. * previously defined (Scope, Method, Device, etc.)
  219. * 2) Whenever we are parsing a deferred opcode (op_region, Buffer,
  220. * buffer_field, or Package), the name of the object is already
  221. * in the namespace.
  222. */
  223. if (walk_state->deferred_node) {
  224. /* This name is already in the namespace, get the node */
  225. node = walk_state->deferred_node;
  226. status = AE_OK;
  227. break;
  228. }
  229. flags = ACPI_NS_NO_UPSEARCH;
  230. if ((walk_state->opcode != AML_SCOPE_OP) &&
  231. (!(walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP))) {
  232. flags |= ACPI_NS_ERROR_IF_FOUND;
  233. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
  234. acpi_ut_get_type_name (object_type)));
  235. }
  236. else {
  237. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Both Find or Create allowed\n",
  238. acpi_ut_get_type_name (object_type)));
  239. }
  240. /*
  241. * Enter the named type into the internal namespace. We enter the name
  242. * as we go downward in the parse tree. Any necessary subobjects that involve
  243. * arguments to the opcode must be created as we go back up the parse tree later.
  244. */
  245. status = acpi_ns_lookup (walk_state->scope_info, path, object_type,
  246. ACPI_IMODE_LOAD_PASS1, flags, walk_state, &(node));
  247. if (ACPI_FAILURE (status)) {
  248. ACPI_REPORT_NSERROR (path, status);
  249. return (status);
  250. }
  251. break;
  252. }
  253. /* Common exit */
  254. if (!op) {
  255. /* Create a new op */
  256. op = acpi_ps_alloc_op (walk_state->opcode);
  257. if (!op) {
  258. return (AE_NO_MEMORY);
  259. }
  260. }
  261. /* Initialize */
  262. op->named.name = node->name.integer;
  263. #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
  264. op->named.path = (u8 *) path;
  265. #endif
  266. /*
  267. * Put the Node in the "op" object that the parser uses, so we
  268. * can get it again quickly when this scope is closed
  269. */
  270. op->common.node = node;
  271. acpi_ps_append_arg (acpi_ps_get_parent_scope (&walk_state->parser_state), op);
  272. *out_op = op;
  273. return (status);
  274. }
  275. /*******************************************************************************
  276. *
  277. * FUNCTION: acpi_ds_load1_end_op
  278. *
  279. * PARAMETERS: walk_state - Current state of the parse tree walk
  280. * Op - Op that has been just been completed in the
  281. * walk; Arguments have now been evaluated.
  282. *
  283. * RETURN: Status
  284. *
  285. * DESCRIPTION: Ascending callback used during the loading of the namespace,
  286. * both control methods and everything else.
  287. *
  288. ******************************************************************************/
  289. acpi_status
  290. acpi_ds_load1_end_op (
  291. struct acpi_walk_state *walk_state)
  292. {
  293. union acpi_parse_object *op;
  294. acpi_object_type object_type;
  295. acpi_status status = AE_OK;
  296. ACPI_FUNCTION_NAME ("ds_load1_end_op");
  297. op = walk_state->op;
  298. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op, walk_state));
  299. /* We are only interested in opcodes that have an associated name */
  300. if (!(walk_state->op_info->flags & (AML_NAMED | AML_FIELD))) {
  301. return (AE_OK);
  302. }
  303. /* Get the object type to determine if we should pop the scope */
  304. object_type = walk_state->op_info->object_type;
  305. #ifndef ACPI_NO_METHOD_EXECUTION
  306. if (walk_state->op_info->flags & AML_FIELD) {
  307. if (walk_state->opcode == AML_FIELD_OP ||
  308. walk_state->opcode == AML_BANK_FIELD_OP ||
  309. walk_state->opcode == AML_INDEX_FIELD_OP) {
  310. status = acpi_ds_init_field_objects (op, walk_state);
  311. }
  312. return (status);
  313. }
  314. if (op->common.aml_opcode == AML_REGION_OP) {
  315. status = acpi_ex_create_region (op->named.data, op->named.length,
  316. (acpi_adr_space_type) ((op->common.value.arg)->common.value.integer), walk_state);
  317. if (ACPI_FAILURE (status)) {
  318. return (status);
  319. }
  320. }
  321. #endif
  322. if (op->common.aml_opcode == AML_NAME_OP) {
  323. /* For Name opcode, get the object type from the argument */
  324. if (op->common.value.arg) {
  325. object_type = (acpi_ps_get_opcode_info ((op->common.value.arg)->common.aml_opcode))->object_type;
  326. op->common.node->type = (u8) object_type;
  327. }
  328. }
  329. if (op->common.aml_opcode == AML_METHOD_OP) {
  330. /*
  331. * method_op pkg_length name_string method_flags term_list
  332. *
  333. * Note: We must create the method node/object pair as soon as we
  334. * see the method declaration. This allows later pass1 parsing
  335. * of invocations of the method (need to know the number of
  336. * arguments.)
  337. */
  338. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  339. "LOADING-Method: State=%p Op=%p named_obj=%p\n",
  340. walk_state, op, op->named.node));
  341. if (!acpi_ns_get_attached_object (op->named.node)) {
  342. walk_state->operands[0] = (void *) op->named.node;
  343. walk_state->num_operands = 1;
  344. status = acpi_ds_create_operands (walk_state, op->common.value.arg);
  345. if (ACPI_SUCCESS (status)) {
  346. status = acpi_ex_create_method (op->named.data,
  347. op->named.length, walk_state);
  348. }
  349. walk_state->operands[0] = NULL;
  350. walk_state->num_operands = 0;
  351. if (ACPI_FAILURE (status)) {
  352. return (status);
  353. }
  354. }
  355. }
  356. /* Pop the scope stack */
  357. if (acpi_ns_opens_scope (object_type)) {
  358. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
  359. acpi_ut_get_type_name (object_type), op));
  360. status = acpi_ds_scope_stack_pop (walk_state);
  361. }
  362. return (status);
  363. }
  364. /*******************************************************************************
  365. *
  366. * FUNCTION: acpi_ds_load2_begin_op
  367. *
  368. * PARAMETERS: walk_state - Current state of the parse tree walk
  369. * Op - Op that has been just been reached in the
  370. * walk; Arguments have not been evaluated yet.
  371. *
  372. * RETURN: Status
  373. *
  374. * DESCRIPTION: Descending callback used during the loading of ACPI tables.
  375. *
  376. ******************************************************************************/
  377. acpi_status
  378. acpi_ds_load2_begin_op (
  379. struct acpi_walk_state *walk_state,
  380. union acpi_parse_object **out_op)
  381. {
  382. union acpi_parse_object *op;
  383. struct acpi_namespace_node *node;
  384. acpi_status status;
  385. acpi_object_type object_type;
  386. char *buffer_ptr;
  387. ACPI_FUNCTION_TRACE ("ds_load2_begin_op");
  388. op = walk_state->op;
  389. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op, walk_state));
  390. if (op) {
  391. /* We only care about Namespace opcodes here */
  392. if ((!(walk_state->op_info->flags & AML_NSOPCODE) && (walk_state->opcode != AML_INT_NAMEPATH_OP)) ||
  393. (!(walk_state->op_info->flags & AML_NAMED))) {
  394. return_ACPI_STATUS (AE_OK);
  395. }
  396. /*
  397. * Get the name we are going to enter or lookup in the namespace
  398. */
  399. if (walk_state->opcode == AML_INT_NAMEPATH_OP) {
  400. /* For Namepath op, get the path string */
  401. buffer_ptr = op->common.value.string;
  402. if (!buffer_ptr) {
  403. /* No name, just exit */
  404. return_ACPI_STATUS (AE_OK);
  405. }
  406. }
  407. else {
  408. /* Get name from the op */
  409. buffer_ptr = (char *) &op->named.name;
  410. }
  411. }
  412. else {
  413. /* Get the namestring from the raw AML */
  414. buffer_ptr = acpi_ps_get_next_namestring (&walk_state->parser_state);
  415. }
  416. /* Map the opcode into an internal object type */
  417. object_type = walk_state->op_info->object_type;
  418. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  419. "State=%p Op=%p Type=%X\n", walk_state, op, object_type));
  420. switch (walk_state->opcode) {
  421. case AML_FIELD_OP:
  422. case AML_BANK_FIELD_OP:
  423. case AML_INDEX_FIELD_OP:
  424. node = NULL;
  425. status = AE_OK;
  426. break;
  427. case AML_INT_NAMEPATH_OP:
  428. /*
  429. * The name_path is an object reference to an existing object. Don't enter the
  430. * name into the namespace, but look it up for use later
  431. */
  432. status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
  433. ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node));
  434. break;
  435. case AML_SCOPE_OP:
  436. /*
  437. * The Path is an object reference to an existing object. Don't enter the
  438. * name into the namespace, but look it up for use later
  439. */
  440. status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
  441. ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node));
  442. if (ACPI_FAILURE (status)) {
  443. #ifdef _ACPI_ASL_COMPILER
  444. if (status == AE_NOT_FOUND) {
  445. status = AE_OK;
  446. }
  447. else {
  448. ACPI_REPORT_NSERROR (buffer_ptr, status);
  449. }
  450. #else
  451. ACPI_REPORT_NSERROR (buffer_ptr, status);
  452. #endif
  453. return_ACPI_STATUS (status);
  454. }
  455. /*
  456. * We must check to make sure that the target is
  457. * one of the opcodes that actually opens a scope
  458. */
  459. switch (node->type) {
  460. case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
  461. case ACPI_TYPE_DEVICE:
  462. case ACPI_TYPE_POWER:
  463. case ACPI_TYPE_PROCESSOR:
  464. case ACPI_TYPE_THERMAL:
  465. /* These are acceptable types */
  466. break;
  467. case ACPI_TYPE_INTEGER:
  468. case ACPI_TYPE_STRING:
  469. case ACPI_TYPE_BUFFER:
  470. /*
  471. * These types we will allow, but we will change the type. This
  472. * enables some existing code of the form:
  473. *
  474. * Name (DEB, 0)
  475. * Scope (DEB) { ... }
  476. */
  477. ACPI_REPORT_WARNING (("Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
  478. buffer_ptr, acpi_ut_get_type_name (node->type)));
  479. node->type = ACPI_TYPE_ANY;
  480. walk_state->scope_info->common.value = ACPI_TYPE_ANY;
  481. break;
  482. default:
  483. /* All other types are an error */
  484. ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s]\n",
  485. acpi_ut_get_type_name (node->type), buffer_ptr));
  486. return (AE_AML_OPERAND_TYPE);
  487. }
  488. break;
  489. default:
  490. /* All other opcodes */
  491. if (op && op->common.node) {
  492. /* This op/node was previously entered into the namespace */
  493. node = op->common.node;
  494. if (acpi_ns_opens_scope (object_type)) {
  495. status = acpi_ds_scope_stack_push (node, object_type, walk_state);
  496. if (ACPI_FAILURE (status)) {
  497. return_ACPI_STATUS (status);
  498. }
  499. }
  500. return_ACPI_STATUS (AE_OK);
  501. }
  502. /*
  503. * Enter the named type into the internal namespace. We enter the name
  504. * as we go downward in the parse tree. Any necessary subobjects that involve
  505. * arguments to the opcode must be created as we go back up the parse tree later.
  506. *
  507. * Note: Name may already exist if we are executing a deferred opcode.
  508. */
  509. if (walk_state->deferred_node) {
  510. /* This name is already in the namespace, get the node */
  511. node = walk_state->deferred_node;
  512. status = AE_OK;
  513. break;
  514. }
  515. status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
  516. ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, walk_state, &(node));
  517. break;
  518. }
  519. if (ACPI_FAILURE (status)) {
  520. ACPI_REPORT_NSERROR (buffer_ptr, status);
  521. return_ACPI_STATUS (status);
  522. }
  523. if (!op) {
  524. /* Create a new op */
  525. op = acpi_ps_alloc_op (walk_state->opcode);
  526. if (!op) {
  527. return_ACPI_STATUS (AE_NO_MEMORY);
  528. }
  529. /* Initialize the new op */
  530. if (node) {
  531. op->named.name = node->name.integer;
  532. }
  533. if (out_op) {
  534. *out_op = op;
  535. }
  536. }
  537. /*
  538. * Put the Node in the "op" object that the parser uses, so we
  539. * can get it again quickly when this scope is closed
  540. */
  541. op->common.node = node;
  542. return_ACPI_STATUS (status);
  543. }
  544. /*******************************************************************************
  545. *
  546. * FUNCTION: acpi_ds_load2_end_op
  547. *
  548. * PARAMETERS: walk_state - Current state of the parse tree walk
  549. * Op - Op that has been just been completed in the
  550. * walk; Arguments have now been evaluated.
  551. *
  552. * RETURN: Status
  553. *
  554. * DESCRIPTION: Ascending callback used during the loading of the namespace,
  555. * both control methods and everything else.
  556. *
  557. ******************************************************************************/
  558. acpi_status
  559. acpi_ds_load2_end_op (
  560. struct acpi_walk_state *walk_state)
  561. {
  562. union acpi_parse_object *op;
  563. acpi_status status = AE_OK;
  564. acpi_object_type object_type;
  565. struct acpi_namespace_node *node;
  566. union acpi_parse_object *arg;
  567. struct acpi_namespace_node *new_node;
  568. #ifndef ACPI_NO_METHOD_EXECUTION
  569. u32 i;
  570. #endif
  571. ACPI_FUNCTION_TRACE ("ds_load2_end_op");
  572. op = walk_state->op;
  573. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
  574. walk_state->op_info->name, op, walk_state));
  575. /* Only interested in opcodes that have namespace objects */
  576. if (!(walk_state->op_info->flags & AML_NSOBJECT)) {
  577. return_ACPI_STATUS (AE_OK);
  578. }
  579. if (op->common.aml_opcode == AML_SCOPE_OP) {
  580. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  581. "Ending scope Op=%p State=%p\n", op, walk_state));
  582. }
  583. object_type = walk_state->op_info->object_type;
  584. /*
  585. * Get the Node/name from the earlier lookup
  586. * (It was saved in the *op structure)
  587. */
  588. node = op->common.node;
  589. /*
  590. * Put the Node on the object stack (Contains the ACPI Name of
  591. * this object)
  592. */
  593. walk_state->operands[0] = (void *) node;
  594. walk_state->num_operands = 1;
  595. /* Pop the scope stack */
  596. if (acpi_ns_opens_scope (object_type) && (op->common.aml_opcode != AML_INT_METHODCALL_OP)) {
  597. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
  598. acpi_ut_get_type_name (object_type), op));
  599. status = acpi_ds_scope_stack_pop (walk_state);
  600. if (ACPI_FAILURE (status)) {
  601. goto cleanup;
  602. }
  603. }
  604. /*
  605. * Named operations are as follows:
  606. *
  607. * AML_ALIAS
  608. * AML_BANKFIELD
  609. * AML_CREATEBITFIELD
  610. * AML_CREATEBYTEFIELD
  611. * AML_CREATEDWORDFIELD
  612. * AML_CREATEFIELD
  613. * AML_CREATEQWORDFIELD
  614. * AML_CREATEWORDFIELD
  615. * AML_DATA_REGION
  616. * AML_DEVICE
  617. * AML_EVENT
  618. * AML_FIELD
  619. * AML_INDEXFIELD
  620. * AML_METHOD
  621. * AML_METHODCALL
  622. * AML_MUTEX
  623. * AML_NAME
  624. * AML_NAMEDFIELD
  625. * AML_OPREGION
  626. * AML_POWERRES
  627. * AML_PROCESSOR
  628. * AML_SCOPE
  629. * AML_THERMALZONE
  630. */
  631. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  632. "Create-Load [%s] State=%p Op=%p named_obj=%p\n",
  633. acpi_ps_get_opcode_name (op->common.aml_opcode), walk_state, op, node));
  634. /* Decode the opcode */
  635. arg = op->common.value.arg;
  636. switch (walk_state->op_info->type) {
  637. #ifndef ACPI_NO_METHOD_EXECUTION
  638. case AML_TYPE_CREATE_FIELD:
  639. /*
  640. * Create the field object, but the field buffer and index must
  641. * be evaluated later during the execution phase
  642. */
  643. status = acpi_ds_create_buffer_field (op, walk_state);
  644. break;
  645. case AML_TYPE_NAMED_FIELD:
  646. switch (op->common.aml_opcode) {
  647. case AML_INDEX_FIELD_OP:
  648. status = acpi_ds_create_index_field (op, (acpi_handle) arg->common.node,
  649. walk_state);
  650. break;
  651. case AML_BANK_FIELD_OP:
  652. status = acpi_ds_create_bank_field (op, arg->common.node, walk_state);
  653. break;
  654. case AML_FIELD_OP:
  655. status = acpi_ds_create_field (op, arg->common.node, walk_state);
  656. break;
  657. default:
  658. /* All NAMED_FIELD opcodes must be handled above */
  659. break;
  660. }
  661. break;
  662. case AML_TYPE_NAMED_SIMPLE:
  663. status = acpi_ds_create_operands (walk_state, arg);
  664. if (ACPI_FAILURE (status)) {
  665. goto cleanup;
  666. }
  667. switch (op->common.aml_opcode) {
  668. case AML_PROCESSOR_OP:
  669. status = acpi_ex_create_processor (walk_state);
  670. break;
  671. case AML_POWER_RES_OP:
  672. status = acpi_ex_create_power_resource (walk_state);
  673. break;
  674. case AML_MUTEX_OP:
  675. status = acpi_ex_create_mutex (walk_state);
  676. break;
  677. case AML_EVENT_OP:
  678. status = acpi_ex_create_event (walk_state);
  679. break;
  680. case AML_DATA_REGION_OP:
  681. status = acpi_ex_create_table_region (walk_state);
  682. break;
  683. case AML_ALIAS_OP:
  684. status = acpi_ex_create_alias (walk_state);
  685. break;
  686. default:
  687. /* Unknown opcode */
  688. status = AE_OK;
  689. goto cleanup;
  690. }
  691. /* Delete operands */
  692. for (i = 1; i < walk_state->num_operands; i++) {
  693. acpi_ut_remove_reference (walk_state->operands[i]);
  694. walk_state->operands[i] = NULL;
  695. }
  696. break;
  697. #endif /* ACPI_NO_METHOD_EXECUTION */
  698. case AML_TYPE_NAMED_COMPLEX:
  699. switch (op->common.aml_opcode) {
  700. #ifndef ACPI_NO_METHOD_EXECUTION
  701. case AML_REGION_OP:
  702. /*
  703. * The op_region is not fully parsed at this time. Only valid argument is the space_id.
  704. * (We must save the address of the AML of the address and length operands)
  705. */
  706. /*
  707. * If we have a valid region, initialize it
  708. * Namespace is NOT locked at this point.
  709. */
  710. status = acpi_ev_initialize_region (acpi_ns_get_attached_object (node), FALSE);
  711. if (ACPI_FAILURE (status)) {
  712. /*
  713. * If AE_NOT_EXIST is returned, it is not fatal
  714. * because many regions get created before a handler
  715. * is installed for said region.
  716. */
  717. if (AE_NOT_EXIST == status) {
  718. status = AE_OK;
  719. }
  720. }
  721. break;
  722. case AML_NAME_OP:
  723. status = acpi_ds_create_node (walk_state, node, op);
  724. break;
  725. #endif /* ACPI_NO_METHOD_EXECUTION */
  726. default:
  727. /* All NAMED_COMPLEX opcodes must be handled above */
  728. /* Note: Method objects were already created in Pass 1 */
  729. break;
  730. }
  731. break;
  732. case AML_CLASS_INTERNAL:
  733. /* case AML_INT_NAMEPATH_OP: */
  734. break;
  735. case AML_CLASS_METHOD_CALL:
  736. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  737. "RESOLVING-method_call: State=%p Op=%p named_obj=%p\n",
  738. walk_state, op, node));
  739. /*
  740. * Lookup the method name and save the Node
  741. */
  742. status = acpi_ns_lookup (walk_state->scope_info, arg->common.value.string,
  743. ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
  744. ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
  745. walk_state, &(new_node));
  746. if (ACPI_SUCCESS (status)) {
  747. /*
  748. * Make sure that what we found is indeed a method
  749. * We didn't search for a method on purpose, to see if the name would resolve
  750. */
  751. if (new_node->type != ACPI_TYPE_METHOD) {
  752. status = AE_AML_OPERAND_TYPE;
  753. }
  754. /* We could put the returned object (Node) on the object stack for later, but
  755. * for now, we will put it in the "op" object that the parser uses, so we
  756. * can get it again at the end of this scope
  757. */
  758. op->common.node = new_node;
  759. }
  760. else {
  761. ACPI_REPORT_NSERROR (arg->common.value.string, status);
  762. }
  763. break;
  764. default:
  765. break;
  766. }
  767. cleanup:
  768. /* Remove the Node pushed at the very beginning */
  769. walk_state->operands[0] = NULL;
  770. walk_state->num_operands = 0;
  771. return_ACPI_STATUS (status);
  772. }