2 This file implements protocol interfaces for ATA bus driver.
4 This file implements protocol interfaces: Driver Binding protocol,
5 Block IO protocol and DiskInfo protocol.
7 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 // ATA Bus Driver Binding Protocol Instance
24 EFI_DRIVER_BINDING_PROTOCOL gAtaBusDriverBinding
= {
25 AtaBusDriverBindingSupported
,
26 AtaBusDriverBindingStart
,
27 AtaBusDriverBindingStop
,
34 // Template for ATA Child Device.
36 ATA_DEVICE gAtaDeviceTemplate
= {
37 ATA_DEVICE_SIGNATURE
, // Signature
40 EFI_BLOCK_IO_PROTOCOL_REVISION
,
44 AtaBlockIoWriteBlocks
,
49 FALSE
, // RemovableMedia
51 FALSE
, // LogicPartition
53 FALSE
, // WritingCache
57 0, // LowestAlignedLba
58 1 // LogicalBlocksPerPhysicalBlock
61 EFI_DISK_INFO_IDE_INTERFACE_GUID
,
68 NULL
, // AtaBusDriverData
70 0, // PortMultiplierPort
77 NULL
, // ControllerNameTable
78 {L
'\0', } // ModelName
82 Allocates an aligned buffer for ATA device.
84 This function allocates an aligned buffer for the ATA device to perform
85 ATA pass through operations. The alignment requirement is from ATA pass
88 @param AtaDevice The ATA child device involved for the operation.
89 @param BufferSize The request buffer size.
91 @return A pointer to the aligned buffer or NULL if the allocation fails.
95 AllocateAlignedBuffer (
96 IN ATA_DEVICE
*AtaDevice
,
100 return AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize
), AtaDevice
->AtaBusDriverData
->AtaPassThru
->Mode
->IoAlign
);
104 Frees an aligned buffer for ATA device.
106 This function frees an aligned buffer for the ATA device to perform
107 ATA pass through operations.
109 @param Buffer The aligned buffer to be freed.
110 @param BufferSize The request buffer size.
119 if (Buffer
!= NULL
) {
120 FreePages (Buffer
, EFI_SIZE_TO_PAGES (BufferSize
));
126 Release all the resources allocated for the ATA device.
128 This function releases all the resources allocated for the ATA device.
130 @param AtaDevice The ATA child device involved for the operation.
134 ReleaseAtaResources (
135 IN ATA_DEVICE
*AtaDevice
138 FreeUnicodeStringTable (AtaDevice
->ControllerNameTable
);
139 FreeAlignedBuffer (AtaDevice
->Asb
, sizeof (*AtaDevice
->Asb
));
140 FreeAlignedBuffer (AtaDevice
->IdentifyData
, sizeof (*AtaDevice
->IdentifyData
));
141 if (AtaDevice
->DevicePath
!= NULL
) {
142 FreePool (AtaDevice
->DevicePath
);
144 FreePool (AtaDevice
);
149 Registers an ATA device.
151 This function allocates an ATA device structure for the ATA device specified by
152 Port and PortMultiplierPort if the ATA device is identified as a valid one.
153 Then it will create child handle and install Block IO and Disk Info protocol on
156 @param AtaBusDriverData The parent ATA bus driver data structure.
157 @param Port The port number of the ATA device.
158 @param PortMultiplierPort The port multiplier port number of the ATA device.
160 @retval EFI_SUCCESS The ATA device is successfully registered.
161 @retval EFI_OUT_OF_RESOURCES There is not enough memory to allocate the ATA device
162 and related data structures.
163 @return Others Some error occurs when registering the ATA device.
167 IN OUT ATA_BUS_DRIVER_DATA
*AtaBusDriverData
,
169 IN UINT16 PortMultiplierPort
173 ATA_DEVICE
*AtaDevice
;
174 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
175 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePathNode
;
176 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
177 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
178 EFI_HANDLE DeviceHandle
;
181 NewDevicePathNode
= NULL
;
183 RemainingDevicePath
= NULL
;
188 AtaPassThru
= AtaBusDriverData
->AtaPassThru
;
189 Status
= AtaPassThru
->BuildDevicePath (AtaPassThru
, Port
, PortMultiplierPort
, &NewDevicePathNode
);
190 if (EFI_ERROR (Status
)) {
194 DevicePath
= AppendDevicePathNode (AtaBusDriverData
->ParentDevicePath
, NewDevicePathNode
);
195 if (DevicePath
== NULL
) {
200 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &DeviceHandle
);
201 if (!EFI_ERROR (Status
) && (DeviceHandle
!= NULL
) && IsDevicePathEnd(RemainingDevicePath
)) {
202 Status
= EFI_ALREADY_STARTED
;
207 // Allocate ATA device from the template.
209 AtaDevice
= AllocateCopyPool (sizeof (gAtaDeviceTemplate
), &gAtaDeviceTemplate
);
210 if (AtaDevice
== NULL
) {
211 Status
= EFI_OUT_OF_RESOURCES
;
216 // Initializes ATA device structures and allocates the required buffer.
218 AtaDevice
->BlockIo
.Media
= &AtaDevice
->BlockMedia
;
219 AtaDevice
->AtaBusDriverData
= AtaBusDriverData
;
220 AtaDevice
->DevicePath
= DevicePath
;
221 AtaDevice
->Port
= Port
;
222 AtaDevice
->PortMultiplierPort
= PortMultiplierPort
;
223 AtaDevice
->Asb
= AllocateAlignedBuffer (AtaDevice
, sizeof (*AtaDevice
->Asb
));
224 if (AtaDevice
->Asb
== NULL
) {
225 Status
= EFI_OUT_OF_RESOURCES
;
228 AtaDevice
->IdentifyData
= AllocateAlignedBuffer (AtaDevice
, sizeof (*AtaDevice
->IdentifyData
));
229 if (AtaDevice
->IdentifyData
== NULL
) {
230 Status
= EFI_OUT_OF_RESOURCES
;
235 // Try to identify the ATA device via the ATA pass through command.
237 Status
= DiscoverAtaDevice (AtaDevice
);
238 if (EFI_ERROR (Status
)) {
243 // Build controller name for Component Name (2) protocol.
245 Status
= AddUnicodeString2 (
247 gAtaBusComponentName
.SupportedLanguages
,
248 &AtaDevice
->ControllerNameTable
,
249 AtaDevice
->ModelName
,
252 if (EFI_ERROR (Status
)) {
256 Status
= AddUnicodeString2 (
258 gAtaBusComponentName2
.SupportedLanguages
,
259 &AtaDevice
->ControllerNameTable
,
260 AtaDevice
->ModelName
,
263 if (EFI_ERROR (Status
)) {
268 // Update to AHCI interface GUID based on device path node. The default one
269 // is IDE interface GUID copied from template.
271 if (NewDevicePathNode
->SubType
== MSG_SATA_DP
) {
272 CopyGuid (&AtaDevice
->DiskInfo
.Interface
, &gEfiDiskInfoAhciInterfaceGuid
);
275 Status
= gBS
->InstallMultipleProtocolInterfaces (
277 &gEfiDevicePathProtocolGuid
,
278 AtaDevice
->DevicePath
,
279 &gEfiBlockIoProtocolGuid
,
281 &gEfiDiskInfoProtocolGuid
,
282 &AtaDevice
->DiskInfo
,
285 if (EFI_ERROR (Status
)) {
290 AtaBusDriverData
->Controller
,
291 &gEfiAtaPassThruProtocolGuid
,
292 (VOID
**) &AtaPassThru
,
293 AtaBusDriverData
->DriverBindingHandle
,
295 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
299 if (NewDevicePathNode
!= NULL
) {
300 FreePool (NewDevicePathNode
);
303 if (EFI_ERROR (Status
) && (AtaDevice
!= NULL
)) {
304 ReleaseAtaResources (AtaDevice
);
305 DEBUG ((DEBUG_ERROR
| DEBUG_INIT
, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port
, PortMultiplierPort
, Status
));
312 Unregisters an ATA device.
314 This function removes the protocols installed on the controller handle and
315 frees the resources allocated for the ATA device.
317 @param This The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.
318 @param Controller The controller handle of the ATA device.
319 @param Handle The child handle.
321 @retval EFI_SUCCESS The ATA device is successfully unregistered.
322 @return Others Some error occurs when unregistering the ATA device.
326 UnregisterAtaDevice (
327 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
328 IN EFI_HANDLE Controller
,
333 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
334 ATA_DEVICE
*AtaDevice
;
335 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
337 Status
= gBS
->OpenProtocol (
339 &gEfiBlockIoProtocolGuid
,
341 This
->DriverBindingHandle
,
343 EFI_OPEN_PROTOCOL_GET_PROTOCOL
345 if (EFI_ERROR (Status
)) {
349 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (BlockIo
);
352 // Close the child handle
356 &gEfiAtaPassThruProtocolGuid
,
357 This
->DriverBindingHandle
,
361 Status
= gBS
->UninstallMultipleProtocolInterfaces (
363 &gEfiDevicePathProtocolGuid
,
364 AtaDevice
->DevicePath
,
365 &gEfiBlockIoProtocolGuid
,
367 &gEfiDiskInfoProtocolGuid
,
368 &AtaDevice
->DiskInfo
,
372 if (EFI_ERROR (Status
)) {
375 &gEfiAtaPassThruProtocolGuid
,
376 (VOID
**) &AtaPassThru
,
377 This
->DriverBindingHandle
,
379 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
384 ReleaseAtaResources (AtaDevice
);
392 Tests to see if this driver supports a given controller. If a child device is provided,
393 it further tests to see if this driver supports creating a handle for the specified child device.
395 This function checks to see if the driver specified by This supports the device specified by
396 ControllerHandle. Drivers will typically use the device path attached to
397 ControllerHandle and/or the services from the bus I/O abstraction attached to
398 ControllerHandle to determine if the driver supports ControllerHandle. This function
399 may be called many times during platform initialization. In order to reduce boot times, the tests
400 performed by this function must be very small, and take as little time as possible to execute. This
401 function must not change the state of any hardware devices, and this function must be aware that the
402 device specified by ControllerHandle may already be managed by the same driver or a
403 different driver. This function must match its calls to AllocatePages() with FreePages(),
404 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
405 Since ControllerHandle may have been previously started by the same driver, if a protocol is
406 already in the opened state, then it must not be closed with CloseProtocol(). This is required
407 to guarantee the state of ControllerHandle is not modified by this function.
409 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
410 @param[in] ControllerHandle The handle of the controller to test. This handle
411 must support a protocol interface that supplies
412 an I/O abstraction to the driver.
413 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
414 parameter is ignored by device drivers, and is optional for bus
415 drivers. For bus drivers, if this parameter is not NULL, then
416 the bus driver must determine if the bus controller specified
417 by ControllerHandle and the child controller specified
418 by RemainingDevicePath are both supported by this
421 @retval EFI_SUCCESS The device specified by ControllerHandle and
422 RemainingDevicePath is supported by the driver specified by This.
423 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
424 RemainingDevicePath is already being managed by the driver
426 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
427 RemainingDevicePath is already being managed by a different
428 driver or an application that requires exclusive access.
429 Currently not implemented.
430 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
431 RemainingDevicePath is not supported by the driver specified by This.
435 AtaBusDriverBindingSupported (
436 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
437 IN EFI_HANDLE Controller
,
438 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
442 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
443 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
445 UINT16 PortMultiplierPort
;
448 // Test EFI_ATA_PASS_THRU_PROTOCOL on controller handle.
450 Status
= gBS
->OpenProtocol (
452 &gEfiAtaPassThruProtocolGuid
,
453 (VOID
**) &AtaPassThru
,
454 This
->DriverBindingHandle
,
456 EFI_OPEN_PROTOCOL_BY_DRIVER
459 if (Status
== EFI_ALREADY_STARTED
) {
463 if (EFI_ERROR (Status
)) {
468 // Test RemainingDevicePath is valid or not.
470 if ((RemainingDevicePath
!= NULL
) && !IsDevicePathEnd (RemainingDevicePath
)) {
471 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
472 if (EFI_ERROR (Status
)) {
478 // Close the I/O Abstraction(s) used to perform the supported test
482 &gEfiAtaPassThruProtocolGuid
,
483 This
->DriverBindingHandle
,
488 // Open the EFI Device Path protocol needed to perform the supported test
490 Status
= gBS
->OpenProtocol (
492 &gEfiDevicePathProtocolGuid
,
493 (VOID
**) &ParentDevicePath
,
494 This
->DriverBindingHandle
,
496 EFI_OPEN_PROTOCOL_GET_PROTOCOL
503 Starts a device controller or a bus controller.
505 The Start() function is designed to be invoked from the EFI boot service ConnectController().
506 As a result, much of the error checking on the parameters to Start() has been moved into this
507 common boot service. It is legal to call Start() from other locations,
508 but the following calling restrictions must be followed or the system behavior will not be deterministic.
509 1. ControllerHandle must be a valid EFI_HANDLE.
510 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
511 EFI_DEVICE_PATH_PROTOCOL.
512 3. Prior to calling Start(), the Supported() function for the driver specified by This must
513 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
515 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
516 @param[in] ControllerHandle The handle of the controller to start. This handle
517 must support a protocol interface that supplies
518 an I/O abstraction to the driver.
519 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
520 parameter is ignored by device drivers, and is optional for bus
521 drivers. For a bus driver, if this parameter is NULL, then handles
522 for all the children of Controller are created by this driver.
523 If this parameter is not NULL and the first Device Path Node is
524 not the End of Device Path Node, then only the handle for the
525 child device specified by the first Device Path Node of
526 RemainingDevicePath is created by this driver.
527 If the first Device Path Node of RemainingDevicePath is
528 the End of Device Path Node, no child handle is created by this
531 @retval EFI_SUCCESS The device was started.
532 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
533 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
534 @retval Others The driver failded to start the device.
539 AtaBusDriverBindingStart (
540 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
541 IN EFI_HANDLE Controller
,
542 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
546 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
547 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
548 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
550 UINT16 PortMultiplierPort
;
552 AtaBusDriverData
= NULL
;
554 Status
= gBS
->OpenProtocol (
556 &gEfiDevicePathProtocolGuid
,
557 (VOID
**) &ParentDevicePath
,
558 This
->DriverBindingHandle
,
560 EFI_OPEN_PROTOCOL_GET_PROTOCOL
562 if (EFI_ERROR (Status
)) {
566 Status
= gBS
->OpenProtocol (
568 &gEfiAtaPassThruProtocolGuid
,
569 (VOID
**) &AtaPassThru
,
570 This
->DriverBindingHandle
,
572 EFI_OPEN_PROTOCOL_BY_DRIVER
574 if ((EFI_ERROR (Status
)) && (Status
!= EFI_ALREADY_STARTED
)) {
579 // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.
581 if (Status
!= EFI_ALREADY_STARTED
) {
582 AtaBusDriverData
= AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA
));
583 if (AtaBusDriverData
== NULL
) {
584 Status
= EFI_OUT_OF_RESOURCES
;
588 AtaBusDriverData
->AtaPassThru
= AtaPassThru
;
589 AtaBusDriverData
->Controller
= Controller
;
590 AtaBusDriverData
->ParentDevicePath
= ParentDevicePath
;
591 AtaBusDriverData
->DriverBindingHandle
= This
->DriverBindingHandle
;
593 Status
= gBS
->InstallMultipleProtocolInterfaces (
599 if (EFI_ERROR (Status
)) {
604 Status
= gBS
->OpenProtocol (
607 (VOID
**) &AtaBusDriverData
,
608 This
->DriverBindingHandle
,
610 EFI_OPEN_PROTOCOL_GET_PROTOCOL
612 if (EFI_ERROR (Status
)) {
613 AtaBusDriverData
= NULL
;
618 if (RemainingDevicePath
== NULL
) {
621 Status
= AtaPassThru
->GetNextPort (AtaPassThru
, &Port
);
622 if (EFI_ERROR (Status
)) {
624 // We cannot find more legal port then we are done.
629 PortMultiplierPort
= 0xFFFF;
631 Status
= AtaPassThru
->GetNextDevice (AtaPassThru
, Port
, &PortMultiplierPort
);
632 if (EFI_ERROR (Status
)) {
634 // We cannot find more legal port multiplier port number for ATA device
635 // on the port, then we are done.
639 RegisterAtaDevice (AtaBusDriverData
, Port
, PortMultiplierPort
);
642 Status
= EFI_SUCCESS
;
643 } else if (!IsDevicePathEnd (RemainingDevicePath
)) {
644 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
645 if (!EFI_ERROR (Status
)) {
646 Status
= RegisterAtaDevice (AtaBusDriverData
,Port
, PortMultiplierPort
);
654 if (AtaBusDriverData
!= NULL
) {
655 gBS
->UninstallMultipleProtocolInterfaces (
661 FreePool (AtaBusDriverData
);
666 &gEfiAtaPassThruProtocolGuid
,
667 This
->DriverBindingHandle
,
677 Stops a device controller or a bus controller.
679 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
680 As a result, much of the error checking on the parameters to Stop() has been moved
681 into this common boot service. It is legal to call Stop() from other locations,
682 but the following calling restrictions must be followed or the system behavior will not be deterministic.
683 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
684 same driver's Start() function.
685 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
686 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
687 Start() function, and the Start() function must have called OpenProtocol() on
688 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
690 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
691 @param[in] ControllerHandle A handle to the device being stopped. The handle must
692 support a bus specific I/O protocol for the driver
693 to use to stop the device.
694 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
695 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
696 if NumberOfChildren is 0.
698 @retval EFI_SUCCESS The device was stopped.
699 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
704 AtaBusDriverBindingStop (
705 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
706 IN EFI_HANDLE Controller
,
707 IN UINTN NumberOfChildren
,
708 IN EFI_HANDLE
*ChildHandleBuffer
712 BOOLEAN AllChildrenStopped
;
714 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
716 if (NumberOfChildren
== 0) {
717 Status
= gBS
->OpenProtocol (
720 (VOID
**) &AtaBusDriverData
,
721 This
->DriverBindingHandle
,
723 EFI_OPEN_PROTOCOL_GET_PROTOCOL
725 if (!EFI_ERROR (Status
)) {
726 gBS
->UninstallMultipleProtocolInterfaces (
732 FreePool (AtaBusDriverData
);
737 &gEfiAtaPassThruProtocolGuid
,
738 This
->DriverBindingHandle
,
745 AllChildrenStopped
= TRUE
;
747 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
749 Status
= UnregisterAtaDevice (This
, Controller
, ChildHandleBuffer
[Index
]);
750 if (EFI_ERROR (Status
)) {
751 AllChildrenStopped
= FALSE
;
755 if (!AllChildrenStopped
) {
756 return EFI_DEVICE_ERROR
;
764 Reset the Block Device.
766 @param This Indicates a pointer to the calling context.
767 @param ExtendedVerification Driver may perform diagnostics on reset.
769 @retval EFI_SUCCESS The device was reset.
770 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
777 IN EFI_BLOCK_IO_PROTOCOL
*This
,
778 IN BOOLEAN ExtendedVerification
782 ATA_DEVICE
*AtaDevice
;
785 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
787 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
789 Status
= ResetAtaDevice (AtaDevice
);
791 if (EFI_ERROR (Status
)) {
792 Status
= EFI_DEVICE_ERROR
;
795 gBS
->RestoreTPL (OldTpl
);
801 Read/Write BufferSize bytes from Lba from/into Buffer.
803 @param This Indicates a pointer to the calling context.
804 @param MediaId The media ID that the read/write request is for.
805 @param Lba The starting logical block address to be read/written. The caller is
806 responsible for reading/writing to only legitimate locations.
807 @param BufferSize Size of Buffer, must be a multiple of device block size.
808 @param Buffer A pointer to the destination/source buffer for the data.
809 @param IsWrite Indicates whether it is a write operation.
811 @retval EFI_SUCCESS The data was read/written correctly to the device.
812 @retval EFI_WRITE_PROTECTED The device can not be read/written to.
813 @retval EFI_DEVICE_ERROR The device reported an error while performing the read/write.
814 @retval EFI_NO_MEDIA There is no media in the device.
815 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
816 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
817 @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid,
818 or the buffer is not on proper alignment.
823 IN EFI_BLOCK_IO_PROTOCOL
*This
,
831 ATA_DEVICE
*AtaDevice
;
834 EFI_BLOCK_IO_MEDIA
*Media
;
836 UINTN NumberOfBlocks
;
842 if (Buffer
== NULL
) {
843 return EFI_INVALID_PARAMETER
;
846 if (BufferSize
== 0) {
851 if (MediaId
!= Media
->MediaId
) {
852 return EFI_MEDIA_CHANGED
;
855 BlockSize
= Media
->BlockSize
;
856 if ((BufferSize
% BlockSize
) != 0) {
857 return EFI_BAD_BUFFER_SIZE
;
860 NumberOfBlocks
= BufferSize
/ BlockSize
;
861 if ((Lba
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
862 return EFI_INVALID_PARAMETER
;
865 IoAlign
= Media
->IoAlign
;
866 if (IoAlign
> 0 && (((UINTN
) Buffer
& (IoAlign
- 1)) != 0)) {
867 return EFI_INVALID_PARAMETER
;
870 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
872 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
875 // Invoke low level AtaDevice Access Routine.
877 Status
= AccessAtaDevice (AtaDevice
, Buffer
, Lba
, NumberOfBlocks
, IsWrite
);
879 gBS
->RestoreTPL (OldTpl
);
886 Read BufferSize bytes from Lba into Buffer.
888 @param This Indicates a pointer to the calling context.
889 @param MediaId Id of the media, changes every time the media is replaced.
890 @param Lba The starting Logical Block Address to read from
891 @param BufferSize Size of Buffer, must be a multiple of device block size.
892 @param Buffer A pointer to the destination buffer for the data. The caller is
893 responsible for either having implicit or explicit ownership of the buffer.
895 @retval EFI_SUCCESS The data was read correctly from the device.
896 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
897 @retval EFI_NO_MEDIA There is no media in the device.
898 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
899 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
900 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
901 or the buffer is not on proper alignment.
906 AtaBlockIoReadBlocks (
907 IN EFI_BLOCK_IO_PROTOCOL
*This
,
914 return BlockIoReadWrite (This
, MediaId
, Lba
, BufferSize
, Buffer
, FALSE
);
919 Write BufferSize bytes from Lba into Buffer.
921 @param This Indicates a pointer to the calling context.
922 @param MediaId The media ID that the write request is for.
923 @param Lba The starting logical block address to be written. The caller is
924 responsible for writing to only legitimate locations.
925 @param BufferSize Size of Buffer, must be a multiple of device block size.
926 @param Buffer A pointer to the source buffer for the data.
928 @retval EFI_SUCCESS The data was written correctly to the device.
929 @retval EFI_WRITE_PROTECTED The device can not be written to.
930 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
931 @retval EFI_NO_MEDIA There is no media in the device.
932 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
933 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
934 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
935 or the buffer is not on proper alignment.
940 AtaBlockIoWriteBlocks (
941 IN EFI_BLOCK_IO_PROTOCOL
*This
,
948 return BlockIoReadWrite (This
, MediaId
, Lba
, BufferSize
, Buffer
, TRUE
);
953 Flush the Block Device.
955 @param This Indicates a pointer to the calling context.
957 @retval EFI_SUCCESS All outstanding data was written to the device
958 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
959 @retval EFI_NO_MEDIA There is no media in the device.
964 AtaBlockIoFlushBlocks (
965 IN EFI_BLOCK_IO_PROTOCOL
*This
976 Provides inquiry information for the controller type.
978 This function is used by the IDE bus driver to get inquiry data. Data format
979 of Identify data is defined by the Interface GUID.
981 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
982 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
983 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
985 @retval EFI_SUCCESS The command was accepted without any errors.
986 @retval EFI_NOT_FOUND Device does not support this data class
987 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
988 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
994 IN EFI_DISK_INFO_PROTOCOL
*This
,
995 IN OUT VOID
*InquiryData
,
996 IN OUT UINT32
*InquiryDataSize
999 return EFI_NOT_FOUND
;
1004 Provides identify information for the controller type.
1006 This function is used by the IDE bus driver to get identify data. Data format
1007 of Identify data is defined by the Interface GUID.
1009 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
1011 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
1012 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
1015 @retval EFI_SUCCESS The command was accepted without any errors.
1016 @retval EFI_NOT_FOUND Device does not support this data class
1017 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
1018 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
1023 AtaDiskInfoIdentify (
1024 IN EFI_DISK_INFO_PROTOCOL
*This
,
1025 IN OUT VOID
*IdentifyData
,
1026 IN OUT UINT32
*IdentifyDataSize
1030 ATA_DEVICE
*AtaDevice
;
1032 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1034 Status
= EFI_BUFFER_TOO_SMALL
;
1035 if (*IdentifyDataSize
>= sizeof (*AtaDevice
->IdentifyData
)) {
1036 Status
= EFI_SUCCESS
;
1037 CopyMem (IdentifyData
, AtaDevice
->IdentifyData
, sizeof (*AtaDevice
->IdentifyData
));
1039 *IdentifyDataSize
= sizeof (*AtaDevice
->IdentifyData
);
1046 Provides sense data information for the controller type.
1048 This function is used by the IDE bus driver to get sense data.
1049 Data format of Sense data is defined by the Interface GUID.
1051 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1052 @param[in, out] SenseData Pointer to the SenseData.
1053 @param[in, out] SenseDataSize Size of SenseData in bytes.
1054 @param[out] SenseDataNumber Pointer to the value for the sense data size.
1056 @retval EFI_SUCCESS The command was accepted without any errors.
1057 @retval EFI_NOT_FOUND Device does not support this data class.
1058 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
1059 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
1064 AtaDiskInfoSenseData (
1065 IN EFI_DISK_INFO_PROTOCOL
*This
,
1066 IN OUT VOID
*SenseData
,
1067 IN OUT UINT32
*SenseDataSize
,
1068 OUT UINT8
*SenseDataNumber
1071 return EFI_NOT_FOUND
;
1076 This function is used by the IDE bus driver to get controller information.
1078 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1079 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
1080 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
1082 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
1083 @retval EFI_UNSUPPORTED This is not an IDE device.
1088 AtaDiskInfoWhichIde (
1089 IN EFI_DISK_INFO_PROTOCOL
*This
,
1090 OUT UINT32
*IdeChannel
,
1091 OUT UINT32
*IdeDevice
1094 ATA_DEVICE
*AtaDevice
;
1096 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1097 *IdeChannel
= AtaDevice
->Port
;
1098 *IdeDevice
= AtaDevice
->PortMultiplierPort
;
1105 The user Entry Point for module AtaBus. The user code starts with this function.
1107 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1108 @param[in] SystemTable A pointer to the EFI System Table.
1110 @retval EFI_SUCCESS The entry point is executed successfully.
1111 @retval other Some error occurs when executing this entry point.
1117 IN EFI_HANDLE ImageHandle
,
1118 IN EFI_SYSTEM_TABLE
*SystemTable
1124 // Install driver model protocol(s).
1126 Status
= EfiLibInstallDriverBindingComponentName2 (
1129 &gAtaBusDriverBinding
,
1131 &gAtaBusComponentName
,
1132 &gAtaBusComponentName2
1134 ASSERT_EFI_ERROR (Status
);