dswload.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  1. /******************************************************************************
  2. *
  3. * Module Name: dswload - Dispatcher namespace load callbacks
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2007, 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, 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. break;
  653. }
  654. if (ACPI_FAILURE(status)) {
  655. ACPI_ERROR_NAMESPACE(buffer_ptr, status);
  656. return_ACPI_STATUS(status);
  657. }
  658. if (!op) {
  659. /* Create a new op */
  660. op = acpi_ps_alloc_op(walk_state->opcode);
  661. if (!op) {
  662. return_ACPI_STATUS(AE_NO_MEMORY);
  663. }
  664. /* Initialize the new op */
  665. if (node) {
  666. op->named.name = node->name.integer;
  667. }
  668. *out_op = op;
  669. }
  670. /*
  671. * Put the Node in the "op" object that the parser uses, so we
  672. * can get it again quickly when this scope is closed
  673. */
  674. op->common.node = node;
  675. return_ACPI_STATUS(status);
  676. }
  677. /*******************************************************************************
  678. *
  679. * FUNCTION: acpi_ds_load2_end_op
  680. *
  681. * PARAMETERS: walk_state - Current state of the parse tree walk
  682. *
  683. * RETURN: Status
  684. *
  685. * DESCRIPTION: Ascending callback used during the loading of the namespace,
  686. * both control methods and everything else.
  687. *
  688. ******************************************************************************/
  689. acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
  690. {
  691. union acpi_parse_object *op;
  692. acpi_status status = AE_OK;
  693. acpi_object_type object_type;
  694. struct acpi_namespace_node *node;
  695. union acpi_parse_object *arg;
  696. struct acpi_namespace_node *new_node;
  697. #ifndef ACPI_NO_METHOD_EXECUTION
  698. u32 i;
  699. u8 region_space;
  700. #endif
  701. ACPI_FUNCTION_TRACE(ds_load2_end_op);
  702. op = walk_state->op;
  703. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
  704. walk_state->op_info->name, op, walk_state));
  705. /* Check if opcode had an associated namespace object */
  706. if (!(walk_state->op_info->flags & AML_NSOBJECT)) {
  707. #ifndef ACPI_NO_METHOD_EXECUTION
  708. #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
  709. /* No namespace object. Executable opcode? */
  710. if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
  711. (walk_state->op_info->class == AML_CLASS_CONTROL)) {
  712. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  713. "End/EXEC: %s (fl %8.8X)\n",
  714. walk_state->op_info->name,
  715. walk_state->op_info->flags));
  716. /* Executing a type1 or type2 opcode outside of a method */
  717. status = acpi_ds_exec_end_op(walk_state);
  718. return_ACPI_STATUS(status);
  719. }
  720. #endif
  721. #endif
  722. return_ACPI_STATUS(AE_OK);
  723. }
  724. if (op->common.aml_opcode == AML_SCOPE_OP) {
  725. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  726. "Ending scope Op=%p State=%p\n", op,
  727. walk_state));
  728. }
  729. object_type = walk_state->op_info->object_type;
  730. /*
  731. * Get the Node/name from the earlier lookup
  732. * (It was saved in the *op structure)
  733. */
  734. node = op->common.node;
  735. /*
  736. * Put the Node on the object stack (Contains the ACPI Name of
  737. * this object)
  738. */
  739. walk_state->operands[0] = (void *)node;
  740. walk_state->num_operands = 1;
  741. /* Pop the scope stack */
  742. if (acpi_ns_opens_scope(object_type) &&
  743. (op->common.aml_opcode != AML_INT_METHODCALL_OP)) {
  744. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  745. "(%s) Popping scope for Op %p\n",
  746. acpi_ut_get_type_name(object_type), op));
  747. status = acpi_ds_scope_stack_pop(walk_state);
  748. if (ACPI_FAILURE(status)) {
  749. goto cleanup;
  750. }
  751. }
  752. /*
  753. * Named operations are as follows:
  754. *
  755. * AML_ALIAS
  756. * AML_BANKFIELD
  757. * AML_CREATEBITFIELD
  758. * AML_CREATEBYTEFIELD
  759. * AML_CREATEDWORDFIELD
  760. * AML_CREATEFIELD
  761. * AML_CREATEQWORDFIELD
  762. * AML_CREATEWORDFIELD
  763. * AML_DATA_REGION
  764. * AML_DEVICE
  765. * AML_EVENT
  766. * AML_FIELD
  767. * AML_INDEXFIELD
  768. * AML_METHOD
  769. * AML_METHODCALL
  770. * AML_MUTEX
  771. * AML_NAME
  772. * AML_NAMEDFIELD
  773. * AML_OPREGION
  774. * AML_POWERRES
  775. * AML_PROCESSOR
  776. * AML_SCOPE
  777. * AML_THERMALZONE
  778. */
  779. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  780. "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
  781. acpi_ps_get_opcode_name(op->common.aml_opcode),
  782. walk_state, op, node));
  783. /* Decode the opcode */
  784. arg = op->common.value.arg;
  785. switch (walk_state->op_info->type) {
  786. #ifndef ACPI_NO_METHOD_EXECUTION
  787. case AML_TYPE_CREATE_FIELD:
  788. /*
  789. * Create the field object, but the field buffer and index must
  790. * be evaluated later during the execution phase
  791. */
  792. status = acpi_ds_create_buffer_field(op, walk_state);
  793. break;
  794. case AML_TYPE_NAMED_FIELD:
  795. /*
  796. * If we are executing a method, initialize the field
  797. */
  798. if (walk_state->method_node) {
  799. status = acpi_ds_init_field_objects(op, walk_state);
  800. }
  801. switch (op->common.aml_opcode) {
  802. case AML_INDEX_FIELD_OP:
  803. status =
  804. acpi_ds_create_index_field(op,
  805. (acpi_handle) arg->
  806. common.node, walk_state);
  807. break;
  808. case AML_BANK_FIELD_OP:
  809. status =
  810. acpi_ds_create_bank_field(op, arg->common.node,
  811. walk_state);
  812. break;
  813. case AML_FIELD_OP:
  814. status =
  815. acpi_ds_create_field(op, arg->common.node,
  816. walk_state);
  817. break;
  818. default:
  819. /* All NAMED_FIELD opcodes must be handled above */
  820. break;
  821. }
  822. break;
  823. case AML_TYPE_NAMED_SIMPLE:
  824. status = acpi_ds_create_operands(walk_state, arg);
  825. if (ACPI_FAILURE(status)) {
  826. goto cleanup;
  827. }
  828. switch (op->common.aml_opcode) {
  829. case AML_PROCESSOR_OP:
  830. status = acpi_ex_create_processor(walk_state);
  831. break;
  832. case AML_POWER_RES_OP:
  833. status = acpi_ex_create_power_resource(walk_state);
  834. break;
  835. case AML_MUTEX_OP:
  836. status = acpi_ex_create_mutex(walk_state);
  837. break;
  838. case AML_EVENT_OP:
  839. status = acpi_ex_create_event(walk_state);
  840. break;
  841. case AML_ALIAS_OP:
  842. status = acpi_ex_create_alias(walk_state);
  843. break;
  844. default:
  845. /* Unknown opcode */
  846. status = AE_OK;
  847. goto cleanup;
  848. }
  849. /* Delete operands */
  850. for (i = 1; i < walk_state->num_operands; i++) {
  851. acpi_ut_remove_reference(walk_state->operands[i]);
  852. walk_state->operands[i] = NULL;
  853. }
  854. break;
  855. #endif /* ACPI_NO_METHOD_EXECUTION */
  856. case AML_TYPE_NAMED_COMPLEX:
  857. switch (op->common.aml_opcode) {
  858. #ifndef ACPI_NO_METHOD_EXECUTION
  859. case AML_REGION_OP:
  860. case AML_DATA_REGION_OP:
  861. if (op->common.aml_opcode == AML_REGION_OP) {
  862. region_space = (acpi_adr_space_type)
  863. ((op->common.value.arg)->common.value.
  864. integer);
  865. } else {
  866. region_space = REGION_DATA_TABLE;
  867. }
  868. /*
  869. * If we are executing a method, initialize the region
  870. */
  871. if (walk_state->method_node) {
  872. status =
  873. acpi_ex_create_region(op->named.data,
  874. op->named.length,
  875. region_space,
  876. walk_state);
  877. if (ACPI_FAILURE(status)) {
  878. return (status);
  879. }
  880. }
  881. /*
  882. * The op_region is not fully parsed at this time. Only valid
  883. * argument is the space_id. (We must save the address of the
  884. * AML of the address and length operands)
  885. */
  886. /*
  887. * If we have a valid region, initialize it
  888. * Namespace is NOT locked at this point.
  889. */
  890. status =
  891. acpi_ev_initialize_region
  892. (acpi_ns_get_attached_object(node), FALSE);
  893. if (ACPI_FAILURE(status)) {
  894. /*
  895. * If AE_NOT_EXIST is returned, it is not fatal
  896. * because many regions get created before a handler
  897. * is installed for said region.
  898. */
  899. if (AE_NOT_EXIST == status) {
  900. status = AE_OK;
  901. }
  902. }
  903. break;
  904. case AML_NAME_OP:
  905. status = acpi_ds_create_node(walk_state, node, op);
  906. break;
  907. case AML_METHOD_OP:
  908. /*
  909. * method_op pkg_length name_string method_flags term_list
  910. *
  911. * Note: We must create the method node/object pair as soon as we
  912. * see the method declaration. This allows later pass1 parsing
  913. * of invocations of the method (need to know the number of
  914. * arguments.)
  915. */
  916. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  917. "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
  918. walk_state, op, op->named.node));
  919. if (!acpi_ns_get_attached_object(op->named.node)) {
  920. walk_state->operands[0] =
  921. ACPI_CAST_PTR(void, op->named.node);
  922. walk_state->num_operands = 1;
  923. status =
  924. acpi_ds_create_operands(walk_state,
  925. op->common.value.
  926. arg);
  927. if (ACPI_SUCCESS(status)) {
  928. status =
  929. acpi_ex_create_method(op->named.
  930. data,
  931. op->named.
  932. length,
  933. walk_state);
  934. }
  935. walk_state->operands[0] = NULL;
  936. walk_state->num_operands = 0;
  937. if (ACPI_FAILURE(status)) {
  938. return_ACPI_STATUS(status);
  939. }
  940. }
  941. break;
  942. #endif /* ACPI_NO_METHOD_EXECUTION */
  943. default:
  944. /* All NAMED_COMPLEX opcodes must be handled above */
  945. break;
  946. }
  947. break;
  948. case AML_CLASS_INTERNAL:
  949. /* case AML_INT_NAMEPATH_OP: */
  950. break;
  951. case AML_CLASS_METHOD_CALL:
  952. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  953. "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
  954. walk_state, op, node));
  955. /*
  956. * Lookup the method name and save the Node
  957. */
  958. status =
  959. acpi_ns_lookup(walk_state->scope_info,
  960. arg->common.value.string, ACPI_TYPE_ANY,
  961. ACPI_IMODE_LOAD_PASS2,
  962. ACPI_NS_SEARCH_PARENT |
  963. ACPI_NS_DONT_OPEN_SCOPE, walk_state,
  964. &(new_node));
  965. if (ACPI_SUCCESS(status)) {
  966. /*
  967. * Make sure that what we found is indeed a method
  968. * We didn't search for a method on purpose, to see if the name
  969. * would resolve
  970. */
  971. if (new_node->type != ACPI_TYPE_METHOD) {
  972. status = AE_AML_OPERAND_TYPE;
  973. }
  974. /* We could put the returned object (Node) on the object stack for
  975. * later, but for now, we will put it in the "op" object that the
  976. * parser uses, so we can get it again at the end of this scope
  977. */
  978. op->common.node = new_node;
  979. } else {
  980. ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
  981. }
  982. break;
  983. default:
  984. break;
  985. }
  986. cleanup:
  987. /* Remove the Node pushed at the very beginning */
  988. walk_state->operands[0] = NULL;
  989. walk_state->num_operands = 0;
  990. return_ACPI_STATUS(status);
  991. }