From patchwork Wed Sep 24 05:03:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 37786 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 648A520792 for ; Wed, 24 Sep 2014 05:05:15 +0000 (UTC) Received: by mail-we0-f200.google.com with SMTP id w62sf2427488wes.11 for ; Tue, 23 Sep 2014 22:05:14 -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=92dQ5hjWbqZq7liswuKmgNlouqRAlkhmMuCWvJZvSJg=; b=c+E00Z+olGUVDnfjCYJ8RMzUupeoiLGOB8eIymRpLqNKQ/KJmAjFaXkLbrxh9d5zZ8 l8adT4kYvdWuEiOU0CZAtQDxClFWteX6pP/6mm5t8uAF82oRhV9PxFN3CNVaz8VUmnro 5dSLAEP6W0R6svwF/Hod2RLxUPVdZDr33Zz3wzN+bdWDwl4OBEbONklEqzzD4BBn02pD X9Cgx7IwQuSPqh1YCsFAeBIb2K+NgT6HIX+kYvICpSAbLdsCNkIpz6DQM7Qr63p+9hZX PuoYYU9GoVOVo7UBSLZV4x9xoaKcCzGDOAe4aLc530vtK2yh6Gk8AgdWTZYG5tVXVO1T lOHQ== X-Gm-Message-State: ALoCoQk1AuFeOpPwKp9pF1suv6qfiLVDPOdXt4OpvEKc2hpUAuqFdxvWjvWFJ2CARFzsSALH0KXB X-Received: by 10.194.205.34 with SMTP id ld2mr2897wjc.5.1411535114668; Tue, 23 Sep 2014 22:05:14 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.2 with SMTP id p2ls120643lag.10.gmail; Tue, 23 Sep 2014 22:05:14 -0700 (PDT) X-Received: by 10.152.26.101 with SMTP id k5mr3962899lag.74.1411535114516; Tue, 23 Sep 2014 22:05:14 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com [209.85.217.176]) by mx.google.com with ESMTPS id g1si21306266lbc.52.2014.09.23.22.05.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 23 Sep 2014 22:05:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id w7so5152028lbi.35 for ; Tue, 23 Sep 2014 22:05:14 -0700 (PDT) X-Received: by 10.152.204.231 with SMTP id lb7mr3807826lac.44.1411535114428; Tue, 23 Sep 2014 22:05:14 -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 of9csp526224lbb; Tue, 23 Sep 2014 22:05:13 -0700 (PDT) X-Received: by 10.52.175.5 with SMTP id bw5mr3199341vdc.66.1411535106418; Tue, 23 Sep 2014 22:05:06 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id t10si5279317vcf.39.2014.09.23.22.05.05 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 23 Sep 2014 22:05:06 -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 1XWejy-0006OA-V9; Wed, 24 Sep 2014 05:03:46 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XWejx-0006Lo-6Z for xen-devel@lists.xen.org; Wed, 24 Sep 2014 05:03:45 +0000 Received: from [193.109.254.147:36347] by server-1.bemta-14.messagelabs.com id BF/43-24760-FA052245; Wed, 24 Sep 2014 05:03:43 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-8.tower-27.messagelabs.com!1411535019!12635347!1 X-Originating-IP: [209.85.223.176] 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 18727 invoked from network); 24 Sep 2014 05:03:40 -0000 Received: from mail-ie0-f176.google.com (HELO mail-ie0-f176.google.com) (209.85.223.176) by server-8.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 24 Sep 2014 05:03:40 -0000 Received: by mail-ie0-f176.google.com with SMTP id ar1so10434892iec.7 for ; Tue, 23 Sep 2014 22:03:39 -0700 (PDT) X-Received: by 10.50.111.80 with SMTP id ig16mr9548057igb.43.1411535019551; Tue, 23 Sep 2014 22:03:39 -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 ig9sm3477662igb.13.2014.09.23.22.03.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Sep 2014 22:03:38 -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: Tue, 23 Sep 2014 22:03:08 -0700 Message-Id: <1411534992-27443-11-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1411534992-27443-1-git-send-email-roy.franz@linaro.org> References: <1411534992-27443-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org Subject: [Xen-devel] [PATCH for-4.5 V6 10/14] 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.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: 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 the are loaded. ucode module handling is changed to not process remainder of string after filename as options, since ucode module does not take options. Signed-off-by: Roy Franz --- xen/arch/x86/efi/efi-boot.h | 31 ++++++++++++++++-- xen/common/efi/boot.c | 77 ++++++++++++++++++++++++++++----------------- 2 files changed, 78 insertions(+), 30 deletions(-) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 32fc950..ee43cc4 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -266,8 +266,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); } } @@ -567,3 +567,30 @@ 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"ERROR Unable to allocate string buffer"); + + local_name.w = ptr; + wstrcpy(local_name.w, name); + w2s(&local_name); + + place_string(&mb_modules[mbi.mods_count].string, options); + place_string(&mb_modules[mbi.mods_count].string, ""); + 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 596c16f..4e579c6 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -56,11 +56,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; @@ -117,6 +118,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; @@ -406,9 +416,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; @@ -449,6 +475,7 @@ static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, } else { + file->size = size; if ( file != &cfg ) { PrintStr(name); @@ -457,12 +484,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; @@ -533,7 +557,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); @@ -541,16 +571,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; @@ -670,6 +690,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; @@ -801,7 +822,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; } @@ -811,7 +832,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); @@ -830,7 +851,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); @@ -845,8 +866,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, @@ -857,16 +878,16 @@ 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); + option_str = split_string(name.s); + read_file(dir_handle, s2w(&name), &ramdisk, option_str); 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); + option_str = split_string(name.s); + read_file(dir_handle, s2w(&name), &xsm, option_str); efi_bs->FreePool(name.w); }