utaddress.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /******************************************************************************
  2. *
  3. * Module Name: utaddress - op_region address range check
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acnamesp.h"
  45. #define _COMPONENT ACPI_UTILITIES
  46. ACPI_MODULE_NAME("utaddress")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_ut_add_address_range
  50. *
  51. * PARAMETERS: space_id - Address space ID
  52. * Address - op_region start address
  53. * Length - op_region length
  54. * region_node - op_region namespace node
  55. *
  56. * RETURN: Status
  57. *
  58. * DESCRIPTION: Add the Operation Region address range to the global list.
  59. * The only supported Space IDs are Memory and I/O. Called when
  60. * the op_region address/length operands are fully evaluated.
  61. *
  62. * MUTEX: Locks the namespace
  63. *
  64. * NOTE: Because this interface is only called when an op_region argument
  65. * list is evaluated, there cannot be any duplicate region_nodes.
  66. * Duplicate Address/Length values are allowed, however, so that multiple
  67. * address conflicts can be detected.
  68. *
  69. ******************************************************************************/
  70. acpi_status
  71. acpi_ut_add_address_range(acpi_adr_space_type space_id,
  72. acpi_physical_address address,
  73. u32 length, struct acpi_namespace_node *region_node)
  74. {
  75. struct acpi_address_range *range_info;
  76. acpi_status status;
  77. ACPI_FUNCTION_TRACE(ut_add_address_range);
  78. if ((space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
  79. (space_id != ACPI_ADR_SPACE_SYSTEM_IO)) {
  80. return_ACPI_STATUS(AE_OK);
  81. }
  82. /* Allocate/init a new info block, add it to the appropriate list */
  83. range_info = ACPI_ALLOCATE(sizeof(struct acpi_address_range));
  84. if (!range_info) {
  85. return_ACPI_STATUS(AE_NO_MEMORY);
  86. }
  87. range_info->start_address = address;
  88. range_info->end_address = (address + length - 1);
  89. range_info->region_node = region_node;
  90. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  91. if (ACPI_FAILURE(status)) {
  92. ACPI_FREE(range_info);
  93. return_ACPI_STATUS(status);
  94. }
  95. range_info->next = acpi_gbl_address_range_list[space_id];
  96. acpi_gbl_address_range_list[space_id] = range_info;
  97. ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
  98. "\nAdded [%4.4s] address range: 0x%p-0x%p\n",
  99. acpi_ut_get_node_name(range_info->region_node),
  100. ACPI_CAST_PTR(void, address),
  101. ACPI_CAST_PTR(void, range_info->end_address)));
  102. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  103. return_ACPI_STATUS(AE_OK);
  104. }
  105. /*******************************************************************************
  106. *
  107. * FUNCTION: acpi_ut_remove_address_range
  108. *
  109. * PARAMETERS: space_id - Address space ID
  110. * region_node - op_region namespace node
  111. *
  112. * RETURN: None
  113. *
  114. * DESCRIPTION: Remove the Operation Region from the global list. The only
  115. * supported Space IDs are Memory and I/O. Called when an
  116. * op_region is deleted.
  117. *
  118. * MUTEX: Assumes the namespace is locked
  119. *
  120. ******************************************************************************/
  121. void
  122. acpi_ut_remove_address_range(acpi_adr_space_type space_id,
  123. struct acpi_namespace_node *region_node)
  124. {
  125. struct acpi_address_range *range_info;
  126. struct acpi_address_range *prev;
  127. ACPI_FUNCTION_TRACE(ut_remove_address_range);
  128. if ((space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
  129. (space_id != ACPI_ADR_SPACE_SYSTEM_IO)) {
  130. return_VOID;
  131. }
  132. /* Get the appropriate list head and check the list */
  133. range_info = prev = acpi_gbl_address_range_list[space_id];
  134. while (range_info) {
  135. if (range_info->region_node == region_node) {
  136. if (range_info == prev) { /* Found at list head */
  137. acpi_gbl_address_range_list[space_id] =
  138. range_info->next;
  139. } else {
  140. prev->next = range_info->next;
  141. }
  142. ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
  143. "\nRemoved [%4.4s] address range: 0x%p-0x%p\n",
  144. acpi_ut_get_node_name(range_info->
  145. region_node),
  146. ACPI_CAST_PTR(void,
  147. range_info->
  148. start_address),
  149. ACPI_CAST_PTR(void,
  150. range_info->
  151. end_address)));
  152. ACPI_FREE(range_info);
  153. return_VOID;
  154. }
  155. prev = range_info;
  156. range_info = range_info->next;
  157. }
  158. return_VOID;
  159. }
  160. /*******************************************************************************
  161. *
  162. * FUNCTION: acpi_ut_check_address_range
  163. *
  164. * PARAMETERS: space_id - Address space ID
  165. * Address - Start address
  166. * Length - Length of address range
  167. * Warn - TRUE if warning on overlap desired
  168. *
  169. * RETURN: Count of the number of conflicts detected. Zero is always
  170. * returned for Space IDs other than Memory or I/O.
  171. *
  172. * DESCRIPTION: Check if the input address range overlaps any of the
  173. * ASL operation region address ranges. The only supported
  174. * Space IDs are Memory and I/O.
  175. *
  176. * MUTEX: Assumes the namespace is locked.
  177. *
  178. ******************************************************************************/
  179. u32
  180. acpi_ut_check_address_range(acpi_adr_space_type space_id,
  181. acpi_physical_address address, u32 length, u8 warn)
  182. {
  183. struct acpi_address_range *range_info;
  184. acpi_physical_address end_address;
  185. char *pathname;
  186. u32 overlap_count = 0;
  187. ACPI_FUNCTION_TRACE(ut_check_address_range);
  188. if ((space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
  189. (space_id != ACPI_ADR_SPACE_SYSTEM_IO)) {
  190. return_UINT32(0);
  191. }
  192. range_info = acpi_gbl_address_range_list[space_id];
  193. end_address = address + length - 1;
  194. /* Check entire list for all possible conflicts */
  195. while (range_info) {
  196. /*
  197. * Check if the requested Address/Length overlaps this address_range.
  198. * Four cases to consider:
  199. *
  200. * 1) Input address/length is contained completely in the address range
  201. * 2) Input address/length overlaps range at the range start
  202. * 3) Input address/length overlaps range at the range end
  203. * 4) Input address/length completely encompasses the range
  204. */
  205. if ((address <= range_info->end_address) &&
  206. (end_address >= range_info->start_address)) {
  207. /* Found an address range overlap */
  208. overlap_count++;
  209. if (warn) { /* Optional warning message */
  210. pathname =
  211. acpi_ns_get_external_pathname(range_info->
  212. region_node);
  213. ACPI_WARNING((AE_INFO,
  214. "0x%p-0x%p %s conflicts with Region %s %d",
  215. ACPI_CAST_PTR(void, address),
  216. ACPI_CAST_PTR(void, end_address),
  217. acpi_ut_get_region_name(space_id),
  218. pathname, overlap_count));
  219. ACPI_FREE(pathname);
  220. }
  221. }
  222. range_info = range_info->next;
  223. }
  224. return_UINT32(overlap_count);
  225. }
  226. /*******************************************************************************
  227. *
  228. * FUNCTION: acpi_ut_delete_address_lists
  229. *
  230. * PARAMETERS: None
  231. *
  232. * RETURN: None
  233. *
  234. * DESCRIPTION: Delete all global address range lists (called during
  235. * subsystem shutdown).
  236. *
  237. ******************************************************************************/
  238. void acpi_ut_delete_address_lists(void)
  239. {
  240. struct acpi_address_range *next;
  241. struct acpi_address_range *range_info;
  242. int i;
  243. /* Delete all elements in all address range lists */
  244. for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++) {
  245. next = acpi_gbl_address_range_list[i];
  246. while (next) {
  247. range_info = next;
  248. next = range_info->next;
  249. ACPI_FREE(range_info);
  250. }
  251. acpi_gbl_address_range_list[i] = NULL;
  252. }
  253. }