Skip to contentSkip to conversation

arm64 EFI stub

PATCH Superseded Roy Franz 3 participants 63 messages Sep 18, 2014 – Sep 24, 2014

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Roy Franz

author
#0 lore raw

v5 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.

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 (15):
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 add arm64 cache flushing code from linux v3.16
Update libfdt to v1.4.0
Add ARM EFI boot support

 .gitignore                             |   8 +
 xen/Makefile                           |   1 +
 xen/arch/arm/Makefile                  |   1 +
 xen/arch/arm/arm64/Makefile            |   1 +
 xen/arch/arm/arm64/cache.S             | 100 ++++
 xen/arch/arm/arm64/head.S              | 150 +++++-
 xen/arch/arm/efi/Makefile              |   4 +
 xen/arch/arm/xen.lds.S                 |   1 +
 xen/{arch/x86 => common}/efi/boot.c    | 835 ++++++++-------------------------
 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/common/libfdt/Makefile.libfdt      |   4 +-
 xen/common/libfdt/fdt.c                |  30 +-
 xen/common/libfdt/fdt_empty_tree.c     |  84 ++++
 xen/common/libfdt/fdt_ro.c             |   7 +-
 xen/common/libfdt/fdt_rw.c             |  31 +-
 xen/common/libfdt/fdt_sw.c             |   4 +-
 xen/common/libfdt/fdt_wip.c            |   2 +-
 xen/common/libfdt/version.lds          |   6 +
 xen/include/asm-arm/arm64/efibind.h    | 216 +++++++++
 xen/include/asm-arm/efi-boot.h         | 593 +++++++++++++++++++++++
 xen/include/asm-arm/efibind.h          |   2 +
 xen/include/asm-arm/setup.h            |   2 +-
 xen/include/asm-x86/efi-boot.h         | 645 +++++++++++++++++++++++++
 xen/include/xen/libfdt/fdt.h           |  93 +++-
 xen/include/xen/libfdt/libfdt.h        | 315 ++++++++++++-
 xen/include/xen/libfdt/libfdt_env.h    |   4 +
 28 files changed, 2460 insertions(+), 696 deletions(-)
 create mode 100644 xen/arch/arm/arm64/cache.S
 create mode 100644 xen/arch/arm/efi/Makefile
 rename xen/{arch/x86 => common}/efi/boot.c (57%)
 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/common/libfdt/fdt_empty_tree.c
 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/efibind.h
 create mode 100644 xen/include/asm-x86/efi-boot.h
Signature · 1 line
2.1.0
author
#1 lore raw

PATCH v5 1/15 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                           | 1 +
 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, 5 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
index 6d725aa..1aa4a5b 100644
@@ -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 +1 -0
index 0e58bce..f182df2 100644
@@ -100,6 +100,7 @@ $(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 -sf $(BASEDIR)/common/efi/* 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
similarity index 100%
rename from xen/arch/x86/efi/boot.c
rename to xen/common/efi/boot.c
xen/common/efi/compat.c renamed from xen/arch/x86/efi/compat.c +0 -0
similarity index 100%
rename from xen/arch/x86/efi/compat.c
rename to xen/common/efi/compat.c
xen/common/efi/efi.h renamed from xen/arch/x86/efi/efi.h +0 -0
similarity index 100%
rename from xen/arch/x86/efi/efi.h
rename to xen/common/efi/efi.h
xen/common/efi/runtime.c renamed from xen/arch/x86/efi/runtime.c +0 -0
similarity index 100%
rename from xen/arch/x86/efi/runtime.c
rename to xen/common/efi/runtime.c
Signature · 1 line
2.1.0
#2 lore raw

Re: [PATCH V5 01/15] move x86 EFI boot/runtime code to common/efi

xen/Makefile $(TARGET): delete-unfresh-files · line 103

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
xen/Makefile +1 -0
@@ -100,6 +100,7 @@ $(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 -sf $(BASEDIR)/common/efi/* arch/$(TARGET_ARCH)/efi/

I guess this would better be

	ln -sf ../../../common/efi/* arch/$(TARGET_ARCH)/efi/

- there's no reason to prevent the tree from being moved.

Also I hope the recurring link creation upon incremental rebuilds isn't going to cause any kind of problems.

Jan

#3 lore raw

Re: [PATCH V5 01/15] move x86 EFI boot/runtime code to common/efi

Quoted 11 lines · Jan Beulich

xen/Makefile $(TARGET): delete-unfresh-files · line 103

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
xen/Makefile +1 -0
@@ -100,6 +100,7 @@ $(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 -sf $(BASEDIR)/common/efi/* arch/$(TARGET_ARCH)/efi/

I guess this would better be

Quoted 6 lines
	ln -sf ../../../common/efi/* arch/$(TARGET_ARCH)/efi/

- there's no reason to prevent the tree from being moved.

Also I hope the recurring link creation upon incremental rebuilds isn't going to cause any kind of problems.

FWIW my finger macros usually use ln -nfs to avoid issues of this type of thing, although maybe that's only for directory targets, since the -n stops it creating ever deeper links within the original target.

Ian.

author
#4 lore raw

PATCH v5 2/15 Move x86 specific funtions/variables to arch header

In reply to Roy Franz

Move the global variables and functions that can be moved as-is from the common boot.c file to the x86 implementation header file.

---
 xen/common/efi/boot.c          | 148 +++++------------------------------------
 xen/include/asm-x86/efi-boot.h | 135 +++++++++++++++++++++++++++++++++++++
 2 files changed, 150 insertions(+), 133 deletions(-)
 create mode 100644 xen/include/asm-x86/efi-boot.h
xen/common/efi/boot.c +15 -133
index 3bdc158..1a6cd7c 100644
@@ -18,13 +18,6 @@
 #include <xen/string.h>
 #include <xen/stringify.h>
 #include <xen/vga.h>
-#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>
 
 /* Using SetVirtualAddressMap() is incompatible with kexec: */
 #undef USE_SET_VIRTUAL_ADDRESS_MAP
@@ -41,9 +34,6 @@ typedef struct {
     EFI_SHIM_LOCK_VERIFY Verify;
 } EFI_SHIM_LOCK_PROTOCOL;
 
-extern char start[];
-extern u32 cpuid_ext_features;
-
 union string {
     CHAR16 *w;
     char *s;
@@ -58,6 +48,13 @@ struct file {
     };
 };
 
+static CHAR16 *FormatDec(UINT64 Val, CHAR16 *Buffer);
+static CHAR16 *FormatHex(UINT64 Val, UINTN Width, CHAR16 *Buffer);
+static void  DisplayUint(UINT64 Val, INTN Width);
+static CHAR16 *wstrcpy(CHAR16 *d, const CHAR16 *s);
+static void noreturn blexit(const CHAR16 *str);
+static void PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode);
+
 static EFI_BOOT_SERVICES *__initdata efi_bs;
 static EFI_HANDLE __initdata efi_ih;
 
@@ -69,19 +66,18 @@ static UINT32 __initdata mdesc_ver;
 static struct file __initdata cfg;
 static struct file __initdata kernel;
 static struct file __initdata ramdisk;
-static struct file __initdata ucode;
 static struct file __initdata xsm;
-
-static multiboot_info_t __initdata mbi = {
-    .flags = MBI_MODULES | MBI_LOADERNAME
-};
-static module_t __initdata mb_modules[3];
-
 static CHAR16 __initdata newline[] = L"\r\n";
 
 #define PrintStr(s) StdOut->OutputString(StdOut, s)
 #define PrintErr(s) StdErr->OutputString(StdErr, s)
 
+/*
+ * Include architecture specific implementation here, which references the
+ * static globals defined above.
+ */
+#include <asm/efi-boot.h>
+
 static CHAR16 *__init FormatDec(UINT64 Val, CHAR16 *Buffer)
 {
     if ( Val >= 10 )
@@ -255,32 +251,6 @@ static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode)
     blexit(mesg);
 }
 
-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;
-}
-
 static unsigned int __init get_argv(unsigned int argc, CHAR16 **argv,
                                     CHAR16 *cmdline, UINTN cmdsize)
 {
@@ -574,18 +544,6 @@ static void __init split_value(char *s)
     *s = 0;
 }
 
-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)
-
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -687,82 +645,6 @@ static int __init set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
    return max(*pos + *sz, bpp);
 }
 
-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 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;
-}
-
 void EFIAPI __init noreturn
 efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 {
@@ -879,7 +761,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     PrintStr(L"Xen " __stringify(XEN_VERSION) "." __stringify(XEN_SUBVERSION)
              XEN_EXTRAVERSION " (c/s " XEN_CHANGESET ") EFI loader\r\n");
 
-    relocate_image(0);
+    efi_arch_relocate_image(0);
 
     if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
                            &cols, &rows) == EFI_SUCCESS )
@@ -1460,7 +1342,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
     efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
 
-    relocate_image(__XEN_VIRT_START - xen_phys_start);
+    efi_arch_relocate_image(__XEN_VIRT_START - xen_phys_start);
     memcpy((void *)trampoline_phys, trampoline_start, cfg.size);
 
     /* Set system registers and transfer control. */
xen/include/asm-x86/efi-boot.h new file +135 -0

135 lines not on this page · raw message

Signature · 1 line
2.1.0
#5 lore raw

Re: [PATCH V5 02/15] Move x86 specific funtions/variables to arch header

Quoted 51 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
xen/common/efi/boot.c +0 -46
@@ -687,82 +645,6 @@ static int __init set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
    return max(*pos + *sz, bpp);
 }
 
-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 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) )

xen/common/efi/boot.c static int __init set_color(u32 mask, int bpp, u8 *pos, u8 *sz) · line 745

Quoted 10 lines
xen/common/efi/boot.c +0 -10
-                        *(intpte_t *)addr += xen_phys_start;
-                }
-                break;
-            default:
-                blexit(L"Unsupported relocation type");
-            }
-        }
-        base_relocs = (const void *)(base_relocs->entries + i + (i & 1));
-    }
-}

Hmm, so you're still moving the relocation processing code - why? I don't recall you having said you're sure you'll not need this on ARM.

Jan

#6 lore raw

Re: [PATCH V5 02/15] Move x86 specific funtions/variables to arch header

Quoted 56 lines · Jan Beulich
Quoted 56 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
xen/common/efi/boot.c +0 -51
@@ -687,82 +645,6 @@ static int __init set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
    return max(*pos + *sz, bpp);
 }
 
-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 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");
Quoted 8 lines

xen/common/efi/boot.c static int __init set_color(u32 mask, int bpp, u8 *pos, u8 *sz) · line 745

Quoted 5 lines
xen/common/efi/boot.c +0 -5
-            }
-        }
-        base_relocs = (const void *)(base_relocs->entries + i + (i & 1));
-    }
-}

Hmm, so you're still moving the relocation processing code - why? I don't recall you having said you're sure you'll not need this on ARM.

ARM relocates itself to the top of memory during bringup already. I don't think we need to do it here as well/instead.

Ian.

#7 lore raw

Re: [PATCH V5 02/15] Move x86 specific funtions/variables to arch header

Quoted 69 lines
Quoted 1 line
Quoted 1 line · On 22.09.14 at 12:52, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich

Review static int __init set_color(u32 mask, int bpp, u8

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -687,82 +645,6 @@ static int __init set_color(u32 mask, int bpp, u8 

*pos, u8 *sz)

Quoted 14 lines
Quoted 14 lines
xen/common/efi/boot.c +0 -11
    return max(*pos + *sz, bpp);
 }
 
-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;
Quoted 8 lines

xen/common/efi/boot.c static int __init set_color(u32 mask, int bpp, u8 *pos, u8 *sz)

Quoted 8 lines
xen/common/efi/boot.c +0 -8
-    u16 entries[];
-} __base_relocs_start[], __base_relocs_end[];
-
-static void __init relocate_image(unsigned long delta)
-{
-    const struct pe_base_relocs *base_relocs;
-
-    for ( base_relocs = __base_relocs_start; base_relocs < 

__base_relocs_end; )

Quoted 32 lines
Quoted 32 lines
xen/common/efi/boot.c +0 -32
-    {
-        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");
Quoted 8 lines

xen/common/efi/boot.c static int __init set_color(u32 mask, int bpp, u8 *pos, u8 *sz) · line 745

Quoted 5 lines
xen/common/efi/boot.c +0 -5
-            }
-        }
-        base_relocs = (const void *)(base_relocs->entries + i + (i & 1));
-    }
-}

Hmm, so you're still moving the relocation processing code - why? I don't recall you having said you're sure you'll not need this on ARM.

Quoted 2 lines

ARM relocates itself to the top of memory during bringup already. I don't think we need to do it here as well/instead.

There are two relocations (on x86) actually: One (always used) is to move the hypervisor image to high physical memory. The other (needed under UEFI only) is to relocate the hypervisor from where the UEFI loader put it (running in physical mode, virtual and physical addresses are the same) to its linked virtual address. Are you saying that ARM isn't in need of this?

Jan

#8 lore raw

Re: [PATCH V5 02/15] Move x86 specific funtions/variables to arch header

Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 22.09.14 at 12:52, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich

Hmm, so you're still moving the relocation processing code - why? I don't recall you having said you're sure you'll not need this on ARM.

ARM relocates itself to the top of memory during bringup already. I don't think we need to do it here as well/instead.

Quoted 6 lines

There are two relocations (on x86) actually: One (always used) is to move the hypervisor image to high physical memory. The other (needed under UEFI only) is to relocate the hypervisor from where the UEFI loader put it (running in physical mode, virtual and physical addresses are the same) to its linked virtual address. Are you saying that ARM isn't in need of this?

Correct, the main ARM entry point (which the UEFI stub calls) takes care of enabling paging, including handling the move from (potentially differing) physical to virtual addresses.

Ian.

#9 lore raw

Re: [PATCH V5 02/15] Move x86 specific funtions/variables to arch header

Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 22.09.14 at 13:09, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 22.09.14 at 12:52, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich

Hmm, so you're still moving the relocation processing code - why? I don't recall you having said you're sure you'll not need this on ARM.

ARM relocates itself to the top of memory during bringup already. I don't think we need to do it here as well/instead.

Quoted 6 lines

There are two relocations (on x86) actually: One (always used) is to move the hypervisor image to high physical memory. The other (needed under UEFI only) is to relocate the hypervisor from where the UEFI loader put it (running in physical mode, virtual and physical addresses are the same) to its linked virtual address. Are you saying that ARM isn't in need of this?

Quoted 3 lines

Correct, the main ARM entry point (which the UEFI stub calls) takes care of enabling paging, including handling the move from (potentially differing) physical to virtual addresses.

