/** Read data from a block IO device @param This Block IO protocol instance pointer. @param MediaId The media ID of the device @param Lba Starting LBA address to read data @param BufferSize The size of data to be read @param Buffer Caller supplied buffer to save data @retval EFI_DEVICE_ERROR unknown device type @retval other read data status. **/ EFI_STATUS EFIAPI IDEBlkIoReadBlocks ( IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, OUT VOID *Buffer ) { IDE_BLK_IO_DEV *IdeBlkIoDevice; EFI_STATUS Status; EFI_TPL OldTpl; OldTpl = gBS->RaiseTPL (TPL_CALLBACK); IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (This); // // Requery IDE IO resources in case of the switch of native and legacy modes // ReassignIdeResources (IdeBlkIoDevice); // // For ATA compatible device, use ATA read block's mechanism // if (IdeBlkIoDevice->Type == IdeHardDisk || IdeBlkIoDevice->Type == Ide48bitAddressingHardDisk) { Status = AtaBlkIoReadBlocks ( IdeBlkIoDevice, MediaId, Lba, BufferSize, Buffer ); goto Done; } if (IdeBlkIoDevice->Type == IdeUnknown) { Status = EFI_DEVICE_ERROR; goto Done; } // // for ATAPI device, using ATAPI read block's mechanism // Status = AtapiBlkIoReadBlocks ( IdeBlkIoDevice, MediaId, Lba, BufferSize, Buffer ); Done: gBS->RestoreTPL (OldTpl); return Status; }
/** issue ATA or ATAPI command to reset a block IO device. @param This Block IO protocol instance pointer. @param ExtendedVerification If FALSE,for ATAPI device, driver will only invoke ATAPI reset method If TRUE, for ATAPI device, driver need invoke ATA reset method after invoke ATAPI reset method @retval EFI_DEVICE_ERROR When the device is neighther ATA device or ATAPI device. @retval EFI_SUCCESS The device reset successfully **/ EFI_STATUS EFIAPI IDEBlkIoReset ( IN EFI_BLOCK_IO_PROTOCOL *This, IN BOOLEAN ExtendedVerification ) { IDE_BLK_IO_DEV *IdeBlkIoDevice; EFI_STATUS Status; EFI_TPL OldTpl; OldTpl = gBS->RaiseTPL (TPL_CALLBACK); IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (This); // // Requery IDE IO resources in case of the switch of native and legacy modes // ReassignIdeResources (IdeBlkIoDevice); // // for ATA device, using ATA reset method // if (IdeBlkIoDevice->Type == IdeHardDisk || IdeBlkIoDevice->Type == Ide48bitAddressingHardDisk) { Status = AtaSoftReset (IdeBlkIoDevice); goto Done; } if (IdeBlkIoDevice->Type == IdeUnknown) { Status = EFI_DEVICE_ERROR; goto Done; } // // for ATAPI device, using ATAPI reset method // Status = AtapiSoftReset (IdeBlkIoDevice); if (ExtendedVerification) { Status = AtaSoftReset (IdeBlkIoDevice); } Done: gBS->RestoreTPL (OldTpl); return Status; }
EFI_STATUS EFIAPI IdeControllerGetControllerName ( #if (EFI_SPECIFICATION_VERSION >= 0x00020000) IN EFI_COMPONENT_NAME2_PROTOCOL *This, #else IN EFI_COMPONENT_NAME_PROTOCOL *This, #endif IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName ) /*++ Routine Description: Retrieves a Unicode string that is the user readable name of the controller that is being managed by an EFI Driver. Arguments: This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance. ControllerHandle - The handle of a controller that the driver specified by This is managing. This handle specifies the controller whose name is to be returned. ChildHandle - The handle of the child controller to retrieve the name of. This is an optional parameter that may be NULL. It will be NULL for device drivers. It will also be NULL for a bus drivers that wish to retrieve the name of the bus controller. It will not be NULL for a bus driver that wishes to retrieve the name of a child controller. Language - A pointer to a three character ISO 639-2 language identifier. This is the language of the controller name that that the caller is requesting, and it must match one of the languages specified in SupportedLanguages. The number of languages supported by a driver is up to the driver writer. ControllerName - A pointer to the Unicode string to return. This Unicode string is the name of the controller specified by ControllerHandle and ChildHandle in the language specified by Language from the point of view of the driver specified by This. Returns: EFI_SUCCESS - The Unicode string for the user readable name in the language specified by Language for the driver specified by This was returned in DriverName. EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE. EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE. EFI_INVALID_PARAMETER - Language is NULL. EFI_INVALID_PARAMETER - ControllerName is NULL. EFI_UNSUPPORTED - The driver specified by This is not currently managing the controller specified by ControllerHandle and ChildHandle. EFI_UNSUPPORTED - The driver specified by This does not support the language specified by Language. --*/ { EFI_STATUS Status; EFI_BLOCK_IO_PROTOCOL *BlockIo; IDE_BLK_IO_DEV *IdeBlkIoDevice; // // Make sure this driver is currently managing ControllHandle // Status = EfiLibTestManagedDevice ( ControllerHandle, gIdeControllerDriverBinding.DriverBindingHandle, &gEfiPciIoProtocolGuid ); if (EFI_ERROR (Status)) { return Status; } if (ChildHandle == NULL) { return EfiLibLookupUnicodeString ( Language, gIdeControllerName.SupportedLanguages, mIdeControllerControllerNameTable, ControllerName ); } Status = EfiLibTestChildHandle ( ControllerHandle, ChildHandle, &gEfiPciIoProtocolGuid ); if (EFI_ERROR (Status)) { return Status; } // // Get the child context // Status = gBS->OpenProtocol ( ChildHandle, &gEfiBlockIoProtocolGuid, (VOID **) &BlockIo, gIdeControllerDriverBinding.DriverBindingHandle, ChildHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (BlockIo); return EfiLibLookupUnicodeString ( Language, gIdeControllerName.SupportedLanguages, IdeBlkIoDevice->ControllerNameTable, ControllerName ); }
/** Retrieves a Unicode string that is the user readable name of the controller that is being managed by a driver. This function retrieves the user readable name of the controller specified by ControllerHandle and ChildHandle in the form of a Unicode string. If the driver specified by This has a user readable name in the language specified by Language, then a pointer to the controller name is returned in ControllerName, and EFI_SUCCESS is returned. If the driver specified by This is not currently managing the controller specified by ControllerHandle and ChildHandle, then EFI_UNSUPPORTED is returned. If the driver specified by This does not support the language specified by Language, then EFI_UNSUPPORTED is returned. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or EFI_COMPONENT_NAME_PROTOCOL instance. @param ControllerHandle[in] The handle of a controller that the driver specified by This is managing. This handle specifies the controller whose name is to be returned. @param ChildHandle[in] The handle of the child controller to retrieve the name of. This is an optional parameter that may be NULL. It will be NULL for device drivers. It will also be NULL for a bus drivers that wish to retrieve the name of the bus controller. It will not be NULL for a bus driver that wishes to retrieve the name of a child controller. @param Language[in] A pointer to a Null-terminated ASCII string array indicating the language. This is the language of the driver name that the caller is requesting, and it must match one of the languages specified in SupportedLanguages. The number of languages supported by a driver is up to the driver writer. Language is specified in RFC 4646 or ISO 639-2 language code format. @param ControllerName[out] A pointer to the Unicode string to return. This Unicode string is the name of the controller specified by ControllerHandle and ChildHandle in the language specified by Language from the point of view of the driver specified by This. @retval EFI_SUCCESS The Unicode string for the user readable name in the language specified by Language for the driver specified by This was returned in DriverName. @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE. @retval EFI_INVALID_PARAMETER Language is NULL. @retval EFI_INVALID_PARAMETER ControllerName is NULL. @retval EFI_UNSUPPORTED The driver specified by This is not currently managing the controller specified by ControllerHandle and ChildHandle. @retval EFI_UNSUPPORTED The driver specified by This does not support the language specified by Language. **/ EFI_STATUS EFIAPI IDEBusComponentNameGetControllerName ( IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName ) { EFI_STATUS Status; EFI_BLOCK_IO_PROTOCOL *BlockIo; IDE_BLK_IO_DEV *IdeBlkIoDevice; // // Make sure this driver is currently managing ControllHandle // Status = EfiTestManagedDevice ( ControllerHandle, gIDEBusDriverBinding.DriverBindingHandle, &gEfiIdeControllerInitProtocolGuid ); if (EFI_ERROR (Status)) { return Status; } if (ChildHandle == NULL) { return LookupUnicodeString2 ( Language, This->SupportedLanguages, mIDEBusControllerNameTable, ControllerName, (BOOLEAN)(This == &gIDEBusComponentName) ); } Status = EfiTestChildHandle ( ControllerHandle, ChildHandle, &gEfiPciIoProtocolGuid ); if (EFI_ERROR (Status)) { return Status; } // // Get the child context // Status = gBS->OpenProtocol ( ChildHandle, &gEfiBlockIoProtocolGuid, (VOID **) &BlockIo, gIDEBusDriverBinding.DriverBindingHandle, ChildHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (BlockIo); return LookupUnicodeString2 ( Language, This->SupportedLanguages, IdeBlkIoDevice->ControllerNameTable, ControllerName, (BOOLEAN)(This == &gIDEBusComponentName) ); }
/** Runs diagnostics on a controller. @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOLinstance. @param ControllerHandle The handle of the controller to run diagnostics on. @param ChildHandle The handle of the child controller to run diagnostics on This is an optional parameter that may be NULL. It will be NULL for device drivers. It will also be NULL for a bus drivers that wish to run diagnostics on the bus controller. It will not be NULL for a bus driver that wishes to run diagnostics on one of its child controllers. @param DiagnosticType Indicates type of diagnostics to perform on the controller specified by ControllerHandle and ChildHandle. @param Language A pointer to a three character ISO 639-2 language identifier. This is the language in which the optional error message should be returned in Buffer, and it must match one of the languages specified in SupportedLanguages. The number of languages supported by a driver is up to the driver writer. @param ErrorType A GUID that defines the format of the data returned in Buffer. @param BufferSize The size, in bytes, of the data returned in Buffer. @param Buffer A buffer that contains a Null-terminated Unicode string plus some additional data whose format is defined by ErrorType. Buffer is allocated by this function with AllocatePool(), and it is the caller's responsibility to free it with a call to FreePool(). @retval EFI_SUCCESS The controller specified by ControllerHandle and ChildHandle passed the diagnostic. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE. @retval EFI_INVALID_PARAMETER Language is NULL. @retval EFI_INVALID_PARAMETER ErrorType is NULL. @retval EFI_INVALID_PARAMETER BufferType is NULL. @retval EFI_INVALID_PARAMETER Buffer is NULL. @retval EFI_UNSUPPORTED The driver specified by This does not support running diagnostics for the controller specified by ControllerHandle and ChildHandle. @retval EFI_UNSUPPORTED The driver specified by This does not support the type of diagnostic specified by DiagnosticType. @retval EFI_UNSUPPORTED The driver specified by This does not support the language specified by Language. @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete the diagnostics. @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return the status information in ErrorType, BufferSize,and Buffer. @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and ChildHandle did not pass the diagnostic. **/ EFI_STATUS EFIAPI IDEBusDriverDiagnosticsRunDiagnostics ( IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType, IN CHAR8 *Language, OUT EFI_GUID **ErrorType, OUT UINTN *BufferSize, OUT CHAR16 **Buffer ) { EFI_STATUS Status; EFI_PCI_IO_PROTOCOL *PciIo; EFI_BLOCK_IO_PROTOCOL *BlkIo; IDE_BLK_IO_DEV *IdeBlkIoDevice; UINT32 VendorDeviceId; VOID *BlockBuffer; CHAR8 *SupportedLanguages; BOOLEAN Iso639Language; BOOLEAN Found; UINTN Index; if (Language == NULL || ErrorType == NULL || Buffer == NULL || ControllerHandle == NULL || BufferSize == NULL) { return EFI_INVALID_PARAMETER; } SupportedLanguages = This->SupportedLanguages; Iso639Language = (BOOLEAN)(This == &gIDEBusDriverDiagnostics); // // Make sure Language is in the set of Supported Languages // Found = FALSE; while (*SupportedLanguages != 0) { if (Iso639Language) { if (CompareMem (Language, SupportedLanguages, 3) == 0) { Found = TRUE; break; } SupportedLanguages += 3; } else { for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++); if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) { Found = TRUE; break; } SupportedLanguages += Index; for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++); } } // // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED // if (!Found) { return EFI_UNSUPPORTED; } *ErrorType = NULL; *BufferSize = 0; if (ChildHandle == NULL) { Status = gBS->OpenProtocol ( ControllerHandle, &gEfiCallerIdGuid, NULL, gIDEBusDriverBinding.DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL ); if (EFI_ERROR (Status)) { return Status; } Status = gBS->OpenProtocol ( ControllerHandle, &gEfiPciIoProtocolGuid, (VOID **) &PciIo, gIDEBusDriverBinding.DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } // // Use services of PCI I/O Protocol to test the PCI IDE/ATAPI Controller // The following test simply reads the Device ID and Vendor ID. // It should never fail. A real test would perform more advanced // diagnostics. // Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0, 1, &VendorDeviceId); if (EFI_ERROR (Status) || VendorDeviceId == 0xffffffff) { return EFI_DEVICE_ERROR; } return EFI_SUCCESS; } Status = gBS->OpenProtocol ( ChildHandle, &gEfiBlockIoProtocolGuid, (VOID **) &BlkIo, gIDEBusDriverBinding.DriverBindingHandle, ChildHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return Status; } IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo); // // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device // Status = gBS->AllocatePool ( EfiBootServicesData, IdeBlkIoDevice->BlkMedia.BlockSize, (VOID **) &BlockBuffer ); if (EFI_ERROR (Status)) { return Status; } Status = IdeBlkIoDevice->BlkIo.ReadBlocks ( &IdeBlkIoDevice->BlkIo, IdeBlkIoDevice->BlkMedia.MediaId, 0, IdeBlkIoDevice->BlkMedia.BlockSize, BlockBuffer ); if (EFI_ERROR (Status)) { *ErrorType = &gEfiCallerIdGuid; *BufferSize = sizeof (IDE_BUS_DIAGNOSTIC_ERROR); Status = gBS->AllocatePool ( EfiBootServicesData, (UINTN) (*BufferSize), (VOID **) Buffer ); if (EFI_ERROR (Status)) { return Status; } CopyMem (*Buffer, IDE_BUS_DIAGNOSTIC_ERROR, *BufferSize); Status = EFI_DEVICE_ERROR; } gBS->FreePool (BlockBuffer); return Status; }
/** Deregister an IDE device and free resources @param This Protocol instance pointer. @param Controller Ide device handle @param Handle Handle of device to deregister driver on @retval EFI_SUCCESS Deregiter a specific IDE device successfully **/ EFI_STATUS DeRegisterIdeDevice ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_HANDLE Handle ) { EFI_STATUS Status; EFI_BLOCK_IO_PROTOCOL *BlkIo; IDE_BLK_IO_DEV *IdeBlkIoDevice; EFI_PCI_IO_PROTOCOL *PciIo; UINTN Index; Status = gBS->OpenProtocol ( Handle, &gEfiBlockIoProtocolGuid, (VOID **) &BlkIo, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return Status; } IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo); // // Report Status code: Device disabled // REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, (EFI_IO_BUS_ATA_ATAPI | EFI_P_PC_DISABLE), IdeBlkIoDevice->DevicePath ); // // Close the child handle // Status = gBS->CloseProtocol ( Controller, &gEfiPciIoProtocolGuid, This->DriverBindingHandle, Handle ); Status = gBS->UninstallMultipleProtocolInterfaces ( Handle, &gEfiDevicePathProtocolGuid, IdeBlkIoDevice->DevicePath, &gEfiBlockIoProtocolGuid, &IdeBlkIoDevice->BlkIo, &gEfiDiskInfoProtocolGuid, &IdeBlkIoDevice->DiskInfo, NULL ); if (EFI_ERROR (Status)) { gBS->OpenProtocol ( Controller, &gEfiPciIoProtocolGuid, (VOID **) &PciIo, This->DriverBindingHandle, Handle, EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ); return Status; } // // Release allocated resources // Index = IdeBlkIoDevice->Channel * 2 + IdeBlkIoDevice->Device; if (Index < MAX_IDE_DEVICE) { IdeBlkIoDevice->IdeBusDriverPrivateData->HaveScannedDevice[Index] = FALSE; } ReleaseIdeResources (IdeBlkIoDevice); return EFI_SUCCESS; }