2 This file implements protocol interfaces for ATA bus driver.
4 This file implements protocol interfaces: Driver Binding protocol,
5 Block IO protocol and DiskInfo protocol.
7 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 // ATA Bus Driver Binding Protocol Instance
26 EFI_DRIVER_BINDING_PROTOCOL gAtaBusDriverBinding
= {
27 AtaBusDriverBindingSupported
,
28 AtaBusDriverBindingStart
,
29 AtaBusDriverBindingStop
,
36 // Template for ATA Child Device.
38 ATA_DEVICE gAtaDeviceTemplate
= {
39 ATA_DEVICE_SIGNATURE
, // Signature
42 EFI_BLOCK_IO_PROTOCOL_REVISION
,
46 AtaBlockIoWriteBlocks
,
52 AtaBlockIoReadBlocksEx
,
53 AtaBlockIoWriteBlocksEx
,
54 AtaBlockIoFlushBlocksEx
58 FALSE
, // RemovableMedia
60 FALSE
, // LogicPartition
62 FALSE
, // WritingCache
66 0, // LowestAlignedLba
67 1 // LogicalBlocksPerPhysicalBlock
70 EFI_DISK_INFO_IDE_INTERFACE_GUID
,
78 AtaStorageSecurityReceiveData
,
79 AtaStorageSecuritySendData
81 NULL
, // AtaBusDriverData
83 0, // PortMultiplierPort
90 NULL
, // ControllerNameTable
91 {L
'\0', }, // ModelName
92 {NULL
, NULL
}, // AtaTaskList
93 {NULL
, NULL
} // AtaSubTaskList
97 Allocates an aligned buffer for ATA device.
99 This function allocates an aligned buffer for the ATA device to perform
100 ATA pass through operations. The alignment requirement is from ATA pass
103 @param AtaDevice The ATA child device involved for the operation.
104 @param BufferSize The request buffer size.
106 @return A pointer to the aligned buffer or NULL if the allocation fails.
110 AllocateAlignedBuffer (
111 IN ATA_DEVICE
*AtaDevice
,
115 return AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize
), AtaDevice
->AtaBusDriverData
->AtaPassThru
->Mode
->IoAlign
);
119 Frees an aligned buffer for ATA device.
121 This function frees an aligned buffer for the ATA device to perform
122 ATA pass through operations.
124 @param Buffer The aligned buffer to be freed.
125 @param BufferSize The request buffer size.
134 if (Buffer
!= NULL
) {
135 FreeAlignedPages (Buffer
, EFI_SIZE_TO_PAGES (BufferSize
));
141 Release all the resources allocated for the ATA device.
143 This function releases all the resources allocated for the ATA device.
145 @param AtaDevice The ATA child device involved for the operation.
149 ReleaseAtaResources (
150 IN ATA_DEVICE
*AtaDevice
153 ATA_BUS_ASYN_SUB_TASK
*SubTask
;
154 ATA_BUS_ASYN_TASK
*AtaTask
;
156 LIST_ENTRY
*DelEntry
;
159 FreeUnicodeStringTable (AtaDevice
->ControllerNameTable
);
160 FreeAlignedBuffer (AtaDevice
->Asb
, sizeof (EFI_ATA_STATUS_BLOCK
));
161 FreeAlignedBuffer (AtaDevice
->IdentifyData
, sizeof (ATA_IDENTIFY_DATA
));
162 if (AtaDevice
->DevicePath
!= NULL
) {
163 FreePool (AtaDevice
->DevicePath
);
165 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
166 if (!IsListEmpty (&AtaDevice
->AtaSubTaskList
)) {
168 // Free the Subtask list.
170 for(Entry
= AtaDevice
->AtaSubTaskList
.ForwardLink
;
171 Entry
!= (&AtaDevice
->AtaSubTaskList
);
174 Entry
= Entry
->ForwardLink
;
175 SubTask
= ATA_AYNS_SUB_TASK_FROM_ENTRY (DelEntry
);
177 RemoveEntryList (DelEntry
);
178 FreeAtaSubTask (SubTask
);
181 if (!IsListEmpty (&AtaDevice
->AtaTaskList
)) {
183 // Free the Subtask list.
185 for(Entry
= AtaDevice
->AtaTaskList
.ForwardLink
;
186 Entry
!= (&AtaDevice
->AtaTaskList
);
189 Entry
= Entry
->ForwardLink
;
190 AtaTask
= ATA_AYNS_TASK_FROM_ENTRY (DelEntry
);
192 RemoveEntryList (DelEntry
);
196 gBS
->RestoreTPL (OldTpl
);
197 FreePool (AtaDevice
);
202 Registers an ATA device.
204 This function allocates an ATA device structure for the ATA device specified by
205 Port and PortMultiplierPort if the ATA device is identified as a valid one.
206 Then it will create child handle and install Block IO and Disk Info protocol on
209 @param AtaBusDriverData The parent ATA bus driver data structure.
210 @param Port The port number of the ATA device.
211 @param PortMultiplierPort The port multiplier port number of the ATA device.
213 @retval EFI_SUCCESS The ATA device is successfully registered.
214 @retval EFI_OUT_OF_RESOURCES There is not enough memory to allocate the ATA device
215 and related data structures.
216 @return Others Some error occurs when registering the ATA device.
220 IN OUT ATA_BUS_DRIVER_DATA
*AtaBusDriverData
,
222 IN UINT16 PortMultiplierPort
226 ATA_DEVICE
*AtaDevice
;
227 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
228 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePathNode
;
229 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
230 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
231 EFI_HANDLE DeviceHandle
;
234 NewDevicePathNode
= NULL
;
236 RemainingDevicePath
= NULL
;
241 AtaPassThru
= AtaBusDriverData
->AtaPassThru
;
242 Status
= AtaPassThru
->BuildDevicePath (AtaPassThru
, Port
, PortMultiplierPort
, &NewDevicePathNode
);
243 if (EFI_ERROR (Status
)) {
247 DevicePath
= AppendDevicePathNode (AtaBusDriverData
->ParentDevicePath
, NewDevicePathNode
);
248 if (DevicePath
== NULL
) {
249 Status
= EFI_OUT_OF_RESOURCES
;
254 RemainingDevicePath
= DevicePath
;
255 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &DeviceHandle
);
256 if (!EFI_ERROR (Status
) && (DeviceHandle
!= NULL
) && IsDevicePathEnd(RemainingDevicePath
)) {
257 Status
= EFI_ALREADY_STARTED
;
258 FreePool (DevicePath
);
263 // Allocate ATA device from the template.
265 AtaDevice
= AllocateCopyPool (sizeof (ATA_DEVICE
), &gAtaDeviceTemplate
);
266 if (AtaDevice
== NULL
) {
267 Status
= EFI_OUT_OF_RESOURCES
;
272 // Initializes ATA device structures and allocates the required buffer.
274 AtaDevice
->BlockIo
.Media
= &AtaDevice
->BlockMedia
;
275 AtaDevice
->BlockIo2
.Media
= &AtaDevice
->BlockMedia
;
276 AtaDevice
->AtaBusDriverData
= AtaBusDriverData
;
277 AtaDevice
->DevicePath
= DevicePath
;
278 AtaDevice
->Port
= Port
;
279 AtaDevice
->PortMultiplierPort
= PortMultiplierPort
;
280 AtaDevice
->Asb
= AllocateAlignedBuffer (AtaDevice
, sizeof (EFI_ATA_STATUS_BLOCK
));
281 if (AtaDevice
->Asb
== NULL
) {
282 Status
= EFI_OUT_OF_RESOURCES
;
285 AtaDevice
->IdentifyData
= AllocateAlignedBuffer (AtaDevice
, sizeof (ATA_IDENTIFY_DATA
));
286 if (AtaDevice
->IdentifyData
== NULL
) {
287 Status
= EFI_OUT_OF_RESOURCES
;
292 // Initial Ata Task List
294 InitializeListHead (&AtaDevice
->AtaTaskList
);
295 InitializeListHead (&AtaDevice
->AtaSubTaskList
);
298 // Report Status Code to indicate the ATA device will be enabled
300 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
302 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_ENABLE
),
303 AtaBusDriverData
->ParentDevicePath
307 // Try to identify the ATA device via the ATA pass through command.
309 Status
= DiscoverAtaDevice (AtaDevice
);
310 if (EFI_ERROR (Status
)) {
315 // Build controller name for Component Name (2) protocol.
317 Status
= AddUnicodeString2 (
319 gAtaBusComponentName
.SupportedLanguages
,
320 &AtaDevice
->ControllerNameTable
,
321 AtaDevice
->ModelName
,
324 if (EFI_ERROR (Status
)) {
328 Status
= AddUnicodeString2 (
330 gAtaBusComponentName2
.SupportedLanguages
,
331 &AtaDevice
->ControllerNameTable
,
332 AtaDevice
->ModelName
,
335 if (EFI_ERROR (Status
)) {
340 // Update to AHCI interface GUID based on device path node. The default one
341 // is IDE interface GUID copied from template.
343 if (NewDevicePathNode
->SubType
== MSG_SATA_DP
) {
344 CopyGuid (&AtaDevice
->DiskInfo
.Interface
, &gEfiDiskInfoAhciInterfaceGuid
);
347 Status
= gBS
->InstallMultipleProtocolInterfaces (
349 &gEfiDevicePathProtocolGuid
,
350 AtaDevice
->DevicePath
,
351 &gEfiBlockIoProtocolGuid
,
353 &gEfiBlockIo2ProtocolGuid
,
354 &AtaDevice
->BlockIo2
,
355 &gEfiDiskInfoProtocolGuid
,
356 &AtaDevice
->DiskInfo
,
359 if (EFI_ERROR (Status
)) {
364 // See if the ata device support trust computing feature or not.
365 // If yes, then install Storage Security Protocol at the ata device handle.
367 if ((AtaDevice
->IdentifyData
->trusted_computing_support
& BIT0
) != 0) {
368 DEBUG ((EFI_D_INFO
, "Found TCG support in Port %x PortMultiplierPort %x\n", Port
, PortMultiplierPort
));
369 Status
= gBS
->InstallProtocolInterface (
371 &gEfiStorageSecurityCommandProtocolGuid
,
372 EFI_NATIVE_INTERFACE
,
373 &AtaDevice
->StorageSecurity
375 if (EFI_ERROR (Status
)) {
378 DEBUG ((EFI_D_INFO
, "Successfully Install Storage Security Protocol on the ATA device\n"));
382 if (((mMorControl
& 0x01) == 0x01) && ((AtaDevice
->IdentifyData
->trusted_computing_support
& BIT0
) != 0)) {
384 "mMorControl = %x, AtaDevice->IdentifyData->trusted_computing_support & BIT0 = %x\n",
386 (AtaDevice
->IdentifyData
->trusted_computing_support
& BIT0
)
388 DEBUG ((EFI_D_INFO
, "Try to lock device by sending TPer Reset command...\n"));
389 InitiateTPerReset(AtaDevice
);
393 AtaBusDriverData
->Controller
,
394 &gEfiAtaPassThruProtocolGuid
,
395 (VOID
**) &AtaPassThru
,
396 AtaBusDriverData
->DriverBindingHandle
,
398 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
402 if (NewDevicePathNode
!= NULL
) {
403 FreePool (NewDevicePathNode
);
406 if (EFI_ERROR (Status
) && (AtaDevice
!= NULL
)) {
407 ReleaseAtaResources (AtaDevice
);
408 DEBUG ((EFI_D_ERROR
| EFI_D_INIT
, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port
, PortMultiplierPort
, Status
));
415 Unregisters an ATA device.
417 This function removes the protocols installed on the controller handle and
418 frees the resources allocated for the ATA device.
420 @param This The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.
421 @param Controller The controller handle of the ATA device.
422 @param Handle The child handle.
424 @retval EFI_SUCCESS The ATA device is successfully unregistered.
425 @return Others Some error occurs when unregistering the ATA device.
429 UnregisterAtaDevice (
430 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
431 IN EFI_HANDLE Controller
,
436 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
437 EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
;
438 ATA_DEVICE
*AtaDevice
;
439 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
440 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*StorageSecurity
;
445 Status
= gBS
->OpenProtocol (
447 &gEfiBlockIoProtocolGuid
,
449 This
->DriverBindingHandle
,
451 EFI_OPEN_PROTOCOL_GET_PROTOCOL
453 if (EFI_ERROR (Status
)) {
455 // Locate BlockIo2 protocol
457 Status
= gBS
->OpenProtocol (
459 &gEfiBlockIo2ProtocolGuid
,
461 This
->DriverBindingHandle
,
463 EFI_OPEN_PROTOCOL_GET_PROTOCOL
465 if (EFI_ERROR (Status
)) {
471 // Get AtaDevice data.
473 if (BlockIo
!= NULL
) {
474 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (BlockIo
);
476 ASSERT (BlockIo2
!= NULL
);
477 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (BlockIo2
);
481 // Close the child handle
485 &gEfiAtaPassThruProtocolGuid
,
486 This
->DriverBindingHandle
,
491 // The Ata Bus driver installs the BlockIo and BlockIo2 in the DriverBindingStart().
492 // Here should uninstall both of them.
494 Status
= gBS
->UninstallMultipleProtocolInterfaces (
496 &gEfiDevicePathProtocolGuid
,
497 AtaDevice
->DevicePath
,
498 &gEfiBlockIoProtocolGuid
,
500 &gEfiBlockIo2ProtocolGuid
,
501 &AtaDevice
->BlockIo2
,
502 &gEfiDiskInfoProtocolGuid
,
503 &AtaDevice
->DiskInfo
,
507 if (EFI_ERROR (Status
)) {
510 &gEfiAtaPassThruProtocolGuid
,
511 (VOID
**) &AtaPassThru
,
512 This
->DriverBindingHandle
,
514 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
520 // If Storage Security Command Protocol is installed, then uninstall this protocol.
522 Status
= gBS
->OpenProtocol (
524 &gEfiStorageSecurityCommandProtocolGuid
,
525 (VOID
**) &StorageSecurity
,
526 This
->DriverBindingHandle
,
528 EFI_OPEN_PROTOCOL_GET_PROTOCOL
531 if (!EFI_ERROR (Status
)) {
532 Status
= gBS
->UninstallProtocolInterface (
534 &gEfiStorageSecurityCommandProtocolGuid
,
535 &AtaDevice
->StorageSecurity
537 if (EFI_ERROR (Status
)) {
540 &gEfiAtaPassThruProtocolGuid
,
541 (VOID
**) &AtaPassThru
,
542 This
->DriverBindingHandle
,
544 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
550 ReleaseAtaResources (AtaDevice
);
557 Tests to see if this driver supports a given controller. If a child device is provided,
558 it further tests to see if this driver supports creating a handle for the specified child device.
560 This function checks to see if the driver specified by This supports the device specified by
561 ControllerHandle. Drivers will typically use the device path attached to
562 ControllerHandle and/or the services from the bus I/O abstraction attached to
563 ControllerHandle to determine if the driver supports ControllerHandle. This function
564 may be called many times during platform initialization. In order to reduce boot times, the tests
565 performed by this function must be very small, and take as little time as possible to execute. This
566 function must not change the state of any hardware devices, and this function must be aware that the
567 device specified by ControllerHandle may already be managed by the same driver or a
568 different driver. This function must match its calls to AllocatePages() with FreePages(),
569 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
570 Since ControllerHandle may have been previously started by the same driver, if a protocol is
571 already in the opened state, then it must not be closed with CloseProtocol(). This is required
572 to guarantee the state of ControllerHandle is not modified by this function.
574 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
575 @param[in] ControllerHandle The handle of the controller to test. This handle
576 must support a protocol interface that supplies
577 an I/O abstraction to the driver.
578 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
579 parameter is ignored by device drivers, and is optional for bus
580 drivers. For bus drivers, if this parameter is not NULL, then
581 the bus driver must determine if the bus controller specified
582 by ControllerHandle and the child controller specified
583 by RemainingDevicePath are both supported by this
586 @retval EFI_SUCCESS The device specified by ControllerHandle and
587 RemainingDevicePath is supported by the driver specified by This.
588 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
589 RemainingDevicePath is already being managed by the driver
591 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
592 RemainingDevicePath is already being managed by a different
593 driver or an application that requires exclusive access.
594 Currently not implemented.
595 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
596 RemainingDevicePath is not supported by the driver specified by This.
600 AtaBusDriverBindingSupported (
601 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
602 IN EFI_HANDLE Controller
,
603 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
607 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
608 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
610 UINT16 PortMultiplierPort
;
613 // Test EFI_ATA_PASS_THRU_PROTOCOL on controller handle.
615 Status
= gBS
->OpenProtocol (
617 &gEfiAtaPassThruProtocolGuid
,
618 (VOID
**) &AtaPassThru
,
619 This
->DriverBindingHandle
,
621 EFI_OPEN_PROTOCOL_BY_DRIVER
624 if (Status
== EFI_ALREADY_STARTED
) {
628 if (EFI_ERROR (Status
)) {
633 // Test to see if this ATA Pass Thru Protocol is for a LOGICAL channel
635 if ((AtaPassThru
->Mode
->Attributes
& EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL
) == 0) {
637 // Close the I/O Abstraction(s) used to perform the supported test
641 &gEfiAtaPassThruProtocolGuid
,
642 This
->DriverBindingHandle
,
645 return EFI_UNSUPPORTED
;
649 // Test RemainingDevicePath is valid or not.
651 if ((RemainingDevicePath
!= NULL
) && !IsDevicePathEnd (RemainingDevicePath
)) {
652 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
653 if (EFI_ERROR (Status
)) {
655 // Close the I/O Abstraction(s) used to perform the supported test
659 &gEfiAtaPassThruProtocolGuid
,
660 This
->DriverBindingHandle
,
668 // Close the I/O Abstraction(s) used to perform the supported test
672 &gEfiAtaPassThruProtocolGuid
,
673 This
->DriverBindingHandle
,
678 // Open the EFI Device Path protocol needed to perform the supported test
680 Status
= gBS
->OpenProtocol (
682 &gEfiDevicePathProtocolGuid
,
683 (VOID
**) &ParentDevicePath
,
684 This
->DriverBindingHandle
,
686 EFI_OPEN_PROTOCOL_GET_PROTOCOL
693 Starts a device controller or a bus controller.
695 The Start() function is designed to be invoked from the EFI boot service ConnectController().
696 As a result, much of the error checking on the parameters to Start() has been moved into this
697 common boot service. It is legal to call Start() from other locations,
698 but the following calling restrictions must be followed or the system behavior will not be deterministic.
699 1. ControllerHandle must be a valid EFI_HANDLE.
700 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
701 EFI_DEVICE_PATH_PROTOCOL.
702 3. Prior to calling Start(), the Supported() function for the driver specified by This must
703 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
705 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
706 @param[in] ControllerHandle The handle of the controller to start. This handle
707 must support a protocol interface that supplies
708 an I/O abstraction to the driver.
709 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
710 parameter is ignored by device drivers, and is optional for bus
711 drivers. For a bus driver, if this parameter is NULL, then handles
712 for all the children of Controller are created by this driver.
713 If this parameter is not NULL and the first Device Path Node is
714 not the End of Device Path Node, then only the handle for the
715 child device specified by the first Device Path Node of
716 RemainingDevicePath is created by this driver.
717 If the first Device Path Node of RemainingDevicePath is
718 the End of Device Path Node, no child handle is created by this
721 @retval EFI_SUCCESS The device was started.
722 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
723 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
724 @retval Others The driver failded to start the device.
729 AtaBusDriverBindingStart (
730 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
731 IN EFI_HANDLE Controller
,
732 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
736 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
737 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
738 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
740 UINT16 PortMultiplierPort
;
742 AtaBusDriverData
= NULL
;
744 Status
= gBS
->OpenProtocol (
746 &gEfiDevicePathProtocolGuid
,
747 (VOID
**) &ParentDevicePath
,
748 This
->DriverBindingHandle
,
750 EFI_OPEN_PROTOCOL_GET_PROTOCOL
752 if (EFI_ERROR (Status
)) {
757 // Report Status Code to indicate ATA bus starts
759 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
761 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_INIT
),
765 Status
= gBS
->OpenProtocol (
767 &gEfiAtaPassThruProtocolGuid
,
768 (VOID
**) &AtaPassThru
,
769 This
->DriverBindingHandle
,
771 EFI_OPEN_PROTOCOL_BY_DRIVER
773 if ((EFI_ERROR (Status
)) && (Status
!= EFI_ALREADY_STARTED
)) {
778 // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.
780 if (Status
!= EFI_ALREADY_STARTED
) {
781 AtaBusDriverData
= AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA
));
782 if (AtaBusDriverData
== NULL
) {
783 Status
= EFI_OUT_OF_RESOURCES
;
787 AtaBusDriverData
->AtaPassThru
= AtaPassThru
;
788 AtaBusDriverData
->Controller
= Controller
;
789 AtaBusDriverData
->ParentDevicePath
= ParentDevicePath
;
790 AtaBusDriverData
->DriverBindingHandle
= This
->DriverBindingHandle
;
792 Status
= gBS
->InstallMultipleProtocolInterfaces (
798 if (EFI_ERROR (Status
)) {
803 Status
= gBS
->OpenProtocol (
806 (VOID
**) &AtaBusDriverData
,
807 This
->DriverBindingHandle
,
809 EFI_OPEN_PROTOCOL_GET_PROTOCOL
811 if (EFI_ERROR (Status
)) {
812 AtaBusDriverData
= NULL
;
818 // Report Status Code to indicate detecting devices on bus
820 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
822 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_DETECT
),
826 if (RemainingDevicePath
== NULL
) {
829 Status
= AtaPassThru
->GetNextPort (AtaPassThru
, &Port
);
830 if (EFI_ERROR (Status
)) {
832 // We cannot find more legal port then we are done.
837 PortMultiplierPort
= 0xFFFF;
839 Status
= AtaPassThru
->GetNextDevice (AtaPassThru
, Port
, &PortMultiplierPort
);
840 if (EFI_ERROR (Status
)) {
842 // We cannot find more legal port multiplier port number for ATA device
843 // on the port, then we are done.
847 RegisterAtaDevice (AtaBusDriverData
, Port
, PortMultiplierPort
);
850 Status
= EFI_SUCCESS
;
851 } else if (!IsDevicePathEnd (RemainingDevicePath
)) {
852 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
853 if (!EFI_ERROR (Status
)) {
854 Status
= RegisterAtaDevice (AtaBusDriverData
,Port
, PortMultiplierPort
);
862 if (AtaBusDriverData
!= NULL
) {
863 gBS
->UninstallMultipleProtocolInterfaces (
869 FreePool (AtaBusDriverData
);
874 &gEfiAtaPassThruProtocolGuid
,
875 This
->DriverBindingHandle
,
885 Stops a device controller or a bus controller.
887 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
888 As a result, much of the error checking on the parameters to Stop() has been moved
889 into this common boot service. It is legal to call Stop() from other locations,
890 but the following calling restrictions must be followed or the system behavior will not be deterministic.
891 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
892 same driver's Start() function.
893 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
894 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
895 Start() function, and the Start() function must have called OpenProtocol() on
896 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
898 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
899 @param[in] ControllerHandle A handle to the device being stopped. The handle must
900 support a bus specific I/O protocol for the driver
901 to use to stop the device.
902 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
903 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
904 if NumberOfChildren is 0.
906 @retval EFI_SUCCESS The device was stopped.
907 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
912 AtaBusDriverBindingStop (
913 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
914 IN EFI_HANDLE Controller
,
915 IN UINTN NumberOfChildren
,
916 IN EFI_HANDLE
*ChildHandleBuffer
920 BOOLEAN AllChildrenStopped
;
922 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
924 if (NumberOfChildren
== 0) {
925 Status
= gBS
->OpenProtocol (
928 (VOID
**) &AtaBusDriverData
,
929 This
->DriverBindingHandle
,
931 EFI_OPEN_PROTOCOL_GET_PROTOCOL
933 if (!EFI_ERROR (Status
)) {
934 gBS
->UninstallMultipleProtocolInterfaces (
940 FreePool (AtaBusDriverData
);
945 &gEfiAtaPassThruProtocolGuid
,
946 This
->DriverBindingHandle
,
953 AllChildrenStopped
= TRUE
;
955 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
957 Status
= UnregisterAtaDevice (This
, Controller
, ChildHandleBuffer
[Index
]);
958 if (EFI_ERROR (Status
)) {
959 AllChildrenStopped
= FALSE
;
963 if (!AllChildrenStopped
) {
964 return EFI_DEVICE_ERROR
;
972 Reset the Block Device.
974 @param This Indicates a pointer to the calling context.
975 @param ExtendedVerification Driver may perform diagnostics on reset.
977 @retval EFI_SUCCESS The device was reset.
978 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
985 IN EFI_BLOCK_IO_PROTOCOL
*This
,
986 IN BOOLEAN ExtendedVerification
990 ATA_DEVICE
*AtaDevice
;
993 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
995 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
997 Status
= ResetAtaDevice (AtaDevice
);
999 if (EFI_ERROR (Status
)) {
1000 Status
= EFI_DEVICE_ERROR
;
1003 gBS
->RestoreTPL (OldTpl
);
1009 Read/Write BufferSize bytes from Lba from/into Buffer.
1011 @param[in] This Indicates a pointer to the calling context. Either be
1012 block I/O or block I/O2.
1013 @param[in] MediaId The media ID that the read/write request is for.
1014 @param[in] Lba The starting logical block address to be read/written.
1015 The caller is responsible for reading/writing to only
1016 legitimate locations.
1017 @param[in, out] Token A pointer to the token associated with the transaction.
1018 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1019 @param[out] Buffer A pointer to the destination/source buffer for the data.
1020 @param[in] IsBlockIo2 Indicate the calling is from BlockIO or BlockIO2. TURE is
1021 from BlockIO2, FALSE is for BlockIO.
1022 @param[in] IsWrite Indicates whether it is a write operation.
1024 @retval EFI_SUCCESS The data was read/written correctly to the device.
1025 @retval EFI_WRITE_PROTECTED The device can not be read/written to.
1026 @retval EFI_DEVICE_ERROR The device reported an error while performing the read/write.
1027 @retval EFI_NO_MEDIA There is no media in the device.
1028 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1029 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1030 @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid,
1031 or the buffer is not on proper alignment.
1039 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1040 IN UINTN BufferSize
,
1042 IN BOOLEAN IsBlockIo2
,
1046 ATA_DEVICE
*AtaDevice
;
1049 EFI_BLOCK_IO_MEDIA
*Media
;
1051 UINTN NumberOfBlocks
;
1055 Media
= ((EFI_BLOCK_IO2_PROTOCOL
*) This
)->Media
;
1056 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (This
);
1058 Media
= ((EFI_BLOCK_IO_PROTOCOL
*) This
)->Media
;
1059 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
1062 if (MediaId
!= Media
->MediaId
) {
1063 return EFI_MEDIA_CHANGED
;
1067 // Check parameters.
1069 if (Buffer
== NULL
) {
1070 return EFI_INVALID_PARAMETER
;
1073 if (BufferSize
== 0) {
1077 BlockSize
= Media
->BlockSize
;
1078 if ((BufferSize
% BlockSize
) != 0) {
1079 return EFI_BAD_BUFFER_SIZE
;
1082 NumberOfBlocks
= BufferSize
/ BlockSize
;
1083 if ((Lba
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
1084 return EFI_INVALID_PARAMETER
;
1087 IoAlign
= Media
->IoAlign
;
1088 if (IoAlign
> 0 && (((UINTN
) Buffer
& (IoAlign
- 1)) != 0)) {
1089 return EFI_INVALID_PARAMETER
;
1092 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1095 // Invoke low level AtaDevice Access Routine.
1097 Status
= AccessAtaDevice (AtaDevice
, Buffer
, Lba
, NumberOfBlocks
, IsWrite
, Token
);
1099 gBS
->RestoreTPL (OldTpl
);
1106 Read BufferSize bytes from Lba into Buffer.
1108 @param This Indicates a pointer to the calling context.
1109 @param MediaId Id of the media, changes every time the media is replaced.
1110 @param Lba The starting Logical Block Address to read from
1111 @param BufferSize Size of Buffer, must be a multiple of device block size.
1112 @param Buffer A pointer to the destination buffer for the data. The caller is
1113 responsible for either having implicit or explicit ownership of the buffer.
1115 @retval EFI_SUCCESS The data was read correctly from the device.
1116 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
1117 @retval EFI_NO_MEDIA There is no media in the device.
1118 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
1119 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1120 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1121 or the buffer is not on proper alignment.
1126 AtaBlockIoReadBlocks (
1127 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1130 IN UINTN BufferSize
,
1134 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, NULL
, BufferSize
, Buffer
, FALSE
, FALSE
);
1139 Write BufferSize bytes from Lba into Buffer.
1141 @param This Indicates a pointer to the calling context.
1142 @param MediaId The media ID that the write request is for.
1143 @param Lba The starting logical block address to be written. The caller is
1144 responsible for writing to only legitimate locations.
1145 @param BufferSize Size of Buffer, must be a multiple of device block size.
1146 @param Buffer A pointer to the source buffer for the data.
1148 @retval EFI_SUCCESS The data was written correctly to the device.
1149 @retval EFI_WRITE_PROTECTED The device can not be written to.
1150 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1151 @retval EFI_NO_MEDIA There is no media in the device.
1152 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1153 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1154 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1155 or the buffer is not on proper alignment.
1160 AtaBlockIoWriteBlocks (
1161 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1164 IN UINTN BufferSize
,
1168 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, NULL
, BufferSize
, Buffer
, FALSE
, TRUE
);
1173 Flush the Block Device.
1175 @param This Indicates a pointer to the calling context.
1177 @retval EFI_SUCCESS All outstanding data was written to the device
1178 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1179 @retval EFI_NO_MEDIA There is no media in the device.
1184 AtaBlockIoFlushBlocks (
1185 IN EFI_BLOCK_IO_PROTOCOL
*This
1195 Reset the Block Device.
1197 @param[in] This Indicates a pointer to the calling context.
1198 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
1200 @retval EFI_SUCCESS The device was reset.
1201 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
1208 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1209 IN BOOLEAN ExtendedVerification
1213 ATA_DEVICE
*AtaDevice
;
1216 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1218 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (This
);
1220 Status
= ResetAtaDevice (AtaDevice
);
1222 if (EFI_ERROR (Status
)) {
1223 Status
= EFI_DEVICE_ERROR
;
1226 gBS
->RestoreTPL (OldTpl
);
1231 Read BufferSize bytes from Lba into Buffer.
1233 @param[in] This Indicates a pointer to the calling context.
1234 @param[in] MediaId Id of the media, changes every time the media is replaced.
1235 @param[in] Lba The starting Logical Block Address to read from.
1236 @param[in, out] Token A pointer to the token associated with the transaction.
1237 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1238 @param[out] Buffer A pointer to the destination buffer for the data. The caller is
1239 responsible for either having implicit or explicit ownership of the buffer.
1241 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
1242 The data was read correctly from the device if
1244 @retval EFI_DEVICE_ERROR The device reported an error while performing
1246 @retval EFI_NO_MEDIA There is no media in the device.
1247 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1248 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
1249 intrinsic block size of the device.
1250 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1251 or the buffer is not on proper alignment.
1252 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
1258 AtaBlockIoReadBlocksEx (
1259 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1262 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1263 IN UINTN BufferSize
,
1267 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, Token
, BufferSize
, Buffer
, TRUE
, FALSE
);
1272 Write BufferSize bytes from Lba into Buffer.
1274 @param[in] This Indicates a pointer to the calling context.
1275 @param[in] MediaId The media ID that the write request is for.
1276 @param[in] Lba The starting logical block address to be written. The
1277 caller is responsible for writing to only legitimate
1279 @param[in, out] Token A pointer to the token associated with the transaction.
1280 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1281 @param[in] Buffer A pointer to the source buffer for the data.
1283 @retval EFI_SUCCESS The data was written correctly to the device.
1284 @retval EFI_WRITE_PROTECTED The device can not be written to.
1285 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1286 @retval EFI_NO_MEDIA There is no media in the device.
1287 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1288 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1289 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1290 or the buffer is not on proper alignment.
1295 AtaBlockIoWriteBlocksEx (
1296 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1299 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1300 IN UINTN BufferSize
,
1304 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, Token
, BufferSize
, Buffer
, TRUE
, TRUE
);
1309 Flush the Block Device.
1311 @param[in] This Indicates a pointer to the calling context.
1312 @param[in, out] Token A pointer to the token associated with the transaction.
1314 @retval EFI_SUCCESS All outstanding data was written to the device
1315 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1316 @retval EFI_NO_MEDIA There is no media in the device.
1321 AtaBlockIoFlushBlocksEx (
1322 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1323 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
1327 // Signal event and return directly.
1329 if (Token
!= NULL
&& Token
->Event
!= NULL
) {
1330 Token
->TransactionStatus
= EFI_SUCCESS
;
1331 gBS
->SignalEvent (Token
->Event
);
1336 Provides inquiry information for the controller type.
1338 This function is used by the IDE bus driver to get inquiry data. Data format
1339 of Identify data is defined by the Interface GUID.
1341 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1342 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
1343 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
1345 @retval EFI_SUCCESS The command was accepted without any errors.
1346 @retval EFI_NOT_FOUND Device does not support this data class
1347 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
1348 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
1353 AtaDiskInfoInquiry (
1354 IN EFI_DISK_INFO_PROTOCOL
*This
,
1355 IN OUT VOID
*InquiryData
,
1356 IN OUT UINT32
*InquiryDataSize
1359 return EFI_NOT_FOUND
;
1364 Provides identify information for the controller type.
1366 This function is used by the IDE bus driver to get identify data. Data format
1367 of Identify data is defined by the Interface GUID.
1369 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
1371 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
1372 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
1375 @retval EFI_SUCCESS The command was accepted without any errors.
1376 @retval EFI_NOT_FOUND Device does not support this data class
1377 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
1378 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
1383 AtaDiskInfoIdentify (
1384 IN EFI_DISK_INFO_PROTOCOL
*This
,
1385 IN OUT VOID
*IdentifyData
,
1386 IN OUT UINT32
*IdentifyDataSize
1390 ATA_DEVICE
*AtaDevice
;
1392 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1394 Status
= EFI_BUFFER_TOO_SMALL
;
1395 if (*IdentifyDataSize
>= sizeof (ATA_IDENTIFY_DATA
)) {
1396 Status
= EFI_SUCCESS
;
1397 CopyMem (IdentifyData
, AtaDevice
->IdentifyData
, sizeof (ATA_IDENTIFY_DATA
));
1399 *IdentifyDataSize
= sizeof (ATA_IDENTIFY_DATA
);
1406 Provides sense data information for the controller type.
1408 This function is used by the IDE bus driver to get sense data.
1409 Data format of Sense data is defined by the Interface GUID.
1411 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1412 @param[in, out] SenseData Pointer to the SenseData.
1413 @param[in, out] SenseDataSize Size of SenseData in bytes.
1414 @param[out] SenseDataNumber Pointer to the value for the sense data size.
1416 @retval EFI_SUCCESS The command was accepted without any errors.
1417 @retval EFI_NOT_FOUND Device does not support this data class.
1418 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
1419 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
1424 AtaDiskInfoSenseData (
1425 IN EFI_DISK_INFO_PROTOCOL
*This
,
1426 IN OUT VOID
*SenseData
,
1427 IN OUT UINT32
*SenseDataSize
,
1428 OUT UINT8
*SenseDataNumber
1431 return EFI_NOT_FOUND
;
1436 This function is used by the IDE bus driver to get controller information.
1438 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1439 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
1440 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
1442 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
1443 @retval EFI_UNSUPPORTED This is not an IDE device.
1448 AtaDiskInfoWhichIde (
1449 IN EFI_DISK_INFO_PROTOCOL
*This
,
1450 OUT UINT32
*IdeChannel
,
1451 OUT UINT32
*IdeDevice
1454 ATA_DEVICE
*AtaDevice
;
1456 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1457 *IdeChannel
= AtaDevice
->Port
;
1458 *IdeDevice
= AtaDevice
->PortMultiplierPort
;
1464 Send a security protocol command to a device that receives data and/or the result
1465 of one or more commands sent by SendData.
1467 The ReceiveData function sends a security protocol command to the given MediaId.
1468 The security protocol command sent is defined by SecurityProtocolId and contains
1469 the security protocol specific data SecurityProtocolSpecificData. The function
1470 returns the data from the security protocol command in PayloadBuffer.
1472 For devices supporting the SCSI command set, the security protocol command is sent
1473 using the SECURITY PROTOCOL IN command defined in SPC-4.
1475 For devices supporting the ATA command set, the security protocol command is sent
1476 using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize
1479 If the PayloadBufferSize is zero, the security protocol command is sent using the
1480 Trusted Non-Data command defined in ATA8-ACS.
1482 If PayloadBufferSize is too small to store the available data from the security
1483 protocol command, the function shall copy PayloadBufferSize bytes into the
1484 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
1486 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
1487 the function shall return EFI_INVALID_PARAMETER.
1489 If the given MediaId does not support security protocol commands, the function shall
1490 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
1491 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
1492 the function returns EFI_MEDIA_CHANGED.
1494 If the security protocol fails to complete within the Timeout period, the function
1495 shall return EFI_TIMEOUT.
1497 If the security protocol command completes without an error, the function shall
1498 return EFI_SUCCESS. If the security protocol command completes with an error, the
1499 function shall return EFI_DEVICE_ERROR.
1501 @param This Indicates a pointer to the calling context.
1502 @param MediaId ID of the medium to receive data from.
1503 @param Timeout The timeout, in 100ns units, to use for the execution
1504 of the security protocol command. A Timeout value of 0
1505 means that this function will wait indefinitely for the
1506 security protocol command to execute. If Timeout is greater
1507 than zero, then this function will return EFI_TIMEOUT
1508 if the time required to execute the receive data command
1509 is greater than Timeout.
1510 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1511 the security protocol command to be sent.
1512 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1513 of the security protocol command to be sent.
1514 @param PayloadBufferSize Size in bytes of the payload data buffer.
1515 @param PayloadBuffer A pointer to a destination buffer to store the security
1516 protocol command specific payload data for the security
1517 protocol command. The caller is responsible for having
1518 either implicit or explicit ownership of the buffer.
1519 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
1520 data written to the payload data buffer.
1522 @retval EFI_SUCCESS The security protocol command completed successfully.
1523 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
1524 data from the device. The PayloadBuffer contains the truncated data.
1525 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1526 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1527 @retval EFI_NO_MEDIA There is no media in the device.
1528 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1529 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
1530 PayloadBufferSize is non-zero.
1531 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1532 protocol command to execute.
1537 AtaStorageSecurityReceiveData (
1538 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1541 IN UINT8 SecurityProtocolId
,
1542 IN UINT16 SecurityProtocolSpecificData
,
1543 IN UINTN PayloadBufferSize
,
1544 OUT VOID
*PayloadBuffer
,
1545 OUT UINTN
*PayloadTransferSize
1549 ATA_DEVICE
*Private
;
1552 DEBUG ((EFI_D_INFO
, "EFI Storage Security Protocol - Read"));
1553 if ((PayloadBuffer
== NULL
|| PayloadTransferSize
== NULL
) && PayloadBufferSize
!= 0) {
1554 return EFI_INVALID_PARAMETER
;
1557 Status
= EFI_SUCCESS
;
1558 Private
= ATA_DEVICE_FROM_STORAGE_SECURITY (This
);
1560 if (MediaId
!= Private
->BlockIo
.Media
->MediaId
) {
1561 return EFI_MEDIA_CHANGED
;
1564 if (!Private
->BlockIo
.Media
->MediaPresent
) {
1565 return EFI_NO_MEDIA
;
1568 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1570 Status
= TrustTransferAtaDevice (
1574 SecurityProtocolSpecificData
,
1581 gBS
->RestoreTPL (OldTpl
);
1586 Send a security protocol command to a device.
1588 The SendData function sends a security protocol command containing the payload
1589 PayloadBuffer to the given MediaId. The security protocol command sent is
1590 defined by SecurityProtocolId and contains the security protocol specific data
1591 SecurityProtocolSpecificData. If the underlying protocol command requires a
1592 specific padding for the command payload, the SendData function shall add padding
1593 bytes to the command payload to satisfy the padding requirements.
1595 For devices supporting the SCSI command set, the security protocol command is sent
1596 using the SECURITY PROTOCOL OUT command defined in SPC-4.
1598 For devices supporting the ATA command set, the security protocol command is sent
1599 using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize
1600 is non-zero. If the PayloadBufferSize is zero, the security protocol command is
1601 sent using the Trusted Non-Data command defined in ATA8-ACS.
1603 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
1604 return EFI_INVALID_PARAMETER.
1606 If the given MediaId does not support security protocol commands, the function
1607 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
1608 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
1609 device, the function returns EFI_MEDIA_CHANGED.
1611 If the security protocol fails to complete within the Timeout period, the function
1612 shall return EFI_TIMEOUT.
1614 If the security protocol command completes without an error, the function shall return
1615 EFI_SUCCESS. If the security protocol command completes with an error, the function
1616 shall return EFI_DEVICE_ERROR.
1618 @param This Indicates a pointer to the calling context.
1619 @param MediaId ID of the medium to receive data from.
1620 @param Timeout The timeout, in 100ns units, to use for the execution
1621 of the security protocol command. A Timeout value of 0
1622 means that this function will wait indefinitely for the
1623 security protocol command to execute. If Timeout is greater
1624 than zero, then this function will return EFI_TIMEOUT
1625 if the time required to execute the receive data command
1626 is greater than Timeout.
1627 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1628 the security protocol command to be sent.
1629 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1630 of the security protocol command to be sent.
1631 @param PayloadBufferSize Size in bytes of the payload data buffer.
1632 @param PayloadBuffer A pointer to a destination buffer to store the security
1633 protocol command specific payload data for the security
1636 @retval EFI_SUCCESS The security protocol command completed successfully.
1637 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1638 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1639 @retval EFI_NO_MEDIA There is no media in the device.
1640 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1641 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
1642 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1643 protocol command to execute.
1648 AtaStorageSecuritySendData (
1649 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1652 IN UINT8 SecurityProtocolId
,
1653 IN UINT16 SecurityProtocolSpecificData
,
1654 IN UINTN PayloadBufferSize
,
1655 IN VOID
*PayloadBuffer
1659 ATA_DEVICE
*Private
;
1662 DEBUG ((EFI_D_INFO
, "EFI Storage Security Protocol - Send"));
1663 if ((PayloadBuffer
== NULL
) && (PayloadBufferSize
!= 0)) {
1664 return EFI_INVALID_PARAMETER
;
1667 Status
= EFI_SUCCESS
;
1668 Private
= ATA_DEVICE_FROM_STORAGE_SECURITY (This
);
1670 if (MediaId
!= Private
->BlockIo
.Media
->MediaId
) {
1671 return EFI_MEDIA_CHANGED
;
1674 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1675 Status
= TrustTransferAtaDevice (
1679 SecurityProtocolSpecificData
,
1686 gBS
->RestoreTPL (OldTpl
);
1691 The user Entry Point for module AtaBus. The user code starts with this function.
1693 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1694 @param[in] SystemTable A pointer to the EFI System Table.
1696 @retval EFI_SUCCESS The entry point is executed successfully.
1697 @retval other Some error occurs when executing this entry point.
1703 IN EFI_HANDLE ImageHandle
,
1704 IN EFI_SYSTEM_TABLE
*SystemTable
1711 // Install driver model protocol(s).
1713 Status
= EfiLibInstallDriverBindingComponentName2 (
1716 &gAtaBusDriverBinding
,
1718 &gAtaBusComponentName
,
1719 &gAtaBusComponentName2
1721 ASSERT_EFI_ERROR (Status
);
1724 // Get the MorControl bit.
1726 DataSize
= sizeof (mMorControl
);
1727 Status
= gRT
->GetVariable (
1728 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
1729 &gEfiMemoryOverwriteControlDataGuid
,
1735 if (EFI_ERROR (Status
)) {
1736 DEBUG ((EFI_D_INFO
, "AtaBus:gEfiMemoryOverwriteControlDataGuid doesn't exist!!***\n"));
1738 Status
= EFI_SUCCESS
;
1740 DEBUG ((EFI_D_INFO
, "AtaBus:Get the gEfiMemoryOverwriteControlDataGuid = %x!!***\n", mMorControl
));
1747 Send TPer Reset command to reset eDrive to lock all protected bands.
1748 Typically, there are 2 mechanism for resetting eDrive. They are:
1749 1. TPer Reset through IEEE 1667 protocol.
1750 2. TPer Reset through native TCG protocol.
1751 This routine will detect what protocol the attached eDrive comform to, TCG or
1752 IEEE 1667 protocol. Then send out TPer Reset command separately.
1754 @param[in] AtaDevice ATA_DEVICE pointer.
1759 IN ATA_DEVICE
*AtaDevice
1770 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
1771 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Ssp
;
1772 SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*Data
;
1777 Ssp
= &AtaDevice
->StorageSecurity
;
1778 BlockIo
= &AtaDevice
->BlockIo
;
1781 // ATA8-ACS 7.57.6.1 indicates the Transfer Length field requirements a multiple of 512.
1782 // If the length of the TRUSTED RECEIVE parameter data is greater than the Transfer Length,
1783 // then the device shall return the TRUSTED RECEIVE parameter data truncated to the requested Transfer Length.
1785 Len
= ROUNDUP512(sizeof(SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
));
1786 Buffer
= AllocateZeroPool(Len
);
1788 if (Buffer
== NULL
) {
1793 // When the Security Protocol field is set to 00h, and SP Specific is set to 0000h in a TRUSTED RECEIVE
1794 // command, the device basic information data shall be returned.
1796 Status
= Ssp
->ReceiveData (
1798 BlockIo
->Media
->MediaId
,
1799 100000000, // Timeout 10-sec
1800 0, // SecurityProtocol
1801 0, // SecurityProtocolSpecifcData
1802 Len
, // PayloadBufferSize,
1803 Buffer
, // PayloadBuffer
1806 if (EFI_ERROR (Status
)) {
1811 // In returned data, the ListLength field indicates the total length, in bytes,
1812 // of the supported security protocol list.
1814 Data
= (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*)Buffer
;
1815 Len
= ROUNDUP512(sizeof (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
) +
1816 (Data
->SupportedSecurityListLength
[0] << 8) +
1817 (Data
->SupportedSecurityListLength
[1])
1821 // Free original buffer and allocate new buffer.
1824 Buffer
= AllocateZeroPool(Len
);
1825 if (Buffer
== NULL
) {
1830 // Read full supported security protocol list from device.
1832 Status
= Ssp
->ReceiveData (
1834 BlockIo
->Media
->MediaId
,
1835 100000000, // Timeout 10-sec
1836 0, // SecurityProtocol
1837 0, // SecurityProtocolSpecifcData
1838 Len
, // PayloadBufferSize,
1839 Buffer
, // PayloadBuffer
1843 if (EFI_ERROR (Status
)) {
1847 Data
= (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*)Buffer
;
1848 Len
= (Data
->SupportedSecurityListLength
[0] << 8) + Data
->SupportedSecurityListLength
[1];
1851 // Iterate full supported security protocol list to check if TCG or IEEE 1667 protocol
1854 for (Index
= 0; Index
< Len
; Index
++) {
1855 if (Data
->SupportedSecurityProtocol
[Index
] == SECURITY_PROTOCOL_TCG
) {
1857 // Found a TCG device.
1860 DEBUG ((EFI_D_INFO
, "This device is a TCG protocol device\n"));
1864 if (Data
->SupportedSecurityProtocol
[Index
] == SECURITY_PROTOCOL_IEEE1667
) {
1866 // Found a IEEE 1667 device.
1869 DEBUG ((EFI_D_INFO
, "This device is a IEEE 1667 protocol device\n"));
1874 if (!TcgFlag
&& !IeeeFlag
) {
1875 DEBUG ((EFI_D_INFO
, "Neither a TCG nor IEEE 1667 protocol device is found\n"));
1881 // As long as TCG protocol is supported, send out a TPer Reset
1882 // TCG command to the device via the TrustedSend command with a non-zero Transfer Length.
1884 Status
= Ssp
->SendData (
1886 BlockIo
->Media
->MediaId
,
1887 100000000, // Timeout 10-sec
1888 SECURITY_PROTOCOL_TCG
, // SecurityProtocol
1889 0x0400, // SecurityProtocolSpecifcData
1890 512, // PayloadBufferSize,
1891 Buffer
// PayloadBuffer
1894 if (!EFI_ERROR (Status
)) {
1895 DEBUG ((EFI_D_INFO
, "Send TPer Reset Command Successfully !\n"));
1897 DEBUG ((EFI_D_INFO
, "Send TPer Reset Command Fail !\n"));
1903 // TBD : Perform a TPer Reset via IEEE 1667 Protocol
1905 DEBUG ((EFI_D_INFO
, "IEEE 1667 Protocol didn't support yet!\n"));
1910 if (Buffer
!= NULL
) {