blob: 24955d2be1932a7503fe952cdc3a843540c88d36 [file] [log] [blame]
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +02001// 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
Heinrich Schuchardt7fd892b2021-01-19 19:44:45 +000012struct sbi_imp {
13 const long id;
14 const char *name;
15};
16
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020017struct sbi_ext {
18 const u32 id;
19 const char *name;
20};
21
Heinrich Schuchardt7fd892b2021-01-19 19:44:45 +000022static 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" },
Heinrich Schuchardt73872eb2022-05-07 14:42:10 +020029 { 6, "Coffer" },
Heinrich Schuchardt7fd892b2021-01-19 19:44:45 +000030};
31
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020032static struct sbi_ext extensions[] = {
Heinrich Schuchardt09d7cc32021-09-12 21:11:45 +020033 { SBI_EXT_0_1_SET_TIMER, "sbi_set_timer" },
34 { SBI_EXT_0_1_CONSOLE_PUTCHAR, "sbi_console_putchar" },
35 { SBI_EXT_0_1_CONSOLE_GETCHAR, "sbi_console_getchar" },
36 { SBI_EXT_0_1_CLEAR_IPI, "sbi_clear_ipi" },
37 { SBI_EXT_0_1_SEND_IPI, "sbi_send_ipi" },
38 { SBI_EXT_0_1_REMOTE_FENCE_I, "sbi_remote_fence_i" },
39 { SBI_EXT_0_1_REMOTE_SFENCE_VMA, "sbi_remote_sfence_vma" },
40 { SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID, "sbi_remote_sfence_vma_asid" },
41 { SBI_EXT_0_1_SHUTDOWN, "sbi_shutdown" },
42 { SBI_EXT_BASE, "SBI Base Functionality" },
43 { SBI_EXT_TIME, "Timer Extension" },
44 { SBI_EXT_IPI, "IPI Extension" },
45 { SBI_EXT_RFENCE, "RFENCE Extension" },
46 { SBI_EXT_HSM, "Hart State Management Extension" },
47 { SBI_EXT_SRST, "System Reset Extension" },
Heinrich Schuchardt70ae54b2022-03-16 21:21:18 +010048 { SBI_EXT_PMU, "Performance Monitoring Unit Extension" },
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020049};
50
51static int do_sbi(struct cmd_tbl *cmdtp, int flag, int argc,
52 char *const argv[])
53{
Heinrich Schuchardt89a86dc2021-10-25 15:09:35 +020054 int i, impl_id;
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020055 long ret;
Heinrich Schuchardtcfb31e02022-03-17 07:36:15 +010056 long mvendorid, marchid, mimpid;
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020057
58 ret = sbi_get_spec_version();
Heinrich Schuchardt72c1f5f2022-10-04 10:09:53 +020059 if (ret < 0) {
60 printf("No SBI 0.2+\n");
61 return CMD_RET_FAILURE;
62 }
63 printf("SBI %ld.%ld", ret >> 24, ret & 0xffffff);
Heinrich Schuchardt89a86dc2021-10-25 15:09:35 +020064 impl_id = sbi_get_impl_id();
65 if (impl_id >= 0) {
Heinrich Schuchardt7fd892b2021-01-19 19:44:45 +000066 for (i = 0; i < ARRAY_SIZE(implementations); ++i) {
Heinrich Schuchardt89a86dc2021-10-25 15:09:35 +020067 if (impl_id == implementations[i].id) {
68 long vers;
69
70 printf("\n%s ", implementations[i].name);
71 ret = sbi_get_impl_version(&vers);
72 if (ret < 0)
73 break;
Heinrich Schuchardtaa8aa482022-08-14 21:57:14 +020074 switch (impl_id) {
75 case 1: /* OpenSBI */
Heinrich Schuchardt89a86dc2021-10-25 15:09:35 +020076 printf("%ld.%ld",
77 vers >> 16, vers & 0xffff);
Heinrich Schuchardtaa8aa482022-08-14 21:57:14 +020078 break;
79 case 3: /* KVM */
Heinrich Schuchardt94877642022-10-04 10:09:52 +020080 case 4: /* RustSBI */
Heinrich Schuchardtaa8aa482022-08-14 21:57:14 +020081 printf("%ld.%ld.%ld",
82 vers >> 16,
83 (vers >> 8) & 0xff,
84 vers & 0xff);
85 break;
86 default:
Heinrich Schuchardt89a86dc2021-10-25 15:09:35 +020087 printf("0x%lx", vers);
Heinrich Schuchardtaa8aa482022-08-14 21:57:14 +020088 break;
89 }
Heinrich Schuchardt7fd892b2021-01-19 19:44:45 +000090 break;
91 }
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020092 }
Heinrich Schuchardt7fd892b2021-01-19 19:44:45 +000093 if (i == ARRAY_SIZE(implementations))
Heinrich Schuchardt89a86dc2021-10-25 15:09:35 +020094 printf("Unknown implementation ID %ld", ret);
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020095 }
Heinrich Schuchardtcfb31e02022-03-17 07:36:15 +010096 printf("\nMachine:\n");
97 ret = sbi_get_mvendorid(&mvendorid);
98 if (!ret)
99 printf(" Vendor ID %lx\n", mvendorid);
100 ret = sbi_get_marchid(&marchid);
101 if (!ret)
102 printf(" Architecture ID %lx\n", marchid);
103 ret = sbi_get_mimpid(&mimpid);
104 if (!ret)
105 printf(" Implementation ID %lx\n", mimpid);
106 printf("Extensions:\n");
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +0200107 for (i = 0; i < ARRAY_SIZE(extensions); ++i) {
108 ret = sbi_probe_extension(extensions[i].id);
109 if (ret > 0)
110 printf(" %s\n", extensions[i].name);
111 }
112 return 0;
113}
114
115#ifdef CONFIG_SYS_LONGHELP
116static char sbi_help_text[] =
117 "- display SBI spec version, implementation, and available extensions";
118
119#endif
120
121U_BOOT_CMD_COMPLETE(
122 sbi, 1, 0, do_sbi,
123 "display SBI information",
124 sbi_help_text, NULL
125);