From patchwork Fri Aug 5 23:04:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiper X-Patchwork-Id: 9265795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5D2F2608A1 for ; Fri, 5 Aug 2016 23:08:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48E4C2841F for ; Fri, 5 Aug 2016 23:08:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D51528462; Fri, 5 Aug 2016 23:08:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D8C89284A4 for ; Fri, 5 Aug 2016 23:08:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVoBd-0003Lf-V4; Fri, 05 Aug 2016 23:05:53 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVoBd-0003JY-2l for xen-devel@lists.xenproject.org; Fri, 05 Aug 2016 23:05:53 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id 76/B7-05127-0DB15A75; Fri, 05 Aug 2016 23:05:52 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42LpnVTnqnteemm 4wcK5+hbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bNnzNZC2b7VJz8e4mtgXGvbRcjF4eQQDuT xO4LO5m6GDmBnM+MEs076yASGxglTmz5yAThTGSUmH5rKyNIFZuAjsTFLw/ZQWwRASWJe6smg xUxCxxlkvg/+TErSEJYwFjix8cTQAkODhYBVYlps0JBTF4Bd4k7J5NAKiQEFCW6n01gA7E5gc LzNj5ngzjCTeJj93xWiBpjifa3F9kmMPItYGRYxahenFpUllqka6qXVJSZnlGSm5iZo2toYKq Xm1pcnJiempOYVKyXnJ+7iREYJgxAsIPxS7/zIUZJDiYlUd7zl5eEC/El5adUZiQWZ8QXleak Fh9ilOHgUJLgnSq1NFxIsCg1PbUiLTMHGLAwaQkOHiUR3lkgad7igsTc4sx0iNQpRl2OLQtur GUSYsnLz0uVEud1BSkSACnKKM2DGwGLnkuMslLCvIxARwnxFKQW5WaWoMq/YhTnYFQShljFk5 lXArfpFdARTEBHfLRaAnJESSJCSqqB0eftIk+B/z9WM1REK59O00j3sX3E2iGky/56Isf2hmW t34Mm3fku+jersGEmx87e9N6Dede+PL6hynf6Sbpz1xSp4geyteJra6p2X85bHsTfpPl5cdiS qWsCmqSZfn3rXmb+es/OFouX/UVGe7SuxEzxevF4j9rrry9Y27tvci284iDPeqmUSYmlOCPRU Iu5qDgRAAmHTTeZAgAA X-Env-Sender: daniel.kiper@oracle.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1470438350!41153238!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34990 invoked from network); 5 Aug 2016 23:05:51 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-15.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 Aug 2016 23:05:51 -0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u75N5ilc005475 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Aug 2016 23:05:44 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id u75N5hcS019829 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Aug 2016 23:05:44 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u75N5gTC010306; Fri, 5 Aug 2016 23:05:42 GMT Received: from olila.local.net-space.pl (/10.175.255.156) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 05 Aug 2016 16:05:42 -0700 From: Daniel Kiper To: xen-devel@lists.xenproject.org Date: Sat, 6 Aug 2016 01:04:34 +0200 Message-Id: <1470438282-4226-12-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1470438282-4226-1-git-send-email-daniel.kiper@oracle.com> References: <1470438282-4226-1-git-send-email-daniel.kiper@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] Cc: jgross@suse.com, sstabellini@kernel.org, andrew.cooper3@citrix.com, cardoe@cardoe.com, pgnet.dev@gmail.com, ning.sun@intel.com, david.vrabel@citrix.com, jbeulich@suse.com, qiaowei.ren@intel.com, richard.l.maliszewski@intel.com, gang.wei@intel.com, fu.wei@linaro.org Subject: [Xen-devel] [PATCH v4 11/19] efi: create efi_enabled() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP First of all we need to differentiate between legacy BIOS and EFI platforms during runtime, not during build, because one image will have legacy and EFI code and can be executed on both platforms. Additionally, we need more fine grained knowledge about EFI environment and check for EFI platform and EFI loader separately to properly support multiboot2 protocol. In general Xen loaded by this protocol uses memory mappings and loaded modules in similar way to Xen loaded by multiboot (v1) protocol. Hence, create efi_enabled() which checks available features in efi.flags. This patch only defines EFI_BOOT feature which is equal to old efi_enabled == 1. Subsequent patches will define EFI_LOADER and EFI_RS features accordingly. Latter one is added to ease control on runtime services usage. Suggested-by: Jan Beulich Signed-off-by: Daniel Kiper --- v4 - suggestions/fixes: - rename EFI_PLATFORM to EFI_BOOT (suggested by Jan Beulich), - move EFI_BOOT definition to efi struct definition (suggested by Jan Beulich), - remove unneeded efi.flags initialization (suggested by Jan Beulich), - use __set_bit() instead of set_bit() if possible (suggested by Jan Beulich), - do efi_enabled() cleanup (suggested by Jan Beulich), - improve comments (suggested by Jan Beulich), - improve commit message. v3 - suggestions/fixes: - define efi struct in xen/arch/x86/efi/stub.c in earlier patch (suggested by Jan Beulich), - improve comments (suggested by Jan Beulich), - improve commit message (suggested by Jan Beulich). --- xen/arch/x86/dmi_scan.c | 4 ++-- xen/arch/x86/domain_page.c | 2 +- xen/arch/x86/efi/stub.c | 4 ---- xen/arch/x86/mpparse.c | 4 ++-- xen/arch/x86/setup.c | 10 +++++----- xen/arch/x86/shutdown.c | 2 +- xen/arch/x86/time.c | 2 +- xen/common/efi/boot.c | 2 ++ xen/common/efi/runtime.c | 6 ------ xen/drivers/acpi/osl.c | 2 +- xen/include/xen/efi.h | 11 +++++++++-- 11 files changed, 24 insertions(+), 25 deletions(-) diff --git a/xen/arch/x86/dmi_scan.c b/xen/arch/x86/dmi_scan.c index b049e31..8dcb640 100644 --- a/xen/arch/x86/dmi_scan.c +++ b/xen/arch/x86/dmi_scan.c @@ -238,7 +238,7 @@ const char *__init dmi_get_table(paddr_t *base, u32 *len) { static unsigned int __initdata instance; - if (efi_enabled) { + if (efi_enabled(EFI_BOOT)) { if (efi_smbios3_size && !(instance & 1)) { *base = efi_smbios3_address; *len = efi_smbios3_size; @@ -696,7 +696,7 @@ static void __init dmi_decode(struct dmi_header *dm) void __init dmi_scan_machine(void) { - if ((!efi_enabled ? dmi_iterate(dmi_decode) : + if ((!efi_enabled(EFI_BOOT) ? dmi_iterate(dmi_decode) : dmi_efi_iterate(dmi_decode)) == 0) dmi_check_system(dmi_blacklist); else diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c index d86f8fe..71ade05 100644 --- a/xen/arch/x86/domain_page.c +++ b/xen/arch/x86/domain_page.c @@ -36,7 +36,7 @@ static inline struct vcpu *mapcache_current_vcpu(void) * domain's page tables but current may point at another domain's VCPU. * Return NULL as though current is not properly set up yet. */ - if ( efi_enabled && efi_rs_using_pgtables() ) + if ( efi_enabled(EFI_BOOT) && efi_rs_using_pgtables() ) return NULL; /* diff --git a/xen/arch/x86/efi/stub.c b/xen/arch/x86/efi/stub.c index 07c2bd0..3e1d1ea 100644 --- a/xen/arch/x86/efi/stub.c +++ b/xen/arch/x86/efi/stub.c @@ -4,10 +4,6 @@ #include #include -#ifndef efi_enabled -const bool_t efi_enabled = 0; -#endif - void __init efi_init_memory(void) { } void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { } diff --git a/xen/arch/x86/mpparse.c b/xen/arch/x86/mpparse.c index ef6557c..c3d5bdc 100644 --- a/xen/arch/x86/mpparse.c +++ b/xen/arch/x86/mpparse.c @@ -564,7 +564,7 @@ static inline void __init construct_default_ISA_mptable(int mpc_default_type) static __init void efi_unmap_mpf(void) { - if (efi_enabled) + if (efi_enabled(EFI_BOOT)) clear_fixmap(FIX_EFI_MPF); } @@ -722,7 +722,7 @@ void __init find_smp_config (void) { unsigned int address; - if (efi_enabled) { + if (efi_enabled(EFI_BOOT)) { efi_check_config(); return; } diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 217c775..1e8dfa5 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -438,8 +438,8 @@ static void __init parse_video_info(void) { struct boot_video_info *bvi = &bootsym(boot_vid_info); - /* The EFI loader fills vga_console_info directly. */ - if ( efi_enabled ) + /* vga_console_info is filled directly on EFI platform. */ + if ( efi_enabled(EFI_BOOT) ) return; if ( (bvi->orig_video_isVGA == 1) && (bvi->orig_video_mode == 3) ) @@ -725,7 +725,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) ) panic("dom0 kernel not specified. Check bootloader configuration."); - if ( efi_enabled ) + if ( efi_enabled(EFI_BOOT) ) { set_pdx_range(xen_phys_start >> PAGE_SHIFT, (xen_phys_start + BOOTSTRAP_MAP_BASE) >> PAGE_SHIFT); @@ -836,7 +836,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * we can relocate the dom0 kernel and other multiboot modules. Also, on * x86/64, we relocate Xen to higher memory. */ - for ( i = 0; !efi_enabled && i < mbi->mods_count; i++ ) + for ( i = 0; !efi_enabled(EFI_BOOT) && i < mbi->mods_count; i++ ) { if ( mod[i].mod_start & (PAGE_SIZE - 1) ) panic("Bootloader didn't honor module alignment request."); @@ -1077,7 +1077,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) if ( !xen_phys_start ) panic("Not enough memory to relocate Xen."); - reserve_e820_ram(&boot_e820, efi_enabled ? mbi->mem_upper : __pa(&_start), + reserve_e820_ram(&boot_e820, efi_enabled(EFI_BOOT) ? mbi->mem_upper : __pa(&_start), __pa(&_end)); /* Late kexec reservation (dynamic start address). */ diff --git a/xen/arch/x86/shutdown.c b/xen/arch/x86/shutdown.c index 3cdd4e8..7ce3761 100644 --- a/xen/arch/x86/shutdown.c +++ b/xen/arch/x86/shutdown.c @@ -119,7 +119,7 @@ void machine_halt(void) static void default_reboot_type(void) { if ( reboot_type == BOOT_INVALID ) - reboot_type = efi_enabled ? BOOT_EFI + reboot_type = efi_enabled(EFI_BOOT) ? BOOT_EFI : acpi_disabled ? BOOT_KBD : BOOT_ACPI; } diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 9707e76..b2ecc8e 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -686,7 +686,7 @@ static unsigned long get_cmos_time(void) static bool_t __read_mostly cmos_rtc_probe; boolean_param("cmos-rtc-probe", cmos_rtc_probe); - if ( efi_enabled ) + if ( efi_enabled(EFI_BOOT) ) { res = efi_get_time(); if ( res ) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 125c9ce..edd0434 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -934,6 +934,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) char *option_str; bool_t use_cfg_file; + __set_bit(EFI_BOOT, &efi.flags); + efi_init(ImageHandle, SystemTable); use_cfg_file = efi_arch_use_config_file(SystemTable); diff --git a/xen/common/efi/runtime.c b/xen/common/efi/runtime.c index 82c45bc..900c011 100644 --- a/xen/common/efi/runtime.c +++ b/xen/common/efi/runtime.c @@ -10,12 +10,6 @@ DEFINE_XEN_GUEST_HANDLE(CHAR16); #ifndef COMPAT -/* - * Currently runtime services are not implemented on ARM. To boot Xen with ACPI, - * set efi_enabled to 1, so that Xen can get the ACPI root pointer from EFI. - */ -const bool_t efi_enabled = 1; - #ifndef CONFIG_ARM # include # include diff --git a/xen/drivers/acpi/osl.c b/xen/drivers/acpi/osl.c index 9a49029..3616dfd 100644 --- a/xen/drivers/acpi/osl.c +++ b/xen/drivers/acpi/osl.c @@ -66,7 +66,7 @@ void __init acpi_os_vprintf(const char *fmt, va_list args) acpi_physical_address __init acpi_os_get_root_pointer(void) { - if (efi_enabled) { + if (efi_enabled(EFI_BOOT)) { if (efi.acpi20 != EFI_INVALID_TABLE_ADDR) return efi.acpi20; else if (efi.acpi != EFI_INVALID_TABLE_ADDR) diff --git a/xen/include/xen/efi.h b/xen/include/xen/efi.h index e74dad1..be18e4d 100644 --- a/xen/include/xen/efi.h +++ b/xen/include/xen/efi.h @@ -2,15 +2,16 @@ #define __XEN_EFI_H__ #ifndef __ASSEMBLY__ +#include #include #endif -extern const bool_t efi_enabled; - #define EFI_INVALID_TABLE_ADDR (~0UL) /* Add fields here only if they need to be referenced from non-EFI code. */ struct efi { + unsigned long flags; /* Bit fields representing available EFI features/properties */ +#define EFI_BOOT 0 /* Were we booted from EFI? */ unsigned long mps; /* MPS table */ unsigned long acpi; /* ACPI table (IA64 ext 0.71) */ unsigned long acpi20; /* ACPI table (ACPI 2.0) */ @@ -40,6 +41,12 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *); int efi_compat_get_info(uint32_t idx, union compat_pf_efi_info *); int efi_compat_runtime_call(struct compat_pf_efi_runtime_call *); +/* Test whether the above defined EFI_* bits are enabled. */ +static inline unsigned int efi_enabled(int feature) +{ + return !!test_bit(feature, &efi.flags); +} + #endif /* !__ASSEMBLY__ */ #endif /* __XEN_EFI_H__ */