blob: 90c0811e14c60565ddd2be0cee449039f817271f [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" },
29};
30
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020031static 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" },
Heinrich Schuchardt921d5472021-01-17 21:27:13 +000046 { 0x53525354, "System Reset Extension" },
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020047};
48
49static 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) {
Heinrich Schuchardt7fd892b2021-01-19 19:44:45 +000060 for (i = 0; i < ARRAY_SIZE(implementations); ++i) {
61 if (ret == implementations[i].id) {
62 printf("%s\n", implementations[i].name);
63 break;
64 }
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020065 }
Heinrich Schuchardt7fd892b2021-01-19 19:44:45 +000066 if (i == ARRAY_SIZE(implementations))
67 printf("Unknown implementation ID %ld\n", ret);
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020068 }
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
79static char sbi_help_text[] =
80 "- display SBI spec version, implementation, and available extensions";
81
82#endif
83
84U_BOOT_CMD_COMPLETE(
85 sbi, 1, 0, do_sbi,
86 "display SBI information",
87 sbi_help_text, NULL
88);