TianoCore EDK2 master
Loading...
Searching...
No Matches
NvmExpressPei.h
Go to the documentation of this file.
1
11#ifndef _NVM_EXPRESS_PEI_H_
12#define _NVM_EXPRESS_PEI_H_
13
14#include <PiPei.h>
15
18
20#include <Ppi/BlockIo.h>
21#include <Ppi/BlockIo2.h>
24#include <Ppi/IoMmu.h>
25#include <Ppi/EndOfPeiPhase.h>
26#include <Ppi/PciDevice.h>
27
28#include <Library/DebugLib.h>
32#include <Library/IoLib.h>
33#include <Library/TimerLib.h>
35
36//
37// Structure forward declarations
38//
41
51#define IS_PCI_NVMHCI(_p) IS_CLASS3 (_p, PCI_CLASS_MASS_STORAGE, PCI_CLASS_MASS_STORAGE_SOLID_STATE, PCI_IF_MASS_STORAGE_SOLID_STATE_ENTERPRISE_NVMHCI)
52
53#include "NvmExpressPeiHci.h"
57
58//
59// NVME PEI driver implementation related definitions
60//
61#define NVME_MAX_QUEUES 2 // Number of I/O queues supported by the driver, 1 for AQ, 1 for CQ
62#define NVME_ASQ_SIZE 1 // Number of admin submission queue entries, which is 0-based
63#define NVME_ACQ_SIZE 1 // Number of admin completion queue entries, which is 0-based
64#define NVME_CSQ_SIZE 63 // Number of I/O submission queue entries, which is 0-based
65#define NVME_CCQ_SIZE 63 // Number of I/O completion queue entries, which is 0-based
66#define NVME_PRP_SIZE (8) // Pages of PRP list
67
68#define NVME_MEM_MAX_PAGES \
69 ( \
70 1 /* ASQ */ + \
71 1 /* ACQ */ + \
72 1 /* SQs */ + \
73 1 /* CQs */ + \
74 NVME_PRP_SIZE) /* PRPs */
75
76#define NVME_ADMIN_QUEUE 0x00
77#define NVME_IO_QUEUE 0x01
78#define NVME_GENERIC_TIMEOUT 5000000 // Generic PassThru command timeout value, in us unit
79#define NVME_POLL_INTERVAL 100 // Poll interval for PassThru command, in us unit
80
81//
82// Nvme namespace data structure.
83//
85 UINT32 NamespaceId;
86 UINT64 NamespaceUuid;
88
90};
91
92#define NVME_CONTROLLER_NSID 0
93
94//
95// Unique signature for private data structure.
96//
97#define NVME_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('N','V','P','C')
98
99//
100// Nvme controller private data structure.
101//
103 UINT32 Signature;
104 UINTN MmioBase;
106 UINTN DevicePathLength;
107 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
108
111 EDKII_PEI_STORAGE_SECURITY_CMD_PPI StorageSecurityPpi;
113 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList;
114 EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList;
115 EFI_PEI_PPI_DESCRIPTOR StorageSecurityPpiList;
116 EFI_PEI_PPI_DESCRIPTOR NvmePassThruPpiList;
117 EFI_PEI_NOTIFY_DESCRIPTOR EndOfPeiNotifyList;
118
119 //
120 // Pointer to identify controller data
121 //
122 NVME_ADMIN_CONTROLLER_DATA *ControllerData;
123
124 //
125 // (4 + NVME_PRP_SIZE) x 4kB aligned buffers will be carved out of this buffer
126 // 1st 4kB boundary is the start of the admin submission queue
127 // 2nd 4kB boundary is the start of the admin completion queue
128 // 3rd 4kB boundary is the start of I/O submission queue
129 // 4th 4kB boundary is the start of I/O completion queue
130 // 5th 4kB boundary is the start of PRP list buffers
131 //
132 VOID *Buffer;
133 VOID *BufferMapping;
134
135 //
136 // Pointers to 4kB aligned submission & completion queues
137 //
138 NVME_SQ *SqBuffer[NVME_MAX_QUEUES];
139 NVME_CQ *CqBuffer[NVME_MAX_QUEUES];
140
141 //
142 // Submission and completion queue indices
143 //
144 NVME_SQTDBL SqTdbl[NVME_MAX_QUEUES];
145 NVME_CQHDBL CqHdbl[NVME_MAX_QUEUES];
146
147 UINT8 Pt[NVME_MAX_QUEUES];
148 UINT16 Cid[NVME_MAX_QUEUES];
149
150 //
151 // Nvme controller capabilities
152 //
153 NVME_CAP Cap;
154
155 //
156 // Namespaces information on the controller
157 //
158 UINT32 ActiveNamespaceNum;
159 PEI_NVME_NAMESPACE_INFO *NamespaceInfo;
160};
161
162#define GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO(a) \
163 CR (a, PEI_NVME_CONTROLLER_PRIVATE_DATA, BlkIoPpi, NVME_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE)
164#define GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO2(a) \
165 CR (a, PEI_NVME_CONTROLLER_PRIVATE_DATA, BlkIo2Ppi, NVME_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE)
166#define GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_STROAGE_SECURITY(a) \
167 CR (a, PEI_NVME_CONTROLLER_PRIVATE_DATA, StorageSecurityPpi, NVME_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE)
168#define GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_NVME_PASSTHRU(a) \
169 CR (a, PEI_NVME_CONTROLLER_PRIVATE_DATA, NvmePassThruPpi, NVME_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE)
170#define GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY(a) \
171 CR (a, PEI_NVME_CONTROLLER_PRIVATE_DATA, EndOfPeiNotifyList, NVME_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE)
172
173//
174// Internal functions
175//
176
197 IN UINTN Pages,
198 OUT VOID **HostAddress,
199 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
200 OUT VOID **Mapping
201 );
202
217 IN UINTN Pages,
218 IN VOID *HostAddress,
219 IN VOID *Mapping
220 );
221
242IoMmuMap (
243 IN EDKII_IOMMU_OPERATION Operation,
244 IN VOID *HostAddress,
245 IN OUT UINTN *NumberOfBytes,
246 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
247 OUT VOID **Mapping
248 );
249
261 IN VOID *Mapping
262 );
263
276EFIAPI
278 IN EFI_PEI_SERVICES **PeiServices,
279 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
280 IN VOID *Ppi
281 );
282
298 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
299 OUT UINTN *InstanceSize,
300 OUT BOOLEAN *EntireDevicePathEnd
301 );
302
316 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
317 IN UINTN DevicePathLength
318 );
319
340 IN UINT32 NamespaceId,
341 IN UINT64 NamespaceUuid,
342 OUT UINTN *DevicePathLength,
343 OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
344 );
345
356BOOLEAN
358 IN EFI_DEVICE_PATH_PROTOCOL *HcDevicePath,
359 IN UINTN HcDevicePathLength
360 );
361
375EFIAPI
377 IN EFI_PEI_SERVICES **PeiServices,
378 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
379 IN VOID *Ppi
380 );
381
395EFIAPI
397 IN EFI_PEI_SERVICES **PeiServices,
398 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
399 IN VOID *Ppi
400 );
401
402#endif
UINT64 UINTN
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS IoMmuUnmap(IN VOID *Mapping)
Definition: DmaMem.c:132
EFI_STATUS NvmeBuildDevicePath(IN PEI_NVME_CONTROLLER_PRIVATE_DATA *Private, IN UINT32 NamespaceId, IN UINT64 NamespaceUuid, OUT UINTN *DevicePathLength, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
Definition: DevicePath.c:177
BOOLEAN NvmeS3SkipThisController(IN EFI_DEVICE_PATH_PROTOCOL *HcDevicePath, IN UINTN HcDevicePathLength)
EFI_STATUS IoMmuAllocateBuffer(IN UINTN Pages, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
Definition: DmaMem.c:170
EFI_STATUS EFIAPI NvmePeimEndOfPei(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
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 GetDevicePathInstanceSize(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT UINTN *InstanceSize, OUT BOOLEAN *EntireDevicePathEnd)
Definition: DevicePath.c:55
EFI_STATUS NvmeIsHcDevicePathValid(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINTN DevicePathLength)
Definition: DevicePath.c:105
EFI_STATUS EFIAPI NvmePciDevicePpiInstallationCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS EFIAPI NvmeHostControllerPpiInstallationCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS IoMmuFreeBuffer(IN UINTN Pages, IN VOID *HostAddress, IN VOID *Mapping)
Definition: DmaMem.c:251
EDKII_IOMMU_OPERATION
Definition: IoMmu.h:44
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
Definition: Nvme.h:55
Definition: Nvme.h:901
Definition: Nvme.h:865