evxface.c 22 KB

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