Re: [Xen-devel] [PATCH v2 07/23] x86/boot/reloc: Rename some variables and rearrange code a bit

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:02PM +0200, Daniel Kiper wrote:
 Rename mbi and mbi_old variables and rearrange code a bit to make

s/mbi_old/mbi_in/

Perhaps you want to say: rename mbi_old with mbi_in, and mbi with mbi_out

or better:

Replace mbi with mbi_out and mbi_old with mbi_in and ...


 it more readable. Additionally, this way multiboot (v1) protocol
 implementation and future multiboot2 protocol implementation will
 use the same variable naming convention.
 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
 ---
 v2 - suggestions/fixes:
- extract this change from main mutliboot2
  protocol implementation
  (suggested by Jan Beulich).
 ---
  xen/arch/x86/boot/reloc.c |   39 +--
  1 file changed, 21 insertions(+), 18 deletions(-)
 
 diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c
 index 09fd540..feb1d72 100644
 --- a/xen/arch/x86/boot/reloc.c
 +++ b/xen/arch/x86/boot/reloc.c
 @@ -86,41 +86,44 @@ static u32 copy_string(u32 src)
  return copy_mem(src, p - src + 1);
  }
  
 -multiboot_info_t *reloc(u32 mbi_old)
 +multiboot_info_t *reloc(u32 mbi_in)
  {
 -multiboot_info_t *mbi = (multiboot_info_t *)copy_mem(mbi_old, 
 sizeof(*mbi));
  int i;
 +multiboot_info_t *mbi_out;
  
 -if ( mbi-flags  MBI_CMDLINE )
 -mbi-cmdline = copy_string(mbi-cmdline);
 +mbi_out = (multiboot_info_t *)copy_mem(mbi_in, sizeof(*mbi_out));
  
 -if ( mbi-flags  MBI_MODULES )
 +if ( mbi_out-flags  MBI_CMDLINE )
 +mbi_out-cmdline = copy_string(mbi_out-cmdline);
 +
 +if ( mbi_out-flags  MBI_MODULES )
  {
  module_t *mods;
  
 -mbi-mods_addr = copy_mem(mbi-mods_addr, mbi-mods_count * 
 sizeof(module_t));
 +mbi_out-mods_addr = copy_mem(mbi_out-mods_addr,
 +  mbi_out-mods_count * 
 sizeof(module_t));
  
 -mods = (module_t *)mbi-mods_addr;
 +mods = (module_t *)mbi_out-mods_addr;
  
 -for ( i = 0; i  mbi-mods_count; i++ )
 +for ( i = 0; i  mbi_out-mods_count; i++ )
  {
  if ( mods[i].string )
  mods[i].string = copy_string(mods[i].string);
  }
  }
  
 -if ( mbi-flags  MBI_MEMMAP )
 -mbi-mmap_addr = copy_mem(mbi-mmap_addr, mbi-mmap_length);
 +if ( mbi_out-flags  MBI_MEMMAP )
 +mbi_out-mmap_addr = copy_mem(mbi_out-mmap_addr, 
 mbi_out-mmap_length);
  
 -if ( mbi-flags  MBI_LOADERNAME )
 -mbi-boot_loader_name = copy_string(mbi-boot_loader_name);
 +if ( mbi_out-flags  MBI_LOADERNAME )
 +mbi_out-boot_loader_name = copy_string(mbi_out-boot_loader_name);
  
  /* Mask features we don't understand or don't relocate. */
 -mbi-flags = (MBI_MEMLIMITS |
 -   MBI_CMDLINE |
 -   MBI_MODULES |
 -   MBI_MEMMAP |
 -   MBI_LOADERNAME);
 +mbi_out-flags = (MBI_MEMLIMITS |
 +   MBI_CMDLINE |
 +   MBI_MODULES |
 +   MBI_MEMMAP |
 +   MBI_LOADERNAME);
  
 -return mbi;
 +return mbi_out;
  }
 -- 
 1.7.10.4
 
 
 ___
 Xen-devel mailing list
 xen-de...@lists.xen.org
 http://lists.xen.org/xen-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [Xen-devel] [PATCH v2 06/23] x86/boot: use %ecx instead of %eax

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:01PM +0200, Daniel Kiper wrote:
 Use %ecx instead of %eax to store low memory upper limit from EBDA.
 This way we do not wipe multiboot protocol identifier. It is needed
 in reloc() to differentiate between multiboot (v1) and
 multiboot2 protocol.
 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com
 Reviewed-by: Andrew Cooper andrew.coop...@citrix.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
 ---
  xen/arch/x86/boot/head.S |   24 
  1 file changed, 12 insertions(+), 12 deletions(-)
 
 diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
 index 3cbb2e6..77e7da9 100644
 --- a/xen/arch/x86/boot/head.S
 +++ b/xen/arch/x86/boot/head.S
 @@ -87,14 +87,14 @@ __start:
  jne not_multiboot
  
  /* Set up trampoline segment 64k below EBDA */
 -movzwl  0x40e,%eax  /* EBDA segment */
 -cmp $0xa000,%eax/* sanity check (high) */
 +movzwl  0x40e,%ecx  /* EBDA segment */
 +cmp $0xa000,%ecx/* sanity check (high) */
  jae 0f
 -cmp $0x4000,%eax/* sanity check (low) */
 +cmp $0x4000,%ecx/* sanity check (low) */
  jae 1f
  0:
 -movzwl  0x413,%eax  /* use base memory size on failure */
 -shl $10-4,%eax
 +movzwl  0x413,%ecx  /* use base memory size on failure */
 +shl $10-4,%ecx
  1:
  /*
   * Compare the value in the BDA with the information from the
 @@ -106,21 +106,21 @@ __start:
  cmp $0x100,%edx /* is the multiboot value too small? */
  jb  2f  /* if so, do not use it */
  shl $10-4,%edx
 -cmp %eax,%edx   /* compare with BDA value */
 -cmovb   %edx,%eax   /* and use the smaller */
 +cmp %ecx,%edx   /* compare with BDA value */
 +cmovb   %edx,%ecx   /* and use the smaller */
  
  2:  /* Reserve 64kb for the trampoline */
 -sub $0x1000,%eax
 +sub $0x1000,%ecx
  
  /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
 -xor %al, %al
 -shl $4, %eax
 -mov %eax,sym_phys(trampoline_phys)
 +xor %cl, %cl
 +shl $4, %ecx
 +mov %ecx,sym_phys(trampoline_phys)
  
  /* Save the Multiboot info struct (after relocation) for later use. 
 */
  mov $sym_phys(cpu0_stack)+1024,%esp
  push%ebx/* Multiboot information address. */
 -push%eax/* Boot trampoline address. */
 +push%ecx/* Boot trampoline address. */
  callreloc
  add $8,%esp /* Remove reloc() args from stack. */
  mov %eax,sym_phys(multiboot_ptr)
 -- 
 1.7.10.4
 
 
 ___
 Xen-devel mailing list
 xen-de...@lists.xen.org
 http://lists.xen.org/xen-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [Xen-devel] [PATCH v2 08/23] x86: add multiboot2 protocol support

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:03PM +0200, Daniel Kiper wrote:
 Add multiboot2 protocol support. Alter min memory limit handling as we
 now may not find it from either multiboot (v1) or multiboot2.
 
 This way we are laying the foundation for EFI + GRUB2 + Xen development.
 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com
 Reviewed-by: Andrew Cooper andrew.coop...@citrix.com
 ---
 v2 - suggestions/fixes:
- generate multiboot2 header using macros
  (suggested by Jan Beulich),
- improve comments
  (suggested by Jan Beulich),
- simplify assembly in xen/arch/x86/boot/head.S
  (suggested by Jan Beulich),
- do not include include/xen/compiler.h
  in xen/arch/x86/boot/reloc.c
  (suggested by Jan Beulich),
- do not read data beyond the end of Multiboot2 information
  (suggested by Jan Beulich).
 
 v2 - not fixed yet:

You have two 'v2' 

- dynamic dependency generation for xen/arch/x86/boot/reloc.S;
  this requires more work; I am not sure that it pays because
  potential patch requires more changes than addition of just
  multiboot2.h to Makefile
  (suggested by Jan Beulich),
