]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiDiskDxe / ScsiDisk.h
1 /** @file
2 Header file for SCSI Disk Driver.
3
4 Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef _SCSI_DISK_H_
10 #define _SCSI_DISK_H_
11
12 #include <Uefi.h>
13
14 #include <Protocol/ScsiIo.h>
15 #include <Protocol/ComponentName.h>
16 #include <Protocol/BlockIo.h>
17 #include <Protocol/BlockIo2.h>
18 #include <Protocol/EraseBlock.h>
19 #include <Protocol/DriverBinding.h>
20 #include <Protocol/ScsiPassThruExt.h>
21 #include <Protocol/ScsiPassThru.h>
22 #include <Protocol/DiskInfo.h>
23 #include <Protocol/StorageSecurityCommand.h>
24
25 #include <Library/DebugLib.h>
26 #include <Library/UefiDriverEntryPoint.h>
27 #include <Library/UefiLib.h>
28 #include <Library/BaseMemoryLib.h>
29 #include <Library/MemoryAllocationLib.h>
30 #include <Library/UefiScsiLib.h>
31 #include <Library/UefiBootServicesTableLib.h>
32 #include <Library/DevicePathLib.h>
33
34 #include <IndustryStandard/Scsi.h>
35 #include <IndustryStandard/Atapi.h>
36
37 #define IS_DEVICE_FIXED(a) (a)->FixedDevice ? 1 : 0
38
39 #define IS_ALIGNED(addr, size) (((UINTN) (addr) & (size - 1)) == 0)
40
41 #define UFS_WLUN_RPMB 0xC4
42
43 typedef struct {
44 UINT32 MaxLbaCnt;
45 UINT32 MaxBlkDespCnt;
46 UINT32 GranularityAlignment;
47 } SCSI_UNMAP_PARAM_INFO;
48
49 #define SCSI_DISK_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'd', 'k')
50
51 typedef struct {
52 UINT32 Signature;
53
54 EFI_HANDLE Handle;
55
56 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL StorageSecurity;
57
58 EFI_BLOCK_IO_PROTOCOL BlkIo;
59 EFI_BLOCK_IO2_PROTOCOL BlkIo2;
60 EFI_BLOCK_IO_MEDIA BlkIoMedia;
61 EFI_ERASE_BLOCK_PROTOCOL EraseBlock;
62 EFI_SCSI_IO_PROTOCOL *ScsiIo;
63 UINT8 DeviceType;
64 BOOLEAN FixedDevice;
65 UINT16 Reserved;
66
67 EFI_SCSI_SENSE_DATA *SenseData;
68 UINTN SenseDataNumber;
69 EFI_SCSI_INQUIRY_DATA InquiryData;
70
71 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
72
73 EFI_DISK_INFO_PROTOCOL DiskInfo;
74
75 //
76 // The following fields are only valid for ATAPI/SATA device
77 //
78 UINT32 Channel;
79 UINT32 Device;
80 ATAPI_IDENTIFY_DATA IdentifyData;
81
82 //
83 // Scsi UNMAP command parameters information
84 //
85 SCSI_UNMAP_PARAM_INFO UnmapInfo;
86 BOOLEAN BlockLimitsVpdSupported;
87
88 //
89 // The flag indicates if 16-byte command can be used
90 //
91 BOOLEAN Cdb16Byte;
92
93 //
94 // The queue for asynchronous task requests
95 //
96 LIST_ENTRY AsyncTaskQueue;
97 } SCSI_DISK_DEV;
98
99 #define SCSI_DISK_DEV_FROM_BLKIO(a) CR (a, SCSI_DISK_DEV, BlkIo, SCSI_DISK_DEV_SIGNATURE)
100 #define SCSI_DISK_DEV_FROM_BLKIO2(a) CR (a, SCSI_DISK_DEV, BlkIo2, SCSI_DISK_DEV_SIGNATURE)
101 #define SCSI_DISK_DEV_FROM_ERASEBLK(a) CR (a, SCSI_DISK_DEV, EraseBlock, SCSI_DISK_DEV_SIGNATURE)
102 #define SCSI_DISK_DEV_FROM_STORSEC(a) CR (a, SCSI_DISK_DEV, StorageSecurity, SCSI_DISK_DEV_SIGNATURE)
103
104 #define SCSI_DISK_DEV_FROM_DISKINFO(a) CR (a, SCSI_DISK_DEV, DiskInfo, SCSI_DISK_DEV_SIGNATURE)
105
106 //
107 // Asynchronous I/O request
108 //
109 //
110 // Private data structure for a BlockIo2 request
111 //
112 typedef struct {
113 EFI_BLOCK_IO2_TOKEN *Token;
114 //
115 // The flag indicates if the last Scsi Read/Write sub-task for a BlockIo2
116 // request is sent to device
117 //
118 BOOLEAN LastScsiRW;
119
120 //
121 // The queue for Scsi Read/Write sub-tasks of a BlockIo2 request
122 //
123 LIST_ENTRY ScsiRWQueue;
124
125 LIST_ENTRY Link;
126 } SCSI_BLKIO2_REQUEST;
127
128 //
129 // Private data structure for a SCSI Read/Write request
130 //
131 typedef struct {
132 SCSI_DISK_DEV *ScsiDiskDevice;
133 UINT64 Timeout;
134 EFI_SCSI_SENSE_DATA *SenseData;
135 UINT8 SenseDataLength;
136 UINT8 HostAdapterStatus;
137 UINT8 TargetStatus;
138 UINT8 *InBuffer;
139 UINT8 *OutBuffer;
140 UINT32 DataLength;
141 UINT64 StartLba;
142 UINT32 SectorCount;
143 UINT8 TimesRetry;
144
145 //
146 // The BlockIo2 request this SCSI command belongs to
147 //
148 SCSI_BLKIO2_REQUEST *BlkIo2Req;
149
150 LIST_ENTRY Link;
151 } SCSI_ASYNC_RW_REQUEST;
152
153 //
154 // Private data structure for an EraseBlock request
155 //
156 typedef struct {
157 EFI_ERASE_BLOCK_TOKEN *Token;
158
159 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
160
161 LIST_ENTRY Link;
162 } SCSI_ERASEBLK_REQUEST;
163
164 //
165 // Global Variables
166 //
167 extern EFI_DRIVER_BINDING_PROTOCOL gScsiDiskDriverBinding;
168 extern EFI_COMPONENT_NAME_PROTOCOL gScsiDiskComponentName;
169 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiDiskComponentName2;
170 //
171 // action code used in detect media process
172 //
173 #define ACTION_NO_ACTION 0x00
174 #define ACTION_READ_CAPACITY 0x01
175 #define ACTION_RETRY_COMMAND_LATER 0x02
176 #define ACTION_RETRY_WITH_BACKOFF_ALGO 0x03
177
178 #define SCSI_COMMAND_VERSION_1 0x01
179 #define SCSI_COMMAND_VERSION_2 0x02
180 #define SCSI_COMMAND_VERSION_3 0x03
181
182 //
183 // SCSI Disk Timeout Experience Value
184 //
185 // As ScsiDisk and ScsiBus driver are used to manage SCSI or ATAPI devices, the timeout
186 // value is updated to 30s to follow ATA/ATAPI spec in which the device may take up to 30s
187 // to respond command.
188 //
189 #define SCSI_DISK_TIMEOUT EFI_TIMER_PERIOD_SECONDS (30)
190
191 /**
192 Test to see if this driver supports ControllerHandle.
193
194 This service is called by the EFI boot service ConnectController(). In order
195 to make drivers as small as possible, there are a few calling restrictions for
196 this service. ConnectController() must follow these calling restrictions.
197 If any other agent wishes to call Supported() it must also follow these
198 calling restrictions.
199
200 @param This Protocol instance pointer.
201 @param ControllerHandle Handle of device to test
202 @param RemainingDevicePath Optional parameter use to pick a specific child
203 device to start.
204
205 @retval EFI_SUCCESS This driver supports this device
206 @retval EFI_ALREADY_STARTED This driver is already running on this device
207 @retval other This driver does not support this device
208
209 **/
210 EFI_STATUS
211 EFIAPI
212 ScsiDiskDriverBindingSupported (
213 IN EFI_DRIVER_BINDING_PROTOCOL *This,
214 IN EFI_HANDLE Controller,
215 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
216 );
217
218 /**
219 Start this driver on ControllerHandle.
220
221 This service is called by the EFI boot service ConnectController(). In order
222 to make drivers as small as possible, there are a few calling restrictions for
223 this service. ConnectController() must follow these calling restrictions. If
224 any other agent wishes to call Start() it must also follow these calling
225 restrictions.
226
227 @param This Protocol instance pointer.
228 @param ControllerHandle Handle of device to bind driver to
229 @param RemainingDevicePath Optional parameter use to pick a specific child
230 device to start.
231
232 @retval EFI_SUCCESS This driver is added to ControllerHandle
233 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
234 @retval other This driver does not support this device
235
236 **/
237 EFI_STATUS
238 EFIAPI
239 ScsiDiskDriverBindingStart (
240 IN EFI_DRIVER_BINDING_PROTOCOL *This,
241 IN EFI_HANDLE Controller,
242 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
243 );
244
245 /**
246 Stop this driver on ControllerHandle.
247
248 This service is called by the EFI boot service DisconnectController().
249 In order to make drivers as small as possible, there are a few calling
250 restrictions for this service. DisconnectController() must follow these
251 calling restrictions. If any other agent wishes to call Stop() it must
252 also follow these calling restrictions.
253
254 @param This Protocol instance pointer.
255 @param ControllerHandle Handle of device to stop driver on
256 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
257 children is zero stop the entire bus driver.
258 @param ChildHandleBuffer List of Child Handles to Stop.
259
260 @retval EFI_SUCCESS This driver is removed ControllerHandle
261 @retval other This driver was not removed from this device
262
263 **/
264 EFI_STATUS
265 EFIAPI
266 ScsiDiskDriverBindingStop (
267 IN EFI_DRIVER_BINDING_PROTOCOL *This,
268 IN EFI_HANDLE Controller,
269 IN UINTN NumberOfChildren,
270 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
271 );
272
273 //
274 // EFI Component Name Functions
275 //
276
277 /**
278 Retrieves a Unicode string that is the user readable name of the driver.
279
280 This function retrieves the user readable name of a driver in the form of a
281 Unicode string. If the driver specified by This has a user readable name in
282 the language specified by Language, then a pointer to the driver name is
283 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
284 by This does not support the language specified by Language,
285 then EFI_UNSUPPORTED is returned.
286
287 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
288 EFI_COMPONENT_NAME_PROTOCOL instance.
289
290 @param Language A pointer to a Null-terminated ASCII string
291 array indicating the language. This is the
292 language of the driver name that the caller is
293 requesting, and it must match one of the
294 languages specified in SupportedLanguages. The
295 number of languages supported by a driver is up
296 to the driver writer. Language is specified
297 in RFC 4646 or ISO 639-2 language code format.
298
299 @param DriverName A pointer to the Unicode string to return.
300 This Unicode string is the name of the
301 driver specified by This in the language
302 specified by Language.
303
304 @retval EFI_SUCCESS The Unicode string for the Driver specified by
305 This and the language specified by Language was
306 returned in DriverName.
307
308 @retval EFI_INVALID_PARAMETER Language is NULL.
309
310 @retval EFI_INVALID_PARAMETER DriverName is NULL.
311
312 @retval EFI_UNSUPPORTED The driver specified by This does not support
313 the language specified by Language.
314
315 **/
316 EFI_STATUS
317 EFIAPI
318 ScsiDiskComponentNameGetDriverName (
319 IN EFI_COMPONENT_NAME_PROTOCOL *This,
320 IN CHAR8 *Language,
321 OUT CHAR16 **DriverName
322 );
323
324 /**
325 Retrieves a Unicode string that is the user readable name of the controller
326 that is being managed by a driver.
327
328 This function retrieves the user readable name of the controller specified by
329 ControllerHandle and ChildHandle in the form of a Unicode string. If the
330 driver specified by This has a user readable name in the language specified by
331 Language, then a pointer to the controller name is returned in ControllerName,
332 and EFI_SUCCESS is returned. If the driver specified by This is not currently
333 managing the controller specified by ControllerHandle and ChildHandle,
334 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
335 support the language specified by Language, then EFI_UNSUPPORTED is returned.
336
337 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
338 EFI_COMPONENT_NAME_PROTOCOL instance.
339
340 @param ControllerHandle The handle of a controller that the driver
341 specified by This is managing. This handle
342 specifies the controller whose name is to be
343 returned.
344
345 @param ChildHandle The handle of the child controller to retrieve
346 the name of. This is an optional parameter that
347 may be NULL. It will be NULL for device
348 drivers. It will also be NULL for a bus drivers
349 that wish to retrieve the name of the bus
350 controller. It will not be NULL for a bus
351 driver that wishes to retrieve the name of a
352 child controller.
353
354 @param Language A pointer to a Null-terminated ASCII string
355 array indicating the language. This is the
356 language of the driver name that the caller is
357 requesting, and it must match one of the
358 languages specified in SupportedLanguages. The
359 number of languages supported by a driver is up
360 to the driver writer. Language is specified in
361 RFC 4646 or ISO 639-2 language code format.
362
363 @param ControllerName A pointer to the Unicode string to return.
364 This Unicode string is the name of the
365 controller specified by ControllerHandle and
366 ChildHandle in the language specified by
367 Language from the point of view of the driver
368 specified by This.
369
370 @retval EFI_SUCCESS The Unicode string for the user readable name in
371 the language specified by Language for the
372 driver specified by This was returned in
373 DriverName.
374
375 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
376
377 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
378 EFI_HANDLE.
379
380 @retval EFI_INVALID_PARAMETER Language is NULL.
381
382 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
383
384 @retval EFI_UNSUPPORTED The driver specified by This is not currently
385 managing the controller specified by
386 ControllerHandle and ChildHandle.
387
388 @retval EFI_UNSUPPORTED The driver specified by This does not support
389 the language specified by Language.
390
391 **/
392 EFI_STATUS
393 EFIAPI
394 ScsiDiskComponentNameGetControllerName (
395 IN EFI_COMPONENT_NAME_PROTOCOL *This,
396 IN EFI_HANDLE ControllerHandle,
397 IN EFI_HANDLE ChildHandle OPTIONAL,
398 IN CHAR8 *Language,
399 OUT CHAR16 **ControllerName
400 );
401
402 /**
403 Reset SCSI Disk.
404
405
406 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
407 @param ExtendedVerification The flag about if extend verificate
408
409 @retval EFI_SUCCESS The device was reset.
410 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
411 not be reset.
412 @return EFI_STATUS is returned from EFI_SCSI_IO_PROTOCOL.ResetDevice().
413
414 **/
415 EFI_STATUS
416 EFIAPI
417 ScsiDiskReset (
418 IN EFI_BLOCK_IO_PROTOCOL *This,
419 IN BOOLEAN ExtendedVerification
420 );
421
422 /**
423 The function is to Read Block from SCSI Disk.
424
425 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
426 @param MediaId The Id of Media detected
427 @param Lba The logic block address
428 @param BufferSize The size of Buffer
429 @param Buffer The buffer to fill the read out data
430
431 @retval EFI_SUCCESS Successfully to read out block.
432 @retval EFI_DEVICE_ERROR Fail to detect media.
433 @retval EFI_NO_MEDIA Media is not present.
434 @retval EFI_MEDIA_CHANGED Media has changed.
435 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
436 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
437
438 **/
439 EFI_STATUS
440 EFIAPI
441 ScsiDiskReadBlocks (
442 IN EFI_BLOCK_IO_PROTOCOL *This,
443 IN UINT32 MediaId,
444 IN EFI_LBA Lba,
445 IN UINTN BufferSize,
446 OUT VOID *Buffer
447 );
448
449 /**
450 The function is to Write Block to SCSI Disk.
451
452 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
453 @param MediaId The Id of Media detected
454 @param Lba The logic block address
455 @param BufferSize The size of Buffer
456 @param Buffer The buffer to fill the read out data
457
458 @retval EFI_SUCCESS Successfully to read out block.
459 @retval EFI_WRITE_PROTECTED The device can not be written to.
460 @retval EFI_DEVICE_ERROR Fail to detect media.
461 @retval EFI_NO_MEDIA Media is not present.
462 @retval EFI_MEDIA_CHANGED Media has changed.
463 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
464 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
465
466 **/
467 EFI_STATUS
468 EFIAPI
469 ScsiDiskWriteBlocks (
470 IN EFI_BLOCK_IO_PROTOCOL *This,
471 IN UINT32 MediaId,
472 IN EFI_LBA Lba,
473 IN UINTN BufferSize,
474 IN VOID *Buffer
475 );
476
477 /**
478 Flush Block to Disk.
479
480 EFI_SUCCESS is returned directly.
481
482 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
483
484 @retval EFI_SUCCESS All outstanding data was written to the device
485
486 **/
487 EFI_STATUS
488 EFIAPI
489 ScsiDiskFlushBlocks (
490 IN EFI_BLOCK_IO_PROTOCOL *This
491 );
492
493 /**
494 Reset SCSI Disk.
495
496 @param This The pointer of EFI_BLOCK_IO2_PROTOCOL.
497 @param ExtendedVerification The flag about if extend verificate.
498
499 @retval EFI_SUCCESS The device was reset.
500 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
501 not be reset.
502 @return EFI_STATUS is returned from EFI_SCSI_IO_PROTOCOL.ResetDevice().
503
504 **/
505 EFI_STATUS
506 EFIAPI
507 ScsiDiskResetEx (
508 IN EFI_BLOCK_IO2_PROTOCOL *This,
509 IN BOOLEAN ExtendedVerification
510 );
511
512 /**
513 The function is to Read Block from SCSI Disk.
514
515 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
516 @param MediaId The Id of Media detected.
517 @param Lba The logic block address.
518 @param Token A pointer to the token associated with the transaction.
519 @param BufferSize The size of Buffer.
520 @param Buffer The buffer to fill the read out data.
521
522 @retval EFI_SUCCESS The read request was queued if Token-> Event is
523 not NULL. The data was read correctly from the
524 device if theToken-> Event is NULL.
525 @retval EFI_DEVICE_ERROR The device reported an error while attempting
526 to perform the read operation.
527 @retval EFI_NO_MEDIA There is no media in the device.
528 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
529 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
530 the intrinsic block size of the device.
531 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
532 valid, or the buffer is not on proper
533 alignment.
534 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
535 lack of resources.
536
537 **/
538 EFI_STATUS
539 EFIAPI
540 ScsiDiskReadBlocksEx (
541 IN EFI_BLOCK_IO2_PROTOCOL *This,
542 IN UINT32 MediaId,
543 IN EFI_LBA Lba,
544 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
545 IN UINTN BufferSize,
546 OUT VOID *Buffer
547 );
548
549 /**
550 The function is to Write Block to SCSI Disk.
551
552 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
553 @param MediaId The Id of Media detected.
554 @param Lba The logic block address.
555 @param Token A pointer to the token associated with the transaction.
556 @param BufferSize The size of Buffer.
557 @param Buffer The buffer to fill the read out data.
558
559 @retval EFI_SUCCESS The data were written correctly to the device.
560 @retval EFI_WRITE_PROTECTED The device cannot be written to.
561 @retval EFI_NO_MEDIA There is no media in the device.
562 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
563 @retval EFI_DEVICE_ERROR The device reported an error while attempting
564 to perform the write operation.
565 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
566 the intrinsic block size of the device.
567 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
568 valid, or the buffer is not on proper
569 alignment.
570
571 **/
572 EFI_STATUS
573 EFIAPI
574 ScsiDiskWriteBlocksEx (
575 IN EFI_BLOCK_IO2_PROTOCOL *This,
576 IN UINT32 MediaId,
577 IN EFI_LBA Lba,
578 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
579 IN UINTN BufferSize,
580 IN VOID *Buffer
581 );
582
583 /**
584 Flush the Block Device.
585
586 @param This Indicates a pointer to the calling context.
587 @param Token A pointer to the token associated with the transaction.
588
589 @retval EFI_SUCCESS All outstanding data was written to the device.
590 @retval EFI_DEVICE_ERROR The device reported an error while attempting to
591 write data.
592 @retval EFI_WRITE_PROTECTED The device cannot be written to.
593 @retval EFI_NO_MEDIA There is no media in the device.
594 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
595
596 **/
597 EFI_STATUS
598 EFIAPI
599 ScsiDiskFlushBlocksEx (
600 IN EFI_BLOCK_IO2_PROTOCOL *This,
601 IN OUT EFI_BLOCK_IO2_TOKEN *Token
602 );
603
604 /**
605 Erase a specified number of device blocks.
606
607 @param[in] This Indicates a pointer to the calling context.
608 @param[in] MediaId The media ID that the erase request is for.
609 @param[in] Lba The starting logical block address to be
610 erased. The caller is responsible for erasing
611 only legitimate locations.
612 @param[in, out] Token A pointer to the token associated with the
613 transaction.
614 @param[in] Size The size in bytes to be erased. This must be
615 a multiple of the physical block size of the
616 device.
617
618 @retval EFI_SUCCESS The erase request was queued if Event is not
619 NULL. The data was erased correctly to the
620 device if the Event is NULL.to the device.
621 @retval EFI_WRITE_PROTECTED The device cannot be erased due to write
622 protection.
623 @retval EFI_DEVICE_ERROR The device reported an error while attempting
624 to perform the erase operation.
625 @retval EFI_INVALID_PARAMETER The erase request contains LBAs that are not
626 valid.
627 @retval EFI_NO_MEDIA There is no media in the device.
628 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
629
630 **/
631 EFI_STATUS
632 EFIAPI
633 ScsiDiskEraseBlocks (
634 IN EFI_ERASE_BLOCK_PROTOCOL *This,
635 IN UINT32 MediaId,
636 IN EFI_LBA Lba,
637 IN OUT EFI_ERASE_BLOCK_TOKEN *Token,
638 IN UINTN Size
639 );
640
641 /**
642 Send a security protocol command to a device that receives data and/or the result
643 of one or more commands sent by SendData.
644
645 The ReceiveData function sends a security protocol command to the given MediaId.
646 The security protocol command sent is defined by SecurityProtocolId and contains
647 the security protocol specific data SecurityProtocolSpecificData. The function
648 returns the data from the security protocol command in PayloadBuffer.
649
650 For devices supporting the SCSI command set, the security protocol command is sent
651 using the SECURITY PROTOCOL IN command defined in SPC-4.
652
653 If PayloadBufferSize is too small to store the available data from the security
654 protocol command, the function shall copy PayloadBufferSize bytes into the
655 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
656
657 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
658 the function shall return EFI_INVALID_PARAMETER.
659
660 If the given MediaId does not support security protocol commands, the function shall
661 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
662 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
663 the function returns EFI_MEDIA_CHANGED.
664
665 If the security protocol fails to complete within the Timeout period, the function
666 shall return EFI_TIMEOUT.
667
668 If the security protocol command completes without an error, the function shall
669 return EFI_SUCCESS. If the security protocol command completes with an error, the
670 function shall return EFI_DEVICE_ERROR.
671
672 @param This Indicates a pointer to the calling context.
673 @param MediaId ID of the medium to receive data from.
674 @param Timeout The timeout, in 100ns units, to use for the execution
675 of the security protocol command. A Timeout value of 0
676 means that this function will wait indefinitely for the
677 security protocol command to execute. If Timeout is greater
678 than zero, then this function will return EFI_TIMEOUT if the
679 time required to execute the receive data command is greater than Timeout.
680 @param SecurityProtocolId The value of the "Security Protocol" parameter of
681 the security protocol command to be sent.
682 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
683 of the security protocol command to be sent.
684 @param PayloadBufferSize Size in bytes of the payload data buffer.
685 @param PayloadBuffer A pointer to a destination buffer to store the security
686 protocol command specific payload data for the security
687 protocol command. The caller is responsible for having
688 either implicit or explicit ownership of the buffer.
689 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
690 data written to the payload data buffer.
691
692 @retval EFI_SUCCESS The security protocol command completed successfully.
693 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
694 data from the device. The PayloadBuffer contains the truncated data.
695 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
696 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
697 @retval EFI_NO_MEDIA There is no media in the device.
698 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
699 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
700 PayloadBufferSize is non-zero.
701 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
702 protocol command to execute.
703
704 **/
705 EFI_STATUS
706 EFIAPI
707 ScsiDiskReceiveData (
708 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
709 IN UINT32 MediaId OPTIONAL,
710 IN UINT64 Timeout,
711 IN UINT8 SecurityProtocolId,
712 IN UINT16 SecurityProtocolSpecificData,
713 IN UINTN PayloadBufferSize,
714 OUT VOID *PayloadBuffer,
715 OUT UINTN *PayloadTransferSize
716 );
717
718 /**
719 Send a security protocol command to a device.
720
721 The SendData function sends a security protocol command containing the payload
722 PayloadBuffer to the given MediaId. The security protocol command sent is
723 defined by SecurityProtocolId and contains the security protocol specific data
724 SecurityProtocolSpecificData. If the underlying protocol command requires a
725 specific padding for the command payload, the SendData function shall add padding
726 bytes to the command payload to satisfy the padding requirements.
727
728 For devices supporting the SCSI command set, the security protocol command is sent
729 using the SECURITY PROTOCOL OUT command defined in SPC-4.
730
731 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
732 return EFI_INVALID_PARAMETER.
733
734 If the given MediaId does not support security protocol commands, the function
735 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
736 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
737 device, the function returns EFI_MEDIA_CHANGED.
738
739 If the security protocol fails to complete within the Timeout period, the function
740 shall return EFI_TIMEOUT.
741
742 If the security protocol command completes without an error, the function shall return
743 EFI_SUCCESS. If the security protocol command completes with an error, the function
744 shall return EFI_DEVICE_ERROR.
745
746 @param This Indicates a pointer to the calling context.
747 @param MediaId ID of the medium to receive data from.
748 @param Timeout The timeout, in 100ns units, to use for the execution
749 of the security protocol command. A Timeout value of 0
750 means that this function will wait indefinitely for the
751 security protocol command to execute. If Timeout is greater
752 than zero, then this function will return EFI_TIMEOUT if the
753 time required to execute the receive data command is greater than Timeout.
754 @param SecurityProtocolId The value of the "Security Protocol" parameter of
755 the security protocol command to be sent.
756 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
757 of the security protocol command to be sent.
758 @param PayloadBufferSize Size in bytes of the payload data buffer.
759 @param PayloadBuffer A pointer to a destination buffer to store the security
760 protocol command specific payload data for the security
761 protocol command.
762
763 @retval EFI_SUCCESS The security protocol command completed successfully.
764 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
765 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
766 @retval EFI_NO_MEDIA There is no media in the device.
767 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
768 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
769 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
770 protocol command to execute.
771
772 **/
773 EFI_STATUS
774 EFIAPI
775 ScsiDiskSendData (
776 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
777 IN UINT32 MediaId OPTIONAL,
778 IN UINT64 Timeout,
779 IN UINT8 SecurityProtocolId,
780 IN UINT16 SecurityProtocolSpecificData,
781 IN UINTN PayloadBufferSize,
782 OUT VOID *PayloadBuffer
783 );
784
785 /**
786 Provides inquiry information for the controller type.
787
788 This function is used by the IDE bus driver to get inquiry data. Data format
789 of Identify data is defined by the Interface GUID.
790
791 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
792 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
793 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
794
795 @retval EFI_SUCCESS The command was accepted without any errors.
796 @retval EFI_NOT_FOUND Device does not support this data class
797 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
798 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
799
800 **/
801 EFI_STATUS
802 EFIAPI
803 ScsiDiskInfoInquiry (
804 IN EFI_DISK_INFO_PROTOCOL *This,
805 IN OUT VOID *InquiryData,
806 IN OUT UINT32 *InquiryDataSize
807 );
808
809 /**
810 Provides identify information for the controller type.
811
812 This function is used by the IDE bus driver to get identify data. Data format
813 of Identify data is defined by the Interface GUID.
814
815 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
816 instance.
817 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
818 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
819 size.
820
821 @retval EFI_SUCCESS The command was accepted without any errors.
822 @retval EFI_NOT_FOUND Device does not support this data class
823 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
824 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
825
826 **/
827 EFI_STATUS
828 EFIAPI
829 ScsiDiskInfoIdentify (
830 IN EFI_DISK_INFO_PROTOCOL *This,
831 IN OUT VOID *IdentifyData,
832 IN OUT UINT32 *IdentifyDataSize
833 );
834
835 /**
836 Provides sense data information for the controller type.
837
838 This function is used by the IDE bus driver to get sense data.
839 Data format of Sense data is defined by the Interface GUID.
840
841 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
842 @param[in, out] SenseData Pointer to the SenseData.
843 @param[in, out] SenseDataSize Size of SenseData in bytes.
844 @param[out] SenseDataNumber Pointer to the value for the sense data size.
845
846 @retval EFI_SUCCESS The command was accepted without any errors.
847 @retval EFI_NOT_FOUND Device does not support this data class.
848 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
849 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
850
851 **/
852 EFI_STATUS
853 EFIAPI
854 ScsiDiskInfoSenseData (
855 IN EFI_DISK_INFO_PROTOCOL *This,
856 IN OUT VOID *SenseData,
857 IN OUT UINT32 *SenseDataSize,
858 OUT UINT8 *SenseDataNumber
859 );
860
861 /**
862 This function is used by the IDE bus driver to get controller information.
863
864 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
865 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
866 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
867
868 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
869 @retval EFI_UNSUPPORTED This is not an IDE device.
870
871 **/
872 EFI_STATUS
873 EFIAPI
874 ScsiDiskInfoWhichIde (
875 IN EFI_DISK_INFO_PROTOCOL *This,
876 OUT UINT32 *IdeChannel,
877 OUT UINT32 *IdeDevice
878 );
879
880 /**
881 Detect Device and read out capacity ,if error occurs, parse the sense key.
882
883 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
884 @param MustReadCapacity The flag about reading device capacity
885 @param MediaChange The pointer of flag indicates if media has changed
886
887 @retval EFI_DEVICE_ERROR Indicates that error occurs
888 @retval EFI_SUCCESS Successfully to detect media
889
890 **/
891 EFI_STATUS
892 ScsiDiskDetectMedia (
893 IN SCSI_DISK_DEV *ScsiDiskDevice,
894 IN BOOLEAN MustReadCapacity,
895 OUT BOOLEAN *MediaChange
896 );
897
898 /**
899 To test device.
900
901 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
902 When Test Unit Ready command encounters any error caused by host adapter or
903 target, return error without retrieving Sense Keys.
904
905 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
906 @param NeedRetry The pointer of flag indicates try again
907 @param SenseDataArray The pointer of an array of sense data
908 @param NumberOfSenseKeys The pointer of the number of sense data array
909
910 @retval EFI_DEVICE_ERROR Indicates that error occurs
911 @retval EFI_SUCCESS Successfully to test unit
912
913 **/
914 EFI_STATUS
915 ScsiDiskTestUnitReady (
916 IN SCSI_DISK_DEV *ScsiDiskDevice,
917 OUT BOOLEAN *NeedRetry,
918 OUT EFI_SCSI_SENSE_DATA **SenseDataArray,
919 OUT UINTN *NumberOfSenseKeys
920 );
921
922 /**
923 Parsing Sense Keys which got from request sense command.
924
925 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
926 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
927 @param NumberOfSenseKeys The number of sense key
928 @param Action The pointer of action which indicates what is need to do next
929
930 @retval EFI_DEVICE_ERROR Indicates that error occurs
931 @retval EFI_SUCCESS Successfully to complete the parsing
932
933 **/
934 EFI_STATUS
935 DetectMediaParsingSenseKeys (
936 OUT SCSI_DISK_DEV *ScsiDiskDevice,
937 IN EFI_SCSI_SENSE_DATA *SenseData,
938 IN UINTN NumberOfSenseKeys,
939 OUT UINTN *Action
940 );
941
942 /**
943 Send read capacity command to device and get the device parameter.
944
945 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
946 @param NeedRetry The pointer of flag indicates if need a retry
947 @param SenseDataArray The pointer of an array of sense data
948 @param NumberOfSenseKeys The number of sense key
949
950 @retval EFI_DEVICE_ERROR Indicates that error occurs
951 @retval EFI_SUCCESS Successfully to read capacity
952
953 **/
954 EFI_STATUS
955 ScsiDiskReadCapacity (
956 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
957 OUT BOOLEAN *NeedRetry,
958 OUT EFI_SCSI_SENSE_DATA **SenseDataArray,
959 OUT UINTN *NumberOfSenseKeys
960 );
961
962 /**
963 Check the HostAdapter status and re-interpret it in EFI_STATUS.
964
965 @param HostAdapterStatus Host Adapter status
966
967 @retval EFI_SUCCESS Host adapter is OK.
968 @retval EFI_TIMEOUT Timeout.
969 @retval EFI_NOT_READY Adapter NOT ready.
970 @retval EFI_DEVICE_ERROR Adapter device error.
971
972 **/
973 EFI_STATUS
974 CheckHostAdapterStatus (
975 IN UINT8 HostAdapterStatus
976 );
977
978 /**
979 Check the target status and re-interpret it in EFI_STATUS.
980
981 @param TargetStatus Target status
982
983 @retval EFI_NOT_READY Device is NOT ready.
984 @retval EFI_DEVICE_ERROR
985 @retval EFI_SUCCESS
986
987 **/
988 EFI_STATUS
989 CheckTargetStatus (
990 IN UINT8 TargetStatus
991 );
992
993 /**
994 Retrieve all sense keys from the device.
995
996 When encountering error during the process, if retrieve sense keys before
997 error encountered, it returns the sense keys with return status set to EFI_SUCCESS,
998 and NeedRetry set to FALSE; otherwise, return the proper return status.
999
1000 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1001 @param NeedRetry The pointer of flag indicates if need a retry
1002 @param SenseDataArray The pointer of an array of sense data
1003 @param NumberOfSenseKeys The number of sense key
1004 @param AskResetIfError The flag indicates if need reset when error occurs
1005
1006 @retval EFI_DEVICE_ERROR Indicates that error occurs
1007 @retval EFI_SUCCESS Successfully to request sense key
1008
1009 **/
1010 EFI_STATUS
1011 ScsiDiskRequestSenseKeys (
1012 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
1013 OUT BOOLEAN *NeedRetry,
1014 OUT EFI_SCSI_SENSE_DATA **SenseDataArray,
1015 OUT UINTN *NumberOfSenseKeys,
1016 IN BOOLEAN AskResetIfError
1017 );
1018
1019 /**
1020 Send out Inquiry command to Device.
1021
1022 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1023 @param NeedRetry Indicates if needs try again when error happens
1024
1025 @retval EFI_DEVICE_ERROR Indicates that error occurs
1026 @retval EFI_SUCCESS Successfully to detect media
1027
1028 **/
1029 EFI_STATUS
1030 ScsiDiskInquiryDevice (
1031 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
1032 OUT BOOLEAN *NeedRetry
1033 );
1034
1035 /**
1036 Parse Inquiry data.
1037
1038 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1039
1040 **/
1041 VOID
1042 ParseInquiryData (
1043 IN OUT SCSI_DISK_DEV *ScsiDiskDevice
1044 );
1045
1046 /**
1047 Read sector from SCSI Disk.
1048
1049 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1050 @param Buffer The buffer to fill in the read out data
1051 @param Lba Logic block address
1052 @param NumberOfBlocks The number of blocks to read
1053
1054 @retval EFI_DEVICE_ERROR Indicates a device error.
1055 @retval EFI_SUCCESS Operation is successful.
1056
1057 **/
1058 EFI_STATUS
1059 ScsiDiskReadSectors (
1060 IN SCSI_DISK_DEV *ScsiDiskDevice,
1061 OUT VOID *Buffer,
1062 IN EFI_LBA Lba,
1063 IN UINTN NumberOfBlocks
1064 );
1065
1066 /**
1067 Write sector to SCSI Disk.
1068
1069 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1070 @param Buffer The buffer of data to be written into SCSI Disk
1071 @param Lba Logic block address
1072 @param NumberOfBlocks The number of blocks to read
1073
1074 @retval EFI_DEVICE_ERROR Indicates a device error.
1075 @retval EFI_SUCCESS Operation is successful.
1076
1077 **/
1078 EFI_STATUS
1079 ScsiDiskWriteSectors (
1080 IN SCSI_DISK_DEV *ScsiDiskDevice,
1081 IN VOID *Buffer,
1082 IN EFI_LBA Lba,
1083 IN UINTN NumberOfBlocks
1084 );
1085
1086 /**
1087 Asynchronously read sector from SCSI Disk.
1088
1089 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1090 @param Buffer The buffer to fill in the read out data.
1091 @param Lba Logic block address.
1092 @param NumberOfBlocks The number of blocks to read.
1093 @param Token A pointer to the token associated with the
1094 non-blocking read request.
1095
1096 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL.
1097 @retval EFI_DEVICE_ERROR Indicates a device error.
1098 @retval EFI_SUCCESS Operation is successful.
1099
1100 **/
1101 EFI_STATUS
1102 ScsiDiskAsyncReadSectors (
1103 IN SCSI_DISK_DEV *ScsiDiskDevice,
1104 OUT VOID *Buffer,
1105 IN EFI_LBA Lba,
1106 IN UINTN NumberOfBlocks,
1107 IN EFI_BLOCK_IO2_TOKEN *Token
1108 );
1109
1110 /**
1111 Asynchronously write sector to SCSI Disk.
1112
1113 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1114 @param Buffer The buffer of data to be written into SCSI Disk.
1115 @param Lba Logic block address.
1116 @param NumberOfBlocks The number of blocks to read.
1117 @param Token A pointer to the token associated with the
1118 non-blocking read request.
1119
1120 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL
1121 @retval EFI_DEVICE_ERROR Indicates a device error.
1122 @retval EFI_SUCCESS Operation is successful.
1123
1124 **/
1125 EFI_STATUS
1126 ScsiDiskAsyncWriteSectors (
1127 IN SCSI_DISK_DEV *ScsiDiskDevice,
1128 IN VOID *Buffer,
1129 IN EFI_LBA Lba,
1130 IN UINTN NumberOfBlocks,
1131 IN EFI_BLOCK_IO2_TOKEN *Token
1132 );
1133
1134 /**
1135 Submit Read(10) command.
1136
1137 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1138 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1139 @param Timeout The time to complete the command
1140 @param DataBuffer The buffer to fill with the read out data
1141 @param DataLength The length of buffer
1142 @param StartLba The start logic block address
1143 @param SectorCount The number of blocks to read
1144
1145 @return EFI_STATUS is returned by calling ScsiRead10Command().
1146 **/
1147 EFI_STATUS
1148 ScsiDiskRead10 (
1149 IN SCSI_DISK_DEV *ScsiDiskDevice,
1150 OUT BOOLEAN *NeedRetry,
1151 IN UINT64 Timeout,
1152 OUT UINT8 *DataBuffer,
1153 IN OUT UINT32 *DataLength,
1154 IN UINT32 StartLba,
1155 IN UINT32 SectorCount
1156 );
1157
1158 /**
1159 Submit Write(10) Command.
1160
1161 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1162 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1163 @param Timeout The time to complete the command
1164 @param DataBuffer The buffer to fill with the read out data
1165 @param DataLength The length of buffer
1166 @param StartLba The start logic block address
1167 @param SectorCount The number of blocks to write
1168
1169 @return EFI_STATUS is returned by calling ScsiWrite10Command().
1170
1171 **/
1172 EFI_STATUS
1173 ScsiDiskWrite10 (
1174 IN SCSI_DISK_DEV *ScsiDiskDevice,
1175 OUT BOOLEAN *NeedRetry,
1176 IN UINT64 Timeout,
1177 IN UINT8 *DataBuffer,
1178 IN OUT UINT32 *DataLength,
1179 IN UINT32 StartLba,
1180 IN UINT32 SectorCount
1181 );
1182
1183 /**
1184 Submit Read(16) command.
1185
1186 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1187 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1188 @param Timeout The time to complete the command
1189 @param DataBuffer The buffer to fill with the read out data
1190 @param DataLength The length of buffer
1191 @param StartLba The start logic block address
1192 @param SectorCount The number of blocks to read
1193
1194 @return EFI_STATUS is returned by calling ScsiRead16Command().
1195 **/
1196 EFI_STATUS
1197 ScsiDiskRead16 (
1198 IN SCSI_DISK_DEV *ScsiDiskDevice,
1199 OUT BOOLEAN *NeedRetry,
1200 IN UINT64 Timeout,
1201 OUT UINT8 *DataBuffer,
1202 IN OUT UINT32 *DataLength,
1203 IN UINT64 StartLba,
1204 IN UINT32 SectorCount
1205 );
1206
1207 /**
1208 Submit Write(16) Command.
1209
1210 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1211 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1212 @param Timeout The time to complete the command
1213 @param DataBuffer The buffer to fill with the read out data
1214 @param DataLength The length of buffer
1215 @param StartLba The start logic block address
1216 @param SectorCount The number of blocks to write
1217
1218 @return EFI_STATUS is returned by calling ScsiWrite16Command().
1219
1220 **/
1221 EFI_STATUS
1222 ScsiDiskWrite16 (
1223 IN SCSI_DISK_DEV *ScsiDiskDevice,
1224 OUT BOOLEAN *NeedRetry,
1225 IN UINT64 Timeout,
1226 IN UINT8 *DataBuffer,
1227 IN OUT UINT32 *DataLength,
1228 IN UINT64 StartLba,
1229 IN UINT32 SectorCount
1230 );
1231
1232 /**
1233 Submit Async Read(10) command.
1234
1235 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1236 @param Timeout The time to complete the command.
1237 @param TimesRetry The number of times the command has been retried.
1238 @param DataBuffer The buffer to fill with the read out data.
1239 @param DataLength The length of buffer.
1240 @param StartLba The start logic block address.
1241 @param SectorCount The number of blocks to read.
1242 @param BlkIo2Req The upstream BlockIo2 request.
1243 @param Token The pointer to the token associated with the
1244 non-blocking read request.
1245
1246 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1247 lack of resources.
1248 @return others Status returned by calling
1249 ScsiRead10CommandEx().
1250
1251 **/
1252 EFI_STATUS
1253 ScsiDiskAsyncRead10 (
1254 IN SCSI_DISK_DEV *ScsiDiskDevice,
1255 IN UINT64 Timeout,
1256 IN UINT8 TimesRetry,
1257 OUT UINT8 *DataBuffer,
1258 IN UINT32 DataLength,
1259 IN UINT32 StartLba,
1260 IN UINT32 SectorCount,
1261 IN OUT SCSI_BLKIO2_REQUEST *BlkIo2Req,
1262 IN EFI_BLOCK_IO2_TOKEN *Token
1263 );
1264
1265 /**
1266 Submit Async Write(10) command.
1267
1268 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1269 @param Timeout The time to complete the command.
1270 @param TimesRetry The number of times the command has been retried.
1271 @param DataBuffer The buffer contains the data to write.
1272 @param DataLength The length of buffer.
1273 @param StartLba The start logic block address.
1274 @param SectorCount The number of blocks to write.
1275 @param BlkIo2Req The upstream BlockIo2 request.
1276 @param Token The pointer to the token associated with the
1277 non-blocking read request.
1278
1279 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1280 lack of resources.
1281 @return others Status returned by calling
1282 ScsiWrite10CommandEx().
1283
1284 **/
1285 EFI_STATUS
1286 ScsiDiskAsyncWrite10 (
1287 IN SCSI_DISK_DEV *ScsiDiskDevice,
1288 IN UINT64 Timeout,
1289 IN UINT8 TimesRetry,
1290 IN UINT8 *DataBuffer,
1291 IN UINT32 DataLength,
1292 IN UINT32 StartLba,
1293 IN UINT32 SectorCount,
1294 IN OUT SCSI_BLKIO2_REQUEST *BlkIo2Req,
1295 IN EFI_BLOCK_IO2_TOKEN *Token
1296 );
1297
1298 /**
1299 Submit Async Read(16) command.
1300
1301 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1302 @param Timeout The time to complete the command.
1303 @param TimesRetry The number of times the command has been retried.
1304 @param DataBuffer The buffer to fill with the read out data.
1305 @param DataLength The length of buffer.
1306 @param StartLba The start logic block address.
1307 @param SectorCount The number of blocks to read.
1308 @param BlkIo2Req The upstream BlockIo2 request.
1309 @param Token The pointer to the token associated with the
1310 non-blocking read request.
1311
1312 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1313 lack of resources.
1314 @return others Status returned by calling
1315 ScsiRead16CommandEx().
1316
1317 **/
1318 EFI_STATUS
1319 ScsiDiskAsyncRead16 (
1320 IN SCSI_DISK_DEV *ScsiDiskDevice,
1321 IN UINT64 Timeout,
1322 IN UINT8 TimesRetry,
1323 OUT UINT8 *DataBuffer,
1324 IN UINT32 DataLength,
1325 IN UINT64 StartLba,
1326 IN UINT32 SectorCount,
1327 IN OUT SCSI_BLKIO2_REQUEST *BlkIo2Req,
1328 IN EFI_BLOCK_IO2_TOKEN *Token
1329 );
1330
1331 /**
1332 Submit Async Write(16) command.
1333
1334 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1335 @param Timeout The time to complete the command.
1336 @param TimesRetry The number of times the command has been retried.
1337 @param DataBuffer The buffer contains the data to write.
1338 @param DataLength The length of buffer.
1339 @param StartLba The start logic block address.
1340 @param SectorCount The number of blocks to write.
1341 @param BlkIo2Req The upstream BlockIo2 request.
1342 @param Token The pointer to the token associated with the
1343 non-blocking read request.
1344
1345 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1346 lack of resources.
1347 @return others Status returned by calling
1348 ScsiWrite16CommandEx().
1349
1350 **/
1351 EFI_STATUS
1352 ScsiDiskAsyncWrite16 (
1353 IN SCSI_DISK_DEV *ScsiDiskDevice,
1354 IN UINT64 Timeout,
1355 IN UINT8 TimesRetry,
1356 IN UINT8 *DataBuffer,
1357 IN UINT32 DataLength,
1358 IN UINT64 StartLba,
1359 IN UINT32 SectorCount,
1360 IN OUT SCSI_BLKIO2_REQUEST *BlkIo2Req,
1361 IN EFI_BLOCK_IO2_TOKEN *Token
1362 );
1363
1364 /**
1365 Get information from media read capacity command.
1366
1367 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1368 @param Capacity10 The pointer of EFI_SCSI_DISK_CAPACITY_DATA
1369 @param Capacity16 The pointer of EFI_SCSI_DISK_CAPACITY_DATA16
1370 **/
1371 VOID
1372 GetMediaInfo (
1373 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
1374 IN EFI_SCSI_DISK_CAPACITY_DATA *Capacity10,
1375 IN EFI_SCSI_DISK_CAPACITY_DATA16 *Capacity16
1376 );
1377
1378 /**
1379 Check sense key to find if media presents.
1380
1381 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1382 @param SenseCounts The number of sense key
1383
1384 @retval TRUE NOT any media
1385 @retval FALSE Media presents
1386 **/
1387 BOOLEAN
1388 ScsiDiskIsNoMedia (
1389 IN EFI_SCSI_SENSE_DATA *SenseData,
1390 IN UINTN SenseCounts
1391 );
1392
1393 /**
1394 Parse sense key.
1395
1396 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1397 @param SenseCounts The number of sense key
1398
1399 @retval TRUE Error
1400 @retval FALSE NOT error
1401
1402 **/
1403 BOOLEAN
1404 ScsiDiskIsMediaError (
1405 IN EFI_SCSI_SENSE_DATA *SenseData,
1406 IN UINTN SenseCounts
1407 );
1408
1409 /**
1410 Check sense key to find if hardware error happens.
1411
1412 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1413 @param SenseCounts The number of sense key
1414
1415 @retval TRUE Hardware error exits.
1416 @retval FALSE NO error.
1417
1418 **/
1419 BOOLEAN
1420 ScsiDiskIsHardwareError (
1421 IN EFI_SCSI_SENSE_DATA *SenseData,
1422 IN UINTN SenseCounts
1423 );
1424
1425 /**
1426 Check sense key to find if media has changed.
1427
1428 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1429 @param SenseCounts The number of sense key
1430
1431 @retval TRUE Media is changed.
1432 @retval FALSE Media is NOT changed.
1433 **/
1434 BOOLEAN
1435 ScsiDiskIsMediaChange (
1436 IN EFI_SCSI_SENSE_DATA *SenseData,
1437 IN UINTN SenseCounts
1438 );
1439
1440 /**
1441 Check sense key to find if reset happens.
1442
1443 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1444 @param SenseCounts The number of sense key
1445
1446 @retval TRUE It is reset before.
1447 @retval FALSE It is NOT reset before.
1448
1449 **/
1450 BOOLEAN
1451 ScsiDiskIsResetBefore (
1452 IN EFI_SCSI_SENSE_DATA *SenseData,
1453 IN UINTN SenseCounts
1454 );
1455
1456 /**
1457 Check sense key to find if the drive is ready.
1458
1459 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1460 @param SenseCounts The number of sense key
1461 @param RetryLater The flag means if need a retry
1462
1463 @retval TRUE Drive is ready.
1464 @retval FALSE Drive is NOT ready.
1465
1466 **/
1467 BOOLEAN
1468 ScsiDiskIsDriveReady (
1469 IN EFI_SCSI_SENSE_DATA *SenseData,
1470 IN UINTN SenseCounts,
1471 OUT BOOLEAN *RetryLater
1472 );
1473
1474 /**
1475 Check sense key to find if it has sense key.
1476
1477 @param SenseData - The pointer of EFI_SCSI_SENSE_DATA
1478 @param SenseCounts - The number of sense key
1479
1480 @retval TRUE It has sense key.
1481 @retval FALSE It has NOT any sense key.
1482
1483 **/
1484 BOOLEAN
1485 ScsiDiskHaveSenseKey (
1486 IN EFI_SCSI_SENSE_DATA *SenseData,
1487 IN UINTN SenseCounts
1488 );
1489
1490 /**
1491 Release resource about disk device.
1492
1493 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1494
1495 **/
1496 VOID
1497 ReleaseScsiDiskDeviceResources (
1498 IN SCSI_DISK_DEV *ScsiDiskDevice
1499 );
1500
1501 /**
1502 Determine if Block Io should be produced.
1503
1504
1505 @param ChildHandle Child Handle to retrieve Parent information.
1506
1507 @retval TRUE Should produce Block Io.
1508 @retval FALSE Should not produce Block Io.
1509
1510 **/
1511 BOOLEAN
1512 DetermineInstallBlockIo (
1513 IN EFI_HANDLE ChildHandle
1514 );
1515
1516 /**
1517 Initialize the installation of DiskInfo protocol.
1518
1519 This function prepares for the installation of DiskInfo protocol on the child handle.
1520 By default, it installs DiskInfo protocol with SCSI interface GUID. If it further
1521 detects that the physical device is an ATAPI/AHCI device, it then updates interface GUID
1522 to be IDE/AHCI interface GUID.
1523
1524 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1525 @param ChildHandle Child handle to install DiskInfo protocol.
1526
1527 **/
1528 VOID
1529 InitializeInstallDiskInfo (
1530 IN SCSI_DISK_DEV *ScsiDiskDevice,
1531 IN EFI_HANDLE ChildHandle
1532 );
1533
1534 /**
1535 Search protocol database and check to see if the protocol
1536 specified by ProtocolGuid is present on a ControllerHandle and opened by
1537 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1538 If the ControllerHandle is found, then the protocol specified by ProtocolGuid
1539 will be opened on it.
1540
1541
1542 @param ProtocolGuid ProtocolGuid pointer.
1543 @param ChildHandle Child Handle to retrieve Parent information.
1544
1545 **/
1546 VOID *
1547 EFIAPI
1548 GetParentProtocol (
1549 IN EFI_GUID *ProtocolGuid,
1550 IN EFI_HANDLE ChildHandle
1551 );
1552
1553 /**
1554 Determine if EFI Erase Block Protocol should be produced.
1555
1556 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1557 @param ChildHandle Handle of device.
1558
1559 @retval TRUE Should produce EFI Erase Block Protocol.
1560 @retval FALSE Should not produce EFI Erase Block Protocol.
1561
1562 **/
1563 BOOLEAN
1564 DetermineInstallEraseBlock (
1565 IN SCSI_DISK_DEV *ScsiDiskDevice,
1566 IN EFI_HANDLE ChildHandle
1567 );
1568
1569 /**
1570 Determine if EFI Storage Security Command Protocol should be produced.
1571
1572 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1573 @param ChildHandle Handle of device.
1574
1575 @retval TRUE Should produce EFI Storage Security Command Protocol.
1576 @retval FALSE Should not produce EFI Storage Security Command Protocol.
1577
1578 **/
1579 BOOLEAN
1580 DetermineInstallStorageSecurity (
1581 IN SCSI_DISK_DEV *ScsiDiskDevice,
1582 IN EFI_HANDLE ChildHandle
1583 );
1584
1585 #endif