dswload.c 26 KB

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