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 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <asm/sbi.h> |
| 11 | |
Heinrich Schuchardt | 89f8267 | 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 | 95492ae | 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 | 89f8267 | 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" }, |
| 29 | }; |
| 30 | |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 31 | static struct sbi_ext extensions[] = { |
Heinrich Schuchardt | b36bc1c | 2021-09-12 21:11:45 +0200 | [diff] [blame] | 32 | { SBI_EXT_0_1_SET_TIMER, "sbi_set_timer" }, |
| 33 | { SBI_EXT_0_1_CONSOLE_PUTCHAR, "sbi_console_putchar" }, |
| 34 | { SBI_EXT_0_1_CONSOLE_GETCHAR, "sbi_console_getchar" }, |
| 35 | { SBI_EXT_0_1_CLEAR_IPI, "sbi_clear_ipi" }, |
| 36 | { SBI_EXT_0_1_SEND_IPI, "sbi_send_ipi" }, |
| 37 | { SBI_EXT_0_1_REMOTE_FENCE_I, "sbi_remote_fence_i" }, |
| 38 | { SBI_EXT_0_1_REMOTE_SFENCE_VMA, "sbi_remote_sfence_vma" }, |
| 39 | { SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID, "sbi_remote_sfence_vma_asid" }, |
| 40 | { SBI_EXT_0_1_SHUTDOWN, "sbi_shutdown" }, |
| 41 | { SBI_EXT_BASE, "SBI Base Functionality" }, |
| 42 | { SBI_EXT_TIME, "Timer Extension" }, |
| 43 | { SBI_EXT_IPI, "IPI Extension" }, |
| 44 | { SBI_EXT_RFENCE, "RFENCE Extension" }, |
| 45 | { SBI_EXT_HSM, "Hart State Management Extension" }, |
| 46 | { SBI_EXT_SRST, "System Reset Extension" }, |
Heinrich Schuchardt | 295e1ce | 2022-03-16 21:21:18 +0100 | [diff] [blame^] | 47 | { SBI_EXT_PMU, "Performance Monitoring Unit Extension" }, |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | static int do_sbi(struct cmd_tbl *cmdtp, int flag, int argc, |
| 51 | char *const argv[]) |
| 52 | { |
Heinrich Schuchardt | 9607674 | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 53 | int i, impl_id; |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 54 | long ret; |
| 55 | |
| 56 | ret = sbi_get_spec_version(); |
| 57 | if (ret >= 0) |
Heinrich Schuchardt | 9607674 | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 58 | printf("SBI %ld.%ld", ret >> 24, ret & 0xffffff); |
| 59 | impl_id = sbi_get_impl_id(); |
| 60 | if (impl_id >= 0) { |
Heinrich Schuchardt | 89f8267 | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 61 | for (i = 0; i < ARRAY_SIZE(implementations); ++i) { |
Heinrich Schuchardt | 9607674 | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 62 | if (impl_id == implementations[i].id) { |
| 63 | long vers; |
| 64 | |
| 65 | printf("\n%s ", implementations[i].name); |
| 66 | ret = sbi_get_impl_version(&vers); |
| 67 | if (ret < 0) |
| 68 | break; |
| 69 | if (impl_id == 1) |
| 70 | printf("%ld.%ld", |
| 71 | vers >> 16, vers & 0xffff); |
| 72 | else |
| 73 | printf("0x%lx", vers); |
Heinrich Schuchardt | 89f8267 | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 74 | break; |
| 75 | } |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 76 | } |
Heinrich Schuchardt | 89f8267 | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 77 | if (i == ARRAY_SIZE(implementations)) |
Heinrich Schuchardt | 9607674 | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 78 | printf("Unknown implementation ID %ld", ret); |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 79 | } |
Heinrich Schuchardt | 9607674 | 2021-10-25 15:09:35 +0200 | [diff] [blame] | 80 | printf("\nExtensions:\n"); |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 81 | for (i = 0; i < ARRAY_SIZE(extensions); ++i) { |
| 82 | ret = sbi_probe_extension(extensions[i].id); |
| 83 | if (ret > 0) |
| 84 | printf(" %s\n", extensions[i].name); |
| 85 | } |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | #ifdef CONFIG_SYS_LONGHELP |
| 90 | static char sbi_help_text[] = |
| 91 | "- display SBI spec version, implementation, and available extensions"; |
| 92 | |
| 93 | #endif |
| 94 | |
| 95 | U_BOOT_CMD_COMPLETE( |
| 96 | sbi, 1, 0, do_sbi, |
| 97 | "display SBI information", |
| 98 | sbi_help_text, NULL |
| 99 | ); |