global: Migrate CONFIG_SYS_FSL* symbols to the CFG_SYS namespace
[platform/kernel/u-boot.git] / arch / powerpc / cpu / mpc85xx / mp.c
index 39adf8e..f109ecb 100644 (file)
@@ -1,38 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2008-2011 Freescale Semiconductor, Inc.
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
  */
 
 #include <common.h>
+#include <cpu_func.h>
+#include <env.h>
+#include <log.h>
+#include <asm/global_data.h>
 #include <asm/processor.h>
+#include <env.h>
 #include <ioports.h>
 #include <lmb.h>
 #include <asm/io.h>
 #include <asm/mmu.h>
 #include <asm/fsl_law.h>
-#include <asm/fsl_ddr_sdram.h>
+#include <fsl_ddr_sdram.h>
+#include <linux/delay.h>
 #include "mp.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 u32 fsl_ddr_get_intl3r(void);
 
+extern u32 __spin_table[];
+
 u32 get_my_id()
 {
        return mfspr(SPRN_PIR);
@@ -44,10 +35,8 @@ u32 get_my_id()
  */
 int hold_cores_in_reset(int verbose)
 {
-       const char *s = getenv("mp_holdoff");
-
-       /* Default to no, overriden by 'y', 'yes', 'Y', 'Yes', or '1' */
-       if (s && (*s == 'y' || *s == 'Y' || *s == '1')) {
+       /* Default to no, overridden by 'y', 'yes', 'Y', 'Yes', or '1' */
+       if (env_get_yesno("mp_holdoff") == 1) {
                if (verbose) {
                        puts("Secondary cores are being held in reset.\n");
                        puts("See 'mp_holdoff' environment variable\n");
@@ -59,9 +48,9 @@ int hold_cores_in_reset(int verbose)
        return 0;
 }
 
-int cpu_reset(int nr)
+int cpu_reset(u32 nr)
 {
-       volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
+       volatile ccsr_pic_t *pic = (void *)(CFG_SYS_MPC8xxx_PIC_ADDR);
        out_be32(&pic->pir, 1 << nr);
        /* the dummy read works around an errata on early 85xx MP PICs */
        (void)in_be32(&pic->pir);
@@ -70,7 +59,7 @@ int cpu_reset(int nr)
        return 0;
 }
 
-int cpu_status(int nr)
+int cpu_status(u32 nr)
 {
        u32 *table, id = get_my_id();
 
@@ -78,26 +67,27 @@ int cpu_status(int nr)
                return 0;
 
        if (nr == id) {
-               table = (u32 *)get_spin_virt_addr();
+               table = (u32 *)&__spin_table;
                printf("table base @ 0x%p\n", table);
+       } else if (is_core_disabled(nr)) {
+               puts("Disabled\n");
        } else {
-               table = (u32 *)get_spin_virt_addr() + nr * NUM_BOOT_ENTRY;
+               table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
                printf("Running on cpu %d\n", id);
                printf("\n");
                printf("table @ 0x%p\n", table);
                printf("   addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
-               printf("   pir  - 0x%08x\n", table[BOOT_ENTRY_PIR]);
                printf("   r3   - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
-               printf("   r6   - 0x%08x\n", table[BOOT_ENTRY_R6_LOWER]);
+               printf("   pir  - 0x%08x\n", table[BOOT_ENTRY_PIR]);
        }
 
        return 0;
 }
 
 #ifdef CONFIG_FSL_CORENET
-int cpu_disable(int nr)
+int cpu_disable(u32 nr)
 {
-       volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
+       volatile ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
 
        setbits_be32(&gur->coredisrl, 1 << nr);
 
@@ -105,15 +95,15 @@ int cpu_disable(int nr)
 }
 
 int is_core_disabled(int nr) {
-       ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
+       ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
        u32 coredisrl = in_be32(&gur->coredisrl);
 
        return (coredisrl & (1 << nr));
 }
 #else
-int cpu_disable(int nr)
+int cpu_disable(u32 nr)
 {
-       volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
+       volatile ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
 
        switch (nr) {
        case 0:
@@ -131,7 +121,7 @@ int cpu_disable(int nr)
 }
 
 int is_core_disabled(int nr) {
-       ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
+       ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
        u32 devdisr = in_be32(&gur->devdisr);
 
        switch (nr) {
@@ -151,12 +141,11 @@ static u8 boot_entry_map[4] = {
        0,
        BOOT_ENTRY_PIR,
        BOOT_ENTRY_R3_LOWER,
-       BOOT_ENTRY_R6_LOWER,
 };
 
-int cpu_release(int nr, int argc, char * const argv[])
+int cpu_release(u32 nr, int argc, char *const argv[])
 {
-       u32 i, val, *table = (u32 *)get_spin_virt_addr() + nr * NUM_BOOT_ENTRY;
+       u32 i, val, *table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
        u64 boot_addr;
 
        if (hold_cores_in_reset(1))
@@ -174,11 +163,11 @@ int cpu_release(int nr, int argc, char * const argv[])
 
        boot_addr = simple_strtoull(argv[0], NULL, 16);
 
-       /* handle pir, r3, r6 */
-       for (i = 1; i < 4; i++) {
+       /* handle pir, r3 */
+       for (i = 1; i < 3; i++) {
                if (argv[i][0] != '-') {
                        u8 entry = boot_entry_map[i];
-                       val = simple_strtoul(argv[i], NULL, 16);
+                       val = hextoul(argv[i], NULL);
                        table[entry] = val;
                }
        }
@@ -202,11 +191,11 @@ u32 determine_mp_bootpg(unsigned int *pagesize)
        struct law_entry e;
 #endif
 
-       /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
-       if ((u64)gd->ram_size > 0xfffff000)
-               bootpg = 0xfffff000;
-       else
-               bootpg = gd->ram_size - 4096;
+
+       /* use last 4K of mapped memory */
+       bootpg = ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
+               CONFIG_MAX_MEM_MAPPED : gd->ram_size) +
+               CONFIG_SYS_SDRAM_BASE - 4096;
        if (pagesize)
                *pagesize = 4096;
 
@@ -257,29 +246,16 @@ u32 determine_mp_bootpg(unsigned int *pagesize)
        return bootpg;
 }
 
-ulong get_spin_phys_addr(void)
+phys_addr_t get_spin_phys_addr(void)
 {
-       extern ulong __secondary_start_page;
-       extern ulong __spin_table;
-
-       return (determine_mp_bootpg() +
-               (ulong)&__spin_table - (ulong)&__secondary_start_page);
-}
-
-ulong get_spin_virt_addr(void)
-{
-       extern ulong __secondary_start_page;
-       extern ulong __spin_table;
-
-       return (CONFIG_BPTR_VIRT_ADDR +
-               (ulong)&__spin_table - (ulong)&__secondary_start_page);
+       return virt_to_phys(&__spin_table);
 }
 
 #ifdef CONFIG_FSL_CORENET
 static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
 {
        u32 cpu_up_mask, whoami, brsize = LAW_SIZE_4K;
-       u32 *table = (u32 *)get_spin_virt_addr();
+       u32 *table = (u32 *)&__spin_table;
        volatile ccsr_gur_t *gur;
        volatile ccsr_local_t *ccm;
        volatile ccsr_rcpm_t *rcpm;
@@ -288,10 +264,10 @@ static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
        u32 mask = cpu_mask();
        struct law_entry e;
 
-       gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-       ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
-       rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
-       pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
+       gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
+       ccm = (void *)(CFG_SYS_FSL_CORENET_CCM_ADDR);
+       rcpm = (void *)(CFG_SYS_FSL_CORENET_RCPM_ADDR);
+       pic = (void *)(CFG_SYS_MPC8xxx_PIC_ADDR);
 
        whoami = in_be32(&pic->whoami);
        cpu_up_mask = 1 << whoami;
@@ -358,11 +334,11 @@ static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
 static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
 {
        u32 up, cpu_up_mask, whoami;
-       u32 *table = (u32 *)get_spin_virt_addr();
+       u32 *table = (u32 *)&__spin_table;
        volatile u32 bpcr;
-       volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
-       volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
-       volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
+       volatile ccsr_local_ecm_t *ecm = (void *)(CFG_SYS_MPC85xx_ECM_ADDR);
+       volatile ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
+       volatile ccsr_pic_t *pic = (void *)(CFG_SYS_MPC8xxx_PIC_ADDR);
        u32 devdisr;
        int timeout = 10;
 
@@ -442,10 +418,11 @@ void cpu_mp_lmb_reserve(struct lmb *lmb)
 
 void setup_mp(void)
 {
-       extern ulong __secondary_start_page;
-       extern ulong __bootpg_addr;
+       extern u32 __secondary_start_page;
+       extern u32 __bootpg_addr, __spin_table_addr, __second_half_boot_page;
 
-       ulong fixup = (ulong)&__secondary_start_page;
+       int i;
+       ulong fixup = (u32)&__secondary_start_page;
        u32 bootpg, bootpg_map, pagesize;
 
        bootpg = determine_mp_bootpg(&pagesize);
@@ -466,22 +443,31 @@ void setup_mp(void)
        if (hold_cores_in_reset(0))
                return;
 
-       /* Store the bootpg's SDRAM address for use by secondary CPU cores */
-       __bootpg_addr = bootpg;
+       /*
+        * Store the bootpg's cache-able half address for use by secondary
+        * CPU cores to continue to boot
+        */
+       __bootpg_addr = (u32)virt_to_phys(&__second_half_boot_page);
+
+       /* Store spin table's physical address for use by secondary cores */
+       __spin_table_addr = (u32)get_spin_phys_addr();
+
+       /* flush bootpg it before copying invalidate any staled cacheline */
+       flush_cache(bootpg, 4096);
 
        /* look for the tlb covering the reset page, there better be one */
-       int i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
+       i = find_tlb_idx((void *)BPTR_VIRT_ADDR, 1);
 
        /* we found a match */
        if (i != -1) {
                /* map reset page to bootpg so we can copy code there */
                disable_tlb(i);
 
-               set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
+               set_tlb(1, BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
                        MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
                        0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
 
-               memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
+               memcpy((void *)BPTR_VIRT_ADDR, (void *)fixup, 4096);
 
                plat_mp_up(bootpg_map, pagesize);
        } else {