src/add-ons/kernel/bus_managers/acpi/acpica/components/events/evhandler.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiEvInstallHandler
 *
 * PARAMETERS:  WalkNamespace callback
 *
 * DESCRIPTION: This routine installs an address handler into objects that are
 *              of type Region or Device.
 *
 *              If the Object is a Device, and the device has a handler of
 *              the same type then the search is terminated in that branch.
 *
 *              This is because the existing handler is closer in proximity
 *              to any more regions than the one we are trying to install.
 *
 ******************************************************************************/


This routine installs an address handler into objects that are
of type Region or Device.

If the Object is a Device, and the device has a handler of
the same type then the search is terminated in that branch.

This is because the existing handler is closer in proximity
to any more regions than the one we are trying to install.
This routine installs an address handler into objects that are of type Region or Device . If the Object is a Device and the device has a handler of the same type then the search is terminated in that branch . This is because the existing handler is closer in proximity to any more regions than the one we are trying to install .
static ACPI_STATUS
AcpiEvInstallHandler (
    ACPI_HANDLE             ObjHandle,
    UINT32                  Level,
    void                    *Context,
    void                    **ReturnValue)
{
    ACPI_OPERAND_OBJECT     *HandlerObj;
    ACPI_OPERAND_OBJECT     *NextHandlerObj;
    ACPI_OPERAND_OBJECT     *ObjDesc;
    ACPI_NAMESPACE_NODE     *Node;
    ACPI_STATUS             Status;
    ACPI_FUNCTION_NAME (EvInstallHandler);
    HandlerObj = (ACPI_OPERAND_OBJECT  *) Context;
    if (!HandlerObj)
    {
        return (AE_OK);
    }
    Node = AcpiNsValidateHandle (ObjHandle);
    if (!Node)
    {
        return (AE_BAD_PARAMETER);
    }
    if ((Node->Type != ACPI_TYPE_DEVICE) &&
        (Node->Type != ACPI_TYPE_REGION) &&
        (Node != AcpiGbl_RootNode))
    {
        return (AE_OK);
    }
    ObjDesc = AcpiNsGetAttachedObject (Node);
    if (!ObjDesc)
    {
        return (AE_OK);
    }
    if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
    {
        NextHandlerObj = AcpiEvFindRegionHandler (
            HandlerObj->AddressSpace.SpaceId, ObjDesc->CommonNotify.Handler);
        if (NextHandlerObj)
        {
            ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
                "Found handler for region [%s] in device %p(%p) handler %p\n",
                AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
                ObjDesc, NextHandlerObj, HandlerObj));
            return (AE_CTRL_DEPTH);
        }
        return (AE_OK);
    }
    if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
    {
        return (AE_OK);
    }
    AcpiEvDetachRegion (ObjDesc, FALSE);
    Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
    return (Status);
}
static ACPI_STATUS AcpiEvInstallHandler ( ACPI_HANDLE ObjHandle , UINT32 Level , void * Context , void * * ReturnValue ) { ACPI_OPERAND_OBJECT * HandlerObj ; ACPI_OPERAND_OBJECT * NextHandlerObj ; ACPI_OPERAND_OBJECT * ObjDesc ; ACPI_NAMESPACE_NODE * Node ; ACPI_STATUS Status ; ACPI_FUNCTION_NAME ( EvInstallHandler ) ; HandlerObj = ( ACPI_OPERAND_OBJECT * ) Context ; if ( ! HandlerObj ) { return ( AE_OK ) ; } Node = AcpiNsValidateHandle ( ObjHandle ) ; if ( ! Node ) { return ( AE_BAD_PARAMETER ) ; } if ( ( Node -> Type != ACPI_TYPE_DEVICE ) && ( Node -> Type != ACPI_TYPE_REGION ) && ( Node != AcpiGbl_RootNode ) ) { return ( AE_OK ) ; } ObjDesc = AcpiNsGetAttachedObject ( Node ) ; if ( ! ObjDesc ) { return ( AE_OK ) ; } if ( ObjDesc -> Common . Type == ACPI_TYPE_DEVICE ) { NextHandlerObj = AcpiEvFindRegionHandler ( HandlerObj -> AddressSpace . SpaceId , ObjDesc -> CommonNotify . Handler ) ; if ( NextHandlerObj ) { ACPI_DEBUG_PRINT ( ( ACPI_DB_OPREGION , " \n " , AcpiUtGetRegionName ( HandlerObj -> AddressSpace . SpaceId ) , ObjDesc , NextHandlerObj , HandlerObj ) ) ; return ( AE_CTRL_DEPTH ) ; } return ( AE_OK ) ; } if ( ObjDesc -> Region . SpaceId != HandlerObj -> AddressSpace . SpaceId ) { return ( AE_OK ) ; } AcpiEvDetachRegion ( ObjDesc , FALSE ) ; Status = AcpiEvAttachRegion ( HandlerObj , ObjDesc , FALSE ) ; return ( Status ) ; }
FUNCTION:    AcpiEvInstallHandler
 PARAMETERS:  WalkNamespace callback
FUNCTION : AcpiEvInstallHandler PARAMETERS : WalkNamespace callback
/* Parameter validation */ /* Convert and validate the device handle */ /*
     * We only care about regions and objects that are allowed to have
     * address space handlers
     */ /* Check for an existing internal object */ /* No object, just exit */ /* Devices are handled different than regions */ /* Check if this Device already has a handler for this address space */ /* Found a handler, is it for the same address space? */ /*
             * Since the object we found it on was a device, then it means
             * that someone has already installed a handler for the branch
             * of the namespace from this device on. Just bail out telling
             * the walk routine to not traverse this branch. This preserves
             * the scoping rule for handlers.
             */ /*
         * As long as the device didn't have a handler for this space we
         * don't care about it. We just ignore it and proceed.
         */ /* Object is a Region */ /* This region is for a different address space, just ignore it */ /*
     * Now we have a region and it is for the handler's address space type.
     *
     * First disconnect region for any previous handler (if any)
     */ /* Connect the region to the new handler */