-/**\r
- Connect the specific Usb device which match the short form device path,\r
- and whose bus is determined by Host Controller.\r
-\r
- @param DevicePath A short-form device path that starts with the first\r
- element being a USB WWID or a USB Class device\r
- path\r
-\r
- @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.\r
- DevicePath is not a USB device path.\r
-\r
- @return EFI_SUCCESS Success to connect USB device\r
- @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-ConSplitterConnectUsbShortFormDevicePath (\r
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_HANDLE *Handles;\r
- UINTN HandleCount;\r
- UINTN Index;\r
- EFI_PCI_IO_PROTOCOL *PciIo;\r
- UINT8 Class[3];\r
- BOOLEAN AtLeastOneConnected;\r
-\r
- //\r
- // Check the passed in parameters\r
- //\r
- if (DevicePath == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if ((DevicePathType (DevicePath) != MESSAGING_DEVICE_PATH) ||\r
- ((DevicePathSubType (DevicePath) != MSG_USB_CLASS_DP) && (DevicePathSubType (DevicePath) != MSG_USB_WWID_DP))\r
- ) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- //\r
- // Find the usb host controller firstly, then connect with the remaining device path\r
- //\r
- AtLeastOneConnected = FALSE;\r
- Status = gBS->LocateHandleBuffer (\r
- ByProtocol,\r
- &gEfiPciIoProtocolGuid,\r
- NULL,\r
- &HandleCount,\r
- &Handles\r
- );\r
- for (Index = 0; Index < HandleCount; Index++) {\r
- Status = gBS->HandleProtocol (\r
- Handles[Index],\r
- &gEfiPciIoProtocolGuid,\r
- (VOID **) &PciIo\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- //\r
- // Check whether the Pci device is the wanted usb host controller\r
- //\r
- Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);\r
- if (!EFI_ERROR (Status) &&\r
- ((PCI_CLASS_SERIAL == Class[2]) && (PCI_CLASS_SERIAL_USB == Class[1]))\r
- ) {\r
- Status = gBS->ConnectController (\r
- Handles[Index],\r
- NULL,\r
- DevicePath,\r
- FALSE\r
- );\r
- if (!EFI_ERROR(Status)) {\r
- AtLeastOneConnected = TRUE;\r
- }\r
- }\r
- }\r
- }\r
-\r
- return AtLeastOneConnected ? EFI_SUCCESS : EFI_NOT_FOUND;\r
-}\r
-\r
-\r
-/**\r
- This function will create all handles associate with every device\r
- path node. If the handle associate with one device path node can not\r
- be created successfully, then still give one chance to do the dispatch,\r
- which load the missing drivers if possible.\r
-\r
- @param DevicePathToConnect The device path which will be connected, it CANNOT be\r
- a multi-instance device path\r
- @param MatchingHandle Return the controller handle closest to the DevicePathToConnect\r
-\r
- @retval EFI_INVALID_PARAMETER DevicePathToConnect is NULL.\r
- @retval EFI_NOT_FOUND Failed to create all handles associate with every device path node.\r
- @retval EFI_SUCCESS Successful to create all handles associate with every device path node.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-ConSplitterConnectDevicePath (\r
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect,\r
- OUT EFI_HANDLE *MatchingHandle OPTIONAL\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;\r
- EFI_HANDLE Handle;\r
- EFI_HANDLE PreviousHandle;\r
-\r
- if (DevicePathToConnect == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- //\r
- // Start the real work of connect with RemainingDevicePath\r
- //\r
- PreviousHandle = NULL;\r
- do {\r
- //\r
- // Find the handle that best matches the Device Path. If it is only a\r
- // partial match the remaining part of the device path is returned in\r
- // RemainingDevicePath.\r
- //\r
- RemainingDevicePath = DevicePathToConnect;\r
- Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle);\r
- if (!EFI_ERROR (Status)) {\r
- if (Handle == PreviousHandle) {\r
- //\r
- // If no forward progress is made try invoking the Dispatcher.\r
- // A new FV may have been added to the system an new drivers\r
- // may now be found.\r
- // Status == EFI_SUCCESS means a driver was dispatched\r
- // Status == EFI_NOT_FOUND means no new drivers were dispatched\r
- //\r
- Status = gDS->Dispatch ();\r
- }\r
-\r
- if (!EFI_ERROR (Status)) {\r
- PreviousHandle = Handle;\r
- //\r
- // Connect all drivers that apply to Handle and RemainingDevicePath,\r
- // the Recursive flag is FALSE so only one level will be expanded.\r
- //\r
- // Do not check the connect status here, if the connect controller fail,\r
- // then still give the chance to do dispatch, because partial\r
- // RemainingDevicepath may be in the new FV\r
- //\r
- // 1. If the connect fail, RemainingDevicepath and handle will not\r
- // change, so next time will do the dispatch, then dispatch's status\r
- // will take effect\r
- // 2. If the connect success, the RemainingDevicepath and handle will\r
- // change, then avoid the dispatch, we have chance to continue the\r
- // next connection\r
- //\r
- gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE);\r
- if (MatchingHandle != NULL) {\r
- *MatchingHandle = Handle;\r
- }\r
- }\r
- }\r
- //\r
- // Loop until RemainingDevicePath is an empty device path\r
- //\r
- } while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath));\r
-\r
- ASSERT (EFI_ERROR (Status) || IsDevicePathEnd (RemainingDevicePath));\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Connect to all ConIn device which is in the ConIn variable.\r
-\r
- @param DevicePath A short-form device path that starts with the first\r
- element being a USB WWID or a USB Class device\r
- path\r
-\r
- @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.\r
- DevicePath is not a USB device path.\r
-\r
- @return EFI_SUCCESS Success to connect USB device\r
- @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-ConSplitterConnectConInDevicePath (\r
- \r
- )\r
-{\r
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
- EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r
- EFI_DEVICE_PATH_PROTOCOL *CopyDevicePath;\r
- UINTN Size;\r
- EFI_DEVICE_PATH_PROTOCOL *Next;\r
-\r
- DevicePath = GetEfiGlobalVariable (L"ConIn");\r
-\r
- //\r
- // Check the passed in parameters\r
- //\r
- if (DevicePath == NULL) {\r
- return EFI_NOT_FOUND;\r
- }\r
-\r
- CopyDevicePath = DevicePath;\r
-\r
- DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
- while (DevicePathInst != NULL) {\r
-\r
- Next = DevicePathInst;\r
- while (!IsDevicePathEndType (Next)) {\r
- Next = NextDevicePathNode (Next);\r
- }\r
-\r
- SetDevicePathEndNode (Next);\r
- \r
- //\r
- // Connect the USB console\r
- // USB console device path is a short-form device path that \r
- // starts with the first element being a USB WWID\r
- // or a USB Class device path\r
- //\r
- if ((DevicePathType (DevicePathInst) == MESSAGING_DEVICE_PATH) &&\r
- ((DevicePathSubType (DevicePathInst) == MSG_USB_CLASS_DP)\r
- || (DevicePathSubType (DevicePathInst) == MSG_USB_WWID_DP)\r
- )) {\r
- ConSplitterConnectUsbShortFormDevicePath (DevicePathInst);\r
- } else {\r
- ConSplitterConnectDevicePath (DevicePathInst, NULL);\r
- } \r
- DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
- }\r
- return EFI_SUCCESS;\r
-}\r
-\r