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