1 /******************************************************************************
3 * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2016, 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 EXPORT_ACPI_INTERFACES
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 (
118 Node
, SpaceId
, Handler
, Setup
, Context
);
119 if (ACPI_FAILURE (Status
))
124 /* Run all _REG methods for this address space */
126 AcpiEvExecuteRegMethods (Node
, SpaceId
, ACPI_REG_CONNECT
);
130 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
131 return_ACPI_STATUS (Status
);
134 ACPI_EXPORT_SYMBOL (AcpiInstallAddressSpaceHandler
)
137 /*******************************************************************************
139 * FUNCTION: AcpiRemoveAddressSpaceHandler
141 * PARAMETERS: Device - Handle for the device
142 * SpaceId - The address space ID
143 * Handler - Address of the handler
147 * DESCRIPTION: Remove a previously installed handler.
149 ******************************************************************************/
152 AcpiRemoveAddressSpaceHandler (
154 ACPI_ADR_SPACE_TYPE SpaceId
,
155 ACPI_ADR_SPACE_HANDLER Handler
)
157 ACPI_OPERAND_OBJECT
*ObjDesc
;
158 ACPI_OPERAND_OBJECT
*HandlerObj
;
159 ACPI_OPERAND_OBJECT
*RegionObj
;
160 ACPI_OPERAND_OBJECT
**LastObjPtr
;
161 ACPI_NAMESPACE_NODE
*Node
;
165 ACPI_FUNCTION_TRACE (AcpiRemoveAddressSpaceHandler
);
168 /* Parameter validation */
172 return_ACPI_STATUS (AE_BAD_PARAMETER
);
175 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
176 if (ACPI_FAILURE (Status
))
178 return_ACPI_STATUS (Status
);
181 /* Convert and validate the device handle */
183 Node
= AcpiNsValidateHandle (Device
);
185 ((Node
->Type
!= ACPI_TYPE_DEVICE
) &&
186 (Node
->Type
!= ACPI_TYPE_PROCESSOR
) &&
187 (Node
->Type
!= ACPI_TYPE_THERMAL
) &&
188 (Node
!= AcpiGbl_RootNode
)))
190 Status
= AE_BAD_PARAMETER
;
194 /* Make sure the internal object exists */
196 ObjDesc
= AcpiNsGetAttachedObject (Node
);
199 Status
= AE_NOT_EXIST
;
203 /* Find the address handler the user requested */
205 HandlerObj
= ObjDesc
->CommonNotify
.Handler
;
206 LastObjPtr
= &ObjDesc
->CommonNotify
.Handler
;
209 /* We have a handler, see if user requested this one */
211 if (HandlerObj
->AddressSpace
.SpaceId
== SpaceId
)
213 /* Handler must be the same as the installed handler */
215 if (HandlerObj
->AddressSpace
.Handler
!= Handler
)
217 Status
= AE_BAD_PARAMETER
;
221 /* Matched SpaceId, first dereference this in the Regions */
223 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
224 "Removing address handler %p(%p) for region %s "
225 "on Device %p(%p)\n",
226 HandlerObj
, Handler
, AcpiUtGetRegionName (SpaceId
),
229 RegionObj
= HandlerObj
->AddressSpace
.RegionList
;
231 /* Walk the handler's region list */
236 * First disassociate the handler from the region.
238 * NOTE: this doesn't mean that the region goes away
239 * The region is just inaccessible as indicated to
242 AcpiEvDetachRegion (RegionObj
, TRUE
);
245 * Walk the list: Just grab the head because the
246 * DetachRegion removed the previous head.
248 RegionObj
= HandlerObj
->AddressSpace
.RegionList
;
252 /* Remove this Handler object from the list */
254 *LastObjPtr
= HandlerObj
->AddressSpace
.Next
;
256 /* Now we can delete the handler object */
258 AcpiUtRemoveReference (HandlerObj
);
262 /* Walk the linked list of handlers */
264 LastObjPtr
= &HandlerObj
->AddressSpace
.Next
;
265 HandlerObj
= HandlerObj
->AddressSpace
.Next
;
268 /* The handler does not exist */
270 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
271 "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",
272 Handler
, AcpiUtGetRegionName (SpaceId
), SpaceId
, Node
, ObjDesc
));
274 Status
= AE_NOT_EXIST
;
277 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
278 return_ACPI_STATUS (Status
);
281 ACPI_EXPORT_SYMBOL (AcpiRemoveAddressSpaceHandler
)