dswload.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /******************************************************************************
  2. *
  3. * Module Name: dswload - Dispatcher first pass namespace load callbacks
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, 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. #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.
  187. * This 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,
  193. * we will report a warning
  194. */
  195. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  196. "Type override - [%4.4s] had invalid type (%s) "
  197. "for Scope operator, changed to type ANY\n",
  198. acpi_ut_get_node_name(node),
  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. case ACPI_TYPE_METHOD:
  204. /*
  205. * Allow scope change to root during execution of module-level
  206. * code. Root is typed METHOD during this time.
  207. */
  208. if ((node == acpi_gbl_root_node) &&
  209. (walk_state->
  210. parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
  211. break;
  212. }
  213. /*lint -fallthrough */
  214. default:
  215. /* All other types are an error */
  216. ACPI_ERROR((AE_INFO,
  217. "Invalid type (%s) for target of "
  218. "Scope operator [%4.4s] (Cannot override)",
  219. acpi_ut_get_type_name(node->type),
  220. acpi_ut_get_node_name(node)));
  221. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  222. }
  223. break;
  224. default:
  225. /*
  226. * For all other named opcodes, we will enter the name into
  227. * the namespace.
  228. *
  229. * Setup the search flags.
  230. * Since we are entering a name into the namespace, we do not want to
  231. * enable the search-to-root upsearch.
  232. *
  233. * There are only two conditions where it is acceptable that the name
  234. * already exists:
  235. * 1) the Scope() operator can reopen a scoping object that was
  236. * previously defined (Scope, Method, Device, etc.)
  237. * 2) Whenever we are parsing a deferred opcode (op_region, Buffer,
  238. * buffer_field, or Package), the name of the object is already
  239. * in the namespace.
  240. */
  241. if (walk_state->deferred_node) {
  242. /* This name is already in the namespace, get the node */
  243. node = walk_state->deferred_node;
  244. status = AE_OK;
  245. break;
  246. }
  247. /*
  248. * If we are executing a method, do not create any namespace objects
  249. * during the load phase, only during execution.
  250. */
  251. if (walk_state->method_node) {
  252. node = NULL;
  253. status = AE_OK;
  254. break;
  255. }
  256. flags = ACPI_NS_NO_UPSEARCH;
  257. if ((walk_state->opcode != AML_SCOPE_OP) &&
  258. (!(walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP))) {
  259. flags |= ACPI_NS_ERROR_IF_FOUND;
  260. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  261. "[%s] Cannot already exist\n",
  262. acpi_ut_get_type_name(object_type)));
  263. } else {
  264. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  265. "[%s] Both Find or Create allowed\n",
  266. acpi_ut_get_type_name(object_type)));
  267. }
  268. /*
  269. * Enter the named type into the internal namespace. We enter the name
  270. * as we go downward in the parse tree. Any necessary subobjects that
  271. * involve arguments to the opcode must be created as we go back up the
  272. * parse tree later.
  273. */
  274. status =
  275. acpi_ns_lookup(walk_state->scope_info, path, object_type,
  276. ACPI_IMODE_LOAD_PASS1, flags, walk_state,
  277. &node);
  278. if (ACPI_FAILURE(status)) {
  279. if (status == AE_ALREADY_EXISTS) {
  280. /* The name already exists in this scope */
  281. if (node->flags & ANOBJ_IS_EXTERNAL) {
  282. /*
  283. * Allow one create on an object or segment that was
  284. * previously declared External
  285. */
  286. node->flags &= ~ANOBJ_IS_EXTERNAL;
  287. node->type = (u8) object_type;
  288. /* Just retyped a node, probably will need to open a scope */
  289. if (acpi_ns_opens_scope(object_type)) {
  290. status =
  291. acpi_ds_scope_stack_push
  292. (node, object_type,
  293. walk_state);
  294. if (ACPI_FAILURE(status)) {
  295. return_ACPI_STATUS
  296. (status);
  297. }
  298. }
  299. status = AE_OK;
  300. }
  301. }
  302. if (ACPI_FAILURE(status)) {
  303. ACPI_ERROR_NAMESPACE(path, status);
  304. return_ACPI_STATUS(status);
  305. }
  306. }
  307. break;
  308. }
  309. /* Common exit */
  310. if (!op) {
  311. /* Create a new op */
  312. op = acpi_ps_alloc_op(walk_state->opcode);
  313. if (!op) {
  314. return_ACPI_STATUS(AE_NO_MEMORY);
  315. }
  316. }
  317. /* Initialize the op */
  318. #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
  319. op->named.path = ACPI_CAST_PTR(u8, path);
  320. #endif
  321. if (node) {
  322. /*
  323. * Put the Node in the "op" object that the parser uses, so we
  324. * can get it again quickly when this scope is closed
  325. */
  326. op->common.node = node;
  327. op->named.name = node->name.integer;
  328. }
  329. acpi_ps_append_arg(acpi_ps_get_parent_scope(&walk_state->parser_state),
  330. op);
  331. *out_op = op;
  332. return_ACPI_STATUS(status);
  333. }
  334. /*******************************************************************************
  335. *
  336. * FUNCTION: acpi_ds_load1_end_op
  337. *
  338. * PARAMETERS: walk_state - Current state of the parse tree walk
  339. *
  340. * RETURN: Status
  341. *
  342. * DESCRIPTION: Ascending callback used during the loading of the namespace,
  343. * both control methods and everything else.
  344. *
  345. ******************************************************************************/
  346. acpi_status acpi_ds_load1_end_op(struct acpi_walk_state *walk_state)
  347. {
  348. union acpi_parse_object *op;
  349. acpi_object_type object_type;
  350. acpi_status status = AE_OK;
  351. ACPI_FUNCTION_TRACE(ds_load1_end_op);
  352. op = walk_state->op;
  353. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op,
  354. walk_state));
  355. /* We are only interested in opcodes that have an associated name */
  356. if (!(walk_state->op_info->flags & (AML_NAMED | AML_FIELD))) {
  357. return_ACPI_STATUS(AE_OK);
  358. }
  359. /* Get the object type to determine if we should pop the scope */
  360. object_type = walk_state->op_info->object_type;
  361. #ifndef ACPI_NO_METHOD_EXECUTION
  362. if (walk_state->op_info->flags & AML_FIELD) {
  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 (walk_state->opcode == AML_FIELD_OP ||
  369. walk_state->opcode == AML_BANK_FIELD_OP ||
  370. walk_state->opcode == AML_INDEX_FIELD_OP) {
  371. status =
  372. acpi_ds_init_field_objects(op, walk_state);
  373. }
  374. }
  375. return_ACPI_STATUS(status);
  376. }
  377. /*
  378. * If we are executing a method, do not create any namespace objects
  379. * during the load phase, only during execution.
  380. */
  381. if (!walk_state->method_node) {
  382. if (op->common.aml_opcode == AML_REGION_OP) {
  383. status =
  384. acpi_ex_create_region(op->named.data,
  385. op->named.length,
  386. (acpi_adr_space_type) ((op->
  387. common.
  388. value.
  389. arg)->
  390. common.
  391. value.
  392. integer),
  393. walk_state);
  394. if (ACPI_FAILURE(status)) {
  395. return_ACPI_STATUS(status);
  396. }
  397. } else if (op->common.aml_opcode == AML_DATA_REGION_OP) {
  398. status =
  399. acpi_ex_create_region(op->named.data,
  400. op->named.length,
  401. ACPI_ADR_SPACE_DATA_TABLE,
  402. walk_state);
  403. if (ACPI_FAILURE(status)) {
  404. return_ACPI_STATUS(status);
  405. }
  406. }
  407. }
  408. #endif
  409. if (op->common.aml_opcode == AML_NAME_OP) {
  410. /* For Name opcode, get the object type from the argument */
  411. if (op->common.value.arg) {
  412. object_type = (acpi_ps_get_opcode_info((op->common.
  413. value.arg)->
  414. common.
  415. aml_opcode))->
  416. object_type;
  417. /* Set node type if we have a namespace node */
  418. if (op->common.node) {
  419. op->common.node->type = (u8) object_type;
  420. }
  421. }
  422. }
  423. /*
  424. * If we are executing a method, do not create any namespace objects
  425. * during the load phase, only during execution.
  426. */
  427. if (!walk_state->method_node) {
  428. if (op->common.aml_opcode == AML_METHOD_OP) {
  429. /*
  430. * method_op pkg_length name_string method_flags term_list
  431. *
  432. * Note: We must create the method node/object pair as soon as we
  433. * see the method declaration. This allows later pass1 parsing
  434. * of invocations of the method (need to know the number of
  435. * arguments.)
  436. */
  437. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  438. "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
  439. walk_state, op, op->named.node));
  440. if (!acpi_ns_get_attached_object(op->named.node)) {
  441. walk_state->operands[0] =
  442. ACPI_CAST_PTR(void, op->named.node);
  443. walk_state->num_operands = 1;
  444. status =
  445. acpi_ds_create_operands(walk_state,
  446. op->common.value.
  447. arg);
  448. if (ACPI_SUCCESS(status)) {
  449. status =
  450. acpi_ex_create_method(op->named.
  451. data,
  452. op->named.
  453. length,
  454. walk_state);
  455. }
  456. walk_state->operands[0] = NULL;
  457. walk_state->num_operands = 0;
  458. if (ACPI_FAILURE(status)) {
  459. return_ACPI_STATUS(status);
  460. }
  461. }
  462. }
  463. }
  464. /* Pop the scope stack (only if loading a table) */
  465. if (!walk_state->method_node && acpi_ns_opens_scope(object_type)) {
  466. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  467. "(%s): Popping scope for Op %p\n",
  468. acpi_ut_get_type_name(object_type), op));
  469. status = acpi_ds_scope_stack_pop(walk_state);
  470. }
  471. return_ACPI_STATUS(status);
  472. }