mp.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
  78. printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
  79. printf(" r6 - 0x%08x\n", table[BOOT_ENTRY_R6_LOWER]);
  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. BOOT_ENTRY_R6_LOWER,
  131. };
  132. int cpu_release(int nr, int argc, char * const argv[])
  133. {
  134. u32 i, val, *table = (u32 *)get_spin_virt_addr() + 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, r6 */
  148. for (i = 1; i < 4; 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. /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
  170. if ((u64)gd->ram_size > 0xfffff000)
  171. bootpg = 0xfffff000;
  172. else
  173. bootpg = gd->ram_size - 4096;
  174. if (pagesize)
  175. *pagesize = 4096;
  176. #ifdef CONFIG_SYS_FSL_ERRATUM_A004468
  177. /*
  178. * Erratum A004468 has two parts. The 3-way interleaving applies to T4240,
  179. * to be fixed in rev 2.0. The 2-way interleaving applies to many SoCs. But
  180. * the way boot page chosen in u-boot avoids hitting this erratum. So only
  181. * thw workaround for 3-way interleaving is needed.
  182. *
  183. * To make sure boot page translation works with 3-Way DDR interleaving
  184. * enforce a check for the following constrains
  185. * 8K granule size requires BRSIZE=8K and
  186. * bootpg >> log2(BRSIZE) %3 == 1
  187. * 4K and 1K granule size requires BRSIZE=4K and
  188. * bootpg >> log2(BRSIZE) %3 == 0
  189. */
  190. if (SVR_SOC_VER(svr) == SVR_T4240 && SVR_MAJ(svr) < 2) {
  191. e = find_law(bootpg);
  192. switch (e.trgt_id) {
  193. case LAW_TRGT_IF_DDR_INTLV_123:
  194. granule_size = fsl_ddr_get_intl3r() & 0x1f;
  195. if (granule_size == FSL_DDR_3WAY_8KB_INTERLEAVING) {
  196. if (pagesize)
  197. *pagesize = 8192;
  198. bootpg &= 0xffffe000; /* align to 8KB */
  199. check = bootpg >> 13;
  200. while ((check % 3) != 1)
  201. check--;
  202. bootpg = check << 13;
  203. debug("Boot page (8K) at 0x%08x\n", bootpg);
  204. break;
  205. } else {
  206. bootpg &= 0xfffff000; /* align to 4KB */
  207. check = bootpg >> 12;
  208. while ((check % 3) != 0)
  209. check--;
  210. bootpg = check << 12;
  211. debug("Boot page (4K) at 0x%08x\n", bootpg);
  212. }
  213. break;
  214. default:
  215. break;
  216. }
  217. }
  218. #endif /* CONFIG_SYS_FSL_ERRATUM_A004468 */
  219. return bootpg;
  220. }
  221. ulong get_spin_phys_addr(void)
  222. {
  223. extern ulong __secondary_start_page;
  224. extern ulong __spin_table;
  225. return (determine_mp_bootpg() +
  226. (ulong)&__spin_table - (ulong)&__secondary_start_page);
  227. }
  228. ulong get_spin_virt_addr(void)
  229. {
  230. extern ulong __secondary_start_page;
  231. extern ulong __spin_table;
  232. return (CONFIG_BPTR_VIRT_ADDR +
  233. (ulong)&__spin_table - (ulong)&__secondary_start_page);
  234. }
  235. #ifdef CONFIG_FSL_CORENET
  236. static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
  237. {
  238. u32 cpu_up_mask, whoami, brsize = LAW_SIZE_4K;
  239. u32 *table = (u32 *)get_spin_virt_addr();
  240. volatile ccsr_gur_t *gur;
  241. volatile ccsr_local_t *ccm;
  242. volatile ccsr_rcpm_t *rcpm;
  243. volatile ccsr_pic_t *pic;
  244. int timeout = 10;
  245. u32 mask = cpu_mask();
  246. struct law_entry e;
  247. gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  248. ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
  249. rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
  250. pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  251. whoami = in_be32(&pic->whoami);
  252. cpu_up_mask = 1 << whoami;
  253. out_be32(&ccm->bstrl, bootpg);
  254. e = find_law(bootpg);
  255. /* pagesize is only 4K or 8K */
  256. if (pagesize == 8192)
  257. brsize = LAW_SIZE_8K;
  258. out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | brsize);
  259. debug("BRSIZE is 0x%x\n", brsize);
  260. /* readback to sync write */
  261. in_be32(&ccm->bstrar);
  262. /* disable time base at the platform */
  263. out_be32(&rcpm->ctbenrl, cpu_up_mask);
  264. out_be32(&gur->brrl, mask);
  265. /* wait for everyone */
  266. while (timeout) {
  267. unsigned int i, cpu, nr_cpus = cpu_numcores();
  268. for_each_cpu(i, cpu, nr_cpus, mask) {
  269. if (table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
  270. cpu_up_mask |= (1 << cpu);
  271. }
  272. if ((cpu_up_mask & mask) == mask)
  273. break;
  274. udelay(100);
  275. timeout--;
  276. }
  277. if (timeout == 0)
  278. printf("CPU up timeout. CPU up mask is %x should be %x\n",
  279. cpu_up_mask, mask);
  280. /* enable time base at the platform */
  281. out_be32(&rcpm->ctbenrl, 0);
  282. /* readback to sync write */
  283. in_be32(&rcpm->ctbenrl);
  284. mtspr(SPRN_TBWU, 0);
  285. mtspr(SPRN_TBWL, 0);
  286. out_be32(&rcpm->ctbenrl, mask);
  287. #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
  288. /*
  289. * Disabling Boot Page Translation allows the memory region 0xfffff000
  290. * to 0xffffffff to be used normally. Leaving Boot Page Translation
  291. * enabled remaps 0xfffff000 to SDRAM which makes that memory region
  292. * unusable for normal operation but it does allow OSes to easily
  293. * reset a processor core to put it back into U-Boot's spinloop.
  294. */
  295. clrbits_be32(&ccm->bstrar, LAW_EN);
  296. #endif
  297. }
  298. #else
  299. static void plat_mp_up(unsigned long bootpg, unsigned int pagesize)
  300. {
  301. u32 up, cpu_up_mask, whoami;
  302. u32 *table = (u32 *)get_spin_virt_addr();
  303. volatile u32 bpcr;
  304. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  305. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  306. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  307. u32 devdisr;
  308. int timeout = 10;
  309. whoami = in_be32(&pic->whoami);
  310. out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
  311. /* disable time base at the platform */
  312. devdisr = in_be32(&gur->devdisr);
  313. if (whoami)
  314. devdisr |= MPC85xx_DEVDISR_TB0;
  315. else
  316. devdisr |= MPC85xx_DEVDISR_TB1;
  317. out_be32(&gur->devdisr, devdisr);
  318. /* release the hounds */
  319. up = ((1 << cpu_numcores()) - 1);
  320. bpcr = in_be32(&ecm->eebpcr);
  321. bpcr |= (up << 24);
  322. out_be32(&ecm->eebpcr, bpcr);
  323. asm("sync; isync; msync");
  324. cpu_up_mask = 1 << whoami;
  325. /* wait for everyone */
  326. while (timeout) {
  327. int i;
  328. for (i = 0; i < cpu_numcores(); i++) {
  329. if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
  330. cpu_up_mask |= (1 << i);
  331. };
  332. if ((cpu_up_mask & up) == up)
  333. break;
  334. udelay(100);
  335. timeout--;
  336. }
  337. if (timeout == 0)
  338. printf("CPU up timeout. CPU up mask is %x should be %x\n",
  339. cpu_up_mask, up);
  340. /* enable time base at the platform */
  341. if (whoami)
  342. devdisr |= MPC85xx_DEVDISR_TB1;
  343. else
  344. devdisr |= MPC85xx_DEVDISR_TB0;
  345. out_be32(&gur->devdisr, devdisr);
  346. /* readback to sync write */
  347. in_be32(&gur->devdisr);
  348. mtspr(SPRN_TBWU, 0);
  349. mtspr(SPRN_TBWL, 0);
  350. devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
  351. out_be32(&gur->devdisr, devdisr);
  352. #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
  353. /*
  354. * Disabling Boot Page Translation allows the memory region 0xfffff000
  355. * to 0xffffffff to be used normally. Leaving Boot Page Translation
  356. * enabled remaps 0xfffff000 to SDRAM which makes that memory region
  357. * unusable for normal operation but it does allow OSes to easily
  358. * reset a processor core to put it back into U-Boot's spinloop.
  359. */
  360. clrbits_be32(&ecm->bptr, 0x80000000);
  361. #endif
  362. }
  363. #endif
  364. void cpu_mp_lmb_reserve(struct lmb *lmb)
  365. {
  366. u32 bootpg = determine_mp_bootpg(NULL);
  367. lmb_reserve(lmb, bootpg, 4096);
  368. }
  369. void setup_mp(void)
  370. {
  371. extern ulong __secondary_start_page;
  372. extern ulong __bootpg_addr;
  373. ulong fixup = (ulong)&__secondary_start_page;
  374. u32 bootpg, bootpg_map, pagesize;
  375. bootpg = determine_mp_bootpg(&pagesize);
  376. /*
  377. * pagesize is only 4K or 8K
  378. * we only use the last 4K of boot page
  379. * bootpg_map saves the address for the boot page
  380. * 8K is used for the workaround of 3-way DDR interleaving
  381. */
  382. bootpg_map = bootpg;
  383. if (pagesize == 8192)
  384. bootpg += 4096; /* use 2nd half */
  385. /* Some OSes expect secondary cores to be held in reset */
  386. if (hold_cores_in_reset(0))
  387. return;
  388. /* Store the bootpg's SDRAM address for use by secondary CPU cores */
  389. __bootpg_addr = bootpg;
  390. /* look for the tlb covering the reset page, there better be one */
  391. int i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
  392. /* we found a match */
  393. if (i != -1) {
  394. /* map reset page to bootpg so we can copy code there */
  395. disable_tlb(i);
  396. set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
  397. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
  398. 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
  399. memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
  400. plat_mp_up(bootpg_map, pagesize);
  401. } else {
  402. puts("WARNING: No reset page TLB. "
  403. "Skipping secondary core setup\n");
  404. }
  405. }