utxface.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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, "[Init] Initializing ACPI hardware\n"));
  124. status = acpi_hw_initialize ();
  125. if (ACPI_FAILURE (status)) {
  126. return_ACPI_STATUS (status);
  127. }
  128. }
  129. /* Enable ACPI mode */
  130. if (!(flags & ACPI_NO_ACPI_ENABLE)) {
  131. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Going into ACPI mode\n"));
  132. acpi_gbl_original_mode = acpi_hw_get_mode();
  133. status = acpi_enable ();
  134. if (ACPI_FAILURE (status)) {
  135. ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "acpi_enable failed.\n"));
  136. return_ACPI_STATUS (status);
  137. }
  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, "[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. * NOTE: We must have the hardware AND events initialized before we can execute
  155. * ANY control methods SAFELY. Any control method can require ACPI hardware
  156. * support, so the hardware MUST be initialized before execution!
  157. */
  158. if (!(flags & ACPI_NO_EVENT_INIT)) {
  159. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Initializing ACPI events\n"));
  160. status = acpi_ev_initialize_events ();
  161. if (ACPI_FAILURE (status)) {
  162. return_ACPI_STATUS (status);
  163. }
  164. }
  165. /* Install the SCI handler and Global Lock handler */
  166. if (!(flags & ACPI_NO_HANDLER_INIT)) {
  167. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Installing SCI/GL handlers\n"));
  168. status = acpi_ev_install_xrupt_handlers ();
  169. if (ACPI_FAILURE (status)) {
  170. return_ACPI_STATUS (status);
  171. }
  172. }
  173. return_ACPI_STATUS (status);
  174. }
  175. /*******************************************************************************
  176. *
  177. * FUNCTION: acpi_initialize_objects
  178. *
  179. * PARAMETERS: Flags - Init/enable Options
  180. *
  181. * RETURN: Status
  182. *
  183. * DESCRIPTION: Completes namespace initialization by initializing device
  184. * objects and executing AML code for Regions, buffers, etc.
  185. *
  186. ******************************************************************************/
  187. acpi_status
  188. acpi_initialize_objects (
  189. u32 flags)
  190. {
  191. acpi_status status = AE_OK;
  192. ACPI_FUNCTION_TRACE ("acpi_initialize_objects");
  193. /*
  194. * Run all _REG methods
  195. *
  196. * NOTE: Any objects accessed
  197. * by the _REG methods will be automatically initialized, even if they
  198. * contain executable AML (see call to acpi_ns_initialize_objects below).
  199. */
  200. if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
  201. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Executing _REG op_region methods\n"));
  202. status = acpi_ev_initialize_op_regions ();
  203. if (ACPI_FAILURE (status)) {
  204. return_ACPI_STATUS (status);
  205. }
  206. }
  207. /*
  208. * Initialize the objects that remain uninitialized. This
  209. * runs the executable AML that may be part of the declaration of these
  210. * objects: operation_regions, buffer_fields, Buffers, and Packages.
  211. */
  212. if (!(flags & ACPI_NO_OBJECT_INIT)) {
  213. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Completing Initialization of ACPI Objects\n"));
  214. status = acpi_ns_initialize_objects ();
  215. if (ACPI_FAILURE (status)) {
  216. return_ACPI_STATUS (status);
  217. }
  218. }
  219. /*
  220. * Initialize all device objects in the namespace
  221. * This runs the _STA and _INI methods.
  222. */
  223. if (!(flags & ACPI_NO_DEVICE_INIT)) {
  224. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Initializing ACPI Devices\n"));
  225. status = acpi_ns_initialize_devices ();
  226. if (ACPI_FAILURE (status)) {
  227. return_ACPI_STATUS (status);
  228. }
  229. }
  230. /*
  231. * Empty the caches (delete the cached objects) on the assumption that
  232. * the table load filled them up more than they will be at runtime --
  233. * thus wasting non-paged memory.
  234. */
  235. status = acpi_purge_cached_objects ();
  236. acpi_gbl_startup_flags |= ACPI_INITIALIZED_OK;
  237. return_ACPI_STATUS (status);
  238. }
  239. /*******************************************************************************
  240. *
  241. * FUNCTION: acpi_terminate
  242. *
  243. * PARAMETERS: None
  244. *
  245. * RETURN: Status
  246. *
  247. * DESCRIPTION: Shutdown the ACPI subsystem. Release all resources.
  248. *
  249. ******************************************************************************/
  250. acpi_status
  251. acpi_terminate (void)
  252. {
  253. acpi_status status;
  254. ACPI_FUNCTION_TRACE ("acpi_terminate");
  255. /* Terminate the AML Debugger if present */
  256. ACPI_DEBUGGER_EXEC(acpi_gbl_db_terminate_threads = TRUE);
  257. /* Shutdown and free all resources */
  258. acpi_ut_subsystem_shutdown ();
  259. /* Free the mutex objects */
  260. acpi_ut_mutex_terminate ();
  261. #ifdef ACPI_DEBUGGER
  262. /* Shut down the debugger */
  263. acpi_db_terminate ();
  264. #endif
  265. /* Now we can shutdown the OS-dependent layer */
  266. status = acpi_os_terminate ();
  267. return_ACPI_STATUS (status);
  268. }
  269. #ifdef ACPI_FUTURE_USAGE
  270. /*****************************************************************************
  271. *
  272. * FUNCTION: acpi_subsystem_status
  273. *
  274. * PARAMETERS: None
  275. *
  276. * RETURN: Status of the ACPI subsystem
  277. *
  278. * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
  279. * before making any other calls, to ensure the subsystem initial-
  280. * ized successfully.
  281. *
  282. ****************************************************************************/
  283. acpi_status
  284. acpi_subsystem_status (void)
  285. {
  286. if (acpi_gbl_startup_flags & ACPI_INITIALIZED_OK) {
  287. return (AE_OK);
  288. }
  289. else {
  290. return (AE_ERROR);
  291. }
  292. }
  293. /******************************************************************************
  294. *
  295. * FUNCTION: acpi_get_system_info
  296. *
  297. * PARAMETERS: out_buffer - a pointer to a buffer to receive the
  298. * resources for the device
  299. * buffer_length - the number of bytes available in the buffer
  300. *
  301. * RETURN: Status - the status of the call
  302. *
  303. * DESCRIPTION: This function is called to get information about the current
  304. * state of the ACPI subsystem. It will return system information
  305. * in the out_buffer.
  306. *
  307. * If the function fails an appropriate status will be returned
  308. * and the value of out_buffer is undefined.
  309. *
  310. ******************************************************************************/
  311. acpi_status
  312. acpi_get_system_info (
  313. struct acpi_buffer *out_buffer)
  314. {
  315. struct acpi_system_info *info_ptr;
  316. u32 i;
  317. acpi_status status;
  318. ACPI_FUNCTION_TRACE ("acpi_get_system_info");
  319. /* Parameter validation */
  320. status = acpi_ut_validate_buffer (out_buffer);
  321. if (ACPI_FAILURE (status)) {
  322. return_ACPI_STATUS (status);
  323. }
  324. /* Validate/Allocate/Clear caller buffer */
  325. status = acpi_ut_initialize_buffer (out_buffer, sizeof (struct acpi_system_info));
  326. if (ACPI_FAILURE (status)) {
  327. return_ACPI_STATUS (status);
  328. }
  329. /*
  330. * Populate the return buffer
  331. */
  332. info_ptr = (struct acpi_system_info *) out_buffer->pointer;
  333. info_ptr->acpi_ca_version = ACPI_CA_VERSION;
  334. /* System flags (ACPI capabilities) */
  335. info_ptr->flags = ACPI_SYS_MODE_ACPI;
  336. /* Timer resolution - 24 or 32 bits */
  337. if (!acpi_gbl_FADT) {
  338. info_ptr->timer_resolution = 0;
  339. }
  340. else if (acpi_gbl_FADT->tmr_val_ext == 0) {
  341. info_ptr->timer_resolution = 24;
  342. }
  343. else {
  344. info_ptr->timer_resolution = 32;
  345. }
  346. /* Clear the reserved fields */
  347. info_ptr->reserved1 = 0;
  348. info_ptr->reserved2 = 0;
  349. /* Current debug levels */
  350. info_ptr->debug_layer = acpi_dbg_layer;
  351. info_ptr->debug_level = acpi_dbg_level;
  352. /* Current status of the ACPI tables, per table type */
  353. info_ptr->num_table_types = NUM_ACPI_TABLE_TYPES;
  354. for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++) {
  355. info_ptr->table_info[i].count = acpi_gbl_table_lists[i].count;
  356. }
  357. return_ACPI_STATUS (AE_OK);
  358. }
  359. EXPORT_SYMBOL(acpi_get_system_info);
  360. /*****************************************************************************
  361. *
  362. * FUNCTION: acpi_install_initialization_handler
  363. *
  364. * PARAMETERS: Handler - Callback procedure
  365. *
  366. * RETURN: Status
  367. *
  368. * DESCRIPTION: Install an initialization handler
  369. *
  370. * TBD: When a second function is added, must save the Function also.
  371. *
  372. ****************************************************************************/
  373. acpi_status
  374. acpi_install_initialization_handler (
  375. acpi_init_handler handler,
  376. u32 function)
  377. {
  378. if (!handler) {
  379. return (AE_BAD_PARAMETER);
  380. }
  381. if (acpi_gbl_init_handler) {
  382. return (AE_ALREADY_EXISTS);
  383. }
  384. acpi_gbl_init_handler = handler;
  385. return AE_OK;
  386. }
  387. #endif /* ACPI_FUTURE_USAGE */
  388. /*****************************************************************************
  389. *
  390. * FUNCTION: acpi_purge_cached_objects
  391. *
  392. * PARAMETERS: None
  393. *
  394. * RETURN: Status
  395. *
  396. * DESCRIPTION: Empty all caches (delete the cached objects)
  397. *
  398. ****************************************************************************/
  399. acpi_status
  400. acpi_purge_cached_objects (void)
  401. {
  402. ACPI_FUNCTION_TRACE ("acpi_purge_cached_objects");
  403. #ifdef ACPI_ENABLE_OBJECT_CACHE
  404. acpi_ut_delete_generic_state_cache ();
  405. acpi_ut_delete_object_cache ();
  406. acpi_ds_delete_walk_state_cache ();
  407. acpi_ps_delete_parse_cache ();
  408. #endif
  409. return_ACPI_STATUS (AE_OK);
  410. }