utxface.c 14 KB

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