dswload.c 30 KB

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