blob: e338ad6d0d200f8d8c4601dcbd318917774be862 [file] [log] [blame]
Ken Wang220ab9b2017-03-06 14:49:53 -05001/*
2 * Copyright 2016 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>
Masahiro Yamada248a1d62017-04-24 13:50:21 +090026#include <drm/drmP.h>
Ken Wang220ab9b2017-03-06 14:49:53 -050027#include "amdgpu.h"
Alex Deucherd05da0e2017-06-30 17:08:45 -040028#include "amdgpu_atombios.h"
Ken Wang220ab9b2017-03-06 14:49:53 -050029#include "amdgpu_ih.h"
30#include "amdgpu_uvd.h"
31#include "amdgpu_vce.h"
32#include "amdgpu_ucode.h"
33#include "amdgpu_psp.h"
34#include "atom.h"
35#include "amd_pcie.h"
36
Feifei Xu5d735f82017-11-23 11:09:07 +080037#include "uvd/uvd_7_0_offset.h"
Feifei Xucde5c342017-11-24 10:29:00 +080038#include "gc/gc_9_0_offset.h"
39#include "gc/gc_9_0_sh_mask.h"
Feifei Xu812f77b2017-11-15 16:01:30 +080040#include "sdma0/sdma0_4_0_offset.h"
41#include "sdma1/sdma1_4_0_offset.h"
Feifei Xu75199b82017-11-15 18:09:33 +080042#include "hdp/hdp_4_0_offset.h"
43#include "hdp/hdp_4_0_sh_mask.h"
Feifei Xu424d9bb2017-11-23 15:09:51 +080044#include "smuio/smuio_9_0_offset.h"
45#include "smuio/smuio_9_0_sh_mask.h"
Ken Wang220ab9b2017-03-06 14:49:53 -050046
47#include "soc15.h"
48#include "soc15_common.h"
49#include "gfx_v9_0.h"
50#include "gmc_v9_0.h"
51#include "gfxhub_v1_0.h"
52#include "mmhub_v1_0.h"
Hawking Zhang070706c2018-03-28 17:08:04 +080053#include "df_v1_7.h"
Feifei Xu698758b2018-04-04 14:32:10 +080054#include "df_v3_6.h"
Ken Wang220ab9b2017-03-06 14:49:53 -050055#include "vega10_ih.h"
56#include "sdma_v4_0.h"
57#include "uvd_v7_0.h"
58#include "vce_v4_0.h"
Leo Liuf2d7e702016-12-28 13:36:00 -050059#include "vcn_v1_0.h"
Xiangliang Yu796b6562017-02-28 17:22:03 +080060#include "dce_virtual.h"
Xiangliang Yuf1a34462017-03-08 15:06:47 +080061#include "mxgpu_ai.h"
Ken Wang220ab9b2017-03-06 14:49:53 -050062
Ken Wang220ab9b2017-03-06 14:49:53 -050063#define mmMP0_MISC_CGTT_CTRL0 0x01b9
64#define mmMP0_MISC_CGTT_CTRL0_BASE_IDX 0
65#define mmMP0_MISC_LIGHT_SLEEP_CTRL 0x01ba
66#define mmMP0_MISC_LIGHT_SLEEP_CTRL_BASE_IDX 0
67
68/*
69 * Indirect registers accessor
70 */
71static u32 soc15_pcie_rreg(struct amdgpu_device *adev, u32 reg)
72{
73 unsigned long flags, address, data;
74 u32 r;
Shaoyun Liu946a4d52017-11-28 17:01:21 -050075 address = adev->nbio_funcs->get_pcie_index_offset(adev);
76 data = adev->nbio_funcs->get_pcie_data_offset(adev);
Ken Wang220ab9b2017-03-06 14:49:53 -050077
78 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
79 WREG32(address, reg);
80 (void)RREG32(address);
81 r = RREG32(data);
82 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
83 return r;
84}
85
86static void soc15_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
87{
88 unsigned long flags, address, data;
Ken Wang220ab9b2017-03-06 14:49:53 -050089
Shaoyun Liu946a4d52017-11-28 17:01:21 -050090 address = adev->nbio_funcs->get_pcie_index_offset(adev);
91 data = adev->nbio_funcs->get_pcie_data_offset(adev);
Ken Wang220ab9b2017-03-06 14:49:53 -050092
93 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
94 WREG32(address, reg);
95 (void)RREG32(address);
96 WREG32(data, v);
97 (void)RREG32(data);
98 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
99}
100
101static u32 soc15_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
102{
103 unsigned long flags, address, data;
104 u32 r;
105
106 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
107 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
108
109 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
110 WREG32(address, ((reg) & 0x1ff));
111 r = RREG32(data);
112 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
113 return r;
114}
115
116static void soc15_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
117{
118 unsigned long flags, address, data;
119
120 address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
121 data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
122
123 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
124 WREG32(address, ((reg) & 0x1ff));
125 WREG32(data, (v));
126 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
127}
128
129static u32 soc15_didt_rreg(struct amdgpu_device *adev, u32 reg)
130{
131 unsigned long flags, address, data;
132 u32 r;
133
134 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
135 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
136
137 spin_lock_irqsave(&adev->didt_idx_lock, flags);
138 WREG32(address, (reg));
139 r = RREG32(data);
140 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
141 return r;
142}
143
144static void soc15_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
145{
146 unsigned long flags, address, data;
147
148 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
149 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
150
151 spin_lock_irqsave(&adev->didt_idx_lock, flags);
152 WREG32(address, (reg));
153 WREG32(data, (v));
154 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
155}
156
Evan Quan560460f2017-07-03 22:37:44 +0800157static u32 soc15_gc_cac_rreg(struct amdgpu_device *adev, u32 reg)
158{
159 unsigned long flags;
160 u32 r;
161
162 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
163 WREG32_SOC15(GC, 0, mmGC_CAC_IND_INDEX, (reg));
164 r = RREG32_SOC15(GC, 0, mmGC_CAC_IND_DATA);
165 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
166 return r;
167}
168
169static void soc15_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
170{
171 unsigned long flags;
172
173 spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
174 WREG32_SOC15(GC, 0, mmGC_CAC_IND_INDEX, (reg));
175 WREG32_SOC15(GC, 0, mmGC_CAC_IND_DATA, (v));
176 spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
177}
178
Evan Quan2f11fb02017-07-04 09:23:01 +0800179static u32 soc15_se_cac_rreg(struct amdgpu_device *adev, u32 reg)
180{
181 unsigned long flags;
182 u32 r;
183
184 spin_lock_irqsave(&adev->se_cac_idx_lock, flags);
185 WREG32_SOC15(GC, 0, mmSE_CAC_IND_INDEX, (reg));
186 r = RREG32_SOC15(GC, 0, mmSE_CAC_IND_DATA);
187 spin_unlock_irqrestore(&adev->se_cac_idx_lock, flags);
188 return r;
189}
190
191static void soc15_se_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
192{
193 unsigned long flags;
194
195 spin_lock_irqsave(&adev->se_cac_idx_lock, flags);
196 WREG32_SOC15(GC, 0, mmSE_CAC_IND_INDEX, (reg));
197 WREG32_SOC15(GC, 0, mmSE_CAC_IND_DATA, (v));
198 spin_unlock_irqrestore(&adev->se_cac_idx_lock, flags);
199}
200
Ken Wang220ab9b2017-03-06 14:49:53 -0500201static u32 soc15_get_config_memsize(struct amdgpu_device *adev)
202{
Alex Deucherbf383fb2017-12-08 13:07:58 -0500203 return adev->nbio_funcs->get_memsize(adev);
Ken Wang220ab9b2017-03-06 14:49:53 -0500204}
205
Ken Wang220ab9b2017-03-06 14:49:53 -0500206static u32 soc15_get_xclk(struct amdgpu_device *adev)
207{
Ken Wang76d61722017-09-29 15:41:43 +0800208 return adev->clock.spll.reference_freq;
Ken Wang220ab9b2017-03-06 14:49:53 -0500209}
210
211
212void soc15_grbm_select(struct amdgpu_device *adev,
213 u32 me, u32 pipe, u32 queue, u32 vmid)
214{
215 u32 grbm_gfx_cntl = 0;
216 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
217 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
218 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
219 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
220
221 WREG32(SOC15_REG_OFFSET(GC, 0, mmGRBM_GFX_CNTL), grbm_gfx_cntl);
222}
223
224static void soc15_vga_set_state(struct amdgpu_device *adev, bool state)
225{
226 /* todo */
227}
228
229static bool soc15_read_disabled_bios(struct amdgpu_device *adev)
230{
231 /* todo */
232 return false;
233}
234
235static bool soc15_read_bios_from_rom(struct amdgpu_device *adev,
236 u8 *bios, u32 length_bytes)
237{
238 u32 *dw_ptr;
239 u32 i, length_dw;
240
241 if (bios == NULL)
242 return false;
243 if (length_bytes == 0)
244 return false;
245 /* APU vbios image is part of sbios image */
246 if (adev->flags & AMD_IS_APU)
247 return false;
248
249 dw_ptr = (u32 *)bios;
250 length_dw = ALIGN(length_bytes, 4) / 4;
251
252 /* set rom index to 0 */
253 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0);
254 /* read out the rom data */
255 for (i = 0; i < length_dw; i++)
256 dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA));
257
258 return true;
259}
260
Shaoyun Liu946a4d52017-11-28 17:01:21 -0500261struct soc15_allowed_register_entry {
262 uint32_t hwip;
263 uint32_t inst;
264 uint32_t seg;
265 uint32_t reg_offset;
266 bool grbm_indexed;
267};
268
269
270static struct soc15_allowed_register_entry soc15_allowed_read_registers[] = {
271 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
272 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},
273 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)},
274 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)},
275 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)},
276 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)},
277 { SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)},
278 { SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)},
279 { SOC15_REG_ENTRY(GC, 0, mmCP_STAT)},
280 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)},
281 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)},
282 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)},
283 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)},
284 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)},
285 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)},
286 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)},
287 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)},
288 { SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)},
Alex Deucher5eeae242018-04-10 10:15:26 -0500289 { SOC15_REG_ENTRY(GC, 0, mmDB_DEBUG2)},
Ken Wang220ab9b2017-03-06 14:49:53 -0500290};
291
292static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
293 u32 sh_num, u32 reg_offset)
294{
295 uint32_t val;
296
297 mutex_lock(&adev->grbm_idx_mutex);
298 if (se_num != 0xffffffff || sh_num != 0xffffffff)
299 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
300
301 val = RREG32(reg_offset);
302
303 if (se_num != 0xffffffff || sh_num != 0xffffffff)
304 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
305 mutex_unlock(&adev->grbm_idx_mutex);
306 return val;
307}
308
Alex Deucherc013cea2017-03-24 15:05:07 -0400309static uint32_t soc15_get_register_value(struct amdgpu_device *adev,
310 bool indexed, u32 se_num,
311 u32 sh_num, u32 reg_offset)
312{
313 if (indexed) {
314 return soc15_read_indexed_register(adev, se_num, sh_num, reg_offset);
315 } else {
Shaoyun Liucd292532017-11-29 13:51:32 -0500316 if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
Alex Deucherc013cea2017-03-24 15:05:07 -0400317 return adev->gfx.config.gb_addr_config;
Alex Deucher5eeae242018-04-10 10:15:26 -0500318 else if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmDB_DEBUG2))
319 return adev->gfx.config.db_debug2;
Shaoyun Liucd292532017-11-29 13:51:32 -0500320 return RREG32(reg_offset);
Alex Deucherc013cea2017-03-24 15:05:07 -0400321 }
322}
323
Ken Wang220ab9b2017-03-06 14:49:53 -0500324static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
325 u32 sh_num, u32 reg_offset, u32 *value)
326{
Christian König3032f352017-04-12 12:53:18 +0200327 uint32_t i;
Shaoyun Liu946a4d52017-11-28 17:01:21 -0500328 struct soc15_allowed_register_entry *en;
Ken Wang220ab9b2017-03-06 14:49:53 -0500329
330 *value = 0;
Ken Wang220ab9b2017-03-06 14:49:53 -0500331 for (i = 0; i < ARRAY_SIZE(soc15_allowed_read_registers); i++) {
Shaoyun Liu946a4d52017-11-28 17:01:21 -0500332 en = &soc15_allowed_read_registers[i];
333 if (reg_offset != (adev->reg_offset[en->hwip][en->inst][en->seg]
334 + en->reg_offset))
Ken Wang220ab9b2017-03-06 14:49:53 -0500335 continue;
336
Christian König97fcc762017-04-12 12:49:54 +0200337 *value = soc15_get_register_value(adev,
338 soc15_allowed_read_registers[i].grbm_indexed,
339 se_num, sh_num, reg_offset);
Ken Wang220ab9b2017-03-06 14:49:53 -0500340 return 0;
341 }
342 return -EINVAL;
343}
344
Shaoyun Liu946a4d52017-11-28 17:01:21 -0500345
346/**
347 * soc15_program_register_sequence - program an array of registers.
348 *
349 * @adev: amdgpu_device pointer
350 * @regs: pointer to the register array
351 * @array_size: size of the register array
352 *
353 * Programs an array or registers with and and or masks.
354 * This is a helper for setting golden registers.
355 */
356
357void soc15_program_register_sequence(struct amdgpu_device *adev,
358 const struct soc15_reg_golden *regs,
359 const u32 array_size)
360{
361 const struct soc15_reg_golden *entry;
362 u32 tmp, reg;
363 int i;
364
365 for (i = 0; i < array_size; ++i) {
366 entry = &regs[i];
367 reg = adev->reg_offset[entry->hwip][entry->instance][entry->segment] + entry->reg;
368
369 if (entry->and_mask == 0xffffffff) {
370 tmp = entry->or_mask;
371 } else {
372 tmp = RREG32(reg);
373 tmp &= ~(entry->and_mask);
374 tmp |= entry->or_mask;
375 }
376 WREG32(reg, tmp);
377 }
378
379}
380
381
Ken Wang98512bb2017-09-14 16:25:19 +0800382static int soc15_asic_reset(struct amdgpu_device *adev)
Ken Wang220ab9b2017-03-06 14:49:53 -0500383{
384 u32 i;
385
Ken Wang98512bb2017-09-14 16:25:19 +0800386 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
387
388 dev_info(adev->dev, "GPU reset\n");
Ken Wang220ab9b2017-03-06 14:49:53 -0500389
390 /* disable BM */
391 pci_clear_master(adev->pdev);
Ken Wang220ab9b2017-03-06 14:49:53 -0500392
Ken Wang98512bb2017-09-14 16:25:19 +0800393 pci_save_state(adev->pdev);
394
Alex Deucherf75a9a52018-01-23 16:27:31 -0500395 psp_gpu_reset(adev);
Ken Wang98512bb2017-09-14 16:25:19 +0800396
397 pci_restore_state(adev->pdev);
Ken Wang220ab9b2017-03-06 14:49:53 -0500398
399 /* wait for asic to come out of reset */
400 for (i = 0; i < adev->usec_timeout; i++) {
Alex Deucherbf383fb2017-12-08 13:07:58 -0500401 u32 memsize = adev->nbio_funcs->get_memsize(adev);
402
Chunming Zhouaecbe642017-05-04 15:06:25 -0400403 if (memsize != 0xffffffff)
Ken Wang220ab9b2017-03-06 14:49:53 -0500404 break;
405 udelay(1);
406 }
407
Alex Deucherd05da0e2017-06-30 17:08:45 -0400408 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
Ken Wang220ab9b2017-03-06 14:49:53 -0500409
410 return 0;
411}
412
413/*static int soc15_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
414 u32 cntl_reg, u32 status_reg)
415{
416 return 0;
417}*/
418
419static int soc15_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
420{
421 /*int r;
422
423 r = soc15_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
424 if (r)
425 return r;
426
427 r = soc15_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
428 */
429 return 0;
430}
431
432static int soc15_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
433{
434 /* todo */
435
436 return 0;
437}
438
439static void soc15_pcie_gen3_enable(struct amdgpu_device *adev)
440{
441 if (pci_is_root_bus(adev->pdev->bus))
442 return;
443
444 if (amdgpu_pcie_gen2 == 0)
445 return;
446
447 if (adev->flags & AMD_IS_APU)
448 return;
449
450 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
451 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
452 return;
453
454 /* todo */
455}
456
457static void soc15_program_aspm(struct amdgpu_device *adev)
458{
459
460 if (amdgpu_aspm == 0)
461 return;
462
463 /* todo */
464}
465
466static void soc15_enable_doorbell_aperture(struct amdgpu_device *adev,
Alex Deucherbf383fb2017-12-08 13:07:58 -0500467 bool enable)
Ken Wang220ab9b2017-03-06 14:49:53 -0500468{
Alex Deucherbf383fb2017-12-08 13:07:58 -0500469 adev->nbio_funcs->enable_doorbell_aperture(adev, enable);
470 adev->nbio_funcs->enable_doorbell_selfring_aperture(adev, enable);
Ken Wang220ab9b2017-03-06 14:49:53 -0500471}
472
473static const struct amdgpu_ip_block_version vega10_common_ip_block =
474{
475 .type = AMD_IP_BLOCK_TYPE_COMMON,
476 .major = 2,
477 .minor = 0,
478 .rev = 0,
479 .funcs = &soc15_common_ip_funcs,
480};
481
482int soc15_set_ip_blocks(struct amdgpu_device *adev)
483{
Shaoyun Liu45228242017-11-27 13:16:35 -0500484 /* Set IP register base before any HW register access */
485 switch (adev->asic_type) {
486 case CHIP_VEGA10:
Hawking Zhang3084eb02018-03-12 18:25:15 +0800487 case CHIP_VEGA12:
Shaoyun Liu45228242017-11-27 13:16:35 -0500488 case CHIP_RAVEN:
Likun Gaoad5a67a2018-07-10 20:22:36 +0800489 case CHIP_PICASSO:
Shaoyun Liu45228242017-11-27 13:16:35 -0500490 vega10_reg_base_init(adev);
491 break;
Feifei Xu8ee273e2018-03-23 14:42:28 -0500492 case CHIP_VEGA20:
493 vega20_reg_base_init(adev);
494 break;
Shaoyun Liu45228242017-11-27 13:16:35 -0500495 default:
496 return -EINVAL;
497 }
498
Alex Deucherbf383fb2017-12-08 13:07:58 -0500499 if (adev->flags & AMD_IS_APU)
500 adev->nbio_funcs = &nbio_v7_0_funcs;
Feifei Xufe3c9482018-03-23 14:44:28 -0500501 else if (adev->asic_type == CHIP_VEGA20)
502 adev->nbio_funcs = &nbio_v7_4_funcs;
Alex Deucherbf383fb2017-12-08 13:07:58 -0500503 else
504 adev->nbio_funcs = &nbio_v6_1_funcs;
505
Feifei Xu698758b2018-04-04 14:32:10 +0800506 if (adev->asic_type == CHIP_VEGA20)
507 adev->df_funcs = &df_v3_6_funcs;
508 else
509 adev->df_funcs = &df_v1_7_funcs;
Alex Deucherbf383fb2017-12-08 13:07:58 -0500510 adev->nbio_funcs->detect_hw_virt(adev);
Xiangliang Yu1b922422017-03-08 15:00:48 +0800511
Xiangliang Yuf1a34462017-03-08 15:06:47 +0800512 if (amdgpu_sriov_vf(adev))
513 adev->virt.ops = &xgpu_ai_virt_ops;
514
Ken Wang220ab9b2017-03-06 14:49:53 -0500515 switch (adev->asic_type) {
516 case CHIP_VEGA10:
Alex Deucher692069a2018-03-06 22:35:19 -0500517 case CHIP_VEGA12:
Feifei Xu7c7af6c2018-04-20 18:35:42 +0800518 case CHIP_VEGA20:
Alex Deucher2990a1f2017-12-15 16:18:00 -0500519 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
520 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
521 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
Feifei Xu654f7612018-05-11 14:54:50 +0800522 if (adev->asic_type == CHIP_VEGA20)
523 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
524 else
Feifei Xu602ed6c2018-04-24 11:20:16 +0800525 amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
Evan Quana6637312018-05-02 15:45:54 +0800526 if (!amdgpu_sriov_vf(adev))
527 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
Alex Deucherf8445302017-03-22 10:49:25 -0400528 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
Alex Deucher2990a1f2017-12-15 16:18:00 -0500529 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Alex Deucherab587d42017-04-19 17:28:47 -0400530#if defined(CONFIG_DRM_AMD_DC)
531 else if (amdgpu_device_has_dc_support(adev))
Alex Deucher2990a1f2017-12-15 16:18:00 -0500532 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Alex Deucherab587d42017-04-19 17:28:47 -0400533#else
534# warning "Enable CONFIG_DRM_AMD_DC for display support on SOC15."
535#endif
Alex Deucher2990a1f2017-12-15 16:18:00 -0500536 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
537 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
James Zhu705e98d2018-04-30 08:43:12 -0400538 amdgpu_device_ip_block_add(adev, &uvd_v7_0_ip_block);
539 amdgpu_device_ip_block_add(adev, &vce_v4_0_ip_block);
Ken Wang220ab9b2017-03-06 14:49:53 -0500540 break;
Chunming Zhou1023b792016-12-08 10:09:13 +0800541 case CHIP_RAVEN:
Alex Deucher2990a1f2017-12-15 16:18:00 -0500542 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
543 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
544 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
545 amdgpu_device_ip_block_add(adev, &psp_v10_0_ip_block);
Rex Zhub9050902018-03-12 19:52:23 +0800546 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
Alex Deucherd67fed162017-06-02 14:52:18 -0400547 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
Alex Deucher2990a1f2017-12-15 16:18:00 -0500548 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Alex Deucher0bf954c2017-06-02 14:54:26 -0400549#if defined(CONFIG_DRM_AMD_DC)
550 else if (amdgpu_device_has_dc_support(adev))
Alex Deucher2990a1f2017-12-15 16:18:00 -0500551 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Alex Deucher0bf954c2017-06-02 14:54:26 -0400552#else
553# warning "Enable CONFIG_DRM_AMD_DC for display support on SOC15."
554#endif
Alex Deucher2990a1f2017-12-15 16:18:00 -0500555 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
556 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
557 amdgpu_device_ip_block_add(adev, &vcn_v1_0_ip_block);
Chunming Zhou1023b792016-12-08 10:09:13 +0800558 break;
Huang Rui40c23582018-07-09 20:00:05 +0800559 case CHIP_PICASSO:
560 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
561 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
562 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
563 amdgpu_device_ip_block_add(adev, &psp_v10_0_ip_block);
564 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
565 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
566 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
567#if defined(CONFIG_DRM_AMD_DC)
568 else if (amdgpu_device_has_dc_support(adev))
569 amdgpu_device_ip_block_add(adev, &dm_ip_block);
570#else
571# warning "Enable CONFIG_DRM_AMD_DC for display support on SOC15."
572#endif
573 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
574 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
575 amdgpu_device_ip_block_add(adev, &vcn_v1_0_ip_block);
576 break;
Ken Wang220ab9b2017-03-06 14:49:53 -0500577 default:
578 return -EINVAL;
579 }
580
581 return 0;
582}
583
584static uint32_t soc15_get_rev_id(struct amdgpu_device *adev)
585{
Alex Deucherbf383fb2017-12-08 13:07:58 -0500586 return adev->nbio_funcs->get_rev_id(adev);
Ken Wang220ab9b2017-03-06 14:49:53 -0500587}
588
Christian König69882562018-01-19 14:17:40 +0100589static void soc15_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
Alex Deucher73c73242017-09-06 18:06:45 -0400590{
Christian König69882562018-01-19 14:17:40 +0100591 adev->nbio_funcs->hdp_flush(adev, ring);
Alex Deucher73c73242017-09-06 18:06:45 -0400592}
593
Christian König69882562018-01-19 14:17:40 +0100594static void soc15_invalidate_hdp(struct amdgpu_device *adev,
595 struct amdgpu_ring *ring)
Alex Deucher73c73242017-09-06 18:06:45 -0400596{
Christian König69882562018-01-19 14:17:40 +0100597 if (!ring || !ring->funcs->emit_wreg)
598 WREG32_SOC15_NO_KIQ(NBIO, 0, mmHDP_READ_CACHE_INVALIDATE, 1);
599 else
600 amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
601 HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1);
Alex Deucher73c73242017-09-06 18:06:45 -0400602}
603
Alex Deucheradbd4f82018-03-29 14:39:46 -0500604static bool soc15_need_full_reset(struct amdgpu_device *adev)
605{
606 /* change this when we implement soft reset */
607 return true;
608}
609
Ken Wang220ab9b2017-03-06 14:49:53 -0500610static const struct amdgpu_asic_funcs soc15_asic_funcs =
611{
612 .read_disabled_bios = &soc15_read_disabled_bios,
613 .read_bios_from_rom = &soc15_read_bios_from_rom,
614 .read_register = &soc15_read_register,
615 .reset = &soc15_asic_reset,
616 .set_vga_state = &soc15_vga_set_state,
617 .get_xclk = &soc15_get_xclk,
618 .set_uvd_clocks = &soc15_set_uvd_clocks,
619 .set_vce_clocks = &soc15_set_vce_clocks,
620 .get_config_memsize = &soc15_get_config_memsize,
Alex Deucher73c73242017-09-06 18:06:45 -0400621 .flush_hdp = &soc15_flush_hdp,
622 .invalidate_hdp = &soc15_invalidate_hdp,
Alex Deucheradbd4f82018-03-29 14:39:46 -0500623 .need_full_reset = &soc15_need_full_reset,
Ken Wang220ab9b2017-03-06 14:49:53 -0500624};
625
626static int soc15_common_early_init(void *handle)
627{
Ken Wang220ab9b2017-03-06 14:49:53 -0500628 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
629
630 adev->smc_rreg = NULL;
631 adev->smc_wreg = NULL;
632 adev->pcie_rreg = &soc15_pcie_rreg;
633 adev->pcie_wreg = &soc15_pcie_wreg;
634 adev->uvd_ctx_rreg = &soc15_uvd_ctx_rreg;
635 adev->uvd_ctx_wreg = &soc15_uvd_ctx_wreg;
636 adev->didt_rreg = &soc15_didt_rreg;
637 adev->didt_wreg = &soc15_didt_wreg;
Evan Quan560460f2017-07-03 22:37:44 +0800638 adev->gc_cac_rreg = &soc15_gc_cac_rreg;
639 adev->gc_cac_wreg = &soc15_gc_cac_wreg;
Evan Quan2f11fb02017-07-04 09:23:01 +0800640 adev->se_cac_rreg = &soc15_se_cac_rreg;
641 adev->se_cac_wreg = &soc15_se_cac_wreg;
Ken Wang220ab9b2017-03-06 14:49:53 -0500642
643 adev->asic_funcs = &soc15_asic_funcs;
644
Ken Wang220ab9b2017-03-06 14:49:53 -0500645 adev->rev_id = soc15_get_rev_id(adev);
646 adev->external_rev_id = 0xFF;
647 switch (adev->asic_type) {
648 case CHIP_VEGA10:
649 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
650 AMD_CG_SUPPORT_GFX_MGLS |
651 AMD_CG_SUPPORT_GFX_RLC_LS |
652 AMD_CG_SUPPORT_GFX_CP_LS |
653 AMD_CG_SUPPORT_GFX_3D_CGCG |
654 AMD_CG_SUPPORT_GFX_3D_CGLS |
655 AMD_CG_SUPPORT_GFX_CGCG |
656 AMD_CG_SUPPORT_GFX_CGLS |
657 AMD_CG_SUPPORT_BIF_MGCG |
658 AMD_CG_SUPPORT_BIF_LS |
659 AMD_CG_SUPPORT_HDP_LS |
660 AMD_CG_SUPPORT_DRM_MGCG |
661 AMD_CG_SUPPORT_DRM_LS |
662 AMD_CG_SUPPORT_ROM_MGCG |
663 AMD_CG_SUPPORT_DF_MGCG |
664 AMD_CG_SUPPORT_SDMA_MGCG |
665 AMD_CG_SUPPORT_SDMA_LS |
666 AMD_CG_SUPPORT_MC_MGCG |
667 AMD_CG_SUPPORT_MC_LS;
668 adev->pg_flags = 0;
669 adev->external_rev_id = 0x1;
670 break;
Alex Deucher692069a2018-03-06 22:35:19 -0500671 case CHIP_VEGA12:
Evan Quane4a38752017-12-25 13:16:11 +0800672 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
673 AMD_CG_SUPPORT_GFX_MGLS |
674 AMD_CG_SUPPORT_GFX_CGCG |
675 AMD_CG_SUPPORT_GFX_CGLS |
676 AMD_CG_SUPPORT_GFX_3D_CGCG |
677 AMD_CG_SUPPORT_GFX_3D_CGLS |
678 AMD_CG_SUPPORT_GFX_CP_LS |
679 AMD_CG_SUPPORT_MC_LS |
680 AMD_CG_SUPPORT_MC_MGCG |
681 AMD_CG_SUPPORT_SDMA_MGCG |
682 AMD_CG_SUPPORT_SDMA_LS |
683 AMD_CG_SUPPORT_BIF_MGCG |
684 AMD_CG_SUPPORT_BIF_LS |
685 AMD_CG_SUPPORT_HDP_MGCG |
686 AMD_CG_SUPPORT_HDP_LS |
687 AMD_CG_SUPPORT_ROM_MGCG |
688 AMD_CG_SUPPORT_VCE_MGCG |
689 AMD_CG_SUPPORT_UVD_MGCG;
Alex Deucher692069a2018-03-06 22:35:19 -0500690 adev->pg_flags = 0;
Feifei Xuf559fe22017-12-14 19:02:47 +0800691 adev->external_rev_id = adev->rev_id + 0x14;
Alex Deucher692069a2018-03-06 22:35:19 -0500692 break;
Feifei Xu935be7a2018-01-26 15:06:22 +0800693 case CHIP_VEGA20:
Evan Quan3fdbab52018-03-26 11:43:04 +0800694 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
695 AMD_CG_SUPPORT_GFX_MGLS |
696 AMD_CG_SUPPORT_GFX_CGCG |
697 AMD_CG_SUPPORT_GFX_CGLS |
698 AMD_CG_SUPPORT_GFX_3D_CGCG |
699 AMD_CG_SUPPORT_GFX_3D_CGLS |
700 AMD_CG_SUPPORT_GFX_CP_LS |
701 AMD_CG_SUPPORT_MC_LS |
702 AMD_CG_SUPPORT_MC_MGCG |
703 AMD_CG_SUPPORT_SDMA_MGCG |
704 AMD_CG_SUPPORT_SDMA_LS |
705 AMD_CG_SUPPORT_BIF_MGCG |
706 AMD_CG_SUPPORT_BIF_LS |
707 AMD_CG_SUPPORT_HDP_MGCG |
Evan Quan102e4942018-05-28 09:22:09 +0800708 AMD_CG_SUPPORT_HDP_LS |
Evan Quan3fdbab52018-03-26 11:43:04 +0800709 AMD_CG_SUPPORT_ROM_MGCG |
710 AMD_CG_SUPPORT_VCE_MGCG |
711 AMD_CG_SUPPORT_UVD_MGCG;
Feifei Xu935be7a2018-01-26 15:06:22 +0800712 adev->pg_flags = 0;
713 adev->external_rev_id = adev->rev_id + 0x28;
714 break;
Hawking Zhang957c6fe2016-12-27 21:02:48 +0800715 case CHIP_RAVEN:
Huang Rui5c5928a2017-01-18 18:14:08 +0800716 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
717 AMD_CG_SUPPORT_GFX_MGLS |
718 AMD_CG_SUPPORT_GFX_RLC_LS |
719 AMD_CG_SUPPORT_GFX_CP_LS |
720 AMD_CG_SUPPORT_GFX_3D_CGCG |
721 AMD_CG_SUPPORT_GFX_3D_CGLS |
722 AMD_CG_SUPPORT_GFX_CGCG |
723 AMD_CG_SUPPORT_GFX_CGLS |
724 AMD_CG_SUPPORT_BIF_MGCG |
725 AMD_CG_SUPPORT_BIF_LS |
726 AMD_CG_SUPPORT_HDP_MGCG |
727 AMD_CG_SUPPORT_HDP_LS |
728 AMD_CG_SUPPORT_DRM_MGCG |
729 AMD_CG_SUPPORT_DRM_LS |
Huang Ruic2cdb0e2017-05-05 14:27:23 -0400730 AMD_CG_SUPPORT_ROM_MGCG |
731 AMD_CG_SUPPORT_MC_MGCG |
Huang Ruife1a3b22017-05-05 14:28:27 -0400732 AMD_CG_SUPPORT_MC_LS |
733 AMD_CG_SUPPORT_SDMA_MGCG |
Rex Zhu79953a62018-05-17 11:13:51 +0800734 AMD_CG_SUPPORT_SDMA_LS |
735 AMD_CG_SUPPORT_VCN_MGCG;
Rex Zhu61c8e902018-05-17 16:03:47 +0800736
737 adev->pg_flags = AMD_PG_SUPPORT_SDMA | AMD_PG_SUPPORT_VCN;
Huang Rui400b6af2017-12-14 13:47:16 +0800738
Huang Rui9ac4b0d2017-12-15 14:34:57 +0800739 if (adev->powerplay.pp_feature & PP_GFXOFF_MASK)
740 adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |
741 AMD_PG_SUPPORT_CP |
742 AMD_PG_SUPPORT_RLC_SMU_HS;
743
Hawking Zhang957c6fe2016-12-27 21:02:48 +0800744 adev->external_rev_id = 0x1;
745 break;
Likun Gaoad5a67a2018-07-10 20:22:36 +0800746 case CHIP_PICASSO:
747 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGLS |
748 AMD_CG_SUPPORT_GFX_CP_LS |
749 AMD_CG_SUPPORT_GFX_3D_CGCG |
750 AMD_CG_SUPPORT_GFX_3D_CGLS |
751 AMD_CG_SUPPORT_GFX_CGCG |
752 AMD_CG_SUPPORT_GFX_CGLS |
753 AMD_CG_SUPPORT_BIF_LS |
754 AMD_CG_SUPPORT_HDP_LS |
755 AMD_CG_SUPPORT_ROM_MGCG |
756 AMD_CG_SUPPORT_MC_MGCG |
757 AMD_CG_SUPPORT_MC_LS |
758 AMD_CG_SUPPORT_SDMA_MGCG |
759 AMD_CG_SUPPORT_SDMA_LS;
760
Kenneth Feng1a84d962018-08-24 16:44:11 +0800761 adev->pg_flags = AMD_PG_SUPPORT_SDMA |
762 AMD_PG_SUPPORT_MMHUB |
763 AMD_PG_SUPPORT_VCN;
Kenneth Fenga4494fd2018-08-10 16:22:26 +0800764
Kenneth Feng8c7bf582018-08-07 17:05:22 +0800765 if (adev->powerplay.pp_feature & PP_GFXOFF_MASK)
766 adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |
767 AMD_PG_SUPPORT_CP |
768 AMD_PG_SUPPORT_RLC_SMU_HS;
Likun Gaoad5a67a2018-07-10 20:22:36 +0800769
770 adev->external_rev_id = adev->rev_id + 0x41;
771 break;
Ken Wang220ab9b2017-03-06 14:49:53 -0500772 default:
773 /* FIXME: not supported yet */
774 return -EINVAL;
775 }
776
Xiangliang Yuab276632017-04-21 14:06:09 +0800777 if (amdgpu_sriov_vf(adev)) {
778 amdgpu_virt_init_setting(adev);
779 xgpu_ai_mailbox_set_irq_funcs(adev);
780 }
781
Ken Wang220ab9b2017-03-06 14:49:53 -0500782 return 0;
783}
784
Monk Liu81758c52017-04-05 13:04:50 +0800785static int soc15_common_late_init(void *handle)
786{
787 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
788
789 if (amdgpu_sriov_vf(adev))
790 xgpu_ai_mailbox_get_irq(adev);
791
792 return 0;
793}
794
Ken Wang220ab9b2017-03-06 14:49:53 -0500795static int soc15_common_sw_init(void *handle)
796{
Monk Liu81758c52017-04-05 13:04:50 +0800797 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
798
799 if (amdgpu_sriov_vf(adev))
800 xgpu_ai_mailbox_add_irq_id(adev);
801
Ken Wang220ab9b2017-03-06 14:49:53 -0500802 return 0;
803}
804
805static int soc15_common_sw_fini(void *handle)
806{
807 return 0;
808}
809
810static int soc15_common_hw_init(void *handle)
811{
812 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
813
Ken Wang220ab9b2017-03-06 14:49:53 -0500814 /* enable pcie gen2/3 link */
815 soc15_pcie_gen3_enable(adev);
816 /* enable aspm */
817 soc15_program_aspm(adev);
Alex Deucher833fa072017-07-06 13:43:55 -0400818 /* setup nbio registers */
Alex Deucherbf383fb2017-12-08 13:07:58 -0500819 adev->nbio_funcs->init_registers(adev);
Ken Wang220ab9b2017-03-06 14:49:53 -0500820 /* enable the doorbell aperture */
821 soc15_enable_doorbell_aperture(adev, true);
822
823 return 0;
824}
825
826static int soc15_common_hw_fini(void *handle)
827{
828 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
829
830 /* disable the doorbell aperture */
831 soc15_enable_doorbell_aperture(adev, false);
Monk Liu81758c52017-04-05 13:04:50 +0800832 if (amdgpu_sriov_vf(adev))
833 xgpu_ai_mailbox_put_irq(adev);
Ken Wang220ab9b2017-03-06 14:49:53 -0500834
835 return 0;
836}
837
838static int soc15_common_suspend(void *handle)
839{
840 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
841
842 return soc15_common_hw_fini(adev);
843}
844
845static int soc15_common_resume(void *handle)
846{
847 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
848
849 return soc15_common_hw_init(adev);
850}
851
852static bool soc15_common_is_idle(void *handle)
853{
854 return true;
855}
856
857static int soc15_common_wait_for_idle(void *handle)
858{
859 return 0;
860}
861
862static int soc15_common_soft_reset(void *handle)
863{
864 return 0;
865}
866
867static void soc15_update_hdp_light_sleep(struct amdgpu_device *adev, bool enable)
868{
869 uint32_t def, data;
870
871 def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
872
873 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
874 data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
875 else
876 data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
877
878 if (def != data)
879 WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS), data);
880}
881
882static void soc15_update_drm_clock_gating(struct amdgpu_device *adev, bool enable)
883{
884 uint32_t def, data;
885
886 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
887
888 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_MGCG))
889 data &= ~(0x01000000 |
890 0x02000000 |
891 0x04000000 |
892 0x08000000 |
893 0x10000000 |
894 0x20000000 |
895 0x40000000 |
896 0x80000000);
897 else
898 data |= (0x01000000 |
899 0x02000000 |
900 0x04000000 |
901 0x08000000 |
902 0x10000000 |
903 0x20000000 |
904 0x40000000 |
905 0x80000000);
906
907 if (def != data)
908 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0), data);
909}
910
911static void soc15_update_drm_light_sleep(struct amdgpu_device *adev, bool enable)
912{
913 uint32_t def, data;
914
915 def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
916
917 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
918 data |= 1;
919 else
920 data &= ~1;
921
922 if (def != data)
923 WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL), data);
924}
925
926static void soc15_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
927 bool enable)
928{
929 uint32_t def, data;
930
931 def = data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
932
933 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
934 data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
935 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
936 else
937 data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
938 CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
939
940 if (def != data)
941 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0), data);
942}
943
Ken Wang220ab9b2017-03-06 14:49:53 -0500944static int soc15_common_set_clockgating_state(void *handle,
945 enum amd_clockgating_state state)
946{
947 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
948
Monk Liu6e9dc862017-03-22 18:02:40 +0800949 if (amdgpu_sriov_vf(adev))
950 return 0;
951
Ken Wang220ab9b2017-03-06 14:49:53 -0500952 switch (adev->asic_type) {
953 case CHIP_VEGA10:
Alex Deucher692069a2018-03-06 22:35:19 -0500954 case CHIP_VEGA12:
Feifei Xuf980d122018-01-26 15:10:55 +0800955 case CHIP_VEGA20:
Alex Deucherbf383fb2017-12-08 13:07:58 -0500956 adev->nbio_funcs->update_medium_grain_clock_gating(adev,
Ken Wang220ab9b2017-03-06 14:49:53 -0500957 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucherbf383fb2017-12-08 13:07:58 -0500958 adev->nbio_funcs->update_medium_grain_light_sleep(adev,
Ken Wang220ab9b2017-03-06 14:49:53 -0500959 state == AMD_CG_STATE_GATE ? true : false);
960 soc15_update_hdp_light_sleep(adev,
961 state == AMD_CG_STATE_GATE ? true : false);
962 soc15_update_drm_clock_gating(adev,
963 state == AMD_CG_STATE_GATE ? true : false);
964 soc15_update_drm_light_sleep(adev,
965 state == AMD_CG_STATE_GATE ? true : false);
966 soc15_update_rom_medium_grain_clock_gating(adev,
967 state == AMD_CG_STATE_GATE ? true : false);
Hawking Zhang070706c2018-03-28 17:08:04 +0800968 adev->df_funcs->update_medium_grain_clock_gating(adev,
Ken Wang220ab9b2017-03-06 14:49:53 -0500969 state == AMD_CG_STATE_GATE ? true : false);
970 break;
Huang Rui9e5a9eb2017-01-18 18:12:59 +0800971 case CHIP_RAVEN:
Likun Gaoad5a67a2018-07-10 20:22:36 +0800972 case CHIP_PICASSO:
Alex Deucherbf383fb2017-12-08 13:07:58 -0500973 adev->nbio_funcs->update_medium_grain_clock_gating(adev,
Huang Rui9e5a9eb2017-01-18 18:12:59 +0800974 state == AMD_CG_STATE_GATE ? true : false);
Alex Deucherbf383fb2017-12-08 13:07:58 -0500975 adev->nbio_funcs->update_medium_grain_light_sleep(adev,
Huang Rui9e5a9eb2017-01-18 18:12:59 +0800976 state == AMD_CG_STATE_GATE ? true : false);
977 soc15_update_hdp_light_sleep(adev,
978 state == AMD_CG_STATE_GATE ? true : false);
979 soc15_update_drm_clock_gating(adev,
980 state == AMD_CG_STATE_GATE ? true : false);
981 soc15_update_drm_light_sleep(adev,
982 state == AMD_CG_STATE_GATE ? true : false);
983 soc15_update_rom_medium_grain_clock_gating(adev,
984 state == AMD_CG_STATE_GATE ? true : false);
985 break;
Ken Wang220ab9b2017-03-06 14:49:53 -0500986 default:
987 break;
988 }
989 return 0;
990}
991
Huang Ruif9abe352017-03-24 10:46:16 +0800992static void soc15_common_get_clockgating_state(void *handle, u32 *flags)
993{
994 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
995 int data;
996
997 if (amdgpu_sriov_vf(adev))
998 *flags = 0;
999
Alex Deucherbf383fb2017-12-08 13:07:58 -05001000 adev->nbio_funcs->get_clockgating_state(adev, flags);
Huang Ruif9abe352017-03-24 10:46:16 +08001001
1002 /* AMD_CG_SUPPORT_HDP_LS */
1003 data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
1004 if (data & HDP_MEM_POWER_LS__LS_ENABLE_MASK)
1005 *flags |= AMD_CG_SUPPORT_HDP_LS;
1006
1007 /* AMD_CG_SUPPORT_DRM_MGCG */
1008 data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
1009 if (!(data & 0x01000000))
1010 *flags |= AMD_CG_SUPPORT_DRM_MGCG;
1011
1012 /* AMD_CG_SUPPORT_DRM_LS */
1013 data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
1014 if (data & 0x1)
1015 *flags |= AMD_CG_SUPPORT_DRM_LS;
1016
1017 /* AMD_CG_SUPPORT_ROM_MGCG */
1018 data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
1019 if (!(data & CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK))
1020 *flags |= AMD_CG_SUPPORT_ROM_MGCG;
1021
Hawking Zhang070706c2018-03-28 17:08:04 +08001022 adev->df_funcs->get_clockgating_state(adev, flags);
Huang Ruif9abe352017-03-24 10:46:16 +08001023}
1024
Ken Wang220ab9b2017-03-06 14:49:53 -05001025static int soc15_common_set_powergating_state(void *handle,
1026 enum amd_powergating_state state)
1027{
1028 /* todo */
1029 return 0;
1030}
1031
1032const struct amd_ip_funcs soc15_common_ip_funcs = {
1033 .name = "soc15_common",
1034 .early_init = soc15_common_early_init,
Monk Liu81758c52017-04-05 13:04:50 +08001035 .late_init = soc15_common_late_init,
Ken Wang220ab9b2017-03-06 14:49:53 -05001036 .sw_init = soc15_common_sw_init,
1037 .sw_fini = soc15_common_sw_fini,
1038 .hw_init = soc15_common_hw_init,
1039 .hw_fini = soc15_common_hw_fini,
1040 .suspend = soc15_common_suspend,
1041 .resume = soc15_common_resume,
1042 .is_idle = soc15_common_is_idle,
1043 .wait_for_idle = soc15_common_wait_for_idle,
1044 .soft_reset = soc15_common_soft_reset,
1045 .set_clockgating_state = soc15_common_set_clockgating_state,
1046 .set_powergating_state = soc15_common_set_powergating_state,
Huang Ruif9abe352017-03-24 10:46:16 +08001047 .get_clockgating_state= soc15_common_get_clockgating_state,
Ken Wang220ab9b2017-03-06 14:49:53 -05001048};