aetests.c revision 1.1 1 /******************************************************************************
2 *
3 * Module Name: aetests - Miscellaneous tests for ACPICA public interfaces
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2017, 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 "aecommon.h"
45
46 #define _COMPONENT ACPI_TOOLS
47 ACPI_MODULE_NAME ("aetests")
48
49 /* Local prototypes */
50
51 static void
52 AeMutexInterfaces (
53 void);
54
55 static void
56 AeHardwareInterfaces (
57 void);
58
59 static void
60 AeTestSleepData (
61 void);
62
63
64 /******************************************************************************
65 *
66 * FUNCTION: AeMiscellaneousTests
67 *
68 * DESCRIPTION: Various ACPICA validation tests.
69 *
70 *****************************************************************************/
71
72 void
73 AeMiscellaneousTests (
74 void)
75 {
76 ACPI_BUFFER ReturnBuf;
77 char Buffer[32];
78 ACPI_STATUS Status;
79 ACPI_STATISTICS Stats;
80 ACPI_HANDLE Handle;
81
82 #if (!ACPI_REDUCED_HARDWARE)
83 UINT32 Temp;
84 UINT32 LockHandle1;
85 UINT32 LockHandle2;
86 ACPI_VENDOR_UUID Uuid = {0, {ACPI_INIT_UUID (0,0,0,0,0,0,0,0,0,0,0)}};
87 #endif /* !ACPI_REDUCED_HARDWARE */
88
89
90 Status = AcpiGetHandle (NULL, "\\", &Handle);
91 ACPI_CHECK_OK (AcpiGetHandle, Status);
92
93 if (AcpiGbl_DoInterfaceTests)
94 {
95 /*
96 * Tests for AcpiLoadTable and AcpiUnloadParentTable
97 */
98
99 /* Attempt unload of DSDT, should fail */
100
101 Status = AcpiGetHandle (NULL, "\\_SB_", &Handle);
102 ACPI_CHECK_OK (AcpiGetHandle, Status);
103
104 Status = AcpiUnloadParentTable (Handle);
105 ACPI_CHECK_STATUS (AcpiUnloadParentTable, Status, AE_TYPE);
106
107 /* Load and unload SSDT4 */
108
109 Status = AcpiLoadTable ((ACPI_TABLE_HEADER *) Ssdt4Code);
110 ACPI_CHECK_OK (AcpiLoadTable, Status);
111
112 Status = AcpiGetHandle (NULL, "\\_T96", &Handle);
113 ACPI_CHECK_OK (AcpiGetHandle, Status);
114
115 Status = AcpiUnloadParentTable (Handle);
116 ACPI_CHECK_OK (AcpiUnloadParentTable, Status);
117
118 /* Re-load SSDT4 */
119
120 Status = AcpiLoadTable ((ACPI_TABLE_HEADER *) Ssdt4Code);
121 ACPI_CHECK_OK (AcpiLoadTable, Status);
122
123 /* Unload and re-load SSDT2 (SSDT2 is in the XSDT) */
124
125 Status = AcpiGetHandle (NULL, "\\_T99", &Handle);
126 ACPI_CHECK_OK (AcpiGetHandle, Status);
127
128 Status = AcpiUnloadParentTable (Handle);
129 ACPI_CHECK_OK (AcpiUnloadParentTable, Status);
130
131 Status = AcpiLoadTable ((ACPI_TABLE_HEADER *) Ssdt2Code);
132 ACPI_CHECK_OK (AcpiLoadTable, Status);
133
134 /* Load OEM9 table (causes table override) */
135
136 Status = AcpiLoadTable ((ACPI_TABLE_HEADER *) Ssdt3Code);
137 ACPI_CHECK_OK (AcpiLoadTable, Status);
138 }
139
140 AeHardwareInterfaces ();
141 AeGenericRegisters ();
142 AeSetupConfiguration (Ssdt3Code);
143
144 AeTestBufferArgument();
145 AeTestPackageArgument ();
146 AeMutexInterfaces ();
147 AeTestSleepData ();
148
149 /* Test _OSI install/remove */
150
151 Status = AcpiInstallInterface ("");
152 ACPI_CHECK_STATUS (AcpiInstallInterface, Status, AE_BAD_PARAMETER);
153
154 Status = AcpiInstallInterface ("TestString");
155 ACPI_CHECK_OK (AcpiInstallInterface, Status);
156
157 Status = AcpiInstallInterface ("TestString");
158 ACPI_CHECK_STATUS (AcpiInstallInterface, Status, AE_ALREADY_EXISTS);
159
160 Status = AcpiRemoveInterface ("Windows 2006");
161 ACPI_CHECK_OK (AcpiRemoveInterface, Status);
162
163 Status = AcpiRemoveInterface ("TestString");
164 ACPI_CHECK_OK (AcpiRemoveInterface, Status);
165
166 Status = AcpiRemoveInterface ("XXXXXX");
167 ACPI_CHECK_STATUS (AcpiRemoveInterface, Status, AE_NOT_EXIST);
168
169 Status = AcpiInstallInterface ("AnotherTestString");
170 ACPI_CHECK_OK (AcpiInstallInterface, Status);
171
172 /* Test _OSI execution */
173
174 Status = ExecuteOSI ("Extended Address Space Descriptor", ACPI_UINT64_MAX);
175 ACPI_CHECK_OK (ExecuteOSI, Status);
176
177 Status = ExecuteOSI ("Windows 2001", ACPI_UINT64_MAX);
178 ACPI_CHECK_OK (ExecuteOSI, Status);
179
180 Status = ExecuteOSI ("MichiganTerminalSystem", 0);
181 ACPI_CHECK_OK (ExecuteOSI, Status);
182
183
184 ReturnBuf.Length = 32;
185 ReturnBuf.Pointer = Buffer;
186
187 Status = AcpiGetName (ACPI_ROOT_OBJECT,
188 ACPI_FULL_PATHNAME_NO_TRAILING, &ReturnBuf);
189 ACPI_CHECK_OK (AcpiGetName, Status);
190
191 /* Get Devices */
192
193 Status = AcpiGetDevices (NULL, AeGetDevices, NULL, NULL);
194 ACPI_CHECK_OK (AcpiGetDevices, Status);
195
196 Status = AcpiGetStatistics (&Stats);
197 ACPI_CHECK_OK (AcpiGetStatistics, Status);
198
199
200 #if (!ACPI_REDUCED_HARDWARE)
201
202 Status = AcpiInstallGlobalEventHandler (AeGlobalEventHandler, NULL);
203 ACPI_CHECK_OK (AcpiInstallGlobalEventHandler, Status);
204
205 /* If Hardware Reduced flag is set, we are all done */
206
207 if (AcpiGbl_ReducedHardware)
208 {
209 return;
210 }
211
212 Status = AcpiEnableEvent (ACPI_EVENT_GLOBAL, 0);
213 ACPI_CHECK_OK (AcpiEnableEvent, Status);
214
215 /*
216 * GPEs: Handlers, enable/disable, etc.
217 */
218 Status = AcpiInstallGpeHandler (NULL, 0,
219 ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
220 ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
221
222 Status = AcpiEnableGpe (NULL, 0);
223 ACPI_CHECK_OK (AcpiEnableGpe, Status);
224
225 Status = AcpiRemoveGpeHandler (NULL, 0, AeGpeHandler);
226 ACPI_CHECK_OK (AcpiRemoveGpeHandler, Status);
227
228 Status = AcpiInstallGpeHandler (NULL, 0,
229 ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
230 ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
231
232 Status = AcpiEnableGpe (NULL, 0);
233 ACPI_CHECK_OK (AcpiEnableGpe, Status);
234
235 Status = AcpiSetGpe (NULL, 0, ACPI_GPE_DISABLE);
236 ACPI_CHECK_OK (AcpiSetGpe, Status);
237
238 Status = AcpiSetGpe (NULL, 0, ACPI_GPE_ENABLE);
239 ACPI_CHECK_OK (AcpiSetGpe, Status);
240
241
242 Status = AcpiInstallGpeHandler (NULL, 1,
243 ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL);
244 ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
245
246 Status = AcpiEnableGpe (NULL, 1);
247 ACPI_CHECK_OK (AcpiEnableGpe, Status);
248
249
250 Status = AcpiInstallGpeHandler (NULL, 2,
251 ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
252 ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
253
254 Status = AcpiEnableGpe (NULL, 2);
255 ACPI_CHECK_OK (AcpiEnableGpe, Status);
256
257
258 Status = AcpiInstallGpeHandler (NULL, 3,
259 ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL);
260 ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
261
262 Status = AcpiInstallGpeHandler (NULL, 4,
263 ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
264 ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
265
266 Status = AcpiInstallGpeHandler (NULL, 5,
267 ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL);
268 ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
269
270 Status = AcpiGetHandle (NULL, "\\_SB", &Handle);
271 ACPI_CHECK_OK (AcpiGetHandle, Status);
272
273 Status = AcpiSetupGpeForWake (Handle, NULL, 5);
274 ACPI_CHECK_OK (AcpiSetupGpeForWake, Status);
275
276 Status = AcpiSetGpeWakeMask (NULL, 5, ACPI_GPE_ENABLE);
277 ACPI_CHECK_OK (AcpiSetGpeWakeMask, Status);
278
279 Status = AcpiSetupGpeForWake (Handle, NULL, 6);
280 ACPI_CHECK_OK (AcpiSetupGpeForWake, Status);
281
282 Status = AcpiSetupGpeForWake (ACPI_ROOT_OBJECT, NULL, 6);
283 ACPI_CHECK_OK (AcpiSetupGpeForWake, Status);
284
285 Status = AcpiSetupGpeForWake (Handle, NULL, 9);
286 ACPI_CHECK_OK (AcpiSetupGpeForWake, Status);
287
288 Status = AcpiInstallGpeHandler (NULL, 0x19,
289 ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
290 ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
291
292 Status = AcpiEnableGpe (NULL, 0x19);
293 ACPI_CHECK_OK (AcpiEnableGpe, Status);
294
295
296 /* GPE block 1 */
297
298 Status = AcpiInstallGpeHandler (NULL, 101,
299 ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
300 ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
301
302 Status = AcpiEnableGpe (NULL, 101);
303 ACPI_CHECK_OK (AcpiEnableGpe, Status);
304
305 Status = AcpiDisableGpe (NULL, 101);
306 ACPI_CHECK_OK (AcpiDisableGpe, Status);
307
308 AfInstallGpeBlock ();
309
310 /* Here is where the GPEs are actually "enabled" */
311
312 Status = AcpiUpdateAllGpes ();
313 ACPI_CHECK_OK (AcpiUpdateAllGpes, Status);
314
315 Status = AcpiGetHandle (NULL, "RSRC", &Handle);
316 if (ACPI_SUCCESS (Status))
317 {
318 ReturnBuf.Length = ACPI_ALLOCATE_BUFFER;
319
320 Status = AcpiGetVendorResource (Handle, "_CRS", &Uuid, &ReturnBuf);
321 if (ACPI_SUCCESS (Status))
322 {
323 AcpiOsFree (ReturnBuf.Pointer);
324 }
325 }
326
327 /* Test global lock */
328
329 Status = AcpiAcquireGlobalLock (0xFFFF, &LockHandle1);
330 ACPI_CHECK_OK (AcpiAcquireGlobalLock, Status);
331
332 Status = AcpiAcquireGlobalLock (0x5, &LockHandle2);
333 ACPI_CHECK_OK (AcpiAcquireGlobalLock, Status);
334
335 Status = AcpiReleaseGlobalLock (LockHandle1);
336 ACPI_CHECK_OK (AcpiReleaseGlobalLock, Status);
337
338 Status = AcpiReleaseGlobalLock (LockHandle2);
339 ACPI_CHECK_OK (AcpiReleaseGlobalLock, Status);
340
341 /* Test timer interfaces */
342
343 Status = AcpiGetTimerResolution (&Temp);
344 ACPI_CHECK_OK (AcpiGetTimerResolution, Status);
345
346 Status = AcpiGetTimer (&Temp);
347 ACPI_CHECK_OK (AcpiGetTimer, Status);
348
349 Status = AcpiGetTimerDuration (0x1000, 0x2000, &Temp);
350 ACPI_CHECK_OK (AcpiGetTimerDuration, Status);
351
352
353 #endif /* !ACPI_REDUCED_HARDWARE */
354 }
355
356
357 /******************************************************************************
358 *
359 * FUNCTION: AeMutexInterfaces
360 *
361 * DESCRIPTION: Exercise the AML mutex access interfaces
362 *
363 *****************************************************************************/
364
365 static void
366 AeMutexInterfaces (
367 void)
368 {
369 ACPI_STATUS Status;
370 ACPI_HANDLE MutexHandle;
371
372
373 /* Get a handle to an AML mutex */
374
375 Status = AcpiGetHandle (NULL, "\\MTX1", &MutexHandle);
376 if (Status == AE_NOT_FOUND)
377 {
378 return;
379 }
380
381 ACPI_CHECK_OK (AcpiGetHandle, Status);
382 if (ACPI_FAILURE (Status))
383 {
384 return;
385 }
386
387 /* Acquire the mutex */
388
389 Status = AcpiAcquireMutex (NULL, "\\MTX1", 0xFFFF);
390 ACPI_CHECK_OK (AcpiAcquireMutex, Status);
391 if (ACPI_FAILURE (Status))
392 {
393 return;
394 }
395
396 /* Release mutex with different parameters */
397
398 Status = AcpiReleaseMutex (MutexHandle, NULL);
399 ACPI_CHECK_OK (AcpiReleaseMutex, Status);
400 }
401
402
403 /******************************************************************************
404 *
405 * FUNCTION: AeHardwareInterfaces
406 *
407 * DESCRIPTION: Call various hardware support interfaces
408 *
409 *****************************************************************************/
410
411 static void
412 AeHardwareInterfaces (
413 void)
414 {
415 #if (!ACPI_REDUCED_HARDWARE)
416
417 ACPI_STATUS Status;
418 UINT32 Value;
419
420
421 /* If Hardware Reduced flag is set, we are all done */
422
423 if (AcpiGbl_ReducedHardware)
424 {
425 return;
426 }
427
428 Status = AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS, 1);
429 ACPI_CHECK_OK (AcpiWriteBitRegister, Status);
430
431 Status = AcpiWriteBitRegister (ACPI_BITREG_GLOBAL_LOCK_ENABLE, 1);
432 ACPI_CHECK_OK (AcpiWriteBitRegister, Status);
433
434 Status = AcpiWriteBitRegister (ACPI_BITREG_SLEEP_ENABLE, 1);
435 ACPI_CHECK_OK (AcpiWriteBitRegister, Status);
436
437 Status = AcpiWriteBitRegister (ACPI_BITREG_ARB_DISABLE, 1);
438 ACPI_CHECK_OK (AcpiWriteBitRegister, Status);
439
440
441 Status = AcpiReadBitRegister (ACPI_BITREG_WAKE_STATUS, &Value);
442 ACPI_CHECK_OK (AcpiReadBitRegister, Status);
443
444 Status = AcpiReadBitRegister (ACPI_BITREG_GLOBAL_LOCK_ENABLE, &Value);
445 ACPI_CHECK_OK (AcpiReadBitRegister, Status);
446
447 Status = AcpiReadBitRegister (ACPI_BITREG_SLEEP_ENABLE, &Value);
448 ACPI_CHECK_OK (AcpiReadBitRegister, Status);
449
450 Status = AcpiReadBitRegister (ACPI_BITREG_ARB_DISABLE, &Value);
451 ACPI_CHECK_OK (AcpiReadBitRegister, Status);
452
453 #endif /* !ACPI_REDUCED_HARDWARE */
454 }
455
456
457 /******************************************************************************
458 *
459 * FUNCTION: AeTestSleepData
460 *
461 * DESCRIPTION: Exercise the sleep/wake support (_S0, _S1, etc.)
462 *
463 *****************************************************************************/
464
465 static void
466 AeTestSleepData (
467 void)
468 {
469 int State;
470 UINT8 TypeA;
471 UINT8 TypeB;
472 ACPI_STATUS Status;
473
474
475 /* Attempt to get sleep data for all known sleep states */
476
477 for (State = ACPI_STATE_S0; State <= ACPI_S_STATES_MAX; State++)
478 {
479 Status = AcpiGetSleepTypeData ((UINT8) State, &TypeA, &TypeB);
480
481 /* All sleep methods are optional */
482
483 if (Status != AE_NOT_FOUND)
484 {
485 ACPI_CHECK_OK (AcpiGetSleepTypeData, Status);
486 }
487 }
488 }
489