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