Home | History | Annotate | Line # | Download | only in utilities
utaddress.c revision 1.1.1.5.2.1
      1          1.1  christos /******************************************************************************
      2          1.1  christos  *
      3          1.1  christos  * Module Name: utaddress - OpRegion address range check
      4          1.1  christos  *
      5          1.1  christos  *****************************************************************************/
      6          1.1  christos 
      7          1.1  christos /*
      8  1.1.1.5.2.1    bouyer  * 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 "acpi.h"
     45          1.1  christos #include "accommon.h"
     46          1.1  christos #include "acnamesp.h"
     47          1.1  christos 
     48          1.1  christos 
     49          1.1  christos #define _COMPONENT          ACPI_UTILITIES
     50          1.1  christos         ACPI_MODULE_NAME    ("utaddress")
     51          1.1  christos 
     52          1.1  christos 
     53          1.1  christos /*******************************************************************************
     54          1.1  christos  *
     55          1.1  christos  * FUNCTION:    AcpiUtAddAddressRange
     56          1.1  christos  *
     57          1.1  christos  * PARAMETERS:  SpaceId             - Address space ID
     58          1.1  christos  *              Address             - OpRegion start address
     59          1.1  christos  *              Length              - OpRegion length
     60          1.1  christos  *              RegionNode          - OpRegion namespace node
     61          1.1  christos  *
     62          1.1  christos  * RETURN:      Status
     63          1.1  christos  *
     64          1.1  christos  * DESCRIPTION: Add the Operation Region address range to the global list.
     65          1.1  christos  *              The only supported Space IDs are Memory and I/O. Called when
     66          1.1  christos  *              the OpRegion address/length operands are fully evaluated.
     67          1.1  christos  *
     68          1.1  christos  * MUTEX:       Locks the namespace
     69          1.1  christos  *
     70          1.1  christos  * NOTE: Because this interface is only called when an OpRegion argument
     71          1.1  christos  * list is evaluated, there cannot be any duplicate RegionNodes.
     72          1.1  christos  * Duplicate Address/Length values are allowed, however, so that multiple
     73          1.1  christos  * address conflicts can be detected.
     74          1.1  christos  *
     75          1.1  christos  ******************************************************************************/
     76          1.1  christos 
     77          1.1  christos ACPI_STATUS
     78          1.1  christos AcpiUtAddAddressRange (
     79          1.1  christos     ACPI_ADR_SPACE_TYPE     SpaceId,
     80          1.1  christos     ACPI_PHYSICAL_ADDRESS   Address,
     81          1.1  christos     UINT32                  Length,
     82          1.1  christos     ACPI_NAMESPACE_NODE     *RegionNode)
     83          1.1  christos {
     84          1.1  christos     ACPI_ADDRESS_RANGE      *RangeInfo;
     85          1.1  christos 
     86          1.1  christos 
     87          1.1  christos     ACPI_FUNCTION_TRACE (UtAddAddressRange);
     88          1.1  christos 
     89          1.1  christos 
     90          1.1  christos     if ((SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
     91          1.1  christos         (SpaceId != ACPI_ADR_SPACE_SYSTEM_IO))
     92          1.1  christos     {
     93          1.1  christos         return_ACPI_STATUS (AE_OK);
     94          1.1  christos     }
     95          1.1  christos 
     96          1.1  christos     /* Allocate/init a new info block, add it to the appropriate list */
     97          1.1  christos 
     98          1.1  christos     RangeInfo = ACPI_ALLOCATE (sizeof (ACPI_ADDRESS_RANGE));
     99          1.1  christos     if (!RangeInfo)
    100          1.1  christos     {
    101          1.1  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    102          1.1  christos     }
    103          1.1  christos 
    104          1.1  christos     RangeInfo->StartAddress = Address;
    105          1.1  christos     RangeInfo->EndAddress = (Address + Length - 1);
    106          1.1  christos     RangeInfo->RegionNode = RegionNode;
    107          1.1  christos 
    108          1.1  christos     RangeInfo->Next = AcpiGbl_AddressRangeList[SpaceId];
    109          1.1  christos     AcpiGbl_AddressRangeList[SpaceId] = RangeInfo;
    110          1.1  christos 
    111          1.1  christos     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    112      1.1.1.3  christos         "\nAdded [%4.4s] address range: 0x%8.8X%8.8X-0x%8.8X%8.8X\n",
    113          1.1  christos         AcpiUtGetNodeName (RangeInfo->RegionNode),
    114      1.1.1.3  christos         ACPI_FORMAT_UINT64 (Address),
    115      1.1.1.3  christos         ACPI_FORMAT_UINT64 (RangeInfo->EndAddress)));
    116          1.1  christos 
    117          1.1  christos     return_ACPI_STATUS (AE_OK);
    118          1.1  christos }
    119          1.1  christos 
    120          1.1  christos 
    121          1.1  christos /*******************************************************************************
    122          1.1  christos  *
    123          1.1  christos  * FUNCTION:    AcpiUtRemoveAddressRange
    124          1.1  christos  *
    125          1.1  christos  * PARAMETERS:  SpaceId             - Address space ID
    126          1.1  christos  *              RegionNode          - OpRegion namespace node
    127          1.1  christos  *
    128          1.1  christos  * RETURN:      None
    129          1.1  christos  *
    130          1.1  christos  * DESCRIPTION: Remove the Operation Region from the global list. The only
    131          1.1  christos  *              supported Space IDs are Memory and I/O. Called when an
    132          1.1  christos  *              OpRegion is deleted.
    133          1.1  christos  *
    134          1.1  christos  * MUTEX:       Assumes the namespace is locked
    135          1.1  christos  *
    136          1.1  christos  ******************************************************************************/
    137          1.1  christos 
    138          1.1  christos void
    139          1.1  christos AcpiUtRemoveAddressRange (
    140          1.1  christos     ACPI_ADR_SPACE_TYPE     SpaceId,
    141          1.1  christos     ACPI_NAMESPACE_NODE     *RegionNode)
    142          1.1  christos {
    143          1.1  christos     ACPI_ADDRESS_RANGE      *RangeInfo;
    144          1.1  christos     ACPI_ADDRESS_RANGE      *Prev;
    145          1.1  christos 
    146          1.1  christos 
    147          1.1  christos     ACPI_FUNCTION_TRACE (UtRemoveAddressRange);
    148          1.1  christos 
    149          1.1  christos 
    150          1.1  christos     if ((SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
    151          1.1  christos         (SpaceId != ACPI_ADR_SPACE_SYSTEM_IO))
    152          1.1  christos     {
    153          1.1  christos         return_VOID;
    154          1.1  christos     }
    155          1.1  christos 
    156          1.1  christos     /* Get the appropriate list head and check the list */
    157          1.1  christos 
    158          1.1  christos     RangeInfo = Prev = AcpiGbl_AddressRangeList[SpaceId];
    159          1.1  christos     while (RangeInfo)
    160          1.1  christos     {
    161          1.1  christos         if (RangeInfo->RegionNode == RegionNode)
    162          1.1  christos         {
    163          1.1  christos             if (RangeInfo == Prev) /* Found at list head */
    164          1.1  christos             {
    165          1.1  christos                 AcpiGbl_AddressRangeList[SpaceId] = RangeInfo->Next;
    166          1.1  christos             }
    167          1.1  christos             else
    168          1.1  christos             {
    169          1.1  christos                 Prev->Next = RangeInfo->Next;
    170          1.1  christos             }
    171          1.1  christos 
    172          1.1  christos             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    173      1.1.1.3  christos                 "\nRemoved [%4.4s] address range: 0x%8.8X%8.8X-0x%8.8X%8.8X\n",
    174          1.1  christos                 AcpiUtGetNodeName (RangeInfo->RegionNode),
    175      1.1.1.3  christos                 ACPI_FORMAT_UINT64 (RangeInfo->StartAddress),
    176      1.1.1.3  christos                 ACPI_FORMAT_UINT64 (RangeInfo->EndAddress)));
    177          1.1  christos 
    178          1.1  christos             ACPI_FREE (RangeInfo);
    179          1.1  christos             return_VOID;
    180          1.1  christos         }
    181          1.1  christos 
    182          1.1  christos         Prev = RangeInfo;
    183          1.1  christos         RangeInfo = RangeInfo->Next;
    184          1.1  christos     }
    185          1.1  christos 
    186          1.1  christos     return_VOID;
    187          1.1  christos }
    188          1.1  christos 
    189          1.1  christos 
    190          1.1  christos /*******************************************************************************
    191          1.1  christos  *
    192          1.1  christos  * FUNCTION:    AcpiUtCheckAddressRange
    193          1.1  christos  *
    194          1.1  christos  * PARAMETERS:  SpaceId             - Address space ID
    195          1.1  christos  *              Address             - Start address
    196          1.1  christos  *              Length              - Length of address range
    197          1.1  christos  *              Warn                - TRUE if warning on overlap desired
    198          1.1  christos  *
    199          1.1  christos  * RETURN:      Count of the number of conflicts detected. Zero is always
    200          1.1  christos  *              returned for Space IDs other than Memory or I/O.
    201          1.1  christos  *
    202          1.1  christos  * DESCRIPTION: Check if the input address range overlaps any of the
    203          1.1  christos  *              ASL operation region address ranges. The only supported
    204          1.1  christos  *              Space IDs are Memory and I/O.
    205          1.1  christos  *
    206          1.1  christos  * MUTEX:       Assumes the namespace is locked.
    207          1.1  christos  *
    208          1.1  christos  ******************************************************************************/
    209          1.1  christos 
    210          1.1  christos UINT32
    211          1.1  christos AcpiUtCheckAddressRange (
    212          1.1  christos     ACPI_ADR_SPACE_TYPE     SpaceId,
    213          1.1  christos     ACPI_PHYSICAL_ADDRESS   Address,
    214          1.1  christos     UINT32                  Length,
    215          1.1  christos     BOOLEAN                 Warn)
    216          1.1  christos {
    217          1.1  christos     ACPI_ADDRESS_RANGE      *RangeInfo;
    218          1.1  christos     ACPI_PHYSICAL_ADDRESS   EndAddress;
    219          1.1  christos     char                    *Pathname;
    220          1.1  christos     UINT32                  OverlapCount = 0;
    221          1.1  christos 
    222          1.1  christos 
    223          1.1  christos     ACPI_FUNCTION_TRACE (UtCheckAddressRange);
    224          1.1  christos 
    225          1.1  christos 
    226          1.1  christos     if ((SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
    227          1.1  christos         (SpaceId != ACPI_ADR_SPACE_SYSTEM_IO))
    228          1.1  christos     {
    229          1.1  christos         return_UINT32 (0);
    230          1.1  christos     }
    231          1.1  christos 
    232          1.1  christos     RangeInfo = AcpiGbl_AddressRangeList[SpaceId];
    233          1.1  christos     EndAddress = Address + Length - 1;
    234          1.1  christos 
    235          1.1  christos     /* Check entire list for all possible conflicts */
    236          1.1  christos 
    237          1.1  christos     while (RangeInfo)
    238          1.1  christos     {
    239          1.1  christos         /*
    240          1.1  christos          * Check if the requested address/length overlaps this
    241          1.1  christos          * address range. There are four cases to consider:
    242          1.1  christos          *
    243          1.1  christos          * 1) Input address/length is contained completely in the
    244          1.1  christos          *    address range
    245          1.1  christos          * 2) Input address/length overlaps range at the range start
    246          1.1  christos          * 3) Input address/length overlaps range at the range end
    247          1.1  christos          * 4) Input address/length completely encompasses the range
    248          1.1  christos          */
    249          1.1  christos         if ((Address <= RangeInfo->EndAddress) &&
    250          1.1  christos             (EndAddress >= RangeInfo->StartAddress))
    251          1.1  christos         {
    252          1.1  christos             /* Found an address range overlap */
    253          1.1  christos 
    254          1.1  christos             OverlapCount++;
    255          1.1  christos             if (Warn)   /* Optional warning message */
    256          1.1  christos             {
    257      1.1.1.4  christos                 Pathname = AcpiNsGetNormalizedPathname (RangeInfo->RegionNode, TRUE);
    258          1.1  christos 
    259          1.1  christos                 ACPI_WARNING ((AE_INFO,
    260      1.1.1.3  christos                     "%s range 0x%8.8X%8.8X-0x%8.8X%8.8X conflicts with OpRegion 0x%8.8X%8.8X-0x%8.8X%8.8X (%s)",
    261          1.1  christos                     AcpiUtGetRegionName (SpaceId),
    262      1.1.1.3  christos                     ACPI_FORMAT_UINT64 (Address),
    263      1.1.1.3  christos                     ACPI_FORMAT_UINT64 (EndAddress),
    264      1.1.1.3  christos                     ACPI_FORMAT_UINT64 (RangeInfo->StartAddress),
    265      1.1.1.3  christos                     ACPI_FORMAT_UINT64 (RangeInfo->EndAddress),
    266          1.1  christos                     Pathname));
    267          1.1  christos                 ACPI_FREE (Pathname);
    268          1.1  christos             }
    269          1.1  christos         }
    270          1.1  christos 
    271          1.1  christos         RangeInfo = RangeInfo->Next;
    272          1.1  christos     }
    273          1.1  christos 
    274          1.1  christos     return_UINT32 (OverlapCount);
    275          1.1  christos }
    276          1.1  christos 
    277          1.1  christos 
    278          1.1  christos /*******************************************************************************
    279          1.1  christos  *
    280          1.1  christos  * FUNCTION:    AcpiUtDeleteAddressLists
    281          1.1  christos  *
    282          1.1  christos  * PARAMETERS:  None
    283          1.1  christos  *
    284          1.1  christos  * RETURN:      None
    285          1.1  christos  *
    286          1.1  christos  * DESCRIPTION: Delete all global address range lists (called during
    287          1.1  christos  *              subsystem shutdown).
    288          1.1  christos  *
    289          1.1  christos  ******************************************************************************/
    290          1.1  christos 
    291          1.1  christos void
    292          1.1  christos AcpiUtDeleteAddressLists (
    293          1.1  christos     void)
    294          1.1  christos {
    295          1.1  christos     ACPI_ADDRESS_RANGE      *Next;
    296          1.1  christos     ACPI_ADDRESS_RANGE      *RangeInfo;
    297          1.1  christos     int                     i;
    298          1.1  christos 
    299          1.1  christos 
    300          1.1  christos     /* Delete all elements in all address range lists */
    301          1.1  christos 
    302          1.1  christos     for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++)
    303          1.1  christos     {
    304          1.1  christos         Next = AcpiGbl_AddressRangeList[i];
    305          1.1  christos 
    306          1.1  christos         while (Next)
    307          1.1  christos         {
    308          1.1  christos             RangeInfo = Next;
    309          1.1  christos             Next = RangeInfo->Next;
    310          1.1  christos             ACPI_FREE (RangeInfo);
    311          1.1  christos         }
    312          1.1  christos 
    313          1.1  christos         AcpiGbl_AddressRangeList[i] = NULL;
    314          1.1  christos     }
    315          1.1  christos }
    316