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