]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Merged in the following trackers from EDK:
authorqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 23 Jun 2008 09:41:33 +0000 (09:41 +0000)
committerqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 23 Jun 2008 09:41:33 +0000 (09:41 +0000)
EDK1145 Cursor mising in shell in some case
EDK1099: Dell - [HII] HiiGetFontInfo() not retrieve the system font by FoFontInfoMask
EDK1127: [UEFI 2.10] Keyboard layout support
EDK1129: [UEFI HII] GUID is represented wrongly in Config String
And some other fixes such as
*[UEFI HII] HiiGetAltCfg is generating "Name=" sub string in the wrong format
*UEFI HII: GetUnicodeStringTextOrSize() doesn't handle NULL StringDest properly
*GetFontInfo() need be updated to avoid iteration
*HIIStringProtocolTest failed on multiple platform
*[Uefi 2.1] Comply with latest Hii ECR
* GetFontInfo() need be updated to avoid iteration

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5361 6f19259b-4bc3-4df7-8a09-765794883524

18 files changed:
MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
MdeModulePkg/Bus/Usb/UsbKbDxe/efikey.c
MdeModulePkg/Bus/Usb/UsbKbDxe/efikey.h
MdeModulePkg/Bus/Usb/UsbKbDxe/keyboard.c
MdeModulePkg/Bus/Usb/UsbKbDxe/keyboard.h
MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/Universal/BdsDxe/FrontPage.c
MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseEntry.c
MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
MdeModulePkg/Universal/HiiDatabaseDxe/String.c
MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c
MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
MdeModulePkg/Universal/SetupBrowserDxe/Ui.c

index a075c0e1aba2e81b5ec19eadf9086fb88d019661..0a50c277c54d8ace3de00c02c5b0a1e245d6eee3 100644 (file)
   gSimpleTextInExNotifyGuid                     # ALWAYS_CONSUMED\r
 \r
 [Protocols]\r
-  gEfiUsbIoProtocolGuid                         # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiDevicePathProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiSimpleTextInProtocolGuid                  # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiSimpleTextInputExProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiUsbIoProtocolGuid                         # PROTOCOL TO_START\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL TO_START\r
+  gEfiSimpleTextInProtocolGuid                  # PROTOCOL BY_START\r
+  gEfiSimpleTextInputExProtocolGuid             # PROTOCOL BY_START\r
+  gEfiHiiDatabaseProtocolGuid                   # PROTOCOL TO_START\r
 \r
+[FeaturePcd.common]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDisableDefaultKeyboardLayoutInUsbKbDriver\r
+  \r
 [FixedPcd]\r
   gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueKeyboardEnable\r
   gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueKeyboardPresenceDetect\r
index 6ce448642ec7989fd2dc9653215571abde47f726..50413bd500b0807bbb1dfc18047180d9cd41770d 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2004 - 2007, Intel Corporation\r
+Copyright (c) 2004 - 2008, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -382,6 +382,11 @@ USBKeyboardDriverBindingStart (
     goto ErrorExit;\r
   }\r
 \r
+  Status = InitKeyboardLayout (UsbKeyboardDevice);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_WAIT,\r
                   TPL_NOTIFY,\r
@@ -650,6 +655,9 @@ USBKeyboardDriverBindingStop (
   gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);  \r
   KbdFreeNotifyList (&UsbKeyboardDevice->NotifyList);    \r
 \r
+  ReleaseKeyboardLayoutResources (UsbKeyboardDevice);\r
+  gBS->CloseEvent (UsbKeyboardDevice->KeyboardLayoutEvent);\r
+\r
   if (UsbKeyboardDevice->ControllerNameTable != NULL) {\r
     FreeUnicodeStringTable (UsbKeyboardDevice->ControllerNameTable);\r
   }\r
index bab22a3b883ea05970a5d20f3eda57984b704747..19443949e9fc26cb36326236fce6039c25417a70 100644 (file)
@@ -1,5 +1,5 @@
 /** @file\r
-Copyright (c) 2004 - 2007, Intel Corporation\r
+Copyright (c) 2004 - 2008, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -27,9 +27,11 @@ Revision History
 \r
 #include <Protocol/SimpleTextIn.h>\r
 #include <Protocol/SimpleTextInEx.h>\r
-#include <Guid/HotPlugDevice.h>\r
+#include <Protocol/HiiDatabase.h>\r
 #include <Protocol/UsbIo.h>\r
 #include <Protocol/DevicePath.h>\r
+#include <Guid/HiiKeyBoardLayout.h>\r
+#include <Guid/HotPlugDevice.h>\r
 \r
 #include <Library/DebugLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
@@ -79,6 +81,27 @@ typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {
   EFI_KEY_NOTIFY_FUNCTION               KeyNotificationFn;\r
   LIST_ENTRY                            NotifyEntry;\r
 } KEYBOARD_CONSOLE_IN_EX_NOTIFY;\r
+\r
+#define USB_NS_KEY_SIGNATURE  EFI_SIGNATURE_32 ('u', 'n', 's', 'k')\r
+\r
+typedef struct {\r
+  UINTN                         Signature;\r
+  LIST_ENTRY                    Link;\r
+\r
+  //\r
+  // The number of EFI_NS_KEY_MODIFIER children definitions\r
+  //\r
+  UINTN                         KeyCount;\r
+\r
+  //\r
+  // NsKey[0] : Non-spacing key\r
+  // NsKey[1] ~ NsKey[KeyCount] : Physical keys\r
+  //\r
+  EFI_KEY_DESCRIPTOR            *NsKey;\r
+} USB_NS_KEY;\r
+\r
+#define USB_NS_KEY_FORM_FROM_LINK(a)  CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)\r
+\r
 typedef struct {\r
   UINTN                          Signature;\r
   EFI_DEVICE_PATH_PROTOCOL       *DevicePath;\r
@@ -115,12 +138,21 @@ typedef struct {
   UINT8                         RightLogoOn;  \r
   UINT8                         MenuKeyOn;\r
   UINT8                         SysReqOn;\r
+  UINT8                         AltGrOn;\r
 \r
   EFI_KEY_STATE                 KeyState;\r
   //\r
   // Notification function list\r
   //\r
   LIST_ENTRY                    NotifyList;\r
+\r
+  //\r
+  // Non-spacing key list\r
+  //\r
+  LIST_ENTRY                    NsKeyList;\r
+  USB_NS_KEY                    *CurrentNsKey;\r
+  EFI_KEY_DESCRIPTOR            *KeyConvertionTable;\r
+  EFI_EVENT                     KeyboardLayoutEvent;\r
 } USB_KB_DEV;\r
 \r
 //\r
@@ -159,7 +191,7 @@ typedef struct {
   UINT8 Key;\r
 } KB_MODIFIER;\r
 \r
-#define USB_KEYCODE_MAX_MAKE      0x7E\r
+#define USB_KEYCODE_MAX_MAKE      0x62\r
 \r
 #define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3)\r
 \r
index 87179a4c6bbac6255814901fec4388643141e2ad..72fafd9472277404ba2f6a5f7108dd2053d293eb 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2004 - 2005, Intel Corporation\r
+Copyright (c) 2004 - 2008, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -24,129 +24,316 @@ Revision History
 \r
 #include "keyboard.h"\r
 #include <Library/UsbLib.h>\r
+\r
+//\r
+// Static English keyboard layout\r
+// Format:<efi key>, <unicode without shift>, <unicode with shift>, <Modifier>, <AffectedAttribute>\r
+//\r
+STATIC\r
+UINT8 KeyboardLayoutTable[USB_KEYCODE_MAX_MAKE + 8][5] = {\r
+  {EfiKeyC1,         'a',      'A',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x04\r
+  {EfiKeyB5,         'b',      'B',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x05\r
+  {EfiKeyB3,         'c',      'C',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x06\r
+  {EfiKeyC3,         'd',      'D',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x07\r
+  {EfiKeyD3,         'e',      'E',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x08\r
+  {EfiKeyC4,         'f',      'F',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x09\r
+  {EfiKeyC5,         'g',      'G',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x0A\r
+  {EfiKeyC6,         'h',      'H',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x0B\r
+  {EfiKeyD8,         'i',      'I',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x0C\r
+  {EfiKeyC7,         'j',      'J',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x0D\r
+  {EfiKeyC8,         'k',      'K',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x0E\r
+  {EfiKeyC9,         'l',      'L',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x0F\r
+  {EfiKeyB7,         'm',      'M',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x10\r
+  {EfiKeyB6,         'n',      'N',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x11\r
+  {EfiKeyD9,         'o',      'O',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x12\r
+  {EfiKeyD10,        'p',      'P',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x13\r
+  {EfiKeyD1,         'q',      'Q',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x14\r
+  {EfiKeyD4,         'r',      'R',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x15\r
+  {EfiKeyC2,         's',      'S',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x16\r
+  {EfiKeyD5,         't',      'T',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x17\r
+  {EfiKeyD7,         'u',      'U',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x18\r
+  {EfiKeyB4,         'v',      'V',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x19\r
+  {EfiKeyD2,         'w',      'W',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x1A\r
+  {EfiKeyB2,         'x',      'X',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x1B\r
+  {EfiKeyD6,         'y',      'Y',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x1C\r
+  {EfiKeyB1,         'z',      'Z',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},   // 0x1D\r
+  {EfiKeyE1,         '1',      '!',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x1E\r
+  {EfiKeyE2,         '2',      '@',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x1F\r
+  {EfiKeyE3,         '3',      '#',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x20\r
+  {EfiKeyE4,         '4',      '$',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x21\r
+  {EfiKeyE5,         '5',      '%',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x22\r
+  {EfiKeyE6,         '6',      '^',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x23\r
+  {EfiKeyE7,         '7',      '&',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x24\r
+  {EfiKeyE8,         '8',      '*',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x25\r
+  {EfiKeyE9,         '9',      '(',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x26\r
+  {EfiKeyE10,        '0',      ')',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x27\r
+  {EfiKeyEnter,      0x0d,     0x0d,  EFI_NULL_MODIFIER,   0},                                // 0x28   Enter\r
+  {EfiKeyEsc,        0x1b,     0x1b,  EFI_NULL_MODIFIER,   0},                                // 0x29   Esc\r
+  {EfiKeyBackSpace,  0x08,     0x08,  EFI_NULL_MODIFIER,   0},                                // 0x2A   Backspace\r
+  {EfiKeyTab,        0x09,     0x09,  EFI_NULL_MODIFIER,   0},                                // 0x2B   Tab\r
+  {EfiKeySpaceBar,   ' ',      ' ',   EFI_NULL_MODIFIER,   0},                                // 0x2C   Spacebar\r
+  {EfiKeyE11,        '-',      '_',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x2D\r
+  {EfiKeyE12,        '=',      '+',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x2E\r
+  {EfiKeyD11,        '[',      '{',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x2F\r
+  {EfiKeyD12,        ']',      '}',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x30\r
+  {EfiKeyD13,        '\\',     '|',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x31\r
+  {EfiKeyC12,        '\\',     '|',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x32  Keyboard Non-US # and ~\r
+  {EfiKeyC10,        ';',      ':',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x33\r
+  {EfiKeyC11,        '\'',     '"',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x34\r
+  {EfiKeyE0,         '`',      '~',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x35  Keyboard Grave Accent and Tlide\r
+  {EfiKeyB8,         ',',      '<',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x36\r
+  {EfiKeyB9,         '.',      '>',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x37\r
+  {EfiKeyB10,        '/',      '?',   EFI_NULL_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT},   // 0x38\r
+  {EfiKeyCapsLock,   0x00,     0x00,  EFI_CAPS_LOCK_MODIFIER,            0},                  // 0x39   CapsLock\r
+  {EfiKeyF1,         0x00,     0x00,  EFI_FUNCTION_KEY_ONE_MODIFIER,     0},                  // 0x3A\r
+  {EfiKeyF2,         0x00,     0x00,  EFI_FUNCTION_KEY_TWO_MODIFIER,     0},                  // 0x3B\r
+  {EfiKeyF3,         0x00,     0x00,  EFI_FUNCTION_KEY_THREE_MODIFIER,   0},                  // 0x3C\r
+  {EfiKeyF4,         0x00,     0x00,  EFI_FUNCTION_KEY_FOUR_MODIFIER,    0},                  // 0x3D\r
+  {EfiKeyF5,         0x00,     0x00,  EFI_FUNCTION_KEY_FIVE_MODIFIER,    0},                  // 0x3E\r
+  {EfiKeyF6,         0x00,     0x00,  EFI_FUNCTION_KEY_SIX_MODIFIER,     0},                  // 0x3F\r
+  {EfiKeyF7,         0x00,     0x00,  EFI_FUNCTION_KEY_SEVEN_MODIFIER,   0},                  // 0x40\r
+  {EfiKeyF8,         0x00,     0x00,  EFI_FUNCTION_KEY_EIGHT_MODIFIER,   0},                  // 0x41\r
+  {EfiKeyF9,         0x00,     0x00,  EFI_FUNCTION_KEY_NINE_MODIFIER,    0},                  // 0x42\r
+  {EfiKeyF10,        0x00,     0x00,  EFI_FUNCTION_KEY_TEN_MODIFIER,     0},                  // 0x43\r
+  {EfiKeyF11,        0x00,     0x00,  EFI_FUNCTION_KEY_ELEVEN_MODIFIER,  0},                  // 0x44   F11\r
+  {EfiKeyF12,        0x00,     0x00,  EFI_FUNCTION_KEY_TWELVE_MODIFIER,  0},                  // 0x45   F12\r
+  {EfiKeyPrint,      0x00,     0x00,  EFI_PRINT_MODIFIER,                0},                  // 0x46   PrintScreen\r
+  {EfiKeySLck,       0x00,     0x00,  EFI_SCROLL_LOCK_MODIFIER,          0},                  // 0x47   Scroll Lock\r
+  {EfiKeyPause,      0x00,     0x00,  EFI_PAUSE_MODIFIER,                0},                  // 0x48   Pause\r
+  {EfiKeyIns,        0x00,     0x00,  EFI_INSERT_MODIFIER,               0},                  // 0x49\r
+  {EfiKeyHome,       0x00,     0x00,  EFI_HOME_MODIFIER,                 0},                  // 0x4A\r
+  {EfiKeyPgUp,       0x00,     0x00,  EFI_PAGE_UP_MODIFIER,              0},                  // 0x4B\r
+  {EfiKeyDel,        0x00,     0x00,  EFI_DELETE_MODIFIER,               0},                  // 0x4C\r
+  {EfiKeyEnd,        0x00,     0x00,  EFI_END_MODIFIER,                  0},                  // 0x4D\r
+  {EfiKeyPgDn,       0x00,     0x00,  EFI_PAGE_DOWN_MODIFIER,            0},                  // 0x4E\r
+  {EfiKeyRightArrow, 0x00,     0x00,  EFI_RIGHT_ARROW_MODIFIER,          0},                  // 0x4F\r
+  {EfiKeyLeftArrow,  0x00,     0x00,  EFI_LEFT_ARROW_MODIFIER,           0},                  // 0x50\r
+  {EfiKeyDownArrow,  0x00,     0x00,  EFI_DOWN_ARROW_MODIFIER,           0},                  // 0x51\r
+  {EfiKeyUpArrow,    0x00,     0x00,  EFI_UP_ARROW_MODIFIER,             0},                  // 0x52\r
+  {EfiKeyNLck,       0x00,     0x00,  EFI_NUM_LOCK_MODIFIER,             0},                  // 0x53   NumLock\r
+  {EfiKeySlash,      '/',      '/',   EFI_NULL_MODIFIER,                 0},                  // 0x54\r
+  {EfiKeyAsterisk,   '*',      '*',   EFI_NULL_MODIFIER,                 0},                  // 0x55\r
+  {EfiKeyMinus,      '-',      '-',   EFI_NULL_MODIFIER,                 0},                  // 0x56\r
+  {EfiKeyPlus,       '+',      '+',   EFI_NULL_MODIFIER,                 0},                  // 0x57\r
+  {EfiKeyEnter,      0x0d,     0x0d,  EFI_NULL_MODIFIER,                 0},                  // 0x58\r
+  {EfiKeyOne,        '1',      '1',   EFI_END_MODIFIER,         EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},   // 0x59\r
+  {EfiKeyTwo,        '2',      '2',   EFI_DOWN_ARROW_MODIFIER,  EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},   // 0x5A\r
+  {EfiKeyThree,      '3',      '3',   EFI_PAGE_DOWN_MODIFIER,   EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},   // 0x5B\r
+  {EfiKeyFour,       '4',      '4',   EFI_LEFT_ARROW_MODIFIER,  EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},   // 0x5C\r
+  {EfiKeyFive,       '5',      '5',   EFI_NULL_MODIFIER,        EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},   // 0x5D\r
+  {EfiKeySix,        '6',      '6',   EFI_RIGHT_ARROW_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},   // 0x5E\r
+  {EfiKeySeven,      '7',      '7',   EFI_HOME_MODIFIER,        EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},   // 0x5F\r
+  {EfiKeyEight,      '8',      '8',   EFI_UP_ARROW_MODIFIER,    EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},   // 0x60\r
+  {EfiKeyNine,       '9',      '9',   EFI_PAGE_UP_MODIFIER,     EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},   // 0x61\r
+  {EfiKeyZero,       '0',      '0',   EFI_INSERT_MODIFIER,      EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},   // 0x62\r
+  {EfiKeyPeriod,     '.',      '.',   EFI_DELETE_MODIFIER,      EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},   // 0x63\r
+  {EfiKeyB0,         '\\',     '|',   EFI_NULL_MODIFIER,        EFI_AFFECTED_BY_STANDARD_SHIFT}, // 0x64 Keyboard Non-US \ and |\r
+  {EfiKeyA4,         0x00,     0x00,  EFI_NULL_MODIFIER,        0},                              // 0x65 Keyboard Application\r
+\r
+  {EfiKeyLCtrl,      0,        0,     EFI_LEFT_CONTROL_MODIFIER,    0},  // 0xe0\r
+  {EfiKeyLShift,     0,        0,     EFI_LEFT_SHIFT_MODIFIER,      0},  // 0xe1\r
+  {EfiKeyLAlt,       0,        0,     EFI_LEFT_ALT_MODIFIER,        0},  // 0xe2\r
+  {EfiKeyA0,         0,        0,     EFI_NULL_MODIFIER,            0},  // 0xe3\r
+  {EfiKeyRCtrl,      0,        0,     EFI_RIGHT_CONTROL_MODIFIER,   0},  // 0xe4\r
+  {EfiKeyRShift,     0,        0,     EFI_RIGHT_SHIFT_MODIFIER,     0},  // 0xe5\r
+  {EfiKeyA2,         0,        0,     EFI_RIGHT_ALT_MODIFIER,       0},  // 0xe6\r
+  {EfiKeyA3,         0,        0,     EFI_NULL_MODIFIER,            0},  // 0xe7\r
+};\r
+\r
+VOID\r
+LoadDefaultKeyboardLayout (\r
+  IN USB_KB_DEV                 *UsbKeyboardDevice\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Initialize KeyConvertionTable by using default keyboard layout.\r
+\r
+  Arguments:\r
+    UsbKeyboardDevice    The USB_KB_DEV instance.\r
+\r
+  Returns:\r
+    None.\r
+\r
+--*/\r
+{\r
+  UINTN               Index;\r
+  EFI_KEY_DESCRIPTOR  *KeyDescriptor;\r
+\r
+  //\r
+  // Construct KeyConvertionTable by default keyboard layout\r
+  //\r
+  KeyDescriptor = &UsbKeyboardDevice->KeyConvertionTable[0];\r
+\r
+  for (Index = 0; Index < (USB_KEYCODE_MAX_MAKE + 8); Index++) {\r
+    KeyDescriptor->Key                 = (EFI_KEY) KeyboardLayoutTable[Index][0];\r
+    KeyDescriptor->Unicode             = KeyboardLayoutTable[Index][1];\r
+    KeyDescriptor->ShiftedUnicode      = KeyboardLayoutTable[Index][2];\r
+    KeyDescriptor->AltGrUnicode        = 0;\r
+    KeyDescriptor->ShiftedAltGrUnicode = 0;\r
+    KeyDescriptor->Modifier            = KeyboardLayoutTable[Index][3];\r
+    KeyDescriptor->AffectedAttribute   = KeyboardLayoutTable[Index][4];\r
+\r
+    KeyDescriptor++;\r
+  }\r
+}\r
+\r
+//\r
+// EFI_KEY to USB Scan Code convertion table\r
+//\r
+STATIC\r
+UINT8 UsbScanCodeConvertionTable[] = {\r
+  0xe0,  //  EfiKeyLCtrl\r
+  0xe3,  //  EfiKeyA0\r
+  0xe2,  //  EfiKeyLAlt\r
+  0x2c,  //  EfiKeySpaceBar\r
+  0xe6,  //  EfiKeyA2\r
+  0xe7,  //  EfiKeyA3\r
+  0x65,  //  EfiKeyA4\r
+  0xe4,  //  EfiKeyRCtrl\r
+  0x50,  //  EfiKeyLeftArrow\r
+  0x51,  //  EfiKeyDownArrow\r
+  0x4F,  //  EfiKeyRightArrow\r
+  0x62,  //  EfiKeyZero\r
+  0x63,  //  EfiKeyPeriod\r
+  0x28,  //  EfiKeyEnter\r
+  0xe1,  //  EfiKeyLShift\r
+  0x64,  //  EfiKeyB0\r
+  0x1D,  //  EfiKeyB1\r
+  0x1B,  //  EfiKeyB2\r
+  0x06,  //  EfiKeyB3\r
+  0x19,  //  EfiKeyB4\r
+  0x05,  //  EfiKeyB5\r
+  0x11,  //  EfiKeyB6\r
+  0x10,  //  EfiKeyB7\r
+  0x36,  //  EfiKeyB8\r
+  0x37,  //  EfiKeyB9\r
+  0x38,  //  EfiKeyB10\r
+  0xe5,  //  EfiKeyRShift\r
+  0x52,  //  EfiKeyUpArrow\r
+  0x59,  //  EfiKeyOne\r
+  0x5A,  //  EfiKeyTwo\r
+  0x5B,  //  EfiKeyThree\r
+  0x39,  //  EfiKeyCapsLock\r
+  0x04,  //  EfiKeyC1\r
+  0x16,  //  EfiKeyC2\r
+  0x07,  //  EfiKeyC3\r
+  0x09,  //  EfiKeyC4\r
+  0x0A,  //  EfiKeyC5\r
+  0x0B,  //  EfiKeyC6\r
+  0x0D,  //  EfiKeyC7\r
+  0x0E,  //  EfiKeyC8\r
+  0x0F,  //  EfiKeyC9\r
+  0x33,  //  EfiKeyC10\r
+  0x34,  //  EfiKeyC11\r
+  0x32,  //  EfiKeyC12\r
+  0x5C,  //  EfiKeyFour\r
+  0x5D,  //  EfiKeyFive\r
+  0x5E,  //  EfiKeySix\r
+  0x57,  //  EfiKeyPlus\r
+  0x2B,  //  EfiKeyTab\r
+  0x14,  //  EfiKeyD1\r
+  0x1A,  //  EfiKeyD2\r
+  0x08,  //  EfiKeyD3\r
+  0x15,  //  EfiKeyD4\r
+  0x17,  //  EfiKeyD5\r
+  0x1C,  //  EfiKeyD6\r
+  0x18,  //  EfiKeyD7\r
+  0x0C,  //  EfiKeyD8\r
+  0x12,  //  EfiKeyD9\r
+  0x13,  //  EfiKeyD10\r
+  0x2F,  //  EfiKeyD11\r
+  0x30,  //  EfiKeyD12\r
+  0x31,  //  EfiKeyD13\r
+  0x4C,  //  EfiKeyDel\r
+  0x4D,  //  EfiKeyEnd\r
+  0x4E,  //  EfiKeyPgDn\r
+  0x5F,  //  EfiKeySeven\r
+  0x60,  //  EfiKeyEight\r
+  0x61,  //  EfiKeyNine\r
+  0x35,  //  EfiKeyE0\r
+  0x1E,  //  EfiKeyE1\r
+  0x1F,  //  EfiKeyE2\r
+  0x20,  //  EfiKeyE3\r
+  0x21,  //  EfiKeyE4\r
+  0x22,  //  EfiKeyE5\r
+  0x23,  //  EfiKeyE6\r
+  0x24,  //  EfiKeyE7\r
+  0x25,  //  EfiKeyE8\r
+  0x26,  //  EfiKeyE9\r
+  0x27,  //  EfiKeyE10\r
+  0x2D,  //  EfiKeyE11\r
+  0x2E,  //  EfiKeyE12\r
+  0x2A,  //  EfiKeyBackSpace\r
+  0x49,  //  EfiKeyIns\r
+  0x4A,  //  EfiKeyHome\r
+  0x4B,  //  EfiKeyPgUp\r
+  0x53,  //  EfiKeyNLck\r
+  0x54,  //  EfiKeySlash\r
+  0x55,  //  EfiKeyAsterisk\r
+  0x56,  //  EfiKeyMinus\r
+  0x29,  //  EfiKeyEsc\r
+  0x3A,  //  EfiKeyF1\r
+  0x3B,  //  EfiKeyF2\r
+  0x3C,  //  EfiKeyF3\r
+  0x3D,  //  EfiKeyF4\r
+  0x3E,  //  EfiKeyF5\r
+  0x3F,  //  EfiKeyF6\r
+  0x40,  //  EfiKeyF7\r
+  0x41,  //  EfiKeyF8\r
+  0x42,  //  EfiKeyF9\r
+  0x43,  //  EfiKeyF10\r
+  0x44,  //  EfiKeyF11\r
+  0x45,  //  EfiKeyF12\r
+  0x46,  //  EfiKeyPrint\r
+  0x47,  //  EfiKeySLck\r
+  0x48   //  EfiKeyPause\r
+};\r
+\r
 //\r
