]>
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 |
30d62f5e DP |
235 | if ((Progress == NULL) || (Results == NULL)) {\r |
236 | return EFI_INVALID_PARAMETER;\r | |
237 | }\r | |
238 | \r | |
cbd08bcc LE |
239 | Status = PlatformConfigToFormState (&MainFormState);\r |
240 | if (EFI_ERROR (Status)) {\r | |
241 | *Progress = Request;\r | |
242 | return Status;\r | |
243 | }\r | |
244 | \r | |
245 | //\r | |
246 | // Answer the textual request keying off the binary form state.\r | |
247 | //\r | |
ac0a286f MK |
248 | Status = gHiiConfigRouting->BlockToConfig (\r |
249 | gHiiConfigRouting,\r | |
250 | Request,\r | |
251 | (VOID *)&MainFormState,\r | |
252 | sizeof MainFormState,\r | |
253 | Results,\r | |
254 | Progress\r | |
255 | );\r | |
92e74550 | 256 | if (EFI_ERROR (Status)) {\r |
ac0a286f MK |
257 | DEBUG ((\r |
258 | DEBUG_ERROR,\r | |
259 | "%a: BlockToConfig(): %r, Progress=\"%s\"\n",\r | |
260 | __FUNCTION__,\r | |
261 | Status,\r | |
262 | (Status == EFI_DEVICE_ERROR) ? NULL : *Progress\r | |
263 | ));\r | |
92e74550 | 264 | } else {\r |
70d5086c | 265 | DEBUG ((DEBUG_VERBOSE, "%a: Results=\"%s\"\n", __FUNCTION__, *Results));\r |
92e74550 | 266 | }\r |
ac0a286f | 267 | \r |
92e74550 | 268 | return Status;\r |
877a4dbb LE |
269 | }\r |
270 | \r | |
ddb2c493 LE |
271 | /**\r |
272 | Interpret the binary form state and save it as persistent platform\r | |
273 | configuration.\r | |
274 | \r | |
275 | @param[in] MainFormState Binary form/widget state to verify and save.\r | |
276 | \r | |
277 | @retval EFI_SUCCESS Platform configuration saved.\r | |
278 | @return Error codes from underlying functions.\r | |
279 | **/\r | |
280 | STATIC\r | |
281 | EFI_STATUS\r | |
282 | EFIAPI\r | |
283 | FormStateToPlatformConfig (\r | |
ac0a286f | 284 | IN CONST MAIN_FORM_STATE *MainFormState\r |
ddb2c493 LE |
285 | )\r |
286 | {\r | |
ac0a286f MK |
287 | EFI_STATUS Status;\r |
288 | PLATFORM_CONFIG PlatformConfig;\r | |
289 | CONST GOP_MODE *GopMode;\r | |
ddb2c493 LE |
290 | \r |
291 | //\r | |
292 | // There's nothing to do with the textual CurrentPreferredResolution field.\r | |
293 | // We verify and translate the selection in the drop-down list.\r | |
294 | //\r | |
295 | if (MainFormState->NextPreferredResolution >= mNumGopModes) {\r | |
296 | return EFI_INVALID_PARAMETER;\r | |
297 | }\r | |
ac0a286f | 298 | \r |
ddb2c493 LE |
299 | GopMode = mGopModes + MainFormState->NextPreferredResolution;\r |
300 | \r | |
301 | ZeroMem (&PlatformConfig, sizeof PlatformConfig);\r | |
302 | PlatformConfig.HorizontalResolution = GopMode->X;\r | |
303 | PlatformConfig.VerticalResolution = GopMode->Y;\r | |
304 | \r | |
305 | Status = PlatformConfigSave (&PlatformConfig);\r | |
306 | return Status;\r | |
307 | }\r | |
308 | \r | |
ddb2c493 LE |
309 | /**\r |
310 | This function is called by the HII machinery when it wants the driver to\r | |
311 | interpret and persist the form state.\r | |
312 | \r | |
313 | See the precise documentation in the UEFI spec.\r | |
314 | \r | |
315 | @param[in] This The Config Access Protocol instance.\r | |
316 | \r | |
317 | @param[in] Configuration A <ConfigResp> format UCS-2 string describing the\r | |
318 | form state.\r | |
319 | \r | |
320 | @param[out] Progress A pointer into Configuration on output,\r | |
321 | identifying the element where processing failed.\r | |
322 | \r | |
323 | @retval EFI_SUCCESS Configuration verified, state permanent.\r | |
324 | \r | |
325 | @return Status codes from underlying functions.\r | |
326 | **/\r | |
877a4dbb LE |
327 | STATIC\r |
328 | EFI_STATUS\r | |
329 | EFIAPI\r | |
330 | RouteConfig (\r | |
331 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
332 | IN CONST EFI_STRING Configuration,\r | |
333 | OUT EFI_STRING *Progress\r | |
ac0a286f | 334 | )\r |
877a4dbb | 335 | {\r |
ac0a286f MK |
336 | MAIN_FORM_STATE MainFormState;\r |
337 | UINTN BlockSize;\r | |
338 | EFI_STATUS Status;\r | |
ddb2c493 | 339 | \r |
ac0a286f MK |
340 | DEBUG ((\r |
341 | DEBUG_VERBOSE,\r | |
342 | "%a: Configuration=\"%s\"\n",\r | |
343 | __FUNCTION__,\r | |
344 | Configuration\r | |
345 | ));\r | |
ddb2c493 | 346 | \r |
165b5bcd | 347 | if ((Progress == NULL) || (Configuration == NULL)) {\r |
30d62f5e DP |
348 | return EFI_INVALID_PARAMETER;\r |
349 | }\r | |
350 | \r | |
ddb2c493 LE |
351 | //\r |
352 | // the "read" step in RMW\r | |
353 | //\r | |
354 | Status = PlatformConfigToFormState (&MainFormState);\r | |
355 | if (EFI_ERROR (Status)) {\r | |
356 | *Progress = Configuration;\r | |
357 | return Status;\r | |
358 | }\r | |
359 | \r | |
360 | //\r | |
361 | // the "modify" step in RMW\r | |
362 | //\r | |
363 | // (Update the binary form state. This update may be partial, which is why in\r | |
364 | // general we must pre-load the form state from the platform config.)\r | |
365 | //\r | |
366 | BlockSize = sizeof MainFormState;\r | |
ac0a286f MK |
367 | Status = gHiiConfigRouting->ConfigToBlock (\r |
368 | gHiiConfigRouting,\r | |
369 | Configuration,\r | |
370 | (VOID *)&MainFormState,\r | |
371 | &BlockSize,\r | |
372 | Progress\r | |
373 | );\r | |
ddb2c493 | 374 | if (EFI_ERROR (Status)) {\r |
ac0a286f MK |
375 | DEBUG ((\r |
376 | DEBUG_ERROR,\r | |
377 | "%a: ConfigToBlock(): %r, Progress=\"%s\"\n",\r | |
378 | __FUNCTION__,\r | |
379 | Status,\r | |
380 | (Status == EFI_BUFFER_TOO_SMALL) ? NULL : *Progress\r | |
381 | ));\r | |
ddb2c493 LE |
382 | return Status;\r |
383 | }\r | |
384 | \r | |
385 | //\r | |
386 | // the "write" step in RMW\r | |
387 | //\r | |
388 | Status = FormStateToPlatformConfig (&MainFormState);\r | |
389 | if (EFI_ERROR (Status)) {\r | |
390 | *Progress = Configuration;\r | |
391 | }\r | |
ac0a286f | 392 | \r |
ddb2c493 | 393 | return Status;\r |
877a4dbb LE |
394 | }\r |
395 | \r | |
877a4dbb LE |
396 | STATIC\r |
397 | EFI_STATUS\r | |
398 | EFIAPI\r | |
399 | Callback (\r | |
ac0a286f MK |
400 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r |
401 | IN EFI_BROWSER_ACTION Action,\r | |
402 | IN EFI_QUESTION_ID QuestionId,\r | |
403 | IN UINT8 Type,\r | |
404 | IN OUT EFI_IFR_TYPE_VALUE *Value,\r | |
405 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
877a4dbb LE |
406 | )\r |
407 | {\r | |
ac0a286f MK |
408 | DEBUG ((\r |
409 | DEBUG_VERBOSE,\r | |
410 | "%a: Action=0x%Lx QuestionId=%d Type=%d\n",\r | |
411 | __FUNCTION__,\r | |
412 | (UINT64)Action,\r | |
413 | QuestionId,\r | |
414 | Type\r | |
415 | ));\r | |
1df57ba3 LE |
416 | \r |
417 | if (Action != EFI_BROWSER_ACTION_CHANGED) {\r | |
418 | return EFI_UNSUPPORTED;\r | |
419 | }\r | |
420 | \r | |
421 | switch (QuestionId) {\r | |
ac0a286f MK |
422 | case QUESTION_SAVE_EXIT:\r |
423 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;\r | |
424 | break;\r | |
1df57ba3 | 425 | \r |
ac0a286f MK |
426 | case QUESTION_DISCARD_EXIT:\r |
427 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r | |
428 | break;\r | |
1df57ba3 | 429 | \r |
ac0a286f MK |
430 | default:\r |
431 | break;\r | |
1df57ba3 LE |
432 | }\r |
433 | \r | |
877a4dbb LE |
434 | return EFI_SUCCESS;\r |
435 | }\r | |
436 | \r | |
da07afaf LE |
437 | /**\r |
438 | Query and save all resolutions supported by the GOP.\r | |
439 | \r | |
440 | @param[in] Gop The Graphics Output Protocol instance to query.\r | |
441 | \r | |
442 | @param[out] NumGopModes The number of modes supported by the GOP. On output,\r | |
443 | this parameter will be positive.\r | |
444 | \r | |
445 | @param[out] GopModes On output, a dynamically allocated array containing\r | |
446 | the resolutions returned by the GOP. The caller is\r | |
447 | responsible for freeing the array after use.\r | |
448 | \r | |
449 | @retval EFI_UNSUPPORTED No modes found.\r | |
450 | @retval EFI_OUT_OF_RESOURCES Failed to allocate GopModes.\r | |
451 | @return Error codes from Gop->QueryMode().\r | |
452 | \r | |
453 | **/\r | |
454 | STATIC\r | |
455 | EFI_STATUS\r | |
456 | EFIAPI\r | |
457 | QueryGopModes (\r | |
ac0a286f MK |
458 | IN EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop,\r |
459 | OUT UINTN *NumGopModes,\r | |
460 | OUT GOP_MODE **GopModes\r | |
da07afaf LE |
461 | )\r |
462 | {\r | |
ac0a286f MK |
463 | EFI_STATUS Status;\r |
464 | UINT32 ModeNumber;\r | |
da07afaf LE |
465 | \r |
466 | if (Gop->Mode->MaxMode == 0) {\r | |
467 | return EFI_UNSUPPORTED;\r | |
468 | }\r | |
ac0a286f | 469 | \r |
da07afaf LE |
470 | *NumGopModes = Gop->Mode->MaxMode;\r |
471 | \r | |
472 | *GopModes = AllocatePool (Gop->Mode->MaxMode * sizeof **GopModes);\r | |
473 | if (*GopModes == NULL) {\r | |
474 | return EFI_OUT_OF_RESOURCES;\r | |
475 | }\r | |
476 | \r | |
477 | for (ModeNumber = 0; ModeNumber < Gop->Mode->MaxMode; ++ModeNumber) {\r | |
ac0a286f MK |
478 | EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r |
479 | UINTN SizeOfInfo;\r | |
da07afaf LE |
480 | \r |
481 | Status = Gop->QueryMode (Gop, ModeNumber, &SizeOfInfo, &Info);\r | |
482 | if (EFI_ERROR (Status)) {\r | |
483 | goto FreeGopModes;\r | |
484 | }\r | |
485 | \r | |
486 | (*GopModes)[ModeNumber].X = Info->HorizontalResolution;\r | |
487 | (*GopModes)[ModeNumber].Y = Info->VerticalResolution;\r | |
488 | FreePool (Info);\r | |
489 | }\r | |
490 | \r | |
491 | return EFI_SUCCESS;\r | |
492 | \r | |
493 | FreeGopModes:\r | |
494 | FreePool (*GopModes);\r | |
495 | \r | |
496 | return Status;\r | |
497 | }\r | |
498 | \r | |
92e74550 LE |
499 | /**\r |
500 | Create a set of "one-of-many" (ie. "drop down list") option IFR opcodes,\r | |
501 | based on available GOP resolutions, to be placed under a "one-of-many" (ie.\r | |
502 | "drop down list") opcode.\r | |
503 | \r | |
504 | @param[in] PackageList The package list with the formset and form for\r | |
505 | which the drop down options are produced. Option\r | |
506 | names are added as new strings to PackageList.\r | |
507 | \r | |
508 | @param[out] OpCodeBuffer On output, a dynamically allocated opcode buffer\r | |
509 | with drop down list options corresponding to GOP\r | |
510 | resolutions. The caller is responsible for freeing\r | |
511 | OpCodeBuffer with HiiFreeOpCodeHandle() after use.\r | |
512 | \r | |
da07afaf LE |
513 | @param[in] NumGopModes Number of entries in GopModes.\r |
514 | \r | |
515 | @param[in] GopModes Array of resolutions retrieved from the GOP.\r | |
516 | \r | |
92e74550 LE |
517 | @retval EFI_SUCESS Opcodes have been successfully produced.\r |
518 | \r | |
519 | @return Status codes from underlying functions. PackageList may\r | |
520 | have been extended with new strings. OpCodeBuffer is\r | |
521 | unchanged.\r | |
522 | **/\r | |
523 | STATIC\r | |
524 | EFI_STATUS\r | |
525 | EFIAPI\r | |
526 | CreateResolutionOptions (\r | |
35dd574a | 527 | IN EFI_HII_HANDLE PackageList,\r |
da07afaf LE |
528 | OUT VOID **OpCodeBuffer,\r |
529 | IN UINTN NumGopModes,\r | |
530 | IN GOP_MODE *GopModes\r | |
92e74550 LE |
531 | )\r |
532 | {\r | |
ac0a286f MK |
533 | EFI_STATUS Status;\r |
534 | VOID *OutputBuffer;\r | |
535 | UINTN ModeNumber;\r | |
92e74550 LE |
536 | \r |
537 | OutputBuffer = HiiAllocateOpCodeHandle ();\r | |
538 | if (OutputBuffer == NULL) {\r | |
539 | return EFI_OUT_OF_RESOURCES;\r | |
540 | }\r | |
541 | \r | |
da07afaf | 542 | for (ModeNumber = 0; ModeNumber < NumGopModes; ++ModeNumber) {\r |
ac0a286f MK |
543 | CHAR16 Desc[MAXSIZE_RES_CUR];\r |
544 | EFI_STRING_ID NewString;\r | |
545 | VOID *OpCode;\r | |
546 | \r | |
547 | UnicodeSPrintAsciiFormat (\r | |
548 | Desc,\r | |
549 | sizeof Desc,\r | |
550 | "%Ldx%Ld",\r | |
551 | (INT64)GopModes[ModeNumber].X,\r | |
552 | (INT64)GopModes[ModeNumber].Y\r | |
553 | );\r | |
554 | NewString = HiiSetString (\r | |
555 | PackageList,\r | |
556 | 0 /* new string */,\r | |
557 | Desc,\r | |
558 | NULL /* for all languages */\r | |
559 | );\r | |
da07afaf LE |
560 | if (NewString == 0) {\r |
561 | Status = EFI_OUT_OF_RESOURCES;\r | |
562 | goto FreeOutputBuffer;\r | |
563 | }\r | |
ac0a286f MK |
564 | \r |
565 | OpCode = HiiCreateOneOfOptionOpCode (\r | |
566 | OutputBuffer,\r | |
567 | NewString,\r | |
568 | 0 /* Flags */,\r | |
569 | EFI_IFR_NUMERIC_SIZE_4,\r | |
570 | ModeNumber\r | |
571 | );\r | |
da07afaf LE |
572 | if (OpCode == NULL) {\r |
573 | Status = EFI_OUT_OF_RESOURCES;\r | |
574 | goto FreeOutputBuffer;\r | |
575 | }\r | |
92e74550 LE |
576 | }\r |
577 | \r | |
578 | *OpCodeBuffer = OutputBuffer;\r | |
579 | return EFI_SUCCESS;\r | |
580 | \r | |
581 | FreeOutputBuffer:\r | |
582 | HiiFreeOpCodeHandle (OutputBuffer);\r | |
583 | \r | |
584 | return Status;\r | |
585 | }\r | |
586 | \r | |
92e74550 LE |
587 | /**\r |
588 | Populate the form identified by the (PackageList, FormSetGuid, FormId)\r | |
589 | triplet.\r | |
590 | \r | |
da07afaf LE |
591 | The drop down list of video resolutions is generated from (NumGopModes,\r |
592 | GopModes).\r | |
593 | \r | |
92e74550 LE |
594 | @retval EFI_SUCESS Form successfully updated.\r |
595 | @return Status codes from underlying functions.\r | |
596 | \r | |
597 | **/\r | |
598 | STATIC\r | |
599 | EFI_STATUS\r | |
600 | EFIAPI\r | |
601 | PopulateForm (\r | |
35dd574a | 602 | IN EFI_HII_HANDLE PackageList,\r |
92e74550 | 603 | IN EFI_GUID *FormSetGuid,\r |
da07afaf LE |
604 | IN EFI_FORM_ID FormId,\r |
605 | IN UINTN NumGopModes,\r | |
606 | IN GOP_MODE *GopModes\r | |
92e74550 LE |
607 | )\r |
608 | {\r | |
ac0a286f MK |
609 | EFI_STATUS Status;\r |
610 | VOID *OpCodeBuffer;\r | |
611 | VOID *OpCode;\r | |
612 | EFI_IFR_GUID_LABEL *Anchor;\r | |
613 | VOID *OpCodeBuffer2;\r | |
92e74550 | 614 | \r |
bc4c5366 JJ |
615 | OpCodeBuffer2 = NULL;\r |
616 | \r | |
92e74550 LE |
617 | //\r |
618 | // 1. Allocate an empty opcode buffer.\r | |
619 | //\r | |
620 | OpCodeBuffer = HiiAllocateOpCodeHandle ();\r | |
621 | if (OpCodeBuffer == NULL) {\r | |
622 | return EFI_OUT_OF_RESOURCES;\r | |
623 | }\r | |
624 | \r | |
625 | //\r | |
626 | // 2. Create a label opcode (which is a Tiano extension) inside the buffer.\r | |
627 | // The label's number must match the "anchor" label in the form.\r | |
628 | //\r | |
ac0a286f MK |
629 | OpCode = HiiCreateGuidOpCode (\r |
630 | OpCodeBuffer,\r | |
631 | &gEfiIfrTianoGuid,\r | |
632 | NULL /* optional copy origin */,\r | |
633 | sizeof *Anchor\r | |
634 | );\r | |
92e74550 LE |
635 | if (OpCode == NULL) {\r |
636 | Status = EFI_OUT_OF_RESOURCES;\r | |
637 | goto FreeOpCodeBuffer;\r | |
638 | }\r | |
ac0a286f | 639 | \r |
92e74550 LE |
640 | Anchor = OpCode;\r |
641 | Anchor->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
642 | Anchor->Number = LABEL_RES_NEXT;\r | |
643 | \r | |
644 | //\r | |
645 | // 3. Create the opcodes inside the buffer that are to be inserted into the\r | |
646 | // form.\r | |
647 | //\r | |
648 | // 3.1. Get a list of resolutions.\r | |
649 | //\r | |
ac0a286f MK |
650 | Status = CreateResolutionOptions (\r |
651 | PackageList,\r | |
652 | &OpCodeBuffer2,\r | |
653 | NumGopModes,\r | |
654 | GopModes\r | |
655 | );\r | |
92e74550 LE |
656 | if (EFI_ERROR (Status)) {\r |
657 | goto FreeOpCodeBuffer;\r | |
658 | }\r | |
659 | \r | |
660 | //\r | |
661 | // 3.2. Create a one-of-many question with the above options.\r | |
662 | //\r | |
663 | OpCode = HiiCreateOneOfOpCode (\r | |
664 | OpCodeBuffer, // create opcode inside this\r | |
665 | // opcode buffer,\r | |
666 | QUESTION_RES_NEXT, // ID of question,\r | |
667 | FORMSTATEID_MAIN_FORM, // identifies form state\r | |
668 | // storage,\r | |
ac0a286f MK |
669 | (UINT16)OFFSET_OF (\r |
670 | MAIN_FORM_STATE, // value of question stored\r | |
671 | NextPreferredResolution\r | |
672 | ), // at this offset,\r | |
92e74550 LE |
673 | STRING_TOKEN (STR_RES_NEXT), // Prompt,\r |
674 | STRING_TOKEN (STR_RES_NEXT_HELP), // Help,\r | |
675 | 0, // QuestionFlags,\r | |
676 | EFI_IFR_NUMERIC_SIZE_4, // see sizeof\r | |
677 | // NextPreferredResolution,\r | |
678 | OpCodeBuffer2, // buffer with possible\r | |
679 | // choices,\r | |
680 | NULL // DEFAULT opcodes\r | |
681 | );\r | |
682 | if (OpCode == NULL) {\r | |
683 | Status = EFI_OUT_OF_RESOURCES;\r | |
684 | goto FreeOpCodeBuffer2;\r | |
685 | }\r | |
686 | \r | |
687 | //\r | |
688 | // 4. Update the form with the opcode buffer.\r | |
689 | //\r | |
ac0a286f MK |
690 | Status = HiiUpdateForm (\r |
691 | PackageList,\r | |
692 | FormSetGuid,\r | |
693 | FormId,\r | |
92e74550 LE |
694 | OpCodeBuffer, // buffer with head anchor, and new contents to be\r |
695 | // inserted at it\r | |
696 | NULL // buffer with tail anchor, for deleting old\r | |
697 | // contents up to it\r | |
698 | );\r | |
699 | \r | |
700 | FreeOpCodeBuffer2:\r | |
701 | HiiFreeOpCodeHandle (OpCodeBuffer2);\r | |
702 | \r | |
703 | FreeOpCodeBuffer:\r | |
704 | HiiFreeOpCodeHandle (OpCodeBuffer);\r | |
705 | \r | |
706 | return Status;\r | |
707 | }\r | |
708 | \r | |
bdaf30e4 LE |
709 | /**\r |
710 | Load and execute the platform configuration.\r | |
711 | \r | |
712 | @retval EFI_SUCCESS Configuration loaded and executed.\r | |
713 | @return Status codes from PlatformConfigLoad().\r | |
714 | **/\r | |
715 | STATIC\r | |
716 | EFI_STATUS\r | |
717 | EFIAPI\r | |
718 | ExecutePlatformConfig (\r | |
719 | VOID\r | |
720 | )\r | |
721 | {\r | |
ac0a286f MK |
722 | EFI_STATUS Status;\r |
723 | PLATFORM_CONFIG PlatformConfig;\r | |
724 | UINT64 OptionalElements;\r | |
725 | RETURN_STATUS PcdStatus;\r | |
bdaf30e4 LE |
726 | \r |
727 | Status = PlatformConfigLoad (&PlatformConfig, &OptionalElements);\r | |
728 | if (EFI_ERROR (Status)) {\r | |
ac0a286f MK |
729 | DEBUG ((\r |
730 | (Status == EFI_NOT_FOUND) ? DEBUG_VERBOSE : DEBUG_ERROR,\r | |
731 | "%a: failed to load platform config: %r\n",\r | |
732 | __FUNCTION__,\r | |
733 | Status\r | |
734 | ));\r | |
bdaf30e4 LE |
735 | return Status;\r |
736 | }\r | |
737 | \r | |
738 | if (OptionalElements & PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION) {\r | |
739 | //\r | |
740 | // Pass the preferred resolution to GraphicsConsoleDxe via dynamic PCDs.\r | |
741 | //\r | |
ac0a286f MK |
742 | PcdStatus = PcdSet32S (\r |
743 | PcdVideoHorizontalResolution,\r | |
744 | PlatformConfig.HorizontalResolution\r | |
745 | );\r | |
4d1362e1 LE |
746 | ASSERT_RETURN_ERROR (PcdStatus);\r |
747 | \r | |
ac0a286f MK |
748 | PcdStatus = PcdSet32S (\r |
749 | PcdVideoVerticalResolution,\r | |
750 | PlatformConfig.VerticalResolution\r | |
751 | );\r | |
4d1362e1 | 752 | ASSERT_RETURN_ERROR (PcdStatus);\r |
929804b1 GH |
753 | \r |
754 | PcdStatus = PcdSet8S (PcdVideoResolutionSource, 1);\r | |
755 | ASSERT_RETURN_ERROR (PcdStatus);\r | |
bdaf30e4 LE |
756 | }\r |
757 | \r | |
758 | return EFI_SUCCESS;\r | |
759 | }\r | |
760 | \r | |
da07afaf LE |
761 | /**\r |
762 | Notification callback for GOP interface installation.\r | |
763 | \r | |
764 | @param[in] Event Event whose notification function is being invoked.\r | |
765 | \r | |
766 | @param[in] Context The pointer to the notification function's context, which\r | |
767 | is implementation-dependent.\r | |
768 | **/\r | |
769 | STATIC\r | |
770 | VOID\r | |
771 | EFIAPI\r | |
772 | GopInstalled (\r | |
ac0a286f MK |
773 | IN EFI_EVENT Event,\r |
774 | IN VOID *Context\r | |
da07afaf LE |
775 | )\r |
776 | {\r | |
ac0a286f MK |
777 | EFI_STATUS Status;\r |
778 | EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;\r | |
da07afaf LE |
779 | \r |
780 | ASSERT (Event == mGopEvent);\r | |
781 | \r | |
782 | //\r | |
783 | // Check further GOPs.\r | |
784 | //\r | |
ac0a286f | 785 | for ( ; ;) {\r |
da07afaf | 786 | mNumGopModes = 0;\r |
ac0a286f | 787 | mGopModes = NULL;\r |
da07afaf | 788 | \r |
ac0a286f MK |
789 | Status = gBS->LocateProtocol (\r |
790 | &gEfiGraphicsOutputProtocolGuid,\r | |
791 | mGopTracker,\r | |
792 | (VOID **)&Gop\r | |
793 | );\r | |
da07afaf LE |
794 | if (EFI_ERROR (Status)) {\r |
795 | return;\r | |
796 | }\r | |
797 | \r | |
798 | Status = QueryGopModes (Gop, &mNumGopModes, &mGopModes);\r | |
799 | if (EFI_ERROR (Status)) {\r | |
800 | continue;\r | |
801 | }\r | |
802 | \r | |
ac0a286f MK |
803 | Status = PopulateForm (\r |
804 | mInstalledPackages,\r | |
805 | &gOvmfPlatformConfigGuid,\r | |
806 | FORMID_MAIN_FORM,\r | |
807 | mNumGopModes,\r | |
808 | mGopModes\r | |
809 | );\r | |
da07afaf LE |
810 | if (EFI_ERROR (Status)) {\r |
811 | FreePool (mGopModes);\r | |
812 | continue;\r | |
813 | }\r | |
814 | \r | |
815 | break;\r | |
816 | }\r | |
817 | \r | |
818 | //\r | |
819 | // Success -- so uninstall this callback. Closing the event removes all\r | |
820 | // pending notifications and all protocol registrations.\r | |
821 | //\r | |
822 | Status = gBS->CloseEvent (mGopEvent);\r | |
823 | ASSERT_EFI_ERROR (Status);\r | |
ac0a286f | 824 | mGopEvent = NULL;\r |
da07afaf LE |
825 | mGopTracker = NULL;\r |
826 | }\r | |
827 | \r | |
d945a8ba LE |
828 | /**\r |
829 | Entry point for this driver.\r | |
830 | \r | |
831 | @param[in] ImageHandle Image handle of this driver.\r | |
832 | @param[in] SystemTable Pointer to SystemTable.\r | |
833 | \r | |
834 | @retval EFI_SUCESS Driver has loaded successfully.\r | |
877a4dbb LE |
835 | @retval EFI_OUT_OF_RESOURCES Failed to install HII packages.\r |
836 | @return Error codes from lower level functions.\r | |
d945a8ba LE |
837 | \r |
838 | **/\r | |
839 | EFI_STATUS\r | |
840 | EFIAPI\r | |
841 | PlatformInit (\r | |
842 | IN EFI_HANDLE ImageHandle,\r | |
843 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
844 | )\r | |
845 | {\r | |
ac0a286f | 846 | EFI_STATUS Status;\r |
877a4dbb | 847 | \r |
bdaf30e4 | 848 | ExecutePlatformConfig ();\r |
877a4dbb LE |
849 | \r |
850 | mConfigAccess.ExtractConfig = &ExtractConfig;\r | |
851 | mConfigAccess.RouteConfig = &RouteConfig;\r | |
852 | mConfigAccess.Callback = &Callback;\r | |
853 | \r | |
854 | //\r | |
855 | // Declare ourselves suitable for HII communication.\r | |
856 | //\r | |
ac0a286f MK |
857 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
858 | &ImageHandle,\r | |
859 | &gEfiDevicePathProtocolGuid,\r | |
860 | &mPkgDevicePath,\r | |
861 | &gEfiHiiConfigAccessProtocolGuid,\r | |
862 | &mConfigAccess,\r | |
863 | NULL\r | |
864 | );\r | |
877a4dbb LE |
865 | if (EFI_ERROR (Status)) {\r |
866 | return Status;\r | |
867 | }\r | |
868 | \r | |
869 | //\r | |
870 | // Publish the HII package list to HII Database.\r | |
871 | //\r | |
872 | mInstalledPackages = HiiAddPackages (\r | |
873 | &gEfiCallerIdGuid, // PackageListGuid\r | |
874 | ImageHandle, // associated DeviceHandle\r | |
875 | PlatformDxeStrings, // 1st package\r | |
876 | PlatformFormsBin, // 2nd package\r | |
877 | NULL // terminator\r | |
878 | );\r | |
879 | if (mInstalledPackages == NULL) {\r | |
880 | Status = EFI_OUT_OF_RESOURCES;\r | |
881 | goto UninstallProtocols;\r | |
882 | }\r | |
883 | \r | |
ac0a286f MK |
884 | Status = gBS->CreateEvent (\r |
885 | EVT_NOTIFY_SIGNAL,\r | |
886 | TPL_CALLBACK,\r | |
887 | &GopInstalled,\r | |
888 | NULL /* Context */,\r | |
889 | &mGopEvent\r | |
890 | );\r | |
92e74550 LE |
891 | if (EFI_ERROR (Status)) {\r |
892 | goto RemovePackages;\r | |
893 | }\r | |
894 | \r | |
ac0a286f MK |
895 | Status = gBS->RegisterProtocolNotify (\r |
896 | &gEfiGraphicsOutputProtocolGuid,\r | |
897 | mGopEvent,\r | |
898 | &mGopTracker\r | |
899 | );\r | |
da07afaf LE |
900 | if (EFI_ERROR (Status)) {\r |
901 | goto CloseGopEvent;\r | |
902 | }\r | |
903 | \r | |
904 | //\r | |
905 | // Check already installed GOPs.\r | |
906 | //\r | |
907 | Status = gBS->SignalEvent (mGopEvent);\r | |
908 | ASSERT_EFI_ERROR (Status);\r | |
909 | \r | |
d945a8ba | 910 | return EFI_SUCCESS;\r |
877a4dbb | 911 | \r |
da07afaf LE |
912 | CloseGopEvent:\r |
913 | gBS->CloseEvent (mGopEvent);\r | |
914 | \r | |
92e74550 LE |
915 | RemovePackages:\r |
916 | HiiRemovePackages (mInstalledPackages);\r | |
917 | \r | |
877a4dbb | 918 | UninstallProtocols:\r |
ac0a286f MK |
919 | gBS->UninstallMultipleProtocolInterfaces (\r |
920 | ImageHandle,\r | |
921 | &gEfiDevicePathProtocolGuid,\r | |
922 | &mPkgDevicePath,\r | |
923 | &gEfiHiiConfigAccessProtocolGuid,\r | |
924 | &mConfigAccess,\r | |
925 | NULL\r | |
926 | );\r | |
877a4dbb | 927 | return Status;\r |
d945a8ba LE |
928 | }\r |
929 | \r | |
930 | /**\r | |
931 | Unload the driver.\r | |
932 | \r | |
933 | @param[in] ImageHandle Handle that identifies the image to evict.\r | |
934 | \r | |
935 | @retval EFI_SUCCESS The image has been unloaded.\r | |
936 | **/\r | |
937 | EFI_STATUS\r | |
938 | EFIAPI\r | |
939 | PlatformUnload (\r | |
940 | IN EFI_HANDLE ImageHandle\r | |
941 | )\r | |
942 | {\r | |
da07afaf LE |
943 | if (mGopEvent == NULL) {\r |
944 | //\r | |
945 | // The GOP callback ran successfully and unregistered itself. Release the\r | |
946 | // resources allocated there.\r | |
947 | //\r | |
948 | ASSERT (mGopModes != NULL);\r | |
949 | FreePool (mGopModes);\r | |
950 | } else {\r | |
951 | //\r | |
952 | // Otherwise we need to unregister the callback.\r | |
953 | //\r | |
954 | ASSERT (mGopModes == NULL);\r | |
955 | gBS->CloseEvent (mGopEvent);\r | |
956 | }\r | |
957 | \r | |
958 | //\r | |
959 | // Release resources allocated by the entry point.\r | |
960 | //\r | |
877a4dbb | 961 | HiiRemovePackages (mInstalledPackages);\r |
ac0a286f MK |
962 | gBS->UninstallMultipleProtocolInterfaces (\r |
963 | ImageHandle,\r | |
964 | &gEfiDevicePathProtocolGuid,\r | |
965 | &mPkgDevicePath,\r | |
966 | &gEfiHiiConfigAccessProtocolGuid,\r | |
967 | &mConfigAccess,\r | |
968 | NULL\r | |
969 | );\r | |
d945a8ba LE |
970 | return EFI_SUCCESS;\r |
971 | }\r |