Home | History | Annotate | Line # | Download | only in acpiexec
aeinstall.c revision 1.1.1.1
      1  1.1  christos /******************************************************************************
      2  1.1  christos  *
      3  1.1  christos  * Module Name: aeinstall - Installation of operation region handlers
      4  1.1  christos  *
      5  1.1  christos  *****************************************************************************/
      6  1.1  christos 
      7  1.1  christos /*
      8  1.1  christos  * Copyright (C) 2000 - 2017, Intel Corp.
      9  1.1  christos  * All rights reserved.
     10  1.1  christos  *
     11  1.1  christos  * Redistribution and use in source and binary forms, with or without
     12  1.1  christos  * modification, are permitted provided that the following conditions
     13  1.1  christos  * are met:
     14  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15  1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16  1.1  christos  *    without modification.
     17  1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21  1.1  christos  *    binary redistribution.
     22  1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24  1.1  christos  *    from this software without specific prior written permission.
     25  1.1  christos  *
     26  1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27  1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1  christos  * Software Foundation.
     29  1.1  christos  *
     30  1.1  christos  * NO WARRANTY
     31  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1  christos  */
     43  1.1  christos 
     44  1.1  christos #include "aecommon.h"
     45  1.1  christos 
     46  1.1  christos #define _COMPONENT          ACPI_TOOLS
     47  1.1  christos         ACPI_MODULE_NAME    ("aeinstall")
     48  1.1  christos 
     49  1.1  christos 
     50  1.1  christos static ACPI_STATUS
     51  1.1  christos AeRegionInit (
     52  1.1  christos     ACPI_HANDLE             RegionHandle,
     53  1.1  christos     UINT32                  Function,
     54  1.1  christos     void                    *HandlerContext,
     55  1.1  christos     void                    **RegionContext);
     56  1.1  christos 
     57  1.1  christos static ACPI_STATUS
     58  1.1  christos AeInstallEcHandler (
     59  1.1  christos     ACPI_HANDLE             ObjHandle,
     60  1.1  christos     UINT32                  Level,
     61  1.1  christos     void                    *Context,
     62  1.1  christos     void                    **ReturnValue);
     63  1.1  christos 
     64  1.1  christos static ACPI_STATUS
     65  1.1  christos AeInstallPciHandler (
     66  1.1  christos     ACPI_HANDLE             ObjHandle,
     67  1.1  christos     UINT32                  Level,
     68  1.1  christos     void                    *Context,
     69  1.1  christos     void                    **ReturnValue);
     70  1.1  christos 
     71  1.1  christos 
     72  1.1  christos BOOLEAN                     AcpiGbl_DisplayRegionAccess = FALSE;
     73  1.1  christos ACPI_CONNECTION_INFO        AeMyContext;
     74  1.1  christos 
     75  1.1  christos 
     76  1.1  christos /*
     77  1.1  christos  * We will override some of the default region handlers, especially
     78  1.1  christos  * the SystemMemory handler, which must be implemented locally.
     79  1.1  christos  * These handlers are installed "early" - before any _REG methods
     80  1.1  christos  * are executed - since they are special in the sense that the ACPI spec
     81  1.1  christos  * declares that they must "always be available". Cannot override the
     82  1.1  christos  * DataTable region handler either -- needed for test execution.
     83  1.1  christos  *
     84  1.1  christos  * NOTE: The local region handler will simulate access to these address
     85  1.1  christos  * spaces by creating a memory buffer behind each operation region.
     86  1.1  christos  */
     87  1.1  christos static ACPI_ADR_SPACE_TYPE  DefaultSpaceIdList[] =
     88  1.1  christos {
     89  1.1  christos     ACPI_ADR_SPACE_SYSTEM_MEMORY,
     90  1.1  christos     ACPI_ADR_SPACE_SYSTEM_IO,
     91  1.1  christos     ACPI_ADR_SPACE_PCI_CONFIG,
     92  1.1  christos     ACPI_ADR_SPACE_EC
     93  1.1  christos };
     94  1.1  christos 
     95  1.1  christos /*
     96  1.1  christos  * We will install handlers for some of the various address space IDs.
     97  1.1  christos  * Test one user-defined address space (used by aslts).
     98  1.1  christos  */
     99  1.1  christos #define ACPI_ADR_SPACE_USER_DEFINED1        0x80
    100  1.1  christos #define ACPI_ADR_SPACE_USER_DEFINED2        0xE4
    101  1.1  christos 
    102  1.1  christos static ACPI_ADR_SPACE_TYPE  SpaceIdList[] =
    103  1.1  christos {
    104  1.1  christos     ACPI_ADR_SPACE_SMBUS,
    105  1.1  christos     ACPI_ADR_SPACE_CMOS,
    106  1.1  christos     ACPI_ADR_SPACE_PCI_BAR_TARGET,
    107  1.1  christos     ACPI_ADR_SPACE_IPMI,
    108  1.1  christos     ACPI_ADR_SPACE_GPIO,
    109  1.1  christos     ACPI_ADR_SPACE_GSBUS,
    110  1.1  christos     ACPI_ADR_SPACE_FIXED_HARDWARE,
    111  1.1  christos     ACPI_ADR_SPACE_USER_DEFINED1,
    112  1.1  christos     ACPI_ADR_SPACE_USER_DEFINED2
    113  1.1  christos };
    114  1.1  christos 
    115  1.1  christos 
    116  1.1  christos /******************************************************************************
    117  1.1  christos  *
    118  1.1  christos  * FUNCTION:    AeRegionInit
    119  1.1  christos  *
    120  1.1  christos  * PARAMETERS:  Region init handler
    121  1.1  christos  *
    122  1.1  christos  * RETURN:      Status
    123  1.1  christos  *
    124  1.1  christos  * DESCRIPTION: Opregion init function.
    125  1.1  christos  *
    126  1.1  christos  *****************************************************************************/
    127  1.1  christos 
    128  1.1  christos static ACPI_STATUS
    129  1.1  christos AeRegionInit (
    130  1.1  christos     ACPI_HANDLE                 RegionHandle,
    131  1.1  christos     UINT32                      Function,
    132  1.1  christos     void                        *HandlerContext,
    133  1.1  christos     void                        **RegionContext)
    134  1.1  christos {
    135  1.1  christos 
    136  1.1  christos     if (Function == ACPI_REGION_DEACTIVATE)
    137  1.1  christos     {
    138  1.1  christos         *RegionContext = NULL;
    139  1.1  christos     }
    140  1.1  christos     else
    141  1.1  christos     {
    142  1.1  christos         *RegionContext = RegionHandle;
    143  1.1  christos     }
    144  1.1  christos 
    145  1.1  christos     return (AE_OK);
    146  1.1  christos }
    147  1.1  christos 
    148  1.1  christos 
    149  1.1  christos /******************************************************************************
    150  1.1  christos  *
    151  1.1  christos  * FUNCTION:    AeOverrideRegionHandlers
    152  1.1  christos  *
    153  1.1  christos  * PARAMETERS:  None
    154  1.1  christos  *
    155  1.1  christos  * RETURN:      None
    156  1.1  christos  *
    157  1.1  christos  * DESCRIPTION: Override the default region handlers for memory, i/o, and
    158  1.1  christos  *              pci_config. Also install a handler for EC. This is part of
    159  1.1  christos  *              the "install early handlers" functionality.
    160  1.1  christos  *
    161  1.1  christos  *****************************************************************************/
    162  1.1  christos 
    163  1.1  christos void
    164  1.1  christos AeOverrideRegionHandlers (
    165  1.1  christos     void)
    166  1.1  christos {
    167  1.1  christos     UINT32                  i;
    168  1.1  christos     ACPI_STATUS             Status;
    169  1.1  christos 
    170  1.1  christos     /*
    171  1.1  christos      * Install handlers that will override the default handlers for some of
    172  1.1  christos      * the space IDs.
    173  1.1  christos      */
    174  1.1  christos     for (i = 0; i < ACPI_ARRAY_LENGTH (DefaultSpaceIdList); i++)
    175  1.1  christos     {
    176  1.1  christos         /* Install handler at the root object */
    177  1.1  christos 
    178  1.1  christos         Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
    179  1.1  christos             DefaultSpaceIdList[i], AeRegionHandler, AeRegionInit,
    180  1.1  christos             &AeMyContext);
    181  1.1  christos 
    182  1.1  christos         if (ACPI_FAILURE (Status))
    183  1.1  christos         {
    184  1.1  christos             ACPI_EXCEPTION ((AE_INFO, Status,
    185  1.1  christos                 "Could not install an OpRegion handler for %s space(%u)",
    186  1.1  christos                 AcpiUtGetRegionName ((UINT8) DefaultSpaceIdList[i]),
    187  1.1  christos                 DefaultSpaceIdList[i]));
    188  1.1  christos         }
    189  1.1  christos     }
    190  1.1  christos }
    191  1.1  christos 
    192  1.1  christos 
    193  1.1  christos /******************************************************************************
    194  1.1  christos  *
    195  1.1  christos  * FUNCTION:    AeInstallRegionHandlers
    196  1.1  christos  *
    197  1.1  christos  * PARAMETERS:  None
    198  1.1  christos  *
    199  1.1  christos  * RETURN:      None
    200  1.1  christos  *
    201  1.1  christos  * DESCRIPTION: Install handlers for the address spaces other than
    202  1.1  christos  *              SystemMemory, SystemIO, and PCI_CONFIG.
    203  1.1  christos  *
    204  1.1  christos  *****************************************************************************/
    205  1.1  christos 
    206  1.1  christos void
    207  1.1  christos AeInstallRegionHandlers (
    208  1.1  christos     void)
    209  1.1  christos {
    210  1.1  christos     UINT32                  i;
    211  1.1  christos     ACPI_STATUS             Status;
    212  1.1  christos 
    213  1.1  christos 
    214  1.1  christos     /*
    215  1.1  christos      * Install handlers for some of the "device driver" address spaces
    216  1.1  christos      * such as SMBus, etc.
    217  1.1  christos      */
    218  1.1  christos     for (i = 0; i < ACPI_ARRAY_LENGTH (SpaceIdList); i++)
    219  1.1  christos     {
    220  1.1  christos         /* Install handler at the root object */
    221  1.1  christos 
    222  1.1  christos         Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
    223  1.1  christos             SpaceIdList[i], AeRegionHandler, AeRegionInit,
    224  1.1  christos             &AeMyContext);
    225  1.1  christos 
    226  1.1  christos         if (ACPI_FAILURE (Status))
    227  1.1  christos         {
    228  1.1  christos             ACPI_EXCEPTION ((AE_INFO, Status,
    229  1.1  christos                 "Could not install an OpRegion handler for %s space(%u)",
    230  1.1  christos                 AcpiUtGetRegionName((UINT8) SpaceIdList[i]), SpaceIdList[i]));
    231  1.1  christos             return;
    232  1.1  christos         }
    233  1.1  christos     }
    234  1.1  christos }
    235  1.1  christos 
    236  1.1  christos 
    237  1.1  christos /*******************************************************************************
    238  1.1  christos  *
    239  1.1  christos  * FUNCTION:    AeInstallDeviceHandlers
    240  1.1  christos  *
    241  1.1  christos  * PARAMETERS:  None
    242  1.1  christos  *
    243  1.1  christos  * RETURN:      Status
    244  1.1  christos  *
    245  1.1  christos  * DESCRIPTION: Install handlers for all EC and PCI devices in the namespace
    246  1.1  christos  *
    247  1.1  christos  ******************************************************************************/
    248  1.1  christos 
    249  1.1  christos ACPI_STATUS
    250  1.1  christos AeInstallDeviceHandlers (
    251  1.1  christos     void)
    252  1.1  christos {
    253  1.1  christos 
    254  1.1  christos     /* Find all Embedded Controller devices */
    255  1.1  christos 
    256  1.1  christos     AcpiGetDevices ("PNP0C09", AeInstallEcHandler, NULL, NULL);
    257  1.1  christos 
    258  1.1  christos     /* Install a PCI handler */
    259  1.1  christos 
    260  1.1  christos     AcpiGetDevices ("PNP0A08", AeInstallPciHandler, NULL, NULL);
    261  1.1  christos     return (AE_OK);
    262  1.1  christos }
    263  1.1  christos 
    264  1.1  christos 
    265  1.1  christos /*******************************************************************************
    266  1.1  christos  *
    267  1.1  christos  * FUNCTION:    AeInstallEcHandler
    268  1.1  christos  *
    269  1.1  christos  * PARAMETERS:  ACPI_WALK_NAMESPACE callback
    270  1.1  christos  *
    271  1.1  christos  * RETURN:      Status
    272  1.1  christos  *
    273  1.1  christos  * DESCRIPTION: Walk entire namespace, install a handler for every EC
    274  1.1  christos  *              device found.
    275  1.1  christos  *
    276  1.1  christos  ******************************************************************************/
    277  1.1  christos 
    278  1.1  christos static ACPI_STATUS
    279  1.1  christos AeInstallEcHandler (
    280  1.1  christos     ACPI_HANDLE             ObjHandle,
    281  1.1  christos     UINT32                  Level,
    282  1.1  christos     void                    *Context,
    283  1.1  christos     void                    **ReturnValue)
    284  1.1  christos {
    285  1.1  christos     ACPI_STATUS             Status;
    286  1.1  christos 
    287  1.1  christos 
    288  1.1  christos     /* Install the handler for this EC device */
    289  1.1  christos 
    290  1.1  christos     Status = AcpiInstallAddressSpaceHandler (ObjHandle,
    291  1.1  christos         ACPI_ADR_SPACE_EC, AeRegionHandler, AeRegionInit, &AeMyContext);
    292  1.1  christos     if (ACPI_FAILURE (Status))
    293  1.1  christos     {
    294  1.1  christos         ACPI_EXCEPTION ((AE_INFO, Status,
    295  1.1  christos             "Could not install an OpRegion handler for EC device (%p)",
    296  1.1  christos             ObjHandle));
    297  1.1  christos     }
    298  1.1  christos 
    299  1.1  christos     return (Status);
    300  1.1  christos }
    301  1.1  christos 
    302  1.1  christos 
    303  1.1  christos /*******************************************************************************
    304  1.1  christos  *
    305  1.1  christos  * FUNCTION:    AeInstallPciHandler
    306  1.1  christos  *
    307  1.1  christos  * PARAMETERS:  ACPI_WALK_NAMESPACE callback
    308  1.1  christos  *
    309  1.1  christos  * RETURN:      Status
    310  1.1  christos  *
    311  1.1  christos  * DESCRIPTION: Walk entire namespace, install a handler for every PCI
    312  1.1  christos  *              device found.
    313  1.1  christos  *
    314  1.1  christos  ******************************************************************************/
    315  1.1  christos 
    316  1.1  christos static ACPI_STATUS
    317  1.1  christos AeInstallPciHandler (
    318  1.1  christos     ACPI_HANDLE             ObjHandle,
    319  1.1  christos     UINT32                  Level,
    320  1.1  christos     void                    *Context,
    321  1.1  christos     void                    **ReturnValue)
    322  1.1  christos {
    323  1.1  christos     ACPI_STATUS             Status;
    324  1.1  christos 
    325  1.1  christos 
    326  1.1  christos     /* Install memory and I/O handlers for the PCI device */
    327  1.1  christos 
    328  1.1  christos     Status = AcpiInstallAddressSpaceHandler (ObjHandle,
    329  1.1  christos         ACPI_ADR_SPACE_SYSTEM_IO, AeRegionHandler, AeRegionInit,
    330  1.1  christos         &AeMyContext);
    331  1.1  christos     if (ACPI_FAILURE (Status))
    332  1.1  christos     {
    333  1.1  christos         ACPI_EXCEPTION ((AE_INFO, Status,
    334  1.1  christos             "Could not install an OpRegion handler for PCI device (%p)",
    335  1.1  christos             ObjHandle));
    336  1.1  christos     }
    337  1.1  christos 
    338  1.1  christos     Status = AcpiInstallAddressSpaceHandler (ObjHandle,
    339  1.1  christos         ACPI_ADR_SPACE_SYSTEM_MEMORY, AeRegionHandler, AeRegionInit,
    340  1.1  christos         &AeMyContext);
    341  1.1  christos     if (ACPI_FAILURE (Status))
    342  1.1  christos     {
    343  1.1  christos         ACPI_EXCEPTION ((AE_INFO, Status,
    344  1.1  christos             "Could not install an OpRegion handler for PCI device (%p)",
    345  1.1  christos             ObjHandle));
    346  1.1  christos     }
    347  1.1  christos 
    348  1.1  christos     return (AE_CTRL_TERMINATE);
    349  1.1  christos }
    350