]>
Commit | Line | Data |
---|---|---|
d945a8ba LE |
1 | /** @file\r |
2 | This driver effectuates OVMF's platform configuration settings and exposes\r | |
3 | them via HII.\r | |
4 | \r | |
5 | Copyright (C) 2014, Red Hat, Inc.\r | |
bc4c5366 | 6 | Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r |
d945a8ba | 7 | \r |
b26f0cf9 | 8 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
d945a8ba LE |
9 | **/\r |
10 | \r | |
92e74550 | 11 | #include <Library/BaseLib.h>\r |
cbd08bcc | 12 | #include <Library/BaseMemoryLib.h>\r |
d945a8ba | 13 | #include <Library/DebugLib.h>\r |
877a4dbb LE |
14 | #include <Library/DevicePathLib.h>\r |
15 | #include <Library/HiiLib.h>\r | |
da07afaf LE |
16 | #include <Library/MemoryAllocationLib.h>\r |
17 | #include <Library/PrintLib.h>\r | |
d945a8ba | 18 | #include <Library/UefiBootServicesTableLib.h>\r |
92e74550 | 19 | #include <Library/UefiHiiServicesLib.h>\r |
877a4dbb | 20 | #include <Protocol/DevicePath.h>\r |
da07afaf | 21 | #include <Protocol/GraphicsOutput.h>\r |
877a4dbb | 22 | #include <Protocol/HiiConfigAccess.h>\r |
92e74550 LE |
23 | #include <Guid/MdeModuleHii.h>\r |
24 | #include <Guid/OvmfPlatformConfig.h>\r | |
d945a8ba | 25 | \r |
92e74550 | 26 | #include "Platform.h"\r |
bdaf30e4 LE |
27 | #include "PlatformConfig.h"\r |
28 | \r | |
877a4dbb LE |
29 | //\r |
30 | // The HiiAddPackages() library function requires that any controller (or\r | |
31 | // image) handle, to be associated with the HII packages under installation, be\r | |
32 | // "decorated" with a device path. The tradition seems to be a vendor device\r | |
33 | // path.\r | |
34 | //\r | |
35 | // We'd like to associate our HII packages with the driver's image handle. The\r | |
36 | // first idea is to use the driver image's device path. Unfortunately, loaded\r | |
37 | // images only come with an EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL (not the\r | |
38 | // usual EFI_DEVICE_PATH_PROTOCOL), ie. a different GUID. In addition, even the\r | |
39 | // EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL interface may be NULL, if the image\r | |
40 | // has been loaded from an "unnamed" memory source buffer.\r | |
41 | //\r | |
42 | // Hence let's just stick with the tradition -- use a dedicated vendor device\r | |
43 | // path, with the driver's FILE_GUID.\r | |
44 | //\r | |
45 | #pragma pack(1)\r | |
46 | typedef struct {\r | |
ac0a286f MK |
47 | VENDOR_DEVICE_PATH VendorDevicePath;\r |
48 | EFI_DEVICE_PATH_PROTOCOL End;\r | |
877a4dbb LE |
49 | } PKG_DEVICE_PATH;\r |
50 | #pragma pack()\r | |
51 | \r | |
ac0a286f | 52 | STATIC PKG_DEVICE_PATH mPkgDevicePath = {\r |
877a4dbb LE |
53 | {\r |
54 | {\r | |
55 | HARDWARE_DEVICE_PATH,\r | |
56 | HW_VENDOR_DP,\r | |
57 | {\r | |
ac0a286f MK |
58 | (UINT8)(sizeof (VENDOR_DEVICE_PATH)),\r |
59 | (UINT8)(sizeof (VENDOR_DEVICE_PATH) >> 8)\r | |
877a4dbb LE |
60 | }\r |
61 | },\r | |
62 | EFI_CALLER_ID_GUID\r | |
63 | },\r | |
64 | {\r | |
65 | END_DEVICE_PATH_TYPE,\r | |
66 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
67 | {\r | |
ac0a286f MK |
68 | (UINT8)(END_DEVICE_PATH_LENGTH),\r |
69 | (UINT8)(END_DEVICE_PATH_LENGTH >> 8)\r | |
877a4dbb LE |
70 | }\r |
71 | }\r | |
72 | };\r | |
73 | \r | |
74 | //\r | |
75 | // The configuration interface between the HII engine (form display etc) and\r | |
76 | // this driver.\r | |
77 | //\r | |
ac0a286f | 78 | STATIC EFI_HII_CONFIG_ACCESS_PROTOCOL mConfigAccess;\r |
877a4dbb LE |
79 | \r |
80 | //\r | |
81 | // The handle representing our list of packages after installation.\r | |
82 | //\r | |
ac0a286f | 83 | STATIC EFI_HII_HANDLE mInstalledPackages;\r |
877a4dbb LE |
84 | \r |
85 | //\r | |
86 | // The arrays below constitute our HII package list. They are auto-generated by\r | |
87 | // the VFR compiler and linked into the driver image during the build.\r | |
88 | //\r | |
89 | // - The strings package receives its C identifier from the driver's BASE_NAME,\r | |
90 | // plus "Strings".\r | |
91 | //\r | |
92 | // - The forms package receives its C identifier from the VFR file's basename,\r | |
93 | // plus "Bin".\r | |
94 | //\r | |
95 | //\r | |
ac0a286f MK |
96 | extern UINT8 PlatformDxeStrings[];\r |
97 | extern UINT8 PlatformFormsBin[];\r | |
877a4dbb | 98 | \r |
da07afaf LE |
99 | //\r |
100 | // We want to be notified about GOP installations until we find one GOP\r | |
101 | // interface that lets us populate the form.\r | |
102 | //\r | |
ac0a286f | 103 | STATIC EFI_EVENT mGopEvent;\r |
da07afaf LE |
104 | \r |
105 | //\r | |
106 | // The registration record underneath this pointer allows us to iterate through\r | |
107 | // the GOP instances one by one.\r | |
108 | //\r | |
ac0a286f | 109 | STATIC VOID *mGopTracker;\r |
da07afaf LE |
110 | \r |
111 | //\r | |
112 | // Cache the resolutions we get from the GOP.\r | |
113 | //\r | |
114 | typedef struct {\r | |
ac0a286f MK |
115 | UINT32 X;\r |
116 | UINT32 Y;\r | |
da07afaf LE |
117 | } GOP_MODE;\r |
118 | \r | |
ac0a286f MK |
119 | STATIC UINTN mNumGopModes;\r |
120 | STATIC GOP_MODE *mGopModes;\r | |
877a4dbb | 121 | \r |
cbd08bcc LE |
122 | /**\r |
123 | Load the persistent platform configuration and translate it to binary form\r | |
124 | state.\r | |
125 | \r | |
126 | If the platform configuration is missing, then the function fills in a\r | |
127 | default state.\r | |
128 | \r | |
129 | @param[out] MainFormState Binary form/widget state after translation.\r | |
130 | \r | |
131 | @retval EFI_SUCCESS Form/widget state ready.\r | |
132 | @return Error codes from underlying functions.\r | |
133 | **/\r | |
134 | STATIC\r | |
135 | EFI_STATUS\r | |
136 | EFIAPI\r | |
137 | PlatformConfigToFormState (\r | |
ac0a286f | 138 | OUT MAIN_FORM_STATE *MainFormState\r |
cbd08bcc LE |
139 | )\r |
140 | {\r | |
ac0a286f MK |
141 | EFI_STATUS Status;\r |
142 | PLATFORM_CONFIG PlatformConfig;\r | |
143 | UINT64 OptionalElements;\r | |
144 | UINTN ModeNumber;\r | |
cbd08bcc LE |
145 | \r |
146 | ZeroMem (MainFormState, sizeof *MainFormState);\r | |
147 | \r | |
148 | Status = PlatformConfigLoad (&PlatformConfig, &OptionalElements);\r | |
149 | switch (Status) {\r | |
ac0a286f MK |
150 | case EFI_SUCCESS:\r |
151 | if (OptionalElements & PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION) {\r | |
152 | //\r | |
153 | // Format the preferred resolution as text.\r | |
154 | //\r | |
155 | UnicodeSPrintAsciiFormat (\r | |
156 | (CHAR16 *)MainFormState->CurrentPreferredResolution,\r | |
157 | sizeof MainFormState->CurrentPreferredResolution,\r | |
158 | "%Ldx%Ld",\r | |
159 | (INT64)PlatformConfig.HorizontalResolution,\r | |
160 | (INT64)PlatformConfig.VerticalResolution\r | |
161 | );\r | |
162 | \r | |
163 | //\r | |
164 | // Try to locate it in the drop-down list too. This may not succeed, but\r | |
165 | // that's fine.\r | |
166 | //\r | |
167 | for (ModeNumber = 0; ModeNumber < mNumGopModes; ++ModeNumber) {\r | |
168 | if ((mGopModes[ModeNumber].X == PlatformConfig.HorizontalResolution) &&\r | |
169 | (mGopModes[ModeNumber].Y == PlatformConfig.VerticalResolution))\r | |
170 | {\r | |
171 | MainFormState->NextPreferredResolution = (UINT32)ModeNumber;\r | |
172 | break;\r | |
173 | }\r | |
cbd08bcc | 174 | }\r |
ac0a286f MK |
175 | \r |
176 | break;\r | |
cbd08bcc LE |
177 | }\r |
178 | \r | |
cbd08bcc LE |
179 | //\r |
180 | // fall through otherwise\r | |
181 | //\r | |
182 | \r | |
ac0a286f MK |
183 | case EFI_NOT_FOUND:\r |
184 | UnicodeSPrintAsciiFormat (\r | |
185 | (CHAR16 *)MainFormState->CurrentPreferredResolution,\r | |
186 | sizeof MainFormState->CurrentPreferredResolution,\r | |
187 | "Unset"\r | |
188 | );\r | |
189 | break;\r | |
cbd08bcc | 190 | \r |
ac0a286f MK |
191 | default:\r |
192 | return Status;\r | |
cbd08bcc LE |
193 | }\r |
194 | \r | |
195 | return EFI_SUCCESS;\r | |
196 | }\r | |
197 | \r | |
92e74550 LE |
198 | /**\r |
199 | This function is called by the HII machinery when it fetches the form state.\r | |
200 | \r | |
201 | See the precise documentation in the UEFI spec.\r | |
202 | \r | |
203 | @param[in] This The Config Access Protocol instance.\r | |
204 | \r | |
205 | @param[in] Request A <ConfigRequest> format UCS-2 string describing the\r | |
206 | query.\r | |
207 | \r | |
208 | @param[out] Progress A pointer into Request on output, identifying the query\r | |
209 | element where processing failed.\r | |
210 | \r | |
211 | @param[out] Results A <MultiConfigAltResp> format UCS-2 string that has\r | |
212 | all values filled in for the names in the Request\r | |
213 | string.\r | |
214 | \r | |
cbd08bcc LE |
215 | @retval EFI_SUCCESS Extraction of form state in <MultiConfigAltResp>\r |
216 | encoding successful.\r | |
217 | @return Status codes from underlying functions.\r | |
92e74550 LE |
218 | \r |
219 | **/\r | |
877a4dbb LE |
220 | STATIC\r |
221 | EFI_STATUS\r | |
222 | EFIAPI\r | |
223 | ExtractConfig (\r | |
224 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
225 | IN CONST EFI_STRING Request,\r | |
226 | OUT EFI_STRING *Progress,\r | |
227 | OUT EFI_STRING *Results\r | |
ac0a286f | 228 | )\r |
877a4dbb | 229 | {\r |
ac0a286f MK |
230 | MAIN_FORM_STATE MainFormState;\r |
231 | EFI_STATUS Status;\r | |
92e74550 | 232 | \r |
70d5086c | 233 | DEBUG ((DEBUG_VERBOSE, "%a: Request=\"%s\"\n", __FUNCTION__, Request));\r |
92e74550 | 234 | \r |
cbd08bcc LE |
235 | Status = PlatformConfigToFormState (&MainFormState);\r |
236 | if (EFI_ERROR (Status)) {\r | |
237 | *Progress = Request;\r | |
238 | return Status;\r | |
239 | }\r | |
240 | \r | |
241 | //\r | |
242 | // Answer the textual request keying off the binary form state.\r | |
243 | //\r | |
ac0a286f MK |
244 | Status = gHiiConfigRouting->BlockToConfig (\r |
245 | gHiiConfigRouting,\r | |
246 | Request,\r | |
247 | (VOID *)&MainFormState,\r | |
248 | sizeof MainFormState,\r | |
249 | Results,\r | |
250 | Progress\r | |
251 | );\r | |
92e74550 | 252 | if (EFI_ERROR (Status)) {\r |
ac0a286f MK |
253 | DEBUG ((\r |
254 | DEBUG_ERROR,\r | |
255 | "%a: BlockToConfig(): %r, Progress=\"%s\"\n",\r | |
256 | __FUNCTION__,\r | |
257 | Status,\r | |
258 | (Status == EFI_DEVICE_ERROR) ? NULL : *Progress\r | |
259 | ));\r | |
92e74550 | 260 | } else {\r |
70d5086c | 261 | DEBUG ((DEBUG_VERBOSE, "%a: Results=\"%s\"\n", __FUNCTION__, *Results));\r |
92e74550 | 262 | }\r |
ac0a286f | 263 | \r |
92e74550 | 264 | return Status;\r |
877a4dbb LE |
265 | }\r |
266 | \r | |
ddb2c493 LE |
267 | /**\r |
268 | Interpret the binary form state and save it as persistent platform\r | |
269 | configuration.\r | |
270 | \r | |
271 | @param[in] MainFormState Binary form/widget state to verify and save.\r | |
272 | \r | |
273 | @retval EFI_SUCCESS Platform configuration saved.\r | |
274 | @return Error codes from underlying functions.\r | |
275 | **/\r | |
276 | STATIC\r | |
277 | EFI_STATUS\r | |
278 | EFIAPI\r | |
279 | FormStateToPlatformConfig (\r | |
ac0a286f | 280 | IN CONST MAIN_FORM_STATE *MainFormState\r |
ddb2c493 LE |
281 | )\r |
282 | {\r | |
ac0a286f MK |
283 | EFI_STATUS Status;\r |
284 | PLATFORM_CONFIG PlatformConfig;\r | |
285 | CONST GOP_MODE *GopMode;\r | |
ddb2c493 LE |
286 | \r |
287 | //\r | |
288 | // There's nothing to do with the textual CurrentPreferredResolution field.\r | |
289 | // We verify and translate the selection in the drop-down list.\r | |
290 | //\r | |
291 | if (MainFormState->NextPreferredResolution >= mNumGopModes) {\r | |
292 | return EFI_INVALID_PARAMETER;\r | |
293 | }\r | |
ac0a286f | 294 | \r |
ddb2c493 LE |
295 | GopMode = mGopModes + MainFormState->NextPreferredResolution;\r |
296 | \r | |
297 | ZeroMem (&PlatformConfig, sizeof PlatformConfig);\r | |
298 | PlatformConfig.HorizontalResolution = GopMode->X;\r | |
299 | PlatformConfig.VerticalResolution = GopMode->Y;\r | |
300 | \r | |
301 | Status = PlatformConfigSave (&PlatformConfig);\r | |
302 | return Status;\r | |
303 | }\r | |
304 | \r | |
ddb2c493 LE |
305 | /**\r |
306 | This function is called by the HII machinery when it wants the driver to\r | |
307 | interpret and persist the form state.\r | |
308 | \r | |
309 | See the precise documentation in the UEFI spec.\r | |
310 | \r | |
311 | @param[in] This The Config Access Protocol instance.\r | |
312 | \r | |
313 | @param[in] Configuration A <ConfigResp> format UCS-2 string describing the\r | |
314 | form state.\r | |
315 | \r | |
316 | @param[out] Progress A pointer into Configuration on output,\r | |
317 | identifying the element where processing failed.\r | |
318 | \r | |
319 | @retval EFI_SUCCESS Configuration verified, state permanent.\r | |
320 | \r | |
321 | @return Status codes from underlying functions.\r | |
322 | **/\r | |
877a4dbb LE |
323 | STATIC\r |
324 | EFI_STATUS\r | |
325 | EFIAPI\r | |
326 | RouteConfig (\r | |
327 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
328 | IN CONST EFI_STRING Configuration,\r | |
329 | OUT EFI_STRING *Progress\r | |
ac0a286f | 330 | )\r |
877a4dbb | 331 | {\r |
ac0a286f MK |
332 | MAIN_FORM_STATE MainFormState;\r |
333 | UINTN BlockSize;\r | |
334 | EFI_STATUS Status;\r | |
ddb2c493 | 335 | \r |
ac0a286f MK |
336 | DEBUG ((\r |
337 | DEBUG_VERBOSE,\r | |
338 | "%a: Configuration=\"%s\"\n",\r | |
339 | __FUNCTION__,\r | |
340 | Configuration\r | |
341 | ));\r | |
ddb2c493 LE |
342 | \r |
343 | //\r | |
344 | // the "read" step in RMW\r | |
345 | //\r | |
346 | Status = PlatformConfigToFormState (&MainFormState);\r | |
347 | if (EFI_ERROR (Status)) {\r | |
348 | *Progress = Configuration;\r | |
349 | return Status;\r | |
350 | }\r | |
351 | \r | |
352 | //\r | |
353 | // the "modify" step in RMW\r | |
354 | //\r | |
355 | // (Update the binary form state. This update may be partial, which is why in\r | |
356 | // general we must pre-load the form state from the platform config.)\r | |
357 | //\r | |
358 | BlockSize = sizeof MainFormState;\r | |
ac0a286f MK |
359 | Status = gHiiConfigRouting->ConfigToBlock (\r |
360 | gHiiConfigRouting,\r | |
361 | Configuration,\r | |
362 | (VOID *)&MainFormState,\r | |
363 | &BlockSize,\r | |
364 | Progress\r | |
365 | );\r | |
ddb2c493 | 366 | if (EFI_ERROR (Status)) {\r |
ac0a286f MK |
367 | DEBUG ((\r |
368 | DEBUG_ERROR,\r | |
369 | "%a: ConfigToBlock(): %r, Progress=\"%s\"\n",\r | |
370 | __FUNCTION__,\r | |
371 | Status,\r | |
372 | (Status == EFI_BUFFER_TOO_SMALL) ? NULL : *Progress\r | |
373 | ));\r | |
ddb2c493 LE |
374 | return Status;\r |
375 | }\r | |
376 | \r | |
377 | //\r | |
378 | // the "write" step in RMW\r | |
379 | //\r | |
380 | Status = FormStateToPlatformConfig (&MainFormState);\r | |
381 | if (EFI_ERROR (Status)) {\r | |
382 | *Progress = Configuration;\r | |
383 | }\r | |
ac0a286f | 384 | \r |
ddb2c493 | 385 | return Status;\r |
877a4dbb LE |
386 | }\r |
387 | \r | |
877a4dbb LE |
388 | STATIC\r |
389 | EFI_STATUS\r | |
390 | EFIAPI\r | |
391 | Callback (\r | |
ac0a286f MK |
392 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r |
393 | IN EFI_BROWSER_ACTION Action,\r | |
394 | IN EFI_QUESTION_ID QuestionId,\r | |
395 | IN UINT8 Type,\r | |
396 | IN OUT EFI_IFR_TYPE_VALUE *Value,\r | |
397 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
877a4dbb LE |
398 | )\r |
399 | {\r | |
ac0a286f MK |
400 | DEBUG ((\r |
401 | DEBUG_VERBOSE,\r | |
402 | "%a: Action=0x%Lx QuestionId=%d Type=%d\n",\r | |
403 | __FUNCTION__,\r | |
404 | (UINT64)Action,\r | |
405 | QuestionId,\r | |
406 | Type\r | |
407 | ));\r | |
1df57ba3 LE |
408 | \r |
409 | if (Action != EFI_BROWSER_ACTION_CHANGED) {\r | |
410 | return EFI_UNSUPPORTED;\r | |
411 | }\r | |
412 | \r | |
413 | switch (QuestionId) {\r | |
ac0a286f MK |
414 | case QUESTION_SAVE_EXIT:\r |
415 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;\r | |
416 | break;\r | |
1df57ba3 | 417 | \r |
ac0a286f MK |
418 | case QUESTION_DISCARD_EXIT:\r |
419 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r | |
420 | break;\r | |
1df57ba3 | 421 | \r |
ac0a286f MK |
422 | default:\r |
423 | break;\r | |
1df57ba3 LE |
424 | }\r |
425 | \r | |
877a4dbb LE |
426 | return EFI_SUCCESS;\r |
427 | }\r | |
428 | \r | |
da07afaf LE |
429 | /**\r |
430 | Query and save all resolutions supported by the GOP.\r | |
431 | \r | |
432 | @param[in] Gop The Graphics Output Protocol instance to query.\r | |
433 | \r | |
434 | @param[out] NumGopModes The number of modes supported by the GOP. On output,\r | |
435 | this parameter will be positive.\r | |
436 | \r | |
437 | @param[out] GopModes On output, a dynamically allocated array containing\r | |
438 | the resolutions returned by the GOP. The caller is\r | |
439 | responsible for freeing the array after use.\r | |
440 | \r | |
441 | @retval EFI_UNSUPPORTED No modes found.\r | |
442 | @retval EFI_OUT_OF_RESOURCES Failed to allocate GopModes.\r | |
443 | @return Error codes from Gop->QueryMode().\r | |
444 | \r | |
445 | **/\r | |
446 | STATIC\r | |
447 | EFI_STATUS\r | |
448 | EFIAPI\r | |
449 | QueryGopModes (\r | |
ac0a286f MK |
450 | IN EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop,\r |
451 | OUT UINTN *NumGopModes,\r | |
452 | OUT GOP_MODE **GopModes\r | |
da07afaf LE |
453 | )\r |
454 | {\r | |
ac0a286f MK |
455 | EFI_STATUS Status;\r |
456 | UINT32 ModeNumber;\r | |
da07afaf LE |
457 | \r |
458 | if (Gop->Mode->MaxMode == 0) {\r | |
459 | return EFI_UNSUPPORTED;\r | |
460 | }\r | |
ac0a286f | 461 | \r |
da07afaf LE |
462 | *NumGopModes = Gop->Mode->MaxMode;\r |
463 | \r | |
464 | *GopModes = AllocatePool (Gop->Mode->MaxMode * sizeof **GopModes);\r | |
465 | if (*GopModes == NULL) {\r | |
466 | return EFI_OUT_OF_RESOURCES;\r | |
467 | }\r | |
468 | \r | |
469 | for (ModeNumber = 0; ModeNumber < Gop->Mode->MaxMode; ++ModeNumber) {\r | |
ac0a286f MK |
470 | EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r |
471 | UINTN SizeOfInfo;\r | |
da07afaf LE |
472 | \r |
473 | Status = Gop->QueryMode (Gop, ModeNumber, &SizeOfInfo, &Info);\r | |
474 | if (EFI_ERROR (Status)) {\r | |
475 | goto FreeGopModes;\r | |
476 | }\r | |
477 | \r | |
478 | (*GopModes)[ModeNumber].X = Info->HorizontalResolution;\r | |
479 | (*GopModes)[ModeNumber].Y = Info->VerticalResolution;\r | |
480 | FreePool (Info);\r | |
481 | }\r | |
482 | \r | |
483 | return EFI_SUCCESS;\r | |
484 | \r | |
485 | FreeGopModes:\r | |
486 | FreePool (*GopModes);\r | |
487 | \r | |
488 | return Status;\r | |
489 | }\r | |
490 | \r | |
92e74550 LE |
491 | /**\r |
492 | Create a set of "one-of-many" (ie. "drop down list") option IFR opcodes,\r | |
493 | based on available GOP resolutions, to be placed under a "one-of-many" (ie.\r | |
494 | "drop down list") opcode.\r | |
495 | \r | |
496 | @param[in] PackageList The package list with the formset and form for\r | |
497 | which the drop down options are produced. Option\r | |
498 | names are added as new strings to PackageList.\r | |
499 | \r | |
500 | @param[out] OpCodeBuffer On output, a dynamically allocated opcode buffer\r | |
501 | with drop down list options corresponding to GOP\r | |
502 | resolutions. The caller is responsible for freeing\r | |
503 | OpCodeBuffer with HiiFreeOpCodeHandle() after use.\r | |
504 | \r | |
da07afaf LE |
505 | @param[in] NumGopModes Number of entries in GopModes.\r |
506 | \r | |
507 | @param[in] GopModes Array of resolutions retrieved from the GOP.\r | |
508 | \r | |
92e74550 LE |
509 | @retval EFI_SUCESS Opcodes have been successfully produced.\r |
510 | \r | |
511 | @return Status codes from underlying functions. PackageList may\r | |
512 | have been extended with new strings. OpCodeBuffer is\r | |
513 | unchanged.\r | |
514 | **/\r | |
515 | STATIC\r | |
516 | EFI_STATUS\r | |
517 | EFIAPI\r | |
518 | CreateResolutionOptions (\r | |
35dd574a | 519 | IN EFI_HII_HANDLE PackageList,\r |
da07afaf LE |
520 | OUT VOID **OpCodeBuffer,\r |
521 | IN UINTN NumGopModes,\r | |
522 | IN GOP_MODE *GopModes\r | |
92e74550 LE |
523 | )\r |
524 | {\r | |
ac0a286f MK |
525 | EFI_STATUS Status;\r |
526 | VOID *OutputBuffer;\r | |
527 | UINTN ModeNumber;\r | |
92e74550 LE |
528 | \r |
529 | OutputBuffer = HiiAllocateOpCodeHandle ();\r | |
530 | if (OutputBuffer == NULL) {\r | |
531 | return EFI_OUT_OF_RESOURCES;\r | |
532 | }\r | |
533 | \r | |
da07afaf | 534 | for (ModeNumber = 0; ModeNumber < NumGopModes; ++ModeNumber) {\r |
ac0a286f MK |
535 | CHAR16 Desc[MAXSIZE_RES_CUR];\r |
536 | EFI_STRING_ID NewString;\r | |
537 | VOID *OpCode;\r | |
538 | \r | |
539 | UnicodeSPrintAsciiFormat (\r | |
540 | Desc,\r | |
541 | sizeof Desc,\r | |
542 | "%Ldx%Ld",\r | |
543 | (INT64)GopModes[ModeNumber].X,\r | |
544 | (INT64)GopModes[ModeNumber].Y\r | |
545 | );\r | |
546 | NewString = HiiSetString (\r | |
547 | PackageList,\r | |
548 | 0 /* new string */,\r | |
549 | Desc,\r | |
550 | NULL /* for all languages */\r | |
551 | );\r | |
da07afaf LE |
552 | if (NewString == 0) {\r |
553 | Status = EFI_OUT_OF_RESOURCES;\r | |
554 | goto FreeOutputBuffer;\r | |
555 | }\r | |
ac0a286f MK |
556 | \r |
557 | OpCode = HiiCreateOneOfOptionOpCode (\r | |
558 | OutputBuffer,\r | |
559 | NewString,\r | |
560 | 0 /* Flags */,\r | |
561 | EFI_IFR_NUMERIC_SIZE_4,\r | |
562 | ModeNumber\r | |
563 | );\r | |
da07afaf LE |
564 | if (OpCode == NULL) {\r |
565 | Status = EFI_OUT_OF_RESOURCES;\r | |
566 | goto FreeOutputBuffer;\r | |
567 | }\r | |
92e74550 LE |
568 | }\r |
569 | \r | |
570 | *OpCodeBuffer = OutputBuffer;\r | |
571 | return EFI_SUCCESS;\r | |
572 | \r | |
573 | FreeOutputBuffer:\r | |
574 | HiiFreeOpCodeHandle (OutputBuffer);\r | |
575 | \r | |
576 | return Status;\r | |
577 | }\r | |
578 | \r | |
92e74550 LE |
579 | /**\r |
580 | Populate the form identified by the (PackageList, FormSetGuid, FormId)\r | |
581 | triplet.\r | |
582 | \r | |
da07afaf LE |
583 | The drop down list of video resolutions is generated from (NumGopModes,\r |
584 | GopModes).\r | |
585 | \r | |
92e74550 LE |
586 | @retval EFI_SUCESS Form successfully updated.\r |
587 | @return Status codes from underlying functions.\r | |
588 | \r | |
589 | **/\r | |
590 | STATIC\r | |
591 | EFI_STATUS\r | |
592 | EFIAPI\r | |
593 | PopulateForm (\r | |
35dd574a | 594 | IN EFI_HII_HANDLE PackageList,\r |
92e74550 | 595 | IN EFI_GUID *FormSetGuid,\r |
da07afaf LE |
596 | IN EFI_FORM_ID FormId,\r |
597 | IN UINTN NumGopModes,\r | |
598 | IN GOP_MODE *GopModes\r | |
92e74550 LE |
599 | )\r |
600 | {\r | |
ac0a286f MK |
601 | EFI_STATUS Status;\r |
602 | VOID *OpCodeBuffer;\r | |
603 | VOID *OpCode;\r | |
604 | EFI_IFR_GUID_LABEL *Anchor;\r | |
605 | VOID *OpCodeBuffer2;\r | |
92e74550 | 606 | \r |
bc4c5366 JJ |
607 | OpCodeBuffer2 = NULL;\r |
608 | \r | |
92e74550 LE |
609 | //\r |
610 | // 1. Allocate an empty opcode buffer.\r | |
611 | //\r | |
612 | OpCodeBuffer = HiiAllocateOpCodeHandle ();\r | |
613 | if (OpCodeBuffer == NULL) {\r | |
614 | return EFI_OUT_OF_RESOURCES;\r | |
615 | }\r | |
616 | \r | |
617 | //\r | |
618 | // 2. Create a label opcode (which is a Tiano extension) inside the buffer.\r | |
619 | // The label's number must match the "anchor" label in the form.\r | |
620 | //\r | |
ac0a286f MK |
621 | OpCode = HiiCreateGuidOpCode (\r |
622 | OpCodeBuffer,\r | |
623 | &gEfiIfrTianoGuid,\r | |
624 | NULL /* optional copy origin */,\r | |
625 | sizeof *Anchor\r | |
626 | );\r | |
92e74550 LE |
627 | if (OpCode == NULL) {\r |
628 | Status = EFI_OUT_OF_RESOURCES;\r | |
629 | goto FreeOpCodeBuffer;\r | |
630 | }\r | |
ac0a286f | 631 | \r |
92e74550 LE |
632 | Anchor = OpCode;\r |
633 | Anchor->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
634 | Anchor->Number = LABEL_RES_NEXT;\r | |
635 | \r | |
636 | //\r | |
637 | // 3. Create the opcodes inside the buffer that are to be inserted into the\r | |
638 | // form.\r | |
639 | //\r | |
640 | // 3.1. Get a list of resolutions.\r | |
641 | //\r | |
ac0a286f MK |
642 | Status = CreateResolutionOptions (\r |
643 | PackageList,\r | |
644 | &OpCodeBuffer2,\r | |
645 | NumGopModes,\r | |
646 | GopModes\r | |
647 | );\r | |
92e74550 LE |
648 | if (EFI_ERROR (Status)) {\r |
649 | goto FreeOpCodeBuffer;\r | |
650 | }\r | |
651 | \r | |
652 | //\r | |
653 | // 3.2. Create a one-of-many question with the above options.\r | |
654 | //\r | |
655 | OpCode = HiiCreateOneOfOpCode (\r | |
656 | OpCodeBuffer, // create opcode inside this\r | |
657 | // opcode buffer,\r | |
658 | QUESTION_RES_NEXT, // ID of question,\r | |
659 | FORMSTATEID_MAIN_FORM, // identifies form state\r | |
660 | // storage,\r | |
ac0a286f MK |
661 | (UINT16)OFFSET_OF (\r |
662 | MAIN_FORM_STATE, // value of question stored\r | |
663 | NextPreferredResolution\r | |
664 | ), // at this offset,\r | |
92e74550 LE |
665 | STRING_TOKEN (STR_RES_NEXT), // Prompt,\r |
666 | STRING_TOKEN (STR_RES_NEXT_HELP), // Help,\r | |
667 | 0, // QuestionFlags,\r | |
668 | EFI_IFR_NUMERIC_SIZE_4, // see sizeof\r | |
669 | // NextPreferredResolution,\r | |
670 | OpCodeBuffer2, // buffer with possible\r | |
671 | // choices,\r | |
672 | NULL // DEFAULT opcodes\r | |
673 | );\r | |
674 | if (OpCode == NULL) {\r | |
675 | Status = EFI_OUT_OF_RESOURCES;\r | |
676 | goto FreeOpCodeBuffer2;\r | |
677 | }\r | |
678 | \r | |
679 | //\r | |
680 | // 4. Update the form with the opcode buffer.\r | |
681 | //\r | |
ac0a286f MK |
682 | Status = HiiUpdateForm (\r |
683 | PackageList,\r | |
684 | FormSetGuid,\r | |
685 | FormId,\r | |
92e74550 LE |
686 | OpCodeBuffer, // buffer with head anchor, and new contents to be\r |
687 | // inserted at it\r | |
688 | NULL // buffer with tail anchor, for deleting old\r | |
689 | // contents up to it\r | |
690 | );\r | |
691 | \r | |
692 | FreeOpCodeBuffer2:\r | |
693 | HiiFreeOpCodeHandle (OpCodeBuffer2);\r | |
694 | \r | |
695 | FreeOpCodeBuffer:\r | |
696 | HiiFreeOpCodeHandle (OpCodeBuffer);\r | |
697 | \r | |
698 | return Status;\r | |
699 | }\r | |
700 | \r | |
bdaf30e4 LE |
701 | /**\r |
702 | Load and execute the platform configuration.\r | |
703 | \r | |
704 | @retval EFI_SUCCESS Configuration loaded and executed.\r | |
705 | @return Status codes from PlatformConfigLoad().\r | |
706 | **/\r | |
707 | STATIC\r | |
708 | EFI_STATUS\r | |
709 | EFIAPI\r | |
710 | ExecutePlatformConfig (\r | |
711 | VOID\r | |
712 | )\r | |
713 | {\r | |
ac0a286f MK |
714 | EFI_STATUS Status;\r |
715 | PLATFORM_CONFIG PlatformConfig;\r | |
716 | UINT64 OptionalElements;\r | |
717 | RETURN_STATUS PcdStatus;\r | |
bdaf30e4 LE |
718 | \r |
719 | Status = PlatformConfigLoad (&PlatformConfig, &OptionalElements);\r | |
720 | if (EFI_ERROR (Status)) {\r | |
ac0a286f MK |
721 | DEBUG ((\r |
722 | (Status == EFI_NOT_FOUND) ? DEBUG_VERBOSE : DEBUG_ERROR,\r | |
723 | "%a: failed to load platform config: %r\n",\r | |
724 | __FUNCTION__,\r | |
725 | Status\r | |
726 | ));\r | |
bdaf30e4 LE |
727 | return Status;\r |
728 | }\r | |
729 | \r | |
730 | if (OptionalElements & PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION) {\r | |
731 | //\r | |
732 | // Pass the preferred resolution to GraphicsConsoleDxe via dynamic PCDs.\r | |
733 | //\r | |
ac0a286f MK |
734 | PcdStatus = PcdSet32S (\r |
735 | PcdVideoHorizontalResolution,\r | |
736 | PlatformConfig.HorizontalResolution\r | |
737 | );\r | |
4d1362e1 LE |
738 | ASSERT_RETURN_ERROR (PcdStatus);\r |
739 | \r | |
ac0a286f MK |
740 | PcdStatus = PcdSet32S (\r |
741 | PcdVideoVerticalResolution,\r | |
742 | PlatformConfig.VerticalResolution\r | |
743 | );\r | |
4d1362e1 | 744 | ASSERT_RETURN_ERROR (PcdStatus);\r |
bdaf30e4 LE |
745 | }\r |
746 | \r | |
747 | return EFI_SUCCESS;\r | |
748 | }\r | |
749 | \r | |
da07afaf LE |
750 | /**\r |
751 | Notification callback for GOP interface installation.\r | |
752 | \r | |
753 | @param[in] Event Event whose notification function is being invoked.\r | |
754 | \r | |
755 | @param[in] Context The pointer to the notification function's context, which\r | |
756 | is implementation-dependent.\r | |
757 | **/\r | |
758 | STATIC\r | |
759 | VOID\r | |
760 | EFIAPI\r | |
761 | GopInstalled (\r | |
ac0a286f MK |
762 | IN EFI_EVENT Event,\r |
763 | IN VOID *Context\r | |
da07afaf LE |
764 | )\r |
765 | {\r | |
ac0a286f MK |
766 | EFI_STATUS Status;\r |
767 | EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;\r | |
da07afaf LE |
768 | \r |
769 | ASSERT (Event == mGopEvent);\r | |
770 | \r | |
771 | //\r | |
772 | // Check further GOPs.\r | |
773 | //\r | |
ac0a286f | 774 | for ( ; ;) {\r |
da07afaf | 775 | mNumGopModes = 0;\r |
ac0a286f | 776 | mGopModes = NULL;\r |
da07afaf | 777 | \r |
ac0a286f MK |
778 | Status = gBS->LocateProtocol (\r |
779 | &gEfiGraphicsOutputProtocolGuid,\r | |
780 | mGopTracker,\r | |
781 | (VOID **)&Gop\r | |
782 | );\r | |
da07afaf LE |
783 | if (EFI_ERROR (Status)) {\r |
784 | return;\r | |
785 | }\r | |
786 | \r | |
787 | Status = QueryGopModes (Gop, &mNumGopModes, &mGopModes);\r | |
788 | if (EFI_ERROR (Status)) {\r | |
789 | continue;\r | |
790 | }\r | |
791 | \r | |
ac0a286f MK |
792 | Status = PopulateForm (\r |
793 | mInstalledPackages,\r | |
794 | &gOvmfPlatformConfigGuid,\r | |
795 | FORMID_MAIN_FORM,\r | |
796 | mNumGopModes,\r | |
797 | mGopModes\r | |
798 | );\r | |
da07afaf LE |
799 | if (EFI_ERROR (Status)) {\r |
800 | FreePool (mGopModes);\r | |
801 | continue;\r | |
802 | }\r | |
803 | \r | |
804 | break;\r | |
805 | }\r | |
806 | \r | |
807 | //\r | |
808 | // Success -- so uninstall this callback. Closing the event removes all\r | |
809 | // pending notifications and all protocol registrations.\r | |
810 | //\r | |
811 | Status = gBS->CloseEvent (mGopEvent);\r | |
812 | ASSERT_EFI_ERROR (Status);\r | |
ac0a286f | 813 | mGopEvent = NULL;\r |
da07afaf LE |
814 | mGopTracker = NULL;\r |
815 | }\r | |
816 | \r | |
d945a8ba LE |
817 | /**\r |
818 | Entry point for this driver.\r | |
819 | \r | |
820 | @param[in] ImageHandle Image handle of this driver.\r | |
821 | @param[in] SystemTable Pointer to SystemTable.\r | |
822 | \r | |
823 | @retval EFI_SUCESS Driver has loaded successfully.\r | |
877a4dbb LE |
824 | @retval EFI_OUT_OF_RESOURCES Failed to install HII packages.\r |
825 | @return Error codes from lower level functions.\r | |
d945a8ba LE |
826 | \r |
827 | **/\r | |
828 | EFI_STATUS\r | |
829 | EFIAPI\r | |
830 | PlatformInit (\r | |
831 | IN EFI_HANDLE ImageHandle,\r | |
832 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
833 | )\r | |
834 | {\r | |
ac0a286f | 835 | EFI_STATUS Status;\r |
877a4dbb | 836 | \r |
bdaf30e4 | 837 | ExecutePlatformConfig ();\r |
877a4dbb LE |
838 | \r |
839 | mConfigAccess.ExtractConfig = &ExtractConfig;\r | |
840 | mConfigAccess.RouteConfig = &RouteConfig;\r | |
841 | mConfigAccess.Callback = &Callback;\r | |
842 | \r | |
843 | //\r | |
844 | // Declare ourselves suitable for HII communication.\r | |
845 | //\r | |
ac0a286f MK |
846 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
847 | &ImageHandle,\r | |
848 | &gEfiDevicePathProtocolGuid,\r | |
849 | &mPkgDevicePath,\r | |
850 | &gEfiHiiConfigAccessProtocolGuid,\r | |
851 | &mConfigAccess,\r | |
852 | NULL\r | |
853 | );\r | |
877a4dbb LE |
854 | if (EFI_ERROR (Status)) {\r |
855 | return Status;\r | |
856 | }\r | |
857 | \r | |
858 | //\r | |
859 | // Publish the HII package list to HII Database.\r | |
860 | //\r | |
861 | mInstalledPackages = HiiAddPackages (\r | |
862 | &gEfiCallerIdGuid, // PackageListGuid\r | |
863 | ImageHandle, // associated DeviceHandle\r | |
864 | PlatformDxeStrings, // 1st package\r | |
865 | PlatformFormsBin, // 2nd package\r | |
866 | NULL // terminator\r | |
867 | );\r | |
868 | if (mInstalledPackages == NULL) {\r | |
869 | Status = EFI_OUT_OF_RESOURCES;\r | |
870 | goto UninstallProtocols;\r | |
871 | }\r | |
872 | \r | |
ac0a286f MK |
873 | Status = gBS->CreateEvent (\r |
874 | EVT_NOTIFY_SIGNAL,\r | |
875 | TPL_CALLBACK,\r | |
876 | &GopInstalled,\r | |
877 | NULL /* Context */,\r | |
878 | &mGopEvent\r | |
879 | );\r | |
92e74550 LE |
880 | if (EFI_ERROR (Status)) {\r |
881 | goto RemovePackages;\r | |
882 | }\r | |
883 | \r | |
ac0a286f MK |
884 | Status = gBS->RegisterProtocolNotify (\r |
885 | &gEfiGraphicsOutputProtocolGuid,\r | |
886 | mGopEvent,\r | |
887 | &mGopTracker\r | |
888 | );\r | |
da07afaf LE |
889 | if (EFI_ERROR (Status)) {\r |
890 | goto CloseGopEvent;\r | |
891 | }\r | |
892 | \r | |
893 | //\r | |
894 | // Check already installed GOPs.\r | |
895 | //\r | |
896 | Status = gBS->SignalEvent (mGopEvent);\r | |
897 | ASSERT_EFI_ERROR (Status);\r | |
898 | \r | |
d945a8ba | 899 | return EFI_SUCCESS;\r |
877a4dbb | 900 | \r |
da07afaf LE |
901 | CloseGopEvent:\r |
902 | gBS->CloseEvent (mGopEvent);\r | |
903 | \r | |
92e74550 LE |
904 | RemovePackages:\r |
905 | HiiRemovePackages (mInstalledPackages);\r | |
906 | \r | |
877a4dbb | 907 | UninstallProtocols:\r |
ac0a286f MK |
908 | gBS->UninstallMultipleProtocolInterfaces (\r |
909 | ImageHandle,\r | |
910 | &gEfiDevicePathProtocolGuid,\r | |
911 | &mPkgDevicePath,\r | |
912 | &gEfiHiiConfigAccessProtocolGuid,\r | |
913 | &mConfigAccess,\r | |
914 | NULL\r | |
915 | );\r | |
877a4dbb | 916 | return Status;\r |
d945a8ba LE |
917 | }\r |
918 | \r | |
919 | /**\r | |
920 | Unload the driver.\r | |
921 | \r | |
922 | @param[in] ImageHandle Handle that identifies the image to evict.\r | |
923 | \r | |
924 | @retval EFI_SUCCESS The image has been unloaded.\r | |
925 | **/\r | |
926 | EFI_STATUS\r | |
927 | EFIAPI\r | |
928 | PlatformUnload (\r | |
929 | IN EFI_HANDLE ImageHandle\r | |
930 | )\r | |
931 | {\r | |
da07afaf LE |
932 | if (mGopEvent == NULL) {\r |
933 | //\r | |
934 | // The GOP callback ran successfully and unregistered itself. Release the\r | |
935 | // resources allocated there.\r | |
936 | //\r | |
937 | ASSERT (mGopModes != NULL);\r | |
938 | FreePool (mGopModes);\r | |
939 | } else {\r | |
940 | //\r | |
941 | // Otherwise we need to unregister the callback.\r | |
942 | //\r | |
943 | ASSERT (mGopModes == NULL);\r | |
944 | gBS->CloseEvent (mGopEvent);\r | |
945 | }\r | |
946 | \r | |
947 | //\r | |
948 | // Release resources allocated by the entry point.\r | |
949 | //\r | |
877a4dbb | 950 | HiiRemovePackages (mInstalledPackages);\r |
ac0a286f MK |
951 | gBS->UninstallMultipleProtocolInterfaces (\r |
952 | ImageHandle,\r | |
953 | &gEfiDevicePathProtocolGuid,\r | |
954 | &mPkgDevicePath,\r | |
955 | &gEfiHiiConfigAccessProtocolGuid,\r | |
956 | &mConfigAccess,\r | |
957 | NULL\r | |
958 | );\r | |
d945a8ba LE |
959 | return EFI_SUCCESS;\r |
960 | }\r |