]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c
Remove the check of signature because the code which looks for the input NotifyHandle...
[mirror_edk2.git] / MdeModulePkg / Universal / Console / ConSplitterDxe / ConSplitter.c
index ab42b924dd55f8a163d9ca0fafe1f9c131a4362b..38004bb31c15c4c3efee5a767a3d675c4ee8a306 100644 (file)
@@ -1708,12 +1708,12 @@ ConSplitterStdErrDriverBindingStop (
 \r
 \r
 /**\r
-  Take the passed in Buffer of size SizeOfCount and grow the buffer\r
-  by MAX (CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT, MaxGrow) * SizeOfCount\r
-  bytes. Copy the current data in Buffer to the new version of Buffer\r
-  and free the old version of buffer.\r
+  Take the passed in Buffer of size ElementSize and grow the buffer\r
+  by CONSOLE_SPLITTER_ALLOC_UNIT * ElementSize bytes.\r
+  Copy the current data in Buffer to the new version of Buffer and\r
+  free the old version of buffer.\r
 \r
-  @param  SizeOfCount              Size of element in array.\r
+  @param  ElementSize              Size of element in array.\r
   @param  Count                    Current number of elements in array.\r
   @param  Buffer                   Bigger version of passed in Buffer with all the\r
                                    data.\r
@@ -1724,7 +1724,7 @@ ConSplitterStdErrDriverBindingStop (
 **/\r
 EFI_STATUS\r
 ConSplitterGrowBuffer (\r
-  IN      UINTN                       SizeOfCount,\r
+  IN      UINTN                       ElementSize,\r
   IN OUT  UINTN                       *Count,\r
   IN OUT  VOID                        **Buffer\r
   )\r
@@ -1736,15 +1736,15 @@ ConSplitterGrowBuffer (
   // copy the old buffer's content to the new-size buffer,\r
   // then free the old buffer.\r
   //\r
-  *Count += CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT;\r
   Ptr = ReallocatePool (\r
-          SizeOfCount * ((*Count) - CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT),\r
-          SizeOfCount * (*Count),\r
+          ElementSize * (*Count),\r
+          ElementSize * ((*Count) + CONSOLE_SPLITTER_ALLOC_UNIT),\r
           *Buffer\r
           );\r
   if (Ptr == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+  *Count += CONSOLE_SPLITTER_ALLOC_UNIT;\r
   *Buffer = Ptr;\r
   return EFI_SUCCESS;\r
 }\r
@@ -1847,12 +1847,28 @@ ConSplitterTextInExAddDevice (
   IN  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL     *TextInEx\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS                  Status;\r
+  LIST_ENTRY                  *Link;\r
+  TEXT_IN_EX_SPLITTER_NOTIFY  *CurrentNotify;\r
+  UINTN                       TextInExListCount;\r
 \r
   //\r
-  // If the Text Input Ex List is full, enlarge it by calling ConSplitterGrowBuffer().\r
+  // Enlarge the NotifyHandleList and the TextInExList\r
   //\r
   if (Private->CurrentNumberOfExConsoles >= Private->TextInExListCount) {\r
+    for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {\r
+      CurrentNotify     = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);\r
+      TextInExListCount = Private->TextInExListCount;\r
+\r
+      Status = ConSplitterGrowBuffer (\r
+                 sizeof (EFI_HANDLE),\r
+                 &TextInExListCount,\r
+                 (VOID **) &CurrentNotify->NotifyHandleList\r
+                 );\r
+      if (EFI_ERROR (Status)) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+    }\r
     Status = ConSplitterGrowBuffer (\r
               sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),\r
               &Private->TextInExListCount,\r
@@ -1862,6 +1878,30 @@ ConSplitterTextInExAddDevice (
       return EFI_OUT_OF_RESOURCES;\r
     }\r
   }\r
+\r
+  //\r
+  // Register the key notify in the new text-in device\r
+  //\r
+  for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {\r
+    CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);\r
+    Status = TextInEx->RegisterKeyNotify (\r
+                         TextInEx,\r
+                         &CurrentNotify->KeyData,\r
+                         CurrentNotify->KeyNotificationFn,\r
+                         &CurrentNotify->NotifyHandleList[Private->CurrentNumberOfExConsoles]\r
+                         );\r
+    if (EFI_ERROR (Status)) {\r
+      for (Link = Link->BackLink; Link != &Private->NotifyList; Link = Link->BackLink) {\r
+        CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);\r
+        TextInEx->UnregisterKeyNotify (\r
+                    TextInEx,\r
+                    CurrentNotify->NotifyHandleList[Private->CurrentNumberOfExConsoles]\r
+                    );\r
+      }\r
+      return Status;\r
+    }\r
+  }\r
+\r
   //\r
   // Add the new text-in device data structure into the Text Input Ex List.\r
   //\r
