3 The definition for SD media device driver model and blkio protocol routines.
5 Copyright (c) 2013-2015 Intel Corporation.
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #ifndef _SD_MEDIA_DEVICE_H_
18 #define _SD_MEDIA_DEVICE_H_
23 #include <Protocol/PciIo.h>
24 #include <Protocol/BlockIo.h>
26 #include <Library/DebugLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/UefiLib.h>
31 #include <Library/BaseLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/PcdLib.h>
34 #include <IndustryStandard/Pci22.h>
36 #include "ComponentName.h"
40 extern EFI_DRIVER_BINDING_PROTOCOL gSDMediaDeviceDriverBinding
;
41 extern EFI_COMPONENT_NAME_PROTOCOL gSDMediaDeviceName
;
42 extern EFI_COMPONENT_NAME2_PROTOCOL gSDMediaDeviceName2
;
45 // Define the region of memory used for DMA memory
47 #define DMA_MEMORY_TOP 0x0000000001FFFFFFULL
49 #define CARD_DATA_SIGNATURE SIGNATURE_32 ('c', 'a', 'r', 'd')
52 // Command timeout will be max 100 ms
54 #define TIMEOUT_COMMAND 100
55 #define TIMEOUT_DATA 5000
60 MMCCardHighCap
, // MMC Card High Capacity
61 CEATACard
, // CE-ATA device
62 SDMemoryCard
, // SD 1.1 card
63 SDMemoryCard2
, // SD 2.0 or above standard card
64 SDMemoryCard2High
// SD 2.0 or above high capacity card
73 EFI_BLOCK_IO_PROTOCOL BlockIo
;
75 EFI_BLOCK_IO_MEDIA BlockIoMedia
;
77 EFI_SD_HOST_IO_PROTOCOL
*SDHostIo
;
78 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
81 UINT8 CurrentBusWidth
;
93 CARD_STATUS CardStatus
;
97 EXT_CSD ExtCSDRegister
;
98 UINT8
*RawBufferPointer
;
104 IDENTIFY_DEVICE_DATA IndentifyDeviceData
;
109 SD_STATUS_REG SDSattus
;
110 SWITCH_STATUS SwitchStatus
;
113 #define CARD_DATA_FROM_THIS(a) \
114 CR(a, CARD_DATA, BlockIo, CARD_DATA_SIGNATURE)
117 Test to see if this driver supports ControllerHandle. Any
118 ControllerHandle that has BlockIoProtocol installed will be supported.
120 @param This Protocol instance pointer.
121 @param Controller Handle of device to test.
122 @param RemainingDevicePath Not used.
124 @return EFI_SUCCESS This driver supports this device.
125 @return EFI_UNSUPPORTED This driver does not support this device.
130 SDMediaDeviceSupported (
131 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
132 IN EFI_HANDLE Controller
,
133 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
137 Starting the SD Media Device Driver.
139 @param This Protocol instance pointer.
140 @param Controller Handle of device to test.
141 @param RemainingDevicePath Not used.
143 @retval EFI_SUCCESS This driver supports this device.
144 @retval EFI_UNSUPPORTED This driver does not support this device.
145 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
146 EFI_OUT_OF_RESOURCES- Failed due to resource shortage.
152 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
153 IN EFI_HANDLE Controller
,
154 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
158 Stop this driver on ControllerHandle. Support stoping any child handles
159 created by this driver.
161 @param This Protocol instance pointer.
162 @param Controller Handle of device to stop driver on.
163 @param NumberOfChildren Number of Children in the ChildHandleBuffer.
164 @param ChildHandleBuffer List of handles for the children we need to stop.
173 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
174 IN EFI_HANDLE Controller
,
175 IN UINTN NumberOfChildren
,
176 IN EFI_HANDLE
*ChildHandleBuffer
180 MMC/SD card init function
182 @param CardData Pointer to CARD_DATA.
190 IN CARD_DATA
*CardData
194 Send command by using Host IO protocol
196 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
197 @param CommandIndex The command index to set the command index field of command register.
198 @param Argument Command argument to set the argument field of command register.
199 @param DataType TRANSFER_TYPE, indicates no data, data in or data out.
200 @param Buffer Contains the data read from / write to the device.
201 @param BufferSize The size of the buffer.
202 @param ResponseType RESPONSE_TYPE.
203 @param TimeOut Time out value in 1 ms unit.
204 @param ResponseData Depending on the ResponseType, such as CSD or card status.
207 @retval EFI_INVALID_PARAMETER
208 @retval EFI_UNSUPPORTED
209 @retval EFI_DEVICE_ERROR
214 IN CARD_DATA
*CardData
,
215 IN UINT16 CommandIndex
,
217 IN TRANSFER_TYPE DataType
,
218 IN UINT8
*Buffer
, OPTIONAL
219 IN UINT32 BufferSize
,
220 IN RESPONSE_TYPE ResponseType
,
222 OUT UINT32
*ResponseData
226 Send the card APP_CMD command with the following command indicated by CommandIndex
228 @param CardData Pointer to CARD_DATA.
229 @param CommandIndex The command index to set the command index field of command register.
230 @param Argument Command argument to set the argument field of command register.
231 @param DataType TRANSFER_TYPE, indicates no data, data in or data out.
232 @param Buffer Contains the data read from / write to the device.
233 @param BufferSize The size of the buffer.
234 @param ResponseType RESPONSE_TYPE.
235 @param TimeOut Time out value in 1 ms unit.
236 @param ResponseData Depending on the ResponseType, such as CSD or card status.
239 @retval EFI_INVALID_PARAMETER
240 @retval EFI_UNSUPPORTED
241 @retval EFI_DEVICE_ERROR
246 IN CARD_DATA
*CardData
,
247 IN UINT16 CommandIndex
,
249 IN TRANSFER_TYPE DataType
,
250 IN UINT8
*Buffer
, OPTIONAL
251 IN UINT32 BufferSize
,
252 IN RESPONSE_TYPE ResponseType
,
254 OUT UINT32
*ResponseData
258 Send the card FAST_IO command
260 @param CardData Pointer to CARD_DATA.
261 @param RegisterAddress Register Address.
262 @param RegisterData Pointer to register Data.
263 @param Write TRUE for write, FALSE for read.
266 @retval EFI_UNSUPPORTED
267 @retval EFI_INVALID_PARAMETER
268 @retval EFI_DEVICE_ERROR
273 IN CARD_DATA
*CardData
,
274 IN UINT8 RegisterAddress
,
275 IN OUT UINT8
*RegisterData
,
280 Judge whether it is CE-ATA device or not.
282 @param CardData Pointer to CARD_DATA.
290 IN CARD_DATA
*CardData
296 @param CardData Pointer to CARD_DATA.
298 @retval EFI_SUCCESS Success
299 @retval EFI_DEVICE_ERROR Hardware Error
300 @retval EFI_INVALID_PARAMETER Parameter is error
301 @retval EFI_NO_MEDIA No media
302 @retval EFI_MEDIA_CHANGED Media Change
303 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
308 IN CARD_DATA
*CardData
312 SendATACommand specificed in Taskfile
314 @param CardData Pointer to CARD_DATA.
315 @param TaskFile Pointer to TASK_FILE.
316 @param Write TRUE means write, FALSE means read.
317 @param Buffer If NULL, means no data transfer, neither read nor write.
318 @param SectorCount Buffer size in 512 bytes unit.
320 @retval EFI_SUCCESS Success
321 @retval EFI_DEVICE_ERROR Hardware Error
322 @retval EFI_INVALID_PARAMETER Parameter is error
323 @retval EFI_NO_MEDIA No media
324 @retval EFI_MEDIA_CHANGED Media Change
325 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
330 IN CARD_DATA
*CardData
,
331 IN TASK_FILE
*TaskFile
,
334 IN UINT16 SectorCount
338 IDENTIFY_DEVICE command
340 @param CardData Pointer to CARD_DATA.
342 @retval EFI_SUCCESS Success
343 @retval EFI_DEVICE_ERROR Hardware Error
344 @retval EFI_INVALID_PARAMETER Parameter is error
345 @retval EFI_NO_MEDIA No media
346 @retval EFI_MEDIA_CHANGED Media Change
347 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
352 IN CARD_DATA
*CardData
356 FLUSH_CACHE_EXT command
358 @param CardData Pointer to CARD_DATA.
360 @retval EFI_SUCCESS Success
361 @retval EFI_DEVICE_ERROR Hardware Error
362 @retval EFI_INVALID_PARAMETER Parameter is error
363 @retval EFI_NO_MEDIA No media
364 @retval EFI_MEDIA_CHANGED Media Change
365 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
370 IN CARD_DATA
*CardData
374 STANDBY_IMMEDIATE command
376 @param CardData Pointer to CARD_DATA.
378 @retval EFI_SUCCESS Success
379 @retval EFI_DEVICE_ERROR Hardware Error
380 @retval EFI_INVALID_PARAMETER Parameter is error
381 @retval EFI_NO_MEDIA No media
382 @retval EFI_MEDIA_CHANGED Media Change
383 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
388 IN CARD_DATA
*CardData
394 @param CardData Pointer to CARD_DATA.
395 @param LBA The starting logical block address to read from on the device.
396 @param Buffer A pointer to the destination buffer for the data. The caller
397 is responsible for either having implicit or explicit ownership
399 @param SectorCount Size in 512 bytes unit.
401 @retval EFI_SUCCESS Success
402 @retval EFI_DEVICE_ERROR Hardware Error
403 @retval EFI_INVALID_PARAMETER Parameter is error
404 @retval EFI_NO_MEDIA No media
405 @retval EFI_MEDIA_CHANGED Media Change
406 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
411 IN CARD_DATA
*CardData
,
414 IN UINT16 SectorCount
418 WRITE_DMA_EXT command
420 @param CardData Pointer to CARD_DATA.
421 @param LBA The starting logical block address to read from on the device.
422 @param Buffer A pointer to the destination buffer for the data. The caller
423 is responsible for either having implicit or explicit ownership
425 @param SectorCount Size in 512 bytes unit.
427 @retval EFI_SUCCESS Success
428 @retval EFI_DEVICE_ERROR Hardware Error
429 @retval EFI_INVALID_PARAMETER Parameter is error
430 @retval EFI_NO_MEDIA No media
431 @retval EFI_MEDIA_CHANGED Media Change
432 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
437 IN CARD_DATA
*CardData
,
440 IN UINT16 SectorCount
444 CEATA card BlockIo init function.
446 @param CardData Pointer to CARD_DATA.
453 IN CARD_DATA
*CardData
457 MMC/SD card BlockIo init function.
459 @param CardData Pointer to CARD_DATA.
466 IN CARD_DATA
*CardData