+/** @file\r
+ This file consumes the ISA Host Controller protocol produced by the ISA Host\r
+ Controller and installs the ISA Host Controller Service Binding protocol\r
+ on the ISA Host Controller's handle.\r
+\r
+ Copyright (c) 2015, 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
+\r
+**/\r
+\r
+#include "IsaBusDxe.h"\r
+#include "ComponentName.h"\r
+\r
+/**\r
+ Tests to see if this driver supports a given controller. If a child device is provided, \r
+ it further tests to see if this driver supports creating a handle for the specified child device.\r
+\r
+ @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+ @param[in] ControllerHandle The handle of the controller to test. This handle \r
+ must support a protocol interface that supplies \r
+ an I/O abstraction to the driver.\r
+ @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r
+ parameter is ignored by device drivers, and is optional for bus \r
+ drivers. For bus drivers, if this parameter is not NULL, then \r
+ the bus driver must determine if the bus controller specified \r
+ by ControllerHandle and the child controller specified \r
+ by RemainingDevicePath are both supported by this \r
+ bus driver.\r
+\r
+ @retval EFI_SUCCESS The device specified by ControllerHandle and\r
+ RemainingDevicePath is supported by the driver specified by This.\r
+ @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
+ RemainingDevicePath is already being managed by the driver\r
+ specified by This.\r
+ @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
+ RemainingDevicePath is already being managed by a different\r
+ driver or an application that requires exclusive access.\r
+ Currently not implemented.\r
+ @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
+ RemainingDevicePath is not supported by the driver specified by This.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IsaBusDriverBindingSupported (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ VOID *Instance;\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiIsaHcProtocolGuid,\r
+ &Instance,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiIsaHcProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ &Instance,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
+ISA_BUS_CHILD_PRIVATE_DATA mIsaBusChildPrivateTemplate = {\r
+ ISA_BUS_CHILD_PRIVATE_DATA_SIGNATURE,\r
+ FALSE\r
+};\r
+\r
+/**\r
+ Creates a child handle and installs a protocol.\r
+ \r
+ The CreateChild() function installs a protocol on ChildHandle. \r
+ If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle. \r
+ If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.\r
+\r
+ @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r
+ @param ChildHandle Pointer to the handle of the child to create. If it is NULL,\r
+ then a new handle is created. If it is a pointer to an existing UEFI handle, \r
+ then the protocol is added to the existing UEFI handle.\r
+\r
+ @retval EFI_SUCCES The protocol was added to ChildHandle.\r
+ @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create\r
+ the child\r
+ @retval other The child handle was not created\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IsaBusCreateChild (\r
+ IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
+ IN OUT EFI_HANDLE *ChildHandle\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ ISA_BUS_PRIVATE_DATA *Private;\r
+ EFI_ISA_HC_PROTOCOL *IsaHc;\r
+ ISA_BUS_CHILD_PRIVATE_DATA *Child;\r
+\r
+ Private = ISA_BUS_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+ Child = AllocateCopyPool (sizeof (mIsaBusChildPrivateTemplate), &mIsaBusChildPrivateTemplate);\r
+ if (Child == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ ChildHandle,\r
+ &gEfiIsaHcProtocolGuid, Private->IsaHc,\r
+ &gEfiCallerIdGuid, Child,\r
+ NULL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ FreePool (Child);\r
+ return Status;\r
+ }\r
+\r
+ return gBS->OpenProtocol (\r
+ Private->IsaHcHandle,\r
+ &gEfiIsaHcProtocolGuid,\r
+ (VOID **) &IsaHc,\r
+ gIsaBusDriverBinding.DriverBindingHandle,\r
+ *ChildHandle,\r
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+ );\r
+}\r
+\r
+/**\r
+ Destroys a child handle with a protocol installed on it.\r
+ \r
+ The DestroyChild() function does the opposite of CreateChild(). It removes a protocol \r
+ that was installed by CreateChild() from ChildHandle. If the removed protocol is the \r
+ last protocol on ChildHandle, then ChildHandle is destroyed.\r
+\r
+ @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r
+ @param ChildHandle Handle of the child to destroy\r
+\r
+ @retval EFI_SUCCES The protocol was removed from ChildHandle.\r
+ @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r
+ @retval EFI_INVALID_PARAMETER Child handle is NULL.\r
+ @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle\r
+ because its services are being used.\r
+ @retval other The child handle was not destroyed\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IsaBusDestroyChild (\r
+ IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE ChildHandle\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ ISA_BUS_PRIVATE_DATA *Private;\r
+ EFI_ISA_HC_PROTOCOL *IsaHc;\r
+ ISA_BUS_CHILD_PRIVATE_DATA *Child;\r
+\r
+ Private = ISA_BUS_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+ Status = gBS->OpenProtocol (\r
+ ChildHandle,\r
+ &gEfiCallerIdGuid,\r
+ (VOID **) &Child,\r
+ gIsaBusDriverBinding.DriverBindingHandle,\r
+ ChildHandle,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ ASSERT (Child->Signature == ISA_BUS_CHILD_PRIVATE_DATA_SIGNATURE);\r
+\r
+ if (Child->InDestroying) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ Child->InDestroying = TRUE;\r
+ Status = gBS->CloseProtocol (\r
+ Private->IsaHcHandle,\r
+ &gEfiIsaHcProtocolGuid,\r
+ gIsaBusDriverBinding.DriverBindingHandle,\r
+ ChildHandle\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ if (!EFI_ERROR (Status)) {\r
+ Status = gBS->UninstallMultipleProtocolInterfaces (\r
+ ChildHandle,\r
+ &gEfiIsaHcProtocolGuid, Private->IsaHc,\r
+ &gEfiCallerIdGuid, Child,\r
+ NULL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ gBS->OpenProtocol (\r
+ Private->IsaHcHandle,\r
+ &gEfiIsaHcProtocolGuid,\r
+ (VOID **) &IsaHc,\r
+ gIsaBusDriverBinding.DriverBindingHandle,\r
+ ChildHandle,\r
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+ );\r
+ }\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ Child->InDestroying = FALSE;\r
+ } else {\r
+ FreePool (Child);\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
+ISA_BUS_PRIVATE_DATA mIsaBusPrivateTemplate = {\r
+ ISA_BUS_PRIVATE_DATA_SIGNATURE,\r
+ {\r
+ IsaBusCreateChild,\r
+ IsaBusDestroyChild\r
+ }\r
+};\r
+\r
+/**\r
+ Starts a device controller or a bus controller.\r
+\r
+ @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+ @param[in] ControllerHandle The handle of the controller to start. This handle \r
+ must support a protocol interface that supplies \r
+ an I/O abstraction to the driver.\r
+ @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r
+ parameter is ignored by device drivers, and is optional for bus \r
+ drivers. For a bus driver, if this parameter is NULL, then handles \r
+ for all the children of Controller are created by this driver. \r
+ If this parameter is not NULL and the first Device Path Node is \r
+ not the End of Device Path Node, then only the handle for the \r
+ child device specified by the first Device Path Node of \r
+ RemainingDevicePath is created by this driver.\r
+ If the first Device Path Node of RemainingDevicePath is \r
+ the End of Device Path Node, no child handle is created by this\r
+ driver.\r
+\r
+ @retval EFI_SUCCESS The device was started.\r
+ @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
+ @retval Others The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IsaBusDriverBindingStart (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
+ ISA_BUS_PRIVATE_DATA *Private;\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiIsaHcProtocolGuid,\r
+ (VOID **) &mIsaBusPrivateTemplate.IsaHc,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ (VOID **) &DevicePath,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiIsaHcProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+ return Status;\r
+ }\r
+\r
+ Private = AllocateCopyPool (sizeof (mIsaBusPrivateTemplate), &mIsaBusPrivateTemplate);\r
+ ASSERT (Private != NULL);\r
+\r
+ Private->IsaHcHandle = Controller;\r
+\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ &Controller,\r
+ &gEfiIsaHcServiceBindingProtocolGuid, &Private->ServiceBinding,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Stops a device controller or a bus controller.\r
+ \r
+ @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+ @param[in] ControllerHandle A handle to the device being stopped. The handle must \r
+ support a bus specific I/O protocol for the driver \r
+ to use to stop the device.\r
+ @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
+ @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r
+ if NumberOfChildren is 0.\r
+\r
+ @retval EFI_SUCCESS The device was stopped.\r
+ @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IsaBusDriverBindingStop (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN UINTN NumberOfChildren,\r
+ IN EFI_HANDLE *ChildHandleBuffer\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
+ ISA_BUS_PRIVATE_DATA *Private;\r
+ UINTN Index;\r
+ BOOLEAN AllChildrenStopped;\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiIsaHcServiceBindingProtocolGuid,\r
+ (VOID **) &ServiceBinding,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Private = ISA_BUS_PRIVATE_DATA_FROM_THIS (ServiceBinding);\r
+\r
+ if (NumberOfChildren == 0) {\r
+ Status = gBS->UninstallMultipleProtocolInterfaces (\r
+ Controller,\r
+ &gEfiIsaHcServiceBindingProtocolGuid, &Private->ServiceBinding,\r
+ NULL\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiIsaHcProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+ FreePool (Private);\r
+ }\r
+\r
+ return Status;\r
+ }\r
+\r
+ AllChildrenStopped = TRUE;\r
+ for (Index = 0; Index < NumberOfChildren; Index++) {\r
+ Status = ServiceBinding->DestroyChild (ServiceBinding, ChildHandleBuffer[Index]);\r
+ if (EFI_ERROR (Status)) {\r
+ AllChildrenStopped = FALSE;\r
+ }\r
+ }\r
+\r
+ return AllChildrenStopped ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
+}\r
+\r
+//\r
+// ISA Bus Driver Binding Protocol Instance\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL gIsaBusDriverBinding = {\r
+ IsaBusDriverBindingSupported,\r
+ IsaBusDriverBindingStart,\r
+ IsaBusDriverBindingStop,\r
+ 0x10,\r
+ NULL,\r
+ NULL\r
+};\r
+\r
+/**\r
+ Entry point of the IsaBusDxe driver.\r
+ \r
+ @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
+ @param[in] SystemTable A pointer to the EFI System Table.\r
+ \r
+ @retval EFI_SUCCESS The entry point is executed successfully.\r
+ @retval other Some error occurs when executing this entry point.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeIsaBus (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ \r
+ Status = EfiLibInstallDriverBindingComponentName2 (\r
+ ImageHandle,\r
+ SystemTable,\r
+ &gIsaBusDriverBinding,\r
+ ImageHandle,\r
+ &gIsaBusComponentName,\r
+ &gIsaBusComponentName2\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ return Status;\r
+}\r