Heinrich Schuchardt | c92b50a | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 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 | |
Heinrich Schuchardt | 7fd892b | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 12 | struct sbi_imp { |
| 13 | const long id; |
| 14 | const char *name; |
| 15 | }; |
| 16 | |
Heinrich Schuchardt | c92b50a | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 17 | struct sbi_ext { |
| 18 | const u32 id; |
| 19 | const char *name; |
| 20 | }; |
| 21 | |
Heinrich Schuchardt | 7fd892b | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 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" }, |
Heinrich Schuchardt | 73872eb | 2022-05-07 14:42:10 +0200 | [diff] [blame] | 29 | { 6, "Coffer" }, |
Heinrich Schuchardt | 7fd892b | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
Heinrich Schuchardt | c92b50a | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 32 | static struct sbi_ext extensions[] = { |
Heinrich Schuchardt | f22db44 | 2022-10-04 10:09:54 +0200 | [diff] [blame] | 33 | { SBI_EXT_0_1_SET_TIMER, "Set Timer" }, |
| 34 | { SBI_EXT_0_1_CONSOLE_PUTCHAR, "Console Putchar" }, |
| 35 | { SBI_EXT_0_1_CONSOLE_GETCHAR, "Console Getchar" }, |
| 36 | { SBI_EXT_0_1_CLEAR_IPI, "Clear IPI" }, |
| 37 | { SBI_EXT_0_1_SEND_IPI, "Send IPI" }, |
| 38 | { SBI_EXT_0_1_REMOTE_FENCE_I, "Remote FENCE.I" }, |
| 39 | { SBI_EXT_0_1_REMOTE_SFENCE_VMA, "Remote SFENCE.VMA" }, |
| 40 | { SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID, "Remote SFENCE.VMA with ASID" }, |
| 41 | { SBI_EXT_0_1_SHUTDOWN, "System Shutdown" }, |
Heinrich Schuchardt | 09d7cc3 | 2021-09-12 21:11:45 +0200 | [diff] [blame] | 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 Schuchardt | 70ae54b | 2022-03-16 21:21:18 +0100 | [diff] [blame] | 48 | { SBI_EXT_PMU, "Performance Monitoring Unit Extension" }, |
Heinrich Schuchardt | 7906155 | 2023-04-12 10:38:16 +0200 | [diff] [blame] | 49 | { SBI_EXT_DBCN, "Debug Console Extension" }, |
| 50 | { SBI_EXT_SUSP, "System Suspend Extension" }, |
| 51 | { SBI_EXT_CPPC, "Collaborative Processor Performance Control Extension" }, |
Heinrich Schuchardt | c92b50a | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | static int do_sbi(struct cmd_tbl *cmdtp, int flag, int argc, |
| 55 | char *const argv[]) |
| 56 | { |
Heinrich Schuchardt | 89a86dc | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 57 | int i, impl_id; |
Heinrich Schuchardt | c92b50a | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 58 | long ret; |
Heinrich Schuchardt | cfb31e0 | 2022-03-17 07:36:15 +0100 | [diff] [blame] | 59 | long mvendorid, marchid, mimpid; |
Heinrich Schuchardt | c92b50a | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 60 | |
| 61 | ret = sbi_get_spec_version(); |
Heinrich Schuchardt | 72c1f5f | 2022-10-04 10:09:53 +0200 | [diff] [blame] | 62 | if (ret < 0) { |
| 63 | printf("No SBI 0.2+\n"); |
| 64 | return CMD_RET_FAILURE; |
| 65 | } |
| 66 | printf("SBI %ld.%ld", ret >> 24, ret & 0xffffff); |
Heinrich Schuchardt | 89a86dc | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 67 | impl_id = sbi_get_impl_id(); |
| 68 | if (impl_id >= 0) { |
Heinrich Schuchardt | 7fd892b | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 69 | for (i = 0; i < ARRAY_SIZE(implementations); ++i) { |
Heinrich Schuchardt | 89a86dc | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 70 | if (impl_id == implementations[i].id) { |
| 71 | long vers; |
| 72 | |
| 73 | printf("\n%s ", implementations[i].name); |
| 74 | ret = sbi_get_impl_version(&vers); |
| 75 | if (ret < 0) |
| 76 | break; |
Heinrich Schuchardt | aa8aa48 | 2022-08-14 21:57:14 +0200 | [diff] [blame] | 77 | switch (impl_id) { |
| 78 | case 1: /* OpenSBI */ |
Heinrich Schuchardt | 89a86dc | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 79 | printf("%ld.%ld", |
| 80 | vers >> 16, vers & 0xffff); |
Heinrich Schuchardt | aa8aa48 | 2022-08-14 21:57:14 +0200 | [diff] [blame] | 81 | break; |
| 82 | case 3: /* KVM */ |
Heinrich Schuchardt | 9487764 | 2022-10-04 10:09:52 +0200 | [diff] [blame] | 83 | case 4: /* RustSBI */ |
Heinrich Schuchardt | aa8aa48 | 2022-08-14 21:57:14 +0200 | [diff] [blame] | 84 | printf("%ld.%ld.%ld", |
| 85 | vers >> 16, |
| 86 | (vers >> 8) & 0xff, |
| 87 | vers & 0xff); |
| 88 | break; |
| 89 | default: |
Heinrich Schuchardt | 89a86dc | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 90 | printf("0x%lx", vers); |
Heinrich Schuchardt | aa8aa48 | 2022-08-14 21:57:14 +0200 | [diff] [blame] | 91 | break; |
| 92 | } |
Heinrich Schuchardt | 7fd892b | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 93 | break; |
| 94 | } |
Heinrich Schuchardt | c92b50a | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 95 | } |
Heinrich Schuchardt | 7fd892b | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 96 | if (i == ARRAY_SIZE(implementations)) |
Heinrich Schuchardt | 89a86dc | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 97 | printf("Unknown implementation ID %ld", ret); |
Heinrich Schuchardt | c92b50a | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 98 | } |
Heinrich Schuchardt | cfb31e0 | 2022-03-17 07:36:15 +0100 | [diff] [blame] | 99 | printf("\nMachine:\n"); |
| 100 | ret = sbi_get_mvendorid(&mvendorid); |
| 101 | if (!ret) |
| 102 | printf(" Vendor ID %lx\n", mvendorid); |
| 103 | ret = sbi_get_marchid(&marchid); |
| 104 | if (!ret) |
| 105 | printf(" Architecture ID %lx\n", marchid); |
| 106 | ret = sbi_get_mimpid(&mimpid); |
| 107 | if (!ret) |
| 108 | printf(" Implementation ID %lx\n", mimpid); |
| 109 | printf("Extensions:\n"); |
Heinrich Schuchardt | c92b50a | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 110 | for (i = 0; i < ARRAY_SIZE(extensions); ++i) { |
| 111 | ret = sbi_probe_extension(extensions[i].id); |
| 112 | if (ret > 0) |
| 113 | printf(" %s\n", extensions[i].name); |
| 114 | } |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | #ifdef CONFIG_SYS_LONGHELP |
| 119 | static char sbi_help_text[] = |
| 120 | "- display SBI spec version, implementation, and available extensions"; |
| 121 | |
| 122 | #endif |
| 123 | |
| 124 | U_BOOT_CMD_COMPLETE( |
| 125 | sbi, 1, 0, do_sbi, |
| 126 | "display SBI information", |
| 127 | sbi_help_text, NULL |
| 128 | ); |