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
237 Discovers whether it is a valid ATA device.
239 This function issues ATA_CMD_IDENTIFY_DRIVE command to the ATA device to identify it.
240 If the command is executed successfully, it then identifies it and initializes
241 the Media information in Block IO protocol interface.
243 @param AtaDevice The ATA child device involved for the operation.
245 @retval EFI_SUCCESS The device is successfully identified and Media information
246 is correctly initialized.
247 @return others Some error occurs when discovering the ATA device.
252 IN OUT ATA_DEVICE
*AtaDevice
256 Read or write a number of blocks from ATA device.
258 This function performs ATA pass through transactions to read/write data from/to
259 ATA device. It may separate the read/write request into several ATA pass through
262 @param[in, out] AtaDevice The ATA child device involved for the operation.
263 @param[in, out] Buffer The pointer to the current transaction buffer.
264 @param[in] StartLba The starting logical block address to be accessed.
265 @param[in] NumberOfBlocks The block number or sector count of the transfer.
266 @param[in] IsWrite Indicates whether it is a write operation.
267 @param[in, out] Token A pointer to the token associated with the transaction.
269 @retval EFI_SUCCESS The data transfer is complete successfully.
270 @return others Some error occurs when transferring data.
275 IN OUT ATA_DEVICE
*AtaDevice
,
276 IN OUT UINT8
*Buffer
,
278 IN UINTN NumberOfBlocks
,
280 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
284 Trust transfer data from/to ATA device.
286 This function performs one ATA pass through transaction to do a trust transfer from/to
287 ATA device. It chooses the appropriate ATA command and protocol to invoke PassThru
288 interface of ATA pass through.
290 @param AtaDevice The ATA child device involved for the operation.
291 @param Buffer The pointer to the current transaction buffer.
292 @param SecurityProtocolId The value of the "Security Protocol" parameter of
293 the security protocol command to be sent.
294 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
295 of the security protocol command to be sent.
296 @param TransferLength The block number or sector count of the transfer.
297 @param IsTrustSend Indicates whether it is a trust send operation or not.
298 @param Timeout The timeout, in 100ns units, to use for the execution
299 of the security protocol command. A Timeout value of 0
300 means that this function will wait indefinitely for the
301 security protocol command to execute. If Timeout is greater
302 than zero, then this function will return EFI_TIMEOUT
303 if the time required to execute the receive data command
304 is greater than Timeout.
305 @param TransferLengthOut A pointer to a buffer to store the size in bytes of the data
306 written to the buffer. Ignore it when IsTrustSend is TRUE.
308 @retval EFI_SUCCESS The data transfer is complete successfully.
309 @return others Some error occurs when transferring data.
314 TrustTransferAtaDevice (
315 IN OUT ATA_DEVICE
*AtaDevice
,
317 IN UINT8 SecurityProtocolId
,
318 IN UINT16 SecurityProtocolSpecificData
,
319 IN UINTN TransferLength
,
320 IN BOOLEAN IsTrustSend
,
322 OUT UINTN
*TransferLengthOut
326 // 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 failed 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
458 Retrieves a Unicode string that is the user readable name of the driver.
460 This function retrieves the user readable name of a driver in the form of a
461 Unicode string. If the driver specified by This has a user readable name in
462 the language specified by Language, then a pointer to the driver name is
463 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
464 by This does not support the language specified by Language,
465 then EFI_UNSUPPORTED is returned.
467 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
468 EFI_COMPONENT_NAME_PROTOCOL instance.
470 @param Language[in] A pointer to a Null-terminated ASCII string
471 array indicating the language. This is the
472 language of the driver name that the caller is
473 requesting, and it must match one of the
474 languages specified in SupportedLanguages. The
475 number of languages supported by a driver is up
476 to the driver writer. Language is specified
477 in RFC 4646 or ISO 639-2 language code format.
479 @param DriverName[out] A pointer to the Unicode string to return.
480 This Unicode string is the name of the
481 driver specified by This in the language
482 specified by Language.
484 @retval EFI_SUCCESS The Unicode string for the Driver specified by
485 This and the language specified by Language was
486 returned in DriverName.
488 @retval EFI_INVALID_PARAMETER Language is NULL.
490 @retval EFI_INVALID_PARAMETER DriverName is NULL.
492 @retval EFI_UNSUPPORTED The driver specified by This does not support
493 the language specified by Language.
498 AtaBusComponentNameGetDriverName (
499 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
501 OUT CHAR16
**DriverName
505 Retrieves a Unicode string that is the user readable name of the controller
506 that is being managed by a driver.
508 This function retrieves the user readable name of the controller specified by
509 ControllerHandle and ChildHandle in the form of a Unicode string. If the
510 driver specified by This has a user readable name in the language specified by
511 Language, then a pointer to the controller name is returned in ControllerName,
512 and EFI_SUCCESS is returned. If the driver specified by This is not currently
513 managing the controller specified by ControllerHandle and ChildHandle,
514 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
515 support the language specified by Language, then EFI_UNSUPPORTED is returned.
517 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
518 EFI_COMPONENT_NAME_PROTOCOL instance.
520 @param ControllerHandle[in] The handle of a controller that the driver
521 specified by This is managing. This handle
522 specifies the controller whose name is to be
525 @param ChildHandle[in] The handle of the child controller to retrieve
526 the name of. This is an optional parameter that
527 may be NULL. It will be NULL for device
528 drivers. It will also be NULL for a bus drivers
529 that wish to retrieve the name of the bus
530 controller. It will not be NULL for a bus
531 driver that wishes to retrieve the name of a
534 @param Language[in] A pointer to a Null-terminated ASCII string
535 array indicating the language. This is the
536 language of the driver name that the caller is
537 requesting, and it must match one of the
538 languages specified in SupportedLanguages. The
539 number of languages supported by a driver is up
540 to the driver writer. Language is specified in
541 RFC 4646 or ISO 639-2 language code format.
543 @param ControllerName[out] A pointer to the Unicode string to return.
544 This Unicode string is the name of the
545 controller specified by ControllerHandle and
546 ChildHandle in the language specified by
547 Language from the point of view of the driver
550 @retval EFI_SUCCESS The Unicode string for the user readable name in
551 the language specified by Language for the
552 driver specified by This was returned in
555 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
557 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
560 @retval EFI_INVALID_PARAMETER Language is NULL.
562 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
564 @retval EFI_UNSUPPORTED The driver specified by This is not currently
565 managing the controller specified by
566 ControllerHandle and ChildHandle.
568 @retval EFI_UNSUPPORTED The driver specified by This does not support
569 the language specified by Language.
574 AtaBusComponentNameGetControllerName (
575 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
576 IN EFI_HANDLE ControllerHandle
,
577 IN EFI_HANDLE ChildHandle OPTIONAL
,
579 OUT CHAR16
**ControllerName
583 Reset the Block Device.
585 @param This Indicates a pointer to the calling context.
586 @param ExtendedVerification Driver may perform diagnostics on reset.
588 @retval EFI_SUCCESS The device was reset.
589 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
596 IN EFI_BLOCK_IO_PROTOCOL
*This
,
597 IN BOOLEAN ExtendedVerification
601 Read BufferSize bytes from Lba into Buffer.
603 @param This Indicates a pointer to the calling context.
604 @param MediaId Id of the media, changes every time the media is replaced.
605 @param Lba The starting Logical Block Address to read from
606 @param BufferSize Size of Buffer, must be a multiple of device block size.
607 @param Buffer A pointer to the destination buffer for the data. The caller is
608 responsible for either having implicit or explicit ownership of the buffer.
610 @retval EFI_SUCCESS The data was read correctly from the device.
611 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
612 @retval EFI_NO_MEDIA There is no media in the device.
613 @retval EFI_MEDIA_CHANGED The MediaId does not match the current device.
614 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
615 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
616 or the buffer is not on proper alignment.
621 AtaBlockIoReadBlocks (
622 IN EFI_BLOCK_IO_PROTOCOL
*This
,
630 Write BufferSize bytes from Lba into Buffer.
632 @param This Indicates a pointer to the calling context.
633 @param MediaId The media ID that the write request is for.
634 @param Lba The starting logical block address to be written. The caller is
635 responsible for writing to only legitimate locations.
636 @param BufferSize Size of Buffer, must be a multiple of device block size.
637 @param Buffer A pointer to the source buffer for the data.
639 @retval EFI_SUCCESS The data was written correctly to the device.
640 @retval EFI_WRITE_PROTECTED The device can not be written to.
641 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
642 @retval EFI_NO_MEDIA There is no media in the device.
643 @retval EFI_MEDIA_CHANGED The MediaId does not match the current device.
644 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
645 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
646 or the buffer is not on proper alignment.
651 AtaBlockIoWriteBlocks (
652 IN EFI_BLOCK_IO_PROTOCOL
*This
,
660 Flush the Block Device.
662 @param This Indicates a pointer to the calling context.
664 @retval EFI_SUCCESS All outstanding data was written to the device
665 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
666 @retval EFI_NO_MEDIA There is no media in the device.
671 AtaBlockIoFlushBlocks (
672 IN EFI_BLOCK_IO_PROTOCOL
*This
676 Reset the Block Device through Block I/O2 protocol.
678 @param[in] This Indicates a pointer to the calling context.
679 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
681 @retval EFI_SUCCESS The device was reset.
682 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
689 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
690 IN BOOLEAN ExtendedVerification
694 Read BufferSize bytes from Lba into Buffer.
696 @param[in] This Indicates a pointer to the calling context.
697 @param[in] MediaId Id of the media, changes every time the media is replaced.
698 @param[in] Lba The starting Logical Block Address to read from.
699 @param[in, out] Token A pointer to the token associated with the transaction.
700 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
701 @param[out] Buffer A pointer to the destination buffer for the data. The caller is
702 responsible for either having implicit or explicit ownership of the buffer.
704 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
705 The data was read correctly from the device if
707 @retval EFI_DEVICE_ERROR The device reported an error while performing
709 @retval EFI_NO_MEDIA There is no media in the device.
710 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
711 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
712 intrinsic block size of the device.
713 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
714 or the buffer is not on proper alignment.
715 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
721 AtaBlockIoReadBlocksEx (
722 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
725 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
731 Write BufferSize bytes from Lba into Buffer.
733 @param[in] This Indicates a pointer to the calling context.
734 @param[in] MediaId The media ID that the write request is for.
735 @param[in] Lba The starting logical block address to be written. The
736 caller is responsible for writing to only legitimate
738 @param[in, out] Token A pointer to the token associated with the transaction.
739 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
740 @param[in] Buffer A pointer to the source buffer for the data.
742 @retval EFI_SUCCESS The data was written correctly to the device.
743 @retval EFI_WRITE_PROTECTED The device can not be written to.
744 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
745 @retval EFI_NO_MEDIA There is no media in the device.
746 @retval EFI_MEDIA_CHANGED The MediaId does not match the current device.
747 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
748 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
749 or the buffer is not on proper alignment.
754 AtaBlockIoWriteBlocksEx (
755 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
758 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
764 Flush the Block Device.
766 @param[in] This Indicates a pointer to the calling context.
767 @param[in, out] Token A pointer to the token associated with the transaction.
769 @retval EFI_SUCCESS All outstanding data was written to the device
770 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
771 @retval EFI_NO_MEDIA There is no media in the device.
776 AtaBlockIoFlushBlocksEx (
777 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
778 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
782 Terminate any in-flight non-blocking I/O requests by signaling an EFI_ABORTED
783 in the TransactionStatus member of the EFI_BLOCK_IO2_TOKEN for the non-blocking
784 I/O. After that it is safe to free any Token or Buffer data structures that
785 were allocated to initiate the non-blockingI/O requests that were in-flight for
788 @param[in] AtaDevice The ATA child device involved for the operation.
793 AtaTerminateNonBlockingTask (
794 IN ATA_DEVICE
*AtaDevice
798 Provides inquiry information for the controller type.
800 This function is used by the IDE bus driver to get inquiry data. Data format
801 of Identify data is defined by the Interface GUID.
803 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
804 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
805 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
807 @retval EFI_SUCCESS The command was accepted without any errors.
808 @retval EFI_NOT_FOUND Device does not support this data class
809 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
810 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
816 IN EFI_DISK_INFO_PROTOCOL
*This
,
817 IN OUT VOID
*InquiryData
,
818 IN OUT UINT32
*InquiryDataSize
822 Provides identify information for the controller type.
824 This function is used by the IDE bus driver to get identify data. Data format
825 of Identify data is defined by the Interface GUID.
827 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
829 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
830 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
833 @retval EFI_SUCCESS The command was accepted without any errors.
834 @retval EFI_NOT_FOUND Device does not support this data class
835 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
836 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
841 AtaDiskInfoIdentify (
842 IN EFI_DISK_INFO_PROTOCOL
*This
,
843 IN OUT VOID
*IdentifyData
,
844 IN OUT UINT32
*IdentifyDataSize
848 Provides sense data information for the controller type.
850 This function is used by the IDE bus driver to get sense data.
851 Data format of Sense data is defined by the Interface GUID.
853 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
854 @param[in, out] SenseData Pointer to the SenseData.
855 @param[in, out] SenseDataSize Size of SenseData in bytes.
856 @param[out] SenseDataNumber Pointer to the value for the sense data size.
858 @retval EFI_SUCCESS The command was accepted without any errors.
859 @retval EFI_NOT_FOUND Device does not support this data class.
860 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
861 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
866 AtaDiskInfoSenseData (
867 IN EFI_DISK_INFO_PROTOCOL
*This
,
868 IN OUT VOID
*SenseData
,
869 IN OUT UINT32
*SenseDataSize
,
870 OUT UINT8
*SenseDataNumber
874 This function is used by the IDE bus driver to get controller information.
876 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
877 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
878 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
880 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
881 @retval EFI_UNSUPPORTED This is not an IDE device.
886 AtaDiskInfoWhichIde (
887 IN EFI_DISK_INFO_PROTOCOL
*This
,
888 OUT UINT32
*IdeChannel
,
889 OUT UINT32
*IdeDevice
893 Send a security protocol command to a device that receives data and/or the result
894 of one or more commands sent by SendData.
896 The ReceiveData function sends a security protocol command to the given MediaId.
897 The security protocol command sent is defined by SecurityProtocolId and contains
898 the security protocol specific data SecurityProtocolSpecificData. The function
899 returns the data from the security protocol command in PayloadBuffer.
901 For devices supporting the SCSI command set, the security protocol command is sent
902 using the SECURITY PROTOCOL IN command defined in SPC-4.
904 For devices supporting the ATA command set, the security protocol command is sent
905 using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize
908 If the PayloadBufferSize is zero, the security protocol command is sent using the
909 Trusted Non-Data command defined in ATA8-ACS.
911 If PayloadBufferSize is too small to store the available data from the security
912 protocol command, the function shall copy PayloadBufferSize bytes into the
913 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
915 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
916 the function shall return EFI_INVALID_PARAMETER.
918 If the given MediaId does not support security protocol commands, the function shall
919 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
920 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
921 the function returns EFI_MEDIA_CHANGED.
923 If the security protocol fails to complete within the Timeout period, the function
924 shall return EFI_TIMEOUT.
926 If the security protocol command completes without an error, the function shall
927 return EFI_SUCCESS. If the security protocol command completes with an error, the
928 function shall return EFI_DEVICE_ERROR.
930 @param This Indicates a pointer to the calling context.
931 @param MediaId ID of the medium to receive data from.
932 @param Timeout The timeout, in 100ns units, to use for the execution
933 of the security protocol command. A Timeout value of 0
934 means that this function will wait indefinitely for the
935 security protocol command to execute. If Timeout is greater
936 than zero, then this function will return EFI_TIMEOUT
937 if the time required to execute the receive data command
938 is greater than Timeout.
939 @param SecurityProtocolId The value of the "Security Protocol" parameter of
940 the security protocol command to be sent.
941 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
942 of the security protocol command to be sent.
943 @param PayloadBufferSize Size in bytes of the payload data buffer.
944 @param PayloadBuffer A pointer to a destination buffer to store the security
945 protocol command specific payload data for the security
946 protocol command. The caller is responsible for having
947 either implicit or explicit ownership of the buffer.
948 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
949 data written to the payload data buffer.
951 @retval EFI_SUCCESS The security protocol command completed successfully.
952 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
953 data from the device. The PayloadBuffer contains the truncated data.
954 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
955 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
956 @retval EFI_NO_MEDIA There is no media in the device.
957 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
958 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
959 PayloadBufferSize is non-zero.
960 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
961 protocol command to execute.
966 AtaStorageSecurityReceiveData (
967 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
970 IN UINT8 SecurityProtocolId
,
971 IN UINT16 SecurityProtocolSpecificData
,
972 IN UINTN PayloadBufferSize
,
973 OUT VOID
*PayloadBuffer
,
974 OUT UINTN
*PayloadTransferSize
978 Send a security protocol command to a device.
980 The SendData function sends a security protocol command containing the payload
981 PayloadBuffer to the given MediaId. The security protocol command sent is
982 defined by SecurityProtocolId and contains the security protocol specific data
983 SecurityProtocolSpecificData. If the underlying protocol command requires a
984 specific padding for the command payload, the SendData function shall add padding
985 bytes to the command payload to satisfy the padding requirements.
987 For devices supporting the SCSI command set, the security protocol command is sent
988 using the SECURITY PROTOCOL OUT command defined in SPC-4.
990 For devices supporting the ATA command set, the security protocol command is sent
991 using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize
992 is non-zero. If the PayloadBufferSize is zero, the security protocol command is
993 sent using the Trusted Non-Data command defined in ATA8-ACS.
995 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
996 return EFI_INVALID_PARAMETER.
998 If the given MediaId does not support security protocol commands, the function
999 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
1000 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
1001 device, the function returns EFI_MEDIA_CHANGED.
1003 If the security protocol fails to complete within the Timeout period, the function
1004 shall return EFI_TIMEOUT.
1006 If the security protocol command completes without an error, the function shall return
1007 EFI_SUCCESS. If the security protocol command completes with an error, the function
1008 shall return EFI_DEVICE_ERROR.
1010 @param This Indicates a pointer to the calling context.
1011 @param MediaId ID of the medium to receive data from.
1012 @param Timeout The timeout, in 100ns units, to use for the execution
1013 of the security protocol command. A Timeout value of 0
1014 means that this function will wait indefinitely for the
1015 security protocol command to execute. If Timeout is greater
1016 than zero, then this function will return EFI_TIMEOUT
1017 if the time required to execute the receive data command
1018 is greater than Timeout.
1019 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1020 the security protocol command to be sent.
1021 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1022 of the security protocol command to be sent.
1023 @param PayloadBufferSize Size in bytes of the payload data buffer.
1024 @param PayloadBuffer A pointer to a destination buffer to store the security
1025 protocol command specific payload data for the security
1028 @retval EFI_SUCCESS The security protocol command completed successfully.
1029 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1030 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1031 @retval EFI_NO_MEDIA There is no media in the device.
1032 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1033 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
1034 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1035 protocol command to execute.
1040 AtaStorageSecuritySendData (
1041 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*This
,
1044 IN UINT8 SecurityProtocolId
,
1045 IN UINT16 SecurityProtocolSpecificData
,
1046 IN UINTN PayloadBufferSize
,
1047 IN VOID
*PayloadBuffer
1051 Send TPer Reset command to reset eDrive to lock all protected bands.
1052 Typically, there are 2 mechanism for resetting eDrive. They are:
1053 1. TPer Reset through IEEE 1667 protocol.
1054 2. TPer Reset through native TCG protocol.
1055 This routine will detect what protocol the attached eDrive conform to, TCG or
1056 IEEE 1667 protocol. Then send out TPer Reset command separately.
1058 @param[in] AtaDevice ATA_DEVICE pointer.
1063 IN ATA_DEVICE
*AtaDevice