dswload.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. /******************************************************************************
  2. *
  3. * Module Name: dswload - Dispatcher namespace load callbacks
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, Intel Corp.
  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 "accommon.h"
  44. #include "acparser.h"
  45. #include "amlcode.h"
  46. #include "acdispat.h"
  47. #include "acinterp.h"
  48. #include "acnamesp.h"
  49. #include "acevents.h"
  50. #ifdef ACPI_ASL_COMPILER
  51. #include <acpi/acdisasm.h>
  52. #endif
  53. #define _COMPONENT ACPI_DISPATCHER
  54. ACPI_MODULE_NAME("dswload")
  55. /*******************************************************************************
  56. *
  57. * FUNCTION: acpi_ds_init_callbacks
  58. *
  59. * PARAMETERS: walk_state - Current state of the parse tree walk
  60. * pass_number - 1, 2, or 3
  61. *
  62. * RETURN: Status
  63. *
  64. * DESCRIPTION: Init walk state callbacks
  65. *
  66. ******************************************************************************/
  67. acpi_status
  68. acpi_ds_init_callbacks(struct acpi_walk_state *walk_state, u32 pass_number)
  69. {
  70. switch (pass_number) {
  71. case 1:
  72. walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 |
  73. ACPI_PARSE_DELETE_TREE;
  74. walk_state->descending_callback = acpi_ds_load1_begin_op;
  75. walk_state->ascending_callback = acpi_ds_load1_end_op;
  76. break;
  77. case 2:
  78. walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 |
  79. ACPI_PARSE_DELETE_TREE;
  80. walk_state->descending_callback = acpi_ds_load2_begin_op;
  81. walk_state->ascending_callback = acpi_ds_load2_end_op;
  82. break;
  83. case 3:
  84. #ifndef ACPI_NO_METHOD_EXECUTION
  85. walk_state->parse_flags |= ACPI_PARSE_EXECUTE |
  86. ACPI_PARSE_DELETE_TREE;
  87. walk_state->descending_callback = acpi_ds_exec_begin_op;
  88. walk_state->ascending_callback = acpi_ds_exec_end_op;
  89. #endif
  90. break;
  91. default:
  92. return (AE_BAD_PARAMETER);
  93. }
  94. return (AE_OK);
  95. }
  96. /*******************************************************************************
  97. *
  98. * FUNCTION: acpi_ds_load1_begin_op
  99. *
  100. * PARAMETERS: walk_state - Current state of the parse tree walk
  101. * out_op - Where to return op if a new one is created
  102. *
  103. * RETURN: Status
  104. *
  105. * DESCRIPTION: Descending callback used during the loading of ACPI tables.
  106. *
  107. ******************************************************************************/
  108. acpi_status
  109. acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state,
  110. union acpi_parse_object ** out_op)
  111. {
  112. union acpi_parse_object *op;
  113. struct acpi_namespace_node *node;
  114. acpi_status status;
  115. acpi_object_type object_type;
  116. char *path;
  117. u32 flags;
  118. ACPI_FUNCTION_TRACE(ds_load1_begin_op);
  119. op = walk_state->op;
  120. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op,
  121. walk_state));
  122. /* We are only interested in opcodes that have an associated name */
  123. if (op) {
  124. if (!(walk_state->op_info->flags & AML_NAMED)) {
  125. *out_op = op;
  126. return_ACPI_STATUS(AE_OK);
  127. }
  128. /* Check if this object has already been installed in the namespace */
  129. if (op->common.node) {
  130. *out_op = op;
  131. return_ACPI_STATUS(AE_OK);
  132. }
  133. }
  134. path = acpi_ps_get_next_namestring(&walk_state->parser_state);
  135. /* Map the raw opcode into an internal object type */
  136. object_type = walk_state->op_info->object_type;
  137. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  138. "State=%p Op=%p [%s]\n", walk_state, op,
  139. 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 =
  148. acpi_ns_lookup(walk_state->scope_info, path, object_type,
  149. ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
  150. walk_state, &(node));
  151. #ifdef ACPI_ASL_COMPILER
  152. if (status == AE_NOT_FOUND) {
  153. /*
  154. * Table disassembly:
  155. * Target of Scope() not found. Generate an External for it, and
  156. * insert the name into the namespace.
  157. */
  158. acpi_dm_add_to_external_list(path, ACPI_TYPE_DEVICE, 0);
  159. status =
  160. acpi_ns_lookup(walk_state->scope_info, path,
  161. object_type, ACPI_IMODE_LOAD_PASS1,
  162. ACPI_NS_SEARCH_PARENT, walk_state,
  163. &node);
  164. }
  165. #endif
  166. if (ACPI_FAILURE(status)) {
  167. ACPI_ERROR_NAMESPACE(path, status);
  168. return_ACPI_STATUS(status);
  169. }
  170. /*
  171. * Check to make sure that the target is
  172. * one of the opcodes that actually opens a scope
  173. */
  174. switch (node->type) {
  175. case ACPI_TYPE_ANY:
  176. case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
  177. case ACPI_TYPE_DEVICE:
  178. case ACPI_TYPE_POWER:
  179. case ACPI_TYPE_PROCESSOR:
  180. case ACPI_TYPE_THERMAL:
  181. /* These are acceptable types */
  182. break;
  183. case ACPI_TYPE_INTEGER:
  184. case ACPI_TYPE_STRING:
  185. case ACPI_TYPE_BUFFER:
  186. /*
  187. * These types we will allow, but we will change the type.
  188. * This enables some existing code of the form:
  189. *
  190. * Name (DEB, 0)
  191. * Scope (DEB) { ... }
  192. *
  193. * Note: silently change the type here. On the second pass,
  194. * we will report a warning
  195. */
  196. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  197. "Type override - [%4.4s] had invalid type (%s) "
  198. "for Scope operator, changed to type ANY\n",
  199. acpi_ut_get_node_name(node),
  200. acpi_ut_get_type_name(node->type)));
  201. node->type = ACPI_TYPE_ANY;
  202. walk_state->scope_info->common.value = ACPI_TYPE_ANY;
  203. break;
  204. default:
  205. /* All other types are an error */
  206. ACPI_ERROR((AE_INFO,
  207. "Invalid type (%s) for target of "
  208. "Scope operator [%4.4s] (Cannot override)",
  209. acpi_ut_get_type_name(node->type),
  210. acpi_ut_get_node_name(node)));
  211. return_ACPI_STATUS(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. /*
  238. * If we are executing a method, do not create any namespace objects
  239. * during the load phase, only during execution.
  240. */
  241. if (walk_state->method_node) {
  242. node = NULL;
  243. status = AE_OK;
  244. break;
  245. }
  246. flags = ACPI_NS_NO_UPSEARCH;
  247. if ((walk_state->opcode != AML_SCOPE_OP) &&
  248. (!(walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP))) {
  249. flags |= ACPI_NS_ERROR_IF_FOUND;
  250. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  251. "[%s] Cannot already exist\n",
  252. acpi_ut_get_type_name(object_type)));
  253. } else {
  254. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  255. "[%s] Both Find or Create allowed\n",
  256. acpi_ut_get_type_name(object_type)));
  257. }
  258. /*
  259. * Enter the named type into the internal namespace. We enter the name
  260. * as we go downward in the parse tree. Any necessary subobjects that
  261. * involve arguments to the opcode must be created as we go back up the
  262. * parse tree later.
  263. */
  264. status =
  265. acpi_ns_lookup(walk_state->scope_info, path, object_type,
  266. ACPI_IMODE_LOAD_PASS1, flags, walk_state,
  267. &node);
  268. if (ACPI_FAILURE(status)) {
  269. if (status == AE_ALREADY_EXISTS) {
  270. /* The name already exists in this scope */
  271. if (node->flags & ANOBJ_IS_EXTERNAL) {
  272. /*
  273. * Allow one create on an object or segment that was
  274. * previously declared External
  275. */
  276. node->flags &= ~ANOBJ_IS_EXTERNAL;
  277. node->type = (u8) object_type;
  278. /* Just retyped a node, probably will need to open a scope */
  279. if (acpi_ns_opens_scope(object_type)) {
  280. status =
  281. acpi_ds_scope_stack_push
  282. (node, object_type,
  283. walk_state);
  284. if (ACPI_FAILURE(status)) {
  285. return_ACPI_STATUS
  286. (status);
  287. }
  288. }
  289. status = AE_OK;
  290. }
  291. }
  292. if (ACPI_FAILURE(status)) {
  293. ACPI_ERROR_NAMESPACE(path, status);
  294. return_ACPI_STATUS(status);
  295. }
  296. }
  297. break;
  298. }
  299. /* Common exit */
  300. if (!op) {
  301. /* Create a new op */
  302. op = acpi_ps_alloc_op(walk_state->opcode);
  303. if (!op) {
  304. return_ACPI_STATUS(AE_NO_MEMORY);
  305. }
  306. }
  307. /* Initialize the op */
  308. #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
  309. op->named.path = ACPI_CAST_PTR(u8, path);
  310. #endif
  311. if (node) {
  312. /*
  313. * Put the Node in the "op" object that the parser uses, so we
  314. * can get it again quickly when this scope is closed
  315. */
  316. op->common.node = node;
  317. op->named.name = node->name.integer;
  318. }
  319. acpi_ps_append_arg(acpi_ps_get_parent_scope(&walk_state->parser_state),
  320. op);
  321. *out_op = op;
  322. return_ACPI_STATUS(status);
  323. }
  324. /*******************************************************************************
  325. *
  326. * FUNCTION: acpi_ds_load1_end_op
  327. *
  328. * PARAMETERS: walk_state - Current state of the parse tree walk
  329. *
  330. * RETURN: Status
  331. *
  332. * DESCRIPTION: Ascending callback used during the loading of the namespace,
  333. * both control methods and everything else.
  334. *
  335. ******************************************************************************/
  336. acpi_status acpi_ds_load1_end_op(struct acpi_walk_state *walk_state)
  337. {
  338. union acpi_parse_object *op;
  339. acpi_object_type object_type;
  340. acpi_status status = AE_OK;
  341. ACPI_FUNCTION_TRACE(ds_load1_end_op);
  342. op = walk_state->op;
  343. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op,
  344. walk_state));
  345. /* We are only interested in opcodes that have an associated name */
  346. if (!(walk_state->op_info->flags & (AML_NAMED | AML_FIELD))) {
  347. return_ACPI_STATUS(AE_OK);
  348. }
  349. /* Get the object type to determine if we should pop the scope */
  350. object_type = walk_state->op_info->object_type;
  351. #ifndef ACPI_NO_METHOD_EXECUTION
  352. if (walk_state->op_info->flags & AML_FIELD) {
  353. /*
  354. * If we are executing a method, do not create any namespace objects
  355. * during the load phase, only during execution.
  356. */
  357. if (!walk_state->method_node) {
  358. if (walk_state->opcode == AML_FIELD_OP ||
  359. walk_state->opcode == AML_BANK_FIELD_OP ||
  360. walk_state->opcode == AML_INDEX_FIELD_OP) {
  361. status =
  362. acpi_ds_init_field_objects(op, walk_state);
  363. }
  364. }
  365. return_ACPI_STATUS(status);
  366. }
  367. /*
  368. * If we are executing a method, do not create any namespace objects
  369. * during the load phase, only during execution.
  370. */
  371. if (!walk_state->method_node) {
  372. if (op->common.aml_opcode == AML_REGION_OP) {
  373. status =
  374. acpi_ex_create_region(op->named.data,
  375. op->named.length,
  376. (acpi_adr_space_type) ((op->
  377. common.
  378. value.
  379. arg)->
  380. common.
  381. value.
  382. integer),
  383. walk_state);
  384. if (ACPI_FAILURE(status)) {
  385. return_ACPI_STATUS(status);
  386. }
  387. } else if (op->common.aml_opcode == AML_DATA_REGION_OP) {
  388. status =
  389. acpi_ex_create_region(op->named.data,
  390. op->named.length,
  391. REGION_DATA_TABLE,
  392. walk_state);
  393. if (ACPI_FAILURE(status)) {
  394. return_ACPI_STATUS(status);
  395. }
  396. }
  397. }
  398. #endif
  399. if (op->common.aml_opcode == AML_NAME_OP) {
  400. /* For Name opcode, get the object type from the argument */
  401. if (op->common.value.arg) {
  402. object_type = (acpi_ps_get_opcode_info((op->common.
  403. value.arg)->
  404. common.
  405. aml_opcode))->
  406. object_type;
  407. /* Set node type if we have a namespace node */
  408. if (op->common.node) {
  409. op->common.node->type = (u8) object_type;
  410. }
  411. }
  412. }
  413. /*
  414. * If we are executing a method, do not create any namespace objects
  415. * during the load phase, only during execution.
  416. */
  417. if (!walk_state->method_node) {
  418. if (op->common.aml_opcode == AML_METHOD_OP) {
  419. /*
  420. * method_op pkg_length name_string method_flags term_list
  421. *
  422. * Note: We must create the method node/object pair as soon as we
  423. * see the method declaration. This allows later pass1 parsing
  424. * of invocations of the method (need to know the number of
  425. * arguments.)
  426. */
  427. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  428. "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
  429. walk_state, op, op->named.node));
  430. if (!acpi_ns_get_attached_object(op->named.node)) {
  431. walk_state->operands[0] =
  432. ACPI_CAST_PTR(void, op->named.node);
  433. walk_state->num_operands = 1;
  434. status =
  435. acpi_ds_create_operands(walk_state,
  436. op->common.value.
  437. arg);
  438. if (ACPI_SUCCESS(status)) {
  439. status =
  440. acpi_ex_create_method(op->named.
  441. data,
  442. op->named.
  443. length,
  444. walk_state);
  445. }
  446. walk_state->operands[0] = NULL;
  447. walk_state->num_operands = 0;
  448. if (ACPI_FAILURE(status)) {
  449. return_ACPI_STATUS(status);
  450. }
  451. }
  452. }
  453. }
  454. /* Pop the scope stack (only if loading a table) */
  455. if (!walk_state->method_node && acpi_ns_opens_scope(object_type)) {
  456. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  457. "(%s): Popping scope for Op %p\n",
  458. acpi_ut_get_type_name(object_type), op));
  459. status = acpi_ds_scope_stack_pop(walk_state);
  460. }
  461. return_ACPI_STATUS(status);
  462. }
  463. /*******************************************************************************
  464. *
  465. * FUNCTION: acpi_ds_load2_begin_op
  466. *
  467. * PARAMETERS: walk_state - Current state of the parse tree walk
  468. * out_op - Wher to return op if a new one is created
  469. *
  470. * RETURN: Status
  471. *
  472. * DESCRIPTION: Descending callback used during the loading of ACPI tables.
  473. *
  474. ******************************************************************************/
  475. acpi_status
  476. acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
  477. union acpi_parse_object **out_op)
  478. {
  479. union acpi_parse_object *op;
  480. struct acpi_namespace_node *node;
  481. acpi_status status;
  482. acpi_object_type object_type;
  483. char *buffer_ptr;
  484. u32 flags;
  485. ACPI_FUNCTION_TRACE(ds_load2_begin_op);
  486. op = walk_state->op;
  487. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op,
  488. walk_state));
  489. if (op) {
  490. if ((walk_state->control_state) &&
  491. (walk_state->control_state->common.state ==
  492. ACPI_CONTROL_CONDITIONAL_EXECUTING)) {
  493. /* We are executing a while loop outside of a method */
  494. status = acpi_ds_exec_begin_op(walk_state, out_op);
  495. return_ACPI_STATUS(status);
  496. }
  497. /* We only care about Namespace opcodes here */
  498. if ((!(walk_state->op_info->flags & AML_NSOPCODE) &&
  499. (walk_state->opcode != AML_INT_NAMEPATH_OP)) ||
  500. (!(walk_state->op_info->flags & AML_NAMED))) {
  501. return_ACPI_STATUS(AE_OK);
  502. }
  503. /* Get the name we are going to enter or lookup in the namespace */
  504. if (walk_state->opcode == AML_INT_NAMEPATH_OP) {
  505. /* For Namepath op, get the path string */
  506. buffer_ptr = op->common.value.string;
  507. if (!buffer_ptr) {
  508. /* No name, just exit */
  509. return_ACPI_STATUS(AE_OK);
  510. }
  511. } else {
  512. /* Get name from the op */
  513. buffer_ptr = ACPI_CAST_PTR(char, &op->named.name);
  514. }
  515. } else {
  516. /* Get the namestring from the raw AML */
  517. buffer_ptr =
  518. acpi_ps_get_next_namestring(&walk_state->parser_state);
  519. }
  520. /* Map the opcode into an internal object type */
  521. object_type = walk_state->op_info->object_type;
  522. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  523. "State=%p Op=%p Type=%X\n", walk_state, op,
  524. object_type));
  525. switch (walk_state->opcode) {
  526. case AML_FIELD_OP:
  527. case AML_BANK_FIELD_OP:
  528. case AML_INDEX_FIELD_OP:
  529. node = NULL;
  530. status = AE_OK;
  531. break;
  532. case AML_INT_NAMEPATH_OP:
  533. /*
  534. * The name_path is an object reference to an existing object.
  535. * Don't enter the name into the namespace, but look it up
  536. * for use later.
  537. */
  538. status =
  539. acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
  540. object_type, ACPI_IMODE_EXECUTE,
  541. ACPI_NS_SEARCH_PARENT, walk_state, &(node));
  542. break;
  543. case AML_SCOPE_OP:
  544. /* Special case for Scope(\) -> refers to the Root node */
  545. if (op && (op->named.node == acpi_gbl_root_node)) {
  546. node = op->named.node;
  547. status =
  548. acpi_ds_scope_stack_push(node, object_type,
  549. walk_state);
  550. if (ACPI_FAILURE(status)) {
  551. return_ACPI_STATUS(status);
  552. }
  553. } else {
  554. /*
  555. * The Path is an object reference to an existing object.
  556. * Don't enter the name into the namespace, but look it up
  557. * for use later.
  558. */
  559. status =
  560. acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
  561. object_type, ACPI_IMODE_EXECUTE,
  562. ACPI_NS_SEARCH_PARENT, walk_state,
  563. &(node));
  564. if (ACPI_FAILURE(status)) {
  565. #ifdef ACPI_ASL_COMPILER
  566. if (status == AE_NOT_FOUND) {
  567. status = AE_OK;
  568. } else {
  569. ACPI_ERROR_NAMESPACE(buffer_ptr,
  570. status);
  571. }
  572. #else
  573. ACPI_ERROR_NAMESPACE(buffer_ptr, status);
  574. #endif
  575. return_ACPI_STATUS(status);
  576. }
  577. }
  578. /*
  579. * We must check to make sure that the target is
  580. * one of the opcodes that actually opens a scope
  581. */
  582. switch (node->type) {
  583. case ACPI_TYPE_ANY:
  584. case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
  585. case ACPI_TYPE_DEVICE:
  586. case ACPI_TYPE_POWER:
  587. case ACPI_TYPE_PROCESSOR:
  588. case ACPI_TYPE_THERMAL:
  589. /* These are acceptable types */
  590. break;
  591. case ACPI_TYPE_INTEGER:
  592. case ACPI_TYPE_STRING:
  593. case ACPI_TYPE_BUFFER:
  594. /*
  595. * These types we will allow, but we will change the type. This
  596. * enables some existing code of the form:
  597. *
  598. * Name (DEB, 0)
  599. * Scope (DEB) { ... }
  600. */
  601. ACPI_WARNING((AE_INFO,
  602. "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)",
  603. buffer_ptr,
  604. acpi_ut_get_type_name(node->type)));
  605. node->type = ACPI_TYPE_ANY;
  606. walk_state->scope_info->common.value = ACPI_TYPE_ANY;
  607. break;
  608. default:
  609. /* All other types are an error */
  610. ACPI_ERROR((AE_INFO,
  611. "Invalid type (%s) for target of Scope operator [%4.4s]",
  612. acpi_ut_get_type_name(node->type),
  613. buffer_ptr));
  614. return (AE_AML_OPERAND_TYPE);
  615. }
  616. break;
  617. default:
  618. /* All other opcodes */
  619. if (op && op->common.node) {
  620. /* This op/node was previously entered into the namespace */
  621. node = op->common.node;
  622. if (acpi_ns_opens_scope(object_type)) {
  623. status =
  624. acpi_ds_scope_stack_push(node, object_type,
  625. walk_state);
  626. if (ACPI_FAILURE(status)) {
  627. return_ACPI_STATUS(status);
  628. }
  629. }
  630. return_ACPI_STATUS(AE_OK);
  631. }
  632. /*
  633. * Enter the named type into the internal namespace. We enter the name
  634. * as we go downward in the parse tree. Any necessary subobjects that
  635. * involve arguments to the opcode must be created as we go back up the
  636. * parse tree later.
  637. *
  638. * Note: Name may already exist if we are executing a deferred opcode.
  639. */
  640. if (walk_state->deferred_node) {
  641. /* This name is already in the namespace, get the node */
  642. node = walk_state->deferred_node;
  643. status = AE_OK;
  644. break;
  645. }
  646. flags = ACPI_NS_NO_UPSEARCH;
  647. if (walk_state->pass_number == ACPI_IMODE_EXECUTE) {
  648. /* Execution mode, node cannot already exist, node is temporary */
  649. flags |= ACPI_NS_ERROR_IF_FOUND;
  650. if (!
  651. (walk_state->
  652. parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
  653. flags |= ACPI_NS_TEMPORARY;
  654. }
  655. }
  656. /* Add new entry or lookup existing entry */
  657. status =
  658. acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
  659. object_type, ACPI_IMODE_LOAD_PASS2, flags,
  660. walk_state, &node);
  661. if (ACPI_SUCCESS(status) && (flags & ACPI_NS_TEMPORARY)) {
  662. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  663. "***New Node [%4.4s] %p is temporary\n",
  664. acpi_ut_get_node_name(node), node));
  665. }
  666. break;
  667. }
  668. if (ACPI_FAILURE(status)) {
  669. ACPI_ERROR_NAMESPACE(buffer_ptr, status);
  670. return_ACPI_STATUS(status);
  671. }
  672. if (!op) {
  673. /* Create a new op */
  674. op = acpi_ps_alloc_op(walk_state->opcode);
  675. if (!op) {
  676. return_ACPI_STATUS(AE_NO_MEMORY);
  677. }
  678. /* Initialize the new op */
  679. if (node) {
  680. op->named.name = node->name.integer;
  681. }
  682. *out_op = op;
  683. }
  684. /*
  685. * Put the Node in the "op" object that the parser uses, so we
  686. * can get it again quickly when this scope is closed
  687. */
  688. op->common.node = node;
  689. return_ACPI_STATUS(status);
  690. }
  691. /*******************************************************************************
  692. *
  693. * FUNCTION: acpi_ds_load2_end_op
  694. *
  695. * PARAMETERS: walk_state - Current state of the parse tree walk
  696. *
  697. * RETURN: Status
  698. *
  699. * DESCRIPTION: Ascending callback used during the loading of the namespace,
  700. * both control methods and everything else.
  701. *
  702. ******************************************************************************/
  703. acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
  704. {
  705. union acpi_parse_object *op;
  706. acpi_status status = AE_OK;
  707. acpi_object_type object_type;
  708. struct acpi_namespace_node *node;
  709. union acpi_parse_object *arg;
  710. struct acpi_namespace_node *new_node;
  711. #ifndef ACPI_NO_METHOD_EXECUTION
  712. u32 i;
  713. u8 region_space;
  714. #endif
  715. ACPI_FUNCTION_TRACE(ds_load2_end_op);
  716. op = walk_state->op;
  717. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
  718. walk_state->op_info->name, op, walk_state));
  719. /* Check if opcode had an associated namespace object */
  720. if (!(walk_state->op_info->flags & AML_NSOBJECT)) {
  721. return_ACPI_STATUS(AE_OK);
  722. }
  723. if (op->common.aml_opcode == AML_SCOPE_OP) {
  724. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  725. "Ending scope Op=%p State=%p\n", op,
  726. walk_state));
  727. }
  728. object_type = walk_state->op_info->object_type;
  729. /*
  730. * Get the Node/name from the earlier lookup
  731. * (It was saved in the *op structure)
  732. */
  733. node = op->common.node;
  734. /*
  735. * Put the Node on the object stack (Contains the ACPI Name of
  736. * this object)
  737. */
  738. walk_state->operands[0] = (void *)node;
  739. walk_state->num_operands = 1;
  740. /* Pop the scope stack */
  741. if (acpi_ns_opens_scope(object_type) &&
  742. (op->common.aml_opcode != AML_INT_METHODCALL_OP)) {
  743. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  744. "(%s) Popping scope for Op %p\n",
  745. acpi_ut_get_type_name(object_type), op));
  746. status = acpi_ds_scope_stack_pop(walk_state);
  747. if (ACPI_FAILURE(status)) {
  748. goto cleanup;
  749. }
  750. }
  751. /*
  752. * Named operations are as follows:
  753. *
  754. * AML_ALIAS
  755. * AML_BANKFIELD
  756. * AML_CREATEBITFIELD
  757. * AML_CREATEBYTEFIELD
  758. * AML_CREATEDWORDFIELD
  759. * AML_CREATEFIELD
  760. * AML_CREATEQWORDFIELD
  761. * AML_CREATEWORDFIELD
  762. * AML_DATA_REGION
  763. * AML_DEVICE
  764. * AML_EVENT
  765. * AML_FIELD
  766. * AML_INDEXFIELD
  767. * AML_METHOD
  768. * AML_METHODCALL
  769. * AML_MUTEX
  770. * AML_NAME
  771. * AML_NAMEDFIELD
  772. * AML_OPREGION
  773. * AML_POWERRES
  774. * AML_PROCESSOR
  775. * AML_SCOPE
  776. * AML_THERMALZONE
  777. */
  778. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  779. "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
  780. acpi_ps_get_opcode_name(op->common.aml_opcode),
  781. walk_state, op, node));
  782. /* Decode the opcode */
  783. arg = op->common.value.arg;
  784. switch (walk_state->op_info->type) {
  785. #ifndef ACPI_NO_METHOD_EXECUTION
  786. case AML_TYPE_CREATE_FIELD:
  787. /*
  788. * Create the field object, but the field buffer and index must
  789. * be evaluated later during the execution phase
  790. */
  791. status = acpi_ds_create_buffer_field(op, walk_state);
  792. break;
  793. case AML_TYPE_NAMED_FIELD:
  794. /*
  795. * If we are executing a method, initialize the field
  796. */
  797. if (walk_state->method_node) {
  798. status = acpi_ds_init_field_objects(op, walk_state);
  799. }
  800. switch (op->common.aml_opcode) {
  801. case AML_INDEX_FIELD_OP:
  802. status =
  803. acpi_ds_create_index_field(op,
  804. (acpi_handle) arg->
  805. common.node, walk_state);
  806. break;
  807. case AML_BANK_FIELD_OP:
  808. status =
  809. acpi_ds_create_bank_field(op, arg->common.node,
  810. walk_state);
  811. break;
  812. case AML_FIELD_OP:
  813. status =
  814. acpi_ds_create_field(op, arg->common.node,
  815. walk_state);
  816. break;
  817. default:
  818. /* All NAMED_FIELD opcodes must be handled above */
  819. break;
  820. }
  821. break;
  822. case AML_TYPE_NAMED_SIMPLE:
  823. status = acpi_ds_create_operands(walk_state, arg);
  824. if (ACPI_FAILURE(status)) {
  825. goto cleanup;
  826. }
  827. switch (op->common.aml_opcode) {
  828. case AML_PROCESSOR_OP:
  829. status = acpi_ex_create_processor(walk_state);
  830. break;
  831. case AML_POWER_RES_OP:
  832. status = acpi_ex_create_power_resource(walk_state);
  833. break;
  834. case AML_MUTEX_OP:
  835. status = acpi_ex_create_mutex(walk_state);
  836. break;
  837. case AML_EVENT_OP:
  838. status = acpi_ex_create_event(walk_state);
  839. break;
  840. case AML_ALIAS_OP:
  841. status = acpi_ex_create_alias(walk_state);
  842. break;
  843. default:
  844. /* Unknown opcode */
  845. status = AE_OK;
  846. goto cleanup;
  847. }
  848. /* Delete operands */
  849. for (i = 1; i < walk_state->num_operands; i++) {
  850. acpi_ut_remove_reference(walk_state->operands[i]);
  851. walk_state->operands[i] = NULL;
  852. }
  853. break;
  854. #endif /* ACPI_NO_METHOD_EXECUTION */
  855. case AML_TYPE_NAMED_COMPLEX:
  856. switch (op->common.aml_opcode) {
  857. #ifndef ACPI_NO_METHOD_EXECUTION
  858. case AML_REGION_OP:
  859. case AML_DATA_REGION_OP:
  860. if (op->common.aml_opcode == AML_REGION_OP) {
  861. region_space = (acpi_adr_space_type)
  862. ((op->common.value.arg)->common.value.
  863. integer);
  864. } else {
  865. region_space = REGION_DATA_TABLE;
  866. }
  867. /*
  868. * If we are executing a method, initialize the region
  869. */
  870. if (walk_state->method_node) {
  871. status =
  872. acpi_ex_create_region(op->named.data,
  873. op->named.length,
  874. region_space,
  875. walk_state);
  876. if (ACPI_FAILURE(status)) {
  877. return (status);
  878. }
  879. }
  880. /*
  881. * The op_region is not fully parsed at this time. Only valid
  882. * argument is the space_id. (We must save the address of the
  883. * AML of the address and length operands)
  884. */
  885. /*
  886. * If we have a valid region, initialize it
  887. * Namespace is NOT locked at this point.
  888. */
  889. status =
  890. acpi_ev_initialize_region
  891. (acpi_ns_get_attached_object(node), FALSE);
  892. if (ACPI_FAILURE(status)) {
  893. /*
  894. * If AE_NOT_EXIST is returned, it is not fatal
  895. * because many regions get created before a handler
  896. * is installed for said region.
  897. */
  898. if (AE_NOT_EXIST == status) {
  899. status = AE_OK;
  900. }
  901. }
  902. break;
  903. case AML_NAME_OP:
  904. status = acpi_ds_create_node(walk_state, node, op);
  905. break;
  906. case AML_METHOD_OP:
  907. /*
  908. * method_op pkg_length name_string method_flags term_list
  909. *
  910. * Note: We must create the method node/object pair as soon as we
  911. * see the method declaration. This allows later pass1 parsing
  912. * of invocations of the method (need to know the number of
  913. * arguments.)
  914. */
  915. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  916. "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
  917. walk_state, op, op->named.node));
  918. if (!acpi_ns_get_attached_object(op->named.node)) {
  919. walk_state->operands[0] =
  920. ACPI_CAST_PTR(void, op->named.node);
  921. walk_state->num_operands = 1;
  922. status =
  923. acpi_ds_create_operands(walk_state,
  924. op->common.value.
  925. arg);
  926. if (ACPI_SUCCESS(status)) {
  927. status =
  928. acpi_ex_create_method(op->named.
  929. data,
  930. op->named.
  931. length,
  932. walk_state);
  933. }
  934. walk_state->operands[0] = NULL;
  935. walk_state->num_operands = 0;
  936. if (ACPI_FAILURE(status)) {
  937. return_ACPI_STATUS(status);
  938. }
  939. }
  940. break;
  941. #endif /* ACPI_NO_METHOD_EXECUTION */
  942. default:
  943. /* All NAMED_COMPLEX opcodes must be handled above */
  944. break;
  945. }
  946. break;
  947. case AML_CLASS_INTERNAL:
  948. /* case AML_INT_NAMEPATH_OP: */
  949. break;
  950. case AML_CLASS_METHOD_CALL:
  951. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  952. "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
  953. walk_state, op, node));
  954. /*
  955. * Lookup the method name and save the Node
  956. */
  957. status =
  958. acpi_ns_lookup(walk_state->scope_info,
  959. arg->common.value.string, ACPI_TYPE_ANY,
  960. ACPI_IMODE_LOAD_PASS2,
  961. ACPI_NS_SEARCH_PARENT |
  962. ACPI_NS_DONT_OPEN_SCOPE, walk_state,
  963. &(new_node));
  964. if (ACPI_SUCCESS(status)) {
  965. /*
  966. * Make sure that what we found is indeed a method
  967. * We didn't search for a method on purpose, to see if the name
  968. * would resolve
  969. */
  970. if (new_node->type != ACPI_TYPE_METHOD) {
  971. status = AE_AML_OPERAND_TYPE;
  972. }
  973. /* We could put the returned object (Node) on the object stack for
  974. * later, but for now, we will put it in the "op" object that the
  975. * parser uses, so we can get it again at the end of this scope
  976. */
  977. op->common.node = new_node;
  978. } else {
  979. ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
  980. }
  981. break;
  982. default:
  983. break;
  984. }
  985. cleanup:
  986. /* Remove the Node pushed at the very beginning */
  987. walk_state->operands[0] = NULL;
  988. walk_state->num_operands = 0;
  989. return_ACPI_STATUS(status);
  990. }