mp.c 4.1 KB

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