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