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, Intel Corporation
8 All rights reserved. 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 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 AtaDevice The ATA child device involved for the operation.
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 AtaDevice The ATA child device involved for the operation.
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
;
177 NewDevicePathNode
= NULL
;
180 // Allocate ATA device from the template.
182 AtaDevice
= AllocateCopyPool (sizeof (gAtaDeviceTemplate
), &gAtaDeviceTemplate
);
183 if (AtaDevice
== NULL
) {
184 return EFI_OUT_OF_RESOURCES
;
188 // Initializes ATA device structures and allocates the required buffer.
190 AtaDevice
->BlockIo
.Media
= &AtaDevice
->BlockMedia
;
191 AtaDevice
->AtaBusDriverData
= AtaBusDriverData
;
192 AtaDevice
->Port
= Port
;
193 AtaDevice
->PortMultiplierPort
= PortMultiplierPort
;
194 AtaDevice
->Asb
= AllocateAlignedBuffer (AtaDevice
, sizeof (*AtaDevice
->Asb
));
195 if (AtaDevice
->Asb
== NULL
) {
196 Status
= EFI_OUT_OF_RESOURCES
;
199 AtaDevice
->IdentifyData
= AllocateAlignedBuffer (AtaDevice
, sizeof (*AtaDevice
->IdentifyData
));
200 if (AtaDevice
->IdentifyData
== NULL
) {
201 Status
= EFI_OUT_OF_RESOURCES
;
206 // Try to identify the ATA device via the ATA pass through command.
208 Status
= DiscoverAtaDevice (AtaDevice
);
209 if (EFI_ERROR (Status
)) {
214 // Build controller name for Component Name (2) protocol.
216 Status
= AddUnicodeString2 (
218 gAtaBusComponentName
.SupportedLanguages
,
219 &AtaDevice
->ControllerNameTable
,
220 AtaDevice
->ModelName
,
223 if (EFI_ERROR (Status
)) {
227 Status
= AddUnicodeString2 (
229 gAtaBusComponentName2
.SupportedLanguages
,
230 &AtaDevice
->ControllerNameTable
,
231 AtaDevice
->ModelName
,
234 if (EFI_ERROR (Status
)) {
241 AtaPassThru
= AtaBusDriverData
->AtaPassThru
;
242 Status
= AtaPassThru
->BuildDevicePath (AtaPassThru
, Port
, PortMultiplierPort
, &NewDevicePathNode
);
243 if (EFI_ERROR (Status
)) {
248 // Update to AHCI interface GUID based on device path node. The default one
249 // is IDE interface GUID copied from template.
251 if (NewDevicePathNode
->SubType
== MSG_SATA_DP
) {
252 CopyGuid (&AtaDevice
->DiskInfo
.Interface
, &gEfiDiskInfoAhciInterfaceGuid
);
255 AtaDevice
->DevicePath
= AppendDevicePathNode (AtaBusDriverData
->ParentDevicePath
, NewDevicePathNode
);
256 if (AtaDevice
->DevicePath
== NULL
) {
260 Status
= gBS
->InstallMultipleProtocolInterfaces (
262 &gEfiDevicePathProtocolGuid
,
263 AtaDevice
->DevicePath
,
264 &gEfiBlockIoProtocolGuid
,
266 &gEfiDiskInfoProtocolGuid
,
267 &AtaDevice
->DiskInfo
,
270 if (EFI_ERROR (Status
)) {
275 AtaBusDriverData
->Controller
,
276 &gEfiAtaPassThruProtocolGuid
,
277 (VOID
**) &AtaPassThru
,
278 AtaBusDriverData
->DriverBindingHandle
,
280 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
284 if (NewDevicePathNode
!= NULL
) {
285 FreePool (NewDevicePathNode
);
288 if (EFI_ERROR (Status
)) {
289 ReleaseAtaResources (AtaDevice
);
290 DEBUG ((DEBUG_ERROR
| DEBUG_INIT
, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port
, PortMultiplierPort
, Status
));
297 Unregisters an ATA device.
299 This function removes the protocols installed on the controller handle and
300 frees the resources allocated for the ATA device.
302 @param AtaDevice The ATA child device involved for the operation.
303 @param Controller The controller handle of the ATA device.
304 @param Handle The child handle.
306 @retval EFI_SUCCESS The ATA device is successfully unregistered.
307 @return Others Some error occurs when unregistering the ATA device.
311 UnregisterAtaDevice (
312 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
313 IN EFI_HANDLE Controller
,
318 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
319 ATA_DEVICE
*AtaDevice
;
320 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
322 Status
= gBS
->OpenProtocol (
324 &gEfiBlockIoProtocolGuid
,
326 This
->DriverBindingHandle
,
328 EFI_OPEN_PROTOCOL_GET_PROTOCOL
330 if (EFI_ERROR (Status
)) {
334 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (BlockIo
);
337 // Close the child handle
341 &gEfiAtaPassThruProtocolGuid
,
342 This
->DriverBindingHandle
,
346 Status
= gBS
->UninstallMultipleProtocolInterfaces (
348 &gEfiDevicePathProtocolGuid
,
349 AtaDevice
->DevicePath
,
350 &gEfiBlockIoProtocolGuid
,
352 &gEfiDiskInfoProtocolGuid
,
353 &AtaDevice
->DiskInfo
,
357 if (EFI_ERROR (Status
)) {
360 &gEfiAtaPassThruProtocolGuid
,
361 (VOID
**) &AtaPassThru
,
362 This
->DriverBindingHandle
,
364 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
369 ReleaseAtaResources (AtaDevice
);
377 Tests to see if this driver supports a given controller. If a child device is provided,
378 it further tests to see if this driver supports creating a handle for the specified child device.
380 This function checks to see if the driver specified by This supports the device specified by
381 ControllerHandle. Drivers will typically use the device path attached to
382 ControllerHandle and/or the services from the bus I/O abstraction attached to
383 ControllerHandle to determine if the driver supports ControllerHandle. This function
384 may be called many times during platform initialization. In order to reduce boot times, the tests
385 performed by this function must be very small, and take as little time as possible to execute. This
386 function must not change the state of any hardware devices, and this function must be aware that the
387 device specified by ControllerHandle may already be managed by the same driver or a
388 different driver. This function must match its calls to AllocatePages() with FreePages(),
389 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
390 Since ControllerHandle may have been previously started by the same driver, if a protocol is
391 already in the opened state, then it must not be closed with CloseProtocol(). This is required
392 to guarantee the state of ControllerHandle is not modified by this function.
394 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
395 @param[in] ControllerHandle The handle of the controller to test. This handle
396 must support a protocol interface that supplies
397 an I/O abstraction to the driver.
398 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
399 parameter is ignored by device drivers, and is optional for bus
400 drivers. For bus drivers, if this parameter is not NULL, then
401 the bus driver must determine if the bus controller specified
402 by ControllerHandle and the child controller specified
403 by RemainingDevicePath are both supported by this
406 @retval EFI_SUCCESS The device specified by ControllerHandle and
407 RemainingDevicePath is supported by the driver specified by This.
408 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
409 RemainingDevicePath is already being managed by the driver
411 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
412 RemainingDevicePath is already being managed by a different
413 driver or an application that requires exclusive access.
414 Currently not implemented.
415 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
416 RemainingDevicePath is not supported by the driver specified by This.
420 AtaBusDriverBindingSupported (
421 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
422 IN EFI_HANDLE Controller
,
423 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
427 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
428 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
430 UINT16 PortMultiplierPort
;
433 // Test EFI_ATA_PASS_THRU_PROTOCOL on controller handle.
435 Status
= gBS
->OpenProtocol (
437 &gEfiAtaPassThruProtocolGuid
,
438 (VOID
**) &AtaPassThru
,
439 This
->DriverBindingHandle
,
441 EFI_OPEN_PROTOCOL_BY_DRIVER
444 if (Status
== EFI_ALREADY_STARTED
) {
448 if (EFI_ERROR (Status
)) {
453 // Test RemainingDevicePath is valid or not.
455 if ((RemainingDevicePath
!= NULL
) && !IsDevicePathEnd (RemainingDevicePath
)) {
456 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
457 if (EFI_ERROR (Status
)) {
463 // Close the I/O Abstraction(s) used to perform the supported test
467 &gEfiAtaPassThruProtocolGuid
,
468 This
->DriverBindingHandle
,
473 // Open the EFI Device Path protocol needed to perform the supported test
475 Status
= gBS
->OpenProtocol (
477 &gEfiDevicePathProtocolGuid
,
478 (VOID
**) &ParentDevicePath
,
479 This
->DriverBindingHandle
,
481 EFI_OPEN_PROTOCOL_GET_PROTOCOL
488 Starts a device controller or a bus controller.
490 The Start() function is designed to be invoked from the EFI boot service ConnectController().
491 As a result, much of the error checking on the parameters to Start() has been moved into this
492 common boot service. It is legal to call Start() from other locations,
493 but the following calling restrictions must be followed or the system behavior will not be deterministic.
494 1. ControllerHandle must be a valid EFI_HANDLE.
495 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
496 EFI_DEVICE_PATH_PROTOCOL.
497 3. Prior to calling Start(), the Supported() function for the driver specified by This must
498 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
500 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
501 @param[in] ControllerHandle The handle of the controller to start. This handle
502 must support a protocol interface that supplies
503 an I/O abstraction to the driver.
504 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
505 parameter is ignored by device drivers, and is optional for bus
506 drivers. For a bus driver, if this parameter is NULL, then handles
507 for all the children of Controller are created by this driver.
508 If this parameter is not NULL and the first Device Path Node is
509 not the End of Device Path Node, then only the handle for the
510 child device specified by the first Device Path Node of
511 RemainingDevicePath is created by this driver.
512 If the first Device Path Node of RemainingDevicePath is
513 the End of Device Path Node, no child handle is created by this
516 @retval EFI_SUCCESS The device was started.
517 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
518 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
519 @retval Others The driver failded to start the device.
524 AtaBusDriverBindingStart (
525 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
526 IN EFI_HANDLE Controller
,
527 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
531 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
532 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
533 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
535 UINT16 PortMultiplierPort
;
537 AtaBusDriverData
= NULL
;
539 Status
= gBS
->OpenProtocol (
541 &gEfiDevicePathProtocolGuid
,
542 (VOID
**) &ParentDevicePath
,
543 This
->DriverBindingHandle
,
545 EFI_OPEN_PROTOCOL_GET_PROTOCOL
547 if (EFI_ERROR (Status
)) {
551 Status
= gBS
->OpenProtocol (
553 &gEfiAtaPassThruProtocolGuid
,
554 (VOID
**) &AtaPassThru
,
555 This
->DriverBindingHandle
,
557 EFI_OPEN_PROTOCOL_BY_DRIVER
559 if ((EFI_ERROR (Status
)) && (Status
!= EFI_ALREADY_STARTED
)) {
564 // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.
566 if (Status
!= EFI_ALREADY_STARTED
) {
567 AtaBusDriverData
= AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA
));
568 if (AtaBusDriverData
== NULL
) {
569 Status
= EFI_OUT_OF_RESOURCES
;
573 AtaBusDriverData
->AtaPassThru
= AtaPassThru
;
574 AtaBusDriverData
->Controller
= Controller
;
575 AtaBusDriverData
->ParentDevicePath
= ParentDevicePath
;
576 AtaBusDriverData
->DriverBindingHandle
= This
->DriverBindingHandle
;
578 Status
= gBS
->InstallMultipleProtocolInterfaces (
584 if (EFI_ERROR (Status
)) {
589 Status
= gBS
->OpenProtocol (
592 (VOID
**) &AtaBusDriverData
,
593 This
->DriverBindingHandle
,
595 EFI_OPEN_PROTOCOL_GET_PROTOCOL
597 if (EFI_ERROR (Status
)) {
598 AtaBusDriverData
= NULL
;
603 if (RemainingDevicePath
== NULL
) {
606 Status
= AtaPassThru
->GetNextPort (AtaPassThru
, &Port
);
607 if (EFI_ERROR (Status
)) {
609 // We cannot find more legal port then we are done.
614 PortMultiplierPort
= 0xFFFF;
616 Status
= AtaPassThru
->GetNextDevice (AtaPassThru
, Port
, &PortMultiplierPort
);
617 if (EFI_ERROR (Status
)) {
619 // We cannot find more legal port multiplier port number for ATA device
620 // on the port, then we are done.
624 RegisterAtaDevice (AtaBusDriverData
, Port
, PortMultiplierPort
);
627 Status
= EFI_SUCCESS
;
628 } else if (!IsDevicePathEnd (RemainingDevicePath
)) {
629 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
630 if (!EFI_ERROR (Status
)) {
631 Status
= RegisterAtaDevice (AtaBusDriverData
,Port
, PortMultiplierPort
);
639 if (AtaBusDriverData
!= NULL
) {
640 gBS
->UninstallMultipleProtocolInterfaces (
646 FreePool (AtaBusDriverData
);
651 &gEfiAtaPassThruProtocolGuid
,
652 This
->DriverBindingHandle
,
662 Stops a device controller or a bus controller.
664 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
665 As a result, much of the error checking on the parameters to Stop() has been moved
666 into this common boot service. It is legal to call Stop() from other locations,
667 but the following calling restrictions must be followed or the system behavior will not be deterministic.
668 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
669 same driver's Start() function.
670 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
671 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
672 Start() function, and the Start() function must have called OpenProtocol() on
673 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
675 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
676 @param[in] ControllerHandle A handle to the device being stopped. The handle must
677 support a bus specific I/O protocol for the driver
678 to use to stop the device.
679 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
680 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
681 if NumberOfChildren is 0.
683 @retval EFI_SUCCESS The device was stopped.
684 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
689 AtaBusDriverBindingStop (
690 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
691 IN EFI_HANDLE Controller
,
692 IN UINTN NumberOfChildren
,
693 IN EFI_HANDLE
*ChildHandleBuffer
697 BOOLEAN AllChildrenStopped
;
699 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
701 if (NumberOfChildren
== 0) {
702 Status
= gBS
->OpenProtocol (
705 (VOID
**) &AtaBusDriverData
,
706 This
->DriverBindingHandle
,
708 EFI_OPEN_PROTOCOL_GET_PROTOCOL
710 if (!EFI_ERROR (Status
)) {
711 gBS
->UninstallMultipleProtocolInterfaces (
717 FreePool (AtaBusDriverData
);
722 &gEfiAtaPassThruProtocolGuid
,
723 This
->DriverBindingHandle
,
730 AllChildrenStopped
= TRUE
;
732 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
734 Status
= UnregisterAtaDevice (This
, Controller
, ChildHandleBuffer
[Index
]);
735 if (EFI_ERROR (Status
)) {
736 AllChildrenStopped
= FALSE
;
740 if (!AllChildrenStopped
) {
741 return EFI_DEVICE_ERROR
;
749 Reset the Block Device.
751 @param This Indicates a pointer to the calling context.
752 @param ExtendedVerification Driver may perform diagnostics on reset.
754 @retval EFI_SUCCESS The device was reset.
755 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
762 IN EFI_BLOCK_IO_PROTOCOL
*This
,
763 IN BOOLEAN ExtendedVerification
767 ATA_DEVICE
*AtaDevice
;
770 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
772 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
774 Status
= ResetAtaDevice (AtaDevice
);
776 gBS
->RestoreTPL (OldTpl
);
782 Read/Write BufferSize bytes from Lba from/into Buffer.
784 @param This Indicates a pointer to the calling context.
785 @param MediaId The media ID that the read/write request is for.
786 @param Lba The starting logical block address to be read/written. The caller is
787 responsible for reading/writing to only legitimate locations.
788 @param BufferSize Size of Buffer, must be a multiple of device block size.
789 @param Buffer A pointer to the destination/source buffer for the data.
791 @retval EFI_SUCCESS The data was read/written correctly to the device.
792 @retval EFI_WRITE_PROTECTED The device can not be read/written to.
793 @retval EFI_DEVICE_ERROR The device reported an error while performing the read/write.
794 @retval EFI_NO_MEDIA There is no media in the device.
795 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
796 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
797 @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid,
798 or the buffer is not on proper alignment.
803 IN EFI_BLOCK_IO_PROTOCOL
*This
,
811 ATA_DEVICE
*AtaDevice
;
814 EFI_BLOCK_IO_MEDIA
*Media
;
816 UINTN NumberOfBlocks
;
822 if (Buffer
== NULL
) {
823 return EFI_INVALID_PARAMETER
;
826 if (BufferSize
== 0) {
831 if (MediaId
!= Media
->MediaId
) {
832 return EFI_MEDIA_CHANGED
;
835 BlockSize
= Media
->BlockSize
;
836 if ((BufferSize
% BlockSize
) != 0) {
837 return EFI_BAD_BUFFER_SIZE
;
840 NumberOfBlocks
= BufferSize
/ BlockSize
;
841 if ((Lba
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
842 return EFI_INVALID_PARAMETER
;
845 IoAlign
= Media
->IoAlign
;
846 if (IoAlign
> 0 && (((UINTN
) Buffer
& (IoAlign
- 1)) != 0)) {
847 return EFI_INVALID_PARAMETER
;
850 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
852 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
855 // Invoke low level AtaDevice Access Routine.
857 Status
= AccessAtaDevice (AtaDevice
, Buffer
, Lba
, NumberOfBlocks
, IsWrite
);
859 gBS
->RestoreTPL (OldTpl
);
866 Read BufferSize bytes from Lba into Buffer.
868 @param This Indicates a pointer to the calling context.
869 @param MediaId Id of the media, changes every time the media is replaced.
870 @param Lba The starting Logical Block Address to read from
871 @param BufferSize Size of Buffer, must be a multiple of device block size.
872 @param Buffer A pointer to the destination buffer for the data. The caller is
873 responsible for either having implicit or explicit ownership of the buffer.
875 @retval EFI_SUCCESS The data was read correctly from the device.
876 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
877 @retval EFI_NO_MEDIA There is no media in the device.
878 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
879 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
880 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
881 or the buffer is not on proper alignment.
886 AtaBlockIoReadBlocks (
887 IN EFI_BLOCK_IO_PROTOCOL
*This
,
894 return BlockIoReadWrite (This
, MediaId
, Lba
, BufferSize
, Buffer
, FALSE
);
899 Write BufferSize bytes from Lba into Buffer.
901 @param This Indicates a pointer to the calling context.
902 @param MediaId The media ID that the write request is for.
903 @param Lba The starting logical block address to be written. The caller is
904 responsible for writing to only legitimate locations.
905 @param BufferSize Size of Buffer, must be a multiple of device block size.
906 @param Buffer A pointer to the source buffer for the data.
908 @retval EFI_SUCCESS The data was written correctly to the device.
909 @retval EFI_WRITE_PROTECTED The device can not be written to.
910 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
911 @retval EFI_NO_MEDIA There is no media in the device.
912 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
913 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
914 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
915 or the buffer is not on proper alignment.
920 AtaBlockIoWriteBlocks (
921 IN EFI_BLOCK_IO_PROTOCOL
*This
,
928 return BlockIoReadWrite (This
, MediaId
, Lba
, BufferSize
, Buffer
, TRUE
);
933 Flush the Block Device.
935 @param This Indicates a pointer to the calling context.
937 @retval EFI_SUCCESS All outstanding data was written to the device
938 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
939 @retval EFI_NO_MEDIA There is no media in the device.
944 AtaBlockIoFlushBlocks (
945 IN EFI_BLOCK_IO_PROTOCOL
*This
956 Provides inquiry information for the controller type.
958 This function is used by the IDE bus driver to get inquiry data. Data format
959 of Identify data is defined by the Interface GUID.
961 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
962 @param[in,out] InquiryData Pointer to a buffer for the inquiry data.
963 @param[in,out] InquiryDataSize Pointer to the value for the inquiry data size.
965 @retval EFI_SUCCESS The command was accepted without any errors.
966 @retval EFI_NOT_FOUND Device does not support this data class
967 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
968 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
974 IN EFI_DISK_INFO_PROTOCOL
*This
,
975 IN OUT VOID
*InquiryData
,
976 IN OUT UINT32
*InquiryDataSize
979 return EFI_NOT_FOUND
;
984 Provides identify information for the controller type.
986 This function is used by the IDE bus driver to get identify data. Data format
987 of Identify data is defined by the Interface GUID.
989 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
991 @param[in,out] IdentifyData Pointer to a buffer for the identify data.
992 @param[in,out] IdentifyDataSize Pointer to the value for the identify data
995 @retval EFI_SUCCESS The command was accepted without any errors.
996 @retval EFI_NOT_FOUND Device does not support this data class
997 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
998 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
1003 AtaDiskInfoIdentify (
1004 IN EFI_DISK_INFO_PROTOCOL
*This
,
1005 IN OUT VOID
*IdentifyData
,
1006 IN OUT UINT32
*IdentifyDataSize
1010 ATA_DEVICE
*AtaDevice
;
1012 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1014 Status
= EFI_BUFFER_TOO_SMALL
;
1015 if (*IdentifyDataSize
>= sizeof (*AtaDevice
->IdentifyData
)) {
1016 Status
= EFI_SUCCESS
;
1017 CopyMem (IdentifyData
, AtaDevice
->IdentifyData
, sizeof (*AtaDevice
->IdentifyData
));
1019 *IdentifyDataSize
= sizeof (*AtaDevice
->IdentifyData
);
1026 Provides sense data information for the controller type.
1028 This function is used by the IDE bus driver to get sense data.
1029 Data format of Sense data is defined by the Interface GUID.
1031 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1032 @param[in,out] SenseData Pointer to the SenseData.
1033 @param[in,out] SenseDataSize Size of SenseData in bytes.
1034 @param[out] SenseDataNumber Pointer to the value for the sense data size.
1036 @retval EFI_SUCCESS The command was accepted without any errors.
1037 @retval EFI_NOT_FOUND Device does not support this data class.
1038 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
1039 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
1044 AtaDiskInfoSenseData (
1045 IN EFI_DISK_INFO_PROTOCOL
*This
,
1046 IN OUT VOID
*SenseData
,
1047 IN OUT UINT32
*SenseDataSize
,
1048 OUT UINT8
*SenseDataNumber
1051 return EFI_NOT_FOUND
;
1056 This function is used by the IDE bus driver to get controller information.
1058 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1059 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
1060 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
1062 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
1063 @retval EFI_UNSUPPORTED This is not an IDE device.
1068 AtaDiskInfoWhichIde (
1069 IN EFI_DISK_INFO_PROTOCOL
*This
,
1070 OUT UINT32
*IdeChannel
,
1071 OUT UINT32
*IdeDevice
1074 ATA_DEVICE
*AtaDevice
;
1076 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1077 *IdeChannel
= AtaDevice
->Port
;
1078 *IdeDevice
= AtaDevice
->PortMultiplierPort
;
1085 The user Entry Point for module AtaBus. The user code starts with this function.
1087 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1088 @param[in] SystemTable A pointer to the EFI System Table.
1090 @retval EFI_SUCCESS The entry point is executed successfully.
1091 @retval other Some error occurs when executing this entry point.
1097 IN EFI_HANDLE ImageHandle
,
1098 IN EFI_SYSTEM_TABLE
*SystemTable
1104 // Install driver model protocol(s).
1106 Status
= EfiLibInstallDriverBindingComponentName2 (
1109 &gAtaBusDriverBinding
,
1111 &gAtaBusComponentName
,
1112 &gAtaBusComponentName2
1114 ASSERT_EFI_ERROR (Status
);