- isolated/stray __packed attribute usage for multiboot2_memory_map_t
  (suggested by Jan Beulich).
 ---
  xen/arch/x86/boot/Makefile|3 +-
  xen/arch/x86/boot/head.S  |  105 +--
  xen/arch/x86/boot/reloc.c |  146 +++-
  xen/arch/x86/x86_64/asm-offsets.c |7 ++
  xen/include/xen/multiboot2.h  |  169 
 +
  5 files changed, 420 insertions(+), 10 deletions(-)
  create mode 100644 xen/include/xen/multiboot2.h
 
 diff --git a/xen/arch/x86/boot/Makefile b/xen/arch/x86/boot/Makefile
 index 5fdb5ae..06893d8 100644
 --- a/xen/arch/x86/boot/Makefile
 +++ b/xen/arch/x86/boot/Makefile
 @@ -1,6 +1,7 @@
  obj-bin-y += head.o
  
 -RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h 
 $(BASEDIR)/include/xen/multiboot.h
 +RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h 
 $(BASEDIR)/include/xen/multiboot.h \
 +  $(BASEDIR)/include/xen/multiboot2.h
  
  head.o: reloc.S
  
 diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
 index 77e7da9..57197db 100644
 --- a/xen/arch/x86/boot/head.S
 +++ b/xen/arch/x86/boot/head.S
 @@ -1,5 +1,6 @@
  #include xen/config.h
  #include xen/multiboot.h
 +#include xen/multiboot2.h
  #include public/xen.h
  #include asm/asm_defns.h
  #include asm/desc.h
 @@ -19,6 +20,28 @@
  #define BOOT_PSEUDORM_CS 0x0020
  #define BOOT_PSEUDORM_DS 0x0028
  
 +#define MB2_HT(name)  (MULTIBOOT2_HEADER_TAG_##name)
 +#define MB2_TT(name)  (MULTIBOOT2_TAG_TYPE_##name)
 +
 +.macro mb2ht_args arg, args:vararg
 +.long \arg
 +.ifnb \args
 +mb2ht_args \args
 +.endif
 +.endm
 +
 +.macro mb2ht_init type, req, args:vararg
 +.align MULTIBOOT2_TAG_ALIGN
 +0:
 +.short \type
 +.short \req
 +.long 1f - 0b
 +.ifnb \args
 +mb2ht_args \args
 +.endif
 +1:
 +.endm
 +
  ENTRY(start)
  jmp __start
  
 @@ -34,6 +57,42 @@ multiboot1_header_start:   /*** MULTIBOOT1 HEADER /
  .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
  multiboot1_header_end:
  
 +/*** MULTIBOOT2 HEADER /
 +/* Some ideas are taken from grub-2.00/grub-core/tests/boot/kernel-i386.S 
 file. */
 +.align  MULTIBOOT2_HEADER_ALIGN
 +
 +.Lmultiboot2_header:

How come you use .L? It makes this hidden while the multiboot1 headers
are visible? Makes it a bit harder to see the contents of this under
an debugger.

 +/* Magic number indicating a Multiboot2 header. */
 +.long   MULTIBOOT2_HEADER_MAGIC
 +/* Architecture: i386. */
 +.long   MULTIBOOT2_ARCHITECTURE_I386
 +/* Multiboot2 header length. */
 +.long   .Lmultiboot2_header_end - .Lmultiboot2_header
 +/* Multiboot2 header checksum. */
 +.long   -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_ARCHITECTURE_I386 + \
 +(.Lmultiboot2_header_end - .Lmultiboot2_header))
 +
 +/* Multiboot2 information request tag. */
 +mb2ht_init MB2_HT(INFORMATION_REQUEST), MB2_HT(REQUIRED), \
 +   MB2_TT(BASIC_MEMINFO), MB2_TT(MMAP)
 +
 +/* Align modules at page boundry. */
 +mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED)
 +
 +/* Console flags tag. */
 +mb2ht_init MB2_HT(CONSOLE_FLAGS), MB2_HT(OPTIONAL), \
 +   MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED
 +
 +/* Framebuffer tag. */
 +mb2ht_init MB2_HT(FRAMEBUFFER), MB2_HT(OPTIONAL), \
 +   0, /* Number of the columns - no preference. */ \
 +   0, /* Number of the lines - no preference. */ \
 +   0  /* Number of bits per pixel - no preference. */
 +
 +/* Multiboot2 header end tag. */
 +

Re: [Xen-devel] [PATCH v2 18/23] efi: split out efi_exit_boot()

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:13PM +0200, Daniel Kiper wrote:
 ..which gets memory map and calls ExitBootServices(). We want to re-use this
 code to support multiboot2 protocol on EFI platforms.
 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
 ---
 v2 - suggestions/fixes:
- improve commit message
  (suggested by Jan Beulich).
 ---
  xen/common/efi/boot.c |   92 
 +++--
  1 file changed, 50 insertions(+), 42 deletions(-)
 
 diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
 index 04b9c7e..bf2f198 100644
 --- a/xen/common/efi/boot.c
 +++ b/xen/common/efi/boot.c
 @@ -879,6 +879,53 @@ static void __init 
 efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop
  efi_arch_video_init(gop, info_size, mode_info);
  }
  
 +static void __init efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
 +{
 +EFI_STATUS status;
 +UINTN info_size = 0, map_key;
 +bool_t retry;
 +
 +efi_bs-GetMemoryMap(info_size, NULL, map_key,
 + efi_mdesc_size, mdesc_ver);
 +info_size += 8 * efi_mdesc_size;
 +efi_memmap = efi_arch_allocate_mmap_buffer(info_size);
 +if ( !efi_memmap )
 +blexit(LUnable to allocate memory for EFI memory map);
 +
 +for ( retry = 0; ; retry = 1 )
 +{
 +efi_memmap_size = info_size;
 +status = SystemTable-BootServices-GetMemoryMap(efi_memmap_size,
 + efi_memmap, 
 map_key,
 + efi_mdesc_size,
 + mdesc_ver);
 +if ( EFI_ERROR(status) )
 +PrintErrMesg(LCannot obtain memory map, status);
 +
 +efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
 +efi_mdesc_size, mdesc_ver);
 +
 +efi_arch_pre_exit_boot();
 +
 +status = SystemTable-BootServices-ExitBootServices(ImageHandle,
 + map_key);
 +efi_bs = NULL;
 +if ( status != EFI_INVALID_PARAMETER || retry )
 +break;
 +}
 +
 +if ( EFI_ERROR(status) )
 +PrintErrMesg(LCannot exit boot services, status);
 +
 +/* Adjust pointers into EFI. */
 +efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START;
 +#ifdef USE_SET_VIRTUAL_ADDRESS_MAP
 +efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START;
 +#endif
 +efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
 +efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
 +}
 +
  static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 
 *sz)
  {
 if ( bpp  0 )
 @@ -903,11 +950,11 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
  EFI_STATUS status;
  unsigned int i, argc;
  CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
 -UINTN map_key, info_size, gop_mode = ~0;
 +UINTN gop_mode = ~0;
  EFI_SHIM_LOCK_PROTOCOL *shim_lock;
  EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
  union string section = { NULL }, name;
 -bool_t base_video = 0, retry;
 +bool_t base_video = 0;
  char *option_str;
  bool_t use_cfg_file;
  
 @@ -1125,46 +1172,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
  
  efi_set_gop_mode(gop, gop_mode);
  
 -info_size = 0;
 -efi_bs-GetMemoryMap(info_size, NULL, map_key,
 - efi_mdesc_size, mdesc_ver);
 -info_size += 8 * efi_mdesc_size;
 -efi_memmap = efi_arch_allocate_mmap_buffer(info_size);
 -if ( !efi_memmap )
 -blexit(LUnable to allocate memory for EFI memory map);
 -
 -for ( retry = 0; ; retry = 1 )
 -{
 -efi_memmap_size = info_size;
 -status = SystemTable-BootServices-GetMemoryMap(efi_memmap_size,
 - efi_memmap, 
 map_key,
 - efi_mdesc_size,
 - mdesc_ver);
 -if ( EFI_ERROR(status) )
 -PrintErrMesg(LCannot obtain memory map, status);
 -
 -efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
 -efi_mdesc_size, mdesc_ver);
 -
 -efi_arch_pre_exit_boot();
 -
 -status = SystemTable-BootServices-ExitBootServices(ImageHandle,
 - map_key);
 -efi_bs = NULL;
 -if ( status != EFI_INVALID_PARAMETER || retry )
 -break;
 -}
 -
 -if ( EFI_ERROR(status) )
 -PrintErrMesg(LCannot exit boot services, status);
 -
 -/* Adjust pointers into EFI. */
 -efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START;
 -#ifdef USE_SET_VIRTUAL_ADDRESS_MAP
 -efi_rs = (void *)efi_rs 

Re: [PATCH v2 01/23] x86/boot: remove unneeded instruction

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 27, 2015 at 09:46:08PM +0200, Daniel Kiper wrote:
 On Fri, Jul 24, 2015 at 12:22:57PM -0400, Konrad Rzeszutek Wilk wrote:
  On Mon, Jul 20, 2015 at 04:28:56PM +0200, Daniel Kiper wrote:
   Signed-off-by: Daniel Kiper daniel.ki...@oracle.com
 
  Don't you use it in:
 
  /* Switch to low-memory stack.  */
  193 mov sym_phys(trampoline_phys),%edi
  194 lea 0x1(%edi),%esp
  195 lea trampoline_boot_cpu_entry-trampoline_start(%edi),%eax
  ?
 
 Yep, but...
 
   ---
xen/arch/x86/boot/head.S |1 -
1 file changed, 1 deletion(-)
  
   diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
   index cfd59dc..f63b349 100644
   --- a/xen/arch/x86/boot/head.S
   +++ b/xen/arch/x86/boot/head.S
   @@ -169,7 +169,6 @@ __start:
/* Apply relocations to bootstrap trampoline. */
mov sym_phys(trampoline_phys),%edx
 
 ...relevant value is stored in sym_phys(trampoline_phys) earlier then it is
 read into %edx here and...
 
