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