]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c
MdeModulePkg/UiApp: Update RouteConfig function
[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
4b1f4646 5 (C) Copyright 2016 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
5cf8a917 280 return EFI_NOT_FOUND;\r
20752cb8
HW
281}\r
282\r
283\r
284/**\r
285 Allocate memory and register the RAM disk created within RamDiskDxe\r
286 driver HII.\r
287\r
288 @param[in] Size If creating raw, size of the RAM disk to create.\r
289 If creating from file, zero.\r
290 @param[in] FileHandle If creating raw, NULL. If creating from file, the\r
291 file handle.\r
4b1f4646 292 @param[in] MemoryType Type of memory to be used to create RAM Disk.\r
20752cb8
HW
293\r
294 @retval EFI_SUCCESS RAM disk is created and registered.\r
295 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to match the\r
296 size required.\r
297\r
298**/\r
299EFI_STATUS\r
300HiiCreateRamDisk (\r
301 IN UINT64 Size,\r
4b1f4646
TS
302 IN EFI_FILE_HANDLE FileHandle,\r
303 IN UINT8 MemoryType\r
20752cb8
HW
304 )\r
305{\r
306 EFI_STATUS Status;\r
307 UINTN BufferSize;\r
4b1f4646 308 UINT64 *StartingAddr;\r
20752cb8
HW
309 EFI_INPUT_KEY Key;\r
310 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
311 RAM_DISK_PRIVATE_DATA *PrivateData;\r
312 EFI_FILE_INFO *FileInformation;\r
313\r
314 FileInformation = NULL;\r
4b1f4646 315 StartingAddr = NULL;\r
20752cb8
HW
316\r
317 if (FileHandle != NULL) {\r
318 //\r
319 // Create from file.\r
320 //\r
321 FileInformation = FileInfo (FileHandle);\r
322 if (NULL == FileInformation) {\r
323 do {\r
324 CreatePopUp (\r
325 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
326 &Key,\r
327 L"",\r
328 L"Not enough memory to get the file information!",\r
329 L"Press ENTER to continue ...",\r
330 L"",\r
331 NULL\r
332 );\r
333 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
334\r
335 return EFI_OUT_OF_RESOURCES;\r
336 }\r
337\r
338 //\r
339 // Update the size of RAM disk according to the file size.\r
340 //\r
341 Size = FileInformation->FileSize;\r
342 }\r
343\r
5cf8a917
HW
344 if (Size > (UINTN) -1) {\r
345 do {\r
346 CreatePopUp (\r
347 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
348 &Key,\r
349 L"",\r
350 L"The given RAM disk size is too large!",\r
351 L"Press ENTER to continue ...",\r
352 L"",\r
353 NULL\r
354 );\r
355 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
356\r
357 return EFI_OUT_OF_RESOURCES;\r
358 }\r
359\r
4b1f4646
TS
360 if (MemoryType == RAM_DISK_BOOT_SERVICE_DATA_MEMORY) {\r
361 Status = gBS->AllocatePool (\r
362 EfiBootServicesData,\r
363 (UINTN)Size,\r
364 (VOID**)&StartingAddr\r
365 );\r
366 } else if (MemoryType == RAM_DISK_RESERVED_MEMORY) {\r
367 Status = gBS->AllocatePool (\r
368 EfiReservedMemoryType,\r
369 (UINTN)Size,\r
370 (VOID**)&StartingAddr\r
371 );\r
372 } else {\r
373 Status = EFI_INVALID_PARAMETER;\r
374 }\r
375\r
376 if ((StartingAddr == NULL) || EFI_ERROR(Status)) {\r
20752cb8
HW
377 do {\r
378 CreatePopUp (\r
379 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
380 &Key,\r
381 L"",\r
382 L"Not enough memory to create the RAM disk!",\r
383 L"Press ENTER to continue ...",\r
384 L"",\r
385 NULL\r
386 );\r
387 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
388\r
389 return EFI_OUT_OF_RESOURCES;\r
390 }\r
391\r
392 if (FileHandle != NULL) {\r
393 //\r
394 // Copy the file content to the RAM disk.\r
395 //\r
396 BufferSize = (UINTN) Size;\r
397 FileHandle->Read (\r
398 FileHandle,\r
399 &BufferSize,\r
400 (VOID *)(UINTN) StartingAddr\r
401 );\r
402 if (BufferSize != FileInformation->FileSize) {\r
403 do {\r
404 CreatePopUp (\r
405 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
406 &Key,\r
407 L"",\r
408 L"File content read error!",\r
409 L"Press ENTER to continue ...",\r
410 L"",\r
411 NULL\r
412 );\r
413 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
414\r
415 return EFI_DEVICE_ERROR;\r
416 }\r
417 }\r
418\r
419 //\r
420 // Register the newly created RAM disk.\r
421 //\r
422 Status = RamDiskRegister (\r
4b1f4646 423 ((UINT64)(UINTN) StartingAddr),\r
20752cb8
HW
424 Size,\r
425 &gEfiVirtualDiskGuid,\r
426 NULL,\r
427 &DevicePath\r
428 );\r
429 if (EFI_ERROR (Status)) {\r
430 do {\r
431 CreatePopUp (\r
432 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
433 &Key,\r
434 L"",\r
435 L"Fail to register the newly created RAM disk!",\r
436 L"Press ENTER to continue ...",\r
437 L"",\r
438 NULL\r
439 );\r
440 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
441\r
442 return Status;\r
443 }\r
444\r
445 //\r
446 // If RAM disk is created within HII, memory should be freed when the\r
447 // RAM disk is unregisterd.\r
448 //\r
449 PrivateData = RAM_DISK_PRIVATE_FROM_THIS (RegisteredRamDisks.BackLink);\r
450 PrivateData->CreateMethod = RamDiskCreateHii;\r
451\r
452 return EFI_SUCCESS;\r
453}\r
454\r
455\r
456/**\r
457 This function updates the registered RAM disks list on the main form.\r
458\r
459 @param[in, out] ConfigPrivate\r
460 Private data for configurating hii data for RAM\r
461 disks.\r
462\r
463**/\r
464VOID\r
465UpdateMainForm (\r
466 IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate\r
467 )\r
468{\r
469 VOID *StartOpCodeHandle;\r
470 VOID *EndOpCodeHandle;\r
471 EFI_IFR_GUID_LABEL *StartLabel;\r
472 EFI_IFR_GUID_LABEL *EndLabel;\r
473 LIST_ENTRY *Entry;\r
474 UINTN Index;\r
475 RAM_DISK_PRIVATE_DATA *PrivateData;\r
476 CHAR16 *String;\r
477 CHAR16 RamDiskStr[128];\r
478 EFI_STRING_ID StringId;\r
20752cb8
HW
479\r
480 //\r
481 // Init OpCode Handle\r
482 //\r
483 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
484 ASSERT (StartOpCodeHandle != NULL);\r
485\r
486 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
487 ASSERT (EndOpCodeHandle != NULL);\r
488\r
489 //\r
490 // Create Hii Extend Label OpCode as the start opcode\r
491 //\r
492 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
493 StartOpCodeHandle,\r
494 &gEfiIfrTianoGuid,\r
495 NULL,\r
496 sizeof (EFI_IFR_GUID_LABEL)\r
497 );\r
498 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
499 StartLabel->Number = MAIN_LABEL_LIST_START;\r
500\r
501 //\r
502 // Create Hii Extend Label OpCode as the end opcode\r
503 //\r
504 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
505 EndOpCodeHandle,\r
506 &gEfiIfrTianoGuid,\r
507 NULL,\r
508 sizeof (EFI_IFR_GUID_LABEL)\r
509 );\r
510 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
511 EndLabel->Number = MAIN_LABEL_LIST_END;\r
512\r
513 Index = 0;\r
20752cb8 514 EFI_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {\r
09abc636
HW
515 PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);\r
516 PrivateData->CheckBoxId = (EFI_QUESTION_ID)\r
517 (MAIN_CHECKBOX_QUESTION_ID_START + Index);\r
518 //\r
519 // CheckBox is unchecked by default.\r
520 //\r
521 PrivateData->CheckBoxChecked = FALSE;\r
522 String = RamDiskStr;\r
20752cb8
HW
523\r
524 UnicodeSPrint (\r
525 String,\r
526 sizeof (RamDiskStr),\r
527 L" RAM Disk %d: [0x%lx, 0x%lx]\n",\r
528 Index,\r
529 PrivateData->StartingAddr,\r
5eae4ff0 530 PrivateData->StartingAddr + PrivateData->Size - 1\r
20752cb8
HW
531 );\r
532\r
533 StringId = HiiSetString (ConfigPrivate->HiiHandle, 0, RamDiskStr, NULL);\r
534 ASSERT (StringId != 0);\r
535\r
536 HiiCreateCheckBoxOpCode (\r
537 StartOpCodeHandle,\r
09abc636
HW
538 PrivateData->CheckBoxId,\r
539 0,\r
540 0,\r
20752cb8
HW
541 StringId,\r
542 STRING_TOKEN (STR_RAM_DISK_LIST_HELP),\r
09abc636 543 EFI_IFR_FLAG_CALLBACK,\r
20752cb8
HW
544 0,\r
545 NULL\r
546 );\r
547\r
548 Index++;\r
549 }\r
20752cb8
HW
550\r
551 HiiUpdateForm (\r
552 ConfigPrivate->HiiHandle,\r
553 &gRamDiskFormSetGuid,\r
554 MAIN_FORM_ID,\r
555 StartOpCodeHandle,\r
556 EndOpCodeHandle\r
557 );\r
558\r
559 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
560 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
561}\r
562\r
563\r
564/**\r
565 This function processes the results of changes in configuration.\r
566\r
567 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
568 @param[in] Action Specifies the type of action taken by the browser.\r
569 @param[in] QuestionId A unique value which is sent to the original\r
570 exporting driver so that it can identify the type\r
571 of data to expect.\r
572 @param[in] Type The type of value for the question.\r
573 @param[in] Value A pointer to the data being sent to the original\r
574 exporting driver.\r
575 @param[out] ActionRequest On return, points to the action requested by the\r
576 callback function.\r
577\r
578 @retval EFI_SUCCESS The callback successfully handled the action.\r
579 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
580 variable and its data.\r
581 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
582 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
583 callback.\r
584\r
585**/\r
586EFI_STATUS\r
587EFIAPI\r
588RamDiskCallback (\r
589 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
590 IN EFI_BROWSER_ACTION Action,\r
591 IN EFI_QUESTION_ID QuestionId,\r
592 IN UINT8 Type,\r
593 IN EFI_IFR_TYPE_VALUE *Value,\r
594 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
595 )\r
596{\r
597 EFI_STATUS Status;\r
20752cb8
HW
598 RAM_DISK_PRIVATE_DATA *PrivateData;\r
599 RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;\r
20752cb8
HW
600 EFI_DEVICE_PATH_PROTOCOL *FileDevPath;\r
601 EFI_FILE_HANDLE FileHandle;\r
602 LIST_ENTRY *Entry;\r
603 LIST_ENTRY *NextEntry;\r
20752cb8
HW
604\r
605 if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {\r
606 return EFI_INVALID_PARAMETER;\r
607 }\r
608\r
5cf8a917
HW
609 ConfigPrivate = RAM_DISK_CONFIG_PRIVATE_FROM_THIS (This);\r
610\r
20752cb8
HW
611 if (Action == EFI_BROWSER_ACTION_RETRIEVE) {\r
612 Status = EFI_UNSUPPORTED;\r
613 if (QuestionId == CREATE_RAW_SIZE_QUESTION_ID) {\r
614 Value->u64 = EFI_PAGE_SIZE;\r
5cf8a917 615 ConfigPrivate->ConfigStore.Size = EFI_PAGE_SIZE;\r
20752cb8 616 Status = EFI_SUCCESS;\r
4b1f4646
TS
617 } else if (QuestionId == CREATE_RAW_MEMORY_TYPE_QUESTION_ID) {\r
618 Value->u8 = RAM_DISK_BOOT_SERVICE_DATA_MEMORY;\r
619 ConfigPrivate->ConfigStore.MemType = RAM_DISK_BOOT_SERVICE_DATA_MEMORY;\r
620 Status = EFI_SUCCESS;\r
20752cb8
HW
621 }\r
622 return Status;\r
623 }\r
624\r
625 if ((Action != EFI_BROWSER_ACTION_CHANGED) &&\r
626 (Action != EFI_BROWSER_ACTION_CHANGING) &&\r
627 (Action != EFI_BROWSER_ACTION_FORM_OPEN)) {\r
628 return EFI_UNSUPPORTED;\r
629 }\r
630\r
20752cb8
HW
631 //\r
632 // Update the RAM disk list show at the main form first.\r
633 //\r
634 if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r
635 Status = EFI_UNSUPPORTED;\r
636 if (QuestionId == MAIN_GOTO_FILE_EXPLORER_ID) {\r
637 UpdateMainForm (ConfigPrivate);\r
638 Status = EFI_SUCCESS;\r
639 }\r
640 return Status;\r
641 }\r
642\r
20752cb8
HW
643 Status = EFI_SUCCESS;\r
644\r
20752cb8
HW
645 if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
646 switch (QuestionId) {\r
647 case MAIN_GOTO_FILE_EXPLORER_ID:\r
648 Status = ChooseFile (NULL, NULL, NULL, &FileDevPath);\r
649 if (EFI_ERROR (Status)) {\r
650 break;\r
651 }\r
652\r
653 if (FileDevPath != NULL) {\r
654 //\r
655 // Open the file.\r
656 //\r
657 Status = OpenFileByDevicePath (\r
658 &FileDevPath,\r
659 &FileHandle,\r
660 EFI_FILE_MODE_READ,\r
661 0\r
662 );\r
663 if (EFI_ERROR (Status)) {\r
664 break;\r
665 }\r
666\r
667 //\r
668 // Create from file, RAM disk size is zero. It will be updated\r
669 // according to the file size.\r
670 //\r
4b1f4646
TS
671 Status = HiiCreateRamDisk (\r
672 0,\r
673 FileHandle,\r
674 ConfigPrivate->ConfigStore.MemType\r
675 );\r
20752cb8
HW
676 if (EFI_ERROR (Status)) {\r
677 break;\r
678 }\r
679\r
680 //\r
681 // Refresh the registered RAM disks list.\r
682 //\r
683 UpdateMainForm (ConfigPrivate);\r
684 }\r
20752cb8
HW
685 break;\r
686\r
687 default:\r
688 break;\r
689 }\r
690 } else if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
691 switch (QuestionId) {\r
692 case MAIN_REMOVE_RD_QUESTION_ID:\r
693 //\r
694 // Remove the selected RAM disks\r
695 //\r
20752cb8 696 EFI_LIST_FOR_EACH_SAFE (Entry, NextEntry, &RegisteredRamDisks) {\r
09abc636
HW
697 PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);\r
698 if (PrivateData->CheckBoxChecked) {\r
20752cb8
HW
699 RamDiskUnregister (\r
700 (EFI_DEVICE_PATH_PROTOCOL *) PrivateData->DevicePath\r
701 );\r
702 }\r
703 }\r
20752cb8
HW
704\r
705 UpdateMainForm (ConfigPrivate);\r
706\r
707 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
20752cb8
HW
708 break;\r
709\r
5cf8a917
HW
710 case CREATE_RAW_SIZE_QUESTION_ID:\r
711 ConfigPrivate->ConfigStore.Size = Value->u64;\r
712 break;\r
713\r
4b1f4646
TS
714 case CREATE_RAW_MEMORY_TYPE_QUESTION_ID:\r
715 ConfigPrivate->ConfigStore.MemType = Value->u8;\r
716 break;\r
717\r
20752cb8
HW
718 case CREATE_RAW_SUBMIT_QUESTION_ID:\r
719 //\r
720 // Create raw, FileHandle is NULL.\r
721 //\r
4b1f4646
TS
722 Status = HiiCreateRamDisk (\r
723 ConfigPrivate->ConfigStore.Size,\r
724 NULL,\r
725 ConfigPrivate->ConfigStore.MemType\r
726 );\r
20752cb8
HW
727 if (EFI_ERROR (Status)) {\r
728 break;\r
729 }\r
730\r
731 //\r
732 // Refresh the registered RAM disks list.\r
733 //\r
734 UpdateMainForm (ConfigPrivate);\r
735\r
736 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r
737 break;\r
738\r
739 case CREATE_RAW_DISCARD_QUESTION_ID:\r
740 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r
741 break;\r
742\r
743 default:\r
09abc636
HW
744 //\r
745 // QuestionIds for checkboxes\r
746 //\r
747 if ((QuestionId >= MAIN_CHECKBOX_QUESTION_ID_START) &&\r
748 (QuestionId < CREATE_RAW_RAM_DISK_FORM_ID)) {\r
749 EFI_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {\r
750 PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);\r
751 if (PrivateData->CheckBoxId == QuestionId) {\r
752 PrivateData->CheckBoxChecked = (BOOLEAN) (Value->u8 != 0);\r
753 }\r
754 }\r
755 }\r
20752cb8
HW
756 break;\r
757 }\r
758 }\r
759\r
20752cb8
HW
760 return EFI_SUCCESS;\r
761}\r