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