sbi.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2015 Regents of the University of California
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _ASM_RISCV_SBI_H
  14. #define _ASM_RISCV_SBI_H
  15. #include <linux/types.h>
  16. #define SBI_SET_TIMER 0
  17. #define SBI_CONSOLE_PUTCHAR 1
  18. #define SBI_CONSOLE_GETCHAR 2
  19. #define SBI_CLEAR_IPI 3
  20. #define SBI_SEND_IPI 4
  21. #define SBI_REMOTE_FENCE_I 5
  22. #define SBI_REMOTE_SFENCE_VMA 6
  23. #define SBI_REMOTE_SFENCE_VMA_ASID 7
  24. #define SBI_SHUTDOWN 8
  25. #define SBI_CALL(which, arg0, arg1, arg2) ({ \
  26. register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); \
  27. register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); \
  28. register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); \
  29. register uintptr_t a7 asm ("a7") = (uintptr_t)(which); \
  30. asm volatile ("ecall" \
  31. : "+r" (a0) \
  32. : "r" (a1), "r" (a2), "r" (a7) \
  33. : "memory"); \
  34. a0; \
  35. })
  36. /* Lazy implementations until SBI is finalized */
  37. #define SBI_CALL_0(which) SBI_CALL(which, 0, 0, 0)
  38. #define SBI_CALL_1(which, arg0) SBI_CALL(which, arg0, 0, 0)
  39. #define SBI_CALL_2(which, arg0, arg1) SBI_CALL(which, arg0, arg1, 0)
  40. static inline void sbi_console_putchar(int ch)
  41. {
  42. SBI_CALL_1(SBI_CONSOLE_PUTCHAR, ch);
  43. }
  44. static inline int sbi_console_getchar(void)
  45. {
  46. return SBI_CALL_0(SBI_CONSOLE_GETCHAR);
  47. }
  48. static inline void sbi_set_timer(uint64_t stime_value)
  49. {
  50. #if __riscv_xlen == 32
  51. SBI_CALL_2(SBI_SET_TIMER, stime_value, stime_value >> 32);
  52. #else
  53. SBI_CALL_1(SBI_SET_TIMER, stime_value);
  54. #endif
  55. }
  56. static inline void sbi_shutdown(void)
  57. {
  58. SBI_CALL_0(SBI_SHUTDOWN);
  59. }
  60. static inline void sbi_clear_ipi(void)
  61. {
  62. SBI_CALL_0(SBI_CLEAR_IPI);
  63. }
  64. static inline void sbi_send_ipi(const unsigned long *hart_mask)
  65. {
  66. SBI_CALL_1(SBI_SEND_IPI, hart_mask);
  67. }
  68. static inline void sbi_remote_fence_i(const unsigned long *hart_mask)
  69. {
  70. SBI_CALL_1(SBI_REMOTE_FENCE_I, hart_mask);
  71. }
  72. static inline void sbi_remote_sfence_vma(const unsigned long *hart_mask,
  73. unsigned long start,
  74. unsigned long size)
  75. {
  76. SBI_CALL_1(SBI_REMOTE_SFENCE_VMA, hart_mask);
  77. }
  78. static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
  79. unsigned long start,
  80. unsigned long size,
  81. unsigned long asid)
  82. {
  83. SBI_CALL_1(SBI_REMOTE_SFENCE_VMA_ASID, hart_mask);
  84. }
  85. #endif