fw_dynamic.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. lla 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. lla a4, _dynamic_next_addr
  62. REG_L a3, FW_DYNAMIC_INFO_NEXT_ADDR_OFFSET(a2)
  63. REG_S a3, (a4)
  64. lla a4, _dynamic_next_mode
  65. REG_L a3, FW_DYNAMIC_INFO_NEXT_MODE_OFFSET(a2)
  66. REG_S a3, (a4)
  67. lla 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. lla 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_next_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 next arg1 should be returned in 'a0'.
  87. */
  88. fw_next_arg1:
  89. lla a0, _dynamic_next_arg1
  90. REG_L a0, (a0)
  91. ret
  92. .section .entry, "ax", %progbits
  93. .align 3
  94. .global fw_next_addr
  95. /*
  96. * We can only use a0, a1, and a2 registers here.
  97. * The next address should be returned in 'a0'.
  98. */
  99. fw_next_addr:
  100. lla a0, _dynamic_next_addr
  101. REG_L a0, (a0)
  102. ret
  103. .section .entry, "ax", %progbits
  104. .align 3
  105. .global fw_next_mode
  106. /*
  107. * We can only use a0, a1, and a2 registers here.
  108. * The next address should be returned in 'a0'
  109. */
  110. fw_next_mode:
  111. lla a0, _dynamic_next_mode
  112. REG_L a0, (a0)
  113. ret
  114. .section .entry, "ax", %progbits
  115. .align 3
  116. .global fw_options
  117. /*
  118. * We can only use a0, a1, and a2 registers here.
  119. * The 'a4' register will have default options.
  120. * The next address should be returned in 'a0'.
  121. */
  122. fw_options:
  123. lla a0, _dynamic_options
  124. REG_L a0, (a0)
  125. ret
  126. .section .entry, "ax", %progbits
  127. .align 3
  128. _dynamic_next_arg1:
  129. RISCV_PTR 0x0
  130. _dynamic_next_addr:
  131. RISCV_PTR 0x0
  132. _dynamic_next_mode:
  133. RISCV_PTR PRV_S
  134. _dynamic_options:
  135. RISCV_PTR 0x0
  136. _dynamic_boot_hart:
  137. RISCV_PTR -1