dswload.c 30 KB

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