1*385cc6b4SJerry Jelinek /*******************************************************************************
2*385cc6b4SJerry Jelinek *
3*385cc6b4SJerry Jelinek * Module Name: utxfmutex - external AML mutex access functions
4*385cc6b4SJerry Jelinek *
5*385cc6b4SJerry Jelinek ******************************************************************************/
6*385cc6b4SJerry Jelinek
7*385cc6b4SJerry Jelinek /*
8*385cc6b4SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp.
9*385cc6b4SJerry Jelinek * All rights reserved.
10*385cc6b4SJerry Jelinek *
11*385cc6b4SJerry Jelinek * Redistribution and use in source and binary forms, with or without
12*385cc6b4SJerry Jelinek * modification, are permitted provided that the following conditions
13*385cc6b4SJerry Jelinek * are met:
14*385cc6b4SJerry Jelinek * 1. Redistributions of source code must retain the above copyright
15*385cc6b4SJerry Jelinek * notice, this list of conditions, and the following disclaimer,
16*385cc6b4SJerry Jelinek * without modification.
17*385cc6b4SJerry Jelinek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*385cc6b4SJerry Jelinek * substantially similar to the "NO WARRANTY" disclaimer below
19*385cc6b4SJerry Jelinek * ("Disclaimer") and any redistribution must be conditioned upon
20*385cc6b4SJerry Jelinek * including a substantially similar Disclaimer requirement for further
21*385cc6b4SJerry Jelinek * binary redistribution.
22*385cc6b4SJerry Jelinek * 3. Neither the names of the above-listed copyright holders nor the names
23*385cc6b4SJerry Jelinek * of any contributors may be used to endorse or promote products derived
24*385cc6b4SJerry Jelinek * from this software without specific prior written permission.
25*385cc6b4SJerry Jelinek *
26*385cc6b4SJerry Jelinek * Alternatively, this software may be distributed under the terms of the
27*385cc6b4SJerry Jelinek * GNU General Public License ("GPL") version 2 as published by the Free
28*385cc6b4SJerry Jelinek * Software Foundation.
29*385cc6b4SJerry Jelinek *
30*385cc6b4SJerry Jelinek * NO WARRANTY
31*385cc6b4SJerry Jelinek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*385cc6b4SJerry Jelinek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*385cc6b4SJerry Jelinek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*385cc6b4SJerry Jelinek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*385cc6b4SJerry Jelinek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*385cc6b4SJerry Jelinek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*385cc6b4SJerry Jelinek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*385cc6b4SJerry Jelinek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*385cc6b4SJerry Jelinek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*385cc6b4SJerry Jelinek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*385cc6b4SJerry Jelinek * POSSIBILITY OF SUCH DAMAGES.
42*385cc6b4SJerry Jelinek */
43*385cc6b4SJerry Jelinek
44*385cc6b4SJerry Jelinek #include "acpi.h"
45*385cc6b4SJerry Jelinek #include "accommon.h"
46*385cc6b4SJerry Jelinek #include "acnamesp.h"
47*385cc6b4SJerry Jelinek
48*385cc6b4SJerry Jelinek
49*385cc6b4SJerry Jelinek #define _COMPONENT ACPI_UTILITIES
50*385cc6b4SJerry Jelinek ACPI_MODULE_NAME ("utxfmutex")
51*385cc6b4SJerry Jelinek
52*385cc6b4SJerry Jelinek
53*385cc6b4SJerry Jelinek /* Local prototypes */
54*385cc6b4SJerry Jelinek
55*385cc6b4SJerry Jelinek static ACPI_STATUS
56*385cc6b4SJerry Jelinek AcpiUtGetMutexObject (
57*385cc6b4SJerry Jelinek ACPI_HANDLE Handle,
58*385cc6b4SJerry Jelinek ACPI_STRING Pathname,
59*385cc6b4SJerry Jelinek ACPI_OPERAND_OBJECT **RetObj);
60*385cc6b4SJerry Jelinek
61*385cc6b4SJerry Jelinek
62*385cc6b4SJerry Jelinek /*******************************************************************************
63*385cc6b4SJerry Jelinek *
64*385cc6b4SJerry Jelinek * FUNCTION: AcpiUtGetMutexObject
65*385cc6b4SJerry Jelinek *
66*385cc6b4SJerry Jelinek * PARAMETERS: Handle - Mutex or prefix handle (optional)
67*385cc6b4SJerry Jelinek * Pathname - Mutex pathname (optional)
68*385cc6b4SJerry Jelinek * RetObj - Where the mutex object is returned
69*385cc6b4SJerry Jelinek *
70*385cc6b4SJerry Jelinek * RETURN: Status
71*385cc6b4SJerry Jelinek *
72*385cc6b4SJerry Jelinek * DESCRIPTION: Get an AML mutex object. The mutex node is pointed to by
73*385cc6b4SJerry Jelinek * Handle:Pathname. Either Handle or Pathname can be NULL, but
74*385cc6b4SJerry Jelinek * not both.
75*385cc6b4SJerry Jelinek *
76*385cc6b4SJerry Jelinek ******************************************************************************/
77*385cc6b4SJerry Jelinek
78*385cc6b4SJerry Jelinek static ACPI_STATUS
AcpiUtGetMutexObject(ACPI_HANDLE Handle,ACPI_STRING Pathname,ACPI_OPERAND_OBJECT ** RetObj)79*385cc6b4SJerry Jelinek AcpiUtGetMutexObject (
80*385cc6b4SJerry Jelinek ACPI_HANDLE Handle,
81*385cc6b4SJerry Jelinek ACPI_STRING Pathname,
82*385cc6b4SJerry Jelinek ACPI_OPERAND_OBJECT **RetObj)
83*385cc6b4SJerry Jelinek {
84*385cc6b4SJerry Jelinek ACPI_NAMESPACE_NODE *MutexNode;
85*385cc6b4SJerry Jelinek ACPI_OPERAND_OBJECT *MutexObj;
86*385cc6b4SJerry Jelinek ACPI_STATUS Status;
87*385cc6b4SJerry Jelinek
88*385cc6b4SJerry Jelinek
89*385cc6b4SJerry Jelinek /* Parameter validation */
90*385cc6b4SJerry Jelinek
91*385cc6b4SJerry Jelinek if (!RetObj || (!Handle && !Pathname))
92*385cc6b4SJerry Jelinek {
93*385cc6b4SJerry Jelinek return (AE_BAD_PARAMETER);
94*385cc6b4SJerry Jelinek }
95*385cc6b4SJerry Jelinek
96*385cc6b4SJerry Jelinek /* Get a the namespace node for the mutex */
97*385cc6b4SJerry Jelinek
98*385cc6b4SJerry Jelinek MutexNode = Handle;
99*385cc6b4SJerry Jelinek if (Pathname != NULL)
100*385cc6b4SJerry Jelinek {
101*385cc6b4SJerry Jelinek Status = AcpiGetHandle (
102*385cc6b4SJerry Jelinek Handle, Pathname, ACPI_CAST_PTR (ACPI_HANDLE, &MutexNode));
103*385cc6b4SJerry Jelinek if (ACPI_FAILURE (Status))
104*385cc6b4SJerry Jelinek {
105*385cc6b4SJerry Jelinek return (Status);
106*385cc6b4SJerry Jelinek }
107*385cc6b4SJerry Jelinek }
108*385cc6b4SJerry Jelinek
109*385cc6b4SJerry Jelinek /* Ensure that we actually have a Mutex object */
110*385cc6b4SJerry Jelinek
111*385cc6b4SJerry Jelinek if (!MutexNode ||
112*385cc6b4SJerry Jelinek (MutexNode->Type != ACPI_TYPE_MUTEX))
113*385cc6b4SJerry Jelinek {
114*385cc6b4SJerry Jelinek return (AE_TYPE);
115*385cc6b4SJerry Jelinek }
116*385cc6b4SJerry Jelinek
117*385cc6b4SJerry Jelinek /* Get the low-level mutex object */
118*385cc6b4SJerry Jelinek
119*385cc6b4SJerry Jelinek MutexObj = AcpiNsGetAttachedObject (MutexNode);
120*385cc6b4SJerry Jelinek if (!MutexObj)
121*385cc6b4SJerry Jelinek {
122*385cc6b4SJerry Jelinek return (AE_NULL_OBJECT);
123*385cc6b4SJerry Jelinek }
124*385cc6b4SJerry Jelinek
125*385cc6b4SJerry Jelinek *RetObj = MutexObj;
126*385cc6b4SJerry Jelinek return (AE_OK);
127*385cc6b4SJerry Jelinek }
128*385cc6b4SJerry Jelinek
129*385cc6b4SJerry Jelinek
130*385cc6b4SJerry Jelinek /*******************************************************************************
131*385cc6b4SJerry Jelinek *
132*385cc6b4SJerry Jelinek * FUNCTION: AcpiAcquireMutex
133*385cc6b4SJerry Jelinek *
134*385cc6b4SJerry Jelinek * PARAMETERS: Handle - Mutex or prefix handle (optional)
135*385cc6b4SJerry Jelinek * Pathname - Mutex pathname (optional)
136*385cc6b4SJerry Jelinek * Timeout - Max time to wait for the lock (millisec)
137*385cc6b4SJerry Jelinek *
138*385cc6b4SJerry Jelinek * RETURN: Status
139*385cc6b4SJerry Jelinek *
140*385cc6b4SJerry Jelinek * DESCRIPTION: Acquire an AML mutex. This is a device driver interface to
141*385cc6b4SJerry Jelinek * AML mutex objects, and allows for transaction locking between
142*385cc6b4SJerry Jelinek * drivers and AML code. The mutex node is pointed to by
143*385cc6b4SJerry Jelinek * Handle:Pathname. Either Handle or Pathname can be NULL, but
144*385cc6b4SJerry Jelinek * not both.
145*385cc6b4SJerry Jelinek *
146*385cc6b4SJerry Jelinek ******************************************************************************/
147*385cc6b4SJerry Jelinek
148*385cc6b4SJerry Jelinek ACPI_STATUS
AcpiAcquireMutex(ACPI_HANDLE Handle,ACPI_STRING Pathname,UINT16 Timeout)149*385cc6b4SJerry Jelinek AcpiAcquireMutex (
150*385cc6b4SJerry Jelinek ACPI_HANDLE Handle,
151*385cc6b4SJerry Jelinek ACPI_STRING Pathname,
152*385cc6b4SJerry Jelinek UINT16 Timeout)
153*385cc6b4SJerry Jelinek {
154*385cc6b4SJerry Jelinek ACPI_STATUS Status;
155*385cc6b4SJerry Jelinek ACPI_OPERAND_OBJECT *MutexObj;
156*385cc6b4SJerry Jelinek
157*385cc6b4SJerry Jelinek
158*385cc6b4SJerry Jelinek /* Get the low-level mutex associated with Handle:Pathname */
159*385cc6b4SJerry Jelinek
160*385cc6b4SJerry Jelinek Status = AcpiUtGetMutexObject (Handle, Pathname, &MutexObj);
161*385cc6b4SJerry Jelinek if (ACPI_FAILURE (Status))
162*385cc6b4SJerry Jelinek {
163*385cc6b4SJerry Jelinek return (Status);
164*385cc6b4SJerry Jelinek }
165*385cc6b4SJerry Jelinek
166*385cc6b4SJerry Jelinek /* Acquire the OS mutex */
167*385cc6b4SJerry Jelinek
168*385cc6b4SJerry Jelinek Status = AcpiOsAcquireMutex (MutexObj->Mutex.OsMutex, Timeout);
169*385cc6b4SJerry Jelinek return (Status);
170*385cc6b4SJerry Jelinek }
171*385cc6b4SJerry Jelinek
172*385cc6b4SJerry Jelinek
173*385cc6b4SJerry Jelinek /*******************************************************************************
174*385cc6b4SJerry Jelinek *
175*385cc6b4SJerry Jelinek * FUNCTION: AcpiReleaseMutex
176*385cc6b4SJerry Jelinek *
177*385cc6b4SJerry Jelinek * PARAMETERS: Handle - Mutex or prefix handle (optional)
178*385cc6b4SJerry Jelinek * Pathname - Mutex pathname (optional)
179*385cc6b4SJerry Jelinek *
180*385cc6b4SJerry Jelinek * RETURN: Status
181*385cc6b4SJerry Jelinek *
182*385cc6b4SJerry Jelinek * DESCRIPTION: Release an AML mutex. This is a device driver interface to
183*385cc6b4SJerry Jelinek * AML mutex objects, and allows for transaction locking between
184*385cc6b4SJerry Jelinek * drivers and AML code. The mutex node is pointed to by
185*385cc6b4SJerry Jelinek * Handle:Pathname. Either Handle or Pathname can be NULL, but
186*385cc6b4SJerry Jelinek * not both.
187*385cc6b4SJerry Jelinek *
188*385cc6b4SJerry Jelinek ******************************************************************************/
189*385cc6b4SJerry Jelinek
190*385cc6b4SJerry Jelinek ACPI_STATUS
AcpiReleaseMutex(ACPI_HANDLE Handle,ACPI_STRING Pathname)191*385cc6b4SJerry Jelinek AcpiReleaseMutex (
192*385cc6b4SJerry Jelinek ACPI_HANDLE Handle,
193*385cc6b4SJerry Jelinek ACPI_STRING Pathname)
194*385cc6b4SJerry Jelinek {
195*385cc6b4SJerry Jelinek ACPI_STATUS Status;
196*385cc6b4SJerry Jelinek ACPI_OPERAND_OBJECT *MutexObj;
197*385cc6b4SJerry Jelinek
198*385cc6b4SJerry Jelinek
199*385cc6b4SJerry Jelinek /* Get the low-level mutex associated with Handle:Pathname */
200*385cc6b4SJerry Jelinek
201*385cc6b4SJerry Jelinek Status = AcpiUtGetMutexObject (Handle, Pathname, &MutexObj);
202*385cc6b4SJerry Jelinek if (ACPI_FAILURE (Status))
203*385cc6b4SJerry Jelinek {
204*385cc6b4SJerry Jelinek return (Status);
205*385cc6b4SJerry Jelinek }
206*385cc6b4SJerry Jelinek
207*385cc6b4SJerry Jelinek /* Release the OS mutex */
208*385cc6b4SJerry Jelinek
209*385cc6b4SJerry Jelinek AcpiOsReleaseMutex (MutexObj->Mutex.OsMutex);
210*385cc6b4SJerry Jelinek return (AE_OK);
211*385cc6b4SJerry Jelinek }
212