1 /** @file 2 The EFI_ATA_PASS_THRU_PROTOCOL provides information about an ATA controller and the ability 3 to send ATA Command Blocks to any ATA device attached to that ATA controller. The information 4 includes the attributes of the ATA controller. 5 6 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR> 7 SPDX-License-Identifier: BSD-2-Clause-Patent 8 9 @par Revision Reference: 10 This Protocol was introduced in UEFI Specification 2.3. 11 12 **/ 13 14 #ifndef __ATA_PASS_THROUGH_H__ 15 #define __ATA_PASS_THROUGH_H__ 16 17 #define EFI_ATA_PASS_THRU_PROTOCOL_GUID \ 18 { \ 19 0x1d3de7f0, 0x807, 0x424f, {0xaa, 0x69, 0x11, 0xa5, 0x4e, 0x19, 0xa4, 0x6f } \ 20 } 21 22 typedef struct _EFI_ATA_PASS_THRU_PROTOCOL EFI_ATA_PASS_THRU_PROTOCOL; 23 24 typedef struct { 25 UINT32 Attributes; 26 UINT32 IoAlign; 27 } EFI_ATA_PASS_THRU_MODE; 28 29 /// 30 /// If this bit is set, then the EFI_ATA_PASS_THRU_PROTOCOL interface is for physical 31 /// devices on the ATA controller. 32 /// 33 #define EFI_ATA_PASS_THRU_ATTRIBUTES_PHYSICAL 0x0001 34 /// 35 /// If this bit is set, then the EFI_ATA_PASS_THRU_PROTOCOL interface is for logical 36 /// devices on the ATA controller. 37 /// 38 #define EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL 0x0002 39 /// 40 /// If this bit is set, then the EFI_ATA_PASS_THRU_PROTOCOL interface supports non blocking 41 /// I/O. Every EFI_ATA_PASS_THRU_PROTOCOL must support blocking I/O. The support of non-blocking 42 /// I/O is optional. 43 /// 44 #define EFI_ATA_PASS_THRU_ATTRIBUTES_NONBLOCKIO 0x0004 45 46 typedef struct _EFI_ATA_COMMAND_BLOCK { 47 UINT8 Reserved1[2]; 48 UINT8 AtaCommand; 49 UINT8 AtaFeatures; 50 UINT8 AtaSectorNumber; 51 UINT8 AtaCylinderLow; 52 UINT8 AtaCylinderHigh; 53 UINT8 AtaDeviceHead; 54 UINT8 AtaSectorNumberExp; 55 UINT8 AtaCylinderLowExp; 56 UINT8 AtaCylinderHighExp; 57 UINT8 AtaFeaturesExp; 58 UINT8 AtaSectorCount; 59 UINT8 AtaSectorCountExp; 60 UINT8 Reserved2[6]; 61 } EFI_ATA_COMMAND_BLOCK; 62 63 typedef struct _EFI_ATA_STATUS_BLOCK { 64 UINT8 Reserved1[2]; 65 UINT8 AtaStatus; 66 UINT8 AtaError; 67 UINT8 AtaSectorNumber; 68 UINT8 AtaCylinderLow; 69 UINT8 AtaCylinderHigh; 70 UINT8 AtaDeviceHead; 71 UINT8 AtaSectorNumberExp; 72 UINT8 AtaCylinderLowExp; 73 UINT8 AtaCylinderHighExp; 74 UINT8 Reserved2; 75 UINT8 AtaSectorCount; 76 UINT8 AtaSectorCountExp; 77 UINT8 Reserved3[6]; 78 } EFI_ATA_STATUS_BLOCK; 79 80 typedef UINT8 EFI_ATA_PASS_THRU_CMD_PROTOCOL; 81 82 #define EFI_ATA_PASS_THRU_PROTOCOL_ATA_HARDWARE_RESET 0x00 83 #define EFI_ATA_PASS_THRU_PROTOCOL_ATA_SOFTWARE_RESET 0x01 84 #define EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA 0x02 85 #define EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_IN 0x04 86 #define EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT 0x05 87 #define EFI_ATA_PASS_THRU_PROTOCOL_DMA 0x06 88 #define EFI_ATA_PASS_THRU_PROTOCOL_DMA_QUEUED 0x07 89 #define EFI_ATA_PASS_THRU_PROTOCOL_DEVICE_DIAGNOSTIC 0x08 90 #define EFI_ATA_PASS_THRU_PROTOCOL_DEVICE_RESET 0x09 91 #define EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_IN 0x0A 92 #define EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_OUT 0x0B 93 #define EFI_ATA_PASS_THRU_PROTOCOL_FPDMA 0x0C 94 #define EFI_ATA_PASS_THRU_PROTOCOL_RETURN_RESPONSE 0xFF 95 96 typedef UINT8 EFI_ATA_PASS_THRU_LENGTH; 97 98 #define EFI_ATA_PASS_THRU_LENGTH_BYTES 0x80 99 100 101 #define EFI_ATA_PASS_THRU_LENGTH_MASK 0x70 102 #define EFI_ATA_PASS_THRU_LENGTH_NO_DATA_TRANSFER 0x00 103 #define EFI_ATA_PASS_THRU_LENGTH_FEATURES 0x10 104 #define EFI_ATA_PASS_THRU_LENGTH_SECTOR_COUNT 0x20 105 #define EFI_ATA_PASS_THRU_LENGTH_TPSIU 0x30 106 107 #define EFI_ATA_PASS_THRU_LENGTH_COUNT 0x0F 108 109 typedef struct { 110 /// 111 /// A pointer to the sense data that was generated by the execution of the ATA 112 /// command. It must be aligned to the boundary specified in the IoAlign field 113 /// in the EFI_ATA_PASS_THRU_MODE structure. 114 /// 115 EFI_ATA_STATUS_BLOCK *Asb; 116 /// 117 /// A pointer to buffer that contains the Command Data Block to send to the ATA 118 /// device specified by Port and PortMultiplierPort. 119 /// 120 EFI_ATA_COMMAND_BLOCK *Acb; 121 /// 122 /// The timeout, in 100 ns units, to use for the execution of this ATA command. 123 /// A Timeout value of 0 means that this function will wait indefinitely for the 124 /// ATA command to execute. If Timeout is greater than zero, then this function 125 /// will return EFI_TIMEOUT if the time required to execute the ATA command is 126 /// greater than Timeout. 127 /// 128 UINT64 Timeout; 129 /// 130 /// A pointer to the data buffer to transfer between the ATA controller and the 131 /// ATA device for read and bidirectional commands. For all write and non data 132 /// commands where InTransferLength is 0 this field is optional and may be NULL. 133 /// If this field is not NULL, then it must be aligned on the boundary specified 134 /// by the IoAlign field in the EFI_ATA_PASS_THRU_MODE structure. 135 /// 136 VOID *InDataBuffer; 137 /// 138 /// A pointer to the data buffer to transfer between the ATA controller and the 139 /// ATA device for write or bidirectional commands. For all read and non data 140 /// commands where OutTransferLength is 0 this field is optional and may be NULL. 141 /// If this field is not NULL, then it must be aligned on the boundary specified 142 /// by the IoAlign field in the EFI_ATA_PASS_THRU_MODE structure. 143 /// 144 VOID *OutDataBuffer; 145 /// 146 /// On input, the size, in bytes, of InDataBuffer. On output, the number of bytes 147 /// transferred between the ATA controller and the ATA device. If InTransferLength 148 /// is larger than the ATA controller can handle, no data will be transferred, 149 /// InTransferLength will be updated to contain the number of bytes that the ATA 150 /// controller is able to transfer, and EFI_BAD_BUFFER_SIZE will be returned. 151 /// 152 UINT32 InTransferLength; 153 /// 154 /// On Input, the size, in bytes of OutDataBuffer. On Output, the Number of bytes 155 /// transferred between ATA Controller and the ATA device. If OutTransferLength is 156 /// larger than the ATA controller can handle, no data will be transferred, 157 /// OutTransferLength will be updated to contain the number of bytes that the ATA 158 /// controller is able to transfer, and EFI_BAD_BUFFER_SIZE will be returned. 159 /// 160 UINT32 OutTransferLength; 161 /// 162 /// Specifies the protocol used when the ATA device executes the command. 163 /// 164 EFI_ATA_PASS_THRU_CMD_PROTOCOL Protocol; 165 /// 166 /// Specifies the way in which the ATA command length is encoded. 167 /// 168 EFI_ATA_PASS_THRU_LENGTH Length; 169 } EFI_ATA_PASS_THRU_COMMAND_PACKET; 170 171 172 /** 173 Sends an ATA command to an ATA device that is attached to the ATA controller. This function 174 supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required, 175 and the non-blocking I/O functionality is optional. 176 177 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance. 178 @param[in] Port The port number of the ATA device to send the command. 179 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command. 180 If there is no port multiplier, then specify 0xFFFF. 181 @param[in,out] Packet A pointer to the ATA command to send to the ATA device specified by Port 182 and PortMultiplierPort. 183 @param[in] Event If non-blocking I/O is not supported then Event is ignored, and blocking 184 I/O is performed. If Event is NULL, then blocking I/O is performed. If 185 Event is not NULL and non blocking I/O is supported, then non-blocking 186 I/O is performed, and Event will be signaled when the ATA command completes. 187 188 @retval EFI_SUCCESS The ATA command was sent by the host. For bi-directional commands, 189 InTransferLength bytes were transferred from InDataBuffer. For write and 190 bi-directional commands, OutTransferLength bytes were transferred by OutDataBuffer. 191 @retval EFI_BAD_BUFFER_SIZE The ATA command was not executed. The number of bytes that could be transferred 192 is returned in InTransferLength. For write and bi-directional commands, 193 OutTransferLength bytes were transferred by OutDataBuffer. 194 @retval EFI_NOT_READY The ATA command could not be sent because there are too many ATA commands 195 already queued. The caller may retry again later. 196 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the ATA command. 197 @retval EFI_INVALID_PARAMETER Port, PortMultiplierPort, or the contents of Acb are invalid. The ATA 198 command was not sent, so no additional status information is available. 199 200 **/ 201 typedef 202 EFI_STATUS 203 (EFIAPI *EFI_ATA_PASS_THRU_PASSTHRU)( 204 IN EFI_ATA_PASS_THRU_PROTOCOL *This, 205 IN UINT16 Port, 206 IN UINT16 PortMultiplierPort, 207 IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET *Packet, 208 IN EFI_EVENT Event OPTIONAL 209 ); 210 211 /** 212 Used to retrieve the list of legal port numbers for ATA devices on an ATA controller. 213 These can either be the list of ports where ATA devices are actually present or the 214 list of legal port numbers for the ATA controller. Regardless, the caller of this 215 function must probe the port number returned to see if an ATA device is actually 216 present at that location on the ATA controller. 217 218 The GetNextPort() function retrieves the port number on an ATA controller. If on input 219 Port is 0xFFFF, then the port number of the first port on the ATA controller is returned 220 in Port and EFI_SUCCESS is returned. 221 222 If Port is a port number that was returned on a previous call to GetNextPort(), then the 223 port number of the next port on the ATA controller is returned in Port, and EFI_SUCCESS 224 is returned. If Port is not 0xFFFF and Port was not returned on a previous call to 225 GetNextPort(), then EFI_INVALID_PARAMETER is returned. 226 227 If Port is the port number of the last port on the ATA controller, then EFI_NOT_FOUND is 228 returned. 229 230 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance. 231 @param[in,out] Port On input, a pointer to the port number on the ATA controller. 232 On output, a pointer to the next port number on the ATA 233 controller. An input value of 0xFFFF retrieves the first port 234 number on the ATA controller. 235 236 @retval EFI_SUCCESS The next port number on the ATA controller was returned in Port. 237 @retval EFI_NOT_FOUND There are no more ports on this ATA controller. 238 @retval EFI_INVALID_PARAMETER Port is not 0xFFFF and Port was not returned on a previous call 239 to GetNextPort(). 240 241 **/ 242 typedef 243 EFI_STATUS 244 (EFIAPI *EFI_ATA_PASS_THRU_GET_NEXT_PORT)( 245 IN EFI_ATA_PASS_THRU_PROTOCOL *This, 246 IN OUT UINT16 *Port 247 ); 248 249 /** 250 Used to retrieve the list of legal port multiplier port numbers for ATA devices on a port of an ATA 251 controller. These can either be the list of port multiplier ports where ATA devices are actually 252 present on port or the list of legal port multiplier ports on that port. Regardless, the caller of this 253 function must probe the port number and port multiplier port number returned to see if an ATA 254 device is actually present. 255 256 The GetNextDevice() function retrieves the port multiplier port number of an ATA device 257 present on a port of an ATA controller. 258 259 If PortMultiplierPort points to a port multiplier port number value that was returned on a 260 previous call to GetNextDevice(), then the port multiplier port number of the next ATA device 261 on the port of the ATA controller is returned in PortMultiplierPort, and EFI_SUCCESS is 262 returned. 263 264 If PortMultiplierPort points to 0xFFFF, then the port multiplier port number of the first 265 ATA device on port of the ATA controller is returned in PortMultiplierPort and 266 EFI_SUCCESS is returned. 267 268 If PortMultiplierPort is not 0xFFFF and the value pointed to by PortMultiplierPort 269 was not returned on a previous call to GetNextDevice(), then EFI_INVALID_PARAMETER 270 is returned. 271 272 If PortMultiplierPort is the port multiplier port number of the last ATA device on the port of 273 the ATA controller, then EFI_NOT_FOUND is returned. 274 275 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance. 276 @param[in] Port The port number present on the ATA controller. 277 @param[in,out] PortMultiplierPort On input, a pointer to the port multiplier port number of an 278 ATA device present on the ATA controller. 279 If on input a PortMultiplierPort of 0xFFFF is specified, 280 then the port multiplier port number of the first ATA device 281 is returned. On output, a pointer to the port multiplier port 282 number of the next ATA device present on an ATA controller. 283 284 @retval EFI_SUCCESS The port multiplier port number of the next ATA device on the port 285 of the ATA controller was returned in PortMultiplierPort. 286 @retval EFI_NOT_FOUND There are no more ATA devices on this port of the ATA controller. 287 @retval EFI_INVALID_PARAMETER PortMultiplierPort is not 0xFFFF, and PortMultiplierPort was not 288 returned on a previous call to GetNextDevice(). 289 290 **/ 291 typedef 292 EFI_STATUS 293 (EFIAPI *EFI_ATA_PASS_THRU_GET_NEXT_DEVICE)( 294 IN EFI_ATA_PASS_THRU_PROTOCOL *This, 295 IN UINT16 Port, 296 IN OUT UINT16 *PortMultiplierPort 297 ); 298 299 /** 300 Used to allocate and build a device path node for an ATA device on an ATA controller. 301 302 The BuildDevicePath() function allocates and builds a single device node for the ATA 303 device specified by Port and PortMultiplierPort. If the ATA device specified by Port and 304 PortMultiplierPort is not present on the ATA controller, then EFI_NOT_FOUND is returned. 305 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned. If there are not enough 306 resources to allocate the device path node, then EFI_OUT_OF_RESOURCES is returned. 307 308 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of 309 DevicePath are initialized to describe the ATA device specified by Port and PortMultiplierPort, 310 and EFI_SUCCESS is returned. 311 312 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance. 313 @param[in] Port Port specifies the port number of the ATA device for which a 314 device path node is to be allocated and built. 315 @param[in] PortMultiplierPort The port multiplier port number of the ATA device for which a 316 device path node is to be allocated and built. If there is no 317 port multiplier, then specify 0xFFFF. 318 @param[out] DevicePath A pointer to a single device path node that describes the ATA 319 device specified by Port and PortMultiplierPort. This function 320 is responsible for allocating the buffer DevicePath with the 321 boot service AllocatePool(). It is the caller's responsibility 322 to free DevicePath when the caller is finished with DevicePath. 323 @retval EFI_SUCCESS The device path node that describes the ATA device specified by 324 Port and PortMultiplierPort was allocated and returned in DevicePath. 325 @retval EFI_NOT_FOUND The ATA device specified by Port and PortMultiplierPort does not 326 exist on the ATA controller. 327 @retval EFI_INVALID_PARAMETER DevicePath is NULL. 328 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath. 329 330 **/ 331 typedef 332 EFI_STATUS 333 (EFIAPI *EFI_ATA_PASS_THRU_BUILD_DEVICE_PATH)( 334 IN EFI_ATA_PASS_THRU_PROTOCOL *This, 335 IN UINT16 Port, 336 IN UINT16 PortMultiplierPort, 337 OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath 338 ); 339 340 /** 341 Used to translate a device path node to a port number and port multiplier port number. 342 343 The GetDevice() function determines the port and port multiplier port number associated with 344 the ATA device described by DevicePath. If DevicePath is a device path node type that the 345 ATA Pass Thru driver supports, then the ATA Pass Thru driver will attempt to translate the contents 346 DevicePath into a port number and port multiplier port number. 347 348 If this translation is successful, then that port number and port multiplier port number are returned 349 in Port and PortMultiplierPort, and EFI_SUCCESS is returned. 350 351 If DevicePath, Port, or PortMultiplierPort are NULL, then EFI_INVALID_PARAMETER is returned. 352 353 If DevicePath is not a device path node type that the ATA Pass Thru driver supports, then 354 EFI_UNSUPPORTED is returned. 355 356 If DevicePath is a device path node type that the ATA Pass Thru driver supports, but there is not 357 a valid translation from DevicePath to a port number and port multiplier port number, then 358 EFI_NOT_FOUND is returned. 359 360 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance. 361 @param[in] DevicePath A pointer to the device path node that describes an ATA device on the 362 ATA controller. 363 @param[out] Port On return, points to the port number of an ATA device on the ATA controller. 364 @param[out] PortMultiplierPort On return, points to the port multiplier port number of an ATA device 365 on the ATA controller. 366 367 @retval EFI_SUCCESS DevicePath was successfully translated to a port number and port multiplier 368 port number, and they were returned in Port and PortMultiplierPort. 369 @retval EFI_INVALID_PARAMETER DevicePath is NULL. 370 @retval EFI_INVALID_PARAMETER Port is NULL. 371 @retval EFI_INVALID_PARAMETER PortMultiplierPort is NULL. 372 @retval EFI_UNSUPPORTED This driver does not support the device path node type in DevicePath. 373 @retval EFI_NOT_FOUND A valid translation from DevicePath to a port number and port multiplier 374 port number does not exist. 375 **/ 376 typedef 377 EFI_STATUS 378 (EFIAPI *EFI_ATA_PASS_THRU_GET_DEVICE)( 379 IN EFI_ATA_PASS_THRU_PROTOCOL *This, 380 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, 381 OUT UINT16 *Port, 382 OUT UINT16 *PortMultiplierPort 383 ); 384 385 /** 386 Resets a specific port on the ATA controller. This operation also resets all the ATA devices 387 connected to the port. 388 389 The ResetChannel() function resets an a specific port on an ATA controller. This operation 390 resets all the ATA devices connected to that port. If this ATA controller does not support 391 a reset port operation, then EFI_UNSUPPORTED is returned. 392 393 If a device error occurs while executing that port reset operation, then EFI_DEVICE_ERROR is 394 returned. 395 396 If a timeout occurs during the execution of the port reset operation, then EFI_TIMEOUT is returned. 397 398 If the port reset operation is completed, then EFI_SUCCESS is returned. 399 400 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance. 401 @param[in] Port The port number on the ATA controller. 402 403 @retval EFI_SUCCESS The ATA controller port was reset. 404 @retval EFI_UNSUPPORTED The ATA controller does not support a port reset operation. 405 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the ATA port. 406 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the ATA port. 407 408 **/ 409 typedef 410 EFI_STATUS 411 (EFIAPI *EFI_ATA_PASS_THRU_RESET_PORT)( 412 IN EFI_ATA_PASS_THRU_PROTOCOL *This, 413 IN UINT16 Port 414 ); 415 416 /** 417 Resets an ATA device that is connected to an ATA controller. 418 419 The ResetDevice() function resets the ATA device specified by Port and PortMultiplierPort. 420 If this ATA controller does not support a device reset operation, then EFI_UNSUPPORTED is 421 returned. 422 423 If Port or PortMultiplierPort are not in a valid range for this ATA controller, then 424 EFI_INVALID_PARAMETER is returned. 425 426 If a device error occurs while executing that device reset operation, then EFI_DEVICE_ERROR 427 is returned. 428 429 If a timeout occurs during the execution of the device reset operation, then EFI_TIMEOUT is 430 returned. 431 432 If the device reset operation is completed, then EFI_SUCCESS is returned. 433 434 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance. 435 @param[in] Port Port represents the port number of the ATA device to be reset. 436 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to reset. 437 If there is no port multiplier, then specify 0xFFFF. 438 @retval EFI_SUCCESS The ATA device specified by Port and PortMultiplierPort was reset. 439 @retval EFI_UNSUPPORTED The ATA controller does not support a device reset operation. 440 @retval EFI_INVALID_PARAMETER Port or PortMultiplierPort are invalid. 441 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the ATA device 442 specified by Port and PortMultiplierPort. 443 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the ATA device 444 specified by Port and PortMultiplierPort. 445 446 **/ 447 typedef 448 EFI_STATUS 449 (EFIAPI *EFI_ATA_PASS_THRU_RESET_DEVICE)( 450 IN EFI_ATA_PASS_THRU_PROTOCOL *This, 451 IN UINT16 Port, 452 IN UINT16 PortMultiplierPort 453 ); 454 455 struct _EFI_ATA_PASS_THRU_PROTOCOL { 456 EFI_ATA_PASS_THRU_MODE *Mode; 457 EFI_ATA_PASS_THRU_PASSTHRU PassThru; 458 EFI_ATA_PASS_THRU_GET_NEXT_PORT GetNextPort; 459 EFI_ATA_PASS_THRU_GET_NEXT_DEVICE GetNextDevice; 460 EFI_ATA_PASS_THRU_BUILD_DEVICE_PATH BuildDevicePath; 461 EFI_ATA_PASS_THRU_GET_DEVICE GetDevice; 462 EFI_ATA_PASS_THRU_RESET_PORT ResetPort; 463 EFI_ATA_PASS_THRU_RESET_DEVICE ResetDevice; 464 }; 465 466 extern EFI_GUID gEfiAtaPassThruProtocolGuid; 467 468 #endif 469