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