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