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