Home | History | Annotate | Download | only in I2CLibPei
      1 /** @file
      2   Functions for access I2C MMIO register.
      3 
      4   Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
      5   This program and the accompanying materials
      6   are licensed and made available under the terms and conditions of the BSD License
      7   which accompanies this distribution.  The full text of the license may be found at
      8   http://opensource.org/licenses/bsd-license.php.
      9 
     10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 
     13 **/
     14 
     15 #include <PiPei.h>
     16 #include <Library/DebugLib.h>
     17 #include <Library/PeiServicesTablePointerLib.h>
     18 
     19 /**
     20   Reads an 8-bit MMIO register.
     21 
     22   Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
     23   returned. This function must guarantee that all MMIO read and write
     24   operations are serialized.
     25 
     26   If 8-bit MMIO register operations are not supported, then ASSERT().
     27 
     28   @param  Address The MMIO register to read.
     29 
     30   @return The value read.
     31 
     32 **/
     33 UINT8
     34 EFIAPI
     35 I2CLibPeiMmioRead8 (
     36   IN UINTN Address
     37   )
     38 {
     39   UINT8 Value;
     40 
     41   Value = *(volatile UINT8*)Address;
     42   return Value;
     43 }
     44 
     45 /**
     46   Reads a 16-bit MMIO register.
     47 
     48   Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
     49   returned. This function must guarantee that all MMIO read and write
     50   operations are serialized.
     51 
     52   If 16-bit MMIO register operations are not supported, then ASSERT().
     53   If Address is not aligned on a 16-bit boundary, then ASSERT().
     54 
     55   @param  Address The MMIO register to read.
     56 
     57   @return The value read.
     58 
     59 **/
     60 UINT16
     61 EFIAPI
     62 I2CLibPeiMmioRead16 (
     63   IN UINTN  Address
     64   )
     65 {
     66   UINT16 Value;
     67 
     68   ASSERT ((Address & 1) == 0);
     69   Value = *(volatile UINT16*)Address;
     70   return Value;
     71 }
     72 
     73 /**
     74   Writes a 16-bit MMIO register.
     75 
     76   Writes the 16-bit MMIO register specified by Address with the value specified
     77   by Value and returns Value. This function must guarantee that all MMIO read
     78   and write operations are serialized.
     79 
     80   If 16-bit MMIO register operations are not supported, then ASSERT().
     81   If Address is not aligned on a 16-bit boundary, then ASSERT().
     82 
     83   @param  Address The MMIO register to write.
     84   @param  Value   The value to write to the MMIO register.
     85 
     86   @return Value.
     87 
     88 **/
     89 UINT16
     90 EFIAPI
     91 I2CLibPeiMmioWrite16 (
     92   IN  UINTN   Address,
     93   IN  UINT16  Value
     94   )
     95 {
     96   ASSERT ((Address & 1) == 0);
     97   *(volatile UINT16*)Address = Value;
     98   return Value;
     99 }
    100 
    101 /**
    102   Reads a 32-bit MMIO register.
    103 
    104   Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
    105   returned. This function must guarantee that all MMIO read and write
    106   operations are serialized.
    107 
    108   If 32-bit MMIO register operations are not supported, then ASSERT().
    109   If Address is not aligned on a 32-bit boundary, then ASSERT().
    110 
    111   @param  Address The MMIO register to read.
    112 
    113   @return The value read.
    114 
    115 **/
    116 UINT32
    117 EFIAPI
    118 I2CLibPeiMmioRead32 (
    119   IN UINTN Address
    120   )
    121 {
    122   UINT32  Value;
    123 
    124   ASSERT ((Address & 3) == 0);
    125   Value = *(volatile UINT32*)Address;
    126 
    127   return Value;
    128 }
    129 
    130 /**
    131   Writes a 32-bit MMIO register.
    132 
    133   Writes the 32-bit MMIO register specified by Address with the value specified
    134   by Value and returns Value. This function must guarantee that all MMIO read
    135   and write operations are serialized.
    136 
    137   If 32-bit MMIO register operations are not supported, then ASSERT().
    138   If Address is not aligned on a 32-bit boundary, then ASSERT().
    139 
    140   @param  Address The MMIO register to write.
    141   @param  Value   The value to write to the MMIO register.
    142 
    143   @return Value.
    144 
    145 **/
    146 UINT32
    147 EFIAPI
    148 I2CLibPeiMmioWrite32 (
    149   IN      UINTN                     Address,
    150   IN      UINT32                    Value
    151   )
    152 {
    153   ASSERT ((Address & 3) == 0);
    154   *(volatile UINT32*)Address = Value;
    155   return Value;
    156 }
    157 
    158 /**
    159   OR a 32-bit MMIO register.
    160 
    161   OR the 32-bit MMIO register specified by Address with the value specified
    162   by Value and returns Value. This function must guarantee that all MMIO read
    163   and write operations are serialized.
    164 
    165   If 32-bit MMIO register operations are not supported, then ASSERT().
    166   If Address is not aligned on a 32-bit boundary, then ASSERT().
    167 
    168   @param  Address The MMIO register to write OR.
    169   @param  Value   The value to OR to the MMIO register.
    170 
    171   @return Value.
    172 
    173 **/
    174 UINT32
    175 EFIAPI
    176 I2CLibPeiMmioOr32 (
    177   IN      UINTN                     Address,
    178   IN      UINT32                    OrData
    179   )
    180 {
    181   return I2CLibPeiMmioWrite32 (Address, I2CLibPeiMmioRead32(Address) | OrData);
    182 }
    183 
    184 
    185