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