From patchwork Tue Jul 22 00:43:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 34015 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f199.google.com (mail-pd0-f199.google.com [209.85.192.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4886F20492 for ; Tue, 22 Jul 2014 00:46:21 +0000 (UTC) Received: by mail-pd0-f199.google.com with SMTP id ft15sf55595501pdb.6 for ; Mon, 21 Jul 2014 17:46:20 -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=rQc4IQxugrrS9Szui/Nj/iGYLHIj5NhUprN9uxOZq5w=; b=InFnaO3BgazYqPZtPpk+YHrh7SgkmcUu5P5IDUtd+N+4T9Qp73ESAcfDBjxjBAVbBO FDIu2dCPzPCqXPGOTY8JOirhx15uQ7w7XLI5Eh55TIN4S5pBR/vl3QfNER2GGHoPDQd2 RvdzwPft6f+/OAJyt3JUA/85norKeLQs0zZviKid6Pot7ICkdXgDtm8n+6D+Ogl3bsAb FY3lgxyJiHvKorSEnvidS/4T5CgNlbSvcvRqPnaTlZ2oeiumpYceiKoY3qGg8Ge4lT+s zxA2DALg8665VjI/+8dsciJ+ss/fyieKOI7fyhAmm28I3WVpmOYIcT3rlVAfvTGZsjCP VCcA== X-Gm-Message-State: ALoCoQmsSweTV3te3v2fdnF8IzwR7POlDbTbUVk4VwhsNsriaFWhFHL3wSpo1Nl7ZzmhYvQ705zc X-Received: by 10.70.48.38 with SMTP id i6mr14292380pdn.5.1405989980366; Mon, 21 Jul 2014 17:46:20 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.96.201 with SMTP id k67ls2133024qge.22.gmail; Mon, 21 Jul 2014 17:46:20 -0700 (PDT) X-Received: by 10.52.172.5 with SMTP id ay5mr29414440vdc.38.1405989980225; Mon, 21 Jul 2014 17:46:20 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id i4si4091855vdg.41.2014.07.21.17.46.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Jul 2014 17:46:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id hq11so12229280vcb.10 for ; Mon, 21 Jul 2014 17:46:20 -0700 (PDT) X-Received: by 10.52.37.81 with SMTP id w17mr6239003vdj.95.1405989980137; Mon, 21 Jul 2014 17:46:20 -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.221.37.5 with SMTP id tc5csp154159vcb; Mon, 21 Jul 2014 17:46:19 -0700 (PDT) X-Received: by 10.43.135.194 with SMTP id ih2mr32470159icc.21.1405989978698; Mon, 21 Jul 2014 17:46:18 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id ih8si49530551icb.63.2014.07.21.17.46.18 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 21 Jul 2014 17:46:18 -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 1X9OBi-000099-K8; Tue, 22 Jul 2014 00:44:14 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X9OBh-00008P-4x for xen-devel@lists.xen.org; Tue, 22 Jul 2014 00:44:13 +0000 Received: from [193.109.254.147:17082] by server-12.bemta-14.messagelabs.com id 6F/67-23840-CD3BDC35; Tue, 22 Jul 2014 00:44:12 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-16.tower-27.messagelabs.com!1405989847!13342170!1 X-Originating-IP: [209.85.220.45] 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 29501 invoked from network); 22 Jul 2014 00:44:09 -0000 Received: from mail-pa0-f45.google.com (HELO mail-pa0-f45.google.com) (209.85.220.45) by server-16.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 22 Jul 2014 00:44:09 -0000 Received: by mail-pa0-f45.google.com with SMTP id eu11so10822419pac.18 for ; Mon, 21 Jul 2014 17:44:07 -0700 (PDT) X-Received: by 10.68.114.65 with SMTP id je1mr12268928pbb.124.1405989847527; Mon, 21 Jul 2014 17:44:07 -0700 (PDT) Received: from rfranz-t520.local (c-24-10-97-91.hsd1.ca.comcast.net. [24.10.97.91]) by mx.google.com with ESMTPSA id fl3sm15417298pbc.35.2014.07.21.17.44.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Jul 2014 17:44:06 -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: Mon, 21 Jul 2014 17:43:27 -0700 Message-Id: <1405989815-25236-5-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1405989815-25236-1-git-send-email-roy.franz@linaro.org> References: <1405989815-25236-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org, linaro-uefi@lists.linaro.org Subject: [Xen-devel] [PATCH V2 04/12] Refactor read_file() so it can be shared. 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.220.179 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 read_file() function updated some multiboot specific data structures as it was loading a file. These changes make read_file() more generic, and create a load_file() wrapper for x86 that updates the multiboot data structures. read_file() no longer does special handling of the configuration file, as this was only needed to avoid adding it to the multiboot structures. read_file() and load_file() return error codes rather than directly exiting on error to facilicate sharing. Different architectures may require different max allocation addresses so take that as an argument. Signed-off-by: Roy Franz --- xen/arch/x86/efi/boot.c | 89 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 30 deletions(-) diff --git a/xen/arch/x86/efi/boot.c b/xen/arch/x86/efi/boot.c index c0546ec..17aaa67 100644 --- a/xen/arch/x86/efi/boot.c +++ b/xen/arch/x86/efi/boot.c @@ -338,7 +338,7 @@ static CHAR16 *__init point_tail(CHAR16 *fn) } static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, - struct file *file) + struct file *file, EFI_PHYSICAL_ADDRESS max_addr) { EFI_FILE_HANDLE FileHandle = NULL; UINT64 size; @@ -346,11 +346,14 @@ static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, CHAR16 *what = NULL; if ( !name ) - PrintErrMesgExit(L"No filename", EFI_OUT_OF_RESOURCES); + { + PrintErrMesg(L"No Filename", EFI_OUT_OF_RESOURCES); + return 0; + } + ret = dir_handle->Open(dir_handle, &FileHandle, name, EFI_FILE_MODE_READ, 0); - if ( file == &cfg && ret == EFI_NOT_FOUND ) - return 0; + if ( EFI_ERROR(ret) ) what = L"Open"; else @@ -367,8 +370,7 @@ static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, what = what ?: L"Seek"; else { - file->addr = min(1UL << (32 + PAGE_SHIFT), - HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START); + file->addr = max_addr; ret = efi_bs->AllocatePages(AllocateMaxAddress, EfiLoaderData, PFN_UP(size), &file->addr); } @@ -379,25 +381,17 @@ static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, } else { - if ( file != &cfg ) - { - PrintStr(name); - PrintStr(L": "); - DisplayUint(file->addr, 2 * sizeof(file->addr)); - PrintStr(L"-"); - DisplayUint(file->addr + size, 2 * sizeof(file->addr)); - PrintStr(newline); - mb_modules[mbi.mods_count].mod_start = file->addr >> PAGE_SHIFT; - mb_modules[mbi.mods_count].mod_end = size; - ++mbi.mods_count; - } file->size = size; ret = FileHandle->Read(FileHandle, &file->size, file->ptr); if ( !EFI_ERROR(ret) && file->size != size ) ret = EFI_ABORTED; if ( EFI_ERROR(ret) ) - what = L"Read"; + { + what = what ?: L"Read"; + efi_bs->FreePages(file->addr, PFN_UP(file->size)); + file->addr = 0; + } } if ( FileHandle ) @@ -405,12 +399,21 @@ static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, if ( what ) { - PrintErr(what); - PrintErr(L" failed for "); - PrintErrMesgExit(name, ret); + PrintErrMesg(what, ret); + PrintErr(L"Unable to load file"); + return 0; + } + else + { + PrintStr(name); + PrintStr(L": "); + DisplayUint(file->addr, 2 * sizeof(file->addr)); + PrintStr(L"-"); + DisplayUint(file->addr + file->size, 2 * sizeof(file->addr)); + PrintStr(newline); + return 1; } - return 1; } static void __init pre_parse(const struct file *cfg) @@ -470,6 +473,21 @@ static char *__init get_value(const struct file *cfg, const char *section, } return NULL; } +/* Only call with non-config files. */ +bool_t __init load_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, + struct file *file) +{ + EFI_PHYSICAL_ADDRESS max = min(1UL << (32 + PAGE_SHIFT), + HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START); + if ( read_file(dir_handle, name, file, max) ) + { + mb_modules[mbi.mods_count].mod_start = file->addr >> PAGE_SHIFT; + mb_modules[mbi.mods_count].mod_end = file->size; + ++mbi.mods_count; + return 1; + } + return 0; +} static void __init split_value(char *s) { @@ -692,6 +710,9 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) struct e820entry *e; u64 efer; bool_t base_video = 0; + bool_t load_ok = 0; + EFI_PHYSICAL_ADDRESS max_addr = min(1UL << (32 + PAGE_SHIFT), + HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START); efi_ih = ImageHandle; efi_bs = SystemTable->BootServices; @@ -831,7 +852,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) while ( (tail = point_tail(file_name)) != NULL ) { wstrcpy(tail, L".cfg"); - if ( read_file(dir_handle, file_name, &cfg) ) + if ( read_file(dir_handle, file_name, &cfg, max_addr) ) break; *tail = 0; } @@ -841,7 +862,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) PrintStr(file_name); PrintStr(L"'\r\n"); } - else if ( !read_file(dir_handle, cfg_file_name, &cfg) ) + else if ( !read_file(dir_handle, cfg_file_name, &cfg, max_addr) ) blexit(L"Configuration file not found."); pre_parse(&cfg); @@ -860,7 +881,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) break; efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size)); cfg.addr = 0; - if ( !read_file(dir_handle, s2w(&name), &cfg) ) + if ( !read_file(dir_handle, s2w(&name), &cfg, max_addr) ) { PrintStr(L"Chained configuration file '"); PrintStr(name.w); @@ -873,8 +894,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) if ( !name.s ) blexit(L"No Dom0 kernel image specified."); split_value(name.s); - read_file(dir_handle, s2w(&name), &kernel); + load_ok = load_file(dir_handle, s2w(&name), &kernel); efi_bs->FreePool(name.w); + if ( !load_ok ) + blexit(L"Unable to load Dom0 Kernel image."); if ( !EFI_ERROR(efi_bs->LocateProtocol(&shim_lock_guid, NULL, (void **)&shim_lock)) && @@ -885,8 +908,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) if ( name.s ) { split_value(name.s); - read_file(dir_handle, s2w(&name), &ramdisk); + load_ok = load_file(dir_handle, s2w(&name), &ramdisk); efi_bs->FreePool(name.w); + if ( !load_ok ) + blexit(L"Unable to load ramdisk image."); } name.s = get_value(&cfg, section.s, "ucode"); @@ -896,16 +921,20 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { microcode_set_module(mbi.mods_count); split_value(name.s); - read_file(dir_handle, s2w(&name), &ucode); + load_ok = load_file(dir_handle, s2w(&name), &ucode); efi_bs->FreePool(name.w); + if ( !load_ok ) + blexit(L"Unable to load ucode image."); } name.s = get_value(&cfg, section.s, "xsm"); if ( name.s ) { split_value(name.s); - read_file(dir_handle, s2w(&name), &xsm); + load_ok = load_file(dir_handle, s2w(&name), &xsm); efi_bs->FreePool(name.w); + if ( !load_ok ) + blexit(L"Unable to load ucode image."); } name.s = get_value(&cfg, section.s, "options");