dswload.c 30 KB

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