processor.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/elf.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. static const char * const int_hwcap_str[] = {
  58. "sie"
  59. };
  60. unsigned long n = (unsigned long) v - 1;
  61. int i;
  62. if (!n) {
  63. s390_adjust_jiffies();
  64. seq_printf(m, "vendor_id : IBM/S390\n"
  65. "# processors : %i\n"
  66. "bogomips per cpu: %lu.%02lu\n",
  67. num_online_cpus(), loops_per_jiffy/(500000/HZ),
  68. (loops_per_jiffy/(5000/HZ))%100);
  69. seq_puts(m, "features\t: ");
  70. for (i = 0; i < ARRAY_SIZE(hwcap_str); i++)
  71. if (hwcap_str[i] && (elf_hwcap & (1UL << i)))
  72. seq_printf(m, "%s ", hwcap_str[i]);
  73. for (i = 0; i < ARRAY_SIZE(int_hwcap_str); i++)
  74. if (int_hwcap_str[i] && (int_hwcap & (1UL << i)))
  75. seq_printf(m, "%s ", int_hwcap_str[i]);
  76. seq_puts(m, "\n");
  77. show_cacheinfo(m);
  78. }
  79. if (cpu_online(n)) {
  80. struct cpuid *id = &per_cpu(cpu_id, n);
  81. seq_printf(m, "processor %li: "
  82. "version = %02X, "
  83. "identification = %06X, "
  84. "machine = %04X\n",
  85. n, id->version, id->ident, id->machine);
  86. }
  87. return 0;
  88. }
  89. static inline void *c_update(loff_t *pos)
  90. {
  91. if (*pos)
  92. *pos = cpumask_next(*pos - 1, cpu_online_mask);
  93. return *pos < nr_cpu_ids ? (void *)*pos + 1 : NULL;
  94. }
  95. static void *c_start(struct seq_file *m, loff_t *pos)
  96. {
  97. get_online_cpus();
  98. return c_update(pos);
  99. }
  100. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  101. {
  102. ++*pos;
  103. return c_update(pos);
  104. }
  105. static void c_stop(struct seq_file *m, void *v)
  106. {
  107. put_online_cpus();
  108. }
  109. const struct seq_operations cpuinfo_op = {
  110. .start = c_start,
  111. .next = c_next,
  112. .stop = c_stop,
  113. .show = show_cpuinfo,
  114. };