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