mp.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Copyright 2014-2015 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/system.h>
  9. #include <asm/arch/mp.h>
  10. #include <asm/arch/soc.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. void *get_spin_tbl_addr(void)
  13. {
  14. return &__spin_table;
  15. }
  16. phys_addr_t determine_mp_bootpg(void)
  17. {
  18. return (phys_addr_t)&secondary_boot_code;
  19. }
  20. int fsl_layerscape_wake_seconday_cores(void)
  21. {
  22. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  23. #ifdef CONFIG_FSL_LSCH3
  24. struct ccsr_reset __iomem *rst = (void *)(CONFIG_SYS_FSL_RST_ADDR);
  25. #elif defined(CONFIG_FSL_LSCH2)
  26. struct ccsr_scfg __iomem *scfg = (void *)(CONFIG_SYS_FSL_SCFG_ADDR);
  27. #endif
  28. u32 cores, cpu_up_mask = 1;
  29. int i, timeout = 10;
  30. u64 *table = get_spin_tbl_addr();
  31. #ifdef COUNTER_FREQUENCY_REAL
  32. /* update for secondary cores */
  33. __real_cntfrq = COUNTER_FREQUENCY_REAL;
  34. flush_dcache_range((unsigned long)&__real_cntfrq,
  35. (unsigned long)&__real_cntfrq + 8);
  36. #endif
  37. cores = cpu_mask();
  38. /* Clear spin table so that secondary processors
  39. * observe the correct value after waking up from wfe.
  40. */
  41. memset(table, 0, CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE);
  42. flush_dcache_range((unsigned long)table,
  43. (unsigned long)table +
  44. (CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE));
  45. printf("Waking secondary cores to start from %lx\n", gd->relocaddr);
  46. #ifdef CONFIG_FSL_LSCH3
  47. gur_out32(&gur->bootlocptrh, (u32)(gd->relocaddr >> 32));
  48. gur_out32(&gur->bootlocptrl, (u32)gd->relocaddr);
  49. gur_out32(&gur->scratchrw[6], 1);
  50. asm volatile("dsb st" : : : "memory");
  51. rst->brrl = cores;
  52. asm volatile("dsb st" : : : "memory");
  53. #elif defined(CONFIG_FSL_LSCH2)
  54. scfg_out32(&scfg->scratchrw[0], (u32)(gd->relocaddr >> 32));
  55. scfg_out32(&scfg->scratchrw[1], (u32)gd->relocaddr);
  56. asm volatile("dsb st" : : : "memory");
  57. gur_out32(&gur->brrl, cores);
  58. asm volatile("dsb st" : : : "memory");
  59. /* Bootup online cores */
  60. scfg_out32(&scfg->corebcr, cores);
  61. #endif
  62. /* This is needed as a precautionary measure.
  63. * If some code before this has accidentally released the secondary
  64. * cores then the pre-bootloader code will trap them in a "wfe" unless
  65. * the scratchrw[6] is set. In this case we need a sev here to get these
  66. * cores moving again.
  67. */
  68. asm volatile("sev");
  69. while (timeout--) {
  70. flush_dcache_range((unsigned long)table, (unsigned long)table +
  71. CONFIG_MAX_CPUS * 64);
  72. for (i = 1; i < CONFIG_MAX_CPUS; i++) {
  73. if (table[i * WORDS_PER_SPIN_TABLE_ENTRY +
  74. SPIN_TABLE_ELEM_STATUS_IDX])
  75. cpu_up_mask |= 1 << i;
  76. }
  77. if (hweight32(cpu_up_mask) == hweight32(cores))
  78. break;
  79. udelay(10);
  80. }
  81. if (timeout <= 0) {
  82. printf("Not all cores (0x%x) are up (0x%x)\n",
  83. cores, cpu_up_mask);
  84. return 1;
  85. }
  86. printf("All (%d) cores are up.\n", hweight32(cores));
  87. return 0;
  88. }
  89. int is_core_valid(unsigned int core)
  90. {
  91. return !!((1 << core) & cpu_mask());
  92. }
  93. int is_core_online(u64 cpu_id)
  94. {
  95. u64 *table;
  96. int pos = id_to_core(cpu_id);
  97. table = (u64 *)get_spin_tbl_addr() + pos * WORDS_PER_SPIN_TABLE_ENTRY;
  98. return table[SPIN_TABLE_ELEM_STATUS_IDX] == 1;
  99. }
  100. int cpu_reset(int nr)
  101. {
  102. puts("Feature is not implemented.\n");
  103. return 0;
  104. }
  105. int cpu_disable(int nr)
  106. {
  107. puts("Feature is not implemented.\n");
  108. return 0;
  109. }
  110. int core_to_pos(int nr)
  111. {
  112. u32 cores = cpu_mask();
  113. int i, count = 0;
  114. if (nr == 0) {
  115. return 0;
  116. } else if (nr >= hweight32(cores)) {
  117. puts("Not a valid core number.\n");
  118. return -1;
  119. }
  120. for (i = 1; i < 32; i++) {
  121. if (is_core_valid(i)) {
  122. count++;
  123. if (count == nr)
  124. break;
  125. }
  126. }
  127. return count;
  128. }
  129. int cpu_status(int nr)
  130. {
  131. u64 *table;
  132. int pos;
  133. if (nr == 0) {
  134. table = (u64 *)get_spin_tbl_addr();
  135. printf("table base @ 0x%p\n", table);
  136. } else {
  137. pos = core_to_pos(nr);
  138. if (pos < 0)
  139. return -1;
  140. table = (u64 *)get_spin_tbl_addr() + pos *
  141. WORDS_PER_SPIN_TABLE_ENTRY;
  142. printf("table @ 0x%p\n", table);
  143. printf(" addr - 0x%016llx\n",
  144. table[SPIN_TABLE_ELEM_ENTRY_ADDR_IDX]);
  145. printf(" status - 0x%016llx\n",
  146. table[SPIN_TABLE_ELEM_STATUS_IDX]);
  147. printf(" lpid - 0x%016llx\n",
  148. table[SPIN_TABLE_ELEM_LPID_IDX]);
  149. }
  150. return 0;
  151. }
  152. int cpu_release(int nr, int argc, char * const argv[])
  153. {
  154. u64 boot_addr;
  155. u64 *table = (u64 *)get_spin_tbl_addr();
  156. int pos;
  157. pos = core_to_pos(nr);
  158. if (pos <= 0)
  159. return -1;
  160. table += pos * WORDS_PER_SPIN_TABLE_ENTRY;
  161. boot_addr = simple_strtoull(argv[0], NULL, 16);
  162. table[SPIN_TABLE_ELEM_ENTRY_ADDR_IDX] = boot_addr;
  163. flush_dcache_range((unsigned long)table,
  164. (unsigned long)table + SPIN_TABLE_ELEM_SIZE);
  165. asm volatile("dsb st");
  166. smp_kick_all_cpus(); /* only those with entry addr set will run */
  167. return 0;
  168. }