processor.c 4.3 KB

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