From ea1ac7a0f736dfcdb43df01e87037c899693e42b Mon Sep 17 00:00:00 2001
From: vanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Date: Mon, 23 Feb 2009 02:12:01 +0000
Subject: Clean up gEfiHotPlugDeviceGuid in ConPlatformDxe.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7559 6f19259b-4bc3-4df7-8a09-765794883524
---
 .../Universal/Console/ConPlatformDxe/ConPlatform.c | 148 +++++++++++----------
 .../Universal/Console/ConPlatformDxe/ConPlatform.h |  11 +-
 .../Console/ConPlatformDxe/ConPlatformDxe.inf      |   1 -
 3 files changed, 86 insertions(+), 74 deletions(-)

(limited to 'MdeModulePkg/Universal')

diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
index f3aa4a4fb3..0cb07a2971 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
@@ -261,7 +261,7 @@ ConPlatformTextInDriverBindingStart (
   // gEfiConsoleInDeviceGuid to the device handle directly.
   // The policy is, make hot plug device plug in and play immediately.
   //
-  if (IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {
+  if (IsHotPlugDevice (DevicePath)) {
     gBS->InstallMultipleProtocolInterfaces (
            &ControllerHandle,
            &gEfiConsoleInDeviceGuid,
@@ -378,7 +378,7 @@ ConPlatformTextOutDriverBindingStart (
   // and install gEfiConsoleOutDeviceGuid to the device handle directly.
   // The policy is, make hot plug device plug in and play immediately.
   //
-  if (IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {
+  if (IsHotPlugDevice (DevicePath)) {
     gBS->InstallMultipleProtocolInterfaces (
            &ControllerHandle,
            &gEfiConsoleOutDeviceGuid,
@@ -481,32 +481,36 @@ ConPlatformTextInDriverBindingStop (
   EFI_STATUS                Status;
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
 
+  //
+  // Get the Device Path Protocol firstly
+  //
+  Status = gBS->OpenProtocol (
+                  ControllerHandle,
+                  &gEfiDevicePathProtocolGuid,
+                  (VOID **) &DevicePath,
+                  This->DriverBindingHandle,
+                  ControllerHandle,
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
+                  );
+
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
   //
   // If it is not a hot-plug device, first delete it from the ConInDev variable.
   //
-  if (!IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {
+  if (!IsHotPlugDevice (DevicePath)) {
+   //
+    // Remove DevicePath from ConInDev
     //
-    // Get the Device Path Protocol so the environment variables can be updated
-    //
-    Status = gBS->OpenProtocol (
-                    ControllerHandle,
-                    &gEfiDevicePathProtocolGuid,
-                    (VOID **) &DevicePath,
-                    This->DriverBindingHandle,
-                    ControllerHandle,
-                    EFI_OPEN_PROTOCOL_GET_PROTOCOL
-                    );
-    if (!EFI_ERROR (Status)) {
-      //
-      // Remove DevicePath from ConInDev
-      //
-      ConPlatformUpdateDeviceVariable (
-        L"ConInDev",
-        DevicePath,
-        DELETE
-        );
-    }
+    ConPlatformUpdateDeviceVariable (
+      L"ConInDev",
+      DevicePath,
+      DELETE
+      );
   }
+
   //
   // Uninstall the Console Device GUIDs from Controller Handle
   //
@@ -556,37 +560,41 @@ ConPlatformTextOutDriverBindingStop (
   EFI_STATUS                Status;
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
 
+  //
+  // Get the Device Path Protocol firstly
+  //
+  Status = gBS->OpenProtocol (
+                  ControllerHandle,
+                  &gEfiDevicePathProtocolGuid,
+                  (VOID **) &DevicePath,
+                  This->DriverBindingHandle,
+                  ControllerHandle,
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
+                  );
+
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
   //
   // If it is not a hot-plug device, first delete it from the ConOutDev and ErrOutDev variable.
   //
-  if (!IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {
+  if (!IsHotPlugDevice (DevicePath)) {
     //
-    // Get the Device Path Protocol so the environment variables can be updated
+    // Remove DevicePath from ConOutDev, and ErrOutDev
     //
-    Status = gBS->OpenProtocol (
-                    ControllerHandle,
-                    &gEfiDevicePathProtocolGuid,
-                    (VOID **) &DevicePath,
-                    This->DriverBindingHandle,
-                    ControllerHandle,
-                    EFI_OPEN_PROTOCOL_GET_PROTOCOL
-                    );
-    if (!EFI_ERROR (Status)) {
-      //
-      // Remove DevicePath from ConOutDev, and ErrOutDev
-      //
-      ConPlatformUpdateDeviceVariable (
-        L"ConOutDev",
-        DevicePath,
-        DELETE
-        );
-      ConPlatformUpdateDeviceVariable (
-        L"ErrOutDev",
-        DevicePath,
-        DELETE
-        );
-    }
+    ConPlatformUpdateDeviceVariable (
+      L"ConOutDev",
+      DevicePath,
+      DELETE
+      );
+    ConPlatformUpdateDeviceVariable (
+      L"ErrOutDev",
+      DevicePath,
+      DELETE
+      );
   }
+ 
   //
   // Uninstall the Console Device GUIDs from Controller Handle
   //
@@ -929,10 +937,12 @@ ConPlatformUpdateDeviceVariable (
 }
 
 /**
-  Check if the device supports hot-plug.
+  Check if the device supports hot-plug through its device path.
+
+  This function could be updated to check more types of Hot Plug devices.
+  Currently, it checks USB and PCCard device.
 
-  @param  DriverBindingHandle   Protocol instance pointer.
-  @param  ControllerHandle      Handle of device to check.
+  @param  DevicePath            Pointer to device's device path.
 
   @retval TRUE                  The devcie is a hot-plug device
   @retval FALSE                 The devcie is not a hot-plug device.
@@ -940,26 +950,28 @@ ConPlatformUpdateDeviceVariable (
 **/
 BOOLEAN
 IsHotPlugDevice (
-  EFI_HANDLE    DriverBindingHandle,
-  EFI_HANDLE    ControllerHandle
+  IN  EFI_DEVICE_PATH_PROTOCOL    *DevicePath
   )
 {
-  EFI_STATUS  Status;
-
   //
-  // HotPlugDeviceGuid indicates ControllerHandle stands for a hot plug device.
-  //
-  Status = gBS->OpenProtocol (
-                  ControllerHandle,
-                  &gEfiHotPlugDeviceGuid,
-                  NULL,
-                  DriverBindingHandle,
-                  ControllerHandle,
-                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL
-                  );
-  if (EFI_ERROR (Status)) {
-    return FALSE;
+  // Check device whether is hot plug device or not throught Device Path
+  // 
+  if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
+      (DevicePathSubType (DevicePath) == MSG_USB_DP ||
+       DevicePathSubType (DevicePath) == MSG_USB_CLASS_DP ||
+       DevicePathSubType (DevicePath) == MSG_USB_WWID_DP)) {
+    //
+    // If Device is USB device
+    //
+    return TRUE;
+  }
+  if ((DevicePathType (DevicePath) == HARDWARE_DEVICE_PATH) &&
+      (DevicePathSubType (DevicePath) == HW_PCCARD_DP)) {
+    //
+    // If Device is PCCard
+    //
+    return TRUE;
   }
 
-  return TRUE;
+  return FALSE;
 }
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
index f7883dce6c..d0fa03af5b 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
@@ -293,10 +293,12 @@ ConPlatformUpdateDeviceVariable (
   );
 
 /**
-  Check if the device supports hot-plug.
+  Check if the device supports hot-plug through its device path.
 
-  @param  DriverBindingHandle   Protocol instance pointer.
-  @param  ControllerHandle      Handle of device to check.
+  This function could be updated to check more types of Hot Plug devices.
+  Currently, it checks USB and PCCard device.
+
+  @param  DevicePath            Pointer to device's device path.
 
   @retval TRUE                  The devcie is a hot-plug device
   @retval FALSE                 The devcie is not a hot-plug device.
@@ -304,8 +306,7 @@ ConPlatformUpdateDeviceVariable (
 **/
 BOOLEAN
 IsHotPlugDevice (
-  EFI_HANDLE    DriverBindingHandle,
-  EFI_HANDLE    ControllerHandle
+  IN  EFI_DEVICE_PATH_PROTOCOL    *DevicePath
   );
 
 //
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
index a96a6330a0..892d051a1a 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
@@ -87,5 +87,4 @@
   gEfiDevicePathProtocolGuid                    ## TO_START
   gEfiSimpleTextInProtocolGuid                  ## TO_START
   gEfiSimpleTextOutProtocolGuid                 ## TO_START
-  gEfiHotPlugDeviceGuid                         ## SOMETIMES_CONSUMES (Used to check if it's a hot-plug device)
   
\ No newline at end of file
-- 
cgit v1.2.3