TianoCore EDK2 master
Loading...
Searching...
No Matches
UfsBlockIoPei.h
Go to the documentation of this file.
1
8#ifndef _UFS_BLOCK_IO_PEI_H_
9#define _UFS_BLOCK_IO_PEI_H_
10
11#include <PiPei.h>
12
15#include <Ppi/BlockIo.h>
16#include <Ppi/BlockIo2.h>
17#include <Ppi/IoMmu.h>
18#include <Ppi/EndOfPeiPhase.h>
19
20#include <Library/DebugLib.h>
21#include <Library/BaseLib.h>
24#include <Library/IoLib.h>
25#include <Library/TimerLib.h>
26#include <Library/PcdLib.h>
28
30
31#include "UfsHci.h"
32#include "UfsHcMem.h"
33
34#define UFS_PEIM_HC_SIG SIGNATURE_32 ('U', 'F', 'S', 'H')
35
36#define UFS_PEIM_MAX_LUNS 8
37
38typedef struct {
39 UINT8 Lun[UFS_PEIM_MAX_LUNS];
40 UINT16 BitMask : 12; // Bit 0~7 is for common luns. Bit 8~11 is reserved for those well known luns
41 UINT16 Rsvd : 4;
43
44typedef struct {
53 UINT64 Timeout;
68 VOID *SenseData;
73 VOID *Cdb;
88 UINT8 CdbLength;
100
102 UINT32 Signature;
103 EFI_HANDLE Controller;
104
105 UFS_PEIM_MEM_POOL *Pool;
106
109 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList;
110 EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList;
111 EFI_PEI_BLOCK_IO2_MEDIA Media[UFS_PEIM_MAX_LUNS];
112
113 //
114 // EndOfPei callback is used to stop the UFS DMA operation
115 // after exit PEI phase.
116 //
117 EFI_PEI_NOTIFY_DESCRIPTOR EndOfPeiNotifyList;
118
119 UINTN UfsHcBase;
120 UINT32 Capabilities;
121
122 UINT8 TaskTag;
123
124 VOID *UtpTrlBase;
125 UINT8 Nutrs;
126 VOID *TrlMapping;
127 VOID *UtpTmrlBase;
128 UINT8 Nutmrs;
129 VOID *TmrlMapping;
130
133
134#define UFS_TIMEOUT MultU64x32((UINT64)(3), 10000000)
135
136#define ROUNDUP8(x) (((x) % 8 == 0) ? (x) : ((x) / 8 + 1) * 8)
137
138#define GET_UFS_PEIM_HC_PRIVATE_DATA_FROM_THIS(a) CR (a, UFS_PEIM_HC_PRIVATE_DATA, BlkIoPpi, UFS_PEIM_HC_SIG)
139#define GET_UFS_PEIM_HC_PRIVATE_DATA_FROM_THIS2(a) CR (a, UFS_PEIM_HC_PRIVATE_DATA, BlkIo2Ppi, UFS_PEIM_HC_SIG)
140#define GET_UFS_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY(a) CR (a, UFS_PEIM_HC_PRIVATE_DATA, EndOfPeiNotifyList, UFS_PEIM_HC_SIG)
141
142#define UFS_SCSI_OP_LENGTH_SIX 0x6
143#define UFS_SCSI_OP_LENGTH_TEN 0xa
144#define UFS_SCSI_OP_LENGTH_SIXTEEN 0x10
145
147 UINT64 Timeout;
148 VOID *InDataBuffer;
149 VOID *OutDataBuffer;
150 UINT8 Opcode;
151 UINT8 DescId;
152 UINT8 Index;
153 UINT8 Selector;
154 UINT32 InTransferLength;
155 UINT32 OutTransferLength;
156 UINT8 DataDirection;
157 UINT8 Ocs;
159
180 IN BOOLEAN Read,
181 IN UINT8 AttrId,
182 IN UINT8 Index,
183 IN UINT8 Selector,
184 IN OUT UINT32 *Attributes
185 );
186
209 IN UINT8 Lun,
211 );
212
224 IN EDKII_UFS_HC_PLATFORM_PPI *UfsHcPlatformPpi,
226 );
227
240 );
241
256 IN UINT8 FlagId
257 );
258
274 IN UINT8 FlagId,
275 OUT UINT8 *Value
276 );
277
297 IN BOOLEAN Read,
298 IN UINT8 DescId,
299 IN UINT8 Index,
300 IN UINT8 Selector,
301 IN OUT VOID *Descriptor,
302 IN UINT32 DescSize
303 );
304
321 );
322
343EFIAPI
345 IN EFI_PEI_SERVICES **PeiServices,
347 OUT UINTN *NumberBlockDevices
348 );
349
392EFIAPI
394 IN EFI_PEI_SERVICES **PeiServices,
396 IN UINTN DeviceIndex,
397 OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo
398 );
399
435EFIAPI
437 IN EFI_PEI_SERVICES **PeiServices,
439 IN UINTN DeviceIndex,
440 IN EFI_PEI_LBA StartLBA,
441 IN UINTN BufferSize,
442 OUT VOID *Buffer
443 );
444
465EFIAPI
467 IN EFI_PEI_SERVICES **PeiServices,
469 OUT UINTN *NumberBlockDevices
470 );
471
514EFIAPI
516 IN EFI_PEI_SERVICES **PeiServices,
518 IN UINTN DeviceIndex,
520 );
521
557EFIAPI
559 IN EFI_PEI_SERVICES **PeiServices,
561 IN UINTN DeviceIndex,
562 IN EFI_PEI_LBA StartLBA,
563 IN UINTN BufferSize,
564 OUT VOID *Buffer
565 );
566
579 );
580
593 );
594
605VOID *
607 IN UFS_PEIM_MEM_POOL *Pool,
608 IN UINTN Size
609 );
610
619VOID
621 IN UFS_PEIM_MEM_POOL *Pool,
622 IN VOID *Mem,
623 IN UINTN Size
624 );
625
629VOID
630IoMmuInit (
631 VOID
632 );
633
654IoMmuMap (
655 IN EDKII_IOMMU_OPERATION Operation,
656 IN VOID *HostAddress,
657 IN OUT UINTN *NumberOfBytes,
658 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
659 OUT VOID **Mapping
660 );
661
673 IN VOID *Mapping
674 );
675
696 IN UINTN Pages,
697 OUT VOID **HostAddress,
698 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
699 OUT VOID **Mapping
700 );
701
716 IN UINTN Pages,
717 IN VOID *HostAddress,
718 IN VOID *Mapping
719 );
720
733EFIAPI
735 IN EFI_PEI_SERVICES **PeiServices,
736 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
737 IN VOID *Ppi
738 );
739
740#endif
UINT64 UINTN
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
UINT64 EFI_PEI_LBA
Definition: BlockIo.h:41
EDKII_IOMMU_OPERATION
Definition: IoMmu.h:44
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
VOID * UfsPeimAllocateMem(IN UFS_PEIM_MEM_POOL *Pool, IN UINTN Size)
Definition: UfsHcMem.c:295
EFI_STATUS EFIAPI UfsBlockIoPeimReadBlocks(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, IN UINTN DeviceIndex, IN EFI_PEI_LBA StartLBA, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS UfsRwDeviceDesc(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN BOOLEAN Read, IN UINT8 DescId, IN UINT8 Index, IN UINT8 Selector, IN OUT VOID *Descriptor, IN UINT32 DescSize)
Definition: UfsHci.c:960
EFI_STATUS IoMmuUnmap(IN VOID *Mapping)
Definition: DmaMem.c:132
VOID UfsPeimFreeMem(IN UFS_PEIM_MEM_POOL *Pool, IN VOID *Mem, IN UINTN Size)
Definition: UfsHcMem.c:367
EFI_STATUS UfsRwAttributes(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN BOOLEAN Read, IN UINT8 AttrId, IN UINT8 Index, IN UINT8 Selector, IN OUT UINT32 *Attributes)
Definition: UfsHci.c:1014
EFI_STATUS IoMmuAllocateBuffer(IN UINTN Pages, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
Definition: DmaMem.c:170
EFI_STATUS UfsPeimFreeMemPool(IN UFS_PEIM_MEM_POOL *Pool)
Definition: UfsHcMem.c:264
EFI_STATUS UfsReadFlag(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN UINT8 FlagId, OUT UINT8 *Value)
Definition: UfsHci.c:1144
EFI_STATUS IoMmuMap(IN EDKII_IOMMU_OPERATION Operation, IN VOID *HostAddress, IN OUT UINTN *NumberOfBytes, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
Definition: DmaMem.c:60
EFI_STATUS EFIAPI UfsBlockIoPeimReadBlocks2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, IN UINTN DeviceIndex, IN EFI_PEI_LBA StartLBA, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS UfsPeimInitMemPool(IN UFS_PEIM_HC_PRIVATE_DATA *Private)
Definition: UfsHcMem.c:224
EFI_STATUS UfsExecNopCmds(IN UFS_PEIM_HC_PRIVATE_DATA *Private)
Definition: UfsHci.c:1171
EFI_STATUS EFIAPI UfsEndOfPei(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS UfsControllerInit(IN EDKII_UFS_HC_PLATFORM_PPI *UfsHcPlatformPpi, IN UFS_PEIM_HC_PRIVATE_DATA *Private)
Definition: UfsHci.c:1726
EFI_STATUS EFIAPI UfsBlockIoPeimGetMediaInfo(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, IN UINTN DeviceIndex, OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo)
EFI_STATUS UfsControllerStop(IN UFS_PEIM_HC_PRIVATE_DATA *Private)
Definition: UfsHci.c:1781
EFI_STATUS EFIAPI UfsBlockIoPeimGetDeviceNo2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, OUT UINTN *NumberBlockDevices)
EFI_STATUS EFIAPI UfsBlockIoPeimGetMediaInfo2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, IN UINTN DeviceIndex, OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo)
EFI_STATUS IoMmuFreeBuffer(IN UINTN Pages, IN VOID *HostAddress, IN VOID *Mapping)
Definition: DmaMem.c:251
VOID IoMmuInit(VOID)
Definition: DmaMem.c:375
EFI_STATUS UfsSetFlag(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN UINT8 FlagId)
Definition: UfsHci.c:1117
EFI_STATUS EFIAPI UfsBlockIoPeimGetDeviceNo(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, OUT UINTN *NumberBlockDevices)
EFI_STATUS UfsExecScsiCmds(IN UFS_PEIM_HC_PRIVATE_DATA *Private, IN UINT8 Lun, IN OUT UFS_SCSI_REQUEST_PACKET *Packet)
Definition: UfsHci.c:1251