fw_dynamic.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. */
  9. #include <sbi/fw_dynamic.h>
  10. #include "fw_base.S"
  11. .section .entry, "ax", %progbits
  12. .align 3
  13. _bad_dynamic_info:
  14. wfi
  15. j _bad_dynamic_info
  16. .section .entry, "ax", %progbits
  17. .align 3
  18. .global fw_boot_hart
  19. /*
  20. * This function is called very early even before
  21. * fw_save_info() is called.
  22. * We can only use a0, a1, and a2 registers here.
  23. * The boot HART id should be returned in 'a0'.
  24. */
  25. fw_boot_hart:
  26. /* Sanity checks */
  27. li a1, FW_DYNAMIC_INFO_MAGIC_VALUE
  28. REG_L a0, FW_DYNAMIC_INFO_MAGIC_OFFSET(a2)
  29. bne a0, a1, _bad_dynamic_info
  30. li a1, FW_DYNAMIC_INFO_VERSION_MAX
  31. REG_L a0, FW_DYNAMIC_INFO_VERSION_OFFSET(a2)
  32. bgt a0, a1, _bad_dynamic_info
  33. /* Read boot HART id */
  34. li a1, 0x2
  35. blt a0, a1, 2f
  36. REG_L a0, FW_DYNAMIC_INFO_BOOT_HART_OFFSET(a2)
  37. ret
  38. 2: li a0, -1
  39. ret
  40. .section .entry, "ax", %progbits
  41. .align 3
  42. .global fw_save_info
  43. /*
  44. * We can only use a0, a1, a2, a3, and a4 registers here.
  45. * The a0, a1, and a2 registers will be same as passed by
  46. * previous booting stage.
  47. * Nothing to be returned here.
  48. */
  49. fw_save_info:
  50. /* Save next arg1 in 'a1' */
  51. la a4, _dynamic_next_arg1
  52. REG_S a1, (a4)
  53. /* Sanity checks */
  54. li a4, FW_DYNAMIC_INFO_MAGIC_VALUE
  55. REG_L a3, FW_DYNAMIC_INFO_MAGIC_OFFSET(a2)
  56. bne a3, a4, _bad_dynamic_info
  57. li a4, FW_DYNAMIC_INFO_VERSION_MAX
  58. REG_L a3, FW_DYNAMIC_INFO_VERSION_OFFSET(a2)
  59. bgt a3, a4, _bad_dynamic_info
  60. /* Save version == 0x1 fields */
  61. la a4, _dynamic_next_addr
  62. REG_L a3, FW_DYNAMIC_INFO_NEXT_ADDR_OFFSET(a2)
  63. REG_S a3, (a4)
  64. la a4, _dynamic_next_mode
  65. REG_L a3, FW_DYNAMIC_INFO_NEXT_MODE_OFFSET(a2)
  66. REG_S a3, (a4)
  67. la a4, _dynamic_options
  68. REG_L a3, FW_DYNAMIC_INFO_OPTIONS_OFFSET(a2)
  69. REG_S a3, (a4)
  70. /* Save version == 0x2 fields */
  71. li a4, 0x2
  72. REG_L a3, FW_DYNAMIC_INFO_VERSION_OFFSET(a2)
  73. blt a3, a4, 2f
  74. la a4, _dynamic_boot_hart
  75. REG_L a3, FW_DYNAMIC_INFO_BOOT_HART_OFFSET(a2)
  76. REG_S a3, (a4)
  77. 2:
  78. ret
  79. .section .entry, "ax", %progbits
  80. .align 3
  81. .global fw_prev_arg1
  82. /*
  83. * We can only use a0, a1, and a2 registers here.
  84. * The a0, a1, and a2 registers will be same as passed by
  85. * previous booting stage.
  86. * The previous arg1 should be returned in 'a0'.
  87. */
  88. fw_prev_arg1:
  89. add a0, zero, zero
  90. ret
  91. .section .entry, "ax", %progbits
  92. .align 3
  93. .global fw_next_arg1
  94. /*
  95. * We can only use a0, a1, and a2 registers here.
  96. * The a0, a1, and a2 registers will be same as passed by
  97. * previous booting stage.
  98. * The next arg1 should be returned in 'a0'.
  99. */
  100. fw_next_arg1:
  101. la a0, _dynamic_next_arg1
  102. REG_L a0, (a0)
  103. ret
  104. .section .entry, "ax", %progbits
  105. .align 3
  106. .global fw_next_addr
  107. /*
  108. * We can only use a0, a1, and a2 registers here.
  109. * The next address should be returned in 'a0'.
  110. */
  111. fw_next_addr:
  112. la a0, _dynamic_next_addr
  113. REG_L a0, (a0)
  114. ret
  115. .section .entry, "ax", %progbits
  116. .align 3
  117. .global fw_next_mode
  118. /*
  119. * We can only use a0, a1, and a2 registers here.
  120. * The next address should be returned in 'a0'
  121. */
  122. fw_next_mode:
  123. la a0, _dynamic_next_mode
  124. REG_L a0, (a0)
  125. ret
  126. .section .entry, "ax", %progbits
  127. .align 3
  128. .global fw_options
  129. /*
  130. * We can only use a0, a1, and a2 registers here.
  131. * The 'a4' register will have default options.
  132. * The next address should be returned in 'a0'.
  133. */
  134. fw_options:
  135. la a0, _dynamic_options
  136. REG_L a0, (a0)
  137. ret
  138. .section .entry, "ax", %progbits
  139. .align 3
  140. _dynamic_next_arg1:
  141. RISCV_PTR 0x0
  142. _dynamic_next_addr:
  143. RISCV_PTR 0x0
  144. _dynamic_next_mode:
  145. RISCV_PTR PRV_S
  146. _dynamic_options:
  147. RISCV_PTR 0x0
  148. _dynamic_boot_hart:
  149. RISCV_PTR -1