utxface.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /******************************************************************************
  2. *
  3. * Module Name: utxface - External interfaces for "global" ACPI functions
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, 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 <acpi/acevents.h>
  44. #include <acpi/acnamesp.h>
  45. #include <acpi/acdebug.h>
  46. #define _COMPONENT ACPI_UTILITIES
  47. ACPI_MODULE_NAME("utxface")
  48. #ifndef ACPI_ASL_COMPILER
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_initialize_subsystem
  52. *
  53. * PARAMETERS: None
  54. *
  55. * RETURN: Status
  56. *
  57. * DESCRIPTION: Initializes all global variables. This is the first function
  58. * called, so any early initialization belongs here.
  59. *
  60. ******************************************************************************/
  61. acpi_status __init acpi_initialize_subsystem(void)
  62. {
  63. acpi_status status;
  64. ACPI_FUNCTION_TRACE(acpi_initialize_subsystem);
  65. acpi_gbl_startup_flags = ACPI_SUBSYSTEM_INITIALIZE;
  66. ACPI_DEBUG_EXEC(acpi_ut_init_stack_ptr_trace());
  67. /* Initialize the OS-Dependent layer */
  68. status = acpi_os_initialize();
  69. if (ACPI_FAILURE(status)) {
  70. ACPI_EXCEPTION((AE_INFO, status, "During OSL initialization"));
  71. return_ACPI_STATUS(status);
  72. }
  73. /* Initialize all globals used by the subsystem */
  74. acpi_ut_init_globals();
  75. /* Create the default mutex objects */
  76. status = acpi_ut_mutex_initialize();
  77. if (ACPI_FAILURE(status)) {
  78. ACPI_EXCEPTION((AE_INFO, status,
  79. "During Global Mutex creation"));
  80. return_ACPI_STATUS(status);
  81. }
  82. /*
  83. * Initialize the namespace manager and
  84. * the root of the namespace tree
  85. */
  86. status = acpi_ns_root_initialize();
  87. if (ACPI_FAILURE(status)) {
  88. ACPI_EXCEPTION((AE_INFO, status,
  89. "During Namespace initialization"));
  90. return_ACPI_STATUS(status);
  91. }
  92. /* If configured, initialize the AML debugger */
  93. ACPI_DEBUGGER_EXEC(status = acpi_db_initialize());
  94. return_ACPI_STATUS(status);
  95. }
  96. /*******************************************************************************
  97. *
  98. * FUNCTION: acpi_enable_subsystem
  99. *
  100. * PARAMETERS: Flags - Init/enable Options
  101. *
  102. * RETURN: Status
  103. *
  104. * DESCRIPTION: Completes the subsystem initialization including hardware.
  105. * Puts system into ACPI mode if it isn't already.
  106. *
  107. ******************************************************************************/
  108. acpi_status acpi_enable_subsystem(u32 flags)
  109. {
  110. acpi_status status = AE_OK;
  111. ACPI_FUNCTION_TRACE(acpi_enable_subsystem);
  112. /* Enable ACPI mode */
  113. if (!(flags & ACPI_NO_ACPI_ENABLE)) {
  114. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  115. "[Init] Going into ACPI mode\n"));
  116. acpi_gbl_original_mode = acpi_hw_get_mode();
  117. status = acpi_enable();
  118. if (ACPI_FAILURE(status)) {
  119. ACPI_WARNING((AE_INFO, "AcpiEnable failed"));
  120. return_ACPI_STATUS(status);
  121. }
  122. }
  123. /*
  124. * Install the default op_region handlers. These are installed unless
  125. * other handlers have already been installed via the
  126. * install_address_space_handler interface.
  127. */
  128. if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
  129. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  130. "[Init] Installing default address space handlers\n"));
  131. status = acpi_ev_install_region_handlers();
  132. if (ACPI_FAILURE(status)) {
  133. return_ACPI_STATUS(status);
  134. }
  135. }
  136. /*
  137. * Initialize ACPI Event handling (Fixed and General Purpose)
  138. *
  139. * Note1: We must have the hardware and events initialized before we can
  140. * execute any control methods safely. Any control method can require
  141. * ACPI hardware support, so the hardware must be fully initialized before
  142. * any method execution!
  143. *
  144. * Note2: Fixed events are initialized and enabled here. GPEs are
  145. * initialized, but cannot be enabled until after the hardware is
  146. * completely initialized (SCI and global_lock activated)
  147. */
  148. if (!(flags & ACPI_NO_EVENT_INIT)) {
  149. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  150. "[Init] Initializing ACPI events\n"));
  151. status = acpi_ev_initialize_events();
  152. if (ACPI_FAILURE(status)) {
  153. return_ACPI_STATUS(status);
  154. }
  155. }
  156. /*
  157. * Install the SCI handler and Global Lock handler. This completes the
  158. * hardware initialization.
  159. */
  160. if (!(flags & ACPI_NO_HANDLER_INIT)) {
  161. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  162. "[Init] Installing SCI/GL handlers\n"));
  163. status = acpi_ev_install_xrupt_handlers();
  164. if (ACPI_FAILURE(status)) {
  165. return_ACPI_STATUS(status);
  166. }
  167. }
  168. return_ACPI_STATUS(status);
  169. }
  170. ACPI_EXPORT_SYMBOL(acpi_enable_subsystem)
  171. /*******************************************************************************
  172. *
  173. * FUNCTION: acpi_initialize_objects
  174. *
  175. * PARAMETERS: Flags - Init/enable Options
  176. *
  177. * RETURN: Status
  178. *
  179. * DESCRIPTION: Completes namespace initialization by initializing device
  180. * objects and executing AML code for Regions, buffers, etc.
  181. *
  182. ******************************************************************************/
  183. acpi_status acpi_initialize_objects(u32 flags)
  184. {
  185. acpi_status status = AE_OK;
  186. ACPI_FUNCTION_TRACE(acpi_initialize_objects);
  187. /*
  188. * Run all _REG methods
  189. *
  190. * Note: Any objects accessed by the _REG methods will be automatically
  191. * initialized, even if they contain executable AML (see the call to
  192. * acpi_ns_initialize_objects below).
  193. */
  194. if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
  195. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  196. "[Init] Executing _REG OpRegion methods\n"));
  197. status = acpi_ev_initialize_op_regions();
  198. if (ACPI_FAILURE(status)) {
  199. return_ACPI_STATUS(status);
  200. }
  201. }
  202. /*
  203. * Initialize the objects that remain uninitialized. This runs the
  204. * executable AML that may be part of the declaration of these objects:
  205. * operation_regions, buffer_fields, Buffers, and Packages.
  206. */
  207. if (!(flags & ACPI_NO_OBJECT_INIT)) {
  208. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  209. "[Init] Completing Initialization of ACPI Objects\n"));
  210. status = acpi_ns_initialize_objects();
  211. if (ACPI_FAILURE(status)) {
  212. return_ACPI_STATUS(status);
  213. }
  214. }
  215. /*
  216. * Initialize all device objects in the namespace. This runs the device
  217. * _STA and _INI methods.
  218. */
  219. if (!(flags & ACPI_NO_DEVICE_INIT)) {
  220. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  221. "[Init] Initializing ACPI Devices\n"));
  222. status = acpi_ns_initialize_devices();
  223. if (ACPI_FAILURE(status)) {
  224. return_ACPI_STATUS(status);
  225. }
  226. }
  227. /*
  228. * Complete the GPE initialization for the GPE blocks defined in the FADT
  229. * (GPE block 0 and 1).
  230. *
  231. * Note1: This is where the _PRW methods are executed for the GPEs. These
  232. * methods can only be executed after the SCI and Global Lock handlers are
  233. * installed and initialized.
  234. *
  235. * Note2: Currently, there seems to be no need to run the _REG methods
  236. * before execution of the _PRW methods and enabling of the GPEs.
  237. */
  238. if (!(flags & ACPI_NO_EVENT_INIT)) {
  239. status = acpi_ev_install_fadt_gpes();
  240. if (ACPI_FAILURE(status))
  241. return (status);
  242. }
  243. /*
  244. * Empty the caches (delete the cached objects) on the assumption that
  245. * the table load filled them up more than they will be at runtime --
  246. * thus wasting non-paged memory.
  247. */
  248. status = acpi_purge_cached_objects();
  249. acpi_gbl_startup_flags |= ACPI_INITIALIZED_OK;
  250. return_ACPI_STATUS(status);
  251. }
  252. ACPI_EXPORT_SYMBOL(acpi_initialize_objects)
  253. #endif
  254. /*******************************************************************************
  255. *
  256. * FUNCTION: acpi_terminate
  257. *
  258. * PARAMETERS: None
  259. *
  260. * RETURN: Status
  261. *
  262. * DESCRIPTION: Shutdown the ACPI subsystem. Release all resources.
  263. *
  264. ******************************************************************************/
  265. acpi_status acpi_terminate(void)
  266. {
  267. acpi_status status;
  268. ACPI_FUNCTION_TRACE(acpi_terminate);
  269. /* Terminate the AML Debugger if present */
  270. ACPI_DEBUGGER_EXEC(acpi_gbl_db_terminate_threads = TRUE);
  271. /* Shutdown and free all resources */
  272. acpi_ut_subsystem_shutdown();
  273. /* Free the mutex objects */
  274. acpi_ut_mutex_terminate();
  275. #ifdef ACPI_DEBUGGER
  276. /* Shut down the debugger */
  277. acpi_db_terminate();
  278. #endif
  279. /* Now we can shutdown the OS-dependent layer */
  280. status = acpi_os_terminate();
  281. return_ACPI_STATUS(status);
  282. }
  283. ACPI_EXPORT_SYMBOL(acpi_terminate)
  284. #ifndef ACPI_ASL_COMPILER
  285. #ifdef ACPI_FUTURE_USAGE
  286. /*******************************************************************************
  287. *
  288. * FUNCTION: acpi_subsystem_status
  289. *
  290. * PARAMETERS: None
  291. *
  292. * RETURN: Status of the ACPI subsystem
  293. *
  294. * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
  295. * before making any other calls, to ensure the subsystem
  296. * initialized successfully.
  297. *
  298. ******************************************************************************/
  299. acpi_status acpi_subsystem_status(void)
  300. {
  301. if (acpi_gbl_startup_flags & ACPI_INITIALIZED_OK) {
  302. return (AE_OK);
  303. } else {
  304. return (AE_ERROR);
  305. }
  306. }
  307. ACPI_EXPORT_SYMBOL(acpi_subsystem_status)
  308. /*******************************************************************************
  309. *
  310. * FUNCTION: acpi_get_system_info
  311. *
  312. * PARAMETERS: out_buffer - A buffer to receive the resources for the
  313. * device
  314. *
  315. * RETURN: Status - the status of the call
  316. *
  317. * DESCRIPTION: This function is called to get information about the current
  318. * state of the ACPI subsystem. It will return system information
  319. * in the out_buffer.
  320. *
  321. * If the function fails an appropriate status will be returned
  322. * and the value of out_buffer is undefined.
  323. *
  324. ******************************************************************************/
  325. acpi_status acpi_get_system_info(struct acpi_buffer * out_buffer)
  326. {
  327. struct acpi_system_info *info_ptr;
  328. acpi_status status;
  329. ACPI_FUNCTION_TRACE(acpi_get_system_info);
  330. /* Parameter validation */
  331. status = acpi_ut_validate_buffer(out_buffer);
  332. if (ACPI_FAILURE(status)) {
  333. return_ACPI_STATUS(status);
  334. }
  335. /* Validate/Allocate/Clear caller buffer */
  336. status =
  337. acpi_ut_initialize_buffer(out_buffer,
  338. sizeof(struct acpi_system_info));
  339. if (ACPI_FAILURE(status)) {
  340. return_ACPI_STATUS(status);
  341. }
  342. /*
  343. * Populate the return buffer
  344. */
  345. info_ptr = (struct acpi_system_info *)out_buffer->pointer;
  346. info_ptr->acpi_ca_version = ACPI_CA_VERSION;
  347. /* System flags (ACPI capabilities) */
  348. info_ptr->flags = ACPI_SYS_MODE_ACPI;
  349. /* Timer resolution - 24 or 32 bits */
  350. if (acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER) {
  351. info_ptr->timer_resolution = 24;
  352. } else {
  353. info_ptr->timer_resolution = 32;
  354. }
  355. /* Clear the reserved fields */
  356. info_ptr->reserved1 = 0;
  357. info_ptr->reserved2 = 0;
  358. /* Current debug levels */
  359. info_ptr->debug_layer = acpi_dbg_layer;
  360. info_ptr->debug_level = acpi_dbg_level;
  361. return_ACPI_STATUS(AE_OK);
  362. }
  363. ACPI_EXPORT_SYMBOL(acpi_get_system_info)
  364. /*****************************************************************************
  365. *
  366. * FUNCTION: acpi_install_initialization_handler
  367. *
  368. * PARAMETERS: Handler - Callback procedure
  369. * Function - Not (currently) used, see below
  370. *
  371. * RETURN: Status
  372. *
  373. * DESCRIPTION: Install an initialization handler
  374. *
  375. * TBD: When a second function is added, must save the Function also.
  376. *
  377. ****************************************************************************/
  378. acpi_status
  379. acpi_install_initialization_handler(acpi_init_handler handler, u32 function)
  380. {
  381. if (!handler) {
  382. return (AE_BAD_PARAMETER);
  383. }
  384. if (acpi_gbl_init_handler) {
  385. return (AE_ALREADY_EXISTS);
  386. }
  387. acpi_gbl_init_handler = handler;
  388. return AE_OK;
  389. }
  390. ACPI_EXPORT_SYMBOL(acpi_install_initialization_handler)
  391. #endif /* ACPI_FUTURE_USAGE */
  392. /*****************************************************************************
  393. *
  394. * FUNCTION: acpi_purge_cached_objects
  395. *
  396. * PARAMETERS: None
  397. *
  398. * RETURN: Status
  399. *
  400. * DESCRIPTION: Empty all caches (delete the cached objects)
  401. *
  402. ****************************************************************************/
  403. acpi_status acpi_purge_cached_objects(void)
  404. {
  405. ACPI_FUNCTION_TRACE(acpi_purge_cached_objects);
  406. (void)acpi_os_purge_cache(acpi_gbl_state_cache);
  407. (void)acpi_os_purge_cache(acpi_gbl_operand_cache);
  408. (void)acpi_os_purge_cache(acpi_gbl_ps_node_cache);
  409. (void)acpi_os_purge_cache(acpi_gbl_ps_node_ext_cache);
  410. return_ACPI_STATUS(AE_OK);
  411. }
  412. ACPI_EXPORT_SYMBOL(acpi_purge_cached_objects)
  413. #endif