Home | History | Annotate | Download | only in Dxe
      1 /** @file
      2 QNC Legacy Region Driver
      3 
      4 Copyright (c) 2013-2015 Intel Corporation.
      5 
      6 This program and the accompanying materials
      7 are licensed and made available under the terms and conditions of the BSD License
      8 which accompanies this distribution.  The full text of the license may be found at
      9 http://opensource.org/licenses/bsd-license.php
     10 
     11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 
     16 #include "CommonHeader.h"
     17 #include "LegacyRegion.h"
     18 
     19 //
     20 // Handle used to install the Legacy Region Protocol
     21 //
     22 EFI_HANDLE  mLegacyRegion2Handle = NULL;
     23 
     24 //
     25 // Instance of the Legacy Region Protocol to install into the handle database
     26 //
     27 EFI_LEGACY_REGION2_PROTOCOL  mLegacyRegion2 = {
     28   LegacyRegion2Decode,
     29   LegacyRegion2Lock,
     30   LegacyRegion2BootLock,
     31   LegacyRegion2Unlock,
     32   LegacyRegionGetInfo
     33 };
     34 
     35 
     36 /**
     37   Modify the hardware to allow (decode) or disallow (not decode) memory reads in a region.
     38 
     39   If the On parameter evaluates to TRUE, this function enables memory reads in the address range
     40   Start to (Start + Length - 1).
     41   If the On parameter evaluates to FALSE, this function disables memory reads in the address range
     42   Start to (Start + Length - 1).
     43 
     44   @param  This[in]              Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
     45   @param  Start[in]             The beginning of the physical address of the region whose attributes
     46                                 should be modified.
     47   @param  Length[in]            The number of bytes of memory whose attributes should be modified.
     48                                 The actual number of bytes modified may be greater than the number
     49                                 specified.
     50   @param  Granularity[out]      The number of bytes in the last region affected. This may be less
     51                                 than the total number of bytes affected if the starting address
     52                                 was not aligned to a region's starting address or if the length
     53                                 was greater than the number of bytes in the first region.
     54   @param  On[in]                Decode / Non-Decode flag.
     55 
     56   @retval EFI_SUCCESS           The region's attributes were successfully modified.
     57   @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
     58 
     59 **/
     60 EFI_STATUS
     61 EFIAPI
     62 LegacyRegion2Decode (
     63   IN  EFI_LEGACY_REGION2_PROTOCOL  *This,
     64   IN  UINT32                       Start,
     65   IN  UINT32                       Length,
     66   OUT UINT32                       *Granularity,
     67   IN  BOOLEAN                      *On
     68   )
     69 {
     70   return QNCLegacyRegionManipulation (Start, Length, On, NULL, Granularity);
     71 }
     72 
     73 
     74 /**
     75   Modify the hardware to disallow memory attribute changes in a region.
     76 
     77   This function makes the attributes of a region read only. Once a region is boot-locked with this
     78   function, the read and write attributes of that region cannot be changed until a power cycle has
     79   reset the boot-lock attribute. Calls to Decode(), Lock() and Unlock() will have no effect.
     80 
     81   @param  This[in]              Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
     82   @param  Start[in]             The beginning of the physical address of the region whose
     83                                 attributes should be modified.
     84   @param  Length[in]            The number of bytes of memory whose attributes should be modified.
     85                                 The actual number of bytes modified may be greater than the number
     86                                 specified.
     87   @param  Granularity[out]      The number of bytes in the last region affected. This may be less
     88                                 than the total number of bytes affected if the starting address was
     89                                 not aligned to a region's starting address or if the length was
     90                                 greater than the number of bytes in the first region.
     91 
     92   @retval EFI_SUCCESS           The region's attributes were successfully modified.
     93   @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
     94   @retval EFI_UNSUPPORTED       The chipset does not support locking the configuration registers in
     95                                 a way that will not affect memory regions outside the legacy memory
     96                                 region.
     97 
     98 **/
     99 EFI_STATUS
    100 EFIAPI
    101 LegacyRegion2BootLock (
    102   IN  EFI_LEGACY_REGION2_PROTOCOL         *This,
    103   IN  UINT32                              Start,
    104   IN  UINT32                              Length,
    105   OUT UINT32                              *Granularity
    106   )
    107 {
    108   if ((Start < 0xC0000) || ((Start + Length - 1) > 0xFFFFF)) {
    109     return EFI_INVALID_PARAMETER;
    110   }
    111 
    112   return EFI_UNSUPPORTED;
    113 }
    114 
    115 
    116 /**
    117   Modify the hardware to disallow memory writes in a region.
    118 
    119   This function changes the attributes of a memory range to not allow writes.
    120 
    121   @param  This[in]              Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
    122   @param  Start[in]             The beginning of the physical address of the region whose
    123                                 attributes should be modified.
    124   @param  Length[in]            The number of bytes of memory whose attributes should be modified.
    125                                 The actual number of bytes modified may be greater than the number
    126                                 specified.
    127   @param  Granularity[out]      The number of bytes in the last region affected. This may be less
    128                                 than the total number of bytes affected if the starting address was
    129                                 not aligned to a region's starting address or if the length was
    130                                 greater than the number of bytes in the first region.
    131 
    132   @retval EFI_SUCCESS           The region's attributes were successfully modified.
    133   @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
    134 
    135 **/
    136 EFI_STATUS
    137 EFIAPI
    138 LegacyRegion2Lock (
    139   IN  EFI_LEGACY_REGION2_PROTOCOL *This,
    140   IN  UINT32                      Start,
    141   IN  UINT32                      Length,
    142   OUT UINT32                      *Granularity
    143   )
    144 {
    145   BOOLEAN  WriteEnable;
    146 
    147   WriteEnable = FALSE;
    148   return QNCLegacyRegionManipulation (Start, Length, NULL, &WriteEnable, Granularity);
    149 }
    150 
    151 
    152 /**
    153   Modify the hardware to allow memory writes in a region.
    154 
    155   This function changes the attributes of a memory range to allow writes.
    156 
    157   @param  This[in]              Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
    158   @param  Start[in]             The beginning of the physical address of the region whose
    159                                 attributes should be modified.
    160   @param  Length[in]            The number of bytes of memory whose attributes should be modified.
    161                                 The actual number of bytes modified may be greater than the number
    162                                 specified.
    163   @param  Granularity[out]      The number of bytes in the last region affected. This may be less
    164                                 than the total number of bytes affected if the starting address was
    165                                 not aligned to a region's starting address or if the length was
    166                                 greater than the number of bytes in the first region.
    167 
    168   @retval EFI_SUCCESS           The region's attributes were successfully modified.
    169   @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
    170 
    171 **/
    172 EFI_STATUS
    173 EFIAPI
    174 LegacyRegion2Unlock (
    175   IN  EFI_LEGACY_REGION2_PROTOCOL  *This,
    176   IN  UINT32                       Start,
    177   IN  UINT32                       Length,
    178   OUT UINT32                       *Granularity
    179   )
    180 {
    181   BOOLEAN  WriteEnable;
    182 
    183   WriteEnable = TRUE;
    184   return QNCLegacyRegionManipulation (Start, Length, NULL, &WriteEnable, Granularity);
    185 }
    186 
    187 /**
    188   Get region information for the attributes of the Legacy Region.
    189 
    190   This function is used to discover the granularity of the attributes for the memory in the legacy
    191   region. Each attribute may have a different granularity and the granularity may not be the same
    192   for all memory ranges in the legacy region.
    193 
    194   @param  This[in]              Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
    195   @param  DescriptorCount[out]  The number of region descriptor entries returned in the Descriptor
    196                                 buffer.
    197   @param  Descriptor[out]       A pointer to a pointer used to return a buffer where the legacy
    198                                 region information is deposited. This buffer will contain a list of
    199                                 DescriptorCount number of region descriptors.  This function will
    200                                 provide the memory for the buffer.
    201 
    202   @retval EFI_SUCCESS           The region's attributes were successfully modified.
    203   @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
    204 
    205 **/
    206 EFI_STATUS
    207 EFIAPI
    208 LegacyRegionGetInfo (
    209   IN  EFI_LEGACY_REGION2_PROTOCOL   *This,
    210   OUT UINT32                        *DescriptorCount,
    211   OUT EFI_LEGACY_REGION_DESCRIPTOR  **Descriptor
    212   )
    213 {
    214 
    215   return EFI_UNSUPPORTED;
    216 }
    217 
    218 /**
    219   Entry point to the DXE Driver that produces the Legacy Region Protocol.
    220 
    221   @retval  EFI_SUCCESS One or more of the drivers returned a success code.
    222   @retval  !EFI_SUCESS The return status from the last driver entry point in the list.
    223 
    224 **/
    225 EFI_STATUS
    226 LegacyRegionInit (
    227   )
    228 {
    229   EFI_STATUS  Status;
    230 
    231   //
    232   // Install the Legacy Region Protocol on a new handle
    233   //
    234   Status = gBS->InstallMultipleProtocolInterfaces (
    235                   &mLegacyRegion2Handle,
    236                   &gEfiLegacyRegion2ProtocolGuid, &mLegacyRegion2,
    237                   NULL
    238                   );
    239 
    240   ASSERT_EFI_ERROR (Status);
    241 
    242   return Status;
    243 }
    244