phytium_cpu_id.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Email: opensource_embedded@phytium.com.cn
  7. *
  8. * Change Logs:
  9. * Date Author Notes
  10. * 2023-07-26 huanghe first commit
  11. *
  12. */
  13. #include "fparameters.h"
  14. #ifndef __aarch64__
  15. .globl cpu_id_mapping
  16. cpu_id_mapping:
  17. #if defined(TARGET_E2000Q)
  18. cmp r0, #0 // compare cpu_id with 0
  19. beq map_cpu_id_0
  20. cmp r0, #1 // compare cpu_id with 1
  21. beq map_cpu_id_1
  22. cmp r0, #2 // compare cpu_id with 2
  23. beq map_cpu_id_2
  24. cmp r0, #3 // compare cpu_id with 3
  25. beq map_cpu_id_3
  26. mov pc, lr // no mapping needed
  27. #endif
  28. mov pc, lr // no mapping needed
  29. // Mapping for E2000Q
  30. map_cpu_id_0:
  31. mov r0, #2
  32. mov pc, lr
  33. map_cpu_id_1:
  34. mov r0, #3
  35. mov pc, lr
  36. map_cpu_id_2:
  37. mov r0, #0
  38. mov pc, lr
  39. map_cpu_id_3:
  40. mov r0, #1
  41. mov pc, lr
  42. .globl rt_asm_cpu_id
  43. rt_asm_cpu_id:
  44. // read MPIDR
  45. mov r9, lr
  46. mrc p15, 0, r0, c0, c0, 5
  47. ubfx r0, r0, #0, #12
  48. ldr r1,= CORE0_AFF
  49. cmp r0, r1
  50. beq core0
  51. #if defined(CORE1_AFF)
  52. ldr r1,= CORE1_AFF
  53. cmp r0, r1
  54. beq core1
  55. #endif
  56. #if defined(CORE2_AFF)
  57. ldr r1,= CORE2_AFF
  58. cmp r0, r1
  59. beq core2
  60. #endif
  61. #if defined(CORE3_AFF)
  62. ldr r1,= CORE3_AFF
  63. cmp r0, r1
  64. beq core3
  65. #endif
  66. b default
  67. core0:
  68. mov r0, #0
  69. b return
  70. core1:
  71. mov r0, #1
  72. b return
  73. core2:
  74. mov r0, #2
  75. b return
  76. core3:
  77. mov r0, #3
  78. b return
  79. core4:
  80. mov r0, #4
  81. b return
  82. core5:
  83. mov r0, #5
  84. b return
  85. core6:
  86. mov r0, #6
  87. b return
  88. core8:
  89. mov r0, #8
  90. b return
  91. default:
  92. and r0, r0, #15
  93. return:
  94. bl cpu_id_mapping
  95. mov pc, r9
  96. #else
  97. .globl cpu_id_mapping
  98. cpu_id_mapping:
  99. #if defined(TARGET_E2000Q)
  100. cmp x0, #0 // compare cpu_id with 0
  101. beq map_cpu_id_0
  102. cmp x0, #1 // compare cpu_id with 1
  103. beq map_cpu_id_1
  104. cmp x0, #2 // compare cpu_id with 2
  105. beq map_cpu_id_2
  106. cmp x0, #3 // compare cpu_id with 3
  107. beq map_cpu_id_3
  108. RET // no mapping needed
  109. #endif
  110. RET // no mapping needed
  111. // Mapping for E2000Q
  112. map_cpu_id_0:
  113. mov x0, #2
  114. RET
  115. map_cpu_id_1:
  116. mov x0, #3
  117. RET
  118. map_cpu_id_2:
  119. mov x0, #0
  120. RET
  121. map_cpu_id_3:
  122. mov x0, #1
  123. RET
  124. .globl rt_hw_cpu_id_set
  125. rt_hw_cpu_id_set:
  126. mov x9, lr
  127. mrs x0,MPIDR_EL1
  128. and x1, x0, #15
  129. msr tpidr_el1, x1
  130. ubfx x0, x0, #0, #12
  131. ldr x1,= CORE0_AFF
  132. cmp x0, x1
  133. beq core0
  134. #if defined(CORE1_AFF)
  135. ldr x1,= CORE1_AFF
  136. cmp x0, x1
  137. beq core1
  138. #endif
  139. #if defined(CORE2_AFF)
  140. ldr x1,= CORE2_AFF
  141. cmp x0, x1
  142. beq core2
  143. #endif
  144. #if defined(CORE3_AFF)
  145. ldr x1,= CORE3_AFF
  146. cmp x0, x1
  147. beq core3
  148. #endif
  149. b default
  150. core0:
  151. mov x0, #0
  152. b return
  153. core1:
  154. mov x0, #1
  155. b return
  156. core2:
  157. mov x0, #2
  158. b return
  159. core3:
  160. mov x0, #3
  161. b return
  162. core4:
  163. mov x0, #4
  164. b return
  165. core5:
  166. mov x0, #5
  167. b return
  168. core6:
  169. mov x0, #6
  170. b return
  171. core8:
  172. mov x0, #8
  173. b return
  174. default:
  175. and x0, x0, #15
  176. return:
  177. //bl cpu_id_mapping
  178. mov lr, x9
  179. RET
  180. #endif