Ah, right - this really makes the need for doing the extra relocation step x86-64-specific. So Roy, I withdraw my objection then to moving these pieces into arch-specific code.

Jan

#10 lore raw

Re: [PATCH V5 02/15] Move x86 specific funtions/variables to arch header

In reply to Roy Franz
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
xen/include/asm-x86/efi-boot.h new file +11 -0
@@ -0,0 +1,135 @@
+/*
+ * 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 <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>

xen/include/asm-x86/efi-boot.h line 21

Quoted 10 lines
xen/include/asm-x86/efi-boot.h new file +10 -0
+#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];
+
+extern char start[];
+extern u32 cpuid_ext_features;

I don't think these (and other extern-s) are valid to be put here.

Jan

author
#11 lore raw

Re: [PATCH V5 02/15] Move x86 specific funtions/variables to arch header

Quoted 28 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
xen/include/asm-x86/efi-boot.h new file +11 -0
@@ -0,0 +1,135 @@
+/*
+ * 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 <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>

xen/include/asm-x86/efi-boot.h line 21

Quoted 10 lines
xen/include/asm-x86/efi-boot.h new file +10 -0
+#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];
+
+extern char start[];
+extern u32 cpuid_ext_features;

I don't think these (and other extern-s) are valid to be put here.

Quoted 2 lines

Jan

Why not, and where should they go??

cpuid_ext_features is x86 architecture specific, and start[] is only used by the x86 code by the place_string() allocator. The extern declaration is in the file in which the variables are referenced.

extern l4_pgentry_t *efi_l4_pgtable;
maybe should be moved back to boot.c for now, but this is an x86 specific structure that is only referenced there due to the runtime code being #ifdef'ed out.

Roy

#12 lore raw

Re: [PATCH V5 02/15] Move x86 specific funtions/variables to arch header

Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 23.09.14 at 04:08, <[email protected]> wrote:
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
xen/include/asm-x86/efi-boot.h new file +15 -0
@@ -0,0 +1,135 @@
+/*
+ * 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 <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 = {
Quoted 8 lines

xen/include/asm-x86/efi-boot.h line 21

Quoted 6 lines
xen/include/asm-x86/efi-boot.h new file +6 -0
+    .flags = MBI_MODULES | MBI_LOADERNAME
+};
+static module_t __initdata mb_modules[3];
+
+extern char start[];
+extern u32 cpuid_ext_features;

I don't think these (and other extern-s) are valid to be put here.

Quoted 5 lines

Why not, and where should they go??

cpuid_ext_features is x86 architecture specific, and start[] is only used by the x86 code by the place_string() allocator. The extern declaration is in the file in which the variables are referenced.

I'm sorry, I only now realized they're both currently being declared in boot.c, so moving them here is kind of okay. Nevertheless it would seem better to find them a more appropriate home: start[] could likely go alongside _start[] in xen/kernel.h, and cpuid_ext_features would seem to fit into either asm-x86/cpufeature.h or asm-x86/processor.h.

Quoted 4 lines

extern l4_pgentry_t *efi_l4_pgtable;
maybe should be moved back to boot.c for now, but this is an x86 specific structure that is only referenced there due to the runtime code being #ifdef'ed out.

It's currently being declared in xen/arch/x86/efi/efi.h, and I can't really see why this isn't sufficient.

Speaking of which - putting the new header under asm-x86/ instead of in x86/efi/ seems bogus with the changed symlinking model too. The header should be as private as possible. Perhaps what you put there could even go into said efi.h (possibly inside a suitable #if)?

Jan

author
#13 lore raw

Re: [PATCH V5 02/15] Move x86 specific funtions/variables to arch header

Quoted 36 lines · Jan Beulich
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 23.09.14 at 04:08, <[email protected]> wrote:
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
xen/include/asm-x86/efi-boot.h new file +15 -0
@@ -0,0 +1,135 @@
+/*
+ * 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 <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 = {
Quoted 8 lines

xen/include/asm-x86/efi-boot.h line 21

Quoted 6 lines
xen/include/asm-x86/efi-boot.h new file +6 -0
+    .flags = MBI_MODULES | MBI_LOADERNAME
+};
+static module_t __initdata mb_modules[3];
+
+extern char start[];
+extern u32 cpuid_ext_features;

I don't think these (and other extern-s) are valid to be put here.

Quoted 5 lines

Why not, and where should they go??

cpuid_ext_features is x86 architecture specific, and start[] is only used by the x86 code by the place_string() allocator. The extern declaration is in the file in which the variables are referenced.

Quoted 6 lines

I'm sorry, I only now realized they're both currently being declared in boot.c, so moving them here is kind of okay. Nevertheless it would seem better to find them a more appropriate home: start[] could likely go alongside _start[] in xen/kernel.h, and cpuid_ext_features would seem to fit into either asm-x86/cpufeature.h or asm-x86/processor.h.

I moved start to xen/kernel.h, and cpuid_ext_features to asm-x86/processor.h alongside some other externs. cpufeature.h didn't have any externs, so putting it with other externs seemed a better fit.

Quoted 8 lines
Quoted 5 lines

extern l4_pgentry_t *efi_l4_pgtable;
maybe should be moved back to boot.c for now, but this is an x86 specific structure that is only referenced there due to the runtime code being #ifdef'ed out.

It's currently being declared in xen/arch/x86/efi/efi.h, and I can't really see why this isn't sufficient.

xen/arch/x86/efi/efi.h is a link to common/efi/efi.h, so it is a shared header. I could put it there with #ifdef, or leave it the the architecture specific header file.

Quoted 5 lines

Speaking of which - putting the new header under asm-x86/ instead of in x86/efi/ seems bogus with the changed symlinking model too. The header should be as private as possible. Perhaps what you put there could even go into said efi.h (possibly inside a suitable #if)?

Yup, putting the efi-boot.h headers in arch/XX/efi is better, so I have moved them.

Since the efi-boot.h is a 'special' include file - ie it defines global variables,
I think having it directly included where it is intended is a good thing. This would also require a lot of forward declarations for functions and global variables referenced by this implementation header but defined in efi-boot.c. This is all avoided right now by including efi-boot.h a bit lower
down.

Quoted 3 lines

Jan

#14 lore raw

Re: [PATCH V5 02/15] Move x86 specific funtions/variables to arch header

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 04:35, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 23.09.14 at 04:08, <[email protected]> wrote:

extern l4_pgentry_t *efi_l4_pgtable;
maybe should be moved back to boot.c for now, but this is an x86 specific structure that is only referenced there due to the runtime code being #ifdef'ed out.

Quoted 6 lines
Quoted 2 lines

It's currently being declared in xen/arch/x86/efi/efi.h, and I can't really see why this isn't sufficient.

xen/arch/x86/efi/efi.h is a link to common/efi/efi.h, so it is a shared header. I could put it there with #ifdef, or leave it the the architecture specific header file.

Following the as-private-as-possible model going the #ifdef route seems better to me even if resulting in slightly more ugly code.

Jan

author
#15 lore raw

PATCH v5 3/15 create arch functions to allocate memory for and process EFI memory map.

In reply to Roy Franz

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.

---
 xen/common/efi/boot.c          | 79 ++++++++----------------------------------
 xen/include/asm-x86/efi-boot.h | 76 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 64 deletions(-)
xen/common/efi/boot.c +15 -64
index 1a6cd7c..307740b 100644
@@ -61,8 +61,6 @@ static EFI_HANDLE __initdata efi_ih;
 static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdOut;
 static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr;
 
-static UINT32 __initdata mdesc_ver;
-
 static struct file __initdata cfg;
 static struct file __initdata kernel;
 static struct file __initdata ramdisk;
@@ -657,16 +655,18 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     EFI_STATUS status;
     unsigned int i, argc;
     CHAR16 **argv, *file_name, *cfg_file_name = NULL;
-    UINTN cols, rows, depth, size, map_key, info_size, gop_mode = ~0;
+    UINTN cols, rows, depth, size, info_size, gop_mode = ~0;
     EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     EFI_FILE_HANDLE dir_handle;
     union string section = { NULL }, name;
-    struct e820entry *e;
     u64 efer;
     bool_t base_video = 0;
+    UINT32 mmap_desc_ver = 0;
+    UINTN mmap_size, mmap_desc_size, mmap_key = 0;
+    void *mmap;
 
     efi_ih = ImageHandle;
     efi_bs = SystemTable->BootServices;
@@ -966,8 +966,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     mbi.boot_loader_name = (long)"EFI";
     mbi.mods_addr = (long)mb_modules;
 
-    place_string(&mbi.mem_upper, NULL);
-
     /* Collect EDD info. */
     BUILD_BUG_ON(offsetof(struct edd_info, edd_device_params) != EDDEXTSIZE);
     BUILD_BUG_ON(sizeof(struct edd_device_params) != EDDPARMSIZE);
@@ -1262,67 +1260,20 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         }
     }
 
-    efi_bs->GetMemoryMap(&efi_memmap_size, NULL, &map_key,
-                         &efi_mdesc_size, &mdesc_ver);
-    mbi.mem_upper -= efi_memmap_size;
-    mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR);
-    if ( mbi.mem_upper < xen_phys_start )
-        blexit(L"Out of static memory");
-    efi_memmap = (void *)(long)mbi.mem_upper;
-    status = efi_bs->GetMemoryMap(&efi_memmap_size, efi_memmap, &map_key,
-                                  &efi_mdesc_size, &mdesc_ver);
+    efi_bs->GetMemoryMap(&mmap_size, NULL, &mmap_key,
+                         &mmap_desc_size, &mmap_desc_ver);
+    mmap = efi_arch_allocate_mmap_buffer(mmap_size);
+    if ( !mmap )
+        blexit(L"ERROR Unable to allocate memory for EFI memory map\r\n");
+
+    status = efi_bs->GetMemoryMap(&mmap_size, mmap, &mmap_key,
+                         &mmap_desc_size, &mmap_desc_ver);
     if ( EFI_ERROR(status) )
         PrintErrMesg(L"Cannot obtain memory map", status);
 
-    /* Populate E820 table and check trampoline area availability. */
-    e = e820map - 1;
-    for ( i = 0; i < efi_memmap_size; i += efi_mdesc_size )
-    {
-        EFI_MEMORY_DESCRIPTOR *desc = efi_memmap + i;
-        u64 len = desc->NumberOfPages << EFI_PAGE_SHIFT;
-        u32 type;
+    efi_arch_process_memory_map(SystemTable, mmap, mmap_size,
+                                mmap_desc_size, mmap_desc_ver);
 
-        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;
-        }
-    }
     if ( !trampoline_phys )
     {
         if ( !cfg.addr )
@@ -1330,7 +1281,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         relocate_trampoline(cfg.addr);
     }
 
-    status = efi_bs->ExitBootServices(ImageHandle, map_key);
+    status = efi_bs->ExitBootServices(ImageHandle, mmap_key);
     if ( EFI_ERROR(status) )
         PrintErrMesg(L"Cannot exit boot services", status);
 
xen/include/asm-x86/efi-boot.h +76 -0

79 lines not on this page · raw message

Signature · 1 line
2.1.0
#16 lore raw

Re: [PATCH V5 03/15] create arch functions to allocate memory for and process EFI memory map.

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
xen/common/efi/boot.c +1 -1
@@ -657,16 +655,18 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     EFI_STATUS status;
     unsigned int i, argc;
     CHAR16 **argv, *file_name, *cfg_file_name = NULL;
-    UINTN cols, rows, depth, size, map_key, info_size, gop_mode = ~0;
+    UINTN cols, rows, depth, size, info_size, gop_mode = ~0;
     EFI_HANDLE *handles = NULL;

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 668

Quoted 10 lines
xen/common/efi/boot.c +2 -1
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     EFI_FILE_HANDLE dir_handle;
     union string section = { NULL }, name;
-    struct e820entry *e;
     u64 efer;
     bool_t base_video = 0;
+    UINT32 mmap_desc_ver = 0;
+    UINTN mmap_size, mmap_desc_size, mmap_key = 0;

Are these initializers really needed?

Also I previously commented about mdesc_ver having been static rather than automatic for a reason, yet you still don't retain that.

Similarly for efi_memmap_size, efi_mdesc_size, and efi_memmap:
With runtime.c moved and (presumably later in the series) also built for ARM, there's no point in moving the setting of these into efi_arch_process_memory_map().

Quoted 8 lines
xen/common/efi/boot.c +0 -4
@@ -1262,67 +1260,20 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         }
     }
 
-    efi_bs->GetMemoryMap(&efi_memmap_size, NULL, &map_key,
-                         &efi_mdesc_size, &mdesc_ver);
-    mbi.mem_upper -= efi_memmap_size;
-    mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR);

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 1267

Quoted 10 lines
xen/common/efi/boot.c +5 -5
-    if ( mbi.mem_upper < xen_phys_start )
-        blexit(L"Out of static memory");
-    efi_memmap = (void *)(long)mbi.mem_upper;
-    status = efi_bs->GetMemoryMap(&efi_memmap_size, efi_memmap, &map_key,
-                                  &efi_mdesc_size, &mdesc_ver);
+    efi_bs->GetMemoryMap(&mmap_size, NULL, &mmap_key,
+                         &mmap_desc_size, &mmap_desc_ver);
+    mmap = efi_arch_allocate_mmap_buffer(mmap_size);
+    if ( !mmap )
+        blexit(L"ERROR Unable to allocate memory for EFI memory map\r\n");

blexit() appends a newline itself.

Jan

author
#17 lore raw

Re: [PATCH V5 03/15] create arch functions to allocate memory for and process EFI memory map.

Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
xen/common/efi/boot.c +1 -1
@@ -657,16 +655,18 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     EFI_STATUS status;
     unsigned int i, argc;
     CHAR16 **argv, *file_name, *cfg_file_name = NULL;
-    UINTN cols, rows, depth, size, map_key, info_size, gop_mode = ~0;
+    UINTN cols, rows, depth, size, info_size, gop_mode = ~0;
     EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     EFI_FILE_HANDLE dir_handle;
Quoted 8 lines

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 668

Quoted 6 lines
xen/common/efi/boot.c +2 -1
     union string section = { NULL }, name;
-    struct e820entry *e;
     u64 efer;
     bool_t base_video = 0;
+    UINT32 mmap_desc_ver = 0;
+    UINTN mmap_size, mmap_desc_size, mmap_key = 0;

Are these initializers really needed?

The base_video is, some of the others aren't in the current form. I will audit the initialized local variables here.

Quoted 3 lines

Also I previously commented about mdesc_ver having been static rather than automatic for a reason, yet you still don't retain that.

Sorry, I had missed that bit in the virtual mapping issues. I'll return this to being static.

Quoted 5 lines

