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