utxface.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: utxface - External interfaces, miscellaneous utility functions
  5. *
  6. * Copyright (C) 2000 - 2022, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #define EXPORT_ACPI_INTERFACES
  10. #include <acpi/acpi.h>
  11. #include "accommon.h"
  12. #include "acdebug.h"
  13. #define _COMPONENT ACPI_UTILITIES
  14. ACPI_MODULE_NAME("utxface")
  15. /*******************************************************************************
  16. *
  17. * FUNCTION: acpi_terminate
  18. *
  19. * PARAMETERS: None
  20. *
  21. * RETURN: Status
  22. *
  23. * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
  24. *
  25. ******************************************************************************/
  26. acpi_status ACPI_INIT_FUNCTION acpi_terminate(void)
  27. {
  28. acpi_status status;
  29. ACPI_FUNCTION_TRACE(acpi_terminate);
  30. /* Shutdown and free all resources */
  31. acpi_ut_subsystem_shutdown();
  32. /* Free the mutex objects */
  33. acpi_ut_mutex_terminate();
  34. /* Now we can shutdown the OS-dependent layer */
  35. status = acpi_os_terminate();
  36. return_ACPI_STATUS(status);
  37. }
  38. ACPI_EXPORT_SYMBOL_INIT(acpi_terminate)
  39. #ifndef ACPI_ASL_COMPILER
  40. #ifdef ACPI_FUTURE_USAGE
  41. /*******************************************************************************
  42. *
  43. * FUNCTION: acpi_subsystem_status
  44. *
  45. * PARAMETERS: None
  46. *
  47. * RETURN: Status of the ACPI subsystem
  48. *
  49. * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
  50. * before making any other calls, to ensure the subsystem
  51. * initialized successfully.
  52. *
  53. ******************************************************************************/
  54. acpi_status acpi_subsystem_status(void)
  55. {
  56. if (acpi_gbl_startup_flags & ACPI_INITIALIZED_OK) {
  57. return (AE_OK);
  58. } else {
  59. return (AE_ERROR);
  60. }
  61. }
  62. ACPI_EXPORT_SYMBOL(acpi_subsystem_status)
  63. /*******************************************************************************
  64. *
  65. * FUNCTION: acpi_get_system_info
  66. *
  67. * PARAMETERS: out_buffer - A buffer to receive the resources for the
  68. * device
  69. *
  70. * RETURN: status - the status of the call
  71. *
  72. * DESCRIPTION: This function is called to get information about the current
  73. * state of the ACPI subsystem. It will return system information
  74. * in the out_buffer.
  75. *
  76. * If the function fails an appropriate status will be returned
  77. * and the value of out_buffer is undefined.
  78. *
  79. ******************************************************************************/
  80. acpi_status acpi_get_system_info(struct acpi_buffer *out_buffer)
  81. {
  82. struct acpi_system_info *info_ptr;
  83. acpi_status status;
  84. ACPI_FUNCTION_TRACE(acpi_get_system_info);
  85. /* Parameter validation */
  86. status = acpi_ut_validate_buffer(out_buffer);
  87. if (ACPI_FAILURE(status)) {
  88. return_ACPI_STATUS(status);
  89. }
  90. /* Validate/Allocate/Clear caller buffer */
  91. status =
  92. acpi_ut_initialize_buffer(out_buffer,
  93. sizeof(struct acpi_system_info));
  94. if (ACPI_FAILURE(status)) {
  95. return_ACPI_STATUS(status);
  96. }
  97. /*
  98. * Populate the return buffer
  99. */
  100. info_ptr = (struct acpi_system_info *)out_buffer->pointer;
  101. info_ptr->acpi_ca_version = ACPI_CA_VERSION;
  102. /* System flags (ACPI capabilities) */
  103. info_ptr->flags = ACPI_SYS_MODE_ACPI;
  104. /* Timer resolution - 24 or 32 bits */
  105. if (acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER) {
  106. info_ptr->timer_resolution = 24;
  107. } else {
  108. info_ptr->timer_resolution = 32;
  109. }
  110. /* Clear the reserved fields */
  111. info_ptr->reserved1 = 0;
  112. info_ptr->reserved2 = 0;
  113. /* Current debug levels */
  114. info_ptr->debug_layer = acpi_dbg_layer;
  115. info_ptr->debug_level = acpi_dbg_level;
  116. return_ACPI_STATUS(AE_OK);
  117. }
  118. ACPI_EXPORT_SYMBOL(acpi_get_system_info)
  119. /*******************************************************************************
  120. *
  121. * FUNCTION: acpi_get_statistics
  122. *
  123. * PARAMETERS: stats - Where the statistics are returned
  124. *
  125. * RETURN: status - the status of the call
  126. *
  127. * DESCRIPTION: Get the contents of the various system counters
  128. *
  129. ******************************************************************************/
  130. acpi_status acpi_get_statistics(struct acpi_statistics *stats)
  131. {
  132. ACPI_FUNCTION_TRACE(acpi_get_statistics);
  133. /* Parameter validation */
  134. if (!stats) {
  135. return_ACPI_STATUS(AE_BAD_PARAMETER);
  136. }
  137. /* Various interrupt-based event counters */
  138. stats->sci_count = acpi_sci_count;
  139. stats->gpe_count = acpi_gpe_count;
  140. memcpy(stats->fixed_event_count, acpi_fixed_event_count,
  141. sizeof(acpi_fixed_event_count));
  142. /* Other counters */
  143. stats->method_count = acpi_method_count;
  144. return_ACPI_STATUS(AE_OK);
  145. }
  146. ACPI_EXPORT_SYMBOL(acpi_get_statistics)
  147. /*****************************************************************************
  148. *
  149. * FUNCTION: acpi_install_initialization_handler
  150. *
  151. * PARAMETERS: handler - Callback procedure
  152. * function - Not (currently) used, see below
  153. *
  154. * RETURN: Status
  155. *
  156. * DESCRIPTION: Install an initialization handler
  157. *
  158. * TBD: When a second function is added, must save the Function also.
  159. *
  160. ****************************************************************************/
  161. acpi_status
  162. acpi_install_initialization_handler(acpi_init_handler handler, u32 function)
  163. {
  164. if (!handler) {
  165. return (AE_BAD_PARAMETER);
  166. }
  167. if (acpi_gbl_init_handler) {
  168. return (AE_ALREADY_EXISTS);
  169. }
  170. acpi_gbl_init_handler = handler;
  171. return (AE_OK);
  172. }
  173. ACPI_EXPORT_SYMBOL(acpi_install_initialization_handler)
  174. #endif
  175. /*****************************************************************************
  176. *
  177. * FUNCTION: acpi_purge_cached_objects
  178. *
  179. * PARAMETERS: None
  180. *
  181. * RETURN: Status
  182. *
  183. * DESCRIPTION: Empty all caches (delete the cached objects)
  184. *
  185. ****************************************************************************/
  186. acpi_status acpi_purge_cached_objects(void)
  187. {
  188. ACPI_FUNCTION_TRACE(acpi_purge_cached_objects);
  189. (void)acpi_os_purge_cache(acpi_gbl_state_cache);
  190. (void)acpi_os_purge_cache(acpi_gbl_operand_cache);
  191. (void)acpi_os_purge_cache(acpi_gbl_ps_node_cache);
  192. (void)acpi_os_purge_cache(acpi_gbl_ps_node_ext_cache);
  193. return_ACPI_STATUS(AE_OK);
  194. }
  195. ACPI_EXPORT_SYMBOL(acpi_purge_cached_objects)
  196. /*****************************************************************************
  197. *
  198. * FUNCTION: acpi_install_interface
  199. *
  200. * PARAMETERS: interface_name - The interface to install
  201. *
  202. * RETURN: Status
  203. *
  204. * DESCRIPTION: Install an _OSI interface to the global list
  205. *
  206. ****************************************************************************/
  207. acpi_status acpi_install_interface(acpi_string interface_name)
  208. {
  209. acpi_status status;
  210. struct acpi_interface_info *interface_info;
  211. /* Parameter validation */
  212. if (!interface_name || (strlen(interface_name) == 0)) {
  213. return (AE_BAD_PARAMETER);
  214. }
  215. status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
  216. if (ACPI_FAILURE(status)) {
  217. return (status);
  218. }
  219. /* Check if the interface name is already in the global list */
  220. interface_info = acpi_ut_get_interface(interface_name);
  221. if (interface_info) {
  222. /*
  223. * The interface already exists in the list. This is OK if the
  224. * interface has been marked invalid -- just clear the bit.
  225. */
  226. if (interface_info->flags & ACPI_OSI_INVALID) {
  227. interface_info->flags &= ~ACPI_OSI_INVALID;
  228. status = AE_OK;
  229. } else {
  230. status = AE_ALREADY_EXISTS;
  231. }
  232. } else {
  233. /* New interface name, install into the global list */
  234. status = acpi_ut_install_interface(interface_name);
  235. }
  236. acpi_os_release_mutex(acpi_gbl_osi_mutex);
  237. return (status);
  238. }
  239. ACPI_EXPORT_SYMBOL(acpi_install_interface)
  240. /*****************************************************************************
  241. *
  242. * FUNCTION: acpi_remove_interface
  243. *
  244. * PARAMETERS: interface_name - The interface to remove
  245. *
  246. * RETURN: Status
  247. *
  248. * DESCRIPTION: Remove an _OSI interface from the global list
  249. *
  250. ****************************************************************************/
  251. acpi_status acpi_remove_interface(acpi_string interface_name)
  252. {
  253. acpi_status status;
  254. /* Parameter validation */
  255. if (!interface_name || (strlen(interface_name) == 0)) {
  256. return (AE_BAD_PARAMETER);
  257. }
  258. status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
  259. if (ACPI_FAILURE(status)) {
  260. return (status);
  261. }
  262. status = acpi_ut_remove_interface(interface_name);
  263. acpi_os_release_mutex(acpi_gbl_osi_mutex);
  264. return (status);
  265. }
  266. ACPI_EXPORT_SYMBOL(acpi_remove_interface)
  267. /*****************************************************************************
  268. *
  269. * FUNCTION: acpi_install_interface_handler
  270. *
  271. * PARAMETERS: handler - The _OSI interface handler to install
  272. * NULL means "remove existing handler"
  273. *
  274. * RETURN: Status
  275. *
  276. * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
  277. * invoked during execution of the internal implementation of
  278. * _OSI. A NULL handler simply removes any existing handler.
  279. *
  280. ****************************************************************************/
  281. acpi_status acpi_install_interface_handler(acpi_interface_handler handler)
  282. {
  283. acpi_status status;
  284. status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
  285. if (ACPI_FAILURE(status)) {
  286. return (status);
  287. }
  288. if (handler && acpi_gbl_interface_handler) {
  289. status = AE_ALREADY_EXISTS;
  290. } else {
  291. acpi_gbl_interface_handler = handler;
  292. }
  293. acpi_os_release_mutex(acpi_gbl_osi_mutex);
  294. return (status);
  295. }
  296. ACPI_EXPORT_SYMBOL(acpi_install_interface_handler)
  297. /*****************************************************************************
  298. *
  299. * FUNCTION: acpi_update_interfaces
  300. *
  301. * PARAMETERS: action - Actions to be performed during the
  302. * update
  303. *
  304. * RETURN: Status
  305. *
  306. * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
  307. * string or/and feature group strings.
  308. *
  309. ****************************************************************************/
  310. acpi_status acpi_update_interfaces(u8 action)
  311. {
  312. acpi_status status;
  313. status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
  314. if (ACPI_FAILURE(status)) {
  315. return (status);
  316. }
  317. status = acpi_ut_update_interfaces(action);
  318. acpi_os_release_mutex(acpi_gbl_osi_mutex);
  319. return (status);
  320. }
  321. /*****************************************************************************
  322. *
  323. * FUNCTION: acpi_check_address_range
  324. *
  325. * PARAMETERS: space_id - Address space ID
  326. * address - Start address
  327. * length - Length
  328. * warn - TRUE if warning on overlap desired
  329. *
  330. * RETURN: Count of the number of conflicts detected.
  331. *
  332. * DESCRIPTION: Check if the input address range overlaps any of the
  333. * ASL operation region address ranges.
  334. *
  335. ****************************************************************************/
  336. u32
  337. acpi_check_address_range(acpi_adr_space_type space_id,
  338. acpi_physical_address address,
  339. acpi_size length, u8 warn)
  340. {
  341. u32 overlaps;
  342. acpi_status status;
  343. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  344. if (ACPI_FAILURE(status)) {
  345. return (0);
  346. }
  347. overlaps = acpi_ut_check_address_range(space_id, address,
  348. (u32)length, warn);
  349. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  350. return (overlaps);
  351. }
  352. ACPI_EXPORT_SYMBOL(acpi_check_address_range)
  353. #endif /* !ACPI_ASL_COMPILER */
  354. /*******************************************************************************
  355. *
  356. * FUNCTION: acpi_decode_pld_buffer
  357. *
  358. * PARAMETERS: in_buffer - Buffer returned by _PLD method
  359. * length - Length of the in_buffer
  360. * return_buffer - Where the decode buffer is returned
  361. *
  362. * RETURN: Status and the decoded _PLD buffer. User must deallocate
  363. * the buffer via ACPI_FREE.
  364. *
  365. * DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into
  366. * a local struct that is much more useful to an ACPI driver.
  367. *
  368. ******************************************************************************/
  369. acpi_status
  370. acpi_decode_pld_buffer(u8 *in_buffer,
  371. acpi_size length, struct acpi_pld_info **return_buffer)
  372. {
  373. struct acpi_pld_info *pld_info;
  374. u32 *buffer = ACPI_CAST_PTR(u32, in_buffer);
  375. u32 dword;
  376. /* Parameter validation */
  377. if (!in_buffer || !return_buffer
  378. || (length < ACPI_PLD_REV1_BUFFER_SIZE)) {
  379. return (AE_BAD_PARAMETER);
  380. }
  381. pld_info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pld_info));
  382. if (!pld_info) {
  383. return (AE_NO_MEMORY);
  384. }
  385. /* First 32-bit DWord */
  386. ACPI_MOVE_32_TO_32(&dword, &buffer[0]);
  387. pld_info->revision = ACPI_PLD_GET_REVISION(&dword);
  388. pld_info->ignore_color = ACPI_PLD_GET_IGNORE_COLOR(&dword);
  389. pld_info->red = ACPI_PLD_GET_RED(&dword);
  390. pld_info->green = ACPI_PLD_GET_GREEN(&dword);
  391. pld_info->blue = ACPI_PLD_GET_BLUE(&dword);
  392. /* Second 32-bit DWord */
  393. ACPI_MOVE_32_TO_32(&dword, &buffer[1]);
  394. pld_info->width = ACPI_PLD_GET_WIDTH(&dword);
  395. pld_info->height = ACPI_PLD_GET_HEIGHT(&dword);
  396. /* Third 32-bit DWord */
  397. ACPI_MOVE_32_TO_32(&dword, &buffer[2]);
  398. pld_info->user_visible = ACPI_PLD_GET_USER_VISIBLE(&dword);
  399. pld_info->dock = ACPI_PLD_GET_DOCK(&dword);
  400. pld_info->lid = ACPI_PLD_GET_LID(&dword);
  401. pld_info->panel = ACPI_PLD_GET_PANEL(&dword);
  402. pld_info->vertical_position = ACPI_PLD_GET_VERTICAL(&dword);
  403. pld_info->horizontal_position = ACPI_PLD_GET_HORIZONTAL(&dword);
  404. pld_info->shape = ACPI_PLD_GET_SHAPE(&dword);
  405. pld_info->group_orientation = ACPI_PLD_GET_ORIENTATION(&dword);
  406. pld_info->group_token = ACPI_PLD_GET_TOKEN(&dword);
  407. pld_info->group_position = ACPI_PLD_GET_POSITION(&dword);
  408. pld_info->bay = ACPI_PLD_GET_BAY(&dword);
  409. /* Fourth 32-bit DWord */
  410. ACPI_MOVE_32_TO_32(&dword, &buffer[3]);
  411. pld_info->ejectable = ACPI_PLD_GET_EJECTABLE(&dword);
  412. pld_info->ospm_eject_required = ACPI_PLD_GET_OSPM_EJECT(&dword);
  413. pld_info->cabinet_number = ACPI_PLD_GET_CABINET(&dword);
  414. pld_info->card_cage_number = ACPI_PLD_GET_CARD_CAGE(&dword);
  415. pld_info->reference = ACPI_PLD_GET_REFERENCE(&dword);
  416. pld_info->rotation = ACPI_PLD_GET_ROTATION(&dword);
  417. pld_info->order = ACPI_PLD_GET_ORDER(&dword);
  418. if (length >= ACPI_PLD_REV2_BUFFER_SIZE) {
  419. /* Fifth 32-bit DWord (Revision 2 of _PLD) */
  420. ACPI_MOVE_32_TO_32(&dword, &buffer[4]);
  421. pld_info->vertical_offset = ACPI_PLD_GET_VERT_OFFSET(&dword);
  422. pld_info->horizontal_offset = ACPI_PLD_GET_HORIZ_OFFSET(&dword);
  423. }
  424. *return_buffer = pld_info;
  425. return (AE_OK);
  426. }
  427. ACPI_EXPORT_SYMBOL(acpi_decode_pld_buffer)