evxfregn.c 9.1 KB

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