evxface.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. /******************************************************************************
  2. *
  3. * Module Name: evxface - External interfaces for ACPI events
  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 <linux/module.h>
  43. #include <acpi/acpi.h>
  44. #include <acpi/acnamesp.h>
  45. #include <acpi/acevents.h>
  46. #include <acpi/acinterp.h>
  47. #define _COMPONENT ACPI_EVENTS
  48. ACPI_MODULE_NAME("evxface")
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_install_exception_handler
  52. *
  53. * PARAMETERS: Handler - Pointer to the handler function for the
  54. * event
  55. *
  56. * RETURN: Status
  57. *
  58. * DESCRIPTION: Saves the pointer to the handler function
  59. *
  60. ******************************************************************************/
  61. #ifdef ACPI_FUTURE_USAGE
  62. acpi_status acpi_install_exception_handler(acpi_exception_handler handler)
  63. {
  64. acpi_status status;
  65. ACPI_FUNCTION_TRACE("acpi_install_exception_handler");
  66. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  67. if (ACPI_FAILURE(status)) {
  68. return_ACPI_STATUS(status);
  69. }
  70. /* Don't allow two handlers. */
  71. if (acpi_gbl_exception_handler) {
  72. status = AE_ALREADY_EXISTS;
  73. goto cleanup;
  74. }
  75. /* Install the handler */
  76. acpi_gbl_exception_handler = handler;
  77. cleanup:
  78. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  79. return_ACPI_STATUS(status);
  80. }
  81. #endif /* ACPI_FUTURE_USAGE */
  82. /*******************************************************************************
  83. *
  84. * FUNCTION: acpi_install_fixed_event_handler
  85. *
  86. * PARAMETERS: Event - Event type to enable.
  87. * Handler - Pointer to the handler function for the
  88. * event
  89. * Context - Value passed to the handler on each GPE
  90. *
  91. * RETURN: Status
  92. *
  93. * DESCRIPTION: Saves the pointer to the handler function and then enables the
  94. * event.
  95. *
  96. ******************************************************************************/
  97. acpi_status
  98. acpi_install_fixed_event_handler(u32 event,
  99. acpi_event_handler handler, void *context)
  100. {
  101. acpi_status status;
  102. ACPI_FUNCTION_TRACE("acpi_install_fixed_event_handler");
  103. /* Parameter validation */
  104. if (event > ACPI_EVENT_MAX) {
  105. return_ACPI_STATUS(AE_BAD_PARAMETER);
  106. }
  107. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  108. if (ACPI_FAILURE(status)) {
  109. return_ACPI_STATUS(status);
  110. }
  111. /* Don't allow two handlers. */
  112. if (NULL != acpi_gbl_fixed_event_handlers[event].handler) {
  113. status = AE_ALREADY_EXISTS;
  114. goto cleanup;
  115. }
  116. /* Install the handler before enabling the event */
  117. acpi_gbl_fixed_event_handlers[event].handler = handler;
  118. acpi_gbl_fixed_event_handlers[event].context = context;
  119. status = acpi_clear_event(event);
  120. if (ACPI_SUCCESS(status))
  121. status = acpi_enable_event(event, 0);
  122. if (ACPI_FAILURE(status)) {
  123. ACPI_REPORT_WARNING(("Could not enable fixed event %X\n",
  124. event));
  125. /* Remove the handler */
  126. acpi_gbl_fixed_event_handlers[event].handler = NULL;
  127. acpi_gbl_fixed_event_handlers[event].context = NULL;
  128. } else {
  129. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  130. "Enabled fixed event %X, Handler=%p\n", event,
  131. handler));
  132. }
  133. cleanup:
  134. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  135. return_ACPI_STATUS(status);
  136. }
  137. EXPORT_SYMBOL(acpi_install_fixed_event_handler);
  138. /*******************************************************************************
  139. *
  140. * FUNCTION: acpi_remove_fixed_event_handler
  141. *
  142. * PARAMETERS: Event - Event type to disable.
  143. * Handler - Address of the handler
  144. *
  145. * RETURN: Status
  146. *
  147. * DESCRIPTION: Disables the event and unregisters the event handler.
  148. *
  149. ******************************************************************************/
  150. acpi_status
  151. acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler)
  152. {
  153. acpi_status status = AE_OK;
  154. ACPI_FUNCTION_TRACE("acpi_remove_fixed_event_handler");
  155. /* Parameter validation */
  156. if (event > ACPI_EVENT_MAX) {
  157. return_ACPI_STATUS(AE_BAD_PARAMETER);
  158. }
  159. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  160. if (ACPI_FAILURE(status)) {
  161. return_ACPI_STATUS(status);
  162. }
  163. /* Disable the event before removing the handler */
  164. status = acpi_disable_event(event, 0);
  165. /* Always Remove the handler */
  166. acpi_gbl_fixed_event_handlers[event].handler = NULL;
  167. acpi_gbl_fixed_event_handlers[event].context = NULL;
  168. if (ACPI_FAILURE(status)) {
  169. ACPI_REPORT_WARNING(("Could not write to fixed event enable register %X\n", event));
  170. } else {
  171. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Disabled fixed event %X\n",
  172. event));
  173. }
  174. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  175. return_ACPI_STATUS(status);
  176. }
  177. EXPORT_SYMBOL(acpi_remove_fixed_event_handler);
  178. /*******************************************************************************
  179. *
  180. * FUNCTION: acpi_install_notify_handler
  181. *
  182. * PARAMETERS: Device - The device for which notifies will be handled
  183. * handler_type - The type of handler:
  184. * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
  185. * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
  186. * ACPI_ALL_NOTIFY: both system and device
  187. * Handler - Address of the handler
  188. * Context - Value passed to the handler on each GPE
  189. *
  190. * RETURN: Status
  191. *
  192. * DESCRIPTION: Install a handler for notifies on an ACPI device
  193. *
  194. ******************************************************************************/
  195. acpi_status
  196. acpi_install_notify_handler(acpi_handle device,
  197. u32 handler_type,
  198. acpi_notify_handler handler, void *context)
  199. {
  200. union acpi_operand_object *obj_desc;
  201. union acpi_operand_object *notify_obj;
  202. struct acpi_namespace_node *node;
  203. acpi_status status;
  204. ACPI_FUNCTION_TRACE("acpi_install_notify_handler");
  205. /* Parameter validation */
  206. if ((!device) ||
  207. (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
  208. return_ACPI_STATUS(AE_BAD_PARAMETER);
  209. }
  210. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  211. if (ACPI_FAILURE(status)) {
  212. return_ACPI_STATUS(status);
  213. }
  214. /* Convert and validate the device handle */
  215. node = acpi_ns_map_handle_to_node(device);
  216. if (!node) {
  217. status = AE_BAD_PARAMETER;
  218. goto unlock_and_exit;
  219. }
  220. /*
  221. * Root Object:
  222. * Registering a notify handler on the root object indicates that the
  223. * caller wishes to receive notifications for all objects. Note that
  224. * only one <external> global handler can be regsitered (per notify type).
  225. */
  226. if (device == ACPI_ROOT_OBJECT) {
  227. /* Make sure the handler is not already installed */
  228. if (((handler_type & ACPI_SYSTEM_NOTIFY) &&
  229. acpi_gbl_system_notify.handler) ||
  230. ((handler_type & ACPI_DEVICE_NOTIFY) &&
  231. acpi_gbl_device_notify.handler)) {
  232. status = AE_ALREADY_EXISTS;
  233. goto unlock_and_exit;
  234. }
  235. if (handler_type & ACPI_SYSTEM_NOTIFY) {
  236. acpi_gbl_system_notify.node = node;
  237. acpi_gbl_system_notify.handler = handler;
  238. acpi_gbl_system_notify.context = context;
  239. }
  240. if (handler_type & ACPI_DEVICE_NOTIFY) {
  241. acpi_gbl_device_notify.node = node;
  242. acpi_gbl_device_notify.handler = handler;
  243. acpi_gbl_device_notify.context = context;
  244. }
  245. /* Global notify handler installed */
  246. }
  247. /*
  248. * All Other Objects:
  249. * Caller will only receive notifications specific to the target object.
  250. * Note that only certain object types can receive notifications.
  251. */
  252. else {
  253. /* Notifies allowed on this object? */
  254. if (!acpi_ev_is_notify_object(node)) {
  255. status = AE_TYPE;
  256. goto unlock_and_exit;
  257. }
  258. /* Check for an existing internal object */
  259. obj_desc = acpi_ns_get_attached_object(node);
  260. if (obj_desc) {
  261. /* Object exists - make sure there's no handler */
  262. if (((handler_type & ACPI_SYSTEM_NOTIFY) &&
  263. obj_desc->common_notify.system_notify) ||
  264. ((handler_type & ACPI_DEVICE_NOTIFY) &&
  265. obj_desc->common_notify.device_notify)) {
  266. status = AE_ALREADY_EXISTS;
  267. goto unlock_and_exit;
  268. }
  269. } else {
  270. /* Create a new object */
  271. obj_desc = acpi_ut_create_internal_object(node->type);
  272. if (!obj_desc) {
  273. status = AE_NO_MEMORY;
  274. goto unlock_and_exit;
  275. }
  276. /* Attach new object to the Node */
  277. status =
  278. acpi_ns_attach_object(device, obj_desc, node->type);
  279. /* Remove local reference to the object */
  280. acpi_ut_remove_reference(obj_desc);
  281. if (ACPI_FAILURE(status)) {
  282. goto unlock_and_exit;
  283. }
  284. }
  285. /* Install the handler */
  286. notify_obj =
  287. acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY);
  288. if (!notify_obj) {
  289. status = AE_NO_MEMORY;
  290. goto unlock_and_exit;
  291. }
  292. notify_obj->notify.node = node;
  293. notify_obj->notify.handler = handler;
  294. notify_obj->notify.context = context;
  295. if (handler_type & ACPI_SYSTEM_NOTIFY) {
  296. obj_desc->common_notify.system_notify = notify_obj;
  297. }
  298. if (handler_type & ACPI_DEVICE_NOTIFY) {
  299. obj_desc->common_notify.device_notify = notify_obj;
  300. }
  301. if (handler_type == ACPI_ALL_NOTIFY) {
  302. /* Extra ref if installed in both */
  303. acpi_ut_add_reference(notify_obj);
  304. }
  305. }
  306. unlock_and_exit:
  307. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  308. return_ACPI_STATUS(status);
  309. }
  310. EXPORT_SYMBOL(acpi_install_notify_handler);
  311. /*******************************************************************************
  312. *
  313. * FUNCTION: acpi_remove_notify_handler
  314. *
  315. * PARAMETERS: Device - The device for which notifies will be handled
  316. * handler_type - The type of handler:
  317. * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
  318. * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
  319. * ACPI_ALL_NOTIFY: both system and device
  320. * Handler - Address of the handler
  321. *
  322. * RETURN: Status
  323. *
  324. * DESCRIPTION: Remove a handler for notifies on an ACPI device
  325. *
  326. ******************************************************************************/
  327. acpi_status
  328. acpi_remove_notify_handler(acpi_handle device,
  329. u32 handler_type, acpi_notify_handler handler)
  330. {
  331. union acpi_operand_object *notify_obj;
  332. union acpi_operand_object *obj_desc;
  333. struct acpi_namespace_node *node;
  334. acpi_status status;
  335. ACPI_FUNCTION_TRACE("acpi_remove_notify_handler");
  336. /* Parameter validation */
  337. if ((!device) ||
  338. (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
  339. return_ACPI_STATUS(AE_BAD_PARAMETER);
  340. }
  341. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  342. if (ACPI_FAILURE(status)) {
  343. return_ACPI_STATUS(status);
  344. }
  345. /* Convert and validate the device handle */
  346. node = acpi_ns_map_handle_to_node(device);
  347. if (!node) {
  348. status = AE_BAD_PARAMETER;
  349. goto unlock_and_exit;
  350. }
  351. /* Root Object */
  352. if (device == ACPI_ROOT_OBJECT) {
  353. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  354. "Removing notify handler for namespace root object\n"));
  355. if (((handler_type & ACPI_SYSTEM_NOTIFY) &&
  356. !acpi_gbl_system_notify.handler) ||
  357. ((handler_type & ACPI_DEVICE_NOTIFY) &&
  358. !acpi_gbl_device_notify.handler)) {
  359. status = AE_NOT_EXIST;
  360. goto unlock_and_exit;
  361. }
  362. /* Make sure all deferred tasks are completed */
  363. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  364. acpi_os_wait_events_complete(NULL);
  365. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  366. if (ACPI_FAILURE(status)) {
  367. return_ACPI_STATUS(status);
  368. }
  369. if (handler_type & ACPI_SYSTEM_NOTIFY) {
  370. acpi_gbl_system_notify.node = NULL;
  371. acpi_gbl_system_notify.handler = NULL;
  372. acpi_gbl_system_notify.context = NULL;
  373. }
  374. if (handler_type & ACPI_DEVICE_NOTIFY) {
  375. acpi_gbl_device_notify.node = NULL;
  376. acpi_gbl_device_notify.handler = NULL;
  377. acpi_gbl_device_notify.context = NULL;
  378. }
  379. }
  380. /* All Other Objects */
  381. else {
  382. /* Notifies allowed on this object? */
  383. if (!acpi_ev_is_notify_object(node)) {
  384. status = AE_TYPE;
  385. goto unlock_and_exit;
  386. }
  387. /* Check for an existing internal object */
  388. obj_desc = acpi_ns_get_attached_object(node);
  389. if (!obj_desc) {
  390. status = AE_NOT_EXIST;
  391. goto unlock_and_exit;
  392. }
  393. /* Object exists - make sure there's an existing handler */
  394. if (handler_type & ACPI_SYSTEM_NOTIFY) {
  395. notify_obj = obj_desc->common_notify.system_notify;
  396. if ((!notify_obj) ||
  397. (notify_obj->notify.handler != handler)) {
  398. status = AE_BAD_PARAMETER;
  399. goto unlock_and_exit;
  400. }
  401. /* Make sure all deferred tasks are completed */
  402. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  403. acpi_os_wait_events_complete(NULL);
  404. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  405. if (ACPI_FAILURE(status)) {
  406. return_ACPI_STATUS(status);
  407. }
  408. /* Remove the handler */
  409. obj_desc->common_notify.system_notify = NULL;
  410. acpi_ut_remove_reference(notify_obj);
  411. }
  412. if (handler_type & ACPI_DEVICE_NOTIFY) {
  413. notify_obj = obj_desc->common_notify.device_notify;
  414. if ((!notify_obj) ||
  415. (notify_obj->notify.handler != handler)) {
  416. status = AE_BAD_PARAMETER;
  417. goto unlock_and_exit;
  418. }
  419. /* Make sure all deferred tasks are completed */
  420. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  421. acpi_os_wait_events_complete(NULL);
  422. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  423. if (ACPI_FAILURE(status)) {
  424. return_ACPI_STATUS(status);
  425. }
  426. /* Remove the handler */
  427. obj_desc->common_notify.device_notify = NULL;
  428. acpi_ut_remove_reference(notify_obj);
  429. }
  430. }
  431. unlock_and_exit:
  432. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  433. return_ACPI_STATUS(status);
  434. }
  435. EXPORT_SYMBOL(acpi_remove_notify_handler);
  436. /*******************************************************************************
  437. *
  438. * FUNCTION: acpi_install_gpe_handler
  439. *
  440. * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
  441. * defined GPEs)
  442. * gpe_number - The GPE number within the GPE block
  443. * Type - Whether this GPE should be treated as an
  444. * edge- or level-triggered interrupt.
  445. * Address - Address of the handler
  446. * Context - Value passed to the handler on each GPE
  447. *
  448. * RETURN: Status
  449. *
  450. * DESCRIPTION: Install a handler for a General Purpose Event.
  451. *
  452. ******************************************************************************/
  453. acpi_status
  454. acpi_install_gpe_handler(acpi_handle gpe_device,
  455. u32 gpe_number,
  456. u32 type, acpi_event_handler address, void *context)
  457. {
  458. struct acpi_gpe_event_info *gpe_event_info;
  459. struct acpi_handler_info *handler;
  460. acpi_status status;
  461. acpi_native_uint flags;
  462. ACPI_FUNCTION_TRACE("acpi_install_gpe_handler");
  463. /* Parameter validation */
  464. if ((!address) || (type > ACPI_GPE_XRUPT_TYPE_MASK)) {
  465. return_ACPI_STATUS(AE_BAD_PARAMETER);
  466. }
  467. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  468. if (ACPI_FAILURE(status)) {
  469. return_ACPI_STATUS(status);
  470. }
  471. /* Ensure that we have a valid GPE number */
  472. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  473. if (!gpe_event_info) {
  474. status = AE_BAD_PARAMETER;
  475. goto unlock_and_exit;
  476. }
  477. /* Make sure that there isn't a handler there already */
  478. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  479. ACPI_GPE_DISPATCH_HANDLER) {
  480. status = AE_ALREADY_EXISTS;
  481. goto unlock_and_exit;
  482. }
  483. /* Allocate and init handler object */
  484. handler = ACPI_MEM_CALLOCATE(sizeof(struct acpi_handler_info));
  485. if (!handler) {
  486. status = AE_NO_MEMORY;
  487. goto unlock_and_exit;
  488. }
  489. handler->address = address;
  490. handler->context = context;
  491. handler->method_node = gpe_event_info->dispatch.method_node;
  492. /* Disable the GPE before installing the handler */
  493. status = acpi_ev_disable_gpe(gpe_event_info);
  494. if (ACPI_FAILURE(status)) {
  495. goto unlock_and_exit;
  496. }
  497. /* Install the handler */
  498. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  499. gpe_event_info->dispatch.handler = handler;
  500. /* Setup up dispatch flags to indicate handler (vs. method) */
  501. gpe_event_info->flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); /* Clear bits */
  502. gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER);
  503. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  504. unlock_and_exit:
  505. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  506. return_ACPI_STATUS(status);
  507. }
  508. EXPORT_SYMBOL(acpi_install_gpe_handler);
  509. /*******************************************************************************
  510. *
  511. * FUNCTION: acpi_remove_gpe_handler
  512. *
  513. * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
  514. * defined GPEs)
  515. * gpe_number - The event to remove a handler
  516. * Address - Address of the handler
  517. *
  518. * RETURN: Status
  519. *
  520. * DESCRIPTION: Remove a handler for a General Purpose acpi_event.
  521. *
  522. ******************************************************************************/
  523. acpi_status
  524. acpi_remove_gpe_handler(acpi_handle gpe_device,
  525. u32 gpe_number, acpi_event_handler address)
  526. {
  527. struct acpi_gpe_event_info *gpe_event_info;
  528. struct acpi_handler_info *handler;
  529. acpi_status status;
  530. acpi_native_uint flags;
  531. ACPI_FUNCTION_TRACE("acpi_remove_gpe_handler");
  532. /* Parameter validation */
  533. if (!address) {
  534. return_ACPI_STATUS(AE_BAD_PARAMETER);
  535. }
  536. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  537. if (ACPI_FAILURE(status)) {
  538. return_ACPI_STATUS(status);
  539. }
  540. /* Ensure that we have a valid GPE number */
  541. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  542. if (!gpe_event_info) {
  543. status = AE_BAD_PARAMETER;
  544. goto unlock_and_exit;
  545. }
  546. /* Make sure that a handler is indeed installed */
  547. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) !=
  548. ACPI_GPE_DISPATCH_HANDLER) {
  549. status = AE_NOT_EXIST;
  550. goto unlock_and_exit;
  551. }
  552. /* Make sure that the installed handler is the same */
  553. if (gpe_event_info->dispatch.handler->address != address) {
  554. status = AE_BAD_PARAMETER;
  555. goto unlock_and_exit;
  556. }
  557. /* Disable the GPE before removing the handler */
  558. status = acpi_ev_disable_gpe(gpe_event_info);
  559. if (ACPI_FAILURE(status)) {
  560. goto unlock_and_exit;
  561. }
  562. /* Make sure all deferred tasks are completed */
  563. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  564. acpi_os_wait_events_complete(NULL);
  565. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  566. if (ACPI_FAILURE(status)) {
  567. return_ACPI_STATUS(status);
  568. }
  569. /* Remove the handler */
  570. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  571. handler = gpe_event_info->dispatch.handler;
  572. /* Restore Method node (if any), set dispatch flags */
  573. gpe_event_info->dispatch.method_node = handler->method_node;
  574. gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK; /* Clear bits */
  575. if (handler->method_node) {
  576. gpe_event_info->flags |= ACPI_GPE_DISPATCH_METHOD;
  577. }
  578. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  579. /* Now we can free the handler object */
  580. ACPI_MEM_FREE(handler);
  581. unlock_and_exit:
  582. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  583. return_ACPI_STATUS(status);
  584. }
  585. EXPORT_SYMBOL(acpi_remove_gpe_handler);
  586. /*******************************************************************************
  587. *
  588. * FUNCTION: acpi_acquire_global_lock
  589. *
  590. * PARAMETERS: Timeout - How long the caller is willing to wait
  591. * Handle - Where the handle to the lock is returned
  592. * (if acquired)
  593. *
  594. * RETURN: Status
  595. *
  596. * DESCRIPTION: Acquire the ACPI Global Lock
  597. *
  598. ******************************************************************************/
  599. acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle)
  600. {
  601. acpi_status status;
  602. if (!handle) {
  603. return (AE_BAD_PARAMETER);
  604. }
  605. status = acpi_ex_enter_interpreter();
  606. if (ACPI_FAILURE(status)) {
  607. return (status);
  608. }
  609. status = acpi_ev_acquire_global_lock(timeout);
  610. acpi_ex_exit_interpreter();
  611. if (ACPI_SUCCESS(status)) {
  612. acpi_gbl_global_lock_handle++;
  613. *handle = acpi_gbl_global_lock_handle;
  614. }
  615. return (status);
  616. }
  617. EXPORT_SYMBOL(acpi_acquire_global_lock);
  618. /*******************************************************************************
  619. *
  620. * FUNCTION: acpi_release_global_lock
  621. *
  622. * PARAMETERS: Handle - Returned from acpi_acquire_global_lock
  623. *
  624. * RETURN: Status
  625. *
  626. * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
  627. *
  628. ******************************************************************************/
  629. acpi_status acpi_release_global_lock(u32 handle)
  630. {
  631. acpi_status status;
  632. if (handle != acpi_gbl_global_lock_handle) {
  633. return (AE_NOT_ACQUIRED);
  634. }
  635. status = acpi_ev_release_global_lock();
  636. return (status);
  637. }
  638. EXPORT_SYMBOL(acpi_release_global_lock);