]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / BmHotkey.c
CommitLineData
067ed98a
RN
1/** @file\r
2 Hotkey library functions.\r
3\r
d1102dba 4Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
065e587c 5(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
9d510e61 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
067ed98a
RN
7\r
8**/\r
9\r
10#include "InternalBm.h"\r
11\r
12//\r
13// Lock for linked list\r
14//\r
15EFI_LOCK mBmHotkeyLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);\r
16LIST_ENTRY mBmHotkeyList = INITIALIZE_LIST_HEAD_VARIABLE (mBmHotkeyList);\r
17EFI_EVENT mBmHotkeyTriggered = NULL;\r
18BOOLEAN mBmHotkeyServiceStarted = FALSE;\r
19UINTN mBmHotkeySupportCount = 0;\r
20\r
21//\r
22// Set OptionNumber as unassigned value to indicate the option isn't initialized\r
23//\r
24EFI_BOOT_MANAGER_LOAD_OPTION mBmHotkeyBootOption = { LoadOptionNumberUnassigned };\r
25\r
26EFI_BOOT_MANAGER_KEY_OPTION *mBmContinueKeyOption = NULL;\r
27VOID *mBmTxtInExRegistration = NULL;\r
28\r
121300c4
RN
29\r
30/**\r
31 Return the buffer size of the EFI_BOOT_MANAGER_KEY_OPTION data.\r
32\r
33 @param KeyOption The input key option info.\r
34\r
35 @retval The buffer size of the key option data.\r
36**/\r
37UINTN\r
38BmSizeOfKeyOption (\r
7320b8ed 39 IN CONST EFI_BOOT_MANAGER_KEY_OPTION *KeyOption\r
121300c4
RN
40 )\r
41{\r
42 return OFFSET_OF (EFI_BOOT_MANAGER_KEY_OPTION, Keys)\r
43 + KeyOption->KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY);\r
44}\r
45\r
067ed98a
RN
46/**\r
47\r
48 Check whether the input key option is valid.\r
49\r
121300c4
RN
50 @param KeyOption Key option.\r
51 @param KeyOptionSize Size of the key option.\r
067ed98a
RN
52\r
53 @retval TRUE Input key option is valid.\r
54 @retval FALSE Input key option is not valid.\r
55**/\r
56BOOLEAN\r
57BmIsKeyOptionValid (\r
7320b8ed
RN
58 IN CONST EFI_BOOT_MANAGER_KEY_OPTION *KeyOption,\r
59 IN UINTN KeyOptionSize\r
067ed98a
RN
60)\r
61{\r
f9a24380 62 UINT16 OptionName[BM_OPTION_NAME_LEN];\r
067ed98a
RN
63 UINT8 *BootOption;\r
64 UINTN BootOptionSize;\r
65 UINT32 Crc;\r
66\r
121300c4
RN
67 if (BmSizeOfKeyOption (KeyOption) != KeyOptionSize) {\r
68 return FALSE;\r
69 }\r
70\r
067ed98a
RN
71 //\r
72 // Check whether corresponding Boot Option exist\r
73 //\r
121300c4
RN
74 UnicodeSPrint (\r
75 OptionName, sizeof (OptionName), L"%s%04x",\r
76 mBmLoadOptionName[LoadOptionTypeBoot], KeyOption->BootOption\r
77 );\r
067ed98a
RN
78 GetEfiGlobalVariable2 (OptionName, (VOID **) &BootOption, &BootOptionSize);\r
79\r
80 if (BootOption == NULL) {\r
81 return FALSE;\r
82 }\r
83\r
84 //\r
85 // Check CRC for Boot Option\r
86 //\r
87 gBS->CalculateCrc32 (BootOption, BootOptionSize, &Crc);\r
88 FreePool (BootOption);\r
89\r
90 return (BOOLEAN) (KeyOption->BootOptionCrc == Crc);\r
91}\r
92\r
93/**\r
94\r
95 Check whether the input variable is an key option variable.\r
96\r
97 @param Name Input variable name.\r
98 @param Guid Input variable guid.\r
99 @param OptionNumber The option number of this key option variable.\r
100\r
101 @retval TRUE Input variable is a key option variable.\r
102 @retval FALSE Input variable is not a key option variable.\r
103**/\r
104BOOLEAN\r
105BmIsKeyOptionVariable (\r
106 CHAR16 *Name,\r
107 EFI_GUID *Guid,\r
108 UINT16 *OptionNumber\r
109 )\r
110{\r
111 UINTN Index;\r
418e8cd9 112 UINTN Uint;\r
d1102dba 113\r
067ed98a
RN
114 if (!CompareGuid (Guid, &gEfiGlobalVariableGuid) ||\r
115 (StrSize (Name) != sizeof (L"Key####")) ||\r
116 (StrnCmp (Name, L"Key", 3) != 0)\r
117 ) {\r
118 return FALSE;\r
119 }\r
120\r
121 *OptionNumber = 0;\r
122 for (Index = 3; Index < 7; Index++) {\r
418e8cd9
RN
123 Uint = BmCharToUint (Name[Index]);\r
124 if (Uint == -1) {\r
067ed98a 125 return FALSE;\r
418e8cd9
RN
126 } else {\r
127 *OptionNumber = (UINT16) Uint + *OptionNumber * 0x10;\r
067ed98a
RN
128 }\r
129 }\r
130\r
131 return TRUE;\r
132}\r
133\r
121300c4
RN
134typedef struct {\r
135 EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions;\r
136 UINTN KeyOptionCount;\r
137} BM_COLLECT_KEY_OPTIONS_PARAM;\r
067ed98a 138\r
121300c4
RN
139/**\r
140 Visitor function to collect the key options from NV storage.\r
067ed98a 141\r
121300c4
RN
142 @param Name Variable name.\r
143 @param Guid Variable GUID.\r
144 @param Context The same context passed to BmForEachVariable.\r
067ed98a 145**/\r
121300c4
RN
146VOID\r
147BmCollectKeyOptions (\r
148 CHAR16 *Name,\r
149 EFI_GUID *Guid,\r
150 VOID *Context\r
067ed98a
RN
151 )\r
152{\r
121300c4
RN
153 UINTN Index;\r
154 BM_COLLECT_KEY_OPTIONS_PARAM *Param;\r
7320b8ed 155 VOID *KeyOption;\r
121300c4
RN
156 UINT16 OptionNumber;\r
157 UINTN KeyOptionSize;\r
158\r
159 Param = (BM_COLLECT_KEY_OPTIONS_PARAM *) Context;\r
160\r
161 if (BmIsKeyOptionVariable (Name, Guid, &OptionNumber)) {\r
7320b8ed 162 GetEfiGlobalVariable2 (Name, &KeyOption, &KeyOptionSize);\r
121300c4 163 ASSERT (KeyOption != NULL);\r
121300c4
RN
164 if (BmIsKeyOptionValid (KeyOption, KeyOptionSize)) {\r
165 Param->KeyOptions = ReallocatePool (\r
166 Param->KeyOptionCount * sizeof (EFI_BOOT_MANAGER_KEY_OPTION),\r
167 (Param->KeyOptionCount + 1) * sizeof (EFI_BOOT_MANAGER_KEY_OPTION),\r
168 Param->KeyOptions\r
169 );\r
170 ASSERT (Param->KeyOptions != NULL);\r
171 //\r
172 // Insert the key option in order\r
173 //\r
174 for (Index = 0; Index < Param->KeyOptionCount; Index++) {\r
7320b8ed 175 if (OptionNumber < Param->KeyOptions[Index].OptionNumber) {\r
121300c4
RN
176 break;\r
177 }\r
178 }\r
179 CopyMem (&Param->KeyOptions[Index + 1], &Param->KeyOptions[Index], (Param->KeyOptionCount - Index) * sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r
7320b8ed
RN
180 CopyMem (&Param->KeyOptions[Index], KeyOption, KeyOptionSize);\r
181 Param->KeyOptions[Index].OptionNumber = OptionNumber;\r
121300c4
RN
182 Param->KeyOptionCount++;\r
183 }\r
184 FreePool (KeyOption);\r
185 }\r
067ed98a
RN
186}\r
187\r
188/**\r
189 Return the array of key options.\r
190\r
191 @param Count Return the number of key options.\r
192\r
193 @retval NULL No key option.\r
194 @retval Other Pointer to the key options.\r
195**/\r
196EFI_BOOT_MANAGER_KEY_OPTION *\r
197BmGetKeyOptions (\r
198 OUT UINTN *Count\r
199 )\r
200{\r
121300c4 201 BM_COLLECT_KEY_OPTIONS_PARAM Param;\r
067ed98a
RN
202\r
203 if (Count == NULL) {\r
204 return NULL;\r
205 }\r
206\r
121300c4
RN
207 Param.KeyOptions = NULL;\r
208 Param.KeyOptionCount = 0;\r
067ed98a 209\r
121300c4 210 BmForEachVariable (BmCollectKeyOptions, (VOID *) &Param);\r
067ed98a 211\r
121300c4 212 *Count = Param.KeyOptionCount;\r
067ed98a 213\r
121300c4 214 return Param.KeyOptions;\r
067ed98a
RN
215}\r
216\r
067ed98a
RN
217/**\r
218 Check whether the bit is set in the value.\r
219\r
220 @param Value The value need to be check.\r
221 @param Bit The bit filed need to be check.\r
222\r
223 @retval TRUE The bit is set.\r
224 @retval FALSE The bit is not set.\r
225**/\r
226BOOLEAN\r
227BmBitSet (\r
228 IN UINT32 Value,\r
229 IN UINT32 Bit\r
230 )\r
231{\r
232 return (BOOLEAN) ((Value & Bit) != 0);\r
233}\r
234\r
235/**\r
236 Initialize the KeyData and Key[] in the EFI_BOOT_MANAGER_KEY_OPTION.\r
237\r
238 @param Modifier Input key info.\r
239 @param Args Va_list info.\r
240 @param KeyOption Key info which need to update.\r
241\r
242 @retval EFI_SUCCESS Succeed to initialize the KeyData and Key[].\r
243 @return EFI_INVALID_PARAMETER Input parameter error.\r
244**/\r
245EFI_STATUS\r
246BmInitializeKeyFields (\r
247 IN UINT32 Modifier,\r
248 IN VA_LIST Args,\r
249 OUT EFI_BOOT_MANAGER_KEY_OPTION *KeyOption\r
250 )\r
251{\r
252 EFI_INPUT_KEY *Key;\r
253\r
254 if (KeyOption == NULL) {\r
255 return EFI_INVALID_PARAMETER;\r
256 }\r
257\r
258 Key = NULL;\r
259 while (KeyOption->KeyData.Options.InputKeyCount < sizeof (KeyOption->Keys) / sizeof (KeyOption->Keys[0])) {\r
260 Key = VA_ARG (Args, EFI_INPUT_KEY *);\r
261 if (Key == NULL) {\r
262 break;\r
263 }\r
264 CopyMem (\r
265 &KeyOption->Keys[KeyOption->KeyData.Options.InputKeyCount],\r
266 Key,\r
267 sizeof (EFI_INPUT_KEY)\r
268 );\r
269 KeyOption->KeyData.Options.InputKeyCount++;\r
270 }\r
271\r
272 if (Key != NULL) {\r
273 //\r
274 // Too many keys\r
275 //\r
276 return EFI_INVALID_PARAMETER;\r
277 }\r
278\r
279 if ((Modifier & ~(EFI_BOOT_MANAGER_SHIFT_PRESSED\r
280 | EFI_BOOT_MANAGER_CONTROL_PRESSED\r
281 | EFI_BOOT_MANAGER_ALT_PRESSED\r
282 | EFI_BOOT_MANAGER_LOGO_PRESSED\r
283 | EFI_BOOT_MANAGER_MENU_KEY_PRESSED\r
284 | EFI_BOOT_MANAGER_SYS_REQ_PRESSED\r
285 )) != 0) {\r
286 return EFI_INVALID_PARAMETER;\r
287 }\r
288\r
289 if (BmBitSet (Modifier, EFI_BOOT_MANAGER_SHIFT_PRESSED)) {\r
290 KeyOption->KeyData.Options.ShiftPressed = 1;\r
291 }\r
292 if (BmBitSet (Modifier, EFI_BOOT_MANAGER_CONTROL_PRESSED)) {\r
293 KeyOption->KeyData.Options.ControlPressed = 1;\r
294 }\r
295 if (BmBitSet (Modifier, EFI_BOOT_MANAGER_ALT_PRESSED)) {\r
296 KeyOption->KeyData.Options.AltPressed = 1;\r
297 }\r
298 if (BmBitSet (Modifier, EFI_BOOT_MANAGER_LOGO_PRESSED)) {\r
299 KeyOption->KeyData.Options.LogoPressed = 1;\r
300 }\r
301 if (BmBitSet (Modifier, EFI_BOOT_MANAGER_MENU_KEY_PRESSED)) {\r
302 KeyOption->KeyData.Options.MenuPressed = 1;\r
303 }\r
304 if (BmBitSet (Modifier, EFI_BOOT_MANAGER_SYS_REQ_PRESSED)) {\r
305 KeyOption->KeyData.Options.SysReqPressed = 1;\r
306 }\r
307\r
308 return EFI_SUCCESS;\r
309}\r
310\r
311/**\r
312 Try to boot the boot option triggered by hot key.\r
313**/\r
314VOID\r
315EFIAPI\r
316EfiBootManagerHotkeyBoot (\r
317 VOID\r
318 )\r
319{\r
320 if (mBmHotkeyBootOption.OptionNumber != LoadOptionNumberUnassigned) {\r
321 EfiBootManagerBoot (&mBmHotkeyBootOption);\r
322 EfiBootManagerFreeLoadOption (&mBmHotkeyBootOption);\r
323 mBmHotkeyBootOption.OptionNumber = LoadOptionNumberUnassigned;\r
324 }\r
325}\r
326\r
327/**\r
328 This is the common notification function for HotKeys, it will be registered\r
329 with SimpleTextInEx protocol interface - RegisterKeyNotify() of ConIn handle.\r
330\r
331 @param KeyData A pointer to a buffer that is filled in with the keystroke\r
332 information for the key that was pressed.\r
333\r
334 @retval EFI_SUCCESS KeyData is successfully processed.\r
335 @return EFI_NOT_FOUND Fail to find boot option variable.\r
336**/\r
337EFI_STATUS\r
338EFIAPI\r
339BmHotkeyCallback (\r
340 IN EFI_KEY_DATA *KeyData\r
341)\r
342{\r
343 LIST_ENTRY *Link;\r
344 BM_HOTKEY *Hotkey;\r
f9a24380 345 CHAR16 OptionName[BM_OPTION_NAME_LEN];\r
067ed98a
RN
346 EFI_STATUS Status;\r
347 EFI_KEY_DATA *HotkeyData;\r
348\r
349 if (mBmHotkeyBootOption.OptionNumber != LoadOptionNumberUnassigned) {\r
350 //\r
351 // Do not process sequential hotkey stroke until the current boot option returns\r
352 //\r
353 return EFI_SUCCESS;\r
354 }\r
355\r
356 DEBUG ((EFI_D_INFO, "[Bds]BmHotkeyCallback: %04x:%04x\n", KeyData->Key.ScanCode, KeyData->Key.UnicodeChar));\r
357\r
358 EfiAcquireLock (&mBmHotkeyLock);\r
359 for ( Link = GetFirstNode (&mBmHotkeyList)\r
360 ; !IsNull (&mBmHotkeyList, Link)\r
361 ; Link = GetNextNode (&mBmHotkeyList, Link)\r
362 ) {\r
363 Hotkey = BM_HOTKEY_FROM_LINK (Link);\r
364\r
365 //\r
366 // Is this Key Stroke we are waiting for?\r
367 //\r
368 ASSERT (Hotkey->WaitingKey < (sizeof (Hotkey->KeyData) / sizeof (Hotkey->KeyData[0])));\r
369 HotkeyData = &Hotkey->KeyData[Hotkey->WaitingKey];\r
370 if ((KeyData->Key.ScanCode == HotkeyData->Key.ScanCode) &&\r
371 (KeyData->Key.UnicodeChar == HotkeyData->Key.UnicodeChar) &&\r
d1102dba 372 (((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) ?\r
067ed98a
RN
373 (KeyData->KeyState.KeyShiftState == HotkeyData->KeyState.KeyShiftState) : TRUE\r
374 )\r
375 ) {\r
376\r
377 //\r
378 // Receive an expecting key stroke, transit to next waiting state\r
379 //\r
380 Hotkey->WaitingKey++;\r
381\r
382 if (Hotkey->WaitingKey == Hotkey->CodeCount) {\r
383 //\r
384 // Reset to initial waiting state\r
385 //\r
386 Hotkey->WaitingKey = 0;\r
387 //\r
388 // Received the whole key stroke sequence\r
389 //\r
390 Status = gBS->SignalEvent (mBmHotkeyTriggered);\r
391 ASSERT_EFI_ERROR (Status);\r
392\r
393 if (!Hotkey->IsContinue) {\r
394 //\r
395 // Launch its BootOption\r
396 //\r
121300c4
RN
397 UnicodeSPrint (\r
398 OptionName, sizeof (OptionName), L"%s%04x",\r
399 mBmLoadOptionName[LoadOptionTypeBoot], Hotkey->BootOption\r
400 );\r
067ed98a
RN
401 Status = EfiBootManagerVariableToLoadOption (OptionName, &mBmHotkeyBootOption);\r
402 DEBUG ((EFI_D_INFO, "[Bds]Hotkey for %s pressed - %r\n", OptionName, Status));\r
403 if (EFI_ERROR (Status)) {\r
404 mBmHotkeyBootOption.OptionNumber = LoadOptionNumberUnassigned;\r
405 }\r
406 } else {\r
407 DEBUG ((EFI_D_INFO, "[Bds]Continue key pressed!\n"));\r
408 }\r
409 }\r
410 } else {\r
411 //\r
412 // Receive an unexpected key stroke, reset to initial waiting state\r
413 //\r
414 Hotkey->WaitingKey = 0;\r
415 }\r
416\r
417 }\r
418 EfiReleaseLock (&mBmHotkeyLock);\r
419\r
420 return EFI_SUCCESS;\r
421}\r
422\r
2d15a830
RN
423/**\r
424 Return the active Simple Text Input Ex handle array.\r
425 If the SystemTable.ConsoleInHandle is NULL, the function returns all\r
426 founded Simple Text Input Ex handles.\r
427 Otherwise, it just returns the ConsoleInHandle.\r
428\r
429 @param Count Return the handle count.\r
430\r
431 @retval The active console handles.\r
432**/\r
433EFI_HANDLE *\r
434BmGetActiveConsoleIn (\r
435 OUT UINTN *Count\r
436 )\r
437{\r
438 EFI_STATUS Status;\r
439 EFI_HANDLE *Handles;\r
440\r
b99e9ca9
RN
441 Handles = NULL;\r
442 *Count = 0;\r
443\r
2d15a830
RN
444 if (gST->ConsoleInHandle != NULL) {\r
445 Status = gBS->OpenProtocol (\r
446 gST->ConsoleInHandle,\r
447 &gEfiSimpleTextInputExProtocolGuid,\r
448 NULL,\r
449 gImageHandle,\r
450 NULL,\r
451 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
452 );\r
453 if (!EFI_ERROR (Status)) {\r
065e587c
TP
454 Handles = AllocateCopyPool (sizeof (EFI_HANDLE), &gST->ConsoleInHandle);\r
455 if (Handles != NULL) {\r
456 *Count = 1;\r
457 }\r
2d15a830
RN
458 }\r
459 } else {\r
460 Status = gBS->LocateHandleBuffer (\r
461 ByProtocol,\r
462 &gEfiSimpleTextInputExProtocolGuid,\r
463 NULL,\r
464 Count,\r
465 &Handles\r
466 );\r
467 }\r
2d15a830
RN
468\r
469 return Handles;\r
470}\r
471\r
067ed98a
RN
472/**\r
473 Unregister hotkey notify list.\r
474\r
475 @param Hotkey Hotkey list.\r
476\r
477 @retval EFI_SUCCESS Unregister hotkey notify success.\r
478 @retval Others Unregister hotkey notify failed.\r
479**/\r
480EFI_STATUS\r
481BmUnregisterHotkeyNotify (\r
482 IN BM_HOTKEY *Hotkey\r
483 )\r
484{\r
485 EFI_STATUS Status;\r
486 UINTN Index;\r
487 UINTN KeyIndex;\r
488 EFI_HANDLE *Handles;\r
489 UINTN HandleCount;\r
490 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;\r
491 VOID *NotifyHandle;\r
492\r
2d15a830 493 Handles = BmGetActiveConsoleIn (&HandleCount);\r
067ed98a
RN
494 for (Index = 0; Index < HandleCount; Index++) {\r
495 Status = gBS->HandleProtocol (Handles[Index], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);\r
496 ASSERT_EFI_ERROR (Status);\r
497 for (KeyIndex = 0; KeyIndex < Hotkey->CodeCount; KeyIndex++) {\r
498 Status = TxtInEx->RegisterKeyNotify (\r
499 TxtInEx,\r
500 &Hotkey->KeyData[KeyIndex],\r
501 BmHotkeyCallback,\r
502 &NotifyHandle\r
503 );\r
504 if (!EFI_ERROR (Status)) {\r
505 Status = TxtInEx->UnregisterKeyNotify (TxtInEx, NotifyHandle);\r
506 DEBUG ((EFI_D_INFO, "[Bds]UnregisterKeyNotify: %04x/%04x %r\n", Hotkey->KeyData[KeyIndex].Key.ScanCode, Hotkey->KeyData[KeyIndex].Key.UnicodeChar, Status));\r
507 }\r
508 }\r
509 }\r
510\r
2d15a830
RN
511 if (Handles != NULL) {\r
512 FreePool (Handles);\r
513 }\r
514\r
067ed98a
RN
515 return EFI_SUCCESS;\r
516}\r
517\r
518/**\r
519 Register hotkey notify list.\r
520\r
521 @param TxtInEx Pointer to EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL protocol.\r
522 @param Hotkey Hotkey list.\r
523\r
524 @retval EFI_SUCCESS Register hotkey notify success.\r
525 @retval Others Register hotkey notify failed.\r
526**/\r
527EFI_STATUS\r
528BmRegisterHotkeyNotify (\r
529 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx,\r
530 IN BM_HOTKEY *Hotkey\r
531 )\r
532{\r
533 EFI_STATUS Status;\r
534 UINTN Index;\r
535 VOID *NotifyHandle;\r
536\r
537 for (Index = 0; Index < Hotkey->CodeCount; Index++) {\r
538 Status = TxtInEx->RegisterKeyNotify (\r
539 TxtInEx,\r
540 &Hotkey->KeyData[Index],\r
541 BmHotkeyCallback,\r
542 &NotifyHandle\r
543 );\r
544 DEBUG ((\r
545 EFI_D_INFO,\r
546 "[Bds]RegisterKeyNotify: %04x/%04x %08x/%02x %r\n",\r
547 Hotkey->KeyData[Index].Key.ScanCode,\r
548 Hotkey->KeyData[Index].Key.UnicodeChar,\r
549 Hotkey->KeyData[Index].KeyState.KeyShiftState,\r
550 Hotkey->KeyData[Index].KeyState.KeyToggleState,\r
551 Status\r
552 ));\r
553 if (EFI_ERROR (Status)) {\r
554 //\r
555 // some of the hotkey registry failed\r
556 // do not unregister all in case we have both CTRL-ALT-P and CTRL-ALT-P-R\r
557 //\r
558 break;\r
559 }\r
560 }\r
561\r
562 return EFI_SUCCESS;\r
563}\r
564\r
565/**\r
566 Generate key shift state base on the input key option info.\r
567\r
568 @param Depth Which key is checked.\r
569 @param KeyOption Input key option info.\r
570 @param KeyShiftState Input key shift state.\r
571 @param KeyShiftStates Return possible key shift state array.\r
572 @param KeyShiftStateCount Possible key shift state count.\r
573**/\r
574VOID\r
575BmGenerateKeyShiftState (\r
576 IN UINTN Depth,\r
577 IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOption,\r
578 IN UINT32 KeyShiftState,\r
579 IN UINT32 *KeyShiftStates,\r
580 IN UINTN *KeyShiftStateCount\r
581 )\r
582{\r
583 switch (Depth) {\r
584 case 0:\r
585 if (KeyOption->KeyData.Options.ShiftPressed) {\r
586 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_RIGHT_SHIFT_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
587 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_LEFT_SHIFT_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
588 } else {\r
589 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState, KeyShiftStates, KeyShiftStateCount);\r
590 }\r
591 break;\r
592\r
593 case 1:\r
594 if (KeyOption->KeyData.Options.ControlPressed) {\r
595 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_RIGHT_CONTROL_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
596 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_LEFT_CONTROL_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
597 } else {\r
598 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState, KeyShiftStates, KeyShiftStateCount);\r
599 }\r
600 break;\r
601\r
602 case 2:\r
603 if (KeyOption->KeyData.Options.AltPressed) {\r
604 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_RIGHT_ALT_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
605 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_LEFT_ALT_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
606 } else {\r
607 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState, KeyShiftStates, KeyShiftStateCount);\r
608 }\r
609 break;\r
610 case 3:\r
611 if (KeyOption->KeyData.Options.LogoPressed) {\r
612 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_RIGHT_LOGO_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
613 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_LEFT_LOGO_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
614 } else {\r
615 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState, KeyShiftStates, KeyShiftStateCount);\r
616 }\r
617 break;\r
618 case 4:\r
619 if (KeyOption->KeyData.Options.MenuPressed) {\r
620 KeyShiftState |= EFI_MENU_KEY_PRESSED;\r
621 }\r
622 if (KeyOption->KeyData.Options.SysReqPressed) {\r
623 KeyShiftState |= EFI_SYS_REQ_PRESSED;\r
624 }\r
625 KeyShiftStates[*KeyShiftStateCount] = KeyShiftState;\r
626 (*KeyShiftStateCount)++;\r
627 break;\r
628 }\r
629}\r
630\r
631/**\r
632 Add it to hot key database, register it to existing TxtInEx.\r
633 New TxtInEx will be automatically registered with all the hot key in dababase\r
634\r
635 @param KeyOption Input key option info.\r
636**/\r
637EFI_STATUS\r
638BmProcessKeyOption (\r
639 IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOption\r
640 )\r
641{\r
642 EFI_STATUS Status;\r
643 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;\r
644 EFI_HANDLE *Handles;\r
645 UINTN HandleCount;\r
646 UINTN HandleIndex;\r
647 UINTN Index;\r
648 BM_HOTKEY *Hotkey;\r
649 UINTN KeyIndex;\r
650 //\r
651 // 16 is enough to enumerate all the possible combination of LEFT_XXX and RIGHT_XXX\r
652 //\r
653 UINT32 KeyShiftStates[16];\r
654 UINTN KeyShiftStateCount;\r
655\r
656 if (KeyOption->KeyData.Options.InputKeyCount > mBmHotkeySupportCount) {\r
657 return EFI_UNSUPPORTED;\r
658 }\r
659\r
660 KeyShiftStateCount = 0;\r
661 BmGenerateKeyShiftState (0, KeyOption, EFI_SHIFT_STATE_VALID, KeyShiftStates, &KeyShiftStateCount);\r
f0209935 662 ASSERT (KeyShiftStateCount <= ARRAY_SIZE (KeyShiftStates));\r
067ed98a
RN
663\r
664 EfiAcquireLock (&mBmHotkeyLock);\r
665\r
2d15a830
RN
666 Handles = BmGetActiveConsoleIn (&HandleCount);\r
667\r
067ed98a
RN
668 for (Index = 0; Index < KeyShiftStateCount; Index++) {\r
669 Hotkey = AllocateZeroPool (sizeof (BM_HOTKEY));\r
670 ASSERT (Hotkey != NULL);\r
671\r
672 Hotkey->Signature = BM_HOTKEY_SIGNATURE;\r
673 Hotkey->BootOption = KeyOption->BootOption;\r
674 Hotkey->IsContinue = (BOOLEAN) (KeyOption == mBmContinueKeyOption);\r
675 Hotkey->CodeCount = (UINT8) KeyOption->KeyData.Options.InputKeyCount;\r
676\r
677 for (KeyIndex = 0; KeyIndex < Hotkey->CodeCount; KeyIndex++) {\r
678 CopyMem (&Hotkey->KeyData[KeyIndex].Key, &KeyOption->Keys[KeyIndex], sizeof (EFI_INPUT_KEY));\r
679 Hotkey->KeyData[KeyIndex].KeyState.KeyShiftState = KeyShiftStates[Index];\r
680 }\r
681 InsertTailList (&mBmHotkeyList, &Hotkey->Link);\r
682\r
067ed98a
RN
683 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
684 Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);\r
685 ASSERT_EFI_ERROR (Status);\r
686 BmRegisterHotkeyNotify (TxtInEx, Hotkey);\r
687 }\r
688 }\r
689\r
2d15a830
RN
690 if (Handles != NULL) {\r
691 FreePool (Handles);\r
692 }\r
067ed98a
RN
693 EfiReleaseLock (&mBmHotkeyLock);\r
694\r
695 return EFI_SUCCESS;\r
696}\r
697\r
698/**\r
699 Callback function for SimpleTextInEx protocol install events\r
700\r
701 @param Event the event that is signaled.\r
702 @param Context not used here.\r
703\r
704**/\r
705VOID\r
706EFIAPI\r
707BmTxtInExCallback (\r
708 IN EFI_EVENT Event,\r
709 IN VOID *Context\r
710 )\r
711{\r
712 EFI_STATUS Status;\r
713 UINTN BufferSize;\r
714 EFI_HANDLE Handle;\r
715 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;\r
716 LIST_ENTRY *Link;\r
717\r
718 while (TRUE) {\r
719 BufferSize = sizeof (EFI_HANDLE);\r
720 Status = gBS->LocateHandle (\r
721 ByRegisterNotify,\r
722 NULL,\r
723 mBmTxtInExRegistration,\r
724 &BufferSize,\r
725 &Handle\r
726 );\r
727 if (EFI_ERROR (Status)) {\r
728 //\r
729 // If no more notification events exist\r
730 //\r
731 return ;\r
732 }\r
733\r
734 Status = gBS->HandleProtocol (\r
735 Handle,\r
736 &gEfiSimpleTextInputExProtocolGuid,\r
737 (VOID **) &TxtInEx\r
738 );\r
739 ASSERT_EFI_ERROR (Status);\r
740\r
741 //\r
742 // Register the hot key notification for the existing items in the list\r
743 //\r
744 EfiAcquireLock (&mBmHotkeyLock);\r
745 for (Link = GetFirstNode (&mBmHotkeyList); !IsNull (&mBmHotkeyList, Link); Link = GetNextNode (&mBmHotkeyList, Link)) {\r
746 BmRegisterHotkeyNotify (TxtInEx, BM_HOTKEY_FROM_LINK (Link));\r
747 }\r
748 EfiReleaseLock (&mBmHotkeyLock);\r
749 }\r
750}\r
751\r
752/**\r
753 Free the key options returned from BmGetKeyOptions.\r
754\r
755 @param KeyOptions Pointer to the key options.\r
756 @param KeyOptionCount Number of the key options.\r
757\r
758 @retval EFI_SUCCESS The key options are freed.\r
759 @retval EFI_NOT_FOUND KeyOptions is NULL.\r
760**/\r
761EFI_STATUS\r
762BmFreeKeyOptions (\r
763 IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions,\r
764 IN UINTN KeyOptionCount\r
765 )\r
766{\r
767 if (KeyOptions != NULL) {\r
768 FreePool (KeyOptions);\r
769 return EFI_SUCCESS;\r
770 } else {\r
771 return EFI_NOT_FOUND;\r
772 }\r
773}\r
774\r
775/**\r
776 Register the key option to exit the waiting of the Boot Manager timeout.\r
777 Platform should ensure that the continue key option isn't conflict with\r
778 other boot key options.\r
779\r
780 @param Modifier Key shift state.\r
781 @param ... Parameter list of pointer of EFI_INPUT_KEY.\r
782\r
783 @retval EFI_SUCCESS Successfully register the continue key option.\r
784 @retval EFI_ALREADY_STARTED The continue key option is already registered.\r
785**/\r
786EFI_STATUS\r
787EFIAPI\r
788EfiBootManagerRegisterContinueKeyOption (\r
789 IN UINT32 Modifier,\r
790 ...\r
791 )\r
792{\r
793 EFI_STATUS Status;\r
794 EFI_BOOT_MANAGER_KEY_OPTION KeyOption;\r
795 VA_LIST Args;\r
d1102dba 796\r
067ed98a
RN
797 if (mBmContinueKeyOption != NULL) {\r
798 return EFI_ALREADY_STARTED;\r
799 }\r
800\r
801 ZeroMem (&KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r
802 VA_START (Args, Modifier);\r
803 Status = BmInitializeKeyFields (Modifier, Args, &KeyOption);\r
804 VA_END (Args);\r
805\r
806 if (!EFI_ERROR (Status)) {\r
807 mBmContinueKeyOption = AllocateCopyPool (sizeof (EFI_BOOT_MANAGER_KEY_OPTION), &KeyOption);\r
808 ASSERT (mBmContinueKeyOption != NULL);\r
809 if (mBmHotkeyServiceStarted) {\r
810 BmProcessKeyOption (mBmContinueKeyOption);\r
811 }\r
812 }\r
813\r
814 return Status;\r
815}\r
816\r
817/**\r
818 Stop the hotkey processing.\r
d1102dba 819\r
067ed98a
RN
820 @param Event Event pointer related to hotkey service.\r
821 @param Context Context pass to this function.\r
822**/\r
823VOID\r
824EFIAPI\r
825BmStopHotkeyService (\r
826 IN EFI_EVENT Event,\r
827 IN VOID *Context\r
828 )\r
829{\r
830 LIST_ENTRY *Link;\r
831 BM_HOTKEY *Hotkey;\r
832\r
833 DEBUG ((EFI_D_INFO, "[Bds]Stop Hotkey Service!\n"));\r
834 gBS->CloseEvent (Event);\r
835\r
836 EfiAcquireLock (&mBmHotkeyLock);\r
837 for (Link = GetFirstNode (&mBmHotkeyList); !IsNull (&mBmHotkeyList, Link); ) {\r
838 Hotkey = BM_HOTKEY_FROM_LINK (Link);\r
839 BmUnregisterHotkeyNotify (Hotkey);\r
840 Link = RemoveEntryList (Link);\r
841 FreePool (Hotkey);\r
842 }\r
843 EfiReleaseLock (&mBmHotkeyLock);\r
844}\r
845\r
846/**\r
847 Start the hot key service so that the key press can trigger the boot option.\r
848\r
d1102dba 849 @param HotkeyTriggered Return the waitable event and it will be signaled\r
067ed98a
RN
850 when a valid hot key is pressed.\r
851\r
852 @retval EFI_SUCCESS The hot key service is started.\r
853**/\r
854EFI_STATUS\r
855EFIAPI\r
856EfiBootManagerStartHotkeyService (\r
857 IN EFI_EVENT *HotkeyTriggered\r
858 )\r
859{\r
860 EFI_STATUS Status;\r
861 EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions;\r
862 UINTN KeyOptionCount;\r
863 UINTN Index;\r
864 EFI_EVENT Event;\r
865 UINT32 *BootOptionSupport;\r
866\r
a0a03415
RN
867 GetEfiGlobalVariable2 (EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME, (VOID **) &BootOptionSupport, NULL);\r
868 if (BootOptionSupport != NULL) {\r
869 if ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_KEY) != 0) {\r
870 mBmHotkeySupportCount = ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_COUNT) >> LowBitSet32 (EFI_BOOT_OPTION_SUPPORT_COUNT));\r
871 }\r
872 FreePool (BootOptionSupport);\r
067ed98a 873 }\r
067ed98a
RN
874\r
875 if (mBmHotkeySupportCount == 0) {\r
876 DEBUG ((EFI_D_INFO, "Bds: BootOptionSupport NV variable forbids starting the hotkey service.\n"));\r
877 return EFI_UNSUPPORTED;\r
878 }\r
879\r
880 Status = gBS->CreateEvent (\r
881 EVT_NOTIFY_WAIT,\r
882 TPL_CALLBACK,\r
ac72474d 883 EfiEventEmptyFunction,\r
067ed98a
RN
884 NULL,\r
885 &mBmHotkeyTriggered\r
886 );\r
887 ASSERT_EFI_ERROR (Status);\r
888\r
889 if (HotkeyTriggered != NULL) {\r
890 *HotkeyTriggered = mBmHotkeyTriggered;\r
891 }\r
892\r
893 KeyOptions = BmGetKeyOptions (&KeyOptionCount);\r
894 for (Index = 0; Index < KeyOptionCount; Index ++) {\r
895 BmProcessKeyOption (&KeyOptions[Index]);\r
896 }\r
897 BmFreeKeyOptions (KeyOptions, KeyOptionCount);\r
898\r
899 if (mBmContinueKeyOption != NULL) {\r
900 BmProcessKeyOption (mBmContinueKeyOption);\r
901 }\r
902\r
2d15a830
RN
903 //\r
904 // Hook hotkey on every future SimpleTextInputEx instance when\r
905 // SystemTable.ConsoleInHandle == NULL, which means the console\r
906 // manager (ConSplitter) is absent.\r
907 //\r
908 if (gST->ConsoleInHandle == NULL) {\r
909 EfiCreateProtocolNotifyEvent (\r
910 &gEfiSimpleTextInputExProtocolGuid,\r
911 TPL_CALLBACK,\r
912 BmTxtInExCallback,\r
913 NULL,\r
914 &mBmTxtInExRegistration\r
915 );\r
916 }\r
067ed98a
RN
917\r
918 Status = EfiCreateEventReadyToBootEx (\r
919 TPL_CALLBACK,\r
920 BmStopHotkeyService,\r
921 NULL,\r
922 &Event\r
923 );\r
924 ASSERT_EFI_ERROR (Status);\r
925\r
067ed98a
RN
926 mBmHotkeyServiceStarted = TRUE;\r
927 return Status;\r
928}\r
929\r
930/**\r
931 Add the key option.\r
932 It adds the key option variable and the key option takes affect immediately.\r
933\r
934 @param AddedOption Return the added key option.\r
935 @param BootOptionNumber The boot option number for the key option.\r
936 @param Modifier Key shift state.\r
937 @param ... Parameter list of pointer of EFI_INPUT_KEY.\r
938\r
939 @retval EFI_SUCCESS The key option is added.\r
940 @retval EFI_ALREADY_STARTED The hot key is already used by certain key option.\r
941**/\r
942EFI_STATUS\r
943EFIAPI\r
944EfiBootManagerAddKeyOptionVariable (\r
945 OUT EFI_BOOT_MANAGER_KEY_OPTION *AddedOption, OPTIONAL\r
946 IN UINT16 BootOptionNumber,\r
947 IN UINT32 Modifier,\r
948 ...\r
949 )\r
950{\r
951 EFI_STATUS Status;\r
952 VA_LIST Args;\r
953 VOID *BootOption;\r
954 UINTN BootOptionSize;\r
f9a24380 955 CHAR16 BootOptionName[BM_OPTION_NAME_LEN];\r
067ed98a
RN
956 EFI_BOOT_MANAGER_KEY_OPTION KeyOption;\r
957 EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions;\r
958 UINTN KeyOptionCount;\r
959 UINTN Index;\r
960 UINTN KeyOptionNumber;\r
f9a24380 961 CHAR16 KeyOptionName[sizeof ("Key####")];\r
067ed98a 962\r
121300c4
RN
963 UnicodeSPrint (\r
964 BootOptionName, sizeof (BootOptionName), L"%s%04x",\r
965 mBmLoadOptionName[LoadOptionTypeBoot], BootOptionNumber\r
966 );\r
067ed98a
RN
967 GetEfiGlobalVariable2 (BootOptionName, &BootOption, &BootOptionSize);\r
968\r
969 if (BootOption == NULL) {\r
970 return EFI_NOT_FOUND;\r
971 }\r
972\r
973 ZeroMem (&KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r
974 KeyOption.BootOption = BootOptionNumber;\r
975 Status = gBS->CalculateCrc32 (BootOption, BootOptionSize, &KeyOption.BootOptionCrc);\r
976 ASSERT_EFI_ERROR (Status);\r
977 FreePool (BootOption);\r
978\r
979 VA_START (Args, Modifier);\r
980 Status = BmInitializeKeyFields (Modifier, Args, &KeyOption);\r
981 VA_END (Args);\r
982 if (EFI_ERROR (Status)) {\r
983 return Status;\r
984 }\r
985\r
986 KeyOptionNumber = LoadOptionNumberUnassigned;\r
987 //\r
988 // Check if the hot key sequence was defined already\r
989 //\r
990 KeyOptions = BmGetKeyOptions (&KeyOptionCount);\r
991 for (Index = 0; Index < KeyOptionCount; Index++) {\r
992 if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) &&\r
993 (CompareMem (KeyOptions[Index].Keys, KeyOption.Keys, KeyOption.KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY)) == 0)) {\r
994 break;\r
995 }\r
996\r
997 if ((KeyOptionNumber == LoadOptionNumberUnassigned) &&\r
998 (KeyOptions[Index].OptionNumber > Index)\r
999 ){\r
1000 KeyOptionNumber = Index;\r
1001 }\r
1002 }\r
1003 BmFreeKeyOptions (KeyOptions, KeyOptionCount);\r
1004\r
1005 if (Index < KeyOptionCount) {\r
1006 return EFI_ALREADY_STARTED;\r
1007 }\r
1008\r
1009 if (KeyOptionNumber == LoadOptionNumberUnassigned) {\r
1010 KeyOptionNumber = KeyOptionCount;\r
1011 }\r
1012\r
1013 UnicodeSPrint (KeyOptionName, sizeof (KeyOptionName), L"Key%04x", KeyOptionNumber);\r
1014\r
1015 Status = gRT->SetVariable (\r
1016 KeyOptionName,\r
1017 &gEfiGlobalVariableGuid,\r
1018 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1019 BmSizeOfKeyOption (&KeyOption),\r
1020 &KeyOption\r
1021 );\r
1022 if (!EFI_ERROR (Status)) {\r
1023 //\r
1024 // Return the Key Option in case needed by caller\r
1025 //\r
1026 if (AddedOption != NULL) {\r
1027 CopyMem (AddedOption, &KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r
1028 }\r
1029\r
1030 //\r
1031 // Register the newly added hot key\r
1032 // Calling this function before EfiBootManagerStartHotkeyService doesn't\r
1033 // need to call BmProcessKeyOption\r
1034 //\r
1035 if (mBmHotkeyServiceStarted) {\r
1036 BmProcessKeyOption (&KeyOption);\r
1037 }\r
1038 }\r
1039\r
1040 return Status;\r
1041}\r
1042\r
1043/**\r
1044 Delete the Key Option variable and unregister the hot key\r
1045\r
1046 @param DeletedOption Return the deleted key options.\r
1047 @param Modifier Key shift state.\r
1048 @param ... Parameter list of pointer of EFI_INPUT_KEY.\r
1049\r
1050 @retval EFI_SUCCESS The key option is deleted.\r
1051 @retval EFI_NOT_FOUND The key option cannot be found.\r
1052**/\r
1053EFI_STATUS\r
1054EFIAPI\r
1055EfiBootManagerDeleteKeyOptionVariable (\r
1056 IN EFI_BOOT_MANAGER_KEY_OPTION *DeletedOption, OPTIONAL\r
1057 IN UINT32 Modifier,\r
1058 ...\r
1059 )\r
1060{\r
1061 EFI_STATUS Status;\r
1062 UINTN Index;\r
1063 VA_LIST Args;\r
1064 EFI_BOOT_MANAGER_KEY_OPTION KeyOption;\r
1065 EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions;\r
1066 UINTN KeyOptionCount;\r
1067 LIST_ENTRY *Link;\r
1068 BM_HOTKEY *Hotkey;\r
1069 UINT32 ShiftState;\r
1070 BOOLEAN Match;\r
f9a24380 1071 CHAR16 KeyOptionName[sizeof ("Key####")];\r
067ed98a
RN
1072\r
1073 ZeroMem (&KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r
1074 VA_START (Args, Modifier);\r
1075 Status = BmInitializeKeyFields (Modifier, Args, &KeyOption);\r
1076 VA_END (Args);\r
1077\r
1078 if (EFI_ERROR (Status)) {\r
1079 return Status;\r
1080 }\r
1081\r
1082 EfiAcquireLock (&mBmHotkeyLock);\r
1083 //\r
1084 // Delete the key option from active hot key list\r
1085 // Could have multiple entries when modifier isn't 0 because we map the ShiftPressed to RIGHT_SHIFT and RIGHT_SHIFT\r
1086 //\r
1087 for (Link = GetFirstNode (&mBmHotkeyList); !IsNull (&mBmHotkeyList, Link); ) {\r
1088 Hotkey = BM_HOTKEY_FROM_LINK (Link);\r
1089 Match = (BOOLEAN) (Hotkey->CodeCount == KeyOption.KeyData.Options.InputKeyCount);\r
1090\r
1091 for (Index = 0; Match && (Index < Hotkey->CodeCount); Index++) {\r
1092 ShiftState = Hotkey->KeyData[Index].KeyState.KeyShiftState;\r
1093 if (\r
1094 (BmBitSet (ShiftState, EFI_RIGHT_SHIFT_PRESSED | EFI_LEFT_SHIFT_PRESSED) != KeyOption.KeyData.Options.ShiftPressed) ||\r
1095 (BmBitSet (ShiftState, EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED) != KeyOption.KeyData.Options.ControlPressed) ||\r
1096 (BmBitSet (ShiftState, EFI_RIGHT_ALT_PRESSED | EFI_LEFT_ALT_PRESSED) != KeyOption.KeyData.Options.AltPressed) ||\r
1097 (BmBitSet (ShiftState, EFI_RIGHT_LOGO_PRESSED | EFI_LEFT_LOGO_PRESSED) != KeyOption.KeyData.Options.LogoPressed) ||\r
1098 (BmBitSet (ShiftState, EFI_MENU_KEY_PRESSED) != KeyOption.KeyData.Options.MenuPressed) ||\r
1099 (BmBitSet (ShiftState, EFI_SYS_REQ_PRESSED) != KeyOption.KeyData.Options.SysReqPressed) ||\r
1100 (CompareMem (&Hotkey->KeyData[Index].Key, &KeyOption.Keys[Index], sizeof (EFI_INPUT_KEY)) != 0)\r
1101 ) {\r
1102 //\r
1103 // Break when any field doesn't match\r
1104 //\r
1105 Match = FALSE;\r
1106 break;\r
1107 }\r
1108 }\r
1109\r
1110 if (Match) {\r
1111 Link = RemoveEntryList (Link);\r
1112 FreePool (Hotkey);\r
1113 } else {\r
1114 Link = GetNextNode (&mBmHotkeyList, Link);\r
1115 }\r
1116 }\r
1117\r
1118 //\r
1119 // Delete the key option from the variable\r
1120 //\r
1121 Status = EFI_NOT_FOUND;\r
1122 KeyOptions = BmGetKeyOptions (&KeyOptionCount);\r
1123 for (Index = 0; Index < KeyOptionCount; Index++) {\r
1124 if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) &&\r
1125 (CompareMem (\r
1126 KeyOptions[Index].Keys, KeyOption.Keys,\r
1127 KeyOption.KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY)) == 0)\r
1128 ) {\r
1129 UnicodeSPrint (KeyOptionName, sizeof (KeyOptionName), L"Key%04x", KeyOptions[Index].OptionNumber);\r
1130 Status = gRT->SetVariable (\r
1131 KeyOptionName,\r
1132 &gEfiGlobalVariableGuid,\r
1133 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1134 0,\r
1135 NULL\r
1136 );\r
1137 //\r
1138 // Return the deleted key option in case needed by caller\r
1139 //\r
1140 if (DeletedOption != NULL) {\r
1141 CopyMem (DeletedOption, &KeyOptions[Index], sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r
1142 }\r
1143 break;\r
1144 }\r
1145 }\r
1146 BmFreeKeyOptions (KeyOptions, KeyOptionCount);\r
1147\r
1148 EfiReleaseLock (&mBmHotkeyLock);\r
1149\r
1150 return Status;\r
1151}\r