]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
ShellPkg: Modify the 'dh' Shell command to dump the Firmware Management Protocol...
[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
461 if (gST->ConsoleInHandle != NULL) {\r
462 Status = gBS->OpenProtocol (\r
463 gST->ConsoleInHandle,\r
464 &gEfiSimpleTextInputExProtocolGuid,\r
465 NULL,\r
466 gImageHandle,\r
467 NULL,\r
468 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
469 );\r
470 if (!EFI_ERROR (Status)) {\r
471 Handles = AllocateCopyPool (sizeof (EFI_HANDLE *), &gST->ConsoleInHandle);\r
472 *Count = 1;\r
473 }\r
474 } else {\r
475 Status = gBS->LocateHandleBuffer (\r
476 ByProtocol,\r
477 &gEfiSimpleTextInputExProtocolGuid,\r
478 NULL,\r
479 Count,\r
480 &Handles\r
481 );\r
482 }\r
483 if (EFI_ERROR (Status)) {\r
484 Handles = NULL;\r
485 *Count = 0;\r
486 }\r
487\r
488 return Handles;\r
489}\r
490\r
067ed98a
RN
491/**\r
492 Unregister hotkey notify list.\r
493\r
494 @param Hotkey Hotkey list.\r
495\r
496 @retval EFI_SUCCESS Unregister hotkey notify success.\r
497 @retval Others Unregister hotkey notify failed.\r
498**/\r
499EFI_STATUS\r
500BmUnregisterHotkeyNotify (\r
501 IN BM_HOTKEY *Hotkey\r
502 )\r
503{\r
504 EFI_STATUS Status;\r
505 UINTN Index;\r
506 UINTN KeyIndex;\r
507 EFI_HANDLE *Handles;\r
508 UINTN HandleCount;\r
509 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;\r
510 VOID *NotifyHandle;\r
511\r
2d15a830 512 Handles = BmGetActiveConsoleIn (&HandleCount);\r
067ed98a
RN
513 for (Index = 0; Index < HandleCount; Index++) {\r
514 Status = gBS->HandleProtocol (Handles[Index], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);\r
515 ASSERT_EFI_ERROR (Status);\r
516 for (KeyIndex = 0; KeyIndex < Hotkey->CodeCount; KeyIndex++) {\r
517 Status = TxtInEx->RegisterKeyNotify (\r
518 TxtInEx,\r
519 &Hotkey->KeyData[KeyIndex],\r
520 BmHotkeyCallback,\r
521 &NotifyHandle\r
522 );\r
523 if (!EFI_ERROR (Status)) {\r
524 Status = TxtInEx->UnregisterKeyNotify (TxtInEx, NotifyHandle);\r
525 DEBUG ((EFI_D_INFO, "[Bds]UnregisterKeyNotify: %04x/%04x %r\n", Hotkey->KeyData[KeyIndex].Key.ScanCode, Hotkey->KeyData[KeyIndex].Key.UnicodeChar, Status));\r
526 }\r
527 }\r
528 }\r
529\r
2d15a830
RN
530 if (Handles != NULL) {\r
531 FreePool (Handles);\r
532 }\r
533\r
067ed98a
RN
534 return EFI_SUCCESS;\r
535}\r
536\r
537/**\r
538 Register hotkey notify list.\r
539\r
540 @param TxtInEx Pointer to EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL protocol.\r
541 @param Hotkey Hotkey list.\r
542\r
543 @retval EFI_SUCCESS Register hotkey notify success.\r
544 @retval Others Register hotkey notify failed.\r
545**/\r
546EFI_STATUS\r
547BmRegisterHotkeyNotify (\r
548 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx,\r
549 IN BM_HOTKEY *Hotkey\r
550 )\r
551{\r
552 EFI_STATUS Status;\r
553 UINTN Index;\r
554 VOID *NotifyHandle;\r
555\r
556 for (Index = 0; Index < Hotkey->CodeCount; Index++) {\r
557 Status = TxtInEx->RegisterKeyNotify (\r
558 TxtInEx,\r
559 &Hotkey->KeyData[Index],\r
560 BmHotkeyCallback,\r
561 &NotifyHandle\r
562 );\r
563 DEBUG ((\r
564 EFI_D_INFO,\r
565 "[Bds]RegisterKeyNotify: %04x/%04x %08x/%02x %r\n",\r
566 Hotkey->KeyData[Index].Key.ScanCode,\r
567 Hotkey->KeyData[Index].Key.UnicodeChar,\r
568 Hotkey->KeyData[Index].KeyState.KeyShiftState,\r
569 Hotkey->KeyData[Index].KeyState.KeyToggleState,\r
570 Status\r
571 ));\r
572 if (EFI_ERROR (Status)) {\r
573 //\r
574 // some of the hotkey registry failed\r
575 // do not unregister all in case we have both CTRL-ALT-P and CTRL-ALT-P-R\r
576 //\r
577 break;\r
578 }\r
579 }\r
580\r
581 return EFI_SUCCESS;\r
582}\r
583\r
584/**\r
585 Generate key shift state base on the input key option info.\r
586\r
587 @param Depth Which key is checked.\r
588 @param KeyOption Input key option info.\r
589 @param KeyShiftState Input key shift state.\r
590 @param KeyShiftStates Return possible key shift state array.\r
591 @param KeyShiftStateCount Possible key shift state count.\r
592**/\r
593VOID\r
594BmGenerateKeyShiftState (\r
595 IN UINTN Depth,\r
596 IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOption,\r
597 IN UINT32 KeyShiftState,\r
598 IN UINT32 *KeyShiftStates,\r
599 IN UINTN *KeyShiftStateCount\r
600 )\r
601{\r
602 switch (Depth) {\r
603 case 0:\r
604 if (KeyOption->KeyData.Options.ShiftPressed) {\r
605 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_RIGHT_SHIFT_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
606 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_LEFT_SHIFT_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
607 } else {\r
608 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState, KeyShiftStates, KeyShiftStateCount);\r
609 }\r
610 break;\r
611\r
612 case 1:\r
613 if (KeyOption->KeyData.Options.ControlPressed) {\r
614 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_RIGHT_CONTROL_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
615 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_LEFT_CONTROL_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
616 } else {\r
617 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState, KeyShiftStates, KeyShiftStateCount);\r
618 }\r
619 break;\r
620\r
621 case 2:\r
622 if (KeyOption->KeyData.Options.AltPressed) {\r
623 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_RIGHT_ALT_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
624 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_LEFT_ALT_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
625 } else {\r
626 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState, KeyShiftStates, KeyShiftStateCount);\r
627 }\r
628 break;\r
629 case 3:\r
630 if (KeyOption->KeyData.Options.LogoPressed) {\r
631 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_RIGHT_LOGO_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
632 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_LEFT_LOGO_PRESSED, KeyShiftStates, KeyShiftStateCount);\r
633 } else {\r
634 BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState, KeyShiftStates, KeyShiftStateCount);\r
635 }\r
636 break;\r
637 case 4:\r
638 if (KeyOption->KeyData.Options.MenuPressed) {\r
639 KeyShiftState |= EFI_MENU_KEY_PRESSED;\r
640 }\r
641 if (KeyOption->KeyData.Options.SysReqPressed) {\r
642 KeyShiftState |= EFI_SYS_REQ_PRESSED;\r
643 }\r
644 KeyShiftStates[*KeyShiftStateCount] = KeyShiftState;\r
645 (*KeyShiftStateCount)++;\r
646 break;\r
647 }\r
648}\r
649\r
650/**\r
651 Add it to hot key database, register it to existing TxtInEx.\r
652 New TxtInEx will be automatically registered with all the hot key in dababase\r
653\r
654 @param KeyOption Input key option info.\r
655**/\r
656EFI_STATUS\r
657BmProcessKeyOption (\r
658 IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOption\r
659 )\r
660{\r
661 EFI_STATUS Status;\r
662 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;\r
663 EFI_HANDLE *Handles;\r
664 UINTN HandleCount;\r
665 UINTN HandleIndex;\r
666 UINTN Index;\r
667 BM_HOTKEY *Hotkey;\r
668 UINTN KeyIndex;\r
669 //\r
670 // 16 is enough to enumerate all the possible combination of LEFT_XXX and RIGHT_XXX\r
671 //\r
672 UINT32 KeyShiftStates[16];\r
673 UINTN KeyShiftStateCount;\r
674\r
675 if (KeyOption->KeyData.Options.InputKeyCount > mBmHotkeySupportCount) {\r
676 return EFI_UNSUPPORTED;\r
677 }\r
678\r
679 KeyShiftStateCount = 0;\r
680 BmGenerateKeyShiftState (0, KeyOption, EFI_SHIFT_STATE_VALID, KeyShiftStates, &KeyShiftStateCount);\r
681 ASSERT (KeyShiftStateCount <= sizeof (KeyShiftStates) / sizeof (KeyShiftStates[0]));\r
682\r
683 EfiAcquireLock (&mBmHotkeyLock);\r
684\r
2d15a830
RN
685 Handles = BmGetActiveConsoleIn (&HandleCount);\r
686\r
067ed98a
RN
687 for (Index = 0; Index < KeyShiftStateCount; Index++) {\r
688 Hotkey = AllocateZeroPool (sizeof (BM_HOTKEY));\r
689 ASSERT (Hotkey != NULL);\r
690\r
691 Hotkey->Signature = BM_HOTKEY_SIGNATURE;\r
692 Hotkey->BootOption = KeyOption->BootOption;\r
693 Hotkey->IsContinue = (BOOLEAN) (KeyOption == mBmContinueKeyOption);\r
694 Hotkey->CodeCount = (UINT8) KeyOption->KeyData.Options.InputKeyCount;\r
695\r
696 for (KeyIndex = 0; KeyIndex < Hotkey->CodeCount; KeyIndex++) {\r
697 CopyMem (&Hotkey->KeyData[KeyIndex].Key, &KeyOption->Keys[KeyIndex], sizeof (EFI_INPUT_KEY));\r
698 Hotkey->KeyData[KeyIndex].KeyState.KeyShiftState = KeyShiftStates[Index];\r
699 }\r
700 InsertTailList (&mBmHotkeyList, &Hotkey->Link);\r
701\r
067ed98a
RN
702 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
703 Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);\r
704 ASSERT_EFI_ERROR (Status);\r
705 BmRegisterHotkeyNotify (TxtInEx, Hotkey);\r
706 }\r
707 }\r
708\r
2d15a830
RN
709 if (Handles != NULL) {\r
710 FreePool (Handles);\r
711 }\r
067ed98a
RN
712 EfiReleaseLock (&mBmHotkeyLock);\r
713\r
714 return EFI_SUCCESS;\r
715}\r
716\r
717/**\r
718 Callback function for SimpleTextInEx protocol install events\r
719\r
720 @param Event the event that is signaled.\r
721 @param Context not used here.\r
722\r
723**/\r
724VOID\r
725EFIAPI\r
726BmTxtInExCallback (\r
727 IN EFI_EVENT Event,\r
728 IN VOID *Context\r
729 )\r
730{\r
731 EFI_STATUS Status;\r
732 UINTN BufferSize;\r
733 EFI_HANDLE Handle;\r
734 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;\r
735 LIST_ENTRY *Link;\r
736\r
737 while (TRUE) {\r
738 BufferSize = sizeof (EFI_HANDLE);\r
739 Status = gBS->LocateHandle (\r
740 ByRegisterNotify,\r
741 NULL,\r
742 mBmTxtInExRegistration,\r
743 &BufferSize,\r
744 &Handle\r
745 );\r
746 if (EFI_ERROR (Status)) {\r
747 //\r
748 // If no more notification events exist\r
749 //\r
750 return ;\r
751 }\r
752\r
753 Status = gBS->HandleProtocol (\r
754 Handle,\r
755 &gEfiSimpleTextInputExProtocolGuid,\r
756 (VOID **) &TxtInEx\r
757 );\r
758 ASSERT_EFI_ERROR (Status);\r
759\r
760 //\r
761 // Register the hot key notification for the existing items in the list\r
762 //\r
763 EfiAcquireLock (&mBmHotkeyLock);\r
764 for (Link = GetFirstNode (&mBmHotkeyList); !IsNull (&mBmHotkeyList, Link); Link = GetNextNode (&mBmHotkeyList, Link)) {\r
765 BmRegisterHotkeyNotify (TxtInEx, BM_HOTKEY_FROM_LINK (Link));\r
766 }\r
767 EfiReleaseLock (&mBmHotkeyLock);\r
768 }\r
769}\r
770\r
771/**\r
772 Free the key options returned from BmGetKeyOptions.\r
773\r
774 @param KeyOptions Pointer to the key options.\r
775 @param KeyOptionCount Number of the key options.\r
776\r
777 @retval EFI_SUCCESS The key options are freed.\r
778 @retval EFI_NOT_FOUND KeyOptions is NULL.\r
779**/\r
780EFI_STATUS\r
781BmFreeKeyOptions (\r
782 IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions,\r
783 IN UINTN KeyOptionCount\r
784 )\r
785{\r
786 if (KeyOptions != NULL) {\r
787 FreePool (KeyOptions);\r
788 return EFI_SUCCESS;\r
789 } else {\r
790 return EFI_NOT_FOUND;\r
791 }\r
792}\r
793\r
794/**\r
795 Register the key option to exit the waiting of the Boot Manager timeout.\r
796 Platform should ensure that the continue key option isn't conflict with\r
797 other boot key options.\r
798\r
799 @param Modifier Key shift state.\r
800 @param ... Parameter list of pointer of EFI_INPUT_KEY.\r
801\r
802 @retval EFI_SUCCESS Successfully register the continue key option.\r
803 @retval EFI_ALREADY_STARTED The continue key option is already registered.\r
804**/\r
805EFI_STATUS\r
806EFIAPI\r
807EfiBootManagerRegisterContinueKeyOption (\r
808 IN UINT32 Modifier,\r
809 ...\r
810 )\r
811{\r
812 EFI_STATUS Status;\r
813 EFI_BOOT_MANAGER_KEY_OPTION KeyOption;\r
814 VA_LIST Args;\r
815 \r
816 if (mBmContinueKeyOption != NULL) {\r
817 return EFI_ALREADY_STARTED;\r
818 }\r
819\r
820 ZeroMem (&KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r
821 VA_START (Args, Modifier);\r
822 Status = BmInitializeKeyFields (Modifier, Args, &KeyOption);\r
823 VA_END (Args);\r
824\r
825 if (!EFI_ERROR (Status)) {\r
826 mBmContinueKeyOption = AllocateCopyPool (sizeof (EFI_BOOT_MANAGER_KEY_OPTION), &KeyOption);\r
827 ASSERT (mBmContinueKeyOption != NULL);\r
828 if (mBmHotkeyServiceStarted) {\r
829 BmProcessKeyOption (mBmContinueKeyOption);\r
830 }\r
831 }\r
832\r
833 return Status;\r
834}\r
835\r
836/**\r
837 Stop the hotkey processing.\r
838 \r
839 @param Event Event pointer related to hotkey service.\r
840 @param Context Context pass to this function.\r
841**/\r
842VOID\r
843EFIAPI\r
844BmStopHotkeyService (\r
845 IN EFI_EVENT Event,\r
846 IN VOID *Context\r
847 )\r
848{\r
849 LIST_ENTRY *Link;\r
850 BM_HOTKEY *Hotkey;\r
851\r
852 DEBUG ((EFI_D_INFO, "[Bds]Stop Hotkey Service!\n"));\r
853 gBS->CloseEvent (Event);\r
854\r
855 EfiAcquireLock (&mBmHotkeyLock);\r
856 for (Link = GetFirstNode (&mBmHotkeyList); !IsNull (&mBmHotkeyList, Link); ) {\r
857 Hotkey = BM_HOTKEY_FROM_LINK (Link);\r
858 BmUnregisterHotkeyNotify (Hotkey);\r
859 Link = RemoveEntryList (Link);\r
860 FreePool (Hotkey);\r
861 }\r
862 EfiReleaseLock (&mBmHotkeyLock);\r
863}\r
864\r
865/**\r
866 Start the hot key service so that the key press can trigger the boot option.\r
867\r
868 @param HotkeyTriggered Return the waitable event and it will be signaled \r
869 when a valid hot key is pressed.\r
870\r
871 @retval EFI_SUCCESS The hot key service is started.\r
872**/\r
873EFI_STATUS\r
874EFIAPI\r
875EfiBootManagerStartHotkeyService (\r
876 IN EFI_EVENT *HotkeyTriggered\r
877 )\r
878{\r
879 EFI_STATUS Status;\r
880 EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions;\r
881 UINTN KeyOptionCount;\r
882 UINTN Index;\r
883 EFI_EVENT Event;\r
884 UINT32 *BootOptionSupport;\r
885\r
886 Status = GetEfiGlobalVariable2 (EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME, (VOID **) &BootOptionSupport, NULL);\r
887 ASSERT (BootOptionSupport != NULL);\r
888\r
889 if ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_KEY) != 0) {\r
890 mBmHotkeySupportCount = ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_COUNT) >> LowBitSet32 (EFI_BOOT_OPTION_SUPPORT_COUNT));\r
891 }\r
892 FreePool (BootOptionSupport);\r
893\r
894 if (mBmHotkeySupportCount == 0) {\r
895 DEBUG ((EFI_D_INFO, "Bds: BootOptionSupport NV variable forbids starting the hotkey service.\n"));\r
896 return EFI_UNSUPPORTED;\r
897 }\r
898\r
899 Status = gBS->CreateEvent (\r
900 EVT_NOTIFY_WAIT,\r
901 TPL_CALLBACK,\r
902 BmEmptyFunction,\r
903 NULL,\r
904 &mBmHotkeyTriggered\r
905 );\r
906 ASSERT_EFI_ERROR (Status);\r
907\r
908 if (HotkeyTriggered != NULL) {\r
909 *HotkeyTriggered = mBmHotkeyTriggered;\r
910 }\r
911\r
912 KeyOptions = BmGetKeyOptions (&KeyOptionCount);\r
913 for (Index = 0; Index < KeyOptionCount; Index ++) {\r
914 BmProcessKeyOption (&KeyOptions[Index]);\r
915 }\r
916 BmFreeKeyOptions (KeyOptions, KeyOptionCount);\r
917\r
918 if (mBmContinueKeyOption != NULL) {\r
919 BmProcessKeyOption (mBmContinueKeyOption);\r
920 }\r
921\r
2d15a830
RN
922 //\r
923 // Hook hotkey on every future SimpleTextInputEx instance when\r
924 // SystemTable.ConsoleInHandle == NULL, which means the console\r
925 // manager (ConSplitter) is absent.\r
926 //\r
927 if (gST->ConsoleInHandle == NULL) {\r
928 EfiCreateProtocolNotifyEvent (\r
929 &gEfiSimpleTextInputExProtocolGuid,\r
930 TPL_CALLBACK,\r
931 BmTxtInExCallback,\r
932 NULL,\r
933 &mBmTxtInExRegistration\r
934 );\r
935 }\r
067ed98a
RN
936\r
937 Status = EfiCreateEventReadyToBootEx (\r
938 TPL_CALLBACK,\r
939 BmStopHotkeyService,\r
940 NULL,\r
941 &Event\r
942 );\r
943 ASSERT_EFI_ERROR (Status);\r
944\r
067ed98a
RN
945 mBmHotkeyServiceStarted = TRUE;\r
946 return Status;\r
947}\r
948\r
949/**\r
950 Add the key option.\r
951 It adds the key option variable and the key option takes affect immediately.\r
952\r
953 @param AddedOption Return the added key option.\r
954 @param BootOptionNumber The boot option number for the key option.\r
955 @param Modifier Key shift state.\r
956 @param ... Parameter list of pointer of EFI_INPUT_KEY.\r
957\r
958 @retval EFI_SUCCESS The key option is added.\r
959 @retval EFI_ALREADY_STARTED The hot key is already used by certain key option.\r
960**/\r
961EFI_STATUS\r
962EFIAPI\r
963EfiBootManagerAddKeyOptionVariable (\r
964 OUT EFI_BOOT_MANAGER_KEY_OPTION *AddedOption, OPTIONAL\r
965 IN UINT16 BootOptionNumber,\r
966 IN UINT32 Modifier,\r
967 ...\r
968 )\r
969{\r
970 EFI_STATUS Status;\r
971 VA_LIST Args;\r
972 VOID *BootOption;\r
973 UINTN BootOptionSize;\r
f9a24380 974 CHAR16 BootOptionName[BM_OPTION_NAME_LEN];\r
067ed98a
RN
975 EFI_BOOT_MANAGER_KEY_OPTION KeyOption;\r
976 EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions;\r
977 UINTN KeyOptionCount;\r
978 UINTN Index;\r
979 UINTN KeyOptionNumber;\r
f9a24380 980 CHAR16 KeyOptionName[sizeof ("Key####")];\r
067ed98a 981\r
121300c4
RN
982 UnicodeSPrint (\r
983 BootOptionName, sizeof (BootOptionName), L"%s%04x",\r
984 mBmLoadOptionName[LoadOptionTypeBoot], BootOptionNumber\r
985 );\r
067ed98a
RN
986 GetEfiGlobalVariable2 (BootOptionName, &BootOption, &BootOptionSize);\r
987\r
988 if (BootOption == NULL) {\r
989 return EFI_NOT_FOUND;\r
990 }\r
991\r
992 ZeroMem (&KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r
993 KeyOption.BootOption = BootOptionNumber;\r
994 Status = gBS->CalculateCrc32 (BootOption, BootOptionSize, &KeyOption.BootOptionCrc);\r
995 ASSERT_EFI_ERROR (Status);\r
996 FreePool (BootOption);\r
997\r
998 VA_START (Args, Modifier);\r
999 Status = BmInitializeKeyFields (Modifier, Args, &KeyOption);\r
1000 VA_END (Args);\r
1001 if (EFI_ERROR (Status)) {\r
1002 return Status;\r
1003 }\r
1004\r
1005 KeyOptionNumber = LoadOptionNumberUnassigned;\r
1006 //\r
1007 // Check if the hot key sequence was defined already\r
1008 //\r
1009 KeyOptions = BmGetKeyOptions (&KeyOptionCount);\r
1010 for (Index = 0; Index < KeyOptionCount; Index++) {\r
1011 if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) &&\r
1012 (CompareMem (KeyOptions[Index].Keys, KeyOption.Keys, KeyOption.KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY)) == 0)) {\r
1013 break;\r
1014 }\r
1015\r
1016 if ((KeyOptionNumber == LoadOptionNumberUnassigned) &&\r
1017 (KeyOptions[Index].OptionNumber > Index)\r
1018 ){\r
1019 KeyOptionNumber = Index;\r
1020 }\r
1021 }\r
1022 BmFreeKeyOptions (KeyOptions, KeyOptionCount);\r
1023\r
1024 if (Index < KeyOptionCount) {\r
1025 return EFI_ALREADY_STARTED;\r
1026 }\r
1027\r
1028 if (KeyOptionNumber == LoadOptionNumberUnassigned) {\r
1029 KeyOptionNumber = KeyOptionCount;\r
1030 }\r
1031\r
1032 UnicodeSPrint (KeyOptionName, sizeof (KeyOptionName), L"Key%04x", KeyOptionNumber);\r
1033\r
1034 Status = gRT->SetVariable (\r
1035 KeyOptionName,\r
1036 &gEfiGlobalVariableGuid,\r
1037 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1038 BmSizeOfKeyOption (&KeyOption),\r
1039 &KeyOption\r
1040 );\r
1041 if (!EFI_ERROR (Status)) {\r
1042 //\r
1043 // Return the Key Option in case needed by caller\r
1044 //\r
1045 if (AddedOption != NULL) {\r
1046 CopyMem (AddedOption, &KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r
1047 }\r
1048\r
1049 //\r
1050 // Register the newly added hot key\r
1051 // Calling this function before EfiBootManagerStartHotkeyService doesn't\r
1052 // need to call BmProcessKeyOption\r
1053 //\r
1054 if (mBmHotkeyServiceStarted) {\r
1055 BmProcessKeyOption (&KeyOption);\r
1056 }\r
1057 }\r
1058\r
1059 return Status;\r
1060}\r
1061\r
1062/**\r
1063 Delete the Key Option variable and unregister the hot key\r
1064\r
1065 @param DeletedOption Return the deleted key options.\r
1066 @param Modifier Key shift state.\r
1067 @param ... Parameter list of pointer of EFI_INPUT_KEY.\r
1068\r
1069 @retval EFI_SUCCESS The key option is deleted.\r
1070 @retval EFI_NOT_FOUND The key option cannot be found.\r
1071**/\r
1072EFI_STATUS\r
1073EFIAPI\r
1074EfiBootManagerDeleteKeyOptionVariable (\r
1075 IN EFI_BOOT_MANAGER_KEY_OPTION *DeletedOption, OPTIONAL\r
1076 IN UINT32 Modifier,\r
1077 ...\r
1078 )\r
1079{\r
1080 EFI_STATUS Status;\r
1081 UINTN Index;\r
1082 VA_LIST Args;\r
1083 EFI_BOOT_MANAGER_KEY_OPTION KeyOption;\r
1084 EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions;\r
1085 UINTN KeyOptionCount;\r
1086 LIST_ENTRY *Link;\r
1087 BM_HOTKEY *Hotkey;\r
1088 UINT32 ShiftState;\r
1089 BOOLEAN Match;\r
f9a24380 1090 CHAR16 KeyOptionName[sizeof ("Key####")];\r
067ed98a
RN
1091\r
1092 ZeroMem (&KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r
1093 VA_START (Args, Modifier);\r
1094 Status = BmInitializeKeyFields (Modifier, Args, &KeyOption);\r
1095 VA_END (Args);\r
1096\r
1097 if (EFI_ERROR (Status)) {\r
1098 return Status;\r
1099 }\r
1100\r
1101 EfiAcquireLock (&mBmHotkeyLock);\r
1102 //\r
1103 // Delete the key option from active hot key list\r
1104 // Could have multiple entries when modifier isn't 0 because we map the ShiftPressed to RIGHT_SHIFT and RIGHT_SHIFT\r
1105 //\r
1106 for (Link = GetFirstNode (&mBmHotkeyList); !IsNull (&mBmHotkeyList, Link); ) {\r
1107 Hotkey = BM_HOTKEY_FROM_LINK (Link);\r
1108 Match = (BOOLEAN) (Hotkey->CodeCount == KeyOption.KeyData.Options.InputKeyCount);\r
1109\r
1110 for (Index = 0; Match && (Index < Hotkey->CodeCount); Index++) {\r
1111 ShiftState = Hotkey->KeyData[Index].KeyState.KeyShiftState;\r
1112 if (\r
1113 (BmBitSet (ShiftState, EFI_RIGHT_SHIFT_PRESSED | EFI_LEFT_SHIFT_PRESSED) != KeyOption.KeyData.Options.ShiftPressed) ||\r
1114 (BmBitSet (ShiftState, EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED) != KeyOption.KeyData.Options.ControlPressed) ||\r
1115 (BmBitSet (ShiftState, EFI_RIGHT_ALT_PRESSED | EFI_LEFT_ALT_PRESSED) != KeyOption.KeyData.Options.AltPressed) ||\r
1116 (BmBitSet (ShiftState, EFI_RIGHT_LOGO_PRESSED | EFI_LEFT_LOGO_PRESSED) != KeyOption.KeyData.Options.LogoPressed) ||\r
1117 (BmBitSet (ShiftState, EFI_MENU_KEY_PRESSED) != KeyOption.KeyData.Options.MenuPressed) ||\r
1118 (BmBitSet (ShiftState, EFI_SYS_REQ_PRESSED) != KeyOption.KeyData.Options.SysReqPressed) ||\r
1119 (CompareMem (&Hotkey->KeyData[Index].Key, &KeyOption.Keys[Index], sizeof (EFI_INPUT_KEY)) != 0)\r
1120 ) {\r
1121 //\r
1122 // Break when any field doesn't match\r
1123 //\r
1124 Match = FALSE;\r
1125 break;\r
1126 }\r
1127 }\r
1128\r
1129 if (Match) {\r
1130 Link = RemoveEntryList (Link);\r
1131 FreePool (Hotkey);\r
1132 } else {\r
1133 Link = GetNextNode (&mBmHotkeyList, Link);\r
1134 }\r
1135 }\r
1136\r
1137 //\r
1138 // Delete the key option from the variable\r
1139 //\r
1140 Status = EFI_NOT_FOUND;\r
1141 KeyOptions = BmGetKeyOptions (&KeyOptionCount);\r
1142 for (Index = 0; Index < KeyOptionCount; Index++) {\r
1143 if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) &&\r
1144 (CompareMem (\r
1145 KeyOptions[Index].Keys, KeyOption.Keys,\r
1146 KeyOption.KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY)) == 0)\r
1147 ) {\r
1148 UnicodeSPrint (KeyOptionName, sizeof (KeyOptionName), L"Key%04x", KeyOptions[Index].OptionNumber);\r
1149 Status = gRT->SetVariable (\r
1150 KeyOptionName,\r
1151 &gEfiGlobalVariableGuid,\r
1152 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1153 0,\r
1154 NULL\r
1155 );\r
1156 //\r
1157 // Return the deleted key option in case needed by caller\r
1158 //\r
1159 if (DeletedOption != NULL) {\r
1160 CopyMem (DeletedOption, &KeyOptions[Index], sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r
1161 }\r
1162 break;\r
1163 }\r
1164 }\r
1165 BmFreeKeyOptions (KeyOptions, KeyOptionCount);\r
1166\r
1167 EfiReleaseLock (&mBmHotkeyLock);\r
1168\r
1169 return Status;\r
1170}\r