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
82 NULL
, // ControllerNameTable
83 {L
'\0', }, // ModelName
84 {NULL
, NULL
}, // AtaTaskList
85 {NULL
, NULL
}, // AtaSubTaskList
90 Allocates an aligned buffer for ATA device.
92 This function allocates an aligned buffer for the ATA device to perform
93 ATA pass through operations. The alignment requirement is from ATA pass
96 @param AtaDevice The ATA child device involved for the operation.
97 @param BufferSize The request buffer size.
99 @return A pointer to the aligned buffer or NULL if the allocation fails.
103 AllocateAlignedBuffer (
104 IN ATA_DEVICE
*AtaDevice
,
108 return AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize
), AtaDevice
->AtaBusDriverData
->AtaPassThru
->Mode
->IoAlign
);
112 Frees an aligned buffer for ATA device.
114 This function frees an aligned buffer for the ATA device to perform
115 ATA pass through operations.
117 @param Buffer The aligned buffer to be freed.
118 @param BufferSize The request buffer size.
127 if (Buffer
!= NULL
) {
128 FreeAlignedPages (Buffer
, EFI_SIZE_TO_PAGES (BufferSize
));
134 Release all the resources allocated for the ATA device.
136 This function releases all the resources allocated for the ATA device.
138 @param AtaDevice The ATA child device involved for the operation.
142 ReleaseAtaResources (
143 IN ATA_DEVICE
*AtaDevice
146 ATA_BUS_ASYN_SUB_TASK
*SubTask
;
147 ATA_BUS_ASYN_TASK
*AtaTask
;
149 LIST_ENTRY
*DelEntry
;
152 FreeUnicodeStringTable (AtaDevice
->ControllerNameTable
);
153 FreeAlignedBuffer (AtaDevice
->Asb
, sizeof (EFI_ATA_STATUS_BLOCK
));
154 FreeAlignedBuffer (AtaDevice
->IdentifyData
, sizeof (ATA_IDENTIFY_DATA
));
155 if (AtaDevice
->DevicePath
!= NULL
) {
156 FreePool (AtaDevice
->DevicePath
);
158 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
159 if (!IsListEmpty (&AtaDevice
->AtaSubTaskList
)) {
161 // Free the Subtask list.
163 for(Entry
= AtaDevice
->AtaSubTaskList
.ForwardLink
;
164 Entry
!= (&AtaDevice
->AtaSubTaskList
);
167 Entry
= Entry
->ForwardLink
;
168 SubTask
= ATA_ASYN_SUB_TASK_FROM_ENTRY (DelEntry
);
170 RemoveEntryList (DelEntry
);
171 FreeAtaSubTask (SubTask
);
174 if (!IsListEmpty (&AtaDevice
->AtaTaskList
)) {
176 // Free the Subtask list.
178 for(Entry
= AtaDevice
->AtaTaskList
.ForwardLink
;
179 Entry
!= (&AtaDevice
->AtaTaskList
);
182 Entry
= Entry
->ForwardLink
;
183 AtaTask
= ATA_ASYN_TASK_FROM_ENTRY (DelEntry
);
185 RemoveEntryList (DelEntry
);
189 gBS
->RestoreTPL (OldTpl
);
190 FreePool (AtaDevice
);
195 Registers an ATA device.
197 This function allocates an ATA device structure for the ATA device specified by
198 Port and PortMultiplierPort if the ATA device is identified as a valid one.
199 Then it will create child handle and install Block IO and Disk Info protocol on
202 @param AtaBusDriverData The parent ATA bus driver data structure.
203 @param Port The port number of the ATA device.
204 @param PortMultiplierPort The port multiplier port number of the ATA device.
206 @retval EFI_SUCCESS The ATA device is successfully registered.
207 @retval EFI_OUT_OF_RESOURCES There is not enough memory to allocate the ATA device
208 and related data structures.
209 @return Others Some error occurs when registering the ATA device.
213 IN OUT ATA_BUS_DRIVER_DATA
*AtaBusDriverData
,
215 IN UINT16 PortMultiplierPort
219 ATA_DEVICE
*AtaDevice
;
220 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
221 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePathNode
;
222 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
223 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
224 EFI_HANDLE DeviceHandle
;
227 NewDevicePathNode
= NULL
;
229 RemainingDevicePath
= NULL
;
234 AtaPassThru
= AtaBusDriverData
->AtaPassThru
;
235 Status
= AtaPassThru
->BuildDevicePath (AtaPassThru
, Port
, PortMultiplierPort
, &NewDevicePathNode
);
236 if (EFI_ERROR (Status
)) {
240 DevicePath
= AppendDevicePathNode (AtaBusDriverData
->ParentDevicePath
, NewDevicePathNode
);
241 if (DevicePath
== NULL
) {
242 Status
= EFI_OUT_OF_RESOURCES
;
247 RemainingDevicePath
= DevicePath
;
248 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &DeviceHandle
);
249 if (!EFI_ERROR (Status
) && (DeviceHandle
!= NULL
) && IsDevicePathEnd(RemainingDevicePath
)) {
250 Status
= EFI_ALREADY_STARTED
;
251 FreePool (DevicePath
);
256 // Allocate ATA device from the template.
258 AtaDevice
= AllocateCopyPool (sizeof (ATA_DEVICE
), &gAtaDeviceTemplate
);
259 if (AtaDevice
== NULL
) {
260 Status
= EFI_OUT_OF_RESOURCES
;
265 // Initializes ATA device structures and allocates the required buffer.
267 AtaDevice
->BlockIo
.Media
= &AtaDevice
->BlockMedia
;
268 AtaDevice
->BlockIo2
.Media
= &AtaDevice
->BlockMedia
;
269 AtaDevice
->AtaBusDriverData
= AtaBusDriverData
;
270 AtaDevice
->DevicePath
= DevicePath
;
271 AtaDevice
->Port
= Port
;
272 AtaDevice
->PortMultiplierPort
= PortMultiplierPort
;
273 AtaDevice
->Asb
= AllocateAlignedBuffer (AtaDevice
, sizeof (EFI_ATA_STATUS_BLOCK
));
274 if (AtaDevice
->Asb
== NULL
) {
275 Status
= EFI_OUT_OF_RESOURCES
;
278 AtaDevice
->IdentifyData
= AllocateAlignedBuffer (AtaDevice
, sizeof (ATA_IDENTIFY_DATA
));
279 if (AtaDevice
->IdentifyData
== NULL
) {
280 Status
= EFI_OUT_OF_RESOURCES
;
285 // Initial Ata Task List
287 InitializeListHead (&AtaDevice
->AtaTaskList
);
288 InitializeListHead (&AtaDevice
->AtaSubTaskList
);
291 // Report Status Code to indicate the ATA device will be enabled
293 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
295 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_ENABLE
),
296 AtaBusDriverData
->ParentDevicePath
300 // Try to identify the ATA device via the ATA pass through command.
302 Status
= DiscoverAtaDevice (AtaDevice
);
303 if (EFI_ERROR (Status
)) {
308 // Build controller name for Component Name (2) protocol.
310 Status
= AddUnicodeString2 (
312 gAtaBusComponentName
.SupportedLanguages
,
313 &AtaDevice
->ControllerNameTable
,
314 AtaDevice
->ModelName
,
317 if (EFI_ERROR (Status
)) {
321 Status
= AddUnicodeString2 (
323 gAtaBusComponentName2
.SupportedLanguages
,
324 &AtaDevice
->ControllerNameTable
,
325 AtaDevice
->ModelName
,
328 if (EFI_ERROR (Status
)) {
333 // Update to AHCI interface GUID based on device path node. The default one
334 // is IDE interface GUID copied from template.
336 if (NewDevicePathNode
->SubType
== MSG_SATA_DP
) {
337 CopyGuid (&AtaDevice
->DiskInfo
.Interface
, &gEfiDiskInfoAhciInterfaceGuid
);
340 Status
= gBS
->InstallMultipleProtocolInterfaces (
342 &gEfiDevicePathProtocolGuid
,
343 AtaDevice
->DevicePath
,
344 &gEfiBlockIoProtocolGuid
,
346 &gEfiBlockIo2ProtocolGuid
,
347 &AtaDevice
->BlockIo2
,
348 &gEfiDiskInfoProtocolGuid
,
349 &AtaDevice
->DiskInfo
,
352 if (EFI_ERROR (Status
)) {
357 // See if the ata device support trust computing feature or not.
358 // If yes, then install Storage Security Protocol at the ata device handle.
360 if ((AtaDevice
->IdentifyData
->trusted_computing_support
& BIT0
) != 0) {
361 DEBUG ((EFI_D_INFO
, "Found TCG support in Port %x PortMultiplierPort %x\n", Port
, PortMultiplierPort
));
362 Status
= gBS
->InstallProtocolInterface (
364 &gEfiStorageSecurityCommandProtocolGuid
,
365 EFI_NATIVE_INTERFACE
,
366 &AtaDevice
->StorageSecurity
368 if (EFI_ERROR (Status
)) {
371 DEBUG ((EFI_D_INFO
, "Successfully Install Storage Security Protocol on the ATA device\n"));
375 AtaBusDriverData
->Controller
,
376 &gEfiAtaPassThruProtocolGuid
,
377 (VOID
**) &AtaPassThru
,
378 AtaBusDriverData
->DriverBindingHandle
,
380 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
384 if (NewDevicePathNode
!= NULL
) {
385 FreePool (NewDevicePathNode
);
388 if (EFI_ERROR (Status
) && (AtaDevice
!= NULL
)) {
389 ReleaseAtaResources (AtaDevice
);
390 DEBUG ((EFI_D_ERROR
| EFI_D_INIT
, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port
, PortMultiplierPort
, Status
));
397 Unregisters an ATA device.
399 This function removes the protocols installed on the controller handle and
400 frees the resources allocated for the ATA device.
402 @param This The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.
403 @param Controller The controller handle of the ATA device.
404 @param Handle The child handle.
406 @retval EFI_SUCCESS The ATA device is successfully unregistered.
407 @return Others Some error occurs when unregistering the ATA device.
411 UnregisterAtaDevice (
412 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
413 IN EFI_HANDLE Controller
,
418 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
419 EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
;
420 ATA_DEVICE
*AtaDevice
;
421 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
422 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*StorageSecurity
;
427 Status
= gBS
->OpenProtocol (
429 &gEfiBlockIoProtocolGuid
,
431 This
->DriverBindingHandle
,
433 EFI_OPEN_PROTOCOL_GET_PROTOCOL
435 if (EFI_ERROR (Status
)) {
437 // Locate BlockIo2 protocol
439 Status
= gBS
->OpenProtocol (
441 &gEfiBlockIo2ProtocolGuid
,
443 This
->DriverBindingHandle
,
445 EFI_OPEN_PROTOCOL_GET_PROTOCOL
447 if (EFI_ERROR (Status
)) {
453 // Get AtaDevice data.
455 if (BlockIo
!= NULL
) {
456 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (BlockIo
);
458 ASSERT (BlockIo2
!= NULL
);
459 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (BlockIo2
);
463 // Close the child handle
467 &gEfiAtaPassThruProtocolGuid
,
468 This
->DriverBindingHandle
,
473 // The Ata Bus driver installs the BlockIo and BlockIo2 in the DriverBindingStart().
474 // Here should uninstall both of them.
476 Status
= gBS
->UninstallMultipleProtocolInterfaces (
478 &gEfiDevicePathProtocolGuid
,
479 AtaDevice
->DevicePath
,
480 &gEfiBlockIoProtocolGuid
,
482 &gEfiBlockIo2ProtocolGuid
,
483 &AtaDevice
->BlockIo2
,
484 &gEfiDiskInfoProtocolGuid
,
485 &AtaDevice
->DiskInfo
,
489 if (EFI_ERROR (Status
)) {
492 &gEfiAtaPassThruProtocolGuid
,
493 (VOID
**) &AtaPassThru
,
494 This
->DriverBindingHandle
,
496 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
502 // If Storage Security Command Protocol is installed, then uninstall this protocol.
504 Status
= gBS
->OpenProtocol (
506 &gEfiStorageSecurityCommandProtocolGuid
,
507 (VOID
**) &StorageSecurity
,
508 This
->DriverBindingHandle
,
510 EFI_OPEN_PROTOCOL_GET_PROTOCOL
513 if (!EFI_ERROR (Status
)) {
514 Status
= gBS
->UninstallProtocolInterface (
516 &gEfiStorageSecurityCommandProtocolGuid
,
517 &AtaDevice
->StorageSecurity
519 if (EFI_ERROR (Status
)) {
522 &gEfiAtaPassThruProtocolGuid
,
523 (VOID
**) &AtaPassThru
,
524 This
->DriverBindingHandle
,
526 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
532 ReleaseAtaResources (AtaDevice
);
539 Tests to see if this driver supports a given controller. If a child device is provided,
540 it further tests to see if this driver supports creating a handle for the specified child device.
542 This function checks to see if the driver specified by This supports the device specified by
543 ControllerHandle. Drivers will typically use the device path attached to
544 ControllerHandle and/or the services from the bus I/O abstraction attached to
545 ControllerHandle to determine if the driver supports ControllerHandle. This function
546 may be called many times during platform initialization. In order to reduce boot times, the tests
547 performed by this function must be very small, and take as little time as possible to execute. This
548 function must not change the state of any hardware devices, and this function must be aware that the
549 device specified by ControllerHandle may already be managed by the same driver or a
550 different driver. This function must match its calls to AllocatePages() with FreePages(),
551 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
552 Since ControllerHandle may have been previously started by the same driver, if a protocol is
553 already in the opened state, then it must not be closed with CloseProtocol(). This is required
554 to guarantee the state of ControllerHandle is not modified by this function.
556 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
557 @param[in] ControllerHandle The handle of the controller to test. This handle
558 must support a protocol interface that supplies
559 an I/O abstraction to the driver.
560 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
561 parameter is ignored by device drivers, and is optional for bus
562 drivers. For bus drivers, if this parameter is not NULL, then
563 the bus driver must determine if the bus controller specified
564 by ControllerHandle and the child controller specified
565 by RemainingDevicePath are both supported by this
568 @retval EFI_SUCCESS The device specified by ControllerHandle and
569 RemainingDevicePath is supported by the driver specified by This.
570 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
571 RemainingDevicePath is already being managed by the driver
573 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
574 RemainingDevicePath is already being managed by a different
575 driver or an application that requires exclusive access.
576 Currently not implemented.
577 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
578 RemainingDevicePath is not supported by the driver specified by This.
582 AtaBusDriverBindingSupported (
583 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
584 IN EFI_HANDLE Controller
,
585 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
589 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
590 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
592 UINT16 PortMultiplierPort
;
595 // Test EFI_ATA_PASS_THRU_PROTOCOL on controller handle.
597 Status
= gBS
->OpenProtocol (
599 &gEfiAtaPassThruProtocolGuid
,
600 (VOID
**) &AtaPassThru
,
601 This
->DriverBindingHandle
,
603 EFI_OPEN_PROTOCOL_BY_DRIVER
606 if (Status
== EFI_ALREADY_STARTED
) {
610 if (EFI_ERROR (Status
)) {
615 // Test to see if this ATA Pass Thru Protocol is for a LOGICAL channel
617 if ((AtaPassThru
->Mode
->Attributes
& EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL
) == 0) {
619 // Close the I/O Abstraction(s) used to perform the supported test
623 &gEfiAtaPassThruProtocolGuid
,
624 This
->DriverBindingHandle
,
627 return EFI_UNSUPPORTED
;
631 // Test RemainingDevicePath is valid or not.
633 if ((RemainingDevicePath
!= NULL
) && !IsDevicePathEnd (RemainingDevicePath
)) {
634 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
635 if (EFI_ERROR (Status
)) {
637 // Close the I/O Abstraction(s) used to perform the supported test
641 &gEfiAtaPassThruProtocolGuid
,
642 This
->DriverBindingHandle
,
650 // Close the I/O Abstraction(s) used to perform the supported test
654 &gEfiAtaPassThruProtocolGuid
,
655 This
->DriverBindingHandle
,
660 // Open the EFI Device Path protocol needed to perform the supported test
662 Status
= gBS
->OpenProtocol (
664 &gEfiDevicePathProtocolGuid
,
665 (VOID
**) &ParentDevicePath
,
666 This
->DriverBindingHandle
,
668 EFI_OPEN_PROTOCOL_GET_PROTOCOL
675 Starts a device controller or a bus controller.
677 The Start() function is designed to be invoked from the EFI boot service ConnectController().
678 As a result, much of the error checking on the parameters to Start() has been moved into this
679 common boot service. It is legal to call Start() from other locations,
680 but the following calling restrictions must be followed or the system behavior will not be deterministic.
681 1. ControllerHandle must be a valid EFI_HANDLE.
682 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
683 EFI_DEVICE_PATH_PROTOCOL.
684 3. Prior to calling Start(), the Supported() function for the driver specified by This must
685 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
687 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
688 @param[in] ControllerHandle The handle of the controller to start. This handle
689 must support a protocol interface that supplies
690 an I/O abstraction to the driver.
691 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
692 parameter is ignored by device drivers, and is optional for bus
693 drivers. For a bus driver, if this parameter is NULL, then handles
694 for all the children of Controller are created by this driver.
695 If this parameter is not NULL and the first Device Path Node is
696 not the End of Device Path Node, then only the handle for the
697 child device specified by the first Device Path Node of
698 RemainingDevicePath is created by this driver.
699 If the first Device Path Node of RemainingDevicePath is
700 the End of Device Path Node, no child handle is created by this
703 @retval EFI_SUCCESS The device was started.
704 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
705 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
706 @retval Others The driver failded to start the device.
711 AtaBusDriverBindingStart (
712 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
713 IN EFI_HANDLE Controller
,
714 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
718 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
719 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
720 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
722 UINT16 PortMultiplierPort
;
724 AtaBusDriverData
= NULL
;
726 Status
= gBS
->OpenProtocol (
728 &gEfiDevicePathProtocolGuid
,
729 (VOID
**) &ParentDevicePath
,
730 This
->DriverBindingHandle
,
732 EFI_OPEN_PROTOCOL_GET_PROTOCOL
734 if (EFI_ERROR (Status
)) {
739 // Report Status Code to indicate ATA bus starts
741 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
743 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_INIT
),
747 Status
= gBS
->OpenProtocol (
749 &gEfiAtaPassThruProtocolGuid
,
750 (VOID
**) &AtaPassThru
,
751 This
->DriverBindingHandle
,
753 EFI_OPEN_PROTOCOL_BY_DRIVER
755 if ((EFI_ERROR (Status
)) && (Status
!= EFI_ALREADY_STARTED
)) {
760 // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.
762 if (Status
!= EFI_ALREADY_STARTED
) {
763 AtaBusDriverData
= AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA
));
764 if (AtaBusDriverData
== NULL
) {
765 Status
= EFI_OUT_OF_RESOURCES
;
769 AtaBusDriverData
->AtaPassThru
= AtaPassThru
;
770 AtaBusDriverData
->Controller
= Controller
;
771 AtaBusDriverData
->ParentDevicePath
= ParentDevicePath
;
772 AtaBusDriverData
->DriverBindingHandle
= This
->DriverBindingHandle
;
774 Status
= gBS
->InstallMultipleProtocolInterfaces (
780 if (EFI_ERROR (Status
)) {
785 Status
= gBS
->OpenProtocol (
788 (VOID
**) &AtaBusDriverData
,
789 This
->DriverBindingHandle
,
791 EFI_OPEN_PROTOCOL_GET_PROTOCOL
793 if (EFI_ERROR (Status
)) {
794 AtaBusDriverData
= NULL
;
800 // Report Status Code to indicate detecting devices on bus
802 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
804 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_DETECT
),
808 if (RemainingDevicePath
== NULL
) {
811 Status
= AtaPassThru
->GetNextPort (AtaPassThru
, &Port
);
812 if (EFI_ERROR (Status
)) {
814 // We cannot find more legal port then we are done.
819 PortMultiplierPort
= 0xFFFF;
821 Status
= AtaPassThru
->GetNextDevice (AtaPassThru
, Port
, &PortMultiplierPort
);
822 if (EFI_ERROR (Status
)) {
824 // We cannot find more legal port multiplier port number for ATA device
825 // on the port, then we are done.
829 RegisterAtaDevice (AtaBusDriverData
, Port
, PortMultiplierPort
);
832 Status
= EFI_SUCCESS
;
833 } else if (!IsDevicePathEnd (RemainingDevicePath
)) {
834 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
835 if (!EFI_ERROR (Status
)) {
836 Status
= RegisterAtaDevice (AtaBusDriverData
,Port
, PortMultiplierPort
);
844 if (AtaBusDriverData
!= NULL
) {
845 gBS
->UninstallMultipleProtocolInterfaces (
851 FreePool (AtaBusDriverData
);
856 &gEfiAtaPassThruProtocolGuid
,
857 This
->DriverBindingHandle
,
867 Stops a device controller or a bus controller.
869 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
870 As a result, much of the error checking on the parameters to Stop() has been moved
871 into this common boot service. It is legal to call Stop() from other locations,
872 but the following calling restrictions must be followed or the system behavior will not be deterministic.
873 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
874 same driver's Start() function.
875 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
876 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
877 Start() function, and the Start() function must have called OpenProtocol() on
878 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
880 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
881 @param[in] ControllerHandle A handle to the device being stopped. The handle must
882 support a bus specific I/O protocol for the driver
883 to use to stop the device.
884 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
885 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
886 if NumberOfChildren is 0.
888 @retval EFI_SUCCESS The device was stopped.
889 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
894 AtaBusDriverBindingStop (
895 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
896 IN EFI_HANDLE Controller
,
897 IN UINTN NumberOfChildren
,
898 IN EFI_HANDLE
*ChildHandleBuffer
902 BOOLEAN AllChildrenStopped
;
904 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
906 if (NumberOfChildren
== 0) {
907 Status
= gBS
->OpenProtocol (
910 (VOID
**) &AtaBusDriverData
,
911 This
->DriverBindingHandle
,
913 EFI_OPEN_PROTOCOL_GET_PROTOCOL
915 if (!EFI_ERROR (Status
)) {
916 gBS
->UninstallMultipleProtocolInterfaces (
922 FreePool (AtaBusDriverData
);
927 &gEfiAtaPassThruProtocolGuid
,
928 This
->DriverBindingHandle
,
935 AllChildrenStopped
= TRUE
;
937 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
939 Status
= UnregisterAtaDevice (This
, Controller
, ChildHandleBuffer
[Index
]);
940 if (EFI_ERROR (Status
)) {
941 AllChildrenStopped
= FALSE
;
945 if (!AllChildrenStopped
) {
946 return EFI_DEVICE_ERROR
;
954 Reset the Block Device.
956 @param This Indicates a pointer to the calling context.
957 @param ExtendedVerification Driver may perform diagnostics on reset.
959 @retval EFI_SUCCESS The device was reset.
960 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
967 IN EFI_BLOCK_IO_PROTOCOL
*This
,
968 IN BOOLEAN ExtendedVerification
972 ATA_DEVICE
*AtaDevice
;
975 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
977 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
979 Status
= ResetAtaDevice (AtaDevice
);
981 if (EFI_ERROR (Status
)) {
982 Status
= EFI_DEVICE_ERROR
;
985 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_CHNAGED The MediaId does not matched 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
);
1063 BlockSize
= Media
->BlockSize
;
1064 if ((BufferSize
% BlockSize
) != 0) {
1065 return EFI_BAD_BUFFER_SIZE
;
1068 NumberOfBlocks
= BufferSize
/ BlockSize
;
1069 if ((Lba
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
1070 return EFI_INVALID_PARAMETER
;
1073 IoAlign
= Media
->IoAlign
;
1074 if (IoAlign
> 0 && (((UINTN
) Buffer
& (IoAlign
- 1)) != 0)) {
1075 return EFI_INVALID_PARAMETER
;
1078 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1081 // Invoke low level AtaDevice Access Routine.
1083 Status
= AccessAtaDevice (AtaDevice
, Buffer
, Lba
, NumberOfBlocks
, IsWrite
, Token
);
1085 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 matched 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
);
1125 Write BufferSize bytes from Lba into Buffer.
1127 @param This Indicates a pointer to the calling context.
1128 @param MediaId The media ID that the write request is for.
1129 @param Lba The starting logical block address to be written. The caller is
1130 responsible for writing to only legitimate locations.
1131 @param BufferSize Size of Buffer, must be a multiple of device block size.
1132 @param Buffer A pointer to the source buffer for the data.
1134 @retval EFI_SUCCESS The data was written correctly to the device.
1135 @retval EFI_WRITE_PROTECTED The device can not be written to.
1136 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1137 @retval EFI_NO_MEDIA There is no media in the device.
1138 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1139 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1140 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1141 or the buffer is not on proper alignment.
1146 AtaBlockIoWriteBlocks (
1147 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1150 IN UINTN BufferSize
,
1154 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, NULL
, BufferSize
, Buffer
, FALSE
, TRUE
);
1159 Flush the Block Device.
1161 @param This Indicates a pointer to the calling context.
1163 @retval EFI_SUCCESS All outstanding data was written to the device
1164 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1165 @retval EFI_NO_MEDIA There is no media in the device.
1170 AtaBlockIoFlushBlocks (
1171 IN EFI_BLOCK_IO_PROTOCOL
*This
1181 Reset the Block Device.
1183 @param[in] This Indicates a pointer to the calling context.
1184 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
1186 @retval EFI_SUCCESS The device was reset.
1187 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
1194 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1195 IN BOOLEAN ExtendedVerification
1199 ATA_DEVICE
*AtaDevice
;
1202 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1204 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (This
);
1206 AtaTerminateNonBlockingTask (AtaDevice
);
1208 Status
= ResetAtaDevice (AtaDevice
);
1210 if (EFI_ERROR (Status
)) {
1211 Status
= EFI_DEVICE_ERROR
;
1214 gBS
->RestoreTPL (OldTpl
);
1219 Read BufferSize bytes from Lba into Buffer.
1221 @param[in] This Indicates a pointer to the calling context.
1222 @param[in] MediaId Id of the media, changes every time the media is replaced.
1223 @param[in] Lba The starting Logical Block Address to read from.
1224 @param[in, out] Token A pointer to the token associated with the transaction.
1225 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1226 @param[out] Buffer A pointer to the destination buffer for the data. The caller is
1227 responsible for either having implicit or explicit ownership of the buffer.
1229 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
1230 The data was read correctly from the device if
1232 @retval EFI_DEVICE_ERROR The device reported an error while performing
1234 @retval EFI_NO_MEDIA There is no media in the device.
1235 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1236 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
1237 intrinsic block size of the device.
1238 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1239 or the buffer is not on proper alignment.
1240 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
1246 AtaBlockIoReadBlocksEx (
1247 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1250 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1251 IN UINTN BufferSize
,
1255 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, Token
, BufferSize
, Buffer
, TRUE
, FALSE
);
1260 Write BufferSize bytes from Lba into Buffer.
1262 @param[in] This Indicates a pointer to the calling context.
1263 @param[in] MediaId The media ID that the write request is for.
1264 @param[in] Lba The starting logical block address to be written. The
1265 caller is responsible for writing to only legitimate
1267 @param[in, out] Token A pointer to the token associated with the transaction.
1268 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1269 @param[in] Buffer A pointer to the source buffer for the data.
1271 @retval EFI_SUCCESS The data was written correctly to the device.
1272 @retval EFI_WRITE_PROTECTED The device can not be written to.
1273 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1274 @retval EFI_NO_MEDIA There is no media in the device.
1275 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1276 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1277 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1278 or the buffer is not on proper alignment.
1283 AtaBlockIoWriteBlocksEx (
1284 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1287 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1288 IN UINTN BufferSize
,
1292 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, Token
, BufferSize
, Buffer
, TRUE
, TRUE
);
1297 Flush the Block Device.
1299 @param[in] This Indicates a pointer to the calling context.
1300 @param[in, out] Token A pointer to the token associated with the transaction.
1302 @retval EFI_SUCCESS All outstanding data was written to the device
1303 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1304 @retval EFI_NO_MEDIA There is no media in the device.
1309 AtaBlockIoFlushBlocksEx (
1310 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1311 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
1315 // Signal event and return directly.
1317 if (Token
!= NULL
&& Token
->Event
!= NULL
) {
1318 Token
->TransactionStatus
= EFI_SUCCESS
;
1319 gBS
->SignalEvent (Token
->Event
);
1324 Provides inquiry information for the controller type.
1326 This function is used by the IDE bus driver to get inquiry data. Data format
1327 of Identify data is defined by the Interface GUID.
1329 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1330 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
1331 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
1333 @retval EFI_SUCCESS The command was accepted without any errors.
1334 @retval EFI_NOT_FOUND Device does not support this data class
1335 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
1336 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
1341 AtaDiskInfoInquiry (
1342 IN EFI_DISK_INFO_PROTOCOL
*This
,
1343 IN OUT VOID
*InquiryData
,
1344 IN OUT UINT32
*InquiryDataSize
1347 return EFI_NOT_FOUND
;
1352 Provides identify information for the controller type.
1354 This function is used by the IDE bus driver to get identify data. Data format
1355 of Identify data is defined by the Interface GUID.
1357 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
1359 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
1360 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
1363 @retval EFI_SUCCESS The command was accepted without any errors.
1364 @retval EFI_NOT_FOUND Device does not support this data class
1365 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
1366 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
1371 AtaDiskInfoIdentify (
1372 IN EFI_DISK_INFO_PROTOCOL
*This
,
1373 IN OUT VOID
*IdentifyData
,
1374 IN OUT UINT32
*IdentifyDataSize
1378 ATA_DEVICE
*AtaDevice
;
1380 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1382 Status
= EFI_BUFFER_TOO_SMALL
;
1383 if (*IdentifyDataSize
>= sizeof (ATA_IDENTIFY_DATA
)) {
1384 Status
= EFI_SUCCESS
;
1385 CopyMem (IdentifyData
, AtaDevice
->IdentifyData
, sizeof (ATA_IDENTIFY_DATA
));
1387 *IdentifyDataSize
= sizeof (ATA_IDENTIFY_DATA
);
1394 Provides sense data information for the controller type.
1396 This function is used by the IDE bus driver to get sense data.
1397 Data format of Sense data is defined by the Interface GUID.
1399 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1400 @param[in, out] SenseData Pointer to the SenseData.
1401 @param[in, out] SenseDataSize Size of SenseData in bytes.
1402 @param[out] SenseDataNumber Pointer to the value for the sense data size.
1404 @retval EFI_SUCCESS The command was accepted without any errors.
1405 @retval EFI_NOT_FOUND Device does not support this data class.
1406 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
1407 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
1412 AtaDiskInfoSenseData (
1413 IN EFI_DISK_INFO_PROTOCOL
*This
,
1414 IN OUT VOID
*SenseData
,
1415 IN OUT UINT32
*SenseDataSize
,
1416 OUT UINT8
*SenseDataNumber
1419 return EFI_NOT_FOUND
;
1424 This function is used by the IDE bus driver to get controller information.
1426 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1427 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
1428 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
1430 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
1431 @retval EFI_UNSUPPORTED This is not an IDE device.
1436 AtaDiskInfoWhichIde (
1437 IN EFI_DISK_INFO_PROTOCOL
*This
,
1438 OUT UINT32
*IdeChannel
,
1439 OUT UINT32
*IdeDevice
1442 ATA_DEVICE
*AtaDevice
;
1444 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1445 *IdeChannel
= AtaDevice
->Port
;
1446 *IdeDevice
= AtaDevice
->PortMultiplierPort
;
1452 Send a security protocol command to a device that receives data and/or the result
1453 of one or more commands sent by SendData.
1455 The ReceiveData function sends a security protocol command to the given MediaId.
1456 The security protocol command sent is defined by SecurityProtocolId and contains
1457 the security protocol specific data SecurityProtocolSpecificData. The function
1458 returns the data from the security protocol command in PayloadBuffer.
1460 For devices supporting the SCSI command set, the security protocol command is sent
1461 using the SECURITY PROTOCOL IN command defined in SPC-4.
1463 For devices supporting the ATA command set, the security protocol command is sent
1464 using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize
1467 If the PayloadBufferSize is zero, the security protocol command is sent using the
1468 Trusted Non-Data command defined in ATA8-ACS.
1470 If PayloadBufferSize is too small to store the available data from the security
1471 protocol command, the function shall copy PayloadBufferSize bytes into the
1472 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
1474 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
1475 the function shall return EFI_INVALID_PARAMETER.
1477 If the given MediaId does not support security protocol commands, the function shall
1478 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
1479 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
1480 the function returns EFI_MEDIA_CHANGED.
1482 If the security protocol fails to complete within the Timeout period, the function
1483 shall return EFI_TIMEOUT.
1485 If the security protocol command completes without an error, the function shall
1486 return EFI_SUCCESS. If the security protocol command completes with an error, the
1487 function shall return EFI_DEVICE_ERROR.
1489 @param This Indicates a pointer to the calling context.
1490 @param MediaId ID of the medium to receive data from.
1491 @param Timeout The timeout, in 100ns units, to use for the execution
1492 of the security protocol command. A Timeout value of 0
1493 means that this function will wait indefinitely for the
1494 security protocol command to execute. If Timeout is greater
1495 than zero, then this function will return EFI_TIMEOUT
1496 if the time required to execute the receive data command
1497 is greater than Timeout.
1498 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1499 the security protocol command to be sent.
1500 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1501 of the security protocol command to be sent.
1502 @param PayloadBufferSize Size in bytes of the payload data buffer.
1503 @param PayloadBuffer A pointer to a destination buffer to store the security
1504 protocol command specific payload data for the security
1505 protocol command. The caller is responsible for having
1506 either implicit or explicit ownership of the buffer.
1507 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
1508 data written to the payload data buffer.
1510 @retval EFI_SUCCESS The security protocol command completed successfully.
1511 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
1512 data from the device. The PayloadBuffer contains the truncated data.
1513 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1514 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1515 @retval EFI_NO_MEDIA There is no media in the device.
1516 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1517 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
1518 PayloadBufferSize is non-zero.
1519 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1520 protocol command to execute.
1525 AtaStorageSecurityReceiveData (
1526 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1529 IN UINT8 SecurityProtocolId
,
1530 IN UINT16 SecurityProtocolSpecificData
,
1531 IN UINTN PayloadBufferSize
,
1532 OUT VOID
*PayloadBuffer
,
1533 OUT UINTN
*PayloadTransferSize
1537 ATA_DEVICE
*Private
;
1540 DEBUG ((EFI_D_INFO
, "EFI Storage Security Protocol - Read\n"));
1541 if ((PayloadBuffer
== NULL
|| PayloadTransferSize
== NULL
) && PayloadBufferSize
!= 0) {
1542 return EFI_INVALID_PARAMETER
;
1545 Status
= EFI_SUCCESS
;
1546 Private
= ATA_DEVICE_FROM_STORAGE_SECURITY (This
);
1548 if (MediaId
!= Private
->BlockIo
.Media
->MediaId
) {
1549 return EFI_MEDIA_CHANGED
;
1552 if (!Private
->BlockIo
.Media
->MediaPresent
) {
1553 return EFI_NO_MEDIA
;
1556 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1558 Status
= TrustTransferAtaDevice (
1562 SecurityProtocolSpecificData
,
1569 gBS
->RestoreTPL (OldTpl
);
1574 Send a security protocol command to a device.
1576 The SendData function sends a security protocol command containing the payload
1577 PayloadBuffer to the given MediaId. The security protocol command sent is
1578 defined by SecurityProtocolId and contains the security protocol specific data
1579 SecurityProtocolSpecificData. If the underlying protocol command requires a
1580 specific padding for the command payload, the SendData function shall add padding
1581 bytes to the command payload to satisfy the padding requirements.
1583 For devices supporting the SCSI command set, the security protocol command is sent
1584 using the SECURITY PROTOCOL OUT command defined in SPC-4.
1586 For devices supporting the ATA command set, the security protocol command is sent
1587 using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize
1588 is non-zero. If the PayloadBufferSize is zero, the security protocol command is
1589 sent using the Trusted Non-Data command defined in ATA8-ACS.
1591 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
1592 return EFI_INVALID_PARAMETER.
1594 If the given MediaId does not support security protocol commands, the function
1595 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
1596 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
1597 device, the function returns EFI_MEDIA_CHANGED.
1599 If the security protocol fails to complete within the Timeout period, the function
1600 shall return EFI_TIMEOUT.
1602 If the security protocol command completes without an error, the function shall return
1603 EFI_SUCCESS. If the security protocol command completes with an error, the function
1604 shall return EFI_DEVICE_ERROR.
1606 @param This Indicates a pointer to the calling context.
1607 @param MediaId ID of the medium to receive data from.
1608 @param Timeout The timeout, in 100ns units, to use for the execution
1609 of the security protocol command. A Timeout value of 0
1610 means that this function will wait indefinitely for the
1611 security protocol command to execute. If Timeout is greater
1612 than zero, then this function will return EFI_TIMEOUT
1613 if the time required to execute the receive data command
1614 is greater than Timeout.
1615 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1616 the security protocol command to be sent.
1617 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1618 of the security protocol command to be sent.
1619 @param PayloadBufferSize Size in bytes of the payload data buffer.
1620 @param PayloadBuffer A pointer to a destination buffer to store the security
1621 protocol command specific payload data for the security
1624 @retval EFI_SUCCESS The security protocol command completed successfully.
1625 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1626 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1627 @retval EFI_NO_MEDIA There is no media in the device.
1628 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1629 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
1630 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1631 protocol command to execute.
1636 AtaStorageSecuritySendData (
1637 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1640 IN UINT8 SecurityProtocolId
,
1641 IN UINT16 SecurityProtocolSpecificData
,
1642 IN UINTN PayloadBufferSize
,
1643 IN VOID
*PayloadBuffer
1647 ATA_DEVICE
*Private
;
1650 DEBUG ((EFI_D_INFO
, "EFI Storage Security Protocol - Send\n"));
1651 if ((PayloadBuffer
== NULL
) && (PayloadBufferSize
!= 0)) {
1652 return EFI_INVALID_PARAMETER
;
1655 Status
= EFI_SUCCESS
;
1656 Private
= ATA_DEVICE_FROM_STORAGE_SECURITY (This
);
1658 if (MediaId
!= Private
->BlockIo
.Media
->MediaId
) {
1659 return EFI_MEDIA_CHANGED
;
1662 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1663 Status
= TrustTransferAtaDevice (
1667 SecurityProtocolSpecificData
,
1674 gBS
->RestoreTPL (OldTpl
);
1679 The user Entry Point for module AtaBus. The user code starts with this function.
1681 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1682 @param[in] SystemTable A pointer to the EFI System Table.
1684 @retval EFI_SUCCESS The entry point is executed successfully.
1685 @retval other Some error occurs when executing this entry point.
1691 IN EFI_HANDLE ImageHandle
,
1692 IN EFI_SYSTEM_TABLE
*SystemTable
1698 // Install driver model protocol(s).
1700 Status
= EfiLibInstallDriverBindingComponentName2 (
1703 &gAtaBusDriverBinding
,
1705 &gAtaBusComponentName
,
1706 &gAtaBusComponentName2
1708 ASSERT_EFI_ERROR (Status
);