From patchwork Thu Sep 18 22:49:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 37615 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AF3F22054E for ; Thu, 18 Sep 2014 22:52:22 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gi9sf1036232lab.11 for ; Thu, 18 Sep 2014 15:52:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=m//hi6gWzO1VZ6w5g0B8BTSrssPdBEBouMr31UdaYZY=; b=LQTtgN+COGgXMwY79OH6AxZlAPNgQAa2Tacfun3wyO72cbxK1EsmSG3blJXPKweL6t zxzEzhXMNyiXPMOGX2u3gRGIlo/fabvSgLOJwsgcpkbOu530pwfkp9Y9/sZE46wv6euz SpN28SQgH2zz/eg+JOdjpPrCaMxI1xEpkgcmi+iy0ivMqps2fuIaf5NdT/MOS6//LpyQ S+Jc53V/UljlUxDfc/lb3Xb7h4OlGZJFuoQHkjwPdpvdZjsQ4pRQYc/oK3zX2kYUhG4C 9hSbOn9yMYgdQ5AQRnlhLUjfhTaIUbmZTNnknFnlisWROpcfYGGBpw2ZLecNBcYGM0WI 4UlQ== X-Gm-Message-State: ALoCoQnD7OIcKMV13m4VD7RKtYZELcRk82bx2jv7klbtFmkrnNql+Qo3mPxxY1tJAfolJiuVqCq+ X-Received: by 10.152.21.137 with SMTP id v9mr1290875lae.1.1411080741593; Thu, 18 Sep 2014 15:52:21 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.2 with SMTP id p2ls279210lag.10.gmail; Thu, 18 Sep 2014 15:52:21 -0700 (PDT) X-Received: by 10.112.28.8 with SMTP id x8mr2565791lbg.104.1411080741287; Thu, 18 Sep 2014 15:52:21 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com [209.85.215.47]) by mx.google.com with ESMTPS id pt7si80610lbb.120.2014.09.18.15.52.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 18 Sep 2014 15:52:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id mc6so2063937lab.20 for ; Thu, 18 Sep 2014 15:52:21 -0700 (PDT) X-Received: by 10.152.22.137 with SMTP id d9mr2680958laf.29.1411080741221; Thu, 18 Sep 2014 15:52:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.130.169 with SMTP id of9csp843139lbb; Thu, 18 Sep 2014 15:52:20 -0700 (PDT) X-Received: by 10.224.162.196 with SMTP id w4mr13327909qax.60.1411080739291; Thu, 18 Sep 2014 15:52:19 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id e34si171343qgf.51.2014.09.18.15.52.18 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 18 Sep 2014 15:52:19 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XUkWu-0006JK-Pr; Thu, 18 Sep 2014 22:50:24 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XUkWt-0006Ia-2f for xen-devel@lists.xen.org; Thu, 18 Sep 2014 22:50:23 +0000 Received: from [85.158.139.211:17110] by server-17.bemta-5.messagelabs.com id C4/21-08943-DA16B145; Thu, 18 Sep 2014 22:50:21 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-13.tower-206.messagelabs.com!1411080619!11506826!1 X-Originating-IP: [209.85.192.176] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 339 invoked from network); 18 Sep 2014 22:50:20 -0000 Received: from mail-pd0-f176.google.com (HELO mail-pd0-f176.google.com) (209.85.192.176) by server-13.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 18 Sep 2014 22:50:20 -0000 Received: by mail-pd0-f176.google.com with SMTP id g10so2320097pdj.7 for ; Thu, 18 Sep 2014 15:50:18 -0700 (PDT) X-Received: by 10.70.60.197 with SMTP id j5mr11435669pdr.145.1411080618767; Thu, 18 Sep 2014 15:50:18 -0700 (PDT) Received: from rfranz-t520.swisscom.com (70-35-38-154.static.wiline.com. [70.35.38.154]) by mx.google.com with ESMTPSA id ig4sm66332pbb.55.2014.09.18.15.50.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Sep 2014 15:50:18 -0700 (PDT) From: Roy Franz To: xen-devel@lists.xen.org, ian.campbell@citrix.com, stefano.stabellini@citrix.com, tim@xen.org, jbeulich@suse.com, keir@xen.org Date: Thu, 18 Sep 2014 15:49:54 -0700 Message-Id: <1411080607-32365-4-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1411080607-32365-1-git-send-email-roy.franz@linaro.org> References: <1411080607-32365-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org Subject: [Xen-devel] [PATCH V5 03/15] create arch functions to allocate memory for and process EFI memory map. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: roy.franz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: 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 --- xen/common/efi/boot.c | 79 ++++++++---------------------------------- xen/include/asm-x86/efi-boot.h | 76 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 64 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 1a6cd7c..307740b 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -61,8 +61,6 @@ static EFI_HANDLE __initdata efi_ih; static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdOut; static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr; -static UINT32 __initdata mdesc_ver; - static struct file __initdata cfg; static struct file __initdata kernel; static struct file __initdata ramdisk; @@ -657,16 +655,18 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) EFI_STATUS status; unsigned int i, argc; CHAR16 **argv, *file_name, *cfg_file_name = NULL; - UINTN cols, rows, depth, size, map_key, info_size, gop_mode = ~0; + UINTN cols, rows, depth, size, info_size, gop_mode = ~0; EFI_HANDLE *handles = NULL; EFI_SHIM_LOCK_PROTOCOL *shim_lock; EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL; 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; + UINT32 mmap_desc_ver = 0; + UINTN mmap_size, mmap_desc_size, mmap_key = 0; + void *mmap; efi_ih = ImageHandle; efi_bs = SystemTable->BootServices; @@ -966,8 +966,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); @@ -1262,67 +1260,20 @@ 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; - status = efi_bs->GetMemoryMap(&efi_memmap_size, efi_memmap, &map_key, - &efi_mdesc_size, &mdesc_ver); + efi_bs->GetMemoryMap(&mmap_size, NULL, &mmap_key, + &mmap_desc_size, &mmap_desc_ver); + mmap = efi_arch_allocate_mmap_buffer(mmap_size); + if ( !mmap ) + blexit(L"ERROR Unable to allocate memory for EFI memory map\r\n"); + + status = efi_bs->GetMemoryMap(&mmap_size, mmap, &mmap_key, + &mmap_desc_size, &mmap_desc_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, mmap, mmap_size, + mmap_desc_size, mmap_desc_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 ) @@ -1330,7 +1281,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) relocate_trampoline(cfg.addr); } - status = efi_bs->ExitBootServices(ImageHandle, map_key); + status = efi_bs->ExitBootServices(ImageHandle, mmap_key); if ( EFI_ERROR(status) ) PrintErrMesg(L"Cannot exit boot services", status); diff --git a/xen/include/asm-x86/efi-boot.h b/xen/include/asm-x86/efi-boot.h index f250941..8832b21 100644 --- a/xen/include/asm-x86/efi-boot.h +++ b/xen/include/asm-x86/efi-boot.h @@ -133,3 +133,79 @@ 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; + + /* Set global EFI memory map variables */ + efi_memmap_size = map_size; + efi_mdesc_size = desc_size; + efi_memmap = map; + + /* 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; +}