Home | History | Annotate | Line # | Download | only in acpiexec
aeinstall.c revision 1.1.1.5.2.1
      1 /******************************************************************************
      2  *
      3  * Module Name: aeinstall - Installation of operation region handlers
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2021, 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    ("aeinstall")
     48 
     49 
     50 static ACPI_STATUS
     51 AeRegionInit (
     52     ACPI_HANDLE             RegionHandle,
     53     UINT32                  Function,
     54     void                    *HandlerContext,
     55     void                    **RegionContext);
     56 
     57 static ACPI_STATUS
     58 AeInstallEcHandler (
     59     ACPI_HANDLE             ObjHandle,
     60     UINT32                  Level,
     61     void                    *Context,
     62     void                    **ReturnValue);
     63 
     64 static ACPI_STATUS
     65 AeInstallPciHandler (
     66     ACPI_HANDLE             ObjHandle,
     67     UINT32                  Level,
     68     void                    *Context,
     69     void                    **ReturnValue);
     70 
     71 
     72 BOOLEAN                     AcpiGbl_DisplayRegionAccess = FALSE;
     73 ACPI_CONNECTION_INFO        AeMyContext;
     74 
     75 
     76 /*
     77  * We will override some of the default region handlers, especially
     78  * the SystemMemory handler, which must be implemented locally.
     79  * These handlers are installed "early" - before any _REG methods
     80  * are executed - since they are special in the sense that the ACPI spec
     81  * declares that they must "always be available". Cannot override the
     82  * DataTable region handler either -- needed for test execution.
     83  *
     84  * NOTE: The local region handler will simulate access to these address
     85  * spaces by creating a memory buffer behind each operation region.
     86  */
     87 static ACPI_ADR_SPACE_TYPE  DefaultSpaceIdList[] =
     88 {
     89     ACPI_ADR_SPACE_SYSTEM_MEMORY,
     90     ACPI_ADR_SPACE_SYSTEM_IO,
     91     ACPI_ADR_SPACE_PCI_CONFIG,
     92     ACPI_ADR_SPACE_EC
     93 };
     94 
     95 /*
     96  * We will install handlers for some of the various address space IDs.
     97  * Test one user-defined address space (used by aslts).
     98  */
     99 #define ACPI_ADR_SPACE_USER_DEFINED1        0x80
    100 #define ACPI_ADR_SPACE_USER_DEFINED2        0xE4
    101 
    102 static ACPI_ADR_SPACE_TYPE  SpaceIdList[] =
    103 {
    104     ACPI_ADR_SPACE_SMBUS,
    105     ACPI_ADR_SPACE_CMOS,
    106     ACPI_ADR_SPACE_PCI_BAR_TARGET,
    107     ACPI_ADR_SPACE_IPMI,
    108     ACPI_ADR_SPACE_GPIO,
    109     ACPI_ADR_SPACE_GSBUS,
    110     ACPI_ADR_SPACE_PLATFORM_COMM,
    111     ACPI_ADR_SPACE_PLATFORM_RT,
    112     ACPI_ADR_SPACE_FIXED_HARDWARE,
    113     ACPI_ADR_SPACE_USER_DEFINED1,
    114     ACPI_ADR_SPACE_USER_DEFINED2
    115 };
    116 
    117 
    118 /******************************************************************************
    119  *
    120  * FUNCTION:    AeRegionInit
    121  *
    122  * PARAMETERS:  Region init handler
    123  *
    124  * RETURN:      Status
    125  *
    126  * DESCRIPTION: Opregion init function.
    127  *
    128  *****************************************************************************/
    129 
    130 static ACPI_STATUS
    131 AeRegionInit (
    132     ACPI_HANDLE                 RegionHandle,
    133     UINT32                      Function,
    134     void                        *HandlerContext,
    135     void                        **RegionContext)
    136 {
    137 
    138     if (Function == ACPI_REGION_DEACTIVATE)
    139     {
    140         *RegionContext = NULL;
    141     }
    142     else
    143     {
    144         *RegionContext = RegionHandle;
    145     }
    146 
    147     return (AE_OK);
    148 }
    149 
    150 
    151 /******************************************************************************
    152  *
    153  * FUNCTION:    AeOverrideRegionHandlers
    154  *
    155  * PARAMETERS:  None
    156  *
    157  * RETURN:      None
    158  *
    159  * DESCRIPTION: Override the default region handlers for memory, i/o, and
    160  *              pci_config. Also install a handler for EC. This is part of
    161  *              the "install early handlers" functionality.
    162  *
    163  *****************************************************************************/
    164 
    165 void
    166 AeOverrideRegionHandlers (
    167     void)
    168 {
    169     UINT32                  i;
    170     ACPI_STATUS             Status;
    171 
    172     /*
    173      * Install handlers that will override the default handlers for some of
    174      * the space IDs.
    175      */
    176     for (i = 0; i < ACPI_ARRAY_LENGTH (DefaultSpaceIdList); i++)
    177     {
    178         /* Install handler at the root object */
    179 
    180         Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
    181             DefaultSpaceIdList[i], AeRegionHandler, AeRegionInit,
    182             &AeMyContext);
    183 
    184         if (ACPI_FAILURE (Status))
    185         {
    186             ACPI_EXCEPTION ((AE_INFO, Status,
    187                 "Could not install an OpRegion handler for %s space(%u)",
    188                 AcpiUtGetRegionName ((UINT8) DefaultSpaceIdList[i]),
    189                 DefaultSpaceIdList[i]));
    190         }
    191     }
    192 }
    193 
    194 
    195 /******************************************************************************
    196  *
    197  * FUNCTION:    AeInstallRegionHandlers
    198  *
    199  * PARAMETERS:  None
    200  *
    201  * RETURN:      None
    202  *
    203  * DESCRIPTION: Install handlers for the address spaces other than
    204  *              SystemMemory, SystemIO, and PCI_CONFIG.
    205  *
    206  *****************************************************************************/
    207 
    208 void
    209 AeInstallRegionHandlers (
    210     void)
    211 {
    212     UINT32                  i;
    213     ACPI_STATUS             Status;
    214 
    215 
    216     /*
    217      * Install handlers for some of the "device driver" address spaces
    218      * such as SMBus, etc.
    219      */
    220     for (i = 0; i < ACPI_ARRAY_LENGTH (SpaceIdList); i++)
    221     {
    222         /* Install handler at the root object */
    223 
    224         Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
    225             SpaceIdList[i], AeRegionHandler, AeRegionInit,
    226             &AeMyContext);
    227 
    228         if (ACPI_FAILURE (Status))
    229         {
    230             ACPI_EXCEPTION ((AE_INFO, Status,
    231                 "Could not install an OpRegion handler for %s space(%u)",
    232                 AcpiUtGetRegionName((UINT8) SpaceIdList[i]), SpaceIdList[i]));
    233             return;
    234         }
    235     }
    236 }
    237 
    238 
    239 /*******************************************************************************
    240  *
    241  * FUNCTION:    AeInstallDeviceHandlers
    242  *
    243  * PARAMETERS:  None
    244  *
    245  * RETURN:      Status
    246  *
    247  * DESCRIPTION: Install handlers for all EC and PCI devices in the namespace
    248  *
    249  ******************************************************************************/
    250 
    251 ACPI_STATUS
    252 AeInstallDeviceHandlers (
    253     void)
    254 {
    255 
    256     /* Find all Embedded Controller devices */
    257 
    258     AcpiGetDevices ("PNP0C09", AeInstallEcHandler, NULL, NULL);
    259 
    260     /* Install a PCI handler */
    261 
    262     AcpiGetDevices ("PNP0A08", AeInstallPciHandler, NULL, NULL);
    263     return (AE_OK);
    264 }
    265 
    266 
    267 /*******************************************************************************
    268  *
    269  * FUNCTION:    AeInstallEcHandler
    270  *
    271  * PARAMETERS:  ACPI_WALK_NAMESPACE callback
    272  *
    273  * RETURN:      Status
    274  *
    275  * DESCRIPTION: Walk entire namespace, install a handler for every EC
    276  *              device found.
    277  *
    278  ******************************************************************************/
    279 
    280 static ACPI_STATUS
    281 AeInstallEcHandler (
    282     ACPI_HANDLE             ObjHandle,
    283     UINT32                  Level,
    284     void                    *Context,
    285     void                    **ReturnValue)
    286 {
    287     ACPI_STATUS             Status;
    288 
    289 
    290     /* Install the handler for this EC device */
    291 
    292     Status = AcpiInstallAddressSpaceHandler (ObjHandle,
    293         ACPI_ADR_SPACE_EC, AeRegionHandler, AeRegionInit, &AeMyContext);
    294     if (ACPI_FAILURE (Status))
    295     {
    296         ACPI_EXCEPTION ((AE_INFO, Status,
    297             "Could not install an OpRegion handler for EC device (%p)",
    298             ObjHandle));
    299     }
    300 
    301     return (Status);
    302 }
    303 
    304 
    305 /*******************************************************************************
    306  *
    307  * FUNCTION:    AeInstallPciHandler
    308  *
    309  * PARAMETERS:  ACPI_WALK_NAMESPACE callback
    310  *
    311  * RETURN:      Status
    312  *
    313  * DESCRIPTION: Walk entire namespace, install a handler for every PCI
    314  *              device found.
    315  *
    316  ******************************************************************************/
    317 
    318 static ACPI_STATUS
    319 AeInstallPciHandler (
    320     ACPI_HANDLE             ObjHandle,
    321     UINT32                  Level,
    322     void                    *Context,
    323     void                    **ReturnValue)
    324 {
    325     ACPI_STATUS             Status;
    326 
    327 
    328     /* Install memory and I/O handlers for the PCI device */
    329 
    330     Status = AcpiInstallAddressSpaceHandler (ObjHandle,
    331         ACPI_ADR_SPACE_SYSTEM_IO, AeRegionHandler, AeRegionInit,
    332         &AeMyContext);
    333     if (ACPI_FAILURE (Status))
    334     {
    335         ACPI_EXCEPTION ((AE_INFO, Status,
    336             "Could not install an OpRegion handler for PCI device (%p)",
    337             ObjHandle));
    338     }
    339 
    340     Status = AcpiInstallAddressSpaceHandler (ObjHandle,
    341         ACPI_ADR_SPACE_SYSTEM_MEMORY, AeRegionHandler, AeRegionInit,
    342         &AeMyContext);
    343     if (ACPI_FAILURE (Status))
    344     {
    345         ACPI_EXCEPTION ((AE_INFO, Status,
    346             "Could not install an OpRegion handler for PCI device (%p)",
    347             ObjHandle));
    348     }
    349 
    350     return (AE_CTRL_TERMINATE);
    351 }
    352