excreate.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. /******************************************************************************
  2. *
  3. * Module Name: excreate - Named object creation
  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/acinterp.h>
  44. #include <acpi/amlcode.h>
  45. #include <acpi/acnamesp.h>
  46. #include <acpi/acevents.h>
  47. #include <acpi/actables.h>
  48. #define _COMPONENT ACPI_EXECUTER
  49. ACPI_MODULE_NAME("excreate")
  50. #ifndef ACPI_NO_METHOD_EXECUTION
  51. /*******************************************************************************
  52. *
  53. * FUNCTION: acpi_ex_create_alias
  54. *
  55. * PARAMETERS: walk_state - Current state, contains operands
  56. *
  57. * RETURN: Status
  58. *
  59. * DESCRIPTION: Create a new named alias
  60. *
  61. ******************************************************************************/
  62. acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
  63. {
  64. struct acpi_namespace_node *target_node;
  65. struct acpi_namespace_node *alias_node;
  66. acpi_status status = AE_OK;
  67. ACPI_FUNCTION_TRACE(ex_create_alias);
  68. /* Get the source/alias operands (both namespace nodes) */
  69. alias_node = (struct acpi_namespace_node *)walk_state->operands[0];
  70. target_node = (struct acpi_namespace_node *)walk_state->operands[1];
  71. if ((target_node->type == ACPI_TYPE_LOCAL_ALIAS) ||
  72. (target_node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
  73. /*
  74. * Dereference an existing alias so that we don't create a chain
  75. * of aliases. With this code, we guarantee that an alias is
  76. * always exactly one level of indirection away from the
  77. * actual aliased name.
  78. */
  79. target_node =
  80. ACPI_CAST_PTR(struct acpi_namespace_node,
  81. target_node->object);
  82. }
  83. /*
  84. * For objects that can never change (i.e., the NS node will
  85. * permanently point to the same object), we can simply attach
  86. * the object to the new NS node. For other objects (such as
  87. * Integers, buffers, etc.), we have to point the Alias node
  88. * to the original Node.
  89. */
  90. switch (target_node->type) {
  91. /* For these types, the sub-object can change dynamically via a Store */
  92. case ACPI_TYPE_INTEGER:
  93. case ACPI_TYPE_STRING:
  94. case ACPI_TYPE_BUFFER:
  95. case ACPI_TYPE_PACKAGE:
  96. case ACPI_TYPE_BUFFER_FIELD:
  97. /*
  98. * These types open a new scope, so we need the NS node in order to access
  99. * any children.
  100. */
  101. case ACPI_TYPE_DEVICE:
  102. case ACPI_TYPE_POWER:
  103. case ACPI_TYPE_PROCESSOR:
  104. case ACPI_TYPE_THERMAL:
  105. case ACPI_TYPE_LOCAL_SCOPE:
  106. /*
  107. * The new alias has the type ALIAS and points to the original
  108. * NS node, not the object itself.
  109. */
  110. alias_node->type = ACPI_TYPE_LOCAL_ALIAS;
  111. alias_node->object =
  112. ACPI_CAST_PTR(union acpi_operand_object, target_node);
  113. break;
  114. case ACPI_TYPE_METHOD:
  115. /*
  116. * Control method aliases need to be differentiated
  117. */
  118. alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
  119. alias_node->object =
  120. ACPI_CAST_PTR(union acpi_operand_object, target_node);
  121. break;
  122. default:
  123. /* Attach the original source object to the new Alias Node */
  124. /*
  125. * The new alias assumes the type of the target, and it points
  126. * to the same object. The reference count of the object has an
  127. * additional reference to prevent deletion out from under either the
  128. * target node or the alias Node
  129. */
  130. status = acpi_ns_attach_object(alias_node,
  131. acpi_ns_get_attached_object
  132. (target_node),
  133. target_node->type);
  134. break;
  135. }
  136. /* Since both operands are Nodes, we don't need to delete them */
  137. return_ACPI_STATUS(status);
  138. }
  139. /*******************************************************************************
  140. *
  141. * FUNCTION: acpi_ex_create_event
  142. *
  143. * PARAMETERS: walk_state - Current state
  144. *
  145. * RETURN: Status
  146. *
  147. * DESCRIPTION: Create a new event object
  148. *
  149. ******************************************************************************/
  150. acpi_status acpi_ex_create_event(struct acpi_walk_state *walk_state)
  151. {
  152. acpi_status status;
  153. union acpi_operand_object *obj_desc;
  154. ACPI_FUNCTION_TRACE(ex_create_event);
  155. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_EVENT);
  156. if (!obj_desc) {
  157. status = AE_NO_MEMORY;
  158. goto cleanup;
  159. }
  160. /*
  161. * Create the actual OS semaphore, with zero initial units -- meaning
  162. * that the event is created in an unsignalled state
  163. */
  164. status = acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0,
  165. &obj_desc->event.os_semaphore);
  166. if (ACPI_FAILURE(status)) {
  167. goto cleanup;
  168. }
  169. /* Attach object to the Node */
  170. status =
  171. acpi_ns_attach_object((struct acpi_namespace_node *)walk_state->
  172. operands[0], obj_desc, ACPI_TYPE_EVENT);
  173. cleanup:
  174. /*
  175. * Remove local reference to the object (on error, will cause deletion
  176. * of both object and semaphore if present.)
  177. */
  178. acpi_ut_remove_reference(obj_desc);
  179. return_ACPI_STATUS(status);
  180. }
  181. /*******************************************************************************
  182. *
  183. * FUNCTION: acpi_ex_create_mutex
  184. *
  185. * PARAMETERS: walk_state - Current state
  186. *
  187. * RETURN: Status
  188. *
  189. * DESCRIPTION: Create a new mutex object
  190. *
  191. * Mutex (Name[0], sync_level[1])
  192. *
  193. ******************************************************************************/
  194. acpi_status acpi_ex_create_mutex(struct acpi_walk_state *walk_state)
  195. {
  196. acpi_status status = AE_OK;
  197. union acpi_operand_object *obj_desc;
  198. ACPI_FUNCTION_TRACE_PTR(ex_create_mutex, ACPI_WALK_OPERANDS);
  199. /* Create the new mutex object */
  200. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX);
  201. if (!obj_desc) {
  202. status = AE_NO_MEMORY;
  203. goto cleanup;
  204. }
  205. /* Create the actual OS Mutex */
  206. status = acpi_os_create_mutex(&obj_desc->mutex.os_mutex);
  207. if (ACPI_FAILURE(status)) {
  208. goto cleanup;
  209. }
  210. /* Init object and attach to NS node */
  211. obj_desc->mutex.sync_level =
  212. (u8) walk_state->operands[1]->integer.value;
  213. obj_desc->mutex.node =
  214. (struct acpi_namespace_node *)walk_state->operands[0];
  215. status =
  216. acpi_ns_attach_object(obj_desc->mutex.node, obj_desc,
  217. ACPI_TYPE_MUTEX);
  218. cleanup:
  219. /*
  220. * Remove local reference to the object (on error, will cause deletion
  221. * of both object and semaphore if present.)
  222. */
  223. acpi_ut_remove_reference(obj_desc);
  224. return_ACPI_STATUS(status);
  225. }
  226. /*******************************************************************************
  227. *
  228. * FUNCTION: acpi_ex_create_region
  229. *
  230. * PARAMETERS: aml_start - Pointer to the region declaration AML
  231. * aml_length - Max length of the declaration AML
  232. * region_space - space_iD for the region
  233. * walk_state - Current state
  234. *
  235. * RETURN: Status
  236. *
  237. * DESCRIPTION: Create a new operation region object
  238. *
  239. ******************************************************************************/
  240. acpi_status
  241. acpi_ex_create_region(u8 * aml_start,
  242. u32 aml_length,
  243. u8 region_space, struct acpi_walk_state *walk_state)
  244. {
  245. acpi_status status;
  246. union acpi_operand_object *obj_desc;
  247. struct acpi_namespace_node *node;
  248. union acpi_operand_object *region_obj2;
  249. ACPI_FUNCTION_TRACE(ex_create_region);
  250. /* Get the Namespace Node */
  251. node = walk_state->op->common.node;
  252. /*
  253. * If the region object is already attached to this node,
  254. * just return
  255. */
  256. if (acpi_ns_get_attached_object(node)) {
  257. return_ACPI_STATUS(AE_OK);
  258. }
  259. /*
  260. * Space ID must be one of the predefined IDs, or in the user-defined
  261. * range
  262. */
  263. if ((region_space >= ACPI_NUM_PREDEFINED_REGIONS) &&
  264. (region_space < ACPI_USER_REGION_BEGIN)) {
  265. ACPI_ERROR((AE_INFO, "Invalid AddressSpace type %X",
  266. region_space));
  267. return_ACPI_STATUS(AE_AML_INVALID_SPACE_ID);
  268. }
  269. ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Region Type - %s (%X)\n",
  270. acpi_ut_get_region_name(region_space), region_space));
  271. /* Create the region descriptor */
  272. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION);
  273. if (!obj_desc) {
  274. status = AE_NO_MEMORY;
  275. goto cleanup;
  276. }
  277. /*
  278. * Remember location in AML stream of address & length
  279. * operands since they need to be evaluated at run time.
  280. */
  281. region_obj2 = obj_desc->common.next_object;
  282. region_obj2->extra.aml_start = aml_start;
  283. region_obj2->extra.aml_length = aml_length;
  284. /* Init the region from the operands */
  285. obj_desc->region.space_id = region_space;
  286. obj_desc->region.address = 0;
  287. obj_desc->region.length = 0;
  288. obj_desc->region.node = node;
  289. /* Install the new region object in the parent Node */
  290. status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_REGION);
  291. cleanup:
  292. /* Remove local reference to the object */
  293. acpi_ut_remove_reference(obj_desc);
  294. return_ACPI_STATUS(status);
  295. }
  296. /*******************************************************************************
  297. *
  298. * FUNCTION: acpi_ex_create_processor
  299. *
  300. * PARAMETERS: walk_state - Current state
  301. *
  302. * RETURN: Status
  303. *
  304. * DESCRIPTION: Create a new processor object and populate the fields
  305. *
  306. * Processor (Name[0], cpu_iD[1], pblock_addr[2], pblock_length[3])
  307. *
  308. ******************************************************************************/
  309. acpi_status acpi_ex_create_processor(struct acpi_walk_state *walk_state)
  310. {
  311. union acpi_operand_object **operand = &walk_state->operands[0];
  312. union acpi_operand_object *obj_desc;
  313. acpi_status status;
  314. ACPI_FUNCTION_TRACE_PTR(ex_create_processor, walk_state);
  315. /* Create the processor object */
  316. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PROCESSOR);
  317. if (!obj_desc) {
  318. return_ACPI_STATUS(AE_NO_MEMORY);
  319. }
  320. /* Initialize the processor object from the operands */
  321. obj_desc->processor.proc_id = (u8) operand[1]->integer.value;
  322. obj_desc->processor.length = (u8) operand[3]->integer.value;
  323. obj_desc->processor.address =
  324. (acpi_io_address) operand[2]->integer.value;
  325. /* Install the processor object in the parent Node */
  326. status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
  327. obj_desc, ACPI_TYPE_PROCESSOR);
  328. /* Remove local reference to the object */
  329. acpi_ut_remove_reference(obj_desc);
  330. return_ACPI_STATUS(status);
  331. }
  332. /*******************************************************************************
  333. *
  334. * FUNCTION: acpi_ex_create_power_resource
  335. *
  336. * PARAMETERS: walk_state - Current state
  337. *
  338. * RETURN: Status
  339. *
  340. * DESCRIPTION: Create a new power_resource object and populate the fields
  341. *
  342. * power_resource (Name[0], system_level[1], resource_order[2])
  343. *
  344. ******************************************************************************/
  345. acpi_status acpi_ex_create_power_resource(struct acpi_walk_state *walk_state)
  346. {
  347. union acpi_operand_object **operand = &walk_state->operands[0];
  348. acpi_status status;
  349. union acpi_operand_object *obj_desc;
  350. ACPI_FUNCTION_TRACE_PTR(ex_create_power_resource, walk_state);
  351. /* Create the power resource object */
  352. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_POWER);
  353. if (!obj_desc) {
  354. return_ACPI_STATUS(AE_NO_MEMORY);
  355. }
  356. /* Initialize the power object from the operands */
  357. obj_desc->power_resource.system_level = (u8) operand[1]->integer.value;
  358. obj_desc->power_resource.resource_order =
  359. (u16) operand[2]->integer.value;
  360. /* Install the power resource object in the parent Node */
  361. status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
  362. obj_desc, ACPI_TYPE_POWER);
  363. /* Remove local reference to the object */
  364. acpi_ut_remove_reference(obj_desc);
  365. return_ACPI_STATUS(status);
  366. }
  367. #endif
  368. /*******************************************************************************
  369. *
  370. * FUNCTION: acpi_ex_create_method
  371. *
  372. * PARAMETERS: aml_start - First byte of the method's AML
  373. * aml_length - AML byte count for this method
  374. * walk_state - Current state
  375. *
  376. * RETURN: Status
  377. *
  378. * DESCRIPTION: Create a new method object
  379. *
  380. ******************************************************************************/
  381. acpi_status
  382. acpi_ex_create_method(u8 * aml_start,
  383. u32 aml_length, struct acpi_walk_state *walk_state)
  384. {
  385. union acpi_operand_object **operand = &walk_state->operands[0];
  386. union acpi_operand_object *obj_desc;
  387. acpi_status status;
  388. u8 method_flags;
  389. ACPI_FUNCTION_TRACE_PTR(ex_create_method, walk_state);
  390. /* Create a new method object */
  391. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
  392. if (!obj_desc) {
  393. status = AE_NO_MEMORY;
  394. goto exit;
  395. }
  396. /* Save the method's AML pointer and length */
  397. obj_desc->method.aml_start = aml_start;
  398. obj_desc->method.aml_length = aml_length;
  399. /*
  400. * Disassemble the method flags. Split off the Arg Count
  401. * for efficiency
  402. */
  403. method_flags = (u8) operand[1]->integer.value;
  404. obj_desc->method.method_flags =
  405. (u8) (method_flags & ~AML_METHOD_ARG_COUNT);
  406. obj_desc->method.param_count =
  407. (u8) (method_flags & AML_METHOD_ARG_COUNT);
  408. /*
  409. * Get the sync_level. If method is serialized, a mutex will be
  410. * created for this method when it is parsed.
  411. */
  412. if (method_flags & AML_METHOD_SERIALIZED) {
  413. /*
  414. * ACPI 1.0: sync_level = 0
  415. * ACPI 2.0: sync_level = sync_level in method declaration
  416. */
  417. obj_desc->method.sync_level = (u8)
  418. ((method_flags & AML_METHOD_SYNCH_LEVEL) >> 4);
  419. }
  420. /* Attach the new object to the method Node */
  421. status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
  422. obj_desc, ACPI_TYPE_METHOD);
  423. /* Remove local reference to the object */
  424. acpi_ut_remove_reference(obj_desc);
  425. exit:
  426. /* Remove a reference to the operand */
  427. acpi_ut_remove_reference(operand[1]);
  428. return_ACPI_STATUS(status);
  429. }