@@ -3583,14 +3623,6 @@ ConSplitterTextInRegisterKeyNotify (
 \r
   Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
 \r
-  //\r
-  // If no physical console input device exists,\r
-  // return EFI_SUCCESS directly.\r
-  //\r
-  if (Private->CurrentNumberOfExConsoles <= 0) {\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
   //\r
   // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.\r
   //\r
@@ -3611,7 +3643,7 @@ ConSplitterTextInRegisterKeyNotify (
   if (NewNotify == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  NewNotify->NotifyHandleList = (EFI_HANDLE *) AllocateZeroPool (sizeof (EFI_HANDLE) * Private->CurrentNumberOfExConsoles);\r
+  NewNotify->NotifyHandleList = (EFI_HANDLE *) AllocateZeroPool (sizeof (EFI_HANDLE) *  Private->TextInExListCount);\r
   if (NewNotify->NotifyHandleList == NULL) {\r
     gBS->FreePool (NewNotify);\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -3633,6 +3665,15 @@ ConSplitterTextInRegisterKeyNotify (
                                              &NewNotify->NotifyHandleList[Index]\r
                                              );\r
     if (EFI_ERROR (Status)) {\r
+      //\r
+      // Un-register the key notify on all physical console input devices\r
+      //\r
+      while (Index-- != 0) {\r
+        Private->TextInExList[Index]->UnregisterKeyNotify (\r
+                                        Private->TextInExList[Index],\r
+                                        NewNotify->NotifyHandleList[Index]\r
+                                        );\r
+      }\r
       gBS->FreePool (NewNotify->NotifyHandleList);\r
       gBS->FreePool (NewNotify);\r
       return Status;\r
@@ -3668,7 +3709,6 @@ ConSplitterTextInUnregisterKeyNotify (
   )\r
 {\r
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
-  EFI_STATUS                    Status;\r
   UINTN                         Index;\r
   TEXT_IN_EX_SPLITTER_NOTIFY    *CurrentNotify;\r
   LIST_ENTRY                    *Link;\r
@@ -3677,31 +3717,16 @@ ConSplitterTextInUnregisterKeyNotify (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (((TEXT_IN_EX_SPLITTER_NOTIFY *) NotificationHandle)->Signature != TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
   Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
 \r
-  //\r
-  // if no physical console input device exists,\r
-  // return EFI_SUCCESS directly.\r
-  //\r
-  if (Private->CurrentNumberOfExConsoles <= 0) {\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
   for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {\r
     CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);\r
     if (CurrentNotify->NotifyHandle == NotificationHandle) {\r
       for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {\r
-        Status = Private->TextInExList[Index]->UnregisterKeyNotify (\r
-                                                 Private->TextInExList[Index],\r
-                                                 CurrentNotify->NotifyHandleList[Index]\r
-                                                 );\r
-        if (EFI_ERROR (Status)) {\r
-          return Status;\r
-        }\r
+        Private->TextInExList[Index]->UnregisterKeyNotify (\r
+                                        Private->TextInExList[Index],\r
+                                        CurrentNotify->NotifyHandleList[Index]\r
+                                        );\r
       }\r
       RemoveEntryList (&CurrentNotify->NotifyEntry);\r
 \r