vi.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547
  1. /*
  2. * Copyright 2014 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. */
  23. #include <linux/firmware.h>
  24. #include <linux/slab.h>
  25. #include <linux/module.h>
  26. #include "drmP.h"
  27. #include "amdgpu.h"
  28. #include "amdgpu_atombios.h"
  29. #include "amdgpu_ih.h"
  30. #include "amdgpu_uvd.h"
  31. #include "amdgpu_vce.h"
  32. #include "amdgpu_ucode.h"
  33. #include "atom.h"
  34. #include "gmc/gmc_8_1_d.h"
  35. #include "gmc/gmc_8_1_sh_mask.h"
  36. #include "oss/oss_3_0_d.h"
  37. #include "oss/oss_3_0_sh_mask.h"
  38. #include "bif/bif_5_0_d.h"
  39. #include "bif/bif_5_0_sh_mask.h"
  40. #include "gca/gfx_8_0_d.h"
  41. #include "gca/gfx_8_0_sh_mask.h"
  42. #include "smu/smu_7_1_1_d.h"
  43. #include "smu/smu_7_1_1_sh_mask.h"
  44. #include "uvd/uvd_5_0_d.h"
  45. #include "uvd/uvd_5_0_sh_mask.h"
  46. #include "vce/vce_3_0_d.h"
  47. #include "vce/vce_3_0_sh_mask.h"
  48. #include "dce/dce_10_0_d.h"
  49. #include "dce/dce_10_0_sh_mask.h"
  50. #include "vid.h"
  51. #include "vi.h"
  52. #include "vi_dpm.h"
  53. #include "gmc_v8_0.h"
  54. #include "gmc_v7_0.h"
  55. #include "gfx_v8_0.h"
  56. #include "sdma_v2_4.h"
  57. #include "sdma_v3_0.h"
  58. #include "dce_v10_0.h"
  59. #include "dce_v11_0.h"
  60. #include "iceland_ih.h"
  61. #include "tonga_ih.h"
  62. #include "cz_ih.h"
  63. #include "uvd_v5_0.h"
  64. #include "uvd_v6_0.h"
  65. #include "vce_v3_0.h"
  66. /*
  67. * Indirect registers accessor
  68. */
  69. static u32 vi_pcie_rreg(struct amdgpu_device *adev, u32 reg)
  70. {
  71. unsigned long flags;
  72. u32 r;
  73. spin_lock_irqsave(&adev->pcie_idx_lock, flags);
  74. WREG32(mmPCIE_INDEX, reg);
  75. (void)RREG32(mmPCIE_INDEX);
  76. r = RREG32(mmPCIE_DATA);
  77. spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
  78. return r;
  79. }
  80. static void vi_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  81. {
  82. unsigned long flags;
  83. spin_lock_irqsave(&adev->pcie_idx_lock, flags);
  84. WREG32(mmPCIE_INDEX, reg);
  85. (void)RREG32(mmPCIE_INDEX);
  86. WREG32(mmPCIE_DATA, v);
  87. (void)RREG32(mmPCIE_DATA);
  88. spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
  89. }
  90. static u32 vi_smc_rreg(struct amdgpu_device *adev, u32 reg)
  91. {
  92. unsigned long flags;
  93. u32 r;
  94. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  95. WREG32(mmSMC_IND_INDEX_0, (reg));
  96. r = RREG32(mmSMC_IND_DATA_0);
  97. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  98. return r;
  99. }
  100. static void vi_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  101. {
  102. unsigned long flags;
  103. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  104. WREG32(mmSMC_IND_INDEX_0, (reg));
  105. WREG32(mmSMC_IND_DATA_0, (v));
  106. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  107. }
  108. /* smu_8_0_d.h */
  109. #define mmMP0PUB_IND_INDEX 0x180
  110. #define mmMP0PUB_IND_DATA 0x181
  111. static u32 cz_smc_rreg(struct amdgpu_device *adev, u32 reg)
  112. {
  113. unsigned long flags;
  114. u32 r;
  115. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  116. WREG32(mmMP0PUB_IND_INDEX, (reg));
  117. r = RREG32(mmMP0PUB_IND_DATA);
  118. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  119. return r;
  120. }
  121. static void cz_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  122. {
  123. unsigned long flags;
  124. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  125. WREG32(mmMP0PUB_IND_INDEX, (reg));
  126. WREG32(mmMP0PUB_IND_DATA, (v));
  127. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  128. }
  129. static u32 vi_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
  130. {
  131. unsigned long flags;
  132. u32 r;
  133. spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
  134. WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
  135. r = RREG32(mmUVD_CTX_DATA);
  136. spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
  137. return r;
  138. }
  139. static void vi_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  140. {
  141. unsigned long flags;
  142. spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
  143. WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
  144. WREG32(mmUVD_CTX_DATA, (v));
  145. spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
  146. }
  147. static u32 vi_didt_rreg(struct amdgpu_device *adev, u32 reg)
  148. {
  149. unsigned long flags;
  150. u32 r;
  151. spin_lock_irqsave(&adev->didt_idx_lock, flags);
  152. WREG32(mmDIDT_IND_INDEX, (reg));
  153. r = RREG32(mmDIDT_IND_DATA);
  154. spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
  155. return r;
  156. }
  157. static void vi_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  158. {
  159. unsigned long flags;
  160. spin_lock_irqsave(&adev->didt_idx_lock, flags);
  161. WREG32(mmDIDT_IND_INDEX, (reg));
  162. WREG32(mmDIDT_IND_DATA, (v));
  163. spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
  164. }
  165. static const u32 tonga_mgcg_cgcg_init[] =
  166. {
  167. mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
  168. mmPCIE_INDEX, 0xffffffff, 0x0140001c,
  169. mmPCIE_DATA, 0x000f0000, 0x00000000,
  170. mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
  171. mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
  172. mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
  173. mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
  174. };
  175. static const u32 fiji_mgcg_cgcg_init[] =
  176. {
  177. mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
  178. mmPCIE_INDEX, 0xffffffff, 0x0140001c,
  179. mmPCIE_DATA, 0x000f0000, 0x00000000,
  180. mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
  181. mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
  182. mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
  183. mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
  184. };
  185. static const u32 iceland_mgcg_cgcg_init[] =
  186. {
  187. mmPCIE_INDEX, 0xffffffff, ixPCIE_CNTL2,
  188. mmPCIE_DATA, 0x000f0000, 0x00000000,
  189. mmSMC_IND_INDEX_4, 0xffffffff, ixCGTT_ROM_CLK_CTRL0,
  190. mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
  191. mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
  192. };
  193. static const u32 cz_mgcg_cgcg_init[] =
  194. {
  195. mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
  196. mmPCIE_INDEX, 0xffffffff, 0x0140001c,
  197. mmPCIE_DATA, 0x000f0000, 0x00000000,
  198. mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
  199. mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
  200. };
  201. static const u32 stoney_mgcg_cgcg_init[] =
  202. {
  203. mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00000100,
  204. mmHDP_XDP_CGTT_BLK_CTRL, 0xffffffff, 0x00000104,
  205. mmHDP_HOST_PATH_CNTL, 0xffffffff, 0x0f000027,
  206. };
  207. static void vi_init_golden_registers(struct amdgpu_device *adev)
  208. {
  209. /* Some of the registers might be dependent on GRBM_GFX_INDEX */
  210. mutex_lock(&adev->grbm_idx_mutex);
  211. switch (adev->asic_type) {
  212. case CHIP_TOPAZ:
  213. amdgpu_program_register_sequence(adev,
  214. iceland_mgcg_cgcg_init,
  215. (const u32)ARRAY_SIZE(iceland_mgcg_cgcg_init));
  216. break;
  217. case CHIP_FIJI:
  218. amdgpu_program_register_sequence(adev,
  219. fiji_mgcg_cgcg_init,
  220. (const u32)ARRAY_SIZE(fiji_mgcg_cgcg_init));
  221. break;
  222. case CHIP_TONGA:
  223. amdgpu_program_register_sequence(adev,
  224. tonga_mgcg_cgcg_init,
  225. (const u32)ARRAY_SIZE(tonga_mgcg_cgcg_init));
  226. break;
  227. case CHIP_CARRIZO:
  228. amdgpu_program_register_sequence(adev,
  229. cz_mgcg_cgcg_init,
  230. (const u32)ARRAY_SIZE(cz_mgcg_cgcg_init));
  231. break;
  232. case CHIP_STONEY:
  233. amdgpu_program_register_sequence(adev,
  234. stoney_mgcg_cgcg_init,
  235. (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init));
  236. break;
  237. default:
  238. break;
  239. }
  240. mutex_unlock(&adev->grbm_idx_mutex);
  241. }
  242. /**
  243. * vi_get_xclk - get the xclk
  244. *
  245. * @adev: amdgpu_device pointer
  246. *
  247. * Returns the reference clock used by the gfx engine
  248. * (VI).
  249. */
  250. static u32 vi_get_xclk(struct amdgpu_device *adev)
  251. {
  252. u32 reference_clock = adev->clock.spll.reference_freq;
  253. u32 tmp;
  254. if (adev->flags & AMD_IS_APU)
  255. return reference_clock;
  256. tmp = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
  257. if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK))
  258. return 1000;
  259. tmp = RREG32_SMC(ixCG_CLKPIN_CNTL);
  260. if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL, XTALIN_DIVIDE))
  261. return reference_clock / 4;
  262. return reference_clock;
  263. }
  264. /**
  265. * vi_srbm_select - select specific register instances
  266. *
  267. * @adev: amdgpu_device pointer
  268. * @me: selected ME (micro engine)
  269. * @pipe: pipe
  270. * @queue: queue
  271. * @vmid: VMID
  272. *
  273. * Switches the currently active registers instances. Some
  274. * registers are instanced per VMID, others are instanced per
  275. * me/pipe/queue combination.
  276. */
  277. void vi_srbm_select(struct amdgpu_device *adev,
  278. u32 me, u32 pipe, u32 queue, u32 vmid)
  279. {
  280. u32 srbm_gfx_cntl = 0;
  281. srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, PIPEID, pipe);
  282. srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, MEID, me);
  283. srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, VMID, vmid);
  284. srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, QUEUEID, queue);
  285. WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
  286. }
  287. static void vi_vga_set_state(struct amdgpu_device *adev, bool state)
  288. {
  289. /* todo */
  290. }
  291. static bool vi_read_disabled_bios(struct amdgpu_device *adev)
  292. {
  293. u32 bus_cntl;
  294. u32 d1vga_control = 0;
  295. u32 d2vga_control = 0;
  296. u32 vga_render_control = 0;
  297. u32 rom_cntl;
  298. bool r;
  299. bus_cntl = RREG32(mmBUS_CNTL);
  300. if (adev->mode_info.num_crtc) {
  301. d1vga_control = RREG32(mmD1VGA_CONTROL);
  302. d2vga_control = RREG32(mmD2VGA_CONTROL);
  303. vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
  304. }
  305. rom_cntl = RREG32_SMC(ixROM_CNTL);
  306. /* enable the rom */
  307. WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
  308. if (adev->mode_info.num_crtc) {
  309. /* Disable VGA mode */
  310. WREG32(mmD1VGA_CONTROL,
  311. (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
  312. D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
  313. WREG32(mmD2VGA_CONTROL,
  314. (d2vga_control & ~(D2VGA_CONTROL__D2VGA_MODE_ENABLE_MASK |
  315. D2VGA_CONTROL__D2VGA_TIMING_SELECT_MASK)));
  316. WREG32(mmVGA_RENDER_CONTROL,
  317. (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
  318. }
  319. WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
  320. r = amdgpu_read_bios(adev);
  321. /* restore regs */
  322. WREG32(mmBUS_CNTL, bus_cntl);
  323. if (adev->mode_info.num_crtc) {
  324. WREG32(mmD1VGA_CONTROL, d1vga_control);
  325. WREG32(mmD2VGA_CONTROL, d2vga_control);
  326. WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
  327. }
  328. WREG32_SMC(ixROM_CNTL, rom_cntl);
  329. return r;
  330. }
  331. static struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = {
  332. {mmGB_MACROTILE_MODE7, true},
  333. };
  334. static struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = {
  335. {mmGB_TILE_MODE7, true},
  336. {mmGB_TILE_MODE12, true},
  337. {mmGB_TILE_MODE17, true},
  338. {mmGB_TILE_MODE23, true},
  339. {mmGB_MACROTILE_MODE7, true},
  340. };
  341. static struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
  342. {mmGRBM_STATUS, false},
  343. {mmGRBM_STATUS2, false},
  344. {mmGRBM_STATUS_SE0, false},
  345. {mmGRBM_STATUS_SE1, false},
  346. {mmGRBM_STATUS_SE2, false},
  347. {mmGRBM_STATUS_SE3, false},
  348. {mmSRBM_STATUS, false},
  349. {mmSRBM_STATUS2, false},
  350. {mmSRBM_STATUS3, false},
  351. {mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET, false},
  352. {mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET, false},
  353. {mmCP_STAT, false},
  354. {mmCP_STALLED_STAT1, false},
  355. {mmCP_STALLED_STAT2, false},
  356. {mmCP_STALLED_STAT3, false},
  357. {mmCP_CPF_BUSY_STAT, false},
  358. {mmCP_CPF_STALLED_STAT1, false},
  359. {mmCP_CPF_STATUS, false},
  360. {mmCP_CPC_BUSY_STAT, false},
  361. {mmCP_CPC_STALLED_STAT1, false},
  362. {mmCP_CPC_STATUS, false},
  363. {mmGB_ADDR_CONFIG, false},
  364. {mmMC_ARB_RAMCFG, false},
  365. {mmGB_TILE_MODE0, false},
  366. {mmGB_TILE_MODE1, false},
  367. {mmGB_TILE_MODE2, false},
  368. {mmGB_TILE_MODE3, false},
  369. {mmGB_TILE_MODE4, false},
  370. {mmGB_TILE_MODE5, false},
  371. {mmGB_TILE_MODE6, false},
  372. {mmGB_TILE_MODE7, false},
  373. {mmGB_TILE_MODE8, false},
  374. {mmGB_TILE_MODE9, false},
  375. {mmGB_TILE_MODE10, false},
  376. {mmGB_TILE_MODE11, false},
  377. {mmGB_TILE_MODE12, false},
  378. {mmGB_TILE_MODE13, false},
  379. {mmGB_TILE_MODE14, false},
  380. {mmGB_TILE_MODE15, false},
  381. {mmGB_TILE_MODE16, false},
  382. {mmGB_TILE_MODE17, false},
  383. {mmGB_TILE_MODE18, false},
  384. {mmGB_TILE_MODE19, false},
  385. {mmGB_TILE_MODE20, false},
  386. {mmGB_TILE_MODE21, false},
  387. {mmGB_TILE_MODE22, false},
  388. {mmGB_TILE_MODE23, false},
  389. {mmGB_TILE_MODE24, false},
  390. {mmGB_TILE_MODE25, false},
  391. {mmGB_TILE_MODE26, false},
  392. {mmGB_TILE_MODE27, false},
  393. {mmGB_TILE_MODE28, false},
  394. {mmGB_TILE_MODE29, false},
  395. {mmGB_TILE_MODE30, false},
  396. {mmGB_TILE_MODE31, false},
  397. {mmGB_MACROTILE_MODE0, false},
  398. {mmGB_MACROTILE_MODE1, false},
  399. {mmGB_MACROTILE_MODE2, false},
  400. {mmGB_MACROTILE_MODE3, false},
  401. {mmGB_MACROTILE_MODE4, false},
  402. {mmGB_MACROTILE_MODE5, false},
  403. {mmGB_MACROTILE_MODE6, false},
  404. {mmGB_MACROTILE_MODE7, false},
  405. {mmGB_MACROTILE_MODE8, false},
  406. {mmGB_MACROTILE_MODE9, false},
  407. {mmGB_MACROTILE_MODE10, false},
  408. {mmGB_MACROTILE_MODE11, false},
  409. {mmGB_MACROTILE_MODE12, false},
  410. {mmGB_MACROTILE_MODE13, false},
  411. {mmGB_MACROTILE_MODE14, false},
  412. {mmGB_MACROTILE_MODE15, false},
  413. {mmCC_RB_BACKEND_DISABLE, false, true},
  414. {mmGC_USER_RB_BACKEND_DISABLE, false, true},
  415. {mmGB_BACKEND_MAP, false, false},
  416. {mmPA_SC_RASTER_CONFIG, false, true},
  417. {mmPA_SC_RASTER_CONFIG_1, false, true},
  418. };
  419. static uint32_t vi_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
  420. u32 sh_num, u32 reg_offset)
  421. {
  422. uint32_t val;
  423. mutex_lock(&adev->grbm_idx_mutex);
  424. if (se_num != 0xffffffff || sh_num != 0xffffffff)
  425. gfx_v8_0_select_se_sh(adev, se_num, sh_num);
  426. val = RREG32(reg_offset);
  427. if (se_num != 0xffffffff || sh_num != 0xffffffff)
  428. gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff);
  429. mutex_unlock(&adev->grbm_idx_mutex);
  430. return val;
  431. }
  432. static int vi_read_register(struct amdgpu_device *adev, u32 se_num,
  433. u32 sh_num, u32 reg_offset, u32 *value)
  434. {
  435. struct amdgpu_allowed_register_entry *asic_register_table = NULL;
  436. struct amdgpu_allowed_register_entry *asic_register_entry;
  437. uint32_t size, i;
  438. *value = 0;
  439. switch (adev->asic_type) {
  440. case CHIP_TOPAZ:
  441. asic_register_table = tonga_allowed_read_registers;
  442. size = ARRAY_SIZE(tonga_allowed_read_registers);
  443. break;
  444. case CHIP_FIJI:
  445. case CHIP_TONGA:
  446. case CHIP_CARRIZO:
  447. case CHIP_STONEY:
  448. asic_register_table = cz_allowed_read_registers;
  449. size = ARRAY_SIZE(cz_allowed_read_registers);
  450. break;
  451. default:
  452. return -EINVAL;
  453. }
  454. if (asic_register_table) {
  455. for (i = 0; i < size; i++) {
  456. asic_register_entry = asic_register_table + i;
  457. if (reg_offset != asic_register_entry->reg_offset)
  458. continue;
  459. if (!asic_register_entry->untouched)
  460. *value = asic_register_entry->grbm_indexed ?
  461. vi_read_indexed_register(adev, se_num,
  462. sh_num, reg_offset) :
  463. RREG32(reg_offset);
  464. return 0;
  465. }
  466. }
  467. for (i = 0; i < ARRAY_SIZE(vi_allowed_read_registers); i++) {
  468. if (reg_offset != vi_allowed_read_registers[i].reg_offset)
  469. continue;
  470. if (!vi_allowed_read_registers[i].untouched)
  471. *value = vi_allowed_read_registers[i].grbm_indexed ?
  472. vi_read_indexed_register(adev, se_num,
  473. sh_num, reg_offset) :
  474. RREG32(reg_offset);
  475. return 0;
  476. }
  477. return -EINVAL;
  478. }
  479. static void vi_print_gpu_status_regs(struct amdgpu_device *adev)
  480. {
  481. dev_info(adev->dev, " GRBM_STATUS=0x%08X\n",
  482. RREG32(mmGRBM_STATUS));
  483. dev_info(adev->dev, " GRBM_STATUS2=0x%08X\n",
  484. RREG32(mmGRBM_STATUS2));
  485. dev_info(adev->dev, " GRBM_STATUS_SE0=0x%08X\n",
  486. RREG32(mmGRBM_STATUS_SE0));
  487. dev_info(adev->dev, " GRBM_STATUS_SE1=0x%08X\n",
  488. RREG32(mmGRBM_STATUS_SE1));
  489. dev_info(adev->dev, " GRBM_STATUS_SE2=0x%08X\n",
  490. RREG32(mmGRBM_STATUS_SE2));
  491. dev_info(adev->dev, " GRBM_STATUS_SE3=0x%08X\n",
  492. RREG32(mmGRBM_STATUS_SE3));
  493. dev_info(adev->dev, " SRBM_STATUS=0x%08X\n",
  494. RREG32(mmSRBM_STATUS));
  495. dev_info(adev->dev, " SRBM_STATUS2=0x%08X\n",
  496. RREG32(mmSRBM_STATUS2));
  497. dev_info(adev->dev, " SDMA0_STATUS_REG = 0x%08X\n",
  498. RREG32(mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET));
  499. if (adev->sdma.num_instances > 1) {
  500. dev_info(adev->dev, " SDMA1_STATUS_REG = 0x%08X\n",
  501. RREG32(mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET));
  502. }
  503. dev_info(adev->dev, " CP_STAT = 0x%08x\n", RREG32(mmCP_STAT));
  504. dev_info(adev->dev, " CP_STALLED_STAT1 = 0x%08x\n",
  505. RREG32(mmCP_STALLED_STAT1));
  506. dev_info(adev->dev, " CP_STALLED_STAT2 = 0x%08x\n",
  507. RREG32(mmCP_STALLED_STAT2));
  508. dev_info(adev->dev, " CP_STALLED_STAT3 = 0x%08x\n",
  509. RREG32(mmCP_STALLED_STAT3));
  510. dev_info(adev->dev, " CP_CPF_BUSY_STAT = 0x%08x\n",
  511. RREG32(mmCP_CPF_BUSY_STAT));
  512. dev_info(adev->dev, " CP_CPF_STALLED_STAT1 = 0x%08x\n",
  513. RREG32(mmCP_CPF_STALLED_STAT1));
  514. dev_info(adev->dev, " CP_CPF_STATUS = 0x%08x\n", RREG32(mmCP_CPF_STATUS));
  515. dev_info(adev->dev, " CP_CPC_BUSY_STAT = 0x%08x\n", RREG32(mmCP_CPC_BUSY_STAT));
  516. dev_info(adev->dev, " CP_CPC_STALLED_STAT1 = 0x%08x\n",
  517. RREG32(mmCP_CPC_STALLED_STAT1));
  518. dev_info(adev->dev, " CP_CPC_STATUS = 0x%08x\n", RREG32(mmCP_CPC_STATUS));
  519. }
  520. /**
  521. * vi_gpu_check_soft_reset - check which blocks are busy
  522. *
  523. * @adev: amdgpu_device pointer
  524. *
  525. * Check which blocks are busy and return the relevant reset
  526. * mask to be used by vi_gpu_soft_reset().
  527. * Returns a mask of the blocks to be reset.
  528. */
  529. u32 vi_gpu_check_soft_reset(struct amdgpu_device *adev)
  530. {
  531. u32 reset_mask = 0;
  532. u32 tmp;
  533. /* GRBM_STATUS */
  534. tmp = RREG32(mmGRBM_STATUS);
  535. if (tmp & (GRBM_STATUS__PA_BUSY_MASK | GRBM_STATUS__SC_BUSY_MASK |
  536. GRBM_STATUS__BCI_BUSY_MASK | GRBM_STATUS__SX_BUSY_MASK |
  537. GRBM_STATUS__TA_BUSY_MASK | GRBM_STATUS__VGT_BUSY_MASK |
  538. GRBM_STATUS__DB_BUSY_MASK | GRBM_STATUS__CB_BUSY_MASK |
  539. GRBM_STATUS__GDS_BUSY_MASK | GRBM_STATUS__SPI_BUSY_MASK |
  540. GRBM_STATUS__IA_BUSY_MASK | GRBM_STATUS__IA_BUSY_NO_DMA_MASK))
  541. reset_mask |= AMDGPU_RESET_GFX;
  542. if (tmp & (GRBM_STATUS__CP_BUSY_MASK | GRBM_STATUS__CP_COHERENCY_BUSY_MASK))
  543. reset_mask |= AMDGPU_RESET_CP;
  544. /* GRBM_STATUS2 */
  545. tmp = RREG32(mmGRBM_STATUS2);
  546. if (tmp & GRBM_STATUS2__RLC_BUSY_MASK)
  547. reset_mask |= AMDGPU_RESET_RLC;
  548. if (tmp & (GRBM_STATUS2__CPF_BUSY_MASK |
  549. GRBM_STATUS2__CPC_BUSY_MASK |
  550. GRBM_STATUS2__CPG_BUSY_MASK))
  551. reset_mask |= AMDGPU_RESET_CP;
  552. /* SRBM_STATUS2 */
  553. tmp = RREG32(mmSRBM_STATUS2);
  554. if (tmp & SRBM_STATUS2__SDMA_BUSY_MASK)
  555. reset_mask |= AMDGPU_RESET_DMA;
  556. if (tmp & SRBM_STATUS2__SDMA1_BUSY_MASK)
  557. reset_mask |= AMDGPU_RESET_DMA1;
  558. /* SRBM_STATUS */
  559. tmp = RREG32(mmSRBM_STATUS);
  560. if (tmp & SRBM_STATUS__IH_BUSY_MASK)
  561. reset_mask |= AMDGPU_RESET_IH;
  562. if (tmp & SRBM_STATUS__SEM_BUSY_MASK)
  563. reset_mask |= AMDGPU_RESET_SEM;
  564. if (tmp & SRBM_STATUS__GRBM_RQ_PENDING_MASK)
  565. reset_mask |= AMDGPU_RESET_GRBM;
  566. if (adev->asic_type != CHIP_TOPAZ) {
  567. if (tmp & (SRBM_STATUS__UVD_RQ_PENDING_MASK |
  568. SRBM_STATUS__UVD_BUSY_MASK))
  569. reset_mask |= AMDGPU_RESET_UVD;
  570. }
  571. if (tmp & SRBM_STATUS__VMC_BUSY_MASK)
  572. reset_mask |= AMDGPU_RESET_VMC;
  573. if (tmp & (SRBM_STATUS__MCB_BUSY_MASK | SRBM_STATUS__MCB_NON_DISPLAY_BUSY_MASK |
  574. SRBM_STATUS__MCC_BUSY_MASK | SRBM_STATUS__MCD_BUSY_MASK))
  575. reset_mask |= AMDGPU_RESET_MC;
  576. /* SDMA0_STATUS_REG */
  577. tmp = RREG32(mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET);
  578. if (!(tmp & SDMA0_STATUS_REG__IDLE_MASK))
  579. reset_mask |= AMDGPU_RESET_DMA;
  580. /* SDMA1_STATUS_REG */
  581. if (adev->sdma.num_instances > 1) {
  582. tmp = RREG32(mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET);
  583. if (!(tmp & SDMA0_STATUS_REG__IDLE_MASK))
  584. reset_mask |= AMDGPU_RESET_DMA1;
  585. }
  586. #if 0
  587. /* VCE_STATUS */
  588. if (adev->asic_type != CHIP_TOPAZ) {
  589. tmp = RREG32(mmVCE_STATUS);
  590. if (tmp & VCE_STATUS__VCPU_REPORT_RB0_BUSY_MASK)
  591. reset_mask |= AMDGPU_RESET_VCE;
  592. if (tmp & VCE_STATUS__VCPU_REPORT_RB1_BUSY_MASK)
  593. reset_mask |= AMDGPU_RESET_VCE1;
  594. }
  595. if (adev->asic_type != CHIP_TOPAZ) {
  596. if (amdgpu_display_is_display_hung(adev))
  597. reset_mask |= AMDGPU_RESET_DISPLAY;
  598. }
  599. #endif
  600. /* Skip MC reset as it's mostly likely not hung, just busy */
  601. if (reset_mask & AMDGPU_RESET_MC) {
  602. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  603. reset_mask &= ~AMDGPU_RESET_MC;
  604. }
  605. return reset_mask;
  606. }
  607. /**
  608. * vi_gpu_soft_reset - soft reset GPU
  609. *
  610. * @adev: amdgpu_device pointer
  611. * @reset_mask: mask of which blocks to reset
  612. *
  613. * Soft reset the blocks specified in @reset_mask.
  614. */
  615. static void vi_gpu_soft_reset(struct amdgpu_device *adev, u32 reset_mask)
  616. {
  617. struct amdgpu_mode_mc_save save;
  618. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  619. u32 tmp;
  620. if (reset_mask == 0)
  621. return;
  622. dev_info(adev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  623. vi_print_gpu_status_regs(adev);
  624. dev_info(adev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  625. RREG32(mmVM_CONTEXT1_PROTECTION_FAULT_ADDR));
  626. dev_info(adev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  627. RREG32(mmVM_CONTEXT1_PROTECTION_FAULT_STATUS));
  628. /* disable CG/PG */
  629. /* stop the rlc */
  630. //XXX
  631. //gfx_v8_0_rlc_stop(adev);
  632. /* Disable GFX parsing/prefetching */
  633. tmp = RREG32(mmCP_ME_CNTL);
  634. tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, ME_HALT, 1);
  635. tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, PFP_HALT, 1);
  636. tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, 1);
  637. WREG32(mmCP_ME_CNTL, tmp);
  638. /* Disable MEC parsing/prefetching */
  639. tmp = RREG32(mmCP_MEC_CNTL);
  640. tmp = REG_SET_FIELD(tmp, CP_MEC_CNTL, MEC_ME1_HALT, 1);
  641. tmp = REG_SET_FIELD(tmp, CP_MEC_CNTL, MEC_ME2_HALT, 1);
  642. WREG32(mmCP_MEC_CNTL, tmp);
  643. if (reset_mask & AMDGPU_RESET_DMA) {
  644. /* sdma0 */
  645. tmp = RREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET);
  646. tmp = REG_SET_FIELD(tmp, SDMA0_F32_CNTL, HALT, 1);
  647. WREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET, tmp);
  648. }
  649. if (reset_mask & AMDGPU_RESET_DMA1) {
  650. /* sdma1 */
  651. tmp = RREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET);
  652. tmp = REG_SET_FIELD(tmp, SDMA0_F32_CNTL, HALT, 1);
  653. WREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET, tmp);
  654. }
  655. gmc_v8_0_mc_stop(adev, &save);
  656. if (amdgpu_asic_wait_for_mc_idle(adev)) {
  657. dev_warn(adev->dev, "Wait for MC idle timedout !\n");
  658. }
  659. if (reset_mask & (AMDGPU_RESET_GFX | AMDGPU_RESET_COMPUTE | AMDGPU_RESET_CP)) {
  660. grbm_soft_reset =
  661. REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP, 1);
  662. grbm_soft_reset =
  663. REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_GFX, 1);
  664. }
  665. if (reset_mask & AMDGPU_RESET_CP) {
  666. grbm_soft_reset =
  667. REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP, 1);
  668. srbm_soft_reset =
  669. REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
  670. }
  671. if (reset_mask & AMDGPU_RESET_DMA)
  672. srbm_soft_reset =
  673. REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_SDMA, 1);
  674. if (reset_mask & AMDGPU_RESET_DMA1)
  675. srbm_soft_reset =
  676. REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_SDMA1, 1);
  677. if (reset_mask & AMDGPU_RESET_DISPLAY)
  678. srbm_soft_reset =
  679. REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_DC, 1);
  680. if (reset_mask & AMDGPU_RESET_RLC)
  681. grbm_soft_reset =
  682. REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
  683. if (reset_mask & AMDGPU_RESET_SEM)
  684. srbm_soft_reset =
  685. REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_SEM, 1);
  686. if (reset_mask & AMDGPU_RESET_IH)
  687. srbm_soft_reset =
  688. REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_IH, 1);
  689. if (reset_mask & AMDGPU_RESET_GRBM)
  690. srbm_soft_reset =
  691. REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
  692. if (reset_mask & AMDGPU_RESET_VMC)
  693. srbm_soft_reset =
  694. REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VMC, 1);
  695. if (reset_mask & AMDGPU_RESET_UVD)
  696. srbm_soft_reset =
  697. REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_UVD, 1);
  698. if (reset_mask & AMDGPU_RESET_VCE)
  699. srbm_soft_reset =
  700. REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VCE0, 1);
  701. if (reset_mask & AMDGPU_RESET_VCE)
  702. srbm_soft_reset =
  703. REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VCE1, 1);
  704. if (!(adev->flags & AMD_IS_APU)) {
  705. if (reset_mask & AMDGPU_RESET_MC)
  706. srbm_soft_reset =
  707. REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_MC, 1);
  708. }
  709. if (grbm_soft_reset) {
  710. tmp = RREG32(mmGRBM_SOFT_RESET);
  711. tmp |= grbm_soft_reset;
  712. dev_info(adev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  713. WREG32(mmGRBM_SOFT_RESET, tmp);
  714. tmp = RREG32(mmGRBM_SOFT_RESET);
  715. udelay(50);
  716. tmp &= ~grbm_soft_reset;
  717. WREG32(mmGRBM_SOFT_RESET, tmp);
  718. tmp = RREG32(mmGRBM_SOFT_RESET);
  719. }
  720. if (srbm_soft_reset) {
  721. tmp = RREG32(mmSRBM_SOFT_RESET);
  722. tmp |= srbm_soft_reset;
  723. dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  724. WREG32(mmSRBM_SOFT_RESET, tmp);
  725. tmp = RREG32(mmSRBM_SOFT_RESET);
  726. udelay(50);
  727. tmp &= ~srbm_soft_reset;
  728. WREG32(mmSRBM_SOFT_RESET, tmp);
  729. tmp = RREG32(mmSRBM_SOFT_RESET);
  730. }
  731. /* Wait a little for things to settle down */
  732. udelay(50);
  733. gmc_v8_0_mc_resume(adev, &save);
  734. udelay(50);
  735. vi_print_gpu_status_regs(adev);
  736. }
  737. static void vi_gpu_pci_config_reset(struct amdgpu_device *adev)
  738. {
  739. struct amdgpu_mode_mc_save save;
  740. u32 tmp, i;
  741. dev_info(adev->dev, "GPU pci config reset\n");
  742. /* disable dpm? */
  743. /* disable cg/pg */
  744. /* Disable GFX parsing/prefetching */
  745. tmp = RREG32(mmCP_ME_CNTL);
  746. tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, ME_HALT, 1);
  747. tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, PFP_HALT, 1);
  748. tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, 1);
  749. WREG32(mmCP_ME_CNTL, tmp);
  750. /* Disable MEC parsing/prefetching */
  751. tmp = RREG32(mmCP_MEC_CNTL);
  752. tmp = REG_SET_FIELD(tmp, CP_MEC_CNTL, MEC_ME1_HALT, 1);
  753. tmp = REG_SET_FIELD(tmp, CP_MEC_CNTL, MEC_ME2_HALT, 1);
  754. WREG32(mmCP_MEC_CNTL, tmp);
  755. /* Disable GFX parsing/prefetching */
  756. WREG32(mmCP_ME_CNTL, CP_ME_CNTL__ME_HALT_MASK |
  757. CP_ME_CNTL__PFP_HALT_MASK | CP_ME_CNTL__CE_HALT_MASK);
  758. /* Disable MEC parsing/prefetching */
  759. WREG32(mmCP_MEC_CNTL,
  760. CP_MEC_CNTL__MEC_ME1_HALT_MASK | CP_MEC_CNTL__MEC_ME2_HALT_MASK);
  761. /* sdma0 */
  762. tmp = RREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET);
  763. tmp = REG_SET_FIELD(tmp, SDMA0_F32_CNTL, HALT, 1);
  764. WREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET, tmp);
  765. /* sdma1 */
  766. tmp = RREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET);
  767. tmp = REG_SET_FIELD(tmp, SDMA0_F32_CNTL, HALT, 1);
  768. WREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET, tmp);
  769. /* XXX other engines? */
  770. /* halt the rlc, disable cp internal ints */
  771. //XXX
  772. //gfx_v8_0_rlc_stop(adev);
  773. udelay(50);
  774. /* disable mem access */
  775. gmc_v8_0_mc_stop(adev, &save);
  776. if (amdgpu_asic_wait_for_mc_idle(adev)) {
  777. dev_warn(adev->dev, "Wait for MC idle timed out !\n");
  778. }
  779. /* disable BM */
  780. pci_clear_master(adev->pdev);
  781. /* reset */
  782. amdgpu_pci_config_reset(adev);
  783. udelay(100);
  784. /* wait for asic to come out of reset */
  785. for (i = 0; i < adev->usec_timeout; i++) {
  786. if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff)
  787. break;
  788. udelay(1);
  789. }
  790. }
  791. static void vi_set_bios_scratch_engine_hung(struct amdgpu_device *adev, bool hung)
  792. {
  793. u32 tmp = RREG32(mmBIOS_SCRATCH_3);
  794. if (hung)
  795. tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
  796. else
  797. tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
  798. WREG32(mmBIOS_SCRATCH_3, tmp);
  799. }
  800. /**
  801. * vi_asic_reset - soft reset GPU
  802. *
  803. * @adev: amdgpu_device pointer
  804. *
  805. * Look up which blocks are hung and attempt
  806. * to reset them.
  807. * Returns 0 for success.
  808. */
  809. static int vi_asic_reset(struct amdgpu_device *adev)
  810. {
  811. u32 reset_mask;
  812. reset_mask = vi_gpu_check_soft_reset(adev);
  813. if (reset_mask)
  814. vi_set_bios_scratch_engine_hung(adev, true);
  815. /* try soft reset */
  816. vi_gpu_soft_reset(adev, reset_mask);
  817. reset_mask = vi_gpu_check_soft_reset(adev);
  818. /* try pci config reset */
  819. if (reset_mask && amdgpu_hard_reset)
  820. vi_gpu_pci_config_reset(adev);
  821. reset_mask = vi_gpu_check_soft_reset(adev);
  822. if (!reset_mask)
  823. vi_set_bios_scratch_engine_hung(adev, false);
  824. return 0;
  825. }
  826. static int vi_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
  827. u32 cntl_reg, u32 status_reg)
  828. {
  829. int r, i;
  830. struct atom_clock_dividers dividers;
  831. uint32_t tmp;
  832. r = amdgpu_atombios_get_clock_dividers(adev,
  833. COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
  834. clock, false, &dividers);
  835. if (r)
  836. return r;
  837. tmp = RREG32_SMC(cntl_reg);
  838. tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
  839. CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
  840. tmp |= dividers.post_divider;
  841. WREG32_SMC(cntl_reg, tmp);
  842. for (i = 0; i < 100; i++) {
  843. if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
  844. break;
  845. mdelay(10);
  846. }
  847. if (i == 100)
  848. return -ETIMEDOUT;
  849. return 0;
  850. }
  851. static int vi_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
  852. {
  853. int r;
  854. r = vi_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
  855. if (r)
  856. return r;
  857. r = vi_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
  858. return 0;
  859. }
  860. static int vi_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
  861. {
  862. /* todo */
  863. return 0;
  864. }
  865. static void vi_pcie_gen3_enable(struct amdgpu_device *adev)
  866. {
  867. u32 mask;
  868. int ret;
  869. if (pci_is_root_bus(adev->pdev->bus))
  870. return;
  871. if (amdgpu_pcie_gen2 == 0)
  872. return;
  873. if (adev->flags & AMD_IS_APU)
  874. return;
  875. ret = drm_pcie_get_speed_cap_mask(adev->ddev, &mask);
  876. if (ret != 0)
  877. return;
  878. if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
  879. return;
  880. /* todo */
  881. }
  882. static void vi_program_aspm(struct amdgpu_device *adev)
  883. {
  884. if (amdgpu_aspm == 0)
  885. return;
  886. /* todo */
  887. }
  888. static void vi_enable_doorbell_aperture(struct amdgpu_device *adev,
  889. bool enable)
  890. {
  891. u32 tmp;
  892. /* not necessary on CZ */
  893. if (adev->flags & AMD_IS_APU)
  894. return;
  895. tmp = RREG32(mmBIF_DOORBELL_APER_EN);
  896. if (enable)
  897. tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 1);
  898. else
  899. tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 0);
  900. WREG32(mmBIF_DOORBELL_APER_EN, tmp);
  901. }
  902. /* topaz has no DCE, UVD, VCE */
  903. static const struct amdgpu_ip_block_version topaz_ip_blocks[] =
  904. {
  905. /* ORDER MATTERS! */
  906. {
  907. .type = AMD_IP_BLOCK_TYPE_COMMON,
  908. .major = 2,
  909. .minor = 0,
  910. .rev = 0,
  911. .funcs = &vi_common_ip_funcs,
  912. },
  913. {
  914. .type = AMD_IP_BLOCK_TYPE_GMC,
  915. .major = 7,
  916. .minor = 4,
  917. .rev = 0,
  918. .funcs = &gmc_v7_0_ip_funcs,
  919. },
  920. {
  921. .type = AMD_IP_BLOCK_TYPE_IH,
  922. .major = 2,
  923. .minor = 4,
  924. .rev = 0,
  925. .funcs = &iceland_ih_ip_funcs,
  926. },
  927. {
  928. .type = AMD_IP_BLOCK_TYPE_SMC,
  929. .major = 7,
  930. .minor = 1,
  931. .rev = 0,
  932. .funcs = &iceland_dpm_ip_funcs,
  933. },
  934. {
  935. .type = AMD_IP_BLOCK_TYPE_GFX,
  936. .major = 8,
  937. .minor = 0,
  938. .rev = 0,
  939. .funcs = &gfx_v8_0_ip_funcs,
  940. },
  941. {
  942. .type = AMD_IP_BLOCK_TYPE_SDMA,
  943. .major = 2,
  944. .minor = 4,
  945. .rev = 0,
  946. .funcs = &sdma_v2_4_ip_funcs,
  947. },
  948. };
  949. static const struct amdgpu_ip_block_version tonga_ip_blocks[] =
  950. {
  951. /* ORDER MATTERS! */
  952. {
  953. .type = AMD_IP_BLOCK_TYPE_COMMON,
  954. .major = 2,
  955. .minor = 0,
  956. .rev = 0,
  957. .funcs = &vi_common_ip_funcs,
  958. },
  959. {
  960. .type = AMD_IP_BLOCK_TYPE_GMC,
  961. .major = 8,
  962. .minor = 0,
  963. .rev = 0,
  964. .funcs = &gmc_v8_0_ip_funcs,
  965. },
  966. {
  967. .type = AMD_IP_BLOCK_TYPE_IH,
  968. .major = 3,
  969. .minor = 0,
  970. .rev = 0,
  971. .funcs = &tonga_ih_ip_funcs,
  972. },
  973. {
  974. .type = AMD_IP_BLOCK_TYPE_SMC,
  975. .major = 7,
  976. .minor = 1,
  977. .rev = 0,
  978. .funcs = &tonga_dpm_ip_funcs,
  979. },
  980. {
  981. .type = AMD_IP_BLOCK_TYPE_DCE,
  982. .major = 10,
  983. .minor = 0,
  984. .rev = 0,
  985. .funcs = &dce_v10_0_ip_funcs,
  986. },
  987. {
  988. .type = AMD_IP_BLOCK_TYPE_GFX,
  989. .major = 8,
  990. .minor = 0,
  991. .rev = 0,
  992. .funcs = &gfx_v8_0_ip_funcs,
  993. },
  994. {
  995. .type = AMD_IP_BLOCK_TYPE_SDMA,
  996. .major = 3,
  997. .minor = 0,
  998. .rev = 0,
  999. .funcs = &sdma_v3_0_ip_funcs,
  1000. },
  1001. {
  1002. .type = AMD_IP_BLOCK_TYPE_UVD,
  1003. .major = 5,
  1004. .minor = 0,
  1005. .rev = 0,
  1006. .funcs = &uvd_v5_0_ip_funcs,
  1007. },
  1008. {
  1009. .type = AMD_IP_BLOCK_TYPE_VCE,
  1010. .major = 3,
  1011. .minor = 0,
  1012. .rev = 0,
  1013. .funcs = &vce_v3_0_ip_funcs,
  1014. },
  1015. };
  1016. static const struct amdgpu_ip_block_version fiji_ip_blocks[] =
  1017. {
  1018. /* ORDER MATTERS! */
  1019. {
  1020. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1021. .major = 2,
  1022. .minor = 0,
  1023. .rev = 0,
  1024. .funcs = &vi_common_ip_funcs,
  1025. },
  1026. {
  1027. .type = AMD_IP_BLOCK_TYPE_GMC,
  1028. .major = 8,
  1029. .minor = 5,
  1030. .rev = 0,
  1031. .funcs = &gmc_v8_0_ip_funcs,
  1032. },
  1033. {
  1034. .type = AMD_IP_BLOCK_TYPE_IH,
  1035. .major = 3,
  1036. .minor = 0,
  1037. .rev = 0,
  1038. .funcs = &tonga_ih_ip_funcs,
  1039. },
  1040. {
  1041. .type = AMD_IP_BLOCK_TYPE_SMC,
  1042. .major = 7,
  1043. .minor = 1,
  1044. .rev = 0,
  1045. .funcs = &fiji_dpm_ip_funcs,
  1046. },
  1047. {
  1048. .type = AMD_IP_BLOCK_TYPE_DCE,
  1049. .major = 10,
  1050. .minor = 1,
  1051. .rev = 0,
  1052. .funcs = &dce_v10_0_ip_funcs,
  1053. },
  1054. {
  1055. .type = AMD_IP_BLOCK_TYPE_GFX,
  1056. .major = 8,
  1057. .minor = 0,
  1058. .rev = 0,
  1059. .funcs = &gfx_v8_0_ip_funcs,
  1060. },
  1061. {
  1062. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1063. .major = 3,
  1064. .minor = 0,
  1065. .rev = 0,
  1066. .funcs = &sdma_v3_0_ip_funcs,
  1067. },
  1068. {
  1069. .type = AMD_IP_BLOCK_TYPE_UVD,
  1070. .major = 6,
  1071. .minor = 0,
  1072. .rev = 0,
  1073. .funcs = &uvd_v6_0_ip_funcs,
  1074. },
  1075. {
  1076. .type = AMD_IP_BLOCK_TYPE_VCE,
  1077. .major = 3,
  1078. .minor = 0,
  1079. .rev = 0,
  1080. .funcs = &vce_v3_0_ip_funcs,
  1081. },
  1082. };
  1083. static const struct amdgpu_ip_block_version cz_ip_blocks[] =
  1084. {
  1085. /* ORDER MATTERS! */
  1086. {
  1087. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1088. .major = 2,
  1089. .minor = 0,
  1090. .rev = 0,
  1091. .funcs = &vi_common_ip_funcs,
  1092. },
  1093. {
  1094. .type = AMD_IP_BLOCK_TYPE_GMC,
  1095. .major = 8,
  1096. .minor = 0,
  1097. .rev = 0,
  1098. .funcs = &gmc_v8_0_ip_funcs,
  1099. },
  1100. {
  1101. .type = AMD_IP_BLOCK_TYPE_IH,
  1102. .major = 3,
  1103. .minor = 0,
  1104. .rev = 0,
  1105. .funcs = &cz_ih_ip_funcs,
  1106. },
  1107. {
  1108. .type = AMD_IP_BLOCK_TYPE_SMC,
  1109. .major = 8,
  1110. .minor = 0,
  1111. .rev = 0,
  1112. .funcs = &cz_dpm_ip_funcs,
  1113. },
  1114. {
  1115. .type = AMD_IP_BLOCK_TYPE_DCE,
  1116. .major = 11,
  1117. .minor = 0,
  1118. .rev = 0,
  1119. .funcs = &dce_v11_0_ip_funcs,
  1120. },
  1121. {
  1122. .type = AMD_IP_BLOCK_TYPE_GFX,
  1123. .major = 8,
  1124. .minor = 0,
  1125. .rev = 0,
  1126. .funcs = &gfx_v8_0_ip_funcs,
  1127. },
  1128. {
  1129. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1130. .major = 3,
  1131. .minor = 0,
  1132. .rev = 0,
  1133. .funcs = &sdma_v3_0_ip_funcs,
  1134. },
  1135. {
  1136. .type = AMD_IP_BLOCK_TYPE_UVD,
  1137. .major = 6,
  1138. .minor = 0,
  1139. .rev = 0,
  1140. .funcs = &uvd_v6_0_ip_funcs,
  1141. },
  1142. {
  1143. .type = AMD_IP_BLOCK_TYPE_VCE,
  1144. .major = 3,
  1145. .minor = 0,
  1146. .rev = 0,
  1147. .funcs = &vce_v3_0_ip_funcs,
  1148. },
  1149. };
  1150. int vi_set_ip_blocks(struct amdgpu_device *adev)
  1151. {
  1152. switch (adev->asic_type) {
  1153. case CHIP_TOPAZ:
  1154. adev->ip_blocks = topaz_ip_blocks;
  1155. adev->num_ip_blocks = ARRAY_SIZE(topaz_ip_blocks);
  1156. break;
  1157. case CHIP_FIJI:
  1158. adev->ip_blocks = fiji_ip_blocks;
  1159. adev->num_ip_blocks = ARRAY_SIZE(fiji_ip_blocks);
  1160. break;
  1161. case CHIP_TONGA:
  1162. adev->ip_blocks = tonga_ip_blocks;
  1163. adev->num_ip_blocks = ARRAY_SIZE(tonga_ip_blocks);
  1164. break;
  1165. case CHIP_CARRIZO:
  1166. case CHIP_STONEY:
  1167. adev->ip_blocks = cz_ip_blocks;
  1168. adev->num_ip_blocks = ARRAY_SIZE(cz_ip_blocks);
  1169. break;
  1170. default:
  1171. /* FIXME: not supported yet */
  1172. return -EINVAL;
  1173. }
  1174. return 0;
  1175. }
  1176. #define ATI_REV_ID_FUSE_MACRO__ADDRESS 0xC0014044
  1177. #define ATI_REV_ID_FUSE_MACRO__SHIFT 9
  1178. #define ATI_REV_ID_FUSE_MACRO__MASK 0x00001E00
  1179. static uint32_t vi_get_rev_id(struct amdgpu_device *adev)
  1180. {
  1181. if (adev->asic_type == CHIP_TOPAZ)
  1182. return (RREG32(mmPCIE_EFUSE4) & PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID_MASK)
  1183. >> PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID__SHIFT;
  1184. else if (adev->flags & AMD_IS_APU)
  1185. return (RREG32_SMC(ATI_REV_ID_FUSE_MACRO__ADDRESS) & ATI_REV_ID_FUSE_MACRO__MASK)
  1186. >> ATI_REV_ID_FUSE_MACRO__SHIFT;
  1187. else
  1188. return (RREG32(mmCC_DRM_ID_STRAPS) & CC_DRM_ID_STRAPS__ATI_REV_ID_MASK)
  1189. >> CC_DRM_ID_STRAPS__ATI_REV_ID__SHIFT;
  1190. }
  1191. static const struct amdgpu_asic_funcs vi_asic_funcs =
  1192. {
  1193. .read_disabled_bios = &vi_read_disabled_bios,
  1194. .read_register = &vi_read_register,
  1195. .reset = &vi_asic_reset,
  1196. .set_vga_state = &vi_vga_set_state,
  1197. .get_xclk = &vi_get_xclk,
  1198. .set_uvd_clocks = &vi_set_uvd_clocks,
  1199. .set_vce_clocks = &vi_set_vce_clocks,
  1200. .get_cu_info = &gfx_v8_0_get_cu_info,
  1201. /* these should be moved to their own ip modules */
  1202. .get_gpu_clock_counter = &gfx_v8_0_get_gpu_clock_counter,
  1203. .wait_for_mc_idle = &gmc_v8_0_mc_wait_for_idle,
  1204. };
  1205. static int vi_common_early_init(void *handle)
  1206. {
  1207. bool smc_enabled = false;
  1208. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1209. if (adev->flags & AMD_IS_APU) {
  1210. adev->smc_rreg = &cz_smc_rreg;
  1211. adev->smc_wreg = &cz_smc_wreg;
  1212. } else {
  1213. adev->smc_rreg = &vi_smc_rreg;
  1214. adev->smc_wreg = &vi_smc_wreg;
  1215. }
  1216. adev->pcie_rreg = &vi_pcie_rreg;
  1217. adev->pcie_wreg = &vi_pcie_wreg;
  1218. adev->uvd_ctx_rreg = &vi_uvd_ctx_rreg;
  1219. adev->uvd_ctx_wreg = &vi_uvd_ctx_wreg;
  1220. adev->didt_rreg = &vi_didt_rreg;
  1221. adev->didt_wreg = &vi_didt_wreg;
  1222. adev->asic_funcs = &vi_asic_funcs;
  1223. if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_SMC) &&
  1224. (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_SMC)))
  1225. smc_enabled = true;
  1226. adev->rev_id = vi_get_rev_id(adev);
  1227. adev->external_rev_id = 0xFF;
  1228. switch (adev->asic_type) {
  1229. case CHIP_TOPAZ:
  1230. adev->has_uvd = false;
  1231. adev->cg_flags = 0;
  1232. adev->pg_flags = 0;
  1233. adev->external_rev_id = 0x1;
  1234. break;
  1235. case CHIP_FIJI:
  1236. adev->has_uvd = true;
  1237. adev->cg_flags = 0;
  1238. adev->pg_flags = 0;
  1239. adev->external_rev_id = adev->rev_id + 0x3c;
  1240. break;
  1241. case CHIP_TONGA:
  1242. adev->has_uvd = true;
  1243. adev->cg_flags = 0;
  1244. adev->pg_flags = 0;
  1245. adev->external_rev_id = adev->rev_id + 0x14;
  1246. break;
  1247. case CHIP_CARRIZO:
  1248. case CHIP_STONEY:
  1249. adev->has_uvd = true;
  1250. adev->cg_flags = 0;
  1251. /* Disable UVD pg */
  1252. adev->pg_flags = /* AMDGPU_PG_SUPPORT_UVD | */AMDGPU_PG_SUPPORT_VCE;
  1253. adev->external_rev_id = adev->rev_id + 0x1;
  1254. break;
  1255. default:
  1256. /* FIXME: not supported yet */
  1257. return -EINVAL;
  1258. }
  1259. if (amdgpu_smc_load_fw && smc_enabled)
  1260. adev->firmware.smu_load = true;
  1261. return 0;
  1262. }
  1263. static int vi_common_sw_init(void *handle)
  1264. {
  1265. return 0;
  1266. }
  1267. static int vi_common_sw_fini(void *handle)
  1268. {
  1269. return 0;
  1270. }
  1271. static int vi_common_hw_init(void *handle)
  1272. {
  1273. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1274. /* move the golden regs per IP block */
  1275. vi_init_golden_registers(adev);
  1276. /* enable pcie gen2/3 link */
  1277. vi_pcie_gen3_enable(adev);
  1278. /* enable aspm */
  1279. vi_program_aspm(adev);
  1280. /* enable the doorbell aperture */
  1281. vi_enable_doorbell_aperture(adev, true);
  1282. return 0;
  1283. }
  1284. static int vi_common_hw_fini(void *handle)
  1285. {
  1286. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1287. /* enable the doorbell aperture */
  1288. vi_enable_doorbell_aperture(adev, false);
  1289. return 0;
  1290. }
  1291. static int vi_common_suspend(void *handle)
  1292. {
  1293. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1294. return vi_common_hw_fini(adev);
  1295. }
  1296. static int vi_common_resume(void *handle)
  1297. {
  1298. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1299. return vi_common_hw_init(adev);
  1300. }
  1301. static bool vi_common_is_idle(void *handle)
  1302. {
  1303. return true;
  1304. }
  1305. static int vi_common_wait_for_idle(void *handle)
  1306. {
  1307. return 0;
  1308. }
  1309. static void vi_common_print_status(void *handle)
  1310. {
  1311. return;
  1312. }
  1313. static int vi_common_soft_reset(void *handle)
  1314. {
  1315. return 0;
  1316. }
  1317. static int vi_common_set_clockgating_state(void *handle,
  1318. enum amd_clockgating_state state)
  1319. {
  1320. return 0;
  1321. }
  1322. static int vi_common_set_powergating_state(void *handle,
  1323. enum amd_powergating_state state)
  1324. {
  1325. return 0;
  1326. }
  1327. const struct amd_ip_funcs vi_common_ip_funcs = {
  1328. .early_init = vi_common_early_init,
  1329. .late_init = NULL,
  1330. .sw_init = vi_common_sw_init,
  1331. .sw_fini = vi_common_sw_fini,
  1332. .hw_init = vi_common_hw_init,
  1333. .hw_fini = vi_common_hw_fini,
  1334. .suspend = vi_common_suspend,
  1335. .resume = vi_common_resume,
  1336. .is_idle = vi_common_is_idle,
  1337. .wait_for_idle = vi_common_wait_for_idle,
  1338. .soft_reset = vi_common_soft_reset,
  1339. .print_status = vi_common_print_status,
  1340. .set_clockgating_state = vi_common_set_clockgating_state,
  1341. .set_powergating_state = vi_common_set_powergating_state,
  1342. };