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