kfd_crat.c 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460
  1. // SPDX-License-Identifier: GPL-2.0 OR MIT
  2. /*
  3. * Copyright 2015-2022 Advanced Micro Devices, Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <linux/pci.h>
  24. #include <linux/acpi.h>
  25. #include "kfd_crat.h"
  26. #include "kfd_priv.h"
  27. #include "kfd_topology.h"
  28. #include "amdgpu.h"
  29. #include "amdgpu_amdkfd.h"
  30. /* GPU Processor ID base for dGPUs for which VCRAT needs to be created.
  31. * GPU processor ID are expressed with Bit[31]=1.
  32. * The base is set to 0x8000_0000 + 0x1000 to avoid collision with GPU IDs
  33. * used in the CRAT.
  34. */
  35. static uint32_t gpu_processor_id_low = 0x80001000;
  36. /* Return the next available gpu_processor_id and increment it for next GPU
  37. * @total_cu_count - Total CUs present in the GPU including ones
  38. * masked off
  39. */
  40. static inline unsigned int get_and_inc_gpu_processor_id(
  41. unsigned int total_cu_count)
  42. {
  43. int current_id = gpu_processor_id_low;
  44. gpu_processor_id_low += total_cu_count;
  45. return current_id;
  46. }
  47. static struct kfd_gpu_cache_info kaveri_cache_info[] = {
  48. {
  49. /* TCP L1 Cache per CU */
  50. .cache_size = 16,
  51. .cache_level = 1,
  52. .cache_line_size = 64,
  53. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  54. CRAT_CACHE_FLAGS_DATA_CACHE |
  55. CRAT_CACHE_FLAGS_SIMD_CACHE),
  56. .num_cu_shared = 1,
  57. },
  58. {
  59. /* Scalar L1 Instruction Cache (in SQC module) per bank */
  60. .cache_size = 16,
  61. .cache_level = 1,
  62. .cache_line_size = 64,
  63. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  64. CRAT_CACHE_FLAGS_INST_CACHE |
  65. CRAT_CACHE_FLAGS_SIMD_CACHE),
  66. .num_cu_shared = 2,
  67. },
  68. {
  69. /* Scalar L1 Data Cache (in SQC module) per bank */
  70. .cache_size = 8,
  71. .cache_level = 1,
  72. .cache_line_size = 64,
  73. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  74. CRAT_CACHE_FLAGS_DATA_CACHE |
  75. CRAT_CACHE_FLAGS_SIMD_CACHE),
  76. .num_cu_shared = 2,
  77. },
  78. /* TODO: Add L2 Cache information */
  79. };
  80. static struct kfd_gpu_cache_info carrizo_cache_info[] = {
  81. {
  82. /* TCP L1 Cache per CU */
  83. .cache_size = 16,
  84. .cache_level = 1,
  85. .cache_line_size = 64,
  86. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  87. CRAT_CACHE_FLAGS_DATA_CACHE |
  88. CRAT_CACHE_FLAGS_SIMD_CACHE),
  89. .num_cu_shared = 1,
  90. },
  91. {
  92. /* Scalar L1 Instruction Cache (in SQC module) per bank */
  93. .cache_size = 32,
  94. .cache_level = 1,
  95. .cache_line_size = 64,
  96. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  97. CRAT_CACHE_FLAGS_INST_CACHE |
  98. CRAT_CACHE_FLAGS_SIMD_CACHE),
  99. .num_cu_shared = 4,
  100. },
  101. {
  102. /* Scalar L1 Data Cache (in SQC module) per bank. */
  103. .cache_size = 16,
  104. .cache_level = 1,
  105. .cache_line_size = 64,
  106. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  107. CRAT_CACHE_FLAGS_DATA_CACHE |
  108. CRAT_CACHE_FLAGS_SIMD_CACHE),
  109. .num_cu_shared = 4,
  110. },
  111. /* TODO: Add L2 Cache information */
  112. };
  113. #define hawaii_cache_info kaveri_cache_info
  114. #define tonga_cache_info carrizo_cache_info
  115. #define fiji_cache_info carrizo_cache_info
  116. #define polaris10_cache_info carrizo_cache_info
  117. #define polaris11_cache_info carrizo_cache_info
  118. #define polaris12_cache_info carrizo_cache_info
  119. #define vegam_cache_info carrizo_cache_info
  120. /* NOTE: L1 cache information has been updated and L2/L3
  121. * cache information has been added for Vega10 and
  122. * newer ASICs. The unit for cache_size is KiB.
  123. * In future, check & update cache details
  124. * for every new ASIC is required.
  125. */
  126. static struct kfd_gpu_cache_info vega10_cache_info[] = {
  127. {
  128. /* TCP L1 Cache per CU */
  129. .cache_size = 16,
  130. .cache_level = 1,
  131. .cache_line_size = 64,
  132. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  133. CRAT_CACHE_FLAGS_DATA_CACHE |
  134. CRAT_CACHE_FLAGS_SIMD_CACHE),
  135. .num_cu_shared = 1,
  136. },
  137. {
  138. /* Scalar L1 Instruction Cache per SQC */
  139. .cache_size = 32,
  140. .cache_level = 1,
  141. .cache_line_size = 64,
  142. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  143. CRAT_CACHE_FLAGS_INST_CACHE |
  144. CRAT_CACHE_FLAGS_SIMD_CACHE),
  145. .num_cu_shared = 3,
  146. },
  147. {
  148. /* Scalar L1 Data Cache per SQC */
  149. .cache_size = 16,
  150. .cache_level = 1,
  151. .cache_line_size = 64,
  152. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  153. CRAT_CACHE_FLAGS_DATA_CACHE |
  154. CRAT_CACHE_FLAGS_SIMD_CACHE),
  155. .num_cu_shared = 3,
  156. },
  157. {
  158. /* L2 Data Cache per GPU (Total Tex Cache) */
  159. .cache_size = 4096,
  160. .cache_level = 2,
  161. .cache_line_size = 64,
  162. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  163. CRAT_CACHE_FLAGS_DATA_CACHE |
  164. CRAT_CACHE_FLAGS_SIMD_CACHE),
  165. .num_cu_shared = 16,
  166. },
  167. };
  168. static struct kfd_gpu_cache_info raven_cache_info[] = {
  169. {
  170. /* TCP L1 Cache per CU */
  171. .cache_size = 16,
  172. .cache_level = 1,
  173. .cache_line_size = 64,
  174. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  175. CRAT_CACHE_FLAGS_DATA_CACHE |
  176. CRAT_CACHE_FLAGS_SIMD_CACHE),
  177. .num_cu_shared = 1,
  178. },
  179. {
  180. /* Scalar L1 Instruction Cache per SQC */
  181. .cache_size = 32,
  182. .cache_level = 1,
  183. .cache_line_size = 64,
  184. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  185. CRAT_CACHE_FLAGS_INST_CACHE |
  186. CRAT_CACHE_FLAGS_SIMD_CACHE),
  187. .num_cu_shared = 3,
  188. },
  189. {
  190. /* Scalar L1 Data Cache per SQC */
  191. .cache_size = 16,
  192. .cache_level = 1,
  193. .cache_line_size = 64,
  194. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  195. CRAT_CACHE_FLAGS_DATA_CACHE |
  196. CRAT_CACHE_FLAGS_SIMD_CACHE),
  197. .num_cu_shared = 3,
  198. },
  199. {
  200. /* L2 Data Cache per GPU (Total Tex Cache) */
  201. .cache_size = 1024,
  202. .cache_level = 2,
  203. .cache_line_size = 64,
  204. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  205. CRAT_CACHE_FLAGS_DATA_CACHE |
  206. CRAT_CACHE_FLAGS_SIMD_CACHE),
  207. .num_cu_shared = 11,
  208. },
  209. };
  210. static struct kfd_gpu_cache_info renoir_cache_info[] = {
  211. {
  212. /* TCP L1 Cache per CU */
  213. .cache_size = 16,
  214. .cache_level = 1,
  215. .cache_line_size = 64,
  216. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  217. CRAT_CACHE_FLAGS_DATA_CACHE |
  218. CRAT_CACHE_FLAGS_SIMD_CACHE),
  219. .num_cu_shared = 1,
  220. },
  221. {
  222. /* Scalar L1 Instruction Cache per SQC */
  223. .cache_size = 32,
  224. .cache_level = 1,
  225. .cache_line_size = 64,
  226. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  227. CRAT_CACHE_FLAGS_INST_CACHE |
  228. CRAT_CACHE_FLAGS_SIMD_CACHE),
  229. .num_cu_shared = 3,
  230. },
  231. {
  232. /* Scalar L1 Data Cache per SQC */
  233. .cache_size = 16,
  234. .cache_level = 1,
  235. .cache_line_size = 64,
  236. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  237. CRAT_CACHE_FLAGS_DATA_CACHE |
  238. CRAT_CACHE_FLAGS_SIMD_CACHE),
  239. .num_cu_shared = 3,
  240. },
  241. {
  242. /* L2 Data Cache per GPU (Total Tex Cache) */
  243. .cache_size = 1024,
  244. .cache_level = 2,
  245. .cache_line_size = 64,
  246. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  247. CRAT_CACHE_FLAGS_DATA_CACHE |
  248. CRAT_CACHE_FLAGS_SIMD_CACHE),
  249. .num_cu_shared = 8,
  250. },
  251. };
  252. static struct kfd_gpu_cache_info vega12_cache_info[] = {
  253. {
  254. /* TCP L1 Cache per CU */
  255. .cache_size = 16,
  256. .cache_level = 1,
  257. .cache_line_size = 64,
  258. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  259. CRAT_CACHE_FLAGS_DATA_CACHE |
  260. CRAT_CACHE_FLAGS_SIMD_CACHE),
  261. .num_cu_shared = 1,
  262. },
  263. {
  264. /* Scalar L1 Instruction Cache per SQC */
  265. .cache_size = 32,
  266. .cache_level = 1,
  267. .cache_line_size = 64,
  268. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  269. CRAT_CACHE_FLAGS_INST_CACHE |
  270. CRAT_CACHE_FLAGS_SIMD_CACHE),
  271. .num_cu_shared = 3,
  272. },
  273. {
  274. /* Scalar L1 Data Cache per SQC */
  275. .cache_size = 16,
  276. .cache_level = 1,
  277. .cache_line_size = 64,
  278. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  279. CRAT_CACHE_FLAGS_DATA_CACHE |
  280. CRAT_CACHE_FLAGS_SIMD_CACHE),
  281. .num_cu_shared = 3,
  282. },
  283. {
  284. /* L2 Data Cache per GPU (Total Tex Cache) */
  285. .cache_size = 2048,
  286. .cache_level = 2,
  287. .cache_line_size = 64,
  288. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  289. CRAT_CACHE_FLAGS_DATA_CACHE |
  290. CRAT_CACHE_FLAGS_SIMD_CACHE),
  291. .num_cu_shared = 5,
  292. },
  293. };
  294. static struct kfd_gpu_cache_info vega20_cache_info[] = {
  295. {
  296. /* TCP L1 Cache per CU */
  297. .cache_size = 16,
  298. .cache_level = 1,
  299. .cache_line_size = 64,
  300. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  301. CRAT_CACHE_FLAGS_DATA_CACHE |
  302. CRAT_CACHE_FLAGS_SIMD_CACHE),
  303. .num_cu_shared = 1,
  304. },
  305. {
  306. /* Scalar L1 Instruction Cache per SQC */
  307. .cache_size = 32,
  308. .cache_level = 1,
  309. .cache_line_size = 64,
  310. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  311. CRAT_CACHE_FLAGS_INST_CACHE |
  312. CRAT_CACHE_FLAGS_SIMD_CACHE),
  313. .num_cu_shared = 3,
  314. },
  315. {
  316. /* Scalar L1 Data Cache per SQC */
  317. .cache_size = 16,
  318. .cache_level = 1,
  319. .cache_line_size = 64,
  320. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  321. CRAT_CACHE_FLAGS_DATA_CACHE |
  322. CRAT_CACHE_FLAGS_SIMD_CACHE),
  323. .num_cu_shared = 3,
  324. },
  325. {
  326. /* L2 Data Cache per GPU (Total Tex Cache) */
  327. .cache_size = 8192,
  328. .cache_level = 2,
  329. .cache_line_size = 64,
  330. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  331. CRAT_CACHE_FLAGS_DATA_CACHE |
  332. CRAT_CACHE_FLAGS_SIMD_CACHE),
  333. .num_cu_shared = 16,
  334. },
  335. };
  336. static struct kfd_gpu_cache_info aldebaran_cache_info[] = {
  337. {
  338. /* TCP L1 Cache per CU */
  339. .cache_size = 16,
  340. .cache_level = 1,
  341. .cache_line_size = 64,
  342. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  343. CRAT_CACHE_FLAGS_DATA_CACHE |
  344. CRAT_CACHE_FLAGS_SIMD_CACHE),
  345. .num_cu_shared = 1,
  346. },
  347. {
  348. /* Scalar L1 Instruction Cache per SQC */
  349. .cache_size = 32,
  350. .cache_level = 1,
  351. .cache_line_size = 64,
  352. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  353. CRAT_CACHE_FLAGS_INST_CACHE |
  354. CRAT_CACHE_FLAGS_SIMD_CACHE),
  355. .num_cu_shared = 2,
  356. },
  357. {
  358. /* Scalar L1 Data Cache per SQC */
  359. .cache_size = 16,
  360. .cache_level = 1,
  361. .cache_line_size = 64,
  362. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  363. CRAT_CACHE_FLAGS_DATA_CACHE |
  364. CRAT_CACHE_FLAGS_SIMD_CACHE),
  365. .num_cu_shared = 2,
  366. },
  367. {
  368. /* L2 Data Cache per GPU (Total Tex Cache) */
  369. .cache_size = 8192,
  370. .cache_level = 2,
  371. .cache_line_size = 128,
  372. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  373. CRAT_CACHE_FLAGS_DATA_CACHE |
  374. CRAT_CACHE_FLAGS_SIMD_CACHE),
  375. .num_cu_shared = 14,
  376. },
  377. };
  378. static struct kfd_gpu_cache_info navi10_cache_info[] = {
  379. {
  380. /* TCP L1 Cache per CU */
  381. .cache_size = 16,
  382. .cache_level = 1,
  383. .cache_line_size = 128,
  384. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  385. CRAT_CACHE_FLAGS_DATA_CACHE |
  386. CRAT_CACHE_FLAGS_SIMD_CACHE),
  387. .num_cu_shared = 1,
  388. },
  389. {
  390. /* Scalar L1 Instruction Cache per SQC */
  391. .cache_size = 32,
  392. .cache_level = 1,
  393. .cache_line_size = 64,
  394. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  395. CRAT_CACHE_FLAGS_INST_CACHE |
  396. CRAT_CACHE_FLAGS_SIMD_CACHE),
  397. .num_cu_shared = 2,
  398. },
  399. {
  400. /* Scalar L1 Data Cache per SQC */
  401. .cache_size = 16,
  402. .cache_level = 1,
  403. .cache_line_size = 64,
  404. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  405. CRAT_CACHE_FLAGS_DATA_CACHE |
  406. CRAT_CACHE_FLAGS_SIMD_CACHE),
  407. .num_cu_shared = 2,
  408. },
  409. {
  410. /* GL1 Data Cache per SA */
  411. .cache_size = 128,
  412. .cache_level = 1,
  413. .cache_line_size = 128,
  414. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  415. CRAT_CACHE_FLAGS_DATA_CACHE |
  416. CRAT_CACHE_FLAGS_SIMD_CACHE),
  417. .num_cu_shared = 10,
  418. },
  419. {
  420. /* L2 Data Cache per GPU (Total Tex Cache) */
  421. .cache_size = 4096,
  422. .cache_level = 2,
  423. .cache_line_size = 128,
  424. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  425. CRAT_CACHE_FLAGS_DATA_CACHE |
  426. CRAT_CACHE_FLAGS_SIMD_CACHE),
  427. .num_cu_shared = 10,
  428. },
  429. };
  430. static struct kfd_gpu_cache_info vangogh_cache_info[] = {
  431. {
  432. /* TCP L1 Cache per CU */
  433. .cache_size = 16,
  434. .cache_level = 1,
  435. .cache_line_size = 128,
  436. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  437. CRAT_CACHE_FLAGS_DATA_CACHE |
  438. CRAT_CACHE_FLAGS_SIMD_CACHE),
  439. .num_cu_shared = 1,
  440. },
  441. {
  442. /* Scalar L1 Instruction Cache per SQC */
  443. .cache_size = 32,
  444. .cache_level = 1,
  445. .cache_line_size = 64,
  446. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  447. CRAT_CACHE_FLAGS_INST_CACHE |
  448. CRAT_CACHE_FLAGS_SIMD_CACHE),
  449. .num_cu_shared = 2,
  450. },
  451. {
  452. /* Scalar L1 Data Cache per SQC */
  453. .cache_size = 16,
  454. .cache_level = 1,
  455. .cache_line_size = 64,
  456. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  457. CRAT_CACHE_FLAGS_DATA_CACHE |
  458. CRAT_CACHE_FLAGS_SIMD_CACHE),
  459. .num_cu_shared = 2,
  460. },
  461. {
  462. /* GL1 Data Cache per SA */
  463. .cache_size = 128,
  464. .cache_level = 1,
  465. .cache_line_size = 128,
  466. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  467. CRAT_CACHE_FLAGS_DATA_CACHE |
  468. CRAT_CACHE_FLAGS_SIMD_CACHE),
  469. .num_cu_shared = 8,
  470. },
  471. {
  472. /* L2 Data Cache per GPU (Total Tex Cache) */
  473. .cache_size = 1024,
  474. .cache_level = 2,
  475. .cache_line_size = 128,
  476. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  477. CRAT_CACHE_FLAGS_DATA_CACHE |
  478. CRAT_CACHE_FLAGS_SIMD_CACHE),
  479. .num_cu_shared = 8,
  480. },
  481. };
  482. static struct kfd_gpu_cache_info navi14_cache_info[] = {
  483. {
  484. /* TCP L1 Cache per CU */
  485. .cache_size = 16,
  486. .cache_level = 1,
  487. .cache_line_size = 128,
  488. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  489. CRAT_CACHE_FLAGS_DATA_CACHE |
  490. CRAT_CACHE_FLAGS_SIMD_CACHE),
  491. .num_cu_shared = 1,
  492. },
  493. {
  494. /* Scalar L1 Instruction Cache per SQC */
  495. .cache_size = 32,
  496. .cache_level = 1,
  497. .cache_line_size = 64,
  498. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  499. CRAT_CACHE_FLAGS_INST_CACHE |
  500. CRAT_CACHE_FLAGS_SIMD_CACHE),
  501. .num_cu_shared = 2,
  502. },
  503. {
  504. /* Scalar L1 Data Cache per SQC */
  505. .cache_size = 16,
  506. .cache_level = 1,
  507. .cache_line_size = 64,
  508. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  509. CRAT_CACHE_FLAGS_DATA_CACHE |
  510. CRAT_CACHE_FLAGS_SIMD_CACHE),
  511. .num_cu_shared = 2,
  512. },
  513. {
  514. /* GL1 Data Cache per SA */
  515. .cache_size = 128,
  516. .cache_level = 1,
  517. .cache_line_size = 128,
  518. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  519. CRAT_CACHE_FLAGS_DATA_CACHE |
  520. CRAT_CACHE_FLAGS_SIMD_CACHE),
  521. .num_cu_shared = 12,
  522. },
  523. {
  524. /* L2 Data Cache per GPU (Total Tex Cache) */
  525. .cache_size = 2048,
  526. .cache_level = 2,
  527. .cache_line_size = 128,
  528. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  529. CRAT_CACHE_FLAGS_DATA_CACHE |
  530. CRAT_CACHE_FLAGS_SIMD_CACHE),
  531. .num_cu_shared = 12,
  532. },
  533. };
  534. static struct kfd_gpu_cache_info sienna_cichlid_cache_info[] = {
  535. {
  536. /* TCP L1 Cache per CU */
  537. .cache_size = 16,
  538. .cache_level = 1,
  539. .cache_line_size = 128,
  540. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  541. CRAT_CACHE_FLAGS_DATA_CACHE |
  542. CRAT_CACHE_FLAGS_SIMD_CACHE),
  543. .num_cu_shared = 1,
  544. },
  545. {
  546. /* Scalar L1 Instruction Cache per SQC */
  547. .cache_size = 32,
  548. .cache_level = 1,
  549. .cache_line_size = 64,
  550. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  551. CRAT_CACHE_FLAGS_INST_CACHE |
  552. CRAT_CACHE_FLAGS_SIMD_CACHE),
  553. .num_cu_shared = 2,
  554. },
  555. {
  556. /* Scalar L1 Data Cache per SQC */
  557. .cache_size = 16,
  558. .cache_level = 1,
  559. .cache_line_size = 64,
  560. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  561. CRAT_CACHE_FLAGS_DATA_CACHE |
  562. CRAT_CACHE_FLAGS_SIMD_CACHE),
  563. .num_cu_shared = 2,
  564. },
  565. {
  566. /* GL1 Data Cache per SA */
  567. .cache_size = 128,
  568. .cache_level = 1,
  569. .cache_line_size = 128,
  570. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  571. CRAT_CACHE_FLAGS_DATA_CACHE |
  572. CRAT_CACHE_FLAGS_SIMD_CACHE),
  573. .num_cu_shared = 10,
  574. },
  575. {
  576. /* L2 Data Cache per GPU (Total Tex Cache) */
  577. .cache_size = 4096,
  578. .cache_level = 2,
  579. .cache_line_size = 128,
  580. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  581. CRAT_CACHE_FLAGS_DATA_CACHE |
  582. CRAT_CACHE_FLAGS_SIMD_CACHE),
  583. .num_cu_shared = 10,
  584. },
  585. {
  586. /* L3 Data Cache per GPU */
  587. .cache_size = 128*1024,
  588. .cache_level = 3,
  589. .cache_line_size = 64,
  590. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  591. CRAT_CACHE_FLAGS_DATA_CACHE |
  592. CRAT_CACHE_FLAGS_SIMD_CACHE),
  593. .num_cu_shared = 10,
  594. },
  595. };
  596. static struct kfd_gpu_cache_info navy_flounder_cache_info[] = {
  597. {
  598. /* TCP L1 Cache per CU */
  599. .cache_size = 16,
  600. .cache_level = 1,
  601. .cache_line_size = 128,
  602. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  603. CRAT_CACHE_FLAGS_DATA_CACHE |
  604. CRAT_CACHE_FLAGS_SIMD_CACHE),
  605. .num_cu_shared = 1,
  606. },
  607. {
  608. /* Scalar L1 Instruction Cache per SQC */
  609. .cache_size = 32,
  610. .cache_level = 1,
  611. .cache_line_size = 64,
  612. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  613. CRAT_CACHE_FLAGS_INST_CACHE |
  614. CRAT_CACHE_FLAGS_SIMD_CACHE),
  615. .num_cu_shared = 2,
  616. },
  617. {
  618. /* Scalar L1 Data Cache per SQC */
  619. .cache_size = 16,
  620. .cache_level = 1,
  621. .cache_line_size = 64,
  622. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  623. CRAT_CACHE_FLAGS_DATA_CACHE |
  624. CRAT_CACHE_FLAGS_SIMD_CACHE),
  625. .num_cu_shared = 2,
  626. },
  627. {
  628. /* GL1 Data Cache per SA */
  629. .cache_size = 128,
  630. .cache_level = 1,
  631. .cache_line_size = 128,
  632. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  633. CRAT_CACHE_FLAGS_DATA_CACHE |
  634. CRAT_CACHE_FLAGS_SIMD_CACHE),
  635. .num_cu_shared = 10,
  636. },
  637. {
  638. /* L2 Data Cache per GPU (Total Tex Cache) */
  639. .cache_size = 3072,
  640. .cache_level = 2,
  641. .cache_line_size = 128,
  642. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  643. CRAT_CACHE_FLAGS_DATA_CACHE |
  644. CRAT_CACHE_FLAGS_SIMD_CACHE),
  645. .num_cu_shared = 10,
  646. },
  647. {
  648. /* L3 Data Cache per GPU */
  649. .cache_size = 96*1024,
  650. .cache_level = 3,
  651. .cache_line_size = 64,
  652. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  653. CRAT_CACHE_FLAGS_DATA_CACHE |
  654. CRAT_CACHE_FLAGS_SIMD_CACHE),
  655. .num_cu_shared = 10,
  656. },
  657. };
  658. static struct kfd_gpu_cache_info dimgrey_cavefish_cache_info[] = {
  659. {
  660. /* TCP L1 Cache per CU */
  661. .cache_size = 16,
  662. .cache_level = 1,
  663. .cache_line_size = 128,
  664. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  665. CRAT_CACHE_FLAGS_DATA_CACHE |
  666. CRAT_CACHE_FLAGS_SIMD_CACHE),
  667. .num_cu_shared = 1,
  668. },
  669. {
  670. /* Scalar L1 Instruction Cache per SQC */
  671. .cache_size = 32,
  672. .cache_level = 1,
  673. .cache_line_size = 64,
  674. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  675. CRAT_CACHE_FLAGS_INST_CACHE |
  676. CRAT_CACHE_FLAGS_SIMD_CACHE),
  677. .num_cu_shared = 2,
  678. },
  679. {
  680. /* Scalar L1 Data Cache per SQC */
  681. .cache_size = 16,
  682. .cache_level = 1,
  683. .cache_line_size = 64,
  684. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  685. CRAT_CACHE_FLAGS_DATA_CACHE |
  686. CRAT_CACHE_FLAGS_SIMD_CACHE),
  687. .num_cu_shared = 2,
  688. },
  689. {
  690. /* GL1 Data Cache per SA */
  691. .cache_size = 128,
  692. .cache_level = 1,
  693. .cache_line_size = 128,
  694. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  695. CRAT_CACHE_FLAGS_DATA_CACHE |
  696. CRAT_CACHE_FLAGS_SIMD_CACHE),
  697. .num_cu_shared = 8,
  698. },
  699. {
  700. /* L2 Data Cache per GPU (Total Tex Cache) */
  701. .cache_size = 2048,
  702. .cache_level = 2,
  703. .cache_line_size = 128,
  704. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  705. CRAT_CACHE_FLAGS_DATA_CACHE |
  706. CRAT_CACHE_FLAGS_SIMD_CACHE),
  707. .num_cu_shared = 8,
  708. },
  709. {
  710. /* L3 Data Cache per GPU */
  711. .cache_size = 32*1024,
  712. .cache_level = 3,
  713. .cache_line_size = 64,
  714. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  715. CRAT_CACHE_FLAGS_DATA_CACHE |
  716. CRAT_CACHE_FLAGS_SIMD_CACHE),
  717. .num_cu_shared = 8,
  718. },
  719. };
  720. static struct kfd_gpu_cache_info beige_goby_cache_info[] = {
  721. {
  722. /* TCP L1 Cache per CU */
  723. .cache_size = 16,
  724. .cache_level = 1,
  725. .cache_line_size = 128,
  726. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  727. CRAT_CACHE_FLAGS_DATA_CACHE |
  728. CRAT_CACHE_FLAGS_SIMD_CACHE),
  729. .num_cu_shared = 1,
  730. },
  731. {
  732. /* Scalar L1 Instruction Cache per SQC */
  733. .cache_size = 32,
  734. .cache_level = 1,
  735. .cache_line_size = 64,
  736. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  737. CRAT_CACHE_FLAGS_INST_CACHE |
  738. CRAT_CACHE_FLAGS_SIMD_CACHE),
  739. .num_cu_shared = 2,
  740. },
  741. {
  742. /* Scalar L1 Data Cache per SQC */
  743. .cache_size = 16,
  744. .cache_level = 1,
  745. .cache_line_size = 64,
  746. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  747. CRAT_CACHE_FLAGS_DATA_CACHE |
  748. CRAT_CACHE_FLAGS_SIMD_CACHE),
  749. .num_cu_shared = 2,
  750. },
  751. {
  752. /* GL1 Data Cache per SA */
  753. .cache_size = 128,
  754. .cache_level = 1,
  755. .cache_line_size = 128,
  756. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  757. CRAT_CACHE_FLAGS_DATA_CACHE |
  758. CRAT_CACHE_FLAGS_SIMD_CACHE),
  759. .num_cu_shared = 8,
  760. },
  761. {
  762. /* L2 Data Cache per GPU (Total Tex Cache) */
  763. .cache_size = 1024,
  764. .cache_level = 2,
  765. .cache_line_size = 128,
  766. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  767. CRAT_CACHE_FLAGS_DATA_CACHE |
  768. CRAT_CACHE_FLAGS_SIMD_CACHE),
  769. .num_cu_shared = 8,
  770. },
  771. {
  772. /* L3 Data Cache per GPU */
  773. .cache_size = 16*1024,
  774. .cache_level = 3,
  775. .cache_line_size = 64,
  776. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  777. CRAT_CACHE_FLAGS_DATA_CACHE |
  778. CRAT_CACHE_FLAGS_SIMD_CACHE),
  779. .num_cu_shared = 8,
  780. },
  781. };
  782. static struct kfd_gpu_cache_info yellow_carp_cache_info[] = {
  783. {
  784. /* TCP L1 Cache per CU */
  785. .cache_size = 16,
  786. .cache_level = 1,
  787. .cache_line_size = 128,
  788. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  789. CRAT_CACHE_FLAGS_DATA_CACHE |
  790. CRAT_CACHE_FLAGS_SIMD_CACHE),
  791. .num_cu_shared = 1,
  792. },
  793. {
  794. /* Scalar L1 Instruction Cache per SQC */
  795. .cache_size = 32,
  796. .cache_level = 1,
  797. .cache_line_size = 64,
  798. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  799. CRAT_CACHE_FLAGS_INST_CACHE |
  800. CRAT_CACHE_FLAGS_SIMD_CACHE),
  801. .num_cu_shared = 2,
  802. },
  803. {
  804. /* Scalar L1 Data Cache per SQC */
  805. .cache_size = 16,
  806. .cache_level = 1,
  807. .cache_line_size = 64,
  808. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  809. CRAT_CACHE_FLAGS_DATA_CACHE |
  810. CRAT_CACHE_FLAGS_SIMD_CACHE),
  811. .num_cu_shared = 2,
  812. },
  813. {
  814. /* GL1 Data Cache per SA */
  815. .cache_size = 128,
  816. .cache_level = 1,
  817. .cache_line_size = 128,
  818. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  819. CRAT_CACHE_FLAGS_DATA_CACHE |
  820. CRAT_CACHE_FLAGS_SIMD_CACHE),
  821. .num_cu_shared = 6,
  822. },
  823. {
  824. /* L2 Data Cache per GPU (Total Tex Cache) */
  825. .cache_size = 2048,
  826. .cache_level = 2,
  827. .cache_line_size = 128,
  828. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  829. CRAT_CACHE_FLAGS_DATA_CACHE |
  830. CRAT_CACHE_FLAGS_SIMD_CACHE),
  831. .num_cu_shared = 6,
  832. },
  833. };
  834. static struct kfd_gpu_cache_info gfx1037_cache_info[] = {
  835. {
  836. /* TCP L1 Cache per CU */
  837. .cache_size = 16,
  838. .cache_level = 1,
  839. .cache_line_size = 128,
  840. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  841. CRAT_CACHE_FLAGS_DATA_CACHE |
  842. CRAT_CACHE_FLAGS_SIMD_CACHE),
  843. .num_cu_shared = 1,
  844. },
  845. {
  846. /* Scalar L1 Instruction Cache per SQC */
  847. .cache_size = 32,
  848. .cache_level = 1,
  849. .cache_line_size = 64,
  850. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  851. CRAT_CACHE_FLAGS_INST_CACHE |
  852. CRAT_CACHE_FLAGS_SIMD_CACHE),
  853. .num_cu_shared = 2,
  854. },
  855. {
  856. /* Scalar L1 Data Cache per SQC */
  857. .cache_size = 16,
  858. .cache_level = 1,
  859. .cache_line_size = 64,
  860. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  861. CRAT_CACHE_FLAGS_DATA_CACHE |
  862. CRAT_CACHE_FLAGS_SIMD_CACHE),
  863. .num_cu_shared = 2,
  864. },
  865. {
  866. /* GL1 Data Cache per SA */
  867. .cache_size = 128,
  868. .cache_level = 1,
  869. .cache_line_size = 128,
  870. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  871. CRAT_CACHE_FLAGS_DATA_CACHE |
  872. CRAT_CACHE_FLAGS_SIMD_CACHE),
  873. .num_cu_shared = 2,
  874. },
  875. {
  876. /* L2 Data Cache per GPU (Total Tex Cache) */
  877. .cache_size = 256,
  878. .cache_level = 2,
  879. .cache_line_size = 128,
  880. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  881. CRAT_CACHE_FLAGS_DATA_CACHE |
  882. CRAT_CACHE_FLAGS_SIMD_CACHE),
  883. .num_cu_shared = 2,
  884. },
  885. };
  886. static struct kfd_gpu_cache_info gc_10_3_6_cache_info[] = {
  887. {
  888. /* TCP L1 Cache per CU */
  889. .cache_size = 16,
  890. .cache_level = 1,
  891. .cache_line_size = 128,
  892. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  893. CRAT_CACHE_FLAGS_DATA_CACHE |
  894. CRAT_CACHE_FLAGS_SIMD_CACHE),
  895. .num_cu_shared = 1,
  896. },
  897. {
  898. /* Scalar L1 Instruction Cache per SQC */
  899. .cache_size = 32,
  900. .cache_level = 1,
  901. .cache_line_size = 64,
  902. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  903. CRAT_CACHE_FLAGS_INST_CACHE |
  904. CRAT_CACHE_FLAGS_SIMD_CACHE),
  905. .num_cu_shared = 2,
  906. },
  907. {
  908. /* Scalar L1 Data Cache per SQC */
  909. .cache_size = 16,
  910. .cache_level = 1,
  911. .cache_line_size = 64,
  912. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  913. CRAT_CACHE_FLAGS_DATA_CACHE |
  914. CRAT_CACHE_FLAGS_SIMD_CACHE),
  915. .num_cu_shared = 2,
  916. },
  917. {
  918. /* GL1 Data Cache per SA */
  919. .cache_size = 128,
  920. .cache_level = 1,
  921. .cache_line_size = 128,
  922. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  923. CRAT_CACHE_FLAGS_DATA_CACHE |
  924. CRAT_CACHE_FLAGS_SIMD_CACHE),
  925. .num_cu_shared = 2,
  926. },
  927. {
  928. /* L2 Data Cache per GPU (Total Tex Cache) */
  929. .cache_size = 256,
  930. .cache_level = 2,
  931. .cache_line_size = 128,
  932. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  933. CRAT_CACHE_FLAGS_DATA_CACHE |
  934. CRAT_CACHE_FLAGS_SIMD_CACHE),
  935. .num_cu_shared = 2,
  936. },
  937. };
  938. static struct kfd_gpu_cache_info dummy_cache_info[] = {
  939. {
  940. /* TCP L1 Cache per CU */
  941. .cache_size = 16,
  942. .cache_level = 1,
  943. .cache_line_size = 64,
  944. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  945. CRAT_CACHE_FLAGS_DATA_CACHE |
  946. CRAT_CACHE_FLAGS_SIMD_CACHE),
  947. .num_cu_shared = 1,
  948. },
  949. {
  950. /* Scalar L1 Instruction Cache per SQC */
  951. .cache_size = 32,
  952. .cache_level = 1,
  953. .cache_line_size = 64,
  954. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  955. CRAT_CACHE_FLAGS_INST_CACHE |
  956. CRAT_CACHE_FLAGS_SIMD_CACHE),
  957. .num_cu_shared = 2,
  958. },
  959. {
  960. /* Scalar L1 Data Cache per SQC */
  961. .cache_size = 16,
  962. .cache_level = 1,
  963. .cache_line_size = 64,
  964. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  965. CRAT_CACHE_FLAGS_DATA_CACHE |
  966. CRAT_CACHE_FLAGS_SIMD_CACHE),
  967. .num_cu_shared = 2,
  968. },
  969. {
  970. /* GL1 Data Cache per SA */
  971. .cache_size = 128,
  972. .cache_level = 1,
  973. .cache_line_size = 64,
  974. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  975. CRAT_CACHE_FLAGS_DATA_CACHE |
  976. CRAT_CACHE_FLAGS_SIMD_CACHE),
  977. .num_cu_shared = 6,
  978. },
  979. {
  980. /* L2 Data Cache per GPU (Total Tex Cache) */
  981. .cache_size = 2048,
  982. .cache_level = 2,
  983. .cache_line_size = 64,
  984. .flags = (CRAT_CACHE_FLAGS_ENABLED |
  985. CRAT_CACHE_FLAGS_DATA_CACHE |
  986. CRAT_CACHE_FLAGS_SIMD_CACHE),
  987. .num_cu_shared = 6,
  988. },
  989. };
  990. static void kfd_populated_cu_info_cpu(struct kfd_topology_device *dev,
  991. struct crat_subtype_computeunit *cu)
  992. {
  993. dev->node_props.cpu_cores_count = cu->num_cpu_cores;
  994. dev->node_props.cpu_core_id_base = cu->processor_id_low;
  995. if (cu->hsa_capability & CRAT_CU_FLAGS_IOMMU_PRESENT)
  996. dev->node_props.capability |= HSA_CAP_ATS_PRESENT;
  997. pr_debug("CU CPU: cores=%d id_base=%d\n", cu->num_cpu_cores,
  998. cu->processor_id_low);
  999. }
  1000. static void kfd_populated_cu_info_gpu(struct kfd_topology_device *dev,
  1001. struct crat_subtype_computeunit *cu)
  1002. {
  1003. dev->node_props.simd_id_base = cu->processor_id_low;
  1004. dev->node_props.simd_count = cu->num_simd_cores;
  1005. dev->node_props.lds_size_in_kb = cu->lds_size_in_kb;
  1006. dev->node_props.max_waves_per_simd = cu->max_waves_simd;
  1007. dev->node_props.wave_front_size = cu->wave_front_size;
  1008. dev->node_props.array_count = cu->array_count;
  1009. dev->node_props.cu_per_simd_array = cu->num_cu_per_array;
  1010. dev->node_props.simd_per_cu = cu->num_simd_per_cu;
  1011. dev->node_props.max_slots_scratch_cu = cu->max_slots_scatch_cu;
  1012. if (cu->hsa_capability & CRAT_CU_FLAGS_HOT_PLUGGABLE)
  1013. dev->node_props.capability |= HSA_CAP_HOT_PLUGGABLE;
  1014. pr_debug("CU GPU: id_base=%d\n", cu->processor_id_low);
  1015. }
  1016. /* kfd_parse_subtype_cu - parse compute unit subtypes and attach it to correct
  1017. * topology device present in the device_list
  1018. */
  1019. static int kfd_parse_subtype_cu(struct crat_subtype_computeunit *cu,
  1020. struct list_head *device_list)
  1021. {
  1022. struct kfd_topology_device *dev;
  1023. pr_debug("Found CU entry in CRAT table with proximity_domain=%d caps=%x\n",
  1024. cu->proximity_domain, cu->hsa_capability);
  1025. list_for_each_entry(dev, device_list, list) {
  1026. if (cu->proximity_domain == dev->proximity_domain) {
  1027. if (cu->flags & CRAT_CU_FLAGS_CPU_PRESENT)
  1028. kfd_populated_cu_info_cpu(dev, cu);
  1029. if (cu->flags & CRAT_CU_FLAGS_GPU_PRESENT)
  1030. kfd_populated_cu_info_gpu(dev, cu);
  1031. break;
  1032. }
  1033. }
  1034. return 0;
  1035. }
  1036. static struct kfd_mem_properties *
  1037. find_subtype_mem(uint32_t heap_type, uint32_t flags, uint32_t width,
  1038. struct kfd_topology_device *dev)
  1039. {
  1040. struct kfd_mem_properties *props;
  1041. list_for_each_entry(props, &dev->mem_props, list) {
  1042. if (props->heap_type == heap_type
  1043. && props->flags == flags
  1044. && props->width == width)
  1045. return props;
  1046. }
  1047. return NULL;
  1048. }
  1049. /* kfd_parse_subtype_mem - parse memory subtypes and attach it to correct
  1050. * topology device present in the device_list
  1051. */
  1052. static int kfd_parse_subtype_mem(struct crat_subtype_memory *mem,
  1053. struct list_head *device_list)
  1054. {
  1055. struct kfd_mem_properties *props;
  1056. struct kfd_topology_device *dev;
  1057. uint32_t heap_type;
  1058. uint64_t size_in_bytes;
  1059. uint32_t flags = 0;
  1060. uint32_t width;
  1061. pr_debug("Found memory entry in CRAT table with proximity_domain=%d\n",
  1062. mem->proximity_domain);
  1063. list_for_each_entry(dev, device_list, list) {
  1064. if (mem->proximity_domain == dev->proximity_domain) {
  1065. /* We're on GPU node */
  1066. if (dev->node_props.cpu_cores_count == 0) {
  1067. /* APU */
  1068. if (mem->visibility_type == 0)
  1069. heap_type =
  1070. HSA_MEM_HEAP_TYPE_FB_PRIVATE;
  1071. /* dGPU */
  1072. else
  1073. heap_type = mem->visibility_type;
  1074. } else
  1075. heap_type = HSA_MEM_HEAP_TYPE_SYSTEM;
  1076. if (mem->flags & CRAT_MEM_FLAGS_HOT_PLUGGABLE)
  1077. flags |= HSA_MEM_FLAGS_HOT_PLUGGABLE;
  1078. if (mem->flags & CRAT_MEM_FLAGS_NON_VOLATILE)
  1079. flags |= HSA_MEM_FLAGS_NON_VOLATILE;
  1080. size_in_bytes =
  1081. ((uint64_t)mem->length_high << 32) +
  1082. mem->length_low;
  1083. width = mem->width;
  1084. /* Multiple banks of the same type are aggregated into
  1085. * one. User mode doesn't care about multiple physical
  1086. * memory segments. It's managed as a single virtual
  1087. * heap for user mode.
  1088. */
  1089. props = find_subtype_mem(heap_type, flags, width, dev);
  1090. if (props) {
  1091. props->size_in_bytes += size_in_bytes;
  1092. break;
  1093. }
  1094. props = kfd_alloc_struct(props);
  1095. if (!props)
  1096. return -ENOMEM;
  1097. props->heap_type = heap_type;
  1098. props->flags = flags;
  1099. props->size_in_bytes = size_in_bytes;
  1100. props->width = width;
  1101. dev->node_props.mem_banks_count++;
  1102. list_add_tail(&props->list, &dev->mem_props);
  1103. break;
  1104. }
  1105. }
  1106. return 0;
  1107. }
  1108. /* kfd_parse_subtype_cache - parse cache subtypes and attach it to correct
  1109. * topology device present in the device_list
  1110. */
  1111. static int kfd_parse_subtype_cache(struct crat_subtype_cache *cache,
  1112. struct list_head *device_list)
  1113. {
  1114. struct kfd_cache_properties *props;
  1115. struct kfd_topology_device *dev;
  1116. uint32_t id;
  1117. uint32_t total_num_of_cu;
  1118. id = cache->processor_id_low;
  1119. pr_debug("Found cache entry in CRAT table with processor_id=%d\n", id);
  1120. list_for_each_entry(dev, device_list, list) {
  1121. total_num_of_cu = (dev->node_props.array_count *
  1122. dev->node_props.cu_per_simd_array);
  1123. /* Cache infomration in CRAT doesn't have proximity_domain
  1124. * information as it is associated with a CPU core or GPU
  1125. * Compute Unit. So map the cache using CPU core Id or SIMD
  1126. * (GPU) ID.
  1127. * TODO: This works because currently we can safely assume that
  1128. * Compute Units are parsed before caches are parsed. In
  1129. * future, remove this dependency
  1130. */
  1131. if ((id >= dev->node_props.cpu_core_id_base &&
  1132. id <= dev->node_props.cpu_core_id_base +
  1133. dev->node_props.cpu_cores_count) ||
  1134. (id >= dev->node_props.simd_id_base &&
  1135. id < dev->node_props.simd_id_base +
  1136. total_num_of_cu)) {
  1137. props = kfd_alloc_struct(props);
  1138. if (!props)
  1139. return -ENOMEM;
  1140. props->processor_id_low = id;
  1141. props->cache_level = cache->cache_level;
  1142. props->cache_size = cache->cache_size;
  1143. props->cacheline_size = cache->cache_line_size;
  1144. props->cachelines_per_tag = cache->lines_per_tag;
  1145. props->cache_assoc = cache->associativity;
  1146. props->cache_latency = cache->cache_latency;
  1147. memcpy(props->sibling_map, cache->sibling_map,
  1148. CRAT_SIBLINGMAP_SIZE);
  1149. /* set the sibling_map_size as 32 for CRAT from ACPI */
  1150. props->sibling_map_size = CRAT_SIBLINGMAP_SIZE;
  1151. if (cache->flags & CRAT_CACHE_FLAGS_DATA_CACHE)
  1152. props->cache_type |= HSA_CACHE_TYPE_DATA;
  1153. if (cache->flags & CRAT_CACHE_FLAGS_INST_CACHE)
  1154. props->cache_type |= HSA_CACHE_TYPE_INSTRUCTION;
  1155. if (cache->flags & CRAT_CACHE_FLAGS_CPU_CACHE)
  1156. props->cache_type |= HSA_CACHE_TYPE_CPU;
  1157. if (cache->flags & CRAT_CACHE_FLAGS_SIMD_CACHE)
  1158. props->cache_type |= HSA_CACHE_TYPE_HSACU;
  1159. dev->node_props.caches_count++;
  1160. list_add_tail(&props->list, &dev->cache_props);
  1161. break;
  1162. }
  1163. }
  1164. return 0;
  1165. }
  1166. /* kfd_parse_subtype_iolink - parse iolink subtypes and attach it to correct
  1167. * topology device present in the device_list
  1168. */
  1169. static int kfd_parse_subtype_iolink(struct crat_subtype_iolink *iolink,
  1170. struct list_head *device_list)
  1171. {
  1172. struct kfd_iolink_properties *props = NULL, *props2;
  1173. struct kfd_topology_device *dev, *to_dev;
  1174. uint32_t id_from;
  1175. uint32_t id_to;
  1176. id_from = iolink->proximity_domain_from;
  1177. id_to = iolink->proximity_domain_to;
  1178. pr_debug("Found IO link entry in CRAT table with id_from=%d, id_to %d\n",
  1179. id_from, id_to);
  1180. list_for_each_entry(dev, device_list, list) {
  1181. if (id_from == dev->proximity_domain) {
  1182. props = kfd_alloc_struct(props);
  1183. if (!props)
  1184. return -ENOMEM;
  1185. props->node_from = id_from;
  1186. props->node_to = id_to;
  1187. props->ver_maj = iolink->version_major;
  1188. props->ver_min = iolink->version_minor;
  1189. props->iolink_type = iolink->io_interface_type;
  1190. if (props->iolink_type == CRAT_IOLINK_TYPE_PCIEXPRESS)
  1191. props->weight = 20;
  1192. else if (props->iolink_type == CRAT_IOLINK_TYPE_XGMI)
  1193. props->weight = iolink->weight_xgmi;
  1194. else
  1195. props->weight = node_distance(id_from, id_to);
  1196. props->min_latency = iolink->minimum_latency;
  1197. props->max_latency = iolink->maximum_latency;
  1198. props->min_bandwidth = iolink->minimum_bandwidth_mbs;
  1199. props->max_bandwidth = iolink->maximum_bandwidth_mbs;
  1200. props->rec_transfer_size =
  1201. iolink->recommended_transfer_size;
  1202. dev->node_props.io_links_count++;
  1203. list_add_tail(&props->list, &dev->io_link_props);
  1204. break;
  1205. }
  1206. }
  1207. /* CPU topology is created before GPUs are detected, so CPU->GPU
  1208. * links are not built at that time. If a PCIe type is discovered, it
  1209. * means a GPU is detected and we are adding GPU->CPU to the topology.
  1210. * At this time, also add the corresponded CPU->GPU link if GPU
  1211. * is large bar.
  1212. * For xGMI, we only added the link with one direction in the crat
  1213. * table, add corresponded reversed direction link now.
  1214. */
  1215. if (props && (iolink->flags & CRAT_IOLINK_FLAGS_BI_DIRECTIONAL)) {
  1216. to_dev = kfd_topology_device_by_proximity_domain_no_lock(id_to);
  1217. if (!to_dev)
  1218. return -ENODEV;
  1219. /* same everything but the other direction */
  1220. props2 = kmemdup(props, sizeof(*props2), GFP_KERNEL);
  1221. if (!props2)
  1222. return -ENOMEM;
  1223. props2->node_from = id_to;
  1224. props2->node_to = id_from;
  1225. props2->kobj = NULL;
  1226. to_dev->node_props.io_links_count++;
  1227. list_add_tail(&props2->list, &to_dev->io_link_props);
  1228. }
  1229. return 0;
  1230. }
  1231. /* kfd_parse_subtype - parse subtypes and attach it to correct topology device
  1232. * present in the device_list
  1233. * @sub_type_hdr - subtype section of crat_image
  1234. * @device_list - list of topology devices present in this crat_image
  1235. */
  1236. static int kfd_parse_subtype(struct crat_subtype_generic *sub_type_hdr,
  1237. struct list_head *device_list)
  1238. {
  1239. struct crat_subtype_computeunit *cu;
  1240. struct crat_subtype_memory *mem;
  1241. struct crat_subtype_cache *cache;
  1242. struct crat_subtype_iolink *iolink;
  1243. int ret = 0;
  1244. switch (sub_type_hdr->type) {
  1245. case CRAT_SUBTYPE_COMPUTEUNIT_AFFINITY:
  1246. cu = (struct crat_subtype_computeunit *)sub_type_hdr;
  1247. ret = kfd_parse_subtype_cu(cu, device_list);
  1248. break;
  1249. case CRAT_SUBTYPE_MEMORY_AFFINITY:
  1250. mem = (struct crat_subtype_memory *)sub_type_hdr;
  1251. ret = kfd_parse_subtype_mem(mem, device_list);
  1252. break;
  1253. case CRAT_SUBTYPE_CACHE_AFFINITY:
  1254. cache = (struct crat_subtype_cache *)sub_type_hdr;
  1255. ret = kfd_parse_subtype_cache(cache, device_list);
  1256. break;
  1257. case CRAT_SUBTYPE_TLB_AFFINITY:
  1258. /*
  1259. * For now, nothing to do here
  1260. */
  1261. pr_debug("Found TLB entry in CRAT table (not processing)\n");
  1262. break;
  1263. case CRAT_SUBTYPE_CCOMPUTE_AFFINITY:
  1264. /*
  1265. * For now, nothing to do here
  1266. */
  1267. pr_debug("Found CCOMPUTE entry in CRAT table (not processing)\n");
  1268. break;
  1269. case CRAT_SUBTYPE_IOLINK_AFFINITY:
  1270. iolink = (struct crat_subtype_iolink *)sub_type_hdr;
  1271. ret = kfd_parse_subtype_iolink(iolink, device_list);
  1272. break;
  1273. default:
  1274. pr_warn("Unknown subtype %d in CRAT\n",
  1275. sub_type_hdr->type);
  1276. }
  1277. return ret;
  1278. }
  1279. /* kfd_parse_crat_table - parse CRAT table. For each node present in CRAT
  1280. * create a kfd_topology_device and add in to device_list. Also parse
  1281. * CRAT subtypes and attach it to appropriate kfd_topology_device
  1282. * @crat_image - input image containing CRAT
  1283. * @device_list - [OUT] list of kfd_topology_device generated after
  1284. * parsing crat_image
  1285. * @proximity_domain - Proximity domain of the first device in the table
  1286. *
  1287. * Return - 0 if successful else -ve value
  1288. */
  1289. int kfd_parse_crat_table(void *crat_image, struct list_head *device_list,
  1290. uint32_t proximity_domain)
  1291. {
  1292. struct kfd_topology_device *top_dev = NULL;
  1293. struct crat_subtype_generic *sub_type_hdr;
  1294. uint16_t node_id;
  1295. int ret = 0;
  1296. struct crat_header *crat_table = (struct crat_header *)crat_image;
  1297. uint16_t num_nodes;
  1298. uint32_t image_len;
  1299. if (!crat_image)
  1300. return -EINVAL;
  1301. if (!list_empty(device_list)) {
  1302. pr_warn("Error device list should be empty\n");
  1303. return -EINVAL;
  1304. }
  1305. num_nodes = crat_table->num_domains;
  1306. image_len = crat_table->length;
  1307. pr_debug("Parsing CRAT table with %d nodes\n", num_nodes);
  1308. for (node_id = 0; node_id < num_nodes; node_id++) {
  1309. top_dev = kfd_create_topology_device(device_list);
  1310. if (!top_dev)
  1311. break;
  1312. top_dev->proximity_domain = proximity_domain++;
  1313. }
  1314. if (!top_dev) {
  1315. ret = -ENOMEM;
  1316. goto err;
  1317. }
  1318. memcpy(top_dev->oem_id, crat_table->oem_id, CRAT_OEMID_LENGTH);
  1319. memcpy(top_dev->oem_table_id, crat_table->oem_table_id,
  1320. CRAT_OEMTABLEID_LENGTH);
  1321. top_dev->oem_revision = crat_table->oem_revision;
  1322. sub_type_hdr = (struct crat_subtype_generic *)(crat_table+1);
  1323. while ((char *)sub_type_hdr + sizeof(struct crat_subtype_generic) <
  1324. ((char *)crat_image) + image_len) {
  1325. if (sub_type_hdr->flags & CRAT_SUBTYPE_FLAGS_ENABLED) {
  1326. ret = kfd_parse_subtype(sub_type_hdr, device_list);
  1327. if (ret)
  1328. break;
  1329. }
  1330. sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
  1331. sub_type_hdr->length);
  1332. }
  1333. err:
  1334. if (ret)
  1335. kfd_release_topology_device_list(device_list);
  1336. return ret;
  1337. }
  1338. static int kfd_fill_gpu_cache_info_from_gfx_config(struct kfd_dev *kdev,
  1339. bool cache_line_size_missing,
  1340. struct kfd_gpu_cache_info *pcache_info)
  1341. {
  1342. struct amdgpu_device *adev = kdev->adev;
  1343. int i = 0;
  1344. /* TCP L1 Cache per CU */
  1345. if (adev->gfx.config.gc_tcp_l1_size) {
  1346. pcache_info[i].cache_size = adev->gfx.config.gc_tcp_l1_size;
  1347. pcache_info[i].cache_level = 1;
  1348. pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
  1349. CRAT_CACHE_FLAGS_DATA_CACHE |
  1350. CRAT_CACHE_FLAGS_SIMD_CACHE);
  1351. pcache_info[i].num_cu_shared = adev->gfx.config.gc_num_tcp_per_wpg / 2;
  1352. pcache_info[i].cache_line_size = adev->gfx.config.gc_tcp_cache_line_size;
  1353. if (cache_line_size_missing && !pcache_info[i].cache_line_size)
  1354. pcache_info[i].cache_line_size = 128;
  1355. i++;
  1356. }
  1357. /* Scalar L1 Instruction Cache per SQC */
  1358. if (adev->gfx.config.gc_l1_instruction_cache_size_per_sqc) {
  1359. pcache_info[i].cache_size =
  1360. adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
  1361. pcache_info[i].cache_level = 1;
  1362. pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
  1363. CRAT_CACHE_FLAGS_INST_CACHE |
  1364. CRAT_CACHE_FLAGS_SIMD_CACHE);
  1365. pcache_info[i].num_cu_shared = adev->gfx.config.gc_num_sqc_per_wgp * 2;
  1366. pcache_info[i].cache_line_size = adev->gfx.config.gc_instruction_cache_line_size;
  1367. if (cache_line_size_missing && !pcache_info[i].cache_line_size)
  1368. pcache_info[i].cache_line_size = 128;
  1369. i++;
  1370. }
  1371. /* Scalar L1 Data Cache per SQC */
  1372. if (adev->gfx.config.gc_l1_data_cache_size_per_sqc) {
  1373. pcache_info[i].cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
  1374. pcache_info[i].cache_level = 1;
  1375. pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
  1376. CRAT_CACHE_FLAGS_DATA_CACHE |
  1377. CRAT_CACHE_FLAGS_SIMD_CACHE);
  1378. pcache_info[i].num_cu_shared = adev->gfx.config.gc_num_sqc_per_wgp * 2;
  1379. pcache_info[i].cache_line_size = adev->gfx.config.gc_scalar_data_cache_line_size;
  1380. if (cache_line_size_missing && !pcache_info[i].cache_line_size)
  1381. pcache_info[i].cache_line_size = 64;
  1382. i++;
  1383. }
  1384. /* GL1 Data Cache per SA */
  1385. if (adev->gfx.config.gc_gl1c_per_sa &&
  1386. adev->gfx.config.gc_gl1c_size_per_instance) {
  1387. pcache_info[i].cache_size = adev->gfx.config.gc_gl1c_per_sa *
  1388. adev->gfx.config.gc_gl1c_size_per_instance;
  1389. pcache_info[i].cache_level = 1;
  1390. pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
  1391. CRAT_CACHE_FLAGS_DATA_CACHE |
  1392. CRAT_CACHE_FLAGS_SIMD_CACHE);
  1393. pcache_info[i].num_cu_shared = adev->gfx.config.max_cu_per_sh;
  1394. if (cache_line_size_missing)
  1395. pcache_info[i].cache_line_size = 128;
  1396. i++;
  1397. }
  1398. /* L2 Data Cache per GPU (Total Tex Cache) */
  1399. if (adev->gfx.config.gc_gl2c_per_gpu) {
  1400. pcache_info[i].cache_size = adev->gfx.config.gc_gl2c_per_gpu;
  1401. pcache_info[i].cache_level = 2;
  1402. pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
  1403. CRAT_CACHE_FLAGS_DATA_CACHE |
  1404. CRAT_CACHE_FLAGS_SIMD_CACHE);
  1405. pcache_info[i].num_cu_shared = adev->gfx.config.max_cu_per_sh;
  1406. pcache_info[i].cache_line_size = adev->gfx.config.gc_tcc_cache_line_size;
  1407. if (cache_line_size_missing && !pcache_info[i].cache_line_size)
  1408. pcache_info[i].cache_line_size = 128;
  1409. i++;
  1410. }
  1411. /* L3 Data Cache per GPU */
  1412. if (adev->gmc.mall_size) {
  1413. pcache_info[i].cache_size = adev->gmc.mall_size / 1024;
  1414. pcache_info[i].cache_level = 3;
  1415. pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
  1416. CRAT_CACHE_FLAGS_DATA_CACHE |
  1417. CRAT_CACHE_FLAGS_SIMD_CACHE);
  1418. pcache_info[i].num_cu_shared = adev->gfx.config.max_cu_per_sh;
  1419. pcache_info[i].cache_line_size = 64;
  1420. i++;
  1421. }
  1422. return i;
  1423. }
  1424. static int kfd_fill_gpu_cache_info_from_gfx_config_v2(struct kfd_dev *kdev,
  1425. struct kfd_gpu_cache_info *pcache_info)
  1426. {
  1427. struct amdgpu_device *adev = kdev->adev;
  1428. int i = 0;
  1429. /* TCP L1 Cache per CU */
  1430. if (adev->gfx.config.gc_tcp_size_per_cu) {
  1431. pcache_info[i].cache_size = adev->gfx.config.gc_tcp_size_per_cu;
  1432. pcache_info[i].cache_level = 1;
  1433. /* Cacheline size not available in IP discovery for gc943,gc944 */
  1434. pcache_info[i].cache_line_size = 128;
  1435. pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
  1436. CRAT_CACHE_FLAGS_DATA_CACHE |
  1437. CRAT_CACHE_FLAGS_SIMD_CACHE);
  1438. pcache_info[i].num_cu_shared = 1;
  1439. i++;
  1440. }
  1441. /* Scalar L1 Instruction Cache per SQC */
  1442. if (adev->gfx.config.gc_l1_instruction_cache_size_per_sqc) {
  1443. pcache_info[i].cache_size =
  1444. adev->gfx.config.gc_l1_instruction_cache_size_per_sqc;
  1445. pcache_info[i].cache_level = 1;
  1446. pcache_info[i].cache_line_size = 64;
  1447. pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
  1448. CRAT_CACHE_FLAGS_INST_CACHE |
  1449. CRAT_CACHE_FLAGS_SIMD_CACHE);
  1450. pcache_info[i].num_cu_shared = adev->gfx.config.gc_num_cu_per_sqc;
  1451. i++;
  1452. }
  1453. /* Scalar L1 Data Cache per SQC */
  1454. if (adev->gfx.config.gc_l1_data_cache_size_per_sqc) {
  1455. pcache_info[i].cache_size = adev->gfx.config.gc_l1_data_cache_size_per_sqc;
  1456. pcache_info[i].cache_level = 1;
  1457. pcache_info[i].cache_line_size = 64;
  1458. pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
  1459. CRAT_CACHE_FLAGS_DATA_CACHE |
  1460. CRAT_CACHE_FLAGS_SIMD_CACHE);
  1461. pcache_info[i].num_cu_shared = adev->gfx.config.gc_num_cu_per_sqc;
  1462. i++;
  1463. }
  1464. /* L2 Data Cache per GPU (Total Tex Cache) */
  1465. if (adev->gfx.config.gc_tcc_size) {
  1466. pcache_info[i].cache_size = adev->gfx.config.gc_tcc_size;
  1467. pcache_info[i].cache_level = 2;
  1468. pcache_info[i].cache_line_size = 128;
  1469. pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
  1470. CRAT_CACHE_FLAGS_DATA_CACHE |
  1471. CRAT_CACHE_FLAGS_SIMD_CACHE);
  1472. pcache_info[i].num_cu_shared = adev->gfx.config.max_cu_per_sh;
  1473. i++;
  1474. }
  1475. /* L3 Data Cache per GPU */
  1476. if (adev->gmc.mall_size) {
  1477. pcache_info[i].cache_size = adev->gmc.mall_size / 1024;
  1478. pcache_info[i].cache_level = 3;
  1479. pcache_info[i].cache_line_size = 64;
  1480. pcache_info[i].flags = (CRAT_CACHE_FLAGS_ENABLED |
  1481. CRAT_CACHE_FLAGS_DATA_CACHE |
  1482. CRAT_CACHE_FLAGS_SIMD_CACHE);
  1483. pcache_info[i].num_cu_shared = adev->gfx.config.max_cu_per_sh;
  1484. i++;
  1485. }
  1486. return i;
  1487. }
  1488. int kfd_get_gpu_cache_info(struct kfd_node *kdev, struct kfd_gpu_cache_info **pcache_info)
  1489. {
  1490. int num_of_cache_types = 0;
  1491. bool cache_line_size_missing = false;
  1492. switch (kdev->adev->asic_type) {
  1493. case CHIP_KAVERI:
  1494. *pcache_info = kaveri_cache_info;
  1495. num_of_cache_types = ARRAY_SIZE(kaveri_cache_info);
  1496. break;
  1497. case CHIP_HAWAII:
  1498. *pcache_info = hawaii_cache_info;
  1499. num_of_cache_types = ARRAY_SIZE(hawaii_cache_info);
  1500. break;
  1501. case CHIP_CARRIZO:
  1502. *pcache_info = carrizo_cache_info;
  1503. num_of_cache_types = ARRAY_SIZE(carrizo_cache_info);
  1504. break;
  1505. case CHIP_TONGA:
  1506. *pcache_info = tonga_cache_info;
  1507. num_of_cache_types = ARRAY_SIZE(tonga_cache_info);
  1508. break;
  1509. case CHIP_FIJI:
  1510. *pcache_info = fiji_cache_info;
  1511. num_of_cache_types = ARRAY_SIZE(fiji_cache_info);
  1512. break;
  1513. case CHIP_POLARIS10:
  1514. *pcache_info = polaris10_cache_info;
  1515. num_of_cache_types = ARRAY_SIZE(polaris10_cache_info);
  1516. break;
  1517. case CHIP_POLARIS11:
  1518. *pcache_info = polaris11_cache_info;
  1519. num_of_cache_types = ARRAY_SIZE(polaris11_cache_info);
  1520. break;
  1521. case CHIP_POLARIS12:
  1522. *pcache_info = polaris12_cache_info;
  1523. num_of_cache_types = ARRAY_SIZE(polaris12_cache_info);
  1524. break;
  1525. case CHIP_VEGAM:
  1526. *pcache_info = vegam_cache_info;
  1527. num_of_cache_types = ARRAY_SIZE(vegam_cache_info);
  1528. break;
  1529. default:
  1530. switch (KFD_GC_VERSION(kdev)) {
  1531. case IP_VERSION(9, 0, 1):
  1532. *pcache_info = vega10_cache_info;
  1533. num_of_cache_types = ARRAY_SIZE(vega10_cache_info);
  1534. break;
  1535. case IP_VERSION(9, 2, 1):
  1536. *pcache_info = vega12_cache_info;
  1537. num_of_cache_types = ARRAY_SIZE(vega12_cache_info);
  1538. break;
  1539. case IP_VERSION(9, 4, 0):
  1540. case IP_VERSION(9, 4, 1):
  1541. *pcache_info = vega20_cache_info;
  1542. num_of_cache_types = ARRAY_SIZE(vega20_cache_info);
  1543. break;
  1544. case IP_VERSION(9, 4, 2):
  1545. *pcache_info = aldebaran_cache_info;
  1546. num_of_cache_types = ARRAY_SIZE(aldebaran_cache_info);
  1547. break;
  1548. case IP_VERSION(9, 4, 3):
  1549. case IP_VERSION(9, 4, 4):
  1550. num_of_cache_types =
  1551. kfd_fill_gpu_cache_info_from_gfx_config_v2(kdev->kfd,
  1552. *pcache_info);
  1553. break;
  1554. case IP_VERSION(9, 1, 0):
  1555. case IP_VERSION(9, 2, 2):
  1556. *pcache_info = raven_cache_info;
  1557. num_of_cache_types = ARRAY_SIZE(raven_cache_info);
  1558. break;
  1559. case IP_VERSION(9, 3, 0):
  1560. *pcache_info = renoir_cache_info;
  1561. num_of_cache_types = ARRAY_SIZE(renoir_cache_info);
  1562. break;
  1563. case IP_VERSION(10, 1, 10):
  1564. case IP_VERSION(10, 1, 2):
  1565. case IP_VERSION(10, 1, 3):
  1566. case IP_VERSION(10, 1, 4):
  1567. *pcache_info = navi10_cache_info;
  1568. num_of_cache_types = ARRAY_SIZE(navi10_cache_info);
  1569. break;
  1570. case IP_VERSION(10, 1, 1):
  1571. *pcache_info = navi14_cache_info;
  1572. num_of_cache_types = ARRAY_SIZE(navi14_cache_info);
  1573. break;
  1574. case IP_VERSION(10, 3, 0):
  1575. *pcache_info = sienna_cichlid_cache_info;
  1576. num_of_cache_types = ARRAY_SIZE(sienna_cichlid_cache_info);
  1577. break;
  1578. case IP_VERSION(10, 3, 2):
  1579. *pcache_info = navy_flounder_cache_info;
  1580. num_of_cache_types = ARRAY_SIZE(navy_flounder_cache_info);
  1581. break;
  1582. case IP_VERSION(10, 3, 4):
  1583. *pcache_info = dimgrey_cavefish_cache_info;
  1584. num_of_cache_types = ARRAY_SIZE(dimgrey_cavefish_cache_info);
  1585. break;
  1586. case IP_VERSION(10, 3, 1):
  1587. *pcache_info = vangogh_cache_info;
  1588. num_of_cache_types = ARRAY_SIZE(vangogh_cache_info);
  1589. break;
  1590. case IP_VERSION(10, 3, 5):
  1591. *pcache_info = beige_goby_cache_info;
  1592. num_of_cache_types = ARRAY_SIZE(beige_goby_cache_info);
  1593. break;
  1594. case IP_VERSION(10, 3, 3):
  1595. *pcache_info = yellow_carp_cache_info;
  1596. num_of_cache_types = ARRAY_SIZE(yellow_carp_cache_info);
  1597. break;
  1598. case IP_VERSION(10, 3, 6):
  1599. *pcache_info = gc_10_3_6_cache_info;
  1600. num_of_cache_types = ARRAY_SIZE(gc_10_3_6_cache_info);
  1601. break;
  1602. case IP_VERSION(10, 3, 7):
  1603. *pcache_info = gfx1037_cache_info;
  1604. num_of_cache_types = ARRAY_SIZE(gfx1037_cache_info);
  1605. break;
  1606. case IP_VERSION(11, 0, 0):
  1607. case IP_VERSION(11, 0, 1):
  1608. case IP_VERSION(11, 0, 2):
  1609. case IP_VERSION(11, 0, 3):
  1610. case IP_VERSION(11, 0, 4):
  1611. case IP_VERSION(11, 5, 0):
  1612. case IP_VERSION(11, 5, 1):
  1613. case IP_VERSION(11, 5, 2):
  1614. /* Cacheline size not available in IP discovery for gc11.
  1615. * kfd_fill_gpu_cache_info_from_gfx_config to hard code it
  1616. */
  1617. cache_line_size_missing = true;
  1618. fallthrough;
  1619. case IP_VERSION(12, 0, 0):
  1620. case IP_VERSION(12, 0, 1):
  1621. num_of_cache_types =
  1622. kfd_fill_gpu_cache_info_from_gfx_config(kdev->kfd,
  1623. cache_line_size_missing,
  1624. *pcache_info);
  1625. break;
  1626. default:
  1627. *pcache_info = dummy_cache_info;
  1628. num_of_cache_types = ARRAY_SIZE(dummy_cache_info);
  1629. pr_warn("dummy cache info is used temporarily and real cache info need update later.\n");
  1630. break;
  1631. }
  1632. }
  1633. return num_of_cache_types;
  1634. }
  1635. /* Memory required to create Virtual CRAT.
  1636. * Since there is no easy way to predict the amount of memory required, the
  1637. * following amount is allocated for GPU Virtual CRAT. This is
  1638. * expected to cover all known conditions. But to be safe additional check
  1639. * is put in the code to ensure we don't overwrite.
  1640. */
  1641. #define VCRAT_SIZE_FOR_GPU (4 * PAGE_SIZE)
  1642. /* kfd_fill_cu_for_cpu - Fill in Compute info for the given CPU NUMA node
  1643. *
  1644. * @numa_node_id: CPU NUMA node id
  1645. * @avail_size: Available size in the memory
  1646. * @sub_type_hdr: Memory into which compute info will be filled in
  1647. *
  1648. * Return 0 if successful else return -ve value
  1649. */
  1650. static int kfd_fill_cu_for_cpu(int numa_node_id, int *avail_size,
  1651. int proximity_domain,
  1652. struct crat_subtype_computeunit *sub_type_hdr)
  1653. {
  1654. const struct cpumask *cpumask;
  1655. *avail_size -= sizeof(struct crat_subtype_computeunit);
  1656. if (*avail_size < 0)
  1657. return -ENOMEM;
  1658. memset(sub_type_hdr, 0, sizeof(struct crat_subtype_computeunit));
  1659. /* Fill in subtype header data */
  1660. sub_type_hdr->type = CRAT_SUBTYPE_COMPUTEUNIT_AFFINITY;
  1661. sub_type_hdr->length = sizeof(struct crat_subtype_computeunit);
  1662. sub_type_hdr->flags = CRAT_SUBTYPE_FLAGS_ENABLED;
  1663. cpumask = cpumask_of_node(numa_node_id);
  1664. /* Fill in CU data */
  1665. sub_type_hdr->flags |= CRAT_CU_FLAGS_CPU_PRESENT;
  1666. sub_type_hdr->proximity_domain = proximity_domain;
  1667. sub_type_hdr->processor_id_low = kfd_numa_node_to_apic_id(numa_node_id);
  1668. if (sub_type_hdr->processor_id_low == -1)
  1669. return -EINVAL;
  1670. sub_type_hdr->num_cpu_cores = cpumask_weight(cpumask);
  1671. return 0;
  1672. }
  1673. /* kfd_fill_mem_info_for_cpu - Fill in Memory info for the given CPU NUMA node
  1674. *
  1675. * @numa_node_id: CPU NUMA node id
  1676. * @avail_size: Available size in the memory
  1677. * @sub_type_hdr: Memory into which compute info will be filled in
  1678. *
  1679. * Return 0 if successful else return -ve value
  1680. */
  1681. static int kfd_fill_mem_info_for_cpu(int numa_node_id, int *avail_size,
  1682. int proximity_domain,
  1683. struct crat_subtype_memory *sub_type_hdr)
  1684. {
  1685. uint64_t mem_in_bytes = 0;
  1686. pg_data_t *pgdat;
  1687. int zone_type;
  1688. *avail_size -= sizeof(struct crat_subtype_memory);
  1689. if (*avail_size < 0)
  1690. return -ENOMEM;
  1691. memset(sub_type_hdr, 0, sizeof(struct crat_subtype_memory));
  1692. /* Fill in subtype header data */
  1693. sub_type_hdr->type = CRAT_SUBTYPE_MEMORY_AFFINITY;
  1694. sub_type_hdr->length = sizeof(struct crat_subtype_memory);
  1695. sub_type_hdr->flags = CRAT_SUBTYPE_FLAGS_ENABLED;
  1696. /* Fill in Memory Subunit data */
  1697. /* Unlike si_meminfo, si_meminfo_node is not exported. So
  1698. * the following lines are duplicated from si_meminfo_node
  1699. * function
  1700. */
  1701. pgdat = NODE_DATA(numa_node_id);
  1702. for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++)
  1703. mem_in_bytes += zone_managed_pages(&pgdat->node_zones[zone_type]);
  1704. mem_in_bytes <<= PAGE_SHIFT;
  1705. sub_type_hdr->length_low = lower_32_bits(mem_in_bytes);
  1706. sub_type_hdr->length_high = upper_32_bits(mem_in_bytes);
  1707. sub_type_hdr->proximity_domain = proximity_domain;
  1708. return 0;
  1709. }
  1710. #ifdef CONFIG_X86_64
  1711. static int kfd_fill_iolink_info_for_cpu(int numa_node_id, int *avail_size,
  1712. uint32_t *num_entries,
  1713. struct crat_subtype_iolink *sub_type_hdr)
  1714. {
  1715. int nid;
  1716. struct cpuinfo_x86 *c = &cpu_data(0);
  1717. uint8_t link_type;
  1718. if (c->x86_vendor == X86_VENDOR_AMD)
  1719. link_type = CRAT_IOLINK_TYPE_HYPERTRANSPORT;
  1720. else
  1721. link_type = CRAT_IOLINK_TYPE_QPI_1_1;
  1722. *num_entries = 0;
  1723. /* Create IO links from this node to other CPU nodes */
  1724. for_each_online_node(nid) {
  1725. if (nid == numa_node_id) /* node itself */
  1726. continue;
  1727. *avail_size -= sizeof(struct crat_subtype_iolink);
  1728. if (*avail_size < 0)
  1729. return -ENOMEM;
  1730. memset(sub_type_hdr, 0, sizeof(struct crat_subtype_iolink));
  1731. /* Fill in subtype header data */
  1732. sub_type_hdr->type = CRAT_SUBTYPE_IOLINK_AFFINITY;
  1733. sub_type_hdr->length = sizeof(struct crat_subtype_iolink);
  1734. sub_type_hdr->flags = CRAT_SUBTYPE_FLAGS_ENABLED;
  1735. /* Fill in IO link data */
  1736. sub_type_hdr->proximity_domain_from = numa_node_id;
  1737. sub_type_hdr->proximity_domain_to = nid;
  1738. sub_type_hdr->io_interface_type = link_type;
  1739. (*num_entries)++;
  1740. sub_type_hdr++;
  1741. }
  1742. return 0;
  1743. }
  1744. #endif
  1745. /* kfd_create_vcrat_image_cpu - Create Virtual CRAT for CPU
  1746. *
  1747. * @pcrat_image: Fill in VCRAT for CPU
  1748. * @size: [IN] allocated size of crat_image.
  1749. * [OUT] actual size of data filled in crat_image
  1750. */
  1751. static int kfd_create_vcrat_image_cpu(void *pcrat_image, size_t *size)
  1752. {
  1753. struct crat_header *crat_table = (struct crat_header *)pcrat_image;
  1754. struct acpi_table_header *acpi_table;
  1755. acpi_status status;
  1756. struct crat_subtype_generic *sub_type_hdr;
  1757. int avail_size = *size;
  1758. int numa_node_id;
  1759. #ifdef CONFIG_X86_64
  1760. uint32_t entries = 0;
  1761. #endif
  1762. int ret = 0;
  1763. if (!pcrat_image)
  1764. return -EINVAL;
  1765. /* Fill in CRAT Header.
  1766. * Modify length and total_entries as subunits are added.
  1767. */
  1768. avail_size -= sizeof(struct crat_header);
  1769. if (avail_size < 0)
  1770. return -ENOMEM;
  1771. memset(crat_table, 0, sizeof(struct crat_header));
  1772. memcpy(&crat_table->signature, CRAT_SIGNATURE,
  1773. sizeof(crat_table->signature));
  1774. crat_table->length = sizeof(struct crat_header);
  1775. status = acpi_get_table("DSDT", 0, &acpi_table);
  1776. if (status != AE_OK)
  1777. pr_warn("DSDT table not found for OEM information\n");
  1778. else {
  1779. crat_table->oem_revision = acpi_table->revision;
  1780. memcpy(crat_table->oem_id, acpi_table->oem_id,
  1781. CRAT_OEMID_LENGTH);
  1782. memcpy(crat_table->oem_table_id, acpi_table->oem_table_id,
  1783. CRAT_OEMTABLEID_LENGTH);
  1784. acpi_put_table(acpi_table);
  1785. }
  1786. crat_table->total_entries = 0;
  1787. crat_table->num_domains = 0;
  1788. sub_type_hdr = (struct crat_subtype_generic *)(crat_table+1);
  1789. for_each_online_node(numa_node_id) {
  1790. if (kfd_numa_node_to_apic_id(numa_node_id) == -1)
  1791. continue;
  1792. /* Fill in Subtype: Compute Unit */
  1793. ret = kfd_fill_cu_for_cpu(numa_node_id, &avail_size,
  1794. crat_table->num_domains,
  1795. (struct crat_subtype_computeunit *)sub_type_hdr);
  1796. if (ret < 0)
  1797. return ret;
  1798. crat_table->length += sub_type_hdr->length;
  1799. crat_table->total_entries++;
  1800. sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
  1801. sub_type_hdr->length);
  1802. /* Fill in Subtype: Memory */
  1803. ret = kfd_fill_mem_info_for_cpu(numa_node_id, &avail_size,
  1804. crat_table->num_domains,
  1805. (struct crat_subtype_memory *)sub_type_hdr);
  1806. if (ret < 0)
  1807. return ret;
  1808. crat_table->length += sub_type_hdr->length;
  1809. crat_table->total_entries++;
  1810. sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
  1811. sub_type_hdr->length);
  1812. /* Fill in Subtype: IO Link */
  1813. #ifdef CONFIG_X86_64
  1814. ret = kfd_fill_iolink_info_for_cpu(numa_node_id, &avail_size,
  1815. &entries,
  1816. (struct crat_subtype_iolink *)sub_type_hdr);
  1817. if (ret < 0)
  1818. return ret;
  1819. if (entries) {
  1820. crat_table->length += (sub_type_hdr->length * entries);
  1821. crat_table->total_entries += entries;
  1822. sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
  1823. sub_type_hdr->length * entries);
  1824. }
  1825. #else
  1826. pr_info("IO link not available for non x86 platforms\n");
  1827. #endif
  1828. crat_table->num_domains++;
  1829. }
  1830. /* TODO: Add cache Subtype for CPU.
  1831. * Currently, CPU cache information is available in function
  1832. * detect_cache_attributes(cpu) defined in the file
  1833. * ./arch/x86/kernel/cpu/intel_cacheinfo.c. This function is not
  1834. * exported and to get the same information the code needs to be
  1835. * duplicated.
  1836. */
  1837. *size = crat_table->length;
  1838. pr_info("Virtual CRAT table created for CPU\n");
  1839. return 0;
  1840. }
  1841. static int kfd_fill_gpu_memory_affinity(int *avail_size,
  1842. struct kfd_node *kdev, uint8_t type, uint64_t size,
  1843. struct crat_subtype_memory *sub_type_hdr,
  1844. uint32_t proximity_domain,
  1845. const struct kfd_local_mem_info *local_mem_info)
  1846. {
  1847. *avail_size -= sizeof(struct crat_subtype_memory);
  1848. if (*avail_size < 0)
  1849. return -ENOMEM;
  1850. memset((void *)sub_type_hdr, 0, sizeof(struct crat_subtype_memory));
  1851. sub_type_hdr->type = CRAT_SUBTYPE_MEMORY_AFFINITY;
  1852. sub_type_hdr->length = sizeof(struct crat_subtype_memory);
  1853. sub_type_hdr->flags |= CRAT_SUBTYPE_FLAGS_ENABLED;
  1854. sub_type_hdr->proximity_domain = proximity_domain;
  1855. pr_debug("Fill gpu memory affinity - type 0x%x size 0x%llx\n",
  1856. type, size);
  1857. sub_type_hdr->length_low = lower_32_bits(size);
  1858. sub_type_hdr->length_high = upper_32_bits(size);
  1859. sub_type_hdr->width = local_mem_info->vram_width;
  1860. sub_type_hdr->visibility_type = type;
  1861. return 0;
  1862. }
  1863. #ifdef CONFIG_ACPI_NUMA
  1864. static void kfd_find_numa_node_in_srat(struct kfd_node *kdev)
  1865. {
  1866. struct acpi_table_header *table_header = NULL;
  1867. struct acpi_subtable_header *sub_header = NULL;
  1868. unsigned long table_end, subtable_len;
  1869. u32 pci_id = pci_domain_nr(kdev->adev->pdev->bus) << 16 |
  1870. pci_dev_id(kdev->adev->pdev);
  1871. u32 bdf;
  1872. acpi_status status;
  1873. struct acpi_srat_cpu_affinity *cpu;
  1874. struct acpi_srat_generic_affinity *gpu;
  1875. int pxm = 0, max_pxm = 0;
  1876. int numa_node = NUMA_NO_NODE;
  1877. bool found = false;
  1878. /* Fetch the SRAT table from ACPI */
  1879. status = acpi_get_table(ACPI_SIG_SRAT, 0, &table_header);
  1880. if (status == AE_NOT_FOUND) {
  1881. pr_warn("SRAT table not found\n");
  1882. return;
  1883. } else if (ACPI_FAILURE(status)) {
  1884. const char *err = acpi_format_exception(status);
  1885. pr_err("SRAT table error: %s\n", err);
  1886. return;
  1887. }
  1888. table_end = (unsigned long)table_header + table_header->length;
  1889. /* Parse all entries looking for a match. */
  1890. sub_header = (struct acpi_subtable_header *)
  1891. ((unsigned long)table_header +
  1892. sizeof(struct acpi_table_srat));
  1893. subtable_len = sub_header->length;
  1894. while (((unsigned long)sub_header) + subtable_len < table_end) {
  1895. /*
  1896. * If length is 0, break from this loop to avoid
  1897. * infinite loop.
  1898. */
  1899. if (subtable_len == 0) {
  1900. pr_err("SRAT invalid zero length\n");
  1901. break;
  1902. }
  1903. switch (sub_header->type) {
  1904. case ACPI_SRAT_TYPE_CPU_AFFINITY:
  1905. cpu = (struct acpi_srat_cpu_affinity *)sub_header;
  1906. pxm = *((u32 *)cpu->proximity_domain_hi) << 8 |
  1907. cpu->proximity_domain_lo;
  1908. if (pxm > max_pxm)
  1909. max_pxm = pxm;
  1910. break;
  1911. case ACPI_SRAT_TYPE_GENERIC_AFFINITY:
  1912. gpu = (struct acpi_srat_generic_affinity *)sub_header;
  1913. bdf = *((u16 *)(&gpu->device_handle[0])) << 16 |
  1914. *((u16 *)(&gpu->device_handle[2]));
  1915. if (bdf == pci_id) {
  1916. found = true;
  1917. numa_node = pxm_to_node(gpu->proximity_domain);
  1918. }
  1919. break;
  1920. default:
  1921. break;
  1922. }
  1923. if (found)
  1924. break;
  1925. sub_header = (struct acpi_subtable_header *)
  1926. ((unsigned long)sub_header + subtable_len);
  1927. subtable_len = sub_header->length;
  1928. }
  1929. acpi_put_table(table_header);
  1930. /* Workaround bad cpu-gpu binding case */
  1931. if (found && (numa_node < 0 ||
  1932. numa_node > pxm_to_node(max_pxm)))
  1933. numa_node = 0;
  1934. if (numa_node != NUMA_NO_NODE)
  1935. set_dev_node(&kdev->adev->pdev->dev, numa_node);
  1936. }
  1937. #endif
  1938. #define KFD_CRAT_INTRA_SOCKET_WEIGHT 13
  1939. #define KFD_CRAT_XGMI_WEIGHT 15
  1940. /* kfd_fill_gpu_direct_io_link - Fill in direct io link from GPU
  1941. * to its NUMA node
  1942. * @avail_size: Available size in the memory
  1943. * @kdev - [IN] GPU device
  1944. * @sub_type_hdr: Memory into which io link info will be filled in
  1945. * @proximity_domain - proximity domain of the GPU node
  1946. *
  1947. * Return 0 if successful else return -ve value
  1948. */
  1949. static int kfd_fill_gpu_direct_io_link_to_cpu(int *avail_size,
  1950. struct kfd_node *kdev,
  1951. struct crat_subtype_iolink *sub_type_hdr,
  1952. uint32_t proximity_domain)
  1953. {
  1954. *avail_size -= sizeof(struct crat_subtype_iolink);
  1955. if (*avail_size < 0)
  1956. return -ENOMEM;
  1957. memset((void *)sub_type_hdr, 0, sizeof(struct crat_subtype_iolink));
  1958. /* Fill in subtype header data */
  1959. sub_type_hdr->type = CRAT_SUBTYPE_IOLINK_AFFINITY;
  1960. sub_type_hdr->length = sizeof(struct crat_subtype_iolink);
  1961. sub_type_hdr->flags |= CRAT_SUBTYPE_FLAGS_ENABLED;
  1962. if (kfd_dev_is_large_bar(kdev))
  1963. sub_type_hdr->flags |= CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
  1964. /* Fill in IOLINK subtype.
  1965. * TODO: Fill-in other fields of iolink subtype
  1966. */
  1967. if (kdev->adev->gmc.xgmi.connected_to_cpu ||
  1968. (KFD_GC_VERSION(kdev) == IP_VERSION(9, 4, 3) &&
  1969. kdev->adev->smuio.funcs->get_pkg_type(kdev->adev) ==
  1970. AMDGPU_PKG_TYPE_APU)) {
  1971. bool ext_cpu = KFD_GC_VERSION(kdev) != IP_VERSION(9, 4, 3);
  1972. int mem_bw = 819200, weight = ext_cpu ? KFD_CRAT_XGMI_WEIGHT :
  1973. KFD_CRAT_INTRA_SOCKET_WEIGHT;
  1974. uint32_t bandwidth = ext_cpu ? amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(
  1975. kdev->adev, NULL, true) : mem_bw;
  1976. /*
  1977. * with host gpu xgmi link, host can access gpu memory whether
  1978. * or not pcie bar type is large, so always create bidirectional
  1979. * io link.
  1980. */
  1981. sub_type_hdr->flags |= CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
  1982. sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
  1983. sub_type_hdr->weight_xgmi = weight;
  1984. sub_type_hdr->minimum_bandwidth_mbs = bandwidth;
  1985. sub_type_hdr->maximum_bandwidth_mbs = bandwidth;
  1986. } else {
  1987. sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_PCIEXPRESS;
  1988. sub_type_hdr->minimum_bandwidth_mbs =
  1989. amdgpu_amdkfd_get_pcie_bandwidth_mbytes(kdev->adev, true);
  1990. sub_type_hdr->maximum_bandwidth_mbs =
  1991. amdgpu_amdkfd_get_pcie_bandwidth_mbytes(kdev->adev, false);
  1992. }
  1993. sub_type_hdr->proximity_domain_from = proximity_domain;
  1994. #ifdef CONFIG_ACPI_NUMA
  1995. if (kdev->adev->pdev->dev.numa_node == NUMA_NO_NODE &&
  1996. num_possible_nodes() > 1)
  1997. kfd_find_numa_node_in_srat(kdev);
  1998. #endif
  1999. #ifdef CONFIG_NUMA
  2000. if (kdev->adev->pdev->dev.numa_node == NUMA_NO_NODE)
  2001. sub_type_hdr->proximity_domain_to = 0;
  2002. else
  2003. sub_type_hdr->proximity_domain_to = kdev->adev->pdev->dev.numa_node;
  2004. #else
  2005. sub_type_hdr->proximity_domain_to = 0;
  2006. #endif
  2007. return 0;
  2008. }
  2009. static int kfd_fill_gpu_xgmi_link_to_gpu(int *avail_size,
  2010. struct kfd_node *kdev,
  2011. struct kfd_node *peer_kdev,
  2012. struct crat_subtype_iolink *sub_type_hdr,
  2013. uint32_t proximity_domain_from,
  2014. uint32_t proximity_domain_to)
  2015. {
  2016. bool use_ta_info = kdev->kfd->num_nodes == 1;
  2017. *avail_size -= sizeof(struct crat_subtype_iolink);
  2018. if (*avail_size < 0)
  2019. return -ENOMEM;
  2020. memset((void *)sub_type_hdr, 0, sizeof(struct crat_subtype_iolink));
  2021. sub_type_hdr->type = CRAT_SUBTYPE_IOLINK_AFFINITY;
  2022. sub_type_hdr->length = sizeof(struct crat_subtype_iolink);
  2023. sub_type_hdr->flags |= CRAT_SUBTYPE_FLAGS_ENABLED |
  2024. CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
  2025. sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
  2026. sub_type_hdr->proximity_domain_from = proximity_domain_from;
  2027. sub_type_hdr->proximity_domain_to = proximity_domain_to;
  2028. if (use_ta_info) {
  2029. sub_type_hdr->weight_xgmi = KFD_CRAT_XGMI_WEIGHT *
  2030. amdgpu_amdkfd_get_xgmi_hops_count(kdev->adev, peer_kdev->adev);
  2031. sub_type_hdr->maximum_bandwidth_mbs =
  2032. amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(kdev->adev,
  2033. peer_kdev->adev, false);
  2034. sub_type_hdr->minimum_bandwidth_mbs = sub_type_hdr->maximum_bandwidth_mbs ?
  2035. amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(kdev->adev, NULL, true) : 0;
  2036. } else {
  2037. bool is_single_hop = kdev->kfd == peer_kdev->kfd;
  2038. int weight = is_single_hop ? KFD_CRAT_INTRA_SOCKET_WEIGHT :
  2039. (2 * KFD_CRAT_INTRA_SOCKET_WEIGHT) + KFD_CRAT_XGMI_WEIGHT;
  2040. int mem_bw = 819200;
  2041. sub_type_hdr->weight_xgmi = weight;
  2042. sub_type_hdr->maximum_bandwidth_mbs = is_single_hop ? mem_bw : 0;
  2043. sub_type_hdr->minimum_bandwidth_mbs = is_single_hop ? mem_bw : 0;
  2044. }
  2045. return 0;
  2046. }
  2047. /* kfd_create_vcrat_image_gpu - Create Virtual CRAT for CPU
  2048. *
  2049. * @pcrat_image: Fill in VCRAT for GPU
  2050. * @size: [IN] allocated size of crat_image.
  2051. * [OUT] actual size of data filled in crat_image
  2052. */
  2053. static int kfd_create_vcrat_image_gpu(void *pcrat_image,
  2054. size_t *size, struct kfd_node *kdev,
  2055. uint32_t proximity_domain)
  2056. {
  2057. struct crat_header *crat_table = (struct crat_header *)pcrat_image;
  2058. struct amdgpu_gfx_config *gfx_info = &kdev->adev->gfx.config;
  2059. struct amdgpu_cu_info *cu_info = &kdev->adev->gfx.cu_info;
  2060. struct crat_subtype_generic *sub_type_hdr;
  2061. struct kfd_local_mem_info local_mem_info;
  2062. struct kfd_topology_device *peer_dev;
  2063. struct crat_subtype_computeunit *cu;
  2064. int avail_size = *size;
  2065. uint32_t total_num_of_cu;
  2066. uint32_t nid = 0;
  2067. int ret = 0;
  2068. if (!pcrat_image || avail_size < VCRAT_SIZE_FOR_GPU)
  2069. return -EINVAL;
  2070. /* Fill the CRAT Header.
  2071. * Modify length and total_entries as subunits are added.
  2072. */
  2073. avail_size -= sizeof(struct crat_header);
  2074. memset(crat_table, 0, sizeof(struct crat_header));
  2075. memcpy(&crat_table->signature, CRAT_SIGNATURE,
  2076. sizeof(crat_table->signature));
  2077. /* Change length as we add more subtypes*/
  2078. crat_table->length = sizeof(struct crat_header);
  2079. crat_table->num_domains = 1;
  2080. crat_table->total_entries = 0;
  2081. /* Fill in Subtype: Compute Unit
  2082. * First fill in the sub type header and then sub type data
  2083. */
  2084. avail_size -= sizeof(struct crat_subtype_computeunit);
  2085. sub_type_hdr = (struct crat_subtype_generic *)(crat_table + 1);
  2086. memset(sub_type_hdr, 0, sizeof(struct crat_subtype_computeunit));
  2087. sub_type_hdr->type = CRAT_SUBTYPE_COMPUTEUNIT_AFFINITY;
  2088. sub_type_hdr->length = sizeof(struct crat_subtype_computeunit);
  2089. sub_type_hdr->flags = CRAT_SUBTYPE_FLAGS_ENABLED;
  2090. /* Fill CU subtype data */
  2091. cu = (struct crat_subtype_computeunit *)sub_type_hdr;
  2092. cu->flags |= CRAT_CU_FLAGS_GPU_PRESENT;
  2093. cu->proximity_domain = proximity_domain;
  2094. cu->num_simd_per_cu = cu_info->simd_per_cu;
  2095. cu->num_simd_cores = cu_info->simd_per_cu *
  2096. (cu_info->number / kdev->kfd->num_nodes);
  2097. cu->max_waves_simd = cu_info->max_waves_per_simd;
  2098. cu->wave_front_size = cu_info->wave_front_size;
  2099. cu->array_count = gfx_info->max_sh_per_se *
  2100. gfx_info->max_shader_engines;
  2101. total_num_of_cu = (cu->array_count * gfx_info->max_cu_per_sh);
  2102. cu->processor_id_low = get_and_inc_gpu_processor_id(total_num_of_cu);
  2103. cu->num_cu_per_array = gfx_info->max_cu_per_sh;
  2104. cu->max_slots_scatch_cu = cu_info->max_scratch_slots_per_cu;
  2105. cu->num_banks = gfx_info->max_shader_engines;
  2106. cu->lds_size_in_kb = cu_info->lds_size;
  2107. cu->hsa_capability = 0;
  2108. crat_table->length += sub_type_hdr->length;
  2109. crat_table->total_entries++;
  2110. /* Fill in Subtype: Memory. Only on systems with large BAR (no
  2111. * private FB), report memory as public. On other systems
  2112. * report the total FB size (public+private) as a single
  2113. * private heap.
  2114. */
  2115. local_mem_info = kdev->local_mem_info;
  2116. sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
  2117. sub_type_hdr->length);
  2118. if (kdev->adev->debug_largebar)
  2119. local_mem_info.local_mem_size_private = 0;
  2120. if (local_mem_info.local_mem_size_private == 0)
  2121. ret = kfd_fill_gpu_memory_affinity(&avail_size,
  2122. kdev, HSA_MEM_HEAP_TYPE_FB_PUBLIC,
  2123. local_mem_info.local_mem_size_public,
  2124. (struct crat_subtype_memory *)sub_type_hdr,
  2125. proximity_domain,
  2126. &local_mem_info);
  2127. else
  2128. ret = kfd_fill_gpu_memory_affinity(&avail_size,
  2129. kdev, HSA_MEM_HEAP_TYPE_FB_PRIVATE,
  2130. local_mem_info.local_mem_size_public +
  2131. local_mem_info.local_mem_size_private,
  2132. (struct crat_subtype_memory *)sub_type_hdr,
  2133. proximity_domain,
  2134. &local_mem_info);
  2135. if (ret < 0)
  2136. return ret;
  2137. crat_table->length += sizeof(struct crat_subtype_memory);
  2138. crat_table->total_entries++;
  2139. /* Fill in Subtype: IO_LINKS
  2140. * Only direct links are added here which is Link from GPU to
  2141. * its NUMA node. Indirect links are added by userspace.
  2142. */
  2143. sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
  2144. sub_type_hdr->length);
  2145. ret = kfd_fill_gpu_direct_io_link_to_cpu(&avail_size, kdev,
  2146. (struct crat_subtype_iolink *)sub_type_hdr, proximity_domain);
  2147. if (ret < 0)
  2148. return ret;
  2149. crat_table->length += sub_type_hdr->length;
  2150. crat_table->total_entries++;
  2151. /* Fill in Subtype: IO_LINKS
  2152. * Direct links from GPU to other GPUs through xGMI.
  2153. * We will loop GPUs that already be processed (with lower value
  2154. * of proximity_domain), add the link for the GPUs with same
  2155. * hive id (from this GPU to other GPU) . The reversed iolink
  2156. * (from other GPU to this GPU) will be added
  2157. * in kfd_parse_subtype_iolink.
  2158. */
  2159. if (kdev->kfd->hive_id) {
  2160. for (nid = 0; nid < proximity_domain; ++nid) {
  2161. peer_dev = kfd_topology_device_by_proximity_domain_no_lock(nid);
  2162. if (!peer_dev->gpu)
  2163. continue;
  2164. if (peer_dev->gpu->kfd->hive_id != kdev->kfd->hive_id)
  2165. continue;
  2166. sub_type_hdr = (typeof(sub_type_hdr))(
  2167. (char *)sub_type_hdr +
  2168. sizeof(struct crat_subtype_iolink));
  2169. ret = kfd_fill_gpu_xgmi_link_to_gpu(
  2170. &avail_size, kdev, peer_dev->gpu,
  2171. (struct crat_subtype_iolink *)sub_type_hdr,
  2172. proximity_domain, nid);
  2173. if (ret < 0)
  2174. return ret;
  2175. crat_table->length += sub_type_hdr->length;
  2176. crat_table->total_entries++;
  2177. }
  2178. }
  2179. *size = crat_table->length;
  2180. pr_info("Virtual CRAT table created for GPU\n");
  2181. return ret;
  2182. }
  2183. /* kfd_create_crat_image_virtual - Allocates memory for CRAT image and
  2184. * creates a Virtual CRAT (VCRAT) image
  2185. *
  2186. * NOTE: Call kfd_destroy_crat_image to free CRAT image memory
  2187. *
  2188. * @crat_image: VCRAT image created because ACPI does not have a
  2189. * CRAT for this device
  2190. * @size: [OUT] size of virtual crat_image
  2191. * @flags: COMPUTE_UNIT_CPU - Create VCRAT for CPU device
  2192. * COMPUTE_UNIT_GPU - Create VCRAT for GPU
  2193. * (COMPUTE_UNIT_CPU | COMPUTE_UNIT_GPU) - Create VCRAT for APU
  2194. * -- this option is not currently implemented.
  2195. * The assumption is that all AMD APUs will have CRAT
  2196. * @kdev: Valid kfd_node required if flags contain COMPUTE_UNIT_GPU
  2197. *
  2198. * Return 0 if successful else return -ve value
  2199. */
  2200. int kfd_create_crat_image_virtual(void **crat_image, size_t *size,
  2201. int flags, struct kfd_node *kdev,
  2202. uint32_t proximity_domain)
  2203. {
  2204. void *pcrat_image = NULL;
  2205. int ret = 0, num_nodes;
  2206. size_t dyn_size;
  2207. if (!crat_image)
  2208. return -EINVAL;
  2209. *crat_image = NULL;
  2210. /* Allocate the CPU Virtual CRAT size based on the number of online
  2211. * nodes. Allocate VCRAT_SIZE_FOR_GPU for GPU virtual CRAT image.
  2212. * This should cover all the current conditions. A check is put not
  2213. * to overwrite beyond allocated size for GPUs
  2214. */
  2215. switch (flags) {
  2216. case COMPUTE_UNIT_CPU:
  2217. num_nodes = num_online_nodes();
  2218. dyn_size = sizeof(struct crat_header) +
  2219. num_nodes * (sizeof(struct crat_subtype_computeunit) +
  2220. sizeof(struct crat_subtype_memory) +
  2221. (num_nodes - 1) * sizeof(struct crat_subtype_iolink));
  2222. pcrat_image = kvmalloc(dyn_size, GFP_KERNEL);
  2223. if (!pcrat_image)
  2224. return -ENOMEM;
  2225. *size = dyn_size;
  2226. pr_debug("CRAT size is %ld", dyn_size);
  2227. ret = kfd_create_vcrat_image_cpu(pcrat_image, size);
  2228. break;
  2229. case COMPUTE_UNIT_GPU:
  2230. if (!kdev)
  2231. return -EINVAL;
  2232. pcrat_image = kvmalloc(VCRAT_SIZE_FOR_GPU, GFP_KERNEL);
  2233. if (!pcrat_image)
  2234. return -ENOMEM;
  2235. *size = VCRAT_SIZE_FOR_GPU;
  2236. ret = kfd_create_vcrat_image_gpu(pcrat_image, size, kdev,
  2237. proximity_domain);
  2238. break;
  2239. case (COMPUTE_UNIT_CPU | COMPUTE_UNIT_GPU):
  2240. /* TODO: */
  2241. ret = -EINVAL;
  2242. pr_err("VCRAT not implemented for APU\n");
  2243. break;
  2244. default:
  2245. ret = -EINVAL;
  2246. }
  2247. if (!ret)
  2248. *crat_image = pcrat_image;
  2249. else
  2250. kvfree(pcrat_image);
  2251. return ret;
  2252. }
  2253. /* kfd_destroy_crat_image
  2254. *
  2255. * @crat_image: [IN] - crat_image from kfd_create_crat_image_xxx(..)
  2256. *
  2257. */
  2258. void kfd_destroy_crat_image(void *crat_image)
  2259. {
  2260. kvfree(crat_image);
  2261. }