utxface.c 18 KB

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