1 /******************************************************************************
3 * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and
6 *****************************************************************************/
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
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.
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__
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acnamesp.h>
50 #include <contrib/dev/acpica/include/acevents.h>
52 #define _COMPONENT ACPI_EVENTS
53 ACPI_MODULE_NAME ("evxfregn")
56 /*******************************************************************************
58 * FUNCTION: AcpiInstallAddressSpaceHandler
60 * PARAMETERS: Device - Handle for the device
61 * SpaceId - The address space ID
62 * Handler - Address of the handler
63 * Setup - Address of the setup function
64 * Context - Value passed to the handler on each access
68 * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
70 * NOTE: This function should only be called after AcpiEnableSubsystem has
71 * been called. This is because any _REG methods associated with the Space ID
72 * are executed here, and these methods can only be safely executed after
73 * the default handlers have been installed and the hardware has been
74 * initialized (via AcpiEnableSubsystem.)
76 ******************************************************************************/
79 AcpiInstallAddressSpaceHandler (
81 ACPI_ADR_SPACE_TYPE SpaceId,
82 ACPI_ADR_SPACE_HANDLER Handler,
83 ACPI_ADR_SPACE_SETUP Setup,
86 ACPI_NAMESPACE_NODE *Node;
90 ACPI_FUNCTION_TRACE (AcpiInstallAddressSpaceHandler);
93 /* Parameter validation */
97 return_ACPI_STATUS (AE_BAD_PARAMETER);
100 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
101 if (ACPI_FAILURE (Status))
103 return_ACPI_STATUS (Status);
106 /* Convert and validate the device handle */
108 Node = AcpiNsValidateHandle (Device);
111 Status = AE_BAD_PARAMETER;
115 /* Install the handler for all Regions for this Space ID */
117 Status = AcpiEvInstallSpaceHandler (Node, SpaceId, Handler, Setup, Context);
118 if (ACPI_FAILURE (Status))
124 * For the default SpaceIDs, (the IDs for which there are default region handlers
125 * installed) Only execute the _REG methods if the global initialization _REG
126 * methods have already been run (via AcpiInitializeObjects). In other words,
127 * we will defer the execution of the _REG methods for these SpaceIDs until
128 * execution of AcpiInitializeObjects. This is done because we need the handlers
129 * for the default spaces (mem/io/pci/table) to be installed before we can run
130 * any control methods (or _REG methods). There is known BIOS code that depends
133 * For all other SpaceIDs, we can safely execute the _REG methods immediately.
134 * This means that for IDs like EmbeddedController, this function should be called
135 * only after AcpiEnableSubsystem has been called.
139 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
140 case ACPI_ADR_SPACE_SYSTEM_IO:
141 case ACPI_ADR_SPACE_PCI_CONFIG:
142 case ACPI_ADR_SPACE_DATA_TABLE:
144 if (!AcpiGbl_RegMethodsExecuted)
146 /* We will defer execution of the _REG methods for this space */
156 /* Run all _REG methods for this address space */
158 Status = AcpiEvExecuteRegMethods (Node, SpaceId);
162 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
163 return_ACPI_STATUS (Status);
166 ACPI_EXPORT_SYMBOL (AcpiInstallAddressSpaceHandler)
169 /*******************************************************************************
171 * FUNCTION: AcpiRemoveAddressSpaceHandler
173 * PARAMETERS: Device - Handle for the device
174 * SpaceId - The address space ID
175 * Handler - Address of the handler
179 * DESCRIPTION: Remove a previously installed handler.
181 ******************************************************************************/
184 AcpiRemoveAddressSpaceHandler (
186 ACPI_ADR_SPACE_TYPE SpaceId,
187 ACPI_ADR_SPACE_HANDLER Handler)
189 ACPI_OPERAND_OBJECT *ObjDesc;
190 ACPI_OPERAND_OBJECT *HandlerObj;
191 ACPI_OPERAND_OBJECT *RegionObj;
192 ACPI_OPERAND_OBJECT **LastObjPtr;
193 ACPI_NAMESPACE_NODE *Node;
197 ACPI_FUNCTION_TRACE (AcpiRemoveAddressSpaceHandler);
200 /* Parameter validation */
204 return_ACPI_STATUS (AE_BAD_PARAMETER);
207 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
208 if (ACPI_FAILURE (Status))
210 return_ACPI_STATUS (Status);
213 /* Convert and validate the device handle */
215 Node = AcpiNsValidateHandle (Device);
217 ((Node->Type != ACPI_TYPE_DEVICE) &&
218 (Node->Type != ACPI_TYPE_PROCESSOR) &&
219 (Node->Type != ACPI_TYPE_THERMAL) &&
220 (Node != AcpiGbl_RootNode)))
222 Status = AE_BAD_PARAMETER;
226 /* Make sure the internal object exists */
228 ObjDesc = AcpiNsGetAttachedObject (Node);
231 Status = AE_NOT_EXIST;
235 /* Find the address handler the user requested */
237 HandlerObj = ObjDesc->Device.Handler;
238 LastObjPtr = &ObjDesc->Device.Handler;
241 /* We have a handler, see if user requested this one */
243 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
245 /* Handler must be the same as the installed handler */
247 if (HandlerObj->AddressSpace.Handler != Handler)
249 Status = AE_BAD_PARAMETER;
253 /* Matched SpaceId, first dereference this in the Regions */
255 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
256 "Removing address handler %p(%p) for region %s "
257 "on Device %p(%p)\n",
258 HandlerObj, Handler, AcpiUtGetRegionName (SpaceId),
261 RegionObj = HandlerObj->AddressSpace.RegionList;
263 /* Walk the handler's region list */
268 * First disassociate the handler from the region.
270 * NOTE: this doesn't mean that the region goes away
271 * The region is just inaccessible as indicated to
274 AcpiEvDetachRegion (RegionObj, TRUE);
277 * Walk the list: Just grab the head because the
278 * DetachRegion removed the previous head.
280 RegionObj = HandlerObj->AddressSpace.RegionList;
284 /* Remove this Handler object from the list */
286 *LastObjPtr = HandlerObj->AddressSpace.Next;
288 /* Now we can delete the handler object */
290 AcpiUtRemoveReference (HandlerObj);
294 /* Walk the linked list of handlers */
296 LastObjPtr = &HandlerObj->AddressSpace.Next;
297 HandlerObj = HandlerObj->AddressSpace.Next;
300 /* The handler does not exist */
302 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
303 "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",
304 Handler, AcpiUtGetRegionName (SpaceId), SpaceId, Node, ObjDesc));
306 Status = AE_NOT_EXIST;
309 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
310 return_ACPI_STATUS (Status);
313 ACPI_EXPORT_SYMBOL (AcpiRemoveAddressSpaceHandler)