Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMD memory map fixes #189

Open
wants to merge 2 commits into
base: dasharo
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions DasharoPayloadPkg/Include/Coreboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,14 @@ struct cb_memory_range {
UINT32 type;
};

#define CB_MEM_RAM 1
#define CB_MEM_RESERVED 2
#define CB_MEM_ACPI 3
#define CB_MEM_NVS 4
#define CB_MEM_UNUSABLE 5
#define CB_MEM_VENDOR_RSVD 6
#define CB_MEM_TABLE 16
#define CB_MEM_RAM 1
#define CB_MEM_RESERVED 2
#define CB_MEM_ACPI 3
#define CB_MEM_NVS 4
#define CB_MEM_UNUSABLE 5
#define CB_MEM_VENDOR_RSVD 6
#define CB_MEM_TABLE 16
#define CB_MEM_SOFT_RESERVED 0xefffffff

struct cb_memory {
UINT32 tag;
Expand Down
47 changes: 38 additions & 9 deletions DasharoPayloadPkg/Library/CbParseLib/CbParseLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ ParseCbMemTable (
return Status;
}


#define MSR_TOP_MEM 0xC001001A
#define MSR_TOM2 0xC001001D
#define TOLUD 0xBC
#define TOUUD 0xA8

/**
Acquire the memory information from the coreboot table in memory.
Expand All @@ -385,9 +388,20 @@ ParseMemoryInfo (
struct cb_memory_range *Range;
UINTN Index;
MEMROY_MAP_ENTRY MemoryMap;
UINT32 Tolud;

Tolud = PciRead32(PCI_LIB_ADDRESS(0,0,0,0xbc)) & 0xFFF00000;
UINT64 Tolud;
UINT64 Touud;

Tolud = 0;
Touud = 0;

if (PciRead16(PCI_LIB_ADDRESS(0, 0, 0, 0x00)) == 0x8086) /* Intel */ {
Tolud = PciRead32(PCI_LIB_ADDRESS(0, 0, 0, TOLUD)) & 0xFFF00000;
Touud = PciRead32(PCI_LIB_ADDRESS(0, 0, 0, TOUUD)) & 0xFFF00000;
Touud |= RShiftU64(PciRead32(PCI_LIB_ADDRESS(0, 0, 0, TOUUD + 4)), 32);
} else if (PciRead16(PCI_LIB_ADDRESS(0, 0, 0, 0x00)) == 0x1022) /* AMD */ {
Tolud = AsmReadMsr64(MSR_TOP_MEM);
Touud = AsmReadMsr64(MSR_TOM2);
}

//
// Get the coreboot memory table
Expand All @@ -411,13 +425,27 @@ ParseMemoryInfo (
/* Only MMIO is marked reserved */
case CB_MEM_RESERVED:
/*
* Reserved memory Below TOLUD can't be MMIO except legacy VGA which
* is reported elsewhere as reserved.
* Reserved memory Below TOLUD/TOUUD can't be MMIO except legacy VGA
* which is reported elsewhere as reserved.
*/
if (MemoryMap.Base < Tolud) {
MemoryMap.Type = EFI_RESOURCE_MEMORY_RESERVED;
MemoryMap.Flag = EFI_RESOURCE_ATTRIBUTE_PRESENT;
if (MemoryMap.Base >= BASE_4GB && Touud != 0) {
if (MemoryMap.Base < Touud) {
MemoryMap.Type = EFI_RESOURCE_MEMORY_RESERVED;
MemoryMap.Flag = EFI_RESOURCE_ATTRIBUTE_PRESENT;
} else {
MemoryMap.Type = EFI_RESOURCE_MEMORY_MAPPED_IO;
MemoryMap.Flag = EFI_RESOURCE_ATTRIBUTE_PRESENT;
}
} else if (MemoryMap.Base < BASE_4GB && Tolud != 0) {
if (MemoryMap.Base < Tolud) {
MemoryMap.Type = EFI_RESOURCE_MEMORY_RESERVED;
MemoryMap.Flag = EFI_RESOURCE_ATTRIBUTE_PRESENT;
} else {
MemoryMap.Type = EFI_RESOURCE_MEMORY_MAPPED_IO;
MemoryMap.Flag = EFI_RESOURCE_ATTRIBUTE_PRESENT;
}
} else {
/* Fallback, if not Intel/AMD or TOLUD/TOUUD is zero, treat everything as MMIO */
MemoryMap.Type = EFI_RESOURCE_MEMORY_MAPPED_IO;
MemoryMap.Flag = EFI_RESOURCE_ATTRIBUTE_PRESENT;
}
Expand All @@ -433,6 +461,7 @@ ParseMemoryInfo (
/* ACPI/SMBIOS/CBMEM has it's own tag */
case CB_MEM_ACPI:
case CB_MEM_TABLE:
case CB_MEM_SOFT_RESERVED:
MemoryMap.Type = EFI_RESOURCE_MEMORY_RESERVED;
MemoryMap.Flag = EFI_RESOURCE_ATTRIBUTE_PRESENT;
break;
Expand Down
Loading