utxface.c 15 KB

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