evregion.c revision 1.1 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: evregion - ACPI AddressSpace (OpRegion) handler dispatch
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1 jruoho /******************************************************************************
8 1.1 jruoho *
9 1.1 jruoho * 1. Copyright Notice
10 1.1 jruoho *
11 1.1 jruoho * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 1.1 jruoho * All rights reserved.
13 1.1 jruoho *
14 1.1 jruoho * 2. License
15 1.1 jruoho *
16 1.1 jruoho * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.1 jruoho * rights. You may have additional license terms from the party that provided
18 1.1 jruoho * you this software, covering your right to use that party's intellectual
19 1.1 jruoho * property rights.
20 1.1 jruoho *
21 1.1 jruoho * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.1 jruoho * copy of the source code appearing in this file ("Covered Code") an
23 1.1 jruoho * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.1 jruoho * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.1 jruoho * make derivatives, distribute, use and display any portion of the Covered
26 1.1 jruoho * Code in any form, with the right to sublicense such rights; and
27 1.1 jruoho *
28 1.1 jruoho * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.1 jruoho * license (with the right to sublicense), under only those claims of Intel
30 1.1 jruoho * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.1 jruoho * offer to sell, and import the Covered Code and derivative works thereof
32 1.1 jruoho * solely to the minimum extent necessary to exercise the above copyright
33 1.1 jruoho * license, and in no event shall the patent license extend to any additions
34 1.1 jruoho * to or modifications of the Original Intel Code. No other license or right
35 1.1 jruoho * is granted directly or by implication, estoppel or otherwise;
36 1.1 jruoho *
37 1.1 jruoho * The above copyright and patent license is granted only if the following
38 1.1 jruoho * conditions are met:
39 1.1 jruoho *
40 1.1 jruoho * 3. Conditions
41 1.1 jruoho *
42 1.1 jruoho * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.1 jruoho * Redistribution of source code of any substantial portion of the Covered
44 1.1 jruoho * Code or modification with rights to further distribute source must include
45 1.1 jruoho * the above Copyright Notice, the above License, this list of Conditions,
46 1.1 jruoho * and the following Disclaimer and Export Compliance provision. In addition,
47 1.1 jruoho * Licensee must cause all Covered Code to which Licensee contributes to
48 1.1 jruoho * contain a file documenting the changes Licensee made to create that Covered
49 1.1 jruoho * Code and the date of any change. Licensee must include in that file the
50 1.1 jruoho * documentation of any changes made by any predecessor Licensee. Licensee
51 1.1 jruoho * must include a prominent statement that the modification is derived,
52 1.1 jruoho * directly or indirectly, from Original Intel Code.
53 1.1 jruoho *
54 1.1 jruoho * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.1 jruoho * Redistribution of source code of any substantial portion of the Covered
56 1.1 jruoho * Code or modification without rights to further distribute source must
57 1.1 jruoho * include the following Disclaimer and Export Compliance provision in the
58 1.1 jruoho * documentation and/or other materials provided with distribution. In
59 1.1 jruoho * addition, Licensee may not authorize further sublicense of source of any
60 1.1 jruoho * portion of the Covered Code, and must include terms to the effect that the
61 1.1 jruoho * license from Licensee to its licensee is limited to the intellectual
62 1.1 jruoho * property embodied in the software Licensee provides to its licensee, and
63 1.1 jruoho * not to intellectual property embodied in modifications its licensee may
64 1.1 jruoho * make.
65 1.1 jruoho *
66 1.1 jruoho * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.1 jruoho * substantial portion of the Covered Code or modification must reproduce the
68 1.1 jruoho * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.1 jruoho * provision in the documentation and/or other materials provided with the
70 1.1 jruoho * distribution.
71 1.1 jruoho *
72 1.1 jruoho * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.1 jruoho * Intel Code.
74 1.1 jruoho *
75 1.1 jruoho * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.1 jruoho * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.1 jruoho * other dealings in products derived from or relating to the Covered Code
78 1.1 jruoho * without prior written authorization from Intel.
79 1.1 jruoho *
80 1.1 jruoho * 4. Disclaimer and Export Compliance
81 1.1 jruoho *
82 1.1 jruoho * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.1 jruoho * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.1 jruoho * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.1 jruoho * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.1 jruoho * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 1.1 jruoho * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 1.1 jruoho * PARTICULAR PURPOSE.
89 1.1 jruoho *
90 1.1 jruoho * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 1.1 jruoho * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 1.1 jruoho * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 1.1 jruoho * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 1.1 jruoho * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 1.1 jruoho * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 1.1 jruoho * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 1.1 jruoho * LIMITED REMEDY.
98 1.1 jruoho *
99 1.1 jruoho * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 1.1 jruoho * software or system incorporating such software without first obtaining any
101 1.1 jruoho * required license or other approval from the U. S. Department of Commerce or
102 1.1 jruoho * any other agency or department of the United States Government. In the
103 1.1 jruoho * event Licensee exports any such software from the United States or
104 1.1 jruoho * re-exports any such software from a foreign destination, Licensee shall
105 1.1 jruoho * ensure that the distribution and export/re-export of the software is in
106 1.1 jruoho * compliance with all laws, regulations, orders, or other restrictions of the
107 1.1 jruoho * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 1.1 jruoho * any of its subsidiaries will export/re-export any technical data, process,
109 1.1 jruoho * software, or service, directly or indirectly, to any country for which the
110 1.1 jruoho * United States government or any agency thereof requires an export license,
111 1.1 jruoho * other governmental approval, or letter of assurance, without first obtaining
112 1.1 jruoho * such license, approval or letter.
113 1.1 jruoho *
114 1.1 jruoho *****************************************************************************/
115 1.1 jruoho
116 1.1 jruoho
117 1.1 jruoho #define __EVREGION_C__
118 1.1 jruoho
119 1.1 jruoho #include "acpi.h"
120 1.1 jruoho #include "accommon.h"
121 1.1 jruoho #include "acevents.h"
122 1.1 jruoho #include "acnamesp.h"
123 1.1 jruoho #include "acinterp.h"
124 1.1 jruoho
125 1.1 jruoho #define _COMPONENT ACPI_EVENTS
126 1.1 jruoho ACPI_MODULE_NAME ("evregion")
127 1.1 jruoho
128 1.1 jruoho
129 1.1 jruoho /* Local prototypes */
130 1.1 jruoho
131 1.1 jruoho static BOOLEAN
132 1.1 jruoho AcpiEvHasDefaultHandler (
133 1.1 jruoho ACPI_NAMESPACE_NODE *Node,
134 1.1 jruoho ACPI_ADR_SPACE_TYPE SpaceId);
135 1.1 jruoho
136 1.1 jruoho static ACPI_STATUS
137 1.1 jruoho AcpiEvRegRun (
138 1.1 jruoho ACPI_HANDLE ObjHandle,
139 1.1 jruoho UINT32 Level,
140 1.1 jruoho void *Context,
141 1.1 jruoho void **ReturnValue);
142 1.1 jruoho
143 1.1 jruoho static ACPI_STATUS
144 1.1 jruoho AcpiEvInstallHandler (
145 1.1 jruoho ACPI_HANDLE ObjHandle,
146 1.1 jruoho UINT32 Level,
147 1.1 jruoho void *Context,
148 1.1 jruoho void **ReturnValue);
149 1.1 jruoho
150 1.1 jruoho /* These are the address spaces that will get default handlers */
151 1.1 jruoho
152 1.1 jruoho #define ACPI_NUM_DEFAULT_SPACES 4
153 1.1 jruoho
154 1.1 jruoho static UINT8 AcpiGbl_DefaultAddressSpaces[ACPI_NUM_DEFAULT_SPACES] =
155 1.1 jruoho {
156 1.1 jruoho ACPI_ADR_SPACE_SYSTEM_MEMORY,
157 1.1 jruoho ACPI_ADR_SPACE_SYSTEM_IO,
158 1.1 jruoho ACPI_ADR_SPACE_PCI_CONFIG,
159 1.1 jruoho ACPI_ADR_SPACE_DATA_TABLE
160 1.1 jruoho };
161 1.1 jruoho
162 1.1 jruoho
163 1.1 jruoho /*******************************************************************************
164 1.1 jruoho *
165 1.1 jruoho * FUNCTION: AcpiEvInstallRegionHandlers
166 1.1 jruoho *
167 1.1 jruoho * PARAMETERS: None
168 1.1 jruoho *
169 1.1 jruoho * RETURN: Status
170 1.1 jruoho *
171 1.1 jruoho * DESCRIPTION: Installs the core subsystem default address space handlers.
172 1.1 jruoho *
173 1.1 jruoho ******************************************************************************/
174 1.1 jruoho
175 1.1 jruoho ACPI_STATUS
176 1.1 jruoho AcpiEvInstallRegionHandlers (
177 1.1 jruoho void)
178 1.1 jruoho {
179 1.1 jruoho ACPI_STATUS Status;
180 1.1 jruoho UINT32 i;
181 1.1 jruoho
182 1.1 jruoho
183 1.1 jruoho ACPI_FUNCTION_TRACE (EvInstallRegionHandlers);
184 1.1 jruoho
185 1.1 jruoho
186 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
187 1.1 jruoho if (ACPI_FAILURE (Status))
188 1.1 jruoho {
189 1.1 jruoho return_ACPI_STATUS (Status);
190 1.1 jruoho }
191 1.1 jruoho
192 1.1 jruoho /*
193 1.1 jruoho * All address spaces (PCI Config, EC, SMBus) are scope dependent and
194 1.1 jruoho * registration must occur for a specific device.
195 1.1 jruoho *
196 1.1 jruoho * In the case of the system memory and IO address spaces there is
197 1.1 jruoho * currently no device associated with the address space. For these we
198 1.1 jruoho * use the root.
199 1.1 jruoho *
200 1.1 jruoho * We install the default PCI config space handler at the root so that
201 1.1 jruoho * this space is immediately available even though the we have not
202 1.1 jruoho * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
203 1.1 jruoho * specification which states that the PCI config space must be always
204 1.1 jruoho * available -- even though we are nowhere near ready to find the PCI root
205 1.1 jruoho * buses at this point.
206 1.1 jruoho *
207 1.1 jruoho * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
208 1.1 jruoho * has already been installed (via AcpiInstallAddressSpaceHandler).
209 1.1 jruoho * Similar for AE_SAME_HANDLER.
210 1.1 jruoho */
211 1.1 jruoho for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
212 1.1 jruoho {
213 1.1 jruoho Status = AcpiEvInstallSpaceHandler (AcpiGbl_RootNode,
214 1.1 jruoho AcpiGbl_DefaultAddressSpaces[i],
215 1.1 jruoho ACPI_DEFAULT_HANDLER, NULL, NULL);
216 1.1 jruoho switch (Status)
217 1.1 jruoho {
218 1.1 jruoho case AE_OK:
219 1.1 jruoho case AE_SAME_HANDLER:
220 1.1 jruoho case AE_ALREADY_EXISTS:
221 1.1 jruoho
222 1.1 jruoho /* These exceptions are all OK */
223 1.1 jruoho
224 1.1 jruoho Status = AE_OK;
225 1.1 jruoho break;
226 1.1 jruoho
227 1.1 jruoho default:
228 1.1 jruoho
229 1.1 jruoho goto UnlockAndExit;
230 1.1 jruoho }
231 1.1 jruoho }
232 1.1 jruoho
233 1.1 jruoho UnlockAndExit:
234 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
235 1.1 jruoho return_ACPI_STATUS (Status);
236 1.1 jruoho }
237 1.1 jruoho
238 1.1 jruoho
239 1.1 jruoho /*******************************************************************************
240 1.1 jruoho *
241 1.1 jruoho * FUNCTION: AcpiEvHasDefaultHandler
242 1.1 jruoho *
243 1.1 jruoho * PARAMETERS: Node - Namespace node for the device
244 1.1 jruoho * SpaceId - The address space ID
245 1.1 jruoho *
246 1.1 jruoho * RETURN: TRUE if default handler is installed, FALSE otherwise
247 1.1 jruoho *
248 1.1 jruoho * DESCRIPTION: Check if the default handler is installed for the requested
249 1.1 jruoho * space ID.
250 1.1 jruoho *
251 1.1 jruoho ******************************************************************************/
252 1.1 jruoho
253 1.1 jruoho static BOOLEAN
254 1.1 jruoho AcpiEvHasDefaultHandler (
255 1.1 jruoho ACPI_NAMESPACE_NODE *Node,
256 1.1 jruoho ACPI_ADR_SPACE_TYPE SpaceId)
257 1.1 jruoho {
258 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
259 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerObj;
260 1.1 jruoho
261 1.1 jruoho
262 1.1 jruoho /* Must have an existing internal object */
263 1.1 jruoho
264 1.1 jruoho ObjDesc = AcpiNsGetAttachedObject (Node);
265 1.1 jruoho if (ObjDesc)
266 1.1 jruoho {
267 1.1 jruoho HandlerObj = ObjDesc->Device.Handler;
268 1.1 jruoho
269 1.1 jruoho /* Walk the linked list of handlers for this object */
270 1.1 jruoho
271 1.1 jruoho while (HandlerObj)
272 1.1 jruoho {
273 1.1 jruoho if (HandlerObj->AddressSpace.SpaceId == SpaceId)
274 1.1 jruoho {
275 1.1 jruoho if (HandlerObj->AddressSpace.HandlerFlags &
276 1.1 jruoho ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
277 1.1 jruoho {
278 1.1 jruoho return (TRUE);
279 1.1 jruoho }
280 1.1 jruoho }
281 1.1 jruoho
282 1.1 jruoho HandlerObj = HandlerObj->AddressSpace.Next;
283 1.1 jruoho }
284 1.1 jruoho }
285 1.1 jruoho
286 1.1 jruoho return (FALSE);
287 1.1 jruoho }
288 1.1 jruoho
289 1.1 jruoho
290 1.1 jruoho /*******************************************************************************
291 1.1 jruoho *
292 1.1 jruoho * FUNCTION: AcpiEvInitializeOpRegions
293 1.1 jruoho *
294 1.1 jruoho * PARAMETERS: None
295 1.1 jruoho *
296 1.1 jruoho * RETURN: Status
297 1.1 jruoho *
298 1.1 jruoho * DESCRIPTION: Execute _REG methods for all Operation Regions that have
299 1.1 jruoho * an installed default region handler.
300 1.1 jruoho *
301 1.1 jruoho ******************************************************************************/
302 1.1 jruoho
303 1.1 jruoho ACPI_STATUS
304 1.1 jruoho AcpiEvInitializeOpRegions (
305 1.1 jruoho void)
306 1.1 jruoho {
307 1.1 jruoho ACPI_STATUS Status;
308 1.1 jruoho UINT32 i;
309 1.1 jruoho
310 1.1 jruoho
311 1.1 jruoho ACPI_FUNCTION_TRACE (EvInitializeOpRegions);
312 1.1 jruoho
313 1.1 jruoho
314 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
315 1.1 jruoho if (ACPI_FAILURE (Status))
316 1.1 jruoho {
317 1.1 jruoho return_ACPI_STATUS (Status);
318 1.1 jruoho }
319 1.1 jruoho
320 1.1 jruoho /* Run the _REG methods for OpRegions in each default address space */
321 1.1 jruoho
322 1.1 jruoho for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
323 1.1 jruoho {
324 1.1 jruoho /*
325 1.1 jruoho * Make sure the installed handler is the DEFAULT handler. If not the
326 1.1 jruoho * default, the _REG methods will have already been run (when the
327 1.1 jruoho * handler was installed)
328 1.1 jruoho */
329 1.1 jruoho if (AcpiEvHasDefaultHandler (AcpiGbl_RootNode,
330 1.1 jruoho AcpiGbl_DefaultAddressSpaces[i]))
331 1.1 jruoho {
332 1.1 jruoho Status = AcpiEvExecuteRegMethods (AcpiGbl_RootNode,
333 1.1 jruoho AcpiGbl_DefaultAddressSpaces[i]);
334 1.1 jruoho }
335 1.1 jruoho }
336 1.1 jruoho
337 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
338 1.1 jruoho return_ACPI_STATUS (Status);
339 1.1 jruoho }
340 1.1 jruoho
341 1.1 jruoho
342 1.1 jruoho /*******************************************************************************
343 1.1 jruoho *
344 1.1 jruoho * FUNCTION: AcpiEvExecuteRegMethod
345 1.1 jruoho *
346 1.1 jruoho * PARAMETERS: RegionObj - Region object
347 1.1 jruoho * Function - Passed to _REG: On (1) or Off (0)
348 1.1 jruoho *
349 1.1 jruoho * RETURN: Status
350 1.1 jruoho *
351 1.1 jruoho * DESCRIPTION: Execute _REG method for a region
352 1.1 jruoho *
353 1.1 jruoho ******************************************************************************/
354 1.1 jruoho
355 1.1 jruoho ACPI_STATUS
356 1.1 jruoho AcpiEvExecuteRegMethod (
357 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj,
358 1.1 jruoho UINT32 Function)
359 1.1 jruoho {
360 1.1 jruoho ACPI_EVALUATE_INFO *Info;
361 1.1 jruoho ACPI_OPERAND_OBJECT *Args[3];
362 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj2;
363 1.1 jruoho ACPI_STATUS Status;
364 1.1 jruoho
365 1.1 jruoho
366 1.1 jruoho ACPI_FUNCTION_TRACE (EvExecuteRegMethod);
367 1.1 jruoho
368 1.1 jruoho
369 1.1 jruoho RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
370 1.1 jruoho if (!RegionObj2)
371 1.1 jruoho {
372 1.1 jruoho return_ACPI_STATUS (AE_NOT_EXIST);
373 1.1 jruoho }
374 1.1 jruoho
375 1.1 jruoho if (RegionObj2->Extra.Method_REG == NULL)
376 1.1 jruoho {
377 1.1 jruoho return_ACPI_STATUS (AE_OK);
378 1.1 jruoho }
379 1.1 jruoho
380 1.1 jruoho /* Allocate and initialize the evaluation information block */
381 1.1 jruoho
382 1.1 jruoho Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
383 1.1 jruoho if (!Info)
384 1.1 jruoho {
385 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
386 1.1 jruoho }
387 1.1 jruoho
388 1.1 jruoho Info->PrefixNode = RegionObj2->Extra.Method_REG;
389 1.1 jruoho Info->Pathname = NULL;
390 1.1 jruoho Info->Parameters = Args;
391 1.1 jruoho Info->Flags = ACPI_IGNORE_RETURN_VALUE;
392 1.1 jruoho
393 1.1 jruoho /*
394 1.1 jruoho * The _REG method has two arguments:
395 1.1 jruoho *
396 1.1 jruoho * Arg0 - Integer:
397 1.1 jruoho * Operation region space ID Same value as RegionObj->Region.SpaceId
398 1.1 jruoho *
399 1.1 jruoho * Arg1 - Integer:
400 1.1 jruoho * connection status 1 for connecting the handler, 0 for disconnecting
401 1.1 jruoho * the handler (Passed as a parameter)
402 1.1 jruoho */
403 1.1 jruoho Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId);
404 1.1 jruoho if (!Args[0])
405 1.1 jruoho {
406 1.1 jruoho Status = AE_NO_MEMORY;
407 1.1 jruoho goto Cleanup1;
408 1.1 jruoho }
409 1.1 jruoho
410 1.1 jruoho Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function);
411 1.1 jruoho if (!Args[1])
412 1.1 jruoho {
413 1.1 jruoho Status = AE_NO_MEMORY;
414 1.1 jruoho goto Cleanup2;
415 1.1 jruoho }
416 1.1 jruoho
417 1.1 jruoho Args[2] = NULL; /* Terminate list */
418 1.1 jruoho
419 1.1 jruoho /* Execute the method, no return value */
420 1.1 jruoho
421 1.1 jruoho ACPI_DEBUG_EXEC (
422 1.1 jruoho AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL));
423 1.1 jruoho
424 1.1 jruoho Status = AcpiNsEvaluate (Info);
425 1.1 jruoho AcpiUtRemoveReference (Args[1]);
426 1.1 jruoho
427 1.1 jruoho Cleanup2:
428 1.1 jruoho AcpiUtRemoveReference (Args[0]);
429 1.1 jruoho
430 1.1 jruoho Cleanup1:
431 1.1 jruoho ACPI_FREE (Info);
432 1.1 jruoho return_ACPI_STATUS (Status);
433 1.1 jruoho }
434 1.1 jruoho
435 1.1 jruoho
436 1.1 jruoho /*******************************************************************************
437 1.1 jruoho *
438 1.1 jruoho * FUNCTION: AcpiEvAddressSpaceDispatch
439 1.1 jruoho *
440 1.1 jruoho * PARAMETERS: RegionObj - Internal region object
441 1.1 jruoho * Function - Read or Write operation
442 1.1 jruoho * RegionOffset - Where in the region to read or write
443 1.1 jruoho * BitWidth - Field width in bits (8, 16, 32, or 64)
444 1.1 jruoho * Value - Pointer to in or out value, must be
445 1.1 jruoho * a full 64-bit integer
446 1.1 jruoho *
447 1.1 jruoho * RETURN: Status
448 1.1 jruoho *
449 1.1 jruoho * DESCRIPTION: Dispatch an address space or operation region access to
450 1.1 jruoho * a previously installed handler.
451 1.1 jruoho *
452 1.1 jruoho ******************************************************************************/
453 1.1 jruoho
454 1.1 jruoho ACPI_STATUS
455 1.1 jruoho AcpiEvAddressSpaceDispatch (
456 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj,
457 1.1 jruoho UINT32 Function,
458 1.1 jruoho UINT32 RegionOffset,
459 1.1 jruoho UINT32 BitWidth,
460 1.1 jruoho UINT64 *Value)
461 1.1 jruoho {
462 1.1 jruoho ACPI_STATUS Status;
463 1.1 jruoho ACPI_ADR_SPACE_HANDLER Handler;
464 1.1 jruoho ACPI_ADR_SPACE_SETUP RegionSetup;
465 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerDesc;
466 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj2;
467 1.1 jruoho void *RegionContext = NULL;
468 1.1 jruoho
469 1.1 jruoho
470 1.1 jruoho ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch);
471 1.1 jruoho
472 1.1 jruoho
473 1.1 jruoho RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
474 1.1 jruoho if (!RegionObj2)
475 1.1 jruoho {
476 1.1 jruoho return_ACPI_STATUS (AE_NOT_EXIST);
477 1.1 jruoho }
478 1.1 jruoho
479 1.1 jruoho /* Ensure that there is a handler associated with this region */
480 1.1 jruoho
481 1.1 jruoho HandlerDesc = RegionObj->Region.Handler;
482 1.1 jruoho if (!HandlerDesc)
483 1.1 jruoho {
484 1.1 jruoho ACPI_ERROR ((AE_INFO,
485 1.1 jruoho "No handler for Region [%4.4s] (%p) [%s]",
486 1.1 jruoho AcpiUtGetNodeName (RegionObj->Region.Node),
487 1.1 jruoho RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
488 1.1 jruoho
489 1.1 jruoho return_ACPI_STATUS (AE_NOT_EXIST);
490 1.1 jruoho }
491 1.1 jruoho
492 1.1 jruoho /*
493 1.1 jruoho * It may be the case that the region has never been initialized.
494 1.1 jruoho * Some types of regions require special init code
495 1.1 jruoho */
496 1.1 jruoho if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
497 1.1 jruoho {
498 1.1 jruoho /* This region has not been initialized yet, do it */
499 1.1 jruoho
500 1.1 jruoho RegionSetup = HandlerDesc->AddressSpace.Setup;
501 1.1 jruoho if (!RegionSetup)
502 1.1 jruoho {
503 1.1 jruoho /* No initialization routine, exit with error */
504 1.1 jruoho
505 1.1 jruoho ACPI_ERROR ((AE_INFO,
506 1.1 jruoho "No init routine for region(%p) [%s]",
507 1.1 jruoho RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
508 1.1 jruoho return_ACPI_STATUS (AE_NOT_EXIST);
509 1.1 jruoho }
510 1.1 jruoho
511 1.1 jruoho /*
512 1.1 jruoho * We must exit the interpreter because the region setup will
513 1.1 jruoho * potentially execute control methods (for example, the _REG method
514 1.1 jruoho * for this region)
515 1.1 jruoho */
516 1.1 jruoho AcpiExExitInterpreter ();
517 1.1 jruoho
518 1.1 jruoho Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
519 1.1 jruoho HandlerDesc->AddressSpace.Context, &RegionContext);
520 1.1 jruoho
521 1.1 jruoho /* Re-enter the interpreter */
522 1.1 jruoho
523 1.1 jruoho AcpiExEnterInterpreter ();
524 1.1 jruoho
525 1.1 jruoho /* Check for failure of the Region Setup */
526 1.1 jruoho
527 1.1 jruoho if (ACPI_FAILURE (Status))
528 1.1 jruoho {
529 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
530 1.1 jruoho "During region initialization: [%s]",
531 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
532 1.1 jruoho return_ACPI_STATUS (Status);
533 1.1 jruoho }
534 1.1 jruoho
535 1.1 jruoho /* Region initialization may have been completed by RegionSetup */
536 1.1 jruoho
537 1.1 jruoho if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
538 1.1 jruoho {
539 1.1 jruoho RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
540 1.1 jruoho
541 1.1 jruoho if (RegionObj2->Extra.RegionContext)
542 1.1 jruoho {
543 1.1 jruoho /* The handler for this region was already installed */
544 1.1 jruoho
545 1.1 jruoho ACPI_FREE (RegionContext);
546 1.1 jruoho }
547 1.1 jruoho else
548 1.1 jruoho {
549 1.1 jruoho /*
550 1.1 jruoho * Save the returned context for use in all accesses to
551 1.1 jruoho * this particular region
552 1.1 jruoho */
553 1.1 jruoho RegionObj2->Extra.RegionContext = RegionContext;
554 1.1 jruoho }
555 1.1 jruoho }
556 1.1 jruoho }
557 1.1 jruoho
558 1.1 jruoho /* We have everything we need, we can invoke the address space handler */
559 1.1 jruoho
560 1.1 jruoho Handler = HandlerDesc->AddressSpace.Handler;
561 1.1 jruoho
562 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
563 1.1 jruoho "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
564 1.1 jruoho &RegionObj->Region.Handler->AddressSpace, Handler,
565 1.1 jruoho ACPI_FORMAT_NATIVE_UINT (RegionObj->Region.Address + RegionOffset),
566 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
567 1.1 jruoho
568 1.1 jruoho if (!(HandlerDesc->AddressSpace.HandlerFlags &
569 1.1 jruoho ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
570 1.1 jruoho {
571 1.1 jruoho /*
572 1.1 jruoho * For handlers other than the default (supplied) handlers, we must
573 1.1 jruoho * exit the interpreter because the handler *might* block -- we don't
574 1.1 jruoho * know what it will do, so we can't hold the lock on the intepreter.
575 1.1 jruoho */
576 1.1 jruoho AcpiExExitInterpreter();
577 1.1 jruoho }
578 1.1 jruoho
579 1.1 jruoho /* Call the handler */
580 1.1 jruoho
581 1.1 jruoho Status = Handler (Function,
582 1.1 jruoho (RegionObj->Region.Address + RegionOffset), BitWidth, Value,
583 1.1 jruoho HandlerDesc->AddressSpace.Context, RegionObj2->Extra.RegionContext);
584 1.1 jruoho
585 1.1 jruoho if (ACPI_FAILURE (Status))
586 1.1 jruoho {
587 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]",
588 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
589 1.1 jruoho }
590 1.1 jruoho
591 1.1 jruoho if (!(HandlerDesc->AddressSpace.HandlerFlags &
592 1.1 jruoho ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
593 1.1 jruoho {
594 1.1 jruoho /*
595 1.1 jruoho * We just returned from a non-default handler, we must re-enter the
596 1.1 jruoho * interpreter
597 1.1 jruoho */
598 1.1 jruoho AcpiExEnterInterpreter ();
599 1.1 jruoho }
600 1.1 jruoho
601 1.1 jruoho return_ACPI_STATUS (Status);
602 1.1 jruoho }
603 1.1 jruoho
604 1.1 jruoho
605 1.1 jruoho /*******************************************************************************
606 1.1 jruoho *
607 1.1 jruoho * FUNCTION: AcpiEvDetachRegion
608 1.1 jruoho *
609 1.1 jruoho * PARAMETERS: RegionObj - Region Object
610 1.1 jruoho * AcpiNsIsLocked - Namespace Region Already Locked?
611 1.1 jruoho *
612 1.1 jruoho * RETURN: None
613 1.1 jruoho *
614 1.1 jruoho * DESCRIPTION: Break the association between the handler and the region
615 1.1 jruoho * this is a two way association.
616 1.1 jruoho *
617 1.1 jruoho ******************************************************************************/
618 1.1 jruoho
619 1.1 jruoho void
620 1.1 jruoho AcpiEvDetachRegion(
621 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj,
622 1.1 jruoho BOOLEAN AcpiNsIsLocked)
623 1.1 jruoho {
624 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerObj;
625 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
626 1.1 jruoho ACPI_OPERAND_OBJECT **LastObjPtr;
627 1.1 jruoho ACPI_ADR_SPACE_SETUP RegionSetup;
628 1.1 jruoho void **RegionContext;
629 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj2;
630 1.1 jruoho ACPI_STATUS Status;
631 1.1 jruoho
632 1.1 jruoho
633 1.1 jruoho ACPI_FUNCTION_TRACE (EvDetachRegion);
634 1.1 jruoho
635 1.1 jruoho
636 1.1 jruoho RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
637 1.1 jruoho if (!RegionObj2)
638 1.1 jruoho {
639 1.1 jruoho return_VOID;
640 1.1 jruoho }
641 1.1 jruoho RegionContext = &RegionObj2->Extra.RegionContext;
642 1.1 jruoho
643 1.1 jruoho /* Get the address handler from the region object */
644 1.1 jruoho
645 1.1 jruoho HandlerObj = RegionObj->Region.Handler;
646 1.1 jruoho if (!HandlerObj)
647 1.1 jruoho {
648 1.1 jruoho /* This region has no handler, all done */
649 1.1 jruoho
650 1.1 jruoho return_VOID;
651 1.1 jruoho }
652 1.1 jruoho
653 1.1 jruoho /* Find this region in the handler's list */
654 1.1 jruoho
655 1.1 jruoho ObjDesc = HandlerObj->AddressSpace.RegionList;
656 1.1 jruoho LastObjPtr = &HandlerObj->AddressSpace.RegionList;
657 1.1 jruoho
658 1.1 jruoho while (ObjDesc)
659 1.1 jruoho {
660 1.1 jruoho /* Is this the correct Region? */
661 1.1 jruoho
662 1.1 jruoho if (ObjDesc == RegionObj)
663 1.1 jruoho {
664 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
665 1.1 jruoho "Removing Region %p from address handler %p\n",
666 1.1 jruoho RegionObj, HandlerObj));
667 1.1 jruoho
668 1.1 jruoho /* This is it, remove it from the handler's list */
669 1.1 jruoho
670 1.1 jruoho *LastObjPtr = ObjDesc->Region.Next;
671 1.1 jruoho ObjDesc->Region.Next = NULL; /* Must clear field */
672 1.1 jruoho
673 1.1 jruoho if (AcpiNsIsLocked)
674 1.1 jruoho {
675 1.1 jruoho Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
676 1.1 jruoho if (ACPI_FAILURE (Status))
677 1.1 jruoho {
678 1.1 jruoho return_VOID;
679 1.1 jruoho }
680 1.1 jruoho }
681 1.1 jruoho
682 1.1 jruoho /* Now stop region accesses by executing the _REG method */
683 1.1 jruoho
684 1.1 jruoho Status = AcpiEvExecuteRegMethod (RegionObj, 0);
685 1.1 jruoho if (ACPI_FAILURE (Status))
686 1.1 jruoho {
687 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]",
688 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
689 1.1 jruoho }
690 1.1 jruoho
691 1.1 jruoho if (AcpiNsIsLocked)
692 1.1 jruoho {
693 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
694 1.1 jruoho if (ACPI_FAILURE (Status))
695 1.1 jruoho {
696 1.1 jruoho return_VOID;
697 1.1 jruoho }
698 1.1 jruoho }
699 1.1 jruoho
700 1.1 jruoho /*
701 1.1 jruoho * If the region has been activated, call the setup handler with
702 1.1 jruoho * the deactivate notification
703 1.1 jruoho */
704 1.1 jruoho if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
705 1.1 jruoho {
706 1.1 jruoho RegionSetup = HandlerObj->AddressSpace.Setup;
707 1.1 jruoho Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
708 1.1 jruoho HandlerObj->AddressSpace.Context, RegionContext);
709 1.1 jruoho
710 1.1 jruoho /* Init routine may fail, Just ignore errors */
711 1.1 jruoho
712 1.1 jruoho if (ACPI_FAILURE (Status))
713 1.1 jruoho {
714 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
715 1.1 jruoho "from region handler - deactivate, [%s]",
716 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
717 1.1 jruoho }
718 1.1 jruoho
719 1.1 jruoho RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
720 1.1 jruoho }
721 1.1 jruoho
722 1.1 jruoho /*
723 1.1 jruoho * Remove handler reference in the region
724 1.1 jruoho *
725 1.1 jruoho * NOTE: this doesn't mean that the region goes away, the region
726 1.1 jruoho * is just inaccessible as indicated to the _REG method
727 1.1 jruoho *
728 1.1 jruoho * If the region is on the handler's list, this must be the
729 1.1 jruoho * region's handler
730 1.1 jruoho */
731 1.1 jruoho RegionObj->Region.Handler = NULL;
732 1.1 jruoho AcpiUtRemoveReference (HandlerObj);
733 1.1 jruoho
734 1.1 jruoho return_VOID;
735 1.1 jruoho }
736 1.1 jruoho
737 1.1 jruoho /* Walk the linked list of handlers */
738 1.1 jruoho
739 1.1 jruoho LastObjPtr = &ObjDesc->Region.Next;
740 1.1 jruoho ObjDesc = ObjDesc->Region.Next;
741 1.1 jruoho }
742 1.1 jruoho
743 1.1 jruoho /* If we get here, the region was not in the handler's region list */
744 1.1 jruoho
745 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
746 1.1 jruoho "Cannot remove region %p from address handler %p\n",
747 1.1 jruoho RegionObj, HandlerObj));
748 1.1 jruoho
749 1.1 jruoho return_VOID;
750 1.1 jruoho }
751 1.1 jruoho
752 1.1 jruoho
753 1.1 jruoho /*******************************************************************************
754 1.1 jruoho *
755 1.1 jruoho * FUNCTION: AcpiEvAttachRegion
756 1.1 jruoho *
757 1.1 jruoho * PARAMETERS: HandlerObj - Handler Object
758 1.1 jruoho * RegionObj - Region Object
759 1.1 jruoho * AcpiNsIsLocked - Namespace Region Already Locked?
760 1.1 jruoho *
761 1.1 jruoho * RETURN: None
762 1.1 jruoho *
763 1.1 jruoho * DESCRIPTION: Create the association between the handler and the region
764 1.1 jruoho * this is a two way association.
765 1.1 jruoho *
766 1.1 jruoho ******************************************************************************/
767 1.1 jruoho
768 1.1 jruoho ACPI_STATUS
769 1.1 jruoho AcpiEvAttachRegion (
770 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerObj,
771 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj,
772 1.1 jruoho BOOLEAN AcpiNsIsLocked)
773 1.1 jruoho {
774 1.1 jruoho
775 1.1 jruoho ACPI_FUNCTION_TRACE (EvAttachRegion);
776 1.1 jruoho
777 1.1 jruoho
778 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
779 1.1 jruoho "Adding Region [%4.4s] %p to address handler %p [%s]\n",
780 1.1 jruoho AcpiUtGetNodeName (RegionObj->Region.Node),
781 1.1 jruoho RegionObj, HandlerObj,
782 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
783 1.1 jruoho
784 1.1 jruoho /* Link this region to the front of the handler's list */
785 1.1 jruoho
786 1.1 jruoho RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList;
787 1.1 jruoho HandlerObj->AddressSpace.RegionList = RegionObj;
788 1.1 jruoho
789 1.1 jruoho /* Install the region's handler */
790 1.1 jruoho
791 1.1 jruoho if (RegionObj->Region.Handler)
792 1.1 jruoho {
793 1.1 jruoho return_ACPI_STATUS (AE_ALREADY_EXISTS);
794 1.1 jruoho }
795 1.1 jruoho
796 1.1 jruoho RegionObj->Region.Handler = HandlerObj;
797 1.1 jruoho AcpiUtAddReference (HandlerObj);
798 1.1 jruoho
799 1.1 jruoho return_ACPI_STATUS (AE_OK);
800 1.1 jruoho }
801 1.1 jruoho
802 1.1 jruoho
803 1.1 jruoho /*******************************************************************************
804 1.1 jruoho *
805 1.1 jruoho * FUNCTION: AcpiEvInstallHandler
806 1.1 jruoho *
807 1.1 jruoho * PARAMETERS: WalkNamespace callback
808 1.1 jruoho *
809 1.1 jruoho * DESCRIPTION: This routine installs an address handler into objects that are
810 1.1 jruoho * of type Region or Device.
811 1.1 jruoho *
812 1.1 jruoho * If the Object is a Device, and the device has a handler of
813 1.1 jruoho * the same type then the search is terminated in that branch.
814 1.1 jruoho *
815 1.1 jruoho * This is because the existing handler is closer in proximity
816 1.1 jruoho * to any more regions than the one we are trying to install.
817 1.1 jruoho *
818 1.1 jruoho ******************************************************************************/
819 1.1 jruoho
820 1.1 jruoho static ACPI_STATUS
821 1.1 jruoho AcpiEvInstallHandler (
822 1.1 jruoho ACPI_HANDLE ObjHandle,
823 1.1 jruoho UINT32 Level,
824 1.1 jruoho void *Context,
825 1.1 jruoho void **ReturnValue)
826 1.1 jruoho {
827 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerObj;
828 1.1 jruoho ACPI_OPERAND_OBJECT *NextHandlerObj;
829 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
830 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
831 1.1 jruoho ACPI_STATUS Status;
832 1.1 jruoho
833 1.1 jruoho
834 1.1 jruoho ACPI_FUNCTION_NAME (EvInstallHandler);
835 1.1 jruoho
836 1.1 jruoho
837 1.1 jruoho HandlerObj = (ACPI_OPERAND_OBJECT *) Context;
838 1.1 jruoho
839 1.1 jruoho /* Parameter validation */
840 1.1 jruoho
841 1.1 jruoho if (!HandlerObj)
842 1.1 jruoho {
843 1.1 jruoho return (AE_OK);
844 1.1 jruoho }
845 1.1 jruoho
846 1.1 jruoho /* Convert and validate the device handle */
847 1.1 jruoho
848 1.1 jruoho Node = AcpiNsValidateHandle (ObjHandle);
849 1.1 jruoho if (!Node)
850 1.1 jruoho {
851 1.1 jruoho return (AE_BAD_PARAMETER);
852 1.1 jruoho }
853 1.1 jruoho
854 1.1 jruoho /*
855 1.1 jruoho * We only care about regions and objects that are allowed to have
856 1.1 jruoho * address space handlers
857 1.1 jruoho */
858 1.1 jruoho if ((Node->Type != ACPI_TYPE_DEVICE) &&
859 1.1 jruoho (Node->Type != ACPI_TYPE_REGION) &&
860 1.1 jruoho (Node != AcpiGbl_RootNode))
861 1.1 jruoho {
862 1.1 jruoho return (AE_OK);
863 1.1 jruoho }
864 1.1 jruoho
865 1.1 jruoho /* Check for an existing internal object */
866 1.1 jruoho
867 1.1 jruoho ObjDesc = AcpiNsGetAttachedObject (Node);
868 1.1 jruoho if (!ObjDesc)
869 1.1 jruoho {
870 1.1 jruoho /* No object, just exit */
871 1.1 jruoho
872 1.1 jruoho return (AE_OK);
873 1.1 jruoho }
874 1.1 jruoho
875 1.1 jruoho /* Devices are handled different than regions */
876 1.1 jruoho
877 1.1 jruoho if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
878 1.1 jruoho {
879 1.1 jruoho /* Check if this Device already has a handler for this address space */
880 1.1 jruoho
881 1.1 jruoho NextHandlerObj = ObjDesc->Device.Handler;
882 1.1 jruoho while (NextHandlerObj)
883 1.1 jruoho {
884 1.1 jruoho /* Found a handler, is it for the same address space? */
885 1.1 jruoho
886 1.1 jruoho if (NextHandlerObj->AddressSpace.SpaceId ==
887 1.1 jruoho HandlerObj->AddressSpace.SpaceId)
888 1.1 jruoho {
889 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
890 1.1 jruoho "Found handler for region [%s] in device %p(%p) "
891 1.1 jruoho "handler %p\n",
892 1.1 jruoho AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
893 1.1 jruoho ObjDesc, NextHandlerObj, HandlerObj));
894 1.1 jruoho
895 1.1 jruoho /*
896 1.1 jruoho * Since the object we found it on was a device, then it
897 1.1 jruoho * means that someone has already installed a handler for
898 1.1 jruoho * the branch of the namespace from this device on. Just
899 1.1 jruoho * bail out telling the walk routine to not traverse this
900 1.1 jruoho * branch. This preserves the scoping rule for handlers.
901 1.1 jruoho */
902 1.1 jruoho return (AE_CTRL_DEPTH);
903 1.1 jruoho }
904 1.1 jruoho
905 1.1 jruoho /* Walk the linked list of handlers attached to this device */
906 1.1 jruoho
907 1.1 jruoho NextHandlerObj = NextHandlerObj->AddressSpace.Next;
908 1.1 jruoho }
909 1.1 jruoho
910 1.1 jruoho /*
911 1.1 jruoho * As long as the device didn't have a handler for this space we
912 1.1 jruoho * don't care about it. We just ignore it and proceed.
913 1.1 jruoho */
914 1.1 jruoho return (AE_OK);
915 1.1 jruoho }
916 1.1 jruoho
917 1.1 jruoho /* Object is a Region */
918 1.1 jruoho
919 1.1 jruoho if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
920 1.1 jruoho {
921 1.1 jruoho /* This region is for a different address space, just ignore it */
922 1.1 jruoho
923 1.1 jruoho return (AE_OK);
924 1.1 jruoho }
925 1.1 jruoho
926 1.1 jruoho /*
927 1.1 jruoho * Now we have a region and it is for the handler's address space type.
928 1.1 jruoho *
929 1.1 jruoho * First disconnect region for any previous handler (if any)
930 1.1 jruoho */
931 1.1 jruoho AcpiEvDetachRegion (ObjDesc, FALSE);
932 1.1 jruoho
933 1.1 jruoho /* Connect the region to the new handler */
934 1.1 jruoho
935 1.1 jruoho Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
936 1.1 jruoho return (Status);
937 1.1 jruoho }
938 1.1 jruoho
939 1.1 jruoho
940 1.1 jruoho /*******************************************************************************
941 1.1 jruoho *
942 1.1 jruoho * FUNCTION: AcpiEvInstallSpaceHandler
943 1.1 jruoho *
944 1.1 jruoho * PARAMETERS: Node - Namespace node for the device
945 1.1 jruoho * SpaceId - The address space ID
946 1.1 jruoho * Handler - Address of the handler
947 1.1 jruoho * Setup - Address of the setup function
948 1.1 jruoho * Context - Value passed to the handler on each access
949 1.1 jruoho *
950 1.1 jruoho * RETURN: Status
951 1.1 jruoho *
952 1.1 jruoho * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
953 1.1 jruoho * Assumes namespace is locked
954 1.1 jruoho *
955 1.1 jruoho ******************************************************************************/
956 1.1 jruoho
957 1.1 jruoho ACPI_STATUS
958 1.1 jruoho AcpiEvInstallSpaceHandler (
959 1.1 jruoho ACPI_NAMESPACE_NODE *Node,
960 1.1 jruoho ACPI_ADR_SPACE_TYPE SpaceId,
961 1.1 jruoho ACPI_ADR_SPACE_HANDLER Handler,
962 1.1 jruoho ACPI_ADR_SPACE_SETUP Setup,
963 1.1 jruoho void *Context)
964 1.1 jruoho {
965 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
966 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerObj;
967 1.1 jruoho ACPI_STATUS Status;
968 1.1 jruoho ACPI_OBJECT_TYPE Type;
969 1.1 jruoho UINT8 Flags = 0;
970 1.1 jruoho
971 1.1 jruoho
972 1.1 jruoho ACPI_FUNCTION_TRACE (EvInstallSpaceHandler);
973 1.1 jruoho
974 1.1 jruoho
975 1.1 jruoho /*
976 1.1 jruoho * This registration is valid for only the types below and the root. This
977 1.1 jruoho * is where the default handlers get placed.
978 1.1 jruoho */
979 1.1 jruoho if ((Node->Type != ACPI_TYPE_DEVICE) &&
980 1.1 jruoho (Node->Type != ACPI_TYPE_PROCESSOR) &&
981 1.1 jruoho (Node->Type != ACPI_TYPE_THERMAL) &&
982 1.1 jruoho (Node != AcpiGbl_RootNode))
983 1.1 jruoho {
984 1.1 jruoho Status = AE_BAD_PARAMETER;
985 1.1 jruoho goto UnlockAndExit;
986 1.1 jruoho }
987 1.1 jruoho
988 1.1 jruoho if (Handler == ACPI_DEFAULT_HANDLER)
989 1.1 jruoho {
990 1.1 jruoho Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
991 1.1 jruoho
992 1.1 jruoho switch (SpaceId)
993 1.1 jruoho {
994 1.1 jruoho case ACPI_ADR_SPACE_SYSTEM_MEMORY:
995 1.1 jruoho Handler = AcpiExSystemMemorySpaceHandler;
996 1.1 jruoho Setup = AcpiEvSystemMemoryRegionSetup;
997 1.1 jruoho break;
998 1.1 jruoho
999 1.1 jruoho case ACPI_ADR_SPACE_SYSTEM_IO:
1000 1.1 jruoho Handler = AcpiExSystemIoSpaceHandler;
1001 1.1 jruoho Setup = AcpiEvIoSpaceRegionSetup;
1002 1.1 jruoho break;
1003 1.1 jruoho
1004 1.1 jruoho case ACPI_ADR_SPACE_PCI_CONFIG:
1005 1.1 jruoho Handler = AcpiExPciConfigSpaceHandler;
1006 1.1 jruoho Setup = AcpiEvPciConfigRegionSetup;
1007 1.1 jruoho break;
1008 1.1 jruoho
1009 1.1 jruoho case ACPI_ADR_SPACE_CMOS:
1010 1.1 jruoho Handler = AcpiExCmosSpaceHandler;
1011 1.1 jruoho Setup = AcpiEvCmosRegionSetup;
1012 1.1 jruoho break;
1013 1.1 jruoho
1014 1.1 jruoho case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1015 1.1 jruoho Handler = AcpiExPciBarSpaceHandler;
1016 1.1 jruoho Setup = AcpiEvPciBarRegionSetup;
1017 1.1 jruoho break;
1018 1.1 jruoho
1019 1.1 jruoho case ACPI_ADR_SPACE_DATA_TABLE:
1020 1.1 jruoho Handler = AcpiExDataTableSpaceHandler;
1021 1.1 jruoho Setup = NULL;
1022 1.1 jruoho break;
1023 1.1 jruoho
1024 1.1 jruoho default:
1025 1.1 jruoho Status = AE_BAD_PARAMETER;
1026 1.1 jruoho goto UnlockAndExit;
1027 1.1 jruoho }
1028 1.1 jruoho }
1029 1.1 jruoho
1030 1.1 jruoho /* If the caller hasn't specified a setup routine, use the default */
1031 1.1 jruoho
1032 1.1 jruoho if (!Setup)
1033 1.1 jruoho {
1034 1.1 jruoho Setup = AcpiEvDefaultRegionSetup;
1035 1.1 jruoho }
1036 1.1 jruoho
1037 1.1 jruoho /* Check for an existing internal object */
1038 1.1 jruoho
1039 1.1 jruoho ObjDesc = AcpiNsGetAttachedObject (Node);
1040 1.1 jruoho if (ObjDesc)
1041 1.1 jruoho {
1042 1.1 jruoho /*
1043 1.1 jruoho * The attached device object already exists. Make sure the handler
1044 1.1 jruoho * is not already installed.
1045 1.1 jruoho */
1046 1.1 jruoho HandlerObj = ObjDesc->Device.Handler;
1047 1.1 jruoho
1048 1.1 jruoho /* Walk the handler list for this device */
1049 1.1 jruoho
1050 1.1 jruoho while (HandlerObj)
1051 1.1 jruoho {
1052 1.1 jruoho /* Same SpaceId indicates a handler already installed */
1053 1.1 jruoho
1054 1.1 jruoho if (HandlerObj->AddressSpace.SpaceId == SpaceId)
1055 1.1 jruoho {
1056 1.1 jruoho if (HandlerObj->AddressSpace.Handler == Handler)
1057 1.1 jruoho {
1058 1.1 jruoho /*
1059 1.1 jruoho * It is (relatively) OK to attempt to install the SAME
1060 1.1 jruoho * handler twice. This can easily happen with the
1061 1.1 jruoho * PCI_Config space.
1062 1.1 jruoho */
1063 1.1 jruoho Status = AE_SAME_HANDLER;
1064 1.1 jruoho goto UnlockAndExit;
1065 1.1 jruoho }
1066 1.1 jruoho else
1067 1.1 jruoho {
1068 1.1 jruoho /* A handler is already installed */
1069 1.1 jruoho
1070 1.1 jruoho Status = AE_ALREADY_EXISTS;
1071 1.1 jruoho }
1072 1.1 jruoho goto UnlockAndExit;
1073 1.1 jruoho }
1074 1.1 jruoho
1075 1.1 jruoho /* Walk the linked list of handlers */
1076 1.1 jruoho
1077 1.1 jruoho HandlerObj = HandlerObj->AddressSpace.Next;
1078 1.1 jruoho }
1079 1.1 jruoho }
1080 1.1 jruoho else
1081 1.1 jruoho {
1082 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
1083 1.1 jruoho "Creating object on Device %p while installing handler\n", Node));
1084 1.1 jruoho
1085 1.1 jruoho /* ObjDesc does not exist, create one */
1086 1.1 jruoho
1087 1.1 jruoho if (Node->Type == ACPI_TYPE_ANY)
1088 1.1 jruoho {
1089 1.1 jruoho Type = ACPI_TYPE_DEVICE;
1090 1.1 jruoho }
1091 1.1 jruoho else
1092 1.1 jruoho {
1093 1.1 jruoho Type = Node->Type;
1094 1.1 jruoho }
1095 1.1 jruoho
1096 1.1 jruoho ObjDesc = AcpiUtCreateInternalObject (Type);
1097 1.1 jruoho if (!ObjDesc)
1098 1.1 jruoho {
1099 1.1 jruoho Status = AE_NO_MEMORY;
1100 1.1 jruoho goto UnlockAndExit;
1101 1.1 jruoho }
1102 1.1 jruoho
1103 1.1 jruoho /* Init new descriptor */
1104 1.1 jruoho
1105 1.1 jruoho ObjDesc->Common.Type = (UINT8) Type;
1106 1.1 jruoho
1107 1.1 jruoho /* Attach the new object to the Node */
1108 1.1 jruoho
1109 1.1 jruoho Status = AcpiNsAttachObject (Node, ObjDesc, Type);
1110 1.1 jruoho
1111 1.1 jruoho /* Remove local reference to the object */
1112 1.1 jruoho
1113 1.1 jruoho AcpiUtRemoveReference (ObjDesc);
1114 1.1 jruoho
1115 1.1 jruoho if (ACPI_FAILURE (Status))
1116 1.1 jruoho {
1117 1.1 jruoho goto UnlockAndExit;
1118 1.1 jruoho }
1119 1.1 jruoho }
1120 1.1 jruoho
1121 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
1122 1.1 jruoho "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
1123 1.1 jruoho AcpiUtGetRegionName (SpaceId), SpaceId,
1124 1.1 jruoho AcpiUtGetNodeName (Node), Node, ObjDesc));
1125 1.1 jruoho
1126 1.1 jruoho /*
1127 1.1 jruoho * Install the handler
1128 1.1 jruoho *
1129 1.1 jruoho * At this point there is no existing handler. Just allocate the object
1130 1.1 jruoho * for the handler and link it into the list.
1131 1.1 jruoho */
1132 1.1 jruoho HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
1133 1.1 jruoho if (!HandlerObj)
1134 1.1 jruoho {
1135 1.1 jruoho Status = AE_NO_MEMORY;
1136 1.1 jruoho goto UnlockAndExit;
1137 1.1 jruoho }
1138 1.1 jruoho
1139 1.1 jruoho /* Init handler obj */
1140 1.1 jruoho
1141 1.1 jruoho HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId;
1142 1.1 jruoho HandlerObj->AddressSpace.HandlerFlags = Flags;
1143 1.1 jruoho HandlerObj->AddressSpace.RegionList = NULL;
1144 1.1 jruoho HandlerObj->AddressSpace.Node = Node;
1145 1.1 jruoho HandlerObj->AddressSpace.Handler = Handler;
1146 1.1 jruoho HandlerObj->AddressSpace.Context = Context;
1147 1.1 jruoho HandlerObj->AddressSpace.Setup = Setup;
1148 1.1 jruoho
1149 1.1 jruoho /* Install at head of Device.AddressSpace list */
1150 1.1 jruoho
1151 1.1 jruoho HandlerObj->AddressSpace.Next = ObjDesc->Device.Handler;
1152 1.1 jruoho
1153 1.1 jruoho /*
1154 1.1 jruoho * The Device object is the first reference on the HandlerObj.
1155 1.1 jruoho * Each region that uses the handler adds a reference.
1156 1.1 jruoho */
1157 1.1 jruoho ObjDesc->Device.Handler = HandlerObj;
1158 1.1 jruoho
1159 1.1 jruoho /*
1160 1.1 jruoho * Walk the namespace finding all of the regions this
1161 1.1 jruoho * handler will manage.
1162 1.1 jruoho *
1163 1.1 jruoho * Start at the device and search the branch toward
1164 1.1 jruoho * the leaf nodes until either the leaf is encountered or
1165 1.1 jruoho * a device is detected that has an address handler of the
1166 1.1 jruoho * same type.
1167 1.1 jruoho *
1168 1.1 jruoho * In either case, back up and search down the remainder
1169 1.1 jruoho * of the branch
1170 1.1 jruoho */
1171 1.1 jruoho Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
1172 1.1 jruoho ACPI_NS_WALK_UNLOCK, AcpiEvInstallHandler, NULL,
1173 1.1 jruoho HandlerObj, NULL);
1174 1.1 jruoho
1175 1.1 jruoho UnlockAndExit:
1176 1.1 jruoho return_ACPI_STATUS (Status);
1177 1.1 jruoho }
1178 1.1 jruoho
1179 1.1 jruoho
1180 1.1 jruoho /*******************************************************************************
1181 1.1 jruoho *
1182 1.1 jruoho * FUNCTION: AcpiEvExecuteRegMethods
1183 1.1 jruoho *
1184 1.1 jruoho * PARAMETERS: Node - Namespace node for the device
1185 1.1 jruoho * SpaceId - The address space ID
1186 1.1 jruoho *
1187 1.1 jruoho * RETURN: Status
1188 1.1 jruoho *
1189 1.1 jruoho * DESCRIPTION: Run all _REG methods for the input Space ID;
1190 1.1 jruoho * Note: assumes namespace is locked, or system init time.
1191 1.1 jruoho *
1192 1.1 jruoho ******************************************************************************/
1193 1.1 jruoho
1194 1.1 jruoho ACPI_STATUS
1195 1.1 jruoho AcpiEvExecuteRegMethods (
1196 1.1 jruoho ACPI_NAMESPACE_NODE *Node,
1197 1.1 jruoho ACPI_ADR_SPACE_TYPE SpaceId)
1198 1.1 jruoho {
1199 1.1 jruoho ACPI_STATUS Status;
1200 1.1 jruoho
1201 1.1 jruoho
1202 1.1 jruoho ACPI_FUNCTION_TRACE (EvExecuteRegMethods);
1203 1.1 jruoho
1204 1.1 jruoho
1205 1.1 jruoho /*
1206 1.1 jruoho * Run all _REG methods for all Operation Regions for this space ID. This
1207 1.1 jruoho * is a separate walk in order to handle any interdependencies between
1208 1.1 jruoho * regions and _REG methods. (i.e. handlers must be installed for all
1209 1.1 jruoho * regions of this Space ID before we can run any _REG methods)
1210 1.1 jruoho */
1211 1.1 jruoho Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
1212 1.1 jruoho ACPI_NS_WALK_UNLOCK, AcpiEvRegRun, NULL,
1213 1.1 jruoho &SpaceId, NULL);
1214 1.1 jruoho
1215 1.1 jruoho return_ACPI_STATUS (Status);
1216 1.1 jruoho }
1217 1.1 jruoho
1218 1.1 jruoho
1219 1.1 jruoho /*******************************************************************************
1220 1.1 jruoho *
1221 1.1 jruoho * FUNCTION: AcpiEvRegRun
1222 1.1 jruoho *
1223 1.1 jruoho * PARAMETERS: WalkNamespace callback
1224 1.1 jruoho *
1225 1.1 jruoho * DESCRIPTION: Run _REG method for region objects of the requested spaceID
1226 1.1 jruoho *
1227 1.1 jruoho ******************************************************************************/
1228 1.1 jruoho
1229 1.1 jruoho static ACPI_STATUS
1230 1.1 jruoho AcpiEvRegRun (
1231 1.1 jruoho ACPI_HANDLE ObjHandle,
1232 1.1 jruoho UINT32 Level,
1233 1.1 jruoho void *Context,
1234 1.1 jruoho void **ReturnValue)
1235 1.1 jruoho {
1236 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
1237 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
1238 1.1 jruoho ACPI_ADR_SPACE_TYPE SpaceId;
1239 1.1 jruoho ACPI_STATUS Status;
1240 1.1 jruoho
1241 1.1 jruoho
1242 1.1 jruoho SpaceId = *ACPI_CAST_PTR (ACPI_ADR_SPACE_TYPE, Context);
1243 1.1 jruoho
1244 1.1 jruoho /* Convert and validate the device handle */
1245 1.1 jruoho
1246 1.1 jruoho Node = AcpiNsValidateHandle (ObjHandle);
1247 1.1 jruoho if (!Node)
1248 1.1 jruoho {
1249 1.1 jruoho return (AE_BAD_PARAMETER);
1250 1.1 jruoho }
1251 1.1 jruoho
1252 1.1 jruoho /*
1253 1.1 jruoho * We only care about regions.and objects that are allowed to have address
1254 1.1 jruoho * space handlers
1255 1.1 jruoho */
1256 1.1 jruoho if ((Node->Type != ACPI_TYPE_REGION) &&
1257 1.1 jruoho (Node != AcpiGbl_RootNode))
1258 1.1 jruoho {
1259 1.1 jruoho return (AE_OK);
1260 1.1 jruoho }
1261 1.1 jruoho
1262 1.1 jruoho /* Check for an existing internal object */
1263 1.1 jruoho
1264 1.1 jruoho ObjDesc = AcpiNsGetAttachedObject (Node);
1265 1.1 jruoho if (!ObjDesc)
1266 1.1 jruoho {
1267 1.1 jruoho /* No object, just exit */
1268 1.1 jruoho
1269 1.1 jruoho return (AE_OK);
1270 1.1 jruoho }
1271 1.1 jruoho
1272 1.1 jruoho /* Object is a Region */
1273 1.1 jruoho
1274 1.1 jruoho if (ObjDesc->Region.SpaceId != SpaceId)
1275 1.1 jruoho {
1276 1.1 jruoho /* This region is for a different address space, just ignore it */
1277 1.1 jruoho
1278 1.1 jruoho return (AE_OK);
1279 1.1 jruoho }
1280 1.1 jruoho
1281 1.1 jruoho Status = AcpiEvExecuteRegMethod (ObjDesc, 1);
1282 1.1 jruoho return (Status);
1283 1.1 jruoho }
1284 1.1 jruoho
1285