]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Ata / AtaBusDxe / AtaBus.h
1 /** @file
2 Master header file for ATA Bus Driver.
3
4 This file defines common data structures, macro definitions and some module
5 internal function header files.
6
7 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10 **/
11
12 #ifndef _ATA_BUS_H_
13 #define _ATA_BUS_H_
14
15 #include <Uefi.h>
16
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>
23
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>
35
36 #include <IndustryStandard/Atapi.h>
37
38 //
39 // Time out value for ATA pass through protocol
40 //
41 #define ATA_TIMEOUT EFI_TIMER_PERIOD_SECONDS (3)
42
43 //
44 // Maximum number of times to retry ATA command
45 //
46 #define MAX_RETRY_TIMES 3
47
48 //
49 // The maximum total sectors count in 28 bit addressing mode
50 //
51 #define MAX_28BIT_ADDRESSING_CAPACITY 0xfffffff
52
53 //
54 // The maximum ATA transaction sector count in 28 bit addressing mode.
55 //
56 #define MAX_28BIT_TRANSFER_BLOCK_NUM 0x100
57
58 //
59 // The maximum ATA transaction sector count in 48 bit addressing mode.
60 //
61 //#define MAX_48BIT_TRANSFER_BLOCK_NUM 0x10000
62
63 //
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
67 // this issue.
68 //
69 #define MAX_48BIT_TRANSFER_BLOCK_NUM 0xFFFF
70
71 //
72 // The maximum model name in ATA identify data
73 //
74 #define MAX_MODEL_NAME_LEN 40
75
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)
80
81 //
82 // ATA bus data structure for ATA controller
83 //
84 typedef struct {
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;
90
91 //
92 // ATA device data structure for each child device
93 //
94 typedef struct {
95 UINT32 Signature;
96
97 EFI_HANDLE Handle;
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;
104
105 ATA_BUS_DRIVER_DATA *AtaBusDriverData;
106 UINT16 Port;
107 UINT16 PortMultiplierPort;
108
109 //
110 // Buffer for the execution of ATA pass through protocol
111 //
112 EFI_ATA_PASS_THRU_COMMAND_PACKET Packet;
113 EFI_ATA_COMMAND_BLOCK Acb;
114 EFI_ATA_STATUS_BLOCK *Asb;
115
116 BOOLEAN UdmaValid;
117 BOOLEAN Lba48Bit;
118
119 //
120 // Cached data for ATA identify data
121 //
122 ATA_IDENTIFY_DATA *IdentifyData;
123
124 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
125 CHAR16 ModelName[MAX_MODEL_NAME_LEN + 1];
126
127 LIST_ENTRY AtaTaskList;
128 LIST_ENTRY AtaSubTaskList;
129 BOOLEAN Abort;
130 } ATA_DEVICE;
131
132 //
133 // Sub-Task for the non blocking I/O
134 //
135 typedef struct {
136 UINT32 Signature;
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;
144
145 //
146 // Task for the non blocking I/O
147 //
148 typedef struct {
149 UINT32 Signature;
150 EFI_BLOCK_IO2_TOKEN *Token;
151 ATA_DEVICE *AtaDevice;
152 UINT8 *Buffer;
153 EFI_LBA StartLba;
154 UINTN NumberOfBlocks;
155 BOOLEAN IsWrite;
156 LIST_ENTRY TaskEntry;
157 } ATA_BUS_ASYN_TASK;
158
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)
165
166 //
167 // Global Variables
168 //
169 extern EFI_DRIVER_BINDING_PROTOCOL gAtaBusDriverBinding;
170 extern EFI_COMPONENT_NAME_PROTOCOL gAtaBusComponentName;
171 extern EFI_COMPONENT_NAME2_PROTOCOL gAtaBusComponentName2;
172
173 /**
174 Allocates an aligned buffer for ATA device.
175
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
178 through interface.
179
180 @param AtaDevice The ATA child device involved for the operation.
181 @param BufferSize The request buffer size.
182
183 @return A pointer to the aligned buffer or NULL if the allocation fails.
184
185 **/
186 VOID *
187 AllocateAlignedBuffer (
188 IN ATA_DEVICE *AtaDevice,
189 IN UINTN BufferSize
190 );
191
192 /**
193 Frees an aligned buffer for ATA device.
194
195 This function frees an aligned buffer for the ATA device to perform
196 ATA pass through operations.
197
198 @param Buffer The aligned buffer to be freed.
199 @param BufferSize The request buffer size.
200
201 **/
202 VOID
203 FreeAlignedBuffer (
204 IN VOID *Buffer,
205 IN UINTN BufferSize
206 );
207
208 /**
209 Free SubTask.
210
211 @param[in, out] Task Pointer to task to be freed.
212
213 **/
214 VOID
215 EFIAPI
216 FreeAtaSubTask (
217 IN OUT ATA_BUS_ASYN_SUB_TASK *Task
218 );
219
220 /**
221 Wrapper for EFI_ATA_PASS_THRU_PROTOCOL.ResetDevice().
222
223 This function wraps the ResetDevice() invocation for ATA pass through function
224 for an ATA device.
225
226 @param AtaDevice The ATA child device involved for the operation.
227
228 @return The return status from EFI_ATA_PASS_THRU_PROTOCOL.PassThru().
229
230 **/
231 EFI_STATUS
232 ResetAtaDevice (
233 IN ATA_DEVICE *AtaDevice
234 );
235
236
237 /**
238 Discovers whether it is a valid ATA device.
239
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.
243
244 @param AtaDevice The ATA child device involved for the operation.
245
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.
249
250 **/
251 EFI_STATUS
252 DiscoverAtaDevice (
253 IN OUT ATA_DEVICE *AtaDevice
254 );
255
256 /**
257 Read or write a number of blocks from ATA device.
258
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
261 transactions.
262
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.
269
270 @retval EFI_SUCCESS The data transfer is complete successfully.
271 @return others Some error occurs when transferring data.
272
273 **/
274 EFI_STATUS
275 AccessAtaDevice(
276 IN OUT ATA_DEVICE *AtaDevice,
277 IN OUT UINT8 *Buffer,
278 IN EFI_LBA StartLba,
279 IN UINTN NumberOfBlocks,
280 IN BOOLEAN IsWrite,
281 IN OUT EFI_BLOCK_IO2_TOKEN *Token
282 );
283
284 /**
285 Trust transfer data from/to ATA device.
286
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.
290
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.
308
309 @retval EFI_SUCCESS The data transfer is complete successfully.
310 @return others Some error occurs when transferring data.
311
312 **/
313 EFI_STATUS
314 EFIAPI
315 TrustTransferAtaDevice (
316 IN OUT ATA_DEVICE *AtaDevice,
317 IN OUT VOID *Buffer,
318 IN UINT8 SecurityProtocolId,
319 IN UINT16 SecurityProtocolSpecificData,
320 IN UINTN TransferLength,
321 IN BOOLEAN IsTrustSend,
322 IN UINT64 Timeout,
323 OUT UINTN *TransferLengthOut
324 );
325
326 //
327 // Protocol interface prototypes
328 //
329 /**
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.
332
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.
346
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
357 bus driver.
358
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
363 specified by This.
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.
370 **/
371 EFI_STATUS
372 EFIAPI
373 AtaBusDriverBindingSupported (
374 IN EFI_DRIVER_BINDING_PROTOCOL *This,
375 IN EFI_HANDLE Controller,
376 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
377 );
378
379 /**
380 Starts a device controller or a bus controller.
381
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.
391
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
406 driver.
407
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.
412
413 **/
414 EFI_STATUS
415 EFIAPI
416 AtaBusDriverBindingStart (
417 IN EFI_DRIVER_BINDING_PROTOCOL *This,
418 IN EFI_HANDLE Controller,
419 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
420 );
421
422 /**
423 Stops a device controller or a bus controller.
424
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.
435
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.
443
444 @retval EFI_SUCCESS The device was stopped.
445 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
446
447 **/
448 EFI_STATUS
449 EFIAPI
450 AtaBusDriverBindingStop (
451 IN EFI_DRIVER_BINDING_PROTOCOL *This,
452 IN EFI_HANDLE Controller,
453 IN UINTN NumberOfChildren,
454 IN EFI_HANDLE *ChildHandleBuffer
455 );
456
457
458 /**
459 Retrieves a Unicode string that is the user readable name of the driver.
460
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.
467
468 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
469 EFI_COMPONENT_NAME_PROTOCOL instance.
470
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.
479
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.
484
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.
488
489 @retval EFI_INVALID_PARAMETER Language is NULL.
490
491 @retval EFI_INVALID_PARAMETER DriverName is NULL.
492
493 @retval EFI_UNSUPPORTED The driver specified by This does not support
494 the language specified by Language.
495
496 **/
497 EFI_STATUS
498 EFIAPI
499 AtaBusComponentNameGetDriverName (
500 IN EFI_COMPONENT_NAME_PROTOCOL *This,
501 IN CHAR8 *Language,
502 OUT CHAR16 **DriverName
503 );
504
505
506 /**
507 Retrieves a Unicode string that is the user readable name of the controller
508 that is being managed by a driver.
509
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.
518
519 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
520 EFI_COMPONENT_NAME_PROTOCOL instance.
521
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
525 returned.
526
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
534 child controller.
535
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.
544
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
550 specified by This.
551
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
555 DriverName.
556
557 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
558
559 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
560 EFI_HANDLE.
561
562 @retval EFI_INVALID_PARAMETER Language is NULL.
563
564 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
565
566 @retval EFI_UNSUPPORTED The driver specified by This is not currently
567 managing the controller specified by
568 ControllerHandle and ChildHandle.
569
570 @retval EFI_UNSUPPORTED The driver specified by This does not support
571 the language specified by Language.
572
573 **/
574 EFI_STATUS
575 EFIAPI
576 AtaBusComponentNameGetControllerName (
577 IN EFI_COMPONENT_NAME_PROTOCOL *This,
578 IN EFI_HANDLE ControllerHandle,
579 IN EFI_HANDLE ChildHandle OPTIONAL,
580 IN CHAR8 *Language,
581 OUT CHAR16 **ControllerName
582 );
583
584
585 /**
586 Reset the Block Device.
587
588 @param This Indicates a pointer to the calling context.
589 @param ExtendedVerification Driver may perform diagnostics on reset.
590
591 @retval EFI_SUCCESS The device was reset.
592 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
593 not be reset.
594
595 **/
596 EFI_STATUS
597 EFIAPI
598 AtaBlockIoReset (
599 IN EFI_BLOCK_IO_PROTOCOL *This,
600 IN BOOLEAN ExtendedVerification
601 );
602
603
604 /**
605 Read BufferSize bytes from Lba into Buffer.
606
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.
613
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.
621
622 **/
623 EFI_STATUS
624 EFIAPI
625 AtaBlockIoReadBlocks (
626 IN EFI_BLOCK_IO_PROTOCOL *This,
627 IN UINT32 MediaId,
628 IN EFI_LBA Lba,
629 IN UINTN BufferSize,
630 OUT VOID *Buffer
631 );
632
633
634 /**
635 Write BufferSize bytes from Lba into Buffer.
636
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.
643
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.
652
653 **/
654 EFI_STATUS
655 EFIAPI
656 AtaBlockIoWriteBlocks (
657 IN EFI_BLOCK_IO_PROTOCOL *This,
658 IN UINT32 MediaId,
659 IN EFI_LBA Lba,
660 IN UINTN BufferSize,
661 IN VOID *Buffer
662 );
663
664
665 /**
666 Flush the Block Device.
667
668 @param This Indicates a pointer to the calling context.
669
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.
673
674 **/
675 EFI_STATUS
676 EFIAPI
677 AtaBlockIoFlushBlocks (
678 IN EFI_BLOCK_IO_PROTOCOL *This
679 );
680
681 /**
682 Reset the Block Device throught Block I/O2 protocol.
683
684 @param[in] This Indicates a pointer to the calling context.
685 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
686
687 @retval EFI_SUCCESS The device was reset.
688 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
689 not be reset.
690
691 **/
692 EFI_STATUS
693 EFIAPI
694 AtaBlockIoResetEx (
695 IN EFI_BLOCK_IO2_PROTOCOL *This,
696 IN BOOLEAN ExtendedVerification
697 );
698
699 /**
700 Read BufferSize bytes from Lba into Buffer.
701
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.
709
710 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
711 The data was read correctly from the device if
712 the Event is NULL.
713 @retval EFI_DEVICE_ERROR The device reported an error while performing
714 the read.
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
722 of resources.
723
724 **/
725 EFI_STATUS
726 EFIAPI
727 AtaBlockIoReadBlocksEx (
728 IN EFI_BLOCK_IO2_PROTOCOL *This,
729 IN UINT32 MediaId,
730 IN EFI_LBA Lba,
731 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
732 IN UINTN BufferSize,
733 OUT VOID *Buffer
734 );
735
736 /**
737 Write BufferSize bytes from Lba into Buffer.
738
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
743 locations.
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.
747
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.
756
757 **/
758 EFI_STATUS
759 EFIAPI
760 AtaBlockIoWriteBlocksEx (
761 IN EFI_BLOCK_IO2_PROTOCOL *This,
762 IN UINT32 MediaId,
763 IN EFI_LBA Lba,
764 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
765 IN UINTN BufferSize,
766 IN VOID *Buffer
767 );
768
769 /**
770 Flush the Block Device.
771
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.
774
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.
778
779 **/
780 EFI_STATUS
781 EFIAPI
782 AtaBlockIoFlushBlocksEx (
783 IN EFI_BLOCK_IO2_PROTOCOL *This,
784 IN OUT EFI_BLOCK_IO2_TOKEN *Token
785 );
786
787 /**
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
792 this device.
793
794 @param[in] AtaDevice The ATA child device involved for the operation.
795
796 **/
797 VOID
798 EFIAPI
799 AtaTerminateNonBlockingTask (
800 IN ATA_DEVICE *AtaDevice
801 );
802
803 /**
804 Provides inquiry information for the controller type.
805
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.
808
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.
812
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
817
818 **/
819 EFI_STATUS
820 EFIAPI
821 AtaDiskInfoInquiry (
822 IN EFI_DISK_INFO_PROTOCOL *This,
823 IN OUT VOID *InquiryData,
824 IN OUT UINT32 *InquiryDataSize
825 );
826
827
828 /**
829 Provides identify information for the controller type.
830
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.
833
834 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
835 instance.
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
838 size.
839
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
844
845 **/
846 EFI_STATUS
847 EFIAPI
848 AtaDiskInfoIdentify (
849 IN EFI_DISK_INFO_PROTOCOL *This,
850 IN OUT VOID *IdentifyData,
851 IN OUT UINT32 *IdentifyDataSize
852 );
853
854
855 /**
856 Provides sense data information for the controller type.
857
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.
860
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.
865
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.
870
871 **/
872 EFI_STATUS
873 EFIAPI
874 AtaDiskInfoSenseData (
875 IN EFI_DISK_INFO_PROTOCOL *This,
876 IN OUT VOID *SenseData,
877 IN OUT UINT32 *SenseDataSize,
878 OUT UINT8 *SenseDataNumber
879 );
880
881
882 /**
883 This function is used by the IDE bus driver to get controller information.
884
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.
888
889 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
890 @retval EFI_UNSUPPORTED This is not an IDE device.
891
892 **/
893 EFI_STATUS
894 EFIAPI
895 AtaDiskInfoWhichIde (
896 IN EFI_DISK_INFO_PROTOCOL *This,
897 OUT UINT32 *IdeChannel,
898 OUT UINT32 *IdeDevice
899 );
900
901 /**
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.
904
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.
909
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.
912
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
915 is non-zero.
916
917 If the PayloadBufferSize is zero, the security protocol command is sent using the
918 Trusted Non-Data command defined in ATA8-ACS.
919
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.
923
924 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
925 the function shall return EFI_INVALID_PARAMETER.
926
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.
931
932 If the security protocol fails to complete within the Timeout period, the function
933 shall return EFI_TIMEOUT.
934
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.
938
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.
959
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.
971
972 **/
973 EFI_STATUS
974 EFIAPI
975 AtaStorageSecurityReceiveData (
976 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
977 IN UINT32 MediaId,
978 IN UINT64 Timeout,
979 IN UINT8 SecurityProtocolId,
980 IN UINT16 SecurityProtocolSpecificData,
981 IN UINTN PayloadBufferSize,
982 OUT VOID *PayloadBuffer,
983 OUT UINTN *PayloadTransferSize
984 );
985
986 /**
987 Send a security protocol command to a device.
988
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.
995
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.
998
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.
1003
1004 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
1005 return EFI_INVALID_PARAMETER.
1006
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.
1011
1012 If the security protocol fails to complete within the Timeout period, the function
1013 shall return EFI_TIMEOUT.
1014
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.
1018
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
1035 protocol command.
1036
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.
1045
1046 **/
1047 EFI_STATUS
1048 EFIAPI
1049 AtaStorageSecuritySendData (
1050 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
1051 IN UINT32 MediaId,
1052 IN UINT64 Timeout,
1053 IN UINT8 SecurityProtocolId,
1054 IN UINT16 SecurityProtocolSpecificData,
1055 IN UINTN PayloadBufferSize,
1056 IN VOID *PayloadBuffer
1057 );
1058
1059 /**
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.
1066
1067 @param[in] AtaDevice ATA_DEVICE pointer.
1068
1069 **/
1070 VOID
1071 InitiateTPerReset (
1072 IN ATA_DEVICE *AtaDevice
1073 );
1074
1075 #endif