From: Daniel Kiper <daniel.kiper@oracle.com>
To: xen-devel@lists.xenproject.org, grub-devel@gnu.org
Cc: jgross@suse.com, keir@xen.org, ian.campbell@citrix.com,
andrew.cooper3@citrix.com, stefano.stabellini@eu.citrix.com,
roy.franz@linaro.org, ning.sun@intel.com,
david.vrabel@citrix.com, jbeulich@suse.com, phcoder@gmail.com,
qiaowei.ren@intel.com, richard.l.maliszewski@intel.com,
gang.wei@intel.com, fu.wei@linaro.org
Subject: [PATCH 18/18] x86: add multiboot2 protocol support for EFI platforms
Date: Fri, 30 Jan 2015 18:54:22 +0100 [thread overview]
Message-ID: <1422640462-28103-19-git-send-email-daniel.kiper@oracle.com> (raw)
In-Reply-To: <1422640462-28103-1-git-send-email-daniel.kiper@oracle.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
xen/arch/x86/boot/head.S | 174 +++++++++++++++++++++++++++++++++++--
xen/arch/x86/efi/efi-boot.h | 29 +++++++
xen/arch/x86/setup.c | 23 ++---
xen/arch/x86/x86_64/asm-offsets.c | 2 +
xen/common/efi/boot.c | 11 +++
5 files changed, 222 insertions(+), 17 deletions(-)
diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
index 7861057..89f5aa7 100644
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -8,6 +8,7 @@
#include <asm/page.h>
#include <asm/msr.h>
#include <asm/cpufeature.h>
+#include <asm/processor.h>
.text
.code32
@@ -57,6 +58,9 @@ ENTRY(start)
.long .Lmultiboot2_info_req_end - .Lmultiboot2_info_req
.long MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO
.long MULTIBOOT2_TAG_TYPE_MMAP
+ .long MULTIBOOT2_TAG_TYPE_EFI_BS
+ .long MULTIBOOT2_TAG_TYPE_EFI64
+ .long MULTIBOOT2_TAG_TYPE_EFI64_IH
.Lmultiboot2_info_req_end:
.align MULTIBOOT2_TAG_ALIGN
@@ -80,6 +84,19 @@ ENTRY(start)
.long 0 /* Number of the lines - no preference. */
.long 0 /* Number of bits per pixel - no preference. */
+ /* Do not disable EFI boot services. */
+ .align MULTIBOOT2_TAG_ALIGN
+ .short MULTIBOOT2_HEADER_TAG_EFI_BS
+ .short MULTIBOOT2_HEADER_TAG_OPTIONAL
+ .long 8 /* Tag size. */
+
+ /* EFI64 entry point. */
+ .align MULTIBOOT2_TAG_ALIGN
+ .short MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI64
+ .short MULTIBOOT2_HEADER_TAG_OPTIONAL
+ .long 12 /* Tag size. */
+ .long sym_phys(__efi64_start)
+
/* Multiboot2 header end tag. */
.align MULTIBOOT2_TAG_ALIGN
.short MULTIBOOT2_HEADER_TAG_END
@@ -94,6 +111,17 @@ ENTRY(start)
gdt_boot_descr:
.word 6*8-1
.long sym_phys(trampoline_gdt)
+ .long 0 /* Needed for 64-bit lgdt */
+
+cs32_switch_addr:
+ .long sym_phys(cs32_switch)
+ .long BOOT_CS32
+
+efi_st:
+ .quad 0
+
+efi_ih:
+ .quad 0
.Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!"
.Lbad_ldr_msg: .asciz "ERR: Not a Multiboot bootloader!"
@@ -124,6 +152,133 @@ print_err:
.Lhalt: hlt
jmp .Lhalt
+ .code64
+
+__efi64_start:
+ cld
+
+ /* Bootloaders may set multiboot[12].mem_lower to a nonzero value */
+ xor %edx,%edx
+
+ /* Check for Multiboot2 bootloader */
+ cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
+ je efi_multiboot2_proto
+
+ jmp not_multiboot
+
+efi_multiboot2_proto:
+ /* Skip Multiboot2 information fixed part */
+ lea MB2_fixed_sizeof(%ebx),%ecx
+
+0:
+ /* Get mem_lower from Multiboot2 information */
+ cmpl $MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO,(%ecx)
+ jne 1f
+
+ mov MB2_mem_lower(%ecx),%edx
+ jmp 4f
+
+1:
+ /* Get EFI SystemTable address from Multiboot2 information */
+ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,(%ecx)
+ jne 2f
+
+ lea MB2_efi64_st(%ecx),%esi
+ lea efi_st(%rip),%edi
+ movsq
+
+ /* Do not go into real mode on EFI platform */
+ movb $1,skip_realmode(%rip)
+
+ jmp 4f
+
+2:
+ /* Get EFI ImageHandle address from Multiboot2 information */
+ cmpl $MULTIBOOT2_TAG_TYPE_EFI64_IH,(%ecx)
+ jne 3f
+
+ lea MB2_efi64_ih(%ecx),%esi
+ lea efi_ih(%rip),%edi
+ movsq
+ jmp 4f
+
+3:
+ /* Is it the end of Multiboot2 information? */
+ cmpl $MULTIBOOT2_TAG_TYPE_END,(%ecx)
+ je run_bs
+
+4:
+ /* Go to next Multiboot2 information tag */
+ add MB2_tag_size(%ecx),%ecx
+ add $(MULTIBOOT2_TAG_ALIGN-1),%ecx
+ and $~(MULTIBOOT2_TAG_ALIGN-1),%ecx
+ jmp 0b
+
+run_bs:
+ push %rax
+ push %rdx
+
+ /* Initialize BSS (no nasty surprises!) */
+ lea __bss_start(%rip),%rdi
+ lea _end(%rip),%rcx
+ sub %rdi,%rcx
+ xor %rax,%rax
+ rep stosb
+
+ mov efi_ih(%rip),%rdi /* EFI ImageHandle */
+ mov efi_st(%rip),%rsi /* EFI SystemTable */
+ call efi_multiboot2
+
+ pop %rcx
+ pop %rax
+
+ shl $10-4,%rcx /* Convert multiboot2.mem_lower to bytes/16 */
+
+ cli
+
+ /* Initialise GDT */
+ lgdt gdt_boot_descr(%rip)
+
+ /* Reload code selector */
+ ljmpl *cs32_switch_addr(%rip)
+
+ .code32
+
+cs32_switch:
+ /* Initialise basic data segments */
+ mov $BOOT_DS,%edx
+ mov %edx,%ds
+ mov %edx,%es
+ mov %edx,%fs
+ mov %edx,%gs
+ mov %edx,%ss
+
+ mov $sym_phys(cpu0_stack)+1024,%esp
+
+ /* Disable paging */
+ mov %cr0,%edx
+ and $(~X86_CR0_PG),%edx
+ mov %edx,%cr0
+
+ push %eax
+ push %ecx
+
+ /* Disable Long Mode */
+ mov $MSR_EFER,%ecx
+ rdmsr
+ and $(~EFER_LME),%eax
+ wrmsr
+
+ pop %ecx
+ pop %eax
+
+ /* Turn off PAE */
+ mov %cr4,%edx
+ and $(~X86_CR4_PAE),%edx
+ mov %edx,%cr4
+
+ jmp trampoline_setup
+
__start:
cld
cli
@@ -151,10 +306,10 @@ __start:
multiboot1_proto:
/* Get mem_lower from Multiboot information */
testb $MBI_MEMLIMITS,(%ebx)
- jz trampoline_setup /* not available? BDA value will be fine */
+ jz bios_platform /* not available? BDA value will be fine */
mov MB_mem_lower(%ebx),%edx
- jmp trampoline_setup
+ jmp bios_platform
multiboot2_proto:
/* Skip Multiboot2 information fixed part */
@@ -166,12 +321,12 @@ multiboot2_proto:
jne 1f
mov MB2_mem_lower(%ecx),%edx
- jmp trampoline_setup
+ jmp bios_platform
1:
/* Is it the end of Multiboot2 information? */
cmpl $MULTIBOOT2_TAG_TYPE_END,(%ecx)
- je trampoline_setup
+ je bios_platform
/* Go to next Multiboot2 information tag */
add MB2_tag_size(%ecx),%ecx
@@ -179,7 +334,7 @@ multiboot2_proto:
and $~(MULTIBOOT2_TAG_ALIGN-1),%ecx
jmp 0b
-trampoline_setup:
+bios_platform:
/* Set up trampoline segment 64k below EBDA */
movzwl 0x40e,%ecx /* EBDA segment */
cmp $0xa000,%ecx /* sanity check (high) */
@@ -195,12 +350,13 @@ trampoline_setup:
* multiboot structure (if available) and use the smallest.
*/
cmp $0x100,%edx /* is the multiboot value too small? */
- jb 2f /* if so, do not use it */
+ jb trampoline_setup /* if so, do not use it */
shl $10-4,%edx
cmp %ecx,%edx /* compare with BDA value */
cmovb %edx,%ecx /* and use the smaller */
-2: /* Reserve 64kb for the trampoline */
+trampoline_setup:
+ /* Reserve 64kb for the trampoline */
sub $0x1000,%ecx
/* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
@@ -215,6 +371,9 @@ trampoline_setup:
call reloc /* %ecx contains trampoline address */
mov %eax,sym_phys(multiboot_ptr)
+ cmpb $1,sym_phys(skip_realmode)
+ je 1f
+
/* Initialize BSS (no nasty surprises!) */
mov $sym_phys(__bss_start),%edi
mov $sym_phys(_end),%ecx
@@ -222,6 +381,7 @@ trampoline_setup:
xor %eax,%eax
rep stosb
+1:
/* Interrogate CPU extended features via CPUID. */
mov $0x80000000,%eax
cpuid
diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
index 6e98bc8..f50c10a 100644
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -223,6 +223,9 @@ static void *__init efi_arch_allocate_mmap_buffer(UINTN *map_size)
static void __init efi_arch_pre_exit_boot(void)
{
+ if ( !efi_loader )
+ return;
+
if ( !trampoline_phys )
{
if ( !cfg.addr )
@@ -650,6 +653,32 @@ static bool_t __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)
return 1; /* x86 always uses a config file */
}
+void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+ EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
+ UINTN cols, gop_mode = ~0, rows;
+
+ efi_platform = 1;
+ efi_loader = 0;
+
+ efi_init(ImageHandle, SystemTable);
+
+ efi_console_set_mode();
+
+ if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
+ &cols, &rows) == EFI_SUCCESS )
+ efi_arch_console_init(cols, rows);
+
+ gop = efi_get_gop();
+ gop_mode = efi_find_gop_mode(gop, 0, 0, 0);
+ efi_arch_edd();
+ efi_tables();
+ setup_efi_pci();
+ efi_variables();
+ efi_set_gop_mode(gop, gop_mode);
+ efi_exit_boot(ImageHandle, SystemTable);
+}
+
/*
* Local variables:
* mode: C
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index aebd010..8991b12 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -663,20 +663,23 @@ void __init noreturn __start_xen(unsigned long mbi_p)
if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
panic("Misaligned CPU0 stack.");
- if ( efi_loader )
+ if ( efi_platform )
{
- set_pdx_range(xen_phys_start >> PAGE_SHIFT,
- (xen_phys_start + BOOTSTRAP_MAP_BASE) >> PAGE_SHIFT);
+ if ( efi_loader )
+ {
+ set_pdx_range(xen_phys_start >> PAGE_SHIFT,
+ (xen_phys_start + BOOTSTRAP_MAP_BASE) >> PAGE_SHIFT);
- /* Clean up boot loader identity mappings. */
- destroy_xen_mappings(xen_phys_start,
- xen_phys_start + BOOTSTRAP_MAP_BASE);
+ /* Clean up boot loader identity mappings. */
+ destroy_xen_mappings(xen_phys_start,
+ xen_phys_start + BOOTSTRAP_MAP_BASE);
- /* Make boot page tables match non-EFI boot. */
- l3_bootmap[l3_table_offset(BOOTSTRAP_MAP_BASE)] =
- l3e_from_paddr(__pa(l2_bootmap), __PAGE_HYPERVISOR);
+ /* Make boot page tables match non-EFI boot. */
+ l3_bootmap[l3_table_offset(BOOTSTRAP_MAP_BASE)] =
+ l3e_from_paddr(__pa(l2_bootmap), __PAGE_HYPERVISOR);
+ }
- memmap_type = loader;
+ memmap_type = "EFI";
}
else if ( e820_raw_nr != 0 )
{
diff --git a/xen/arch/x86/x86_64/asm-offsets.c b/xen/arch/x86/x86_64/asm-offsets.c
index ca3712f..d27596b 100644
--- a/xen/arch/x86/x86_64/asm-offsets.c
+++ b/xen/arch/x86/x86_64/asm-offsets.c
@@ -172,4 +172,6 @@ void __dummy__(void)
DEFINE(MB2_fixed_sizeof, sizeof(multiboot2_fixed_t));
OFFSET(MB2_tag_size, multiboot2_tag_t, size);
OFFSET(MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);
+ OFFSET(MB2_efi64_st, multiboot2_tag_efi64_t, pointer);
+ OFFSET(MB2_efi64_ih, multiboot2_tag_efi64_ih_t, pointer);
}
diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index f8be3dd..c5725ca 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -75,6 +75,17 @@ static size_t wstrlen(const CHAR16 * s);
static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
static bool_t match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2);
+static void efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable);
+static void efi_console_set_mode(void);
+static EFI_GRAPHICS_OUTPUT_PROTOCOL *efi_get_gop(void);
+static UINTN efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
+ UINTN cols, UINTN rows, UINTN depth);
+static void efi_tables(void);
+static void setup_efi_pci(void);
+static void efi_variables(void);
+static void efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop_mode);
+static void efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable);
+
static const EFI_BOOT_SERVICES *__initdata efi_bs;
static EFI_HANDLE __initdata efi_ih;
--
1.7.10.4
next prev parent reply other threads:[~2015-01-30 17:56 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-30 17:54 [PATCH 00/18] x86: multiboot2 protocol support Daniel Kiper
2015-01-30 17:54 ` [PATCH 01/18] x86/boot/reloc: mask out MBI_BOOTDEV from mbi flags Daniel Kiper
2015-01-30 17:59 ` [Xen-devel] " Andrew Cooper
2015-01-30 17:54 ` [PATCH 02/18] x86/boot/reloc: create generic alloc and copy functions Daniel Kiper
2015-01-30 18:02 ` Andrew Cooper
2015-02-03 10:13 ` Jan Beulich
2015-01-30 17:54 ` [PATCH 03/18] x86/boot: use %ecx instead of %eax Daniel Kiper
2015-02-03 10:02 ` Jan Beulich
2015-02-03 17:43 ` Daniel Kiper
2015-01-30 17:54 ` [PATCH 04/18] xen/x86: add multiboot2 protocol support Daniel Kiper
2015-01-30 18:11 ` Andrew Cooper
2015-02-20 16:06 ` Jan Beulich
2015-03-27 10:56 ` Daniel Kiper
2015-03-27 11:20 ` Jan Beulich
2015-03-27 12:22 ` Daniel Kiper
2015-03-27 12:42 ` Jan Beulich
2015-01-30 17:54 ` [PATCH 05/18] efi: split efi_enabled to efi_platform and efi_loader Daniel Kiper
2015-02-20 16:17 ` Jan Beulich
2015-03-27 13:32 ` Daniel Kiper
2015-03-27 13:43 ` Jan Beulich
2015-03-27 13:53 ` Andrew Cooper
2015-03-27 14:04 ` Jan Beulich
2015-03-27 14:09 ` Lennart Sorensen
2015-03-27 14:19 ` [Xen-devel] " Jan Beulich
2015-03-27 14:21 ` Lennart Sorensen
2015-03-02 17:21 ` Stefano Stabellini
2015-03-02 18:43 ` Roy Franz
2015-03-02 23:40 ` Roy Franz
2015-03-03 8:49 ` Jan Beulich
2015-01-30 17:54 ` [PATCH 06/18] x86: remove commented out stale references to efi_enabled Daniel Kiper
2015-01-30 17:54 ` [PATCH 07/18] efi: run EFI specific code on EFI platform only Daniel Kiper
2015-02-20 16:47 ` Jan Beulich
2015-01-30 17:54 ` [PATCH 08/18] efi: build xen.gz with EFI code Daniel Kiper
2015-03-02 16:14 ` Jan Beulich
2015-03-27 11:14 ` Daniel Kiper
2015-03-27 11:46 ` Jan Beulich
2015-03-27 11:54 ` Andrew Cooper
2015-01-30 17:54 ` [PATCH 09/18] efi: create efi_init() Daniel Kiper
2015-01-30 17:54 ` [PATCH 10/18] efi: create efi_console_set_mode() Daniel Kiper
2015-01-30 17:54 ` [PATCH 11/18] efi: create efi_get_gop() Daniel Kiper
2015-01-30 17:54 ` [PATCH 12/18] efi: create efi_find_gop_mode() Daniel Kiper
2015-01-30 17:54 ` [PATCH 13/18] efi: create efi_tables() Daniel Kiper
2015-01-30 17:54 ` [PATCH 14/18] efi: create efi_variables() Daniel Kiper
2015-01-30 17:54 ` [PATCH 15/18] efi: create efi_set_gop_mode() Daniel Kiper
2015-01-30 17:54 ` [PATCH 16/18] efi: create efi_exit_boot() Daniel Kiper
2015-03-02 16:45 ` Jan Beulich
2015-03-27 12:00 ` Daniel Kiper
2015-03-27 12:10 ` Jan Beulich
2015-03-27 12:43 ` Daniel Kiper
2015-03-27 13:17 ` Ian Campbell
2015-01-30 17:54 ` [PATCH 17/18] x86/efi: create new early memory allocator Daniel Kiper
2015-03-02 17:23 ` Jan Beulich
2015-03-02 20:25 ` Roy Franz
2015-03-03 8:04 ` Jan Beulich
2015-03-03 9:39 ` Daniel Kiper
2015-03-27 12:57 ` Daniel Kiper
2015-03-27 13:35 ` Jan Beulich
2015-03-27 14:28 ` Daniel Kiper
2015-01-30 17:54 ` Daniel Kiper [this message]
2015-01-30 19:06 ` [PATCH 18/18] x86: add multiboot2 protocol support for EFI platforms Andrew Cooper
2015-01-30 23:43 ` Daniel Kiper
2015-01-31 0:47 ` Andrew Cooper
2015-02-10 21:27 ` Daniel Kiper
2015-02-10 22:41 ` Andrew Cooper
2015-02-11 8:20 ` Jan Beulich
2015-02-14 17:23 ` Andrei Borzenkov
2015-02-15 21:00 ` Daniel Kiper
2015-03-17 10:32 ` Jan Beulich
2015-03-17 12:47 ` Daniel Kiper
2015-03-27 13:06 ` Daniel Kiper
2015-03-27 13:36 ` Jan Beulich
2015-03-27 14:26 ` Daniel Kiper
2015-03-27 14:34 ` Jan Beulich
2015-03-27 14:57 ` Daniel Kiper
2015-03-27 15:06 ` Jan Beulich
2015-03-27 15:10 ` Daniel Kiper
2015-01-30 18:04 ` [PATCH 00/18] x86: multiboot2 protocol support Daniel Kiper
2015-01-31 7:22 ` João Jerónimo
2015-02-02 9:28 ` Jan Beulich
2015-02-03 17:14 ` Daniel Kiper
2015-02-04 9:04 ` Andrew Cooper
2015-02-04 9:51 ` Jan Beulich
2015-02-05 10:59 ` Andrew Cooper
2015-02-05 11:50 ` Vladimir 'phcoder' Serbinenko
2015-02-05 12:00 ` Jan Beulich
2015-02-09 17:59 ` Daniel Kiper
2015-02-10 9:05 ` Jan Beulich
2015-03-03 12:10 ` Ian Campbell
2015-03-03 12:36 ` Daniel Kiper
2015-03-03 12:39 ` Ian Campbell
2015-03-03 12:51 ` Daniel Kiper
2015-03-27 10:59 ` Daniel Kiper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1422640462-28103-19-git-send-email-daniel.kiper@oracle.com \
--to=daniel.kiper@oracle.com \
--cc=andrew.cooper3@citrix.com \
--cc=david.vrabel@citrix.com \
--cc=fu.wei@linaro.org \
--cc=gang.wei@intel.com \
--cc=grub-devel@gnu.org \
--cc=ian.campbell@citrix.com \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=keir@xen.org \
--cc=ning.sun@intel.com \
--cc=phcoder@gmail.com \
--cc=qiaowei.ren@intel.com \
--cc=richard.l.maliszewski@intel.com \
--cc=roy.franz@linaro.org \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).