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 | |
| 12 | struct sbi_ext { |
| 13 | const u32 id; |
| 14 | const char *name; |
| 15 | }; |
| 16 | |
| 17 | static struct sbi_ext extensions[] = { |
| 18 | { 0x00000000, "sbi_set_timer" }, |
| 19 | { 0x00000001, "sbi_console_putchar" }, |
| 20 | { 0x00000002, "sbi_console_getchar" }, |
| 21 | { 0x00000003, "sbi_clear_ipi" }, |
| 22 | { 0x00000004, "sbi_send_ipi" }, |
| 23 | { 0x00000005, "sbi_remote_fence_i" }, |
| 24 | { 0x00000006, "sbi_remote_sfence_vma" }, |
| 25 | { 0x00000007, "sbi_remote_sfence_vma_asid" }, |
| 26 | { 0x00000008, "sbi_shutdown" }, |
| 27 | { 0x00000010, "SBI Base Functionality" }, |
| 28 | { 0x54494D45, "Timer Extension" }, |
| 29 | { 0x00735049, "IPI Extension" }, |
| 30 | { 0x52464E43, "RFENCE Extension" }, |
| 31 | { 0x0048534D, "Hart State Management Extension" }, |
| 32 | }; |
| 33 | |
| 34 | static int do_sbi(struct cmd_tbl *cmdtp, int flag, int argc, |
| 35 | char *const argv[]) |
| 36 | { |
| 37 | int i; |
| 38 | long ret; |
| 39 | |
| 40 | ret = sbi_get_spec_version(); |
| 41 | if (ret >= 0) |
| 42 | printf("SBI %ld.%ld\n", ret >> 24, ret & 0xffffff); |
| 43 | ret = sbi_get_impl_id(); |
| 44 | if (ret >= 0) { |
| 45 | switch (ret) { |
| 46 | case 0: |
| 47 | printf("Berkeley Boot Loader (BBL)\n"); |
| 48 | break; |
| 49 | case 1: |
| 50 | printf("OpenSBI\n"); |
| 51 | break; |
| 52 | case 2: |
| 53 | printf("Xvisor\n"); |
| 54 | break; |
| 55 | case 3: |
| 56 | printf("KVM\n"); |
| 57 | break; |
| 58 | default: |
| 59 | printf("Unknown implementation\n"); |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | printf("Extensions:\n"); |
| 64 | for (i = 0; i < ARRAY_SIZE(extensions); ++i) { |
| 65 | ret = sbi_probe_extension(extensions[i].id); |
| 66 | if (ret > 0) |
| 67 | printf(" %s\n", extensions[i].name); |
| 68 | } |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | #ifdef CONFIG_SYS_LONGHELP |
| 73 | static char sbi_help_text[] = |
| 74 | "- display SBI spec version, implementation, and available extensions"; |
| 75 | |
| 76 | #endif |
| 77 | |
| 78 | U_BOOT_CMD_COMPLETE( |
| 79 | sbi, 1, 0, do_sbi, |
| 80 | "display SBI information", |
| 81 | sbi_help_text, NULL |
| 82 | ); |