]> git.proxmox.com Git - mirror_edk2.git/blob - QuarkSocPkg/QuarkSouthCluster/Sdio/Dxe/SDMediaDeviceDxe/SDMediaDevice.h
QuarkSocPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / QuarkSocPkg / QuarkSouthCluster / Sdio / Dxe / SDMediaDeviceDxe / SDMediaDevice.h
1 /** @file
2
3 The definition for SD media device driver model and blkio protocol routines.
4
5 Copyright (c) 2013-2016 Intel Corporation.
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #ifndef _SD_MEDIA_DEVICE_H_
12 #define _SD_MEDIA_DEVICE_H_
13
14
15 #include <Uefi.h>
16
17 #include <Protocol/PciIo.h>
18 #include <Protocol/BlockIo.h>
19
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>
29
30 #include "ComponentName.h"
31 #include "SDHostIo.h"
32
33
34 extern EFI_DRIVER_BINDING_PROTOCOL gSDMediaDeviceDriverBinding;
35 extern EFI_COMPONENT_NAME_PROTOCOL gSDMediaDeviceName;
36 extern EFI_COMPONENT_NAME2_PROTOCOL gSDMediaDeviceName2;
37
38 //
39 // Define the region of memory used for DMA memory
40 //
41 #define DMA_MEMORY_TOP 0x0000000001FFFFFFULL
42
43 #define CARD_DATA_SIGNATURE SIGNATURE_32 ('c', 'a', 'r', 'd')
44
45 //
46 // Command timeout will be max 100 ms
47 //
48 #define TIMEOUT_COMMAND 100
49 #define TIMEOUT_DATA 5000
50
51 typedef enum{
52 UnknownCard = 0,
53 MMCCard, // MMC card
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
59 }CARD_TYPE;
60
61
62 typedef struct {
63 //
64 //BlockIO
65 //
66 UINTN Signature;
67 EFI_BLOCK_IO_PROTOCOL BlockIo;
68
69 EFI_BLOCK_IO_MEDIA BlockIoMedia;
70
71 EFI_SD_HOST_IO_PROTOCOL *SDHostIo;
72 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
73 CARD_TYPE CardType;
74
75 UINT8 CurrentBusWidth;
76 BOOLEAN DualVoltage;
77 BOOLEAN NeedFlush;
78 UINT8 Reserved[3];
79
80 UINT16 Address;
81 UINT32 BlockLen;
82 UINT32 MaxFrequency;
83 UINT64 BlockNumber;
84 //
85 //Common used
86 //
87 CARD_STATUS CardStatus;
88 OCR OCRRegister;
89 CID CIDRegister;
90 CSD CSDRegister;
91 EXT_CSD ExtCSDRegister;
92 UINT8 *RawBufferPointer;
93 UINT8 *AlignedBuffer;
94 //
95 //CE-ATA specific
96 //
97 TASK_FILE TaskFile;
98 IDENTIFY_DEVICE_DATA IndentifyDeviceData;
99 //
100 //SD specific
101 //
102 SCR SCRRegister;
103 SD_STATUS_REG SDSattus;
104 SWITCH_STATUS SwitchStatus;
105 }CARD_DATA;
106
107 #define CARD_DATA_FROM_THIS(a) \
108 CR(a, CARD_DATA, BlockIo, CARD_DATA_SIGNATURE)
109
110 /**
111 Test to see if this driver supports ControllerHandle. Any
112 ControllerHandle that has BlockIoProtocol installed will be supported.
113
114 @param This Protocol instance pointer.
115 @param Controller Handle of device to test.
116 @param RemainingDevicePath Not used.
117
118 @return EFI_SUCCESS This driver supports this device.
119 @return EFI_UNSUPPORTED This driver does not support this device.
120
121 **/
122 EFI_STATUS
123 EFIAPI
124 SDMediaDeviceSupported (
125 IN EFI_DRIVER_BINDING_PROTOCOL *This,
126 IN EFI_HANDLE Controller,
127 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
128 );
129
130 /**
131 Starting the SD Media Device Driver.
132
133 @param This Protocol instance pointer.
134 @param Controller Handle of device to test.
135 @param RemainingDevicePath Not used.
136
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.
141
142 **/
143 EFI_STATUS
144 EFIAPI
145 SDMediaDeviceStart (
146 IN EFI_DRIVER_BINDING_PROTOCOL *This,
147 IN EFI_HANDLE Controller,
148 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
149 );
150
151 /**
152 Stop this driver on ControllerHandle. Support stopping any child handles
153 created by this driver.
154
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.
159
160 @return EFI_SUCCESS
161 @return others
162
163 **/
164 EFI_STATUS
165 EFIAPI
166 SDMediaDeviceStop (
167 IN EFI_DRIVER_BINDING_PROTOCOL *This,
168 IN EFI_HANDLE Controller,
169 IN UINTN NumberOfChildren,
170 IN EFI_HANDLE *ChildHandleBuffer
171 );
172
173 /**
174 MMC/SD card init function
175
176 @param CardData Pointer to CARD_DATA.
177
178 @return EFI_SUCCESS
179 @return others
180
181 **/
182 EFI_STATUS
183 MMCSDCardInit (
184 IN CARD_DATA *CardData
185 );
186
187 /**
188 Send command by using Host IO protocol
189
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.
199
200 @retval EFI_SUCCESS
201 @retval EFI_INVALID_PARAMETER
202 @retval EFI_UNSUPPORTED
203 @retval EFI_DEVICE_ERROR
204
205 **/
206 EFI_STATUS
207 SendCommand (
208 IN CARD_DATA *CardData,
209 IN UINT16 CommandIndex,
210 IN UINT32 Argument,
211 IN TRANSFER_TYPE DataType,
212 IN UINT8 *Buffer, OPTIONAL
213 IN UINT32 BufferSize,
214 IN RESPONSE_TYPE ResponseType,
215 IN UINT32 TimeOut,
216 OUT UINT32 *ResponseData
217 );
218
219 /**
220 Send the card APP_CMD command with the following command indicated by CommandIndex
221
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.
231
232 @retval EFI_SUCCESS
233 @retval EFI_INVALID_PARAMETER
234 @retval EFI_UNSUPPORTED
235 @retval EFI_DEVICE_ERROR
236
237 **/
238 EFI_STATUS
239 SendAppCommand (
240 IN CARD_DATA *CardData,
241 IN UINT16 CommandIndex,
242 IN UINT32 Argument,
243 IN TRANSFER_TYPE DataType,
244 IN UINT8 *Buffer, OPTIONAL
245 IN UINT32 BufferSize,
246 IN RESPONSE_TYPE ResponseType,
247 IN UINT32 TimeOut,
248 OUT UINT32 *ResponseData
249 );
250
251 /**
252 Send the card FAST_IO command
253
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.
258
259 @retval EFI_SUCCESS
260 @retval EFI_UNSUPPORTED
261 @retval EFI_INVALID_PARAMETER
262 @retval EFI_DEVICE_ERROR
263
264 **/
265 EFI_STATUS
266 FastIO (
267 IN CARD_DATA *CardData,
268 IN UINT8 RegisterAddress,
269 IN OUT UINT8 *RegisterData,
270 IN BOOLEAN Write
271 );
272
273 /**
274 Judge whether it is CE-ATA device or not.
275
276 @param CardData Pointer to CARD_DATA.
277
278 @retval TRUE
279 @retval FALSE
280
281 **/
282 BOOLEAN
283 IsCEATADevice (
284 IN CARD_DATA *CardData
285 );
286
287 /**
288 Send software reset
289
290 @param CardData Pointer to CARD_DATA.
291
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
298
299 **/
300 EFI_STATUS
301 SoftwareReset (
302 IN CARD_DATA *CardData
303 );
304
305 /**
306 SendATACommand specificed in Taskfile
307
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.
313
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
320
321 **/
322 EFI_STATUS
323 SendATACommand (
324 IN CARD_DATA *CardData,
325 IN TASK_FILE *TaskFile,
326 IN BOOLEAN Write,
327 IN UINT8 *Buffer,
328 IN UINT16 SectorCount
329 );
330
331 /**
332 IDENTIFY_DEVICE command
333
334 @param CardData Pointer to CARD_DATA.
335
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
342
343 **/
344 EFI_STATUS
345 IndentifyDevice (
346 IN CARD_DATA *CardData
347 );
348
349 /**
350 FLUSH_CACHE_EXT command
351
352 @param CardData Pointer to CARD_DATA.
353
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
360
361 **/
362 EFI_STATUS
363 FlushCache (
364 IN CARD_DATA *CardData
365 );
366
367 /**
368 STANDBY_IMMEDIATE command
369
370 @param CardData Pointer to CARD_DATA.
371
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
378
379 **/
380 EFI_STATUS
381 StandByImmediate (
382 IN CARD_DATA *CardData
383 );
384
385 /**
386 READ_DMA_EXT command
387
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
392 of the buffer.
393 @param SectorCount Size in 512 bytes unit.
394
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
401
402 **/
403 EFI_STATUS
404 ReadDMAExt (
405 IN CARD_DATA *CardData,
406 IN EFI_LBA LBA,
407 IN UINT8 *Buffer,
408 IN UINT16 SectorCount
409 );
410
411 /**
412 WRITE_DMA_EXT command
413
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
418 of the buffer.
419 @param SectorCount Size in 512 bytes unit.
420
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
427
428 **/
429 EFI_STATUS
430 WriteDMAExt (
431 IN CARD_DATA *CardData,
432 IN EFI_LBA LBA,
433 IN UINT8 *Buffer,
434 IN UINT16 SectorCount
435 );
436
437 /**
438 CEATA card BlockIo init function.
439
440 @param CardData Pointer to CARD_DATA.
441
442 @retval EFI_SUCCESS
443 @retval Others
444 **/
445 EFI_STATUS
446 CEATABlockIoInit (
447 IN CARD_DATA *CardData
448 );
449
450 /**
451 MMC/SD card BlockIo init function.
452
453 @param CardData Pointer to CARD_DATA.
454
455 @retval EFI_SUCCESS
456 @retval Others
457 **/
458 EFI_STATUS
459 MMCSDBlockIoInit (
460 IN CARD_DATA *CardData
461 );
462 #endif