evxface.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  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_and_exit;
  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_and_exit;
  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_and_exit;
  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_and_exit;
  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. status = AE_NOT_EXIST;
  401. goto unlock_and_exit;
  402. }
  403. if (notify_obj->notify.handler != handler) {
  404. status = AE_BAD_PARAMETER;
  405. goto unlock_and_exit;
  406. }
  407. /* Make sure all deferred tasks are completed */
  408. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  409. acpi_os_wait_events_complete(NULL);
  410. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  411. if (ACPI_FAILURE(status)) {
  412. goto exit;
  413. }
  414. /* Remove the handler */
  415. obj_desc->common_notify.system_notify = NULL;
  416. acpi_ut_remove_reference(notify_obj);
  417. }
  418. if (handler_type & ACPI_DEVICE_NOTIFY) {
  419. notify_obj = obj_desc->common_notify.device_notify;
  420. if (!notify_obj) {
  421. status = AE_NOT_EXIST;
  422. goto unlock_and_exit;
  423. }
  424. if (notify_obj->notify.handler != handler) {
  425. status = AE_BAD_PARAMETER;
  426. goto unlock_and_exit;
  427. }
  428. /* Make sure all deferred tasks are completed */
  429. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  430. acpi_os_wait_events_complete(NULL);
  431. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  432. if (ACPI_FAILURE(status)) {
  433. goto exit;
  434. }
  435. /* Remove the handler */
  436. obj_desc->common_notify.device_notify = NULL;
  437. acpi_ut_remove_reference(notify_obj);
  438. }
  439. }
  440. unlock_and_exit:
  441. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  442. exit:
  443. if (ACPI_FAILURE(status))
  444. ACPI_EXCEPTION((AE_INFO, status, "Removing notify handler"));
  445. return_ACPI_STATUS(status);
  446. }
  447. ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler)
  448. /*******************************************************************************
  449. *
  450. * FUNCTION: acpi_install_gpe_handler
  451. *
  452. * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
  453. * defined GPEs)
  454. * gpe_number - The GPE number within the GPE block
  455. * Type - Whether this GPE should be treated as an
  456. * edge- or level-triggered interrupt.
  457. * Address - Address of the handler
  458. * Context - Value passed to the handler on each GPE
  459. *
  460. * RETURN: Status
  461. *
  462. * DESCRIPTION: Install a handler for a General Purpose Event.
  463. *
  464. ******************************************************************************/
  465. acpi_status
  466. acpi_install_gpe_handler(acpi_handle gpe_device,
  467. u32 gpe_number,
  468. u32 type, acpi_event_handler address, void *context)
  469. {
  470. struct acpi_gpe_event_info *gpe_event_info;
  471. struct acpi_handler_info *handler;
  472. acpi_status status;
  473. acpi_cpu_flags flags;
  474. ACPI_FUNCTION_TRACE(acpi_install_gpe_handler);
  475. /* Parameter validation */
  476. if ((!address) || (type > ACPI_GPE_XRUPT_TYPE_MASK)) {
  477. status = AE_BAD_PARAMETER;
  478. goto exit;
  479. }
  480. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  481. if (ACPI_FAILURE(status)) {
  482. goto exit;
  483. }
  484. /* Ensure that we have a valid GPE number */
  485. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  486. if (!gpe_event_info) {
  487. status = AE_BAD_PARAMETER;
  488. goto unlock_and_exit;
  489. }
  490. /* Make sure that there isn't a handler there already */
  491. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  492. ACPI_GPE_DISPATCH_HANDLER) {
  493. status = AE_ALREADY_EXISTS;
  494. goto unlock_and_exit;
  495. }
  496. /* Allocate and init handler object */
  497. handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_handler_info));
  498. if (!handler) {
  499. status = AE_NO_MEMORY;
  500. goto unlock_and_exit;
  501. }
  502. handler->address = address;
  503. handler->context = context;
  504. handler->method_node = gpe_event_info->dispatch.method_node;
  505. /* Disable the GPE before installing the handler */
  506. status = acpi_ev_disable_gpe(gpe_event_info);
  507. if (ACPI_FAILURE(status)) {
  508. goto unlock_and_exit;
  509. }
  510. /* Install the handler */
  511. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  512. gpe_event_info->dispatch.handler = handler;
  513. /* Setup up dispatch flags to indicate handler (vs. method) */
  514. gpe_event_info->flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); /* Clear bits */
  515. gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER);
  516. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  517. unlock_and_exit:
  518. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  519. exit:
  520. if (ACPI_FAILURE(status))
  521. ACPI_EXCEPTION((AE_INFO, status,
  522. "Installing notify handler failed"));
  523. return_ACPI_STATUS(status);
  524. }
  525. ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler)
  526. /*******************************************************************************
  527. *
  528. * FUNCTION: acpi_remove_gpe_handler
  529. *
  530. * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
  531. * defined GPEs)
  532. * gpe_number - The event to remove a handler
  533. * Address - Address of the handler
  534. *
  535. * RETURN: Status
  536. *
  537. * DESCRIPTION: Remove a handler for a General Purpose acpi_event.
  538. *
  539. ******************************************************************************/
  540. acpi_status
  541. acpi_remove_gpe_handler(acpi_handle gpe_device,
  542. u32 gpe_number, acpi_event_handler address)
  543. {
  544. struct acpi_gpe_event_info *gpe_event_info;
  545. struct acpi_handler_info *handler;
  546. acpi_status status;
  547. acpi_cpu_flags flags;
  548. ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler);
  549. /* Parameter validation */
  550. if (!address) {
  551. return_ACPI_STATUS(AE_BAD_PARAMETER);
  552. }
  553. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  554. if (ACPI_FAILURE(status)) {
  555. return_ACPI_STATUS(status);
  556. }
  557. /* Ensure that we have a valid GPE number */
  558. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  559. if (!gpe_event_info) {
  560. status = AE_BAD_PARAMETER;
  561. goto unlock_and_exit;
  562. }
  563. /* Make sure that a handler is indeed installed */
  564. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) !=
  565. ACPI_GPE_DISPATCH_HANDLER) {
  566. status = AE_NOT_EXIST;
  567. goto unlock_and_exit;
  568. }
  569. /* Make sure that the installed handler is the same */
  570. if (gpe_event_info->dispatch.handler->address != address) {
  571. status = AE_BAD_PARAMETER;
  572. goto unlock_and_exit;
  573. }
  574. /* Disable the GPE before removing the handler */
  575. status = acpi_ev_disable_gpe(gpe_event_info);
  576. if (ACPI_FAILURE(status)) {
  577. goto unlock_and_exit;
  578. }
  579. /* Make sure all deferred tasks are completed */
  580. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  581. acpi_os_wait_events_complete(NULL);
  582. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  583. if (ACPI_FAILURE(status)) {
  584. return_ACPI_STATUS(status);
  585. }
  586. /* Remove the handler */
  587. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  588. handler = gpe_event_info->dispatch.handler;
  589. /* Restore Method node (if any), set dispatch flags */
  590. gpe_event_info->dispatch.method_node = handler->method_node;
  591. gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK; /* Clear bits */
  592. if (handler->method_node) {
  593. gpe_event_info->flags |= ACPI_GPE_DISPATCH_METHOD;
  594. }
  595. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  596. /* Now we can free the handler object */
  597. ACPI_FREE(handler);
  598. unlock_and_exit:
  599. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  600. return_ACPI_STATUS(status);
  601. }
  602. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler)
  603. /*******************************************************************************
  604. *
  605. * FUNCTION: acpi_acquire_global_lock
  606. *
  607. * PARAMETERS: Timeout - How long the caller is willing to wait
  608. * Handle - Where the handle to the lock is returned
  609. * (if acquired)
  610. *
  611. * RETURN: Status
  612. *
  613. * DESCRIPTION: Acquire the ACPI Global Lock
  614. *
  615. ******************************************************************************/
  616. acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle)
  617. {
  618. acpi_status status;
  619. if (!handle) {
  620. return (AE_BAD_PARAMETER);
  621. }
  622. status = acpi_ex_enter_interpreter();
  623. if (ACPI_FAILURE(status)) {
  624. return (status);
  625. }
  626. status = acpi_ev_acquire_global_lock(timeout);
  627. acpi_ex_exit_interpreter();
  628. if (ACPI_SUCCESS(status)) {
  629. acpi_gbl_global_lock_handle++;
  630. *handle = acpi_gbl_global_lock_handle;
  631. }
  632. return (status);
  633. }
  634. ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock)
  635. /*******************************************************************************
  636. *
  637. * FUNCTION: acpi_release_global_lock
  638. *
  639. * PARAMETERS: Handle - Returned from acpi_acquire_global_lock
  640. *
  641. * RETURN: Status
  642. *
  643. * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
  644. *
  645. ******************************************************************************/
  646. acpi_status acpi_release_global_lock(u32 handle)
  647. {
  648. acpi_status status;
  649. if (handle != acpi_gbl_global_lock_handle) {
  650. return (AE_NOT_ACQUIRED);
  651. }
  652. status = acpi_ev_release_global_lock();
  653. return (status);
  654. }
  655. ACPI_EXPORT_SYMBOL(acpi_release_global_lock)