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