arm64 EFI stub
v6 cover arm64 EFI stub
This patch series adds EFI boot support for arm64. A PE/COFF header is created in head.S, as there is no toolchain support for PE/COFF on arm64. This also has the advantage that the file is both an "Image" file and a PE/COFF executable - the same binary can be loaded and run either way. The EFI 'stub' code is a shim layer that serves as the loader for the XEN kernel in the EFI environment. The stub loads the dom0 kernel and initrd if required, and adds entries for them as well as for the EFI data structures into the device tree passed to XEN. Once the device tree is constructed, EFI boot services are exited, and the stub transfers control to the normal XEN entry point. The only indication XEN has that it was loaded via the stub is that the device tree contains EFI properties. This is all very similar to the arm/arm64 Linux kernel EFI stubs.
Open feedback:
* moving extern declaration of efi_l4_pgtable. I have left this x86 specific declaration in the x86 specific efi-boot.h file, as I don't see a clearly better place to put it.
Changes since v5:
* FDT and ARM cache flushing patches removed, as those have been applied to master branch
* rebased to master that includes above changesets.
* Added new patch fixing bug in PCI rom scan code.
(separate patch since it is a bug fix)
* efi-boot.h files moved from global include directories to arch/*/efi directories, as that is the only place they are used.
* removed redundant newlines in blexit() calls
* removed uneccessary initializers.
* reverted string variable changes that where left over from other reverted changes.
* removed local memory map variables, no longer required.
* made symlinks from commone/efi relative
* simplify get_argv() call with NULL parameter
* rename efi_arch_memory to efi_arch_memory_setup
* fixed type of local 'i' variable in new arch functions. reviewed other local variables.
* fixed wstrlen coding style
* various formatting fixes - init ordering, remove declration reordering, blank lines, etc.
* moved x86 externs to appropriate global includes.
* fixed XXX placeholder in comments
* simplified ucode file handling, ignore anything after filename, as options not supported
* Added Acked-by lines for patches fully acked, or where minor changes were requested and made.
Changes since v4:
* Move runtime.c/compat.c/efi.h from arch/x86/efi to common/efi
* Create symbolic links at build time from common/efi to arch/xxx/efi
* Moved all non-VGA video code back to boot.c
* Cleaned up __init in forward declarations, moved declarations to common file
* Fixed type of i in efi_arch_process_memory_map()
* Added early/late arch cfg file functions - arm64 needs early, x86 wants late.
* Added #ifdefs to disable runtime services code that is not yet implemented for ARM (code moved back from arch specific file.)
Global variables are left, as this allows common code setting these in boot code to be left.
* just provide arch specific allocator for EFI memory map, not function returning the map.
* Renamed truncate_string() to split_string()
* Fixed up MBI static inilization comments in moved code.
* Added explanation of ARM config file ordering requirement to commit message and code.
* Added explanation of increase of NR_MEM_BANKS
* Variety of minor formating cleanups.
* Remove mem-reserve regions from DTB in addition to the memory banks. The EFI memory map is the only memory description that is used.
Changes since v3:
* Add symbolic link from common/efi/boot.c to arch/x86/efi/boot.c. This simplifies the build system changes and resolves the parallel build issues in v3. x86 EFI code build is unchanged, and ARM EFI code uses the normal common build structure. (This symlink seems to have confused git's moved file detection for boot.c)
* Fix XEN to be Xen throughout
* Fix spacing and missing blank lines between functions
* Add pseudo-prototype of efi_xen_start is head.S, change prototype to take pointer instead of integer to avoid cast, add comment explaining saving of x0
* Use uintptr_t in casts from uint to pointer for device tree.
* Change alignment requirements to 4k in PE/COFF header and alignment check in code.
* Rebased to latest master branch.
Changes since v2:
* Major refactor to use common EFI entry point and factor out arch specific code, rather than factoring out the common code.
* Update entire libfdt to v1.4.0 to provide fdt_create_empty_tree()
Changes since v1:
* Added common/efi directory for shared EFI code, and arch/arm/efi for arm-specfic code. Global build hacking of -fshort-wchar removed. arm32, arm64, and x86 with/without EFI enabled toolchain all build. The x86 build previously autodetected whether the EFI version should be built or not based on toolchain support. I couldn't get this working nicely with the common code, so for x86 I have the common code always build, and the EFI autodection works as normal for building the EFI version.
* Basic use of the EFI memory map instead of FDT based memory description. More work needed to resolve differences between FDT description of a small number of large memory banks with reserved regions, and EFI's potentially long list of available regions, which can be long.
* More refactoring of common EFI code to not directly exit using blexit(), as this broke the pre-linking targets. All shared code returns status, and it is up to the caller to exit and clean up.
* Reduced the number of patches. Refactoring of x86 code first, then moving all code to efi-shared.c in one patch.
* Fixed formatting/tab issues in new files, added Emacs footer.
* Fixed efi_get_memory_map to return NULL map pointer on error in addition to failed status.
* Added comments in head.S regarding PE/COFF specification, and 1:1 mapping used by EFI code.
* Updated device tree bindings to use new multiboot bindings. Since the stub is always built into XEN, we don't have to support older bindings.
Roy Franz (14):
move x86 EFI boot/runtime code to common/efi
Move x86 specific funtions/variables to arch header
create arch functions to allocate memory for and process EFI memory
map.
Add architecture functions for pre/post ExitBootServices Add efi_arch_cfg_file_early/late() to handle arch specific cfg file
fields
Add efi_arch_handle_cmdline() for processing commandline Move x86 specific disk probing code
Create arch functions for console and video init
Add efi_arch_memory() for arch specific memory setup
Add arch specific module handling to read_file()
Add several misc. arch functions for EFI boot code.
Add efi_arch_use_config_file() function to control use of config file Fix freeing of uninitialized pointer
Add ARM EFI boot support
.gitignore | 8 +
xen/Makefile | 4 +
xen/arch/arm/Makefile | 1 +
xen/arch/arm/arm64/head.S | 150 +++++-
xen/arch/arm/efi/Makefile | 4 +
xen/arch/arm/efi/efi-boot.h | 593 ++++++++++++++++++++++++
xen/arch/arm/xen.lds.S | 1 +
xen/arch/x86/efi/efi-boot.h | 637 ++++++++++++++++++++++++++
xen/{arch/x86 => common}/efi/boot.c | 810 ++++++++-------------------------
xen/{arch/x86 => common}/efi/compat.c | 0
xen/{arch/x86 => common}/efi/efi.h | 2 -
xen/{arch/x86 => common}/efi/runtime.c | 15 +-
xen/include/asm-arm/arm64/efibind.h | 216 +++++++++
xen/include/asm-arm/efibind.h | 2 +
xen/include/asm-arm/setup.h | 2 +-
xen/include/asm-x86/processor.h | 1 +
xen/include/xen/kernel.h | 2 +-
17 files changed, 1818 insertions(+), 630 deletions(-)
create mode 100644 xen/arch/arm/efi/Makefile
create mode 100644 xen/arch/arm/efi/efi-boot.h
create mode 100644 xen/arch/x86/efi/efi-boot.h
rename xen/{arch/x86 => common}/efi/boot.c (59%)
rename xen/{arch/x86 => common}/efi/compat.c (100%)
rename xen/{arch/x86 => common}/efi/efi.h (95%)
rename xen/{arch/x86 => common}/efi/runtime.c (98%)
create mode 100644 xen/include/asm-arm/arm64/efibind.h
create mode 100644 xen/include/asm-arm/efibind.hSignature · 1 line
2.1.0
PATCH v6 1/14 move x86 EFI boot/runtime code to common/efi
This moves the EFI boot and runtime services code to the common/efi directory. This code is symbolicly linked back into the arch/x86/efi directory where it is built if a build-time check for PE/COFF support in the toolchain passes. In the PE/COFF supporting case, both the EFI executable and the normal Xen image (with stubbed EFI functions) are built. We can't use the normal common build infrastructure since we are building two versions at the same time, with different EFI related code in each. No code changes, just file movement and make updates. The files are symbolicly linked at build time back toe the original arch/x86/efi directory. This is in preparation for adding ARM EFI support where much of these files can be shared.
---
.gitignore | 4 ++++
xen/Makefile | 4 ++++
xen/{arch/x86 => common}/efi/boot.c | 0
xen/{arch/x86 => common}/efi/compat.c | 0
xen/{arch/x86 => common}/efi/efi.h | 0
xen/{arch/x86 => common}/efi/runtime.c | 0
6 files changed, 8 insertions(+)
rename xen/{arch/x86 => common}/efi/boot.c (100%)
rename xen/{arch/x86 => common}/efi/compat.c (100%)
rename xen/{arch/x86 => common}/efi/efi.h (100%)
rename xen/{arch/x86 => common}/efi/runtime.c (100%).gitignore +4 -0
@@ -254,6 +254,10 @@ xen/arch/x86/efi.lds xen/arch/x86/efi/check.efi xen/arch/x86/efi/disabled xen/arch/x86/efi/mkreloc +xen/arch/x86/efi/boot.c +xen/arch/x86/efi/runtime.c +xen/arch/x86/efi/compat.c +xen/arch/x86/efi/efi.h xen/ddb/* xen/include/headers.chk xen/include/asm
xen/Makefile +4 -0
@@ -100,6 +100,10 @@ $(TARGET): delete-unfresh-files $(MAKE) -C tools $(MAKE) -f $(BASEDIR)/Rules.mk include/xen/compile.h [ -e include/asm ] || ln -sf asm-$(TARGET_ARCH) include/asm + [ -e arch/$(TARGET_ARCH)/efi ] && ln -nsf ../../../common/efi/boot.c arch/$(TARGET_ARCH)/efi/;\ + ln -nsf ../../../common/efi/runtime.c arch/$(TARGET_ARCH)/efi/;\ + ln -nsf ../../../common/efi/compat.c arch/$(TARGET_ARCH)/efi/;\ + ln -nsf ../../../common/efi/efi.h arch/$(TARGET_ARCH)/efi/; $(MAKE) -f $(BASEDIR)/Rules.mk -C include $(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) asm-offsets.s $(MAKE) -f $(BASEDIR)/Rules.mk include/asm-$(TARGET_ARCH)/asm-offsets.h
xen/common/efi/boot.c renamed from xen/arch/x86/efi/boot.c +0 -0
xen/common/efi/compat.c renamed from xen/arch/x86/efi/compat.c +0 -0
xen/common/efi/efi.h renamed from xen/arch/x86/efi/efi.h +0 -0
xen/common/efi/runtime.c renamed from xen/arch/x86/efi/runtime.c +0 -0
Signature · 1 line
2.1.0
Re: [PATCH for-4.5 V6 01/14] move x86 EFI boot/runtime code to common/efi
xen/Makefile $(TARGET): delete-unfresh-files · line 106
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 07:02, <[email protected]> wrote:
xen/Makefile +4
-0@@ -100,6 +100,10 @@ $(TARGET): delete-unfresh-files $(MAKE) -C tools $(MAKE) -f $(BASEDIR)/Rules.mk include/xen/compile.h [ -e include/asm ] || ln -sf asm-$(TARGET_ARCH) include/asm + [ -e arch/$(TARGET_ARCH)/efi ] && ln -nsf ../../../common/efi/boot.c arch/$(TARGET_ARCH)/efi/;\ + ln -nsf ../../../common/efi/runtime.c arch/$(TARGET_ARCH)/efi/;\ + ln -nsf ../../../common/efi/compat.c arch/$(TARGET_ARCH)/efi/;\ + ln -nsf ../../../common/efi/efi.h arch/$(TARGET_ARCH)/efi/;
I don't think this does what you want: The && applies only to the first ln invocation, the others will be done unconditionally. And this would be better done with "for f in boot.c runtime.c ..." anyway, at which point the issue magically disappears.
Furthermore (I'm sorry for not paying attention to the before) you shouldn't use && in make rules without some extra care: If the left side evaluates to false, the whole compound command (and hence the make rule) will fail. Either use || or invoke /bin/true as last operation.
Jan
Re: [PATCH for-4.5 V6 01/14] move x86 EFI boot/runtime code to common/efi
Quoted 17 lines · Jan Beulich
xen/Makefile $(TARGET): delete-unfresh-files · line 106
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 07:02, <[email protected]> wrote:
xen/Makefile +4
-0@@ -100,6 +100,10 @@ $(TARGET): delete-unfresh-files $(MAKE) -C tools $(MAKE) -f $(BASEDIR)/Rules.mk include/xen/compile.h [ -e include/asm ] || ln -sf asm-$(TARGET_ARCH) include/asm + [ -e arch/$(TARGET_ARCH)/efi ] && ln -nsf ../../../common/efi/boot.c arch/$(TARGET_ARCH)/efi/;\ + ln -nsf ../../../common/efi/runtime.c arch/$(TARGET_ARCH)/efi/;\ + ln -nsf ../../../common/efi/compat.c arch/$(TARGET_ARCH)/efi/;\ + ln -nsf ../../../common/efi/efi.h arch/$(TARGET_ARCH)/efi/;I don't think this does what you want: The && applies only to the first ln invocation, the others will be done unconditionally. And this would be better done with "for f in
boot.cruntime.c..." anyway, at which point the issue magically disappears.
Quoted 8 lines
Furthermore (I'm sorry for not paying attention to the before) you shouldn't use && in make rules without some extra care: If the left side evaluates to false, the whole compound command (and hence the make rule) will fail. Either use || or invoke
/bin/trueas last operation.Jan
I had overlooked that effect of the failure - I'll redo this as a for loop.
thanks,
Roy
PATCH v6 2/14 Move x86 specific funtions/variables to arch header
In reply to Roy FranzMove the global variables and functions that can be moved as-is from the common boot.c file to the x86 implementation header file.
--- xen/arch/x86/efi/efi-boot.h | 132 +++++++++++++++++++++++++++++++++++ xen/common/efi/boot.c | 148 ++++------------------------------------ xen/include/asm-x86/processor.h | 1 + xen/include/xen/kernel.h | 2 +- 4 files changed, 149 insertions(+), 134 deletions(-) create mode 100644 xen/arch/x86/efi/efi-boot.h
xen/arch/x86/efi/efi-boot.h new file +132 -0
@@ -0,0 +1,132 @@ +/* +* Architecture specific implementation for EFI boot code. This file +* is intended to be included by common/efi/boot.c _only_, and +* therefore can define arch specific global variables. +*/ +#include <asm/e820.h> +#include <asm/edd.h> +#define __ASSEMBLY__/* avoid pulling in ACPI stuff (conflicts with EFI) */ +#include <asm/fixmap.h> +#undef __ASSEMBLY__ +#include <asm/msr.h> +#include <asm/processor.h> + +static struct file __initdata ucode; +static multiboot_info_t __initdata mbi = { + .flags =MBI_MODULES |MBI_LOADERNAME +}; +static module_t __initdata mb_modules[3 ]; + +static void __init edd_put_string (u8 *dst,size_t n,const char *src) +{ +while ( n-- && *src ) + *dst++ = *src++; +if ( *src ) +PrintErrMesg (L"Internal error populating EDD info" , +EFI_BUFFER_TOO_SMALL ); +while ( n-- ) + *dst++ =' ' ; +} +#define edd_put_string (d, s) edd_put_string(d, ARRAY_SIZE(d), s) + +extern const intpte_t __page_tables_start[], __page_tables_end[]; +#define in_page_tables (v) ((intpte_t *)(v) >= __page_tables_start && \ + (intpte_t *)(v) < __page_tables_end) + +#define PE_BASE_RELOC_ABS 0 +#define PE_BASE_RELOC_HIGHLOW 3 +#define PE_BASE_RELOC_DIR64 10 + +extern const struct pe_base_relocs { +u32 rva; +u32 size; +u16 entries[]; +} __base_relocs_start[], __base_relocs_end[]; + +static void __init efi_arch_relocate_image (unsigned long delta) +{ +const struct pe_base_relocs *base_relocs; + +for ( base_relocs = __base_relocs_start; base_relocs < __base_relocs_end; ) + { +unsigned int i, n; + + n = (base_relocs->size -sizeof (*base_relocs)) / +sizeof (*base_relocs->entries); +for ( i =0 ; i < n; ++i ) + { +unsigned long addr = xen_phys_start + base_relocs->rva + + (base_relocs->entries[i] &0xfff ); + +switch ( base_relocs->entries[i] >>12 ) + { +case PE_BASE_RELOC_ABS : +break ; +case PE_BASE_RELOC_HIGHLOW : +if ( delta ) + { + *(u32 *)addr += delta; +if (in_page_tables (addr) ) + *(u32 *)addr += xen_phys_start; + } +break ; +case PE_BASE_RELOC_DIR64 : +if ( delta ) + { + *(u64 *)addr += delta; +if (in_page_tables (addr) ) + *(intpte_t *)addr += xen_phys_start; + } +break ; +default : +blexit (L"Unsupported relocation type" ); + } + } + base_relocs = (const void *)(base_relocs->entries + i + (i &1 )); + } +} + +extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[]; +extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[]; + +static void __init relocate_trampoline (unsigned long phys) +{ +const s32 *trampoline_ptr; + + trampoline_phys = phys; +/* Apply relocations to trampoline. */ +for ( trampoline_ptr = __trampoline_rel_start; + trampoline_ptr < __trampoline_rel_stop; + ++trampoline_ptr ) + *(u32 *)(*trampoline_ptr + (long )trampoline_ptr) += phys; +for ( trampoline_ptr = __trampoline_seg_start; + trampoline_ptr < __trampoline_seg_stop; + ++trampoline_ptr ) + *(u16 *)(*trampoline_ptr + (long )trampoline_ptr) = phys >>4 ; +} + +static void __init place_string (u32 *addr,const char *s) +{ +static char *__initdata alloc = start; + +if ( s && *s ) + { +size_t len1 =strlen (s) +1 ; +const char *old = (char *)(long )*addr; +size_t len2 = *addr ?strlen (old) +1 :0 ; + + alloc -= len1 + len2; +/* +* Insert new string before already existing one. This is needed +* for options passed on the command line to override options from +* the configuration file. +*/ +memcpy (alloc, s, len1); +if ( *addr ) + { + alloc[len1 -1 ] =' ' ; +memcpy (alloc + len1, old, len2); + } + } + *addr = (long )alloc; +}
xen/common/efi/boot.c +15 -133
208 lines not on this page · raw message
xen/include/asm-x86/processor.h +1 -0
@@ -199,6 +199,7 @@ extern void set_cpuid_faulting(bool_t enable);extern u64 host_pat;extern bool_t opt_cpu_info; +extern u32 cpuid_ext_features;/* Maximum width of physical addresses supported by the hardware */ extern unsigned int paddr_bits;
xen/include/xen/kernel.h +1 -1
@@ -65,7 +65,7 @@1 ; \ }) -extern char _start[], _end[]; +extern char _start[], _end[], start[];#define is_kernel (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _start) && (__p < _end); \
Signature · 1 line
2.1.0
Re: [PATCH for-4.5 V6 02/14] Move x86 specific funtions/variables to arch header
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 07:03, <[email protected]> wrote:
xen/arch/x86/efi/efi-boot.h line 10
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h new file +10
-0@@ -0,0 +1,132 @@ +/* +* Architecture specific implementation for EFI boot code. This file +* is intended to be included by common/efi/boot.c _only_, and +* therefore can define arch specific global variables. +*/ +#include <asm/e820.h> +#include <asm/edd.h> +#define __ASSEMBLY__/* avoid pulling in ACPI stuff (conflicts with EFI) */ +#include <asm/fixmap.h> +#undef __ASSEMBLY__
Just noticed this: Moving this here makes things even more fragile than they are now: If asm/fixmap.h happens to be included by any other header processed prior to reaching this point, the whole effect will be gone. Please keep this in the original place (with an #ifdef and comment as to why).
With that adjusted
Jan
Re: [PATCH for-4.5 V6 02/14] Move x86 specific funtions/variables to arch header
Quoted 21 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 07:03, <[email protected]> wrote:
xen/arch/x86/efi/efi-boot.h line 10
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h new file +10
-0@@ -0,0 +1,132 @@ +/* +* Architecture specific implementation for EFI boot code. This file +* is intended to be included by common/efi/boot.c _only_, and +* therefore can define arch specific global variables. +*/ +#include <asm/e820.h> +#include <asm/edd.h> +#define __ASSEMBLY__/* avoid pulling in ACPI stuff (conflicts with EFI) */ +#include <asm/fixmap.h> +#undef __ASSEMBLY__Just noticed this: Moving this here makes things even more fragile than they are now: If
asm/fixmap.hhappens to be included by any other header processed prior to reaching this point, the whole effect will be gone. Please keep this in the original place (with an #ifdef and comment as to why).
Quoted 5 lines
With that adjusted
Acked-by Jan Beulich <[email protected]>Jan
OK, I'll move that. Just to clarify, it's just the
Quoted 3 lines
xen/arch/x86/efi/efi-boot.h line 10
Quoted 3 lines
xen/arch/x86/efi/efi-boot.h new file +3
-0+#define __ASSEMBLY__/* avoid pulling in ACPI stuff (conflicts with EFI) */ +#include <asm/fixmap.h> +#undef __ASSEMBLY__
that should be moved.
Roy
Re: [PATCH for-4.5 V6 02/14] Move x86 specific funtions/variables to arch header
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 21:45, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 07:03, <[email protected]> wrote:
xen/arch/x86/efi/efi-boot.h line 10
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h new file +10
-0@@ -0,0 +1,132 @@ +/* +* Architecture specific implementation for EFI boot code. This file +* is intended to be included by common/efi/boot.c _only_, and +* therefore can define arch specific global variables. +*/ +#include <asm/e820.h> +#include <asm/edd.h> +#define __ASSEMBLY__/* avoid pulling in ACPI stuff (conflicts with EFI) */ +#include <asm/fixmap.h> +#undef __ASSEMBLY__Just noticed this: Moving this here makes things even more fragile than they are now: If
asm/fixmap.hhappens to be included by any other header processed prior to reaching this point, the whole effect will be gone. Please keep this in the original place (with an #ifdef and comment as to why).Quoted 2 lines
With that adjusted
Acked-by Jan Beulich <[email protected]>
Quoted 7 lines
OK, I'll move that. Just to clarify, it's just the
Quoted 3 lines
xen/arch/x86/efi/efi-boot.h line 10
Quoted 3 lines
xen/arch/x86/efi/efi-boot.h new file +3
-0+#define __ASSEMBLY__/* avoid pulling in ACPI stuff (conflicts with EFI) */ +#include <asm/fixmap.h> +#undef __ASSEMBLY__that should be moved.
Yes.
Jan
PATCH v6 3/14 create arch functions to allocate memory for and process EFI memory map.
In reply to Roy FranzThe memory used to store the EFI memory map is allocated in an architecture specific way, and the processing of the memory map itself uses x86 specific data structures. This patch adds architecture specific funtions so each architecture can provide its own implementation.
--- xen/arch/x86/efi/efi-boot.h | 71 +++++++++++++++++++++++++++++++++++++++++++++ xen/common/efi/boot.c | 62 ++++----------------------------------- 2 files changed, 77 insertions(+), 56 deletions(-)
xen/arch/x86/efi/efi-boot.h +71 -0
@@ -130,3 +130,74 @@ static void __init place_string(u32 *addr, const char *s) } *addr = (long )alloc; } + +static void __init efi_arch_process_memory_map (EFI_SYSTEM_TABLE *SystemTable, +void *map, +UINTN map_size, +UINTN desc_size, +UINT32 desc_ver) +{ +struct e820entry *e; +unsigned int i; + +/* Populate E820 table and check trampoline area availability. */ + e = e820map -1 ; +for ( i =0 ; i < map_size; i += desc_size ) + { +EFI_MEMORY_DESCRIPTOR *desc = map + i; +u64 len = desc->NumberOfPages <<EFI_PAGE_SHIFT ; +u32 type; + +switch ( desc->Type ) + { +default : + type =E820_RESERVED ; +break ; +case EfiConventionalMemory: +case EfiBootServicesCode: +case EfiBootServicesData: +if ( !trampoline_phys && desc->PhysicalStart + len <=0x100000 && + len >= cfg.size && desc->PhysicalStart + len > cfg.addr ) + cfg.addr = (desc->PhysicalStart + len - cfg.size) &PAGE_MASK ; +/* fall through */ +case EfiLoaderCode: +case EfiLoaderData: +if ( desc->Attribute &EFI_MEMORY_WB ) + type =E820_RAM ; +else +case EfiUnusableMemory: + type =E820_UNUSABLE ; +break ; +case EfiACPIReclaimMemory: + type =E820_ACPI ; +break ; +case EfiACPIMemoryNVS: + type =E820_NVS ; +break ; + } +if ( e820nr && type == e->type && + desc->PhysicalStart == e->addr + e->size ) + e->size += len; +else if ( !len || e820nr >=E820MAX ) +continue ; +else + { + ++e; + e->addr = desc->PhysicalStart; + e->size = len; + e->type = type; + ++e820nr; + } + } + +} + +static void *__init efi_arch_allocate_mmap_buffer (UINTN map_size) +{ +place_string (&mbi.mem_upper,NULL ); + mbi.mem_upper -= map_size; + mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR ); +if ( mbi.mem_upper < xen_phys_start ) +return NULL ; +return (void *)(long )mbi.mem_upper; +}
xen/common/efi/boot.c +6 -56
86 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [PATCH for-4.5 V6 03/14] create arch functions to allocate memory for and process EFI memory map.
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 07:03, <[email protected]> wrote:
The memory used to store the EFI memory map is allocated in an architecture specific way, and the processing of the memory map itself uses x86 specific data structures. This patch adds architecture specific funtions so each architecture can provide its own implementation.
Signed-off-by Roy Franz <[email protected]>
PATCH v6 4/14 Add architecture functions for pre/post ExitBootServices
In reply to Roy FranzThe 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.
--- xen/arch/x86/efi/efi-boot.h | 50 +++++++++++++++++++++++++++++++++++++++++++++ xen/common/efi/boot.c | 42 ++----------------------------------- 2 files changed, 52 insertions(+), 40 deletions(-)
xen/arch/x86/efi/efi-boot.h +50 -0
@@ -201,3 +201,53 @@ static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)return NULL ;return (void *)(long )mbi.mem_upper; } + +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 noreturnefi_arch_post_exit_boot (void ) +{ +u64 efer; + +efi_arch_relocate_image (__XEN_VIRT_START - xen_phys_start); +memcpy ((void *)trampoline_phys, trampoline_start, cfg.size); + +/* Set system registers and transfer control. */ + asmvolatile ("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 ); + asmvolatile ("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" ); +for ( ; ; );/* not reached */ +}
xen/common/efi/boot.c +2 -40
60 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v6 5/14 Add efi_arch_cfg_file_early/late() to handle arch specific cfg file fields
In reply to Roy FranzDifferent architectures have some different configuration file fields that need to be handled. In particular, x86 has ucode and ARM has device tree files to be loaded. These arch specific functions is used to allow each architecture to implement these features in arch specific code. Early/late versions are provided, as ARM needs to process the DTB entry first, and x86 wants to process the ucode entry last as it is the smallest allocation.
--- xen/arch/x86/efi/efi-boot.h | 20 ++++++++++++++++++++ xen/common/efi/boot.c | 21 ++++++++++----------- 2 files changed, 30 insertions(+), 11 deletions(-)
xen/arch/x86/efi/efi-boot.h +20 -0
@@ -251,3 +251,23 @@ static void __init noreturn efi_arch_post_exit_boot(void) : "memory" );for ( ; ; );/* not reached */ } + +static void __init efi_arch_cfg_file_early (EFI_FILE_HANDLE dir_handle,char *section) +{ +} + +static void __init efi_arch_cfg_file_late (EFI_FILE_HANDLE dir_handle,char *section) +{ +union string name; + + name.s =get_value (&cfg, section,"ucode" ); +if ( !name.s ) + name.s =get_value (&cfg,"global" ,"ucode" ); +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); + } +}
xen/common/efi/boot.c +10 -11
@@ -54,6 +54,12 @@ static void DisplayUint(UINT64 Val, INTN Width);static CHAR16 *wstrcpy (CHAR16 *d,const CHAR16 *s);static void noreturnblexit (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 CHAR16 *s2w (union string *str); +static bool_t read_file (EFI_FILE_HANDLE dir_handle,CHAR16 *name, +struct file *file);static EFI_BOOT_SERVICES *__initdata efi_bs;static EFI_HANDLE __initdata efi_ih;
@@ -842,6 +848,9 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) }if ( !name.s )blexit (L"No Dom0 kernel image specified." ); + +efi_arch_cfg_file_early (dir_handle, section.s); +split_value (name.s);read_file (dir_handle,s2w (&name), &kernel); efi_bs->FreePool (name.w);
@@ -859,17 +868,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) efi_bs->FreePool (name.w); } - name.s =get_value (&cfg, section.s,"ucode" ); -if ( !name.s ) - name.s =get_value (&cfg,"global" ,"ucode" ); -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); - } - name.s =get_value (&cfg, section.s,"xsm" );if ( name.s ) {
@@ -908,6 +906,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) cols = rows = depth =0 ; } } +efi_arch_cfg_file_late (dir_handle, section.s); efi_bs->FreePages (cfg.addr,PFN_UP (cfg.size)); cfg.addr =0 ;
Signature · 1 line
2.1.0
PATCH v6 6/14 Add efi_arch_handle_cmdline() for processing commandline
In reply to Roy FranzAdd arch function for processing the Xen commandline and updating internal structures.
--- xen/arch/x86/efi/efi-boot.h | 34 ++++++++++++++++++++++++++++++++++ xen/common/efi/boot.c | 37 +++++++++---------------------------- 2 files changed, 43 insertions(+), 28 deletions(-)
xen/arch/x86/efi/efi-boot.h +34 -0
@@ -271,3 +271,37 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect efi_bs->FreePool (name.w); } } + +static void __init efi_arch_handle_cmdline (CHAR16 *image_name, +CHAR16 *cmdline_options, +char *cfgfile_options) +{ +union string name; + +if ( cmdline_options ) + { + name.w = cmdline_options; +w2s (&name); +place_string (&mbi.cmdline, name.s); + } +if ( cfgfile_options ) +place_string (&mbi.cmdline, cfgfile_options); +/* Insert image name last, as it gets prefixed to the other options. */ +if ( image_name ) + { + name.w = image_name; +w2s (&name); + } +else + name.s ="xen" ; +place_string (&mbi.cmdline, name.s); + +if ( mbi.cmdline ) + mbi.flags |=MBI_CMDLINE ; +/* +* These must not be initialized statically, since the value must +* not get relocated when processing base relocations later. +*/ + mbi.boot_loader_name = (long )"EFI" ; + mbi.mods_addr = (long )mb_modules; +}
xen/common/efi/boot.c +9 -28
@@ -58,6 +58,7 @@ static char *get_value(const struct file *cfg, const char *section, const char *item);static void split_value (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);
@@ -258,7 +259,8 @@ static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode) }static unsigned int __init get_argv (unsigned int argc,CHAR16 **argv, -CHAR16 *cmdline,UINTN cmdsize) +CHAR16 *cmdline,UINTN cmdsize, +CHAR16 **options) {CHAR16 *ptr = (CHAR16 *)(argv + argc +1 ), *prev =NULL ;bool_t prev_sep = TRUE;
@@ -284,10 +286,8 @@ static unsigned int __init get_argv(unsigned int argc, CHAR16 **argv, ++argc; else if ( prev && wstrcmp(prev, L"--") == 0 ) { -union string rest = { .w = cmdline }; - - --argv; -place_string (&mbi.cmdline,w2s (&rest)); +if ( options ) + *options = cmdline;break ; } else
@@ -662,7 +662,7 @@ 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 ; +CHAR16 **argv, *file_name, *cfg_file_name =NULL , *options =NULL ;UINTN cols, rows, depth, size, map_key, info_size, gop_mode = ~0 ;EFI_HANDLE *handles =NULL ;EFI_SHIM_LOCK_PROTOCOL *shim_lock;
@@ -700,14 +700,14 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) dir_handle =get_parent_handle (loaded_image, &file_name); argc =get_argv (0 ,NULL , loaded_image->LoadOptions, - loaded_image->LoadOptionsSize); + loaded_image->LoadOptionsSize,NULL );if ( argc >0 && efi_bs->AllocatePool (EfiLoaderData, (argc +1 ) *sizeof (*argv) + loaded_image->LoadOptionsSize, (void **)&argv) ==EFI_SUCCESS )get_argv (argc, argv, loaded_image->LoadOptions, - loaded_image->LoadOptionsSize); + loaded_image->LoadOptionsSize, &options);else argc =0 ;for ( i =1 ; i < argc; ++i )
@@ -877,17 +877,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) } name.s =get_value (&cfg, section.s,"options" ); -if ( name.s ) -place_string (&mbi.cmdline, name.s); -/* Insert image name last, as it gets prefixed to the other options. */ -if ( argc ) - { - name.w = *argv; -w2s (&name); - } -else - name.s ="xen" ; -place_string (&mbi.cmdline, name.s); +efi_arch_handle_cmdline (argc ? *argv :NULL , options, name.s); cols = rows = depth =0 ;if ( !base_video )
@@ -954,15 +944,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) } } -if ( mbi.cmdline ) - mbi.flags |=MBI_CMDLINE ; -/* -* These must not be initialized statically, since the value must -* not get relocated when processing base relocations below. -*/ - mbi.boot_loader_name = (long )"EFI" ; - mbi.mods_addr = (long )mb_modules; -/* Collect EDD info. */ BUILD_BUG_ON (offsetof(struct edd_info , edd_device_params) !=EDDEXTSIZE );BUILD_BUG_ON (sizeof (struct edd_device_params ) !=EDDPARMSIZE );
Signature · 1 line
2.1.0
PATCH v6 7/14 Move x86 specific disk probing code
In reply to Roy FranzMove x86 specific disk (EDD) probing to arch specific file. This code is x86 only and relates to legacy BIOS handling of disk drives.
--- xen/arch/x86/efi/efi-boot.h | 152 ++++++++++++++++++++++++++++++++++++++++++++ xen/common/efi/boot.c | 144 +---------------------------------------- 2 files changed, 153 insertions(+), 143 deletions(-)
xen/arch/x86/efi/efi-boot.h +152 -0
@@ -305,3 +305,155 @@ static void __init efi_arch_handle_cmdline(CHAR16 *image_name, mbi.boot_loader_name = (long )"EFI" ; mbi.mods_addr = (long )mb_modules; } + +static void __init efi_arch_edd (void ) +{ +static EFI_GUID __initdata bio_guid =BLOCK_IO_PROTOCOL ; +static EFI_GUID __initdata devp_guid =DEVICE_PATH_PROTOCOL ; +EFI_HANDLE *handles =NULL ; +unsigned int i; +UINTN size; +EFI_STATUS status; + +/* Collect EDD info. */ +BUILD_BUG_ON (offsetof(struct edd_info , edd_device_params) !=EDDEXTSIZE ); +BUILD_BUG_ON (sizeof (struct edd_device_params ) !=EDDPARMSIZE ); + size =0 ; + status = efi_bs->LocateHandle (ByProtocol, &bio_guid,NULL , &size,NULL ); +if ( status ==EFI_BUFFER_TOO_SMALL ) + status = efi_bs->AllocatePool (EfiLoaderData, size, (void **)&handles); +if ( !EFI_ERROR (status) ) + status = efi_bs->LocateHandle (ByProtocol, &bio_guid,NULL , &size, + handles); +if (EFI_ERROR (status) ) + size =0 ; +for ( i =0 ; i < size /sizeof (*handles); ++i ) + { +EFI_BLOCK_IO *bio; +EFI_DEV_PATH_PTR devp; +struct edd_info *info = boot_edd_info + boot_edd_info_nr; +struct edd_device_params *params = &info->edd_device_params; +enum { root, acpi, pci, ctrlr } state = root; + + status = efi_bs->HandleProtocol (handles[i], &bio_guid, (void **)&bio); +if (EFI_ERROR (status) || + bio->Media->RemovableMedia || + bio->Media->LogicalPartition ) +continue ; +if ( boot_edd_info_nr <EDD_INFO_MAX ) + { + info->device =0x80 + boot_edd_info_nr;/* fake */ + info->version =0x11 ; + params->length = offsetof(struct edd_device_params , dpte_ptr); + params->number_of_sectors = bio->Media->LastBlock +1 ; + params->bytes_per_sector = bio->Media->BlockSize; + params->dpte_ptr = ~0 ; + } + ++boot_edd_info_nr; + status = efi_bs->HandleProtocol (handles[i], &devp_guid, + (void **)&devp); +if (EFI_ERROR (status) ) +continue ; +for ( ; !IsDevicePathEnd (devp.DevPath); + devp.DevPath =NextDevicePathNode (devp.DevPath) ) + { +switch (DevicePathType (devp.DevPath) ) + { +const u8 *p; + +case ACPI_DEVICE_PATH : +if ( state != root || boot_edd_info_nr >EDD_INFO_MAX ) +break ; +switch (DevicePathSubType (devp.DevPath) ) + { +case ACPI_DP : +if ( devp.Acpi->HID !=EISA_PNP_ID (0xA03 ) && + devp.Acpi->HID !=EISA_PNP_ID (0xA08 ) ) +break ; + params->interface_path.pci.bus = devp.Acpi->UID; + state = acpi; +break ; +case EXPANDED_ACPI_DP : +/* XXX */ +break ; + } +break ; +case HARDWARE_DEVICE_PATH : +if ( state != acpi || +DevicePathSubType (devp.DevPath) !=HW_PCI_DP || + boot_edd_info_nr >EDD_INFO_MAX ) +break ; + state = pci; +edd_put_string (params->host_bus_type,"PCI" ); + params->interface_path.pci.slot = devp.Pci->Device; + params->interface_path.pci.function = devp.Pci->Function; +break ; +case MESSAGING_DEVICE_PATH : +if ( state != pci || boot_edd_info_nr >EDD_INFO_MAX ) +break ; + state = ctrlr; +switch (DevicePathSubType (devp.DevPath) ) + { +case MSG_ATAPI_DP : +edd_put_string (params->interface_type,"ATAPI" ); + params->interface_path.pci.channel = + devp.Atapi->PrimarySecondary; + params->device_path.atapi.device = devp.Atapi->SlaveMaster; + params->device_path.atapi.lun = devp.Atapi->Lun; +break ; +case MSG_SCSI_DP : +edd_put_string (params->interface_type,"SCSI" ); + params->device_path.scsi.id = devp.Scsi->Pun; + params->device_path.scsi.lun = devp.Scsi->Lun; +break ; +case MSG_FIBRECHANNEL_DP : +edd_put_string (params->interface_type,"FIBRE" ); + params->device_path.fibre.wwid = devp.FibreChannel->WWN; + params->device_path.fibre.lun = devp.FibreChannel->Lun; +break ; +case MSG_1394_DP : +edd_put_string (params->interface_type,"1394" ); + params->device_path.i1394.eui = devp.F1394->Guid; +break ; +case MSG_USB_DP : +case MSG_USB_CLASS_DP : +edd_put_string (params->interface_type,"USB" ); +break ; +case MSG_I2O_DP : +edd_put_string (params->interface_type,"I2O" ); + params->device_path.i2o.identity_tag = devp.I2O->Tid; +break ; +default : +continue ; + } + info->version =0x30 ; + params->length =sizeof (struct edd_device_params ); + params->key =0xbedd ; + params->device_path_info_length = +sizeof (struct edd_device_params ) - + offsetof(struct edd_device_params , key); +for ( p = (const u8 *)¶ms->key; p < ¶ms->checksum; ++p ) + params->checksum -= *p; +break ; +case MEDIA_DEVICE_PATH : +if (DevicePathSubType (devp.DevPath) ==MEDIA_HARDDRIVE_DP && + devp.HardDrive->MBRType ==MBR_TYPE_PCAT && + boot_mbr_signature_nr <EDD_MBR_SIG_MAX ) + { +struct mbr_signature *sig = boot_mbr_signature + + boot_mbr_signature_nr; + + sig->device =0x80 + boot_edd_info_nr;/* fake */ +memcpy (&sig->signature, devp.HardDrive->Signature, +sizeof (sig->signature)); + ++boot_mbr_signature_nr; + } +break ; + } + } + } +if ( handles ) + efi_bs->FreePool (handles); +if ( boot_edd_info_nr >EDD_INFO_MAX ) + boot_edd_info_nr =EDD_INFO_MAX ; +}
xen/common/efi/boot.c +1 -143
156 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v6 8/14 Create arch functions for console and video init
In reply to Roy FranzAdd arch functions for text console and graphics initialization, and move VGA specific code to x86 architecture file.
--- xen/arch/x86/efi/efi-boot.h | 75 +++++++++++++++++++++++++++++++++++++++++++++ xen/common/efi/boot.c | 69 ++--------------------------------------- 2 files changed, 78 insertions(+), 66 deletions(-)
xen/arch/x86/efi/efi-boot.h +75 -0
@@ -457,3 +457,78 @@ static void __init efi_arch_edd(void)if ( boot_edd_info_nr >EDD_INFO_MAX ) boot_edd_info_nr =EDD_INFO_MAX ; } + +static void __init efi_arch_console_init (UINTN cols,UINTN rows) +{ + vga_console_info.video_type =XEN_VGATYPE_TEXT_MODE_3 ; + vga_console_info.u.text_mode_3.columns = cols; + vga_console_info.u.text_mode_3.rows = rows; + vga_console_info.u.text_mode_3.font_height =16 ; +} + +static void __init efi_arch_video_init (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, +UINTN info_size, +EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info) +{ +int bpp =0 ; + +switch ( mode_info->PixelFormat ) + { +case PixelRedGreenBlueReserved8BitPerColor: + vga_console_info.u.vesa_lfb.red_pos =0 ; + vga_console_info.u.vesa_lfb.red_size =8 ; + vga_console_info.u.vesa_lfb.green_pos =8 ; + vga_console_info.u.vesa_lfb.green_size =8 ; + vga_console_info.u.vesa_lfb.blue_pos =16 ; + vga_console_info.u.vesa_lfb.blue_size =8 ; + vga_console_info.u.vesa_lfb.rsvd_pos =24 ; + vga_console_info.u.vesa_lfb.rsvd_size =8 ; + bpp =32 ; +break ; +case PixelBlueGreenRedReserved8BitPerColor: + vga_console_info.u.vesa_lfb.red_pos =16 ; + vga_console_info.u.vesa_lfb.red_size =8 ; + vga_console_info.u.vesa_lfb.green_pos =8 ; + vga_console_info.u.vesa_lfb.green_size =8 ; + vga_console_info.u.vesa_lfb.blue_pos =0 ; + vga_console_info.u.vesa_lfb.blue_size =8 ; + vga_console_info.u.vesa_lfb.rsvd_pos =24 ; + vga_console_info.u.vesa_lfb.rsvd_size =8 ; + bpp =32 ; +break ; +case PixelBitMask: + bpp =set_color (mode_info->PixelInformation.RedMask, bpp, + &vga_console_info.u.vesa_lfb.red_pos, + &vga_console_info.u.vesa_lfb.red_size); + bpp =set_color (mode_info->PixelInformation.GreenMask, bpp, + &vga_console_info.u.vesa_lfb.green_pos, + &vga_console_info.u.vesa_lfb.green_size); + bpp =set_color (mode_info->PixelInformation.BlueMask, bpp, + &vga_console_info.u.vesa_lfb.blue_pos, + &vga_console_info.u.vesa_lfb.blue_size); + bpp =set_color (mode_info->PixelInformation.ReservedMask, bpp, + &vga_console_info.u.vesa_lfb.rsvd_pos, + &vga_console_info.u.vesa_lfb.rsvd_size); +if ( bpp >0 ) +break ; +/* fall through */ +default : +PrintErr (L"Current graphics mode is unsupported!\r\n" ); + bpp =0 ; +break ; + } +if ( bpp >0 ) + { + vga_console_info.video_type =XEN_VGATYPE_EFI_LFB ; + vga_console_info.u.vesa_lfb.gbl_caps =2 ;/* possibly non-VGA */ + vga_console_info.u.vesa_lfb.width = + mode_info->HorizontalResolution; + vga_console_info.u.vesa_lfb.height = mode_info->VerticalResolution; + vga_console_info.u.vesa_lfb.bits_per_pixel = bpp; + vga_console_info.u.vesa_lfb.bytes_per_line = + (mode_info->PixelsPerScanLine * bpp +7 ) >>3 ; + vga_console_info.u.vesa_lfb.lfb_base = gop->Mode->FrameBufferBase; + vga_console_info.u.vesa_lfb.lfb_size = + (gop->Mode->FrameBufferSize +0xffff ) >>16 ; + } +}
xen/common/efi/boot.c +3 -66
93 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v6 9/14 Add efi_arch_memory() for arch specific memory setup
In reply to Roy FranzThis patch adds efi_arch_memory() to allow each architecture a hook to use for do memory setup. x86 uses this for trampoline memory setup and some pagetable setup.
--- xen/arch/x86/efi/efi-boot.h | 35 +++++++++++++++++++++++++++++++++++ xen/common/efi/boot.c | 29 +---------------------------- 2 files changed, 36 insertions(+), 28 deletions(-)
xen/arch/x86/efi/efi-boot.h +35 -0
@@ -532,3 +532,38 @@ static void __init efi_arch_video_init(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, (gop->Mode->FrameBufferSize +0xffff ) >>16 ; } } + +static void __init efi_arch_memory_setup (void ) +{ +unsigned int i; +EFI_STATUS status; + +/* Allocate space for trampoline (in first Mb). */ + cfg.addr =0x100000 ; + cfg.size = trampoline_end - trampoline_start; + status = efi_bs->AllocatePages (AllocateMaxAddress, EfiLoaderData, +PFN_UP (cfg.size), &cfg.addr); +if ( status ==EFI_SUCCESS ) +relocate_trampoline (cfg.addr); +else + { + cfg.addr =0 ; +PrintStr (L"Trampoline space cannot be allocated; will try fallback.\r\n" ); + } + +/* Initialise L2 identity-map and boot-map page table entries (16MB). */ +for ( i =0 ; i <8 ; ++i ) + { +unsigned int slot = (xen_phys_start >>L2_PAGETABLE_SHIFT ) + i; +paddr_t addr = slot <<L2_PAGETABLE_SHIFT ; + + l2_identmap[slot] =l2e_from_paddr (addr,PAGE_HYPERVISOR |_PAGE_PSE); + slot &=L2_PAGETABLE_ENTRIES -1 ; + l2_bootmap[slot] =l2e_from_paddr (addr, __PAGE_HYPERVISOR|_PAGE_PSE); + } +/* Initialise L3 boot-map page directory entries. */ + l3_bootmap[l3_table_offset (xen_phys_start)] = +l3e_from_paddr ((UINTN )l2_bootmap, __PAGE_HYPERVISOR); + l3_bootmap[l3_table_offset (xen_phys_start + (8 <<L2_PAGETABLE_SHIFT ) -1 )] = +l3e_from_paddr ((UINTN )l2_bootmap, __PAGE_HYPERVISOR); +}
xen/common/efi/boot.c +1 -28
@@ -991,34 +991,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)PrintStr (newline); } -/* Allocate space for trampoline (in first Mb). */ - cfg.addr =0x100000 ; - cfg.size = trampoline_end - trampoline_start; - status = efi_bs->AllocatePages (AllocateMaxAddress, EfiLoaderData, -PFN_UP (cfg.size), &cfg.addr); -if ( status ==EFI_SUCCESS ) -relocate_trampoline (cfg.addr); -else - { - cfg.addr =0 ; -PrintStr (L"Trampoline space cannot be allocated; will try fallback.\r\n" ); - } - -/* Initialise L2 identity-map and boot-map page table entries (16MB). */ -for ( i =0 ; i <8 ; ++i ) - { -unsigned int slot = (xen_phys_start >>L2_PAGETABLE_SHIFT ) + i; -paddr_t addr = slot <<L2_PAGETABLE_SHIFT ; - - l2_identmap[slot] =l2e_from_paddr (addr,PAGE_HYPERVISOR |_PAGE_PSE); - slot &=L2_PAGETABLE_ENTRIES -1 ; - l2_bootmap[slot] =l2e_from_paddr (addr, __PAGE_HYPERVISOR|_PAGE_PSE); - } -/* Initialise L3 boot-map page directory entries. */ - l3_bootmap[l3_table_offset (xen_phys_start)] = -l3e_from_paddr ((UINTN )l2_bootmap, __PAGE_HYPERVISOR); - l3_bootmap[l3_table_offset (xen_phys_start + (8 <<L2_PAGETABLE_SHIFT ) -1 )] = -l3e_from_paddr ((UINTN )l2_bootmap, __PAGE_HYPERVISOR); +efi_arch_memory_setup ();if ( gop ) {
Signature · 1 line
2.1.0
PATCH v6 10/14 Add arch specific module handling to read_file()
In reply to Roy FranzEach 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.
--- xen/arch/x86/efi/efi-boot.h | 31 ++++++++++++++++-- xen/common/efi/boot.c | 77 ++++++++++++++++++++++++++++----------------- 2 files changed, 78 insertions(+), 30 deletions(-)
xen/arch/x86/efi/efi-boot.h +29 -2
@@ -266,8 +266,8 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sectif ( 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); +}
xen/common/efi/boot.c +49 -28
167 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [PATCH for-4.5 V6 10/14] Add arch specific module handling to read_file()
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 07:03, <[email protected]> wrote:
xen/arch/x86/efi/efi-boot.h +3
-0+static void __init efi_arch_handle_module (struct file *file,const CHAR16 *name, +char *options) +{
xen/arch/x86/efi/efi-boot.h static void __init efi_arch_memory_setup(void) · line 583
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10
-0+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" );
As I keep seeing this: Please drop these "ERROR " prefixes from blexit() messages - their text already makes clear that this is an error (and even more so together with the module returning to whatever component invoked it).
xen/arch/x86/efi/efi-boot.h static void __init efi_arch_memory_setup(void) · line 590
Quoted 7 lines
xen/arch/x86/efi/efi-boot.h +7
-0+ + 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,"" );
What is this good for btw? I don't see anything similar being done in the original code.
Jan
PATCH v6 11/14 Add several misc. arch functions for EFI boot code.
In reply to Roy FranzAdd efi_arch_blexit() for arch specific cleanup on error exit, efi_arch_load_addr_check() to do the arch specific verifications of where the UEFI firmware loaded Xen, and efi_arch_cpu() for probing CPU features.
--- xen/arch/x86/efi/efi-boot.h | 25 +++++++++++++++++++++++++ xen/common/efi/boot.c | 18 ++++-------------- 2 files changed, 29 insertions(+), 14 deletions(-)
xen/arch/x86/efi/efi-boot.h +25 -0
@@ -594,3 +594,28 @@ static void __init efi_arch_handle_module(struct file *file, const CHAR16 *name, ++mbi.mods_count; efi_bs->FreePool (ptr); } + +static void __init efi_arch_cpu (void ) +{ +if (cpuid_eax (0x80000000 ) >0x80000000 ) + { + cpuid_ext_features =cpuid_edx (0x80000001 ); + boot_cpu_data.x86_capability[1 ] = cpuid_ext_features; + } +} + +static void __init efi_arch_blexit (void ) +{ +if ( ucode.addr ) + efi_bs->FreePages (ucode.addr,PFN_UP (ucode.size)); +} + +static void __init efi_arch_load_addr_check (EFI_LOADED_IMAGE *loaded_image) +{ + xen_phys_start = (UINTN )loaded_image->ImageBase; +if ( (xen_phys_start + loaded_image->ImageSize -1 ) >>32 ) +blexit (L"Xen must be loaded below 4Gb." ); +if ( xen_phys_start & ((1 <<L2_PAGETABLE_SHIFT ) -1 ) ) +blexit (L"Xen must be loaded at a 2Mb boundary." ); + trampoline_xen_phys_start = xen_phys_start; +}
xen/common/efi/boot.c +4 -14
@@ -209,11 +209,11 @@ static void __init noreturn blexit(const CHAR16 *str) efi_bs->FreePages (kernel.addr,PFN_UP (kernel.size));if ( ramdisk.addr ) efi_bs->FreePages (ramdisk.addr,PFN_UP (ramdisk.size)); -if ( ucode.addr ) - efi_bs->FreePages (ucode.addr,PFN_UP (ucode.size));if ( xsm.addr ) efi_bs->FreePages (xsm.addr,PFN_UP (xsm.size)); +efi_arch_blexit (); + efi_bs->Exit (efi_ih,EFI_SUCCESS ,0 ,NULL );unreachable ();/* not reached */ }
@@ -709,12 +709,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)if ( status !=EFI_SUCCESS )PrintErrMesg (L"No Loaded Image Protocol" , status); - xen_phys_start = (UINTN )loaded_image->ImageBase; -if ( (xen_phys_start + loaded_image->ImageSize -1 ) >>32 ) -blexit (L"Xen must be loaded below 4Gb." ); -if ( xen_phys_start & ((1 <<L2_PAGETABLE_SHIFT ) -1 ) ) -blexit (L"Xen must be loaded at a 2Mb boundary." ); - trampoline_xen_phys_start = xen_phys_start; +efi_arch_load_addr_check (loaded_image);/* Get the file system interface. */ dir_handle =get_parent_handle (loaded_image, &file_name);
@@ -962,12 +957,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)efi_arch_edd ();/* XXX Collect EDID info. */ - -if (cpuid_eax (0x80000000 ) >0x80000000 ) - { - cpuid_ext_features =cpuid_edx (0x80000001 ); - boot_cpu_data.x86_capability[1 ] = cpuid_ext_features; - } +efi_arch_cpu ();/* Obtain basic table pointers. */ for ( i =0 ; i < efi_num_ct; ++i )
Signature · 1 line
2.1.0
PATCH v6 12/14 Add efi_arch_use_config_file() function to control use of config file
In reply to Roy FranzThe x86 EFI build of Xen always uses a configuration file to load modules, but the ARM version can either use a config file to specify the modules, or be loaded by GRUB in which case GRUB loads the modules and adds them to the DTB that is passed to Xen. Add the efi_arch_use_config_file() to indicate if a configuration file is required. For x86, this will always be true. ARM will examine the DTB passed via EFI configuration table (if any), and if it contains module information will use that that not use the configuration file at all. Add Emacs footer to efi-boot.h and boot.c
--- xen/arch/x86/efi/efi-boot.h | 14 ++++ xen/common/efi/boot.c | 179 +++++++++++++++++++++++--------------------- 2 files changed, 107 insertions(+), 86 deletions(-)
xen/arch/x86/efi/efi-boot.h +14 -0
@@ -619,3 +619,17 @@ static void __init efi_arch_load_addr_check(EFI_LOADED_IMAGE *loaded_image)blexit (L"Xen must be loaded at a 2Mb boundary." ); trampoline_xen_phys_start = xen_phys_start; } + +static bool_t __init efi_arch_use_config_file (EFI_SYSTEM_TABLE *SystemTable) +{ +return 1 ;/* x86 always uses a config file */ +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/common/efi/boot.c +93 -86
218 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v6 13/14 Fix freeing of uninitialized pointer
In reply to Roy FranzThe only valid response from the LocateHandle() call is EFI_BUFFER_TOO_SMALL, so exit if we get anything else. We pass a 0 size/NULL pointer buffer, so the only other returns we will get is an error. Return right away as there is nothing to do. Also return if there is an error allocating the buffer, as the previous code path also allowed for an undefined pointer to be freed.
--- xen/common/efi/boot.c | 6 ++++++ 1 file changed, 6 insertions(+)
xen/common/efi/boot.c +6 -0
@@ -582,9 +582,15 @@ static void __init setup_efi_pci(void) status = efi_bs->LocateHandle (ByProtocol, &pci_guid,NULL , &size,NULL );if ( status ==EFI_BUFFER_TOO_SMALL ) status = efi_bs->AllocatePool (EfiLoaderData, size, (void **)&handles); +else +return ; +if ( !EFI_ERROR (status) ) status = efi_bs->LocateHandle (ByProtocol, &pci_guid,NULL , &size, handles); +else +return ; +if (EFI_ERROR (status) ) size =0 ;
Signature · 1 line
2.1.0
Re: [PATCH for-4.5 V6 13/14] Fix freeing of uninitialized pointer
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 07:03, <[email protected]> wrote:
The only valid response from the
LocateHandle()call isEFI_BUFFER_TOO_SMALL, so exit if we get anything else. We pass a 0 size/NULL pointer buffer, so the only other returns we will get is an error. Return right away as there is nothing to do. Also return if there is an error allocating the buffer, as the previous code path also allowed for an undefined pointer to be freed.Signed-off-by Roy Franz <[email protected]>
Thanks, but I restructured the patch (see below). Additionally such bug fixes would better be placed at the start of a series to ease backporting.
Jan
x86/EFI: fix freeing of uninitialized pointer
The only valid response from the LocateHandle() call is EFI_BUFFER_TOO_SMALL, so exit if we get anything else. We pass a 0 size/NULL pointer buffer, so the only other returns we will get is an error. Return right away as there is nothing to do. Also return if there is an error allocating the buffer, as the previous code path also allowed for an undefined pointer to be freed.
Re-structure the change.
xen/arch/x86/efi/boot.c +6 -5
@@ -595,11 +595,12 @@ static void __init setup_efi_pci(void)struct efi_pci_rom *last =NULL ; status = efi_bs->LocateHandle (ByProtocol, &pci_guid,NULL , &size,NULL ); -if ( status ==EFI_BUFFER_TOO_SMALL ) - status = efi_bs->AllocatePool (EfiLoaderData, size, (void **)&handles); -if ( !EFI_ERROR (status) ) - status = efi_bs->LocateHandle (ByProtocol, &pci_guid,NULL , &size, - handles); +if ( status !=EFI_BUFFER_TOO_SMALL ) +return ; + status = efi_bs->AllocatePool (EfiLoaderData, size, (void **)&handles); +if (EFI_ERROR (status) ) +return ; + status = efi_bs->LocateHandle (ByProtocol, &pci_guid,NULL , &size, handles);if (EFI_ERROR (status) ) size =0 ;
Re: [PATCH for-4.5 V6 13/14] Fix freeing of uninitialized pointer
Quoted 42 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 07:03, <[email protected]> wrote:
The only valid response from the
LocateHandle()call isEFI_BUFFER_TOO_SMALL, so exit if we get anything else. We pass a 0 size/NULL pointer buffer, so the only other returns we will get is an error. Return right away as there is nothing to do. Also return if there is an error allocating the buffer, as the previous code path also allowed for an undefined pointer to be freed.Signed-off-by Roy Franz <[email protected]>Thanks, but I restructured the patch (see below). Additionally such bug fixes would better be placed at the start of a series to ease backporting.
Jan
x86/EFI: fix freeing of uninitialized pointer
The only valid response from the
LocateHandle()call isEFI_BUFFER_TOO_SMALL, so exit if we get anything else. We pass a 0 size/NULL pointer buffer, so the only other returns we will get is an error. Return right away as there is nothing to do. Also return if there is an error allocating the buffer, as the previous code path also allowed for an undefined pointer to be freed.Signed-off-by Roy Franz <[email protected]>Re-structure the change.
Signed-off-by Jan Beulich <[email protected]>xen/arch/x86/efi/boot.c +0
-4@@ -595,11 +595,12 @@ static void __init setup_efi_pci(void)struct efi_pci_rom *last =NULL ; status = efi_bs->LocateHandle (ByProtocol, &pci_guid,NULL , &size,NULL ); -if ( status ==EFI_BUFFER_TOO_SMALL ) - status = efi_bs->AllocatePool (EfiLoaderData, size, (void **)&handles); -if ( !EFI_ERROR (status) ) - status = efi_bs->LocateHandle(ByProtocol, &pci_guid, NULL, &size,
xen/arch/x86/efi/boot.c static void __init setup_efi_pci(void) · line 606
Quoted 10 lines
xen/arch/x86/efi/boot.c +6
-1- handles); +if ( status !=EFI_BUFFER_TOO_SMALL ) +return ; + status = efi_bs->AllocatePool (EfiLoaderData, size, (void **)&handles); +if (EFI_ERROR (status) ) +return ; + status = efi_bs->LocateHandle (ByProtocol, &pci_guid,NULL , &size, handles);if (EFI_ERROR (status) ) size =0 ;
OK, I'll use your version, and move it to the start of the patch series.
Roy
Re: [PATCH for-4.5 V6 13/14] Fix freeing of uninitialized pointer
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 21:22, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
xen/arch/x86/efi/boot.c +0
-0@@ -595,11 +595,12 @@ static void __init setup_efi_pci(void)struct efi_pci_rom *last =NULL ;
Quoted 16 lines
Quoted 5 lines
xen/arch/x86/efi/boot.c +0
-4status = efi_bs->LocateHandle (ByProtocol, &pci_guid,NULL , &size,NULL ); -if ( status ==EFI_BUFFER_TOO_SMALL ) - status = efi_bs->AllocatePool (EfiLoaderData, size, (void **)&handles); -if ( !EFI_ERROR (status) ) - status = efi_bs->LocateHandle(ByProtocol, &pci_guid, NULL, &size,xen/arch/x86/efi/boot.c static void __init setup_efi_pci(void)
Quoted 10 lines
xen/arch/x86/efi/boot.c +6
-1- handles); +if ( status !=EFI_BUFFER_TOO_SMALL ) +return ; + status = efi_bs->AllocatePool (EfiLoaderData, size, (void **)&handles); +if (EFI_ERROR (status) ) +return ; + status = efi_bs->LocateHandle (ByProtocol, &pci_guid,NULL , &size, handles);if (EFI_ERROR (status) ) size =0 ;OK, I'll use your version, and move it to the start of the patch series.
Did you overlook that I committed it already?
Jan
Re: [PATCH for-4.5 V6 13/14] Fix freeing of uninitialized pointer
Quoted 24 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 21:22, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
xen/arch/x86/efi/boot.c +0
-0@@ -595,11 +595,12 @@ static void __init setup_efi_pci(void)struct efi_pci_rom *last =NULL ;Quoted 16 lines
Quoted 5 lines
xen/arch/x86/efi/boot.c +0
-4status = efi_bs->LocateHandle (ByProtocol, &pci_guid,NULL , &size,NULL ); -if ( status ==EFI_BUFFER_TOO_SMALL ) - status = efi_bs->AllocatePool (EfiLoaderData, size, (void **)&handles); -if ( !EFI_ERROR (status) ) - status = efi_bs->LocateHandle(ByProtocol, &pci_guid, NULL, &size,xen/arch/x86/efi/boot.c static void __init setup_efi_pci(void)
Quoted 10 lines
xen/arch/x86/efi/boot.c +6
-1- handles); +if ( status !=EFI_BUFFER_TOO_SMALL ) +return ; + status = efi_bs->AllocatePool (EfiLoaderData, size, (void **)&handles); +if (EFI_ERROR (status) ) +return ; + status = efi_bs->LocateHandle (ByProtocol, &pci_guid,NULL , &size, handles);if (EFI_ERROR (status) ) size =0 ;OK, I'll use your version, and move it to the start of the patch series.
Quoted 4 lines
Did you overlook that I committed it already?
Jan
I sure did..
PATCH v6 14/14 Add ARM EFI boot support
In reply to Roy FranzThis patch adds EFI boot support for ARM based on the previous refactoring of the x86 EFI boot code. All ARM specific code is in the ARM efi-boot.h header file, with the main EFI entry point common/efi/boot.c. The PE/COFF header is open-coded in head.S, which allows us to have a single binary be both an EFI executable and a normal arm64 IMAGE file. There is currently no PE/COFF toolchain support for arm64, so it is not possible to create the PE/COFF header in the same manner as on x86. This also simplifies the build as compared to x86, as we always build the same executable, whereas x86 builds 2. An ARM version of efi-bind.h is added, which is based on the x86_64 version with the x86 specific portions removed. The Makefile in common/efi is different for x86 and ARM, as for ARM we always build in EFI support.NR_MEM_BANKS is increased, as memory regions are now added from the UEFI memory map, rather than memory banks from a DTB. The UEFI memory map may be fragmented so a larger number of regions will be used.
--- .gitignore | 4 + xen/arch/arm/Makefile | 1 + xen/arch/arm/arm64/head.S | 150 ++++++++- xen/arch/arm/efi/Makefile | 4 + xen/arch/arm/efi/efi-boot.h | 593 ++++++++++++++++++++++++++++++++++++ xen/arch/arm/xen.lds.S | 1 + xen/arch/x86/efi/efi-boot.h | 2 + xen/common/efi/boot.c | 10 +- xen/common/efi/efi.h | 2 - xen/common/efi/runtime.c | 15 +- xen/include/asm-arm/arm64/efibind.h | 216 +++++++++++++ xen/include/asm-arm/efibind.h | 2 + xen/include/asm-arm/setup.h | 2 +- 13 files changed, 990 insertions(+), 12 deletions(-) create mode 100644 xen/arch/arm/efi/Makefile create mode 100644 xen/arch/arm/efi/efi-boot.h create mode 100644 xen/include/asm-arm/arm64/efibind.h create mode 100644 xen/include/asm-arm/efibind.h
.gitignore +4 -0
@@ -258,6 +258,10 @@ xen/arch/x86/efi/boot.c xen/arch/x86/efi/runtime.c xen/arch/x86/efi/compat.c xen/arch/x86/efi/efi.h +xen/arch/arm/efi/boot.c +xen/arch/arm/efi/runtime.c +xen/arch/arm/efi/compat.c +xen/arch/arm/efi/efi.h xen/ddb/* xen/include/headers.chk xen/include/asm
xen/arch/arm/Makefile +1 -0
@@ -1,6 +1,7 @@ subdir-$(arm32) += arm32 subdir-$(arm64) += arm64 subdir-y += platforms +subdir-$(arm64) += efi obj-$(EARLY_PRINTK) += early_printk.o obj-y += cpu.o
xen/arch/arm/arm64/head.S +147 -3
175 lines not on this page · raw message
xen/arch/arm/efi/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +CFLAGS += -fshort-wchar + +obj-y += boot.init.o runtime.o +
xen/arch/arm/efi/efi-boot.h new file +593 -0
593 lines not on this page · raw message
xen/arch/arm/xen.lds.S +1 -0
@@ -135,6 +135,7 @@ SECTIONS *(.xsm_initcall.init) __xsm_initcall_end = .; } :text + __init_end_efi = .; . = ALIGN(STACK_SIZE); __init_end = .;
xen/arch/x86/efi/efi-boot.h +2 -0
@@ -17,6 +17,8 @@ static multiboot_info_t __initdata mbi = { };static module_t __initdata mb_modules[3 ]; +extern l4_pgentry_t *efi_l4_pgtable; +static void __init edd_put_string (u8 *dst,size_t n,const char *src) {while ( n-- && *src )
xen/common/efi/boot.c +8 -2
@@ -18,6 +18,7 @@#include <xen/string.h> #include <xen/stringify.h> #include <xen/vga.h> +#include <xen/bitops.h> /* Using SetVirtualAddressMap() is incompatible with kexec: */ #undef USE_SET_VIRTUAL_ADDRESS_MAP
@@ -63,6 +64,7 @@ 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 bool_t match_guid (const EFI_GUID *guid1,const EFI_GUID *guid2);static EFI_BOOT_SERVICES *__initdata efi_bs;static EFI_HANDLE __initdata efi_ih;
@@ -118,7 +120,7 @@ static void __init DisplayUint(UINT64 Val, INTN Width)PrintStr (PrintString); } -static size_t __init wstrlen (const CHAR16 *s) +static size_t __init __maybe_unused wstrlen (const CHAR16 *s) {const CHAR16 *sc;
@@ -663,7 +665,7 @@ static void __init setup_efi_pci(void) efi_bs->FreePool (handles); } -static int __init set_color (u32 mask,int bpp,u8 *pos,u8 *sz) +static int __init __maybe_unused set_color (u32 mask,int bpp,u8 *pos,u8 *sz) {if ( bpp <0 )return bpp;
@@ -990,8 +992,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) efi.smbios = (long )efi_ct[i].VendorTable; } +#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */ if (efi.smbios !=EFI_INVALID_TABLE_ADDR )dmi_efi_get_table ((void *)(long )efi.smbios); +#endif /* Collect PCI ROM contents. */ setup_efi_pci ();
@@ -1062,6 +1066,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)for ( ; ; );/* not reached */ } +#ifndef CONFIG_ARM /* TODO - runtime service support */ #ifndef USE_SET_VIRTUAL_ADDRESS_MAP static __init void copy_mapping(unsigned long mfn, unsigned long end, bool_t (*is_valid)(unsigned long smfn,
@@ -1287,3 +1292,4 @@ void __init efi_init_memory(void) efi_l4_pgtable[i] = idle_pg_table[i]; #endif } +#endif
xen/common/efi/efi.h +0 -2
@@ -28,8 +28,6 @@ extern EFI_RUNTIME_SERVICES *efi_rs;extern UINTN efi_memmap_size, efi_mdesc_size;extern void *efi_memmap; -extern l4_pgentry_t *efi_l4_pgtable; -extern const struct efi_pci_rom *efi_pci_roms; extern UINT64 efi_boot_max_var_store_size, efi_boot_remain_var_store_size,
xen/common/efi/runtime.c +11 -4
@@ -4,17 +4,21 @@#include <xen/guest_access.h> #include <xen/irq.h> #include <xen/time.h> -#include <asm/mc146818rtc.h> +extern spinlock_t rtc_lock;DEFINE_XEN_GUEST_HANDLE (CHAR16 );#ifndef COMPAT +#ifdef CONFIG_ARM /* Disabled until runtime services implemented */ +const bool_t efi_enabled =0 ; +#else # include <asm/i387.h> # include <asm/xstate.h> # include <public/platform.h> const bool_t efi_enabled =1 ; +#endif unsigned int __read_mostly efi_num_ct;EFI_CONFIGURATION_TABLE *__read_mostly efi_ct;
@@ -24,7 +28,6 @@ unsigned int __read_mostly efi_fw_revision;const CHAR16 *__read_mostly efi_fw_vendor;EFI_RUNTIME_SERVICES *__read_mostly efi_rs; -static DEFINE_SPINLOCK (efi_rs_lock);UINTN __read_mostly efi_memmap_size;UINTN __read_mostly efi_mdesc_size;
@@ -41,10 +44,11 @@ struct efi __read_mostly efi = { .smbios = EFI_INVALID_TABLE_ADDR, }; -l4_pgentry_t *__read_mostly efi_l4_pgtable; -const struct efi_pci_rom *__read_mostly efi_pci_roms; +#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */ +static DEFINE_SPINLOCK (efi_rs_lock); +l4_pgentry_t *__read_mostly efi_l4_pgtable;unsigned long efi_rs_enter (void ) {static const u16 fcw =FCW_DEFAULT ;
@@ -135,7 +139,9 @@ void efi_reset_system(bool_t warm) }#endif +#endif +#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */ int efi_get_info (uint32_t idx,union xenpf_efi_info *info) {unsigned int i, n;
@@ -545,3 +551,4 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op) return rc; } +#endif
xen/include/asm-arm/arm64/efibind.h new file +216 -0
216 lines not on this page · raw message
xen/include/asm-arm/efibind.h new file +2 -0
@@ -0,0 +1,2 @@ +#include <xen/types.h> +#include <asm/arm64/efibind.h>
xen/include/asm-arm/setup.h +1 -1
@@ -3,7 +3,7 @@#include <public/version.h> -#define NR_MEM_BANKS 8 +#define NR_MEM_BANKS 64#define MAX_MODULES 5/* Current maximum useful modules */
Signature · 1 line
2.1.0
Re: [PATCH for-4.5 V6 14/14] Add ARM EFI boot support
Hi Roy,
Quoted 29 lines · Roy Franz
xen/arch/arm/efi/efi-boot.h new file +29
-0+static int __init fdt_set_reg (void *fdt,int node,int addr_cells, +int size_cells,uint64_t addr,uint64_t len) +{ +uint8_t data[16 ];/* at most 2 64 bit words */ +void *p = data; + +/* Make sure that the values provided can be represented in +* the reg property. +*/ +if ( addr_cells ==1 && (addr >>32 ) ) +return -1 ; +if ( size_cells ==1 && (len >>32 ) ) +return -1 ; + +if ( addr_cells ==1 ) + { + *(uint32_t *)p =cpu_to_fdt32 (addr); + p +=sizeof (uint32_t ); + } +else if ( addr_cells ==2 ) + { + *(uint64_t *)p =cpu_to_fdt64 (addr); + p +=sizeof (uint64_t ); + } +else +return -1 ; + +if ( size_cells ==1 ) + {
xen/arch/arm/efi/efi-boot.h line 118
Quoted 10 lines
xen/arch/arm/efi/efi-boot.h new file +10
-0+ *(uint32_t *)p =cpu_to_fdt32 (len); + p +=sizeof (uint32_t ); + } +else if ( size_cells ==2 ) + { + *(uint64_t *)p =cpu_to_fdt64 (len); + p +=sizeof (uint64_t ); + } +else +return -1 ;
You could give a look to dt_set_cell (xen/common/device_tree.c). I think it will fit to your usage and avoid open coding size in this function.
xen/common/efi/runtime.c line 7
Quoted 9 lines
xen/common/efi/runtime.c +0
-1@@ -4,17 +4,21 @@#include <xen/guest_access.h> #include <xen/irq.h> #include <xen/time.h> -#include <asm/mc146818rtc.h>
NIT: Missing a blank line here.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH for-4.5 V6 14/14] Add ARM EFI boot support
Quoted 37 lines · Julien Grall
Hi Roy,
Quoted 34 lines · Roy Franz
xen/arch/arm/efi/efi-boot.h new file +34
-0+static int __init fdt_set_reg (void *fdt,int node,int addr_cells, +int size_cells,uint64_t addr,uint64_t len) +{ +uint8_t data[16 ];/* at most 2 64 bit words */ +void *p = data; + +/* Make sure that the values provided can be represented in +* the reg property. +*/ +if ( addr_cells ==1 && (addr >>32 ) ) +return -1 ; +if ( size_cells ==1 && (len >>32 ) ) +return -1 ; + +if ( addr_cells ==1 ) + { + *(uint32_t *)p =cpu_to_fdt32 (addr); + p +=sizeof (uint32_t ); + } +else if ( addr_cells ==2 ) + { + *(uint64_t *)p =cpu_to_fdt64 (addr); + p +=sizeof (uint64_t ); + } +else +return -1 ; + +if ( size_cells ==1 ) + { + *(uint32_t *)p =cpu_to_fdt32 (len); + p +=sizeof (uint32_t ); + } +else if ( size_cells ==2 ) + {
Quoted 8 lines
xen/arch/arm/efi/efi-boot.h line 118
Quoted 5 lines
xen/arch/arm/efi/efi-boot.h new file +5
-0+ *(uint64_t *)p =cpu_to_fdt64 (len); + p +=sizeof (uint64_t ); + } +else +return -1 ;You could give a look to
dt_set_cell(xen/common/device_tree.c). I think it will fit to your usage and avoid open coding size in this function.
I think this will work - I'll take a closer look to confirm. This would clean this code
up a fair bit.
Quoted 12 lines
xen/common/efi/runtime.c line 7
Quoted 10 lines
xen/common/efi/runtime.c +0
-1@@ -4,17 +4,21 @@#include <xen/guest_access.h> #include <xen/irq.h> #include <xen/time.h> -#include <asm/mc146818rtc.h> NIT: Missing a blank line here.
I'll fix this.
Thanks,
Roy
Quoted 5 lines
Regards,
--
Julien Grall
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 07:02, <[email protected]> wrote:
Open feedback:
* moving extern declaration ofefi_l4_pgtable. I have left this x86 specific declaration in the x86 specificefi-boot.hfile, as I don't see a clearly better place to put it.
Since runtime.c (hopefully) doesn't include efi-boot.h, this is certainly not a viable option - files defining variables should include the headers declaring them.
Jan
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 07:02, <[email protected]> wrote:
Open feedback:
* moving extern declaration ofefi_l4_pgtable. I have left this x86 specific declaration in the x86 specificefi-boot.hfile, as I don't see a clearly better place to put it.
Quoted 6 lines
Since
runtime.c(hopefully) doesn't includeefi-boot.h, this is certainly not a viable option - files defining variables should include the headers declaring them.Jan
I'll move it and add a #ifdef