fw_dynamic.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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, FW_DYNAMIC_INFO_VERSION_2
  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. /* Save version == 0x1 fields */
  54. lla a4, _dynamic_next_addr
  55. REG_L a3, FW_DYNAMIC_INFO_NEXT_ADDR_OFFSET(a2)
  56. REG_S a3, (a4)
  57. lla a4, _dynamic_next_mode
  58. REG_L a3, FW_DYNAMIC_INFO_NEXT_MODE_OFFSET(a2)
  59. REG_S a3, (a4)
  60. lla a4, _dynamic_options
  61. REG_L a3, FW_DYNAMIC_INFO_OPTIONS_OFFSET(a2)
  62. REG_S a3, (a4)
  63. /* Save version == 0x2 fields */
  64. li a4, FW_DYNAMIC_INFO_VERSION_2
  65. REG_L a3, FW_DYNAMIC_INFO_VERSION_OFFSET(a2)
  66. blt a3, a4, 2f
  67. lla a4, _dynamic_boot_hart
  68. REG_L a3, FW_DYNAMIC_INFO_BOOT_HART_OFFSET(a2)
  69. REG_S a3, (a4)
  70. 2:
  71. ret
  72. .section .entry, "ax", %progbits
  73. .align 3
  74. .global fw_next_arg1
  75. /*
  76. * We can only use a0, a1, and a2 registers here.
  77. * The a0, a1, and a2 registers will be same as passed by
  78. * previous booting stage.
  79. * The next arg1 should be returned in 'a0'.
  80. */
  81. fw_next_arg1:
  82. lla a0, _dynamic_next_arg1
  83. REG_L a0, (a0)
  84. ret
  85. .section .entry, "ax", %progbits
  86. .align 3
  87. .global fw_next_addr
  88. /*
  89. * We can only use a0, a1, and a2 registers here.
  90. * The next address should be returned in 'a0'.
  91. */
  92. fw_next_addr:
  93. lla a0, _dynamic_next_addr
  94. REG_L a0, (a0)
  95. ret
  96. .section .entry, "ax", %progbits
  97. .align 3
  98. .global fw_next_mode
  99. /*
  100. * We can only use a0, a1, and a2 registers here.
  101. * The next address should be returned in 'a0'
  102. */
  103. fw_next_mode:
  104. lla a0, _dynamic_next_mode
  105. REG_L a0, (a0)
  106. ret
  107. .section .entry, "ax", %progbits
  108. .align 3
  109. .global fw_options
  110. /*
  111. * We can only use a0, a1, and a2 registers here.
  112. * The 'a4' register will have default options.
  113. * The next address should be returned in 'a0'.
  114. */
  115. fw_options:
  116. lla a0, _dynamic_options
  117. REG_L a0, (a0)
  118. ret
  119. .section .entry, "ax", %progbits
  120. .align 3
  121. _dynamic_next_arg1:
  122. RISCV_PTR 0x0
  123. _dynamic_next_addr:
  124. RISCV_PTR 0x0
  125. _dynamic_next_mode:
  126. RISCV_PTR PRV_S
  127. _dynamic_options:
  128. RISCV_PTR 0x0
  129. _dynamic_boot_hart:
  130. RISCV_PTR -1