-// USB Key Code to Efi key mapping table\r
-// Format:<efi scan code>, <unicode without shift>, <unicode with shift>\r
+// Keyboard Layout Modifier to EFI Scan Code convertion table\r
 //\r
 STATIC\r
-UINT8 KeyConvertionTable[USB_KEYCODE_MAX_MAKE][3] = {\r
-  { SCAN_NULL,      'a',      'A' },      // 0x04\r
-  { SCAN_NULL,      'b',      'B' },      // 0x05\r
-  { SCAN_NULL,      'c',      'C' },      // 0x06\r
-  { SCAN_NULL,      'd',      'D' },      // 0x07\r
-  { SCAN_NULL,      'e',      'E' },      // 0x08\r
-  { SCAN_NULL,      'f',      'F' },      // 0x09\r
-  { SCAN_NULL,      'g',      'G' },      // 0x0A\r
-  { SCAN_NULL,      'h',      'H' },      // 0x0B\r
-  { SCAN_NULL,      'i',      'I' },      // 0x0C\r
-  { SCAN_NULL,      'j',      'J' },      // 0x0D\r
-  { SCAN_NULL,      'k',      'K' },      // 0x0E\r
-  { SCAN_NULL,      'l',      'L' },      // 0x0F\r
-  { SCAN_NULL,      'm',      'M' },      // 0x10\r
-  { SCAN_NULL,      'n',      'N' },      // 0x11\r
-  { SCAN_NULL,      'o',      'O' },      // 0x12\r
-  { SCAN_NULL,      'p',      'P' },      // 0x13\r
-  { SCAN_NULL,      'q',      'Q' },      // 0x14\r
-  { SCAN_NULL,      'r',      'R' },      // 0x15\r
-  { SCAN_NULL,      's',      'S' },      // 0x16\r
-  { SCAN_NULL,      't',      'T' },      // 0x17\r
-  { SCAN_NULL,      'u',      'U' },      // 0x18\r
-  { SCAN_NULL,      'v',      'V' },      // 0x19\r
-  { SCAN_NULL,      'w',      'W' },      // 0x1A\r
-  { SCAN_NULL,      'x',      'X' },      // 0x1B\r
-  { SCAN_NULL,      'y',      'Y' },      // 0x1C\r
-  { SCAN_NULL,      'z',      'Z' },      // 0x1D\r
-  { SCAN_NULL,      '1',      '!' },      // 0x1E\r
-  { SCAN_NULL,      '2',      '@' },      // 0x1F\r
-  { SCAN_NULL,      '3',      '#' },      // 0x20\r
-  { SCAN_NULL,      '4',      '$' },      // 0x21\r
-  { SCAN_NULL,      '5',      '%' },      // 0x22\r
-  { SCAN_NULL,      '6',      '^' },      // 0x23\r
-  { SCAN_NULL,      '7',      '&' },      // 0x24\r
-  { SCAN_NULL,      '8',      '*' },      // 0x25\r
-  { SCAN_NULL,      '9',      '(' },      // 0x26\r
-  { SCAN_NULL,      '0',      ')' },      // 0x27\r
-  { SCAN_NULL,      0x0d,     0x0d },     // 0x28   Enter\r
-  { SCAN_ESC,       0x00,     0x00 },     // 0x29   Esc\r
-  { SCAN_NULL,      0x08,     0x08 },     // 0x2A   Backspace\r
-  { SCAN_NULL,      0x09,     0x09 },     // 0x2B   Tab\r
-  { SCAN_NULL,      ' ',      ' ' },      // 0x2C   Spacebar\r
-  { SCAN_NULL,      '-',      '_' },      // 0x2D\r
-  { SCAN_NULL,      '=',      '+' },      // 0x2E\r
-  { SCAN_NULL,      '[',      '{' },      // 0x2F\r
-  { SCAN_NULL,      ']',      '}' },      // 0x30\r
-  { SCAN_NULL,      '\\',     '|' },      // 0x31\r
-  { SCAN_NULL,      '\\',     '|' },      // 0x32  Keyboard US \ and |\r
-  { SCAN_NULL,      ';',      ':' },      // 0x33\r
-  { SCAN_NULL,      '\'',     '"' },      // 0x34\r
-  { SCAN_NULL,      '`',      '~' },      // 0x35  Keyboard Grave Accent and Tlide\r
-  { SCAN_NULL,      ',',      '<' },      // 0x36\r
-  { SCAN_NULL,      '.',      '>' },      // 0x37\r
-  { SCAN_NULL,      '/',      '?' },      // 0x38\r
-  { SCAN_NULL,      0x00,     0x00 },     // 0x39   CapsLock\r
-  { SCAN_F1,        0x00,     0x00 },     // 0x3A\r
-  { SCAN_F2,        0x00,     0x00 },     // 0x3B\r
-  { SCAN_F3,        0x00,     0x00 },     // 0x3C\r
-  { SCAN_F4,        0x00,     0x00 },     // 0x3D\r
-  { SCAN_F5,        0x00,     0x00 },     // 0x3E\r
-  { SCAN_F6,        0x00,     0x00 },     // 0x3F\r
-  { SCAN_F7,        0x00,     0x00 },     // 0x40\r
-  { SCAN_F8,        0x00,     0x00 },     // 0x41\r
-  { SCAN_F9,        0x00,     0x00 },     // 0x42\r
-  { SCAN_F10,       0x00,     0x00 },     // 0x43\r
-  { SCAN_F11,       0x00,     0x00 },     // 0x44   F11\r
-  { SCAN_F12,       0x00,     0x00 },     // 0x45   F12\r
-  { SCAN_NULL,      0x00,     0x00 },     // 0x46   PrintScreen\r
-  { SCAN_NULL,      0x00,     0x00 },     // 0x47   Scroll Lock\r
-  { SCAN_NULL,      0x00,     0x00 },     // 0x48   Pause\r
-  { SCAN_INSERT,    0x00,     0x00 },     // 0x49\r
-  { SCAN_HOME,      0x00,     0x00 },     // 0x4A\r
-  { SCAN_PAGE_UP,   0x00,     0x00 },     // 0x4B\r
-  { SCAN_DELETE,    0x00,     0x00 },     // 0x4C\r
-  { SCAN_END,       0x00,     0x00 },     // 0x4D\r
-  { SCAN_PAGE_DOWN, 0x00,     0x00 },     // 0x4E\r
-  { SCAN_RIGHT,     0x00,     0x00 },     // 0x4F\r
-  { SCAN_LEFT,      0x00,     0x00 },     // 0x50\r
-  { SCAN_DOWN,      0x00,     0x00 },     // 0x51\r
-  { SCAN_UP,        0x00,     0x00 },     // 0x52\r
-  { SCAN_NULL,      0x00,     0x00 },     // 0x53   NumLock\r
-  { SCAN_NULL,      '/',      '/' },      // 0x54\r
-  { SCAN_NULL,      '*',      '*' },      // 0x55\r
-  { SCAN_NULL,      '-',      '-' },      // 0x56\r
-  { SCAN_NULL,      '+',      '+' },      // 0x57\r
-  { SCAN_NULL,      0x0d,     0x0d },     // 0x58\r
-  { SCAN_END,       '1',      '1' },      // 0x59\r
-  { SCAN_DOWN,      '2',      '2' },      // 0x5A\r
-  { SCAN_PAGE_DOWN, '3',      '3' },      // 0x5B\r
-  { SCAN_LEFT,      '4',      '4' },      // 0x5C\r
-  { SCAN_NULL,      '5',      '5' },      // 0x5D\r
-  { SCAN_RIGHT,     '6',      '6' },      // 0x5E\r
-  { SCAN_HOME,      '7',      '7' },      // 0x5F\r
-  { SCAN_UP,        '8',      '8' },      // 0x60\r
-  { SCAN_PAGE_UP,   '9',      '9' },      // 0x61\r
-  { SCAN_INSERT,    '0',      '0' },      // 0x62\r
-  { SCAN_DELETE,    '.',      '.' },      // 0x63\r
-  { SCAN_NULL,      '\\',     '|' },      // 0x64 Keyboard Non-US \ and |\r
-  { SCAN_NULL,      0x00,     0x00 },     // 0x65 Keyboard Application\r
-  { SCAN_NULL,      0x00,     0x00 },     // 0x66 Keyboard Power\r
-  { SCAN_NULL,      '=' ,     '='  },     // 0x67 Keypad =\r
-  { SCAN_F13,       0x00,     0x00 },     // 0x68\r
-  { SCAN_F14,       0x00,     0x00 },     // 0x69\r
-  { SCAN_F15,       0x00,     0x00 },     // 0x6A  \r
-  { SCAN_F16,       0x00,     0x00 },     // 0x6B  \r
-  { SCAN_F17,       0x00,     0x00 },     // 0x6C\r
-  { SCAN_F18,       0x00,     0x00 },     // 0x6D\r
-  { SCAN_F19,       0x00,     0x00 },     // 0x6E\r
-  { SCAN_F20,       0x00,     0x00 },     // 0x6F\r
-  { SCAN_F21,       0x00,     0x00 },     // 0x70\r
-  { SCAN_F22,       0x00,     0x00 },     // 0x71\r
-  { SCAN_F23,       0x00,     0x00 },     // 0x72\r
-  { SCAN_F24,       0x00,     0x00 },     // 0x73\r
-  { SCAN_MUTE,      0x00,     0x00 },     // 0x7F\r
-  { SCAN_VOLUME_UP, 0x00,     0x00 },     // 0x80\r
-  { SCAN_VOLUME_DOWN, 0x00,   0x00 },     // 0x81\r
+UINT8 EfiScanCodeConvertionTable[] = {\r
+  SCAN_NULL,       // EFI_NULL_MODIFIER\r
+  SCAN_NULL,       // EFI_LEFT_CONTROL_MODIFIER\r
+  SCAN_NULL,       // EFI_RIGHT_CONTROL_MODIFIER\r
+  SCAN_NULL,       // EFI_LEFT_ALT_MODIFIER\r
+  SCAN_NULL,       // EFI_RIGHT_ALT_MODIFIER\r
+  SCAN_NULL,       // EFI_ALT_GR_MODIFIER\r
+  SCAN_INSERT,     // EFI_INSERT_MODIFIER\r
+  SCAN_DELETE,     // EFI_DELETE_MODIFIER\r
+  SCAN_PAGE_DOWN,  // EFI_PAGE_DOWN_MODIFIER\r
+  SCAN_PAGE_UP,    // EFI_PAGE_UP_MODIFIER\r
+  SCAN_HOME,       // EFI_HOME_MODIFIER\r
+  SCAN_END,        // EFI_END_MODIFIER\r
+  SCAN_NULL,       // EFI_LEFT_SHIFT_MODIFIER\r
+  SCAN_NULL,       // EFI_RIGHT_SHIFT_MODIFIER\r
+  SCAN_NULL,       // EFI_CAPS_LOCK_MODIFIER\r
+  SCAN_NULL,       // EFI_NUM_LOCK_MODIFIER\r
+  SCAN_LEFT,       // EFI_LEFT_ARROW_MODIFIER\r
+  SCAN_RIGHT,      // EFI_RIGHT_ARROW_MODIFIER\r
+  SCAN_DOWN,       // EFI_DOWN_ARROW_MODIFIER\r
+  SCAN_UP,         // EFI_UP_ARROW_MODIFIER\r
+  SCAN_NULL,       // EFI_NS_KEY_MODIFIER\r
+  SCAN_NULL,       // EFI_NS_KEY_DEPENDENCY_MODIFIER\r
+  SCAN_F1,         // EFI_FUNCTION_KEY_ONE_MODIFIER\r
+  SCAN_F2,         // EFI_FUNCTION_KEY_TWO_MODIFIER\r
+  SCAN_F3,         // EFI_FUNCTION_KEY_THREE_MODIFIER\r
+  SCAN_F4,         // EFI_FUNCTION_KEY_FOUR_MODIFIER\r
+  SCAN_F5,         // EFI_FUNCTION_KEY_FIVE_MODIFIER\r
+  SCAN_F6,         // EFI_FUNCTION_KEY_SIX_MODIFIER\r
+  SCAN_F7,         // EFI_FUNCTION_KEY_SEVEN_MODIFIER\r
+  SCAN_F8,         // EFI_FUNCTION_KEY_EIGHT_MODIFIER\r
+  SCAN_F9,         // EFI_FUNCTION_KEY_NINE_MODIFIER\r
+  SCAN_F10,        // EFI_FUNCTION_KEY_TEN_MODIFIER\r
+  SCAN_F11,        // EFI_FUNCTION_KEY_ELEVEN_MODIFIER\r
+  SCAN_F12,        // EFI_FUNCTION_KEY_TWELVE_MODIFIER\r
 };\r
 \r
+EFI_GUID  mKeyboardLayoutEventGuid = EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID;\r
+\r
+\r
 STATIC KB_MODIFIER  KB_Mod[8] = {\r
   { MOD_CONTROL_L,  0xe0 }, // 11100000\r
   { MOD_CONTROL_R,  0xe4 }, // 11100100\r
@@ -200,6 +387,387 @@ IsUSBKeyboard (
 }\r
 \r
 \r
+EFI_HII_KEYBOARD_LAYOUT *\r
+GetCurrentKeyboardLayout (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Get current keyboard layout from HII database.\r
+\r
+  Arguments:\r
+    None.\r
+\r
+  Returns:\r
+    Pointer to EFI_HII_KEYBOARD_LAYOUT.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_HII_DATABASE_PROTOCOL *HiiDatabase;\r
+  EFI_HII_KEYBOARD_LAYOUT   *KeyboardLayout;\r
+  UINT16                    Length;\r
+\r
+  //\r
+  // Locate Hii database protocol\r
+  //\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiHiiDatabaseProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &HiiDatabase\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Get current keyboard layout from HII database\r
+  //\r
+  Length = 0;\r
+  KeyboardLayout = NULL;\r
+  Status = HiiDatabase->GetKeyboardLayout (\r
+                          HiiDatabase,\r
+                          NULL,\r
+                          &Length,\r
+                          KeyboardLayout\r
+                          );\r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    KeyboardLayout = AllocatePool (Length);\r
+    ASSERT (KeyboardLayout != NULL);\r
+\r
+    Status = HiiDatabase->GetKeyboardLayout (\r
+                            HiiDatabase,\r
+                            NULL,\r
+                            &Length,\r
+                            KeyboardLayout\r
+                            );\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->FreePool (KeyboardLayout);\r
+      KeyboardLayout = NULL;\r
+    }\r
+  }\r
+\r
+  return KeyboardLayout;\r
+}\r
+\r
+EFI_KEY_DESCRIPTOR *\r
+GetKeyDescriptor (\r
+  IN USB_KB_DEV        *UsbKeyboardDevice,\r
+  IN UINT8             ScanCode\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Find Key Descriptor in KeyConvertionTable given its scan code.\r
+\r
+  Arguments:\r
+    UsbKeyboardDevice  -  The USB_KB_DEV instance.\r
+    ScanCode           -  USB scan code.\r
+\r
+  Returns:\r
+    The Key descriptor in KeyConvertionTable.\r
+\r
+--*/\r
+{\r
+  UINT8  Index;\r
+\r
+  if (((ScanCode > 0x65) && (ScanCode < 0xe0)) || (ScanCode > 0xe7)) {\r
+    return NULL;\r
+  }\r
+\r
+  if (ScanCode <= 0x65) {\r
+    Index = (UINT8) (ScanCode - 4);\r
+  } else {\r
+    Index = (UINT8) (ScanCode - 0xe0 + USB_KEYCODE_MAX_MAKE);\r
+  }\r
+\r
+  return &UsbKeyboardDevice->KeyConvertionTable[Index];\r
+}\r
+\r
+USB_NS_KEY *\r
+FindUsbNsKey (\r
+  IN USB_KB_DEV          *UsbKeyboardDevice,\r
+  IN EFI_KEY_DESCRIPTOR  *KeyDescriptor\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Find Non-Spacing key for given KeyDescriptor.\r
+\r
+  Arguments:\r
+    UsbKeyboardDevice  -  The USB_KB_DEV instance.\r
+    KeyDescriptor      -  Key descriptor.\r
+\r
+  Returns:\r
+    The Non-Spacing key.\r
+\r
+--*/\r
+{\r
+  LIST_ENTRY      *Link;\r
+  USB_NS_KEY      *UsbNsKey;\r
+\r
+  Link = GetFirstNode (&UsbKeyboardDevice->NsKeyList);\r
+  while (!IsNull (&UsbKeyboardDevice->NsKeyList, Link)) {\r
+    UsbNsKey = USB_NS_KEY_FORM_FROM_LINK (Link);\r
+\r
+    if (UsbNsKey->NsKey[0].Key == KeyDescriptor->Key) {\r
+      return UsbNsKey;\r
+    }\r
+\r
+    Link = GetNextNode (&UsbKeyboardDevice->NsKeyList, Link);\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+EFI_KEY_DESCRIPTOR *\r
+FindPhysicalKey (\r
+  IN USB_NS_KEY          *UsbNsKey,\r
+  IN EFI_KEY_DESCRIPTOR  *KeyDescriptor\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Find physical key definition for a given Key stroke.\r
+\r
+  Arguments:\r
+    UsbNsKey        -  The Non-Spacing key information.\r
+    KeyDescriptor   -  The key stroke.\r
+\r
+  Returns:\r
+    The physical key definition.\r
+\r
+--*/\r
+{\r
+  UINTN               Index;\r
+  EFI_KEY_DESCRIPTOR  *PhysicalKey;\r
+\r
+  PhysicalKey = &UsbNsKey->NsKey[1];\r
+  for (Index = 0; Index < UsbNsKey->KeyCount; Index++) {\r
+    if (KeyDescriptor->Key == PhysicalKey->Key) {\r
+      return PhysicalKey;\r
+    }\r
+\r
+    PhysicalKey++;\r
+  }\r
+\r
+  //\r
+  // No children definition matched, return original key\r
+  //\r
+  return KeyDescriptor;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+SetKeyboardLayoutEvent (\r
+  EFI_EVENT                  Event,\r
+  VOID                       *Context\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    The notification function for SET_KEYBOARD_LAYOUT_EVENT.\r
+\r
+  Arguments:\r
+\r
+  Returns:\r
+\r
+--*/\r
+{\r
+  USB_KB_DEV                *UsbKeyboardDevice;\r
+  EFI_HII_KEYBOARD_LAYOUT   *KeyboardLayout;\r
+  EFI_KEY_DESCRIPTOR        TempKey;\r
+  EFI_KEY_DESCRIPTOR        *KeyDescriptor;\r
+  EFI_KEY_DESCRIPTOR        *TableEntry;\r
+  EFI_KEY_DESCRIPTOR        *NsKey;\r
+  USB_NS_KEY                *UsbNsKey;\r
+  UINTN                     Index;\r
+  UINTN                     Index2;\r
+  UINTN                     KeyCount;\r
+  UINT8                     ScanCode;\r
+\r
+  UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
+\r
+  //\r
+  // Try to get current Keyboard Layout from HII database\r
+  //\r
+  KeyboardLayout = GetCurrentKeyboardLayout ();\r
+  if (KeyboardLayout == NULL) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Allocate resource for KeyConvertionTable\r
+  //\r
+  ReleaseKeyboardLayoutResources (UsbKeyboardDevice);\r
+  UsbKeyboardDevice->KeyConvertionTable = AllocateZeroPool ((USB_KEYCODE_MAX_MAKE + 8) * sizeof (EFI_KEY_DESCRIPTOR));\r
+  ASSERT (UsbKeyboardDevice->KeyConvertionTable != NULL);\r
+\r
+  KeyDescriptor = (EFI_KEY_DESCRIPTOR *) (((UINT8 *) KeyboardLayout) + sizeof (EFI_HII_KEYBOARD_LAYOUT));\r
+  for (Index = 0; Index < KeyboardLayout->DescriptorCount; Index++) {\r
+    //\r
+    // Copy from HII keyboard layout package binary for alignment\r
+    //\r
+    CopyMem (&TempKey, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR));\r
+\r
+    //\r
+    // Fill the key into KeyConvertionTable (which use USB Scan Code as index)\r
+    //\r
+    ScanCode = UsbScanCodeConvertionTable [(UINT8) (TempKey.Key)];\r
+    TableEntry = GetKeyDescriptor (UsbKeyboardDevice, ScanCode);\r
+    CopyMem (TableEntry, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR));\r
+\r
+    if (TempKey.Modifier == EFI_NS_KEY_MODIFIER) {\r
+      //\r
+      // Non-spacing key\r
+      //\r
+      UsbNsKey = AllocatePool (sizeof (USB_NS_KEY));\r
+      ASSERT (UsbNsKey != NULL);\r
+\r
+      //\r
+      // Search for sequential children physical key definitions\r
+      //\r
+      KeyCount = 0;\r
+      NsKey = KeyDescriptor + 1;\r
+      for (Index2 = Index + 1; Index2 < KeyboardLayout->DescriptorCount; Index2++) {\r
+        CopyMem (&TempKey, NsKey, sizeof (EFI_KEY_DESCRIPTOR));\r
+        if (TempKey.Modifier & EFI_NS_KEY_DEPENDENCY_MODIFIER) {\r
+          KeyCount++;\r
+        } else {\r
+          break;\r
+        }\r
+        NsKey++;\r
+      }\r
+\r
+      UsbNsKey->Signature = USB_NS_KEY_SIGNATURE;\r
+      UsbNsKey->KeyCount = KeyCount;\r
+      UsbNsKey->NsKey = AllocateCopyPool (\r
+                          (KeyCount + 1) * sizeof (EFI_KEY_DESCRIPTOR),\r
+                          KeyDescriptor\r
+                          );\r
+      InsertTailList (&UsbKeyboardDevice->NsKeyList, &UsbNsKey->Link);\r
+\r
+      //\r
+      // Skip over the child physical keys\r
+      //\r
+      Index += KeyCount;\r
+      KeyDescriptor += KeyCount;\r
+    }\r
+\r
+    KeyDescriptor++;\r
+  }\r
+\r
+  //\r
+  // There are two EfiKeyEnter, duplicate its Key Descriptor\r
+  //\r
+  TableEntry = GetKeyDescriptor (UsbKeyboardDevice, 0x58);\r
+  KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, 0x28);\r
+  CopyMem (TableEntry, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR));\r
+\r
+  gBS->FreePool (KeyboardLayout);\r
+}\r
+\r
+VOID\r
+ReleaseKeyboardLayoutResources (\r
+  IN USB_KB_DEV              *UsbKeyboardDevice\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Destroy resources for Keyboard layout.\r
+\r
+  Arguments:\r
+    UsbKeyboardDevice  -  The USB_KB_DEV instance.\r
+\r
+  Returns:\r
+    None.\r
+\r
+--*/\r
+{\r
+  USB_NS_KEY      *UsbNsKey;\r
+  LIST_ENTRY      *Link;\r
+\r
+  SafeFreePool (UsbKeyboardDevice->KeyConvertionTable);\r
+  UsbKeyboardDevice->KeyConvertionTable = NULL;\r
+\r
+  while (!IsListEmpty (&UsbKeyboardDevice->NsKeyList)) {\r
+    Link = GetFirstNode (&UsbKeyboardDevice->NsKeyList);\r
+    UsbNsKey = USB_NS_KEY_FORM_FROM_LINK (Link);\r
+    RemoveEntryList (&UsbNsKey->Link);\r
+\r
+    gBS->FreePool (UsbNsKey->NsKey);\r
+    gBS->FreePool (UsbNsKey);\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+InitKeyboardLayout (\r
+  IN USB_KB_DEV   *UsbKeyboardDevice\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Initialize USB Keyboard layout.\r
+\r
+  Arguments:\r
+    UsbKeyboardDevice    The USB_KB_DEV instance.\r
+\r
+  Returns:\r
+    EFI_SUCCESS  - Success\r
+    Other        - Keyboard layout initial failed.\r
+--*/\r
+{\r
+  EFI_HII_KEYBOARD_LAYOUT   *KeyboardLayout;\r
+  EFI_STATUS                Status;\r
+\r
+  UsbKeyboardDevice->KeyConvertionTable = AllocateZeroPool ((USB_KEYCODE_MAX_MAKE + 8) * sizeof (EFI_KEY_DESCRIPTOR));\r
+  ASSERT (UsbKeyboardDevice->KeyConvertionTable != NULL);\r
+\r
+  InitializeListHead (&UsbKeyboardDevice->NsKeyList);\r
+  UsbKeyboardDevice->CurrentNsKey = NULL;\r
+  UsbKeyboardDevice->KeyboardLayoutEvent = NULL;\r
+\r
+  //\r
+  // Register SET_KEYBOARD_LAYOUT_EVENT notification\r
+  //\r
+  Status = gBS->CreateEventEx (\r
+                  EFI_EVENT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  SetKeyboardLayoutEvent,\r
+                  UsbKeyboardDevice,\r
+                  &mKeyboardLayoutEventGuid,\r
+                  &UsbKeyboardDevice->KeyboardLayoutEvent\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Try to get current keyboard layout from HII database\r
+  //\r
+  KeyboardLayout = GetCurrentKeyboardLayout ();\r
+  if (KeyboardLayout != NULL) {\r
+    //\r
+    // Force to initialize the keyboard layout\r
+    //\r
+    gBS->SignalEvent (UsbKeyboardDevice->KeyboardLayoutEvent);\r
+  } else {\r
+    if (FeaturePcdGet (PcdDisableDefaultKeyboardLayoutInUsbKbDriver)) {\r
+      return EFI_NOT_READY;\r
+    } else {\r
+\r
+      //\r
+      // Fail to get keyboard layout from HII database,\r
+      // use default keyboard layout\r
+      //\r
+      LoadDefaultKeyboardLayout (UsbKeyboardDevice);\r
+    }\r
+  }\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
 \r
 /**\r
   Initialize USB Keyboard device and all private data structures.\r
@@ -304,14 +872,18 @@ InitUSBKeyboard (
   \r
   UsbKeyboardDevice->LeftCtrlOn   = 0;\r
   UsbKeyboardDevice->LeftAltOn    = 0;\r
-  UsbKeyboardDevice->LeftShiftOn  = 0;  \r
-  UsbKeyboardDevice->LeftLogoOn   = 0;  \r
+  UsbKeyboardDevice->LeftShiftOn  = 0;\r
+  UsbKeyboardDevice->LeftLogoOn   = 0;\r
   UsbKeyboardDevice->RightCtrlOn  = 0;\r
   UsbKeyboardDevice->RightAltOn   = 0;\r
-  UsbKeyboardDevice->RightShiftOn = 0;  \r
-  UsbKeyboardDevice->RightLogoOn  = 0;  \r
+  UsbKeyboardDevice->RightShiftOn = 0;\r
+  UsbKeyboardDevice->RightLogoOn  = 0;\r
   UsbKeyboardDevice->MenuKeyOn    = 0;\r
-  UsbKeyboardDevice->SysReqOn     = 0;  \r
+  UsbKeyboardDevice->SysReqOn     = 0;\r
+\r
+  UsbKeyboardDevice->AltGrOn      = 0;\r
+\r
+  UsbKeyboardDevice->CurrentNsKey = NULL;\r
 \r
   //\r
   // Sync the initial state of lights\r
@@ -390,6 +962,7 @@ KeyboardHandler (
   USB_KEY             UsbKey;\r
   UINT8               NewRepeatKey;\r
   UINT32              UsbStatus;\r
+  EFI_KEY_DESCRIPTOR  *KeyDescriptor;\r
 \r
   ASSERT (Context);\r
 \r
@@ -573,7 +1146,8 @@ KeyboardHandler (
       //\r
       // NumLock pressed or CapsLock pressed\r
       //\r
-      if (CurKeyCodeBuffer[Index] == 0x53 || CurKeyCodeBuffer[Index] == 0x39) {\r
+      KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, CurKeyCodeBuffer[Index]);\r
+      if (KeyDescriptor->Modifier == EFI_NUM_LOCK_MODIFIER || KeyDescriptor->Modifier == EFI_CAPS_LOCK_MODIFIER) {\r
         UsbKeyboardDevice->RepeatKey = 0;\r
       } else {\r
         NewRepeatKey = CurKeyCodeBuffer[Index];\r
@@ -602,10 +1176,12 @@ KeyboardHandler (
   while (Index != SavedTail) {\r
     RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);\r
 \r
-    switch (UsbKey.KeyCode) {\r
+    KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode);\r
 \r
-    case 0xe0:\r
-    case 0xe4:\r
+    switch (KeyDescriptor->Modifier) {\r
+\r
+    case EFI_LEFT_CONTROL_MODIFIER:\r
+    case EFI_RIGHT_CONTROL_MODIFIER:\r
       if (UsbKey.Down) {\r
         UsbKeyboardDevice->CtrlOn = 1;\r
       } else {\r
@@ -613,8 +1189,8 @@ KeyboardHandler (
       }\r
       break;\r
 \r
-    case 0xe2:\r
-    case 0xe6:\r
+    case EFI_LEFT_ALT_MODIFIER:\r
+    case EFI_RIGHT_ALT_MODIFIER:\r
       if (UsbKey.Down) {\r
         UsbKeyboardDevice->AltOn = 1;\r
       } else {\r
@@ -622,11 +1198,18 @@ KeyboardHandler (
       }\r
       break;\r
 \r
+    case EFI_ALT_GR_MODIFIER:\r
+      if (UsbKey.Down) {\r
+        UsbKeyboardDevice->AltGrOn = 1;\r
+      } else {\r
+        UsbKeyboardDevice->AltGrOn = 0;\r
+      }\r
+      break;\r
+\r
     //\r
     // Del Key Code\r
     //\r
-    case 0x4c:\r
-    case 0x63:\r
+    case EFI_DELETE_MODIFIER:\r
       if (UsbKey.Down) {\r
         if (UsbKeyboardDevice->CtrlOn && UsbKeyboardDevice->AltOn) {\r
           gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
@@ -688,7 +1271,8 @@ USBParseKey (
   OUT     UINT8       *KeyChar\r
   )\r
 {\r
-  USB_KEY UsbKey;\r
+  USB_KEY             UsbKey;\r
+  EFI_KEY_DESCRIPTOR  *KeyDescriptor;\r
 \r
   *KeyChar = 0;\r
 \r
@@ -698,17 +1282,18 @@ USBParseKey (
     //\r
     RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);\r
 \r
+    KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode);\r
     if (!UsbKey.Down) {\r
-      switch (UsbKey.KeyCode) {\r
+      switch (KeyDescriptor->Modifier) {\r
 \r
       //\r
       // CTRL release\r
       //\r
-      case 0xe0:\r
+      case EFI_LEFT_CONTROL_MODIFIER:\r
         UsbKeyboardDevice->LeftCtrlOn = 0;\r
         UsbKeyboardDevice->CtrlOn = 0;\r
         break;\r
-      case 0xe4:\r
+      case EFI_RIGHT_CONTROL_MODIFIER:\r
         UsbKeyboardDevice->RightCtrlOn = 0;\r
         UsbKeyboardDevice->CtrlOn = 0;\r
         break;\r
@@ -716,11 +1301,11 @@ USBParseKey (
       //\r
       // Shift release\r
       //\r
-      case 0xe1:\r
+      case EFI_LEFT_SHIFT_MODIFIER:\r
         UsbKeyboardDevice->LeftShiftOn = 0;\r
         UsbKeyboardDevice->ShiftOn = 0;\r
         break;\r
-      case 0xe5:\r
+      case EFI_RIGHT_SHIFT_MODIFIER:\r
         UsbKeyboardDevice->RightShiftOn = 0;\r
         UsbKeyboardDevice->ShiftOn = 0;\r
         break;\r
@@ -728,38 +1313,50 @@ USBParseKey (
       //\r
       // Alt release\r
       //\r
-      case 0xe2:\r
+      case EFI_LEFT_ALT_MODIFIER:\r
         UsbKeyboardDevice->LeftAltOn = 0;\r
         UsbKeyboardDevice->AltOn = 0;\r
         break;\r
-      case 0xe6:\r
+      case EFI_RIGHT_ALT_MODIFIER:\r
         UsbKeyboardDevice->RightAltOn = 0;\r
         UsbKeyboardDevice->AltOn = 0;\r
         break;\r
 \r
       //\r
-      // Logo release\r
+      // Left Logo release\r
       //\r
-     case 0xe3:\r
+      case EFI_LEFT_LOGO_MODIFIER:\r
         UsbKeyboardDevice->LeftLogoOn = 0;\r
         break;\r
-      case 0xe7:\r
+\r
+      //\r
+      // Right Logo release\r
+      //\r
+      case EFI_RIGHT_LOGO_MODIFIER:\r
         UsbKeyboardDevice->RightLogoOn = 0;\r
         break;\r
 \r
       //\r
-      // Menu key (App/Apps) release\r
+      // Menu key release\r
       //\r
-      case 0x65:\r
+      case EFI_MENU_MODIFIER:\r
         UsbKeyboardDevice->MenuKeyOn = 0;\r
         break;\r
 \r
       //\r
       // SysReq release\r
       //\r
-      case 0x46:\r
+      case EFI_SYS_REQUEST_MODIFIER:\r
         UsbKeyboardDevice->SysReqOn = 0;\r
         break;\r
+\r
+      //\r
+      // AltGr release\r
+      //\r
+      case EFI_ALT_GR_MODIFIER:\r
+        UsbKeyboardDevice->AltGrOn = 0;\r
+        break;\r
+\r
       default:\r
         break;\r
       }\r
@@ -770,14 +1367,17 @@ USBParseKey (
     //\r
     // Analyzes key pressing situation\r
     //\r
-    switch (UsbKey.KeyCode) {\r
+    switch (KeyDescriptor->Modifier) {\r
 \r
-    case 0xe0:\r
+    //\r
+    // CTRL press\r
+    //\r
+    case EFI_LEFT_CONTROL_MODIFIER:\r
       UsbKeyboardDevice->LeftCtrlOn = 1;\r
       UsbKeyboardDevice->CtrlOn = 1;\r
-      continue;      \r
+      continue;\r
       break;\r
-    case 0xe4:\r
+    case EFI_RIGHT_CONTROL_MODIFIER:\r
       UsbKeyboardDevice->RightCtrlOn = 1;\r
       UsbKeyboardDevice->CtrlOn = 1;\r
       continue;\r
@@ -786,13 +1386,13 @@ USBParseKey (
     //\r
     // Shift press\r
     //\r
-    case 0xe1:\r
+    case EFI_LEFT_SHIFT_MODIFIER:\r
       UsbKeyboardDevice->LeftShiftOn = 1;\r
       UsbKeyboardDevice->ShiftOn = 1;\r
       continue;\r
       break;\r
-    case 0xe5:\r
-      UsbKeyboardDevice->RightShiftOn = 1;      \r
+    case EFI_RIGHT_SHIFT_MODIFIER:\r
+      UsbKeyboardDevice->RightShiftOn = 1;\r
       UsbKeyboardDevice->ShiftOn = 1;\r
       continue;\r
       break;\r
@@ -800,46 +1400,54 @@ USBParseKey (
     //\r
     // Alt press\r
     //\r
-    case 0xe2:\r
+    case EFI_LEFT_ALT_MODIFIER:\r
       UsbKeyboardDevice->LeftAltOn = 1;\r
       UsbKeyboardDevice->AltOn = 1;\r
       continue;\r
       break;\r
-    case 0xe6:\r
-      UsbKeyboardDevice->RightAltOn = 1;      \r
+    case EFI_RIGHT_ALT_MODIFIER:\r
+      UsbKeyboardDevice->RightAltOn = 1;\r
       UsbKeyboardDevice->AltOn = 1;\r
       continue;\r
       break;\r
 \r
     //\r
-    // Logo press\r
+    // Left Logo press\r
     //\r
-    case 0xe3:\r
+    case EFI_LEFT_LOGO_MODIFIER:\r
       UsbKeyboardDevice->LeftLogoOn = 1;\r
-      continue;      \r
       break;\r
-    case 0xe7:\r
+\r
+    //\r
+    // Right Logo press\r
+    //\r
+    case EFI_RIGHT_LOGO_MODIFIER:\r
       UsbKeyboardDevice->RightLogoOn = 1;\r
-      continue;\r
       break;\r
 \r
     //\r
-    // Menu key (App/Apps) press\r
+    // Menu key press\r
     //\r
-    case 0x65:\r
+    case EFI_MENU_MODIFIER:\r
       UsbKeyboardDevice->MenuKeyOn = 1;\r
-      continue;      \r
       break;\r
 \r
     //\r
     // SysReq press\r
     //\r
-    case 0x46:\r
+    case EFI_SYS_REQUEST_MODIFIER:\r
       UsbKeyboardDevice->SysReqOn = 1;\r
-      continue;      \r
+      continue;\r
+      break;\r
+\r
+    //\r
+    // AltGr press\r
+    //\r
+    case EFI_ALT_GR_MODIFIER:\r
+      UsbKeyboardDevice->AltGrOn = 1;\r
       break;\r
 \r
-    case 0x53:\r
+    case EFI_NUM_LOCK_MODIFIER:\r
       UsbKeyboardDevice->NumLockOn ^= 1;\r
       //\r
       // Turn on the NumLock light on KB\r
@@ -848,7 +1456,7 @@ USBParseKey (
       continue;\r
       break;\r
 \r
-    case 0x39:\r
+    case EFI_CAPS_LOCK_MODIFIER:\r
       UsbKeyboardDevice->CapsOn ^= 1;\r
       //\r
       // Turn on the CapsLock light on KB\r
@@ -857,7 +1465,7 @@ USBParseKey (
       continue;\r
       break;\r
 \r
-    case 0x47:\r
+    case EFI_SCROLL_LOCK_MODIFIER:\r
       UsbKeyboardDevice->ScrollOn ^= 1;\r
       //\r
       // Turn on the ScrollLock light on KB\r
@@ -867,22 +1475,17 @@ USBParseKey (
       break;\r
 \r
     //\r
-    // PrintScreen,Pause,Application,Power\r
-    // keys are not valid EFI key\r
-    //\r
-\r
-    //\r
-    // PrintScreen/SysRq key and Application key\r
-    // Should be handled by UEFI2.1 compliant code\r
-\r
-    case 0x48:\r
-    //\r
-    // fall through\r
-    //\r
-    case 0x66:\r
-    //\r
-    // fall through\r
+    // F11,F12,PrintScreen,Pause/Break\r
+    // could not be retrieved via SimpleTxtInEx protocol\r
     //\r
+    case EFI_FUNCTION_KEY_ELEVEN_MODIFIER:\r
+    case EFI_FUNCTION_KEY_TWELVE_MODIFIER:\r
+    case EFI_PRINT_MODIFIER:\r
+    case EFI_PAUSE_MODIFIER:\r
+    case EFI_BREAK_MODIFIER:\r
+      //\r
+      // fall through\r
+      //\r
       continue;\r
       break;\r
 \r
@@ -893,7 +1496,7 @@ USBParseKey (
     //\r
     // When encountered Del Key...\r
     //\r
-    if (UsbKey.KeyCode == 0x4c || UsbKey.KeyCode == 0x63) {\r
+    if (KeyDescriptor->Modifier == EFI_DELETE_MODIFIER) {\r
       if (UsbKeyboardDevice->CtrlOn && UsbKeyboardDevice->AltOn) {\r
         gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
       }\r
@@ -904,7 +1507,6 @@ USBParseKey (
   }\r
 \r
   return EFI_NOT_READY;\r
-\r
 }\r
 \r
 \r
@@ -929,7 +1531,8 @@ USBKeyCodeToEFIScanCode (
   OUT EFI_INPUT_KEY   *Key\r
   )\r
 {\r
-  UINT8 Index;\r
+  UINT8               Index;\r
+  EFI_KEY_DESCRIPTOR  *KeyDescriptor;\r
 \r
   if (!USBKBD_VALID_KEYCODE (KeyChar)) {\r
     return EFI_NOT_READY;\r
@@ -944,68 +1547,100 @@ USBKeyCodeToEFIScanCode (
     return EFI_NOT_READY;\r
   }\r
 \r
+  KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, KeyChar);\r
+\r
   //\r
-  // Undefined entries from 0x74 to 0x7E\r
+  // Check for Non-spacing key\r
   //\r
-  if (KeyChar > USB_KEYCODE_MAX_MAKE) {\r
-    Index = (UINT8) (Index - 11);\r
+  if (KeyDescriptor->Modifier == EFI_NS_KEY_MODIFIER) {\r
+    UsbKeyboardDevice->CurrentNsKey = FindUsbNsKey (UsbKeyboardDevice, KeyDescriptor);\r
+    return EFI_NOT_READY;\r
   }\r
 \r
-  Key->ScanCode = KeyConvertionTable[Index][0];\r
+  //\r
+  // Check whether this keystroke follows a Non-spacing key\r
+  //\r
+  if (UsbKeyboardDevice->CurrentNsKey != NULL) {\r
+    KeyDescriptor = FindPhysicalKey (UsbKeyboardDevice->CurrentNsKey, KeyDescriptor);\r
+    UsbKeyboardDevice->CurrentNsKey = NULL;\r
+  }\r
 \r
-  if (UsbKeyboardDevice->ShiftOn) {\r
+  Key->ScanCode = EfiScanCodeConvertionTable[KeyDescriptor->Modifier];\r
+  Key->UnicodeChar = KeyDescriptor->Unicode;\r
 \r
-    Key->UnicodeChar = KeyConvertionTable[Index][2];\r
-    //\r
-    // Need not return associated shift state if a class of printable characters that\r
-    // are normally adjusted by shift modifiers. e.g. Shift Key + 'f' key = 'F'\r
-    //\r
-    if (Key->UnicodeChar >= 'A' && Key->UnicodeChar <= 'Z') {\r
-      UsbKeyboardDevice->LeftShiftOn = 0;\r
-      UsbKeyboardDevice->RightShiftOn = 0;\r
-    }\r
+  if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_STANDARD_SHIFT) {\r
+    if (UsbKeyboardDevice->ShiftOn) {\r
+      Key->UnicodeChar = KeyDescriptor->ShiftedUnicode;\r
 \r
-  } else {\r
+      //\r
+      // Need not return associated shift state if a class of printable characters that\r
+      // are normally adjusted by shift modifiers. e.g. Shift Key + 'f' key = 'F'\r
+      //\r
+      if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) {\r
+        UsbKeyboardDevice->LeftShiftOn = 0;\r
+        UsbKeyboardDevice->RightShiftOn = 0;\r
+      }\r
+\r
+      if (UsbKeyboardDevice->AltGrOn) {\r
+        Key->UnicodeChar = KeyDescriptor->ShiftedAltGrUnicode;\r
+      }\r
+    } else {\r
+      //\r
+      // Shift off\r
+      //\r
+      Key->UnicodeChar = KeyDescriptor->Unicode;\r
 \r
-    Key->UnicodeChar = KeyConvertionTable[Index][1];\r
+      if (UsbKeyboardDevice->AltGrOn) {\r
+        Key->UnicodeChar = KeyDescriptor->AltGrUnicode;\r
+      }\r
+    }\r
   }\r
 \r
-  if (UsbKeyboardDevice->CapsOn) {\r
+  if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) {\r
+    if (UsbKeyboardDevice->CapsOn) {\r
 \r
-    if (Key->UnicodeChar >= 'a' && Key->UnicodeChar <= 'z') {\r
+      if (Key->UnicodeChar == KeyDescriptor->Unicode) {\r
 \r
-      Key->UnicodeChar = KeyConvertionTable[Index][2];\r
+        Key->UnicodeChar = KeyDescriptor->ShiftedUnicode;\r
 \r
-    } else if (Key->UnicodeChar >= 'A' && Key->UnicodeChar <= 'Z') {\r
+      } else if (Key->UnicodeChar == KeyDescriptor->ShiftedUnicode) {\r
 \r
-      Key->UnicodeChar = KeyConvertionTable[Index][1];\r
+        Key->UnicodeChar = KeyDescriptor->Unicode;\r
 \r
+      }\r
     }\r
   }\r
+\r
   //\r
   // Translate the CTRL-Alpha characters to their corresponding control value  (ctrl-a = 0x0001 through ctrl-Z = 0x001A)\r
   //\r
   if (UsbKeyboardDevice->CtrlOn) {\r
     if (Key->UnicodeChar >= 'a' && Key->UnicodeChar <= 'z') {\r
-      Key->UnicodeChar = (UINT16) (Key->UnicodeChar - 'a' + 1);\r
+      Key->UnicodeChar = (UINT8) (Key->UnicodeChar - 'a' + 1);\r
     } else if (Key->UnicodeChar >= 'A' && Key->UnicodeChar <= 'Z') {\r
-      Key->UnicodeChar = (UINT16) (Key->UnicodeChar - 'A' + 1);\r
+      Key->UnicodeChar = (UINT8) (Key->UnicodeChar - 'A' + 1);\r
     }\r
   }\r
-  \r
-  \r
-  if (KeyChar >= 0x59 && KeyChar <= 0x63) {\r
+\r
+  if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_NUM_LOCK) {\r
 \r
     if (UsbKeyboardDevice->NumLockOn && !UsbKeyboardDevice->ShiftOn) {\r
 \r
       Key->ScanCode = SCAN_NULL;\r
 \r
     } else {\r
-\r
       Key->UnicodeChar = 0x00;\r
     }\r
   }\r
 \r
+  //\r
+  // Translate Unicode 0x1B (ESC) to EFI Scan Code\r
+  //\r
+  if (Key->UnicodeChar == 0x1B && Key->ScanCode == SCAN_NULL) {\r
+    Key->ScanCode = SCAN_ESC;\r
+    Key->UnicodeChar = 0x00;\r
+  }\r
+\r
   if (Key->UnicodeChar == 0 && Key->ScanCode == SCAN_NULL) {\r
     return EFI_NOT_READY;\r
   }\r
@@ -1043,7 +1678,7 @@ USBKeyCodeToEFIScanCode (
   }\r
   if (UsbKeyboardDevice->SysReqOn == 1) {\r
     UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_SYS_REQ_PRESSED;\r
-  }  \r
+  }\r
 \r
   if (UsbKeyboardDevice->ScrollOn == 1) {\r
     UsbKeyboardDevice->KeyState.KeyToggleState |= EFI_SCROLL_LOCK_ACTIVE;\r
index 9a8cb0f493d67e36d18a44e212905d9ae1384b12..2e7ccf78880ec8caab27c185db34b0f08b6100c7 100644 (file)
@@ -36,6 +36,16 @@ InitUSBKeyboard (
   IN USB_KB_DEV   *UsbKeyboardDevice\r
   );\r
 \r
+EFI_STATUS\r
+InitKeyboardLayout (\r
+  IN USB_KB_DEV   *UsbKeyboardDevice\r
+  );\r
+\r
+VOID\r
+ReleaseKeyboardLayoutResources (\r
+  USB_KB_DEV  *UsbKeyboardDevice\r
+  );\r
+\r
 EFI_STATUS\r
 EFIAPI\r
 KeyboardHandler (\r
index ea709c5aa1bbb0b362784300d796860419a193ce..8e9bb040dd8ef67c5c05ecce93c1785b61f1b716 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHardwareErrorRecord|FALSE|BOOLEAN|0x00010045\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdUgaConsumeSupport|TRUE|BOOLEAN|0x00010046\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|FALSE|BOOLEAN|0x00010047\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol|TRUE|BOOLEAN|0x00010100\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDisableDefaultKeyboardLayoutInUsbKbDriver|FALSE|BOOLEAN|0x00010200\r
 \r
 [PcdsFixedAtBuild.common]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPcdCallBackNumberPerPcdEntry|0x08|UINT32|0x0001000f\r
index 7f3155b2c2afd0181b082e3b14bb844f79dbb2a5..47da390f17e001cdc13f204156ae3db8e6568213 100644 (file)
@@ -931,6 +931,8 @@ Returns:
       //\r
       // Timeout or user press enter to continue\r
       //\r
+      gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
+      gST->ConOut->ClearScreen (gST->ConOut);\r
       goto Exit;\r
     }\r
   }\r
index 3f35ed9005e27405399beb58e09ae6da29bdc13e..8decc76102094fbf3f8f14c719da9543e8afc7fa 100644 (file)
@@ -27,189 +27,6 @@ Revision History
 \r
 #ifndef DISABLE_UNUSED_HII_PROTOCOLS\r
 \r
-STATIC\r
-CHAR16\r
-NibbleToHexCharPrivate (\r
-  IN UINT8                         Nibble\r
-  )\r
-/*++\r
-\r
-  Routine Description:\r
-    Converts the low nibble of a byte to hex unicode character.\r
-\r
-  Arguments:\r
-    Nibble - lower nibble of a byte.\r
-\r
-  Returns:\r
-    Hex unicode character between L'0' to L'f'.\r
-\r
---*/\r
-{\r
-  Nibble &= 0x0F;\r
-\r
-  if (Nibble <= 0x9) {\r
-    return (CHAR16)(Nibble + L'0');\r
-  }\r
-\r
-  return (CHAR16)(Nibble - 0xA + L'a');\r
-}\r
-\r
-\r
-/**\r
-  Converts Unicode string to binary buffer.\r
-  The conversion may be partial.\r
-  The first character in the string that is not hex digit stops the conversion.\r
-  At a minimum, any blob of data could be represented as a hex string.\r
-\r
-  @param  Buf                    Pointer to buffer that receives the data.\r
-  @param  Len                    Length in bytes of the buffer to hold converted\r
-                                 data. If routine return with EFI_SUCCESS,\r
-                                 containing length of converted data. If routine\r
-                                 return with EFI_BUFFER_TOO_SMALL, containg length\r
-                                 of buffer desired.\r
-  @param  Str                    String to be converted from.\r
-  @param  ConvertedStrLen        Length of the Hex String consumed.\r
-\r
-  @retval EFI_SUCCESS            Routine Success.\r
-  @retval EFI_BUFFER_TOO_SMALL   The buffer is too small to hold converted data.\r
-\r
-**/\r
-STATIC\r
-EFI_STATUS\r
-HexStringToBufPrivate (\r
-  IN OUT UINT8                     *Buf,\r
-  IN OUT UINTN                     *Len,\r
-  IN     CHAR16                    *Str,\r
-  OUT    UINTN                     *ConvertedStrLen  OPTIONAL\r
-  )\r
-{\r
-  UINTN       HexCnt;\r
-  UINTN       Idx;\r
-  UINTN       BufferLength;\r
-  UINT8       Digit;\r
-  UINT8       Byte;\r
-\r
-  //\r
-  // Find out how many hex characters the string has.\r
-  //\r
-  for (Idx = 0, HexCnt = 0; IsHexDigit (&Digit, Str[Idx]); Idx++, HexCnt++);\r
-\r
-  if (HexCnt == 0) {\r
-    *Len = 0;\r
-    return EFI_SUCCESS;\r
-  }\r
-  //\r
-  // Two Unicode characters make up 1 buffer byte. Round up.\r
-  //\r
-  BufferLength = (HexCnt + 1) / 2;\r
-\r
-  //\r
-  // Test if  buffer is passed enough.\r
-  //\r
-  if (BufferLength > (*Len)) {\r
-    *Len = BufferLength;\r
-    return EFI_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  *Len = BufferLength;\r
-\r
-  for (Idx = 0; Idx < HexCnt; Idx++) {\r
-\r
-    IsHexDigit (&Digit, Str[Idx]);\r
-\r
-    //\r
-    // For odd charaters, write the lower nibble for each buffer byte,\r
-    // and for even characters, the upper nibble.\r
-    //\r
-    if ((Idx & 1) == 0) {\r
-      Byte = (UINT8) (Digit << 4);\r
-    } else {\r
-      Byte = Buf[Idx / 2];\r
-      Byte &= 0xF0;\r
-      Byte = (UINT8) (Byte | Digit);\r
-    }\r
-\r
-    Buf[Idx / 2] = Byte;\r
-  }\r
-\r
-  if (ConvertedStrLen != NULL) {\r
-    *ConvertedStrLen = HexCnt;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
-  Converts binary buffer to Unicode string.\r
-  At a minimum, any blob of data could be represented as a hex string.\r
-\r
-  @param  Str                    Pointer to the string.\r
-  @param  HexStringBufferLength  Length in bytes of buffer to hold the hex string.\r
-                                 Includes tailing '\0' character. If routine return\r
-                                 with EFI_SUCCESS, containing length of hex string\r
-                                 buffer. If routine return with\r
-                                 EFI_BUFFER_TOO_SMALL, containg length of hex\r
-                                 string buffer desired.\r
-  @param  Buf                    Buffer to be converted from.\r
-  @param  Len                    Length in bytes of the buffer to be converted.\r
-  @param  Flag                   If TRUE, encode the data in the same order as the\r
-                                 it  resides in the Buf. Else encode it in the\r
-                                 reverse direction.\r
-\r
-  @retval EFI_SUCCESS            Routine  success.\r
-  @retval EFI_BUFFER_TOO_SMALL   The hex string buffer is too small.\r
-\r
-**/\r
-STATIC\r
-EFI_STATUS\r
-BufToHexStringPrivate (\r
-  IN OUT CHAR16                    *Str,\r
-  IN OUT UINTN                     *HexStringBufferLength,\r
-  IN     UINT8                     *Buf,\r
-  IN     UINTN                     Len,\r
-  IN     BOOLEAN                   Flag\r
-  )\r
-{\r
-  UINTN       Idx;\r
-  UINT8       Byte;\r
-  UINTN       StrLen;\r
-\r
-  //\r
-  // Make sure string is either passed or allocate enough.\r
-  // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.\r
-  // Plus the Unicode termination character.\r
-  //\r
-  StrLen = Len * 2;\r
-  if ((*HexStringBufferLength) < (StrLen + 1) * sizeof (CHAR16)) {\r
-    *HexStringBufferLength = (StrLen + 1) * sizeof (CHAR16);\r
-    return EFI_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  *HexStringBufferLength = (StrLen + 1) * sizeof (CHAR16);\r
-\r
-  //\r
-  // Ends the string.\r
-  //\r
-  Str[StrLen] = 0;\r
-\r
-  for (Idx = 0; Idx < Len; Idx++) {\r
-\r
-    Byte = Buf[Idx];\r
-    if (Flag) {\r
-      Str[Idx * 2]     = NibbleToHexCharPrivate ((UINT8)(Byte >> 4));\r
-      Str[Idx * 2 + 1] = NibbleToHexCharPrivate (Byte);\r
-    } else {\r
-      Str[StrLen - 1 - Idx * 2] = NibbleToHexCharPrivate (Byte);\r
-      Str[StrLen - 2 - Idx * 2] = NibbleToHexCharPrivate ((UINT8)(Byte >> 4));\r
-    }\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-\r
 /**\r
   Calculate the number of Unicode characters of the incoming Configuration string,\r
   not including NULL terminator.\r
@@ -306,7 +123,6 @@ GetDevicePath (
   // The data in <PathHdr> is encoded as hex UNICODE %02x bytes in the same order\r
   // as the device path resides in RAM memory.\r
   // Translate the data into binary.\r
-  // Two Unicode characters make up 1 buffer byte.\r
   //\r
   Length /= 2;\r
   *DevicePath = (UINT8 *) AllocateZeroPool (Length);\r
@@ -315,7 +131,7 @@ GetDevicePath (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  HexStringToBufPrivate (*DevicePath, &Length, DevicePathString, NULL);\r
+  HexStringToBuffer (*DevicePath, &Length, DevicePathString);\r
 \r
   SafeFreePool (DevicePathString);\r
 \r
@@ -503,12 +319,11 @@ ExportAllStorage (
   @param  String                 A constant string which is the prefix of the to be\r
                                  generated string, e.g. GUID=\r
   @param  BufferLen              The length of the Buffer in bytes.\r
-  @param  Buffer                 Points to a buffer which will be converted to hex\r
-                                 string and to be the content of the generated\r
-                                 string.\r
-  @param  Flag                   If TRUE, convert the buffer data in the same order\r
-                                 as the it  resides in the Buffer. Else convert it\r
-                                 in the reverse direction.\r
+  @param  Buffer                 Points to a buffer which will be converted to be the \r
+                                          content of the generated string.\r
+  @param  Flag           If 1, the buffer contains data for the value of GUID or PATH stored in \r
+                                UINT8 *; if 2, the buffer contains unicode string for the value of NAME;\r
+                                if 3, the buffer contains other data.\r
   @param  SubStr                 Points to the output string. It's caller's\r
                                  responsibility to free this buffer.\r
 \r
@@ -519,14 +334,15 @@ VOID
 GenerateSubStr (\r
   IN CONST EFI_STRING              String,\r
   IN  UINTN                        BufferLen,\r
-  IN  UINT8                        *Buffer,\r
-  IN  BOOLEAN                      Flag,\r
+  IN  VOID                         *Buffer,\r
+  IN  UINT8                        Flag,\r
   OUT EFI_STRING                   *SubStr\r
   )\r
 {\r
   UINTN       Length;\r
   EFI_STRING  Str;\r
   EFI_STATUS  Status;\r
+  EFI_STRING  StringHeader;\r
 \r
   ASSERT (String != NULL && SubStr != NULL);\r
 \r
@@ -536,20 +352,33 @@ GenerateSubStr (
     return ;\r
   }\r
 \r
-  Length = BufferLen * 2 + 1 + StrLen (String) + 1;\r
+  Length = StrLen (String) + BufferLen * 2 + 1 + 1;\r
   Str = AllocateZeroPool (Length * sizeof (CHAR16));\r
   ASSERT (Str != NULL);\r
 \r
   StrCpy (Str, String);\r
   Length = (BufferLen * 2 + 1) * sizeof (CHAR16);\r
 \r
-  Status = BufToHexStringPrivate (\r
-             Str + StrLen (String),\r
-             &Length,\r
-             Buffer,\r
-             BufferLen,\r
-             Flag\r
-             );\r
+  Status       = EFI_SUCCESS;\r
+  StringHeader = Str + StrLen (String);\r
+\r
+  switch (Flag) {\r
+  case 1:\r
+    Status = BufferToHexString (StringHeader, (UINT8 *) Buffer, BufferLen);\r
+    break;\r
+  case 2:\r
+    Status = UnicodeToConfigString (StringHeader, &Length, (CHAR16 *) Buffer);\r
+    break;\r
+  case 3:\r
+    Status = BufToHexString (StringHeader, &Length, (UINT8 *) Buffer, BufferLen);\r
+    //\r
+    // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.\r
+    //\r
+    ToLower (StringHeader);\r
+    break;\r
+  default:\r
+    break;\r
+  }\r
 \r
   ASSERT_EFI_ERROR (Status);\r
   StrCat (Str, L"&");\r
@@ -1096,7 +925,7 @@ HiiConfigRoutingExportConfig (
     if (PathHdr == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-    Status = BufToHexStringPrivate (PathHdr, &PathHdrSize, (UINT8 *) DevicePath, Length, TRUE);\r
+    Status = BufferToHexString (PathHdr, (UINT8 *) DevicePath, Length);\r
     ASSERT_EFI_ERROR (Status);\r
 \r
     //\r
@@ -1104,7 +933,7 @@ HiiConfigRoutingExportConfig (
     // It means extract all possible configurations from this specific driver.\r
     //\r
     TmpSize = StrLen (L"GUID=&NAME=&PATH=");\r
-    RequestSize   = (TmpSize + sizeof (EFI_GUID) * 2 +  StrLen (Storage->Name))\r
+    RequestSize   = (TmpSize + 32 +  StrLen (Storage->Name) * 4)\r
                      * sizeof (CHAR16) + PathHdrSize;\r
     ConfigRequest = (EFI_STRING) AllocateZeroPool (RequestSize);\r
     if (ConfigRequest == NULL) {\r
@@ -1115,20 +944,16 @@ HiiConfigRoutingExportConfig (
     //\r
     // Add <GuidHdr>\r
     // <GuidHdr> ::= 'GUID='<Guid>\r
+    // Convert <Guid> in the same order as it resides in RAM memory.\r
     //\r
     StringPtr = ConfigRequest;\r
     StrnCpy (StringPtr, L"GUID=", StrLen (L"GUID="));\r
     StringPtr += StrLen (L"GUID=");\r
 \r
-    Status = BufToHexStringPrivate (\r
-               StringPtr,\r
-               &RequestSize,\r
-               (UINT8 *) (&Storage->Guid),\r
-               sizeof (EFI_GUID),\r
-               FALSE\r
-               );\r
+    Status = BufferToHexString (StringPtr, (UINT8 *) (&Storage->Guid), sizeof (EFI_GUID));\r
     ASSERT_EFI_ERROR (Status);\r
-    StringPtr += RequestSize / 2 - 1;\r
+    \r
+    StringPtr += 32;\r
     ASSERT (*StringPtr == 0);\r
     *StringPtr = L'&';\r
     StringPtr++;\r
@@ -1139,8 +964,12 @@ HiiConfigRoutingExportConfig (
     //\r
     StrnCpy (StringPtr, L"NAME=", StrLen (L"NAME="));\r
     StringPtr += StrLen (L"NAME=");\r
-    StrnCpy (StringPtr, Storage->Name, StrLen (Storage->Name));\r
-    StringPtr += StrLen (Storage->Name);\r
+\r
+    Length = (StrLen (Storage->Name) * 4 + 1) * sizeof (CHAR16);\r
+    Status = UnicodeToConfigString (StringPtr, &Length, Storage->Name);\r
+    ASSERT_EFI_ERROR (Status);\r
+    StringPtr += StrLen (Storage->Name) * 4;\r
+    \r
     *StringPtr = L'&';\r
     StringPtr++;\r
 \r
@@ -1250,7 +1079,7 @@ HiiConfigRoutingExportConfig (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-HiiConfigRoutingRoutConfig (\r
+HiiConfigRoutingRouteConfig (\r
   IN  CONST EFI_HII_CONFIG_ROUTING_PROTOCOL  *This,\r
   IN  CONST EFI_STRING                       Configuration,\r
   OUT EFI_STRING                             *Progress\r
@@ -1609,6 +1438,8 @@ HiiBlockToConfig (
 \r
     Status = BufToHexString (ValueStr, &Length, Value, Width);\r
     ASSERT_EFI_ERROR (Status);\r
+    ToLower (ValueStr);\r
+\r
     SafeFreePool (Value);\r
     Value = NULL;\r
 \r
@@ -1955,30 +1786,21 @@ HiiGetAltCfg (
   //\r
   // Generate the sub string for later matching.\r
   //\r
-  GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (UINT8 *) Guid, FALSE, &GuidStr);\r
+  GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (VOID *) Guid, 1, &GuidStr);\r
   GenerateSubStr (\r
     L"PATH=",\r
     GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) DevicePath),\r
-    (UINT8 *) DevicePath,\r
-    TRUE,\r
+    (VOID *) DevicePath,\r
+    1,\r
     &PathStr\r
     );\r
   if (AltCfgId != NULL) {\r
-    GenerateSubStr (L"ALTCFG=", sizeof (UINT16), (UINT8 *) AltCfgId, FALSE, &AltIdStr);\r
+    GenerateSubStr (L"ALTCFG=", sizeof (UINT16), (VOID *) AltCfgId, 3, &AltIdStr);  \r
   }\r
   if (Name != NULL) {\r
-    Length  = StrLen (Name);\r
-    Length  += StrLen (L"NAME=&") + 1;\r
-    NameStr = AllocateZeroPool (Length * sizeof (CHAR16));\r
-    if (NameStr == NULL) {\r
-      Status = EFI_OUT_OF_RESOURCES;\r
-      goto Exit;\r
-    }\r
-    StrCpy (NameStr, L"NAME=");\r
-    StrCat (NameStr, Name);\r
-    StrCat (NameStr, L"&");\r
+    GenerateSubStr (L"NAME=", StrLen (Name) * sizeof (CHAR16), (VOID *) Name, 2, &NameStr);    \r
   } else {\r
-    GenerateSubStr (L"NAME=", 0, NULL, FALSE, &NameStr);\r
+    GenerateSubStr (L"NAME=", 0, NULL, 2, &NameStr);\r
   }\r
 \r
   while (*StringPtr != 0) {\r
index 3ee8b4ca349348a5ccd5f3bea1f316182b10a652..b5a5c43b43c568286eb6152efd6769fba78e2083 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -2771,8 +2771,7 @@ HiiNewPackageList (
 \r
   @retval EFI_SUCCESS            The data associated with the Handle was removed\r
                                  from  the HII database.\r
-  @retval EFI_NOT_FOUND          The specified PackageList could not be found in\r
-                                 database.\r
+  @retval EFI_NOT_FOUND          The specified andle is not in database.\r
   @retval EFI_INVALID_PARAMETER  The Handle was not valid.\r
 \r
 **/\r
@@ -2790,10 +2789,14 @@ HiiRemovePackageList (
   HII_DATABASE_PACKAGE_LIST_INSTANCE  *PackageList;\r
   HII_HANDLE                          *HiiHandle;\r
 \r
-  if (This == NULL || !IsHiiHandleValid (Handle)) {\r
+  if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (!IsHiiHandleValid (Handle)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
   Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
 \r
   //\r
@@ -2879,9 +2882,8 @@ HiiRemovePackageList (
   @retval EFI_SUCCESS            The HII database was successfully updated.\r
   @retval EFI_OUT_OF_RESOURCES   Unable to allocate enough memory for the updated\r
                                  database.\r
-  @retval EFI_INVALID_PARAMETER  Handle or PackageList was NULL.\r
-  @retval EFI_NOT_FOUND          The Handle was not valid or could not be found in\r
-                                 database.\r
+  @retval EFI_INVALID_PARAMETER  PackageList was NULL.\r
+  @retval EFI_NOT_FOUND          The specified Handle is not in database.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -2900,7 +2902,7 @@ HiiUpdatePackageList (
   HII_DATABASE_PACKAGE_LIST_INSTANCE  *OldPackageList;\r
   EFI_HII_PACKAGE_HEADER              PackageHeader;\r
 \r
-  if (This == NULL || PackageList == NULL || Handle == NULL) {\r
+  if (This == NULL || PackageList == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -2993,12 +2995,17 @@ HiiUpdatePackageList (
   @param  Handle                 An array of EFI_HII_HANDLE instances returned.\r
 \r
   @retval EFI_SUCCESS            The matching handles are outputed successfully.\r
+                                               HandleBufferLength is updated with the actual length.\r
   @retval EFI_BUFFER_TO_SMALL    The HandleBufferLength parameter indicates that\r
                                  Handle is too small to support the number of\r
                                  handles. HandleBufferLength is updated with a\r
                                  value that will  enable the data to fit.\r
   @retval EFI_NOT_FOUND          No matching handle could not be found in database.\r
   @retval EFI_INVALID_PARAMETER  Handle or HandleBufferLength was NULL.\r
+  \r
+  @retval EFI_INVALID_PARAMETER  PackageType is not a EFI_HII_PACKAGE_TYPE_GUID but\r
+                                                     PackageGuid is not NULL, PackageType is a EFI_HII_\r
+                                                     PACKAGE_TYPE_GUID but PackageGuid is NULL.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -3350,10 +3357,14 @@ HiiUnregisterPackageNotify (
   LIST_ENTRY                          *Link;\r
   EFI_STATUS                          Status;\r
 \r
-  if (This == NULL || NotificationHandle == NULL) {\r
+  if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (NotificationHandle == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
   Status = gBS->OpenProtocol (\r
                   NotificationHandle,\r
                   &mHiiDatabaseNotifyGuid,\r
@@ -3363,7 +3374,7 @@ HiiUnregisterPackageNotify (
                   EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    return EFI_INVALID_PARAMETER;\r
+    return EFI_NOT_FOUND;\r
   }\r
 \r
   Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
@@ -3474,7 +3485,7 @@ HiiFindKeyboardLayouts (
       for (Index = 0; Index < LayoutCount; Index++) {\r
         ResultSize += sizeof (EFI_GUID);\r
         if (ResultSize <= *KeyGuidBufferLength) {\r
-          CopyMem (KeyGuidBuffer + Index, Layout + sizeof (UINT16), sizeof (EFI_GUID));\r
+          CopyMem (KeyGuidBuffer + (ResultSize / sizeof (EFI_GUID) - 1), Layout + sizeof (UINT16), sizeof (EFI_GUID));\r
           CopyMem (&LayoutLength, Layout, sizeof (UINT16));\r
           Layout = Layout + LayoutLength;\r
         }\r
index f60506198125d0dbb53d4692e988aac265c0deeb..9e99a120125548e5faeaea6ef6efd29bb9cfc60f 100644 (file)
@@ -905,15 +905,14 @@ GetSystemFont (
 \r
 \r
 /**\r
-  Check whether EFI_FONT_DISPLAY_INFO points to system default font and color.\r
+  Check whether EFI_FONT_DISPLAY_INFO points to system default font and color or\r
+  returns the system default according to the optional inputs.\r
 \r
   @param  Private                 HII database driver private data.\r
   @param  StringInfo              Points to the string output information,\r
                                   including the color and font.\r
-  @param  SystemInfo              If not NULL, points to system default font and\r
-                                  color when incoming StringInfo does not match the\r
-                                  default.  Points to NULL if matches. It's\r
-                                  caller's reponsibility to free this buffer.\r
+  @param  SystemInfo              If not NULL, points to system default font and color.\r
+\r
   @param  SystemInfoLen           If not NULL, output the length of default system\r
                                   info.\r
 \r
@@ -933,6 +932,7 @@ IsSystemFontInfo (
   EFI_STATUS                          Status;\r
   EFI_FONT_DISPLAY_INFO               *SystemDefault;\r
   UINTN                               DefaultLen;\r
+  BOOLEAN                             Flag;\r
 \r
   ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);\r
 \r
@@ -940,28 +940,69 @@ IsSystemFontInfo (
     return TRUE;\r
   }\r
 \r
-  //\r
-  // Check whether incoming string font and color matches system default.\r
-  //\r
   Status = GetSystemFont (Private, &SystemDefault, &DefaultLen);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Record the system default info.\r
+  //\r
   if (SystemInfo != NULL) {\r
     *SystemInfo = SystemDefault;\r
-  } else {\r
-    SafeFreePool (SystemDefault);\r
   }\r
 \r
   if (SystemInfoLen != NULL) {\r
     *SystemInfoLen = DefaultLen;\r
   }\r
 \r
-  if (StringInfo == NULL ||\r
-      (StringInfo != NULL && CompareMem (SystemDefault, StringInfo, DefaultLen) == 0)) {\r
+  if (StringInfo == NULL) {\r
     return TRUE;\r
   }\r
 \r
-  return FALSE;\r
+  Flag = FALSE;\r
+  //\r
+  // Check the FontInfoMask to see whether it is retrieving system info.\r
+  //\r
+  if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) == 0) {\r
+    if (StrCmp (StringInfo->FontInfo.FontName, SystemDefault->FontInfo.FontName) != 0) {\r
+      goto Exit;\r
+    }\r
+  }\r
+  if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) == 0) {\r
+    if (StringInfo->FontInfo.FontSize != SystemDefault->FontInfo.FontSize) {\r
+      goto Exit;\r
+    }\r
+  }\r
+  if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) == 0) {\r
+    if (StringInfo->FontInfo.FontStyle != SystemDefault->FontInfo.FontStyle) {\r
+      goto Exit;\r
+    }\r
+  }\r
+  if ((StringInfo->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == 0) {\r
+    if (CompareMem (\r
+          &StringInfo->ForegroundColor, \r
+          &SystemDefault->ForegroundColor, \r
+          sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+          ) != 0) {\r
+      goto Exit;\r
+    }\r
+  }\r
+  if ((StringInfo->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == 0) {\r
+    if (CompareMem (\r
+          &StringInfo->BackgroundColor, \r
+          &SystemDefault->BackgroundColor, \r
+          sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+          ) != 0) {\r
+      goto Exit;\r
+    }\r
+  }\r
+\r
+  Flag = TRUE;\r
+\r
+Exit:\r
+  if (SystemInfo == NULL) {\r
+    SafeFreePool (SystemDefault);    \r
+  }\r
+  return Flag;\r
 }\r
 \r
 \r
@@ -1400,6 +1441,7 @@ IsLineBreak (
   @retval EFI_OUT_OF_RESOURCES    Unable to allocate an output buffer for\r
                                   RowInfoArray or Blt.\r
   @retval EFI_INVALID_PARAMETER   The String or Blt was NULL.\r
+  @retval EFI_INVALID_PARAMETER Flags were invalid combination..\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1470,16 +1512,16 @@ HiiStringToImage (
   //\r
   // These two flags require that EFI_HII_OUT_FLAG_CLIP be also set.\r
   //\r
-  if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLEAN_X)) ==  EFI_HII_OUT_FLAG_CLEAN_X) {\r
+  if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLIP_CLEAN_X)) ==  EFI_HII_OUT_FLAG_CLIP_CLEAN_X) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLEAN_Y)) ==  EFI_HII_OUT_FLAG_CLEAN_Y) {\r
+  if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y)) ==  EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   //\r
   // This flag cannot be used with EFI_HII_OUT_FLAG_CLEAN_X.\r
   //\r
-  if ((Flags & (EFI_HII_OUT_FLAG_WRAP | EFI_HII_OUT_FLAG_CLEAN_X)) ==  (EFI_HII_OUT_FLAG_WRAP | EFI_HII_OUT_FLAG_CLEAN_X)) {\r
+  if ((Flags & (EFI_HII_OUT_FLAG_WRAP | EFI_HII_OUT_FLAG_CLIP_CLEAN_X)) ==  (EFI_HII_OUT_FLAG_WRAP | EFI_HII_OUT_FLAG_CLIP_CLEAN_X)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -1633,7 +1675,7 @@ HiiStringToImage (
     //\r
 \r
     Transparent = (BOOLEAN) ((Flags & EFI_HII_OUT_FLAG_TRANSPARENT) == EFI_HII_OUT_FLAG_TRANSPARENT ? TRUE : FALSE);\r
-    if ((Flags & EFI_HII_OUT_FLAG_CLEAN_Y) == EFI_HII_OUT_FLAG_CLEAN_Y) {\r
+    if ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {\r
       //\r
       // Don't draw at all if there is only one row and\r
       // the row's bottom-most on pixel cannot fit.\r
@@ -1705,7 +1747,7 @@ HiiStringToImage (
         //\r
         if (!LineBreak) {\r
           Flags &= (~ (EFI_HII_OUT_FLAGS) EFI_HII_OUT_FLAG_WRAP);\r
-          Flags |= EFI_HII_OUT_FLAG_CLEAN_X;\r
+          Flags |= EFI_HII_OUT_FLAG_CLIP_CLEAN_X;\r
         }\r
       }\r
 \r
@@ -1713,7 +1755,7 @@ HiiStringToImage (
       // Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set.\r
       //\r
       if (LineWidth + BltX <= Image->Width ||\r
-          (LineWidth + BltX > Image->Width && (Flags & EFI_HII_OUT_FLAG_CLEAN_X) == 0)) {\r
+        (LineWidth + BltX > Image->Width && (Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_X) == 0)) {\r
         //\r
         // Record right-most character in RowInfo even if it is partially displayed.\r
         //\r
@@ -1749,7 +1791,7 @@ HiiStringToImage (
       //\r
       if (RowIndex == MaxRowNum - 1 && Image->Height < LineHeight) {\r
         LineHeight = Image->Height;\r
-        if ((Flags & EFI_HII_OUT_FLAG_CLEAN_Y) == EFI_HII_OUT_FLAG_CLEAN_Y) {\r
+        if ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {\r
           //\r
           // Don't draw at all if the row's bottom-most on pixel cannot fit.\r
           //\r
@@ -1968,7 +2010,10 @@ Exit:
   @retval EFI_SUCCESS             The string was successfully rendered.\r
   @retval EFI_OUT_OF_RESOURCES    Unable to allocate an output buffer for\r
                                   RowInfoArray or Blt.\r
-  @retval EFI_INVALID_PARAMETER   The PackageList was NULL.\r
+  @retval EFI_INVALID_PARAMETER  The Blt or PackageList was NULL.\r
+  @retval EFI_INVALID_PARAMETER  Flags were invalid combination.\r
+  @retval EFI_NOT_FOUND         The specified PackageList is not in the Database or the stringid is not \r
+                          in the specified PackageList. \r
 \r
 **/\r
 EFI_STATUS\r
@@ -1992,6 +2037,10 @@ HiiStringIdToImage (
   HII_DATABASE_PRIVATE_DATA           *Private;\r
   EFI_STRING                          String;\r
   UINTN                               StringSize;\r
+  UINTN                               FontLen;\r
+  EFI_FONT_INFO                       *StringFontInfo;\r
+  EFI_FONT_DISPLAY_INFO               *NewStringInfo;\r
+  CHAR8                               CurrentLang[RFC_3066_ENTRY_SIZE];\r
 \r
   if (This == NULL || PackageList == NULL || Blt == NULL || PackageList == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -2001,7 +2050,14 @@ HiiStringIdToImage (
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
+  //\r
+  // When Language points to NULL, current system language is used.\r
+  //\r
+  if (Language != NULL) {\r
+    AsciiStrCpy (CurrentLang, (CHAR8 *) Language);\r
+  } else {\r
+    HiiLibGetCurrentLanguage (CurrentLang);\r
+  }\r
 \r
   //\r
   // Get the string to be displayed.\r
@@ -2013,14 +2069,18 @@ HiiStringIdToImage (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
+  Private        = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
+  StringFontInfo = NULL;\r
+  NewStringInfo  = NULL;\r
+  \r
   Status = Private->HiiString.GetString (\r
                                 &Private->HiiString,\r
-                                Language,\r
+                                CurrentLang,\r
                                 PackageList,\r
                                 StringId,\r
                                 String,\r
                                 &StringSize,\r
-                                NULL\r
+                                &StringFontInfo\r
                                 );\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
     SafeFreePool (String);\r
@@ -2041,11 +2101,42 @@ HiiStringIdToImage (
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
-    SafeFreePool (String);\r
-    return Status;\r
+      goto Exit;\r
+  }\r
+    \r
+  //\r
+  // When StringInfo specifies that string will be output in the system default font and color,\r
+  // use particular stringfontinfo described in string package instead if exists. \r
+  // StringFontInfo equals NULL means system default font attaches with the string block.\r
+  //\r
+  if (StringFontInfo != NULL && IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, NULL, NULL)) {\r
+    FontLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + StrSize (StringFontInfo->FontName);\r
+    NewStringInfo = AllocateZeroPool (FontLen);\r
+    if (NewStringInfo == NULL) {      \r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Exit;\r
+    }\r
+    NewStringInfo->FontInfoMask       = EFI_FONT_INFO_SYS_FORE_COLOR | EFI_FONT_INFO_SYS_BACK_COLOR;\r
+    NewStringInfo->FontInfo.FontStyle = StringFontInfo->FontStyle;\r
+    NewStringInfo->FontInfo.FontSize  = StringFontInfo->FontSize;    \r
+    StrCpy (NewStringInfo->FontInfo.FontName, StringFontInfo->FontName);\r
+  \r
+    Status = HiiStringToImage (\r
+               This, \r
+               Flags, \r
+               String, \r
+               NewStringInfo, \r
+               Blt, \r
+               BltX, \r
+               BltY, \r
+               RowInfoArray,\r
+               RowInfoArraySize,\r
+               ColumnInfoArray\r
+               );\r
+    goto Exit;\r
   }\r
 \r
-  return HiiStringToImage (\r
+  Status = HiiStringToImage (\r
            This,\r
            Flags,\r
            String,\r
@@ -2058,6 +2149,12 @@ HiiStringIdToImage (
            ColumnInfoArray\r
            );\r
 \r
+Exit:\r
+  SafeFreePool (String);\r
+  SafeFreePool (StringFontInfo);\r
+  SafeFreePool (NewStringInfo);\r
+\r
+  return Status;\r
 }\r
 \r
 \r
@@ -2231,7 +2328,9 @@ Exit:
                                   returned font handle or points to NULL if there\r
                                   are no more matching fonts.\r
   @param  StringInfoIn            Upon entry, points to the font to return\r
-                                  information about.\r
+                                  information about. \r
+                                  If NULL, then the information about the system default \r
+                                  font will be returned.\r
   @param  StringInfoOut           Upon return, contains the matching font's\r
                                   information.  If NULL, then no information is\r
                                   returned. It's caller's responsibility to free\r
@@ -2242,7 +2341,7 @@ Exit:
 \r
   @retval EFI_SUCCESS             Matching font returned successfully.\r
   @retval EFI_NOT_FOUND           No matching font was found.\r
-  @retval EFI_INVALID_PARAMETER   StringInfoIn is NULL.\r
+  @retval EFI_INVALID_PARAMETER  StringInfoIn->FontInfoMask is an invalid combination.\r
   @retval EFI_OUT_OF_RESOURCES    There were insufficient resources to complete the\r
                                   request.\r
 \r
@@ -2252,7 +2351,7 @@ EFIAPI
 HiiGetFontInfo (\r
   IN  CONST EFI_HII_FONT_PROTOCOL    *This,\r
   IN  OUT   EFI_FONT_HANDLE          *FontHandle,\r
-  IN  CONST EFI_FONT_DISPLAY_INFO    *StringInfoIn,\r
+  IN  CONST EFI_FONT_DISPLAY_INFO    *StringInfoIn, OPTIONAL\r
   OUT       EFI_FONT_DISPLAY_INFO    **StringInfoOut,\r
   IN  CONST EFI_STRING               String OPTIONAL\r
   )\r
@@ -2267,51 +2366,71 @@ HiiGetFontInfo (
   EFI_STRING                         StringIn;\r
   EFI_FONT_HANDLE                    LocalFontHandle;\r
 \r
-  if (This == NULL || StringInfoIn == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  //\r
-  // Check the font information mask to make sure it is valid.\r
-  //\r
-  if (((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_FONT  | EFI_FONT_INFO_ANY_FONT))  ==\r
-       (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT))   ||\r
-      ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE  | EFI_FONT_INFO_ANY_SIZE))  ==\r
-       (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE))   ||\r
-      ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) ==\r
-       (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) ||\r
-      ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESIZE    | EFI_FONT_INFO_ANY_SIZE))  ==\r
-       (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE))     ||\r
-      ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESTYLE   | EFI_FONT_INFO_ANY_STYLE)) ==\r
-       (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE))) {\r
+  if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   FontInfo        = NULL;\r
+  SystemDefault   = NULL;\r
   LocalFontHandle = NULL;\r
   if (FontHandle != NULL) {\r
     LocalFontHandle = *FontHandle;\r
   }\r
 \r
+  Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  // Already searched to the end of the whole list, return directly.\r
+  //\r
+  if (LocalFontHandle == &Private->FontInfoList) {\r
+    LocalFontHandle = NULL;\r
+    Status = EFI_NOT_FOUND;\r
+    goto Exit;\r
+  }\r
+\r
   //\r
   // Get default system display info, if StringInfoIn points to\r
   // system display info, return it directly.\r
   //\r
-  Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
-\r
   if (IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfoIn, &SystemDefault, &StringInfoOutLen)) {\r
-    if (StringInfoOut != NULL) {\r
-      *StringInfoOut = AllocateCopyPool (StringInfoOutLen, (EFI_FONT_DISPLAY_INFO *) StringInfoIn);\r
-      if (*StringInfoOut == NULL) {\r
-        Status = EFI_OUT_OF_RESOURCES;\r
-        LocalFontHandle = NULL;\r
-        goto Exit;\r
+    //\r
+    // System font is the first node. When handle is not NULL, system font can not\r
+    // be found any more.\r
+    //\r
+    if (LocalFontHandle == NULL) {\r
+      if (StringInfoOut != NULL) {\r
+        *StringInfoOut = AllocateCopyPool (StringInfoOutLen, SystemDefault);\r
+        if (*StringInfoOut == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          LocalFontHandle = NULL;\r
+          goto Exit;\r
+        }\r
       }\r
+\r
+      LocalFontHandle = Private->FontInfoList.ForwardLink;\r
+      Status = EFI_SUCCESS;\r
+      goto Exit;\r
+    } else {\r
+      LocalFontHandle = NULL;\r
+      Status = EFI_NOT_FOUND;\r
+      goto Exit;\r
     }\r
+  }\r
 \r
-    LocalFontHandle = Private->FontInfoList.ForwardLink;\r
-    Status = EFI_SUCCESS;\r
-    goto Exit;\r
+  //\r
+  // Check the font information mask to make sure it is valid.\r
+  //\r
+  if (((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_FONT  | EFI_FONT_INFO_ANY_FONT))  == \r
+       (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT))   ||\r
+      ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE  | EFI_FONT_INFO_ANY_SIZE))  == \r
+       (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE))   ||\r
+      ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) == \r
+       (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) ||\r
+      ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESIZE    | EFI_FONT_INFO_ANY_SIZE))  == \r
+       (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE))     ||           \r
+      ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESTYLE   | EFI_FONT_INFO_ANY_STYLE)) == \r
+       (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE))) {\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   //\r
@@ -2331,13 +2450,17 @@ HiiGetFontInfo (
 \r
   if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_SIZE) == EFI_FONT_INFO_SYS_SIZE) {\r
     InfoOut.FontInfo.FontSize = SystemDefault->FontInfo.FontSize;\r
-  } else if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_STYLE) == EFI_FONT_INFO_SYS_STYLE) {\r
+  } \r
+  if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_STYLE) == EFI_FONT_INFO_SYS_STYLE) {\r
     InfoOut.FontInfo.FontStyle = SystemDefault->FontInfo.FontStyle;\r
-  } else if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == EFI_FONT_INFO_SYS_FORE_COLOR) {\r
+  }\r
+  if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == EFI_FONT_INFO_SYS_FORE_COLOR) {\r
     InfoOut.ForegroundColor = SystemDefault->ForegroundColor;\r
-  } else if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == EFI_FONT_INFO_SYS_BACK_COLOR) {\r
+  }\r
+  if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == EFI_FONT_INFO_SYS_BACK_COLOR) {\r
     InfoOut.BackgroundColor = SystemDefault->BackgroundColor;\r
   }\r
+  \r
 \r
   FontInfo->FontSize  = InfoOut.FontInfo.FontSize;\r
   FontInfo->FontStyle = InfoOut.FontInfo.FontStyle;\r
@@ -2393,3 +2516,4 @@ Exit:
   return Status;\r
 }\r
 \r
+\r
index f19813298edfff2d11d0d7639751db57c448d4fd..bbd366edece9c1f84654e514d9d14142b02311ef 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -47,6 +47,8 @@ Revision History
 #include <Library/BaseLib.h>\r
 #include <Library/DevicePathLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
+#include <Library/IfrSupportLib.h>\r
+#include <Library/HiiLib.h>\r
 \r
 #define HII_DATABASE_NOTIFY_GUID \\r
   { \\r
@@ -495,7 +497,8 @@ FindGlyphBlock (
   @retval EFI_SUCCESS             The string was successfully rendered.\r
   @retval EFI_OUT_OF_RESOURCES    Unable to allocate an output buffer for\r
                                   RowInfoArray or Blt.\r
-  @retval EFI_INVALID_PARAMETER   The String was NULL.\r
+  @retval EFI_INVALID_PARAMETER The String or Blt.\r
+  @retval EFI_INVALID_PARAMETER Flags were invalid combination..\r
 \r
 **/\r
 EFI_STATUS\r
@@ -567,7 +570,10 @@ HiiStringToImage (
   @retval EFI_SUCCESS             The string was successfully rendered.\r
   @retval EFI_OUT_OF_RESOURCES    Unable to allocate an output buffer for\r
                                   RowInfoArray or Blt.\r
-  @retval EFI_INVALID_PARAMETER   The String was NULL.\r
+  @retval EFI_INVALID_PARAMETER The Blt or PackageList was NULL.\r
+  @retval EFI_INVALID_PARAMETER Flags were invalid combination.\r
+  @retval EFI_NOT_FOUND         The specified PackageList is not in the Database or the stringid is not \r
+                          in the specified PackageList. \r
 \r
 **/\r
 EFI_STATUS\r
@@ -616,7 +622,7 @@ EFIAPI
 HiiGetGlyph (\r
   IN  CONST EFI_HII_FONT_PROTOCOL    *This,\r
   IN  CHAR16                         Char,\r
-  IN  CONST EFI_FONT_DISPLAY_INFO    *StringInfo,\r
+  IN  CONST EFI_FONT_DISPLAY_INFO    *StringInfo, OPTIONAL\r
   OUT EFI_IMAGE_OUTPUT               **Blt,\r
   OUT UINTN                          *Baseline OPTIONAL\r
   )\r
@@ -635,7 +641,8 @@ HiiGetGlyph (
                                   returned font handle or points to NULL if there\r
                                   are no more matching fonts.\r
   @param  StringInfoIn            Upon entry, points to the font to return\r
-                                  information about.\r
+                                  information about. If NULL, then the information about the system default \r
+                                  font will be returned.\r
   @param  StringInfoOut           Upon return, contains the matching font's\r
                                   information.  If NULL, then no information is\r
                                   returned. It's caller's responsibility to free\r
@@ -647,9 +654,9 @@ HiiGetGlyph (
   @retval EFI_SUCCESS             Matching font returned successfully.\r
   @retval EFI_NOT_FOUND           No matching font was found.\r
   @retval EFI_INVALID_PARAMETER   StringInfoIn is NULL.\r
+  @retval EFI_INVALID_PARAMETER  StringInfoIn->FontInfoMask is an invalid combination.\r
   @retval EFI_OUT_OF_RESOURCES    There were insufficient resources to complete the\r
                                   request.\r
-\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -706,15 +713,15 @@ HiiNewImage (
   @param  ImageId                 The image's id,, which is unique within\r
                                   PackageList.\r
   @param  Image                   Points to the image.\r
-  @param  ImageSize               On entry, points to the size of the buffer\r
-                                  pointed to by Image, in bytes. On return, points\r
-                                  to the length of the image, in bytes.\r
 \r
   @retval EFI_SUCCESS             The new image was returned successfully.\r
   @retval EFI_NOT_FOUND           The image specified by ImageId is not available.\r
+                                                 The specified PackageList is not in the database.\r
   @retval EFI_BUFFER_TOO_SMALL    The buffer specified by ImageSize is too small to\r
                                   hold the image.\r
   @retval EFI_INVALID_PARAMETER   The Image or ImageSize was NULL.\r
+  @retval EFI_OUT_OF_RESOURCES   The bitmap could not be retrieved because there was not\r
+                                                       enough memory.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -723,8 +730,7 @@ HiiGetImage (
   IN  CONST EFI_HII_IMAGE_PROTOCOL   *This,\r
   IN  EFI_HII_HANDLE                 PackageList,\r
   IN  EFI_IMAGE_ID                   ImageId,\r
-  OUT EFI_IMAGE_INPUT                *Image,\r
-  OUT UINTN                          *ImageSize\r
+  OUT EFI_IMAGE_INPUT                *Image\r
   )\r
 ;\r
 \r
@@ -741,7 +747,7 @@ HiiGetImage (
 \r
   @retval EFI_SUCCESS             The new image was updated successfully.\r
   @retval EFI_NOT_FOUND           The image specified by ImageId is not in the\r
-                                  database.\r
+                                                database. The specified PackageList is not in the database.\r
   @retval EFI_INVALID_PARAMETER   The Image was NULL.\r
 \r
 **/\r
@@ -821,9 +827,9 @@ HiiDrawImage (
 \r
   @retval EFI_SUCCESS             The image was successfully drawn.\r
   @retval EFI_OUT_OF_RESOURCES    Unable to allocate an output buffer for Blt.\r
-  @retval EFI_INVALID_PARAMETER   The Image was NULL.\r
-  @retval EFI_NOT_FOUND           The specified packagelist could not be found in\r
-                                  current database.\r
+  @retval EFI_INVALID_PARAMETER  The Blt was NULL.\r
+  @retval EFI_NOT_FOUND          The image specified by ImageId is not in the database. \r
+                           The specified PackageList is not in the database.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -914,7 +920,9 @@ HiiNewString (
   @retval EFI_NOT_FOUND           The string specified by StringId is not\r
                                   available.\r
   @retval EFI_NOT_FOUND           The string specified by StringId is available but\r
-                                  not in the specified language.\r
+                                                not in the specified language.\r
+                                                The specified PackageList is not in the database.\r
+  @retval EFI_INVALID_LANGUAGE   - The string specified by StringId is available but\r
   @retval EFI_BUFFER_TOO_SMALL    The buffer specified by StringSize is too small\r
                                   to  hold the string.\r
   @retval EFI_INVALID_PARAMETER   The String or Language or StringSize was NULL.\r
@@ -1029,8 +1037,9 @@ HiiGetLanguages (
                                   too small to hold the returned information.\r
                                   SecondLanguageSize is updated to hold the size of\r
                                   the buffer required.\r
-  @retval EFI_NOT_FOUND           The language specified by FirstLanguage is not\r
+  @retval EFI_INVALID_LANGUAGE           The language specified by FirstLanguage is not\r
                                   present in the specified package list.\r
+  @retval EFI_NOT_FOUND          The specified PackageList is not in the Database.                                \r
 \r
 **/\r
 EFI_STATUS\r
@@ -1091,9 +1100,7 @@ HiiNewPackageList (
 \r
   @retval EFI_SUCCESS             The data associated with the Handle was removed\r
                                   from  the HII database.\r
-  @retval EFI_NOT_FOUND           The specified PackageList could not be found in\r
-                                  database.\r
-  @retval EFI_INVALID_PARAMETER   The Handle was not valid.\r
+  @retval EFI_NOT_FOUND           The specified Handle is not in database.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1119,9 +1126,8 @@ HiiRemovePackageList (
   @retval EFI_SUCCESS             The HII database was successfully updated.\r
   @retval EFI_OUT_OF_RESOURCES    Unable to allocate enough memory for the updated\r
                                   database.\r
-  @retval EFI_INVALID_PARAMETER   Handle or PackageList was NULL.\r
-  @retval EFI_NOT_FOUND           The Handle was not valid or could not be found in\r
-                                  database.\r
+  @retval EFI_INVALID_PARAMETER  PackageList was NULL.\r
+  @retval EFI_NOT_FOUND          The specified Handle is not in database.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1154,6 +1160,7 @@ HiiUpdatePackageList (
   @param  Handle                  An array of EFI_HII_HANDLE instances returned.\r
 \r
   @retval EFI_SUCCESS             The matching handles are outputed successfully.\r
+                                                HandleBufferLength is updated with the actual length.\r
   @retval EFI_BUFFER_TO_SMALL     The HandleBufferLength parameter indicates that\r
                                   Handle is too small to support the number of\r
                                   handles. HandleBufferLength is updated with a\r
@@ -1161,6 +1168,10 @@ HiiUpdatePackageList (
   @retval EFI_NOT_FOUND           No matching handle could not be found in\r
                                   database.\r
   @retval EFI_INVALID_PARAMETER   Handle or HandleBufferLength was NULL.\r
+  @retval EFI_INVALID_PARAMETER  PackageType is not a EFI_HII_PACKAGE_TYPE_GUID but\r
+                         PackageGuid is not NULL, PackageType is a EFI_HII_\r
+                         PACKAGE_TYPE_GUID but PackageGuid is NULL.\r
+  \r
 \r
 **/\r
 EFI_STATUS\r
@@ -1271,7 +1282,8 @@ HiiRegisterPackageNotify (
                                   unregistered.\r
 \r
   @retval EFI_SUCCESS             Notification is unregistered successfully.\r
-  @retval EFI_INVALID_PARAMETER   The Handle is invalid.\r
+  @retval EFI_NOT_FOUND          The incoming notification handle does not exist \r
+                           in current hii database.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1511,7 +1523,7 @@ HiiConfigRoutingExportConfig (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-HiiConfigRoutingRoutConfig (\r
+HiiConfigRoutingRouteConfig (\r
   IN  CONST EFI_HII_CONFIG_ROUTING_PROTOCOL  *This,\r
   IN  CONST EFI_STRING                       Configuration,\r
   OUT EFI_STRING                             *Progress\r
index 2bafb25b1878f33c1fd11b00e3aa6004b3b0efda..5bdc60470021583fafdeb3c2a9b29743f10da447 100644 (file)
@@ -57,7 +57,8 @@
   UefiDriverEntryPoint\r
   BaseMemoryLib\r
   DebugLib\r
-\r
+  IfrSupportLib\r
+  HiiLib\r
 \r
 [Protocols]\r
   gEfiConsoleControlProtocolGuid                \r
index 6583f6b6547713ad4f72b0c0af2ccf5235fbbaa9..4bba8af1b182a9a50a9eed58b2440f65b8985015 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -80,7 +80,7 @@ STATIC HII_DATABASE_PRIVATE_DATA mPrivate = {
   {\r
     HiiConfigRoutingExtractConfig,\r
     HiiConfigRoutingExportConfig,\r
-    HiiConfigRoutingRoutConfig,\r
+    HiiConfigRoutingRouteConfig,\r
     HiiBlockToConfig,\r
     HiiConfigToBlock,\r
     HiiGetAltCfg\r
@@ -104,6 +104,17 @@ STATIC HII_DATABASE_PRIVATE_DATA mPrivate = {
   NULL\r
 };\r
 \r
+STATIC\r
+VOID\r
+EFIAPI\r
+KeyboardLayoutChangeNullEvent (\r
+  IN EFI_EVENT                Event,\r
+  IN VOID                     *Context\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
 EFI_STATUS\r
 EFIAPI\r
 InitializeHiiDatabase (\r
@@ -161,9 +172,9 @@ Returns:
   // Create a event with EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group type.\r
   //\r
   Status = gBS->CreateEventEx (\r
-                  0,\r
-                  0,\r
-                  NULL,\r
+                  EFI_EVENT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  KeyboardLayoutChangeNullEvent,\r
                   NULL,\r
                   &gHiiSetKbdLayoutEventGuid,\r
                   &gHiiKeyboardLayoutChanged\r
index 341a50a7e8f3303126f0b914e9a3621fdb0727a2..6b6a72002dc2e6b22a71bf7eb0ac987d5c4d91fc 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -610,7 +610,7 @@ HiiNewImage (
   UINTN                               NewBlockSize;\r
   EFI_IMAGE_INPUT                     *ImageIn;\r
 \r
-  if (This == NULL || ImageId == NULL || Image == NULL || PackageList == NULL) {\r
+  if (This == NULL || ImageId == NULL || Image == NULL || Image->Bitmap == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -798,10 +798,13 @@ HiiNewImage (
                                  length of the image, in bytes.\r
 \r
   @retval EFI_SUCCESS            The new image was returned successfully.\r
-  @retval EFI_NOT_FOUND          The image specified by ImageId is not available.\r
+  @retval EFI_NOT_FOUND           The image specified by ImageId is not in the\r
+                                                database. The specified PackageList is not in the database.\r
   @retval EFI_BUFFER_TOO_SMALL   The buffer specified by ImageSize is too small to\r
                                  hold the image.\r
   @retval EFI_INVALID_PARAMETER  The Image or ImageSize was NULL.\r
+  @retval EFI_OUT_OF_RESOURCES   The bitmap could not be retrieved because there was not\r
+                                                     enough memory.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -810,8 +813,7 @@ HiiGetImage (
   IN  CONST EFI_HII_IMAGE_PROTOCOL   *This,\r
   IN  EFI_HII_HANDLE                 PackageList,\r
   IN  EFI_IMAGE_ID                   ImageId,\r
-  OUT EFI_IMAGE_INPUT                *Image,\r
-  OUT UINTN                          *ImageSize\r
+  OUT EFI_IMAGE_INPUT                *Image\r
   )\r
 {\r
   HII_DATABASE_PRIVATE_DATA           *Private;\r
@@ -831,7 +833,7 @@ HiiGetImage (
   UINT8                               PaletteIndex;\r
   UINT16                              PaletteSize;\r
 \r
-  if (This == NULL || ImageSize == NULL || Image == NULL || ImageId < 1 || PackageList == NULL) {\r
+  if (This == NULL || Image == NULL || ImageId < 1) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -897,13 +899,12 @@ HiiGetImage (
     // Use the common block code since the definition of these structures is the same.\r
     //\r
     CopyMem (&Iibt1bit, ImageBlock, sizeof (EFI_HII_IIBT_IMAGE_1BIT_BLOCK));\r
-    ImageLength = sizeof (EFI_IMAGE_INPUT) + sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) *\r
-                  (Iibt1bit.Bitmap.Width * Iibt1bit.Bitmap.Height - 1);\r
-    if (*ImageSize < ImageLength) {\r
-      *ImageSize = ImageLength;\r
-      return EFI_BUFFER_TOO_SMALL;\r
+    ImageLength = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) *\r
+                  (Iibt1bit.Bitmap.Width * Iibt1bit.Bitmap.Height);\r
+    Image->Bitmap = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (ImageLength);\r
+    if (Image->Bitmap == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
     }\r
-    ZeroMem (Image, ImageLength);\r
 \r
     if (Flag) {\r
       Image->Flags = EFI_IMAGE_TRANSPARENT;\r
@@ -956,13 +957,11 @@ HiiGetImage (
       ImageBlock + sizeof (EFI_HII_IMAGE_BLOCK) + sizeof (UINT16),\r
       sizeof (UINT16)\r
       );\r
-    ImageLength = sizeof (EFI_IMAGE_INPUT) +\r
-                  sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * (Width * Height - 1);\r
-    if (*ImageSize < ImageLength) {\r
-      *ImageSize = ImageLength;\r
-      return EFI_BUFFER_TOO_SMALL;\r
+    ImageLength = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * (Width * Height);\r
+    Image->Bitmap = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocateZeroPool (ImageLength);\r
+    if (Image->Bitmap == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
     }\r
-    ZeroMem (Image, ImageLength);\r
 \r
     if (Flag) {\r
       Image->Flags = EFI_IMAGE_TRANSPARENT;\r
@@ -999,7 +998,7 @@ HiiGetImage (
 \r
   @retval EFI_SUCCESS            The new image was updated successfully.\r
   @retval EFI_NOT_FOUND          The image specified by ImageId is not in the\r
-                                 database.\r
+                                                database. The specified PackageList is not in the database.    \r
   @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
 \r
 **/\r
@@ -1036,7 +1035,7 @@ HiiSetImage (
   UINT32                               Part1Size;\r
   UINT32                               Part2Size;\r
 \r
-  if (This == NULL || Image == NULL || ImageId < 1 || PackageList == NULL) {\r
+  if (This == NULL || Image == NULL || ImageId < 1 || Image->Bitmap == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -1448,9 +1447,9 @@ HiiDrawImage (
 \r
   @retval EFI_SUCCESS            The image was successfully drawn.\r
   @retval EFI_OUT_OF_RESOURCES   Unable to allocate an output buffer for Blt.\r
-  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
-  @retval EFI_NOT_FOUND          The specified packagelist could not be found in\r
-                                 current database.\r
+  @retval EFI_INVALID_PARAMETER  The Blt was NULL.\r
+  @retval EFI_NOT_FOUND          The image specified by ImageId is not in the database. \r
+                           The specified PackageList is not in the database.                             \r
 \r
 **/\r
 EFI_STATUS\r
@@ -1466,14 +1465,12 @@ HiiDrawImageId (
   )\r
 {\r
   EFI_STATUS                          Status;\r
-  EFI_IMAGE_INPUT                     ImageTemp;\r
-  EFI_IMAGE_INPUT                     *Image;\r
-  UINTN                               ImageSize;\r
+  EFI_IMAGE_INPUT                     Image;\r
 \r
   //\r
   // Check input parameter.\r
   //\r
-  if (This == NULL || PackageList == NULL || Blt == NULL || PackageList == NULL) {\r
+  if (This == NULL || Blt == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -1484,24 +1481,16 @@ HiiDrawImageId (
   //\r
   // Get the specified Image.\r
   //\r
-  ImageSize = 0;\r
-  Status = HiiGetImage (This, PackageList, ImageId, &ImageTemp, &ImageSize);\r
-  if (Status != EFI_BUFFER_TOO_SMALL) {\r
+  Status = HiiGetImage (This, PackageList, ImageId, &Image);\r
+  if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  Image = (EFI_IMAGE_INPUT *) AllocateZeroPool (ImageSize);\r
-  if (Image == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  Status = HiiGetImage (This, PackageList, ImageId, Image, &ImageSize);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   //\r
   // Draw this image.\r
   //\r
-  Status = HiiDrawImage (This, Flags, Image, Blt, BltX, BltY);\r
-  SafeFreePool (Image);\r
+  Status = HiiDrawImage (This, Flags, &Image, Blt, BltX, BltY);\r
+  SafeFreePool (Image.Bitmap);\r
   return Status;\r
 }\r
 \r
index 0d830106cd7532a55bc6fd964fffeb25d287e2da..f6a4cdf02d028b2dd05c894487d645ac88f0c732 100644 (file)
@@ -40,6 +40,7 @@ CHAR16 mLanguageWindow[16] = {
 \r
   @param  Private                Hii database private structure.\r
   @param  StringPackage          HII string package instance.\r
+  @param  FontId                Font identifer, which must be unique within the string package.\r
   @param  DuplicateEnable        If true, duplicate HII_FONT_INFO which refers to\r
                                  the same EFI_FONT_INFO is permitted. Otherwise it\r
                                  is not allowed.\r
@@ -57,6 +58,7 @@ BOOLEAN
 ReferFontInfoLocally (\r
   IN  HII_DATABASE_PRIVATE_DATA   *Private,\r
   IN  HII_STRING_PACKAGE_INSTANCE *StringPackage,\r
+  IN  UINT8                       FontId,\r
   IN  BOOLEAN                     DuplicateEnable,\r
   IN  HII_GLOBAL_FONT_INFO        *GlobalFontInfo,\r
   OUT HII_FONT_INFO               **LocalFontInfo\r
@@ -82,11 +84,6 @@ ReferFontInfoLocally (
       }\r
     }\r
   }\r
-  //\r
-  // Since string package tool set FontId initially to 0 and increases it\r
-  // progressively by one, StringPackage->FondId always represents an unique\r
-  // and available FontId.\r
-  //\r
   // FontId identifies EFI_FONT_INFO in local string package uniquely.\r
   // GlobalEntry points to a HII_GLOBAL_FONT_INFO which identifies\r
   // EFI_FONT_INFO uniquely in whole hii database.\r
@@ -95,12 +92,10 @@ ReferFontInfoLocally (
   ASSERT (LocalFont != NULL);\r
 \r
   LocalFont->Signature   = HII_FONT_INFO_SIGNATURE;\r
-  LocalFont->FontId      = StringPackage->FontId;\r
+  LocalFont->FontId      = FontId;\r
   LocalFont->GlobalEntry = &GlobalFontInfo->Entry;\r
   InsertTailList (&StringPackage->FontInfoList, &LocalFont->Entry);\r
 \r
-  StringPackage->FontId++;\r
-\r
   *LocalFontInfo = LocalFont;\r
   return FALSE;\r
 }\r
@@ -183,13 +178,12 @@ GetUnicodeStringTextOrSize (
     StringPtr += sizeof (CHAR16);\r
   }\r
 \r
+  if (*BufferSize < StringSize) {\r
+    *BufferSize = StringSize;\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
   if (StringDest != NULL) {\r
-    if (*BufferSize < StringSize) {\r
-      *BufferSize = StringSize;\r
-      return EFI_BUFFER_TOO_SMALL;\r
-    }\r
     CopyMem (StringDest, StringSrc, StringSize);\r
-    return EFI_SUCCESS;\r
   }\r
 \r
   *BufferSize = StringSize;\r
@@ -292,6 +286,7 @@ FindStringBlock (
   UINT16                               FontSize;\r
   UINT8                                Length8;\r
   EFI_HII_SIBT_EXT2_BLOCK              Ext2;\r
+  UINT8                                FontId;\r
   UINT32                               Length32;\r
   UINTN                                StringSize;\r
   CHAR16                               Zero;\r
@@ -486,7 +481,9 @@ FindStringBlock (
         // Find the relationship between global font info and the font info of\r
         // this EFI_HII_SIBT_FONT block then backup its information in local package.\r
         //\r
-        BlockHdr += sizeof (EFI_HII_SIBT_EXT2_BLOCK) + sizeof (UINT8);\r
+        BlockHdr += sizeof (EFI_HII_SIBT_EXT2_BLOCK);\r
+        CopyMem (&FontId, BlockHdr, sizeof (UINT8));\r
+        BlockHdr += sizeof (UINT8);\r
         CopyMem (&FontSize, BlockHdr, sizeof (UINT16));\r
         BlockHdr += sizeof (UINT16);\r
         CopyMem (&FontStyle, BlockHdr, sizeof (EFI_HII_FONT_STYLE));\r
@@ -502,16 +499,21 @@ FindStringBlock (
         FontInfo->FontSize  = FontSize;\r
         CopyMem (FontInfo->FontName, BlockHdr, StringSize);\r
 \r
+        //\r
+        // If find the corresponding global font info, save the relationship.\r
+        // Otherwise ignore this EFI_HII_SIBT_FONT block.\r
+        //\r
         if (IsFontInfoExisted (Private, FontInfo, NULL, NULL, &GlobalFont)) {\r
-          //\r
-          // If find the corresponding global font info, save the relationship.\r
-          //\r
-          ReferFontInfoLocally (Private, StringPackage, TRUE, GlobalFont, &LocalFont);\r
+          ReferFontInfoLocally (Private, StringPackage, FontId, TRUE, GlobalFont, &LocalFont);\r
         }\r
 \r
         //\r
-        // If can not find, ignore this EFI_HII_SIBT_FONT block.\r
-        //\r
+        // Since string package tool set FontId initially to 0 and increases it\r
+        // progressively by one, StringPackage->FondId always represents an unique\r
+        // and available FontId.\r
+        //        \r
+        StringPackage->FontId++;\r
+\r
         SafeFreePool (FontInfo);\r
       }\r
 \r
@@ -647,7 +649,8 @@ GetStringWorker (
   }\r
 \r
   //\r
-  // Get the string font.\r
+  // Get the string font. The FontId 0 is the default font for those string blocks which \r
+  // do not specify a font identifier. If default font is not specified, return NULL.\r
   //\r
   if (StringFontInfo != NULL) {\r
     switch (BlockType) {\r
@@ -656,10 +659,13 @@ GetStringWorker (
     case EFI_HII_SIBT_STRING_UCS2_FONT:\r
     case EFI_HII_SIBT_STRINGS_UCS2_FONT:\r
       FontId = *(StringBlockAddr + sizeof (EFI_HII_STRING_BLOCK));\r
-      return GetStringFontInfo (StringPackage, FontId, StringFontInfo);\r
       break;\r
     default:\r
-      break;\r
+      FontId = 0;\r
+    }\r
+    Status = GetStringFontInfo (StringPackage, FontId, StringFontInfo);\r
+    if (Status == EFI_NOT_FOUND) {\r
+        *StringFontInfo = NULL;\r
     }\r
   }\r
 \r
@@ -737,38 +743,48 @@ SetStringWorker (
   Referred   = FALSE;\r
 \r
   //\r
-  // Set the string font according to input font information.\r
+  // The input StringFontInfo should exist in current database if specified.\r
   //\r
   if (StringFontInfo != NULL) {\r
-    //\r
-    // The input StringFontInfo should exist in current database\r
-    //\r
     if (!IsFontInfoExisted (Private, StringFontInfo, NULL, NULL, &GlobalFont)) {\r
       return EFI_INVALID_PARAMETER;\r
     } else {\r
-      Referred = ReferFontInfoLocally (Private, StringPackage, FALSE, GlobalFont, &LocalFont);\r
+      Referred = ReferFontInfoLocally (\r
+                   Private, \r
+                   StringPackage, \r
+                   StringPackage->FontId, \r
+                   FALSE, \r
+                   GlobalFont, \r
+                   &LocalFont\r
+                   );\r
+      if (!Referred) {\r
+        StringPackage->FontId++;\r
+      }\r
     }\r
-\r
     //\r
-    // Update the FontId of the specified string block\r
+    // Update the FontId of the specified string block to input font info.\r
     //\r
     switch (BlockType) {\r
-    case EFI_HII_SIBT_STRING_SCSU_FONT:\r
+    case EFI_HII_SIBT_STRING_SCSU_FONT:  \r
     case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r
     case EFI_HII_SIBT_STRING_UCS2_FONT:\r
     case EFI_HII_SIBT_STRINGS_UCS2_FONT:\r
       *(StringBlockAddr + sizeof (EFI_HII_STRING_BLOCK)) = LocalFont->FontId;\r
       break;\r
     default:\r
-      return EFI_NOT_FOUND;\r
+      //\r
+      // When modify the font info of these blocks, the block type should be updated\r
+      // to contain font info thus the whole structure should be revised.\r
+      // It is recommended to use tool to modify the block type not in the code.\r
+      //      \r
+      return EFI_UNSUPPORTED;\r
     }\r
-\r
   }\r
 \r
   OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;\r
 \r
   //\r
-  // Set the string text.\r
+  // Set the string text and font.\r
   //\r
   StringTextPtr = StringBlockAddr + StringTextOffset;\r
   switch (BlockType) {\r
@@ -1138,7 +1154,7 @@ HiiNewString (
     //\r
     Ucs2FontBlockSize = (UINT32) (StrSize (String) + sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) -\r
                                   sizeof (CHAR16));\r
-    if (ReferFontInfoLocally (Private, StringPackage, FALSE, GlobalFont, &LocalFont)) {\r
+    if (ReferFontInfoLocally (Private, StringPackage, StringPackage->FontId, FALSE, GlobalFont, &LocalFont)) {\r
       //\r
       // Create a EFI_HII_SIBT_STRING_UCS2_FONT block only.\r
       //\r
@@ -1229,6 +1245,12 @@ HiiNewString (
       StringPackage->StringBlock = StringBlock;\r
       StringPackage->StringPkgHdr->Header.Length += FontBlockSize + Ucs2FontBlockSize;\r
       PackageListNode->PackageListHdr.PackageLength += FontBlockSize + Ucs2FontBlockSize;\r
+\r
+      //\r
+      // Increase the FontId to make it unique since we already add \r
+      // a EFI_HII_SIBT_FONT block to this string package.\r
+      //\r
+      StringPackage->FontId++;\r
     }\r
   }\r
 \r
@@ -1258,7 +1280,9 @@ HiiNewString (
   @retval EFI_SUCCESS            The string was returned successfully.\r
   @retval EFI_NOT_FOUND          The string specified by StringId is not available.\r
   @retval EFI_NOT_FOUND          The string specified by StringId is available but\r
-                                 not in the specified language.\r
+                                                not in the specified language.\r
+                                                The specified PackageList is not in the database.\r
+  @retval EFI_INVALID_LANGUAGE   - The string specified by StringId is available but\r
   @retval EFI_BUFFER_TOO_SMALL   The buffer specified by StringSize is too small to\r
                                   hold the string.\r
   @retval EFI_INVALID_PARAMETER  The String or Language or StringSize was NULL.\r
@@ -1309,18 +1333,34 @@ HiiGetString (
   }\r
 \r
   if (PackageListNode != NULL) {\r
+    //\r
+    // First search: to match the StringId in the specified language.\r
+    //\r
     for (Link =  PackageListNode->StringPkgHdr.ForwardLink;\r
          Link != &PackageListNode->StringPkgHdr;\r
          Link =  Link->ForwardLink\r
         ) {\r
-      StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r
-      if (R8_EfiLibCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language)) {\r
-        Status = GetStringWorker (Private, StringPackage, StringId, String, StringSize, StringFontInfo);\r
-        if (Status != EFI_NOT_FOUND) {\r
-          return Status;\r
+        StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r
+        if (R8_EfiLibCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language)) {\r
+          Status = GetStringWorker (Private, StringPackage, StringId, String, StringSize, StringFontInfo);\r
+          if (Status != EFI_NOT_FOUND) {\r
+            return Status;\r
+          }\r
         }\r
       }\r
-    }\r
+      //\r
+      // Second search: to match the StringId in other available languages if exist.\r
+      //\r
+      for (Link =  PackageListNode->StringPkgHdr.ForwardLink; \r
+           Link != &PackageListNode->StringPkgHdr;\r
+           Link =  Link->ForwardLink\r
+          ) {\r
+      StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);      \r
+      Status = GetStringWorker (Private, StringPackage, StringId, String, StringSize, StringFontInfo);\r
+      if (!EFI_ERROR (Status)) {\r
+        return EFI_INVALID_LANGUAGE;\r
+      }\r
+    }    \r
   }\r
 \r
   return EFI_NOT_FOUND;\r
@@ -1528,8 +1568,9 @@ HiiGetLanguages (
                                  too small to hold the returned information.\r
                                  SecondLanguageSize is updated to hold the size of\r
                                  the buffer required.\r
-  @retval EFI_NOT_FOUND          The language specified by FirstLanguage is not\r
-                                 present in the specified package list.\r
+  @retval EFI_INVALID_LANGUAGE           The language specified by FirstLanguage is not\r
+                                  present in the specified package list.\r
+  @retval EFI_NOT_FOUND          The specified PackageList is not in the Database.                                \r
 \r
 **/\r
 EFI_STATUS\r
@@ -1562,45 +1603,51 @@ HiiGetSecondaryLanguages (
   }\r
 \r
   Private    = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
-  Languages  = NULL;\r
-  ResultSize = 0;\r
 \r
+  PackageListNode = NULL;     \r
   for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {\r
     DatabaseRecord  = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r
     if (DatabaseRecord->Handle == PackageList) {\r
       PackageListNode = (HII_DATABASE_PACKAGE_LIST_INSTANCE *) (DatabaseRecord->PackageList);\r
-      for (Link1 = PackageListNode->StringPkgHdr.ForwardLink;\r
-           Link1 != &PackageListNode->StringPkgHdr;\r
-           Link1 = Link1->ForwardLink\r
-          ) {\r
-        StringPackage = CR (Link1, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r
-        if (R8_EfiLibCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) FirstLanguage)) {\r
-          Languages = StringPackage->StringPkgHdr->Language;\r
-          //\r
-          // Language is a series of ';' terminated strings, first one is primary\r
-          // language and following with other secondary languages or NULL if no\r
-          // secondary languages any more.\r
-          //\r
-          Languages = AsciiStrStr (Languages, ";");\r
-          if (Languages == NULL) {\r
-            break;\r
-          }\r
-          Languages++;\r
-\r
-          ResultSize = AsciiStrSize (Languages);\r
-          if (ResultSize <= *SecondLanguagesSize) {\r
-            AsciiStrCpy (SecondLanguages, Languages);\r
-          } else {\r
-            *SecondLanguagesSize = ResultSize;\r
-            return EFI_BUFFER_TOO_SMALL;\r
-          }\r
+        break;\r
+      }\r
+    }\r
+    if (PackageListNode == NULL) {\r
+      return EFI_NOT_FOUND;\r
+    }\r
+      \r
+    Languages  = NULL;\r
+    ResultSize = 0;\r
+    for (Link1 = PackageListNode->StringPkgHdr.ForwardLink;\r
+         Link1 != &PackageListNode->StringPkgHdr;\r
+         Link1 = Link1->ForwardLink\r
+        ) {\r
+    StringPackage = CR (Link1, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r
+    if (R8_EfiLibCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) FirstLanguage)) {\r
+      Languages = StringPackage->StringPkgHdr->Language;\r
+      //\r
+      // Language is a series of ';' terminated strings, first one is primary\r
+      // language and following with other secondary languages or NULL if no\r
+      // secondary languages any more.\r
+      //\r
+      Languages = AsciiStrStr (Languages, ";");\r
+      if (Languages == NULL) {\r
+        break;\r
+      }\r
+      Languages++;\r
 \r
-          return EFI_SUCCESS;\r
-        }\r
+      ResultSize = AsciiStrSize (Languages);\r
+      if (ResultSize <= *SecondLanguagesSize) {\r
+        AsciiStrCpy (SecondLanguages, Languages);\r
+      } else {\r
+        *SecondLanguagesSize = ResultSize;\r
+        return EFI_BUFFER_TOO_SMALL;\r
       }\r
+\r
+      return EFI_SUCCESS;\r
     }\r
   }\r
 \r
-  return EFI_NOT_FOUND;\r
+  return EFI_INVALID_LANGUAGE;\r
 }\r
 \r
index c813081454965cc3809213c6acde88edc4d3995e..9108acb473ea6ded418216d2e23f1675ea62ee8d 100644 (file)
@@ -1,5 +1,5 @@
 /** @file
-Copyright (c) 2007, Intel Corporation
+Copyright (c) 2007 - 2008, Intel Corporation
 All rights reserved. This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -1233,11 +1233,11 @@ ParseOpCodes (
       //
       CurrentStatement->Minimum = ((EFI_IFR_STRING *) OpCodeData)->MinSize;
       CurrentStatement->Maximum = ((EFI_IFR_STRING *) OpCodeData)->MaxSize;
-      CurrentStatement->StorageWidth = (UINT16)((UINTN) CurrentStatement->Maximum * sizeof (UINT16));
+      CurrentStatement->StorageWidth = (UINT16)((UINTN) CurrentStatement->Maximum * sizeof (CHAR16));
       CurrentStatement->Flags = ((EFI_IFR_STRING *) OpCodeData)->Flags;
 
       CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_STRING;
-      CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth);
+      CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth + sizeof (CHAR16));
 
       InitializeRequestElement (FormSet, CurrentStatement);
       break;
@@ -1252,10 +1252,10 @@ ParseOpCodes (
       //
       CopyMem (&CurrentStatement->Minimum, &((EFI_IFR_PASSWORD *) OpCodeData)->MinSize, sizeof (UINT16));
       CopyMem (&CurrentStatement->Maximum, &((EFI_IFR_PASSWORD *) OpCodeData)->MaxSize, sizeof (UINT16));
-      CurrentStatement->StorageWidth = (UINT16)((UINTN) CurrentStatement->Maximum * sizeof (UINT16));
+      CurrentStatement->StorageWidth = (UINT16)((UINTN) CurrentStatement->Maximum * sizeof (CHAR16));
 
       CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_STRING;
-      CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth);
+      CurrentStatement->BufferValue = AllocateZeroPool ((CurrentStatement->StorageWidth + sizeof (CHAR16)));
 
       InitializeRequestElement (FormSet, CurrentStatement);
       break;
index 820353131f47ecdbce57791757ebd2daacdb45f6..ff857750efdcd140e4389d60bfdfb5456f9bc246 100644 (file)
@@ -1,5 +1,5 @@
 /** @file
-Copyright (c) 2007, Intel Corporation
+Copyright (c) 2007 - 2008, Intel Corporation
 All rights reserved. This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -1173,7 +1173,11 @@ GetQuestionValue (
       }
 
       if (IsString) {
-        StrCpy ((CHAR16 *) Dst, Value);
+        //
+        // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
+        //
+        Length = StorageWidth + sizeof (CHAR16);
+        Status = ConfigStringToUnicode ((CHAR16 *) Dst, &Length, Value);
       } else {
         Status = HexStringToBuf (Dst, &StorageWidth, Value, NULL);
       }
@@ -1239,7 +1243,11 @@ GetQuestionValue (
     //
     Value = Value + 1;
     if (!IsBufferStorage && IsString) {
-      StrCpy ((CHAR16 *) Dst, Value);
+      //
+      // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
+      //
+      Length = StorageWidth + sizeof (CHAR16);
+      Status = ConfigStringToUnicode ((CHAR16 *) Dst, &Length, Value);
     } else {
       Status = HexStringToBuf (Dst, &StorageWidth, Value, NULL);
       if (EFI_ERROR (Status)) {
@@ -1408,13 +1416,21 @@ SetQuestionValue (
     CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);
   } else {
     if (IsString) {
+      //
+      // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
+      //
       Value = NULL;
-      NewStringCpy (&Value, (CHAR16 *) Src);
-    } else {
-      BufferLen = (StorageWidth * 2 + 1) * sizeof (CHAR16);
+      BufferLen = ((StrLen ((CHAR16 *) Src) * 4) + 1) * sizeof (CHAR16);
       Value = AllocateZeroPool (BufferLen);
       ASSERT (Value != NULL);
+      Status = UnicodeToConfigString (Value, &BufferLen, (CHAR16 *) Src);
+      ASSERT_EFI_ERROR (Status);
+    } else {
+      BufferLen = StorageWidth * 2 + 1;
+      Value = AllocateZeroPool (BufferLen * sizeof (CHAR16));
+      ASSERT (Value != NULL);
       BufToHexString (Value, &BufferLen, Src, StorageWidth);
+      ToLower (Value);
     }
 
     Status = SetValueByName (Storage, Question->VariableName, Value);
@@ -1424,7 +1440,7 @@ SetQuestionValue (
   if (!Cached) {
     //
     // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
-    //                <ConfigHdr> + "&" + <VariableName> + "=" + "<HexCh>StorageWidth * 2"
+    //                <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
     //
     if (IsBufferStorage) {
       Length = StrLen (Question->BlockName) + 7;
@@ -1432,7 +1448,7 @@ SetQuestionValue (
       Length = StrLen (Question->VariableName) + 2;
     }
     if (!IsBufferStorage && IsString) {
-      Length += StrLen ((CHAR16 *) Src);
+      Length += (StrLen ((CHAR16 *) Src) * 4);
     } else {
       Length += (StorageWidth * 2);
     }
@@ -1451,10 +1467,16 @@ SetQuestionValue (
 
     Value = ConfigResp + StrLen (ConfigResp);
     if (!IsBufferStorage && IsString) {
-      StrCpy (Value, (CHAR16 *) Src);
+      //
+      // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
+      //
+      BufferLen = ((StrLen ((CHAR16 *) Src) * 4) + 1) * sizeof (CHAR16);
+      Status = UnicodeToConfigString (Value, &BufferLen, (CHAR16 *) Src);
+      ASSERT_EFI_ERROR (Status);
     } else {
-      BufferLen = (StorageWidth * 2 + 1) * sizeof (CHAR16);
+      BufferLen = StorageWidth * 2 + 1;
       BufToHexString (Value, &BufferLen, Src, StorageWidth);
+      ToLower (Value);
     }
 
     //
index 064a8d9e33e19911a3db3b53cc3276be6071ccaa..04b9f693031f0161329fa2d9030ab2a157c794ad 100644 (file)
@@ -2299,7 +2299,7 @@ UiDisplayMenu (
             Selection->Statement = NULL;
             break;
           }
-          BufferSize = StrLen (StringPtr) / 4;
+          BufferSize = StrLen (StringPtr) / 2;
           DevicePath = AllocatePool (BufferSize);
 
           HexStringToBuffer ((UINT8 *) DevicePath, &BufferSize, StringPtr);