Guo Ren | 081860b | 2018-09-05 14:25:08 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. |
| 3 | |
| 4 | #include <linux/of.h> |
| 5 | #include <linux/init.h> |
| 6 | #include <linux/seq_file.h> |
| 7 | #include <linux/memblock.h> |
| 8 | |
| 9 | #include <abi/reg_ops.h> |
| 10 | |
| 11 | static void percpu_print(void *arg) |
| 12 | { |
| 13 | struct seq_file *m = (struct seq_file *)arg; |
| 14 | unsigned int cur, next, i; |
| 15 | |
| 16 | seq_printf(m, "processor : %d\n", smp_processor_id()); |
| 17 | seq_printf(m, "C-SKY CPU model : %s\n", CSKYCPU_DEF_NAME); |
| 18 | |
| 19 | /* read processor id, max is 100 */ |
| 20 | cur = mfcr("cr13"); |
| 21 | for (i = 0; i < 100; i++) { |
| 22 | seq_printf(m, "product info[%d] : 0x%08x\n", i, cur); |
| 23 | |
| 24 | next = mfcr("cr13"); |
| 25 | |
| 26 | /* some CPU only has one id reg */ |
| 27 | if (cur == next) |
| 28 | break; |
| 29 | |
| 30 | cur = next; |
| 31 | |
| 32 | /* cpid index is 31-28, reset */ |
| 33 | if (!(next >> 28)) { |
| 34 | while ((mfcr("cr13") >> 28) != i); |
| 35 | break; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /* CPU feature regs, setup by bootloader or gdbinit */ |
| 40 | seq_printf(m, "hint (CPU funcs): 0x%08x\n", mfcr_hint()); |
| 41 | seq_printf(m, "ccr (L1C & MMU): 0x%08x\n", mfcr("cr18")); |
| 42 | seq_printf(m, "ccr2 (L2C) : 0x%08x\n", mfcr_ccr2()); |
| 43 | seq_printf(m, "\n"); |
| 44 | } |
| 45 | |
| 46 | static int c_show(struct seq_file *m, void *v) |
| 47 | { |
| 48 | int cpu; |
| 49 | |
| 50 | for_each_online_cpu(cpu) |
| 51 | smp_call_function_single(cpu, percpu_print, m, true); |
| 52 | |
| 53 | #ifdef CSKY_ARCH_VERSION |
| 54 | seq_printf(m, "arch-version : %s\n", CSKY_ARCH_VERSION); |
| 55 | seq_printf(m, "\n"); |
| 56 | #endif |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static void *c_start(struct seq_file *m, loff_t *pos) |
| 62 | { |
| 63 | return *pos < 1 ? (void *)1 : NULL; |
| 64 | } |
| 65 | |
| 66 | static void *c_next(struct seq_file *m, void *v, loff_t *pos) |
| 67 | { |
| 68 | ++*pos; |
| 69 | return NULL; |
| 70 | } |
| 71 | |
| 72 | static void c_stop(struct seq_file *m, void *v) {} |
| 73 | |
| 74 | const struct seq_operations cpuinfo_op = { |
| 75 | .start = c_start, |
| 76 | .next = c_next, |
| 77 | .stop = c_stop, |
| 78 | .show = c_show, |
| 79 | }; |