utxface.c 15 KB

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