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