1 /** @file 2 3 A DXE_DRIVER providing SMRAM access by producing EFI_SMM_ACCESS2_PROTOCOL. 4 5 Q35 TSEG is expected to have been verified and set up by the SmmAccessPei 6 driver. 7 8 Copyright (C) 2013, 2015, Red Hat, Inc.<BR> 9 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR> 10 11 This program and the accompanying materials are licensed and made available 12 under the terms and conditions of the BSD License which accompanies this 13 distribution. The full text of the license may be found at 14 http://opensource.org/licenses/bsd-license.php 15 16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT 17 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 18 19 **/ 20 21 #include <Library/DebugLib.h> 22 #include <Library/PcdLib.h> 23 #include <Library/UefiBootServicesTableLib.h> 24 #include <Protocol/SmmAccess2.h> 25 26 #include "SmramInternal.h" 27 28 /** 29 Opens the SMRAM area to be accessible by a boot-service driver. 30 31 This function "opens" SMRAM so that it is visible while not inside of SMM. 32 The function should return EFI_UNSUPPORTED if the hardware does not support 33 hiding of SMRAM. The function should return EFI_DEVICE_ERROR if the SMRAM 34 configuration is locked. 35 36 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance. 37 38 @retval EFI_SUCCESS The operation was successful. 39 @retval EFI_UNSUPPORTED The system does not support opening and closing of 40 SMRAM. 41 @retval EFI_DEVICE_ERROR SMRAM cannot be opened, perhaps because it is 42 locked. 43 **/ 44 STATIC 45 EFI_STATUS 46 EFIAPI 47 SmmAccess2DxeOpen ( 48 IN EFI_SMM_ACCESS2_PROTOCOL *This 49 ) 50 { 51 return SmramAccessOpen (&This->LockState, &This->OpenState); 52 } 53 54 /** 55 Inhibits access to the SMRAM. 56 57 This function "closes" SMRAM so that it is not visible while outside of SMM. 58 The function should return EFI_UNSUPPORTED if the hardware does not support 59 hiding of SMRAM. 60 61 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance. 62 63 @retval EFI_SUCCESS The operation was successful. 64 @retval EFI_UNSUPPORTED The system does not support opening and closing of 65 SMRAM. 66 @retval EFI_DEVICE_ERROR SMRAM cannot be closed. 67 **/ 68 STATIC 69 EFI_STATUS 70 EFIAPI 71 SmmAccess2DxeClose ( 72 IN EFI_SMM_ACCESS2_PROTOCOL *This 73 ) 74 { 75 return SmramAccessClose (&This->LockState, &This->OpenState); 76 } 77 78 /** 79 Inhibits access to the SMRAM. 80 81 This function prohibits access to the SMRAM region. This function is usually 82 implemented such that it is a write-once operation. 83 84 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance. 85 86 @retval EFI_SUCCESS The device was successfully locked. 87 @retval EFI_UNSUPPORTED The system does not support locking of SMRAM. 88 **/ 89 STATIC 90 EFI_STATUS 91 EFIAPI 92 SmmAccess2DxeLock ( 93 IN EFI_SMM_ACCESS2_PROTOCOL *This 94 ) 95 { 96 return SmramAccessLock (&This->LockState, &This->OpenState); 97 } 98 99 /** 100 Queries the memory controller for the possible regions that will support 101 SMRAM. 102 103 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance. 104 @param[in,out] SmramMapSize A pointer to the size, in bytes, of the 105 SmramMemoryMap buffer. 106 @param[in,out] SmramMap A pointer to the buffer in which firmware 107 places the current memory map. 108 109 @retval EFI_SUCCESS The chipset supported the given resource. 110 @retval EFI_BUFFER_TOO_SMALL The SmramMap parameter was too small. The 111 current buffer size needed to hold the memory 112 map is returned in SmramMapSize. 113 **/ 114 STATIC 115 EFI_STATUS 116 EFIAPI 117 SmmAccess2DxeGetCapabilities ( 118 IN CONST EFI_SMM_ACCESS2_PROTOCOL *This, 119 IN OUT UINTN *SmramMapSize, 120 IN OUT EFI_SMRAM_DESCRIPTOR *SmramMap 121 ) 122 { 123 return SmramAccessGetCapabilities (This->LockState, This->OpenState, 124 SmramMapSize, SmramMap); 125 } 126 127 // 128 // LockState and OpenState will be filled in by the entry point. 129 // 130 STATIC EFI_SMM_ACCESS2_PROTOCOL mAccess2 = { 131 &SmmAccess2DxeOpen, 132 &SmmAccess2DxeClose, 133 &SmmAccess2DxeLock, 134 &SmmAccess2DxeGetCapabilities 135 }; 136 137 // 138 // Entry point of this driver. 139 // 140 EFI_STATUS 141 EFIAPI 142 SmmAccess2DxeEntryPoint ( 143 IN EFI_HANDLE ImageHandle, 144 IN EFI_SYSTEM_TABLE *SystemTable 145 ) 146 { 147 // 148 // This module should only be included if SMRAM support is required. 149 // 150 ASSERT (FeaturePcdGet (PcdSmmSmramRequire)); 151 152 GetStates (&mAccess2.LockState, &mAccess2.OpenState); 153 return gBS->InstallMultipleProtocolInterfaces (&ImageHandle, 154 &gEfiSmmAccess2ProtocolGuid, &mAccess2, 155 NULL); 156 } 157