mp.c 5.0 KB

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