Similarly for efi_memmap_size, efi_mdesc_size, and efi_memmap:
With runtime.c moved and (presumably later in the series) also built for ARM, there's no point in moving the setting of these into efi_arch_process_memory_map().

Yes, I missed undoing this as part of pulling the in the global runtime variables. These should
all be able to be reverted.

Quoted 5 lines
Quoted 5 lines
(quoted diff) +0 -0
@@ -1262,67 +1260,20 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         }
     }
 
Quoted 16 lines
Quoted 4 lines
xen/common/efi/boot.c +0 -4
-    efi_bs->GetMemoryMap(&efi_memmap_size, NULL, &map_key,
-                         &efi_mdesc_size, &mdesc_ver);
-    mbi.mem_upper -= efi_memmap_size;
-    mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR);

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 1267

Quoted 10 lines
xen/common/efi/boot.c +5 -5
-    if ( mbi.mem_upper < xen_phys_start )
-        blexit(L"Out of static memory");
-    efi_memmap = (void *)(long)mbi.mem_upper;
-    status = efi_bs->GetMemoryMap(&efi_memmap_size, efi_memmap, &map_key,
-                                  &efi_mdesc_size, &mdesc_ver);
+    efi_bs->GetMemoryMap(&mmap_size, NULL, &mmap_key,
+                         &mmap_desc_size, &mmap_desc_ver);
+    mmap = efi_arch_allocate_mmap_buffer(mmap_size);
+    if ( !mmap )
+        blexit(L"ERROR Unable to allocate memory for EFI memory map\r\n");

blexit() appends a newline itself.

I'll fix this and review the other blexit() calls.

Quoted 3 lines

Jan

author
#18 lore raw

PATCH v5 4/15 Add architecture functions for pre/post ExitBootServices

In reply to Roy Franz

The UEFI ExitBootServices function is invoked to transition the system to the 'runtime' mode of operation, and is done right before transitioning from the EFI loader code into Xen proper. x86 does some arch specific memory management (trampoline) before exit boot services, and the code that transitions from the EFI application state to Xen is architecture specific. This patch adds two functions, one pre and one post ExitBootServices to allow each architecture to to handle these cases in a customized manner.

---
 xen/common/efi/boot.c          | 42 ++---------------------------------
 xen/include/asm-x86/efi-boot.h | 50 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 40 deletions(-)
xen/common/efi/boot.c +2 -40
index 307740b..f4662b4 100644
@@ -662,7 +662,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     EFI_FILE_HANDLE dir_handle;
     union string section = { NULL }, name;
-    u64 efer;
     bool_t base_video = 0;
     UINT32 mmap_desc_ver = 0;
     UINTN mmap_size, mmap_desc_size, mmap_key = 0;
@@ -1274,12 +1273,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     efi_arch_process_memory_map(SystemTable, mmap, mmap_size,
                                 mmap_desc_size, mmap_desc_ver);
 
-    if ( !trampoline_phys )
-    {
-        if ( !cfg.addr )
-            blexit(L"No memory for trampoline");
-        relocate_trampoline(cfg.addr);
-    }
+    efi_arch_pre_exit_boot();
 
     status = efi_bs->ExitBootServices(ImageHandle, mmap_key);
     if ( EFI_ERROR(status) )
@@ -1293,39 +1287,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
     efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
 
-    efi_arch_relocate_image(__XEN_VIRT_START - xen_phys_start);
-    memcpy((void *)trampoline_phys, trampoline_start, cfg.size);
-
-    /* Set system registers and transfer control. */
-    asm volatile("pushq $0\n\tpopfq");
-    rdmsrl(MSR_EFER, efer);
-    efer |= EFER_SCE;
-    if ( cpuid_ext_features & (1 << (X86_FEATURE_NX & 0x1f)) )
-        efer |= EFER_NX;
-    wrmsrl(MSR_EFER, efer);
-    write_cr0(X86_CR0_PE | X86_CR0_MP | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP |
-              X86_CR0_AM | X86_CR0_PG);
-    asm volatile ( "mov    %[cr4], %%cr4\n\t"
-                   "mov    %[cr3], %%cr3\n\t"
-                   "movabs $__start_xen, %[rip]\n\t"
-                   "lgdt   gdt_descr(%%rip)\n\t"
-                   "mov    stack_start(%%rip), %%rsp\n\t"
-                   "mov    %[ds], %%ss\n\t"
-                   "mov    %[ds], %%ds\n\t"
-                   "mov    %[ds], %%es\n\t"
-                   "mov    %[ds], %%fs\n\t"
-                   "mov    %[ds], %%gs\n\t"
-                   "movl   %[cs], 8(%%rsp)\n\t"
-                   "mov    %[rip], (%%rsp)\n\t"
-                   "lretq  %[stkoff]-16"
-                   : [rip] "=&r" (efer/* any dead 64-bit variable */)
-                   : [cr3] "r" (idle_pg_table),
-                     [cr4] "r" (mmu_cr4_features),
-                     [cs] "ir" (__HYPERVISOR_CS),
-                     [ds] "r" (__HYPERVISOR_DS),
-                     [stkoff] "i" (STACK_SIZE - sizeof(struct cpu_info)),
-                     "D" (&mbi)
-                   : "memory" );
+    efi_arch_post_exit_boot();
     for( ; ; ); /* not reached */
 }
 
xen/include/asm-x86/efi-boot.h +50 -0

53 lines not on this page · raw message

Signature · 1 line
2.1.0
Acked-by on v5 4/15
#19 lore raw

Re: [PATCH V5 04/15] Add architecture functions for pre/post ExitBootServices

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:

The UEFI ExitBootServices function is invoked to transition the system to the 'runtime' mode of operation, and is done right before transitioning from the EFI loader code into Xen proper. x86 does some arch specific memory management (trampoline) before exit boot services, and the code that transitions from the EFI application state to Xen is architecture specific. This patch adds two functions, one pre and one post ExitBootServices to allow each architecture to to handle these cases in a customized manner.

author
#20 lore raw

PATCH v5 5/15 Add efi_arch_cfg_file_early/late() to handle arch specific cfg file fields

In reply to Roy Franz

Different 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/common/efi/boot.c          | 21 ++++++++++-----------
 xen/include/asm-x86/efi-boot.h | 20 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 11 deletions(-)
xen/common/efi/boot.c +10 -11
index f4662b4..58e3cbc 100644
@@ -54,6 +54,12 @@ static void  DisplayUint(UINT64 Val, INTN Width);
 static CHAR16 *wstrcpy(CHAR16 *d, const CHAR16 *s);
 static void noreturn blexit(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;
@@ -843,6 +849,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);
@@ -860,17 +869,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 )
     {
@@ -909,6 +907,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;
xen/include/asm-x86/efi-boot.h +20 -0
index 7aba173..93498bb 100644
@@ -259,3 +259,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);
+    }
+}
Signature · 1 line
2.1.0
Acked-by on v5 5/15
#21 lore raw

Re: [PATCH V5 05/15] Add efi_arch_cfg_file_early/late() to handle arch specific cfg file fields

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:

Different 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.

author
#22 lore raw

PATCH v5 6/15 Add efi_arch_handle_cmdline() for processing commandline

In reply to Roy Franz

Add arch function for processing the Xen commandline and updating internal structures.

---
 xen/common/efi/boot.c          | 37 +++++++++----------------------------
 xen/include/asm-x86/efi-boot.h | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 28 deletions(-)
xen/common/efi/boot.c +9 -28
index 58e3cbc..2f8dade 100644
@@ -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);
 
@@ -256,7 +257,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;
@@ -282,10 +284,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
@@ -660,7 +660,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, info_size, gop_mode = ~0;
     EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
@@ -701,14 +701,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, &options);
     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 )
@@ -878,17 +878,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 )
@@ -955,15 +945,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);
xen/include/asm-x86/efi-boot.h +34 -0
index 93498bb..6e9376a 100644
@@ -279,3 +279,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;
+}
Signature · 1 line
2.1.0
Acked-by on v5 6/15
#23 lore raw

Re: [PATCH V5 06/15] Add efi_arch_handle_cmdline() for processing commandline

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:

Add arch function for processing the Xen commandline and updating internal structures.

With two small requests for adjustments below

xen/common/efi/boot.c static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode) · line 261

Quoted 7 lines
xen/common/efi/boot.c +2 -1
@@ -256,7 +257,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)

I think this would better be named "dom0_options" or "dom0_opts" or some such (also in the caller).

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 704

Quoted 6 lines
xen/common/efi/boot.c +1 -1
@@ -701,14 +701,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, &options);

I don't see why you don't pass NULL here, the more that you add a respective check to get_argv().

Jan

author
#24 lore raw

Re: [PATCH V5 06/15] Add efi_arch_handle_cmdline() for processing commandline

Quoted 12 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:

Add arch function for processing the Xen commandline and updating internal structures.

With two small requests for adjustments below

Quoted 3 lines
(quoted diff) +0 -0
@@ -256,7 +257,8 @@ static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode)
 }
 
Quoted 7 lines

xen/common/efi/boot.c static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode) · line 261

Quoted 4 lines
xen/common/efi/boot.c +2 -1
 static unsigned int __init get_argv(unsigned int argc, CHAR16 **argv,
-                                    CHAR16 *cmdline, UINTN cmdsize)
+                                    CHAR16 *cmdline, UINTN cmdsize,
+                                    CHAR16 **options)

I think this would better be named "dom0_options" or "dom0_opts" or some such (also in the caller).

I think xen_options would be better, or else I'm really confused :) This string is combined with the Xen options from the config file into mbi.cmdline. Dom0 arguments come from the "kernel" line in the configuration tile.

Quoted 10 lines

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 704

Quoted 7 lines
xen/common/efi/boot.c +1 -1
@@ -701,14 +701,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, &options);

I don't see why you don't pass NULL here, the more that you add a respective check to get_argv().

I don't either - I will change this.

Quoted 3 lines

Jan

#25 lore raw

Re: [PATCH V5 06/15] Add efi_arch_handle_cmdline() for processing commandline

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 23.09.14 at 03:40, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich

xen/common/efi/boot.c static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode) · line 261

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
xen/common/efi/boot.c +2 -1
@@ -256,7 +257,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)

I think this would better be named "dom0_options" or "dom0_opts" or some such (also in the caller).

Quoted 4 lines

I think xen_options would be better, or else I'm really confused :) This string is combined with the Xen options from the config file into mbi.cmdline. Dom0 arguments come from the "kernel" line in the configuration tile.

Indeed - I mixed things up: This is the first "--" separator, the Dom0 options come after the second. In which case staying with just "options" is quite fine.

Jan

author
#26 lore raw

Re: [PATCH V5 06/15] Add efi_arch_handle_cmdline() for processing commandline

Quoted 19 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 23.09.14 at 03:40, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich

xen/common/efi/boot.c static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode) · line 261

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
xen/common/efi/boot.c +2 -1
@@ -256,7 +257,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)

I think this would better be named "dom0_options" or "dom0_opts" or some such (also in the caller).

Quoted 4 lines

I think xen_options would be better, or else I'm really confused :) This string is combined with the Xen options from the config file into mbi.cmdline. Dom0 arguments come from the "kernel" line in the configuration tile.

Quoted 6 lines

Indeed - I mixed things up: This is the first "--" separator, the Dom0 options come after the second. In which case staying with just "options" is quite fine.

Jan

Is this second "--" handled by XEN itself? I don't see any handling of that in the EFI boot code. The only thing that goes
into the multiboot .string field for the dom0 kernel is from the config file.

Roy

#27 lore raw

Re: [PATCH V5 06/15] Add efi_arch_handle_cmdline() for processing commandline

Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 02:09, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.09.14 at 03:40, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich

Review static void __init PrintErrMesg(const CHAR16 *mesg,

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -256,7 +257,8 @@ static void __init PrintErrMesg(const CHAR16 *mesg, 

EFI_STATUS ErrCode)

Quoted 15 lines
Quoted 14 lines
Quoted 9 lines

xen/common/efi/boot.c static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode) · line 261

Quoted 6 lines
xen/common/efi/boot.c +2 -1
 }
 
 static unsigned int __init get_argv(unsigned int argc, CHAR16 **argv,
-                                    CHAR16 *cmdline, UINTN cmdsize)
+                                    CHAR16 *cmdline, UINTN cmdsize,
+                                    CHAR16 **options)

I think this would better be named "dom0_options" or "dom0_opts" or some such (also in the caller).

I think xen_options would be better, or else I'm really confused :) This string is combined with the Xen options from the config file into mbi.cmdline. Dom0 arguments come from the "kernel" line in the configuration tile.

Quoted 8 lines
Quoted 3 lines

Indeed - I mixed things up: This is the first "--" separator, the Dom0 options come after the second. In which case staying with just "options" is quite fine.

Is this second "--" handled by XEN itself? I don't see any handling of that in the EFI boot code. The only thing that goes
into the multiboot .string field for the dom0 kernel is from the config file.

Yes, that's being handled in __start_xen() (search for "kextra" if you want to see where exactly).

Jan

#28 lore raw

Re: [PATCH V5 06/15] Add efi_arch_handle_cmdline() for processing commandline

Quoted 26 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 02:09, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.09.14 at 03:40, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich

Review static void __init PrintErrMesg(const CHAR16 *mesg,

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -256,7 +257,8 @@ static void __init PrintErrMesg(const CHAR16 *mesg, 

EFI_STATUS ErrCode)

Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
xen/common/efi/boot.c +2 -1
 }
 
 static unsigned int __init get_argv(unsigned int argc, CHAR16 **argv,
-                                    CHAR16 *cmdline, UINTN cmdsize)
+                                    CHAR16 *cmdline, UINTN cmdsize,
+                                    CHAR16 **options)
Quoted 7 lines
Quoted 2 lines

I think this would better be named "dom0_options" or "dom0_opts" or some such (also in the caller).

I think xen_options would be better, or else I'm really confused :) This string is combined with the Xen options from the config file into mbi.cmdline. Dom0 arguments come from the "kernel" line in the configuration tile.

Indeed - I mixed things up: This is the first "--" separator, the Dom0 options come after the second. In which case staying with just "options" is quite fine.

Quoted 7 lines
Quoted 4 lines

Is this second "--" handled by XEN itself? I don't see any handling of that in the EFI boot code. The only thing that goes
into the multiboot .string field for the dom0 kernel is from the config file.

Yes, that's being handled in __start_xen() (search for "kextra" if you want to see where exactly).

I'd never heard of this behaviour before, and it is (currently at least) x86 specific.

I don't know if this is relevant to the discusion here though, probably not?

Ian.

#29 lore raw

Re: [PATCH V5 06/15] Add efi_arch_handle_cmdline() for processing commandline

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 11:33, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 02:09, <[email protected]> wrote:

