mp.c 12 KB

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