2 This file implements ATA_PASSTHRU_PROTOCOL and EXT_SCSI_PASSTHRU_PROTOCOL interfaces
3 for managed ATA controllers.
5 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "AtaAtapiPassThru.h"
13 // EFI_DRIVER_BINDING_PROTOCOL instance
15 EFI_DRIVER_BINDING_PROTOCOL gAtaAtapiPassThruDriverBinding
= {
16 AtaAtapiPassThruSupported
,
17 AtaAtapiPassThruStart
,
24 ATA_ATAPI_PASS_THRU_INSTANCE gAtaAtapiPassThruInstanceTemplate
= {
25 ATA_ATAPI_PASS_THRU_SIGNATURE
,
26 0, // Controller Handle
27 NULL
, // PciIo Protocol
28 NULL
, // IdeControllerInit Protocol
31 // According to UEFI2.3 spec Section 12.10, Drivers for non-RAID ATA controllers should set
32 // both EFI_ATA_PASS_THRU_ATTRIBUTES_PHYSICAL and EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL
34 // Note that the driver doesn't support AtaPassThru non blocking I/O.
36 EFI_ATA_PASS_THRU_ATTRIBUTES_PHYSICAL
| EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL
| EFI_ATA_PASS_THRU_ATTRIBUTES_NONBLOCKIO
,
45 AtaPassThruGetNextPort
,
46 AtaPassThruGetNextDevice
,
47 AtaPassThruBuildDevicePath
,
50 AtaPassThruResetDevice
52 { // ExtScsiPassThruMode
58 // According to UEFI2.3 spec Section 14.7, Drivers for non-RAID SCSI controllers should set
59 // both EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL and EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL
61 // Note that the driver doesn't support ExtScsiPassThru non blocking I/O.
63 EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL
| EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL
,
71 ExtScsiPassThruPassThru
,
72 ExtScsiPassThruGetNextTargetLun
,
73 ExtScsiPassThruBuildDevicePath
,
74 ExtScsiPassThruGetTargetLun
,
75 ExtScsiPassThruResetChannel
,
76 ExtScsiPassThruResetTargetLun
,
77 ExtScsiPassThruGetNextTarget
79 EfiAtaUnknownMode
, // Work Mode
91 0, // EnabledPciAttributes
92 0, // OriginalAttributes
94 0, // PreviousPortMultiplier
95 0, // PreviousTargetId
98 { // NonBlocking TaskList
104 ATAPI_DEVICE_PATH mAtapiDevicePathTemplate
= {
106 MESSAGING_DEVICE_PATH
,
109 (UINT8
)(sizeof (ATAPI_DEVICE_PATH
)),
110 (UINT8
)((sizeof (ATAPI_DEVICE_PATH
)) >> 8)
118 SATA_DEVICE_PATH mSataDevicePathTemplate
= {
120 MESSAGING_DEVICE_PATH
,
123 (UINT8
)(sizeof (SATA_DEVICE_PATH
)),
124 (UINT8
)((sizeof (SATA_DEVICE_PATH
)) >> 8)
132 UINT8 mScsiId
[TARGET_MAX_BYTES
] = {
133 0xFF, 0xFF, 0xFF, 0xFF,
134 0xFF, 0xFF, 0xFF, 0xFF,
135 0xFF, 0xFF, 0xFF, 0xFF,
136 0xFF, 0xFF, 0xFF, 0xFF
139 EDKII_ATA_ATAPI_POLICY_PROTOCOL
*mAtaAtapiPolicy
;
140 EDKII_ATA_ATAPI_POLICY_PROTOCOL mDefaultAtaAtapiPolicy
= {
141 EDKII_ATA_ATAPI_POLICY_VERSION
,
143 0, // DeviceSleepEnable
144 0, // AggressiveDeviceSleepEnable
149 Sends an ATA command to an ATA device that is attached to the ATA controller. This function
150 supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required,
151 and the non-blocking I/O functionality is optional.
153 @param[in] Port The port number of the ATA device to send the command.
154 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
155 If there is no port multiplier, then specify 0xFFFF.
156 @param[in, out] Packet A pointer to the ATA command to send to the ATA device specified by Port
157 and PortMultiplierPort.
158 @param[in] Instance Pointer to the ATA_ATAPI_PASS_THRU_INSTANCE.
159 @param[in] Task Optional. Pointer to the ATA_NONBLOCK_TASK
160 used by non-blocking mode.
162 @retval EFI_SUCCESS The ATA command was sent by the host. For
163 bi-directional commands, InTransferLength bytes
164 were transferred from InDataBuffer. For
165 write and bi-directional commands, OutTransferLength
166 bytes were transferred by OutDataBuffer.
167 @retval EFI_BAD_BUFFER_SIZE The ATA command was not executed. The number
168 of bytes that could be transferred is returned
169 in InTransferLength. For write and bi-directional
170 commands, OutTransferLength bytes were transferred
172 @retval EFI_NOT_READY The ATA command could not be sent because
173 there are too many ATA commands already
174 queued. The caller may retry again later.
175 @retval EFI_DEVICE_ERROR A device error occurred while attempting
176 to send the ATA command.
177 @retval EFI_INVALID_PARAMETER Port, PortMultiplierPort, or the contents
178 of Acb are invalid. The ATA command was
179 not sent, so no additional status information
185 AtaPassThruPassThruExecute (
187 IN UINT16 PortMultiplierPort
,
188 IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET
*Packet
,
189 IN ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
,
190 IN ATA_NONBLOCK_TASK
*Task OPTIONAL
193 EFI_ATA_PASS_THRU_CMD_PROTOCOL Protocol
;
194 EFI_ATA_HC_WORK_MODE Mode
;
197 Protocol
= Packet
->Protocol
;
199 Mode
= Instance
->Mode
;
203 // Reassign IDE mode io port registers' base addresses
205 Status
= GetIdeRegisterIoAddr (Instance
->PciIo
, Instance
->IdeRegisters
);
207 if (EFI_ERROR (Status
)) {
212 case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA
:
213 Status
= AtaNonDataCommandIn (
215 &Instance
->IdeRegisters
[Port
],
222 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_IN
:
223 Status
= AtaPioDataInOut (
225 &Instance
->IdeRegisters
[Port
],
226 Packet
->InDataBuffer
,
227 Packet
->InTransferLength
,
235 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT
:
236 Status
= AtaPioDataInOut (
238 &Instance
->IdeRegisters
[Port
],
239 Packet
->OutDataBuffer
,
240 Packet
->OutTransferLength
,
248 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_IN
:
249 Status
= AtaUdmaInOut (
251 &Instance
->IdeRegisters
[Port
],
253 Packet
->InDataBuffer
,
254 Packet
->InTransferLength
,
261 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_OUT
:
262 Status
= AtaUdmaInOut (
264 &Instance
->IdeRegisters
[Port
],
266 Packet
->OutDataBuffer
,
267 Packet
->OutTransferLength
,
275 return EFI_UNSUPPORTED
;
280 if (PortMultiplierPort
== 0xFFFF) {
282 // If there is no port multiplier, PortMultiplierPort will be 0xFFFF
283 // according to UEFI spec. Here, we convert its value to 0 to follow
286 PortMultiplierPort
= 0;
290 case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA
:
291 Status
= AhciNonDataTransfer (
293 &Instance
->AhciRegisters
,
295 (UINT8
)PortMultiplierPort
,
304 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_IN
:
305 Status
= AhciPioTransfer (
307 &Instance
->AhciRegisters
,
309 (UINT8
)PortMultiplierPort
,
315 Packet
->InDataBuffer
,
316 Packet
->InTransferLength
,
321 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT
:
322 Status
= AhciPioTransfer (
324 &Instance
->AhciRegisters
,
326 (UINT8
)PortMultiplierPort
,
332 Packet
->OutDataBuffer
,
333 Packet
->OutTransferLength
,
338 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_IN
:
339 Status
= AhciDmaTransfer (
341 &Instance
->AhciRegisters
,
343 (UINT8
)PortMultiplierPort
,
349 Packet
->InDataBuffer
,
350 Packet
->InTransferLength
,
355 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_OUT
:
356 Status
= AhciDmaTransfer (
358 &Instance
->AhciRegisters
,
360 (UINT8
)PortMultiplierPort
,
366 Packet
->OutDataBuffer
,
367 Packet
->OutTransferLength
,
373 return EFI_UNSUPPORTED
;
379 Status
= EFI_DEVICE_ERROR
;
387 Call back function when the timer event is signaled.
389 @param[in] Event The Event this notify function registered to.
390 @param[in] Context Pointer to the context data registered to the
396 AsyncNonBlockingTransferRoutine (
402 LIST_ENTRY
*EntryHeader
;
403 ATA_NONBLOCK_TASK
*Task
;
405 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
407 Instance
= (ATA_ATAPI_PASS_THRU_INSTANCE
*)Context
;
408 EntryHeader
= &Instance
->NonBlockingTaskList
;
410 // Get the Tasks from the Tasks List and execute it, until there is
411 // no task in the list or the device is busy with task (EFI_NOT_READY).
414 if (!IsListEmpty (EntryHeader
)) {
415 Entry
= GetFirstNode (EntryHeader
);
416 Task
= ATA_NON_BLOCK_TASK_FROM_ENTRY (Entry
);
421 Status
= AtaPassThruPassThruExecute (
423 Task
->PortMultiplier
,
430 // If the data transfer meet a error, remove all tasks in the list since these tasks are
431 // associated with one task from Ata Bus and signal the event with error status.
433 if ((Status
!= EFI_NOT_READY
) && (Status
!= EFI_SUCCESS
)) {
434 DestroyAsynTaskList (Instance
, TRUE
);
439 // For Non blocking mode, the Status of EFI_NOT_READY means the operation
440 // is not finished yet. Otherwise the operation is successful.
442 if (Status
== EFI_NOT_READY
) {
445 RemoveEntryList (&Task
->Link
);
446 gBS
->SignalEvent (Task
->Event
);
453 The Entry Point of module.
455 @param[in] ImageHandle The firmware allocated handle for the EFI image.
456 @param[in] SystemTable A pointer to the EFI System Table.
458 @retval EFI_SUCCESS The entry point is executed successfully.
459 @retval other Some error occurs when executing this entry point.
464 InitializeAtaAtapiPassThru (
465 IN EFI_HANDLE ImageHandle
,
466 IN EFI_SYSTEM_TABLE
*SystemTable
472 // Install driver model protocol(s).
474 Status
= EfiLibInstallDriverBindingComponentName2 (
477 &gAtaAtapiPassThruDriverBinding
,
479 &gAtaAtapiPassThruComponentName
,
480 &gAtaAtapiPassThruComponentName2
482 ASSERT_EFI_ERROR (Status
);
488 Tests to see if this driver supports a given controller. If a child device is provided,
489 it further tests to see if this driver supports creating a handle for the specified child device.
491 This function checks to see if the driver specified by This supports the device specified by
492 ControllerHandle. Drivers will typically use the device path attached to
493 ControllerHandle and/or the services from the bus I/O abstraction attached to
494 ControllerHandle to determine if the driver supports ControllerHandle. This function
495 may be called many times during platform initialization. In order to reduce boot times, the tests
496 performed by this function must be very small, and take as little time as possible to execute. This
497 function must not change the state of any hardware devices, and this function must be aware that the
498 device specified by ControllerHandle may already be managed by the same driver or a
499 different driver. This function must match its calls to AllocatePages() with FreePages(),
500 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
501 Because ControllerHandle may have been previously started by the same driver, if a protocol is
502 already in the opened state, then it must not be closed with CloseProtocol(). This is required
503 to guarantee the state of ControllerHandle is not modified by this function.
505 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
506 @param[in] ControllerHandle The handle of the controller to test. This handle
507 must support a protocol interface that supplies
508 an I/O abstraction to the driver.
509 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
510 parameter is ignored by device drivers, and is optional for bus
511 drivers. For bus drivers, if this parameter is not NULL, then
512 the bus driver must determine if the bus controller specified
513 by ControllerHandle and the child controller specified
514 by RemainingDevicePath are both supported by this
517 @retval EFI_SUCCESS The device specified by ControllerHandle and
518 RemainingDevicePath is supported by the driver specified by This.
519 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
520 RemainingDevicePath is already being managed by the driver
522 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
523 RemainingDevicePath is already being managed by a different
524 driver or an application that requires exclusive access.
525 Currently not implemented.
526 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
527 RemainingDevicePath is not supported by the driver specified by This.
531 AtaAtapiPassThruSupported (
532 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
533 IN EFI_HANDLE Controller
,
534 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
538 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
539 EFI_PCI_IO_PROTOCOL
*PciIo
;
541 EFI_IDE_CONTROLLER_INIT_PROTOCOL
*IdeControllerInit
;
544 // SATA Controller is a device driver, and should ignore the
545 // "RemainingDevicePath" according to UEFI spec
547 Status
= gBS
->OpenProtocol (
549 &gEfiDevicePathProtocolGuid
,
550 (VOID
*)&ParentDevicePath
,
551 This
->DriverBindingHandle
,
553 EFI_OPEN_PROTOCOL_BY_DRIVER
555 if (EFI_ERROR (Status
)) {
557 // EFI_ALREADY_STARTED is also an error
563 // Close the protocol because we don't use it here
567 &gEfiDevicePathProtocolGuid
,
568 This
->DriverBindingHandle
,
572 Status
= gBS
->OpenProtocol (
574 &gEfiIdeControllerInitProtocolGuid
,
575 (VOID
**)&IdeControllerInit
,
576 This
->DriverBindingHandle
,
578 EFI_OPEN_PROTOCOL_BY_DRIVER
581 if (EFI_ERROR (Status
)) {
583 // EFI_ALREADY_STARTED is also an error
589 // Close the I/O Abstraction(s) used to perform the supported test
593 &gEfiIdeControllerInitProtocolGuid
,
594 This
->DriverBindingHandle
,
599 // Now test the EfiPciIoProtocol
601 Status
= gBS
->OpenProtocol (
603 &gEfiPciIoProtocolGuid
,
605 This
->DriverBindingHandle
,
607 EFI_OPEN_PROTOCOL_GET_PROTOCOL
609 if (EFI_ERROR (Status
)) {
614 // Now further check the PCI header: Base class (offset 0x0B) and
615 // Sub Class (offset 0x0A). This controller should be an ATA controller
617 Status
= PciIo
->Pci
.Read (
620 PCI_CLASSCODE_OFFSET
,
621 sizeof (PciData
.Hdr
.ClassCode
),
622 PciData
.Hdr
.ClassCode
624 if (EFI_ERROR (Status
)) {
625 return EFI_UNSUPPORTED
;
628 if (IS_PCI_IDE (&PciData
) || IS_PCI_SATADPA (&PciData
)) {
632 return EFI_UNSUPPORTED
;
636 Starts a device controller or a bus controller.
638 The Start() function is designed to be invoked from the EFI boot service ConnectController().
639 As a result, much of the error checking on the parameters to Start() has been moved into this
640 common boot service. It is legal to call Start() from other locations,
641 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
642 1. ControllerHandle must be a valid EFI_HANDLE.
643 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
644 EFI_DEVICE_PATH_PROTOCOL.
645 3. Prior to calling Start(), the Supported() function for the driver specified by This must
646 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
648 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
649 @param[in] ControllerHandle The handle of the controller to start. This handle
650 must support a protocol interface that supplies
651 an I/O abstraction to the driver.
652 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
653 parameter is ignored by device drivers, and is optional for bus
654 drivers. For a bus driver, if this parameter is NULL, then handles
655 for all the children of Controller are created by this driver.
656 If this parameter is not NULL and the first Device Path Node is
657 not the End of Device Path Node, then only the handle for the
658 child device specified by the first Device Path Node of
659 RemainingDevicePath is created by this driver.
660 If the first Device Path Node of RemainingDevicePath is
661 the End of Device Path Node, no child handle is created by this
664 @retval EFI_SUCCESS The device was started.
665 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
666 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
667 @retval Others The driver failed to start the device.
672 AtaAtapiPassThruStart (
673 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
674 IN EFI_HANDLE Controller
,
675 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
679 EFI_IDE_CONTROLLER_INIT_PROTOCOL
*IdeControllerInit
;
680 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
681 EFI_PCI_IO_PROTOCOL
*PciIo
;
682 UINT64 EnabledPciAttributes
;
683 UINT64 OriginalPciAttributes
;
685 Status
= EFI_SUCCESS
;
686 IdeControllerInit
= NULL
;
688 OriginalPciAttributes
= 0;
690 DEBUG ((DEBUG_INFO
, "==AtaAtapiPassThru Start== Controller = %x\n", Controller
));
692 Status
= gBS
->OpenProtocol (
694 &gEfiIdeControllerInitProtocolGuid
,
695 (VOID
**)&IdeControllerInit
,
696 This
->DriverBindingHandle
,
698 EFI_OPEN_PROTOCOL_BY_DRIVER
701 if (EFI_ERROR (Status
)) {
702 DEBUG ((DEBUG_ERROR
, "Open Ide_Controller_Init Error, Status=%r", Status
));
706 Status
= gBS
->OpenProtocol (
708 &gEfiPciIoProtocolGuid
,
710 This
->DriverBindingHandle
,
712 EFI_OPEN_PROTOCOL_GET_PROTOCOL
714 if (EFI_ERROR (Status
)) {
715 DEBUG ((DEBUG_ERROR
, "Get Pci_Io Protocol Error, Status=%r", Status
));
719 Status
= PciIo
->Attributes (
721 EfiPciIoAttributeOperationGet
,
723 &OriginalPciAttributes
726 if (EFI_ERROR (Status
)) {
730 Status
= PciIo
->Attributes (
732 EfiPciIoAttributeOperationSupported
,
734 &EnabledPciAttributes
736 if (!EFI_ERROR (Status
)) {
737 EnabledPciAttributes
&= (UINT64
)EFI_PCI_DEVICE_ENABLE
;
738 Status
= PciIo
->Attributes (
740 EfiPciIoAttributeOperationEnable
,
741 EnabledPciAttributes
,
746 if (EFI_ERROR (Status
)) {
750 Status
= gBS
->LocateProtocol (&gEdkiiAtaAtapiPolicyProtocolGuid
, NULL
, (VOID
**)&mAtaAtapiPolicy
);
751 if (EFI_ERROR (Status
)) {
753 // If there is no AtaAtapiPolicy exposed, use the default policy.
755 mAtaAtapiPolicy
= &mDefaultAtaAtapiPolicy
;
759 // Allocate a buffer to store the ATA_ATAPI_PASS_THRU_INSTANCE data structure
761 Instance
= AllocateCopyPool (sizeof (ATA_ATAPI_PASS_THRU_INSTANCE
), &gAtaAtapiPassThruInstanceTemplate
);
762 if (Instance
== NULL
) {
766 Instance
->ControllerHandle
= Controller
;
767 Instance
->IdeControllerInit
= IdeControllerInit
;
768 Instance
->PciIo
= PciIo
;
769 Instance
->EnabledPciAttributes
= EnabledPciAttributes
;
770 Instance
->OriginalPciAttributes
= OriginalPciAttributes
;
771 Instance
->AtaPassThru
.Mode
= &Instance
->AtaPassThruMode
;
772 Instance
->ExtScsiPassThru
.Mode
= &Instance
->ExtScsiPassThruMode
;
773 InitializeListHead (&Instance
->DeviceList
);
774 InitializeListHead (&Instance
->NonBlockingTaskList
);
776 Instance
->TimerEvent
= NULL
;
778 Status
= gBS
->CreateEvent (
779 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
781 AsyncNonBlockingTransferRoutine
,
783 &Instance
->TimerEvent
785 if (EFI_ERROR (Status
)) {
792 Status
= gBS
->SetTimer (Instance
->TimerEvent
, TimerPeriodic
, 10000);
793 if (EFI_ERROR (Status
)) {
798 // Enumerate all inserted ATA devices.
800 Status
= EnumerateAttachedDevice (Instance
);
801 if (EFI_ERROR (Status
)) {
805 Status
= gBS
->InstallMultipleProtocolInterfaces (
807 &gEfiAtaPassThruProtocolGuid
,
808 &(Instance
->AtaPassThru
),
809 &gEfiExtScsiPassThruProtocolGuid
,
810 &(Instance
->ExtScsiPassThru
),
813 ASSERT_EFI_ERROR (Status
);
818 if (IdeControllerInit
!= NULL
) {
821 &gEfiIdeControllerInitProtocolGuid
,
822 This
->DriverBindingHandle
,
827 if ((Instance
!= NULL
) && (Instance
->TimerEvent
!= NULL
)) {
828 gBS
->CloseEvent (Instance
->TimerEvent
);
831 if (Instance
!= NULL
) {
833 // Remove all inserted ATA devices.
835 DestroyDeviceInfoList (Instance
);
839 return EFI_UNSUPPORTED
;
843 Stops a device controller or a bus controller.
845 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
846 As a result, much of the error checking on the parameters to Stop() has been moved
847 into this common boot service. It is legal to call Stop() from other locations,
848 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
849 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
850 same driver's Start() function.
851 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
852 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
853 Start() function, and the Start() function must have called OpenProtocol() on
854 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
856 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
857 @param[in] ControllerHandle A handle to the device being stopped. The handle must
858 support a bus specific I/O protocol for the driver
859 to use to stop the device.
860 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
861 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
862 if NumberOfChildren is 0.
864 @retval EFI_SUCCESS The device was stopped.
865 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
870 AtaAtapiPassThruStop (
871 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
872 IN EFI_HANDLE Controller
,
873 IN UINTN NumberOfChildren
,
874 IN EFI_HANDLE
*ChildHandleBuffer
878 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
879 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
880 EFI_PCI_IO_PROTOCOL
*PciIo
;
881 EFI_AHCI_REGISTERS
*AhciRegisters
;
883 DEBUG ((DEBUG_INFO
, "==AtaAtapiPassThru Stop== Controller = %x\n", Controller
));
885 Status
= gBS
->OpenProtocol (
887 &gEfiAtaPassThruProtocolGuid
,
888 (VOID
**)&AtaPassThru
,
889 This
->DriverBindingHandle
,
891 EFI_OPEN_PROTOCOL_GET_PROTOCOL
894 if (EFI_ERROR (Status
)) {
895 return EFI_DEVICE_ERROR
;
898 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (AtaPassThru
);
900 Status
= gBS
->UninstallMultipleProtocolInterfaces (
902 &gEfiAtaPassThruProtocolGuid
,
903 &(Instance
->AtaPassThru
),
904 &gEfiExtScsiPassThruProtocolGuid
,
905 &(Instance
->ExtScsiPassThru
),
909 if (EFI_ERROR (Status
)) {
910 return EFI_DEVICE_ERROR
;
914 // Close protocols opened by AtaAtapiPassThru controller driver
918 &gEfiIdeControllerInitProtocolGuid
,
919 This
->DriverBindingHandle
,
924 // Close Non-Blocking timer and free Task list.
926 if (Instance
->TimerEvent
!= NULL
) {
927 gBS
->CloseEvent (Instance
->TimerEvent
);
928 Instance
->TimerEvent
= NULL
;
931 DestroyAsynTaskList (Instance
, FALSE
);
933 // Free allocated resource
935 DestroyDeviceInfoList (Instance
);
937 PciIo
= Instance
->PciIo
;
940 // Disable this ATA host controller.
944 EfiPciIoAttributeOperationDisable
,
945 Instance
->EnabledPciAttributes
,
950 // If the current working mode is AHCI mode, then pre-allocated resource
951 // for AHCI initialization should be released.
953 if (Instance
->Mode
== EfiAtaAhciMode
) {
954 AhciRegisters
= &Instance
->AhciRegisters
;
957 AhciRegisters
->MapCommandTable
961 EFI_SIZE_TO_PAGES ((UINTN
)AhciRegisters
->MaxCommandTableSize
),
962 AhciRegisters
->AhciCommandTable
966 AhciRegisters
->MapCmdList
970 EFI_SIZE_TO_PAGES ((UINTN
)AhciRegisters
->MaxCommandListSize
),
971 AhciRegisters
->AhciCmdList
975 AhciRegisters
->MapRFis
979 EFI_SIZE_TO_PAGES ((UINTN
)AhciRegisters
->MaxReceiveFisSize
),
980 AhciRegisters
->AhciRFis
985 // Restore original PCI attributes
987 Status
= PciIo
->Attributes (
989 EfiPciIoAttributeOperationSet
,
990 Instance
->OriginalPciAttributes
,
993 ASSERT_EFI_ERROR (Status
);
1001 Traverse the attached ATA devices list to find out the device to access.
1003 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
1004 @param[in] Port The port number of the ATA device to send the command.
1005 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
1006 If there is no port multiplier, then specify 0xFFFF.
1007 @param[in] DeviceType The device type of the ATA device.
1009 @retval The pointer to the data structure of the device info to access.
1014 SearchDeviceInfoList (
1015 IN ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
,
1017 IN UINT16 PortMultiplier
,
1018 IN EFI_ATA_DEVICE_TYPE DeviceType
1021 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
1024 Node
= GetFirstNode (&Instance
->DeviceList
);
1025 while (!IsNull (&Instance
->DeviceList
, Node
)) {
1026 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1029 // For CD-ROM working in the AHCI mode, only 8 bits are used to record
1030 // the PortMultiplier information. If the CD-ROM is directly attached
1031 // on a SATA port, the PortMultiplier should be translated from 0xFF
1032 // to 0xFFFF according to the UEFI spec.
1034 if ((Instance
->Mode
== EfiAtaAhciMode
) &&
1035 (DeviceInfo
->Type
== EfiIdeCdrom
) &&
1036 (PortMultiplier
== 0xFF))
1038 PortMultiplier
= 0xFFFF;
1041 if ((DeviceInfo
->Type
== DeviceType
) &&
1042 (Port
== DeviceInfo
->Port
) &&
1043 (PortMultiplier
== DeviceInfo
->PortMultiplier
))
1048 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
1055 Allocate device info data structure to contain device info.
1056 And insert the data structure to the tail of device list for tracing.
1058 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
1059 @param[in] Port The port number of the ATA device to send the command.
1060 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
1061 If there is no port multiplier, then specify 0xFFFF.
1062 @param[in] DeviceType The device type of the ATA device.
1063 @param[in] IdentifyData The data buffer to store the output of the IDENTIFY cmd.
1065 @retval EFI_SUCCESS Successfully insert the ata device to the tail of device list.
1066 @retval EFI_OUT_OF_RESOURCES Can not allocate enough resource for use.
1071 CreateNewDeviceInfo (
1072 IN ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
,
1074 IN UINT16 PortMultiplier
,
1075 IN EFI_ATA_DEVICE_TYPE DeviceType
,
1076 IN EFI_IDENTIFY_DATA
*IdentifyData
1079 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
1081 DeviceInfo
= AllocateZeroPool (sizeof (EFI_ATA_DEVICE_INFO
));
1083 if (DeviceInfo
== NULL
) {
1084 return EFI_OUT_OF_RESOURCES
;
1087 DeviceInfo
->Signature
= ATA_ATAPI_DEVICE_SIGNATURE
;
1088 DeviceInfo
->Port
= Port
;
1089 DeviceInfo
->PortMultiplier
= PortMultiplier
;
1090 DeviceInfo
->Type
= DeviceType
;
1092 if (IdentifyData
!= NULL
) {
1093 DeviceInfo
->IdentifyData
= AllocateCopyPool (sizeof (EFI_IDENTIFY_DATA
), IdentifyData
);
1094 if (DeviceInfo
->IdentifyData
== NULL
) {
1095 FreePool (DeviceInfo
);
1096 return EFI_OUT_OF_RESOURCES
;
1100 InsertTailList (&Instance
->DeviceList
, &DeviceInfo
->Link
);
1106 Destroy all attached ATA devices info.
1108 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
1113 DestroyDeviceInfoList (
1114 IN ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
1117 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
1120 Node
= GetFirstNode (&Instance
->DeviceList
);
1121 while (!IsNull (&Instance
->DeviceList
, Node
)) {
1122 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1124 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
1126 RemoveEntryList (&DeviceInfo
->Link
);
1127 if (DeviceInfo
->IdentifyData
!= NULL
) {
1128 FreePool (DeviceInfo
->IdentifyData
);
1131 FreePool (DeviceInfo
);
1136 Destroy all pending non blocking tasks.
1138 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
1139 @param[in] IsSigEvent Indicate whether signal the task event when remove the
1145 DestroyAsynTaskList (
1146 IN ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
,
1147 IN BOOLEAN IsSigEvent
1151 LIST_ENTRY
*DelEntry
;
1152 ATA_NONBLOCK_TASK
*Task
;
1155 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1156 if (!IsListEmpty (&Instance
->NonBlockingTaskList
)) {
1158 // Free the Subtask list.
1160 for (Entry
= (&Instance
->NonBlockingTaskList
)->ForwardLink
;
1161 Entry
!= (&Instance
->NonBlockingTaskList
);
1165 Entry
= Entry
->ForwardLink
;
1166 Task
= ATA_NON_BLOCK_TASK_FROM_ENTRY (DelEntry
);
1168 RemoveEntryList (DelEntry
);
1170 Task
->Packet
->Asb
->AtaStatus
= 0x01;
1171 gBS
->SignalEvent (Task
->Event
);
1178 gBS
->RestoreTPL (OldTpl
);
1182 Enumerate all attached ATA devices at IDE mode or AHCI mode separately.
1184 The function is designed to enumerate all attached ATA devices.
1186 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
1188 @retval EFI_SUCCESS Successfully enumerate attached ATA devices.
1189 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1194 EnumerateAttachedDevice (
1195 IN ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
1202 Status
= EFI_SUCCESS
;
1204 Status
= Instance
->PciIo
->Pci
.Read (
1207 PCI_CLASSCODE_OFFSET
,
1208 sizeof (PciData
.Hdr
.ClassCode
),
1209 PciData
.Hdr
.ClassCode
1211 ASSERT_EFI_ERROR (Status
);
1213 ClassCode
= PciData
.Hdr
.ClassCode
[1];
1215 switch (ClassCode
) {
1216 case PCI_CLASS_MASS_STORAGE_IDE
:
1218 // The ATA controller is working at IDE mode
1220 Instance
->Mode
= EfiAtaIdeMode
;
1222 Status
= IdeModeInitialization (Instance
);
1223 if (EFI_ERROR (Status
)) {
1224 Status
= EFI_DEVICE_ERROR
;
1229 case PCI_CLASS_MASS_STORAGE_SATADPA
:
1231 // The ATA controller is working at AHCI mode
1233 Instance
->Mode
= EfiAtaAhciMode
;
1235 Status
= AhciModeInitialization (Instance
);
1237 if (EFI_ERROR (Status
)) {
1238 Status
= EFI_DEVICE_ERROR
;
1244 Status
= EFI_UNSUPPORTED
;
1252 Sends an ATA command to an ATA device that is attached to the ATA controller. This function
1253 supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required,
1254 and the non-blocking I/O functionality is optional.
1256 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1257 @param[in] Port The port number of the ATA device to send the command.
1258 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
1259 If there is no port multiplier, then specify 0xFFFF.
1260 @param[in, out] Packet A pointer to the ATA command to send to the ATA device specified by Port
1261 and PortMultiplierPort.
1262 @param[in] Event If non-blocking I/O is not supported then Event is ignored, and blocking
1263 I/O is performed. If Event is NULL, then blocking I/O is performed. If
1264 Event is not NULL and non blocking I/O is supported, then non-blocking
1265 I/O is performed, and Event will be signaled when the ATA command completes.
1267 @retval EFI_SUCCESS The ATA command was sent by the host. For bi-directional commands,
1268 InTransferLength bytes were transferred from InDataBuffer. For write and
1269 bi-directional commands, OutTransferLength bytes were transferred by OutDataBuffer.
1270 @retval EFI_BAD_BUFFER_SIZE The ATA command was not executed. The number of bytes that could be transferred
1271 is returned in InTransferLength. For write and bi-directional commands,
1272 OutTransferLength bytes were transferred by OutDataBuffer.
1273 @retval EFI_NOT_READY The ATA command could not be sent because there are too many ATA commands
1274 already queued. The caller may retry again later.
1275 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the ATA command.
1276 @retval EFI_INVALID_PARAMETER Port, PortMultiplierPort, or the contents of Acb are invalid. The ATA
1277 command was not sent, so no additional status information is available.
1282 AtaPassThruPassThru (
1283 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1285 IN UINT16 PortMultiplierPort
,
1286 IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET
*Packet
,
1287 IN EFI_EVENT Event OPTIONAL
1290 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1292 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
1293 EFI_IDENTIFY_DATA
*IdentifyData
;
1295 UINT32 MaxSectorCount
;
1296 ATA_NONBLOCK_TASK
*Task
;
1300 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1302 if ((This
->Mode
->IoAlign
> 1) && !IS_ALIGNED (Packet
->InDataBuffer
, This
->Mode
->IoAlign
)) {
1303 return EFI_INVALID_PARAMETER
;
1306 if ((This
->Mode
->IoAlign
> 1) && !IS_ALIGNED (Packet
->OutDataBuffer
, This
->Mode
->IoAlign
)) {
1307 return EFI_INVALID_PARAMETER
;
1310 if ((This
->Mode
->IoAlign
> 1) && !IS_ALIGNED (Packet
->Asb
, This
->Mode
->IoAlign
)) {
1311 return EFI_INVALID_PARAMETER
;
1314 Node
= SearchDeviceInfoList (Instance
, Port
, PortMultiplierPort
, EfiIdeHarddisk
);
1317 Node
= SearchDeviceInfoList (Instance
, Port
, PortMultiplierPort
, EfiIdeCdrom
);
1319 return EFI_INVALID_PARAMETER
;
1324 // Check whether this device needs 48-bit addressing (ATAPI-6 ata device).
1325 // Per ATA-6 spec, word83: bit15 is zero and bit14 is one.
1326 // If bit10 is one, it means the ata device support 48-bit addressing.
1328 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1329 IdentifyData
= DeviceInfo
->IdentifyData
;
1330 MaxSectorCount
= 0x100;
1331 if ((IdentifyData
->AtaData
.command_set_supported_83
& (BIT10
| BIT15
| BIT14
)) == 0x4400) {
1332 Capacity
= *((UINT64
*)IdentifyData
->AtaData
.maximum_lba_for_48bit_addressing
);
1333 if (Capacity
> 0xFFFFFFF) {
1335 // Capacity exceeds 120GB. 48-bit addressing is really needed
1336 // In this case, the max sector count is 0x10000
1338 MaxSectorCount
= 0x10000;
1343 if ((IdentifyData
->AtaData
.phy_logic_sector_support
& (BIT14
| BIT15
)) == BIT14
) {
1345 // Check logical block size
1347 if ((IdentifyData
->AtaData
.phy_logic_sector_support
& BIT12
) != 0) {
1348 BlockSize
= (UINT32
)(((IdentifyData
->AtaData
.logic_sector_size_hi
<< 16) | IdentifyData
->AtaData
.logic_sector_size_lo
) * sizeof (UINT16
));
1353 // convert the transfer length from sector count to byte.
1355 if (((Packet
->Length
& EFI_ATA_PASS_THRU_LENGTH_BYTES
) == 0) &&
1356 (Packet
->InTransferLength
!= 0))
1358 Packet
->InTransferLength
= Packet
->InTransferLength
* BlockSize
;
1362 // convert the transfer length from sector count to byte.
1364 if (((Packet
->Length
& EFI_ATA_PASS_THRU_LENGTH_BYTES
) == 0) &&
1365 (Packet
->OutTransferLength
!= 0))
1367 Packet
->OutTransferLength
= Packet
->OutTransferLength
* BlockSize
;
1371 // If the data buffer described by InDataBuffer/OutDataBuffer and InTransferLength/OutTransferLength
1372 // is too big to be transferred in a single command, then no data is transferred and EFI_BAD_BUFFER_SIZE
1375 if (((Packet
->InTransferLength
!= 0) && (Packet
->InTransferLength
> MaxSectorCount
* BlockSize
)) ||
1376 ((Packet
->OutTransferLength
!= 0) && (Packet
->OutTransferLength
> MaxSectorCount
* BlockSize
)))
1378 return EFI_BAD_BUFFER_SIZE
;
1382 // For non-blocking mode, queue the Task into the list.
1384 if (Event
!= NULL
) {
1385 Task
= AllocateZeroPool (sizeof (ATA_NONBLOCK_TASK
));
1387 return EFI_OUT_OF_RESOURCES
;
1390 Task
->Signature
= ATA_NONBLOCKING_TASK_SIGNATURE
;
1392 Task
->PortMultiplier
= PortMultiplierPort
;
1393 Task
->Packet
= Packet
;
1394 Task
->Event
= Event
;
1395 Task
->IsStart
= FALSE
;
1396 Task
->RetryTimes
= DivU64x32 (Packet
->Timeout
, 1000) + 1;
1397 if (Packet
->Timeout
== 0) {
1398 Task
->InfiniteWait
= TRUE
;
1400 Task
->InfiniteWait
= FALSE
;
1403 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1404 InsertTailList (&Instance
->NonBlockingTaskList
, &Task
->Link
);
1405 gBS
->RestoreTPL (OldTpl
);
1409 return AtaPassThruPassThruExecute (
1420 Used to retrieve the list of legal port numbers for ATA devices on an ATA controller.
1421 These can either be the list of ports where ATA devices are actually present or the
1422 list of legal port numbers for the ATA controller. Regardless, the caller of this
1423 function must probe the port number returned to see if an ATA device is actually
1424 present at that location on the ATA controller.
1426 The GetNextPort() function retrieves the port number on an ATA controller. If on input
1427 Port is 0xFFFF, then the port number of the first port on the ATA controller is returned
1428 in Port and EFI_SUCCESS is returned.
1430 If Port is a port number that was returned on a previous call to GetNextPort(), then the
1431 port number of the next port on the ATA controller is returned in Port, and EFI_SUCCESS
1432 is returned. If Port is not 0xFFFF and Port was not returned on a previous call to
1433 GetNextPort(), then EFI_INVALID_PARAMETER is returned.
1435 If Port is the port number of the last port on the ATA controller, then EFI_NOT_FOUND is
1438 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1439 @param[in, out] Port On input, a pointer to the port number on the ATA controller.
1440 On output, a pointer to the next port number on the ATA
1441 controller. An input value of 0xFFFF retrieves the first port
1442 number on the ATA controller.
1444 @retval EFI_SUCCESS The next port number on the ATA controller was returned in Port.
1445 @retval EFI_NOT_FOUND There are no more ports on this ATA controller.
1446 @retval EFI_INVALID_PARAMETER Port is not 0xFFFF and Port was not returned on a previous call
1452 AtaPassThruGetNextPort (
1453 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1457 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1459 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
1461 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1464 return EFI_INVALID_PARAMETER
;
1467 if (*Port
== 0xFFFF) {
1469 // If the Port is all 0xFF's, start to traverse the device list from the beginning
1471 Node
= GetFirstNode (&Instance
->DeviceList
);
1473 while (!IsNull (&Instance
->DeviceList
, Node
)) {
1474 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1476 if (DeviceInfo
->Type
== EfiIdeHarddisk
) {
1477 *Port
= DeviceInfo
->Port
;
1481 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
1484 return EFI_NOT_FOUND
;
1485 } else if (*Port
== Instance
->PreviousPort
) {
1486 Node
= GetFirstNode (&Instance
->DeviceList
);
1488 while (!IsNull (&Instance
->DeviceList
, Node
)) {
1489 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1491 if ((DeviceInfo
->Type
== EfiIdeHarddisk
) &&
1492 (DeviceInfo
->Port
> *Port
))
1494 *Port
= DeviceInfo
->Port
;
1498 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
1501 return EFI_NOT_FOUND
;
1504 // Port is not equal to 0xFFFF and also not equal to previous return value
1506 return EFI_INVALID_PARAMETER
;
1511 // Update the PreviousPort and PreviousPortMultiplier.
1513 Instance
->PreviousPort
= *Port
;
1519 Used to retrieve the list of legal port multiplier port numbers for ATA devices on a port of an ATA
1520 controller. These can either be the list of port multiplier ports where ATA devices are actually
1521 present on port or the list of legal port multiplier ports on that port. Regardless, the caller of this
1522 function must probe the port number and port multiplier port number returned to see if an ATA
1523 device is actually present.
1525 The GetNextDevice() function retrieves the port multiplier port number of an ATA device
1526 present on a port of an ATA controller.
1528 If PortMultiplierPort points to a port multiplier port number value that was returned on a
1529 previous call to GetNextDevice(), then the port multiplier port number of the next ATA device
1530 on the port of the ATA controller is returned in PortMultiplierPort, and EFI_SUCCESS is
1533 If PortMultiplierPort points to 0xFFFF, then the port multiplier port number of the first
1534 ATA device on port of the ATA controller is returned in PortMultiplierPort and
1535 EFI_SUCCESS is returned.
1537 If PortMultiplierPort is not 0xFFFF and the value pointed to by PortMultiplierPort
1538 was not returned on a previous call to GetNextDevice(), then EFI_INVALID_PARAMETER
1541 If PortMultiplierPort is the port multiplier port number of the last ATA device on the port of
1542 the ATA controller, then EFI_NOT_FOUND is returned.
1544 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1545 @param[in] Port The port number present on the ATA controller.
1546 @param[in, out] PortMultiplierPort On input, a pointer to the port multiplier port number of an
1547 ATA device present on the ATA controller.
1548 If on input a PortMultiplierPort of 0xFFFF is specified,
1549 then the port multiplier port number of the first ATA device
1550 is returned. On output, a pointer to the port multiplier port
1551 number of the next ATA device present on an ATA controller.
1553 @retval EFI_SUCCESS The port multiplier port number of the next ATA device on the port
1554 of the ATA controller was returned in PortMultiplierPort.
1555 @retval EFI_NOT_FOUND There are no more ATA devices on this port of the ATA controller.
1556 @retval EFI_INVALID_PARAMETER PortMultiplierPort is not 0xFFFF, and PortMultiplierPort was not
1557 returned on a previous call to GetNextDevice().
1562 AtaPassThruGetNextDevice (
1563 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1565 IN OUT UINT16
*PortMultiplierPort
1568 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1570 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
1572 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1574 if (PortMultiplierPort
== NULL
) {
1575 return EFI_INVALID_PARAMETER
;
1578 if (Instance
->PreviousPortMultiplier
== 0xFFFF) {
1580 // If a device is directly attached on a port, previous call to this
1581 // function will return the value 0xFFFF for PortMultiplierPort. In
1582 // this case, there should be no more device on the port multiplier.
1584 Instance
->PreviousPortMultiplier
= 0;
1585 return EFI_NOT_FOUND
;
1588 if (*PortMultiplierPort
== Instance
->PreviousPortMultiplier
) {
1589 Node
= GetFirstNode (&Instance
->DeviceList
);
1591 while (!IsNull (&Instance
->DeviceList
, Node
)) {
1592 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1594 if ((DeviceInfo
->Type
== EfiIdeHarddisk
) &&
1595 (DeviceInfo
->Port
== Port
) &&
1596 (DeviceInfo
->PortMultiplier
> *PortMultiplierPort
))
1598 *PortMultiplierPort
= DeviceInfo
->PortMultiplier
;
1602 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
1605 return EFI_NOT_FOUND
;
1606 } else if (*PortMultiplierPort
== 0xFFFF) {
1608 // If the PortMultiplierPort is all 0xFF's, start to traverse the device list from the beginning
1610 Node
= GetFirstNode (&Instance
->DeviceList
);
1612 while (!IsNull (&Instance
->DeviceList
, Node
)) {
1613 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1615 if ((DeviceInfo
->Type
== EfiIdeHarddisk
) &&
1616 (DeviceInfo
->Port
== Port
))
1618 *PortMultiplierPort
= DeviceInfo
->PortMultiplier
;
1622 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
1625 return EFI_NOT_FOUND
;
1628 // PortMultiplierPort is not equal to 0xFFFF and also not equal to previous return value
1630 return EFI_INVALID_PARAMETER
;
1635 // Update the PreviousPort and PreviousPortMultiplier.
1637 Instance
->PreviousPortMultiplier
= *PortMultiplierPort
;
1643 Used to allocate and build a device path node for an ATA device on an ATA controller.
1645 The BuildDevicePath() function allocates and builds a single device node for the ATA
1646 device specified by Port and PortMultiplierPort. If the ATA device specified by Port and
1647 PortMultiplierPort is not present on the ATA controller, then EFI_NOT_FOUND is returned.
1648 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned. If there are not enough
1649 resources to allocate the device path node, then EFI_OUT_OF_RESOURCES is returned.
1651 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of
1652 DevicePath are initialized to describe the ATA device specified by Port and PortMultiplierPort,
1653 and EFI_SUCCESS is returned.
1655 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1656 @param[in] Port Port specifies the port number of the ATA device for which a
1657 device path node is to be allocated and built.
1658 @param[in] PortMultiplierPort The port multiplier port number of the ATA device for which a
1659 device path node is to be allocated and built. If there is no
1660 port multiplier, then specify 0xFFFF.
1661 @param[in, out] DevicePath A pointer to a single device path node that describes the ATA
1662 device specified by Port and PortMultiplierPort. This function
1663 is responsible for allocating the buffer DevicePath with the
1664 boot service AllocatePool(). It is the caller's responsibility
1665 to free DevicePath when the caller is finished with DevicePath.
1666 @retval EFI_SUCCESS The device path node that describes the ATA device specified by
1667 Port and PortMultiplierPort was allocated and returned in DevicePath.
1668 @retval EFI_NOT_FOUND The ATA device specified by Port and PortMultiplierPort does not
1669 exist on the ATA controller.
1670 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
1671 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
1676 AtaPassThruBuildDevicePath (
1677 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1679 IN UINT16 PortMultiplierPort
,
1680 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
1683 EFI_DEV_PATH
*DevicePathNode
;
1684 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1687 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1690 // Validate parameters passed in.
1692 if (DevicePath
== NULL
) {
1693 return EFI_INVALID_PARAMETER
;
1696 Node
= SearchDeviceInfoList (Instance
, Port
, PortMultiplierPort
, EfiIdeHarddisk
);
1698 return EFI_NOT_FOUND
;
1701 if (Instance
->Mode
== EfiAtaIdeMode
) {
1702 DevicePathNode
= AllocateCopyPool (sizeof (ATAPI_DEVICE_PATH
), &mAtapiDevicePathTemplate
);
1703 if (DevicePathNode
== NULL
) {
1704 return EFI_OUT_OF_RESOURCES
;
1707 DevicePathNode
->Atapi
.PrimarySecondary
= (UINT8
)Port
;
1708 DevicePathNode
->Atapi
.SlaveMaster
= (UINT8
)PortMultiplierPort
;
1709 DevicePathNode
->Atapi
.Lun
= 0;
1711 DevicePathNode
= AllocateCopyPool (sizeof (SATA_DEVICE_PATH
), &mSataDevicePathTemplate
);
1712 if (DevicePathNode
== NULL
) {
1713 return EFI_OUT_OF_RESOURCES
;
1716 DevicePathNode
->Sata
.HBAPortNumber
= Port
;
1717 DevicePathNode
->Sata
.PortMultiplierPortNumber
= PortMultiplierPort
;
1718 DevicePathNode
->Sata
.Lun
= 0;
1721 *DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)DevicePathNode
;
1727 Used to translate a device path node to a port number and port multiplier port number.
1729 The GetDevice() function determines the port and port multiplier port number associated with
1730 the ATA device described by DevicePath. If DevicePath is a device path node type that the
1731 ATA Pass Thru driver supports, then the ATA Pass Thru driver will attempt to translate the contents
1732 DevicePath into a port number and port multiplier port number.
1734 If this translation is successful, then that port number and port multiplier port number are returned
1735 in Port and PortMultiplierPort, and EFI_SUCCESS is returned.
1737 If DevicePath, Port, or PortMultiplierPort are NULL, then EFI_INVALID_PARAMETER is returned.
1739 If DevicePath is not a device path node type that the ATA Pass Thru driver supports, then
1740 EFI_UNSUPPORTED is returned.
1742 If DevicePath is a device path node type that the ATA Pass Thru driver supports, but there is not
1743 a valid translation from DevicePath to a port number and port multiplier port number, then
1744 EFI_NOT_FOUND is returned.
1746 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1747 @param[in] DevicePath A pointer to the device path node that describes an ATA device on the
1749 @param[out] Port On return, points to the port number of an ATA device on the ATA controller.
1750 @param[out] PortMultiplierPort On return, points to the port multiplier port number of an ATA device
1751 on the ATA controller.
1753 @retval EFI_SUCCESS DevicePath was successfully translated to a port number and port multiplier
1754 port number, and they were returned in Port and PortMultiplierPort.
1755 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
1756 @retval EFI_INVALID_PARAMETER Port is NULL.
1757 @retval EFI_INVALID_PARAMETER PortMultiplierPort is NULL.
1758 @retval EFI_UNSUPPORTED This driver does not support the device path node type in DevicePath.
1759 @retval EFI_NOT_FOUND A valid translation from DevicePath to a port number and port multiplier
1760 port number does not exist.
1764 AtaPassThruGetDevice (
1765 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1766 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1768 OUT UINT16
*PortMultiplierPort
1771 EFI_DEV_PATH
*DevicePathNode
;
1772 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1775 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1778 // Validate parameters passed in.
1780 if ((DevicePath
== NULL
) || (Port
== NULL
) || (PortMultiplierPort
== NULL
)) {
1781 return EFI_INVALID_PARAMETER
;
1785 // Check whether the DevicePath belongs to SCSI_DEVICE_PATH or ATAPI_DEVICE_PATH
1787 if ((DevicePath
->Type
!= MESSAGING_DEVICE_PATH
) ||
1788 ((DevicePath
->SubType
!= MSG_SATA_DP
) &&
1789 (DevicePath
->SubType
!= MSG_ATAPI_DP
)) ||
1790 ((DevicePathNodeLength (DevicePath
) != sizeof (ATAPI_DEVICE_PATH
)) &&
1791 (DevicePathNodeLength (DevicePath
) != sizeof (SATA_DEVICE_PATH
))))
1793 return EFI_UNSUPPORTED
;
1796 DevicePathNode
= (EFI_DEV_PATH
*)DevicePath
;
1798 if (Instance
->Mode
== EfiAtaIdeMode
) {
1799 *Port
= DevicePathNode
->Atapi
.PrimarySecondary
;
1800 *PortMultiplierPort
= DevicePathNode
->Atapi
.SlaveMaster
;
1802 *Port
= DevicePathNode
->Sata
.HBAPortNumber
;
1803 *PortMultiplierPort
= DevicePathNode
->Sata
.PortMultiplierPortNumber
;
1806 Node
= SearchDeviceInfoList (Instance
, *Port
, *PortMultiplierPort
, EfiIdeHarddisk
);
1809 return EFI_NOT_FOUND
;
1816 Resets a specific port on the ATA controller. This operation also resets all the ATA devices
1817 connected to the port.
1819 The ResetChannel() function resets an a specific port on an ATA controller. This operation
1820 resets all the ATA devices connected to that port. If this ATA controller does not support
1821 a reset port operation, then EFI_UNSUPPORTED is returned.
1823 If a device error occurs while executing that port reset operation, then EFI_DEVICE_ERROR is
1826 If a timeout occurs during the execution of the port reset operation, then EFI_TIMEOUT is returned.
1828 If the port reset operation is completed, then EFI_SUCCESS is returned.
1830 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1831 @param[in] Port The port number on the ATA controller.
1833 @retval EFI_SUCCESS The ATA controller port was reset.
1834 @retval EFI_UNSUPPORTED The ATA controller does not support a port reset operation.
1835 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the ATA port.
1836 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the ATA port.
1841 AtaPassThruResetPort (
1842 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1847 // Return success directly then upper layer driver could think reset port operation is done.
1853 Resets an ATA device that is connected to an ATA controller.
1855 The ResetDevice() function resets the ATA device specified by Port and PortMultiplierPort.
1856 If this ATA controller does not support a device reset operation, then EFI_UNSUPPORTED is
1859 If Port or PortMultiplierPort are not in a valid range for this ATA controller, then
1860 EFI_INVALID_PARAMETER is returned.
1862 If a device error occurs while executing that device reset operation, then EFI_DEVICE_ERROR
1865 If a timeout occurs during the execution of the device reset operation, then EFI_TIMEOUT is
1868 If the device reset operation is completed, then EFI_SUCCESS is returned.
1870 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1871 @param[in] Port Port represents the port number of the ATA device to be reset.
1872 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to reset.
1873 If there is no port multiplier, then specify 0xFFFF.
1874 @retval EFI_SUCCESS The ATA device specified by Port and PortMultiplierPort was reset.
1875 @retval EFI_UNSUPPORTED The ATA controller does not support a device reset operation.
1876 @retval EFI_INVALID_PARAMETER Port or PortMultiplierPort are invalid.
1877 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the ATA device
1878 specified by Port and PortMultiplierPort.
1879 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the ATA device
1880 specified by Port and PortMultiplierPort.
1885 AtaPassThruResetDevice (
1886 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1888 IN UINT16 PortMultiplierPort
1891 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1894 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1896 Node
= SearchDeviceInfoList (Instance
, Port
, PortMultiplierPort
, EfiIdeHarddisk
);
1899 return EFI_INVALID_PARAMETER
;
1903 // Return success directly then upper layer driver could think reset device operation is done.
1909 Submit ATAPI request sense command.
1911 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
1912 @param[in] Target The Target is an array of size TARGET_MAX_BYTES and it represents
1913 the id of the SCSI device to send the SCSI Request Packet. Each
1914 transport driver may choose to utilize a subset of this size to suit the needs
1915 of transport target representation. For example, a Fibre Channel driver
1916 may use only 8 bytes (WWN) to represent an FC target.
1917 @param[in] Lun The LUN of the SCSI device to send the SCSI Request Packet.
1918 @param[in] SenseData A pointer to store sense data.
1919 @param[in] SenseDataLength The sense data length.
1920 @param[in] Timeout The timeout value to execute this cmd, uses 100ns as a unit.
1922 @retval EFI_SUCCESS Send out the ATAPI packet command successfully.
1923 @retval EFI_DEVICE_ERROR The device failed to send data.
1928 AtaPacketRequestSense (
1929 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
1933 IN UINT8 SenseDataLength
,
1937 EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET Packet
;
1941 ZeroMem (&Packet
, sizeof (EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
));
1944 Cdb
[0] = ATA_CMD_REQUEST_SENSE
;
1945 Cdb
[4] = SenseDataLength
;
1947 Packet
.Timeout
= Timeout
;
1949 Packet
.CdbLength
= 12;
1950 Packet
.DataDirection
= EFI_EXT_SCSI_DATA_DIRECTION_READ
;
1951 Packet
.InDataBuffer
= SenseData
;
1952 Packet
.InTransferLength
= SenseDataLength
;
1954 Status
= ExtScsiPassThruPassThru (This
, Target
, Lun
, &Packet
, NULL
);
1960 Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function
1961 supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the
1962 nonblocking I/O functionality is optional.
1964 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
1965 @param Target The Target is an array of size TARGET_MAX_BYTES and it represents
1966 the id of the SCSI device to send the SCSI Request Packet. Each
1967 transport driver may choose to utilize a subset of this size to suit the needs
1968 of transport target representation. For example, a Fibre Channel driver
1969 may use only 8 bytes (WWN) to represent an FC target.
1970 @param Lun The LUN of the SCSI device to send the SCSI Request Packet.
1971 @param Packet A pointer to the SCSI Request Packet to send to the SCSI device
1972 specified by Target and Lun.
1973 @param Event If nonblocking I/O is not supported then Event is ignored, and blocking
1974 I/O is performed. If Event is NULL, then blocking I/O is performed. If
1975 Event is not NULL and non blocking I/O is supported, then
1976 nonblocking I/O is performed, and Event will be signaled when the
1977 SCSI Request Packet completes.
1979 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional
1980 commands, InTransferLength bytes were transferred from
1981 InDataBuffer. For write and bi-directional commands,
1982 OutTransferLength bytes were transferred by
1984 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was not executed. The number of bytes that
1985 could be transferred is returned in InTransferLength. For write
1986 and bi-directional commands, OutTransferLength bytes were
1987 transferred by OutDataBuffer.
1988 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1989 SCSI Request Packets already queued. The caller may retry again later.
1990 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request
1992 @retval EFI_INVALID_PARAMETER Target, Lun, or the contents of ScsiRequestPacket are invalid.
1993 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported
1994 by the host adapter. This includes the case of Bi-directional SCSI
1995 commands not supported by the implementation. The SCSI Request
1996 Packet was not sent, so no additional status information is available.
1997 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
2002 ExtScsiPassThruPassThru (
2003 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
2006 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
,
2007 IN EFI_EVENT Event OPTIONAL
2011 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
2013 UINT8 PortMultiplier
;
2014 EFI_ATA_HC_WORK_MODE Mode
;
2016 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
2018 EFI_SCSI_SENSE_DATA
*PtrSenseData
;
2020 EFI_STATUS SenseStatus
;
2023 Instance
= EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
2025 if ((Packet
== NULL
) || (Packet
->Cdb
== NULL
)) {
2026 return EFI_INVALID_PARAMETER
;
2030 // Don't support variable length CDB
2032 if ((Packet
->CdbLength
!= 6) && (Packet
->CdbLength
!= 10) &&
2033 (Packet
->CdbLength
!= 12) && (Packet
->CdbLength
!= 16))
2035 return EFI_INVALID_PARAMETER
;
2038 if ((Packet
->SenseDataLength
!= 0) && (Packet
->SenseData
== NULL
)) {
2039 return EFI_INVALID_PARAMETER
;
2042 if ((This
->Mode
->IoAlign
> 1) && !IS_ALIGNED (Packet
->InDataBuffer
, This
->Mode
->IoAlign
)) {
2043 return EFI_INVALID_PARAMETER
;
2046 if ((This
->Mode
->IoAlign
> 1) && !IS_ALIGNED (Packet
->OutDataBuffer
, This
->Mode
->IoAlign
)) {
2047 return EFI_INVALID_PARAMETER
;
2050 if ((This
->Mode
->IoAlign
> 1) && !IS_ALIGNED (Packet
->SenseData
, This
->Mode
->IoAlign
)) {
2051 return EFI_INVALID_PARAMETER
;
2055 // For ATAPI device, doesn't support multiple LUN device.
2058 return EFI_INVALID_PARAMETER
;
2062 // The layout of Target array:
2063 // ________________________________________________________________________
2064 // | Byte 0 | Byte 1 | ... | TARGET_MAX_BYTES - 1 |
2065 // |_____________________|_____________________|_____|______________________|
2066 // | | The port multiplier | | |
2067 // | The port number | port number | N/A | N/A |
2068 // |_____________________|_____________________|_____|______________________|
2070 // For ATAPI device, 2 bytes is enough to represent the location of SCSI device.
2073 PortMultiplier
= Target
[1];
2075 Node
= SearchDeviceInfoList (Instance
, Port
, PortMultiplier
, EfiIdeCdrom
);
2077 return EFI_INVALID_PARAMETER
;
2080 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
2083 // ATA_CMD_IDENTIFY_DEVICE cmd is a ATA cmd but not a SCSI cmd.
2084 // Normally it should NOT be passed down through ExtScsiPassThru protocol interface.
2085 // But to response EFI_DISK_INFO.Identify() request from ScsiDisk, we should handle this command.
2087 if (*((UINT8
*)Packet
->Cdb
) == ATA_CMD_IDENTIFY_DEVICE
) {
2088 CopyMem (Packet
->InDataBuffer
, DeviceInfo
->IdentifyData
, sizeof (EFI_IDENTIFY_DATA
));
2090 // For IDENTIFY DEVICE cmd, we don't need to get sense data.
2092 Packet
->SenseDataLength
= 0;
2096 Mode
= Instance
->Mode
;
2100 // Reassign IDE mode io port registers' base addresses
2102 Status
= GetIdeRegisterIoAddr (Instance
->PciIo
, Instance
->IdeRegisters
);
2104 if (EFI_ERROR (Status
)) {
2108 Status
= AtaPacketCommandExecute (Instance
->PciIo
, &Instance
->IdeRegisters
[Port
], Port
, PortMultiplier
, Packet
);
2110 case EfiAtaAhciMode
:
2111 if (PortMultiplier
== 0xFF) {
2113 // If there is no port multiplier, the PortMultiplier will be 0xFF
2114 // Here, we convert its value to 0 to follow the AHCI spec.
2119 Status
= AhciPacketCommandExecute (Instance
->PciIo
, &Instance
->AhciRegisters
, Port
, PortMultiplier
, Packet
);
2122 Status
= EFI_DEVICE_ERROR
;
2127 // If the cmd doesn't get executed correctly, then check sense data.
2129 if (EFI_ERROR (Status
) && (Packet
->SenseDataLength
!= 0) && (*((UINT8
*)Packet
->Cdb
) != ATA_CMD_REQUEST_SENSE
)) {
2130 PtrSenseData
= AllocateAlignedPages (EFI_SIZE_TO_PAGES (sizeof (EFI_SCSI_SENSE_DATA
)), This
->Mode
->IoAlign
);
2131 if (PtrSenseData
== NULL
) {
2132 return EFI_DEVICE_ERROR
;
2135 for (SenseReq
= TRUE
; SenseReq
;) {
2136 SenseStatus
= AtaPacketRequestSense (
2141 sizeof (EFI_SCSI_SENSE_DATA
),
2144 if (EFI_ERROR (SenseStatus
)) {
2148 CopyMem ((UINT8
*)Packet
->SenseData
+ SenseDataLen
, PtrSenseData
, sizeof (EFI_SCSI_SENSE_DATA
));
2149 SenseDataLen
+= sizeof (EFI_SCSI_SENSE_DATA
);
2152 // no more sense key or number of sense keys exceeds predefined,
2155 if ((PtrSenseData
->Sense_Key
== EFI_SCSI_SK_NO_SENSE
) ||
2156 (SenseDataLen
+ sizeof (EFI_SCSI_SENSE_DATA
) > Packet
->SenseDataLength
))
2162 FreeAlignedPages (PtrSenseData
, EFI_SIZE_TO_PAGES (sizeof (EFI_SCSI_SENSE_DATA
)));
2166 // Update the SenseDataLength field to the data length received.
2168 Packet
->SenseDataLength
= (UINT8
)SenseDataLen
;
2173 Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These
2174 can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal
2175 Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the
2176 Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI
2179 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2180 @param Target On input, a pointer to the Target ID (an array of size
2181 TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
2182 On output, a pointer to the Target ID (an array of
2183 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
2184 channel. An input value of 0xF(all bytes in the array are 0xF) in the
2185 Target array retrieves the Target ID of the first SCSI device present on a
2187 @param Lun On input, a pointer to the LUN of a SCSI device present on the SCSI
2188 channel. On output, a pointer to the LUN of the next SCSI device present
2191 @retval EFI_SUCCESS The Target ID and LUN of the next SCSI device on the SCSI
2192 channel was returned in Target and Lun.
2193 @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were
2194 not returned on a previous call to GetNextTargetLun().
2195 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.
2200 ExtScsiPassThruGetNextTargetLun (
2201 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
2202 IN OUT UINT8
**Target
,
2206 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
2208 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
2212 Instance
= EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
2214 if ((Target
== NULL
) || (Lun
== NULL
)) {
2215 return EFI_INVALID_PARAMETER
;
2218 if (*Target
== NULL
) {
2219 return EFI_INVALID_PARAMETER
;
2223 Target16
= (UINT16
*)*Target
;
2225 if (CompareMem (Target8
, mScsiId
, TARGET_MAX_BYTES
) != 0) {
2227 // For ATAPI device, we use 2 least significant bytes to represent the location of SCSI device.
2228 // So the higher bytes in Target array should be 0xFF.
2230 if (CompareMem (&Target8
[2], &mScsiId
[2], TARGET_MAX_BYTES
- 2) != 0) {
2231 return EFI_INVALID_PARAMETER
;
2235 // When Target is not all 0xFF's, compare 2 least significant bytes with
2236 // previous target id to see if it is returned by previous call.
2238 if ((*Target16
!= Instance
->PreviousTargetId
) ||
2239 (*Lun
!= Instance
->PreviousLun
))
2241 return EFI_INVALID_PARAMETER
;
2245 // Traverse the whole device list to find the next cdrom closed to
2246 // the device signified by Target[0] and Target[1].
2248 // Note that we here use a tricky way to find the next cdrom :
2249 // All ata devices are detected and inserted into the device list
2252 Node
= GetFirstNode (&Instance
->DeviceList
);
2254 while (!IsNull (&Instance
->DeviceList
, Node
)) {
2255 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
2257 if ((DeviceInfo
->Type
== EfiIdeCdrom
) &&
2258 ((Target8
[0] < DeviceInfo
->Port
) ||
2259 ((Target8
[0] == DeviceInfo
->Port
) &&
2260 (Target8
[1] < (UINT8
)DeviceInfo
->PortMultiplier
))))
2262 Target8
[0] = (UINT8
)DeviceInfo
->Port
;
2263 Target8
[1] = (UINT8
)DeviceInfo
->PortMultiplier
;
2267 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
2270 return EFI_NOT_FOUND
;
2273 // If the array is all 0xFF's, start to traverse the device list from the beginning
2275 Node
= GetFirstNode (&Instance
->DeviceList
);
2276 while (!IsNull (&Instance
->DeviceList
, Node
)) {
2277 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
2279 if (DeviceInfo
->Type
== EfiIdeCdrom
) {
2280 Target8
[0] = (UINT8
)DeviceInfo
->Port
;
2281 Target8
[1] = (UINT8
)DeviceInfo
->PortMultiplier
;
2285 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
2288 return EFI_NOT_FOUND
;
2295 // Update the PreviousTargetId.
2297 Instance
->PreviousTargetId
= *Target16
;
2298 Instance
->PreviousLun
= *Lun
;
2304 Used to allocate and build a device path node for a SCSI device on a SCSI channel.
2306 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2307 @param Target The Target is an array of size TARGET_MAX_BYTES and it specifies the
2308 Target ID of the SCSI device for which a device path node is to be
2309 allocated and built. Transport drivers may chose to utilize a subset of
2310 this size to suit the representation of targets. For example, a Fibre
2311 Channel driver may use only 8 bytes (WWN) in the array to represent a
2313 @param Lun The LUN of the SCSI device for which a device path node is to be
2314 allocated and built.
2315 @param DevicePath A pointer to a single device path node that describes the SCSI device
2316 specified by Target and Lun. This function is responsible for
2317 allocating the buffer DevicePath with the boot service
2318 AllocatePool(). It is the caller's responsibility to free
2319 DevicePath when the caller is finished with DevicePath.
2321 @retval EFI_SUCCESS The device path node that describes the SCSI device specified by
2322 Target and Lun was allocated and returned in
2324 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
2325 @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist
2326 on the SCSI channel.
2327 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
2332 ExtScsiPassThruBuildDevicePath (
2333 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
2336 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
2339 EFI_DEV_PATH
*DevicePathNode
;
2340 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
2342 UINT8 PortMultiplier
;
2344 Instance
= EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
2347 PortMultiplier
= Target
[1];
2350 // Validate parameters passed in.
2352 if (DevicePath
== NULL
) {
2353 return EFI_INVALID_PARAMETER
;
2357 // can not build device path for the SCSI Host Controller.
2360 return EFI_NOT_FOUND
;
2363 if (SearchDeviceInfoList (Instance
, Port
, PortMultiplier
, EfiIdeCdrom
) == NULL
) {
2364 return EFI_NOT_FOUND
;
2367 if (Instance
->Mode
== EfiAtaIdeMode
) {
2368 DevicePathNode
= AllocateCopyPool (sizeof (ATAPI_DEVICE_PATH
), &mAtapiDevicePathTemplate
);
2369 if (DevicePathNode
== NULL
) {
2370 return EFI_OUT_OF_RESOURCES
;
2373 DevicePathNode
->Atapi
.PrimarySecondary
= Port
;
2374 DevicePathNode
->Atapi
.SlaveMaster
= PortMultiplier
;
2375 DevicePathNode
->Atapi
.Lun
= (UINT16
)Lun
;
2377 DevicePathNode
= AllocateCopyPool (sizeof (SATA_DEVICE_PATH
), &mSataDevicePathTemplate
);
2378 if (DevicePathNode
== NULL
) {
2379 return EFI_OUT_OF_RESOURCES
;
2382 DevicePathNode
->Sata
.HBAPortNumber
= Port
;
2384 // For CD-ROM working in the AHCI mode, only 8 bits are used to record
2385 // the PortMultiplier information. If the CD-ROM is directly attached
2386 // on a SATA port, the PortMultiplier should be translated from 0xFF
2387 // to 0xFFFF according to the UEFI spec.
2389 DevicePathNode
->Sata
.PortMultiplierPortNumber
= PortMultiplier
== 0xFF ? 0xFFFF : PortMultiplier
;
2390 DevicePathNode
->Sata
.Lun
= (UINT16
)Lun
;
2393 *DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)DevicePathNode
;
2399 Used to translate a device path node to a Target ID and LUN.
2401 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2402 @param DevicePath A pointer to a single device path node that describes the SCSI device
2403 on the SCSI channel.
2404 @param Target A pointer to the Target Array which represents the ID of a SCSI device
2405 on the SCSI channel.
2406 @param Lun A pointer to the LUN of a SCSI device on the SCSI channel.
2408 @retval EFI_SUCCESS DevicePath was successfully translated to a Target ID and
2409 LUN, and they were returned in Target and Lun.
2410 @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL.
2411 @retval EFI_NOT_FOUND A valid translation from DevicePath to a Target ID and LUN
2413 @retval EFI_UNSUPPORTED This driver does not support the device path node type in
2419 ExtScsiPassThruGetTargetLun (
2420 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
2421 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
2426 EFI_DEV_PATH
*DevicePathNode
;
2427 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
2430 Instance
= EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
2433 // Validate parameters passed in.
2435 if ((DevicePath
== NULL
) || (Target
== NULL
) || (Lun
== NULL
)) {
2436 return EFI_INVALID_PARAMETER
;
2439 if (*Target
== NULL
) {
2440 return EFI_INVALID_PARAMETER
;
2444 // Check whether the DevicePath belongs to SCSI_DEVICE_PATH
2446 if ((DevicePath
->Type
!= MESSAGING_DEVICE_PATH
) ||
2447 ((DevicePath
->SubType
!= MSG_ATAPI_DP
) &&
2448 (DevicePath
->SubType
!= MSG_SATA_DP
)) ||
2449 ((DevicePathNodeLength (DevicePath
) != sizeof (ATAPI_DEVICE_PATH
)) &&
2450 (DevicePathNodeLength (DevicePath
) != sizeof (SATA_DEVICE_PATH
))))
2452 return EFI_UNSUPPORTED
;
2455 SetMem (*Target
, TARGET_MAX_BYTES
, 0xFF);
2457 DevicePathNode
= (EFI_DEV_PATH
*)DevicePath
;
2459 if (Instance
->Mode
== EfiAtaIdeMode
) {
2460 (*Target
)[0] = (UINT8
)DevicePathNode
->Atapi
.PrimarySecondary
;
2461 (*Target
)[1] = (UINT8
)DevicePathNode
->Atapi
.SlaveMaster
;
2462 *Lun
= (UINT8
)DevicePathNode
->Atapi
.Lun
;
2464 (*Target
)[0] = (UINT8
)DevicePathNode
->Sata
.HBAPortNumber
;
2465 (*Target
)[1] = (UINT8
)DevicePathNode
->Sata
.PortMultiplierPortNumber
;
2466 *Lun
= (UINT8
)DevicePathNode
->Sata
.Lun
;
2469 Node
= SearchDeviceInfoList (Instance
, (*Target
)[0], (*Target
)[1], EfiIdeCdrom
);
2472 return EFI_NOT_FOUND
;
2476 return EFI_NOT_FOUND
;
2483 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.
2485 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2487 @retval EFI_SUCCESS The SCSI channel was reset.
2488 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.
2489 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI channel.
2490 @retval EFI_UNSUPPORTED The SCSI channel does not support a channel reset operation.
2495 ExtScsiPassThruResetChannel (
2496 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
2500 // Return success directly then upper layer driver could think reset channel operation is done.
2506 Resets a SCSI logical unit that is connected to a SCSI channel.
2508 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2509 @param Target The Target is an array of size TARGET_MAX_BYTE and it represents the
2510 target port ID of the SCSI device containing the SCSI logical unit to
2511 reset. Transport drivers may chose to utilize a subset of this array to suit
2512 the representation of their targets.
2513 @param Lun The LUN of the SCSI device to reset.
2515 @retval EFI_SUCCESS The SCSI device specified by Target and Lun was reset.
2516 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
2517 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI device
2518 specified by Target and Lun.
2519 @retval EFI_UNSUPPORTED The SCSI channel does not support a target reset operation.
2520 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI device
2521 specified by Target and Lun.
2526 ExtScsiPassThruResetTargetLun (
2527 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
2532 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
2535 UINT8 PortMultiplier
;
2537 Instance
= EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
2539 // For ATAPI device, doesn't support multiple LUN device.
2542 return EFI_INVALID_PARAMETER
;
2546 // The layout of Target array:
2547 // ________________________________________________________________________
2548 // | Byte 0 | Byte 1 | ... | TARGET_MAX_BYTES - 1 |
2549 // |_____________________|_____________________|_____|______________________|
2550 // | | The port multiplier | | |
2551 // | The port number | port number | N/A | N/A |
2552 // |_____________________|_____________________|_____|______________________|
2554 // For ATAPI device, 2 bytes is enough to represent the location of SCSI device.
2557 PortMultiplier
= Target
[1];
2559 Node
= SearchDeviceInfoList (Instance
, Port
, PortMultiplier
, EfiIdeCdrom
);
2561 return EFI_INVALID_PARAMETER
;
2565 // Return success directly then upper layer driver could think reset target LUN operation is done.
2571 Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either
2572 be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs
2573 for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to
2574 see if a SCSI device is actually present at that location on the SCSI channel.
2576 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2577 @param Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
2578 On output, a pointer to the Target ID (an array of
2579 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
2580 channel. An input value of 0xF(all bytes in the array are 0xF) in the
2581 Target array retrieves the Target ID of the first SCSI device present on a
2584 @retval EFI_SUCCESS The Target ID of the next SCSI device on the SCSI
2585 channel was returned in Target.
2586 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
2587 @retval EFI_TIMEOUT Target array is not all 0xF, and Target was not
2588 returned on a previous call to GetNextTarget().
2589 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.
2594 ExtScsiPassThruGetNextTarget (
2595 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
2596 IN OUT UINT8
**Target
2599 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
2601 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
2605 Instance
= EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
2607 if ((Target
== NULL
) || (*Target
== NULL
)) {
2608 return EFI_INVALID_PARAMETER
;
2612 Target16
= (UINT16
*)*Target
;
2614 if (CompareMem (Target8
, mScsiId
, TARGET_MAX_BYTES
) != 0) {
2616 // For ATAPI device, we use 2 least significant bytes to represent the location of SCSI device.
2617 // So the higher bytes in Target array should be 0xFF.
2619 if (CompareMem (&Target8
[2], &mScsiId
[2], TARGET_MAX_BYTES
- 2) != 0) {
2620 return EFI_INVALID_PARAMETER
;
2624 // When Target is not all 0xFF's, compare 2 least significant bytes with
2625 // previous target id to see if it is returned by previous call.
2627 if (*Target16
!= Instance
->PreviousTargetId
) {
2628 return EFI_INVALID_PARAMETER
;
2632 // Traverse the whole device list to find the next cdrom closed to
2633 // the device signified by Target[0] and Target[1].
2635 // Note that we here use a tricky way to find the next cdrom :
2636 // All ata devices are detected and inserted into the device list
2639 Node
= GetFirstNode (&Instance
->DeviceList
);
2640 while (!IsNull (&Instance
->DeviceList
, Node
)) {
2641 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
2643 if ((DeviceInfo
->Type
== EfiIdeCdrom
) &&
2644 ((Target8
[0] < DeviceInfo
->Port
) ||
2645 ((Target8
[0] == DeviceInfo
->Port
) &&
2646 (Target8
[1] < (UINT8
)DeviceInfo
->PortMultiplier
))))
2648 Target8
[0] = (UINT8
)DeviceInfo
->Port
;
2649 Target8
[1] = (UINT8
)DeviceInfo
->PortMultiplier
;
2653 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
2656 return EFI_NOT_FOUND
;
2659 // If the array is all 0xFF's, start to traverse the device list from the beginning
2661 Node
= GetFirstNode (&Instance
->DeviceList
);
2663 while (!IsNull (&Instance
->DeviceList
, Node
)) {
2664 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
2666 if (DeviceInfo
->Type
== EfiIdeCdrom
) {
2667 Target8
[0] = (UINT8
)DeviceInfo
->Port
;
2668 Target8
[1] = (UINT8
)DeviceInfo
->PortMultiplier
;
2672 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
2675 return EFI_NOT_FOUND
;
2680 // Update the PreviousTargetId.
2682 Instance
->PreviousTargetId
= *Target16
;