]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.h
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Bus / Ufs / UfsBlockIoPei / UfsBlockIoPei.h
CommitLineData
0591696e
FT
1/** @file\r
2\r
d1102dba 3 Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
0591696e
FT
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 _UFS_BLOCK_IO_PEI_H_\r
15#define _UFS_BLOCK_IO_PEI_H_\r
16\r
17#include <PiPei.h>\r
18\r
19#include <Ppi/UfsHostController.h>\r
20#include <Ppi/BlockIo.h>\r
9d02f824 21#include <Ppi/BlockIo2.h>\r
44a0857e
HW
22#include <Ppi/IoMmu.h>\r
23#include <Ppi/EndOfPeiPhase.h>\r
0591696e
FT
24\r
25#include <Library/DebugLib.h>\r
26#include <Library/BaseLib.h>\r
27#include <Library/BaseMemoryLib.h>\r
28#include <Library/MemoryAllocationLib.h>\r
29#include <Library/IoLib.h>\r
30#include <Library/TimerLib.h>\r
31#include <Library/PeiServicesLib.h>\r
32\r
33#include <IndustryStandard/Scsi.h>\r
34\r
35#include "UfsHci.h"\r
36#include "UfsHcMem.h"\r
37\r
38#define UFS_PEIM_HC_SIG SIGNATURE_32 ('U', 'F', 'S', 'H')\r
39\r
40#define UFS_PEIM_MAX_LUNS 8\r
41\r
42typedef struct {\r
43 UINT8 Lun[UFS_PEIM_MAX_LUNS];\r
44 UINT16 BitMask:12; // Bit 0~7 is for common luns. Bit 8~11 is reserved for those well known luns\r
45 UINT16 Rsvd:4;\r
46} UFS_PEIM_EXPOSED_LUNS;\r
47\r
48typedef struct {\r
49 ///\r
50 /// The timeout, in 100 ns units, to use for the execution of this SCSI\r
51 /// Request Packet. A Timeout value of 0 means that this function\r
52 /// will wait indefinitely for the SCSI Request Packet to execute. If\r
53 /// Timeout is greater than zero, then this function will return\r
54 /// EFI_TIMEOUT if the time required to execute the SCSI\r
55 /// Request Packet is greater than Timeout.\r
56 ///\r
57 UINT64 Timeout;\r
58 ///\r
59 /// A pointer to the data buffer to transfer between the SCSI\r
60 /// controller and the SCSI device for read and bidirectional commands.\r
61 ///\r
62 VOID *InDataBuffer;\r
63 ///\r
64 /// A pointer to the data buffer to transfer between the SCSI\r
65 /// controller and the SCSI device for write or bidirectional commands.\r
66 ///\r
67 VOID *OutDataBuffer;\r
68 ///\r
69 /// A pointer to the sense data that was generated by the execution of\r
70 /// the SCSI Request Packet.\r
71 ///\r
72 VOID *SenseData;\r
73 ///\r
74 /// A pointer to buffer that contains the Command Data Block to\r
75 /// send to the SCSI device specified by Target and Lun.\r
76 ///\r
77 VOID *Cdb;\r
78 ///\r
79 /// On Input, the size, in bytes, of InDataBuffer. On output, the\r
80 /// number of bytes transferred between the SCSI controller and the SCSI device.\r
81 ///\r
82 UINT32 InTransferLength;\r
83 ///\r
84 /// On Input, the size, in bytes of OutDataBuffer. On Output, the\r
85 /// Number of bytes transferred between SCSI Controller and the SCSI device.\r
86 ///\r
87 UINT32 OutTransferLength;\r
88 ///\r
89 /// The length, in bytes, of the buffer Cdb. The standard values are 6,\r
90 /// 10, 12, and 16, but other values are possible if a variable length CDB is used.\r
91 ///\r
92 UINT8 CdbLength;\r
93 ///\r
94 /// The direction of the data transfer. 0 for reads, 1 for writes. A\r
95 /// value of 2 is Reserved for Bi-Directional SCSI commands.\r
96 ///\r
97 UINT8 DataDirection;\r
98 ///\r
99 /// On input, the length in bytes of the SenseData buffer. On\r
100 /// output, the number of bytes written to the SenseData buffer.\r
101 ///\r
102 UINT8 SenseDataLength;\r
103} UFS_SCSI_REQUEST_PACKET;\r
104\r
d1102dba 105typedef struct _UFS_PEIM_HC_PRIVATE_DATA {\r
0591696e
FT
106 UINT32 Signature;\r
107 EFI_HANDLE Controller;\r
108\r
109 UFS_PEIM_MEM_POOL *Pool;\r
110\r
111 EFI_PEI_RECOVERY_BLOCK_IO_PPI BlkIoPpi;\r
9d02f824 112 EFI_PEI_RECOVERY_BLOCK_IO2_PPI BlkIo2Ppi;\r
0591696e 113 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList;\r
9d02f824
FT
114 EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList;\r
115 EFI_PEI_BLOCK_IO2_MEDIA Media[UFS_PEIM_MAX_LUNS];\r
0591696e 116\r
44a0857e
HW
117 //\r
118 // EndOfPei callback is used to stop the UFS DMA operation\r
119 // after exit PEI phase.\r
120 //\r
121 EFI_PEI_NOTIFY_DESCRIPTOR EndOfPeiNotifyList;\r
122\r
0591696e
FT
123 UINTN UfsHcBase;\r
124 UINT32 Capabilities;\r
125\r
126 UINT8 TaskTag;\r
127\r
128 VOID *UtpTrlBase;\r
129 UINT8 Nutrs;\r
44a0857e 130 VOID *TrlMapping;\r
0591696e
FT
131 VOID *UtpTmrlBase;\r
132 UINT8 Nutmrs;\r
44a0857e 133 VOID *TmrlMapping;\r
0591696e
FT
134\r
135 UFS_PEIM_EXPOSED_LUNS Luns;\r
136} UFS_PEIM_HC_PRIVATE_DATA;\r
137\r
138#define UFS_TIMEOUT MultU64x32((UINT64)(3), 10000000)\r
139\r
140#define ROUNDUP8(x) (((x) % 8 == 0) ? (x) : ((x) / 8 + 1) * 8)\r
141\r
142#define IS_ALIGNED(addr, size) (((UINTN) (addr) & (size - 1)) == 0)\r
143\r
144#define GET_UFS_PEIM_HC_PRIVATE_DATA_FROM_THIS(a) CR (a, UFS_PEIM_HC_PRIVATE_DATA, BlkIoPpi, UFS_PEIM_HC_SIG)\r
9d02f824 145#define GET_UFS_PEIM_HC_PRIVATE_DATA_FROM_THIS2(a) CR (a, UFS_PEIM_HC_PRIVATE_DATA, BlkIo2Ppi, UFS_PEIM_HC_SIG)\r
44a0857e 146#define GET_UFS_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY(a) CR (a, UFS_PEIM_HC_PRIVATE_DATA, EndOfPeiNotifyList, UFS_PEIM_HC_SIG)\r
0591696e
FT
147\r
148#define UFS_SCSI_OP_LENGTH_SIX 0x6\r
149#define UFS_SCSI_OP_LENGTH_TEN 0xa\r
150#define UFS_SCSI_OP_LENGTH_SIXTEEN 0x10\r
151\r
152typedef struct _UFS_DEVICE_MANAGEMENT_REQUEST_PACKET {\r
153 UINT64 Timeout;\r
154 VOID *InDataBuffer;\r
155 VOID *OutDataBuffer;\r
156 UINT8 Opcode;\r
157 UINT8 DescId;\r
158 UINT8 Index;\r
159 UINT8 Selector;\r
160 UINT32 InTransferLength;\r
161 UINT32 OutTransferLength;\r
162 UINT8 DataDirection;\r
163 UINT8 Ocs;\r
164} UFS_DEVICE_MANAGEMENT_REQUEST_PACKET;\r
165\r
166/**\r
167 Sends a UFS-supported SCSI Request Packet to a UFS device that is attached to the UFS host controller.\r
168\r
169 @param[in] Private The pointer to the UFS_PEIM_HC_PRIVATE_DATA data structure.\r
170 @param[in] Lun The LUN of the UFS device to send the SCSI Request Packet.\r
171 @param[in, out] Packet A pointer to the SCSI Request Packet to send to a specified Lun of the\r
172 UFS device.\r
173\r
174 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional\r
175 commands, InTransferLength bytes were transferred from\r
176 InDataBuffer. For write and bi-directional commands,\r
177 OutTransferLength bytes were transferred by\r
178 OutDataBuffer.\r
179 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request\r
180 Packet.\r
181 @retval EFI_OUT_OF_RESOURCES The resource for transfer is not available.\r
182 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.\r
183\r
184**/\r
185EFI_STATUS\r
186UfsExecScsiCmds (\r
187 IN UFS_PEIM_HC_PRIVATE_DATA *Private,\r
188 IN UINT8 Lun,\r
189 IN OUT UFS_SCSI_REQUEST_PACKET *Packet\r
190 );\r
191\r
192/**\r
193 Initialize the UFS host controller.\r
194\r
195 @param[in] Private The pointer to the UFS_PEIM_HC_PRIVATE_DATA data structure.\r
196\r
197 @retval EFI_SUCCESS The Ufs Host Controller is initialized successfully.\r
198 @retval Others A device error occurred while initializing the controller.\r
199\r
200**/\r
201EFI_STATUS\r
202UfsControllerInit (\r
203 IN UFS_PEIM_HC_PRIVATE_DATA *Private\r
204 );\r
205\r
206/**\r
207 Stop the UFS host controller.\r
208\r
209 @param[in] Private The pointer to the UFS_PEIM_HC_PRIVATE_DATA data structure.\r
210\r
211 @retval EFI_SUCCESS The Ufs Host Controller is stopped successfully.\r
212 @retval Others A device error occurred while stopping the controller.\r
213\r
214**/\r
215EFI_STATUS\r
216UfsControllerStop (\r
217 IN UFS_PEIM_HC_PRIVATE_DATA *Private\r
218 );\r
219\r
220/**\r
221 Set specified flag to 1 on a UFS device.\r
222\r
223 @param[in] Private The pointer to the UFS_PEIM_HC_PRIVATE_DATA data structure.\r
224 @param[in] FlagId The ID of flag to be set.\r
225\r
226 @retval EFI_SUCCESS The flag was set successfully.\r
227 @retval EFI_DEVICE_ERROR A device error occurred while attempting to set the flag.\r
228 @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of setting the flag.\r
229\r
230**/\r
231EFI_STATUS\r
232UfsSetFlag (\r
233 IN UFS_PEIM_HC_PRIVATE_DATA *Private,\r
234 IN UINT8 FlagId\r
235 );\r
236\r
237/**\r
238 Read or write specified device descriptor of a UFS device.\r
239\r
240 @param[in] Private The pointer to the UFS_PEIM_HC_PRIVATE_DATA data structure.\r
241 @param[in] Read The boolean variable to show r/w direction.\r
242 @param[in] DescId The ID of device descriptor.\r
243 @param[in] Index The Index of device descriptor.\r
244 @param[in] Selector The Selector of device descriptor.\r
245 @param[in, out] Descriptor The buffer of device descriptor to be read or written.\r
246 @param[in] DescSize The size of device descriptor buffer.\r
247\r
248 @retval EFI_SUCCESS The device descriptor was read/written successfully.\r
249 @retval EFI_DEVICE_ERROR A device error occurred while attempting to r/w the device descriptor.\r
250 @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of r/w the device descriptor.\r
251\r
252**/\r
253EFI_STATUS\r
254UfsRwDeviceDesc (\r
255 IN UFS_PEIM_HC_PRIVATE_DATA *Private,\r
256 IN BOOLEAN Read,\r
257 IN UINT8 DescId,\r
258 IN UINT8 Index,\r
259 IN UINT8 Selector,\r
260 IN OUT VOID *Descriptor,\r
261 IN UINT32 DescSize\r
262 );\r
263\r
264/**\r
265 Sends NOP IN cmd to a UFS device for initialization process request.\r
266 For more details, please refer to UFS 2.0 spec Figure 13.3.\r
267\r
268 @param[in] Private The pointer to the UFS_PEIM_HC_PRIVATE_DATA data structure.\r
269\r
270 @retval EFI_SUCCESS The NOP IN command was sent by the host. The NOP OUT response was\r
271 received successfully.\r
272 @retval EFI_DEVICE_ERROR A device error occurred while attempting to execute NOP IN command.\r
273 @retval EFI_OUT_OF_RESOURCES The resource for transfer is not available.\r
274 @retval EFI_TIMEOUT A timeout occurred while waiting for the NOP IN command to execute.\r
275\r
276**/\r
277EFI_STATUS\r
278UfsExecNopCmds (\r
279 IN UFS_PEIM_HC_PRIVATE_DATA *Private\r
280 );\r
281\r
282/**\r
283 Gets the count of block I/O devices that one specific block driver detects.\r
284\r
d1102dba 285 This function is used for getting the count of block I/O devices that one\r
0591696e 286 specific block driver detects. To the PEI ATAPI driver, it returns the number\r
d1102dba
LG
287 of all the detected ATAPI devices it detects during the enumeration process.\r
288 To the PEI legacy floppy driver, it returns the number of all the legacy\r
289 devices it finds during its enumeration process. If no device is detected,\r
290 then the function will return zero.\r
291\r
292 @param[in] PeiServices General-purpose services that are available\r
0591696e 293 to every PEIM.\r
d1102dba 294 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI\r
0591696e
FT
295 instance.\r
296 @param[out] NumberBlockDevices The number of block I/O devices discovered.\r
297\r
298 @retval EFI_SUCCESS The operation performed successfully.\r
299\r
300**/\r
301EFI_STATUS\r
302EFIAPI\r
303UfsBlockIoPeimGetDeviceNo (\r
304 IN EFI_PEI_SERVICES **PeiServices,\r
305 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
306 OUT UINTN *NumberBlockDevices\r
307 );\r
308\r
309/**\r
310 Gets a block device's media information.\r
311\r
d1102dba
LG
312 This function will provide the caller with the specified block device's media\r
313 information. If the media changes, calling this function will update the media\r
0591696e
FT
314 information accordingly.\r
315\r
316 @param[in] PeiServices General-purpose services that are available to every\r
317 PEIM\r
318 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.\r
d1102dba
LG
319 @param[in] DeviceIndex Specifies the block device to which the function wants\r
320 to talk. Because the driver that implements Block I/O\r
321 PPIs will manage multiple block devices, the PPIs that\r
322 want to talk to a single device must specify the\r
0591696e 323 device index that was assigned during the enumeration\r
d1102dba 324 process. This index is a number from one to\r
0591696e 325 NumberBlockDevices.\r
d1102dba
LG
326 @param[out] MediaInfo The media information of the specified block media.\r
327 The caller is responsible for the ownership of this\r
0591696e
FT
328 data structure.\r
329\r
d1102dba
LG
330 @par Note:\r
331 The MediaInfo structure describes an enumeration of possible block device\r
332 types. This enumeration exists because no device paths are actually passed\r
333 across interfaces that describe the type or class of hardware that is publishing\r
0591696e 334 the block I/O interface. This enumeration will allow for policy decisions\r
d1102dba
LG
335 in the Recovery PEIM, such as "Try to recover from legacy floppy first,\r
336 LS-120 second, CD-ROM third." If there are multiple partitions abstracted\r
337 by a given device type, they should be reported in ascending order; this\r
338 order also applies to nested partitions, such as legacy MBR, where the\r
339 outermost partitions would have precedence in the reporting order. The\r
340 same logic applies to systems such as IDE that have precedence relationships\r
341 like "Master/Slave" or "Primary/Secondary". The master device should be\r
0591696e 342 reported first, the slave second.\r
d1102dba
LG
343\r
344 @retval EFI_SUCCESS Media information about the specified block device\r
0591696e 345 was obtained successfully.\r
d1102dba 346 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware\r
0591696e
FT
347 error.\r
348\r
349**/\r
350EFI_STATUS\r
351EFIAPI\r
352UfsBlockIoPeimGetMediaInfo (\r
353 IN EFI_PEI_SERVICES **PeiServices,\r
354 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
355 IN UINTN DeviceIndex,\r
356 OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo\r
357 );\r
358\r
359/**\r
360 Reads the requested number of blocks from the specified block device.\r
361\r
d1102dba 362 The function reads the requested number of blocks from the device. All the\r
0591696e
FT
363 blocks are read, or an error is returned. If there is no media in the device,\r
364 the function returns EFI_NO_MEDIA.\r
365\r
d1102dba 366 @param[in] PeiServices General-purpose services that are available to\r
0591696e
FT
367 every PEIM.\r
368 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.\r
d1102dba
LG
369 @param[in] DeviceIndex Specifies the block device to which the function wants\r
370 to talk. Because the driver that implements Block I/O\r
371 PPIs will manage multiple block devices, PPIs that\r
372 want to talk to a single device must specify the device\r
373 index that was assigned during the enumeration process.\r
0591696e
FT
374 This index is a number from one to NumberBlockDevices.\r
375 @param[in] StartLBA The starting logical block address (LBA) to read from\r
376 on the device\r
377 @param[in] BufferSize The size of the Buffer in bytes. This number must be\r
378 a multiple of the intrinsic block size of the device.\r
379 @param[out] Buffer A pointer to the destination buffer for the data.\r
d1102dba 380 The caller is responsible for the ownership of the\r
0591696e 381 buffer.\r
d1102dba 382\r
0591696e 383 @retval EFI_SUCCESS The data was read correctly from the device.\r
d1102dba 384 @retval EFI_DEVICE_ERROR The device reported an error while attempting\r
0591696e 385 to perform the read operation.\r
d1102dba 386 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not\r
0591696e
FT
387 valid, or the buffer is not properly aligned.\r
388 @retval EFI_NO_MEDIA There is no media in the device.\r
389 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of\r
390 the intrinsic block size of the device.\r
391\r
392**/\r
393EFI_STATUS\r
394EFIAPI\r
395UfsBlockIoPeimReadBlocks (\r
396 IN EFI_PEI_SERVICES **PeiServices,\r
397 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
398 IN UINTN DeviceIndex,\r
399 IN EFI_PEI_LBA StartLBA,\r
400 IN UINTN BufferSize,\r
401 OUT VOID *Buffer\r
402 );\r
403\r
9d02f824
FT
404/**\r
405 Gets the count of block I/O devices that one specific block driver detects.\r
406\r
d1102dba 407 This function is used for getting the count of block I/O devices that one\r
9d02f824 408 specific block driver detects. To the PEI ATAPI driver, it returns the number\r
d1102dba
LG
409 of all the detected ATAPI devices it detects during the enumeration process.\r
410 To the PEI legacy floppy driver, it returns the number of all the legacy\r
411 devices it finds during its enumeration process. If no device is detected,\r
412 then the function will return zero.\r
413\r
414 @param[in] PeiServices General-purpose services that are available\r
9d02f824 415 to every PEIM.\r
d1102dba 416 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI\r
9d02f824
FT
417 instance.\r
418 @param[out] NumberBlockDevices The number of block I/O devices discovered.\r
419\r
420 @retval EFI_SUCCESS The operation performed successfully.\r
421\r
422**/\r
423EFI_STATUS\r
424EFIAPI\r
425UfsBlockIoPeimGetDeviceNo2 (\r
426 IN EFI_PEI_SERVICES **PeiServices,\r
427 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r
428 OUT UINTN *NumberBlockDevices\r
429 );\r
430\r
431/**\r
432 Gets a block device's media information.\r
433\r
d1102dba
LG
434 This function will provide the caller with the specified block device's media\r
435 information. If the media changes, calling this function will update the media\r
9d02f824
FT
436 information accordingly.\r
437\r
438 @param[in] PeiServices General-purpose services that are available to every\r
439 PEIM\r
440 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.\r
d1102dba
LG
441 @param[in] DeviceIndex Specifies the block device to which the function wants\r
442 to talk. Because the driver that implements Block I/O\r
443 PPIs will manage multiple block devices, the PPIs that\r
444 want to talk to a single device must specify the\r
9d02f824 445 device index that was assigned during the enumeration\r
d1102dba 446 process. This index is a number from one to\r
9d02f824 447 NumberBlockDevices.\r
d1102dba
LG
448 @param[out] MediaInfo The media information of the specified block media.\r
449 The caller is responsible for the ownership of this\r
9d02f824
FT
450 data structure.\r
451\r
d1102dba
LG
452 @par Note:\r
453 The MediaInfo structure describes an enumeration of possible block device\r
454 types. This enumeration exists because no device paths are actually passed\r
455 across interfaces that describe the type or class of hardware that is publishing\r
9d02f824 456 the block I/O interface. This enumeration will allow for policy decisions\r
d1102dba
LG
457 in the Recovery PEIM, such as "Try to recover from legacy floppy first,\r
458 LS-120 second, CD-ROM third." If there are multiple partitions abstracted\r
459 by a given device type, they should be reported in ascending order; this\r
460 order also applies to nested partitions, such as legacy MBR, where the\r
461 outermost partitions would have precedence in the reporting order. The\r
462 same logic applies to systems such as IDE that have precedence relationships\r
463 like "Master/Slave" or "Primary/Secondary". The master device should be\r
9d02f824 464 reported first, the slave second.\r
d1102dba
LG
465\r
466 @retval EFI_SUCCESS Media information about the specified block device\r
9d02f824 467 was obtained successfully.\r
d1102dba 468 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware\r
9d02f824
FT
469 error.\r
470\r
471**/\r
472EFI_STATUS\r
473EFIAPI\r
474UfsBlockIoPeimGetMediaInfo2 (\r
475 IN EFI_PEI_SERVICES **PeiServices,\r
476 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r
477 IN UINTN DeviceIndex,\r
478 OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo\r
479 );\r
480\r
481/**\r
482 Reads the requested number of blocks from the specified block device.\r
483\r
d1102dba 484 The function reads the requested number of blocks from the device. All the\r
9d02f824
FT
485 blocks are read, or an error is returned. If there is no media in the device,\r
486 the function returns EFI_NO_MEDIA.\r
487\r
d1102dba 488 @param[in] PeiServices General-purpose services that are available to\r
9d02f824
FT
489 every PEIM.\r
490 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.\r
d1102dba
LG
491 @param[in] DeviceIndex Specifies the block device to which the function wants\r
492 to talk. Because the driver that implements Block I/O\r
493 PPIs will manage multiple block devices, PPIs that\r
494 want to talk to a single device must specify the device\r
495 index that was assigned during the enumeration process.\r
9d02f824
FT
496 This index is a number from one to NumberBlockDevices.\r
497 @param[in] StartLBA The starting logical block address (LBA) to read from\r
498 on the device\r
499 @param[in] BufferSize The size of the Buffer in bytes. This number must be\r
500 a multiple of the intrinsic block size of the device.\r
501 @param[out] Buffer A pointer to the destination buffer for the data.\r
d1102dba 502 The caller is responsible for the ownership of the\r
9d02f824 503 buffer.\r
d1102dba 504\r
9d02f824 505 @retval EFI_SUCCESS The data was read correctly from the device.\r
d1102dba 506 @retval EFI_DEVICE_ERROR The device reported an error while attempting\r
9d02f824 507 to perform the read operation.\r
d1102dba 508 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not\r
9d02f824
FT
509 valid, or the buffer is not properly aligned.\r
510 @retval EFI_NO_MEDIA There is no media in the device.\r
511 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of\r
512 the intrinsic block size of the device.\r
513\r
514**/\r
515EFI_STATUS\r
516EFIAPI\r
517UfsBlockIoPeimReadBlocks2 (\r
518 IN EFI_PEI_SERVICES **PeiServices,\r
519 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r
520 IN UINTN DeviceIndex,\r
521 IN EFI_PEI_LBA StartLBA,\r
522 IN UINTN BufferSize,\r
523 OUT VOID *Buffer\r
524 );\r
525\r
0591696e
FT
526/**\r
527 Initialize the memory management pool for the host controller.\r
d1102dba 528\r
0591696e
FT
529 @param Private The Ufs Peim driver private data.\r
530\r
531 @retval EFI_SUCCESS The memory pool is initialized.\r
532 @retval Others Fail to init the memory pool.\r
533\r
534**/\r
535EFI_STATUS\r
536UfsPeimInitMemPool (\r
537 IN UFS_PEIM_HC_PRIVATE_DATA *Private\r
538 );\r
539\r
44a0857e
HW
540/**\r
541 Release the memory management pool.\r
542\r
543 @param Pool The memory pool to free.\r
544\r
545 @retval EFI_DEVICE_ERROR Fail to free the memory pool.\r
546 @retval EFI_SUCCESS The memory pool is freed.\r
547\r
548**/\r
549EFI_STATUS\r
550UfsPeimFreeMemPool (\r
551 IN UFS_PEIM_MEM_POOL *Pool\r
552 );\r
553\r
0591696e
FT
554/**\r
555 Allocate some memory from the host controller's memory pool\r
556 which can be used to communicate with host controller.\r
d1102dba 557\r
0591696e
FT
558 @param Pool The host controller's memory pool.\r
559 @param Size Size of the memory to allocate.\r
560\r
561 @return The allocated memory or NULL.\r
562\r
563**/\r
564VOID *\r
565UfsPeimAllocateMem (\r
566 IN UFS_PEIM_MEM_POOL *Pool,\r
567 IN UINTN Size\r
568 );\r
569\r
570/**\r
571 Free the allocated memory back to the memory pool.\r
572\r
573 @param Pool The memory pool of the host controller.\r
574 @param Mem The memory to free.\r
575 @param Size The size of the memory to free.\r
576\r
577**/\r
578VOID\r
579UfsPeimFreeMem (\r
580 IN UFS_PEIM_MEM_POOL *Pool,\r
581 IN VOID *Mem,\r
582 IN UINTN Size\r
583 );\r
584\r
44a0857e
HW
585/**\r
586 Initialize IOMMU.\r
587**/\r
588VOID\r
589IoMmuInit (\r
590 VOID\r
591 );\r
592\r
593/**\r
594 Provides the controller-specific addresses required to access system memory from a\r
595 DMA bus master.\r
596\r
597 @param Operation Indicates if the bus master is going to read or write to system memory.\r
598 @param HostAddress The system memory address to map to the PCI controller.\r
599 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes\r
600 that were mapped.\r
601 @param DeviceAddress The resulting map address for the bus master PCI controller to use to\r
602 access the hosts HostAddress.\r
603 @param Mapping A resulting value to pass to Unmap().\r
604\r
605 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r
606 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.\r
607 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
608 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
609 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r
610\r
611**/\r
612EFI_STATUS\r
613IoMmuMap (\r
614 IN EDKII_IOMMU_OPERATION Operation,\r
615 IN VOID *HostAddress,\r
616 IN OUT UINTN *NumberOfBytes,\r
617 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
618 OUT VOID **Mapping\r
619 );\r
620\r
621/**\r
622 Completes the Map() operation and releases any corresponding resources.\r
623\r
624 @param Mapping The mapping value returned from Map().\r
625\r
626 @retval EFI_SUCCESS The range was unmapped.\r
627 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().\r
628 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r
629**/\r
630EFI_STATUS\r
631IoMmuUnmap (\r
632 IN VOID *Mapping\r
633 );\r
634\r
635/**\r
636 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or\r
637 OperationBusMasterCommonBuffer64 mapping.\r
638\r
639 @param Pages The number of pages to allocate.\r
640 @param HostAddress A pointer to store the base system memory address of the\r
641 allocated range.\r
642 @param DeviceAddress The resulting map address for the bus master PCI controller to use to\r
643 access the hosts HostAddress.\r
644 @param Mapping A resulting value to pass to Unmap().\r
645\r
646 @retval EFI_SUCCESS The requested memory pages were allocated.\r
647 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r
648 MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
649 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
650 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r
651\r
652**/\r
653EFI_STATUS\r
654IoMmuAllocateBuffer (\r
655 IN UINTN Pages,\r
656 OUT VOID **HostAddress,\r
657 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
658 OUT VOID **Mapping\r
659 );\r
660\r
661/**\r
662 Frees memory that was allocated with AllocateBuffer().\r
663\r
664 @param Pages The number of pages to free.\r
665 @param HostAddress The base system memory address of the allocated range.\r
666 @param Mapping The mapping value returned from Map().\r
667\r
668 @retval EFI_SUCCESS The requested memory pages were freed.\r
669 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
670 was not allocated with AllocateBuffer().\r
671\r
672**/\r
673EFI_STATUS\r
674IoMmuFreeBuffer (\r
675 IN UINTN Pages,\r
676 IN VOID *HostAddress,\r
677 IN VOID *Mapping\r
678 );\r
679\r
680/**\r
681 One notified function to cleanup the allocated DMA buffers at the end of PEI.\r
682\r
683 @param[in] PeiServices Pointer to PEI Services Table.\r
684 @param[in] NotifyDescriptor Pointer to the descriptor for the Notification\r
685 event that caused this function to execute.\r
686 @param[in] Ppi Pointer to the PPI data associated with this function.\r
687\r
688 @retval EFI_SUCCESS The function completes successfully\r
689\r
690**/\r
691EFI_STATUS\r
692EFIAPI\r
693UfsEndOfPei (\r
694 IN EFI_PEI_SERVICES **PeiServices,\r
695 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
696 IN VOID *Ppi\r
697 );\r
698\r
0591696e 699#endif\r