Is this second "--" handled by XEN itself? I don't see any handling of that in the EFI boot code. The only thing that goes
into the multiboot .string field for the dom0 kernel is from the config file.

Quoted 5 lines
Quoted 2 lines

Yes, that's being handled in __start_xen() (search for "kextra" if you want to see where exactly).

I'd never heard of this behaviour before, and it is (currently at least) x86 specific.

Yeah, we needed this a long while ago for the case where the GrUB GUI shows only a single line for entering extra options, which then all get passed to the hypervisor making it impossible to add extra Dom0 kernel options this same way.

Quoted 2 lines

I don't know if this is relevant to the discusion here though, probably not?

Definitely not. I just didn't want to leave Roy's question unanswered.

Jan

author
#30 lore raw

PATCH v5 7/15 Move x86 specific disk probing code

In reply to Roy Franz

Move x86 specific disk (EDD) probing to arch specific file. This code is x86 only and relates to legacy BIOS handling of disk drives.

---
 xen/common/efi/boot.c          | 144 +-------------------------------------
 xen/include/asm-x86/efi-boot.h | 152 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 143 deletions(-)
xen/common/efi/boot.c +1 -143
index 2f8dade..2914225 100644
@@ -654,8 +654,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 {
     static EFI_GUID __initdata loaded_image_guid = LOADED_IMAGE_PROTOCOL;
     static EFI_GUID __initdata gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
-    static EFI_GUID __initdata bio_guid = BLOCK_IO_PROTOCOL;
-    static EFI_GUID __initdata devp_guid = DEVICE_PATH_PROTOCOL;
     static EFI_GUID __initdata shim_lock_guid = SHIM_LOCK_PROTOCOL_GUID;
     EFI_LOADED_IMAGE *loaded_image;
     EFI_STATUS status;
@@ -945,147 +943,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         }
     }
 
-    /* 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 *)&params->key; p < &params->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;
+    efi_arch_edd();
 
     /* XXX Collect EDID info. */
 
xen/include/asm-x86/efi-boot.h +152 -0

155 lines not on this page · raw message

Signature · 1 line
2.1.0
Acked-by on v5 7/15
#31 lore raw

Re: [PATCH V5 07/15] Move x86 specific disk probing code

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:

Move x86 specific disk (EDD) probing to arch specific file. This code is x86 only and relates to legacy BIOS handling of disk drives.

as soon as ...

xen/include/asm-x86/efi-boot.h static void __init efi_arch_handle_cmdline(CHAR16 *image_name, · line 322

Quoted 6 lines
xen/include/asm-x86/efi-boot.h +6 -0
+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;
+    int i;

... this becomes "unsigned int". Didn't you say you'd go through the whole series and correct these?

Jan

author
#32 lore raw

Re: [PATCH V5 07/15] Move x86 specific disk probing code

Quoted 19 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:49, <[email protected]> wrote:

Move x86 specific disk (EDD) probing to arch specific file. This code is x86 only and relates to legacy BIOS handling of disk drives.

as soon as ...

xen/include/asm-x86/efi-boot.h static void __init efi_arch_handle_cmdline(CHAR16 *image_name, · line 322

Quoted 6 lines
xen/include/asm-x86/efi-boot.h +6 -0
+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;
+    int i;

... this becomes "unsigned int". Didn't you say you'd go through the whole series and correct these?

Quoted 2 lines

Jan

My review all comment was regarding the blank line between variable definitions and statements in functions. (looks like I missed one of those too.)

I will fix this and review types of all local variables created in the arch specific functions.

author
#33 lore raw

PATCH v5 8/15 Create arch functions for console and video init

In reply to Roy Franz

Add arch functions for text console and graphics initialization, and move VGA specific code to x86 architecture file.

---
 xen/common/efi/boot.c          | 69 ++------------------------------------
 xen/include/asm-x86/efi-boot.h | 75 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 66 deletions(-)
xen/common/efi/boot.c +3 -66
index 2914225..1917052 100644
@@ -61,6 +61,7 @@ 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);
+static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
 
 static EFI_BOOT_SERVICES *__initdata efi_bs;
 static EFI_HANDLE __initdata efi_ih;
@@ -768,12 +769,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
                            &cols, &rows) == EFI_SUCCESS )
-    {
-        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;
-    }
+        efi_arch_console_init(cols, rows);
 
     size = 0;
     status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL);
@@ -1027,7 +1023,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     if ( gop )
     {
-        int bpp = 0;
 
         /* Set graphics mode. */
         if ( gop_mode < gop->Mode->MaxMode && gop_mode != gop->Mode->Mode )
@@ -1036,65 +1031,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         /* Get graphics and frame buffer info. */
         status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
         if ( !EFI_ERROR(status) )
-            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");
-                status = EFI_UNSUPPORTED;
-                break;
-            }
-        if ( !EFI_ERROR(status) )
-        {
-            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;
-        }
+            efi_arch_video_init(gop, info_size, mode_info);
     }
 
     efi_bs->GetMemoryMap(&mmap_size, NULL, &mmap_key,
xen/include/asm-x86/efi-boot.h +75 -0

78 lines not on this page · raw message

Signature · 1 line
2.1.0
author
#35 lore raw

PATCH v5 9/15 Add efi_arch_memory() for arch specific memory setup

In reply to Roy Franz

This 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/common/efi/boot.c          | 29 +----------------------------
 xen/include/asm-x86/efi-boot.h | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 28 deletions(-)
xen/common/efi/boot.c +1 -28
index 1917052..38177bf 100644
@@ -992,34 +992,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();
 
     if ( gop )
     {
xen/include/asm-x86/efi-boot.h +35 -0
index 7df04bb..2902970 100644
@@ -540,3 +540,38 @@ static void __init efi_arch_video_init(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
             (gop->Mode->FrameBufferSize + 0xffff) >> 16;
     }
 }
+
+static void __init efi_arch_memory(void)
+{
+    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);
+}
Signature · 1 line
2.1.0
Acked-by on v5 9/15
#36 lore raw

Re: [PATCH V5 09/15] Add efi_arch_memory() for arch specific memory setup

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:

This 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.

Again

provided ...

