dswload.c 30 KB

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