From patchwork Mon Sep 8 03:53:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 36933 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 BFF9C20491 for ; Mon, 8 Sep 2014 03:56:14 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id rd3sf9538020pab.6 for ; Sun, 07 Sep 2014 20:56: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=qEXGpaiboazXFymrcCEuuBmBKkwae6FSoOlzPzjSFZc=; b=KCUyeisTc34MGTYTasFFNLYA+UbzrYxRgvn8ONQlxhI5qsOJnUbarBvTvgeRGuogb5 NN9GmsADaFyEMwfqZXNpBjY0j5b5uZxdoNb/w5zpSSlTeAlUCv6T+fo9FRNhfVLgntns k8DNu/yrtiIrbSHRJiuQFEKa/HaYLjnHXMeL4NVes0Afauysejf+LHWPmvC7lGEj0BYJ g+NY4ZqzvxfvsEvrYL3TDPA7n5xqwCu4HaNOFjJARZI/Kr/6IecOWgplbKVZOKkuczlp 3vSzPEA3EbBD+uWd9ZRNxsV4EYcSO4bpe709CHgqdR3YT1tZC5aE/xfAfHHpt+P5+euK g1yQ== X-Gm-Message-State: ALoCoQkMj/+CZAKovfyySIJJlxUxa4CNNIflTdeZcyfLZzuX+LnmKWp8j36pMu4+4PN4hQyvi87t X-Received: by 10.66.196.193 with SMTP id io1mr2430318pac.28.1410148574048; Sun, 07 Sep 2014 20:56:14 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.37.35 with SMTP id q32ls1581051qgq.50.gmail; Sun, 07 Sep 2014 20:56:13 -0700 (PDT) X-Received: by 10.221.49.133 with SMTP id va5mr3898080vcb.37.1410148573908; Sun, 07 Sep 2014 20:56:13 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id tj2si3497452vcb.64.2014.09.07.20.56.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 07 Sep 2014 20:56:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id id10so14734274vcb.16 for ; Sun, 07 Sep 2014 20:56:13 -0700 (PDT) X-Received: by 10.52.97.233 with SMTP id ed9mr19759470vdb.16.1410148573687; Sun, 07 Sep 2014 20:56:13 -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.45.67 with SMTP id uj3csp76446vcb; Sun, 7 Sep 2014 20:56:13 -0700 (PDT) X-Received: by 10.224.60.129 with SMTP id p1mr5209180qah.99.1410148573071; Sun, 07 Sep 2014 20:56:13 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id y1si9791686qal.18.2014.09.07.20.56.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 07 Sep 2014 20:56:13 -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 1XQq2H-00074U-GW; Mon, 08 Sep 2014 03:54:37 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XQq2E-0006yz-P7 for xen-devel@lists.xen.org; Mon, 08 Sep 2014 03:54:35 +0000 Received: from [85.158.137.68:5896] by server-4.bemta-3.messagelabs.com id 61/3E-18709-6782D045; Mon, 08 Sep 2014 03:54:30 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-6.tower-31.messagelabs.com!1410148468!8565593!1 X-Originating-IP: [209.85.220.42] 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 4992 invoked from network); 8 Sep 2014 03:54:29 -0000 Received: from mail-pa0-f42.google.com (HELO mail-pa0-f42.google.com) (209.85.220.42) by server-6.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 8 Sep 2014 03:54:29 -0000 Received: by mail-pa0-f42.google.com with SMTP id lj1so923765pab.29 for ; Sun, 07 Sep 2014 20:54:27 -0700 (PDT) X-Received: by 10.70.118.68 with SMTP id kk4mr25702086pdb.21.1410148467610; Sun, 07 Sep 2014 20:54:27 -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 qy1sm7524053pbc.27.2014.09.07.20.54.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Sep 2014 20:54:27 -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: Sun, 7 Sep 2014 20:53:55 -0700 Message-Id: <1410148441-18684-10-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1410148441-18684-1-git-send-email-roy.franz@linaro.org> References: <1410148441-18684-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org, linaro-uefi@lists.linaro.org Subject: [Xen-devel] [PATCH V3 09/15] 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.220.171 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. Signed-off-by: Roy Franz --- xen/common/efi/boot.c | 98 +++++++++++++++++++++++------------------- xen/include/asm-x86/efi-boot.h | 15 +++++-- 2 files changed, 66 insertions(+), 47 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 9ee3b4a..5296d88 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -51,11 +51,10 @@ static void __init DisplayUint(UINT64 Val, INTN Width); static CHAR16 *__init wstrcpy(CHAR16 *d, const CHAR16 *s); static char *__init get_value(const struct file *cfg, const char *section, const char *item); -static void __init split_value(char *s); static CHAR16 *__init s2w(union string *str); static char *__init w2s(const union string *str); -static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, - struct file *file); +static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, struct file *file, + char *name_options); static EFI_BOOT_SERVICES *__initdata efi_bs; static EFI_HANDLE __initdata efi_ih; @@ -398,18 +397,39 @@ static CHAR16 *__init point_tail(CHAR16 *fn) break; } } +/* + * Truncate string at first space, and return pointer + * to remainder of string. + */ +static char * __init truncate_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) +static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, struct file *file, + char *name_options) { EFI_FILE_HANDLE FileHandle = NULL; UINT64 size; EFI_STATUS ret; CHAR16 *what = NULL; + char *options; + union string name; + + options = truncate_string(name_options); - if ( !name ) + name.s=name_options; + s2w(&name); + if ( !name.w ) PrintErrMesg(L"No filename", EFI_OUT_OF_RESOURCES); - ret = dir_handle->Open(dir_handle, &FileHandle, name, + ret = dir_handle->Open(dir_handle, &FileHandle, name.w, EFI_FILE_MODE_READ, 0); if ( file == &cfg && ret == EFI_NOT_FOUND ) return 0; @@ -441,20 +461,18 @@ static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, } else { + file->size = size; if ( file != &cfg ) { - PrintStr(name); + PrintStr(name.w); 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; + efi_arch_handle_module(file, name_options, options); } - file->size = size; ret = FileHandle->Read(FileHandle, &file->size, file->ptr); if ( !EFI_ERROR(ret) && file->size != size ) ret = EFI_ABORTED; @@ -469,7 +487,7 @@ static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, { PrintErr(what); PrintErr(L" failed for "); - PrintErrMesg(name, ret); + PrintErrMesg(name.w, ret); } return 1; @@ -525,7 +543,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); @@ -533,16 +557,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; -} - void EFIAPI __init noreturn efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { @@ -552,14 +566,14 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) EFI_LOADED_IMAGE *loaded_image; EFI_STATUS status; unsigned int i, argc; - CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL; + CHAR16 **argv, *options = NULL; UINTN cols, rows, depth, size, info_size; EFI_HANDLE *handles = NULL; EFI_SHIM_LOCK_PROTOCOL *shim_lock; EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL; EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info; EFI_FILE_HANDLE dir_handle; - union string section = { NULL }, name; + union string section = { NULL }, name, file_name, cfg_file_name = {NULL}; bool_t base_video = 0; UINT32 mmap_desc_ver = 0; UINTN mmap_size, mmap_desc_size, mmap_key = 0; @@ -590,7 +604,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) trampoline_xen_phys_start = xen_phys_start; /* Get the file system interface. */ - dir_handle = get_parent_handle(loaded_image, &file_name); + dir_handle = get_parent_handle(loaded_image, &file_name.w); argc = get_argv(0, NULL, loaded_image->LoadOptions, loaded_image->LoadOptionsSize, &options); @@ -614,9 +628,9 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) if ( wstrcmp(ptr + 1, L"basevideo") == 0 ) base_video = 1; else if ( wstrncmp(ptr + 1, L"cfg=", 4) == 0 ) - cfg_file_name = ptr + 5; + cfg_file_name.w = ptr + 5; else if ( i + 1 < argc && wstrcmp(ptr + 1, L"cfg") == 0 ) - cfg_file_name = argv[++i]; + cfg_file_name.w = argv[++i]; else if ( wstrcmp(ptr + 1, L"help") == 0 || (ptr[1] == L'?' && !ptr[2]) ) { @@ -684,24 +698,26 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) gop = NULL; /* Read and parse the config file. */ - if ( !cfg_file_name ) + if ( !cfg_file_name.w ) { CHAR16 *tail; - while ( (tail = point_tail(file_name)) != NULL ) + while ( (tail = point_tail(file_name.w)) != NULL ) { wstrcpy(tail, L".cfg"); - if ( read_file(dir_handle, file_name, &cfg) ) + if ( read_file(dir_handle, &cfg, w2s(&file_name)) ) break; *tail = 0; } if ( !tail ) blexit(L"No configuration file found."); PrintStr(L"Using configuration file '"); - PrintStr(file_name); + s2w(&file_name); + PrintStr(file_name.w); PrintStr(L"'\r\n"); + efi_bs->FreePool(file_name.w); } - else if ( !read_file(dir_handle, cfg_file_name, &cfg) ) + else if ( !read_file(dir_handle, &cfg, w2s(&cfg_file_name)) ) blexit(L"Configuration file not found."); pre_parse(&cfg); @@ -720,7 +736,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, &cfg, name.s) ) { PrintStr(L"Chained configuration file '"); PrintStr(name.w); @@ -735,9 +751,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) efi_arch_cfg_file(dir_handle, section.s); - split_value(name.s); - read_file(dir_handle, s2w(&name), &kernel); - efi_bs->FreePool(name.w); + read_file(dir_handle, &kernel, name.s); if ( !EFI_ERROR(efi_bs->LocateProtocol(&shim_lock_guid, NULL, (void **)&shim_lock)) && @@ -747,17 +761,13 @@ 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); - efi_bs->FreePool(name.w); + read_file(dir_handle, &ramdisk, name.s); } name.s = get_value(&cfg, section.s, "xsm"); if ( name.s ) { - split_value(name.s); - read_file(dir_handle, s2w(&name), &xsm); - efi_bs->FreePool(name.w); + read_file(dir_handle, &xsm, name.s); } cols = rows = depth = 0; diff --git a/xen/include/asm-x86/efi-boot.h b/xen/include/asm-x86/efi-boot.h index e1cbdfc..5684562 100644 --- a/xen/include/asm-x86/efi-boot.h +++ b/xen/include/asm-x86/efi-boot.h @@ -601,9 +601,7 @@ static void __init efi_arch_cfg_file(EFI_FILE_HANDLE dir_handle, char *section) if ( name.s ) { microcode_set_module(mbi.mods_count); - split_value(name.s); - read_file(dir_handle, s2w(&name), &ucode); - efi_bs->FreePool(name.w); + read_file(dir_handle, &ucode, name.s); } } static void __init efi_arch_handle_cmdline(CHAR16 *image_name, @@ -972,3 +970,14 @@ static void __init efi_arch_memory(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, char *name, + char *options) +{ + 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, name); + mb_modules[mbi.mods_count].mod_start = file->addr >> PAGE_SHIFT; + mb_modules[mbi.mods_count].mod_end = file->size; + ++mbi.mods_count; +}