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 - 2015, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
16 // ATA Bus Driver Binding Protocol Instance
18 EFI_DRIVER_BINDING_PROTOCOL gAtaBusDriverBinding
= {
19 AtaBusDriverBindingSupported
,
20 AtaBusDriverBindingStart
,
21 AtaBusDriverBindingStop
,
28 // Template for ATA Child Device.
30 ATA_DEVICE gAtaDeviceTemplate
= {
31 ATA_DEVICE_SIGNATURE
, // Signature
34 EFI_BLOCK_IO_PROTOCOL_REVISION
,
38 AtaBlockIoWriteBlocks
,
44 AtaBlockIoReadBlocksEx
,
45 AtaBlockIoWriteBlocksEx
,
46 AtaBlockIoFlushBlocksEx
50 FALSE
, // RemovableMedia
52 FALSE
, // LogicPartition
54 FALSE
, // WritingCache
58 0, // LowestAlignedLba
59 1 // LogicalBlocksPerPhysicalBlock
62 EFI_DISK_INFO_IDE_INTERFACE_GUID
,
70 AtaStorageSecurityReceiveData
,
71 AtaStorageSecuritySendData
73 NULL
, // AtaBusDriverData
75 0, // PortMultiplierPort
84 NULL
, // ControllerNameTable
85 { L
'\0', }, // ModelName
86 { NULL
, NULL
}, // AtaTaskList
87 { NULL
, NULL
}, // AtaSubTaskList
92 Allocates an aligned buffer for ATA device.
94 This function allocates an aligned buffer for the ATA device to perform
95 ATA pass through operations. The alignment requirement is from ATA pass
98 @param AtaDevice The ATA child device involved for the operation.
99 @param BufferSize The request buffer size.
101 @return A pointer to the aligned buffer or NULL if the allocation fails.
105 AllocateAlignedBuffer (
106 IN ATA_DEVICE
*AtaDevice
,
110 return AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize
), AtaDevice
->AtaBusDriverData
->AtaPassThru
->Mode
->IoAlign
);
114 Frees an aligned buffer for ATA device.
116 This function frees an aligned buffer for the ATA device to perform
117 ATA pass through operations.
119 @param Buffer The aligned buffer to be freed.
120 @param BufferSize The request buffer size.
129 if (Buffer
!= NULL
) {
130 FreeAlignedPages (Buffer
, EFI_SIZE_TO_PAGES (BufferSize
));
135 Release all the resources allocated for the ATA device.
137 This function releases all the resources allocated for the ATA device.
139 @param AtaDevice The ATA child device involved for the operation.
143 ReleaseAtaResources (
144 IN ATA_DEVICE
*AtaDevice
147 ATA_BUS_ASYN_SUB_TASK
*SubTask
;
148 ATA_BUS_ASYN_TASK
*AtaTask
;
150 LIST_ENTRY
*DelEntry
;
153 FreeUnicodeStringTable (AtaDevice
->ControllerNameTable
);
154 FreeAlignedBuffer (AtaDevice
->Asb
, sizeof (EFI_ATA_STATUS_BLOCK
));
155 FreeAlignedBuffer (AtaDevice
->IdentifyData
, sizeof (ATA_IDENTIFY_DATA
));
156 if (AtaDevice
->DevicePath
!= NULL
) {
157 FreePool (AtaDevice
->DevicePath
);
160 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
161 if (!IsListEmpty (&AtaDevice
->AtaSubTaskList
)) {
163 // Free the Subtask list.
165 for (Entry
= AtaDevice
->AtaSubTaskList
.ForwardLink
;
166 Entry
!= (&AtaDevice
->AtaSubTaskList
);
170 Entry
= Entry
->ForwardLink
;
171 SubTask
= ATA_ASYN_SUB_TASK_FROM_ENTRY (DelEntry
);
173 RemoveEntryList (DelEntry
);
174 FreeAtaSubTask (SubTask
);
178 if (!IsListEmpty (&AtaDevice
->AtaTaskList
)) {
180 // Free the Subtask list.
182 for (Entry
= AtaDevice
->AtaTaskList
.ForwardLink
;
183 Entry
!= (&AtaDevice
->AtaTaskList
);
187 Entry
= Entry
->ForwardLink
;
188 AtaTask
= ATA_ASYN_TASK_FROM_ENTRY (DelEntry
);
190 RemoveEntryList (DelEntry
);
195 gBS
->RestoreTPL (OldTpl
);
196 FreePool (AtaDevice
);
200 Registers an ATA device.
202 This function allocates an ATA device structure for the ATA device specified by
203 Port and PortMultiplierPort if the ATA device is identified as a valid one.
204 Then it will create child handle and install Block IO and Disk Info protocol on
207 @param AtaBusDriverData The parent ATA bus driver data structure.
208 @param Port The port number of the ATA device.
209 @param PortMultiplierPort The port multiplier port number of the ATA device.
211 @retval EFI_SUCCESS The ATA device is successfully registered.
212 @retval EFI_OUT_OF_RESOURCES There is not enough memory to allocate the ATA device
213 and related data structures.
214 @return Others Some error occurs when registering the ATA device.
218 IN OUT ATA_BUS_DRIVER_DATA
*AtaBusDriverData
,
220 IN UINT16 PortMultiplierPort
224 ATA_DEVICE
*AtaDevice
;
225 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
226 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePathNode
;
227 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
228 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
229 EFI_HANDLE DeviceHandle
;
232 NewDevicePathNode
= NULL
;
234 RemainingDevicePath
= NULL
;
239 AtaPassThru
= AtaBusDriverData
->AtaPassThru
;
240 Status
= AtaPassThru
->BuildDevicePath (AtaPassThru
, Port
, PortMultiplierPort
, &NewDevicePathNode
);
241 if (EFI_ERROR (Status
)) {
245 DevicePath
= AppendDevicePathNode (AtaBusDriverData
->ParentDevicePath
, NewDevicePathNode
);
246 if (DevicePath
== NULL
) {
247 Status
= EFI_OUT_OF_RESOURCES
;
252 RemainingDevicePath
= DevicePath
;
253 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &DeviceHandle
);
254 if (!EFI_ERROR (Status
) && (DeviceHandle
!= NULL
) && IsDevicePathEnd (RemainingDevicePath
)) {
255 Status
= EFI_ALREADY_STARTED
;
256 FreePool (DevicePath
);
261 // Allocate ATA device from the template.
263 AtaDevice
= AllocateCopyPool (sizeof (ATA_DEVICE
), &gAtaDeviceTemplate
);
264 if (AtaDevice
== NULL
) {
265 Status
= EFI_OUT_OF_RESOURCES
;
270 // Initializes ATA device structures and allocates the required buffer.
272 AtaDevice
->BlockIo
.Media
= &AtaDevice
->BlockMedia
;
273 AtaDevice
->BlockIo2
.Media
= &AtaDevice
->BlockMedia
;
274 AtaDevice
->AtaBusDriverData
= AtaBusDriverData
;
275 AtaDevice
->DevicePath
= DevicePath
;
276 AtaDevice
->Port
= Port
;
277 AtaDevice
->PortMultiplierPort
= PortMultiplierPort
;
278 AtaDevice
->Asb
= AllocateAlignedBuffer (AtaDevice
, sizeof (EFI_ATA_STATUS_BLOCK
));
279 if (AtaDevice
->Asb
== NULL
) {
280 Status
= EFI_OUT_OF_RESOURCES
;
284 AtaDevice
->IdentifyData
= AllocateAlignedBuffer (AtaDevice
, sizeof (ATA_IDENTIFY_DATA
));
285 if (AtaDevice
->IdentifyData
== NULL
) {
286 Status
= EFI_OUT_OF_RESOURCES
;
291 // Initial Ata Task List
293 InitializeListHead (&AtaDevice
->AtaTaskList
);
294 InitializeListHead (&AtaDevice
->AtaSubTaskList
);
297 // Report Status Code to indicate the ATA device will be enabled
299 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
301 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_ENABLE
),
302 AtaBusDriverData
->ParentDevicePath
306 // Try to identify the ATA device via the ATA pass through command.
308 Status
= DiscoverAtaDevice (AtaDevice
);
309 if (EFI_ERROR (Status
)) {
314 // Build controller name for Component Name (2) protocol.
316 Status
= AddUnicodeString2 (
318 gAtaBusComponentName
.SupportedLanguages
,
319 &AtaDevice
->ControllerNameTable
,
320 AtaDevice
->ModelName
,
323 if (EFI_ERROR (Status
)) {
327 Status
= AddUnicodeString2 (
329 gAtaBusComponentName2
.SupportedLanguages
,
330 &AtaDevice
->ControllerNameTable
,
331 AtaDevice
->ModelName
,
334 if (EFI_ERROR (Status
)) {
339 // Update to AHCI interface GUID based on device path node. The default one
340 // is IDE interface GUID copied from template.
342 if (NewDevicePathNode
->SubType
== MSG_SATA_DP
) {
343 CopyGuid (&AtaDevice
->DiskInfo
.Interface
, &gEfiDiskInfoAhciInterfaceGuid
);
346 Status
= gBS
->InstallMultipleProtocolInterfaces (
348 &gEfiDevicePathProtocolGuid
,
349 AtaDevice
->DevicePath
,
350 &gEfiBlockIoProtocolGuid
,
352 &gEfiBlockIo2ProtocolGuid
,
353 &AtaDevice
->BlockIo2
,
354 &gEfiDiskInfoProtocolGuid
,
355 &AtaDevice
->DiskInfo
,
358 if (EFI_ERROR (Status
)) {
363 // See if the ata device support trust computing feature or not.
364 // If yes, then install Storage Security Protocol at the ata device handle.
366 if ((AtaDevice
->IdentifyData
->trusted_computing_support
& BIT0
) != 0) {
367 DEBUG ((DEBUG_INFO
, "Found TCG support in Port %x PortMultiplierPort %x\n", Port
, PortMultiplierPort
));
368 Status
= gBS
->InstallProtocolInterface (
370 &gEfiStorageSecurityCommandProtocolGuid
,
371 EFI_NATIVE_INTERFACE
,
372 &AtaDevice
->StorageSecurity
374 if (EFI_ERROR (Status
)) {
378 DEBUG ((DEBUG_INFO
, "Successfully Install Storage Security Protocol on the ATA device\n"));
382 AtaBusDriverData
->Controller
,
383 &gEfiAtaPassThruProtocolGuid
,
384 (VOID
**)&AtaPassThru
,
385 AtaBusDriverData
->DriverBindingHandle
,
387 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
391 if (NewDevicePathNode
!= NULL
) {
392 FreePool (NewDevicePathNode
);
395 if (EFI_ERROR (Status
) && (AtaDevice
!= NULL
)) {
396 ReleaseAtaResources (AtaDevice
);
397 DEBUG ((DEBUG_ERROR
| DEBUG_INIT
, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port
, PortMultiplierPort
, Status
));
404 Unregisters an ATA device.
406 This function removes the protocols installed on the controller handle and
407 frees the resources allocated for the ATA device.
409 @param This The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.
410 @param Controller The controller handle of the ATA device.
411 @param Handle The child handle.
413 @retval EFI_SUCCESS The ATA device is successfully unregistered.
414 @return Others Some error occurs when unregistering the ATA device.
418 UnregisterAtaDevice (
419 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
420 IN EFI_HANDLE Controller
,
425 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
426 EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
;
427 ATA_DEVICE
*AtaDevice
;
428 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
429 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*StorageSecurity
;
434 Status
= gBS
->OpenProtocol (
436 &gEfiBlockIoProtocolGuid
,
438 This
->DriverBindingHandle
,
440 EFI_OPEN_PROTOCOL_GET_PROTOCOL
442 if (EFI_ERROR (Status
)) {
444 // Locate BlockIo2 protocol
446 Status
= gBS
->OpenProtocol (
448 &gEfiBlockIo2ProtocolGuid
,
450 This
->DriverBindingHandle
,
452 EFI_OPEN_PROTOCOL_GET_PROTOCOL
454 if (EFI_ERROR (Status
)) {
460 // Get AtaDevice data.
462 if (BlockIo
!= NULL
) {
463 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (BlockIo
);
465 ASSERT (BlockIo2
!= NULL
);
466 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (BlockIo2
);
470 // Close the child handle
474 &gEfiAtaPassThruProtocolGuid
,
475 This
->DriverBindingHandle
,
480 // The Ata Bus driver installs the BlockIo and BlockIo2 in the DriverBindingStart().
481 // Here should uninstall both of them.
483 Status
= gBS
->UninstallMultipleProtocolInterfaces (
485 &gEfiDevicePathProtocolGuid
,
486 AtaDevice
->DevicePath
,
487 &gEfiBlockIoProtocolGuid
,
489 &gEfiBlockIo2ProtocolGuid
,
490 &AtaDevice
->BlockIo2
,
491 &gEfiDiskInfoProtocolGuid
,
492 &AtaDevice
->DiskInfo
,
496 if (EFI_ERROR (Status
)) {
499 &gEfiAtaPassThruProtocolGuid
,
500 (VOID
**)&AtaPassThru
,
501 This
->DriverBindingHandle
,
503 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
509 // If Storage Security Command Protocol is installed, then uninstall this protocol.
511 Status
= gBS
->OpenProtocol (
513 &gEfiStorageSecurityCommandProtocolGuid
,
514 (VOID
**)&StorageSecurity
,
515 This
->DriverBindingHandle
,
517 EFI_OPEN_PROTOCOL_GET_PROTOCOL
520 if (!EFI_ERROR (Status
)) {
521 Status
= gBS
->UninstallProtocolInterface (
523 &gEfiStorageSecurityCommandProtocolGuid
,
524 &AtaDevice
->StorageSecurity
526 if (EFI_ERROR (Status
)) {
529 &gEfiAtaPassThruProtocolGuid
,
530 (VOID
**)&AtaPassThru
,
531 This
->DriverBindingHandle
,
533 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
539 ReleaseAtaResources (AtaDevice
);
544 Tests to see if this driver supports a given controller. If a child device is provided,
545 it further tests to see if this driver supports creating a handle for the specified child device.
547 This function checks to see if the driver specified by This supports the device specified by
548 ControllerHandle. Drivers will typically use the device path attached to
549 ControllerHandle and/or the services from the bus I/O abstraction attached to
550 ControllerHandle to determine if the driver supports ControllerHandle. This function
551 may be called many times during platform initialization. In order to reduce boot times, the tests
552 performed by this function must be very small, and take as little time as possible to execute. This
553 function must not change the state of any hardware devices, and this function must be aware that the
554 device specified by ControllerHandle may already be managed by the same driver or a
555 different driver. This function must match its calls to AllocatePages() with FreePages(),
556 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
557 Since ControllerHandle may have been previously started by the same driver, if a protocol is
558 already in the opened state, then it must not be closed with CloseProtocol(). This is required
559 to guarantee the state of ControllerHandle is not modified by this function.
561 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
562 @param[in] ControllerHandle The handle of the controller to test. This handle
563 must support a protocol interface that supplies
564 an I/O abstraction to the driver.
565 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
566 parameter is ignored by device drivers, and is optional for bus
567 drivers. For bus drivers, if this parameter is not NULL, then
568 the bus driver must determine if the bus controller specified
569 by ControllerHandle and the child controller specified
570 by RemainingDevicePath are both supported by this
573 @retval EFI_SUCCESS The device specified by ControllerHandle and
574 RemainingDevicePath is supported by the driver specified by This.
575 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
576 RemainingDevicePath is already being managed by the driver
578 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
579 RemainingDevicePath is already being managed by a different
580 driver or an application that requires exclusive access.
581 Currently not implemented.
582 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
583 RemainingDevicePath is not supported by the driver specified by This.
587 AtaBusDriverBindingSupported (
588 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
589 IN EFI_HANDLE Controller
,
590 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
594 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
595 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
597 UINT16 PortMultiplierPort
;
600 // Test EFI_ATA_PASS_THRU_PROTOCOL on controller handle.
602 Status
= gBS
->OpenProtocol (
604 &gEfiAtaPassThruProtocolGuid
,
605 (VOID
**)&AtaPassThru
,
606 This
->DriverBindingHandle
,
608 EFI_OPEN_PROTOCOL_BY_DRIVER
611 if (Status
== EFI_ALREADY_STARTED
) {
615 if (EFI_ERROR (Status
)) {
620 // Test to see if this ATA Pass Thru Protocol is for a LOGICAL channel
622 if ((AtaPassThru
->Mode
->Attributes
& EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL
) == 0) {
624 // Close the I/O Abstraction(s) used to perform the supported test
628 &gEfiAtaPassThruProtocolGuid
,
629 This
->DriverBindingHandle
,
632 return EFI_UNSUPPORTED
;
636 // Test RemainingDevicePath is valid or not.
638 if ((RemainingDevicePath
!= NULL
) && !IsDevicePathEnd (RemainingDevicePath
)) {
639 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
640 if (EFI_ERROR (Status
)) {
642 // Close the I/O Abstraction(s) used to perform the supported test
646 &gEfiAtaPassThruProtocolGuid
,
647 This
->DriverBindingHandle
,
655 // Close the I/O Abstraction(s) used to perform the supported test
659 &gEfiAtaPassThruProtocolGuid
,
660 This
->DriverBindingHandle
,
665 // Open the EFI Device Path protocol needed to perform the supported test
667 Status
= gBS
->OpenProtocol (
669 &gEfiDevicePathProtocolGuid
,
670 (VOID
**)&ParentDevicePath
,
671 This
->DriverBindingHandle
,
673 EFI_OPEN_PROTOCOL_GET_PROTOCOL
679 Starts a device controller or a bus controller.
681 The Start() function is designed to be invoked from the EFI boot service ConnectController().
682 As a result, much of the error checking on the parameters to Start() has been moved into this
683 common boot service. It is legal to call Start() from other locations,
684 but the following calling restrictions must be followed or the system behavior will not be deterministic.
685 1. ControllerHandle must be a valid EFI_HANDLE.
686 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
687 EFI_DEVICE_PATH_PROTOCOL.
688 3. Prior to calling Start(), the Supported() function for the driver specified by This must
689 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
691 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
692 @param[in] ControllerHandle The handle of the controller to start. This handle
693 must support a protocol interface that supplies
694 an I/O abstraction to the driver.
695 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
696 parameter is ignored by device drivers, and is optional for bus
697 drivers. For a bus driver, if this parameter is NULL, then handles
698 for all the children of Controller are created by this driver.
699 If this parameter is not NULL and the first Device Path Node is
700 not the End of Device Path Node, then only the handle for the
701 child device specified by the first Device Path Node of
702 RemainingDevicePath is created by this driver.
703 If the first Device Path Node of RemainingDevicePath is
704 the End of Device Path Node, no child handle is created by this
707 @retval EFI_SUCCESS The device was started.
708 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
709 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
710 @retval Others The driver failed to start the device.
715 AtaBusDriverBindingStart (
716 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
717 IN EFI_HANDLE Controller
,
718 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
722 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
723 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
724 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
726 UINT16 PortMultiplierPort
;
728 AtaBusDriverData
= NULL
;
730 Status
= gBS
->OpenProtocol (
732 &gEfiDevicePathProtocolGuid
,
733 (VOID
**)&ParentDevicePath
,
734 This
->DriverBindingHandle
,
736 EFI_OPEN_PROTOCOL_GET_PROTOCOL
738 if (EFI_ERROR (Status
)) {
743 // Report Status Code to indicate ATA bus starts
745 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
747 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_INIT
),
751 Status
= gBS
->OpenProtocol (
753 &gEfiAtaPassThruProtocolGuid
,
754 (VOID
**)&AtaPassThru
,
755 This
->DriverBindingHandle
,
757 EFI_OPEN_PROTOCOL_BY_DRIVER
759 if ((EFI_ERROR (Status
)) && (Status
!= EFI_ALREADY_STARTED
)) {
764 // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.
766 if (Status
!= EFI_ALREADY_STARTED
) {
767 AtaBusDriverData
= AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA
));
768 if (AtaBusDriverData
== NULL
) {
769 Status
= EFI_OUT_OF_RESOURCES
;
773 AtaBusDriverData
->AtaPassThru
= AtaPassThru
;
774 AtaBusDriverData
->Controller
= Controller
;
775 AtaBusDriverData
->ParentDevicePath
= ParentDevicePath
;
776 AtaBusDriverData
->DriverBindingHandle
= This
->DriverBindingHandle
;
778 Status
= gBS
->InstallMultipleProtocolInterfaces (
784 if (EFI_ERROR (Status
)) {
788 Status
= gBS
->OpenProtocol (
791 (VOID
**)&AtaBusDriverData
,
792 This
->DriverBindingHandle
,
794 EFI_OPEN_PROTOCOL_GET_PROTOCOL
796 if (EFI_ERROR (Status
)) {
797 AtaBusDriverData
= NULL
;
803 // Report Status Code to indicate detecting devices on bus
805 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
807 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_DETECT
),
811 if (RemainingDevicePath
== NULL
) {
814 Status
= AtaPassThru
->GetNextPort (AtaPassThru
, &Port
);
815 if (EFI_ERROR (Status
)) {
817 // We cannot find more legal port then we are done.
822 PortMultiplierPort
= 0xFFFF;
824 Status
= AtaPassThru
->GetNextDevice (AtaPassThru
, Port
, &PortMultiplierPort
);
825 if (EFI_ERROR (Status
)) {
827 // We cannot find more legal port multiplier port number for ATA device
828 // on the port, then we are done.
833 RegisterAtaDevice (AtaBusDriverData
, Port
, PortMultiplierPort
);
837 Status
= EFI_SUCCESS
;
838 } else if (!IsDevicePathEnd (RemainingDevicePath
)) {
839 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
840 if (!EFI_ERROR (Status
)) {
841 Status
= RegisterAtaDevice (AtaBusDriverData
, Port
, PortMultiplierPort
);
849 if (AtaBusDriverData
!= NULL
) {
850 gBS
->UninstallMultipleProtocolInterfaces (
856 FreePool (AtaBusDriverData
);
861 &gEfiAtaPassThruProtocolGuid
,
862 This
->DriverBindingHandle
,
870 Stops a device controller or a bus controller.
872 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
873 As a result, much of the error checking on the parameters to Stop() has been moved
874 into this common boot service. It is legal to call Stop() from other locations,
875 but the following calling restrictions must be followed or the system behavior will not be deterministic.
876 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
877 same driver's Start() function.
878 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
879 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
880 Start() function, and the Start() function must have called OpenProtocol() on
881 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
883 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
884 @param[in] ControllerHandle A handle to the device being stopped. The handle must
885 support a bus specific I/O protocol for the driver
886 to use to stop the device.
887 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
888 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
889 if NumberOfChildren is 0.
891 @retval EFI_SUCCESS The device was stopped.
892 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
897 AtaBusDriverBindingStop (
898 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
899 IN EFI_HANDLE Controller
,
900 IN UINTN NumberOfChildren
,
901 IN EFI_HANDLE
*ChildHandleBuffer
905 BOOLEAN AllChildrenStopped
;
907 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
909 if (NumberOfChildren
== 0) {
910 Status
= gBS
->OpenProtocol (
913 (VOID
**)&AtaBusDriverData
,
914 This
->DriverBindingHandle
,
916 EFI_OPEN_PROTOCOL_GET_PROTOCOL
918 if (!EFI_ERROR (Status
)) {
919 gBS
->UninstallMultipleProtocolInterfaces (
925 FreePool (AtaBusDriverData
);
930 &gEfiAtaPassThruProtocolGuid
,
931 This
->DriverBindingHandle
,
938 AllChildrenStopped
= TRUE
;
940 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
941 Status
= UnregisterAtaDevice (This
, Controller
, ChildHandleBuffer
[Index
]);
942 if (EFI_ERROR (Status
)) {
943 AllChildrenStopped
= FALSE
;
947 if (!AllChildrenStopped
) {
948 return EFI_DEVICE_ERROR
;
955 Reset the Block Device.
957 @param This Indicates a pointer to the calling context.
958 @param ExtendedVerification Driver may perform diagnostics on reset.
960 @retval EFI_SUCCESS The device was reset.
961 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
968 IN EFI_BLOCK_IO_PROTOCOL
*This
,
969 IN BOOLEAN ExtendedVerification
973 ATA_DEVICE
*AtaDevice
;
976 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
978 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
980 Status
= ResetAtaDevice (AtaDevice
);
982 if (EFI_ERROR (Status
)) {
983 Status
= EFI_DEVICE_ERROR
;
986 gBS
->RestoreTPL (OldTpl
);
991 Read/Write BufferSize bytes from Lba from/into Buffer.
993 @param[in] This Indicates a pointer to the calling context. Either be
994 block I/O or block I/O2.
995 @param[in] MediaId The media ID that the read/write request is for.
996 @param[in] Lba The starting logical block address to be read/written.
997 The caller is responsible for reading/writing to only
998 legitimate locations.
999 @param[in, out] Token A pointer to the token associated with the transaction.
1000 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1001 @param[out] Buffer A pointer to the destination/source buffer for the data.
1002 @param[in] IsBlockIo2 Indicate the calling is from BlockIO or BlockIO2. TRUE is
1003 from BlockIO2, FALSE is for BlockIO.
1004 @param[in] IsWrite Indicates whether it is a write operation.
1006 @retval EFI_SUCCESS The data was read/written correctly to the device.
1007 @retval EFI_WRITE_PROTECTED The device can not be read/written to.
1008 @retval EFI_DEVICE_ERROR The device reported an error while performing the read/write.
1009 @retval EFI_NO_MEDIA There is no media in the device.
1010 @retval EFI_MEDIA_CHANGED The MediaId does not match the current device.
1011 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1012 @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid,
1013 or the buffer is not on proper alignment.
1021 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1022 IN UINTN BufferSize
,
1024 IN BOOLEAN IsBlockIo2
,
1028 ATA_DEVICE
*AtaDevice
;
1031 EFI_BLOCK_IO_MEDIA
*Media
;
1033 UINTN NumberOfBlocks
;
1037 Media
= ((EFI_BLOCK_IO2_PROTOCOL
*)This
)->Media
;
1038 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (This
);
1040 Media
= ((EFI_BLOCK_IO_PROTOCOL
*)This
)->Media
;
1041 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
1044 if (MediaId
!= Media
->MediaId
) {
1045 return EFI_MEDIA_CHANGED
;
1049 // Check parameters.
1051 if (Buffer
== NULL
) {
1052 return EFI_INVALID_PARAMETER
;
1055 if (BufferSize
== 0) {
1056 if ((Token
!= NULL
) && (Token
->Event
!= NULL
)) {
1057 Token
->TransactionStatus
= EFI_SUCCESS
;
1058 gBS
->SignalEvent (Token
->Event
);
1064 BlockSize
= Media
->BlockSize
;
1065 if ((BufferSize
% BlockSize
) != 0) {
1066 return EFI_BAD_BUFFER_SIZE
;
1069 NumberOfBlocks
= BufferSize
/ BlockSize
;
1070 if ((Lba
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
1071 return EFI_INVALID_PARAMETER
;
1074 IoAlign
= Media
->IoAlign
;
1075 if ((IoAlign
> 0) && (((UINTN
)Buffer
& (IoAlign
- 1)) != 0)) {
1076 return EFI_INVALID_PARAMETER
;
1079 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1082 // Invoke low level AtaDevice Access Routine.
1084 Status
= AccessAtaDevice (AtaDevice
, Buffer
, Lba
, NumberOfBlocks
, IsWrite
, Token
);
1086 gBS
->RestoreTPL (OldTpl
);
1092 Read BufferSize bytes from Lba into Buffer.
1094 @param This Indicates a pointer to the calling context.
1095 @param MediaId Id of the media, changes every time the media is replaced.
1096 @param Lba The starting Logical Block Address to read from
1097 @param BufferSize Size of Buffer, must be a multiple of device block size.
1098 @param Buffer A pointer to the destination buffer for the data. The caller is
1099 responsible for either having implicit or explicit ownership of the buffer.
1101 @retval EFI_SUCCESS The data was read correctly from the device.
1102 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
1103 @retval EFI_NO_MEDIA There is no media in the device.
1104 @retval EFI_MEDIA_CHANGED The MediaId does not match the current device.
1105 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1106 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1107 or the buffer is not on proper alignment.
1112 AtaBlockIoReadBlocks (
1113 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1116 IN UINTN BufferSize
,
1120 return BlockIoReadWrite ((VOID
*)This
, MediaId
, Lba
, NULL
, BufferSize
, Buffer
, FALSE
, FALSE
);
1124 Write BufferSize bytes from Lba into Buffer.
1126 @param This Indicates a pointer to the calling context.
1127 @param MediaId The media ID that the write request is for.
1128 @param Lba The starting logical block address to be written. The caller is
1129 responsible for writing to only legitimate locations.
1130 @param BufferSize Size of Buffer, must be a multiple of device block size.
1131 @param Buffer A pointer to the source buffer for the data.
1133 @retval EFI_SUCCESS The data was written correctly to the device.
1134 @retval EFI_WRITE_PROTECTED The device can not be written to.
1135 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1136 @retval EFI_NO_MEDIA There is no media in the device.
1137 @retval EFI_MEDIA_CHANGED The MediaId does not match the current device.
1138 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1139 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1140 or the buffer is not on proper alignment.
1145 AtaBlockIoWriteBlocks (
1146 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1149 IN UINTN BufferSize
,
1153 return BlockIoReadWrite ((VOID
*)This
, MediaId
, Lba
, NULL
, BufferSize
, Buffer
, FALSE
, TRUE
);
1157 Flush the Block Device.
1159 @param This Indicates a pointer to the calling context.
1161 @retval EFI_SUCCESS All outstanding data was written to the device
1162 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1163 @retval EFI_NO_MEDIA There is no media in the device.
1168 AtaBlockIoFlushBlocks (
1169 IN EFI_BLOCK_IO_PROTOCOL
*This
1179 Reset the Block Device.
1181 @param[in] This Indicates a pointer to the calling context.
1182 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
1184 @retval EFI_SUCCESS The device was reset.
1185 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
1192 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1193 IN BOOLEAN ExtendedVerification
1197 ATA_DEVICE
*AtaDevice
;
1200 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1202 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (This
);
1204 AtaTerminateNonBlockingTask (AtaDevice
);
1206 Status
= ResetAtaDevice (AtaDevice
);
1208 if (EFI_ERROR (Status
)) {
1209 Status
= EFI_DEVICE_ERROR
;
1212 gBS
->RestoreTPL (OldTpl
);
1217 Read BufferSize bytes from Lba into Buffer.
1219 @param[in] This Indicates a pointer to the calling context.
1220 @param[in] MediaId Id of the media, changes every time the media is replaced.
1221 @param[in] Lba The starting Logical Block Address to read from.
1222 @param[in, out] Token A pointer to the token associated with the transaction.
1223 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1224 @param[out] Buffer A pointer to the destination buffer for the data. The caller is
1225 responsible for either having implicit or explicit ownership of the buffer.
1227 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
1228 The data was read correctly from the device if
1230 @retval EFI_DEVICE_ERROR The device reported an error while performing
1232 @retval EFI_NO_MEDIA There is no media in the device.
1233 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1234 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
1235 intrinsic block size of the device.
1236 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1237 or the buffer is not on proper alignment.
1238 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
1244 AtaBlockIoReadBlocksEx (
1245 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1248 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1249 IN UINTN BufferSize
,
1253 return BlockIoReadWrite ((VOID
*)This
, MediaId
, Lba
, Token
, BufferSize
, Buffer
, TRUE
, FALSE
);
1257 Write BufferSize bytes from Lba into Buffer.
1259 @param[in] This Indicates a pointer to the calling context.
1260 @param[in] MediaId The media ID that the write request is for.
1261 @param[in] Lba The starting logical block address to be written. The
1262 caller is responsible for writing to only legitimate
1264 @param[in, out] Token A pointer to the token associated with the transaction.
1265 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1266 @param[in] Buffer A pointer to the source buffer for the data.
1268 @retval EFI_SUCCESS The data was written correctly to the device.
1269 @retval EFI_WRITE_PROTECTED The device can not be written to.
1270 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1271 @retval EFI_NO_MEDIA There is no media in the device.
1272 @retval EFI_MEDIA_CHANGED The MediaId does not match the current device.
1273 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1274 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1275 or the buffer is not on proper alignment.
1280 AtaBlockIoWriteBlocksEx (
1281 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1284 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1285 IN UINTN BufferSize
,
1289 return BlockIoReadWrite ((VOID
*)This
, MediaId
, Lba
, Token
, BufferSize
, Buffer
, TRUE
, TRUE
);
1293 Flush the Block Device.
1295 @param[in] This Indicates a pointer to the calling context.
1296 @param[in, out] Token A pointer to the token associated with the transaction.
1298 @retval EFI_SUCCESS All outstanding data was written to the device
1299 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1300 @retval EFI_NO_MEDIA There is no media in the device.
1305 AtaBlockIoFlushBlocksEx (
1306 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1307 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
1311 // Signal event and return directly.
1313 if ((Token
!= NULL
) && (Token
->Event
!= NULL
)) {
1314 Token
->TransactionStatus
= EFI_SUCCESS
;
1315 gBS
->SignalEvent (Token
->Event
);
1322 Provides inquiry information for the controller type.
1324 This function is used by the IDE bus driver to get inquiry data. Data format
1325 of Identify data is defined by the Interface GUID.
1327 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1328 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
1329 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
1331 @retval EFI_SUCCESS The command was accepted without any errors.
1332 @retval EFI_NOT_FOUND Device does not support this data class
1333 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
1334 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
1339 AtaDiskInfoInquiry (
1340 IN EFI_DISK_INFO_PROTOCOL
*This
,
1341 IN OUT VOID
*InquiryData
,
1342 IN OUT UINT32
*InquiryDataSize
1345 return EFI_NOT_FOUND
;
1349 Provides identify information for the controller type.
1351 This function is used by the IDE bus driver to get identify data. Data format
1352 of Identify data is defined by the Interface GUID.
1354 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
1356 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
1357 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
1360 @retval EFI_SUCCESS The command was accepted without any errors.
1361 @retval EFI_NOT_FOUND Device does not support this data class
1362 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
1363 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
1368 AtaDiskInfoIdentify (
1369 IN EFI_DISK_INFO_PROTOCOL
*This
,
1370 IN OUT VOID
*IdentifyData
,
1371 IN OUT UINT32
*IdentifyDataSize
1375 ATA_DEVICE
*AtaDevice
;
1377 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1379 Status
= EFI_BUFFER_TOO_SMALL
;
1380 if (*IdentifyDataSize
>= sizeof (ATA_IDENTIFY_DATA
)) {
1381 Status
= EFI_SUCCESS
;
1382 CopyMem (IdentifyData
, AtaDevice
->IdentifyData
, sizeof (ATA_IDENTIFY_DATA
));
1385 *IdentifyDataSize
= sizeof (ATA_IDENTIFY_DATA
);
1391 Provides sense data information for the controller type.
1393 This function is used by the IDE bus driver to get sense data.
1394 Data format of Sense data is defined by the Interface GUID.
1396 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1397 @param[in, out] SenseData Pointer to the SenseData.
1398 @param[in, out] SenseDataSize Size of SenseData in bytes.
1399 @param[out] SenseDataNumber Pointer to the value for the sense data size.
1401 @retval EFI_SUCCESS The command was accepted without any errors.
1402 @retval EFI_NOT_FOUND Device does not support this data class.
1403 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
1404 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
1409 AtaDiskInfoSenseData (
1410 IN EFI_DISK_INFO_PROTOCOL
*This
,
1411 IN OUT VOID
*SenseData
,
1412 IN OUT UINT32
*SenseDataSize
,
1413 OUT UINT8
*SenseDataNumber
1416 return EFI_NOT_FOUND
;
1420 This function is used by the IDE bus driver to get controller information.
1422 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1423 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
1424 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
1426 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
1427 @retval EFI_UNSUPPORTED This is not an IDE device.
1432 AtaDiskInfoWhichIde (
1433 IN EFI_DISK_INFO_PROTOCOL
*This
,
1434 OUT UINT32
*IdeChannel
,
1435 OUT UINT32
*IdeDevice
1438 ATA_DEVICE
*AtaDevice
;
1440 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1441 *IdeChannel
= AtaDevice
->Port
;
1442 *IdeDevice
= AtaDevice
->PortMultiplierPort
;
1448 Send a security protocol command to a device that receives data and/or the result
1449 of one or more commands sent by SendData.
1451 The ReceiveData function sends a security protocol command to the given MediaId.
1452 The security protocol command sent is defined by SecurityProtocolId and contains
1453 the security protocol specific data SecurityProtocolSpecificData. The function
1454 returns the data from the security protocol command in PayloadBuffer.
1456 For devices supporting the SCSI command set, the security protocol command is sent
1457 using the SECURITY PROTOCOL IN command defined in SPC-4.
1459 For devices supporting the ATA command set, the security protocol command is sent
1460 using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize
1463 If the PayloadBufferSize is zero, the security protocol command is sent using the
1464 Trusted Non-Data command defined in ATA8-ACS.
1466 If PayloadBufferSize is too small to store the available data from the security
1467 protocol command, the function shall copy PayloadBufferSize bytes into the
1468 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
1470 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
1471 the function shall return EFI_INVALID_PARAMETER.
1473 If the given MediaId does not support security protocol commands, the function shall
1474 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
1475 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
1476 the function returns EFI_MEDIA_CHANGED.
1478 If the security protocol fails to complete within the Timeout period, the function
1479 shall return EFI_TIMEOUT.
1481 If the security protocol command completes without an error, the function shall
1482 return EFI_SUCCESS. If the security protocol command completes with an error, the
1483 function shall return EFI_DEVICE_ERROR.
1485 @param This Indicates a pointer to the calling context.
1486 @param MediaId ID of the medium to receive data from.
1487 @param Timeout The timeout, in 100ns units, to use for the execution
1488 of the security protocol command. A Timeout value of 0
1489 means that this function will wait indefinitely for the
1490 security protocol command to execute. If Timeout is greater
1491 than zero, then this function will return EFI_TIMEOUT
1492 if the time required to execute the receive data command
1493 is greater than Timeout.
1494 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1495 the security protocol command to be sent.
1496 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1497 of the security protocol command to be sent.
1498 @param PayloadBufferSize Size in bytes of the payload data buffer.
1499 @param PayloadBuffer A pointer to a destination buffer to store the security
1500 protocol command specific payload data for the security
1501 protocol command. The caller is responsible for having
1502 either implicit or explicit ownership of the buffer.
1503 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
1504 data written to the payload data buffer.
1506 @retval EFI_SUCCESS The security protocol command completed successfully.
1507 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
1508 data from the device. The PayloadBuffer contains the truncated data.
1509 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1510 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1511 @retval EFI_NO_MEDIA There is no media in the device.
1512 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1513 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
1514 PayloadBufferSize is non-zero.
1515 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1516 protocol command to execute.
1521 AtaStorageSecurityReceiveData (
1522 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1525 IN UINT8 SecurityProtocolId
,
1526 IN UINT16 SecurityProtocolSpecificData
,
1527 IN UINTN PayloadBufferSize
,
1528 OUT VOID
*PayloadBuffer
,
1529 OUT UINTN
*PayloadTransferSize
1533 ATA_DEVICE
*Private
;
1536 DEBUG ((DEBUG_INFO
, "EFI Storage Security Protocol - Read\n"));
1537 if (((PayloadBuffer
== NULL
) || (PayloadTransferSize
== NULL
)) && (PayloadBufferSize
!= 0)) {
1538 return EFI_INVALID_PARAMETER
;
1541 Status
= EFI_SUCCESS
;
1542 Private
= ATA_DEVICE_FROM_STORAGE_SECURITY (This
);
1544 if (MediaId
!= Private
->BlockIo
.Media
->MediaId
) {
1545 return EFI_MEDIA_CHANGED
;
1548 if (!Private
->BlockIo
.Media
->MediaPresent
) {
1549 return EFI_NO_MEDIA
;
1552 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1554 Status
= TrustTransferAtaDevice (
1558 SecurityProtocolSpecificData
,
1565 gBS
->RestoreTPL (OldTpl
);
1570 Send a security protocol command to a device.
1572 The SendData function sends a security protocol command containing the payload
1573 PayloadBuffer to the given MediaId. The security protocol command sent is
1574 defined by SecurityProtocolId and contains the security protocol specific data
1575 SecurityProtocolSpecificData. If the underlying protocol command requires a
1576 specific padding for the command payload, the SendData function shall add padding
1577 bytes to the command payload to satisfy the padding requirements.
1579 For devices supporting the SCSI command set, the security protocol command is sent
1580 using the SECURITY PROTOCOL OUT command defined in SPC-4.
1582 For devices supporting the ATA command set, the security protocol command is sent
1583 using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize
1584 is non-zero. If the PayloadBufferSize is zero, the security protocol command is
1585 sent using the Trusted Non-Data command defined in ATA8-ACS.
1587 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
1588 return EFI_INVALID_PARAMETER.
1590 If the given MediaId does not support security protocol commands, the function
1591 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
1592 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
1593 device, the function returns EFI_MEDIA_CHANGED.
1595 If the security protocol fails to complete within the Timeout period, the function
1596 shall return EFI_TIMEOUT.
1598 If the security protocol command completes without an error, the function shall return
1599 EFI_SUCCESS. If the security protocol command completes with an error, the function
1600 shall return EFI_DEVICE_ERROR.
1602 @param This Indicates a pointer to the calling context.
1603 @param MediaId ID of the medium to receive data from.
1604 @param Timeout The timeout, in 100ns units, to use for the execution
1605 of the security protocol command. A Timeout value of 0
1606 means that this function will wait indefinitely for the
1607 security protocol command to execute. If Timeout is greater
1608 than zero, then this function will return EFI_TIMEOUT
1609 if the time required to execute the receive data command
1610 is greater than Timeout.
1611 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1612 the security protocol command to be sent.
1613 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1614 of the security protocol command to be sent.
1615 @param PayloadBufferSize Size in bytes of the payload data buffer.
1616 @param PayloadBuffer A pointer to a destination buffer to store the security
1617 protocol command specific payload data for the security
1620 @retval EFI_SUCCESS The security protocol command completed successfully.
1621 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1622 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1623 @retval EFI_NO_MEDIA There is no media in the device.
1624 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1625 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
1626 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1627 protocol command to execute.
1632 AtaStorageSecuritySendData (
1633 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1636 IN UINT8 SecurityProtocolId
,
1637 IN UINT16 SecurityProtocolSpecificData
,
1638 IN UINTN PayloadBufferSize
,
1639 IN VOID
*PayloadBuffer
1643 ATA_DEVICE
*Private
;
1646 DEBUG ((DEBUG_INFO
, "EFI Storage Security Protocol - Send\n"));
1647 if ((PayloadBuffer
== NULL
) && (PayloadBufferSize
!= 0)) {
1648 return EFI_INVALID_PARAMETER
;
1651 Status
= EFI_SUCCESS
;
1652 Private
= ATA_DEVICE_FROM_STORAGE_SECURITY (This
);
1654 if (MediaId
!= Private
->BlockIo
.Media
->MediaId
) {
1655 return EFI_MEDIA_CHANGED
;
1658 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1659 Status
= TrustTransferAtaDevice (
1663 SecurityProtocolSpecificData
,
1670 gBS
->RestoreTPL (OldTpl
);
1675 The user Entry Point for module AtaBus. The user code starts with this function.
1677 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1678 @param[in] SystemTable A pointer to the EFI System Table.
1680 @retval EFI_SUCCESS The entry point is executed successfully.
1681 @retval other Some error occurs when executing this entry point.
1687 IN EFI_HANDLE ImageHandle
,
1688 IN EFI_SYSTEM_TABLE
*SystemTable
1694 // Install driver model protocol(s).
1696 Status
= EfiLibInstallDriverBindingComponentName2 (
1699 &gAtaBusDriverBinding
,
1701 &gAtaBusComponentName
,
1702 &gAtaBusComponentName2
1704 ASSERT_EFI_ERROR (Status
);