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__
46 #define EXPORT_ACPI_INTERFACES
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
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 ******************************************************************************/
80 AcpiInstallAddressSpaceHandler (
82 ACPI_ADR_SPACE_TYPE SpaceId
,
83 ACPI_ADR_SPACE_HANDLER Handler
,
84 ACPI_ADR_SPACE_SETUP Setup
,
87 ACPI_NAMESPACE_NODE
*Node
;
91 ACPI_FUNCTION_TRACE (AcpiInstallAddressSpaceHandler
);
94 /* Parameter validation */
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
);
112 Status
= AE_BAD_PARAMETER
;
116 /* Install the handler for all Regions for this Space ID */
118 Status
= AcpiEvInstallSpaceHandler (Node
, SpaceId
, Handler
, Setup
, Context
);
119 if (ACPI_FAILURE (Status
))
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
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.
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 */
157 /* Run all _REG methods for this address space */
159 Status
= AcpiEvExecuteRegMethods (Node
, SpaceId
);
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
180 * DESCRIPTION: Remove a previously installed handler.
182 ******************************************************************************/
185 AcpiRemoveAddressSpaceHandler (
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
;
198 ACPI_FUNCTION_TRACE (AcpiRemoveAddressSpaceHandler
);
201 /* Parameter validation */
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
);
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
;
227 /* Make sure the internal object exists */
229 ObjDesc
= AcpiNsGetAttachedObject (Node
);
232 Status
= AE_NOT_EXIST
;
236 /* Find the address handler the user requested */
238 HandlerObj
= ObjDesc
->Device
.Handler
;
239 LastObjPtr
= &ObjDesc
->Device
.Handler
;
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
;
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
),
262 RegionObj
= HandlerObj
->AddressSpace
.RegionList
;
264 /* Walk the handler's region list */
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
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
);
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
;
310 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
311 return_ACPI_STATUS (Status
);
314 ACPI_EXPORT_SYMBOL (AcpiRemoveAddressSpaceHandler
)