From patchwork Sat Jun 28 01:25:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 32644 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8BC07200B9 for ; Sat, 28 Jun 2014 01:26:56 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id uz6sf32953834obc.4 for ; Fri, 27 Jun 2014 18:26:56 -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=2ILCw8mV3W4dM1kGvSYqnSgRf0dlRpgCVFPX0bmphrI=; b=BQCPCs/8PI+oOtN5Gqb2hL9irvb40KLrqpObSY6aCAfj+cUKr8cWJd69vmK+YWcIvv N7mfpYKldy3BtXEmA9HTSwm7JFjr0dSjaeo6MzMktbRdJ2Z4Z0YYxie0d5IaVkSRvKRk 5Y9XB0J/PEIjFKIEHlp/rMhYvPEVDpfRmzLlkK66PaQfXH8Hlzo775mzV5rKet5Y6Wy+ 3azzYO0POI3iKQ8Z3FMuzmFnkTIckLTQFrp2PogfjoqjdGjj7TvsAxHkLO8Fl2fA46Aj AaQjD6LBys3pHcSRpR3NmS0uHFN3igKxFNkabc3WPJPfk6qI0VoT7V0BiufpczEVAv8M N0hg== X-Gm-Message-State: ALoCoQnbSxocOVSWq2qTZwKjtIFXE/CMUiR9F/ZGHKK+eOAp9Qpo1CeNU17a9l90GN1UBnrlc/OB X-Received: by 10.43.12.67 with SMTP id ph3mr13054231icb.28.1403918816158; Fri, 27 Jun 2014 18:26:56 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.49.193 with SMTP id q59ls856285qga.91.gmail; Fri, 27 Jun 2014 18:26:56 -0700 (PDT) X-Received: by 10.220.177.133 with SMTP id bi5mr17161316vcb.26.1403918816076; Fri, 27 Jun 2014 18:26:56 -0700 (PDT) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id cx7si7221850vcb.57.2014.06.27.18.26.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Jun 2014 18:26:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.176 as permitted sender) client-ip=209.85.128.176; Received: by mail-ve0-f176.google.com with SMTP id db12so6094073veb.35 for ; Fri, 27 Jun 2014 18:26:56 -0700 (PDT) X-Received: by 10.52.26.237 with SMTP id o13mr19152249vdg.1.1403918815944; Fri, 27 Jun 2014 18:26:55 -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 tc5csp147819vcb; Fri, 27 Jun 2014 18:26:55 -0700 (PDT) X-Received: by 10.224.98.197 with SMTP id r5mr34160044qan.57.1403918815556; Fri, 27 Jun 2014 18:26:55 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id g90si16107720qgf.80.2014.06.27.18.26.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 27 Jun 2014 18:26:55 -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 1X0hOv-0007GN-1q; Sat, 28 Jun 2014 01:25:57 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X0hOu-0007Fj-8b for xen-devel@lists.xen.org; Sat, 28 Jun 2014 01:25:56 +0000 Received: from [85.158.139.211:53778] by server-16.bemta-5.messagelabs.com id BF/69-18862-3A91EA35; Sat, 28 Jun 2014 01:25:55 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-4.tower-206.messagelabs.com!1403918753!12498959!1 X-Originating-IP: [209.85.192.182] 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 18616 invoked from network); 28 Jun 2014 01:25:54 -0000 Received: from mail-pd0-f182.google.com (HELO mail-pd0-f182.google.com) (209.85.192.182) by server-4.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 28 Jun 2014 01:25:54 -0000 Received: by mail-pd0-f182.google.com with SMTP id y13so5111779pdi.41 for ; Fri, 27 Jun 2014 18:25:52 -0700 (PDT) X-Received: by 10.67.13.134 with SMTP id ey6mr35306647pad.44.1403918752726; Fri, 27 Jun 2014 18:25:52 -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.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Jun 2014 18:25:52 -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:23 +0100 Message-Id: <1403918735-30027-8-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 07/19] move read_file() to efi-shared.c 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.176 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 now refactored read_file() is shareable with the ARM code that will be added, so move it to the shared C file. Signed-off-by: Roy Franz --- xen/arch/x86/efi/boot.c | 77 --------------------------------------- xen/arch/x86/efi/efi-shared.c | 83 +++++++++++++++++++++++++++++++++++++++++++ xen/include/efi/efi-shared.h | 2 ++ 3 files changed, 85 insertions(+), 77 deletions(-) diff --git a/xen/arch/x86/efi/boot.c b/xen/arch/x86/efi/boot.c index 8904a4e..2e3d341 100644 --- a/xen/arch/x86/efi/boot.c +++ b/xen/arch/x86/efi/boot.c @@ -164,83 +164,6 @@ static unsigned int __init get_argv(unsigned int argc, CHAR16 **argv, return argc; } -static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, - struct file *file) -{ - EFI_FILE_HANDLE FileHandle = NULL; - UINT64 size; - EFI_STATUS ret; - CHAR16 *what = NULL; - - if ( !name ) - PrintErrMesgExit(L"No Filename", EFI_OUT_OF_RESOURCES); - - ret = dir_handle->Open(dir_handle, &FileHandle, name, - EFI_FILE_MODE_READ, 0); - - if ( EFI_ERROR(ret) ) - what = L"Open"; - else - ret = FileHandle->SetPosition(FileHandle, -1); - if ( EFI_ERROR(ret) ) - what = what ?: L"Seek"; - else - ret = FileHandle->GetPosition(FileHandle, &size); - if ( EFI_ERROR(ret) ) - what = what ?: L"Get size"; - else - ret = FileHandle->SetPosition(FileHandle, 0); - if ( EFI_ERROR(ret) ) - what = what ?: L"Seek"; - else - { - file->addr = min(1UL << (32 + PAGE_SHIFT), - HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START); - ret = efi_bs->AllocatePages(AllocateMaxAddress, EfiLoaderData, - PFN_UP(size), &file->addr); - } - if ( EFI_ERROR(ret) ) - { - file->addr = 0; - what = what ?: L"Allocation"; - } - else - { - - 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 = what ?: L"Read"; - efi_bs->FreePages(file->addr, PFN_UP(file->size)); - file->addr = 0; - } - } - - if ( FileHandle ) - FileHandle->Close(FileHandle); - - - if ( what ) - { - 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; - } - -} - /* Only call with non-config files. */ void __init load_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, struct file *file) diff --git a/xen/arch/x86/efi/efi-shared.c b/xen/arch/x86/efi/efi-shared.c index d997b5c..98ad5db 100644 --- a/xen/arch/x86/efi/efi-shared.c +++ b/xen/arch/x86/efi/efi-shared.c @@ -11,6 +11,12 @@ #include #include #include +#include +#include +#if EFI_PAGE_SIZE != PAGE_SIZE +# error Cannot use xen/pfn.h here! +#endif + SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdOut; SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr; @@ -338,3 +344,80 @@ char *__init get_value(const struct file *cfg, const char *section, } return NULL; } + +bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, + struct file *file) +{ + EFI_FILE_HANDLE FileHandle = NULL; + UINT64 size; + EFI_STATUS ret; + CHAR16 *what = NULL; + + if ( !name ) + PrintErrMesgExit(L"No Filename", EFI_OUT_OF_RESOURCES); + + ret = dir_handle->Open(dir_handle, &FileHandle, name, + EFI_FILE_MODE_READ, 0); + + if ( EFI_ERROR(ret) ) + what = L"Open"; + else + ret = FileHandle->SetPosition(FileHandle, -1); + if ( EFI_ERROR(ret) ) + what = what ?: L"Seek"; + else + ret = FileHandle->GetPosition(FileHandle, &size); + if ( EFI_ERROR(ret) ) + what = what ?: L"Get size"; + else + ret = FileHandle->SetPosition(FileHandle, 0); + if ( EFI_ERROR(ret) ) + what = what ?: L"Seek"; + else + { + file->addr = min(1UL << (32 + PAGE_SHIFT), + HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START); + ret = efi_bs->AllocatePages(AllocateMaxAddress, EfiLoaderData, + PFN_UP(size), &file->addr); + } + if ( EFI_ERROR(ret) ) + { + file->addr = 0; + what = what ?: L"Allocation"; + } + else + { + + 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 = what ?: L"Read"; + efi_bs->FreePages(file->addr, PFN_UP(file->size)); + file->addr = 0; + } + } + + if ( FileHandle ) + FileHandle->Close(FileHandle); + + + if ( what ) + { + 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; + } + +} diff --git a/xen/include/efi/efi-shared.h b/xen/include/efi/efi-shared.h index d4b6e13..168cf2a 100644 --- a/xen/include/efi/efi-shared.h +++ b/xen/include/efi/efi-shared.h @@ -54,4 +54,6 @@ char *__init get_value(const struct file *cfg, const char *section, /* These functions need to be provided by the architecture's EFI code */ void __init noreturn blexit(const CHAR16 *str); +bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, + struct file *file); #endif