X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FConsole%2FConPlatformDxe%2FConPlatform.c;h=9fccfc0cad81b174ceb84c500a0cf3174020263e;hb=ca6b86efedb7694333c77623a3e0a236afd6f1d2;hp=56bdd11693926ffdc7360f1a929173b196acaf4d;hpb=415df2a396a2d7c1bc4be2af6db6cb1ff45f0200;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c index 56bdd11693..9fccfc0cad 100644 --- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c +++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c @@ -1,5 +1,5 @@ /** @file - Console Platfrom DXE Driver, install Console Device Guids and update Console + Console Platform DXE Driver, install Console Device Guids and update Console Environment Variables. Copyright (c) 2006 - 2008, Intel Corporation.
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ -#include +#include "ConPlatform.h" EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextInDriverBinding = { @@ -35,13 +35,15 @@ EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextOutDriverBinding = { }; /** - The user Entry Point for module ConPlatform. The user code starts with this function. + Entrypoint of this module. - @param[in] ImageHandle The firmware allocated handle for the EFI image. - @param[in] SystemTable A pointer to the EFI System Table. + This function is the entrypoint of this module. It installs Driver Binding + Protocols together with Component Name Protocols. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS The entry point is executed successfully. - @retval other Some error occurs when executing this entry point. **/ EFI_STATUS @@ -53,9 +55,6 @@ InitializeConPlatform( { EFI_STATUS Status; - // - // Install driver model protocol(s). - // Status = EfiLibInstallDriverBindingComponentName2 ( ImageHandle, SystemTable, @@ -76,21 +75,20 @@ InitializeConPlatform( ); ASSERT_EFI_ERROR (Status); - - return Status; + return EFI_SUCCESS; } /** - Test to see if EFI Text In Protocol could be supported on the ControllerHandle. + Test to see if EFI_SIMPLE_TEXT_INPUT_PROTOCOL is supported on ControllerHandle. @param This Protocol instance pointer. @param ControllerHandle Handle of device to test. @param RemainingDevicePath Optional parameter use to pick a specific child device to start. - @retval EFI_SUCCESS This driver supports this device - @retval other This driver does not support this device + @retval EFI_SUCCESS This driver supports this device. + @retval other This driver does not support this device. **/ EFI_STATUS @@ -98,28 +96,27 @@ EFIAPI ConPlatformTextInDriverBindingSupported ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) { return ConPlatformDriverBindingSupported ( - This, - ControllerHandle, - RemainingDevicePath, - &gEfiSimpleTextInProtocolGuid - ); + This, + ControllerHandle, + &gEfiSimpleTextInProtocolGuid + ); } /** - Test to see if EFI Text Out Protocol could be supported on the ControllerHandle. + Test to see if EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL is supported on ControllerHandle. @param This Protocol instance pointer. @param ControllerHandle Handle of device to test. @param RemainingDevicePath Optional parameter use to pick a specific child device to start. - @retval EFI_SUCCESS This driver supports this device - @retval other This driver does not support this device + @retval EFI_SUCCESS This driver supports this device. + @retval other This driver does not support this device. **/ EFI_STATUS @@ -127,36 +124,32 @@ EFIAPI ConPlatformTextOutDriverBindingSupported ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) { return ConPlatformDriverBindingSupported ( - This, - ControllerHandle, - RemainingDevicePath, - &gEfiSimpleTextOutProtocolGuid - ); + This, + ControllerHandle, + &gEfiSimpleTextOutProtocolGuid + ); } /** - Test to see if specific Protocol could be supported on the ControllerHandle. + Test to see if the specified protocol is supported on ControllerHandle. @param This Protocol instance pointer. @param ControllerHandle Handle of device to test. - @param RemainingDevicePath Optional parameter use to pick a specific child - device to start. @param ProtocolGuid The specfic protocol. - @retval EFI_SUCCESS This driver supports this device - @retval other This driver does not support this device + @retval EFI_SUCCESS This driver supports this device. + @retval other This driver does not support this device. **/ EFI_STATUS ConPlatformDriverBindingSupported ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath, IN EFI_GUID *ProtocolGuid ) { @@ -164,8 +157,8 @@ ConPlatformDriverBindingSupported ( VOID *Interface; // - // Test to see if this is a physical device by checking to see if - // it has a Device Path Protocol + // Test to see if this is a physical device by checking if + // it has a Device Path Protocol. // Status = gBS->OpenProtocol ( ControllerHandle, @@ -179,7 +172,7 @@ ConPlatformDriverBindingSupported ( return Status; } // - // Test to see if this device supports the specific Protocol + // Test to see if this device supports the specified Protocol. // Status = gBS->OpenProtocol ( ControllerHandle, @@ -194,17 +187,19 @@ ConPlatformDriverBindingSupported ( } gBS->CloseProtocol ( - ControllerHandle, - ProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); + ControllerHandle, + ProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); return EFI_SUCCESS; } /** - Start this driver on ControllerHandle by opening Simple Text In protocol, + Start this driver on the device for console input. + + Start this driver on ControllerHandle by opening Simple Text Input Protocol, reading Device Path, and installing Console In Devcice GUID on ControllerHandle. If this devcie is not one hot-plug devce, append its device path into the @@ -228,9 +223,10 @@ ConPlatformTextInDriverBindingStart ( IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) { - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn; + BOOLEAN IsInConInVariable; // // Get the Device Path Protocol so the environment variables can be updated @@ -247,7 +243,7 @@ ConPlatformTextInDriverBindingStart ( return Status; } // - // Open the Simple Input Protocol BY_DRIVER + // Open the Simple Text Input Protocol BY_DRIVER // Status = gBS->OpenProtocol ( ControllerHandle, @@ -261,21 +257,45 @@ ConPlatformTextInDriverBindingStart ( return Status; } // - // Check the device handle, if it is a hot plug device, + // Check if the device path is in ConIn Variable + // + IsInConInVariable = FALSE; + Status = ConPlatformUpdateDeviceVariable ( + L"ConIn", + DevicePath, + CHECK + ); + if (!EFI_ERROR (Status)) { + IsInConInVariable = TRUE; + } + + // + // Check the device path, if it is a hot plug device, // do not put the device path into ConInDev, and install // 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, - NULL, - NULL - ); + &ControllerHandle, + &gEfiConsoleInDeviceGuid, + NULL, + NULL + ); + // + // Append the device path to ConInDev only if it is in ConIn variable. + // + if (IsInConInVariable) { + ConPlatformUpdateDeviceVariable ( + L"ConInDev", + DevicePath, + APPEND + ); + } } else { // - // Append the device path to the ConInDev environment variable + // If it is not a hot-plug device, append the device path to the + // ConInDev environment variable // ConPlatformUpdateDeviceVariable ( L"ConInDev", @@ -287,26 +307,20 @@ ConPlatformTextInDriverBindingStart ( // If the device path is an instance in the ConIn environment variable, // then install EfiConsoleInDeviceGuid onto ControllerHandle // - Status = ConPlatformUpdateDeviceVariable ( - L"ConIn", - DevicePath, - CHECK - ); - - if (!EFI_ERROR (Status)) { + if (IsInConInVariable) { gBS->InstallMultipleProtocolInterfaces ( - &ControllerHandle, - &gEfiConsoleInDeviceGuid, - NULL, - NULL - ); + &ControllerHandle, + &gEfiConsoleInDeviceGuid, + NULL, + NULL + ); } else { gBS->CloseProtocol ( - ControllerHandle, - &gEfiSimpleTextInProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); + ControllerHandle, + &gEfiSimpleTextInProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); } } @@ -314,12 +328,14 @@ ConPlatformTextInDriverBindingStart ( } /** - Start this driver on ControllerHandle by opening Simple Text Out protocol, + Start this driver on the device for console output and stardard error output. + + Start this driver on ControllerHandle by opening Simple Text Output Protocol, reading Device Path, and installing Console Out Devcic GUID, Standard Error Device GUID on ControllerHandle. If this devcie is not one hot-plug devce, append its device path into the - console environment variables ConOutDev, StdErrDev. + console environment variables ConOutDev, ErrOutDev. @param This Protocol instance pointer. @param ControllerHandle Handle of device to bind driver to @@ -339,10 +355,12 @@ ConPlatformTextOutDriverBindingStart ( IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) { - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut; - BOOLEAN NeedClose; + BOOLEAN NeedClose; + BOOLEAN IsInConOutVariable; + BOOLEAN IsInErrOutVariable; NeedClose = TRUE; @@ -375,21 +393,65 @@ ConPlatformTextOutDriverBindingStart ( return Status; } // - // Check the device handle, if it is a hot plug device, - // do not put the device path into ConOutDev and StdErrDev, + // Check if the device path is in ConOut & ErrOut Variable + // + IsInConOutVariable = FALSE; + Status = ConPlatformUpdateDeviceVariable ( + L"ConOut", + DevicePath, + CHECK + ); + if (!EFI_ERROR (Status)) { + IsInConOutVariable = TRUE; + } + + IsInErrOutVariable = FALSE; + Status = ConPlatformUpdateDeviceVariable ( + L"ErrOut", + DevicePath, + CHECK + ); + if (!EFI_ERROR (Status)) { + IsInErrOutVariable = TRUE; + } + + // + // Check the device path, if it is a hot plug device, + // do not put the device path into ConOutDev and ErrOutDev, // 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, - NULL, - NULL - ); + &ControllerHandle, + &gEfiConsoleOutDeviceGuid, + NULL, + NULL + ); + // + // Append the device path to ConOutDev only if it is in ConOut variable. + // + if (IsInConOutVariable) { + ConPlatformUpdateDeviceVariable ( + L"ConOutDev", + DevicePath, + APPEND + ); + } + // + // Append the device path to ErrOutDev only if it is in ErrOut variable. + // + if (IsInErrOutVariable) { + ConPlatformUpdateDeviceVariable ( + L"ErrOutDev", + DevicePath, + APPEND + ); + } } else { // - // Append the device path to the ConOutDev environment variable + // If it is not a hot-plug device, first append the device path to the + // ConOutDev environment variable // ConPlatformUpdateDeviceVariable ( L"ConOutDev", @@ -397,7 +459,7 @@ ConPlatformTextOutDriverBindingStart ( APPEND ); // - // Append the device path to the StdErrDev environment variable + // Then append the device path to the ErrOutDev environment variable // ConPlatformUpdateDeviceVariable ( L"ErrOutDev", @@ -409,13 +471,7 @@ ConPlatformTextOutDriverBindingStart ( // If the device path is an instance in the ConOut environment variable, // then install EfiConsoleOutDeviceGuid onto ControllerHandle // - Status = ConPlatformUpdateDeviceVariable ( - L"ConOut", - DevicePath, - CHECK - ); - - if (!EFI_ERROR (Status)) { + if (IsInConOutVariable) { NeedClose = FALSE; Status = gBS->InstallMultipleProtocolInterfaces ( &ControllerHandle, @@ -425,31 +481,26 @@ ConPlatformTextOutDriverBindingStart ( ); } // - // If the device path is an instance in the StdErr environment variable, + // If the device path is an instance in the ErrOut environment variable, // then install EfiStandardErrorDeviceGuid onto ControllerHandle // - Status = ConPlatformUpdateDeviceVariable ( - L"ErrOut", - DevicePath, - CHECK - ); - if (!EFI_ERROR (Status)) { + if (IsInErrOutVariable) { NeedClose = FALSE; gBS->InstallMultipleProtocolInterfaces ( - &ControllerHandle, - &gEfiStandardErrorDeviceGuid, - NULL, - NULL - ); + &ControllerHandle, + &gEfiStandardErrorDeviceGuid, + NULL, + NULL + ); } if (NeedClose) { gBS->CloseProtocol ( - ControllerHandle, - &gEfiSimpleTextOutProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); + ControllerHandle, + &gEfiSimpleTextOutProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); } } @@ -458,7 +509,7 @@ ConPlatformTextOutDriverBindingStart ( /** Stop this driver on ControllerHandle by removing Console In Devcice GUID - and closing the Simple Text In protocol on ControllerHandle. + and closing the Simple Text Input protocol on ControllerHandle. @param This Protocol instance pointer. @param ControllerHandle Handle of device to stop driver on @@ -483,32 +534,30 @@ ConPlatformTextInDriverBindingStop ( EFI_DEVICE_PATH_PROTOCOL *DevicePath; // - // hot plug device is not included into the console associated variables, - // so no need to check variable for those hot plug devices. + // Get the Device Path Protocol firstly // - if (!IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) { + Status = gBS->OpenProtocol ( + ControllerHandle, + &gEfiDevicePathProtocolGuid, + (VOID **) &DevicePath, + This->DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + // + // If there is device path on ControllerHandle + // + if (!EFI_ERROR (Status)) { // - // Get the Device Path Protocol so the environment variables can be updated + // Remove DevicePath from ConInDev if exists. // - 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 // @@ -519,14 +568,14 @@ ConPlatformTextInDriverBindingStop ( ); // - // Close the Simple Input Protocol + // Close the Simple Text Input Protocol // gBS->CloseProtocol ( - ControllerHandle, - &gEfiSimpleTextInProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); + ControllerHandle, + &gEfiSimpleTextInProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); return EFI_SUCCESS; } @@ -534,7 +583,7 @@ ConPlatformTextInDriverBindingStop ( /** Stop this driver on ControllerHandle by removing Console Out Devcice GUID - and closing the Simple Text Out protocol on ControllerHandle. + and closing the Simple Text Output protocol on ControllerHandle. @param This Protocol instance pointer. @param ControllerHandle Handle of device to stop driver on @@ -559,37 +608,32 @@ ConPlatformTextOutDriverBindingStop ( EFI_DEVICE_PATH_PROTOCOL *DevicePath; // - // hot plug device is not included into the console associated variables, - // so no need to check variable for those hot plug devices. + // Get the Device Path Protocol firstly // - if (!IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) { + Status = gBS->OpenProtocol ( + ControllerHandle, + &gEfiDevicePathProtocolGuid, + (VOID **) &DevicePath, + This->DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR (Status)) { // - // Get the Device Path Protocol so the environment variables can be updated + // Remove DevicePath from ConOutDev and ErrOutDev if exists. // - Status = gBS->OpenProtocol ( - ControllerHandle, - &gEfiDevicePathProtocolGuid, - (VOID **) &DevicePath, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (!EFI_ERROR (Status)) { - // - // Remove DevicePath from ConOutDev, and StdErrDev - // - 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 // @@ -620,13 +664,11 @@ ConPlatformTextOutDriverBindingStop ( /** - Unstall the specific protocol. + Uninstall the specified protocol. @param This Protocol instance pointer. - @param Handle Handle of device to unstall protocol on. - @param ProtocolGuid The specific protocol need to be uninstalled. - - @return None. + @param Handle Handle of device to uninstall protocol on. + @param ProtocolGuid The specified protocol need to be uninstalled. **/ VOID @@ -649,26 +691,28 @@ ConPlatformUnInstallProtocol ( if (!EFI_ERROR (Status)) { gBS->UninstallMultipleProtocolInterfaces ( - Handle, - ProtocolGuid, - NULL, - NULL - ); + Handle, + ProtocolGuid, + NULL, + NULL + ); } return ; } /** - Read the EFI variable (Name) and return a dynamically allocated - buffer, and the size of the buffer. On failure return NULL. + Get the necessary size of buffer and read the variable. + First get the necessary size of buffer. Then read the + EFI variable (Name) and return a dynamically allocated + buffer. On failure return NULL. @param Name String part of EFI variable name @return Dynamically allocated memory that contains a copy of the EFI variable. - Caller is repsoncible freeing the buffer. - NULL - Variable was not read + Caller is repsoncible freeing the buffer. Return NULL means Variable + was not read. **/ VOID * @@ -684,7 +728,7 @@ ConPlatformGetVariable ( Buffer = NULL; // - // Test to see if the variable exists. If it doesn't reuturn NULL + // Test to see if the variable exists. If it doesn't, return NULL. // Status = gRT->GetVariable ( Name, @@ -714,6 +758,9 @@ ConPlatformGetVariable ( ); if (EFI_ERROR (Status)) { FreePool (Buffer); + // + // To make sure Buffer is NULL if any error occurs. + // Buffer = NULL; } } @@ -725,7 +772,6 @@ ConPlatformGetVariable ( Function compares a device path data structure to that of all the nodes of a second device path instance. - @param Multi A pointer to a multi-instance device path data structure. @param Single A pointer to a single-instance device path data structure. @param NewDevicePath If Delete is TRUE, this parameter must not be null, and it @@ -735,20 +781,24 @@ ConPlatformGetVariable ( If FALSE, the routine just check whether Single matches with any instance in Multi. - @return The function returns EFI_SUCCESS if the Single is contained within Multi. - Otherwise, EFI_NOT_FOUND is returned. + @retval EFI_SUCCESS If the Single is contained within Multi. + @retval EFI_NOT_FOUND If the Single is not contained within Multi. + @retval EFI_INVALID_PARAMETER Multi is NULL. + @retval EFI_INVALID_PARAMETER Single is NULL. + @retval EFI_INVALID_PARAMETER NewDevicePath is NULL when Delete is TRUE. **/ EFI_STATUS ConPlatformMatchDevicePaths ( IN EFI_DEVICE_PATH_PROTOCOL *Multi, IN EFI_DEVICE_PATH_PROTOCOL *Single, - IN EFI_DEVICE_PATH_PROTOCOL **NewDevicePath OPTIONAL, + OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath OPTIONAL, IN BOOLEAN Delete ) { EFI_DEVICE_PATH_PROTOCOL *DevicePath; - EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath1; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath2; EFI_DEVICE_PATH_PROTOCOL *DevicePathInst; UINTN Size; @@ -756,31 +806,49 @@ ConPlatformMatchDevicePaths ( // The passed in DevicePath should not be NULL // if ((Multi == NULL) || (Single == NULL)) { - return EFI_NOT_FOUND; + return EFI_INVALID_PARAMETER; } + // - // if performing Delete operation, the NewDevicePath must not be NULL. + // If performing Delete operation, the NewDevicePath must not be NULL. // - TempDevicePath = NULL; + if (Delete) { + if (NewDevicePath == NULL) { + return EFI_INVALID_PARAMETER; + } + } + + TempDevicePath1 = NULL; DevicePath = Multi; DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size); // - // search for the match of 'Single' in 'Multi' + // Search for the match of 'Single' in 'Multi' // while (DevicePathInst != NULL) { if (CompareMem (Single, DevicePathInst, Size) == 0) { if (!Delete) { + // + // If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi. + // FreePool (DevicePathInst); return EFI_SUCCESS; } } else { if (Delete) { - TempDevicePath = AppendDevicePathInstance ( - NULL, + // + // If the node of Multi does not match Single, then added it back to the result. + // That is, the node matching Single will be dropped and deleted from result. + // + TempDevicePath2 = AppendDevicePathInstance ( + TempDevicePath1, DevicePathInst ); + if (TempDevicePath1 != NULL) { + FreePool (TempDevicePath1); + } + TempDevicePath1 = TempDevicePath2; } } @@ -789,7 +857,10 @@ ConPlatformMatchDevicePaths ( } if (Delete) { - *NewDevicePath = TempDevicePath; + // + // Return the new device path data structure with specified node deleted. + // + *NewDevicePath = TempDevicePath1; return EFI_SUCCESS; } @@ -797,12 +868,12 @@ ConPlatformMatchDevicePaths ( } /** - Update console devicein console environment variables. + Update console environment variables. @param VariableName Console environment variables, ConOutDev, ConInDev - StdErrDev, ConIn or ConOut. + ErrOutDev, ConIn ,ConOut or ErrOut. @param DevicePath Console devcie's device path. - @param Operation Variable operations, such as APPEND or DELETE. + @param Operation Variable operations, including APPEND, CHECK and DELETE. @retval EFI_SUCCESS Variable operates successfully. @retval EFI_OUT_OF_RESOURCES If variable cannot be appended. @@ -831,17 +902,21 @@ ConPlatformUpdateDeviceVariable ( VariableDevicePath = ConPlatformGetVariable (VariableName); if (Operation != DELETE) { - + // + // Match specified DevicePath in Console Variable. + // Status = ConPlatformMatchDevicePaths ( - VariableDevicePath, - DevicePath, - NULL, - FALSE - ); + VariableDevicePath, + DevicePath, + NULL, + FALSE + ); if ((Operation == CHECK) || (!EFI_ERROR (Status))) { // - // The device path is already in the variable + // Branch here includes 2 cases: + // 1. Operation is CHECK, simply return Status. + // 2. Operation is APPEND, and device path already exists in variable, also return. // if (VariableDevicePath != NULL) { FreePool (VariableDevicePath); @@ -850,8 +925,7 @@ ConPlatformUpdateDeviceVariable ( return Status; } // - // The device path is not in variable. Append DevicePath to the - // environment variable that is a multi-instance device path. + // We reach here to append a device path that does not exist in variable. // Status = EFI_SUCCESS; NewVariableDevicePath = AppendDevicePathInstance ( @@ -864,15 +938,15 @@ ConPlatformUpdateDeviceVariable ( } else { // - // Remove DevicePath from the environment variable that + // We reach here to remove DevicePath from the environment variable that // is a multi-instance device path. // Status = ConPlatformMatchDevicePaths ( - VariableDevicePath, - DevicePath, - &NewVariableDevicePath, - TRUE - ); + VariableDevicePath, + DevicePath, + &NewVariableDevicePath, + TRUE + ); } if (VariableDevicePath != NULL) { @@ -884,6 +958,9 @@ ConPlatformUpdateDeviceVariable ( } if (NewVariableDevicePath != NULL) { + // + // Update Console Environment Variable. + // Status = gRT->SetVariable ( VariableName, &gEfiGlobalVariableGuid, @@ -899,10 +976,12 @@ ConPlatformUpdateDeviceVariable ( } /** - Check if the device is one hot-plug supported. + 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. @@ -910,26 +989,36 @@ ConPlatformUpdateDeviceVariable ( **/ BOOLEAN IsHotPlugDevice ( - EFI_HANDLE DriverBindingHandle, - EFI_HANDLE ControllerHandle + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { - EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *CheckDevicePath; - // - // 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; + CheckDevicePath = DevicePath; + while (!IsDevicePathEnd (CheckDevicePath)) { + // + // Check device whether is hot plug device or not throught Device Path + // + if ((DevicePathType (CheckDevicePath) == MESSAGING_DEVICE_PATH) && + (DevicePathSubType (CheckDevicePath) == MSG_USB_DP || + DevicePathSubType (CheckDevicePath) == MSG_USB_CLASS_DP || + DevicePathSubType (CheckDevicePath) == MSG_USB_WWID_DP)) { + // + // If Device is USB device + // + return TRUE; + } + if ((DevicePathType (CheckDevicePath) == HARDWARE_DEVICE_PATH) && + (DevicePathSubType (CheckDevicePath) == HW_PCCARD_DP)) { + // + // If Device is PCCard + // + return TRUE; + } + + CheckDevicePath = NextDevicePathNode (CheckDevicePath); } - return TRUE; + return FALSE; } +