blob: de7451065c34228b0485d615ad8577cb9e94d660 [file] [log] [blame]
Martin Schwidefsky395d31d2008-12-25 13:39:50 +01001/*
Martin Schwidefsky395d31d2008-12-25 13:39:50 +01002 * 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
Heiko Carstensca218722016-05-07 12:15:34 +02009#include <linux/cpufeature.h>
Martin Schwidefsky395d31d2008-12-25 13:39:50 +010010#include <linux/kernel.h>
11#include <linux/init.h>
Martin Schwidefsky395d31d2008-12-25 13:39:50 +010012#include <linux/seq_file.h>
13#include <linux/delay.h>
Heiko Carstens19726ce2011-01-05 12:48:17 +010014#include <linux/cpu.h>
Martin Schwidefsky1ec27722015-08-20 17:28:44 +020015#include <asm/diag.h>
Martin Schwidefsky395d31d2008-12-25 13:39:50 +010016#include <asm/elf.h>
17#include <asm/lowcore.h>
18#include <asm/param.h>
Heiko Carstens4d92f502015-01-28 07:43:56 +010019#include <asm/smp.h>
Martin Schwidefsky395d31d2008-12-25 13:39:50 +010020
Martin Schwidefsky94038a92010-05-17 10:00:00 +020021static DEFINE_PER_CPU(struct cpuid, cpu_id);
22
Heiko Carstensa9ca8eb2015-02-28 11:35:26 +010023void notrace cpu_relax(void)
Heiko Carstens4d92f502015-01-28 07:43:56 +010024{
Martin Schwidefsky1ec27722015-08-20 17:28:44 +020025 if (!smp_cpu_mtid && MACHINE_HAS_DIAG44) {
26 diag_stat_inc(DIAG_STAT_X044);
Heiko Carstens4d92f502015-01-28 07:43:56 +010027 asm volatile("diag 0,0,0x44");
Martin Schwidefsky1ec27722015-08-20 17:28:44 +020028 }
Heiko Carstens4d92f502015-01-28 07:43:56 +010029 barrier();
30}
31EXPORT_SYMBOL(cpu_relax);
32
Martin Schwidefsky94038a92010-05-17 10:00:00 +020033/*
34 * cpu_init - initializes state that is per-CPU.
35 */
Paul Gortmakere2741f12013-06-18 17:04:52 -040036void cpu_init(void)
Martin Schwidefsky94038a92010-05-17 10:00:00 +020037{
Christoph Lametereb7e7d72014-08-17 12:30:45 -050038 struct cpuid *id = this_cpu_ptr(&cpu_id);
Martin Schwidefsky94038a92010-05-17 10:00:00 +020039
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/*
Hendrik Brueckner8f00b3e2015-02-19 12:22:02 +010048 * cpu_have_feature - Test CPU features on module initialization
49 */
50int cpu_have_feature(unsigned int num)
51{
52 return elf_hwcap & (1UL << num);
53}
54EXPORT_SYMBOL(cpu_have_feature);
55
56/*
Martin Schwidefsky395d31d2008-12-25 13:39:50 +010057 * show_cpuinfo - Get information on one CPU for use by procfs.
58 */
Martin Schwidefsky395d31d2008-12-25 13:39:50 +010059static int show_cpuinfo(struct seq_file *m, void *v)
60{
Heiko Carstensfbf3c542012-08-29 14:54:38 +020061 static const char *hwcap_str[] = {
Martin Schwidefsky395d31d2008-12-25 13:39:50 +010062 "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp",
Martin Schwidefsky80703612014-10-06 17:53:53 +020063 "edat", "etf3eh", "highgprs", "te", "vx"
Martin Schwidefsky395d31d2008-12-25 13:39:50 +010064 };
David Hildenbrand7f16d7e2015-02-24 15:54:47 +010065 static const char * const int_hwcap_str[] = {
66 "sie"
67 };
Martin Schwidefsky7b468482009-03-26 15:24:42 +010068 unsigned long n = (unsigned long) v - 1;
69 int i;
Martin Schwidefsky395d31d2008-12-25 13:39:50 +010070
Martin Schwidefsky7b468482009-03-26 15:24:42 +010071 if (!n) {
Heiko Carstens8e102302011-01-05 12:48:18 +010072 s390_adjust_jiffies();
Martin Schwidefsky7b468482009-03-26 15:24:42 +010073 seq_printf(m, "vendor_id : IBM/S390\n"
74 "# processors : %i\n"
75 "bogomips per cpu: %lu.%02lu\n",
76 num_online_cpus(), loops_per_jiffy/(500000/HZ),
77 (loops_per_jiffy/(5000/HZ))%100);
78 seq_puts(m, "features\t: ");
Heiko Carstensfbf3c542012-08-29 14:54:38 +020079 for (i = 0; i < ARRAY_SIZE(hwcap_str); i++)
Martin Schwidefsky7b468482009-03-26 15:24:42 +010080 if (hwcap_str[i] && (elf_hwcap & (1UL << i)))
81 seq_printf(m, "%s ", hwcap_str[i]);
David Hildenbrand7f16d7e2015-02-24 15:54:47 +010082 for (i = 0; i < ARRAY_SIZE(int_hwcap_str); i++)
83 if (int_hwcap_str[i] && (int_hwcap & (1UL << i)))
84 seq_printf(m, "%s ", int_hwcap_str[i]);
Martin Schwidefsky7b468482009-03-26 15:24:42 +010085 seq_puts(m, "\n");
Heiko Carstens66680222012-08-29 14:12:20 +020086 show_cacheinfo(m);
Martin Schwidefsky7b468482009-03-26 15:24:42 +010087 }
Martin Schwidefsky7b468482009-03-26 15:24:42 +010088 if (cpu_online(n)) {
Martin Schwidefsky94038a92010-05-17 10:00:00 +020089 struct cpuid *id = &per_cpu(cpu_id, n);
Martin Schwidefsky7b468482009-03-26 15:24:42 +010090 seq_printf(m, "processor %li: "
91 "version = %02X, "
92 "identification = %06X, "
93 "machine = %04X\n",
Martin Schwidefsky94038a92010-05-17 10:00:00 +020094 n, id->version, id->ident, id->machine);
Martin Schwidefsky7b468482009-03-26 15:24:42 +010095 }
Martin Schwidefsky7b468482009-03-26 15:24:42 +010096 return 0;
Martin Schwidefsky395d31d2008-12-25 13:39:50 +010097}
98
Heiko Carstens281eaa82016-04-13 14:49:12 +020099static inline void *c_update(loff_t *pos)
100{
101 if (*pos)
102 *pos = cpumask_next(*pos - 1, cpu_online_mask);
103 return *pos < nr_cpu_ids ? (void *)*pos + 1 : NULL;
104}
105
Martin Schwidefsky395d31d2008-12-25 13:39:50 +0100106static void *c_start(struct seq_file *m, loff_t *pos)
107{
Heiko Carstens281eaa82016-04-13 14:49:12 +0200108 get_online_cpus();
109 return c_update(pos);
Martin Schwidefsky395d31d2008-12-25 13:39:50 +0100110}
111
112static void *c_next(struct seq_file *m, void *v, loff_t *pos)
113{
114 ++*pos;
Heiko Carstens281eaa82016-04-13 14:49:12 +0200115 return c_update(pos);
Martin Schwidefsky395d31d2008-12-25 13:39:50 +0100116}
117
118static void c_stop(struct seq_file *m, void *v)
119{
Heiko Carstens281eaa82016-04-13 14:49:12 +0200120 put_online_cpus();
Martin Schwidefsky395d31d2008-12-25 13:39:50 +0100121}
122
123const struct seq_operations cpuinfo_op = {
124 .start = c_start,
125 .next = c_next,
126 .stop = c_stop,
127 .show = show_cpuinfo,
128};
129