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
) {
196 Status
= EFI_OUT_OF_RESOURCES
;
201 RemainingDevicePath
= DevicePath
;
202 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &DeviceHandle
);
203 if (!EFI_ERROR (Status
) && (DeviceHandle
!= NULL
) && IsDevicePathEnd(RemainingDevicePath
)) {
204 Status
= EFI_ALREADY_STARTED
;
205 FreePool (DevicePath
);
210 // Allocate ATA device from the template.
212 AtaDevice
= AllocateCopyPool (sizeof (gAtaDeviceTemplate
), &gAtaDeviceTemplate
);
213 if (AtaDevice
== NULL
) {
214 Status
= EFI_OUT_OF_RESOURCES
;
219 // Initializes ATA device structures and allocates the required buffer.
221 AtaDevice
->BlockIo
.Media
= &AtaDevice
->BlockMedia
;
222 AtaDevice
->AtaBusDriverData
= AtaBusDriverData
;
223 AtaDevice
->DevicePath
= DevicePath
;
224 AtaDevice
->Port
= Port
;
225 AtaDevice
->PortMultiplierPort
= PortMultiplierPort
;
226 AtaDevice
->Asb
= AllocateAlignedBuffer (AtaDevice
, sizeof (*AtaDevice
->Asb
));
227 if (AtaDevice
->Asb
== NULL
) {
228 Status
= EFI_OUT_OF_RESOURCES
;
231 AtaDevice
->IdentifyData
= AllocateAlignedBuffer (AtaDevice
, sizeof (*AtaDevice
->IdentifyData
));
232 if (AtaDevice
->IdentifyData
== NULL
) {
233 Status
= EFI_OUT_OF_RESOURCES
;
238 // Try to identify the ATA device via the ATA pass through command.
240 Status
= DiscoverAtaDevice (AtaDevice
);
241 if (EFI_ERROR (Status
)) {
246 // Build controller name for Component Name (2) protocol.
248 Status
= AddUnicodeString2 (
250 gAtaBusComponentName
.SupportedLanguages
,
251 &AtaDevice
->ControllerNameTable
,
252 AtaDevice
->ModelName
,
255 if (EFI_ERROR (Status
)) {
259 Status
= AddUnicodeString2 (
261 gAtaBusComponentName2
.SupportedLanguages
,
262 &AtaDevice
->ControllerNameTable
,
263 AtaDevice
->ModelName
,
266 if (EFI_ERROR (Status
)) {
271 // Update to AHCI interface GUID based on device path node. The default one
272 // is IDE interface GUID copied from template.
274 if (NewDevicePathNode
->SubType
== MSG_SATA_DP
) {
275 CopyGuid (&AtaDevice
->DiskInfo
.Interface
, &gEfiDiskInfoAhciInterfaceGuid
);
278 Status
= gBS
->InstallMultipleProtocolInterfaces (
280 &gEfiDevicePathProtocolGuid
,
281 AtaDevice
->DevicePath
,
282 &gEfiBlockIoProtocolGuid
,
284 &gEfiDiskInfoProtocolGuid
,
285 &AtaDevice
->DiskInfo
,
288 if (EFI_ERROR (Status
)) {
293 AtaBusDriverData
->Controller
,
294 &gEfiAtaPassThruProtocolGuid
,
295 (VOID
**) &AtaPassThru
,
296 AtaBusDriverData
->DriverBindingHandle
,
298 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
302 if (NewDevicePathNode
!= NULL
) {
303 FreePool (NewDevicePathNode
);
306 if (EFI_ERROR (Status
) && (AtaDevice
!= NULL
)) {
307 ReleaseAtaResources (AtaDevice
);
308 DEBUG ((DEBUG_ERROR
| DEBUG_INIT
, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port
, PortMultiplierPort
, Status
));
315 Unregisters an ATA device.
317 This function removes the protocols installed on the controller handle and
318 frees the resources allocated for the ATA device.
320 @param This The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.
321 @param Controller The controller handle of the ATA device.
322 @param Handle The child handle.
324 @retval EFI_SUCCESS The ATA device is successfully unregistered.
325 @return Others Some error occurs when unregistering the ATA device.
329 UnregisterAtaDevice (
330 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
331 IN EFI_HANDLE Controller
,
336 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
337 ATA_DEVICE
*AtaDevice
;
338 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
340 Status
= gBS
->OpenProtocol (
342 &gEfiBlockIoProtocolGuid
,
344 This
->DriverBindingHandle
,
346 EFI_OPEN_PROTOCOL_GET_PROTOCOL
348 if (EFI_ERROR (Status
)) {
352 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (BlockIo
);
355 // Close the child handle
359 &gEfiAtaPassThruProtocolGuid
,
360 This
->DriverBindingHandle
,
364 Status
= gBS
->UninstallMultipleProtocolInterfaces (
366 &gEfiDevicePathProtocolGuid
,
367 AtaDevice
->DevicePath
,
368 &gEfiBlockIoProtocolGuid
,
370 &gEfiDiskInfoProtocolGuid
,
371 &AtaDevice
->DiskInfo
,
375 if (EFI_ERROR (Status
)) {
378 &gEfiAtaPassThruProtocolGuid
,
379 (VOID
**) &AtaPassThru
,
380 This
->DriverBindingHandle
,
382 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
387 ReleaseAtaResources (AtaDevice
);
395 Tests to see if this driver supports a given controller. If a child device is provided,
396 it further tests to see if this driver supports creating a handle for the specified child device.
398 This function checks to see if the driver specified by This supports the device specified by
399 ControllerHandle. Drivers will typically use the device path attached to
400 ControllerHandle and/or the services from the bus I/O abstraction attached to
401 ControllerHandle to determine if the driver supports ControllerHandle. This function
402 may be called many times during platform initialization. In order to reduce boot times, the tests
403 performed by this function must be very small, and take as little time as possible to execute. This
404 function must not change the state of any hardware devices, and this function must be aware that the
405 device specified by ControllerHandle may already be managed by the same driver or a
406 different driver. This function must match its calls to AllocatePages() with FreePages(),
407 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
408 Since ControllerHandle may have been previously started by the same driver, if a protocol is
409 already in the opened state, then it must not be closed with CloseProtocol(). This is required
410 to guarantee the state of ControllerHandle is not modified by this function.
412 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
413 @param[in] ControllerHandle The handle of the controller to test. This handle
414 must support a protocol interface that supplies
415 an I/O abstraction to the driver.
416 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
417 parameter is ignored by device drivers, and is optional for bus
418 drivers. For bus drivers, if this parameter is not NULL, then
419 the bus driver must determine if the bus controller specified
420 by ControllerHandle and the child controller specified
421 by RemainingDevicePath are both supported by this
424 @retval EFI_SUCCESS The device specified by ControllerHandle and
425 RemainingDevicePath is supported by the driver specified by This.
426 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
427 RemainingDevicePath is already being managed by the driver
429 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
430 RemainingDevicePath is already being managed by a different
431 driver or an application that requires exclusive access.
432 Currently not implemented.
433 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
434 RemainingDevicePath is not supported by the driver specified by This.
438 AtaBusDriverBindingSupported (
439 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
440 IN EFI_HANDLE Controller
,
441 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
445 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
446 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
448 UINT16 PortMultiplierPort
;
451 // Test EFI_ATA_PASS_THRU_PROTOCOL on controller handle.
453 Status
= gBS
->OpenProtocol (
455 &gEfiAtaPassThruProtocolGuid
,
456 (VOID
**) &AtaPassThru
,
457 This
->DriverBindingHandle
,
459 EFI_OPEN_PROTOCOL_BY_DRIVER
462 if (Status
== EFI_ALREADY_STARTED
) {
466 if (EFI_ERROR (Status
)) {
471 // Test RemainingDevicePath is valid or not.
473 if ((RemainingDevicePath
!= NULL
) && !IsDevicePathEnd (RemainingDevicePath
)) {
474 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
475 if (EFI_ERROR (Status
)) {
481 // Close the I/O Abstraction(s) used to perform the supported test
485 &gEfiAtaPassThruProtocolGuid
,
486 This
->DriverBindingHandle
,
491 // Open the EFI Device Path protocol needed to perform the supported test
493 Status
= gBS
->OpenProtocol (
495 &gEfiDevicePathProtocolGuid
,
496 (VOID
**) &ParentDevicePath
,
497 This
->DriverBindingHandle
,
499 EFI_OPEN_PROTOCOL_GET_PROTOCOL
506 Starts a device controller or a bus controller.
508 The Start() function is designed to be invoked from the EFI boot service ConnectController().
509 As a result, much of the error checking on the parameters to Start() has been moved into this
510 common boot service. It is legal to call Start() from other locations,
511 but the following calling restrictions must be followed or the system behavior will not be deterministic.
512 1. ControllerHandle must be a valid EFI_HANDLE.
513 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
514 EFI_DEVICE_PATH_PROTOCOL.
515 3. Prior to calling Start(), the Supported() function for the driver specified by This must
516 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
518 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
519 @param[in] ControllerHandle The handle of the controller to start. This handle
520 must support a protocol interface that supplies
521 an I/O abstraction to the driver.
522 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
523 parameter is ignored by device drivers, and is optional for bus
524 drivers. For a bus driver, if this parameter is NULL, then handles
525 for all the children of Controller are created by this driver.
526 If this parameter is not NULL and the first Device Path Node is
527 not the End of Device Path Node, then only the handle for the
528 child device specified by the first Device Path Node of
529 RemainingDevicePath is created by this driver.
530 If the first Device Path Node of RemainingDevicePath is
531 the End of Device Path Node, no child handle is created by this
534 @retval EFI_SUCCESS The device was started.
535 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
536 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
537 @retval Others The driver failded to start the device.
542 AtaBusDriverBindingStart (
543 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
544 IN EFI_HANDLE Controller
,
545 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
549 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
550 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
551 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
553 UINT16 PortMultiplierPort
;
555 AtaBusDriverData
= NULL
;
557 Status
= gBS
->OpenProtocol (
559 &gEfiDevicePathProtocolGuid
,
560 (VOID
**) &ParentDevicePath
,
561 This
->DriverBindingHandle
,
563 EFI_OPEN_PROTOCOL_GET_PROTOCOL
565 if (EFI_ERROR (Status
)) {
569 Status
= gBS
->OpenProtocol (
571 &gEfiAtaPassThruProtocolGuid
,
572 (VOID
**) &AtaPassThru
,
573 This
->DriverBindingHandle
,
575 EFI_OPEN_PROTOCOL_BY_DRIVER
577 if ((EFI_ERROR (Status
)) && (Status
!= EFI_ALREADY_STARTED
)) {
582 // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.
584 if (Status
!= EFI_ALREADY_STARTED
) {
585 AtaBusDriverData
= AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA
));
586 if (AtaBusDriverData
== NULL
) {
587 Status
= EFI_OUT_OF_RESOURCES
;
591 AtaBusDriverData
->AtaPassThru
= AtaPassThru
;
592 AtaBusDriverData
->Controller
= Controller
;
593 AtaBusDriverData
->ParentDevicePath
= ParentDevicePath
;
594 AtaBusDriverData
->DriverBindingHandle
= This
->DriverBindingHandle
;
596 Status
= gBS
->InstallMultipleProtocolInterfaces (
602 if (EFI_ERROR (Status
)) {
607 Status
= gBS
->OpenProtocol (
610 (VOID
**) &AtaBusDriverData
,
611 This
->DriverBindingHandle
,
613 EFI_OPEN_PROTOCOL_GET_PROTOCOL
615 if (EFI_ERROR (Status
)) {
616 AtaBusDriverData
= NULL
;
621 if (RemainingDevicePath
== NULL
) {
624 Status
= AtaPassThru
->GetNextPort (AtaPassThru
, &Port
);
625 if (EFI_ERROR (Status
)) {
627 // We cannot find more legal port then we are done.
632 PortMultiplierPort
= 0xFFFF;
634 Status
= AtaPassThru
->GetNextDevice (AtaPassThru
, Port
, &PortMultiplierPort
);
635 if (EFI_ERROR (Status
)) {
637 // We cannot find more legal port multiplier port number for ATA device
638 // on the port, then we are done.
642 RegisterAtaDevice (AtaBusDriverData
, Port
, PortMultiplierPort
);
645 Status
= EFI_SUCCESS
;
646 } else if (!IsDevicePathEnd (RemainingDevicePath
)) {
647 Status
= AtaPassThru
->GetDevice (AtaPassThru
, RemainingDevicePath
, &Port
, &PortMultiplierPort
);
648 if (!EFI_ERROR (Status
)) {
649 Status
= RegisterAtaDevice (AtaBusDriverData
,Port
, PortMultiplierPort
);
657 if (AtaBusDriverData
!= NULL
) {
658 gBS
->UninstallMultipleProtocolInterfaces (
664 FreePool (AtaBusDriverData
);
669 &gEfiAtaPassThruProtocolGuid
,
670 This
->DriverBindingHandle
,
680 Stops a device controller or a bus controller.
682 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
683 As a result, much of the error checking on the parameters to Stop() has been moved
684 into this common boot service. It is legal to call Stop() from other locations,
685 but the following calling restrictions must be followed or the system behavior will not be deterministic.
686 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
687 same driver's Start() function.
688 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
689 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
690 Start() function, and the Start() function must have called OpenProtocol() on
691 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
693 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
694 @param[in] ControllerHandle A handle to the device being stopped. The handle must
695 support a bus specific I/O protocol for the driver
696 to use to stop the device.
697 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
698 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
699 if NumberOfChildren is 0.
701 @retval EFI_SUCCESS The device was stopped.
702 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
707 AtaBusDriverBindingStop (
708 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
709 IN EFI_HANDLE Controller
,
710 IN UINTN NumberOfChildren
,
711 IN EFI_HANDLE
*ChildHandleBuffer
715 BOOLEAN AllChildrenStopped
;
717 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
719 if (NumberOfChildren
== 0) {
720 Status
= gBS
->OpenProtocol (
723 (VOID
**) &AtaBusDriverData
,
724 This
->DriverBindingHandle
,
726 EFI_OPEN_PROTOCOL_GET_PROTOCOL
728 if (!EFI_ERROR (Status
)) {
729 gBS
->UninstallMultipleProtocolInterfaces (
735 FreePool (AtaBusDriverData
);
740 &gEfiAtaPassThruProtocolGuid
,
741 This
->DriverBindingHandle
,
748 AllChildrenStopped
= TRUE
;
750 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
752 Status
= UnregisterAtaDevice (This
, Controller
, ChildHandleBuffer
[Index
]);
753 if (EFI_ERROR (Status
)) {
754 AllChildrenStopped
= FALSE
;
758 if (!AllChildrenStopped
) {
759 return EFI_DEVICE_ERROR
;
767 Reset the Block Device.
769 @param This Indicates a pointer to the calling context.
770 @param ExtendedVerification Driver may perform diagnostics on reset.
772 @retval EFI_SUCCESS The device was reset.
773 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
780 IN EFI_BLOCK_IO_PROTOCOL
*This
,
781 IN BOOLEAN ExtendedVerification
785 ATA_DEVICE
*AtaDevice
;
788 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
790 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
792 Status
= ResetAtaDevice (AtaDevice
);
794 if (EFI_ERROR (Status
)) {
795 Status
= EFI_DEVICE_ERROR
;
798 gBS
->RestoreTPL (OldTpl
);
804 Read/Write BufferSize bytes from Lba from/into Buffer.
806 @param This Indicates a pointer to the calling context.
807 @param MediaId The media ID that the read/write request is for.
808 @param Lba The starting logical block address to be read/written. The caller is
809 responsible for reading/writing to only legitimate locations.
810 @param BufferSize Size of Buffer, must be a multiple of device block size.
811 @param Buffer A pointer to the destination/source buffer for the data.
812 @param IsWrite Indicates whether it is a write operation.
814 @retval EFI_SUCCESS The data was read/written correctly to the device.
815 @retval EFI_WRITE_PROTECTED The device can not be read/written to.
816 @retval EFI_DEVICE_ERROR The device reported an error while performing the read/write.
817 @retval EFI_NO_MEDIA There is no media in the device.
818 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
819 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
820 @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid,
821 or the buffer is not on proper alignment.
826 IN EFI_BLOCK_IO_PROTOCOL
*This
,
834 ATA_DEVICE
*AtaDevice
;
837 EFI_BLOCK_IO_MEDIA
*Media
;
839 UINTN NumberOfBlocks
;
845 if (Buffer
== NULL
) {
846 return EFI_INVALID_PARAMETER
;
849 if (BufferSize
== 0) {
854 if (MediaId
!= Media
->MediaId
) {
855 return EFI_MEDIA_CHANGED
;
858 BlockSize
= Media
->BlockSize
;
859 if ((BufferSize
% BlockSize
) != 0) {
860 return EFI_BAD_BUFFER_SIZE
;
863 NumberOfBlocks
= BufferSize
/ BlockSize
;
864 if ((Lba
+ NumberOfBlocks
- 1) > Media
->LastBlock
) {
865 return EFI_INVALID_PARAMETER
;
868 IoAlign
= Media
->IoAlign
;
869 if (IoAlign
> 0 && (((UINTN
) Buffer
& (IoAlign
- 1)) != 0)) {
870 return EFI_INVALID_PARAMETER
;
873 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
875 AtaDevice
= ATA_DEVICE_FROM_BLOCK_IO (This
);
878 // Invoke low level AtaDevice Access Routine.
880 Status
= AccessAtaDevice (AtaDevice
, Buffer
, Lba
, NumberOfBlocks
, IsWrite
);
882 gBS
->RestoreTPL (OldTpl
);
889 Read BufferSize bytes from Lba into Buffer.
891 @param This Indicates a pointer to the calling context.
892 @param MediaId Id of the media, changes every time the media is replaced.
893 @param Lba The starting Logical Block Address to read from
894 @param BufferSize Size of Buffer, must be a multiple of device block size.
895 @param Buffer A pointer to the destination buffer for the data. The caller is
896 responsible for either having implicit or explicit ownership of the buffer.
898 @retval EFI_SUCCESS The data was read correctly from the device.
899 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
900 @retval EFI_NO_MEDIA There is no media in the device.
901 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
902 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
903 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
904 or the buffer is not on proper alignment.
909 AtaBlockIoReadBlocks (
910 IN EFI_BLOCK_IO_PROTOCOL
*This
,
917 return BlockIoReadWrite (This
, MediaId
, Lba
, BufferSize
, Buffer
, FALSE
);
922 Write BufferSize bytes from Lba into Buffer.
924 @param This Indicates a pointer to the calling context.
925 @param MediaId The media ID that the write request is for.
926 @param Lba The starting logical block address to be written. The caller is
927 responsible for writing to only legitimate locations.
928 @param BufferSize Size of Buffer, must be a multiple of device block size.
929 @param Buffer A pointer to the source buffer for the data.
931 @retval EFI_SUCCESS The data was written correctly to the device.
932 @retval EFI_WRITE_PROTECTED The device can not be written to.
933 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
934 @retval EFI_NO_MEDIA There is no media in the device.
935 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
936 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
937 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
938 or the buffer is not on proper alignment.
943 AtaBlockIoWriteBlocks (
944 IN EFI_BLOCK_IO_PROTOCOL
*This
,
951 return BlockIoReadWrite (This
, MediaId
, Lba
, BufferSize
, Buffer
, TRUE
);
956 Flush the Block Device.
958 @param This Indicates a pointer to the calling context.
960 @retval EFI_SUCCESS All outstanding data was written to the device
961 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
962 @retval EFI_NO_MEDIA There is no media in the device.
967 AtaBlockIoFlushBlocks (
968 IN EFI_BLOCK_IO_PROTOCOL
*This
979 Provides inquiry information for the controller type.
981 This function is used by the IDE bus driver to get inquiry data. Data format
982 of Identify data is defined by the Interface GUID.
984 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
985 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
986 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
988 @retval EFI_SUCCESS The command was accepted without any errors.
989 @retval EFI_NOT_FOUND Device does not support this data class
990 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
991 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
997 IN EFI_DISK_INFO_PROTOCOL
*This
,
998 IN OUT VOID
*InquiryData
,
999 IN OUT UINT32
*InquiryDataSize
1002 return EFI_NOT_FOUND
;
1007 Provides identify information for the controller type.
1009 This function is used by the IDE bus driver to get identify data. Data format
1010 of Identify data is defined by the Interface GUID.
1012 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
1014 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
1015 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
1018 @retval EFI_SUCCESS The command was accepted without any errors.
1019 @retval EFI_NOT_FOUND Device does not support this data class
1020 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
1021 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
1026 AtaDiskInfoIdentify (
1027 IN EFI_DISK_INFO_PROTOCOL
*This
,
1028 IN OUT VOID
*IdentifyData
,
1029 IN OUT UINT32
*IdentifyDataSize
1033 ATA_DEVICE
*AtaDevice
;
1035 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1037 Status
= EFI_BUFFER_TOO_SMALL
;
1038 if (*IdentifyDataSize
>= sizeof (*AtaDevice
->IdentifyData
)) {
1039 Status
= EFI_SUCCESS
;
1040 CopyMem (IdentifyData
, AtaDevice
->IdentifyData
, sizeof (*AtaDevice
->IdentifyData
));
1042 *IdentifyDataSize
= sizeof (*AtaDevice
->IdentifyData
);
1049 Provides sense data information for the controller type.
1051 This function is used by the IDE bus driver to get sense data.
1052 Data format of Sense data is defined by the Interface GUID.
1054 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1055 @param[in, out] SenseData Pointer to the SenseData.
1056 @param[in, out] SenseDataSize Size of SenseData in bytes.
1057 @param[out] SenseDataNumber Pointer to the value for the sense data size.
1059 @retval EFI_SUCCESS The command was accepted without any errors.
1060 @retval EFI_NOT_FOUND Device does not support this data class.
1061 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
1062 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
1067 AtaDiskInfoSenseData (
1068 IN EFI_DISK_INFO_PROTOCOL
*This
,
1069 IN OUT VOID
*SenseData
,
1070 IN OUT UINT32
*SenseDataSize
,
1071 OUT UINT8
*SenseDataNumber
1074 return EFI_NOT_FOUND
;
1079 This function is used by the IDE bus driver to get controller information.
1081 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1082 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
1083 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
1085 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
1086 @retval EFI_UNSUPPORTED This is not an IDE device.
1091 AtaDiskInfoWhichIde (
1092 IN EFI_DISK_INFO_PROTOCOL
*This
,
1093 OUT UINT32
*IdeChannel
,
1094 OUT UINT32
*IdeDevice
1097 ATA_DEVICE
*AtaDevice
;
1099 AtaDevice
= ATA_DEVICE_FROM_DISK_INFO (This
);
1100 *IdeChannel
= AtaDevice
->Port
;
1101 *IdeDevice
= AtaDevice
->PortMultiplierPort
;
1108 The user Entry Point for module AtaBus. The user code starts with this function.
1110 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1111 @param[in] SystemTable A pointer to the EFI System Table.
1113 @retval EFI_SUCCESS The entry point is executed successfully.
1114 @retval other Some error occurs when executing this entry point.
1120 IN EFI_HANDLE ImageHandle
,
1121 IN EFI_SYSTEM_TABLE
*SystemTable
1127 // Install driver model protocol(s).
1129 Status
= EfiLibInstallDriverBindingComponentName2 (
1132 &gAtaBusDriverBinding
,
1134 &gAtaBusComponentName
,
1135 &gAtaBusComponentName2
1137 ASSERT_EFI_ERROR (Status
);