We can get the information of memory via SMC calls.
Signed-off-by: Xiong Yining xiongyining1480@phytium.com.cn Signed-off-by: Chen Baozi chenbaozi@phytium.com.cn --- Platform/Qemu/SbsaQemu/SbsaQemu.dsc | 5 +++- .../SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.c | 29 +++++++++++++++++++ .../SbsaQemuPlatformDxe.inf | 1 + .../SbsaQemuPlatformVersion.h | 14 +++++++++ .../Include/IndustryStandard/SbsaQemuSmc.h | 2 ++ Silicon/Qemu/SbsaQemu/SbsaQemu.dec | 2 ++ 6 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc index 378600050d..e1c4e1aa9b 100644 --- a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc +++ b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc @@ -78,7 +78,7 @@ DEFINE NETWORK_HTTP_BOOT_ENABLE = FALSE SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf - ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf @@ -520,6 +520,9 @@ DEFINE NETWORK_HTTP_BOOT_ENABLE = FALSE # TODO as no DT will be used we should pass this by some other method gArmTokenSpaceGuid.PcdSystemMemorySize|0x08000000
+ #Memory Information + gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdBaseMemoryInfoLocation|0 + # # ARM General Interrupt Controller # diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.c b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.c index 4ebbe7c93a..6fb9282899 100644 --- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.c +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.c @@ -16,6 +16,7 @@ #include <Library/UefiDriverEntryPoint.h> #include <IndustryStandard/SbsaQemuSmc.h> #include <IndustryStandard/SbsaQemuPlatformVersion.h> +#include <Library/MemoryAllocationLib.h>
#include <Protocol/FdtClient.h>
@@ -31,6 +32,7 @@ InitializeSbsaQemuPlatformDxe ( VOID* Base; UINTN Arg0; UINTN Arg1; + UINTN Arg2; UINTN SmcResult; RETURN_STATUS Result;
@@ -123,5 +125,32 @@ InitializeSbsaQemuPlatformDxe ( } }
+ MemoryInfo *MemoryPtr; + UINTN MemPages, index; + + MemPages = EFI_SIZE_TO_PAGES(sizeof(MemoryInfo)); + MemoryPtr = AllocatePages (MemPages); + PcdSet64S (PcdBaseMemoryInfoLocation, (UINTN)MemoryPtr); + + SmcResult = ArmCallSmc0 (SIP_SVC_GET_MEMORYNODE_COUNT, &Arg0, NULL, NULL); + if (SmcResult == SMC_ARCH_CALL_SUCCESS) { + MemoryPtr->NumMemNode = Arg0; + DEBUG((DEBUG_INFO, "The Number of Memory Node is %ld\n", MemoryPtr->NumMemNode)); + } + + for(index = 0; index < MemoryPtr->NumMemNode; index ++){ + Arg0 = index; + SmcResult = ArmCallSmc1 (SIP_SVC_GET_MEMORY, &Arg0, &Arg1, &Arg2); + if (SmcResult == SMC_ARCH_CALL_SUCCESS) { + MemoryPtr->MemNode[index].NodeId = Arg0; + MemoryPtr->MemNode[index].AddressBase = Arg1; + MemoryPtr->MemNode[index].AddressSize = Arg2; + DEBUG(( DEBUG_INFO, "Sysyem RAM@%d: 0x%lx - 0x%lx\n", + MemoryPtr->MemNode[index].NodeId, + MemoryPtr->MemNode[index].AddressBase, + MemoryPtr->MemNode[index].AddressBase + MemoryPtr->MemNode[index].AddressSize)); + } + } + return EFI_SUCCESS; } diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.inf b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.inf index 19534b7a27..3333e6fa59 100644 --- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.inf +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.inf @@ -42,6 +42,7 @@
gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdPlatformVersionMajor gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdPlatformVersionMinor + gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdBaseMemoryInfoLocation
gArmTokenSpaceGuid.PcdGicDistributorBase gArmTokenSpaceGuid.PcdGicRedistributorsBase diff --git a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuPlatformVersion.h b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuPlatformVersion.h index d342f8f363..e4aa33dd3a 100644 --- a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuPlatformVersion.h +++ b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuPlatformVersion.h @@ -22,4 +22,18 @@ ) \ ) \ ) + +#define MAXNODE 128 + +typedef struct{ + UINT32 NodeId; + UINT64 AddressBase; + UINT64 AddressSize; +} Memorynode; + +typedef struct{ + UINT32 NumMemNode; + Memorynode MemNode[MAXNODE]; +} MemoryInfo; + #endif diff --git a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h index 7934875e4a..50a9cfdb0b 100644 --- a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h +++ b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h @@ -14,5 +14,7 @@ #define SIP_SVC_VERSION SMC_SIP_FUNCTION_ID(1) #define SIP_SVC_GET_GIC SMC_SIP_FUNCTION_ID(100) #define SIP_SVC_GET_GIC_ITS SMC_SIP_FUNCTION_ID(101) +#define SIP_SVC_GET_MEMORY SMC_SIP_FUNCTION_ID(300) +#define SIP_SVC_GET_MEMORYNODE_COUNT SMC_SIP_FUNCTION_ID(301)
#endif /* SBSA_QEMU_SMC_H_ */ diff --git a/Silicon/Qemu/SbsaQemu/SbsaQemu.dec b/Silicon/Qemu/SbsaQemu/SbsaQemu.dec index 913d1d75ef..668e8aa5d7 100644 --- a/Silicon/Qemu/SbsaQemu/SbsaQemu.dec +++ b/Silicon/Qemu/SbsaQemu/SbsaQemu.dec @@ -74,3 +74,5 @@ # ARM Generic Interrupt Controller ITS gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdGicItsBase|0|UINT64|0x00000120 gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdSmmuBase|0|UINT64|0x00000121 + + gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdBaseMemoryInfoLocation|0|UINT64|0x00000122