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