Heinrich Schuchardt | 95492ae | 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 | |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 8 | #include <command.h> |
| 9 | #include <asm/sbi.h> |
| 10 | |
Heinrich Schuchardt | 89f8267 | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 11 | struct sbi_imp { |
| 12 | const long id; |
| 13 | const char *name; |
| 14 | }; |
| 15 | |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 16 | struct sbi_ext { |
| 17 | const u32 id; |
| 18 | const char *name; |
| 19 | }; |
| 20 | |
Heinrich Schuchardt | 89f8267 | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 21 | static struct sbi_imp implementations[] = { |
| 22 | { 0, "Berkeley Boot Loader (BBL)" }, |
| 23 | { 1, "OpenSBI" }, |
| 24 | { 2, "Xvisor" }, |
| 25 | { 3, "KVM" }, |
| 26 | { 4, "RustSBI" }, |
| 27 | { 5, "Diosix" }, |
Heinrich Schuchardt | 9e2550f | 2022-05-07 14:42:10 +0200 | [diff] [blame] | 28 | { 6, "Coffer" }, |
Heinrich Schuchardt | 70884d7 | 2023-08-02 22:39:46 +0200 | [diff] [blame] | 29 | { 7, "Xen Project" }, |
| 30 | { 8, "PolarFire Hart Software Services" }, |
Heinrich Schuchardt | 9f251d1 | 2024-04-17 16:01:28 +0200 | [diff] [blame] | 31 | { 9, "coreboot" }, |
| 32 | { 10, "oreboot" }, |
Heinrich Schuchardt | 89f8267 | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 35 | static struct sbi_ext extensions[] = { |
Heinrich Schuchardt | 2396ca7 | 2022-10-04 10:09:54 +0200 | [diff] [blame] | 36 | { SBI_EXT_0_1_SET_TIMER, "Set Timer" }, |
| 37 | { SBI_EXT_0_1_CONSOLE_PUTCHAR, "Console Putchar" }, |
| 38 | { SBI_EXT_0_1_CONSOLE_GETCHAR, "Console Getchar" }, |
| 39 | { SBI_EXT_0_1_CLEAR_IPI, "Clear IPI" }, |
| 40 | { SBI_EXT_0_1_SEND_IPI, "Send IPI" }, |
| 41 | { SBI_EXT_0_1_REMOTE_FENCE_I, "Remote FENCE.I" }, |
| 42 | { SBI_EXT_0_1_REMOTE_SFENCE_VMA, "Remote SFENCE.VMA" }, |
| 43 | { SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID, "Remote SFENCE.VMA with ASID" }, |
| 44 | { SBI_EXT_0_1_SHUTDOWN, "System Shutdown" }, |
Heinrich Schuchardt | b36bc1c | 2021-09-12 21:11:45 +0200 | [diff] [blame] | 45 | { SBI_EXT_BASE, "SBI Base Functionality" }, |
| 46 | { SBI_EXT_TIME, "Timer Extension" }, |
| 47 | { SBI_EXT_IPI, "IPI Extension" }, |
| 48 | { SBI_EXT_RFENCE, "RFENCE Extension" }, |
| 49 | { SBI_EXT_HSM, "Hart State Management Extension" }, |
| 50 | { SBI_EXT_SRST, "System Reset Extension" }, |
Heinrich Schuchardt | 295e1ce | 2022-03-16 21:21:18 +0100 | [diff] [blame] | 51 | { SBI_EXT_PMU, "Performance Monitoring Unit Extension" }, |
Heinrich Schuchardt | cd464d1 | 2023-04-12 10:38:16 +0200 | [diff] [blame] | 52 | { SBI_EXT_DBCN, "Debug Console Extension" }, |
| 53 | { SBI_EXT_SUSP, "System Suspend Extension" }, |
| 54 | { SBI_EXT_CPPC, "Collaborative Processor Performance Control Extension" }, |
Heinrich Schuchardt | 70884d7 | 2023-08-02 22:39:46 +0200 | [diff] [blame] | 55 | { SBI_EXT_NACL, "Nested Acceleration Extension" }, |
| 56 | { SBI_EXT_STA, "Steal-time Accounting Extension" }, |
Heinrich Schuchardt | 35b0d18 | 2024-01-17 17:46:52 +0100 | [diff] [blame] | 57 | { SBI_EXT_DBTR, "Debug Trigger Extension" }, |
Heinrich Schuchardt | 85efa4e | 2024-04-17 16:01:27 +0200 | [diff] [blame] | 58 | { SBI_EXT_SSE, "Supervisor Software Events" }, |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | static int do_sbi(struct cmd_tbl *cmdtp, int flag, int argc, |
| 62 | char *const argv[]) |
| 63 | { |
Heinrich Schuchardt | 9607674 | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 64 | int i, impl_id; |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 65 | long ret; |
Heinrich Schuchardt | fdc7577 | 2022-03-17 07:36:15 +0100 | [diff] [blame] | 66 | long mvendorid, marchid, mimpid; |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 67 | |
| 68 | ret = sbi_get_spec_version(); |
Heinrich Schuchardt | a375178 | 2022-10-04 10:09:53 +0200 | [diff] [blame] | 69 | if (ret < 0) { |
| 70 | printf("No SBI 0.2+\n"); |
| 71 | return CMD_RET_FAILURE; |
| 72 | } |
| 73 | printf("SBI %ld.%ld", ret >> 24, ret & 0xffffff); |
Heinrich Schuchardt | 9607674 | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 74 | impl_id = sbi_get_impl_id(); |
| 75 | if (impl_id >= 0) { |
Heinrich Schuchardt | 89f8267 | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 76 | for (i = 0; i < ARRAY_SIZE(implementations); ++i) { |
Heinrich Schuchardt | 9607674 | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 77 | if (impl_id == implementations[i].id) { |
| 78 | long vers; |
| 79 | |
| 80 | printf("\n%s ", implementations[i].name); |
| 81 | ret = sbi_get_impl_version(&vers); |
| 82 | if (ret < 0) |
| 83 | break; |
Heinrich Schuchardt | c8ed628 | 2022-08-14 21:57:14 +0200 | [diff] [blame] | 84 | switch (impl_id) { |
| 85 | case 1: /* OpenSBI */ |
Heinrich Schuchardt | d66844d | 2024-03-06 15:48:52 +0100 | [diff] [blame] | 86 | case 8: /* PolarFire Hart Software Services */ |
Heinrich Schuchardt | 9607674 | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 87 | printf("%ld.%ld", |
| 88 | vers >> 16, vers & 0xffff); |
Heinrich Schuchardt | c8ed628 | 2022-08-14 21:57:14 +0200 | [diff] [blame] | 89 | break; |
| 90 | case 3: /* KVM */ |
Heinrich Schuchardt | 933c6f3 | 2022-10-04 10:09:52 +0200 | [diff] [blame] | 91 | case 4: /* RustSBI */ |
Heinrich Schuchardt | c8ed628 | 2022-08-14 21:57:14 +0200 | [diff] [blame] | 92 | printf("%ld.%ld.%ld", |
| 93 | vers >> 16, |
| 94 | (vers >> 8) & 0xff, |
| 95 | vers & 0xff); |
| 96 | break; |
| 97 | default: |
Heinrich Schuchardt | 9607674 | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 98 | printf("0x%lx", vers); |
Heinrich Schuchardt | c8ed628 | 2022-08-14 21:57:14 +0200 | [diff] [blame] | 99 | break; |
| 100 | } |
Heinrich Schuchardt | 89f8267 | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 101 | break; |
| 102 | } |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 103 | } |
Heinrich Schuchardt | 89f8267 | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 104 | if (i == ARRAY_SIZE(implementations)) |
Heinrich Schuchardt | 6e53e1d | 2024-03-06 15:44:02 +0100 | [diff] [blame] | 105 | printf("\nUnknown implementation ID 0x%x", impl_id); |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 106 | } |
Heinrich Schuchardt | fdc7577 | 2022-03-17 07:36:15 +0100 | [diff] [blame] | 107 | printf("\nMachine:\n"); |
| 108 | ret = sbi_get_mvendorid(&mvendorid); |
| 109 | if (!ret) |
| 110 | printf(" Vendor ID %lx\n", mvendorid); |
| 111 | ret = sbi_get_marchid(&marchid); |
| 112 | if (!ret) |
| 113 | printf(" Architecture ID %lx\n", marchid); |
| 114 | ret = sbi_get_mimpid(&mimpid); |
| 115 | if (!ret) |
| 116 | printf(" Implementation ID %lx\n", mimpid); |
| 117 | printf("Extensions:\n"); |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 118 | for (i = 0; i < ARRAY_SIZE(extensions); ++i) { |
| 119 | ret = sbi_probe_extension(extensions[i].id); |
| 120 | if (ret > 0) |
| 121 | printf(" %s\n", extensions[i].name); |
| 122 | } |
| 123 | return 0; |
| 124 | } |
| 125 | |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 126 | U_BOOT_LONGHELP(sbi, |
| 127 | "- display SBI spec version, implementation, and available extensions"); |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 128 | |
| 129 | U_BOOT_CMD_COMPLETE( |
| 130 | sbi, 1, 0, do_sbi, |
| 131 | "display SBI information", |
| 132 | sbi_help_text, NULL |
| 133 | ); |