]>
Commit | Line | Data |
---|---|---|
20752cb8 HW |
1 | /** @file\r |
2 | HII Config Access protocol implementation of RamDiskDxe driver.\r | |
3 | \r | |
4 | Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r | |
124b18cf | 5 | (C) Copyright 2016-2018 Hewlett Packard Enterprise Development LP<BR>\r |
9c463f6f | 6 | Copyright (c) Microsoft Corporation.<BR>\r |
9d510e61 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
20752cb8 HW |
8 | \r |
9 | **/\r | |
10 | \r | |
11 | #include "RamDiskImpl.h"\r | |
12 | \r | |
13 | CHAR16 mRamDiskStorageName[] = L"RAM_DISK_CONFIGURATION";\r | |
14 | \r | |
1436aea4 | 15 | RAM_DISK_CONFIG_PRIVATE_DATA mRamDiskConfigPrivateDataTemplate = {\r |
20752cb8 | 16 | RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE,\r |
5cf8a917 | 17 | {\r |
4b1f4646 TS |
18 | EFI_PAGE_SIZE,\r |
19 | RAM_DISK_BOOT_SERVICE_DATA_MEMORY\r | |
5cf8a917 | 20 | },\r |
20752cb8 HW |
21 | {\r |
22 | RamDiskExtractConfig,\r | |
23 | RamDiskRouteConfig,\r | |
24 | RamDiskCallback\r | |
25 | }\r | |
26 | };\r | |
27 | \r | |
1436aea4 | 28 | HII_VENDOR_DEVICE_PATH mRamDiskHiiVendorDevicePath = {\r |
20752cb8 HW |
29 | {\r |
30 | {\r | |
31 | HARDWARE_DEVICE_PATH,\r | |
32 | HW_VENDOR_DP,\r | |
33 | {\r | |
1436aea4 MK |
34 | (UINT8)(sizeof (VENDOR_DEVICE_PATH)),\r |
35 | (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r | |
20752cb8 HW |
36 | }\r |
37 | },\r | |
38 | RAM_DISK_FORM_SET_GUID\r | |
39 | },\r | |
40 | {\r | |
41 | END_DEVICE_PATH_TYPE,\r | |
42 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
43 | {\r | |
1436aea4 MK |
44 | (UINT8)(END_DEVICE_PATH_LENGTH),\r |
45 | (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)\r | |
20752cb8 HW |
46 | }\r |
47 | }\r | |
48 | };\r | |
49 | \r | |
20752cb8 HW |
50 | /**\r |
51 | This function publish the RAM disk configuration Form.\r | |
52 | \r | |
53 | @param[in, out] ConfigPrivateData\r | |
54 | Points to RAM disk configuration private data.\r | |
55 | \r | |
56 | @retval EFI_SUCCESS HII Form is installed successfully.\r | |
57 | @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.\r | |
58 | @retval Others Other errors as indicated.\r | |
59 | \r | |
60 | **/\r | |
61 | EFI_STATUS\r | |
62 | InstallRamDiskConfigForm (\r | |
1436aea4 | 63 | IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData\r |
20752cb8 HW |
64 | )\r |
65 | {\r | |
66 | EFI_STATUS Status;\r | |
67 | EFI_HII_HANDLE HiiHandle;\r | |
68 | EFI_HANDLE DriverHandle;\r | |
69 | EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r | |
70 | \r | |
71 | DriverHandle = NULL;\r | |
72 | ConfigAccess = &ConfigPrivateData->ConfigAccess;\r | |
1436aea4 MK |
73 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
74 | &DriverHandle,\r | |
75 | &gEfiDevicePathProtocolGuid,\r | |
76 | &mRamDiskHiiVendorDevicePath,\r | |
77 | &gEfiHiiConfigAccessProtocolGuid,\r | |
78 | ConfigAccess,\r | |
79 | NULL\r | |
80 | );\r | |
20752cb8 HW |
81 | if (EFI_ERROR (Status)) {\r |
82 | return Status;\r | |
83 | }\r | |
84 | \r | |
85 | ConfigPrivateData->DriverHandle = DriverHandle;\r | |
86 | \r | |
87 | //\r | |
88 | // Publish the HII package list\r | |
89 | //\r | |
90 | HiiHandle = HiiAddPackages (\r | |
91 | &gRamDiskFormSetGuid,\r | |
92 | DriverHandle,\r | |
93 | RamDiskDxeStrings,\r | |
94 | RamDiskHiiBin,\r | |
95 | NULL\r | |
96 | );\r | |
97 | if (HiiHandle == NULL) {\r | |
98 | gBS->UninstallMultipleProtocolInterfaces (\r | |
99 | DriverHandle,\r | |
100 | &gEfiDevicePathProtocolGuid,\r | |
101 | &mRamDiskHiiVendorDevicePath,\r | |
102 | &gEfiHiiConfigAccessProtocolGuid,\r | |
103 | ConfigAccess,\r | |
104 | NULL\r | |
105 | );\r | |
106 | return EFI_OUT_OF_RESOURCES;\r | |
107 | }\r | |
108 | \r | |
109 | ConfigPrivateData->HiiHandle = HiiHandle;\r | |
110 | \r | |
111 | return EFI_SUCCESS;\r | |
112 | }\r | |
113 | \r | |
20752cb8 HW |
114 | /**\r |
115 | This function removes RAM disk configuration Form.\r | |
116 | \r | |
117 | @param[in, out] ConfigPrivateData\r | |
118 | Points to RAM disk configuration private data.\r | |
119 | \r | |
120 | **/\r | |
121 | VOID\r | |
122 | UninstallRamDiskConfigForm (\r | |
1436aea4 | 123 | IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData\r |
20752cb8 HW |
124 | )\r |
125 | {\r | |
126 | //\r | |
127 | // Uninstall HII package list\r | |
128 | //\r | |
129 | if (ConfigPrivateData->HiiHandle != NULL) {\r | |
130 | HiiRemovePackages (ConfigPrivateData->HiiHandle);\r | |
131 | ConfigPrivateData->HiiHandle = NULL;\r | |
132 | }\r | |
133 | \r | |
134 | //\r | |
135 | // Uninstall HII Config Access Protocol\r | |
136 | //\r | |
137 | if (ConfigPrivateData->DriverHandle != NULL) {\r | |
138 | gBS->UninstallMultipleProtocolInterfaces (\r | |
139 | ConfigPrivateData->DriverHandle,\r | |
140 | &gEfiDevicePathProtocolGuid,\r | |
141 | &mRamDiskHiiVendorDevicePath,\r | |
142 | &gEfiHiiConfigAccessProtocolGuid,\r | |
143 | &ConfigPrivateData->ConfigAccess,\r | |
144 | NULL\r | |
145 | );\r | |
146 | ConfigPrivateData->DriverHandle = NULL;\r | |
147 | }\r | |
148 | \r | |
149 | FreePool (ConfigPrivateData);\r | |
150 | }\r | |
151 | \r | |
20752cb8 HW |
152 | /**\r |
153 | Unregister all registered RAM disks.\r | |
154 | \r | |
155 | **/\r | |
156 | VOID\r | |
157 | UnregisterAllRamDisks (\r | |
158 | VOID\r | |
159 | )\r | |
160 | {\r | |
1436aea4 MK |
161 | LIST_ENTRY *Entry;\r |
162 | LIST_ENTRY *NextEntry;\r | |
163 | RAM_DISK_PRIVATE_DATA *PrivateData;\r | |
20752cb8 | 164 | \r |
1436aea4 | 165 | if (!IsListEmpty (&RegisteredRamDisks)) {\r |
9c463f6f | 166 | BASE_LIST_FOR_EACH_SAFE (Entry, NextEntry, &RegisteredRamDisks) {\r |
20752cb8 HW |
167 | PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);\r |
168 | \r | |
169 | gBS->UninstallMultipleProtocolInterfaces (\r | |
170 | PrivateData->Handle,\r | |
171 | &gEfiBlockIoProtocolGuid,\r | |
172 | &PrivateData->BlockIo,\r | |
216fefa3 HW |
173 | &gEfiBlockIo2ProtocolGuid,\r |
174 | &PrivateData->BlockIo2,\r | |
20752cb8 | 175 | &gEfiDevicePathProtocolGuid,\r |
1436aea4 | 176 | (EFI_DEVICE_PATH_PROTOCOL *)PrivateData->DevicePath,\r |
20752cb8 HW |
177 | NULL\r |
178 | );\r | |
179 | \r | |
180 | RemoveEntryList (&PrivateData->ThisInstance);\r | |
181 | \r | |
182 | if (RamDiskCreateHii == PrivateData->CreateMethod) {\r | |
183 | //\r | |
184 | // If a RAM disk is created within HII, then the RamDiskDxe driver\r | |
185 | // driver is responsible for freeing the allocated memory for the\r | |
186 | // RAM disk.\r | |
187 | //\r | |
1436aea4 | 188 | FreePool ((VOID *)(UINTN)PrivateData->StartingAddr);\r |
20752cb8 HW |
189 | }\r |
190 | \r | |
20752cb8 HW |
191 | FreePool (PrivateData->DevicePath);\r |
192 | FreePool (PrivateData);\r | |
20752cb8 HW |
193 | }\r |
194 | }\r | |
195 | }\r | |
196 | \r | |
20752cb8 HW |
197 | /**\r |
198 | This function allows a caller to extract the current configuration for one\r | |
199 | or more named elements from the target driver.\r | |
200 | \r | |
201 | @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
202 | @param[in] Request A null-terminated Unicode string in\r | |
203 | <ConfigRequest> format.\r | |
204 | @param[out] Progress On return, points to a character in the Request\r | |
205 | string. Points to the string's null terminator if\r | |
206 | request was successful. Points to the most recent\r | |
207 | '&' before the first failing name/value pair (or\r | |
208 | the beginning of the string if the failure is in\r | |
209 | the first name/value pair) if the request was not\r | |
210 | successful.\r | |
211 | @param[out] Results A null-terminated Unicode string in\r | |
212 | <ConfigAltResp> format which has all values filled\r | |
213 | in for the names in the Request string. String to\r | |
214 | be allocated by the called function.\r | |
215 | \r | |
216 | @retval EFI_SUCCESS The Results is filled with the requested\r | |
217 | values.\r | |
218 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r | |
219 | @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r | |
220 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in\r | |
221 | this driver.\r | |
222 | \r | |
223 | **/\r | |
224 | EFI_STATUS\r | |
225 | EFIAPI\r | |
226 | RamDiskExtractConfig (\r | |
1436aea4 MK |
227 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r |
228 | IN CONST EFI_STRING Request,\r | |
229 | OUT EFI_STRING *Progress,\r | |
230 | OUT EFI_STRING *Results\r | |
20752cb8 HW |
231 | )\r |
232 | {\r | |
1436aea4 | 233 | if ((Progress == NULL) || (Results == NULL)) {\r |
20752cb8 HW |
234 | return EFI_INVALID_PARAMETER;\r |
235 | }\r | |
1436aea4 | 236 | \r |
20752cb8 | 237 | *Progress = Request;\r |
5cf8a917 | 238 | return EFI_NOT_FOUND;\r |
20752cb8 HW |
239 | }\r |
240 | \r | |
20752cb8 HW |
241 | /**\r |
242 | This function processes the results of changes in configuration.\r | |
243 | \r | |
244 | @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
245 | @param[in] Configuration A null-terminated Unicode string in <ConfigResp>\r | |
246 | format.\r | |
247 | @param[out] Progress A pointer to a string filled in with the offset of\r | |
248 | the most recent '&' before the first failing\r | |
249 | name/value pair (or the beginning of the string if\r | |
250 | the failure is in the first name/value pair) or\r | |
251 | the terminating NULL if all was successful.\r | |
252 | \r | |
253 | @retval EFI_SUCCESS The Results is processed successfully.\r | |
254 | @retval EFI_INVALID_PARAMETER Configuration is NULL.\r | |
255 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in\r | |
256 | this driver.\r | |
257 | \r | |
258 | **/\r | |
259 | EFI_STATUS\r | |
260 | EFIAPI\r | |
261 | RamDiskRouteConfig (\r | |
1436aea4 MK |
262 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r |
263 | IN CONST EFI_STRING Configuration,\r | |
264 | OUT EFI_STRING *Progress\r | |
20752cb8 HW |
265 | )\r |
266 | {\r | |
1436aea4 | 267 | if ((Configuration == NULL) || (Progress == NULL)) {\r |
20752cb8 HW |
268 | return EFI_INVALID_PARAMETER;\r |
269 | }\r | |
270 | \r | |
124b18cf TP |
271 | *Progress = Configuration;\r |
272 | \r | |
5cf8a917 | 273 | return EFI_NOT_FOUND;\r |
20752cb8 HW |
274 | }\r |
275 | \r | |
20752cb8 HW |
276 | /**\r |
277 | Allocate memory and register the RAM disk created within RamDiskDxe\r | |
278 | driver HII.\r | |
279 | \r | |
280 | @param[in] Size If creating raw, size of the RAM disk to create.\r | |
281 | If creating from file, zero.\r | |
282 | @param[in] FileHandle If creating raw, NULL. If creating from file, the\r | |
283 | file handle.\r | |
4b1f4646 | 284 | @param[in] MemoryType Type of memory to be used to create RAM Disk.\r |
20752cb8 HW |
285 | \r |
286 | @retval EFI_SUCCESS RAM disk is created and registered.\r | |
287 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to match the\r | |
288 | size required.\r | |
289 | \r | |
290 | **/\r | |
291 | EFI_STATUS\r | |
292 | HiiCreateRamDisk (\r | |
1436aea4 MK |
293 | IN UINT64 Size,\r |
294 | IN EFI_FILE_HANDLE FileHandle,\r | |
295 | IN UINT8 MemoryType\r | |
20752cb8 HW |
296 | )\r |
297 | {\r | |
1436aea4 MK |
298 | EFI_STATUS Status;\r |
299 | UINTN BufferSize;\r | |
300 | UINT64 *StartingAddr;\r | |
301 | EFI_INPUT_KEY Key;\r | |
302 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
303 | RAM_DISK_PRIVATE_DATA *PrivateData;\r | |
304 | EFI_FILE_INFO *FileInformation;\r | |
20752cb8 HW |
305 | \r |
306 | FileInformation = NULL;\r | |
4b1f4646 | 307 | StartingAddr = NULL;\r |
20752cb8 HW |
308 | \r |
309 | if (FileHandle != NULL) {\r | |
310 | //\r | |
311 | // Create from file.\r | |
312 | //\r | |
313 | FileInformation = FileInfo (FileHandle);\r | |
314 | if (NULL == FileInformation) {\r | |
315 | do {\r | |
316 | CreatePopUp (\r | |
317 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
318 | &Key,\r | |
319 | L"",\r | |
320 | L"Not enough memory to get the file information!",\r | |
321 | L"Press ENTER to continue ...",\r | |
322 | L"",\r | |
323 | NULL\r | |
324 | );\r | |
325 | } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r | |
326 | \r | |
327 | return EFI_OUT_OF_RESOURCES;\r | |
328 | }\r | |
329 | \r | |
330 | //\r | |
331 | // Update the size of RAM disk according to the file size.\r | |
332 | //\r | |
333 | Size = FileInformation->FileSize;\r | |
334 | }\r | |
335 | \r | |
1436aea4 | 336 | if (Size > (UINTN)-1) {\r |
5cf8a917 HW |
337 | do {\r |
338 | CreatePopUp (\r | |
339 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
340 | &Key,\r | |
341 | L"",\r | |
342 | L"The given RAM disk size is too large!",\r | |
343 | L"Press ENTER to continue ...",\r | |
344 | L"",\r | |
345 | NULL\r | |
346 | );\r | |
347 | } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r | |
348 | \r | |
349 | return EFI_OUT_OF_RESOURCES;\r | |
350 | }\r | |
351 | \r | |
4b1f4646 TS |
352 | if (MemoryType == RAM_DISK_BOOT_SERVICE_DATA_MEMORY) {\r |
353 | Status = gBS->AllocatePool (\r | |
354 | EfiBootServicesData,\r | |
355 | (UINTN)Size,\r | |
1436aea4 | 356 | (VOID **)&StartingAddr\r |
4b1f4646 TS |
357 | );\r |
358 | } else if (MemoryType == RAM_DISK_RESERVED_MEMORY) {\r | |
359 | Status = gBS->AllocatePool (\r | |
360 | EfiReservedMemoryType,\r | |
361 | (UINTN)Size,\r | |
1436aea4 | 362 | (VOID **)&StartingAddr\r |
4b1f4646 TS |
363 | );\r |
364 | } else {\r | |
365 | Status = EFI_INVALID_PARAMETER;\r | |
366 | }\r | |
367 | \r | |
1436aea4 | 368 | if ((StartingAddr == NULL) || EFI_ERROR (Status)) {\r |
20752cb8 HW |
369 | do {\r |
370 | CreatePopUp (\r | |
371 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
372 | &Key,\r | |
373 | L"",\r | |
374 | L"Not enough memory to create the RAM disk!",\r | |
375 | L"Press ENTER to continue ...",\r | |
376 | L"",\r | |
377 | NULL\r | |
378 | );\r | |
379 | } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r | |
380 | \r | |
381 | return EFI_OUT_OF_RESOURCES;\r | |
382 | }\r | |
383 | \r | |
384 | if (FileHandle != NULL) {\r | |
385 | //\r | |
386 | // Copy the file content to the RAM disk.\r | |
387 | //\r | |
1436aea4 | 388 | BufferSize = (UINTN)Size;\r |
20752cb8 HW |
389 | FileHandle->Read (\r |
390 | FileHandle,\r | |
391 | &BufferSize,\r | |
1436aea4 | 392 | (VOID *)(UINTN)StartingAddr\r |
20752cb8 HW |
393 | );\r |
394 | if (BufferSize != FileInformation->FileSize) {\r | |
395 | do {\r | |
396 | CreatePopUp (\r | |
397 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
398 | &Key,\r | |
399 | L"",\r | |
400 | L"File content read error!",\r | |
401 | L"Press ENTER to continue ...",\r | |
402 | L"",\r | |
403 | NULL\r | |
404 | );\r | |
405 | } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r | |
406 | \r | |
407 | return EFI_DEVICE_ERROR;\r | |
408 | }\r | |
409 | }\r | |
410 | \r | |
411 | //\r | |
412 | // Register the newly created RAM disk.\r | |
413 | //\r | |
414 | Status = RamDiskRegister (\r | |
1436aea4 | 415 | ((UINT64)(UINTN)StartingAddr),\r |
20752cb8 HW |
416 | Size,\r |
417 | &gEfiVirtualDiskGuid,\r | |
418 | NULL,\r | |
419 | &DevicePath\r | |
420 | );\r | |
421 | if (EFI_ERROR (Status)) {\r | |
422 | do {\r | |
423 | CreatePopUp (\r | |
424 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r | |
425 | &Key,\r | |
426 | L"",\r | |
427 | L"Fail to register the newly created RAM disk!",\r | |
428 | L"Press ENTER to continue ...",\r | |
429 | L"",\r | |
430 | NULL\r | |
431 | );\r | |
432 | } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r | |
433 | \r | |
434 | return Status;\r | |
435 | }\r | |
436 | \r | |
437 | //\r | |
438 | // If RAM disk is created within HII, memory should be freed when the\r | |
439 | // RAM disk is unregisterd.\r | |
440 | //\r | |
1436aea4 | 441 | PrivateData = RAM_DISK_PRIVATE_FROM_THIS (RegisteredRamDisks.BackLink);\r |
20752cb8 HW |
442 | PrivateData->CreateMethod = RamDiskCreateHii;\r |
443 | \r | |
444 | return EFI_SUCCESS;\r | |
445 | }\r | |
446 | \r | |
20752cb8 HW |
447 | /**\r |
448 | This function updates the registered RAM disks list on the main form.\r | |
449 | \r | |
450 | @param[in, out] ConfigPrivate\r | |
451 | Private data for configurating hii data for RAM\r | |
452 | disks.\r | |
453 | \r | |
454 | **/\r | |
455 | VOID\r | |
456 | UpdateMainForm (\r | |
1436aea4 | 457 | IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate\r |
20752cb8 HW |
458 | )\r |
459 | {\r | |
1436aea4 MK |
460 | VOID *StartOpCodeHandle;\r |
461 | VOID *EndOpCodeHandle;\r | |
462 | EFI_IFR_GUID_LABEL *StartLabel;\r | |
463 | EFI_IFR_GUID_LABEL *EndLabel;\r | |
464 | LIST_ENTRY *Entry;\r | |
465 | UINTN Index;\r | |
466 | RAM_DISK_PRIVATE_DATA *PrivateData;\r | |
467 | CHAR16 *String;\r | |
468 | CHAR16 RamDiskStr[128];\r | |
469 | EFI_STRING_ID StringId;\r | |
20752cb8 HW |
470 | \r |
471 | //\r | |
472 | // Init OpCode Handle\r | |
473 | //\r | |
474 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
475 | ASSERT (StartOpCodeHandle != NULL);\r | |
476 | \r | |
477 | EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
478 | ASSERT (EndOpCodeHandle != NULL);\r | |
479 | \r | |
480 | //\r | |
481 | // Create Hii Extend Label OpCode as the start opcode\r | |
482 | //\r | |
1436aea4 MK |
483 | StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (\r |
484 | StartOpCodeHandle,\r | |
485 | &gEfiIfrTianoGuid,\r | |
486 | NULL,\r | |
487 | sizeof (EFI_IFR_GUID_LABEL)\r | |
488 | );\r | |
20752cb8 HW |
489 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r |
490 | StartLabel->Number = MAIN_LABEL_LIST_START;\r | |
491 | \r | |
492 | //\r | |
493 | // Create Hii Extend Label OpCode as the end opcode\r | |
494 | //\r | |
1436aea4 MK |
495 | EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (\r |
496 | EndOpCodeHandle,\r | |
497 | &gEfiIfrTianoGuid,\r | |
498 | NULL,\r | |
499 | sizeof (EFI_IFR_GUID_LABEL)\r | |
500 | );\r | |
20752cb8 HW |
501 | EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r |
502 | EndLabel->Number = MAIN_LABEL_LIST_END;\r | |
503 | \r | |
504 | Index = 0;\r | |
9c463f6f | 505 | BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {\r |
1436aea4 MK |
506 | PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);\r |
507 | PrivateData->CheckBoxId = (EFI_QUESTION_ID)\r | |
508 | (MAIN_CHECKBOX_QUESTION_ID_START + Index);\r | |
09abc636 HW |
509 | //\r |
510 | // CheckBox is unchecked by default.\r | |
511 | //\r | |
512 | PrivateData->CheckBoxChecked = FALSE;\r | |
513 | String = RamDiskStr;\r | |
20752cb8 HW |
514 | \r |
515 | UnicodeSPrint (\r | |
516 | String,\r | |
517 | sizeof (RamDiskStr),\r | |
518 | L" RAM Disk %d: [0x%lx, 0x%lx]\n",\r | |
519 | Index,\r | |
520 | PrivateData->StartingAddr,\r | |
5eae4ff0 | 521 | PrivateData->StartingAddr + PrivateData->Size - 1\r |
20752cb8 HW |
522 | );\r |
523 | \r | |
524 | StringId = HiiSetString (ConfigPrivate->HiiHandle, 0, RamDiskStr, NULL);\r | |
525 | ASSERT (StringId != 0);\r | |
526 | \r | |
527 | HiiCreateCheckBoxOpCode (\r | |
528 | StartOpCodeHandle,\r | |
09abc636 HW |
529 | PrivateData->CheckBoxId,\r |
530 | 0,\r | |
531 | 0,\r | |
20752cb8 HW |
532 | StringId,\r |
533 | STRING_TOKEN (STR_RAM_DISK_LIST_HELP),\r | |
09abc636 | 534 | EFI_IFR_FLAG_CALLBACK,\r |
20752cb8 HW |
535 | 0,\r |
536 | NULL\r | |
537 | );\r | |
538 | \r | |
539 | Index++;\r | |
540 | }\r | |
20752cb8 HW |
541 | \r |
542 | HiiUpdateForm (\r | |
543 | ConfigPrivate->HiiHandle,\r | |
544 | &gRamDiskFormSetGuid,\r | |
545 | MAIN_FORM_ID,\r | |
546 | StartOpCodeHandle,\r | |
547 | EndOpCodeHandle\r | |
548 | );\r | |
549 | \r | |
550 | HiiFreeOpCodeHandle (StartOpCodeHandle);\r | |
551 | HiiFreeOpCodeHandle (EndOpCodeHandle);\r | |
552 | }\r | |
553 | \r | |
20752cb8 HW |
554 | /**\r |
555 | This function processes the results of changes in configuration.\r | |
556 | \r | |
557 | @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
558 | @param[in] Action Specifies the type of action taken by the browser.\r | |
559 | @param[in] QuestionId A unique value which is sent to the original\r | |
560 | exporting driver so that it can identify the type\r | |
561 | of data to expect.\r | |
562 | @param[in] Type The type of value for the question.\r | |
563 | @param[in] Value A pointer to the data being sent to the original\r | |
564 | exporting driver.\r | |
565 | @param[out] ActionRequest On return, points to the action requested by the\r | |
566 | callback function.\r | |
567 | \r | |
568 | @retval EFI_SUCCESS The callback successfully handled the action.\r | |
569 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r | |
570 | variable and its data.\r | |
571 | @retval EFI_DEVICE_ERROR The variable could not be saved.\r | |
572 | @retval EFI_UNSUPPORTED The specified Action is not supported by the\r | |
573 | callback.\r | |
574 | \r | |
575 | **/\r | |
576 | EFI_STATUS\r | |
577 | EFIAPI\r | |
578 | RamDiskCallback (\r | |
1436aea4 MK |
579 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r |
580 | IN EFI_BROWSER_ACTION Action,\r | |
581 | IN EFI_QUESTION_ID QuestionId,\r | |
582 | IN UINT8 Type,\r | |
583 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
584 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
20752cb8 HW |
585 | )\r |
586 | {\r | |
1436aea4 MK |
587 | EFI_STATUS Status;\r |
588 | RAM_DISK_PRIVATE_DATA *PrivateData;\r | |
589 | RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;\r | |
590 | EFI_DEVICE_PATH_PROTOCOL *FileDevPath;\r | |
591 | EFI_FILE_HANDLE FileHandle;\r | |
592 | LIST_ENTRY *Entry;\r | |
593 | LIST_ENTRY *NextEntry;\r | |
20752cb8 HW |
594 | \r |
595 | if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {\r | |
596 | return EFI_INVALID_PARAMETER;\r | |
597 | }\r | |
598 | \r | |
5cf8a917 HW |
599 | ConfigPrivate = RAM_DISK_CONFIG_PRIVATE_FROM_THIS (This);\r |
600 | \r | |
20752cb8 HW |
601 | if (Action == EFI_BROWSER_ACTION_RETRIEVE) {\r |
602 | Status = EFI_UNSUPPORTED;\r | |
603 | if (QuestionId == CREATE_RAW_SIZE_QUESTION_ID) {\r | |
1436aea4 | 604 | Value->u64 = EFI_PAGE_SIZE;\r |
5cf8a917 | 605 | ConfigPrivate->ConfigStore.Size = EFI_PAGE_SIZE;\r |
1436aea4 | 606 | Status = EFI_SUCCESS;\r |
4b1f4646 | 607 | } else if (QuestionId == CREATE_RAW_MEMORY_TYPE_QUESTION_ID) {\r |
1436aea4 | 608 | Value->u8 = RAM_DISK_BOOT_SERVICE_DATA_MEMORY;\r |
4b1f4646 | 609 | ConfigPrivate->ConfigStore.MemType = RAM_DISK_BOOT_SERVICE_DATA_MEMORY;\r |
1436aea4 | 610 | Status = EFI_SUCCESS;\r |
20752cb8 | 611 | }\r |
1436aea4 | 612 | \r |
20752cb8 HW |
613 | return Status;\r |
614 | }\r | |
615 | \r | |
616 | if ((Action != EFI_BROWSER_ACTION_CHANGED) &&\r | |
617 | (Action != EFI_BROWSER_ACTION_CHANGING) &&\r | |
1436aea4 MK |
618 | (Action != EFI_BROWSER_ACTION_FORM_OPEN))\r |
619 | {\r | |
20752cb8 HW |
620 | return EFI_UNSUPPORTED;\r |
621 | }\r | |
622 | \r | |
20752cb8 HW |
623 | //\r |
624 | // Update the RAM disk list show at the main form first.\r | |
625 | //\r | |
626 | if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r | |
627 | Status = EFI_UNSUPPORTED;\r | |
628 | if (QuestionId == MAIN_GOTO_FILE_EXPLORER_ID) {\r | |
629 | UpdateMainForm (ConfigPrivate);\r | |
630 | Status = EFI_SUCCESS;\r | |
631 | }\r | |
1436aea4 | 632 | \r |
20752cb8 HW |
633 | return Status;\r |
634 | }\r | |
635 | \r | |
20752cb8 HW |
636 | Status = EFI_SUCCESS;\r |
637 | \r | |
20752cb8 HW |
638 | if (Action == EFI_BROWSER_ACTION_CHANGING) {\r |
639 | switch (QuestionId) {\r | |
1436aea4 MK |
640 | case MAIN_GOTO_FILE_EXPLORER_ID:\r |
641 | Status = ChooseFile (NULL, NULL, NULL, &FileDevPath);\r | |
642 | if (EFI_ERROR (Status)) {\r | |
643 | break;\r | |
644 | }\r | |
645 | \r | |
646 | if (FileDevPath != NULL) {\r | |
647 | //\r | |
648 | // Open the file.\r | |
649 | //\r | |
650 | Status = EfiOpenFileByDevicePath (\r | |
651 | &FileDevPath,\r | |
652 | &FileHandle,\r | |
653 | EFI_FILE_MODE_READ,\r | |
654 | 0\r | |
655 | );\r | |
656 | if (EFI_ERROR (Status)) {\r | |
657 | break;\r | |
658 | }\r | |
659 | \r | |
660 | //\r | |
661 | // Create from file, RAM disk size is zero. It will be updated\r | |
662 | // according to the file size.\r | |
663 | //\r | |
664 | Status = HiiCreateRamDisk (\r | |
665 | 0,\r | |
666 | FileHandle,\r | |
667 | ConfigPrivate->ConfigStore.MemType\r | |
668 | );\r | |
669 | if (EFI_ERROR (Status)) {\r | |
670 | break;\r | |
671 | }\r | |
672 | \r | |
673 | //\r | |
674 | // Refresh the registered RAM disks list.\r | |
675 | //\r | |
676 | UpdateMainForm (ConfigPrivate);\r | |
677 | }\r | |
678 | \r | |
20752cb8 | 679 | break;\r |
20752cb8 | 680 | \r |
1436aea4 MK |
681 | default:\r |
682 | break;\r | |
683 | }\r | |
684 | } else if (Action == EFI_BROWSER_ACTION_CHANGED) {\r | |
685 | switch (QuestionId) {\r | |
686 | case MAIN_REMOVE_RD_QUESTION_ID:\r | |
20752cb8 | 687 | //\r |
1436aea4 | 688 | // Remove the selected RAM disks\r |
20752cb8 | 689 | //\r |
1436aea4 MK |
690 | BASE_LIST_FOR_EACH_SAFE (Entry, NextEntry, &RegisteredRamDisks) {\r |
691 | PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);\r | |
692 | if (PrivateData->CheckBoxChecked) {\r | |
693 | RamDiskUnregister (\r | |
694 | (EFI_DEVICE_PATH_PROTOCOL *)PrivateData->DevicePath\r | |
695 | );\r | |
696 | }\r | |
20752cb8 HW |
697 | }\r |
698 | \r | |
1436aea4 MK |
699 | UpdateMainForm (ConfigPrivate);\r |
700 | \r | |
701 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r | |
702 | break;\r | |
703 | \r | |
704 | case CREATE_RAW_SIZE_QUESTION_ID:\r | |
705 | ConfigPrivate->ConfigStore.Size = Value->u64;\r | |
706 | break;\r | |
707 | \r | |
708 | case CREATE_RAW_MEMORY_TYPE_QUESTION_ID:\r | |
709 | ConfigPrivate->ConfigStore.MemType = Value->u8;\r | |
710 | break;\r | |
711 | \r | |
712 | case CREATE_RAW_SUBMIT_QUESTION_ID:\r | |
20752cb8 | 713 | //\r |
1436aea4 | 714 | // Create raw, FileHandle is NULL.\r |
20752cb8 | 715 | //\r |
4b1f4646 | 716 | Status = HiiCreateRamDisk (\r |
1436aea4 MK |
717 | ConfigPrivate->ConfigStore.Size,\r |
718 | NULL,\r | |
4b1f4646 TS |
719 | ConfigPrivate->ConfigStore.MemType\r |
720 | );\r | |
20752cb8 HW |
721 | if (EFI_ERROR (Status)) {\r |
722 | break;\r | |
723 | }\r | |
724 | \r | |
725 | //\r | |
726 | // Refresh the registered RAM disks list.\r | |
727 | //\r | |
728 | UpdateMainForm (ConfigPrivate);\r | |
20752cb8 | 729 | \r |
1436aea4 | 730 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r |
20752cb8 | 731 | break;\r |
20752cb8 | 732 | \r |
1436aea4 MK |
733 | case CREATE_RAW_DISCARD_QUESTION_ID:\r |
734 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r | |
735 | break;\r | |
20752cb8 | 736 | \r |
1436aea4 MK |
737 | default:\r |
738 | //\r | |
739 | // QuestionIds for checkboxes\r | |
740 | //\r | |
741 | if ((QuestionId >= MAIN_CHECKBOX_QUESTION_ID_START) &&\r | |
742 | (QuestionId < CREATE_RAW_RAM_DISK_FORM_ID))\r | |
743 | {\r | |
744 | BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {\r | |
745 | PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);\r | |
746 | if (PrivateData->CheckBoxId == QuestionId) {\r | |
747 | PrivateData->CheckBoxChecked = (BOOLEAN)(Value->u8 != 0);\r | |
748 | }\r | |
09abc636 HW |
749 | }\r |
750 | }\r | |
1436aea4 MK |
751 | \r |
752 | break;\r | |
20752cb8 HW |
753 | }\r |
754 | }\r | |
755 | \r | |
20752cb8 HW |
756 | return EFI_SUCCESS;\r |
757 | }\r |