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 - 2011, 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.
22 // ATA Bus Driver Binding Protocol Instance
24 EFI_DRIVER_BINDING_PROTOCOL gAtaBusDriverBinding
= {
25 AtaBusDriverBindingSupported
,
26 AtaBusDriverBindingStart
,
27 AtaBusDriverBindingStop
,
34 // Template for ATA Child Device.
36 ATA_DEVICE gAtaDeviceTemplate
= {
37 ATA_DEVICE_SIGNATURE
, // Signature
40 EFI_BLOCK_IO_PROTOCOL_REVISION
,
44 AtaBlockIoWriteBlocks
,
50 AtaBlockIoReadBlocksEx
,
51 AtaBlockIoWriteBlocksEx
,
52 AtaBlockIoFlushBlocksEx
56 FALSE
, // RemovableMedia
58 FALSE
, // LogicPartition
60 FALSE
, // WritingCache
64 0, // LowestAlignedLba
65 1 // LogicalBlocksPerPhysicalBlock
68 EFI_DISK_INFO_IDE_INTERFACE_GUID
,
76 AtaStorageSecurityReceiveData
,
77 AtaStorageSecuritySendData
79 NULL
, // AtaBusDriverData
81 0, // PortMultiplierPort
88 NULL
, // ControllerNameTable
89 {L
'\0', }, // ModelName
90 {NULL
, NULL
} // AtaTaskList
94 Allocates an aligned buffer for ATA device.
96 This function allocates an aligned buffer for the ATA device to perform
97 ATA pass through operations. The alignment requirement is from ATA pass
100 @param AtaDevice The ATA child device involved for the operation.
101 @param BufferSize The request buffer size.
103 @return A pointer to the aligned buffer or NULL if the allocation fails.
107 AllocateAlignedBuffer (
108 IN ATA_DEVICE
*AtaDevice
,
112 return AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize
), AtaDevice
->AtaBusDriverData
->AtaPassThru
->Mode
->IoAlign
);
116 Frees an aligned buffer for ATA device.
118 This function frees an aligned buffer for the ATA device to perform
119 ATA pass through operations.
121 @param Buffer The aligned buffer to be freed.
122 @param BufferSize The request buffer size.
131 if (Buffer
!= NULL
) {
132 FreePages (Buffer
, EFI_SIZE_TO_PAGES (BufferSize
));
138 Release all the resources allocated for the ATA device.
140 This function releases all the resources allocated for the ATA device.
142 @param AtaDevice The ATA child device involved for the operation.
146 ReleaseAtaResources (
147 IN ATA_DEVICE
*AtaDevice
150 ATA_BUS_ASYN_TASK
*Task
;
152 LIST_ENTRY
*DelEntry
;
155 FreeUnicodeStringTable (AtaDevice
->ControllerNameTable
);
156 FreeAlignedBuffer (AtaDevice
->Asb
, sizeof (*AtaDevice
->Asb
));
157 FreeAlignedBuffer (AtaDevice
->IdentifyData
, sizeof (*AtaDevice
->IdentifyData
));
158 if (AtaDevice
->DevicePath
!= NULL
) {
159 FreePool (AtaDevice
->DevicePath
);
161 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
162 if (!IsListEmpty (&AtaDevice
->AtaTaskList
)) {
164 // Free the Subtask list.
166 for(Entry
= (&AtaDevice
->AtaTaskList
)->ForwardLink
;
167 Entry
!= (&AtaDevice
->AtaTaskList
);
170 Entry
= Entry
->ForwardLink
;
171 Task
= ATA_AYNS_TASK_FROM_ENTRY (DelEntry
);
173 RemoveEntryList (DelEntry
);
174 FreeAtaSubTask (Task
);
177 gBS
->RestoreTPL (OldTpl
);
178 FreePool (AtaDevice
);
183 Registers an ATA device.
185 This function allocates an ATA device structure for the ATA device specified by
186 Port and PortMultiplierPort if the ATA device is identified as a valid one.
187 Then it will create child handle and install Block IO and Disk Info protocol on
190 @param AtaBusDriverData The parent ATA bus driver data structure.
191 @param Port The port number of the ATA device.
192 @param PortMultiplierPort The port multiplier port number of the ATA device.
194 @retval EFI_SUCCESS The ATA device is successfully registered.
195 @retval EFI_OUT_OF_RESOURCES There is not enough memory to allocate the ATA device
196 and related data structures.
197 @return Others Some error occurs when registering the ATA device.
201 IN OUT ATA_BUS_DRIVER_DATA
*AtaBusDriverData
,
203 IN UINT16 PortMultiplierPort
207 ATA_DEVICE
*AtaDevice
;
208 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
209 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePathNode
;
210 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
211 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
212 EFI_HANDLE DeviceHandle
;
215 NewDevicePathNode
= NULL
;
217 RemainingDevicePath
= NULL
;
222 AtaPassThru
= AtaBusDriverData
->AtaPassThru
;
223 Status
= AtaPassThru
->BuildDevicePath (AtaPassThru
, Port
, PortMultiplierPort
, &NewDevicePathNode
);
224 if (EFI_ERROR (Status
)) {
228 DevicePath
= AppendDevicePathNode (AtaBusDriverData
->ParentDevicePath
, NewDevicePathNode
);
229 if (DevicePath
== NULL
) {
230 Status
= EFI_OUT_OF_RESOURCES
;
235 RemainingDevicePath
= DevicePath
;
236 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &DeviceHandle
);
237 if (!EFI_ERROR (Status
) && (DeviceHandle
!= NULL
) && IsDevicePathEnd(RemainingDevicePath
)) {
238 Status
= EFI_ALREADY_STARTED
;
239 FreePool (DevicePath
);
244 // Allocate ATA device from the template.
246 AtaDevice
= AllocateCopyPool (sizeof (gAtaDeviceTemplate
), &gAtaDeviceTemplate
);
247 if (AtaDevice
== NULL
) {
248 Status
= EFI_OUT_OF_RESOURCES
;
253 // Initializes ATA device structures and allocates the required buffer.
255 AtaDevice
->BlockIo
.Media
= &AtaDevice
->BlockMedia
;
256 AtaDevice
->BlockIo2
.Media
= &AtaDevice
->BlockMedia
;
257 AtaDevice
->AtaBusDriverData
= AtaBusDriverData
;
258 AtaDevice
->DevicePath
= DevicePath
;
259 AtaDevice
->Port
= Port
;
260 AtaDevice
->PortMultiplierPort
= PortMultiplierPort
;
261 AtaDevice
->Asb
= AllocateAlignedBuffer (AtaDevice
, sizeof (*AtaDevice
->Asb
));
262 if (AtaDevice
->Asb
== NULL
) {
263 Status
= EFI_OUT_OF_RESOURCES
;
266 AtaDevice
->IdentifyData
= AllocateAlignedBuffer (AtaDevice
, sizeof (*AtaDevice
->IdentifyData
));
267 if (AtaDevice
->IdentifyData
== NULL
) {
268 Status
= EFI_OUT_OF_RESOURCES
;
273 // Initial Ata Task List
275 InitializeListHead (&AtaDevice
->AtaTaskList
);
278 // Try to identify the ATA device via the ATA pass through command.
280 Status
= DiscoverAtaDevice (AtaDevice
);
281 if (EFI_ERROR (Status
)) {
286 // Build controller name for Component Name (2) protocol.
288 Status
= AddUnicodeString2 (
290 gAtaBusComponentName
.SupportedLanguages
,
291 &AtaDevice
->ControllerNameTable
,
292 AtaDevice
->ModelName
,
295 if (EFI_ERROR (Status
)) {
299 Status
= AddUnicodeString2 (
301 gAtaBusComponentName2
.SupportedLanguages
,
302 &AtaDevice
->ControllerNameTable
,
303 AtaDevice
->ModelName
,
306 if (EFI_ERROR (Status
)) {
311 // Update to AHCI interface GUID based on device path node. The default one
312 // is IDE interface GUID copied from template.
314 if (NewDevicePathNode
->SubType
== MSG_SATA_DP
) {
315 CopyGuid (&AtaDevice
->DiskInfo
.Interface
, &gEfiDiskInfoAhciInterfaceGuid
);
318 Status
= gBS
->InstallMultipleProtocolInterfaces (
320 &gEfiDevicePathProtocolGuid
,
321 AtaDevice
->DevicePath
,
322 &gEfiBlockIoProtocolGuid
,
324 &gEfiBlockIo2ProtocolGuid
,
325 &AtaDevice
->BlockIo2
,
326 &gEfiDiskInfoProtocolGuid
,
327 &AtaDevice
->DiskInfo
,
330 if (EFI_ERROR (Status
)) {
335 // See if the ata device support trust computing feature or not.
336 // If yes, then install Storage Security Protocol at the ata device handle.
338 if ((AtaDevice
->IdentifyData
->trusted_computing_support
& BIT0
) != 0) {
339 DEBUG ((EFI_D_INFO
, "Found TCG support in Port %x PortMultiplierPort %x\n", Port
, PortMultiplierPort
));
340 Status
= gBS
->InstallProtocolInterface (
342 &gEfiStorageSecurityCommandProtocolGuid
,
343 EFI_NATIVE_INTERFACE
,
344 &AtaDevice
->StorageSecurity
346 if (EFI_ERROR (Status
)) {
352 AtaBusDriverData
->Controller
,
353 &gEfiAtaPassThruProtocolGuid
,
354 (VOID
**) &AtaPassThru
,
355 AtaBusDriverData
->DriverBindingHandle
,
357 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
361 if (NewDevicePathNode
!= NULL
) {
362 FreePool (NewDevicePathNode
);
365 if (EFI_ERROR (Status
) && (AtaDevice
!= NULL
)) {
366 ReleaseAtaResources (AtaDevice
);
367 DEBUG ((DEBUG_ERROR
| DEBUG_INIT
, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port
, PortMultiplierPort
, Status
));
374 Unregisters an ATA device.
376 This function removes the protocols installed on the controller handle and
377 frees the resources allocated for the ATA device.
379 @param This The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.
380 @param Controller The controller handle of the ATA device.
381 @param Handle The child handle.
383 @retval EFI_SUCCESS The ATA device is successfully unregistered.
384 @return Others Some error occurs when unregistering the ATA device.
388 UnregisterAtaDevice (
389 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
390 IN EFI_HANDLE Controller
,
395 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
396 EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
;
397 ATA_DEVICE
*AtaDevice
;
398 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
399 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*StorageSecurity
;
404 Status
= gBS
->OpenProtocol (
406 &gEfiBlockIoProtocolGuid
,
408 This
->DriverBindingHandle
,
410 EFI_OPEN_PROTOCOL_GET_PROTOCOL
412 if (EFI_ERROR (Status
)) {
414 // Locate BlockIo2 protocol
416 Status
= gBS
->OpenProtocol (
418 &gEfiBlockIo2ProtocolGuid
,
420 This
->DriverBindingHandle
,
422 EFI_OPEN_PROTOCOL_GET_PROTOCOL
424 if (EFI_ERROR (Status
)) {
430 // Get AtaDevice data.
432 if (BlockIo
!= NULL
) {
433 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (BlockIo
);
435 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (BlockIo2
);
439 // Close the child handle
443 &gEfiAtaPassThruProtocolGuid
,
444 This
->DriverBindingHandle
,
449 // The Ata Bus driver installs the BlockIo and BlockIo2 in the DriverBindingStart().
450 // Here should uninstall both of them.
452 Status
= gBS
->UninstallMultipleProtocolInterfaces (
454 &gEfiDevicePathProtocolGuid
,
455 AtaDevice
->DevicePath
,
456 &gEfiBlockIoProtocolGuid
,
458 &gEfiBlockIo2ProtocolGuid
,
459 &AtaDevice
->BlockIo2
,
460 &gEfiDiskInfoProtocolGuid
,
461 &AtaDevice
->DiskInfo
,
465 if (EFI_ERROR (Status
)) {
468 &gEfiAtaPassThruProtocolGuid
,
469 (VOID
**) &AtaPassThru
,
470 This
->DriverBindingHandle
,
472 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
478 // If Storage Security Command Protocol is installed, then uninstall this protocol.
480 Status
= gBS
->OpenProtocol (
482 &gEfiStorageSecurityCommandProtocolGuid
,
483 (VOID
**) &StorageSecurity
,
484 This
->DriverBindingHandle
,
486 EFI_OPEN_PROTOCOL_GET_PROTOCOL
489 if (!EFI_ERROR (Status
)) {
490 Status
= gBS
->UninstallProtocolInterface (
492 &gEfiStorageSecurityCommandProtocolGuid
,
493 &AtaDevice
->StorageSecurity
495 if (EFI_ERROR (Status
)) {
498 &gEfiAtaPassThruProtocolGuid
,
499 (VOID
**) &AtaPassThru
,
500 This
->DriverBindingHandle
,
502 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
508 ReleaseAtaResources (AtaDevice
);
515 Tests to see if this driver supports a given controller. If a child device is provided,
516 it further tests to see if this driver supports creating a handle for the specified child device.
518 This function checks to see if the driver specified by This supports the device specified by
519 ControllerHandle. Drivers will typically use the device path attached to
520 ControllerHandle and/or the services from the bus I/O abstraction attached to
521 ControllerHandle to determine if the driver supports ControllerHandle. This function
522 may be called many times during platform initialization. In order to reduce boot times, the tests
523 performed by this function must be very small, and take as little time as possible to execute. This
524 function must not change the state of any hardware devices, and this function must be aware that the
525 device specified by ControllerHandle may already be managed by the same driver or a
526 different driver. This function must match its calls to AllocatePages() with FreePages(),
527 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
528 Since ControllerHandle may have been previously started by the same driver, if a protocol is
529 already in the opened state, then it must not be closed with CloseProtocol(). This is required
530 to guarantee the state of ControllerHandle is not modified by this function.
532 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
533 @param[in] ControllerHandle The handle of the controller to test. This handle
534 must support a protocol interface that supplies
535 an I/O abstraction to the driver.
536 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
537 parameter is ignored by device drivers, and is optional for bus
538 drivers. For bus drivers, if this parameter is not NULL, then
539 the bus driver must determine if the bus controller specified
540 by ControllerHandle and the child controller specified
541 by RemainingDevicePath are both supported by this
544 @retval EFI_SUCCESS The device specified by ControllerHandle and
545 RemainingDevicePath is supported by the driver specified by This.
546 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
547 RemainingDevicePath is already being managed by the driver
549 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
550 RemainingDevicePath is already being managed by a different
551 driver or an application that requires exclusive access.
552 Currently not implemented.
553 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
554 RemainingDevicePath is not supported by the driver specified by This.
558 AtaBusDriverBindingSupported (
559 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
560 IN EFI_HANDLE Controller
,
561 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
565 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
566 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
568 UINT16 PortMultiplierPort
;
571 // Test EFI_ATA_PASS_THRU_PROTOCOL on controller handle.
573 Status
= gBS
->OpenProtocol (
575 &gEfiAtaPassThruProtocolGuid
,
576 (VOID
**) &AtaPassThru
,
577 This
->DriverBindingHandle
,
579 EFI_OPEN_PROTOCOL_BY_DRIVER
582 if (Status
== EFI_ALREADY_STARTED
) {
586 if (EFI_ERROR (Status
)) {
591 // Test RemainingDevicePath is valid or not.
593 if ((RemainingDevicePath
!= NULL
) && !IsDevicePathEnd (RemainingDevicePath
)) {
594 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
595 if (EFI_ERROR (Status
)) {
601 // Close the I/O Abstraction(s) used to perform the supported test
605 &gEfiAtaPassThruProtocolGuid
,
606 This
->DriverBindingHandle
,
611 // Open the EFI Device Path protocol needed to perform the supported test
613 Status
= gBS
->OpenProtocol (
615 &gEfiDevicePathProtocolGuid
,
616 (VOID
**) &ParentDevicePath
,
617 This
->DriverBindingHandle
,
619 EFI_OPEN_PROTOCOL_GET_PROTOCOL
626 Starts a device controller or a bus controller.
628 The Start() function is designed to be invoked from the EFI boot service ConnectController().
629 As a result, much of the error checking on the parameters to Start() has been moved into this
630 common boot service. It is legal to call Start() from other locations,
631 but the following calling restrictions must be followed or the system behavior will not be deterministic.
632 1. ControllerHandle must be a valid EFI_HANDLE.
633 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
634 EFI_DEVICE_PATH_PROTOCOL.
635 3. Prior to calling Start(), the Supported() function for the driver specified by This must
636 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
638 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
639 @param[in] ControllerHandle The handle of the controller to start. This handle
640 must support a protocol interface that supplies
641 an I/O abstraction to the driver.
642 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
643 parameter is ignored by device drivers, and is optional for bus
644 drivers. For a bus driver, if this parameter is NULL, then handles
645 for all the children of Controller are created by this driver.
646 If this parameter is not NULL and the first Device Path Node is
647 not the End of Device Path Node, then only the handle for the
648 child device specified by the first Device Path Node of
649 RemainingDevicePath is created by this driver.
650 If the first Device Path Node of RemainingDevicePath is
651 the End of Device Path Node, no child handle is created by this
654 @retval EFI_SUCCESS The device was started.
655 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
656 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
657 @retval Others The driver failded to start the device.
662 AtaBusDriverBindingStart (
663 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
664 IN EFI_HANDLE Controller
,
665 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
669 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
670 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
671 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
673 UINT16 PortMultiplierPort
;
675 AtaBusDriverData
= NULL
;
677 Status
= gBS
->OpenProtocol (
679 &gEfiDevicePathProtocolGuid
,
680 (VOID
**) &ParentDevicePath
,
681 This
->DriverBindingHandle
,
683 EFI_OPEN_PROTOCOL_GET_PROTOCOL
685 if (EFI_ERROR (Status
)) {
689 Status
= gBS
->OpenProtocol (
691 &gEfiAtaPassThruProtocolGuid
,
692 (VOID
**) &AtaPassThru
,
693 This
->DriverBindingHandle
,
695 EFI_OPEN_PROTOCOL_BY_DRIVER
697 if ((EFI_ERROR (Status
)) && (Status
!= EFI_ALREADY_STARTED
)) {
702 // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.
704 if (Status
!= EFI_ALREADY_STARTED
) {
705 AtaBusDriverData
= AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA
));
706 if (AtaBusDriverData
== NULL
) {
707 Status
= EFI_OUT_OF_RESOURCES
;
711 AtaBusDriverData
->AtaPassThru
= AtaPassThru
;
712 AtaBusDriverData
->Controller
= Controller
;
713 AtaBusDriverData
->ParentDevicePath
= ParentDevicePath
;
714 AtaBusDriverData
->DriverBindingHandle
= This
->DriverBindingHandle
;
716 Status
= gBS
->InstallMultipleProtocolInterfaces (
722 if (EFI_ERROR (Status
)) {
727 Status
= gBS
->OpenProtocol (
730 (VOID
**) &AtaBusDriverData
,
731 This
->DriverBindingHandle
,
733 EFI_OPEN_PROTOCOL_GET_PROTOCOL
735 if (EFI_ERROR (Status
)) {
736 AtaBusDriverData
= NULL
;
741 if (RemainingDevicePath
== NULL
) {
744 Status
= AtaPassThru
->GetNextPort (AtaPassThru
, &Port
);
745 if (EFI_ERROR (Status
)) {
747 // We cannot find more legal port then we are done.
752 PortMultiplierPort
= 0xFFFF;
754 Status
= AtaPassThru
->GetNextDevice (AtaPassThru
, Port
, &PortMultiplierPort
);
755 if (EFI_ERROR (Status
)) {
757 // We cannot find more legal port multiplier port number for ATA device
758 // on the port, then we are done.
762 RegisterAtaDevice (AtaBusDriverData
, Port
, PortMultiplierPort
);
765 Status
= EFI_SUCCESS
;
766 } else if (!IsDevicePathEnd (RemainingDevicePath
)) {
767 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
768 if (!EFI_ERROR (Status
)) {
769 Status
= RegisterAtaDevice (AtaBusDriverData
,Port
, PortMultiplierPort
);
777 if (AtaBusDriverData
!= NULL
) {
778 gBS
->UninstallMultipleProtocolInterfaces (
784 FreePool (AtaBusDriverData
);
789 &gEfiAtaPassThruProtocolGuid
,
790 This
->DriverBindingHandle
,
800 Stops a device controller or a bus controller.
802 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
803 As a result, much of the error checking on the parameters to Stop() has been moved
804 into this common boot service. It is legal to call Stop() from other locations,
805 but the following calling restrictions must be followed or the system behavior will not be deterministic.
806 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
807 same driver's Start() function.
808 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
809 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
810 Start() function, and the Start() function must have called OpenProtocol() on
811 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
813 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
814 @param[in] ControllerHandle A handle to the device being stopped. The handle must
815 support a bus specific I/O protocol for the driver
816 to use to stop the device.
817 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
818 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
819 if NumberOfChildren is 0.
821 @retval EFI_SUCCESS The device was stopped.
822 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
827 AtaBusDriverBindingStop (
828 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
829 IN EFI_HANDLE Controller
,
830 IN UINTN NumberOfChildren
,
831 IN EFI_HANDLE
*ChildHandleBuffer
835 BOOLEAN AllChildrenStopped
;
837 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
839 if (NumberOfChildren
== 0) {
840 Status
= gBS
->OpenProtocol (
843 (VOID
**) &AtaBusDriverData
,
844 This
->DriverBindingHandle
,
846 EFI_OPEN_PROTOCOL_GET_PROTOCOL
848 if (!EFI_ERROR (Status
)) {
849 gBS
->UninstallMultipleProtocolInterfaces (
855 FreePool (AtaBusDriverData
);
860 &gEfiAtaPassThruProtocolGuid
,
861 This
->DriverBindingHandle
,
868 AllChildrenStopped
= TRUE
;
870 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
872 Status
= UnregisterAtaDevice (This
, Controller
, ChildHandleBuffer
[Index
]);
873 if (EFI_ERROR (Status
)) {
874 AllChildrenStopped
= FALSE
;
878 if (!AllChildrenStopped
) {
879 return EFI_DEVICE_ERROR
;
887 Reset the Block Device.
889 @param This Indicates a pointer to the calling context.
890 @param ExtendedVerification Driver may perform diagnostics on reset.
892 @retval EFI_SUCCESS The device was reset.
893 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
900 IN EFI_BLOCK_IO_PROTOCOL
*This
,
901 IN BOOLEAN ExtendedVerification
905 ATA_DEVICE
*AtaDevice
;
908 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
910 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
912 Status
= ResetAtaDevice (AtaDevice
);
914 if (EFI_ERROR (Status
)) {
915 Status
= EFI_DEVICE_ERROR
;
918 gBS
->RestoreTPL (OldTpl
);
924 Read/Write BufferSize bytes from Lba from/into Buffer.
926 @param[in] This Indicates a pointer to the calling context. Either be
927 block I/O or block I/O2.
928 @param[in] MediaId The media ID that the read/write request is for.
929 @param[in] Lba The starting logical block address to be read/written.
930 The caller is responsible for reading/writing to only
931 legitimate locations.
932 @param[in, out] Token A pointer to the token associated with the transaction.
933 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
934 @param[out] Buffer A pointer to the destination/source buffer for the data.
935 @param[in] IsBlockIo2 Indicate the calling is from BlockIO or BlockIO2. TURE is
936 from BlockIO2, FALSE is for BlockIO.
937 @param[in] IsWrite Indicates whether it is a write operation.
939 @retval EFI_SUCCESS The data was read/written correctly to the device.
940 @retval EFI_WRITE_PROTECTED The device can not be read/written to.
941 @retval EFI_DEVICE_ERROR The device reported an error while performing the read/write.
942 @retval EFI_NO_MEDIA There is no media in the device.
943 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
944 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
945 @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid,
946 or the buffer is not on proper alignment.
954 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
957 IN BOOLEAN IsBlockIo2
,
961 ATA_DEVICE
*AtaDevice
;
964 EFI_BLOCK_IO_MEDIA
*Media
;
966 UINTN NumberOfBlocks
;
970 Media
= ((EFI_BLOCK_IO2_PROTOCOL
*) This
)->Media
;
971 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (This
);
973 Media
= ((EFI_BLOCK_IO_PROTOCOL
*) This
)->Media
;
974 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
977 if (MediaId
!= Media
->MediaId
) {
978 return EFI_MEDIA_CHANGED
;
984 if (Buffer
== NULL
) {
985 return EFI_INVALID_PARAMETER
;
988 if (BufferSize
== 0) {
992 BlockSize
= Media
->BlockSize
;
993 if ((BufferSize
% BlockSize
) != 0) {
994 return EFI_BAD_BUFFER_SIZE
;
997 NumberOfBlocks
= BufferSize
/ BlockSize
;
998 if ((Lba
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
999 return EFI_INVALID_PARAMETER
;
1002 IoAlign
= Media
->IoAlign
;
1003 if (IoAlign
> 0 && (((UINTN
) Buffer
& (IoAlign
- 1)) != 0)) {
1004 return EFI_INVALID_PARAMETER
;
1007 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1010 // Invoke low level AtaDevice Access Routine.
1012 Status
= AccessAtaDevice (AtaDevice
, Buffer
, Lba
, NumberOfBlocks
, IsWrite
, Token
);
1014 gBS
->RestoreTPL (OldTpl
);
1021 Read BufferSize bytes from Lba into Buffer.
1023 @param This Indicates a pointer to the calling context.
1024 @param MediaId Id of the media, changes every time the media is replaced.
1025 @param Lba The starting Logical Block Address to read from
1026 @param BufferSize Size of Buffer, must be a multiple of device block size.
1027 @param Buffer A pointer to the destination buffer for the data. The caller is
1028 responsible for either having implicit or explicit ownership of the buffer.
1030 @retval EFI_SUCCESS The data was read correctly from the device.
1031 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
1032 @retval EFI_NO_MEDIA There is no media in the device.
1033 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
1034 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1035 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1036 or the buffer is not on proper alignment.
1041 AtaBlockIoReadBlocks (
1042 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1045 IN UINTN BufferSize
,
1049 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, NULL
, BufferSize
, Buffer
, FALSE
, FALSE
);
1054 Write BufferSize bytes from Lba into Buffer.
1056 @param This Indicates a pointer to the calling context.
1057 @param MediaId The media ID that the write request is for.
1058 @param Lba The starting logical block address to be written. The caller is
1059 responsible for writing to only legitimate locations.
1060 @param BufferSize Size of Buffer, must be a multiple of device block size.
1061 @param Buffer A pointer to the source buffer for the data.
1063 @retval EFI_SUCCESS The data was written correctly to the device.
1064 @retval EFI_WRITE_PROTECTED The device can not be written to.
1065 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1066 @retval EFI_NO_MEDIA There is no media in the device.
1067 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1068 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1069 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1070 or the buffer is not on proper alignment.
1075 AtaBlockIoWriteBlocks (
1076 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1079 IN UINTN BufferSize
,
1083 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, NULL
, BufferSize
, Buffer
, FALSE
, TRUE
);
1088 Flush the Block Device.
1090 @param This Indicates a pointer to the calling context.
1092 @retval EFI_SUCCESS All outstanding data was written to the device
1093 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1094 @retval EFI_NO_MEDIA There is no media in the device.
1099 AtaBlockIoFlushBlocks (
1100 IN EFI_BLOCK_IO_PROTOCOL
*This
1110 Reset the Block Device.
1112 @param[in] This Indicates a pointer to the calling context.
1113 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
1115 @retval EFI_SUCCESS The device was reset.
1116 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
1123 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1124 IN BOOLEAN ExtendedVerification
1128 ATA_DEVICE
*AtaDevice
;
1131 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1133 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (This
);
1135 Status
= ResetAtaDevice (AtaDevice
);
1137 if (EFI_ERROR (Status
)) {
1138 Status
= EFI_DEVICE_ERROR
;
1141 gBS
->RestoreTPL (OldTpl
);
1146 Read BufferSize bytes from Lba into Buffer.
1148 @param[in] This Indicates a pointer to the calling context.
1149 @param[in] MediaId Id of the media, changes every time the media is replaced.
1150 @param[in] Lba The starting Logical Block Address to read from.
1151 @param[in, out] Token A pointer to the token associated with the transaction.
1152 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1153 @param[out] Buffer A pointer to the destination buffer for the data. The caller is
1154 responsible for either having implicit or explicit ownership of the buffer.
1156 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
1157 The data was read correctly from the device if
1159 @retval EFI_DEVICE_ERROR The device reported an error while performing
1161 @retval EFI_NO_MEDIA There is no media in the device.
1162 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1163 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
1164 intrinsic block size of the device.
1165 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1166 or the buffer is not on proper alignment.
1167 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
1173 AtaBlockIoReadBlocksEx (
1174 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1177 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1178 IN UINTN BufferSize
,
1182 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, Token
, BufferSize
, Buffer
, TRUE
, FALSE
);
1187 Write BufferSize bytes from Lba into Buffer.
1189 @param[in] This Indicates a pointer to the calling context.
1190 @param[in] MediaId The media ID that the write request is for.
1191 @param[in] Lba The starting logical block address to be written. The
1192 caller is responsible for writing to only legitimate
1194 @param[in, out] Token A pointer to the token associated with the transaction.
1195 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1196 @param[in] Buffer A pointer to the source buffer for the data.
1198 @retval EFI_SUCCESS The data was written correctly to the device.
1199 @retval EFI_WRITE_PROTECTED The device can not be written to.
1200 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1201 @retval EFI_NO_MEDIA There is no media in the device.
1202 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1203 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1204 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1205 or the buffer is not on proper alignment.
1210 AtaBlockIoWriteBlocksEx (
1211 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1214 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1215 IN UINTN BufferSize
,
1219 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, Token
, BufferSize
, Buffer
, TRUE
, TRUE
);
1224 Flush the Block Device.
1226 @param[in] This Indicates a pointer to the calling context.
1227 @param[in, out] Token A pointer to the token associated with the transaction.
1229 @retval EFI_SUCCESS All outstanding data was written to the device
1230 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1231 @retval EFI_NO_MEDIA There is no media in the device.
1236 AtaBlockIoFlushBlocksEx (
1237 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1238 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
1242 // Signla event and return directly.
1244 if (Token
!= NULL
&& Token
->Event
!= NULL
) {
1245 Token
->TransactionStatus
= EFI_SUCCESS
;
1246 gBS
->SignalEvent (Token
->Event
);
1251 Provides inquiry information for the controller type.
1253 This function is used by the IDE bus driver to get inquiry data. Data format
1254 of Identify data is defined by the Interface GUID.
1256 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1257 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
1258 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
1260 @retval EFI_SUCCESS The command was accepted without any errors.
1261 @retval EFI_NOT_FOUND Device does not support this data class
1262 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
1263 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
1268 AtaDiskInfoInquiry (
1269 IN EFI_DISK_INFO_PROTOCOL
*This
,
1270 IN OUT VOID
*InquiryData
,
1271 IN OUT UINT32
*InquiryDataSize
1274 return EFI_NOT_FOUND
;
1279 Provides identify information for the controller type.
1281 This function is used by the IDE bus driver to get identify data. Data format
1282 of Identify data is defined by the Interface GUID.
1284 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
1286 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
1287 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
1290 @retval EFI_SUCCESS The command was accepted without any errors.
1291 @retval EFI_NOT_FOUND Device does not support this data class
1292 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
1293 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
1298 AtaDiskInfoIdentify (
1299 IN EFI_DISK_INFO_PROTOCOL
*This
,
1300 IN OUT VOID
*IdentifyData
,
1301 IN OUT UINT32
*IdentifyDataSize
1305 ATA_DEVICE
*AtaDevice
;
1307 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1309 Status
= EFI_BUFFER_TOO_SMALL
;
1310 if (*IdentifyDataSize
>= sizeof (*AtaDevice
->IdentifyData
)) {
1311 Status
= EFI_SUCCESS
;
1312 CopyMem (IdentifyData
, AtaDevice
->IdentifyData
, sizeof (*AtaDevice
->IdentifyData
));
1314 *IdentifyDataSize
= sizeof (*AtaDevice
->IdentifyData
);
1321 Provides sense data information for the controller type.
1323 This function is used by the IDE bus driver to get sense data.
1324 Data format of Sense data is defined by the Interface GUID.
1326 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1327 @param[in, out] SenseData Pointer to the SenseData.
1328 @param[in, out] SenseDataSize Size of SenseData in bytes.
1329 @param[out] SenseDataNumber Pointer to the value for the sense 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 SenseData from device.
1334 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
1339 AtaDiskInfoSenseData (
1340 IN EFI_DISK_INFO_PROTOCOL
*This
,
1341 IN OUT VOID
*SenseData
,
1342 IN OUT UINT32
*SenseDataSize
,
1343 OUT UINT8
*SenseDataNumber
1346 return EFI_NOT_FOUND
;
1351 This function is used by the IDE bus driver to get controller information.
1353 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1354 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
1355 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
1357 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
1358 @retval EFI_UNSUPPORTED This is not an IDE device.
1363 AtaDiskInfoWhichIde (
1364 IN EFI_DISK_INFO_PROTOCOL
*This
,
1365 OUT UINT32
*IdeChannel
,
1366 OUT UINT32
*IdeDevice
1369 ATA_DEVICE
*AtaDevice
;
1371 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1372 *IdeChannel
= AtaDevice
->Port
;
1373 *IdeDevice
= AtaDevice
->PortMultiplierPort
;
1379 Send a security protocol command to a device that receives data and/or the result
1380 of one or more commands sent by SendData.
1382 The ReceiveData function sends a security protocol command to the given MediaId.
1383 The security protocol command sent is defined by SecurityProtocolId and contains
1384 the security protocol specific data SecurityProtocolSpecificData. The function
1385 returns the data from the security protocol command in PayloadBuffer.
1387 For devices supporting the SCSI command set, the security protocol command is sent
1388 using the SECURITY PROTOCOL IN command defined in SPC-4.
1390 For devices supporting the ATA command set, the security protocol command is sent
1391 using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize
1394 If the PayloadBufferSize is zero, the security protocol command is sent using the
1395 Trusted Non-Data command defined in ATA8-ACS.
1397 If PayloadBufferSize is too small to store the available data from the security
1398 protocol command, the function shall copy PayloadBufferSize bytes into the
1399 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
1401 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
1402 the function shall return EFI_INVALID_PARAMETER.
1404 If the given MediaId does not support security protocol commands, the function shall
1405 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
1406 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
1407 the function returns EFI_MEDIA_CHANGED.
1409 If the security protocol fails to complete within the Timeout period, the function
1410 shall return EFI_TIMEOUT.
1412 If the security protocol command completes without an error, the function shall
1413 return EFI_SUCCESS. If the security protocol command completes with an error, the
1414 function shall return EFI_DEVICE_ERROR.
1416 @param This Indicates a pointer to the calling context.
1417 @param MediaId ID of the medium to receive data from.
1418 @param Timeout The timeout, in 100ns units, to use for the execution
1419 of the security protocol command. A Timeout value of 0
1420 means that this function will wait indefinitely for the
1421 security protocol command to execute. If Timeout is greater
1422 than zero, then this function will return EFI_TIMEOUT
1423 if the time required to execute the receive data command
1424 is greater than Timeout.
1425 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1426 the security protocol command to be sent.
1427 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1428 of the security protocol command to be sent.
1429 @param PayloadBufferSize Size in bytes of the payload data buffer.
1430 @param PayloadBuffer A pointer to a destination buffer to store the security
1431 protocol command specific payload data for the security
1432 protocol command. The caller is responsible for having
1433 either implicit or explicit ownership of the buffer.
1434 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
1435 data written to the payload data buffer.
1437 @retval EFI_SUCCESS The security protocol command completed successfully.
1438 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
1439 data from the device. The PayloadBuffer contains the truncated data.
1440 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1441 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1442 @retval EFI_NO_MEDIA There is no media in the device.
1443 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1444 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
1445 PayloadBufferSize is non-zero.
1446 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1447 protocol command to execute.
1452 AtaStorageSecurityReceiveData (
1453 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1456 IN UINT8 SecurityProtocolId
,
1457 IN UINT16 SecurityProtocolSpecificData
,
1458 IN UINTN PayloadBufferSize
,
1459 OUT VOID
*PayloadBuffer
,
1460 OUT UINTN
*PayloadTransferSize
1464 ATA_DEVICE
*Private
;
1466 DEBUG ((EFI_D_INFO
, "EFI Storage Security Protocol - Read"));
1467 if ((PayloadBuffer
== NULL
|| PayloadTransferSize
== NULL
) && PayloadBufferSize
!= 0) {
1468 return EFI_INVALID_PARAMETER
;
1471 Status
= EFI_SUCCESS
;
1472 Private
= ATA_DEVICE_FROM_STORAGE_SECURITY (This
);
1474 if (MediaId
!= Private
->BlockIo
.Media
->MediaId
) {
1475 return EFI_MEDIA_CHANGED
;
1478 if (!Private
->BlockIo
.Media
->MediaPresent
) {
1479 return EFI_NO_MEDIA
;
1482 Status
= TrustTransferAtaDevice (
1486 SecurityProtocolSpecificData
,
1497 Send a security protocol command to a device.
1499 The SendData function sends a security protocol command containing the payload
1500 PayloadBuffer to the given MediaId. The security protocol command sent is
1501 defined by SecurityProtocolId and contains the security protocol specific data
1502 SecurityProtocolSpecificData. If the underlying protocol command requires a
1503 specific padding for the command payload, the SendData function shall add padding
1504 bytes to the command payload to satisfy the padding requirements.
1506 For devices supporting the SCSI command set, the security protocol command is sent
1507 using the SECURITY PROTOCOL OUT command defined in SPC-4.
1509 For devices supporting the ATA command set, the security protocol command is sent
1510 using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize
1511 is non-zero. If the PayloadBufferSize is zero, the security protocol command is
1512 sent using the Trusted Non-Data command defined in ATA8-ACS.
1514 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
1515 return EFI_INVALID_PARAMETER.
1517 If the given MediaId does not support security protocol commands, the function
1518 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
1519 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
1520 device, the function returns EFI_MEDIA_CHANGED.
1522 If the security protocol fails to complete within the Timeout period, the function
1523 shall return EFI_TIMEOUT.
1525 If the security protocol command completes without an error, the function shall return
1526 EFI_SUCCESS. If the security protocol command completes with an error, the function
1527 shall return EFI_DEVICE_ERROR.
1529 @param This Indicates a pointer to the calling context.
1530 @param MediaId ID of the medium to receive data from.
1531 @param Timeout The timeout, in 100ns units, to use for the execution
1532 of the security protocol command. A Timeout value of 0
1533 means that this function will wait indefinitely for the
1534 security protocol command to execute. If Timeout is greater
1535 than zero, then this function will return EFI_TIMEOUT
1536 if the time required to execute the receive data command
1537 is greater than Timeout.
1538 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1539 the security protocol command to be sent.
1540 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1541 of the security protocol command to be sent.
1542 @param PayloadBufferSize Size in bytes of the payload data buffer.
1543 @param PayloadBuffer A pointer to a destination buffer to store the security
1544 protocol command specific payload data for the security
1547 @retval EFI_SUCCESS The security protocol command completed successfully.
1548 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1549 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1550 @retval EFI_NO_MEDIA There is no media in the device.
1551 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1552 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
1553 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1554 protocol command to execute.
1559 AtaStorageSecuritySendData (
1560 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1563 IN UINT8 SecurityProtocolId
,
1564 IN UINT16 SecurityProtocolSpecificData
,
1565 IN UINTN PayloadBufferSize
,
1566 IN VOID
*PayloadBuffer
1570 ATA_DEVICE
*Private
;
1572 DEBUG ((EFI_D_INFO
, "EFI Storage Security Protocol - Send"));
1573 if ((PayloadBuffer
== NULL
) && (PayloadBufferSize
!= 0)) {
1574 return EFI_INVALID_PARAMETER
;
1577 Status
= EFI_SUCCESS
;
1578 Private
= ATA_DEVICE_FROM_STORAGE_SECURITY (This
);
1580 if (MediaId
!= Private
->BlockIo
.Media
->MediaId
) {
1581 return EFI_MEDIA_CHANGED
;
1584 Status
= TrustTransferAtaDevice (
1588 SecurityProtocolSpecificData
,
1599 The user Entry Point for module AtaBus. The user code starts with this function.
1601 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1602 @param[in] SystemTable A pointer to the EFI System Table.
1604 @retval EFI_SUCCESS The entry point is executed successfully.
1605 @retval other Some error occurs when executing this entry point.
1611 IN EFI_HANDLE ImageHandle
,
1612 IN EFI_SYSTEM_TABLE
*SystemTable
1618 // Install driver model protocol(s).
1620 Status
= EfiLibInstallDriverBindingComponentName2 (
1623 &gAtaBusDriverBinding
,
1625 &gAtaBusComponentName
,
1626 &gAtaBusComponentName2
1628 ASSERT_EFI_ERROR (Status
);