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 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
91 {NULL
, NULL
}, // AtaSubTaskList
96 Allocates an aligned buffer for ATA device.
98 This function allocates an aligned buffer for the ATA device to perform
99 ATA pass through operations. The alignment requirement is from ATA pass
102 @param AtaDevice The ATA child device involved for the operation.
103 @param BufferSize The request buffer size.
105 @return A pointer to the aligned buffer or NULL if the allocation fails.
109 AllocateAlignedBuffer (
110 IN ATA_DEVICE
*AtaDevice
,
114 return AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize
), AtaDevice
->AtaBusDriverData
->AtaPassThru
->Mode
->IoAlign
);
118 Frees an aligned buffer for ATA device.
120 This function frees an aligned buffer for the ATA device to perform
121 ATA pass through operations.
123 @param Buffer The aligned buffer to be freed.
124 @param BufferSize The request buffer size.
133 if (Buffer
!= NULL
) {
134 FreeAlignedPages (Buffer
, EFI_SIZE_TO_PAGES (BufferSize
));
140 Release all the resources allocated for the ATA device.
142 This function releases all the resources allocated for the ATA device.
144 @param AtaDevice The ATA child device involved for the operation.
148 ReleaseAtaResources (
149 IN ATA_DEVICE
*AtaDevice
152 ATA_BUS_ASYN_SUB_TASK
*SubTask
;
153 ATA_BUS_ASYN_TASK
*AtaTask
;
155 LIST_ENTRY
*DelEntry
;
158 FreeUnicodeStringTable (AtaDevice
->ControllerNameTable
);
159 FreeAlignedBuffer (AtaDevice
->Asb
, sizeof (EFI_ATA_STATUS_BLOCK
));
160 FreeAlignedBuffer (AtaDevice
->IdentifyData
, sizeof (ATA_IDENTIFY_DATA
));
161 if (AtaDevice
->DevicePath
!= NULL
) {
162 FreePool (AtaDevice
->DevicePath
);
164 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
165 if (!IsListEmpty (&AtaDevice
->AtaSubTaskList
)) {
167 // Free the Subtask list.
169 for(Entry
= AtaDevice
->AtaSubTaskList
.ForwardLink
;
170 Entry
!= (&AtaDevice
->AtaSubTaskList
);
173 Entry
= Entry
->ForwardLink
;
174 SubTask
= ATA_ASYN_SUB_TASK_FROM_ENTRY (DelEntry
);
176 RemoveEntryList (DelEntry
);
177 FreeAtaSubTask (SubTask
);
180 if (!IsListEmpty (&AtaDevice
->AtaTaskList
)) {
182 // Free the Subtask list.
184 for(Entry
= AtaDevice
->AtaTaskList
.ForwardLink
;
185 Entry
!= (&AtaDevice
->AtaTaskList
);
188 Entry
= Entry
->ForwardLink
;
189 AtaTask
= ATA_ASYN_TASK_FROM_ENTRY (DelEntry
);
191 RemoveEntryList (DelEntry
);
195 gBS
->RestoreTPL (OldTpl
);
196 FreePool (AtaDevice
);
201 Registers an ATA device.
203 This function allocates an ATA device structure for the ATA device specified by
204 Port and PortMultiplierPort if the ATA device is identified as a valid one.
205 Then it will create child handle and install Block IO and Disk Info protocol on
208 @param AtaBusDriverData The parent ATA bus driver data structure.
209 @param Port The port number of the ATA device.
210 @param PortMultiplierPort The port multiplier port number of the ATA device.
212 @retval EFI_SUCCESS The ATA device is successfully registered.
213 @retval EFI_OUT_OF_RESOURCES There is not enough memory to allocate the ATA device
214 and related data structures.
215 @return Others Some error occurs when registering the ATA device.
219 IN OUT ATA_BUS_DRIVER_DATA
*AtaBusDriverData
,
221 IN UINT16 PortMultiplierPort
225 ATA_DEVICE
*AtaDevice
;
226 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
227 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePathNode
;
228 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
229 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
230 EFI_HANDLE DeviceHandle
;
233 NewDevicePathNode
= NULL
;
235 RemainingDevicePath
= NULL
;
240 AtaPassThru
= AtaBusDriverData
->AtaPassThru
;
241 Status
= AtaPassThru
->BuildDevicePath (AtaPassThru
, Port
, PortMultiplierPort
, &NewDevicePathNode
);
242 if (EFI_ERROR (Status
)) {
246 DevicePath
= AppendDevicePathNode (AtaBusDriverData
->ParentDevicePath
, NewDevicePathNode
);
247 if (DevicePath
== NULL
) {
248 Status
= EFI_OUT_OF_RESOURCES
;
253 RemainingDevicePath
= DevicePath
;
254 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &DeviceHandle
);
255 if (!EFI_ERROR (Status
) && (DeviceHandle
!= NULL
) && IsDevicePathEnd(RemainingDevicePath
)) {
256 Status
= EFI_ALREADY_STARTED
;
257 FreePool (DevicePath
);
262 // Allocate ATA device from the template.
264 AtaDevice
= AllocateCopyPool (sizeof (ATA_DEVICE
), &gAtaDeviceTemplate
);
265 if (AtaDevice
== NULL
) {
266 Status
= EFI_OUT_OF_RESOURCES
;
271 // Initializes ATA device structures and allocates the required buffer.
273 AtaDevice
->BlockIo
.Media
= &AtaDevice
->BlockMedia
;
274 AtaDevice
->BlockIo2
.Media
= &AtaDevice
->BlockMedia
;
275 AtaDevice
->AtaBusDriverData
= AtaBusDriverData
;
276 AtaDevice
->DevicePath
= DevicePath
;
277 AtaDevice
->Port
= Port
;
278 AtaDevice
->PortMultiplierPort
= PortMultiplierPort
;
279 AtaDevice
->Asb
= AllocateAlignedBuffer (AtaDevice
, sizeof (EFI_ATA_STATUS_BLOCK
));
280 if (AtaDevice
->Asb
== NULL
) {
281 Status
= EFI_OUT_OF_RESOURCES
;
284 AtaDevice
->IdentifyData
= AllocateAlignedBuffer (AtaDevice
, sizeof (ATA_IDENTIFY_DATA
));
285 if (AtaDevice
->IdentifyData
== NULL
) {
286 Status
= EFI_OUT_OF_RESOURCES
;
291 // Initial Ata Task List
293 InitializeListHead (&AtaDevice
->AtaTaskList
);
294 InitializeListHead (&AtaDevice
->AtaSubTaskList
);
297 // Report Status Code to indicate the ATA device will be enabled
299 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
301 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_ENABLE
),
302 AtaBusDriverData
->ParentDevicePath
306 // Try to identify the ATA device via the ATA pass through command.
308 Status
= DiscoverAtaDevice (AtaDevice
);
309 if (EFI_ERROR (Status
)) {
314 // Build controller name for Component Name (2) protocol.
316 Status
= AddUnicodeString2 (
318 gAtaBusComponentName
.SupportedLanguages
,
319 &AtaDevice
->ControllerNameTable
,
320 AtaDevice
->ModelName
,
323 if (EFI_ERROR (Status
)) {
327 Status
= AddUnicodeString2 (
329 gAtaBusComponentName2
.SupportedLanguages
,
330 &AtaDevice
->ControllerNameTable
,
331 AtaDevice
->ModelName
,
334 if (EFI_ERROR (Status
)) {
339 // Update to AHCI interface GUID based on device path node. The default one
340 // is IDE interface GUID copied from template.
342 if (NewDevicePathNode
->SubType
== MSG_SATA_DP
) {
343 CopyGuid (&AtaDevice
->DiskInfo
.Interface
, &gEfiDiskInfoAhciInterfaceGuid
);
346 Status
= gBS
->InstallMultipleProtocolInterfaces (
348 &gEfiDevicePathProtocolGuid
,
349 AtaDevice
->DevicePath
,
350 &gEfiBlockIoProtocolGuid
,
352 &gEfiBlockIo2ProtocolGuid
,
353 &AtaDevice
->BlockIo2
,
354 &gEfiDiskInfoProtocolGuid
,
355 &AtaDevice
->DiskInfo
,
358 if (EFI_ERROR (Status
)) {
363 // See if the ata device support trust computing feature or not.
364 // If yes, then install Storage Security Protocol at the ata device handle.
366 if ((AtaDevice
->IdentifyData
->trusted_computing_support
& BIT0
) != 0) {
367 DEBUG ((EFI_D_INFO
, "Found TCG support in Port %x PortMultiplierPort %x\n", Port
, PortMultiplierPort
));
368 Status
= gBS
->InstallProtocolInterface (
370 &gEfiStorageSecurityCommandProtocolGuid
,
371 EFI_NATIVE_INTERFACE
,
372 &AtaDevice
->StorageSecurity
374 if (EFI_ERROR (Status
)) {
377 DEBUG ((EFI_D_INFO
, "Successfully Install Storage Security Protocol on the ATA device\n"));
381 AtaBusDriverData
->Controller
,
382 &gEfiAtaPassThruProtocolGuid
,
383 (VOID
**) &AtaPassThru
,
384 AtaBusDriverData
->DriverBindingHandle
,
386 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
390 if (NewDevicePathNode
!= NULL
) {
391 FreePool (NewDevicePathNode
);
394 if (EFI_ERROR (Status
) && (AtaDevice
!= NULL
)) {
395 ReleaseAtaResources (AtaDevice
);
396 DEBUG ((EFI_D_ERROR
| EFI_D_INIT
, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port
, PortMultiplierPort
, Status
));
403 Unregisters an ATA device.
405 This function removes the protocols installed on the controller handle and
406 frees the resources allocated for the ATA device.
408 @param This The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.
409 @param Controller The controller handle of the ATA device.
410 @param Handle The child handle.
412 @retval EFI_SUCCESS The ATA device is successfully unregistered.
413 @return Others Some error occurs when unregistering the ATA device.
417 UnregisterAtaDevice (
418 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
419 IN EFI_HANDLE Controller
,
424 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
425 EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
;
426 ATA_DEVICE
*AtaDevice
;
427 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
428 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*StorageSecurity
;
433 Status
= gBS
->OpenProtocol (
435 &gEfiBlockIoProtocolGuid
,
437 This
->DriverBindingHandle
,
439 EFI_OPEN_PROTOCOL_GET_PROTOCOL
441 if (EFI_ERROR (Status
)) {
443 // Locate BlockIo2 protocol
445 Status
= gBS
->OpenProtocol (
447 &gEfiBlockIo2ProtocolGuid
,
449 This
->DriverBindingHandle
,
451 EFI_OPEN_PROTOCOL_GET_PROTOCOL
453 if (EFI_ERROR (Status
)) {
459 // Get AtaDevice data.
461 if (BlockIo
!= NULL
) {
462 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (BlockIo
);
464 ASSERT (BlockIo2
!= NULL
);
465 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (BlockIo2
);
469 // Close the child handle
473 &gEfiAtaPassThruProtocolGuid
,
474 This
->DriverBindingHandle
,
479 // The Ata Bus driver installs the BlockIo and BlockIo2 in the DriverBindingStart().
480 // Here should uninstall both of them.
482 Status
= gBS
->UninstallMultipleProtocolInterfaces (
484 &gEfiDevicePathProtocolGuid
,
485 AtaDevice
->DevicePath
,
486 &gEfiBlockIoProtocolGuid
,
488 &gEfiBlockIo2ProtocolGuid
,
489 &AtaDevice
->BlockIo2
,
490 &gEfiDiskInfoProtocolGuid
,
491 &AtaDevice
->DiskInfo
,
495 if (EFI_ERROR (Status
)) {
498 &gEfiAtaPassThruProtocolGuid
,
499 (VOID
**) &AtaPassThru
,
500 This
->DriverBindingHandle
,
502 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
508 // If Storage Security Command Protocol is installed, then uninstall this protocol.
510 Status
= gBS
->OpenProtocol (
512 &gEfiStorageSecurityCommandProtocolGuid
,
513 (VOID
**) &StorageSecurity
,
514 This
->DriverBindingHandle
,
516 EFI_OPEN_PROTOCOL_GET_PROTOCOL
519 if (!EFI_ERROR (Status
)) {
520 Status
= gBS
->UninstallProtocolInterface (
522 &gEfiStorageSecurityCommandProtocolGuid
,
523 &AtaDevice
->StorageSecurity
525 if (EFI_ERROR (Status
)) {
528 &gEfiAtaPassThruProtocolGuid
,
529 (VOID
**) &AtaPassThru
,
530 This
->DriverBindingHandle
,
532 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
538 ReleaseAtaResources (AtaDevice
);
545 Tests to see if this driver supports a given controller. If a child device is provided,
546 it further tests to see if this driver supports creating a handle for the specified child device.
548 This function checks to see if the driver specified by This supports the device specified by
549 ControllerHandle. Drivers will typically use the device path attached to
550 ControllerHandle and/or the services from the bus I/O abstraction attached to
551 ControllerHandle to determine if the driver supports ControllerHandle. This function
552 may be called many times during platform initialization. In order to reduce boot times, the tests
553 performed by this function must be very small, and take as little time as possible to execute. This
554 function must not change the state of any hardware devices, and this function must be aware that the
555 device specified by ControllerHandle may already be managed by the same driver or a
556 different driver. This function must match its calls to AllocatePages() with FreePages(),
557 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
558 Since ControllerHandle may have been previously started by the same driver, if a protocol is
559 already in the opened state, then it must not be closed with CloseProtocol(). This is required
560 to guarantee the state of ControllerHandle is not modified by this function.
562 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
563 @param[in] ControllerHandle The handle of the controller to test. This handle
564 must support a protocol interface that supplies
565 an I/O abstraction to the driver.
566 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
567 parameter is ignored by device drivers, and is optional for bus
568 drivers. For bus drivers, if this parameter is not NULL, then
569 the bus driver must determine if the bus controller specified
570 by ControllerHandle and the child controller specified
571 by RemainingDevicePath are both supported by this
574 @retval EFI_SUCCESS The device specified by ControllerHandle and
575 RemainingDevicePath is supported by the driver specified by This.
576 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
577 RemainingDevicePath is already being managed by the driver
579 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
580 RemainingDevicePath is already being managed by a different
581 driver or an application that requires exclusive access.
582 Currently not implemented.
583 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
584 RemainingDevicePath is not supported by the driver specified by This.
588 AtaBusDriverBindingSupported (
589 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
590 IN EFI_HANDLE Controller
,
591 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
595 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
596 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
598 UINT16 PortMultiplierPort
;
601 // Test EFI_ATA_PASS_THRU_PROTOCOL on controller handle.
603 Status
= gBS
->OpenProtocol (
605 &gEfiAtaPassThruProtocolGuid
,
606 (VOID
**) &AtaPassThru
,
607 This
->DriverBindingHandle
,
609 EFI_OPEN_PROTOCOL_BY_DRIVER
612 if (Status
== EFI_ALREADY_STARTED
) {
616 if (EFI_ERROR (Status
)) {
621 // Test to see if this ATA Pass Thru Protocol is for a LOGICAL channel
623 if ((AtaPassThru
->Mode
->Attributes
& EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL
) == 0) {
625 // Close the I/O Abstraction(s) used to perform the supported test
629 &gEfiAtaPassThruProtocolGuid
,
630 This
->DriverBindingHandle
,
633 return EFI_UNSUPPORTED
;
637 // Test RemainingDevicePath is valid or not.
639 if ((RemainingDevicePath
!= NULL
) && !IsDevicePathEnd (RemainingDevicePath
)) {
640 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
641 if (EFI_ERROR (Status
)) {
643 // Close the I/O Abstraction(s) used to perform the supported test
647 &gEfiAtaPassThruProtocolGuid
,
648 This
->DriverBindingHandle
,
656 // Close the I/O Abstraction(s) used to perform the supported test
660 &gEfiAtaPassThruProtocolGuid
,
661 This
->DriverBindingHandle
,
666 // Open the EFI Device Path protocol needed to perform the supported test
668 Status
= gBS
->OpenProtocol (
670 &gEfiDevicePathProtocolGuid
,
671 (VOID
**) &ParentDevicePath
,
672 This
->DriverBindingHandle
,
674 EFI_OPEN_PROTOCOL_GET_PROTOCOL
681 Starts a device controller or a bus controller.
683 The Start() function is designed to be invoked from the EFI boot service ConnectController().
684 As a result, much of the error checking on the parameters to Start() has been moved into this
685 common boot service. It is legal to call Start() from other locations,
686 but the following calling restrictions must be followed or the system behavior will not be deterministic.
687 1. ControllerHandle must be a valid EFI_HANDLE.
688 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
689 EFI_DEVICE_PATH_PROTOCOL.
690 3. Prior to calling Start(), the Supported() function for the driver specified by This must
691 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
693 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
694 @param[in] ControllerHandle The handle of the controller to start. This handle
695 must support a protocol interface that supplies
696 an I/O abstraction to the driver.
697 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
698 parameter is ignored by device drivers, and is optional for bus
699 drivers. For a bus driver, if this parameter is NULL, then handles
700 for all the children of Controller are created by this driver.
701 If this parameter is not NULL and the first Device Path Node is
702 not the End of Device Path Node, then only the handle for the
703 child device specified by the first Device Path Node of
704 RemainingDevicePath is created by this driver.
705 If the first Device Path Node of RemainingDevicePath is
706 the End of Device Path Node, no child handle is created by this
709 @retval EFI_SUCCESS The device was started.
710 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
711 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
712 @retval Others The driver failded to start the device.
717 AtaBusDriverBindingStart (
718 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
719 IN EFI_HANDLE Controller
,
720 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
724 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
725 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
726 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
728 UINT16 PortMultiplierPort
;
730 AtaBusDriverData
= NULL
;
732 Status
= gBS
->OpenProtocol (
734 &gEfiDevicePathProtocolGuid
,
735 (VOID
**) &ParentDevicePath
,
736 This
->DriverBindingHandle
,
738 EFI_OPEN_PROTOCOL_GET_PROTOCOL
740 if (EFI_ERROR (Status
)) {
745 // Report Status Code to indicate ATA bus starts
747 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
749 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_INIT
),
753 Status
= gBS
->OpenProtocol (
755 &gEfiAtaPassThruProtocolGuid
,
756 (VOID
**) &AtaPassThru
,
757 This
->DriverBindingHandle
,
759 EFI_OPEN_PROTOCOL_BY_DRIVER
761 if ((EFI_ERROR (Status
)) && (Status
!= EFI_ALREADY_STARTED
)) {
766 // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.
768 if (Status
!= EFI_ALREADY_STARTED
) {
769 AtaBusDriverData
= AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA
));
770 if (AtaBusDriverData
== NULL
) {
771 Status
= EFI_OUT_OF_RESOURCES
;
775 AtaBusDriverData
->AtaPassThru
= AtaPassThru
;
776 AtaBusDriverData
->Controller
= Controller
;
777 AtaBusDriverData
->ParentDevicePath
= ParentDevicePath
;
778 AtaBusDriverData
->DriverBindingHandle
= This
->DriverBindingHandle
;
780 Status
= gBS
->InstallMultipleProtocolInterfaces (
786 if (EFI_ERROR (Status
)) {
791 Status
= gBS
->OpenProtocol (
794 (VOID
**) &AtaBusDriverData
,
795 This
->DriverBindingHandle
,
797 EFI_OPEN_PROTOCOL_GET_PROTOCOL
799 if (EFI_ERROR (Status
)) {
800 AtaBusDriverData
= NULL
;
806 // Report Status Code to indicate detecting devices on bus
808 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
810 (EFI_IO_BUS_ATA_ATAPI
| EFI_IOB_PC_DETECT
),
814 if (RemainingDevicePath
== NULL
) {
817 Status
= AtaPassThru
->GetNextPort (AtaPassThru
, &Port
);
818 if (EFI_ERROR (Status
)) {
820 // We cannot find more legal port then we are done.
825 PortMultiplierPort
= 0xFFFF;
827 Status
= AtaPassThru
->GetNextDevice (AtaPassThru
, Port
, &PortMultiplierPort
);
828 if (EFI_ERROR (Status
)) {
830 // We cannot find more legal port multiplier port number for ATA device
831 // on the port, then we are done.
835 RegisterAtaDevice (AtaBusDriverData
, Port
, PortMultiplierPort
);
838 Status
= EFI_SUCCESS
;
839 } else if (!IsDevicePathEnd (RemainingDevicePath
)) {
840 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
841 if (!EFI_ERROR (Status
)) {
842 Status
= RegisterAtaDevice (AtaBusDriverData
,Port
, PortMultiplierPort
);
850 if (AtaBusDriverData
!= NULL
) {
851 gBS
->UninstallMultipleProtocolInterfaces (
857 FreePool (AtaBusDriverData
);
862 &gEfiAtaPassThruProtocolGuid
,
863 This
->DriverBindingHandle
,
873 Stops a device controller or a bus controller.
875 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
876 As a result, much of the error checking on the parameters to Stop() has been moved
877 into this common boot service. It is legal to call Stop() from other locations,
878 but the following calling restrictions must be followed or the system behavior will not be deterministic.
879 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
880 same driver's Start() function.
881 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
882 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
883 Start() function, and the Start() function must have called OpenProtocol() on
884 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
886 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
887 @param[in] ControllerHandle A handle to the device being stopped. The handle must
888 support a bus specific I/O protocol for the driver
889 to use to stop the device.
890 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
891 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
892 if NumberOfChildren is 0.
894 @retval EFI_SUCCESS The device was stopped.
895 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
900 AtaBusDriverBindingStop (
901 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
902 IN EFI_HANDLE Controller
,
903 IN UINTN NumberOfChildren
,
904 IN EFI_HANDLE
*ChildHandleBuffer
908 BOOLEAN AllChildrenStopped
;
910 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
912 if (NumberOfChildren
== 0) {
913 Status
= gBS
->OpenProtocol (
916 (VOID
**) &AtaBusDriverData
,
917 This
->DriverBindingHandle
,
919 EFI_OPEN_PROTOCOL_GET_PROTOCOL
921 if (!EFI_ERROR (Status
)) {
922 gBS
->UninstallMultipleProtocolInterfaces (
928 FreePool (AtaBusDriverData
);
933 &gEfiAtaPassThruProtocolGuid
,
934 This
->DriverBindingHandle
,
941 AllChildrenStopped
= TRUE
;
943 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
945 Status
= UnregisterAtaDevice (This
, Controller
, ChildHandleBuffer
[Index
]);
946 if (EFI_ERROR (Status
)) {
947 AllChildrenStopped
= FALSE
;
951 if (!AllChildrenStopped
) {
952 return EFI_DEVICE_ERROR
;
960 Reset the Block Device.
962 @param This Indicates a pointer to the calling context.
963 @param ExtendedVerification Driver may perform diagnostics on reset.
965 @retval EFI_SUCCESS The device was reset.
966 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
973 IN EFI_BLOCK_IO_PROTOCOL
*This
,
974 IN BOOLEAN ExtendedVerification
978 ATA_DEVICE
*AtaDevice
;
981 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
983 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
985 Status
= ResetAtaDevice (AtaDevice
);
987 if (EFI_ERROR (Status
)) {
988 Status
= EFI_DEVICE_ERROR
;
991 gBS
->RestoreTPL (OldTpl
);
997 Read/Write BufferSize bytes from Lba from/into Buffer.
999 @param[in] This Indicates a pointer to the calling context. Either be
1000 block I/O or block I/O2.
1001 @param[in] MediaId The media ID that the read/write request is for.
1002 @param[in] Lba The starting logical block address to be read/written.
1003 The caller is responsible for reading/writing to only
1004 legitimate locations.
1005 @param[in, out] Token A pointer to the token associated with the transaction.
1006 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1007 @param[out] Buffer A pointer to the destination/source buffer for the data.
1008 @param[in] IsBlockIo2 Indicate the calling is from BlockIO or BlockIO2. TRUE is
1009 from BlockIO2, FALSE is for BlockIO.
1010 @param[in] IsWrite Indicates whether it is a write operation.
1012 @retval EFI_SUCCESS The data was read/written correctly to the device.
1013 @retval EFI_WRITE_PROTECTED The device can not be read/written to.
1014 @retval EFI_DEVICE_ERROR The device reported an error while performing the read/write.
1015 @retval EFI_NO_MEDIA There is no media in the device.
1016 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1017 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1018 @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid,
1019 or the buffer is not on proper alignment.
1027 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1028 IN UINTN BufferSize
,
1030 IN BOOLEAN IsBlockIo2
,
1034 ATA_DEVICE
*AtaDevice
;
1037 EFI_BLOCK_IO_MEDIA
*Media
;
1039 UINTN NumberOfBlocks
;
1043 Media
= ((EFI_BLOCK_IO2_PROTOCOL
*) This
)->Media
;
1044 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (This
);
1046 Media
= ((EFI_BLOCK_IO_PROTOCOL
*) This
)->Media
;
1047 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
1050 if (MediaId
!= Media
->MediaId
) {
1051 return EFI_MEDIA_CHANGED
;
1055 // Check parameters.
1057 if (Buffer
== NULL
) {
1058 return EFI_INVALID_PARAMETER
;
1061 if (BufferSize
== 0) {
1062 if ((Token
!= NULL
) && (Token
->Event
!= NULL
)) {
1063 Token
->TransactionStatus
= EFI_SUCCESS
;
1064 gBS
->SignalEvent (Token
->Event
);
1069 BlockSize
= Media
->BlockSize
;
1070 if ((BufferSize
% BlockSize
) != 0) {
1071 return EFI_BAD_BUFFER_SIZE
;
1074 NumberOfBlocks
= BufferSize
/ BlockSize
;
1075 if ((Lba
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
1076 return EFI_INVALID_PARAMETER
;
1079 IoAlign
= Media
->IoAlign
;
1080 if (IoAlign
> 0 && (((UINTN
) Buffer
& (IoAlign
- 1)) != 0)) {
1081 return EFI_INVALID_PARAMETER
;
1084 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1087 // Invoke low level AtaDevice Access Routine.
1089 Status
= AccessAtaDevice (AtaDevice
, Buffer
, Lba
, NumberOfBlocks
, IsWrite
, Token
);
1091 gBS
->RestoreTPL (OldTpl
);
1098 Read BufferSize bytes from Lba into Buffer.
1100 @param This Indicates a pointer to the calling context.
1101 @param MediaId Id of the media, changes every time the media is replaced.
1102 @param Lba The starting Logical Block Address to read from
1103 @param BufferSize Size of Buffer, must be a multiple of device block size.
1104 @param Buffer A pointer to the destination buffer for the data. The caller is
1105 responsible for either having implicit or explicit ownership of the buffer.
1107 @retval EFI_SUCCESS The data was read correctly from the device.
1108 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
1109 @retval EFI_NO_MEDIA There is no media in the device.
1110 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
1111 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1112 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1113 or the buffer is not on proper alignment.
1118 AtaBlockIoReadBlocks (
1119 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1122 IN UINTN BufferSize
,
1126 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, NULL
, BufferSize
, Buffer
, FALSE
, FALSE
);
1131 Write BufferSize bytes from Lba into Buffer.
1133 @param This Indicates a pointer to the calling context.
1134 @param MediaId The media ID that the write request is for.
1135 @param Lba The starting logical block address to be written. The caller is
1136 responsible for writing to only legitimate locations.
1137 @param BufferSize Size of Buffer, must be a multiple of device block size.
1138 @param Buffer A pointer to the source buffer for the data.
1140 @retval EFI_SUCCESS The data was written correctly to the device.
1141 @retval EFI_WRITE_PROTECTED The device can not be written to.
1142 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1143 @retval EFI_NO_MEDIA There is no media in the device.
1144 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1145 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1146 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1147 or the buffer is not on proper alignment.
1152 AtaBlockIoWriteBlocks (
1153 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1156 IN UINTN BufferSize
,
1160 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, NULL
, BufferSize
, Buffer
, FALSE
, TRUE
);
1165 Flush the Block Device.
1167 @param This Indicates a pointer to the calling context.
1169 @retval EFI_SUCCESS All outstanding data was written to the device
1170 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1171 @retval EFI_NO_MEDIA There is no media in the device.
1176 AtaBlockIoFlushBlocks (
1177 IN EFI_BLOCK_IO_PROTOCOL
*This
1187 Reset the Block Device.
1189 @param[in] This Indicates a pointer to the calling context.
1190 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
1192 @retval EFI_SUCCESS The device was reset.
1193 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
1200 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1201 IN BOOLEAN ExtendedVerification
1205 ATA_DEVICE
*AtaDevice
;
1208 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1210 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO2 (This
);
1212 AtaTerminateNonBlockingTask (AtaDevice
);
1214 Status
= ResetAtaDevice (AtaDevice
);
1216 if (EFI_ERROR (Status
)) {
1217 Status
= EFI_DEVICE_ERROR
;
1220 gBS
->RestoreTPL (OldTpl
);
1225 Read BufferSize bytes from Lba into Buffer.
1227 @param[in] This Indicates a pointer to the calling context.
1228 @param[in] MediaId Id of the media, changes every time the media is replaced.
1229 @param[in] Lba The starting Logical Block Address to read from.
1230 @param[in, out] Token A pointer to the token associated with the transaction.
1231 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1232 @param[out] Buffer A pointer to the destination buffer for the data. The caller is
1233 responsible for either having implicit or explicit ownership of the buffer.
1235 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
1236 The data was read correctly from the device if
1238 @retval EFI_DEVICE_ERROR The device reported an error while performing
1240 @retval EFI_NO_MEDIA There is no media in the device.
1241 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1242 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
1243 intrinsic block size of the device.
1244 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1245 or the buffer is not on proper alignment.
1246 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
1252 AtaBlockIoReadBlocksEx (
1253 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1256 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1257 IN UINTN BufferSize
,
1261 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, Token
, BufferSize
, Buffer
, TRUE
, FALSE
);
1266 Write BufferSize bytes from Lba into Buffer.
1268 @param[in] This Indicates a pointer to the calling context.
1269 @param[in] MediaId The media ID that the write request is for.
1270 @param[in] Lba The starting logical block address to be written. The
1271 caller is responsible for writing to only legitimate
1273 @param[in, out] Token A pointer to the token associated with the transaction.
1274 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1275 @param[in] Buffer A pointer to the source buffer for the data.
1277 @retval EFI_SUCCESS The data was written correctly to the device.
1278 @retval EFI_WRITE_PROTECTED The device can not be written to.
1279 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1280 @retval EFI_NO_MEDIA There is no media in the device.
1281 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1282 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1283 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1284 or the buffer is not on proper alignment.
1289 AtaBlockIoWriteBlocksEx (
1290 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1293 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
1294 IN UINTN BufferSize
,
1298 return BlockIoReadWrite ((VOID
*) This
, MediaId
, Lba
, Token
, BufferSize
, Buffer
, TRUE
, TRUE
);
1303 Flush the Block Device.
1305 @param[in] This Indicates a pointer to the calling context.
1306 @param[in, out] Token A pointer to the token associated with the transaction.
1308 @retval EFI_SUCCESS All outstanding data was written to the device
1309 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1310 @retval EFI_NO_MEDIA There is no media in the device.
1315 AtaBlockIoFlushBlocksEx (
1316 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
1317 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
1321 // Signal event and return directly.
1323 if (Token
!= NULL
&& Token
->Event
!= NULL
) {
1324 Token
->TransactionStatus
= EFI_SUCCESS
;
1325 gBS
->SignalEvent (Token
->Event
);
1330 Provides inquiry information for the controller type.
1332 This function is used by the IDE bus driver to get inquiry data. Data format
1333 of Identify data is defined by the Interface GUID.
1335 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1336 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
1337 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
1339 @retval EFI_SUCCESS The command was accepted without any errors.
1340 @retval EFI_NOT_FOUND Device does not support this data class
1341 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
1342 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
1347 AtaDiskInfoInquiry (
1348 IN EFI_DISK_INFO_PROTOCOL
*This
,
1349 IN OUT VOID
*InquiryData
,
1350 IN OUT UINT32
*InquiryDataSize
1353 return EFI_NOT_FOUND
;
1358 Provides identify information for the controller type.
1360 This function is used by the IDE bus driver to get identify data. Data format
1361 of Identify data is defined by the Interface GUID.
1363 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
1365 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
1366 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
1369 @retval EFI_SUCCESS The command was accepted without any errors.
1370 @retval EFI_NOT_FOUND Device does not support this data class
1371 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
1372 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
1377 AtaDiskInfoIdentify (
1378 IN EFI_DISK_INFO_PROTOCOL
*This
,
1379 IN OUT VOID
*IdentifyData
,
1380 IN OUT UINT32
*IdentifyDataSize
1384 ATA_DEVICE
*AtaDevice
;
1386 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1388 Status
= EFI_BUFFER_TOO_SMALL
;
1389 if (*IdentifyDataSize
>= sizeof (ATA_IDENTIFY_DATA
)) {
1390 Status
= EFI_SUCCESS
;
1391 CopyMem (IdentifyData
, AtaDevice
->IdentifyData
, sizeof (ATA_IDENTIFY_DATA
));
1393 *IdentifyDataSize
= sizeof (ATA_IDENTIFY_DATA
);
1400 Provides sense data information for the controller type.
1402 This function is used by the IDE bus driver to get sense data.
1403 Data format of Sense data is defined by the Interface GUID.
1405 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1406 @param[in, out] SenseData Pointer to the SenseData.
1407 @param[in, out] SenseDataSize Size of SenseData in bytes.
1408 @param[out] SenseDataNumber Pointer to the value for the sense data size.
1410 @retval EFI_SUCCESS The command was accepted without any errors.
1411 @retval EFI_NOT_FOUND Device does not support this data class.
1412 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
1413 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
1418 AtaDiskInfoSenseData (
1419 IN EFI_DISK_INFO_PROTOCOL
*This
,
1420 IN OUT VOID
*SenseData
,
1421 IN OUT UINT32
*SenseDataSize
,
1422 OUT UINT8
*SenseDataNumber
1425 return EFI_NOT_FOUND
;
1430 This function is used by the IDE bus driver to get controller information.
1432 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1433 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
1434 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
1436 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
1437 @retval EFI_UNSUPPORTED This is not an IDE device.
1442 AtaDiskInfoWhichIde (
1443 IN EFI_DISK_INFO_PROTOCOL
*This
,
1444 OUT UINT32
*IdeChannel
,
1445 OUT UINT32
*IdeDevice
1448 ATA_DEVICE
*AtaDevice
;
1450 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1451 *IdeChannel
= AtaDevice
->Port
;
1452 *IdeDevice
= AtaDevice
->PortMultiplierPort
;
1458 Send a security protocol command to a device that receives data and/or the result
1459 of one or more commands sent by SendData.
1461 The ReceiveData function sends a security protocol command to the given MediaId.
1462 The security protocol command sent is defined by SecurityProtocolId and contains
1463 the security protocol specific data SecurityProtocolSpecificData. The function
1464 returns the data from the security protocol command in PayloadBuffer.
1466 For devices supporting the SCSI command set, the security protocol command is sent
1467 using the SECURITY PROTOCOL IN command defined in SPC-4.
1469 For devices supporting the ATA command set, the security protocol command is sent
1470 using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize
1473 If the PayloadBufferSize is zero, the security protocol command is sent using the
1474 Trusted Non-Data command defined in ATA8-ACS.
1476 If PayloadBufferSize is too small to store the available data from the security
1477 protocol command, the function shall copy PayloadBufferSize bytes into the
1478 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
1480 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
1481 the function shall return EFI_INVALID_PARAMETER.
1483 If the given MediaId does not support security protocol commands, the function shall
1484 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
1485 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
1486 the function returns EFI_MEDIA_CHANGED.
1488 If the security protocol fails to complete within the Timeout period, the function
1489 shall return EFI_TIMEOUT.
1491 If the security protocol command completes without an error, the function shall
1492 return EFI_SUCCESS. If the security protocol command completes with an error, the
1493 function shall return EFI_DEVICE_ERROR.
1495 @param This Indicates a pointer to the calling context.
1496 @param MediaId ID of the medium to receive data from.
1497 @param Timeout The timeout, in 100ns units, to use for the execution
1498 of the security protocol command. A Timeout value of 0
1499 means that this function will wait indefinitely for the
1500 security protocol command to execute. If Timeout is greater
1501 than zero, then this function will return EFI_TIMEOUT
1502 if the time required to execute the receive data command
1503 is greater than Timeout.
1504 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1505 the security protocol command to be sent.
1506 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1507 of the security protocol command to be sent.
1508 @param PayloadBufferSize Size in bytes of the payload data buffer.
1509 @param PayloadBuffer A pointer to a destination buffer to store the security
1510 protocol command specific payload data for the security
1511 protocol command. The caller is responsible for having
1512 either implicit or explicit ownership of the buffer.
1513 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
1514 data written to the payload data buffer.
1516 @retval EFI_SUCCESS The security protocol command completed successfully.
1517 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
1518 data from the device. The PayloadBuffer contains the truncated data.
1519 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1520 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1521 @retval EFI_NO_MEDIA There is no media in the device.
1522 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1523 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
1524 PayloadBufferSize is non-zero.
1525 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1526 protocol command to execute.
1531 AtaStorageSecurityReceiveData (
1532 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1535 IN UINT8 SecurityProtocolId
,
1536 IN UINT16 SecurityProtocolSpecificData
,
1537 IN UINTN PayloadBufferSize
,
1538 OUT VOID
*PayloadBuffer
,
1539 OUT UINTN
*PayloadTransferSize
1543 ATA_DEVICE
*Private
;
1546 DEBUG ((EFI_D_INFO
, "EFI Storage Security Protocol - Read\n"));
1547 if ((PayloadBuffer
== NULL
|| PayloadTransferSize
== NULL
) && PayloadBufferSize
!= 0) {
1548 return EFI_INVALID_PARAMETER
;
1551 Status
= EFI_SUCCESS
;
1552 Private
= ATA_DEVICE_FROM_STORAGE_SECURITY (This
);
1554 if (MediaId
!= Private
->BlockIo
.Media
->MediaId
) {
1555 return EFI_MEDIA_CHANGED
;
1558 if (!Private
->BlockIo
.Media
->MediaPresent
) {
1559 return EFI_NO_MEDIA
;
1562 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1564 Status
= TrustTransferAtaDevice (
1568 SecurityProtocolSpecificData
,
1575 gBS
->RestoreTPL (OldTpl
);
1580 Send a security protocol command to a device.
1582 The SendData function sends a security protocol command containing the payload
1583 PayloadBuffer to the given MediaId. The security protocol command sent is
1584 defined by SecurityProtocolId and contains the security protocol specific data
1585 SecurityProtocolSpecificData. If the underlying protocol command requires a
1586 specific padding for the command payload, the SendData function shall add padding
1587 bytes to the command payload to satisfy the padding requirements.
1589 For devices supporting the SCSI command set, the security protocol command is sent
1590 using the SECURITY PROTOCOL OUT command defined in SPC-4.
1592 For devices supporting the ATA command set, the security protocol command is sent
1593 using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize
1594 is non-zero. If the PayloadBufferSize is zero, the security protocol command is
1595 sent using the Trusted Non-Data command defined in ATA8-ACS.
1597 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
1598 return EFI_INVALID_PARAMETER.
1600 If the given MediaId does not support security protocol commands, the function
1601 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
1602 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
1603 device, the function returns EFI_MEDIA_CHANGED.
1605 If the security protocol fails to complete within the Timeout period, the function
1606 shall return EFI_TIMEOUT.
1608 If the security protocol command completes without an error, the function shall return
1609 EFI_SUCCESS. If the security protocol command completes with an error, the function
1610 shall return EFI_DEVICE_ERROR.
1612 @param This Indicates a pointer to the calling context.
1613 @param MediaId ID of the medium to receive data from.
1614 @param Timeout The timeout, in 100ns units, to use for the execution
1615 of the security protocol command. A Timeout value of 0
1616 means that this function will wait indefinitely for the
1617 security protocol command to execute. If Timeout is greater
1618 than zero, then this function will return EFI_TIMEOUT
1619 if the time required to execute the receive data command
1620 is greater than Timeout.
1621 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1622 the security protocol command to be sent.
1623 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1624 of the security protocol command to be sent.
1625 @param PayloadBufferSize Size in bytes of the payload data buffer.
1626 @param PayloadBuffer A pointer to a destination buffer to store the security
1627 protocol command specific payload data for the security
1630 @retval EFI_SUCCESS The security protocol command completed successfully.
1631 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1632 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1633 @retval EFI_NO_MEDIA There is no media in the device.
1634 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1635 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
1636 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1637 protocol command to execute.
1642 AtaStorageSecuritySendData (
1643 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1646 IN UINT8 SecurityProtocolId
,
1647 IN UINT16 SecurityProtocolSpecificData
,
1648 IN UINTN PayloadBufferSize
,
1649 IN VOID
*PayloadBuffer
1653 ATA_DEVICE
*Private
;
1656 DEBUG ((EFI_D_INFO
, "EFI Storage Security Protocol - Send\n"));
1657 if ((PayloadBuffer
== NULL
) && (PayloadBufferSize
!= 0)) {
1658 return EFI_INVALID_PARAMETER
;
1661 Status
= EFI_SUCCESS
;
1662 Private
= ATA_DEVICE_FROM_STORAGE_SECURITY (This
);
1664 if (MediaId
!= Private
->BlockIo
.Media
->MediaId
) {
1665 return EFI_MEDIA_CHANGED
;
1668 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1669 Status
= TrustTransferAtaDevice (
1673 SecurityProtocolSpecificData
,
1680 gBS
->RestoreTPL (OldTpl
);
1685 The user Entry Point for module AtaBus. The user code starts with this function.
1687 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1688 @param[in] SystemTable A pointer to the EFI System Table.
1690 @retval EFI_SUCCESS The entry point is executed successfully.
1691 @retval other Some error occurs when executing this entry point.
1697 IN EFI_HANDLE ImageHandle
,
1698 IN EFI_SYSTEM_TABLE
*SystemTable
1704 // Install driver model protocol(s).
1706 Status
= EfiLibInstallDriverBindingComponentName2 (
1709 &gAtaBusDriverBinding
,
1711 &gAtaBusComponentName
,
1712 &gAtaBusComponentName2
1714 ASSERT_EFI_ERROR (Status
);