Home | History | Annotate | Line # | Download | only in executer
exregion.c revision 1.1.1.14
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: exregion - ACPI default OpRegion (address space) handlers
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8  1.1.1.13  christos  * Copyright (C) 2000 - 2021, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13   1.1.1.2    jruoho  * are met:
     14   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.1.1.2    jruoho  *    without modification.
     17   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.1.1.2    jruoho  *    binary redistribution.
     22   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25   1.1.1.2    jruoho  *
     26   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.1.1.2    jruoho  * Software Foundation.
     29   1.1.1.2    jruoho  *
     30   1.1.1.2    jruoho  * NO WARRANTY
     31   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.13  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.1.1.2    jruoho  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "acpi.h"
     45       1.1    jruoho #include "accommon.h"
     46       1.1    jruoho #include "acinterp.h"
     47       1.1    jruoho 
     48       1.1    jruoho 
     49       1.1    jruoho #define _COMPONENT          ACPI_EXECUTER
     50       1.1    jruoho         ACPI_MODULE_NAME    ("exregion")
     51       1.1    jruoho 
     52       1.1    jruoho 
     53       1.1    jruoho /*******************************************************************************
     54       1.1    jruoho  *
     55       1.1    jruoho  * FUNCTION:    AcpiExSystemMemorySpaceHandler
     56       1.1    jruoho  *
     57       1.1    jruoho  * PARAMETERS:  Function            - Read or Write operation
     58       1.1    jruoho  *              Address             - Where in the space to read or write
     59       1.1    jruoho  *              BitWidth            - Field width in bits (8, 16, or 32)
     60       1.1    jruoho  *              Value               - Pointer to in or out value
     61       1.1    jruoho  *              HandlerContext      - Pointer to Handler's context
     62       1.1    jruoho  *              RegionContext       - Pointer to context specific to the
     63       1.1    jruoho  *                                    accessed region
     64       1.1    jruoho  *
     65       1.1    jruoho  * RETURN:      Status
     66       1.1    jruoho  *
     67       1.1    jruoho  * DESCRIPTION: Handler for the System Memory address space (Op Region)
     68       1.1    jruoho  *
     69       1.1    jruoho  ******************************************************************************/
     70       1.1    jruoho 
     71       1.1    jruoho ACPI_STATUS
     72       1.1    jruoho AcpiExSystemMemorySpaceHandler (
     73       1.1    jruoho     UINT32                  Function,
     74       1.1    jruoho     ACPI_PHYSICAL_ADDRESS   Address,
     75       1.1    jruoho     UINT32                  BitWidth,
     76       1.1    jruoho     UINT64                  *Value,
     77       1.1    jruoho     void                    *HandlerContext,
     78       1.1    jruoho     void                    *RegionContext)
     79       1.1    jruoho {
     80       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
     81       1.1    jruoho     void                    *LogicalAddrPtr = NULL;
     82       1.1    jruoho     ACPI_MEM_SPACE_CONTEXT  *MemInfo = RegionContext;
     83  1.1.1.12  christos     ACPI_MEM_MAPPING        *Mm = MemInfo->CurMm;
     84       1.1    jruoho     UINT32                  Length;
     85       1.1    jruoho     ACPI_SIZE               MapLength;
     86       1.1    jruoho     ACPI_SIZE               PageBoundaryMapLength;
     87       1.1    jruoho #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
     88       1.1    jruoho     UINT32                  Remainder;
     89       1.1    jruoho #endif
     90       1.1    jruoho 
     91       1.1    jruoho 
     92       1.1    jruoho     ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler);
     93       1.1    jruoho 
     94       1.1    jruoho 
     95       1.1    jruoho     /* Validate and translate the bit width */
     96       1.1    jruoho 
     97       1.1    jruoho     switch (BitWidth)
     98       1.1    jruoho     {
     99       1.1    jruoho     case 8:
    100   1.1.1.3  christos 
    101       1.1    jruoho         Length = 1;
    102       1.1    jruoho         break;
    103       1.1    jruoho 
    104       1.1    jruoho     case 16:
    105   1.1.1.3  christos 
    106       1.1    jruoho         Length = 2;
    107       1.1    jruoho         break;
    108       1.1    jruoho 
    109       1.1    jruoho     case 32:
    110   1.1.1.3  christos 
    111       1.1    jruoho         Length = 4;
    112       1.1    jruoho         break;
    113       1.1    jruoho 
    114       1.1    jruoho     case 64:
    115   1.1.1.3  christos 
    116       1.1    jruoho         Length = 8;
    117       1.1    jruoho         break;
    118       1.1    jruoho 
    119       1.1    jruoho     default:
    120   1.1.1.3  christos 
    121       1.1    jruoho         ACPI_ERROR ((AE_INFO, "Invalid SystemMemory width %u",
    122       1.1    jruoho             BitWidth));
    123       1.1    jruoho         return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
    124       1.1    jruoho     }
    125       1.1    jruoho 
    126       1.1    jruoho #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
    127       1.1    jruoho     /*
    128       1.1    jruoho      * Hardware does not support non-aligned data transfers, we must verify
    129       1.1    jruoho      * the request.
    130       1.1    jruoho      */
    131       1.1    jruoho     (void) AcpiUtShortDivide ((UINT64) Address, Length, NULL, &Remainder);
    132       1.1    jruoho     if (Remainder != 0)
    133       1.1    jruoho     {
    134       1.1    jruoho         return_ACPI_STATUS (AE_AML_ALIGNMENT);
    135       1.1    jruoho     }
    136       1.1    jruoho #endif
    137       1.1    jruoho 
    138       1.1    jruoho     /*
    139       1.1    jruoho      * Does the request fit into the cached memory mapping?
    140       1.1    jruoho      * Is 1) Address below the current mapping? OR
    141       1.1    jruoho      *    2) Address beyond the current mapping?
    142       1.1    jruoho      */
    143  1.1.1.12  christos     if (!Mm || (Address < Mm->PhysicalAddress) ||
    144  1.1.1.12  christos         ((UINT64) Address + Length > (UINT64) Mm->PhysicalAddress + Mm->Length))
    145       1.1    jruoho     {
    146       1.1    jruoho         /*
    147  1.1.1.12  christos          * The request cannot be resolved by the current memory mapping.
    148  1.1.1.12  christos          *
    149  1.1.1.12  christos          * Look for an existing saved mapping covering the address range
    150  1.1.1.12  christos          * at hand. If found, save it as the current one and carry out
    151  1.1.1.12  christos          * the access.
    152       1.1    jruoho          */
    153  1.1.1.12  christos         for (Mm = MemInfo->FirstMm; Mm; Mm = Mm->NextMm)
    154       1.1    jruoho         {
    155  1.1.1.12  christos             if (Mm == MemInfo->CurMm)
    156  1.1.1.12  christos             {
    157  1.1.1.12  christos                 continue;
    158  1.1.1.12  christos             }
    159  1.1.1.12  christos 
    160  1.1.1.12  christos             if (Address < Mm->PhysicalAddress)
    161  1.1.1.12  christos             {
    162  1.1.1.12  christos                 continue;
    163  1.1.1.12  christos             }
    164  1.1.1.12  christos 
    165  1.1.1.12  christos             if ((UINT64) Address + Length > (UINT64) Mm->PhysicalAddress + Mm->Length)
    166  1.1.1.12  christos             {
    167  1.1.1.12  christos                 continue;
    168  1.1.1.12  christos             }
    169  1.1.1.12  christos 
    170  1.1.1.12  christos             MemInfo->CurMm = Mm;
    171  1.1.1.12  christos             goto access;
    172  1.1.1.12  christos         }
    173  1.1.1.12  christos 
    174  1.1.1.12  christos         /* Create a new mappings list entry */
    175       1.1    jruoho 
    176  1.1.1.12  christos         Mm = ACPI_ALLOCATE_ZEROED(sizeof(*Mm));
    177  1.1.1.12  christos         if (!Mm)
    178  1.1.1.12  christos         {
    179  1.1.1.12  christos             ACPI_ERROR((AE_INFO,
    180  1.1.1.12  christos                 "Unable to save memory mapping at 0x%8.8X%8.8X, size %u",
    181  1.1.1.12  christos                 ACPI_FORMAT_UINT64(Address), Length));
    182  1.1.1.12  christos             return_ACPI_STATUS(AE_NO_MEMORY);
    183       1.1    jruoho         }
    184       1.1    jruoho 
    185       1.1    jruoho         /*
    186       1.1    jruoho          * October 2009: Attempt to map from the requested address to the
    187       1.1    jruoho          * end of the region. However, we will never map more than one
    188       1.1    jruoho          * page, nor will we cross a page boundary.
    189       1.1    jruoho          */
    190       1.1    jruoho         MapLength = (ACPI_SIZE)
    191       1.1    jruoho             ((MemInfo->Address + MemInfo->Length) - Address);
    192       1.1    jruoho 
    193       1.1    jruoho         /*
    194       1.1    jruoho          * If mapping the entire remaining portion of the region will cross
    195       1.1    jruoho          * a page boundary, just map up to the page boundary, do not cross.
    196       1.1    jruoho          * On some systems, crossing a page boundary while mapping regions
    197       1.1    jruoho          * can cause warnings if the pages have different attributes
    198       1.1    jruoho          * due to resource management.
    199       1.1    jruoho          *
    200       1.1    jruoho          * This has the added benefit of constraining a single mapping to
    201       1.1    jruoho          * one page, which is similar to the original code that used a 4k
    202       1.1    jruoho          * maximum window.
    203       1.1    jruoho          */
    204   1.1.1.5  christos         PageBoundaryMapLength = (ACPI_SIZE)
    205   1.1.1.5  christos             (ACPI_ROUND_UP (Address, ACPI_DEFAULT_PAGE_SIZE) - Address);
    206       1.1    jruoho         if (PageBoundaryMapLength == 0)
    207       1.1    jruoho         {
    208       1.1    jruoho             PageBoundaryMapLength = ACPI_DEFAULT_PAGE_SIZE;
    209       1.1    jruoho         }
    210       1.1    jruoho 
    211       1.1    jruoho         if (MapLength > PageBoundaryMapLength)
    212       1.1    jruoho         {
    213       1.1    jruoho             MapLength = PageBoundaryMapLength;
    214       1.1    jruoho         }
    215       1.1    jruoho 
    216       1.1    jruoho         /* Create a new mapping starting at the address given */
    217       1.1    jruoho 
    218  1.1.1.12  christos         LogicalAddrPtr = AcpiOsMapMemory(Address, MapLength);
    219  1.1.1.12  christos         if (!LogicalAddrPtr)
    220       1.1    jruoho         {
    221       1.1    jruoho             ACPI_ERROR ((AE_INFO,
    222       1.1    jruoho                 "Could not map memory at 0x%8.8X%8.8X, size %u",
    223   1.1.1.5  christos                 ACPI_FORMAT_UINT64 (Address), (UINT32) MapLength));
    224  1.1.1.12  christos             ACPI_FREE(Mm);
    225       1.1    jruoho             return_ACPI_STATUS (AE_NO_MEMORY);
    226       1.1    jruoho         }
    227       1.1    jruoho 
    228       1.1    jruoho         /* Save the physical address and mapping size */
    229       1.1    jruoho 
    230  1.1.1.12  christos         Mm->LogicalAddress = LogicalAddrPtr;
    231  1.1.1.12  christos         Mm->PhysicalAddress = Address;
    232  1.1.1.12  christos         Mm->Length = MapLength;
    233  1.1.1.12  christos 
    234  1.1.1.12  christos         /*
    235  1.1.1.12  christos          * Add the new entry to the mappigs list and save it as the
    236  1.1.1.12  christos          * current mapping.
    237  1.1.1.12  christos          */
    238  1.1.1.12  christos         Mm->NextMm = MemInfo->FirstMm;
    239  1.1.1.12  christos         MemInfo->FirstMm = Mm;
    240  1.1.1.12  christos         MemInfo->CurMm = Mm;
    241       1.1    jruoho     }
    242       1.1    jruoho 
    243  1.1.1.12  christos access:
    244       1.1    jruoho     /*
    245       1.1    jruoho      * Generate a logical pointer corresponding to the address we want to
    246       1.1    jruoho      * access
    247       1.1    jruoho      */
    248  1.1.1.12  christos     LogicalAddrPtr = Mm->LogicalAddress +
    249  1.1.1.12  christos         ((UINT64) Address - (UINT64) Mm->PhysicalAddress);
    250       1.1    jruoho 
    251       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    252       1.1    jruoho         "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n",
    253   1.1.1.5  christos         BitWidth, Function, ACPI_FORMAT_UINT64 (Address)));
    254       1.1    jruoho 
    255       1.1    jruoho     /*
    256       1.1    jruoho      * Perform the memory read or write
    257       1.1    jruoho      *
    258       1.1    jruoho      * Note: For machines that do not support non-aligned transfers, the target
    259   1.1.1.3  christos      * address was checked for alignment above. We do not attempt to break the
    260       1.1    jruoho      * transfer up into smaller (byte-size) chunks because the AML specifically
    261       1.1    jruoho      * asked for a transfer width that the hardware may require.
    262       1.1    jruoho      */
    263       1.1    jruoho     switch (Function)
    264       1.1    jruoho     {
    265       1.1    jruoho     case ACPI_READ:
    266       1.1    jruoho 
    267       1.1    jruoho         *Value = 0;
    268       1.1    jruoho         switch (BitWidth)
    269       1.1    jruoho         {
    270       1.1    jruoho         case 8:
    271   1.1.1.3  christos 
    272       1.1    jruoho             *Value = (UINT64) ACPI_GET8 (LogicalAddrPtr);
    273       1.1    jruoho             break;
    274       1.1    jruoho 
    275       1.1    jruoho         case 16:
    276   1.1.1.3  christos 
    277       1.1    jruoho             *Value = (UINT64) ACPI_GET16 (LogicalAddrPtr);
    278       1.1    jruoho             break;
    279       1.1    jruoho 
    280       1.1    jruoho         case 32:
    281   1.1.1.3  christos 
    282       1.1    jruoho             *Value = (UINT64) ACPI_GET32 (LogicalAddrPtr);
    283       1.1    jruoho             break;
    284       1.1    jruoho 
    285       1.1    jruoho         case 64:
    286   1.1.1.3  christos 
    287       1.1    jruoho             *Value = (UINT64) ACPI_GET64 (LogicalAddrPtr);
    288       1.1    jruoho             break;
    289       1.1    jruoho 
    290       1.1    jruoho         default:
    291   1.1.1.3  christos 
    292       1.1    jruoho             /* BitWidth was already validated */
    293   1.1.1.3  christos 
    294       1.1    jruoho             break;
    295       1.1    jruoho         }
    296       1.1    jruoho         break;
    297       1.1    jruoho 
    298       1.1    jruoho     case ACPI_WRITE:
    299       1.1    jruoho 
    300       1.1    jruoho         switch (BitWidth)
    301       1.1    jruoho         {
    302       1.1    jruoho         case 8:
    303   1.1.1.3  christos 
    304   1.1.1.3  christos             ACPI_SET8 (LogicalAddrPtr, *Value);
    305       1.1    jruoho             break;
    306       1.1    jruoho 
    307       1.1    jruoho         case 16:
    308   1.1.1.3  christos 
    309   1.1.1.3  christos             ACPI_SET16 (LogicalAddrPtr, *Value);
    310       1.1    jruoho             break;
    311       1.1    jruoho 
    312       1.1    jruoho         case 32:
    313   1.1.1.3  christos 
    314   1.1.1.3  christos             ACPI_SET32 (LogicalAddrPtr, *Value);
    315       1.1    jruoho             break;
    316       1.1    jruoho 
    317       1.1    jruoho         case 64:
    318   1.1.1.3  christos 
    319   1.1.1.3  christos             ACPI_SET64 (LogicalAddrPtr, *Value);
    320       1.1    jruoho             break;
    321       1.1    jruoho 
    322       1.1    jruoho         default:
    323   1.1.1.3  christos 
    324       1.1    jruoho             /* BitWidth was already validated */
    325   1.1.1.3  christos 
    326       1.1    jruoho             break;
    327       1.1    jruoho         }
    328       1.1    jruoho         break;
    329       1.1    jruoho 
    330       1.1    jruoho     default:
    331   1.1.1.3  christos 
    332       1.1    jruoho         Status = AE_BAD_PARAMETER;
    333       1.1    jruoho         break;
    334       1.1    jruoho     }
    335       1.1    jruoho 
    336       1.1    jruoho     return_ACPI_STATUS (Status);
    337       1.1    jruoho }
    338       1.1    jruoho 
    339       1.1    jruoho 
    340       1.1    jruoho /*******************************************************************************
    341       1.1    jruoho  *
    342       1.1    jruoho  * FUNCTION:    AcpiExSystemIoSpaceHandler
    343       1.1    jruoho  *
    344       1.1    jruoho  * PARAMETERS:  Function            - Read or Write operation
    345       1.1    jruoho  *              Address             - Where in the space to read or write
    346       1.1    jruoho  *              BitWidth            - Field width in bits (8, 16, or 32)
    347       1.1    jruoho  *              Value               - Pointer to in or out value
    348       1.1    jruoho  *              HandlerContext      - Pointer to Handler's context
    349       1.1    jruoho  *              RegionContext       - Pointer to context specific to the
    350       1.1    jruoho  *                                    accessed region
    351       1.1    jruoho  *
    352       1.1    jruoho  * RETURN:      Status
    353       1.1    jruoho  *
    354       1.1    jruoho  * DESCRIPTION: Handler for the System IO address space (Op Region)
    355       1.1    jruoho  *
    356       1.1    jruoho  ******************************************************************************/
    357       1.1    jruoho 
    358       1.1    jruoho ACPI_STATUS
    359       1.1    jruoho AcpiExSystemIoSpaceHandler (
    360       1.1    jruoho     UINT32                  Function,
    361       1.1    jruoho     ACPI_PHYSICAL_ADDRESS   Address,
    362       1.1    jruoho     UINT32                  BitWidth,
    363       1.1    jruoho     UINT64                  *Value,
    364       1.1    jruoho     void                    *HandlerContext,
    365       1.1    jruoho     void                    *RegionContext)
    366       1.1    jruoho {
    367       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    368       1.1    jruoho     UINT32                  Value32;
    369       1.1    jruoho 
    370       1.1    jruoho 
    371       1.1    jruoho     ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler);
    372       1.1    jruoho 
    373       1.1    jruoho 
    374       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    375       1.1    jruoho         "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n",
    376   1.1.1.5  christos         BitWidth, Function, ACPI_FORMAT_UINT64 (Address)));
    377       1.1    jruoho 
    378       1.1    jruoho     /* Decode the function parameter */
    379       1.1    jruoho 
    380       1.1    jruoho     switch (Function)
    381       1.1    jruoho     {
    382       1.1    jruoho     case ACPI_READ:
    383       1.1    jruoho 
    384       1.1    jruoho         Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address,
    385       1.1    jruoho                     &Value32, BitWidth);
    386       1.1    jruoho         *Value = Value32;
    387       1.1    jruoho         break;
    388       1.1    jruoho 
    389       1.1    jruoho     case ACPI_WRITE:
    390       1.1    jruoho 
    391       1.1    jruoho         Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address,
    392       1.1    jruoho                     (UINT32) *Value, BitWidth);
    393       1.1    jruoho         break;
    394       1.1    jruoho 
    395       1.1    jruoho     default:
    396   1.1.1.3  christos 
    397       1.1    jruoho         Status = AE_BAD_PARAMETER;
    398       1.1    jruoho         break;
    399       1.1    jruoho     }
    400       1.1    jruoho 
    401       1.1    jruoho     return_ACPI_STATUS (Status);
    402       1.1    jruoho }
    403       1.1    jruoho 
    404       1.1    jruoho 
    405       1.1    jruoho /*******************************************************************************
    406       1.1    jruoho  *
    407       1.1    jruoho  * FUNCTION:    AcpiExPciConfigSpaceHandler
    408       1.1    jruoho  *
    409       1.1    jruoho  * PARAMETERS:  Function            - Read or Write operation
    410       1.1    jruoho  *              Address             - Where in the space to read or write
    411       1.1    jruoho  *              BitWidth            - Field width in bits (8, 16, or 32)
    412       1.1    jruoho  *              Value               - Pointer to in or out value
    413       1.1    jruoho  *              HandlerContext      - Pointer to Handler's context
    414       1.1    jruoho  *              RegionContext       - Pointer to context specific to the
    415       1.1    jruoho  *                                    accessed region
    416       1.1    jruoho  *
    417       1.1    jruoho  * RETURN:      Status
    418       1.1    jruoho  *
    419       1.1    jruoho  * DESCRIPTION: Handler for the PCI Config address space (Op Region)
    420       1.1    jruoho  *
    421       1.1    jruoho  ******************************************************************************/
    422       1.1    jruoho 
    423       1.1    jruoho ACPI_STATUS
    424       1.1    jruoho AcpiExPciConfigSpaceHandler (
    425       1.1    jruoho     UINT32                  Function,
    426       1.1    jruoho     ACPI_PHYSICAL_ADDRESS   Address,
    427       1.1    jruoho     UINT32                  BitWidth,
    428       1.1    jruoho     UINT64                  *Value,
    429       1.1    jruoho     void                    *HandlerContext,
    430       1.1    jruoho     void                    *RegionContext)
    431       1.1    jruoho {
    432       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    433       1.1    jruoho     ACPI_PCI_ID             *PciId;
    434       1.1    jruoho     UINT16                  PciRegister;
    435       1.1    jruoho 
    436       1.1    jruoho 
    437       1.1    jruoho     ACPI_FUNCTION_TRACE (ExPciConfigSpaceHandler);
    438       1.1    jruoho 
    439       1.1    jruoho 
    440       1.1    jruoho     /*
    441       1.1    jruoho      *  The arguments to AcpiOs(Read|Write)PciConfiguration are:
    442       1.1    jruoho      *
    443       1.1    jruoho      *  PciSegment  is the PCI bus segment range 0-31
    444       1.1    jruoho      *  PciBus      is the PCI bus number range 0-255
    445       1.1    jruoho      *  PciDevice   is the PCI device number range 0-31
    446       1.1    jruoho      *  PciFunction is the PCI device function number
    447       1.1    jruoho      *  PciRegister is the Config space register range 0-255 bytes
    448       1.1    jruoho      *
    449       1.1    jruoho      *  Value - input value for write, output address for read
    450       1.1    jruoho      *
    451       1.1    jruoho      */
    452       1.1    jruoho     PciId       = (ACPI_PCI_ID *) RegionContext;
    453       1.1    jruoho     PciRegister = (UINT16) (UINT32) Address;
    454       1.1    jruoho 
    455       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    456   1.1.1.7  christos         "Pci-Config %u (%u) Seg(%04x) Bus(%04x) "
    457   1.1.1.7  christos         "Dev(%04x) Func(%04x) Reg(%04x)\n",
    458       1.1    jruoho         Function, BitWidth, PciId->Segment, PciId->Bus, PciId->Device,
    459       1.1    jruoho         PciId->Function, PciRegister));
    460       1.1    jruoho 
    461       1.1    jruoho     switch (Function)
    462       1.1    jruoho     {
    463       1.1    jruoho     case ACPI_READ:
    464       1.1    jruoho 
    465       1.1    jruoho         *Value = 0;
    466   1.1.1.7  christos         Status = AcpiOsReadPciConfiguration (
    467   1.1.1.7  christos             PciId, PciRegister, Value, BitWidth);
    468       1.1    jruoho         break;
    469       1.1    jruoho 
    470       1.1    jruoho     case ACPI_WRITE:
    471       1.1    jruoho 
    472   1.1.1.7  christos         Status = AcpiOsWritePciConfiguration (
    473   1.1.1.7  christos             PciId, PciRegister, *Value, BitWidth);
    474       1.1    jruoho         break;
    475       1.1    jruoho 
    476       1.1    jruoho     default:
    477       1.1    jruoho 
    478       1.1    jruoho         Status = AE_BAD_PARAMETER;
    479       1.1    jruoho         break;
    480       1.1    jruoho     }
    481       1.1    jruoho 
    482       1.1    jruoho     return_ACPI_STATUS (Status);
    483       1.1    jruoho }
    484       1.1    jruoho 
    485       1.1    jruoho 
    486       1.1    jruoho /*******************************************************************************
    487       1.1    jruoho  *
    488       1.1    jruoho  * FUNCTION:    AcpiExCmosSpaceHandler
    489       1.1    jruoho  *
    490       1.1    jruoho  * PARAMETERS:  Function            - Read or Write operation
    491       1.1    jruoho  *              Address             - Where in the space to read or write
    492       1.1    jruoho  *              BitWidth            - Field width in bits (8, 16, or 32)
    493       1.1    jruoho  *              Value               - Pointer to in or out value
    494       1.1    jruoho  *              HandlerContext      - Pointer to Handler's context
    495       1.1    jruoho  *              RegionContext       - Pointer to context specific to the
    496       1.1    jruoho  *                                    accessed region
    497       1.1    jruoho  *
    498       1.1    jruoho  * RETURN:      Status
    499       1.1    jruoho  *
    500       1.1    jruoho  * DESCRIPTION: Handler for the CMOS address space (Op Region)
    501       1.1    jruoho  *
    502       1.1    jruoho  ******************************************************************************/
    503       1.1    jruoho 
    504       1.1    jruoho ACPI_STATUS
    505       1.1    jruoho AcpiExCmosSpaceHandler (
    506       1.1    jruoho     UINT32                  Function,
    507       1.1    jruoho     ACPI_PHYSICAL_ADDRESS   Address,
    508       1.1    jruoho     UINT32                  BitWidth,
    509       1.1    jruoho     UINT64                  *Value,
    510       1.1    jruoho     void                    *HandlerContext,
    511       1.1    jruoho     void                    *RegionContext)
    512       1.1    jruoho {
    513       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    514       1.1    jruoho 
    515       1.1    jruoho 
    516       1.1    jruoho     ACPI_FUNCTION_TRACE (ExCmosSpaceHandler);
    517       1.1    jruoho 
    518       1.1    jruoho 
    519       1.1    jruoho     return_ACPI_STATUS (Status);
    520       1.1    jruoho }
    521       1.1    jruoho 
    522       1.1    jruoho 
    523       1.1    jruoho /*******************************************************************************
    524       1.1    jruoho  *
    525       1.1    jruoho  * FUNCTION:    AcpiExPciBarSpaceHandler
    526       1.1    jruoho  *
    527       1.1    jruoho  * PARAMETERS:  Function            - Read or Write operation
    528       1.1    jruoho  *              Address             - Where in the space to read or write
    529       1.1    jruoho  *              BitWidth            - Field width in bits (8, 16, or 32)
    530       1.1    jruoho  *              Value               - Pointer to in or out value
    531       1.1    jruoho  *              HandlerContext      - Pointer to Handler's context
    532       1.1    jruoho  *              RegionContext       - Pointer to context specific to the
    533       1.1    jruoho  *                                    accessed region
    534       1.1    jruoho  *
    535       1.1    jruoho  * RETURN:      Status
    536       1.1    jruoho  *
    537       1.1    jruoho  * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
    538       1.1    jruoho  *
    539       1.1    jruoho  ******************************************************************************/
    540       1.1    jruoho 
    541       1.1    jruoho ACPI_STATUS
    542       1.1    jruoho AcpiExPciBarSpaceHandler (
    543       1.1    jruoho     UINT32                  Function,
    544       1.1    jruoho     ACPI_PHYSICAL_ADDRESS   Address,
    545       1.1    jruoho     UINT32                  BitWidth,
    546       1.1    jruoho     UINT64                  *Value,
    547       1.1    jruoho     void                    *HandlerContext,
    548       1.1    jruoho     void                    *RegionContext)
    549       1.1    jruoho {
    550       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    551       1.1    jruoho 
    552       1.1    jruoho 
    553       1.1    jruoho     ACPI_FUNCTION_TRACE (ExPciBarSpaceHandler);
    554       1.1    jruoho 
    555       1.1    jruoho 
    556       1.1    jruoho     return_ACPI_STATUS (Status);
    557       1.1    jruoho }
    558       1.1    jruoho 
    559       1.1    jruoho 
    560       1.1    jruoho /*******************************************************************************
    561       1.1    jruoho  *
    562       1.1    jruoho  * FUNCTION:    AcpiExDataTableSpaceHandler
    563       1.1    jruoho  *
    564       1.1    jruoho  * PARAMETERS:  Function            - Read or Write operation
    565       1.1    jruoho  *              Address             - Where in the space to read or write
    566       1.1    jruoho  *              BitWidth            - Field width in bits (8, 16, or 32)
    567       1.1    jruoho  *              Value               - Pointer to in or out value
    568       1.1    jruoho  *              HandlerContext      - Pointer to Handler's context
    569       1.1    jruoho  *              RegionContext       - Pointer to context specific to the
    570       1.1    jruoho  *                                    accessed region
    571       1.1    jruoho  *
    572       1.1    jruoho  * RETURN:      Status
    573       1.1    jruoho  *
    574       1.1    jruoho  * DESCRIPTION: Handler for the Data Table address space (Op Region)
    575       1.1    jruoho  *
    576       1.1    jruoho  ******************************************************************************/
    577       1.1    jruoho 
    578       1.1    jruoho ACPI_STATUS
    579       1.1    jruoho AcpiExDataTableSpaceHandler (
    580       1.1    jruoho     UINT32                  Function,
    581       1.1    jruoho     ACPI_PHYSICAL_ADDRESS   Address,
    582       1.1    jruoho     UINT32                  BitWidth,
    583       1.1    jruoho     UINT64                  *Value,
    584       1.1    jruoho     void                    *HandlerContext,
    585       1.1    jruoho     void                    *RegionContext)
    586       1.1    jruoho {
    587  1.1.1.14  christos     ACPI_DATA_TABLE_MAPPING *Mapping;
    588  1.1.1.14  christos     char                    *Pointer;
    589  1.1.1.14  christos 
    590  1.1.1.14  christos 
    591       1.1    jruoho     ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler);
    592       1.1    jruoho 
    593       1.1    jruoho 
    594  1.1.1.14  christos     Mapping = (ACPI_DATA_TABLE_MAPPING *) RegionContext;
    595  1.1.1.14  christos     Pointer = ACPI_CAST_PTR (char, Mapping->Pointer) +
    596  1.1.1.14  christos         (Address - ACPI_PTR_TO_PHYSADDR (Mapping->Pointer));
    597  1.1.1.14  christos 
    598       1.1    jruoho     /*
    599       1.1    jruoho      * Perform the memory read or write. The BitWidth was already
    600       1.1    jruoho      * validated.
    601       1.1    jruoho      */
    602       1.1    jruoho     switch (Function)
    603       1.1    jruoho     {
    604       1.1    jruoho     case ACPI_READ:
    605       1.1    jruoho 
    606  1.1.1.14  christos         memcpy (ACPI_CAST_PTR (char, Value), Pointer, ACPI_DIV_8 (BitWidth));
    607       1.1    jruoho         break;
    608       1.1    jruoho 
    609       1.1    jruoho     case ACPI_WRITE:
    610       1.1    jruoho 
    611  1.1.1.14  christos         memcpy (Pointer, ACPI_CAST_PTR (char, Value), ACPI_DIV_8 (BitWidth));
    612       1.1    jruoho         break;
    613       1.1    jruoho 
    614       1.1    jruoho     default:
    615       1.1    jruoho 
    616       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    617       1.1    jruoho     }
    618       1.1    jruoho 
    619       1.1    jruoho     return_ACPI_STATUS (AE_OK);
    620       1.1    jruoho }
    621