[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH V4 15/15] Add ARM EFI boot support



On Thu, Sep 11, 2014 at 5:49 PM, Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> wrote:
On Tue, 9 Sep 2014, Roy Franz wrote:
> This 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.
>
> Signed-off-by: Roy Franz <roy.franz@xxxxxxxxxx>
> ---
> config/arm64.mk          Â| Â1 +
>Â xen/arch/arm/arm64/head.SÂ Â Â Â Â Â| 150 ++++++++-
>Â xen/arch/arm/xen.lds.SÂ Â Â Â Â Â Â |Â Â1 +
> xen/common/Makefile        Â| Â1 +
> xen/common/efi/Makefile      Â| Â3 +
>Â xen/include/asm-arm/arm64/efibind.h | 216 +++++++++++++
> xen/include/asm-arm/efi-boot.h   | 630 ++++++++++++++++++++++++++++++++++++
> xen/include/asm-arm/efi.h     Â| 29 ++
> xen/include/asm-arm/efibind.h   Â| Â2 +
> xen/include/asm-arm/setup.h    Â| Â2 +-
>Â 10 files changed, 1031 insertions(+), 4 deletions(-)
>Â create mode 100644 xen/common/efi/Makefile
>Â create mode 100644 xen/include/asm-arm/arm64/efibind.h
>Â create mode 100644 xen/include/asm-arm/efi-boot.h
>Â create mode 100644 xen/include/asm-arm/efi.h
>Â create mode 100644 xen/include/asm-arm/efibind.h
>
> diff --git a/config/arm64.mk b/config/arm64.mk
> index 15b57a4..e6aab0e 100644
> --- a/config/arm64.mk
> +++ b/config/arm64.mk
> @@ -1,6 +1,7 @@
>Â CONFIG_ARM := y
>Â CONFIG_ARM_64 := y
>Â CONFIG_ARM_$(XEN_OS) := y
> +CONFIG_EFI := y
>
>Â CONFIG_XEN_INSTALL_SUFFIX :=
>
> diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S
> index 43b5e72..158c102 100644
> --- a/xen/arch/arm/arm64/head.S
> +++ b/xen/arch/arm/arm64/head.S
> @@ -24,6 +24,8 @@
>Â #include <asm/page.h>
>Â #include <asm/asm_defns.h>
>Â #include <asm/early_printk.h>
> +#include <efi/efierr.h>
> +#include <asm/arm64/efibind.h>
>
>Â #define PT_PTÂ Â Â0xf7f /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=1 P=1 */
>Â #define PT_MEMÂ Â 0xf7d /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=0 P=1 */
> @@ -104,8 +106,14 @@ GLOBAL(start)
>Â Â Â Â Â /*
>Â Â Â Â Â Â* DO NOT MODIFY. Image header expected by Linux boot-loaders.
>Â Â Â Â Â Â*/
> -    b   Âreal_start     Â/* branch to kernel start, magic */
> -    .long Â0          /* reserved */
> +efi_head:
> +Â Â Â Â /*
> +Â Â Â Â Â* This add instruction has no meaningful effect except that
> +Â Â Â Â Â* its opcode forms the magic "MZ" signature of a PE/COFF file
> +Â Â Â Â Â* that is required for UEFI applications.
> +Â Â Â Â Â*/
> +    add  Âx13, x18, #0x16
> +    b   Âreal_start     Â/* branch to kernel start */
>     .quad Â0          /* Image load offset from start of RAM */
>     .quad Â0          /* reserved */
>     .quad Â0          /* reserved */
> @@ -116,8 +124,113 @@ GLOBAL(start)
>     .byte Â0x52
>     .byte Â0x4d
>     .byte Â0x64
> -    .word Â0          /* reserved */
> +    .long Âpe_header - efi_head    /* Offset to the PE header. */
> +
> +Â Â Â Â /*
> +    Â* Add the PE/COFF header to the file. The address of this header
> +Â Â Â Â Â* is at offset 0x3c in the file, and is part of Linux "Image"
> +    Â* header. The arm64 Linux Image format is designed to support
> +Â Â Â Â Â* being both an 'Image' format binary and a PE/COFF binary.
> +Â Â Â Â Â* The PE/COFF format is defined by Microsoft, and is available
> +Â Â Â Â Â* from: http://msdn.microsoft.com/en-us/gg463119.aspx
> +Â Â Â Â Â* Version 8.3 adds support for arm64 and UEFI usage.
> +Â Â Â Â Â*/
> +
> +    .align 3
> +pe_header:
> +    .ascii "PE"
> +    .short 0
> +coff_header:
> +    .short 0xaa64             /* AArch64 */
> +    .short 2               Â/* nr_sections */
> +    .long Â0               Â/* TimeDateStamp */
> +    .long Â0               Â/* PointerToSymbolTable */
> +    .long Â1               Â/* NumberOfSymbols */
> +    .short section_table - optional_header /* SizeOfOptionalHeader */
> +    .short 0x206             Â/* Characteristics. */
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â /* IMAGE_FILE_DEBUG_STRIPPED | */
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â /* IMAGE_FILE_EXECUTABLE_IMAGE | */
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â /* IMAGE_FILE_LINE_NUMS_STRIPPED */
> +optional_header:
> +    .short 0x20b             Â/* PE32+ format */
> +    .byte Â0x02              /* MajorLinkerVersion */
> +    .byte Â0x14              /* MinorLinkerVersion */
> +    .long Â_end - real_start       Â/* SizeOfCode */
> +    .long Â0               Â/* SizeOfInitializedData */
> +    .long Â0               Â/* SizeOfUninitializedData */
> +    .long Âefi_start - efi_head      /* AddressOfEntryPoint */
> +    .long Âreal_start - efi_head     Â/* BaseOfCode */
> +
> +extra_header_fields:
> +    .quad Â0               Â/* ImageBase */
> +    .long Â0x1000             /* SectionAlignment (4 KByte) */
> +    .long Â0x8              Â/* FileAlignment */
> +    .short 0               Â/* MajorOperatingSystemVersion */
> +    .short 0               Â/* MinorOperatingSystemVersion */
> +    .short 0               Â/* MajorImageVersion */
> +    .short 0               Â/* MinorImageVersion */
> +    .short 0               Â/* MajorSubsystemVersion */
> +    .short 0               Â/* MinorSubsystemVersion */
> +    .long Â0               Â/* Win32VersionValue */
> +
> +    .long Â_end - efi_head        Â/* SizeOfImage */
> +
> +Â Â Â Â /* Everything before the kernel image is considered part of the header */
> +    .long Âreal_start - efi_head     Â/* SizeOfHeaders */
> +    .long Â0               Â/* CheckSum */
> +    .short 0xa              Â/* Subsystem (EFI application) */
> +    .short 0               Â/* DllCharacteristics */
> +    .quad Â0               Â/* SizeOfStackReserve */
> +    .quad Â0               Â/* SizeOfStackCommit */
> +    .quad Â0               Â/* SizeOfHeapReserve */
> +    .quad Â0               Â/* SizeOfHeapCommit */
> +    .long Â0               Â/* LoaderFlags */
> +    .long Â0x6              Â/* NumberOfRvaAndSizes */
> +
> +    .quad Â0               Â/* ExportTable */
> +    .quad Â0               Â/* ImportTable */
> +    .quad Â0               Â/* ResourceTable */
> +    .quad Â0               Â/* ExceptionTable */
> +    .quad Â0               Â/* CertificationTable */
> +    .quad Â0               Â/* BaseRelocationTable */
> +
> +Â Â Â Â /* Section table */
> +section_table:
>
> +Â Â Â Â /*
> +Â Â Â Â Â* The EFI application loader requires a relocation section
> +    Â* because EFI applications must be relocatable. This is a
> +Â Â Â Â Â* dummy section as far as we are concerned.
> +Â Â Â Â Â*/
> +    .ascii ".reloc"
> +    .byte Â0
> +    .byte Â0               Â/* end of 0 padding of section name */
> +    .long Â0
> +    .long Â0
> +    .long Â0               Â/* SizeOfRawData */
> +    .long Â0               Â/* PointerToRawData */
> +    .long Â0               Â/* PointerToRelocations */
> +    .long Â0               Â/* PointerToLineNumbers */
> +    .short 0               Â/* NumberOfRelocations */
> +    .short 0               Â/* NumberOfLineNumbers */
> +    .long Â0x42100040           /* Characteristics (section flags) */
> +
> +
> +    .ascii ".text"
> +    .byte Â0
> +    .byte Â0
> +    .byte Â0               Â/* end of 0 padding of section name */
> +    .long Â_end - real_start       Â/* VirtualSize */
> +    .long Âreal_start - efi_head     Â/* VirtualAddress */
> +    .long Â__init_end_efi - real_start  Â/* SizeOfRawData */
> +    .long Âreal_start - efi_head     Â/* PointerToRawData */
> +
> +    .long Â0        /* PointerToRelocations (0 for executables) */
> +    .long Â0        /* PointerToLineNumbers (0 for executables) */
> +    .short 0        /* NumberOfRelocations (0 for executables) */
> +    .short 0        /* NumberOfLineNumbers (0 for executables) */
> +    .long Â0xe0500020   Â/* Characteristics (section flags) */
> +    .align 5
>Â real_start:
>     msr ÂDAIFSet, 0xf     Â/* Disable all interrupts */
>
> @@ -617,6 +730,37 @@ putn:Â Âret
>Â ENTRY(lookup_processor_type)
>     mov x0, #0
>Â Â Â Â Â ret
> +/*
> + *Â Function to transition from EFI loader in C, to Xen entry point.
> + *Â void noreturn efi_xen_start(void *fdt_ptr);
> + */
> +ENTRY(efi_xen_start)
> +Â Â Â Â /*
> +Â Â Â Â Â* Turn off cache and MMU as Xen expects. EFI enables them, but also
> +Â Â Â Â Â* mandates a 1:1 (unity) VA->PA mapping, so we can turn off the
> +Â Â Â Â Â* MMU while executing EFI code before entering Xen.
> +Â Â Â Â Â* The EFI loader calls this to start Xen.
> +Â Â Â Â Â* Preserve x0 (fdf pointer) across call to __flush_dcache_all,
> +Â Â Â Â Â* restore for entry into Xen.
> +Â Â Â Â Â*/
> +    mov Âx20, x0
> +    bl  __flush_dcache_all
> +    ic  ialluis
> +
> +Â Â Â Â /* Turn off Dcache and MMU */
> +    mrs Âx0, sctlr_el2
> +    bic Âx0, x0, #1 << 0    /* clear SCTLR.M */
> +    bic Âx0, x0, #1 << 2    /* clear SCTLR.C */

