1 /******************************************************************************
3 * Module Name: utaddress - OpRegion address range check
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
49 #define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utaddress")
53 /*******************************************************************************
55 * FUNCTION: AcpiUtAddAddressRange
57 * PARAMETERS: SpaceId - Address space ID
58 * Address - OpRegion start address
59 * Length - OpRegion length
60 * RegionNode - OpRegion namespace node
64 * DESCRIPTION: Add the Operation Region address range to the global list.
65 * The only supported Space IDs are Memory and I/O. Called when
66 * the OpRegion address/length operands are fully evaluated.
68 * MUTEX: Locks the namespace
70 * NOTE: Because this interface is only called when an OpRegion argument
71 * list is evaluated, there cannot be any duplicate RegionNodes.
72 * Duplicate Address/Length values are allowed, however, so that multiple
73 * address conflicts can be detected.
75 ******************************************************************************/
78 AcpiUtAddAddressRange (
79 ACPI_ADR_SPACE_TYPE SpaceId
,
80 ACPI_PHYSICAL_ADDRESS Address
,
82 ACPI_NAMESPACE_NODE
*RegionNode
)
84 ACPI_ADDRESS_RANGE
*RangeInfo
;
87 ACPI_FUNCTION_TRACE (UtAddAddressRange
);
90 if ((SpaceId
!= ACPI_ADR_SPACE_SYSTEM_MEMORY
) &&
91 (SpaceId
!= ACPI_ADR_SPACE_SYSTEM_IO
))
93 return_ACPI_STATUS (AE_OK
);
96 /* Allocate/init a new info block, add it to the appropriate list */
98 RangeInfo
= ACPI_ALLOCATE (sizeof (ACPI_ADDRESS_RANGE
));
101 return_ACPI_STATUS (AE_NO_MEMORY
);
104 RangeInfo
->StartAddress
= Address
;
105 RangeInfo
->EndAddress
= (Address
+ Length
- 1);
106 RangeInfo
->RegionNode
= RegionNode
;
108 RangeInfo
->Next
= AcpiGbl_AddressRangeList
[SpaceId
];
109 AcpiGbl_AddressRangeList
[SpaceId
] = RangeInfo
;
111 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
112 "\nAdded [%4.4s] address range: 0x%8.8X%8.8X-0x%8.8X%8.8X\n",
113 AcpiUtGetNodeName (RangeInfo
->RegionNode
),
114 ACPI_FORMAT_UINT64 (Address
),
115 ACPI_FORMAT_UINT64 (RangeInfo
->EndAddress
)));
117 return_ACPI_STATUS (AE_OK
);
121 /*******************************************************************************
123 * FUNCTION: AcpiUtRemoveAddressRange
125 * PARAMETERS: SpaceId - Address space ID
126 * RegionNode - OpRegion namespace node
130 * DESCRIPTION: Remove the Operation Region from the global list. The only
131 * supported Space IDs are Memory and I/O. Called when an
132 * OpRegion is deleted.
134 * MUTEX: Assumes the namespace is locked
136 ******************************************************************************/
139 AcpiUtRemoveAddressRange (
140 ACPI_ADR_SPACE_TYPE SpaceId
,
141 ACPI_NAMESPACE_NODE
*RegionNode
)
143 ACPI_ADDRESS_RANGE
*RangeInfo
;
144 ACPI_ADDRESS_RANGE
*Prev
;
147 ACPI_FUNCTION_TRACE (UtRemoveAddressRange
);
150 if ((SpaceId
!= ACPI_ADR_SPACE_SYSTEM_MEMORY
) &&
151 (SpaceId
!= ACPI_ADR_SPACE_SYSTEM_IO
))
156 /* Get the appropriate list head and check the list */
158 RangeInfo
= Prev
= AcpiGbl_AddressRangeList
[SpaceId
];
161 if (RangeInfo
->RegionNode
== RegionNode
)
163 if (RangeInfo
== Prev
) /* Found at list head */
165 AcpiGbl_AddressRangeList
[SpaceId
] = RangeInfo
->Next
;
169 Prev
->Next
= RangeInfo
->Next
;
172 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
173 "\nRemoved [%4.4s] address range: 0x%8.8X%8.8X-0x%8.8X%8.8X\n",
174 AcpiUtGetNodeName (RangeInfo
->RegionNode
),
175 ACPI_FORMAT_UINT64 (RangeInfo
->StartAddress
),
176 ACPI_FORMAT_UINT64 (RangeInfo
->EndAddress
)));
178 ACPI_FREE (RangeInfo
);
183 RangeInfo
= RangeInfo
->Next
;
190 /*******************************************************************************
192 * FUNCTION: AcpiUtCheckAddressRange
194 * PARAMETERS: SpaceId - Address space ID
195 * Address - Start address
196 * Length - Length of address range
197 * Warn - TRUE if warning on overlap desired
199 * RETURN: Count of the number of conflicts detected. Zero is always
200 * returned for Space IDs other than Memory or I/O.
202 * DESCRIPTION: Check if the input address range overlaps any of the
203 * ASL operation region address ranges. The only supported
204 * Space IDs are Memory and I/O.
206 * MUTEX: Assumes the namespace is locked.
208 ******************************************************************************/
211 AcpiUtCheckAddressRange (
212 ACPI_ADR_SPACE_TYPE SpaceId
,
213 ACPI_PHYSICAL_ADDRESS Address
,
217 ACPI_ADDRESS_RANGE
*RangeInfo
;
218 ACPI_PHYSICAL_ADDRESS EndAddress
;
220 UINT32 OverlapCount
= 0;
223 ACPI_FUNCTION_TRACE (UtCheckAddressRange
);
226 if ((SpaceId
!= ACPI_ADR_SPACE_SYSTEM_MEMORY
) &&
227 (SpaceId
!= ACPI_ADR_SPACE_SYSTEM_IO
))
232 RangeInfo
= AcpiGbl_AddressRangeList
[SpaceId
];
233 EndAddress
= Address
+ Length
- 1;
235 /* Check entire list for all possible conflicts */
240 * Check if the requested address/length overlaps this
241 * address range. There are four cases to consider:
243 * 1) Input address/length is contained completely in the
245 * 2) Input address/length overlaps range at the range start
246 * 3) Input address/length overlaps range at the range end
247 * 4) Input address/length completely encompasses the range
249 if ((Address
<= RangeInfo
->EndAddress
) &&
250 (EndAddress
>= RangeInfo
->StartAddress
))
252 /* Found an address range overlap */
255 if (Warn
) /* Optional warning message */
257 Pathname
= AcpiNsGetNormalizedPathname (RangeInfo
->RegionNode
, TRUE
);
259 ACPI_WARNING ((AE_INFO
,
260 "%s range 0x%8.8X%8.8X-0x%8.8X%8.8X conflicts with OpRegion 0x%8.8X%8.8X-0x%8.8X%8.8X (%s)",
261 AcpiUtGetRegionName (SpaceId
),
262 ACPI_FORMAT_UINT64 (Address
),
263 ACPI_FORMAT_UINT64 (EndAddress
),
264 ACPI_FORMAT_UINT64 (RangeInfo
->StartAddress
),
265 ACPI_FORMAT_UINT64 (RangeInfo
->EndAddress
),
267 ACPI_FREE (Pathname
);
271 RangeInfo
= RangeInfo
->Next
;
274 return_UINT32 (OverlapCount
);
278 /*******************************************************************************
280 * FUNCTION: AcpiUtDeleteAddressLists
286 * DESCRIPTION: Delete all global address range lists (called during
287 * subsystem shutdown).
289 ******************************************************************************/
292 AcpiUtDeleteAddressLists (
295 ACPI_ADDRESS_RANGE
*Next
;
296 ACPI_ADDRESS_RANGE
*RangeInfo
;
300 /* Delete all elements in all address range lists */
302 for (i
= 0; i
< ACPI_ADDRESS_RANGE_MAX
; i
++)
304 Next
= AcpiGbl_AddressRangeList
[i
];
309 Next
= RangeInfo
->Next
;
310 ACPI_FREE (RangeInfo
);
313 AcpiGbl_AddressRangeList
[i
] = NULL
;