From patchwork Mon Aug 3 00:10:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 502998 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id AC0F61402D7 for ; Mon, 3 Aug 2015 14:39:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=CncX0jVY; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 514D44BF4B; Mon, 3 Aug 2015 06:39:25 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kLXVhKuGga8H; Mon, 3 Aug 2015 06:39:25 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 60CF5A7436; Mon, 3 Aug 2015 06:39:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 232454BF6F for ; Mon, 3 Aug 2015 02:10:31 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WwDL9uDRs9mf for ; Mon, 3 Aug 2015 02:10:31 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-io0-f179.google.com (mail-io0-f179.google.com [209.85.223.179]) by theia.denx.de (Postfix) with ESMTPS id BA0884BF6E for ; Mon, 3 Aug 2015 02:10:26 +0200 (CEST) Received: by ioii16 with SMTP id i16so130022391ioi.0 for ; Sun, 02 Aug 2015 17:10:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=8Yt7ESnnvwOu82WsMuOY3hw8axM8iCwY4SPAG1CXkk8=; b=CncX0jVYbi7zBxURXK3j18LXCiKHK5Rg2F+K1ffgBewAkBEpdWDpZitEvNPLXFPM14 UZLl5hCDKz9XWVxQ2ECc3SnZx/lGFoK0LJjrGxm0grv3A9bXqz6DMYY99zBYmWwqDUyF VukcfIWUucSoJNg12kVmHFRrrRlCZbVa+opTaZiVxnNTfnjK2u1+nosCIRiQPskfsKqU S+X8gn+aXPtfLDuz72L680flwadUDiAfRB1+7Ky/y+Zb1ITvH3EmssnEqL7k5zUzketE u8lnKsPhpavDz91VGNtthSdue2kt68A5Pp3SxjfiX4O3vgV0dQ9tL/OWsldoRero9cHd 7ccA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=8Yt7ESnnvwOu82WsMuOY3hw8axM8iCwY4SPAG1CXkk8=; b=WC7IgheXbR1lgfWohQpX4kaZhhxvetjJ82iOkrQsb0mZ2MYaY1VHo/Wlm8DmCB3NTP ks8+Cy0fJk3EiBBZ4o9HQJ2S01mn76UmczfR6cO95imfHMtHdRTrwEPq2raKZkEk7sgA 8r7wo7EjxmuuppzxGfgPezuK2b8x8G5ySSvZldFgcG4ZiO5qbSlAiHNS74OU4X687xF1 w6Ny/YDv1su6IJg+5EWx9HvQyCCp8pA5D9tIVPOItWKI2now7UkP2R9OXCyPoiFdfiNC 8D9EcQQF9kqCNZd0WtN4rLHFoG0AKE/StC3p83VzgRf6cN9tChrrtH2OgtKgENJQZNW2 nc7g== X-Gm-Message-State: ALoCoQkVlkhOaazuAUm65W4d04cPHds6HfAxPLjS550dkjMm92nq93+YBlFlwvZ+ILCXEr2mYaMK X-Received: by 10.107.134.22 with SMTP id i22mr17886266iod.111.1438560625299; Sun, 02 Aug 2015 17:10:25 -0700 (PDT) Received: from kaki.bld.corp.google.com ([2620:0:1005:1100:2963:d53d:d81a:9c37]) by smtp.gmail.com with ESMTPSA id n6sm4500537igv.17.2015.08.02.17.10.23 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Aug 2015 17:10:24 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id D204F222133; Sun, 2 Aug 2015 18:10:22 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Sun, 2 Aug 2015 18:10:10 -0600 Message-Id: <1438560612-29910-4-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.5.0.rc2.392.g76e840b In-Reply-To: <1438560612-29910-1-git-send-email-sjg@chromium.org> References: <1438560612-29910-1-git-send-email-sjg@chromium.org> X-Mailman-Approved-At: Mon, 03 Aug 2015 06:39:15 +0200 Cc: Tom Rini , Sonic Zhang , Stephen Warren , Gabe Black , "angelo@sysam.it" , Joe Hershberger , Eric Nelson , Alexey Brodkin , Masahiro Yamada , York Sun Subject: [U-Boot] [PATCH 3/5] Allow arch-specific setting of global_data in board_init_f_mem() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 Reviewed-by: York Sun --- 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);