]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 Discovers whether it is a valid ATA device.
238
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.
242
243 @param AtaDevice The ATA child device involved for the operation.
244
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.
248
249 **/
250 EFI_STATUS
251 DiscoverAtaDevice (
252 IN OUT ATA_DEVICE *AtaDevice
253 );
254
255 /**
256 Read or write a number of blocks from ATA device.
257
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
260 transactions.
261
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.
268
269 @retval EFI_SUCCESS The data transfer is complete successfully.
270 @return others Some error occurs when transferring data.
271
272 **/
273 EFI_STATUS
274 AccessAtaDevice (
275 IN OUT ATA_DEVICE *AtaDevice,
276 IN OUT UINT8 *Buffer,
277 IN EFI_LBA StartLba,
278 IN UINTN NumberOfBlocks,
279 IN BOOLEAN IsWrite,
280 IN OUT EFI_BLOCK_IO2_TOKEN *Token
281 );
282
283 /**
284 Trust transfer data from/to ATA device.
285
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.
289
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.
307
308 @retval EFI_SUCCESS The data transfer is complete successfully.
309 @return others Some error occurs when transferring data.
310
311 **/
312 EFI_STATUS
313 EFIAPI
314 TrustTransferAtaDevice (
315 IN OUT ATA_DEVICE *AtaDevice,
316 IN OUT VOID *Buffer,
317 IN UINT8 SecurityProtocolId,
318 IN UINT16 SecurityProtocolSpecificData,
319 IN UINTN TransferLength,
320 IN BOOLEAN IsTrustSend,
321 IN UINT64 Timeout,
322 OUT UINTN *TransferLengthOut
323 );
324
325 //
326 // Protocol interface prototypes
327 //
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 failed 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 Retrieves a Unicode string that is the user readable name of the driver.
459
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.
466
467 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
468 EFI_COMPONENT_NAME_PROTOCOL instance.
469
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.
478
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.
483
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.
487
488 @retval EFI_INVALID_PARAMETER Language is NULL.
489
490 @retval EFI_INVALID_PARAMETER DriverName is NULL.
491
492 @retval EFI_UNSUPPORTED The driver specified by This does not support
493 the language specified by Language.
494
495 **/
496 EFI_STATUS
497 EFIAPI
498 AtaBusComponentNameGetDriverName (
499 IN EFI_COMPONENT_NAME_PROTOCOL *This,
500 IN CHAR8 *Language,
501 OUT CHAR16 **DriverName
502 );
503
504 /**
505 Retrieves a Unicode string that is the user readable name of the controller
506 that is being managed by a driver.
507
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.
516
517 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
518 EFI_COMPONENT_NAME_PROTOCOL instance.
519
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
523 returned.
524
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
532 child controller.
533
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.
542
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
548 specified by This.
549
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
553 DriverName.
554
555 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
556
557 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
558 EFI_HANDLE.
559
560 @retval EFI_INVALID_PARAMETER Language is NULL.
561
562 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
563
564 @retval EFI_UNSUPPORTED The driver specified by This is not currently
565 managing the controller specified by
566 ControllerHandle and ChildHandle.
567
568 @retval EFI_UNSUPPORTED The driver specified by This does not support
569 the language specified by Language.
570
571 **/
572 EFI_STATUS
573 EFIAPI
574 AtaBusComponentNameGetControllerName (
575 IN EFI_COMPONENT_NAME_PROTOCOL *This,
576 IN EFI_HANDLE ControllerHandle,
577 IN EFI_HANDLE ChildHandle OPTIONAL,
578 IN CHAR8 *Language,
579 OUT CHAR16 **ControllerName
580 );
581
582 /**
583 Reset the Block Device.
584
585 @param This Indicates a pointer to the calling context.
586 @param ExtendedVerification Driver may perform diagnostics on reset.
587
588 @retval EFI_SUCCESS The device was reset.
589 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
590 not be reset.
591
592 **/
593 EFI_STATUS
594 EFIAPI
595 AtaBlockIoReset (
596 IN EFI_BLOCK_IO_PROTOCOL *This,
597 IN BOOLEAN ExtendedVerification
598 );
599
600 /**
601 Read BufferSize bytes from Lba into Buffer.
602
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.
609
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.
617
618 **/
619 EFI_STATUS
620 EFIAPI
621 AtaBlockIoReadBlocks (
622 IN EFI_BLOCK_IO_PROTOCOL *This,
623 IN UINT32 MediaId,
624 IN EFI_LBA Lba,
625 IN UINTN BufferSize,
626 OUT VOID *Buffer
627 );
628
629 /**
630 Write BufferSize bytes from Lba into Buffer.
631
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.
638
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.
647
648 **/
649 EFI_STATUS
650 EFIAPI
651 AtaBlockIoWriteBlocks (
652 IN EFI_BLOCK_IO_PROTOCOL *This,
653 IN UINT32 MediaId,
654 IN EFI_LBA Lba,
655 IN UINTN BufferSize,
656 IN VOID *Buffer
657 );
658
659 /**
660 Flush the Block Device.
661
662 @param This Indicates a pointer to the calling context.
663
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.
667
668 **/
669 EFI_STATUS
670 EFIAPI
671 AtaBlockIoFlushBlocks (
672 IN EFI_BLOCK_IO_PROTOCOL *This
673 );
674
675 /**
676 Reset the Block Device through Block I/O2 protocol.
677
678 @param[in] This Indicates a pointer to the calling context.
679 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
680
681 @retval EFI_SUCCESS The device was reset.
682 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
683 not be reset.
684
685 **/
686 EFI_STATUS
687 EFIAPI
688 AtaBlockIoResetEx (
689 IN EFI_BLOCK_IO2_PROTOCOL *This,
690 IN BOOLEAN ExtendedVerification
691 );
692
693 /**
694 Read BufferSize bytes from Lba into Buffer.
695
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.
703
704 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
705 The data was read correctly from the device if
706 the Event is NULL.
707 @retval EFI_DEVICE_ERROR The device reported an error while performing
708 the read.
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
716 of resources.
717
718 **/
719 EFI_STATUS
720 EFIAPI
721 AtaBlockIoReadBlocksEx (
722 IN EFI_BLOCK_IO2_PROTOCOL *This,
723 IN UINT32 MediaId,
724 IN EFI_LBA Lba,
725 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
726 IN UINTN BufferSize,
727 OUT VOID *Buffer
728 );
729
730 /**
731 Write BufferSize bytes from Lba into Buffer.
732
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
737 locations.
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.
741
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.
750
751 **/
752 EFI_STATUS
753 EFIAPI
754 AtaBlockIoWriteBlocksEx (
755 IN EFI_BLOCK_IO2_PROTOCOL *This,
756 IN UINT32 MediaId,
757 IN EFI_LBA Lba,
758 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
759 IN UINTN BufferSize,
760 IN VOID *Buffer
761 );
762
763 /**
764 Flush the Block Device.
765
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.
768
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.
772
773 **/
774 EFI_STATUS
775 EFIAPI
776 AtaBlockIoFlushBlocksEx (
777 IN EFI_BLOCK_IO2_PROTOCOL *This,
778 IN OUT EFI_BLOCK_IO2_TOKEN *Token
779 );
780
781 /**
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
786 this device.
787
788 @param[in] AtaDevice The ATA child device involved for the operation.
789
790 **/
791 VOID
792 EFIAPI
793 AtaTerminateNonBlockingTask (
794 IN ATA_DEVICE *AtaDevice
795 );
796
797 /**
798 Provides inquiry information for the controller type.
799
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.
802
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.
806
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
811
812 **/
813 EFI_STATUS
814 EFIAPI
815 AtaDiskInfoInquiry (
816 IN EFI_DISK_INFO_PROTOCOL *This,
817 IN OUT VOID *InquiryData,
818 IN OUT UINT32 *InquiryDataSize
819 );
820
821 /**
822 Provides identify information for the controller type.
823
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.
826
827 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
828 instance.
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
831 size.
832
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
837
838 **/
839 EFI_STATUS
840 EFIAPI
841 AtaDiskInfoIdentify (
842 IN EFI_DISK_INFO_PROTOCOL *This,
843 IN OUT VOID *IdentifyData,
844 IN OUT UINT32 *IdentifyDataSize
845 );
846
847 /**
848 Provides sense data information for the controller type.
849
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.
852
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.
857
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.
862
863 **/
864 EFI_STATUS
865 EFIAPI
866 AtaDiskInfoSenseData (
867 IN EFI_DISK_INFO_PROTOCOL *This,
868 IN OUT VOID *SenseData,
869 IN OUT UINT32 *SenseDataSize,
870 OUT UINT8 *SenseDataNumber
871 );
872
873 /**
874 This function is used by the IDE bus driver to get controller information.
875
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.
879
880 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
881 @retval EFI_UNSUPPORTED This is not an IDE device.
882
883 **/
884 EFI_STATUS
885 EFIAPI
886 AtaDiskInfoWhichIde (
887 IN EFI_DISK_INFO_PROTOCOL *This,
888 OUT UINT32 *IdeChannel,
889 OUT UINT32 *IdeDevice
890 );
891
892 /**
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.
895
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.
900
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.
903
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
906 is non-zero.
907
908 If the PayloadBufferSize is zero, the security protocol command is sent using the
909 Trusted Non-Data command defined in ATA8-ACS.
910
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.
914
915 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
916 the function shall return EFI_INVALID_PARAMETER.
917
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.
922
923 If the security protocol fails to complete within the Timeout period, the function
924 shall return EFI_TIMEOUT.
925
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.
929
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.
950
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.
962
963 **/
964 EFI_STATUS
965 EFIAPI
966 AtaStorageSecurityReceiveData (
967 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
968 IN UINT32 MediaId,
969 IN UINT64 Timeout,
970 IN UINT8 SecurityProtocolId,
971 IN UINT16 SecurityProtocolSpecificData,
972 IN UINTN PayloadBufferSize,
973 OUT VOID *PayloadBuffer,
974 OUT UINTN *PayloadTransferSize
975 );
976
977 /**
978 Send a security protocol command to a device.
979
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.
986
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.
989
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.
994
995 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
996 return EFI_INVALID_PARAMETER.
997
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.
1002
1003 If the security protocol fails to complete within the Timeout period, the function
1004 shall return EFI_TIMEOUT.
1005
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.
1009
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
1026 protocol command.
1027
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.
1036
1037 **/
1038 EFI_STATUS
1039 EFIAPI
1040 AtaStorageSecuritySendData (
1041 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
1042 IN UINT32 MediaId,
1043 IN UINT64 Timeout,
1044 IN UINT8 SecurityProtocolId,
1045 IN UINT16 SecurityProtocolSpecificData,
1046 IN UINTN PayloadBufferSize,
1047 IN VOID *PayloadBuffer
1048 );
1049
1050 /**
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.
1057
1058 @param[in] AtaDevice ATA_DEVICE pointer.
1059
1060 **/
1061 VOID
1062 InitiateTPerReset (
1063 IN ATA_DEVICE *AtaDevice
1064 );
1065
1066 #endif