utxface.c 16 KB

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