From patchwork Thu Sep 25 01:42:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 37880 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f200.google.com (mail-we0-f200.google.com [74.125.82.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BB39820063 for ; Thu, 25 Sep 2014 01:44:50 +0000 (UTC) Received: by mail-we0-f200.google.com with SMTP id w62sf3372338wes.3 for ; Wed, 24 Sep 2014 18:44:50 -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=3ts8m4J39RgwulmPYTPHfoHvl5AGB08iQRvHrEDldIU=; b=jW/dC+BoOYpISNqTWe6afoGu6xZsyMUuGyOkEVR8oGHBQEjf2qfBIluXEx5vZv8jse BoUA6UbXRrBaloEqC0LSn/O3D9JxJzb5NmyUeBABLWHLIv/fwbB/tHeLF5mmcwdrDmz8 bsOaw+yj2T+IZuPrTRNB8mwpfUKE6Z0VJaetx2aTWCUlg3iF/Up5908iH1B0WpLygtfm TQ0wSkwqZdfwi2vIOCa72fZASQf5slDNmcVybjGrtI/5MaxtsjfFAKoPUdkHcHqbGOxK Cqze5ZQGngiz997/G+C8fmt5vbwSB79gRiYGtR+HPmMgLNcaNdA+nsScNLrfJd4xCDjl CNzw== X-Gm-Message-State: ALoCoQmo+cci9DT0RizLnpvY8AL+mpaLLDTbQRiVEf7LyEgpoL7pPGNDYKZxC+ycB2+EP8a1gSIv X-Received: by 10.112.89.8 with SMTP id bk8mr1568164lbb.6.1411609490001; Wed, 24 Sep 2014 18:44:50 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.8 with SMTP id bc8ls208555lab.86.gmail; Wed, 24 Sep 2014 18:44:49 -0700 (PDT) X-Received: by 10.152.29.100 with SMTP id j4mr9651334lah.47.1411609489867; Wed, 24 Sep 2014 18:44:49 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com [209.85.217.169]) by mx.google.com with ESMTPS id 1si926795lal.89.2014.09.24.18.44.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 24 Sep 2014 18:44:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id b12so11782308lbj.14 for ; Wed, 24 Sep 2014 18:44:49 -0700 (PDT) X-Received: by 10.112.224.9 with SMTP id qy9mr9370851lbc.57.1411609489794; Wed, 24 Sep 2014 18:44:49 -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 of9csp678227lbb; Wed, 24 Sep 2014 18:44:49 -0700 (PDT) X-Received: by 10.52.253.39 with SMTP id zx7mr7377830vdc.2.1411609488549; Wed, 24 Sep 2014 18:44:48 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id rl7si433009vcb.85.2014.09.24.18.44.47 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 24 Sep 2014 18:44:48 -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 1XWy56-0000wk-E1; Thu, 25 Sep 2014 01:42:52 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XWy54-0000vc-GV for xen-devel@lists.xen.org; Thu, 25 Sep 2014 01:42:50 +0000 Received: from [85.158.137.68:39102] by server-4.bemta-3.messagelabs.com id E7/14-18709-91373245; Thu, 25 Sep 2014 01:42:49 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-8.tower-31.messagelabs.com!1411609367!11894422!1 X-Originating-IP: [209.85.213.181] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.12.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10674 invoked from network); 25 Sep 2014 01:42:48 -0000 Received: from mail-ig0-f181.google.com (HELO mail-ig0-f181.google.com) (209.85.213.181) by server-8.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 25 Sep 2014 01:42:48 -0000 Received: by mail-ig0-f181.google.com with SMTP id h18so7587785igc.2 for ; Wed, 24 Sep 2014 18:42:47 -0700 (PDT) X-Received: by 10.42.84.9 with SMTP id j9mr15781105icl.60.1411609367247; Wed, 24 Sep 2014 18:42:47 -0700 (PDT) Received: from rfranz-v430.caveonetworks.com (64.2.3.195.ptr.us.xo.net. [64.2.3.195]) by mx.google.com with ESMTPSA id x9sm5829238igl.10.2014.09.24.18.42.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Sep 2014 18:42:46 -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: Wed, 24 Sep 2014 18:42:22 -0700 Message-Id: <1411609352-24549-5-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1411609352-24549-1-git-send-email-roy.franz@linaro.org> References: <1411609352-24549-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org Subject: [Xen-devel] [PATCH for-4.5 V7 04/14] 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.217.169 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/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 )