utaddress.c revision 1.1 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 christos * Copyright (C) 2000 - 2013, 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 #define __UTADDRESS_C__
45 1.1 christos
46 1.1 christos #include "acpi.h"
47 1.1 christos #include "accommon.h"
48 1.1 christos #include "acnamesp.h"
49 1.1 christos
50 1.1 christos
51 1.1 christos #define _COMPONENT ACPI_UTILITIES
52 1.1 christos ACPI_MODULE_NAME ("utaddress")
53 1.1 christos
54 1.1 christos
55 1.1 christos /*******************************************************************************
56 1.1 christos *
57 1.1 christos * FUNCTION: AcpiUtAddAddressRange
58 1.1 christos *
59 1.1 christos * PARAMETERS: SpaceId - Address space ID
60 1.1 christos * Address - OpRegion start address
61 1.1 christos * Length - OpRegion length
62 1.1 christos * RegionNode - OpRegion namespace node
63 1.1 christos *
64 1.1 christos * RETURN: Status
65 1.1 christos *
66 1.1 christos * DESCRIPTION: Add the Operation Region address range to the global list.
67 1.1 christos * The only supported Space IDs are Memory and I/O. Called when
68 1.1 christos * the OpRegion address/length operands are fully evaluated.
69 1.1 christos *
70 1.1 christos * MUTEX: Locks the namespace
71 1.1 christos *
72 1.1 christos * NOTE: Because this interface is only called when an OpRegion argument
73 1.1 christos * list is evaluated, there cannot be any duplicate RegionNodes.
74 1.1 christos * Duplicate Address/Length values are allowed, however, so that multiple
75 1.1 christos * address conflicts can be detected.
76 1.1 christos *
77 1.1 christos ******************************************************************************/
78 1.1 christos
79 1.1 christos ACPI_STATUS
80 1.1 christos AcpiUtAddAddressRange (
81 1.1 christos ACPI_ADR_SPACE_TYPE SpaceId,
82 1.1 christos ACPI_PHYSICAL_ADDRESS Address,
83 1.1 christos UINT32 Length,
84 1.1 christos ACPI_NAMESPACE_NODE *RegionNode)
85 1.1 christos {
86 1.1 christos ACPI_ADDRESS_RANGE *RangeInfo;
87 1.1 christos ACPI_STATUS Status;
88 1.1 christos
89 1.1 christos
90 1.1 christos ACPI_FUNCTION_TRACE (UtAddAddressRange);
91 1.1 christos
92 1.1 christos
93 1.1 christos if ((SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
94 1.1 christos (SpaceId != ACPI_ADR_SPACE_SYSTEM_IO))
95 1.1 christos {
96 1.1 christos return_ACPI_STATUS (AE_OK);
97 1.1 christos }
98 1.1 christos
99 1.1 christos /* Allocate/init a new info block, add it to the appropriate list */
100 1.1 christos
101 1.1 christos RangeInfo = ACPI_ALLOCATE (sizeof (ACPI_ADDRESS_RANGE));
102 1.1 christos if (!RangeInfo)
103 1.1 christos {
104 1.1 christos return_ACPI_STATUS (AE_NO_MEMORY);
105 1.1 christos }
106 1.1 christos
107 1.1 christos RangeInfo->StartAddress = Address;
108 1.1 christos RangeInfo->EndAddress = (Address + Length - 1);
109 1.1 christos RangeInfo->RegionNode = RegionNode;
110 1.1 christos
111 1.1 christos Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
112 1.1 christos if (ACPI_FAILURE (Status))
113 1.1 christos {
114 1.1 christos ACPI_FREE (RangeInfo);
115 1.1 christos return_ACPI_STATUS (Status);
116 1.1 christos }
117 1.1 christos
118 1.1 christos RangeInfo->Next = AcpiGbl_AddressRangeList[SpaceId];
119 1.1 christos AcpiGbl_AddressRangeList[SpaceId] = RangeInfo;
120 1.1 christos
121 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
122 1.1 christos "\nAdded [%4.4s] address range: 0x%p-0x%p\n",
123 1.1 christos AcpiUtGetNodeName (RangeInfo->RegionNode),
124 1.1 christos ACPI_CAST_PTR (void, Address),
125 1.1 christos ACPI_CAST_PTR (void, RangeInfo->EndAddress)));
126 1.1 christos
127 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
128 1.1 christos return_ACPI_STATUS (AE_OK);
129 1.1 christos }
130 1.1 christos
131 1.1 christos
132 1.1 christos /*******************************************************************************
133 1.1 christos *
134 1.1 christos * FUNCTION: AcpiUtRemoveAddressRange
135 1.1 christos *
136 1.1 christos * PARAMETERS: SpaceId - Address space ID
137 1.1 christos * RegionNode - OpRegion namespace node
138 1.1 christos *
139 1.1 christos * RETURN: None
140 1.1 christos *
141 1.1 christos * DESCRIPTION: Remove the Operation Region from the global list. The only
142 1.1 christos * supported Space IDs are Memory and I/O. Called when an
143 1.1 christos * OpRegion is deleted.
144 1.1 christos *
145 1.1 christos * MUTEX: Assumes the namespace is locked
146 1.1 christos *
147 1.1 christos ******************************************************************************/
148 1.1 christos
149 1.1 christos void
150 1.1 christos AcpiUtRemoveAddressRange (
151 1.1 christos ACPI_ADR_SPACE_TYPE SpaceId,
152 1.1 christos ACPI_NAMESPACE_NODE *RegionNode)
153 1.1 christos {
154 1.1 christos ACPI_ADDRESS_RANGE *RangeInfo;
155 1.1 christos ACPI_ADDRESS_RANGE *Prev;
156 1.1 christos
157 1.1 christos
158 1.1 christos ACPI_FUNCTION_TRACE (UtRemoveAddressRange);
159 1.1 christos
160 1.1 christos
161 1.1 christos if ((SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
162 1.1 christos (SpaceId != ACPI_ADR_SPACE_SYSTEM_IO))
163 1.1 christos {
164 1.1 christos return_VOID;
165 1.1 christos }
166 1.1 christos
167 1.1 christos /* Get the appropriate list head and check the list */
168 1.1 christos
169 1.1 christos RangeInfo = Prev = AcpiGbl_AddressRangeList[SpaceId];
170 1.1 christos while (RangeInfo)
171 1.1 christos {
172 1.1 christos if (RangeInfo->RegionNode == RegionNode)
173 1.1 christos {
174 1.1 christos if (RangeInfo == Prev) /* Found at list head */
175 1.1 christos {
176 1.1 christos AcpiGbl_AddressRangeList[SpaceId] = RangeInfo->Next;
177 1.1 christos }
178 1.1 christos else
179 1.1 christos {
180 1.1 christos Prev->Next = RangeInfo->Next;
181 1.1 christos }
182 1.1 christos
183 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
184 1.1 christos "\nRemoved [%4.4s] address range: 0x%p-0x%p\n",
185 1.1 christos AcpiUtGetNodeName (RangeInfo->RegionNode),
186 1.1 christos ACPI_CAST_PTR (void, RangeInfo->StartAddress),
187 1.1 christos ACPI_CAST_PTR (void, RangeInfo->EndAddress)));
188 1.1 christos
189 1.1 christos ACPI_FREE (RangeInfo);
190 1.1 christos return_VOID;
191 1.1 christos }
192 1.1 christos
193 1.1 christos Prev = RangeInfo;
194 1.1 christos RangeInfo = RangeInfo->Next;
195 1.1 christos }
196 1.1 christos
197 1.1 christos return_VOID;
198 1.1 christos }
199 1.1 christos
200 1.1 christos
201 1.1 christos /*******************************************************************************
202 1.1 christos *
203 1.1 christos * FUNCTION: AcpiUtCheckAddressRange
204 1.1 christos *
205 1.1 christos * PARAMETERS: SpaceId - Address space ID
206 1.1 christos * Address - Start address
207 1.1 christos * Length - Length of address range
208 1.1 christos * Warn - TRUE if warning on overlap desired
209 1.1 christos *
210 1.1 christos * RETURN: Count of the number of conflicts detected. Zero is always
211 1.1 christos * returned for Space IDs other than Memory or I/O.
212 1.1 christos *
213 1.1 christos * DESCRIPTION: Check if the input address range overlaps any of the
214 1.1 christos * ASL operation region address ranges. The only supported
215 1.1 christos * Space IDs are Memory and I/O.
216 1.1 christos *
217 1.1 christos * MUTEX: Assumes the namespace is locked.
218 1.1 christos *
219 1.1 christos ******************************************************************************/
220 1.1 christos
221 1.1 christos UINT32
222 1.1 christos AcpiUtCheckAddressRange (
223 1.1 christos ACPI_ADR_SPACE_TYPE SpaceId,
224 1.1 christos ACPI_PHYSICAL_ADDRESS Address,
225 1.1 christos UINT32 Length,
226 1.1 christos BOOLEAN Warn)
227 1.1 christos {
228 1.1 christos ACPI_ADDRESS_RANGE *RangeInfo;
229 1.1 christos ACPI_PHYSICAL_ADDRESS EndAddress;
230 1.1 christos char *Pathname;
231 1.1 christos UINT32 OverlapCount = 0;
232 1.1 christos
233 1.1 christos
234 1.1 christos ACPI_FUNCTION_TRACE (UtCheckAddressRange);
235 1.1 christos
236 1.1 christos
237 1.1 christos if ((SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
238 1.1 christos (SpaceId != ACPI_ADR_SPACE_SYSTEM_IO))
239 1.1 christos {
240 1.1 christos return_UINT32 (0);
241 1.1 christos }
242 1.1 christos
243 1.1 christos RangeInfo = AcpiGbl_AddressRangeList[SpaceId];
244 1.1 christos EndAddress = Address + Length - 1;
245 1.1 christos
246 1.1 christos /* Check entire list for all possible conflicts */
247 1.1 christos
248 1.1 christos while (RangeInfo)
249 1.1 christos {
250 1.1 christos /*
251 1.1 christos * Check if the requested address/length overlaps this
252 1.1 christos * address range. There are four cases to consider:
253 1.1 christos *
254 1.1 christos * 1) Input address/length is contained completely in the
255 1.1 christos * address range
256 1.1 christos * 2) Input address/length overlaps range at the range start
257 1.1 christos * 3) Input address/length overlaps range at the range end
258 1.1 christos * 4) Input address/length completely encompasses the range
259 1.1 christos */
260 1.1 christos if ((Address <= RangeInfo->EndAddress) &&
261 1.1 christos (EndAddress >= RangeInfo->StartAddress))
262 1.1 christos {
263 1.1 christos /* Found an address range overlap */
264 1.1 christos
265 1.1 christos OverlapCount++;
266 1.1 christos if (Warn) /* Optional warning message */
267 1.1 christos {
268 1.1 christos Pathname = AcpiNsGetExternalPathname (RangeInfo->RegionNode);
269 1.1 christos
270 1.1 christos ACPI_WARNING ((AE_INFO,
271 1.1 christos "%s range 0x%p-0x%p conflicts with OpRegion 0x%p-0x%p (%s)",
272 1.1 christos AcpiUtGetRegionName (SpaceId),
273 1.1 christos ACPI_CAST_PTR (void, Address),
274 1.1 christos ACPI_CAST_PTR (void, EndAddress),
275 1.1 christos ACPI_CAST_PTR (void, RangeInfo->StartAddress),
276 1.1 christos ACPI_CAST_PTR (void, RangeInfo->EndAddress),
277 1.1 christos Pathname));
278 1.1 christos ACPI_FREE (Pathname);
279 1.1 christos }
280 1.1 christos }
281 1.1 christos
282 1.1 christos RangeInfo = RangeInfo->Next;
283 1.1 christos }
284 1.1 christos
285 1.1 christos return_UINT32 (OverlapCount);
286 1.1 christos }
287 1.1 christos
288 1.1 christos
289 1.1 christos /*******************************************************************************
290 1.1 christos *
291 1.1 christos * FUNCTION: AcpiUtDeleteAddressLists
292 1.1 christos *
293 1.1 christos * PARAMETERS: None
294 1.1 christos *
295 1.1 christos * RETURN: None
296 1.1 christos *
297 1.1 christos * DESCRIPTION: Delete all global address range lists (called during
298 1.1 christos * subsystem shutdown).
299 1.1 christos *
300 1.1 christos ******************************************************************************/
301 1.1 christos
302 1.1 christos void
303 1.1 christos AcpiUtDeleteAddressLists (
304 1.1 christos void)
305 1.1 christos {
306 1.1 christos ACPI_ADDRESS_RANGE *Next;
307 1.1 christos ACPI_ADDRESS_RANGE *RangeInfo;
308 1.1 christos int i;
309 1.1 christos
310 1.1 christos
311 1.1 christos /* Delete all elements in all address range lists */
312 1.1 christos
313 1.1 christos for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++)
314 1.1 christos {
315 1.1 christos Next = AcpiGbl_AddressRangeList[i];
316 1.1 christos
317 1.1 christos while (Next)
318 1.1 christos {
319 1.1 christos RangeInfo = Next;
320 1.1 christos Next = RangeInfo->Next;
321 1.1 christos ACPI_FREE (RangeInfo);
322 1.1 christos }
323 1.1 christos
324 1.1 christos AcpiGbl_AddressRangeList[i] = NULL;
325 1.1 christos }
326 1.1 christos }
327