]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/HiiResourcesSampleDxe/HiiResourcesSample.c
Clean up the private GUID definition in module Level.
[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 - 2011, Intel Corporation. All rights reserved.<BR>
6 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 <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 ///
29 typedef struct {
30 VENDOR_DEVICE_PATH VendorDevicePath;
31 EFI_DEVICE_PATH_PROTOCOL End;
32 } HII_VENDOR_DEVICE_PATH;
33 #pragma pack()
34
35
36 EFI_HII_HANDLE mHiiHandle = NULL;
37 EFI_HANDLE mDriverHandle = NULL;
38
39 HII_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 **/
70 EFI_STATUS
71 EFIAPI
72 HiiResourcesSampleInit (
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 **/
131 EFI_STATUS
132 EFIAPI
133 HiiResourcesSampleUnload (
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 }