public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: York Sun <yorksun@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/5] Allow arch-specific setting of global_data in board_init_f_mem()
Date: Mon, 3 Aug 2015 08:58:20 -0700	[thread overview]
Message-ID: <55BF8F9C.10704@freescale.com> (raw)
In-Reply-To: <1438560612-29910-4-git-send-email-sjg@chromium.org>



On 08/02/2015 05:10 PM, Simon Glass wrote:
> At present we have a simple assignment to gd. With some archs this is
> implemented as a register or through some other means; a simple assignment
> does not suit in all cases.
> 
> Change this to a function and add documentation to describe how this all
> works.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
>  common/board_f.c | 14 +++++++++++---
>  include/common.h | 40 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 51 insertions(+), 3 deletions(-)
> 
> diff --git a/common/board_f.c b/common/board_f.c
> index a947770..3d1f305 100644
> --- a/common/board_f.c
> +++ b/common/board_f.c
> @@ -1024,15 +1024,23 @@ void board_init_f_r(void)
>  #endif /* CONFIG_X86 */
>  
>  #ifndef CONFIG_X86
> -ulong board_init_f_mem(ulong top)
> +__weak void arch_setup_gdt(struct global_data *gd_ptr)
>  {
> +	gd = gd_ptr;
> +}
> +
> +ulong board_init_f_mem(ulong top, ulong reserve_size)
> +{
> +	struct global_data *gd_ptr;
> +
>  	/* Leave space for the stack we are running with now */
>  	top -= 0x40;
>  
>  	top -= sizeof(struct global_data);
>  	top = ALIGN(top, 16);
> -	gd = (struct global_data *)top;
> -	memset((void *)gd, '\0', sizeof(*gd));
> +	gd_ptr = (struct global_data *)top;
> +	memset(gd_ptr, '\0', sizeof(*gd));
> +	arch_setup_gdt(gd_ptr);
>  
>  #ifdef CONFIG_SYS_MALLOC_F_LEN
>  	top -= CONFIG_SYS_MALLOC_F_LEN;
> diff --git a/include/common.h b/include/common.h
> index fcc9ae7..029eb1f 100644
> --- a/include/common.h
> +++ b/include/common.h
> @@ -217,6 +217,46 @@ extern char console_buffer[];
>  /* arch/$(ARCH)/lib/board.c */
>  void board_init_f(ulong);
>  void board_init_r(gd_t *, ulong) __attribute__ ((noreturn));
> +
> +/**
> + * board_init_f_mem() - Allocate global data and set stack position
> + *
> + * This function is called by each architecture very early in the start-up
> + * code to set up the environment for board_init_f(). It allocates space for
> + * global_data (see include/asm-generic/global_data.h) and places the stack
> + * below this.
> + *
> + * This function requires a stack[1] Normally this is at @top. The function
> + * starts allocating space from 64 bytes below @top. First it creates space
> + * for global_data. then it calls arch_setup_gd() which sets gd to point to
> + * the global_data space and can reserve additional bytes of space if
> + * required). Finally it allocates early malloc() memory
> + * (CONFIG_SYS_MALLOC_F_LEN). The new top of the stack is just below this,
> + * and it returned by this function.
> + *
> + * [1] Strictly speaking it would be possible to implement this function
> + * in C on many archs such that it does not require a stack. However this
> + * does not seem hugely important as only 64 byte are wasted.
> + *
> + * @top:	Top of available memory, also normally the top of the stack
> + * @return:	New stack location
> + */
> +ulong board_init_f_mem(ulong top, ulong reserve_size);
> +
> +/**
> + * arch_setup_gdt() - Set up the global_data pointer
> + *
> + * This pointer is special in some architectures and cannot easily be assigned
> + * to. For example on x86 it is implemented by adding a specific record to its
> + * Global Descriptor Table! So we we provide a function to carry out this task.
> + * For most architectures this can simply be:
> + *
> + *    gd = gd_ptr;
> + *
> + * @gd_ptr:	Pointer to global data
> + */
> +void arch_setup_gdt(gd_t *gd_ptr);
> +
>  int checkboard(void);
>  int show_board_info(void);
>  int checkflash(void);
> 

This looks good to me.
Reviewed-by: York Sun <yorksun@freescale.com>

York

  reply	other threads:[~2015-08-03 15:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-03  0:10 [U-Boot] [PATCH 0/5] x86: Move x86 to use board_init_f_mem() instead of assembler Simon Glass
2015-08-03  0:10 ` [U-Boot] [PATCH 1/5] x86: Remove init_gd() function Simon Glass
2015-08-06  7:15   ` Bin Meng
2015-08-03  0:10 ` [U-Boot] [PATCH 2/5] Align global_data to a 16-byte boundary Simon Glass
2015-08-06  7:15   ` Bin Meng
2015-08-03  0:10 ` [U-Boot] [PATCH 3/5] Allow arch-specific setting of global_data in board_init_f_mem() Simon Glass
2015-08-03 15:58   ` York Sun [this message]
2015-08-06  7:15   ` Bin Meng
2015-08-07 19:09     ` Simon Glass
2015-08-03  0:10 ` [U-Boot] [PATCH 4/5] x86: Move the GDT into global_data Simon Glass
2015-08-06  7:15   ` Bin Meng
2015-08-03  0:10 ` [U-Boot] [PATCH 5/5] x86: Switch to using generic global_data setup Simon Glass
2015-08-06  7:16   ` Bin Meng
2015-08-10 18:51     ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55BF8F9C.10704@freescale.com \
    --to=yorksun@freescale.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox