1/** @file 2This is an example of how a driver retrieve HII data using HII Package List 3Protocol, and how to publish the HII data. 4 5Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR> 6This program and the accompanying materials 7are licensed and made available under the terms and conditions of the BSD License 8which accompanies this distribution. The full text of the license may be found at 9http://opensource.org/licenses/bsd-license.php 10 11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 14**/ 15 16#include <Uefi.h> 17#include <Guid/HiiResourceSampleHii.h> 18#include <Protocol/HiiPackageList.h> 19#include <Library/DevicePathLib.h> 20#include <Library/UefiDriverEntryPoint.h> 21#include <Library/UefiBootServicesTableLib.h> 22#include <Library/UefiHiiServicesLib.h> 23#include <Library/HiiLib.h> 24 25#pragma pack(1) 26/// 27/// HII specific Vendor Device Path definition. 28/// 29typedef struct { 30 VENDOR_DEVICE_PATH VendorDevicePath; 31 EFI_DEVICE_PATH_PROTOCOL End; 32} HII_VENDOR_DEVICE_PATH; 33#pragma pack() 34 35 36EFI_HII_HANDLE mHiiHandle = NULL; 37EFI_HANDLE mDriverHandle = NULL; 38 39HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath = { 40 { 41 { 42 HARDWARE_DEVICE_PATH, 43 HW_VENDOR_DP, 44 { 45 (UINT8) (sizeof (VENDOR_DEVICE_PATH)), 46 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) 47 } 48 }, 49 HII_RESOURCE_SAMPLE_FORM_SET_GUID 50 }, 51 { 52 END_DEVICE_PATH_TYPE, 53 END_ENTIRE_DEVICE_PATH_SUBTYPE, 54 { 55 (UINT8) (END_DEVICE_PATH_LENGTH), 56 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8) 57 } 58 } 59}; 60 61/** 62 Main entry for this driver. 63 64 @param[in] ImageHandle Image handle this driver. 65 @param[in] SystemTable Pointer to SystemTable. 66 67 @retval EFI_SUCESS This function always complete successfully. 68 69**/ 70EFI_STATUS 71EFIAPI 72HiiResourcesSampleInit ( 73 IN EFI_HANDLE ImageHandle, 74 IN EFI_SYSTEM_TABLE *SystemTable 75 ) 76{ 77 EFI_STATUS Status; 78 EFI_HII_PACKAGE_LIST_HEADER *PackageList; 79 80 // 81 // Retrieve HII package list from ImageHandle 82 // 83 Status = gBS->OpenProtocol ( 84 ImageHandle, 85 &gEfiHiiPackageListProtocolGuid, 86 (VOID **) &PackageList, 87 ImageHandle, 88 NULL, 89 EFI_OPEN_PROTOCOL_GET_PROTOCOL 90 ); 91 if (EFI_ERROR (Status)) { 92 return Status; 93 } 94 95 // 96 // Publish sample Fromset 97 // 98 Status = gBS->InstallProtocolInterface ( 99 &mDriverHandle, 100 &gEfiDevicePathProtocolGuid, 101 EFI_NATIVE_INTERFACE, 102 &mHiiVendorDevicePath 103 ); 104 if (EFI_ERROR (Status)) { 105 return Status; 106 } 107 108 // 109 // Publish HII package list to HII Database. 110 // 111 Status = gHiiDatabase->NewPackageList ( 112 gHiiDatabase, 113 PackageList, 114 mDriverHandle, 115 &mHiiHandle 116 ); 117 if (EFI_ERROR (Status)) { 118 return Status; 119 } 120 121 return EFI_SUCCESS; 122} 123 124/** 125 Unloads the application and its installed protocol. 126 127 @param[in] ImageHandle Handle that identifies the image to be unloaded. 128 129 @retval EFI_SUCCESS The image has been unloaded. 130**/ 131EFI_STATUS 132EFIAPI 133HiiResourcesSampleUnload ( 134 IN EFI_HANDLE ImageHandle 135 ) 136{ 137 if (mDriverHandle != NULL) { 138 gBS->UninstallProtocolInterface ( 139 mDriverHandle, 140 &gEfiDevicePathProtocolGuid, 141 &mHiiVendorDevicePath 142 ); 143 mDriverHandle = NULL; 144 } 145 146 if (mHiiHandle != NULL) { 147 HiiRemovePackages (mHiiHandle); 148 mHiiHandle = NULL; 149 } 150 151 return EFI_SUCCESS; 152} 153