1 /*++ 2 3 Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved 4 5 This program and the accompanying materials are licensed and made available under 6 the terms and conditions of the BSD License that accompanies this distribution. 7 The full text of the license may be found at 8 http://opensource.org/licenses/bsd-license.php. 9 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 13 14 --*/ 15 16 17 /*++ 18 Module Name: 19 20 SdHostIo.h 21 22 Abstract: 23 24 Interface definition for EFI_SD_HOST_IO_PROTOCOL 25 26 --*/ 27 28 #ifndef _SD_HOST_IO_H 29 #define _SD_HOST_IO_H 30 31 32 // Global ID for the EFI_SD_HOST_IO_PROTOCOL 33 // {B63F8EC7-A9C9-4472-A4C0-4D8BF365CC51} 34 // 35 #define EFI_SD_HOST_IO_PROTOCOL_GUID \ 36 { 0xb63f8ec7, 0xa9c9, 0x4472, { 0xa4, 0xc0, 0x4d, 0x8b, 0xf3, 0x65, 0xcc, 0x51 } } 37 38 typedef struct _EFI_SD_HOST_IO_PROTOCOL EFI_SD_HOST_IO_PROTOCOL; 39 40 // 41 // TODO: Move to Pci22.h 42 // 43 #define PCI_SUBCLASS_SD_HOST_CONTROLLER 0x05 44 #define PCI_IF_STANDARD_HOST_NO_DMA 0x00 45 #define PCI_IF_STANDARD_HOST_SUPPORT_DMA 0x01 46 47 // 48 // TODO: Retire 49 // 50 #define EFI_SD_HOST_IO_PROTOCOL_REVISION_01 0x01 51 52 // 53 // TODO: Do these belong in an Industry Standard include file? 54 // 55 // MMIO Registers definition for MMC/SDIO controller 56 // 57 #define MMIO_DMAADR 0x00 58 #define MMIO_BLKSZ 0x04 59 #define MMIO_BLKCNT 0x06 60 #define MMIO_CMDARG 0x08 61 #define MMIO_XFRMODE 0x0C 62 #define MMIO_SDCMD 0x0E 63 #define MMIO_RESP 0x10 64 #define MMIO_BUFDATA 0x20 65 #define MMIO_PSTATE 0x24 66 #define MMIO_HOSTCTL 0x28 67 #define MMIO_PWRCTL 0x29 68 #define MMIO_BLKGAPCTL 0x2A 69 #define MMIO_WAKECTL 0x2B 70 #define MMIO_CLKCTL 0x2C 71 #define MMIO_TOCTL 0x2E 72 #define MMIO_SWRST 0x2F 73 #define MMIO_NINTSTS 0x30 74 #define MMIO_ERINTSTS 0x32 75 #define MMIO_NINTEN 0x34 76 #define MMIO_ERINTEN 0x36 77 #define MMIO_NINTSIGEN 0x38 78 #define MMIO_ERINTSIGEN 0x3A 79 #define MMIO_AC12ERRSTS 0x3C 80 #define MMIO_HOST_CTL2 0x3E //hphang <- New in VLV2 81 #define MMIO_CAP 0x40 82 #define MMIO_CAP2 0x44 //hphang <- New in VLV2 83 #define MMIO_MCCAP 0x48 84 #define MMIO_FORCEEVENTCMD12ERRSTAT 0x50 //hphang <- New in VLV2 85 #define MMIO_FORCEEVENTERRINTSTAT 0x52 //hphang <- New in VLV2 86 #define MMIO_ADMAERRSTAT 0x54 //hphang <- New in VLV2 87 #define MMIO_ADMASYSADDR 0x58 //hphang <- New in VLV2 88 #define MMIO_PRESETVALUE0 0x60 //hphang <- New in VLV2 89 #define MMIO_PRESETVALUE1 0x64 //hphang <- New in VLV2 90 #define MMIO_PRESETVALUE2 0x68 //hphang <- New in VLV2 91 #define MMIO_PRESETVALUE3 0x6C //hphang <- New in VLV2 92 #define MMIO_BOOTTIMEOUTCTRL 0x70 //hphang <- New in VLV2 93 #define MMIO_DEBUGSEL 0x74 //hphang <- New in VLV2 94 #define MMIO_SHAREDBUS 0xE0 //hphang <- New in VLV2 95 #define MMIO_SPIINTSUP 0xF0 //hphang <- New in VLV2 96 #define MMIO_SLTINTSTS 0xFC 97 #define MMIO_CTRLRVER 0xFE 98 99 typedef enum { 100 ResponseNo = 0, 101 ResponseR1, 102 ResponseR1b, 103 ResponseR2, 104 ResponseR3, 105 ResponseR4, 106 ResponseR5, 107 ResponseR5b, 108 ResponseR6, 109 ResponseR7 110 } RESPONSE_TYPE; 111 112 typedef enum { 113 NoData = 0, 114 InData, 115 OutData 116 } TRANSFER_TYPE; 117 118 typedef enum { 119 Reset_Auto = 0, 120 Reset_DAT, 121 Reset_CMD, 122 Reset_DAT_CMD, 123 Reset_All, 124 Reset_HW 125 } RESET_TYPE; 126 127 128 typedef enum { 129 SDMA = 0, 130 ADMA2, 131 PIO 132 } DMA_MOD; 133 134 typedef struct { 135 UINT32 HighSpeedSupport: 1; //High speed supported 136 UINT32 V18Support: 1; //1.8V supported 137 UINT32 V30Support: 1; //3.0V supported 138 UINT32 V33Support: 1; //3.3V supported 139 UINT32 SDR50Support: 1; 140 UINT32 SDR104Support: 1; 141 UINT32 DDR50Support: 1; 142 UINT32 Reserved0: 1; 143 UINT32 BusWidth4: 1; // 4 bit width 144 UINT32 BusWidth8: 1; // 8 bit width 145 UINT32 Reserved1: 6; 146 UINT32 SDMASupport: 1; 147 UINT32 ADMA2Support: 1; 148 UINT32 DmaMode: 2; 149 UINT32 ReTuneTimer: 4; 150 UINT32 ReTuneMode: 2; 151 UINT32 Reserved2: 6; 152 UINT32 BoundarySize; 153 } HOST_CAPABILITY; 154 155 /*++ 156 157 Routine Description: 158 The main function used to send the command to the card inserted into the SD host 159 slot. 160 It will assemble the arguments to set the command register and wait for the command 161 and transfer completed until timeout. Then it will read the response register to fill 162 the ResponseData 163 164 Arguments: 165 This - Pointer to EFI_SD_HOST_IO_PROTOCOL 166 CommandIndex - The command index to set the command index field of command register 167 Argument - Command argument to set the argument field of command register 168 DataType - TRANSFER_TYPE, indicates no data, data in or data out 169 Buffer - Contains the data read from / write to the device 170 BufferSize - The size of the buffer 171 ResponseType - RESPONSE_TYPE 172 TimeOut - Time out value in 1 ms unit 173 ResponseData - Depending on the ResponseType, such as CSD or card status 174 175 Returns: 176 EFI_SUCCESS 177 EFI_INVALID_PARAMETER 178 EFI_OUT_OF_RESOURCES 179 EFI_TIMEOUT 180 EFI_DEVICE_ERROR 181 182 --*/ 183 typedef 184 EFI_STATUS 185 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SEND_COMMAND) ( 186 IN EFI_SD_HOST_IO_PROTOCOL *This, 187 IN UINT16 CommandIndex, 188 IN UINT32 Argument, 189 IN TRANSFER_TYPE DataType, 190 IN UINT8 *Buffer, OPTIONAL 191 IN UINT32 BufferSize, 192 IN RESPONSE_TYPE ResponseType, 193 IN UINT32 TimeOut, 194 OUT UINT32 *ResponseData OPTIONAL 195 ); 196 197 /*++ 198 199 Routine Description: 200 Set max clock frequency of the host, the actual frequency 201 may not be the same as MaxFrequency. It depends on 202 the max frequency the host can support, divider, and host 203 speed mode. 204 205 Arguments: 206 This - Pointer to EFI_SD_HOST_IO_PROTOCOL 207 MaxFrequency - Max frequency in HZ 208 209 Returns: 210 EFI_SUCCESS 211 EFI_TIMEOUT 212 --*/ 213 typedef 214 EFI_STATUS 215 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_CLOCK_FREQUENCY) ( 216 IN EFI_SD_HOST_IO_PROTOCOL *This, 217 IN UINT32 MaxFrequency 218 ); 219 220 /*++ 221 222 Routine Description: 223 Set bus width of the host 224 225 Arguments: 226 This - Pointer to EFI_SD_HOST_IO_PROTOCOL 227 BusWidth - Bus width in 1, 4, 8 bits 228 229 Returns: 230 EFI_SUCCESS 231 EFI_INVALID_PARAMETER 232 233 --*/ 234 typedef 235 EFI_STATUS 236 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_BUS_WIDTH) ( 237 IN EFI_SD_HOST_IO_PROTOCOL *This, 238 IN UINT32 BusWidth 239 ); 240 241 /*++ 242 243 Routine Description: 244 Set voltage which could supported by the host. 245 Support 0(Power off the host), 1.8V, 3.0V, 3.3V 246 Arguments: 247 This - Pointer to EFI_SD_HOST_IO_PROTOCOL 248 Voltage - Units in 0.1 V 249 250 Returns: 251 EFI_SUCCESS 252 EFI_INVALID_PARAMETER 253 254 --*/ 255 typedef 256 EFI_STATUS 257 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_HOST_VOLTAGE) ( 258 IN EFI_SD_HOST_IO_PROTOCOL *This, 259 IN UINT32 Voltage 260 ); 261 262 /*++ 263 264 Routine Description: 265 Set Host High Speed 266 Arguments: 267 This - Pointer to EFI_SD_HOST_IO_PROTOCOL 268 HighSpeed - True for High Speed Mode set, false for normal mode 269 270 Returns: 271 EFI_SUCCESS 272 EFI_INVALID_PARAMETER 273 274 --*/ 275 typedef 276 EFI_STATUS 277 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_HOST_SPEED_MODE) ( 278 IN EFI_SD_HOST_IO_PROTOCOL *This, 279 IN UINT32 HighSpeed 280 ); 281 282 /*++ 283 284 Routine Description: 285 Set High Speed Mode 286 Arguments: 287 This - Pointer to EFI_SD_HOST_IO_PROTOCOL 288 SetHostDdrMode - True for DDR Mode set, false for normal mode 289 290 Returns: 291 EFI_SUCCESS 292 EFI_INVALID_PARAMETER 293 294 --*/ 295 typedef 296 EFI_STATUS 297 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_HOST_DDR_MODE) ( 298 IN EFI_SD_HOST_IO_PROTOCOL *This, 299 IN UINT32 DdrMode 300 ); 301 302 303 /*++ 304 305 Routine Description: 306 Reset the host 307 308 Arguments: 309 This - Pointer to EFI_SD_HOST_IO_PROTOCOL 310 ResetAll - TRUE to reset all 311 312 Returns: 313 EFI_SUCCESS 314 EFI_TIMEOUT 315 316 --*/ 317 typedef 318 EFI_STATUS 319 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_RESET_SD_HOST) ( 320 IN EFI_SD_HOST_IO_PROTOCOL *This, 321 IN RESET_TYPE ResetType 322 ); 323 324 /*++ 325 326 Routine Description: 327 Reset the host 328 329 Arguments: 330 This - Pointer to EFI_SD_HOST_IO_PROTOCOL 331 Enable - TRUE to enable, FALSE to disable 332 333 Returns: 334 EFI_SUCCESS 335 EFI_TIMEOUT 336 337 --*/ 338 typedef 339 EFI_STATUS 340 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_ENABLE_AUTO_STOP_CMD) ( 341 IN EFI_SD_HOST_IO_PROTOCOL *This, 342 IN BOOLEAN Enable 343 ); 344 345 /*++ 346 347 Routine Description: 348 Find whether these is a card inserted into the slot. If so 349 init the host. If not, return EFI_NOT_FOUND. 350 351 Arguments: 352 This - Pointer to EFI_SD_HOST_IO_PROTOCOL 353 354 Returns: 355 EFI_SUCCESS 356 EFI_NOT_FOUND 357 358 --*/ 359 typedef 360 EFI_STATUS 361 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_DETECT_CARD_AND_INIT_HOST) ( 362 IN EFI_SD_HOST_IO_PROTOCOL *This 363 ); 364 365 /*++ 366 367 Routine Description: 368 Set the Block length 369 370 Arguments: 371 This - Pointer to EFI_SD_HOST_IO_PROTOCOL 372 BlockLength - card supportes block length 373 374 Returns: 375 EFI_SUCCESS 376 EFI_TIMEOUT 377 378 --*/ 379 typedef 380 EFI_STATUS 381 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_BLOCK_LENGTH) ( 382 IN EFI_SD_HOST_IO_PROTOCOL *This, 383 IN UINT32 BlockLength 384 ); 385 386 typedef EFI_STATUS 387 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SETUP_DEVICE)( 388 IN EFI_SD_HOST_IO_PROTOCOL *This 389 ); 390 391 392 393 // 394 // Interface structure for the EFI SD Host I/O Protocol 395 // 396 struct _EFI_SD_HOST_IO_PROTOCOL { 397 UINT32 Revision; 398 HOST_CAPABILITY HostCapability; 399 EFI_SD_HOST_IO_PROTOCOL_SEND_COMMAND SendCommand; 400 EFI_SD_HOST_IO_PROTOCOL_SET_CLOCK_FREQUENCY SetClockFrequency; 401 EFI_SD_HOST_IO_PROTOCOL_SET_BUS_WIDTH SetBusWidth; 402 EFI_SD_HOST_IO_PROTOCOL_SET_HOST_VOLTAGE SetHostVoltage; 403 EFI_SD_HOST_IO_PROTOCOL_SET_HOST_DDR_MODE SetHostDdrMode; 404 EFI_SD_HOST_IO_PROTOCOL_RESET_SD_HOST ResetSdHost; 405 EFI_SD_HOST_IO_PROTOCOL_ENABLE_AUTO_STOP_CMD EnableAutoStopCmd; 406 EFI_SD_HOST_IO_PROTOCOL_DETECT_CARD_AND_INIT_HOST DetectCardAndInitHost; 407 EFI_SD_HOST_IO_PROTOCOL_SET_BLOCK_LENGTH SetBlockLength; 408 EFI_SD_HOST_IO_PROTOCOL_SETUP_DEVICE SetupDevice; 409 EFI_SD_HOST_IO_PROTOCOL_SET_HOST_SPEED_MODE SetHostSpeedMode; 410 }; 411 412 extern EFI_GUID gEfiSdHostIoProtocolGuid; 413 414 #endif 415 416