evxface.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  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 <acpi/acpi.h>
  43. #include <acpi/acnamesp.h>
  44. #include <acpi/acevents.h>
  45. #include <acpi/acinterp.h>
  46. #define _COMPONENT ACPI_EVENTS
  47. ACPI_MODULE_NAME("evxface")
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_install_exception_handler
  51. *
  52. * PARAMETERS: Handler - Pointer to the handler function for the
  53. * event
  54. *
  55. * RETURN: Status
  56. *
  57. * DESCRIPTION: Saves the pointer to the handler function
  58. *
  59. ******************************************************************************/
  60. #ifdef ACPI_FUTURE_USAGE
  61. acpi_status acpi_install_exception_handler(acpi_exception_handler handler)
  62. {
  63. acpi_status status;
  64. ACPI_FUNCTION_TRACE(acpi_install_exception_handler);
  65. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  66. if (ACPI_FAILURE(status)) {
  67. return_ACPI_STATUS(status);
  68. }
  69. /* Don't allow two handlers. */
  70. if (acpi_gbl_exception_handler) {
  71. status = AE_ALREADY_EXISTS;
  72. goto cleanup;
  73. }
  74. /* Install the handler */
  75. acpi_gbl_exception_handler = handler;
  76. cleanup:
  77. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  78. return_ACPI_STATUS(status);
  79. }
  80. ACPI_EXPORT_SYMBOL(acpi_install_exception_handler)
  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. ACPI_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. ACPI_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. ACPI_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. status = AE_BAD_PARAMETER;
  342. goto exit;
  343. }
  344. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  345. if (ACPI_FAILURE(status)) {
  346. goto exit;
  347. }
  348. /* Convert and validate the device handle */
  349. node = acpi_ns_map_handle_to_node(device);
  350. if (!node) {
  351. status = AE_BAD_PARAMETER;
  352. goto unlock;
  353. }
  354. /* Root Object */
  355. if (device == ACPI_ROOT_OBJECT) {
  356. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  357. "Removing notify handler for namespace root object\n"));
  358. if (((handler_type & ACPI_SYSTEM_NOTIFY) &&
  359. !acpi_gbl_system_notify.handler) ||
  360. ((handler_type & ACPI_DEVICE_NOTIFY) &&
  361. !acpi_gbl_device_notify.handler)) {
  362. status = AE_NOT_EXIST;
  363. goto unlock;
  364. }
  365. /* Make sure all deferred tasks are completed */
  366. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  367. acpi_os_wait_events_complete(NULL);
  368. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  369. if (ACPI_FAILURE(status)) {
  370. goto exit;
  371. }
  372. if (handler_type & ACPI_SYSTEM_NOTIFY) {
  373. acpi_gbl_system_notify.node = NULL;
  374. acpi_gbl_system_notify.handler = NULL;
  375. acpi_gbl_system_notify.context = NULL;
  376. }
  377. if (handler_type & ACPI_DEVICE_NOTIFY) {
  378. acpi_gbl_device_notify.node = NULL;
  379. acpi_gbl_device_notify.handler = NULL;
  380. acpi_gbl_device_notify.context = NULL;
  381. }
  382. }
  383. /* All Other Objects */
  384. else {
  385. /* Notifies allowed on this object? */
  386. if (!acpi_ev_is_notify_object(node)) {
  387. status = AE_TYPE;
  388. goto unlock;
  389. }
  390. /* Check for an existing internal object */
  391. obj_desc = acpi_ns_get_attached_object(node);
  392. if (!obj_desc) {
  393. status = AE_NOT_EXIST;
  394. goto unlock;
  395. }
  396. /* Object exists - make sure there's an existing handler */
  397. if (handler_type & ACPI_SYSTEM_NOTIFY) {
  398. notify_obj = obj_desc->common_notify.system_notify;
  399. if ((!notify_obj) ||
  400. (notify_obj->notify.handler != handler)) {
  401. status = AE_BAD_PARAMETER;
  402. goto unlock;
  403. }
  404. /* Make sure all deferred tasks are completed */
  405. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  406. acpi_os_wait_events_complete(NULL);
  407. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  408. if (ACPI_FAILURE(status)) {
  409. goto exit;
  410. }
  411. /* Remove the handler */
  412. obj_desc->common_notify.system_notify = NULL;
  413. acpi_ut_remove_reference(notify_obj);
  414. }
  415. if (handler_type & ACPI_DEVICE_NOTIFY) {
  416. notify_obj = obj_desc->common_notify.device_notify;
  417. if ((!notify_obj) ||
  418. (notify_obj->notify.handler != handler)) {
  419. status = AE_BAD_PARAMETER;
  420. goto unlock;
  421. }
  422. /* Make sure all deferred tasks are completed */
  423. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  424. acpi_os_wait_events_complete(NULL);
  425. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  426. if (ACPI_FAILURE(status)) {
  427. goto exit;
  428. }
  429. /* Remove the handler */
  430. obj_desc->common_notify.device_notify = NULL;
  431. acpi_ut_remove_reference(notify_obj);
  432. }
  433. }
  434. unlock:
  435. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  436. exit:
  437. if (ACPI_FAILURE(status))
  438. ACPI_EXCEPTION((AE_INFO, status, "Removing notify handler"));
  439. return_ACPI_STATUS(status);
  440. }
  441. ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler)
  442. /*******************************************************************************
  443. *
  444. * FUNCTION: acpi_install_gpe_handler
  445. *
  446. * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
  447. * defined GPEs)
  448. * gpe_number - The GPE number within the GPE block
  449. * Type - Whether this GPE should be treated as an
  450. * edge- or level-triggered interrupt.
  451. * Address - Address of the handler
  452. * Context - Value passed to the handler on each GPE
  453. *
  454. * RETURN: Status
  455. *
  456. * DESCRIPTION: Install a handler for a General Purpose Event.
  457. *
  458. ******************************************************************************/
  459. acpi_status
  460. acpi_install_gpe_handler(acpi_handle gpe_device,
  461. u32 gpe_number,
  462. u32 type, acpi_event_handler address, void *context)
  463. {
  464. struct acpi_gpe_event_info *gpe_event_info;
  465. struct acpi_handler_info *handler;
  466. acpi_status status;
  467. acpi_cpu_flags flags;
  468. ACPI_FUNCTION_TRACE(acpi_install_gpe_handler);
  469. /* Parameter validation */
  470. if ((!address) || (type > ACPI_GPE_XRUPT_TYPE_MASK)) {
  471. status = AE_BAD_PARAMETER;
  472. goto exit;
  473. }
  474. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  475. if (ACPI_FAILURE(status)) {
  476. goto exit;
  477. }
  478. /* Ensure that we have a valid GPE number */
  479. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  480. if (!gpe_event_info) {
  481. status = AE_BAD_PARAMETER;
  482. goto unlock;
  483. }
  484. /* Make sure that there isn't a handler there already */
  485. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  486. ACPI_GPE_DISPATCH_HANDLER) {
  487. status = AE_ALREADY_EXISTS;
  488. goto unlock;
  489. }
  490. /* Allocate and init handler object */
  491. handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_handler_info));
  492. if (!handler) {
  493. status = AE_NO_MEMORY;
  494. goto unlock;
  495. }
  496. handler->address = address;
  497. handler->context = context;
  498. handler->method_node = gpe_event_info->dispatch.method_node;
  499. /* Disable the GPE before installing the handler */
  500. status = acpi_ev_disable_gpe(gpe_event_info);
  501. if (ACPI_FAILURE(status)) {
  502. goto unlock;
  503. }
  504. /* Install the handler */
  505. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  506. gpe_event_info->dispatch.handler = handler;
  507. /* Setup up dispatch flags to indicate handler (vs. method) */
  508. gpe_event_info->flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); /* Clear bits */
  509. gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER);
  510. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  511. unlock:
  512. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  513. exit:
  514. if (ACPI_FAILURE(status))
  515. ACPI_EXCEPTION((AE_INFO, status,
  516. "Installing notify handler failed"));
  517. return_ACPI_STATUS(status);
  518. }
  519. ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler)
  520. /*******************************************************************************
  521. *
  522. * FUNCTION: acpi_remove_gpe_handler
  523. *
  524. * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
  525. * defined GPEs)
  526. * gpe_number - The event to remove a handler
  527. * Address - Address of the handler
  528. *
  529. * RETURN: Status
  530. *
  531. * DESCRIPTION: Remove a handler for a General Purpose acpi_event.
  532. *
  533. ******************************************************************************/
  534. acpi_status
  535. acpi_remove_gpe_handler(acpi_handle gpe_device,
  536. u32 gpe_number, acpi_event_handler address)
  537. {
  538. struct acpi_gpe_event_info *gpe_event_info;
  539. struct acpi_handler_info *handler;
  540. acpi_status status;
  541. acpi_cpu_flags flags;
  542. ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler);
  543. /* Parameter validation */
  544. if (!address) {
  545. return_ACPI_STATUS(AE_BAD_PARAMETER);
  546. }
  547. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  548. if (ACPI_FAILURE(status)) {
  549. return_ACPI_STATUS(status);
  550. }
  551. /* Ensure that we have a valid GPE number */
  552. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  553. if (!gpe_event_info) {
  554. status = AE_BAD_PARAMETER;
  555. goto unlock_and_exit;
  556. }
  557. /* Make sure that a handler is indeed installed */
  558. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) !=
  559. ACPI_GPE_DISPATCH_HANDLER) {
  560. status = AE_NOT_EXIST;
  561. goto unlock_and_exit;
  562. }
  563. /* Make sure that the installed handler is the same */
  564. if (gpe_event_info->dispatch.handler->address != address) {
  565. status = AE_BAD_PARAMETER;
  566. goto unlock_and_exit;
  567. }
  568. /* Disable the GPE before removing the handler */
  569. status = acpi_ev_disable_gpe(gpe_event_info);
  570. if (ACPI_FAILURE(status)) {
  571. goto unlock_and_exit;
  572. }
  573. /* Make sure all deferred tasks are completed */
  574. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  575. acpi_os_wait_events_complete(NULL);
  576. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  577. if (ACPI_FAILURE(status)) {
  578. return_ACPI_STATUS(status);
  579. }
  580. /* Remove the handler */
  581. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  582. handler = gpe_event_info->dispatch.handler;
  583. /* Restore Method node (if any), set dispatch flags */
  584. gpe_event_info->dispatch.method_node = handler->method_node;
  585. gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK; /* Clear bits */
  586. if (handler->method_node) {
  587. gpe_event_info->flags |= ACPI_GPE_DISPATCH_METHOD;
  588. }
  589. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  590. /* Now we can free the handler object */
  591. ACPI_FREE(handler);
  592. unlock_and_exit:
  593. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  594. return_ACPI_STATUS(status);
  595. }
  596. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler)
  597. /*******************************************************************************
  598. *
  599. * FUNCTION: acpi_acquire_global_lock
  600. *
  601. * PARAMETERS: Timeout - How long the caller is willing to wait
  602. * Handle - Where the handle to the lock is returned
  603. * (if acquired)
  604. *
  605. * RETURN: Status
  606. *
  607. * DESCRIPTION: Acquire the ACPI Global Lock
  608. *
  609. ******************************************************************************/
  610. acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle)
  611. {
  612. acpi_status status;
  613. if (!handle) {
  614. return (AE_BAD_PARAMETER);
  615. }
  616. status = acpi_ex_enter_interpreter();
  617. if (ACPI_FAILURE(status)) {
  618. return (status);
  619. }
  620. status = acpi_ev_acquire_global_lock(timeout);
  621. acpi_ex_exit_interpreter();
  622. if (ACPI_SUCCESS(status)) {
  623. acpi_gbl_global_lock_handle++;
  624. *handle = acpi_gbl_global_lock_handle;
  625. }
  626. return (status);
  627. }
  628. ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock)
  629. /*******************************************************************************
  630. *
  631. * FUNCTION: acpi_release_global_lock
  632. *
  633. * PARAMETERS: Handle - Returned from acpi_acquire_global_lock
  634. *
  635. * RETURN: Status
  636. *
  637. * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
  638. *
  639. ******************************************************************************/
  640. acpi_status acpi_release_global_lock(u32 handle)
  641. {
  642. acpi_status status;
  643. if (handle != acpi_gbl_global_lock_handle) {
  644. return (AE_NOT_ACQUIRED);
  645. }
  646. status = acpi_ev_release_global_lock();
  647. return (status);
  648. }
  649. ACPI_EXPORT_SYMBOL(acpi_release_global_lock)