/** Starts a device controller or a bus controller. The Start() function is designed to be invoked from the EFI boot service ConnectController(). As a result, much of the error checking on the parameters to Start() has been moved into this common boot service. It is legal to call Start() from other locations, but the following calling restrictions must be followed or the system behavior will not be deterministic. 1. ControllerHandle must be a valid EFI_HANDLE. 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned EFI_DEVICE_PATH_PROTOCOL. 3. Prior to calling Start(), the Supported() function for the driver specified by This must have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. @param[in] ControllerHandle The handle of the controller to start. This handle must support a protocol interface that supplies an I/O abstraction to the driver. @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This parameter is ignored by device drivers, and is optional for bus drivers. For a bus driver, if this parameter is NULL, then handles for all the children of Controller are created by this driver. If this parameter is not NULL and the first Device Path Node is not the End of Device Path Node, then only the handle for the child device specified by the first Device Path Node of RemainingDevicePath is created by this driver. If the first Device Path Node of RemainingDevicePath is the End of Device Path Node, no child handle is created by this driver. @retval EFI_SUCCESS The device was started. @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented. @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. @retval Others The driver failded to start the device. **/ EFI_STATUS EFIAPI EmmcDxeDriverBindingStart ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) { EFI_STATUS Status; EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru; EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath; EMMC_DRIVER_PRIVATE_DATA *Private; UINT8 Slot; Private = NULL; PassThru = NULL; Status = gBS->OpenProtocol ( Controller, &gEfiSdMmcPassThruProtocolGuid, (VOID **) &PassThru, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_BY_DRIVER ); if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) { return Status; } // // Check EFI_ALREADY_STARTED to reuse the original EMMC_DRIVER_PRIVATE_DATA. // if (Status != EFI_ALREADY_STARTED) { Private = AllocateZeroPool (sizeof (EMMC_DRIVER_PRIVATE_DATA)); if (Private == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Error; } Status = gBS->OpenProtocol ( Controller, &gEfiDevicePathProtocolGuid, (VOID **) &ParentDevicePath, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); ASSERT_EFI_ERROR (Status); Private->PassThru = PassThru; Private->Controller = Controller; Private->ParentDevicePath = ParentDevicePath; Private->DriverBindingHandle = This->DriverBindingHandle; Status = gBS->InstallProtocolInterface ( &Controller, &gEfiCallerIdGuid, EFI_NATIVE_INTERFACE, Private ); if (EFI_ERROR (Status)) { goto Error; } } else { Status = gBS->OpenProtocol ( Controller, &gEfiCallerIdGuid, (VOID **) &Private, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { goto Error; } } if (RemainingDevicePath == NULL) { Slot = 0xFF; while (TRUE) { Status = PassThru->GetNextSlot (PassThru, &Slot); if (EFI_ERROR (Status)) { // // Cannot find more legal slots. // Status = EFI_SUCCESS; break; } Status = DiscoverEmmcDevice (Private, Slot, NULL); if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) { break; } } } else if (!IsDevicePathEnd (RemainingDevicePath)) { Status = PassThru->GetSlotNumber (PassThru, RemainingDevicePath, &Slot); if (!EFI_ERROR (Status)) { Status = DiscoverEmmcDevice (Private, Slot, NextDevicePathNode (RemainingDevicePath)); } } Error: if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) { gBS->CloseProtocol ( Controller, &gEfiSdMmcPassThruProtocolGuid, This->DriverBindingHandle, Controller ); if (Private != NULL) { gBS->UninstallMultipleProtocolInterfaces ( Controller, &gEfiCallerIdGuid, Private, NULL ); FreePool (Private); } } return Status; }