+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-Module Name:\r
-\r
- BdsConnect.c\r
-\r
-Abstract:\r
-\r
- BDS Lib functions which relate with connect the device\r
-\r
---*/\r
-\r
-VOID\r
-BdsLibConnectAll (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This function will connect all the system driver to controller\r
- first, and then special connect the default console, this make\r
- sure all the system controller avialbe and the platform default\r
- console connected.\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-{\r
- //\r
- // Connect the platform console first\r
- //\r
- BdsLibConnectAllDefaultConsoles ();\r
-\r
- //\r
- // Generic way to connect all the drivers\r
- //\r
- BdsLibConnectAllDriversToAllControllers ();\r
-\r
- //\r
- // Here we have the assumption that we have already had\r
- // platform default console\r
- //\r
- BdsLibConnectAllDefaultConsoles ();\r
-}\r
-\r
-VOID\r
-BdsLibGenericConnectAll (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This function will connect all the system drivers to all controllers\r
- first, and then connect all the console devices the system current\r
- have. After this we should get all the device work and console avariable\r
- if the system have console device.\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-{\r
- //\r
- // Most generic way to connect all the drivers\r
- //\r
- BdsLibConnectAllDriversToAllControllers ();\r
- BdsLibConnectAllConsoles ();\r
-}\r
-\r
-EFI_STATUS\r
-BdsLibConnectDevicePath (\r
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect\r
- )\r
-/*++\r
-\r
-Routine Description:\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 success, then still give one chance to do the dispatch,\r
- which load the missing drivers if possible.\r
-\r
-Arguments:\r
-\r
- DevicePathToConnect - The device path which will be connected, it can\r
- be a multi-instance device path\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - All handles associate with every device path\r
- node have been created\r
-\r
- EFI_OUT_OF_RESOURCES - There is no resource to create new handles\r
-\r
- EFI_NOT_FOUND - Create the handle associate with one device\r
- path node failed\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
- EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath;\r
- EFI_DEVICE_PATH_PROTOCOL *Instance;\r
- EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;\r
- EFI_DEVICE_PATH_PROTOCOL *Next;\r
- EFI_HANDLE Handle;\r
- EFI_HANDLE PreviousHandle;\r
- UINTN Size;\r
-\r
- if (DevicePathToConnect == NULL) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- DevicePath = DuplicateDevicePath (DevicePathToConnect);\r
- CopyOfDevicePath = DevicePath;\r
- if (DevicePath == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- do {\r
- //\r
- // The outer loop handles multi instance device paths.\r
- // Only console variables contain multiple instance device paths.\r
- //\r
- // After this call DevicePath points to the next Instance\r
- //\r
- Instance = GetNextDevicePathInstance (&DevicePath, &Size);\r
- Next = Instance;\r
- while (!IsDevicePathEndType (Next)) {\r
- Next = NextDevicePathNode (Next);\r
- }\r
-\r
- SetDevicePathEndNode (Next);\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 = Instance;\r
- Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle);\r
-\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
- }\r
- }\r
- //\r
- // Loop until RemainingDevicePath is an empty device path\r
- //\r
- } while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath));\r
-\r
- } while (DevicePath != NULL);\r
-\r
- if (CopyOfDevicePath != NULL) {\r
- FreePool (CopyOfDevicePath);\r
- }\r
- //\r
- // All handle with DevicePath exists in the handle database\r
- //\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-BdsLibConnectAllEfi (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This function will connect all current system handles recursively. The\r
- connection will finish until every handle's child handle created if it have.\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - All handles and it's child handle have been connected\r
-\r
- EFI_STATUS - Return the status of gBS->LocateHandleBuffer().\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- UINTN HandleCount;\r
- EFI_HANDLE *HandleBuffer;\r
- UINTN Index;\r
-\r
- Status = gBS->LocateHandleBuffer (\r
- AllHandles,\r
- NULL,\r
- NULL,\r
- &HandleCount,\r
- &HandleBuffer\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- for (Index = 0; Index < HandleCount; Index++) {\r
- Status = gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);\r
- }\r
-\r
- FreePool (HandleBuffer);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-BdsLibDisconnectAllEfi (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This function will disconnect all current system handles. The disconnection\r
- will finish until every handle have been disconnected.\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - All handles have been disconnected\r
-\r
- EFI_STATUS - Return the status of gBS->LocateHandleBuffer().\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- UINTN HandleCount;\r
- EFI_HANDLE *HandleBuffer;\r
- UINTN Index;\r
-\r
- //\r
- // Disconnect all\r
- //\r
- Status = gBS->LocateHandleBuffer (\r
- AllHandles,\r
- NULL,\r
- NULL,\r
- &HandleCount,\r
- &HandleBuffer\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- for (Index = 0; Index < HandleCount; Index++) {\r
- Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);\r
- }\r
-\r
- FreePool (HandleBuffer);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-VOID\r
-BdsLibConnectAllDriversToAllControllers (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Connects all drivers to all controllers.\r
- This function make sure all the current system driver will manage\r
- the correspoinding controllers if have. And at the same time, make\r
- sure all the system controllers have driver to manage it if have.\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
-\r
- do {\r
- //\r
- // Connect All EFI 1.10 drivers following EFI 1.10 algorithm\r
- //\r
- BdsLibConnectAllEfi ();\r
-\r
- //\r
- // Check to see if it's possible to dispatch an more DXE drivers.\r
- // The BdsLibConnectAllEfi () may have made new DXE drivers show up.\r
- // If anything is Dispatched Status == EFI_SUCCESS and we will try\r
- // the connect again.\r
- //\r
- Status = gDS->Dispatch ();\r
-\r
- } while (!EFI_ERROR (Status));\r
-\r
-}\r