Home | History | Annotate | Download | only in PciCfgOnPciCfg2Thunk
      1 /** @file
      2 Module produce PciCfgPpi on top of PciCfgPpi2.
      3 
      4 PIWG's PI specification replaces Inte's EFI Specification 1.10.
      5 EFI_PEI_PCI_CFG_PPI defined in Inte's EFI Specification 1.10 is replaced by
      6 EFI_PEI_PCI_CFG2_PPI in PI 1.0.
      7 This module produces PciCfgPpi on top of PciCfgPpi2. This module is used on platform when both of
      8 these two conditions are true:
      9 1) Framework module is present that consumes PCI CFG  AND
     10 2) PI module is present that produces PCI CFG2 but not PCI CFG
     11 
     12 The Usage of this module is rare since EDK II module IntelFrameworkModulePkg\Universal\PcatSingleSegmentPciCfgPei\PcatSingleSegmentPciCfgPei.inf
     13 that produce PCI CFG2 can also produce PCI CFG by setting Pcd Feature Flag gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPciCfgDisable
     14 to FALSE.
     15 
     16 
     17 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
     18 This program and the accompanying materials
     19 are licensed and made available under the terms and conditions of the BSD License
     20 which accompanies this distribution.  The full text of the license may be found at
     21 http://opensource.org/licenses/bsd-license.php
     22 
     23 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     24 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     25 Module Name:
     26 **/
     27 
     28 #include <PiPei.h>
     29 #include <Ppi/PciCfg.h>
     30 #include <Ppi/PciCfg2.h>
     31 #include <Library/DebugLib.h>
     32 
     33 //
     34 // Function Prototypes
     35 //
     36 
     37 /**
     38   Reads from a given location in the PCI configuration space.
     39 
     40   @param  PeiServices                   An indirect pointer to the PEI Services Table published by the PEI Foundation.
     41 
     42   @param  This                              Pointer to local data for the interface.
     43 
     44   @param  Width                           The width of the access. Enumerated in bytes.
     45                                                    See EFI_PEI_PCI_CFG_PPI_WIDTH above.
     46 
     47   @param  Address                       The physical address of the access. The format of
     48                                                   the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
     49 
     50   @param  Buffer                           A pointer to the buffer of data..
     51 
     52 
     53   @retval EFI_SUCCESS                 The function completed successfully.
     54 
     55   @retval EFI_DEVICE_ERROR        There was a problem with the transaction.
     56 
     57   @retval EFI_DEVICE_NOT_READY  The device is not capable of supporting the operation at this
     58                                                     time.
     59 
     60 **/
     61 EFI_STATUS
     62 EFIAPI
     63 PciCfgRead (
     64   IN EFI_PEI_SERVICES             **PeiServices,
     65   IN EFI_PEI_PCI_CFG_PPI          *This,
     66   IN EFI_PEI_PCI_CFG_PPI_WIDTH    Width,
     67   IN UINT64                       Address,
     68   IN OUT VOID                     *Buffer
     69   );
     70 
     71 /**
     72   Write to a given location in the PCI configuration space.
     73 
     74   @param  PeiServices                   An indirect pointer to the PEI Services Table published by the PEI Foundation.
     75 
     76   @param  This                              Pointer to local data for the interface.
     77 
     78   @param  Width                            The width of the access. Enumerated in bytes.
     79                                                     See EFI_PEI_PCI_CFG_PPI_WIDTH above.
     80 
     81   @param  Address                         The physical address of the access. The format of
     82                                                     the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
     83 
     84   @param  Buffer                            A pointer to the buffer of data..
     85 
     86 
     87   @retval EFI_SUCCESS                   The function completed successfully.
     88 
     89   @retval EFI_DEVICE_ERROR          There was a problem with the transaction.
     90 
     91   @retval EFI_DEVICE_NOT_READY  The device is not capable of supporting the operation at this
     92                                                      time.
     93 
     94 **/
     95 EFI_STATUS
     96 EFIAPI
     97 PciCfgWrite (
     98   IN EFI_PEI_SERVICES             **PeiServices,
     99   IN EFI_PEI_PCI_CFG_PPI          *This,
    100   IN EFI_PEI_PCI_CFG_PPI_WIDTH    Width,
    101   IN UINT64                       Address,
    102   IN OUT VOID                     *Buffer
    103   );
    104 
    105 /**
    106   PCI read-modify-write operation.
    107 
    108   @param  PeiServices                     An indirect pointer to the PEI Services Table
    109                                                       published by the PEI Foundation.
    110 
    111   @param  This                                Pointer to local data for the interface.
    112 
    113   @param  Width                             The width of the access. Enumerated in bytes. Type
    114                                                       EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
    115 
    116   @param  Address                           The physical address of the access.
    117 
    118   @param  SetBits                            Points to value to bitwise-OR with the read configuration value.
    119                                                       The size of the value is determined by Width.
    120 
    121   @param  ClearBits                         Points to the value to negate and bitwise-AND with the read configuration value.
    122                                                       The size of the value is determined by Width.
    123 
    124 
    125   @retval EFI_SUCCESS                   The function completed successfully.
    126 
    127   @retval EFI_DEVICE_ERROR          There was a problem with the transaction.
    128 
    129   @retval EFI_DEVICE_NOT_READY  The device is not capable of supporting
    130                                                     the operation at this time.
    131 
    132 **/
    133 EFI_STATUS
    134 EFIAPI
    135 PciCfgModify (
    136   IN EFI_PEI_SERVICES             **PeiServices,
    137   IN EFI_PEI_PCI_CFG_PPI          *This,
    138   IN EFI_PEI_PCI_CFG_PPI_WIDTH    Width,
    139   IN UINT64                       Address,
    140   IN UINTN                        SetBits,
    141   IN UINTN                        ClearBits
    142   );
    143 
    144 //
    145 // Module globals
    146 //
    147 EFI_PEI_PCI_CFG_PPI mPciCfgPpi = {
    148   PciCfgRead,
    149   PciCfgWrite,
    150   PciCfgModify,
    151 };
    152 
    153 EFI_PEI_PPI_DESCRIPTOR     mPpiListPciCfg = {
    154   (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
    155   &gEfiPciCfgPpiInServiceTableGuid,
    156   &mPciCfgPpi
    157 };
    158 
    159 /**
    160 
    161   Standard PEIM entry point.
    162 
    163   @param FileHandle   Handle of the file being invoked.
    164   @param PeiServices  General purpose services available to every PEIM.
    165 
    166   @retval EFI_SUCCESS The interface could be successfully installed.
    167 
    168 **/
    169 EFI_STATUS
    170 EFIAPI
    171 PeimInitializePciCfg (
    172   IN EFI_PEI_FILE_HANDLE     FileHandle,
    173   IN CONST EFI_PEI_SERVICES  **PeiServices
    174   )
    175 {
    176   //
    177   // Publish the PciCfgToPciCfg2 Thunk capability to other modules
    178   //
    179   return (*PeiServices)->InstallPpi (PeiServices, &mPpiListPciCfg);
    180 }
    181 
    182 /**
    183   Reads from a given location in the PCI configuration space.
    184 
    185   @param  PeiServices                   An indirect pointer to the PEI Services Table published by the PEI Foundation.
    186 
    187   @param  This                              Pointer to local data for the interface.
    188 
    189   @param  Width                           The width of the access. Enumerated in bytes.
    190                                                    See EFI_PEI_PCI_CFG_PPI_WIDTH above.
    191 
    192   @param  Address                       The physical address of the access. The format of
    193                                                   the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
    194 
    195   @param  Buffer                           A pointer to the buffer of data..
    196 
    197 
    198   @retval EFI_SUCCESS                 The function completed successfully.
    199 
    200   @retval EFI_DEVICE_ERROR        There was a problem with the transaction.
    201 
    202   @retval EFI_DEVICE_NOT_READY  The device is not capable of supporting the operation at this
    203                                                     time.
    204 
    205 **/
    206 EFI_STATUS
    207 EFIAPI
    208 PciCfgRead (
    209   IN EFI_PEI_SERVICES             **PeiServices,
    210   IN EFI_PEI_PCI_CFG_PPI          *This,
    211   IN EFI_PEI_PCI_CFG_PPI_WIDTH    Width,
    212   IN UINT64                       Address,
    213   IN OUT VOID                     *Buffer
    214   )
    215 {
    216   EFI_PEI_PCI_CFG2_PPI  *PciCfg2;
    217 
    218   PciCfg2 = (*PeiServices)->PciCfg;
    219 
    220   return PciCfg2->Read ((CONST EFI_PEI_SERVICES **)PeiServices, PciCfg2, Width, Address, Buffer);
    221 }
    222 
    223 
    224 /**
    225   Write to a given location in the PCI configuration space.
    226 
    227   @param  PeiServices                   An indirect pointer to the PEI Services Table published by the PEI Foundation.
    228 
    229   @param  This                              Pointer to local data for the interface.
    230 
    231   @param  Width                            The width of the access. Enumerated in bytes.
    232                                                     See EFI_PEI_PCI_CFG_PPI_WIDTH above.
    233 
    234   @param  Address                         The physical address of the access. The format of
    235                                                     the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.
    236 
    237   @param  Buffer                            A pointer to the buffer of data..
    238 
    239 
    240   @retval EFI_SUCCESS                   The function completed successfully.
    241 
    242   @retval EFI_DEVICE_ERROR          There was a problem with the transaction.
    243 
    244   @retval EFI_DEVICE_NOT_READY  The device is not capable of supporting the operation at this
    245                                                      time.
    246 
    247 **/
    248 EFI_STATUS
    249 EFIAPI
    250 PciCfgWrite (
    251   IN EFI_PEI_SERVICES             **PeiServices,
    252   IN EFI_PEI_PCI_CFG_PPI          *This,
    253   IN EFI_PEI_PCI_CFG_PPI_WIDTH    Width,
    254   IN UINT64                       Address,
    255   IN OUT VOID                     *Buffer
    256   )
    257 {
    258   EFI_PEI_PCI_CFG2_PPI  *PciCfg2;
    259 
    260   PciCfg2 = (*PeiServices)->PciCfg;
    261 
    262   return PciCfg2->Write ((CONST EFI_PEI_SERVICES **)PeiServices, PciCfg2, Width, Address, Buffer);
    263 }
    264 
    265 /**
    266   PCI read-modify-write operation.
    267 
    268   @param  PeiServices                     An indirect pointer to the PEI Services Table
    269                                                       published by the PEI Foundation.
    270 
    271   @param  This                                Pointer to local data for the interface.
    272 
    273   @param  Width                             The width of the access. Enumerated in bytes. Type
    274                                                       EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().
    275 
    276   @param  Address                           The physical address of the access.
    277 
    278   @param  SetBits                            Points to value to bitwise-OR with the read configuration value.
    279                                                       The size of the value is determined by Width.
    280 
    281   @param  ClearBits                         Points to the value to negate and bitwise-AND with the read configuration value.
    282                                                       The size of the value is determined by Width.
    283 
    284 
    285   @retval EFI_SUCCESS                   The function completed successfully.
    286 
    287   @retval EFI_DEVICE_ERROR          There was a problem with the transaction.
    288 
    289   @retval EFI_DEVICE_NOT_READY  The device is not capable of supporting
    290                                                     the operation at this time.
    291 
    292 **/
    293 EFI_STATUS
    294 EFIAPI
    295 PciCfgModify (
    296   IN EFI_PEI_SERVICES             **PeiServices,
    297   IN EFI_PEI_PCI_CFG_PPI          *This,
    298   IN EFI_PEI_PCI_CFG_PPI_WIDTH    Width,
    299   IN UINT64                       Address,
    300   IN UINTN                        SetBits,
    301   IN UINTN                        ClearBits
    302   )
    303 {
    304   EFI_PEI_PCI_CFG2_PPI  *PciCfg2;
    305 
    306   PciCfg2 = (*PeiServices)->PciCfg;
    307 
    308   return PciCfg2->Modify ((CONST EFI_PEI_SERVICES **)PeiServices, PciCfg2, Width, Address, &SetBits, &ClearBits);
    309 }
    310