diff mbox series

[v4,07/21] sandbox: Map host memory for efi_loader

Message ID 20180618152315.34233-8-agraf@suse.de
State New
Headers show
Series sandbox: efi_loader support | expand

Commit Message

Alexander Graf June 18, 2018, 3:23 p.m. UTC
With efi_loader we do not control payload applications, so we can not
teach them about the difference between virtual and physical addresses.

Instead, let's just always map host virtual addresses in the efi memory
map. That way we can be sure that all memory allocation functions always
return consumable pointers.

Signed-off-by: Alexander Graf <agraf@suse.de>

---

v1 -> v2:

  - only compile efi_add_known_memory if efi_loader is enabled

v3 -> v4:

  - don't compile efi mapping code in for spl
---
 arch/sandbox/cpu/cpu.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Simon Glass June 21, 2018, 2:01 a.m. UTC | #1
Hi Alex,

On 18 June 2018 at 09:23, Alexander Graf <agraf@suse.de> wrote:
> With efi_loader we do not control payload applications, so we can not
> teach them about the difference between virtual and physical addresses.
>
> Instead, let's just always map host virtual addresses in the efi memory
> map. That way we can be sure that all memory allocation functions always
> return consumable pointers.
>
> Signed-off-by: Alexander Graf <agraf@suse.de>
>
> ---
>
> v1 -> v2:
>
>   - only compile efi_add_known_memory if efi_loader is enabled
>
> v3 -> v4:
>
>   - don't compile efi mapping code in for spl
> ---
>  arch/sandbox/cpu/cpu.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)

I don't want to use this patch. As mentioned EFI memory allocation
should use addresses, and not internal sandbox pointers.

Regards,
Simon
diff mbox series

Patch

diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c
index cde0b055a6..29dac8dfda 100644
--- a/arch/sandbox/cpu/cpu.c
+++ b/arch/sandbox/cpu/cpu.c
@@ -5,6 +5,7 @@ 
 #define DEBUG
 #include <common.h>
 #include <dm.h>
+#include <efi_loader.h>
 #include <errno.h>
 #include <linux/libfdt.h>
 #include <os.h>
@@ -177,3 +178,22 @@  void longjmp(jmp_buf jmp, int ret)
 	while (1)
 		;
 }
+
+#if CONFIG_IS_ENABLED(EFI_LOADER)
+
+/*
+ * In sandbox, we don't have a 1:1 map, so we need to expose
+ * process addresses instead of U-Boot addresses
+ */
+void efi_add_known_memory(void)
+{
+	u64 ram_start = (uintptr_t)map_sysmem(0, gd->ram_size);
+	u64 ram_size = gd->ram_size;
+	u64 start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
+	u64 pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
+
+	efi_add_memory_map(start, pages, EFI_CONVENTIONAL_MEMORY,
+			   false);
+}
+
+#endif