+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
-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
- EfiDriverModelLib.c\r
-\r
-Abstract:\r
-\r
- Light weight lib to support EFI drivers.\r
-\r
---*/\r
-\r
-#include "Tiano.h"\r
-#include "EfiDriverLib.h"\r
-\r
-EFI_STATUS\r
-EfiLibInstallDriverBinding (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable,\r
- IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,\r
- IN EFI_HANDLE DriverBindingHandle\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Intialize a driver by installing the Driver Binding Protocol onto the \r
- driver's DriverBindingHandle. This is typically the same as the driver's\r
- ImageHandle, but it can be different if the driver produces multiple\r
- DriverBinding Protocols. This function also initializes the EFI Driver\r
- Library that initializes the global variables gST, gBS, gRT.\r
-\r
-Arguments:\r
-\r
- ImageHandle - The image handle of the driver\r
-\r
- SystemTable - The EFI System Table that was passed to the driver's entry point\r
-\r
- DriverBinding - A Driver Binding Protocol instance that this driver is producing\r
-\r
- DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this\r
- parameter is NULL, then a new handle is created.\r
-\r
-Returns: \r
-\r
- EFI_SUCCESS is DriverBinding is installed onto DriverBindingHandle\r
-\r
- Otherwise, then return status from gBS->InstallProtocolInterface()\r
-\r
---*/\r
-{\r
- EfiInitializeDriverLib (ImageHandle, SystemTable);\r
-\r
- DriverBinding->ImageHandle = ImageHandle;\r
-\r
- DriverBinding->DriverBindingHandle = DriverBindingHandle;\r
-\r
- return gBS->InstallProtocolInterface (\r
- &DriverBinding->DriverBindingHandle,\r
- &gEfiDriverBindingProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- DriverBinding\r
- );\r
-}\r
-\r
-EFI_STATUS\r
-InstallAllDriverProtocolsWorker (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE * SystemTable,\r
- IN EFI_DRIVER_BINDING_PROTOCOL * DriverBinding,\r
- IN EFI_HANDLE DriverBindingHandle,\r
- IN EFI_COMPONENT_NAME_PROTOCOL * ComponentName, OPTIONAL\r
- IN EFI_COMPONENT_NAME2_PROTOCOL * ComponentName2, OPTIONAL\r
- IN EFI_DRIVER_CONFIGURATION_PROTOCOL * DriverConfiguration, OPTIONAL\r
- IN EFI_DRIVER_CONFIGURATION2_PROTOCOL * DriverConfiguration2, OPTIONAL\r
- IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL * DriverDiagnostics, OPTIONAL\r
- IN EFI_DRIVER_DIAGNOSTICS2_PROTOCOL * DriverDiagnostics2 OPTIONAL\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Intialize a driver by installing the Driver Binding Protocol onto the \r
- driver's DriverBindingHandle. This is typically the same as the driver's\r
- ImageHandle, but it can be different if the driver produces multiple\r
- DriverBinding Protocols. This function also initializes the EFI Driver\r
- Library that initializes the global variables gST, gBS, gRT.\r
-\r
-Arguments:\r
-\r
- ImageHandle - The image handle of the driver\r
-\r
- SystemTable - The EFI System Table that was passed to the driver's entry point\r
-\r
- DriverBinding - A Driver Binding Protocol instance that this driver is producing\r
-\r
- DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this\r
- parameter is NULL, then a new handle is created.\r
-\r
- ComponentName - A Component Name Protocol instance that this driver is producing\r
-\r
- ComponentName2 - A Component Name2 Protocol instance that this driver is producing\r
-\r
- DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing\r
-\r
- DriverConfiguration2- A Driver Configuration2 Protocol instance that this driver is producing\r
- \r
- DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing\r
-\r
- DriverDiagnostics2 - A Driver Diagnostics2 Protocol instance that this driver is producing\r
-\r
-Returns: \r
-\r
- EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle\r
-\r
- Otherwise, then return status from gBS->InstallProtocolInterface()\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
-\r
- Status = EfiLibInstallDriverBinding (ImageHandle, SystemTable, DriverBinding, DriverBindingHandle);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- if (ComponentName != NULL) {\r
- Status = gBS->InstallProtocolInterface (\r
- &DriverBinding->DriverBindingHandle,\r
- &gEfiComponentNameProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- ComponentName\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- }\r
-\r
- if (ComponentName2 != NULL) {\r
- Status = gBS->InstallProtocolInterface (\r
- &DriverBinding->DriverBindingHandle,\r
- &gEfiComponentName2ProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- ComponentName2\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- }\r
-\r
- if (DriverConfiguration != NULL) {\r
- Status = gBS->InstallProtocolInterface (\r
- &DriverBinding->DriverBindingHandle,\r
- &gEfiDriverConfigurationProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- DriverConfiguration\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- }\r
-\r
- if (DriverConfiguration2 != NULL) {\r
- Status = gBS->InstallProtocolInterface (\r
- &DriverBinding->DriverBindingHandle,\r
- &gEfiDriverConfiguration2ProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- DriverConfiguration2\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- }\r
-\r
- if (DriverDiagnostics != NULL) {\r
- Status = gBS->InstallProtocolInterface (\r
- &DriverBinding->DriverBindingHandle,\r
- &gEfiDriverDiagnosticsProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- DriverDiagnostics\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- }\r
-\r
- if (DriverDiagnostics2 != NULL) {\r
- Status = gBS->InstallProtocolInterface (\r
- &DriverBinding->DriverBindingHandle,\r
- &gEfiDriverDiagnostics2ProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- DriverDiagnostics2\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EfiLibInstallAllDriverProtocols (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE * SystemTable,\r
- IN EFI_DRIVER_BINDING_PROTOCOL * DriverBinding,\r
- IN EFI_HANDLE DriverBindingHandle,\r
- IN EFI_COMPONENT_NAME_PROTOCOL * ComponentName, OPTIONAL\r
- IN EFI_DRIVER_CONFIGURATION_PROTOCOL * DriverConfiguration, OPTIONAL\r
- IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL * DriverDiagnostics OPTIONAL\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Intialize a driver by installing the Driver Binding Protocol onto the \r
- driver's DriverBindingHandle. This is typically the same as the driver's\r
- ImageHandle, but it can be different if the driver produces multiple\r
- DriverBinding Protocols. This function also initializes the EFI Driver\r
- Library that initializes the global variables gST, gBS, gRT.\r
-\r
-Arguments:\r
-\r
- ImageHandle - The image handle of the driver\r
-\r
- SystemTable - The EFI System Table that was passed to the driver's entry point\r
-\r
- DriverBinding - A Driver Binding Protocol instance that this driver is producing\r
-\r
- DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this\r
- parameter is NULL, then a new handle is created.\r
-\r
- ComponentName - A Component Name Protocol instance that this driver is producing\r
-\r
- DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing\r
- \r
- DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing\r
-\r
-Returns: \r
-\r
- EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle\r
-\r
- Otherwise, then return status from gBS->InstallProtocolInterface()\r
-\r
---*/\r
-{\r
- return InstallAllDriverProtocolsWorker (\r
- ImageHandle,\r
- SystemTable,\r
- DriverBinding,\r
- DriverBindingHandle,\r
- ComponentName,\r
- NULL,\r
- DriverConfiguration,\r
- NULL,\r
- DriverDiagnostics,\r
- NULL\r
- );\r
-}\r
-\r
-EFI_STATUS\r
-EfiLibInstallAllDriverProtocols2 (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE * SystemTable,\r
- IN EFI_DRIVER_BINDING_PROTOCOL * DriverBinding,\r
- IN EFI_HANDLE DriverBindingHandle,\r
- IN EFI_COMPONENT_NAME2_PROTOCOL * ComponentName2, OPTIONAL\r
- IN EFI_DRIVER_CONFIGURATION2_PROTOCOL * DriverConfiguration2, OPTIONAL\r
- IN EFI_DRIVER_DIAGNOSTICS2_PROTOCOL * DriverDiagnostics2 OPTIONAL\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Intialize a driver by installing the Driver Binding Protocol onto the \r
- driver's DriverBindingHandle. This is typically the same as the driver's\r
- ImageHandle, but it can be different if the driver produces multiple\r
- DriverBinding Protocols. This function also initializes the EFI Driver\r
- Library that initializes the global variables gST, gBS, gRT.\r
-\r
-Arguments:\r
-\r
- ImageHandle - The image handle of the driver\r
-\r
- SystemTable - The EFI System Table that was passed to the driver's entry point\r
-\r
- DriverBinding - A Driver Binding Protocol instance that this driver is producing\r
-\r
- DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this\r
- parameter is NULL, then a new handle is created.\r
-\r
- ComponentName2 - A Component Name2 Protocol instance that this driver is producing\r
-\r
- DriverConfiguration2- A Driver Configuration2 Protocol instance that this driver is producing\r
- \r
- DriverDiagnostics2 - A Driver Diagnostics2 Protocol instance that this driver is producing\r
-\r
-Returns: \r
-\r
- EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle\r
-\r
- Otherwise, then return status from gBS->InstallProtocolInterface()\r
-\r
---*/\r
-{\r
- return InstallAllDriverProtocolsWorker (\r
- ImageHandle,\r
- SystemTable,\r
- DriverBinding,\r
- DriverBindingHandle,\r
- NULL,\r
- ComponentName2,\r
- NULL,\r
- DriverConfiguration2,\r
- NULL,\r
- DriverDiagnostics2\r
- );\r
-}\r
-\r
-EFI_STATUS\r
-EfiLibTestManagedDevice (\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_HANDLE DriverBindingHandle,\r
- IN EFI_GUID *ManagedProtocolGuid\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Test to see if the controller is managed by a specific driver.\r
-\r
-Arguments:\r
-\r
- ControllerHandle - Handle for controller to test\r
-\r
- DriverBindingHandle - Driver binding handle for controller\r
-\r
- ManagedProtocolGuid - The protocol guid the driver opens on controller\r
-\r
-Returns: \r
-\r
- EFI_SUCCESS - The controller is managed by the driver\r
-\r
- EFI_UNSUPPORTED - The controller is not managed by the driver\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- VOID *ManagedInterface;\r
-\r
- Status = gBS->OpenProtocol (\r
- ControllerHandle,\r
- ManagedProtocolGuid,\r
- &ManagedInterface,\r
- DriverBindingHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_BY_DRIVER\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- gBS->CloseProtocol (\r
- ControllerHandle,\r
- ManagedProtocolGuid,\r
- DriverBindingHandle,\r
- ControllerHandle\r
- );\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- if (Status != EFI_ALREADY_STARTED) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EfiLibTestChildHandle (\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_HANDLE ChildHandle,\r
- IN EFI_GUID *ConsumedGuid\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Test to see if the child handle is the child of the controller\r
-\r
-Arguments:\r
-\r
- ControllerHandle - Handle for controller (parent)\r
-\r
- ChildHandle - Child handle to test\r
-\r
- ConsumsedGuid - Protocol guid consumed by child from controller\r
-\r
-Returns: \r
-\r
- EFI_SUCCESS - The child handle is the child of the controller\r
-\r
- EFI_UNSUPPORTED - The child handle is not the child of the controller\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
- UINTN EntryCount;\r
- UINTN Index;\r
-\r
- //\r
- // Retrieve the list of agents that are consuming one of the protocols\r
- // on ControllerHandle that the children consume\r
- //\r
- Status = gBS->OpenProtocolInformation (\r
- ControllerHandle,\r
- ConsumedGuid,\r
- &OpenInfoBuffer,\r
- &EntryCount\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- //\r
- // See if one of the agents is ChildHandle\r
- //\r
- Status = EFI_UNSUPPORTED;\r
- for (Index = 0; Index < EntryCount; Index++) {\r
- if (OpenInfoBuffer[Index].ControllerHandle == ChildHandle &&\r
- OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {\r
- Status = EFI_SUCCESS;\r
- }\r
- }\r
- gBS->FreePool (OpenInfoBuffer);\r
- return Status;\r
-}\r