Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /*******************************************************************************
0003  *
0004  * Module Name: utxfmutex - external AML mutex access functions
0005  *
0006  ******************************************************************************/
0007 
0008 #include <acpi/acpi.h>
0009 #include "accommon.h"
0010 #include "acnamesp.h"
0011 
0012 #define _COMPONENT          ACPI_UTILITIES
0013 ACPI_MODULE_NAME("utxfmutex")
0014 
0015 /* Local prototypes */
0016 static acpi_status
0017 acpi_ut_get_mutex_object(acpi_handle handle,
0018              acpi_string pathname,
0019              union acpi_operand_object **ret_obj);
0020 
0021 /*******************************************************************************
0022  *
0023  * FUNCTION:    acpi_ut_get_mutex_object
0024  *
0025  * PARAMETERS:  handle              - Mutex or prefix handle (optional)
0026  *              pathname            - Mutex pathname (optional)
0027  *              ret_obj             - Where the mutex object is returned
0028  *
0029  * RETURN:      Status
0030  *
0031  * DESCRIPTION: Get an AML mutex object. The mutex node is pointed to by
0032  *              Handle:Pathname. Either Handle or Pathname can be NULL, but
0033  *              not both.
0034  *
0035  ******************************************************************************/
0036 
0037 static acpi_status
0038 acpi_ut_get_mutex_object(acpi_handle handle,
0039              acpi_string pathname,
0040              union acpi_operand_object **ret_obj)
0041 {
0042     struct acpi_namespace_node *mutex_node;
0043     union acpi_operand_object *mutex_obj;
0044     acpi_status status;
0045 
0046     /* Parameter validation */
0047 
0048     if (!ret_obj || (!handle && !pathname)) {
0049         return (AE_BAD_PARAMETER);
0050     }
0051 
0052     /* Get a the namespace node for the mutex */
0053 
0054     mutex_node = handle;
0055     if (pathname != NULL) {
0056         status =
0057             acpi_get_handle(handle, pathname,
0058                     ACPI_CAST_PTR(acpi_handle, &mutex_node));
0059         if (ACPI_FAILURE(status)) {
0060             return (status);
0061         }
0062     }
0063 
0064     /* Ensure that we actually have a Mutex object */
0065 
0066     if (!mutex_node || (mutex_node->type != ACPI_TYPE_MUTEX)) {
0067         return (AE_TYPE);
0068     }
0069 
0070     /* Get the low-level mutex object */
0071 
0072     mutex_obj = acpi_ns_get_attached_object(mutex_node);
0073     if (!mutex_obj) {
0074         return (AE_NULL_OBJECT);
0075     }
0076 
0077     *ret_obj = mutex_obj;
0078     return (AE_OK);
0079 }
0080 
0081 /*******************************************************************************
0082  *
0083  * FUNCTION:    acpi_acquire_mutex
0084  *
0085  * PARAMETERS:  handle              - Mutex or prefix handle (optional)
0086  *              pathname            - Mutex pathname (optional)
0087  *              timeout             - Max time to wait for the lock (millisec)
0088  *
0089  * RETURN:      Status
0090  *
0091  * DESCRIPTION: Acquire an AML mutex. This is a device driver interface to
0092  *              AML mutex objects, and allows for transaction locking between
0093  *              drivers and AML code. The mutex node is pointed to by
0094  *              Handle:Pathname. Either Handle or Pathname can be NULL, but
0095  *              not both.
0096  *
0097  ******************************************************************************/
0098 
0099 acpi_status
0100 acpi_acquire_mutex(acpi_handle handle, acpi_string pathname, u16 timeout)
0101 {
0102     acpi_status status;
0103     union acpi_operand_object *mutex_obj;
0104 
0105     /* Get the low-level mutex associated with Handle:Pathname */
0106 
0107     status = acpi_ut_get_mutex_object(handle, pathname, &mutex_obj);
0108     if (ACPI_FAILURE(status)) {
0109         return (status);
0110     }
0111 
0112     /* Acquire the OS mutex */
0113 
0114     status = acpi_os_acquire_mutex(mutex_obj->mutex.os_mutex, timeout);
0115     return (status);
0116 }
0117 
0118 ACPI_EXPORT_SYMBOL(acpi_acquire_mutex)
0119 
0120 /*******************************************************************************
0121  *
0122  * FUNCTION:    acpi_release_mutex
0123  *
0124  * PARAMETERS:  handle              - Mutex or prefix handle (optional)
0125  *              pathname            - Mutex pathname (optional)
0126  *
0127  * RETURN:      Status
0128  *
0129  * DESCRIPTION: Release an AML mutex. This is a device driver interface to
0130  *              AML mutex objects, and allows for transaction locking between
0131  *              drivers and AML code. The mutex node is pointed to by
0132  *              Handle:Pathname. Either Handle or Pathname can be NULL, but
0133  *              not both.
0134  *
0135  ******************************************************************************/
0136 acpi_status acpi_release_mutex(acpi_handle handle, acpi_string pathname)
0137 {
0138     acpi_status status;
0139     union acpi_operand_object *mutex_obj;
0140 
0141     /* Get the low-level mutex associated with Handle:Pathname */
0142 
0143     status = acpi_ut_get_mutex_object(handle, pathname, &mutex_obj);
0144     if (ACPI_FAILURE(status)) {
0145         return (status);
0146     }
0147 
0148     /* Release the OS mutex */
0149 
0150     acpi_os_release_mutex(mutex_obj->mutex.os_mutex);
0151     return (AE_OK);
0152 }
0153 
0154 ACPI_EXPORT_SYMBOL(acpi_release_mutex)