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