dswload.c 26 KB

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