evxface.c

来自「acpi tools for linux include acpiexec a」· C语言 代码 · 共 966 行 · 第 1/2 页

C
966
字号
            ObjDesc->CommonNotify.SystemNotify = NotifyObj;        }        if (HandlerType & ACPI_DEVICE_NOTIFY)        {            ObjDesc->CommonNotify.DeviceNotify = NotifyObj;        }        if (HandlerType == ACPI_ALL_NOTIFY)        {            /* Extra ref if installed in both */            AcpiUtAddReference (NotifyObj);        }    }UnlockAndExit:    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);    return_ACPI_STATUS (Status);}ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler)/******************************************************************************* * * FUNCTION:    AcpiRemoveNotifyHandler * * PARAMETERS:  Device          - The device for which notifies will be handled *              HandlerType     - The type of handler: *                                  ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f) *                                  ACPI_DEVICE_NOTIFY: DriverHandler (80-ff) *                                  ACPI_ALL_NOTIFY:  both system and device *              Handler         - Address of the handler * * RETURN:      Status * * DESCRIPTION: Remove a handler for notifies on an ACPI device * ******************************************************************************/ACPI_STATUSAcpiRemoveNotifyHandler (    ACPI_HANDLE             Device,    UINT32                  HandlerType,    ACPI_NOTIFY_HANDLER     Handler){    ACPI_OPERAND_OBJECT     *NotifyObj;    ACPI_OPERAND_OBJECT     *ObjDesc;    ACPI_NAMESPACE_NODE     *Node;    ACPI_STATUS             Status;    ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler);    /* Parameter validation */    if ((!Device)  ||        (!Handler) ||        (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))    {        return_ACPI_STATUS (AE_BAD_PARAMETER);    }    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);    if (ACPI_FAILURE (Status))    {        return_ACPI_STATUS (Status);    }    /* Convert and validate the device handle */    Node = AcpiNsMapHandleToNode (Device);    if (!Node)    {        Status = AE_BAD_PARAMETER;        goto UnlockAndExit;    }    /* Root Object */    if (Device == ACPI_ROOT_OBJECT)    {        ACPI_DEBUG_PRINT ((ACPI_DB_INFO,            "Removing notify handler for namespace root object\n"));        if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&              !AcpiGbl_SystemNotify.Handler)        ||            ((HandlerType & ACPI_DEVICE_NOTIFY) &&              !AcpiGbl_DeviceNotify.Handler))        {            Status = AE_NOT_EXIST;            goto UnlockAndExit;        }        if (HandlerType & ACPI_SYSTEM_NOTIFY)        {            AcpiGbl_SystemNotify.Node    = NULL;            AcpiGbl_SystemNotify.Handler = NULL;            AcpiGbl_SystemNotify.Context = NULL;        }        if (HandlerType & ACPI_DEVICE_NOTIFY)        {            AcpiGbl_DeviceNotify.Node    = NULL;            AcpiGbl_DeviceNotify.Handler = NULL;            AcpiGbl_DeviceNotify.Context = NULL;        }    }    /* All Other Objects */    else    {        /* Notifies allowed on this object? */        if (!AcpiEvIsNotifyObject (Node))        {            Status = AE_TYPE;            goto UnlockAndExit;        }        /* Check for an existing internal object */        ObjDesc = AcpiNsGetAttachedObject (Node);        if (!ObjDesc)        {            Status = AE_NOT_EXIST;            goto UnlockAndExit;        }        /* Object exists - make sure there's an existing handler */        if (HandlerType & ACPI_SYSTEM_NOTIFY)        {            NotifyObj = ObjDesc->CommonNotify.SystemNotify;            if (!NotifyObj)            {                Status = AE_NOT_EXIST;                goto UnlockAndExit;            }            if (NotifyObj->Notify.Handler != Handler)            {                Status = AE_BAD_PARAMETER;                goto UnlockAndExit;            }            /* Remove the handler */            ObjDesc->CommonNotify.SystemNotify = NULL;            AcpiUtRemoveReference (NotifyObj);        }        if (HandlerType & ACPI_DEVICE_NOTIFY)        {            NotifyObj = ObjDesc->CommonNotify.DeviceNotify;            if (!NotifyObj)            {                Status = AE_NOT_EXIST;                goto UnlockAndExit;            }            if (NotifyObj->Notify.Handler != Handler)            {                Status = AE_BAD_PARAMETER;                goto UnlockAndExit;            }            /* Remove the handler */            ObjDesc->CommonNotify.DeviceNotify = NULL;            AcpiUtRemoveReference (NotifyObj);        }    }UnlockAndExit:    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);    return_ACPI_STATUS (Status);}ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler)/******************************************************************************* * * FUNCTION:    AcpiInstallGpeHandler * * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT *                                defined GPEs) *              GpeNumber       - The GPE number within the GPE block *              Type            - Whether this GPE should be treated as an *                                edge- or level-triggered interrupt. *              Address         - Address of the handler *              Context         - Value passed to the handler on each GPE * * RETURN:      Status * * DESCRIPTION: Install a handler for a General Purpose Event. * ******************************************************************************/ACPI_STATUSAcpiInstallGpeHandler (    ACPI_HANDLE             GpeDevice,    UINT32                  GpeNumber,    UINT32                  Type,    ACPI_EVENT_HANDLER      Address,    void                    *Context){    ACPI_GPE_EVENT_INFO     *GpeEventInfo;    ACPI_HANDLER_INFO       *Handler;    ACPI_STATUS             Status;    ACPI_CPU_FLAGS          Flags;    ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler);    /* Parameter validation */    if ((!Address) || (Type > ACPI_GPE_XRUPT_TYPE_MASK))    {        return_ACPI_STATUS (AE_BAD_PARAMETER);    }    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);    if (ACPI_FAILURE (Status))    {        return_ACPI_STATUS (Status);    }    /* Ensure that we have a valid GPE number */    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);    if (!GpeEventInfo)    {        Status = AE_BAD_PARAMETER;        goto UnlockAndExit;    }    /* Make sure that there isn't a handler there already */    if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_HANDLER)    {        Status = AE_ALREADY_EXISTS;        goto UnlockAndExit;    }    /* Allocate and init handler object */    Handler = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_HANDLER_INFO));    if (!Handler)    {        Status = AE_NO_MEMORY;        goto UnlockAndExit;    }    Handler->Address    = Address;    Handler->Context    = Context;    Handler->MethodNode = GpeEventInfo->Dispatch.MethodNode;    /* Disable the GPE before installing the handler */    Status = AcpiEvDisableGpe (GpeEventInfo);    if (ACPI_FAILURE (Status))    {        goto UnlockAndExit;    }    /* Install the handler */    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);    GpeEventInfo->Dispatch.Handler = Handler;    /* Setup up dispatch flags to indicate handler (vs. method) */    GpeEventInfo->Flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);  /* Clear bits */    GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_HANDLER);    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);UnlockAndExit:    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);    return_ACPI_STATUS (Status);}ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler)/******************************************************************************* * * FUNCTION:    AcpiRemoveGpeHandler * * PARAMETERS:  GpeDevice       - Namespace node for the GPE (NULL for FADT *                                defined GPEs) *              GpeNumber       - The event to remove a handler *              Address         - Address of the handler * * RETURN:      Status * * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent. * ******************************************************************************/ACPI_STATUSAcpiRemoveGpeHandler (    ACPI_HANDLE             GpeDevice,    UINT32                  GpeNumber,    ACPI_EVENT_HANDLER      Address){    ACPI_GPE_EVENT_INFO     *GpeEventInfo;    ACPI_HANDLER_INFO       *Handler;    ACPI_STATUS             Status;    ACPI_CPU_FLAGS          Flags;    ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler);    /* Parameter validation */    if (!Address)    {        return_ACPI_STATUS (AE_BAD_PARAMETER);    }    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);    if (ACPI_FAILURE (Status))    {        return_ACPI_STATUS (Status);    }    /* Ensure that we have a valid GPE number */    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);    if (!GpeEventInfo)    {        Status = AE_BAD_PARAMETER;        goto UnlockAndExit;    }    /* Make sure that a handler is indeed installed */    if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) != ACPI_GPE_DISPATCH_HANDLER)    {        Status = AE_NOT_EXIST;        goto UnlockAndExit;    }    /* Make sure that the installed handler is the same */    if (GpeEventInfo->Dispatch.Handler->Address != Address)    {        Status = AE_BAD_PARAMETER;        goto UnlockAndExit;    }    /* Disable the GPE before removing the handler */    Status = AcpiEvDisableGpe (GpeEventInfo);    if (ACPI_FAILURE (Status))    {        goto UnlockAndExit;    }    /* Remove the handler */    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);    Handler = GpeEventInfo->Dispatch.Handler;    /* Restore Method node (if any), set dispatch flags */    GpeEventInfo->Dispatch.MethodNode = Handler->MethodNode;    GpeEventInfo->Flags &= ~ACPI_GPE_DISPATCH_MASK;  /* Clear bits */    if (Handler->MethodNode)    {        GpeEventInfo->Flags |= ACPI_GPE_DISPATCH_METHOD;    }    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);    /* Now we can free the handler object */    ACPI_FREE (Handler);UnlockAndExit:    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);    return_ACPI_STATUS (Status);}ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler)/******************************************************************************* * * FUNCTION:    AcpiAcquireGlobalLock * * PARAMETERS:  Timeout         - How long the caller is willing to wait *              Handle          - Where the handle to the lock is returned *                                (if acquired) * * RETURN:      Status * * DESCRIPTION: Acquire the ACPI Global Lock * * Note: Allows callers with the same thread ID to acquire the global lock * multiple times. In other words, externally, the behavior of the global lock * is identical to an AML mutex. On the first acquire, a new handle is * returned. On any subsequent calls to acquire by the same thread, the same * handle is returned. * ******************************************************************************/ACPI_STATUSAcpiAcquireGlobalLock (    UINT16                  Timeout,    UINT32                  *Handle){    ACPI_STATUS             Status;    if (!Handle)    {        return (AE_BAD_PARAMETER);    }    /* Must lock interpreter to prevent race conditions */    AcpiExEnterInterpreter ();    Status = AcpiExAcquireMutexObject (Timeout,                AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());    if (ACPI_SUCCESS (Status))    {        /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */        *Handle = AcpiGbl_GlobalLockHandle;    }    AcpiExExitInterpreter ();    return (Status);}ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock)/******************************************************************************* * * FUNCTION:    AcpiReleaseGlobalLock * * PARAMETERS:  Handle      - Returned from AcpiAcquireGlobalLock * * RETURN:      Status * * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid. * ******************************************************************************/ACPI_STATUSAcpiReleaseGlobalLock (    UINT32                  Handle){    ACPI_STATUS             Status;    if (!Handle || (Handle != AcpiGbl_GlobalLockHandle))    {        return (AE_NOT_ACQUIRED);    }    Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);    return (Status);}ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?