dsb?

The dsb is done at the end of Â__flush_dcache_all



> +    msr Âsctlr_el2, x0
> +Â Â Â Â isb
> +
> +Â Â Â Â /* Jump to Xen entry point */
> +    mov Âx0, x20
> +    mov Âx1, xzr
> +    mov Âx2, xzr
> +    mov Âx3, xzr
> +    b  Âreal_start
> +ENDPROC(efi_xen_start)
>
>Â /*
>Â Â* Local variables:
> diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S
> index 079e085..d8b0cfe 100644
> --- a/xen/arch/arm/xen.lds.S
> +++ b/xen/arch/arm/xen.lds.S
> @@ -135,6 +135,7 @@ SECTIONS
>Â Â Â Â Â*(.xsm_initcall.init)
>Â Â Â Â Â__xsm_initcall_end = .;
>Â Â } :text
> +Â __init_end_efi = .;
>Â Â . = ALIGN(STACK_SIZE);
>Â Â __init_end = .;
>
> diff --git a/xen/common/Makefile b/xen/common/Makefile
> index 3683ae3..e78cb29 100644
> --- a/xen/common/Makefile
> +++ b/xen/common/Makefile
> @@ -67,4 +67,5 @@ subdir-$(x86_64) += hvm
>Â subdir-$(coverage) += gcov
>
>Â subdir-y += libelf
> +subdir-$(CONFIG_EFI) += efi
>Â subdir-$(HAS_DEVICE_TREE) += libfdt
> diff --git a/xen/common/efi/Makefile b/xen/common/efi/Makefile
> new file mode 100644
> index 0000000..195b2f3
> --- /dev/null
> +++ b/xen/common/efi/Makefile
> @@ -0,0 +1,3 @@
> +CFLAGS += -fshort-wchar
> +
> +obj-y += boot.init.o
> diff --git a/xen/include/asm-arm/arm64/efibind.h b/xen/include/asm-arm/arm64/efibind.h
> new file mode 100644
> index 0000000..2b0bf40
> --- /dev/null
> +++ b/xen/include/asm-arm/arm64/efibind.h
> @@ -0,0 +1,216 @@
> +/*++
> +
> +Copyright (c) 1998Â Intel Corporation
> +
> +Module Name:
> +
> +Â Â efefind.h
> +
> +Abstract:
> +
> +Â Â EFI to compile bindings
> +
> +
> +
> +
> +Revision History
> +
> +--*/
> +
> +#ifndef __GNUC__
> +#pragma pack()
> +#endif
> +
> +#define EFIERR(a)Â Â Â Â Â Â(0x8000000000000000 | a)
> +#define EFI_ERROR_MASKÂ Â Â 0x8000000000000000
> +#define EFIERR_OEM(a)Â Â Â Â(0xc000000000000000 | a)
> +
> +#define BAD_POINTERÂ Â Â Â Â0xFBFBFBFBFBFBFBFB
> +#define MAX_ADDRESSÂ Â Â Â Â0xFFFFFFFFFFFFFFFF
> +
> +#define EFI_STUB_ERRORÂ Â Â MAX_ADDRESS
> +
> +#ifndef __ASSEMBLY__
> +//
> +// Basic int types of various widths
> +//
> +
> +#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )
> +
> +Â Â // No ANSI C 1999/2000 stdint.h integer width declarations
> +
> +Â Â #if defined(__GNUC__)
> +    typedef unsigned long long uint64_t __attribute__((aligned (8)));
> +    typedef long long     Âint64_t __attribute__((aligned (8)));
> +    typedef unsigned int    uint32_t;
> +    typedef int        Âint32_t;
> +    typedef unsigned short   uint16_t;
> +    typedef short       Âint16_t;
> +    typedef unsigned char   Âuint8_t;
> +    typedef char        int8_t;
> +Â Â #elif defined(UNIX_LP64)
> +
> +Â Â Â Â /*Â Use LP64 programming model from C_FLAGS for integer width declarations */
> +
> +   Âtypedef unsigned long   Âuint64_t;
> +   Âtypedef long        int64_t;
> +   Âtypedef unsigned int    uint32_t;
> +   Âtypedef int        Âint32_t;
> +   Âtypedef unsigned short   uint16_t;
> +   Âtypedef short       Âint16_t;
> +   Âtypedef unsigned char   Âuint8_t;
> +   Âtypedef char        int8_t;
> +Â Â #else
> +
> +Â Â Â Â/*Â Assume P64 programming model from C_FLAGS for integer width declarations */
> +
> +   Âtypedef unsigned long long uint64_t __attribute__((aligned (8)));
> +   Âtypedef long long     Âint64_t __attribute__((aligned (8)));
> +   Âtypedef unsigned int    uint32_t;
> +   Âtypedef int        Âint32_t;
> +   Âtypedef unsigned short   uint16_t;
> +   Âtypedef short       Âint16_t;
> +   Âtypedef unsigned char   Âuint8_t;
> +   Âtypedef char        int8_t;
> +Â Â #endif
> +#endif
> +
> +//
> +// Basic EFI types of various widths
> +//
> +
> +#ifndef __WCHAR_TYPE__
> +# define __WCHAR_TYPE__ short
> +#endif
> +
> +typedef uint64_t ÂUINT64;
> +typedef int64_t  INT64;
> +
> +#ifndef _BASETSD_H_
> +  typedef uint32_t ÂUINT32;
> +  typedef int32_t  INT32;
> +#endif
> +
> +typedef uint16_t ÂUINT16;
> +typedef int16_t  INT16;
> +typedef uint8_t  UINT8;
> +typedef int8_t  ÂINT8;
> +typedef __WCHAR_TYPE__ WCHAR;
> +
> +#undef VOID
> +#define VOIDÂ Â void
> +
> +
> +typedef int64_t  INTN;
> +typedef uint64_t ÂUINTN;
> +
> +#define POST_CODE(_Data)
> +
> +
> +#define BREAKPOINT()Â Â Â Â while (TRUE);Â Â // Make it hang on Bios[Dbg]32
> +
> +//
> +// Pointers must be aligned to these address to function
> +//
> +
> +#define MIN_ALIGNMENT_SIZEÂ 4
> +
> +#define ALIGN_VARIABLE(Value ,Adjustment) \
> +Â Â Â Â Â Â (UINTN)Adjustment = 0; \
> +Â Â Â Â Â Â if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
> +Â Â Â Â Â Â Â Â (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
> +Â Â Â Â Â Â Value = (UINTN)Value + (UINTN)Adjustment
> +
> +
> +//
> +// Define macros to build data structure signatures from characters.
> +//
> +
> +#define EFI_SIGNATURE_16(A,B)Â Â Â Â Â Â Â((A) | (B<<8))
> +#define EFI_SIGNATURE_32(A,B,C,D)Â Â Â Â Â(EFI_SIGNATURE_16(A,B)Â Â Â| (EFI_SIGNATURE_16(C,D)Â Â Â<< 16))
> +#define EFI_SIGNATURE_64(A,B,C,D,E,F,G,H) (EFI_SIGNATURE_32(A,B,C,D) | ((UINT64)(EFI_SIGNATURE_32(E,F,G,H)) << 32))
> +
> +#define EXPORTAPI
> +
> +
> +//
> +// EFIAPI - prototype calling convention for EFI function pointers
> +// BOOTSERVICE - prototype for implementation of a boot service interface
> +// RUNTIMESERVICE - prototype for implementation of a runtime service interface
> +// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
> +// RUNTIME_CODE - pragma macro for declaring runtime code
> +//
> +
> +#ifndef EFIAPIÂ Â Â Â Â Â Â Â Â // Forces EFI calling conventions reguardless of compiler options
> +Â Â Â Â #define EFIAPIÂ Â Â Â Â // Substitute expresion to force C calling convention
> +#endif
> +
> +#define BOOTSERVICE
> +//#define RUNTIMESERVICE(proto,a)Â Â alloc_text("rtcode",a); proto a
> +//#define RUNTIMEFUNCTION(proto,a)Â Âalloc_text("rtcode",a); proto a
> +#define RUNTIMESERVICE
> +#define RUNTIMEFUNCTION
> +
> +
> +#define RUNTIME_CODE(a)Â Â Â Â Âalloc_text("rtcode", a)
> +#define BEGIN_RUNTIME_DATA()Â Â data_seg("rtdata")
> +#define END_RUNTIME_DATA()Â Â Â data_seg("")
> +
> +#define VOLATILEÂ Â volatile
> +
> +#define MEMORY_FENCE()
> +
> +
> +//
> +// When build similiar to FW, then link everything together as
> +// one big module.
> +//
> +
> +#define EFI_DRIVER_ENTRY_POINT(InitFunction)Â Â \
> +Â Â UINTNÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> +Â Â InitializeDriver (Â Â Â Â Â Â Â Â Â Â Â Â Â \
> +    VOID  *ImageHandle,         Â\
> +    VOID  *SystemTable          \
> +Â Â Â Â )Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> +Â Â {Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> +    return InitFunction(ImageHandle,    \
> +Â Â Â Â Â Â Â Â SystemTable);Â Â Â Â Â Â Â Â Â Â\
> +Â Â }Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> +Â Â EFI_STATUS efi_main(Â Â Â Â Â Â Â Â Â Â Â Â \
> +    EFI_HANDLE image,           Â\
> +    EFI_SYSTEM_TABLE *systab        \
> +    ) __attribute__((weak,         \
> +Â Â Â Â Â Â Â Â alias ("InitializeDriver")));
> +
> +#define LOAD_INTERNAL_DRIVER(_if, type, name, entry)Â Â \
> +Â Â Â Â (_if)->LoadInternal(type, name, entry)
> +
> +
> +//
> +// Some compilers don't support the forward reference construct:
> +//Â typedef struct XXXXX
> +//
> +// The following macro provide a workaround for such cases.
> +//
> +#ifdef NO_INTERFACE_DECL
> +#define INTERFACE_DECL(x)
> +#else
> +#ifdef __GNUC__
> +#define INTERFACE_DECL(x) struct x
> +#else
> +#define INTERFACE_DECL(x) typedef struct x
> +#endif
> +#endif
> +
> +#endif
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * tab-width: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> diff --git a/xen/include/asm-arm/efi-boot.h b/xen/include/asm-arm/efi-boot.h
> new file mode 100644
> index 0000000..2db0966
> --- /dev/null
> +++ b/xen/include/asm-arm/efi-boot.h
> @@ -0,0 +1,630 @@
> +/*
> + * Architecture specific implementation for EFI boot code. This file
> + * is intended to be included by XXX _only_, and therefore can define
> + * arch specific global variables.
> + */
> +#include <xen/libfdt/libfdt.h>
> +#include <asm/setup.h>
> +
> +static void noreturn blexit(const CHAR16 *str);
> +static void PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode);
> +void noreturn efi_xen_start(void *fdt_ptr);
> +
> +#define DEVICE_TREE_GUID \
> +{0xb1b621d5, 0xf19c, 0x41a5, {0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0}}
> +
> +static struct file __initdata dtbfile;
> +static void __initdata *fdt;
> +static void __initdata *memmap;
> +
> +static int __init setup_chosen_node(void *fdt, int *addr_cells, int *size_cells)
> +{
> +Â Â int node;
> +Â Â const struct fdt_property *prop;
> +Â Â int len;
> +Â Â uint32_t val;
> +
> +Â Â if ( !fdt || !addr_cells || !size_cells )
> +Â Â Â Â return -1;
> +
> +Â Â /* locate chosen node, which is where we add Xen module info. */
> +Â Â node = fdt_subnode_offset(fdt, 0, "chosen");
> +Â Â if ( node < 0 )
> +Â Â {
> +Â Â Â Â node = fdt_add_subnode(fdt, 0, "chosen");
> +Â Â Â Â if ( node < 0 )
> +Â Â Â Â Â Â return node;
> +Â Â }
> +
> +Â Â /* Get or set #address-cells and #size-cells */
> +Â Â prop = fdt_get_property(fdt, node, "#address-cells", &len);
> +Â Â if ( !prop )
> +Â Â {
> +Â Â Â Â val = cpu_to_fdt32(2);
> +Â Â Â Â if ( fdt_setprop(fdt, node, "#address-cells", &val, sizeof(val)) )
> +Â Â Â Â Â Â return -1;
> +Â Â Â Â *addr_cells = 2;
> +Â Â }
> +Â Â else
> +Â Â Â Â *addr_cells = fdt32_to_cpu(*((uint32_t *)prop->data));
> +
> +Â Â prop = fdt_get_property(fdt, node, "#size-cells", &len);
> +Â Â if ( !prop )
> +Â Â {
> +Â Â Â Â val = cpu_to_fdt32(2);
> +Â Â Â Â if ( fdt_setprop(fdt, node, "#size-cells", &val, sizeof(val)) )
> +Â Â Â Â Â Â return -1;
> +Â Â Â Â *size_cells = 2;
> +Â Â }
> +Â Â else
> +Â Â Â Â *size_cells = fdt32_to_cpu(*((uint32_t *)prop->data));
> +
> +Â Â /*
> +Â Â Â* Make sure ranges is empty if it exists, otherwise create empty ranges
> +Â Â Â* property.
> +Â Â Â*/
> +Â Â prop = fdt_get_property(fdt, node, "ranges", &len);
> +Â Â if ( !prop )
> +Â Â {
> +Â Â Â Â val = cpu_to_fdt32(0);
> +Â Â Â Â if ( fdt_setprop(fdt, node, "ranges", &val, 0) )
> +Â Â Â Â Â Â return -1;
> +Â Â }
> +Â Â else if ( fdt32_to_cpu(prop->len) )
> +Â Â Â Â Â Â return -1;Â /* Non-empty ranges property */
> +Â Â return node;
> +}
> +
> +/*
> + * Set a single 'reg' property taking into account the
> + * configured addr and size cell sizes.
> + */
> +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 )
> +Â Â {
> +Â Â Â Â *(uint64_t *)p = cpu_to_fdt64(len);
> +Â Â Â Â p += sizeof(uint64_t);
> +Â Â }
> +Â Â else
> +Â Â Â Â return -1;
> +
> +Â Â return(fdt_setprop(fdt, node, "reg", data, p - (void *)data));
> +}
> +
> +static void __init *lookup_fdt_config_table(EFI_SYSTEM_TABLE *sys_table)
> +{
> +Â Â const EFI_GUID fdt_guid = DEVICE_TREE_GUID;
> +Â Â EFI_CONFIGURATION_TABLE *tables;
> +Â Â void *fdt = NULL;
> +Â Â int i;
> +
> +Â Â tables = sys_table->ConfigurationTable;
> +Â Â for ( i = 0; i < sys_table->NumberOfTableEntries; i++ )
> +Â Â {
> +Â Â Â Â if ( match_guid(&tables[i].VendorGuid, &fdt_guid) )
> +Â Â Â Â {
> +Â Â Â Â Â Â fdt = tables[i].VendorTable;
> +Â Â Â Â Â Â break;
> +Â Â Â Â }
> +Â Â }
> +Â Â return fdt;
> +}
> +
> +static EFI_STATUS __init efi_get_memory_map(void **map,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â UINTN *mmap_size,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â UINTN *desc_size,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â UINT32 *desc_ver,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â UINTN *key_ptr)
> +{
> +Â Â EFI_MEMORY_DESCRIPTOR *m = NULL;
> +Â Â EFI_STATUS status;
> +Â Â unsigned long key;
> +Â Â u32 desc_version;
> +
> +Â Â *map = NULL;
> +Â Â *mmap_size = EFI_PAGE_SIZE;
> +again:
> +Â Â *mmap_size += EFI_PAGE_SIZE;Â /* Page size is allocation granularity */
> +Â Â status = efi_bs->AllocatePool(EfiLoaderData, *mmap_size, (void **)&m);
> +Â Â if ( status != EFI_SUCCESS )
> +Â Â Â Â return status;
> +
> +Â Â *desc_size = 0;
> +Â Â key = 0;
> +Â Â status = efi_bs->GetMemoryMap(mmap_size, m, &key, desc_size, &desc_version);
> +Â Â if ( status == EFI_BUFFER_TOO_SMALL )
> +Â Â {
> +Â Â Â Â efi_bs->FreePool(m);
> +Â Â Â Â goto again;
> +Â Â }
> +
> +Â Â if ( status != EFI_SUCCESS )
> +Â Â {
> +Â Â Â Â efi_bs->FreePool(m);
> +Â Â Â Â return status;
> +Â Â }
> +
> +Â Â if ( key_ptr && status == EFI_SUCCESS )
> +Â Â Â Â *key_ptr = key;
> +Â Â if ( desc_ver && status == EFI_SUCCESS )
> +Â Â Â Â *desc_ver = desc_version;
> +
> +Â Â *map = m;
> +Â Â return status;
> +}
> +
> +static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR *map,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â UINTN mmap_size,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â UINTN desc_size)
> +{
> +Â Â int Index;
> +Â Â int i = 0;
> +
> +Â Â EFI_MEMORY_DESCRIPTOR *desc_ptr = map;
> +
> +Â Â for ( Index = 0; Index < (mmap_size / desc_size); Index++ )
> +Â Â {
> +Â Â Â Â if ( desc_ptr->Type == EfiConventionalMemory
> +Â Â Â Â Â Â Â|| desc_ptr->Type == EfiBootServicesCode
> +Â Â Â Â Â Â Â|| desc_ptr->Type == EfiBootServicesData )
> +Â Â Â Â {
> +Â Â Â Â Â Â bootinfo.mem.bank[i].start = desc_ptr->PhysicalStart;
> +Â Â Â Â Â Â bootinfo.mem.bank[i].size = desc_ptr->NumberOfPages * EFI_PAGE_SIZE;
> +Â Â Â Â Â Â if ( ++i >= NR_MEM_BANKS )
> +Â Â Â Â Â Â {
> +Â Â Â Â Â Â Â Â PrintStr(L"Warning: All ");
> +Â Â Â Â Â Â Â Â DisplayUint(NR_MEM_BANKS, -1);
> +Â Â Â Â Â Â Â Â PrintStr(L" bootinfo mem banks exhausted.\r\n");
> +Â Â Â Â Â Â Â Â break;
> +Â Â Â Â Â Â }
> +Â Â Â Â }
> +Â Â Â Â desc_ptr = NextMemoryDescriptor(desc_ptr, desc_size);
> +Â Â }
> +
> +Â Â bootinfo.mem.nr_banks = i;
> +Â Â return EFI_SUCCESS;
> +
> +}
> +
> +/*
> + * Add the FDT nodes for the standard EFI information, which consist
> + * of the System table address, the address of the final EFI memory map,
> + * and memory map information.
> + */
> +EFI_STATUS __init fdt_add_uefi_nodes(EFI_SYSTEM_TABLE *sys_table,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â void *fdt,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â EFI_MEMORY_DESCRIPTOR *memory_map,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â UINTN map_size,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â UINTN desc_size,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â UINT32 desc_ver)
> +{
> +Â Â int node;
> +Â Â int status;
> +Â Â u32 fdt_val32;
> +Â Â u64 fdt_val64;
> +Â Â int prev;
> +Â Â /*
> +  Â* Delete any memory nodes present. The EFI memory map is the only
> +Â Â Â* memory description provided to Xen.
> +Â Â Â*/
> +Â Â prev = 0;
> +Â Â for (;;)
> +Â Â {
> +Â Â Â Â const char *type;
> +Â Â Â Â int len;
> +
> +Â Â Â Â node = fdt_next_node(fdt, prev, NULL);
> +Â Â Â Â if ( node < 0 )
> +Â Â Â Â Â Â break;
> +
> +Â Â Â Â type = fdt_getprop(fdt, node, "device_type", &len);
> +Â Â Â Â if ( type && strncmp(type, "memory", len) == 0 )
> +Â Â Â Â {
> +Â Â Â Â Â Â fdt_del_node(fdt, node);
> +Â Â Â Â Â Â continue;
> +Â Â Â Â }
> +
> +Â Â Â Â prev = node;
> +Â Â }
> +
> +Â Â /* Add FDT entries for EFI runtime services in chosen node. */
> +Â Â node = fdt_subnode_offset(fdt, 0, "chosen");
> +Â Â if ( node < 0 )
> +Â Â {
> +Â Â Â Â node = fdt_add_subnode(fdt, 0, "chosen");
> +Â Â Â Â if ( node < 0 )
> +Â Â Â Â {
> +Â Â Â Â Â Â status = node; /* node is error code when negative */
> +Â Â Â Â Â Â goto fdt_set_fail;
> +Â Â Â Â }
> +Â Â }

setup_chosen_node?

Yes, this should be done here as well. ÂI will add that for the case of creating
a new FDT.Â


> +Â Â fdt_val64 = cpu_to_fdt64((u64)(uintptr_t)sys_table);
> +Â Â status = fdt_setprop(fdt, node, "linux,uefi-system-table",
> +Â Â Â Â Â Â Â Â Â Â Â Â Â&fdt_val64, sizeof(fdt_val64));
> +Â Â if ( status )
> +Â Â Â Â goto fdt_set_fail;
> +
> +Â Â fdt_val64 = cpu_to_fdt64((u64)(uintptr_t)memory_map);
> +Â Â status = fdt_setprop(fdt, node, "linux,uefi-mmap-start",
> +            Â&fdt_val64, sizeof(fdt_val64));
> +Â Â if ( status )
> +Â Â Â Â goto fdt_set_fail;
> +
> +Â Â fdt_val32 = cpu_to_fdt32(map_size);
> +Â Â status = fdt_setprop(fdt, node, "linux,uefi-mmap-size",
> +            Â&fdt_val32, sizeof(fdt_val32));
> +Â Â if ( status )
> +Â Â Â Â goto fdt_set_fail;
> +
> +Â Â fdt_val32 = cpu_to_fdt32(desc_size);
> +Â Â status = fdt_setprop(fdt, node, "linux,uefi-mmap-desc-size",
> +Â Â Â Â Â Â Â Â Â Â Â Â Â&fdt_val32, sizeof(fdt_val32));
> +Â Â if ( status )
> +Â Â Â Â goto fdt_set_fail;
> +
> +Â Â fdt_val32 = cpu_to_fdt32(desc_ver);
> +Â Â status = fdt_setprop(fdt, node, "linux,uefi-mmap-desc-ver",
> +Â Â Â Â Â Â Â Â Â Â Â Â Â&fdt_val32, sizeof(fdt_val32));
> +Â Â if ( status )
> +Â Â Â Â goto fdt_set_fail;
> +
> +Â Â return EFI_SUCCESS;
> +
> +fdt_set_fail:
> +Â Â if ( status == -FDT_ERR_NOSPACE )
> +Â Â Â Â return EFI_BUFFER_TOO_SMALL;
> +
> +Â Â return EFI_LOAD_ERROR;
> +}
> +
> +/*
> + * Allocates new memory for a larger FDT, and frees existing memory if
> + * struct file size is non-zero. Updates file struct with new memory
> + * address/size for later freeing. If fdtfile.ptr is NULL, an empty FDT
> + * is created.
> + */
> +static void __init *fdt_increase_size(struct file *fdtfile, int add_size)
> +{
> +Â Â EFI_STATUS status;
> +Â Â EFI_PHYSICAL_ADDRESS fdt_addr;
> +Â Â int fdt_size;
> +Â Â int pages;
> +Â Â void *new_fdt;
> +
> +Â Â if ( fdtfile->ptr )
> +Â Â Â Â fdt_size = fdt_totalsize(fdtfile->ptr);
> +Â Â else
> +Â Â Â Â fdt_size = 0;
> +
> +Â Â pages = PFN_UP(fdt_size) + PFN_UP(add_size);

Shouldn't this be PFN_UP(fdt_size+add_size)?
Yup, I will fix this.Â


> +Â Â status = efi_bs->AllocatePages(AllocateAnyPages, EfiLoaderData,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âpages, &fdt_addr);
> +
> +Â Â if ( status != EFI_SUCCESS )
> +Â Â Â Â return NULL;
> +
> +Â Â new_fdt = (void *)fdt_addr;
> +
> +Â Â if ( fdt_size )
> +Â Â {
> +Â Â Â Â if ( fdt_open_into(dtbfile.ptr, new_fdt, pages * EFI_PAGE_SIZE) )
> +Â Â Â Â Â Â return NULL;
> +Â Â }
> +Â Â else
> +Â Â {
> +Â Â Â Â /*
> +Â Â Â Â Â* Create an empty FDT if not provided one, which is the expected case
> +    Â* when booted from the UEFI shell on an ACPI only system. We will use
> +Â Â Â Â Â* the FDT to pass the EFI information to Xen, as well as nodes for
> +    Â* any modules the stub loads. The ACPI tables are part of the UEFI
> +Â Â Â Â Â* system table that is passed in the FDT.
> +Â Â Â Â Â*/
> +Â Â Â Â if ( fdt_create_empty_tree(new_fdt, pages * EFI_PAGE_SIZE) )
> +Â Â Â Â Â Â return NULL;
> +Â Â }
> +
> +Â Â /*
> +Â Â Â* Now that we have the new FDT allocated and copied, free the
> +Â Â Â* original and update the struct file so that the error handling
> +  Â* code will free it. If the original FDT came from a configuration
> +Â Â Â* table, we don't own that memory and can't free it.
> +Â Â Â*/
> +Â Â if ( dtbfile.size )
> +Â Â Â Â efi_bs->FreePages(dtbfile.addr, PFN_UP(dtbfile.size));
> +
> +Â Â /* Update 'file' info for new memory so we clean it up on error exits */
> +Â Â dtbfile.addr = fdt_addr;
> +Â Â dtbfile.size = pages * EFI_PAGE_SIZE;
> +Â Â return new_fdt;
> +}
> +
> +static void __init efi_arch_pci(void)
> +{
> +}
> +
> +static void __init efi_arch_relocate_image(unsigned long delta)
> +{
> +}
> +
> +static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âvoid *map,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂUINTN map_size,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂUINTN desc_size,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂUINT32 desc_ver)
> +{
> +Â Â EFI_STATUS status;
> +
> +Â Â status = efi_process_memory_map_bootinfo(map, map_size, desc_size);
> +Â Â if ( EFI_ERROR(status) )
> +Â Â Â Â blexit(L"ERROR processing EFI memory map\r\n");
> +
> +Â Â status = fdt_add_uefi_nodes(SystemTable, fdt, map, map_size, desc_size,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â desc_ver);
> +Â Â if ( EFI_ERROR(status) )
> +Â Â Â Â PrintErrMesg(L"ERROR updating FDT\r\n", status);
> +}
> +
> +static void __init efi_arch_pre_exit_boot(void)
> +{
> +}
> +
> +static void __init efi_arch_post_exit_boot(void)
> +{
> +Â Â efi_xen_start(fdt);
> +}
> +
> +static void __init efi_arch_cfg_file(EFI_FILE_HANDLE dir_handle, char *section)
> +{
> +Â Â union string name;
> +Â Â name.s = get_value(&cfg, section, "dtb");
> +Â Â if ( name.s )
> +Â Â {
> +Â Â Â Â if ( !read_file(dir_handle, &dtbfile, name.s))
> +Â Â Â Â Â Â blexit(NULL);
> +Â Â }
> +Â Â fdt = fdt_increase_size(&dtbfile, cfg.size + EFI_PAGE_SIZE);
> +Â Â if ( !fdt )
> +Â Â Â Â blexit(L"Unable to create new FDT\r\n");
> +}
> +
> +static void __init efi_arch_get_memory_map(UINTN *map_size,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âvoid **map,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂUINTN *map_key, UINTN *desc_size,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂUINT32 *desc_ver)
> +{
> +Â Â EFI_STATUS status;
> +
> +Â Â status = efi_get_memory_map(map, map_size, desc_size, desc_ver, map_key);
> +Â Â if ( EFI_ERROR(status) )
> +Â Â Â Â blexit(L"ERROR getting EFI memory map.\r\n");
> +Â Â memmap = *map;
> +}
> +
> +static void __init efi_arch_edd(void)
> +{
> +}
> +
> +static void __init efi_arch_video(bool_t base_video,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â UINTN cols, UINTN rows, UINTN depth,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
> +{
> +}
> +
> +static void __init efi_arch_memory(void)
> +{
> +}
> +
> +static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂCHAR16 *cmdline_options,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âchar *cfgfile_options)
> +{
> +Â Â union string name;
> +Â Â char *buf;
> +Â Â EFI_STATUS status;
> +Â Â int prop_len;
> +Â Â int chosen;
> +
> +Â Â /* locate chosen node, which is where we add Xen module info. */
> +Â Â chosen = fdt_subnode_offset(fdt, 0, "chosen");
> +Â Â if ( chosen < 0 )
> +Â Â Â Â blexit(L"ERROR unable to find chosen node\r\n");
> +
> +Â Â status = efi_bs->AllocatePool(EfiBootServicesData, EFI_PAGE_SIZE, (void **)&buf);
> +Â Â if ( EFI_ERROR(status) )
> +Â Â Â Â PrintErrMesg(L"ERROR allocating memory.\r\n", status);
> +
> +Â Â if ( image_name )
> +Â Â {
> +Â Â Â Â name.w = image_name;
> +Â Â Â Â w2s(&name);
> +Â Â }
> +Â Â else
> +Â Â Â Â name.s = "xen";
> +
> +Â Â prop_len = 0;
> +Â Â prop_len += snprintf(buf + prop_len,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â ÂEFI_PAGE_SIZE - prop_len, "%s", name.s);
> +Â Â if ( prop_len >= EFI_PAGE_SIZE )
> +Â Â Â Â blexit(L"FDT string overflow");
> +
> +Â Â if ( cfgfile_options )
> +Â Â {
> +Â Â Â Â prop_len += snprintf(buf + prop_len,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂEFI_PAGE_SIZE - prop_len, " %s", cfgfile_options);
> +Â Â Â Â if ( prop_len >= EFI_PAGE_SIZE )
> +Â Â Â Â Â Â blexit(L"FDT string overflow");
> +Â Â }
> +
> +Â Â if ( cmdline_options )
> +Â Â {
> +Â Â Â Â name.w = cmdline_options;
> +Â Â Â Â w2s(&name);
> +Â Â }
> +Â Â else
> +Â Â Â Â name.s = NULL;
> +
> +Â Â if ( name.s )
> +Â Â {
> +Â Â Â Â prop_len += snprintf(buf + prop_len,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂEFI_PAGE_SIZE - prop_len, " %s", name.s);
> +Â Â Â Â if ( prop_len >= EFI_PAGE_SIZE )
> +Â Â Â Â Â Â blexit(L"FDT string overflow");
> +Â Â }
> +
> +Â Â if ( fdt_setprop_string(fdt, chosen, "xen,xen-bootargs", buf) < 0 )
> +Â Â Â Â blexit(L"unable to set xen,xen-bootargs property.");
> +
> +Â Â efi_bs->FreePool(buf);
> +}
> +
> +static void __init efi_arch_handle_module(struct file *file, char *name,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â char *options)
> +{
> +Â Â int node;
> +Â Â int chosen;
> +Â Â int addr_len, size_len;
> +
> +Â Â if ( file == &dtbfile )
> +Â Â Â Â return;
> +Â Â chosen = setup_chosen_node(fdt, &addr_len, &size_len);
> +Â Â if ( chosen < 0 )
> +Â Â Â Â blexit(L"Unable to setup chosen node\r\n");
> +
> +Â Â if ( file == &ramdisk )
> +Â Â {
> +Â Â Â Â char ramdisk_compat[] = "multiboot,ramdisk\0multiboot,module";
> +Â Â Â Â node = fdt_add_subnode(fdt, chosen, "ramdisk");
> +Â Â Â Â if ( node < 0 )
> +Â Â Â Â Â Â blexit(L"Error adding ramdisk FDT node.");
> +Â Â Â Â if ( fdt_setprop(fdt, node, "compatible", ramdisk_compat,
> +Â Â Â Â Â Â Â Â Â Â Â Â Âsizeof(ramdisk_compat)) < 0 )
> +Â Â Â Â Â Â blexit(L"unable to set compatible property.");
> +Â Â Â Â if ( fdt_set_reg(fdt, node, addr_len, size_len, ramdisk.addr,
> +Â Â Â Â Â Â Â Â Â Â ramdisk.size) < 0 )
> +Â Â Â Â Â Â blexit(L"unable to set reg property.");
> +Â Â }
> +Â Â else if ( file == &xsm )
> +Â Â {
> +Â Â Â Â char xsm_compat[] = "xen,xsm-policy\0multiboot,module";
> +Â Â Â Â node = fdt_add_subnode(fdt, chosen, "xsm");
> +Â Â Â Â if ( node < 0 )
> +Â Â Â Â Â Â blexit(L"Error adding xsm FDT node.");
> +Â Â Â Â if ( fdt_setprop(fdt, node, "compatible", xsm_compat,
> +Â Â Â Â Â Â Â Â Â Â Â Â Âsizeof(xsm_compat)) < 0 )
> +Â Â Â Â Â Â blexit(L"unable to set compatible property.");
> +Â Â Â Â if ( fdt_set_reg(fdt, node, addr_len, size_len, xsm.addr,
> +Â Â Â Â Â Â Â Â Â Â xsm.size) < 0 )
> +Â Â Â Â Â Â blexit(L"unable to set reg property.");
> +Â Â }
> +Â Â else if ( file == &kernel )
> +Â Â {
> +Â Â Â Â char kernel_compat[] = "multiboot,kernel\0multiboot,module";
> +Â Â Â Â node = fdt_add_subnode(fdt, chosen, "kernel");
> +Â Â Â Â if ( node < 0 )
> +Â Â Â Â Â Â blexit(L"Error adding dom0 FDT node.");
> +Â Â Â Â if ( fdt_setprop(fdt, node, "compatible", kernel_compat,
> +Â Â Â Â Â Â Â Â Â Â Â Â Âsizeof(kernel_compat)) < 0 )
> +Â Â Â Â Â Â blexit(L"unable to set compatible property.");
> +Â Â Â Â if ( options && fdt_setprop_string(fdt, node, "bootargs", options) < 0 )
> +Â Â Â Â Â Â blexit(L"unable to set bootargs property.");
> +Â Â Â Â if ( fdt_set_reg(fdt, node, addr_len, size_len, kernel.addr,
> +Â Â Â Â Â Â Â Â Â Â Â Â Âkernel.size) < 0 )
> +Â Â Â Â Â Â blexit(L"unable to set reg property.");
> +Â Â }
> +Â Â else
> +Â Â Â Â blexit(L"Unknown module type\r\n");
> +}
> +
> +static void __init efi_arch_cpu(void)
> +{
> +}
> +
> +static void __init efi_arch_smbios(void)
> +{
> +}
> +
> +static void __init efi_arch_blexit(void)
> +{
> +Â Â if ( dtbfile.addr && dtbfile.size )
> +Â Â Â Â efi_bs->FreePages(dtbfile.addr, PFN_UP(dtbfile.size));
> +Â Â if ( memmap )
> +Â Â Â Â efi_bs->FreePool(memmap);
> +}
> +
> +static void __init efi_arch_load_addr_check(EFI_LOADED_IMAGE *loaded_image)
> +{
> +Â Â if ( (unsigned long)loaded_image->ImageBase & ((1 << 12) - 1) )
> +Â Â Â Â blexit(L"Xen must be loaded at a 4 KByte boundary.");
> +}
> +
> +static void __init efi_arch_runtime_setup(EFI_SYSTEM_TABLE *SystemTable)
> +{
> +}
> +
> +static __init bool_t efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)
> +{
> +Â Â /*
> +Â Â Â* For arm, we may get a device tree from GRUB (or other bootloader)
> +  Â* that contains modules that have already been loaded into memory. In
> +Â Â Â* this case, we do not use a configuration file, and rely on the
> +Â Â Â* bootloader to have loaded all required modules and appropriate
> +Â Â Â* options.
> +Â Â Â*/
> +
> +Â Â fdt = lookup_fdt_config_table(SystemTable);
> +Â Â dtbfile.ptr = fdt;
> +Â Â dtbfile.size = 0;Â /* Config table memory can't be freed, so set size to 0 */
> +Â Â if ( !fdt || fdt_node_offset_by_compatible(fdt, 0, "multiboot,module") < 0 )
> +Â Â {
> +Â Â Â Â /*
> +Â Â Â Â Â* We either have no FDT, or one without modules, so we must have a
> +    Â* Xen EFI configuration file to specify modules. (dom0 required)
> +Â Â Â Â Â*/
> +Â Â Â Â return 1;
> +Â Â }
> +Â Â PrintStr(L"Using modules provided by bootloader in FDT\r\n");
> +Â Â /* We have modules already defined in fdt, just add space. */
> +Â Â fdt = fdt_increase_size(&dtbfile, EFI_PAGE_SIZE);
> +Â Â return 0;
> +}
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> diff --git a/xen/include/asm-arm/efi.h b/xen/include/asm-arm/efi.h
> new file mode 100644
> index 0000000..aae4716
> --- /dev/null
> +++ b/xen/include/asm-arm/efi.h
> @@ -0,0 +1,29 @@
> +#include <asm/efibind.h>
> +#include <efi/efidef.h>
> +#include <efi/efierr.h>
> +#include <efi/eficon.h>
> +#include <efi/efidevp.h>
> +#include <efi/eficapsule.h>
> +#include <efi/efiapi.h>
> +#include <xen/efi.h>
> +#include <xen/spinlock.h>
> +#include <asm/page.h>
> +
> +extern unsigned int efi_num_ct;
> +extern EFI_CONFIGURATION_TABLE *efi_ct;
> +
> +extern unsigned int efi_version, efi_fw_revision;
> +extern const CHAR16 *efi_fw_vendor;
> +
> +extern EFI_RUNTIME_SERVICES *efi_rs;
> +
> +extern UINTN efi_memmap_size, efi_mdesc_size;
> +extern void *efi_memmap;
> +
> +extern const struct efi_pci_rom *efi_pci_roms;
> +
> +extern UINT64 efi_boot_max_var_store_size, efi_boot_remain_var_store_size,
> +Â Â Â Â Â Â Â efi_boot_max_var_size;
> +
> +unsigned long efi_rs_enter(void);
> +void efi_rs_leave(unsigned long);
> diff --git a/xen/include/asm-arm/efibind.h b/xen/include/asm-arm/efibind.h
> new file mode 100644
> index 0000000..09dca7a
> --- /dev/null
> +++ b/xen/include/asm-arm/efibind.h
> @@ -0,0 +1,2 @@
> +#include <xen/types.h>
> +#include <asm/arm64/efibind.h>
> diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h
> index 36e5704..40814e6 100644
> --- a/xen/include/asm-arm/setup.h
> +++ b/xen/include/asm-arm/setup.h
> @@ -3,7 +3,7 @@
>
>Â #include <public/version.h>
>
> -#define NR_MEM_BANKS 8
> +#define NR_MEM_BANKS 32

Why?
At the very least you should write it in the commit message.

In the EFI case, we have the EFI memory map which lists all memory by region and usage Â(ie available, boot_services, runtime, etc.)
not the physical memory banks that are provided by FDT. ÂI am putting the available memory from the EFI memory map into the memory bank
list, so this requires more entries. ÂThis is somewhat problematic as it is possible for the EFI memory map to be very fragmented, which could lead
to a great many regions.

Roy



>Â #define MAX_MODULES 5 /* Current maximum useful modules */
>
> --
> 2.1.0.rc1
>

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.