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[] = { |
| 32 | { 0x00000000, "sbi_set_timer" }, |
| 33 | { 0x00000001, "sbi_console_putchar" }, |
| 34 | { 0x00000002, "sbi_console_getchar" }, |
| 35 | { 0x00000003, "sbi_clear_ipi" }, |
| 36 | { 0x00000004, "sbi_send_ipi" }, |
| 37 | { 0x00000005, "sbi_remote_fence_i" }, |
| 38 | { 0x00000006, "sbi_remote_sfence_vma" }, |
| 39 | { 0x00000007, "sbi_remote_sfence_vma_asid" }, |
| 40 | { 0x00000008, "sbi_shutdown" }, |
| 41 | { 0x00000010, "SBI Base Functionality" }, |
| 42 | { 0x54494D45, "Timer Extension" }, |
| 43 | { 0x00735049, "IPI Extension" }, |
| 44 | { 0x52464E43, "RFENCE Extension" }, |
| 45 | { 0x0048534D, "Hart State Management Extension" }, |
| 46 | }; |
| 47 | |
| 48 | static int do_sbi(struct cmd_tbl *cmdtp, int flag, int argc, |
| 49 | char *const argv[]) |
| 50 | { |
| 51 | int i; |
| 52 | long ret; |
| 53 | |
| 54 | ret = sbi_get_spec_version(); |
| 55 | if (ret >= 0) |
| 56 | printf("SBI %ld.%ld\n", ret >> 24, ret & 0xffffff); |
| 57 | ret = sbi_get_impl_id(); |
| 58 | if (ret >= 0) { |
Heinrich Schuchardt | 89f8267 | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 59 | for (i = 0; i < ARRAY_SIZE(implementations); ++i) { |
| 60 | if (ret == implementations[i].id) { |
| 61 | printf("%s\n", implementations[i].name); |
| 62 | break; |
| 63 | } |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 64 | } |
Heinrich Schuchardt | 89f8267 | 2021-01-19 19:44:45 +0000 | [diff] [blame] | 65 | if (i == ARRAY_SIZE(implementations)) |
| 66 | printf("Unknown implementation ID %ld\n", ret); |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 67 | } |
| 68 | printf("Extensions:\n"); |
| 69 | for (i = 0; i < ARRAY_SIZE(extensions); ++i) { |
| 70 | ret = sbi_probe_extension(extensions[i].id); |
| 71 | if (ret > 0) |
| 72 | printf(" %s\n", extensions[i].name); |
| 73 | } |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | #ifdef CONFIG_SYS_LONGHELP |
| 78 | static char sbi_help_text[] = |
| 79 | "- display SBI spec version, implementation, and available extensions"; |
| 80 | |
| 81 | #endif |
| 82 | |
| 83 | U_BOOT_CMD_COMPLETE( |
| 84 | sbi, 1, 0, do_sbi, |
| 85 | "display SBI information", |
| 86 | sbi_help_text, NULL |
| 87 | ); |