mp.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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. u32 get_my_id()
  34. {
  35. return mfspr(SPRN_PIR);
  36. }
  37. /*
  38. * Determine if U-Boot should keep secondary cores in reset, or let them out
  39. * of reset and hold them in a spinloop
  40. */
  41. int hold_cores_in_reset(int verbose)
  42. {
  43. const char *s = getenv("mp_holdoff");
  44. /* Default to no, overriden by 'y', 'yes', 'Y', 'Yes', or '1' */
  45. if (s && (*s == 'y' || *s == 'Y' || *s == '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 *)get_spin_virt_addr();
  70. printf("table base @ 0x%p\n", table);
  71. } else {
  72. table = (u32 *)get_spin_virt_addr() + 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 *)get_spin_virt_addr() + 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. /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
  168. if ((u64)gd->ram_size > 0xfffff000)
  169. bootpg = 0xfffff000;
  170. else
  171. bootpg = gd->ram_size - 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. ulong get_spin_phys_addr(void)
  220. {
  221. extern ulong __secondary_start_page;
  222. extern ulong __spin_table;
  223. return (determine_mp_bootpg() +
  224. (ulong)&__spin_table - (ulong)&__secondary_start_page);
  225. }
  226. ulong get_spin_virt_addr(void)
  227. {
  228. extern ulong __secondary_start_page;
  229. extern ulong __spin_table;
  230. return (CONFIG_BPTR_VIRT_ADDR +
  231. (ulong)&__spin_table - (ulong)&__secondary_start_page);
  232. }
  233. #ifdef CONFIG_FSL_CORENET
  234. static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
  235. {
  236. u32 cpu_up_mask, whoami, brsize = LAW_SIZE_4K;
  237. u32 *table = (u32 *)get_spin_virt_addr();
  238. volatile ccsr_gur_t *gur;
  239. volatile ccsr_local_t *ccm;
  240. volatile ccsr_rcpm_t *rcpm;
  241. volatile ccsr_pic_t *pic;
  242. int timeout = 10;
  243. u32 mask = cpu_mask();
  244. struct law_entry e;
  245. gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  246. ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
  247. rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
  248. pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  249. whoami = in_be32(&pic->whoami);
  250. cpu_up_mask = 1 << whoami;
  251. out_be32(&ccm->bstrl, bootpg);
  252. e = find_law(bootpg);
  253. /* pagesize is only 4K or 8K */
  254. if (pagesize == 8192)
  255. brsize = LAW_SIZE_8K;
  256. out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | brsize);
  257. debug("BRSIZE is 0x%x\n", brsize);
  258. /* readback to sync write */
  259. in_be32(&ccm->bstrar);
  260. /* disable time base at the platform */
  261. out_be32(&rcpm->ctbenrl, cpu_up_mask);
  262. out_be32(&gur->brrl, mask);
  263. /* wait for everyone */
  264. while (timeout) {
  265. unsigned int i, cpu, nr_cpus = cpu_numcores();
  266. for_each_cpu(i, cpu, nr_cpus, mask) {
  267. if (table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
  268. cpu_up_mask |= (1 << cpu);
  269. }
  270. if ((cpu_up_mask & mask) == mask)
  271. break;
  272. udelay(100);
  273. timeout--;
  274. }
  275. if (timeout == 0)
  276. printf("CPU up timeout. CPU up mask is %x should be %x\n",
  277. cpu_up_mask, mask);
  278. /* enable time base at the platform */
  279. out_be32(&rcpm->ctbenrl, 0);
  280. /* readback to sync write */
  281. in_be32(&rcpm->ctbenrl);
  282. mtspr(SPRN_TBWU, 0);
  283. mtspr(SPRN_TBWL, 0);
  284. out_be32(&rcpm->ctbenrl, mask);
  285. #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
  286. /*
  287. * Disabling Boot Page Translation allows the memory region 0xfffff000
  288. * to 0xffffffff to be used normally. Leaving Boot Page Translation
  289. * enabled remaps 0xfffff000 to SDRAM which makes that memory region
  290. * unusable for normal operation but it does allow OSes to easily
  291. * reset a processor core to put it back into U-Boot's spinloop.
  292. */
  293. clrbits_be32(&ccm->bstrar, LAW_EN);
  294. #endif
  295. }
  296. #else
  297. static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
  298. {
  299. u32 up, cpu_up_mask, whoami;
  300. u32 *table = (u32 *)get_spin_virt_addr();
  301. volatile u32 bpcr;
  302. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  303. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  304. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  305. u32 devdisr;
  306. int timeout = 10;
  307. whoami = in_be32(&pic->whoami);
  308. out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
  309. /* disable time base at the platform */
  310. devdisr = in_be32(&gur->devdisr);
  311. if (whoami)
  312. devdisr |= MPC85xx_DEVDISR_TB0;
  313. else
  314. devdisr |= MPC85xx_DEVDISR_TB1;
  315. out_be32(&gur->devdisr, devdisr);
  316. /* release the hounds */
  317. up = ((1 << cpu_numcores()) - 1);
  318. bpcr = in_be32(&ecm->eebpcr);
  319. bpcr |= (up << 24);
  320. out_be32(&ecm->eebpcr, bpcr);
  321. asm("sync; isync; msync");
  322. cpu_up_mask = 1 << whoami;
  323. /* wait for everyone */
  324. while (timeout) {
  325. int i;
  326. for (i = 0; i < cpu_numcores(); i++) {
  327. if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
  328. cpu_up_mask |= (1 << i);
  329. };
  330. if ((cpu_up_mask & up) == up)
  331. break;
  332. udelay(100);
  333. timeout--;
  334. }
  335. if (timeout == 0)
  336. printf("CPU up timeout. CPU up mask is %x should be %x\n",
  337. cpu_up_mask, up);
  338. /* enable time base at the platform */
  339. if (whoami)
  340. devdisr |= MPC85xx_DEVDISR_TB1;
  341. else
  342. devdisr |= MPC85xx_DEVDISR_TB0;
  343. out_be32(&gur->devdisr, devdisr);
  344. /* readback to sync write */
  345. in_be32(&gur->devdisr);
  346. mtspr(SPRN_TBWU, 0);
  347. mtspr(SPRN_TBWL, 0);
  348. devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
  349. out_be32(&gur->devdisr, devdisr);
  350. #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
  351. /*
  352. * Disabling Boot Page Translation allows the memory region 0xfffff000
  353. * to 0xffffffff to be used normally. Leaving Boot Page Translation
  354. * enabled remaps 0xfffff000 to SDRAM which makes that memory region
  355. * unusable for normal operation but it does allow OSes to easily
  356. * reset a processor core to put it back into U-Boot's spinloop.
  357. */
  358. clrbits_be32(&ecm->bptr, 0x80000000);
  359. #endif
  360. }
  361. #endif
  362. void cpu_mp_lmb_reserve(struct lmb *lmb)
  363. {
  364. u32 bootpg = determine_mp_bootpg(NULL);
  365. lmb_reserve(lmb, bootpg, 4096);
  366. }
  367. void setup_mp(void)
  368. {
  369. extern ulong __secondary_start_page;
  370. extern ulong __bootpg_addr;
  371. ulong fixup = (ulong)&__secondary_start_page;
  372. u32 bootpg, bootpg_map, pagesize;
  373. bootpg = determine_mp_bootpg(&pagesize);
  374. /*
  375. * pagesize is only 4K or 8K
  376. * we only use the last 4K of boot page
  377. * bootpg_map saves the address for the boot page
  378. * 8K is used for the workaround of 3-way DDR interleaving
  379. */
  380. bootpg_map = bootpg;
  381. if (pagesize == 8192)
  382. bootpg += 4096; /* use 2nd half */
  383. /* Some OSes expect secondary cores to be held in reset */
  384. if (hold_cores_in_reset(0))
  385. return;
  386. /* Store the bootpg's SDRAM address for use by secondary CPU cores */
  387. __bootpg_addr = bootpg;
  388. /* look for the tlb covering the reset page, there better be one */
  389. int i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
  390. /* we found a match */
  391. if (i != -1) {
  392. /* map reset page to bootpg so we can copy code there */
  393. disable_tlb(i);
  394. set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
  395. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
  396. 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
  397. memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
  398. plat_mp_up(bootpg_map, pagesize);
  399. } else {
  400. puts("WARNING: No reset page TLB. "
  401. "Skipping secondary core setup\n");
  402. }
  403. }