]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/FrameworkHiiLib/HiiLib.c
25c0f28868911bc43dffecd337f0e387036ac208
[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 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 **/
114 EFI_HII_PACKAGES *
115 EFIAPI
116 PreparePackages (
117 IN UINTN NumberOfPackages,
118 IN CONST EFI_GUID *Guid OPTIONAL,
119 ...
120 )
121 {
122 VA_LIST Args;
123
124 VA_START (Args, Guid);
125
126 return InternalPreparePackages (NumberOfPackages, Guid, Args);
127 }
128
129
130 /**
131 This function allocates pool for an EFI_HII_PACKAGE_LIST structure
132 with additional space that is big enough to host all packages described by the variable
133 argument list of package pointers. The allocated structure is initialized using NumberOfPackages,
134 GuidId, and the variable length argument list of package pointers.
135
136 Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The
137 Handle to the newly registered Package List is returned throught HiiHandle.
138
139 @param NumberOfPackages The number of HII packages to register.
140 @param GuidId Package List GUID ID.
141 @param DriverHandle The pointer of driver handle
142 @param HiiHandle The ID used to retrieve the Package List later.
143 @param ... The variable argument list describing all HII Package.
144
145 @return
146 The allocated and initialized packages.
147
148 **/
149 EFI_STATUS
150 EFIAPI
151 HiiLibAddPackages (
152 IN UINTN NumberOfPackages,
153 IN CONST EFI_GUID *GuidId,
154 IN EFI_HANDLE DriverHandle, OPTIONAL
155 OUT EFI_HII_HANDLE *HiiHandle, OPTIONAL
156 ...
157 )
158 {
159 VA_LIST Args;
160 EFI_HII_PACKAGES *FrameworkHiiPacages;
161 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;
162 EFI_STATUS Status;
163
164
165 VA_START (Args, HiiHandle);
166 FrameworkHiiPacages = InternalPreparePackages (NumberOfPackages, GuidId, Args);
167
168 Status = mHii->NewPack (mHii, FrameworkHiiPacages, &FrameworkHiiHandle);
169 if (HiiHandle != NULL) {
170 if (EFI_ERROR (Status)) {
171 *HiiHandle = NULL;
172 } else {
173 *HiiHandle = (EFI_HII_HANDLE) (UINTN) FrameworkHiiHandle;
174 }
175 }
176
177 FreePool (FrameworkHiiPacages);
178
179 return Status;
180 }
181
182 /**
183 Removes a package list from the default HII database.
184
185 If HiiHandle is NULL, then ASSERT.
186 If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.
187
188 @param HiiHandle The handle that was previously registered to the data base that is requested for removal.
189 List later.
190
191 @return VOID
192
193 **/
194 VOID
195 EFIAPI
196 HiiLibRemovePackages (
197 IN EFI_HII_HANDLE HiiHandle
198 )
199 {
200 EFI_STATUS Status;
201
202 Status = mHii->RemovePack (mHii, (FRAMEWORK_EFI_HII_HANDLE) (UINTN) HiiHandle);
203 ASSERT_EFI_ERROR (Status);
204 }
205
206
207 /**
208 This function adds the string into String Package of each language.
209
210 @param PackageList Handle of the package list where this string will
211 be added.
212 @param StringId On return, contains the new strings id, which is
213 unique within PackageList.
214 @param String Points to the new null-terminated string.
215
216 @retval EFI_SUCCESS The new string was added successfully.
217 @retval EFI_NOT_FOUND The specified PackageList could not be found in
218 database.
219 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
220 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL is NULL.
221
222 **/
223 EFI_STATUS
224 EFIAPI
225 HiiLibNewString (
226 IN EFI_HII_HANDLE PackageList,
227 OUT EFI_STRING_ID *StringId,
228 IN CONST EFI_STRING String
229 )
230 {
231 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;
232 EFI_STATUS Status;
233
234 FrameworkHiiHandle = (FRAMEWORK_EFI_HII_HANDLE) (UINTN) PackageList;
235 Status = mHii->NewString (
236 mHii,
237 NULL,
238 FrameworkHiiHandle,
239 StringId,
240 String
241 );
242
243 return Status;
244 }
245
246 /**
247 Get the string given the StringId and String package Producer's Guid. The caller
248 is responsible to free the *String.
249
250 If PackageList with the matching ProducerGuid is not found, then ASSERT.
251 If PackageList with the matching ProducerGuid is found but no String is
252 specified by StringId is found, then ASSERT.
253
254 @param ProducerGuid The Guid of String package list.
255 @param StringId The String ID.
256 @param String The output string.
257
258 @retval EFI_SUCCESS Operation is successful.
259 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
260
261 **/
262 EFI_STATUS
263 EFIAPI
264 HiiLibGetStringFromToken (
265 IN EFI_GUID *ProducerGuid,
266 IN EFI_STRING_ID StringId,
267 OUT EFI_STRING *String
268 )
269 {
270 return EFI_SUCCESS;
271 }
272
273 /**
274 Get string specified by StringId form the HiiHandle. The caller
275 is responsible to free the *String.
276
277 If String is NULL, then ASSERT.
278 If HiiHandle could not be found in the default HII database, then ASSERT.
279 If StringId is not found in PackageList, then ASSERT.
280
281 @param PackageList The HII handle of package list.
282 @param StringId The String ID.
283 @param String The output string.
284
285 @retval EFI_NOT_FOUND String is not found.
286 @retval EFI_SUCCESS Operation is successful.
287 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
288
289 **/
290 EFI_STATUS
291 EFIAPI
292 HiiLibGetStringFromHandle (
293 IN EFI_HII_HANDLE PackageList,
294 IN EFI_STRING_ID StringId,
295 OUT EFI_STRING *String
296 )
297 {
298 return EFI_SUCCESS;
299 }
300
301 /**
302 Create the driver handle for HII driver. The protocol and
303 Package list of this driver wili be installed into this
304 driver handle.
305 The implement set DriverHandle to NULL simpliy to let
306 handle manager create a default new handle.
307
308 @param[out] DriverHandle the pointer of driver handle
309 @return always successful.
310 **/
311 EFI_STATUS
312 EFIAPI
313 HiiLibCreateHiiDriverHandle (
314 OUT EFI_HANDLE *DriverHandle
315 )
316 {
317 //
318 // Driver
319 // This implementation does nothing as DriverHandle concept only
320 // applies to UEFI HII specification.
321 //
322
323 *DriverHandle = NULL;
324
325 return EFI_SUCCESS;
326 }
327