]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Sd/SdBlockIoPei/SdBlockIoPei.h
MdeModulePkg NvmExpressDxe: Add NamespaceId validity check in PassThru
[mirror_edk2.git] / MdeModulePkg / Bus / Sd / SdBlockIoPei / SdBlockIoPei.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 _SD_BLOCK_IO_PEI_H_\r
15#define _SD_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/Sd.h>\r
32\r
33typedef struct _SD_PEIM_HC_PRIVATE_DATA SD_PEIM_HC_PRIVATE_DATA;\r
34typedef struct _SD_PEIM_HC_SLOT SD_PEIM_HC_SLOT;\r
35typedef struct _SD_TRB SD_TRB;\r
36\r
37#include "SdHci.h"\r
38#include "SdHcMem.h"\r
39\r
40#define SD_PEIM_SIG SIGNATURE_32 ('S', 'D', 'C', 'P')\r
41#define SD_PEIM_SLOT_SIG SIGNATURE_32 ('S', 'D', 'C', 'S')\r
42\r
43#define SD_PEIM_MAX_SLOTS 6\r
44\r
45struct _SD_PEIM_HC_SLOT {\r
46 UINT32 Signature;\r
47 EFI_PEI_BLOCK_IO2_MEDIA Media;\r
48\r
49 UINTN SdHcBase;\r
50 SD_HC_SLOT_CAP Capability;\r
51 SD_CSD Csd;\r
52 BOOLEAN SectorAddressing;\r
53 SD_PEIM_HC_PRIVATE_DATA *Private;\r
54};\r
55\r
56struct _SD_PEIM_HC_PRIVATE_DATA {\r
57 UINT32 Signature;\r
58 SD_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
63 SD_PEIM_HC_SLOT Slot[SD_PEIM_MAX_SLOTS];\r
64 UINT8 SlotNum;\r
65 UINT8 TotalBlkIoDevices;\r
66};\r
67\r
68#define SD_TIMEOUT MultU64x32((UINT64)(3), 1000000)\r
69#define GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS(a) CR (a, SD_PEIM_HC_PRIVATE_DATA, BlkIoPpi, SD_PEIM_SIG)\r
70#define GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS2(a) CR (a, SD_PEIM_HC_PRIVATE_DATA, BlkIo2Ppi, SD_PEIM_SIG)\r
71\r
72struct _SD_TRB {\r
73 SD_PEIM_HC_SLOT *Slot;\r
74 UINT16 BlockSize;\r
75\r
76 SD_COMMAND_PACKET *Packet;\r
77 VOID *Data;\r
78 UINT32 DataLen;\r
79 BOOLEAN Read;\r
80 SD_HC_TRANSFER_MODE Mode;\r
81\r
82 UINT64 Timeout;\r
83\r
84 SD_HC_ADMA_DESC_LINE *AdmaDesc;\r
85 UINTN AdmaDescSize;\r
86};\r
87\r
88/**\r
89 Gets the count of block I/O devices that one specific block driver detects.\r
90\r
91 This function is used for getting the count of block I/O devices that one\r
92 specific block driver detects. To the PEI ATAPI driver, it returns the number\r
93 of all the detected ATAPI devices it detects during the enumeration process.\r
94 To the PEI legacy floppy driver, it returns the number of all the legacy\r
95 devices it finds during its enumeration process. If no device is detected,\r
96 then the function will return zero.\r
97\r
98 @param[in] PeiServices General-purpose services that are available\r
99 to every PEIM.\r
100 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI\r
101 instance.\r
102 @param[out] NumberBlockDevices The number of block I/O devices discovered.\r
103\r
104 @retval EFI_SUCCESS The operation performed successfully.\r
105\r
106**/\r
107EFI_STATUS\r
108EFIAPI\r
109SdBlockIoPeimGetDeviceNo (\r
110 IN EFI_PEI_SERVICES **PeiServices,\r
111 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
112 OUT UINTN *NumberBlockDevices\r
113 );\r
114\r
115/**\r
116 Gets a block device's media information.\r
117\r
118 This function will provide the caller with the specified block device's media\r
119 information. If the media changes, calling this function will update the media\r
120 information accordingly.\r
121\r
122 @param[in] PeiServices General-purpose services that are available to every\r
123 PEIM\r
124 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.\r
125 @param[in] DeviceIndex Specifies the block device to which the function wants\r
126 to talk. Because the driver that implements Block I/O\r
127 PPIs will manage multiple block devices, the PPIs that\r
128 want to talk to a single device must specify the\r
129 device index that was assigned during the enumeration\r
130 process. This index is a number from one to\r
131 NumberBlockDevices.\r
132 @param[out] MediaInfo The media information of the specified block media.\r
133 The caller is responsible for the ownership of this\r
134 data structure.\r
135\r
136 @par Note:\r
137 The MediaInfo structure describes an enumeration of possible block device\r
138 types. This enumeration exists because no device paths are actually passed\r
139 across interfaces that describe the type or class of hardware that is publishing\r
140 the block I/O interface. This enumeration will allow for policy decisions\r
141 in the Recovery PEIM, such as "Try to recover from legacy floppy first,\r
142 LS-120 second, CD-ROM third." If there are multiple partitions abstracted\r
143 by a given device type, they should be reported in ascending order; this\r
144 order also applies to nested partitions, such as legacy MBR, where the\r
145 outermost partitions would have precedence in the reporting order. The\r
146 same logic applies to systems such as IDE that have precedence relationships\r
147 like "Master/Slave" or "Primary/Secondary". The master device should be\r
148 reported first, the slave second.\r
149\r
150 @retval EFI_SUCCESS Media information about the specified block device\r
151 was obtained successfully.\r
152 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware\r
153 error.\r
154\r
155**/\r
156EFI_STATUS\r
157EFIAPI\r
158SdBlockIoPeimGetMediaInfo (\r
159 IN EFI_PEI_SERVICES **PeiServices,\r
160 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
161 IN UINTN DeviceIndex,\r
162 OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo\r
163 );\r
164\r
165/**\r
166 Reads the requested number of blocks from the specified block device.\r
167\r
168 The function reads the requested number of blocks from the device. All the\r
169 blocks are read, or an error is returned. If there is no media in the device,\r
170 the function returns EFI_NO_MEDIA.\r
171\r
172 @param[in] PeiServices General-purpose services that are available to\r
173 every PEIM.\r
174 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.\r
175 @param[in] DeviceIndex Specifies the block device to which the function wants\r
176 to talk. Because the driver that implements Block I/O\r
177 PPIs will manage multiple block devices, PPIs that\r
178 want to talk to a single device must specify the device\r
179 index that was assigned during the enumeration process.\r
180 This index is a number from one to NumberBlockDevices.\r
181 @param[in] StartLBA The starting logical block address (LBA) to read from\r
182 on the device\r
183 @param[in] BufferSize The size of the Buffer in bytes. This number must be\r
184 a multiple of the intrinsic block size of the device.\r
185 @param[out] Buffer A pointer to the destination buffer for the data.\r
186 The caller is responsible for the ownership of the\r
187 buffer.\r
188\r
189 @retval EFI_SUCCESS The data was read correctly from the device.\r
190 @retval EFI_DEVICE_ERROR The device reported an error while attempting\r
191 to perform the read operation.\r
192 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not\r
193 valid, or the buffer is not properly aligned.\r
194 @retval EFI_NO_MEDIA There is no media in the device.\r
195 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of\r
196 the intrinsic block size of the device.\r
197\r
198**/\r
199EFI_STATUS\r
200EFIAPI\r
201SdBlockIoPeimReadBlocks (\r
202 IN EFI_PEI_SERVICES **PeiServices,\r
203 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
204 IN UINTN DeviceIndex,\r
205 IN EFI_PEI_LBA StartLBA,\r
206 IN UINTN BufferSize,\r
207 OUT VOID *Buffer\r
208 );\r
209\r
210/**\r
211 Gets the count of block I/O devices that one specific block driver detects.\r
212\r
213 This function is used for getting the count of block I/O devices that one\r
214 specific block driver detects. To the PEI ATAPI driver, it returns the number\r
215 of all the detected ATAPI devices it detects during the enumeration process.\r
216 To the PEI legacy floppy driver, it returns the number of all the legacy\r
217 devices it finds during its enumeration process. If no device is detected,\r
218 then the function will return zero.\r
219\r
220 @param[in] PeiServices General-purpose services that are available\r
221 to every PEIM.\r
222 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI\r
223 instance.\r
224 @param[out] NumberBlockDevices The number of block I/O devices discovered.\r
225\r
226 @retval EFI_SUCCESS The operation performed successfully.\r
227\r
228**/\r
229EFI_STATUS\r
230EFIAPI\r
231SdBlockIoPeimGetDeviceNo2 (\r
232 IN EFI_PEI_SERVICES **PeiServices,\r
233 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r
234 OUT UINTN *NumberBlockDevices\r
235 );\r
236\r
237/**\r
238 Gets a block device's media information.\r
239\r
240 This function will provide the caller with the specified block device's media\r
241 information. If the media changes, calling this function will update the media\r
242 information accordingly.\r
243\r
244 @param[in] PeiServices General-purpose services that are available to every\r
245 PEIM\r
246 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.\r
247 @param[in] DeviceIndex Specifies the block device to which the function wants\r
248 to talk. Because the driver that implements Block I/O\r
249 PPIs will manage multiple block devices, the PPIs that\r
250 want to talk to a single device must specify the\r
251 device index that was assigned during the enumeration\r
252 process. This index is a number from one to\r
253 NumberBlockDevices.\r
254 @param[out] MediaInfo The media information of the specified block media.\r
255 The caller is responsible for the ownership of this\r
256 data structure.\r
257\r
258 @par Note:\r
259 The MediaInfo structure describes an enumeration of possible block device\r
260 types. This enumeration exists because no device paths are actually passed\r
261 across interfaces that describe the type or class of hardware that is publishing\r
262 the block I/O interface. This enumeration will allow for policy decisions\r
263 in the Recovery PEIM, such as "Try to recover from legacy floppy first,\r
264 LS-120 second, CD-ROM third." If there are multiple partitions abstracted\r
265 by a given device type, they should be reported in ascending order; this\r
266 order also applies to nested partitions, such as legacy MBR, where the\r
267 outermost partitions would have precedence in the reporting order. The\r
268 same logic applies to systems such as IDE that have precedence relationships\r
269 like "Master/Slave" or "Primary/Secondary". The master device should be\r
270 reported first, the slave second.\r
271\r
272 @retval EFI_SUCCESS Media information about the specified block device\r
273 was obtained successfully.\r
274 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware\r
275 error.\r
276\r
277**/\r
278EFI_STATUS\r
279EFIAPI\r
280SdBlockIoPeimGetMediaInfo2 (\r
281 IN EFI_PEI_SERVICES **PeiServices,\r
282 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r
283 IN UINTN DeviceIndex,\r
284 OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo\r
285 );\r
286\r
287/**\r
288 Reads the requested number of blocks from the specified block device.\r
289\r
290 The function reads the requested number of blocks from the device. All the\r
291 blocks are read, or an error is returned. If there is no media in the device,\r
292 the function returns EFI_NO_MEDIA.\r
293\r
294 @param[in] PeiServices General-purpose services that are available to\r
295 every PEIM.\r
296 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.\r
297 @param[in] DeviceIndex Specifies the block device to which the function wants\r
298 to talk. Because the driver that implements Block I/O\r
299 PPIs will manage multiple block devices, PPIs that\r
300 want to talk to a single device must specify the device\r
301 index that was assigned during the enumeration process.\r
302 This index is a number from one to NumberBlockDevices.\r
303 @param[in] StartLBA The starting logical block address (LBA) to read from\r
304 on the device\r
305 @param[in] BufferSize The size of the Buffer in bytes. This number must be\r
306 a multiple of the intrinsic block size of the device.\r
307 @param[out] Buffer A pointer to the destination buffer for the data.\r
308 The caller is responsible for the ownership of the\r
309 buffer.\r
310\r
311 @retval EFI_SUCCESS The data was read correctly from the device.\r
312 @retval EFI_DEVICE_ERROR The device reported an error while attempting\r
313 to perform the read operation.\r
314 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not\r
315 valid, or the buffer is not properly aligned.\r
316 @retval EFI_NO_MEDIA There is no media in the device.\r
317 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of\r
318 the intrinsic block size of the device.\r
319\r
320**/\r
321EFI_STATUS\r
322EFIAPI\r
323SdBlockIoPeimReadBlocks2 (\r
324 IN EFI_PEI_SERVICES **PeiServices,\r
325 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r
326 IN UINTN DeviceIndex,\r
327 IN EFI_PEI_LBA StartLBA,\r
328 IN UINTN BufferSize,\r
329 OUT VOID *Buffer\r
330 );\r
331\r
332/**\r
333 Initialize the memory management pool for the host controller.\r
334\r
335 @param Private The Sd Peim driver private data.\r
336\r
337 @retval EFI_SUCCESS The memory pool is initialized.\r
338 @retval Others Fail to init the memory pool.\r
339\r
340**/\r
341EFI_STATUS\r
342SdPeimInitMemPool (\r
343 IN SD_PEIM_HC_PRIVATE_DATA *Private\r
344 );\r
345\r
346/**\r
347 Allocate some memory from the host controller's memory pool\r
348 which can be used to communicate with host controller.\r
349\r
350 @param Pool The host controller's memory pool.\r
351 @param Size Size of the memory to allocate.\r
352\r
353 @return The allocated memory or NULL.\r
354\r
355**/\r
356VOID *\r
357SdPeimAllocateMem (\r
358 IN SD_PEIM_MEM_POOL *Pool,\r
359 IN UINTN Size\r
360 );\r
361\r
362/**\r
363 Free the allocated memory back to the memory pool.\r
364\r
365 @param Pool The memory pool of the host controller.\r
366 @param Mem The memory to free.\r
367 @param Size The size of the memory to free.\r
368\r
369**/\r
370VOID\r
371SdPeimFreeMem (\r
372 IN SD_PEIM_MEM_POOL *Pool,\r
373 IN VOID *Mem,\r
374 IN UINTN Size\r
375 );\r
376\r
377#endif\r