dswload.c 30 KB

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