dswload.c 30 KB

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