Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 1 | /* |
Ed Swarthout | 853e2de | 2011-03-03 18:28:14 -0600 | [diff] [blame] | 2 | * Copyright 2008-2011 Freescale Semiconductor, Inc. |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/processor.h> |
| 9 | #include <ioports.h> |
Kumar Gala | 5769ded | 2008-03-26 08:53:53 -0500 | [diff] [blame] | 10 | #include <lmb.h> |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 11 | #include <asm/io.h> |
Kumar Gala | 8399e12 | 2009-09-03 08:41:31 -0500 | [diff] [blame] | 12 | #include <asm/mmu.h> |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 13 | #include <asm/fsl_law.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 14 | #include <fsl_ddr_sdram.h> |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 15 | #include "mp.h" |
| 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 18 | u32 fsl_ddr_get_intl3r(void); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 19 | |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 20 | extern u32 __spin_table[]; |
| 21 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 22 | u32 get_my_id() |
| 23 | { |
| 24 | return mfspr(SPRN_PIR); |
| 25 | } |
| 26 | |
Aaron Sierra | ec8863b | 2010-09-30 12:22:16 -0500 | [diff] [blame] | 27 | /* |
| 28 | * Determine if U-Boot should keep secondary cores in reset, or let them out |
| 29 | * of reset and hold them in a spinloop |
| 30 | */ |
| 31 | int hold_cores_in_reset(int verbose) |
| 32 | { |
Robert P. J. Day | 8d56db9 | 2016-07-15 13:44:45 -0400 | [diff] [blame] | 33 | /* Default to no, overridden by 'y', 'yes', 'Y', 'Yes', or '1' */ |
Joe Hershberger | 864ec56 | 2012-12-11 22:16:22 -0600 | [diff] [blame] | 34 | if (getenv_yesno("mp_holdoff") == 1) { |
Aaron Sierra | ec8863b | 2010-09-30 12:22:16 -0500 | [diff] [blame] | 35 | if (verbose) { |
| 36 | puts("Secondary cores are being held in reset.\n"); |
| 37 | puts("See 'mp_holdoff' environment variable\n"); |
| 38 | } |
| 39 | |
| 40 | return 1; |
| 41 | } |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 46 | int cpu_reset(int nr) |
| 47 | { |
Kim Phillips | 2ecbfeb | 2010-08-09 18:39:57 -0500 | [diff] [blame] | 48 | volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 49 | out_be32(&pic->pir, 1 << nr); |
Kumar Gala | e1064b3 | 2009-03-31 23:11:05 -0500 | [diff] [blame] | 50 | /* the dummy read works around an errata on early 85xx MP PICs */ |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 51 | (void)in_be32(&pic->pir); |
| 52 | out_be32(&pic->pir, 0x0); |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | int cpu_status(int nr) |
| 58 | { |
| 59 | u32 *table, id = get_my_id(); |
| 60 | |
Aaron Sierra | ec8863b | 2010-09-30 12:22:16 -0500 | [diff] [blame] | 61 | if (hold_cores_in_reset(1)) |
| 62 | return 0; |
| 63 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 64 | if (nr == id) { |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 65 | table = (u32 *)&__spin_table; |
Kumar Gala | 275f4c1 | 2008-07-14 14:03:02 -0500 | [diff] [blame] | 66 | printf("table base @ 0x%p\n", table); |
York Sun | c072306 | 2013-03-25 07:40:00 +0000 | [diff] [blame] | 67 | } else if (is_core_disabled(nr)) { |
| 68 | puts("Disabled\n"); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 69 | } else { |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 70 | table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY; |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 71 | printf("Running on cpu %d\n", id); |
| 72 | printf("\n"); |
Kumar Gala | 275f4c1 | 2008-07-14 14:03:02 -0500 | [diff] [blame] | 73 | printf("table @ 0x%p\n", table); |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 74 | printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]); |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 75 | printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]); |
York Sun | 31a0c8c | 2012-10-08 07:44:29 +0000 | [diff] [blame] | 76 | printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
Kumar Gala | c7bf0f9 | 2010-01-12 12:56:05 -0600 | [diff] [blame] | 82 | #ifdef CONFIG_FSL_CORENET |
Kumar Gala | 006e2c8 | 2010-01-12 11:42:43 -0600 | [diff] [blame] | 83 | int cpu_disable(int nr) |
| 84 | { |
Kumar Gala | c7bf0f9 | 2010-01-12 12:56:05 -0600 | [diff] [blame] | 85 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 86 | |
| 87 | setbits_be32(&gur->coredisrl, 1 << nr); |
| 88 | |
| 89 | return 0; |
| 90 | } |
Kumar Gala | 819a479 | 2010-06-09 22:33:53 -0500 | [diff] [blame] | 91 | |
| 92 | int is_core_disabled(int nr) { |
| 93 | ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 94 | u32 coredisrl = in_be32(&gur->coredisrl); |
| 95 | |
| 96 | return (coredisrl & (1 << nr)); |
| 97 | } |
Kumar Gala | c7bf0f9 | 2010-01-12 12:56:05 -0600 | [diff] [blame] | 98 | #else |
| 99 | int cpu_disable(int nr) |
| 100 | { |
| 101 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 102 | |
| 103 | switch (nr) { |
| 104 | case 0: |
| 105 | setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU0); |
| 106 | break; |
| 107 | case 1: |
| 108 | setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU1); |
| 109 | break; |
| 110 | default: |
| 111 | printf("Invalid cpu number for disable %d\n", nr); |
| 112 | return 1; |
| 113 | } |
| 114 | |
| 115 | return 0; |
Kumar Gala | 006e2c8 | 2010-01-12 11:42:43 -0600 | [diff] [blame] | 116 | } |
Kumar Gala | 819a479 | 2010-06-09 22:33:53 -0500 | [diff] [blame] | 117 | |
| 118 | int is_core_disabled(int nr) { |
| 119 | ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 120 | u32 devdisr = in_be32(&gur->devdisr); |
| 121 | |
| 122 | switch (nr) { |
| 123 | case 0: |
| 124 | return (devdisr & MPC85xx_DEVDISR_CPU0); |
| 125 | case 1: |
| 126 | return (devdisr & MPC85xx_DEVDISR_CPU1); |
| 127 | default: |
| 128 | printf("Invalid cpu number for disable %d\n", nr); |
| 129 | } |
| 130 | |
| 131 | return 0; |
| 132 | } |
Kumar Gala | c7bf0f9 | 2010-01-12 12:56:05 -0600 | [diff] [blame] | 133 | #endif |
Kumar Gala | 006e2c8 | 2010-01-12 11:42:43 -0600 | [diff] [blame] | 134 | |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 135 | static u8 boot_entry_map[4] = { |
| 136 | 0, |
| 137 | BOOT_ENTRY_PIR, |
| 138 | BOOT_ENTRY_R3_LOWER, |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 139 | }; |
| 140 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 141 | int cpu_release(int nr, int argc, char * const argv[]) |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 142 | { |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 143 | u32 i, val, *table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY; |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 144 | u64 boot_addr; |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 145 | |
Aaron Sierra | ec8863b | 2010-09-30 12:22:16 -0500 | [diff] [blame] | 146 | if (hold_cores_in_reset(1)) |
| 147 | return 0; |
| 148 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 149 | if (nr == get_my_id()) { |
| 150 | printf("Invalid to release the boot core.\n\n"); |
| 151 | return 1; |
| 152 | } |
| 153 | |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 154 | if (argc != 4) { |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 155 | printf("Invalid number of arguments to release.\n\n"); |
| 156 | return 1; |
| 157 | } |
| 158 | |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 159 | boot_addr = simple_strtoull(argv[0], NULL, 16); |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 160 | |
York Sun | 31a0c8c | 2012-10-08 07:44:29 +0000 | [diff] [blame] | 161 | /* handle pir, r3 */ |
| 162 | for (i = 1; i < 3; i++) { |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 163 | if (argv[i][0] != '-') { |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 164 | u8 entry = boot_entry_map[i]; |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 165 | val = simple_strtoul(argv[i], NULL, 16); |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 166 | table[entry] = val; |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 170 | table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32); |
Kumar Gala | 398dcd6 | 2008-04-28 02:24:04 -0500 | [diff] [blame] | 171 | |
| 172 | /* ensure all table updates complete before final address write */ |
| 173 | eieio(); |
| 174 | |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 175 | table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 180 | u32 determine_mp_bootpg(unsigned int *pagesize) |
Kumar Gala | e1064b3 | 2009-03-31 23:11:05 -0500 | [diff] [blame] | 181 | { |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 182 | u32 bootpg; |
| 183 | #ifdef CONFIG_SYS_FSL_ERRATUM_A004468 |
| 184 | u32 svr = get_svr(); |
| 185 | u32 granule_size, check; |
| 186 | struct law_entry e; |
| 187 | #endif |
| 188 | |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 189 | |
| 190 | /* use last 4K of mapped memory */ |
| 191 | bootpg = ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ? |
| 192 | CONFIG_MAX_MEM_MAPPED : gd->ram_size) + |
| 193 | CONFIG_SYS_SDRAM_BASE - 4096; |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 194 | if (pagesize) |
| 195 | *pagesize = 4096; |
Kumar Gala | e1064b3 | 2009-03-31 23:11:05 -0500 | [diff] [blame] | 196 | |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 197 | #ifdef CONFIG_SYS_FSL_ERRATUM_A004468 |
| 198 | /* |
| 199 | * Erratum A004468 has two parts. The 3-way interleaving applies to T4240, |
| 200 | * to be fixed in rev 2.0. The 2-way interleaving applies to many SoCs. But |
| 201 | * the way boot page chosen in u-boot avoids hitting this erratum. So only |
| 202 | * thw workaround for 3-way interleaving is needed. |
| 203 | * |
| 204 | * To make sure boot page translation works with 3-Way DDR interleaving |
| 205 | * enforce a check for the following constrains |
| 206 | * 8K granule size requires BRSIZE=8K and |
| 207 | * bootpg >> log2(BRSIZE) %3 == 1 |
| 208 | * 4K and 1K granule size requires BRSIZE=4K and |
| 209 | * bootpg >> log2(BRSIZE) %3 == 0 |
| 210 | */ |
| 211 | if (SVR_SOC_VER(svr) == SVR_T4240 && SVR_MAJ(svr) < 2) { |
| 212 | e = find_law(bootpg); |
| 213 | switch (e.trgt_id) { |
| 214 | case LAW_TRGT_IF_DDR_INTLV_123: |
| 215 | granule_size = fsl_ddr_get_intl3r() & 0x1f; |
| 216 | if (granule_size == FSL_DDR_3WAY_8KB_INTERLEAVING) { |
| 217 | if (pagesize) |
| 218 | *pagesize = 8192; |
| 219 | bootpg &= 0xffffe000; /* align to 8KB */ |
| 220 | check = bootpg >> 13; |
| 221 | while ((check % 3) != 1) |
| 222 | check--; |
| 223 | bootpg = check << 13; |
| 224 | debug("Boot page (8K) at 0x%08x\n", bootpg); |
| 225 | break; |
| 226 | } else { |
| 227 | bootpg &= 0xfffff000; /* align to 4KB */ |
| 228 | check = bootpg >> 12; |
| 229 | while ((check % 3) != 0) |
| 230 | check--; |
| 231 | bootpg = check << 12; |
| 232 | debug("Boot page (4K) at 0x%08x\n", bootpg); |
| 233 | } |
| 234 | break; |
| 235 | default: |
| 236 | break; |
| 237 | } |
| 238 | } |
| 239 | #endif /* CONFIG_SYS_FSL_ERRATUM_A004468 */ |
| 240 | |
| 241 | return bootpg; |
Kumar Gala | e1064b3 | 2009-03-31 23:11:05 -0500 | [diff] [blame] | 242 | } |
| 243 | |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 244 | phys_addr_t get_spin_phys_addr(void) |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 245 | { |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 246 | return virt_to_phys(&__spin_table); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 247 | } |
| 248 | |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 249 | #ifdef CONFIG_FSL_CORENET |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 250 | static void plat_mp_up(unsigned long bootpg, unsigned int pagesize) |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 251 | { |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 252 | u32 cpu_up_mask, whoami, brsize = LAW_SIZE_4K; |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 253 | u32 *table = (u32 *)&__spin_table; |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 254 | volatile ccsr_gur_t *gur; |
| 255 | volatile ccsr_local_t *ccm; |
| 256 | volatile ccsr_rcpm_t *rcpm; |
| 257 | volatile ccsr_pic_t *pic; |
| 258 | int timeout = 10; |
Timur Tabi | 4728942 | 2011-08-05 16:15:24 -0500 | [diff] [blame] | 259 | u32 mask = cpu_mask(); |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 260 | struct law_entry e; |
| 261 | |
| 262 | gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 263 | ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR); |
| 264 | rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR); |
Kim Phillips | 2ecbfeb | 2010-08-09 18:39:57 -0500 | [diff] [blame] | 265 | pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR); |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 266 | |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 267 | whoami = in_be32(&pic->whoami); |
| 268 | cpu_up_mask = 1 << whoami; |
| 269 | out_be32(&ccm->bstrl, bootpg); |
| 270 | |
| 271 | e = find_law(bootpg); |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 272 | /* pagesize is only 4K or 8K */ |
| 273 | if (pagesize == 8192) |
| 274 | brsize = LAW_SIZE_8K; |
| 275 | out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | brsize); |
| 276 | debug("BRSIZE is 0x%x\n", brsize); |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 277 | |
Dave Liu | 452ddb6 | 2009-11-17 20:01:24 -0600 | [diff] [blame] | 278 | /* readback to sync write */ |
| 279 | in_be32(&ccm->bstrar); |
| 280 | |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 281 | /* disable time base at the platform */ |
| 282 | out_be32(&rcpm->ctbenrl, cpu_up_mask); |
| 283 | |
Timur Tabi | 4728942 | 2011-08-05 16:15:24 -0500 | [diff] [blame] | 284 | out_be32(&gur->brrl, mask); |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 285 | |
| 286 | /* wait for everyone */ |
| 287 | while (timeout) { |
Timur Tabi | 4728942 | 2011-08-05 16:15:24 -0500 | [diff] [blame] | 288 | unsigned int i, cpu, nr_cpus = cpu_numcores(); |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 289 | |
Timur Tabi | 4728942 | 2011-08-05 16:15:24 -0500 | [diff] [blame] | 290 | for_each_cpu(i, cpu, nr_cpus, mask) { |
| 291 | if (table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER]) |
| 292 | cpu_up_mask |= (1 << cpu); |
| 293 | } |
| 294 | |
| 295 | if ((cpu_up_mask & mask) == mask) |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 296 | break; |
| 297 | |
| 298 | udelay(100); |
| 299 | timeout--; |
| 300 | } |
| 301 | |
| 302 | if (timeout == 0) |
| 303 | printf("CPU up timeout. CPU up mask is %x should be %x\n", |
Timur Tabi | 4728942 | 2011-08-05 16:15:24 -0500 | [diff] [blame] | 304 | cpu_up_mask, mask); |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 305 | |
| 306 | /* enable time base at the platform */ |
| 307 | out_be32(&rcpm->ctbenrl, 0); |
Kumar Gala | 6c5025e | 2011-03-13 10:55:53 -0500 | [diff] [blame] | 308 | |
| 309 | /* readback to sync write */ |
| 310 | in_be32(&rcpm->ctbenrl); |
| 311 | |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 312 | mtspr(SPRN_TBWU, 0); |
| 313 | mtspr(SPRN_TBWL, 0); |
Kumar Gala | 6c5025e | 2011-03-13 10:55:53 -0500 | [diff] [blame] | 314 | |
Timur Tabi | 4728942 | 2011-08-05 16:15:24 -0500 | [diff] [blame] | 315 | out_be32(&rcpm->ctbenrl, mask); |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 316 | |
| 317 | #ifdef CONFIG_MPC8xxx_DISABLE_BPTR |
| 318 | /* |
| 319 | * Disabling Boot Page Translation allows the memory region 0xfffff000 |
| 320 | * to 0xffffffff to be used normally. Leaving Boot Page Translation |
| 321 | * enabled remaps 0xfffff000 to SDRAM which makes that memory region |
| 322 | * unusable for normal operation but it does allow OSes to easily |
| 323 | * reset a processor core to put it back into U-Boot's spinloop. |
| 324 | */ |
Ed Swarthout | 853e2de | 2011-03-03 18:28:14 -0600 | [diff] [blame] | 325 | clrbits_be32(&ccm->bstrar, LAW_EN); |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 326 | #endif |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 327 | } |
| 328 | #else |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 329 | static void plat_mp_up(unsigned long bootpg, unsigned int pagesize) |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 330 | { |
| 331 | u32 up, cpu_up_mask, whoami; |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 332 | u32 *table = (u32 *)&__spin_table; |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 333 | volatile u32 bpcr; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 334 | volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR); |
| 335 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
Kim Phillips | 2ecbfeb | 2010-08-09 18:39:57 -0500 | [diff] [blame] | 336 | volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 337 | u32 devdisr; |
| 338 | int timeout = 10; |
| 339 | |
| 340 | whoami = in_be32(&pic->whoami); |
| 341 | out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12)); |
| 342 | |
| 343 | /* disable time base at the platform */ |
| 344 | devdisr = in_be32(&gur->devdisr); |
| 345 | if (whoami) |
| 346 | devdisr |= MPC85xx_DEVDISR_TB0; |
| 347 | else |
| 348 | devdisr |= MPC85xx_DEVDISR_TB1; |
| 349 | out_be32(&gur->devdisr, devdisr); |
| 350 | |
| 351 | /* release the hounds */ |
Poonam Aggrwal | 4baef82 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 352 | up = ((1 << cpu_numcores()) - 1); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 353 | bpcr = in_be32(&ecm->eebpcr); |
| 354 | bpcr |= (up << 24); |
| 355 | out_be32(&ecm->eebpcr, bpcr); |
| 356 | asm("sync; isync; msync"); |
| 357 | |
| 358 | cpu_up_mask = 1 << whoami; |
| 359 | /* wait for everyone */ |
| 360 | while (timeout) { |
| 361 | int i; |
Poonam Aggrwal | 4baef82 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 362 | for (i = 0; i < cpu_numcores(); i++) { |
Kumar Gala | 615f14d | 2008-04-09 04:20:57 -0500 | [diff] [blame] | 363 | if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER]) |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 364 | cpu_up_mask |= (1 << i); |
| 365 | }; |
| 366 | |
| 367 | if ((cpu_up_mask & up) == up) |
| 368 | break; |
| 369 | |
| 370 | udelay(100); |
| 371 | timeout--; |
| 372 | } |
| 373 | |
Kumar Gala | 615f14d | 2008-04-09 04:20:57 -0500 | [diff] [blame] | 374 | if (timeout == 0) |
| 375 | printf("CPU up timeout. CPU up mask is %x should be %x\n", |
| 376 | cpu_up_mask, up); |
| 377 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 378 | /* enable time base at the platform */ |
| 379 | if (whoami) |
| 380 | devdisr |= MPC85xx_DEVDISR_TB1; |
| 381 | else |
| 382 | devdisr |= MPC85xx_DEVDISR_TB0; |
| 383 | out_be32(&gur->devdisr, devdisr); |
Kumar Gala | 6c5025e | 2011-03-13 10:55:53 -0500 | [diff] [blame] | 384 | |
| 385 | /* readback to sync write */ |
| 386 | in_be32(&gur->devdisr); |
| 387 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 388 | mtspr(SPRN_TBWU, 0); |
| 389 | mtspr(SPRN_TBWL, 0); |
| 390 | |
| 391 | devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1); |
| 392 | out_be32(&gur->devdisr, devdisr); |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 393 | |
| 394 | #ifdef CONFIG_MPC8xxx_DISABLE_BPTR |
| 395 | /* |
| 396 | * Disabling Boot Page Translation allows the memory region 0xfffff000 |
| 397 | * to 0xffffffff to be used normally. Leaving Boot Page Translation |
| 398 | * enabled remaps 0xfffff000 to SDRAM which makes that memory region |
| 399 | * unusable for normal operation but it does allow OSes to easily |
| 400 | * reset a processor core to put it back into U-Boot's spinloop. |
| 401 | */ |
| 402 | clrbits_be32(&ecm->bptr, 0x80000000); |
| 403 | #endif |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 404 | } |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 405 | #endif |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 406 | |
Kumar Gala | 5769ded | 2008-03-26 08:53:53 -0500 | [diff] [blame] | 407 | void cpu_mp_lmb_reserve(struct lmb *lmb) |
| 408 | { |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 409 | u32 bootpg = determine_mp_bootpg(NULL); |
Kumar Gala | 5769ded | 2008-03-26 08:53:53 -0500 | [diff] [blame] | 410 | |
| 411 | lmb_reserve(lmb, bootpg, 4096); |
| 412 | } |
| 413 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 414 | void setup_mp(void) |
| 415 | { |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 416 | extern u32 __secondary_start_page; |
| 417 | extern u32 __bootpg_addr, __spin_table_addr, __second_half_boot_page; |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 418 | |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 419 | int i; |
| 420 | ulong fixup = (u32)&__secondary_start_page; |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 421 | u32 bootpg, bootpg_map, pagesize; |
| 422 | |
| 423 | bootpg = determine_mp_bootpg(&pagesize); |
| 424 | |
| 425 | /* |
| 426 | * pagesize is only 4K or 8K |
| 427 | * we only use the last 4K of boot page |
| 428 | * bootpg_map saves the address for the boot page |
| 429 | * 8K is used for the workaround of 3-way DDR interleaving |
| 430 | */ |
| 431 | |
| 432 | bootpg_map = bootpg; |
| 433 | |
| 434 | if (pagesize == 8192) |
| 435 | bootpg += 4096; /* use 2nd half */ |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 436 | |
Aaron Sierra | ec8863b | 2010-09-30 12:22:16 -0500 | [diff] [blame] | 437 | /* Some OSes expect secondary cores to be held in reset */ |
| 438 | if (hold_cores_in_reset(0)) |
| 439 | return; |
| 440 | |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 441 | /* |
| 442 | * Store the bootpg's cache-able half address for use by secondary |
| 443 | * CPU cores to continue to boot |
| 444 | */ |
| 445 | __bootpg_addr = (u32)virt_to_phys(&__second_half_boot_page); |
| 446 | |
| 447 | /* Store spin table's physical address for use by secondary cores */ |
| 448 | __spin_table_addr = (u32)get_spin_phys_addr(); |
| 449 | |
| 450 | /* flush bootpg it before copying invalidate any staled cacheline */ |
| 451 | flush_cache(bootpg, 4096); |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 452 | |
Kumar Gala | 8399e12 | 2009-09-03 08:41:31 -0500 | [diff] [blame] | 453 | /* look for the tlb covering the reset page, there better be one */ |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 454 | i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1); |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 455 | |
Kumar Gala | 8399e12 | 2009-09-03 08:41:31 -0500 | [diff] [blame] | 456 | /* we found a match */ |
| 457 | if (i != -1) { |
| 458 | /* map reset page to bootpg so we can copy code there */ |
| 459 | disable_tlb(i); |
Kumar Gala | 4d9190d | 2009-09-17 01:44:39 -0500 | [diff] [blame] | 460 | |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 461 | set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */ |
Kumar Gala | 4756ffa | 2009-11-17 20:21:20 -0600 | [diff] [blame] | 462 | MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */ |
Kumar Gala | 8399e12 | 2009-09-03 08:41:31 -0500 | [diff] [blame] | 463 | 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */ |
| 464 | |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 465 | memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096); |
| 466 | |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 467 | plat_mp_up(bootpg_map, pagesize); |
Kumar Gala | 8399e12 | 2009-09-03 08:41:31 -0500 | [diff] [blame] | 468 | } else { |
| 469 | puts("WARNING: No reset page TLB. " |
| 470 | "Skipping secondary core setup\n"); |
| 471 | } |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 472 | } |