dsobject.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /******************************************************************************
  2. *
  3. * Module Name: dsobject - Dispatcher object management routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, 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/acnamesp.h>
  47. #include <acpi/acinterp.h>
  48. #define _COMPONENT ACPI_DISPATCHER
  49. ACPI_MODULE_NAME("dsobject")
  50. /* Local prototypes */
  51. static acpi_status
  52. acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
  53. union acpi_parse_object *op,
  54. union acpi_operand_object **obj_desc_ptr);
  55. #ifndef ACPI_NO_METHOD_EXECUTION
  56. /*******************************************************************************
  57. *
  58. * FUNCTION: acpi_ds_build_internal_object
  59. *
  60. * PARAMETERS: walk_state - Current walk state
  61. * Op - Parser object to be translated
  62. * obj_desc_ptr - Where the ACPI internal object is returned
  63. *
  64. * RETURN: Status
  65. *
  66. * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
  67. * Simple objects are any objects other than a package object!
  68. *
  69. ******************************************************************************/
  70. static acpi_status
  71. acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
  72. union acpi_parse_object *op,
  73. union acpi_operand_object **obj_desc_ptr)
  74. {
  75. union acpi_operand_object *obj_desc;
  76. acpi_status status;
  77. ACPI_FUNCTION_TRACE("ds_build_internal_object");
  78. *obj_desc_ptr = NULL;
  79. if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
  80. /*
  81. * This is a named object reference. If this name was
  82. * previously looked up in the namespace, it was stored in this op.
  83. * Otherwise, go ahead and look it up now
  84. */
  85. if (!op->common.node) {
  86. status = acpi_ns_lookup(walk_state->scope_info,
  87. op->common.value.string,
  88. ACPI_TYPE_ANY,
  89. ACPI_IMODE_EXECUTE,
  90. ACPI_NS_SEARCH_PARENT |
  91. ACPI_NS_DONT_OPEN_SCOPE, NULL,
  92. ACPI_CAST_INDIRECT_PTR(struct
  93. acpi_namespace_node,
  94. &(op->
  95. common.
  96. node)));
  97. if (ACPI_FAILURE(status)) {
  98. /* Check if we are resolving a named reference within a package */
  99. if ((status == AE_NOT_FOUND)
  100. && (acpi_gbl_enable_interpreter_slack)
  101. &&
  102. ((op->common.parent->common.aml_opcode ==
  103. AML_PACKAGE_OP)
  104. || (op->common.parent->common.aml_opcode ==
  105. AML_VAR_PACKAGE_OP))) {
  106. /*
  107. * We didn't find the target and we are populating elements
  108. * of a package - ignore if slack enabled. Some ASL code
  109. * contains dangling invalid references in packages and
  110. * expects that no exception will be issued. Leave the
  111. * element as a null element. It cannot be used, but it
  112. * can be overwritten by subsequent ASL code - this is
  113. * typically the case.
  114. */
  115. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  116. "Ignoring unresolved reference in package [%4.4s]\n",
  117. walk_state->
  118. scope_info->scope.
  119. node->name.ascii));
  120. return_ACPI_STATUS(AE_OK);
  121. } else {
  122. ACPI_REPORT_NSERROR(op->common.value.
  123. string, status);
  124. }
  125. return_ACPI_STATUS(status);
  126. }
  127. }
  128. }
  129. /* Create and init a new internal ACPI object */
  130. obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
  131. (op->common.aml_opcode))->
  132. object_type);
  133. if (!obj_desc) {
  134. return_ACPI_STATUS(AE_NO_MEMORY);
  135. }
  136. status =
  137. acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
  138. &obj_desc);
  139. if (ACPI_FAILURE(status)) {
  140. acpi_ut_remove_reference(obj_desc);
  141. return_ACPI_STATUS(status);
  142. }
  143. *obj_desc_ptr = obj_desc;
  144. return_ACPI_STATUS(AE_OK);
  145. }
  146. /*******************************************************************************
  147. *
  148. * FUNCTION: acpi_ds_build_internal_buffer_obj
  149. *
  150. * PARAMETERS: walk_state - Current walk state
  151. * Op - Parser object to be translated
  152. * buffer_length - Length of the buffer
  153. * obj_desc_ptr - Where the ACPI internal object is returned
  154. *
  155. * RETURN: Status
  156. *
  157. * DESCRIPTION: Translate a parser Op package object to the equivalent
  158. * namespace object
  159. *
  160. ******************************************************************************/
  161. acpi_status
  162. acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
  163. union acpi_parse_object *op,
  164. u32 buffer_length,
  165. union acpi_operand_object **obj_desc_ptr)
  166. {
  167. union acpi_parse_object *arg;
  168. union acpi_operand_object *obj_desc;
  169. union acpi_parse_object *byte_list;
  170. u32 byte_list_length = 0;
  171. ACPI_FUNCTION_TRACE("ds_build_internal_buffer_obj");
  172. /*
  173. * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
  174. * The buffer object already exists (from the NS node), otherwise it must
  175. * be created.
  176. */
  177. obj_desc = *obj_desc_ptr;
  178. if (!obj_desc) {
  179. /* Create a new buffer object */
  180. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
  181. *obj_desc_ptr = obj_desc;
  182. if (!obj_desc) {
  183. return_ACPI_STATUS(AE_NO_MEMORY);
  184. }
  185. }
  186. /*
  187. * Second arg is the buffer data (optional) byte_list can be either
  188. * individual bytes or a string initializer. In either case, a
  189. * byte_list appears in the AML.
  190. */
  191. arg = op->common.value.arg; /* skip first arg */
  192. byte_list = arg->named.next;
  193. if (byte_list) {
  194. if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
  195. ACPI_REPORT_ERROR(("Expecting bytelist, got AML opcode %X in op %p\n", byte_list->common.aml_opcode, byte_list));
  196. acpi_ut_remove_reference(obj_desc);
  197. return (AE_TYPE);
  198. }
  199. byte_list_length = (u32) byte_list->common.value.integer;
  200. }
  201. /*
  202. * The buffer length (number of bytes) will be the larger of:
  203. * 1) The specified buffer length and
  204. * 2) The length of the initializer byte list
  205. */
  206. obj_desc->buffer.length = buffer_length;
  207. if (byte_list_length > buffer_length) {
  208. obj_desc->buffer.length = byte_list_length;
  209. }
  210. /* Allocate the buffer */
  211. if (obj_desc->buffer.length == 0) {
  212. obj_desc->buffer.pointer = NULL;
  213. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  214. "Buffer defined with zero length in AML, creating\n"));
  215. } else {
  216. obj_desc->buffer.pointer =
  217. ACPI_MEM_CALLOCATE(obj_desc->buffer.length);
  218. if (!obj_desc->buffer.pointer) {
  219. acpi_ut_delete_object_desc(obj_desc);
  220. return_ACPI_STATUS(AE_NO_MEMORY);
  221. }
  222. /* Initialize buffer from the byte_list (if present) */
  223. if (byte_list) {
  224. ACPI_MEMCPY(obj_desc->buffer.pointer,
  225. byte_list->named.data, byte_list_length);
  226. }
  227. }
  228. obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
  229. op->common.node = (struct acpi_namespace_node *)obj_desc;
  230. return_ACPI_STATUS(AE_OK);
  231. }
  232. /*******************************************************************************
  233. *
  234. * FUNCTION: acpi_ds_build_internal_package_obj
  235. *
  236. * PARAMETERS: walk_state - Current walk state
  237. * Op - Parser object to be translated
  238. * package_length - Number of elements in the package
  239. * obj_desc_ptr - Where the ACPI internal object is returned
  240. *
  241. * RETURN: Status
  242. *
  243. * DESCRIPTION: Translate a parser Op package object to the equivalent
  244. * namespace object
  245. *
  246. ******************************************************************************/
  247. acpi_status
  248. acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
  249. union acpi_parse_object *op,
  250. u32 package_length,
  251. union acpi_operand_object **obj_desc_ptr)
  252. {
  253. union acpi_parse_object *arg;
  254. union acpi_parse_object *parent;
  255. union acpi_operand_object *obj_desc = NULL;
  256. u32 package_list_length;
  257. acpi_status status = AE_OK;
  258. acpi_native_uint i;
  259. ACPI_FUNCTION_TRACE("ds_build_internal_package_obj");
  260. /* Find the parent of a possibly nested package */
  261. parent = op->common.parent;
  262. while ((parent->common.aml_opcode == AML_PACKAGE_OP) ||
  263. (parent->common.aml_opcode == AML_VAR_PACKAGE_OP)) {
  264. parent = parent->common.parent;
  265. }
  266. /*
  267. * If we are evaluating a Named package object "Name (xxxx, Package)",
  268. * the package object already exists, otherwise it must be created.
  269. */
  270. obj_desc = *obj_desc_ptr;
  271. if (!obj_desc) {
  272. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE);
  273. *obj_desc_ptr = obj_desc;
  274. if (!obj_desc) {
  275. return_ACPI_STATUS(AE_NO_MEMORY);
  276. }
  277. obj_desc->package.node = parent->common.node;
  278. }
  279. obj_desc->package.count = package_length;
  280. /* Count the number of items in the package list */
  281. arg = op->common.value.arg;
  282. arg = arg->common.next;
  283. for (package_list_length = 0; arg; package_list_length++) {
  284. arg = arg->common.next;
  285. }
  286. /*
  287. * The package length (number of elements) will be the greater
  288. * of the specified length and the length of the initializer list
  289. */
  290. if (package_list_length > package_length) {
  291. obj_desc->package.count = package_list_length;
  292. }
  293. /*
  294. * Allocate the pointer array (array of pointers to the
  295. * individual objects). Add an extra pointer slot so
  296. * that the list is always null terminated.
  297. */
  298. obj_desc->package.elements = ACPI_MEM_CALLOCATE(((acpi_size) obj_desc->
  299. package.count +
  300. 1) * sizeof(void *));
  301. if (!obj_desc->package.elements) {
  302. acpi_ut_delete_object_desc(obj_desc);
  303. return_ACPI_STATUS(AE_NO_MEMORY);
  304. }
  305. /*
  306. * Initialize all elements of the package
  307. */
  308. arg = op->common.value.arg;
  309. arg = arg->common.next;
  310. for (i = 0; arg; i++) {
  311. if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
  312. /* Object (package or buffer) is already built */
  313. obj_desc->package.elements[i] =
  314. ACPI_CAST_PTR(union acpi_operand_object,
  315. arg->common.node);
  316. } else {
  317. status = acpi_ds_build_internal_object(walk_state, arg,
  318. &obj_desc->
  319. package.
  320. elements[i]);
  321. }
  322. arg = arg->common.next;
  323. }
  324. obj_desc->package.flags |= AOPOBJ_DATA_VALID;
  325. op->common.node = (struct acpi_namespace_node *)obj_desc;
  326. return_ACPI_STATUS(status);
  327. }
  328. /*******************************************************************************
  329. *
  330. * FUNCTION: acpi_ds_create_node
  331. *
  332. * PARAMETERS: walk_state - Current walk state
  333. * Node - NS Node to be initialized
  334. * Op - Parser object to be translated
  335. *
  336. * RETURN: Status
  337. *
  338. * DESCRIPTION: Create the object to be associated with a namespace node
  339. *
  340. ******************************************************************************/
  341. acpi_status
  342. acpi_ds_create_node(struct acpi_walk_state *walk_state,
  343. struct acpi_namespace_node *node,
  344. union acpi_parse_object *op)
  345. {
  346. acpi_status status;
  347. union acpi_operand_object *obj_desc;
  348. ACPI_FUNCTION_TRACE_PTR("ds_create_node", op);
  349. /*
  350. * Because of the execution pass through the non-control-method
  351. * parts of the table, we can arrive here twice. Only init
  352. * the named object node the first time through
  353. */
  354. if (acpi_ns_get_attached_object(node)) {
  355. return_ACPI_STATUS(AE_OK);
  356. }
  357. if (!op->common.value.arg) {
  358. /* No arguments, there is nothing to do */
  359. return_ACPI_STATUS(AE_OK);
  360. }
  361. /* Build an internal object for the argument(s) */
  362. status = acpi_ds_build_internal_object(walk_state, op->common.value.arg,
  363. &obj_desc);
  364. if (ACPI_FAILURE(status)) {
  365. return_ACPI_STATUS(status);
  366. }
  367. /* Re-type the object according to its argument */
  368. node->type = ACPI_GET_OBJECT_TYPE(obj_desc);
  369. /* Attach obj to node */
  370. status = acpi_ns_attach_object(node, obj_desc, node->type);
  371. /* Remove local reference to the object */
  372. acpi_ut_remove_reference(obj_desc);
  373. return_ACPI_STATUS(status);
  374. }
  375. #endif /* ACPI_NO_METHOD_EXECUTION */
  376. /*******************************************************************************
  377. *
  378. * FUNCTION: acpi_ds_init_object_from_op
  379. *
  380. * PARAMETERS: walk_state - Current walk state
  381. * Op - Parser op used to init the internal object
  382. * Opcode - AML opcode associated with the object
  383. * ret_obj_desc - Namespace object to be initialized
  384. *
  385. * RETURN: Status
  386. *
  387. * DESCRIPTION: Initialize a namespace object from a parser Op and its
  388. * associated arguments. The namespace object is a more compact
  389. * representation of the Op and its arguments.
  390. *
  391. ******************************************************************************/
  392. acpi_status
  393. acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
  394. union acpi_parse_object *op,
  395. u16 opcode,
  396. union acpi_operand_object **ret_obj_desc)
  397. {
  398. const struct acpi_opcode_info *op_info;
  399. union acpi_operand_object *obj_desc;
  400. acpi_status status = AE_OK;
  401. ACPI_FUNCTION_TRACE("ds_init_object_from_op");
  402. obj_desc = *ret_obj_desc;
  403. op_info = acpi_ps_get_opcode_info(opcode);
  404. if (op_info->class == AML_CLASS_UNKNOWN) {
  405. /* Unknown opcode */
  406. return_ACPI_STATUS(AE_TYPE);
  407. }
  408. /* Perform per-object initialization */
  409. switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
  410. case ACPI_TYPE_BUFFER:
  411. /*
  412. * Defer evaluation of Buffer term_arg operand
  413. */
  414. obj_desc->buffer.node = (struct acpi_namespace_node *)
  415. walk_state->operands[0];
  416. obj_desc->buffer.aml_start = op->named.data;
  417. obj_desc->buffer.aml_length = op->named.length;
  418. break;
  419. case ACPI_TYPE_PACKAGE:
  420. /*
  421. * Defer evaluation of Package term_arg operand
  422. */
  423. obj_desc->package.node = (struct acpi_namespace_node *)
  424. walk_state->operands[0];
  425. obj_desc->package.aml_start = op->named.data;
  426. obj_desc->package.aml_length = op->named.length;
  427. break;
  428. case ACPI_TYPE_INTEGER:
  429. switch (op_info->type) {
  430. case AML_TYPE_CONSTANT:
  431. /*
  432. * Resolve AML Constants here - AND ONLY HERE!
  433. * All constants are integers.
  434. * We mark the integer with a flag that indicates that it started
  435. * life as a constant -- so that stores to constants will perform
  436. * as expected (noop). zero_op is used as a placeholder for optional
  437. * target operands.
  438. */
  439. obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
  440. switch (opcode) {
  441. case AML_ZERO_OP:
  442. obj_desc->integer.value = 0;
  443. break;
  444. case AML_ONE_OP:
  445. obj_desc->integer.value = 1;
  446. break;
  447. case AML_ONES_OP:
  448. obj_desc->integer.value = ACPI_INTEGER_MAX;
  449. /* Truncate value if we are executing from a 32-bit ACPI table */
  450. #ifndef ACPI_NO_METHOD_EXECUTION
  451. acpi_ex_truncate_for32bit_table(obj_desc);
  452. #endif
  453. break;
  454. case AML_REVISION_OP:
  455. obj_desc->integer.value = ACPI_CA_VERSION;
  456. break;
  457. default:
  458. ACPI_REPORT_ERROR(("Unknown constant opcode %X\n", opcode));
  459. status = AE_AML_OPERAND_TYPE;
  460. break;
  461. }
  462. break;
  463. case AML_TYPE_LITERAL:
  464. obj_desc->integer.value = op->common.value.integer;
  465. #ifndef ACPI_NO_METHOD_EXECUTION
  466. acpi_ex_truncate_for32bit_table(obj_desc);
  467. #endif
  468. break;
  469. default:
  470. ACPI_REPORT_ERROR(("Unknown Integer type %X\n",
  471. op_info->type));
  472. status = AE_AML_OPERAND_TYPE;
  473. break;
  474. }
  475. break;
  476. case ACPI_TYPE_STRING:
  477. obj_desc->string.pointer = op->common.value.string;
  478. obj_desc->string.length =
  479. (u32) ACPI_STRLEN(op->common.value.string);
  480. /*
  481. * The string is contained in the ACPI table, don't ever try
  482. * to delete it
  483. */
  484. obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
  485. break;
  486. case ACPI_TYPE_METHOD:
  487. break;
  488. case ACPI_TYPE_LOCAL_REFERENCE:
  489. switch (op_info->type) {
  490. case AML_TYPE_LOCAL_VARIABLE:
  491. /* Split the opcode into a base opcode + offset */
  492. obj_desc->reference.opcode = AML_LOCAL_OP;
  493. obj_desc->reference.offset = opcode - AML_LOCAL_OP;
  494. #ifndef ACPI_NO_METHOD_EXECUTION
  495. status = acpi_ds_method_data_get_node(AML_LOCAL_OP,
  496. obj_desc->
  497. reference.offset,
  498. walk_state,
  499. (struct
  500. acpi_namespace_node
  501. **)&obj_desc->
  502. reference.object);
  503. #endif
  504. break;
  505. case AML_TYPE_METHOD_ARGUMENT:
  506. /* Split the opcode into a base opcode + offset */
  507. obj_desc->reference.opcode = AML_ARG_OP;
  508. obj_desc->reference.offset = opcode - AML_ARG_OP;
  509. #ifndef ACPI_NO_METHOD_EXECUTION
  510. status = acpi_ds_method_data_get_node(AML_ARG_OP,
  511. obj_desc->
  512. reference.offset,
  513. walk_state,
  514. (struct
  515. acpi_namespace_node
  516. **)&obj_desc->
  517. reference.object);
  518. #endif
  519. break;
  520. default: /* Other literals, etc.. */
  521. if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
  522. /* Node was saved in Op */
  523. obj_desc->reference.node = op->common.node;
  524. }
  525. obj_desc->reference.opcode = opcode;
  526. break;
  527. }
  528. break;
  529. default:
  530. ACPI_REPORT_ERROR(("Unimplemented data type: %X\n",
  531. ACPI_GET_OBJECT_TYPE(obj_desc)));
  532. status = AE_AML_OPERAND_TYPE;
  533. break;
  534. }
  535. return_ACPI_STATUS(status);
  536. }