]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcBlockIoPei.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Sd / EmmcBlockIoPei / EmmcBlockIoPei.h
CommitLineData
48555339
FT
1/** @file\r
2\r
85ad9a6e 3 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
9d510e61 4 SPDX-License-Identifier: BSD-2-Clause-Patent\r
48555339
FT
5\r
6**/\r
7\r
8#ifndef _EMMC_BLOCK_IO_PEI_H_\r
9#define _EMMC_BLOCK_IO_PEI_H_\r
10\r
11#include <PiPei.h>\r
12\r
13#include <Ppi/SdMmcHostController.h>\r
14#include <Ppi/BlockIo.h>\r
15#include <Ppi/BlockIo2.h>\r
85ad9a6e
HW
16#include <Ppi/IoMmu.h>\r
17#include <Ppi/EndOfPeiPhase.h>\r
48555339
FT
18\r
19#include <Library/DebugLib.h>\r
20#include <Library/BaseLib.h>\r
21#include <Library/BaseMemoryLib.h>\r
22#include <Library/MemoryAllocationLib.h>\r
23#include <Library/IoLib.h>\r
24#include <Library/TimerLib.h>\r
25#include <Library/PeiServicesLib.h>\r
26\r
27#include <IndustryStandard/Emmc.h>\r
28\r
29typedef struct _EMMC_PEIM_HC_PRIVATE_DATA EMMC_PEIM_HC_PRIVATE_DATA;\r
30typedef struct _EMMC_PEIM_HC_SLOT EMMC_PEIM_HC_SLOT;\r
31typedef struct _EMMC_TRB EMMC_TRB;\r
32\r
33#include "EmmcHci.h"\r
34#include "EmmcHcMem.h"\r
35\r
36#define EMMC_PEIM_SIG SIGNATURE_32 ('E', 'M', 'C', 'P')\r
37#define EMMC_PEIM_SLOT_SIG SIGNATURE_32 ('E', 'M', 'C', 'S')\r
38\r
39#define EMMC_PEIM_MAX_SLOTS 6\r
40#define EMMC_PEIM_MAX_PARTITIONS 8\r
41\r
42struct _EMMC_PEIM_HC_SLOT {\r
43 UINT32 Signature;\r
44 EFI_PEI_BLOCK_IO2_MEDIA Media[EMMC_PEIM_MAX_PARTITIONS];\r
45 UINT8 MediaNum;\r
46 EMMC_PARTITION_TYPE PartitionType[EMMC_PEIM_MAX_PARTITIONS];\r
47\r
48 UINTN EmmcHcBase;\r
49 EMMC_HC_SLOT_CAP Capability;\r
50 EMMC_CSD Csd;\r
51 EMMC_EXT_CSD ExtCsd;\r
52 BOOLEAN SectorAddressing;\r
53 EMMC_PEIM_HC_PRIVATE_DATA *Private;\r
54};\r
55\r
56struct _EMMC_PEIM_HC_PRIVATE_DATA {\r
57 UINT32 Signature;\r
58 EMMC_PEIM_MEM_POOL *Pool;\r
59 EFI_PEI_RECOVERY_BLOCK_IO_PPI BlkIoPpi;\r
60 EFI_PEI_RECOVERY_BLOCK_IO2_PPI BlkIo2Ppi;\r
61 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList;\r
62 EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList;\r
85ad9a6e
HW
63\r
64 //\r
65 // EndOfPei callback is used to do the cleanups before exit of PEI phase.\r
66 //\r
67 EFI_PEI_NOTIFY_DESCRIPTOR EndOfPeiNotifyList;\r
68\r
48555339
FT
69 EMMC_PEIM_HC_SLOT Slot[EMMC_PEIM_MAX_SLOTS];\r
70 UINT8 SlotNum;\r
71 UINT8 TotalBlkIoDevices;\r
72};\r
73\r
74#define EMMC_TIMEOUT MultU64x32((UINT64)(3), 1000000)\r
75#define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, BlkIoPpi, EMMC_PEIM_SIG)\r
76#define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS2(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, BlkIo2Ppi, EMMC_PEIM_SIG)\r
85ad9a6e 77#define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, EndOfPeiNotifyList, EMMC_PEIM_SIG)\r
48555339
FT
78\r
79struct _EMMC_TRB {\r
80 EMMC_PEIM_HC_SLOT *Slot;\r
81 UINT16 BlockSize;\r
82\r
83 EMMC_COMMAND_PACKET *Packet;\r
84 VOID *Data;\r
85 UINT32 DataLen;\r
86 BOOLEAN Read;\r
85ad9a6e
HW
87 EFI_PHYSICAL_ADDRESS DataPhy;\r
88 VOID *DataMap;\r
48555339
FT
89 EMMC_HC_TRANSFER_MODE Mode;\r
90\r
91 UINT64 Timeout;\r
92\r
93 EMMC_HC_ADMA_DESC_LINE *AdmaDesc;\r
94 UINTN AdmaDescSize;\r
95};\r
96\r
97/**\r
98 Gets the count of block I/O devices that one specific block driver detects.\r
99\r
100 This function is used for getting the count of block I/O devices that one\r
101 specific block driver detects. To the PEI ATAPI driver, it returns the number\r
102 of all the detected ATAPI devices it detects during the enumeration process.\r
103 To the PEI legacy floppy driver, it returns the number of all the legacy\r
104 devices it finds during its enumeration process. If no device is detected,\r
105 then the function will return zero.\r
106\r
107 @param[in] PeiServices General-purpose services that are available\r
108 to every PEIM.\r
109 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI\r
110 instance.\r
111 @param[out] NumberBlockDevices The number of block I/O devices discovered.\r
112\r
113 @retval EFI_SUCCESS The operation performed successfully.\r
114\r
115**/\r
116EFI_STATUS\r
117EFIAPI\r
118EmmcBlockIoPeimGetDeviceNo (\r
119 IN EFI_PEI_SERVICES **PeiServices,\r
120 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
121 OUT UINTN *NumberBlockDevices\r
122 );\r
123\r
124/**\r
125 Gets a block device's media information.\r
126\r
127 This function will provide the caller with the specified block device's media\r
128 information. If the media changes, calling this function will update the media\r
129 information accordingly.\r
130\r
131 @param[in] PeiServices General-purpose services that are available to every\r
132 PEIM\r
133 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.\r
134 @param[in] DeviceIndex Specifies the block device to which the function wants\r
135 to talk. Because the driver that implements Block I/O\r
136 PPIs will manage multiple block devices, the PPIs that\r
137 want to talk to a single device must specify the\r
138 device index that was assigned during the enumeration\r
139 process. This index is a number from one to\r
140 NumberBlockDevices.\r
141 @param[out] MediaInfo The media information of the specified block media.\r
142 The caller is responsible for the ownership of this\r
143 data structure.\r
144\r
145 @par Note:\r
146 The MediaInfo structure describes an enumeration of possible block device\r
147 types. This enumeration exists because no device paths are actually passed\r
148 across interfaces that describe the type or class of hardware that is publishing\r
149 the block I/O interface. This enumeration will allow for policy decisions\r
150 in the Recovery PEIM, such as "Try to recover from legacy floppy first,\r
151 LS-120 second, CD-ROM third." If there are multiple partitions abstracted\r
152 by a given device type, they should be reported in ascending order; this\r
153 order also applies to nested partitions, such as legacy MBR, where the\r
154 outermost partitions would have precedence in the reporting order. The\r
155 same logic applies to systems such as IDE that have precedence relationships\r
156 like "Master/Slave" or "Primary/Secondary". The master device should be\r
157 reported first, the slave second.\r
158\r
159 @retval EFI_SUCCESS Media information about the specified block device\r
160 was obtained successfully.\r
161 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware\r
162 error.\r
163\r
164**/\r
165EFI_STATUS\r
166EFIAPI\r
167EmmcBlockIoPeimGetMediaInfo (\r
168 IN EFI_PEI_SERVICES **PeiServices,\r
169 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
170 IN UINTN DeviceIndex,\r
171 OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo\r
172 );\r
173\r
174/**\r
175 Reads the requested number of blocks from the specified block device.\r
176\r
177 The function reads the requested number of blocks from the device. All the\r
178 blocks are read, or an error is returned. If there is no media in the device,\r
179 the function returns EFI_NO_MEDIA.\r
180\r
181 @param[in] PeiServices General-purpose services that are available to\r
182 every PEIM.\r
183 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.\r
184 @param[in] DeviceIndex Specifies the block device to which the function wants\r
185 to talk. Because the driver that implements Block I/O\r
186 PPIs will manage multiple block devices, PPIs that\r
187 want to talk to a single device must specify the device\r
188 index that was assigned during the enumeration process.\r
189 This index is a number from one to NumberBlockDevices.\r
190 @param[in] StartLBA The starting logical block address (LBA) to read from\r
191 on the device\r
192 @param[in] BufferSize The size of the Buffer in bytes. This number must be\r
193 a multiple of the intrinsic block size of the device.\r
194 @param[out] Buffer A pointer to the destination buffer for the data.\r
195 The caller is responsible for the ownership of the\r
196 buffer.\r
197\r
198 @retval EFI_SUCCESS The data was read correctly from the device.\r
199 @retval EFI_DEVICE_ERROR The device reported an error while attempting\r
200 to perform the read operation.\r
201 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not\r
202 valid, or the buffer is not properly aligned.\r
203 @retval EFI_NO_MEDIA There is no media in the device.\r
204 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of\r
205 the intrinsic block size of the device.\r
206\r
207**/\r
208EFI_STATUS\r
209EFIAPI\r
210EmmcBlockIoPeimReadBlocks (\r
211 IN EFI_PEI_SERVICES **PeiServices,\r
212 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
213 IN UINTN DeviceIndex,\r
214 IN EFI_PEI_LBA StartLBA,\r
215 IN UINTN BufferSize,\r
216 OUT VOID *Buffer\r
217 );\r
218\r
219/**\r
220 Gets the count of block I/O devices that one specific block driver detects.\r
221\r
222 This function is used for getting the count of block I/O devices that one\r
223 specific block driver detects. To the PEI ATAPI driver, it returns the number\r
224 of all the detected ATAPI devices it detects during the enumeration process.\r
225 To the PEI legacy floppy driver, it returns the number of all the legacy\r
226 devices it finds during its enumeration process. If no device is detected,\r
227 then the function will return zero.\r
228\r
229 @param[in] PeiServices General-purpose services that are available\r
230 to every PEIM.\r
231 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI\r
232 instance.\r
233 @param[out] NumberBlockDevices The number of block I/O devices discovered.\r
234\r
235 @retval EFI_SUCCESS The operation performed successfully.\r
236\r
237**/\r
238EFI_STATUS\r
239EFIAPI\r
240EmmcBlockIoPeimGetDeviceNo2 (\r
241 IN EFI_PEI_SERVICES **PeiServices,\r
242 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r
243 OUT UINTN *NumberBlockDevices\r
244 );\r
245\r
246/**\r
247 Gets a block device's media information.\r
248\r
249 This function will provide the caller with the specified block device's media\r
250 information. If the media changes, calling this function will update the media\r
251 information accordingly.\r
252\r
253 @param[in] PeiServices General-purpose services that are available to every\r
254 PEIM\r
255 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.\r
256 @param[in] DeviceIndex Specifies the block device to which the function wants\r
257 to talk. Because the driver that implements Block I/O\r
258 PPIs will manage multiple block devices, the PPIs that\r
259 want to talk to a single device must specify the\r
260 device index that was assigned during the enumeration\r
261 process. This index is a number from one to\r
262 NumberBlockDevices.\r
263 @param[out] MediaInfo The media information of the specified block media.\r
264 The caller is responsible for the ownership of this\r
265 data structure.\r
266\r
267 @par Note:\r
268 The MediaInfo structure describes an enumeration of possible block device\r
269 types. This enumeration exists because no device paths are actually passed\r
270 across interfaces that describe the type or class of hardware that is publishing\r
271 the block I/O interface. This enumeration will allow for policy decisions\r
272 in the Recovery PEIM, such as "Try to recover from legacy floppy first,\r
273 LS-120 second, CD-ROM third." If there are multiple partitions abstracted\r
274 by a given device type, they should be reported in ascending order; this\r
275 order also applies to nested partitions, such as legacy MBR, where the\r
276 outermost partitions would have precedence in the reporting order. The\r
277 same logic applies to systems such as IDE that have precedence relationships\r
278 like "Master/Slave" or "Primary/Secondary". The master device should be\r
279 reported first, the slave second.\r
280\r
281 @retval EFI_SUCCESS Media information about the specified block device\r
282 was obtained successfully.\r
283 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware\r
284 error.\r
285\r
286**/\r
287EFI_STATUS\r
288EFIAPI\r
289EmmcBlockIoPeimGetMediaInfo2 (\r
290 IN EFI_PEI_SERVICES **PeiServices,\r
291 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r
292 IN UINTN DeviceIndex,\r
293 OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo\r
294 );\r
295\r
296/**\r
297 Reads the requested number of blocks from the specified block device.\r
298\r
299 The function reads the requested number of blocks from the device. All the\r
300 blocks are read, or an error is returned. If there is no media in the device,\r
301 the function returns EFI_NO_MEDIA.\r
302\r
303 @param[in] PeiServices General-purpose services that are available to\r
304 every PEIM.\r
305 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.\r
306 @param[in] DeviceIndex Specifies the block device to which the function wants\r
307 to talk. Because the driver that implements Block I/O\r
308 PPIs will manage multiple block devices, PPIs that\r
309 want to talk to a single device must specify the device\r
310 index that was assigned during the enumeration process.\r
311 This index is a number from one to NumberBlockDevices.\r
312 @param[in] StartLBA The starting logical block address (LBA) to read from\r
313 on the device\r
314 @param[in] BufferSize The size of the Buffer in bytes. This number must be\r
315 a multiple of the intrinsic block size of the device.\r
316 @param[out] Buffer A pointer to the destination buffer for the data.\r
317 The caller is responsible for the ownership of the\r
318 buffer.\r
319\r
320 @retval EFI_SUCCESS The data was read correctly from the device.\r
321 @retval EFI_DEVICE_ERROR The device reported an error while attempting\r
322 to perform the read operation.\r
323 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not\r
324 valid, or the buffer is not properly aligned.\r
325 @retval EFI_NO_MEDIA There is no media in the device.\r
326 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of\r
327 the intrinsic block size of the device.\r
328\r
329**/\r
330EFI_STATUS\r
331EFIAPI\r
332EmmcBlockIoPeimReadBlocks2 (\r
333 IN EFI_PEI_SERVICES **PeiServices,\r
334 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r
335 IN UINTN DeviceIndex,\r
336 IN EFI_PEI_LBA StartLBA,\r
337 IN UINTN BufferSize,\r
338 OUT VOID *Buffer\r
339 );\r
340\r
341/**\r
342 Initialize the memory management pool for the host controller.\r
343\r
344 @param Private The Emmc Peim driver private data.\r
345\r
346 @retval EFI_SUCCESS The memory pool is initialized.\r
347 @retval Others Fail to init the memory pool.\r
348\r
349**/\r
350EFI_STATUS\r
351EmmcPeimInitMemPool (\r
352 IN EMMC_PEIM_HC_PRIVATE_DATA *Private\r
353 );\r
354\r
85ad9a6e
HW
355/**\r
356 Release the memory management pool.\r
357\r
358 @param Pool The memory pool to free.\r
359\r
360 @retval EFI_DEVICE_ERROR Fail to free the memory pool.\r
361 @retval EFI_SUCCESS The memory pool is freed.\r
362\r
363**/\r
364EFI_STATUS\r
365EmmcPeimFreeMemPool (\r
366 IN EMMC_PEIM_MEM_POOL *Pool\r
367 );\r
368\r
48555339
FT
369/**\r
370 Allocate some memory from the host controller's memory pool\r
371 which can be used to communicate with host controller.\r
372\r
373 @param Pool The host controller's memory pool.\r
374 @param Size Size of the memory to allocate.\r
375\r
376 @return The allocated memory or NULL.\r
377\r
378**/\r
379VOID *\r
380EmmcPeimAllocateMem (\r
381 IN EMMC_PEIM_MEM_POOL *Pool,\r
382 IN UINTN Size\r
383 );\r
384\r
385/**\r
386 Free the allocated memory back to the memory pool.\r
387\r
388 @param Pool The memory pool of the host controller.\r
389 @param Mem The memory to free.\r
390 @param Size The size of the memory to free.\r
391\r
392**/\r
393VOID\r
394EmmcPeimFreeMem (\r
395 IN EMMC_PEIM_MEM_POOL *Pool,\r
396 IN VOID *Mem,\r
397 IN UINTN Size\r
398 );\r
399\r
85ad9a6e
HW
400/**\r
401 Initialize IOMMU.\r
402**/\r
403VOID\r
404IoMmuInit (\r
405 VOID\r
406 );\r
407\r
408/**\r
409 Provides the controller-specific addresses required to access system memory from a\r
410 DMA bus master.\r
411\r
412 @param Operation Indicates if the bus master is going to read or write to system memory.\r
413 @param HostAddress The system memory address to map to the PCI controller.\r
414 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes\r
415 that were mapped.\r
416 @param DeviceAddress The resulting map address for the bus master PCI controller to use to\r
417 access the hosts HostAddress.\r
418 @param Mapping A resulting value to pass to Unmap().\r
419\r
420 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r
421 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.\r
422 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
423 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
424 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r
425\r
426**/\r
427EFI_STATUS\r
428IoMmuMap (\r
429 IN EDKII_IOMMU_OPERATION Operation,\r
430 IN VOID *HostAddress,\r
431 IN OUT UINTN *NumberOfBytes,\r
432 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
433 OUT VOID **Mapping\r
434 );\r
435\r
436/**\r
437 Completes the Map() operation and releases any corresponding resources.\r
438\r
439 @param Mapping The mapping value returned from Map().\r
440\r
441 @retval EFI_SUCCESS The range was unmapped.\r
442 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().\r
443 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r
444**/\r
445EFI_STATUS\r
446IoMmuUnmap (\r
447 IN VOID *Mapping\r
448 );\r
449\r
450/**\r
451 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or\r
452 OperationBusMasterCommonBuffer64 mapping.\r
453\r
454 @param Pages The number of pages to allocate.\r
455 @param HostAddress A pointer to store the base system memory address of the\r
456 allocated range.\r
457 @param DeviceAddress The resulting map address for the bus master PCI controller to use to\r
458 access the hosts HostAddress.\r
459 @param Mapping A resulting value to pass to Unmap().\r
460\r
461 @retval EFI_SUCCESS The requested memory pages were allocated.\r
462 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r
463 MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
464 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
465 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r
466\r
467**/\r
468EFI_STATUS\r
469IoMmuAllocateBuffer (\r
470 IN UINTN Pages,\r
471 OUT VOID **HostAddress,\r
472 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
473 OUT VOID **Mapping\r
474 );\r
475\r
476/**\r
477 Frees memory that was allocated with AllocateBuffer().\r
478\r
479 @param Pages The number of pages to free.\r
480 @param HostAddress The base system memory address of the allocated range.\r
481 @param Mapping The mapping value returned from Map().\r
482\r
483 @retval EFI_SUCCESS The requested memory pages were freed.\r
484 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
485 was not allocated with AllocateBuffer().\r
486\r
487**/\r
488EFI_STATUS\r
489IoMmuFreeBuffer (\r
490 IN UINTN Pages,\r
491 IN VOID *HostAddress,\r
492 IN VOID *Mapping\r
493 );\r
494\r
495/**\r
496 One notified function to cleanup the allocated DMA buffers at the end of PEI.\r
497\r
498 @param[in] PeiServices Pointer to PEI Services Table.\r
499 @param[in] NotifyDescriptor Pointer to the descriptor for the Notification\r
500 event that caused this function to execute.\r
501 @param[in] Ppi Pointer to the PPI data associated with this function.\r
502\r
503 @retval EFI_SUCCESS The function completes successfully\r
504\r
505**/\r
506EFI_STATUS\r
507EFIAPI\r
508EmmcBlockIoPeimEndOfPei (\r
509 IN EFI_PEI_SERVICES **PeiServices,\r
510 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
511 IN VOID *Ppi\r
512 );\r
513\r
48555339 514#endif\r