]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/contrib/dev/acpica/evrgnini.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / contrib / dev / acpica / evrgnini.c
1 /******************************************************************************
2  *
3  * Module Name: evrgnini- ACPI AddressSpace (OpRegion) init
4  *              $Revision: 1.88 $
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116
117
118 #define __EVRGNINI_C__
119
120 #include <contrib/dev/acpica/acpi.h>
121 #include <contrib/dev/acpica/acevents.h>
122 #include <contrib/dev/acpica/acnamesp.h>
123
124 #define _COMPONENT          ACPI_EVENTS
125         ACPI_MODULE_NAME    ("evrgnini")
126
127 /* Local prototypes */
128
129 static BOOLEAN
130 AcpiEvMatchPciRootBridge (
131     char                    *Id);
132
133 static BOOLEAN
134 AcpiEvIsPciRootBridge (
135     ACPI_NAMESPACE_NODE     *Node);
136
137
138 /*******************************************************************************
139  *
140  * FUNCTION:    AcpiEvSystemMemoryRegionSetup
141  *
142  * PARAMETERS:  Handle              - Region we are interested in
143  *              Function            - Start or stop
144  *              HandlerContext      - Address space handler context
145  *              RegionContext       - Region specific context
146  *
147  * RETURN:      Status
148  *
149  * DESCRIPTION: Setup a SystemMemory operation region
150  *
151  ******************************************************************************/
152
153 ACPI_STATUS
154 AcpiEvSystemMemoryRegionSetup (
155     ACPI_HANDLE             Handle,
156     UINT32                  Function,
157     void                    *HandlerContext,
158     void                    **RegionContext)
159 {
160     ACPI_OPERAND_OBJECT     *RegionDesc = (ACPI_OPERAND_OBJECT *) Handle;
161     ACPI_MEM_SPACE_CONTEXT  *LocalRegionContext;
162
163
164     ACPI_FUNCTION_TRACE (EvSystemMemoryRegionSetup);
165
166
167     if (Function == ACPI_REGION_DEACTIVATE)
168     {
169         if (*RegionContext)
170         {
171             LocalRegionContext = (ACPI_MEM_SPACE_CONTEXT *) *RegionContext;
172
173             /* Delete a cached mapping if present */
174
175             if (LocalRegionContext->MappedLength)
176             {
177                 AcpiOsUnmapMemory (LocalRegionContext->MappedLogicalAddress,
178                     LocalRegionContext->MappedLength);
179             }
180             ACPI_FREE (LocalRegionContext);
181             *RegionContext = NULL;
182         }
183         return_ACPI_STATUS (AE_OK);
184     }
185
186     /* Create a new context */
187
188     LocalRegionContext = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_MEM_SPACE_CONTEXT));
189     if (!(LocalRegionContext))
190     {
191         return_ACPI_STATUS (AE_NO_MEMORY);
192     }
193
194     /* Save the region length and address for use in the handler */
195
196     LocalRegionContext->Length  = RegionDesc->Region.Length;
197     LocalRegionContext->Address = RegionDesc->Region.Address;
198
199     *RegionContext = LocalRegionContext;
200     return_ACPI_STATUS (AE_OK);
201 }
202
203
204 /*******************************************************************************
205  *
206  * FUNCTION:    AcpiEvIoSpaceRegionSetup
207  *
208  * PARAMETERS:  Handle              - Region we are interested in
209  *              Function            - Start or stop
210  *              HandlerContext      - Address space handler context
211  *              RegionContext       - Region specific context
212  *
213  * RETURN:      Status
214  *
215  * DESCRIPTION: Setup a IO operation region
216  *
217  ******************************************************************************/
218
219 ACPI_STATUS
220 AcpiEvIoSpaceRegionSetup (
221     ACPI_HANDLE             Handle,
222     UINT32                  Function,
223     void                    *HandlerContext,
224     void                    **RegionContext)
225 {
226     ACPI_FUNCTION_TRACE (EvIoSpaceRegionSetup);
227
228
229     if (Function == ACPI_REGION_DEACTIVATE)
230     {
231         *RegionContext = NULL;
232     }
233     else
234     {
235         *RegionContext = HandlerContext;
236     }
237
238     return_ACPI_STATUS (AE_OK);
239 }
240
241
242 /*******************************************************************************
243  *
244  * FUNCTION:    AcpiEvPciConfigRegionSetup
245  *
246  * PARAMETERS:  Handle              - Region we are interested in
247  *              Function            - Start or stop
248  *              HandlerContext      - Address space handler context
249  *              RegionContext       - Region specific context
250  *
251  * RETURN:      Status
252  *
253  * DESCRIPTION: Setup a PCI_Config operation region
254  *
255  * MUTEX:       Assumes namespace is not locked
256  *
257  ******************************************************************************/
258
259 ACPI_STATUS
260 AcpiEvPciConfigRegionSetup (
261     ACPI_HANDLE             Handle,
262     UINT32                  Function,
263     void                    *HandlerContext,
264     void                    **RegionContext)
265 {
266     ACPI_STATUS             Status = AE_OK;
267     ACPI_INTEGER            PciValue;
268     ACPI_PCI_ID             *PciId = *RegionContext;
269     ACPI_OPERAND_OBJECT     *HandlerObj;
270     ACPI_NAMESPACE_NODE     *ParentNode;
271     ACPI_NAMESPACE_NODE     *PciRootNode;
272     ACPI_NAMESPACE_NODE     *PciDeviceNode;
273     ACPI_OPERAND_OBJECT     *RegionObj = (ACPI_OPERAND_OBJECT  *) Handle;
274
275
276     ACPI_FUNCTION_TRACE (EvPciConfigRegionSetup);
277
278
279     HandlerObj = RegionObj->Region.Handler;
280     if (!HandlerObj)
281     {
282         /*
283          * No installed handler. This shouldn't happen because the dispatch
284          * routine checks before we get here, but we check again just in case.
285          */
286         ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
287             "Attempting to init a region %p, with no handler\n", RegionObj));
288         return_ACPI_STATUS (AE_NOT_EXIST);
289     }
290
291     *RegionContext = NULL;
292     if (Function == ACPI_REGION_DEACTIVATE)
293     {
294         if (PciId)
295         {
296             ACPI_FREE (PciId);
297         }
298         return_ACPI_STATUS (Status);
299     }
300
301     ParentNode = AcpiNsGetParentNode (RegionObj->Region.Node);
302
303     /*
304      * Get the _SEG and _BBN values from the device upon which the handler
305      * is installed.
306      *
307      * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
308      * This is the device the handler has been registered to handle.
309      */
310
311     /*
312      * If the AddressSpace.Node is still pointing to the root, we need
313      * to scan upward for a PCI Root bridge and re-associate the OpRegion
314      * handlers with that device.
315      */
316     if (HandlerObj->AddressSpace.Node == AcpiGbl_RootNode)
317     {
318         /* Start search from the parent object */
319
320         PciRootNode = ParentNode;
321         while (PciRootNode != AcpiGbl_RootNode)
322         {
323             /* Get the _HID/_CID in order to detect a RootBridge */
324
325             if (AcpiEvIsPciRootBridge (PciRootNode))
326             {
327                 /* Install a handler for this PCI root bridge */
328
329                 Status = AcpiInstallAddressSpaceHandler (
330                             (ACPI_HANDLE) PciRootNode,
331                             ACPI_ADR_SPACE_PCI_CONFIG,
332                             ACPI_DEFAULT_HANDLER, NULL, NULL);
333                 if (ACPI_FAILURE (Status))
334                 {
335                     if (Status == AE_SAME_HANDLER)
336                     {
337                         /*
338                          * It is OK if the handler is already installed on the root
339                          * bridge.  Still need to return a context object for the
340                          * new PCI_Config operation region, however.
341                          */
342                         Status = AE_OK;
343                     }
344                     else
345                     {
346                         ACPI_EXCEPTION ((AE_INFO, Status,
347                             "Could not install PciConfig handler for Root Bridge %4.4s",
348                             AcpiUtGetNodeName (PciRootNode)));
349                     }
350                 }
351                 break;
352             }
353
354             PciRootNode = AcpiNsGetParentNode (PciRootNode);
355         }
356
357         /* PCI root bridge not found, use namespace root node */
358     }
359     else
360     {
361         PciRootNode = HandlerObj->AddressSpace.Node;
362     }
363
364     /*
365      * If this region is now initialized, we are done.
366      * (InstallAddressSpaceHandler could have initialized it)
367      */
368     if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
369     {
370         return_ACPI_STATUS (AE_OK);
371     }
372
373     /* Region is still not initialized. Create a new context */
374
375     PciId = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PCI_ID));
376     if (!PciId)
377     {
378         return_ACPI_STATUS (AE_NO_MEMORY);
379     }
380
381     /*
382      * For PCI_Config space access, we need the segment, bus,
383      * device and function numbers.  Acquire them here.
384      *
385      * Find the parent device object. (This allows the operation region to be
386      * within a subscope under the device, such as a control method.)
387      */
388     PciDeviceNode = RegionObj->Region.Node;
389     while (PciDeviceNode && (PciDeviceNode->Type != ACPI_TYPE_DEVICE))
390     {
391         PciDeviceNode = AcpiNsGetParentNode (PciDeviceNode);
392     }
393
394     if (!PciDeviceNode)
395     {
396         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
397     }
398
399     /*
400      * Get the PCI device and function numbers from the _ADR object
401      * contained in the parent's scope.
402      */
403     Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, PciDeviceNode, &PciValue);
404
405     /*
406      * The default is zero, and since the allocation above zeroed
407      * the data, just do nothing on failure.
408      */
409     if (ACPI_SUCCESS (Status))
410     {
411         PciId->Device   = ACPI_HIWORD (ACPI_LODWORD (PciValue));
412         PciId->Function = ACPI_LOWORD (ACPI_LODWORD (PciValue));
413     }
414
415     /* The PCI segment number comes from the _SEG method */
416
417     Status = AcpiUtEvaluateNumericObject (METHOD_NAME__SEG, PciRootNode, &PciValue);
418     if (ACPI_SUCCESS (Status))
419     {
420         PciId->Segment = ACPI_LOWORD (PciValue);
421     }
422
423     /* The PCI bus number comes from the _BBN method */
424
425     Status = AcpiUtEvaluateNumericObject (METHOD_NAME__BBN, PciRootNode, &PciValue);
426     if (ACPI_SUCCESS (Status))
427     {
428         PciId->Bus = ACPI_LOWORD (PciValue);
429     }
430
431     /* Complete this device's PciId */
432
433     AcpiOsDerivePciId (PciRootNode, RegionObj->Region.Node, &PciId);
434
435     *RegionContext = PciId;
436     return_ACPI_STATUS (AE_OK);
437 }
438
439
440 /*******************************************************************************
441  *
442  * FUNCTION:    AcpiEvMatchPciRootBridge
443  *
444  * PARAMETERS:  Id              - The HID/CID in string format
445  *
446  * RETURN:      TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
447  *
448  * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
449  *
450  ******************************************************************************/
451
452 static BOOLEAN
453 AcpiEvMatchPciRootBridge (
454     char                    *Id)
455 {
456
457     /*
458      * Check if this is a PCI root.
459      * ACPI 3.0+: check for a PCI Express root also.
460      */
461     if (!(ACPI_STRNCMP (Id,
462             PCI_ROOT_HID_STRING,
463             sizeof (PCI_ROOT_HID_STRING)))      ||
464
465         !(ACPI_STRNCMP (Id,
466             PCI_EXPRESS_ROOT_HID_STRING,
467             sizeof (PCI_EXPRESS_ROOT_HID_STRING))))
468     {
469         return (TRUE);
470     }
471
472     return (FALSE);
473 }
474
475
476 /*******************************************************************************
477  *
478  * FUNCTION:    AcpiEvIsPciRootBridge
479  *
480  * PARAMETERS:  Node            - Device node being examined
481  *
482  * RETURN:      TRUE if device is a PCI/PCI-Express Root Bridge
483  *
484  * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by
485  *              examining the _HID and _CID for the device.
486  *
487  ******************************************************************************/
488
489 static BOOLEAN
490 AcpiEvIsPciRootBridge (
491     ACPI_NAMESPACE_NODE     *Node)
492 {
493     ACPI_STATUS             Status;
494     ACPI_DEVICE_ID          Hid;
495     ACPI_COMPATIBLE_ID_LIST *Cid;
496     ACPI_NATIVE_UINT        i;
497
498
499     /*
500      * Get the _HID and check for a PCI Root Bridge
501      */
502     Status = AcpiUtExecute_HID (Node, &Hid);
503     if (ACPI_FAILURE (Status))
504     {
505         return (FALSE);
506     }
507
508     if (AcpiEvMatchPciRootBridge (Hid.Value))
509     {
510         return (TRUE);
511     }
512
513     /*
514      * The _HID did not match.
515      * Get the _CID and check for a PCI Root Bridge
516      */
517     Status = AcpiUtExecute_CID (Node, &Cid);
518     if (ACPI_FAILURE (Status))
519     {
520         return (FALSE);
521     }
522
523     /* Check all _CIDs in the returned list */
524
525     for (i = 0; i < Cid->Count; i++)
526     {
527         if (AcpiEvMatchPciRootBridge (Cid->Id[i].Value))
528         {
529             ACPI_FREE (Cid);
530             return (TRUE);
531         }
532     }
533
534     ACPI_FREE (Cid);
535     return (FALSE);
536 }
537
538
539 /*******************************************************************************
540  *
541  * FUNCTION:    AcpiEvPciBarRegionSetup
542  *
543  * PARAMETERS:  Handle              - Region we are interested in
544  *              Function            - Start or stop
545  *              HandlerContext      - Address space handler context
546  *              RegionContext       - Region specific context
547  *
548  * RETURN:      Status
549  *
550  * DESCRIPTION: Setup a PciBAR operation region
551  *
552  * MUTEX:       Assumes namespace is not locked
553  *
554  ******************************************************************************/
555
556 ACPI_STATUS
557 AcpiEvPciBarRegionSetup (
558     ACPI_HANDLE             Handle,
559     UINT32                  Function,
560     void                    *HandlerContext,
561     void                    **RegionContext)
562 {
563     ACPI_FUNCTION_TRACE (EvPciBarRegionSetup);
564
565
566     return_ACPI_STATUS (AE_OK);
567 }
568
569
570 /*******************************************************************************
571  *
572  * FUNCTION:    AcpiEvCmosRegionSetup
573  *
574  * PARAMETERS:  Handle              - Region we are interested in
575  *              Function            - Start or stop
576  *              HandlerContext      - Address space handler context
577  *              RegionContext       - Region specific context
578  *
579  * RETURN:      Status
580  *
581  * DESCRIPTION: Setup a CMOS operation region
582  *
583  * MUTEX:       Assumes namespace is not locked
584  *
585  ******************************************************************************/
586
587 ACPI_STATUS
588 AcpiEvCmosRegionSetup (
589     ACPI_HANDLE             Handle,
590     UINT32                  Function,
591     void                    *HandlerContext,
592     void                    **RegionContext)
593 {
594     ACPI_FUNCTION_TRACE (EvCmosRegionSetup);
595
596
597     return_ACPI_STATUS (AE_OK);
598 }
599
600
601 /*******************************************************************************
602  *
603  * FUNCTION:    AcpiEvDefaultRegionSetup
604  *
605  * PARAMETERS:  Handle              - Region we are interested in
606  *              Function            - Start or stop
607  *              HandlerContext      - Address space handler context
608  *              RegionContext       - Region specific context
609  *
610  * RETURN:      Status
611  *
612  * DESCRIPTION: Default region initialization
613  *
614  ******************************************************************************/
615
616 ACPI_STATUS
617 AcpiEvDefaultRegionSetup (
618     ACPI_HANDLE             Handle,
619     UINT32                  Function,
620     void                    *HandlerContext,
621     void                    **RegionContext)
622 {
623     ACPI_FUNCTION_TRACE (EvDefaultRegionSetup);
624
625
626     if (Function == ACPI_REGION_DEACTIVATE)
627     {
628         *RegionContext = NULL;
629     }
630     else
631     {
632         *RegionContext = HandlerContext;
633     }
634
635     return_ACPI_STATUS (AE_OK);
636 }
637
638
639 /*******************************************************************************
640  *
641  * FUNCTION:    AcpiEvInitializeRegion
642  *
643  * PARAMETERS:  RegionObj       - Region we are initializing
644  *              AcpiNsLocked    - Is namespace locked?
645  *
646  * RETURN:      Status
647  *
648  * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
649  *              for execution at a later time
650  *
651  *              Get the appropriate address space handler for a newly
652  *              created region.
653  *
654  *              This also performs address space specific initialization.  For
655  *              example, PCI regions must have an _ADR object that contains
656  *              a PCI address in the scope of the definition.  This address is
657  *              required to perform an access to PCI config space.
658  *
659  * MUTEX:       Interpreter should be unlocked, because we may run the _REG
660  *              method for this region.
661  *
662  ******************************************************************************/
663
664 ACPI_STATUS
665 AcpiEvInitializeRegion (
666     ACPI_OPERAND_OBJECT     *RegionObj,
667     BOOLEAN                 AcpiNsLocked)
668 {
669     ACPI_OPERAND_OBJECT     *HandlerObj;
670     ACPI_OPERAND_OBJECT     *ObjDesc;
671     ACPI_ADR_SPACE_TYPE     SpaceId;
672     ACPI_NAMESPACE_NODE     *Node;
673     ACPI_STATUS             Status;
674     ACPI_NAMESPACE_NODE     *MethodNode;
675     ACPI_NAME               *RegNamePtr = (ACPI_NAME *) METHOD_NAME__REG;
676     ACPI_OPERAND_OBJECT     *RegionObj2;
677
678
679     ACPI_FUNCTION_TRACE_U32 (EvInitializeRegion, AcpiNsLocked);
680
681
682     if (!RegionObj)
683     {
684         return_ACPI_STATUS (AE_BAD_PARAMETER);
685     }
686
687     if (RegionObj->Common.Flags & AOPOBJ_OBJECT_INITIALIZED)
688     {
689         return_ACPI_STATUS (AE_OK);
690     }
691
692     RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
693     if (!RegionObj2)
694     {
695         return_ACPI_STATUS (AE_NOT_EXIST);
696     }
697
698     Node = AcpiNsGetParentNode (RegionObj->Region.Node);
699     SpaceId = RegionObj->Region.SpaceId;
700
701     /* Setup defaults */
702
703     RegionObj->Region.Handler = NULL;
704     RegionObj2->Extra.Method_REG = NULL;
705     RegionObj->Common.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
706     RegionObj->Common.Flags |= AOPOBJ_OBJECT_INITIALIZED;
707
708     /* Find any "_REG" method associated with this region definition */
709
710     Status = AcpiNsSearchOneScope (
711                 *RegNamePtr, Node, ACPI_TYPE_METHOD, &MethodNode);
712     if (ACPI_SUCCESS (Status))
713     {
714         /*
715          * The _REG method is optional and there can be only one per region
716          * definition.  This will be executed when the handler is attached
717          * or removed
718          */
719         RegionObj2->Extra.Method_REG = MethodNode;
720     }
721
722     /*
723      * The following loop depends upon the root Node having no parent
724      * ie: AcpiGbl_RootNode->ParentEntry being set to NULL
725      */
726     while (Node)
727     {
728         /* Check to see if a handler exists */
729
730         HandlerObj = NULL;
731         ObjDesc = AcpiNsGetAttachedObject (Node);
732         if (ObjDesc)
733         {
734             /* Can only be a handler if the object exists */
735
736             switch (Node->Type)
737             {
738             case ACPI_TYPE_DEVICE:
739
740                 HandlerObj = ObjDesc->Device.Handler;
741                 break;
742
743             case ACPI_TYPE_PROCESSOR:
744
745                 HandlerObj = ObjDesc->Processor.Handler;
746                 break;
747
748             case ACPI_TYPE_THERMAL:
749
750                 HandlerObj = ObjDesc->ThermalZone.Handler;
751                 break;
752
753             default:
754                 /* Ignore other objects */
755                 break;
756             }
757
758             while (HandlerObj)
759             {
760                 /* Is this handler of the correct type? */
761
762                 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
763                 {
764                     /* Found correct handler */
765
766                     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
767                         "Found handler %p for region %p in obj %p\n",
768                         HandlerObj, RegionObj, ObjDesc));
769
770                     Status = AcpiEvAttachRegion (HandlerObj, RegionObj,
771                                 AcpiNsLocked);
772
773                     /*
774                      * Tell all users that this region is usable by running the _REG
775                      * method
776                      */
777                     if (AcpiNsLocked)
778                     {
779                         Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
780                         if (ACPI_FAILURE (Status))
781                         {
782                             return_ACPI_STATUS (Status);
783                         }
784                     }
785
786                     Status = AcpiEvExecuteRegMethod (RegionObj, 1);
787
788                     if (AcpiNsLocked)
789                     {
790                         Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
791                         if (ACPI_FAILURE (Status))
792                         {
793                             return_ACPI_STATUS (Status);
794                         }
795                     }
796
797                     return_ACPI_STATUS (AE_OK);
798                 }
799
800                 /* Try next handler in the list */
801
802                 HandlerObj = HandlerObj->AddressSpace.Next;
803             }
804         }
805
806         /*
807          * This node does not have the handler we need;
808          * Pop up one level
809          */
810         Node = AcpiNsGetParentNode (Node);
811     }
812
813     /* If we get here, there is no handler for this region */
814
815     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
816         "No handler for RegionType %s(%X) (RegionObj %p)\n",
817         AcpiUtGetRegionName (SpaceId), SpaceId, RegionObj));
818
819     return_ACPI_STATUS (AE_NOT_EXIST);
820 }
821