xen/include/asm-x86/efi-boot.h static void __init efi_arch_video_init(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, · line 546

Quoted 3 lines
xen/include/asm-x86/efi-boot.h +3 -0
+static void __init efi_arch_memory(void)
+{
+    int i;

... this gets converted to unsigned int.

Also maybe name the function efi_arch_memory_setup()?

Jan

author
#37 lore raw

Re: [PATCH V5 09/15] Add efi_arch_memory() for arch specific memory setup

Quoted 17 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:

This 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.

Again

provided ...

xen/include/asm-x86/efi-boot.h static void __init efi_arch_video_init(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, · line 546

Quoted 3 lines
xen/include/asm-x86/efi-boot.h +3 -0
+static void __init efi_arch_memory(void)
+{
+    int i;

... this gets converted to unsigned int.

Quoted 4 lines

Also maybe name the function efi_arch_memory_setup()?

Jan

Sure.

author
#38 lore raw

PATCH v5 10/15 Add arch specific module handling to read_file()

In reply to Roy Franz

Each 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.

---
 xen/common/efi/boot.c          | 102 ++++++++++++++++++++++++-----------------
 xen/include/asm-x86/efi-boot.h |  32 ++++++++++++-
 2 files changed, 91 insertions(+), 43 deletions(-)
xen/common/efi/boot.c +61 -41
index 38177bf..4acab40 100644
@@ -56,12 +56,13 @@ static void noreturn blexit(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 char *split_string(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);
+static size_t wstrlen(const CHAR16 * s);
 static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
+static bool_t read_file(EFI_FILE_HANDLE dir_handle, struct file *file,
+                               CHAR16 *filename, char *options);
 
 static EFI_BOOT_SERVICES *__initdata efi_bs;
 static EFI_HANDLE __initdata efi_ih;
@@ -115,6 +116,15 @@ static void __init DisplayUint(UINT64 Val, INTN Width)
     PrintStr(PrintString);
 }
 
+static size_t __init wstrlen(const CHAR16 * s)
+{
+	const CHAR16 *sc;
+
+	for (sc = s; *sc != L'\0'; ++sc)
+		/* nothing */;
+	return sc - s;
+}
+
 static CHAR16 *__init wstrcpy(CHAR16 *d, const CHAR16 *s)
 {
     CHAR16 *r = d;
@@ -404,18 +414,33 @@ static CHAR16 *__init point_tail(CHAR16 *fn)
             break;
         }
 }
+/*
+ * Truncate string at first space, and return pointer
+ * to remainder of string.
+ */
+static char * __init split_string(char *s)
+{
+    while ( *s && !isspace(*s) )
+        ++s;
+    if ( *s )
+    {
+        *s = 0;
+        return(s + 1);
+    }
+    return NULL;
+}
 
-static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
-                               struct file *file)
+static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, struct file *file,
+                               CHAR16 *filename, char *options)
 {
     EFI_FILE_HANDLE FileHandle = NULL;
     UINT64 size;
     EFI_STATUS ret;
     CHAR16 *what = NULL;
 
-    if ( !name )
+    if ( !filename )
         PrintErrMesg(L"No filename", EFI_OUT_OF_RESOURCES);
-    ret = dir_handle->Open(dir_handle, &FileHandle, name,
+    ret = dir_handle->Open(dir_handle, &FileHandle, filename,
                            EFI_FILE_MODE_READ, 0);
     if ( file == &cfg && ret == EFI_NOT_FOUND )
         return 0;
@@ -447,20 +472,18 @@ static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
     }
     else
     {
+        file->size = size;
         if ( file != &cfg )
         {
-            PrintStr(name);
+            PrintStr(filename);
             PrintStr(L": ");
             DisplayUint(file->addr, 2 * sizeof(file->addr));
             PrintStr(L"-");
             DisplayUint(file->addr + size, 2 * sizeof(file->addr));
             PrintStr(newline);
-            mb_modules[mbi.mods_count].mod_start = file->addr >> PAGE_SHIFT;
-            mb_modules[mbi.mods_count].mod_end = size;
-            ++mbi.mods_count;
+            efi_arch_handle_module(file, filename, options);
         }
 
-        file->size = size;
         ret = FileHandle->Read(FileHandle, &file->size, file->ptr);
         if ( !EFI_ERROR(ret) && file->size != size )
             ret = EFI_ABORTED;
@@ -475,7 +498,7 @@ static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
     {
         PrintErr(what);
         PrintErr(L" failed for ");
-        PrintErrMesg(name, ret);
+        PrintErrMesg(filename, ret);
     }
 
     return 1;
@@ -531,7 +554,13 @@ static char *__init get_value(const struct file *cfg, const char *section,
             break;
         default:
             if ( match && strncmp(ptr, item, ilen) == 0 && ptr[ilen] == '=' )
-                return ptr + ilen + 1;
+            {
+                ptr += ilen + 1;
+                /* strip off any leading spaces */
+                while ( *ptr && isspace(*ptr) )
+                    ptr++;
+                return ptr;
+            }
             break;
         }
         ptr += strlen(ptr);
@@ -539,16 +568,6 @@ static char *__init get_value(const struct file *cfg, const char *section,
     return NULL;
 }
 
-static void __init split_value(char *s)
-{
-    while ( *s && isspace(*s) )
-        ++s;
-    place_string(&mb_modules[mbi.mods_count].string, s);
-    while ( *s && !isspace(*s) )
-        ++s;
-    *s = 0;
-}
-
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -659,18 +678,19 @@ 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, *options = NULL;
+    CHAR16 **argv, *options = NULL;
     UINTN cols, rows, depth, size, info_size, gop_mode = ~0;
     EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     EFI_FILE_HANDLE dir_handle;
-    union string section = { NULL }, name;
+    union string section = { NULL }, name, file_name, cfg_file_name = {NULL};
     bool_t base_video = 0;
     UINT32 mmap_desc_ver = 0;
     UINTN mmap_size, mmap_desc_size, mmap_key = 0;
     void *mmap;
+    char *option_str;
 
     efi_ih = ImageHandle;
     efi_bs = SystemTable->BootServices;
@@ -697,7 +717,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     trampoline_xen_phys_start = xen_phys_start;
 
     /* Get the file system interface. */
-    dir_handle = get_parent_handle(loaded_image, &file_name);
+    dir_handle = get_parent_handle(loaded_image, &file_name.w);
 
     argc = get_argv(0, NULL, loaded_image->LoadOptions,
                     loaded_image->LoadOptionsSize, &options);
@@ -721,9 +741,9 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
             if ( wstrcmp(ptr + 1, L"basevideo") == 0 )
                 base_video = 1;
             else if ( wstrncmp(ptr + 1, L"cfg=", 4) == 0 )
-                cfg_file_name = ptr + 5;
+                cfg_file_name.w = ptr + 5;
             else if ( i + 1 < argc && wstrcmp(ptr + 1, L"cfg") == 0 )
-                cfg_file_name = argv[++i];
+                cfg_file_name.w = argv[++i];
             else if ( wstrcmp(ptr + 1, L"help") == 0 ||
                       (ptr[1] == L'?' && !ptr[2]) )
             {
@@ -795,24 +815,24 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         gop = NULL;
 
     /* Read and parse the config file. */
-    if ( !cfg_file_name )
+    if ( !cfg_file_name.w )
     {
         CHAR16 *tail;
 
-        while ( (tail = point_tail(file_name)) != NULL )
+        while ( (tail = point_tail(file_name.w)) != NULL )
         {
             wstrcpy(tail, L".cfg");
-            if ( read_file(dir_handle, file_name, &cfg) )
+            if ( read_file(dir_handle, &cfg, file_name.w, NULL) )
                 break;
             *tail = 0;
         }
         if ( !tail )
             blexit(L"No configuration file found.");
         PrintStr(L"Using configuration file '");
-        PrintStr(file_name);
+        PrintStr(file_name.w);
         PrintStr(L"'\r\n");
     }
-    else if ( !read_file(dir_handle, cfg_file_name, &cfg) )
+    else if ( !read_file(dir_handle, &cfg, cfg_file_name.w, NULL) )
         blexit(L"Configuration file not found.");
     pre_parse(&cfg);
 
@@ -831,7 +851,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
             break;
         efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
         cfg.addr = 0;
-        if ( !read_file(dir_handle, s2w(&name), &cfg) )
+        if ( !read_file(dir_handle, &cfg, s2w(&name), NULL) )
         {
             PrintStr(L"Chained configuration file '");
             PrintStr(name.w);
@@ -846,8 +866,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     efi_arch_cfg_file_early(dir_handle, section.s);
 
-    split_value(name.s);
-    read_file(dir_handle, s2w(&name), &kernel);
+    option_str = split_string(name.s);
+    read_file(dir_handle, &kernel, s2w(&name), option_str);
     efi_bs->FreePool(name.w);
 
     if ( !EFI_ERROR(efi_bs->LocateProtocol(&shim_lock_guid, NULL,
@@ -858,16 +878,16 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     name.s = get_value(&cfg, section.s, "ramdisk");
     if ( name.s )
     {
-        split_value(name.s);
-        read_file(dir_handle, s2w(&name), &ramdisk);
+        option_str = split_string(name.s);
+        read_file(dir_handle, &ramdisk, s2w(&name), option_str);
         efi_bs->FreePool(name.w);
     }
 
     name.s = get_value(&cfg, section.s, "xsm");
     if ( name.s )
     {
-        split_value(name.s);
-        read_file(dir_handle, s2w(&name), &xsm);
+        option_str = split_string(name.s);
+        read_file(dir_handle, &xsm, s2w(&name), option_str);
         efi_bs->FreePool(name.w);
     }
 
xen/include/asm-x86/efi-boot.h +30 -2
index 2902970..3902b6c 100644
@@ -267,6 +267,7 @@ static void __init efi_arch_cfg_file_early(EFI_FILE_HANDLE dir_handle, char *sec
 static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *section)
 {
     union string name;
+    char *options;
 
     name.s = get_value(&cfg, section, "ucode");
     if ( !name.s )
@@ -274,8 +275,8 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect
     if ( name.s )
     {
         microcode_set_module(mbi.mods_count);
-        split_value(name.s);
-        read_file(dir_handle, s2w(&name), &ucode);
+        options = split_string(name.s);
+        read_file(dir_handle, &ucode, s2w(&name), options);
         efi_bs->FreePool(name.w);
     }
 }
@@ -575,3 +576,30 @@ static void __init efi_arch_memory(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\r\n");
+
+    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);
+}
Signature · 1 line
2.1.0
#39 lore raw

Re: [PATCH V5 10/15] Add arch specific module handling to read_file()

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:
xen/common/efi/boot.c +0 -0
@@ -56,12 +56,13 @@ static void noreturn blexit(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);

xen/common/efi/boot.c static void noreturn blexit(const CHAR16 *str); · line 65

Quoted 10 lines
xen/common/efi/boot.c +4 -3
-static void  split_value(char *s);
+static char *split_string(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);
+static size_t wstrlen(const CHAR16 * s);
 static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
+static bool_t read_file(EFI_FILE_HANDLE dir_handle, struct file *file,
+                               CHAR16 *filename, char *options);

Please don't needlessly move this declaration down.

xen/common/efi/boot.c static void __init DisplayUint(UINT64 Val, INTN Width) · line 126

Quoted 12 lines
xen/common/efi/boot.c +8 -0
@@ -115,6 +116,15 @@ static void __init DisplayUint(UINT64 Val, INTN Width)
     PrintStr(PrintString);
 }
 
+static size_t __init wstrlen(const CHAR16 * s)
+{
+	const CHAR16 *sc;
+
+	for (sc = s; *sc != L'\0'; ++sc)
+		/* nothing */;
+	return sc - s;
+}

Coding style (many issues).

xen/common/efi/boot.c static CHAR16 *__init point_tail(CHAR16 *fn) · line 419

Quoted 7 lines
xen/common/efi/boot.c +3 -0
@@ -404,18 +414,33 @@ static CHAR16 *__init point_tail(CHAR16 *fn)
             break;
         }
 }
+/*
+ * Truncate string at first space, and return pointer
+ * to remainder of string.

... (if any).

xen/common/efi/boot.c static CHAR16 *__init point_tail(CHAR16 *fn) · line 428

Quoted 9 lines
xen/common/efi/boot.c +9 -0
+ */
+static char * __init split_string(char *s)
+{
+    while ( *s && !isspace(*s) )
+        ++s;
+    if ( *s )
+    {
+        *s = 0;
+        return(s + 1);

No parentheses here please.

xen/common/efi/boot.c static CHAR16 *__init point_tail(CHAR16 *fn) · line 434

Quoted 8 lines
xen/common/efi/boot.c +5 -2
+    }
+    return NULL;
+}
 
-static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
-                               struct file *file)
+static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, struct file *file,
+                               CHAR16 *filename, char *options)

Is the renaming from "name" to "filename" really necessary/useful? And the flipping of the order of pre-existing parameters?

Quoted 5 lines
xen/common/efi/boot.c +0 -0
@@ -659,18 +678,19 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
     EFI_LOADED_IMAGE *loaded_image;
     EFI_STATUS status;
     unsigned int i, argc;

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE · line 689

Quoted 10 lines
xen/common/efi/boot.c +2 -2
-    CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
+    CHAR16 **argv, *options = NULL;
     UINTN cols, rows, depth, size, info_size, gop_mode = ~0;
     EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     EFI_FILE_HANDLE dir_handle;
-    union string section = { NULL }, name;
+    union string section = { NULL }, name, file_name, cfg_file_name = {NULL};

Your addition should be consistent with existing code (blanks around NULL). But - why are you changing the types of the two variables in the first place? Afaics all references to them now are using the .w member access, suggesting that this is just a remnant of your earlier version changes.

xen/common/efi/boot.c static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect · line 279

Quoted 8 lines
xen/common/efi/boot.c +2 -2
@@ -274,8 +275,8 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect
     if ( name.s )
     {
         microcode_set_module(mbi.mods_count);
-        split_value(name.s);
-        read_file(dir_handle, s2w(&name), &ucode);
+        options = split_string(name.s);
+        read_file(dir_handle, &ucode, s2w(&name), options);

Perhaps rather NULL instead of options?

Quoted 8 lines
xen/common/efi/boot.c +4 -0
@@ -575,3 +576,30 @@ static void __init efi_arch_memory(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)
+{

xen/common/efi/boot.c static void __init efi_arch_memory(void) · line 592

Quoted 10 lines
xen/common/efi/boot.c +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\r\n");

Iirc I said this before, but just in case: No explicit newline on strings passed to blexit() please.

Jan

author
#40 lore raw

Re: [PATCH V5 10/15] Add arch specific module handling to read_file()

Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:
xen/common/efi/boot.c +1 -1
@@ -56,12 +56,13 @@ static void noreturn blexit(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 char *split_string(char *s);
 static CHAR16 *s2w(union string *str);
 static char *w2s(const union string *str);
Quoted 9 lines

xen/common/efi/boot.c static void noreturn blexit(const CHAR16 *str); · line 65

Quoted 6 lines
xen/common/efi/boot.c +3 -2
-static bool_t  read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
-                               struct file *file);
+static size_t wstrlen(const CHAR16 * s);
 static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
+static bool_t read_file(EFI_FILE_HANDLE dir_handle, struct file *file,
+                               CHAR16 *filename, char *options);

Please don't needlessly move this declaration down.

I'll fix this.

Quoted 4 lines
Quoted 4 lines
xen/common/efi/boot.c +0 -0
@@ -115,6 +116,15 @@ static void __init DisplayUint(UINT64 Val, INTN Width)
     PrintStr(PrintString);
 }
 
Quoted 10 lines

xen/common/efi/boot.c static void __init DisplayUint(UINT64 Val, INTN Width) · line 126

Quoted 8 lines
xen/common/efi/boot.c +8 -0
+static size_t __init wstrlen(const CHAR16 * s)
+{
+     const CHAR16 *sc;
+
+     for (sc = s; *sc != L'\0'; ++sc)
+             /* nothing */;
+     return sc - s;
+}

Coding style (many issues).

static size_t __init wstrlen(const CHAR16 *s)

{
     const CHAR16 *sc;

     for ( sc = s; *sc != L'\0'; ++sc )
            ;
     return sc - s;
}

Is the above OK? Not sure what else to change here...

Quoted 11 lines

xen/common/efi/boot.c static CHAR16 *__init point_tail(CHAR16 *fn) · line 419

Quoted 8 lines
xen/common/efi/boot.c +3 -0
@@ -404,18 +414,33 @@ static CHAR16 *__init point_tail(CHAR16 *fn)
             break;
         }
 }
+/*
+ * Truncate string at first space, and return pointer
+ * to remainder of string.

... (if any).

Sure.

Quoted 11 lines

xen/common/efi/boot.c static CHAR16 *__init point_tail(CHAR16 *fn) · line 428

Quoted 9 lines
xen/common/efi/boot.c +9 -0
+ */
+static char * __init split_string(char *s)
+{
+    while ( *s && !isspace(*s) )
+        ++s;
+    if ( *s )
+    {
+        *s = 0;
+        return(s + 1);

No parentheses here please.

sure

Quoted 5 lines
Quoted 5 lines
xen/common/efi/boot.c +3 -0
+    }
+    return NULL;
+}
 
Quoted 7 lines

xen/common/efi/boot.c static CHAR16 *__init point_tail(CHAR16 *fn) · line 434

Quoted 4 lines
xen/common/efi/boot.c +2 -2
-static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
-                               struct file *file)
+static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, struct file *file,
+                               CHAR16 *filename, char *options)

Is the renaming from "name" to "filename" really necessary/useful? And the flipping of the order of pre-existing parameters?

I'll fix this.

Quoted 14 lines
Quoted 14 lines
xen/common/efi/boot.c +1 -1
@@ -659,18 +678,19 @@ 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, *options = NULL;
+    CHAR16 **argv, *options = NULL;
     UINTN cols, rows, depth, size, info_size, gop_mode = ~0;
     EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     EFI_FILE_HANDLE dir_handle;
Quoted 9 lines

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 688

Quoted 2 lines
xen/common/efi/boot.c +1 -1
-    union string section = { NULL }, name;
+    union string section = { NULL }, name, file_name, cfg_file_name = {NULL};

Your addition should be consistent with existing code (blanks around NULL). But - why are you changing the types of the two variables in the first place? Afaics all references to them now are using the .w member access, suggesting that this is just a remnant of your earlier version changes.

Yes, this is leftover type changes from a previous version. Both
these should be able to to be
reverted to simple CHAR16 *

Quoted 10 lines

xen/common/efi/boot.c static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect · line 279

Quoted 8 lines
xen/common/efi/boot.c +2 -2
@@ -274,8 +275,8 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect
     if ( name.s )
     {
         microcode_set_module(mbi.mods_count);
-        split_value(name.s);
-        read_file(dir_handle, s2w(&name), &ucode);
+        options = split_string(name.s);
+        read_file(dir_handle, &ucode, s2w(&name), options);

Perhaps rather NULL instead of options?

Yup.

Quoted 14 lines
Quoted 14 lines
xen/common/efi/boot.c +9 -0
@@ -575,3 +576,30 @@ static void __init efi_arch_memory(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
Quoted 8 lines

xen/common/efi/boot.c static void __init efi_arch_memory(void) · line 592

Quoted 5 lines
xen/common/efi/boot.c +5 -0
+     * 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\r\n");

Iirc I said this before, but just in case: No explicit newline on strings passed to blexit() please.

Yes.

Quoted 2 lines

Jan

#41 lore raw

Re: [PATCH V5 10/15] Add arch specific module handling to read_file()

Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 23.09.14 at 03:57, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:
xen/common/efi/boot.c +0 -0
@@ -115,6 +116,15 @@ static void __init DisplayUint(UINT64 Val, INTN Width)
     PrintStr(PrintString);
 }
 
Quoted 10 lines

xen/common/efi/boot.c static void __init DisplayUint(UINT64 Val, INTN Width) · line 126

Quoted 8 lines
xen/common/efi/boot.c +8 -0
+static size_t __init wstrlen(const CHAR16 * s)
+{
+     const CHAR16 *sc;
+
+     for (sc = s; *sc != L'\0'; ++sc)
+             /* nothing */;
+     return sc - s;
+}

Coding style (many issues).

static size_t __init wstrlen(const CHAR16 *s)

{
     const CHAR16 *sc;

     for ( sc = s; *sc != L'\0'; ++sc )
            ;
     return sc - s;
}
Quoted 1 line

Is the above OK? Not sure what else to change here...

Almost - the lone ; is still indented one level (4 spaces) too deep.

Jan

#42 lore raw

Re: [PATCH V5 10/15] Add arch specific module handling to read_file()

Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 23.09.14 at 03:57, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:
xen/common/efi/boot.c +0 -0
@@ -115,6 +116,15 @@ static void __init DisplayUint(UINT64 Val, INTN Width)
     PrintStr(PrintString);
 }
 
Quoted 10 lines

xen/common/efi/boot.c static void __init DisplayUint(UINT64 Val, INTN Width) · line 126

Quoted 8 lines
xen/common/efi/boot.c +8 -0
+static size_t __init wstrlen(const CHAR16 * s)
+{
+     const CHAR16 *sc;
+
+     for (sc = s; *sc != L'\0'; ++sc)
+             /* nothing */;
+     return sc - s;
+}

Coding style (many issues).

static size_t __init wstrlen(const CHAR16 *s)

{
     const CHAR16 *sc;
Quoted 8 lines
Quoted 6 lines
     for ( sc = s; *sc != L'\0'; ++sc )
            ;
     return sc - s;
}

Is the above OK? Not sure what else to change here...

Almost - the lone ; is still indented one level (4 spaces) too deep.

Would you be inclined to keep the /* nothing */ too as a signal to the reader that it is deliberate?

Ian

#43 lore raw

Re: [PATCH V5 10/15] Add arch specific module handling to read_file()

Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 23.09.14 at 14:41, <[email protected]> wrote:
Quoted 27 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 23.09.14 at 03:57, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:
xen/common/efi/boot.c +0 -0
@@ -115,6 +116,15 @@ static void __init DisplayUint(UINT64 Val, INTN Width)
     PrintStr(PrintString);
 }
 
Quoted 10 lines

xen/common/efi/boot.c static void __init DisplayUint(UINT64 Val, INTN Width) · line 126

Quoted 8 lines
xen/common/efi/boot.c +8 -0
+static size_t __init wstrlen(const CHAR16 * s)
+{
+     const CHAR16 *sc;
+
+     for (sc = s; *sc != L'\0'; ++sc)
+             /* nothing */;
+     return sc - s;
+}

Coding style (many issues).

static size_t __init wstrlen(const CHAR16 *s)

{
     const CHAR16 *sc;

     for ( sc = s; *sc != L'\0'; ++sc )
            ;
     return sc - s;
}
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Is the above OK? Not sure what else to change here...

Almost - the lone ; is still indented one level (4 spaces) too deep.

Would you be inclined to keep the /* nothing */ too as a signal to the reader that it is deliberate?

Yes - I didn't pay attention to it having got dropped with the re-formatting.

Jan

author
#44 lore raw

