blob: 940d9bc1681aba88e8d13ce27473d3a214776b28 [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 Schuchardt6982e6b2023-08-02 22:39:46 +020030 { 7, "Xen Project" },
31 { 8, "PolarFire Hart Software Services" },
Heinrich Schuchardt7fd892b2021-01-19 19:44:45 +000032};
33
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020034static struct sbi_ext extensions[] = {
Heinrich Schuchardtf22db442022-10-04 10:09:54 +020035 { SBI_EXT_0_1_SET_TIMER, "Set Timer" },
36 { SBI_EXT_0_1_CONSOLE_PUTCHAR, "Console Putchar" },
37 { SBI_EXT_0_1_CONSOLE_GETCHAR, "Console Getchar" },
38 { SBI_EXT_0_1_CLEAR_IPI, "Clear IPI" },
39 { SBI_EXT_0_1_SEND_IPI, "Send IPI" },
40 { SBI_EXT_0_1_REMOTE_FENCE_I, "Remote FENCE.I" },
41 { SBI_EXT_0_1_REMOTE_SFENCE_VMA, "Remote SFENCE.VMA" },
42 { SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID, "Remote SFENCE.VMA with ASID" },
43 { SBI_EXT_0_1_SHUTDOWN, "System Shutdown" },
Heinrich Schuchardt09d7cc32021-09-12 21:11:45 +020044 { SBI_EXT_BASE, "SBI Base Functionality" },
45 { SBI_EXT_TIME, "Timer Extension" },
46 { SBI_EXT_IPI, "IPI Extension" },
47 { SBI_EXT_RFENCE, "RFENCE Extension" },
48 { SBI_EXT_HSM, "Hart State Management Extension" },
49 { SBI_EXT_SRST, "System Reset Extension" },
Heinrich Schuchardt70ae54b2022-03-16 21:21:18 +010050 { SBI_EXT_PMU, "Performance Monitoring Unit Extension" },
Heinrich Schuchardt79061552023-04-12 10:38:16 +020051 { SBI_EXT_DBCN, "Debug Console Extension" },
52 { SBI_EXT_SUSP, "System Suspend Extension" },
53 { SBI_EXT_CPPC, "Collaborative Processor Performance Control Extension" },
Heinrich Schuchardt6982e6b2023-08-02 22:39:46 +020054 { SBI_EXT_NACL, "Nested Acceleration Extension" },
55 { SBI_EXT_STA, "Steal-time Accounting Extension" },
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020056};
57
58static int do_sbi(struct cmd_tbl *cmdtp, int flag, int argc,
59 char *const argv[])
60{
Heinrich Schuchardt89a86dc2021-10-25 15:09:35 +020061 int i, impl_id;
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020062 long ret;
Heinrich Schuchardtcfb31e02022-03-17 07:36:15 +010063 long mvendorid, marchid, mimpid;
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020064
65 ret = sbi_get_spec_version();
Heinrich Schuchardt72c1f5f2022-10-04 10:09:53 +020066 if (ret < 0) {
67 printf("No SBI 0.2+\n");
68 return CMD_RET_FAILURE;
69 }
70 printf("SBI %ld.%ld", ret >> 24, ret & 0xffffff);
Heinrich Schuchardt89a86dc2021-10-25 15:09:35 +020071 impl_id = sbi_get_impl_id();
72 if (impl_id >= 0) {
Heinrich Schuchardt7fd892b2021-01-19 19:44:45 +000073 for (i = 0; i < ARRAY_SIZE(implementations); ++i) {
Heinrich Schuchardt89a86dc2021-10-25 15:09:35 +020074 if (impl_id == implementations[i].id) {
75 long vers;
76
77 printf("\n%s ", implementations[i].name);
78 ret = sbi_get_impl_version(&vers);
79 if (ret < 0)
80 break;
Heinrich Schuchardtaa8aa482022-08-14 21:57:14 +020081 switch (impl_id) {
82 case 1: /* OpenSBI */
Heinrich Schuchardt89a86dc2021-10-25 15:09:35 +020083 printf("%ld.%ld",
84 vers >> 16, vers & 0xffff);
Heinrich Schuchardtaa8aa482022-08-14 21:57:14 +020085 break;
86 case 3: /* KVM */
Heinrich Schuchardt94877642022-10-04 10:09:52 +020087 case 4: /* RustSBI */
Heinrich Schuchardtaa8aa482022-08-14 21:57:14 +020088 printf("%ld.%ld.%ld",
89 vers >> 16,
90 (vers >> 8) & 0xff,
91 vers & 0xff);
92 break;
93 default:
Heinrich Schuchardt89a86dc2021-10-25 15:09:35 +020094 printf("0x%lx", vers);
Heinrich Schuchardtaa8aa482022-08-14 21:57:14 +020095 break;
96 }
Heinrich Schuchardt7fd892b2021-01-19 19:44:45 +000097 break;
98 }
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +020099 }
Heinrich Schuchardt7fd892b2021-01-19 19:44:45 +0000100 if (i == ARRAY_SIZE(implementations))
Heinrich Schuchardt89a86dc2021-10-25 15:09:35 +0200101 printf("Unknown implementation ID %ld", ret);
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +0200102 }
Heinrich Schuchardtcfb31e02022-03-17 07:36:15 +0100103 printf("\nMachine:\n");
104 ret = sbi_get_mvendorid(&mvendorid);
105 if (!ret)
106 printf(" Vendor ID %lx\n", mvendorid);
107 ret = sbi_get_marchid(&marchid);
108 if (!ret)
109 printf(" Architecture ID %lx\n", marchid);
110 ret = sbi_get_mimpid(&mimpid);
111 if (!ret)
112 printf(" Implementation ID %lx\n", mimpid);
113 printf("Extensions:\n");
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +0200114 for (i = 0; i < ARRAY_SIZE(extensions); ++i) {
115 ret = sbi_probe_extension(extensions[i].id);
116 if (ret > 0)
117 printf(" %s\n", extensions[i].name);
118 }
119 return 0;
120}
121
Tom Rini36162182023-10-07 15:13:08 -0400122U_BOOT_LONGHELP(sbi,
123 "- display SBI spec version, implementation, and available extensions");
Heinrich Schuchardtc92b50a2020-08-20 19:43:39 +0200124
125U_BOOT_CMD_COMPLETE(
126 sbi, 1, 0, do_sbi,
127 "display SBI information",
128 sbi_help_text, NULL
129);