[PATCH 1/1] efi_loader: memory reservations according to e820 table

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 1/1] efi_loader: memory reservations according to e820 table

Heinrich Schuchardt
On the x86 architecture the e820 BIOS table defines reserved memory.
Mark it as EFI reserved memory.

Signed-off-by: Heinrich Schuchardt <[hidden email]>
---
 lib/efi_loader/efi_memory.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index aaf64421a3..bee0a0c97d 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -10,6 +10,9 @@
 #include <efi_loader.h>
 #include <malloc.h>
 #include <asm/global_data.h>
+#ifdef CONFIG_X86
+#include <asm/e820.h>
+#endif
 #include <libfdt_env.h>
 #include <linux/list_sort.h>
 #include <inttypes.h>
@@ -493,6 +496,30 @@ __weak void efi_add_known_memory(void)
  }
 }
 
+/*
+ * Create reservations according to the BIOS e820 table.
+ */
+static void e820_memory_reservation(void)
+{
+#ifdef CONFIG_X86
+ struct e820entry e820[32];
+ unsigned int i, num;
+ unsigned long start, pages;
+
+ num = install_e820_map(ARRAY_SIZE(e820), e820);
+
+ for (i = 0; i < num; ++i) {
+ if (e820[i].type == E820_RESERVED) {
+ start = e820[i].addr;
+ pages = ALIGN(e820[i].size, EFI_PAGE_SIZE) >>
+ EFI_PAGE_SHIFT;
+ efi_add_memory_map(start, pages,
+   EFI_RESERVED_MEMORY_TYPE, false);
+ }
+ }
+#endif
+}
+
 int efi_memory_init(void)
 {
  unsigned long runtime_start, runtime_end, runtime_pages;
@@ -525,6 +552,7 @@ int efi_memory_init(void)
 
  efi_bounce_buffer = (void*)(uintptr_t)efi_bounce_buffer_addr;
 #endif
+ e820_memory_reservation();
 
  return 0;
 }
--
2.15.1

_______________________________________________
U-Boot mailing list
[hidden email]
https://lists.denx.de/listinfo/u-boot
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/1] efi_loader: memory reservations according to e820 table

Heinrich Schuchardt
On 01/14/2018 04:27 AM, Heinrich Schuchardt wrote:
> On the x86 architecture the e820 BIOS table defines reserved memory.
> Mark it as EFI reserved memory.
>

Hello Simon, hello Bin,

is there a place in the x86 start up code where we could put the new
e820_memory_reservation() function?

Putting this into the EFI mainline code is a bit awkward.

Best regards

Heinrich

> Signed-off-by: Heinrich Schuchardt <[hidden email]>
> ---
>   lib/efi_loader/efi_memory.c | 28 ++++++++++++++++++++++++++++
>   1 file changed, 28 insertions(+)
>
> diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
> index aaf64421a3..bee0a0c97d 100644
> --- a/lib/efi_loader/efi_memory.c
> +++ b/lib/efi_loader/efi_memory.c
> @@ -10,6 +10,9 @@
>   #include <efi_loader.h>
>   #include <malloc.h>
>   #include <asm/global_data.h>
> +#ifdef CONFIG_X86
> +#include <asm/e820.h>
> +#endif
>   #include <libfdt_env.h>
>   #include <linux/list_sort.h>
>   #include <inttypes.h>
> @@ -493,6 +496,30 @@ __weak void efi_add_known_memory(void)
>   }
>   }
>  
> +/*
> + * Create reservations according to the BIOS e820 table.
> + */
> +static void e820_memory_reservation(void)
> +{
> +#ifdef CONFIG_X86
> + struct e820entry e820[32];
> + unsigned int i, num;
> + unsigned long start, pages;
> +
> + num = install_e820_map(ARRAY_SIZE(e820), e820);
> +
> + for (i = 0; i < num; ++i) {
> + if (e820[i].type == E820_RESERVED) {
> + start = e820[i].addr;
> + pages = ALIGN(e820[i].size, EFI_PAGE_SIZE) >>
> + EFI_PAGE_SHIFT;
> + efi_add_memory_map(start, pages,
> +   EFI_RESERVED_MEMORY_TYPE, false);
> + }
> + }
> +#endif
> +}
> +
>   int efi_memory_init(void)
>   {
>   unsigned long runtime_start, runtime_end, runtime_pages;
> @@ -525,6 +552,7 @@ int efi_memory_init(void)
>  
>   efi_bounce_buffer = (void*)(uintptr_t)efi_bounce_buffer_addr;
>   #endif
> + e820_memory_reservation();
>  
>   return 0;
>   }
>
_______________________________________________
U-Boot mailing list
[hidden email]
https://lists.denx.de/listinfo/u-boot
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/1] efi_loader: memory reservations according to e820 table

Alexander Graf


On 14.01.18 16:59, Heinrich Schuchardt wrote:

> On 01/14/2018 04:27 AM, Heinrich Schuchardt wrote:
>> On the x86 architecture the e820 BIOS table defines reserved memory.
>> Mark it as EFI reserved memory.
>>
>
> Hello Simon, hello Bin,
>
> is there a place in the x86 start up code where we could put the new
> e820_memory_reservation() function?
>
> Putting this into the EFI mainline code is a bit awkward.

Maybe you could just use the e820 table for all RAM population?
Something like this:


diff --git a/arch/x86/lib/e820.c b/arch/x86/lib/e820.c
index 5babfde268..b88a4f8d3c 100644
--- a/arch/x86/lib/e820.c
+++ b/arch/x86/lib/e820.c
@@ -35,3 +35,32 @@ __weak unsigned install_e820_map(unsigned max_entries,

  return 4;
 }
+
+#ifdef CONFIG_EFI_LOADER
+#include <efi_loader.h>
+
+void efi_add_known_memory(void)
+{
+    struct e820entry e820[32];
+    unsigned int i, num;
+    unsigned long start, pages;
+
+    num = install_e820_map(ARRAY_SIZE(e820), e820);
+
+    for (i = 0; i < num; ++i) {
+ start = e820[i].addr;
+ pages = ALIGN(e820[i].size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT;
+
+ switch (e820[i].type) {
+ case E820_RESERVED:
+ efi_add_memory_map(start, pages,
+   EFI_RESERVED_MEMORY_TYPE, false);
+ break;
+ case E820_RAM:
+ efi_add_memory_map(start, pages,
+   EFI_CONVENTIONAL_MEMORY, false);
+ break;
+        }
+    }
+}
+#endif
_______________________________________________
U-Boot mailing list
[hidden email]
https://lists.denx.de/listinfo/u-boot