utxface.c 14 KB

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