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 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include <Uefi.h>
|
---|
11 | #include <Guid/HiiResourceSampleHii.h>
|
---|
12 | #include <Protocol/HiiPackageList.h>
|
---|
13 | #include <Library/DevicePathLib.h>
|
---|
14 | #include <Library/UefiDriverEntryPoint.h>
|
---|
15 | #include <Library/UefiBootServicesTableLib.h>
|
---|
16 | #include <Library/UefiHiiServicesLib.h>
|
---|
17 | #include <Library/HiiLib.h>
|
---|
18 |
|
---|
19 | #pragma pack(1)
|
---|
20 | ///
|
---|
21 | /// HII specific Vendor Device Path definition.
|
---|
22 | ///
|
---|
23 | typedef struct {
|
---|
24 | VENDOR_DEVICE_PATH VendorDevicePath;
|
---|
25 | EFI_DEVICE_PATH_PROTOCOL End;
|
---|
26 | } HII_VENDOR_DEVICE_PATH;
|
---|
27 | #pragma pack()
|
---|
28 |
|
---|
29 |
|
---|
30 | EFI_HII_HANDLE mHiiHandle = NULL;
|
---|
31 | EFI_HANDLE mDriverHandle = NULL;
|
---|
32 |
|
---|
33 | HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath = {
|
---|
34 | {
|
---|
35 | {
|
---|
36 | HARDWARE_DEVICE_PATH,
|
---|
37 | HW_VENDOR_DP,
|
---|
38 | {
|
---|
39 | (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
|
---|
40 | (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
|
---|
41 | }
|
---|
42 | },
|
---|
43 | HII_RESOURCE_SAMPLE_FORM_SET_GUID
|
---|
44 | },
|
---|
45 | {
|
---|
46 | END_DEVICE_PATH_TYPE,
|
---|
47 | END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
---|
48 | {
|
---|
49 | (UINT8) (END_DEVICE_PATH_LENGTH),
|
---|
50 | (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
|
---|
51 | }
|
---|
52 | }
|
---|
53 | };
|
---|
54 |
|
---|
55 | /**
|
---|
56 | Main entry for this driver.
|
---|
57 |
|
---|
58 | @param[in] ImageHandle Image handle this driver.
|
---|
59 | @param[in] SystemTable Pointer to SystemTable.
|
---|
60 |
|
---|
61 | @retval EFI_SUCESS This function always complete successfully.
|
---|
62 |
|
---|
63 | **/
|
---|
64 | EFI_STATUS
|
---|
65 | EFIAPI
|
---|
66 | HiiResourcesSampleInit (
|
---|
67 | IN EFI_HANDLE ImageHandle,
|
---|
68 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
69 | )
|
---|
70 | {
|
---|
71 | EFI_STATUS Status;
|
---|
72 | EFI_HII_PACKAGE_LIST_HEADER *PackageList;
|
---|
73 |
|
---|
74 | //
|
---|
75 | // Retrieve HII package list from ImageHandle
|
---|
76 | //
|
---|
77 | Status = gBS->OpenProtocol (
|
---|
78 | ImageHandle,
|
---|
79 | &gEfiHiiPackageListProtocolGuid,
|
---|
80 | (VOID **) &PackageList,
|
---|
81 | ImageHandle,
|
---|
82 | NULL,
|
---|
83 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
---|
84 | );
|
---|
85 | if (EFI_ERROR (Status)) {
|
---|
86 | return Status;
|
---|
87 | }
|
---|
88 |
|
---|
89 | //
|
---|
90 | // Publish sample Fromset
|
---|
91 | //
|
---|
92 | Status = gBS->InstallProtocolInterface (
|
---|
93 | &mDriverHandle,
|
---|
94 | &gEfiDevicePathProtocolGuid,
|
---|
95 | EFI_NATIVE_INTERFACE,
|
---|
96 | &mHiiVendorDevicePath
|
---|
97 | );
|
---|
98 | if (EFI_ERROR (Status)) {
|
---|
99 | return Status;
|
---|
100 | }
|
---|
101 |
|
---|
102 | //
|
---|
103 | // Publish HII package list to HII Database.
|
---|
104 | //
|
---|
105 | Status = gHiiDatabase->NewPackageList (
|
---|
106 | gHiiDatabase,
|
---|
107 | PackageList,
|
---|
108 | mDriverHandle,
|
---|
109 | &mHiiHandle
|
---|
110 | );
|
---|
111 | if (EFI_ERROR (Status)) {
|
---|
112 | return Status;
|
---|
113 | }
|
---|
114 |
|
---|
115 | return EFI_SUCCESS;
|
---|
116 | }
|
---|
117 |
|
---|
118 | /**
|
---|
119 | Unloads the application and its installed protocol.
|
---|
120 |
|
---|
121 | @param[in] ImageHandle Handle that identifies the image to be unloaded.
|
---|
122 |
|
---|
123 | @retval EFI_SUCCESS The image has been unloaded.
|
---|
124 | **/
|
---|
125 | EFI_STATUS
|
---|
126 | EFIAPI
|
---|
127 | HiiResourcesSampleUnload (
|
---|
128 | IN EFI_HANDLE ImageHandle
|
---|
129 | )
|
---|
130 | {
|
---|
131 | if (mDriverHandle != NULL) {
|
---|
132 | gBS->UninstallProtocolInterface (
|
---|
133 | mDriverHandle,
|
---|
134 | &gEfiDevicePathProtocolGuid,
|
---|
135 | &mHiiVendorDevicePath
|
---|
136 | );
|
---|
137 | mDriverHandle = NULL;
|
---|
138 | }
|
---|
139 |
|
---|
140 | if (mHiiHandle != NULL) {
|
---|
141 | HiiRemovePackages (mHiiHandle);
|
---|
142 | mHiiHandle = NULL;
|
---|
143 | }
|
---|
144 |
|
---|
145 | return EFI_SUCCESS;
|
---|
146 | }
|
---|