evxfregn.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and
  4. * Address Spaces.
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2005, R. Byron Moore
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions, and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * substantially similar to the "NO WARRANTY" disclaimer below
  19. * ("Disclaimer") and any redistribution must be conditioned upon
  20. * including a substantially similar Disclaimer requirement for further
  21. * binary redistribution.
  22. * 3. Neither the names of the above-listed copyright holders nor the names
  23. * of any contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * Alternatively, this software may be distributed under the terms of the
  27. * GNU General Public License ("GPL") version 2 as published by the Free
  28. * Software Foundation.
  29. *
  30. * NO WARRANTY
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGES.
  42. */
  43. #include <linux/module.h>
  44. #include <acpi/acpi.h>
  45. #include <acpi/acnamesp.h>
  46. #include <acpi/acevents.h>
  47. #define _COMPONENT ACPI_EVENTS
  48. ACPI_MODULE_NAME ("evxfregn")
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_install_address_space_handler
  52. *
  53. * PARAMETERS: Device - Handle for the device
  54. * space_id - The address space ID
  55. * Handler - Address of the handler
  56. * Setup - Address of the setup function
  57. * Context - Value passed to the handler on each access
  58. *
  59. * RETURN: Status
  60. *
  61. * DESCRIPTION: Install a handler for all op_regions of a given space_id.
  62. *
  63. ******************************************************************************/
  64. acpi_status
  65. acpi_install_address_space_handler (
  66. acpi_handle device,
  67. acpi_adr_space_type space_id,
  68. acpi_adr_space_handler handler,
  69. acpi_adr_space_setup setup,
  70. void *context)
  71. {
  72. struct acpi_namespace_node *node;
  73. acpi_status status;
  74. ACPI_FUNCTION_TRACE ("acpi_install_address_space_handler");
  75. /* Parameter validation */
  76. if (!device) {
  77. return_ACPI_STATUS (AE_BAD_PARAMETER);
  78. }
  79. status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
  80. if (ACPI_FAILURE (status)) {
  81. return_ACPI_STATUS (status);
  82. }
  83. /* Convert and validate the device handle */
  84. node = acpi_ns_map_handle_to_node (device);
  85. if (!node) {
  86. status = AE_BAD_PARAMETER;
  87. goto unlock_and_exit;
  88. }
  89. /* Install the handler for all Regions for this Space ID */
  90. status = acpi_ev_install_space_handler (node, space_id, handler, setup, context);
  91. if (ACPI_FAILURE (status)) {
  92. goto unlock_and_exit;
  93. }
  94. /* Run all _REG methods for this address space */
  95. status = acpi_ev_execute_reg_methods (node, space_id);
  96. unlock_and_exit:
  97. (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  98. return_ACPI_STATUS (status);
  99. }
  100. EXPORT_SYMBOL(acpi_install_address_space_handler);
  101. /*******************************************************************************
  102. *
  103. * FUNCTION: acpi_remove_address_space_handler
  104. *
  105. * PARAMETERS: Device - Handle for the device
  106. * space_id - The address space ID
  107. * Handler - Address of the handler
  108. *
  109. * RETURN: Status
  110. *
  111. * DESCRIPTION: Remove a previously installed handler.
  112. *
  113. ******************************************************************************/
  114. acpi_status
  115. acpi_remove_address_space_handler (
  116. acpi_handle device,
  117. acpi_adr_space_type space_id,
  118. acpi_adr_space_handler handler)
  119. {
  120. union acpi_operand_object *obj_desc;
  121. union acpi_operand_object *handler_obj;
  122. union acpi_operand_object *region_obj;
  123. union acpi_operand_object **last_obj_ptr;
  124. struct acpi_namespace_node *node;
  125. acpi_status status;
  126. ACPI_FUNCTION_TRACE ("acpi_remove_address_space_handler");
  127. /* Parameter validation */
  128. if (!device) {
  129. return_ACPI_STATUS (AE_BAD_PARAMETER);
  130. }
  131. status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
  132. if (ACPI_FAILURE (status)) {
  133. return_ACPI_STATUS (status);
  134. }
  135. /* Convert and validate the device handle */
  136. node = acpi_ns_map_handle_to_node (device);
  137. if (!node) {
  138. status = AE_BAD_PARAMETER;
  139. goto unlock_and_exit;
  140. }
  141. /* Make sure the internal object exists */
  142. obj_desc = acpi_ns_get_attached_object (node);
  143. if (!obj_desc) {
  144. status = AE_NOT_EXIST;
  145. goto unlock_and_exit;
  146. }
  147. /* Find the address handler the user requested */
  148. handler_obj = obj_desc->device.handler;
  149. last_obj_ptr = &obj_desc->device.handler;
  150. while (handler_obj) {
  151. /* We have a handler, see if user requested this one */
  152. if (handler_obj->address_space.space_id == space_id) {
  153. /* Matched space_id, first dereference this in the Regions */
  154. ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
  155. "Removing address handler %p(%p) for region %s on Device %p(%p)\n",
  156. handler_obj, handler, acpi_ut_get_region_name (space_id),
  157. node, obj_desc));
  158. region_obj = handler_obj->address_space.region_list;
  159. /* Walk the handler's region list */
  160. while (region_obj) {
  161. /*
  162. * First disassociate the handler from the region.
  163. *
  164. * NOTE: this doesn't mean that the region goes away
  165. * The region is just inaccessible as indicated to
  166. * the _REG method
  167. */
  168. acpi_ev_detach_region (region_obj, TRUE);
  169. /*
  170. * Walk the list: Just grab the head because the
  171. * detach_region removed the previous head.
  172. */
  173. region_obj = handler_obj->address_space.region_list;
  174. }
  175. /* Remove this Handler object from the list */
  176. *last_obj_ptr = handler_obj->address_space.next;
  177. /* Now we can delete the handler object */
  178. acpi_ut_remove_reference (handler_obj);
  179. goto unlock_and_exit;
  180. }
  181. /* Walk the linked list of handlers */
  182. last_obj_ptr = &handler_obj->address_space.next;
  183. handler_obj = handler_obj->address_space.next;
  184. }
  185. /* The handler does not exist */
  186. ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
  187. "Unable to remove address handler %p for %s(%X), dev_node %p, obj %p\n",
  188. handler, acpi_ut_get_region_name (space_id), space_id, node, obj_desc));
  189. status = AE_NOT_EXIST;
  190. unlock_and_exit:
  191. (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
  192. return_ACPI_STATUS (status);
  193. }
  194. EXPORT_SYMBOL(acpi_remove_address_space_handler);