dswload.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  1. /******************************************************************************
  2. *
  3. * Module Name: dswload - Dispatcher namespace load callbacks
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, 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);
  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_REPORT_NSERROR(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_LOCAL_SCOPE: /* Scope */
  175. case ACPI_TYPE_DEVICE:
  176. case ACPI_TYPE_POWER:
  177. case ACPI_TYPE_PROCESSOR:
  178. case ACPI_TYPE_THERMAL:
  179. /* These are acceptable types */
  180. break;
  181. case ACPI_TYPE_INTEGER:
  182. case ACPI_TYPE_STRING:
  183. case ACPI_TYPE_BUFFER:
  184. /*
  185. * These types we will allow, but we will change the type. This
  186. * enables some existing code of the form:
  187. *
  188. * Name (DEB, 0)
  189. * Scope (DEB) { ... }
  190. *
  191. * Note: silently change the type here. On the second pass, we will report
  192. * a warning
  193. */
  194. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  195. "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
  196. path,
  197. acpi_ut_get_type_name(node->type)));
  198. node->type = ACPI_TYPE_ANY;
  199. walk_state->scope_info->common.value = ACPI_TYPE_ANY;
  200. break;
  201. default:
  202. /* All other types are an error */
  203. ACPI_REPORT_ERROR(("Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)\n", acpi_ut_get_type_name(node->type), path));
  204. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  205. }
  206. break;
  207. default:
  208. /*
  209. * For all other named opcodes, we will enter the name into
  210. * the namespace.
  211. *
  212. * Setup the search flags.
  213. * Since we are entering a name into the namespace, we do not want to
  214. * enable the search-to-root upsearch.
  215. *
  216. * There are only two conditions where it is acceptable that the name
  217. * already exists:
  218. * 1) the Scope() operator can reopen a scoping object that was
  219. * previously defined (Scope, Method, Device, etc.)
  220. * 2) Whenever we are parsing a deferred opcode (op_region, Buffer,
  221. * buffer_field, or Package), the name of the object is already
  222. * in the namespace.
  223. */
  224. if (walk_state->deferred_node) {
  225. /* This name is already in the namespace, get the node */
  226. node = walk_state->deferred_node;
  227. status = AE_OK;
  228. break;
  229. }
  230. /*
  231. * If we are executing a method, do not create any namespace objects
  232. * during the load phase, only during execution.
  233. */
  234. if (walk_state->method_node) {
  235. node = NULL;
  236. status = AE_OK;
  237. break;
  238. }
  239. flags = ACPI_NS_NO_UPSEARCH;
  240. if ((walk_state->opcode != AML_SCOPE_OP) &&
  241. (!(walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP))) {
  242. flags |= ACPI_NS_ERROR_IF_FOUND;
  243. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  244. "[%s] Cannot already exist\n",
  245. acpi_ut_get_type_name(object_type)));
  246. } else {
  247. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  248. "[%s] Both Find or Create allowed\n",
  249. acpi_ut_get_type_name(object_type)));
  250. }
  251. /*
  252. * Enter the named type into the internal namespace. We enter the name
  253. * as we go downward in the parse tree. Any necessary subobjects that
  254. * involve arguments to the opcode must be created as we go back up the
  255. * parse tree later.
  256. */
  257. status =
  258. acpi_ns_lookup(walk_state->scope_info, path, object_type,
  259. ACPI_IMODE_LOAD_PASS1, flags, walk_state,
  260. &(node));
  261. if (ACPI_FAILURE(status)) {
  262. ACPI_REPORT_NSERROR(path, status);
  263. return_ACPI_STATUS(status);
  264. }
  265. break;
  266. }
  267. /* Common exit */
  268. if (!op) {
  269. /* Create a new op */
  270. op = acpi_ps_alloc_op(walk_state->opcode);
  271. if (!op) {
  272. return_ACPI_STATUS(AE_NO_MEMORY);
  273. }
  274. }
  275. /* Initialize the op */
  276. #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
  277. op->named.path = ACPI_CAST_PTR(u8, path);
  278. #endif
  279. if (node) {
  280. /*
  281. * Put the Node in the "op" object that the parser uses, so we
  282. * can get it again quickly when this scope is closed
  283. */
  284. op->common.node = node;
  285. op->named.name = node->name.integer;
  286. }
  287. acpi_ps_append_arg(acpi_ps_get_parent_scope(&walk_state->parser_state),
  288. op);
  289. *out_op = op;
  290. return_ACPI_STATUS(status);
  291. }
  292. /*******************************************************************************
  293. *
  294. * FUNCTION: acpi_ds_load1_end_op
  295. *
  296. * PARAMETERS: walk_state - Current state of the parse tree walk
  297. *
  298. * RETURN: Status
  299. *
  300. * DESCRIPTION: Ascending callback used during the loading of the namespace,
  301. * both control methods and everything else.
  302. *
  303. ******************************************************************************/
  304. acpi_status acpi_ds_load1_end_op(struct acpi_walk_state *walk_state)
  305. {
  306. union acpi_parse_object *op;
  307. acpi_object_type object_type;
  308. acpi_status status = AE_OK;
  309. ACPI_FUNCTION_TRACE("ds_load1_end_op");
  310. op = walk_state->op;
  311. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op,
  312. walk_state));
  313. /* We are only interested in opcodes that have an associated name */
  314. if (!(walk_state->op_info->flags & (AML_NAMED | AML_FIELD))) {
  315. return_ACPI_STATUS(AE_OK);
  316. }
  317. /* Get the object type to determine if we should pop the scope */
  318. object_type = walk_state->op_info->object_type;
  319. #ifndef ACPI_NO_METHOD_EXECUTION
  320. if (walk_state->op_info->flags & AML_FIELD) {
  321. /*
  322. * If we are executing a method, do not create any namespace objects
  323. * during the load phase, only during execution.
  324. */
  325. if (!walk_state->method_node) {
  326. if (walk_state->opcode == AML_FIELD_OP ||
  327. walk_state->opcode == AML_BANK_FIELD_OP ||
  328. walk_state->opcode == AML_INDEX_FIELD_OP) {
  329. status =
  330. acpi_ds_init_field_objects(op, walk_state);
  331. }
  332. }
  333. return_ACPI_STATUS(status);
  334. }
  335. /*
  336. * If we are executing a method, do not create any namespace objects
  337. * during the load phase, only during execution.
  338. */
  339. if (!walk_state->method_node) {
  340. if (op->common.aml_opcode == AML_REGION_OP) {
  341. status =
  342. acpi_ex_create_region(op->named.data,
  343. op->named.length,
  344. (acpi_adr_space_type)
  345. ((op->common.value.arg)->
  346. common.value.integer),
  347. walk_state);
  348. if (ACPI_FAILURE(status)) {
  349. return_ACPI_STATUS(status);
  350. }
  351. }
  352. }
  353. #endif
  354. if (op->common.aml_opcode == AML_NAME_OP) {
  355. /* For Name opcode, get the object type from the argument */
  356. if (op->common.value.arg) {
  357. object_type = (acpi_ps_get_opcode_info((op->common.
  358. value.arg)->
  359. common.
  360. aml_opcode))->
  361. object_type;
  362. /* Set node type if we have a namespace node */
  363. if (op->common.node) {
  364. op->common.node->type = (u8) object_type;
  365. }
  366. }
  367. }
  368. /*
  369. * If we are executing a method, do not create any namespace objects
  370. * during the load phase, only during execution.
  371. */
  372. if (!walk_state->method_node) {
  373. if (op->common.aml_opcode == AML_METHOD_OP) {
  374. /*
  375. * method_op pkg_length name_string method_flags term_list
  376. *
  377. * Note: We must create the method node/object pair as soon as we
  378. * see the method declaration. This allows later pass1 parsing
  379. * of invocations of the method (need to know the number of
  380. * arguments.)
  381. */
  382. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  383. "LOADING-Method: State=%p Op=%p named_obj=%p\n",
  384. walk_state, op, op->named.node));
  385. if (!acpi_ns_get_attached_object(op->named.node)) {
  386. walk_state->operands[0] =
  387. ACPI_CAST_PTR(void, op->named.node);
  388. walk_state->num_operands = 1;
  389. status =
  390. acpi_ds_create_operands(walk_state,
  391. op->common.value.
  392. arg);
  393. if (ACPI_SUCCESS(status)) {
  394. status =
  395. acpi_ex_create_method(op->named.
  396. data,
  397. op->named.
  398. length,
  399. walk_state);
  400. }
  401. walk_state->operands[0] = NULL;
  402. walk_state->num_operands = 0;
  403. if (ACPI_FAILURE(status)) {
  404. return_ACPI_STATUS(status);
  405. }
  406. }
  407. }
  408. }
  409. /* Pop the scope stack (only if loading a table) */
  410. if (!walk_state->method_node && acpi_ns_opens_scope(object_type)) {
  411. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  412. "(%s): Popping scope for Op %p\n",
  413. acpi_ut_get_type_name(object_type), op));
  414. status = acpi_ds_scope_stack_pop(walk_state);
  415. }
  416. return_ACPI_STATUS(status);
  417. }
  418. /*******************************************************************************
  419. *
  420. * FUNCTION: acpi_ds_load2_begin_op
  421. *
  422. * PARAMETERS: walk_state - Current state of the parse tree walk
  423. * out_op - Wher to return op if a new one is created
  424. *
  425. * RETURN: Status
  426. *
  427. * DESCRIPTION: Descending callback used during the loading of ACPI tables.
  428. *
  429. ******************************************************************************/
  430. acpi_status
  431. acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
  432. union acpi_parse_object **out_op)
  433. {
  434. union acpi_parse_object *op;
  435. struct acpi_namespace_node *node;
  436. acpi_status status;
  437. acpi_object_type object_type;
  438. char *buffer_ptr;
  439. ACPI_FUNCTION_TRACE("ds_load2_begin_op");
  440. op = walk_state->op;
  441. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p State=%p\n", op,
  442. walk_state));
  443. if (op) {
  444. if ((walk_state->control_state) &&
  445. (walk_state->control_state->common.state ==
  446. ACPI_CONTROL_CONDITIONAL_EXECUTING)) {
  447. /* We are executing a while loop outside of a method */
  448. status = acpi_ds_exec_begin_op(walk_state, out_op);
  449. return_ACPI_STATUS(status);
  450. }
  451. /* We only care about Namespace opcodes here */
  452. if ((!(walk_state->op_info->flags & AML_NSOPCODE) &&
  453. (walk_state->opcode != AML_INT_NAMEPATH_OP)) ||
  454. (!(walk_state->op_info->flags & AML_NAMED))) {
  455. #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
  456. if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
  457. (walk_state->op_info->class == AML_CLASS_CONTROL)) {
  458. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  459. "Begin/EXEC: %s (fl %8.8X)\n",
  460. walk_state->op_info->name,
  461. walk_state->op_info->flags));
  462. /* Executing a type1 or type2 opcode outside of a method */
  463. status =
  464. acpi_ds_exec_begin_op(walk_state, out_op);
  465. return_ACPI_STATUS(status);
  466. }
  467. #endif
  468. return_ACPI_STATUS(AE_OK);
  469. }
  470. /* Get the name we are going to enter or lookup in the namespace */
  471. if (walk_state->opcode == AML_INT_NAMEPATH_OP) {
  472. /* For Namepath op, get the path string */
  473. buffer_ptr = op->common.value.string;
  474. if (!buffer_ptr) {
  475. /* No name, just exit */
  476. return_ACPI_STATUS(AE_OK);
  477. }
  478. } else {
  479. /* Get name from the op */
  480. buffer_ptr = (char *)&op->named.name;
  481. }
  482. } else {
  483. /* Get the namestring from the raw AML */
  484. buffer_ptr =
  485. acpi_ps_get_next_namestring(&walk_state->parser_state);
  486. }
  487. /* Map the opcode into an internal object type */
  488. object_type = walk_state->op_info->object_type;
  489. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  490. "State=%p Op=%p Type=%X\n", walk_state, op,
  491. object_type));
  492. switch (walk_state->opcode) {
  493. case AML_FIELD_OP:
  494. case AML_BANK_FIELD_OP:
  495. case AML_INDEX_FIELD_OP:
  496. node = NULL;
  497. status = AE_OK;
  498. break;
  499. case AML_INT_NAMEPATH_OP:
  500. /*
  501. * The name_path is an object reference to an existing object.
  502. * Don't enter the name into the namespace, but look it up
  503. * for use later.
  504. */
  505. status =
  506. acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
  507. object_type, ACPI_IMODE_EXECUTE,
  508. ACPI_NS_SEARCH_PARENT, walk_state, &(node));
  509. break;
  510. case AML_SCOPE_OP:
  511. /*
  512. * The Path is an object reference to an existing object.
  513. * Don't enter the name into the namespace, but look it up
  514. * for use later.
  515. */
  516. status =
  517. acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
  518. object_type, ACPI_IMODE_EXECUTE,
  519. ACPI_NS_SEARCH_PARENT, walk_state, &(node));
  520. if (ACPI_FAILURE(status)) {
  521. #ifdef ACPI_ASL_COMPILER
  522. if (status == AE_NOT_FOUND) {
  523. status = AE_OK;
  524. } else {
  525. ACPI_REPORT_NSERROR(buffer_ptr, status);
  526. }
  527. #else
  528. ACPI_REPORT_NSERROR(buffer_ptr, status);
  529. #endif
  530. return_ACPI_STATUS(status);
  531. }
  532. /*
  533. * We must check to make sure that the target is
  534. * one of the opcodes that actually opens a scope
  535. */
  536. switch (node->type) {
  537. case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
  538. case ACPI_TYPE_DEVICE:
  539. case ACPI_TYPE_POWER:
  540. case ACPI_TYPE_PROCESSOR:
  541. case ACPI_TYPE_THERMAL:
  542. /* These are acceptable types */
  543. break;
  544. case ACPI_TYPE_INTEGER:
  545. case ACPI_TYPE_STRING:
  546. case ACPI_TYPE_BUFFER:
  547. /*
  548. * These types we will allow, but we will change the type. This
  549. * enables some existing code of the form:
  550. *
  551. * Name (DEB, 0)
  552. * Scope (DEB) { ... }
  553. */
  554. ACPI_REPORT_WARNING(("Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n", buffer_ptr, acpi_ut_get_type_name(node->type)));
  555. node->type = ACPI_TYPE_ANY;
  556. walk_state->scope_info->common.value = ACPI_TYPE_ANY;
  557. break;
  558. default:
  559. /* All other types are an error */
  560. ACPI_REPORT_ERROR(("Invalid type (%s) for target of Scope operator [%4.4s]\n", acpi_ut_get_type_name(node->type), buffer_ptr));
  561. return (AE_AML_OPERAND_TYPE);
  562. }
  563. break;
  564. default:
  565. /* All other opcodes */
  566. if (op && op->common.node) {
  567. /* This op/node was previously entered into the namespace */
  568. node = op->common.node;
  569. if (acpi_ns_opens_scope(object_type)) {
  570. status =
  571. acpi_ds_scope_stack_push(node, object_type,
  572. walk_state);
  573. if (ACPI_FAILURE(status)) {
  574. return_ACPI_STATUS(status);
  575. }
  576. }
  577. return_ACPI_STATUS(AE_OK);
  578. }
  579. /*
  580. * Enter the named type into the internal namespace. We enter the name
  581. * as we go downward in the parse tree. Any necessary subobjects that
  582. * involve arguments to the opcode must be created as we go back up the
  583. * parse tree later.
  584. *
  585. * Note: Name may already exist if we are executing a deferred opcode.
  586. */
  587. if (walk_state->deferred_node) {
  588. /* This name is already in the namespace, get the node */
  589. node = walk_state->deferred_node;
  590. status = AE_OK;
  591. break;
  592. }
  593. /* Add new entry into namespace */
  594. status =
  595. acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
  596. object_type, ACPI_IMODE_LOAD_PASS2,
  597. ACPI_NS_NO_UPSEARCH, walk_state, &(node));
  598. break;
  599. }
  600. if (ACPI_FAILURE(status)) {
  601. ACPI_REPORT_NSERROR(buffer_ptr, status);
  602. return_ACPI_STATUS(status);
  603. }
  604. if (!op) {
  605. /* Create a new op */
  606. op = acpi_ps_alloc_op(walk_state->opcode);
  607. if (!op) {
  608. return_ACPI_STATUS(AE_NO_MEMORY);
  609. }
  610. /* Initialize the new op */
  611. if (node) {
  612. op->named.name = node->name.integer;
  613. }
  614. *out_op = op;
  615. }
  616. /*
  617. * Put the Node in the "op" object that the parser uses, so we
  618. * can get it again quickly when this scope is closed
  619. */
  620. op->common.node = node;
  621. return_ACPI_STATUS(status);
  622. }
  623. /*******************************************************************************
  624. *
  625. * FUNCTION: acpi_ds_load2_end_op
  626. *
  627. * PARAMETERS: walk_state - Current state of the parse tree walk
  628. *
  629. * RETURN: Status
  630. *
  631. * DESCRIPTION: Ascending callback used during the loading of the namespace,
  632. * both control methods and everything else.
  633. *
  634. ******************************************************************************/
  635. acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
  636. {
  637. union acpi_parse_object *op;
  638. acpi_status status = AE_OK;
  639. acpi_object_type object_type;
  640. struct acpi_namespace_node *node;
  641. union acpi_parse_object *arg;
  642. struct acpi_namespace_node *new_node;
  643. #ifndef ACPI_NO_METHOD_EXECUTION
  644. u32 i;
  645. #endif
  646. ACPI_FUNCTION_TRACE("ds_load2_end_op");
  647. op = walk_state->op;
  648. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
  649. walk_state->op_info->name, op, walk_state));
  650. /* Check if opcode had an associated namespace object */
  651. if (!(walk_state->op_info->flags & AML_NSOBJECT)) {
  652. #ifndef ACPI_NO_METHOD_EXECUTION
  653. #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
  654. /* No namespace object. Executable opcode? */
  655. if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
  656. (walk_state->op_info->class == AML_CLASS_CONTROL)) {
  657. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  658. "End/EXEC: %s (fl %8.8X)\n",
  659. walk_state->op_info->name,
  660. walk_state->op_info->flags));
  661. /* Executing a type1 or type2 opcode outside of a method */
  662. status = acpi_ds_exec_end_op(walk_state);
  663. return_ACPI_STATUS(status);
  664. }
  665. #endif
  666. #endif
  667. return_ACPI_STATUS(AE_OK);
  668. }
  669. if (op->common.aml_opcode == AML_SCOPE_OP) {
  670. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  671. "Ending scope Op=%p State=%p\n", op,
  672. walk_state));
  673. }
  674. object_type = walk_state->op_info->object_type;
  675. /*
  676. * Get the Node/name from the earlier lookup
  677. * (It was saved in the *op structure)
  678. */
  679. node = op->common.node;
  680. /*
  681. * Put the Node on the object stack (Contains the ACPI Name of
  682. * this object)
  683. */
  684. walk_state->operands[0] = (void *)node;
  685. walk_state->num_operands = 1;
  686. /* Pop the scope stack */
  687. if (acpi_ns_opens_scope(object_type) &&
  688. (op->common.aml_opcode != AML_INT_METHODCALL_OP)) {
  689. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  690. "(%s) Popping scope for Op %p\n",
  691. acpi_ut_get_type_name(object_type), op));
  692. status = acpi_ds_scope_stack_pop(walk_state);
  693. if (ACPI_FAILURE(status)) {
  694. goto cleanup;
  695. }
  696. }
  697. /*
  698. * Named operations are as follows:
  699. *
  700. * AML_ALIAS
  701. * AML_BANKFIELD
  702. * AML_CREATEBITFIELD
  703. * AML_CREATEBYTEFIELD
  704. * AML_CREATEDWORDFIELD
  705. * AML_CREATEFIELD
  706. * AML_CREATEQWORDFIELD
  707. * AML_CREATEWORDFIELD
  708. * AML_DATA_REGION
  709. * AML_DEVICE
  710. * AML_EVENT
  711. * AML_FIELD
  712. * AML_INDEXFIELD
  713. * AML_METHOD
  714. * AML_METHODCALL
  715. * AML_MUTEX
  716. * AML_NAME
  717. * AML_NAMEDFIELD
  718. * AML_OPREGION
  719. * AML_POWERRES
  720. * AML_PROCESSOR
  721. * AML_SCOPE
  722. * AML_THERMALZONE
  723. */
  724. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  725. "Create-Load [%s] State=%p Op=%p named_obj=%p\n",
  726. acpi_ps_get_opcode_name(op->common.aml_opcode),
  727. walk_state, op, node));
  728. /* Decode the opcode */
  729. arg = op->common.value.arg;
  730. switch (walk_state->op_info->type) {
  731. #ifndef ACPI_NO_METHOD_EXECUTION
  732. case AML_TYPE_CREATE_FIELD:
  733. /*
  734. * Create the field object, but the field buffer and index must
  735. * be evaluated later during the execution phase
  736. */
  737. status = acpi_ds_create_buffer_field(op, walk_state);
  738. break;
  739. case AML_TYPE_NAMED_FIELD:
  740. /*
  741. * If we are executing a method, initialize the field
  742. */
  743. if (walk_state->method_node) {
  744. status = acpi_ds_init_field_objects(op, walk_state);
  745. }
  746. switch (op->common.aml_opcode) {
  747. case AML_INDEX_FIELD_OP:
  748. status =
  749. acpi_ds_create_index_field(op,
  750. (acpi_handle) arg->
  751. common.node, walk_state);
  752. break;
  753. case AML_BANK_FIELD_OP:
  754. status =
  755. acpi_ds_create_bank_field(op, arg->common.node,
  756. walk_state);
  757. break;
  758. case AML_FIELD_OP:
  759. status =
  760. acpi_ds_create_field(op, arg->common.node,
  761. walk_state);
  762. break;
  763. default:
  764. /* All NAMED_FIELD opcodes must be handled above */
  765. break;
  766. }
  767. break;
  768. case AML_TYPE_NAMED_SIMPLE:
  769. status = acpi_ds_create_operands(walk_state, arg);
  770. if (ACPI_FAILURE(status)) {
  771. goto cleanup;
  772. }
  773. switch (op->common.aml_opcode) {
  774. case AML_PROCESSOR_OP:
  775. status = acpi_ex_create_processor(walk_state);
  776. break;
  777. case AML_POWER_RES_OP:
  778. status = acpi_ex_create_power_resource(walk_state);
  779. break;
  780. case AML_MUTEX_OP:
  781. status = acpi_ex_create_mutex(walk_state);
  782. break;
  783. case AML_EVENT_OP:
  784. status = acpi_ex_create_event(walk_state);
  785. break;
  786. case AML_DATA_REGION_OP:
  787. status = acpi_ex_create_table_region(walk_state);
  788. break;
  789. case AML_ALIAS_OP:
  790. status = acpi_ex_create_alias(walk_state);
  791. break;
  792. default:
  793. /* Unknown opcode */
  794. status = AE_OK;
  795. goto cleanup;
  796. }
  797. /* Delete operands */
  798. for (i = 1; i < walk_state->num_operands; i++) {
  799. acpi_ut_remove_reference(walk_state->operands[i]);
  800. walk_state->operands[i] = NULL;
  801. }
  802. break;
  803. #endif /* ACPI_NO_METHOD_EXECUTION */
  804. case AML_TYPE_NAMED_COMPLEX:
  805. switch (op->common.aml_opcode) {
  806. #ifndef ACPI_NO_METHOD_EXECUTION
  807. case AML_REGION_OP:
  808. /*
  809. * If we are executing a method, initialize the region
  810. */
  811. if (walk_state->method_node) {
  812. status =
  813. acpi_ex_create_region(op->named.data,
  814. op->named.length,
  815. (acpi_adr_space_type)
  816. ((op->common.value.
  817. arg)->common.value.
  818. integer),
  819. walk_state);
  820. if (ACPI_FAILURE(status)) {
  821. return (status);
  822. }
  823. }
  824. /*
  825. * The op_region is not fully parsed at this time. Only valid
  826. * argument is the space_id. (We must save the address of the
  827. * AML of the address and length operands)
  828. */
  829. /*
  830. * If we have a valid region, initialize it
  831. * Namespace is NOT locked at this point.
  832. */
  833. status =
  834. acpi_ev_initialize_region
  835. (acpi_ns_get_attached_object(node), FALSE);
  836. if (ACPI_FAILURE(status)) {
  837. /*
  838. * If AE_NOT_EXIST is returned, it is not fatal
  839. * because many regions get created before a handler
  840. * is installed for said region.
  841. */
  842. if (AE_NOT_EXIST == status) {
  843. status = AE_OK;
  844. }
  845. }
  846. break;
  847. case AML_NAME_OP:
  848. status = acpi_ds_create_node(walk_state, node, op);
  849. break;
  850. case AML_METHOD_OP:
  851. /*
  852. * method_op pkg_length name_string method_flags term_list
  853. *
  854. * Note: We must create the method node/object pair as soon as we
  855. * see the method declaration. This allows later pass1 parsing
  856. * of invocations of the method (need to know the number of
  857. * arguments.)
  858. */
  859. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  860. "LOADING-Method: State=%p Op=%p named_obj=%p\n",
  861. walk_state, op, op->named.node));
  862. if (!acpi_ns_get_attached_object(op->named.node)) {
  863. walk_state->operands[0] =
  864. ACPI_CAST_PTR(void, op->named.node);
  865. walk_state->num_operands = 1;
  866. status =
  867. acpi_ds_create_operands(walk_state,
  868. op->common.value.
  869. arg);
  870. if (ACPI_SUCCESS(status)) {
  871. status =
  872. acpi_ex_create_method(op->named.
  873. data,
  874. op->named.
  875. length,
  876. walk_state);
  877. }
  878. walk_state->operands[0] = NULL;
  879. walk_state->num_operands = 0;
  880. if (ACPI_FAILURE(status)) {
  881. return_ACPI_STATUS(status);
  882. }
  883. }
  884. break;
  885. #endif /* ACPI_NO_METHOD_EXECUTION */
  886. default:
  887. /* All NAMED_COMPLEX opcodes must be handled above */
  888. break;
  889. }
  890. break;
  891. case AML_CLASS_INTERNAL:
  892. /* case AML_INT_NAMEPATH_OP: */
  893. break;
  894. case AML_CLASS_METHOD_CALL:
  895. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  896. "RESOLVING-method_call: State=%p Op=%p named_obj=%p\n",
  897. walk_state, op, node));
  898. /*
  899. * Lookup the method name and save the Node
  900. */
  901. status =
  902. acpi_ns_lookup(walk_state->scope_info,
  903. arg->common.value.string, ACPI_TYPE_ANY,
  904. ACPI_IMODE_LOAD_PASS2,
  905. ACPI_NS_SEARCH_PARENT |
  906. ACPI_NS_DONT_OPEN_SCOPE, walk_state,
  907. &(new_node));
  908. if (ACPI_SUCCESS(status)) {
  909. /*
  910. * Make sure that what we found is indeed a method
  911. * We didn't search for a method on purpose, to see if the name
  912. * would resolve
  913. */
  914. if (new_node->type != ACPI_TYPE_METHOD) {
  915. status = AE_AML_OPERAND_TYPE;
  916. }
  917. /* We could put the returned object (Node) on the object stack for
  918. * later, but for now, we will put it in the "op" object that the
  919. * parser uses, so we can get it again at the end of this scope
  920. */
  921. op->common.node = new_node;
  922. } else {
  923. ACPI_REPORT_NSERROR(arg->common.value.string, status);
  924. }
  925. break;
  926. default:
  927. break;
  928. }
  929. cleanup:
  930. /* Remove the Node pushed at the very beginning */
  931. walk_state->operands[0] = NULL;
  932. walk_state->num_operands = 0;
  933. return_ACPI_STATUS(status);
  934. }