2 This driver effectuates OVMF's platform configuration settings and exposes
5 Copyright (C) 2014, Red Hat, Inc.
6 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
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
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.
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>
24 #include "PlatformConfig.h"
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
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.
39 // Hence let's just stick with the tradition -- use a dedicated vendor device
40 // path, with the driver's FILE_GUID.
44 VENDOR_DEVICE_PATH VendorDevicePath
;
45 EFI_DEVICE_PATH_PROTOCOL End
;
49 STATIC PKG_DEVICE_PATH mPkgDevicePath
= {
55 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
) ),
56 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
) >> 8)
63 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
65 (UINT8
) (END_DEVICE_PATH_LENGTH
),
66 (UINT8
) (END_DEVICE_PATH_LENGTH
>> 8)
72 // The configuration interface between the HII engine (form display etc) and
75 STATIC EFI_HII_CONFIG_ACCESS_PROTOCOL mConfigAccess
;
78 // The handle representing our list of packages after installation.
80 STATIC EFI_HII_HANDLE mInstalledPackages
;
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.
86 // - The strings package receives its C identifier from the driver's BASE_NAME,
89 // - The forms package receives its C identifier from the VFR file's basename,
93 extern UINT8 PlatformDxeStrings
[];
94 extern UINT8 PlatformFormsBin
[];
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
115 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
116 IN CONST EFI_STRING Configuration
,
117 OUT EFI_STRING
*Progress
128 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
129 IN EFI_BROWSER_ACTION Action
,
130 IN EFI_QUESTION_ID QuestionId
,
132 IN OUT EFI_IFR_TYPE_VALUE
*Value
,
133 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
141 Load and execute the platform configuration.
143 @retval EFI_SUCCESS Configuration loaded and executed.
144 @return Status codes from PlatformConfigLoad().
149 ExecutePlatformConfig (
154 PLATFORM_CONFIG PlatformConfig
;
155 UINT64 OptionalElements
;
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
));
164 if (OptionalElements
& PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION
) {
166 // Pass the preferred resolution to GraphicsConsoleDxe via dynamic PCDs.
168 PcdSet32 (PcdVideoHorizontalResolution
,
169 PlatformConfig
.HorizontalResolution
);
170 PcdSet32 (PcdVideoVerticalResolution
,
171 PlatformConfig
.VerticalResolution
);
179 Entry point for this driver.
181 @param[in] ImageHandle Image handle of this driver.
182 @param[in] SystemTable Pointer to SystemTable.
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.
192 IN EFI_HANDLE ImageHandle
,
193 IN EFI_SYSTEM_TABLE
*SystemTable
198 ExecutePlatformConfig ();
200 mConfigAccess
.ExtractConfig
= &ExtractConfig
;
201 mConfigAccess
.RouteConfig
= &RouteConfig
;
202 mConfigAccess
.Callback
= &Callback
;
205 // Declare ourselves suitable for HII communication.
207 Status
= gBS
->InstallMultipleProtocolInterfaces (&ImageHandle
,
208 &gEfiDevicePathProtocolGuid
, &mPkgDevicePath
,
209 &gEfiHiiConfigAccessProtocolGuid
, &mConfigAccess
,
211 if (EFI_ERROR (Status
)) {
216 // Publish the HII package list to HII Database.
218 mInstalledPackages
= HiiAddPackages (
219 &gEfiCallerIdGuid
, // PackageListGuid
220 ImageHandle
, // associated DeviceHandle
221 PlatformDxeStrings
, // 1st package
222 PlatformFormsBin
, // 2nd package
225 if (mInstalledPackages
== NULL
) {
226 Status
= EFI_OUT_OF_RESOURCES
;
227 goto UninstallProtocols
;
233 gBS
->UninstallMultipleProtocolInterfaces (ImageHandle
,
234 &gEfiDevicePathProtocolGuid
, &mPkgDevicePath
,
235 &gEfiHiiConfigAccessProtocolGuid
, &mConfigAccess
,
243 @param[in] ImageHandle Handle that identifies the image to evict.
245 @retval EFI_SUCCESS The image has been unloaded.
250 IN EFI_HANDLE ImageHandle
253 HiiRemovePackages (mInstalledPackages
);
254 gBS
->UninstallMultipleProtocolInterfaces (ImageHandle
,
255 &gEfiDevicePathProtocolGuid
, &mPkgDevicePath
,
256 &gEfiHiiConfigAccessProtocolGuid
, &mConfigAccess
,