sbi.c 2.0 KB

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