Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / components / utilities / utxfmutex.c
blob476bbf4b28aff7f5b2260bf3fc1e40eef748eebe
1 /*******************************************************************************
3 * Module Name: utxfmutex - external AML mutex access functions
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, 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 #define __UTXFMUTEX_C__
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "acnamesp.h"
51 #define _COMPONENT ACPI_UTILITIES
52 ACPI_MODULE_NAME ("utxfmutex")
55 /* Local prototypes */
57 static ACPI_STATUS
58 AcpiUtGetMutexObject (
59 ACPI_HANDLE Handle,
60 ACPI_STRING Pathname,
61 ACPI_OPERAND_OBJECT **RetObj);
64 /*******************************************************************************
66 * FUNCTION: AcpiUtGetMutexObject
68 * PARAMETERS: Handle - Mutex or prefix handle (optional)
69 * Pathname - Mutex pathname (optional)
70 * RetObj - Where the mutex object is returned
72 * RETURN: Status
74 * DESCRIPTION: Get an AML mutex object. The mutex node is pointed to by
75 * Handle:Pathname. Either Handle or Pathname can be NULL, but
76 * not both.
78 ******************************************************************************/
80 static ACPI_STATUS
81 AcpiUtGetMutexObject (
82 ACPI_HANDLE Handle,
83 ACPI_STRING Pathname,
84 ACPI_OPERAND_OBJECT **RetObj)
86 ACPI_NAMESPACE_NODE *MutexNode;
87 ACPI_OPERAND_OBJECT *MutexObj;
88 ACPI_STATUS Status;
91 /* Parameter validation */
93 if (!RetObj || (!Handle && !Pathname))
95 return (AE_BAD_PARAMETER);
98 /* Get a the namespace node for the mutex */
100 MutexNode = Handle;
101 if (Pathname != NULL)
103 Status = AcpiGetHandle (Handle, Pathname,
104 ACPI_CAST_PTR (ACPI_HANDLE, &MutexNode));
105 if (ACPI_FAILURE (Status))
107 return (Status);
111 /* Ensure that we actually have a Mutex object */
113 if (!MutexNode ||
114 (MutexNode->Type != ACPI_TYPE_MUTEX))
116 return (AE_TYPE);
119 /* Get the low-level mutex object */
121 MutexObj = AcpiNsGetAttachedObject (MutexNode);
122 if (!MutexObj)
124 return (AE_NULL_OBJECT);
127 *RetObj = MutexObj;
128 return (AE_OK);
132 /*******************************************************************************
134 * FUNCTION: AcpiAcquireMutex
136 * PARAMETERS: Handle - Mutex or prefix handle (optional)
137 * Pathname - Mutex pathname (optional)
138 * Timeout - Max time to wait for the lock (millisec)
140 * RETURN: Status
142 * DESCRIPTION: Acquire an AML mutex. This is a device driver interface to
143 * AML mutex objects, and allows for transaction locking between
144 * drivers and AML code. The mutex node is pointed to by
145 * Handle:Pathname. Either Handle or Pathname can be NULL, but
146 * not both.
148 ******************************************************************************/
150 ACPI_STATUS
151 AcpiAcquireMutex (
152 ACPI_HANDLE Handle,
153 ACPI_STRING Pathname,
154 UINT16 Timeout)
156 ACPI_STATUS Status;
157 ACPI_OPERAND_OBJECT *MutexObj;
160 /* Get the low-level mutex associated with Handle:Pathname */
162 Status = AcpiUtGetMutexObject (Handle, Pathname, &MutexObj);
163 if (ACPI_FAILURE (Status))
165 return (Status);
168 /* Acquire the OS mutex */
170 Status = AcpiOsAcquireMutex (MutexObj->Mutex.OsMutex, Timeout);
171 return (Status);
175 /*******************************************************************************
177 * FUNCTION: AcpiReleaseMutex
179 * PARAMETERS: Handle - Mutex or prefix handle (optional)
180 * Pathname - Mutex pathname (optional)
182 * RETURN: Status
184 * DESCRIPTION: Release an AML mutex. This is a device driver interface to
185 * AML mutex objects, and allows for transaction locking between
186 * drivers and AML code. The mutex node is pointed to by
187 * Handle:Pathname. Either Handle or Pathname can be NULL, but
188 * not both.
190 ******************************************************************************/
192 ACPI_STATUS
193 AcpiReleaseMutex (
194 ACPI_HANDLE Handle,
195 ACPI_STRING Pathname)
197 ACPI_STATUS Status;
198 ACPI_OPERAND_OBJECT *MutexObj;
201 /* Get the low-level mutex associated with Handle:Pathname */
203 Status = AcpiUtGetMutexObject (Handle, Pathname, &MutexObj);
204 if (ACPI_FAILURE (Status))
206 return (Status);
209 /* Release the OS mutex */
211 AcpiOsReleaseMutex (MutexObj->Mutex.OsMutex);
212 return (AE_OK);