[U-Boot] [PATCH v2 10/10] sparc: Cleanup of LEON3 CPU initialisation code

Francois Retief fgretief at spaceteq.co.za
Wed Nov 5 13:08:23 CET 2014


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 <fgretief at spaceteq.co.za>
---

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(-)

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;
--
1.9.3


________________________________
Disclaimer and confidentiality note – refer to our website for further details: www.spaceteq.co.za <http://www.spaceteq.co.za/home/emaildisclaimer/>


More information about the U-Boot mailing list