dswload.c 30 KB

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