dswload.c 26 KB

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