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) {
119 AdvancedPioMode
= IdentifyData
->AtaData
.advanced_pio_modes
;
120 DEBUG ((DEBUG_INFO
, "CalculateBestPioMode: AdvancedPioMode = %x\n", AdvancedPioMode
));
122 for (Index
= 0; Index
< 8; Index
++) {
123 if ((AdvancedPioMode
& 0x01) != 0) {
127 AdvancedPioMode
>>= 1;
131 // If Temp is modified, mean the advanced_pio_modes is not zero;
132 // if Temp is not modified, mean there is no advanced PIO mode supported,
133 // the best PIO Mode is the value in pio_cycle_timing.
136 AdvancedPioMode
= (UINT16
)(Temp
+ 3);
138 AdvancedPioMode
= PioMode
;
142 // Limit the PIO mode to at most PIO4.
144 PioMode
= (UINT16
)MIN (AdvancedPioMode
, 4);
146 MinimumPioCycleTime
= IdentifyData
->AtaData
.min_pio_cycle_time_with_flow_control
;
148 if (MinimumPioCycleTime
<= 120) {
149 PioMode
= (UINT16
)MIN (4, PioMode
);
150 } else if (MinimumPioCycleTime
<= 180) {
151 PioMode
= (UINT16
)MIN (3, PioMode
);
152 } else if (MinimumPioCycleTime
<= 240) {
153 PioMode
= (UINT16
)MIN (2, PioMode
);
159 // Degrade the PIO mode if the mode has been disqualified
161 if (DisPioMode
!= NULL
) {
162 if (*DisPioMode
< 2) {
163 return EFI_UNSUPPORTED
; // no mode below ATA_PIO_MODE_BELOW_2
166 if (PioMode
>= *DisPioMode
) {
167 PioMode
= (UINT16
)(*DisPioMode
- 1);
172 *SelectedMode
= 1; // ATA_PIO_MODE_BELOW_2;
174 *SelectedMode
= PioMode
; // ATA_PIO_MODE_2 to ATA_PIO_MODE_4;
178 // Identify Data word 64 - 70 are not valid
179 // Degrade the PIO mode if the mode has been disqualified
181 if (DisPioMode
!= NULL
) {
182 if (*DisPioMode
< 2) {
183 return EFI_UNSUPPORTED
; // no mode below ATA_PIO_MODE_BELOW_2
186 if (PioMode
== *DisPioMode
) {
192 *SelectedMode
= 1; // ATA_PIO_MODE_BELOW_2;
194 *SelectedMode
= 2; // ATA_PIO_MODE_2;
202 This function is used to calculate the best UDMA mode supported by specific IDE device
204 @param IdentifyData The identify data of specific IDE device.
205 @param DisUDmaMode Disqualified UDMA modes collection.
206 @param SelectedMode Available UDMA modes collection.
208 @retval EFI_SUCCESS Best UDMA modes are returned.
209 @retval EFI_UNSUPPORTED The device doesn't support UDMA mode,
210 or all supported modes have been disqualified.
213 CalculateBestUdmaMode (
214 IN EFI_IDENTIFY_DATA
*IdentifyData
,
215 IN UINT16
*DisUDmaMode OPTIONAL
,
216 OUT UINT16
*SelectedMode
220 UINT16 DeviceUDmaMode
;
225 // Check whether the WORD 88 (supported UltraDMA by drive) is valid
227 if ((IdentifyData
->AtaData
.field_validity
& 0x04) == 0x00) {
228 return EFI_UNSUPPORTED
;
231 DeviceUDmaMode
= IdentifyData
->AtaData
.ultra_dma_mode
;
232 DEBUG ((DEBUG_INFO
, "CalculateBestUdmaMode: DeviceUDmaMode = %x\n", DeviceUDmaMode
));
233 DeviceUDmaMode
&= 0x3f;
234 TempMode
= 0; // initialize it to UDMA-0
236 while ((DeviceUDmaMode
>>= 1) != 0) {
241 // Degrade the UDMA mode if the mode has been disqualified
243 if (DisUDmaMode
!= NULL
) {
244 if (*DisUDmaMode
== 0) {
246 return EFI_UNSUPPORTED
; // no mode below ATA_UDMA_MODE_0
249 if (TempMode
>= *DisUDmaMode
) {
250 TempMode
= (UINT16
)(*DisUDmaMode
- 1);
255 // Possible returned mode is between ATA_UDMA_MODE_0 and ATA_UDMA_MODE_5
257 *SelectedMode
= TempMode
;
263 The Entry Point of module. It follows the standard UEFI driver model.
265 @param[in] ImageHandle The firmware allocated handle for the EFI image.
266 @param[in] SystemTable A pointer to the EFI System Table.
268 @retval EFI_SUCCESS The entry point is executed successfully.
269 @retval other Some error occurs when executing this entry point.
274 InitializeSataControllerDriver (
275 IN EFI_HANDLE ImageHandle
,
276 IN EFI_SYSTEM_TABLE
*SystemTable
282 // Install driver model protocol(s).
284 Status
= EfiLibInstallDriverBindingComponentName2 (
287 &gSataControllerDriverBinding
,
289 &gSataControllerComponentName
,
290 &gSataControllerComponentName2
292 ASSERT_EFI_ERROR (Status
);
298 Supported function of Driver Binding protocol for this driver.
299 Test to see if this driver supports ControllerHandle.
301 @param This Protocol instance pointer.
302 @param Controller Handle of device to test.
303 @param RemainingDevicePath A pointer to the device path.
304 it should be ignored by device driver.
306 @retval EFI_SUCCESS This driver supports this device.
307 @retval EFI_ALREADY_STARTED This driver is already running on this device.
308 @retval other This driver does not support this device.
313 SataControllerSupported (
314 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
315 IN EFI_HANDLE Controller
,
316 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
320 EFI_PCI_IO_PROTOCOL
*PciIo
;
324 // Attempt to open PCI I/O Protocol
326 Status
= gBS
->OpenProtocol (
328 &gEfiPciIoProtocolGuid
,
330 This
->DriverBindingHandle
,
332 EFI_OPEN_PROTOCOL_GET_PROTOCOL
334 if (EFI_ERROR (Status
)) {
339 // Now further check the PCI header: Base Class (offset 0x0B) and
340 // Sub Class (offset 0x0A). This controller should be an SATA controller
342 Status
= PciIo
->Pci
.Read (
345 PCI_CLASSCODE_OFFSET
,
346 sizeof (PciData
.Hdr
.ClassCode
),
347 PciData
.Hdr
.ClassCode
349 if (EFI_ERROR (Status
)) {
350 return EFI_UNSUPPORTED
;
353 if (IS_PCI_IDE (&PciData
) || IS_PCI_SATADPA (&PciData
)) {
357 return EFI_UNSUPPORTED
;
361 This routine is called right after the .Supported() called and
362 Start this driver on ControllerHandle.
364 @param This Protocol instance pointer.
365 @param Controller Handle of device to bind driver to.
366 @param RemainingDevicePath A pointer to the device path.
367 it should be ignored by device driver.
369 @retval EFI_SUCCESS This driver is added to this device.
370 @retval EFI_ALREADY_STARTED This driver is already running on this device.
371 @retval other Some error occurs when binding this driver to this device.
376 SataControllerStart (
377 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
378 IN EFI_HANDLE Controller
,
379 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
384 EFI_PCI_IO_PROTOCOL
*PciIo
;
385 UINT64 OriginalPciAttributes
;
387 EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
;
389 UINTN ChannelDeviceCount
;
391 DEBUG ((DEBUG_INFO
, "SataControllerStart START\n"));
393 BailLogMask
= DEBUG_ERROR
;
394 SataPrivateData
= NULL
;
397 // Now test and open PCI I/O Protocol
399 Status
= gBS
->OpenProtocol (
401 &gEfiPciIoProtocolGuid
,
403 This
->DriverBindingHandle
,
405 EFI_OPEN_PROTOCOL_BY_DRIVER
407 if (EFI_ERROR (Status
)) {
408 if (Status
== EFI_ALREADY_STARTED
) {
410 // This is an expected condition for OpenProtocol() / BY_DRIVER, in a
411 // DriverBindingStart() member function; degrade the log mask to
414 BailLogMask
= DEBUG_INFO
;
421 // Save original PCI attributes, and enable IO space access, memory space
422 // access, and Bus Master (DMA).
424 Status
= PciIo
->Attributes (
426 EfiPciIoAttributeOperationGet
,
428 &OriginalPciAttributes
430 if (EFI_ERROR (Status
)) {
434 Status
= PciIo
->Attributes (
436 EfiPciIoAttributeOperationEnable
,
437 EFI_PCI_DEVICE_ENABLE
,
440 if (EFI_ERROR (Status
)) {
445 // Allocate Sata Private Data structure
447 SataPrivateData
= AllocateZeroPool (sizeof (EFI_SATA_CONTROLLER_PRIVATE_DATA
));
448 if (SataPrivateData
== NULL
) {
449 Status
= EFI_OUT_OF_RESOURCES
;
450 goto RestorePciAttributes
;
454 // Initialize Sata Private Data
456 SataPrivateData
->Signature
= SATA_CONTROLLER_SIGNATURE
;
457 SataPrivateData
->PciIo
= PciIo
;
458 SataPrivateData
->OriginalPciAttributes
= OriginalPciAttributes
;
459 SataPrivateData
->IdeInit
.GetChannelInfo
= IdeInitGetChannelInfo
;
460 SataPrivateData
->IdeInit
.NotifyPhase
= IdeInitNotifyPhase
;
461 SataPrivateData
->IdeInit
.SubmitData
= IdeInitSubmitData
;
462 SataPrivateData
->IdeInit
.DisqualifyMode
= IdeInitDisqualifyMode
;
463 SataPrivateData
->IdeInit
.CalculateMode
= IdeInitCalculateMode
;
464 SataPrivateData
->IdeInit
.SetTiming
= IdeInitSetTiming
;
465 SataPrivateData
->IdeInit
.EnumAll
= SATA_ENUMER_ALL
;
467 Status
= PciIo
->Pci
.Read (
470 PCI_CLASSCODE_OFFSET
,
471 sizeof (PciData
.Hdr
.ClassCode
),
472 PciData
.Hdr
.ClassCode
474 if (EFI_ERROR (Status
)) {
475 goto FreeSataPrivateData
;
478 if (IS_PCI_IDE (&PciData
)) {
479 SataPrivateData
->IdeInit
.ChannelCount
= IDE_MAX_CHANNEL
;
480 SataPrivateData
->DeviceCount
= IDE_MAX_DEVICES
;
481 } else if (IS_PCI_SATADPA (&PciData
)) {
483 // Read Host Capability Register(CAP) to get Number of Ports(NPS) and Supports Port Multiplier(SPM)
484 // NPS is 0's based value indicating the maximum number of ports supported by the HBA silicon.
485 // A maximum of 32 ports can be supported. A value of '0h', indicating one port, is the minimum requirement.
487 Data32
= AhciReadReg (PciIo
, R_AHCI_CAP
);
488 SataPrivateData
->IdeInit
.ChannelCount
= (UINT8
)((Data32
& B_AHCI_CAP_NPS
) + 1);
489 SataPrivateData
->DeviceCount
= AHCI_MAX_DEVICES
;
490 if ((Data32
& B_AHCI_CAP_SPM
) == B_AHCI_CAP_SPM
) {
491 SataPrivateData
->DeviceCount
= AHCI_MULTI_MAX_DEVICES
;
495 ChannelDeviceCount
= (UINTN
)(SataPrivateData
->IdeInit
.ChannelCount
) * (UINTN
)(SataPrivateData
->DeviceCount
);
496 SataPrivateData
->DisqualifiedModes
= AllocateZeroPool ((sizeof (EFI_ATA_COLLECTIVE_MODE
)) * ChannelDeviceCount
);
497 if (SataPrivateData
->DisqualifiedModes
== NULL
) {
498 Status
= EFI_OUT_OF_RESOURCES
;
499 goto FreeSataPrivateData
;
502 SataPrivateData
->IdentifyData
= AllocateZeroPool ((sizeof (EFI_IDENTIFY_DATA
)) * ChannelDeviceCount
);
503 if (SataPrivateData
->IdentifyData
== NULL
) {
504 Status
= EFI_OUT_OF_RESOURCES
;
505 goto FreeDisqualifiedModes
;
508 SataPrivateData
->IdentifyValid
= AllocateZeroPool ((sizeof (BOOLEAN
)) * ChannelDeviceCount
);
509 if (SataPrivateData
->IdentifyValid
== NULL
) {
510 Status
= EFI_OUT_OF_RESOURCES
;
511 goto FreeIdentifyData
;
515 // Install IDE Controller Init Protocol to this instance
517 Status
= gBS
->InstallMultipleProtocolInterfaces (
519 &gEfiIdeControllerInitProtocolGuid
,
520 &(SataPrivateData
->IdeInit
),
524 if (EFI_ERROR (Status
)) {
525 goto FreeIdentifyValid
;
528 DEBUG ((DEBUG_INFO
, "SataControllerStart END status = %r\n", Status
));
532 FreePool (SataPrivateData
->IdentifyValid
);
535 FreePool (SataPrivateData
->IdentifyData
);
537 FreeDisqualifiedModes
:
538 FreePool (SataPrivateData
->DisqualifiedModes
);
541 FreePool (SataPrivateData
);
543 RestorePciAttributes
:
546 EfiPciIoAttributeOperationSet
,
547 OriginalPciAttributes
,
554 &gEfiPciIoProtocolGuid
,
555 This
->DriverBindingHandle
,
562 "SataControllerStart error return status = %r\n",
569 Stop this driver on ControllerHandle.
571 @param This Protocol instance pointer.
572 @param Controller Handle of device to stop driver on.
573 @param NumberOfChildren Not used.
574 @param ChildHandleBuffer Not used.
576 @retval EFI_SUCCESS This driver is removed from this device.
577 @retval other Some error occurs when removing this driver from this device.
583 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
584 IN EFI_HANDLE Controller
,
585 IN UINTN NumberOfChildren
,
586 IN EFI_HANDLE
*ChildHandleBuffer
590 EFI_IDE_CONTROLLER_INIT_PROTOCOL
*IdeInit
;
591 EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
;
592 EFI_PCI_IO_PROTOCOL
*PciIo
;
593 UINT64 OriginalPciAttributes
;
596 // Open the produced protocol
598 Status
= gBS
->OpenProtocol (
600 &gEfiIdeControllerInitProtocolGuid
,
602 This
->DriverBindingHandle
,
604 EFI_OPEN_PROTOCOL_GET_PROTOCOL
606 if (EFI_ERROR (Status
)) {
607 return EFI_UNSUPPORTED
;
610 SataPrivateData
= SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (IdeInit
);
611 ASSERT (SataPrivateData
!= NULL
);
613 PciIo
= SataPrivateData
->PciIo
;
614 OriginalPciAttributes
= SataPrivateData
->OriginalPciAttributes
;
617 // Uninstall the IDE Controller Init Protocol from this instance
619 Status
= gBS
->UninstallMultipleProtocolInterfaces (
621 &gEfiIdeControllerInitProtocolGuid
,
622 &(SataPrivateData
->IdeInit
),
625 if (EFI_ERROR (Status
)) {
629 if (SataPrivateData
->DisqualifiedModes
!= NULL
) {
630 FreePool (SataPrivateData
->DisqualifiedModes
);
633 if (SataPrivateData
->IdentifyData
!= NULL
) {
634 FreePool (SataPrivateData
->IdentifyData
);
637 if (SataPrivateData
->IdentifyValid
!= NULL
) {
638 FreePool (SataPrivateData
->IdentifyValid
);
641 FreePool (SataPrivateData
);
644 // Restore original PCI attributes
648 EfiPciIoAttributeOperationSet
,
649 OriginalPciAttributes
,
654 // Close protocols opened by Sata Controller driver
656 return gBS
->CloseProtocol (
658 &gEfiPciIoProtocolGuid
,
659 This
->DriverBindingHandle
,
665 Calculate the flat array subscript of a (Channel, Device) pair.
667 @param[in] SataPrivateData The private data structure corresponding to the
668 SATA controller that attaches the device for
669 which the flat array subscript is being
672 @param[in] Channel The channel (ie. port) number on the SATA
673 controller that the device is attached to.
675 @param[in] Device The device number on the channel.
677 @return The flat array subscript suitable for indexing DisqualifiedModes,
678 IdentifyData, and IdentifyValid.
683 IN CONST EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
,
688 ASSERT (SataPrivateData
!= NULL
);
689 ASSERT (Channel
< SataPrivateData
->IdeInit
.ChannelCount
);
690 ASSERT (Device
< SataPrivateData
->DeviceCount
);
692 return Channel
* SataPrivateData
->DeviceCount
+ Device
;
696 // Interface functions of IDE_CONTROLLER_INIT protocol
700 Returns the information about the specified IDE channel.
702 This function can be used to obtain information about a particular IDE channel.
703 The driver entity uses this information during the enumeration process.
705 If Enabled is set to FALSE, the driver entity will not scan the channel. Note
706 that it will not prevent an operating system driver from scanning the channel.
708 For most of today's controllers, MaxDevices will either be 1 or 2. For SATA
709 controllers, this value will always be 1. SATA configurations can contain SATA
710 port multipliers. SATA port multipliers behave like SATA bridges and can support
711 up to 16 devices on the other side. If a SATA port out of the IDE controller
712 is connected to a port multiplier, MaxDevices will be set to the number of SATA
713 devices that the port multiplier supports. Because today's port multipliers
714 support up to fifteen SATA devices, this number can be as large as fifteen. The IDE
715 bus driver is required to scan for the presence of port multipliers behind an SATA
716 controller and enumerate up to MaxDevices number of devices behind the port
719 In this context, the devices behind a port multiplier constitute a channel.
721 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
722 @param[in] Channel Zero-based channel number.
723 @param[out] Enabled TRUE if this channel is enabled. Disabled channels
724 are not scanned to see if any devices are present.
725 @param[out] MaxDevices The maximum number of IDE devices that the bus driver
726 can expect on this channel. For the ATA/ATAPI
727 specification, version 6, this number will either be
728 one or two. For Serial ATA (SATA) configurations with a
729 port multiplier, this number can be as large as fifteen.
731 @retval EFI_SUCCESS Information was returned without any errors.
732 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
737 IdeInitGetChannelInfo (
738 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
740 OUT BOOLEAN
*Enabled
,
741 OUT UINT8
*MaxDevices
744 EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
;
746 SataPrivateData
= SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This
);
747 ASSERT (SataPrivateData
!= NULL
);
749 if (Channel
< This
->ChannelCount
) {
751 *MaxDevices
= SataPrivateData
->DeviceCount
;
756 return EFI_INVALID_PARAMETER
;
760 The notifications from the driver entity that it is about to enter a certain
761 phase of the IDE channel enumeration process.
763 This function can be used to notify the IDE controller driver to perform
764 specific actions, including any chipset-specific initialization, so that the
765 chipset is ready to enter the next phase. Seven notification points are defined
768 More synchronization points may be added as required in the future.
770 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
771 @param[in] Phase The phase during enumeration.
772 @param[in] Channel Zero-based channel number.
774 @retval EFI_SUCCESS The notification was accepted without any errors.
775 @retval EFI_UNSUPPORTED Phase is not supported.
776 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
777 @retval EFI_NOT_READY This phase cannot be entered at this time; for
778 example, an attempt was made to enter a Phase
779 without having entered one or more previous
786 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
787 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase
,
795 Submits the device information to the IDE controller driver.
797 This function is used by the driver entity to pass detailed information about
798 a particular device to the IDE controller driver. The driver entity obtains
799 this information by issuing an ATA or ATAPI IDENTIFY_DEVICE command. IdentifyData
800 is the pointer to the response data buffer. The IdentifyData buffer is owned
801 by the driver entity, and the IDE controller driver must make a local copy
802 of the entire buffer or parts of the buffer as needed. The original IdentifyData
803 buffer pointer may not be valid when
805 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() or
806 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() is called at a later point.
808 The IDE controller driver may consult various fields of EFI_IDENTIFY_DATA to
809 compute the optimum mode for the device. These fields are not limited to the
810 timing information. For example, an implementation of the IDE controller driver
811 may examine the vendor and type/mode field to match known bad drives.
813 The driver entity may submit drive information in any order, as long as it
814 submits information for all the devices belonging to the enumeration group
815 before EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() is called for any device
816 in that enumeration group. If a device is absent, EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
817 should be called with IdentifyData set to NULL. The IDE controller driver may
818 not have any other mechanism to know whether a device is present or not. Therefore,
819 setting IdentifyData to NULL does not constitute an error condition.
820 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() can be called only once for a
821 given (Channel, Device) pair.
823 @param[in] This A pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
824 @param[in] Channel Zero-based channel number.
825 @param[in] Device Zero-based device number on the Channel.
826 @param[in] IdentifyData The device's response to the ATA IDENTIFY_DEVICE command.
828 @retval EFI_SUCCESS The information was accepted without any errors.
829 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
830 @retval EFI_INVALID_PARAMETER Device is invalid.
836 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
839 IN EFI_IDENTIFY_DATA
*IdentifyData
842 EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
;
845 SataPrivateData
= SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This
);
846 ASSERT (SataPrivateData
!= NULL
);
848 if ((Channel
>= This
->ChannelCount
) || (Device
>= SataPrivateData
->DeviceCount
)) {
849 return EFI_INVALID_PARAMETER
;
852 DeviceIndex
= FlatDeviceIndex (SataPrivateData
, Channel
, Device
);
855 // Make a local copy of device's IdentifyData and mark the valid flag
857 if (IdentifyData
!= NULL
) {
859 &(SataPrivateData
->IdentifyData
[DeviceIndex
]),
861 sizeof (EFI_IDENTIFY_DATA
)
864 SataPrivateData
->IdentifyValid
[DeviceIndex
] = TRUE
;
866 SataPrivateData
->IdentifyValid
[DeviceIndex
] = FALSE
;
873 Disqualifies specific modes for an IDE device.
875 This function allows the driver entity or other drivers (such as platform
876 drivers) to reject certain timing modes and request the IDE controller driver
877 to recalculate modes. This function allows the driver entity and the IDE
878 controller driver to negotiate the timings on a per-device basis. This function
879 is useful in the case of drives that lie about their capabilities. An example
880 is when the IDE device fails to accept the timing modes that are calculated
881 by the IDE controller driver based on the response to the Identify Drive command.
883 If the driver entity does not want to limit the ATA timing modes and leave that
884 decision to the IDE controller driver, it can either not call this function for
885 the given device or call this function and set the Valid flag to FALSE for all
886 modes that are listed in EFI_ATA_COLLECTIVE_MODE.
888 The driver entity may disqualify modes for a device in any order and any number
891 This function can be called multiple times to invalidate multiple modes of the
892 same type (e.g., Programmed Input/Output [PIO] modes 3 and 4). See the ATA/ATAPI
893 specification for more information on PIO modes.
895 For Serial ATA (SATA) controllers, this member function can be used to disqualify
896 a higher transfer rate mode on a given channel. For example, a platform driver
897 may inform the IDE controller driver to not use second-generation (Gen2) speeds
898 for a certain SATA drive.
900 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
901 @param[in] Channel The zero-based channel number.
902 @param[in] Device The zero-based device number on the Channel.
903 @param[in] BadModes The modes that the device does not support and that
904 should be disqualified.
906 @retval EFI_SUCCESS The modes were accepted without any errors.
907 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
908 @retval EFI_INVALID_PARAMETER Device is invalid.
909 @retval EFI_INVALID_PARAMETER IdentifyData is NULL.
914 IdeInitDisqualifyMode (
915 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
918 IN EFI_ATA_COLLECTIVE_MODE
*BadModes
921 EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
;
924 SataPrivateData
= SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This
);
925 ASSERT (SataPrivateData
!= NULL
);
927 if ((Channel
>= This
->ChannelCount
) || (BadModes
== NULL
) || (Device
>= SataPrivateData
->DeviceCount
)) {
928 return EFI_INVALID_PARAMETER
;
931 DeviceIndex
= FlatDeviceIndex (SataPrivateData
, Channel
, Device
);
934 // Record the disqualified modes per channel per device. From ATA/ATAPI spec,
935 // if a mode is not supported, the modes higher than it is also not supported.
938 &(SataPrivateData
->DisqualifiedModes
[DeviceIndex
]),
940 sizeof (EFI_ATA_COLLECTIVE_MODE
)
947 Returns the information about the optimum modes for the specified IDE device.
949 This function is used by the driver entity to obtain the optimum ATA modes for
950 a specific device. The IDE controller driver takes into account the following
951 while calculating the mode:
952 - The IdentifyData inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
953 - The BadModes inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode()
955 The driver entity is required to call EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
956 for all the devices that belong to an enumeration group before calling
957 EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() for any device in the same group.
959 The IDE controller driver will use controller- and possibly platform-specific
960 algorithms to arrive at SupportedModes. The IDE controller may base its
961 decision on user preferences and other considerations as well. This function
962 may be called multiple times because the driver entity may renegotiate the mode
963 with the IDE controller driver using EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode().
965 The driver entity may collect timing information for various devices in any
966 order. The driver entity is responsible for making sure that all the dependencies
967 are satisfied. For example, the SupportedModes information for device A that
968 was previously returned may become stale after a call to
969 EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() for device B.
971 The buffer SupportedModes is allocated by the callee because the caller does
972 not necessarily know the size of the buffer. The type EFI_ATA_COLLECTIVE_MODE
973 is defined in a way that allows for future extensibility and can be of variable
974 length. This memory pool should be deallocated by the caller when it is no
977 The IDE controller driver for a Serial ATA (SATA) controller can use this
978 member function to force a lower speed (first-generation [Gen1] speeds on a
979 second-generation [Gen2]-capable hardware). The IDE controller driver can
980 also allow the driver entity to stay with the speed that has been negotiated
981 by the physical layer.
983 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
984 @param[in] Channel A zero-based channel number.
985 @param[in] Device A zero-based device number on the Channel.
986 @param[out] SupportedModes The optimum modes for the device.
988 @retval EFI_SUCCESS SupportedModes was returned.
989 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
990 @retval EFI_INVALID_PARAMETER Device is invalid.
991 @retval EFI_INVALID_PARAMETER SupportedModes is NULL.
992 @retval EFI_NOT_READY Modes cannot be calculated due to a lack of
993 data. This error may happen if
994 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
995 and EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyData()
996 were not called for at least one drive in the
997 same enumeration group.
1002 IdeInitCalculateMode (
1003 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
1006 OUT EFI_ATA_COLLECTIVE_MODE
**SupportedModes
1009 EFI_SATA_CONTROLLER_PRIVATE_DATA
*SataPrivateData
;
1010 EFI_IDENTIFY_DATA
*IdentifyData
;
1011 BOOLEAN IdentifyValid
;
1012 EFI_ATA_COLLECTIVE_MODE
*DisqualifiedModes
;
1013 UINT16 SelectedMode
;
1017 SataPrivateData
= SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This
);
1018 ASSERT (SataPrivateData
!= NULL
);
1020 if ((Channel
>= This
->ChannelCount
) || (SupportedModes
== NULL
) || (Device
>= SataPrivateData
->DeviceCount
)) {
1021 return EFI_INVALID_PARAMETER
;
1024 *SupportedModes
= AllocateZeroPool (sizeof (EFI_ATA_COLLECTIVE_MODE
));
1025 if (*SupportedModes
== NULL
) {
1026 ASSERT (*SupportedModes
!= NULL
);
1027 return EFI_OUT_OF_RESOURCES
;
1030 DeviceIndex
= FlatDeviceIndex (SataPrivateData
, Channel
, Device
);
1032 IdentifyData
= &(SataPrivateData
->IdentifyData
[DeviceIndex
]);
1033 IdentifyValid
= SataPrivateData
->IdentifyValid
[DeviceIndex
];
1034 DisqualifiedModes
= &(SataPrivateData
->DisqualifiedModes
[DeviceIndex
]);
1037 // Make sure we've got the valid identify data of the device from SubmitData()
1039 if (!IdentifyValid
) {
1040 FreePool (*SupportedModes
);
1041 return EFI_NOT_READY
;
1044 Status
= CalculateBestPioMode (
1046 (DisqualifiedModes
->PioMode
.Valid
? ((UINT16
*)&(DisqualifiedModes
->PioMode
.Mode
)) : NULL
),
1049 if (!EFI_ERROR (Status
)) {
1050 (*SupportedModes
)->PioMode
.Valid
= TRUE
;
1051 (*SupportedModes
)->PioMode
.Mode
= SelectedMode
;
1053 (*SupportedModes
)->PioMode
.Valid
= FALSE
;
1056 DEBUG ((DEBUG_INFO
, "IdeInitCalculateMode: PioMode = %x\n", (*SupportedModes
)->PioMode
.Mode
));
1058 Status
= CalculateBestUdmaMode (
1060 (DisqualifiedModes
->UdmaMode
.Valid
? ((UINT16
*)&(DisqualifiedModes
->UdmaMode
.Mode
)) : NULL
),
1064 if (!EFI_ERROR (Status
)) {
1065 (*SupportedModes
)->UdmaMode
.Valid
= TRUE
;
1066 (*SupportedModes
)->UdmaMode
.Mode
= SelectedMode
;
1068 (*SupportedModes
)->UdmaMode
.Valid
= FALSE
;
1071 DEBUG ((DEBUG_INFO
, "IdeInitCalculateMode: UdmaMode = %x\n", (*SupportedModes
)->UdmaMode
.Mode
));
1074 // The modes other than PIO and UDMA are not supported
1080 Commands the IDE controller driver to program the IDE controller hardware
1081 so that the specified device can operate at the specified mode.
1083 This function is used by the driver entity to instruct the IDE controller
1084 driver to program the IDE controller hardware to the specified modes. This
1085 function can be called only once for a particular device. For a Serial ATA
1086 (SATA) Advanced Host Controller Interface (AHCI) controller, no controller-
1087 specific programming may be required.
1089 @param[in] This Pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
1090 @param[in] Channel Zero-based channel number.
1091 @param[in] Device Zero-based device number on the Channel.
1092 @param[in] Modes The modes to set.
1094 @retval EFI_SUCCESS The command was accepted without any errors.
1095 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
1096 @retval EFI_INVALID_PARAMETER Device is invalid.
1097 @retval EFI_NOT_READY Modes cannot be set at this time due to lack of data.
1098 @retval EFI_DEVICE_ERROR Modes cannot be set due to hardware failure.
1099 The driver entity should not use this device.
1105 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
1108 IN EFI_ATA_COLLECTIVE_MODE
*Modes