evxface.c 22 KB

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