Ronak Kanabar | 1ae366f | 2023-06-07 01:21:56 +0530 | [diff] [blame^] | 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 - 2018, Intel Corporation. All rights reserved.<BR> |
| 9 | SPDX-License-Identifier: BSD-2-Clause-Patent |
| 10 | |
| 11 | **/ |
| 12 | |
| 13 | #ifndef _SMM_MEM_LIB_H_ |
| 14 | #define _SMM_MEM_LIB_H_ |
| 15 | |
| 16 | /** |
| 17 | This function check if the buffer is valid per processor architecture and not overlap with SMRAM. |
| 18 | |
| 19 | @param Buffer The buffer start address to be checked. |
| 20 | @param Length The buffer length to be checked. |
| 21 | |
| 22 | @retval TRUE This buffer is valid per processor architecture and not overlap with SMRAM. |
| 23 | @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM. |
| 24 | **/ |
| 25 | BOOLEAN |
| 26 | EFIAPI |
| 27 | SmmIsBufferOutsideSmmValid ( |
| 28 | IN EFI_PHYSICAL_ADDRESS Buffer, |
| 29 | IN UINT64 Length |
| 30 | ); |
| 31 | |
| 32 | /** |
| 33 | Copies a source buffer (non-SMRAM) to a destination buffer (SMRAM). |
| 34 | |
| 35 | This function copies a source buffer (non-SMRAM) to a destination buffer (SMRAM). |
| 36 | It checks if source buffer is valid per processor architecture and not overlap with SMRAM. |
| 37 | If the check passes, it copies memory and returns EFI_SUCCESS. |
| 38 | If the check fails, it return EFI_SECURITY_VIOLATION. |
| 39 | The implementation must be reentrant. |
| 40 | |
| 41 | @param DestinationBuffer The pointer to the destination buffer of the memory copy. |
| 42 | @param SourceBuffer The pointer to the source buffer of the memory copy. |
| 43 | @param Length The number of bytes to copy from SourceBuffer to DestinationBuffer. |
| 44 | |
| 45 | @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per processor architecture or overlap with SMRAM. |
| 46 | @retval EFI_SUCCESS Memory is copied. |
| 47 | |
| 48 | **/ |
| 49 | EFI_STATUS |
| 50 | EFIAPI |
| 51 | SmmCopyMemToSmram ( |
| 52 | OUT VOID *DestinationBuffer, |
| 53 | IN CONST VOID *SourceBuffer, |
| 54 | IN UINTN Length |
| 55 | ); |
| 56 | |
| 57 | /** |
| 58 | Copies a source buffer (SMRAM) to a destination buffer (NON-SMRAM). |
| 59 | |
| 60 | This function copies a source buffer (non-SMRAM) to a destination buffer (SMRAM). |
| 61 | It checks if destination buffer is valid per processor architecture and not overlap with SMRAM. |
| 62 | If the check passes, it copies memory and returns EFI_SUCCESS. |
| 63 | If the check fails, it returns EFI_SECURITY_VIOLATION. |
| 64 | The implementation must be reentrant. |
| 65 | |
| 66 | @param DestinationBuffer The pointer to the destination buffer of the memory copy. |
| 67 | @param SourceBuffer The pointer to the source buffer of the memory copy. |
| 68 | @param Length The number of bytes to copy from SourceBuffer to DestinationBuffer. |
| 69 | |
| 70 | @retval EFI_SECURITY_VIOLATION The DestinationBuffer is invalid per processor architecture or overlap with SMRAM. |
| 71 | @retval EFI_SUCCESS Memory is copied. |
| 72 | |
| 73 | **/ |
| 74 | EFI_STATUS |
| 75 | EFIAPI |
| 76 | SmmCopyMemFromSmram ( |
| 77 | OUT VOID *DestinationBuffer, |
| 78 | IN CONST VOID *SourceBuffer, |
| 79 | IN UINTN Length |
| 80 | ); |
| 81 | |
| 82 | /** |
| 83 | Copies a source buffer (NON-SMRAM) to a destination buffer (NON-SMRAM). |
| 84 | |
| 85 | This function copies a source buffer (non-SMRAM) to a destination buffer (SMRAM). |
| 86 | It checks if source buffer and destination buffer are valid per processor architecture and not overlap with SMRAM. |
| 87 | If the check passes, it copies memory and returns EFI_SUCCESS. |
| 88 | If the check fails, it returns EFI_SECURITY_VIOLATION. |
| 89 | The implementation must be reentrant, and it must handle the case where source buffer overlaps destination buffer. |
| 90 | |
| 91 | @param DestinationBuffer The pointer to the destination buffer of the memory copy. |
| 92 | @param SourceBuffer The pointer to the source buffer of the memory copy. |
| 93 | @param Length The number of bytes to copy from SourceBuffer to DestinationBuffer. |
| 94 | |
| 95 | @retval EFI_SECURITY_VIOLATION The DestinationBuffer is invalid per processor architecture or overlap with SMRAM. |
| 96 | @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per processor architecture or overlap with SMRAM. |
| 97 | @retval EFI_SUCCESS Memory is copied. |
| 98 | |
| 99 | **/ |
| 100 | EFI_STATUS |
| 101 | EFIAPI |
| 102 | SmmCopyMem ( |
| 103 | OUT VOID *DestinationBuffer, |
| 104 | IN CONST VOID *SourceBuffer, |
| 105 | IN UINTN Length |
| 106 | ); |
| 107 | |
| 108 | /** |
| 109 | Fills a target buffer (NON-SMRAM) with a byte value. |
| 110 | |
| 111 | This function fills a target buffer (non-SMRAM) with a byte value. |
| 112 | It checks if target buffer is valid per processor architecture and not overlap with SMRAM. |
| 113 | If the check passes, it fills memory and returns EFI_SUCCESS. |
| 114 | If the check fails, it returns EFI_SECURITY_VIOLATION. |
| 115 | |
| 116 | @param Buffer The memory to set. |
| 117 | @param Length The number of bytes to set. |
| 118 | @param Value The value with which to fill Length bytes of Buffer. |
| 119 | |
| 120 | @retval EFI_SECURITY_VIOLATION The Buffer is invalid per processor architecture or overlap with SMRAM. |
| 121 | @retval EFI_SUCCESS Memory is set. |
| 122 | |
| 123 | **/ |
| 124 | EFI_STATUS |
| 125 | EFIAPI |
| 126 | SmmSetMem ( |
| 127 | OUT VOID *Buffer, |
| 128 | IN UINTN Length, |
| 129 | IN UINT8 Value |
| 130 | ); |
| 131 | |
| 132 | #endif |