Linux 4.1.16
[linux/fpc-iii.git] / drivers / acpi / acpica / utxfmutex.c
blobf2606af3364c7f6ca1c580bc3bc4921df46f1b3f
1 /*******************************************************************************
3 * Module Name: utxfmutex - external AML mutex access functions
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2015, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acnamesp.h"
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME("utxfmutex")
51 /* Local prototypes */
52 static acpi_status
53 acpi_ut_get_mutex_object(acpi_handle handle,
54 acpi_string pathname,
55 union acpi_operand_object **ret_obj);
57 /*******************************************************************************
59 * FUNCTION: acpi_ut_get_mutex_object
61 * PARAMETERS: handle - Mutex or prefix handle (optional)
62 * pathname - Mutex pathname (optional)
63 * ret_obj - Where the mutex object is returned
65 * RETURN: Status
67 * DESCRIPTION: Get an AML mutex object. The mutex node is pointed to by
68 * Handle:Pathname. Either Handle or Pathname can be NULL, but
69 * not both.
71 ******************************************************************************/
73 static acpi_status
74 acpi_ut_get_mutex_object(acpi_handle handle,
75 acpi_string pathname,
76 union acpi_operand_object **ret_obj)
78 struct acpi_namespace_node *mutex_node;
79 union acpi_operand_object *mutex_obj;
80 acpi_status status;
82 /* Parameter validation */
84 if (!ret_obj || (!handle && !pathname)) {
85 return (AE_BAD_PARAMETER);
88 /* Get a the namespace node for the mutex */
90 mutex_node = handle;
91 if (pathname != NULL) {
92 status = acpi_get_handle(handle, pathname,
93 ACPI_CAST_PTR(acpi_handle,
94 &mutex_node));
95 if (ACPI_FAILURE(status)) {
96 return (status);
100 /* Ensure that we actually have a Mutex object */
102 if (!mutex_node || (mutex_node->type != ACPI_TYPE_MUTEX)) {
103 return (AE_TYPE);
106 /* Get the low-level mutex object */
108 mutex_obj = acpi_ns_get_attached_object(mutex_node);
109 if (!mutex_obj) {
110 return (AE_NULL_OBJECT);
113 *ret_obj = mutex_obj;
114 return (AE_OK);
117 /*******************************************************************************
119 * FUNCTION: acpi_acquire_mutex
121 * PARAMETERS: handle - Mutex or prefix handle (optional)
122 * pathname - Mutex pathname (optional)
123 * timeout - Max time to wait for the lock (millisec)
125 * RETURN: Status
127 * DESCRIPTION: Acquire an AML mutex. This is a device driver interface to
128 * AML mutex objects, and allows for transaction locking between
129 * drivers and AML code. The mutex node is pointed to by
130 * Handle:Pathname. Either Handle or Pathname can be NULL, but
131 * not both.
133 ******************************************************************************/
135 acpi_status
136 acpi_acquire_mutex(acpi_handle handle, acpi_string pathname, u16 timeout)
138 acpi_status status;
139 union acpi_operand_object *mutex_obj;
141 /* Get the low-level mutex associated with Handle:Pathname */
143 status = acpi_ut_get_mutex_object(handle, pathname, &mutex_obj);
144 if (ACPI_FAILURE(status)) {
145 return (status);
148 /* Acquire the OS mutex */
150 status = acpi_os_acquire_mutex(mutex_obj->mutex.os_mutex, timeout);
151 return (status);
154 /*******************************************************************************
156 * FUNCTION: acpi_release_mutex
158 * PARAMETERS: handle - Mutex or prefix handle (optional)
159 * pathname - Mutex pathname (optional)
161 * RETURN: Status
163 * DESCRIPTION: Release an AML mutex. This is a device driver interface to
164 * AML mutex objects, and allows for transaction locking between
165 * drivers and AML code. The mutex node is pointed to by
166 * Handle:Pathname. Either Handle or Pathname can be NULL, but
167 * not both.
169 ******************************************************************************/
171 acpi_status acpi_release_mutex(acpi_handle handle, acpi_string pathname)
173 acpi_status status;
174 union acpi_operand_object *mutex_obj;
176 /* Get the low-level mutex associated with Handle:Pathname */
178 status = acpi_ut_get_mutex_object(handle, pathname, &mutex_obj);
179 if (ACPI_FAILURE(status)) {
180 return (status);
183 /* Release the OS mutex */
185 acpi_os_release_mutex(mutex_obj->mutex.os_mutex);
186 return (AE_OK);