[edk2-devel] [PATCH edk2-platforms v6 6/7] Platform/SbsaQemu: get the information of memory via SMC calls
From: Xiong Yining Provide functions to check for memory information: - amount of memory nodes - memory address - NUMA node id for memory Values are read from TF-A using platform specific SMC calls. Signed-off-by: Xiong Yining Signed-off-by: Chen Baozi --- .../SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf | 2 +- .../SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h | 2 + .../Include/Library/SbsaQemuHardwareInfoLib.h| 28 ++ .../SbsaQemuHardwareInfoLib.c| 47 + .../Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuMem.c | 54 +--- 5 files changed, 91 insertions(+), 42 deletions(-) diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf index c067a80cc715..fb856efe4c27 100644 --- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf +++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf @@ -32,9 +32,9 @@ [LibraryClasses] ArmLib BaseMemoryLib DebugLib - FdtLib MemoryAllocationLib PcdLib + SbsaQemuHardwareInfoLib [Pcd] gArmTokenSpaceGuid.PcdSystemMemoryBase diff --git a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h index d9faee7fa5b2..e7bf54978d4e 100644 --- a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h +++ b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h @@ -16,6 +16,8 @@ #define SIP_SVC_GET_GIC_ITSSMC_SIP_FUNCTION_ID(101) #define SIP_SVC_GET_CPU_COUNT SMC_SIP_FUNCTION_ID(200) #define SIP_SVC_GET_CPU_NODE SMC_SIP_FUNCTION_ID(201) +#define SIP_SVC_GET_MEMORY_NODE_COUNT SMC_SIP_FUNCTION_ID(300) +#define SIP_SVC_GET_MEMORY_NODE SMC_SIP_FUNCTION_ID(301) /* * SMCC does not define return codes for SiP functions. diff --git a/Silicon/Qemu/SbsaQemu/Include/Library/SbsaQemuHardwareInfoLib.h b/Silicon/Qemu/SbsaQemu/Include/Library/SbsaQemuHardwareInfoLib.h index ca52c6b27093..0b71a3f7e6eb 100644 --- a/Silicon/Qemu/SbsaQemu/Include/Library/SbsaQemuHardwareInfoLib.h +++ b/Silicon/Qemu/SbsaQemu/Include/Library/SbsaQemuHardwareInfoLib.h @@ -9,6 +9,12 @@ #ifndef SBSA_QEMU_HARDWARE_INFO_ #define SBSA_QEMU_HARDWARE_INFO_ +typedef struct{ + UINT32 NodeId; + UINT64 AddressBase; + UINT64 AddressSize; +} MemoryInfo; + /** Get CPU count from information passed by Qemu. @@ -42,4 +48,26 @@ SbsaQemuGetCpuNumaNode ( IN UINTN CpuId ); +/** + Get the number of memory node from device tree passed by Qemu. + + @retval the number of memory nodes. +**/ +UINT32 +SbsaQemuGetMemNodeCount ( + VOID + ); + +/** + Get memory infomation(node-id, addressbase, addresssize) for a given memory node from device tree passed by Qemu. + + @param [in] MemoryIdIndex of memory to retrieve memory information. + + @retval memory infomation for given memory node. +**/ +MemoryInfo +SbsaQemuGetMemInfo ( + IN UINTN MemoryId + ); + #endif /* SBSA_QEMU_HARDWARE_INFO_ */ diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c index e1f1a9588b19..88b50e46c072 100644 --- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c +++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c @@ -201,3 +201,50 @@ SbsaQemuGetCpuNumaNode ( return Arg0; } + +UINT32 +SbsaQemuGetMemNodeCount ( + VOID + ) +{ + UINTNSmcResult; + UINTNArg0; + + SmcResult = ArmCallSmc0 (SIP_SVC_GET_MEMORY_NODE_COUNT, &Arg0, NULL, NULL); + if (SmcResult != SMC_SIP_CALL_SUCCESS) { +DEBUG ((DEBUG_ERROR, "SIP_SVC_GET_MEMORY_NODE_COUNT call failed.\n")); + } + + DEBUG(( DEBUG_INFO, "The number of the memory nodes is %ld\n", Arg0)); + return (UINT32)Arg0; +} + +MemoryInfo +SbsaQemuGetMemInfo ( + IN UINTN MemoryId + ) +{ + UINTN SmcResult; + UINTN Arg0; + UINTN Arg1; + UINTN Arg2; + MemoryInfo MemInfo; + + Arg0 = MemoryId; + + SmcResult = ArmCallSmc1 (SIP_SVC_GET_MEMORY_NODE, &Arg0, &Arg1, &Arg2); + if (SmcResult != SMC_SIP_CALL_SUCCESS) { +DEBUG ((DEBUG_ERROR, "SIP_SVC_GET_MEMORY_NODE call failed.\n")); + } else { +MemInfo.NodeId = Arg0; +MemInfo.AddressBase = Arg1; +MemInfo.AddressSize = Arg2; + } + + DEBUG(( DEBUG_INFO, "NUMA node for System RAM:%d = 0x%lx - 0x%lx\n", + MemInfo.NodeId, + MemInfo.AddressBase, + MemInfo.AddressBase + MemInfo.AddressSize -1 )); + + return MemInfo; +} diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuMem.c b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuMem.c index 8c2eb0b6a028..5a418a461174 100644 --- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuMem.c +++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuMem.c @@ -12,7 +12,7 @@ #include #include #
Re: [edk2-devel] [PATCH edk2-platforms v6 6/7] Platform/SbsaQemu: get the information of memory via SMC calls
On Wed, 6 Mar 2024 at 12:42, Marcin Juszkiewicz wrote: > > From: Xiong Yining > > Provide functions to check for memory information: > > - amount of memory nodes > - memory address > - NUMA node id for memory > > Values are read from TF-A using platform specific SMC calls. > > Signed-off-by: Xiong Yining > Signed-off-by: Chen Baozi > --- > .../SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf | 2 +- > .../SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h | 2 + > .../Include/Library/SbsaQemuHardwareInfoLib.h| 28 ++ > .../SbsaQemuHardwareInfoLib.c| 47 + > .../Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuMem.c | 54 > +--- > 5 files changed, 91 insertions(+), 42 deletions(-) > > diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf > b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf > index c067a80cc715..fb856efe4c27 100644 > --- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf > +++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf > @@ -32,9 +32,9 @@ [LibraryClasses] >ArmLib >BaseMemoryLib >DebugLib > - FdtLib >MemoryAllocationLib >PcdLib > + SbsaQemuHardwareInfoLib > > [Pcd] >gArmTokenSpaceGuid.PcdSystemMemoryBase > diff --git a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h > b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h > index d9faee7fa5b2..e7bf54978d4e 100644 > --- a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h > +++ b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h > @@ -16,6 +16,8 @@ > #define SIP_SVC_GET_GIC_ITSSMC_SIP_FUNCTION_ID(101) > #define SIP_SVC_GET_CPU_COUNT SMC_SIP_FUNCTION_ID(200) > #define SIP_SVC_GET_CPU_NODE SMC_SIP_FUNCTION_ID(201) > +#define SIP_SVC_GET_MEMORY_NODE_COUNT SMC_SIP_FUNCTION_ID(300) > +#define SIP_SVC_GET_MEMORY_NODE SMC_SIP_FUNCTION_ID(301) > > /* > * SMCC does not define return codes for SiP functions. > diff --git a/Silicon/Qemu/SbsaQemu/Include/Library/SbsaQemuHardwareInfoLib.h > b/Silicon/Qemu/SbsaQemu/Include/Library/SbsaQemuHardwareInfoLib.h > index ca52c6b27093..0b71a3f7e6eb 100644 > --- a/Silicon/Qemu/SbsaQemu/Include/Library/SbsaQemuHardwareInfoLib.h > +++ b/Silicon/Qemu/SbsaQemu/Include/Library/SbsaQemuHardwareInfoLib.h > @@ -9,6 +9,12 @@ > #ifndef SBSA_QEMU_HARDWARE_INFO_ > #define SBSA_QEMU_HARDWARE_INFO_ > > +typedef struct{ > + UINT32 NodeId; > + UINT64 AddressBase; > + UINT64 AddressSize; > +} MemoryInfo; > + > /** >Get CPU count from information passed by Qemu. > > @@ -42,4 +48,26 @@ SbsaQemuGetCpuNumaNode ( >IN UINTN CpuId >); > > +/** > + Get the number of memory node from device tree passed by Qemu. > + > + @retval the number of memory nodes. > +**/ > +UINT32 > +SbsaQemuGetMemNodeCount ( > + VOID > + ); > + > +/** > + Get memory infomation(node-id, addressbase, addresssize) for a given > memory node from device tree passed by Qemu. > + > + @param [in] MemoryIdIndex of memory to retrieve memory information. > + > + @retval memory infomation for given memory node. > +**/ > +MemoryInfo Let's avoid aggregates as return types. Pass/return by reference instead using an OUT pointer. > +SbsaQemuGetMemInfo ( > + IN UINTN MemoryId > + ); > + > #endif /* SBSA_QEMU_HARDWARE_INFO_ */ > diff --git > a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c > > b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c > index e1f1a9588b19..88b50e46c072 100644 > --- > a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c > +++ > b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c > @@ -201,3 +201,50 @@ SbsaQemuGetCpuNumaNode ( > >return Arg0; > } > + > +UINT32 > +SbsaQemuGetMemNodeCount ( > + VOID > + ) > +{ > + UINTNSmcResult; > + UINTNArg0; > + > + SmcResult = ArmCallSmc0 (SIP_SVC_GET_MEMORY_NODE_COUNT, &Arg0, NULL, NULL); > + if (SmcResult != SMC_SIP_CALL_SUCCESS) { > +DEBUG ((DEBUG_ERROR, "SIP_SVC_GET_MEMORY_NODE_COUNT call failed.\n")); > + } > + > + DEBUG(( DEBUG_INFO, "The number of the memory nodes is %ld\n", Arg0)); > + return (UINT32)Arg0; > +} > + > +MemoryInfo > +SbsaQemuGetMemInfo ( > + IN UINTN MemoryId > + ) > +{ > + UINTN SmcResult; > + UINTN Arg0; > + UINTN Arg1; > + UINTN Arg2; > + MemoryInfo MemInfo; > + > + Arg0 = MemoryId; > + > + SmcResult = ArmCallSmc1 (SIP_SVC_GET_MEMORY_NODE, &Arg0, &Arg1, &Arg2); > + if (SmcResult != SMC_SIP_CALL_SUCCESS) { > +DEBUG ((DEBUG_ERROR, "SIP_SVC_GET_MEMORY_NODE call failed.\n")); > + } else { > +MemInfo.NodeId = Arg0; > +MemInfo.AddressBase = Arg1; > +MemInfo.AddressSize = Arg2; > + } > + > + DEBUG(( DEBUG_INFO, "NUMA node for System RAM:%d = 0x%lx - 0x%lx\n", > + MemInfo.NodeId