mp.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 "mp.h"
  30. DECLARE_GLOBAL_DATA_PTR;
  31. u32 get_my_id()
  32. {
  33. return mfspr(SPRN_PIR);
  34. }
  35. /*
  36. * Determine if U-Boot should keep secondary cores in reset, or let them out
  37. * of reset and hold them in a spinloop
  38. */
  39. int hold_cores_in_reset(int verbose)
  40. {
  41. const char *s = getenv("mp_holdoff");
  42. /* Default to no, overriden by 'y', 'yes', 'Y', 'Yes', or '1' */
  43. if (s && (*s == 'y' || *s == 'Y' || *s == '1')) {
  44. if (verbose) {
  45. puts("Secondary cores are being held in reset.\n");
  46. puts("See 'mp_holdoff' environment variable\n");
  47. }
  48. return 1;
  49. }
  50. return 0;
  51. }
  52. int cpu_reset(int nr)
  53. {
  54. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  55. out_be32(&pic->pir, 1 << nr);
  56. /* the dummy read works around an errata on early 85xx MP PICs */
  57. (void)in_be32(&pic->pir);
  58. out_be32(&pic->pir, 0x0);
  59. return 0;
  60. }
  61. int cpu_status(int nr)
  62. {
  63. u32 *table, id = get_my_id();
  64. if (hold_cores_in_reset(1))
  65. return 0;
  66. if (nr == id) {
  67. table = (u32 *)get_spin_virt_addr();
  68. printf("table base @ 0x%p\n", table);
  69. } else {
  70. table = (u32 *)get_spin_virt_addr() + nr * NUM_BOOT_ENTRY;
  71. printf("Running on cpu %d\n", id);
  72. printf("\n");
  73. printf("table @ 0x%p\n", table);
  74. printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
  75. printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
  76. printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
  77. printf(" r6 - 0x%08x\n", table[BOOT_ENTRY_R6_LOWER]);
  78. }
  79. return 0;
  80. }
  81. #ifdef CONFIG_FSL_CORENET
  82. int cpu_disable(int nr)
  83. {
  84. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  85. setbits_be32(&gur->coredisrl, 1 << nr);
  86. return 0;
  87. }
  88. int is_core_disabled(int nr) {
  89. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  90. u32 coredisrl = in_be32(&gur->coredisrl);
  91. return (coredisrl & (1 << nr));
  92. }
  93. #else
  94. int cpu_disable(int nr)
  95. {
  96. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  97. switch (nr) {
  98. case 0:
  99. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU0);
  100. break;
  101. case 1:
  102. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_CPU1);
  103. break;
  104. default:
  105. printf("Invalid cpu number for disable %d\n", nr);
  106. return 1;
  107. }
  108. return 0;
  109. }
  110. int is_core_disabled(int nr) {
  111. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  112. u32 devdisr = in_be32(&gur->devdisr);
  113. switch (nr) {
  114. case 0:
  115. return (devdisr & MPC85xx_DEVDISR_CPU0);
  116. case 1:
  117. return (devdisr & MPC85xx_DEVDISR_CPU1);
  118. default:
  119. printf("Invalid cpu number for disable %d\n", nr);
  120. }
  121. return 0;
  122. }
  123. #endif
  124. static u8 boot_entry_map[4] = {
  125. 0,
  126. BOOT_ENTRY_PIR,
  127. BOOT_ENTRY_R3_LOWER,
  128. BOOT_ENTRY_R6_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, r6 */
  146. for (i = 1; i < 4; 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(void)
  160. {
  161. /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
  162. if ((u64)gd->ram_size > 0xfffff000)
  163. return (0xfffff000);
  164. return (gd->ram_size - 4096);
  165. }
  166. ulong get_spin_phys_addr(void)
  167. {
  168. extern ulong __secondary_start_page;
  169. extern ulong __spin_table;
  170. return (determine_mp_bootpg() +
  171. (ulong)&__spin_table - (ulong)&__secondary_start_page);
  172. }
  173. ulong get_spin_virt_addr(void)
  174. {
  175. extern ulong __secondary_start_page;
  176. extern ulong __spin_table;
  177. return (CONFIG_BPTR_VIRT_ADDR +
  178. (ulong)&__spin_table - (ulong)&__secondary_start_page);
  179. }
  180. #ifdef CONFIG_FSL_CORENET
  181. static void plat_mp_up(unsigned long bootpg)
  182. {
  183. u32 cpu_up_mask, whoami;
  184. u32 *table = (u32 *)get_spin_virt_addr();
  185. volatile ccsr_gur_t *gur;
  186. volatile ccsr_local_t *ccm;
  187. volatile ccsr_rcpm_t *rcpm;
  188. volatile ccsr_pic_t *pic;
  189. int timeout = 10;
  190. u32 mask = cpu_mask();
  191. struct law_entry e;
  192. gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  193. ccm = (void *)(CONFIG_SYS_FSL_CORENET_CCM_ADDR);
  194. rcpm = (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
  195. pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  196. whoami = in_be32(&pic->whoami);
  197. cpu_up_mask = 1 << whoami;
  198. out_be32(&ccm->bstrl, bootpg);
  199. e = find_law(bootpg);
  200. out_be32(&ccm->bstrar, LAW_EN | e.trgt_id << 20 | LAW_SIZE_4K);
  201. /* readback to sync write */
  202. in_be32(&ccm->bstrar);
  203. /* disable time base at the platform */
  204. out_be32(&rcpm->ctbenrl, cpu_up_mask);
  205. out_be32(&gur->brrl, mask);
  206. /* wait for everyone */
  207. while (timeout) {
  208. unsigned int i, cpu, nr_cpus = cpu_numcores();
  209. for_each_cpu(i, cpu, nr_cpus, mask) {
  210. if (table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
  211. cpu_up_mask |= (1 << cpu);
  212. }
  213. if ((cpu_up_mask & mask) == mask)
  214. break;
  215. udelay(100);
  216. timeout--;
  217. }
  218. if (timeout == 0)
  219. printf("CPU up timeout. CPU up mask is %x should be %x\n",
  220. cpu_up_mask, mask);
  221. /* enable time base at the platform */
  222. out_be32(&rcpm->ctbenrl, 0);
  223. /* readback to sync write */
  224. in_be32(&rcpm->ctbenrl);
  225. mtspr(SPRN_TBWU, 0);
  226. mtspr(SPRN_TBWL, 0);
  227. out_be32(&rcpm->ctbenrl, mask);
  228. #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
  229. /*
  230. * Disabling Boot Page Translation allows the memory region 0xfffff000
  231. * to 0xffffffff to be used normally. Leaving Boot Page Translation
  232. * enabled remaps 0xfffff000 to SDRAM which makes that memory region
  233. * unusable for normal operation but it does allow OSes to easily
  234. * reset a processor core to put it back into U-Boot's spinloop.
  235. */
  236. clrbits_be32(&ccm->bstrar, LAW_EN);
  237. #endif
  238. }
  239. #else
  240. static void plat_mp_up(unsigned long bootpg)
  241. {
  242. u32 up, cpu_up_mask, whoami;
  243. u32 *table = (u32 *)get_spin_virt_addr();
  244. volatile u32 bpcr;
  245. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  246. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  247. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  248. u32 devdisr;
  249. int timeout = 10;
  250. whoami = in_be32(&pic->whoami);
  251. out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
  252. /* disable time base at the platform */
  253. devdisr = in_be32(&gur->devdisr);
  254. if (whoami)
  255. devdisr |= MPC85xx_DEVDISR_TB0;
  256. else
  257. devdisr |= MPC85xx_DEVDISR_TB1;
  258. out_be32(&gur->devdisr, devdisr);
  259. /* release the hounds */
  260. up = ((1 << cpu_numcores()) - 1);
  261. bpcr = in_be32(&ecm->eebpcr);
  262. bpcr |= (up << 24);
  263. out_be32(&ecm->eebpcr, bpcr);
  264. asm("sync; isync; msync");
  265. cpu_up_mask = 1 << whoami;
  266. /* wait for everyone */
  267. while (timeout) {
  268. int i;
  269. for (i = 0; i < cpu_numcores(); i++) {
  270. if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
  271. cpu_up_mask |= (1 << i);
  272. };
  273. if ((cpu_up_mask & up) == up)
  274. break;
  275. udelay(100);
  276. timeout--;
  277. }
  278. if (timeout == 0)
  279. printf("CPU up timeout. CPU up mask is %x should be %x\n",
  280. cpu_up_mask, up);
  281. /* enable time base at the platform */
  282. if (whoami)
  283. devdisr |= MPC85xx_DEVDISR_TB1;
  284. else
  285. devdisr |= MPC85xx_DEVDISR_TB0;
  286. out_be32(&gur->devdisr, devdisr);
  287. /* readback to sync write */
  288. in_be32(&gur->devdisr);
  289. mtspr(SPRN_TBWU, 0);
  290. mtspr(SPRN_TBWL, 0);
  291. devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
  292. out_be32(&gur->devdisr, devdisr);
  293. #ifdef CONFIG_MPC8xxx_DISABLE_BPTR
  294. /*
  295. * Disabling Boot Page Translation allows the memory region 0xfffff000
  296. * to 0xffffffff to be used normally. Leaving Boot Page Translation
  297. * enabled remaps 0xfffff000 to SDRAM which makes that memory region
  298. * unusable for normal operation but it does allow OSes to easily
  299. * reset a processor core to put it back into U-Boot's spinloop.
  300. */
  301. clrbits_be32(&ecm->bptr, 0x80000000);
  302. #endif
  303. }
  304. #endif
  305. void cpu_mp_lmb_reserve(struct lmb *lmb)
  306. {
  307. u32 bootpg = determine_mp_bootpg();
  308. lmb_reserve(lmb, bootpg, 4096);
  309. }
  310. void setup_mp(void)
  311. {
  312. extern ulong __secondary_start_page;
  313. extern ulong __bootpg_addr;
  314. ulong fixup = (ulong)&__secondary_start_page;
  315. u32 bootpg = determine_mp_bootpg();
  316. /* Some OSes expect secondary cores to be held in reset */
  317. if (hold_cores_in_reset(0))
  318. return;
  319. /* Store the bootpg's SDRAM address for use by secondary CPU cores */
  320. __bootpg_addr = bootpg;
  321. /* look for the tlb covering the reset page, there better be one */
  322. int i = find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1);
  323. /* we found a match */
  324. if (i != -1) {
  325. /* map reset page to bootpg so we can copy code there */
  326. disable_tlb(i);
  327. set_tlb(1, CONFIG_BPTR_VIRT_ADDR, bootpg, /* tlb, epn, rpn */
  328. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
  329. 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
  330. memcpy((void *)CONFIG_BPTR_VIRT_ADDR, (void *)fixup, 4096);
  331. plat_mp_up(bootpg);
  332. } else {
  333. puts("WARNING: No reset page TLB. "
  334. "Skipping secondary core setup\n");
  335. }
  336. }