ReactOS 0.4.15-dev-7934-g1dc8d80
evxfregn.c
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and
4 * Address Spaces.
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2022, Intel Corp.
10 * All rights reserved.
11 *
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.
26 *
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.
30 *
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 MERCHANTABILITY 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.
43 */
44
45#define EXPORT_ACPI_INTERFACES
46
47#include "acpi.h"
48#include "accommon.h"
49#include "acnamesp.h"
50#include "acevents.h"
51
52#define _COMPONENT ACPI_EVENTS
53 ACPI_MODULE_NAME ("evxfregn")
54
55
56/*******************************************************************************
57 *
58 * FUNCTION: AcpiInstallAddressSpaceHandler
59 *
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
65 *
66 * RETURN: Status
67 *
68 * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
69 *
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.)
75 *
76 ******************************************************************************/
77
84 void *Context)
85{
88
89
91
92
93 /* Parameter validation */
94
95 if (!Device)
96 {
98 }
99
101 if (ACPI_FAILURE (Status))
102 {
104 }
105
106 /* Convert and validate the device handle */
107
109 if (!Node)
110 {
112 goto UnlockAndExit;
113 }
114
115 /* Install the handler for all Regions for this Space ID */
116
119 if (ACPI_FAILURE (Status))
120 {
121 goto UnlockAndExit;
122 }
123
124 /* Run all _REG methods for this address space */
125
127
128
129UnlockAndExit:
132}
133
135
136
137/*******************************************************************************
138 *
139 * FUNCTION: AcpiRemoveAddressSpaceHandler
140 *
141 * PARAMETERS: Device - Handle for the device
142 * SpaceId - The address space ID
143 * Handler - Address of the handler
144 *
145 * RETURN: Status
146 *
147 * DESCRIPTION: Remove a previously installed handler.
148 *
149 ******************************************************************************/
150
156{
157 ACPI_OPERAND_OBJECT *ObjDesc;
158 ACPI_OPERAND_OBJECT *HandlerObj;
159 ACPI_OPERAND_OBJECT *RegionObj;
160 ACPI_OPERAND_OBJECT **LastObjPtr;
163
164
166
167
168 /* Parameter validation */
169
170 if (!Device)
171 {
173 }
174
176 if (ACPI_FAILURE (Status))
177 {
179 }
180
181 /* Convert and validate the device handle */
182
184 if (!Node ||
185 ((Node->Type != ACPI_TYPE_DEVICE) &&
186 (Node->Type != ACPI_TYPE_PROCESSOR) &&
187 (Node->Type != ACPI_TYPE_THERMAL) &&
188 (Node != AcpiGbl_RootNode)))
189 {
191 goto UnlockAndExit;
192 }
193
194 /* Make sure the internal object exists */
195
196 ObjDesc = AcpiNsGetAttachedObject (Node);
197 if (!ObjDesc)
198 {
200 goto UnlockAndExit;
201 }
202
203 /* Find the address handler the user requested */
204
205 HandlerObj = ObjDesc->CommonNotify.Handler;
206 LastObjPtr = &ObjDesc->CommonNotify.Handler;
207 while (HandlerObj)
208 {
209 /* We have a handler, see if user requested this one */
210
211 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
212 {
213 /* Handler must be the same as the installed handler */
214
215 if (HandlerObj->AddressSpace.Handler != Handler)
216 {
218 goto UnlockAndExit;
219 }
220
221 /* Matched SpaceId, first dereference this in the Regions */
222
224 "Removing address handler %p(%p) for region %s "
225 "on Device %p(%p)\n",
226 HandlerObj, Handler, AcpiUtGetRegionName (SpaceId),
227 Node, ObjDesc));
228
229 RegionObj = HandlerObj->AddressSpace.RegionList;
230
231 /* Walk the handler's region list */
232
233 while (RegionObj)
234 {
235 /*
236 * First disassociate the handler from the region.
237 *
238 * NOTE: this doesn't mean that the region goes away
239 * The region is just inaccessible as indicated to
240 * the _REG method
241 */
242 AcpiEvDetachRegion (RegionObj, TRUE);
243
244 /*
245 * Walk the list: Just grab the head because the
246 * DetachRegion removed the previous head.
247 */
248 RegionObj = HandlerObj->AddressSpace.RegionList;
249 }
250
251 /* Remove this Handler object from the list */
252
253 *LastObjPtr = HandlerObj->AddressSpace.Next;
254
255 /* Now we can delete the handler object */
256
258 AcpiUtRemoveReference (HandlerObj);
259 goto UnlockAndExit;
260 }
261
262 /* Walk the linked list of handlers */
263
264 LastObjPtr = &HandlerObj->AddressSpace.Next;
265 HandlerObj = HandlerObj->AddressSpace.Next;
266 }
267
268 /* The handler does not exist */
269
271 "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",
273
275
276UnlockAndExit:
279}
280
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_BAD_PARAMETER
Definition: acexcep.h:151
#define AE_NOT_EXIST
Definition: acexcep.h:114
#define ACPI_MTX_NAMESPACE
Definition: aclocal.h:85
ACPI_OPERAND_OBJECT * AcpiNsGetAttachedObject(ACPI_NAMESPACE_NODE *Node)
Definition: nsobject.c:308
ACPI_NAMESPACE_NODE * AcpiNsValidateHandle(ACPI_HANDLE Handle)
Definition: nsutils.c:655
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_DB_OPREGION
Definition: acoutput.h:167
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE ACPI_HANDLE ACPI_HANDLE *OutHandle ACPI_HANDLE *OutHandle void *Context void *Context ACPI_EVENT_HANDLER Handler UINT32 UINT32 ACPI_GPE_HANDLER void *Context UINT32 ACPI_NOTIFY_HANDLER void *Context ACPI_ADR_SPACE_TYPE ACPI_ADR_SPACE_HANDLER ACPI_ADR_SPACE_SETUP Setup
Definition: acpixf.h:834
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE ACPI_HANDLE ACPI_HANDLE *OutHandle ACPI_HANDLE *OutHandle void *Context void *Context ACPI_EVENT_HANDLER Handler UINT32 UINT32 ACPI_GPE_HANDLER void *Context UINT32 ACPI_NOTIFY_HANDLER void *Context ACPI_ADR_SPACE_TYPE SpaceId
Definition: acpixf.h:832
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER Handler
Definition: acpixf.h:672
#define ACPI_TYPE_PROCESSOR
Definition: actypes.h:699
UINT8 ACPI_ADR_SPACE_TYPE
Definition: actypes.h:859
#define ACPI_REG_CONNECT
Definition: actypes.h:890
ACPI_STATUS(* ACPI_ADR_SPACE_SETUP)(ACPI_HANDLE RegionHandle, UINT32 Function, void *HandlerContext, void **RegionContext)
Definition: actypes.h:1239
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define AcpiOsReleaseMutex(Handle)
Definition: actypes.h:277
ACPI_STATUS(* ACPI_ADR_SPACE_HANDLER)(UINT32 Function, ACPI_PHYSICAL_ADDRESS Address, UINT32 BitWidth, UINT64 *Value, void *HandlerContext, void *RegionContext)
Definition: actypes.h:1203
#define ACPI_TYPE_DEVICE
Definition: actypes.h:693
#define ACPI_EXPORT_SYMBOL(Symbol)
Definition: actypes.h:343
#define ACPI_TYPE_THERMAL
Definition: actypes.h:700
const char * AcpiUtGetRegionName(UINT8 SpaceId)
Definition: utdecode.c:125
ACPI_STATUS AcpiUtAcquireMutex(ACPI_MUTEX_HANDLE MutexId)
Definition: utmutex.c:256
ACPI_STATUS AcpiUtReleaseMutex(ACPI_MUTEX_HANDLE MutexId)
Definition: utmutex.c:348
void AcpiUtRemoveReference(ACPI_OPERAND_OBJECT *Object)
Definition: utdelete.c:790
#define TRUE
Definition: types.h:120
union node Node
Definition: types.h:1255
ACPI_STATUS AcpiEvInstallSpaceHandler(ACPI_NAMESPACE_NODE *Node, ACPI_ADR_SPACE_TYPE SpaceId, ACPI_ADR_SPACE_HANDLER Handler, ACPI_ADR_SPACE_SETUP Setup, void *Context)
Definition: evhandler.c:389
void AcpiEvExecuteRegMethods(ACPI_NAMESPACE_NODE *Node, ACPI_ADR_SPACE_TYPE SpaceId, UINT32 Function)
Definition: evregion.c:761
void AcpiEvDetachRegion(ACPI_OPERAND_OBJECT *RegionObj, BOOLEAN AcpiNsIsLocked)
Definition: evregion.c:398
ACPI_STATUS AcpiInstallAddressSpaceHandler(ACPI_HANDLE Device, ACPI_ADR_SPACE_TYPE SpaceId, ACPI_ADR_SPACE_HANDLER Handler, ACPI_ADR_SPACE_SETUP Setup, void *Context)
Definition: evxfregn.c:79
ACPI_STATUS AcpiRemoveAddressSpaceHandler(ACPI_HANDLE Device, ACPI_ADR_SPACE_TYPE SpaceId, ACPI_ADR_SPACE_HANDLER Handler)
Definition: evxfregn.c:152
Status
Definition: gdiplustypes.h:25
union acpi_operand_object * RegionList
Definition: acobject.h:419
ACPI_OBJECT_COMMON_HEADER UINT8 SpaceId
Definition: acobject.h:412
ACPI_ADR_SPACE_HANDLER Handler
Definition: acobject.h:414
ACPI_MUTEX ContextMutex
Definition: acobject.h:417
union acpi_operand_object * Next
Definition: acobject.h:420
ACPI_OBJECT_ADDR_HANDLER AddressSpace
Definition: acobject.h:539
ACPI_OBJECT_NOTIFY_COMMON CommonNotify
Definition: acobject.h:528
Definition: dlist.c:348
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474