mp.c 9.1 KB

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