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