excreate.c 14 KB

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