evxfregn.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and
  4. * Address Spaces.
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2006, 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(acpi_handle device,
  66. acpi_adr_space_type space_id,
  67. acpi_adr_space_handler handler,
  68. acpi_adr_space_setup setup, void *context)
  69. {
  70. struct acpi_namespace_node *node;
  71. acpi_status status;
  72. ACPI_FUNCTION_TRACE("acpi_install_address_space_handler");
  73. /* Parameter validation */
  74. if (!device) {
  75. return_ACPI_STATUS(AE_BAD_PARAMETER);
  76. }
  77. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  78. if (ACPI_FAILURE(status)) {
  79. return_ACPI_STATUS(status);
  80. }
  81. /* Convert and validate the device handle */
  82. node = acpi_ns_map_handle_to_node(device);
  83. if (!node) {
  84. status = AE_BAD_PARAMETER;
  85. goto unlock_and_exit;
  86. }
  87. /* Install the handler for all Regions for this Space ID */
  88. status =
  89. acpi_ev_install_space_handler(node, space_id, handler, setup,
  90. 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(acpi_handle device,
  116. acpi_adr_space_type space_id,
  117. acpi_adr_space_handler handler)
  118. {
  119. union acpi_operand_object *obj_desc;
  120. union acpi_operand_object *handler_obj;
  121. union acpi_operand_object *region_obj;
  122. union acpi_operand_object **last_obj_ptr;
  123. struct acpi_namespace_node *node;
  124. acpi_status status;
  125. ACPI_FUNCTION_TRACE("acpi_remove_address_space_handler");
  126. /* Parameter validation */
  127. if (!device) {
  128. return_ACPI_STATUS(AE_BAD_PARAMETER);
  129. }
  130. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  131. if (ACPI_FAILURE(status)) {
  132. return_ACPI_STATUS(status);
  133. }
  134. /* Convert and validate the device handle */
  135. node = acpi_ns_map_handle_to_node(device);
  136. if (!node) {
  137. status = AE_BAD_PARAMETER;
  138. goto unlock_and_exit;
  139. }
  140. /* Make sure the internal object exists */
  141. obj_desc = acpi_ns_get_attached_object(node);
  142. if (!obj_desc) {
  143. status = AE_NOT_EXIST;
  144. goto unlock_and_exit;
  145. }
  146. /* Find the address handler the user requested */
  147. handler_obj = obj_desc->device.handler;
  148. last_obj_ptr = &obj_desc->device.handler;
  149. while (handler_obj) {
  150. /* We have a handler, see if user requested this one */
  151. if (handler_obj->address_space.space_id == space_id) {
  152. /* Matched space_id, first dereference this in the Regions */
  153. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  154. "Removing address handler %p(%p) for region %s on Device %p(%p)\n",
  155. handler_obj, handler,
  156. 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 =
  174. handler_obj->address_space.region_list;
  175. }
  176. /* Remove this Handler object from the list */
  177. *last_obj_ptr = handler_obj->address_space.next;
  178. /* Now we can delete the handler object */
  179. acpi_ut_remove_reference(handler_obj);
  180. goto unlock_and_exit;
  181. }
  182. /* Walk the linked list of handlers */
  183. last_obj_ptr = &handler_obj->address_space.next;
  184. handler_obj = handler_obj->address_space.next;
  185. }
  186. /* The handler does not exist */
  187. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  188. "Unable to remove address handler %p for %s(%X), dev_node %p, obj %p\n",
  189. handler, acpi_ut_get_region_name(space_id), space_id,
  190. node, obj_desc));
  191. status = AE_NOT_EXIST;
  192. unlock_and_exit:
  193. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  194. return_ACPI_STATUS(status);
  195. }
  196. EXPORT_SYMBOL(acpi_remove_address_space_handler);