Home | History | Annotate | Download | only in CsmSupportLib
      1 /** @file
      2   Legacy Region Support
      3 
      4   Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
      5 
      6   This program and the accompanying materials are
      7   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 #ifndef _LEGACY_REGION_DXE_H_
     17 #define _LEGACY_REGION_DXE_H_
     18 
     19 #include <PiDxe.h>
     20 
     21 #include <Protocol/LegacyRegion2.h>
     22 
     23 #include <IndustryStandard/Pci.h>
     24 
     25 #include <Library/PciLib.h>
     26 #include <Library/PcdLib.h>
     27 #include <Library/DebugLib.h>
     28 #include <Library/MemoryAllocationLib.h>
     29 #include <Library/UefiBootServicesTableLib.h>
     30 
     31 #define PAM_PCI_BUS        0
     32 #define PAM_PCI_DEV        0
     33 #define PAM_PCI_FUNC       0
     34 
     35 #define REG_PAM0_OFFSET    0x59    // Programmable Attribute Map 0
     36 #define REG_PAM1_OFFSET    0x5a    // Programmable Attribute Map 1
     37 #define REG_PAM2_OFFSET    0x5b    // Programmable Attribute Map 2
     38 #define REG_PAM3_OFFSET    0x5c    // Programmable Attribute Map 3
     39 #define REG_PAM4_OFFSET    0x5d    // Programmable Attribute Map 4
     40 #define REG_PAM5_OFFSET    0x5e    // Programmable Attribute Map 5
     41 #define REG_PAM6_OFFSET    0x5f    // Programmable Attribute Map 6
     42 
     43 #define PAM_BASE_ADDRESS   0xc0000
     44 #define PAM_LIMIT_ADDRESS  BASE_1MB
     45 
     46 //
     47 // Describes Legacy Region blocks and status.
     48 //
     49 typedef struct {
     50   UINT32  Start;
     51   UINT32  Length;
     52   BOOLEAN ReadEnabled;
     53   BOOLEAN WriteEnabled;
     54 } LEGACY_MEMORY_SECTION_INFO;
     55 
     56 //
     57 // Provides a map of the PAM registers and bits used to set Read/Write access.
     58 //
     59 typedef struct {
     60   UINT8   PAMRegOffset;
     61   UINT8   ReadEnableData;
     62   UINT8   WriteEnableData;
     63 } PAM_REGISTER_VALUE;
     64 
     65 /**
     66   Modify the hardware to allow (decode) or disallow (not decode) memory reads in a region.
     67 
     68   If the On parameter evaluates to TRUE, this function enables memory reads in the address range
     69   Start to (Start + Length - 1).
     70   If the On parameter evaluates to FALSE, this function disables memory reads in the address range
     71   Start to (Start + Length - 1).
     72 
     73   @param  This[in]              Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
     74   @param  Start[in]             The beginning of the physical address of the region whose attributes
     75                                 should be modified.
     76   @param  Length[in]            The number of bytes of memory whose attributes should be modified.
     77                                 The actual number of bytes modified may be greater than the number
     78                                 specified.
     79   @param  Granularity[out]      The number of bytes in the last region affected. This may be less
     80                                 than the total number of bytes affected if the starting address
     81                                 was not aligned to a region's starting address or if the length
     82                                 was greater than the number of bytes in the first region.
     83   @param  On[in]                Decode / Non-Decode flag.
     84 
     85   @retval EFI_SUCCESS           The region's attributes were successfully modified.
     86   @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
     87 
     88 **/
     89 EFI_STATUS
     90 EFIAPI
     91 LegacyRegion2Decode (
     92   IN  EFI_LEGACY_REGION2_PROTOCOL  *This,
     93   IN  UINT32                       Start,
     94   IN  UINT32                       Length,
     95   OUT UINT32                       *Granularity,
     96   IN  BOOLEAN                      *On
     97   );
     98 
     99 /**
    100   Modify the hardware to disallow memory writes in a region.
    101 
    102   This function changes the attributes of a memory range to not allow writes.
    103 
    104   @param  This[in]              Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
    105   @param  Start[in]             The beginning of the physical address of the region whose
    106                                 attributes should be modified.
    107   @param  Length[in]            The number of bytes of memory whose attributes should be modified.
    108                                 The actual number of bytes modified may be greater than the number
    109                                 specified.
    110   @param  Granularity[out]      The number of bytes in the last region affected. This may be less
    111                                 than the total number of bytes affected if the starting address was
    112                                 not aligned to a region's starting address or if the length was
    113                                 greater than the number of bytes in the first region.
    114 
    115   @retval EFI_SUCCESS           The region's attributes were successfully modified.
    116   @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
    117 
    118 **/
    119 EFI_STATUS
    120 EFIAPI
    121 LegacyRegion2Lock (
    122   IN  EFI_LEGACY_REGION2_PROTOCOL *This,
    123   IN  UINT32                      Start,
    124   IN  UINT32                      Length,
    125   OUT UINT32                      *Granularity
    126   );
    127 
    128 /**
    129   Modify the hardware to disallow memory attribute changes in a region.
    130 
    131   This function makes the attributes of a region read only. Once a region is boot-locked with this
    132   function, the read and write attributes of that region cannot be changed until a power cycle has
    133   reset the boot-lock attribute. Calls to Decode(), Lock() and Unlock() will have no effect.
    134 
    135   @param  This[in]              Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
    136   @param  Start[in]             The beginning of the physical address of the region whose
    137                                 attributes should be modified.
    138   @param  Length[in]            The number of bytes of memory whose attributes should be modified.
    139                                 The actual number of bytes modified may be greater than the number
    140                                 specified.
    141   @param  Granularity[out]      The number of bytes in the last region affected. This may be less
    142                                 than the total number of bytes affected if the starting address was
    143                                 not aligned to a region's starting address or if the length was
    144                                 greater than the number of bytes in the first region.
    145 
    146   @retval EFI_SUCCESS           The region's attributes were successfully modified.
    147   @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
    148   @retval EFI_UNSUPPORTED       The chipset does not support locking the configuration registers in
    149                                 a way that will not affect memory regions outside the legacy memory
    150                                 region.
    151 
    152 **/
    153 EFI_STATUS
    154 EFIAPI
    155 LegacyRegion2BootLock (
    156   IN EFI_LEGACY_REGION2_PROTOCOL          *This,
    157   IN  UINT32                              Start,
    158   IN  UINT32                              Length,
    159   OUT UINT32                              *Granularity
    160   );
    161 
    162 /**
    163   Modify the hardware to allow memory writes in a region.
    164 
    165   This function changes the attributes of a memory range to allow writes.
    166 
    167   @param  This[in]              Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
    168   @param  Start[in]             The beginning of the physical address of the region whose
    169                                 attributes should be modified.
    170   @param  Length[in]            The number of bytes of memory whose attributes should be modified.
    171                                 The actual number of bytes modified may be greater than the number
    172                                 specified.
    173   @param  Granularity[out]      The number of bytes in the last region affected. This may be less
    174                                 than the total number of bytes affected if the starting address was
    175                                 not aligned to a region's starting address or if the length was
    176                                 greater than the number of bytes in the first region.
    177 
    178   @retval EFI_SUCCESS           The region's attributes were successfully modified.
    179   @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
    180 
    181 **/
    182 EFI_STATUS
    183 EFIAPI
    184 LegacyRegion2Unlock (
    185   IN  EFI_LEGACY_REGION2_PROTOCOL  *This,
    186   IN  UINT32                       Start,
    187   IN  UINT32                       Length,
    188   OUT UINT32                       *Granularity
    189   );
    190 
    191 /**
    192   Get region information for the attributes of the Legacy Region.
    193 
    194   This function is used to discover the granularity of the attributes for the memory in the legacy
    195   region. Each attribute may have a different granularity and the granularity may not be the same
    196   for all memory ranges in the legacy region.
    197 
    198   @param  This[in]              Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
    199   @param  DescriptorCount[out]  The number of region descriptor entries returned in the Descriptor
    200                                 buffer.
    201   @param  Descriptor[out]       A pointer to a pointer used to return a buffer where the legacy
    202                                 region information is deposited. This buffer will contain a list of
    203                                 DescriptorCount number of region descriptors.  This function will
    204                                 provide the memory for the buffer.
    205 
    206   @retval EFI_SUCCESS           The region's attributes were successfully modified.
    207   @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
    208 
    209 **/
    210 EFI_STATUS
    211 EFIAPI
    212 LegacyRegionGetInfo (
    213   IN  EFI_LEGACY_REGION2_PROTOCOL   *This,
    214   OUT UINT32                        *DescriptorCount,
    215   OUT EFI_LEGACY_REGION_DESCRIPTOR  **Descriptor
    216   );
    217 
    218 #endif
    219 
    220