]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/HiiResourcesSampleDxe/HiiResourcesSample.c
c86bb4c7420f47a7f4a4129e419a2d4941635e9c
[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.
112 //
113 Status = gHiiDatabase->NewPackageList (
114 gHiiDatabase,
115 PackageList,
116 mDriverHandle,
117 &mHiiHandle
118 );
119 if (EFI_ERROR (Status)) {
120 return Status;
121 }
122
123 return EFI_SUCCESS;
124 }
125
126 /**
127 Unloads the application and its installed protocol.
128
129 @param[in] ImageHandle Handle that identifies the image to be unloaded.
130
131 @retval EFI_SUCCESS The image has been unloaded.
132 **/
133 EFI_STATUS
134 EFIAPI
135 HiiResourcesSampleUnload (
136 IN EFI_HANDLE ImageHandle
137 )
138 {
139 if (mDriverHandle != NULL) {
140 gBS->UninstallProtocolInterface (
141 mDriverHandle,
142 &gEfiDevicePathProtocolGuid,
143 &mHiiVendorDevicePath
144 );
145 mDriverHandle = NULL;
146 }
147
148 if (mHiiHandle != NULL) {
149 HiiRemovePackages (mHiiHandle);
150 mHiiHandle = NULL;
151 }
152
153 return EFI_SUCCESS;
154 }