mp.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. /*
  2. * Copyright 2008-2011 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <asm/processor.h>
  24. #include <ioports.h>
  25. #include <lmb.h>
  26. #include <asm/io.h>
  27. #include <asm/mmu.h>
  28. #include <asm/fsl_law.h>
  29. #include <asm/fsl_ddr_sdram.h>
  30. #include "mp.h"
  31. DECLARE_GLOBAL_DATA_PTR;
  32. u32 fsl_ddr_get_intl3r(void);
  33. extern u32 __spin_table[];
  34. u32 get_my_id()
  35. {
  36. return mfspr(SPRN_PIR);
  37. }
  38. /*
  39. * Determine if U-Boot should keep secondary cores in reset, or let them out
  40. * of reset and hold them in a spinloop
  41. */
  42. int hold_cores_in_reset(int verbose)
  43. {
  44. const char *s = getenv("mp_holdoff");
  45. /* Default to no, overriden by 'y', 'yes', 'Y', 'Yes', or '1' */
  46. if (s && (*s == 'y' || *s == 'Y' || *s == '1')) {
  47. if (verbose) {
  48. puts("Secondary cores are being held in reset.\n");
  49. puts("See 'mp_holdoff' environment variable\n");
  50. }
  51. return 1;
  52. }
  53. return 0;
  54. }
  55. int cpu_reset(int nr)
  56. {
  57. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  58. out_be32(&pic->pir, 1 << nr);
  59. /* the dummy read works around an errata on early 85xx MP PICs */
  60. (void)in_be32(&pic->pir);
  61. out_be32(&pic->pir, 0x0);
  62. return 0;
  63. }
  64. int cpu_status(int nr)
  65. {
  66. u32 *table, id = get_my_id();
  67. if (hold_cores_in_reset(1))
  68. return 0;
  69. if (nr == id) {
  70. table = (u32 *)&__spin_table;
  71. printf("table base @ 0x%p\n", table);
  72. } else {
  73. table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
  74. printf("Running on cpu %d\n", id);
  75. printf("\n");
  76. printf("table @ 0x%p\n", table);
  77. printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
  78. printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
  79. printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
  80. }
  81. return 0;
  82. }
  83. #ifdef CONFIG_FSL_CORENET
  84. int cpu_disable(int nr)
  85. {
  86. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  87. setbits_be32(&gur->coredisrl, 1 << nr);
  88. return 0;
  89. }
  90. int is_core_disabled(int nr) {
  91. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  92. u32 coredisrl = in_be32(&gur->coredisrl);
  93. return (coredisrl & (1 << nr));
  94. }
  95. #else
  96. int cpu_disable(int nr)
  97. {
  98. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  99. switch (nr) {
  100. case 0:
  101. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU0);
  102. break;
  103. case 1:
  104. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU1);
  105. break;
  106. default:
  107. printf("Invalid cpu number for disable %d\n", nr);
  108. return 1;
  109. }
  110. return 0;
  111. }
  112. int is_core_disabled(int nr) {
  113. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  114. u32 devdisr = in_be32(&gur->devdisr);
  115. switch (nr) {
  116. case 0:
  117. return (devdisr & MPC85xx_DEVDISR_CPU0);
  118. case 1:
  119. return (devdisr & MPC85xx_DEVDISR_CPU1);
  120. default:
  121. printf("Invalid cpu number for disable %d\n", nr);
  122. }
  123. return 0;
  124. }
  125. #endif
  126. static u8 boot_entry_map[4] = {
  127. 0,
  128. BOOT_ENTRY_PIR,
  129. BOOT_ENTRY_R3_LOWER,
  130. };
  131. int cpu_release(int nr, int argc, char * const argv[])
  132. {
  133. u32 i, val, *table = (u32 *)&__spin_table + nr * NUM_BOOT_ENTRY;
  134. u64 boot_addr;
  135. if (hold_cores_in_reset(1))
  136. return 0;
  137. if (nr == get_my_id()) {
  138. printf("Invalid to release the boot core.\n\n");
  139. return 1;
  140. }
  141. if (argc != 4) {
  142. printf("Invalid number of arguments to release.\n\n");
  143. return 1;
  144. }
  145. boot_addr = simple_strtoull(argv[0], NULL, 16);
  146. /* handle pir, r3 */
  147. for (i = 1; i < 3; i++) {
  148. if (argv[i][0] != '-') {
  149. u8 entry = boot_entry_map[i];
  150. val = simple_strtoul(argv[i], NULL, 16);
  151. table[entry] = val;
  152. }
  153. }
  154. table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
  155. /* ensure all table updates complete before final address write */
  156. eieio();
  157. table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
  158. return 0;
  159. }
  160. u32 determine_mp_bootpg(unsigned int *pagesize)
  161. {
  162. u32 bootpg;
  163. #ifdef CONFIG_SYS_FSL_ERRATUM_A004468
  164. u32 svr = get_svr();
  165. u32 granule_size, check;
  166. struct law_entry e;
  167. #endif
  168. /* use last 4K of mapped memory */
  169. bootpg = ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
  170. CONFIG_MAX_MEM_MAPPED : gd->ram_size) +
  171. CONFIG_SYS_SDRAM_BASE - 4096;
  172. if (pagesize)
  173. *pagesize = 4096;
  174. #ifdef CONFIG_SYS_FSL_ERRATUM_A004468
  175. /*
  176. * Erratum A004468 has two parts. The 3-way interleaving applies to T4240,
  177. * to be fixed in rev 2.0. The 2-way interleaving applies to many SoCs. But
  178. * the way boot page chosen in u-boot avoids hitting this erratum. So only
  179. * thw workaround for 3-way interleaving is needed.
  180. *
  181. * To make sure boot page translation works with 3-Way DDR interleaving
  182. * enforce a check for the following constrains
  183. * 8K granule size requires BRSIZE=8K and
  184. * bootpg >> log2(BRSIZE) %3 == 1
  185. * 4K and 1K granule size requires BRSIZE=4K and
  186. * bootpg >> log2(BRSIZE) %3 == 0
  187. */
  188. if (SVR_SOC_VER(svr) == SVR_T4240 && SVR_MAJ(svr) < 2) {
  189. e = find_law(bootpg);
  190. switch (e.trgt_id) {
  191. case LAW_TRGT_IF_DDR_INTLV_123:
  192. granule_size = fsl_ddr_get_intl3r() & 0x1f;
  193. if (granule_size == FSL_DDR_3WAY_8KB_INTERLEAVING) {
  194. if (pagesize)
  195. *pagesize = 8192;
  196. bootpg &= 0xffffe000; /* align to 8KB */
  197. check = bootpg >> 13;
  198. while ((check % 3) != 1)
  199. check--;
  200. bootpg = check << 13;
  201. debug("Boot page (8K) at 0x%08x\n", bootpg);
  202. break;
  203. } else {
  204. bootpg &= 0xfffff000; /* align to 4KB */
  205. check = bootpg >> 12;
  206. while ((check % 3) != 0)
  207. check--;
  208. bootpg = check << 12;
  209. debug("Boot page (4K) at 0x%08x\n", bootpg);
  210. }
  211. break;
  212. default:
  213. break;
  214. }
  215. }
  216. #endif /* CONFIG_SYS_FSL_ERRATUM_A004468 */
  217. return bootpg;
  218. }
  219. phys_addr_t get_spin_phys_addr(void)
  220. {
  221. return virt_to_phys(&__spin_table);
  222. }
  223. #ifdef CONFIG_FSL_CORENET
  224. static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
  225. {
  226. u32 cpu_up_mask, whoami, brsize = LAW_SIZE_4K;
  227. u32 *table = (u32 *)&__spin_table;
  228. volatile ccsr_gur_t *gur;
  229. volatile ccsr_local_t *ccm;
  230. volatile ccsr_rcpm_t *rcpm;
  231. volatile ccsr_pic_t *pic;
  232. int timeout = 10;
  233. u32 mask = cpu_mask();
  234. struct law_entry e;
  235. gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  236. ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
  237. rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
  238. pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  239. whoami = in_be32(&pic->whoami);
  240. cpu_up_mask = 1 << whoami;
  241. out_be32(&ccm->bstrl, bootpg);
  242. e = find_law(bootpg);
  243. /* pagesize is only 4K or 8K */
  244. if (pagesize == 8192)
  245. brsize = LAW_SIZE_8K;
  246. out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | brsize);
  247. debug("BRSIZE is 0x%x\n", brsize);
  248. /* readback to sync write */
  249. in_be32(&ccm->bstrar);
  250. /* disable time base at the platform */
  251. out_be32(&rcpm->ctbenrl, cpu_up_mask);
  252. out_be32(&gur->brrl, mask);
  253. /* wait for everyone */
  254. while (timeout) {
  255. unsigned int i, cpu, nr_cpus = cpu_numcores();
  256. for_each_cpu(i, cpu, nr_cpus, mask) {
  257. if (table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
  258. cpu_up_mask |= (1 << cpu);
  259. }
  260. if ((cpu_up_mask & mask) == mask)
  261. break;
  262. udelay(100);
  263. timeout--;
  264. }
  265. if (timeout == 0)
  266. printf("CPU up timeout. CPU up mask is %x should be %x\n",
  267. cpu_up_mask, mask);
  268. /* enable time base at the platform */
  269. out_be32(&rcpm->ctbenrl, 0);
  270. /* readback to sync write */
  271. in_be32(&rcpm->ctbenrl);
  272. mtspr(SPRN_TBWU, 0);
  273. mtspr(SPRN_TBWL, 0);
  274. out_be32(&rcpm->ctbenrl, mask);
  275. #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
  276. /*
  277. * Disabling Boot Page Translation allows the memory region 0xfffff000
  278. * to 0xffffffff to be used normally. Leaving Boot Page Translation
  279. * enabled remaps 0xfffff000 to SDRAM which makes that memory region
  280. * unusable for normal operation but it does allow OSes to easily
  281. * reset a processor core to put it back into U-Boot's spinloop.
  282. */
  283. clrbits_be32(&ccm->bstrar, LAW_EN);
  284. #endif
  285. }
  286. #else
  287. static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
  288. {
  289. u32 up, cpu_up_mask, whoami;
  290. u32 *table = (u32 *)&__spin_table;
  291. volatile u32 bpcr;
  292. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  293. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  294. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  295. u32 devdisr;
  296. int timeout = 10;
  297. whoami = in_be32(&pic->whoami);
  298. out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
  299. /* disable time base at the platform */
  300. devdisr = in_be32(&gur->devdisr);
  301. if (whoami)
  302. devdisr |= MPC85xx_DEVDISR_TB0;
  303. else
  304. devdisr |= MPC85xx_DEVDISR_TB1;
  305. out_be32(&gur->devdisr, devdisr);
  306. /* release the hounds */
  307. up = ((1 << cpu_numcores()) - 1);
  308. bpcr = in_be32(&ecm->eebpcr);
  309. bpcr |= (up << 24);
  310. out_be32(&ecm->eebpcr, bpcr);
  311. asm("sync; isync; msync");
  312. cpu_up_mask = 1 << whoami;
  313. /* wait for everyone */
  314. while (timeout) {
  315. int i;
  316. for (i = 0; i < cpu_numcores(); i++) {
  317. if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
  318. cpu_up_mask |= (1 << i);
  319. };
  320. if ((cpu_up_mask & up) == up)
  321. break;
  322. udelay(100);
  323. timeout--;
  324. }
  325. if (timeout == 0)
  326. printf("CPU up timeout. CPU up mask is %x should be %x\n",
  327. cpu_up_mask, up);
  328. /* enable time base at the platform */
  329. if (whoami)
  330. devdisr |= MPC85xx_DEVDISR_TB1;
  331. else
  332. devdisr |= MPC85xx_DEVDISR_TB0;
  333. out_be32(&gur->devdisr, devdisr);
  334. /* readback to sync write */
  335. in_be32(&gur->devdisr);
  336. mtspr(SPRN_TBWU, 0);
  337. mtspr(SPRN_TBWL, 0);
  338. devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
  339. out_be32(&gur->devdisr, devdisr);
  340. #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
  341. /*
  342. * Disabling Boot Page Translation allows the memory region 0xfffff000
  343. * to 0xffffffff to be used normally. Leaving Boot Page Translation
  344. * enabled remaps 0xfffff000 to SDRAM which makes that memory region
  345. * unusable for normal operation but it does allow OSes to easily
  346. * reset a processor core to put it back into U-Boot's spinloop.
  347. */
  348. clrbits_be32(&ecm->bptr, 0x80000000);
  349. #endif
  350. }
  351. #endif
  352. void cpu_mp_lmb_reserve(struct lmb *lmb)
  353. {
  354. u32 bootpg = determine_mp_bootpg(NULL);
  355. lmb_reserve(lmb, bootpg, 4096);
  356. }
  357. void setup_mp(void)
  358. {
  359. extern u32 __secondary_start_page;
  360. extern u32 __bootpg_addr, __spin_table_addr, __second_half_boot_page;
  361. int i;
  362. ulong fixup = (u32)&__secondary_start_page;
  363. u32 bootpg, bootpg_map, pagesize;
  364. bootpg = determine_mp_bootpg(&pagesize);
  365. /*
  366. * pagesize is only 4K or 8K
  367. * we only use the last 4K of boot page
  368. * bootpg_map saves the address for the boot page
  369. * 8K is used for the workaround of 3-way DDR interleaving
  370. */
  371. bootpg_map = bootpg;
  372. if (pagesize == 8192)
  373. bootpg += 4096; /* use 2nd half */
  374. /* Some OSes expect secondary cores to be held in reset */
  375. if (hold_cores_in_reset(0))
  376. return;
  377. /*
  378. * Store the bootpg's cache-able half address for use by secondary
  379. * CPU cores to continue to boot
  380. */
  381. __bootpg_addr = (u32)virt_to_phys(&__second_half_boot_page);
  382. /* Store spin table's physical address for use by secondary cores */
  383. __spin_table_addr = (u32)get_spin_phys_addr();
  384. /* flush bootpg it before copying invalidate any staled cacheline */
  385. flush_cache(bootpg, 4096);
  386. /* look for the tlb covering the reset page, there better be one */
  387. i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
  388. /* we found a match */
  389. if (i != -1) {
  390. /* map reset page to bootpg so we can copy code there */
  391. disable_tlb(i);
  392. set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
  393. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
  394. 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
  395. memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
  396. plat_mp_up(bootpg_map, pagesize);
  397. } else {
  398. puts("WARNING: No reset page TLB. "
  399. "Skipping secondary core setup\n");
  400. }
  401. }