evregion.c revision 1.19 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.2 christos * Module Name: evregion - Operation Region support
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.18 christos /******************************************************************************
8 1.18 christos *
9 1.18 christos * 1. Copyright Notice
10 1.18 christos *
11 1.19 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
12 1.1 jruoho * All rights reserved.
13 1.1 jruoho *
14 1.18 christos * 2. License
15 1.18 christos *
16 1.18 christos * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.18 christos * rights. You may have additional license terms from the party that provided
18 1.18 christos * you this software, covering your right to use that party's intellectual
19 1.18 christos * property rights.
20 1.18 christos *
21 1.18 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.18 christos * copy of the source code appearing in this file ("Covered Code") an
23 1.18 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.18 christos * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.18 christos * make derivatives, distribute, use and display any portion of the Covered
26 1.18 christos * Code in any form, with the right to sublicense such rights; and
27 1.18 christos *
28 1.18 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.18 christos * license (with the right to sublicense), under only those claims of Intel
30 1.18 christos * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.18 christos * offer to sell, and import the Covered Code and derivative works thereof
32 1.18 christos * solely to the minimum extent necessary to exercise the above copyright
33 1.18 christos * license, and in no event shall the patent license extend to any additions
34 1.18 christos * to or modifications of the Original Intel Code. No other license or right
35 1.18 christos * is granted directly or by implication, estoppel or otherwise;
36 1.18 christos *
37 1.18 christos * The above copyright and patent license is granted only if the following
38 1.18 christos * conditions are met:
39 1.18 christos *
40 1.18 christos * 3. Conditions
41 1.18 christos *
42 1.18 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.18 christos * Redistribution of source code of any substantial portion of the Covered
44 1.18 christos * Code or modification with rights to further distribute source must include
45 1.18 christos * the above Copyright Notice, the above License, this list of Conditions,
46 1.18 christos * and the following Disclaimer and Export Compliance provision. In addition,
47 1.18 christos * Licensee must cause all Covered Code to which Licensee contributes to
48 1.18 christos * contain a file documenting the changes Licensee made to create that Covered
49 1.18 christos * Code and the date of any change. Licensee must include in that file the
50 1.18 christos * documentation of any changes made by any predecessor Licensee. Licensee
51 1.18 christos * must include a prominent statement that the modification is derived,
52 1.18 christos * directly or indirectly, from Original Intel Code.
53 1.18 christos *
54 1.18 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.18 christos * Redistribution of source code of any substantial portion of the Covered
56 1.18 christos * Code or modification without rights to further distribute source must
57 1.18 christos * include the following Disclaimer and Export Compliance provision in the
58 1.18 christos * documentation and/or other materials provided with distribution. In
59 1.18 christos * addition, Licensee may not authorize further sublicense of source of any
60 1.18 christos * portion of the Covered Code, and must include terms to the effect that the
61 1.18 christos * license from Licensee to its licensee is limited to the intellectual
62 1.18 christos * property embodied in the software Licensee provides to its licensee, and
63 1.18 christos * not to intellectual property embodied in modifications its licensee may
64 1.18 christos * make.
65 1.18 christos *
66 1.18 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.18 christos * substantial portion of the Covered Code or modification must reproduce the
68 1.18 christos * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.18 christos * provision in the documentation and/or other materials provided with the
70 1.18 christos * distribution.
71 1.18 christos *
72 1.18 christos * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.18 christos * Intel Code.
74 1.18 christos *
75 1.18 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.18 christos * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.18 christos * other dealings in products derived from or relating to the Covered Code
78 1.18 christos * without prior written authorization from Intel.
79 1.18 christos *
80 1.18 christos * 4. Disclaimer and Export Compliance
81 1.18 christos *
82 1.18 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.18 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.18 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.18 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.18 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 1.18 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 1.18 christos * PARTICULAR PURPOSE.
89 1.18 christos *
90 1.18 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 1.18 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 1.18 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 1.18 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 1.18 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 1.18 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 1.18 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 1.18 christos * LIMITED REMEDY.
98 1.18 christos *
99 1.18 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 1.18 christos * software or system incorporating such software without first obtaining any
101 1.18 christos * required license or other approval from the U. S. Department of Commerce or
102 1.18 christos * any other agency or department of the United States Government. In the
103 1.18 christos * event Licensee exports any such software from the United States or
104 1.18 christos * re-exports any such software from a foreign destination, Licensee shall
105 1.18 christos * ensure that the distribution and export/re-export of the software is in
106 1.18 christos * compliance with all laws, regulations, orders, or other restrictions of the
107 1.18 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 1.18 christos * any of its subsidiaries will export/re-export any technical data, process,
109 1.18 christos * software, or service, directly or indirectly, to any country for which the
110 1.18 christos * United States government or any agency thereof requires an export license,
111 1.18 christos * other governmental approval, or letter of assurance, without first obtaining
112 1.18 christos * such license, approval or letter.
113 1.18 christos *
114 1.18 christos *****************************************************************************
115 1.18 christos *
116 1.18 christos * Alternatively, you may choose to be licensed under the terms of the
117 1.18 christos * following license:
118 1.18 christos *
119 1.2 christos * Redistribution and use in source and binary forms, with or without
120 1.2 christos * modification, are permitted provided that the following conditions
121 1.2 christos * are met:
122 1.2 christos * 1. Redistributions of source code must retain the above copyright
123 1.2 christos * notice, this list of conditions, and the following disclaimer,
124 1.2 christos * without modification.
125 1.2 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 1.2 christos * substantially similar to the "NO WARRANTY" disclaimer below
127 1.2 christos * ("Disclaimer") and any redistribution must be conditioned upon
128 1.2 christos * including a substantially similar Disclaimer requirement for further
129 1.2 christos * binary redistribution.
130 1.2 christos * 3. Neither the names of the above-listed copyright holders nor the names
131 1.2 christos * of any contributors may be used to endorse or promote products derived
132 1.2 christos * from this software without specific prior written permission.
133 1.2 christos *
134 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 1.2 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 1.13 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 1.2 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 1.18 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 1.18 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 1.18 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 1.18 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 1.18 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 1.18 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 1.18 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 1.18 christos *
146 1.18 christos * Alternatively, you may choose to be licensed under the terms of the
147 1.18 christos * GNU General Public License ("GPL") version 2 as published by the Free
148 1.18 christos * Software Foundation.
149 1.18 christos *
150 1.18 christos *****************************************************************************/
151 1.1 jruoho
152 1.1 jruoho #include "acpi.h"
153 1.1 jruoho #include "accommon.h"
154 1.1 jruoho #include "acevents.h"
155 1.1 jruoho #include "acnamesp.h"
156 1.1 jruoho #include "acinterp.h"
157 1.1 jruoho
158 1.1 jruoho #define _COMPONENT ACPI_EVENTS
159 1.1 jruoho ACPI_MODULE_NAME ("evregion")
160 1.1 jruoho
161 1.1 jruoho
162 1.2 christos extern UINT8 AcpiGbl_DefaultAddressSpaces[];
163 1.2 christos
164 1.1 jruoho /* Local prototypes */
165 1.1 jruoho
166 1.2 christos static void
167 1.12 christos AcpiEvExecuteOrphanRegMethod (
168 1.12 christos ACPI_NAMESPACE_NODE *DeviceNode,
169 1.12 christos ACPI_ADR_SPACE_TYPE SpaceId);
170 1.12 christos
171 1.1 jruoho
172 1.1 jruoho static ACPI_STATUS
173 1.1 jruoho AcpiEvRegRun (
174 1.1 jruoho ACPI_HANDLE ObjHandle,
175 1.1 jruoho UINT32 Level,
176 1.1 jruoho void *Context,
177 1.1 jruoho void **ReturnValue);
178 1.1 jruoho
179 1.1 jruoho
180 1.1 jruoho /*******************************************************************************
181 1.1 jruoho *
182 1.1 jruoho * FUNCTION: AcpiEvInitializeOpRegions
183 1.1 jruoho *
184 1.1 jruoho * PARAMETERS: None
185 1.1 jruoho *
186 1.1 jruoho * RETURN: Status
187 1.1 jruoho *
188 1.1 jruoho * DESCRIPTION: Execute _REG methods for all Operation Regions that have
189 1.1 jruoho * an installed default region handler.
190 1.1 jruoho *
191 1.1 jruoho ******************************************************************************/
192 1.1 jruoho
193 1.1 jruoho ACPI_STATUS
194 1.1 jruoho AcpiEvInitializeOpRegions (
195 1.1 jruoho void)
196 1.1 jruoho {
197 1.1 jruoho ACPI_STATUS Status;
198 1.1 jruoho UINT32 i;
199 1.1 jruoho
200 1.1 jruoho
201 1.1 jruoho ACPI_FUNCTION_TRACE (EvInitializeOpRegions);
202 1.1 jruoho
203 1.1 jruoho
204 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
205 1.1 jruoho if (ACPI_FAILURE (Status))
206 1.1 jruoho {
207 1.1 jruoho return_ACPI_STATUS (Status);
208 1.1 jruoho }
209 1.1 jruoho
210 1.1 jruoho /* Run the _REG methods for OpRegions in each default address space */
211 1.1 jruoho
212 1.1 jruoho for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
213 1.1 jruoho {
214 1.1 jruoho /*
215 1.1 jruoho * Make sure the installed handler is the DEFAULT handler. If not the
216 1.1 jruoho * default, the _REG methods will have already been run (when the
217 1.1 jruoho * handler was installed)
218 1.1 jruoho */
219 1.1 jruoho if (AcpiEvHasDefaultHandler (AcpiGbl_RootNode,
220 1.1 jruoho AcpiGbl_DefaultAddressSpaces[i]))
221 1.1 jruoho {
222 1.2 christos AcpiEvExecuteRegMethods (AcpiGbl_RootNode,
223 1.2 christos AcpiGbl_DefaultAddressSpaces[i], ACPI_REG_CONNECT);
224 1.1 jruoho }
225 1.1 jruoho }
226 1.1 jruoho
227 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
228 1.1 jruoho return_ACPI_STATUS (Status);
229 1.1 jruoho }
230 1.1 jruoho
231 1.1 jruoho
232 1.1 jruoho /*******************************************************************************
233 1.1 jruoho *
234 1.1 jruoho * FUNCTION: AcpiEvAddressSpaceDispatch
235 1.1 jruoho *
236 1.1 jruoho * PARAMETERS: RegionObj - Internal region object
237 1.2 christos * FieldObj - Corresponding field. Can be NULL.
238 1.1 jruoho * Function - Read or Write operation
239 1.1 jruoho * RegionOffset - Where in the region to read or write
240 1.1 jruoho * BitWidth - Field width in bits (8, 16, 32, or 64)
241 1.1 jruoho * Value - Pointer to in or out value, must be
242 1.1 jruoho * a full 64-bit integer
243 1.1 jruoho *
244 1.1 jruoho * RETURN: Status
245 1.1 jruoho *
246 1.1 jruoho * DESCRIPTION: Dispatch an address space or operation region access to
247 1.1 jruoho * a previously installed handler.
248 1.1 jruoho *
249 1.2 christos * NOTE: During early initialization, we always install the default region
250 1.2 christos * handlers for Memory, I/O and PCI_Config. This ensures that these operation
251 1.2 christos * region address spaces are always available as per the ACPI specification.
252 1.2 christos * This is especially needed in order to support the execution of
253 1.2 christos * module-level AML code during loading of the ACPI tables.
254 1.2 christos *
255 1.1 jruoho ******************************************************************************/
256 1.1 jruoho
257 1.1 jruoho ACPI_STATUS
258 1.1 jruoho AcpiEvAddressSpaceDispatch (
259 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj,
260 1.2 christos ACPI_OPERAND_OBJECT *FieldObj,
261 1.1 jruoho UINT32 Function,
262 1.1 jruoho UINT32 RegionOffset,
263 1.1 jruoho UINT32 BitWidth,
264 1.1 jruoho UINT64 *Value)
265 1.1 jruoho {
266 1.1 jruoho ACPI_STATUS Status;
267 1.1 jruoho ACPI_ADR_SPACE_HANDLER Handler;
268 1.1 jruoho ACPI_ADR_SPACE_SETUP RegionSetup;
269 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerDesc;
270 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj2;
271 1.1 jruoho void *RegionContext = NULL;
272 1.2 christos ACPI_CONNECTION_INFO *Context;
273 1.13 christos ACPI_MUTEX ContextMutex;
274 1.13 christos BOOLEAN ContextLocked;
275 1.2 christos ACPI_PHYSICAL_ADDRESS Address;
276 1.1 jruoho
277 1.1 jruoho
278 1.1 jruoho ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch);
279 1.1 jruoho
280 1.1 jruoho
281 1.1 jruoho RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
282 1.1 jruoho if (!RegionObj2)
283 1.1 jruoho {
284 1.1 jruoho return_ACPI_STATUS (AE_NOT_EXIST);
285 1.1 jruoho }
286 1.1 jruoho
287 1.1 jruoho /* Ensure that there is a handler associated with this region */
288 1.1 jruoho
289 1.1 jruoho HandlerDesc = RegionObj->Region.Handler;
290 1.1 jruoho if (!HandlerDesc)
291 1.1 jruoho {
292 1.1 jruoho ACPI_ERROR ((AE_INFO,
293 1.1 jruoho "No handler for Region [%4.4s] (%p) [%s]",
294 1.1 jruoho AcpiUtGetNodeName (RegionObj->Region.Node),
295 1.1 jruoho RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
296 1.1 jruoho
297 1.1 jruoho return_ACPI_STATUS (AE_NOT_EXIST);
298 1.1 jruoho }
299 1.1 jruoho
300 1.2 christos Context = HandlerDesc->AddressSpace.Context;
301 1.13 christos ContextMutex = HandlerDesc->AddressSpace.ContextMutex;
302 1.13 christos ContextLocked = FALSE;
303 1.2 christos
304 1.1 jruoho /*
305 1.1 jruoho * It may be the case that the region has never been initialized.
306 1.1 jruoho * Some types of regions require special init code
307 1.1 jruoho */
308 1.1 jruoho if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
309 1.1 jruoho {
310 1.1 jruoho /* This region has not been initialized yet, do it */
311 1.1 jruoho
312 1.1 jruoho RegionSetup = HandlerDesc->AddressSpace.Setup;
313 1.1 jruoho if (!RegionSetup)
314 1.1 jruoho {
315 1.1 jruoho /* No initialization routine, exit with error */
316 1.1 jruoho
317 1.1 jruoho ACPI_ERROR ((AE_INFO,
318 1.1 jruoho "No init routine for region(%p) [%s]",
319 1.1 jruoho RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
320 1.1 jruoho return_ACPI_STATUS (AE_NOT_EXIST);
321 1.1 jruoho }
322 1.1 jruoho
323 1.15 christos if (RegionObj->Region.SpaceId == ACPI_ADR_SPACE_PLATFORM_COMM)
324 1.15 christos {
325 1.15 christos ACPI_PCC_INFO *Ctx = HandlerDesc->AddressSpace.Context;
326 1.15 christos
327 1.15 christos Ctx->InternalBuffer = FieldObj->Field.InternalPccBuffer;
328 1.15 christos Ctx->Length = (UINT16) RegionObj->Region.Length;
329 1.15 christos Ctx->SubspaceId = (UINT8) RegionObj->Region.Address;
330 1.15 christos }
331 1.14 christos
332 1.16 christos if (RegionObj->Region.SpaceId == ACPI_ADR_SPACE_FIXED_HARDWARE)
333 1.16 christos {
334 1.16 christos ACPI_FFH_INFO *Ctx = HandlerDesc->AddressSpace.Context;
335 1.16 christos
336 1.16 christos Ctx->Length = RegionObj->Region.Length;
337 1.16 christos Ctx->Offset = RegionObj->Region.Address;
338 1.16 christos }
339 1.16 christos
340 1.1 jruoho /*
341 1.1 jruoho * We must exit the interpreter because the region setup will
342 1.1 jruoho * potentially execute control methods (for example, the _REG method
343 1.1 jruoho * for this region)
344 1.1 jruoho */
345 1.1 jruoho AcpiExExitInterpreter ();
346 1.1 jruoho
347 1.1 jruoho Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
348 1.2 christos Context, &RegionContext);
349 1.1 jruoho
350 1.1 jruoho /* Re-enter the interpreter */
351 1.1 jruoho
352 1.1 jruoho AcpiExEnterInterpreter ();
353 1.1 jruoho
354 1.1 jruoho /* Check for failure of the Region Setup */
355 1.1 jruoho
356 1.1 jruoho if (ACPI_FAILURE (Status))
357 1.1 jruoho {
358 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
359 1.1 jruoho "During region initialization: [%s]",
360 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
361 1.1 jruoho return_ACPI_STATUS (Status);
362 1.1 jruoho }
363 1.1 jruoho
364 1.1 jruoho /* Region initialization may have been completed by RegionSetup */
365 1.1 jruoho
366 1.1 jruoho if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
367 1.1 jruoho {
368 1.1 jruoho RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
369 1.1 jruoho
370 1.2 christos /*
371 1.2 christos * Save the returned context for use in all accesses to
372 1.2 christos * the handler for this particular region
373 1.2 christos */
374 1.2 christos if (!(RegionObj2->Extra.RegionContext))
375 1.1 jruoho {
376 1.1 jruoho RegionObj2->Extra.RegionContext = RegionContext;
377 1.1 jruoho }
378 1.1 jruoho }
379 1.1 jruoho }
380 1.1 jruoho
381 1.1 jruoho /* We have everything we need, we can invoke the address space handler */
382 1.1 jruoho
383 1.1 jruoho Handler = HandlerDesc->AddressSpace.Handler;
384 1.2 christos Address = (RegionObj->Region.Address + RegionOffset);
385 1.2 christos
386 1.13 christos ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
387 1.13 christos "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
388 1.13 christos &RegionObj->Region.Handler->AddressSpace, Handler,
389 1.13 christos ACPI_FORMAT_UINT64 (Address),
390 1.13 christos AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
391 1.13 christos
392 1.13 christos if (!(HandlerDesc->AddressSpace.HandlerFlags &
393 1.13 christos ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
394 1.13 christos {
395 1.13 christos /*
396 1.13 christos * For handlers other than the default (supplied) handlers, we must
397 1.13 christos * exit the interpreter because the handler *might* block -- we don't
398 1.13 christos * know what it will do, so we can't hold the lock on the interpreter.
399 1.13 christos */
400 1.13 christos AcpiExExitInterpreter();
401 1.13 christos }
402 1.13 christos
403 1.2 christos /*
404 1.2 christos * Special handling for GenericSerialBus and GeneralPurposeIo:
405 1.2 christos * There are three extra parameters that must be passed to the
406 1.2 christos * handler via the context:
407 1.2 christos * 1) Connection buffer, a resource template from Connection() op
408 1.2 christos * 2) Length of the above buffer
409 1.2 christos * 3) Actual access length from the AccessAs() op
410 1.2 christos *
411 1.13 christos * Since we pass these extra parameters via the context, which is
412 1.13 christos * shared between threads, we must lock the context to avoid these
413 1.13 christos * parameters being changed from another thread before the handler
414 1.13 christos * has completed running.
415 1.13 christos *
416 1.2 christos * In addition, for GeneralPurposeIo, the Address and BitWidth fields
417 1.2 christos * are defined as follows:
418 1.2 christos * 1) Address is the pin number index of the field (bit offset from
419 1.2 christos * the previous Connection)
420 1.2 christos * 2) BitWidth is the actual bit length of the field (number of pins)
421 1.2 christos */
422 1.13 christos if ((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS ||
423 1.13 christos RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO) &&
424 1.2 christos Context &&
425 1.2 christos FieldObj)
426 1.2 christos {
427 1.2 christos
428 1.13 christos Status = AcpiOsAcquireMutex (ContextMutex, ACPI_WAIT_FOREVER);
429 1.13 christos if (ACPI_FAILURE (Status))
430 1.13 christos {
431 1.13 christos goto ReEnterInterpreter;
432 1.13 christos }
433 1.13 christos
434 1.13 christos ContextLocked = TRUE;
435 1.13 christos
436 1.2 christos /* Get the Connection (ResourceTemplate) buffer */
437 1.2 christos
438 1.2 christos Context->Connection = FieldObj->Field.ResourceBuffer;
439 1.2 christos Context->Length = FieldObj->Field.ResourceLength;
440 1.2 christos Context->AccessLength = FieldObj->Field.AccessLength;
441 1.1 jruoho
442 1.13 christos if (RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO)
443 1.13 christos {
444 1.13 christos Address = FieldObj->Field.PinNumberIndex;
445 1.13 christos BitWidth = FieldObj->Field.BitLength;
446 1.13 christos }
447 1.1 jruoho }
448 1.1 jruoho
449 1.1 jruoho /* Call the handler */
450 1.1 jruoho
451 1.2 christos Status = Handler (Function, Address, BitWidth, Value, Context,
452 1.2 christos RegionObj2->Extra.RegionContext);
453 1.1 jruoho
454 1.13 christos if (ContextLocked)
455 1.13 christos {
456 1.13 christos AcpiOsReleaseMutex (ContextMutex);
457 1.13 christos }
458 1.13 christos
459 1.1 jruoho if (ACPI_FAILURE (Status))
460 1.1 jruoho {
461 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]",
462 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
463 1.5 christos
464 1.5 christos /*
465 1.5 christos * Special case for an EC timeout. These are seen so frequently
466 1.5 christos * that an additional error message is helpful
467 1.5 christos */
468 1.5 christos if ((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&
469 1.5 christos (Status == AE_TIME))
470 1.5 christos {
471 1.5 christos ACPI_ERROR ((AE_INFO,
472 1.5 christos "Timeout from EC hardware or EC device driver"));
473 1.5 christos }
474 1.1 jruoho }
475 1.1 jruoho
476 1.13 christos ReEnterInterpreter:
477 1.1 jruoho if (!(HandlerDesc->AddressSpace.HandlerFlags &
478 1.2 christos ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
479 1.1 jruoho {
480 1.1 jruoho /*
481 1.1 jruoho * We just returned from a non-default handler, we must re-enter the
482 1.1 jruoho * interpreter
483 1.1 jruoho */
484 1.2 christos AcpiExEnterInterpreter ();
485 1.1 jruoho }
486 1.1 jruoho
487 1.1 jruoho return_ACPI_STATUS (Status);
488 1.1 jruoho }
489 1.1 jruoho
490 1.1 jruoho
491 1.1 jruoho /*******************************************************************************
492 1.1 jruoho *
493 1.1 jruoho * FUNCTION: AcpiEvDetachRegion
494 1.1 jruoho *
495 1.1 jruoho * PARAMETERS: RegionObj - Region Object
496 1.1 jruoho * AcpiNsIsLocked - Namespace Region Already Locked?
497 1.1 jruoho *
498 1.1 jruoho * RETURN: None
499 1.1 jruoho *
500 1.1 jruoho * DESCRIPTION: Break the association between the handler and the region
501 1.1 jruoho * this is a two way association.
502 1.1 jruoho *
503 1.1 jruoho ******************************************************************************/
504 1.1 jruoho
505 1.1 jruoho void
506 1.2 christos AcpiEvDetachRegion (
507 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj,
508 1.1 jruoho BOOLEAN AcpiNsIsLocked)
509 1.1 jruoho {
510 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerObj;
511 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
512 1.2 christos ACPI_OPERAND_OBJECT *StartDesc;
513 1.1 jruoho ACPI_OPERAND_OBJECT **LastObjPtr;
514 1.1 jruoho ACPI_ADR_SPACE_SETUP RegionSetup;
515 1.1 jruoho void **RegionContext;
516 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj2;
517 1.1 jruoho ACPI_STATUS Status;
518 1.1 jruoho
519 1.1 jruoho
520 1.1 jruoho ACPI_FUNCTION_TRACE (EvDetachRegion);
521 1.1 jruoho
522 1.1 jruoho
523 1.1 jruoho RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
524 1.1 jruoho if (!RegionObj2)
525 1.1 jruoho {
526 1.1 jruoho return_VOID;
527 1.1 jruoho }
528 1.1 jruoho RegionContext = &RegionObj2->Extra.RegionContext;
529 1.1 jruoho
530 1.1 jruoho /* Get the address handler from the region object */
531 1.1 jruoho
532 1.1 jruoho HandlerObj = RegionObj->Region.Handler;
533 1.1 jruoho if (!HandlerObj)
534 1.1 jruoho {
535 1.1 jruoho /* This region has no handler, all done */
536 1.1 jruoho
537 1.1 jruoho return_VOID;
538 1.1 jruoho }
539 1.1 jruoho
540 1.1 jruoho /* Find this region in the handler's list */
541 1.1 jruoho
542 1.1 jruoho ObjDesc = HandlerObj->AddressSpace.RegionList;
543 1.2 christos StartDesc = ObjDesc;
544 1.1 jruoho LastObjPtr = &HandlerObj->AddressSpace.RegionList;
545 1.1 jruoho
546 1.1 jruoho while (ObjDesc)
547 1.1 jruoho {
548 1.1 jruoho /* Is this the correct Region? */
549 1.1 jruoho
550 1.1 jruoho if (ObjDesc == RegionObj)
551 1.1 jruoho {
552 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
553 1.1 jruoho "Removing Region %p from address handler %p\n",
554 1.1 jruoho RegionObj, HandlerObj));
555 1.1 jruoho
556 1.1 jruoho /* This is it, remove it from the handler's list */
557 1.1 jruoho
558 1.1 jruoho *LastObjPtr = ObjDesc->Region.Next;
559 1.1 jruoho ObjDesc->Region.Next = NULL; /* Must clear field */
560 1.1 jruoho
561 1.1 jruoho if (AcpiNsIsLocked)
562 1.1 jruoho {
563 1.1 jruoho Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
564 1.1 jruoho if (ACPI_FAILURE (Status))
565 1.1 jruoho {
566 1.1 jruoho return_VOID;
567 1.1 jruoho }
568 1.1 jruoho }
569 1.1 jruoho
570 1.1 jruoho /* Now stop region accesses by executing the _REG method */
571 1.1 jruoho
572 1.2 christos Status = AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_DISCONNECT);
573 1.1 jruoho if (ACPI_FAILURE (Status))
574 1.1 jruoho {
575 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]",
576 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
577 1.1 jruoho }
578 1.1 jruoho
579 1.1 jruoho if (AcpiNsIsLocked)
580 1.1 jruoho {
581 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
582 1.1 jruoho if (ACPI_FAILURE (Status))
583 1.1 jruoho {
584 1.1 jruoho return_VOID;
585 1.1 jruoho }
586 1.1 jruoho }
587 1.1 jruoho
588 1.1 jruoho /*
589 1.1 jruoho * If the region has been activated, call the setup handler with
590 1.1 jruoho * the deactivate notification
591 1.1 jruoho */
592 1.1 jruoho if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
593 1.1 jruoho {
594 1.1 jruoho RegionSetup = HandlerObj->AddressSpace.Setup;
595 1.1 jruoho Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
596 1.1 jruoho HandlerObj->AddressSpace.Context, RegionContext);
597 1.1 jruoho
598 1.2 christos /*
599 1.2 christos * RegionContext should have been released by the deactivate
600 1.2 christos * operation. We don't need access to it anymore here.
601 1.2 christos */
602 1.2 christos if (RegionContext)
603 1.2 christos {
604 1.2 christos *RegionContext = NULL;
605 1.2 christos }
606 1.2 christos
607 1.1 jruoho /* Init routine may fail, Just ignore errors */
608 1.1 jruoho
609 1.1 jruoho if (ACPI_FAILURE (Status))
610 1.1 jruoho {
611 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
612 1.1 jruoho "from region handler - deactivate, [%s]",
613 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
614 1.1 jruoho }
615 1.1 jruoho
616 1.1 jruoho RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
617 1.1 jruoho }
618 1.1 jruoho
619 1.1 jruoho /*
620 1.1 jruoho * Remove handler reference in the region
621 1.1 jruoho *
622 1.1 jruoho * NOTE: this doesn't mean that the region goes away, the region
623 1.1 jruoho * is just inaccessible as indicated to the _REG method
624 1.1 jruoho *
625 1.1 jruoho * If the region is on the handler's list, this must be the
626 1.1 jruoho * region's handler
627 1.1 jruoho */
628 1.1 jruoho RegionObj->Region.Handler = NULL;
629 1.1 jruoho AcpiUtRemoveReference (HandlerObj);
630 1.1 jruoho
631 1.1 jruoho return_VOID;
632 1.1 jruoho }
633 1.1 jruoho
634 1.1 jruoho /* Walk the linked list of handlers */
635 1.1 jruoho
636 1.1 jruoho LastObjPtr = &ObjDesc->Region.Next;
637 1.1 jruoho ObjDesc = ObjDesc->Region.Next;
638 1.2 christos
639 1.2 christos /* Prevent infinite loop if list is corrupted */
640 1.2 christos
641 1.2 christos if (ObjDesc == StartDesc)
642 1.2 christos {
643 1.2 christos ACPI_ERROR ((AE_INFO,
644 1.2 christos "Circular handler list in region object %p",
645 1.2 christos RegionObj));
646 1.2 christos return_VOID;
647 1.2 christos }
648 1.1 jruoho }
649 1.1 jruoho
650 1.1 jruoho /* If we get here, the region was not in the handler's region list */
651 1.1 jruoho
652 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
653 1.1 jruoho "Cannot remove region %p from address handler %p\n",
654 1.1 jruoho RegionObj, HandlerObj));
655 1.1 jruoho
656 1.1 jruoho return_VOID;
657 1.1 jruoho }
658 1.1 jruoho
659 1.1 jruoho
660 1.1 jruoho /*******************************************************************************
661 1.1 jruoho *
662 1.1 jruoho * FUNCTION: AcpiEvAttachRegion
663 1.1 jruoho *
664 1.1 jruoho * PARAMETERS: HandlerObj - Handler Object
665 1.1 jruoho * RegionObj - Region Object
666 1.1 jruoho * AcpiNsIsLocked - Namespace Region Already Locked?
667 1.1 jruoho *
668 1.1 jruoho * RETURN: None
669 1.1 jruoho *
670 1.1 jruoho * DESCRIPTION: Create the association between the handler and the region
671 1.1 jruoho * this is a two way association.
672 1.1 jruoho *
673 1.1 jruoho ******************************************************************************/
674 1.1 jruoho
675 1.1 jruoho ACPI_STATUS
676 1.1 jruoho AcpiEvAttachRegion (
677 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerObj,
678 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj,
679 1.1 jruoho BOOLEAN AcpiNsIsLocked)
680 1.1 jruoho {
681 1.1 jruoho
682 1.1 jruoho ACPI_FUNCTION_TRACE (EvAttachRegion);
683 1.1 jruoho
684 1.1 jruoho
685 1.2 christos /* Install the region's handler */
686 1.2 christos
687 1.2 christos if (RegionObj->Region.Handler)
688 1.2 christos {
689 1.2 christos return_ACPI_STATUS (AE_ALREADY_EXISTS);
690 1.2 christos }
691 1.2 christos
692 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
693 1.1 jruoho "Adding Region [%4.4s] %p to address handler %p [%s]\n",
694 1.1 jruoho AcpiUtGetNodeName (RegionObj->Region.Node),
695 1.1 jruoho RegionObj, HandlerObj,
696 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
697 1.1 jruoho
698 1.1 jruoho /* Link this region to the front of the handler's list */
699 1.1 jruoho
700 1.1 jruoho RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList;
701 1.1 jruoho HandlerObj->AddressSpace.RegionList = RegionObj;
702 1.1 jruoho RegionObj->Region.Handler = HandlerObj;
703 1.1 jruoho AcpiUtAddReference (HandlerObj);
704 1.1 jruoho
705 1.1 jruoho return_ACPI_STATUS (AE_OK);
706 1.1 jruoho }
707 1.1 jruoho
708 1.1 jruoho
709 1.1 jruoho /*******************************************************************************
710 1.1 jruoho *
711 1.2 christos * FUNCTION: AcpiEvExecuteRegMethod
712 1.1 jruoho *
713 1.2 christos * PARAMETERS: RegionObj - Region object
714 1.2 christos * Function - Passed to _REG: On (1) or Off (0)
715 1.1 jruoho *
716 1.1 jruoho * RETURN: Status
717 1.1 jruoho *
718 1.2 christos * DESCRIPTION: Execute _REG method for a region
719 1.1 jruoho *
720 1.1 jruoho ******************************************************************************/
721 1.1 jruoho
722 1.1 jruoho ACPI_STATUS
723 1.2 christos AcpiEvExecuteRegMethod (
724 1.2 christos ACPI_OPERAND_OBJECT *RegionObj,
725 1.2 christos UINT32 Function)
726 1.1 jruoho {
727 1.2 christos ACPI_EVALUATE_INFO *Info;
728 1.2 christos ACPI_OPERAND_OBJECT *Args[3];
729 1.2 christos ACPI_OPERAND_OBJECT *RegionObj2;
730 1.9 christos const ACPI_NAME *RegNamePtr = ACPI_ALIGNED_STR_UNION (ACPI_NAME, METHOD_NAME__REG);
731 1.3 christos ACPI_NAMESPACE_NODE *MethodNode;
732 1.3 christos ACPI_NAMESPACE_NODE *Node;
733 1.1 jruoho ACPI_STATUS Status;
734 1.1 jruoho
735 1.1 jruoho
736 1.2 christos ACPI_FUNCTION_TRACE (EvExecuteRegMethod);
737 1.1 jruoho
738 1.1 jruoho
739 1.3 christos if (!AcpiGbl_NamespaceInitialized ||
740 1.3 christos RegionObj->Region.Handler == NULL)
741 1.3 christos {
742 1.3 christos return_ACPI_STATUS (AE_OK);
743 1.3 christos }
744 1.3 christos
745 1.2 christos RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
746 1.2 christos if (!RegionObj2)
747 1.1 jruoho {
748 1.2 christos return_ACPI_STATUS (AE_NOT_EXIST);
749 1.1 jruoho }
750 1.1 jruoho
751 1.3 christos /*
752 1.3 christos * Find any "_REG" method associated with this region definition.
753 1.3 christos * The method should always be updated as this function may be
754 1.3 christos * invoked after a namespace change.
755 1.3 christos */
756 1.3 christos Node = RegionObj->Region.Node->Parent;
757 1.3 christos Status = AcpiNsSearchOneScope (
758 1.3 christos *RegNamePtr, Node, ACPI_TYPE_METHOD, &MethodNode);
759 1.3 christos if (ACPI_SUCCESS (Status))
760 1.3 christos {
761 1.3 christos /*
762 1.3 christos * The _REG method is optional and there can be only one per
763 1.3 christos * region definition. This will be executed when the handler is
764 1.3 christos * attached or removed.
765 1.3 christos */
766 1.3 christos RegionObj2->Extra.Method_REG = MethodNode;
767 1.3 christos }
768 1.3 christos if (RegionObj2->Extra.Method_REG == NULL)
769 1.1 jruoho {
770 1.2 christos return_ACPI_STATUS (AE_OK);
771 1.1 jruoho }
772 1.1 jruoho
773 1.2 christos /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */
774 1.1 jruoho
775 1.2 christos if ((Function == ACPI_REG_CONNECT &&
776 1.2 christos RegionObj->Common.Flags & AOPOBJ_REG_CONNECTED) ||
777 1.2 christos (Function == ACPI_REG_DISCONNECT &&
778 1.2 christos !(RegionObj->Common.Flags & AOPOBJ_REG_CONNECTED)))
779 1.1 jruoho {
780 1.2 christos return_ACPI_STATUS (AE_OK);
781 1.1 jruoho }
782 1.1 jruoho
783 1.2 christos /* Allocate and initialize the evaluation information block */
784 1.1 jruoho
785 1.2 christos Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
786 1.2 christos if (!Info)
787 1.1 jruoho {
788 1.2 christos return_ACPI_STATUS (AE_NO_MEMORY);
789 1.1 jruoho }
790 1.1 jruoho
791 1.2 christos Info->PrefixNode = RegionObj2->Extra.Method_REG;
792 1.2 christos Info->RelativePathname = NULL;
793 1.2 christos Info->Parameters = Args;
794 1.2 christos Info->Flags = ACPI_IGNORE_RETURN_VALUE;
795 1.1 jruoho
796 1.1 jruoho /*
797 1.2 christos * The _REG method has two arguments:
798 1.2 christos *
799 1.2 christos * Arg0 - Integer:
800 1.2 christos * Operation region space ID Same value as RegionObj->Region.SpaceId
801 1.1 jruoho *
802 1.2 christos * Arg1 - Integer:
803 1.2 christos * connection status 1 for connecting the handler, 0 for disconnecting
804 1.2 christos * the handler (Passed as a parameter)
805 1.1 jruoho */
806 1.2 christos Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId);
807 1.2 christos if (!Args[0])
808 1.2 christos {
809 1.2 christos Status = AE_NO_MEMORY;
810 1.2 christos goto Cleanup1;
811 1.2 christos }
812 1.2 christos
813 1.2 christos Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function);
814 1.2 christos if (!Args[1])
815 1.1 jruoho {
816 1.1 jruoho Status = AE_NO_MEMORY;
817 1.2 christos goto Cleanup2;
818 1.1 jruoho }
819 1.1 jruoho
820 1.2 christos Args[2] = NULL; /* Terminate list */
821 1.1 jruoho
822 1.2 christos /* Execute the method, no return value */
823 1.1 jruoho
824 1.2 christos ACPI_DEBUG_EXEC (
825 1.2 christos AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL));
826 1.1 jruoho
827 1.2 christos Status = AcpiNsEvaluate (Info);
828 1.2 christos AcpiUtRemoveReference (Args[1]);
829 1.2 christos
830 1.2 christos if (ACPI_FAILURE (Status))
831 1.2 christos {
832 1.2 christos goto Cleanup2;
833 1.2 christos }
834 1.1 jruoho
835 1.2 christos if (Function == ACPI_REG_CONNECT)
836 1.2 christos {
837 1.2 christos RegionObj->Common.Flags |= AOPOBJ_REG_CONNECTED;
838 1.2 christos }
839 1.2 christos else
840 1.2 christos {
841 1.2 christos RegionObj->Common.Flags &= ~AOPOBJ_REG_CONNECTED;
842 1.2 christos }
843 1.1 jruoho
844 1.2 christos Cleanup2:
845 1.2 christos AcpiUtRemoveReference (Args[0]);
846 1.1 jruoho
847 1.2 christos Cleanup1:
848 1.2 christos ACPI_FREE (Info);
849 1.1 jruoho return_ACPI_STATUS (Status);
850 1.1 jruoho }
851 1.1 jruoho
852 1.1 jruoho
853 1.1 jruoho /*******************************************************************************
854 1.1 jruoho *
855 1.1 jruoho * FUNCTION: AcpiEvExecuteRegMethods
856 1.1 jruoho *
857 1.1 jruoho * PARAMETERS: Node - Namespace node for the device
858 1.1 jruoho * SpaceId - The address space ID
859 1.2 christos * Function - Passed to _REG: On (1) or Off (0)
860 1.1 jruoho *
861 1.2 christos * RETURN: None
862 1.1 jruoho *
863 1.1 jruoho * DESCRIPTION: Run all _REG methods for the input Space ID;
864 1.1 jruoho * Note: assumes namespace is locked, or system init time.
865 1.1 jruoho *
866 1.1 jruoho ******************************************************************************/
867 1.1 jruoho
868 1.2 christos void
869 1.1 jruoho AcpiEvExecuteRegMethods (
870 1.1 jruoho ACPI_NAMESPACE_NODE *Node,
871 1.2 christos ACPI_ADR_SPACE_TYPE SpaceId,
872 1.2 christos UINT32 Function)
873 1.1 jruoho {
874 1.2 christos ACPI_REG_WALK_INFO Info;
875 1.1 jruoho
876 1.1 jruoho
877 1.1 jruoho ACPI_FUNCTION_TRACE (EvExecuteRegMethods);
878 1.1 jruoho
879 1.7 christos /*
880 1.7 christos * These address spaces do not need a call to _REG, since the ACPI
881 1.7 christos * specification defines them as: "must always be accessible". Since
882 1.7 christos * they never change state (never become unavailable), no need to ever
883 1.7 christos * call _REG on them. Also, a DataTable is not a "real" address space,
884 1.7 christos * so do not call _REG. September 2018.
885 1.7 christos */
886 1.7 christos if ((SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY) ||
887 1.7 christos (SpaceId == ACPI_ADR_SPACE_SYSTEM_IO) ||
888 1.7 christos (SpaceId == ACPI_ADR_SPACE_DATA_TABLE))
889 1.7 christos {
890 1.7 christos return_VOID;
891 1.7 christos }
892 1.7 christos
893 1.2 christos Info.SpaceId = SpaceId;
894 1.2 christos Info.Function = Function;
895 1.2 christos Info.RegRunCount = 0;
896 1.2 christos
897 1.2 christos ACPI_DEBUG_PRINT_RAW ((ACPI_DB_NAMES,
898 1.2 christos " Running _REG methods for SpaceId %s\n",
899 1.2 christos AcpiUtGetRegionName (Info.SpaceId)));
900 1.1 jruoho
901 1.1 jruoho /*
902 1.1 jruoho * Run all _REG methods for all Operation Regions for this space ID. This
903 1.1 jruoho * is a separate walk in order to handle any interdependencies between
904 1.1 jruoho * regions and _REG methods. (i.e. handlers must be installed for all
905 1.1 jruoho * regions of this Space ID before we can run any _REG methods)
906 1.1 jruoho */
907 1.2 christos (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
908 1.2 christos ACPI_NS_WALK_UNLOCK, AcpiEvRegRun, NULL, &Info, NULL);
909 1.2 christos
910 1.12 christos /*
911 1.12 christos * Special case for EC and GPIO: handle "orphan" _REG methods with
912 1.12 christos * no region.
913 1.12 christos */
914 1.12 christos if (SpaceId == ACPI_ADR_SPACE_EC || SpaceId == ACPI_ADR_SPACE_GPIO)
915 1.2 christos {
916 1.12 christos AcpiEvExecuteOrphanRegMethod (Node, SpaceId);
917 1.2 christos }
918 1.2 christos
919 1.2 christos ACPI_DEBUG_PRINT_RAW ((ACPI_DB_NAMES,
920 1.2 christos " Executed %u _REG methods for SpaceId %s\n",
921 1.2 christos Info.RegRunCount, AcpiUtGetRegionName (Info.SpaceId)));
922 1.2 christos
923 1.2 christos return_VOID;
924 1.1 jruoho }
925 1.1 jruoho
926 1.1 jruoho
927 1.1 jruoho /*******************************************************************************
928 1.1 jruoho *
929 1.1 jruoho * FUNCTION: AcpiEvRegRun
930 1.1 jruoho *
931 1.1 jruoho * PARAMETERS: WalkNamespace callback
932 1.1 jruoho *
933 1.1 jruoho * DESCRIPTION: Run _REG method for region objects of the requested spaceID
934 1.1 jruoho *
935 1.1 jruoho ******************************************************************************/
936 1.1 jruoho
937 1.1 jruoho static ACPI_STATUS
938 1.1 jruoho AcpiEvRegRun (
939 1.1 jruoho ACPI_HANDLE ObjHandle,
940 1.1 jruoho UINT32 Level,
941 1.1 jruoho void *Context,
942 1.1 jruoho void **ReturnValue)
943 1.1 jruoho {
944 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
945 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
946 1.1 jruoho ACPI_STATUS Status;
947 1.2 christos ACPI_REG_WALK_INFO *Info;
948 1.1 jruoho
949 1.1 jruoho
950 1.2 christos Info = ACPI_CAST_PTR (ACPI_REG_WALK_INFO, Context);
951 1.1 jruoho
952 1.1 jruoho /* Convert and validate the device handle */
953 1.1 jruoho
954 1.1 jruoho Node = AcpiNsValidateHandle (ObjHandle);
955 1.1 jruoho if (!Node)
956 1.1 jruoho {
957 1.1 jruoho return (AE_BAD_PARAMETER);
958 1.1 jruoho }
959 1.1 jruoho
960 1.1 jruoho /*
961 1.7 christos * We only care about regions and objects that are allowed to have
962 1.7 christos * address space handlers
963 1.1 jruoho */
964 1.1 jruoho if ((Node->Type != ACPI_TYPE_REGION) &&
965 1.1 jruoho (Node != AcpiGbl_RootNode))
966 1.1 jruoho {
967 1.1 jruoho return (AE_OK);
968 1.1 jruoho }
969 1.1 jruoho
970 1.1 jruoho /* Check for an existing internal object */
971 1.1 jruoho
972 1.1 jruoho ObjDesc = AcpiNsGetAttachedObject (Node);
973 1.1 jruoho if (!ObjDesc)
974 1.1 jruoho {
975 1.1 jruoho /* No object, just exit */
976 1.1 jruoho
977 1.1 jruoho return (AE_OK);
978 1.1 jruoho }
979 1.1 jruoho
980 1.1 jruoho /* Object is a Region */
981 1.1 jruoho
982 1.2 christos if (ObjDesc->Region.SpaceId != Info->SpaceId)
983 1.1 jruoho {
984 1.1 jruoho /* This region is for a different address space, just ignore it */
985 1.1 jruoho
986 1.1 jruoho return (AE_OK);
987 1.1 jruoho }
988 1.1 jruoho
989 1.2 christos Info->RegRunCount++;
990 1.2 christos Status = AcpiEvExecuteRegMethod (ObjDesc, Info->Function);
991 1.1 jruoho return (Status);
992 1.1 jruoho }
993 1.1 jruoho
994 1.2 christos
995 1.2 christos /*******************************************************************************
996 1.2 christos *
997 1.12 christos * FUNCTION: AcpiEvExecuteOrphanRegMethod
998 1.2 christos *
999 1.12 christos * PARAMETERS: DeviceNode - Namespace node for an ACPI device
1000 1.12 christos * SpaceId - The address space ID
1001 1.2 christos *
1002 1.2 christos * RETURN: None
1003 1.2 christos *
1004 1.12 christos * DESCRIPTION: Execute an "orphan" _REG method that appears under an ACPI
1005 1.2 christos * device. This is a _REG method that has no corresponding region
1006 1.12 christos * within the device's scope. ACPI tables depending on these
1007 1.12 christos * "orphan" _REG methods have been seen for both EC and GPIO
1008 1.12 christos * Operation Regions. Presumably the Windows ACPI implementation
1009 1.12 christos * always calls the _REG method independent of the presence of
1010 1.12 christos * an actual Operation Region with the correct address space ID.
1011 1.2 christos *
1012 1.2 christos * MUTEX: Assumes the namespace is locked
1013 1.2 christos *
1014 1.2 christos ******************************************************************************/
1015 1.2 christos
1016 1.2 christos static void
1017 1.12 christos AcpiEvExecuteOrphanRegMethod (
1018 1.12 christos ACPI_NAMESPACE_NODE *DeviceNode,
1019 1.12 christos ACPI_ADR_SPACE_TYPE SpaceId)
1020 1.2 christos {
1021 1.2 christos ACPI_HANDLE RegMethod;
1022 1.2 christos ACPI_NAMESPACE_NODE *NextNode;
1023 1.2 christos ACPI_STATUS Status;
1024 1.2 christos ACPI_OBJECT_LIST Args;
1025 1.2 christos ACPI_OBJECT Objects[2];
1026 1.2 christos
1027 1.2 christos
1028 1.12 christos ACPI_FUNCTION_TRACE (EvExecuteOrphanRegMethod);
1029 1.2 christos
1030 1.2 christos
1031 1.12 christos if (!DeviceNode)
1032 1.2 christos {
1033 1.2 christos return_VOID;
1034 1.2 christos }
1035 1.2 christos
1036 1.2 christos /* Namespace is currently locked, must release */
1037 1.2 christos
1038 1.2 christos (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1039 1.2 christos
1040 1.2 christos /* Get a handle to a _REG method immediately under the EC device */
1041 1.2 christos
1042 1.12 christos Status = AcpiGetHandle (DeviceNode, METHOD_NAME__REG, &RegMethod);
1043 1.2 christos if (ACPI_FAILURE (Status))
1044 1.2 christos {
1045 1.2 christos goto Exit; /* There is no _REG method present */
1046 1.2 christos }
1047 1.2 christos
1048 1.2 christos /*
1049 1.2 christos * Execute the _REG method only if there is no Operation Region in
1050 1.2 christos * this scope with the Embedded Controller space ID. Otherwise, it
1051 1.2 christos * will already have been executed. Note, this allows for Regions
1052 1.2 christos * with other space IDs to be present; but the code below will then
1053 1.2 christos * execute the _REG method with the EmbeddedControl SpaceID argument.
1054 1.2 christos */
1055 1.12 christos NextNode = AcpiNsGetNextNode (DeviceNode, NULL);
1056 1.2 christos while (NextNode)
1057 1.2 christos {
1058 1.2 christos if ((NextNode->Type == ACPI_TYPE_REGION) &&
1059 1.2 christos (NextNode->Object) &&
1060 1.12 christos (NextNode->Object->Region.SpaceId == SpaceId))
1061 1.2 christos {
1062 1.2 christos goto Exit; /* Do not execute the _REG */
1063 1.2 christos }
1064 1.2 christos
1065 1.12 christos NextNode = AcpiNsGetNextNode (DeviceNode, NextNode);
1066 1.2 christos }
1067 1.2 christos
1068 1.12 christos /* Evaluate the _REG(SpaceId,Connect) method */
1069 1.2 christos
1070 1.2 christos Args.Count = 2;
1071 1.2 christos Args.Pointer = Objects;
1072 1.2 christos Objects[0].Type = ACPI_TYPE_INTEGER;
1073 1.12 christos Objects[0].Integer.Value = SpaceId;
1074 1.2 christos Objects[1].Type = ACPI_TYPE_INTEGER;
1075 1.2 christos Objects[1].Integer.Value = ACPI_REG_CONNECT;
1076 1.2 christos
1077 1.10 christos (void) AcpiEvaluateObject (RegMethod, NULL, &Args, NULL);
1078 1.2 christos
1079 1.2 christos Exit:
1080 1.2 christos /* We ignore all errors from above, don't care */
1081 1.2 christos
1082 1.10 christos (void) AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
1083 1.2 christos return_VOID;
1084 1.2 christos }
1085