xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roy Franz <roy.franz@linaro.org>
To: xen-devel@lists.xen.org, ian.campbell@citrix.com,
	stefano.stabellini@citrix.com, tim@xen.org, jbeulich@suse.com,
	keir@xen.org
Cc: Roy Franz <roy.franz@linaro.org>, fu.wei@linaro.org
Subject: [PATCH for-4.5 V7 04/14] create arch functions to allocate memory for and process EFI memory map.
Date: Wed, 24 Sep 2014 18:42:22 -0700	[thread overview]
Message-ID: <1411609352-24549-5-git-send-email-roy.franz@linaro.org> (raw)
In-Reply-To: <1411609352-24549-1-git-send-email-roy.franz@linaro.org>

The memory used to store the EFI memory map is allocated in an architecture
specific way, and the processing of the memory map itself uses x86 specific
data structures. This patch adds architecture specific funtions so each
architecture can provide its own implementation.

Signed-off-by: Roy Franz <roy.franz@linaro.org>
---
 xen/arch/x86/efi/efi-boot.h | 71 +++++++++++++++++++++++++++++++++++++++++++++
 xen/common/efi/boot.c       | 62 ++++-----------------------------------
 2 files changed, 77 insertions(+), 56 deletions(-)

diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
index bd5f043..80b8dfe 100644
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -127,3 +127,74 @@ static void __init place_string(u32 *addr, const char *s)
     }
     *addr = (long)alloc;
 }
+
+static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,
+                                               void *map,
+                                               UINTN map_size,
+                                               UINTN desc_size,
+                                               UINT32 desc_ver)
+{
+    struct e820entry *e;
+    unsigned int i;
+
+    /* Populate E820 table and check trampoline area availability. */
+    e = e820map - 1;
+    for ( i = 0; i < map_size; i += desc_size )
+    {
+        EFI_MEMORY_DESCRIPTOR *desc = map + i;
+        u64 len = desc->NumberOfPages << EFI_PAGE_SHIFT;
+        u32 type;
+
+        switch ( desc->Type )
+        {
+        default:
+            type = E820_RESERVED;
+            break;
+        case EfiConventionalMemory:
+        case EfiBootServicesCode:
+        case EfiBootServicesData:
+            if ( !trampoline_phys && desc->PhysicalStart + len <= 0x100000 &&
+                 len >= cfg.size && desc->PhysicalStart + len > cfg.addr )
+                cfg.addr = (desc->PhysicalStart + len - cfg.size) & PAGE_MASK;
+            /* fall through */
+        case EfiLoaderCode:
+        case EfiLoaderData:
+            if ( desc->Attribute & EFI_MEMORY_WB )
+                type = E820_RAM;
+            else
+        case EfiUnusableMemory:
+                type = E820_UNUSABLE;
+            break;
+        case EfiACPIReclaimMemory:
+            type = E820_ACPI;
+            break;
+        case EfiACPIMemoryNVS:
+            type = E820_NVS;
+            break;
+        }
+        if ( e820nr && type == e->type &&
+             desc->PhysicalStart == e->addr + e->size )
+            e->size += len;
+        else if ( !len || e820nr >= E820MAX )
+            continue;
+        else
+        {
+            ++e;
+            e->addr = desc->PhysicalStart;
+            e->size = len;
+            e->type = type;
+            ++e820nr;
+        }
+    }
+
+}
+
+static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)
+{
+    place_string(&mbi.mem_upper, NULL);
+    mbi.mem_upper -= map_size;
+    mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR);
+    if ( mbi.mem_upper < xen_phys_start )
+        return NULL;
+    return (void *)(long)mbi.mem_upper;
+}
diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index b543d76..6c7caac 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -668,7 +668,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     EFI_FILE_HANDLE dir_handle;
     union string section = { NULL }, name;
-    struct e820entry *e;
     u64 efer;
     bool_t base_video = 0;
 
@@ -970,8 +969,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     mbi.boot_loader_name = (long)"EFI";
     mbi.mods_addr = (long)mb_modules;
 
-    place_string(&mbi.mem_upper, NULL);
-
     /* Collect EDD info. */
     BUILD_BUG_ON(offsetof(struct edd_info, edd_device_params) != EDDEXTSIZE);
     BUILD_BUG_ON(sizeof(struct edd_device_params) != EDDPARMSIZE);
@@ -1268,65 +1265,18 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     efi_bs->GetMemoryMap(&efi_memmap_size, NULL, &map_key,
                          &efi_mdesc_size, &mdesc_ver);
-    mbi.mem_upper -= efi_memmap_size;
-    mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR);
-    if ( mbi.mem_upper < xen_phys_start )
-        blexit(L"Out of static memory");
-    efi_memmap = (void *)(long)mbi.mem_upper;
+    efi_memmap = efi_arch_allocate_mmap_buffer(efi_memmap_size);
+    if ( !efi_memmap )
+        blexit(L"ERROR Unable to allocate memory for EFI memory map");
+
     status = efi_bs->GetMemoryMap(&efi_memmap_size, efi_memmap, &map_key,
                                   &efi_mdesc_size, &mdesc_ver);
     if ( EFI_ERROR(status) )
         PrintErrMesg(L"Cannot obtain memory map", status);
 
