dswload.c 29 KB

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