]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/PlatformDxe/Platform.c
OvmfPkg: PlatformDxe: add an empty HII form
[mirror_edk2.git] / OvmfPkg / PlatformDxe / Platform.c
1 /** @file
2 This driver effectuates OVMF's platform configuration settings and exposes
3 them via HII.
4
5 Copyright (C) 2014, Red Hat, Inc.
6 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
7
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 **/
16
17 #include <Library/DebugLib.h>
18 #include <Library/DevicePathLib.h>
19 #include <Library/HiiLib.h>
20 #include <Library/UefiBootServicesTableLib.h>
21 #include <Protocol/DevicePath.h>
22 #include <Protocol/HiiConfigAccess.h>
23
24 #include "PlatformConfig.h"
25
26 //
27 // The HiiAddPackages() library function requires that any controller (or
28 // image) handle, to be associated with the HII packages under installation, be
29 // "decorated" with a device path. The tradition seems to be a vendor device
30 // path.
31 //
32 // We'd like to associate our HII packages with the driver's image handle. The
33 // first idea is to use the driver image's device path. Unfortunately, loaded
34 // images only come with an EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL (not the
35 // usual EFI_DEVICE_PATH_PROTOCOL), ie. a different GUID. In addition, even the
36 // EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL interface may be NULL, if the image
37 // has been loaded from an "unnamed" memory source buffer.
38 //
39 // Hence let's just stick with the tradition -- use a dedicated vendor device
40 // path, with the driver's FILE_GUID.
41 //
42 #pragma pack(1)
43 typedef struct {
44 VENDOR_DEVICE_PATH VendorDevicePath;
45 EFI_DEVICE_PATH_PROTOCOL End;
46 } PKG_DEVICE_PATH;
47 #pragma pack()
48
49 STATIC PKG_DEVICE_PATH mPkgDevicePath = {
50 {
51 {
52 HARDWARE_DEVICE_PATH,
53 HW_VENDOR_DP,
54 {
55 (UINT8) (sizeof (VENDOR_DEVICE_PATH) ),
56 (UINT8) (sizeof (VENDOR_DEVICE_PATH) >> 8)
57 }
58 },
59 EFI_CALLER_ID_GUID
60 },
61 {
62 END_DEVICE_PATH_TYPE,
63 END_ENTIRE_DEVICE_PATH_SUBTYPE,
64 {
65 (UINT8) (END_DEVICE_PATH_LENGTH ),
66 (UINT8) (END_DEVICE_PATH_LENGTH >> 8)
67 }
68 }
69 };
70
71 //
72 // The configuration interface between the HII engine (form display etc) and
73 // this driver.
74 //
75 STATIC EFI_HII_CONFIG_ACCESS_PROTOCOL mConfigAccess;
76
77 //
78 // The handle representing our list of packages after installation.
79 //
80 STATIC EFI_HII_HANDLE mInstalledPackages;
81
82 //
83 // The arrays below constitute our HII package list. They are auto-generated by
84 // the VFR compiler and linked into the driver image during the build.
85 //
86 // - The strings package receives its C identifier from the driver's BASE_NAME,
87 // plus "Strings".
88 //
89 // - The forms package receives its C identifier from the VFR file's basename,
90 // plus "Bin".
91 //
92 //
93 extern UINT8 PlatformDxeStrings[];
94 extern UINT8 PlatformFormsBin[];
95
96
97 STATIC
98 EFI_STATUS
99 EFIAPI
100 ExtractConfig (
101 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
102 IN CONST EFI_STRING Request,
103 OUT EFI_STRING *Progress,
104 OUT EFI_STRING *Results
105 )
106 {
107 return EFI_SUCCESS;
108 }
109
110
111 STATIC
112 EFI_STATUS
113 EFIAPI
114 RouteConfig (
115 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
116 IN CONST EFI_STRING Configuration,
117 OUT EFI_STRING *Progress
118 )
119 {
120 return EFI_SUCCESS;
121 }
122
123
124 STATIC
125 EFI_STATUS
126 EFIAPI
127 Callback (
128 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
129 IN EFI_BROWSER_ACTION Action,
130 IN EFI_QUESTION_ID QuestionId,
131 IN UINT8 Type,
132 IN OUT EFI_IFR_TYPE_VALUE *Value,
133 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
134 )
135 {
136 return EFI_SUCCESS;
137 }
138
139
140 /**
141 Load and execute the platform configuration.
142
143 @retval EFI_SUCCESS Configuration loaded and executed.
144 @return Status codes from PlatformConfigLoad().
145 **/
146 STATIC
147 EFI_STATUS
148 EFIAPI
149 ExecutePlatformConfig (
150 VOID
151 )
152 {
153 EFI_STATUS Status;
154 PLATFORM_CONFIG PlatformConfig;
155 UINT64 OptionalElements;
156
157 Status = PlatformConfigLoad (&PlatformConfig, &OptionalElements);
158 if (EFI_ERROR (Status)) {
159 DEBUG (((Status == EFI_NOT_FOUND) ? EFI_D_VERBOSE : EFI_D_ERROR,
160 "%a: failed to load platform config: %r\n", __FUNCTION__, Status));
161 return Status;
162 }
163
164 if (OptionalElements & PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION) {
165 //
166 // Pass the preferred resolution to GraphicsConsoleDxe via dynamic PCDs.
167 //
168 PcdSet32 (PcdVideoHorizontalResolution,
169 PlatformConfig.HorizontalResolution);
170 PcdSet32 (PcdVideoVerticalResolution,
171 PlatformConfig.VerticalResolution);
172 }
173
174 return EFI_SUCCESS;
175 }
176
177
178 /**
179 Entry point for this driver.
180
181 @param[in] ImageHandle Image handle of this driver.
182 @param[in] SystemTable Pointer to SystemTable.
183
184 @retval EFI_SUCESS Driver has loaded successfully.
185 @retval EFI_OUT_OF_RESOURCES Failed to install HII packages.
186 @return Error codes from lower level functions.
187
188 **/
189 EFI_STATUS
190 EFIAPI
191 PlatformInit (
192 IN EFI_HANDLE ImageHandle,
193 IN EFI_SYSTEM_TABLE *SystemTable
194 )
195 {
196 EFI_STATUS Status;
197
198 ExecutePlatformConfig ();
199
200 mConfigAccess.ExtractConfig = &ExtractConfig;
201 mConfigAccess.RouteConfig = &RouteConfig;
202 mConfigAccess.Callback = &Callback;
203
204 //
205 // Declare ourselves suitable for HII communication.
206 //
207 Status = gBS->InstallMultipleProtocolInterfaces (&ImageHandle,
208 &gEfiDevicePathProtocolGuid, &mPkgDevicePath,
209 &gEfiHiiConfigAccessProtocolGuid, &mConfigAccess,
210 NULL);
211 if (EFI_ERROR (Status)) {
212 return Status;
213 }
214
215 //
216 // Publish the HII package list to HII Database.
217 //
218 mInstalledPackages = HiiAddPackages (
219 &gEfiCallerIdGuid, // PackageListGuid
220 ImageHandle, // associated DeviceHandle
221 PlatformDxeStrings, // 1st package
222 PlatformFormsBin, // 2nd package
223 NULL // terminator
224 );
225 if (mInstalledPackages == NULL) {
226 Status = EFI_OUT_OF_RESOURCES;
227 goto UninstallProtocols;
228 }
229
230 return EFI_SUCCESS;
231
232 UninstallProtocols:
233 gBS->UninstallMultipleProtocolInterfaces (ImageHandle,
234 &gEfiDevicePathProtocolGuid, &mPkgDevicePath,
235 &gEfiHiiConfigAccessProtocolGuid, &mConfigAccess,
236 NULL);
237 return Status;
238 }
239
240 /**
241 Unload the driver.
242
243 @param[in] ImageHandle Handle that identifies the image to evict.
244
245 @retval EFI_SUCCESS The image has been unloaded.
246 **/
247 EFI_STATUS
248 EFIAPI
249 PlatformUnload (
250 IN EFI_HANDLE ImageHandle
251 )
252 {
253 HiiRemovePackages (mInstalledPackages);
254 gBS->UninstallMultipleProtocolInterfaces (ImageHandle,
255 &gEfiDevicePathProtocolGuid, &mPkgDevicePath,
256 &gEfiHiiConfigAccessProtocolGuid, &mConfigAccess,
257 NULL);
258 return EFI_SUCCESS;
259 }