From patchwork Wed Sep 10 00:51:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 37174 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0FA8520C93 for ; Wed, 10 Sep 2014 00:54:58 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id lx4sf774054iec.0 for ; Tue, 09 Sep 2014 17:54:57 -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=TCcfnbr72t8N5AUPnknHlCmrQKWqzJTMsFcsUEN1dBY=; b=N2LuxAntfPj1C0wDooY9+KJbUGlcYMmuQcwSknYYuIUGA/RzQug+IO8p1eGlERsOMM 5vw/GcdCJjNpM61I2MUda9HOE+cYxVTCddyIgZUZaeNP2BOQuh7bQn+vNwkINIm2yQHA kxpuUxLt4GGaAMjujwT4forD1c0w83Q39fEJL5VCaDFXfbk7sA/zHExMn1D8c2+uzj7V osyVVshxWgmnw7lR6RZgvDYz/Wdd2/LYdwLCMvOHk2DAoPOetj/1GbwpHNfvIZdDHbTN LItUzVQ8CjXuzroypI13C/RK1Yd22QDH/FJrQPmeTfIhDOpKRwkeTa513Xi471vRo6lA 5V7Q== X-Gm-Message-State: ALoCoQlhY+GduhmNhazc7tHOtXUzItJjfOwLK7H6w5GxLCkjvzaH3pz+IDQjgQiTuTVG+rQjPClx X-Received: by 10.50.25.41 with SMTP id z9mr18970816igf.2.1410310497760; Tue, 09 Sep 2014 17:54:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.18.193 with SMTP id 59ls2451274qgf.7.gmail; Tue, 09 Sep 2014 17:54:57 -0700 (PDT) X-Received: by 10.52.87.144 with SMTP id ay16mr12100253vdb.43.1410310497622; Tue, 09 Sep 2014 17:54:57 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id fh1si2814692vcb.46.2014.09.09.17.54.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Sep 2014 17:54:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id le20so3808248vcb.18 for ; Tue, 09 Sep 2014 17:54:57 -0700 (PDT) X-Received: by 10.221.26.130 with SMTP id rm2mr8672098vcb.47.1410310497519; Tue, 09 Sep 2014 17:54:57 -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 uj3csp363923vcb; Tue, 9 Sep 2014 17:54:57 -0700 (PDT) X-Received: by 10.221.49.133 with SMTP id va5mr13836293vcb.37.1410310496983; Tue, 09 Sep 2014 17:54:56 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id jz15si6401763vdb.94.2014.09.09.17.54.56 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 09 Sep 2014 17:54:56 -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 1XRW93-0006CM-4X; Wed, 10 Sep 2014 00:52:25 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XRW91-0006BR-Nu for xen-devel@lists.xen.org; Wed, 10 Sep 2014 00:52:23 +0000 Received: from [85.158.137.68:6712] by server-4.bemta-3.messagelabs.com id 4B/2E-18709-6C0AF045; Wed, 10 Sep 2014 00:52:22 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-5.tower-31.messagelabs.com!1410310340!13550906!1 X-Originating-IP: [209.85.213.180] 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 9233 invoked from network); 10 Sep 2014 00:52:22 -0000 Received: from mail-ig0-f180.google.com (HELO mail-ig0-f180.google.com) (209.85.213.180) by server-5.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 10 Sep 2014 00:52:22 -0000 Received: by mail-ig0-f180.google.com with SMTP id hn18so5537414igb.13 for ; Tue, 09 Sep 2014 17:52:20 -0700 (PDT) X-Received: by 10.42.172.195 with SMTP id o3mr13712222icz.76.1410310340534; Tue, 09 Sep 2014 17:52:20 -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 dx10sm654825igb.4.2014.09.09.17.52.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Sep 2014 17:52:19 -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, 9 Sep 2014 17:51:54 -0700 Message-Id: <1410310325-4509-5-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1410310325-4509-1-git-send-email-roy.franz@linaro.org> References: <1410310325-4509-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org Subject: [Xen-devel] [PATCH V4 04/15] Add architecture functions for pre/post ExitBootServices 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.173 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 UEFI ExitBootServices function is invoked to transition the system to the 'runtime' mode of operation, and is done right before transitioning from the EFI loader code into Xen proper. x86 does some arch specific memory management (trampoline) before exit boot services, and the code that transitions from the EFI application state to Xen is architecture specific. This patch adds two functions, one pre and one post ExitBootServices to allow each architecture to to handle these cases in a customized manner. Signed-off-by: Roy Franz --- xen/common/efi/boot.c | 50 ++---------------------------------- xen/include/asm-x86/efi-boot.h | 57 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 48 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 16ffe35..ca86beb 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -571,7 +571,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info; EFI_FILE_HANDLE dir_handle; union string section = { NULL }, name; - u64 efer; bool_t base_video = 0; UINT32 mmap_desc_ver = 0; UINTN mmap_size, mmap_desc_size, mmap_key = 0; @@ -1175,58 +1174,13 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) efi_arch_process_memory_map(SystemTable, mmap, mmap_size, mmap_desc_size, mmap_desc_ver); - if ( !trampoline_phys ) - { - if ( !cfg.addr ) - blexit(L"No memory for trampoline"); - relocate_trampoline(cfg.addr); - } + efi_arch_pre_exit_boot(); status = efi_bs->ExitBootServices(ImageHandle, mmap_key); if ( EFI_ERROR(status) ) PrintErrMesg(L"Cannot exit boot services", status); - /* Adjust pointers into EFI. */ - efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START; -#ifdef USE_SET_VIRTUAL_ADDRESS_MAP - efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START; -#endif - efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START; - efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START; - - efi_arch_relocate_image(__XEN_VIRT_START - xen_phys_start); - memcpy((void *)trampoline_phys, trampoline_start, cfg.size); - - /* Set system registers and transfer control. */ - asm volatile("pushq $0\n\tpopfq"); - rdmsrl(MSR_EFER, efer); - efer |= EFER_SCE; - if ( cpuid_ext_features & (1 << (X86_FEATURE_NX & 0x1f)) ) - efer |= EFER_NX; - wrmsrl(MSR_EFER, efer); - write_cr0(X86_CR0_PE | X86_CR0_MP | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | - X86_CR0_AM | X86_CR0_PG); - asm volatile ( "mov %[cr4], %%cr4\n\t" - "mov %[cr3], %%cr3\n\t" - "movabs $__start_xen, %[rip]\n\t" - "lgdt gdt_descr(%%rip)\n\t" - "mov stack_start(%%rip), %%rsp\n\t" - "mov %[ds], %%ss\n\t" - "mov %[ds], %%ds\n\t" - "mov %[ds], %%es\n\t" - "mov %[ds], %%fs\n\t" - "mov %[ds], %%gs\n\t" - "movl %[cs], 8(%%rsp)\n\t" - "mov %[rip], (%%rsp)\n\t" - "lretq %[stkoff]-16" - : [rip] "=&r" (efer/* any dead 64-bit variable */) - : [cr3] "r" (idle_pg_table), - [cr4] "r" (mmu_cr4_features), - [cs] "ir" (__HYPERVISOR_CS), - [ds] "r" (__HYPERVISOR_DS), - [stkoff] "i" (STACK_SIZE - sizeof(struct cpu_info)), - "D" (&mbi) - : "memory" ); + efi_arch_post_exit_boot(); for( ; ; ); /* not reached */ } diff --git a/xen/include/asm-x86/efi-boot.h b/xen/include/asm-x86/efi-boot.h index 3fe6747..518c319 100644 --- a/xen/include/asm-x86/efi-boot.h +++ b/xen/include/asm-x86/efi-boot.h @@ -535,3 +535,60 @@ static void __init efi_arch_get_memory_map(UINTN *map_size, if ( EFI_ERROR(status) ) PrintErrMesg(L"Cannot obtain memory map", status); } + +static void __init efi_arch_pre_exit_boot(void) +{ + if ( !trampoline_phys ) + { + if ( !cfg.addr ) + blexit(L"No memory for trampoline"); + relocate_trampoline(cfg.addr); + } +} + +static void __init efi_arch_post_exit_boot(void) +{ + u64 efer; + + /* Adjust pointers into EFI. */ + efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START; +#ifdef USE_SET_VIRTUAL_ADDRESS_MAP + efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START; +#endif + efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START; + efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START; + + efi_arch_relocate_image(__XEN_VIRT_START - xen_phys_start); + memcpy((void *)trampoline_phys, trampoline_start, cfg.size); + + /* Set system registers and transfer control. */ + asm volatile("pushq $0\n\tpopfq"); + rdmsrl(MSR_EFER, efer); + efer |= EFER_SCE; + if ( cpuid_ext_features & (1 << (X86_FEATURE_NX & 0x1f)) ) + efer |= EFER_NX; + wrmsrl(MSR_EFER, efer); + write_cr0(X86_CR0_PE | X86_CR0_MP | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | + X86_CR0_AM | X86_CR0_PG); + asm volatile ( "mov %[cr4], %%cr4\n\t" + "mov %[cr3], %%cr3\n\t" + "movabs $__start_xen, %[rip]\n\t" + "lgdt gdt_descr(%%rip)\n\t" + "mov stack_start(%%rip), %%rsp\n\t" + "mov %[ds], %%ss\n\t" + "mov %[ds], %%ds\n\t" + "mov %[ds], %%es\n\t" + "mov %[ds], %%fs\n\t" + "mov %[ds], %%gs\n\t" + "movl %[cs], 8(%%rsp)\n\t" + "mov %[rip], (%%rsp)\n\t" + "lretq %[stkoff]-16" + : [rip] "=&r" (efer/* any dead 64-bit variable */) + : [cr3] "r" (idle_pg_table), + [cr4] "r" (mmu_cr4_features), + [cs] "ir" (__HYPERVISOR_CS), + [ds] "r" (__HYPERVISOR_DS), + [stkoff] "i" (STACK_SIZE - sizeof(struct cpu_info)), + "D" (&mbi) + : "memory" ); +}