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