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 - 2026, 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 <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acevents.h>
155 #include <contrib/dev/acpica/include/acnamesp.h>
156 #include <contrib/dev/acpica/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
AcpiEvInstallRegionHandlers(void)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
AcpiEvHasDefaultHandler(ACPI_NAMESPACE_NODE * Node,ACPI_ADR_SPACE_TYPE SpaceId)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 /* Validate handler object type before accessing fields */
294
295 if (HandlerObj->Common.Type != ACPI_TYPE_LOCAL_ADDRESS_HANDLER)
296 {
297 break;
298 }
299
300 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
301 {
302 if (HandlerObj->AddressSpace.HandlerFlags &
303 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
304 {
305 return (TRUE);
306 }
307 }
308
309 HandlerObj = HandlerObj->AddressSpace.Next;
310 }
311 }
312
313 return (FALSE);
314 }
315
316
317 /*******************************************************************************
318 *
319 * FUNCTION: AcpiEvInstallHandler
320 *
321 * PARAMETERS: WalkNamespace callback
322 *
323 * DESCRIPTION: This routine installs an address handler into objects that are
324 * of type Region or Device.
325 *
326 * If the Object is a Device, and the device has a handler of
327 * the same type then the search is terminated in that branch.
328 *
329 * This is because the existing handler is closer in proximity
330 * to any more regions than the one we are trying to install.
331 *
332 ******************************************************************************/
333
334 static ACPI_STATUS
AcpiEvInstallHandler(ACPI_HANDLE ObjHandle,UINT32 Level,void * Context,void ** ReturnValue)335 AcpiEvInstallHandler (
336 ACPI_HANDLE ObjHandle,
337 UINT32 Level,
338 void *Context,
339 void **ReturnValue)
340 {
341 ACPI_OPERAND_OBJECT *HandlerObj;
342 ACPI_OPERAND_OBJECT *NextHandlerObj;
343 ACPI_OPERAND_OBJECT *ObjDesc;
344 ACPI_NAMESPACE_NODE *Node;
345 ACPI_STATUS Status;
346
347
348 ACPI_FUNCTION_NAME (EvInstallHandler);
349
350
351 HandlerObj = (ACPI_OPERAND_OBJECT *) Context;
352
353 /* Parameter validation */
354
355 if (!HandlerObj)
356 {
357 return (AE_OK);
358 }
359
360 /* Convert and validate the device handle */
361
362 Node = AcpiNsValidateHandle (ObjHandle);
363 if (!Node)
364 {
365 return (AE_BAD_PARAMETER);
366 }
367
368 /*
369 * We only care about regions and objects that are allowed to have
370 * address space handlers
371 */
372 if ((Node->Type != ACPI_TYPE_DEVICE) &&
373 (Node->Type != ACPI_TYPE_REGION) &&
374 (Node != AcpiGbl_RootNode))
375 {
376 return (AE_OK);
377 }
378
379 /* Check for an existing internal object */
380
381 ObjDesc = AcpiNsGetAttachedObject (Node);
382 if (!ObjDesc)
383 {
384 /* No object, just exit */
385
386 return (AE_OK);
387 }
388
389 /* Devices are handled different than regions */
390
391 if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
392 {
393 /* Check if this Device already has a handler for this address space */
394
395 NextHandlerObj = AcpiEvFindRegionHandler (
396 HandlerObj->AddressSpace.SpaceId, ObjDesc->CommonNotify.Handler);
397 if (NextHandlerObj)
398 {
399 /* Found a handler, is it for the same address space? */
400
401 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
402 "Found handler for region [%s] in device %p(%p) handler %p\n",
403 AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
404 ObjDesc, NextHandlerObj, HandlerObj));
405
406 /*
407 * Since the object we found it on was a device, then it means
408 * that someone has already installed a handler for the branch
409 * of the namespace from this device on. Just bail out telling
410 * the walk routine to not traverse this branch. This preserves
411 * the scoping rule for handlers.
412 */
413 return (AE_CTRL_DEPTH);
414 }
415
416 /*
417 * As long as the device didn't have a handler for this space we
418 * don't care about it. We just ignore it and proceed.
419 */
420 return (AE_OK);
421 }
422
423 /* Object is a Region */
424
425 if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
426 {
427 /* This region is for a different address space, just ignore it */
428
429 return (AE_OK);
430 }
431
432 /*
433 * Now we have a region and it is for the handler's address space type.
434 *
435 * First disconnect region for any previous handler (if any)
436 */
437 AcpiEvDetachRegion (ObjDesc, FALSE);
438
439 /* Connect the region to the new handler */
440
441 Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
442 return (Status);
443 }
444
445
446 /*******************************************************************************
447 *
448 * FUNCTION: AcpiEvFindRegionHandler
449 *
450 * PARAMETERS: SpaceId - The address space ID
451 * HandlerObj - Head of the handler object list
452 *
453 * RETURN: Matching handler object. NULL if space ID not matched
454 *
455 * DESCRIPTION: Search a handler object list for a match on the address
456 * space ID.
457 *
458 ******************************************************************************/
459
460 ACPI_OPERAND_OBJECT *
AcpiEvFindRegionHandler(ACPI_ADR_SPACE_TYPE SpaceId,ACPI_OPERAND_OBJECT * HandlerObj)461 AcpiEvFindRegionHandler (
462 ACPI_ADR_SPACE_TYPE SpaceId,
463 ACPI_OPERAND_OBJECT *HandlerObj)
464 {
465
466 /* Walk the handler list for this device */
467
468 while (HandlerObj)
469 {
470 if (HandlerObj->Common.Type != ACPI_TYPE_LOCAL_ADDRESS_HANDLER)
471 {
472 break;
473 }
474
475 /* Same SpaceId indicates a handler is installed */
476
477 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
478 {
479 return (HandlerObj);
480 }
481
482 /* Next handler object */
483
484 HandlerObj = HandlerObj->AddressSpace.Next;
485 }
486
487 return (NULL);
488 }
489
490
491 /*******************************************************************************
492 *
493 * FUNCTION: AcpiEvInstallSpaceHandler
494 *
495 * PARAMETERS: Node - Namespace node for the device
496 * SpaceId - The address space ID
497 * Handler - Address of the handler
498 * Setup - Address of the setup function
499 * Context - Value passed to the handler on each access
500 *
501 * RETURN: Status
502 *
503 * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
504 * Assumes namespace is locked
505 *
506 ******************************************************************************/
507
508 ACPI_STATUS
AcpiEvInstallSpaceHandler(ACPI_NAMESPACE_NODE * Node,ACPI_ADR_SPACE_TYPE SpaceId,ACPI_ADR_SPACE_HANDLER Handler,ACPI_ADR_SPACE_SETUP Setup,void * Context)509 AcpiEvInstallSpaceHandler (
510 ACPI_NAMESPACE_NODE *Node,
511 ACPI_ADR_SPACE_TYPE SpaceId,
512 ACPI_ADR_SPACE_HANDLER Handler,
513 ACPI_ADR_SPACE_SETUP Setup,
514 void *Context)
515 {
516 ACPI_OPERAND_OBJECT *ObjDesc;
517 ACPI_OPERAND_OBJECT *HandlerObj;
518 ACPI_STATUS Status = AE_OK;
519 ACPI_OBJECT_TYPE Type;
520 UINT8 Flags = 0;
521
522
523 ACPI_FUNCTION_TRACE (EvInstallSpaceHandler);
524
525
526 /*
527 * This registration is valid for only the types below and the root.
528 * The root node is where the default handlers get installed.
529 */
530 if ((Node->Type != ACPI_TYPE_DEVICE) &&
531 (Node->Type != ACPI_TYPE_PROCESSOR) &&
532 (Node->Type != ACPI_TYPE_THERMAL) &&
533 (Node != AcpiGbl_RootNode))
534 {
535 Status = AE_BAD_PARAMETER;
536 goto UnlockAndExit;
537 }
538
539 if (Handler == ACPI_DEFAULT_HANDLER)
540 {
541 Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
542
543 switch (SpaceId)
544 {
545 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
546
547 Handler = AcpiExSystemMemorySpaceHandler;
548 Setup = AcpiEvSystemMemoryRegionSetup;
549 break;
550
551 case ACPI_ADR_SPACE_SYSTEM_IO:
552
553 Handler = AcpiExSystemIoSpaceHandler;
554 Setup = AcpiEvIoSpaceRegionSetup;
555 break;
556
557 case ACPI_ADR_SPACE_PCI_CONFIG:
558
559 Handler = AcpiExPciConfigSpaceHandler;
560 Setup = AcpiEvPciConfigRegionSetup;
561 break;
562
563 case ACPI_ADR_SPACE_CMOS:
564
565 Handler = AcpiExCmosSpaceHandler;
566 Setup = AcpiEvCmosRegionSetup;
567 break;
568
569 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
570
571 Handler = AcpiExPciBarSpaceHandler;
572 Setup = AcpiEvPciBarRegionSetup;
573 break;
574
575 case ACPI_ADR_SPACE_DATA_TABLE:
576
577 Handler = AcpiExDataTableSpaceHandler;
578 Setup = AcpiEvDataTableRegionSetup;
579 break;
580
581 default:
582
583 Status = AE_BAD_PARAMETER;
584 goto UnlockAndExit;
585 }
586 }
587
588 /* If the caller hasn't specified a setup routine, use the default */
589
590 if (!Setup)
591 {
592 Setup = AcpiEvDefaultRegionSetup;
593 }
594
595 /* Check for an existing internal object */
596
597 ObjDesc = AcpiNsGetAttachedObject (Node);
598 if (ObjDesc)
599 {
600 /*
601 * The attached device object already exists. Now make sure
602 * the handler is not already installed.
603 */
604 HandlerObj = AcpiEvFindRegionHandler (SpaceId,
605 ObjDesc->CommonNotify.Handler);
606
607 if (HandlerObj)
608 {
609 if (HandlerObj->AddressSpace.Handler == Handler)
610 {
611 /*
612 * It is (relatively) OK to attempt to install the SAME
613 * handler twice. This can easily happen with the
614 * PCI_Config space.
615 */
616 Status = AE_SAME_HANDLER;
617 goto UnlockAndExit;
618 }
619 else
620 {
621 /* A handler is already installed */
622
623 Status = AE_ALREADY_EXISTS;
624 }
625
626 goto UnlockAndExit;
627 }
628 }
629 else
630 {
631 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
632 "Creating object on Device %p while installing handler\n",
633 Node));
634
635 /* ObjDesc does not exist, create one */
636
637 if (Node->Type == ACPI_TYPE_ANY)
638 {
639 Type = ACPI_TYPE_DEVICE;
640 }
641 else
642 {
643 Type = Node->Type;
644 }
645
646 ObjDesc = AcpiUtCreateInternalObject (Type);
647 if (!ObjDesc)
648 {
649 Status = AE_NO_MEMORY;
650 goto UnlockAndExit;
651 }
652
653 /* Init new descriptor */
654
655 ObjDesc->Common.Type = (UINT8) Type;
656
657 /* Attach the new object to the Node */
658
659 Status = AcpiNsAttachObject (Node, ObjDesc, Type);
660
661 /* Remove local reference to the object */
662
663 AcpiUtRemoveReference (ObjDesc);
664
665 if (ACPI_FAILURE (Status))
666 {
667 goto UnlockAndExit;
668 }
669 }
670
671 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
672 "Installing address handler for region %s(%X) "
673 "on Device %4.4s %p(%p)\n",
674 AcpiUtGetRegionName (SpaceId), SpaceId,
675 AcpiUtGetNodeName (Node), Node, ObjDesc));
676
677 /*
678 * Install the handler
679 *
680 * At this point there is no existing handler. Just allocate the object
681 * for the handler and link it into the list.
682 */
683 HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
684 if (!HandlerObj)
685 {
686 Status = AE_NO_MEMORY;
687 goto UnlockAndExit;
688 }
689
690 /* Init handler obj */
691
692 Status = AcpiOsCreateMutex (&HandlerObj->AddressSpace.ContextMutex);
693 if (ACPI_FAILURE (Status))
694 {
695 AcpiUtRemoveReference (HandlerObj);
696 goto UnlockAndExit;
697 }
698
699 HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId;
700 HandlerObj->AddressSpace.HandlerFlags = Flags;
701 HandlerObj->AddressSpace.RegionList = NULL;
702 HandlerObj->AddressSpace.Node = Node;
703 HandlerObj->AddressSpace.Handler = Handler;
704 HandlerObj->AddressSpace.Context = Context;
705 HandlerObj->AddressSpace.Setup = Setup;
706
707 /* Install at head of Device.AddressSpace list */
708
709 HandlerObj->AddressSpace.Next = ObjDesc->CommonNotify.Handler;
710
711 /*
712 * The Device object is the first reference on the HandlerObj.
713 * Each region that uses the handler adds a reference.
714 */
715 ObjDesc->CommonNotify.Handler = HandlerObj;
716
717 /*
718 * Walk the namespace finding all of the regions this handler will
719 * manage.
720 *
721 * Start at the device and search the branch toward the leaf nodes
722 * until either the leaf is encountered or a device is detected that
723 * has an address handler of the same type.
724 *
725 * In either case, back up and search down the remainder of the branch
726 */
727 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node,
728 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
729 AcpiEvInstallHandler, NULL, HandlerObj, NULL);
730
731 UnlockAndExit:
732 return_ACPI_STATUS (Status);
733 }
734