]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c
Install default keyboard layout package in USB keyboard driver.
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbKbDxe / EfiKey.c
index 1ccc8784d028960f9ca1d0388dbc3b62a0281f84..da6ce75b3a8daf59a64d4e3ad453b39ece28cb17 100644 (file)
@@ -120,7 +120,7 @@ USBKeyboardDriverBindingSupported (
 }\r
 \r
 /**\r
-  Starts the device with this driver.\r
+  Starts the keyboard device with this driver.\r
 \r
   This function produces Simple Text Input Protocol and Simple Text Input Ex Protocol,\r
   initializes the keyboard device, and submit Asynchronous Interrupt Transfer to manage\r
@@ -219,7 +219,7 @@ USBKeyboardDriverBindingStart (
   EndpointNumber = UsbKeyboardDevice->InterfaceDescriptor.NumEndpoints;\r
 \r
   //\r
-  // Traverse endpoints to find interrupt endpoints\r
+  // Traverse endpoints to find interrupt endpoint\r
   //\r
   Found = FALSE;\r
   for (Index = 0; Index < EndpointNumber; Index++) {\r
@@ -230,7 +230,7 @@ USBKeyboardDriverBindingStart (
              &EndpointDescriptor\r
              );\r
 \r
-    if ((EndpointDescriptor.Attributes & 0x03) == USB_ENDPOINT_INTERRUPT) {\r
+    if ((EndpointDescriptor.Attributes & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT) {\r
       //\r
       // We only care interrupt endpoint here\r
       //\r
@@ -256,7 +256,7 @@ USBKeyboardDriverBindingStart (
   UsbKeyboardDevice->SimpleInputEx.ReadKeyStrokeEx     = USBKeyboardReadKeyStrokeEx;\r
   UsbKeyboardDevice->SimpleInputEx.SetState            = USBKeyboardSetState;\r
   UsbKeyboardDevice->SimpleInputEx.RegisterKeyNotify   = USBKeyboardRegisterKeyNotify;\r
-  UsbKeyboardDevice->SimpleInputEx.UnregisterKeyNotify = USBKeyboardUnregisterKeyNotify; \r
+  UsbKeyboardDevice->SimpleInputEx.UnregisterKeyNotify = USBKeyboardUnregisterKeyNotify;\r
   \r
   InitializeListHead (&UsbKeyboardDevice->NotifyList);\r
   \r
@@ -279,12 +279,6 @@ USBKeyboardDriverBindingStart (
                   UsbKeyboardDevice,\r
                   &(UsbKeyboardDevice->SimpleInput.WaitForKey)\r
                   );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    goto ErrorExit;\r
-  }\r
-\r
-  Status = InitKeyboardLayout (UsbKeyboardDevice);\r
   if (EFI_ERROR (Status)) {\r
     goto ErrorExit;\r
   }\r
@@ -293,9 +287,8 @@ USBKeyboardDriverBindingStart (
   // Install Simple Text Input Protocol and Simple Text Input Ex Protocol\r
   // for the USB keyboard device.\r
   // USB keyboard is a hot plug device, and expected to work immediately\r
-  // when plugging into system, so a HotPlugDeviceGuid is installed onto\r
-  // the usb keyboard device handle, to distinguish it from other conventional\r
-  // console devices.\r
+  // when plugging into system, other conventional console devices could\r
+  // distinguish it by its device path.\r
   //\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &Controller,\r
@@ -303,14 +296,27 @@ USBKeyboardDriverBindingStart (
                   &UsbKeyboardDevice->SimpleInput,\r
                   &gEfiSimpleTextInputExProtocolGuid,\r
                   &UsbKeyboardDevice->SimpleInputEx,\r
-                  &gEfiHotPlugDeviceGuid,\r
-                  NULL,\r
                   NULL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     goto ErrorExit;\r
   }\r
 \r
+  UsbKeyboardDevice->ControllerHandle = Controller;\r
+  Status = InitKeyboardLayout (UsbKeyboardDevice);\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+      Controller,\r
+      &gEfiSimpleTextInProtocolGuid,\r
+      &UsbKeyboardDevice->SimpleInput,\r
+      &gEfiSimpleTextInputExProtocolGuid,\r
+      &UsbKeyboardDevice->SimpleInputEx,\r
+      NULL\r
+      );\r
+    goto ErrorExit;\r
+  }\r
+\r
+\r
   //\r
   // Reset USB Keyboard Device exhaustively.\r
   //\r
@@ -325,8 +331,6 @@ USBKeyboardDriverBindingStart (
            &UsbKeyboardDevice->SimpleInput,\r
            &gEfiSimpleTextInputExProtocolGuid,\r
            &UsbKeyboardDevice->SimpleInputEx,\r
-           &gEfiHotPlugDeviceGuid,\r
-           NULL,\r
            NULL\r
            );\r
     goto ErrorExit;\r
@@ -356,8 +360,6 @@ USBKeyboardDriverBindingStart (
            &UsbKeyboardDevice->SimpleInput,\r
            &gEfiSimpleTextInputExProtocolGuid,\r
            &UsbKeyboardDevice->SimpleInputEx,\r
-           &gEfiHotPlugDeviceGuid,\r
-           NULL,\r
            NULL\r
            );\r
     goto ErrorExit;\r
@@ -392,7 +394,7 @@ ErrorExit:
     if (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx != NULL) {\r
       gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);\r
     }\r
-    gBS->FreePool (UsbKeyboardDevice);\r
+    FreePool (UsbKeyboardDevice);\r
     UsbKeyboardDevice = NULL;\r
   }\r
   gBS->CloseProtocol (\r
@@ -495,8 +497,6 @@ USBKeyboardDriverBindingStop (
                   &UsbKeyboardDevice->SimpleInput,\r
                   &gEfiSimpleTextInputExProtocolGuid,\r
                   &UsbKeyboardDevice->SimpleInputEx,\r
-                  &gEfiHotPlugDeviceGuid,\r
-                  NULL,\r
                   NULL\r
                   );\r
   //\r
@@ -515,7 +515,7 @@ USBKeyboardDriverBindingStop (
     FreeUnicodeStringTable (UsbKeyboardDevice->ControllerNameTable);\r
   }\r
 \r
-  gBS->FreePool (UsbKeyboardDevice);\r
+  FreePool (UsbKeyboardDevice);\r
 \r
   return Status;\r
 }\r
@@ -815,7 +815,7 @@ KbdFreeNotifyList (
     Link = GetFirstNode (NotifyList);\r
     NotifyNode = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE);\r
     RemoveEntryList (Link);\r
-    gBS->FreePool (NotifyNode);\r
+    FreePool (NotifyNode);\r
   }\r
   \r
   return EFI_SUCCESS;\r
@@ -1031,7 +1031,6 @@ USBKeyboardRegisterKeyNotify (
   )\r
 {\r
   USB_KB_DEV                        *UsbKeyboardDevice;\r
-  EFI_STATUS                        Status;\r
   KEYBOARD_CONSOLE_IN_EX_NOTIFY     *NewNotify;\r
   LIST_ENTRY                        *Link;\r
   LIST_ENTRY                        *NotifyList;\r
@@ -1075,20 +1074,11 @@ USBKeyboardRegisterKeyNotify (
 \r
   NewNotify->Signature         = USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE;     \r
   NewNotify->KeyNotificationFn = KeyNotificationFunction;\r
+  NewNotify->NotifyHandle      = (EFI_HANDLE) NewNotify;\r
   CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA));\r
   InsertTailList (&UsbKeyboardDevice->NotifyList, &NewNotify->NotifyEntry);\r
 \r
-  //\r
-  // Use gSimpleTextInExNotifyGuid to get a valid EFI_HANDLE\r
-  //  \r
-  Status = gBS->InstallMultipleProtocolInterfaces (\r
-                  &NewNotify->NotifyHandle,\r
-                  &gSimpleTextInExNotifyGuid,\r
-                  NULL,\r
-                  NULL\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-  \r
+\r
   *NotifyHandle = NewNotify->NotifyHandle;  \r
   \r
   return EFI_SUCCESS;\r
@@ -1103,7 +1093,6 @@ USBKeyboardRegisterKeyNotify (
 \r
   @retval EFI_SUCCESS              The notification function was unregistered successfully.\r
   @retval EFI_INVALID_PARAMETER    The NotificationHandle is invalid\r
-  @retval EFI_NOT_FOUND            Cannot find the matching entry in database.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1114,7 +1103,6 @@ USBKeyboardUnregisterKeyNotify (
   )\r
 {\r
   USB_KB_DEV                        *UsbKeyboardDevice;\r
-  EFI_STATUS                        Status;\r
   KEYBOARD_CONSOLE_IN_EX_NOTIFY     *CurrentNotify;\r
   LIST_ENTRY                        *Link;\r
   LIST_ENTRY                        *NotifyList;\r
@@ -1122,24 +1110,13 @@ USBKeyboardUnregisterKeyNotify (
   if (NotificationHandle == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }  \r
+\r
+  if (((KEYBOARD_CONSOLE_IN_EX_NOTIFY *) NotificationHandle)->Signature != USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE) {\r
+    return EFI_INVALID_PARAMETER;\r
+  } \r
   \r
   UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);\r
   \r
-  //\r
-  // Check if NotificationHandle is returned from RegisterKeyNotify().\r
-  //\r
-  Status = gBS->OpenProtocol (\r
-                  NotificationHandle,\r
-                  &gSimpleTextInExNotifyGuid,\r
-                  NULL,\r
-                  NULL,\r
-                  NULL,\r
-                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
   //\r
   // Traverse notify list of USB keyboard and remove the entry of NotificationHandle.\r
   //\r
@@ -1158,18 +1135,15 @@ USBKeyboardUnregisterKeyNotify (
       // Remove the notification function from NotifyList and free resources\r
       //\r
       RemoveEntryList (&CurrentNotify->NotifyEntry);      \r
-      Status = gBS->UninstallMultipleProtocolInterfaces (\r
-                      CurrentNotify->NotifyHandle,\r
-                      &gSimpleTextInExNotifyGuid,\r
-                      NULL,\r
-                      NULL\r
-                      );\r
-      ASSERT_EFI_ERROR (Status);\r
-      gBS->FreePool (CurrentNotify);            \r
+\r
+      FreePool (CurrentNotify);            \r
       return EFI_SUCCESS;\r
     }\r
   }\r
 \r
-  return EFI_NOT_FOUND;  \r
+  //\r
+  // Cannot find the matching entry in database.\r
+  //\r
+  return EFI_INVALID_PARAMETER;  \r
 }\r
 \r