dsobject.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /******************************************************************************
  2. *
  3. * Module Name: dsobject - Dispatcher object management routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include <acpi/acparser.h>
  44. #include <acpi/amlcode.h>
  45. #include <acpi/acdispat.h>
  46. #include <acpi/acnamesp.h>
  47. #include <acpi/acinterp.h>
  48. #define _COMPONENT ACPI_DISPATCHER
  49. ACPI_MODULE_NAME("dsobject")
  50. static acpi_status
  51. acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
  52. union acpi_parse_object *op,
  53. union acpi_operand_object **obj_desc_ptr);
  54. #ifndef ACPI_NO_METHOD_EXECUTION
  55. /*******************************************************************************
  56. *
  57. * FUNCTION: acpi_ds_build_internal_object
  58. *
  59. * PARAMETERS: walk_state - Current walk state
  60. * Op - Parser object to be translated
  61. * obj_desc_ptr - Where the ACPI internal object is returned
  62. *
  63. * RETURN: Status
  64. *
  65. * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
  66. * Simple objects are any objects other than a package object!
  67. *
  68. ******************************************************************************/
  69. static acpi_status
  70. acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
  71. union acpi_parse_object *op,
  72. union acpi_operand_object **obj_desc_ptr)
  73. {
  74. union acpi_operand_object *obj_desc;
  75. acpi_status status;
  76. ACPI_FUNCTION_TRACE("ds_build_internal_object");
  77. *obj_desc_ptr = NULL;
  78. if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
  79. /*
  80. * This is an named object reference. If this name was
  81. * previously looked up in the namespace, it was stored in this op.
  82. * Otherwise, go ahead and look it up now
  83. */
  84. if (!op->common.node) {
  85. status = acpi_ns_lookup(walk_state->scope_info,
  86. op->common.value.string,
  87. ACPI_TYPE_ANY,
  88. ACPI_IMODE_EXECUTE,
  89. ACPI_NS_SEARCH_PARENT |
  90. ACPI_NS_DONT_OPEN_SCOPE, NULL,
  91. (struct acpi_namespace_node **)
  92. &(op->common.node));
  93. if (ACPI_FAILURE(status)) {
  94. ACPI_REPORT_NSERROR(op->common.value.string,
  95. status);
  96. return_ACPI_STATUS(status);
  97. }
  98. }
  99. }
  100. /* Create and init the internal ACPI object */
  101. obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
  102. (op->common.aml_opcode))->
  103. object_type);
  104. if (!obj_desc) {
  105. return_ACPI_STATUS(AE_NO_MEMORY);
  106. }
  107. status =
  108. acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
  109. &obj_desc);
  110. if (ACPI_FAILURE(status)) {
  111. acpi_ut_remove_reference(obj_desc);
  112. return_ACPI_STATUS(status);
  113. }
  114. *obj_desc_ptr = obj_desc;
  115. return_ACPI_STATUS(AE_OK);
  116. }
  117. /*******************************************************************************
  118. *
  119. * FUNCTION: acpi_ds_build_internal_buffer_obj
  120. *
  121. * PARAMETERS: walk_state - Current walk state
  122. * Op - Parser object to be translated
  123. * buffer_length - Length of the buffer
  124. * obj_desc_ptr - Where the ACPI internal object is returned
  125. *
  126. * RETURN: Status
  127. *
  128. * DESCRIPTION: Translate a parser Op package object to the equivalent
  129. * namespace object
  130. *
  131. ******************************************************************************/
  132. acpi_status
  133. acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
  134. union acpi_parse_object *op,
  135. u32 buffer_length,
  136. union acpi_operand_object **obj_desc_ptr)
  137. {
  138. union acpi_parse_object *arg;
  139. union acpi_operand_object *obj_desc;
  140. union acpi_parse_object *byte_list;
  141. u32 byte_list_length = 0;
  142. ACPI_FUNCTION_TRACE("ds_build_internal_buffer_obj");
  143. obj_desc = *obj_desc_ptr;
  144. if (obj_desc) {
  145. /*
  146. * We are evaluating a Named buffer object "Name (xxxx, Buffer)".
  147. * The buffer object already exists (from the NS node)
  148. */
  149. } else {
  150. /* Create a new buffer object */
  151. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
  152. *obj_desc_ptr = obj_desc;
  153. if (!obj_desc) {
  154. return_ACPI_STATUS(AE_NO_MEMORY);
  155. }
  156. }
  157. /*
  158. * Second arg is the buffer data (optional) byte_list can be either
  159. * individual bytes or a string initializer. In either case, a
  160. * byte_list appears in the AML.
  161. */
  162. arg = op->common.value.arg; /* skip first arg */
  163. byte_list = arg->named.next;
  164. if (byte_list) {
  165. if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
  166. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  167. "Expecting bytelist, got AML opcode %X in op %p\n",
  168. byte_list->common.aml_opcode,
  169. byte_list));
  170. acpi_ut_remove_reference(obj_desc);
  171. return (AE_TYPE);
  172. }
  173. byte_list_length = (u32) byte_list->common.value.integer;
  174. }
  175. /*
  176. * The buffer length (number of bytes) will be the larger of:
  177. * 1) The specified buffer length and
  178. * 2) The length of the initializer byte list
  179. */
  180. obj_desc->buffer.length = buffer_length;
  181. if (byte_list_length > buffer_length) {
  182. obj_desc->buffer.length = byte_list_length;
  183. }
  184. /* Allocate the buffer */
  185. if (obj_desc->buffer.length == 0) {
  186. obj_desc->buffer.pointer = NULL;
  187. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  188. "Buffer defined with zero length in AML, creating\n"));
  189. } else {
  190. obj_desc->buffer.pointer =
  191. ACPI_MEM_CALLOCATE(obj_desc->buffer.length);
  192. if (!obj_desc->buffer.pointer) {
  193. acpi_ut_delete_object_desc(obj_desc);
  194. return_ACPI_STATUS(AE_NO_MEMORY);
  195. }
  196. /* Initialize buffer from the byte_list (if present) */
  197. if (byte_list) {
  198. ACPI_MEMCPY(obj_desc->buffer.pointer,
  199. byte_list->named.data, byte_list_length);
  200. }
  201. }
  202. obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
  203. op->common.node = (struct acpi_namespace_node *)obj_desc;
  204. return_ACPI_STATUS(AE_OK);
  205. }
  206. /*******************************************************************************
  207. *
  208. * FUNCTION: acpi_ds_build_internal_package_obj
  209. *
  210. * PARAMETERS: walk_state - Current walk state
  211. * Op - Parser object to be translated
  212. * package_length - Number of elements in the package
  213. * obj_desc_ptr - Where the ACPI internal object is returned
  214. *
  215. * RETURN: Status
  216. *
  217. * DESCRIPTION: Translate a parser Op package object to the equivalent
  218. * namespace object
  219. *
  220. ******************************************************************************/
  221. acpi_status
  222. acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
  223. union acpi_parse_object *op,
  224. u32 package_length,
  225. union acpi_operand_object **obj_desc_ptr)
  226. {
  227. union acpi_parse_object *arg;
  228. union acpi_parse_object *parent;
  229. union acpi_operand_object *obj_desc = NULL;
  230. u32 package_list_length;
  231. acpi_status status = AE_OK;
  232. u32 i;
  233. ACPI_FUNCTION_TRACE("ds_build_internal_package_obj");
  234. /* Find the parent of a possibly nested package */
  235. parent = op->common.parent;
  236. while ((parent->common.aml_opcode == AML_PACKAGE_OP) ||
  237. (parent->common.aml_opcode == AML_VAR_PACKAGE_OP)) {
  238. parent = parent->common.parent;
  239. }
  240. obj_desc = *obj_desc_ptr;
  241. if (obj_desc) {
  242. /*
  243. * We are evaluating a Named package object "Name (xxxx, Package)".
  244. * Get the existing package object from the NS node
  245. */
  246. } else {
  247. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE);
  248. *obj_desc_ptr = obj_desc;
  249. if (!obj_desc) {
  250. return_ACPI_STATUS(AE_NO_MEMORY);
  251. }
  252. obj_desc->package.node = parent->common.node;
  253. }
  254. obj_desc->package.count = package_length;
  255. /* Count the number of items in the package list */
  256. package_list_length = 0;
  257. arg = op->common.value.arg;
  258. arg = arg->common.next;
  259. while (arg) {
  260. package_list_length++;
  261. arg = arg->common.next;
  262. }
  263. /*
  264. * The package length (number of elements) will be the greater
  265. * of the specified length and the length of the initializer list
  266. */
  267. if (package_list_length > package_length) {
  268. obj_desc->package.count = package_list_length;
  269. }
  270. /*
  271. * Allocate the pointer array (array of pointers to the
  272. * individual objects). Add an extra pointer slot so
  273. * that the list is always null terminated.
  274. */
  275. obj_desc->package.elements = ACPI_MEM_CALLOCATE(((acpi_size) obj_desc->
  276. package.count +
  277. 1) * sizeof(void *));
  278. if (!obj_desc->package.elements) {
  279. acpi_ut_delete_object_desc(obj_desc);
  280. return_ACPI_STATUS(AE_NO_MEMORY);
  281. }
  282. /*
  283. * Now init the elements of the package
  284. */
  285. i = 0;
  286. arg = op->common.value.arg;
  287. arg = arg->common.next;
  288. while (arg) {
  289. if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
  290. /* Object (package or buffer) is already built */
  291. obj_desc->package.elements[i] =
  292. ACPI_CAST_PTR(union acpi_operand_object,
  293. arg->common.node);
  294. } else {
  295. status = acpi_ds_build_internal_object(walk_state, arg,
  296. &obj_desc->
  297. package.
  298. elements[i]);
  299. }
  300. i++;
  301. arg = arg->common.next;
  302. }
  303. obj_desc->package.flags |= AOPOBJ_DATA_VALID;
  304. op->common.node = (struct acpi_namespace_node *)obj_desc;
  305. return_ACPI_STATUS(status);
  306. }
  307. /*******************************************************************************
  308. *
  309. * FUNCTION: acpi_ds_create_node
  310. *
  311. * PARAMETERS: walk_state - Current walk state
  312. * Node - NS Node to be initialized
  313. * Op - Parser object to be translated
  314. *
  315. * RETURN: Status
  316. *
  317. * DESCRIPTION: Create the object to be associated with a namespace node
  318. *
  319. ******************************************************************************/
  320. acpi_status
  321. acpi_ds_create_node(struct acpi_walk_state *walk_state,
  322. struct acpi_namespace_node *node,
  323. union acpi_parse_object *op)
  324. {
  325. acpi_status status;
  326. union acpi_operand_object *obj_desc;
  327. ACPI_FUNCTION_TRACE_PTR("ds_create_node", op);
  328. /*
  329. * Because of the execution pass through the non-control-method
  330. * parts of the table, we can arrive here twice. Only init
  331. * the named object node the first time through
  332. */
  333. if (acpi_ns_get_attached_object(node)) {
  334. return_ACPI_STATUS(AE_OK);
  335. }
  336. if (!op->common.value.arg) {
  337. /* No arguments, there is nothing to do */
  338. return_ACPI_STATUS(AE_OK);
  339. }
  340. /* Build an internal object for the argument(s) */
  341. status = acpi_ds_build_internal_object(walk_state, op->common.value.arg,
  342. &obj_desc);
  343. if (ACPI_FAILURE(status)) {
  344. return_ACPI_STATUS(status);
  345. }
  346. /* Re-type the object according to its argument */
  347. node->type = ACPI_GET_OBJECT_TYPE(obj_desc);
  348. /* Attach obj to node */
  349. status = acpi_ns_attach_object(node, obj_desc, node->type);
  350. /* Remove local reference to the object */
  351. acpi_ut_remove_reference(obj_desc);
  352. return_ACPI_STATUS(status);
  353. }
  354. #endif /* ACPI_NO_METHOD_EXECUTION */
  355. /*******************************************************************************
  356. *
  357. * FUNCTION: acpi_ds_init_object_from_op
  358. *
  359. * PARAMETERS: walk_state - Current walk state
  360. * Op - Parser op used to init the internal object
  361. * Opcode - AML opcode associated with the object
  362. * ret_obj_desc - Namespace object to be initialized
  363. *
  364. * RETURN: Status
  365. *
  366. * DESCRIPTION: Initialize a namespace object from a parser Op and its
  367. * associated arguments. The namespace object is a more compact
  368. * representation of the Op and its arguments.
  369. *
  370. ******************************************************************************/
  371. acpi_status
  372. acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
  373. union acpi_parse_object *op,
  374. u16 opcode,
  375. union acpi_operand_object **ret_obj_desc)
  376. {
  377. const struct acpi_opcode_info *op_info;
  378. union acpi_operand_object *obj_desc;
  379. acpi_status status = AE_OK;
  380. ACPI_FUNCTION_TRACE("ds_init_object_from_op");
  381. obj_desc = *ret_obj_desc;
  382. op_info = acpi_ps_get_opcode_info(opcode);
  383. if (op_info->class == AML_CLASS_UNKNOWN) {
  384. /* Unknown opcode */
  385. return_ACPI_STATUS(AE_TYPE);
  386. }
  387. /* Perform per-object initialization */
  388. switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
  389. case ACPI_TYPE_BUFFER:
  390. /*
  391. * Defer evaluation of Buffer term_arg operand
  392. */
  393. obj_desc->buffer.node = (struct acpi_namespace_node *)
  394. walk_state->operands[0];
  395. obj_desc->buffer.aml_start = op->named.data;
  396. obj_desc->buffer.aml_length = op->named.length;
  397. break;
  398. case ACPI_TYPE_PACKAGE:
  399. /*
  400. * Defer evaluation of Package term_arg operand
  401. */
  402. obj_desc->package.node = (struct acpi_namespace_node *)
  403. walk_state->operands[0];
  404. obj_desc->package.aml_start = op->named.data;
  405. obj_desc->package.aml_length = op->named.length;
  406. break;
  407. case ACPI_TYPE_INTEGER:
  408. switch (op_info->type) {
  409. case AML_TYPE_CONSTANT:
  410. /*
  411. * Resolve AML Constants here - AND ONLY HERE!
  412. * All constants are integers.
  413. * We mark the integer with a flag that indicates that it started
  414. * life as a constant -- so that stores to constants will perform
  415. * as expected (noop). zero_op is used as a placeholder for optional
  416. * target operands.
  417. */
  418. obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
  419. switch (opcode) {
  420. case AML_ZERO_OP:
  421. obj_desc->integer.value = 0;
  422. break;
  423. case AML_ONE_OP:
  424. obj_desc->integer.value = 1;
  425. break;
  426. case AML_ONES_OP:
  427. obj_desc->integer.value = ACPI_INTEGER_MAX;
  428. /* Truncate value if we are executing from a 32-bit ACPI table */
  429. #ifndef ACPI_NO_METHOD_EXECUTION
  430. acpi_ex_truncate_for32bit_table(obj_desc);
  431. #endif
  432. break;
  433. case AML_REVISION_OP:
  434. obj_desc->integer.value = ACPI_CA_VERSION;
  435. break;
  436. default:
  437. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  438. "Unknown constant opcode %X\n",
  439. opcode));
  440. status = AE_AML_OPERAND_TYPE;
  441. break;
  442. }
  443. break;
  444. case AML_TYPE_LITERAL:
  445. obj_desc->integer.value = op->common.value.integer;
  446. #ifndef ACPI_NO_METHOD_EXECUTION
  447. acpi_ex_truncate_for32bit_table(obj_desc);
  448. #endif
  449. break;
  450. default:
  451. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  452. "Unknown Integer type %X\n",
  453. op_info->type));
  454. status = AE_AML_OPERAND_TYPE;
  455. break;
  456. }
  457. break;
  458. case ACPI_TYPE_STRING:
  459. obj_desc->string.pointer = op->common.value.string;
  460. obj_desc->string.length =
  461. (u32) ACPI_STRLEN(op->common.value.string);
  462. /*
  463. * The string is contained in the ACPI table, don't ever try
  464. * to delete it
  465. */
  466. obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
  467. break;
  468. case ACPI_TYPE_METHOD:
  469. break;
  470. case ACPI_TYPE_LOCAL_REFERENCE:
  471. switch (op_info->type) {
  472. case AML_TYPE_LOCAL_VARIABLE:
  473. /* Split the opcode into a base opcode + offset */
  474. obj_desc->reference.opcode = AML_LOCAL_OP;
  475. obj_desc->reference.offset = opcode - AML_LOCAL_OP;
  476. #ifndef ACPI_NO_METHOD_EXECUTION
  477. status = acpi_ds_method_data_get_node(AML_LOCAL_OP,
  478. obj_desc->
  479. reference.offset,
  480. walk_state,
  481. (struct
  482. acpi_namespace_node
  483. **)&obj_desc->
  484. reference.object);
  485. #endif
  486. break;
  487. case AML_TYPE_METHOD_ARGUMENT:
  488. /* Split the opcode into a base opcode + offset */
  489. obj_desc->reference.opcode = AML_ARG_OP;
  490. obj_desc->reference.offset = opcode - AML_ARG_OP;
  491. #ifndef ACPI_NO_METHOD_EXECUTION
  492. status = acpi_ds_method_data_get_node(AML_ARG_OP,
  493. obj_desc->
  494. reference.offset,
  495. walk_state,
  496. (struct
  497. acpi_namespace_node
  498. **)&obj_desc->
  499. reference.object);
  500. #endif
  501. break;
  502. default: /* Other literals, etc.. */
  503. if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
  504. /* Node was saved in Op */
  505. obj_desc->reference.node = op->common.node;
  506. }
  507. obj_desc->reference.opcode = opcode;
  508. break;
  509. }
  510. break;
  511. default:
  512. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  513. "Unimplemented data type: %X\n",
  514. ACPI_GET_OBJECT_TYPE(obj_desc)));
  515. status = AE_AML_OPERAND_TYPE;
  516. break;
  517. }
  518. return_ACPI_STATUS(status);
  519. }