Re: [PATCH V5 10/15] Add arch specific module handling to read_file()

In reply to Roy Franz
Quoted 132 lines · Roy Franz
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:
xen/common/efi/boot.c +1 -1
@@ -56,12 +56,13 @@ static void noreturn blexit(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 char *split_string(char *s);
 static CHAR16 *s2w(union string *str);
 static char *w2s(const union string *str);
Quoted 9 lines

xen/common/efi/boot.c static void noreturn blexit(const CHAR16 *str); · line 65

Quoted 6 lines
xen/common/efi/boot.c +3 -2
-static bool_t  read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
-                               struct file *file);
+static size_t wstrlen(const CHAR16 * s);
 static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
+static bool_t read_file(EFI_FILE_HANDLE dir_handle, struct file *file,
+                               CHAR16 *filename, char *options);

Please don't needlessly move this declaration down.

I'll fix this.

Quoted 4 lines
Quoted 4 lines
xen/common/efi/boot.c +0 -0
@@ -115,6 +116,15 @@ static void __init DisplayUint(UINT64 Val, INTN Width)
     PrintStr(PrintString);
 }
 
Quoted 10 lines

xen/common/efi/boot.c static void __init DisplayUint(UINT64 Val, INTN Width) · line 126

Quoted 8 lines
xen/common/efi/boot.c +8 -0
+static size_t __init wstrlen(const CHAR16 * s)
+{
+     const CHAR16 *sc;
+
+     for (sc = s; *sc != L'\0'; ++sc)
+             /* nothing */;
+     return sc - s;
+}

Coding style (many issues).

static size_t __init wstrlen(const CHAR16 *s)

{
     const CHAR16 *sc;

     for ( sc = s; *sc != L'\0'; ++sc )
            ;
     return sc - s;
}

Is the above OK? Not sure what else to change here...

Quoted 11 lines

xen/common/efi/boot.c static CHAR16 *__init point_tail(CHAR16 *fn) · line 419

Quoted 8 lines
xen/common/efi/boot.c +3 -0
@@ -404,18 +414,33 @@ static CHAR16 *__init point_tail(CHAR16 *fn)
             break;
         }
 }
+/*
+ * Truncate string at first space, and return pointer
+ * to remainder of string.

... (if any).

Sure.

Quoted 11 lines

xen/common/efi/boot.c static CHAR16 *__init point_tail(CHAR16 *fn) · line 428

Quoted 9 lines
xen/common/efi/boot.c +9 -0
+ */
+static char * __init split_string(char *s)
+{
+    while ( *s && !isspace(*s) )
+        ++s;
+    if ( *s )
+    {
+        *s = 0;
+        return(s + 1);

No parentheses here please.

sure

Quoted 5 lines
Quoted 5 lines
xen/common/efi/boot.c +3 -0
+    }
+    return NULL;
+}
 
Quoted 7 lines

xen/common/efi/boot.c static CHAR16 *__init point_tail(CHAR16 *fn) · line 434

Quoted 4 lines
xen/common/efi/boot.c +2 -2
-static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
-                               struct file *file)
+static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, struct file *file,
+                               CHAR16 *filename, char *options)

Is the renaming from "name" to "filename" really necessary/useful? And the flipping of the order of pre-existing parameters?

I'll fix this.

Quoted 14 lines
Quoted 14 lines
xen/common/efi/boot.c +1 -1
@@ -659,18 +678,19 @@ 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, *options = NULL;
+    CHAR16 **argv, *options = NULL;
     UINTN cols, rows, depth, size, info_size, gop_mode = ~0;
     EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     EFI_FILE_HANDLE dir_handle;
Quoted 9 lines

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 688

Quoted 2 lines
xen/common/efi/boot.c +1 -1
-    union string section = { NULL }, name;
+    union string section = { NULL }, name, file_name, cfg_file_name = {NULL};

Your addition should be consistent with existing code (blanks around NULL). But - why are you changing the types of the two variables in the first place? Afaics all references to them now are using the .w member access, suggesting that this is just a remnant of your earlier version changes.

Yes, this is leftover type changes from a previous version. Both
these should be able to to be
reverted to simple CHAR16 *

Quoted 10 lines

xen/common/efi/boot.c static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect · line 279

Quoted 8 lines
xen/common/efi/boot.c +2 -2
@@ -274,8 +275,8 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect
     if ( name.s )
     {
         microcode_set_module(mbi.mods_count);
-        split_value(name.s);
-        read_file(dir_handle, s2w(&name), &ucode);
+        options = split_string(name.s);
+        read_file(dir_handle, &ucode, s2w(&name), options);

Perhaps rather NULL instead of options?

Quoted 2 lines

Yup.

OK, I looked at this a little more, and the original code would take anything after the ucode filename
and put it into the mbi.string field for the ucode module. All the modules where treated the same in this
regard - they could all have options.

If ucode never has options, I can remove this, but this would be a change in behavior.

Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
xen/common/efi/boot.c +9 -0
@@ -575,3 +576,30 @@ static void __init efi_arch_memory(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
Quoted 8 lines

xen/common/efi/boot.c static void __init efi_arch_memory(void) · line 592

Quoted 5 lines
xen/common/efi/boot.c +5 -0
+     * 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\r\n");

Iirc I said this before, but just in case: No explicit newline on strings passed to blexit() please.

Yes.

Quoted 2 lines

Jan

author
#45 lore raw

Re: [PATCH V5 10/15] Add arch specific module handling to read_file()

Quoted 135 lines · Roy Franz
Quoted 132 lines · Roy Franz
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:
xen/common/efi/boot.c +1 -1
@@ -56,12 +56,13 @@ static void noreturn blexit(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 char *split_string(char *s);
 static CHAR16 *s2w(union string *str);
 static char *w2s(const union string *str);
Quoted 9 lines

xen/common/efi/boot.c static void noreturn blexit(const CHAR16 *str); · line 65

Quoted 6 lines
xen/common/efi/boot.c +3 -2
-static bool_t  read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
-                               struct file *file);
+static size_t wstrlen(const CHAR16 * s);
 static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
+static bool_t read_file(EFI_FILE_HANDLE dir_handle, struct file *file,
+                               CHAR16 *filename, char *options);

Please don't needlessly move this declaration down.

I'll fix this.

Quoted 4 lines
Quoted 4 lines
xen/common/efi/boot.c +0 -0
@@ -115,6 +116,15 @@ static void __init DisplayUint(UINT64 Val, INTN Width)
     PrintStr(PrintString);
 }
 
Quoted 10 lines

xen/common/efi/boot.c static void __init DisplayUint(UINT64 Val, INTN Width) · line 126

Quoted 8 lines
xen/common/efi/boot.c +8 -0
+static size_t __init wstrlen(const CHAR16 * s)
+{
+     const CHAR16 *sc;
+
+     for (sc = s; *sc != L'\0'; ++sc)
+             /* nothing */;
+     return sc - s;
+}

Coding style (many issues).

static size_t __init wstrlen(const CHAR16 *s)

{
     const CHAR16 *sc;

     for ( sc = s; *sc != L'\0'; ++sc )
            ;
     return sc - s;
}

Is the above OK? Not sure what else to change here...

Quoted 11 lines

xen/common/efi/boot.c static CHAR16 *__init point_tail(CHAR16 *fn) · line 419

Quoted 8 lines
xen/common/efi/boot.c +3 -0
@@ -404,18 +414,33 @@ static CHAR16 *__init point_tail(CHAR16 *fn)
             break;
         }
 }
+/*
+ * Truncate string at first space, and return pointer
+ * to remainder of string.

... (if any).

Sure.

Quoted 11 lines

xen/common/efi/boot.c static CHAR16 *__init point_tail(CHAR16 *fn) · line 428

Quoted 9 lines
xen/common/efi/boot.c +9 -0
+ */
+static char * __init split_string(char *s)
+{
+    while ( *s && !isspace(*s) )
+        ++s;
+    if ( *s )
+    {
+        *s = 0;
+        return(s + 1);

No parentheses here please.

sure

Quoted 5 lines
Quoted 5 lines
xen/common/efi/boot.c +3 -0
+    }
+    return NULL;
+}
 
Quoted 7 lines

xen/common/efi/boot.c static CHAR16 *__init point_tail(CHAR16 *fn) · line 434

Quoted 4 lines
xen/common/efi/boot.c +2 -2
-static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
-                               struct file *file)
+static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, struct file *file,
+                               CHAR16 *filename, char *options)

Is the renaming from "name" to "filename" really necessary/useful? And the flipping of the order of pre-existing parameters?

I'll fix this.

Quoted 14 lines
Quoted 14 lines
xen/common/efi/boot.c +1 -1
@@ -659,18 +678,19 @@ 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, *options = NULL;
+    CHAR16 **argv, *options = NULL;
     UINTN cols, rows, depth, size, info_size, gop_mode = ~0;
     EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     EFI_FILE_HANDLE dir_handle;
Quoted 9 lines

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 688

Quoted 2 lines
xen/common/efi/boot.c +1 -1
-    union string section = { NULL }, name;
+    union string section = { NULL }, name, file_name, cfg_file_name = {NULL};

Your addition should be consistent with existing code (blanks around NULL). But - why are you changing the types of the two variables in the first place? Afaics all references to them now are using the .w member access, suggesting that this is just a remnant of your earlier version changes.

Yes, this is leftover type changes from a previous version. Both
these should be able to to be
reverted to simple CHAR16 *

Quoted 10 lines

xen/common/efi/boot.c static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect · line 279

Quoted 8 lines
xen/common/efi/boot.c +2 -2
@@ -274,8 +275,8 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect
     if ( name.s )
     {
         microcode_set_module(mbi.mods_count);
-        split_value(name.s);
-        read_file(dir_handle, s2w(&name), &ucode);
+        options = split_string(name.s);
+        read_file(dir_handle, &ucode, s2w(&name), options);

Perhaps rather NULL instead of options?

Quoted 2 lines

Yup.

Quoted 8 lines

OK, I looked at this a little more, and the original code would take anything after the ucode filename
and put it into the mbi.string field for the ucode module. All the modules where treated the same in this
regard - they could all have options.

If ucode never has options, I can remove this, but this would be a change in behavior.

The EFI config file documentation specifies just the filename, so I have simplified this
in the next version.

Quoted 27 lines
Quoted 27 lines
Quoted 16 lines
Quoted 16 lines
xen/common/efi/boot.c +9 -0
@@ -575,3 +576,30 @@ static void __init efi_arch_memory(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
Quoted 8 lines

xen/common/efi/boot.c static void __init efi_arch_memory(void) · line 592

Quoted 5 lines
xen/common/efi/boot.c +5 -0
+     * 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\r\n");

Iirc I said this before, but just in case: No explicit newline on strings passed to blexit() please.

Yes.

Quoted 2 lines

Jan

#46 lore raw

Re: [PATCH V5 10/15] Add arch specific module handling to read_file()

In reply to Roy Franz
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 24.09.14 at 03:23, <[email protected]> wrote:
Quoted 13 lines · Roy Franz
Quoted 11 lines · Jan Beulich

xen/include/asm-x86/efi-boot.h static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect · line 279

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:
xen/include/asm-x86/efi-boot.h +2 -2
@@ -274,8 +275,8 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect
     if ( name.s )
     {
         microcode_set_module(mbi.mods_count);
-        split_value(name.s);
-        read_file(dir_handle, s2w(&name), &ucode);
+        options = split_string(name.s);
+        read_file(dir_handle, &ucode, s2w(&name), options);

Perhaps rather NULL instead of options?

Quoted 2 lines

Yup.

Quoted 8 lines

OK, I looked at this a little more, and the original code would take anything after the ucode filename
and put it into the mbi.string field for the ucode module. All the modules where treated the same in this
regard - they could all have options.

If ucode never has options, I can remove this, but this would be a change in behavior.

This was done that way just to avoid extra conditionals. The resulting mbi.string doesn't get consumed anywhere (just like for initrd and xsm, albeit in the latter case one could at least envision a potential future use).

Jan

author
#47 lore raw

PATCH v5 11/15 Add several misc. arch functions for EFI boot code.

In reply to Roy Franz

Add 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/common/efi/boot.c          | 18 ++++--------------
 xen/include/asm-x86/efi-boot.h | 25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 14 deletions(-)
xen/common/efi/boot.c +4 -14
index 4acab40..f4ef308 100644
@@ -207,11 +207,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.w);
@@ -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 )
xen/include/asm-x86/efi-boot.h +25 -0
index 3902b6c..2a3a2b6 100644
@@ -603,3 +603,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;
+}
Signature · 1 line
2.1.0
Acked-by on v5 11/15
#48 lore raw

Re: [PATCH V5 11/15] Add several misc. arch functions for EFI boot code.

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:

Add 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.

author
#49 lore raw

PATCH v5 12/15 Add efi_arch_use_config_file() function to control use of config file

In reply to Roy Franz

The 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/common/efi/boot.c          | 178 +++++++++++++++++++++--------------------
 xen/include/asm-x86/efi-boot.h |  14 ++++
 2 files changed, 106 insertions(+), 86 deletions(-)
xen/common/efi/boot.c +92 -86
index f4ef308..006a73c 100644
@@ -684,7 +684,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
-    EFI_FILE_HANDLE dir_handle;
     union string section = { NULL }, name, file_name, cfg_file_name = {NULL};
     bool_t base_video = 0;
     UINT32 mmap_desc_ver = 0;
@@ -711,9 +710,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     efi_arch_load_addr_check(loaded_image);
 
