xref: /openbmc/u-boot/arch/riscv/cpu/cpu.c (revision cb19c293)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
4  */
5 
6 #include <common.h>
7 #include <asm/csr.h>
8 
9 enum {
10 	ISA_INVALID = 0,
11 	ISA_32BIT,
12 	ISA_64BIT,
13 	ISA_128BIT
14 };
15 
16 static const char * const isa_bits[] = {
17 	[ISA_INVALID] = NULL,
18 	[ISA_32BIT]   = "32",
19 	[ISA_64BIT]   = "64",
20 	[ISA_128BIT]  = "128"
21 };
22 
23 static inline bool supports_extension(char ext)
24 {
25 	return csr_read(misa) & (1 << (ext - 'a'));
26 }
27 
28 int print_cpuinfo(void)
29 {
30 	char name[32];
31 	char *s = name;
32 	int bit;
33 
34 	s += sprintf(name, "rv");
35 	bit = csr_read(misa) >> (sizeof(long) * 8 - 2);
36 	s += sprintf(s, isa_bits[bit]);
37 
38 	supports_extension('i') ? *s++ = 'i' : 'r';
39 	supports_extension('m') ? *s++ = 'm' : 'i';
40 	supports_extension('a') ? *s++ = 'a' : 's';
41 	supports_extension('f') ? *s++ = 'f' : 'c';
42 	supports_extension('d') ? *s++ = 'd' : '-';
43 	supports_extension('c') ? *s++ = 'c' : 'v';
44 	*s++ = '\0';
45 
46 	printf("CPU:   %s\n", name);
47 
48 	return 0;
49 }
50