14 RAM_DISK_PRIVATE_DATA_SIGNATURE,
29BOOLEAN mRamDiskSsdtTableKeyValid =
FALSE;
30UINTN mRamDiskSsdtTableKey;
46 (UINT64 *)&(RamDiskDevNode->StartingAddr[0]),
47 (UINT64)PrivateData->StartingAddr
50 (UINT64 *)&(RamDiskDevNode->EndingAddr[0]),
51 (UINT64)PrivateData->StartingAddr + PrivateData->Size - 1
53 CopyGuid (&RamDiskDevNode->TypeGuid, &PrivateData->TypeGuid);
54 RamDiskDevNode->Instance = PrivateData->InstanceNumber;
71 UINTN SectionInstance;
89 if (EFI_ERROR (Status)) {
93 if (Table->OemTableId ==
SIGNATURE_64 (
'R',
'a',
'm',
'D',
'i',
's',
'k',
' ')) {
94 Status = mAcpiTableProtocol->InstallAcpiTable (
102 if (!EFI_ERROR (Status)) {
103 mRamDiskSsdtTableKeyValid =
TRUE;
138 EFI_ACPI_TABLE_VERSION TableVersion;
147 UINTN DescriptorSize;
148 UINT32 DescriptorVersion;
160 Status =
gBS->GetMemoryMap (
167 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
170 ASSERT (MemoryMap !=
NULL);
171 Status =
gBS->GetMemoryMap (
178 if (EFI_ERROR (Status)) {
181 }
while (Status == EFI_BUFFER_TOO_SMALL);
185 MemoryMapEntry = MemoryMap;
187 while ((
UINTN)MemoryMapEntry < (
UINTN)MemoryMapEnd) {
189 (MemoryMapEntry->
PhysicalStart <= PrivateData->StartingAddr) &&
192 >= PrivateData->StartingAddr + PrivateData->Size))
197 "RamDiskPublishNfit: RAM disk with reserved memory type, will publish to NFIT.\n"
202 MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
208 return EFI_NOT_FOUND;
219 while (!EFI_ERROR (Status)) {
220 Status = mAcpiSdtProtocol->GetAcpiTable (
226 if (!EFI_ERROR (Status)) {
237 if (!EFI_ERROR (Status)) {
243 "RamDiskPublishNfit: A NFIT is already exist in the ACPI Table.\n"
250 return EFI_OUT_OF_RESOURCES;
253 CopyMem (Nfit, TableHeader, NfitHeader->Length);
263 Status = mAcpiTableProtocol->UninstallAcpiTable (
269 if (EFI_ERROR (Status)) {
279 ((UINT8 *)Nfit + NfitHeader->Length);
284 NfitHeader->Length = NfitLen;
289 NfitHeader->Checksum = 0;
298 if (EFI_ERROR (Status)) {
307 "RamDiskPublishNfit: No NFIT is in the ACPI Table, will create one.\n"
314 return EFI_OUT_OF_RESOURCES;
322 NfitHeader->Length = NfitLen;
323 NfitHeader->Revision = EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE_REVISION;
324 NfitHeader->Checksum = 0;
325 NfitHeader->OemRevision =
PcdGet32 (PcdAcpiDefaultOemRevision);
326 NfitHeader->CreatorId =
PcdGet32 (PcdAcpiDefaultCreatorId);
327 NfitHeader->CreatorRevision =
PcdGet32 (PcdAcpiDefaultCreatorRevision);
328 CurrentData =
PcdGet64 (PcdAcpiDefaultOemTableId);
329 CopyMem (NfitHeader->OemId,
PcdGetPtr (PcdAcpiDefaultOemId),
sizeof (NfitHeader->OemId));
330 CopyMem (&NfitHeader->OemTableId, &CurrentData, sizeof (UINT64));
336 SpaRange->Type = EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE_TYPE;
338 SpaRange->SystemPhysicalAddressRangeBase = PrivateData->StartingAddr;
339 SpaRange->SystemPhysicalAddressRangeLength = PrivateData->Size;
340 CopyGuid (&SpaRange->AddressRangeTypeGUID, &PrivateData->TypeGuid);
343 NfitHeader->Checksum = Checksum;
350 Status = mAcpiTableProtocol->InstallAcpiTable (
360 if (EFI_ERROR (Status)) {
364 PrivateData->InNfit =
TRUE;
387 EFI_ACPI_TABLE_VERSION TableVersion;
407 while (!EFI_ERROR (Status)) {
408 Status = mAcpiSdtProtocol->GetAcpiTable (
414 if (!EFI_ERROR (Status)) {
425 if (EFI_ERROR (Status)) {
429 return EFI_NOT_FOUND;
444 Status = mAcpiTableProtocol->UninstallAcpiTable (
449 if (EFI_ERROR (Status)) {
460 if (mRamDiskSsdtTableKeyValid) {
461 mRamDiskSsdtTableKeyValid =
FALSE;
463 mAcpiTableProtocol->UninstallAcpiTable (
473 if (NewNfit ==
NULL) {
474 return EFI_OUT_OF_RESOURCES;
482 NewNfitHeader->Length = NewNfitLen;
483 NewNfitHeader->Checksum = 0;
492 while (RemainLen > 0) {
493 if ((NfitStructHeader->Type == EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE_TYPE) &&
498 if ((SpaRange->SystemPhysicalAddressRangeBase == PrivateData->StartingAddr) &&
499 (SpaRange->SystemPhysicalAddressRangeLength == PrivateData->Size) &&
500 (
CompareGuid (&SpaRange->AddressRangeTypeGUID, &PrivateData->TypeGuid)))
507 ((UINT8 *)NfitStructHeader + NfitStructHeader->Length);
515 CopyMem (NewNfitPtr, NfitStructHeader, NfitStructHeader->Length);
516 NewNfitPtr = (UINT8 *)NewNfitPtr + NfitStructHeader->Length;
521 RemainLen -= NfitStructHeader->Length;
523 ((UINT8 *)NfitStructHeader + NfitStructHeader->Length);
527 NewNfitHeader->Checksum = Checksum;
529 Status = mAcpiTableProtocol->UninstallAcpiTable (
535 if (EFI_ERROR (Status)) {
545 Status = mAcpiTableProtocol->InstallAcpiTable (
554 if (EFI_ERROR (Status)) {
594 IN UINT64 RamDiskBase,
595 IN UINT64 RamDiskSize,
605 UINTN DevicePathSize;
608 if ((0 == RamDiskSize) || (
NULL == RamDiskType) || (
NULL == DevicePath)) {
609 return EFI_INVALID_PARAMETER;
615 if ((RamDiskSize > MAX_UINTN) ||
616 (RamDiskBase > MAX_UINTN - RamDiskSize + 1))
618 return EFI_INVALID_PARAMETER;
621 RamDiskDevNode =
NULL;
628 &mRamDiskPrivateDataTemplate
630 if (
NULL == PrivateData) {
631 return EFI_OUT_OF_RESOURCES;
634 PrivateData->StartingAddr = RamDiskBase;
635 PrivateData->Size = RamDiskSize;
636 CopyGuid (&PrivateData->TypeGuid, RamDiskType);
644 &mRamDiskDeviceNodeTemplate
646 if (
NULL == RamDiskDevNode) {
647 Status = EFI_OUT_OF_RESOURCES;
657 if (
NULL == *DevicePath) {
658 Status = EFI_OUT_OF_RESOURCES;
662 PrivateData->DevicePath = *DevicePath;
672 RegisteredPrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
678 PrivateData->DevicePath,
679 RegisteredPrivateData->DevicePath,
684 Status = EFI_ALREADY_STARTED;
700 Status =
gBS->InstallMultipleProtocolInterfaces (
701 &PrivateData->Handle,
702 &gEfiBlockIoProtocolGuid,
703 &PrivateData->BlockIo,
704 &gEfiBlockIo2ProtocolGuid,
705 &PrivateData->BlockIo2,
706 &gEfiDevicePathProtocolGuid,
707 PrivateData->DevicePath,
710 if (EFI_ERROR (Status)) {
723 if ((mAcpiTableProtocol !=
NULL) && (mAcpiSdtProtocol !=
NULL)) {
730 if (RamDiskDevNode !=
NULL) {
734 if (PrivateData !=
NULL) {
735 if (PrivateData->DevicePath) {
775 if (
NULL == DevicePath) {
776 return EFI_INVALID_PARAMETER;
782 RamDiskDevNode =
NULL;
788 if ((MEDIA_DEVICE_PATH == Header->Type) &&
797 }
while ((Header->Type != END_DEVICE_PATH_TYPE));
799 if (
NULL == RamDiskDevNode) {
800 return EFI_UNSUPPORTED;
809 PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
815 if ((StartingAddr == PrivateData->StartingAddr) &&
816 (EndingAddr == PrivateData->StartingAddr + PrivateData->Size - 1) &&
822 if (PrivateData->InNfit) {
829 gBS->UninstallMultipleProtocolInterfaces (
831 &gEfiBlockIoProtocolGuid,
832 &PrivateData->BlockIo,
833 &gEfiBlockIo2ProtocolGuid,
834 &PrivateData->BlockIo2,
835 &gEfiDevicePathProtocolGuid,
842 if (RamDiskCreateHii == PrivateData->CreateMethod) {
863 return EFI_NOT_FOUND;
#define EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE_STRUCTURE_SIGNATURE
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
UINT64 EFIAPI ReadUnaligned64(IN CONST UINT64 *Buffer)
#define BASE_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead)
UINT8 EFIAPI CalculateCheckSum8(IN CONST UINT8 *Buffer, IN UINTN Length)
#define BASE_LIST_FOR_EACH(Entry, ListHead)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
UINT64 EFIAPI WriteUnaligned64(OUT UINT64 *Buffer, IN UINT64 Value)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
#define MEDIA_RAM_DISK_DP
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathNode(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI NextDevicePathNode(IN CONST VOID *Node)
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
EFI_STATUS EFIAPI GetSectionFromFv(IN CONST EFI_GUID *NameGuid, IN EFI_SECTION_TYPE SectionType, IN UINTN SectionInstance, OUT VOID **Buffer, OUT UINTN *Size)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define SIGNATURE_64(A, B, C, D, E, F, G, H)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGet64(TokenName)
#define PcdGet32(TokenName)
#define PcdGetPtr(TokenName)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID RamDiskInitBlockIo(IN RAM_DISK_PRIVATE_DATA *PrivateData)
EFI_STATUS RamDiskPublishSsdt(VOID)
EFI_STATUS RamDiskUnpublishNfit(IN RAM_DISK_PRIVATE_DATA *PrivateData)
EFI_STATUS RamDiskPublishNfit(IN RAM_DISK_PRIVATE_DATA *PrivateData)
EFI_STATUS EFIAPI RamDiskRegister(IN UINT64 RamDiskBase, IN UINT64 RamDiskSize, IN EFI_GUID *RamDiskType, IN EFI_DEVICE_PATH *ParentDevicePath OPTIONAL, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
EFI_STATUS EFIAPI RamDiskUnregister(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
VOID RamDiskInitDeviceNode(IN RAM_DISK_PRIVATE_DATA *PrivateData, IN OUT MEDIA_RAM_DISK_DEVICE_PATH *RamDiskDevNode)
EFI_PHYSICAL_ADDRESS PhysicalStart