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 - 2012, 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 RemainingDevicePath is valid or not.
635 if ((RemainingDevicePath
!= NULL
) && !IsDevicePathEnd (RemainingDevicePath
)) {
636 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
637 if (EFI_ERROR (Status
)) {
643 // Close the I/O Abstraction(s) used to perform the supported test
647 &gEfiAtaPassThruProtocolGuid
,
648 This
->DriverBindingHandle
,
653 // Open the EFI Device Path protocol needed to perform the supported test
655 Status
= gBS
->OpenProtocol (
657 &gEfiDevicePathProtocolGuid
,
658 (VOID
**) &ParentDevicePath
,
659 This
->DriverBindingHandle
,
661 EFI_OPEN_PROTOCOL_GET_PROTOCOL
668 Starts a device controller or a bus controller.
670 The Start() function is designed to be invoked from the EFI boot service ConnectController().
671 As a result, much of the error checking on the parameters to Start() has been moved into this
672 common boot service. It is legal to call Start() from other locations,
673 but the following calling restrictions must be followed or the system behavior will not be deterministic.
674 1. ControllerHandle must be a valid EFI_HANDLE.
675 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
676 EFI_DEVICE_PATH_PROTOCOL.
677 3. Prior to calling Start(), the Supported() function for the driver specified by This must
678 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
680 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
681 @param[in] ControllerHandle The handle of the controller to start. This handle
682 must support a protocol interface that supplies
683 an I/O abstraction to the driver.
684 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
685 parameter is ignored by device drivers, and is optional for bus
686 drivers. For a bus driver, if this parameter is NULL, then handles
687 for all the children of Controller are created by this driver.
688 If this parameter is not NULL and the first Device Path Node is
689 not the End of Device Path Node, then only the handle for the
690 child device specified by the first Device Path Node of
691 RemainingDevicePath is created by this driver.
692 If the first Device Path Node of RemainingDevicePath is
693 the End of Device Path Node, no child handle is created by this
696 @retval EFI_SUCCESS The device was started.
697 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
698 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
699 @retval Others The driver failded to start the device.
704 AtaBusDriverBindingStart (
705 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
706 IN EFI_HANDLE Controller
,
707 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
711 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
712 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
713 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
715 UINT16 PortMultiplierPort
;
717 AtaBusDriverData
= NULL
;
719 Status
= gBS
->OpenProtocol (
721 &gEfiDevicePathProtocolGuid
,
722 (VOID
**) &ParentDevicePath
,
723 This
->DriverBindingHandle
,
725 EFI_OPEN_PROTOCOL_GET_PROTOCOL
727 if (EFI_ERROR (Status
)) {
732 // Report Status Code to indicate ATA bus starts
734 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
736 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_INIT
),
740 Status
= gBS
->OpenProtocol (
742 &gEfiAtaPassThruProtocolGuid
,
743 (VOID
**) &AtaPassThru
,
744 This
->DriverBindingHandle
,
746 EFI_OPEN_PROTOCOL_BY_DRIVER
748 if ((EFI_ERROR (Status
)) && (Status
!= EFI_ALREADY_STARTED
)) {
753 // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.
755 if (Status
!= EFI_ALREADY_STARTED
) {
756 AtaBusDriverData
= AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA
));
757 if (AtaBusDriverData
== NULL
) {
758 Status
= EFI_OUT_OF_RESOURCES
;
762 AtaBusDriverData
->AtaPassThru
= AtaPassThru
;
763 AtaBusDriverData
->Controller
= Controller
;
764 AtaBusDriverData
->ParentDevicePath
= ParentDevicePath
;
765 AtaBusDriverData
->DriverBindingHandle
= This
->DriverBindingHandle
;
767 Status
= gBS
->InstallMultipleProtocolInterfaces (
773 if (EFI_ERROR (Status
)) {
778 Status
= gBS
->OpenProtocol (
781 (VOID
**) &AtaBusDriverData
,
782 This
->DriverBindingHandle
,
784 EFI_OPEN_PROTOCOL_GET_PROTOCOL
786 if (EFI_ERROR (Status
)) {
787 AtaBusDriverData
= NULL
;
793 // Report Status Code to indicate detecting devices on bus
795 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
797 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_DETECT
),
801 if (RemainingDevicePath
== NULL
) {
804 Status
= AtaPassThru
->GetNextPort (AtaPassThru
, &Port
);
805 if (EFI_ERROR (Status
)) {
807 // We cannot find more legal port then we are done.
812 PortMultiplierPort
= 0xFFFF;
814 Status
= AtaPassThru
->GetNextDevice (AtaPassThru
, Port
, &PortMultiplierPort
);
815 if (EFI_ERROR (Status
)) {
817 // We cannot find more legal port multiplier port number for ATA device
818 // on the port, then we are done.
822 RegisterAtaDevice (AtaBusDriverData
, Port
, PortMultiplierPort
);
825 Status
= EFI_SUCCESS
;
826 } else if (!IsDevicePathEnd (RemainingDevicePath
)) {
827 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
828 if (!EFI_ERROR (Status
)) {
829 Status
= RegisterAtaDevice (AtaBusDriverData
,Port
, PortMultiplierPort
);
837 if (AtaBusDriverData
!= NULL
) {
838 gBS
->UninstallMultipleProtocolInterfaces (
844 FreePool (AtaBusDriverData
);
849 &gEfiAtaPassThruProtocolGuid
,
850 This
->DriverBindingHandle
,
860 Stops a device controller or a bus controller.
862 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
863 As a result, much of the error checking on the parameters to Stop() has been moved
864 into this common boot service. It is legal to call Stop() from other locations,
865 but the following calling restrictions must be followed or the system behavior will not be deterministic.
866 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
867 same driver's Start() function.
868 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
869 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
870 Start() function, and the Start() function must have called OpenProtocol() on
871 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
873 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
874 @param[in] ControllerHandle A handle to the device being stopped. The handle must
875 support a bus specific I/O protocol for the driver
876 to use to stop the device.
877 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
878 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
879 if NumberOfChildren is 0.
881 @retval EFI_SUCCESS The device was stopped.
882 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
887 AtaBusDriverBindingStop (
888 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
889 IN EFI_HANDLE Controller
,
890 IN UINTN NumberOfChildren
,
891 IN EFI_HANDLE
*ChildHandleBuffer
895 BOOLEAN AllChildrenStopped
;
897 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
899 if (NumberOfChildren
== 0) {
900 Status
= gBS
->OpenProtocol (
903 (VOID
**) &AtaBusDriverData
,
904 This
->DriverBindingHandle
,
906 EFI_OPEN_PROTOCOL_GET_PROTOCOL
908 if (!EFI_ERROR (Status
)) {
909 gBS
->UninstallMultipleProtocolInterfaces (
915 FreePool (AtaBusDriverData
);
920 &gEfiAtaPassThruProtocolGuid
,
921 This
->DriverBindingHandle
,
928 AllChildrenStopped
= TRUE
;
930 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
932 Status
= UnregisterAtaDevice (This
, Controller
, ChildHandleBuffer
[Index
]);
933 if (EFI_ERROR (Status
)) {
934 AllChildrenStopped
= FALSE
;
938 if (!AllChildrenStopped
) {
939 return EFI_DEVICE_ERROR
;
947 Reset the Block Device.
949 @param This Indicates a pointer to the calling context.
950 @param ExtendedVerification Driver may perform diagnostics on reset.
952 @retval EFI_SUCCESS The device was reset.
953 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
960 IN EFI_BLOCK_IO_PROTOCOL
*This
,
961 IN BOOLEAN ExtendedVerification
965 ATA_DEVICE
*AtaDevice
;
968 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
970 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
972 Status
= ResetAtaDevice (AtaDevice
);
974 if (EFI_ERROR (Status
)) {
975 Status
= EFI_DEVICE_ERROR
;
978 gBS
->RestoreTPL (OldTpl
);
984 Read/Write BufferSize bytes from Lba from/into Buffer.
986 @param[in] This Indicates a pointer to the calling context. Either be
987 block I/O or block I/O2.
988 @param[in] MediaId The media ID that the read/write request is for.
989 @param[in] Lba The starting logical block address to be read/written.
990 The caller is responsible for reading/writing to only
991 legitimate locations.
992 @param[in, out] Token A pointer to the token associated with the transaction.
993 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
994 @param[out] Buffer A pointer to the destination/source buffer for the data.
995 @param[in] IsBlockIo2 Indicate the calling is from BlockIO or BlockIO2. TURE is
996 from BlockIO2, FALSE is for BlockIO.
997 @param[in] IsWrite Indicates whether it is a write operation.
999 @retval EFI_SUCCESS The data was read/written correctly to the device.
1000 @retval EFI_WRITE_PROTECTED The device can not be read/written to.
1001 @retval EFI_DEVICE_ERROR The device reported an error while performing the read/write.
1002 @retval EFI_NO_MEDIA There is no media in the device.
1003 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1004 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1005 @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid,
1006 or the buffer is not on proper alignment.
1014 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1015 IN UINTN BufferSize
,
1017 IN BOOLEAN IsBlockIo2
,
1021 ATA_DEVICE
*AtaDevice
;
1024 EFI_BLOCK_IO_MEDIA
*Media
;
1026 UINTN NumberOfBlocks
;
1030 Media
= ((EFI_BLOCK_IO2_PROTOCOL
*) This
)->Media
;
1031 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (This
);
1033 Media
= ((EFI_BLOCK_IO_PROTOCOL
*) This
)->Media
;
1034 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
1037 if (MediaId
!= Media
->MediaId
) {
1038 return EFI_MEDIA_CHANGED
;
1042 // Check parameters.
1044 if (Buffer
== NULL
) {
1045 return EFI_INVALID_PARAMETER
;
1048 if (BufferSize
== 0) {
1052 BlockSize
= Media
->BlockSize
;
1053 if ((BufferSize
% BlockSize
) != 0) {
1054 return EFI_BAD_BUFFER_SIZE
;
1057 NumberOfBlocks
= BufferSize
/ BlockSize
;
1058 if ((Lba
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
1059 return EFI_INVALID_PARAMETER
;
1062 IoAlign
= Media
->IoAlign
;
1063 if (IoAlign
> 0 && (((UINTN
) Buffer
& (IoAlign
- 1)) != 0)) {
1064 return EFI_INVALID_PARAMETER
;
1067 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1070 // Invoke low level AtaDevice Access Routine.
1072 Status
= AccessAtaDevice (AtaDevice
, Buffer
, Lba
, NumberOfBlocks
, IsWrite
, Token
);
1074 gBS
->RestoreTPL (OldTpl
);
1081 Read BufferSize bytes from Lba into Buffer.
1083 @param This Indicates a pointer to the calling context.
1084 @param MediaId Id of the media, changes every time the media is replaced.
1085 @param Lba The starting Logical Block Address to read from
1086 @param BufferSize Size of Buffer, must be a multiple of device block size.
1087 @param Buffer A pointer to the destination buffer for the data. The caller is
1088 responsible for either having implicit or explicit ownership of the buffer.
1090 @retval EFI_SUCCESS The data was read correctly from the device.
1091 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
1092 @retval EFI_NO_MEDIA There is no media in the device.
1093 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
1094 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1095 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1096 or the buffer is not on proper alignment.
1101 AtaBlockIoReadBlocks (
1102 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1105 IN UINTN BufferSize
,
1109 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, NULL
, BufferSize
, Buffer
, FALSE
, FALSE
);
1114 Write BufferSize bytes from Lba into Buffer.
1116 @param This Indicates a pointer to the calling context.
1117 @param MediaId The media ID that the write request is for.
1118 @param Lba The starting logical block address to be written. The caller is
1119 responsible for writing to only legitimate locations.
1120 @param BufferSize Size of Buffer, must be a multiple of device block size.
1121 @param Buffer A pointer to the source buffer for the data.
1123 @retval EFI_SUCCESS The data was written correctly to the device.
1124 @retval EFI_WRITE_PROTECTED The device can not be written to.
1125 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1126 @retval EFI_NO_MEDIA There is no media in the device.
1127 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1128 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1129 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1130 or the buffer is not on proper alignment.
1135 AtaBlockIoWriteBlocks (
1136 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1139 IN UINTN BufferSize
,
1143 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, NULL
, BufferSize
, Buffer
, FALSE
, TRUE
);
1148 Flush the Block Device.
1150 @param This Indicates a pointer to the calling context.
1152 @retval EFI_SUCCESS All outstanding data was written to the device
1153 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1154 @retval EFI_NO_MEDIA There is no media in the device.
1159 AtaBlockIoFlushBlocks (
1160 IN EFI_BLOCK_IO_PROTOCOL
*This
1170 Reset the Block Device.
1172 @param[in] This Indicates a pointer to the calling context.
1173 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
1175 @retval EFI_SUCCESS The device was reset.
1176 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
1183 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1184 IN BOOLEAN ExtendedVerification
1188 ATA_DEVICE
*AtaDevice
;
1191 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1193 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (This
);
1195 Status
= ResetAtaDevice (AtaDevice
);
1197 if (EFI_ERROR (Status
)) {
1198 Status
= EFI_DEVICE_ERROR
;
1201 gBS
->RestoreTPL (OldTpl
);
1206 Read BufferSize bytes from Lba into Buffer.
1208 @param[in] This Indicates a pointer to the calling context.
1209 @param[in] MediaId Id of the media, changes every time the media is replaced.
1210 @param[in] Lba The starting Logical Block Address to read from.
1211 @param[in, out] Token A pointer to the token associated with the transaction.
1212 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1213 @param[out] Buffer A pointer to the destination buffer for the data. The caller is
1214 responsible for either having implicit or explicit ownership of the buffer.
1216 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
1217 The data was read correctly from the device if
1219 @retval EFI_DEVICE_ERROR The device reported an error while performing
1221 @retval EFI_NO_MEDIA There is no media in the device.
1222 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1223 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
1224 intrinsic block size of the device.
1225 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1226 or the buffer is not on proper alignment.
1227 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
1233 AtaBlockIoReadBlocksEx (
1234 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1237 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1238 IN UINTN BufferSize
,
1242 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, Token
, BufferSize
, Buffer
, TRUE
, FALSE
);
1247 Write BufferSize bytes from Lba into Buffer.
1249 @param[in] This Indicates a pointer to the calling context.
1250 @param[in] MediaId The media ID that the write request is for.
1251 @param[in] Lba The starting logical block address to be written. The
1252 caller is responsible for writing to only legitimate
1254 @param[in, out] Token A pointer to the token associated with the transaction.
1255 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1256 @param[in] Buffer A pointer to the source buffer for the data.
1258 @retval EFI_SUCCESS The data was written correctly to the device.
1259 @retval EFI_WRITE_PROTECTED The device can not be written to.
1260 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1261 @retval EFI_NO_MEDIA There is no media in the device.
1262 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1263 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1264 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1265 or the buffer is not on proper alignment.
1270 AtaBlockIoWriteBlocksEx (
1271 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1274 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1275 IN UINTN BufferSize
,
1279 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, Token
, BufferSize
, Buffer
, TRUE
, TRUE
);
1284 Flush the Block Device.
1286 @param[in] This Indicates a pointer to the calling context.
1287 @param[in, out] Token A pointer to the token associated with the transaction.
1289 @retval EFI_SUCCESS All outstanding data was written to the device
1290 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1291 @retval EFI_NO_MEDIA There is no media in the device.
1296 AtaBlockIoFlushBlocksEx (
1297 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1298 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
1302 // Signal event and return directly.
1304 if (Token
!= NULL
&& Token
->Event
!= NULL
) {
1305 Token
->TransactionStatus
= EFI_SUCCESS
;
1306 gBS
->SignalEvent (Token
->Event
);
1311 Provides inquiry information for the controller type.
1313 This function is used by the IDE bus driver to get inquiry data. Data format
1314 of Identify data is defined by the Interface GUID.
1316 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1317 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
1318 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
1320 @retval EFI_SUCCESS The command was accepted without any errors.
1321 @retval EFI_NOT_FOUND Device does not support this data class
1322 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
1323 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
1328 AtaDiskInfoInquiry (
1329 IN EFI_DISK_INFO_PROTOCOL
*This
,
1330 IN OUT VOID
*InquiryData
,
1331 IN OUT UINT32
*InquiryDataSize
1334 return EFI_NOT_FOUND
;
1339 Provides identify information for the controller type.
1341 This function is used by the IDE bus driver to get identify data. Data format
1342 of Identify data is defined by the Interface GUID.
1344 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
1346 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
1347 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
1350 @retval EFI_SUCCESS The command was accepted without any errors.
1351 @retval EFI_NOT_FOUND Device does not support this data class
1352 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
1353 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
1358 AtaDiskInfoIdentify (
1359 IN EFI_DISK_INFO_PROTOCOL
*This
,
1360 IN OUT VOID
*IdentifyData
,
1361 IN OUT UINT32
*IdentifyDataSize
1365 ATA_DEVICE
*AtaDevice
;
1367 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1369 Status
= EFI_BUFFER_TOO_SMALL
;
1370 if (*IdentifyDataSize
>= sizeof (ATA_IDENTIFY_DATA
)) {
1371 Status
= EFI_SUCCESS
;
1372 CopyMem (IdentifyData
, AtaDevice
->IdentifyData
, sizeof (ATA_IDENTIFY_DATA
));
1374 *IdentifyDataSize
= sizeof (ATA_IDENTIFY_DATA
);
1381 Provides sense data information for the controller type.
1383 This function is used by the IDE bus driver to get sense data.
1384 Data format of Sense data is defined by the Interface GUID.
1386 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1387 @param[in, out] SenseData Pointer to the SenseData.
1388 @param[in, out] SenseDataSize Size of SenseData in bytes.
1389 @param[out] SenseDataNumber Pointer to the value for the sense data size.
1391 @retval EFI_SUCCESS The command was accepted without any errors.
1392 @retval EFI_NOT_FOUND Device does not support this data class.
1393 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
1394 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
1399 AtaDiskInfoSenseData (
1400 IN EFI_DISK_INFO_PROTOCOL
*This
,
1401 IN OUT VOID
*SenseData
,
1402 IN OUT UINT32
*SenseDataSize
,
1403 OUT UINT8
*SenseDataNumber
1406 return EFI_NOT_FOUND
;
1411 This function is used by the IDE bus driver to get controller information.
1413 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1414 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
1415 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
1417 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
1418 @retval EFI_UNSUPPORTED This is not an IDE device.
1423 AtaDiskInfoWhichIde (
1424 IN EFI_DISK_INFO_PROTOCOL
*This
,
1425 OUT UINT32
*IdeChannel
,
1426 OUT UINT32
*IdeDevice
1429 ATA_DEVICE
*AtaDevice
;
1431 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1432 *IdeChannel
= AtaDevice
->Port
;
1433 *IdeDevice
= AtaDevice
->PortMultiplierPort
;
1439 Send a security protocol command to a device that receives data and/or the result
1440 of one or more commands sent by SendData.
1442 The ReceiveData function sends a security protocol command to the given MediaId.
1443 The security protocol command sent is defined by SecurityProtocolId and contains
1444 the security protocol specific data SecurityProtocolSpecificData. The function
1445 returns the data from the security protocol command in PayloadBuffer.
1447 For devices supporting the SCSI command set, the security protocol command is sent
1448 using the SECURITY PROTOCOL IN command defined in SPC-4.
1450 For devices supporting the ATA command set, the security protocol command is sent
1451 using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize
1454 If the PayloadBufferSize is zero, the security protocol command is sent using the
1455 Trusted Non-Data command defined in ATA8-ACS.
1457 If PayloadBufferSize is too small to store the available data from the security
1458 protocol command, the function shall copy PayloadBufferSize bytes into the
1459 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
1461 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
1462 the function shall return EFI_INVALID_PARAMETER.
1464 If the given MediaId does not support security protocol commands, the function shall
1465 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
1466 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
1467 the function returns EFI_MEDIA_CHANGED.
1469 If the security protocol fails to complete within the Timeout period, the function
1470 shall return EFI_TIMEOUT.
1472 If the security protocol command completes without an error, the function shall
1473 return EFI_SUCCESS. If the security protocol command completes with an error, the
1474 function shall return EFI_DEVICE_ERROR.
1476 @param This Indicates a pointer to the calling context.
1477 @param MediaId ID of the medium to receive data from.
1478 @param Timeout The timeout, in 100ns units, to use for the execution
1479 of the security protocol command. A Timeout value of 0
1480 means that this function will wait indefinitely for the
1481 security protocol command to execute. If Timeout is greater
1482 than zero, then this function will return EFI_TIMEOUT
1483 if the time required to execute the receive data command
1484 is greater than Timeout.
1485 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1486 the security protocol command to be sent.
1487 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1488 of the security protocol command to be sent.
1489 @param PayloadBufferSize Size in bytes of the payload data buffer.
1490 @param PayloadBuffer A pointer to a destination buffer to store the security
1491 protocol command specific payload data for the security
1492 protocol command. The caller is responsible for having
1493 either implicit or explicit ownership of the buffer.
1494 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
1495 data written to the payload data buffer.
1497 @retval EFI_SUCCESS The security protocol command completed successfully.
1498 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
1499 data from the device. The PayloadBuffer contains the truncated data.
1500 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1501 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1502 @retval EFI_NO_MEDIA There is no media in the device.
1503 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1504 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
1505 PayloadBufferSize is non-zero.
1506 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1507 protocol command to execute.
1512 AtaStorageSecurityReceiveData (
1513 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1516 IN UINT8 SecurityProtocolId
,
1517 IN UINT16 SecurityProtocolSpecificData
,
1518 IN UINTN PayloadBufferSize
,
1519 OUT VOID
*PayloadBuffer
,
1520 OUT UINTN
*PayloadTransferSize
1524 ATA_DEVICE
*Private
;
1527 DEBUG ((EFI_D_INFO
, "EFI Storage Security Protocol - Read"));
1528 if ((PayloadBuffer
== NULL
|| PayloadTransferSize
== NULL
) && PayloadBufferSize
!= 0) {
1529 return EFI_INVALID_PARAMETER
;
1532 Status
= EFI_SUCCESS
;
1533 Private
= ATA_DEVICE_FROM_STORAGE_SECURITY (This
);
1535 if (MediaId
!= Private
->BlockIo
.Media
->MediaId
) {
1536 return EFI_MEDIA_CHANGED
;
1539 if (!Private
->BlockIo
.Media
->MediaPresent
) {
1540 return EFI_NO_MEDIA
;
1543 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1545 Status
= TrustTransferAtaDevice (
1549 SecurityProtocolSpecificData
,
1556 gBS
->RestoreTPL (OldTpl
);
1561 Send a security protocol command to a device.
1563 The SendData function sends a security protocol command containing the payload
1564 PayloadBuffer to the given MediaId. The security protocol command sent is
1565 defined by SecurityProtocolId and contains the security protocol specific data
1566 SecurityProtocolSpecificData. If the underlying protocol command requires a
1567 specific padding for the command payload, the SendData function shall add padding
1568 bytes to the command payload to satisfy the padding requirements.
1570 For devices supporting the SCSI command set, the security protocol command is sent
1571 using the SECURITY PROTOCOL OUT command defined in SPC-4.
1573 For devices supporting the ATA command set, the security protocol command is sent
1574 using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize
1575 is non-zero. If the PayloadBufferSize is zero, the security protocol command is
1576 sent using the Trusted Non-Data command defined in ATA8-ACS.
1578 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
1579 return EFI_INVALID_PARAMETER.
1581 If the given MediaId does not support security protocol commands, the function
1582 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
1583 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
1584 device, the function returns EFI_MEDIA_CHANGED.
1586 If the security protocol fails to complete within the Timeout period, the function
1587 shall return EFI_TIMEOUT.
1589 If the security protocol command completes without an error, the function shall return
1590 EFI_SUCCESS. If the security protocol command completes with an error, the function
1591 shall return EFI_DEVICE_ERROR.
1593 @param This Indicates a pointer to the calling context.
1594 @param MediaId ID of the medium to receive data from.
1595 @param Timeout The timeout, in 100ns units, to use for the execution
1596 of the security protocol command. A Timeout value of 0
1597 means that this function will wait indefinitely for the
1598 security protocol command to execute. If Timeout is greater
1599 than zero, then this function will return EFI_TIMEOUT
1600 if the time required to execute the receive data command
1601 is greater than Timeout.
1602 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1603 the security protocol command to be sent.
1604 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1605 of the security protocol command to be sent.
1606 @param PayloadBufferSize Size in bytes of the payload data buffer.
1607 @param PayloadBuffer A pointer to a destination buffer to store the security
1608 protocol command specific payload data for the security
1611 @retval EFI_SUCCESS The security protocol command completed successfully.
1612 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1613 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1614 @retval EFI_NO_MEDIA There is no media in the device.
1615 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1616 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
1617 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1618 protocol command to execute.
1623 AtaStorageSecuritySendData (
1624 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1627 IN UINT8 SecurityProtocolId
,
1628 IN UINT16 SecurityProtocolSpecificData
,
1629 IN UINTN PayloadBufferSize
,
1630 IN VOID
*PayloadBuffer
1634 ATA_DEVICE
*Private
;
1637 DEBUG ((EFI_D_INFO
, "EFI Storage Security Protocol - Send"));
1638 if ((PayloadBuffer
== NULL
) && (PayloadBufferSize
!= 0)) {
1639 return EFI_INVALID_PARAMETER
;
1642 Status
= EFI_SUCCESS
;
1643 Private
= ATA_DEVICE_FROM_STORAGE_SECURITY (This
);
1645 if (MediaId
!= Private
->BlockIo
.Media
->MediaId
) {
1646 return EFI_MEDIA_CHANGED
;
1649 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1650 Status
= TrustTransferAtaDevice (
1654 SecurityProtocolSpecificData
,
1661 gBS
->RestoreTPL (OldTpl
);
1666 The user Entry Point for module AtaBus. The user code starts with this function.
1668 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1669 @param[in] SystemTable A pointer to the EFI System Table.
1671 @retval EFI_SUCCESS The entry point is executed successfully.
1672 @retval other Some error occurs when executing this entry point.
1678 IN EFI_HANDLE ImageHandle
,
1679 IN EFI_SYSTEM_TABLE
*SystemTable
1686 // Install driver model protocol(s).
1688 Status
= EfiLibInstallDriverBindingComponentName2 (
1691 &gAtaBusDriverBinding
,
1693 &gAtaBusComponentName
,
1694 &gAtaBusComponentName2
1696 ASSERT_EFI_ERROR (Status
);
1699 // Get the MorControl bit.
1701 DataSize
= sizeof (mMorControl
);
1702 Status
= gRT
->GetVariable (
1703 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
1704 &gEfiMemoryOverwriteControlDataGuid
,
1710 if (EFI_ERROR (Status
)) {
1711 DEBUG ((EFI_D_INFO
, "AtaBus:gEfiMemoryOverwriteControlDataGuid doesn't exist!!***\n"));
1713 Status
= EFI_SUCCESS
;
1715 DEBUG ((EFI_D_INFO
, "AtaBus:Get the gEfiMemoryOverwriteControlDataGuid = %x!!***\n", mMorControl
));
1722 Send TPer Reset command to reset eDrive to lock all protected bands.
1723 Typically, there are 2 mechanism for resetting eDrive. They are:
1724 1. TPer Reset through IEEE 1667 protocol.
1725 2. TPer Reset through native TCG protocol.
1726 This routine will detect what protocol the attached eDrive comform to, TCG or
1727 IEEE 1667 protocol. Then send out TPer Reset command separately.
1729 @param[in] AtaDevice ATA_DEVICE pointer.
1734 IN ATA_DEVICE
*AtaDevice
1745 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
1746 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Ssp
;
1747 SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*Data
;
1752 Ssp
= &AtaDevice
->StorageSecurity
;
1753 BlockIo
= &AtaDevice
->BlockIo
;
1756 // ATA8-ACS 7.57.6.1 indicates the Transfer Length field requirements a multiple of 512.
1757 // If the length of the TRUSTED RECEIVE parameter data is greater than the Transfer Length,
1758 // then the device shall return the TRUSTED RECEIVE parameter data truncated to the requested Transfer Length.
1760 Len
= ROUNDUP512(sizeof(SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
));
1761 Buffer
= AllocateZeroPool(Len
);
1763 if (Buffer
== NULL
) {
1768 // When the Security Protocol field is set to 00h, and SP Specific is set to 0000h in a TRUSTED RECEIVE
1769 // command, the device basic information data shall be returned.
1771 Status
= Ssp
->ReceiveData (
1773 BlockIo
->Media
->MediaId
,
1774 100000000, // Timeout 10-sec
1775 0, // SecurityProtocol
1776 0, // SecurityProtocolSpecifcData
1777 Len
, // PayloadBufferSize,
1778 Buffer
, // PayloadBuffer
1781 if (EFI_ERROR (Status
)) {
1786 // In returned data, the ListLength field indicates the total length, in bytes,
1787 // of the supported security protocol list.
1789 Data
= (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*)Buffer
;
1790 Len
= ROUNDUP512(sizeof (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
) +
1791 (Data
->SupportedSecurityListLength
[0] << 8) +
1792 (Data
->SupportedSecurityListLength
[1])
1796 // Free original buffer and allocate new buffer.
1799 Buffer
= AllocateZeroPool(Len
);
1800 if (Buffer
== NULL
) {
1805 // Read full supported security protocol list from device.
1807 Status
= Ssp
->ReceiveData (
1809 BlockIo
->Media
->MediaId
,
1810 100000000, // Timeout 10-sec
1811 0, // SecurityProtocol
1812 0, // SecurityProtocolSpecifcData
1813 Len
, // PayloadBufferSize,
1814 Buffer
, // PayloadBuffer
1818 if (EFI_ERROR (Status
)) {
1822 Data
= (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*)Buffer
;
1823 Len
= (Data
->SupportedSecurityListLength
[0] << 8) + Data
->SupportedSecurityListLength
[1];
1826 // Iterate full supported security protocol list to check if TCG or IEEE 1667 protocol
1829 for (Index
= 0; Index
< Len
; Index
++) {
1830 if (Data
->SupportedSecurityProtocol
[Index
] == SECURITY_PROTOCOL_TCG
) {
1832 // Found a TCG device.
1835 DEBUG ((EFI_D_INFO
, "This device is a TCG protocol device\n"));
1839 if (Data
->SupportedSecurityProtocol
[Index
] == SECURITY_PROTOCOL_IEEE1667
) {
1841 // Found a IEEE 1667 device.
1844 DEBUG ((EFI_D_INFO
, "This device is a IEEE 1667 protocol device\n"));
1849 if (!TcgFlag
&& !IeeeFlag
) {
1850 DEBUG ((EFI_D_INFO
, "Neither a TCG nor IEEE 1667 protocol device is found\n"));
1856 // As long as TCG protocol is supported, send out a TPer Reset
1857 // TCG command to the device via the TrustedSend command with a non-zero Transfer Length.
1859 Status
= Ssp
->SendData (
1861 BlockIo
->Media
->MediaId
,
1862 100000000, // Timeout 10-sec
1863 SECURITY_PROTOCOL_TCG
, // SecurityProtocol
1864 0x0400, // SecurityProtocolSpecifcData
1865 512, // PayloadBufferSize,
1866 Buffer
// PayloadBuffer
1869 if (!EFI_ERROR (Status
)) {
1870 DEBUG ((EFI_D_INFO
, "Send TPer Reset Command Successfully !\n"));
1872 DEBUG ((EFI_D_INFO
, "Send TPer Reset Command Fail !\n"));
1878 // TBD : Perform a TPer Reset via IEEE 1667 Protocol
1880 DEBUG ((EFI_D_INFO
, "IEEE 1667 Protocol didn't support yet!\n"));
1885 if (Buffer
!= NULL
) {