utxface.c 14 KB

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