We submit a patch(d56b488) in TF-A which is armed at reporting the information of memory through SMC. Cooperating with that patch, we can get the information of memory in EDK2 via SMC calls.
Xiong Yining (1): SbsaQemu: get the information of memory form TF-A
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(-)
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
W dniu 7.12.2023 o 11:28, Xiong Yining pisze:
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
Nice work on both parts.
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
Please drop this part of change.
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
Please add space after comment marker.
- 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));
- }
Here should be code for situation when EDK2 is paired with older TF-A. Otherwise you get this:
InitializeSbsaQemuPlatformDxe: InitializeSbsaQemuPlatformDxe called InitializeSbsaQemuPlatformDxe: Got platform AHCI 60100000 65536 InstallProtocolInterface: 0D51905B-B77E-452A-A2C0-ECA0CC8D514A 100BAD65918 InstallProtocolInterface: 09576E91-6D3F-11D2-8E39-00A0C969723B 100BAD65118 INFO: Platform version requested Platform version: 0.3 GICD base: 0x40060000 GICR base: 0x40080000 GICI base: 0x44081000 InitializeSbsaQemuPlatformDxe: Got platform XHCI 60110000 65536 InstallProtocolInterface: 0D51905B-B77E-452A-A2C0-ECA0CC8D514A 100BAD65198 InstallProtocolInterface: 09576E91-6D3F-11D2-8E39-00A0C969723B 100BAD65498 ERROR: sbsa_sip_smc_handler: unhandled SMC (0xc200012d) (function id: 301) ERROR: sbsa_sip_smc_handler: unhandled SMC (0xc200012c) (function id: 300) ERROR: sbsa_sip_smc_handler: unhandled SMC (0xc200012c) (function id: 300) ERROR: sbsa_sip_smc_handler: unhandled SMC (0xc200012c) (function id: 300)
[and it goes on and on]
- 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",
Typo - should be "System RAM".
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
W dniu 7.12.2023 o 11:28, Xiong Yining pisze:
We submit a patch(d56b488) in TF-A which is armed at reporting the information of memory through SMC. Cooperating with that patch, we can get the information of memory in EDK2 via SMC calls.
Xiong Yining (1): SbsaQemu: get the information of memory form TF-A
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(-)
Please take a look at code present in Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuMem.c file.
We read DT to get memory information there. This needs to be replaced with use of SMC calls.