Misc cleanups to take care of GCC3.x warnings. Missing 'U' and 'LL'
[dragonfly.git] / sys / contrib / dev / acpica / evregion.c
1 /******************************************************************************
2  *
3  * Module Name: evregion - ACPI AddressSpace (OpRegion) handler dispatch
4  *              $Revision: 137 $
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2003, 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 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/evregion.c,v 1.1 2003/09/24 03:32:15 drhodus Exp $                                                               */
117
118
119 #define __EVREGION_C__
120
121 #include "acpi.h"
122 #include "acevents.h"
123 #include "acnamesp.h"
124 #include "acinterp.h"
125
126 #define _COMPONENT          ACPI_EVENTS
127         ACPI_MODULE_NAME    ("evregion")
128
129
130 /*******************************************************************************
131  *
132  * FUNCTION:    AcpiEvInitAddressSpaces
133  *
134  * PARAMETERS:
135  *
136  * RETURN:      Status
137  *
138  * DESCRIPTION: Installs the core subsystem address space handlers.
139  *
140  ******************************************************************************/
141
142 ACPI_STATUS
143 AcpiEvInitAddressSpaces (
144     void)
145 {
146     ACPI_STATUS             Status;
147
148
149     ACPI_FUNCTION_TRACE ("EvInitAddressSpaces");
150
151
152     /*
153      * All address spaces (PCI Config, EC, SMBus) are scope dependent
154      * and registration must occur for a specific device.  In the case
155      * system memory and IO address spaces there is currently no device
156      * associated with the address space.  For these we use the root.
157      * We install the default PCI config space handler at the root so
158      * that this space is immediately available even though the we have
159      * not enumerated all the PCI Root Buses yet.  This is to conform
160      * to the ACPI specification which states that the PCI config
161      * space must be always available -- even though we are nowhere
162      * near ready to find the PCI root buses at this point.
163      *
164      * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
165      * has already been installed (via AcpiInstallAddressSpaceHandler)
166      */
167
168     Status = AcpiInstallAddressSpaceHandler ((ACPI_HANDLE) AcpiGbl_RootNode,
169                                              ACPI_ADR_SPACE_SYSTEM_MEMORY,
170                                              ACPI_DEFAULT_HANDLER, NULL, NULL);
171     if ((ACPI_FAILURE (Status)) &&
172         (Status != AE_ALREADY_EXISTS))
173     {
174         return_ACPI_STATUS (Status);
175     }
176
177     Status = AcpiInstallAddressSpaceHandler ((ACPI_HANDLE) AcpiGbl_RootNode,
178                                              ACPI_ADR_SPACE_SYSTEM_IO,
179                                              ACPI_DEFAULT_HANDLER, NULL, NULL);
180     if ((ACPI_FAILURE (Status)) &&
181         (Status != AE_ALREADY_EXISTS))
182     {
183         return_ACPI_STATUS (Status);
184     }
185
186     Status = AcpiInstallAddressSpaceHandler ((ACPI_HANDLE) AcpiGbl_RootNode,
187                                              ACPI_ADR_SPACE_PCI_CONFIG,
188                                              ACPI_DEFAULT_HANDLER, NULL, NULL);
189     if ((ACPI_FAILURE (Status)) &&
190         (Status != AE_ALREADY_EXISTS))
191     {
192         return_ACPI_STATUS (Status);
193     }
194
195     Status = AcpiInstallAddressSpaceHandler ((ACPI_HANDLE) AcpiGbl_RootNode,
196                                              ACPI_ADR_SPACE_DATA_TABLE,
197                                              ACPI_DEFAULT_HANDLER, NULL, NULL);
198     if ((ACPI_FAILURE (Status)) &&
199         (Status != AE_ALREADY_EXISTS))
200     {
201         return_ACPI_STATUS (Status);
202     }
203
204     return_ACPI_STATUS (AE_OK);
205 }
206
207
208 /*******************************************************************************
209  *
210  * FUNCTION:    AcpiEvExecuteRegMethod
211  *
212  * PARAMETERS:  RegionObj           - Object structure
213  *              Function            - On (1) or Off (0)
214  *
215  * RETURN:      Status
216  *
217  * DESCRIPTION: Execute _REG method for a region
218  *
219  ******************************************************************************/
220
221 static ACPI_STATUS
222 AcpiEvExecuteRegMethod (
223     ACPI_OPERAND_OBJECT    *RegionObj,
224     UINT32                  Function)
225 {
226     ACPI_OPERAND_OBJECT    *Params[3];
227     ACPI_OPERAND_OBJECT    *RegionObj2;
228     ACPI_STATUS             Status;
229
230
231     ACPI_FUNCTION_TRACE ("EvExecuteRegMethod");
232
233
234     RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
235     if (!RegionObj2)
236     {
237         return_ACPI_STATUS (AE_NOT_EXIST);
238     }
239
240     if (RegionObj2->Extra.Method_REG == NULL)
241     {
242         return_ACPI_STATUS (AE_OK);
243     }
244
245     /*
246      *  _REG method has two arguments
247      *  Arg0:   Integer: Operation region space ID
248      *          Same value as RegionObj->Region.SpaceId
249      *  Arg1:   Integer: connection status
250      *          1 for connecting the handler,
251      *          0 for disconnecting the handler
252      *          Passed as a parameter
253      */
254     Params[0] = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
255     if (!Params[0])
256     {
257         return_ACPI_STATUS (AE_NO_MEMORY);
258     }
259
260     Params[1] = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
261     if (!Params[1])
262     {
263         Status = AE_NO_MEMORY;
264         goto Cleanup;
265     }
266
267     /*
268      *  Set up the parameter objects
269      */
270     Params[0]->Integer.Value = RegionObj->Region.SpaceId;
271     Params[1]->Integer.Value = Function;
272     Params[2] = NULL;
273
274     /*
275      *  Execute the method, no return value
276      */
277     ACPI_DEBUG_EXEC(AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, RegionObj2->Extra.Method_REG, NULL));
278     Status = AcpiNsEvaluateByHandle (RegionObj2->Extra.Method_REG, Params, NULL);
279
280     AcpiUtRemoveReference (Params[1]);
281
282 Cleanup:
283     AcpiUtRemoveReference (Params[0]);
284
285     return_ACPI_STATUS (Status);
286 }
287
288
289 /*******************************************************************************
290  *
291  * FUNCTION:    AcpiEvAddressSpaceDispatch
292  *
293  * PARAMETERS:  RegionObj           - internal region object
294  *              SpaceId             - ID of the address space (0-255)
295  *              Function            - Read or Write operation
296  *              Address             - Where in the space to read or write
297  *              BitWidth            - Field width in bits (8, 16, 32, or 64)
298  *              Value               - Pointer to in or out value
299  *
300  * RETURN:      Status
301  *
302  * DESCRIPTION: Dispatch an address space or operation region access to
303  *              a previously installed handler.
304  *
305  ******************************************************************************/
306
307 ACPI_STATUS
308 AcpiEvAddressSpaceDispatch (
309     ACPI_OPERAND_OBJECT     *RegionObj,
310     UINT32                  Function,
311     ACPI_PHYSICAL_ADDRESS   Address,
312     UINT32                  BitWidth,
313     void                    *Value)
314 {
315     ACPI_STATUS             Status;
316     ACPI_STATUS             Status2;
317     ACPI_ADR_SPACE_HANDLER  Handler;
318     ACPI_ADR_SPACE_SETUP    RegionSetup;
319     ACPI_OPERAND_OBJECT     *HandlerDesc;
320     ACPI_OPERAND_OBJECT     *RegionObj2;
321     void                    *RegionContext = NULL;
322
323
324     ACPI_FUNCTION_TRACE ("EvAddressSpaceDispatch");
325
326
327     RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
328     if (!RegionObj2)
329     {
330         return_ACPI_STATUS (AE_NOT_EXIST);
331     }
332
333     /*
334      * Ensure that there is a handler associated with this region
335      */
336     HandlerDesc = RegionObj->Region.AddrHandler;
337     if (!HandlerDesc)
338     {
339         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "no handler for region(%p) [%s]\n",
340             RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
341
342         return_ACPI_STATUS (AE_NOT_EXIST);
343     }
344
345     /*
346      * It may be the case that the region has never been initialized
347      * Some types of regions require special init code
348      */
349     if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
350     {
351         /*
352          * This region has not been initialized yet, do it
353          */
354         RegionSetup = HandlerDesc->AddrHandler.Setup;
355         if (!RegionSetup)
356         {
357             /*
358              *  Bad news, no init routine and not init'd
359              */
360             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No init routine for region(%p) [%s]\n",
361                 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
362             return_ACPI_STATUS (AE_UNKNOWN_STATUS);
363         }
364
365         /*
366          * We must exit the interpreter because the region setup will potentially
367          * execute control methods
368          */
369         AcpiExExitInterpreter ();
370
371         Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
372                         HandlerDesc->AddrHandler.Context, &RegionContext);
373
374         /* Re-enter the interpreter */
375
376         Status2 = AcpiExEnterInterpreter ();
377         if (ACPI_FAILURE (Status2))
378         {
379             return_ACPI_STATUS (Status2);
380         }
381
382         /*
383          *  Init routine may fail
384          */
385         if (ACPI_FAILURE (Status))
386         {
387             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Region Init: %s [%s]\n",
388                 AcpiFormatException (Status),
389                 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
390             return_ACPI_STATUS (Status);
391         }
392
393         RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
394
395         /*
396          *  Save the returned context for use in all accesses to
397          *  this particular region.
398          */
399         RegionObj2->Extra.RegionContext = RegionContext;
400     }
401
402     /*
403      *  We have everything we need, begin the process
404      */
405     Handler = HandlerDesc->AddrHandler.Handler;
406
407     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
408         "Addrhandler %p (%p), Address %8.8X%8.8X\n",
409         &RegionObj->Region.AddrHandler->AddrHandler, Handler,
410         ACPI_HIDWORD (Address), ACPI_LODWORD (Address)));
411
412     if (!(HandlerDesc->AddrHandler.Flags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
413     {
414         /*
415          *  For handlers other than the default (supplied) handlers, we must
416          *  exit the interpreter because the handler *might* block -- we don't
417          *  know what it will do, so we can't hold the lock on the intepreter.
418          */
419         AcpiExExitInterpreter();
420     }
421
422     /*
423      *  Invoke the handler.
424      */
425     Status = Handler (Function, Address, BitWidth, Value,
426                       HandlerDesc->AddrHandler.Context,
427                       RegionObj2->Extra.RegionContext);
428
429     if (ACPI_FAILURE (Status))
430     {
431         ACPI_REPORT_ERROR (("Handler for [%s] returned %s\n",
432             AcpiUtGetRegionName (RegionObj->Region.SpaceId),
433             AcpiFormatException (Status)));
434     }
435
436     if (!(HandlerDesc->AddrHandler.Flags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
437     {
438         /*
439          * We just returned from a non-default handler, we must re-enter the
440          * interpreter
441          */
442         Status2 = AcpiExEnterInterpreter ();
443         if (ACPI_FAILURE (Status2))
444         {
445             return_ACPI_STATUS (Status2);
446         }
447     }
448
449     return_ACPI_STATUS (Status);
450 }
451
452 /*******************************************************************************
453  *
454  * FUNCTION:    AcpiEvDetachRegion
455  *
456  * PARAMETERS:  RegionObj       - Region Object
457  *              AcpiNsIsLocked  - Namespace Region Already Locked?
458  *
459  * RETURN:      None
460  *
461  * DESCRIPTION: Break the association between the handler and the region
462  *              this is a two way association.
463  *
464  ******************************************************************************/
465
466 void
467 AcpiEvDetachRegion(
468     ACPI_OPERAND_OBJECT     *RegionObj,
469     BOOLEAN                 AcpiNsIsLocked)
470 {
471     ACPI_OPERAND_OBJECT     *HandlerObj;
472     ACPI_OPERAND_OBJECT     *ObjDesc;
473     ACPI_OPERAND_OBJECT     **LastObjPtr;
474     ACPI_ADR_SPACE_SETUP    RegionSetup;
475     void                    *RegionContext;
476     ACPI_OPERAND_OBJECT     *RegionObj2;
477     ACPI_STATUS             Status;
478
479
480     ACPI_FUNCTION_TRACE ("EvDetachRegion");
481
482
483     RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
484     if (!RegionObj2)
485     {
486         return_VOID;
487     }
488     RegionContext = RegionObj2->Extra.RegionContext;
489
490     /*
491      *  Get the address handler from the region object
492      */
493     HandlerObj = RegionObj->Region.AddrHandler;
494     if (!HandlerObj)
495     {
496         /*
497          *  This region has no handler, all done
498          */
499         return_VOID;
500     }
501
502
503     /*
504      *  Find this region in the handler's list
505      */
506     ObjDesc = HandlerObj->AddrHandler.RegionList;
507     LastObjPtr = &HandlerObj->AddrHandler.RegionList;
508
509     while (ObjDesc)
510     {
511         /*
512          *  See if this is the one
513          */
514         if (ObjDesc == RegionObj)
515         {
516             ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
517                 "Removing Region %p from address handler %p\n",
518                 RegionObj, HandlerObj));
519             /*
520              *  This is it, remove it from the handler's list
521              */
522             *LastObjPtr = ObjDesc->Region.Next;
523             ObjDesc->Region.Next = NULL;            /* Must clear field */
524
525             if (AcpiNsIsLocked)
526             {
527                 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
528                 if (ACPI_FAILURE (Status))
529                 {
530                     return_VOID;
531                 }
532             }
533
534             /*
535              *  Now stop region accesses by executing the _REG method
536              */
537             Status = AcpiEvExecuteRegMethod (RegionObj, 0);
538             if (ACPI_FAILURE (Status))
539             {
540                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s from region _REG, [%s]\n",
541                     AcpiFormatException (Status),
542                     AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
543             }
544
545             if (AcpiNsIsLocked)
546             {
547                 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
548                 if (ACPI_FAILURE (Status))
549                 {
550                     return_VOID;
551                 }
552             }
553
554             /*
555              *  Call the setup handler with the deactivate notification
556              */
557             RegionSetup = HandlerObj->AddrHandler.Setup;
558             Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
559                             HandlerObj->AddrHandler.Context, &RegionContext);
560
561             /*
562              *  Init routine may fail, Just ignore errors
563              */
564             if (ACPI_FAILURE (Status))
565             {
566                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s from region init, [%s]\n",
567                     AcpiFormatException (Status),
568                     AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
569             }
570
571             RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
572
573             /*
574              *  Remove handler reference in the region
575              *
576              *  NOTE: this doesn't mean that the region goes away
577              *  The region is just inaccessible as indicated to
578              *  the _REG method
579              *
580              *  If the region is on the handler's list
581              *  this better be the region's handler
582              */
583             RegionObj->Region.AddrHandler = NULL;
584
585             return_VOID;
586
587         } /* found the right handler */
588
589         /*
590          *  Move through the linked list of handlers
591          */
592         LastObjPtr = &ObjDesc->Region.Next;
593         ObjDesc = ObjDesc->Region.Next;
594     }
595
596     /*
597      *  If we get here, the region was not in the handler's region list
598      */
599     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
600         "Cannot remove region %p from address handler %p\n",
601         RegionObj, HandlerObj));
602
603     return_VOID;
604 }
605
606
607 /*******************************************************************************
608  *
609  * FUNCTION:    AcpiEvAttachRegion
610  *
611  * PARAMETERS:  HandlerObj      - Handler Object
612  *              RegionObj       - Region Object
613  *              AcpiNsIsLocked  - Namespace Region Already Locked?
614  *
615  * RETURN:      None
616  *
617  * DESCRIPTION: Create the association between the handler and the region
618  *              this is a two way association.
619  *
620  ******************************************************************************/
621
622 ACPI_STATUS
623 AcpiEvAttachRegion (
624     ACPI_OPERAND_OBJECT     *HandlerObj,
625     ACPI_OPERAND_OBJECT     *RegionObj,
626     BOOLEAN                 AcpiNsIsLocked)
627 {
628     ACPI_STATUS             Status;
629     ACPI_STATUS             Status2;
630
631
632     ACPI_FUNCTION_TRACE ("EvAttachRegion");
633
634
635     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
636         "Adding Region %p to address handler %p [%s]\n",
637         RegionObj, HandlerObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
638
639
640     /*
641      * Link this region to the front of the handler's list
642      */
643     RegionObj->Region.Next = HandlerObj->AddrHandler.RegionList;
644     HandlerObj->AddrHandler.RegionList = RegionObj;
645
646     /*
647      * Set the region's handler
648      */
649     RegionObj->Region.AddrHandler = HandlerObj;
650
651     /*
652      * Tell all users that this region is usable by running the _REG
653      * method
654      */
655     if (AcpiNsIsLocked)
656     {
657         Status2 = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
658         if (ACPI_FAILURE (Status2))
659         {
660             return_ACPI_STATUS (Status2);
661         }
662     }
663
664     Status = AcpiEvExecuteRegMethod (RegionObj, 1);
665
666     if (AcpiNsIsLocked)
667     {
668         Status2 = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
669         if (ACPI_FAILURE (Status2))
670         {
671             return_ACPI_STATUS (Status2);
672         }
673     }
674
675     return_ACPI_STATUS (Status);
676 }
677
678
679 /*******************************************************************************
680  *
681  * FUNCTION:    AcpiEvAddrHandlerHelper
682  *
683  * PARAMETERS:  Handle              - Node to be dumped
684  *              Level               - Nesting level of the handle
685  *              Context             - Passed into AcpiNsWalkNamespace
686  *
687  * DESCRIPTION: This routine installs an address handler into objects that are
688  *              of type Region.
689  *
690  *              If the Object is a Device, and the device has a handler of
691  *              the same type then the search is terminated in that branch.
692  *
693  *              This is because the existing handler is closer in proximity
694  *              to any more regions than the one we are trying to install.
695  *
696  ******************************************************************************/
697
698 ACPI_STATUS
699 AcpiEvAddrHandlerHelper (
700     ACPI_HANDLE             ObjHandle,
701     UINT32                  Level,
702     void                    *Context,
703     void                    **ReturnValue)
704 {
705     ACPI_OPERAND_OBJECT     *HandlerObj;
706     ACPI_OPERAND_OBJECT     *TmpObj;
707     ACPI_OPERAND_OBJECT     *ObjDesc;
708     ACPI_NAMESPACE_NODE     *Node;
709     ACPI_STATUS             Status;
710
711
712     ACPI_FUNCTION_NAME ("EvAddrHandlerHelper");
713
714
715     HandlerObj = (ACPI_OPERAND_OBJECT  *) Context;
716
717     /* Parameter validation */
718
719     if (!HandlerObj)
720     {
721         return (AE_OK);
722     }
723
724     /* Convert and validate the device handle */
725
726     Node = AcpiNsMapHandleToNode (ObjHandle);
727     if (!Node)
728     {
729         return (AE_BAD_PARAMETER);
730     }
731
732     /*
733      *  We only care about regions.and objects
734      *  that can have address handlers
735      */
736     if ((Node->Type != ACPI_TYPE_DEVICE) &&
737         (Node->Type != ACPI_TYPE_REGION) &&
738         (Node != AcpiGbl_RootNode))
739     {
740         return (AE_OK);
741     }
742
743     /* Check for an existing internal object */
744
745     ObjDesc = AcpiNsGetAttachedObject (Node);
746     if (!ObjDesc)
747     {
748         /*
749          *  The object DNE, we don't care about it
750          */
751         return (AE_OK);
752     }
753
754     /*
755      *  Devices are handled different than regions
756      */
757     if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_DEVICE)
758     {
759         /*
760          *  See if this guy has any handlers
761          */
762         TmpObj = ObjDesc->Device.AddrHandler;
763         while (TmpObj)
764         {
765             /*
766              *  Now let's see if it's for the same address space.
767              */
768             if (TmpObj->AddrHandler.SpaceId == HandlerObj->AddrHandler.SpaceId)
769             {
770                 /*
771                  *  It's for the same address space
772                  */
773                 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
774                     "Found handler for region [%s] in device %p(%p) handler %p\n",
775                     AcpiUtGetRegionName (HandlerObj->AddrHandler.SpaceId),
776                     ObjDesc, TmpObj, HandlerObj));
777
778                 /*
779                  *  Since the object we found it on was a device, then it
780                  *  means that someone has already installed a handler for
781                  *  the branch of the namespace from this device on.  Just
782                  *  bail out telling the walk routine to not traverse this
783                  *  branch.  This preserves the scoping rule for handlers.
784                  */
785                 return (AE_CTRL_DEPTH);
786             }
787
788             /*
789              *  Move through the linked list of handlers
790              */
791             TmpObj = TmpObj->AddrHandler.Next;
792         }
793
794         /*
795          *  As long as the device didn't have a handler for this
796          *  space we don't care about it.  We just ignore it and
797          *  proceed.
798          */
799         return (AE_OK);
800     }
801
802     /*
803      *  Only here if it was a region
804      */
805     if (ObjDesc->Region.SpaceId != HandlerObj->AddrHandler.SpaceId)
806     {
807         /*
808          *  This region is for a different address space
809          *  ignore it
810          */
811         return (AE_OK);
812     }
813
814     /*
815      *  Now we have a region and it is for the handler's address
816      *  space type.
817      *
818      *  First disconnect region for any previous handler (if any)
819      */
820     AcpiEvDetachRegion (ObjDesc, FALSE);
821
822     /*
823      *  Then connect the region to the new handler
824      */
825     Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
826
827     return (Status);
828 }
829
830