utaddress.c revision 1.1.1.3 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: utaddress - OpRegion address range check
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1.1.3 christos * Copyright (C) 2000 - 2015, Intel Corp.
9 1.1 christos * All rights reserved.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions, and the following disclaimer,
16 1.1 christos * without modification.
17 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 christos * including a substantially similar Disclaimer requirement for further
21 1.1 christos * binary redistribution.
22 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 christos * of any contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * Alternatively, this software may be distributed under the terms of the
27 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 christos * Software Foundation.
29 1.1 christos *
30 1.1 christos * NO WARRANTY
31 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #include "acpi.h"
45 1.1 christos #include "accommon.h"
46 1.1 christos #include "acnamesp.h"
47 1.1 christos
48 1.1 christos
49 1.1 christos #define _COMPONENT ACPI_UTILITIES
50 1.1 christos ACPI_MODULE_NAME ("utaddress")
51 1.1 christos
52 1.1 christos
53 1.1 christos /*******************************************************************************
54 1.1 christos *
55 1.1 christos * FUNCTION: AcpiUtAddAddressRange
56 1.1 christos *
57 1.1 christos * PARAMETERS: SpaceId - Address space ID
58 1.1 christos * Address - OpRegion start address
59 1.1 christos * Length - OpRegion length
60 1.1 christos * RegionNode - OpRegion namespace node
61 1.1 christos *
62 1.1 christos * RETURN: Status
63 1.1 christos *
64 1.1 christos * DESCRIPTION: Add the Operation Region address range to the global list.
65 1.1 christos * The only supported Space IDs are Memory and I/O. Called when
66 1.1 christos * the OpRegion address/length operands are fully evaluated.
67 1.1 christos *
68 1.1 christos * MUTEX: Locks the namespace
69 1.1 christos *
70 1.1 christos * NOTE: Because this interface is only called when an OpRegion argument
71 1.1 christos * list is evaluated, there cannot be any duplicate RegionNodes.
72 1.1 christos * Duplicate Address/Length values are allowed, however, so that multiple
73 1.1 christos * address conflicts can be detected.
74 1.1 christos *
75 1.1 christos ******************************************************************************/
76 1.1 christos
77 1.1 christos ACPI_STATUS
78 1.1 christos AcpiUtAddAddressRange (
79 1.1 christos ACPI_ADR_SPACE_TYPE SpaceId,
80 1.1 christos ACPI_PHYSICAL_ADDRESS Address,
81 1.1 christos UINT32 Length,
82 1.1 christos ACPI_NAMESPACE_NODE *RegionNode)
83 1.1 christos {
84 1.1 christos ACPI_ADDRESS_RANGE *RangeInfo;
85 1.1 christos ACPI_STATUS Status;
86 1.1 christos
87 1.1 christos
88 1.1 christos ACPI_FUNCTION_TRACE (UtAddAddressRange);
89 1.1 christos
90 1.1 christos
91 1.1 christos if ((SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
92 1.1 christos (SpaceId != ACPI_ADR_SPACE_SYSTEM_IO))
93 1.1 christos {
94 1.1 christos return_ACPI_STATUS (AE_OK);
95 1.1 christos }
96 1.1 christos
97 1.1 christos /* Allocate/init a new info block, add it to the appropriate list */
98 1.1 christos
99 1.1 christos RangeInfo = ACPI_ALLOCATE (sizeof (ACPI_ADDRESS_RANGE));
100 1.1 christos if (!RangeInfo)
101 1.1 christos {
102 1.1 christos return_ACPI_STATUS (AE_NO_MEMORY);
103 1.1 christos }
104 1.1 christos
105 1.1 christos RangeInfo->StartAddress = Address;
106 1.1 christos RangeInfo->EndAddress = (Address + Length - 1);
107 1.1 christos RangeInfo->RegionNode = RegionNode;
108 1.1 christos
109 1.1 christos Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
110 1.1 christos if (ACPI_FAILURE (Status))
111 1.1 christos {
112 1.1 christos ACPI_FREE (RangeInfo);
113 1.1 christos return_ACPI_STATUS (Status);
114 1.1 christos }
115 1.1 christos
116 1.1 christos RangeInfo->Next = AcpiGbl_AddressRangeList[SpaceId];
117 1.1 christos AcpiGbl_AddressRangeList[SpaceId] = RangeInfo;
118 1.1 christos
119 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
120 1.1.1.3 christos "\nAdded [%4.4s] address range: 0x%8.8X%8.8X-0x%8.8X%8.8X\n",
121 1.1 christos AcpiUtGetNodeName (RangeInfo->RegionNode),
122 1.1.1.3 christos ACPI_FORMAT_UINT64 (Address),
123 1.1.1.3 christos ACPI_FORMAT_UINT64 (RangeInfo->EndAddress)));
124 1.1 christos
125 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
126 1.1 christos return_ACPI_STATUS (AE_OK);
127 1.1 christos }
128 1.1 christos
129 1.1 christos
130 1.1 christos /*******************************************************************************
131 1.1 christos *
132 1.1 christos * FUNCTION: AcpiUtRemoveAddressRange
133 1.1 christos *
134 1.1 christos * PARAMETERS: SpaceId - Address space ID
135 1.1 christos * RegionNode - OpRegion namespace node
136 1.1 christos *
137 1.1 christos * RETURN: None
138 1.1 christos *
139 1.1 christos * DESCRIPTION: Remove the Operation Region from the global list. The only
140 1.1 christos * supported Space IDs are Memory and I/O. Called when an
141 1.1 christos * OpRegion is deleted.
142 1.1 christos *
143 1.1 christos * MUTEX: Assumes the namespace is locked
144 1.1 christos *
145 1.1 christos ******************************************************************************/
146 1.1 christos
147 1.1 christos void
148 1.1 christos AcpiUtRemoveAddressRange (
149 1.1 christos ACPI_ADR_SPACE_TYPE SpaceId,
150 1.1 christos ACPI_NAMESPACE_NODE *RegionNode)
151 1.1 christos {
152 1.1 christos ACPI_ADDRESS_RANGE *RangeInfo;
153 1.1 christos ACPI_ADDRESS_RANGE *Prev;
154 1.1 christos
155 1.1 christos
156 1.1 christos ACPI_FUNCTION_TRACE (UtRemoveAddressRange);
157 1.1 christos
158 1.1 christos
159 1.1 christos if ((SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
160 1.1 christos (SpaceId != ACPI_ADR_SPACE_SYSTEM_IO))
161 1.1 christos {
162 1.1 christos return_VOID;
163 1.1 christos }
164 1.1 christos
165 1.1 christos /* Get the appropriate list head and check the list */
166 1.1 christos
167 1.1 christos RangeInfo = Prev = AcpiGbl_AddressRangeList[SpaceId];
168 1.1 christos while (RangeInfo)
169 1.1 christos {
170 1.1 christos if (RangeInfo->RegionNode == RegionNode)
171 1.1 christos {
172 1.1 christos if (RangeInfo == Prev) /* Found at list head */
173 1.1 christos {
174 1.1 christos AcpiGbl_AddressRangeList[SpaceId] = RangeInfo->Next;
175 1.1 christos }
176 1.1 christos else
177 1.1 christos {
178 1.1 christos Prev->Next = RangeInfo->Next;
179 1.1 christos }
180 1.1 christos
181 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
182 1.1.1.3 christos "\nRemoved [%4.4s] address range: 0x%8.8X%8.8X-0x%8.8X%8.8X\n",
183 1.1 christos AcpiUtGetNodeName (RangeInfo->RegionNode),
184 1.1.1.3 christos ACPI_FORMAT_UINT64 (RangeInfo->StartAddress),
185 1.1.1.3 christos ACPI_FORMAT_UINT64 (RangeInfo->EndAddress)));
186 1.1 christos
187 1.1 christos ACPI_FREE (RangeInfo);
188 1.1 christos return_VOID;
189 1.1 christos }
190 1.1 christos
191 1.1 christos Prev = RangeInfo;
192 1.1 christos RangeInfo = RangeInfo->Next;
193 1.1 christos }
194 1.1 christos
195 1.1 christos return_VOID;
196 1.1 christos }
197 1.1 christos
198 1.1 christos
199 1.1 christos /*******************************************************************************
200 1.1 christos *
201 1.1 christos * FUNCTION: AcpiUtCheckAddressRange
202 1.1 christos *
203 1.1 christos * PARAMETERS: SpaceId - Address space ID
204 1.1 christos * Address - Start address
205 1.1 christos * Length - Length of address range
206 1.1 christos * Warn - TRUE if warning on overlap desired
207 1.1 christos *
208 1.1 christos * RETURN: Count of the number of conflicts detected. Zero is always
209 1.1 christos * returned for Space IDs other than Memory or I/O.
210 1.1 christos *
211 1.1 christos * DESCRIPTION: Check if the input address range overlaps any of the
212 1.1 christos * ASL operation region address ranges. The only supported
213 1.1 christos * Space IDs are Memory and I/O.
214 1.1 christos *
215 1.1 christos * MUTEX: Assumes the namespace is locked.
216 1.1 christos *
217 1.1 christos ******************************************************************************/
218 1.1 christos
219 1.1 christos UINT32
220 1.1 christos AcpiUtCheckAddressRange (
221 1.1 christos ACPI_ADR_SPACE_TYPE SpaceId,
222 1.1 christos ACPI_PHYSICAL_ADDRESS Address,
223 1.1 christos UINT32 Length,
224 1.1 christos BOOLEAN Warn)
225 1.1 christos {
226 1.1 christos ACPI_ADDRESS_RANGE *RangeInfo;
227 1.1 christos ACPI_PHYSICAL_ADDRESS EndAddress;
228 1.1 christos char *Pathname;
229 1.1 christos UINT32 OverlapCount = 0;
230 1.1 christos
231 1.1 christos
232 1.1 christos ACPI_FUNCTION_TRACE (UtCheckAddressRange);
233 1.1 christos
234 1.1 christos
235 1.1 christos if ((SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
236 1.1 christos (SpaceId != ACPI_ADR_SPACE_SYSTEM_IO))
237 1.1 christos {
238 1.1 christos return_UINT32 (0);
239 1.1 christos }
240 1.1 christos
241 1.1 christos RangeInfo = AcpiGbl_AddressRangeList[SpaceId];
242 1.1 christos EndAddress = Address + Length - 1;
243 1.1 christos
244 1.1 christos /* Check entire list for all possible conflicts */
245 1.1 christos
246 1.1 christos while (RangeInfo)
247 1.1 christos {
248 1.1 christos /*
249 1.1 christos * Check if the requested address/length overlaps this
250 1.1 christos * address range. There are four cases to consider:
251 1.1 christos *
252 1.1 christos * 1) Input address/length is contained completely in the
253 1.1 christos * address range
254 1.1 christos * 2) Input address/length overlaps range at the range start
255 1.1 christos * 3) Input address/length overlaps range at the range end
256 1.1 christos * 4) Input address/length completely encompasses the range
257 1.1 christos */
258 1.1 christos if ((Address <= RangeInfo->EndAddress) &&
259 1.1 christos (EndAddress >= RangeInfo->StartAddress))
260 1.1 christos {
261 1.1 christos /* Found an address range overlap */
262 1.1 christos
263 1.1 christos OverlapCount++;
264 1.1 christos if (Warn) /* Optional warning message */
265 1.1 christos {
266 1.1 christos Pathname = AcpiNsGetExternalPathname (RangeInfo->RegionNode);
267 1.1 christos
268 1.1 christos ACPI_WARNING ((AE_INFO,
269 1.1.1.3 christos "%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)",
270 1.1 christos AcpiUtGetRegionName (SpaceId),
271 1.1.1.3 christos ACPI_FORMAT_UINT64 (Address),
272 1.1.1.3 christos ACPI_FORMAT_UINT64 (EndAddress),
273 1.1.1.3 christos ACPI_FORMAT_UINT64 (RangeInfo->StartAddress),
274 1.1.1.3 christos ACPI_FORMAT_UINT64 (RangeInfo->EndAddress),
275 1.1 christos Pathname));
276 1.1 christos ACPI_FREE (Pathname);
277 1.1 christos }
278 1.1 christos }
279 1.1 christos
280 1.1 christos RangeInfo = RangeInfo->Next;
281 1.1 christos }
282 1.1 christos
283 1.1 christos return_UINT32 (OverlapCount);
284 1.1 christos }
285 1.1 christos
286 1.1 christos
287 1.1 christos /*******************************************************************************
288 1.1 christos *
289 1.1 christos * FUNCTION: AcpiUtDeleteAddressLists
290 1.1 christos *
291 1.1 christos * PARAMETERS: None
292 1.1 christos *
293 1.1 christos * RETURN: None
294 1.1 christos *
295 1.1 christos * DESCRIPTION: Delete all global address range lists (called during
296 1.1 christos * subsystem shutdown).
297 1.1 christos *
298 1.1 christos ******************************************************************************/
299 1.1 christos
300 1.1 christos void
301 1.1 christos AcpiUtDeleteAddressLists (
302 1.1 christos void)
303 1.1 christos {
304 1.1 christos ACPI_ADDRESS_RANGE *Next;
305 1.1 christos ACPI_ADDRESS_RANGE *RangeInfo;
306 1.1 christos int i;
307 1.1 christos
308 1.1 christos
309 1.1 christos /* Delete all elements in all address range lists */
310 1.1 christos
311 1.1 christos for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++)
312 1.1 christos {
313 1.1 christos Next = AcpiGbl_AddressRangeList[i];
314 1.1 christos
315 1.1 christos while (Next)
316 1.1 christos {
317 1.1 christos RangeInfo = Next;
318 1.1 christos Next = RangeInfo->Next;
319 1.1 christos ACPI_FREE (RangeInfo);
320 1.1 christos }
321 1.1 christos
322 1.1 christos AcpiGbl_AddressRangeList[i] = NULL;
323 1.1 christos }
324 1.1 christos }
325