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