Home | History | Annotate | Download | only in Library
      1 /** @file
      2   Provides services for SMM Memory Operation.
      3 
      4   The SMM Mem Library provides function for checking if buffer is outside SMRAM and valid.
      5   It also provides functions for copy data from SMRAM to non-SMRAM, from non-SMRAM to SMRAM,
      6   from non-SMRAM to non-SMRAM, or set data in non-SMRAM.
      7 
      8   Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
      9   This program and the accompanying materials
     10   are licensed and made available under the terms and conditions of the BSD License
     11   which accompanies this distribution.  The full text of the license may be found at
     12   http://opensource.org/licenses/bsd-license.php
     13 
     14   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     15   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     16 
     17 **/
     18 
     19 #ifndef _SMM_MEM_LIB_H_
     20 #define _SMM_MEM_LIB_H_
     21 
     22 /**
     23   This function check if the buffer is valid per processor architecture and not overlap with SMRAM.
     24 
     25   @param Buffer  The buffer start address to be checked.
     26   @param Length  The buffer length to be checked.
     27 
     28   @retval TRUE  This buffer is valid per processor architecture and not overlap with SMRAM.
     29   @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM.
     30 **/
     31 BOOLEAN
     32 EFIAPI
     33 SmmIsBufferOutsideSmmValid (
     34   IN EFI_PHYSICAL_ADDRESS  Buffer,
     35   IN UINT64                Length
     36   );
     37 
     38 /**
     39   Copies a source buffer (non-SMRAM) to a destination buffer (SMRAM).
     40 
     41   This function copies a source buffer (non-SMRAM) to a destination buffer (SMRAM).
     42   It checks if source buffer is valid per processor architecture and not overlap with SMRAM.
     43   If the check passes, it copies memory and returns EFI_SUCCESS.
     44   If the check fails, it return EFI_SECURITY_VIOLATION.
     45   The implementation must be reentrant.
     46 
     47   @param  DestinationBuffer   The pointer to the destination buffer of the memory copy.
     48   @param  SourceBuffer        The pointer to the source buffer of the memory copy.
     49   @param  Length              The number of bytes to copy from SourceBuffer to DestinationBuffer.
     50 
     51   @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per processor architecture or overlap with SMRAM.
     52   @retval EFI_SUCCESS            Memory is copied.
     53 
     54 **/
     55 EFI_STATUS
     56 EFIAPI
     57 SmmCopyMemToSmram (
     58   OUT VOID       *DestinationBuffer,
     59   IN CONST VOID  *SourceBuffer,
     60   IN UINTN       Length
     61   );
     62 
     63 /**
     64   Copies a source buffer (SMRAM) to a destination buffer (NON-SMRAM).
     65 
     66   This function copies a source buffer (non-SMRAM) to a destination buffer (SMRAM).
     67   It checks if destination buffer is valid per processor architecture and not overlap with SMRAM.
     68   If the check passes, it copies memory and returns EFI_SUCCESS.
     69   If the check fails, it returns EFI_SECURITY_VIOLATION.
     70   The implementation must be reentrant.
     71 
     72   @param  DestinationBuffer   The pointer to the destination buffer of the memory copy.
     73   @param  SourceBuffer        The pointer to the source buffer of the memory copy.
     74   @param  Length              The number of bytes to copy from SourceBuffer to DestinationBuffer.
     75 
     76   @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per processor architecture or overlap with SMRAM.
     77   @retval EFI_SUCCESS            Memory is copied.
     78 
     79 **/
     80 EFI_STATUS
     81 EFIAPI
     82 SmmCopyMemFromSmram (
     83   OUT VOID       *DestinationBuffer,
     84   IN CONST VOID  *SourceBuffer,
     85   IN UINTN       Length
     86   );
     87 
     88 /**
     89   Copies a source buffer (NON-SMRAM) to a destination buffer (NON-SMRAM).
     90 
     91   This function copies a source buffer (non-SMRAM) to a destination buffer (SMRAM).
     92   It checks if source buffer and destination buffer are valid per processor architecture and not overlap with SMRAM.
     93   If the check passes, it copies memory and returns EFI_SUCCESS.
     94   If the check fails, it returns EFI_SECURITY_VIOLATION.
     95   The implementation must be reentrant, and it must handle the case where source buffer overlaps destination buffer.
     96 
     97   @param  DestinationBuffer   The pointer to the destination buffer of the memory copy.
     98   @param  SourceBuffer        The pointer to the source buffer of the memory copy.
     99   @param  Length              The number of bytes to copy from SourceBuffer to DestinationBuffer.
    100 
    101   @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per processor architecture or overlap with SMRAM.
    102   @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per processor architecture or overlap with SMRAM.
    103   @retval EFI_SUCCESS            Memory is copied.
    104 
    105 **/
    106 EFI_STATUS
    107 EFIAPI
    108 SmmCopyMem (
    109   OUT VOID       *DestinationBuffer,
    110   IN CONST VOID  *SourceBuffer,
    111   IN UINTN       Length
    112   );
    113 
    114 /**
    115   Fills a target buffer (NON-SMRAM) with a byte value.
    116 
    117   This function fills a target buffer (non-SMRAM) with a byte value.
    118   It checks if target buffer is valid per processor architecture and not overlap with SMRAM.
    119   If the check passes, it fills memory and returns EFI_SUCCESS.
    120   If the check fails, it returns EFI_SECURITY_VIOLATION.
    121 
    122   @param  Buffer    The memory to set.
    123   @param  Length    The number of bytes to set.
    124   @param  Value     The value with which to fill Length bytes of Buffer.
    125 
    126   @retval EFI_SECURITY_VIOLATION The Buffer is invalid per processor architecture or overlap with SMRAM.
    127   @retval EFI_SUCCESS            Memory is set.
    128 
    129 **/
    130 EFI_STATUS
    131 EFIAPI
    132 SmmSetMem (
    133   OUT VOID  *Buffer,
    134   IN UINTN  Length,
    135   IN UINT8  Value
    136   );
    137 
    138 #endif