3 The definition for SD media device driver model and blkio protocol routines.
5 Copyright (c) 2013-2016 Intel Corporation.
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #ifndef _SD_MEDIA_DEVICE_H_
12 #define _SD_MEDIA_DEVICE_H_
17 #include <Protocol/PciIo.h>
18 #include <Protocol/BlockIo.h>
20 #include <Library/DebugLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/UefiDriverEntryPoint.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/UefiLib.h>
25 #include <Library/BaseLib.h>
26 #include <Library/MemoryAllocationLib.h>
27 #include <Library/PcdLib.h>
28 #include <IndustryStandard/Pci22.h>
30 #include "ComponentName.h"
34 extern EFI_DRIVER_BINDING_PROTOCOL gSDMediaDeviceDriverBinding
;
35 extern EFI_COMPONENT_NAME_PROTOCOL gSDMediaDeviceName
;
36 extern EFI_COMPONENT_NAME2_PROTOCOL gSDMediaDeviceName2
;
39 // Define the region of memory used for DMA memory
41 #define DMA_MEMORY_TOP 0x0000000001FFFFFFULL
43 #define CARD_DATA_SIGNATURE SIGNATURE_32 ('c', 'a', 'r', 'd')
46 // Command timeout will be max 100 ms
48 #define TIMEOUT_COMMAND 100
49 #define TIMEOUT_DATA 5000
54 MMCCardHighCap
, // MMC Card High Capacity
55 CEATACard
, // CE-ATA device
56 SDMemoryCard
, // SD 1.1 card
57 SDMemoryCard2
, // SD 2.0 or above standard card
58 SDMemoryCard2High
// SD 2.0 or above high capacity card
67 EFI_BLOCK_IO_PROTOCOL BlockIo
;
69 EFI_BLOCK_IO_MEDIA BlockIoMedia
;
71 EFI_SD_HOST_IO_PROTOCOL
*SDHostIo
;
72 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
75 UINT8 CurrentBusWidth
;
87 CARD_STATUS CardStatus
;
91 EXT_CSD ExtCSDRegister
;
92 UINT8
*RawBufferPointer
;
98 IDENTIFY_DEVICE_DATA IndentifyDeviceData
;
103 SD_STATUS_REG SDSattus
;
104 SWITCH_STATUS SwitchStatus
;
107 #define CARD_DATA_FROM_THIS(a) \
108 CR(a, CARD_DATA, BlockIo, CARD_DATA_SIGNATURE)
111 Test to see if this driver supports ControllerHandle. Any
112 ControllerHandle that has BlockIoProtocol installed will be supported.
114 @param This Protocol instance pointer.
115 @param Controller Handle of device to test.
116 @param RemainingDevicePath Not used.
118 @return EFI_SUCCESS This driver supports this device.
119 @return EFI_UNSUPPORTED This driver does not support this device.
124 SDMediaDeviceSupported (
125 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
126 IN EFI_HANDLE Controller
,
127 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
131 Starting the SD Media Device Driver.
133 @param This Protocol instance pointer.
134 @param Controller Handle of device to test.
135 @param RemainingDevicePath Not used.
137 @retval EFI_SUCCESS This driver supports this device.
138 @retval EFI_UNSUPPORTED This driver does not support this device.
139 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
140 EFI_OUT_OF_RESOURCES- Failed due to resource shortage.
146 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
147 IN EFI_HANDLE Controller
,
148 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
152 Stop this driver on ControllerHandle. Support stopping any child handles
153 created by this driver.
155 @param This Protocol instance pointer.
156 @param Controller Handle of device to stop driver on.
157 @param NumberOfChildren Number of Children in the ChildHandleBuffer.
158 @param ChildHandleBuffer List of handles for the children we need to stop.
167 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
168 IN EFI_HANDLE Controller
,
169 IN UINTN NumberOfChildren
,
170 IN EFI_HANDLE
*ChildHandleBuffer
174 MMC/SD card init function
176 @param CardData Pointer to CARD_DATA.
184 IN CARD_DATA
*CardData
188 Send command by using Host IO protocol
190 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
191 @param CommandIndex The command index to set the command index field of command register.
192 @param Argument Command argument to set the argument field of command register.
193 @param DataType TRANSFER_TYPE, indicates no data, data in or data out.
194 @param Buffer Contains the data read from / write to the device.
195 @param BufferSize The size of the buffer.
196 @param ResponseType RESPONSE_TYPE.
197 @param TimeOut Time out value in 1 ms unit.
198 @param ResponseData Depending on the ResponseType, such as CSD or card status.
201 @retval EFI_INVALID_PARAMETER
202 @retval EFI_UNSUPPORTED
203 @retval EFI_DEVICE_ERROR
208 IN CARD_DATA
*CardData
,
209 IN UINT16 CommandIndex
,
211 IN TRANSFER_TYPE DataType
,
212 IN UINT8
*Buffer
, OPTIONAL
213 IN UINT32 BufferSize
,
214 IN RESPONSE_TYPE ResponseType
,
216 OUT UINT32
*ResponseData
220 Send the card APP_CMD command with the following command indicated by CommandIndex
222 @param CardData Pointer to CARD_DATA.
223 @param CommandIndex The command index to set the command index field of command register.
224 @param Argument Command argument to set the argument field of command register.
225 @param DataType TRANSFER_TYPE, indicates no data, data in or data out.
226 @param Buffer Contains the data read from / write to the device.
227 @param BufferSize The size of the buffer.
228 @param ResponseType RESPONSE_TYPE.
229 @param TimeOut Time out value in 1 ms unit.
230 @param ResponseData Depending on the ResponseType, such as CSD or card status.
233 @retval EFI_INVALID_PARAMETER
234 @retval EFI_UNSUPPORTED
235 @retval EFI_DEVICE_ERROR
240 IN CARD_DATA
*CardData
,
241 IN UINT16 CommandIndex
,
243 IN TRANSFER_TYPE DataType
,
244 IN UINT8
*Buffer
, OPTIONAL
245 IN UINT32 BufferSize
,
246 IN RESPONSE_TYPE ResponseType
,
248 OUT UINT32
*ResponseData
252 Send the card FAST_IO command
254 @param CardData Pointer to CARD_DATA.
255 @param RegisterAddress Register Address.
256 @param RegisterData Pointer to register Data.
257 @param Write TRUE for write, FALSE for read.
260 @retval EFI_UNSUPPORTED
261 @retval EFI_INVALID_PARAMETER
262 @retval EFI_DEVICE_ERROR
267 IN CARD_DATA
*CardData
,
268 IN UINT8 RegisterAddress
,
269 IN OUT UINT8
*RegisterData
,
274 Judge whether it is CE-ATA device or not.
276 @param CardData Pointer to CARD_DATA.
284 IN CARD_DATA
*CardData
290 @param CardData Pointer to CARD_DATA.
292 @retval EFI_SUCCESS Success
293 @retval EFI_DEVICE_ERROR Hardware Error
294 @retval EFI_INVALID_PARAMETER Parameter is error
295 @retval EFI_NO_MEDIA No media
296 @retval EFI_MEDIA_CHANGED Media Change
297 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
302 IN CARD_DATA
*CardData
306 SendATACommand specificed in Taskfile
308 @param CardData Pointer to CARD_DATA.
309 @param TaskFile Pointer to TASK_FILE.
310 @param Write TRUE means write, FALSE means read.
311 @param Buffer If NULL, means no data transfer, neither read nor write.
312 @param SectorCount Buffer size in 512 bytes unit.
314 @retval EFI_SUCCESS Success
315 @retval EFI_DEVICE_ERROR Hardware Error
316 @retval EFI_INVALID_PARAMETER Parameter is error
317 @retval EFI_NO_MEDIA No media
318 @retval EFI_MEDIA_CHANGED Media Change
319 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
324 IN CARD_DATA
*CardData
,
325 IN TASK_FILE
*TaskFile
,
328 IN UINT16 SectorCount
332 IDENTIFY_DEVICE command
334 @param CardData Pointer to CARD_DATA.
336 @retval EFI_SUCCESS Success
337 @retval EFI_DEVICE_ERROR Hardware Error
338 @retval EFI_INVALID_PARAMETER Parameter is error
339 @retval EFI_NO_MEDIA No media
340 @retval EFI_MEDIA_CHANGED Media Change
341 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
346 IN CARD_DATA
*CardData
350 FLUSH_CACHE_EXT command
352 @param CardData Pointer to CARD_DATA.
354 @retval EFI_SUCCESS Success
355 @retval EFI_DEVICE_ERROR Hardware Error
356 @retval EFI_INVALID_PARAMETER Parameter is error
357 @retval EFI_NO_MEDIA No media
358 @retval EFI_MEDIA_CHANGED Media Change
359 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
364 IN CARD_DATA
*CardData
368 STANDBY_IMMEDIATE command
370 @param CardData Pointer to CARD_DATA.
372 @retval EFI_SUCCESS Success
373 @retval EFI_DEVICE_ERROR Hardware Error
374 @retval EFI_INVALID_PARAMETER Parameter is error
375 @retval EFI_NO_MEDIA No media
376 @retval EFI_MEDIA_CHANGED Media Change
377 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
382 IN CARD_DATA
*CardData
388 @param CardData Pointer to CARD_DATA.
389 @param LBA The starting logical block address to read from on the device.
390 @param Buffer A pointer to the destination buffer for the data. The caller
391 is responsible for either having implicit or explicit ownership
393 @param SectorCount Size in 512 bytes unit.
395 @retval EFI_SUCCESS Success
396 @retval EFI_DEVICE_ERROR Hardware Error
397 @retval EFI_INVALID_PARAMETER Parameter is error
398 @retval EFI_NO_MEDIA No media
399 @retval EFI_MEDIA_CHANGED Media Change
400 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
405 IN CARD_DATA
*CardData
,
408 IN UINT16 SectorCount
412 WRITE_DMA_EXT command
414 @param CardData Pointer to CARD_DATA.
415 @param LBA The starting logical block address to read from on the device.
416 @param Buffer A pointer to the destination buffer for the data. The caller
417 is responsible for either having implicit or explicit ownership
419 @param SectorCount Size in 512 bytes unit.
421 @retval EFI_SUCCESS Success
422 @retval EFI_DEVICE_ERROR Hardware Error
423 @retval EFI_INVALID_PARAMETER Parameter is error
424 @retval EFI_NO_MEDIA No media
425 @retval EFI_MEDIA_CHANGED Media Change
426 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
431 IN CARD_DATA
*CardData
,
434 IN UINT16 SectorCount
438 CEATA card BlockIo init function.
440 @param CardData Pointer to CARD_DATA.
447 IN CARD_DATA
*CardData
451 MMC/SD card BlockIo init function.
453 @param CardData Pointer to CARD_DATA.
460 IN CARD_DATA
*CardData