]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/FrameworkHiiLib/HiiLib.c
[Description]:
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkHiiLib / HiiLib.c
1 /** @file
2 HII Library implementation that uses DXE protocols and services.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 Module Name: HiiLib.c
14
15 **/
16
17
18 #include <FrameworkDxe.h>
19
20 #include <Protocol/FrameworkHii.h>
21
22
23 #include <Library/FrameworkHiiLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/MemoryAllocationLib.h>
26 #include <Library/UefiBootServicesTableLib.h>
27 #include <Library/BaseMemoryLib.h>
28
29 EFI_HII_PROTOCOL *mHii = NULL;
30
31 EFI_STATUS
32 EFIAPI
33 FrameworkHiiLibConstructor (
34 IN EFI_HANDLE ImageHandle,
35 IN EFI_SYSTEM_TABLE *SystemTable
36 )
37 {
38 EFI_STATUS Status;
39
40 Status = gBS->LocateProtocol (
41 &gEfiHiiProtocolGuid,
42 NULL,
43 (VOID **) &mHii
44 );
45 ASSERT_EFI_ERROR (Status);
46 ASSERT (mHii != NULL);
47
48 return EFI_SUCCESS;
49 }
50
51
52 EFI_HII_PACKAGES *
53 InternalPreparePackages (
54 IN UINTN NumberOfPackages,
55 IN CONST EFI_GUID *Guid OPTIONAL,
56 VA_LIST Marker
57 )
58 {
59 EFI_HII_PACKAGES *HiiPackages;
60 VOID **Package;
61 UINTN Index;
62
63 ASSERT (NumberOfPackages > 0);
64
65 HiiPackages = AllocateZeroPool (sizeof (EFI_HII_PACKAGES) + NumberOfPackages * sizeof (VOID *));
66 ASSERT (HiiPackages != NULL);
67
68 HiiPackages->GuidId = (EFI_GUID *) Guid;
69 HiiPackages->NumberOfPackages = NumberOfPackages;
70 Package = (VOID **) (((UINT8 *) HiiPackages) + sizeof (EFI_HII_PACKAGES));
71
72 for (Index = 0; Index < NumberOfPackages; Index++) {
73 *Package = VA_ARG (Marker, VOID *);
74 Package++;
75 }
76
77 return HiiPackages;
78
79 }
80
81
82 /**
83 This function allocates pool for an EFI_HII_PACKAGES structure
84 with enough space for the variable argument list of package pointers.
85 The allocated structure is initialized using NumberOfPackages, Guid,
86 and the variable length argument list of package pointers.
87
88 @param NumberOfPackages The number of HII packages to prepare.
89 @param Guid Package GUID.
90
91 @return The allocated and initialized packages.
92
93 **/
94 EFI_HII_PACKAGES *
95 EFIAPI
96 PreparePackages (
97 IN UINTN NumberOfPackages,
98 IN CONST EFI_GUID *Guid OPTIONAL,
99 ...
100 )
101 {
102 VA_LIST Args;
103
104 VA_START (Args, Guid);
105
106 return InternalPreparePackages (NumberOfPackages, Guid, Args);
107 }
108
109
110 /**
111 This function allocates pool for an EFI_HII_PACKAGE_LIST structure
112 with additional space that is big enough to host all packages described by the variable
113 argument list of package pointers. The allocated structure is initialized using NumberOfPackages,
114 GuidId, and the variable length argument list of package pointers.
115
116 Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The
117 Handle to the newly registered Package List is returned throught HiiHandle.
118
119 @param NumberOfPackages The number of HII packages to register.
120 @param GuidId Package List GUID ID.
121 @param HiiHandle The ID used to retrieve the Package List later.
122 @param ... The variable argument list describing all HII Package.
123
124 @return
125 The allocated and initialized packages.
126
127 **/
128
129 EFI_STATUS
130 EFIAPI
131 HiiLibAddPackages (
132 IN UINTN NumberOfPackages,
133 IN CONST EFI_GUID *GuidId,
134 IN EFI_HANDLE DriverHandle, OPTIONAL
135 OUT EFI_HII_HANDLE *HiiHandle, OPTIONAL
136 ...
137 )
138 {
139 VA_LIST Args;
140 EFI_HII_PACKAGES *FrameworkHiiPacages;
141 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;
142 EFI_STATUS Status;
143
144
145 VA_START (Args, HiiHandle);
146 FrameworkHiiPacages = InternalPreparePackages (NumberOfPackages, GuidId, Args);
147
148 Status = mHii->NewPack (mHii, FrameworkHiiPacages, &FrameworkHiiHandle);
149 if (HiiHandle != NULL) {
150 if (EFI_ERROR (Status)) {
151 *HiiHandle = NULL;
152 } else {
153 *HiiHandle = (EFI_HII_HANDLE) (UINTN) FrameworkHiiHandle;
154 }
155 }
156
157 FreePool (FrameworkHiiPacages);
158
159 return Status;
160 }
161
162 VOID
163 EFIAPI
164 HiiLibRemovePackages (
165 IN EFI_HII_HANDLE HiiHandle
166 )
167 {
168 EFI_STATUS Status;
169
170 Status = mHii->RemovePack (mHii, (FRAMEWORK_EFI_HII_HANDLE) (UINTN) HiiHandle);
171 ASSERT_EFI_ERROR (Status);
172 }
173
174
175 /**
176 This function adds the string into String Package of each language.
177
178 @param PackageList Handle of the package list where this string will
179 be added.
180 @param StringId On return, contains the new strings id, which is
181 unique within PackageList.
182 @param String Points to the new null-terminated string.
183
184 @retval EFI_SUCCESS The new string was added successfully.
185 @retval EFI_NOT_FOUND The specified PackageList could not be found in
186 database.
187 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
188 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL is NULL.
189
190 **/
191 EFI_STATUS
192 EFIAPI
193 HiiLibNewString (
194 IN EFI_HII_HANDLE PackageList,
195 OUT EFI_STRING_ID *StringId,
196 IN CONST EFI_STRING String
197 )
198 {
199 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;
200 EFI_STATUS Status;
201
202 FrameworkHiiHandle = (FRAMEWORK_EFI_HII_HANDLE) (UINTN) PackageList;
203 Status = mHii->NewString (
204 mHii,
205 NULL,
206 FrameworkHiiHandle,
207 StringId,
208 String
209 );
210
211 return Status;
212 }
213
214
215 EFI_STATUS
216 EFIAPI
217 HiiLibUpdateString (
218 IN EFI_HII_HANDLE PackageList,
219 IN EFI_STRING_ID StringId,
220 IN CONST EFI_STRING String
221 )
222 {
223 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;
224 EFI_STATUS Status;
225
226 FrameworkHiiHandle = (FRAMEWORK_EFI_HII_HANDLE) (UINTN) PackageList;
227 Status = mHii->NewString (
228 mHii,
229 NULL,
230 FrameworkHiiHandle,
231 &StringId,
232 String
233 );
234
235 return Status;
236 }
237
238 //
239 // Just use the UEFI prototype
240 //
241 EFI_STATUS
242 EFIAPI
243 HiiLibGetStringFromToken (
244 IN EFI_GUID *ProducerGuid,
245 IN EFI_STRING_ID StringId,
246 OUT EFI_STRING *String
247 )
248 {
249 return EFI_SUCCESS;
250 }
251
252 //
253 // Just use the UEFI prototype
254 //
255 EFI_STATUS
256 EFIAPI
257 HiiLibGetStringFromHandle (
258 IN EFI_HII_HANDLE PackageList,
259 IN EFI_STRING_ID StringId,
260 OUT EFI_STRING *String
261 )
262 {
263 return EFI_SUCCESS;
264 }
265
266 //
267 // Just use the UEFI prototype
268 //
269 EFI_STATUS
270 EFIAPI
271 HiiLibCreateHiiDriverHandle (
272 OUT EFI_HANDLE *DriverHandle
273 )
274 {
275 //
276 // Driver
277 // This implementation does nothing as DriverHandle concept only
278 // applies to UEFI HII specification.
279 //
280
281 *DriverHandle = NULL;
282
283 return EFI_SUCCESS;
284 }
285