]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h
MdeModulePkg/AtaBus&AtaAtapiPassThru: Update ATA drivers to follow UEFI2.4 new reques...
[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 - 2013, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #ifndef _ATA_BUS_H_
19 #define _ATA_BUS_H_
20
21 #include <Uefi.h>
22
23 #include <Guid/MemoryOverwriteControl.h>
24 #include <Protocol/AtaPassThru.h>
25 #include <Protocol/BlockIo.h>
26 #include <Protocol/BlockIo2.h>
27 #include <Protocol/DiskInfo.h>
28 #include <Protocol/DevicePath.h>
29 #include <Protocol/StorageSecurityCommand.h>
30
31 #include <Library/DebugLib.h>
32 #include <Library/UefiDriverEntryPoint.h>
33 #include <Library/BaseLib.h>
34 #include <Library/UefiLib.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Library/UefiBootServicesTableLib.h>
38 #include <Library/DevicePathLib.h>
39 #include <Library/UefiRuntimeServicesTableLib.h>
40 #include <Library/TimerLib.h>
41 #include <Library/ReportStatusCodeLib.h>
42
43 #include <IndustryStandard/Atapi.h>
44
45 //
46 // Time out value for ATA pass through protocol
47 //
48 #define ATA_TIMEOUT EFI_TIMER_PERIOD_SECONDS (3)
49
50 //
51 // Maximum number of times to retry ATA command
52 //
53 #define MAX_RETRY_TIMES 3
54
55 //
56 // The maximum total sectors count in 28 bit addressing mode
57 //
58 #define MAX_28BIT_ADDRESSING_CAPACITY 0xfffffff
59
60 //
61 // The maximum ATA transaction sector count in 28 bit addressing mode.
62 //
63 #define MAX_28BIT_TRANSFER_BLOCK_NUM 0x100
64
65 //
66 // The maximum ATA transaction sector count in 48 bit addressing mode.
67 //
68 //#define MAX_48BIT_TRANSFER_BLOCK_NUM 0x10000
69
70 //
71 // BugBug: if the TransferLength is equal with 0x10000 (the 48bit max length),
72 // there is a bug that even the register interrupt bit has been sit, the buffer
73 // seems not ready. Change the Maximum Sector Numbers to 0xFFFF to work round
74 // this issue.
75 //
76 #define MAX_48BIT_TRANSFER_BLOCK_NUM 0xFFFF
77
78 //
79 // The maximum model name in ATA identify data
80 //
81 #define MAX_MODEL_NAME_LEN 40
82
83 #define ATA_TASK_SIGNATURE SIGNATURE_32 ('A', 'T', 'S', 'K')
84 #define ATA_DEVICE_SIGNATURE SIGNATURE_32 ('A', 'B', 'I', 'D')
85 #define ATA_SUB_TASK_SIGNATURE SIGNATURE_32 ('A', 'S', 'T', 'S')
86 #define IS_ALIGNED(addr, size) (((UINTN) (addr) & (size - 1)) == 0)
87
88 #define ROUNDUP512(x) (((x) % 512 == 0) ? (x) : ((x) / 512 + 1) * 512)
89
90 #define SECURITY_PROTOCOL_TCG 0x02
91 #define SECURITY_PROTOCOL_IEEE1667 0xEE
92
93 //
94 // ATA Supported Security Protocols List Description.
95 // Refer to ATA8-ACS Spec 7.57.6.2 Table 69.
96 //
97 typedef struct {
98 UINT8 Reserved1[6];
99 UINT8 SupportedSecurityListLength[2];
100 UINT8 SupportedSecurityProtocol[1];
101 } SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA;
102
103 //
104 // ATA bus data structure for ATA controller
105 //
106 typedef struct {
107 EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
108 EFI_HANDLE Controller;
109 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
110 EFI_HANDLE DriverBindingHandle;
111 } ATA_BUS_DRIVER_DATA;
112
113 //
114 // ATA device data structure for each child device
115 //
116 typedef struct {
117 UINT32 Signature;
118
119 EFI_HANDLE Handle;
120 EFI_BLOCK_IO_PROTOCOL BlockIo;
121 EFI_BLOCK_IO2_PROTOCOL BlockIo2;
122 EFI_BLOCK_IO_MEDIA BlockMedia;
123 EFI_DISK_INFO_PROTOCOL DiskInfo;
124 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
125 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL StorageSecurity;
126
127 ATA_BUS_DRIVER_DATA *AtaBusDriverData;
128 UINT16 Port;
129 UINT16 PortMultiplierPort;
130
131 //
132 // Buffer for the execution of ATA pass through protocol
133 //
134 EFI_ATA_PASS_THRU_COMMAND_PACKET Packet;
135 EFI_ATA_COMMAND_BLOCK Acb;
136 EFI_ATA_STATUS_BLOCK *Asb;
137
138 BOOLEAN UdmaValid;
139 BOOLEAN Lba48Bit;
140
141 //
142 // Cached data for ATA identify data
143 //
144 ATA_IDENTIFY_DATA *IdentifyData;
145
146 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
147 CHAR16 ModelName[MAX_MODEL_NAME_LEN + 1];
148
149 LIST_ENTRY AtaTaskList;
150 LIST_ENTRY AtaSubTaskList;
151 BOOLEAN Abort;
152 } ATA_DEVICE;
153
154 //
155 // Sub-Task for the non blocking I/O
156 //
157 typedef struct {
158 UINT32 Signature;
159 ATA_DEVICE *AtaDevice;
160 EFI_BLOCK_IO2_TOKEN *Token;
161 UINTN *UnsignalledEventCount;
162 EFI_ATA_PASS_THRU_COMMAND_PACKET Packet;
163 BOOLEAN *IsError;// Indicate whether meeting error during source allocation for new task.
164 LIST_ENTRY TaskEntry;
165 } ATA_BUS_ASYN_SUB_TASK;
166
167 //
168 // Task for the non blocking I/O
169 //
170 typedef struct {
171 UINT32 Signature;
172 EFI_BLOCK_IO2_TOKEN *Token;
173 ATA_DEVICE *AtaDevice;
174 UINT8 *Buffer;
175 EFI_LBA StartLba;
176 UINTN NumberOfBlocks;
177 BOOLEAN IsWrite;
178 LIST_ENTRY TaskEntry;
179 } ATA_BUS_ASYN_TASK;
180
181 #define ATA_DEVICE_FROM_BLOCK_IO(a) CR (a, ATA_DEVICE, BlockIo, ATA_DEVICE_SIGNATURE)
182 #define ATA_DEVICE_FROM_BLOCK_IO2(a) CR (a, ATA_DEVICE, BlockIo2, ATA_DEVICE_SIGNATURE)
183 #define ATA_DEVICE_FROM_DISK_INFO(a) CR (a, ATA_DEVICE, DiskInfo, ATA_DEVICE_SIGNATURE)
184 #define ATA_DEVICE_FROM_STORAGE_SECURITY(a) CR (a, ATA_DEVICE, StorageSecurity, ATA_DEVICE_SIGNATURE)
185 #define ATA_ASYN_SUB_TASK_FROM_ENTRY(a) CR (a, ATA_BUS_ASYN_SUB_TASK, TaskEntry, ATA_SUB_TASK_SIGNATURE)
186 #define ATA_ASYN_TASK_FROM_ENTRY(a) CR (a, ATA_BUS_ASYN_TASK, TaskEntry, ATA_TASK_SIGNATURE)
187
188 //
189 // Global Variables
190 //
191 extern EFI_DRIVER_BINDING_PROTOCOL gAtaBusDriverBinding;
192 extern EFI_COMPONENT_NAME_PROTOCOL gAtaBusComponentName;
193 extern EFI_COMPONENT_NAME2_PROTOCOL gAtaBusComponentName2;
194
195 /**
196 Allocates an aligned buffer for ATA device.
197
198 This function allocates an aligned buffer for the ATA device to perform
199 ATA pass through operations. The alignment requirement is from ATA pass
200 through interface.
201
202 @param AtaDevice The ATA child device involved for the operation.
203 @param BufferSize The request buffer size.
204
205 @return A pointer to the aligned buffer or NULL if the allocation fails.
206
207 **/
208 VOID *
209 AllocateAlignedBuffer (
210 IN ATA_DEVICE *AtaDevice,
211 IN UINTN BufferSize
212 );
213
214 /**
215 Frees an aligned buffer for ATA device.
216
217 This function frees an aligned buffer for the ATA device to perform
218 ATA pass through operations.
219
220 @param Buffer The aligned buffer to be freed.
221 @param BufferSize The request buffer size.
222
223 **/
224 VOID
225 FreeAlignedBuffer (
226 IN VOID *Buffer,
227 IN UINTN BufferSize
228 );
229
230 /**
231 Free SubTask.
232
233 @param[in, out] Task Pointer to task to be freed.
234
235 **/
236 VOID
237 EFIAPI
238 FreeAtaSubTask (
239 IN OUT ATA_BUS_ASYN_SUB_TASK *Task
240 );
241
242 /**
243 Wrapper for EFI_ATA_PASS_THRU_PROTOCOL.ResetDevice().
244
245 This function wraps the ResetDevice() invocation for ATA pass through function
246 for an ATA device.
247
248 @param AtaDevice The ATA child device involved for the operation.
249
250 @return The return status from EFI_ATA_PASS_THRU_PROTOCOL.PassThru().
251
252 **/
253 EFI_STATUS
254 ResetAtaDevice (
255 IN ATA_DEVICE *AtaDevice
256 );
257
258
259 /**
260 Discovers whether it is a valid ATA device.
261
262 This function issues ATA_CMD_IDENTIFY_DRIVE command to the ATA device to identify it.
263 If the command is executed successfully, it then identifies it and initializes
264 the Media information in Block IO protocol interface.
265
266 @param AtaDevice The ATA child device involved for the operation.
267
268 @retval EFI_SUCCESS The device is successfully identified and Media information
269 is correctly initialized.
270 @return others Some error occurs when discovering the ATA device.
271
272 **/
273 EFI_STATUS
274 DiscoverAtaDevice (
275 IN OUT ATA_DEVICE *AtaDevice
276 );
277
278 /**
279 Read or write a number of blocks from ATA device.
280
281 This function performs ATA pass through transactions to read/write data from/to
282 ATA device. It may separate the read/write request into several ATA pass through
283 transactions.
284
285 @param[in, out] AtaDevice The ATA child device involved for the operation.
286 @param[in, out] Buffer The pointer to the current transaction buffer.
287 @param[in] StartLba The starting logical block address to be accessed.
288 @param[in] NumberOfBlocks The block number or sector count of the transfer.
289 @param[in] IsWrite Indicates whether it is a write operation.
290 @param[in, out] Token A pointer to the token associated with the transaction.
291
292 @retval EFI_SUCCESS The data transfer is complete successfully.
293 @return others Some error occurs when transferring data.
294
295 **/
296 EFI_STATUS
297 AccessAtaDevice(
298 IN OUT ATA_DEVICE *AtaDevice,
299 IN OUT UINT8 *Buffer,
300 IN EFI_LBA StartLba,
301 IN UINTN NumberOfBlocks,
302 IN BOOLEAN IsWrite,
303 IN OUT EFI_BLOCK_IO2_TOKEN *Token
304 );
305
306 /**
307 Trust transfer data from/to ATA device.
308
309 This function performs one ATA pass through transaction to do a trust transfer from/to
310 ATA device. It chooses the appropriate ATA command and protocol to invoke PassThru
311 interface of ATA pass through.
312
313 @param AtaDevice The ATA child device involved for the operation.
314 @param Buffer The pointer to the current transaction buffer.
315 @param SecurityProtocolId The value of the "Security Protocol" parameter of
316 the security protocol command to be sent.
317 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
318 of the security protocol command to be sent.
319 @param TransferLength The block number or sector count of the transfer.
320 @param IsTrustSend Indicates whether it is a trust send operation or not.
321 @param Timeout The timeout, in 100ns units, to use for the execution
322 of the security protocol command. A Timeout value of 0
323 means that this function will wait indefinitely for the
324 security protocol command to execute. If Timeout is greater
325 than zero, then this function will return EFI_TIMEOUT
326 if the time required to execute the receive data command
327 is greater than Timeout.
328 @param TransferLengthOut A pointer to a buffer to store the size in bytes of the data
329 written to the buffer. Ignore it when IsTrustSend is TRUE.
330
331 @retval EFI_SUCCESS The data transfer is complete successfully.
332 @return others Some error occurs when transferring data.
333
334 **/
335 EFI_STATUS
336 EFIAPI
337 TrustTransferAtaDevice (
338 IN OUT ATA_DEVICE *AtaDevice,
339 IN OUT VOID *Buffer,
340 IN UINT8 SecurityProtocolId,
341 IN UINT16 SecurityProtocolSpecificData,
342 IN UINTN TransferLength,
343 IN BOOLEAN IsTrustSend,
344 IN UINT64 Timeout,
345 OUT UINTN *TransferLengthOut
346 );
347
348 //
349 // Protocol interface prototypes
350 //
351 /**
352 Tests to see if this driver supports a given controller. If a child device is provided,
353 it further tests to see if this driver supports creating a handle for the specified child device.
354
355 This function checks to see if the driver specified by This supports the device specified by
356 ControllerHandle. Drivers will typically use the device path attached to
357 ControllerHandle and/or the services from the bus I/O abstraction attached to
358 ControllerHandle to determine if the driver supports ControllerHandle. This function
359 may be called many times during platform initialization. In order to reduce boot times, the tests
360 performed by this function must be very small, and take as little time as possible to execute. This
361 function must not change the state of any hardware devices, and this function must be aware that the
362 device specified by ControllerHandle may already be managed by the same driver or a
363 different driver. This function must match its calls to AllocatePages() with FreePages(),
364 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
365 Since ControllerHandle may have been previously started by the same driver, if a protocol is
366 already in the opened state, then it must not be closed with CloseProtocol(). This is required
367 to guarantee the state of ControllerHandle is not modified by this function.
368
369 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
370 @param[in] ControllerHandle The handle of the controller to test. This handle
371 must support a protocol interface that supplies
372 an I/O abstraction to the driver.
373 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
374 parameter is ignored by device drivers, and is optional for bus
375 drivers. For bus drivers, if this parameter is not NULL, then
376 the bus driver must determine if the bus controller specified
377 by ControllerHandle and the child controller specified
378 by RemainingDevicePath are both supported by this
379 bus driver.
380
381 @retval EFI_SUCCESS The device specified by ControllerHandle and
382 RemainingDevicePath is supported by the driver specified by This.
383 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
384 RemainingDevicePath is already being managed by the driver
385 specified by This.
386 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
387 RemainingDevicePath is already being managed by a different
388 driver or an application that requires exclusive access.
389 Currently not implemented.
390 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
391 RemainingDevicePath is not supported by the driver specified by This.
392 **/
393 EFI_STATUS
394 EFIAPI
395 AtaBusDriverBindingSupported (
396 IN EFI_DRIVER_BINDING_PROTOCOL *This,
397 IN EFI_HANDLE Controller,
398 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
399 );
400
401 /**
402 Starts a device controller or a bus controller.
403
404 The Start() function is designed to be invoked from the EFI boot service ConnectController().
405 As a result, much of the error checking on the parameters to Start() has been moved into this
406 common boot service. It is legal to call Start() from other locations,
407 but the following calling restrictions must be followed or the system behavior will not be deterministic.
408 1. ControllerHandle must be a valid EFI_HANDLE.
409 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
410 EFI_DEVICE_PATH_PROTOCOL.
411 3. Prior to calling Start(), the Supported() function for the driver specified by This must
412 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
413
414 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
415 @param[in] ControllerHandle The handle of the controller to start. This handle
416 must support a protocol interface that supplies
417 an I/O abstraction to the driver.
418 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
419 parameter is ignored by device drivers, and is optional for bus
420 drivers. For a bus driver, if this parameter is NULL, then handles
421 for all the children of Controller are created by this driver.
422 If this parameter is not NULL and the first Device Path Node is
423 not the End of Device Path Node, then only the handle for the
424 child device specified by the first Device Path Node of
425 RemainingDevicePath is created by this driver.
426 If the first Device Path Node of RemainingDevicePath is
427 the End of Device Path Node, no child handle is created by this
428 driver.
429
430 @retval EFI_SUCCESS The device was started.
431 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
432 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
433 @retval Others The driver failded to start the device.
434
435 **/
436 EFI_STATUS
437 EFIAPI
438 AtaBusDriverBindingStart (
439 IN EFI_DRIVER_BINDING_PROTOCOL *This,
440 IN EFI_HANDLE Controller,
441 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
442 );
443
444 /**
445 Stops a device controller or a bus controller.
446
447 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
448 As a result, much of the error checking on the parameters to Stop() has been moved
449 into this common boot service. It is legal to call Stop() from other locations,
450 but the following calling restrictions must be followed or the system behavior will not be deterministic.
451 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
452 same driver's Start() function.
453 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
454 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
455 Start() function, and the Start() function must have called OpenProtocol() on
456 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
457
458 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
459 @param[in] ControllerHandle A handle to the device being stopped. The handle must
460 support a bus specific I/O protocol for the driver
461 to use to stop the device.
462 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
463 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
464 if NumberOfChildren is 0.
465
466 @retval EFI_SUCCESS The device was stopped.
467 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
468
469 **/
470 EFI_STATUS
471 EFIAPI
472 AtaBusDriverBindingStop (
473 IN EFI_DRIVER_BINDING_PROTOCOL *This,
474 IN EFI_HANDLE Controller,
475 IN UINTN NumberOfChildren,
476 IN EFI_HANDLE *ChildHandleBuffer
477 );
478
479
480 /**
481 Retrieves a Unicode string that is the user readable name of the driver.
482
483 This function retrieves the user readable name of a driver in the form of a
484 Unicode string. If the driver specified by This has a user readable name in
485 the language specified by Language, then a pointer to the driver name is
486 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
487 by This does not support the language specified by Language,
488 then EFI_UNSUPPORTED is returned.
489
490 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
491 EFI_COMPONENT_NAME_PROTOCOL instance.
492
493 @param Language[in] A pointer to a Null-terminated ASCII string
494 array indicating the language. This is the
495 language of the driver name that the caller is
496 requesting, and it must match one of the
497 languages specified in SupportedLanguages. The
498 number of languages supported by a driver is up
499 to the driver writer. Language is specified
500 in RFC 4646 or ISO 639-2 language code format.
501
502 @param DriverName[out] A pointer to the Unicode string to return.
503 This Unicode string is the name of the
504 driver specified by This in the language
505 specified by Language.
506
507 @retval EFI_SUCCESS The Unicode string for the Driver specified by
508 This and the language specified by Language was
509 returned in DriverName.
510
511 @retval EFI_INVALID_PARAMETER Language is NULL.
512
513 @retval EFI_INVALID_PARAMETER DriverName is NULL.
514
515 @retval EFI_UNSUPPORTED The driver specified by This does not support
516 the language specified by Language.
517
518 **/
519 EFI_STATUS
520 EFIAPI
521 AtaBusComponentNameGetDriverName (
522 IN EFI_COMPONENT_NAME_PROTOCOL *This,
523 IN CHAR8 *Language,
524 OUT CHAR16 **DriverName
525 );
526
527
528 /**
529 Retrieves a Unicode string that is the user readable name of the controller
530 that is being managed by a driver.
531
532 This function retrieves the user readable name of the controller specified by
533 ControllerHandle and ChildHandle in the form of a Unicode string. If the
534 driver specified by This has a user readable name in the language specified by
535 Language, then a pointer to the controller name is returned in ControllerName,
536 and EFI_SUCCESS is returned. If the driver specified by This is not currently
537 managing the controller specified by ControllerHandle and ChildHandle,
538 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
539 support the language specified by Language, then EFI_UNSUPPORTED is returned.
540
541 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
542 EFI_COMPONENT_NAME_PROTOCOL instance.
543
544 @param ControllerHandle[in] The handle of a controller that the driver
545 specified by This is managing. This handle
546 specifies the controller whose name is to be
547 returned.
548
549 @param ChildHandle[in] The handle of the child controller to retrieve
550 the name of. This is an optional parameter that
551 may be NULL. It will be NULL for device
552 drivers. It will also be NULL for a bus drivers
553 that wish to retrieve the name of the bus
554 controller. It will not be NULL for a bus
555 driver that wishes to retrieve the name of a
556 child controller.
557
558 @param Language[in] A pointer to a Null-terminated ASCII string
559 array indicating the language. This is the
560 language of the driver name that the caller is
561 requesting, and it must match one of the
562 languages specified in SupportedLanguages. The
563 number of languages supported by a driver is up
564 to the driver writer. Language is specified in
565 RFC 4646 or ISO 639-2 language code format.
566
567 @param ControllerName[out] A pointer to the Unicode string to return.
568 This Unicode string is the name of the
569 controller specified by ControllerHandle and
570 ChildHandle in the language specified by
571 Language from the point of view of the driver
572 specified by This.
573
574 @retval EFI_SUCCESS The Unicode string for the user readable name in
575 the language specified by Language for the
576 driver specified by This was returned in
577 DriverName.
578
579 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
580
581 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
582 EFI_HANDLE.
583
584 @retval EFI_INVALID_PARAMETER Language is NULL.
585
586 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
587
588 @retval EFI_UNSUPPORTED The driver specified by This is not currently
589 managing the controller specified by
590 ControllerHandle and ChildHandle.
591
592 @retval EFI_UNSUPPORTED The driver specified by This does not support
593 the language specified by Language.
594
595 **/
596 EFI_STATUS
597 EFIAPI
598 AtaBusComponentNameGetControllerName (
599 IN EFI_COMPONENT_NAME_PROTOCOL *This,
600 IN EFI_HANDLE ControllerHandle,
601 IN EFI_HANDLE ChildHandle OPTIONAL,
602 IN CHAR8 *Language,
603 OUT CHAR16 **ControllerName
604 );
605
606
607 /**
608 Reset the Block Device.
609
610 @param This Indicates a pointer to the calling context.
611 @param ExtendedVerification Driver may perform diagnostics on reset.
612
613 @retval EFI_SUCCESS The device was reset.
614 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
615 not be reset.
616
617 **/
618 EFI_STATUS
619 EFIAPI
620 AtaBlockIoReset (
621 IN EFI_BLOCK_IO_PROTOCOL *This,
622 IN BOOLEAN ExtendedVerification
623 );
624
625
626 /**
627 Read BufferSize bytes from Lba into Buffer.
628
629 @param This Indicates a pointer to the calling context.
630 @param MediaId Id of the media, changes every time the media is replaced.
631 @param Lba The starting Logical Block Address to read from
632 @param BufferSize Size of Buffer, must be a multiple of device block size.
633 @param Buffer A pointer to the destination buffer for the data. The caller is
634 responsible for either having implicit or explicit ownership of the buffer.
635
636 @retval EFI_SUCCESS The data was read correctly from the device.
637 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
638 @retval EFI_NO_MEDIA There is no media in the device.
639 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
640 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
641 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
642 or the buffer is not on proper alignment.
643
644 **/
645 EFI_STATUS
646 EFIAPI
647 AtaBlockIoReadBlocks (
648 IN EFI_BLOCK_IO_PROTOCOL *This,
649 IN UINT32 MediaId,
650 IN EFI_LBA Lba,
651 IN UINTN BufferSize,
652 OUT VOID *Buffer
653 );
654
655
656 /**
657 Write BufferSize bytes from Lba into Buffer.
658
659 @param This Indicates a pointer to the calling context.
660 @param MediaId The media ID that the write request is for.
661 @param Lba The starting logical block address to be written. The caller is
662 responsible for writing to only legitimate locations.
663 @param BufferSize Size of Buffer, must be a multiple of device block size.
664 @param Buffer A pointer to the source buffer for the data.
665
666 @retval EFI_SUCCESS The data was written correctly to the device.
667 @retval EFI_WRITE_PROTECTED The device can not be written to.
668 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
669 @retval EFI_NO_MEDIA There is no media in the device.
670 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
671 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
672 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
673 or the buffer is not on proper alignment.
674
675 **/
676 EFI_STATUS
677 EFIAPI
678 AtaBlockIoWriteBlocks (
679 IN EFI_BLOCK_IO_PROTOCOL *This,
680 IN UINT32 MediaId,
681 IN EFI_LBA Lba,
682 IN UINTN BufferSize,
683 IN VOID *Buffer
684 );
685
686
687 /**
688 Flush the Block Device.
689
690 @param This Indicates a pointer to the calling context.
691
692 @retval EFI_SUCCESS All outstanding data was written to the device
693 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
694 @retval EFI_NO_MEDIA There is no media in the device.
695
696 **/
697 EFI_STATUS
698 EFIAPI
699 AtaBlockIoFlushBlocks (
700 IN EFI_BLOCK_IO_PROTOCOL *This
701 );
702
703 /**
704 Reset the Block Device throught Block I/O2 protocol.
705
706 @param[in] This Indicates a pointer to the calling context.
707 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
708
709 @retval EFI_SUCCESS The device was reset.
710 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
711 not be reset.
712
713 **/
714 EFI_STATUS
715 EFIAPI
716 AtaBlockIoResetEx (
717 IN EFI_BLOCK_IO2_PROTOCOL *This,
718 IN BOOLEAN ExtendedVerification
719 );
720
721 /**
722 Read BufferSize bytes from Lba into Buffer.
723
724 @param[in] This Indicates a pointer to the calling context.
725 @param[in] MediaId Id of the media, changes every time the media is replaced.
726 @param[in] Lba The starting Logical Block Address to read from.
727 @param[in, out] Token A pointer to the token associated with the transaction.
728 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
729 @param[out] Buffer A pointer to the destination buffer for the data. The caller is
730 responsible for either having implicit or explicit ownership of the buffer.
731
732 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
733 The data was read correctly from the device if
734 the Event is NULL.
735 @retval EFI_DEVICE_ERROR The device reported an error while performing
736 the read.
737 @retval EFI_NO_MEDIA There is no media in the device.
738 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
739 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
740 intrinsic block size of the device.
741 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
742 or the buffer is not on proper alignment.
743 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
744 of resources.
745
746 **/
747 EFI_STATUS
748 EFIAPI
749 AtaBlockIoReadBlocksEx (
750 IN EFI_BLOCK_IO2_PROTOCOL *This,
751 IN UINT32 MediaId,
752 IN EFI_LBA Lba,
753 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
754 IN UINTN BufferSize,
755 OUT VOID *Buffer
756 );
757
758 /**
759 Write BufferSize bytes from Lba into Buffer.
760
761 @param[in] This Indicates a pointer to the calling context.
762 @param[in] MediaId The media ID that the write request is for.
763 @param[in] Lba The starting logical block address to be written. The
764 caller is responsible for writing to only legitimate
765 locations.
766 @param[in, out] Token A pointer to the token associated with the transaction.
767 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
768 @param[in] Buffer A pointer to the source buffer for the data.
769
770 @retval EFI_SUCCESS The data was written correctly to the device.
771 @retval EFI_WRITE_PROTECTED The device can not be written to.
772 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
773 @retval EFI_NO_MEDIA There is no media in the device.
774 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
775 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
776 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
777 or the buffer is not on proper alignment.
778
779 **/
780 EFI_STATUS
781 EFIAPI
782 AtaBlockIoWriteBlocksEx (
783 IN EFI_BLOCK_IO2_PROTOCOL *This,
784 IN UINT32 MediaId,
785 IN EFI_LBA Lba,
786 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
787 IN UINTN BufferSize,
788 IN VOID *Buffer
789 );
790
791 /**
792 Flush the Block Device.
793
794 @param[in] This Indicates a pointer to the calling context.
795 @param[in, out] Token A pointer to the token associated with the transaction.
796
797 @retval EFI_SUCCESS All outstanding data was written to the device
798 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
799 @retval EFI_NO_MEDIA There is no media in the device.
800
801 **/
802 EFI_STATUS
803 EFIAPI
804 AtaBlockIoFlushBlocksEx (
805 IN EFI_BLOCK_IO2_PROTOCOL *This,
806 IN OUT EFI_BLOCK_IO2_TOKEN *Token
807 );
808
809 /**
810 Terminate any in-flight non-blocking I/O requests by signaling an EFI_ABORTED
811 in the TransactionStatus member of the EFI_BLOCK_IO2_TOKEN for the non-blocking
812 I/O. After that it is safe to free any Token or Buffer data structures that
813 were allocated to initiate the non-blockingI/O requests that were in-flight for
814 this device.
815
816 @param[in] AtaDevice The ATA child device involved for the operation.
817
818 **/
819 VOID
820 EFIAPI
821 AtaTerminateNonBlockingTask (
822 IN ATA_DEVICE *AtaDevice
823 );
824
825 /**
826 Provides inquiry information for the controller type.
827
828 This function is used by the IDE bus driver to get inquiry data. Data format
829 of Identify data is defined by the Interface GUID.
830
831 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
832 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
833 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
834
835 @retval EFI_SUCCESS The command was accepted without any errors.
836 @retval EFI_NOT_FOUND Device does not support this data class
837 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
838 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
839
840 **/
841 EFI_STATUS
842 EFIAPI
843 AtaDiskInfoInquiry (
844 IN EFI_DISK_INFO_PROTOCOL *This,
845 IN OUT VOID *InquiryData,
846 IN OUT UINT32 *InquiryDataSize
847 );
848
849
850 /**
851 Provides identify information for the controller type.
852
853 This function is used by the IDE bus driver to get identify data. Data format
854 of Identify data is defined by the Interface GUID.
855
856 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
857 instance.
858 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
859 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
860 size.
861
862 @retval EFI_SUCCESS The command was accepted without any errors.
863 @retval EFI_NOT_FOUND Device does not support this data class
864 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
865 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
866
867 **/
868 EFI_STATUS
869 EFIAPI
870 AtaDiskInfoIdentify (
871 IN EFI_DISK_INFO_PROTOCOL *This,
872 IN OUT VOID *IdentifyData,
873 IN OUT UINT32 *IdentifyDataSize
874 );
875
876
877 /**
878 Provides sense data information for the controller type.
879
880 This function is used by the IDE bus driver to get sense data.
881 Data format of Sense data is defined by the Interface GUID.
882
883 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
884 @param[in, out] SenseData Pointer to the SenseData.
885 @param[in, out] SenseDataSize Size of SenseData in bytes.
886 @param[out] SenseDataNumber Pointer to the value for the sense data size.
887
888 @retval EFI_SUCCESS The command was accepted without any errors.
889 @retval EFI_NOT_FOUND Device does not support this data class.
890 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
891 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
892
893 **/
894 EFI_STATUS
895 EFIAPI
896 AtaDiskInfoSenseData (
897 IN EFI_DISK_INFO_PROTOCOL *This,
898 IN OUT VOID *SenseData,
899 IN OUT UINT32 *SenseDataSize,
900 OUT UINT8 *SenseDataNumber
901 );
902
903
904 /**
905 This function is used by the IDE bus driver to get controller information.
906
907 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
908 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
909 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
910
911 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
912 @retval EFI_UNSUPPORTED This is not an IDE device.
913
914 **/
915 EFI_STATUS
916 EFIAPI
917 AtaDiskInfoWhichIde (
918 IN EFI_DISK_INFO_PROTOCOL *This,
919 OUT UINT32 *IdeChannel,
920 OUT UINT32 *IdeDevice
921 );
922
923 /**
924 Send a security protocol command to a device that receives data and/or the result
925 of one or more commands sent by SendData.
926
927 The ReceiveData function sends a security protocol command to the given MediaId.
928 The security protocol command sent is defined by SecurityProtocolId and contains
929 the security protocol specific data SecurityProtocolSpecificData. The function
930 returns the data from the security protocol command in PayloadBuffer.
931
932 For devices supporting the SCSI command set, the security protocol command is sent
933 using the SECURITY PROTOCOL IN command defined in SPC-4.
934
935 For devices supporting the ATA command set, the security protocol command is sent
936 using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize
937 is non-zero.
938
939 If the PayloadBufferSize is zero, the security protocol command is sent using the
940 Trusted Non-Data command defined in ATA8-ACS.
941
942 If PayloadBufferSize is too small to store the available data from the security
943 protocol command, the function shall copy PayloadBufferSize bytes into the
944 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
945
946 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
947 the function shall return EFI_INVALID_PARAMETER.
948
949 If the given MediaId does not support security protocol commands, the function shall
950 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
951 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
952 the function returns EFI_MEDIA_CHANGED.
953
954 If the security protocol fails to complete within the Timeout period, the function
955 shall return EFI_TIMEOUT.
956
957 If the security protocol command completes without an error, the function shall
958 return EFI_SUCCESS. If the security protocol command completes with an error, the
959 function shall return EFI_DEVICE_ERROR.
960
961 @param This Indicates a pointer to the calling context.
962 @param MediaId ID of the medium to receive data from.
963 @param Timeout The timeout, in 100ns units, to use for the execution
964 of the security protocol command. A Timeout value of 0
965 means that this function will wait indefinitely for the
966 security protocol command to execute. If Timeout is greater
967 than zero, then this function will return EFI_TIMEOUT
968 if the time required to execute the receive data command
969 is greater than Timeout.
970 @param SecurityProtocolId The value of the "Security Protocol" parameter of
971 the security protocol command to be sent.
972 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
973 of the security protocol command to be sent.
974 @param PayloadBufferSize Size in bytes of the payload data buffer.
975 @param PayloadBuffer A pointer to a destination buffer to store the security
976 protocol command specific payload data for the security
977 protocol command. The caller is responsible for having
978 either implicit or explicit ownership of the buffer.
979 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
980 data written to the payload data buffer.
981
982 @retval EFI_SUCCESS The security protocol command completed successfully.
983 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
984 data from the device. The PayloadBuffer contains the truncated data.
985 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
986 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
987 @retval EFI_NO_MEDIA There is no media in the device.
988 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
989 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
990 PayloadBufferSize is non-zero.
991 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
992 protocol command to execute.
993
994 **/
995 EFI_STATUS
996 EFIAPI
997 AtaStorageSecurityReceiveData (
998 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
999 IN UINT32 MediaId,
1000 IN UINT64 Timeout,
1001 IN UINT8 SecurityProtocolId,
1002 IN UINT16 SecurityProtocolSpecificData,
1003 IN UINTN PayloadBufferSize,
1004 OUT VOID *PayloadBuffer,
1005 OUT UINTN *PayloadTransferSize
1006 );
1007
1008 /**
1009 Send a security protocol command to a device.
1010
1011 The SendData function sends a security protocol command containing the payload
1012 PayloadBuffer to the given MediaId. The security protocol command sent is
1013 defined by SecurityProtocolId and contains the security protocol specific data
1014 SecurityProtocolSpecificData. If the underlying protocol command requires a
1015 specific padding for the command payload, the SendData function shall add padding
1016 bytes to the command payload to satisfy the padding requirements.
1017
1018 For devices supporting the SCSI command set, the security protocol command is sent
1019 using the SECURITY PROTOCOL OUT command defined in SPC-4.
1020
1021 For devices supporting the ATA command set, the security protocol command is sent
1022 using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize
1023 is non-zero. If the PayloadBufferSize is zero, the security protocol command is
1024 sent using the Trusted Non-Data command defined in ATA8-ACS.
1025
1026 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
1027 return EFI_INVALID_PARAMETER.
1028
1029 If the given MediaId does not support security protocol commands, the function
1030 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
1031 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
1032 device, the function returns EFI_MEDIA_CHANGED.
1033
1034 If the security protocol fails to complete within the Timeout period, the function
1035 shall return EFI_TIMEOUT.
1036
1037 If the security protocol command completes without an error, the function shall return
1038 EFI_SUCCESS. If the security protocol command completes with an error, the function
1039 shall return EFI_DEVICE_ERROR.
1040
1041 @param This Indicates a pointer to the calling context.
1042 @param MediaId ID of the medium to receive data from.
1043 @param Timeout The timeout, in 100ns units, to use for the execution
1044 of the security protocol command. A Timeout value of 0
1045 means that this function will wait indefinitely for the
1046 security protocol command to execute. If Timeout is greater
1047 than zero, then this function will return EFI_TIMEOUT
1048 if the time required to execute the receive data command
1049 is greater than Timeout.
1050 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1051 the security protocol command to be sent.
1052 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1053 of the security protocol command to be sent.
1054 @param PayloadBufferSize Size in bytes of the payload data buffer.
1055 @param PayloadBuffer A pointer to a destination buffer to store the security
1056 protocol command specific payload data for the security
1057 protocol command.
1058
1059 @retval EFI_SUCCESS The security protocol command completed successfully.
1060 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1061 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1062 @retval EFI_NO_MEDIA There is no media in the device.
1063 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1064 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
1065 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1066 protocol command to execute.
1067
1068 **/
1069 EFI_STATUS
1070 EFIAPI
1071 AtaStorageSecuritySendData (
1072 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
1073 IN UINT32 MediaId,
1074 IN UINT64 Timeout,
1075 IN UINT8 SecurityProtocolId,
1076 IN UINT16 SecurityProtocolSpecificData,
1077 IN UINTN PayloadBufferSize,
1078 IN VOID *PayloadBuffer
1079 );
1080
1081 /**
1082 Send TPer Reset command to reset eDrive to lock all protected bands.
1083 Typically, there are 2 mechanism for resetting eDrive. They are:
1084 1. TPer Reset through IEEE 1667 protocol.
1085 2. TPer Reset through native TCG protocol.
1086 This routine will detect what protocol the attached eDrive comform to, TCG or
1087 IEEE 1667 protocol. Then send out TPer Reset command separately.
1088
1089 @param[in] AtaDevice ATA_DEVICE pointer.
1090
1091 **/
1092 VOID
1093 InitiateTPerReset (
1094 IN ATA_DEVICE *AtaDevice
1095 );
1096
1097 #endif