evxfregn.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer /******************************************************************************
2 1.1.1.2.2.2 bouyer *
3 1.1.1.2.2.2 bouyer * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and
4 1.1.1.2.2.2 bouyer * Address Spaces.
5 1.1.1.2.2.2 bouyer *
6 1.1.1.2.2.2 bouyer *****************************************************************************/
7 1.1.1.2.2.2 bouyer
8 1.1.1.2.2.2 bouyer /*
9 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
10 1.1.1.2.2.2 bouyer * All rights reserved.
11 1.1.1.2.2.2 bouyer *
12 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
13 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
14 1.1.1.2.2.2 bouyer * are met:
15 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
16 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
17 1.1.1.2.2.2 bouyer * without modification.
18 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
22 1.1.1.2.2.2 bouyer * binary redistribution.
23 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
25 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
26 1.1.1.2.2.2 bouyer *
27 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
28 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.2.2.2 bouyer * Software Foundation.
30 1.1.1.2.2.2 bouyer *
31 1.1.1.2.2.2 bouyer * NO WARRANTY
32 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
43 1.1.1.2.2.2 bouyer */
44 1.1.1.2.2.2 bouyer
45 1.1.1.2.2.2 bouyer #define __EVXFREGN_C__
46 1.1.1.2.2.2 bouyer
47 1.1.1.2.2.2 bouyer #include "acpi.h"
48 1.1.1.2.2.2 bouyer #include "accommon.h"
49 1.1.1.2.2.2 bouyer #include "acnamesp.h"
50 1.1.1.2.2.2 bouyer #include "acevents.h"
51 1.1.1.2.2.2 bouyer
52 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_EVENTS
53 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("evxfregn")
54 1.1.1.2.2.2 bouyer
55 1.1.1.2.2.2 bouyer
56 1.1.1.2.2.2 bouyer /*******************************************************************************
57 1.1.1.2.2.2 bouyer *
58 1.1.1.2.2.2 bouyer * FUNCTION: AcpiInstallAddressSpaceHandler
59 1.1.1.2.2.2 bouyer *
60 1.1.1.2.2.2 bouyer * PARAMETERS: Device - Handle for the device
61 1.1.1.2.2.2 bouyer * SpaceId - The address space ID
62 1.1.1.2.2.2 bouyer * Handler - Address of the handler
63 1.1.1.2.2.2 bouyer * Setup - Address of the setup function
64 1.1.1.2.2.2 bouyer * Context - Value passed to the handler on each access
65 1.1.1.2.2.2 bouyer *
66 1.1.1.2.2.2 bouyer * RETURN: Status
67 1.1.1.2.2.2 bouyer *
68 1.1.1.2.2.2 bouyer * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
69 1.1.1.2.2.2 bouyer *
70 1.1.1.2.2.2 bouyer * NOTE: This function should only be called after AcpiEnableSubsystem has
71 1.1.1.2.2.2 bouyer * been called. This is because any _REG methods associated with the Space ID
72 1.1.1.2.2.2 bouyer * are executed here, and these methods can only be safely executed after
73 1.1.1.2.2.2 bouyer * the default handlers have been installed and the hardware has been
74 1.1.1.2.2.2 bouyer * initialized (via AcpiEnableSubsystem.)
75 1.1.1.2.2.2 bouyer *
76 1.1.1.2.2.2 bouyer ******************************************************************************/
77 1.1.1.2.2.2 bouyer
78 1.1.1.2.2.2 bouyer ACPI_STATUS
79 1.1.1.2.2.2 bouyer AcpiInstallAddressSpaceHandler (
80 1.1.1.2.2.2 bouyer ACPI_HANDLE Device,
81 1.1.1.2.2.2 bouyer ACPI_ADR_SPACE_TYPE SpaceId,
82 1.1.1.2.2.2 bouyer ACPI_ADR_SPACE_HANDLER Handler,
83 1.1.1.2.2.2 bouyer ACPI_ADR_SPACE_SETUP Setup,
84 1.1.1.2.2.2 bouyer void *Context)
85 1.1.1.2.2.2 bouyer {
86 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *Node;
87 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
88 1.1.1.2.2.2 bouyer
89 1.1.1.2.2.2 bouyer
90 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (AcpiInstallAddressSpaceHandler);
91 1.1.1.2.2.2 bouyer
92 1.1.1.2.2.2 bouyer
93 1.1.1.2.2.2 bouyer /* Parameter validation */
94 1.1.1.2.2.2 bouyer
95 1.1.1.2.2.2 bouyer if (!Device)
96 1.1.1.2.2.2 bouyer {
97 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
98 1.1.1.2.2.2 bouyer }
99 1.1.1.2.2.2 bouyer
100 1.1.1.2.2.2 bouyer Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
101 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
102 1.1.1.2.2.2 bouyer {
103 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
104 1.1.1.2.2.2 bouyer }
105 1.1.1.2.2.2 bouyer
106 1.1.1.2.2.2 bouyer /* Convert and validate the device handle */
107 1.1.1.2.2.2 bouyer
108 1.1.1.2.2.2 bouyer Node = AcpiNsValidateHandle (Device);
109 1.1.1.2.2.2 bouyer if (!Node)
110 1.1.1.2.2.2 bouyer {
111 1.1.1.2.2.2 bouyer Status = AE_BAD_PARAMETER;
112 1.1.1.2.2.2 bouyer goto UnlockAndExit;
113 1.1.1.2.2.2 bouyer }
114 1.1.1.2.2.2 bouyer
115 1.1.1.2.2.2 bouyer /* Install the handler for all Regions for this Space ID */
116 1.1.1.2.2.2 bouyer
117 1.1.1.2.2.2 bouyer Status = AcpiEvInstallSpaceHandler (Node, SpaceId, Handler, Setup, Context);
118 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
119 1.1.1.2.2.2 bouyer {
120 1.1.1.2.2.2 bouyer goto UnlockAndExit;
121 1.1.1.2.2.2 bouyer }
122 1.1.1.2.2.2 bouyer
123 1.1.1.2.2.2 bouyer /*
124 1.1.1.2.2.2 bouyer * For the default SpaceIDs, (the IDs for which there are default region handlers
125 1.1.1.2.2.2 bouyer * installed) Only execute the _REG methods if the global initialization _REG
126 1.1.1.2.2.2 bouyer * methods have already been run (via AcpiInitializeObjects). In other words,
127 1.1.1.2.2.2 bouyer * we will defer the execution of the _REG methods for these SpaceIDs until
128 1.1.1.2.2.2 bouyer * execution of AcpiInitializeObjects. This is done because we need the handlers
129 1.1.1.2.2.2 bouyer * for the default spaces (mem/io/pci/table) to be installed before we can run
130 1.1.1.2.2.2 bouyer * any control methods (or _REG methods). There is known BIOS code that depends
131 1.1.1.2.2.2 bouyer * on this.
132 1.1.1.2.2.2 bouyer *
133 1.1.1.2.2.2 bouyer * For all other SpaceIDs, we can safely execute the _REG methods immediately.
134 1.1.1.2.2.2 bouyer * This means that for IDs like EmbeddedController, this function should be called
135 1.1.1.2.2.2 bouyer * only after AcpiEnableSubsystem has been called.
136 1.1.1.2.2.2 bouyer */
137 1.1.1.2.2.2 bouyer switch (SpaceId)
138 1.1.1.2.2.2 bouyer {
139 1.1.1.2.2.2 bouyer case ACPI_ADR_SPACE_SYSTEM_MEMORY:
140 1.1.1.2.2.2 bouyer case ACPI_ADR_SPACE_SYSTEM_IO:
141 1.1.1.2.2.2 bouyer case ACPI_ADR_SPACE_PCI_CONFIG:
142 1.1.1.2.2.2 bouyer case ACPI_ADR_SPACE_DATA_TABLE:
143 1.1.1.2.2.2 bouyer
144 1.1.1.2.2.2 bouyer if (AcpiGbl_RegMethodsExecuted)
145 1.1.1.2.2.2 bouyer {
146 1.1.1.2.2.2 bouyer /* Run all _REG methods for this address space */
147 1.1.1.2.2.2 bouyer
148 1.1.1.2.2.2 bouyer Status = AcpiEvExecuteRegMethods (Node, SpaceId);
149 1.1.1.2.2.2 bouyer }
150 1.1.1.2.2.2 bouyer break;
151 1.1.1.2.2.2 bouyer
152 1.1.1.2.2.2 bouyer default:
153 1.1.1.2.2.2 bouyer
154 1.1.1.2.2.2 bouyer Status = AcpiEvExecuteRegMethods (Node, SpaceId);
155 1.1.1.2.2.2 bouyer break;
156 1.1.1.2.2.2 bouyer }
157 1.1.1.2.2.2 bouyer
158 1.1.1.2.2.2 bouyer
159 1.1.1.2.2.2 bouyer UnlockAndExit:
160 1.1.1.2.2.2 bouyer (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
161 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
162 1.1.1.2.2.2 bouyer }
163 1.1.1.2.2.2 bouyer
164 1.1.1.2.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiInstallAddressSpaceHandler)
165 1.1.1.2.2.2 bouyer
166 1.1.1.2.2.2 bouyer
167 1.1.1.2.2.2 bouyer /*******************************************************************************
168 1.1.1.2.2.2 bouyer *
169 1.1.1.2.2.2 bouyer * FUNCTION: AcpiRemoveAddressSpaceHandler
170 1.1.1.2.2.2 bouyer *
171 1.1.1.2.2.2 bouyer * PARAMETERS: Device - Handle for the device
172 1.1.1.2.2.2 bouyer * SpaceId - The address space ID
173 1.1.1.2.2.2 bouyer * Handler - Address of the handler
174 1.1.1.2.2.2 bouyer *
175 1.1.1.2.2.2 bouyer * RETURN: Status
176 1.1.1.2.2.2 bouyer *
177 1.1.1.2.2.2 bouyer * DESCRIPTION: Remove a previously installed handler.
178 1.1.1.2.2.2 bouyer *
179 1.1.1.2.2.2 bouyer ******************************************************************************/
180 1.1.1.2.2.2 bouyer
181 1.1.1.2.2.2 bouyer ACPI_STATUS
182 1.1.1.2.2.2 bouyer AcpiRemoveAddressSpaceHandler (
183 1.1.1.2.2.2 bouyer ACPI_HANDLE Device,
184 1.1.1.2.2.2 bouyer ACPI_ADR_SPACE_TYPE SpaceId,
185 1.1.1.2.2.2 bouyer ACPI_ADR_SPACE_HANDLER Handler)
186 1.1.1.2.2.2 bouyer {
187 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc;
188 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *HandlerObj;
189 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *RegionObj;
190 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT **LastObjPtr;
191 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *Node;
192 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
193 1.1.1.2.2.2 bouyer
194 1.1.1.2.2.2 bouyer
195 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (AcpiRemoveAddressSpaceHandler);
196 1.1.1.2.2.2 bouyer
197 1.1.1.2.2.2 bouyer
198 1.1.1.2.2.2 bouyer /* Parameter validation */
199 1.1.1.2.2.2 bouyer
200 1.1.1.2.2.2 bouyer if (!Device)
201 1.1.1.2.2.2 bouyer {
202 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
203 1.1.1.2.2.2 bouyer }
204 1.1.1.2.2.2 bouyer
205 1.1.1.2.2.2 bouyer Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
206 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
207 1.1.1.2.2.2 bouyer {
208 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
209 1.1.1.2.2.2 bouyer }
210 1.1.1.2.2.2 bouyer
211 1.1.1.2.2.2 bouyer /* Convert and validate the device handle */
212 1.1.1.2.2.2 bouyer
213 1.1.1.2.2.2 bouyer Node = AcpiNsValidateHandle (Device);
214 1.1.1.2.2.2 bouyer if (!Node ||
215 1.1.1.2.2.2 bouyer ((Node->Type != ACPI_TYPE_DEVICE) &&
216 1.1.1.2.2.2 bouyer (Node->Type != ACPI_TYPE_PROCESSOR) &&
217 1.1.1.2.2.2 bouyer (Node->Type != ACPI_TYPE_THERMAL) &&
218 1.1.1.2.2.2 bouyer (Node != AcpiGbl_RootNode)))
219 1.1.1.2.2.2 bouyer {
220 1.1.1.2.2.2 bouyer Status = AE_BAD_PARAMETER;
221 1.1.1.2.2.2 bouyer goto UnlockAndExit;
222 1.1.1.2.2.2 bouyer }
223 1.1.1.2.2.2 bouyer
224 1.1.1.2.2.2 bouyer /* Make sure the internal object exists */
225 1.1.1.2.2.2 bouyer
226 1.1.1.2.2.2 bouyer ObjDesc = AcpiNsGetAttachedObject (Node);
227 1.1.1.2.2.2 bouyer if (!ObjDesc)
228 1.1.1.2.2.2 bouyer {
229 1.1.1.2.2.2 bouyer Status = AE_NOT_EXIST;
230 1.1.1.2.2.2 bouyer goto UnlockAndExit;
231 1.1.1.2.2.2 bouyer }
232 1.1.1.2.2.2 bouyer
233 1.1.1.2.2.2 bouyer /* Find the address handler the user requested */
234 1.1.1.2.2.2 bouyer
235 1.1.1.2.2.2 bouyer HandlerObj = ObjDesc->Device.Handler;
236 1.1.1.2.2.2 bouyer LastObjPtr = &ObjDesc->Device.Handler;
237 1.1.1.2.2.2 bouyer while (HandlerObj)
238 1.1.1.2.2.2 bouyer {
239 1.1.1.2.2.2 bouyer /* We have a handler, see if user requested this one */
240 1.1.1.2.2.2 bouyer
241 1.1.1.2.2.2 bouyer if (HandlerObj->AddressSpace.SpaceId == SpaceId)
242 1.1.1.2.2.2 bouyer {
243 1.1.1.2.2.2 bouyer /* Handler must be the same as the installed handler */
244 1.1.1.2.2.2 bouyer
245 1.1.1.2.2.2 bouyer if (HandlerObj->AddressSpace.Handler != Handler)
246 1.1.1.2.2.2 bouyer {
247 1.1.1.2.2.2 bouyer Status = AE_BAD_PARAMETER;
248 1.1.1.2.2.2 bouyer goto UnlockAndExit;
249 1.1.1.2.2.2 bouyer }
250 1.1.1.2.2.2 bouyer
251 1.1.1.2.2.2 bouyer /* Matched SpaceId, first dereference this in the Regions */
252 1.1.1.2.2.2 bouyer
253 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
254 1.1.1.2.2.2 bouyer "Removing address handler %p(%p) for region %s "
255 1.1.1.2.2.2 bouyer "on Device %p(%p)\n",
256 1.1.1.2.2.2 bouyer HandlerObj, Handler, AcpiUtGetRegionName (SpaceId),
257 1.1.1.2.2.2 bouyer Node, ObjDesc));
258 1.1.1.2.2.2 bouyer
259 1.1.1.2.2.2 bouyer RegionObj = HandlerObj->AddressSpace.RegionList;
260 1.1.1.2.2.2 bouyer
261 1.1.1.2.2.2 bouyer /* Walk the handler's region list */
262 1.1.1.2.2.2 bouyer
263 1.1.1.2.2.2 bouyer while (RegionObj)
264 1.1.1.2.2.2 bouyer {
265 1.1.1.2.2.2 bouyer /*
266 1.1.1.2.2.2 bouyer * First disassociate the handler from the region.
267 1.1.1.2.2.2 bouyer *
268 1.1.1.2.2.2 bouyer * NOTE: this doesn't mean that the region goes away
269 1.1.1.2.2.2 bouyer * The region is just inaccessible as indicated to
270 1.1.1.2.2.2 bouyer * the _REG method
271 1.1.1.2.2.2 bouyer */
272 1.1.1.2.2.2 bouyer AcpiEvDetachRegion (RegionObj, TRUE);
273 1.1.1.2.2.2 bouyer
274 1.1.1.2.2.2 bouyer /*
275 1.1.1.2.2.2 bouyer * Walk the list: Just grab the head because the
276 1.1.1.2.2.2 bouyer * DetachRegion removed the previous head.
277 1.1.1.2.2.2 bouyer */
278 1.1.1.2.2.2 bouyer RegionObj = HandlerObj->AddressSpace.RegionList;
279 1.1.1.2.2.2 bouyer
280 1.1.1.2.2.2 bouyer }
281 1.1.1.2.2.2 bouyer
282 1.1.1.2.2.2 bouyer /* Remove this Handler object from the list */
283 1.1.1.2.2.2 bouyer
284 1.1.1.2.2.2 bouyer *LastObjPtr = HandlerObj->AddressSpace.Next;
285 1.1.1.2.2.2 bouyer
286 1.1.1.2.2.2 bouyer /* Now we can delete the handler object */
287 1.1.1.2.2.2 bouyer
288 1.1.1.2.2.2 bouyer AcpiUtRemoveReference (HandlerObj);
289 1.1.1.2.2.2 bouyer goto UnlockAndExit;
290 1.1.1.2.2.2 bouyer }
291 1.1.1.2.2.2 bouyer
292 1.1.1.2.2.2 bouyer /* Walk the linked list of handlers */
293 1.1.1.2.2.2 bouyer
294 1.1.1.2.2.2 bouyer LastObjPtr = &HandlerObj->AddressSpace.Next;
295 1.1.1.2.2.2 bouyer HandlerObj = HandlerObj->AddressSpace.Next;
296 1.1.1.2.2.2 bouyer }
297 1.1.1.2.2.2 bouyer
298 1.1.1.2.2.2 bouyer /* The handler does not exist */
299 1.1.1.2.2.2 bouyer
300 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
301 1.1.1.2.2.2 bouyer "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",
302 1.1.1.2.2.2 bouyer Handler, AcpiUtGetRegionName (SpaceId), SpaceId, Node, ObjDesc));
303 1.1.1.2.2.2 bouyer
304 1.1.1.2.2.2 bouyer Status = AE_NOT_EXIST;
305 1.1.1.2.2.2 bouyer
306 1.1.1.2.2.2 bouyer UnlockAndExit:
307 1.1.1.2.2.2 bouyer (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
308 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
309 1.1.1.2.2.2 bouyer }
310 1.1.1.2.2.2 bouyer
311 1.1.1.2.2.2 bouyer ACPI_EXPORT_SYMBOL (AcpiRemoveAddressSpaceHandler)
312 1.1.1.2.2.2 bouyer
313