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