phytium_cpu_id.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. * 2024-07-02 zhangyan modify
  12. *
  13. */
  14. #include "fparameters.h"
  15. #include "rtconfig.h"
  16. #ifndef __aarch64__
  17. .globl cpu_id_mapping
  18. cpu_id_mapping:
  19. #if defined(TARGET_PE2204)
  20. cmp r0, #0 // compare cpu_id with 0
  21. beq map_cpu_id_0
  22. cmp r0, #1 // compare cpu_id with 1
  23. beq map_cpu_id_1
  24. cmp r0, #2 // compare cpu_id with 2
  25. beq map_cpu_id_2
  26. cmp r0, #3 // compare cpu_id with 3
  27. beq map_cpu_id_3
  28. mov pc, lr // no mapping needed
  29. #endif
  30. mov pc, lr // no mapping needed
  31. // Mapping for PE2204
  32. map_cpu_id_0:
  33. mov r0, #2
  34. mov pc, lr
  35. map_cpu_id_1:
  36. mov r0, #3
  37. mov pc, lr
  38. map_cpu_id_2:
  39. mov r0, #0
  40. mov pc, lr
  41. map_cpu_id_3:
  42. mov r0, #1
  43. mov pc, lr
  44. .globl rt_hw_cpu_id_early
  45. rt_hw_cpu_id_early:
  46. // read MPIDR
  47. mov r9, lr
  48. mrc p15, 0, r0, c0, c0, 5
  49. ubfx r0, r0, #0, #12
  50. ldr r1,= CORE0_AFF
  51. cmp r0, r1
  52. beq core0
  53. #if defined(CORE1_AFF)
  54. ldr r1,= CORE1_AFF
  55. cmp r0, r1
  56. beq core1
  57. #endif
  58. #if defined(CORE2_AFF)
  59. ldr r1,= CORE2_AFF
  60. cmp r0, r1
  61. beq core2
  62. #endif
  63. #if defined(CORE3_AFF)
  64. ldr r1,= CORE3_AFF
  65. cmp r0, r1
  66. beq core3
  67. #endif
  68. b default
  69. core0:
  70. mov r0, #0
  71. b return
  72. core1:
  73. mov r0, #1
  74. b return
  75. core2:
  76. mov r0, #2
  77. b return
  78. core3:
  79. mov r0, #3
  80. b return
  81. default:
  82. and r0, r0, #15
  83. return:
  84. bl cpu_id_mapping
  85. mov pc, r9
  86. #else
  87. .globl cpu_id_mapping
  88. cpu_id_mapping:
  89. #if defined(TARGET_PE2204)
  90. cmp x0, #0 // compare cpu_id with 0
  91. beq map_cpu_id_0
  92. cmp x0, #1 // compare cpu_id with 1
  93. beq map_cpu_id_1
  94. cmp x0, #2 // compare cpu_id with 2
  95. beq map_cpu_id_2
  96. cmp x0, #3 // compare cpu_id with 3
  97. beq map_cpu_id_3
  98. RET // no mapping needed
  99. #endif
  100. RET // no mapping needed
  101. // Mapping for PE2204
  102. map_cpu_id_0:
  103. mov x0, #2
  104. RET
  105. map_cpu_id_1:
  106. mov x0, #3
  107. RET
  108. map_cpu_id_2:
  109. mov x0, #0
  110. RET
  111. map_cpu_id_3:
  112. mov x0, #1
  113. RET
  114. .globl rt_hw_cpu_id_set
  115. rt_hw_cpu_id_set:
  116. mov x9, lr
  117. mrs x0,MPIDR_EL1
  118. and x1, x0, #15
  119. msr tpidr_el1, x1
  120. mov lr, x9
  121. RET
  122. .globl rt_hw_cpu_id
  123. rt_hw_cpu_id:
  124. mrs x0,MPIDR_EL1
  125. ubfx x0, x0, #0, #20
  126. ldr x1,= CORE0_AFF
  127. cmp x0, x1
  128. beq core0
  129. #if defined(CORE1_AFF)
  130. ldr x1,= CORE1_AFF
  131. cmp x0, x1
  132. beq core1
  133. #endif
  134. #if defined(CORE2_AFF)
  135. ldr x1,= CORE2_AFF
  136. cmp x0, x1
  137. beq core2
  138. #endif
  139. #if defined(CORE3_AFF)
  140. ldr x1,= CORE3_AFF
  141. cmp x0, x1
  142. beq core3
  143. #endif
  144. #if defined(CORE4_AFF)
  145. ldr x1,= CORE4_AFF
  146. cmp x0, x1
  147. beq core4
  148. #endif
  149. #if defined(CORE5_AFF)
  150. ldr x1,= CORE5_AFF
  151. cmp x0, x1
  152. beq core5
  153. #endif
  154. #if defined(CORE6_AFF)
  155. ldr x1,= CORE6_AFF
  156. cmp x0, x1
  157. beq core6
  158. #endif
  159. #if defined(CORE7_AFF)
  160. ldr x1,= CORE7_AFF
  161. cmp x0, x1
  162. beq core7
  163. #endif
  164. core0:
  165. mov x0, #0
  166. b return
  167. core1:
  168. mov x0, #1
  169. b return
  170. core2:
  171. mov x0, #2
  172. b return
  173. core3:
  174. mov x0, #3
  175. b return
  176. core4:
  177. mov x0, #4
  178. b return
  179. core5:
  180. mov x0, #5
  181. b return
  182. core6:
  183. mov x0, #6
  184. b return
  185. core7:
  186. mov x0, #7
  187. b return
  188. return:
  189. b cpu_id_mapping
  190. RET
  191. #endif