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