1 /*++ 2 3 Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved 4 5 6 This program and the accompanying materials are licensed and made available under 7 8 the terms and conditions of the BSD License that accompanies this distribution. 9 10 The full text of the license may be found at 11 12 http://opensource.org/licenses/bsd-license.php. 13 14 15 16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 17 18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 19 20 21 22 23 --*/ 24 25 /** @file 26 **/ 27 28 #include <Library/BaseMemoryLib.h> 29 #include <Library/DebugLib.h> 30 #include <Protocol/FirmwareVolume2.h> 31 #include <Protocol/PlatformGopPolicy.h> 32 33 #include <Guid/SetupVariable.h> 34 #include <SetupMode.h> 35 #include <Library/UefiRuntimeServicesTableLib.h> 36 37 EFI_BOOT_SERVICES *gBS; 38 39 40 PLATFORM_GOP_POLICY_PROTOCOL mPlatformGOPPolicy; 41 42 // 43 // Function implementations 44 // 45 46 /** 47 The function will excute with as the platform policy, and gives 48 the Platform Lid Status. IBV/OEM can customize this code for their specific GetPlatformLidStatus(OUT LID_STATUS * CurrentLidStatus)49 policy action. 50 51 @param CurrentLidStatus Gives the current LID Status 52 53 @retval EFI_SUCCESS. 54 55 **/ 56 EFI_STATUS 57 EFIAPI 58 GetPlatformLidStatus ( 59 OUT LID_STATUS *CurrentLidStatus 60 ) 61 { 62 *CurrentLidStatus = LidOpen; 63 64 return EFI_SUCCESS; 65 } 66 67 /** 68 The function will excute and gives the Video Bios Table Size and Address. 69 70 @param VbtAddress Gives the Physical Address of Video BIOS Table GetVbtData(OUT EFI_PHYSICAL_ADDRESS * VbtAddress,OUT UINT32 * VbtSize)71 72 @param VbtSize Gives the Size of Video BIOS Table 73 74 @retval EFI_STATUS. 75 76 **/ 77 78 EFI_STATUS 79 EFIAPI 80 GetVbtData ( 81 OUT EFI_PHYSICAL_ADDRESS *VbtAddress, 82 OUT UINT32 *VbtSize 83 ) 84 { 85 EFI_STATUS Status; 86 UINTN FvProtocolCount; 87 EFI_HANDLE *FvHandles; 88 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; 89 UINTN Index; 90 UINT32 AuthenticationStatus; 91 92 UINT8 *Buffer; 93 UINTN VbtBufferSize; 94 95 Buffer = 0; 96 FvHandles = NULL; 97 98 if (VbtAddress == NULL || VbtSize == NULL){ 99 return EFI_INVALID_PARAMETER; 100 } 101 Status = gBS->LocateHandleBuffer ( 102 ByProtocol, 103 &gEfiFirmwareVolume2ProtocolGuid, 104 NULL, 105 &FvProtocolCount, 106 &FvHandles 107 ); 108 109 if (!EFI_ERROR (Status)) { 110 for (Index = 0; Index < FvProtocolCount; Index++) { 111 Status = gBS->HandleProtocol ( 112 FvHandles[Index], 113 &gEfiFirmwareVolume2ProtocolGuid, 114 (VOID **) &Fv 115 ); 116 VbtBufferSize = 0; 117 Status = Fv->ReadSection ( 118 Fv, 119 &gBmpImageGuid, 120 EFI_SECTION_RAW, 121 0, 122 (void **)&Buffer, 123 &VbtBufferSize, 124 &AuthenticationStatus 125 ); 126 127 if (!EFI_ERROR (Status)) { 128 *VbtAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer; 129 *VbtSize = (UINT32)VbtBufferSize; 130 Status = EFI_SUCCESS; 131 break; 132 } 133 } 134 } else { 135 Status = EFI_NOT_FOUND; 136 } 137 138 if (FvHandles != NULL) { 139 gBS->FreePool (FvHandles); 140 FvHandles = NULL; 141 } 142 143 return Status; 144 } 145 146 /** 147 Entry point for the Platform GOP Policy Driver. 148 149 @param ImageHandle Image handle of this driver. PlatformGOPPolicyEntryPoint(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)150 @param SystemTable Global system service table. 151 152 @retval EFI_SUCCESS Initialization complete. 153 @retval EFI_OUT_OF_RESOURCES Do not have enough resources to initialize the driver. 154 155 **/ 156 157 EFI_STATUS 158 EFIAPI 159 PlatformGOPPolicyEntryPoint ( 160 IN EFI_HANDLE ImageHandle, 161 IN EFI_SYSTEM_TABLE *SystemTable 162 ) 163 164 { 165 EFI_STATUS Status = EFI_SUCCESS; 166 SYSTEM_CONFIGURATION SystemConfiguration; 167 UINTN VarSize; 168 169 170 gBS = SystemTable->BootServices; 171 172 gBS->SetMem ( 173 &mPlatformGOPPolicy, 174 sizeof (PLATFORM_GOP_POLICY_PROTOCOL), 175 0 176 ); 177 178 mPlatformGOPPolicy.Revision = PLATFORM_GOP_POLICY_PROTOCOL_REVISION_01; 179 mPlatformGOPPolicy.GetPlatformLidStatus = GetPlatformLidStatus; 180 mPlatformGOPPolicy.GetVbtData = GetVbtData; 181 182 // 183 // Install protocol to allow access to this Policy. 184 // 185 VarSize = sizeof(SYSTEM_CONFIGURATION); 186 Status = gRT->GetVariable( 187 L"Setup", 188 &gEfiNormalSetupGuid, 189 NULL, 190 &VarSize, 191 &SystemConfiguration 192 ); 193 if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) { 194 //The setup variable is corrupted 195 VarSize = sizeof(SYSTEM_CONFIGURATION); 196 Status = gRT->GetVariable( 197 L"SetupRecovery", 198 &gEfiNormalSetupGuid, 199 NULL, 200 &VarSize, 201 &SystemConfiguration 202 ); 203 ASSERT_EFI_ERROR (Status); 204 } 205 206 if (SystemConfiguration.GOPEnable == 1) 207 { 208 Status = gBS->InstallMultipleProtocolInterfaces ( 209 &ImageHandle, 210 &gPlatformGOPPolicyGuid, 211 &mPlatformGOPPolicy, 212 NULL 213 ); 214 } 215 216 return Status; 217 } 218