]> git.sur5r.net Git - u-boot/blobdiff - cpu/mpc85xx/cpu_init.c
microblaze: Correct ffs regression for Microblaze
[u-boot] / cpu / mpc85xx / cpu_init.c
index 783c5bae7736315b948993ae7404e733fdb3cf1a..0041a60df967c0c51ee97c004a038a50e6ad9238 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007 Freescale Semiconductor.
+ * Copyright 2007-2009 Freescale Semiconductor, Inc.
  *
  * (C) Copyright 2003 Motorola Inc.
  * Modified by Xianghua Xiao, X.Xiao@motorola.com
@@ -129,40 +129,6 @@ void config_8560_ioports (volatile ccsr_cpm_t * cpm)
 }
 #endif
 
-/* We run cpu_init_early_f in AS = 1 */
-void cpu_init_early_f(void)
-{
-       set_tlb(0, CFG_CCSRBAR, CFG_CCSRBAR_PHYS,
-               MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
-               1, 0, BOOKE_PAGESZ_4K, 0);
-
-       /* set up CCSR if we want it moved */
-#if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR_PHYS)
-       {
-               u32 temp;
-
-               set_tlb(0, CFG_CCSRBAR_DEFAULT, CFG_CCSRBAR_DEFAULT,
-                       MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
-                       1, 1, BOOKE_PAGESZ_4K, 0);
-
-               temp = in_be32((volatile u32 *)CFG_CCSRBAR_DEFAULT);
-               out_be32((volatile u32 *)CFG_CCSRBAR_DEFAULT, CFG_CCSRBAR_PHYS >> 12);
-
-               temp = in_be32((volatile u32 *)CFG_CCSRBAR);
-       }
-#endif
-
-       /* Pointer is writable since we allocated a register for it */
-       gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
-
-       /* Clear initial global data */
-       memset ((void *) gd, 0, sizeof (gd_t));
-
-       init_laws();
-       invalidate_tlb(0);
-       init_tlbs();
-}
-
 /*
  * Breathe some life into the CPU...
  *
@@ -170,71 +136,98 @@ void cpu_init_early_f(void)
  * initialize a bunch of registers
  */
 
