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