processor.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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/kernel.h>
  8. #include <linux/init.h>
  9. #include <linux/seq_file.h>
  10. #include <linux/delay.h>
  11. #include <linux/cpu.h>
  12. #include <asm/diag.h>
  13. #include <asm/elf.h>
  14. #include <asm/facility.h>
  15. #include <asm/lowcore.h>
  16. #include <asm/param.h>
  17. #include <asm/smp.h>
  18. static DEFINE_PER_CPU(struct cpuid, cpu_id);
  19. void notrace cpu_relax(void)
  20. {
  21. if (!smp_cpu_mtid && MACHINE_HAS_DIAG44) {
  22. diag_stat_inc(DIAG_STAT_X044);
  23. asm volatile("diag 0,0,0x44");
  24. }
  25. barrier();
  26. }
  27. EXPORT_SYMBOL(cpu_relax);
  28. /*
  29. * cpu_init - initializes state that is per-CPU.
  30. */
  31. void cpu_init(void)
  32. {
  33. struct cpuid *id = this_cpu_ptr(&cpu_id);
  34. get_cpu_id(id);
  35. atomic_inc(&init_mm.mm_count);
  36. current->active_mm = &init_mm;
  37. BUG_ON(current->mm);
  38. enter_lazy_tlb(&init_mm, current);
  39. }
  40. /*
  41. * cpu_have_feature - Test CPU features on module initialization
  42. */
  43. int cpu_have_feature(unsigned int num)
  44. {
  45. return elf_hwcap & (1UL << num);
  46. }
  47. EXPORT_SYMBOL(cpu_have_feature);
  48. /*
  49. * show_cpuinfo - Get information on one CPU for use by procfs.
  50. */
  51. static int show_cpuinfo(struct seq_file *m, void *v)
  52. {
  53. static const char *hwcap_str[] = {
  54. "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp",
  55. "edat", "etf3eh", "highgprs", "te", "vx"
  56. };
  57. unsigned long n = (unsigned long) v - 1;
  58. int i;
  59. if (!n) {
  60. s390_adjust_jiffies();
  61. seq_printf(m, "vendor_id : IBM/S390\n"
  62. "# processors : %i\n"
  63. "bogomips per cpu: %lu.%02lu\n",
  64. num_online_cpus(), loops_per_jiffy/(500000/HZ),
  65. (loops_per_jiffy/(5000/HZ))%100);
  66. seq_puts(m, "features\t: ");
  67. for (i = 0; i < ARRAY_SIZE(hwcap_str); i++)
  68. if (hwcap_str[i] && (elf_hwcap & (1UL << i)))
  69. seq_printf(m, "%s ", hwcap_str[i]);
  70. seq_puts(m, "\n");
  71. show_cacheinfo(m);
  72. }
  73. get_online_cpus();
  74. if (cpu_online(n)) {
  75. struct cpuid *id = &per_cpu(cpu_id, n);
  76. seq_printf(m, "processor %li: "
  77. "version = %02X, "
  78. "identification = %06X, "
  79. "machine = %04X\n",
  80. n, id->version, id->ident, id->machine);
  81. }
  82. put_online_cpus();
  83. return 0;
  84. }
  85. static void *c_start(struct seq_file *m, loff_t *pos)
  86. {
  87. return *pos < nr_cpu_ids ? (void *)((unsigned long) *pos + 1) : NULL;
  88. }
  89. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  90. {
  91. ++*pos;
  92. return c_start(m, pos);
  93. }
  94. static void c_stop(struct seq_file *m, void *v)
  95. {
  96. }
  97. const struct seq_operations cpuinfo_op = {
  98. .start = c_start,
  99. .next = c_next,
  100. .stop = c_stop,
  101. .show = show_cpuinfo,
  102. };
  103. int s390_isolate_bp(void)
  104. {
  105. if (!test_facility(82))
  106. return -EOPNOTSUPP;
  107. set_thread_flag(TIF_ISOLATE_BP);
  108. return 0;
  109. }
  110. EXPORT_SYMBOL(s390_isolate_bp);
  111. int s390_isolate_bp_guest(void)
  112. {
  113. if (!test_facility(82))
  114. return -EOPNOTSUPP;
  115. set_thread_flag(TIF_ISOLATE_BP_GUEST);
  116. return 0;
  117. }
  118. EXPORT_SYMBOL(s390_isolate_bp_guest);