From patchwork Fri Sep 26 04:42:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 37937 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7AF0E202DB for ; Fri, 26 Sep 2014 04:43:21 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id x13sf3096982wgg.4 for ; Thu, 25 Sep 2014 21:43: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=8hJ6AlP3PihcEEVp6XCM4WeRoI3uR9sj2ijy+aCSTV8=; b=Av+pFD2ddi5rx7YDtrrKH8AJyqydRP4lZVD6Daerjvnfku4UUBpe4gkKlyRn2lCkAa o50J+bkCuWr3vlzG5sZcJvSLdyMcCcefkUQn6u7LPsLA+VveltARtXbqfmeU+DgtV33g WwyrFMU3bxjwf2KaQY+X93WVpBWfy5gSOyK5gX5BPPNBAqBeffaULUIRJ8CAHHyxQSw4 OYTOR4BIQ88sU30Gb7T+ijx6NX8XpfGX6Vr/kkEY5cZSrrH70kh+LcmHs8Fku/ok8OgT 2skKf0dG52XunXuIRjWkfmGOgZ1t63RfqEO41wxuUTKq3P0qMWAGkAVyC+Oxlwzq53WC HTdg== X-Gm-Message-State: ALoCoQnebjQWab/+tVKNR6JdwmS2Ral4P9jH50QLzi0RDP3rT/3Oc7BPkbxJ0/ldUc2EXRyGHox2 X-Received: by 10.152.19.131 with SMTP id f3mr2790251lae.0.1411706600692; Thu, 25 Sep 2014 21:43:20 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.203.235 with SMTP id kt11ls360157lac.83.gmail; Thu, 25 Sep 2014 21:43:20 -0700 (PDT) X-Received: by 10.153.4.39 with SMTP id cb7mr17540917lad.19.1411706600323; Thu, 25 Sep 2014 21:43:20 -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 a4si5591140lbr.29.2014.09.25.21.43.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 25 Sep 2014 21:43:20 -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 u10so400622lbd.28 for ; Thu, 25 Sep 2014 21:43:20 -0700 (PDT) X-Received: by 10.112.163.103 with SMTP id yh7mr16714065lbb.73.1411706600213; Thu, 25 Sep 2014 21:43: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.112.130.169 with SMTP id of9csp2428lbb; Thu, 25 Sep 2014 21:43:19 -0700 (PDT) X-Received: by 10.221.44.7 with SMTP id ue7mr4472070vcb.28.1411706598678; Thu, 25 Sep 2014 21:43:18 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id ui7si2000621vcb.55.2014.09.25.21.43.18 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 25 Sep 2014 21:43: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 1XXNMR-00050u-CD; Fri, 26 Sep 2014 04:42:27 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XXNMP-00050J-8H for xen-devel@lists.xen.org; Fri, 26 Sep 2014 04:42:25 +0000 Received: from [193.109.254.147:65419] by server-13.bemta-14.messagelabs.com id 45/F3-19311-DAEE4245; Fri, 26 Sep 2014 04:42:21 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-4.tower-27.messagelabs.com!1411706538!13139839!1 X-Originating-IP: [209.85.220.52] 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 9612 invoked from network); 26 Sep 2014 04:42:19 -0000 Received: from mail-pa0-f52.google.com (HELO mail-pa0-f52.google.com) (209.85.220.52) by server-4.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 26 Sep 2014 04:42:19 -0000 Received: by mail-pa0-f52.google.com with SMTP id fb1so240861pad.11 for ; Thu, 25 Sep 2014 21:42:18 -0700 (PDT) X-Received: by 10.66.172.36 with SMTP id az4mr25984288pac.104.1411706538021; Thu, 25 Sep 2014 21:42:18 -0700 (PDT) Received: from rfranz-i7.local (c-24-10-97-91.hsd1.ca.comcast.net. [24.10.97.91]) by mx.google.com with ESMTPSA id tv4sm3654788pab.28.2014.09.25.21.42.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Sep 2014 21:42:17 -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, 25 Sep 2014 21:42:06 -0700 Message-Id: <1411706529-8765-2-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1411706529-8765-1-git-send-email-roy.franz@linaro.org> References: <1411706529-8765-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org Subject: [Xen-devel] [PATCH for-4.5 V8 1/4] Add arch specific module handling to read_file() 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: Each architecture tracks modules differently internally, so add efi_arch_handle_module() routine to enable the common code to invoke the proper handling of modules as they are loaded. Module handling for ucode,ramdisk, and xsm is changed to not process remainder of string after filename as options, since these modules don't take options. Signed-off-by: Roy Franz --- xen/arch/x86/efi/efi-boot.h | 37 ++++++++++++++++++++-- xen/common/efi/boot.c | 75 ++++++++++++++++++++++++++++----------------- 2 files changed, 82 insertions(+), 30 deletions(-) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 2f032e0..16d58cc 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -263,8 +263,8 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect if ( name.s ) { microcode_set_module(mbi.mods_count); - split_value(name.s); - read_file(dir_handle, s2w(&name), &ucode); + split_string(name.s); + read_file(dir_handle, s2w(&name), &ucode, NULL); efi_bs->FreePool(name.w); } } @@ -564,3 +564,36 @@ static void __init efi_arch_memory_setup(void) l3_bootmap[l3_table_offset(xen_phys_start + (8 << L2_PAGETABLE_SHIFT) - 1)] = l3e_from_paddr((UINTN)l2_bootmap, __PAGE_HYPERVISOR); } + +static void __init efi_arch_handle_module(struct file *file, const CHAR16 *name, + char *options) +{ + union string local_name; + void *ptr; + + /* + * Make a copy, as conversion is destructive, and caller still wants + * wide string available after this call returns. + */ + if ( efi_bs->AllocatePool(EfiLoaderData, (wstrlen(name) + 1) * sizeof(*name), + &ptr) != EFI_SUCCESS ) + blexit(L"Unable to allocate string buffer"); + + local_name.w = ptr; + wstrcpy(local_name.w, name); + w2s(&local_name); + + /* + * If options are provided, put them in + * mb_modules[mbi.mods_count].string after the filename, with a space + * separating them. place_string() prepends strings and adds separating + * spaces, so the call order is reversed. + */ + if ( options ) + place_string(&mb_modules[mbi.mods_count].string, options); + place_string(&mb_modules[mbi.mods_count].string, local_name.s); + mb_modules[mbi.mods_count].mod_start = file->addr >> PAGE_SHIFT; + mb_modules[mbi.mods_count].mod_end = file->size; + ++mbi.mods_count; + efi_bs->FreePool(ptr); +} diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index c9b5fdc..301c0be 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -59,11 +59,12 @@ static void noreturn blexit(const CHAR16 *str); static void PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode); static char *get_value(const struct file *cfg, const char *section, const char *item); -static void split_value(char *s); +static char *split_string(char *s); static CHAR16 *s2w(union string *str); static char *w2s(const union string *str); -static bool_t read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, - struct file *file); +static bool_t read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, + struct file *file, char *options); +static size_t wstrlen(const CHAR16 * s); static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz); static EFI_BOOT_SERVICES *__initdata efi_bs; @@ -120,6 +121,15 @@ static void __init DisplayUint(UINT64 Val, INTN Width) PrintStr(PrintString); } +static size_t __init wstrlen(const CHAR16 *s) +{ + const CHAR16 *sc; + + for ( sc = s; *sc != L'\0'; ++sc ) + /* nothing */; + return sc - s; +} + static CHAR16 *__init wstrcpy(CHAR16 *d, const CHAR16 *s) { CHAR16 *r = d; @@ -409,9 +419,25 @@ static CHAR16 *__init point_tail(CHAR16 *fn) break; } } +/* + * Truncate string at first space, and return pointer + * to remainder of string, if any/ NULL returned if + * no remainder after space. + */ +static char * __init split_string(char *s) +{ + while ( *s && !isspace(*s) ) + ++s; + if ( *s ) + { + *s = 0; + return s + 1; + } + return NULL; +} static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, - struct file *file) + struct file *file, char *options) { EFI_FILE_HANDLE FileHandle = NULL; UINT64 size; @@ -452,6 +478,7 @@ static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, } else { + file->size = size; if ( file != &cfg ) { PrintStr(name); @@ -460,12 +487,9 @@ static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, 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; + efi_arch_handle_module(file, name, options); } - file->size = size; ret = FileHandle->Read(FileHandle, &file->size, file->ptr); if ( !EFI_ERROR(ret) && file->size != size ) ret = EFI_ABORTED; @@ -536,7 +560,13 @@ static char *__init get_value(const struct file *cfg, const char *section, break; default: if ( match && strncmp(ptr, item, ilen) == 0 && ptr[ilen] == '=' ) - return ptr + ilen + 1; + { + ptr += ilen + 1; + /* strip off any leading spaces */ + while ( *ptr && isspace(*ptr) ) + ptr++; + return ptr; + } break; } ptr += strlen(ptr); @@ -544,16 +574,6 @@ static char *__init get_value(const struct file *cfg, const char *section, return NULL; } -static void __init split_value(char *s) -{ - while ( *s && isspace(*s) ) - ++s; - place_string(&mb_modules[mbi.mods_count].string, s); - while ( *s && !isspace(*s) ) - ++s; - *s = 0; -} - static void __init setup_efi_pci(void) { EFI_STATUS status; @@ -674,6 +694,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) EFI_FILE_HANDLE dir_handle; union string section = { NULL }, name; bool_t base_video = 0; + char *option_str; efi_ih = ImageHandle; efi_bs = SystemTable->BootServices; @@ -805,7 +826,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, NULL) ) break; *tail = 0; } @@ -815,7 +836,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, NULL) ) blexit(L"Configuration file not found."); pre_parse(&cfg); @@ -834,7 +855,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, NULL) ) { PrintStr(L"Chained configuration file '"); PrintStr(name.w); @@ -849,8 +870,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) efi_arch_cfg_file_early(dir_handle, section.s); - split_value(name.s); - read_file(dir_handle, s2w(&name), &kernel); + option_str = split_string(name.s); + read_file(dir_handle, s2w(&name), &kernel, option_str); efi_bs->FreePool(name.w); if ( !EFI_ERROR(efi_bs->LocateProtocol(&shim_lock_guid, NULL, @@ -861,16 +882,14 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) name.s = get_value(&cfg, section.s, "ramdisk"); if ( name.s ) { - split_value(name.s); - read_file(dir_handle, s2w(&name), &ramdisk); + read_file(dir_handle, s2w(&name), &ramdisk, NULL); efi_bs->FreePool(name.w); } name.s = get_value(&cfg, section.s, "xsm"); if ( name.s ) { - split_value(name.s); - read_file(dir_handle, s2w(&name), &xsm); + read_file(dir_handle, s2w(&name), &xsm, NULL); efi_bs->FreePool(name.w); }