RE: [PATCH 7/8] x86: enable 64-bit kernel boot from 64-bit U-Boot

2020-04-28 Thread Park, Aiden
Hi Simon,

> -Original Message-
> From: Simon Glass 
> Sent: Sunday, April 26, 2020 1:16 PM
> To: Park, Aiden 
> Cc: Bin Meng ; U-Boot Mailing List  b...@lists.denx.de>
> Subject: Re: [PATCH 7/8] x86: enable 64-bit kernel boot from 64-bit U-Boot
> 
> Hi Aiden,
> 
> On Tue, 21 Apr 2020 at 18:45,  wrote:
> >
> > From: Aiden Park 
> >
> > Signed-off-by: Aiden Park 
> > ---
> >  arch/x86/cpu/x86_64/Makefile |  2 +-
> >  arch/x86/cpu/x86_64/call64.S | 21 +
> >  arch/x86/cpu/x86_64/cpu.c| 10 ++
> >  arch/x86/include/asm/bootparam.h | 10 +-
> >  arch/x86/include/asm/zimage.h|  2 +-
> >  arch/x86/lib/bootm.c | 10 +++---
> >  arch/x86/lib/zimage.c| 24 
> >  7 files changed, 65 insertions(+), 14 deletions(-)  create mode
> > 100644 arch/x86/cpu/x86_64/call64.S
> >
> > diff --git a/arch/x86/cpu/x86_64/Makefile
> > b/arch/x86/cpu/x86_64/Makefile index 400f0ffe39..951e503a1f 100644
> > --- a/arch/x86/cpu/x86_64/Makefile
> > +++ b/arch/x86/cpu/x86_64/Makefile
> > @@ -3,4 +3,4 @@
> >  # Written by Simon Glass   #
> >
> > -obj-y += cpu.o interrupts.o setjmp.o
> > +obj-y += cpu.o interrupts.o setjmp.o call64.o
> > diff --git a/arch/x86/cpu/x86_64/call64.S
> > b/arch/x86/cpu/x86_64/call64.S new file mode 100644 index
> > 00..e2cfe15080
> > --- /dev/null
> > +++ b/arch/x86/cpu/x86_64/call64.S
> > @@ -0,0 +1,21 @@
> > +/* SPDX-License-Identifier: GPL-2.0+ */
> > +/*
> > + * Copyright (C) 2020 Intel Corporation   */
> > +
> > +.code64
> > +.globl cpu_call64
> > +cpu_call64:
> > +   /*
> > +* cpu_call64(ulong pgtable, ulong setup_base, ulong target)
> > +*
> > +* rdi - pgtable (unused - already in 64-bit with paging)
> > +* rsi - setup_base
> > +* rdx - target
> > +*
> > +*/
> > +   cli
> > +   mov %rdx, %rcx
> > +   mov %rsi, %rdx
> > +   call*%rcx
> > +   ret
> > diff --git a/arch/x86/cpu/x86_64/cpu.c b/arch/x86/cpu/x86_64/cpu.c
> > index 90925e46ea..0730c43f1c 100644
> > --- a/arch/x86/cpu/x86_64/cpu.c
> > +++ b/arch/x86/cpu/x86_64/cpu.c
> > @@ -7,6 +7,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >
> >  /*
> >   * Global declaration of gd.
> > @@ -67,3 +68,12 @@ int x86_cpu_reinit_f(void)  {
> > return 0;
> >  }
> > +
> > +int cpu_jump_to_64bit(ulong setup_base, ulong load_address) {
> > +   ulong target = load_address + 0x200;
> > +
> > +   cpu_call64(0, setup_base, target);
> > +
> > +   return -EFAULT;
> > +}
> > diff --git a/arch/x86/include/asm/bootparam.h
> > b/arch/x86/include/asm/bootparam.h
> > index d961dddc9e..73c94a33ec 100644
> > --- a/arch/x86/include/asm/bootparam.h
> > +++ b/arch/x86/include/asm/bootparam.h
> > @@ -59,7 +59,15 @@ struct setup_header {
> > __u32   initrd_addr_max;
> > __u32   kernel_alignment;
> > __u8relocatable_kernel;
> > -   __u8_pad2[3];
> > +   __u8min_alignment;
> > +   __u16   xloadflags;
> > +#define XLF_KERNEL_64  BIT(0)
> > +#define XLF_CAN_BE_LOADED_ABOVE_4G BIT(1)
> > +#define XLF_EFI_HANDOVER_32BIT(2)
> > +#define XLF_EFI_HANDOVER_64BIT(3)
> > +#define XLF_EFI_KEXEC  BIT(4)
> > +#define XLF_5LEVEL BIT(5)
> > +#define XLF_5LEVEL_ENABLED BIT(6)
> > __u32   cmdline_size;
> > __u32   hardware_subarch;
> > __u64   hardware_subarch_data;
> > diff --git a/arch/x86/include/asm/zimage.h
> > b/arch/x86/include/asm/zimage.h index 80e128ccf3..cadeb04168 100644
> > --- a/arch/x86/include/asm/zimage.h
> > +++ b/arch/x86/include/asm/zimage.h
> > @@ -31,7 +31,7 @@
> >  #define ZIMAGE_LOAD_ADDR   0x1
> >
> >  struct boot_params *load_zimage(char *image, unsigned long kernel_size,
> > -   ulong *load_addressp);
> > +   ulong *load_addressp, bool
> > + *image_64bit);
> 
> Please put a 'p' on the end, so image_64bitp, since it a return value.
Thanks. I will do that.

> 
> >  int setup_zimage(struct boot_params *setup_base, char *cmd_line, int
> auto_boot,
> >  unsigned long initrd_addr, unsigned long
> >

Re: [PATCH 7/8] x86: enable 64-bit kernel boot from 64-bit U-Boot

2020-04-26 Thread Simon Glass
Hi Aiden,

On Tue, 21 Apr 2020 at 18:45,  wrote:
>
> From: Aiden Park 
>
> Signed-off-by: Aiden Park 
> ---
>  arch/x86/cpu/x86_64/Makefile |  2 +-
>  arch/x86/cpu/x86_64/call64.S | 21 +
>  arch/x86/cpu/x86_64/cpu.c| 10 ++
>  arch/x86/include/asm/bootparam.h | 10 +-
>  arch/x86/include/asm/zimage.h|  2 +-
>  arch/x86/lib/bootm.c | 10 +++---
>  arch/x86/lib/zimage.c| 24 
>  7 files changed, 65 insertions(+), 14 deletions(-)
>  create mode 100644 arch/x86/cpu/x86_64/call64.S
>
> diff --git a/arch/x86/cpu/x86_64/Makefile b/arch/x86/cpu/x86_64/Makefile
> index 400f0ffe39..951e503a1f 100644
> --- a/arch/x86/cpu/x86_64/Makefile
> +++ b/arch/x86/cpu/x86_64/Makefile
> @@ -3,4 +3,4 @@
>  # Written by Simon Glass 
>  #
>
> -obj-y += cpu.o interrupts.o setjmp.o
> +obj-y += cpu.o interrupts.o setjmp.o call64.o
> diff --git a/arch/x86/cpu/x86_64/call64.S b/arch/x86/cpu/x86_64/call64.S
> new file mode 100644
> index 00..e2cfe15080
> --- /dev/null
> +++ b/arch/x86/cpu/x86_64/call64.S
> @@ -0,0 +1,21 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Copyright (C) 2020 Intel Corporation 
> + */
> +
> +.code64
> +.globl cpu_call64
> +cpu_call64:
> +   /*
> +* cpu_call64(ulong pgtable, ulong setup_base, ulong target)
> +*
> +* rdi - pgtable (unused - already in 64-bit with paging)
> +* rsi - setup_base
> +* rdx - target
> +*
> +*/
> +   cli
> +   mov %rdx, %rcx
> +   mov %rsi, %rdx
> +   call*%rcx
> +   ret
> diff --git a/arch/x86/cpu/x86_64/cpu.c b/arch/x86/cpu/x86_64/cpu.c
> index 90925e46ea..0730c43f1c 100644
> --- a/arch/x86/cpu/x86_64/cpu.c
> +++ b/arch/x86/cpu/x86_64/cpu.c
> @@ -7,6 +7,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  /*
>   * Global declaration of gd.
> @@ -67,3 +68,12 @@ int x86_cpu_reinit_f(void)
>  {
> return 0;
>  }
> +
> +int cpu_jump_to_64bit(ulong setup_base, ulong load_address)
> +{
> +   ulong target = load_address + 0x200;
> +
> +   cpu_call64(0, setup_base, target);
> +
> +   return -EFAULT;
> +}
> diff --git a/arch/x86/include/asm/bootparam.h 
> b/arch/x86/include/asm/bootparam.h
> index d961dddc9e..73c94a33ec 100644
> --- a/arch/x86/include/asm/bootparam.h
> +++ b/arch/x86/include/asm/bootparam.h
> @@ -59,7 +59,15 @@ struct setup_header {
> __u32   initrd_addr_max;
> __u32   kernel_alignment;
> __u8relocatable_kernel;
> -   __u8_pad2[3];
> +   __u8min_alignment;
> +   __u16   xloadflags;
> +#define XLF_KERNEL_64  BIT(0)
> +#define XLF_CAN_BE_LOADED_ABOVE_4G BIT(1)
> +#define XLF_EFI_HANDOVER_32BIT(2)
> +#define XLF_EFI_HANDOVER_64BIT(3)
> +#define XLF_EFI_KEXEC  BIT(4)
> +#define XLF_5LEVEL BIT(5)
> +#define XLF_5LEVEL_ENABLED BIT(6)
> __u32   cmdline_size;
> __u32   hardware_subarch;
> __u64   hardware_subarch_data;
> diff --git a/arch/x86/include/asm/zimage.h b/arch/x86/include/asm/zimage.h
> index 80e128ccf3..cadeb04168 100644
> --- a/arch/x86/include/asm/zimage.h
> +++ b/arch/x86/include/asm/zimage.h
> @@ -31,7 +31,7 @@
>  #define ZIMAGE_LOAD_ADDR   0x1
>
>  struct boot_params *load_zimage(char *image, unsigned long kernel_size,
> -   ulong *load_addressp);
> +   ulong *load_addressp, bool *image_64bit);

Please put a 'p' on the end, so image_64bitp, since it a return value.

>  int setup_zimage(struct boot_params *setup_base, char *cmd_line, int 
> auto_boot,
>  unsigned long initrd_addr, unsigned long initrd_size);
>  void setup_video(struct screen_info *screen_info);
> diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c
> index 07d8f1f279..ebed9e4605 100644
> --- a/arch/x86/lib/bootm.c
> +++ b/arch/x86/lib/bootm.c
> @@ -74,6 +74,7 @@ static int boot_prep_linux(bootm_headers_t *images)
> void *data = NULL;
> size_t len;
> int ret;
> +   bool image_64bit;
>
>  #ifdef CONFIG_OF_LIBFDT
> if (images->ft_len) {
> @@ -116,7 +117,8 @@ static int boot_prep_linux(bootm_headers_t *images)
> ulong load_address;
> char *base_ptr;
>
> -   base_ptr = (char *)load_zimage(data, len, &load_address);
> +   base_ptr = (char *)load_zimage(data, len, &load_address,
> +  &image_64bit);
> if (!base_ptr) {
> puts("## Kernel loading failed ...\n");
> goto error;
> @@ -124,6 +126,10 @@ static int boot_prep_linux(bootm_headers_t *images)
> images->os.load = load_address;
> cmd_line_dest = base_ptr + COMMAND_LINE_OFFSET;
> images->ep = (ulong)base_ptr;
> +#if CONFIG_IS_ENABLED(X86_64