dswload.c 30 KB

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