X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=ShellPkg%2FLibrary%2FUefiShellDriver1CommandsLib%2FConnect.c;h=dd3d4a6a27340decd40ba81401ce273dc43c66c0;hb=b5e44fbc15085270adfc777c0f2c1890c1e9790f;hp=7073c44260ad293b5674e3ceca6a70c8fa9d52a3;hpb=361a8267362f755cca29495afa79efa0e9fd9714;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c index 7073c44260..dd3d4a6a27 100644 --- a/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c @@ -1,7 +1,8 @@ /** @file Main file for connect shell Driver1 function. - Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.
+ (C) Copyright 2015 Hewlett-Packard Development Company, L.P.
+ Copyright (c) 2010 - 2016, 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 @@ -14,11 +15,97 @@ #include "UefiShellDriver1CommandsLib.h" +/** + Create all handles associate with every device path node. + + @param DevicePathToConnect The device path which will be connected. + + @retval EFI_SUCCESS All handles associate with every device path node + have been created. + @retval EFI_INVALID_PARAMETER DevicePathToConnect is NULL. + @retval EFI_NOT_FOUND Create the handle associate with one device path + node failed + +**/ +EFI_STATUS +ShellConnectDevicePath ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect + ) +{ + EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath; + EFI_STATUS Status; + EFI_HANDLE Handle; + EFI_HANDLE PreviousHandle; + + if (DevicePathToConnect == NULL) { + return EFI_INVALID_PARAMETER; + } + + PreviousHandle = NULL; + do{ + RemainingDevicePath = DevicePathToConnect; + Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle); + + if (!EFI_ERROR (Status) && (Handle != NULL)) { + if (PreviousHandle == Handle) { + Status = EFI_NOT_FOUND; + } else { + PreviousHandle = Handle; + Status = gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE); + } + } + + } while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath) ); + + return Status; + +} + +/** + Connect drivers for PCI root bridge. + + @retval EFI_SUCCESS Connect drivers successfully. + @retval EFI_NOT_FOUND Cannot find PCI root bridge device. + +**/ +EFI_STATUS +ShellConnectPciRootBridge ( + VOID + ) +{ + UINTN RootBridgeHandleCount; + EFI_HANDLE *RootBridgeHandleBuffer; + UINTN RootBridgeIndex; + EFI_STATUS Status; + + RootBridgeHandleCount = 0; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciRootBridgeIoProtocolGuid, + NULL, + &RootBridgeHandleCount, + &RootBridgeHandleBuffer + ); + if (EFI_ERROR (Status)) { + return Status; + } + + for (RootBridgeIndex = 0; RootBridgeIndex < RootBridgeHandleCount; RootBridgeIndex++) { + gBS->ConnectController (RootBridgeHandleBuffer[RootBridgeIndex], NULL, NULL, FALSE); + } + + FreePool (RootBridgeHandleBuffer); + + return EFI_SUCCESS; +} + + /** Connect controller(s) and driver(s). - @param[in] ControllerHandle The handle to the controller. Should have driver binding on it. - @param[in] DriverHandle The handle to the driver. Should have driver binding. + @param[in] ControllerHandle The handle to the controller. Should have driver binding on it. + @param[in] DriverHandle The handle to the driver. Should have driver binding. @param[in] Recursive TRUE to connect recursively, FALSE otherwise. @param[in] Output TRUE to have info on the screen, FALSE otherwise. @param[in] AlwaysOutput Override Output for errors. @@ -108,18 +195,27 @@ ConnectControllers ( **/ EFI_STATUS EFIAPI -ConnectFromDevPaths ( +ShellConnectFromDevPaths ( IN CONST CHAR16 *Key ) { EFI_DEVICE_PATH_PROTOCOL *DevPath; - EFI_DEVICE_PATH_PROTOCOL *DevPathWalker; + EFI_DEVICE_PATH_PROTOCOL *CopyOfDevPath; + EFI_DEVICE_PATH_PROTOCOL *Instance; + EFI_DEVICE_PATH_PROTOCOL *Next; UINTN Length; - EFI_HANDLE Handle; + UINTN Index; + UINTN HandleArrayCount; + UINTN Size; + EFI_HANDLE *HandleArray; EFI_STATUS Status; - + BOOLEAN AtLeastOneConnected; + EFI_PCI_IO_PROTOCOL *PciIo; + UINT8 Class[3]; + DevPath = NULL; Length = 0; + AtLeastOneConnected = FALSE; // // Get the DevicePath buffer from the variable... @@ -127,43 +223,121 @@ ConnectFromDevPaths ( Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath); if (Status == EFI_BUFFER_TOO_SMALL) { DevPath = AllocateZeroPool(Length); + if (DevPath == NULL) { + return EFI_OUT_OF_RESOURCES; + } Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath); + if (EFI_ERROR (Status)) { + if (DevPath != NULL) { + FreePool (DevPath); + } + return Status; + } + } else if (EFI_ERROR (Status)) { + return Status; } Status = EFI_NOT_FOUND; + + CopyOfDevPath = DevPath; // // walk the list of devices and connect them // - for (DevPathWalker = DevPath - ; DevPathWalker < (DevPath + Length) && EFI_ERROR(Status) && DevPath != NULL - ; DevPathWalker += GetDevicePathSize(DevPathWalker) - ){ + do { // - // get the correct handle from a given device path + // Check every instance of the console variable // - if ((StrCmp(Key, L"ConInDev") == 0) - ||(StrCmp(Key, L"ConIn") == 0) - ){ - Status = gBS->LocateDevicePath((EFI_GUID*)&gEfiConsoleInDeviceGuid, &DevPathWalker, &Handle); - if (!EFI_ERROR(Status)) { - Status = ConnectControllers(NULL, Handle, FALSE, TRUE, FALSE); - } - } else if ((StrCmp(Key, L"ConOutDev") == 0) - || (StrCmp(Key, L"ConErrDev") == 0) - || (StrCmp(Key, L"ConOut") == 0) - || (StrCmp(Key, L"ConErr") == 0) - ){ - Status = gBS->LocateDevicePath((EFI_GUID*)&gEfiConsoleOutDeviceGuid, &DevPathWalker, &Handle); - if (!EFI_ERROR(Status)) { - Status = ConnectControllers(NULL, Handle, FALSE, TRUE, FALSE); + Instance = GetNextDevicePathInstance (&CopyOfDevPath, &Size); + if (Instance == NULL) { + if (DevPath != NULL) { + FreePool (DevPath); } + return EFI_UNSUPPORTED; + } + + Next = Instance; + while (!IsDevicePathEndType (Next)) { + Next = NextDevicePathNode (Next); } - } + SetDevicePathEndNode (Next); + // + // connect short form device path + // + if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) && + ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP) + || (DevicePathSubType (Instance) == MSG_USB_WWID_DP) + )) { + + Status = ShellConnectPciRootBridge (); + if (EFI_ERROR(Status)) { + FreePool(Instance); + FreePool(DevPath); + return Status; + } + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciIoProtocolGuid, + NULL, + &HandleArrayCount, + &HandleArray + ); + + if (!EFI_ERROR (Status)) { + for (Index = 0; Index < HandleArrayCount; Index++) { + Status = gBS->HandleProtocol ( + HandleArray[Index], + &gEfiPciIoProtocolGuid, + (VOID **)&PciIo + ); + + if (!EFI_ERROR (Status)) { + Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class); + if (!EFI_ERROR (Status)) { + if ((PCI_CLASS_SERIAL == Class[2]) && + (PCI_CLASS_SERIAL_USB == Class[1])) { + Status = gBS->ConnectController ( + HandleArray[Index], + NULL, + Instance, + FALSE + ); + if (!EFI_ERROR(Status)) { + AtLeastOneConnected = TRUE; + } + } + } + } + } + } + + if (HandleArray != NULL) { + FreePool (HandleArray); + } + } else { + // + // connect the entire device path + // + Status = ShellConnectDevicePath (Instance); + if (!EFI_ERROR (Status)) { + AtLeastOneConnected = TRUE; + } + } + FreePool (Instance); + + } while (CopyOfDevPath != NULL); + if (DevPath != NULL) { FreePool(DevPath); } - return (Status); + + if (AtLeastOneConnected) { + return EFI_SUCCESS; + } else { + return EFI_NOT_FOUND; + } + } /** @@ -251,7 +425,6 @@ ShellCommandRunConnect ( UINT64 Intermediate; ShellStatus = SHELL_SUCCESS; - // // initialize the shell lib (we must be in non-auto-init...) // @@ -267,7 +440,7 @@ ShellCommandRunConnect ( Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"connect", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { @@ -277,45 +450,47 @@ ShellCommandRunConnect ( // // if more than 2 'value' parameters (plus the name one) or either -r or -c with any value parameters we have too many parameters // - if ((ShellCommandLineGetCount(Package) > 3) - ||((ShellCommandLineGetFlag(Package, L"-r") || ShellCommandLineGetFlag(Package, L"-c")) && ShellCommandLineGetCount(Package)>1) + Count = (gInReconnect?0x4:0x3); + if ((ShellCommandLineGetCount(Package) > Count) + ||(ShellCommandLineGetFlag(Package, L"-c") && ShellCommandLineGetCount(Package)>1) + ||(ShellCommandLineGetFlag(Package, L"-r") && ShellCommandLineGetCount(Package)>2) ||(ShellCommandLineGetFlag(Package, L"-r") && ShellCommandLineGetFlag(Package, L"-c") ) - ){ + ){ // // error for too many parameters // - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"connect"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetFlag(Package, L"-c")) { // // do the conin and conout from EFI variables // if the first fails dont 'loose' the error // - Status = ConnectFromDevPaths(L"ConInDev"); + Status = ShellConnectFromDevPaths(L"ConInDev"); if (EFI_ERROR(Status)) { - ConnectFromDevPaths(L"ConOutDev"); + ShellConnectFromDevPaths(L"ConOutDev"); } else { - Status = ConnectFromDevPaths(L"ConOutDev"); + Status = ShellConnectFromDevPaths(L"ConOutDev"); } if (EFI_ERROR(Status)) { - ConnectFromDevPaths(L"ConErrDev"); + ShellConnectFromDevPaths(L"ErrOutDev"); } else { - Status = ConnectFromDevPaths(L"ConErrDev"); + Status = ShellConnectFromDevPaths(L"ErrOutDev"); } if (EFI_ERROR(Status)) { - ConnectFromDevPaths(L"ConErr"); + ShellConnectFromDevPaths(L"ErrOut"); } else { - Status = ConnectFromDevPaths(L"ConErr"); + Status = ShellConnectFromDevPaths(L"ErrOut"); } if (EFI_ERROR(Status)) { - ConnectFromDevPaths(L"ConIn"); + ShellConnectFromDevPaths(L"ConIn"); } else { - Status = ConnectFromDevPaths(L"ConIn"); + Status = ShellConnectFromDevPaths(L"ConIn"); } if (EFI_ERROR(Status)) { - ConnectFromDevPaths(L"ConOut"); + ShellConnectFromDevPaths(L"ConOut"); } else { - Status = ConnectFromDevPaths(L"ConOut"); + Status = ShellConnectFromDevPaths(L"ConOut"); } if (EFI_ERROR(Status)) { ShellStatus = SHELL_DEVICE_ERROR; @@ -328,25 +503,37 @@ ShellCommandRunConnect ( Param2 = ShellCommandLineGetRawValue(Package, 2); Count = ShellCommandLineGetCount(Package); - Status = ShellConvertStringToUint64(Param1, &Intermediate, TRUE, FALSE); - Handle1 = ConvertHandleIndexToHandle((UINTN)Intermediate); - if (EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param1); - ShellStatus = SHELL_INVALID_PARAMETER; + if (Param1 != NULL) { + Status = ShellConvertStringToUint64(Param1, &Intermediate, TRUE, FALSE); + Handle1 = ConvertHandleIndexToHandle((UINTN)Intermediate); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param1); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } else { + Handle1 = NULL; } - Status = ShellConvertStringToUint64(Param2, &Intermediate, TRUE, FALSE); - Handle2 = ConvertHandleIndexToHandle((UINTN)Intermediate); - if (EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param2); - ShellStatus = SHELL_INVALID_PARAMETER; + + if (Param2 != NULL) { + Status = ShellConvertStringToUint64(Param2, &Intermediate, TRUE, FALSE); + Handle2 = ConvertHandleIndexToHandle((UINTN)Intermediate); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param2); + ShellStatus = SHELL_INVALID_PARAMETER; + } + } else { + Handle2 = NULL; } if (ShellStatus == SHELL_SUCCESS) { if (Param1 != NULL && Handle1 == NULL){ - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param1); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param1); ShellStatus = SHELL_INVALID_PARAMETER; } else if (Param2 != NULL && Handle2 == NULL) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param2); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param2); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (Handle2 != NULL && Handle1 != NULL && EFI_ERROR(gBS->OpenProtocol(Handle2, &gEfiDriverBindingProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param2); ShellStatus = SHELL_INVALID_PARAMETER; } else { Status = ConvertAndConnectControllers(Handle1, Handle2, ShellCommandLineGetFlag(Package, L"-r"), (BOOLEAN)(Count!=0));