evxfregn.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 <acpi/acpi.h>
  44. #include <acpi/acnamesp.h>
  45. #include <acpi/acevents.h>
  46. #define _COMPONENT ACPI_EVENTS
  47. ACPI_MODULE_NAME("evxfregn")
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_install_address_space_handler
  51. *
  52. * PARAMETERS: Device - Handle for the device
  53. * space_id - The address space ID
  54. * Handler - Address of the handler
  55. * Setup - Address of the setup function
  56. * Context - Value passed to the handler on each access
  57. *
  58. * RETURN: Status
  59. *
  60. * DESCRIPTION: Install a handler for all op_regions of a given space_id.
  61. *
  62. ******************************************************************************/
  63. acpi_status
  64. acpi_install_address_space_handler(acpi_handle device,
  65. acpi_adr_space_type space_id,
  66. acpi_adr_space_handler handler,
  67. acpi_adr_space_setup setup, void *context)
  68. {
  69. struct acpi_namespace_node *node;
  70. acpi_status status;
  71. ACPI_FUNCTION_TRACE(acpi_install_address_space_handler);
  72. /* Parameter validation */
  73. if (!device) {
  74. return_ACPI_STATUS(AE_BAD_PARAMETER);
  75. }
  76. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  77. if (ACPI_FAILURE(status)) {
  78. return_ACPI_STATUS(status);
  79. }
  80. /* Convert and validate the device handle */
  81. node = acpi_ns_map_handle_to_node(device);
  82. if (!node) {
  83. status = AE_BAD_PARAMETER;
  84. goto unlock_and_exit;
  85. }
  86. /* Install the handler for all Regions for this Space ID */
  87. status =
  88. acpi_ev_install_space_handler(node, space_id, handler, setup,
  89. context);
  90. if (ACPI_FAILURE(status)) {
  91. goto unlock_and_exit;
  92. }
  93. /* Run all _REG methods for this address space */
  94. status = acpi_ev_execute_reg_methods(node, space_id);
  95. unlock_and_exit:
  96. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  97. return_ACPI_STATUS(status);
  98. }
  99. ACPI_EXPORT_SYMBOL(acpi_install_address_space_handler)
  100. /*******************************************************************************
  101. *
  102. * FUNCTION: acpi_remove_address_space_handler
  103. *
  104. * PARAMETERS: Device - Handle for the device
  105. * space_id - The address space ID
  106. * Handler - Address of the handler
  107. *
  108. * RETURN: Status
  109. *
  110. * DESCRIPTION: Remove a previously installed handler.
  111. *
  112. ******************************************************************************/
  113. acpi_status
  114. acpi_remove_address_space_handler(acpi_handle device,
  115. acpi_adr_space_type space_id,
  116. acpi_adr_space_handler handler)
  117. {
  118. union acpi_operand_object *obj_desc;
  119. union acpi_operand_object *handler_obj;
  120. union acpi_operand_object *region_obj;
  121. union acpi_operand_object **last_obj_ptr;
  122. struct acpi_namespace_node *node;
  123. acpi_status status;
  124. ACPI_FUNCTION_TRACE(acpi_remove_address_space_handler);
  125. /* Parameter validation */
  126. if (!device) {
  127. return_ACPI_STATUS(AE_BAD_PARAMETER);
  128. }
  129. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  130. if (ACPI_FAILURE(status)) {
  131. return_ACPI_STATUS(status);
  132. }
  133. /* Convert and validate the device handle */
  134. node = acpi_ns_map_handle_to_node(device);
  135. if (!node ||
  136. ((node->type != ACPI_TYPE_DEVICE) &&
  137. (node->type != ACPI_TYPE_PROCESSOR) &&
  138. (node->type != ACPI_TYPE_THERMAL) &&
  139. (node != acpi_gbl_root_node))) {
  140. status = AE_BAD_PARAMETER;
  141. goto unlock_and_exit;
  142. }
  143. /* Make sure the internal object exists */
  144. obj_desc = acpi_ns_get_attached_object(node);
  145. if (!obj_desc) {
  146. status = AE_NOT_EXIST;
  147. goto unlock_and_exit;
  148. }
  149. /* Find the address handler the user requested */
  150. handler_obj = obj_desc->device.handler;
  151. last_obj_ptr = &obj_desc->device.handler;
  152. while (handler_obj) {
  153. /* We have a handler, see if user requested this one */
  154. if (handler_obj->address_space.space_id == space_id) {
  155. /* Handler must be the same as the installed handler */
  156. if (handler_obj->address_space.handler != handler) {
  157. status = AE_BAD_PARAMETER;
  158. goto unlock_and_exit;
  159. }
  160. /* Matched space_id, first dereference this in the Regions */
  161. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  162. "Removing address handler %p(%p) for region %s on Device %p(%p)\n",
  163. handler_obj, handler,
  164. acpi_ut_get_region_name(space_id),
  165. node, obj_desc));
  166. region_obj = handler_obj->address_space.region_list;
  167. /* Walk the handler's region list */
  168. while (region_obj) {
  169. /*
  170. * First disassociate the handler from the region.
  171. *
  172. * NOTE: this doesn't mean that the region goes away
  173. * The region is just inaccessible as indicated to
  174. * the _REG method
  175. */
  176. acpi_ev_detach_region(region_obj, TRUE);
  177. /*
  178. * Walk the list: Just grab the head because the
  179. * detach_region removed the previous head.
  180. */
  181. region_obj =
  182. handler_obj->address_space.region_list;
  183. }
  184. /* Remove this Handler object from the list */
  185. *last_obj_ptr = handler_obj->address_space.next;
  186. /* Now we can delete the handler object */
  187. acpi_ut_remove_reference(handler_obj);
  188. goto unlock_and_exit;
  189. }
  190. /* Walk the linked list of handlers */
  191. last_obj_ptr = &handler_obj->address_space.next;
  192. handler_obj = handler_obj->address_space.next;
  193. }
  194. /* The handler does not exist */
  195. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  196. "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",
  197. handler, acpi_ut_get_region_name(space_id), space_id,
  198. node, obj_desc));
  199. status = AE_NOT_EXIST;
  200. unlock_and_exit:
  201. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  202. return_ACPI_STATUS(status);
  203. }
  204. ACPI_EXPORT_SYMBOL(acpi_remove_address_space_handler)