platform.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. */
  6. #include <sbi/riscv_encoding.h>
  7. #include <sbi/sbi_const.h>
  8. #include <sbi/sbi_platform.h>
  9. /*
  10. * Include these files as needed.
  11. * See config.mk PLATFORM_xxx configuration parameters.
  12. */
  13. #include <plat/irqchip/plic.h>
  14. #include <plat/serial/uart8250.h>
  15. #include <plat/sys/clint.h>
  16. /*
  17. * Platform early initialization.
  18. */
  19. static int platform_early_init(bool cold_boot)
  20. {
  21. return 0;
  22. }
  23. /*
  24. * Platform final initialization.
  25. */
  26. static int platform_final_init(bool cold_boot)
  27. {
  28. return 0;
  29. }
  30. /*
  31. * Get number of PMP regions for given HART.
  32. */
  33. static u32 platform_pmp_region_count(u32 hartid)
  34. {
  35. return 0;
  36. }
  37. /*
  38. * Get PMP regions details (namely: protection, base address, and size) for
  39. * a given HART.
  40. */
  41. static int platform_pmp_region_info(u32 hartid, u32 index, ulong *prot,
  42. ulong *addr, ulong *log2size)
  43. {
  44. return 0;
  45. }
  46. /*
  47. * Initialize the platform console.
  48. */
  49. static int platform_console_init(void)
  50. {
  51. /* Example if the generic UART8250 driver is used */
  52. return uart8250_init(PLATFORM_UART_ADDR, PLATFORM_UART_SHIFTREG_ADDR,
  53. PLATFORM_UART_BAUDRATE, 0, 1);
  54. }
  55. /*
  56. * Write a character to the platform console output.
  57. */
  58. static void platform_console_putc(char ch)
  59. {
  60. /* Example if the generic UART8250 driver is used */
  61. uart8250_putc(ch);
  62. }
  63. /*
  64. * Read a character from the platform console input.
  65. */
  66. static int platform_console_getc(void)
  67. {
  68. return uart8250_getc();
  69. }
  70. /*
  71. * Initialize the platform interrupt controller for current HART.
  72. */
  73. static int platform_irqchip_init(bool cold_boot)
  74. {
  75. u32 hartid = sbi_current_hartid();
  76. int ret;
  77. /* Example if the generic PLIC driver is used */
  78. if (cold_boot) {
  79. ret = plic_cold_irqchip_init(PLATFORM_PLIC_ADDR,
  80. PLATFORM_PLIC_NUM_SOURCES,
  81. PLATFORM_HART_COUNT);
  82. if (ret)
  83. return ret;
  84. }
  85. return plic_warm_irqchip_init(hartid, 2 * hartid, 2 * hartid + 1);
  86. }
  87. /*
  88. * Initialize IPI for current HART.
  89. */
  90. static int platform_ipi_init(bool cold_boot)
  91. {
  92. int ret;
  93. /* Example if the generic CLINT driver is used */
  94. if (cold_boot) {
  95. ret = clint_cold_ipi_init(PLATFORM_CLINT_ADDR,
  96. PLATFORM_HART_COUNT);
  97. if (ret)
  98. return ret;
  99. }
  100. return clint_warm_ipi_init();
  101. }
  102. /*
  103. * Send IPI to a target HART
  104. */
  105. static void platform_ipi_send(u32 target_hart)
  106. {
  107. /* Example if the generic CLINT driver is used */
  108. clint_ipi_send(target_hart);
  109. }
  110. /*
  111. * Wait for target HART to acknowledge IPI.
  112. */
  113. static void platform_ipi_sync(u32 target_hart)
  114. {
  115. /* Example if the generic CLINT driver is used */
  116. clint_ipi_sync(target_hart);
  117. }
  118. /*
  119. * Clear IPI for a target HART.
  120. */
  121. static void platform_ipi_clear(u32 target_hart)
  122. {
  123. /* Example if the generic CLINT driver is used */
  124. clint_ipi_clear(target_hart);
  125. }
  126. /*
  127. * Initialize platform timer for current HART.
  128. */
  129. static int platform_timer_init(bool cold_boot)
  130. {
  131. int ret;
  132. /* Example if the generic CLINT driver is used */
  133. if (cold_boot) {
  134. ret = clint_cold_timer_init(PLATFORM_CLINT_ADDR,
  135. PLATFORM_HART_COUNT);
  136. if (ret)
  137. return ret;
  138. }
  139. return clint_warm_timer_init();
  140. }
  141. /*
  142. * Get platform timer value.
  143. */
  144. static u64 platform_timer_value(void)
  145. {
  146. /* Example if the generic CLINT driver is used */
  147. return clint_timer_value();
  148. }
  149. /*
  150. * Start platform timer event for current HART.
  151. */
  152. static void platform_timer_event_start(u64 next_event)
  153. {
  154. /* Example if the generic CLINT driver is used */
  155. clint_timer_event_start(next_event);
  156. }
  157. /*
  158. * Stop platform timer event for current HART.
  159. */
  160. static void platform_timer_event_stop(void)
  161. {
  162. /* Example if the generic CLINT driver is used */
  163. clint_timer_event_stop();
  164. }
  165. /*
  166. * Reboot the platform.
  167. */
  168. static int platform_system_reboot(u32 type)
  169. {
  170. return 0;
  171. }
  172. /*
  173. * Shutdown or poweroff the platform.
  174. */
  175. static int platform_system_shutdown(u32 type)
  176. {
  177. return 0;
  178. }
  179. /*
  180. * Platform descriptor.
  181. */
  182. const struct sbi_platform platform = {
  183. .name = "platform-name",
  184. .features = SBI_PLATFORM_DEFAULT_FEATURES,
  185. .hart_count = 1,
  186. .hart_stack_size = 4096,
  187. .disabled_hart_mask = 0,
  188. .early_init = platform_early_init,
  189. .final_init = platform_final_init,
  190. .pmp_region_count = platform_pmp_region_count,
  191. .pmp_region_info = platform_pmp_region_info,
  192. .console_init = platform_console_init,
  193. .console_putc = platform_console_putc,
  194. .console_getc = platform_console_getc,
  195. .irqchip_init = platform_irqchip_init,
  196. .ipi_init = platform_ipi_init,
  197. .ipi_send = platform_ipi_send,
  198. .ipi_sync = platform_ipi_sync,
  199. .ipi_clear = platform_ipi_clear,
  200. .timer_init = platform_timer_init,
  201. .timer_value = platform_timer_value,
  202. .timer_event_start = platform_timer_event_start,
  203. .timer_event_stop = platform_timer_event_stop,
  204. .system_reboot = platform_system_reboot,
  205. .system_shutdown = platform_system_shutdown
  206. };