blob: 87f7966f06bb64a725922f5a1edeefe2bd5dabdc [file] [log] [blame]
Heinrich Schuchardt95492ae2020-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 Schuchardt89f82672021-01-19 19:44:45 +000012struct sbi_imp {
13 const long id;
14 const char *name;
15};
16
Heinrich Schuchardt95492ae2020-08-20 19:43:39 +020017struct sbi_ext {
18 const u32 id;
19 const char *name;
20};
21
Heinrich Schuchardt89f82672021-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 Schuchardt9e2550f2022-05-07 14:42:10 +020029 { 6, "Coffer" },
Heinrich Schuchardt70884d72023-08-02 22:39:46 +020030 { 7, "Xen Project" },
31 { 8, "PolarFire Hart Software Services" },
Heinrich Schuchardt89f82672021-01-19 19:44:45 +000032};
33
Heinrich Schuchardt95492ae2020-08-20 19:43:39 +020034static struct sbi_ext extensions[] = {
Heinrich Schuchardt2396ca72022-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 Schuchardtb36bc1c2021-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 Schuchardt295e1ce2022-03-16 21:21:18 +010050 { SBI_EXT_PMU, "Performance Monitoring Unit Extension" },
Heinrich Schuchardtcd464d12023-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 Schuchardt70884d72023-08-02 22:39:46 +020054 { SBI_EXT_NACL, "Nested Acceleration Extension" },
55 { SBI_EXT_STA, "Steal-time Accounting Extension" },
Heinrich Schuchardt35b0d182024-01-17 17:46:52 +010056 { SBI_EXT_DBTR, "Debug Trigger Extension" },
Heinrich Schuchardt95492ae2020-08-20 19:43:39 +020057};
58
59static int do_sbi(struct cmd_tbl *cmdtp, int flag, int argc,
60 char *const argv[])
61{
Heinrich Schuchardt96076742021-10-25 15:09:35 +020062 int i, impl_id;
Heinrich Schuchardt95492ae2020-08-20 19:43:39 +020063 long ret;
Heinrich Schuchardtfdc75772022-03-17 07:36:15 +010064 long mvendorid, marchid, mimpid;
Heinrich Schuchardt95492ae2020-08-20 19:43:39 +020065
66 ret = sbi_get_spec_version();
Heinrich Schuchardta3751782022-10-04 10:09:53 +020067 if (ret < 0) {
68 printf("No SBI 0.2+\n");
69 return CMD_RET_FAILURE;
70 }
71 printf("SBI %ld.%ld", ret >> 24, ret & 0xffffff);
Heinrich Schuchardt96076742021-10-25 15:09:35 +020072 impl_id = sbi_get_impl_id();
73 if (impl_id >= 0) {
Heinrich Schuchardt89f82672021-01-19 19:44:45 +000074 for (i = 0; i < ARRAY_SIZE(implementations); ++i) {
Heinrich Schuchardt96076742021-10-25 15:09:35 +020075 if (impl_id == implementations[i].id) {
76 long vers;
77
78 printf("\n%s ", implementations[i].name);
79 ret = sbi_get_impl_version(&vers);
80 if (ret < 0)
81 break;
Heinrich Schuchardtc8ed6282022-08-14 21:57:14 +020082 switch (impl_id) {
83 case 1: /* OpenSBI */
Heinrich Schuchardt96076742021-10-25 15:09:35 +020084 printf("%ld.%ld",
85 vers >> 16, vers & 0xffff);
Heinrich Schuchardtc8ed6282022-08-14 21:57:14 +020086 break;
87 case 3: /* KVM */
Heinrich Schuchardt933c6f32022-10-04 10:09:52 +020088 case 4: /* RustSBI */
Heinrich Schuchardtc8ed6282022-08-14 21:57:14 +020089 printf("%ld.%ld.%ld",
90 vers >> 16,
91 (vers >> 8) & 0xff,
92 vers & 0xff);
93 break;
94 default:
Heinrich Schuchardt96076742021-10-25 15:09:35 +020095 printf("0x%lx", vers);
Heinrich Schuchardtc8ed6282022-08-14 21:57:14 +020096 break;
97 }
Heinrich Schuchardt89f82672021-01-19 19:44:45 +000098 break;
99 }
Heinrich Schuchardt95492ae2020-08-20 19:43:39 +0200100 }
Heinrich Schuchardt89f82672021-01-19 19:44:45 +0000101 if (i == ARRAY_SIZE(implementations))
Heinrich Schuchardt6e53e1d2024-03-06 15:44:02 +0100102 printf("\nUnknown implementation ID 0x%x", impl_id);
Heinrich Schuchardt95492ae2020-08-20 19:43:39 +0200103 }
Heinrich Schuchardtfdc75772022-03-17 07:36:15 +0100104 printf("\nMachine:\n");
105 ret = sbi_get_mvendorid(&mvendorid);
106 if (!ret)
107 printf(" Vendor ID %lx\n", mvendorid);
108 ret = sbi_get_marchid(&marchid);
109 if (!ret)
110 printf(" Architecture ID %lx\n", marchid);
111 ret = sbi_get_mimpid(&mimpid);
112 if (!ret)
113 printf(" Implementation ID %lx\n", mimpid);
114 printf("Extensions:\n");
Heinrich Schuchardt95492ae2020-08-20 19:43:39 +0200115 for (i = 0; i < ARRAY_SIZE(extensions); ++i) {
116 ret = sbi_probe_extension(extensions[i].id);
117 if (ret > 0)
118 printf(" %s\n", extensions[i].name);
119 }
120 return 0;
121}
122
Tom Rini03f146c2023-10-07 15:13:08 -0400123U_BOOT_LONGHELP(sbi,
124 "- display SBI spec version, implementation, and available extensions");
Heinrich Schuchardt95492ae2020-08-20 19:43:39 +0200125
126U_BOOT_CMD_COMPLETE(
127 sbi, 1, 0, do_sbi,
128 "display SBI information",
129 sbi_help_text, NULL
130);