1 /** @file 2 3 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR> 4 This program and the accompanying materials 5 are licensed and made available under the terms and conditions of the BSD License 6 which accompanies this distribution. The full text of the license may be found at 7 http://opensource.org/licenses/bsd-license.php 8 9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 12 **/ 13 14 #ifndef _UFS_PASS_THRU_H_ 15 #define _UFS_PASS_THRU_H_ 16 17 #include <Uefi.h> 18 19 #include <Protocol/ScsiPassThruExt.h> 20 #include <Protocol/UfsHostController.h> 21 22 #include <Library/DebugLib.h> 23 #include <Library/UefiDriverEntryPoint.h> 24 #include <Library/BaseLib.h> 25 #include <Library/UefiLib.h> 26 #include <Library/BaseMemoryLib.h> 27 #include <Library/MemoryAllocationLib.h> 28 #include <Library/UefiBootServicesTableLib.h> 29 #include <Library/CacheMaintenanceLib.h> 30 #include <Library/DevicePathLib.h> 31 #include <Library/TimerLib.h> 32 33 #include "UfsPassThruHci.h" 34 35 #define UFS_PASS_THRU_SIG SIGNATURE_32 ('U', 'F', 'S', 'P') 36 37 // 38 // Lun 0~7 is for 8 common luns. 39 // Lun 8~11 is for those 4 well known luns (Refer to UFS 2.0 spec Table 10.58 for details): 40 // Lun 8: REPORT LUNS 41 // Lun 9: UFS DEVICE 42 // Lun 10: BOOT 43 // Lun 11: RPMB 44 // 45 #define UFS_MAX_LUNS 12 46 #define UFS_WLUN_PREFIX 0xC1 47 48 #define UFS_VENDOR_SKHYNIX 0x1AD 49 #define UFS_DEVICE_QUIRK_HOST_VS_DEBUGSAVECONFIGTIME (1 << 0) 50 51 typedef struct { 52 UINT8 Lun[UFS_MAX_LUNS]; 53 UINT16 BitMask:12; // Bit 0~7 is 1/1 mapping to common luns. Bit 8~11 is 1/1 mapping to well-known luns. 54 UINT16 Rsvd:4; 55 } UFS_EXPOSED_LUNS; 56 57 // 58 // Iterate through the double linked list. This is delete-safe. 59 // Do not touch NextEntry 60 // 61 #define EFI_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \ 62 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink;\ 63 Entry != (ListHead); Entry = NextEntry, NextEntry = Entry->ForwardLink) 64 65 typedef struct _UFS_PASS_THRU_PRIVATE_DATA { 66 UINT32 Signature; 67 EFI_HANDLE Handle; 68 EFI_EXT_SCSI_PASS_THRU_MODE ExtScsiPassThruMode; 69 EFI_EXT_SCSI_PASS_THRU_PROTOCOL ExtScsiPassThru; 70 EDKII_UFS_HOST_CONTROLLER_PROTOCOL *UfsHostController; 71 UINTN UfsHcBase; 72 UINT32 Capabilities; 73 74 UINT8 TaskTag; 75 76 VOID *UtpTrlBase; 77 UINT8 Nutrs; 78 VOID *TrlMapping; 79 VOID *UtpTmrlBase; 80 UINT8 Nutmrs; 81 VOID *TmrlMapping; 82 83 UFS_EXPOSED_LUNS Luns; 84 85 // 86 // For Non-blocking operation. 87 // 88 EFI_EVENT TimerEvent; 89 LIST_ENTRY Queue; 90 } UFS_PASS_THRU_PRIVATE_DATA; 91 92 #define UFS_PASS_THRU_TRANS_REQ_SIG SIGNATURE_32 ('U', 'F', 'S', 'T') 93 94 typedef struct { 95 UINT32 Signature; 96 LIST_ENTRY TransferList; 97 98 UINT8 Slot; 99 UTP_TRD *Trd; 100 UINT32 CmdDescSize; 101 VOID *CmdDescHost; 102 VOID *CmdDescMapping; 103 VOID *DataBufMapping; 104 105 EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet; 106 UINT64 TimeoutRemain; 107 EFI_EVENT CallerEvent; 108 } UFS_PASS_THRU_TRANS_REQ; 109 110 #define UFS_PASS_THRU_TRANS_REQ_FROM_THIS(a) \ 111 CR(a, UFS_PASS_THRU_TRANS_REQ, TransferList, UFS_PASS_THRU_TRANS_REQ_SIG) 112 113 #define UFS_TIMEOUT EFI_TIMER_PERIOD_SECONDS(3) 114 #define UFS_HC_ASYNC_TIMER EFI_TIMER_PERIOD_MILLISECONDS(1) 115 116 #define ROUNDUP8(x) (((x) % 8 == 0) ? (x) : ((x) / 8 + 1) * 8) 117 118 #define IS_ALIGNED(addr, size) (((UINTN) (addr) & (size - 1)) == 0) 119 120 #define UFS_PASS_THRU_PRIVATE_DATA_FROM_THIS(a) \ 121 CR (a, \ 122 UFS_PASS_THRU_PRIVATE_DATA, \ 123 ExtScsiPassThru, \ 124 UFS_PASS_THRU_SIG \ 125 ) 126 127 typedef struct _UFS_DEVICE_MANAGEMENT_REQUEST_PACKET { 128 UINT64 Timeout; 129 VOID *InDataBuffer; 130 VOID *OutDataBuffer; 131 UINT8 Opcode; 132 UINT8 DescId; 133 UINT8 Index; 134 UINT8 Selector; 135 UINT32 InTransferLength; 136 UINT32 OutTransferLength; 137 UINT8 DataDirection; 138 UINT8 Ocs; 139 } UFS_DEVICE_MANAGEMENT_REQUEST_PACKET; 140 141 // 142 // function prototype 143 // 144 /** 145 Tests to see if this driver supports a given controller. If a child device is provided, 146 it further tests to see if this driver supports creating a handle for the specified child device. 147 148 This function checks to see if the driver specified by This supports the device specified by 149 ControllerHandle. Drivers will typically use the device path attached to 150 ControllerHandle and/or the services from the bus I/O abstraction attached to 151 ControllerHandle to determine if the driver supports ControllerHandle. This function 152 may be called many times during platform initialization. In order to reduce boot times, the tests 153 performed by this function must be very small, and take as little time as possible to execute. This 154 function must not change the state of any hardware devices, and this function must be aware that the 155 device specified by ControllerHandle may already be managed by the same driver or a 156 different driver. This function must match its calls to AllocatePages() with FreePages(), 157 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol(). 158 Since ControllerHandle may have been previously started by the same driver, if a protocol is 159 already in the opened state, then it must not be closed with CloseProtocol(). This is required 160 to guarantee the state of ControllerHandle is not modified by this function. 161 162 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. 163 @param[in] ControllerHandle The handle of the controller to test. This handle 164 must support a protocol interface that supplies 165 an I/O abstraction to the driver. 166 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This 167 parameter is ignored by device drivers, and is optional for bus 168 drivers. For bus drivers, if this parameter is not NULL, then 169 the bus driver must determine if the bus controller specified 170 by ControllerHandle and the child controller specified 171 by RemainingDevicePath are both supported by this 172 bus driver. 173 174 @retval EFI_SUCCESS The device specified by ControllerHandle and 175 RemainingDevicePath is supported by the driver specified by This. 176 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and 177 RemainingDevicePath is already being managed by the driver 178 specified by This. 179 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and 180 RemainingDevicePath is already being managed by a different 181 driver or an application that requires exclusive access. 182 Currently not implemented. 183 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and 184 RemainingDevicePath is not supported by the driver specified by This. 185 **/ 186 EFI_STATUS 187 EFIAPI 188 UfsPassThruDriverBindingSupported ( 189 IN EFI_DRIVER_BINDING_PROTOCOL *This, 190 IN EFI_HANDLE Controller, 191 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath 192 ); 193 194 /** 195 Starts a device controller or a bus controller. 196 197 The Start() function is designed to be invoked from the EFI boot service ConnectController(). 198 As a result, much of the error checking on the parameters to Start() has been moved into this 199 common boot service. It is legal to call Start() from other locations, 200 but the following calling restrictions must be followed or the system behavior will not be deterministic. 201 1. ControllerHandle must be a valid EFI_HANDLE. 202 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned 203 EFI_DEVICE_PATH_PROTOCOL. 204 3. Prior to calling Start(), the Supported() function for the driver specified by This must 205 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. 206 207 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. 208 @param[in] ControllerHandle The handle of the controller to start. This handle 209 must support a protocol interface that supplies 210 an I/O abstraction to the driver. 211 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This 212 parameter is ignored by device drivers, and is optional for bus 213 drivers. For a bus driver, if this parameter is NULL, then handles 214 for all the children of Controller are created by this driver. 215 If this parameter is not NULL and the first Device Path Node is 216 not the End of Device Path Node, then only the handle for the 217 child device specified by the first Device Path Node of 218 RemainingDevicePath is created by this driver. 219 If the first Device Path Node of RemainingDevicePath is 220 the End of Device Path Node, no child handle is created by this 221 driver. 222 223 @retval EFI_SUCCESS The device was started. 224 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented. 225 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. 226 @retval Others The driver failded to start the device. 227 228 **/ 229 EFI_STATUS 230 EFIAPI 231 UfsPassThruDriverBindingStart ( 232 IN EFI_DRIVER_BINDING_PROTOCOL *This, 233 IN EFI_HANDLE Controller, 234 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath 235 ); 236 237 /** 238 Stops a device controller or a bus controller. 239 240 The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). 241 As a result, much of the error checking on the parameters to Stop() has been moved 242 into this common boot service. It is legal to call Stop() from other locations, 243 but the following calling restrictions must be followed or the system behavior will not be deterministic. 244 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this 245 same driver's Start() function. 246 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid 247 EFI_HANDLE. In addition, all of these handles must have been created in this driver's 248 Start() function, and the Start() function must have called OpenProtocol() on 249 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER. 250 251 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. 252 @param[in] ControllerHandle A handle to the device being stopped. The handle must 253 support a bus specific I/O protocol for the driver 254 to use to stop the device. 255 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer. 256 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL 257 if NumberOfChildren is 0. 258 259 @retval EFI_SUCCESS The device was stopped. 260 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error. 261 262 **/ 263 EFI_STATUS 264 EFIAPI 265 UfsPassThruDriverBindingStop ( 266 IN EFI_DRIVER_BINDING_PROTOCOL *This, 267 IN EFI_HANDLE Controller, 268 IN UINTN NumberOfChildren, 269 IN EFI_HANDLE *ChildHandleBuffer 270 ); 271 272 // 273 // EFI Component Name Functions 274 // 275 /** 276 Retrieves a Unicode string that is the user readable name of the driver. 277 278 This function retrieves the user readable name of a driver in the form of a 279 Unicode string. If the driver specified by This has a user readable name in 280 the language specified by Language, then a pointer to the driver name is 281 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified 282 by This does not support the language specified by Language, 283 then EFI_UNSUPPORTED is returned. 284 285 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 286 EFI_COMPONENT_NAME_PROTOCOL instance. 287 288 @param Language[in] A pointer to a Null-terminated ASCII string 289 array indicating the language. This is the 290 language of the driver name that the caller is 291 requesting, and it must match one of the 292 languages specified in SupportedLanguages. The 293 number of languages supported by a driver is up 294 to the driver writer. Language is specified 295 in RFC 4646 or ISO 639-2 language code format. 296 297 @param DriverName[out] A pointer to the Unicode string to return. 298 This Unicode string is the name of the 299 driver specified by This in the language 300 specified by Language. 301 302 @retval EFI_SUCCESS The Unicode string for the Driver specified by 303 This and the language specified by Language was 304 returned in DriverName. 305 306 @retval EFI_INVALID_PARAMETER Language is NULL. 307 308 @retval EFI_INVALID_PARAMETER DriverName is NULL. 309 310 @retval EFI_UNSUPPORTED The driver specified by This does not support 311 the language specified by Language. 312 313 **/ 314 EFI_STATUS 315 EFIAPI 316 UfsPassThruComponentNameGetDriverName ( 317 IN EFI_COMPONENT_NAME_PROTOCOL *This, 318 IN CHAR8 *Language, 319 OUT CHAR16 **DriverName 320 ); 321 322 323 /** 324 Retrieves a Unicode string that is the user readable name of the controller 325 that is being managed by a driver. 326 327 This function retrieves the user readable name of the controller specified by 328 ControllerHandle and ChildHandle in the form of a Unicode string. If the 329 driver specified by This has a user readable name in the language specified by 330 Language, then a pointer to the controller name is returned in ControllerName, 331 and EFI_SUCCESS is returned. If the driver specified by This is not currently 332 managing the controller specified by ControllerHandle and ChildHandle, 333 then EFI_UNSUPPORTED is returned. If the driver specified by This does not 334 support the language specified by Language, then EFI_UNSUPPORTED is returned. 335 336 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 337 EFI_COMPONENT_NAME_PROTOCOL instance. 338 339 @param ControllerHandle[in] The handle of a controller that the driver 340 specified by This is managing. This handle 341 specifies the controller whose name is to be 342 returned. 343 344 @param ChildHandle[in] The handle of the child controller to retrieve 345 the name of. This is an optional parameter that 346 may be NULL. It will be NULL for device 347 drivers. It will also be NULL for a bus drivers 348 that wish to retrieve the name of the bus 349 controller. It will not be NULL for a bus 350 driver that wishes to retrieve the name of a 351 child controller. 352 353 @param Language[in] A pointer to a Null-terminated ASCII string 354 array indicating the language. This is the 355 language of the driver name that the caller is 356 requesting, and it must match one of the 357 languages specified in SupportedLanguages. The 358 number of languages supported by a driver is up 359 to the driver writer. Language is specified in 360 RFC 4646 or ISO 639-2 language code format. 361 362 @param ControllerName[out] A pointer to the Unicode string to return. 363 This Unicode string is the name of the 364 controller specified by ControllerHandle and 365 ChildHandle in the language specified by 366 Language from the point of view of the driver 367 specified by This. 368 369 @retval EFI_SUCCESS The Unicode string for the user readable name in 370 the language specified by Language for the 371 driver specified by This was returned in 372 DriverName. 373 374 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. 375 376 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid 377 EFI_HANDLE. 378 379 @retval EFI_INVALID_PARAMETER Language is NULL. 380 381 @retval EFI_INVALID_PARAMETER ControllerName is NULL. 382 383 @retval EFI_UNSUPPORTED The driver specified by This is not currently 384 managing the controller specified by 385 ControllerHandle and ChildHandle. 386 387 @retval EFI_UNSUPPORTED The driver specified by This does not support 388 the language specified by Language. 389 390 **/ 391 EFI_STATUS 392 EFIAPI 393 UfsPassThruComponentNameGetControllerName ( 394 IN EFI_COMPONENT_NAME_PROTOCOL *This, 395 IN EFI_HANDLE ControllerHandle, 396 IN EFI_HANDLE ChildHandle OPTIONAL, 397 IN CHAR8 *Language, 398 OUT CHAR16 **ControllerName 399 ); 400 401 /** 402 Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function 403 supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the 404 nonblocking I/O functionality is optional. 405 406 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance. 407 @param Target The Target is an array of size TARGET_MAX_BYTES and it represents 408 the id of the SCSI device to send the SCSI Request Packet. Each 409 transport driver may choose to utilize a subset of this size to suit the needs 410 of transport target representation. For example, a Fibre Channel driver 411 may use only 8 bytes (WWN) to represent an FC target. 412 @param Lun The LUN of the SCSI device to send the SCSI Request Packet. 413 @param Packet A pointer to the SCSI Request Packet to send to the SCSI device 414 specified by Target and Lun. 415 @param Event If nonblocking I/O is not supported then Event is ignored, and blocking 416 I/O is performed. If Event is NULL, then blocking I/O is performed. If 417 Event is not NULL and non blocking I/O is supported, then 418 nonblocking I/O is performed, and Event will be signaled when the 419 SCSI Request Packet completes. 420 421 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional 422 commands, InTransferLength bytes were transferred from 423 InDataBuffer. For write and bi-directional commands, 424 OutTransferLength bytes were transferred by 425 OutDataBuffer. 426 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was not executed. The number of bytes that 427 could be transferred is returned in InTransferLength. For write 428 and bi-directional commands, OutTransferLength bytes were 429 transferred by OutDataBuffer. 430 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many 431 SCSI Request Packets already queued. The caller may retry again later. 432 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request 433 Packet. 434 @retval EFI_INVALID_PARAMETER Target, Lun, or the contents of ScsiRequestPacket are invalid. 435 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported 436 by the host adapter. This includes the case of Bi-directional SCSI 437 commands not supported by the implementation. The SCSI Request 438 Packet was not sent, so no additional status information is available. 439 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute. 440 441 **/ 442 EFI_STATUS 443 EFIAPI 444 UfsPassThruPassThru ( 445 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, 446 IN UINT8 *Target, 447 IN UINT64 Lun, 448 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet, 449 IN EFI_EVENT Event OPTIONAL 450 ); 451 452 /** 453 Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These 454 can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal 455 Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the 456 Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI 457 channel. 458 459 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance. 460 @param Target On input, a pointer to the Target ID (an array of size 461 TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel. 462 On output, a pointer to the Target ID (an array of 463 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI 464 channel. An input value of 0xF(all bytes in the array are 0xF) in the 465 Target array retrieves the Target ID of the first SCSI device present on a 466 SCSI channel. 467 @param Lun On input, a pointer to the LUN of a SCSI device present on the SCSI 468 channel. On output, a pointer to the LUN of the next SCSI device present 469 on a SCSI channel. 470 471 @retval EFI_SUCCESS The Target ID and LUN of the next SCSI device on the SCSI 472 channel was returned in Target and Lun. 473 @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were 474 not returned on a previous call to GetNextTargetLun(). 475 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel. 476 477 **/ 478 EFI_STATUS 479 EFIAPI 480 UfsPassThruGetNextTargetLun ( 481 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, 482 IN OUT UINT8 **Target, 483 IN OUT UINT64 *Lun 484 ); 485 486 /** 487 Used to allocate and build a device path node for a SCSI device on a SCSI channel. 488 489 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance. 490 @param Target The Target is an array of size TARGET_MAX_BYTES and it specifies the 491 Target ID of the SCSI device for which a device path node is to be 492 allocated and built. Transport drivers may chose to utilize a subset of 493 this size to suit the representation of targets. For example, a Fibre 494 Channel driver may use only 8 bytes (WWN) in the array to represent a 495 FC target. 496 @param Lun The LUN of the SCSI device for which a device path node is to be 497 allocated and built. 498 @param DevicePath A pointer to a single device path node that describes the SCSI device 499 specified by Target and Lun. This function is responsible for 500 allocating the buffer DevicePath with the boot service 501 AllocatePool(). It is the caller's responsibility to free 502 DevicePath when the caller is finished with DevicePath. 503 504 @retval EFI_SUCCESS The device path node that describes the SCSI device specified by 505 Target and Lun was allocated and returned in 506 DevicePath. 507 @retval EFI_INVALID_PARAMETER DevicePath is NULL. 508 @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist 509 on the SCSI channel. 510 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath. 511 512 **/ 513 EFI_STATUS 514 EFIAPI 515 UfsPassThruBuildDevicePath ( 516 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, 517 IN UINT8 *Target, 518 IN UINT64 Lun, 519 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath 520 ); 521 522 /** 523 Used to translate a device path node to a Target ID and LUN. 524 525 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance. 526 @param DevicePath A pointer to a single device path node that describes the SCSI device 527 on the SCSI channel. 528 @param Target A pointer to the Target Array which represents the ID of a SCSI device 529 on the SCSI channel. 530 @param Lun A pointer to the LUN of a SCSI device on the SCSI channel. 531 532 @retval EFI_SUCCESS DevicePath was successfully translated to a Target ID and 533 LUN, and they were returned in Target and Lun. 534 @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL. 535 @retval EFI_NOT_FOUND A valid translation from DevicePath to a Target ID and LUN 536 does not exist. 537 @retval EFI_UNSUPPORTED This driver does not support the device path node type in 538 DevicePath. 539 540 **/ 541 EFI_STATUS 542 EFIAPI 543 UfsPassThruGetTargetLun ( 544 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, 545 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, 546 OUT UINT8 **Target, 547 OUT UINT64 *Lun 548 ); 549 550 /** 551 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel. 552 553 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance. 554 555 @retval EFI_SUCCESS The SCSI channel was reset. 556 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel. 557 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI channel. 558 @retval EFI_UNSUPPORTED The SCSI channel does not support a channel reset operation. 559 560 **/ 561 EFI_STATUS 562 EFIAPI 563 UfsPassThruResetChannel ( 564 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This 565 ); 566 567 /** 568 Resets a SCSI logical unit that is connected to a SCSI channel. 569 570 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance. 571 @param Target The Target is an array of size TARGET_MAX_BYTE and it represents the 572 target port ID of the SCSI device containing the SCSI logical unit to 573 reset. Transport drivers may chose to utilize a subset of this array to suit 574 the representation of their targets. 575 @param Lun The LUN of the SCSI device to reset. 576 577 @retval EFI_SUCCESS The SCSI device specified by Target and Lun was reset. 578 @retval EFI_INVALID_PARAMETER Target or Lun is NULL. 579 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI device 580 specified by Target and Lun. 581 @retval EFI_UNSUPPORTED The SCSI channel does not support a target reset operation. 582 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI device 583 specified by Target and Lun. 584 585 **/ 586 EFI_STATUS 587 EFIAPI 588 UfsPassThruResetTargetLun ( 589 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, 590 IN UINT8 *Target, 591 IN UINT64 Lun 592 ); 593 594 /** 595 Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either 596 be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs 597 for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to 598 see if a SCSI device is actually present at that location on the SCSI channel. 599 600 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance. 601 @param Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel. 602 On output, a pointer to the Target ID (an array of 603 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI 604 channel. An input value of 0xF(all bytes in the array are 0xF) in the 605 Target array retrieves the Target ID of the first SCSI device present on a 606 SCSI channel. 607 608 @retval EFI_SUCCESS The Target ID of the next SCSI device on the SCSI 609 channel was returned in Target. 610 @retval EFI_INVALID_PARAMETER Target or Lun is NULL. 611 @retval EFI_TIMEOUT Target array is not all 0xF, and Target was not 612 returned on a previous call to GetNextTarget(). 613 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel. 614 615 **/ 616 EFI_STATUS 617 EFIAPI 618 UfsPassThruGetNextTarget ( 619 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, 620 IN OUT UINT8 **Target 621 ); 622 623 /** 624 Sends a UFS-supported SCSI Request Packet to a UFS device that is attached to the UFS host controller. 625 626 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure. 627 @param[in] Lun The LUN of the UFS device to send the SCSI Request Packet. 628 @param[in, out] Packet A pointer to the SCSI Request Packet to send to a specified Lun of the 629 UFS device. 630 @param[in] Event If nonblocking I/O is not supported then Event is ignored, and blocking 631 I/O is performed. If Event is NULL, then blocking I/O is performed. If 632 Event is not NULL and non blocking I/O is supported, then 633 nonblocking I/O is performed, and Event will be signaled when the 634 SCSI Request Packet completes. 635 636 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional 637 commands, InTransferLength bytes were transferred from 638 InDataBuffer. For write and bi-directional commands, 639 OutTransferLength bytes were transferred by 640 OutDataBuffer. 641 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request 642 Packet. 643 @retval EFI_OUT_OF_RESOURCES The resource for transfer is not available. 644 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute. 645 646 **/ 647 EFI_STATUS 648 UfsExecScsiCmds ( 649 IN UFS_PASS_THRU_PRIVATE_DATA *Private, 650 IN UINT8 Lun, 651 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet, 652 IN EFI_EVENT Event OPTIONAL 653 ); 654 655 /** 656 Initialize the UFS host controller. 657 658 @param[in] Private The pointer to the NVME_CONTROLLER_PRIVATE_DATA data structure. 659 660 @retval EFI_SUCCESS The NVM Express Controller is initialized successfully. 661 @retval Others A device error occurred while initializing the controller. 662 663 **/ 664 EFI_STATUS 665 UfsControllerInit ( 666 IN UFS_PASS_THRU_PRIVATE_DATA *Private 667 ); 668 669 /** 670 Stop the UFS host controller. 671 672 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure. 673 674 @retval EFI_SUCCESS The Ufs Host Controller is stopped successfully. 675 @retval Others A device error occurred while stopping the controller. 676 677 **/ 678 EFI_STATUS 679 UfsControllerStop ( 680 IN UFS_PASS_THRU_PRIVATE_DATA *Private 681 ); 682 683 /** 684 Allocate common buffer for host and UFS bus master access simultaneously. 685 686 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure. 687 @param[in] Size The length of buffer to be allocated. 688 @param[out] CmdDescHost A pointer to store the base system memory address of the allocated range. 689 @param[out] CmdDescPhyAddr The resulting map address for the UFS bus master to use to access the hosts CmdDescHost. 690 @param[out] CmdDescMapping A resulting value to pass to Unmap(). 691 692 @retval EFI_SUCCESS The common buffer was allocated successfully. 693 @retval EFI_DEVICE_ERROR The allocation fails. 694 @retval EFI_OUT_OF_RESOURCES The memory resource is insufficient. 695 696 **/ 697 EFI_STATUS 698 UfsAllocateAlignCommonBuffer ( 699 IN UFS_PASS_THRU_PRIVATE_DATA *Private, 700 IN UINTN Size, 701 OUT VOID **CmdDescHost, 702 OUT EFI_PHYSICAL_ADDRESS *CmdDescPhyAddr, 703 OUT VOID **CmdDescMapping 704 ); 705 706 /** 707 Set specified flag to 1 on a UFS device. 708 709 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure. 710 @param[in] FlagId The ID of flag to be set. 711 712 @retval EFI_SUCCESS The flag was set successfully. 713 @retval EFI_DEVICE_ERROR A device error occurred while attempting to set the flag. 714 @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of setting the flag. 715 716 **/ 717 EFI_STATUS 718 UfsSetFlag ( 719 IN UFS_PASS_THRU_PRIVATE_DATA *Private, 720 IN UINT8 FlagId 721 ); 722 723 /** 724 Read or write specified device descriptor of a UFS device. 725 726 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure. 727 @param[in] Read The boolean variable to show r/w direction. 728 @param[in] DescId The ID of device descriptor. 729 @param[in] Index The Index of device descriptor. 730 @param[in] Selector The Selector of device descriptor. 731 @param[in, out] Descriptor The buffer of device descriptor to be read or written. 732 @param[in] DescSize The size of device descriptor buffer. 733 734 @retval EFI_SUCCESS The device descriptor was read/written successfully. 735 @retval EFI_DEVICE_ERROR A device error occurred while attempting to r/w the device descriptor. 736 @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of r/w the device descriptor. 737 738 **/ 739 EFI_STATUS 740 UfsRwDeviceDesc ( 741 IN UFS_PASS_THRU_PRIVATE_DATA *Private, 742 IN BOOLEAN Read, 743 IN UINT8 DescId, 744 IN UINT8 Index, 745 IN UINT8 Selector, 746 IN OUT VOID *Descriptor, 747 IN UINT32 DescSize 748 ); 749 750 /** 751 Sends NOP IN cmd to a UFS device for initialization process request. 752 For more details, please refer to UFS 2.0 spec Figure 13.3. 753 754 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure. 755 756 @retval EFI_SUCCESS The NOP IN command was sent by the host. The NOP OUT response was 757 received successfully. 758 @retval EFI_DEVICE_ERROR A device error occurred while attempting to execute NOP IN command. 759 @retval EFI_OUT_OF_RESOURCES The resource for transfer is not available. 760 @retval EFI_TIMEOUT A timeout occurred while waiting for the NOP IN command to execute. 761 762 **/ 763 EFI_STATUS 764 UfsExecNopCmds ( 765 IN UFS_PASS_THRU_PRIVATE_DATA *Private 766 ); 767 768 /** 769 Call back function when the timer event is signaled. 770 771 @param[in] Event The Event this notify function registered to. 772 @param[in] Context Pointer to the context data registered to the Event. 773 774 **/ 775 VOID 776 EFIAPI 777 ProcessAsyncTaskList ( 778 IN EFI_EVENT Event, 779 IN VOID *Context 780 ); 781 782 /** 783 Internal helper function which will signal the caller event and clean up 784 resources. 785 786 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data 787 structure. 788 @param[in] TransReq The pointer to the UFS_PASS_THRU_TRANS_REQ data 789 structure. 790 791 **/ 792 VOID 793 EFIAPI 794 SignalCallerEvent ( 795 IN UFS_PASS_THRU_PRIVATE_DATA *Private, 796 IN UFS_PASS_THRU_TRANS_REQ *TransReq 797 ); 798 799 extern EFI_COMPONENT_NAME_PROTOCOL gUfsPassThruComponentName; 800 extern EFI_COMPONENT_NAME2_PROTOCOL gUfsPassThruComponentName2; 801 extern EFI_DRIVER_BINDING_PROTOCOL gUfsPassThruDriverBinding; 802 803 #endif 804