+#ifdef CONFIG_FSL_CORENET
+static void corenet_tb_init(void)
+{
+       volatile ccsr_rcpm_t *rcpm =
+               (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
+       volatile ccsr_pic_t *pic =
+               (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
+       u32 whoami = in_be32(&pic->whoami);
+
+       /* Enable the timebase register for this core */
+       out_be32(&rcpm->ctbenrl, (1 << whoami));
+}
+#endif
+
 void cpu_init_f (void)
 {
-       volatile ccsr_lbc_t *memctl = (void *)(CFG_MPC85xx_LBC_ADDR);
+       volatile ccsr_lbc_t *memctl = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
        extern void m8560_cpm_reset (void);
+#ifdef CONFIG_MPC8548
+       ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
+       uint svr = get_svr();
+
+       /*
+        * CPU2 errata workaround: A core hang possible while executing
+        * a msync instruction and a snoopable transaction from an I/O
+        * master tagged to make quick forward progress is present.
+        * Fixed in silicon rev 2.1.
+        */
+       if ((SVR_MAJ(svr) == 1) || ((SVR_MAJ(svr) == 2 && SVR_MIN(svr) == 0x0)))
+               out_be32(&ecm->eebpcr, in_be32(&ecm->eebpcr) | (1 << 16));
+#endif
 
        disable_tlb(14);
        disable_tlb(15);
 
 #ifdef CONFIG_CPM2
-       config_8560_ioports((ccsr_cpm_t *)CFG_MPC85xx_CPM_ADDR);
+       config_8560_ioports((ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR);
 #endif
 
        /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary
         * addresses - these have to be modified later when FLASH size
         * has been determined
         */
-#if defined(CFG_OR0_REMAP)
-       memctl->or0 = CFG_OR0_REMAP;
+#if defined(CONFIG_SYS_OR0_REMAP)
+       memctl->or0 = CONFIG_SYS_OR0_REMAP;
 #endif
-#if defined(CFG_OR1_REMAP)
-       memctl->or1 = CFG_OR1_REMAP;
+#if defined(CONFIG_SYS_OR1_REMAP)
+       memctl->or1 = CONFIG_SYS_OR1_REMAP;
 #endif
 
        /* now restrict to preliminary range */
        /* if cs1 is already set via debugger, leave cs0/cs1 alone */
        if (! memctl->br1 & 1) {
-#if defined(CFG_BR0_PRELIM) && defined(CFG_OR0_PRELIM)
-               memctl->br0 = CFG_BR0_PRELIM;
-               memctl->or0 = CFG_OR0_PRELIM;
+#if defined(CONFIG_SYS_BR0_PRELIM) && defined(CONFIG_SYS_OR0_PRELIM)
+               memctl->br0 = CONFIG_SYS_BR0_PRELIM;
+               memctl->or0 = CONFIG_SYS_OR0_PRELIM;
 #endif
 
-#if defined(CFG_BR1_PRELIM) && defined(CFG_OR1_PRELIM)
-               memctl->or1 = CFG_OR1_PRELIM;
-               memctl->br1 = CFG_BR1_PRELIM;
+#if defined(CONFIG_SYS_BR1_PRELIM) && defined(CONFIG_SYS_OR1_PRELIM)
+               memctl->or1 = CONFIG_SYS_OR1_PRELIM;
+               memctl->br1 = CONFIG_SYS_BR1_PRELIM;
 #endif
        }
 
-#if defined(CFG_BR2_PRELIM) && defined(CFG_OR2_PRELIM)
-       memctl->or2 = CFG_OR2_PRELIM;
-       memctl->br2 = CFG_BR2_PRELIM;
+#if defined(CONFIG_SYS_BR2_PRELIM) && defined(CONFIG_SYS_OR2_PRELIM)
+       memctl->or2 = CONFIG_SYS_OR2_PRELIM;
+       memctl->br2 = CONFIG_SYS_BR2_PRELIM;
 #endif
 
-#if defined(CFG_BR3_PRELIM) && defined(CFG_OR3_PRELIM)
-       memctl->or3 = CFG_OR3_PRELIM;
-       memctl->br3 = CFG_BR3_PRELIM;
+#if defined(CONFIG_SYS_BR3_PRELIM) && defined(CONFIG_SYS_OR3_PRELIM)
+       memctl->or3 = CONFIG_SYS_OR3_PRELIM;
+       memctl->br3 = CONFIG_SYS_BR3_PRELIM;
 #endif
 
-#if defined(CFG_BR4_PRELIM) && defined(CFG_OR4_PRELIM)
-       memctl->or4 = CFG_OR4_PRELIM;
-       memctl->br4 = CFG_BR4_PRELIM;
+#if defined(CONFIG_SYS_BR4_PRELIM) && defined(CONFIG_SYS_OR4_PRELIM)
+       memctl->or4 = CONFIG_SYS_OR4_PRELIM;
+       memctl->br4 = CONFIG_SYS_BR4_PRELIM;
 #endif
 
-#if defined(CFG_BR5_PRELIM) && defined(CFG_OR5_PRELIM)
-       memctl->or5 = CFG_OR5_PRELIM;
-       memctl->br5 = CFG_BR5_PRELIM;
+#if defined(CONFIG_SYS_BR5_PRELIM) && defined(CONFIG_SYS_OR5_PRELIM)
+       memctl->or5 = CONFIG_SYS_OR5_PRELIM;
+       memctl->br5 = CONFIG_SYS_BR5_PRELIM;
 #endif
 
-#if defined(CFG_BR6_PRELIM) && defined(CFG_OR6_PRELIM)
-       memctl->or6 = CFG_OR6_PRELIM;
-       memctl->br6 = CFG_BR6_PRELIM;
+#if defined(CONFIG_SYS_BR6_PRELIM) && defined(CONFIG_SYS_OR6_PRELIM)
+       memctl->or6 = CONFIG_SYS_OR6_PRELIM;
+       memctl->br6 = CONFIG_SYS_BR6_PRELIM;
 #endif
 
-#if defined(CFG_BR7_PRELIM) && defined(CFG_OR7_PRELIM)
-       memctl->or7 = CFG_OR7_PRELIM;
-       memctl->br7 = CFG_BR7_PRELIM;
+#if defined(CONFIG_SYS_BR7_PRELIM) && defined(CONFIG_SYS_OR7_PRELIM)
+       memctl->or7 = CONFIG_SYS_OR7_PRELIM;
+       memctl->br7 = CONFIG_SYS_BR7_PRELIM;
 #endif
 
 #if defined(CONFIG_CPM2)
@@ -247,7 +240,12 @@ void cpu_init_f (void)
 #if defined(CONFIG_MPC8536)
        fsl_serdes_init();
 #endif
-
+#if defined(CONFIG_FSL_DMA)
+       dma_init();
+#endif
+#ifdef CONFIG_FSL_CORENET
+       corenet_tb_init();
+#endif
 }
 
 
@@ -264,7 +262,7 @@ int cpu_init_r(void)
        puts ("L2:    ");
 
 #if defined(CONFIG_L2_CACHE)
-       volatile ccsr_l2cache_t *l2cache = (void *)CFG_MPC85xx_L2_ADDR;
+       volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR;
        volatile uint cache_ctl;
        uint svr, ver;
        uint l2srbar;
@@ -275,6 +273,25 @@ int cpu_init_r(void)
 
        asm("msync;isync");
        cache_ctl = l2cache->l2ctl;
+
+#if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SYS_INIT_L2_ADDR)
+       if (cache_ctl & MPC85xx_L2CTL_L2E) {
+               /* Clear L2 SRAM memory-mapped base address */
+               out_be32(&l2cache->l2srbar0, 0x0);
+               out_be32(&l2cache->l2srbar1, 0x0);
+
+               /* set MBECCDIS=0, SBECCDIS=0 */
+               clrbits_be32(&l2cache->l2errdis,
+                               (MPC85xx_L2ERRDIS_MBECC |
+                                MPC85xx_L2ERRDIS_SBECC));
+
+               /* set L2E=0, L2SRAM=0 */
+               clrbits_be32(&l2cache->l2ctl,
+                               (MPC85xx_L2CTL_L2E |
+                                MPC85xx_L2CTL_L2SRAM_ENTIRE));
+       }
+#endif
+
        l2siz_field = (cache_ctl >> 28) & 0x3;
 
        switch (l2siz_field) {
@@ -314,16 +331,17 @@ int cpu_init_r(void)
                break;
        }
 
-       if (l2cache->l2ctl & 0x80000000) {
+       if (l2cache->l2ctl & MPC85xx_L2CTL_L2E) {
                puts("already enabled");
                l2srbar = l2cache->l2srbar0;
-#ifdef CFG_INIT_L2_ADDR
-               if (l2cache->l2ctl & 0x00010000 && l2srbar >= CFG_FLASH_BASE) {
-                       l2srbar = CFG_INIT_L2_ADDR;
+#ifdef CONFIG_SYS_INIT_L2_ADDR
+               if (l2cache->l2ctl & MPC85xx_L2CTL_L2SRAM_ENTIRE
+                               && l2srbar >= CONFIG_SYS_FLASH_BASE) {
+                       l2srbar = CONFIG_SYS_INIT_L2_ADDR;
                        l2cache->l2srbar0 = l2srbar;
-                       printf("moving to 0x%08x", CFG_INIT_L2_ADDR);
+                       printf("moving to 0x%08x", CONFIG_SYS_INIT_L2_ADDR);
                }
-#endif /* CFG_INIT_L2_ADDR */
+#endif /* CONFIG_SYS_INIT_L2_ADDR */
                puts("\n");
        } else {
                asm("msync;isync");
@@ -331,11 +349,27 @@ int cpu_init_r(void)
                asm("msync;isync");
                puts("enabled\n");
        }
+#elif defined(CONFIG_BACKSIDE_L2_CACHE)
+       u32 l2cfg0 = mfspr(SPRN_L2CFG0);
+
+       /* invalidate the L2 cache */
+       mtspr(SPRN_L2CSR0, (L2CSR0_L2FI|L2CSR0_L2LFC));
+       while (mfspr(SPRN_L2CSR0) & (L2CSR0_L2FI|L2CSR0_L2LFC))
+               ;
+
+       /* enable the cache */
+       mtspr(SPRN_L2CSR0, CONFIG_SYS_INIT_L2CSR0);
+
+       if (CONFIG_SYS_INIT_L2CSR0 & L2CSR0_L2E) {
+               while (!(mfspr(SPRN_L2CSR0) & L2CSR0_L2E))
+                       ;
+               printf("%d KB enabled\n", (l2cfg0 & 0x3fff) * 64);
+       }
 #else
        puts("disabled\n");
 #endif
 #ifdef CONFIG_QE
-       uint qe_base = CFG_IMMR + 0x00080000; /* QE immr base */
+       uint qe_base = CONFIG_SYS_IMMR + 0x00080000; /* QE immr base */
        qe_init(qe_base);
        qe_reset();
 #endif
@@ -345,3 +379,21 @@ int cpu_init_r(void)
 #endif
        return 0;
 }
+
+extern void setup_ivors(void);
+
+void arch_preboot_os(void)
+{
+       u32 msr;
+
+       /*
+        * We are changing interrupt offsets and are about to boot the OS so
+        * we need to make sure we disable all async interrupts. EE is already
+        * disabled by the time we get called.
+        */
+       msr = mfmsr();
+       msr &= ~(MSR_ME|MSR_CE|MSR_DE);
+       mtmsr(msr);
+
+       setup_ivors();
+}