cputable.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2001 Ben. Herrenschmidt ([email protected])
  4. *
  5. * Modifications for ppc64:
  6. * Copyright (C) 2003 Dave Engebretsen <[email protected]>
  7. */
  8. #include <linux/string.h>
  9. #include <linux/sched.h>
  10. #include <linux/threads.h>
  11. #include <linux/init.h>
  12. #include <linux/export.h>
  13. #include <linux/jump_label.h>
  14. #include <linux/of.h>
  15. #include <asm/cputable.h>
  16. #include <asm/mce.h>
  17. #include <asm/mmu.h>
  18. #include <asm/setup.h>
  19. #include <asm/cpu_setup.h>
  20. static struct cpu_spec the_cpu_spec __read_mostly;
  21. struct cpu_spec* cur_cpu_spec __read_mostly = NULL;
  22. EXPORT_SYMBOL(cur_cpu_spec);
  23. /* The platform string corresponding to the real PVR */
  24. const char *powerpc_base_platform;
  25. #include "cpu_specs.h"
  26. void __init set_cur_cpu_spec(struct cpu_spec *s)
  27. {
  28. struct cpu_spec *t = &the_cpu_spec;
  29. t = PTRRELOC(t);
  30. /*
  31. * use memcpy() instead of *t = *s so that GCC replaces it
  32. * by __memcpy() when KASAN is active
  33. */
  34. memcpy(t, s, sizeof(*t));
  35. *PTRRELOC(&cur_cpu_spec) = &the_cpu_spec;
  36. }
  37. static struct cpu_spec * __init setup_cpu_spec(unsigned long offset,
  38. struct cpu_spec *s)
  39. {
  40. struct cpu_spec *t = &the_cpu_spec;
  41. struct cpu_spec old;
  42. t = PTRRELOC(t);
  43. old = *t;
  44. /*
  45. * Copy everything, then do fixups. Use memcpy() instead of *t = *s
  46. * so that GCC replaces it by __memcpy() when KASAN is active
  47. */
  48. memcpy(t, s, sizeof(*t));
  49. /*
  50. * If we are overriding a previous value derived from the real
  51. * PVR with a new value obtained using a logical PVR value,
  52. * don't modify the performance monitor fields.
  53. */
  54. if (old.num_pmcs && !s->num_pmcs) {
  55. t->num_pmcs = old.num_pmcs;
  56. t->pmc_type = old.pmc_type;
  57. /*
  58. * Let's ensure that the
  59. * fix for the PMAO bug is enabled on compatibility mode.
  60. */
  61. t->cpu_features |= old.cpu_features & CPU_FTR_PMAO_BUG;
  62. }
  63. *PTRRELOC(&cur_cpu_spec) = &the_cpu_spec;
  64. /*
  65. * Set the base platform string once; assumes
  66. * we're called with real pvr first.
  67. */
  68. if (*PTRRELOC(&powerpc_base_platform) == NULL)
  69. *PTRRELOC(&powerpc_base_platform) = t->platform;
  70. #if defined(CONFIG_PPC64) || defined(CONFIG_BOOKE)
  71. /* ppc64 and booke expect identify_cpu to also call setup_cpu for
  72. * that processor. I will consolidate that at a later time, for now,
  73. * just use #ifdef. We also don't need to PTRRELOC the function
  74. * pointer on ppc64 and booke as we are running at 0 in real mode
  75. * on ppc64 and reloc_offset is always 0 on booke.
  76. */
  77. if (t->cpu_setup) {
  78. t->cpu_setup(offset, t);
  79. }
  80. #endif /* CONFIG_PPC64 || CONFIG_BOOKE */
  81. return t;
  82. }
  83. struct cpu_spec * __init identify_cpu(unsigned long offset, unsigned int pvr)
  84. {
  85. struct cpu_spec *s = cpu_specs;
  86. int i;
  87. BUILD_BUG_ON(!ARRAY_SIZE(cpu_specs));
  88. s = PTRRELOC(s);
  89. for (i = 0; i < ARRAY_SIZE(cpu_specs); i++,s++) {
  90. if ((pvr & s->pvr_mask) == s->pvr_value)
  91. return setup_cpu_spec(offset, s);
  92. }
  93. BUG();
  94. return NULL;
  95. }
  96. /*
  97. * Used by cpufeatures to get the name for CPUs with a PVR table.
  98. * If they don't hae a PVR table, cpufeatures gets the name from
  99. * cpu device-tree node.
  100. */
  101. void __init identify_cpu_name(unsigned int pvr)
  102. {
  103. struct cpu_spec *s = cpu_specs;
  104. struct cpu_spec *t = &the_cpu_spec;
  105. int i;
  106. s = PTRRELOC(s);
  107. t = PTRRELOC(t);
  108. for (i = 0; i < ARRAY_SIZE(cpu_specs); i++,s++) {
  109. if ((pvr & s->pvr_mask) == s->pvr_value) {
  110. t->cpu_name = s->cpu_name;
  111. return;
  112. }
  113. }
  114. }
  115. #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
  116. struct static_key_true cpu_feature_keys[NUM_CPU_FTR_KEYS] = {
  117. [0 ... NUM_CPU_FTR_KEYS - 1] = STATIC_KEY_TRUE_INIT
  118. };
  119. EXPORT_SYMBOL_GPL(cpu_feature_keys);
  120. void __init cpu_feature_keys_init(void)
  121. {
  122. int i;
  123. for (i = 0; i < NUM_CPU_FTR_KEYS; i++) {
  124. unsigned long f = 1ul << i;
  125. if (!(cur_cpu_spec->cpu_features & f))
  126. static_branch_disable(&cpu_feature_keys[i]);
  127. }
  128. }
  129. struct static_key_true mmu_feature_keys[NUM_MMU_FTR_KEYS] = {
  130. [0 ... NUM_MMU_FTR_KEYS - 1] = STATIC_KEY_TRUE_INIT
  131. };
  132. EXPORT_SYMBOL(mmu_feature_keys);
  133. void __init mmu_feature_keys_init(void)
  134. {
  135. int i;
  136. for (i = 0; i < NUM_MMU_FTR_KEYS; i++) {
  137. unsigned long f = 1ul << i;
  138. if (!(cur_cpu_spec->mmu_features & f))
  139. static_branch_disable(&mmu_feature_keys[i]);
  140. }
  141. }
  142. #endif