-    /* Get the file system interface. */
-    dir_handle = get_parent_handle(loaded_image, &file_name.w);
-
     argc = get_argv(0, NULL, loaded_image->LoadOptions,
                     loaded_image->LoadOptionsSize, &options);
     if ( argc > 0 &&
@@ -809,109 +805,119 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     if ( EFI_ERROR(status) )
         gop = NULL;
 
-    /* Read and parse the config file. */
-    if ( !cfg_file_name.w )
+    if ( efi_arch_use_config_file(SystemTable) )
     {
-        CHAR16 *tail;
+        EFI_FILE_HANDLE dir_handle;
+        /* Get the file system interface. */
+        dir_handle = get_parent_handle(loaded_image, &file_name.w);
 
-        while ( (tail = point_tail(file_name.w)) != NULL )
+        /* Read and parse the config file. */
+        if ( !cfg_file_name.w )
         {
-            wstrcpy(tail, L".cfg");
-            if ( read_file(dir_handle, &cfg, file_name.w, NULL) )
-                break;
-            *tail = 0;
+            CHAR16 *tail;
+
+            while ( (tail = point_tail(file_name.w)) != NULL )
+            {
+                wstrcpy(tail, L".cfg");
+                if ( read_file(dir_handle, &cfg, file_name.w, NULL) )
+                    break;
+                *tail = 0;
+            }
+            if ( !tail )
+                blexit(L"No configuration file found.");
+            PrintStr(L"Using configuration file '");
+            PrintStr(file_name.w);
+            PrintStr(L"'\r\n");
         }
-        if ( !tail )
-            blexit(L"No configuration file found.");
-        PrintStr(L"Using configuration file '");
-        PrintStr(file_name.w);
-        PrintStr(L"'\r\n");
-    }
-    else if ( !read_file(dir_handle, &cfg, cfg_file_name.w, NULL) )
-        blexit(L"Configuration file not found.");
-    pre_parse(&cfg);
+        else if ( !read_file(dir_handle, &cfg, cfg_file_name.w, NULL) )
+            blexit(L"Configuration file not found.");
+        pre_parse(&cfg);
 
-    if ( section.w )
-        w2s(&section);
-    else
-        section.s = get_value(&cfg, "global", "default");
+        if ( section.w )
+            w2s(&section);
+        else
+            section.s = get_value(&cfg, "global", "default");
 
-    for ( ; ; )
-    {
-        name.s = get_value(&cfg, section.s, "kernel");
-        if ( name.s )
-            break;
-        name.s = get_value(&cfg, "global", "chain");
-        if ( !name.s )
-            break;
-        efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
-        cfg.addr = 0;
-        if ( !read_file(dir_handle, &cfg, s2w(&name), NULL) )
+        for ( ; ; )
         {
-            PrintStr(L"Chained configuration file '");
-            PrintStr(name.w);
+            name.s = get_value(&cfg, section.s, "kernel");
+            if ( name.s )
+                break;
+            name.s = get_value(&cfg, "global", "chain");
+            if ( !name.s )
+                break;
+            efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
+            cfg.addr = 0;
+            if ( !read_file(dir_handle, &cfg, s2w(&name), NULL) )
+            {
+                PrintStr(L"Chained configuration file '");
+                PrintStr(name.w);
+                efi_bs->FreePool(name.w);
+                blexit(L"'not found.");
+            }
+            pre_parse(&cfg);
             efi_bs->FreePool(name.w);
-            blexit(L"'not found.");
         }
-        pre_parse(&cfg);
-        efi_bs->FreePool(name.w);
-    }
-    if ( !name.s )
-        blexit(L"No Dom0 kernel image specified.");
-
-    efi_arch_cfg_file_early(dir_handle, section.s);
 
-    option_str = split_string(name.s);
-    read_file(dir_handle, &kernel, s2w(&name), option_str);
-    efi_bs->FreePool(name.w);
+        if ( !name.s )
+            blexit(L"No Dom0 kernel image specified.");
 
-    if ( !EFI_ERROR(efi_bs->LocateProtocol(&shim_lock_guid, NULL,
-                    (void **)&shim_lock)) &&
-         (status = shim_lock->Verify(kernel.ptr, kernel.size)) != EFI_SUCCESS )
-        PrintErrMesg(L"Dom0 kernel image could not be verified", status);
+        efi_arch_cfg_file_early(dir_handle, section.s);
 
-    name.s = get_value(&cfg, section.s, "ramdisk");
-    if ( name.s )
-    {
         option_str = split_string(name.s);
-        read_file(dir_handle, &ramdisk, s2w(&name), option_str);
+        read_file(dir_handle, &kernel, s2w(&name), option_str);
         efi_bs->FreePool(name.w);
-    }
 
-    name.s = get_value(&cfg, section.s, "xsm");
-    if ( name.s )
-    {
-        option_str = split_string(name.s);
-        read_file(dir_handle, &xsm, s2w(&name), option_str);
-        efi_bs->FreePool(name.w);
-    }
+        if ( !EFI_ERROR(efi_bs->LocateProtocol(&shim_lock_guid, NULL,
+                        (void **)&shim_lock)) &&
+             (status = shim_lock->Verify(kernel.ptr, kernel.size)) != EFI_SUCCESS )
+            PrintErrMesg(L"Dom0 kernel image could not be verified", status);
 
-    name.s = get_value(&cfg, section.s, "options");
-    efi_arch_handle_cmdline(argc ? *argv : NULL, options, name.s);
+        name.s = get_value(&cfg, section.s, "ramdisk");
+        if ( name.s )
+        {
+            option_str = split_string(name.s);
+            read_file(dir_handle, &ramdisk, s2w(&name), option_str);
+            efi_bs->FreePool(name.w);
+        }
 
-    cols = rows = depth = 0;
-    if ( !base_video )
-    {
-        name.cs = get_value(&cfg, section.s, "video");
-        if ( !name.cs )
-            name.cs = get_value(&cfg, "global", "video");
-        if ( name.cs && !strncmp(name.cs, "gfx-", 4) )
+        name.s = get_value(&cfg, section.s, "xsm");
+        if ( name.s )
         {
-            cols = simple_strtoul(name.cs + 4, &name.cs, 10);
-            if ( *name.cs == 'x' )
-                rows = simple_strtoul(name.cs + 1, &name.cs, 10);
-            if ( *name.cs == 'x' )
-                depth = simple_strtoul(name.cs + 1, &name.cs, 10);
-            if ( *name.cs )
-                cols = rows = depth = 0;
+            option_str = split_string(name.s);
+            read_file(dir_handle, &xsm, s2w(&name), option_str);
+            efi_bs->FreePool(name.w);
         }
-    }
-    efi_arch_cfg_file_late(dir_handle, section.s);
 
-    efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
-    cfg.addr = 0;
+        name.s = get_value(&cfg, section.s, "options");
+        efi_arch_handle_cmdline(argc ? *argv : NULL, options, name.s);
+
+        cols = rows = depth = 0;
+        if ( !base_video )
+        {
+            name.cs = get_value(&cfg, section.s, "video");
+            if ( !name.cs )
+                name.cs = get_value(&cfg, "global", "video");
+            if ( name.cs && !strncmp(name.cs, "gfx-", 4) )
+            {
+                cols = simple_strtoul(name.cs + 4, &name.cs, 10);
+                if ( *name.cs == 'x' )
+                    rows = simple_strtoul(name.cs + 1, &name.cs, 10);
+                if ( *name.cs == 'x' )
+                    depth = simple_strtoul(name.cs + 1, &name.cs, 10);
+                if ( *name.cs )
+                    cols = rows = depth = 0;
+            }
+        }
 
-    dir_handle->Close(dir_handle);
+        efi_arch_cfg_file_late(dir_handle, section.s);
+
+        efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
+        cfg.addr = 0;
+
+        dir_handle->Close(dir_handle);
+
+    }
 
     if ( gop && !base_video )
     {
xen/include/asm-x86/efi-boot.h +14 -0
index 2a3a2b6..3ff593d 100644
@@ -628,3 +628,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 __init bool_t 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:
+ */
Signature · 1 line
2.1.0
Acked-by on v5 12/15
#50 lore raw

Re: [PATCH V5 12/15] Add efi_arch_use_config_file() function to control use of config file

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:

The 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

Quoted 1 line

with two formatting change requests:

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 812

Quoted 12 lines
xen/common/efi/boot.c +4 -3
@@ -809,109 +805,119 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     if ( EFI_ERROR(status) )
         gop = NULL;
 
-    /* Read and parse the config file. */
-    if ( !cfg_file_name.w )
+    if ( efi_arch_use_config_file(SystemTable) )
     {
-        CHAR16 *tail;
+        EFI_FILE_HANDLE dir_handle;
+        /* Get the file system interface. */
+        dir_handle = get_parent_handle(loaded_image, &file_name.w);

Blank line between declarations and statements please.

xen/include/asm-x86/efi-boot.h static void __init efi_arch_load_addr_check(EFI_LOADED_IMAGE *loaded_image) · line 632

Quoted 8 lines
xen/include/asm-x86/efi-boot.h +2 -0
@@ -628,3 +628,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 __init bool_t efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)

static <type> <attributes> <name>

please (i.e. __init and bool_t ought to switch places).

author
#51 lore raw

Re: [PATCH V5 12/15] Add efi_arch_use_config_file() function to control use of config file

Quoted 22 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 19.09.14 at 00:50, <[email protected]> wrote:

The 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

Quoted 1 line

with two formatting change requests:

Quoted 4 lines
xen/common/efi/boot.c +0 -0
@@ -809,109 +805,119 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     if ( EFI_ERROR(status) )
         gop = NULL;
 
Quoted 10 lines

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 812

Quoted 8 lines
xen/common/efi/boot.c +4 -3
-    /* Read and parse the config file. */
-    if ( !cfg_file_name.w )
+    if ( efi_arch_use_config_file(SystemTable) )
     {
-        CHAR16 *tail;
+        EFI_FILE_HANDLE dir_handle;
+        /* Get the file system interface. */
+        dir_handle = get_parent_handle(loaded_image, &file_name.w);

Blank line between declarations and statements please.

I reviewed all the functions - forgot to check all the other blocks....

Quoted 12 lines

xen/include/asm-x86/efi-boot.h static void __init efi_arch_load_addr_check(EFI_LOADED_IMAGE *loaded_image) · line 632

Quoted 9 lines
xen/include/asm-x86/efi-boot.h +2 -0
@@ -628,3 +628,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 __init bool_t efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)

static <type> <attributes> <name>

Quoted 2 lines

please (i.e. __init and bool_t ought to switch places).

I'll fix this..

Thanks,
Roy

author
#52 lore raw

PATCH v5 13/15 add arm64 cache flushing code from linux v3.16

In reply to Roy Franz

__flush_dcache_all added from arch/arm64/mm/cache.S, with helper macros from arch/arm64/include/asm/assembler.h, from v3.16. The cache flushing is required when transitioning from EFI code that runs with cache enable to Xen startup code which expects the cache to be disabled.

---
 xen/arch/arm/arm64/Makefile |   1 +
 xen/arch/arm/arm64/cache.S  | 100 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+)
 create mode 100644 xen/arch/arm/arm64/cache.S
xen/arch/arm/arm64/Makefile +1 -0
index d2d5875..c7243f5 100644
@@ -7,5 +7,6 @@ obj-y += domain.o
 obj-y += vfp.o
 obj-y += smpboot.o
 obj-y += domctl.o
+obj-y += cache.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm64/cache.S new file +100 -0

100 lines not on this page · raw message

Signature · 1 line
2.1.0
Acked-by on v5 13/15
#53 lore raw

Re: [PATCH V5 13/15] add arm64 cache flushing code from linux v3.16

Quoted 6 lines · Roy Franz

__flush_dcache_all added from arch/arm64/mm/cache.S, with helper macros from arch/arm64/include/asm/assembler.h, from v3.16. The cache flushing is required when transitioning from EFI code that runs with cache enable to Xen startup code which expects the cache to be disabled.

xen/arch/arm/arm64/cache.S line 52

Quoted 1 line
xen/arch/arm/arm64/cache.S new file +1 -0
+	ENTRY(__flush_dcache_all)

