From patchwork Sat Jun 28 01:25: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: 32660 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 625FC200B9 for ; Sat, 28 Jun 2014 01:28:06 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id eu11sf24409931pac.2 for ; Fri, 27 Jun 2014 18:28:05 -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=wI8tcf/6JFxxAdCMiW3jNZxIDxmCm4wffe4V3Tnwyp4=; b=cbp8ABch/EXNEw1TbodkOmmr+WOtDT6tjlRTfz+TYPnDNOXe/G2WgWplMMdEPBfXpq 3EQiliXQY7KNTKKRrcqbbWwfnHgWaTBeJ+ohCndnUxd7upT53xkI/gQ7KfF38TFE+tGm MXaTe2ARDg1cAgdJEB6rDEsV50pCQ3wbe2QI7hVUg9NIfy2LWkCKOu1mqgOz0awhHQ7J uEMaHEiOp7csoOkFHFe8RFsrB58E9ZsR9/xygPU8IVKY5XZppchfEcMvgrEwtNyaNo1l /DRvxT5KpwAZb/tM3Ene9rxRkC2ujVIIsuDn7mTRDaYUIUsz181trTeTHTPBr5Ebms9R T+UA== X-Gm-Message-State: ALoCoQlgJMGAfUFpC0H8rXbp6NlR8eykMphqp9CP8j0nruRWNQq1w0z8fKpWWLfHeHNC8B6KB/IL X-Received: by 10.66.220.34 with SMTP id pt2mr13973937pac.8.1403918885550; Fri, 27 Jun 2014 18:28:05 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.25.196 with SMTP id 62ls183654qgt.45.gmail; Fri, 27 Jun 2014 18:28:05 -0700 (PDT) X-Received: by 10.58.210.168 with SMTP id mv8mr20120448vec.12.1403918885460; Fri, 27 Jun 2014 18:28:05 -0700 (PDT) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id bk6si7226920vcb.55.2014.06.27.18.28.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Jun 2014 18:28:05 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.173 as permitted sender) client-ip=209.85.128.173; Received: by mail-ve0-f173.google.com with SMTP id db11so6117943veb.18 for ; Fri, 27 Jun 2014 18:28:05 -0700 (PDT) X-Received: by 10.52.241.76 with SMTP id wg12mr19257612vdc.5.1403918885328; Fri, 27 Jun 2014 18:28:05 -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 tc5csp147874vcb; Fri, 27 Jun 2014 18:28:05 -0700 (PDT) X-Received: by 10.224.2.74 with SMTP id 10mr38980807qai.89.1403918884850; Fri, 27 Jun 2014 18:28:04 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id l4si15952155qae.116.2014.06.27.18.28.04 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 27 Jun 2014 18:28:04 -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 1X0hOu-0007G4-L3; Sat, 28 Jun 2014 01:25:56 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X0hOt-0007FL-0U for xen-devel@lists.xen.org; Sat, 28 Jun 2014 01:25:55 +0000 Received: from [193.109.254.147:28183] by server-13.bemta-14.messagelabs.com id 1D/3D-23211-2A91EA35; Sat, 28 Jun 2014 01:25:54 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-8.tower-27.messagelabs.com!1403918751!14244252!1 X-Originating-IP: [209.85.192.180] 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 28858 invoked from network); 28 Jun 2014 01:25:53 -0000 Received: from mail-pd0-f180.google.com (HELO mail-pd0-f180.google.com) (209.85.192.180) by server-8.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 28 Jun 2014 01:25:53 -0000 Received: by mail-pd0-f180.google.com with SMTP id fp1so5088093pdb.25 for ; Fri, 27 Jun 2014 18:25:51 -0700 (PDT) X-Received: by 10.66.119.136 with SMTP id ku8mr34851262pab.121.1403918751422; Fri, 27 Jun 2014 18:25:51 -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 eh4sm16637918pbc.79.2014.06.27.18.25.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Jun 2014 18:25:50 -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: Sat, 28 Jun 2014 02:25:22 +0100 Message-Id: <1403918735-30027-7-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1403918735-30027-1-git-send-email-roy.franz@linaro.org> References: <1403918735-30027-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org, linaro-uefi@lists.linaro.org Subject: [Xen-devel] [PATCH RFC 06/19] 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.128.173 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. Signed-off-by: Roy Franz --- xen/arch/x86/efi/boot.c | 58 +++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/efi/boot.c b/xen/arch/x86/efi/boot.c index 89d7954..8904a4e 100644 --- a/xen/arch/x86/efi/boot.c +++ b/xen/arch/x86/efi/boot.c @@ -173,11 +173,11 @@ 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); + PrintErrMesgExit(L"No Filename", EFI_OUT_OF_RESOURCES); + 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 @@ -206,40 +206,50 @@ 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 ) FileHandle->Close(FileHandle); + if ( what ) { - PrintErr(what); - PrintErr(L" failed for "); - PrintErrMesgExit(name, ret); + PrintErrMesg(what, ret); + blexit(L"Unable to load file"); + } + 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; } +/* Only call with non-config files. */ +void __init load_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, + struct file *file) +{ + read_file(dir_handle, name, file); + mb_modules[mbi.mods_count].mod_start = file->addr >> PAGE_SHIFT; + mb_modules[mbi.mods_count].mod_end = file->size; + ++mbi.mods_count; +} static void __init split_value(char *s) { @@ -640,7 +650,7 @@ 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_file(dir_handle, s2w(&name), &kernel); efi_bs->FreePool(name.w); if ( !EFI_ERROR(efi_bs->LocateProtocol(&shim_lock_guid, NULL, @@ -652,7 +662,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) if ( name.s ) { split_value(name.s); - read_file(dir_handle, s2w(&name), &ramdisk); + load_file(dir_handle, s2w(&name), &ramdisk); efi_bs->FreePool(name.w); } @@ -663,7 +673,7 @@ 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_file(dir_handle, s2w(&name), &ucode); efi_bs->FreePool(name.w); } @@ -671,7 +681,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) if ( name.s ) { split_value(name.s); - read_file(dir_handle, s2w(&name), &xsm); + load_file(dir_handle, s2w(&name), &xsm); efi_bs->FreePool(name.w); }