excreate.c 13 KB

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