Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 1 | /* |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 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> |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 11 | #include <linux/seq_file.h> |
| 12 | #include <linux/delay.h> |
Heiko Carstens | 19726ce | 2011-01-05 12:48:17 +0100 | [diff] [blame] | 13 | #include <linux/cpu.h> |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 14 | #include <asm/elf.h> |
| 15 | #include <asm/lowcore.h> |
| 16 | #include <asm/param.h> |
Heiko Carstens | 4d92f50 | 2015-01-28 07:43:56 +0100 | [diff] [blame] | 17 | #include <asm/smp.h> |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 18 | |
Martin Schwidefsky | 94038a9 | 2010-05-17 10:00:00 +0200 | [diff] [blame] | 19 | static DEFINE_PER_CPU(struct cpuid, cpu_id); |
| 20 | |
Heiko Carstens | a9ca8eb | 2015-02-28 11:35:26 +0100 | [diff] [blame] | 21 | void notrace cpu_relax(void) |
Heiko Carstens | 4d92f50 | 2015-01-28 07:43:56 +0100 | [diff] [blame] | 22 | { |
| 23 | if (!smp_cpu_mtid && MACHINE_HAS_DIAG44) |
| 24 | asm volatile("diag 0,0,0x44"); |
| 25 | barrier(); |
| 26 | } |
| 27 | EXPORT_SYMBOL(cpu_relax); |
| 28 | |
Martin Schwidefsky | 94038a9 | 2010-05-17 10:00:00 +0200 | [diff] [blame] | 29 | /* |
| 30 | * cpu_init - initializes state that is per-CPU. |
| 31 | */ |
Paul Gortmaker | e2741f1 | 2013-06-18 17:04:52 -0400 | [diff] [blame] | 32 | void cpu_init(void) |
Martin Schwidefsky | 94038a9 | 2010-05-17 10:00:00 +0200 | [diff] [blame] | 33 | { |
Christoph Lameter | eb7e7d7 | 2014-08-17 12:30:45 -0500 | [diff] [blame] | 34 | struct cpuid *id = this_cpu_ptr(&cpu_id); |
Martin Schwidefsky | 94038a9 | 2010-05-17 10:00:00 +0200 | [diff] [blame] | 35 | |
| 36 | get_cpu_id(id); |
| 37 | atomic_inc(&init_mm.mm_count); |
| 38 | current->active_mm = &init_mm; |
| 39 | BUG_ON(current->mm); |
| 40 | enter_lazy_tlb(&init_mm, current); |
| 41 | } |
| 42 | |
| 43 | /* |
Hendrik Brueckner | 8f00b3e | 2015-02-19 12:22:02 +0100 | [diff] [blame] | 44 | * cpu_have_feature - Test CPU features on module initialization |
| 45 | */ |
| 46 | int cpu_have_feature(unsigned int num) |
| 47 | { |
| 48 | return elf_hwcap & (1UL << num); |
| 49 | } |
| 50 | EXPORT_SYMBOL(cpu_have_feature); |
| 51 | |
| 52 | /* |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 53 | * show_cpuinfo - Get information on one CPU for use by procfs. |
| 54 | */ |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 55 | static int show_cpuinfo(struct seq_file *m, void *v) |
| 56 | { |
Heiko Carstens | fbf3c54 | 2012-08-29 14:54:38 +0200 | [diff] [blame] | 57 | static const char *hwcap_str[] = { |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 58 | "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp", |
Martin Schwidefsky | 8070361 | 2014-10-06 17:53:53 +0200 | [diff] [blame] | 59 | "edat", "etf3eh", "highgprs", "te", "vx" |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 60 | }; |
Martin Schwidefsky | 7b46848 | 2009-03-26 15:24:42 +0100 | [diff] [blame] | 61 | unsigned long n = (unsigned long) v - 1; |
| 62 | int i; |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 63 | |
Martin Schwidefsky | 7b46848 | 2009-03-26 15:24:42 +0100 | [diff] [blame] | 64 | if (!n) { |
Heiko Carstens | 8e10230 | 2011-01-05 12:48:18 +0100 | [diff] [blame] | 65 | s390_adjust_jiffies(); |
Martin Schwidefsky | 7b46848 | 2009-03-26 15:24:42 +0100 | [diff] [blame] | 66 | seq_printf(m, "vendor_id : IBM/S390\n" |
| 67 | "# processors : %i\n" |
| 68 | "bogomips per cpu: %lu.%02lu\n", |
| 69 | num_online_cpus(), loops_per_jiffy/(500000/HZ), |
| 70 | (loops_per_jiffy/(5000/HZ))%100); |
| 71 | seq_puts(m, "features\t: "); |
Heiko Carstens | fbf3c54 | 2012-08-29 14:54:38 +0200 | [diff] [blame] | 72 | for (i = 0; i < ARRAY_SIZE(hwcap_str); i++) |
Martin Schwidefsky | 7b46848 | 2009-03-26 15:24:42 +0100 | [diff] [blame] | 73 | if (hwcap_str[i] && (elf_hwcap & (1UL << i))) |
| 74 | seq_printf(m, "%s ", hwcap_str[i]); |
| 75 | seq_puts(m, "\n"); |
Heiko Carstens | 6668022 | 2012-08-29 14:12:20 +0200 | [diff] [blame] | 76 | show_cacheinfo(m); |
Martin Schwidefsky | 7b46848 | 2009-03-26 15:24:42 +0100 | [diff] [blame] | 77 | } |
Heiko Carstens | 19726ce | 2011-01-05 12:48:17 +0100 | [diff] [blame] | 78 | get_online_cpus(); |
Martin Schwidefsky | 7b46848 | 2009-03-26 15:24:42 +0100 | [diff] [blame] | 79 | if (cpu_online(n)) { |
Martin Schwidefsky | 94038a9 | 2010-05-17 10:00:00 +0200 | [diff] [blame] | 80 | struct cpuid *id = &per_cpu(cpu_id, n); |
Martin Schwidefsky | 7b46848 | 2009-03-26 15:24:42 +0100 | [diff] [blame] | 81 | seq_printf(m, "processor %li: " |
| 82 | "version = %02X, " |
| 83 | "identification = %06X, " |
| 84 | "machine = %04X\n", |
Martin Schwidefsky | 94038a9 | 2010-05-17 10:00:00 +0200 | [diff] [blame] | 85 | n, id->version, id->ident, id->machine); |
Martin Schwidefsky | 7b46848 | 2009-03-26 15:24:42 +0100 | [diff] [blame] | 86 | } |
Heiko Carstens | 19726ce | 2011-01-05 12:48:17 +0100 | [diff] [blame] | 87 | put_online_cpus(); |
Martin Schwidefsky | 7b46848 | 2009-03-26 15:24:42 +0100 | [diff] [blame] | 88 | return 0; |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static void *c_start(struct seq_file *m, loff_t *pos) |
| 92 | { |
Martin Schwidefsky | dd4a5a3 | 2011-10-30 15:16:05 +0100 | [diff] [blame] | 93 | return *pos < nr_cpu_ids ? (void *)((unsigned long) *pos + 1) : NULL; |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static void *c_next(struct seq_file *m, void *v, loff_t *pos) |
| 97 | { |
| 98 | ++*pos; |
| 99 | return c_start(m, pos); |
| 100 | } |
| 101 | |
| 102 | static void c_stop(struct seq_file *m, void *v) |
| 103 | { |
| 104 | } |
| 105 | |
| 106 | const struct seq_operations cpuinfo_op = { |
| 107 | .start = c_start, |
| 108 | .next = c_next, |
| 109 | .stop = c_stop, |
| 110 | .show = show_cpuinfo, |
| 111 | }; |
| 112 | |