2 This driver module produces IDE_CONTROLLER_INIT protocol for Sata Controllers.
4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "SataController.h"
12 /// EFI_DRIVER_BINDING_PROTOCOL instance
14 EFI_DRIVER_BINDING_PROTOCOL gSataControllerDriverBinding
= {
15 SataControllerSupported
,
24 Read AHCI Operation register.
26 @param PciIo The PCI IO protocol instance.
27 @param Offset The operation register offset.
29 @return The register content read.
35 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
41 ASSERT (PciIo
!= NULL
);
58 Write AHCI Operation register.
60 @param PciIo The PCI IO protocol instance.
61 @param Offset The operation register offset.
62 @param Data The data used to write down.
68 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
73 ASSERT (PciIo
!= NULL
);
88 This function is used to calculate the best PIO mode supported by specific IDE device
90 @param IdentifyData The identify data of specific IDE device.
91 @param DisPioMode Disqualified PIO modes collection.
92 @param SelectedMode Available PIO modes collection.
94 @retval EFI_SUCCESS Best PIO modes are returned.
95 @retval EFI_UNSUPPORTED The device doesn't support PIO mode,
96 or all supported modes have been disqualified.
99 CalculateBestPioMode (
100 IN EFI_IDENTIFY_DATA
*IdentifyData
,
101 IN UINT16
*DisPioMode OPTIONAL
,
102 OUT UINT16
*SelectedMode
106 UINT16 AdvancedPioMode
;
109 UINT16 MinimumPioCycleTime
;
113 PioMode
= (UINT8
) (((ATA5_IDENTIFY_DATA
*) (&(IdentifyData
->AtaData
)))->pio_cycle_timing
>> 8);
116 // See whether Identify Data word 64 - 70 are valid
118 if ((IdentifyData
->AtaData
.field_validity
& 0x02) == 0x02) {
120 AdvancedPioMode
= IdentifyData
->AtaData
.advanced_pio_modes
;
121 DEBUG ((EFI_D_INFO
, "CalculateBestPioMode: AdvancedPioMode = %x\n", AdvancedPioMode
));
123 for (Index
= 0; Index
< 8; Index
++) {
124 if ((AdvancedPioMode
& 0x01) != 0) {
128 AdvancedPioMode
>>= 1;
132 // If Temp is modified, mean the advanced_pio_modes is not zero;
133 // if Temp is not modified, mean there is no advanced PIO mode supported,
134 // the best PIO Mode is the value in pio_cycle_timing.
137 AdvancedPioMode
= (UINT16
) (Temp
+ 3);
139 AdvancedPioMode
= PioMode
;
143 // Limit the PIO mode to at most PIO4.
145 PioMode
= (UINT16
) MIN (AdvancedPioMode
, 4);
147 MinimumPioCycleTime
= IdentifyData
->AtaData
.min_pio_cycle_time_with_flow_control
;
149 if (MinimumPioCycleTime
<= 120) {
150 PioMode
= (UINT16
) MIN (4, PioMode
);
151 } else if (MinimumPioCycleTime
<= 180) {
152 PioMode
= (UINT16
) MIN (3, PioMode
);
153 } else if (MinimumPioCycleTime
<= 240) {
154 PioMode
= (UINT16
) MIN (2, PioMode
);
160 // Degrade the PIO mode if the mode has been disqualified
162 if (DisPioMode
!= NULL
) {
163 if (*DisPioMode
< 2) {
164 return EFI_UNSUPPORTED
; // no mode below ATA_PIO_MODE_BELOW_2
167 if (PioMode
>= *DisPioMode
) {
168 PioMode
= (UINT16
) (*DisPioMode
- 1);
173 *SelectedMode
= 1; // ATA_PIO_MODE_BELOW_2;
175 *SelectedMode
= PioMode
; // ATA_PIO_MODE_2 to ATA_PIO_MODE_4;
180 // Identify Data word 64 - 70 are not valid
181 // Degrade the PIO mode if the mode has been disqualified
183 if (DisPioMode
!= NULL
) {
184 if (*DisPioMode
< 2) {
185 return EFI_UNSUPPORTED
; // no mode below ATA_PIO_MODE_BELOW_2
188 if (PioMode
== *DisPioMode
) {
194 *SelectedMode
= 1; // ATA_PIO_MODE_BELOW_2;
196 *SelectedMode
= 2; // ATA_PIO_MODE_2;
205 This function is used to calculate the best UDMA mode supported by specific IDE device
207 @param IdentifyData The identify data of specific IDE device.
208 @param DisUDmaMode Disqualified UDMA modes collection.
209 @param SelectedMode Available UDMA modes collection.
211 @retval EFI_SUCCESS Best UDMA modes are returned.
212 @retval EFI_UNSUPPORTED The device doesn't support UDMA mode,
213 or all supported modes have been disqualified.
216 CalculateBestUdmaMode (
217 IN EFI_IDENTIFY_DATA
*IdentifyData
,
218 IN UINT16
*DisUDmaMode OPTIONAL
,
219 OUT UINT16
*SelectedMode
223 UINT16 DeviceUDmaMode
;
228 // Check whether the WORD 88 (supported UltraDMA by drive) is valid
230 if ((IdentifyData
->AtaData
.field_validity
& 0x04) == 0x00) {
231 return EFI_UNSUPPORTED
;
234 DeviceUDmaMode
= IdentifyData
->AtaData
.ultra_dma_mode
;
235 DEBUG ((EFI_D_INFO
, "CalculateBestUdmaMode: DeviceUDmaMode = %x\n", DeviceUDmaMode
));
236 DeviceUDmaMode
&= 0x3f;
237 TempMode
= 0; // initialize it to UDMA-0
239 while ((DeviceUDmaMode
>>= 1) != 0) {
244 // Degrade the UDMA mode if the mode has been disqualified
246 if (DisUDmaMode
!= NULL
) {
247 if (*DisUDmaMode
== 0) {
249 return EFI_UNSUPPORTED
; // no mode below ATA_UDMA_MODE_0
252 if (TempMode
>= *DisUDmaMode
) {
253 TempMode
= (UINT16
) (*DisUDmaMode
- 1);
258 // Possible returned mode is between ATA_UDMA_MODE_0 and ATA_UDMA_MODE_5
260 *SelectedMode
= TempMode
;
266 The Entry Point of module. It follows the standard UEFI driver model.
268 @param[in] ImageHandle The firmware allocated handle for the EFI image.
269 @param[in] SystemTable A pointer to the EFI System Table.
271 @retval EFI_SUCCESS The entry point is executed successfully.
272 @retval other Some error occurs when executing this entry point.
277 InitializeSataControllerDriver (
278 IN EFI_HANDLE ImageHandle
,
279 IN EFI_SYSTEM_TABLE
*SystemTable
285 // Install driver model protocol(s).
287 Status
= EfiLibInstallDriverBindingComponentName2 (
290 &gSataControllerDriverBinding
,
292 &gSataControllerComponentName
,
293 &gSataControllerComponentName2
295 ASSERT_EFI_ERROR (Status
);
301 Supported function of Driver Binding protocol for this driver.
302 Test to see if this driver supports ControllerHandle.
304 @param This Protocol instance pointer.
305 @param Controller Handle of device to test.
306 @param RemainingDevicePath A pointer to the device path.
307 it should be ignored by device driver.
309 @retval EFI_SUCCESS This driver supports this device.
310 @retval EFI_ALREADY_STARTED This driver is already running on this device.
311 @retval other This driver does not support this device.
316 SataControllerSupported (
317 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
318 IN EFI_HANDLE Controller
,
319 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
323 EFI_PCI_IO_PROTOCOL
*PciIo
;
327 // Attempt to open PCI I/O Protocol
329 Status
= gBS
->OpenProtocol (
331 &gEfiPciIoProtocolGuid
,
333 This
->DriverBindingHandle
,
335 EFI_OPEN_PROTOCOL_GET_PROTOCOL
337 if (EFI_ERROR (Status
)) {
342 // Now further check the PCI header: Base Class (offset 0x0B) and
343 // Sub Class (offset 0x0A). This controller should be an SATA controller
345 Status
= PciIo
->Pci
.Read (
348 PCI_CLASSCODE_OFFSET
,
349 sizeof (PciData
.Hdr
.ClassCode
),
350 PciData
.Hdr
.ClassCode
352 if (EFI_ERROR (Status
)) {
353 return EFI_UNSUPPORTED
;
356 if (IS_PCI_IDE (&PciData
) || IS_PCI_SATADPA (&PciData
)) {
360 return EFI_UNSUPPORTED
;
364 This routine is called right after the .Supported() called and
365 Start this driver on ControllerHandle.
367 @param This Protocol instance pointer.
368 @param Controller Handle of device to bind driver to.
369 @param RemainingDevicePath A pointer to the device path.
370 it should be ignored by device driver.
372 @retval EFI_SUCCESS This driver is added to this device.
373 @retval EFI_ALREADY_STARTED This driver is already running on this device.
374 @retval other Some error occurs when binding this driver to this device.
379 SataControllerStart (
380 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
381 IN EFI_HANDLE Controller
,
382 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
387 EFI_PCI_IO_PROTOCOL
*PciIo
;
388 UINT64 OriginalPciAttributes
;
390 EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
;
392 UINTN ChannelDeviceCount
;
394 DEBUG ((EFI_D_INFO
, "SataControllerStart START\n"));
396 BailLogMask
= DEBUG_ERROR
;
397 SataPrivateData
= NULL
;
400 // Now test and open PCI I/O Protocol
402 Status
= gBS
->OpenProtocol (
404 &gEfiPciIoProtocolGuid
,
406 This
->DriverBindingHandle
,
408 EFI_OPEN_PROTOCOL_BY_DRIVER
410 if (EFI_ERROR (Status
)) {
411 if (Status
== EFI_ALREADY_STARTED
) {
413 // This is an expected condition for OpenProtocol() / BY_DRIVER, in a
414 // DriverBindingStart() member function; degrade the log mask to
417 BailLogMask
= DEBUG_INFO
;
423 // Save original PCI attributes, and enable IO space access, memory space
424 // access, and Bus Master (DMA).
426 Status
= PciIo
->Attributes (PciIo
, EfiPciIoAttributeOperationGet
, 0,
427 &OriginalPciAttributes
);
428 if (EFI_ERROR (Status
)) {
431 Status
= PciIo
->Attributes (PciIo
, EfiPciIoAttributeOperationEnable
,
432 EFI_PCI_DEVICE_ENABLE
, NULL
);
433 if (EFI_ERROR (Status
)) {
438 // Allocate Sata Private Data structure
440 SataPrivateData
= AllocateZeroPool (sizeof (EFI_SATA_CONTROLLER_PRIVATE_DATA
));
441 if (SataPrivateData
== NULL
) {
442 Status
= EFI_OUT_OF_RESOURCES
;
443 goto RestorePciAttributes
;
447 // Initialize Sata Private Data
449 SataPrivateData
->Signature
= SATA_CONTROLLER_SIGNATURE
;
450 SataPrivateData
->PciIo
= PciIo
;
451 SataPrivateData
->OriginalPciAttributes
= OriginalPciAttributes
;
452 SataPrivateData
->IdeInit
.GetChannelInfo
= IdeInitGetChannelInfo
;
453 SataPrivateData
->IdeInit
.NotifyPhase
= IdeInitNotifyPhase
;
454 SataPrivateData
->IdeInit
.SubmitData
= IdeInitSubmitData
;
455 SataPrivateData
->IdeInit
.DisqualifyMode
= IdeInitDisqualifyMode
;
456 SataPrivateData
->IdeInit
.CalculateMode
= IdeInitCalculateMode
;
457 SataPrivateData
->IdeInit
.SetTiming
= IdeInitSetTiming
;
458 SataPrivateData
->IdeInit
.EnumAll
= SATA_ENUMER_ALL
;
460 Status
= PciIo
->Pci
.Read (
463 PCI_CLASSCODE_OFFSET
,
464 sizeof (PciData
.Hdr
.ClassCode
),
465 PciData
.Hdr
.ClassCode
467 if (EFI_ERROR (Status
)) {
468 goto FreeSataPrivateData
;
471 if (IS_PCI_IDE (&PciData
)) {
472 SataPrivateData
->IdeInit
.ChannelCount
= IDE_MAX_CHANNEL
;
473 SataPrivateData
->DeviceCount
= IDE_MAX_DEVICES
;
474 } else if (IS_PCI_SATADPA (&PciData
)) {
476 // Read Host Capability Register(CAP) to get Number of Ports(NPS) and Supports Port Multiplier(SPM)
477 // NPS is 0's based value indicating the maximum number of ports supported by the HBA silicon.
478 // A maximum of 32 ports can be supported. A value of '0h', indicating one port, is the minimum requirement.
480 Data32
= AhciReadReg (PciIo
, R_AHCI_CAP
);
481 SataPrivateData
->IdeInit
.ChannelCount
= (UINT8
) ((Data32
& B_AHCI_CAP_NPS
) + 1);
482 SataPrivateData
->DeviceCount
= AHCI_MAX_DEVICES
;
483 if ((Data32
& B_AHCI_CAP_SPM
) == B_AHCI_CAP_SPM
) {
484 SataPrivateData
->DeviceCount
= AHCI_MULTI_MAX_DEVICES
;
488 ChannelDeviceCount
= (UINTN
) (SataPrivateData
->IdeInit
.ChannelCount
) * (UINTN
) (SataPrivateData
->DeviceCount
);
489 SataPrivateData
->DisqualifiedModes
= AllocateZeroPool ((sizeof (EFI_ATA_COLLECTIVE_MODE
)) * ChannelDeviceCount
);
490 if (SataPrivateData
->DisqualifiedModes
== NULL
) {
491 Status
= EFI_OUT_OF_RESOURCES
;
492 goto FreeSataPrivateData
;
495 SataPrivateData
->IdentifyData
= AllocateZeroPool ((sizeof (EFI_IDENTIFY_DATA
)) * ChannelDeviceCount
);
496 if (SataPrivateData
->IdentifyData
== NULL
) {
497 Status
= EFI_OUT_OF_RESOURCES
;
498 goto FreeDisqualifiedModes
;
501 SataPrivateData
->IdentifyValid
= AllocateZeroPool ((sizeof (BOOLEAN
)) * ChannelDeviceCount
);
502 if (SataPrivateData
->IdentifyValid
== NULL
) {
503 Status
= EFI_OUT_OF_RESOURCES
;
504 goto FreeIdentifyData
;
508 // Install IDE Controller Init Protocol to this instance
510 Status
= gBS
->InstallMultipleProtocolInterfaces (
512 &gEfiIdeControllerInitProtocolGuid
,
513 &(SataPrivateData
->IdeInit
),
517 if (EFI_ERROR (Status
)) {
518 goto FreeIdentifyValid
;
521 DEBUG ((EFI_D_INFO
, "SataControllerStart END status = %r\n", Status
));
525 FreePool (SataPrivateData
->IdentifyValid
);
528 FreePool (SataPrivateData
->IdentifyData
);
530 FreeDisqualifiedModes
:
531 FreePool (SataPrivateData
->DisqualifiedModes
);
534 FreePool (SataPrivateData
);
536 RestorePciAttributes
:
537 PciIo
->Attributes (PciIo
, EfiPciIoAttributeOperationSet
,
538 OriginalPciAttributes
, NULL
);
543 &gEfiPciIoProtocolGuid
,
544 This
->DriverBindingHandle
,
549 DEBUG ((BailLogMask
, "SataControllerStart error return status = %r\n",
555 Stop this driver on ControllerHandle.
557 @param This Protocol instance pointer.
558 @param Controller Handle of device to stop driver on.
559 @param NumberOfChildren Not used.
560 @param ChildHandleBuffer Not used.
562 @retval EFI_SUCCESS This driver is removed from this device.
563 @retval other Some error occurs when removing this driver from this device.
569 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
570 IN EFI_HANDLE Controller
,
571 IN UINTN NumberOfChildren
,
572 IN EFI_HANDLE
*ChildHandleBuffer
576 EFI_IDE_CONTROLLER_INIT_PROTOCOL
*IdeInit
;
577 EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
;
578 EFI_PCI_IO_PROTOCOL
*PciIo
;
579 UINT64 OriginalPciAttributes
;
582 // Open the produced protocol
584 Status
= gBS
->OpenProtocol (
586 &gEfiIdeControllerInitProtocolGuid
,
588 This
->DriverBindingHandle
,
590 EFI_OPEN_PROTOCOL_GET_PROTOCOL
592 if (EFI_ERROR (Status
)) {
593 return EFI_UNSUPPORTED
;
596 SataPrivateData
= SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (IdeInit
);
597 ASSERT (SataPrivateData
!= NULL
);
599 PciIo
= SataPrivateData
->PciIo
;
600 OriginalPciAttributes
= SataPrivateData
->OriginalPciAttributes
;
603 // Uninstall the IDE Controller Init Protocol from this instance
605 Status
= gBS
->UninstallMultipleProtocolInterfaces (
607 &gEfiIdeControllerInitProtocolGuid
,
608 &(SataPrivateData
->IdeInit
),
611 if (EFI_ERROR (Status
)) {
615 if (SataPrivateData
->DisqualifiedModes
!= NULL
) {
616 FreePool (SataPrivateData
->DisqualifiedModes
);
618 if (SataPrivateData
->IdentifyData
!= NULL
) {
619 FreePool (SataPrivateData
->IdentifyData
);
621 if (SataPrivateData
->IdentifyValid
!= NULL
) {
622 FreePool (SataPrivateData
->IdentifyValid
);
624 FreePool (SataPrivateData
);
627 // Restore original PCI attributes
631 EfiPciIoAttributeOperationSet
,
632 OriginalPciAttributes
,
637 // Close protocols opened by Sata Controller driver
639 return gBS
->CloseProtocol (
641 &gEfiPciIoProtocolGuid
,
642 This
->DriverBindingHandle
,
648 Calculate the flat array subscript of a (Channel, Device) pair.
650 @param[in] SataPrivateData The private data structure corresponding to the
651 SATA controller that attaches the device for
652 which the flat array subscript is being
655 @param[in] Channel The channel (ie. port) number on the SATA
656 controller that the device is attached to.
658 @param[in] Device The device number on the channel.
660 @return The flat array subscript suitable for indexing DisqualifiedModes,
661 IdentifyData, and IdentifyValid.
666 IN CONST EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
,
671 ASSERT (SataPrivateData
!= NULL
);
672 ASSERT (Channel
< SataPrivateData
->IdeInit
.ChannelCount
);
673 ASSERT (Device
< SataPrivateData
->DeviceCount
);
675 return Channel
* SataPrivateData
->DeviceCount
+ Device
;
679 // Interface functions of IDE_CONTROLLER_INIT protocol
682 Returns the information about the specified IDE channel.
684 This function can be used to obtain information about a particular IDE channel.
685 The driver entity uses this information during the enumeration process.
687 If Enabled is set to FALSE, the driver entity will not scan the channel. Note
688 that it will not prevent an operating system driver from scanning the channel.
690 For most of today's controllers, MaxDevices will either be 1 or 2. For SATA
691 controllers, this value will always be 1. SATA configurations can contain SATA
692 port multipliers. SATA port multipliers behave like SATA bridges and can support
693 up to 16 devices on the other side. If a SATA port out of the IDE controller
694 is connected to a port multiplier, MaxDevices will be set to the number of SATA
695 devices that the port multiplier supports. Because today's port multipliers
696 support up to fifteen SATA devices, this number can be as large as fifteen. The IDE
697 bus driver is required to scan for the presence of port multipliers behind an SATA
698 controller and enumerate up to MaxDevices number of devices behind the port
701 In this context, the devices behind a port multiplier constitute a channel.
703 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
704 @param[in] Channel Zero-based channel number.
705 @param[out] Enabled TRUE if this channel is enabled. Disabled channels
706 are not scanned to see if any devices are present.
707 @param[out] MaxDevices The maximum number of IDE devices that the bus driver
708 can expect on this channel. For the ATA/ATAPI
709 specification, version 6, this number will either be
710 one or two. For Serial ATA (SATA) configurations with a
711 port multiplier, this number can be as large as fifteen.
713 @retval EFI_SUCCESS Information was returned without any errors.
714 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
719 IdeInitGetChannelInfo (
720 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
722 OUT BOOLEAN
*Enabled
,
723 OUT UINT8
*MaxDevices
726 EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
;
727 SataPrivateData
= SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This
);
728 ASSERT (SataPrivateData
!= NULL
);
730 if (Channel
< This
->ChannelCount
) {
732 *MaxDevices
= SataPrivateData
->DeviceCount
;
737 return EFI_INVALID_PARAMETER
;
741 The notifications from the driver entity that it is about to enter a certain
742 phase of the IDE channel enumeration process.
744 This function can be used to notify the IDE controller driver to perform
745 specific actions, including any chipset-specific initialization, so that the
746 chipset is ready to enter the next phase. Seven notification points are defined
749 More synchronization points may be added as required in the future.
751 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
752 @param[in] Phase The phase during enumeration.
753 @param[in] Channel Zero-based channel number.
755 @retval EFI_SUCCESS The notification was accepted without any errors.
756 @retval EFI_UNSUPPORTED Phase is not supported.
757 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
758 @retval EFI_NOT_READY This phase cannot be entered at this time; for
759 example, an attempt was made to enter a Phase
760 without having entered one or more previous
767 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
768 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase
,
776 Submits the device information to the IDE controller driver.
778 This function is used by the driver entity to pass detailed information about
779 a particular device to the IDE controller driver. The driver entity obtains
780 this information by issuing an ATA or ATAPI IDENTIFY_DEVICE command. IdentifyData
781 is the pointer to the response data buffer. The IdentifyData buffer is owned
782 by the driver entity, and the IDE controller driver must make a local copy
783 of the entire buffer or parts of the buffer as needed. The original IdentifyData
784 buffer pointer may not be valid when
786 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() or
787 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() is called at a later point.
789 The IDE controller driver may consult various fields of EFI_IDENTIFY_DATA to
790 compute the optimum mode for the device. These fields are not limited to the
791 timing information. For example, an implementation of the IDE controller driver
792 may examine the vendor and type/mode field to match known bad drives.
794 The driver entity may submit drive information in any order, as long as it
795 submits information for all the devices belonging to the enumeration group
796 before EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() is called for any device
797 in that enumeration group. If a device is absent, EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
798 should be called with IdentifyData set to NULL. The IDE controller driver may
799 not have any other mechanism to know whether a device is present or not. Therefore,
800 setting IdentifyData to NULL does not constitute an error condition.
801 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() can be called only once for a
802 given (Channel, Device) pair.
804 @param[in] This A pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
805 @param[in] Channel Zero-based channel number.
806 @param[in] Device Zero-based device number on the Channel.
807 @param[in] IdentifyData The device's response to the ATA IDENTIFY_DEVICE command.
809 @retval EFI_SUCCESS The information was accepted without any errors.
810 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
811 @retval EFI_INVALID_PARAMETER Device is invalid.
817 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
820 IN EFI_IDENTIFY_DATA
*IdentifyData
823 EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
;
826 SataPrivateData
= SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This
);
827 ASSERT (SataPrivateData
!= NULL
);
829 if ((Channel
>= This
->ChannelCount
) || (Device
>= SataPrivateData
->DeviceCount
)) {
830 return EFI_INVALID_PARAMETER
;
833 DeviceIndex
= FlatDeviceIndex (SataPrivateData
, Channel
, Device
);
836 // Make a local copy of device's IdentifyData and mark the valid flag
838 if (IdentifyData
!= NULL
) {
840 &(SataPrivateData
->IdentifyData
[DeviceIndex
]),
842 sizeof (EFI_IDENTIFY_DATA
)
845 SataPrivateData
->IdentifyValid
[DeviceIndex
] = TRUE
;
847 SataPrivateData
->IdentifyValid
[DeviceIndex
] = FALSE
;
854 Disqualifies specific modes for an IDE device.
856 This function allows the driver entity or other drivers (such as platform
857 drivers) to reject certain timing modes and request the IDE controller driver
858 to recalculate modes. This function allows the driver entity and the IDE
859 controller driver to negotiate the timings on a per-device basis. This function
860 is useful in the case of drives that lie about their capabilities. An example
861 is when the IDE device fails to accept the timing modes that are calculated
862 by the IDE controller driver based on the response to the Identify Drive command.
864 If the driver entity does not want to limit the ATA timing modes and leave that
865 decision to the IDE controller driver, it can either not call this function for
866 the given device or call this function and set the Valid flag to FALSE for all
867 modes that are listed in EFI_ATA_COLLECTIVE_MODE.
869 The driver entity may disqualify modes for a device in any order and any number
872 This function can be called multiple times to invalidate multiple modes of the
873 same type (e.g., Programmed Input/Output [PIO] modes 3 and 4). See the ATA/ATAPI
874 specification for more information on PIO modes.
876 For Serial ATA (SATA) controllers, this member function can be used to disqualify
877 a higher transfer rate mode on a given channel. For example, a platform driver
878 may inform the IDE controller driver to not use second-generation (Gen2) speeds
879 for a certain SATA drive.
881 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
882 @param[in] Channel The zero-based channel number.
883 @param[in] Device The zero-based device number on the Channel.
884 @param[in] BadModes The modes that the device does not support and that
885 should be disqualified.
887 @retval EFI_SUCCESS The modes were accepted without any errors.
888 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
889 @retval EFI_INVALID_PARAMETER Device is invalid.
890 @retval EFI_INVALID_PARAMETER IdentifyData is NULL.
895 IdeInitDisqualifyMode (
896 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
899 IN EFI_ATA_COLLECTIVE_MODE
*BadModes
902 EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
;
905 SataPrivateData
= SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This
);
906 ASSERT (SataPrivateData
!= NULL
);
908 if ((Channel
>= This
->ChannelCount
) || (BadModes
== NULL
) || (Device
>= SataPrivateData
->DeviceCount
)) {
909 return EFI_INVALID_PARAMETER
;
912 DeviceIndex
= FlatDeviceIndex (SataPrivateData
, Channel
, Device
);
915 // Record the disqualified modes per channel per device. From ATA/ATAPI spec,
916 // if a mode is not supported, the modes higher than it is also not supported.
919 &(SataPrivateData
->DisqualifiedModes
[DeviceIndex
]),
921 sizeof (EFI_ATA_COLLECTIVE_MODE
)
928 Returns the information about the optimum modes for the specified IDE device.
930 This function is used by the driver entity to obtain the optimum ATA modes for
931 a specific device. The IDE controller driver takes into account the following
932 while calculating the mode:
933 - The IdentifyData inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
934 - The BadModes inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode()
936 The driver entity is required to call EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
937 for all the devices that belong to an enumeration group before calling
938 EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() for any device in the same group.
940 The IDE controller driver will use controller- and possibly platform-specific
941 algorithms to arrive at SupportedModes. The IDE controller may base its
942 decision on user preferences and other considerations as well. This function
943 may be called multiple times because the driver entity may renegotiate the mode
944 with the IDE controller driver using EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode().
946 The driver entity may collect timing information for various devices in any
947 order. The driver entity is responsible for making sure that all the dependencies
948 are satisfied. For example, the SupportedModes information for device A that
949 was previously returned may become stale after a call to
950 EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() for device B.
952 The buffer SupportedModes is allocated by the callee because the caller does
953 not necessarily know the size of the buffer. The type EFI_ATA_COLLECTIVE_MODE
954 is defined in a way that allows for future extensibility and can be of variable
955 length. This memory pool should be deallocated by the caller when it is no
958 The IDE controller driver for a Serial ATA (SATA) controller can use this
959 member function to force a lower speed (first-generation [Gen1] speeds on a
960 second-generation [Gen2]-capable hardware). The IDE controller driver can
961 also allow the driver entity to stay with the speed that has been negotiated
962 by the physical layer.
964 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
965 @param[in] Channel A zero-based channel number.
966 @param[in] Device A zero-based device number on the Channel.
967 @param[out] SupportedModes The optimum modes for the device.
969 @retval EFI_SUCCESS SupportedModes was returned.
970 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
971 @retval EFI_INVALID_PARAMETER Device is invalid.
972 @retval EFI_INVALID_PARAMETER SupportedModes is NULL.
973 @retval EFI_NOT_READY Modes cannot be calculated due to a lack of
974 data. This error may happen if
975 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
976 and EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyData()
977 were not called for at least one drive in the
978 same enumeration group.
983 IdeInitCalculateMode (
984 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
987 OUT EFI_ATA_COLLECTIVE_MODE
**SupportedModes
990 EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
;
991 EFI_IDENTIFY_DATA
*IdentifyData
;
992 BOOLEAN IdentifyValid
;
993 EFI_ATA_COLLECTIVE_MODE
*DisqualifiedModes
;
998 SataPrivateData
= SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This
);
999 ASSERT (SataPrivateData
!= NULL
);
1001 if ((Channel
>= This
->ChannelCount
) || (SupportedModes
== NULL
) || (Device
>= SataPrivateData
->DeviceCount
)) {
1002 return EFI_INVALID_PARAMETER
;
1005 *SupportedModes
= AllocateZeroPool (sizeof (EFI_ATA_COLLECTIVE_MODE
));
1006 if (*SupportedModes
== NULL
) {
1007 ASSERT (*SupportedModes
!= NULL
);
1008 return EFI_OUT_OF_RESOURCES
;
1011 DeviceIndex
= FlatDeviceIndex (SataPrivateData
, Channel
, Device
);
1013 IdentifyData
= &(SataPrivateData
->IdentifyData
[DeviceIndex
]);
1014 IdentifyValid
= SataPrivateData
->IdentifyValid
[DeviceIndex
];
1015 DisqualifiedModes
= &(SataPrivateData
->DisqualifiedModes
[DeviceIndex
]);
1018 // Make sure we've got the valid identify data of the device from SubmitData()
1020 if (!IdentifyValid
) {
1021 FreePool (*SupportedModes
);
1022 return EFI_NOT_READY
;
1025 Status
= CalculateBestPioMode (
1027 (DisqualifiedModes
->PioMode
.Valid
? ((UINT16
*) &(DisqualifiedModes
->PioMode
.Mode
)) : NULL
),
1030 if (!EFI_ERROR (Status
)) {
1031 (*SupportedModes
)->PioMode
.Valid
= TRUE
;
1032 (*SupportedModes
)->PioMode
.Mode
= SelectedMode
;
1035 (*SupportedModes
)->PioMode
.Valid
= FALSE
;
1037 DEBUG ((EFI_D_INFO
, "IdeInitCalculateMode: PioMode = %x\n", (*SupportedModes
)->PioMode
.Mode
));
1039 Status
= CalculateBestUdmaMode (
1041 (DisqualifiedModes
->UdmaMode
.Valid
? ((UINT16
*) &(DisqualifiedModes
->UdmaMode
.Mode
)) : NULL
),
1045 if (!EFI_ERROR (Status
)) {
1046 (*SupportedModes
)->UdmaMode
.Valid
= TRUE
;
1047 (*SupportedModes
)->UdmaMode
.Mode
= SelectedMode
;
1050 (*SupportedModes
)->UdmaMode
.Valid
= FALSE
;
1052 DEBUG ((EFI_D_INFO
, "IdeInitCalculateMode: UdmaMode = %x\n", (*SupportedModes
)->UdmaMode
.Mode
));
1055 // The modes other than PIO and UDMA are not supported
1061 Commands the IDE controller driver to program the IDE controller hardware
1062 so that the specified device can operate at the specified mode.
1064 This function is used by the driver entity to instruct the IDE controller
1065 driver to program the IDE controller hardware to the specified modes. This
1066 function can be called only once for a particular device. For a Serial ATA
1067 (SATA) Advanced Host Controller Interface (AHCI) controller, no controller-
1068 specific programming may be required.
1070 @param[in] This Pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
1071 @param[in] Channel Zero-based channel number.
1072 @param[in] Device Zero-based device number on the Channel.
1073 @param[in] Modes The modes to set.
1075 @retval EFI_SUCCESS The command was accepted without any errors.
1076 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
1077 @retval EFI_INVALID_PARAMETER Device is invalid.
1078 @retval EFI_NOT_READY Modes cannot be set at this time due to lack of data.
1079 @retval EFI_DEVICE_ERROR Modes cannot be set due to hardware failure.
1080 The driver entity should not use this device.
1086 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
1089 IN EFI_ATA_COLLECTIVE_MODE
*Modes