processor.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright IBM Corp. 2008
  4. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  5. */
  6. #define KMSG_COMPONENT "cpu"
  7. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  8. #include <linux/cpufeature.h>
  9. #include <linux/bitops.h>
  10. #include <linux/kernel.h>
  11. #include <linux/sched/mm.h>
  12. #include <linux/init.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/mm_types.h>
  15. #include <linux/delay.h>
  16. #include <linux/cpu.h>
  17. #include <asm/diag.h>
  18. #include <asm/facility.h>
  19. #include <asm/elf.h>
  20. #include <asm/lowcore.h>
  21. #include <asm/param.h>
  22. #include <asm/smp.h>
  23. struct cpu_info {
  24. unsigned int cpu_mhz_dynamic;
  25. unsigned int cpu_mhz_static;
  26. struct cpuid cpu_id;
  27. };
  28. static DEFINE_PER_CPU(struct cpu_info, cpu_info);
  29. static bool machine_has_cpu_mhz;
  30. void __init cpu_detect_mhz_feature(void)
  31. {
  32. if (test_facility(34) && __ecag(ECAG_CPU_ATTRIBUTE, 0) != -1UL)
  33. machine_has_cpu_mhz = true;
  34. }
  35. static void update_cpu_mhz(void *arg)
  36. {
  37. unsigned long mhz;
  38. struct cpu_info *c;
  39. mhz = __ecag(ECAG_CPU_ATTRIBUTE, 0);
  40. c = this_cpu_ptr(&cpu_info);
  41. c->cpu_mhz_dynamic = mhz >> 32;
  42. c->cpu_mhz_static = mhz & 0xffffffff;
  43. }
  44. void s390_update_cpu_mhz(void)
  45. {
  46. s390_adjust_jiffies();
  47. if (machine_has_cpu_mhz)
  48. on_each_cpu(update_cpu_mhz, NULL, 0);
  49. }
  50. void notrace cpu_relax_yield(void)
  51. {
  52. if (!smp_cpu_mtid && MACHINE_HAS_DIAG44) {
  53. diag_stat_inc(DIAG_STAT_X044);
  54. asm volatile("diag 0,0,0x44");
  55. }
  56. barrier();
  57. }
  58. EXPORT_SYMBOL(cpu_relax_yield);
  59. /*
  60. * cpu_init - initializes state that is per-CPU.
  61. */
  62. void cpu_init(void)
  63. {
  64. struct cpuid *id = this_cpu_ptr(&cpu_info.cpu_id);
  65. get_cpu_id(id);
  66. if (machine_has_cpu_mhz)
  67. update_cpu_mhz(NULL);
  68. mmgrab(&init_mm);
  69. current->active_mm = &init_mm;
  70. BUG_ON(current->mm);
  71. enter_lazy_tlb(&init_mm, current);
  72. }
  73. /*
  74. * cpu_have_feature - Test CPU features on module initialization
  75. */
  76. int cpu_have_feature(unsigned int num)
  77. {
  78. return elf_hwcap & (1UL << num);
  79. }
  80. EXPORT_SYMBOL(cpu_have_feature);
  81. static void show_facilities(struct seq_file *m)
  82. {
  83. unsigned int bit;
  84. long *facilities;
  85. facilities = (long *)&S390_lowcore.stfle_fac_list;
  86. seq_puts(m, "facilities :");
  87. for_each_set_bit_inv(bit, facilities, MAX_FACILITY_BIT)
  88. seq_printf(m, " %d", bit);
  89. seq_putc(m, '\n');
  90. }
  91. static void show_cpu_summary(struct seq_file *m, void *v)
  92. {
  93. static const char *hwcap_str[] = {
  94. "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp",
  95. "edat", "etf3eh", "highgprs", "te", "vx", "vxd", "vxe", "gs"
  96. };
  97. static const char * const int_hwcap_str[] = {
  98. "sie"
  99. };
  100. int i, cpu;
  101. seq_printf(m, "vendor_id : IBM/S390\n"
  102. "# processors : %i\n"
  103. "bogomips per cpu: %lu.%02lu\n",
  104. num_online_cpus(), loops_per_jiffy/(500000/HZ),
  105. (loops_per_jiffy/(5000/HZ))%100);
  106. seq_printf(m, "max thread id : %d\n", smp_cpu_mtid);
  107. seq_puts(m, "features\t: ");
  108. for (i = 0; i < ARRAY_SIZE(hwcap_str); i++)
  109. if (hwcap_str[i] && (elf_hwcap & (1UL << i)))
  110. seq_printf(m, "%s ", hwcap_str[i]);
  111. for (i = 0; i < ARRAY_SIZE(int_hwcap_str); i++)
  112. if (int_hwcap_str[i] && (int_hwcap & (1UL << i)))
  113. seq_printf(m, "%s ", int_hwcap_str[i]);
  114. seq_puts(m, "\n");
  115. show_facilities(m);
  116. show_cacheinfo(m);
  117. for_each_online_cpu(cpu) {
  118. struct cpuid *id = &per_cpu(cpu_info.cpu_id, cpu);
  119. seq_printf(m, "processor %d: "
  120. "version = %02X, "
  121. "identification = %06X, "
  122. "machine = %04X\n",
  123. cpu, id->version, id->ident, id->machine);
  124. }
  125. }
  126. static void show_cpu_mhz(struct seq_file *m, unsigned long n)
  127. {
  128. struct cpu_info *c = per_cpu_ptr(&cpu_info, n);
  129. seq_printf(m, "cpu MHz dynamic : %d\n", c->cpu_mhz_dynamic);
  130. seq_printf(m, "cpu MHz static : %d\n", c->cpu_mhz_static);
  131. }
  132. /*
  133. * show_cpuinfo - Get information on one CPU for use by procfs.
  134. */
  135. static int show_cpuinfo(struct seq_file *m, void *v)
  136. {
  137. unsigned long n = (unsigned long) v - 1;
  138. unsigned long first = cpumask_first(cpu_online_mask);
  139. if (n == first)
  140. show_cpu_summary(m, v);
  141. if (!machine_has_cpu_mhz)
  142. return 0;
  143. seq_printf(m, "\ncpu number : %ld\n", n);
  144. show_cpu_mhz(m, n);
  145. return 0;
  146. }
  147. static inline void *c_update(loff_t *pos)
  148. {
  149. if (*pos)
  150. *pos = cpumask_next(*pos - 1, cpu_online_mask);
  151. else
  152. *pos = cpumask_first(cpu_online_mask);
  153. return *pos < nr_cpu_ids ? (void *)*pos + 1 : NULL;
  154. }
  155. static void *c_start(struct seq_file *m, loff_t *pos)
  156. {
  157. get_online_cpus();
  158. return c_update(pos);
  159. }
  160. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  161. {
  162. ++*pos;
  163. return c_update(pos);
  164. }
  165. static void c_stop(struct seq_file *m, void *v)
  166. {
  167. put_online_cpus();
  168. }
  169. const struct seq_operations cpuinfo_op = {
  170. .start = c_start,
  171. .next = c_next,
  172. .stop = c_stop,
  173. .show = show_cpuinfo,
  174. };
  175. int s390_isolate_bp(void)
  176. {
  177. if (!test_facility(82))
  178. return -EOPNOTSUPP;
  179. set_thread_flag(TIF_ISOLATE_BP);
  180. return 0;
  181. }
  182. EXPORT_SYMBOL(s390_isolate_bp);
  183. int s390_isolate_bp_guest(void)
  184. {
  185. if (!test_facility(82))
  186. return -EOPNOTSUPP;
  187. set_thread_flag(TIF_ISOLATE_BP_GUEST);
  188. return 0;
  189. }
  190. EXPORT_SYMBOL(s390_isolate_bp_guest);