evxfregn.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and
  4. * Address Spaces.
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2011, Intel Corp.
  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 "accommon.h"
  45. #include "acnamesp.h"
  46. #include "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. * NOTE: This function should only be called after acpi_enable_subsystem has
  64. * been called. This is because any _REG methods associated with the Space ID
  65. * are executed here, and these methods can only be safely executed after
  66. * the default handlers have been installed and the hardware has been
  67. * initialized (via acpi_enable_subsystem.)
  68. *
  69. ******************************************************************************/
  70. acpi_status
  71. acpi_install_address_space_handler(acpi_handle device,
  72. acpi_adr_space_type space_id,
  73. acpi_adr_space_handler handler,
  74. acpi_adr_space_setup setup, void *context)
  75. {
  76. struct acpi_namespace_node *node;
  77. acpi_status status;
  78. ACPI_FUNCTION_TRACE(acpi_install_address_space_handler);
  79. /* Parameter validation */
  80. if (!device) {
  81. return_ACPI_STATUS(AE_BAD_PARAMETER);
  82. }
  83. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  84. if (ACPI_FAILURE(status)) {
  85. return_ACPI_STATUS(status);
  86. }
  87. /* Convert and validate the device handle */
  88. node = acpi_ns_validate_handle(device);
  89. if (!node) {
  90. status = AE_BAD_PARAMETER;
  91. goto unlock_and_exit;
  92. }
  93. /* Install the handler for all Regions for this Space ID */
  94. status =
  95. acpi_ev_install_space_handler(node, space_id, handler, setup,
  96. context);
  97. if (ACPI_FAILURE(status)) {
  98. goto unlock_and_exit;
  99. }
  100. /*
  101. * For the default space_iDs, (the IDs for which there are default region handlers
  102. * installed) Only execute the _REG methods if the global initialization _REG
  103. * methods have already been run (via acpi_initialize_objects). In other words,
  104. * we will defer the execution of the _REG methods for these space_iDs until
  105. * execution of acpi_initialize_objects. This is done because we need the handlers
  106. * for the default spaces (mem/io/pci/table) to be installed before we can run
  107. * any control methods (or _REG methods). There is known BIOS code that depends
  108. * on this.
  109. *
  110. * For all other space_iDs, we can safely execute the _REG methods immediately.
  111. * This means that for IDs like embedded_controller, this function should be called
  112. * only after acpi_enable_subsystem has been called.
  113. */
  114. switch (space_id) {
  115. case ACPI_ADR_SPACE_SYSTEM_MEMORY:
  116. case ACPI_ADR_SPACE_SYSTEM_IO:
  117. case ACPI_ADR_SPACE_PCI_CONFIG:
  118. case ACPI_ADR_SPACE_DATA_TABLE:
  119. if (!acpi_gbl_reg_methods_executed) {
  120. /* We will defer execution of the _REG methods for this space */
  121. goto unlock_and_exit;
  122. }
  123. break;
  124. default:
  125. break;
  126. }
  127. /* Run all _REG methods for this address space */
  128. status = acpi_ev_execute_reg_methods(node, space_id);
  129. unlock_and_exit:
  130. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  131. return_ACPI_STATUS(status);
  132. }
  133. ACPI_EXPORT_SYMBOL(acpi_install_address_space_handler)
  134. /*******************************************************************************
  135. *
  136. * FUNCTION: acpi_remove_address_space_handler
  137. *
  138. * PARAMETERS: Device - Handle for the device
  139. * space_id - The address space ID
  140. * Handler - Address of the handler
  141. *
  142. * RETURN: Status
  143. *
  144. * DESCRIPTION: Remove a previously installed handler.
  145. *
  146. ******************************************************************************/
  147. acpi_status
  148. acpi_remove_address_space_handler(acpi_handle device,
  149. acpi_adr_space_type space_id,
  150. acpi_adr_space_handler handler)
  151. {
  152. union acpi_operand_object *obj_desc;
  153. union acpi_operand_object *handler_obj;
  154. union acpi_operand_object *region_obj;
  155. union acpi_operand_object **last_obj_ptr;
  156. struct acpi_namespace_node *node;
  157. acpi_status status;
  158. ACPI_FUNCTION_TRACE(acpi_remove_address_space_handler);
  159. /* Parameter validation */
  160. if (!device) {
  161. return_ACPI_STATUS(AE_BAD_PARAMETER);
  162. }
  163. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  164. if (ACPI_FAILURE(status)) {
  165. return_ACPI_STATUS(status);
  166. }
  167. /* Convert and validate the device handle */
  168. node = acpi_ns_validate_handle(device);
  169. if (!node ||
  170. ((node->type != ACPI_TYPE_DEVICE) &&
  171. (node->type != ACPI_TYPE_PROCESSOR) &&
  172. (node->type != ACPI_TYPE_THERMAL) &&
  173. (node != acpi_gbl_root_node))) {
  174. status = AE_BAD_PARAMETER;
  175. goto unlock_and_exit;
  176. }
  177. /* Make sure the internal object exists */
  178. obj_desc = acpi_ns_get_attached_object(node);
  179. if (!obj_desc) {
  180. status = AE_NOT_EXIST;
  181. goto unlock_and_exit;
  182. }
  183. /* Find the address handler the user requested */
  184. handler_obj = obj_desc->device.handler;
  185. last_obj_ptr = &obj_desc->device.handler;
  186. while (handler_obj) {
  187. /* We have a handler, see if user requested this one */
  188. if (handler_obj->address_space.space_id == space_id) {
  189. /* Handler must be the same as the installed handler */
  190. if (handler_obj->address_space.handler != handler) {
  191. status = AE_BAD_PARAMETER;
  192. goto unlock_and_exit;
  193. }
  194. /* Matched space_id, first dereference this in the Regions */
  195. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  196. "Removing address handler %p(%p) for region %s "
  197. "on Device %p(%p)\n",
  198. handler_obj, handler,
  199. acpi_ut_get_region_name(space_id),
  200. node, obj_desc));
  201. region_obj = handler_obj->address_space.region_list;
  202. /* Walk the handler's region list */
  203. while (region_obj) {
  204. /*
  205. * First disassociate the handler from the region.
  206. *
  207. * NOTE: this doesn't mean that the region goes away
  208. * The region is just inaccessible as indicated to
  209. * the _REG method
  210. */
  211. acpi_ev_detach_region(region_obj, TRUE);
  212. /*
  213. * Walk the list: Just grab the head because the
  214. * detach_region removed the previous head.
  215. */
  216. region_obj =
  217. handler_obj->address_space.region_list;
  218. }
  219. /* Remove this Handler object from the list */
  220. *last_obj_ptr = handler_obj->address_space.next;
  221. /* Now we can delete the handler object */
  222. acpi_ut_remove_reference(handler_obj);
  223. goto unlock_and_exit;
  224. }
  225. /* Walk the linked list of handlers */
  226. last_obj_ptr = &handler_obj->address_space.next;
  227. handler_obj = handler_obj->address_space.next;
  228. }
  229. /* The handler does not exist */
  230. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  231. "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",
  232. handler, acpi_ut_get_region_name(space_id), space_id,
  233. node, obj_desc));
  234. status = AE_NOT_EXIST;
  235. unlock_and_exit:
  236. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  237. return_ACPI_STATUS(status);
  238. }
  239. ACPI_EXPORT_SYMBOL(acpi_remove_address_space_handler)