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