]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/FrameworkHiiLib/HiiLib.c
64b64c6ac365a3c21b21288ca58875aeaeb81ab8
[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 **/
14
15
16 #include <FrameworkDxe.h>
17
18 #include <Protocol/FrameworkHii.h>
19
20 #include <Library/FrameworkHiiLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24
25 EFI_HII_PROTOCOL *mHii = NULL;
26
27 /**
28 Library constustor function for HiiLib library instance locate the
29 gEfiHiiProtocolGuid firstly, the other interface in this library
30 instance will dependent on the protocol of gEfiHiiProtocolGuid.
31 So the depex of gEfiHiiProtocolGuid is required for this library
32 instance.
33 If protocol of gEfiHiiProtocolGuid is not installed, then ASSERT().
34
35 @param ImageHandle The image handle of driver module who use this library
36 instance.
37 @param SystemTable Pointer to the EFI System Table.
38 @retval EFI_SUCCESS library constuctor always success.
39 **/
40 EFI_STATUS
41 EFIAPI
42 FrameworkHiiLibConstructor (
43 IN EFI_HANDLE ImageHandle,
44 IN EFI_SYSTEM_TABLE *SystemTable
45 )
46 {
47 EFI_STATUS Status;
48
49 Status = gBS->LocateProtocol (
50 &gEfiHiiProtocolGuid,
51 NULL,
52 (VOID **) &mHii
53 );
54 ASSERT_EFI_ERROR (Status);
55 ASSERT (mHii != NULL);
56
57 return EFI_SUCCESS;
58 }
59
60 /**
61 This function is internal function that prepare and create
62 HII packages with given number and package's guid.
63 It is invoked by HiiAddPackages() and PreparePackages() interface.
64 If the parameter of package's number is 0, then ASSERT().
65
66 @param NumberOfPackages Given number of package item in a HII package list.
67 @param Guid Given GUID of a HII package list.
68 @param Marker Package's content list.
69
70 @return pointer to new created HII package list.
71 **/
72 EFI_HII_PACKAGES *
73 InternalPreparePackages (
74 IN UINTN NumberOfPackages,
75 IN CONST EFI_GUID *Guid OPTIONAL,
76 IN VA_LIST Marker
77 )
78 {
79 EFI_HII_PACKAGES *HiiPackages;
80 VOID **Package;
81 UINTN Index;
82
83 ASSERT (NumberOfPackages > 0);
84
85 HiiPackages = AllocateZeroPool (sizeof (EFI_HII_PACKAGES) + NumberOfPackages * sizeof (VOID *));
86 ASSERT (HiiPackages != NULL);
87
88 HiiPackages->GuidId = (EFI_GUID *) Guid;
89 HiiPackages->NumberOfPackages = NumberOfPackages;
90 Package = (VOID **) (((UINT8 *) HiiPackages) + sizeof (EFI_HII_PACKAGES));
91
92 for (Index = 0; Index < NumberOfPackages; Index++) {
93 *Package = VA_ARG (Marker, VOID *);
94 Package++;
95 }
96
97 return HiiPackages;
98
99 }
100
101 /**
102 This function allocates pool for an EFI_HII_PACKAGES structure
103 with enough space for the variable argument list of package pointers.
104 The allocated structure is initialized using NumberOfPackages, Guid,
105 and the variable length argument list of package pointers.
106
107 @param NumberOfPackages The number of HII packages to prepare.
108 @param Guid Package GUID.
109 @Param ... The variable argument list of package pointers.
110
111 @return The allocated and initialized packages.
112 **/
113 EFI_HII_PACKAGES *
114 EFIAPI
115 PreparePackages (
116 IN UINTN NumberOfPackages,
117 IN CONST EFI_GUID *Guid OPTIONAL,
118 ...
119 )
120 {
121 VA_LIST Args;
122
123 VA_START (Args, Guid);
124
125 return InternalPreparePackages (NumberOfPackages, Guid, Args);
126 }
127
128
129 /**
130 This function allocates pool for an EFI_HII_PACKAGE_LIST structure
131 with additional space that is big enough to host all packages described by the variable
132 argument list of package pointers. The allocated structure is initialized using NumberOfPackages,
133 GuidId, and the variable length argument list of package pointers.
134
135 Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The
136 Handle to the newly registered Package List is returned throught HiiHandle.
137
138 @param NumberOfPackages The number of HII packages to register.
139 @param GuidId Package List GUID ID.
140 @param DriverHandle The pointer of driver handle
141 @param HiiHandle The ID used to retrieve the Package List later.
142 @param ... The variable argument list describing all HII Package.
143
144 @return
145 The allocated and initialized packages.
146 **/
147 EFI_STATUS
148 EFIAPI
149 HiiLibAddPackages (
150 IN UINTN NumberOfPackages,
151 IN CONST EFI_GUID *GuidId,
152 IN EFI_HANDLE DriverHandle, OPTIONAL
153 OUT EFI_HII_HANDLE *HiiHandle, OPTIONAL
154 ...
155 )
156 {
157 VA_LIST Args;
158 EFI_HII_PACKAGES *FrameworkHiiPacages;
159 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;
160 EFI_STATUS Status;
161
162
163 VA_START (Args, HiiHandle);
164 FrameworkHiiPacages = InternalPreparePackages (NumberOfPackages, GuidId, Args);
165
166 Status = mHii->NewPack (mHii, FrameworkHiiPacages, &FrameworkHiiHandle);
167 if (HiiHandle != NULL) {
168 if (EFI_ERROR (Status)) {
169 *HiiHandle = NULL;
170 } else {
171 *HiiHandle = (EFI_HII_HANDLE) (UINTN) FrameworkHiiHandle;
172 }
173 }
174
175 FreePool (FrameworkHiiPacages);
176
177 return Status;
178 }
179
180 /**
181 Removes a package list from the default HII database.
182
183 If HiiHandle is NULL, then ASSERT.
184 If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.
185
186 @param HiiHandle The handle that was previously registered to the data base that is requested for removal.
187 List later.
188
189 @return VOID
190 **/
191 VOID
192 EFIAPI
193 HiiLibRemovePackages (
194 IN EFI_HII_HANDLE HiiHandle
195 )
196 {
197 EFI_STATUS Status;
198
199 Status = mHii->RemovePack (mHii, (FRAMEWORK_EFI_HII_HANDLE) (UINTN) HiiHandle);
200 ASSERT_EFI_ERROR (Status);
201 }
202
203
204 /**
205 This function adds the string into String Package of each language.
206
207 @param PackageList Handle of the package list where this string will
208 be added.
209 @param StringId On return, contains the new strings id, which is
210 unique within PackageList.
211 @param String Points to the new null-terminated string.
212
213 @retval EFI_SUCCESS The new string was added successfully.
214 @retval EFI_NOT_FOUND The specified PackageList could not be found in
215 database.
216 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
217 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL is NULL.
218
219 **/
220 EFI_STATUS
221 EFIAPI
222 HiiLibNewString (
223 IN EFI_HII_HANDLE PackageList,
224 OUT EFI_STRING_ID *StringId,
225 IN CONST EFI_STRING String
226 )
227 {
228 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;
229 EFI_STATUS Status;
230
231 FrameworkHiiHandle = (FRAMEWORK_EFI_HII_HANDLE) (UINTN) PackageList;
232 Status = mHii->NewString (
233 mHii,
234 NULL,
235 FrameworkHiiHandle,
236 StringId,
237 String
238 );
239
240 return Status;
241 }
242
243 /**
244 Get the string given the StringId and String package Producer's Guid. The caller
245 is responsible to free the *String.
246
247 If PackageList with the matching ProducerGuid is not found, then ASSERT.
248 If PackageList with the matching ProducerGuid is found but no String is
249 specified by StringId is found, then ASSERT.
250
251 @param ProducerGuid The Guid of String package list.
252 @param StringId The String ID.
253 @param String The output string.
254
255 @retval EFI_SUCCESS Operation is successful.
256 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
257
258 **/
259 EFI_STATUS
260 EFIAPI
261 HiiLibGetStringFromToken (
262 IN EFI_GUID *ProducerGuid,
263 IN EFI_STRING_ID StringId,
264 OUT EFI_STRING *String
265 )
266 {
267 return EFI_SUCCESS;
268 }
269
270 /**
271 Get string specified by StringId form the HiiHandle. The caller
272 is responsible to free the *String.
273
274 If String is NULL, then ASSERT.
275 If HiiHandle could not be found in the default HII database, then ASSERT.
276 If StringId is not found in PackageList, then ASSERT.
277
278 @param PackageList The HII handle of package list.
279 @param StringId The String ID.
280 @param String The output string.
281
282 @retval EFI_NOT_FOUND String is not found.
283 @retval EFI_SUCCESS Operation is successful.
284 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
285
286 **/
287 EFI_STATUS
288 EFIAPI
289 HiiLibGetStringFromHandle (
290 IN EFI_HII_HANDLE PackageList,
291 IN EFI_STRING_ID StringId,
292 OUT EFI_STRING *String
293 )
294 {
295 return EFI_SUCCESS;
296 }
297
298 /**
299 Create the driver handle for HII driver. The protocol and
300 Package list of this driver wili be installed into this
301 driver handle.
302 The implement set DriverHandle to NULL simpliy to let
303 handle manager create a default new handle.
304
305 @param[out] DriverHandle the pointer of driver handle
306 @return always successful.
307 **/
308 EFI_STATUS
309 EFIAPI
310 HiiLibCreateHiiDriverHandle (
311 OUT EFI_HANDLE *DriverHandle
312 )
313 {
314 //
315 // Driver
316 // This implementation does nothing as DriverHandle concept only
317 // applies to UEFI HII specification.
318 //
319
320 *DriverHandle = NULL;
321
322 return EFI_SUCCESS;
323 }
324