Home | History | Annotate | Line # | Download | only in acpiexec
aeinstall.c revision 1.1.1.1.4.1
      1 /******************************************************************************
      2  *
      3  * Module Name: aeinstall - Installation of operation region handlers
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2018, 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    ("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_FIXED_HARDWARE,
    111     ACPI_ADR_SPACE_USER_DEFINED1,
    112     ACPI_ADR_SPACE_USER_DEFINED2
    113 };
    114 
    115 
    116 /******************************************************************************
    117  *
    118  * FUNCTION:    AeRegionInit
    119  *
    120  * PARAMETERS:  Region init handler
    121  *
    122  * RETURN:      Status
    123  *
    124  * DESCRIPTION: Opregion init function.
    125  *
    126  *****************************************************************************/
    127 
    128 static ACPI_STATUS
    129 AeRegionInit (
    130     ACPI_HANDLE                 RegionHandle,
    131     UINT32                      Function,
    132     void                        *HandlerContext,
    133     void                        **RegionContext)
    134 {
    135 
    136     if (Function == ACPI_REGION_DEACTIVATE)
    137     {
    138         *RegionContext = NULL;
    139     }
    140     else
    141     {
    142         *RegionContext = RegionHandle;
    143     }
    144 
    145     return (AE_OK);
    146 }
    147 
    148 
    149 /******************************************************************************
    150  *
    151  * FUNCTION:    AeOverrideRegionHandlers
    152  *
    153  * PARAMETERS:  None
    154  *
    155  * RETURN:      None
    156  *
    157  * DESCRIPTION: Override the default region handlers for memory, i/o, and
    158  *              pci_config. Also install a handler for EC. This is part of
    159  *              the "install early handlers" functionality.
    160  *
    161  *****************************************************************************/
    162 
    163 void
    164 AeOverrideRegionHandlers (
    165     void)
    166 {
    167     UINT32                  i;
    168     ACPI_STATUS             Status;
    169 
    170     /*
    171      * Install handlers that will override the default handlers for some of
    172      * the space IDs.
    173      */
    174     for (i = 0; i < ACPI_ARRAY_LENGTH (DefaultSpaceIdList); i++)
    175     {
    176         /* Install handler at the root object */
    177 
    178         Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
    179             DefaultSpaceIdList[i], AeRegionHandler, AeRegionInit,
    180             &AeMyContext);
    181 
    182         if (ACPI_FAILURE (Status))
    183         {
    184             ACPI_EXCEPTION ((AE_INFO, Status,
    185                 "Could not install an OpRegion handler for %s space(%u)",
    186                 AcpiUtGetRegionName ((UINT8) DefaultSpaceIdList[i]),
    187                 DefaultSpaceIdList[i]));
    188         }
    189     }
    190 }
    191 
    192 
    193 /******************************************************************************
    194  *
    195  * FUNCTION:    AeInstallRegionHandlers
    196  *
    197  * PARAMETERS:  None
    198  *
    199  * RETURN:      None
    200  *
    201  * DESCRIPTION: Install handlers for the address spaces other than
    202  *              SystemMemory, SystemIO, and PCI_CONFIG.
    203  *
    204  *****************************************************************************/
    205 
    206 void
    207 AeInstallRegionHandlers (
    208     void)
    209 {
    210     UINT32                  i;
    211     ACPI_STATUS             Status;
    212 
    213 
    214     /*
    215      * Install handlers for some of the "device driver" address spaces
    216      * such as SMBus, etc.
    217      */
    218     for (i = 0; i < ACPI_ARRAY_LENGTH (SpaceIdList); i++)
    219     {
    220         /* Install handler at the root object */
    221 
    222         Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
    223             SpaceIdList[i], AeRegionHandler, AeRegionInit,
    224             &AeMyContext);
    225 
    226         if (ACPI_FAILURE (Status))
    227         {
    228             ACPI_EXCEPTION ((AE_INFO, Status,
    229                 "Could not install an OpRegion handler for %s space(%u)",
    230                 AcpiUtGetRegionName((UINT8) SpaceIdList[i]), SpaceIdList[i]));
    231             return;
    232         }
    233     }
    234 }
    235 
    236 
    237 /*******************************************************************************
    238  *
    239  * FUNCTION:    AeInstallDeviceHandlers
    240  *
    241  * PARAMETERS:  None
    242  *
    243  * RETURN:      Status
    244  *
    245  * DESCRIPTION: Install handlers for all EC and PCI devices in the namespace
    246  *
    247  ******************************************************************************/
    248 
    249 ACPI_STATUS
    250 AeInstallDeviceHandlers (
    251     void)
    252 {
    253 
    254     /* Find all Embedded Controller devices */
    255 
    256     AcpiGetDevices ("PNP0C09", AeInstallEcHandler, NULL, NULL);
    257 
    258     /* Install a PCI handler */
    259 
    260     AcpiGetDevices ("PNP0A08", AeInstallPciHandler, NULL, NULL);
    261     return (AE_OK);
    262 }
    263 
    264 
    265 /*******************************************************************************
    266  *
    267  * FUNCTION:    AeInstallEcHandler
    268  *
    269  * PARAMETERS:  ACPI_WALK_NAMESPACE callback
    270  *
    271  * RETURN:      Status
    272  *
    273  * DESCRIPTION: Walk entire namespace, install a handler for every EC
    274  *              device found.
    275  *
    276  ******************************************************************************/
    277 
    278 static ACPI_STATUS
    279 AeInstallEcHandler (
    280     ACPI_HANDLE             ObjHandle,
    281     UINT32                  Level,
    282     void                    *Context,
    283     void                    **ReturnValue)
    284 {
    285     ACPI_STATUS             Status;
    286 
    287 
    288     /* Install the handler for this EC device */
    289 
    290     Status = AcpiInstallAddressSpaceHandler (ObjHandle,
    291         ACPI_ADR_SPACE_EC, AeRegionHandler, AeRegionInit, &AeMyContext);
    292     if (ACPI_FAILURE (Status))
    293     {
    294         ACPI_EXCEPTION ((AE_INFO, Status,
    295             "Could not install an OpRegion handler for EC device (%p)",
    296             ObjHandle));
    297     }
    298 
    299     return (Status);
    300 }
    301 
    302 
    303 /*******************************************************************************
    304  *
    305  * FUNCTION:    AeInstallPciHandler
    306  *
    307  * PARAMETERS:  ACPI_WALK_NAMESPACE callback
    308  *
    309  * RETURN:      Status
    310  *
    311  * DESCRIPTION: Walk entire namespace, install a handler for every PCI
    312  *              device found.
    313  *
    314  ******************************************************************************/
    315 
    316 static ACPI_STATUS
    317 AeInstallPciHandler (
    318     ACPI_HANDLE             ObjHandle,
    319     UINT32                  Level,
    320     void                    *Context,
    321     void                    **ReturnValue)
    322 {
    323     ACPI_STATUS             Status;
    324 
    325 
    326     /* Install memory and I/O handlers for the PCI device */
    327 
    328     Status = AcpiInstallAddressSpaceHandler (ObjHandle,
    329         ACPI_ADR_SPACE_SYSTEM_IO, AeRegionHandler, AeRegionInit,
    330         &AeMyContext);
    331     if (ACPI_FAILURE (Status))
    332     {
    333         ACPI_EXCEPTION ((AE_INFO, Status,
    334             "Could not install an OpRegion handler for PCI device (%p)",
    335             ObjHandle));
    336     }
    337 
    338     Status = AcpiInstallAddressSpaceHandler (ObjHandle,
    339         ACPI_ADR_SPACE_SYSTEM_MEMORY, AeRegionHandler, AeRegionInit,
    340         &AeMyContext);
    341     if (ACPI_FAILURE (Status))
    342     {
    343         ACPI_EXCEPTION ((AE_INFO, Status,
    344             "Could not install an OpRegion handler for PCI device (%p)",
    345             ObjHandle));
    346     }
    347 
    348     return (AE_CTRL_TERMINATE);
    349 }
    350