Sync usage with man page.
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / events / evrgnini.c
blob480c27ad769ea75fbe514f8a1640f648bf70d156
1 /******************************************************************************
3 * Module Name: evrgnini- ACPI AddressSpace (OpRegion) init
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #define __EVRGNINI_C__
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "acevents.h"
122 #include "acnamesp.h"
124 #define _COMPONENT ACPI_EVENTS
125 ACPI_MODULE_NAME ("evrgnini")
127 /* Local prototypes */
129 static BOOLEAN
130 AcpiEvIsPciRootBridge (
131 ACPI_NAMESPACE_NODE *Node);
134 /*******************************************************************************
136 * FUNCTION: AcpiEvSystemMemoryRegionSetup
138 * PARAMETERS: Handle - Region we are interested in
139 * Function - Start or stop
140 * HandlerContext - Address space handler context
141 * RegionContext - Region specific context
143 * RETURN: Status
145 * DESCRIPTION: Setup a SystemMemory operation region
147 ******************************************************************************/
149 ACPI_STATUS
150 AcpiEvSystemMemoryRegionSetup (
151 ACPI_HANDLE Handle,
152 UINT32 Function,
153 void *HandlerContext,
154 void **RegionContext)
156 ACPI_OPERAND_OBJECT *RegionDesc = (ACPI_OPERAND_OBJECT *) Handle;
157 ACPI_MEM_SPACE_CONTEXT *LocalRegionContext;
160 ACPI_FUNCTION_TRACE (EvSystemMemoryRegionSetup);
163 if (Function == ACPI_REGION_DEACTIVATE)
165 if (*RegionContext)
167 LocalRegionContext = (ACPI_MEM_SPACE_CONTEXT *) *RegionContext;
169 /* Delete a cached mapping if present */
171 if (LocalRegionContext->MappedLength)
173 AcpiOsUnmapMemory (LocalRegionContext->MappedLogicalAddress,
174 LocalRegionContext->MappedLength);
176 ACPI_FREE (LocalRegionContext);
177 *RegionContext = NULL;
179 return_ACPI_STATUS (AE_OK);
182 /* Create a new context */
184 LocalRegionContext = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_MEM_SPACE_CONTEXT));
185 if (!(LocalRegionContext))
187 return_ACPI_STATUS (AE_NO_MEMORY);
190 /* Save the region length and address for use in the handler */
192 LocalRegionContext->Length = RegionDesc->Region.Length;
193 LocalRegionContext->Address = RegionDesc->Region.Address;
195 *RegionContext = LocalRegionContext;
196 return_ACPI_STATUS (AE_OK);
200 /*******************************************************************************
202 * FUNCTION: AcpiEvIoSpaceRegionSetup
204 * PARAMETERS: Handle - Region we are interested in
205 * Function - Start or stop
206 * HandlerContext - Address space handler context
207 * RegionContext - Region specific context
209 * RETURN: Status
211 * DESCRIPTION: Setup a IO operation region
213 ******************************************************************************/
215 ACPI_STATUS
216 AcpiEvIoSpaceRegionSetup (
217 ACPI_HANDLE Handle,
218 UINT32 Function,
219 void *HandlerContext,
220 void **RegionContext)
222 ACPI_FUNCTION_TRACE (EvIoSpaceRegionSetup);
225 if (Function == ACPI_REGION_DEACTIVATE)
227 *RegionContext = NULL;
229 else
231 *RegionContext = HandlerContext;
234 return_ACPI_STATUS (AE_OK);
238 /*******************************************************************************
240 * FUNCTION: AcpiEvPciConfigRegionSetup
242 * PARAMETERS: Handle - Region we are interested in
243 * Function - Start or stop
244 * HandlerContext - Address space handler context
245 * RegionContext - Region specific context
247 * RETURN: Status
249 * DESCRIPTION: Setup a PCI_Config operation region
251 * MUTEX: Assumes namespace is not locked
253 ******************************************************************************/
255 ACPI_STATUS
256 AcpiEvPciConfigRegionSetup (
257 ACPI_HANDLE Handle,
258 UINT32 Function,
259 void *HandlerContext,
260 void **RegionContext)
262 ACPI_STATUS Status = AE_OK;
263 ACPI_INTEGER PciValue;
264 ACPI_PCI_ID *PciId = *RegionContext;
265 ACPI_OPERAND_OBJECT *HandlerObj;
266 ACPI_NAMESPACE_NODE *ParentNode;
267 ACPI_NAMESPACE_NODE *PciRootNode;
268 ACPI_NAMESPACE_NODE *PciDeviceNode;
269 ACPI_OPERAND_OBJECT *RegionObj = (ACPI_OPERAND_OBJECT *) Handle;
272 ACPI_FUNCTION_TRACE (EvPciConfigRegionSetup);
275 HandlerObj = RegionObj->Region.Handler;
276 if (!HandlerObj)
279 * No installed handler. This shouldn't happen because the dispatch
280 * routine checks before we get here, but we check again just in case.
282 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
283 "Attempting to init a region %p, with no handler\n", RegionObj));
284 return_ACPI_STATUS (AE_NOT_EXIST);
287 *RegionContext = NULL;
288 if (Function == ACPI_REGION_DEACTIVATE)
290 if (PciId)
292 ACPI_FREE (PciId);
294 return_ACPI_STATUS (Status);
297 ParentNode = AcpiNsGetParentNode (RegionObj->Region.Node);
300 * Get the _SEG and _BBN values from the device upon which the handler
301 * is installed.
303 * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
304 * This is the device the handler has been registered to handle.
308 * If the AddressSpace.Node is still pointing to the root, we need
309 * to scan upward for a PCI Root bridge and re-associate the OpRegion
310 * handlers with that device.
312 if (HandlerObj->AddressSpace.Node == AcpiGbl_RootNode)
314 /* Start search from the parent object */
316 PciRootNode = ParentNode;
317 while (PciRootNode != AcpiGbl_RootNode)
319 /* Get the _HID/_CID in order to detect a RootBridge */
321 if (AcpiEvIsPciRootBridge (PciRootNode))
323 /* Install a handler for this PCI root bridge */
325 Status = AcpiInstallAddressSpaceHandler (
326 (ACPI_HANDLE) PciRootNode,
327 ACPI_ADR_SPACE_PCI_CONFIG,
328 ACPI_DEFAULT_HANDLER, NULL, NULL);
329 if (ACPI_FAILURE (Status))
331 if (Status == AE_SAME_HANDLER)
334 * It is OK if the handler is already installed on the
335 * root bridge. Still need to return a context object
336 * for the new PCI_Config operation region, however.
338 Status = AE_OK;
340 else
342 ACPI_EXCEPTION ((AE_INFO, Status,
343 "Could not install PciConfig handler "
344 "for Root Bridge %4.4s",
345 AcpiUtGetNodeName (PciRootNode)));
348 break;
351 PciRootNode = AcpiNsGetParentNode (PciRootNode);
354 /* PCI root bridge not found, use namespace root node */
356 else
358 PciRootNode = HandlerObj->AddressSpace.Node;
362 * If this region is now initialized, we are done.
363 * (InstallAddressSpaceHandler could have initialized it)
365 if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
367 return_ACPI_STATUS (AE_OK);
370 /* Region is still not initialized. Create a new context */
372 PciId = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PCI_ID));
373 if (!PciId)
375 return_ACPI_STATUS (AE_NO_MEMORY);
379 * For PCI_Config space access, we need the segment, bus, device and
380 * function numbers. Acquire them here.
382 * Find the parent device object. (This allows the operation region to be
383 * within a subscope under the device, such as a control method.)
385 PciDeviceNode = RegionObj->Region.Node;
386 while (PciDeviceNode && (PciDeviceNode->Type != ACPI_TYPE_DEVICE))
388 PciDeviceNode = AcpiNsGetParentNode (PciDeviceNode);
391 if (!PciDeviceNode)
393 ACPI_FREE (PciId);
394 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
398 * Get the PCI device and function numbers from the _ADR object contained
399 * in the parent's scope.
401 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR,
402 PciDeviceNode, &PciValue);
405 * The default is zero, and since the allocation above zeroed the data,
406 * just do nothing on failure.
408 if (ACPI_SUCCESS (Status))
410 PciId->Device = ACPI_HIWORD (ACPI_LODWORD (PciValue));
411 PciId->Function = ACPI_LOWORD (ACPI_LODWORD (PciValue));
414 /* The PCI segment number comes from the _SEG method */
416 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__SEG,
417 PciRootNode, &PciValue);
418 if (ACPI_SUCCESS (Status))
420 PciId->Segment = ACPI_LOWORD (PciValue);
423 /* The PCI bus number comes from the _BBN method */
425 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__BBN,
426 PciRootNode, &PciValue);
427 if (ACPI_SUCCESS (Status))
429 PciId->Bus = ACPI_LOWORD (PciValue);
432 /* Complete this device's PciId */
434 AcpiOsDerivePciId (PciRootNode, RegionObj->Region.Node, &PciId);
436 *RegionContext = PciId;
437 return_ACPI_STATUS (AE_OK);
441 /*******************************************************************************
443 * FUNCTION: AcpiEvIsPciRootBridge
445 * PARAMETERS: Node - Device node being examined
447 * RETURN: TRUE if device is a PCI/PCI-Express Root Bridge
449 * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by
450 * examining the _HID and _CID for the device.
452 ******************************************************************************/
454 static BOOLEAN
455 AcpiEvIsPciRootBridge (
456 ACPI_NAMESPACE_NODE *Node)
458 ACPI_STATUS Status;
459 ACPI_DEVICE_ID *Hid;
460 ACPI_DEVICE_ID_LIST *Cid;
461 UINT32 i;
462 BOOLEAN Match;
465 /* Get the _HID and check for a PCI Root Bridge */
467 Status = AcpiUtExecute_HID (Node, &Hid);
468 if (ACPI_FAILURE (Status))
470 return (FALSE);
473 Match = AcpiUtIsPciRootBridge (Hid->String);
474 ACPI_FREE (Hid);
476 if (Match)
478 return (TRUE);
481 /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */
483 Status = AcpiUtExecute_CID (Node, &Cid);
484 if (ACPI_FAILURE (Status))
486 return (FALSE);
489 /* Check all _CIDs in the returned list */
491 for (i = 0; i < Cid->Count; i++)
493 if (AcpiUtIsPciRootBridge (Cid->Ids[i].String))
495 ACPI_FREE (Cid);
496 return (TRUE);
500 ACPI_FREE (Cid);
501 return (FALSE);
505 /*******************************************************************************
507 * FUNCTION: AcpiEvPciBarRegionSetup
509 * PARAMETERS: Handle - Region we are interested in
510 * Function - Start or stop
511 * HandlerContext - Address space handler context
512 * RegionContext - Region specific context
514 * RETURN: Status
516 * DESCRIPTION: Setup a PciBAR operation region
518 * MUTEX: Assumes namespace is not locked
520 ******************************************************************************/
522 ACPI_STATUS
523 AcpiEvPciBarRegionSetup (
524 ACPI_HANDLE Handle,
525 UINT32 Function,
526 void *HandlerContext,
527 void **RegionContext)
529 ACPI_FUNCTION_TRACE (EvPciBarRegionSetup);
532 return_ACPI_STATUS (AE_OK);
536 /*******************************************************************************
538 * FUNCTION: AcpiEvCmosRegionSetup
540 * PARAMETERS: Handle - Region we are interested in
541 * Function - Start or stop
542 * HandlerContext - Address space handler context
543 * RegionContext - Region specific context
545 * RETURN: Status
547 * DESCRIPTION: Setup a CMOS operation region
549 * MUTEX: Assumes namespace is not locked
551 ******************************************************************************/
553 ACPI_STATUS
554 AcpiEvCmosRegionSetup (
555 ACPI_HANDLE Handle,
556 UINT32 Function,
557 void *HandlerContext,
558 void **RegionContext)
560 ACPI_FUNCTION_TRACE (EvCmosRegionSetup);
563 return_ACPI_STATUS (AE_OK);
567 /*******************************************************************************
569 * FUNCTION: AcpiEvDefaultRegionSetup
571 * PARAMETERS: Handle - Region we are interested in
572 * Function - Start or stop
573 * HandlerContext - Address space handler context
574 * RegionContext - Region specific context
576 * RETURN: Status
578 * DESCRIPTION: Default region initialization
580 ******************************************************************************/
582 ACPI_STATUS
583 AcpiEvDefaultRegionSetup (
584 ACPI_HANDLE Handle,
585 UINT32 Function,
586 void *HandlerContext,
587 void **RegionContext)
589 ACPI_FUNCTION_TRACE (EvDefaultRegionSetup);
592 if (Function == ACPI_REGION_DEACTIVATE)
594 *RegionContext = NULL;
596 else
598 *RegionContext = HandlerContext;
601 return_ACPI_STATUS (AE_OK);
605 /*******************************************************************************
607 * FUNCTION: AcpiEvInitializeRegion
609 * PARAMETERS: RegionObj - Region we are initializing
610 * AcpiNsLocked - Is namespace locked?
612 * RETURN: Status
614 * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
615 * for execution at a later time
617 * Get the appropriate address space handler for a newly
618 * created region.
620 * This also performs address space specific initialization. For
621 * example, PCI regions must have an _ADR object that contains
622 * a PCI address in the scope of the definition. This address is
623 * required to perform an access to PCI config space.
625 * MUTEX: Interpreter should be unlocked, because we may run the _REG
626 * method for this region.
628 ******************************************************************************/
630 ACPI_STATUS
631 AcpiEvInitializeRegion (
632 ACPI_OPERAND_OBJECT *RegionObj,
633 BOOLEAN AcpiNsLocked)
635 ACPI_OPERAND_OBJECT *HandlerObj;
636 ACPI_OPERAND_OBJECT *ObjDesc;
637 ACPI_ADR_SPACE_TYPE SpaceId;
638 ACPI_NAMESPACE_NODE *Node;
639 ACPI_STATUS Status;
640 ACPI_NAMESPACE_NODE *MethodNode;
641 ACPI_NAME *RegNamePtr = (ACPI_NAME *) __UNCONST(METHOD_NAME__REG);
642 ACPI_OPERAND_OBJECT *RegionObj2;
645 ACPI_FUNCTION_TRACE_U32 (EvInitializeRegion, AcpiNsLocked);
648 if (!RegionObj)
650 return_ACPI_STATUS (AE_BAD_PARAMETER);
653 if (RegionObj->Common.Flags & AOPOBJ_OBJECT_INITIALIZED)
655 return_ACPI_STATUS (AE_OK);
658 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
659 if (!RegionObj2)
661 return_ACPI_STATUS (AE_NOT_EXIST);
664 Node = AcpiNsGetParentNode (RegionObj->Region.Node);
665 SpaceId = RegionObj->Region.SpaceId;
667 /* Setup defaults */
669 RegionObj->Region.Handler = NULL;
670 RegionObj2->Extra.Method_REG = NULL;
671 RegionObj->Common.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
672 RegionObj->Common.Flags |= AOPOBJ_OBJECT_INITIALIZED;
674 /* Find any "_REG" method associated with this region definition */
676 Status = AcpiNsSearchOneScope (
677 *RegNamePtr, Node, ACPI_TYPE_METHOD, &MethodNode);
678 if (ACPI_SUCCESS (Status))
681 * The _REG method is optional and there can be only one per region
682 * definition. This will be executed when the handler is attached
683 * or removed
685 RegionObj2->Extra.Method_REG = MethodNode;
689 * The following loop depends upon the root Node having no parent
690 * ie: AcpiGbl_RootNode->ParentEntry being set to NULL
692 while (Node)
694 /* Check to see if a handler exists */
696 HandlerObj = NULL;
697 ObjDesc = AcpiNsGetAttachedObject (Node);
698 if (ObjDesc)
700 /* Can only be a handler if the object exists */
702 switch (Node->Type)
704 case ACPI_TYPE_DEVICE:
706 HandlerObj = ObjDesc->Device.Handler;
707 break;
709 case ACPI_TYPE_PROCESSOR:
711 HandlerObj = ObjDesc->Processor.Handler;
712 break;
714 case ACPI_TYPE_THERMAL:
716 HandlerObj = ObjDesc->ThermalZone.Handler;
717 break;
719 default:
720 /* Ignore other objects */
721 break;
724 while (HandlerObj)
726 /* Is this handler of the correct type? */
728 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
730 /* Found correct handler */
732 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
733 "Found handler %p for region %p in obj %p\n",
734 HandlerObj, RegionObj, ObjDesc));
736 Status = AcpiEvAttachRegion (HandlerObj, RegionObj,
737 AcpiNsLocked);
740 * Tell all users that this region is usable by
741 * running the _REG method
743 if (AcpiNsLocked)
745 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
746 if (ACPI_FAILURE (Status))
748 return_ACPI_STATUS (Status);
752 Status = AcpiEvExecuteRegMethod (RegionObj, 1);
754 if (AcpiNsLocked)
756 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
757 if (ACPI_FAILURE (Status))
759 return_ACPI_STATUS (Status);
763 return_ACPI_STATUS (AE_OK);
766 /* Try next handler in the list */
768 HandlerObj = HandlerObj->AddressSpace.Next;
772 /* This node does not have the handler we need; Pop up one level */
774 Node = AcpiNsGetParentNode (Node);
777 /* If we get here, there is no handler for this region */
779 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
780 "No handler for RegionType %s(%X) (RegionObj %p)\n",
781 AcpiUtGetRegionName (SpaceId), SpaceId, RegionObj));
783 return_ACPI_STATUS (AE_NOT_EXIST);