mov $sym_phys(__trampoline_rel_start),%edi
   -mov %edx,sym_phys(trampoline_phys)
 
 ...it is put back to sym_phys(trampoline_phys) without any change here :-))).
 So, I suppose this is remnant from something which was removed once but
 somebody forgot to remove this instruction too... This patch fixes it.

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [Xen-devel] [PATCH v2 04/23] x86/boot: call reloc() using cdecl calling convention

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:28:59PM +0200, Daniel Kiper wrote:
 Suggested-by: Jan Beulich jbeul...@suse.com
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com

 ---
  xen/arch/x86/boot/head.S  |4 +++-
  xen/arch/x86/boot/reloc.c |   20 
  2 files changed, 19 insertions(+), 5 deletions(-)
 
 diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
 index ed42782..3cbb2e6 100644
 --- a/xen/arch/x86/boot/head.S
 +++ b/xen/arch/x86/boot/head.S
 @@ -119,8 +119,10 @@ __start:
  
  /* Save the Multiboot info struct (after relocation) for later use. 
 */
  mov $sym_phys(cpu0_stack)+1024,%esp
 -push%ebx
 +push%ebx/* Multiboot information address. */
 +push%eax/* Boot trampoline address. */
  callreloc
 +add $8,%esp /* Remove reloc() args from stack. */
  mov %eax,sym_phys(multiboot_ptr)
  
  /* Initialize BSS (no nasty surprises!). */
 diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c
 index 63045c0..708898f 100644
 --- a/xen/arch/x86/boot/reloc.c
 +++ b/xen/arch/x86/boot/reloc.c
 @@ -10,15 +10,27 @@
   *Keir Fraser k...@xen.org
   */
  
 -/* entered with %eax = BOOT_TRAMPOLINE */
 +/*
 + * This entry point is entered from xen/arch/x86/boot/head.S with:
 + *   - 0x4(%esp) = BOOT_TRAMPOLINE_ADDRESS,
 + *   - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS.
 + */
  asm (
  .text \n
  .globl _start \n
  _start:   \n
 +push %ebp \n
 +mov  %esp,%ebp\n
  call 1f   \n
 -1:  pop  %ebx \n
 -mov  %eax,alloc-1b(%ebx)  \n
 -jmp  reloc\n
 +1:  pop  %ecx \n
 +mov  0x8(%ebp),%eax   \n
 +mov  %eax,alloc-1b(%ecx)  \n
 +mov  0xc(%ebp),%eax   \n
 +push %eax \n
 +call reloc\n
 +add  $4,%esp  \n
 +pop  %ebp \n
 +ret   \n
  );
  
  /*
 -- 
 1.7.10.4
 
 
 ___
 Xen-devel mailing list
 xen-de...@lists.xen.org
 http://lists.xen.org/xen-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [Xen-devel] [PATCH v2 11/23] efi: split out efi_init()

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:06PM +0200, Daniel Kiper wrote:
 ..which initializes basic EFI variables. We want to re-use this
 code to support multiboot2 protocol on EFI platforms.
 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
 ---
 v2 - suggestions/fixes:
- improve commit message
  (suggested by Jan Beulich).
 ---
  xen/common/efi/boot.c |   28 +---
  1 file changed, 17 insertions(+), 11 deletions(-)
 
 diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
 index 1f188fe..6f327cd 100644
 --- a/xen/common/efi/boot.c
 +++ b/xen/common/efi/boot.c
 @@ -595,6 +595,22 @@ static char *__init get_value(const struct file *cfg, 
 const char *section,
  return NULL;
  }
  
 +static void __init efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
 +{
 +efi_ih = ImageHandle;
 +efi_bs = SystemTable-BootServices;
 +efi_bs_revision = efi_bs-Hdr.Revision;
 +efi_rs = SystemTable-RuntimeServices;
 +efi_ct = SystemTable-ConfigurationTable;
 +efi_num_ct = SystemTable-NumberOfTableEntries;
 +efi_version = SystemTable-Hdr.Revision;
 +efi_fw_vendor = SystemTable-FirmwareVendor;
 +efi_fw_revision = SystemTable-FirmwareRevision;
 +
 +StdOut = SystemTable-ConOut;
 +StdErr = SystemTable-StdErr ?: StdOut;
 +}
 +
  static void __init setup_efi_pci(void)
  {
  EFI_STATUS status;
 @@ -721,18 +737,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
  set_bit(EFI_PLATFORM, efi.flags);
  #endif
  
 -efi_ih = ImageHandle;
 -efi_bs = SystemTable-BootServices;
 -efi_bs_revision = efi_bs-Hdr.Revision;
 -efi_rs = SystemTable-RuntimeServices;
 -efi_ct = SystemTable-ConfigurationTable;
 -efi_num_ct = SystemTable-NumberOfTableEntries;
 -efi_version = SystemTable-Hdr.Revision;
 -efi_fw_vendor = SystemTable-FirmwareVendor;
 -efi_fw_revision = SystemTable-FirmwareRevision;
 +efi_init(ImageHandle, SystemTable);
  
 -StdOut = SystemTable-ConOut;
 -StdErr = SystemTable-StdErr ?: StdOut;
  use_cfg_file = efi_arch_use_config_file(SystemTable);
  
  status = efi_bs-HandleProtocol(ImageHandle, loaded_image_guid,
 -- 
 1.7.10.4
 
 
 ___
 Xen-devel mailing list
 xen-de...@lists.xen.org
 http://lists.xen.org/xen-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [Xen-devel] [PATCH v2 12/23] efi: split out efi_console_set_mode()

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:07PM +0200, Daniel Kiper wrote:
 ..which sets console mode. We want to re-use this
 code to support multiboot2 protocol on EFI platforms.
 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
 ---
 v2 - suggestions/fixes:
- improve commit message
  (suggested by Jan Beulich).
 ---
  xen/common/efi/boot.c |   37 -
  1 file changed, 20 insertions(+), 17 deletions(-)
 
 diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
 index 6f327cd..4614146 100644
 --- a/xen/common/efi/boot.c
 +++ b/xen/common/efi/boot.c
 @@ -611,6 +611,25 @@ static void __init efi_init(EFI_HANDLE ImageHandle, 
 EFI_SYSTEM_TABLE *SystemTabl
  StdErr = SystemTable-StdErr ?: StdOut;
  }
  
 +static void __init efi_console_set_mode(void)
 +{
 +UINTN cols, rows, size;
 +unsigned int best, i;
 +
 +for ( i = 0, size = 0, best = StdOut-Mode-Mode;
 +  i  StdOut-Mode-MaxMode; ++i )
 +{
 +if ( StdOut-QueryMode(StdOut, i, cols, rows) == EFI_SUCCESS 
 + cols * rows  size )
 +{
 +size = cols * rows;
 +best = i;
 +}
 +}
 +if ( best != StdOut-Mode-Mode )
 +StdOut-SetMode(StdOut, best);
 +}
 +
  static void __init setup_efi_pci(void)
  {
  EFI_STATUS status;
 @@ -799,23 +818,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
  }
  
  if ( !base_video )
 -{
 -unsigned int best;
 -UINTN cols, rows, size;
 -
 -for ( i = 0, size = 0, best = StdOut-Mode-Mode;
 -  i  StdOut-Mode-MaxMode; ++i )
 -{
 -if ( StdOut-QueryMode(StdOut, i, cols, rows) == 
 EFI_SUCCESS 
 - cols * rows  size )
 -{
 -size = cols * rows;
 -best = i;
 -}
 -}
 -if ( best != StdOut-Mode-Mode )
 -StdOut-SetMode(StdOut, best);
 -}
 +efi_console_set_mode();
  }
  
  PrintStr(LXen  __stringify(XEN_VERSION) . __stringify(XEN_SUBVERSION)
 -- 
 1.7.10.4
 
 
 ___
 Xen-devel mailing list
 xen-de...@lists.xen.org
 http://lists.xen.org/xen-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [Xen-devel] [PATCH v2 15/23] efi: split out efi_tables()

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:10PM +0200, Daniel Kiper wrote:
 ..which collects system tables data. We want to re-use this
 code to support multiboot2 protocol on EFI platforms.
 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
 ---
 v2 - suggestions/fixes:
- improve commit message
  (suggested by Jan Beulich).
 ---
  xen/common/efi/boot.c |   61 
 +++--
  1 file changed, 34 insertions(+), 27 deletions(-)
 
 diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
 index 8d16470..fd62125 100644
 --- a/xen/common/efi/boot.c
 +++ b/xen/common/efi/boot.c
 @@ -717,6 +717,39 @@ static UINTN __init 
 efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
  return gop_mode;
  }
  
 +static void __init efi_tables(void)
 +{
 +unsigned int i;
 +
 +/* Obtain basic table pointers. */
 +for ( i = 0; i  efi_num_ct; ++i )
 +{
 +static EFI_GUID __initdata acpi2_guid = ACPI_20_TABLE_GUID;
 +static EFI_GUID __initdata acpi_guid = ACPI_TABLE_GUID;
 +static EFI_GUID __initdata mps_guid = MPS_TABLE_GUID;
 +static EFI_GUID __initdata smbios_guid = SMBIOS_TABLE_GUID;
 +static EFI_GUID __initdata smbios3_guid = SMBIOS3_TABLE_GUID;
 +
 +if ( match_guid(acpi2_guid, efi_ct[i].VendorGuid) )
 +efi.acpi20 = (long)efi_ct[i].VendorTable;
 +if ( match_guid(acpi_guid, efi_ct[i].VendorGuid) )
 +efi.acpi = (long)efi_ct[i].VendorTable;
 +if ( match_guid(mps_guid, efi_ct[i].VendorGuid) )
 +efi.mps = (long)efi_ct[i].VendorTable;
 +if ( match_guid(smbios_guid, efi_ct[i].VendorGuid) )
 +efi.smbios = (long)efi_ct[i].VendorTable;
 +if ( match_guid(smbios3_guid, efi_ct[i].VendorGuid) )
 +efi.smbios3 = (long)efi_ct[i].VendorTable;
 +}
 +
 +#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
 +dmi_efi_get_table(efi.smbios != EFI_INVALID_TABLE_ADDR
 +  ? (void *)(long)efi.smbios : NULL,
 +  efi.smbios3 != EFI_INVALID_TABLE_ADDR
 +  ? (void *)(long)efi.smbios3 : NULL);
 +#endif
 +}
 +
  static void __init setup_efi_pci(void)
  {
  EFI_STATUS status;
 @@ -1039,33 +1072,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
  /* XXX Collect EDID info. */
  efi_arch_cpu();
  
 -/* Obtain basic table pointers. */
 -for ( i = 0; i  efi_num_ct; ++i )
 -{
 -static EFI_GUID __initdata acpi2_guid = ACPI_20_TABLE_GUID;
 -static EFI_GUID __initdata acpi_guid = ACPI_TABLE_GUID;
 -static EFI_GUID __initdata mps_guid = MPS_TABLE_GUID;
 -static EFI_GUID __initdata smbios_guid = SMBIOS_TABLE_GUID;
 -static EFI_GUID __initdata smbios3_guid = SMBIOS3_TABLE_GUID;
 -
 -if ( match_guid(acpi2_guid, efi_ct[i].VendorGuid) )
 -efi.acpi20 = (long)efi_ct[i].VendorTable;
 -if ( match_guid(acpi_guid, efi_ct[i].VendorGuid) )
 -efi.acpi = (long)efi_ct[i].VendorTable;
 -if ( match_guid(mps_guid, efi_ct[i].VendorGuid) )
 -efi.mps = (long)efi_ct[i].VendorTable;
 -if ( match_guid(smbios_guid, efi_ct[i].VendorGuid) )
 -efi.smbios = (long)efi_ct[i].VendorTable;
 -if ( match_guid(smbios3_guid, efi_ct[i].VendorGuid) )
 -efi.smbios3 = (long)efi_ct[i].VendorTable;
 -}
 -
 -#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
 -dmi_efi_get_table(efi.smbios != EFI_INVALID_TABLE_ADDR
 -  ? (void *)(long)efi.smbios : NULL,
 -  efi.smbios3 != EFI_INVALID_TABLE_ADDR
 -  ? (void *)(long)efi.smbios3 : NULL);
 -#endif
 +efi_tables();
  
  /* Collect PCI ROM contents. */
  setup_efi_pci();
 -- 
 1.7.10.4
 
 
 ___
 Xen-devel mailing list
 xen-de...@lists.xen.org
 http://lists.xen.org/xen-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [Xen-devel] [PATCH v2 09/23] efi: create efi_enabled()

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:04PM +0200, Daniel Kiper wrote:
 We need more fine grained knowledge about EFI environment and check
 for EFI platform and EFI loader separately to properly support
 multiboot2 protocol. In general Xen loaded by this protocol uses
 memory mappings and loaded modules in similar way to Xen loaded
 by multiboot (v1) protocol. Hence, create efi_enabled() which
 checks available features in efi.flags. This patch only defines
 EFI_PLATFORM feature which is equal to old efi_enabled == 1.
 Following patch will define EFI_LOADER feature accordingly.
 
 Suggested-by: Jan Beulich jbeul...@suse.com
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
 ---
  xen/arch/x86/dmi_scan.c|4 ++--
  xen/arch/x86/domain_page.c |2 +-
  xen/arch/x86/efi/stub.c|   11 ---
  xen/arch/x86/mpparse.c |4 ++--
  xen/arch/x86/setup.c   |   10 +-
  xen/arch/x86/shutdown.c|2 +-
  xen/arch/x86/time.c|2 +-
  xen/arch/x86/xen.lds.S |2 --
  xen/common/efi/boot.c  |4 
  xen/common/efi/runtime.c   |   17 +++--
  xen/drivers/acpi/osl.c |2 +-
  xen/include/xen/efi.h  |   16 ++--
  12 files changed, 46 insertions(+), 30 deletions(-)
 
 diff --git a/xen/arch/x86/dmi_scan.c b/xen/arch/x86/dmi_scan.c
 index 269168c..95c5a77 100644
 --- a/xen/arch/x86/dmi_scan.c
 +++ b/xen/arch/x86/dmi_scan.c
 @@ -229,7 +229,7 @@ const char *__init dmi_get_table(paddr_t *base, u32 *len)
  {
   static unsigned int __initdata instance;
  
 - if (efi_enabled) {
 + if (efi_enabled(EFI_PLATFORM)) {
   if (efi_smbios3_size  !(instance  1)) {
   *base = efi_smbios3_address;
   *len = efi_smbios3_size;
 @@ -693,7 +693,7 @@ static void __init dmi_decode(struct dmi_header *dm)
  
  void __init dmi_scan_machine(void)
  {
 - if ((!efi_enabled ? dmi_iterate(dmi_decode) :
 + if ((!efi_enabled(EFI_PLATFORM) ? dmi_iterate(dmi_decode) :
   dmi_efi_iterate(dmi_decode)) == 0)
   dmi_check_system(dmi_blacklist);
   else
 diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c
 index d86f8fe..fdf0d8a 100644
 --- a/xen/arch/x86/domain_page.c
 +++ b/xen/arch/x86/domain_page.c
 @@ -36,7 +36,7 @@ static inline struct vcpu *mapcache_current_vcpu(void)
   * domain's page tables but current may point at another domain's VCPU.
   * Return NULL as though current is not properly set up yet.
   */
 -if ( efi_enabled  efi_rs_using_pgtables() )
 +if ( efi_enabled(EFI_PLATFORM)  efi_rs_using_pgtables() )
  return NULL;
  
  /*
 diff --git a/xen/arch/x86/efi/stub.c b/xen/arch/x86/efi/stub.c
 index 07c2bd0..c5ae369 100644
 --- a/xen/arch/x86/efi/stub.c
 +++ b/xen/arch/x86/efi/stub.c
 @@ -4,9 +4,14 @@
  #include xen/lib.h
  #include asm/page.h
  
 -#ifndef efi_enabled
 -const bool_t efi_enabled = 0;
 -#endif
 +struct efi __read_mostly efi = {
 + .flags   = 0, /* Initialized later. */
 + .acpi= EFI_INVALID_TABLE_ADDR,
 + .acpi20  = EFI_INVALID_TABLE_ADDR,
 + .mps = EFI_INVALID_TABLE_ADDR,
 + .smbios  = EFI_INVALID_TABLE_ADDR,
 + .smbios3 = EFI_INVALID_TABLE_ADDR
 +};
  
  void __init efi_init_memory(void) { }
  
 diff --git a/xen/arch/x86/mpparse.c b/xen/arch/x86/mpparse.c
 index 8609f4a..5223579 100644
 --- a/xen/arch/x86/mpparse.c
 +++ b/xen/arch/x86/mpparse.c
 @@ -557,7 +557,7 @@ static inline void __init 
 construct_default_ISA_mptable(int mpc_default_type)
  
  static __init void efi_unmap_mpf(void)
  {
 - if (efi_enabled)
 + if (efi_enabled(EFI_PLATFORM))
   clear_fixmap(FIX_EFI_MPF);
  }
  
 @@ -715,7 +715,7 @@ void __init find_smp_config (void)
  {
   unsigned int address;
  
 - if (efi_enabled) {
 + if (efi_enabled(EFI_PLATFORM)) {
   efi_check_config();
   return;
   }
 diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
 index ff34670..bce708c 100644
 --- a/xen/arch/x86/setup.c
 +++ b/xen/arch/x86/setup.c
 @@ -444,8 +444,8 @@ static void __init parse_video_info(void)
  {
  struct boot_video_info *bvi = bootsym(boot_vid_info);
  
 -/* The EFI loader fills vga_console_info directly. */
 -if ( efi_enabled )
 +/* vga_console_info is filled directly on EFI platform. */
 +if ( efi_enabled(EFI_PLATFORM) )
  return;
  
  if ( (bvi-orig_video_isVGA == 1)  (bvi-orig_video_mode == 3) )
 @@ -695,7 +695,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
  if ( !(mbi-flags  MBI_MODULES) || (mbi-mods_count == 0) )
  panic(dom0 kernel not specified. Check bootloader configuration.);
  
 -if ( efi_enabled )
 +if ( efi_enabled(EFI_PLATFORM) )
  {
  set_pdx_range(xen_phys_start  PAGE_SHIFT,
(xen_phys_start + BOOTSTRAP_MAP_BASE)  PAGE_SHIFT);
 @@ -806,7 +806,7 @@ void 

Re: [Xen-devel] [PATCH v2 13/23] efi: split out efi_get_gop()

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:08PM +0200, Daniel Kiper wrote:
 ..which gets pointer to GOP device. We want to re-use this
 code to support multiboot2 protocol on EFI platforms.
 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
 ---
 v2 - suggestions/fixes:
- improve commit message
  (suggested by Jan Beulich).
 ---
  xen/common/efi/boot.c |   59 
 ++---
  1 file changed, 36 insertions(+), 23 deletions(-)
 
 diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
 index 4614146..6fad230 100644
 --- a/xen/common/efi/boot.c
 +++ b/xen/common/efi/boot.c
 @@ -630,6 +630,41 @@ static void __init efi_console_set_mode(void)
  StdOut-SetMode(StdOut, best);
  }
  
 +static EFI_GRAPHICS_OUTPUT_PROTOCOL __init *efi_get_gop(void)
 +{
 +EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
 +EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
 +EFI_HANDLE *handles;
 +EFI_STATUS status;
 +UINTN info_size, size = 0;
 +static EFI_GUID __initdata gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
 +unsigned int i;
 +
 +status = efi_bs-LocateHandle(ByProtocol, gop_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, gop_guid, NULL, size,
 +  handles);
 +if ( EFI_ERROR(status) )
 +size = 0;
 +for ( i = 0; i  size / sizeof(*handles); ++i )
 +{
 +status = efi_bs-HandleProtocol(handles[i], gop_guid, (void 
 **)gop);
 +if ( EFI_ERROR(status) )
 +continue;
 +status = gop-QueryMode(gop, gop-Mode-Mode, info_size, 
 mode_info);
 +if ( !EFI_ERROR(status) )
 +break;
 +}
 +if ( handles )
 +efi_bs-FreePool(handles);
 +if ( EFI_ERROR(status) )
 +gop = NULL;
 +
 +return gop;
 +}
 +
  static void __init setup_efi_pci(void)
  {
  EFI_STATUS status;
 @@ -736,14 +771,12 @@ void EFIAPI __init noreturn
  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 shim_lock_guid = SHIM_LOCK_PROTOCOL_GUID;
  EFI_LOADED_IMAGE *loaded_image;
  EFI_STATUS status;
  unsigned int i, argc;
  CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
  UINTN map_key, 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;
 @@ -837,27 +870,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
 cols, rows) == EFI_SUCCESS )
  efi_arch_console_init(cols, rows);
  
 -status = efi_bs-LocateHandle(ByProtocol, gop_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, gop_guid, NULL, size,
 -  handles);
 -if ( EFI_ERROR(status) )
 -size = 0;
 -for ( i = 0; i  size / sizeof(*handles); ++i )
 -{
 -status = efi_bs-HandleProtocol(handles[i], gop_guid, (void 
 **)gop);
 -if ( EFI_ERROR(status) )
 -continue;
 -status = gop-QueryMode(gop, gop-Mode-Mode, info_size, 
 mode_info);
 -if ( !EFI_ERROR(status) )
 -break;
 -}
 -if ( handles )
 -efi_bs-FreePool(handles);
 -if ( EFI_ERROR(status) )
 -gop = NULL;
 +gop = efi_get_gop();
  
  /* Get the file system interface. */
  dir_handle = get_parent_handle(loaded_image, file_name);
 -- 
 1.7.10.4
 
 
 ___
 Xen-devel mailing list
 xen-de...@lists.xen.org
 http://lists.xen.org/xen-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [Xen-devel] [PATCH v2 16/23] efi: split out efi_variables()

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:11PM +0200, Daniel Kiper wrote:
 ..which collects variable store parameters. We want to re-use this
 code to support multiboot2 protocol on EFI platforms.
 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
 ---
 v2 - suggestions/fixes:
- improve commit message
  (suggested by Jan Beulich).
 ---
  xen/common/efi/boot.c |   41 -
  1 file changed, 24 insertions(+), 17 deletions(-)
 
 diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
 index fd62125..177697a 100644
 --- a/xen/common/efi/boot.c
 +++ b/xen/common/efi/boot.c
 @@ -837,6 +837,29 @@ static void __init setup_efi_pci(void)
  efi_bs-FreePool(handles);
  }
  
 +static void __init efi_variables(void)
 +{
 +EFI_STATUS status;
 +
 +status = (efi_rs-Hdr.Revision  16) = 2 ?
 + efi_rs-QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE |
 +   EFI_VARIABLE_BOOTSERVICE_ACCESS |
 +   EFI_VARIABLE_RUNTIME_ACCESS,
 +   efi_boot_max_var_store_size,
 +   efi_boot_remain_var_store_size,
 +   efi_boot_max_var_size) :
 + EFI_INCOMPATIBLE_VERSION;
 +if ( EFI_ERROR(status) )
 +{
 +efi_boot_max_var_store_size = 0;
 +efi_boot_remain_var_store_size = 0;
 +efi_boot_max_var_size = status;
 +PrintStr(LWarning: Could not query variable store: );
 +DisplayUint(status, 0);
 +PrintStr(newline);
 +}
 +}
 +
  static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 
 *sz)
  {
 if ( bpp  0 )
 @@ -1078,23 +1101,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
  setup_efi_pci();
  
  /* Get snapshot of variable store parameters. */
 -status = (efi_rs-Hdr.Revision  16) = 2 ?
 - efi_rs-QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE |
 -   EFI_VARIABLE_BOOTSERVICE_ACCESS |
 -   EFI_VARIABLE_RUNTIME_ACCESS,
 -   efi_boot_max_var_store_size,
 -   efi_boot_remain_var_store_size,
 -   efi_boot_max_var_size) :
 - EFI_INCOMPATIBLE_VERSION;
 -if ( EFI_ERROR(status) )
 -{
 -efi_boot_max_var_store_size = 0;
 -efi_boot_remain_var_store_size = 0;
 -efi_boot_max_var_size = status;
 -PrintStr(LWarning: Could not query variable store: );
 -DisplayUint(status, 0);
 -PrintStr(newline);
 -}
 +efi_variables();
  
  efi_arch_memory_setup();
  
 -- 
 1.7.10.4
 
 
 ___
 Xen-devel mailing list
 xen-de...@lists.xen.org
 http://lists.xen.org/xen-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [Xen-devel] [PATCH v2 20/23] x86: add multiboot2 protocol support for EFI platforms

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:15PM +0200, Daniel Kiper wrote:
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com
 ---
 v2 - suggestions/fixes:
- generate multiboot2 header using macros
  (suggested by Jan Beulich),
- switch CPU to x86_32 mode before
  jumping to 32-bit code
  (suggested by Andrew Cooper),
- reduce code changes to increase patch readability
  (suggested by Jan Beulich),
- improve comments
  (suggested by Jan Beulich),
- ignore MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag on EFI platform
  and find on my own multiboot2.mem_lower value,
- stop execution if EFI platform is detected
  in legacy BIOS path.
 ---
  xen/arch/x86/boot/head.S  |  157 
 +++--
  xen/arch/x86/efi/efi-boot.h   |   30 +++
  xen/arch/x86/efi/stub.c   |5 ++
  xen/arch/x86/setup.c  |   10 ++-
  xen/arch/x86/x86_64/asm-offsets.c |2 +
  xen/arch/x86/xen.lds.S|4 +-
  xen/common/efi/boot.c |   12 +++
  xen/include/xen/efi.h |1 +
  8 files changed, 210 insertions(+), 11 deletions(-)
 
 diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
 index 57197db..056047f 100644
 --- a/xen/arch/x86/boot/head.S
 +++ b/xen/arch/x86/boot/head.S
 @@ -89,6 +89,13 @@ multiboot1_header_end:
 0, /* Number of the lines - no preference. */ \
 0  /* Number of bits per pixel - no preference. */
  
 +/* Do not disable EFI boot services. */

s/disable/exit/ ?

Or perhaps:

/* Inhibit GRUB2 from calling ExitBootServices. */

?

 +mb2ht_init MB2_HT(EFI_BS), MB2_HT(OPTIONAL)
 +
 +/* EFI64 entry point. */
 +mb2ht_init MB2_HT(ENTRY_ADDRESS_EFI64), MB2_HT(OPTIONAL), \
 +   sym_phys(__efi64_start)
 +
  /* Multiboot2 header end tag. */
  mb2ht_init MB2_HT(END), MB2_HT(REQUIRED)
  .Lmultiboot2_header_end:
 @@ -100,9 +107,15 @@ multiboot1_header_end:
  gdt_boot_descr:
  .word   6*8-1
  .long   sym_phys(trampoline_gdt)
 +.long   0 /* Needed for 64-bit lgdt */
 +
 +cs32_switch_addr:
 +.long   sym_phys(cs32_switch)
 +.word   BOOT_CS32
  
  .Lbad_cpu_msg: .asciz ERR: Not a 64-bit CPU!
  .Lbad_ldr_msg: .asciz ERR: Not a Multiboot bootloader!
 +.Lbad_mb2_ldr: .asciz ERR: Use latest Multiboot2 compatible bootloader!

Multiboot2+EFI compatible..?
  
  .section .init.text, ax, @progbits
  
 @@ -111,6 +124,9 @@ bad_cpu:
  jmp print_err
  not_multiboot:
  mov $(sym_phys(.Lbad_ldr_msg)),%esi # Error message
 +jmp print_err
 +mb2_too_old:
 +mov $(sym_phys(.Lbad_mb2_ldr)),%esi # Error message
  print_err:
  mov $0xB8000,%edi  # VGA framebuffer
  1:  mov (%esi),%bl
 @@ -130,6 +146,119 @@ print_err:
  .Lhalt: hlt
  jmp .Lhalt
  
 +.code64
 +
 +__efi64_start:
 +cld
 +
 +/* Check for Multiboot2 bootloader. */
 +cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
 +je  efi_multiboot2_proto
 +
 +/* Jump to not_multiboot after switching CPU to x86_32 mode. */
 +lea not_multiboot(%rip),%rdi
 +jmp x86_32_switch
 +
 +efi_multiboot2_proto:
 +/*
 + * Multiboot2 information address is 32-bit,
 + * so, zero higher half of %rbx.
 + */
 +mov %ebx,%ebx
 +
 +/* Skip Multiboot2 information fixed part. */
 +lea MB2_fixed_sizeof(%rbx),%rcx

Don't want to check that the address is aligned properly?

 +
 +0:
 +/* Get EFI SystemTable address from Multiboot2 information. */
 +cmpl$MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%rcx)
 +jne 1f
 +
 +mov MB2_efi64_st(%rcx),%rsi
 +
 +/* Do not go into real mode on EFI platform. */

Add please:

/* And also inhibit clearing of BSS later on. */

 +movb$1,skip_realmode(%rip)
 +jmp 3f
 +
 +1:
 +/* Get EFI ImageHandle address from Multiboot2 information. */
 +cmpl$MULTIBOOT2_TAG_TYPE_EFI64_IH,MB2_tag_type(%rcx)
 +jne 2f
 +
 +mov MB2_efi64_ih(%rcx),%rdi
 +jmp 3f
 +
 +2:
 +/* Is it the end of Multiboot2 information? */
 +cmpl$MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx)
 +je  run_bs
 +
 +3:
 +/* Go to next Multiboot2 information tag. */
 +add MB2_tag_size(%rcx),%ecx
 +add $(MULTIBOOT2_TAG_ALIGN-1),%rcx
 +and $~(MULTIBOOT2_TAG_ALIGN-1),%rcx
 +jmp 0b
 +
 +run_bs:
 +push%rax
 +push%rdi
 +
 +/* Initialize BSS (no nasty surprises!). */
 +lea __bss_start(%rip),%rdi
 +lea __bss_end(%rip),%rcx
 +sub %rdi,%rcx
 +shr $3,%rcx
 +xor %eax,%eax
 +rep stosq
 +
 +pop %rdi
 +
 +/*
 + * IN: %rdi - EFI ImageHandle, 

Re: [Xen-devel] [PATCH v2 10/23] efi: build xen.gz with EFI code

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:05PM +0200, Daniel Kiper wrote:
 Build xen.gz with EFI code. We need this to support multiboot2
 protocol on EFI platforms.
 
 If we wish to load not ELF file using multiboot (v1) or multiboot2 then
 it must contain linear (or flat) representation of code and data.
 Currently, PE file contains many sections which are not linear (one
 after another without any holes) or even do not have representation
 in a file (e.g. BSS). In theory there is a chance that we could build
 proper PE file using current build system. However, it means that
 xen.efi further diverge from xen ELF file (in terms of contents and
 build method). ELF have all needed properties. So, it means that this
 is good starting point for further development. Additionally, I think
 that this is also good starting point for further xen.efi code and
 build optimizations. It looks that there is a chance that finally we
 can generate xen.efi directly from xen ELF using just simple objcopy.
 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com
 ---
 v2 - suggestions/fixes:
- build EFI code only if it is supported in a given build environment
  (suggested by Jan Beulich).
 ---
  xen/arch/x86/Makefile |   13 +
  xen/arch/x86/efi/Makefile |   16 +---
  xen/arch/x86/mm.c |3 ++-
  xen/common/efi/runtime.c  |6 ++
  4 files changed, 22 insertions(+), 16 deletions(-)
 
 diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
 index 5f24951..0335445 100644
 --- a/xen/arch/x86/Makefile
 +++ b/xen/arch/x86/Makefile
 @@ -80,7 +80,7 @@ ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o 
 $(BASEDIR)/arch/x86/efi/built_in
  
  ifeq ($(lto),y)
  # Gather all LTO objects together
 -prelink_lto.o: $(ALL_OBJS)
 +prelink_lto.o: $(ALL_OBJS) efi/relocs-dummy.o
   $(LD_LTO) -r -o $@ $^
  
  prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
 @@ -90,14 +90,14 @@ prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
  prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) 
 prelink_lto.o
   $(LD) $(LDFLAGS) -r -o $@ $^
  
 -prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) 
 prelink-efi_lto.o efi/boot.init.o
 +prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) 
 prelink-efi_lto.o
   $(guard) $(LD) $(LDFLAGS) -r -o $@ $^
  else
 -prelink.o: $(ALL_OBJS)
 +prelink.o: $(ALL_OBJS) efi/relocs-dummy.o
   $(LD) $(LDFLAGS) -r -o $@ $^
  
 -prelink-efi.o: $(ALL_OBJS) efi/boot.init.o efi/runtime.o efi/compat.o
 - $(guard) $(LD) $(LDFLAGS) -r -o $@ $(filter-out %/efi/built_in.o,$^)
 +prelink-efi.o: $(ALL_OBJS)
 + $(guard) $(LD) $(LDFLAGS) -r -o $@ $^
  endif
  
  $(BASEDIR)/common/symbols-dummy.o:
 @@ -146,9 +146,6 @@ $(TARGET).efi: prelink-efi.o efi.lds efi/relocs-dummy.o 
 $(BASEDIR)/common/symbol
   if $(guard) false; then rm -f $@; echo 'EFI support disabled'; fi
   rm -f $(@D)/.$(@F).[0-9]*
  
 -efi/boot.init.o efi/runtime.o efi/compat.o: 
 $(BASEDIR)/arch/x86/efi/built_in.o
 -efi/boot.init.o efi/runtime.o efi/compat.o: ;
 -
  asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c
   $(CC) $(filter-out -flto,$(CFLAGS)) -S -o $@ $
  
 diff --git a/xen/arch/x86/efi/Makefile b/xen/arch/x86/efi/Makefile
 index 1daa7ac..b1e8883 100644
 --- a/xen/arch/x86/efi/Makefile
 +++ b/xen/arch/x86/efi/Makefile
 @@ -1,14 +1,16 @@
  CFLAGS += -fshort-wchar
  
 -obj-y += stub.o
 -
 -create = test -e $(1) || touch -t 19990101 $(1)
 -
  efi := $(filter y,$(x86_64)$(shell rm -f disabled))
  efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c 
 check.c 2disabled  echo y))
  efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi 
 check.o 2disabled  echo y))
 -efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); 
 $(call create,runtime.o)))
 +efi := $(if $(efi),$(shell rm disabled)y)
  
 -extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
 +extra-y += relocs-dummy.o
  
 -stub.o: $(extra-y)
 +ifeq ($(efi),y)
 +obj-y += boot.init.o
 +obj-y += compat.o
 +obj-y += runtime.o
 +else
 +obj-y += stub.o
 +endif

That makefile magic I skipped over, but the C code below looks good, so

Half-Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com


 diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
 index 342414f..cef2eb6 100644
 --- a/xen/arch/x86/mm.c
 +++ b/xen/arch/x86/mm.c
 @@ -344,7 +344,8 @@ void __init arch_init_memory(void)
  
  subarch_init_memory();
  
 -efi_init_memory();
 +if ( efi_enabled(EFI_PLATFORM) )
 +efi_init_memory();
  
  mem_sharing_init();
  
 diff --git a/xen/common/efi/runtime.c b/xen/common/efi/runtime.c
 index aa064e7..3eb21c1 100644
 --- a/xen/common/efi/runtime.c
 +++ b/xen/common/efi/runtime.c
 @@ -167,6 +167,9 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info)
  {
  unsigned int i, n;
  
 +if ( !efi_enabled(EFI_PLATFORM) )
 +return -EOPNOTSUPP;
 +
  switch ( idx )
  {
  

Re: [Xen-devel] [PATCH v2 14/23] efi: split out efi_find_gop_mode()

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:09PM +0200, Daniel Kiper wrote:
 ..which finds suitable GOP mode. We want to re-use this
 code to support multiboot2 protocol on EFI platforms.
 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
 ---
 v2 - suggestions/fixes:
- improve commit message
  (suggested by Jan Beulich).
 ---
  xen/common/efi/boot.c |   94 
 -
  1 file changed, 54 insertions(+), 40 deletions(-)
 
 diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
 index 6fad230..8d16470 100644
 --- a/xen/common/efi/boot.c
 +++ b/xen/common/efi/boot.c
 @@ -665,6 +665,58 @@ static EFI_GRAPHICS_OUTPUT_PROTOCOL __init 
 *efi_get_gop(void)
  return gop;
  }
  
 +static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
 +  UINTN cols, UINTN rows, UINTN depth)
 +{
 +EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
 +EFI_STATUS status;
 +UINTN gop_mode = ~0, info_size, size;
 +unsigned int i;
 +
 +if ( !gop )
 +return gop_mode;
 +
 +for ( i = size = 0; i  gop-Mode-MaxMode; ++i )
 +{
 +unsigned int bpp = 0;
 +
 +status = gop-QueryMode(gop, i, info_size, mode_info);
 +if ( EFI_ERROR(status) )
 +continue;
 +switch ( mode_info-PixelFormat )
 +{
 +case PixelBitMask:
 +bpp = hweight32(mode_info-PixelInformation.RedMask |
 +mode_info-PixelInformation.GreenMask |
 +mode_info-PixelInformation.BlueMask);
 +break;
 +case PixelRedGreenBlueReserved8BitPerColor:
 +case PixelBlueGreenRedReserved8BitPerColor:
 +bpp = 24;
 +break;
 +default:
 +continue;
 +}
 +if ( cols == mode_info-HorizontalResolution 
 + rows == mode_info-VerticalResolution 
 + (!depth || bpp == depth) )
 +{
 +gop_mode = i;
 +break;
 +}
 +if ( !cols  !rows 
 + mode_info-HorizontalResolution *
 + mode_info-VerticalResolution  size )
 +{
 +size = mode_info-HorizontalResolution *
 +   mode_info-VerticalResolution;
 +gop_mode = i;
 +}
 +}
 +
 +return gop_mode;
 +}
 +
  static void __init setup_efi_pci(void)
  {
  EFI_STATUS status;
 @@ -978,46 +1030,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
  
  dir_handle-Close(dir_handle);
  
 -if ( gop  !base_video )
 -{
 -for ( i = size = 0; i  gop-Mode-MaxMode; ++i )
 -{
 -unsigned int bpp = 0;
 -
 -status = gop-QueryMode(gop, i, info_size, mode_info);
 -if ( EFI_ERROR(status) )
 -continue;
 -switch ( mode_info-PixelFormat )
 -{
 -case PixelBitMask:
 -bpp = hweight32(mode_info-PixelInformation.RedMask |
 -mode_info-PixelInformation.GreenMask |
 -mode_info-PixelInformation.BlueMask);
 -break;
 -case PixelRedGreenBlueReserved8BitPerColor:
 -case PixelBlueGreenRedReserved8BitPerColor:
 -bpp = 24;
 -break;
 -default:
 -continue;
 -}
 -if ( cols == mode_info-HorizontalResolution 
 - rows == mode_info-VerticalResolution 
 - (!depth || bpp == depth) )
 -{
 -gop_mode = i;
 -break;
 -}
 -if ( !cols  !rows 
 - mode_info-HorizontalResolution *
 - mode_info-VerticalResolution  size )
 -{
 -size = mode_info-HorizontalResolution *
 -   mode_info-VerticalResolution;
 -gop_mode = i;
 -}
 -}
 -}
 +if ( !base_video )
 +gop_mode = efi_find_gop_mode(gop, cols, rows, depth);
  }
  
  efi_arch_edd();
 -- 
 1.7.10.4
 
 
 ___
 Xen-devel mailing list
 xen-de...@lists.xen.org
 http://lists.xen.org/xen-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [Xen-devel] [PATCH v2 17/23] efi: split out efi_set_gop_mode()

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:12PM +0200, Daniel Kiper wrote:
 ..which sets chosen GOP mode. We want to re-use this
 code to support multiboot2 protocol on EFI platforms.
 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
 ---
 v2 - suggestions/fixes:
- improve commit message
  (suggested by Jan Beulich).
 ---
  xen/common/efi/boot.c |   33 -
  1 file changed, 20 insertions(+), 13 deletions(-)
 
 diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
 index 177697a..04b9c7e 100644
 --- a/xen/common/efi/boot.c
 +++ b/xen/common/efi/boot.c
 @@ -860,6 +860,25 @@ static void __init efi_variables(void)
  }
  }
  
 +static void __init efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN 
 gop_mode)
 +{
 +EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
 +EFI_STATUS status;
 +UINTN info_size;
 +
 +if ( !gop )
 +return;
 +
 +/* Set graphics mode. */
 +if ( gop_mode  gop-Mode-MaxMode  gop_mode != gop-Mode-Mode )
 +gop-SetMode(gop, gop_mode);
 +
 +/* Get graphics and frame buffer info. */
 +status = gop-QueryMode(gop, gop-Mode-Mode, info_size, mode_info);
 +if ( !EFI_ERROR(status) )
 +efi_arch_video_init(gop, info_size, mode_info);
 +}
 +
  static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 
 *sz)
  {
 if ( bpp  0 )
 @@ -887,7 +906,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
  UINTN map_key, info_size, gop_mode = ~0;
  EFI_SHIM_LOCK_PROTOCOL *shim_lock;
  EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
 -EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
  union string section = { NULL }, name;
  bool_t base_video = 0, retry;
  char *option_str;
 @@ -1105,18 +1123,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
  
  efi_arch_memory_setup();
  
 -if ( gop )
 -{
 -
 -/* Set graphics mode. */
 -if ( gop_mode  gop-Mode-MaxMode  gop_mode != gop-Mode-Mode )
 -gop-SetMode(gop, gop_mode);
 -
 -/* Get graphics and frame buffer info. */
 -status = gop-QueryMode(gop, gop-Mode-Mode, info_size, 
 mode_info);
 -if ( !EFI_ERROR(status) )
 -efi_arch_video_init(gop, info_size, mode_info);
 -}
 +efi_set_gop_mode(gop, gop_mode);
  
  info_size = 0;
  efi_bs-GetMemoryMap(info_size, NULL, map_key,
 -- 
 1.7.10.4
 
 
 ___
 Xen-devel mailing list
 xen-de...@lists.xen.org
 http://lists.xen.org/xen-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [Xen-devel] [PATCH v2 19/23] x86/efi: create new early memory allocator

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:14PM +0200, Daniel Kiper wrote:
 There is a problem with place_string() which is used as early memory
 allocator. It gets memory chunks starting from start symbol and
 going down. Sadly this does not work when Xen is loaded using multiboot2
 protocol because start lives on 1 MiB address. So, I tried to use

s/So, I tried to use/With/
 mem_lower address calculated by GRUB2. However, it works only on some

s/GRUB2. However, //

 machines. There are machines in the wild (e.g. Dell PowerEdge R820)
 which uses first ~640 KiB for boot services code or data... :-(((
 
 In case of multiboot2 protocol we need that place_string() only allocate

s/only/to only/
 memory chunk for EFI memory map. However, I think that it should be fixed
 instead of making another function used just in one case. I thought about
 two solutions.

s/I think ...two solutions/There are two solutions:/

 
 1) We could use native EFI allocation functions (e.g. AllocatePool()
or AllocatePages()) to get memory chunk. However, later (somewhere
in __start_xen()) we must copy its contents to safe place or reserve
this in e820 memory map and map it in Xen virtual address space.
In later case we must also care about conflicts with e.g. crash
kernel regions which could be quite difficult.
 
 2) We may allocate memory area statically somewhere in Xen code which
could be used as memory pool for early dynamic allocations. Looks
quite simple. Additionally, it would not depend on EFI at all and
could be used on legacy BIOS platforms if we need it. However, we
must carefully choose size of this pool. We do not want increase
Xen binary size too much and waste too much memory but also we must fit

Aren't we gziping the binary? In which you do not waste that much disk space.

at least memory map on x86 EFI platforms. As I saw on small machine,

s/at least memory map on/on small memory/

s/As I saw on small machine/For example on/

e.g. IBM System x3550 M2 with 8 GiB RAM, memory map may contain more
than 200 entries. Every entry on x86-64 platform is 40 bytes in size.

s/entries. Every entry on .. is/wherein every entry is/

So, it means that we need more than 8 KiB for EFI memory map only.

s/So, it means that we need more than/Brings it up to/

Additionally, if we want to use this memory pool for Xen and modules
command line storage (it would be used when xen.efi is executed as EFI
application) then we should add, I think, about 1 KiB. In this case,

s/,I think, //

to be on safe side, we should assume at least 64 KiB pool for early
memory allocations, which is about 4 times of our earlier calculations.
However, during discussion on Xen-devel Jan Beulich suggested that
just in case we should use 1 MiB memory pool like it was in original
place_string() implementation. So, let's use 1 MiB as it was proposed.

s/If we think that we should not/To not/

If we think that we should not waste unallocated memory in the pool
on running system then we can mark this region as __initdata and move
all required data to dynamically allocated places somewhere in 
 __start_xen().
 
 Now solution #2 is implemented but maybe we should consider #1 one day.

s/Now ../This patch implements #2 solution./

 
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com with the
adjustments mentioned.
 ---
  xen/arch/x86/efi/efi-boot.h |   38 ++
  xen/arch/x86/setup.c|3 +--
  2 files changed, 31 insertions(+), 10 deletions(-)
 
 diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
 index 2dd69f6..3d25c48 100644
 --- a/xen/arch/x86/efi/efi-boot.h
 +++ b/xen/arch/x86/efi/efi-boot.h
 @@ -103,9 +103,36 @@ static void __init relocate_trampoline(unsigned long 
 phys)
  *(u16 *)(*trampoline_ptr + (long)trampoline_ptr) = phys  4;
  }
  
 +#define EBMALLOC_SIZEMB(1)
 +
 +static char __initdata ebmalloc_mem[EBMALLOC_SIZE];
 +static char __initdata *ebmalloc_free = NULL;
 +
 +/* EFI boot allocator. */
 +static void __init *ebmalloc(size_t size)
 +{
 +void *ptr;
 +
 +/*
 + * Init ebmalloc_free on runtime. Static initialization
 + * will not work because it puts virtual address there.

And why is that bad?

 + */
 +if ( ebmalloc_free == NULL )
 +ebmalloc_free = ebmalloc_mem;
 +
 +ptr = ebmalloc_free;
 +
 +ebmalloc_free += size;
 +
 +if ( ebmalloc_free - ebmalloc_mem  sizeof(ebmalloc_mem) )
 +blexit(LOut of static memory\r\n);
 +
 +return ptr;
 +}
 +
  static void __init place_string(u32 *addr, const char *s)
  {
 -static char *__initdata alloc = start;
 +char *alloc = NULL;
  
  if ( s  *s )
  {
 @@ -113,7 +140,7 @@ static void __init place_string(u32 *addr, const char *s)
  const char *old = (char *)(long)*addr;
  size_t len2 = *addr ? strlen(old) + 1 

Re: [Xen-devel] [PATCH v2 21/23] x86/boot: implement early command line parser in C

2015-08-10 Thread Konrad Rzeszutek Wilk
On Mon, Jul 20, 2015 at 04:29:16PM +0200, Daniel Kiper wrote:
 Current early command line parser implementation in assembler
 is very difficult to change to relocatable stuff using segment
 registers. This requires a lot of changes in very weird and
 fragile code. So, reimplement this functionality in C. This
 way code will be relocatable out of the box and much easier
 to maintain.
 
 Suggested-by: Andrew Cooper andrew.coop...@citrix.com
 Signed-off-by: Daniel Kiper daniel.ki...@oracle.com

I did not look at the str* functions that were added in but just
at how the parameters parsing was done. Also at the assembler code and
with that

Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com
.. snip..
 diff --git a/xen/arch/x86/boot/cmdline.c b/xen/arch/x86/boot/cmdline.c
 new file mode 100644
 index 000..5ea50a4
 --- /dev/null
 +++ b/xen/arch/x86/boot/cmdline.c
 @@ -0,0 +1,396 @@
 +/*
 + * Copyright (c) 2015 Oracle Co.


Oracle Corporation.

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 3/3] net: fix ipv6 routing

2015-08-10 Thread Josef Bacik

On 08/09/2015 10:58 AM, Andrei Borzenkov wrote:

В Wed, 5 Aug 2015 14:36:39 -0400
Josef Bacik jba...@fb.com пишет:


Currently we cannot talk to ipv6 addresses outside of our local link area
because we don't setup our routes properly nor do we talk to the router
properly.  Currently net_ipv6_autoconf adds routes for the local link prefix and
ties it to the global link device.  This isn't helpful at all, we completely
drop the router part of the router advertisement.  So instead create a default
route flag in routes and create a new route with the local link prefix and the
router source address.



Note that RA does not always mean default route. You need to check
router lifetime to decide whether to use it as default route.


I've been reading the spec a lot recently and I couldn't figure out a 
way to differentiate between a default route and just another route. 
From my reading if we get multipe RA's we're supposed to just round 
robin through them until we get the one that works, obviously taking 
into account when the router lifetime expires and such.  We don't take 
into account the lifetime at all except to see if it is set to 0, 
otherwise we never expire anything.  We should probably build this out 
in the future, but for now just picking whichever router comes first as 
the default route will work most of the time.





The second part of this problem is that the routing code thinks in ipv4 terms,
so it expects to find a route to the address we're looking for in our routing
table.  If we find a gateway then we just look for which interface matches the
network for the gateway.  This doesn't work for ipv6 since the router gives us
its local link address, so the gateway will find the local link interface,
instead of the global interface.  So to deal with this do a few things



I am afraid it cannot be solved on routing table level. We need to bite
the bullet and add notion of interface zone and associate each link
local IPv6 address with interface it comes from (or sent to). This
automatically solves also the problem in your other patch as well as
this one by eliminating need to (attempt to) route link local in the
first place - it is simply sent to interface it is associated with.

It also means we probably need to support IPv6%scope notation for
addresses.


I'll try and work something out that is better than this patch.




1) Create a new default route flag for any router advertisements we get when
doing the ipv6 autoconf stuff.  Then we create a normal gateway route with the
default route flag set.

2) When looking for routes keep track of any default routes we find, and if we
don't find an exact route that matches we use the default route, which will set
the gateway to the router, and then we will find the local link interface that
matches this router.

3) Translate the local link interface to the global link interface.  We build
the ip packets based on the address on the interface, and this needs to have the
global address, not the local one.  So loop through our interfaces until we find
a global address with the same hwaddress as the local link interface and use
that instead.  This way we get the right addresses on our IP packets.



If I read RFC6724 correctly, we actually must prefer link-local
source address when speaking with link-local destination.


Right if we're talking to a link-local destination, but when talking to 
a global link destination the format is


src-ip: global address for the interface
dst-ip: global address for destination
src-mac: our mac
dst-mac: the mac of the default route

Which is why I did that weird translation.




With this patch I can now do net_ipv6_autoconf and immediately talk to ipv6
addresses outside of my local network.  Thanks,

Signed-off-by: Josef Bacik jba...@fb.com
---
  grub-core/net/bootp.c  |  2 +-
  grub-core/net/drivers/ieee1275/ofnet.c |  2 +-
  grub-core/net/icmp6.c  | 50 ++
  grub-core/net/net.c| 76 +-
  include/grub/net.h | 28 -
  5 files changed, 99 insertions(+), 59 deletions(-)


...

diff --git a/grub-core/net/icmp6.c b/grub-core/net/icmp6.c
index 7953e68..fad04a9 100644
--- a/grub-core/net/icmp6.c
+++ b/grub-core/net/icmp6.c
@@ -373,7 +373,10 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb,
if (ohdr-type == OPTION_PREFIX  ohdr-len == 4)
  {
struct prefix_option *opt = (struct prefix_option *) ptr;
+   struct grub_net_route *route;
struct grub_net_slaac_mac_list *slaac;
+
+   grub_net_network_level_netaddress_t netaddr;
if (!(opt-flags  FLAG_SLAAC)
|| (grub_be_to_cpu64 (opt-prefix[0])  48) == 0xfe80
|| (grub_be_to_cpu32 (opt-preferred_lifetime)
@@ -391,18 +394,12 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb,
for (slaac = 

Re: [PATCH 3/3] net: fix ipv6 routing

2015-08-10 Thread Andrei Borzenkov
On Mon, Aug 10, 2015 at 5:00 PM, Josef Bacik jba...@fb.com wrote:
 On 08/09/2015 10:58 AM, Andrei Borzenkov wrote:

 В Wed, 5 Aug 2015 14:36:39 -0400
 Josef Bacik jba...@fb.com пишет:

 Currently we cannot talk to ipv6 addresses outside of our local link area
 because we don't setup our routes properly nor do we talk to the router
 properly.  Currently net_ipv6_autoconf adds routes for the local link
 prefix and
 ties it to the global link device.  This isn't helpful at all, we
 completely
 drop the router part of the router advertisement.  So instead create a
 default
 route flag in routes and create a new route with the local link prefix
 and the
 router source address.


 Note that RA does not always mean default route. You need to check
 router lifetime to decide whether to use it as default route.


 I've been reading the spec a lot recently and I couldn't figure out a way to
 differentiate between a default route and just another route.

Probably I was not clear. You should not use RA to add *any* route
unless it claims to offer one. Your patch did not check for it.
Default was wrong here, I did not mean to distinguish between
different types of routes (actually, I am not sure if SLAAC can add
default route in usual sense).



 Eesh I just ripped that out didn't I?  Sorry about that, I'll rework this
 again.  I think I'll do like you said above, just kind of create an
 interface with different scopes and that way if you use both slaac and dhcp
 and get the same address we don't end up with two different interfaces.  And
 then I'll come up with something to tie the routers to the interfaces and
 rework the route stuff so it is a bit cleaner.  This will probably be
 towards the end of the week, I've found some weird timeout problem in the
 TCP stack I'm trying to track down, once I've figured that out I'll rework
 this patch.  Thanks,


Thank you for working on it!

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel