2 Master header file for ATA Bus Driver.
4 This file defines common data structures, macro definitions and some module
5 internal function header files.
7 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
17 #include <Protocol/AtaPassThru.h>
18 #include <Protocol/BlockIo.h>
19 #include <Protocol/BlockIo2.h>
20 #include <Protocol/DiskInfo.h>
21 #include <Protocol/DevicePath.h>
22 #include <Protocol/StorageSecurityCommand.h>
24 #include <Library/DebugLib.h>
25 #include <Library/UefiDriverEntryPoint.h>
26 #include <Library/BaseLib.h>
27 #include <Library/UefiLib.h>
28 #include <Library/BaseMemoryLib.h>
29 #include <Library/MemoryAllocationLib.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/DevicePathLib.h>
32 #include <Library/UefiRuntimeServicesTableLib.h>
33 #include <Library/TimerLib.h>
34 #include <Library/ReportStatusCodeLib.h>
36 #include <IndustryStandard/Atapi.h>
39 // Time out value for ATA pass through protocol
41 #define ATA_TIMEOUT EFI_TIMER_PERIOD_SECONDS (3)
44 // Maximum number of times to retry ATA command
46 #define MAX_RETRY_TIMES 3
49 // The maximum total sectors count in 28 bit addressing mode
51 #define MAX_28BIT_ADDRESSING_CAPACITY 0xfffffff
54 // The maximum ATA transaction sector count in 28 bit addressing mode.
56 #define MAX_28BIT_TRANSFER_BLOCK_NUM 0x100
59 // The maximum ATA transaction sector count in 48 bit addressing mode.
61 //#define MAX_48BIT_TRANSFER_BLOCK_NUM 0x10000
64 // BugBug: if the TransferLength is equal with 0x10000 (the 48bit max length),
65 // there is a bug that even the register interrupt bit has been sit, the buffer
66 // seems not ready. Change the Maximum Sector Numbers to 0xFFFF to work round
69 #define MAX_48BIT_TRANSFER_BLOCK_NUM 0xFFFF
72 // The maximum model name in ATA identify data
74 #define MAX_MODEL_NAME_LEN 40
76 #define ATA_TASK_SIGNATURE SIGNATURE_32 ('A', 'T', 'S', 'K')
77 #define ATA_DEVICE_SIGNATURE SIGNATURE_32 ('A', 'B', 'I', 'D')
78 #define ATA_SUB_TASK_SIGNATURE SIGNATURE_32 ('A', 'S', 'T', 'S')
79 #define IS_ALIGNED(addr, size) (((UINTN) (addr) & (size - 1)) == 0)
82 // ATA bus data structure for ATA controller
85 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
86 EFI_HANDLE Controller
;
87 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
88 EFI_HANDLE DriverBindingHandle
;
89 } ATA_BUS_DRIVER_DATA
;
92 // ATA device data structure for each child device
98 EFI_BLOCK_IO_PROTOCOL BlockIo
;
99 EFI_BLOCK_IO2_PROTOCOL BlockIo2
;
100 EFI_BLOCK_IO_MEDIA BlockMedia
;
101 EFI_DISK_INFO_PROTOCOL DiskInfo
;
102 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
103 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL StorageSecurity
;
105 ATA_BUS_DRIVER_DATA
*AtaBusDriverData
;
107 UINT16 PortMultiplierPort
;
110 // Buffer for the execution of ATA pass through protocol
112 EFI_ATA_PASS_THRU_COMMAND_PACKET Packet
;
113 EFI_ATA_COMMAND_BLOCK Acb
;
114 EFI_ATA_STATUS_BLOCK
*Asb
;
120 // Cached data for ATA identify data
122 ATA_IDENTIFY_DATA
*IdentifyData
;
124 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
125 CHAR16 ModelName
[MAX_MODEL_NAME_LEN
+ 1];
127 LIST_ENTRY AtaTaskList
;
128 LIST_ENTRY AtaSubTaskList
;
133 // Sub-Task for the non blocking I/O
137 ATA_DEVICE
*AtaDevice
;
138 EFI_BLOCK_IO2_TOKEN
*Token
;
139 UINTN
*UnsignalledEventCount
;
140 EFI_ATA_PASS_THRU_COMMAND_PACKET Packet
;
141 BOOLEAN
*IsError
;// Indicate whether meeting error during source allocation for new task.
142 LIST_ENTRY TaskEntry
;
143 } ATA_BUS_ASYN_SUB_TASK
;
146 // Task for the non blocking I/O
150 EFI_BLOCK_IO2_TOKEN
*Token
;
151 ATA_DEVICE
*AtaDevice
;
154 UINTN NumberOfBlocks
;
156 LIST_ENTRY TaskEntry
;
159 #define ATA_DEVICE_FROM_BLOCK_IO(a) CR (a, ATA_DEVICE, BlockIo, ATA_DEVICE_SIGNATURE)
160 #define ATA_DEVICE_FROM_BLOCK_IO2(a) CR (a, ATA_DEVICE, BlockIo2, ATA_DEVICE_SIGNATURE)
161 #define ATA_DEVICE_FROM_DISK_INFO(a) CR (a, ATA_DEVICE, DiskInfo, ATA_DEVICE_SIGNATURE)
162 #define ATA_DEVICE_FROM_STORAGE_SECURITY(a) CR (a, ATA_DEVICE, StorageSecurity, ATA_DEVICE_SIGNATURE)
163 #define ATA_ASYN_SUB_TASK_FROM_ENTRY(a) CR (a, ATA_BUS_ASYN_SUB_TASK, TaskEntry, ATA_SUB_TASK_SIGNATURE)
164 #define ATA_ASYN_TASK_FROM_ENTRY(a) CR (a, ATA_BUS_ASYN_TASK, TaskEntry, ATA_TASK_SIGNATURE)
169 extern EFI_DRIVER_BINDING_PROTOCOL gAtaBusDriverBinding
;
170 extern EFI_COMPONENT_NAME_PROTOCOL gAtaBusComponentName
;
171 extern EFI_COMPONENT_NAME2_PROTOCOL gAtaBusComponentName2
;
174 Allocates an aligned buffer for ATA device.
176 This function allocates an aligned buffer for the ATA device to perform
177 ATA pass through operations. The alignment requirement is from ATA pass
180 @param AtaDevice The ATA child device involved for the operation.
181 @param BufferSize The request buffer size.
183 @return A pointer to the aligned buffer or NULL if the allocation fails.
187 AllocateAlignedBuffer (
188 IN ATA_DEVICE
*AtaDevice
,
193 Frees an aligned buffer for ATA device.
195 This function frees an aligned buffer for the ATA device to perform
196 ATA pass through operations.
198 @param Buffer The aligned buffer to be freed.
199 @param BufferSize The request buffer size.
211 @param[in, out] Task Pointer to task to be freed.
217 IN OUT ATA_BUS_ASYN_SUB_TASK
*Task
221 Wrapper for EFI_ATA_PASS_THRU_PROTOCOL.ResetDevice().
223 This function wraps the ResetDevice() invocation for ATA pass through function
226 @param AtaDevice The ATA child device involved for the operation.
228 @return The return status from EFI_ATA_PASS_THRU_PROTOCOL.PassThru().
233 IN ATA_DEVICE
*AtaDevice
238 Discovers whether it is a valid ATA device.
240 This function issues ATA_CMD_IDENTIFY_DRIVE command to the ATA device to identify it.
241 If the command is executed successfully, it then identifies it and initializes
242 the Media information in Block IO protocol interface.
244 @param AtaDevice The ATA child device involved for the operation.
246 @retval EFI_SUCCESS The device is successfully identified and Media information
247 is correctly initialized.
248 @return others Some error occurs when discovering the ATA device.
253 IN OUT ATA_DEVICE
*AtaDevice
257 Read or write a number of blocks from ATA device.
259 This function performs ATA pass through transactions to read/write data from/to
260 ATA device. It may separate the read/write request into several ATA pass through
263 @param[in, out] AtaDevice The ATA child device involved for the operation.
264 @param[in, out] Buffer The pointer to the current transaction buffer.
265 @param[in] StartLba The starting logical block address to be accessed.
266 @param[in] NumberOfBlocks The block number or sector count of the transfer.
267 @param[in] IsWrite Indicates whether it is a write operation.
268 @param[in, out] Token A pointer to the token associated with the transaction.
270 @retval EFI_SUCCESS The data transfer is complete successfully.
271 @return others Some error occurs when transferring data.
276 IN OUT ATA_DEVICE
*AtaDevice
,
277 IN OUT UINT8
*Buffer
,
279 IN UINTN NumberOfBlocks
,
281 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
285 Trust transfer data from/to ATA device.
287 This function performs one ATA pass through transaction to do a trust transfer from/to
288 ATA device. It chooses the appropriate ATA command and protocol to invoke PassThru
289 interface of ATA pass through.
291 @param AtaDevice The ATA child device involved for the operation.
292 @param Buffer The pointer to the current transaction buffer.
293 @param SecurityProtocolId The value of the "Security Protocol" parameter of
294 the security protocol command to be sent.
295 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
296 of the security protocol command to be sent.
297 @param TransferLength The block number or sector count of the transfer.
298 @param IsTrustSend Indicates whether it is a trust send operation or not.
299 @param Timeout The timeout, in 100ns units, to use for the execution
300 of the security protocol command. A Timeout value of 0
301 means that this function will wait indefinitely for the
302 security protocol command to execute. If Timeout is greater
303 than zero, then this function will return EFI_TIMEOUT
304 if the time required to execute the receive data command
305 is greater than Timeout.
306 @param TransferLengthOut A pointer to a buffer to store the size in bytes of the data
307 written to the buffer. Ignore it when IsTrustSend is TRUE.
309 @retval EFI_SUCCESS The data transfer is complete successfully.
310 @return others Some error occurs when transferring data.
315 TrustTransferAtaDevice (
316 IN OUT ATA_DEVICE
*AtaDevice
,
318 IN UINT8 SecurityProtocolId
,
319 IN UINT16 SecurityProtocolSpecificData
,
320 IN UINTN TransferLength
,
321 IN BOOLEAN IsTrustSend
,
323 OUT UINTN
*TransferLengthOut
327 // Protocol interface prototypes
330 Tests to see if this driver supports a given controller. If a child device is provided,
331 it further tests to see if this driver supports creating a handle for the specified child device.
333 This function checks to see if the driver specified by This supports the device specified by
334 ControllerHandle. Drivers will typically use the device path attached to
335 ControllerHandle and/or the services from the bus I/O abstraction attached to
336 ControllerHandle to determine if the driver supports ControllerHandle. This function
337 may be called many times during platform initialization. In order to reduce boot times, the tests
338 performed by this function must be very small, and take as little time as possible to execute. This
339 function must not change the state of any hardware devices, and this function must be aware that the
340 device specified by ControllerHandle may already be managed by the same driver or a
341 different driver. This function must match its calls to AllocatePages() with FreePages(),
342 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
343 Since ControllerHandle may have been previously started by the same driver, if a protocol is
344 already in the opened state, then it must not be closed with CloseProtocol(). This is required
345 to guarantee the state of ControllerHandle is not modified by this function.
347 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
348 @param[in] ControllerHandle The handle of the controller to test. This handle
349 must support a protocol interface that supplies
350 an I/O abstraction to the driver.
351 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
352 parameter is ignored by device drivers, and is optional for bus
353 drivers. For bus drivers, if this parameter is not NULL, then
354 the bus driver must determine if the bus controller specified
355 by ControllerHandle and the child controller specified
356 by RemainingDevicePath are both supported by this
359 @retval EFI_SUCCESS The device specified by ControllerHandle and
360 RemainingDevicePath is supported by the driver specified by This.
361 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
362 RemainingDevicePath is already being managed by the driver
364 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
365 RemainingDevicePath is already being managed by a different
366 driver or an application that requires exclusive access.
367 Currently not implemented.
368 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
369 RemainingDevicePath is not supported by the driver specified by This.
373 AtaBusDriverBindingSupported (
374 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
375 IN EFI_HANDLE Controller
,
376 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
380 Starts a device controller or a bus controller.
382 The Start() function is designed to be invoked from the EFI boot service ConnectController().
383 As a result, much of the error checking on the parameters to Start() has been moved into this
384 common boot service. It is legal to call Start() from other locations,
385 but the following calling restrictions must be followed or the system behavior will not be deterministic.
386 1. ControllerHandle must be a valid EFI_HANDLE.
387 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
388 EFI_DEVICE_PATH_PROTOCOL.
389 3. Prior to calling Start(), the Supported() function for the driver specified by This must
390 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
392 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
393 @param[in] ControllerHandle The handle of the controller to start. This handle
394 must support a protocol interface that supplies
395 an I/O abstraction to the driver.
396 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
397 parameter is ignored by device drivers, and is optional for bus
398 drivers. For a bus driver, if this parameter is NULL, then handles
399 for all the children of Controller are created by this driver.
400 If this parameter is not NULL and the first Device Path Node is
401 not the End of Device Path Node, then only the handle for the
402 child device specified by the first Device Path Node of
403 RemainingDevicePath is created by this driver.
404 If the first Device Path Node of RemainingDevicePath is
405 the End of Device Path Node, no child handle is created by this
408 @retval EFI_SUCCESS The device was started.
409 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
410 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
411 @retval Others The driver failded to start the device.
416 AtaBusDriverBindingStart (
417 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
418 IN EFI_HANDLE Controller
,
419 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
423 Stops a device controller or a bus controller.
425 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
426 As a result, much of the error checking on the parameters to Stop() has been moved
427 into this common boot service. It is legal to call Stop() from other locations,
428 but the following calling restrictions must be followed or the system behavior will not be deterministic.
429 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
430 same driver's Start() function.
431 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
432 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
433 Start() function, and the Start() function must have called OpenProtocol() on
434 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
436 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
437 @param[in] ControllerHandle A handle to the device being stopped. The handle must
438 support a bus specific I/O protocol for the driver
439 to use to stop the device.
440 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
441 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
442 if NumberOfChildren is 0.
444 @retval EFI_SUCCESS The device was stopped.
445 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
450 AtaBusDriverBindingStop (
451 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
452 IN EFI_HANDLE Controller
,
453 IN UINTN NumberOfChildren
,
454 IN EFI_HANDLE
*ChildHandleBuffer
459 Retrieves a Unicode string that is the user readable name of the driver.
461 This function retrieves the user readable name of a driver in the form of a
462 Unicode string. If the driver specified by This has a user readable name in
463 the language specified by Language, then a pointer to the driver name is
464 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
465 by This does not support the language specified by Language,
466 then EFI_UNSUPPORTED is returned.
468 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
469 EFI_COMPONENT_NAME_PROTOCOL instance.
471 @param Language[in] A pointer to a Null-terminated ASCII string
472 array indicating the language. This is the
473 language of the driver name that the caller is
474 requesting, and it must match one of the
475 languages specified in SupportedLanguages. The
476 number of languages supported by a driver is up
477 to the driver writer. Language is specified
478 in RFC 4646 or ISO 639-2 language code format.
480 @param DriverName[out] A pointer to the Unicode string to return.
481 This Unicode string is the name of the
482 driver specified by This in the language
483 specified by Language.
485 @retval EFI_SUCCESS The Unicode string for the Driver specified by
486 This and the language specified by Language was
487 returned in DriverName.
489 @retval EFI_INVALID_PARAMETER Language is NULL.
491 @retval EFI_INVALID_PARAMETER DriverName is NULL.
493 @retval EFI_UNSUPPORTED The driver specified by This does not support
494 the language specified by Language.
499 AtaBusComponentNameGetDriverName (
500 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
502 OUT CHAR16
**DriverName
507 Retrieves a Unicode string that is the user readable name of the controller
508 that is being managed by a driver.
510 This function retrieves the user readable name of the controller specified by
511 ControllerHandle and ChildHandle in the form of a Unicode string. If the
512 driver specified by This has a user readable name in the language specified by
513 Language, then a pointer to the controller name is returned in ControllerName,
514 and EFI_SUCCESS is returned. If the driver specified by This is not currently
515 managing the controller specified by ControllerHandle and ChildHandle,
516 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
517 support the language specified by Language, then EFI_UNSUPPORTED is returned.
519 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
520 EFI_COMPONENT_NAME_PROTOCOL instance.
522 @param ControllerHandle[in] The handle of a controller that the driver
523 specified by This is managing. This handle
524 specifies the controller whose name is to be
527 @param ChildHandle[in] The handle of the child controller to retrieve
528 the name of. This is an optional parameter that
529 may be NULL. It will be NULL for device
530 drivers. It will also be NULL for a bus drivers
531 that wish to retrieve the name of the bus
532 controller. It will not be NULL for a bus
533 driver that wishes to retrieve the name of a
536 @param Language[in] A pointer to a Null-terminated ASCII string
537 array indicating the language. This is the
538 language of the driver name that the caller is
539 requesting, and it must match one of the
540 languages specified in SupportedLanguages. The
541 number of languages supported by a driver is up
542 to the driver writer. Language is specified in
543 RFC 4646 or ISO 639-2 language code format.
545 @param ControllerName[out] A pointer to the Unicode string to return.
546 This Unicode string is the name of the
547 controller specified by ControllerHandle and
548 ChildHandle in the language specified by
549 Language from the point of view of the driver
552 @retval EFI_SUCCESS The Unicode string for the user readable name in
553 the language specified by Language for the
554 driver specified by This was returned in
557 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
559 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
562 @retval EFI_INVALID_PARAMETER Language is NULL.
564 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
566 @retval EFI_UNSUPPORTED The driver specified by This is not currently
567 managing the controller specified by
568 ControllerHandle and ChildHandle.
570 @retval EFI_UNSUPPORTED The driver specified by This does not support
571 the language specified by Language.
576 AtaBusComponentNameGetControllerName (
577 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
578 IN EFI_HANDLE ControllerHandle
,
579 IN EFI_HANDLE ChildHandle OPTIONAL
,
581 OUT CHAR16
**ControllerName
586 Reset the Block Device.
588 @param This Indicates a pointer to the calling context.
589 @param ExtendedVerification Driver may perform diagnostics on reset.
591 @retval EFI_SUCCESS The device was reset.
592 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
599 IN EFI_BLOCK_IO_PROTOCOL
*This
,
600 IN BOOLEAN ExtendedVerification
605 Read BufferSize bytes from Lba into Buffer.
607 @param This Indicates a pointer to the calling context.
608 @param MediaId Id of the media, changes every time the media is replaced.
609 @param Lba The starting Logical Block Address to read from
610 @param BufferSize Size of Buffer, must be a multiple of device block size.
611 @param Buffer A pointer to the destination buffer for the data. The caller is
612 responsible for either having implicit or explicit ownership of the buffer.
614 @retval EFI_SUCCESS The data was read correctly from the device.
615 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
616 @retval EFI_NO_MEDIA There is no media in the device.
617 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
618 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
619 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
620 or the buffer is not on proper alignment.
625 AtaBlockIoReadBlocks (
626 IN EFI_BLOCK_IO_PROTOCOL
*This
,
635 Write BufferSize bytes from Lba into Buffer.
637 @param This Indicates a pointer to the calling context.
638 @param MediaId The media ID that the write request is for.
639 @param Lba The starting logical block address to be written. The caller is
640 responsible for writing to only legitimate locations.
641 @param BufferSize Size of Buffer, must be a multiple of device block size.
642 @param Buffer A pointer to the source buffer for the data.
644 @retval EFI_SUCCESS The data was written correctly to the device.
645 @retval EFI_WRITE_PROTECTED The device can not be written to.
646 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
647 @retval EFI_NO_MEDIA There is no media in the device.
648 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
649 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
650 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
651 or the buffer is not on proper alignment.
656 AtaBlockIoWriteBlocks (
657 IN EFI_BLOCK_IO_PROTOCOL
*This
,
666 Flush the Block Device.
668 @param This Indicates a pointer to the calling context.
670 @retval EFI_SUCCESS All outstanding data was written to the device
671 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
672 @retval EFI_NO_MEDIA There is no media in the device.
677 AtaBlockIoFlushBlocks (
678 IN EFI_BLOCK_IO_PROTOCOL
*This
682 Reset the Block Device throught Block I/O2 protocol.
684 @param[in] This Indicates a pointer to the calling context.
685 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
687 @retval EFI_SUCCESS The device was reset.
688 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
695 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
696 IN BOOLEAN ExtendedVerification
700 Read BufferSize bytes from Lba into Buffer.
702 @param[in] This Indicates a pointer to the calling context.
703 @param[in] MediaId Id of the media, changes every time the media is replaced.
704 @param[in] Lba The starting Logical Block Address to read from.
705 @param[in, out] Token A pointer to the token associated with the transaction.
706 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
707 @param[out] Buffer A pointer to the destination buffer for the data. The caller is
708 responsible for either having implicit or explicit ownership of the buffer.
710 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
711 The data was read correctly from the device if
713 @retval EFI_DEVICE_ERROR The device reported an error while performing
715 @retval EFI_NO_MEDIA There is no media in the device.
716 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
717 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
718 intrinsic block size of the device.
719 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
720 or the buffer is not on proper alignment.
721 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
727 AtaBlockIoReadBlocksEx (
728 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
731 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
737 Write BufferSize bytes from Lba into Buffer.
739 @param[in] This Indicates a pointer to the calling context.
740 @param[in] MediaId The media ID that the write request is for.
741 @param[in] Lba The starting logical block address to be written. The
742 caller is responsible for writing to only legitimate
744 @param[in, out] Token A pointer to the token associated with the transaction.
745 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
746 @param[in] Buffer A pointer to the source buffer for the data.
748 @retval EFI_SUCCESS The data was written correctly to the device.
749 @retval EFI_WRITE_PROTECTED The device can not be written to.
750 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
751 @retval EFI_NO_MEDIA There is no media in the device.
752 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
753 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
754 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
755 or the buffer is not on proper alignment.
760 AtaBlockIoWriteBlocksEx (
761 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
764 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
770 Flush the Block Device.
772 @param[in] This Indicates a pointer to the calling context.
773 @param[in, out] Token A pointer to the token associated with the transaction.
775 @retval EFI_SUCCESS All outstanding data was written to the device
776 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
777 @retval EFI_NO_MEDIA There is no media in the device.
782 AtaBlockIoFlushBlocksEx (
783 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
784 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
788 Terminate any in-flight non-blocking I/O requests by signaling an EFI_ABORTED
789 in the TransactionStatus member of the EFI_BLOCK_IO2_TOKEN for the non-blocking
790 I/O. After that it is safe to free any Token or Buffer data structures that
791 were allocated to initiate the non-blockingI/O requests that were in-flight for
794 @param[in] AtaDevice The ATA child device involved for the operation.
799 AtaTerminateNonBlockingTask (
800 IN ATA_DEVICE
*AtaDevice
804 Provides inquiry information for the controller type.
806 This function is used by the IDE bus driver to get inquiry data. Data format
807 of Identify data is defined by the Interface GUID.
809 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
810 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
811 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
813 @retval EFI_SUCCESS The command was accepted without any errors.
814 @retval EFI_NOT_FOUND Device does not support this data class
815 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
816 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
822 IN EFI_DISK_INFO_PROTOCOL
*This
,
823 IN OUT VOID
*InquiryData
,
824 IN OUT UINT32
*InquiryDataSize
829 Provides identify information for the controller type.
831 This function is used by the IDE bus driver to get identify data. Data format
832 of Identify data is defined by the Interface GUID.
834 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
836 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
837 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
840 @retval EFI_SUCCESS The command was accepted without any errors.
841 @retval EFI_NOT_FOUND Device does not support this data class
842 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
843 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
848 AtaDiskInfoIdentify (
849 IN EFI_DISK_INFO_PROTOCOL
*This
,
850 IN OUT VOID
*IdentifyData
,
851 IN OUT UINT32
*IdentifyDataSize
856 Provides sense data information for the controller type.
858 This function is used by the IDE bus driver to get sense data.
859 Data format of Sense data is defined by the Interface GUID.
861 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
862 @param[in, out] SenseData Pointer to the SenseData.
863 @param[in, out] SenseDataSize Size of SenseData in bytes.
864 @param[out] SenseDataNumber Pointer to the value for the sense data size.
866 @retval EFI_SUCCESS The command was accepted without any errors.
867 @retval EFI_NOT_FOUND Device does not support this data class.
868 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
869 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
874 AtaDiskInfoSenseData (
875 IN EFI_DISK_INFO_PROTOCOL
*This
,
876 IN OUT VOID
*SenseData
,
877 IN OUT UINT32
*SenseDataSize
,
878 OUT UINT8
*SenseDataNumber
883 This function is used by the IDE bus driver to get controller information.
885 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
886 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
887 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
889 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
890 @retval EFI_UNSUPPORTED This is not an IDE device.
895 AtaDiskInfoWhichIde (
896 IN EFI_DISK_INFO_PROTOCOL
*This
,
897 OUT UINT32
*IdeChannel
,
898 OUT UINT32
*IdeDevice
902 Send a security protocol command to a device that receives data and/or the result
903 of one or more commands sent by SendData.
905 The ReceiveData function sends a security protocol command to the given MediaId.
906 The security protocol command sent is defined by SecurityProtocolId and contains
907 the security protocol specific data SecurityProtocolSpecificData. The function
908 returns the data from the security protocol command in PayloadBuffer.
910 For devices supporting the SCSI command set, the security protocol command is sent
911 using the SECURITY PROTOCOL IN command defined in SPC-4.
913 For devices supporting the ATA command set, the security protocol command is sent
914 using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize
917 If the PayloadBufferSize is zero, the security protocol command is sent using the
918 Trusted Non-Data command defined in ATA8-ACS.
920 If PayloadBufferSize is too small to store the available data from the security
921 protocol command, the function shall copy PayloadBufferSize bytes into the
922 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
924 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
925 the function shall return EFI_INVALID_PARAMETER.
927 If the given MediaId does not support security protocol commands, the function shall
928 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
929 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
930 the function returns EFI_MEDIA_CHANGED.
932 If the security protocol fails to complete within the Timeout period, the function
933 shall return EFI_TIMEOUT.
935 If the security protocol command completes without an error, the function shall
936 return EFI_SUCCESS. If the security protocol command completes with an error, the
937 function shall return EFI_DEVICE_ERROR.
939 @param This Indicates a pointer to the calling context.
940 @param MediaId ID of the medium to receive data from.
941 @param Timeout The timeout, in 100ns units, to use for the execution
942 of the security protocol command. A Timeout value of 0
943 means that this function will wait indefinitely for the
944 security protocol command to execute. If Timeout is greater
945 than zero, then this function will return EFI_TIMEOUT
946 if the time required to execute the receive data command
947 is greater than Timeout.
948 @param SecurityProtocolId The value of the "Security Protocol" parameter of
949 the security protocol command to be sent.
950 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
951 of the security protocol command to be sent.
952 @param PayloadBufferSize Size in bytes of the payload data buffer.
953 @param PayloadBuffer A pointer to a destination buffer to store the security
954 protocol command specific payload data for the security
955 protocol command. The caller is responsible for having
956 either implicit or explicit ownership of the buffer.
957 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
958 data written to the payload data buffer.
960 @retval EFI_SUCCESS The security protocol command completed successfully.
961 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
962 data from the device. The PayloadBuffer contains the truncated data.
963 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
964 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
965 @retval EFI_NO_MEDIA There is no media in the device.
966 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
967 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
968 PayloadBufferSize is non-zero.
969 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
970 protocol command to execute.
975 AtaStorageSecurityReceiveData (
976 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
979 IN UINT8 SecurityProtocolId
,
980 IN UINT16 SecurityProtocolSpecificData
,
981 IN UINTN PayloadBufferSize
,
982 OUT VOID
*PayloadBuffer
,
983 OUT UINTN
*PayloadTransferSize
987 Send a security protocol command to a device.
989 The SendData function sends a security protocol command containing the payload
990 PayloadBuffer to the given MediaId. The security protocol command sent is
991 defined by SecurityProtocolId and contains the security protocol specific data
992 SecurityProtocolSpecificData. If the underlying protocol command requires a
993 specific padding for the command payload, the SendData function shall add padding
994 bytes to the command payload to satisfy the padding requirements.
996 For devices supporting the SCSI command set, the security protocol command is sent
997 using the SECURITY PROTOCOL OUT command defined in SPC-4.
999 For devices supporting the ATA command set, the security protocol command is sent
1000 using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize
1001 is non-zero. If the PayloadBufferSize is zero, the security protocol command is
1002 sent using the Trusted Non-Data command defined in ATA8-ACS.
1004 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
1005 return EFI_INVALID_PARAMETER.
1007 If the given MediaId does not support security protocol commands, the function
1008 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
1009 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
1010 device, the function returns EFI_MEDIA_CHANGED.
1012 If the security protocol fails to complete within the Timeout period, the function
1013 shall return EFI_TIMEOUT.
1015 If the security protocol command completes without an error, the function shall return
1016 EFI_SUCCESS. If the security protocol command completes with an error, the function
1017 shall return EFI_DEVICE_ERROR.
1019 @param This Indicates a pointer to the calling context.
1020 @param MediaId ID of the medium to receive data from.
1021 @param Timeout The timeout, in 100ns units, to use for the execution
1022 of the security protocol command. A Timeout value of 0
1023 means that this function will wait indefinitely for the
1024 security protocol command to execute. If Timeout is greater
1025 than zero, then this function will return EFI_TIMEOUT
1026 if the time required to execute the receive data command
1027 is greater than Timeout.
1028 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1029 the security protocol command to be sent.
1030 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1031 of the security protocol command to be sent.
1032 @param PayloadBufferSize Size in bytes of the payload data buffer.
1033 @param PayloadBuffer A pointer to a destination buffer to store the security
1034 protocol command specific payload data for the security
1037 @retval EFI_SUCCESS The security protocol command completed successfully.
1038 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1039 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1040 @retval EFI_NO_MEDIA There is no media in the device.
1041 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1042 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
1043 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1044 protocol command to execute.
1049 AtaStorageSecuritySendData (
1050 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1053 IN UINT8 SecurityProtocolId
,
1054 IN UINT16 SecurityProtocolSpecificData
,
1055 IN UINTN PayloadBufferSize
,
1056 IN VOID
*PayloadBuffer
1060 Send TPer Reset command to reset eDrive to lock all protected bands.
1061 Typically, there are 2 mechanism for resetting eDrive. They are:
1062 1. TPer Reset through IEEE 1667 protocol.
1063 2. TPer Reset through native TCG protocol.
1064 This routine will detect what protocol the attached eDrive comform to, TCG or
1065 IEEE 1667 protocol. Then send out TPer Reset command separately.
1067 @param[in] AtaDevice ATA_DEVICE pointer.
1072 IN ATA_DEVICE
*AtaDevice