dswload.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. /******************************************************************************
  2. *
  3. * Module Name: dswload - Dispatcher namespace load callbacks
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include <acpi/acparser.h>
  44. #include <acpi/amlcode.h>
  45. #include <acpi/acdispat.h>
  46. #include <acpi/acinterp.h>
  47. #include <acpi/acnamesp.h>
  48. #include <acpi/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(struct acpi_walk_state *walk_state, u32 pass_number)
  68. {
  69. switch (pass_number) {
  70. case 1:
  71. walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 |
  72. ACPI_PARSE_DELETE_TREE;
  73. walk_state->descending_callback = acpi_ds_load1_begin_op;
  74. walk_state->ascending_callback = acpi_ds_load1_end_op;
  75. break;
  76. case 2:
  77. walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 |
  78. 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 |
  85. ACPI_PARSE_DELETE_TREE;
  86. walk_state->descending_callback = acpi_ds_exec_begin_op;
  87. walk_state->ascending_callback = acpi_ds_exec_end_op;
  88. #endif
  89. break;
  90. default:
  91. return (AE_BAD_PARAMETER);
  92. }
  93. return (AE_OK);
  94. }
  95. /*******************************************************************************
  96. *
  97. * FUNCTION: acpi_ds_load1_begin_op
  98. *
  99. * PARAMETERS: walk_state - Current state of the parse tree walk
  100. * out_op - Where to return op if a new one is created
  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(struct acpi_walk_state * walk_state,
  109. union acpi_parse_object ** out_op)
  110. {
  111. union acpi_parse_object *op;
  112. struct acpi_namespace_node *node;
  113. acpi_status status;
  114. acpi_object_type object_type;
  115. char *path;
  116. u32 flags;
  117. ACPI_FUNCTION_TRACE("ds_load1_begin_op");
  118. op = walk_state->op;
  119. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op,
  120. 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. *out_op = op;
  125. return_ACPI_STATUS(AE_OK);
  126. }
  127. /* Check if this object has already been installed in the namespace */
  128. if (op->common.node) {
  129. *out_op = op;
  130. return_ACPI_STATUS(AE_OK);
  131. }
  132. }
  133. path = acpi_ps_get_next_namestring(&walk_state->parser_state);
  134. /* Map the raw opcode into an internal object type */
  135. object_type = walk_state->op_info->object_type;
  136. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  137. "State=%p Op=%p [%s]\n", walk_state, op,
  138. acpi_ut_get_type_name(object_type)));
  139. switch (walk_state->opcode) {
  140. case AML_SCOPE_OP:
  141. /*
  142. * The target name of the Scope() operator must exist at this point so
  143. * that we can actually open the scope to enter new names underneath it.
  144. * Allow search-to-root for single namesegs.
  145. */
  146. status =
  147. acpi_ns_lookup(walk_state->scope_info, path, object_type,
  148. ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
  149. walk_state, &(node));
  150. #ifdef ACPI_ASL_COMPILER
  151. if (status == AE_NOT_FOUND) {
  152. /*
  153. * Table disassembly:
  154. * Target of Scope() not found. Generate an External for it, and
  155. * insert the name into the namespace.
  156. */
  157. acpi_dm_add_to_external_list(path);
  158. status =
  159. acpi_ns_lookup(walk_state->scope_info, path,
  160. object_type, ACPI_IMODE_LOAD_PASS1,
  161. ACPI_NS_SEARCH_PARENT, walk_state,
  162. &(node));
  163. }
  164. #endif
  165. if (ACPI_FAILURE(status)) {
  166. ACPI_ERROR_NAMESPACE(path, status);
  167. return_ACPI_STATUS(status);
  168. }
  169. /*
  170. * Check to make sure that the target is
  171. * one of the opcodes that actually opens a scope
  172. */
  173. switch (node->type) {
  174. case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
  175. case ACPI_TYPE_DEVICE:
  176. case ACPI_TYPE_POWER:
  177. case ACPI_TYPE_PROCESSOR:
  178. case ACPI_TYPE_THERMAL:
  179. /* These are acceptable types */
  180. break;
  181. case ACPI_TYPE_INTEGER:
  182. case ACPI_TYPE_STRING:
  183. case ACPI_TYPE_BUFFER:
  184. /*
  185. * These types we will allow, but we will change the type. This
  186. * enables some existing code of the form:
  187. *
  188. * Name (DEB, 0)
  189. * Scope (DEB) { ... }
  190. *
  191. * Note: silently change the type here. On the second pass, we will report
  192. * a warning
  193. */
  194. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  195. "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
  196. path,
  197. acpi_ut_get_type_name(node->type)));
  198. node->type = ACPI_TYPE_ANY;
  199. walk_state->scope_info->common.value = ACPI_TYPE_ANY;
  200. break;
  201. default:
  202. /* All other types are an error */
  203. ACPI_ERROR((AE_INFO,
  204. "Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)",
  205. acpi_ut_get_type_name(node->type), path));
  206. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  207. }
  208. break;
  209. default:
  210. /*
  211. * For all other named opcodes, we will enter the name into
  212. * the namespace.
  213. *
  214. * Setup the search flags.
  215. * Since we are entering a name into the namespace, we do not want to
  216. * enable the search-to-root upsearch.
  217. *
  218. * There are only two conditions where it is acceptable that the name
  219. * already exists:
  220. * 1) the Scope() operator can reopen a scoping object that was
  221. * previously defined (Scope, Method, Device, etc.)
  222. * 2) Whenever we are parsing a deferred opcode (op_region, Buffer,
  223. * buffer_field, or Package), the name of the object is already
  224. * in the namespace.
  225. */
  226. if (walk_state->deferred_node) {
  227. /* This name is already in the namespace, get the node */
  228. node = walk_state->deferred_node;
  229. status = AE_OK;
  230. break;
  231. }
  232. /*
  233. * If we are executing a method, do not create any namespace objects
  234. * during the load phase, only during execution.
  235. */
  236. if (walk_state->method_node) {
  237. node = NULL;
  238. status = AE_OK;
  239. break;
  240. }
  241. flags = ACPI_NS_NO_UPSEARCH;
  242. if ((walk_state->opcode != AML_SCOPE_OP) &&
  243. (!(walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP))) {
  244. flags |= ACPI_NS_ERROR_IF_FOUND;
  245. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  246. "[%s] Cannot already exist\n",
  247. acpi_ut_get_type_name(object_type)));
  248. } else {
  249. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  250. "[%s] Both Find or Create allowed\n",
  251. acpi_ut_get_type_name(object_type)));
  252. }
  253. /*
  254. * Enter the named type into the internal namespace. We enter the name
  255. * as we go downward in the parse tree. Any necessary subobjects that
  256. * involve arguments to the opcode must be created as we go back up the
  257. * parse tree later.
  258. */
  259. status =
  260. acpi_ns_lookup(walk_state->scope_info, path, object_type,
  261. ACPI_IMODE_LOAD_PASS1, flags, walk_state,
  262. &(node));
  263. if (ACPI_FAILURE(status)) {
  264. ACPI_ERROR_NAMESPACE(path, status);
  265. return_ACPI_STATUS(status);
  266. }
  267. break;
  268. }
  269. /* Common exit */
  270. if (!op) {
  271. /* Create a new op */
  272. op = acpi_ps_alloc_op(walk_state->opcode);
  273. if (!op) {
  274. return_ACPI_STATUS(AE_NO_MEMORY);
  275. }
  276. }
  277. /* Initialize the op */
  278. #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
  279. op->named.path = ACPI_CAST_PTR(u8, path);
  280. #endif
  281. if (node) {
  282. /*
  283. * Put the Node in the "op" object that the parser uses, so we
  284. * can get it again quickly when this scope is closed
  285. */
  286. op->common.node = node;
  287. op->named.name = node->name.integer;
  288. }
  289. acpi_ps_append_arg(acpi_ps_get_parent_scope(&walk_state->parser_state),
  290. op);
  291. *out_op = op;
  292. return_ACPI_STATUS(status);
  293. }
  294. /*******************************************************************************
  295. *
  296. * FUNCTION: acpi_ds_load1_end_op
  297. *
  298. * PARAMETERS: walk_state - Current state of the parse tree walk
  299. *
  300. * RETURN: Status
  301. *
  302. * DESCRIPTION: Ascending callback used during the loading of the namespace,
  303. * both control methods and everything else.
  304. *
  305. ******************************************************************************/
  306. acpi_status acpi_ds_load1_end_op(struct acpi_walk_state *walk_state)
  307. {
  308. union acpi_parse_object *op;
  309. acpi_object_type object_type;
  310. acpi_status status = AE_OK;
  311. ACPI_FUNCTION_TRACE("ds_load1_end_op");
  312. op = walk_state->op;
  313. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op,
  314. walk_state));
  315. /* We are only interested in opcodes that have an associated name */
  316. if (!(walk_state->op_info->flags & (AML_NAMED | AML_FIELD))) {
  317. return_ACPI_STATUS(AE_OK);
  318. }
  319. /* Get the object type to determine if we should pop the scope */
  320. object_type = walk_state->op_info->object_type;
  321. #ifndef ACPI_NO_METHOD_EXECUTION
  322. if (walk_state->op_info->flags & AML_FIELD) {
  323. /*
  324. * If we are executing a method, do not create any namespace objects
  325. * during the load phase, only during execution.
  326. */
  327. if (!walk_state->method_node) {
  328. if (walk_state->opcode == AML_FIELD_OP ||
  329. walk_state->opcode == AML_BANK_FIELD_OP ||
  330. walk_state->opcode == AML_INDEX_FIELD_OP) {
  331. status =
  332. acpi_ds_init_field_objects(op, walk_state);
  333. }
  334. }
  335. return_ACPI_STATUS(status);
  336. }
  337. /*
  338. * If we are executing a method, do not create any namespace objects
  339. * during the load phase, only during execution.
  340. */
  341. if (!walk_state->method_node) {
  342. if (op->common.aml_opcode == AML_REGION_OP) {
  343. status =
  344. acpi_ex_create_region(op->named.data,
  345. op->named.length,
  346. (acpi_adr_space_type)
  347. ((op->common.value.arg)->
  348. common.value.integer),
  349. walk_state);
  350. if (ACPI_FAILURE(status)) {
  351. return_ACPI_STATUS(status);
  352. }
  353. }
  354. }
  355. #endif
  356. if (op->common.aml_opcode == AML_NAME_OP) {
  357. /* For Name opcode, get the object type from the argument */
  358. if (op->common.value.arg) {
  359. object_type = (acpi_ps_get_opcode_info((op->common.
  360. value.arg)->
  361. common.
  362. aml_opcode))->
  363. object_type;
  364. /* Set node type if we have a namespace node */
  365. if (op->common.node) {
  366. op->common.node->type = (u8) object_type;
  367. }
  368. }
  369. }
  370. /*
  371. * If we are executing a method, do not create any namespace objects
  372. * during the load phase, only during execution.
  373. */
  374. if (!walk_state->method_node) {
  375. if (op->common.aml_opcode == AML_METHOD_OP) {
  376. /*
  377. * method_op pkg_length name_string method_flags term_list
  378. *
  379. * Note: We must create the method node/object pair as soon as we
  380. * see the method declaration. This allows later pass1 parsing
  381. * of invocations of the method (need to know the number of
  382. * arguments.)
  383. */
  384. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  385. "LOADING-Method: State=%p Op=%p named_obj=%p\n",
  386. walk_state, op, op->named.node));
  387. if (!acpi_ns_get_attached_object(op->named.node)) {
  388. walk_state->operands[0] =
  389. ACPI_CAST_PTR(void, op->named.node);
  390. walk_state->num_operands = 1;
  391. status =
  392. acpi_ds_create_operands(walk_state,
  393. op->common.value.
  394. arg);
  395. if (ACPI_SUCCESS(status)) {
  396. status =
  397. acpi_ex_create_method(op->named.
  398. data,
  399. op->named.
  400. length,
  401. walk_state);
  402. }
  403. walk_state->operands[0] = NULL;
  404. walk_state->num_operands = 0;
  405. if (ACPI_FAILURE(status)) {
  406. return_ACPI_STATUS(status);
  407. }
  408. }
  409. }
  410. }
  411. /* Pop the scope stack (only if loading a table) */
  412. if (!walk_state->method_node && acpi_ns_opens_scope(object_type)) {
  413. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  414. "(%s): Popping scope for Op %p\n",
  415. acpi_ut_get_type_name(object_type), op));
  416. status = acpi_ds_scope_stack_pop(walk_state);
  417. }
  418. return_ACPI_STATUS(status);
  419. }
  420. /*******************************************************************************
  421. *
  422. * FUNCTION: acpi_ds_load2_begin_op
  423. *
  424. * PARAMETERS: walk_state - Current state of the parse tree walk
  425. * out_op - Wher to return op if a new one is created
  426. *
  427. * RETURN: Status
  428. *
  429. * DESCRIPTION: Descending callback used during the loading of ACPI tables.
  430. *
  431. ******************************************************************************/
  432. acpi_status
  433. acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
  434. union acpi_parse_object **out_op)
  435. {
  436. union acpi_parse_object *op;
  437. struct acpi_namespace_node *node;
  438. acpi_status status;
  439. acpi_object_type object_type;
  440. char *buffer_ptr;
  441. ACPI_FUNCTION_TRACE("ds_load2_begin_op");
  442. op = walk_state->op;
  443. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op,
  444. walk_state));
  445. if (op) {
  446. if ((walk_state->control_state) &&
  447. (walk_state->control_state->common.state ==
  448. ACPI_CONTROL_CONDITIONAL_EXECUTING)) {
  449. /* We are executing a while loop outside of a method */
  450. status = acpi_ds_exec_begin_op(walk_state, out_op);
  451. return_ACPI_STATUS(status);
  452. }
  453. /* We only care about Namespace opcodes here */
  454. if ((!(walk_state->op_info->flags & AML_NSOPCODE) &&
  455. (walk_state->opcode != AML_INT_NAMEPATH_OP)) ||
  456. (!(walk_state->op_info->flags & AML_NAMED))) {
  457. #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
  458. if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
  459. (walk_state->op_info->class == AML_CLASS_CONTROL)) {
  460. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  461. "Begin/EXEC: %s (fl %8.8X)\n",
  462. walk_state->op_info->name,
  463. walk_state->op_info->flags));
  464. /* Executing a type1 or type2 opcode outside of a method */
  465. status =
  466. acpi_ds_exec_begin_op(walk_state, out_op);
  467. return_ACPI_STATUS(status);
  468. }
  469. #endif
  470. return_ACPI_STATUS(AE_OK);
  471. }
  472. /* Get the name we are going to enter or lookup in the namespace */
  473. if (walk_state->opcode == AML_INT_NAMEPATH_OP) {
  474. /* For Namepath op, get the path string */
  475. buffer_ptr = op->common.value.string;
  476. if (!buffer_ptr) {
  477. /* No name, just exit */
  478. return_ACPI_STATUS(AE_OK);
  479. }
  480. } else {
  481. /* Get name from the op */
  482. buffer_ptr = (char *)&op->named.name;
  483. }
  484. } else {
  485. /* Get the namestring from the raw AML */
  486. buffer_ptr =
  487. acpi_ps_get_next_namestring(&walk_state->parser_state);
  488. }
  489. /* Map the opcode into an internal object type */
  490. object_type = walk_state->op_info->object_type;
  491. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  492. "State=%p Op=%p Type=%X\n", walk_state, op,
  493. object_type));
  494. switch (walk_state->opcode) {
  495. case AML_FIELD_OP:
  496. case AML_BANK_FIELD_OP:
  497. case AML_INDEX_FIELD_OP:
  498. node = NULL;
  499. status = AE_OK;
  500. break;
  501. case AML_INT_NAMEPATH_OP:
  502. /*
  503. * The name_path is an object reference to an existing object.
  504. * Don't enter the name into the namespace, but look it up
  505. * for use later.
  506. */
  507. status =
  508. acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
  509. object_type, ACPI_IMODE_EXECUTE,
  510. ACPI_NS_SEARCH_PARENT, walk_state, &(node));
  511. break;
  512. case AML_SCOPE_OP:
  513. /*
  514. * The Path is an object reference to an existing object.
  515. * Don't enter the name into the namespace, but look it up
  516. * for use later.
  517. */
  518. status =
  519. acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
  520. object_type, ACPI_IMODE_EXECUTE,
  521. ACPI_NS_SEARCH_PARENT, walk_state, &(node));
  522. if (ACPI_FAILURE(status)) {
  523. #ifdef ACPI_ASL_COMPILER
  524. if (status == AE_NOT_FOUND) {
  525. status = AE_OK;
  526. } else {
  527. ACPI_ERROR_NAMESPACE(buffer_ptr, status);
  528. }
  529. #else
  530. ACPI_ERROR_NAMESPACE(buffer_ptr, status);
  531. #endif
  532. return_ACPI_STATUS(status);
  533. }
  534. /*
  535. * We must check to make sure that the target is
  536. * one of the opcodes that actually opens a scope
  537. */
  538. switch (node->type) {
  539. case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
  540. case ACPI_TYPE_DEVICE:
  541. case ACPI_TYPE_POWER:
  542. case ACPI_TYPE_PROCESSOR:
  543. case ACPI_TYPE_THERMAL:
  544. /* These are acceptable types */
  545. break;
  546. case ACPI_TYPE_INTEGER:
  547. case ACPI_TYPE_STRING:
  548. case ACPI_TYPE_BUFFER:
  549. /*
  550. * These types we will allow, but we will change the type. This
  551. * enables some existing code of the form:
  552. *
  553. * Name (DEB, 0)
  554. * Scope (DEB) { ... }
  555. */
  556. ACPI_WARNING((AE_INFO,
  557. "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)",
  558. buffer_ptr,
  559. acpi_ut_get_type_name(node->type)));
  560. node->type = ACPI_TYPE_ANY;
  561. walk_state->scope_info->common.value = ACPI_TYPE_ANY;
  562. break;
  563. default:
  564. /* All other types are an error */
  565. ACPI_ERROR((AE_INFO,
  566. "Invalid type (%s) for target of Scope operator [%4.4s]",
  567. acpi_ut_get_type_name(node->type),
  568. buffer_ptr));
  569. return (AE_AML_OPERAND_TYPE);
  570. }
  571. break;
  572. default:
  573. /* All other opcodes */
  574. if (op && op->common.node) {
  575. /* This op/node was previously entered into the namespace */
  576. node = op->common.node;
  577. if (acpi_ns_opens_scope(object_type)) {
  578. status =
  579. acpi_ds_scope_stack_push(node, object_type,
  580. walk_state);
  581. if (ACPI_FAILURE(status)) {
  582. return_ACPI_STATUS(status);
  583. }
  584. }
  585. return_ACPI_STATUS(AE_OK);
  586. }
  587. /*
  588. * Enter the named type into the internal namespace. We enter the name
  589. * as we go downward in the parse tree. Any necessary subobjects that
  590. * involve arguments to the opcode must be created as we go back up the
  591. * parse tree later.
  592. *
  593. * Note: Name may already exist if we are executing a deferred opcode.
  594. */
  595. if (walk_state->deferred_node) {
  596. /* This name is already in the namespace, get the node */
  597. node = walk_state->deferred_node;
  598. status = AE_OK;
  599. break;
  600. }
  601. /* Add new entry into namespace */
  602. status =
  603. acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
  604. object_type, ACPI_IMODE_LOAD_PASS2,
  605. ACPI_NS_NO_UPSEARCH, walk_state, &(node));
  606. break;
  607. }
  608. if (ACPI_FAILURE(status)) {
  609. ACPI_ERROR_NAMESPACE(buffer_ptr, status);
  610. return_ACPI_STATUS(status);
  611. }
  612. if (!op) {
  613. /* Create a new op */
  614. op = acpi_ps_alloc_op(walk_state->opcode);
  615. if (!op) {
  616. return_ACPI_STATUS(AE_NO_MEMORY);
  617. }
  618. /* Initialize the new op */
  619. if (node) {
  620. op->named.name = node->name.integer;
  621. }
  622. *out_op = op;
  623. }
  624. /*
  625. * Put the Node in the "op" object that the parser uses, so we
  626. * can get it again quickly when this scope is closed
  627. */
  628. op->common.node = node;
  629. return_ACPI_STATUS(status);
  630. }
  631. /*******************************************************************************
  632. *
  633. * FUNCTION: acpi_ds_load2_end_op
  634. *
  635. * PARAMETERS: walk_state - Current state of the parse tree walk
  636. *
  637. * RETURN: Status
  638. *
  639. * DESCRIPTION: Ascending callback used during the loading of the namespace,
  640. * both control methods and everything else.
  641. *
  642. ******************************************************************************/
  643. acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
  644. {
  645. union acpi_parse_object *op;
  646. acpi_status status = AE_OK;
  647. acpi_object_type object_type;
  648. struct acpi_namespace_node *node;
  649. union acpi_parse_object *arg;
  650. struct acpi_namespace_node *new_node;
  651. #ifndef ACPI_NO_METHOD_EXECUTION
  652. u32 i;
  653. #endif
  654. ACPI_FUNCTION_TRACE("ds_load2_end_op");
  655. op = walk_state->op;
  656. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
  657. walk_state->op_info->name, op, walk_state));
  658. /* Check if opcode had an associated namespace object */
  659. if (!(walk_state->op_info->flags & AML_NSOBJECT)) {
  660. #ifndef ACPI_NO_METHOD_EXECUTION
  661. #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
  662. /* No namespace object. Executable opcode? */
  663. if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
  664. (walk_state->op_info->class == AML_CLASS_CONTROL)) {
  665. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  666. "End/EXEC: %s (fl %8.8X)\n",
  667. walk_state->op_info->name,
  668. walk_state->op_info->flags));
  669. /* Executing a type1 or type2 opcode outside of a method */
  670. status = acpi_ds_exec_end_op(walk_state);
  671. return_ACPI_STATUS(status);
  672. }
  673. #endif
  674. #endif
  675. return_ACPI_STATUS(AE_OK);
  676. }
  677. if (op->common.aml_opcode == AML_SCOPE_OP) {
  678. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  679. "Ending scope Op=%p State=%p\n", op,
  680. walk_state));
  681. }
  682. object_type = walk_state->op_info->object_type;
  683. /*
  684. * Get the Node/name from the earlier lookup
  685. * (It was saved in the *op structure)
  686. */
  687. node = op->common.node;
  688. /*
  689. * Put the Node on the object stack (Contains the ACPI Name of
  690. * this object)
  691. */
  692. walk_state->operands[0] = (void *)node;
  693. walk_state->num_operands = 1;
  694. /* Pop the scope stack */
  695. if (acpi_ns_opens_scope(object_type) &&
  696. (op->common.aml_opcode != AML_INT_METHODCALL_OP)) {
  697. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  698. "(%s) Popping scope for Op %p\n",
  699. acpi_ut_get_type_name(object_type), op));
  700. status = acpi_ds_scope_stack_pop(walk_state);
  701. if (ACPI_FAILURE(status)) {
  702. goto cleanup;
  703. }
  704. }
  705. /*
  706. * Named operations are as follows:
  707. *
  708. * AML_ALIAS
  709. * AML_BANKFIELD
  710. * AML_CREATEBITFIELD
  711. * AML_CREATEBYTEFIELD
  712. * AML_CREATEDWORDFIELD
  713. * AML_CREATEFIELD
  714. * AML_CREATEQWORDFIELD
  715. * AML_CREATEWORDFIELD
  716. * AML_DATA_REGION
  717. * AML_DEVICE
  718. * AML_EVENT
  719. * AML_FIELD
  720. * AML_INDEXFIELD
  721. * AML_METHOD
  722. * AML_METHODCALL
  723. * AML_MUTEX
  724. * AML_NAME
  725. * AML_NAMEDFIELD
  726. * AML_OPREGION
  727. * AML_POWERRES
  728. * AML_PROCESSOR
  729. * AML_SCOPE
  730. * AML_THERMALZONE
  731. */
  732. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  733. "Create-Load [%s] State=%p Op=%p named_obj=%p\n",
  734. acpi_ps_get_opcode_name(op->common.aml_opcode),
  735. walk_state, op, node));
  736. /* Decode the opcode */
  737. arg = op->common.value.arg;
  738. switch (walk_state->op_info->type) {
  739. #ifndef ACPI_NO_METHOD_EXECUTION
  740. case AML_TYPE_CREATE_FIELD:
  741. /*
  742. * Create the field object, but the field buffer and index must
  743. * be evaluated later during the execution phase
  744. */
  745. status = acpi_ds_create_buffer_field(op, walk_state);
  746. break;
  747. case AML_TYPE_NAMED_FIELD:
  748. /*
  749. * If we are executing a method, initialize the field
  750. */
  751. if (walk_state->method_node) {
  752. status = acpi_ds_init_field_objects(op, walk_state);
  753. }
  754. switch (op->common.aml_opcode) {
  755. case AML_INDEX_FIELD_OP:
  756. status =
  757. acpi_ds_create_index_field(op,
  758. (acpi_handle) arg->
  759. common.node, walk_state);
  760. break;
  761. case AML_BANK_FIELD_OP:
  762. status =
  763. acpi_ds_create_bank_field(op, arg->common.node,
  764. walk_state);
  765. break;
  766. case AML_FIELD_OP:
  767. status =
  768. acpi_ds_create_field(op, arg->common.node,
  769. walk_state);
  770. break;
  771. default:
  772. /* All NAMED_FIELD opcodes must be handled above */
  773. break;
  774. }
  775. break;
  776. case AML_TYPE_NAMED_SIMPLE:
  777. status = acpi_ds_create_operands(walk_state, arg);
  778. if (ACPI_FAILURE(status)) {
  779. goto cleanup;
  780. }
  781. switch (op->common.aml_opcode) {
  782. case AML_PROCESSOR_OP:
  783. status = acpi_ex_create_processor(walk_state);
  784. break;
  785. case AML_POWER_RES_OP:
  786. status = acpi_ex_create_power_resource(walk_state);
  787. break;
  788. case AML_MUTEX_OP:
  789. status = acpi_ex_create_mutex(walk_state);
  790. break;
  791. case AML_EVENT_OP:
  792. status = acpi_ex_create_event(walk_state);
  793. break;
  794. case AML_DATA_REGION_OP:
  795. status = acpi_ex_create_table_region(walk_state);
  796. break;
  797. case AML_ALIAS_OP:
  798. status = acpi_ex_create_alias(walk_state);
  799. break;
  800. default:
  801. /* Unknown opcode */
  802. status = AE_OK;
  803. goto cleanup;
  804. }
  805. /* Delete operands */
  806. for (i = 1; i < walk_state->num_operands; i++) {
  807. acpi_ut_remove_reference(walk_state->operands[i]);
  808. walk_state->operands[i] = NULL;
  809. }
  810. break;
  811. #endif /* ACPI_NO_METHOD_EXECUTION */
  812. case AML_TYPE_NAMED_COMPLEX:
  813. switch (op->common.aml_opcode) {
  814. #ifndef ACPI_NO_METHOD_EXECUTION
  815. case AML_REGION_OP:
  816. /*
  817. * If we are executing a method, initialize the region
  818. */
  819. if (walk_state->method_node) {
  820. status =
  821. acpi_ex_create_region(op->named.data,
  822. op->named.length,
  823. (acpi_adr_space_type)
  824. ((op->common.value.
  825. arg)->common.value.
  826. integer),
  827. walk_state);
  828. if (ACPI_FAILURE(status)) {
  829. return (status);
  830. }
  831. }
  832. /*
  833. * The op_region is not fully parsed at this time. Only valid
  834. * argument is the space_id. (We must save the address of the
  835. * AML of the address and length operands)
  836. */
  837. /*
  838. * If we have a valid region, initialize it
  839. * Namespace is NOT locked at this point.
  840. */
  841. status =
  842. acpi_ev_initialize_region
  843. (acpi_ns_get_attached_object(node), FALSE);
  844. if (ACPI_FAILURE(status)) {
  845. /*
  846. * If AE_NOT_EXIST is returned, it is not fatal
  847. * because many regions get created before a handler
  848. * is installed for said region.
  849. */
  850. if (AE_NOT_EXIST == status) {
  851. status = AE_OK;
  852. }
  853. }
  854. break;
  855. case AML_NAME_OP:
  856. status = acpi_ds_create_node(walk_state, node, op);
  857. break;
  858. case AML_METHOD_OP:
  859. /*
  860. * method_op pkg_length name_string method_flags term_list
  861. *
  862. * Note: We must create the method node/object pair as soon as we
  863. * see the method declaration. This allows later pass1 parsing
  864. * of invocations of the method (need to know the number of
  865. * arguments.)
  866. */
  867. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  868. "LOADING-Method: State=%p Op=%p named_obj=%p\n",
  869. walk_state, op, op->named.node));
  870. if (!acpi_ns_get_attached_object(op->named.node)) {
  871. walk_state->operands[0] =
  872. ACPI_CAST_PTR(void, op->named.node);
  873. walk_state->num_operands = 1;
  874. status =
  875. acpi_ds_create_operands(walk_state,
  876. op->common.value.
  877. arg);
  878. if (ACPI_SUCCESS(status)) {
  879. status =
  880. acpi_ex_create_method(op->named.
  881. data,
  882. op->named.
  883. length,
  884. walk_state);
  885. }
  886. walk_state->operands[0] = NULL;
  887. walk_state->num_operands = 0;
  888. if (ACPI_FAILURE(status)) {
  889. return_ACPI_STATUS(status);
  890. }
  891. }
  892. break;
  893. #endif /* ACPI_NO_METHOD_EXECUTION */
  894. default:
  895. /* All NAMED_COMPLEX opcodes must be handled above */
  896. break;
  897. }
  898. break;
  899. case AML_CLASS_INTERNAL:
  900. /* case AML_INT_NAMEPATH_OP: */
  901. break;
  902. case AML_CLASS_METHOD_CALL:
  903. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  904. "RESOLVING-method_call: State=%p Op=%p named_obj=%p\n",
  905. walk_state, op, node));
  906. /*
  907. * Lookup the method name and save the Node
  908. */
  909. status =
  910. acpi_ns_lookup(walk_state->scope_info,
  911. arg->common.value.string, ACPI_TYPE_ANY,
  912. ACPI_IMODE_LOAD_PASS2,
  913. ACPI_NS_SEARCH_PARENT |
  914. ACPI_NS_DONT_OPEN_SCOPE, walk_state,
  915. &(new_node));
  916. if (ACPI_SUCCESS(status)) {
  917. /*
  918. * Make sure that what we found is indeed a method
  919. * We didn't search for a method on purpose, to see if the name
  920. * would resolve
  921. */
  922. if (new_node->type != ACPI_TYPE_METHOD) {
  923. status = AE_AML_OPERAND_TYPE;
  924. }
  925. /* We could put the returned object (Node) on the object stack for
  926. * later, but for now, we will put it in the "op" object that the
  927. * parser uses, so we can get it again at the end of this scope
  928. */
  929. op->common.node = new_node;
  930. } else {
  931. ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
  932. }
  933. break;
  934. default:
  935. break;
  936. }
  937. cleanup:
  938. /* Remove the Node pushed at the very beginning */
  939. walk_state->operands[0] = NULL;
  940. walk_state->num_operands = 0;
  941. return_ACPI_STATUS(status);
  942. }