From patchwork Wed Nov 5 12:08:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francois Retief X-Patchwork-Id: 406971 X-Patchwork-Delegate: daniel@gaisler.com 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 7BA5C14003E for ; Wed, 5 Nov 2014 23:12:15 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A988B4BDFA; Wed, 5 Nov 2014 13:11:34 +0100 (CET) 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 3tyrhA4AqNne; Wed, 5 Nov 2014 13:11:34 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B85FE4BE29; Wed, 5 Nov 2014 13:11:19 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 50A1C4BDDC for ; Wed, 5 Nov 2014 13:11:01 +0100 (CET) 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 Slpp-rR0hRq3 for ; Wed, 5 Nov 2014 13:11:01 +0100 (CET) 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 SPASTBMXS01.sunspace.co.za (unknown [196.44.39.35]) by theia.denx.de (Postfix) with ESMTPS id 649C84BDEA for ; Wed, 5 Nov 2014 13:10:52 +0100 (CET) Received: from SPASTBMXS01.sunspace.co.za (10.24.0.111) by SPASTBMXS01.sunspace.co.za (10.24.0.111) with Microsoft SMTP Server (TLS) id 15.0.847.32; Wed, 5 Nov 2014 14:10:09 +0200 Received: from serengeti.sunspace.co.za (10.24.5.54) by SPASTBMXS01.sunspace.co.za (10.24.0.111) with Microsoft SMTP Server id 15.0.847.32 via Frontend Transport; Wed, 5 Nov 2014 14:10:09 +0200 From: Francois Retief To: Date: Wed, 5 Nov 2014 14:08:23 +0200 Message-ID: <1415189303-6042-11-git-send-email-fgretief@spaceteq.co.za> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1415189303-6042-1-git-send-email-fgretief@spaceteq.co.za> References: <1415189303-6042-1-git-send-email-fgretief@spaceteq.co.za> MIME-Version: 1.0 Received-SPF: None (SPASTBMXS01.sunspace.co.za: fgretief@spaceteq.co.za does not designate permitted sender hosts) Subject: [U-Boot] [PATCH v2 10/10] sparc: Cleanup of LEON3 CPU initialisation code X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This changeset do some cleanup of the LEON3 CPU initialization code. We move the interrupt initialization into a separate function for beter modularity. In the memory controller initialization function, we put amount of code in the function. Thus your board only need to define the variables needed for your device and no more. Create the cpu_panic function so that a back-trace can show us that we ended up in a panic situation. Previously we could not identify where we were inside the cpu_init_f() function during a panic. Signed-off-by: Francois Retief --- Changes in v2: - Add patch to cleanup LEON3 init code a bit - The gr712rc-board patches has been split into a separate series arch/sparc/cpu/leon3/cpu_init.c | 109 +++++++++++++++++++++----------------- arch/sparc/cpu/leon3/interrupts.c | 4 +- 2 files changed, 64 insertions(+), 49 deletions(-) -- 1.9.3 diff --git a/arch/sparc/cpu/leon3/cpu_init.c b/arch/sparc/cpu/leon3/cpu_init.c index b0c7088..462b4a6 100644 --- a/arch/sparc/cpu/leon3/cpu_init.c +++ b/arch/sparc/cpu/leon3/cpu_init.c @@ -19,23 +19,12 @@ DECLARE_GLOBAL_DATA_PTR; -/* reset CPU (jump to 0, without reset) */ -void start(void); - /* find & initialize the memory controller */ -int init_memory_ctrl(void); +static int init_memory_ctrl(void); +static int init_intr_ctrl(void); -ambapp_dev_irqmp *irqmp = NULL; -ambapp_dev_mctrl memctrl; -ambapp_dev_gptimer *gptimer = NULL; -unsigned int gptimer_irq = 0; int leon3_snooping_avail = 0; /* used by arch/sparc/cpu/leon3/usb_uhci.c */ -struct { - gd_t gd_area; - bd_t bd; -} global_data; - /* If CACHE snooping is available in hardware the result will be set * to 0x800000, otherwise 0. */ @@ -46,6 +35,12 @@ static unsigned int snoop_detect(void) return result & 0x00800000; } +void cpu_panic(void) +{ + /* TODO: add some logic to print a warning on uart */ + while (1) ; +} + /* * Breath some life into the CPU... * @@ -60,9 +55,6 @@ static unsigned int snoop_detect(void) void cpu_init_f(void) { - /* these varaiable must not be initialized */ - ambapp_dev_irqmp *irqmp; - ambapp_apbdev apbdev; register unsigned int apbmst; /* find AMBA APB Master */ @@ -73,33 +65,18 @@ void cpu_init_f(void) * no AHB/APB bridge, something is wrong * ==> jump to start (or hang) */ - while (1) ; + cpu_panic(); } + /* Init memory controller */ - if (init_memory_ctrl()) { - while (1) ; - } + if (init_memory_ctrl()) + cpu_panic(); /**************************************************** * From here we can use the main memory and the stack. */ - - /* Find AMBA APB IRQMP Controller */ - if (ambapp_apb_first(VENDOR_GAISLER, GAISLER_IRQMP, &apbdev) != 1) { - /* no IRQ controller, something is wrong - * ==> jump to start (or hang) - */ - while (1) ; - } - irqmp = (ambapp_dev_irqmp *) apbdev.address; - - /* initialize the IRQMP */ - irqmp->ilevel = 0xf; /* all IRQ off */ - irqmp->iforce = 0; - irqmp->ipend = 0; - irqmp->iclear = 0xfffe; /* clear all old pending interrupts */ - irqmp->cpu_mask[0] = 0; /* mask all IRQs on CPU 0 */ - irqmp->cpu_force[0] = 0; /* no force IRQ on CPU 0 */ + if (init_intr_ctrl()) + cpu_panic(); /* cache */ leon3_snooping_avail = snoop_detect(); @@ -136,7 +113,6 @@ int cpu_init_r(void) return 1; } gptimer = (ambapp_dev_gptimer *) apbdev.address; - gptimer_irq = apbdev.irq; /* initialize prescaler common to all timers to 1MHz */ gptimer->scalar = gptimer->scalar_reload = @@ -148,19 +124,19 @@ int cpu_init_r(void) #endif /* find & setup memory controller */ -int init_memory_ctrl() +static int init_memory_ctrl() { - register ambapp_dev_mctrl *mctrl; - register ambapp_dev_sdctrl *sdctrl; - register ambapp_dev_ddrspa *ddrspa; - register ambapp_dev_ddr2spa *ddr2spa; register ahbctrl_pp_dev *ahb; register unsigned int base; register int not_found_mctrl = -1; +#if defined(CONFIG_SYS_GRLIB_MEMCFG1) && \ + defined(CONFIG_SYS_GRLIB_MEMCFG2) && \ + defined(CONFIG_SYS_GRLIB_MEMCFG3) /* find ESA Memory controller */ base = ambapp_apb_next_nomem(VENDOR_ESA, ESA_MCTRL, 0); if (base) { + register ambapp_dev_mctrl *mctrl = (ambapp_dev_mctrl *) base; mctrl = (ambapp_dev_mctrl *) base; /* config MCTRL memory controller */ @@ -169,11 +145,15 @@ int init_memory_ctrl() mctrl->mcfg3 = CONFIG_SYS_GRLIB_MEMCFG3; not_found_mctrl = 0; } +#endif +#if defined(CONFIG_SYS_GRLIB_FT_MEMCFG1) && \ + defined(CONFIG_SYS_GRLIB_FT_MEMCFG2) && \ + defined(CONFIG_SYS_GRLIB_FT_MEMCFG3) /* find Gaisler Fault Tolerant Memory controller */ base = ambapp_apb_next_nomem(VENDOR_GAISLER, GAISLER_FTMCTRL, 0); if (base) { - mctrl = (ambapp_dev_mctrl *) base; + register ambapp_dev_mctrl *mctrl = (ambapp_dev_mctrl *) base; /* config MCTRL memory controller */ mctrl->mcfg1 = CONFIG_SYS_GRLIB_FT_MEMCFG1 | (mctrl->mcfg1 & 0x300); @@ -181,40 +161,73 @@ int init_memory_ctrl() mctrl->mcfg3 = CONFIG_SYS_GRLIB_FT_MEMCFG3; not_found_mctrl = 0; } +#endif +#if defined(CONFIG_SYS_GRLIB_SDRAM) /* find SDRAM controller */ base = ambapp_apb_next_nomem(VENDOR_GAISLER, GAISLER_SDCTRL, 0); if (base) { - sdctrl = (ambapp_dev_sdctrl *) base; + register ambapp_dev_sdctrl *sdctrl = (ambapp_dev_sdctrl *) base; /* config memory controller */ sdctrl->sdcfg = CONFIG_SYS_GRLIB_SDRAM; not_found_mctrl = 0; } +#endif +#if defined(CONFIG_SYS_GRLIB_DDR2_CFG1) && \ + defined(CONFIG_SYS_GRLIB_DDR2_CFG3) ahb = ambapp_ahb_next_nomem(VENDOR_GAISLER, GAISLER_DDR2SPA, 1, 0); if (ahb) { - ddr2spa = (ambapp_dev_ddr2spa *) ambapp_ahb_get_info(ahb, 1); + register ambapp_dev_ddr2spa *ddr2spa = + (ambapp_dev_ddr2spa *) ambapp_ahb_get_info(ahb, 1); /* Config DDR2 memory controller */ ddr2spa->cfg1 = CONFIG_SYS_GRLIB_DDR2_CFG1; ddr2spa->cfg3 = CONFIG_SYS_GRLIB_DDR2_CFG3; not_found_mctrl = 0; } +#endif +#if defined(CONFIG_SYS_GRLIB_DDR_CFG) ahb = ambapp_ahb_next_nomem(VENDOR_GAISLER, GAISLER_DDRSPA, 1, 0); if (ahb) { - ddrspa = (ambapp_dev_ddrspa *) ambapp_ahb_get_info(ahb, 1); + register ambapp_dev_ddrspa *ddrspa = + (ambapp_dev_ddrspa *) ambapp_ahb_get_info(ahb, 1); /* Config DDR memory controller */ ddrspa->ctrl = CONFIG_SYS_GRLIB_DDR_CFG; not_found_mctrl = 0; } +#endif /* failed to find any memory controller */ return not_found_mctrl; } +static int init_intr_ctrl(void) +{ + ambapp_apbdev apbdev; + ambapp_dev_irqmp *irqmp; + + /* look for AMBA APB IRQMP controller... */ + if (ambapp_apb_first(VENDOR_GAISLER, GAISLER_IRQMP, &apbdev) != 1) + return -1; /* no IRQ controller */ + + /* found irqmp, let's init .. */ + irqmp = (ambapp_dev_irqmp *) apbdev.address; + + /* initialize the IRQMP */ + irqmp->ilevel = 0xf; /* all IRQ off */ + irqmp->iforce = 0; + irqmp->ipend = 0; + irqmp->iclear = 0xfffe; /* clear all old pending interrupts */ + irqmp->cpu_mask[0] = 0; /* mask all IRQs on CPU 0 */ + irqmp->cpu_force[0] = 0; /* no force IRQ on CPU 0 */ + + return 0; +} + #ifndef CONFIG_SYS_GENERIC_BOARD /* Uses Timer 0 to get accurate @@ -278,6 +291,7 @@ static ambapp_dev_gptimer_element *tmr = NULL; int timer_init(void) { + ambapp_dev_gptimer *gptimer; ambapp_apbdev apbdev; if (ambapp_apb_first(VENDOR_GAISLER, GAISLER_GPTIMER, &apbdev) != 1) { @@ -285,7 +299,6 @@ int timer_init(void) return 1; } gptimer = (ambapp_dev_gptimer *) apbdev.address; - gptimer_irq = apbdev.irq; /* initialize prescaler common to all timers to 1MHz */ gptimer->scalar = gptimer->scalar_reload = diff --git a/arch/sparc/cpu/leon3/interrupts.c b/arch/sparc/cpu/leon3/interrupts.c index 20e295c..369fcb6 100644 --- a/arch/sparc/cpu/leon3/interrupts.c +++ b/arch/sparc/cpu/leon3/interrupts.c @@ -33,8 +33,10 @@ struct irq_action { unsigned int count; }; -extern ambapp_dev_irqmp *irqmp; +ambapp_dev_irqmp *irqmp = NULL; +#ifndef CONFIG_SYS_GENERIC_BOARD extern ambapp_dev_gptimer *gptimer; +#endif static struct irq_action irq_handlers[NR_IRQS] = { {0}, }; static int spurious_irq_cnt = 0;