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