1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * The 'sbi' command displays information about the SBI implementation.
4  *
5  * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
6  */
7 
8 #include <common.h>
9 #include <command.h>
10 #include <asm/sbi.h>
11 
12 struct sbi_imp {
13 	const long id;
14 	const char *name;
15 };
16 
17 struct sbi_ext {
18 	const u32 id;
19 	const char *name;
20 };
21 
22 static struct sbi_imp implementations[] = {
23 	{ 0, "Berkeley Boot Loader (BBL)" },
24 	{ 1, "OpenSBI" },
25 	{ 2, "Xvisor" },
26 	{ 3, "KVM" },
27 	{ 4, "RustSBI" },
28 	{ 5, "Diosix" },
29 };
30 
31 static struct sbi_ext extensions[] = {
32 	{ 0x00000000, "sbi_set_timer" },
33 	{ 0x00000001, "sbi_console_putchar" },
34 	{ 0x00000002, "sbi_console_getchar" },
35 	{ 0x00000003, "sbi_clear_ipi" },
36 	{ 0x00000004, "sbi_send_ipi" },
37 	{ 0x00000005, "sbi_remote_fence_i" },
38 	{ 0x00000006, "sbi_remote_sfence_vma" },
39 	{ 0x00000007, "sbi_remote_sfence_vma_asid" },
40 	{ 0x00000008, "sbi_shutdown" },
41 	{ 0x00000010, "SBI Base Functionality" },
42 	{ 0x54494D45, "Timer Extension" },
43 	{ 0x00735049, "IPI Extension" },
44 	{ 0x52464E43, "RFENCE Extension" },
45 	{ 0x0048534D, "Hart State Management Extension" },
46 	{ 0x53525354, "System Reset Extension" },
47 };
48 
do_sbi(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])49 static int do_sbi(struct cmd_tbl *cmdtp, int flag, int argc,
50 		  char *const argv[])
51 {
52 	int i;
53 	long ret;
54 
55 	ret = sbi_get_spec_version();
56 	if (ret >= 0)
57 		printf("SBI %ld.%ld\n", ret >> 24, ret & 0xffffff);
58 	ret = sbi_get_impl_id();
59 	if (ret >= 0) {
60 		for (i = 0; i < ARRAY_SIZE(implementations); ++i) {
61 			if (ret == implementations[i].id) {
62 				printf("%s\n", implementations[i].name);
63 				break;
64 			}
65 		}
66 		if (i == ARRAY_SIZE(implementations))
67 			printf("Unknown implementation ID %ld\n", ret);
68 	}
69 	printf("Extensions:\n");
70 	for (i = 0; i < ARRAY_SIZE(extensions); ++i) {
71 		ret = sbi_probe_extension(extensions[i].id);
72 		if (ret > 0)
73 			printf("  %s\n", extensions[i].name);
74 	}
75 	return 0;
76 }
77 
78 #ifdef CONFIG_SYS_LONGHELP
79 static char sbi_help_text[] =
80 	"- display SBI spec version, implementation, and available extensions";
81 
82 #endif
83 
84 U_BOOT_CMD_COMPLETE(
85 	sbi, 1, 0, do_sbi,
86 	"display SBI information",
87 	sbi_help_text, NULL
88 );
89