14 EFI_PEI_PPI_DESCRIPTOR_PPI,
15 &gEfiPeiVirtualBlockIoPpiGuid,
20 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
21 &gEfiPeiVirtualBlockIo2PpiGuid,
26 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
27 &gEdkiiPeiStorageSecurityCommandPpiGuid,
32 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
33 &gEdkiiPeiNvmExpressPassThruPpiGuid,
38 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
39 &gEfiEndOfPeiSignalPpiGuid,
44 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
45 &gEdkiiPeiNvmExpressHostControllerPpiGuid,
50 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
51 &gEdkiiPeiPciDevicePpiGuid,
81 if (NamespaceData ==
NULL) {
82 return EFI_OUT_OF_RESOURCES;
93 if (EFI_ERROR (Status)) {
94 DEBUG ((DEBUG_ERROR,
"%a: NvmeIdentifyNamespace fail, Status - %r\n", __func__, Status));
101 if (NamespaceData->Ncap == 0) {
102 DEBUG ((DEBUG_INFO,
"%a: Namespace ID %d is an inactive one.\n", __func__, NamespaceId));
103 Status = EFI_DEVICE_ERROR;
107 DeviceIndex = Private->ActiveNamespaceNum;
108 NamespaceInfo = &Private->NamespaceInfo[DeviceIndex];
109 NamespaceInfo->NamespaceId = NamespaceId;
110 NamespaceInfo->NamespaceUuid = NamespaceData->Eui64;
111 NamespaceInfo->Controller = Private;
112 Private->ActiveNamespaceNum++;
117 Flbas = NamespaceData->Flbas;
118 LbaFmtIdx = Flbas & 0xF;
123 if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) {
126 "NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n",
128 NamespaceData->LbaFormat[LbaFmtIdx].Ms
130 Status = EFI_UNSUPPORTED;
134 Lbads = NamespaceData->LbaFormat[LbaFmtIdx].Lbads;
140 NamespaceInfo->Media.
BlockSize = (UINT32)1 << Lbads;
144 "%a: Namespace ID %d - BlockSize = 0x%x, LastBlock = 0x%lx\n",
152 if (NamespaceData !=
NULL) {
175 Private->ActiveNamespaceNum = 0;
184 for (NamespaceId = 1; NamespaceId <= Private->ControllerData->Nn; NamespaceId++) {
192 if (Private->ActiveNamespaceNum == 0) {
193 return EFI_NOT_FOUND;
220 Private = GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY (NotifyDescriptor);
249 DEBUG ((DEBUG_INFO,
"%a: Enters.\n", __func__));
255 if (EFI_ERROR (Status)) {
256 DEBUG ((DEBUG_ERROR,
"%a: Fail to get the current boot mode.\n", __func__));
264 if (EFI_ERROR (Status)) {
267 "%a: The device path is invalid.\n",
279 if ((BootMode == BOOT_ON_S3_RESUME) &&
284 "%a: skipped during S3.\n",
294 if (Private ==
NULL) {
297 "%a: Fail to allocate private data.\n",
300 return EFI_OUT_OF_RESOURCES;
310 &Private->BufferMapping
312 if (EFI_ERROR (Status)) {
315 "%a: Fail to allocate DMA buffers.\n",
322 DEBUG ((DEBUG_INFO,
"%a: DMA buffer base at 0x%x\n", __func__, Private->Buffer));
327 Private->Signature = NVME_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE;
328 Private->MmioBase = MmioBase;
329 Private->DevicePathLength = DevicePathLength;
330 Private->DevicePath = DevicePath;
336 if (EFI_ERROR (Status)) {
339 "%a: Controller initialization fail with Status - %r.\n",
351 if (EFI_ERROR (Status)) {
357 "%a: Namespaces discovery fail with Status - %r.\n",
368 Private->PassThruMode.Attributes = EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_PHYSICAL |
369 EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_LOGICAL |
370 EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_CMD_SET_NVM;
371 Private->PassThruMode.IoAlign =
sizeof (
UINTN);
372 Private->PassThruMode.NvmeVersion = EDKII_PEI_NVM_EXPRESS_PASS_THRU_PPI_REVISION;
373 Private->NvmePassThruPpi.Mode = &Private->PassThruMode;
378 &Private->NvmePassThruPpiList,
379 &mNvmePassThruPpiListTemplate,
382 Private->NvmePassThruPpiList.
Ppi = &Private->NvmePassThruPpi;
392 &Private->BlkIoPpiList,
393 &mNvmeBlkIoPpiListTemplate,
396 Private->BlkIoPpiList.
Ppi = &Private->BlkIoPpi;
398 Private->BlkIo2Ppi.
Revision = EFI_PEI_RECOVERY_BLOCK_IO2_PPI_REVISION;
403 &Private->BlkIo2PpiList,
404 &mNvmeBlkIo2PpiListTemplate,
407 Private->BlkIo2PpiList.
Ppi = &Private->BlkIo2Ppi;
413 if ((Private->ControllerData->Oacs & SECURITY_SEND_RECEIVE_SUPPORTED) != 0) {
416 "%a: Security Security Command PPI will be produced.\n",
419 Private->StorageSecurityPpi.Revision = EDKII_STORAGE_SECURITY_PPI_REVISION;
425 &Private->StorageSecurityPpiList,
426 &mNvmeStorageSecurityPpiListTemplate,
429 Private->StorageSecurityPpiList.
Ppi = &Private->StorageSecurityPpi;
434 &Private->EndOfPeiNotifyList,
435 &mNvmeEndOfPeiNotifyListTemplate,
460 UINTN DevicePathLength;
461 UINT64 EnabledPciAttributes;
468 Status = PciDevice->PciIo.Pci.Read (
471 PCI_CLASSCODE_OFFSET,
472 sizeof (PciData.Hdr.ClassCode),
473 PciData.Hdr.ClassCode
475 if (EFI_ERROR (Status)) {
476 return EFI_UNSUPPORTED;
480 return EFI_UNSUPPORTED;
483 Status = PciDevice->PciIo.Attributes (
487 &EnabledPciAttributes
489 if (EFI_ERROR (Status)) {
490 return EFI_UNSUPPORTED;
492 EnabledPciAttributes &= (UINT64)EFI_PCI_DEVICE_ENABLE;
493 Status = PciDevice->PciIo.Attributes (
496 EnabledPciAttributes,
499 if (EFI_ERROR (Status)) {
500 return EFI_UNSUPPORTED;
504 Status = PciDevice->PciIo.Pci.Read (
507 PCI_BASE_ADDRESSREG_OFFSET,
511 if (EFI_ERROR (Status)) {
512 return EFI_UNSUPPORTED;
515 switch (MmioBase & 0x07) {
520 MmioBase = MmioBase & 0xFFFFFFF0;
526 Status = PciDevice->PciIo.Pci.Read (
529 PCI_BASE_ADDRESSREG_OFFSET + 4,
536 if ( EFI_ERROR (Status)
537 || ((MmioBaseH != 0) && (
sizeof (
UINTN) ==
sizeof (UINT32))))
539 return EFI_UNSUPPORTED;
542 MmioBase = MmioBase & 0xFFFFFFF0;
543 MmioBase |=
LShiftU64 ((UINT64)MmioBaseH, 32);
549 return EFI_UNSUPPORTED;
553 DevicePath = PciDevice->DevicePath;
556 if (EFI_ERROR (Status)) {
559 "%a: Failed to init controller, with Status - %r\n",
609 UINTN DevicePathLength;
616 Status = NvmeHcPpi->GetNvmeHcMmioBar (
624 if (EFI_ERROR (Status)) {
628 Status = NvmeHcPpi->GetNvmeHcDevicePath (
634 if (EFI_ERROR (Status)) {
637 "%a: Fail to allocate get the device path for Controller %d.\n",
645 if (EFI_ERROR (Status)) {
648 "%a: Controller initialization fail for Controller %d with Status - %r.\n",
656 "%a: Controller %d has been successfully initialized.\n",
691 return EFI_INVALID_PARAMETER;
715 DEBUG ((DEBUG_INFO,
"%a: Enters.\n", __func__));
EFI_STATUS IoMmuAllocateBuffer(IN UINTN Pages, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS NvmeIsHcDevicePathValid(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINTN DevicePathLength)
#define MSG_NVME_NAMESPACE_DP
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI PeiServicesGetBootMode(OUT EFI_BOOT_MODE *BootMode)
EFI_STATUS EFIAPI PeiServicesNotifyPpi(IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
#define DEBUG(Expression)
@ EfiPciIoAttributeOperationEnable
@ EfiPciIoAttributeOperationSupported
EFI_STATUS EFIAPI NvmeStorageSecuritySendData(IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This, IN UINT32 MediaId, IN UINT64 Timeout, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN PayloadBufferSize, IN VOID *PayloadBuffer)
EFI_STATUS EFIAPI NvmeStorageSecurityReceiveData(IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This, IN UINT32 MediaId, IN UINT64 Timeout, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN PayloadBufferSize, OUT VOID *PayloadBuffer, OUT UINTN *PayloadTransferSize)
EFI_STATUS NvmeIdentifyNamespace(IN NVME_CONTROLLER_PRIVATE_DATA *Private, IN UINT32 NamespaceId, IN VOID *Buffer)
EFI_STATUS NvmeControllerInit(IN NVME_CONTROLLER_PRIVATE_DATA *Private)
EFI_STATUS NvmeDiscoverNamespaces(IN OUT PEI_NVME_CONTROLLER_PRIVATE_DATA *Private)
EFI_STATUS NvmeInitControllerFromHostControllerPpi(IN EDKII_NVM_EXPRESS_HOST_CONTROLLER_PPI *NvmeHcPpi)
EFI_STATUS EFIAPI NvmePeimEndOfPei(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS EFIAPI NvmExpressPeimEntry(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS EFIAPI NvmePciDevicePpiInstallationCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS NvmeInitControllerDataFromPciDevice(EDKII_PCI_DEVICE_PPI *PciDevice)
EFI_STATUS EnumerateNvmeDevNamespace(IN OUT PEI_NVME_CONTROLLER_PRIVATE_DATA *Private, IN UINT32 NamespaceId)
EFI_STATUS EFIAPI NvmeHostControllerPpiInstallationCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS NvmeInitPrivateData(IN UINTN MmioBase, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINTN DevicePathLength)
BOOLEAN NvmeS3SkipThisController(IN EFI_DEVICE_PATH_PROTOCOL *HcDevicePath, IN UINTN HcDevicePathLength)
#define IS_PCI_NVMHCI(_p)
EFI_STATUS EFIAPI NvmeBlockIoPeimReadBlocks(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 EFIAPI NvmeBlockIoPeimGetMediaInfo(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 EFIAPI NvmeBlockIoPeimGetMediaInfo2(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 EFIAPI NvmeBlockIoPeimReadBlocks2(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 EFIAPI NvmeBlockIoPeimGetDeviceNo(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, OUT UINTN *NumberBlockDevices)
EFI_STATUS EFIAPI NvmeBlockIoPeimGetDeviceNo2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, OUT UINTN *NumberBlockDevices)
VOID NvmeFreeDmaResource(IN PEI_NVME_CONTROLLER_PRIVATE_DATA *Private)
EFI_STATUS EFIAPI NvmePassThruGetDevicePath(IN EDKII_PEI_NVM_EXPRESS_PASS_THRU_PPI *This, OUT UINTN *DevicePathLength, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
EFI_STATUS EFIAPI NvmePassThruGetNextNameSpace(IN EDKII_PEI_NVM_EXPRESS_PASS_THRU_PPI *This, IN OUT UINT32 *NamespaceId)
EFI_STATUS EFIAPI NvmePassThru(IN EDKII_PEI_NVM_EXPRESS_PASS_THRU_PPI *This, IN UINT32 NamespaceId, IN OUT EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *Packet)
EFI_STATUS EFIAPI NvmeStorageSecurityGetDeviceNo(IN EDKII_PEI_STORAGE_SECURITY_CMD_PPI *This, OUT UINTN *NumberofDevices)
EFI_STATUS EFIAPI NvmeStorageSecurityGetDevicePath(IN EDKII_PEI_STORAGE_SECURITY_CMD_PPI *This, IN UINTN DeviceIndex, OUT UINTN *DevicePathLength, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
VOID * EFI_PEI_FILE_HANDLE
VOID EFIAPI Exit(IN EFI_STATUS Status)
UINT64 EFI_PHYSICAL_ADDRESS
EFI_PEI_READ_BLOCKS2 ReadBlocks
EFI_PEI_GET_DEVICE_MEDIA_INFORMATION2 GetBlockDeviceMediaInfo
EFI_PEI_GET_NUMBER_BLOCK_DEVICES2 GetNumberOfBlockDevices
EFI_PEI_READ_BLOCKS ReadBlocks
EFI_PEI_GET_NUMBER_BLOCK_DEVICES GetNumberOfBlockDevices
EFI_PEI_GET_DEVICE_MEDIA_INFORMATION GetBlockDeviceMediaInfo