]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcBlockIoPei.h
MdeModulePkg/SdMmc: Add EDKII SD/MMC stack
[mirror_edk2.git] / MdeModulePkg / Bus / Sd / EmmcBlockIoPei / EmmcBlockIoPei.h
CommitLineData
48555339
FT
1/** @file\r
2\r
3 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
4 This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12**/\r
13\r
14#ifndef _EMMC_BLOCK_IO_PEI_H_\r
15#define _EMMC_BLOCK_IO_PEI_H_\r
16\r
17#include <PiPei.h>\r
18\r
19#include <Ppi/SdMmcHostController.h>\r
20#include <Ppi/BlockIo.h>\r
21#include <Ppi/BlockIo2.h>\r
22\r
23#include <Library/DebugLib.h>\r
24#include <Library/BaseLib.h>\r
25#include <Library/BaseMemoryLib.h>\r
26#include <Library/MemoryAllocationLib.h>\r
27#include <Library/IoLib.h>\r
28#include <Library/TimerLib.h>\r
29#include <Library/PeiServicesLib.h>\r
30\r
31#include <IndustryStandard/Emmc.h>\r
32\r
33typedef struct _EMMC_PEIM_HC_PRIVATE_DATA EMMC_PEIM_HC_PRIVATE_DATA;\r
34typedef struct _EMMC_PEIM_HC_SLOT EMMC_PEIM_HC_SLOT;\r
35typedef struct _EMMC_TRB EMMC_TRB;\r
36\r
37#include "EmmcHci.h"\r
38#include "EmmcHcMem.h"\r
39\r
40#define EMMC_PEIM_SIG SIGNATURE_32 ('E', 'M', 'C', 'P')\r
41#define EMMC_PEIM_SLOT_SIG SIGNATURE_32 ('E', 'M', 'C', 'S')\r
42\r
43#define EMMC_PEIM_MAX_SLOTS 6\r
44#define EMMC_PEIM_MAX_PARTITIONS 8\r
45\r
46struct _EMMC_PEIM_HC_SLOT {\r
47 UINT32 Signature;\r
48 EFI_PEI_BLOCK_IO2_MEDIA Media[EMMC_PEIM_MAX_PARTITIONS];\r
49 UINT8 MediaNum;\r
50 EMMC_PARTITION_TYPE PartitionType[EMMC_PEIM_MAX_PARTITIONS];\r
51\r
52 UINTN EmmcHcBase;\r
53 EMMC_HC_SLOT_CAP Capability;\r
54 EMMC_CSD Csd;\r
55 EMMC_EXT_CSD ExtCsd;\r
56 BOOLEAN SectorAddressing;\r
57 EMMC_PEIM_HC_PRIVATE_DATA *Private;\r
58};\r
59\r
60struct _EMMC_PEIM_HC_PRIVATE_DATA {\r
61 UINT32 Signature;\r
62 EMMC_PEIM_MEM_POOL *Pool;\r
63 EFI_PEI_RECOVERY_BLOCK_IO_PPI BlkIoPpi;\r
64 EFI_PEI_RECOVERY_BLOCK_IO2_PPI BlkIo2Ppi;\r
65 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList;\r
66 EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList;\r
67 EMMC_PEIM_HC_SLOT Slot[EMMC_PEIM_MAX_SLOTS];\r
68 UINT8 SlotNum;\r
69 UINT8 TotalBlkIoDevices;\r
70};\r
71\r
72#define EMMC_TIMEOUT MultU64x32((UINT64)(3), 1000000)\r
73#define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, BlkIoPpi, EMMC_PEIM_SIG)\r
74#define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS2(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, BlkIo2Ppi, EMMC_PEIM_SIG)\r
75\r
76struct _EMMC_TRB {\r
77 EMMC_PEIM_HC_SLOT *Slot;\r
78 UINT16 BlockSize;\r
79\r
80 EMMC_COMMAND_PACKET *Packet;\r
81 VOID *Data;\r
82 UINT32 DataLen;\r
83 BOOLEAN Read;\r
84 EMMC_HC_TRANSFER_MODE Mode;\r
85\r
86 UINT64 Timeout;\r
87\r
88 EMMC_HC_ADMA_DESC_LINE *AdmaDesc;\r
89 UINTN AdmaDescSize;\r
90};\r
91\r
92/**\r
93 Gets the count of block I/O devices that one specific block driver detects.\r
94\r
95 This function is used for getting the count of block I/O devices that one\r
96 specific block driver detects. To the PEI ATAPI driver, it returns the number\r
97 of all the detected ATAPI devices it detects during the enumeration process.\r
98 To the PEI legacy floppy driver, it returns the number of all the legacy\r
99 devices it finds during its enumeration process. If no device is detected,\r
100 then the function will return zero.\r
101\r
102 @param[in] PeiServices General-purpose services that are available\r
103 to every PEIM.\r
104 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI\r
105 instance.\r
106 @param[out] NumberBlockDevices The number of block I/O devices discovered.\r
107\r
108 @retval EFI_SUCCESS The operation performed successfully.\r
109\r
110**/\r
111EFI_STATUS\r
112EFIAPI\r
113EmmcBlockIoPeimGetDeviceNo (\r
114 IN EFI_PEI_SERVICES **PeiServices,\r
115 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
116 OUT UINTN *NumberBlockDevices\r
117 );\r
118\r
119/**\r
120 Gets a block device's media information.\r
121\r
122 This function will provide the caller with the specified block device's media\r
123 information. If the media changes, calling this function will update the media\r
124 information accordingly.\r
125\r
126 @param[in] PeiServices General-purpose services that are available to every\r
127 PEIM\r
128 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.\r
129 @param[in] DeviceIndex Specifies the block device to which the function wants\r
130 to talk. Because the driver that implements Block I/O\r
131 PPIs will manage multiple block devices, the PPIs that\r
132 want to talk to a single device must specify the\r
133 device index that was assigned during the enumeration\r
134 process. This index is a number from one to\r
135 NumberBlockDevices.\r
136 @param[out] MediaInfo The media information of the specified block media.\r
137 The caller is responsible for the ownership of this\r
138 data structure.\r
139\r
140 @par Note:\r
141 The MediaInfo structure describes an enumeration of possible block device\r
142 types. This enumeration exists because no device paths are actually passed\r
143 across interfaces that describe the type or class of hardware that is publishing\r
144 the block I/O interface. This enumeration will allow for policy decisions\r
145 in the Recovery PEIM, such as "Try to recover from legacy floppy first,\r
146 LS-120 second, CD-ROM third." If there are multiple partitions abstracted\r
147 by a given device type, they should be reported in ascending order; this\r
148 order also applies to nested partitions, such as legacy MBR, where the\r
149 outermost partitions would have precedence in the reporting order. The\r
150 same logic applies to systems such as IDE that have precedence relationships\r
151 like "Master/Slave" or "Primary/Secondary". The master device should be\r
152 reported first, the slave second.\r
153\r
154 @retval EFI_SUCCESS Media information about the specified block device\r
155 was obtained successfully.\r
156 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware\r
157 error.\r
158\r
159**/\r
160EFI_STATUS\r
161EFIAPI\r
162EmmcBlockIoPeimGetMediaInfo (\r
163 IN EFI_PEI_SERVICES **PeiServices,\r
164 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
165 IN UINTN DeviceIndex,\r
166 OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo\r
167 );\r
168\r
169/**\r
170 Reads the requested number of blocks from the specified block device.\r
171\r
172 The function reads the requested number of blocks from the device. All the\r
173 blocks are read, or an error is returned. If there is no media in the device,\r
174 the function returns EFI_NO_MEDIA.\r
175\r
176 @param[in] PeiServices General-purpose services that are available to\r
177 every PEIM.\r
178 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.\r
179 @param[in] DeviceIndex Specifies the block device to which the function wants\r
180 to talk. Because the driver that implements Block I/O\r
181 PPIs will manage multiple block devices, PPIs that\r
182 want to talk to a single device must specify the device\r
183 index that was assigned during the enumeration process.\r
184 This index is a number from one to NumberBlockDevices.\r
185 @param[in] StartLBA The starting logical block address (LBA) to read from\r
186 on the device\r
187 @param[in] BufferSize The size of the Buffer in bytes. This number must be\r
188 a multiple of the intrinsic block size of the device.\r
189 @param[out] Buffer A pointer to the destination buffer for the data.\r
190 The caller is responsible for the ownership of the\r
191 buffer.\r
192\r
193 @retval EFI_SUCCESS The data was read correctly from the device.\r
194 @retval EFI_DEVICE_ERROR The device reported an error while attempting\r
195 to perform the read operation.\r
196 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not\r
197 valid, or the buffer is not properly aligned.\r
198 @retval EFI_NO_MEDIA There is no media in the device.\r
199 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of\r
200 the intrinsic block size of the device.\r
201\r
202**/\r
203EFI_STATUS\r
204EFIAPI\r
205EmmcBlockIoPeimReadBlocks (\r
206 IN EFI_PEI_SERVICES **PeiServices,\r
207 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
208 IN UINTN DeviceIndex,\r
209 IN EFI_PEI_LBA StartLBA,\r
210 IN UINTN BufferSize,\r
211 OUT VOID *Buffer\r
212 );\r
213\r
214/**\r
215 Gets the count of block I/O devices that one specific block driver detects.\r
216\r
217 This function is used for getting the count of block I/O devices that one\r
218 specific block driver detects. To the PEI ATAPI driver, it returns the number\r
219 of all the detected ATAPI devices it detects during the enumeration process.\r
220 To the PEI legacy floppy driver, it returns the number of all the legacy\r
221 devices it finds during its enumeration process. If no device is detected,\r
222 then the function will return zero.\r
223\r
224 @param[in] PeiServices General-purpose services that are available\r
225 to every PEIM.\r
226 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI\r
227 instance.\r
228 @param[out] NumberBlockDevices The number of block I/O devices discovered.\r
229\r
230 @retval EFI_SUCCESS The operation performed successfully.\r
231\r
232**/\r
233EFI_STATUS\r
234EFIAPI\r
235EmmcBlockIoPeimGetDeviceNo2 (\r
236 IN EFI_PEI_SERVICES **PeiServices,\r
237 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r
238 OUT UINTN *NumberBlockDevices\r
239 );\r
240\r
241/**\r
242 Gets a block device's media information.\r
243\r
244 This function will provide the caller with the specified block device's media\r
245 information. If the media changes, calling this function will update the media\r
246 information accordingly.\r
247\r
248 @param[in] PeiServices General-purpose services that are available to every\r
249 PEIM\r
250 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.\r
251 @param[in] DeviceIndex Specifies the block device to which the function wants\r
252 to talk. Because the driver that implements Block I/O\r
253 PPIs will manage multiple block devices, the PPIs that\r
254 want to talk to a single device must specify the\r
255 device index that was assigned during the enumeration\r
256 process. This index is a number from one to\r
257 NumberBlockDevices.\r
258 @param[out] MediaInfo The media information of the specified block media.\r
259 The caller is responsible for the ownership of this\r
260 data structure.\r
261\r
262 @par Note:\r
263 The MediaInfo structure describes an enumeration of possible block device\r
264 types. This enumeration exists because no device paths are actually passed\r
265 across interfaces that describe the type or class of hardware that is publishing\r
266 the block I/O interface. This enumeration will allow for policy decisions\r
267 in the Recovery PEIM, such as "Try to recover from legacy floppy first,\r
268 LS-120 second, CD-ROM third." If there are multiple partitions abstracted\r
269 by a given device type, they should be reported in ascending order; this\r
270 order also applies to nested partitions, such as legacy MBR, where the\r
271 outermost partitions would have precedence in the reporting order. The\r
272 same logic applies to systems such as IDE that have precedence relationships\r
273 like "Master/Slave" or "Primary/Secondary". The master device should be\r
274 reported first, the slave second.\r
275\r
276 @retval EFI_SUCCESS Media information about the specified block device\r
277 was obtained successfully.\r
278 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware\r
279 error.\r
280\r
281**/\r
282EFI_STATUS\r
283EFIAPI\r
284EmmcBlockIoPeimGetMediaInfo2 (\r
285 IN EFI_PEI_SERVICES **PeiServices,\r
286 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r
287 IN UINTN DeviceIndex,\r
288 OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo\r
289 );\r
290\r
291/**\r
292 Reads the requested number of blocks from the specified block device.\r
293\r
294 The function reads the requested number of blocks from the device. All the\r
295 blocks are read, or an error is returned. If there is no media in the device,\r
296 the function returns EFI_NO_MEDIA.\r
297\r
298 @param[in] PeiServices General-purpose services that are available to\r
299 every PEIM.\r
300 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.\r
301 @param[in] DeviceIndex Specifies the block device to which the function wants\r
302 to talk. Because the driver that implements Block I/O\r
303 PPIs will manage multiple block devices, PPIs that\r
304 want to talk to a single device must specify the device\r
305 index that was assigned during the enumeration process.\r
306 This index is a number from one to NumberBlockDevices.\r
307 @param[in] StartLBA The starting logical block address (LBA) to read from\r
308 on the device\r
309 @param[in] BufferSize The size of the Buffer in bytes. This number must be\r
310 a multiple of the intrinsic block size of the device.\r
311 @param[out] Buffer A pointer to the destination buffer for the data.\r
312 The caller is responsible for the ownership of the\r
313 buffer.\r
314\r
315 @retval EFI_SUCCESS The data was read correctly from the device.\r
316 @retval EFI_DEVICE_ERROR The device reported an error while attempting\r
317 to perform the read operation.\r
318 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not\r
319 valid, or the buffer is not properly aligned.\r
320 @retval EFI_NO_MEDIA There is no media in the device.\r
321 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of\r
322 the intrinsic block size of the device.\r
323\r
324**/\r
325EFI_STATUS\r
326EFIAPI\r
327EmmcBlockIoPeimReadBlocks2 (\r
328 IN EFI_PEI_SERVICES **PeiServices,\r
329 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r
330 IN UINTN DeviceIndex,\r
331 IN EFI_PEI_LBA StartLBA,\r
332 IN UINTN BufferSize,\r
333 OUT VOID *Buffer\r
334 );\r
335\r
336/**\r
337 Initialize the memory management pool for the host controller.\r
338\r
339 @param Private The Emmc Peim driver private data.\r
340\r
341 @retval EFI_SUCCESS The memory pool is initialized.\r
342 @retval Others Fail to init the memory pool.\r
343\r
344**/\r
345EFI_STATUS\r
346EmmcPeimInitMemPool (\r
347 IN EMMC_PEIM_HC_PRIVATE_DATA *Private\r
348 );\r
349\r
350/**\r
351 Allocate some memory from the host controller's memory pool\r
352 which can be used to communicate with host controller.\r
353\r
354 @param Pool The host controller's memory pool.\r
355 @param Size Size of the memory to allocate.\r
356\r
357 @return The allocated memory or NULL.\r
358\r
359**/\r
360VOID *\r
361EmmcPeimAllocateMem (\r
362 IN EMMC_PEIM_MEM_POOL *Pool,\r
363 IN UINTN Size\r
364 );\r
365\r
366/**\r
367 Free the allocated memory back to the memory pool.\r
368\r
369 @param Pool The memory pool of the host controller.\r
370 @param Mem The memory to free.\r
371 @param Size The size of the memory to free.\r
372\r
373**/\r
374VOID\r
375EmmcPeimFreeMem (\r
376 IN EMMC_PEIM_MEM_POOL *Pool,\r
377 IN VOID *Mem,\r
378 IN UINTN Size\r
379 );\r
380\r
381#endif\r