* [edk2-devel] [PATCH] Platform/Loongson: Remove minimium memory size limitation
@ 2024-03-25 9:25 xianglai
2024-03-26 1:10 ` maobibo
0 siblings, 1 reply; 3+ messages in thread
From: xianglai @ 2024-03-25 9:25 UTC (permalink / raw)
To: devel; +Cc: Bibo Mao, Chao Li
From: Bibo Mao <maobibo@loongson.cn>
Temparory stack memory on PEI is hardcoded now, also minimium memory
size 256M is hardcoded now. Here memory map table from fw cfg can be
parsed. If there is memory map entry contains pei stack, it can be
published as usable memory at PEI stage.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
Cc: Bibo Mao <maobibo@loongson.cn>
Cc: Chao Li <lichao@loongson.cn>
---
.../Loongson/LoongArchQemuPkg/Loongson.dec | 2 -
.../Loongson/LoongArchQemuPkg/Loongson.dsc | 6 ---
.../LoongArchQemuPkg/PlatformPei/MemDetect.c | 37 ++++++++++++++++++-
.../PlatformPei/PlatformPei.inf | 2 -
4 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec
index e638b835e4..c2c6cc9596 100644
--- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec
+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec
@@ -48,8 +48,6 @@
gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase|0|UINT64|0x0000000b
gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize|0|UINT32|0x0000000c
- gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop|0x0|UINT64|0x0000000d
- gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom|0x0|UINT64|0x0000000e
gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvBase|0x0|UINT64|0x0000000f
gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvSize|0x0|UINT32|0x00000010
diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc
index 58aa16d3a9..aab2ca9b28 100644
--- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc
+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc
@@ -356,12 +356,6 @@
gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase | 0x10000
gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize | 0x10000
gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreeBase | 0x100000
- #
- # minimal memory for uefi bios should be 512M
- # 0x00000000 - 0x10000000
- # 0x90000000 - 0xA0000000
- #
- gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop | 0x10000000
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions | 0x06
gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile | { 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }
diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c
index 7e6a4a3aa9..03d1b0b75d 100644
--- a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c
+++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c
@@ -40,12 +40,47 @@ PublishPeiMemory (
UINT64 Base;
UINT64 Size;
UINT64 RamTop;
+ FIRMWARE_CONFIG_ITEM FwCfgItem;
+ UINTN FwCfgSize;
+ UINTN Processed;
+ LOONGARCH_MEMMAP_ENTRY MemoryMapEntry;
//
// Determine the range of memory to use during PEI
//
Base = PcdGet64 (PcdSecPeiTempRamBase) + PcdGet32 (PcdSecPeiTempRamSize);
- RamTop = PcdGet64 (PcdUefiRamTop);
+ RamTop = 0;
+
+ Status = QemuFwCfgFindFile ("etc/memmap", &FwCfgItem, &FwCfgSize);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if (FwCfgSize % sizeof MemoryMapEntry != 0) {
+ return EFI_PROTOCOL_ERROR;
+ }
+
+ QemuFwCfgSelectItem (FwCfgItem);
+ for (Processed = 0; Processed < FwCfgSize; Processed += sizeof MemoryMapEntry) {
+ QemuFwCfgReadBytes (sizeof MemoryMapEntry, &MemoryMapEntry);
+ if (MemoryMapEntry.Type != EfiAcpiAddressRangeMemory) {
+ continue;
+ }
+
+ /*
+ * Find memory map entry where PEI temp stack is located
+ */
+ if ((MemoryMapEntry.BaseAddr <= Base) &&
+ (Base < (MemoryMapEntry.BaseAddr + MemoryMapEntry.Length))) {
+ RamTop = MemoryMapEntry.BaseAddr + MemoryMapEntry.Length;
+ }
+ }
+
+ if (RamTop == 0) {
+ DEBUG ((DEBUG_ERROR, "ERROR: No memory map entry contains temp stack \n"));
+ ASSERT (FALSE);
+ }
+
Size = RamTop - Base;
//
diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf
index 6cc3513b63..65591a4d7b 100644
--- a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf
+++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf
@@ -64,8 +64,6 @@
[FixedPcd]
gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvBase
gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvSize
- gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom
- gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop
gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase
gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
--
2.39.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117084): https://edk2.groups.io/g/devel/message/117084
Mute This Topic: https://groups.io/mt/105134610/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [edk2-devel] [PATCH] Platform/Loongson: Remove minimium memory size limitation
2024-03-25 9:25 [edk2-devel] [PATCH] Platform/Loongson: Remove minimium memory size limitation xianglai
@ 2024-03-26 1:10 ` maobibo
2024-03-27 1:09 ` xianglai
0 siblings, 1 reply; 3+ messages in thread
From: maobibo @ 2024-03-26 1:10 UTC (permalink / raw)
To: devel, lixianglai; +Cc: Chao Li
On 2024/3/25 下午5:25, xianglai wrote:
> From: Bibo Mao <maobibo@loongson.cn>
>
> Temparory stack memory on PEI is hardcoded now, also minimium memory
> size 256M is hardcoded now. Here memory map table from fw cfg can be
> parsed. If there is memory map entry contains pei stack, it can be
> published as usable memory at PEI stage.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
> Cc: Bibo Mao <maobibo@loongson.cn>
> Cc: Chao Li <lichao@loongson.cn>
> ---
> .../Loongson/LoongArchQemuPkg/Loongson.dec | 2 -
> .../Loongson/LoongArchQemuPkg/Loongson.dsc | 6 ---
> .../LoongArchQemuPkg/PlatformPei/MemDetect.c | 37 ++++++++++++++++++-
> .../PlatformPei/PlatformPei.inf | 2 -
> 4 files changed, 36 insertions(+), 11 deletions(-)
>
> diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec
> index e638b835e4..c2c6cc9596 100644
> --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec
> +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec
> @@ -48,8 +48,6 @@
>
> gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase|0|UINT64|0x0000000b
> gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize|0|UINT32|0x0000000c
> - gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop|0x0|UINT64|0x0000000d
> - gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom|0x0|UINT64|0x0000000e
> gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvBase|0x0|UINT64|0x0000000f
> gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvSize|0x0|UINT32|0x00000010
>
> diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc
> index 58aa16d3a9..aab2ca9b28 100644
> --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc
> +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc
> @@ -356,12 +356,6 @@
> gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase | 0x10000
> gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize | 0x10000
> gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreeBase | 0x100000
> - #
> - # minimal memory for uefi bios should be 512M
> - # 0x00000000 - 0x10000000
> - # 0x90000000 - 0xA0000000
> - #
> - gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop | 0x10000000
> gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions | 0x06
>
> gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile | { 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }
> diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c
> index 7e6a4a3aa9..03d1b0b75d 100644
> --- a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c
> +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c
> @@ -40,12 +40,47 @@ PublishPeiMemory (
> UINT64 Base;
> UINT64 Size;
> UINT64 RamTop;
> + FIRMWARE_CONFIG_ITEM FwCfgItem;
> + UINTN FwCfgSize;
> + UINTN Processed;
> + LOONGARCH_MEMMAP_ENTRY MemoryMapEntry;
>
> //
> // Determine the range of memory to use during PEI
> //
> Base = PcdGet64 (PcdSecPeiTempRamBase) + PcdGet32 (PcdSecPeiTempRamSize);
> - RamTop = PcdGet64 (PcdUefiRamTop);
> + RamTop = 0;
> +
> + Status = QemuFwCfgFindFile ("etc/memmap", &FwCfgItem, &FwCfgSize);
> + if (EFI_ERROR (Status)) {
> + return Status;
> + }
> +
> + if (FwCfgSize % sizeof MemoryMapEntry != 0) {
> + return EFI_PROTOCOL_ERROR;
> + }
> +
> + QemuFwCfgSelectItem (FwCfgItem);
> + for (Processed = 0; Processed < FwCfgSize; Processed += sizeof MemoryMapEntry) {
> + QemuFwCfgReadBytes (sizeof MemoryMapEntry, &MemoryMapEntry);
> + if (MemoryMapEntry.Type != EfiAcpiAddressRangeMemory) {
> + continue;
> + }
> +
> + /*
> + * Find memory map entry where PEI temp stack is located
> + */
> + if ((MemoryMapEntry.BaseAddr <= Base) &&
> + (Base < (MemoryMapEntry.BaseAddr + MemoryMapEntry.Length))) {
> + RamTop = MemoryMapEntry.BaseAddr + MemoryMapEntry.Length;
Xianglai,
Will it be better if there is one "break" sentence?
Regards
Bibo Mao
> + }
> + }
> +
> + if (RamTop == 0) {
> + DEBUG ((DEBUG_ERROR, "ERROR: No memory map entry contains temp stack \n"));
> + ASSERT (FALSE);
> + }
> +
> Size = RamTop - Base;
>
> //
> diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf
> index 6cc3513b63..65591a4d7b 100644
> --- a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf
> +++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf
> @@ -64,8 +64,6 @@
> [FixedPcd]
> gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvBase
> gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvSize
> - gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom
> - gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop
> gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase
> gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize
> gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117098): https://edk2.groups.io/g/devel/message/117098
Mute This Topic: https://groups.io/mt/105134610/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [edk2-devel] [PATCH] Platform/Loongson: Remove minimium memory size limitation
2024-03-26 1:10 ` maobibo
@ 2024-03-27 1:09 ` xianglai
0 siblings, 0 replies; 3+ messages in thread
From: xianglai @ 2024-03-27 1:09 UTC (permalink / raw)
To: maobibo, devel; +Cc: Chao Li
hi maobibo:
>
>
> On 2024/3/25 下午5:25, xianglai wrote:
>> From: Bibo Mao <maobibo@loongson.cn>
>>
>> Temparory stack memory on PEI is hardcoded now, also minimium memory
>>
[......]
>> +
>> + QemuFwCfgSelectItem (FwCfgItem);
>> + for (Processed = 0; Processed < FwCfgSize; Processed += sizeof MemoryMapEntry) {
>> + QemuFwCfgReadBytes (sizeof MemoryMapEntry, &MemoryMapEntry);
>> + if (MemoryMapEntry.Type != EfiAcpiAddressRangeMemory) {
>> + continue;
>> + }
>> +
>> + /*
>> + * Find memory map entry where PEI temp stack is located
>> + */
>> + if ((MemoryMapEntry.BaseAddr <= Base) &&
>> + (Base < (MemoryMapEntry.BaseAddr + MemoryMapEntry.Length))) {
>> + RamTop = MemoryMapEntry.BaseAddr + MemoryMapEntry.Length;
> Xianglai,
>
> Will it be better if there is one "break" sentence?
Ok,I will fix it in the next version.
Thanks,
Xianglai.
>
> Regards
> Bibo Mao
>
>> + }
>> + }
>> +
>> + if (RamTop == 0) {
>> + DEBUG ((DEBUG_ERROR, "ERROR: No memory map entry contains temp stack \n"));
>> + ASSERT (FALSE);
>> + }
>>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117144): https://edk2.groups.io/g/devel/message/117144
Mute This Topic: https://groups.io/mt/105134610/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-27 1:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-25 9:25 [edk2-devel] [PATCH] Platform/Loongson: Remove minimium memory size limitation xianglai
2024-03-26 1:10 ` maobibo
2024-03-27 1:09 ` xianglai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox