1 /** @file 2 3 Interface definition for EFI_SD_HOST_IO_PROTOCOL. 4 5 Copyright (c) 2013-2015 Intel Corporation. 6 7 SPDX-License-Identifier: BSD-2-Clause-Patent 8 9 **/ 10 11 #ifndef _SD_HOST_IO_H 12 #define _SD_HOST_IO_H 13 14 #include "SDCard.h" 15 #include "CEATA.h" 16 17 18 #define EFI_SD_HOST_IO_PROTOCOL_GUID \ 19 { \ 20 0xb63f8ec7, 0xa9c9, 0x4472, {0xa4, 0xc0, 0x4d, 0x8b, 0xf3, 0x65, 0xcc, 0x51} \ 21 } 22 23 /// 24 /// Forward reference for pure ANSI compatability 25 /// 26 typedef struct _EFI_SD_HOST_IO_PROTOCOL EFI_SD_HOST_IO_PROTOCOL; 27 28 29 30 typedef enum { 31 ResponseNo = 0, 32 ResponseR1, 33 ResponseR1b, 34 ResponseR2, 35 ResponseR3, 36 ResponseR4, 37 ResponseR5, 38 ResponseR5b, 39 ResponseR6, 40 ResponseR7 41 }RESPONSE_TYPE; 42 43 typedef enum { 44 NoData = 0, 45 InData, 46 OutData 47 }TRANSFER_TYPE; 48 49 typedef enum { 50 Reset_Auto = 0, 51 Reset_DAT, 52 Reset_CMD, 53 Reset_DAT_CMD, 54 Reset_All 55 }RESET_TYPE; 56 57 #define PCI_SUBCLASS_SD_HOST_CONTROLLER 0x05 58 #define PCI_IF_STANDARD_HOST_NO_DMA 0x00 59 #define PCI_IF_STANDARD_HOST_SUPPORT_DMA 0x01 60 61 #define SDHCI_SPEC_100 0 62 #define SDHCI_SPEC_200 1 63 #define SDHCI_SPEC_300 2 64 65 // 66 //MMIO Registers definition for MMC/SDIO controller 67 // 68 #define MMIO_DMAADR 0x00 69 #define MMIO_BLKSZ 0x04 70 #define MMIO_BLKCNT 0x06 71 #define MMIO_CMDARG 0x08 72 #define MMIO_XFRMODE 0x0C 73 #define MMIO_SDCMD 0x0E 74 #define MMIO_RESP 0x10 75 #define MMIO_BUFDATA 0x20 76 #define MMIO_PSTATE 0x24 77 #define MMIO_HOSTCTL 0x28 78 #define MMIO_PWRCTL 0x29 79 #define MMIO_BLKGAPCTL 0x2A 80 #define MMIO_WAKECTL 0x2B 81 #define MMIO_CLKCTL 0x2C 82 #define V_MMIO_CLKCTL_MAX_8BIT_FREQ_SEL 0x80 83 #define V_MMIO_CLKCTL_MAX_10BIT_FREQ_SEL 0x3FF 84 #define B_MMIO_CLKCTL_UPR_SDCLK_FREQ_SEL_MASK 0xC0 85 86 #define MMIO_TOCTL 0x2E 87 #define MMIO_SWRST 0x2F 88 #define MMIO_NINTSTS 0x30 89 #define MMIO_ERINTSTS 0x32 90 #define MMIO_NINTEN 0x34 91 #define MMIO_ERINTEN 0x36 92 #define MMIO_NINTSIGEN 0x38 93 #define MMIO_ERINTSIGEN 0x3A 94 #define MMIO_AC12ERRSTS 0x3C 95 #define MMIO_HOSTCTL2 0x3E 96 #define MMIO_CAP 0x40 97 #define MMIO_MCCAP 0x48 98 #define MMIO_SLTINTSTS 0xFC 99 #define MMIO_CTRLRVER 0xFE 100 #define MMIO_SRST 0x1FC 101 102 // 103 // Protocol definitions 104 // 105 106 /** 107 The main function used to send the command to the card inserted into the SD host slot. 108 It will assemble the arguments to set the command register and wait for the command 109 and transfer completed until timeout. Then it will read the response register to fill 110 the ResponseData. 111 112 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 113 @param CommandIndex The command index to set the command index field of command register. 114 @param Argument Command argument to set the argument field of command register. 115 @param DataType TRANSFER_TYPE, indicates no data, data in or data out. 116 @param Buffer Contains the data read from / write to the device. 117 @param BufferSize The size of the buffer. 118 @param ResponseType RESPONSE_TYPE. 119 @param TimeOut Time out value in 1 ms unit. 120 @param ResponseData Depending on the ResponseType, such as CSD or card status. 121 122 @retval EFI_SUCCESS 123 @retval EFI_INVALID_PARAMETER 124 @retval EFI_OUT_OF_RESOURCES 125 @retval EFI_TIMEOUT 126 @retval EFI_DEVICE_ERROR 127 128 **/ 129 130 typedef 131 EFI_STATUS 132 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SEND_COMMAND) ( 133 IN EFI_SD_HOST_IO_PROTOCOL *This, 134 IN UINT16 CommandIndex, 135 IN UINT32 Argument, 136 IN TRANSFER_TYPE DataType, 137 IN UINT8 *Buffer, OPTIONAL 138 IN UINT32 BufferSize, 139 IN RESPONSE_TYPE ResponseType, 140 IN UINT32 TimeOut, 141 OUT UINT32 *ResponseData OPTIONAL 142 ); 143 144 /** 145 Set max clock frequency of the host, the actual frequency may not be the same as MaxFrequency. 146 It depends on the max frequency the host can support, divider, and host speed mode. 147 148 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 149 @param MaxFrequency Max frequency in HZ. 150 151 @retval EFI_SUCCESS 152 @retval EFI_TIMEOUT 153 154 **/ 155 156 typedef 157 EFI_STATUS 158 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_CLOCK_FREQUENCY) ( 159 IN EFI_SD_HOST_IO_PROTOCOL *This, 160 IN UINT32 MaxFrequency 161 ); 162 163 164 /** 165 Set bus width of the host controller 166 167 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 168 @param BusWidth Bus width in 1, 4, 8 bits. 169 170 @retval EFI_SUCCESS 171 @retval EFI_INVALID_PARAMETER 172 173 **/ 174 175 typedef 176 EFI_STATUS 177 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_BUS_WIDTH) ( 178 IN EFI_SD_HOST_IO_PROTOCOL *This, 179 IN UINT32 BusWidth 180 ); 181 182 /** 183 Set voltage which could supported by the host controller. 184 Support 0(Power off the host), 1.8V, 3.0V, 3.3V 185 186 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 187 @param Voltage Units in 0.1 V. 188 189 @retval EFI_SUCCESS 190 @retval EFI_INVALID_PARAMETER 191 192 **/ 193 194 typedef 195 EFI_STATUS 196 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_HOST_VOLTAGE) ( 197 IN EFI_SD_HOST_IO_PROTOCOL *This, 198 IN UINT32 Voltage 199 ); 200 201 /** 202 Reset the host controller. 203 204 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 205 @param ResetAll TRUE to reset all. 206 207 @retval EFI_SUCCESS 208 @retval EFI_TIMEOUT 209 210 **/ 211 212 typedef 213 EFI_STATUS 214 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_RESET_SD_HOST) ( 215 IN EFI_SD_HOST_IO_PROTOCOL *This, 216 IN RESET_TYPE ResetType 217 ); 218 219 /** 220 Enable auto stop on the host controller. 221 222 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 223 @param Enable TRUE to enable, FALSE to disable. 224 225 @retval EFI_SUCCESS 226 @retval EFI_TIMEOUT 227 228 **/ 229 230 typedef 231 EFI_STATUS 232 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_ENABLE_AUTO_STOP_CMD) ( 233 IN EFI_SD_HOST_IO_PROTOCOL *This, 234 IN BOOLEAN Enable 235 ); 236 237 /** 238 Find whether these is a card inserted into the slot. If so init the host. 239 If not, return EFI_NOT_FOUND. 240 241 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 242 243 @retval EFI_SUCCESS 244 @retval EFI_NOT_FOUND 245 246 **/ 247 248 typedef 249 EFI_STATUS 250 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_DETECT_CARD_AND_INIT_HOST) ( 251 IN EFI_SD_HOST_IO_PROTOCOL *This 252 ); 253 254 /** 255 Set the Block length on the host controller. 256 257 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 258 @param BlockLength card supportes block length. 259 260 @retval EFI_SUCCESS 261 @retval EFI_TIMEOUT 262 263 **/ 264 265 typedef 266 EFI_STATUS 267 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_BLOCK_LENGTH) ( 268 IN EFI_SD_HOST_IO_PROTOCOL *This, 269 IN UINT32 BlockLength 270 ); 271 272 /** 273 Enable/Disable High Speed transfer mode 274 275 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 276 @param Enable TRUE to Enable, FALSE to Disable 277 278 @return EFI_SUCCESS 279 **/ 280 typedef 281 EFI_STATUS 282 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_HIGH_SPEED_MODE) ( 283 IN EFI_SD_HOST_IO_PROTOCOL *This, 284 IN BOOLEAN Enable 285 ); 286 287 typedef 288 EFI_STATUS 289 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_DUAL_DATARATE_MODE) ( 290 IN EFI_SD_HOST_IO_PROTOCOL *This, 291 IN BOOLEAN Enable 292 ); 293 294 295 296 #define EFI_SD_HOST_IO_PROTOCOL_REVISION_01 0x02 297 298 299 typedef struct { 300 UINT32 HighSpeedSupport: 1; //High speed supported 301 UINT32 V18Support: 1; //1.8V supported 302 UINT32 V30Support: 1; //3.0V supported 303 UINT32 V33Support: 1; //3.3V supported 304 UINT32 Reserved0: 4; 305 UINT32 HostVersion: 8; 306 UINT32 BusWidth4: 1; // 4 bit width 307 UINT32 BusWidth8: 1; // 8 bit width 308 UINT32 Reserved1: 14; 309 UINT32 BoundarySize; 310 }HOST_CAPABILITY; 311 312 313 // 314 // Interface structure for the SD HOST I/O Protocol 315 // 316 struct _EFI_SD_HOST_IO_PROTOCOL { 317 UINT32 Revision; 318 HOST_CAPABILITY HostCapability; 319 EFI_SD_HOST_IO_PROTOCOL_SEND_COMMAND SendCommand; 320 EFI_SD_HOST_IO_PROTOCOL_SET_CLOCK_FREQUENCY SetClockFrequency; 321 EFI_SD_HOST_IO_PROTOCOL_SET_BUS_WIDTH SetBusWidth; 322 EFI_SD_HOST_IO_PROTOCOL_SET_HOST_VOLTAGE SetHostVoltage; 323 EFI_SD_HOST_IO_PROTOCOL_RESET_SD_HOST ResetSDHost; 324 EFI_SD_HOST_IO_PROTOCOL_ENABLE_AUTO_STOP_CMD EnableAutoStopCmd; 325 EFI_SD_HOST_IO_PROTOCOL_DETECT_CARD_AND_INIT_HOST DetectCardAndInitHost; 326 EFI_SD_HOST_IO_PROTOCOL_SET_BLOCK_LENGTH SetBlockLength; 327 EFI_SD_HOST_IO_PROTOCOL_HIGH_SPEED_MODE SetHighSpeedMode; 328 EFI_SD_HOST_IO_PROTOCOL_DUAL_DATARATE_MODE SetDDRMode; 329 }; 330 331 extern EFI_GUID gEfiSDHostIoProtocolGuid; 332 333 #endif 334