xref: /illumos-gate/usr/src/common/acpica/events/evhandler.c (revision 8459c777fc1aaabb2f7dad05de1313aa169417cd)
1 /******************************************************************************
2  *
3  * Module Name: evhandler - Support for Address Space handlers
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
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.
20  *
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
27  *
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;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
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.
53  *
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.
65  *
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.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
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.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
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.
89  *
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.
98  *
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.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acevents.h"
155 #include "acnamesp.h"
156 #include "acinterp.h"
157 
158 #define _COMPONENT          ACPI_EVENTS
159         ACPI_MODULE_NAME    ("evhandler")
160 
161 
162 /* Local prototypes */
163 
164 static ACPI_STATUS
165 AcpiEvInstallHandler (
166     ACPI_HANDLE             ObjHandle,
167     UINT32                  Level,
168     void                    *Context,
169     void                    **ReturnValue);
170 
171 
172 /* These are the address spaces that will get default handlers */
173 
174 UINT8        AcpiGbl_DefaultAddressSpaces[ACPI_NUM_DEFAULT_SPACES] =
175 {
176     ACPI_ADR_SPACE_SYSTEM_MEMORY,
177     ACPI_ADR_SPACE_SYSTEM_IO,
178     ACPI_ADR_SPACE_PCI_CONFIG,
179     ACPI_ADR_SPACE_DATA_TABLE
180 };
181 
182 
183 /*******************************************************************************
184  *
185  * FUNCTION:    AcpiEvInstallRegionHandlers
186  *
187  * PARAMETERS:  None
188  *
189  * RETURN:      Status
190  *
191  * DESCRIPTION: Installs the core subsystem default address space handlers.
192  *
193  ******************************************************************************/
194 
195 ACPI_STATUS
196 AcpiEvInstallRegionHandlers (
197     void)
198 {
199     ACPI_STATUS             Status;
200     UINT32                  i;
201 
202 
203     ACPI_FUNCTION_TRACE (EvInstallRegionHandlers);
204 
205 
206     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
207     if (ACPI_FAILURE (Status))
208     {
209         return_ACPI_STATUS (Status);
210     }
211 
212     /*
213      * All address spaces (PCI Config, EC, SMBus) are scope dependent and
214      * registration must occur for a specific device.
215      *
216      * In the case of the system memory and IO address spaces there is
217      * currently no device associated with the address space. For these we
218      * use the root.
219      *
220      * We install the default PCI config space handler at the root so that
221      * this space is immediately available even though the we have not
222      * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
223      * specification which states that the PCI config space must be always
224      * available -- even though we are nowhere near ready to find the PCI root
225      * buses at this point.
226      *
227      * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
228      * has already been installed (via AcpiInstallAddressSpaceHandler).
229      * Similar for AE_SAME_HANDLER.
230      */
231     for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
232     {
233         Status = AcpiEvInstallSpaceHandler (AcpiGbl_RootNode,
234             AcpiGbl_DefaultAddressSpaces[i],
235             ACPI_DEFAULT_HANDLER, NULL, NULL);
236         switch (Status)
237         {
238         case AE_OK:
239         case AE_SAME_HANDLER:
240         case AE_ALREADY_EXISTS:
241 
242             /* These exceptions are all OK */
243 
244             Status = AE_OK;
245             break;
246 
247         default:
248 
249             goto UnlockAndExit;
250         }
251     }
252 
253 UnlockAndExit:
254     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
255     return_ACPI_STATUS (Status);
256 }
257 
258 
259 /*******************************************************************************
260  *
261  * FUNCTION:    AcpiEvHasDefaultHandler
262  *
263  * PARAMETERS:  Node                - Namespace node for the device
264  *              SpaceId             - The address space ID
265  *
266  * RETURN:      TRUE if default handler is installed, FALSE otherwise
267  *
268  * DESCRIPTION: Check if the default handler is installed for the requested
269  *              space ID.
270  *
271  ******************************************************************************/
272 
273 BOOLEAN
274 AcpiEvHasDefaultHandler (
275     ACPI_NAMESPACE_NODE     *Node,
276     ACPI_ADR_SPACE_TYPE     SpaceId)
277 {
278     ACPI_OPERAND_OBJECT     *ObjDesc;
279     ACPI_OPERAND_OBJECT     *HandlerObj;
280 
281 
282     /* Must have an existing internal object */
283 
284     ObjDesc = AcpiNsGetAttachedObject (Node);
285     if (ObjDesc)
286     {
287         HandlerObj = ObjDesc->CommonNotify.Handler;
288 
289         /* Walk the linked list of handlers for this object */
290 
291         while (HandlerObj)
292         {
293             if (HandlerObj->AddressSpace.SpaceId == SpaceId)
294             {
295                 if (HandlerObj->AddressSpace.HandlerFlags &
296                     ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
297                 {
298                     return (TRUE);
299                 }
300             }
301 
302             HandlerObj = HandlerObj->AddressSpace.Next;
303         }
304     }
305 
306     return (FALSE);
307 }
308 
309 
310 /*******************************************************************************
311  *
312  * FUNCTION:    AcpiEvInstallHandler
313  *
314  * PARAMETERS:  WalkNamespace callback
315  *
316  * DESCRIPTION: This routine installs an address handler into objects that are
317  *              of type Region or Device.
318  *
319  *              If the Object is a Device, and the device has a handler of
320  *              the same type then the search is terminated in that branch.
321  *
322  *              This is because the existing handler is closer in proximity
323  *              to any more regions than the one we are trying to install.
324  *
325  ******************************************************************************/
326 
327 static ACPI_STATUS
328 AcpiEvInstallHandler (
329     ACPI_HANDLE             ObjHandle,
330     UINT32                  Level,
331     void                    *Context,
332     void                    **ReturnValue)
333 {
334     ACPI_OPERAND_OBJECT     *HandlerObj;
335     ACPI_OPERAND_OBJECT     *NextHandlerObj;
336     ACPI_OPERAND_OBJECT     *ObjDesc;
337     ACPI_NAMESPACE_NODE     *Node;
338     ACPI_STATUS             Status;
339 
340 
341     ACPI_FUNCTION_NAME (EvInstallHandler);
342 
343 
344     HandlerObj = (ACPI_OPERAND_OBJECT  *) Context;
345 
346     /* Parameter validation */
347 
348     if (!HandlerObj)
349     {
350         return (AE_OK);
351     }
352 
353     /* Convert and validate the device handle */
354 
355     Node = AcpiNsValidateHandle (ObjHandle);
356     if (!Node)
357     {
358         return (AE_BAD_PARAMETER);
359     }
360 
361     /*
362      * We only care about regions and objects that are allowed to have
363      * address space handlers
364      */
365     if ((Node->Type != ACPI_TYPE_DEVICE) &&
366         (Node->Type != ACPI_TYPE_REGION) &&
367         (Node != AcpiGbl_RootNode))
368     {
369         return (AE_OK);
370     }
371 
372     /* Check for an existing internal object */
373 
374     ObjDesc = AcpiNsGetAttachedObject (Node);
375     if (!ObjDesc)
376     {
377         /* No object, just exit */
378 
379         return (AE_OK);
380     }
381 
382     /* Devices are handled different than regions */
383 
384     if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
385     {
386         /* Check if this Device already has a handler for this address space */
387 
388         NextHandlerObj = AcpiEvFindRegionHandler (
389             HandlerObj->AddressSpace.SpaceId, ObjDesc->CommonNotify.Handler);
390         if (NextHandlerObj)
391         {
392             /* Found a handler, is it for the same address space? */
393 
394             ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
395                 "Found handler for region [%s] in device %p(%p) handler %p\n",
396                 AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
397                 ObjDesc, NextHandlerObj, HandlerObj));
398 
399             /*
400              * Since the object we found it on was a device, then it means
401              * that someone has already installed a handler for the branch
402              * of the namespace from this device on. Just bail out telling
403              * the walk routine to not traverse this branch. This preserves
404              * the scoping rule for handlers.
405              */
406             return (AE_CTRL_DEPTH);
407         }
408 
409         /*
410          * As long as the device didn't have a handler for this space we
411          * don't care about it. We just ignore it and proceed.
412          */
413         return (AE_OK);
414     }
415 
416     /* Object is a Region */
417 
418     if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
419     {
420         /* This region is for a different address space, just ignore it */
421 
422         return (AE_OK);
423     }
424 
425     /*
426      * Now we have a region and it is for the handler's address space type.
427      *
428      * First disconnect region for any previous handler (if any)
429      */
430     AcpiEvDetachRegion (ObjDesc, FALSE);
431 
432     /* Connect the region to the new handler */
433 
434     Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
435     return (Status);
436 }
437 
438 
439 /*******************************************************************************
440  *
441  * FUNCTION:    AcpiEvFindRegionHandler
442  *
443  * PARAMETERS:  SpaceId         - The address space ID
444  *              HandlerObj      - Head of the handler object list
445  *
446  * RETURN:      Matching handler object. NULL if space ID not matched
447  *
448  * DESCRIPTION: Search a handler object list for a match on the address
449  *              space ID.
450  *
451  ******************************************************************************/
452 
453 ACPI_OPERAND_OBJECT *
454 AcpiEvFindRegionHandler (
455     ACPI_ADR_SPACE_TYPE     SpaceId,
456     ACPI_OPERAND_OBJECT     *HandlerObj)
457 {
458 
459     /* Walk the handler list for this device */
460 
461     while (HandlerObj)
462     {
463         /* Same SpaceId indicates a handler is installed */
464 
465         if (HandlerObj->AddressSpace.SpaceId == SpaceId)
466         {
467             return (HandlerObj);
468         }
469 
470         /* Next handler object */
471 
472         HandlerObj = HandlerObj->AddressSpace.Next;
473     }
474 
475     return (NULL);
476 }
477 
478 
479 /*******************************************************************************
480  *
481  * FUNCTION:    AcpiEvInstallSpaceHandler
482  *
483  * PARAMETERS:  Node            - Namespace node for the device
484  *              SpaceId         - The address space ID
485  *              Handler         - Address of the handler
486  *              Setup           - Address of the setup function
487  *              Context         - Value passed to the handler on each access
488  *
489  * RETURN:      Status
490  *
491  * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
492  *              Assumes namespace is locked
493  *
494  ******************************************************************************/
495 
496 ACPI_STATUS
497 AcpiEvInstallSpaceHandler (
498     ACPI_NAMESPACE_NODE     *Node,
499     ACPI_ADR_SPACE_TYPE     SpaceId,
500     ACPI_ADR_SPACE_HANDLER  Handler,
501     ACPI_ADR_SPACE_SETUP    Setup,
502     void                    *Context)
503 {
504     ACPI_OPERAND_OBJECT     *ObjDesc;
505     ACPI_OPERAND_OBJECT     *HandlerObj;
506     ACPI_STATUS             Status = AE_OK;
507     ACPI_OBJECT_TYPE        Type;
508     UINT8                   Flags = 0;
509 
510 
511     ACPI_FUNCTION_TRACE (EvInstallSpaceHandler);
512 
513 
514     /*
515      * This registration is valid for only the types below and the root.
516      * The root node is where the default handlers get installed.
517      */
518     if ((Node->Type != ACPI_TYPE_DEVICE)     &&
519         (Node->Type != ACPI_TYPE_PROCESSOR)  &&
520         (Node->Type != ACPI_TYPE_THERMAL)    &&
521         (Node != AcpiGbl_RootNode))
522     {
523         Status = AE_BAD_PARAMETER;
524         goto UnlockAndExit;
525     }
526 
527     if (Handler == ACPI_DEFAULT_HANDLER)
528     {
529         Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
530 
531         switch (SpaceId)
532         {
533         case ACPI_ADR_SPACE_SYSTEM_MEMORY:
534 
535             Handler = AcpiExSystemMemorySpaceHandler;
536             Setup   = AcpiEvSystemMemoryRegionSetup;
537             break;
538 
539         case ACPI_ADR_SPACE_SYSTEM_IO:
540 
541             Handler = AcpiExSystemIoSpaceHandler;
542             Setup   = AcpiEvIoSpaceRegionSetup;
543             break;
544 
545         case ACPI_ADR_SPACE_PCI_CONFIG:
546 
547             Handler = AcpiExPciConfigSpaceHandler;
548             Setup   = AcpiEvPciConfigRegionSetup;
549             break;
550 
551         case ACPI_ADR_SPACE_CMOS:
552 
553             Handler = AcpiExCmosSpaceHandler;
554             Setup   = AcpiEvCmosRegionSetup;
555             break;
556 
557         case ACPI_ADR_SPACE_PCI_BAR_TARGET:
558 
559             Handler = AcpiExPciBarSpaceHandler;
560             Setup   = AcpiEvPciBarRegionSetup;
561             break;
562 
563         case ACPI_ADR_SPACE_DATA_TABLE:
564 
565             Handler = AcpiExDataTableSpaceHandler;
566             Setup   = NULL;
567             break;
568 
569         default:
570 
571             Status = AE_BAD_PARAMETER;
572             goto UnlockAndExit;
573         }
574     }
575 
576     /* If the caller hasn't specified a setup routine, use the default */
577 
578     if (!Setup)
579     {
580         Setup = AcpiEvDefaultRegionSetup;
581     }
582 
583     /* Check for an existing internal object */
584 
585     ObjDesc = AcpiNsGetAttachedObject (Node);
586     if (ObjDesc)
587     {
588         /*
589          * The attached device object already exists. Now make sure
590          * the handler is not already installed.
591          */
592         HandlerObj = AcpiEvFindRegionHandler (SpaceId,
593             ObjDesc->CommonNotify.Handler);
594 
595         if (HandlerObj)
596         {
597             if (HandlerObj->AddressSpace.Handler == Handler)
598             {
599                 /*
600                  * It is (relatively) OK to attempt to install the SAME
601                  * handler twice. This can easily happen with the
602                  * PCI_Config space.
603                  */
604                 Status = AE_SAME_HANDLER;
605                 goto UnlockAndExit;
606             }
607             else
608             {
609                 /* A handler is already installed */
610 
611                 Status = AE_ALREADY_EXISTS;
612             }
613 
614             goto UnlockAndExit;
615         }
616     }
617     else
618     {
619         ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
620             "Creating object on Device %p while installing handler\n",
621             Node));
622 
623         /* ObjDesc does not exist, create one */
624 
625         if (Node->Type == ACPI_TYPE_ANY)
626         {
627             Type = ACPI_TYPE_DEVICE;
628         }
629         else
630         {
631             Type = Node->Type;
632         }
633 
634         ObjDesc = AcpiUtCreateInternalObject (Type);
635         if (!ObjDesc)
636         {
637             Status = AE_NO_MEMORY;
638             goto UnlockAndExit;
639         }
640 
641         /* Init new descriptor */
642 
643         ObjDesc->Common.Type = (UINT8) Type;
644 
645         /* Attach the new object to the Node */
646 
647         Status = AcpiNsAttachObject (Node, ObjDesc, Type);
648 
649         /* Remove local reference to the object */
650 
651         AcpiUtRemoveReference (ObjDesc);
652 
653         if (ACPI_FAILURE (Status))
654         {
655             goto UnlockAndExit;
656         }
657     }
658 
659     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
660         "Installing address handler for region %s(%X) "
661         "on Device %4.4s %p(%p)\n",
662         AcpiUtGetRegionName (SpaceId), SpaceId,
663         AcpiUtGetNodeName (Node), Node, ObjDesc));
664 
665     /*
666      * Install the handler
667      *
668      * At this point there is no existing handler. Just allocate the object
669      * for the handler and link it into the list.
670      */
671     HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
672     if (!HandlerObj)
673     {
674         Status = AE_NO_MEMORY;
675         goto UnlockAndExit;
676     }
677 
678     /* Init handler obj */
679 
680     HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId;
681     HandlerObj->AddressSpace.HandlerFlags = Flags;
682     HandlerObj->AddressSpace.RegionList = NULL;
683     HandlerObj->AddressSpace.Node = Node;
684     HandlerObj->AddressSpace.Handler = Handler;
685     HandlerObj->AddressSpace.Context = Context;
686     HandlerObj->AddressSpace.Setup = Setup;
687 
688     /* Install at head of Device.AddressSpace list */
689 
690     HandlerObj->AddressSpace.Next = ObjDesc->CommonNotify.Handler;
691 
692     /*
693      * The Device object is the first reference on the HandlerObj.
694      * Each region that uses the handler adds a reference.
695      */
696     ObjDesc->CommonNotify.Handler = HandlerObj;
697 
698     /*
699      * Walk the namespace finding all of the regions this handler will
700      * manage.
701      *
702      * Start at the device and search the branch toward the leaf nodes
703      * until either the leaf is encountered or a device is detected that
704      * has an address handler of the same type.
705      *
706      * In either case, back up and search down the remainder of the branch
707      */
708     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node,
709         ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
710         AcpiEvInstallHandler, NULL, HandlerObj, NULL);
711 
712 UnlockAndExit:
713     return_ACPI_STATUS (Status);
714 }
715