evxfregn.c revision 1.1.1.4 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.4 christos * Copyright (C) 2000 - 2013, 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.1.4 christos #define EXPORT_ACPI_INTERFACES
47 1.1 jruoho
48 1.1 jruoho #include "acpi.h"
49 1.1 jruoho #include "accommon.h"
50 1.1 jruoho #include "acnamesp.h"
51 1.1 jruoho #include "acevents.h"
52 1.1 jruoho
53 1.1 jruoho #define _COMPONENT ACPI_EVENTS
54 1.1 jruoho ACPI_MODULE_NAME ("evxfregn")
55 1.1 jruoho
56 1.1 jruoho
57 1.1 jruoho /*******************************************************************************
58 1.1 jruoho *
59 1.1 jruoho * FUNCTION: AcpiInstallAddressSpaceHandler
60 1.1 jruoho *
61 1.1 jruoho * PARAMETERS: Device - Handle for the device
62 1.1 jruoho * SpaceId - The address space ID
63 1.1 jruoho * Handler - Address of the handler
64 1.1 jruoho * Setup - Address of the setup function
65 1.1 jruoho * Context - Value passed to the handler on each access
66 1.1 jruoho *
67 1.1 jruoho * RETURN: Status
68 1.1 jruoho *
69 1.1 jruoho * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
70 1.1 jruoho *
71 1.1.1.2 jruoho * NOTE: This function should only be called after AcpiEnableSubsystem has
72 1.1.1.2 jruoho * been called. This is because any _REG methods associated with the Space ID
73 1.1.1.2 jruoho * are executed here, and these methods can only be safely executed after
74 1.1.1.2 jruoho * the default handlers have been installed and the hardware has been
75 1.1.1.2 jruoho * initialized (via AcpiEnableSubsystem.)
76 1.1.1.2 jruoho *
77 1.1 jruoho ******************************************************************************/
78 1.1 jruoho
79 1.1 jruoho ACPI_STATUS
80 1.1 jruoho AcpiInstallAddressSpaceHandler (
81 1.1 jruoho ACPI_HANDLE Device,
82 1.1 jruoho ACPI_ADR_SPACE_TYPE SpaceId,
83 1.1 jruoho ACPI_ADR_SPACE_HANDLER Handler,
84 1.1 jruoho ACPI_ADR_SPACE_SETUP Setup,
85 1.1 jruoho void *Context)
86 1.1 jruoho {
87 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
88 1.1 jruoho ACPI_STATUS Status;
89 1.1 jruoho
90 1.1 jruoho
91 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiInstallAddressSpaceHandler);
92 1.1 jruoho
93 1.1 jruoho
94 1.1 jruoho /* Parameter validation */
95 1.1 jruoho
96 1.1 jruoho if (!Device)
97 1.1 jruoho {
98 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
99 1.1 jruoho }
100 1.1 jruoho
101 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
102 1.1 jruoho if (ACPI_FAILURE (Status))
103 1.1 jruoho {
104 1.1 jruoho return_ACPI_STATUS (Status);
105 1.1 jruoho }
106 1.1 jruoho
107 1.1 jruoho /* Convert and validate the device handle */
108 1.1 jruoho
109 1.1 jruoho Node = AcpiNsValidateHandle (Device);
110 1.1 jruoho if (!Node)
111 1.1 jruoho {
112 1.1 jruoho Status = AE_BAD_PARAMETER;
113 1.1 jruoho goto UnlockAndExit;
114 1.1 jruoho }
115 1.1 jruoho
116 1.1 jruoho /* Install the handler for all Regions for this Space ID */
117 1.1 jruoho
118 1.1 jruoho Status = AcpiEvInstallSpaceHandler (Node, SpaceId, Handler, Setup, Context);
119 1.1 jruoho if (ACPI_FAILURE (Status))
120 1.1 jruoho {
121 1.1 jruoho goto UnlockAndExit;
122 1.1 jruoho }
123 1.1 jruoho
124 1.1.1.2 jruoho /*
125 1.1.1.2 jruoho * For the default SpaceIDs, (the IDs for which there are default region handlers
126 1.1.1.2 jruoho * installed) Only execute the _REG methods if the global initialization _REG
127 1.1.1.2 jruoho * methods have already been run (via AcpiInitializeObjects). In other words,
128 1.1.1.2 jruoho * we will defer the execution of the _REG methods for these SpaceIDs until
129 1.1.1.2 jruoho * execution of AcpiInitializeObjects. This is done because we need the handlers
130 1.1.1.2 jruoho * for the default spaces (mem/io/pci/table) to be installed before we can run
131 1.1.1.2 jruoho * any control methods (or _REG methods). There is known BIOS code that depends
132 1.1.1.2 jruoho * on this.
133 1.1.1.2 jruoho *
134 1.1.1.2 jruoho * For all other SpaceIDs, we can safely execute the _REG methods immediately.
135 1.1.1.2 jruoho * This means that for IDs like EmbeddedController, this function should be called
136 1.1.1.2 jruoho * only after AcpiEnableSubsystem has been called.
137 1.1.1.2 jruoho */
138 1.1.1.2 jruoho switch (SpaceId)
139 1.1.1.2 jruoho {
140 1.1.1.2 jruoho case ACPI_ADR_SPACE_SYSTEM_MEMORY:
141 1.1.1.2 jruoho case ACPI_ADR_SPACE_SYSTEM_IO:
142 1.1.1.2 jruoho case ACPI_ADR_SPACE_PCI_CONFIG:
143 1.1.1.2 jruoho case ACPI_ADR_SPACE_DATA_TABLE:
144 1.1.1.2 jruoho
145 1.1.1.3 jruoho if (!AcpiGbl_RegMethodsExecuted)
146 1.1.1.2 jruoho {
147 1.1.1.3 jruoho /* We will defer execution of the _REG methods for this space */
148 1.1.1.3 jruoho goto UnlockAndExit;
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.4 christos
154 1.1.1.2 jruoho break;
155 1.1.1.2 jruoho }
156 1.1 jruoho
157 1.1.1.3 jruoho /* Run all _REG methods for this address space */
158 1.1.1.3 jruoho
159 1.1.1.3 jruoho Status = AcpiEvExecuteRegMethods (Node, SpaceId);
160 1.1.1.3 jruoho
161 1.1 jruoho
162 1.1 jruoho UnlockAndExit:
163 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
164 1.1 jruoho return_ACPI_STATUS (Status);
165 1.1 jruoho }
166 1.1 jruoho
167 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiInstallAddressSpaceHandler)
168 1.1 jruoho
169 1.1 jruoho
170 1.1 jruoho /*******************************************************************************
171 1.1 jruoho *
172 1.1 jruoho * FUNCTION: AcpiRemoveAddressSpaceHandler
173 1.1 jruoho *
174 1.1 jruoho * PARAMETERS: Device - Handle for the device
175 1.1 jruoho * SpaceId - The address space ID
176 1.1 jruoho * Handler - Address of the handler
177 1.1 jruoho *
178 1.1 jruoho * RETURN: Status
179 1.1 jruoho *
180 1.1 jruoho * DESCRIPTION: Remove a previously installed handler.
181 1.1 jruoho *
182 1.1 jruoho ******************************************************************************/
183 1.1 jruoho
184 1.1 jruoho ACPI_STATUS
185 1.1 jruoho AcpiRemoveAddressSpaceHandler (
186 1.1 jruoho ACPI_HANDLE Device,
187 1.1 jruoho ACPI_ADR_SPACE_TYPE SpaceId,
188 1.1 jruoho ACPI_ADR_SPACE_HANDLER Handler)
189 1.1 jruoho {
190 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
191 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerObj;
192 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj;
193 1.1 jruoho ACPI_OPERAND_OBJECT **LastObjPtr;
194 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
195 1.1 jruoho ACPI_STATUS Status;
196 1.1 jruoho
197 1.1 jruoho
198 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiRemoveAddressSpaceHandler);
199 1.1 jruoho
200 1.1 jruoho
201 1.1 jruoho /* Parameter validation */
202 1.1 jruoho
203 1.1 jruoho if (!Device)
204 1.1 jruoho {
205 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
206 1.1 jruoho }
207 1.1 jruoho
208 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
209 1.1 jruoho if (ACPI_FAILURE (Status))
210 1.1 jruoho {
211 1.1 jruoho return_ACPI_STATUS (Status);
212 1.1 jruoho }
213 1.1 jruoho
214 1.1 jruoho /* Convert and validate the device handle */
215 1.1 jruoho
216 1.1 jruoho Node = AcpiNsValidateHandle (Device);
217 1.1 jruoho if (!Node ||
218 1.1 jruoho ((Node->Type != ACPI_TYPE_DEVICE) &&
219 1.1 jruoho (Node->Type != ACPI_TYPE_PROCESSOR) &&
220 1.1 jruoho (Node->Type != ACPI_TYPE_THERMAL) &&
221 1.1 jruoho (Node != AcpiGbl_RootNode)))
222 1.1 jruoho {
223 1.1 jruoho Status = AE_BAD_PARAMETER;
224 1.1 jruoho goto UnlockAndExit;
225 1.1 jruoho }
226 1.1 jruoho
227 1.1 jruoho /* Make sure the internal object exists */
228 1.1 jruoho
229 1.1 jruoho ObjDesc = AcpiNsGetAttachedObject (Node);
230 1.1 jruoho if (!ObjDesc)
231 1.1 jruoho {
232 1.1 jruoho Status = AE_NOT_EXIST;
233 1.1 jruoho goto UnlockAndExit;
234 1.1 jruoho }
235 1.1 jruoho
236 1.1 jruoho /* Find the address handler the user requested */
237 1.1 jruoho
238 1.1 jruoho HandlerObj = ObjDesc->Device.Handler;
239 1.1 jruoho LastObjPtr = &ObjDesc->Device.Handler;
240 1.1 jruoho while (HandlerObj)
241 1.1 jruoho {
242 1.1 jruoho /* We have a handler, see if user requested this one */
243 1.1 jruoho
244 1.1 jruoho if (HandlerObj->AddressSpace.SpaceId == SpaceId)
245 1.1 jruoho {
246 1.1 jruoho /* Handler must be the same as the installed handler */
247 1.1 jruoho
248 1.1 jruoho if (HandlerObj->AddressSpace.Handler != Handler)
249 1.1 jruoho {
250 1.1 jruoho Status = AE_BAD_PARAMETER;
251 1.1 jruoho goto UnlockAndExit;
252 1.1 jruoho }
253 1.1 jruoho
254 1.1 jruoho /* Matched SpaceId, first dereference this in the Regions */
255 1.1 jruoho
256 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
257 1.1 jruoho "Removing address handler %p(%p) for region %s "
258 1.1 jruoho "on Device %p(%p)\n",
259 1.1 jruoho HandlerObj, Handler, AcpiUtGetRegionName (SpaceId),
260 1.1 jruoho Node, ObjDesc));
261 1.1 jruoho
262 1.1 jruoho RegionObj = HandlerObj->AddressSpace.RegionList;
263 1.1 jruoho
264 1.1 jruoho /* Walk the handler's region list */
265 1.1 jruoho
266 1.1 jruoho while (RegionObj)
267 1.1 jruoho {
268 1.1 jruoho /*
269 1.1 jruoho * First disassociate the handler from the region.
270 1.1 jruoho *
271 1.1 jruoho * NOTE: this doesn't mean that the region goes away
272 1.1 jruoho * The region is just inaccessible as indicated to
273 1.1 jruoho * the _REG method
274 1.1 jruoho */
275 1.1 jruoho AcpiEvDetachRegion (RegionObj, TRUE);
276 1.1 jruoho
277 1.1 jruoho /*
278 1.1 jruoho * Walk the list: Just grab the head because the
279 1.1 jruoho * DetachRegion removed the previous head.
280 1.1 jruoho */
281 1.1 jruoho RegionObj = HandlerObj->AddressSpace.RegionList;
282 1.1 jruoho
283 1.1 jruoho }
284 1.1 jruoho
285 1.1 jruoho /* Remove this Handler object from the list */
286 1.1 jruoho
287 1.1 jruoho *LastObjPtr = HandlerObj->AddressSpace.Next;
288 1.1 jruoho
289 1.1 jruoho /* Now we can delete the handler object */
290 1.1 jruoho
291 1.1 jruoho AcpiUtRemoveReference (HandlerObj);
292 1.1 jruoho goto UnlockAndExit;
293 1.1 jruoho }
294 1.1 jruoho
295 1.1 jruoho /* Walk the linked list of handlers */
296 1.1 jruoho
297 1.1 jruoho LastObjPtr = &HandlerObj->AddressSpace.Next;
298 1.1 jruoho HandlerObj = HandlerObj->AddressSpace.Next;
299 1.1 jruoho }
300 1.1 jruoho
301 1.1 jruoho /* The handler does not exist */
302 1.1 jruoho
303 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
304 1.1 jruoho "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",
305 1.1 jruoho Handler, AcpiUtGetRegionName (SpaceId), SpaceId, Node, ObjDesc));
306 1.1 jruoho
307 1.1 jruoho Status = AE_NOT_EXIST;
308 1.1 jruoho
309 1.1 jruoho UnlockAndExit:
310 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
311 1.1 jruoho return_ACPI_STATUS (Status);
312 1.1 jruoho }
313 1.1 jruoho
314 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveAddressSpaceHandler)
315