mp.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright 2008-2009 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 "mp.h"
  29. DECLARE_GLOBAL_DATA_PTR;
  30. u32 get_my_id()
  31. {
  32. return mfspr(SPRN_PIR);
  33. }
  34. int cpu_reset(int nr)
  35. {
  36. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
  37. out_be32(&pic->pir, 1 << nr);
  38. /* the dummy read works around an errata on early 85xx MP PICs */
  39. (void)in_be32(&pic->pir);
  40. out_be32(&pic->pir, 0x0);
  41. return 0;
  42. }
  43. int cpu_status(int nr)
  44. {
  45. u32 *table, id = get_my_id();
  46. if (nr == id) {
  47. table = (u32 *)get_spin_addr();
  48. printf("table base @ 0x%p\n", table);
  49. } else {
  50. table = (u32 *)get_spin_addr() + nr * NUM_BOOT_ENTRY;
  51. printf("Running on cpu %d\n", id);
  52. printf("\n");
  53. printf("table @ 0x%p\n", table);
  54. printf(" addr - 0x%08x\n", table[BOOT_ENTRY_ADDR_LOWER]);
  55. printf(" pir - 0x%08x\n", table[BOOT_ENTRY_PIR]);
  56. printf(" r3 - 0x%08x\n", table[BOOT_ENTRY_R3_LOWER]);
  57. printf(" r6 - 0x%08x\n", table[BOOT_ENTRY_R6_LOWER]);
  58. }
  59. return 0;
  60. }
  61. static u8 boot_entry_map[4] = {
  62. 0,
  63. BOOT_ENTRY_PIR,
  64. BOOT_ENTRY_R3_LOWER,
  65. BOOT_ENTRY_R6_LOWER,
  66. };
  67. int cpu_release(int nr, int argc, char *argv[])
  68. {
  69. u32 i, val, *table = (u32 *)get_spin_addr() + nr * NUM_BOOT_ENTRY;
  70. u64 boot_addr;
  71. if (nr == get_my_id()) {
  72. printf("Invalid to release the boot core.\n\n");
  73. return 1;
  74. }
  75. if (argc != 4) {
  76. printf("Invalid number of arguments to release.\n\n");
  77. return 1;
  78. }
  79. #ifdef CONFIG_SYS_64BIT_STRTOUL
  80. boot_addr = simple_strtoull(argv[0], NULL, 16);
  81. #else
  82. boot_addr = simple_strtoul(argv[0], NULL, 16);
  83. #endif
  84. /* handle pir, r3, r6 */
  85. for (i = 1; i < 4; i++) {
  86. if (argv[i][0] != '-') {
  87. u8 entry = boot_entry_map[i];
  88. val = simple_strtoul(argv[i], NULL, 16);
  89. table[entry] = val;
  90. }
  91. }
  92. table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
  93. /* ensure all table updates complete before final address write */
  94. eieio();
  95. table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);
  96. return 0;
  97. }
  98. u32 determine_mp_bootpg(void)
  99. {
  100. /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
  101. if ((u64)gd->ram_size > 0xfffff000)
  102. return (0xfffff000);
  103. return (gd->ram_size - 4096);
  104. }
  105. ulong get_spin_addr(void)
  106. {
  107. extern ulong __secondary_start_page;
  108. extern ulong __spin_table;
  109. ulong addr =
  110. (ulong)&__spin_table - (ulong)&__secondary_start_page;
  111. addr += 0xfffff000;
  112. return addr;
  113. }
  114. static void pq3_mp_up(unsigned long bootpg)
  115. {
  116. u32 up, cpu_up_mask, whoami;
  117. u32 *table = (u32 *)get_spin_addr();
  118. volatile u32 bpcr;
  119. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  120. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  121. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
  122. u32 devdisr;
  123. int timeout = 10;
  124. whoami = in_be32(&pic->whoami);
  125. out_be32(&ecm->bptr, 0x80000000 | (bootpg >> 12));
  126. /* disable time base at the platform */
  127. devdisr = in_be32(&gur->devdisr);
  128. if (whoami)
  129. devdisr |= MPC85xx_DEVDISR_TB0;
  130. else
  131. devdisr |= MPC85xx_DEVDISR_TB1;
  132. out_be32(&gur->devdisr, devdisr);
  133. /* release the hounds */
  134. up = ((1 << cpu_numcores()) - 1);
  135. bpcr = in_be32(&ecm->eebpcr);
  136. bpcr |= (up << 24);
  137. out_be32(&ecm->eebpcr, bpcr);
  138. asm("sync; isync; msync");
  139. cpu_up_mask = 1 << whoami;
  140. /* wait for everyone */
  141. while (timeout) {
  142. int i;
  143. for (i = 0; i < cpu_numcores(); i++) {
  144. if (table[i * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER])
  145. cpu_up_mask |= (1 << i);
  146. };
  147. if ((cpu_up_mask & up) == up)
  148. break;
  149. udelay(100);
  150. timeout--;
  151. }
  152. if (timeout == 0)
  153. printf("CPU up timeout. CPU up mask is %x should be %x\n",
  154. cpu_up_mask, up);
  155. /* enable time base at the platform */
  156. if (whoami)
  157. devdisr |= MPC85xx_DEVDISR_TB1;
  158. else
  159. devdisr |= MPC85xx_DEVDISR_TB0;
  160. out_be32(&gur->devdisr, devdisr);
  161. mtspr(SPRN_TBWU, 0);
  162. mtspr(SPRN_TBWL, 0);
  163. devdisr &= ~(MPC85xx_DEVDISR_TB0 | MPC85xx_DEVDISR_TB1);
  164. out_be32(&gur->devdisr, devdisr);
  165. }
  166. void cpu_mp_lmb_reserve(struct lmb *lmb)
  167. {
  168. u32 bootpg = determine_mp_bootpg();
  169. lmb_reserve(lmb, bootpg, 4096);
  170. }
  171. void setup_mp(void)
  172. {
  173. extern ulong __secondary_start_page;
  174. ulong fixup = (ulong)&__secondary_start_page;
  175. u32 bootpg = determine_mp_bootpg();
  176. /* look for the tlb covering the reset page, there better be one */
  177. int i = find_tlb_idx((void *)0xfffff000, 1);
  178. /* we found a match */
  179. if (i != -1) {
  180. /* map reset page to bootpg so we can copy code there */
  181. disable_tlb(i);
  182. set_tlb(1, 0xfffff000, bootpg, /* tlb, epn, rpn */
  183. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_M, /* perms, wimge */
  184. 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
  185. memcpy((void *)0xfffff000, (void *)fixup, 4096);
  186. flush_cache(0xfffff000, 4096);
  187. disable_tlb(i);
  188. /* setup reset page back to 1:1, we'll use HW boot translation
  189. * to map this where we want
  190. */
  191. set_tlb(1, 0xfffff000, 0xfffff000, /* tlb, epn, rpn */
  192. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I, /* perms, wimge */
  193. 0, i, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
  194. pq3_mp_up(bootpg);
  195. } else {
  196. puts("WARNING: No reset page TLB. "
  197. "Skipping secondary core setup\n");
  198. }
  199. }