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