/** Resets the SCSI Bus that the SCSI Controller is attached to. @param This Protocol instance pointer. @retval EFI_SUCCESS The SCSI bus is reset successfully. @retval EFI_DEVICE_ERROR Errors encountered when resetting the SCSI bus. @retval EFI_UNSUPPORTED The bus reset operation is not supported by the SCSI Host Controller. @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI bus. **/ EFI_STATUS EFIAPI ScsiResetBus ( IN EFI_SCSI_IO_PROTOCOL *This ) { SCSI_IO_DEV *ScsiIoDevice; ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This); // // Report Status Code to indicate reset happens // REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_RESET), ScsiIoDevice->ScsiBusDeviceData->DevicePath ); if (ScsiIoDevice->ExtScsiSupport){ return ScsiIoDevice->ExtScsiPassThru->ResetChannel (ScsiIoDevice->ExtScsiPassThru); } else { return ScsiIoDevice->ScsiPassThru->ResetChannel (ScsiIoDevice->ScsiPassThru); } }
/** Resets the SCSI Controller that the device handle specifies. @param This Protocol instance pointer. @retval EFI_SUCCESS Reset the SCSI controller successfully. @retval EFI_DEVICE_ERROR Errors are encountered when resetting the SCSI Controller. @retval EFI_UNSUPPORTED The SCSI bus does not support a device reset operation. @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI Controller. **/ EFI_STATUS EFIAPI ScsiResetDevice ( IN EFI_SCSI_IO_PROTOCOL *This ) { SCSI_IO_DEV *ScsiIoDevice; UINT8 Target[TARGET_MAX_BYTES]; ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This); CopyMem (Target,&ScsiIoDevice->Pun, TARGET_MAX_BYTES); if (ScsiIoDevice->ExtScsiSupport) { return ScsiIoDevice->ExtScsiPassThru->ResetTargetLun ( ScsiIoDevice->ExtScsiPassThru, Target, ScsiIoDevice->Lun ); } else { return ScsiIoDevice->ScsiPassThru->ResetTarget ( ScsiIoDevice->ScsiPassThru, ScsiIoDevice->Pun.ScsiId.Scsi, ScsiIoDevice->Lun ); } }
/** Resets the SCSI Bus that the SCSI Controller is attached to. @param This Protocol instance pointer. @retval EFI_SUCCESS The SCSI bus is reset successfully. @retval EFI_DEVICE_ERROR Errors encountered when resetting the SCSI bus. @retval EFI_UNSUPPORTED The bus reset operation is not supported by the SCSI Host Controller. @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI bus. **/ EFI_STATUS EFIAPI ScsiResetBus ( IN EFI_SCSI_IO_PROTOCOL *This ) { SCSI_IO_DEV *ScsiIoDevice; ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This); if (ScsiIoDevice->ExtScsiSupport){ return ScsiIoDevice->ExtScsiPassThru->ResetChannel (ScsiIoDevice->ExtScsiPassThru); } else { return ScsiIoDevice->ScsiPassThru->ResetChannel (ScsiIoDevice->ScsiPassThru); } }
/** Retrieves the device type information of the SCSI Controller. @param This Protocol instance pointer. @param DeviceType A pointer to the device type information retrieved from the SCSI Controller. @retval EFI_SUCCESS Retrieves the device type information successfully. @retval EFI_INVALID_PARAMETER The DeviceType is NULL. **/ EFI_STATUS EFIAPI ScsiGetDeviceType ( IN EFI_SCSI_IO_PROTOCOL *This, OUT UINT8 *DeviceType ) { SCSI_IO_DEV *ScsiIoDevice; if (DeviceType == NULL) { return EFI_INVALID_PARAMETER; } ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This); *DeviceType = ScsiIoDevice->ScsiDeviceType; return EFI_SUCCESS; }
/** Retrieves the device location in the SCSI channel. @param This Protocol instance pointer. @param Target A pointer to the Target ID of a SCSI device on the SCSI channel. @param Lun A pointer to the LUN of the SCSI device on the SCSI channel. @retval EFI_SUCCESS Retrieves the device location successfully. @retval EFI_INVALID_PARAMETER The Target or Lun is NULL. **/ EFI_STATUS EFIAPI ScsiGetDeviceLocation ( IN EFI_SCSI_IO_PROTOCOL *This, IN OUT UINT8 **Target, OUT UINT64 *Lun ) { SCSI_IO_DEV *ScsiIoDevice; if (Target == NULL || Lun == NULL) { return EFI_INVALID_PARAMETER; } ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This); CopyMem (*Target,&ScsiIoDevice->Pun, TARGET_MAX_BYTES); *Lun = ScsiIoDevice->Lun; return EFI_SUCCESS; }
/** Resets the SCSI Controller that the device handle specifies. @param This Protocol instance pointer. @retval EFI_SUCCESS Reset the SCSI controller successfully. @retval EFI_DEVICE_ERROR Errors are encountered when resetting the SCSI Controller. @retval EFI_UNSUPPORTED The SCSI bus does not support a device reset operation. @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI Controller. **/ EFI_STATUS EFIAPI ScsiResetDevice ( IN EFI_SCSI_IO_PROTOCOL *This ) { SCSI_IO_DEV *ScsiIoDevice; UINT8 Target[TARGET_MAX_BYTES]; ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This); // // Report Status Code to indicate reset happens // REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_RESET), ScsiIoDevice->ScsiBusDeviceData->DevicePath ); CopyMem (Target,&ScsiIoDevice->Pun, TARGET_MAX_BYTES); if (ScsiIoDevice->ExtScsiSupport) { return ScsiIoDevice->ExtScsiPassThru->ResetTargetLun ( ScsiIoDevice->ExtScsiPassThru, Target, ScsiIoDevice->Lun ); } else { return ScsiIoDevice->ScsiPassThru->ResetTarget ( ScsiIoDevice->ScsiPassThru, ScsiIoDevice->Pun.ScsiId.Scsi, ScsiIoDevice->Lun ); } }
/** Sends a SCSI Request Packet to the SCSI Controller for execution. @param This Protocol instance pointer. @param CommandPacket The SCSI request packet to send to the SCSI Controller specified by the device handle. @param Event If the SCSI bus where the SCSI device is attached does not support non-blocking I/O, then Event is ignored, and blocking I/O is performed. If Event is NULL, then blocking I/O is performed. If Event is not NULL and non-blocking I/O is supported, then non-blocking I/O is performed, and Event will be signaled when the SCSI Request Packet completes. @retval EFI_SUCCESS The SCSI Request Packet was sent by the host successfully, and TransferLength bytes were transferred to/from DataBuffer.See HostAdapterStatus, TargetStatus, SenseDataLength, and SenseData in that order for additional status information. @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could not be transferred. The actual number of bytes transferred is returned in TransferLength. See HostAdapterStatus, TargetStatus, SenseDataLength, and SenseData in that order for additional status information. @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many SCSI Command Packets already queued.The caller may retry again later. @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request Packet. See HostAdapterStatus, TargetStatus, SenseDataLength, and SenseData in that order for additional status information. @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid. The SCSI Request Packet was not sent, so no additional status information is available. @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by the SCSI initiator(i.e., SCSI Host Controller). The SCSI Request Packet was not sent, so no additional status information is available. @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute. See HostAdapterStatus, TargetStatus, SenseDataLength, and SenseData in that order for additional status information. **/ EFI_STATUS EFIAPI ScsiExecuteSCSICommand ( IN EFI_SCSI_IO_PROTOCOL *This, IN OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet, IN EFI_EVENT Event OPTIONAL ) { SCSI_IO_DEV *ScsiIoDevice; EFI_STATUS Status; UINT8 Target[TARGET_MAX_BYTES]; EFI_EVENT PacketEvent; EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *ExtRequestPacket; SCSI_EVENT_DATA EventData; PacketEvent = NULL; if (Packet == NULL) { return EFI_INVALID_PARAMETER; } ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This); CopyMem (Target,&ScsiIoDevice->Pun, TARGET_MAX_BYTES); if (ScsiIoDevice->ExtScsiSupport) { ExtRequestPacket = (EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *) Packet; Status = ScsiIoDevice->ExtScsiPassThru->PassThru ( ScsiIoDevice->ExtScsiPassThru, Target, ScsiIoDevice->Lun, ExtRequestPacket, Event ); } else { mWorkingBuffer = AllocatePool (sizeof(EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET)); if (mWorkingBuffer == NULL) { return EFI_DEVICE_ERROR; } // // Convert package into EFI1.0, EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET. // Status = ScsiioToPassThruPacket(Packet, (EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET*)mWorkingBuffer); if (EFI_ERROR(Status)) { FreePool(mWorkingBuffer); return Status; } if (((ScsiIoDevice->ScsiPassThru->Mode->Attributes & EFI_SCSI_PASS_THRU_ATTRIBUTES_NONBLOCKIO) != 0) && (Event != NULL)) { EventData.Data1 = (VOID*)Packet; EventData.Data2 = Event; // // Create Event // Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL, TPL_CALLBACK, NotifyFunction, &EventData, &PacketEvent ); if (EFI_ERROR(Status)) { FreePool(mWorkingBuffer); return Status; } Status = ScsiIoDevice->ScsiPassThru->PassThru ( ScsiIoDevice->ScsiPassThru, ScsiIoDevice->Pun.ScsiId.Scsi, ScsiIoDevice->Lun, mWorkingBuffer, PacketEvent ); if (EFI_ERROR(Status)) { FreePool(mWorkingBuffer); gBS->CloseEvent(PacketEvent); return Status; } } else { // // If there's no event or SCSI Device doesn't support NON-BLOCKING, just convert // EFI1.0 PassThru packet back to UEFI2.0 SCSI IO Packet. // Status = ScsiIoDevice->ScsiPassThru->PassThru ( ScsiIoDevice->ScsiPassThru, ScsiIoDevice->Pun.ScsiId.Scsi, ScsiIoDevice->Lun, mWorkingBuffer, Event ); if (EFI_ERROR(Status)) { FreePool(mWorkingBuffer); return Status; } PassThruToScsiioPacket((EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET*)mWorkingBuffer,Packet); // // After converting EFI1.0 PassThru Packet back to UEFI2.0 SCSI IO Packet, // free mWorkingBuffer. // FreePool(mWorkingBuffer); } } return Status; }
/** Stop this driver on ControllerHandle. This service is called by the EFI boot service DisconnectController(). In order to make drivers as small as possible, there are a few calling restrictions for this service. DisconnectController() must follow these calling restrictions. If any other agent wishes to call Stop() it must also follow these calling restrictions. @param This Protocol instance pointer. @param ControllerHandle Handle of device to stop driver on @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of children is zero stop the entire bus driver. @param ChildHandleBuffer List of Child Handles to Stop. @retval EFI_SUCCESS This driver is removed ControllerHandle @retval other This driver was not removed from this device **/ EFI_STATUS EFIAPI SCSIBusDriverBindingStop ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer ) { EFI_STATUS Status; BOOLEAN AllChildrenStopped; UINTN Index; EFI_SCSI_IO_PROTOCOL *ScsiIo; SCSI_IO_DEV *ScsiIoDevice; VOID *ScsiPassThru; EFI_SCSI_BUS_PROTOCOL *Scsidentifier; SCSI_BUS_DEVICE *ScsiBusDev; if (NumberOfChildren == 0) { // // Get the SCSI_BUS_DEVICE // Status = gBS->OpenProtocol ( Controller, &gEfiCallerIdGuid, (VOID **) &Scsidentifier, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } ScsiBusDev = SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS (Scsidentifier); // // Uninstall SCSI Bus Protocol // gBS->UninstallProtocolInterface ( Controller, &gEfiCallerIdGuid, &ScsiBusDev->BusIdentify ); // // Close the bus driver // if (ScsiBusDev->ExtScsiSupport) { // // Close ExtPassThru Protocol from this controller handle // gBS->CloseProtocol ( Controller, &gEfiExtScsiPassThruProtocolGuid, This->DriverBindingHandle, Controller ); // // When Start() succeeds to open ExtPassThru, it always tries to open PassThru BY_DRIVER. // Its intent is to prevent another SCSI Bus Driver from woking on the same host handle. // So Stop() needs to try to close PassThru if present here. // gBS->CloseProtocol ( Controller, &gEfiScsiPassThruProtocolGuid, This->DriverBindingHandle, Controller ); } else { gBS->CloseProtocol ( Controller, &gEfiScsiPassThruProtocolGuid, This->DriverBindingHandle, Controller ); } gBS->CloseProtocol ( Controller, &gEfiDevicePathProtocolGuid, This->DriverBindingHandle, Controller ); FreePool (ScsiBusDev); return EFI_SUCCESS; } AllChildrenStopped = TRUE; for (Index = 0; Index < NumberOfChildren; Index++) { Status = gBS->OpenProtocol ( ChildHandleBuffer[Index], &gEfiScsiIoProtocolGuid, (VOID **) &ScsiIo, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { AllChildrenStopped = FALSE; continue; } ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (ScsiIo); // // Close the child handle // if (ScsiIoDevice->ExtScsiSupport) { Status = gBS->CloseProtocol ( Controller, &gEfiExtScsiPassThruProtocolGuid, This->DriverBindingHandle, ChildHandleBuffer[Index] ); } else { Status = gBS->CloseProtocol ( Controller, &gEfiScsiPassThruProtocolGuid, This->DriverBindingHandle, ChildHandleBuffer[Index] ); } Status = gBS->UninstallMultipleProtocolInterfaces ( ChildHandleBuffer[Index], &gEfiDevicePathProtocolGuid, ScsiIoDevice->DevicePath, &gEfiScsiIoProtocolGuid, &ScsiIoDevice->ScsiIo, NULL ); if (EFI_ERROR (Status)) { AllChildrenStopped = FALSE; if (ScsiIoDevice->ExtScsiSupport) { gBS->OpenProtocol ( Controller, &gEfiExtScsiPassThruProtocolGuid, &ScsiPassThru, This->DriverBindingHandle, ChildHandleBuffer[Index], EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ); } else { gBS->OpenProtocol ( Controller, &gEfiScsiPassThruProtocolGuid, &ScsiPassThru, This->DriverBindingHandle, ChildHandleBuffer[Index], EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ); } } else { FreePool (ScsiIoDevice); } } if (!AllChildrenStopped) { return EFI_DEVICE_ERROR; } return EFI_SUCCESS; }