1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
/******************************************************************************
*
* Module Name: amsystem - Interface to OS services
* $Revision: 51 $
*
*****************************************************************************/
/*
* Copyright (C) 2000 R. Byron Moore
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "acpi.h"
#include "acinterp.h"
#include "acnamesp.h"
#include "achware.h"
#include "acevents.h"
#define _COMPONENT INTERPRETER
MODULE_NAME ("amsystem")
/*******************************************************************************
*
* FUNCTION: Acpi_aml_system_thread_id
*
* PARAMETERS: None
*
* RETURN: Current Thread ID (for this implementation a 1 is returned)
*
* DESCRIPTION: An invocation is identified by its Thread ID. In a single
* threaded OS the Thread ID is undefined so a 1 will be
* returned.
*
******************************************************************************/
u16
acpi_aml_system_thread_id (void)
{
return (1);
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_system_wait_semaphore
*
* PARAMETERS: Semaphore - OSD semaphore to wait on
* Timeout - Max time to wait
*
* RETURN: Status
*
* DESCRIPTION: Implements a semaphore wait with a check to see if the
* semaphore is available immediately. If it is not, the
* interpreter is released.
*
******************************************************************************/
ACPI_STATUS
acpi_aml_system_wait_semaphore (
ACPI_HANDLE semaphore,
u32 timeout)
{
ACPI_STATUS status;
status = acpi_os_wait_semaphore (semaphore, 1, 0);
if (ACPI_SUCCESS (status)) {
return (status);
}
if (status == AE_TIME) {
/* We must wait, so unlock the interpreter */
acpi_aml_exit_interpreter ();
status = acpi_os_wait_semaphore (semaphore, 1, timeout);
/* Reacquire the interpreter */
acpi_aml_enter_interpreter ();
}
return (status);
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_system_do_stall
*
* PARAMETERS: How_long - The amount of time to stall
*
* RETURN: None
*
* DESCRIPTION: Suspend running thread for specified amount of time.
*
******************************************************************************/
void
acpi_aml_system_do_stall (
u32 how_long)
{
if (how_long > 1000) /* 1 millisecond */ {
/* Since this thread will sleep, we must release the interpreter */
acpi_aml_exit_interpreter ();
acpi_os_sleep_usec (how_long);
/* And now we must get the interpreter again */
acpi_aml_enter_interpreter ();
}
else {
acpi_os_sleep_usec (how_long);
}
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_system_do_suspend
*
* PARAMETERS: How_long - The amount of time to suspend
*
* RETURN: None
*
* DESCRIPTION: Suspend running thread for specified amount of time.
*
******************************************************************************/
void
acpi_aml_system_do_suspend (
u32 how_long)
{
/* Since this thread will sleep, we must release the interpreter */
acpi_aml_exit_interpreter ();
acpi_os_sleep ((u16) (how_long / (u32) 1000),
(u16) (how_long % (u32) 1000));
/* And now we must get the interpreter again */
acpi_aml_enter_interpreter ();
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_system_acquire_mutex
*
* PARAMETERS: *Time_desc - The 'time to delay' object descriptor
* *Obj_desc - The object descriptor for this op
*
* RETURN: Status
*
* DESCRIPTION: Provides an access point to perform synchronization operations
* within the AML. This function will cause a lock to be generated
* for the Mutex pointed to by Obj_desc.
*
******************************************************************************/
ACPI_STATUS
acpi_aml_system_acquire_mutex (
ACPI_OPERAND_OBJECT *time_desc,
ACPI_OPERAND_OBJECT *obj_desc)
{
ACPI_STATUS status = AE_OK;
if (!obj_desc) {
return (AE_BAD_PARAMETER);
}
/*
* Support for the _GL_ Mutex object -- go get the global lock
*/
if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
status = acpi_ev_acquire_global_lock ();
return (status);
}
status = acpi_aml_system_wait_semaphore (obj_desc->mutex.semaphore,
time_desc->number.value);
return (status);
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_system_release_mutex
*
* PARAMETERS: *Obj_desc - The object descriptor for this op
*
* RETURN: Status
*
* DESCRIPTION: Provides an access point to perform synchronization operations
* within the AML. This operation is a request to release a
* previously acquired Mutex. If the Mutex variable is set then
* it will be decremented.
*
******************************************************************************/
ACPI_STATUS
acpi_aml_system_release_mutex (
ACPI_OPERAND_OBJECT *obj_desc)
{
ACPI_STATUS status = AE_OK;
if (!obj_desc) {
return (AE_BAD_PARAMETER);
}
/*
* Support for the _GL_ Mutex object -- release the global lock
*/
if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
acpi_ev_release_global_lock ();
return (AE_OK);
}
status = acpi_os_signal_semaphore (obj_desc->mutex.semaphore, 1);
return (status);
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_system_signal_event
*
* PARAMETERS: *Obj_desc - The object descriptor for this op
*
* RETURN: AE_OK
*
* DESCRIPTION: Provides an access point to perform synchronization operations
* within the AML.
*
******************************************************************************/
ACPI_STATUS
acpi_aml_system_signal_event (
ACPI_OPERAND_OBJECT *obj_desc)
{
ACPI_STATUS status = AE_OK;
if (obj_desc) {
status = acpi_os_signal_semaphore (obj_desc->event.semaphore, 1);
}
return (status);
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_system_wait_event
*
* PARAMETERS: *Time_desc - The 'time to delay' object descriptor
* *Obj_desc - The object descriptor for this op
*
* RETURN: Status
*
* DESCRIPTION: Provides an access point to perform synchronization operations
* within the AML. This operation is a request to wait for an
* event.
*
******************************************************************************/
ACPI_STATUS
acpi_aml_system_wait_event (
ACPI_OPERAND_OBJECT *time_desc,
ACPI_OPERAND_OBJECT *obj_desc)
{
ACPI_STATUS status = AE_OK;
if (obj_desc) {
status = acpi_aml_system_wait_semaphore (obj_desc->event.semaphore,
time_desc->number.value);
}
return (status);
}
/*******************************************************************************
*
* FUNCTION: Acpi_aml_system_reset_event
*
* PARAMETERS: *Obj_desc - The object descriptor for this op
*
* RETURN: Status
*
* DESCRIPTION: Provides an access point to perform synchronization operations
* within the AML.
*
******************************************************************************/
ACPI_STATUS
acpi_aml_system_reset_event (
ACPI_OPERAND_OBJECT *obj_desc)
{
ACPI_STATUS status = AE_OK;
void *temp_semaphore;
/*
* We are going to simply delete the existing semaphore and
* create a new one!
*/
status = acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT, 0, &temp_semaphore);
if (ACPI_SUCCESS (status)) {
acpi_os_delete_semaphore (obj_desc->mutex.semaphore);
obj_desc->mutex.semaphore = temp_semaphore;
}
return (status);
}
|