fcpu_info.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Copyright : (C) 2022 Phytium Information Technology, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is OPEN SOURCE software: you can redistribute it and/or modify it
  6. * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
  7. * either version 1.0 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See the Phytium Public License for more details.
  12. *
  13. *
  14. * FilePath: cpu_info.c
  15. * Date: 2022-03-08 19:37:19
  16. * LastEditTime: 2022-03-15 11:18:14
  17. * Description:  This file is for
  18. *
  19. * Modify History:
  20. * Ver   Who        Date         Changes
  21. * ----- ------     --------    --------------------------------------
  22. */
  23. #include "fcpu_info.h"
  24. #include "ferror_code.h"
  25. #include "fparameters.h"
  26. #include "fprintk.h"
  27. FError GetCpuId(u32 *cpu_id_p)
  28. {
  29. u32 affinity = GetAffinity();
  30. FError ret = ERR_SUCCESS ;
  31. switch (affinity & 0xfff)
  32. {
  33. #ifdef CORE0_AFF
  34. case CORE0_AFF:
  35. *cpu_id_p = 0 ;
  36. break;
  37. #endif
  38. #ifdef CORE1_AFF
  39. case CORE1_AFF:
  40. *cpu_id_p = 1 ;
  41. break;
  42. #endif
  43. #ifdef CORE2_AFF
  44. case CORE2_AFF:
  45. *cpu_id_p = 2;
  46. break;
  47. #endif
  48. #ifdef CORE3_AFF
  49. case CORE3_AFF:
  50. *cpu_id_p = 3 ;
  51. break;
  52. #endif
  53. #ifdef CORE4_AFF
  54. case CORE4_AFF:
  55. *cpu_id_p = 4 ;
  56. break;
  57. #endif
  58. #ifdef CORE5_AFF
  59. case CORE5_AFF:
  60. *cpu_id_p = 5 ;
  61. break;
  62. #endif
  63. #ifdef CORE6_AFF
  64. case CORE6_AFF:
  65. *cpu_id_p = 6 ;
  66. break;
  67. #endif
  68. #ifdef CORE7_AFF
  69. case CORE7_AFF:
  70. *cpu_id_p = 7 ;
  71. break;
  72. #endif
  73. default:
  74. ret = ERR_GENERAL ;
  75. break;
  76. }
  77. return ret;
  78. }
  79. /**
  80. * @name: GetCpuAffinityByMask
  81. * @msg: Determine the cluster information using the CPU ID
  82. * @param {u32} cpu_id cpu id mask .for example : 1 is core0 ,2 is core1 .....
  83. * @param {u64} *affinity_level_p cluster information , format is:
  84. * |--------[bit31-24]-------[bit23-16]-------------[bit15-8]--------[bit7-0]
  85. * |--------Affinity level3-----Affinity level2-----Affinity level1---Affinity level0
  86. * @return {*} ERR_SUCCESS is ok
  87. */
  88. FError GetCpuAffinityByMask(u32 cpu_id_mask, u64 *affinity_level_p)
  89. {
  90. FError ret = ERR_SUCCESS ;
  91. switch (cpu_id_mask)
  92. {
  93. #ifdef CORE0_AFF
  94. case (1<<0):
  95. *affinity_level_p = CORE0_AFF;
  96. break ;
  97. #endif
  98. #ifdef CORE1_AFF
  99. case (1<<1):
  100. *affinity_level_p = CORE1_AFF;
  101. break ;
  102. #endif
  103. #ifdef CORE2_AFF
  104. case (1<<2):
  105. *affinity_level_p = CORE2_AFF;
  106. break ;
  107. #endif
  108. #ifdef CORE3_AFF
  109. case (1<<3):
  110. *affinity_level_p = CORE3_AFF;
  111. break ;
  112. #endif
  113. #ifdef CORE4_AFF
  114. case (1<<4):
  115. *affinity_level_p = CORE4_AFF;
  116. break ;
  117. #endif
  118. #ifdef CORE5_AFF
  119. case (1<<5):
  120. *affinity_level_p = CORE5_AFF;
  121. break ;
  122. #endif
  123. #ifdef CORE6_AFF
  124. case (1<<6):
  125. *affinity_level_p = CORE6_AFF;
  126. break ;
  127. #endif
  128. #ifdef CORE7_AFF
  129. case (1<<7):
  130. *affinity_level_p = CORE7_AFF;
  131. break ;
  132. #endif
  133. default:
  134. ret = ERR_GENERAL;
  135. break;
  136. }
  137. return ret;
  138. }
  139. /**
  140. * @name: GetCpuAffinity
  141. * @msg: Determine the cluster information using the CPU ID
  142. * @param {u32} cpu_id cpu id .for example : 0 is core0 ,1 is core1 .....
  143. * @param {u64} *affinity_level_p cluster information , format is:
  144. * |--------[bit31-24]-------[bit23-16]-------------[bit15-8]--------[bit7-0]
  145. * |--------Affinity level3-----Affinity level2-----Affinity level1---Affinity level0
  146. * @return {*} ERR_SUCCESS is ok
  147. */
  148. FError GetCpuAffinity(u32 cpu_id, u64 *affinity_level_p)
  149. {
  150. FError ret = ERR_SUCCESS ;
  151. switch (cpu_id)
  152. {
  153. #ifdef CORE0_AFF
  154. case (0):
  155. *affinity_level_p = CORE0_AFF;
  156. break ;
  157. #endif
  158. #ifdef CORE1_AFF
  159. case (1):
  160. *affinity_level_p = CORE1_AFF;
  161. break ;
  162. #endif
  163. #ifdef CORE2_AFF
  164. case (2):
  165. *affinity_level_p = CORE2_AFF;
  166. break ;
  167. #endif
  168. #ifdef CORE3_AFF
  169. case (3):
  170. *affinity_level_p = CORE3_AFF;
  171. break ;
  172. #endif
  173. #ifdef CORE4_AFF
  174. case (4):
  175. *affinity_level_p = CORE4_AFF;
  176. break ;
  177. #endif
  178. #ifdef CORE5_AFF
  179. case (5):
  180. *affinity_level_p = CORE5_AFF;
  181. break ;
  182. #endif
  183. #ifdef CORE6_AFF
  184. case (6):
  185. *affinity_level_p = CORE6_AFF;
  186. break ;
  187. #endif
  188. #ifdef CORE7_AFF
  189. case (7):
  190. *affinity_level_p = CORE7_AFF;
  191. break ;
  192. #endif
  193. default:
  194. ret = ERR_GENERAL;
  195. break;
  196. }
  197. return ret;
  198. }
  199. /**
  200. * @name: UseAffinityGetCpuId
  201. * @msg: Get the core value from affinity level
  202. * @param {u64} affinity_level is cpu affinity level value
  203. * @param {u32*} cpu_id_p is pointer to get cpu id value
  204. * @return {*} ERR_SUCCESS is ok , ERR_GENERAL is fail
  205. */
  206. FError UseAffinityGetCpuId(u64 affinity_level, u32 *cpu_id_p)
  207. {
  208. FError ret = ERR_SUCCESS ;
  209. switch (affinity_level)
  210. {
  211. #ifdef CORE0_AFF
  212. case CORE0_AFF:
  213. *cpu_id_p = 0;
  214. break ;
  215. #endif
  216. #ifdef CORE1_AFF
  217. case CORE1_AFF:
  218. *cpu_id_p = 1;
  219. break ;
  220. #endif
  221. #ifdef CORE2_AFF
  222. case CORE2_AFF:
  223. *cpu_id_p = 2;
  224. break ;
  225. #endif
  226. #ifdef CORE3_AFF
  227. case CORE3_AFF:
  228. *cpu_id_p = 3;
  229. break ;
  230. #endif
  231. #ifdef CORE4_AFF
  232. case CORE4_AFF:
  233. *cpu_id_p = 4;
  234. break ;
  235. #endif
  236. #ifdef CORE5_AFF
  237. case CORE5_AFF:
  238. *cpu_id_p = 5;
  239. break ;
  240. #endif
  241. #ifdef CORE6_AFF
  242. case CORE6_AFF:
  243. *cpu_id_p = 6;
  244. break ;
  245. #endif
  246. #ifdef CORE7_AFF
  247. case CORE7_AFF:
  248. *cpu_id_p = 7;
  249. break ;
  250. #endif
  251. default:
  252. ret = ERR_GENERAL;
  253. break;
  254. }
  255. return ret;
  256. }