ReactOS  0.4.14-dev-342-gdc047f9
exsystem.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Module Name: exsystem - Interface to OS services
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2019, Intel Corp.
9  * All rights reserved.
10  *
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.
25  *
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.
29  *
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.
42  */
43 
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acinterp.h"
47 
48 #define _COMPONENT ACPI_EXECUTER
49  ACPI_MODULE_NAME ("exsystem")
50 
51 
52 /*******************************************************************************
53  *
54  * FUNCTION: AcpiExSystemWaitSemaphore
55  *
56  * PARAMETERS: Semaphore - Semaphore to wait on
57  * Timeout - Max time to wait
58  *
59  * RETURN: Status
60  *
61  * DESCRIPTION: Implements a semaphore wait with a check to see if the
62  * semaphore is available immediately. If it is not, the
63  * interpreter is released before waiting.
64  *
65  ******************************************************************************/
66 
69  ACPI_SEMAPHORE Semaphore,
71 {
73 
74 
75  ACPI_FUNCTION_TRACE (ExSystemWaitSemaphore);
76 
77 
79  if (ACPI_SUCCESS (Status))
80  {
82  }
83 
84  if (Status == AE_TIME)
85  {
86  /* We must wait, so unlock the interpreter */
87 
89  Status = AcpiOsWaitSemaphore (Semaphore, 1, Timeout);
90 
92  "*** Thread awake after blocking, %s\n",
94 
95  /* Reacquire the interpreter */
96 
98  }
99 
101 }
102 
103 
104 /*******************************************************************************
105  *
106  * FUNCTION: AcpiExSystemWaitMutex
107  *
108  * PARAMETERS: Mutex - Mutex to wait on
109  * Timeout - Max time to wait
110  *
111  * RETURN: Status
112  *
113  * DESCRIPTION: Implements a mutex wait with a check to see if the
114  * mutex is available immediately. If it is not, the
115  * interpreter is released before waiting.
116  *
117  ******************************************************************************/
118 
122  UINT16 Timeout)
123 {
125 
126 
127  ACPI_FUNCTION_TRACE (ExSystemWaitMutex);
128 
129 
131  if (ACPI_SUCCESS (Status))
132  {
134  }
135 
136  if (Status == AE_TIME)
137  {
138  /* We must wait, so unlock the interpreter */
139 
142 
144  "*** Thread awake after blocking, %s\n",
146 
147  /* Reacquire the interpreter */
148 
150  }
151 
153 }
154 
155 
156 /*******************************************************************************
157  *
158  * FUNCTION: AcpiExSystemDoStall
159  *
160  * PARAMETERS: HowLong - The amount of time to stall,
161  * in microseconds
162  *
163  * RETURN: Status
164  *
165  * DESCRIPTION: Suspend running thread for specified amount of time.
166  * Note: ACPI specification requires that Stall() does not
167  * relinquish the processor, and delays longer than 100 usec
168  * should use Sleep() instead. We allow stalls up to 255 usec
169  * for compatibility with other interpreters and existing BIOSs.
170  *
171  ******************************************************************************/
172 
175  UINT32 HowLong)
176 {
178 
179 
181 
182 
183  if (HowLong > 255) /* 255 microseconds */
184  {
185  /*
186  * Longer than 255 usec, this is an error
187  *
188  * (ACPI specifies 100 usec as max, but this gives some slack in
189  * order to support existing BIOSs)
190  */
192  "Time parameter is too large (%u)", HowLong));
194  }
195  else
196  {
197  AcpiOsStall (HowLong);
198  }
199 
200  return (Status);
201 }
202 
203 
204 /*******************************************************************************
205  *
206  * FUNCTION: AcpiExSystemDoSleep
207  *
208  * PARAMETERS: HowLong - The amount of time to sleep,
209  * in milliseconds
210  *
211  * RETURN: None
212  *
213  * DESCRIPTION: Sleep the running thread for specified amount of time.
214  *
215  ******************************************************************************/
216 
219  UINT64 HowLong)
220 {
222 
223 
224  /* Since this thread will sleep, we must release the interpreter */
225 
227 
228  /*
229  * For compatibility with other ACPI implementations and to prevent
230  * accidental deep sleeps, limit the sleep time to something reasonable.
231  */
232  if (HowLong > ACPI_MAX_SLEEP)
233  {
234  HowLong = ACPI_MAX_SLEEP;
235  }
236 
237  AcpiOsSleep (HowLong);
238 
239  /* And now we must get the interpreter again */
240 
242  return (AE_OK);
243 }
244 
245 
246 /*******************************************************************************
247  *
248  * FUNCTION: AcpiExSystemSignalEvent
249  *
250  * PARAMETERS: ObjDesc - The object descriptor for this op
251  *
252  * RETURN: Status
253  *
254  * DESCRIPTION: Provides an access point to perform synchronization operations
255  * within the AML.
256  *
257  ******************************************************************************/
258 
261  ACPI_OPERAND_OBJECT *ObjDesc)
262 {
264 
265 
266  ACPI_FUNCTION_TRACE (ExSystemSignalEvent);
267 
268 
269  if (ObjDesc)
270  {
272  }
273 
275 }
276 
277 
278 /*******************************************************************************
279  *
280  * FUNCTION: AcpiExSystemWaitEvent
281  *
282  * PARAMETERS: TimeDesc - The 'time to delay' object descriptor
283  * ObjDesc - The object descriptor for this op
284  *
285  * RETURN: Status
286  *
287  * DESCRIPTION: Provides an access point to perform synchronization operations
288  * within the AML. This operation is a request to wait for an
289  * event.
290  *
291  ******************************************************************************/
292 
295  ACPI_OPERAND_OBJECT *TimeDesc,
296  ACPI_OPERAND_OBJECT *ObjDesc)
297 {
299 
300 
301  ACPI_FUNCTION_TRACE (ExSystemWaitEvent);
302 
303 
304  if (ObjDesc)
305  {
307  (UINT16) TimeDesc->Integer.Value);
308  }
309 
311 }
312 
313 
314 /*******************************************************************************
315  *
316  * FUNCTION: AcpiExSystemResetEvent
317  *
318  * PARAMETERS: ObjDesc - The object descriptor for this op
319  *
320  * RETURN: Status
321  *
322  * DESCRIPTION: Reset an event to a known state.
323  *
324  ******************************************************************************/
325 
328  ACPI_OPERAND_OBJECT *ObjDesc)
329 {
331  ACPI_SEMAPHORE TempSemaphore;
332 
333 
335 
336 
337  /*
338  * We are going to simply delete the existing semaphore and
339  * create a new one!
340  */
341  Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0, &TempSemaphore);
342  if (ACPI_SUCCESS (Status))
343  {
345  ObjDesc->Event.OsSemaphore = TempSemaphore;
346  }
347 
348  return (Status);
349 }
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
void AcpiOsSleep(UINT64 Milliseconds)
Definition: osl.c:257
ACPI_STATUS AcpiExSystemResetEvent(ACPI_OPERAND_OBJECT *ObjDesc)
Definition: exsystem.c:327
void AcpiOsStall(UINT32 Microseconds)
Definition: osl.c:264
ACPI_STATUS AcpiOsSignalSemaphore(ACPI_SEMAPHORE Handle, UINT32 Units)
Definition: osl.c:439
#define AE_AML_OPERAND_VALUE
Definition: acexcep.h:183
ACPI_STATUS AcpiOsAcquireMutex(ACPI_MUTEX Handle, UINT16 Timeout)
Definition: osl.c:306
#define ACPI_SEMAPHORE
Definition: actypes.h:287
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define AE_TIME
Definition: acexcep.h:125
Definition: Mutex.h:15
const char * AcpiFormatException(ACPI_STATUS Status)
Definition: utexcep.c:70
ACPI_OBJECT_EVENT Event
Definition: acobject.h:521
unsigned int UINT32
ACPI_STATUS AcpiExSystemSignalEvent(ACPI_OPERAND_OBJECT *ObjDesc)
Definition: exsystem.c:260
#define ACPI_MAX_SLEEP
Definition: acconfig.h:144
ACPI_STATUS AcpiExSystemWaitMutex(ACPI_MUTEX Mutex, UINT16 Timeout)
Definition: exsystem.c:120
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
#define AE_INFO
Definition: acoutput.h:230
#define ACPI_FUNCTION_ENTRY()
Definition: acoutput.h:484
ACPI_STATUS AcpiExSystemWaitSemaphore(ACPI_SEMAPHORE Semaphore, UINT16 Timeout)
Definition: exsystem.c:68
#define ACPI_DO_NOT_WAIT
Definition: actypes.h:502
ACPI_STATUS AcpiOsDeleteSemaphore(ACPI_SEMAPHORE Handle)
Definition: osl.c:378
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
ACPI_STATUS AcpiOsCreateSemaphore(UINT32 MaxUnits, UINT32 InitialUnits, ACPI_SEMAPHORE *OutHandle)
Definition: osl.c:352
ACPI_STATUS AcpiExSystemWaitEvent(ACPI_OPERAND_OBJECT *TimeDesc, ACPI_OPERAND_OBJECT *ObjDesc)
Definition: exsystem.c:294
ACPI_OBJECT_INTEGER Integer
Definition: acobject.h:517
ACPI_STATUS AcpiOsWaitSemaphore(ACPI_SEMAPHORE Handle, UINT32 Units, UINT16 Timeout)
Definition: osl.c:393
Status
Definition: gdiplustypes.h:24
#define ACPI_DB_EXEC
Definition: acoutput.h:165
void AcpiExExitInterpreter(void)
Definition: exutils.c:139
static ULONG Timeout
Definition: ping.c:61
void AcpiExEnterInterpreter(void)
Definition: exutils.c:91
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
unsigned short UINT16
#define ACPI_NO_UNIT_LIMIT
Definition: acpiosxf.h:67
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define ACPI_MUTEX
Definition: actypes.h:273
ACPI_OBJECT_COMMON_HEADER ACPI_SEMAPHORE OsSemaphore
Definition: acobject.h:178
ACPI_STATUS AcpiExSystemDoSleep(UINT64 HowLong)
Definition: exsystem.c:218
unsigned long long UINT64
#define AE_OK
Definition: acexcep.h:97
ACPI_STATUS AcpiExSystemDoStall(UINT32 HowLong)
Definition: exsystem.c:174