2019-09-03 11:58:42 +02:00
|
|
|
/** @file
|
|
|
|
BDS Lib functions which relate with connect the device
|
|
|
|
|
|
|
|
Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
|
|
|
|
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
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
2020-08-17 21:40:52 +02:00
|
|
|
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
|
2020-04-16 11:09:22 +02:00
|
|
|
#include "../include/Handle.h"
|
2020-08-17 21:40:52 +02:00
|
|
|
#include "../Platform/Settings.h"
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function will connect all the system driver to controller
|
|
|
|
first, and then special connect the default console, this make
|
|
|
|
sure all the system controller available and the platform default
|
|
|
|
console connected.
|
|
|
|
|
|
|
|
**/
|
|
|
|
/*
|
2020-10-03 19:02:31 +02:00
|
|
|
void
|
2019-09-03 11:58:42 +02:00
|
|
|
EFIAPI
|
|
|
|
BdsLibConnectAll (
|
2020-10-03 19:02:31 +02:00
|
|
|
void
|
2019-09-03 11:58:42 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Connect the platform console first
|
|
|
|
//
|
|
|
|
BdsLibConnectAllDefaultConsoles ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Generic way to connect all the drivers
|
|
|
|
//
|
|
|
|
BdsLibConnectAllDriversToAllControllers ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Here we have the assumption that we have already had
|
|
|
|
// platform default console
|
|
|
|
//
|
|
|
|
BdsLibConnectAllDefaultConsoles ();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function will connect all the system drivers to all controllers
|
|
|
|
first, and then connect all the console devices the system current
|
|
|
|
have. After this we should get all the device work and console available
|
|
|
|
if the system have console device.
|
|
|
|
|
|
|
|
**/
|
|
|
|
/*
|
2020-10-03 19:02:31 +02:00
|
|
|
void
|
2019-09-03 11:58:42 +02:00
|
|
|
BdsLibGenericConnectAll (
|
2020-10-03 19:02:31 +02:00
|
|
|
void
|
2019-09-03 11:58:42 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Most generic way to connect all the drivers
|
|
|
|
//
|
|
|
|
BdsLibConnectAllDriversToAllControllers ();
|
|
|
|
BdsLibConnectAllConsoles ();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function will create all handles associate with every device
|
|
|
|
path node. If the handle associate with one device path node can not
|
|
|
|
be created success, then still give one chance to do the dispatch,
|
|
|
|
which load the missing drivers if possible.
|
|
|
|
|
|
|
|
@param DevicePathToConnect The device path which will be connected, it can be
|
|
|
|
a multi-instance device path
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS All handles associate with every device path node
|
|
|
|
have been created
|
|
|
|
@retval EFI_OUT_OF_RESOURCES There is no resource to create new handles
|
|
|
|
@retval EFI_NOT_FOUND Create the handle associate with one device path
|
|
|
|
node failed
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
BdsLibConnectDevicePath (
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *Instance;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *Next;
|
|
|
|
EFI_HANDLE Handle;
|
|
|
|
EFI_HANDLE PreviousHandle;
|
|
|
|
UINTN Size;
|
|
|
|
|
|
|
|
if (DevicePathToConnect == NULL) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DevicePath = DuplicateDevicePath (DevicePathToConnect);
|
|
|
|
if (DevicePath == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
CopyOfDevicePath = DevicePath;
|
|
|
|
|
|
|
|
do {
|
|
|
|
//
|
|
|
|
// The outer loop handles multi instance device paths.
|
|
|
|
// Only console variables contain multiple instance device paths.
|
|
|
|
//
|
|
|
|
// After this call DevicePath points to the next Instance
|
|
|
|
//
|
|
|
|
Instance = GetNextDevicePathInstance (&DevicePath, &Size);
|
|
|
|
if (Instance == NULL) {
|
2020-04-23 11:08:10 +02:00
|
|
|
FreePool(CopyOfDevicePath);
|
2019-09-03 11:58:42 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
Next = Instance;
|
|
|
|
while (!IsDevicePathEndType (Next)) {
|
|
|
|
Next = NextDevicePathNode (Next);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetDevicePathEndNode (Next);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Start the real work of connect with RemainingDevicePath
|
|
|
|
//
|
|
|
|
PreviousHandle = NULL;
|
|
|
|
do {
|
|
|
|
//
|
|
|
|
// Find the handle that best matches the Device Path. If it is only a
|
|
|
|
// partial match the remaining part of the device path is returned in
|
|
|
|
// RemainingDevicePath.
|
|
|
|
//
|
|
|
|
RemainingDevicePath = Instance;
|
|
|
|
Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle);
|
|
|
|
|
2020-04-23 11:08:10 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
if (Handle == PreviousHandle) {
|
|
|
|
//
|
|
|
|
// If no forward progress is made try invoking the Dispatcher.
|
|
|
|
// A new FV may have been added to the system an new drivers
|
|
|
|
// may now be found.
|
|
|
|
// Status == EFI_SUCCESS means a driver was dispatched
|
|
|
|
// Status == EFI_NOT_FOUND means no new drivers were dispatched
|
|
|
|
//
|
|
|
|
Status = gDS->Dispatch ();
|
|
|
|
}
|
|
|
|
|
2020-04-23 11:08:10 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
PreviousHandle = Handle;
|
|
|
|
//
|
|
|
|
// Connect all drivers that apply to Handle and RemainingDevicePath,
|
2021-09-28 10:28:45 +02:00
|
|
|
// the Recursive flag is false so only one level will be expanded.
|
2019-09-03 11:58:42 +02:00
|
|
|
//
|
|
|
|
// Do not check the connect status here, if the connect controller fail,
|
|
|
|
// then still give the chance to do dispatch, because partial
|
|
|
|
// RemainingDevicepath may be in the new FV
|
|
|
|
//
|
|
|
|
// 1. If the connect fail, RemainingDevicepath and handle will not
|
|
|
|
// change, so next time will do the dispatch, then dispatch's status
|
|
|
|
// will take effect
|
|
|
|
// 2. If the connect success, the RemainingDevicepath and handle will
|
|
|
|
// change, then avoid the dispatch, we have chance to continue the
|
|
|
|
// next connection
|
|
|
|
//
|
2021-09-28 10:28:45 +02:00
|
|
|
gBS->ConnectController (Handle, NULL, RemainingDevicePath, false);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Loop until RemainingDevicePath is an empty device path
|
|
|
|
//
|
2020-04-23 11:08:10 +02:00
|
|
|
} while (!EFI_ERROR(Status) && !IsDevicePathEnd (RemainingDevicePath));
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
} while (DevicePath != NULL);
|
|
|
|
|
|
|
|
if (CopyOfDevicePath != NULL) {
|
2020-04-23 11:08:10 +02:00
|
|
|
FreePool(CopyOfDevicePath);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// All handle with DevicePath exists in the handle database
|
|
|
|
//
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function will connect all current system handles recursively.
|
|
|
|
|
|
|
|
gBS->ConnectController() service is invoked for each handle exist in system handler buffer.
|
|
|
|
If the handle is bus type handler, all childrens also will be connected recursively
|
|
|
|
by gBS->ConnectController().
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS All handles and it's child handle have been connected
|
|
|
|
@retval EFI_STATUS Error status returned by of gBS->LocateHandleBuffer().
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
BdsLibConnectAllEfi (
|
2020-10-03 19:02:31 +02:00
|
|
|
void
|
2019-09-03 11:58:42 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN HandleCount;
|
|
|
|
EFI_HANDLE *HandleBuffer;
|
|
|
|
UINTN Index;
|
|
|
|
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
AllHandles,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&HandleCount,
|
|
|
|
&HandleBuffer
|
|
|
|
);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Index = 0; Index < HandleCount; Index++) {
|
|
|
|
//Status =
|
2021-09-28 10:28:45 +02:00
|
|
|
gBS->ConnectController (HandleBuffer[Index], NULL, NULL, true);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (HandleBuffer != NULL) {
|
2020-04-23 11:08:10 +02:00
|
|
|
FreePool(HandleBuffer);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function will disconnect all current system handles.
|
|
|
|
|
|
|
|
gBS->DisconnectController() is invoked for each handle exists in system handle buffer.
|
|
|
|
If handle is a bus type handle, all childrens also are disconnected recursively by
|
|
|
|
gBS->DisconnectController().
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS All handles have been disconnected
|
|
|
|
@retval EFI_STATUS Error status returned by of gBS->LocateHandleBuffer().
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
BdsLibDisconnectAllEfi (
|
2020-10-03 19:02:31 +02:00
|
|
|
void
|
2019-09-03 11:58:42 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN HandleCount;
|
|
|
|
EFI_HANDLE *HandleBuffer;
|
|
|
|
UINTN Index;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Disconnect all
|
|
|
|
//
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
AllHandles,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&HandleCount,
|
|
|
|
&HandleBuffer
|
|
|
|
);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Index = 0; Index < HandleCount; Index++) {
|
|
|
|
//Status =
|
|
|
|
gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HandleBuffer != NULL) {
|
2020-04-23 11:08:10 +02:00
|
|
|
FreePool(HandleBuffer);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS ScanDeviceHandles(EFI_HANDLE ControllerHandle,
|
|
|
|
UINTN *HandleCount,
|
|
|
|
EFI_HANDLE **HandleBuffer,
|
|
|
|
UINT32 **HandleType)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN HandleIndex;
|
|
|
|
EFI_GUID **ProtocolGuidArray;
|
|
|
|
UINTN ArrayCount;
|
|
|
|
UINTN ProtocolIndex;
|
|
|
|
EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
|
|
|
|
UINTN OpenInfoCount;
|
|
|
|
UINTN OpenInfoIndex;
|
|
|
|
UINTN ChildIndex;
|
|
|
|
|
|
|
|
*HandleCount = 0;
|
|
|
|
*HandleBuffer = NULL;
|
|
|
|
*HandleType = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Retrieve the list of all handles from the handle database
|
|
|
|
//
|
|
|
|
Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, HandleCount, HandleBuffer);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (EFI_ERROR(Status)) goto Error;
|
2020-02-21 22:22:30 +01:00
|
|
|
|
2020-02-27 15:34:29 +01:00
|
|
|
*HandleType = (__typeof_am__(*HandleType))AllocatePool (*HandleCount * sizeof (**HandleType));
|
2019-09-03 11:58:42 +02:00
|
|
|
if (*HandleType == NULL) goto Error;
|
|
|
|
|
|
|
|
for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
|
|
|
|
(*HandleType)[HandleIndex] = EFI_HANDLE_TYPE_UNKNOWN;
|
|
|
|
//
|
|
|
|
// Retrieve the list of all the protocols on each handle
|
|
|
|
//
|
|
|
|
Status = gBS->ProtocolsPerHandle (
|
|
|
|
(*HandleBuffer)[HandleIndex],
|
|
|
|
&ProtocolGuidArray,
|
|
|
|
&ArrayCount
|
|
|
|
);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
|
|
|
|
|
2022-04-26 00:55:56 +02:00
|
|
|
if ( *(ProtocolGuidArray[ProtocolIndex]) == gEfiLoadedImageProtocolGuid ) {
|
2019-09-03 11:58:42 +02:00
|
|
|
(*HandleType)[HandleIndex] |= EFI_HANDLE_TYPE_IMAGE_HANDLE;
|
|
|
|
}
|
|
|
|
|
2022-04-26 00:55:56 +02:00
|
|
|
if ( *(ProtocolGuidArray[ProtocolIndex]) == gEfiDriverBindingProtocolGuid ) {
|
2019-09-03 11:58:42 +02:00
|
|
|
(*HandleType)[HandleIndex] |= EFI_HANDLE_TYPE_DRIVER_BINDING_HANDLE;
|
|
|
|
}
|
|
|
|
|
2022-04-26 00:55:56 +02:00
|
|
|
if ( *(ProtocolGuidArray[ProtocolIndex]) == gEfiDriverConfigurationProtocolGuid ) {
|
2019-09-03 11:58:42 +02:00
|
|
|
(*HandleType)[HandleIndex] |= EFI_HANDLE_TYPE_DRIVER_CONFIGURATION_HANDLE;
|
|
|
|
}
|
|
|
|
|
2022-04-26 00:55:56 +02:00
|
|
|
if ( *(ProtocolGuidArray[ProtocolIndex]) == gEfiDriverDiagnosticsProtocolGuid ) {
|
2019-09-03 11:58:42 +02:00
|
|
|
(*HandleType)[HandleIndex] |= EFI_HANDLE_TYPE_DRIVER_DIAGNOSTICS_HANDLE;
|
|
|
|
}
|
|
|
|
|
2022-04-26 00:55:56 +02:00
|
|
|
if ( *(ProtocolGuidArray[ProtocolIndex]) == gEfiComponentName2ProtocolGuid ) {
|
2019-09-03 11:58:42 +02:00
|
|
|
(*HandleType)[HandleIndex] |= EFI_HANDLE_TYPE_COMPONENT_NAME_HANDLE;
|
|
|
|
}
|
|
|
|
|
2022-04-26 00:55:56 +02:00
|
|
|
if ( *(ProtocolGuidArray[ProtocolIndex]) == gEfiComponentNameProtocolGuid ) {
|
2019-09-03 11:58:42 +02:00
|
|
|
(*HandleType)[HandleIndex] |= EFI_HANDLE_TYPE_COMPONENT_NAME_HANDLE;
|
|
|
|
}
|
|
|
|
|
2022-04-26 00:55:56 +02:00
|
|
|
if ( *(ProtocolGuidArray[ProtocolIndex]) == gEfiDevicePathProtocolGuid ) {
|
2019-09-03 11:58:42 +02:00
|
|
|
(*HandleType)[HandleIndex] |= EFI_HANDLE_TYPE_DEVICE_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Retrieve the list of agents that have opened each protocol
|
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocolInformation (
|
|
|
|
(*HandleBuffer)[HandleIndex],
|
|
|
|
ProtocolGuidArray[ProtocolIndex],
|
|
|
|
&OpenInfo,
|
|
|
|
&OpenInfoCount
|
|
|
|
);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
|
|
|
|
|
|
|
|
if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
|
|
|
|
if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) == EFI_OPEN_PROTOCOL_BY_DRIVER) {
|
|
|
|
for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
|
|
|
|
if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].AgentHandle) {
|
|
|
|
(*HandleType)[ChildIndex] |= EFI_HANDLE_TYPE_DEVICE_DRIVER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
|
|
|
|
(*HandleType)[HandleIndex] |= EFI_HANDLE_TYPE_PARENT_HANDLE;
|
|
|
|
for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++)
|
|
|
|
{
|
|
|
|
if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].AgentHandle) {
|
|
|
|
(*HandleType)[ChildIndex] |= EFI_HANDLE_TYPE_BUS_DRIVER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-08 11:28:32 +01:00
|
|
|
gBS->FreePool(OpenInfo); // use gBS->FreePool instead of FreePool to avoid message from MemoryTracker
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
}
|
2024-01-08 11:28:32 +01:00
|
|
|
gBS->FreePool(ProtocolGuidArray); // use gBS->FreePool instead of FreePool to avoid message from MemoryTracker
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
Error:
|
|
|
|
if (*HandleType != NULL) {
|
2020-04-23 11:08:10 +02:00
|
|
|
FreePool(*HandleType);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*HandleBuffer != NULL) {
|
2024-01-08 11:28:32 +01:00
|
|
|
gBS->FreePool(*HandleBuffer); // use gBS->FreePool instead of FreePool to avoid message from MemoryTracker
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*HandleCount = 0;
|
|
|
|
*HandleBuffer = NULL;
|
|
|
|
*HandleType = NULL;
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EFI_STATUS BdsLibConnectMostlyAllEfi()
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN AllHandleCount = 0;
|
|
|
|
EFI_HANDLE *AllHandleBuffer = NULL;
|
|
|
|
UINTN Index;
|
|
|
|
UINTN HandleCount = 0;
|
|
|
|
EFI_HANDLE *HandleBuffer = NULL;
|
|
|
|
UINT32 *HandleType = NULL;
|
|
|
|
UINTN HandleIndex;
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool Parent;
|
|
|
|
XBool Device;
|
2019-09-03 11:58:42 +02:00
|
|
|
EFI_PCI_IO_PROTOCOL* PciIo = NULL;
|
|
|
|
PCI_TYPE00 Pci;
|
|
|
|
|
|
|
|
Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &AllHandleCount, &AllHandleBuffer);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (EFI_ERROR(Status))
|
2019-09-03 11:58:42 +02:00
|
|
|
return Status;
|
|
|
|
|
|
|
|
for (Index = 0; Index < AllHandleCount; Index++) {
|
|
|
|
Status = ScanDeviceHandles(AllHandleBuffer[Index], &HandleCount, &HandleBuffer, &HandleType);
|
|
|
|
|
2020-04-23 11:08:10 +02:00
|
|
|
if (EFI_ERROR(Status))
|
2019-09-03 11:58:42 +02:00
|
|
|
goto Done;
|
|
|
|
|
2021-09-28 10:28:45 +02:00
|
|
|
Device = true;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
if (HandleType[Index] & EFI_HANDLE_TYPE_DRIVER_BINDING_HANDLE)
|
2021-09-28 10:28:45 +02:00
|
|
|
Device = false;
|
2019-09-03 11:58:42 +02:00
|
|
|
if (HandleType[Index] & EFI_HANDLE_TYPE_IMAGE_HANDLE)
|
2021-09-28 10:28:45 +02:00
|
|
|
Device = false;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
if (Device) {
|
2021-09-28 10:28:45 +02:00
|
|
|
Parent = false;
|
2019-09-03 11:58:42 +02:00
|
|
|
for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
|
|
|
|
if (HandleType[HandleIndex] & EFI_HANDLE_TYPE_PARENT_HANDLE)
|
2021-09-28 10:28:45 +02:00
|
|
|
Parent = true;
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!Parent) {
|
|
|
|
if (HandleType[Index] & EFI_HANDLE_TYPE_DEVICE_HANDLE) {
|
2020-10-03 19:02:31 +02:00
|
|
|
Status = gBS->HandleProtocol (AllHandleBuffer[Index], &gEfiPciIoProtocolGuid, (void**)&PciIo);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
Status = PciIo->Pci.Read (PciIo,EfiPciIoWidthUint32, 0, sizeof (Pci) / sizeof (UINT32), &Pci);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2021-09-28 10:28:45 +02:00
|
|
|
if(IS_PCI_VGA(&Pci)==true) {
|
2019-09-03 11:58:42 +02:00
|
|
|
gBS->DisconnectController(AllHandleBuffer[Index], NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 10:28:45 +02:00
|
|
|
Status = gBS->ConnectController(AllHandleBuffer[Index], NULL, NULL, true);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-08 11:28:32 +01:00
|
|
|
gBS->FreePool(HandleBuffer); // use gBS->FreePool instead of FreePool to avoid message from MemoryTracker
|
2020-04-23 11:08:10 +02:00
|
|
|
FreePool(HandleType);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Done:
|
2024-01-08 11:28:32 +01:00
|
|
|
gBS->FreePool(AllHandleBuffer); // use gBS->FreePool instead of FreePool to avoid message from MemoryTracker
|
2019-09-03 11:58:42 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Connects all drivers to all controllers.
|
|
|
|
This function make sure all the current system driver will manage
|
|
|
|
the corresponding controllers if have. And at the same time, make
|
|
|
|
sure all the system controllers have driver to manage it if have.
|
|
|
|
|
|
|
|
**/
|
2020-10-03 19:02:31 +02:00
|
|
|
void
|
2019-09-03 11:58:42 +02:00
|
|
|
EFIAPI
|
|
|
|
BdsLibConnectAllDriversToAllControllers (
|
2020-10-03 19:02:31 +02:00
|
|
|
void
|
2019-09-03 11:58:42 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
do {
|
|
|
|
//
|
|
|
|
// Connect All EFI 1.10 drivers following EFI 1.10 algorithm
|
|
|
|
//
|
|
|
|
//BdsLibConnectAllEfi ();
|
|
|
|
BdsLibConnectMostlyAllEfi ();
|
|
|
|
//
|
|
|
|
// Check to see if it's possible to dispatch an more DXE drivers.
|
|
|
|
// The BdsLibConnectAllEfi () may have made new DXE drivers show up.
|
|
|
|
// If anything is Dispatched Status == EFI_SUCCESS and we will try
|
|
|
|
// the connect again.
|
|
|
|
//
|
|
|
|
Status = gDS->Dispatch ();
|
|
|
|
|
2020-04-23 11:08:10 +02:00
|
|
|
} while (!EFI_ERROR(Status));
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Connect the specific Usb device which match the short form device path,
|
|
|
|
and whose bus is determined by Host Controller (Uhci or Ehci).
|
|
|
|
|
|
|
|
@param HostControllerPI Uhci (0x00) or Ehci (0x20) or Both uhci and ehci
|
|
|
|
(0xFF)
|
|
|
|
@param RemainingDevicePath a short-form device path that starts with the first
|
|
|
|
element being a USB WWID or a USB Class device
|
|
|
|
path
|
|
|
|
|
|
|
|
@return EFI_INVALID_PARAMETER RemainingDevicePath is NULL pointer.
|
|
|
|
RemainingDevicePath is not a USB device path.
|
|
|
|
Invalid HostControllerPI type.
|
|
|
|
@return EFI_SUCCESS Success to connect USB device
|
|
|
|
@return EFI_NOT_FOUND Fail to find handle for USB controller to connect.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
BdsLibConnectUsbDevByShortFormDP(
|
|
|
|
IN UINT8 HostControllerPI,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE *HandleArray;
|
|
|
|
UINTN HandleArrayCount;
|
|
|
|
UINTN Index;
|
|
|
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
|
|
|
UINT8 Class[3];
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool AtLeastOneConnected;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Check the passed in parameters
|
|
|
|
//
|
|
|
|
if (RemainingDevicePath == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((DevicePathType (RemainingDevicePath) != MESSAGING_DEVICE_PATH) ||
|
|
|
|
((DevicePathSubType (RemainingDevicePath) != MSG_USB_CLASS_DP)
|
|
|
|
&& (DevicePathSubType (RemainingDevicePath) != MSG_USB_WWID_DP)
|
|
|
|
)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HostControllerPI != 0xFF &&
|
|
|
|
HostControllerPI != 0x00 &&
|
|
|
|
HostControllerPI != 0x10 &&
|
|
|
|
HostControllerPI != 0x20 &&
|
|
|
|
HostControllerPI != 0x30) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Find the usb host controller firstly, then connect with the remaining device path
|
|
|
|
//
|
2021-09-28 10:28:45 +02:00
|
|
|
AtLeastOneConnected = false;
|
2019-09-03 11:58:42 +02:00
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
ByProtocol,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
&HandleArrayCount,
|
|
|
|
&HandleArray
|
|
|
|
);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
for (Index = 0; Index < HandleArrayCount; Index++) {
|
|
|
|
Status = gBS->HandleProtocol (
|
|
|
|
HandleArray[Index],
|
|
|
|
&gEfiPciIoProtocolGuid,
|
2020-10-03 19:02:31 +02:00
|
|
|
(void **)&PciIo
|
2019-09-03 11:58:42 +02:00
|
|
|
);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
//
|
|
|
|
// Check whether the Pci device is the wanted usb host controller
|
|
|
|
//
|
|
|
|
Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
if ((PCI_CLASS_SERIAL == Class[2]) &&
|
|
|
|
(PCI_CLASS_SERIAL_USB == Class[1])) {
|
|
|
|
if (HostControllerPI == Class[0] || HostControllerPI == 0xFF) {
|
|
|
|
Status = gBS->ConnectController (
|
|
|
|
HandleArray[Index],
|
|
|
|
NULL,
|
|
|
|
RemainingDevicePath,
|
2021-09-28 10:28:45 +02:00
|
|
|
false
|
2019-09-03 11:58:42 +02:00
|
|
|
);
|
|
|
|
if (!EFI_ERROR(Status)) {
|
2021-09-28 10:28:45 +02:00
|
|
|
AtLeastOneConnected = true;
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HandleArray != NULL) {
|
2020-04-23 11:08:10 +02:00
|
|
|
FreePool(HandleArray);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (AtLeastOneConnected) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|