2 This file implements ATA_PASSTHRU_PROCTOCOL and EXT_SCSI_PASSTHRU_PROTOCOL interfaces
3 for managed ATA controllers.
5 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "AtaAtapiPassThru.h"
19 // EFI_DRIVER_BINDING_PROTOCOL instance
21 EFI_DRIVER_BINDING_PROTOCOL gAtaAtapiPassThruDriverBinding
= {
22 AtaAtapiPassThruSupported
,
23 AtaAtapiPassThruStart
,
30 ATA_ATAPI_PASS_THRU_INSTANCE gAtaAtapiPassThruInstanceTemplate
= {
31 ATA_ATAPI_PASS_THRU_SIGNATURE
,
32 0, // Controller Handle
33 NULL
, // PciIo Protocol
34 NULL
, // IdeControllerInit Protocol
37 // According to UEFI2.3 spec Section 12.10, Drivers for non-RAID ATA controllers should set
38 // both EFI_ATA_PASS_THRU_ATTRIBUTES_PHYSICAL and EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL
40 // Note that the driver doesn't support AtaPassThru non blocking I/O.
42 EFI_ATA_PASS_THRU_ATTRIBUTES_PHYSICAL
| EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL
,
51 AtaPassThruGetNextPort
,
52 AtaPassThruGetNextDevice
,
53 AtaPassThruBuildDevicePath
,
56 AtaPassThruResetDevice
58 { // ExtScsiPassThruMode
64 // According to UEFI2.3 spec Section 14.7, Drivers for non-RAID SCSI controllers should set
65 // both EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL and EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL
67 // Note that the driver doesn't support ExtScsiPassThru non blocking I/O.
69 EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL
| EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL
,
77 ExtScsiPassThruPassThru
,
78 ExtScsiPassThruGetNextTargetLun
,
79 ExtScsiPassThruBuildDevicePath
,
80 ExtScsiPassThruGetTargetLun
,
81 ExtScsiPassThruResetChannel
,
82 ExtScsiPassThruResetTargetLun
,
83 ExtScsiPassThruGetNextTarget
85 EfiAtaUnknownMode
, // Work Mode
97 0, // OriginalAttributes
99 0, // PreviousPortMultiplier
100 0, // PreviousTargetId
104 ATAPI_DEVICE_PATH mAtapiDevicePathTemplate
= {
106 MESSAGING_DEVICE_PATH
,
108 (UINT8
) (sizeof (ATAPI_DEVICE_PATH
)),
109 (UINT8
) ((sizeof (ATAPI_DEVICE_PATH
)) >> 8),
116 SATA_DEVICE_PATH mSataDevicePathTemplate
= {
118 MESSAGING_DEVICE_PATH
,
120 (UINT8
) (sizeof (SATA_DEVICE_PATH
)),
121 (UINT8
) ((sizeof (SATA_DEVICE_PATH
)) >> 8),
128 UINT8 mScsiId
[TARGET_MAX_BYTES
] = {
129 0xFF, 0xFF, 0xFF, 0xFF,
130 0xFF, 0xFF, 0xFF, 0xFF,
131 0xFF, 0xFF, 0xFF, 0xFF,
132 0xFF, 0xFF, 0xFF, 0xFF
136 The Entry Point of module.
138 @param[in] ImageHandle The firmware allocated handle for the EFI image.
139 @param[in] SystemTable A pointer to the EFI System Table.
141 @retval EFI_SUCCESS The entry point is executed successfully.
142 @retval other Some error occurs when executing this entry point.
147 InitializeAtaAtapiPassThru (
148 IN EFI_HANDLE ImageHandle
,
149 IN EFI_SYSTEM_TABLE
*SystemTable
155 // Install driver model protocol(s).
157 Status
= EfiLibInstallDriverBindingComponentName2 (
160 &gAtaAtapiPassThruDriverBinding
,
162 &gAtaAtapiPassThruComponentName
,
163 &gAtaAtapiPassThruComponentName2
165 ASSERT_EFI_ERROR (Status
);
171 Tests to see if this driver supports a given controller. If a child device is provided,
172 it further tests to see if this driver supports creating a handle for the specified child device.
174 This function checks to see if the driver specified by This supports the device specified by
175 ControllerHandle. Drivers will typically use the device path attached to
176 ControllerHandle and/or the services from the bus I/O abstraction attached to
177 ControllerHandle to determine if the driver supports ControllerHandle. This function
178 may be called many times during platform initialization. In order to reduce boot times, the tests
179 performed by this function must be very small, and take as little time as possible to execute. This
180 function must not change the state of any hardware devices, and this function must be aware that the
181 device specified by ControllerHandle may already be managed by the same driver or a
182 different driver. This function must match its calls to AllocatePages() with FreePages(),
183 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
184 Because ControllerHandle may have been previously started by the same driver, if a protocol is
185 already in the opened state, then it must not be closed with CloseProtocol(). This is required
186 to guarantee the state of ControllerHandle is not modified by this function.
188 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
189 @param[in] ControllerHandle The handle of the controller to test. This handle
190 must support a protocol interface that supplies
191 an I/O abstraction to the driver.
192 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
193 parameter is ignored by device drivers, and is optional for bus
194 drivers. For bus drivers, if this parameter is not NULL, then
195 the bus driver must determine if the bus controller specified
196 by ControllerHandle and the child controller specified
197 by RemainingDevicePath are both supported by this
200 @retval EFI_SUCCESS The device specified by ControllerHandle and
201 RemainingDevicePath is supported by the driver specified by This.
202 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
203 RemainingDevicePath is already being managed by the driver
205 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
206 RemainingDevicePath is already being managed by a different
207 driver or an application that requires exclusive access.
208 Currently not implemented.
209 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
210 RemainingDevicePath is not supported by the driver specified by This.
214 AtaAtapiPassThruSupported (
215 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
216 IN EFI_HANDLE Controller
,
217 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
221 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
222 EFI_PCI_IO_PROTOCOL
*PciIo
;
224 EFI_IDE_CONTROLLER_INIT_PROTOCOL
*IdeControllerInit
;
227 // SATA Controller is a device driver, and should ingore the
228 // "RemainingDevicePath" according to UEFI spec
230 Status
= gBS
->OpenProtocol (
232 &gEfiDevicePathProtocolGuid
,
233 (VOID
*) &ParentDevicePath
,
234 This
->DriverBindingHandle
,
236 EFI_OPEN_PROTOCOL_BY_DRIVER
238 if (EFI_ERROR (Status
)) {
240 // EFI_ALREADY_STARTED is also an error
245 // Close the protocol because we don't use it here
249 &gEfiDevicePathProtocolGuid
,
250 This
->DriverBindingHandle
,
254 Status
= gBS
->OpenProtocol (
256 &gEfiIdeControllerInitProtocolGuid
,
257 (VOID
**) &IdeControllerInit
,
258 This
->DriverBindingHandle
,
260 EFI_OPEN_PROTOCOL_BY_DRIVER
263 if (EFI_ERROR (Status
)) {
265 // EFI_ALREADY_STARTED is also an error
271 // Close the I/O Abstraction(s) used to perform the supported test
275 &gEfiIdeControllerInitProtocolGuid
,
276 This
->DriverBindingHandle
,
281 // Now test the EfiPciIoProtocol
283 Status
= gBS
->OpenProtocol (
285 &gEfiPciIoProtocolGuid
,
287 This
->DriverBindingHandle
,
289 EFI_OPEN_PROTOCOL_GET_PROTOCOL
291 if (EFI_ERROR (Status
)) {
295 // Now further check the PCI header: Base class (offset 0x0B) and
296 // Sub Class (offset 0x0A). This controller should be an ATA controller
298 Status
= PciIo
->Pci
.Read (
301 PCI_CLASSCODE_OFFSET
,
302 sizeof (PciData
.Hdr
.ClassCode
),
303 PciData
.Hdr
.ClassCode
305 if (EFI_ERROR (Status
)) {
306 return EFI_UNSUPPORTED
;
309 if (IS_PCI_IDE (&PciData
) || IS_PCI_SATADPA (&PciData
)) {
313 return EFI_UNSUPPORTED
;
317 Starts a device controller or a bus controller.
319 The Start() function is designed to be invoked from the EFI boot service ConnectController().
320 As a result, much of the error checking on the parameters to Start() has been moved into this
321 common boot service. It is legal to call Start() from other locations,
322 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
323 1. ControllerHandle must be a valid EFI_HANDLE.
324 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
325 EFI_DEVICE_PATH_PROTOCOL.
326 3. Prior to calling Start(), the Supported() function for the driver specified by This must
327 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
329 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
330 @param[in] ControllerHandle The handle of the controller to start. This handle
331 must support a protocol interface that supplies
332 an I/O abstraction to the driver.
333 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
334 parameter is ignored by device drivers, and is optional for bus
335 drivers. For a bus driver, if this parameter is NULL, then handles
336 for all the children of Controller are created by this driver.
337 If this parameter is not NULL and the first Device Path Node is
338 not the End of Device Path Node, then only the handle for the
339 child device specified by the first Device Path Node of
340 RemainingDevicePath is created by this driver.
341 If the first Device Path Node of RemainingDevicePath is
342 the End of Device Path Node, no child handle is created by this
345 @retval EFI_SUCCESS The device was started.
346 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
347 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
348 @retval Others The driver failded to start the device.
353 AtaAtapiPassThruStart (
354 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
355 IN EFI_HANDLE Controller
,
356 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
360 EFI_IDE_CONTROLLER_INIT_PROTOCOL
*IdeControllerInit
;
361 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
362 EFI_PCI_IO_PROTOCOL
*PciIo
;
364 BOOLEAN PciAttributesSaved
;
365 UINT64 OriginalPciAttributes
;
367 Status
= EFI_SUCCESS
;
368 IdeControllerInit
= NULL
;
370 PciAttributesSaved
= FALSE
;
371 OriginalPciAttributes
= 0;
373 DEBUG ((EFI_D_INFO
, "==AtaAtapiPassThru Start== Controller = %x\n", Controller
));
375 Status
= gBS
->OpenProtocol (
377 &gEfiIdeControllerInitProtocolGuid
,
378 (VOID
**) &IdeControllerInit
,
379 This
->DriverBindingHandle
,
381 EFI_OPEN_PROTOCOL_BY_DRIVER
384 if (EFI_ERROR (Status
)) {
385 DEBUG ((EFI_D_ERROR
, "Open Ide_Controller_Init Error, Status=%r", Status
));
389 Status
= gBS
->OpenProtocol (
391 &gEfiPciIoProtocolGuid
,
393 This
->DriverBindingHandle
,
395 EFI_OPEN_PROTOCOL_GET_PROTOCOL
397 if (EFI_ERROR (Status
)) {
398 DEBUG ((EFI_D_ERROR
, "Get Pci_Io Protocol Error, Status=%r", Status
));
402 Status
= PciIo
->Attributes (
404 EfiPciIoAttributeOperationGet
,
406 &OriginalPciAttributes
409 if (EFI_ERROR (Status
)) {
412 PciAttributesSaved
= TRUE
;
414 Status
= PciIo
->Attributes (
416 EfiPciIoAttributeOperationSupported
,
420 if (!EFI_ERROR (Status
)) {
421 Supports
&= EFI_PCI_DEVICE_ENABLE
;
422 Status
= PciIo
->Attributes (
424 EfiPciIoAttributeOperationEnable
,
430 if (EFI_ERROR (Status
)) {
435 // Allocate a buffer to store the ATA_ATAPI_PASS_THRU_INSTANCE data structure
437 Instance
= AllocateCopyPool (sizeof (ATA_ATAPI_PASS_THRU_INSTANCE
), &gAtaAtapiPassThruInstanceTemplate
);
438 if (Instance
== NULL
) {
442 Instance
->ControllerHandle
= Controller
;
443 Instance
->IdeControllerInit
= IdeControllerInit
;
444 Instance
->PciIo
= PciIo
;
445 Instance
->OriginalPciAttributes
= OriginalPciAttributes
;
446 Instance
->AtaPassThru
.Mode
= &Instance
->AtaPassThruMode
;
447 Instance
->ExtScsiPassThru
.Mode
= &Instance
->ExtScsiPassThruMode
;
448 InitializeListHead(&Instance
->DeviceList
);
451 // Enumerate all inserted ATA devices.
453 Status
= EnumerateAttachedDevice (Instance
);
454 if (EFI_ERROR (Status
)) {
458 Status
= gBS
->InstallMultipleProtocolInterfaces (
460 &gEfiAtaPassThruProtocolGuid
, &(Instance
->AtaPassThru
),
461 &gEfiExtScsiPassThruProtocolGuid
, &(Instance
->ExtScsiPassThru
),
464 ASSERT_EFI_ERROR (Status
);
469 if (IdeControllerInit
!= NULL
) {
472 &gEfiIdeControllerInitProtocolGuid
,
473 This
->DriverBindingHandle
,
479 // Remove all inserted ATA devices.
481 DestroyDeviceInfoList(Instance
);
483 if (Instance
!= NULL
) {
486 return EFI_UNSUPPORTED
;
490 Stops a device controller or a bus controller.
492 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
493 As a result, much of the error checking on the parameters to Stop() has been moved
494 into this common boot service. It is legal to call Stop() from other locations,
495 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
496 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
497 same driver's Start() function.
498 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
499 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
500 Start() function, and the Start() function must have called OpenProtocol() on
501 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
503 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
504 @param[in] ControllerHandle A handle to the device being stopped. The handle must
505 support a bus specific I/O protocol for the driver
506 to use to stop the device.
507 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
508 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
509 if NumberOfChildren is 0.
511 @retval EFI_SUCCESS The device was stopped.
512 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
517 AtaAtapiPassThruStop (
518 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
519 IN EFI_HANDLE Controller
,
520 IN UINTN NumberOfChildren
,
521 IN EFI_HANDLE
*ChildHandleBuffer
525 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
526 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
527 EFI_PCI_IO_PROTOCOL
*PciIo
;
528 EFI_AHCI_REGISTERS
*AhciRegisters
;
531 DEBUG ((EFI_D_INFO
, "==AtaAtapiPassThru Stop== Controller = %x\n", Controller
));
533 Status
= gBS
->OpenProtocol (
535 &gEfiAtaPassThruProtocolGuid
,
536 (VOID
**) &AtaPassThru
,
537 This
->DriverBindingHandle
,
539 EFI_OPEN_PROTOCOL_GET_PROTOCOL
542 if (EFI_ERROR (Status
)) {
543 return EFI_DEVICE_ERROR
;
546 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS(AtaPassThru
);
547 PciIo
= Instance
->PciIo
;
550 // Disable this ATA host controller.
552 Status
= PciIo
->Attributes (
554 EfiPciIoAttributeOperationSupported
,
558 if (!EFI_ERROR (Status
)) {
559 Supports
&= EFI_PCI_DEVICE_ENABLE
;
562 EfiPciIoAttributeOperationDisable
,
569 // Restore original PCI attributes
571 Status
= PciIo
->Attributes (
573 EfiPciIoAttributeOperationSet
,
574 Instance
->OriginalPciAttributes
,
577 ASSERT_EFI_ERROR (Status
);
579 gBS
->UninstallMultipleProtocolInterfaces (
581 &gEfiAtaPassThruProtocolGuid
, &(Instance
->AtaPassThru
),
582 &gEfiExtScsiPassThruProtocolGuid
, &(Instance
->ExtScsiPassThru
),
587 // Close protocols opened by AtaAtapiPassThru controller driver
591 &gEfiIdeControllerInitProtocolGuid
,
592 This
->DriverBindingHandle
,
597 // Free allocated resource
599 DestroyDeviceInfoList(Instance
);
602 // If the current working mode is AHCI mode, then pre-allocated resource
603 // for AHCI initialization should be released.
605 if (Instance
->Mode
== EfiAtaAhciMode
) {
606 AhciRegisters
= &Instance
->AhciRegisters
;
609 AhciRegisters
->MapCommandTable
613 (UINTN
) EFI_SIZE_TO_PAGES (AhciRegisters
->MaxCommandTableSize
),
614 AhciRegisters
->AhciCommandTable
618 AhciRegisters
->MapCmdList
622 (UINTN
) EFI_SIZE_TO_PAGES (AhciRegisters
->MaxCommandListSize
),
623 AhciRegisters
->AhciCmdList
627 AhciRegisters
->MapRFis
631 (UINTN
) EFI_SIZE_TO_PAGES (AhciRegisters
->MaxReceiveFisSize
),
632 AhciRegisters
->AhciRFis
641 Traverse the attached ATA devices list to find out the device to access.
643 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
644 @param[in] Port The port number of the ATA device to send the command.
645 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
646 If there is no port multiplier, then specify 0.
647 @param[in] DeviceType The device type of the ATA device.
649 @retval The pointer to the data structure of the device info to access.
654 SearchDeviceInfoList (
655 IN ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
,
657 IN UINT16 PortMultiplier
,
658 IN EFI_ATA_DEVICE_TYPE DeviceType
661 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
664 Node
= GetFirstNode (&Instance
->DeviceList
);
665 while (!IsNull (&Instance
->DeviceList
, Node
)) {
666 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
668 if ((DeviceInfo
->Type
== DeviceType
) &&
669 (Port
== DeviceInfo
->Port
) &&
670 (PortMultiplier
== DeviceInfo
->PortMultiplier
)) {
674 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
681 Allocate device info data structure to contain device info.
682 And insert the data structure to the tail of device list for tracing.
684 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
685 @param[in] Port The port number of the ATA device to send the command.
686 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
687 If there is no port multiplier, then specify 0.
688 @param[in] DeviceType The device type of the ATA device.
689 @param[in] IdentifyData The data buffer to store the output of the IDENTIFY cmd.
691 @retval EFI_SUCCESS Successfully insert the ata device to the tail of device list.
692 @retval EFI_OUT_OF_RESOURCES Can not allocate enough resource for use.
697 CreateNewDeviceInfo (
698 IN ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
,
700 IN UINT16 PortMultiplier
,
701 IN EFI_ATA_DEVICE_TYPE DeviceType
,
702 IN EFI_IDENTIFY_DATA
*IdentifyData
705 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
707 DeviceInfo
= AllocateZeroPool (sizeof (EFI_ATA_DEVICE_INFO
));
709 if (DeviceInfo
== NULL
) {
710 return EFI_OUT_OF_RESOURCES
;
713 DeviceInfo
->Signature
= ATA_ATAPI_DEVICE_SIGNATURE
;
714 DeviceInfo
->Port
= Port
;
715 DeviceInfo
->PortMultiplier
= PortMultiplier
;
716 DeviceInfo
->Type
= DeviceType
;
718 if (IdentifyData
!= NULL
) {
719 DeviceInfo
->IdentifyData
= AllocateCopyPool (sizeof (EFI_IDENTIFY_DATA
), IdentifyData
);
720 if (DeviceInfo
->IdentifyData
== NULL
) {
721 FreePool (DeviceInfo
);
722 return EFI_OUT_OF_RESOURCES
;
726 InsertTailList (&Instance
->DeviceList
, &DeviceInfo
->Link
);
732 Destroy all attached ATA devices info.
734 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
739 DestroyDeviceInfoList (
740 IN ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
743 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
746 Node
= GetFirstNode (&Instance
->DeviceList
);
747 while (!IsNull (&Instance
->DeviceList
, Node
)) {
748 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
750 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
752 RemoveEntryList (&DeviceInfo
->Link
);
753 if (DeviceInfo
->IdentifyData
!= NULL
) {
754 FreePool (DeviceInfo
->IdentifyData
);
756 FreePool (DeviceInfo
);
761 Enumerate all attached ATA devices at IDE mode or AHCI mode separately.
763 The function is designed to enumerate all attached ATA devices.
765 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
767 @retval EFI_SUCCESS Successfully enumerate attached ATA devices.
768 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
773 EnumerateAttachedDevice (
774 IN ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
781 Status
= EFI_SUCCESS
;
783 Status
= Instance
->PciIo
->Pci
.Read (
786 PCI_CLASSCODE_OFFSET
,
787 sizeof (PciData
.Hdr
.ClassCode
),
788 PciData
.Hdr
.ClassCode
790 ASSERT_EFI_ERROR (Status
);
792 ClassCode
= PciData
.Hdr
.ClassCode
[1];
795 case PCI_CLASS_MASS_STORAGE_IDE
:
797 // The ATA controller is working at IDE mode
799 Instance
->Mode
= EfiAtaIdeMode
;
801 Status
= IdeModeInitialization (Instance
);
802 if (EFI_ERROR (Status
)) {
803 Status
= EFI_DEVICE_ERROR
;
807 case PCI_CLASS_MASS_STORAGE_SATADPA
:
809 // The ATA controller is working at AHCI mode
811 Instance
->Mode
= EfiAtaAhciMode
;
813 Status
= AhciModeInitialization (Instance
);
815 if (EFI_ERROR (Status
)) {
816 Status
= EFI_DEVICE_ERROR
;
822 Status
= EFI_UNSUPPORTED
;
830 Sends an ATA command to an ATA device that is attached to the ATA controller. This function
831 supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required,
832 and the non-blocking I/O functionality is optional.
834 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
835 @param[in] Port The port number of the ATA device to send the command.
836 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
837 If there is no port multiplier, then specify 0.
838 @param[in, out] Packet A pointer to the ATA command to send to the ATA device specified by Port
839 and PortMultiplierPort.
840 @param[in] Event If non-blocking I/O is not supported then Event is ignored, and blocking
841 I/O is performed. If Event is NULL, then blocking I/O is performed. If
842 Event is not NULL and non blocking I/O is supported, then non-blocking
843 I/O is performed, and Event will be signaled when the ATA command completes.
845 @retval EFI_SUCCESS The ATA command was sent by the host. For bi-directional commands,
846 InTransferLength bytes were transferred from InDataBuffer. For write and
847 bi-directional commands, OutTransferLength bytes were transferred by OutDataBuffer.
848 @retval EFI_BAD_BUFFER_SIZE The ATA command was not executed. The number of bytes that could be transferred
849 is returned in InTransferLength. For write and bi-directional commands,
850 OutTransferLength bytes were transferred by OutDataBuffer.
851 @retval EFI_NOT_READY The ATA command could not be sent because there are too many ATA commands
852 already queued. The caller may retry again later.
853 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the ATA command.
854 @retval EFI_INVALID_PARAMETER Port, PortMultiplierPort, or the contents of Acb are invalid. The ATA
855 command was not sent, so no additional status information is available.
860 AtaPassThruPassThru (
861 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
863 IN UINT16 PortMultiplierPort
,
864 IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET
*Packet
,
865 IN EFI_EVENT Event OPTIONAL
869 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
870 EFI_ATA_PASS_THRU_CMD_PROTOCOL Protocol
;
871 EFI_ATA_HC_WORK_MODE Mode
;
873 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
874 EFI_IDENTIFY_DATA
*IdentifyData
;
876 UINT32 MaxSectorCount
;
878 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
880 if ((This
->Mode
->IoAlign
> 1) && !IS_ALIGNED(Packet
->InDataBuffer
, This
->Mode
->IoAlign
)) {
881 return EFI_INVALID_PARAMETER
;
884 if ((This
->Mode
->IoAlign
> 1) && !IS_ALIGNED(Packet
->OutDataBuffer
, This
->Mode
->IoAlign
)) {
885 return EFI_INVALID_PARAMETER
;
888 if ((This
->Mode
->IoAlign
> 1) && !IS_ALIGNED(Packet
->Asb
, This
->Mode
->IoAlign
)) {
889 return EFI_INVALID_PARAMETER
;
893 // convert the transfer length from sector count to byte.
895 if (((Packet
->Length
& EFI_ATA_PASS_THRU_LENGTH_BYTES
) == 0) &&
896 (Packet
->InTransferLength
!= 0)) {
897 Packet
->InTransferLength
= Packet
->InTransferLength
* 0x200;
901 // convert the transfer length from sector count to byte.
903 if (((Packet
->Length
& EFI_ATA_PASS_THRU_LENGTH_BYTES
) == 0) &&
904 (Packet
->OutTransferLength
!= 0)) {
905 Packet
->OutTransferLength
= Packet
->OutTransferLength
* 0x200;
908 Node
= SearchDeviceInfoList (Instance
, Port
, PortMultiplierPort
, EfiIdeHarddisk
);
911 return EFI_INVALID_PARAMETER
;
915 // Check whether this device needs 48-bit addressing (ATAPI-6 ata device).
916 // Per ATA-6 spec, word83: bit15 is zero and bit14 is one.
917 // If bit10 is one, it means the ata device support 48-bit addressing.
919 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
920 IdentifyData
= DeviceInfo
->IdentifyData
;
921 MaxSectorCount
= 0x100;
922 if ((IdentifyData
->AtaData
.command_set_supported_83
& (BIT10
| BIT15
| BIT14
)) == 0x4400) {
923 Capacity
= *((UINT64
*)IdentifyData
->AtaData
.maximum_lba_for_48bit_addressing
);
924 if (Capacity
> 0xFFFFFFF) {
926 // Capacity exceeds 120GB. 48-bit addressing is really needed
927 // In this case, the max sector count is 0x10000
929 MaxSectorCount
= 0x10000;
934 // If the data buffer described by InDataBuffer/OutDataBuffer and InTransferLength/OutTransferLength
935 // is too big to be transferred in a single command, then no data is transferred and EFI_BAD_BUFFER_SIZE
938 if (((Packet
->InTransferLength
!= 0) && (Packet
->InTransferLength
> MaxSectorCount
* 0x200)) ||
939 ((Packet
->OutTransferLength
!= 0) && (Packet
->OutTransferLength
> MaxSectorCount
* 0x200))) {
940 return EFI_BAD_BUFFER_SIZE
;
943 Status
= EFI_UNSUPPORTED
;
944 Protocol
= Packet
->Protocol
;
946 Mode
= Instance
->Mode
;
950 // Reassign IDE mode io port registers' base addresses
952 Status
= GetIdeRegisterIoAddr (Instance
->PciIo
, Instance
->IdeRegisters
);
954 if (EFI_ERROR (Status
)) {
959 case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA
:
960 Status
= AtaNonDataCommandIn(
962 &Instance
->IdeRegisters
[Port
],
968 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_IN
:
969 Status
= AtaPioDataInOut(
971 &Instance
->IdeRegisters
[Port
],
972 Packet
->InDataBuffer
,
973 Packet
->InTransferLength
,
980 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT
:
981 Status
= AtaPioDataInOut(
983 &Instance
->IdeRegisters
[Port
],
984 Packet
->OutDataBuffer
,
985 Packet
->OutTransferLength
,
992 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_IN
:
993 Status
= AtaUdmaInOut(
995 &Instance
->IdeRegisters
[Port
],
997 Packet
->InDataBuffer
,
998 Packet
->InTransferLength
,
1004 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_OUT
:
1005 Status
= AtaUdmaInOut(
1007 &Instance
->IdeRegisters
[Port
],
1009 Packet
->OutDataBuffer
,
1010 Packet
->OutTransferLength
,
1017 return EFI_UNSUPPORTED
;
1020 case EfiAtaAhciMode
:
1022 case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA
:
1023 Status
= AhciNonDataTransfer(
1025 &Instance
->AhciRegisters
,
1027 (UINT8
)PortMultiplierPort
,
1035 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_IN
:
1036 Status
= AhciPioTransfer(
1038 &Instance
->AhciRegisters
,
1040 (UINT8
)PortMultiplierPort
,
1046 Packet
->InDataBuffer
,
1047 Packet
->InTransferLength
,
1051 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT
:
1052 Status
= AhciPioTransfer(
1054 &Instance
->AhciRegisters
,
1056 (UINT8
)PortMultiplierPort
,
1062 Packet
->OutDataBuffer
,
1063 Packet
->OutTransferLength
,
1067 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_IN
:
1068 Status
= AhciDmaTransfer(
1070 &Instance
->AhciRegisters
,
1072 (UINT8
)PortMultiplierPort
,
1078 Packet
->InDataBuffer
,
1079 Packet
->InTransferLength
,
1083 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_OUT
:
1084 Status
= AhciDmaTransfer(
1086 &Instance
->AhciRegisters
,
1088 (UINT8
)PortMultiplierPort
,
1094 Packet
->OutDataBuffer
,
1095 Packet
->OutTransferLength
,
1100 return EFI_UNSUPPORTED
;
1105 Status
= EFI_DEVICE_ERROR
;
1113 Used to retrieve the list of legal port numbers for ATA devices on an ATA controller.
1114 These can either be the list of ports where ATA devices are actually present or the
1115 list of legal port numbers for the ATA controller. Regardless, the caller of this
1116 function must probe the port number returned to see if an ATA device is actually
1117 present at that location on the ATA controller.
1119 The GetNextPort() function retrieves the port number on an ATA controller. If on input
1120 Port is 0xFFFF, then the port number of the first port on the ATA controller is returned
1121 in Port and EFI_SUCCESS is returned.
1123 If Port is a port number that was returned on a previous call to GetNextPort(), then the
1124 port number of the next port on the ATA controller is returned in Port, and EFI_SUCCESS
1125 is returned. If Port is not 0xFFFF and Port was not returned on a previous call to
1126 GetNextPort(), then EFI_INVALID_PARAMETER is returned.
1128 If Port is the port number of the last port on the ATA controller, then EFI_NOT_FOUND is
1131 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1132 @param[in, out] Port On input, a pointer to the port number on the ATA controller.
1133 On output, a pointer to the next port number on the ATA
1134 controller. An input value of 0xFFFF retrieves the first port
1135 number on the ATA controller.
1137 @retval EFI_SUCCESS The next port number on the ATA controller was returned in Port.
1138 @retval EFI_NOT_FOUND There are no more ports on this ATA controller.
1139 @retval EFI_INVALID_PARAMETER Port is not 0xFFFF and Port was not returned on a previous call
1145 AtaPassThruGetNextPort (
1146 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1150 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1152 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
1154 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1157 return EFI_INVALID_PARAMETER
;
1160 if (*Port
== 0xFFFF) {
1162 // If the Port is all 0xFF's, start to traverse the device list from the beginning
1164 Node
= GetFirstNode (&Instance
->DeviceList
);
1166 while (!IsNull (&Instance
->DeviceList
, Node
)) {
1167 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1169 if (DeviceInfo
->Type
== EfiIdeHarddisk
) {
1170 *Port
= DeviceInfo
->Port
;
1174 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
1177 return EFI_NOT_FOUND
;
1178 } else if (*Port
== Instance
->PreviousPort
) {
1179 Node
= GetFirstNode (&Instance
->DeviceList
);
1181 while (!IsNull (&Instance
->DeviceList
, Node
)) {
1182 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1184 if ((DeviceInfo
->Type
== EfiIdeHarddisk
) &&
1185 (DeviceInfo
->Port
> *Port
)){
1186 *Port
= DeviceInfo
->Port
;
1190 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
1193 return EFI_NOT_FOUND
;
1196 // Port is not equal to 0xFFFF and also not equal to previous return value
1198 return EFI_INVALID_PARAMETER
;
1203 // Update the PreviousPort and PreviousPortMultiplier.
1205 Instance
->PreviousPort
= *Port
;
1211 Used to retrieve the list of legal port multiplier port numbers for ATA devices on a port of an ATA
1212 controller. These can either be the list of port multiplier ports where ATA devices are actually
1213 present on port or the list of legal port multiplier ports on that port. Regardless, the caller of this
1214 function must probe the port number and port multiplier port number returned to see if an ATA
1215 device is actually present.
1217 The GetNextDevice() function retrieves the port multiplier port number of an ATA device
1218 present on a port of an ATA controller.
1220 If PortMultiplierPort points to a port multiplier port number value that was returned on a
1221 previous call to GetNextDevice(), then the port multiplier port number of the next ATA device
1222 on the port of the ATA controller is returned in PortMultiplierPort, and EFI_SUCCESS is
1225 If PortMultiplierPort points to 0xFFFF, then the port multiplier port number of the first
1226 ATA device on port of the ATA controller is returned in PortMultiplierPort and
1227 EFI_SUCCESS is returned.
1229 If PortMultiplierPort is not 0xFFFF and the value pointed to by PortMultiplierPort
1230 was not returned on a previous call to GetNextDevice(), then EFI_INVALID_PARAMETER
1233 If PortMultiplierPort is the port multiplier port number of the last ATA device on the port of
1234 the ATA controller, then EFI_NOT_FOUND is returned.
1236 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1237 @param[in] Port The port number present on the ATA controller.
1238 @param[in, out] PortMultiplierPort On input, a pointer to the port multiplier port number of an
1239 ATA device present on the ATA controller.
1240 If on input a PortMultiplierPort of 0xFFFF is specified,
1241 then the port multiplier port number of the first ATA device
1242 is returned. On output, a pointer to the port multiplier port
1243 number of the next ATA device present on an ATA controller.
1245 @retval EFI_SUCCESS The port multiplier port number of the next ATA device on the port
1246 of the ATA controller was returned in PortMultiplierPort.
1247 @retval EFI_NOT_FOUND There are no more ATA devices on this port of the ATA controller.
1248 @retval EFI_INVALID_PARAMETER PortMultiplierPort is not 0xFFFF, and PortMultiplierPort was not
1249 returned on a previous call to GetNextDevice().
1254 AtaPassThruGetNextDevice (
1255 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1257 IN OUT UINT16
*PortMultiplierPort
1260 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1262 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
1264 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1266 if (PortMultiplierPort
== NULL
) {
1267 return EFI_INVALID_PARAMETER
;
1270 if (*PortMultiplierPort
== 0xFFFF) {
1272 // If the PortMultiplierPort is all 0xFF's, start to traverse the device list from the beginning
1274 Node
= GetFirstNode (&Instance
->DeviceList
);
1276 while (!IsNull (&Instance
->DeviceList
, Node
)) {
1277 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1279 if ((DeviceInfo
->Type
== EfiIdeHarddisk
) &&
1280 (DeviceInfo
->Port
== Port
)){
1281 *PortMultiplierPort
= DeviceInfo
->PortMultiplier
;
1285 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
1288 return EFI_NOT_FOUND
;
1289 } else if (*PortMultiplierPort
== Instance
->PreviousPortMultiplier
) {
1290 Node
= GetFirstNode (&Instance
->DeviceList
);
1292 while (!IsNull (&Instance
->DeviceList
, Node
)) {
1293 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1295 if ((DeviceInfo
->Type
== EfiIdeHarddisk
) &&
1296 (DeviceInfo
->Port
== Port
) &&
1297 (DeviceInfo
->PortMultiplier
> *PortMultiplierPort
)){
1298 *PortMultiplierPort
= DeviceInfo
->PortMultiplier
;
1302 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
1305 return EFI_NOT_FOUND
;
1308 // PortMultiplierPort is not equal to 0xFFFF and also not equal to previous return value
1310 return EFI_INVALID_PARAMETER
;
1315 // Update the PreviousPort and PreviousPortMultiplier.
1317 Instance
->PreviousPortMultiplier
= *PortMultiplierPort
;
1323 Used to allocate and build a device path node for an ATA device on an ATA controller.
1325 The BuildDevicePath() function allocates and builds a single device node for the ATA
1326 device specified by Port and PortMultiplierPort. If the ATA device specified by Port and
1327 PortMultiplierPort is not present on the ATA controller, then EFI_NOT_FOUND is returned.
1328 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned. If there are not enough
1329 resources to allocate the device path node, then EFI_OUT_OF_RESOURCES is returned.
1331 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of
1332 DevicePath are initialized to describe the ATA device specified by Port and PortMultiplierPort,
1333 and EFI_SUCCESS is returned.
1335 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1336 @param[in] Port Port specifies the port number of the ATA device for which a
1337 device path node is to be allocated and built.
1338 @param[in] PortMultiplierPort The port multiplier port number of the ATA device for which a
1339 device path node is to be allocated and built. If there is no
1340 port multiplier, then specify 0.
1341 @param[in, out] DevicePath A pointer to a single device path node that describes the ATA
1342 device specified by Port and PortMultiplierPort. This function
1343 is responsible for allocating the buffer DevicePath with the
1344 boot service AllocatePool(). It is the caller's responsibility
1345 to free DevicePath when the caller is finished with DevicePath.
1346 @retval EFI_SUCCESS The device path node that describes the ATA device specified by
1347 Port and PortMultiplierPort was allocated and returned in DevicePath.
1348 @retval EFI_NOT_FOUND The ATA device specified by Port and PortMultiplierPort does not
1349 exist on the ATA controller.
1350 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
1351 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
1356 AtaPassThruBuildDevicePath (
1357 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1359 IN UINT16 PortMultiplierPort
,
1360 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
1363 EFI_DEV_PATH
*DevicePathNode
;
1364 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1367 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1370 // Validate parameters passed in.
1372 if (DevicePath
== NULL
) {
1373 return EFI_INVALID_PARAMETER
;
1376 Node
= SearchDeviceInfoList(Instance
, Port
, PortMultiplierPort
, EfiIdeHarddisk
);
1378 return EFI_NOT_FOUND
;
1381 if (Instance
->Mode
== EfiAtaIdeMode
) {
1382 DevicePathNode
= AllocateCopyPool (sizeof (ATAPI_DEVICE_PATH
), &mAtapiDevicePathTemplate
);
1383 if (DevicePathNode
== NULL
) {
1384 return EFI_OUT_OF_RESOURCES
;
1386 DevicePathNode
->Atapi
.PrimarySecondary
= (UINT8
) Port
;
1387 DevicePathNode
->Atapi
.SlaveMaster
= (UINT8
) PortMultiplierPort
;
1388 DevicePathNode
->Atapi
.Lun
= 0;
1390 DevicePathNode
= AllocateCopyPool (sizeof (SATA_DEVICE_PATH
), &mSataDevicePathTemplate
);
1391 if (DevicePathNode
== NULL
) {
1392 return EFI_OUT_OF_RESOURCES
;
1395 DevicePathNode
->Sata
.HBAPortNumber
= Port
;
1396 DevicePathNode
->Sata
.PortMultiplierPortNumber
= PortMultiplierPort
;
1397 DevicePathNode
->Sata
.Lun
= 0;
1400 *DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) DevicePathNode
;
1406 Used to translate a device path node to a port number and port multiplier port number.
1408 The GetDevice() function determines the port and port multiplier port number associated with
1409 the ATA device described by DevicePath. If DevicePath is a device path node type that the
1410 ATA Pass Thru driver supports, then the ATA Pass Thru driver will attempt to translate the contents
1411 DevicePath into a port number and port multiplier port number.
1413 If this translation is successful, then that port number and port multiplier port number are returned
1414 in Port and PortMultiplierPort, and EFI_SUCCESS is returned.
1416 If DevicePath, Port, or PortMultiplierPort are NULL, then EFI_INVALID_PARAMETER is returned.
1418 If DevicePath is not a device path node type that the ATA Pass Thru driver supports, then
1419 EFI_UNSUPPORTED is returned.
1421 If DevicePath is a device path node type that the ATA Pass Thru driver supports, but there is not
1422 a valid translation from DevicePath to a port number and port multiplier port number, then
1423 EFI_NOT_FOUND is returned.
1425 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1426 @param[in] DevicePath A pointer to the device path node that describes an ATA device on the
1428 @param[out] Port On return, points to the port number of an ATA device on the ATA controller.
1429 @param[out] PortMultiplierPort On return, points to the port multiplier port number of an ATA device
1430 on the ATA controller.
1432 @retval EFI_SUCCESS DevicePath was successfully translated to a port number and port multiplier
1433 port number, and they were returned in Port and PortMultiplierPort.
1434 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
1435 @retval EFI_INVALID_PARAMETER Port is NULL.
1436 @retval EFI_INVALID_PARAMETER PortMultiplierPort is NULL.
1437 @retval EFI_UNSUPPORTED This driver does not support the device path node type in DevicePath.
1438 @retval EFI_NOT_FOUND A valid translation from DevicePath to a port number and port multiplier
1439 port number does not exist.
1443 AtaPassThruGetDevice (
1444 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1445 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1447 OUT UINT16
*PortMultiplierPort
1450 EFI_DEV_PATH
*DevicePathNode
;
1451 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1454 Instance
= ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1457 // Validate parameters passed in.
1459 if (DevicePath
== NULL
|| Port
== NULL
|| PortMultiplierPort
== NULL
) {
1460 return EFI_INVALID_PARAMETER
;
1464 // Check whether the DevicePath belongs to SCSI_DEVICE_PATH or ATAPI_DEVICE_PATH
1466 if ((DevicePath
->Type
!= MESSAGING_DEVICE_PATH
) ||
1467 ((DevicePath
->SubType
!= MSG_SATA_DP
) &&
1468 (DevicePath
->SubType
!= MSG_ATAPI_DP
)) ||
1469 ((DevicePathNodeLength(DevicePath
) != sizeof(ATAPI_DEVICE_PATH
)) &&
1470 (DevicePathNodeLength(DevicePath
) != sizeof(SATA_DEVICE_PATH
)))) {
1471 return EFI_UNSUPPORTED
;
1474 DevicePathNode
= (EFI_DEV_PATH
*) DevicePath
;
1476 if (Instance
->Mode
== EfiAtaIdeMode
) {
1477 *Port
= DevicePathNode
->Atapi
.PrimarySecondary
;
1478 *PortMultiplierPort
= DevicePathNode
->Atapi
.SlaveMaster
;
1480 *Port
= DevicePathNode
->Sata
.HBAPortNumber
;
1481 *PortMultiplierPort
= DevicePathNode
->Sata
.PortMultiplierPortNumber
;
1484 Node
= SearchDeviceInfoList(Instance
, *Port
, *PortMultiplierPort
, EfiIdeHarddisk
);
1487 return EFI_NOT_FOUND
;
1494 Resets a specific port on the ATA controller. This operation also resets all the ATA devices
1495 connected to the port.
1497 The ResetChannel() function resets an a specific port on an ATA controller. This operation
1498 resets all the ATA devices connected to that port. If this ATA controller does not support
1499 a reset port operation, then EFI_UNSUPPORTED is returned.
1501 If a device error occurs while executing that port reset operation, then EFI_DEVICE_ERROR is
1504 If a timeout occurs during the execution of the port reset operation, then EFI_TIMEOUT is returned.
1506 If the port reset operation is completed, then EFI_SUCCESS is returned.
1508 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1509 @param[in] Port The port number on the ATA controller.
1511 @retval EFI_SUCCESS The ATA controller port was reset.
1512 @retval EFI_UNSUPPORTED The ATA controller does not support a port reset operation.
1513 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the ATA port.
1514 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the ATA port.
1519 AtaPassThruResetPort (
1520 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1524 return EFI_UNSUPPORTED
;
1528 Resets an ATA device that is connected to an ATA controller.
1530 The ResetDevice() function resets the ATA device specified by Port and PortMultiplierPort.
1531 If this ATA controller does not support a device reset operation, then EFI_UNSUPPORTED is
1534 If Port or PortMultiplierPort are not in a valid range for this ATA controller, then
1535 EFI_INVALID_PARAMETER is returned.
1537 If a device error occurs while executing that device reset operation, then EFI_DEVICE_ERROR
1540 If a timeout occurs during the execution of the device reset operation, then EFI_TIMEOUT is
1543 If the device reset operation is completed, then EFI_SUCCESS is returned.
1545 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1546 @param[in] Port Port represents the port number of the ATA device to be reset.
1547 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to reset.
1548 If there is no port multiplier, then specify 0.
1549 @retval EFI_SUCCESS The ATA device specified by Port and PortMultiplierPort was reset.
1550 @retval EFI_UNSUPPORTED The ATA controller does not support a device reset operation.
1551 @retval EFI_INVALID_PARAMETER Port or PortMultiplierPort are invalid.
1552 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the ATA device
1553 specified by Port and PortMultiplierPort.
1554 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the ATA device
1555 specified by Port and PortMultiplierPort.
1560 AtaPassThruResetDevice (
1561 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
1563 IN UINT16 PortMultiplierPort
1566 return EFI_UNSUPPORTED
;
1570 Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function
1571 supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the
1572 nonblocking I/O functionality is optional.
1574 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
1575 @param Target The Target is an array of size TARGET_MAX_BYTES and it represents
1576 the id of the SCSI device to send the SCSI Request Packet. Each
1577 transport driver may choose to utilize a subset of this size to suit the needs
1578 of transport target representation. For example, a Fibre Channel driver
1579 may use only 8 bytes (WWN) to represent an FC target.
1580 @param Lun The LUN of the SCSI device to send the SCSI Request Packet.
1581 @param Packet A pointer to the SCSI Request Packet to send to the SCSI device
1582 specified by Target and Lun.
1583 @param Event If nonblocking I/O is not supported then Event is ignored, and blocking
1584 I/O is performed. If Event is NULL, then blocking I/O is performed. If
1585 Event is not NULL and non blocking I/O is supported, then
1586 nonblocking I/O is performed, and Event will be signaled when the
1587 SCSI Request Packet completes.
1589 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional
1590 commands, InTransferLength bytes were transferred from
1591 InDataBuffer. For write and bi-directional commands,
1592 OutTransferLength bytes were transferred by
1594 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was not executed. The number of bytes that
1595 could be transferred is returned in InTransferLength. For write
1596 and bi-directional commands, OutTransferLength bytes were
1597 transferred by OutDataBuffer.
1598 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1599 SCSI Request Packets already queued. The caller may retry again later.
1600 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request
1602 @retval EFI_INVALID_PARAMETER Target, Lun, or the contents of ScsiRequestPacket are invalid.
1603 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported
1604 by the host adapter. This includes the case of Bi-directional SCSI
1605 commands not supported by the implementation. The SCSI Request
1606 Packet was not sent, so no additional status information is available.
1607 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1612 ExtScsiPassThruPassThru (
1613 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
1616 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
,
1617 IN EFI_EVENT Event OPTIONAL
1621 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1623 UINT8 PortMultiplier
;
1624 EFI_ATA_HC_WORK_MODE Mode
;
1626 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
1628 Instance
= EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1630 if ((Packet
== NULL
) || (Packet
->Cdb
== NULL
)) {
1631 return EFI_INVALID_PARAMETER
;
1635 // Don't support variable length CDB
1637 if ((Packet
->CdbLength
!= 6) && (Packet
->CdbLength
!= 10) &&
1638 (Packet
->CdbLength
!= 12) && (Packet
->CdbLength
!= 16)) {
1639 return EFI_INVALID_PARAMETER
;
1642 if ((This
->Mode
->IoAlign
> 1) && !IS_ALIGNED(Packet
->InDataBuffer
, This
->Mode
->IoAlign
)) {
1643 return EFI_INVALID_PARAMETER
;
1646 if ((This
->Mode
->IoAlign
> 1) && !IS_ALIGNED(Packet
->OutDataBuffer
, This
->Mode
->IoAlign
)) {
1647 return EFI_INVALID_PARAMETER
;
1650 if ((This
->Mode
->IoAlign
> 1) && !IS_ALIGNED(Packet
->SenseData
, This
->Mode
->IoAlign
)) {
1651 return EFI_INVALID_PARAMETER
;
1655 // For ATAPI device, doesn't support multiple LUN device.
1658 return EFI_INVALID_PARAMETER
;
1662 // The layout of Target array:
1663 // ________________________________________________________________________
1664 // | Byte 0 | Byte 1 | ... | TARGET_MAX_BYTES - 1 |
1665 // |_____________________|_____________________|_____|______________________|
1666 // | | The port multiplier | | |
1667 // | The port number | port number | N/A | N/A |
1668 // |_____________________|_____________________|_____|______________________|
1670 // For ATAPI device, 2 bytes is enough to represent the location of SCSI device.
1673 PortMultiplier
= Target
[1];
1675 Node
= SearchDeviceInfoList(Instance
, Port
, PortMultiplier
, EfiIdeCdrom
);
1677 return EFI_INVALID_PARAMETER
;
1680 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1683 // ATA_CMD_IDENTIFY_DEVICE cmd is a ATA cmd but not a SCSI cmd.
1684 // Normally it should NOT be passed down through ExtScsiPassThru protocol interface.
1685 // But to response EFI_DISK_INFO.Identify() request from ScsiDisk, we should handle this command.
1687 if (*((UINT8
*)Packet
->Cdb
) == ATA_CMD_IDENTIFY_DEVICE
) {
1688 CopyMem (Packet
->InDataBuffer
, DeviceInfo
->IdentifyData
, sizeof (EFI_IDENTIFY_DATA
));
1692 Mode
= Instance
->Mode
;
1696 // Reassign IDE mode io port registers' base addresses
1698 Status
= GetIdeRegisterIoAddr (Instance
->PciIo
, Instance
->IdeRegisters
);
1700 if (EFI_ERROR (Status
)) {
1704 Status
= AtaPacketCommandExecute (Instance
->PciIo
, &Instance
->IdeRegisters
[Port
], Port
, PortMultiplier
, Packet
);
1706 case EfiAtaAhciMode
:
1707 Status
= AhciPacketCommandExecute (Instance
->PciIo
, &Instance
->AhciRegisters
, Port
, PortMultiplier
, Packet
);
1710 Status
= EFI_DEVICE_ERROR
;
1718 Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These
1719 can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal
1720 Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the
1721 Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI
1724 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
1725 @param Target On input, a pointer to the Target ID (an array of size
1726 TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
1727 On output, a pointer to the Target ID (an array of
1728 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
1729 channel. An input value of 0xF(all bytes in the array are 0xF) in the
1730 Target array retrieves the Target ID of the first SCSI device present on a
1732 @param Lun On input, a pointer to the LUN of a SCSI device present on the SCSI
1733 channel. On output, a pointer to the LUN of the next SCSI device present
1736 @retval EFI_SUCCESS The Target ID and LUN of the next SCSI device on the SCSI
1737 channel was returned in Target and Lun.
1738 @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were
1739 not returned on a previous call to GetNextTargetLun().
1740 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.
1745 ExtScsiPassThruGetNextTargetLun (
1746 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
1747 IN OUT UINT8
**Target
,
1751 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1753 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
1757 Instance
= EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1759 if (Target
== NULL
|| Lun
== NULL
) {
1760 return EFI_INVALID_PARAMETER
;
1763 if (*Target
== NULL
) {
1764 return EFI_INVALID_PARAMETER
;
1768 Target16
= (UINT16
*)*Target
;
1770 if (CompareMem(Target8
, mScsiId
, TARGET_MAX_BYTES
) != 0) {
1772 // For ATAPI device, we use 2 least significant bytes to represent the location of SCSI device.
1773 // So the higher bytes in Target array should be 0xFF.
1775 if (CompareMem (&Target8
[2], &mScsiId
[2], TARGET_MAX_BYTES
- 2) != 0) {
1776 return EFI_INVALID_PARAMETER
;
1780 // When Target is not all 0xFF's, compare 2 least significant bytes with
1781 // previous target id to see if it is returned by previous call.
1783 if ((*Target16
!= Instance
->PreviousTargetId
) ||
1784 (*Lun
!= Instance
->PreviousLun
)) {
1785 return EFI_INVALID_PARAMETER
;
1789 // Traverse the whole device list to find the next cdrom closed to
1790 // the device signified by Target[0] and Target[1].
1792 // Note that we here use a tricky way to find the next cdrom :
1793 // All ata devices are detected and inserted into the device list
1796 Node
= GetFirstNode (&Instance
->DeviceList
);
1798 while (!IsNull (&Instance
->DeviceList
, Node
)) {
1799 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1801 if ((DeviceInfo
->Type
== EfiIdeCdrom
) &&
1802 ((Target8
[0] < DeviceInfo
->Port
) ||
1803 (Target8
[1] < DeviceInfo
->PortMultiplier
))) {
1804 Target8
[0] = (UINT8
)DeviceInfo
->Port
;
1805 Target8
[1] = (UINT8
)DeviceInfo
->PortMultiplier
;
1809 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
1812 return EFI_NOT_FOUND
;
1815 // If the array is all 0xFF's, start to traverse the device list from the beginning
1817 Node
= GetFirstNode (&Instance
->DeviceList
);
1818 while (!IsNull (&Instance
->DeviceList
, Node
)) {
1819 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
1821 if (DeviceInfo
->Type
== EfiIdeCdrom
) {
1822 Target8
[0] = (UINT8
)DeviceInfo
->Port
;
1823 Target8
[1] = (UINT8
)DeviceInfo
->PortMultiplier
;
1827 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
1830 return EFI_NOT_FOUND
;
1837 // Update the PreviousTargetId.
1839 Instance
->PreviousTargetId
= *Target16
;
1840 Instance
->PreviousLun
= *Lun
;
1846 Used to allocate and build a device path node for a SCSI device on a SCSI channel.
1848 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
1849 @param Target The Target is an array of size TARGET_MAX_BYTES and it specifies the
1850 Target ID of the SCSI device for which a device path node is to be
1851 allocated and built. Transport drivers may chose to utilize a subset of
1852 this size to suit the representation of targets. For example, a Fibre
1853 Channel driver may use only 8 bytes (WWN) in the array to represent a
1855 @param Lun The LUN of the SCSI device for which a device path node is to be
1856 allocated and built.
1857 @param DevicePath A pointer to a single device path node that describes the SCSI device
1858 specified by Target and Lun. This function is responsible for
1859 allocating the buffer DevicePath with the boot service
1860 AllocatePool(). It is the caller's responsibility to free
1861 DevicePath when the caller is finished with DevicePath.
1863 @retval EFI_SUCCESS The device path node that describes the SCSI device specified by
1864 Target and Lun was allocated and returned in
1866 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
1867 @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist
1868 on the SCSI channel.
1869 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
1874 ExtScsiPassThruBuildDevicePath (
1875 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
1878 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
1881 EFI_DEV_PATH
*DevicePathNode
;
1882 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1884 UINT8 PortMultiplier
;
1886 Instance
= EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1889 PortMultiplier
= Target
[1];
1892 // Validate parameters passed in.
1894 if (DevicePath
== NULL
) {
1895 return EFI_INVALID_PARAMETER
;
1899 // can not build device path for the SCSI Host Controller.
1902 return EFI_NOT_FOUND
;
1905 if (SearchDeviceInfoList(Instance
, Port
, PortMultiplier
, EfiIdeCdrom
) == NULL
) {
1906 return EFI_NOT_FOUND
;
1909 if (Instance
->Mode
== EfiAtaIdeMode
) {
1910 DevicePathNode
= AllocateCopyPool (sizeof (ATAPI_DEVICE_PATH
), &mAtapiDevicePathTemplate
);
1911 if (DevicePathNode
== NULL
) {
1912 return EFI_OUT_OF_RESOURCES
;
1915 DevicePathNode
->Atapi
.PrimarySecondary
= Port
;
1916 DevicePathNode
->Atapi
.SlaveMaster
= PortMultiplier
;
1917 DevicePathNode
->Atapi
.Lun
= (UINT16
) Lun
;
1919 DevicePathNode
= AllocateCopyPool (sizeof (SATA_DEVICE_PATH
), &mSataDevicePathTemplate
);
1920 if (DevicePathNode
== NULL
) {
1921 return EFI_OUT_OF_RESOURCES
;
1924 DevicePathNode
->Sata
.HBAPortNumber
= Port
;
1925 DevicePathNode
->Sata
.PortMultiplierPortNumber
= PortMultiplier
;
1926 DevicePathNode
->Sata
.Lun
= (UINT16
) Lun
;
1929 *DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) DevicePathNode
;
1935 Used to translate a device path node to a Target ID and LUN.
1937 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
1938 @param DevicePath A pointer to a single device path node that describes the SCSI device
1939 on the SCSI channel.
1940 @param Target A pointer to the Target Array which represents the ID of a SCSI device
1941 on the SCSI channel.
1942 @param Lun A pointer to the LUN of a SCSI device on the SCSI channel.
1944 @retval EFI_SUCCESS DevicePath was successfully translated to a Target ID and
1945 LUN, and they were returned in Target and Lun.
1946 @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL.
1947 @retval EFI_NOT_FOUND A valid translation from DevicePath to a Target ID and LUN
1949 @retval EFI_UNSUPPORTED This driver does not support the device path node type in
1955 ExtScsiPassThruGetTargetLun (
1956 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
1957 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1962 EFI_DEV_PATH
*DevicePathNode
;
1963 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
1966 Instance
= EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
1969 // Validate parameters passed in.
1971 if (DevicePath
== NULL
|| Target
== NULL
|| Lun
== NULL
) {
1972 return EFI_INVALID_PARAMETER
;
1975 if (*Target
== NULL
) {
1976 return EFI_INVALID_PARAMETER
;
1979 // Check whether the DevicePath belongs to SCSI_DEVICE_PATH
1981 if ((DevicePath
->Type
!= MESSAGING_DEVICE_PATH
) ||
1982 ((DevicePath
->SubType
!= MSG_ATAPI_DP
) &&
1983 (DevicePath
->SubType
!= MSG_SATA_DP
)) ||
1984 ((DevicePathNodeLength(DevicePath
) != sizeof(ATAPI_DEVICE_PATH
)) &&
1985 (DevicePathNodeLength(DevicePath
) != sizeof(SATA_DEVICE_PATH
)))) {
1986 return EFI_UNSUPPORTED
;
1989 SetMem (*Target
, TARGET_MAX_BYTES
, 0xFF);
1991 DevicePathNode
= (EFI_DEV_PATH
*) DevicePath
;
1993 if (Instance
->Mode
== EfiAtaIdeMode
) {
1994 (*Target
)[0] = (UINT8
) DevicePathNode
->Atapi
.PrimarySecondary
;
1995 (*Target
)[1] = (UINT8
) DevicePathNode
->Atapi
.SlaveMaster
;
1996 *Lun
= (UINT8
) DevicePathNode
->Atapi
.Lun
;
1998 (*Target
)[0] = (UINT8
) DevicePathNode
->Sata
.HBAPortNumber
;
1999 (*Target
)[1] = (UINT8
) DevicePathNode
->Sata
.PortMultiplierPortNumber
;
2000 *Lun
= (UINT8
) DevicePathNode
->Sata
.Lun
;
2003 Node
= SearchDeviceInfoList(Instance
, (*Target
)[0], (*Target
)[1], EfiIdeCdrom
);
2006 return EFI_NOT_FOUND
;
2010 return EFI_NOT_FOUND
;
2017 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.
2019 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2021 @retval EFI_SUCCESS The SCSI channel was reset.
2022 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.
2023 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI channel.
2024 @retval EFI_UNSUPPORTED The SCSI channel does not support a channel reset operation.
2029 ExtScsiPassThruResetChannel (
2030 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
2033 return EFI_UNSUPPORTED
;
2037 Resets a SCSI logical unit that is connected to a SCSI channel.
2039 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2040 @param Target The Target is an array of size TARGET_MAX_BYTE and it represents the
2041 target port ID of the SCSI device containing the SCSI logical unit to
2042 reset. Transport drivers may chose to utilize a subset of this array to suit
2043 the representation of their targets.
2044 @param Lun The LUN of the SCSI device to reset.
2046 @retval EFI_SUCCESS The SCSI device specified by Target and Lun was reset.
2047 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
2048 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI device
2049 specified by Target and Lun.
2050 @retval EFI_UNSUPPORTED The SCSI channel does not support a target reset operation.
2051 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI device
2052 specified by Target and Lun.
2057 ExtScsiPassThruResetTargetLun (
2058 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
2063 return EFI_UNSUPPORTED
;
2067 Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either
2068 be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs
2069 for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to
2070 see if a SCSI device is actually present at that location on the SCSI channel.
2072 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2073 @param Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
2074 On output, a pointer to the Target ID (an array of
2075 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
2076 channel. An input value of 0xF(all bytes in the array are 0xF) in the
2077 Target array retrieves the Target ID of the first SCSI device present on a
2080 @retval EFI_SUCCESS The Target ID of the next SCSI device on the SCSI
2081 channel was returned in Target.
2082 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
2083 @retval EFI_TIMEOUT Target array is not all 0xF, and Target was not
2084 returned on a previous call to GetNextTarget().
2085 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.
2090 ExtScsiPassThruGetNextTarget (
2091 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
2092 IN OUT UINT8
**Target
2095 ATA_ATAPI_PASS_THRU_INSTANCE
*Instance
;
2097 EFI_ATA_DEVICE_INFO
*DeviceInfo
;
2101 Instance
= EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This
);
2103 if (Target
== NULL
|| *Target
== NULL
) {
2104 return EFI_INVALID_PARAMETER
;
2108 Target16
= (UINT16
*)*Target
;
2110 if (CompareMem(Target8
, mScsiId
, TARGET_MAX_BYTES
) != 0) {
2112 // For ATAPI device, we use 2 least significant bytes to represent the location of SCSI device.
2113 // So the higher bytes in Target array should be 0xFF.
2115 if (CompareMem (&Target8
[2], &mScsiId
[2], TARGET_MAX_BYTES
- 2) != 0) {
2116 return EFI_INVALID_PARAMETER
;
2120 // When Target is not all 0xFF's, compare 2 least significant bytes with
2121 // previous target id to see if it is returned by previous call.
2123 if (*Target16
!= Instance
->PreviousTargetId
) {
2124 return EFI_INVALID_PARAMETER
;
2128 // Traverse the whole device list to find the next cdrom closed to
2129 // the device signified by Target[0] and Target[1].
2131 // Note that we here use a tricky way to find the next cdrom :
2132 // All ata devices are detected and inserted into the device list
2135 Node
= GetFirstNode (&Instance
->DeviceList
);
2136 while (!IsNull (&Instance
->DeviceList
, Node
)) {
2137 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
2139 if ((DeviceInfo
->Type
== EfiIdeCdrom
) &&
2140 ((Target8
[0] < DeviceInfo
->Port
) ||
2141 (Target8
[1] < DeviceInfo
->PortMultiplier
))) {
2142 Target8
[0] = (UINT8
)DeviceInfo
->Port
;
2143 Target8
[1] = (UINT8
)DeviceInfo
->PortMultiplier
;
2147 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
2150 return EFI_NOT_FOUND
;
2153 // If the array is all 0xFF's, start to traverse the device list from the beginning
2155 Node
= GetFirstNode (&Instance
->DeviceList
);
2157 while (!IsNull (&Instance
->DeviceList
, Node
)) {
2158 DeviceInfo
= ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node
);
2160 if (DeviceInfo
->Type
== EfiIdeCdrom
) {
2161 Target8
[0] = (UINT8
)DeviceInfo
->Port
;
2162 Target8
[1] = (UINT8
)DeviceInfo
->PortMultiplier
;
2166 Node
= GetNextNode (&Instance
->DeviceList
, Node
);
2169 return EFI_NOT_FOUND
;
2174 // Update the PreviousTargetId.
2176 Instance
->PreviousTargetId
= *Target16
;