If you need to repost please unindent this (if there's no need to repost then I can do it on commit).

author
#54 lore raw

Re: [PATCH V5 13/15] add arm64 cache flushing code from linux v3.16

Quoted 8 lines · Ian Campbell
Quoted 6 lines · Roy Franz

__flush_dcache_all added from arch/arm64/mm/cache.S, with helper macros from arch/arm64/include/asm/assembler.h, from v3.16. The cache flushing is required when transitioning from EFI code that runs with cache enable to Xen startup code which expects the cache to be disabled.

Quoted 9 lines
Quoted 1 line

+ ENTRY(__flush_dcache_all)

If you need to repost please unindent this (if there's no need to repost then I can do it on commit).

I'll be reposting a new series to address other feedback, so I'll include this.

Roy

#55 lore raw

Re: [PATCH V5 13/15] add arm64 cache flushing code from linux v3.16

Quoted 12 lines · Roy Franz
Quoted 11 lines · Ian Campbell
Quoted 6 lines · Roy Franz

__flush_dcache_all added from arch/arm64/mm/cache.S, with helper macros from arch/arm64/include/asm/assembler.h, from v3.16. The cache flushing is required when transitioning from EFI code that runs with cache enable to Xen startup code which expects the cache to be disabled.

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

+ ENTRY(__flush_dcache_all)

If you need to repost please unindent this (if there's no need to repost then I can do it on commit).

I'll be reposting a new series to address other feedback, so I'll include this.

No need, I applied this one already (and fixed it up)

Ian.

author
#56 lore raw

PATCH v5 14/15 Update libfdt to v1.4.0

In reply to Roy Franz

Update libfdt to v1.4.0 of libfdt taken from git://git.jdl.com/software/dtc.git
Xen changes to libfdt_env.h carried over from existing libfdt (v1.3.0) This update provides the fdt_create_empty_tree() function used by the ARM EFI boot code.

---
 xen/common/libfdt/Makefile.libfdt   |   4 +-
 xen/common/libfdt/fdt.c             |  30 +++-
 xen/common/libfdt/fdt_empty_tree.c  |  84 ++++++++++
 xen/common/libfdt/fdt_ro.c          |   7 +-
 xen/common/libfdt/fdt_rw.c          |  31 +++-
 xen/common/libfdt/fdt_sw.c          |   4 +-
 xen/common/libfdt/fdt_wip.c         |   2 +-
 xen/common/libfdt/version.lds       |   6 +
 xen/include/xen/libfdt/fdt.h        |  93 ++++++++---
 xen/include/xen/libfdt/libfdt.h     | 315 +++++++++++++++++++++++++++++++++---
 xen/include/xen/libfdt/libfdt_env.h |   4 +
 11 files changed, 529 insertions(+), 51 deletions(-)
 create mode 100644 xen/common/libfdt/fdt_empty_tree.c
xen/common/libfdt/Makefile.libfdt +2 -2
index d55a6f8..91126c0 100644
@@ -4,7 +4,7 @@
 # be easily embeddable into other systems of Makefiles.
 #
 LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1
-LIBFDT_INCLUDES = fdt.h libfdt.h
+LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h
 LIBFDT_VERSION = version.lds
-LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c
+LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c
 LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
xen/common/libfdt/fdt.c +29 -1
index e56833a..2ce6a44 100644
@@ -92,7 +92,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
 
 uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 {
-	const uint32_t *tagp, *lenp;
+	const fdt32_t *tagp, *lenp;
 	uint32_t tag;
 	int offset = startoffset;
 	const char *p;
@@ -198,6 +198,34 @@ int fdt_next_node(const void *fdt, int offset, int *depth)
 	return offset;
 }
 
+int fdt_first_subnode(const void *fdt, int offset)
+{
+	int depth = 0;
+
+	offset = fdt_next_node(fdt, offset, &depth);
+	if (offset < 0 || depth != 1)
+		return -FDT_ERR_NOTFOUND;
+
+	return offset;
+}
+
+int fdt_next_subnode(const void *fdt, int offset)
+{
+	int depth = 1;
+
+	/*
+	 * With respect to the parent, the depth of the next subnode will be
+	 * the same as the last.
+	 */
+	do {
+		offset = fdt_next_node(fdt, offset, &depth);
+		if (offset < 0 || depth < 1)
+			return -FDT_ERR_NOTFOUND;
+	} while (depth > 1);
+
+	return offset;
+}
+
 const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
 {
 	int len = strlen(s) + 1;
xen/common/libfdt/fdt_empty_tree.c new file +84 -0

84 lines not on this page · raw message

xen/common/libfdt/fdt_ro.c +3 -4
index 02b6d68..50007f6 100644
@@ -322,7 +322,7 @@ const void *fdt_getprop(const void *fdt, int nodeoffset,
 
 uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
 {
-	const uint32_t *php;
+	const fdt32_t *php;
 	int len;
 
 	/* FIXME: This is a bit sub-optimal, since we potentially scan
@@ -515,8 +515,7 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
 	return offset; /* error from fdt_next_node() */
 }
 
-static int _fdt_stringlist_contains(const char *strlist, int listlen,
-				    const char *str)
+int fdt_stringlist_contains(const char *strlist, int listlen, const char *str)
 {
 	int len = strlen(str);
 	const char *p;
@@ -542,7 +541,7 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset,
 	prop = fdt_getprop(fdt, nodeoffset, "compatible", &len);
 	if (!prop)
 		return len;
-	if (_fdt_stringlist_contains(prop, len, compatible))
+	if (fdt_stringlist_contains(prop, len, compatible))
 		return 0;
 	else
 		return 1;
xen/common/libfdt/fdt_rw.c +29 -2
index 994037b..fdba618 100644
@@ -289,6 +289,33 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,
 	return 0;
 }
 
+int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
+		   const void *val, int len)
+{
+	struct fdt_property *prop;
+	int err, oldlen, newlen;
+
+	FDT_RW_CHECK_HEADER(fdt);
+
+	prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
+	if (prop) {
+		newlen = len + oldlen;
+		err = _fdt_splice_struct(fdt, prop->data,
+					 FDT_TAGALIGN(oldlen),
+					 FDT_TAGALIGN(newlen));
+		if (err)
+			return err;
+		prop->len = cpu_to_fdt32(newlen);
+		memcpy(prop->data + oldlen, val, len);
+	} else {
+		err = _fdt_add_property(fdt, nodeoffset, name, len, &prop);
+		if (err)
+			return err;
+		memcpy(prop->data, val, len);
+	}
+	return 0;
+}
+
 int fdt_delprop(void *fdt, int nodeoffset, const char *name)
 {
 	struct fdt_property *prop;
@@ -312,7 +339,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
 	int nodelen;
 	int err;
 	uint32_t tag;
-	uint32_t *endtag;
+	fdt32_t *endtag;
 
 	FDT_RW_CHECK_HEADER(fdt);
 
@@ -339,7 +366,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
 	nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
 	memset(nh->name, 0, FDT_TAGALIGN(namelen+1));
 	memcpy(nh->name, name, namelen);
-	endtag = (uint32_t *)((char *)nh + nodelen - FDT_TAGSIZE);
+	endtag = (fdt32_t *)((char *)nh + nodelen - FDT_TAGSIZE);
 	*endtag = cpu_to_fdt32(FDT_END_NODE);
 
 	return offset;
xen/common/libfdt/fdt_sw.c +2 -2
index 55ebebf..f422754 100644
@@ -153,7 +153,7 @@ int fdt_begin_node(void *fdt, const char *name)
 
 int fdt_end_node(void *fdt)
 {
-	uint32_t *en;
+	fdt32_t *en;
 
 	FDT_SW_CHECK_HEADER(fdt);
 
@@ -213,7 +213,7 @@ int fdt_property(void *fdt, const char *name, const void *val, int len)
 int fdt_finish(void *fdt)
 {
 	char *p = (char *)fdt;
-	uint32_t *end;
+	fdt32_t *end;
 	int oldstroffset, newstroffset;
 	uint32_t tag;
 	int offset, nextoffset;
xen/common/libfdt/fdt_wip.c +1 -1
index 6025fa1..c5bbb68 100644
@@ -74,7 +74,7 @@ int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
 
 static void _fdt_nop_region(void *start, int len)
 {
-	uint32_t *p;
+	fdt32_t *p;
 
 	for (p = start; (char *)p < ((char *)start + len); p++)
 		*p = cpu_to_fdt32(FDT_NOP);
xen/common/libfdt/version.lds +6 -0
index 3c3994e..80b322b 100644
@@ -48,6 +48,12 @@ LIBFDT_1.2 {
 		fdt_strerror;
 		fdt_offset_ptr;
 		fdt_next_tag;
+		fdt_appendprop;
+		fdt_create_empty_tree;
+		fdt_first_property_offset;
+		fdt_get_property_by_offset;
+		fdt_getprop_by_offset;
+		fdt_next_property_offset;
 
 	local:
 		*;
xen/include/xen/libfdt/fdt.h +72 -21

130 lines not on this page · raw message

xen/include/xen/libfdt/libfdt.h +297 -18

398 lines not on this page · raw message

xen/include/xen/libfdt/libfdt_env.h +4 -0
index 2f1b03c..89a794b 100644
@@ -6,6 +6,10 @@
 #include <xen/string.h>
 #include <asm/byteorder.h>
 
+typedef uint16_t fdt16_t;
+typedef uint32_t fdt32_t;
+typedef uint64_t fdt64_t;
+
 #define fdt16_to_cpu(x) be16_to_cpu(x)
 #define cpu_to_fdt16(x) cpu_to_be16(x)
 #define fdt32_to_cpu(x) be32_to_cpu(x)
Signature · 1 line
2.1.0
Acked-by on v5 14/15
#57 lore raw

Re: [PATCH V5 14/15] Update libfdt to v1.4.0

Quoted 6 lines · Roy Franz

Update libfdt to v1.4.0 of libfdt taken from git://git.jdl.com/software/dtc.git
Xen changes to libfdt_env.h carried over from existing libfdt (v1.3.0) This update provides the fdt_create_empty_tree() function used by the ARM EFI boot code.

And I now remember that I planned to apply ths and the previous cache flush one independently. So I have now done so.

For the cache flush I dropped the indent on ENTRY as discussed but I also dropped the __flush_dcache_all label since ENTRY adds that already. I hope that's ok.

Ian.

author
#58 lore raw

Re: [PATCH V5 14/15] Update libfdt to v1.4.0

Quoted 10 lines · Ian Campbell
Quoted 6 lines · Roy Franz

Update libfdt to v1.4.0 of libfdt taken from git://git.jdl.com/software/dtc.git
Xen changes to libfdt_env.h carried over from existing libfdt (v1.3.0) This update provides the fdt_create_empty_tree() function used by the ARM EFI boot code.

Quoted 9 lines

And I now remember that I planned to apply ths and the previous cache flush one independently. So I have now done so.

For the cache flush I dropped the indent on ENTRY as discussed but I also dropped the __flush_dcache_all label since ENTRY adds that already. I hope that's ok.

Ian.

Sure - I'll leave them out of my next series.
I don't see them on the master branch yet though - is there an ARM branch they go to first?

Thanks,
Roy

#59 lore raw

Re: [PATCH V5 14/15] Update libfdt to v1.4.0

Quoted 18 lines · Roy Franz
Quoted 17 lines · Ian Campbell
Quoted 6 lines · Roy Franz

Update libfdt to v1.4.0 of libfdt taken from git://git.jdl.com/software/dtc.git
Xen changes to libfdt_env.h carried over from existing libfdt (v1.3.0) This update provides the fdt_create_empty_tree() function used by the ARM EFI boot code.

And I now remember that I planned to apply ths and the previous cache flush one independently. So I have now done so.

For the cache flush I dropped the indent on ENTRY as discussed but I also dropped the __flush_dcache_all label since ENTRY adds that already. I hope that's ok.

Quoted 6 lines
Quoted 2 lines

Ian.

Sure - I'll leave them out of my next series.
I don't see them on the master branch yet though - is there an ARM branch they go to first?

Things are committed to the "staging" branch which is then propagated to "master" automatically when the tests pass (usually in a day or so, unless there are failures).

Ian.

author
#60 lore raw

PATCH v5 15/15 Add ARM EFI boot support

In reply to Roy Franz

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.
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/xen.lds.S              |   1 +
 xen/common/efi/boot.c               |  12 +-
 xen/common/efi/efi.h                |   2 -
 xen/common/efi/runtime.c            |  15 +-
 xen/include/asm-arm/arm64/efibind.h | 216 +++++++++++++
 xen/include/asm-arm/efi-boot.h      | 593 ++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/efibind.h       |   2 +
 xen/include/asm-arm/setup.h         |   2 +-
 xen/include/asm-x86/efi-boot.h      |   1 +
 13 files changed, 990 insertions(+), 13 deletions(-)
 create mode 100644 xen/arch/arm/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/efibind.h
.gitignore +4 -0
index 1aa4a5b..f8854aa 100644
@@ -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
index c13206f..be51685 100644
@@ -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
new file mode 100644
index 0000000..e8a93e3
@@ -0,0 +1,4 @@
+CFLAGS += -fshort-wchar
+
+obj-y +=  boot.init.o runtime.o
+
xen/arch/arm/xen.lds.S +1 -0
index 079e085..d8b0cfe 100644
@@ -135,6 +135,7 @@ SECTIONS
        *(.xsm_initcall.init)
        __xsm_initcall_end = .;
   } :text
+  __init_end_efi = .;
   . = ALIGN(STACK_SIZE);
   __init_end = .;
 
xen/common/efi/boot.c +9 -3
index 006a73c..0e0c32d 100644
@@ -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 size_t wstrlen(const CHAR16 * s);
 static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
 static bool_t read_file(EFI_FILE_HANDLE dir_handle, struct file *file,
                                CHAR16 *filename, char *options);
+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;
@@ -116,7 +118,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;
 
@@ -654,7 +656,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;
@@ -679,7 +681,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     EFI_STATUS status;
     unsigned int i, argc;
     CHAR16 **argv, *options = NULL;
-    UINTN cols, rows, depth, size, info_size, gop_mode = ~0;
+    UINTN cols, rows, depth = 0, size, info_size, gop_mode = ~0;
     EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
@@ -983,8 +985,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();
@@ -1055,6 +1059,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,
@@ -1280,3 +1285,4 @@ void __init efi_init_memory(void)
         efi_l4_pgtable[i] = idle_pg_table[i];
 #endif
 }
+#endif
xen/common/efi/efi.h +0 -2
index a80d5f1..09b0b0d 100644
@@ -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
index 166852d..ac9deae 100644
@@ -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/efi-boot.h new file +593 -0

593 lines not on this page · raw message

xen/include/asm-arm/efibind.h new file +2 -0
new file mode 100644
index 0000000..09dca7a
@@ -0,0 +1,2 @@
+#include <xen/types.h>
+#include <asm/arm64/efibind.h>
xen/include/asm-arm/setup.h +1 -1
index 36e5704..ba5a67d 100644
@@ -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 */
 
xen/include/asm-x86/efi-boot.h +1 -0
index 3ff593d..cb79956 100644
@@ -19,6 +19,7 @@ static module_t __initdata mb_modules[3];
 
 extern char start[];
 extern u32 cpuid_ext_features;
+extern l4_pgentry_t *efi_l4_pgtable;
 
 static void __init edd_put_string(u8 *dst, size_t n, const char *src)
 {
Signature · 1 line
2.1.0
#61 lore raw

Re: [PATCH V5 15/15] Add ARM EFI boot support

xen/common/efi/efi.h extern EFI_RUNTIME_SERVICES *efi_rs; · line 31

Quoted 9 lines · Roy Franz
xen/common/efi/efi.h +0 -1
index a80d5f1..09b0b0d 100644
@@ -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;

FWIW l4_pgentry_t is an x86 specific type and to add to the confusion ARM counts the other way (so L4==root,L1==leaf on x86 and L0==root,L3==leaf on ARM...)

But I presume handling that correctly is being put off until RTS support, which is fine by me.

xen/include/asm-arm/efi-boot.h line 3

Quoted 9 lines
xen/include/asm-arm/efi-boot.h new file +3 -0
new file mode 100644
index 0000000..4a1877a
@@ -0,0 +1,593 @@
+/*
+ * Architecture specific implementation for EFI boot code.  This file
+ * is intended to be included by XXX _only_, and therefore can define

I guess you meant to come back to the XXX here (I didn't check if the x86 version had something similar).

If XXX is another header then it wouldn't be unreasonable to have an #ifndef check for that header's guard variable and a #error.

Ian.

author
#62 lore raw

Re: [PATCH V5 15/15] Add ARM EFI boot support

Quoted 10 lines · Ian Campbell
Quoted 8 lines · Roy Franz
xen/common/efi/efi.h +0 -0
index a80d5f1..09b0b0d 100644
@@ -28,8 +28,6 @@ extern EFI_RUNTIME_SERVICES *efi_rs;
 extern UINTN efi_memmap_size, efi_mdesc_size;
 extern void *efi_memmap;
 
Quoted 8 lines

xen/common/efi/efi.h extern EFI_RUNTIME_SERVICES *efi_rs; · line 31

Quoted 1 line
xen/common/efi/efi.h +0 -1
-extern l4_pgentry_t *efi_l4_pgtable;

FWIW l4_pgentry_t is an x86 specific type and to add to the confusion ARM counts the other way (so L4==root,L1==leaf on x86 and L0==root,L3==leaf on ARM...)

But I presume handling that correctly is being put off until RTS support, which is fine by me.

Yes, this extern was moved to the x86 specific header file, and the equivalent is not
needed for ARM until runtime services are implemented.

Quoted 14 lines

xen/include/asm-arm/efi-boot.h line 3

Quoted 10 lines
xen/include/asm-arm/efi-boot.h new file +3 -0
new file mode 100644
index 0000000..4a1877a
@@ -0,0 +1,593 @@
+/*
+ * Architecture specific implementation for EFI boot code.  This file
+ * is intended to be included by XXX _only_, and therefore can define

I guess you meant to come back to the XXX here (I didn't check if the x86 version had something similar).

Quoted 5 lines

If XXX is another header then it wouldn't be unreasonable to have an #ifndef check for that header's guard variable and a #error.

Ian.

oops :) That xxx needs to be fixed up - it should be xen/common/efi/boot.c.

Roy