]>
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 | 110 | \r |
aefcc918 DP |
111 | //\r |
112 | // The driver image handle, used to obtain the device path for <ConfigHdr>.\r | |
113 | //\r | |
114 | STATIC EFI_HANDLE mImageHandle;\r | |
115 | \r | |
da07afaf LE |
116 | //\r |
117 | // Cache the resolutions we get from the GOP.\r | |
118 | //\r | |
119 | typedef struct {\r | |
ac0a286f MK |
120 | UINT32 X;\r |
121 | UINT32 Y;\r | |
da07afaf LE |
122 | } GOP_MODE;\r |
123 | \r | |
ac0a286f MK |
124 | STATIC UINTN mNumGopModes;\r |
125 | STATIC GOP_MODE *mGopModes;\r | |
877a4dbb | 126 | \r |
cbd08bcc LE |
127 | /**\r |
128 | Load the persistent platform configuration and translate it to binary form\r | |
129 | state.\r | |
130 | \r | |
131 | If the platform configuration is missing, then the function fills in a\r | |
132 | default state.\r | |
133 | \r | |
134 | @param[out] MainFormState Binary form/widget state after translation.\r | |
135 | \r | |
136 | @retval EFI_SUCCESS Form/widget state ready.\r | |
137 | @return Error codes from underlying functions.\r | |
138 | **/\r | |
139 | STATIC\r | |
140 | EFI_STATUS\r | |
141 | EFIAPI\r | |
142 | PlatformConfigToFormState (\r | |
ac0a286f | 143 | OUT MAIN_FORM_STATE *MainFormState\r |
cbd08bcc LE |
144 | )\r |
145 | {\r | |
ac0a286f MK |
146 | EFI_STATUS Status;\r |
147 | PLATFORM_CONFIG PlatformConfig;\r | |
148 | UINT64 OptionalElements;\r | |
149 | UINTN ModeNumber;\r | |
cbd08bcc LE |
150 | \r |
151 | ZeroMem (MainFormState, sizeof *MainFormState);\r | |
152 | \r | |
153 | Status = PlatformConfigLoad (&PlatformConfig, &OptionalElements);\r | |
154 | switch (Status) {\r | |
ac0a286f MK |
155 | case EFI_SUCCESS:\r |
156 | if (OptionalElements & PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION) {\r | |
157 | //\r | |
158 | // Format the preferred resolution as text.\r | |
159 | //\r | |
160 | UnicodeSPrintAsciiFormat (\r | |
161 | (CHAR16 *)MainFormState->CurrentPreferredResolution,\r | |
162 | sizeof MainFormState->CurrentPreferredResolution,\r | |
163 | "%Ldx%Ld",\r | |
164 | (INT64)PlatformConfig.HorizontalResolution,\r | |
165 | (INT64)PlatformConfig.VerticalResolution\r | |
166 | );\r | |
167 | \r | |
168 | //\r | |
169 | // Try to locate it in the drop-down list too. This may not succeed, but\r | |
170 | // that's fine.\r | |
171 | //\r | |
172 | for (ModeNumber = 0; ModeNumber < mNumGopModes; ++ModeNumber) {\r | |
173 | if ((mGopModes[ModeNumber].X == PlatformConfig.HorizontalResolution) &&\r | |
174 | (mGopModes[ModeNumber].Y == PlatformConfig.VerticalResolution))\r | |
175 | {\r | |
176 | MainFormState->NextPreferredResolution = (UINT32)ModeNumber;\r | |
177 | break;\r | |
178 | }\r | |
cbd08bcc | 179 | }\r |
ac0a286f MK |
180 | \r |
181 | break;\r | |
cbd08bcc LE |
182 | }\r |
183 | \r | |
cbd08bcc LE |
184 | //\r |
185 | // fall through otherwise\r | |
186 | //\r | |
187 | \r | |
ac0a286f MK |
188 | case EFI_NOT_FOUND:\r |
189 | UnicodeSPrintAsciiFormat (\r | |
190 | (CHAR16 *)MainFormState->CurrentPreferredResolution,\r | |
191 | sizeof MainFormState->CurrentPreferredResolution,\r | |
192 | "Unset"\r | |
193 | );\r | |
194 | break;\r | |
cbd08bcc | 195 | \r |
ac0a286f MK |
196 | default:\r |
197 | return Status;\r | |
cbd08bcc LE |
198 | }\r |
199 | \r | |
200 | return EFI_SUCCESS;\r | |
201 | }\r | |
202 | \r | |
92e74550 LE |
203 | /**\r |
204 | This function is called by the HII machinery when it fetches the form state.\r | |
205 | \r | |
206 | See the precise documentation in the UEFI spec.\r | |
207 | \r | |
208 | @param[in] This The Config Access Protocol instance.\r | |
209 | \r | |
210 | @param[in] Request A <ConfigRequest> format UCS-2 string describing the\r | |
211 | query.\r | |
212 | \r | |
213 | @param[out] Progress A pointer into Request on output, identifying the query\r | |
214 | element where processing failed.\r | |
215 | \r | |
216 | @param[out] Results A <MultiConfigAltResp> format UCS-2 string that has\r | |
217 | all values filled in for the names in the Request\r | |
218 | string.\r | |
219 | \r | |
cbd08bcc LE |
220 | @retval EFI_SUCCESS Extraction of form state in <MultiConfigAltResp>\r |
221 | encoding successful.\r | |
222 | @return Status codes from underlying functions.\r | |
92e74550 LE |
223 | \r |
224 | **/\r | |
877a4dbb LE |
225 | STATIC\r |
226 | EFI_STATUS\r | |
227 | EFIAPI\r | |
228 | ExtractConfig (\r | |
229 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
230 | IN CONST EFI_STRING Request,\r | |
231 | OUT EFI_STRING *Progress,\r | |
232 | OUT EFI_STRING *Results\r | |
ac0a286f | 233 | )\r |
877a4dbb | 234 | {\r |
ac0a286f MK |
235 | MAIN_FORM_STATE MainFormState;\r |
236 | EFI_STATUS Status;\r | |
aefcc918 DP |
237 | EFI_STRING ConfigRequestHdr;\r |
238 | EFI_STRING ConfigRequest;\r | |
239 | UINTN Size;\r | |
240 | BOOLEAN AllocatedRequest;\r | |
92e74550 | 241 | \r |
70d5086c | 242 | DEBUG ((DEBUG_VERBOSE, "%a: Request=\"%s\"\n", __FUNCTION__, Request));\r |
92e74550 | 243 | \r |
30d62f5e DP |
244 | if ((Progress == NULL) || (Results == NULL)) {\r |
245 | return EFI_INVALID_PARAMETER;\r | |
246 | }\r | |
247 | \r | |
aefcc918 DP |
248 | ConfigRequestHdr = NULL;\r |
249 | ConfigRequest = NULL;\r | |
250 | Size = 0;\r | |
251 | AllocatedRequest = FALSE;\r | |
252 | \r | |
253 | //\r | |
254 | // Check if <ConfigHdr> matches the GUID and name\r | |
255 | //\r | |
256 | *Progress = Request;\r | |
257 | if ((Request != NULL) &&\r | |
258 | !HiiIsConfigHdrMatch (\r | |
259 | Request,\r | |
260 | &gOvmfPlatformConfigGuid,\r | |
16acacf2 | 261 | mHiiFormName\r |
aefcc918 DP |
262 | )\r |
263 | )\r | |
264 | {\r | |
265 | return EFI_NOT_FOUND;\r | |
266 | }\r | |
267 | \r | |
cbd08bcc LE |
268 | Status = PlatformConfigToFormState (&MainFormState);\r |
269 | if (EFI_ERROR (Status)) {\r | |
cbd08bcc LE |
270 | return Status;\r |
271 | }\r | |
272 | \r | |
aefcc918 DP |
273 | if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r |
274 | //\r | |
275 | // Request has no <RequestElement>, so construct full request string.\r | |
276 | // Allocate and fill a buffer large enough to hold <ConfigHdr>\r | |
277 | // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a\r | |
278 | // null terminator.\r | |
279 | //\r | |
280 | ConfigRequestHdr = HiiConstructConfigHdr (\r | |
281 | &gOvmfPlatformConfigGuid,\r | |
282 | mVariableName,\r | |
283 | mImageHandle\r | |
284 | );\r | |
285 | if (ConfigRequestHdr == NULL) {\r | |
286 | return EFI_OUT_OF_RESOURCES;\r | |
287 | }\r | |
288 | \r | |
289 | Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r | |
290 | ConfigRequest = AllocateZeroPool (Size);\r | |
291 | AllocatedRequest = TRUE;\r | |
292 | if (ConfigRequest == NULL) {\r | |
293 | FreePool (ConfigRequestHdr);\r | |
294 | return EFI_OUT_OF_RESOURCES;\r | |
295 | }\r | |
296 | \r | |
297 | UnicodeSPrint (\r | |
298 | ConfigRequest,\r | |
299 | Size,\r | |
300 | L"%s&OFFSET=0&WIDTH=%016LX",\r | |
301 | ConfigRequestHdr,\r | |
302 | sizeof MainFormState\r | |
303 | );\r | |
304 | FreePool (ConfigRequestHdr);\r | |
305 | } else {\r | |
306 | ConfigRequest = Request;\r | |
307 | }\r | |
308 | \r | |
cbd08bcc LE |
309 | //\r |
310 | // Answer the textual request keying off the binary form state.\r | |
311 | //\r | |
ac0a286f MK |
312 | Status = gHiiConfigRouting->BlockToConfig (\r |
313 | gHiiConfigRouting,\r | |
aefcc918 | 314 | ConfigRequest,\r |
ac0a286f MK |
315 | (VOID *)&MainFormState,\r |
316 | sizeof MainFormState,\r | |
317 | Results,\r | |
318 | Progress\r | |
319 | );\r | |
92e74550 | 320 | if (EFI_ERROR (Status)) {\r |
ac0a286f MK |
321 | DEBUG ((\r |
322 | DEBUG_ERROR,\r | |
323 | "%a: BlockToConfig(): %r, Progress=\"%s\"\n",\r | |
324 | __FUNCTION__,\r | |
325 | Status,\r | |
326 | (Status == EFI_DEVICE_ERROR) ? NULL : *Progress\r | |
327 | ));\r | |
92e74550 | 328 | } else {\r |
70d5086c | 329 | DEBUG ((DEBUG_VERBOSE, "%a: Results=\"%s\"\n", __FUNCTION__, *Results));\r |
92e74550 | 330 | }\r |
ac0a286f | 331 | \r |
aefcc918 DP |
332 | //\r |
333 | // If we used a newly allocated ConfigRequest, update Progress to point to\r | |
334 | // original Request instead of ConfigRequest.\r | |
335 | //\r | |
336 | if (Request == NULL) {\r | |
337 | *Progress = NULL;\r | |
338 | } else if (StrStr (Request, L"OFFSET") == NULL) {\r | |
339 | if (EFI_ERROR (Status)) {\r | |
340 | //\r | |
341 | // Since we constructed ConfigRequest, failure can only occur if there\r | |
342 | // is not enough memory. In this case, we point Progress to the first\r | |
343 | // character of Request.\r | |
344 | //\r | |
345 | *Progress = Request;\r | |
346 | } else {\r | |
347 | //\r | |
348 | // In case of success, we point Progress to the null terminator of\r | |
349 | // Request.\r | |
350 | //\r | |
351 | *Progress = Request + StrLen (Request);\r | |
352 | }\r | |
353 | }\r | |
354 | \r | |
355 | if (AllocatedRequest) {\r | |
356 | FreePool (ConfigRequest);\r | |
357 | }\r | |
358 | \r | |
92e74550 | 359 | return Status;\r |
877a4dbb LE |
360 | }\r |
361 | \r | |
ddb2c493 LE |
362 | /**\r |
363 | Interpret the binary form state and save it as persistent platform\r | |
364 | configuration.\r | |
365 | \r | |
366 | @param[in] MainFormState Binary form/widget state to verify and save.\r | |
367 | \r | |
368 | @retval EFI_SUCCESS Platform configuration saved.\r | |
369 | @return Error codes from underlying functions.\r | |
370 | **/\r | |
371 | STATIC\r | |
372 | EFI_STATUS\r | |
373 | EFIAPI\r | |
374 | FormStateToPlatformConfig (\r | |
ac0a286f | 375 | IN CONST MAIN_FORM_STATE *MainFormState\r |
ddb2c493 LE |
376 | )\r |
377 | {\r | |
ac0a286f MK |
378 | EFI_STATUS Status;\r |
379 | PLATFORM_CONFIG PlatformConfig;\r | |
380 | CONST GOP_MODE *GopMode;\r | |
ddb2c493 LE |
381 | \r |
382 | //\r | |
383 | // There's nothing to do with the textual CurrentPreferredResolution field.\r | |
384 | // We verify and translate the selection in the drop-down list.\r | |
385 | //\r | |
386 | if (MainFormState->NextPreferredResolution >= mNumGopModes) {\r | |
387 | return EFI_INVALID_PARAMETER;\r | |
388 | }\r | |
ac0a286f | 389 | \r |
ddb2c493 LE |
390 | GopMode = mGopModes + MainFormState->NextPreferredResolution;\r |
391 | \r | |
392 | ZeroMem (&PlatformConfig, sizeof PlatformConfig);\r | |
393 | PlatformConfig.HorizontalResolution = GopMode->X;\r | |
394 | PlatformConfig.VerticalResolution = GopMode->Y;\r | |
395 | \r | |
396 | Status = PlatformConfigSave (&PlatformConfig);\r | |
397 | return Status;\r | |
398 | }\r | |
399 | \r | |
ddb2c493 LE |
400 | /**\r |
401 | This function is called by the HII machinery when it wants the driver to\r | |
402 | interpret and persist the form state.\r | |
403 | \r | |
404 | See the precise documentation in the UEFI spec.\r | |
405 | \r | |
406 | @param[in] This The Config Access Protocol instance.\r | |
407 | \r | |
408 | @param[in] Configuration A <ConfigResp> format UCS-2 string describing the\r | |
409 | form state.\r | |
410 | \r | |
411 | @param[out] Progress A pointer into Configuration on output,\r | |
412 | identifying the element where processing failed.\r | |
413 | \r | |
414 | @retval EFI_SUCCESS Configuration verified, state permanent.\r | |
415 | \r | |
416 | @return Status codes from underlying functions.\r | |
417 | **/\r | |
877a4dbb LE |
418 | STATIC\r |
419 | EFI_STATUS\r | |
420 | EFIAPI\r | |
421 | RouteConfig (\r | |
422 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
423 | IN CONST EFI_STRING Configuration,\r | |
424 | OUT EFI_STRING *Progress\r | |
ac0a286f | 425 | )\r |
877a4dbb | 426 | {\r |
ac0a286f MK |
427 | MAIN_FORM_STATE MainFormState;\r |
428 | UINTN BlockSize;\r | |
429 | EFI_STATUS Status;\r | |
ddb2c493 | 430 | \r |
ac0a286f MK |
431 | DEBUG ((\r |
432 | DEBUG_VERBOSE,\r | |
433 | "%a: Configuration=\"%s\"\n",\r | |
434 | __FUNCTION__,\r | |
435 | Configuration\r | |
436 | ));\r | |
ddb2c493 | 437 | \r |
165b5bcd | 438 | if ((Progress == NULL) || (Configuration == NULL)) {\r |
30d62f5e DP |
439 | return EFI_INVALID_PARAMETER;\r |
440 | }\r | |
441 | \r | |
aefcc918 DP |
442 | //\r |
443 | // Check if <ConfigHdr> matches the GUID and name\r | |
444 | //\r | |
445 | *Progress = Configuration;\r | |
446 | if ((Configuration != NULL) &&\r | |
447 | !HiiIsConfigHdrMatch (\r | |
448 | Configuration,\r | |
449 | &gOvmfPlatformConfigGuid,\r | |
16acacf2 | 450 | mHiiFormName\r |
aefcc918 DP |
451 | )\r |
452 | )\r | |
453 | {\r | |
454 | return EFI_NOT_FOUND;\r | |
455 | }\r | |
456 | \r | |
ddb2c493 LE |
457 | //\r |
458 | // the "read" step in RMW\r | |
459 | //\r | |
460 | Status = PlatformConfigToFormState (&MainFormState);\r | |
461 | if (EFI_ERROR (Status)) {\r | |
462 | *Progress = Configuration;\r | |
463 | return Status;\r | |
464 | }\r | |
465 | \r | |
466 | //\r | |
467 | // the "modify" step in RMW\r | |
468 | //\r | |
469 | // (Update the binary form state. This update may be partial, which is why in\r | |
470 | // general we must pre-load the form state from the platform config.)\r | |
471 | //\r | |
472 | BlockSize = sizeof MainFormState;\r | |
ac0a286f MK |
473 | Status = gHiiConfigRouting->ConfigToBlock (\r |
474 | gHiiConfigRouting,\r | |
475 | Configuration,\r | |
476 | (VOID *)&MainFormState,\r | |
477 | &BlockSize,\r | |
478 | Progress\r | |
479 | );\r | |
ddb2c493 | 480 | if (EFI_ERROR (Status)) {\r |
ac0a286f MK |
481 | DEBUG ((\r |
482 | DEBUG_ERROR,\r | |
483 | "%a: ConfigToBlock(): %r, Progress=\"%s\"\n",\r | |
484 | __FUNCTION__,\r | |
485 | Status,\r | |
486 | (Status == EFI_BUFFER_TOO_SMALL) ? NULL : *Progress\r | |
487 | ));\r | |
ddb2c493 LE |
488 | return Status;\r |
489 | }\r | |
490 | \r | |
491 | //\r | |
492 | // the "write" step in RMW\r | |
493 | //\r | |
494 | Status = FormStateToPlatformConfig (&MainFormState);\r | |
495 | if (EFI_ERROR (Status)) {\r | |
496 | *Progress = Configuration;\r | |
497 | }\r | |
ac0a286f | 498 | \r |
ddb2c493 | 499 | return Status;\r |
877a4dbb LE |
500 | }\r |
501 | \r | |
877a4dbb LE |
502 | STATIC\r |
503 | EFI_STATUS\r | |
504 | EFIAPI\r | |
505 | Callback (\r | |
ac0a286f MK |
506 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r |
507 | IN EFI_BROWSER_ACTION Action,\r | |
508 | IN EFI_QUESTION_ID QuestionId,\r | |
509 | IN UINT8 Type,\r | |
510 | IN OUT EFI_IFR_TYPE_VALUE *Value,\r | |
511 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
877a4dbb LE |
512 | )\r |
513 | {\r | |
ac0a286f MK |
514 | DEBUG ((\r |
515 | DEBUG_VERBOSE,\r | |
516 | "%a: Action=0x%Lx QuestionId=%d Type=%d\n",\r | |
517 | __FUNCTION__,\r | |
518 | (UINT64)Action,\r | |
519 | QuestionId,\r | |
520 | Type\r | |
521 | ));\r | |
1df57ba3 LE |
522 | \r |
523 | if (Action != EFI_BROWSER_ACTION_CHANGED) {\r | |
524 | return EFI_UNSUPPORTED;\r | |
525 | }\r | |
526 | \r | |
527 | switch (QuestionId) {\r | |
ac0a286f MK |
528 | case QUESTION_SAVE_EXIT:\r |
529 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;\r | |
530 | break;\r | |
1df57ba3 | 531 | \r |
ac0a286f MK |
532 | case QUESTION_DISCARD_EXIT:\r |
533 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r | |
534 | break;\r | |
1df57ba3 | 535 | \r |
ac0a286f MK |
536 | default:\r |
537 | break;\r | |
1df57ba3 LE |
538 | }\r |
539 | \r | |
877a4dbb LE |
540 | return EFI_SUCCESS;\r |
541 | }\r | |
542 | \r | |
da07afaf LE |
543 | /**\r |
544 | Query and save all resolutions supported by the GOP.\r | |
545 | \r | |
546 | @param[in] Gop The Graphics Output Protocol instance to query.\r | |
547 | \r | |
548 | @param[out] NumGopModes The number of modes supported by the GOP. On output,\r | |
549 | this parameter will be positive.\r | |
550 | \r | |
551 | @param[out] GopModes On output, a dynamically allocated array containing\r | |
552 | the resolutions returned by the GOP. The caller is\r | |
553 | responsible for freeing the array after use.\r | |
554 | \r | |
555 | @retval EFI_UNSUPPORTED No modes found.\r | |
556 | @retval EFI_OUT_OF_RESOURCES Failed to allocate GopModes.\r | |
557 | @return Error codes from Gop->QueryMode().\r | |
558 | \r | |
559 | **/\r | |
560 | STATIC\r | |
561 | EFI_STATUS\r | |
562 | EFIAPI\r | |
563 | QueryGopModes (\r | |
ac0a286f MK |
564 | IN EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop,\r |
565 | OUT UINTN *NumGopModes,\r | |
566 | OUT GOP_MODE **GopModes\r | |
da07afaf LE |
567 | )\r |
568 | {\r | |
ac0a286f MK |
569 | EFI_STATUS Status;\r |
570 | UINT32 ModeNumber;\r | |
da07afaf LE |
571 | \r |
572 | if (Gop->Mode->MaxMode == 0) {\r | |
573 | return EFI_UNSUPPORTED;\r | |
574 | }\r | |
ac0a286f | 575 | \r |
da07afaf LE |
576 | *NumGopModes = Gop->Mode->MaxMode;\r |
577 | \r | |
578 | *GopModes = AllocatePool (Gop->Mode->MaxMode * sizeof **GopModes);\r | |
579 | if (*GopModes == NULL) {\r | |
580 | return EFI_OUT_OF_RESOURCES;\r | |
581 | }\r | |
582 | \r | |
583 | for (ModeNumber = 0; ModeNumber < Gop->Mode->MaxMode; ++ModeNumber) {\r | |
ac0a286f MK |
584 | EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r |
585 | UINTN SizeOfInfo;\r | |
da07afaf LE |
586 | \r |
587 | Status = Gop->QueryMode (Gop, ModeNumber, &SizeOfInfo, &Info);\r | |
588 | if (EFI_ERROR (Status)) {\r | |
589 | goto FreeGopModes;\r | |
590 | }\r | |
591 | \r | |
592 | (*GopModes)[ModeNumber].X = Info->HorizontalResolution;\r | |
593 | (*GopModes)[ModeNumber].Y = Info->VerticalResolution;\r | |
594 | FreePool (Info);\r | |
595 | }\r | |
596 | \r | |
597 | return EFI_SUCCESS;\r | |
598 | \r | |
599 | FreeGopModes:\r | |
600 | FreePool (*GopModes);\r | |
601 | \r | |
602 | return Status;\r | |
603 | }\r | |
604 | \r | |
92e74550 LE |
605 | /**\r |
606 | Create a set of "one-of-many" (ie. "drop down list") option IFR opcodes,\r | |
607 | based on available GOP resolutions, to be placed under a "one-of-many" (ie.\r | |
608 | "drop down list") opcode.\r | |
609 | \r | |
610 | @param[in] PackageList The package list with the formset and form for\r | |
611 | which the drop down options are produced. Option\r | |
612 | names are added as new strings to PackageList.\r | |
613 | \r | |
614 | @param[out] OpCodeBuffer On output, a dynamically allocated opcode buffer\r | |
615 | with drop down list options corresponding to GOP\r | |
616 | resolutions. The caller is responsible for freeing\r | |
617 | OpCodeBuffer with HiiFreeOpCodeHandle() after use.\r | |
618 | \r | |
da07afaf LE |
619 | @param[in] NumGopModes Number of entries in GopModes.\r |
620 | \r | |
621 | @param[in] GopModes Array of resolutions retrieved from the GOP.\r | |
622 | \r | |
92e74550 LE |
623 | @retval EFI_SUCESS Opcodes have been successfully produced.\r |
624 | \r | |
625 | @return Status codes from underlying functions. PackageList may\r | |
626 | have been extended with new strings. OpCodeBuffer is\r | |
627 | unchanged.\r | |
628 | **/\r | |
629 | STATIC\r | |
630 | EFI_STATUS\r | |
631 | EFIAPI\r | |
632 | CreateResolutionOptions (\r | |
35dd574a | 633 | IN EFI_HII_HANDLE PackageList,\r |
da07afaf LE |
634 | OUT VOID **OpCodeBuffer,\r |
635 | IN UINTN NumGopModes,\r | |
636 | IN GOP_MODE *GopModes\r | |
92e74550 LE |
637 | )\r |
638 | {\r | |
ac0a286f MK |
639 | EFI_STATUS Status;\r |
640 | VOID *OutputBuffer;\r | |
641 | UINTN ModeNumber;\r | |
92e74550 LE |
642 | \r |
643 | OutputBuffer = HiiAllocateOpCodeHandle ();\r | |
644 | if (OutputBuffer == NULL) {\r | |
645 | return EFI_OUT_OF_RESOURCES;\r | |
646 | }\r | |
647 | \r | |
da07afaf | 648 | for (ModeNumber = 0; ModeNumber < NumGopModes; ++ModeNumber) {\r |
ac0a286f MK |
649 | CHAR16 Desc[MAXSIZE_RES_CUR];\r |
650 | EFI_STRING_ID NewString;\r | |
651 | VOID *OpCode;\r | |
652 | \r | |
653 | UnicodeSPrintAsciiFormat (\r | |
654 | Desc,\r | |
655 | sizeof Desc,\r | |
656 | "%Ldx%Ld",\r | |
657 | (INT64)GopModes[ModeNumber].X,\r | |
658 | (INT64)GopModes[ModeNumber].Y\r | |
659 | );\r | |
660 | NewString = HiiSetString (\r | |
661 | PackageList,\r | |
662 | 0 /* new string */,\r | |
663 | Desc,\r | |
664 | NULL /* for all languages */\r | |
665 | );\r | |
da07afaf LE |
666 | if (NewString == 0) {\r |
667 | Status = EFI_OUT_OF_RESOURCES;\r | |
668 | goto FreeOutputBuffer;\r | |
669 | }\r | |
ac0a286f MK |
670 | \r |
671 | OpCode = HiiCreateOneOfOptionOpCode (\r | |
672 | OutputBuffer,\r | |
673 | NewString,\r | |
674 | 0 /* Flags */,\r | |
675 | EFI_IFR_NUMERIC_SIZE_4,\r | |
676 | ModeNumber\r | |
677 | );\r | |
da07afaf LE |
678 | if (OpCode == NULL) {\r |
679 | Status = EFI_OUT_OF_RESOURCES;\r | |
680 | goto FreeOutputBuffer;\r | |
681 | }\r | |
92e74550 LE |
682 | }\r |
683 | \r | |
684 | *OpCodeBuffer = OutputBuffer;\r | |
685 | return EFI_SUCCESS;\r | |
686 | \r | |
687 | FreeOutputBuffer:\r | |
688 | HiiFreeOpCodeHandle (OutputBuffer);\r | |
689 | \r | |
690 | return Status;\r | |
691 | }\r | |
692 | \r | |
92e74550 LE |
693 | /**\r |
694 | Populate the form identified by the (PackageList, FormSetGuid, FormId)\r | |
695 | triplet.\r | |
696 | \r | |
da07afaf LE |
697 | The drop down list of video resolutions is generated from (NumGopModes,\r |
698 | GopModes).\r | |
699 | \r | |
92e74550 LE |
700 | @retval EFI_SUCESS Form successfully updated.\r |
701 | @return Status codes from underlying functions.\r | |
702 | \r | |
703 | **/\r | |
704 | STATIC\r | |
705 | EFI_STATUS\r | |
706 | EFIAPI\r | |
707 | PopulateForm (\r | |
35dd574a | 708 | IN EFI_HII_HANDLE PackageList,\r |
92e74550 | 709 | IN EFI_GUID *FormSetGuid,\r |
da07afaf LE |
710 | IN EFI_FORM_ID FormId,\r |
711 | IN UINTN NumGopModes,\r | |
712 | IN GOP_MODE *GopModes\r | |
92e74550 LE |
713 | )\r |
714 | {\r | |
ac0a286f MK |
715 | EFI_STATUS Status;\r |
716 | VOID *OpCodeBuffer;\r | |
717 | VOID *OpCode;\r | |
718 | EFI_IFR_GUID_LABEL *Anchor;\r | |
719 | VOID *OpCodeBuffer2;\r | |
92e74550 | 720 | \r |
bc4c5366 JJ |
721 | OpCodeBuffer2 = NULL;\r |
722 | \r | |
92e74550 LE |
723 | //\r |
724 | // 1. Allocate an empty opcode buffer.\r | |
725 | //\r | |
726 | OpCodeBuffer = HiiAllocateOpCodeHandle ();\r | |
727 | if (OpCodeBuffer == NULL) {\r | |
728 | return EFI_OUT_OF_RESOURCES;\r | |
729 | }\r | |
730 | \r | |
731 | //\r | |
732 | // 2. Create a label opcode (which is a Tiano extension) inside the buffer.\r | |
733 | // The label's number must match the "anchor" label in the form.\r | |
734 | //\r | |
ac0a286f MK |
735 | OpCode = HiiCreateGuidOpCode (\r |
736 | OpCodeBuffer,\r | |
737 | &gEfiIfrTianoGuid,\r | |
738 | NULL /* optional copy origin */,\r | |
739 | sizeof *Anchor\r | |
740 | );\r | |
92e74550 LE |
741 | if (OpCode == NULL) {\r |
742 | Status = EFI_OUT_OF_RESOURCES;\r | |
743 | goto FreeOpCodeBuffer;\r | |
744 | }\r | |
ac0a286f | 745 | \r |
92e74550 LE |
746 | Anchor = OpCode;\r |
747 | Anchor->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
748 | Anchor->Number = LABEL_RES_NEXT;\r | |
749 | \r | |
750 | //\r | |
751 | // 3. Create the opcodes inside the buffer that are to be inserted into the\r | |
752 | // form.\r | |
753 | //\r | |
754 | // 3.1. Get a list of resolutions.\r | |
755 | //\r | |
ac0a286f MK |
756 | Status = CreateResolutionOptions (\r |
757 | PackageList,\r | |
758 | &OpCodeBuffer2,\r | |
759 | NumGopModes,\r | |
760 | GopModes\r | |
761 | );\r | |
92e74550 LE |
762 | if (EFI_ERROR (Status)) {\r |
763 | goto FreeOpCodeBuffer;\r | |
764 | }\r | |
765 | \r | |
766 | //\r | |
767 | // 3.2. Create a one-of-many question with the above options.\r | |
768 | //\r | |
769 | OpCode = HiiCreateOneOfOpCode (\r | |
770 | OpCodeBuffer, // create opcode inside this\r | |
771 | // opcode buffer,\r | |
772 | QUESTION_RES_NEXT, // ID of question,\r | |
773 | FORMSTATEID_MAIN_FORM, // identifies form state\r | |
774 | // storage,\r | |
ac0a286f MK |
775 | (UINT16)OFFSET_OF (\r |
776 | MAIN_FORM_STATE, // value of question stored\r | |
777 | NextPreferredResolution\r | |
778 | ), // at this offset,\r | |
92e74550 LE |
779 | STRING_TOKEN (STR_RES_NEXT), // Prompt,\r |
780 | STRING_TOKEN (STR_RES_NEXT_HELP), // Help,\r | |
781 | 0, // QuestionFlags,\r | |
782 | EFI_IFR_NUMERIC_SIZE_4, // see sizeof\r | |
783 | // NextPreferredResolution,\r | |
784 | OpCodeBuffer2, // buffer with possible\r | |
785 | // choices,\r | |
786 | NULL // DEFAULT opcodes\r | |
787 | );\r | |
788 | if (OpCode == NULL) {\r | |
789 | Status = EFI_OUT_OF_RESOURCES;\r | |
790 | goto FreeOpCodeBuffer2;\r | |
791 | }\r | |
792 | \r | |
793 | //\r | |
794 | // 4. Update the form with the opcode buffer.\r | |
795 | //\r | |
ac0a286f MK |
796 | Status = HiiUpdateForm (\r |
797 | PackageList,\r | |
798 | FormSetGuid,\r | |
799 | FormId,\r | |
92e74550 LE |
800 | OpCodeBuffer, // buffer with head anchor, and new contents to be\r |
801 | // inserted at it\r | |
802 | NULL // buffer with tail anchor, for deleting old\r | |
803 | // contents up to it\r | |
804 | );\r | |
805 | \r | |
806 | FreeOpCodeBuffer2:\r | |
807 | HiiFreeOpCodeHandle (OpCodeBuffer2);\r | |
808 | \r | |
809 | FreeOpCodeBuffer:\r | |
810 | HiiFreeOpCodeHandle (OpCodeBuffer);\r | |
811 | \r | |
812 | return Status;\r | |
813 | }\r | |
814 | \r | |
bdaf30e4 LE |
815 | /**\r |
816 | Load and execute the platform configuration.\r | |
817 | \r | |
818 | @retval EFI_SUCCESS Configuration loaded and executed.\r | |
819 | @return Status codes from PlatformConfigLoad().\r | |
820 | **/\r | |
821 | STATIC\r | |
822 | EFI_STATUS\r | |
823 | EFIAPI\r | |
824 | ExecutePlatformConfig (\r | |
825 | VOID\r | |
826 | )\r | |
827 | {\r | |
ac0a286f MK |
828 | EFI_STATUS Status;\r |
829 | PLATFORM_CONFIG PlatformConfig;\r | |
830 | UINT64 OptionalElements;\r | |
831 | RETURN_STATUS PcdStatus;\r | |
bdaf30e4 LE |
832 | \r |
833 | Status = PlatformConfigLoad (&PlatformConfig, &OptionalElements);\r | |
834 | if (EFI_ERROR (Status)) {\r | |
ac0a286f MK |
835 | DEBUG ((\r |
836 | (Status == EFI_NOT_FOUND) ? DEBUG_VERBOSE : DEBUG_ERROR,\r | |
837 | "%a: failed to load platform config: %r\n",\r | |
838 | __FUNCTION__,\r | |
839 | Status\r | |
840 | ));\r | |
bdaf30e4 LE |
841 | return Status;\r |
842 | }\r | |
843 | \r | |
844 | if (OptionalElements & PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION) {\r | |
845 | //\r | |
846 | // Pass the preferred resolution to GraphicsConsoleDxe via dynamic PCDs.\r | |
847 | //\r | |
ac0a286f MK |
848 | PcdStatus = PcdSet32S (\r |
849 | PcdVideoHorizontalResolution,\r | |
850 | PlatformConfig.HorizontalResolution\r | |
851 | );\r | |
4d1362e1 LE |
852 | ASSERT_RETURN_ERROR (PcdStatus);\r |
853 | \r | |
ac0a286f MK |
854 | PcdStatus = PcdSet32S (\r |
855 | PcdVideoVerticalResolution,\r | |
856 | PlatformConfig.VerticalResolution\r | |
857 | );\r | |
4d1362e1 | 858 | ASSERT_RETURN_ERROR (PcdStatus);\r |
929804b1 GH |
859 | \r |
860 | PcdStatus = PcdSet8S (PcdVideoResolutionSource, 1);\r | |
861 | ASSERT_RETURN_ERROR (PcdStatus);\r | |
bdaf30e4 LE |
862 | }\r |
863 | \r | |
864 | return EFI_SUCCESS;\r | |
865 | }\r | |
866 | \r | |
da07afaf LE |
867 | /**\r |
868 | Notification callback for GOP interface installation.\r | |
869 | \r | |
870 | @param[in] Event Event whose notification function is being invoked.\r | |
871 | \r | |
872 | @param[in] Context The pointer to the notification function's context, which\r | |
873 | is implementation-dependent.\r | |
874 | **/\r | |
875 | STATIC\r | |
876 | VOID\r | |
877 | EFIAPI\r | |
878 | GopInstalled (\r | |
ac0a286f MK |
879 | IN EFI_EVENT Event,\r |
880 | IN VOID *Context\r | |
da07afaf LE |
881 | )\r |
882 | {\r | |
ac0a286f MK |
883 | EFI_STATUS Status;\r |
884 | EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;\r | |
da07afaf LE |
885 | \r |
886 | ASSERT (Event == mGopEvent);\r | |
887 | \r | |
888 | //\r | |
889 | // Check further GOPs.\r | |
890 | //\r | |
ac0a286f | 891 | for ( ; ;) {\r |
da07afaf | 892 | mNumGopModes = 0;\r |
ac0a286f | 893 | mGopModes = NULL;\r |
da07afaf | 894 | \r |
ac0a286f MK |
895 | Status = gBS->LocateProtocol (\r |
896 | &gEfiGraphicsOutputProtocolGuid,\r | |
897 | mGopTracker,\r | |
898 | (VOID **)&Gop\r | |
899 | );\r | |
da07afaf LE |
900 | if (EFI_ERROR (Status)) {\r |
901 | return;\r | |
902 | }\r | |
903 | \r | |
904 | Status = QueryGopModes (Gop, &mNumGopModes, &mGopModes);\r | |
905 | if (EFI_ERROR (Status)) {\r | |
906 | continue;\r | |
907 | }\r | |
908 | \r | |
ac0a286f MK |
909 | Status = PopulateForm (\r |
910 | mInstalledPackages,\r | |
911 | &gOvmfPlatformConfigGuid,\r | |
912 | FORMID_MAIN_FORM,\r | |
913 | mNumGopModes,\r | |
914 | mGopModes\r | |
915 | );\r | |
da07afaf LE |
916 | if (EFI_ERROR (Status)) {\r |
917 | FreePool (mGopModes);\r | |
918 | continue;\r | |
919 | }\r | |
920 | \r | |
921 | break;\r | |
922 | }\r | |
923 | \r | |
924 | //\r | |
925 | // Success -- so uninstall this callback. Closing the event removes all\r | |
926 | // pending notifications and all protocol registrations.\r | |
927 | //\r | |
928 | Status = gBS->CloseEvent (mGopEvent);\r | |
929 | ASSERT_EFI_ERROR (Status);\r | |
ac0a286f | 930 | mGopEvent = NULL;\r |
da07afaf LE |
931 | mGopTracker = NULL;\r |
932 | }\r | |
933 | \r | |
d945a8ba LE |
934 | /**\r |
935 | Entry point for this driver.\r | |
936 | \r | |
937 | @param[in] ImageHandle Image handle of this driver.\r | |
938 | @param[in] SystemTable Pointer to SystemTable.\r | |
939 | \r | |
940 | @retval EFI_SUCESS Driver has loaded successfully.\r | |
877a4dbb LE |
941 | @retval EFI_OUT_OF_RESOURCES Failed to install HII packages.\r |
942 | @return Error codes from lower level functions.\r | |
d945a8ba LE |
943 | \r |
944 | **/\r | |
945 | EFI_STATUS\r | |
946 | EFIAPI\r | |
947 | PlatformInit (\r | |
948 | IN EFI_HANDLE ImageHandle,\r | |
949 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
950 | )\r | |
951 | {\r | |
ac0a286f | 952 | EFI_STATUS Status;\r |
877a4dbb | 953 | \r |
bdaf30e4 | 954 | ExecutePlatformConfig ();\r |
877a4dbb LE |
955 | \r |
956 | mConfigAccess.ExtractConfig = &ExtractConfig;\r | |
957 | mConfigAccess.RouteConfig = &RouteConfig;\r | |
958 | mConfigAccess.Callback = &Callback;\r | |
959 | \r | |
960 | //\r | |
961 | // Declare ourselves suitable for HII communication.\r | |
962 | //\r | |
ac0a286f MK |
963 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
964 | &ImageHandle,\r | |
965 | &gEfiDevicePathProtocolGuid,\r | |
966 | &mPkgDevicePath,\r | |
967 | &gEfiHiiConfigAccessProtocolGuid,\r | |
968 | &mConfigAccess,\r | |
969 | NULL\r | |
970 | );\r | |
877a4dbb LE |
971 | if (EFI_ERROR (Status)) {\r |
972 | return Status;\r | |
973 | }\r | |
974 | \r | |
aefcc918 DP |
975 | //\r |
976 | // Save the driver image handle.\r | |
977 | //\r | |
978 | mImageHandle = ImageHandle;\r | |
979 | \r | |
877a4dbb LE |
980 | //\r |
981 | // Publish the HII package list to HII Database.\r | |
982 | //\r | |
983 | mInstalledPackages = HiiAddPackages (\r | |
984 | &gEfiCallerIdGuid, // PackageListGuid\r | |
985 | ImageHandle, // associated DeviceHandle\r | |
986 | PlatformDxeStrings, // 1st package\r | |
987 | PlatformFormsBin, // 2nd package\r | |
988 | NULL // terminator\r | |
989 | );\r | |
990 | if (mInstalledPackages == NULL) {\r | |
991 | Status = EFI_OUT_OF_RESOURCES;\r | |
992 | goto UninstallProtocols;\r | |
993 | }\r | |
994 | \r | |
ac0a286f MK |
995 | Status = gBS->CreateEvent (\r |
996 | EVT_NOTIFY_SIGNAL,\r | |
997 | TPL_CALLBACK,\r | |
998 | &GopInstalled,\r | |
999 | NULL /* Context */,\r | |
1000 | &mGopEvent\r | |
1001 | );\r | |
92e74550 LE |
1002 | if (EFI_ERROR (Status)) {\r |
1003 | goto RemovePackages;\r | |
1004 | }\r | |
1005 | \r | |
ac0a286f MK |
1006 | Status = gBS->RegisterProtocolNotify (\r |
1007 | &gEfiGraphicsOutputProtocolGuid,\r | |
1008 | mGopEvent,\r | |
1009 | &mGopTracker\r | |
1010 | );\r | |
da07afaf LE |
1011 | if (EFI_ERROR (Status)) {\r |
1012 | goto CloseGopEvent;\r | |
1013 | }\r | |
1014 | \r | |
1015 | //\r | |
1016 | // Check already installed GOPs.\r | |
1017 | //\r | |
1018 | Status = gBS->SignalEvent (mGopEvent);\r | |
1019 | ASSERT_EFI_ERROR (Status);\r | |
1020 | \r | |
d945a8ba | 1021 | return EFI_SUCCESS;\r |
877a4dbb | 1022 | \r |
da07afaf LE |
1023 | CloseGopEvent:\r |
1024 | gBS->CloseEvent (mGopEvent);\r | |
1025 | \r | |
92e74550 LE |
1026 | RemovePackages:\r |
1027 | HiiRemovePackages (mInstalledPackages);\r | |
1028 | \r | |
877a4dbb | 1029 | UninstallProtocols:\r |
ac0a286f MK |
1030 | gBS->UninstallMultipleProtocolInterfaces (\r |
1031 | ImageHandle,\r | |
1032 | &gEfiDevicePathProtocolGuid,\r | |
1033 | &mPkgDevicePath,\r | |
1034 | &gEfiHiiConfigAccessProtocolGuid,\r | |
1035 | &mConfigAccess,\r | |
1036 | NULL\r | |
1037 | );\r | |
877a4dbb | 1038 | return Status;\r |
d945a8ba LE |
1039 | }\r |
1040 | \r | |
1041 | /**\r | |
1042 | Unload the driver.\r | |
1043 | \r | |
1044 | @param[in] ImageHandle Handle that identifies the image to evict.\r | |
1045 | \r | |
1046 | @retval EFI_SUCCESS The image has been unloaded.\r | |
1047 | **/\r | |
1048 | EFI_STATUS\r | |
1049 | EFIAPI\r | |
1050 | PlatformUnload (\r | |
1051 | IN EFI_HANDLE ImageHandle\r | |
1052 | )\r | |
1053 | {\r | |
da07afaf LE |
1054 | if (mGopEvent == NULL) {\r |
1055 | //\r | |
1056 | // The GOP callback ran successfully and unregistered itself. Release the\r | |
1057 | // resources allocated there.\r | |
1058 | //\r | |
1059 | ASSERT (mGopModes != NULL);\r | |
1060 | FreePool (mGopModes);\r | |
1061 | } else {\r | |
1062 | //\r | |
1063 | // Otherwise we need to unregister the callback.\r | |
1064 | //\r | |
1065 | ASSERT (mGopModes == NULL);\r | |
1066 | gBS->CloseEvent (mGopEvent);\r | |
1067 | }\r | |
1068 | \r | |
1069 | //\r | |
1070 | // Release resources allocated by the entry point.\r | |
1071 | //\r | |
877a4dbb | 1072 | HiiRemovePackages (mInstalledPackages);\r |
ac0a286f MK |
1073 | gBS->UninstallMultipleProtocolInterfaces (\r |
1074 | ImageHandle,\r | |
1075 | &gEfiDevicePathProtocolGuid,\r | |
1076 | &mPkgDevicePath,\r | |
1077 | &gEfiHiiConfigAccessProtocolGuid,\r | |
1078 | &mConfigAccess,\r | |
1079 | NULL\r | |
1080 | );\r | |
d945a8ba LE |
1081 | return EFI_SUCCESS;\r |
1082 | }\r |