dswload.c 15 KB

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