-    /* Populate E820 table and check trampoline area availability. */
-    e = e820map - 1;
-    for ( i = 0; i < efi_memmap_size; i += efi_mdesc_size )
-    {
-        EFI_MEMORY_DESCRIPTOR *desc = efi_memmap + i;
-        u64 len = desc->NumberOfPages << EFI_PAGE_SHIFT;
-        u32 type;
+    efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
+                                efi_mdesc_size, mdesc_ver);
 
-        switch ( desc->Type )
-        {
-        default:
-            type = E820_RESERVED;
-            break;
-        case EfiConventionalMemory:
-        case EfiBootServicesCode:
-        case EfiBootServicesData:
-            if ( !trampoline_phys && desc->PhysicalStart + len <= 0x100000 &&
-                 len >= cfg.size && desc->PhysicalStart + len > cfg.addr )
-                cfg.addr = (desc->PhysicalStart + len - cfg.size) & PAGE_MASK;
-            /* fall through */
-        case EfiLoaderCode:
-        case EfiLoaderData:
-            if ( desc->Attribute & EFI_MEMORY_WB )
-                type = E820_RAM;
-            else
-        case EfiUnusableMemory:
-                type = E820_UNUSABLE;
-            break;
-        case EfiACPIReclaimMemory:
-            type = E820_ACPI;
-            break;
-        case EfiACPIMemoryNVS:
-            type = E820_NVS;
-            break;
-        }
-        if ( e820nr && type == e->type &&
-             desc->PhysicalStart == e->addr + e->size )
-            e->size += len;
-        else if ( !len || e820nr >= E820MAX )
-            continue;
-        else
-        {
-            ++e;
-            e->addr = desc->PhysicalStart;
-            e->size = len;
-            e->type = type;
-            ++e820nr;
-        }
-    }
     if ( !trampoline_phys )
     {
         if ( !cfg.addr )
-- 
2.1.0

  parent reply	other threads:[~2014-09-25  1:42 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-25  1:42 [PATCH for-4.5 V7 00/14] arm64 EFI stub Roy Franz
2014-09-25  1:42 ` [PATCH for-4.5 V7 01/14] x86/EFI: fix freeing of uninitialized pointer Roy Franz
2014-09-25  1:42 ` [PATCH for-4.5 V7 02/14] move x86 EFI boot/runtime code to common/efi Roy Franz
2014-09-25  1:42 ` [PATCH for-4.5 V7 03/14] Move x86 specific funtions/variables to arch header Roy Franz
2014-09-25  1:42 ` Roy Franz [this message]
2014-09-25  1:42 ` [PATCH for-4.5 V7 05/14] Add architecture functions for pre/post ExitBootServices Roy Franz
2014-09-25  1:42 ` [PATCH for-4.5 V7 06/14] Add efi_arch_cfg_file_early/late() to handle arch specific cfg file fields Roy Franz
2014-09-25  1:42 ` [PATCH for-4.5 V7 07/14] Add efi_arch_handle_cmdline() for processing commandline Roy Franz
2014-09-25  1:42 ` [PATCH for-4.5 V7 08/14] Move x86 specific disk probing code Roy Franz
2014-09-25  1:42 ` [PATCH for-4.5 V7 09/14] Create arch functions for console and video init Roy Franz
2014-09-25  1:42 ` [PATCH for-4.5 V7 10/14] Add efi_arch_memory() for arch specific memory setup Roy Franz
2014-09-25  1:42 ` [PATCH for-4.5 V7 11/14] Add arch specific module handling to read_file() Roy Franz
2014-09-25 10:34   ` Jan Beulich
2014-09-25 16:44     ` Roy Franz
2014-09-25 18:52       ` Roy Franz
2014-09-26  0:25         ` Roy Franz
2014-09-26  6:25           ` Jan Beulich
2014-09-25  1:42 ` [PATCH for-4.5 V7 12/14] Add several misc. arch functions for EFI boot code Roy Franz
2014-09-25  1:42 ` [PATCH for-4.5 V7 13/14] Add efi_arch_use_config_file() function to control use of config file Roy Franz
2014-09-25  1:42 ` [PATCH for-4.5 V7 14/14] Add ARM EFI boot support Roy Franz
2014-09-25 10:49   ` Jan Beulich
2014-09-25 17:05     ` Roy Franz
2014-09-26  6:28       ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1411609352-24549-5-git-send-email-roy.franz@linaro.org \
    --to=roy.franz@linaro.org \
    --cc=fu.wei@linaro.org \
    --cc=ian.campbell@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=keir@xen.org \
    --cc=stefano.stabellini@citrix.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).