Loading...
1/*
2 * Copyright 2012 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 * Authors: Alex Deucher
23 */
24#include <linux/firmware.h>
25#include <linux/slab.h>
26#include <linux/module.h>
27#include "drmP.h"
28#include "amdgpu.h"
29#include "amdgpu_atombios.h"
30#include "amdgpu_ih.h"
31#include "amdgpu_uvd.h"
32#include "amdgpu_vce.h"
33#include "cikd.h"
34#include "atom.h"
35#include "amd_pcie.h"
36
37#include "cik.h"
38#include "gmc_v7_0.h"
39#include "cik_ih.h"
40#include "dce_v8_0.h"
41#include "gfx_v7_0.h"
42#include "cik_sdma.h"
43#include "uvd_v4_2.h"
44#include "vce_v2_0.h"
45#include "cik_dpm.h"
46
47#include "uvd/uvd_4_2_d.h"
48
49#include "smu/smu_7_0_1_d.h"
50#include "smu/smu_7_0_1_sh_mask.h"
51
52#include "dce/dce_8_0_d.h"
53#include "dce/dce_8_0_sh_mask.h"
54
55#include "bif/bif_4_1_d.h"
56#include "bif/bif_4_1_sh_mask.h"
57
58#include "gca/gfx_7_2_d.h"
59#include "gca/gfx_7_2_enum.h"
60#include "gca/gfx_7_2_sh_mask.h"
61
62#include "gmc/gmc_7_1_d.h"
63#include "gmc/gmc_7_1_sh_mask.h"
64
65#include "oss/oss_2_0_d.h"
66#include "oss/oss_2_0_sh_mask.h"
67
68#include "amdgpu_amdkfd.h"
69#include "amdgpu_powerplay.h"
70
71/*
72 * Indirect registers accessor
73 */
74static u32 cik_pcie_rreg(struct amdgpu_device *adev, u32 reg)
75{
76 unsigned long flags;
77 u32 r;
78
79 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
80 WREG32(mmPCIE_INDEX, reg);
81 (void)RREG32(mmPCIE_INDEX);
82 r = RREG32(mmPCIE_DATA);
83 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
84 return r;
85}
86
87static void cik_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
88{
89 unsigned long flags;
90
91 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
92 WREG32(mmPCIE_INDEX, reg);
93 (void)RREG32(mmPCIE_INDEX);
94 WREG32(mmPCIE_DATA, v);
95 (void)RREG32(mmPCIE_DATA);
96 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
97}
98
99static u32 cik_smc_rreg(struct amdgpu_device *adev, u32 reg)
100{
101 unsigned long flags;
102 u32 r;
103
104 spin_lock_irqsave(&adev->smc_idx_lock, flags);
105 WREG32(mmSMC_IND_INDEX_0, (reg));
106 r = RREG32(mmSMC_IND_DATA_0);
107 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
108 return r;
109}
110
111static void cik_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
112{
113 unsigned long flags;
114
115 spin_lock_irqsave(&adev->smc_idx_lock, flags);
116 WREG32(mmSMC_IND_INDEX_0, (reg));
117 WREG32(mmSMC_IND_DATA_0, (v));
118 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
119}
120
121static u32 cik_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
122{
123 unsigned long flags;
124 u32 r;
125
126 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
127 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
128 r = RREG32(mmUVD_CTX_DATA);
129 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
130 return r;
131}
132
133static void cik_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
134{
135 unsigned long flags;
136
137 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
138 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
139 WREG32(mmUVD_CTX_DATA, (v));
140 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
141}
142
143static u32 cik_didt_rreg(struct amdgpu_device *adev, u32 reg)
144{
145 unsigned long flags;
146 u32 r;
147
148 spin_lock_irqsave(&adev->didt_idx_lock, flags);
149 WREG32(mmDIDT_IND_INDEX, (reg));
150 r = RREG32(mmDIDT_IND_DATA);
151 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
152 return r;
153}
154
155static void cik_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
156{
157 unsigned long flags;
158
159 spin_lock_irqsave(&adev->didt_idx_lock, flags);
160 WREG32(mmDIDT_IND_INDEX, (reg));
161 WREG32(mmDIDT_IND_DATA, (v));
162 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
163}
164
165static const u32 bonaire_golden_spm_registers[] =
166{
167 0xc200, 0xe0ffffff, 0xe0000000
168};
169
170static const u32 bonaire_golden_common_registers[] =
171{
172 0x31dc, 0xffffffff, 0x00000800,
173 0x31dd, 0xffffffff, 0x00000800,
174 0x31e6, 0xffffffff, 0x00007fbf,
175 0x31e7, 0xffffffff, 0x00007faf
176};
177
178static const u32 bonaire_golden_registers[] =
179{
180 0xcd5, 0x00000333, 0x00000333,
181 0xcd4, 0x000c0fc0, 0x00040200,
182 0x2684, 0x00010000, 0x00058208,
183 0xf000, 0xffff1fff, 0x00140000,
184 0xf080, 0xfdfc0fff, 0x00000100,
185 0xf08d, 0x40000000, 0x40000200,
186 0x260c, 0xffffffff, 0x00000000,
187 0x260d, 0xf00fffff, 0x00000400,
188 0x260e, 0x0002021c, 0x00020200,
189 0x31e, 0x00000080, 0x00000000,
190 0x16ec, 0x000000f0, 0x00000070,
191 0x16f0, 0xf0311fff, 0x80300000,
192 0x263e, 0x73773777, 0x12010001,
193 0xd43, 0x00810000, 0x408af000,
194 0x1c0c, 0x31000111, 0x00000011,
195 0xbd2, 0x73773777, 0x12010001,
196 0x883, 0x00007fb6, 0x0021a1b1,
197 0x884, 0x00007fb6, 0x002021b1,
198 0x860, 0x00007fb6, 0x00002191,
199 0x886, 0x00007fb6, 0x002121b1,
200 0x887, 0x00007fb6, 0x002021b1,
201 0x877, 0x00007fb6, 0x00002191,
202 0x878, 0x00007fb6, 0x00002191,
203 0xd8a, 0x0000003f, 0x0000000a,
204 0xd8b, 0x0000003f, 0x0000000a,
205 0xab9, 0x00073ffe, 0x000022a2,
206 0x903, 0x000007ff, 0x00000000,
207 0x2285, 0xf000003f, 0x00000007,
208 0x22fc, 0x00002001, 0x00000001,
209 0x22c9, 0xffffffff, 0x00ffffff,
210 0xc281, 0x0000ff0f, 0x00000000,
211 0xa293, 0x07ffffff, 0x06000000,
212 0x136, 0x00000fff, 0x00000100,
213 0xf9e, 0x00000001, 0x00000002,
214 0x2440, 0x03000000, 0x0362c688,
215 0x2300, 0x000000ff, 0x00000001,
216 0x390, 0x00001fff, 0x00001fff,
217 0x2418, 0x0000007f, 0x00000020,
218 0x2542, 0x00010000, 0x00010000,
219 0x2b05, 0x000003ff, 0x000000f3,
220 0x2b03, 0xffffffff, 0x00001032
221};
222
223static const u32 bonaire_mgcg_cgcg_init[] =
224{
225 0x3108, 0xffffffff, 0xfffffffc,
226 0xc200, 0xffffffff, 0xe0000000,
227 0xf0a8, 0xffffffff, 0x00000100,
228 0xf082, 0xffffffff, 0x00000100,
229 0xf0b0, 0xffffffff, 0xc0000100,
230 0xf0b2, 0xffffffff, 0xc0000100,
231 0xf0b1, 0xffffffff, 0xc0000100,
232 0x1579, 0xffffffff, 0x00600100,
233 0xf0a0, 0xffffffff, 0x00000100,
234 0xf085, 0xffffffff, 0x06000100,
235 0xf088, 0xffffffff, 0x00000100,
236 0xf086, 0xffffffff, 0x06000100,
237 0xf081, 0xffffffff, 0x00000100,
238 0xf0b8, 0xffffffff, 0x00000100,
239 0xf089, 0xffffffff, 0x00000100,
240 0xf080, 0xffffffff, 0x00000100,
241 0xf08c, 0xffffffff, 0x00000100,
242 0xf08d, 0xffffffff, 0x00000100,
243 0xf094, 0xffffffff, 0x00000100,
244 0xf095, 0xffffffff, 0x00000100,
245 0xf096, 0xffffffff, 0x00000100,
246 0xf097, 0xffffffff, 0x00000100,
247 0xf098, 0xffffffff, 0x00000100,
248 0xf09f, 0xffffffff, 0x00000100,
249 0xf09e, 0xffffffff, 0x00000100,
250 0xf084, 0xffffffff, 0x06000100,
251 0xf0a4, 0xffffffff, 0x00000100,
252 0xf09d, 0xffffffff, 0x00000100,
253 0xf0ad, 0xffffffff, 0x00000100,
254 0xf0ac, 0xffffffff, 0x00000100,
255 0xf09c, 0xffffffff, 0x00000100,
256 0xc200, 0xffffffff, 0xe0000000,
257 0xf008, 0xffffffff, 0x00010000,
258 0xf009, 0xffffffff, 0x00030002,
259 0xf00a, 0xffffffff, 0x00040007,
260 0xf00b, 0xffffffff, 0x00060005,
261 0xf00c, 0xffffffff, 0x00090008,
262 0xf00d, 0xffffffff, 0x00010000,
263 0xf00e, 0xffffffff, 0x00030002,
264 0xf00f, 0xffffffff, 0x00040007,
265 0xf010, 0xffffffff, 0x00060005,
266 0xf011, 0xffffffff, 0x00090008,
267 0xf012, 0xffffffff, 0x00010000,
268 0xf013, 0xffffffff, 0x00030002,
269 0xf014, 0xffffffff, 0x00040007,
270 0xf015, 0xffffffff, 0x00060005,
271 0xf016, 0xffffffff, 0x00090008,
272 0xf017, 0xffffffff, 0x00010000,
273 0xf018, 0xffffffff, 0x00030002,
274 0xf019, 0xffffffff, 0x00040007,
275 0xf01a, 0xffffffff, 0x00060005,
276 0xf01b, 0xffffffff, 0x00090008,
277 0xf01c, 0xffffffff, 0x00010000,
278 0xf01d, 0xffffffff, 0x00030002,
279 0xf01e, 0xffffffff, 0x00040007,
280 0xf01f, 0xffffffff, 0x00060005,
281 0xf020, 0xffffffff, 0x00090008,
282 0xf021, 0xffffffff, 0x00010000,
283 0xf022, 0xffffffff, 0x00030002,
284 0xf023, 0xffffffff, 0x00040007,
285 0xf024, 0xffffffff, 0x00060005,
286 0xf025, 0xffffffff, 0x00090008,
287 0xf026, 0xffffffff, 0x00010000,
288 0xf027, 0xffffffff, 0x00030002,
289 0xf028, 0xffffffff, 0x00040007,
290 0xf029, 0xffffffff, 0x00060005,
291 0xf02a, 0xffffffff, 0x00090008,
292 0xf000, 0xffffffff, 0x96e00200,
293 0x21c2, 0xffffffff, 0x00900100,
294 0x3109, 0xffffffff, 0x0020003f,
295 0xe, 0xffffffff, 0x0140001c,
296 0xf, 0x000f0000, 0x000f0000,
297 0x88, 0xffffffff, 0xc060000c,
298 0x89, 0xc0000fff, 0x00000100,
299 0x3e4, 0xffffffff, 0x00000100,
300 0x3e6, 0x00000101, 0x00000000,
301 0x82a, 0xffffffff, 0x00000104,
302 0x1579, 0xff000fff, 0x00000100,
303 0xc33, 0xc0000fff, 0x00000104,
304 0x3079, 0x00000001, 0x00000001,
305 0x3403, 0xff000ff0, 0x00000100,
306 0x3603, 0xff000ff0, 0x00000100
307};
308
309static const u32 spectre_golden_spm_registers[] =
310{
311 0xc200, 0xe0ffffff, 0xe0000000
312};
313
314static const u32 spectre_golden_common_registers[] =
315{
316 0x31dc, 0xffffffff, 0x00000800,
317 0x31dd, 0xffffffff, 0x00000800,
318 0x31e6, 0xffffffff, 0x00007fbf,
319 0x31e7, 0xffffffff, 0x00007faf
320};
321
322static const u32 spectre_golden_registers[] =
323{
324 0xf000, 0xffff1fff, 0x96940200,
325 0xf003, 0xffff0001, 0xff000000,
326 0xf080, 0xfffc0fff, 0x00000100,
327 0x1bb6, 0x00010101, 0x00010000,
328 0x260d, 0xf00fffff, 0x00000400,
329 0x260e, 0xfffffffc, 0x00020200,
330 0x16ec, 0x000000f0, 0x00000070,
331 0x16f0, 0xf0311fff, 0x80300000,
332 0x263e, 0x73773777, 0x12010001,
333 0x26df, 0x00ff0000, 0x00fc0000,
334 0xbd2, 0x73773777, 0x12010001,
335 0x2285, 0xf000003f, 0x00000007,
336 0x22c9, 0xffffffff, 0x00ffffff,
337 0xa0d4, 0x3f3f3fff, 0x00000082,
338 0xa0d5, 0x0000003f, 0x00000000,
339 0xf9e, 0x00000001, 0x00000002,
340 0x244f, 0xffff03df, 0x00000004,
341 0x31da, 0x00000008, 0x00000008,
342 0x2300, 0x000008ff, 0x00000800,
343 0x2542, 0x00010000, 0x00010000,
344 0x2b03, 0xffffffff, 0x54763210,
345 0x853e, 0x01ff01ff, 0x00000002,
346 0x8526, 0x007ff800, 0x00200000,
347 0x8057, 0xffffffff, 0x00000f40,
348 0xc24d, 0xffffffff, 0x00000001
349};
350
351static const u32 spectre_mgcg_cgcg_init[] =
352{
353 0x3108, 0xffffffff, 0xfffffffc,
354 0xc200, 0xffffffff, 0xe0000000,
355 0xf0a8, 0xffffffff, 0x00000100,
356 0xf082, 0xffffffff, 0x00000100,
357 0xf0b0, 0xffffffff, 0x00000100,
358 0xf0b2, 0xffffffff, 0x00000100,
359 0xf0b1, 0xffffffff, 0x00000100,
360 0x1579, 0xffffffff, 0x00600100,
361 0xf0a0, 0xffffffff, 0x00000100,
362 0xf085, 0xffffffff, 0x06000100,
363 0xf088, 0xffffffff, 0x00000100,
364 0xf086, 0xffffffff, 0x06000100,
365 0xf081, 0xffffffff, 0x00000100,
366 0xf0b8, 0xffffffff, 0x00000100,
367 0xf089, 0xffffffff, 0x00000100,
368 0xf080, 0xffffffff, 0x00000100,
369 0xf08c, 0xffffffff, 0x00000100,
370 0xf08d, 0xffffffff, 0x00000100,
371 0xf094, 0xffffffff, 0x00000100,
372 0xf095, 0xffffffff, 0x00000100,
373 0xf096, 0xffffffff, 0x00000100,
374 0xf097, 0xffffffff, 0x00000100,
375 0xf098, 0xffffffff, 0x00000100,
376 0xf09f, 0xffffffff, 0x00000100,
377 0xf09e, 0xffffffff, 0x00000100,
378 0xf084, 0xffffffff, 0x06000100,
379 0xf0a4, 0xffffffff, 0x00000100,
380 0xf09d, 0xffffffff, 0x00000100,
381 0xf0ad, 0xffffffff, 0x00000100,
382 0xf0ac, 0xffffffff, 0x00000100,
383 0xf09c, 0xffffffff, 0x00000100,
384 0xc200, 0xffffffff, 0xe0000000,
385 0xf008, 0xffffffff, 0x00010000,
386 0xf009, 0xffffffff, 0x00030002,
387 0xf00a, 0xffffffff, 0x00040007,
388 0xf00b, 0xffffffff, 0x00060005,
389 0xf00c, 0xffffffff, 0x00090008,
390 0xf00d, 0xffffffff, 0x00010000,
391 0xf00e, 0xffffffff, 0x00030002,
392 0xf00f, 0xffffffff, 0x00040007,
393 0xf010, 0xffffffff, 0x00060005,
394 0xf011, 0xffffffff, 0x00090008,
395 0xf012, 0xffffffff, 0x00010000,
396 0xf013, 0xffffffff, 0x00030002,
397 0xf014, 0xffffffff, 0x00040007,
398 0xf015, 0xffffffff, 0x00060005,
399 0xf016, 0xffffffff, 0x00090008,
400 0xf017, 0xffffffff, 0x00010000,
401 0xf018, 0xffffffff, 0x00030002,
402 0xf019, 0xffffffff, 0x00040007,
403 0xf01a, 0xffffffff, 0x00060005,
404 0xf01b, 0xffffffff, 0x00090008,
405 0xf01c, 0xffffffff, 0x00010000,
406 0xf01d, 0xffffffff, 0x00030002,
407 0xf01e, 0xffffffff, 0x00040007,
408 0xf01f, 0xffffffff, 0x00060005,
409 0xf020, 0xffffffff, 0x00090008,
410 0xf021, 0xffffffff, 0x00010000,
411 0xf022, 0xffffffff, 0x00030002,
412 0xf023, 0xffffffff, 0x00040007,
413 0xf024, 0xffffffff, 0x00060005,
414 0xf025, 0xffffffff, 0x00090008,
415 0xf026, 0xffffffff, 0x00010000,
416 0xf027, 0xffffffff, 0x00030002,
417 0xf028, 0xffffffff, 0x00040007,
418 0xf029, 0xffffffff, 0x00060005,
419 0xf02a, 0xffffffff, 0x00090008,
420 0xf02b, 0xffffffff, 0x00010000,
421 0xf02c, 0xffffffff, 0x00030002,
422 0xf02d, 0xffffffff, 0x00040007,
423 0xf02e, 0xffffffff, 0x00060005,
424 0xf02f, 0xffffffff, 0x00090008,
425 0xf000, 0xffffffff, 0x96e00200,
426 0x21c2, 0xffffffff, 0x00900100,
427 0x3109, 0xffffffff, 0x0020003f,
428 0xe, 0xffffffff, 0x0140001c,
429 0xf, 0x000f0000, 0x000f0000,
430 0x88, 0xffffffff, 0xc060000c,
431 0x89, 0xc0000fff, 0x00000100,
432 0x3e4, 0xffffffff, 0x00000100,
433 0x3e6, 0x00000101, 0x00000000,
434 0x82a, 0xffffffff, 0x00000104,
435 0x1579, 0xff000fff, 0x00000100,
436 0xc33, 0xc0000fff, 0x00000104,
437 0x3079, 0x00000001, 0x00000001,
438 0x3403, 0xff000ff0, 0x00000100,
439 0x3603, 0xff000ff0, 0x00000100
440};
441
442static const u32 kalindi_golden_spm_registers[] =
443{
444 0xc200, 0xe0ffffff, 0xe0000000
445};
446
447static const u32 kalindi_golden_common_registers[] =
448{
449 0x31dc, 0xffffffff, 0x00000800,
450 0x31dd, 0xffffffff, 0x00000800,
451 0x31e6, 0xffffffff, 0x00007fbf,
452 0x31e7, 0xffffffff, 0x00007faf
453};
454
455static const u32 kalindi_golden_registers[] =
456{
457 0xf000, 0xffffdfff, 0x6e944040,
458 0x1579, 0xff607fff, 0xfc000100,
459 0xf088, 0xff000fff, 0x00000100,
460 0xf089, 0xff000fff, 0x00000100,
461 0xf080, 0xfffc0fff, 0x00000100,
462 0x1bb6, 0x00010101, 0x00010000,
463 0x260c, 0xffffffff, 0x00000000,
464 0x260d, 0xf00fffff, 0x00000400,
465 0x16ec, 0x000000f0, 0x00000070,
466 0x16f0, 0xf0311fff, 0x80300000,
467 0x263e, 0x73773777, 0x12010001,
468 0x263f, 0xffffffff, 0x00000010,
469 0x26df, 0x00ff0000, 0x00fc0000,
470 0x200c, 0x00001f0f, 0x0000100a,
471 0xbd2, 0x73773777, 0x12010001,
472 0x902, 0x000fffff, 0x000c007f,
473 0x2285, 0xf000003f, 0x00000007,
474 0x22c9, 0x3fff3fff, 0x00ffcfff,
475 0xc281, 0x0000ff0f, 0x00000000,
476 0xa293, 0x07ffffff, 0x06000000,
477 0x136, 0x00000fff, 0x00000100,
478 0xf9e, 0x00000001, 0x00000002,
479 0x31da, 0x00000008, 0x00000008,
480 0x2300, 0x000000ff, 0x00000003,
481 0x853e, 0x01ff01ff, 0x00000002,
482 0x8526, 0x007ff800, 0x00200000,
483 0x8057, 0xffffffff, 0x00000f40,
484 0x2231, 0x001f3ae3, 0x00000082,
485 0x2235, 0x0000001f, 0x00000010,
486 0xc24d, 0xffffffff, 0x00000000
487};
488
489static const u32 kalindi_mgcg_cgcg_init[] =
490{
491 0x3108, 0xffffffff, 0xfffffffc,
492 0xc200, 0xffffffff, 0xe0000000,
493 0xf0a8, 0xffffffff, 0x00000100,
494 0xf082, 0xffffffff, 0x00000100,
495 0xf0b0, 0xffffffff, 0x00000100,
496 0xf0b2, 0xffffffff, 0x00000100,
497 0xf0b1, 0xffffffff, 0x00000100,
498 0x1579, 0xffffffff, 0x00600100,
499 0xf0a0, 0xffffffff, 0x00000100,
500 0xf085, 0xffffffff, 0x06000100,
501 0xf088, 0xffffffff, 0x00000100,
502 0xf086, 0xffffffff, 0x06000100,
503 0xf081, 0xffffffff, 0x00000100,
504 0xf0b8, 0xffffffff, 0x00000100,
505 0xf089, 0xffffffff, 0x00000100,
506 0xf080, 0xffffffff, 0x00000100,
507 0xf08c, 0xffffffff, 0x00000100,
508 0xf08d, 0xffffffff, 0x00000100,
509 0xf094, 0xffffffff, 0x00000100,
510 0xf095, 0xffffffff, 0x00000100,
511 0xf096, 0xffffffff, 0x00000100,
512 0xf097, 0xffffffff, 0x00000100,
513 0xf098, 0xffffffff, 0x00000100,
514 0xf09f, 0xffffffff, 0x00000100,
515 0xf09e, 0xffffffff, 0x00000100,
516 0xf084, 0xffffffff, 0x06000100,
517 0xf0a4, 0xffffffff, 0x00000100,
518 0xf09d, 0xffffffff, 0x00000100,
519 0xf0ad, 0xffffffff, 0x00000100,
520 0xf0ac, 0xffffffff, 0x00000100,
521 0xf09c, 0xffffffff, 0x00000100,
522 0xc200, 0xffffffff, 0xe0000000,
523 0xf008, 0xffffffff, 0x00010000,
524 0xf009, 0xffffffff, 0x00030002,
525 0xf00a, 0xffffffff, 0x00040007,
526 0xf00b, 0xffffffff, 0x00060005,
527 0xf00c, 0xffffffff, 0x00090008,
528 0xf00d, 0xffffffff, 0x00010000,
529 0xf00e, 0xffffffff, 0x00030002,
530 0xf00f, 0xffffffff, 0x00040007,
531 0xf010, 0xffffffff, 0x00060005,
532 0xf011, 0xffffffff, 0x00090008,
533 0xf000, 0xffffffff, 0x96e00200,
534 0x21c2, 0xffffffff, 0x00900100,
535 0x3109, 0xffffffff, 0x0020003f,
536 0xe, 0xffffffff, 0x0140001c,
537 0xf, 0x000f0000, 0x000f0000,
538 0x88, 0xffffffff, 0xc060000c,
539 0x89, 0xc0000fff, 0x00000100,
540 0x82a, 0xffffffff, 0x00000104,
541 0x1579, 0xff000fff, 0x00000100,
542 0xc33, 0xc0000fff, 0x00000104,
543 0x3079, 0x00000001, 0x00000001,
544 0x3403, 0xff000ff0, 0x00000100,
545 0x3603, 0xff000ff0, 0x00000100
546};
547
548static const u32 hawaii_golden_spm_registers[] =
549{
550 0xc200, 0xe0ffffff, 0xe0000000
551};
552
553static const u32 hawaii_golden_common_registers[] =
554{
555 0xc200, 0xffffffff, 0xe0000000,
556 0xa0d4, 0xffffffff, 0x3a00161a,
557 0xa0d5, 0xffffffff, 0x0000002e,
558 0x2684, 0xffffffff, 0x00018208,
559 0x263e, 0xffffffff, 0x12011003
560};
561
562static const u32 hawaii_golden_registers[] =
563{
564 0xcd5, 0x00000333, 0x00000333,
565 0x2684, 0x00010000, 0x00058208,
566 0x260c, 0xffffffff, 0x00000000,
567 0x260d, 0xf00fffff, 0x00000400,
568 0x260e, 0x0002021c, 0x00020200,
569 0x31e, 0x00000080, 0x00000000,
570 0x16ec, 0x000000f0, 0x00000070,
571 0x16f0, 0xf0311fff, 0x80300000,
572 0xd43, 0x00810000, 0x408af000,
573 0x1c0c, 0x31000111, 0x00000011,
574 0xbd2, 0x73773777, 0x12010001,
575 0x848, 0x0000007f, 0x0000001b,
576 0x877, 0x00007fb6, 0x00002191,
577 0xd8a, 0x0000003f, 0x0000000a,
578 0xd8b, 0x0000003f, 0x0000000a,
579 0xab9, 0x00073ffe, 0x000022a2,
580 0x903, 0x000007ff, 0x00000000,
581 0x22fc, 0x00002001, 0x00000001,
582 0x22c9, 0xffffffff, 0x00ffffff,
583 0xc281, 0x0000ff0f, 0x00000000,
584 0xa293, 0x07ffffff, 0x06000000,
585 0xf9e, 0x00000001, 0x00000002,
586 0x31da, 0x00000008, 0x00000008,
587 0x31dc, 0x00000f00, 0x00000800,
588 0x31dd, 0x00000f00, 0x00000800,
589 0x31e6, 0x00ffffff, 0x00ff7fbf,
590 0x31e7, 0x00ffffff, 0x00ff7faf,
591 0x2300, 0x000000ff, 0x00000800,
592 0x390, 0x00001fff, 0x00001fff,
593 0x2418, 0x0000007f, 0x00000020,
594 0x2542, 0x00010000, 0x00010000,
595 0x2b80, 0x00100000, 0x000ff07c,
596 0x2b05, 0x000003ff, 0x0000000f,
597 0x2b04, 0xffffffff, 0x7564fdec,
598 0x2b03, 0xffffffff, 0x3120b9a8,
599 0x2b02, 0x20000000, 0x0f9c0000
600};
601
602static const u32 hawaii_mgcg_cgcg_init[] =
603{
604 0x3108, 0xffffffff, 0xfffffffd,
605 0xc200, 0xffffffff, 0xe0000000,
606 0xf0a8, 0xffffffff, 0x00000100,
607 0xf082, 0xffffffff, 0x00000100,
608 0xf0b0, 0xffffffff, 0x00000100,
609 0xf0b2, 0xffffffff, 0x00000100,
610 0xf0b1, 0xffffffff, 0x00000100,
611 0x1579, 0xffffffff, 0x00200100,
612 0xf0a0, 0xffffffff, 0x00000100,
613 0xf085, 0xffffffff, 0x06000100,
614 0xf088, 0xffffffff, 0x00000100,
615 0xf086, 0xffffffff, 0x06000100,
616 0xf081, 0xffffffff, 0x00000100,
617 0xf0b8, 0xffffffff, 0x00000100,
618 0xf089, 0xffffffff, 0x00000100,
619 0xf080, 0xffffffff, 0x00000100,
620 0xf08c, 0xffffffff, 0x00000100,
621 0xf08d, 0xffffffff, 0x00000100,
622 0xf094, 0xffffffff, 0x00000100,
623 0xf095, 0xffffffff, 0x00000100,
624 0xf096, 0xffffffff, 0x00000100,
625 0xf097, 0xffffffff, 0x00000100,
626 0xf098, 0xffffffff, 0x00000100,
627 0xf09f, 0xffffffff, 0x00000100,
628 0xf09e, 0xffffffff, 0x00000100,
629 0xf084, 0xffffffff, 0x06000100,
630 0xf0a4, 0xffffffff, 0x00000100,
631 0xf09d, 0xffffffff, 0x00000100,
632 0xf0ad, 0xffffffff, 0x00000100,
633 0xf0ac, 0xffffffff, 0x00000100,
634 0xf09c, 0xffffffff, 0x00000100,
635 0xc200, 0xffffffff, 0xe0000000,
636 0xf008, 0xffffffff, 0x00010000,
637 0xf009, 0xffffffff, 0x00030002,
638 0xf00a, 0xffffffff, 0x00040007,
639 0xf00b, 0xffffffff, 0x00060005,
640 0xf00c, 0xffffffff, 0x00090008,
641 0xf00d, 0xffffffff, 0x00010000,
642 0xf00e, 0xffffffff, 0x00030002,
643 0xf00f, 0xffffffff, 0x00040007,
644 0xf010, 0xffffffff, 0x00060005,
645 0xf011, 0xffffffff, 0x00090008,
646 0xf012, 0xffffffff, 0x00010000,
647 0xf013, 0xffffffff, 0x00030002,
648 0xf014, 0xffffffff, 0x00040007,
649 0xf015, 0xffffffff, 0x00060005,
650 0xf016, 0xffffffff, 0x00090008,
651 0xf017, 0xffffffff, 0x00010000,
652 0xf018, 0xffffffff, 0x00030002,
653 0xf019, 0xffffffff, 0x00040007,
654 0xf01a, 0xffffffff, 0x00060005,
655 0xf01b, 0xffffffff, 0x00090008,
656 0xf01c, 0xffffffff, 0x00010000,
657 0xf01d, 0xffffffff, 0x00030002,
658 0xf01e, 0xffffffff, 0x00040007,
659 0xf01f, 0xffffffff, 0x00060005,
660 0xf020, 0xffffffff, 0x00090008,
661 0xf021, 0xffffffff, 0x00010000,
662 0xf022, 0xffffffff, 0x00030002,
663 0xf023, 0xffffffff, 0x00040007,
664 0xf024, 0xffffffff, 0x00060005,
665 0xf025, 0xffffffff, 0x00090008,
666 0xf026, 0xffffffff, 0x00010000,
667 0xf027, 0xffffffff, 0x00030002,
668 0xf028, 0xffffffff, 0x00040007,
669 0xf029, 0xffffffff, 0x00060005,
670 0xf02a, 0xffffffff, 0x00090008,
671 0xf02b, 0xffffffff, 0x00010000,
672 0xf02c, 0xffffffff, 0x00030002,
673 0xf02d, 0xffffffff, 0x00040007,
674 0xf02e, 0xffffffff, 0x00060005,
675 0xf02f, 0xffffffff, 0x00090008,
676 0xf030, 0xffffffff, 0x00010000,
677 0xf031, 0xffffffff, 0x00030002,
678 0xf032, 0xffffffff, 0x00040007,
679 0xf033, 0xffffffff, 0x00060005,
680 0xf034, 0xffffffff, 0x00090008,
681 0xf035, 0xffffffff, 0x00010000,
682 0xf036, 0xffffffff, 0x00030002,
683 0xf037, 0xffffffff, 0x00040007,
684 0xf038, 0xffffffff, 0x00060005,
685 0xf039, 0xffffffff, 0x00090008,
686 0xf03a, 0xffffffff, 0x00010000,
687 0xf03b, 0xffffffff, 0x00030002,
688 0xf03c, 0xffffffff, 0x00040007,
689 0xf03d, 0xffffffff, 0x00060005,
690 0xf03e, 0xffffffff, 0x00090008,
691 0x30c6, 0xffffffff, 0x00020200,
692 0xcd4, 0xffffffff, 0x00000200,
693 0x570, 0xffffffff, 0x00000400,
694 0x157a, 0xffffffff, 0x00000000,
695 0xbd4, 0xffffffff, 0x00000902,
696 0xf000, 0xffffffff, 0x96940200,
697 0x21c2, 0xffffffff, 0x00900100,
698 0x3109, 0xffffffff, 0x0020003f,
699 0xe, 0xffffffff, 0x0140001c,
700 0xf, 0x000f0000, 0x000f0000,
701 0x88, 0xffffffff, 0xc060000c,
702 0x89, 0xc0000fff, 0x00000100,
703 0x3e4, 0xffffffff, 0x00000100,
704 0x3e6, 0x00000101, 0x00000000,
705 0x82a, 0xffffffff, 0x00000104,
706 0x1579, 0xff000fff, 0x00000100,
707 0xc33, 0xc0000fff, 0x00000104,
708 0x3079, 0x00000001, 0x00000001,
709 0x3403, 0xff000ff0, 0x00000100,
710 0x3603, 0xff000ff0, 0x00000100
711};
712
713static const u32 godavari_golden_registers[] =
714{
715 0x1579, 0xff607fff, 0xfc000100,
716 0x1bb6, 0x00010101, 0x00010000,
717 0x260c, 0xffffffff, 0x00000000,
718 0x260c0, 0xf00fffff, 0x00000400,
719 0x184c, 0xffffffff, 0x00010000,
720 0x16ec, 0x000000f0, 0x00000070,
721 0x16f0, 0xf0311fff, 0x80300000,
722 0x263e, 0x73773777, 0x12010001,
723 0x263f, 0xffffffff, 0x00000010,
724 0x200c, 0x00001f0f, 0x0000100a,
725 0xbd2, 0x73773777, 0x12010001,
726 0x902, 0x000fffff, 0x000c007f,
727 0x2285, 0xf000003f, 0x00000007,
728 0x22c9, 0xffffffff, 0x00ff0fff,
729 0xc281, 0x0000ff0f, 0x00000000,
730 0xa293, 0x07ffffff, 0x06000000,
731 0x136, 0x00000fff, 0x00000100,
732 0x3405, 0x00010000, 0x00810001,
733 0x3605, 0x00010000, 0x00810001,
734 0xf9e, 0x00000001, 0x00000002,
735 0x31da, 0x00000008, 0x00000008,
736 0x31dc, 0x00000f00, 0x00000800,
737 0x31dd, 0x00000f00, 0x00000800,
738 0x31e6, 0x00ffffff, 0x00ff7fbf,
739 0x31e7, 0x00ffffff, 0x00ff7faf,
740 0x2300, 0x000000ff, 0x00000001,
741 0x853e, 0x01ff01ff, 0x00000002,
742 0x8526, 0x007ff800, 0x00200000,
743 0x8057, 0xffffffff, 0x00000f40,
744 0x2231, 0x001f3ae3, 0x00000082,
745 0x2235, 0x0000001f, 0x00000010,
746 0xc24d, 0xffffffff, 0x00000000
747};
748
749static void cik_init_golden_registers(struct amdgpu_device *adev)
750{
751 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
752 mutex_lock(&adev->grbm_idx_mutex);
753
754 switch (adev->asic_type) {
755 case CHIP_BONAIRE:
756 amdgpu_program_register_sequence(adev,
757 bonaire_mgcg_cgcg_init,
758 (const u32)ARRAY_SIZE(bonaire_mgcg_cgcg_init));
759 amdgpu_program_register_sequence(adev,
760 bonaire_golden_registers,
761 (const u32)ARRAY_SIZE(bonaire_golden_registers));
762 amdgpu_program_register_sequence(adev,
763 bonaire_golden_common_registers,
764 (const u32)ARRAY_SIZE(bonaire_golden_common_registers));
765 amdgpu_program_register_sequence(adev,
766 bonaire_golden_spm_registers,
767 (const u32)ARRAY_SIZE(bonaire_golden_spm_registers));
768 break;
769 case CHIP_KABINI:
770 amdgpu_program_register_sequence(adev,
771 kalindi_mgcg_cgcg_init,
772 (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
773 amdgpu_program_register_sequence(adev,
774 kalindi_golden_registers,
775 (const u32)ARRAY_SIZE(kalindi_golden_registers));
776 amdgpu_program_register_sequence(adev,
777 kalindi_golden_common_registers,
778 (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
779 amdgpu_program_register_sequence(adev,
780 kalindi_golden_spm_registers,
781 (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
782 break;
783 case CHIP_MULLINS:
784 amdgpu_program_register_sequence(adev,
785 kalindi_mgcg_cgcg_init,
786 (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
787 amdgpu_program_register_sequence(adev,
788 godavari_golden_registers,
789 (const u32)ARRAY_SIZE(godavari_golden_registers));
790 amdgpu_program_register_sequence(adev,
791 kalindi_golden_common_registers,
792 (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
793 amdgpu_program_register_sequence(adev,
794 kalindi_golden_spm_registers,
795 (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
796 break;
797 case CHIP_KAVERI:
798 amdgpu_program_register_sequence(adev,
799 spectre_mgcg_cgcg_init,
800 (const u32)ARRAY_SIZE(spectre_mgcg_cgcg_init));
801 amdgpu_program_register_sequence(adev,
802 spectre_golden_registers,
803 (const u32)ARRAY_SIZE(spectre_golden_registers));
804 amdgpu_program_register_sequence(adev,
805 spectre_golden_common_registers,
806 (const u32)ARRAY_SIZE(spectre_golden_common_registers));
807 amdgpu_program_register_sequence(adev,
808 spectre_golden_spm_registers,
809 (const u32)ARRAY_SIZE(spectre_golden_spm_registers));
810 break;
811 case CHIP_HAWAII:
812 amdgpu_program_register_sequence(adev,
813 hawaii_mgcg_cgcg_init,
814 (const u32)ARRAY_SIZE(hawaii_mgcg_cgcg_init));
815 amdgpu_program_register_sequence(adev,
816 hawaii_golden_registers,
817 (const u32)ARRAY_SIZE(hawaii_golden_registers));
818 amdgpu_program_register_sequence(adev,
819 hawaii_golden_common_registers,
820 (const u32)ARRAY_SIZE(hawaii_golden_common_registers));
821 amdgpu_program_register_sequence(adev,
822 hawaii_golden_spm_registers,
823 (const u32)ARRAY_SIZE(hawaii_golden_spm_registers));
824 break;
825 default:
826 break;
827 }
828 mutex_unlock(&adev->grbm_idx_mutex);
829}
830
831/**
832 * cik_get_xclk - get the xclk
833 *
834 * @adev: amdgpu_device pointer
835 *
836 * Returns the reference clock used by the gfx engine
837 * (CIK).
838 */
839static u32 cik_get_xclk(struct amdgpu_device *adev)
840{
841 u32 reference_clock = adev->clock.spll.reference_freq;
842
843 if (adev->flags & AMD_IS_APU) {
844 if (RREG32_SMC(ixGENERAL_PWRMGT) & GENERAL_PWRMGT__GPU_COUNTER_CLK_MASK)
845 return reference_clock / 2;
846 } else {
847 if (RREG32_SMC(ixCG_CLKPIN_CNTL) & CG_CLKPIN_CNTL__XTALIN_DIVIDE_MASK)
848 return reference_clock / 4;
849 }
850 return reference_clock;
851}
852
853/**
854 * cik_srbm_select - select specific register instances
855 *
856 * @adev: amdgpu_device pointer
857 * @me: selected ME (micro engine)
858 * @pipe: pipe
859 * @queue: queue
860 * @vmid: VMID
861 *
862 * Switches the currently active registers instances. Some
863 * registers are instanced per VMID, others are instanced per
864 * me/pipe/queue combination.
865 */
866void cik_srbm_select(struct amdgpu_device *adev,
867 u32 me, u32 pipe, u32 queue, u32 vmid)
868{
869 u32 srbm_gfx_cntl =
870 (((pipe << SRBM_GFX_CNTL__PIPEID__SHIFT) & SRBM_GFX_CNTL__PIPEID_MASK)|
871 ((me << SRBM_GFX_CNTL__MEID__SHIFT) & SRBM_GFX_CNTL__MEID_MASK)|
872 ((vmid << SRBM_GFX_CNTL__VMID__SHIFT) & SRBM_GFX_CNTL__VMID_MASK)|
873 ((queue << SRBM_GFX_CNTL__QUEUEID__SHIFT) & SRBM_GFX_CNTL__QUEUEID_MASK));
874 WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
875}
876
877static void cik_vga_set_state(struct amdgpu_device *adev, bool state)
878{
879 uint32_t tmp;
880
881 tmp = RREG32(mmCONFIG_CNTL);
882 if (state == false)
883 tmp |= CONFIG_CNTL__VGA_DIS_MASK;
884 else
885 tmp &= ~CONFIG_CNTL__VGA_DIS_MASK;
886 WREG32(mmCONFIG_CNTL, tmp);
887}
888
889static bool cik_read_disabled_bios(struct amdgpu_device *adev)
890{
891 u32 bus_cntl;
892 u32 d1vga_control = 0;
893 u32 d2vga_control = 0;
894 u32 vga_render_control = 0;
895 u32 rom_cntl;
896 bool r;
897
898 bus_cntl = RREG32(mmBUS_CNTL);
899 if (adev->mode_info.num_crtc) {
900 d1vga_control = RREG32(mmD1VGA_CONTROL);
901 d2vga_control = RREG32(mmD2VGA_CONTROL);
902 vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
903 }
904 rom_cntl = RREG32_SMC(ixROM_CNTL);
905
906 /* enable the rom */
907 WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
908 if (adev->mode_info.num_crtc) {
909 /* Disable VGA mode */
910 WREG32(mmD1VGA_CONTROL,
911 (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
912 D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
913 WREG32(mmD2VGA_CONTROL,
914 (d2vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
915 D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
916 WREG32(mmVGA_RENDER_CONTROL,
917 (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
918 }
919 WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
920
921 r = amdgpu_read_bios(adev);
922
923 /* restore regs */
924 WREG32(mmBUS_CNTL, bus_cntl);
925 if (adev->mode_info.num_crtc) {
926 WREG32(mmD1VGA_CONTROL, d1vga_control);
927 WREG32(mmD2VGA_CONTROL, d2vga_control);
928 WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
929 }
930 WREG32_SMC(ixROM_CNTL, rom_cntl);
931 return r;
932}
933
934static bool cik_read_bios_from_rom(struct amdgpu_device *adev,
935 u8 *bios, u32 length_bytes)
936{
937 u32 *dw_ptr;
938 unsigned long flags;
939 u32 i, length_dw;
940
941 if (bios == NULL)
942 return false;
943 if (length_bytes == 0)
944 return false;
945 /* APU vbios image is part of sbios image */
946 if (adev->flags & AMD_IS_APU)
947 return false;
948
949 dw_ptr = (u32 *)bios;
950 length_dw = ALIGN(length_bytes, 4) / 4;
951 /* take the smc lock since we are using the smc index */
952 spin_lock_irqsave(&adev->smc_idx_lock, flags);
953 /* set rom index to 0 */
954 WREG32(mmSMC_IND_INDEX_0, ixROM_INDEX);
955 WREG32(mmSMC_IND_DATA_0, 0);
956 /* set index to data for continous read */
957 WREG32(mmSMC_IND_INDEX_0, ixROM_DATA);
958 for (i = 0; i < length_dw; i++)
959 dw_ptr[i] = RREG32(mmSMC_IND_DATA_0);
960 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
961
962 return true;
963}
964
965static struct amdgpu_allowed_register_entry cik_allowed_read_registers[] = {
966 {mmGRBM_STATUS, false},
967 {mmGB_ADDR_CONFIG, false},
968 {mmMC_ARB_RAMCFG, false},
969 {mmGB_TILE_MODE0, false},
970 {mmGB_TILE_MODE1, false},
971 {mmGB_TILE_MODE2, false},
972 {mmGB_TILE_MODE3, false},
973 {mmGB_TILE_MODE4, false},
974 {mmGB_TILE_MODE5, false},
975 {mmGB_TILE_MODE6, false},
976 {mmGB_TILE_MODE7, false},
977 {mmGB_TILE_MODE8, false},
978 {mmGB_TILE_MODE9, false},
979 {mmGB_TILE_MODE10, false},
980 {mmGB_TILE_MODE11, false},
981 {mmGB_TILE_MODE12, false},
982 {mmGB_TILE_MODE13, false},
983 {mmGB_TILE_MODE14, false},
984 {mmGB_TILE_MODE15, false},
985 {mmGB_TILE_MODE16, false},
986 {mmGB_TILE_MODE17, false},
987 {mmGB_TILE_MODE18, false},
988 {mmGB_TILE_MODE19, false},
989 {mmGB_TILE_MODE20, false},
990 {mmGB_TILE_MODE21, false},
991 {mmGB_TILE_MODE22, false},
992 {mmGB_TILE_MODE23, false},
993 {mmGB_TILE_MODE24, false},
994 {mmGB_TILE_MODE25, false},
995 {mmGB_TILE_MODE26, false},
996 {mmGB_TILE_MODE27, false},
997 {mmGB_TILE_MODE28, false},
998 {mmGB_TILE_MODE29, false},
999 {mmGB_TILE_MODE30, false},
1000 {mmGB_TILE_MODE31, false},
1001 {mmGB_MACROTILE_MODE0, false},
1002 {mmGB_MACROTILE_MODE1, false},
1003 {mmGB_MACROTILE_MODE2, false},
1004 {mmGB_MACROTILE_MODE3, false},
1005 {mmGB_MACROTILE_MODE4, false},
1006 {mmGB_MACROTILE_MODE5, false},
1007 {mmGB_MACROTILE_MODE6, false},
1008 {mmGB_MACROTILE_MODE7, false},
1009 {mmGB_MACROTILE_MODE8, false},
1010 {mmGB_MACROTILE_MODE9, false},
1011 {mmGB_MACROTILE_MODE10, false},
1012 {mmGB_MACROTILE_MODE11, false},
1013 {mmGB_MACROTILE_MODE12, false},
1014 {mmGB_MACROTILE_MODE13, false},
1015 {mmGB_MACROTILE_MODE14, false},
1016 {mmGB_MACROTILE_MODE15, false},
1017 {mmCC_RB_BACKEND_DISABLE, false, true},
1018 {mmGC_USER_RB_BACKEND_DISABLE, false, true},
1019 {mmGB_BACKEND_MAP, false, false},
1020 {mmPA_SC_RASTER_CONFIG, false, true},
1021 {mmPA_SC_RASTER_CONFIG_1, false, true},
1022};
1023
1024static uint32_t cik_read_indexed_register(struct amdgpu_device *adev,
1025 u32 se_num, u32 sh_num,
1026 u32 reg_offset)
1027{
1028 uint32_t val;
1029
1030 mutex_lock(&adev->grbm_idx_mutex);
1031 if (se_num != 0xffffffff || sh_num != 0xffffffff)
1032 gfx_v7_0_select_se_sh(adev, se_num, sh_num);
1033
1034 val = RREG32(reg_offset);
1035
1036 if (se_num != 0xffffffff || sh_num != 0xffffffff)
1037 gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff);
1038 mutex_unlock(&adev->grbm_idx_mutex);
1039 return val;
1040}
1041
1042static int cik_read_register(struct amdgpu_device *adev, u32 se_num,
1043 u32 sh_num, u32 reg_offset, u32 *value)
1044{
1045 uint32_t i;
1046
1047 *value = 0;
1048 for (i = 0; i < ARRAY_SIZE(cik_allowed_read_registers); i++) {
1049 if (reg_offset != cik_allowed_read_registers[i].reg_offset)
1050 continue;
1051
1052 if (!cik_allowed_read_registers[i].untouched)
1053 *value = cik_allowed_read_registers[i].grbm_indexed ?
1054 cik_read_indexed_register(adev, se_num,
1055 sh_num, reg_offset) :
1056 RREG32(reg_offset);
1057 return 0;
1058 }
1059 return -EINVAL;
1060}
1061
1062struct kv_reset_save_regs {
1063 u32 gmcon_reng_execute;
1064 u32 gmcon_misc;
1065 u32 gmcon_misc3;
1066};
1067
1068static void kv_save_regs_for_reset(struct amdgpu_device *adev,
1069 struct kv_reset_save_regs *save)
1070{
1071 save->gmcon_reng_execute = RREG32(mmGMCON_RENG_EXECUTE);
1072 save->gmcon_misc = RREG32(mmGMCON_MISC);
1073 save->gmcon_misc3 = RREG32(mmGMCON_MISC3);
1074
1075 WREG32(mmGMCON_RENG_EXECUTE, save->gmcon_reng_execute &
1076 ~GMCON_RENG_EXECUTE__RENG_EXECUTE_ON_PWR_UP_MASK);
1077 WREG32(mmGMCON_MISC, save->gmcon_misc &
1078 ~(GMCON_MISC__RENG_EXECUTE_ON_REG_UPDATE_MASK |
1079 GMCON_MISC__STCTRL_STUTTER_EN_MASK));
1080}
1081
1082static void kv_restore_regs_for_reset(struct amdgpu_device *adev,
1083 struct kv_reset_save_regs *save)
1084{
1085 int i;
1086
1087 WREG32(mmGMCON_PGFSM_WRITE, 0);
1088 WREG32(mmGMCON_PGFSM_CONFIG, 0x200010ff);
1089
1090 for (i = 0; i < 5; i++)
1091 WREG32(mmGMCON_PGFSM_WRITE, 0);
1092
1093 WREG32(mmGMCON_PGFSM_WRITE, 0);
1094 WREG32(mmGMCON_PGFSM_CONFIG, 0x300010ff);
1095
1096 for (i = 0; i < 5; i++)
1097 WREG32(mmGMCON_PGFSM_WRITE, 0);
1098
1099 WREG32(mmGMCON_PGFSM_WRITE, 0x210000);
1100 WREG32(mmGMCON_PGFSM_CONFIG, 0xa00010ff);
1101
1102 for (i = 0; i < 5; i++)
1103 WREG32(mmGMCON_PGFSM_WRITE, 0);
1104
1105 WREG32(mmGMCON_PGFSM_WRITE, 0x21003);
1106 WREG32(mmGMCON_PGFSM_CONFIG, 0xb00010ff);
1107
1108 for (i = 0; i < 5; i++)
1109 WREG32(mmGMCON_PGFSM_WRITE, 0);
1110
1111 WREG32(mmGMCON_PGFSM_WRITE, 0x2b00);
1112 WREG32(mmGMCON_PGFSM_CONFIG, 0xc00010ff);
1113
1114 for (i = 0; i < 5; i++)
1115 WREG32(mmGMCON_PGFSM_WRITE, 0);
1116
1117 WREG32(mmGMCON_PGFSM_WRITE, 0);
1118 WREG32(mmGMCON_PGFSM_CONFIG, 0xd00010ff);
1119
1120 for (i = 0; i < 5; i++)
1121 WREG32(mmGMCON_PGFSM_WRITE, 0);
1122
1123 WREG32(mmGMCON_PGFSM_WRITE, 0x420000);
1124 WREG32(mmGMCON_PGFSM_CONFIG, 0x100010ff);
1125
1126 for (i = 0; i < 5; i++)
1127 WREG32(mmGMCON_PGFSM_WRITE, 0);
1128
1129 WREG32(mmGMCON_PGFSM_WRITE, 0x120202);
1130 WREG32(mmGMCON_PGFSM_CONFIG, 0x500010ff);
1131
1132 for (i = 0; i < 5; i++)
1133 WREG32(mmGMCON_PGFSM_WRITE, 0);
1134
1135 WREG32(mmGMCON_PGFSM_WRITE, 0x3e3e36);
1136 WREG32(mmGMCON_PGFSM_CONFIG, 0x600010ff);
1137
1138 for (i = 0; i < 5; i++)
1139 WREG32(mmGMCON_PGFSM_WRITE, 0);
1140
1141 WREG32(mmGMCON_PGFSM_WRITE, 0x373f3e);
1142 WREG32(mmGMCON_PGFSM_CONFIG, 0x700010ff);
1143
1144 for (i = 0; i < 5; i++)
1145 WREG32(mmGMCON_PGFSM_WRITE, 0);
1146
1147 WREG32(mmGMCON_PGFSM_WRITE, 0x3e1332);
1148 WREG32(mmGMCON_PGFSM_CONFIG, 0xe00010ff);
1149
1150 WREG32(mmGMCON_MISC3, save->gmcon_misc3);
1151 WREG32(mmGMCON_MISC, save->gmcon_misc);
1152 WREG32(mmGMCON_RENG_EXECUTE, save->gmcon_reng_execute);
1153}
1154
1155static void cik_gpu_pci_config_reset(struct amdgpu_device *adev)
1156{
1157 struct kv_reset_save_regs kv_save = { 0 };
1158 u32 i;
1159
1160 dev_info(adev->dev, "GPU pci config reset\n");
1161
1162 if (adev->flags & AMD_IS_APU)
1163 kv_save_regs_for_reset(adev, &kv_save);
1164
1165 /* disable BM */
1166 pci_clear_master(adev->pdev);
1167 /* reset */
1168 amdgpu_pci_config_reset(adev);
1169
1170 udelay(100);
1171
1172 /* wait for asic to come out of reset */
1173 for (i = 0; i < adev->usec_timeout; i++) {
1174 if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff)
1175 break;
1176 udelay(1);
1177 }
1178
1179 /* does asic init need to be run first??? */
1180 if (adev->flags & AMD_IS_APU)
1181 kv_restore_regs_for_reset(adev, &kv_save);
1182}
1183
1184static void cik_set_bios_scratch_engine_hung(struct amdgpu_device *adev, bool hung)
1185{
1186 u32 tmp = RREG32(mmBIOS_SCRATCH_3);
1187
1188 if (hung)
1189 tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
1190 else
1191 tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
1192
1193 WREG32(mmBIOS_SCRATCH_3, tmp);
1194}
1195
1196/**
1197 * cik_asic_reset - soft reset GPU
1198 *
1199 * @adev: amdgpu_device pointer
1200 *
1201 * Look up which blocks are hung and attempt
1202 * to reset them.
1203 * Returns 0 for success.
1204 */
1205static int cik_asic_reset(struct amdgpu_device *adev)
1206{
1207 cik_set_bios_scratch_engine_hung(adev, true);
1208
1209 cik_gpu_pci_config_reset(adev);
1210
1211 cik_set_bios_scratch_engine_hung(adev, false);
1212
1213 return 0;
1214}
1215
1216static int cik_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
1217 u32 cntl_reg, u32 status_reg)
1218{
1219 int r, i;
1220 struct atom_clock_dividers dividers;
1221 uint32_t tmp;
1222
1223 r = amdgpu_atombios_get_clock_dividers(adev,
1224 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
1225 clock, false, ÷rs);
1226 if (r)
1227 return r;
1228
1229 tmp = RREG32_SMC(cntl_reg);
1230 tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
1231 CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
1232 tmp |= dividers.post_divider;
1233 WREG32_SMC(cntl_reg, tmp);
1234
1235 for (i = 0; i < 100; i++) {
1236 if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
1237 break;
1238 mdelay(10);
1239 }
1240 if (i == 100)
1241 return -ETIMEDOUT;
1242
1243 return 0;
1244}
1245
1246static int cik_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
1247{
1248 int r = 0;
1249
1250 r = cik_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
1251 if (r)
1252 return r;
1253
1254 r = cik_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
1255 return r;
1256}
1257
1258static int cik_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
1259{
1260 int r, i;
1261 struct atom_clock_dividers dividers;
1262 u32 tmp;
1263
1264 r = amdgpu_atombios_get_clock_dividers(adev,
1265 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
1266 ecclk, false, ÷rs);
1267 if (r)
1268 return r;
1269
1270 for (i = 0; i < 100; i++) {
1271 if (RREG32_SMC(ixCG_ECLK_STATUS) & CG_ECLK_STATUS__ECLK_STATUS_MASK)
1272 break;
1273 mdelay(10);
1274 }
1275 if (i == 100)
1276 return -ETIMEDOUT;
1277
1278 tmp = RREG32_SMC(ixCG_ECLK_CNTL);
1279 tmp &= ~(CG_ECLK_CNTL__ECLK_DIR_CNTL_EN_MASK |
1280 CG_ECLK_CNTL__ECLK_DIVIDER_MASK);
1281 tmp |= dividers.post_divider;
1282 WREG32_SMC(ixCG_ECLK_CNTL, tmp);
1283
1284 for (i = 0; i < 100; i++) {
1285 if (RREG32_SMC(ixCG_ECLK_STATUS) & CG_ECLK_STATUS__ECLK_STATUS_MASK)
1286 break;
1287 mdelay(10);
1288 }
1289 if (i == 100)
1290 return -ETIMEDOUT;
1291
1292 return 0;
1293}
1294
1295static void cik_pcie_gen3_enable(struct amdgpu_device *adev)
1296{
1297 struct pci_dev *root = adev->pdev->bus->self;
1298 int bridge_pos, gpu_pos;
1299 u32 speed_cntl, current_data_rate;
1300 int i;
1301 u16 tmp16;
1302
1303 if (pci_is_root_bus(adev->pdev->bus))
1304 return;
1305
1306 if (amdgpu_pcie_gen2 == 0)
1307 return;
1308
1309 if (adev->flags & AMD_IS_APU)
1310 return;
1311
1312 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
1313 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
1314 return;
1315
1316 speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL);
1317 current_data_rate = (speed_cntl & PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK) >>
1318 PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
1319 if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) {
1320 if (current_data_rate == 2) {
1321 DRM_INFO("PCIE gen 3 link speeds already enabled\n");
1322 return;
1323 }
1324 DRM_INFO("enabling PCIE gen 3 link speeds, disable with amdgpu.pcie_gen2=0\n");
1325 } else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) {
1326 if (current_data_rate == 1) {
1327 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
1328 return;
1329 }
1330 DRM_INFO("enabling PCIE gen 2 link speeds, disable with amdgpu.pcie_gen2=0\n");
1331 }
1332
1333 bridge_pos = pci_pcie_cap(root);
1334 if (!bridge_pos)
1335 return;
1336
1337 gpu_pos = pci_pcie_cap(adev->pdev);
1338 if (!gpu_pos)
1339 return;
1340
1341 if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) {
1342 /* re-try equalization if gen3 is not already enabled */
1343 if (current_data_rate != 2) {
1344 u16 bridge_cfg, gpu_cfg;
1345 u16 bridge_cfg2, gpu_cfg2;
1346 u32 max_lw, current_lw, tmp;
1347
1348 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
1349 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
1350
1351 tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
1352 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
1353
1354 tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
1355 pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
1356
1357 tmp = RREG32_PCIE(ixPCIE_LC_STATUS1);
1358 max_lw = (tmp & PCIE_LC_STATUS1__LC_DETECTED_LINK_WIDTH_MASK) >>
1359 PCIE_LC_STATUS1__LC_DETECTED_LINK_WIDTH__SHIFT;
1360 current_lw = (tmp & PCIE_LC_STATUS1__LC_OPERATING_LINK_WIDTH_MASK)
1361 >> PCIE_LC_STATUS1__LC_OPERATING_LINK_WIDTH__SHIFT;
1362
1363 if (current_lw < max_lw) {
1364 tmp = RREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL);
1365 if (tmp & PCIE_LC_LINK_WIDTH_CNTL__LC_RENEGOTIATION_SUPPORT_MASK) {
1366 tmp &= ~(PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_MASK |
1367 PCIE_LC_LINK_WIDTH_CNTL__LC_UPCONFIGURE_DIS_MASK);
1368 tmp |= (max_lw <<
1369 PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH__SHIFT);
1370 tmp |= PCIE_LC_LINK_WIDTH_CNTL__LC_UPCONFIGURE_SUPPORT_MASK |
1371 PCIE_LC_LINK_WIDTH_CNTL__LC_RENEGOTIATE_EN_MASK |
1372 PCIE_LC_LINK_WIDTH_CNTL__LC_RECONFIG_NOW_MASK;
1373 WREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL, tmp);
1374 }
1375 }
1376
1377 for (i = 0; i < 10; i++) {
1378 /* check status */
1379 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
1380 if (tmp16 & PCI_EXP_DEVSTA_TRPND)
1381 break;
1382
1383 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
1384 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
1385
1386 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
1387 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
1388
1389 tmp = RREG32_PCIE(ixPCIE_LC_CNTL4);
1390 tmp |= PCIE_LC_CNTL4__LC_SET_QUIESCE_MASK;
1391 WREG32_PCIE(ixPCIE_LC_CNTL4, tmp);
1392
1393 tmp = RREG32_PCIE(ixPCIE_LC_CNTL4);
1394 tmp |= PCIE_LC_CNTL4__LC_REDO_EQ_MASK;
1395 WREG32_PCIE(ixPCIE_LC_CNTL4, tmp);
1396
1397 mdelay(100);
1398
1399 /* linkctl */
1400 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
1401 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
1402 tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
1403 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
1404
1405 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
1406 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
1407 tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
1408 pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
1409
1410 /* linkctl2 */
1411 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
1412 tmp16 &= ~((1 << 4) | (7 << 9));
1413 tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
1414 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
1415
1416 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
1417 tmp16 &= ~((1 << 4) | (7 << 9));
1418 tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
1419 pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
1420
1421 tmp = RREG32_PCIE(ixPCIE_LC_CNTL4);
1422 tmp &= ~PCIE_LC_CNTL4__LC_SET_QUIESCE_MASK;
1423 WREG32_PCIE(ixPCIE_LC_CNTL4, tmp);
1424 }
1425 }
1426 }
1427
1428 /* set the link speed */
1429 speed_cntl |= PCIE_LC_SPEED_CNTL__LC_FORCE_EN_SW_SPEED_CHANGE_MASK |
1430 PCIE_LC_SPEED_CNTL__LC_FORCE_DIS_HW_SPEED_CHANGE_MASK;
1431 speed_cntl &= ~PCIE_LC_SPEED_CNTL__LC_FORCE_DIS_SW_SPEED_CHANGE_MASK;
1432 WREG32_PCIE(ixPCIE_LC_SPEED_CNTL, speed_cntl);
1433
1434 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
1435 tmp16 &= ~0xf;
1436 if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
1437 tmp16 |= 3; /* gen3 */
1438 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2)
1439 tmp16 |= 2; /* gen2 */
1440 else
1441 tmp16 |= 1; /* gen1 */
1442 pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
1443
1444 speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL);
1445 speed_cntl |= PCIE_LC_SPEED_CNTL__LC_INITIATE_LINK_SPEED_CHANGE_MASK;
1446 WREG32_PCIE(ixPCIE_LC_SPEED_CNTL, speed_cntl);
1447
1448 for (i = 0; i < adev->usec_timeout; i++) {
1449 speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL);
1450 if ((speed_cntl & PCIE_LC_SPEED_CNTL__LC_INITIATE_LINK_SPEED_CHANGE_MASK) == 0)
1451 break;
1452 udelay(1);
1453 }
1454}
1455
1456static void cik_program_aspm(struct amdgpu_device *adev)
1457{
1458 u32 data, orig;
1459 bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
1460 bool disable_clkreq = false;
1461
1462 if (amdgpu_aspm == 0)
1463 return;
1464
1465 if (pci_is_root_bus(adev->pdev->bus))
1466 return;
1467
1468 /* XXX double check APUs */
1469 if (adev->flags & AMD_IS_APU)
1470 return;
1471
1472 orig = data = RREG32_PCIE(ixPCIE_LC_N_FTS_CNTL);
1473 data &= ~PCIE_LC_N_FTS_CNTL__LC_XMIT_N_FTS_MASK;
1474 data |= (0x24 << PCIE_LC_N_FTS_CNTL__LC_XMIT_N_FTS__SHIFT) |
1475 PCIE_LC_N_FTS_CNTL__LC_XMIT_N_FTS_OVERRIDE_EN_MASK;
1476 if (orig != data)
1477 WREG32_PCIE(ixPCIE_LC_N_FTS_CNTL, data);
1478
1479 orig = data = RREG32_PCIE(ixPCIE_LC_CNTL3);
1480 data |= PCIE_LC_CNTL3__LC_GO_TO_RECOVERY_MASK;
1481 if (orig != data)
1482 WREG32_PCIE(ixPCIE_LC_CNTL3, data);
1483
1484 orig = data = RREG32_PCIE(ixPCIE_P_CNTL);
1485 data |= PCIE_P_CNTL__P_IGNORE_EDB_ERR_MASK;
1486 if (orig != data)
1487 WREG32_PCIE(ixPCIE_P_CNTL, data);
1488
1489 orig = data = RREG32_PCIE(ixPCIE_LC_CNTL);
1490 data &= ~(PCIE_LC_CNTL__LC_L0S_INACTIVITY_MASK |
1491 PCIE_LC_CNTL__LC_L1_INACTIVITY_MASK);
1492 data |= PCIE_LC_CNTL__LC_PMI_TO_L1_DIS_MASK;
1493 if (!disable_l0s)
1494 data |= (7 << PCIE_LC_CNTL__LC_L0S_INACTIVITY__SHIFT);
1495
1496 if (!disable_l1) {
1497 data |= (7 << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT);
1498 data &= ~PCIE_LC_CNTL__LC_PMI_TO_L1_DIS_MASK;
1499 if (orig != data)
1500 WREG32_PCIE(ixPCIE_LC_CNTL, data);
1501
1502 if (!disable_plloff_in_l1) {
1503 bool clk_req_support;
1504
1505 orig = data = RREG32_PCIE(ixPB0_PIF_PWRDOWN_0);
1506 data &= ~(PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0_MASK |
1507 PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0_MASK);
1508 data |= (7 << PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0__SHIFT) |
1509 (7 << PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0__SHIFT);
1510 if (orig != data)
1511 WREG32_PCIE(ixPB0_PIF_PWRDOWN_0, data);
1512
1513 orig = data = RREG32_PCIE(ixPB0_PIF_PWRDOWN_1);
1514 data &= ~(PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1_MASK |
1515 PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1_MASK);
1516 data |= (7 << PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1__SHIFT) |
1517 (7 << PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1__SHIFT);
1518 if (orig != data)
1519 WREG32_PCIE(ixPB0_PIF_PWRDOWN_1, data);
1520
1521 orig = data = RREG32_PCIE(ixPB1_PIF_PWRDOWN_0);
1522 data &= ~(PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0_MASK |
1523 PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0_MASK);
1524 data |= (7 << PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0__SHIFT) |
1525 (7 << PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0__SHIFT);
1526 if (orig != data)
1527 WREG32_PCIE(ixPB1_PIF_PWRDOWN_0, data);
1528
1529 orig = data = RREG32_PCIE(ixPB1_PIF_PWRDOWN_1);
1530 data &= ~(PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1_MASK |
1531 PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1_MASK);
1532 data |= (7 << PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1__SHIFT) |
1533 (7 << PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1__SHIFT);
1534 if (orig != data)
1535 WREG32_PCIE(ixPB1_PIF_PWRDOWN_1, data);
1536
1537 orig = data = RREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL);
1538 data &= ~PCIE_LC_LINK_WIDTH_CNTL__LC_DYN_LANES_PWR_STATE_MASK;
1539 data |= ~(3 << PCIE_LC_LINK_WIDTH_CNTL__LC_DYN_LANES_PWR_STATE__SHIFT);
1540 if (orig != data)
1541 WREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL, data);
1542
1543 if (!disable_clkreq) {
1544 struct pci_dev *root = adev->pdev->bus->self;
1545 u32 lnkcap;
1546
1547 clk_req_support = false;
1548 pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
1549 if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
1550 clk_req_support = true;
1551 } else {
1552 clk_req_support = false;
1553 }
1554
1555 if (clk_req_support) {
1556 orig = data = RREG32_PCIE(ixPCIE_LC_CNTL2);
1557 data |= PCIE_LC_CNTL2__LC_ALLOW_PDWN_IN_L1_MASK |
1558 PCIE_LC_CNTL2__LC_ALLOW_PDWN_IN_L23_MASK;
1559 if (orig != data)
1560 WREG32_PCIE(ixPCIE_LC_CNTL2, data);
1561
1562 orig = data = RREG32_SMC(ixTHM_CLK_CNTL);
1563 data &= ~(THM_CLK_CNTL__CMON_CLK_SEL_MASK |
1564 THM_CLK_CNTL__TMON_CLK_SEL_MASK);
1565 data |= (1 << THM_CLK_CNTL__CMON_CLK_SEL__SHIFT) |
1566 (1 << THM_CLK_CNTL__TMON_CLK_SEL__SHIFT);
1567 if (orig != data)
1568 WREG32_SMC(ixTHM_CLK_CNTL, data);
1569
1570 orig = data = RREG32_SMC(ixMISC_CLK_CTRL);
1571 data &= ~(MISC_CLK_CTRL__DEEP_SLEEP_CLK_SEL_MASK |
1572 MISC_CLK_CTRL__ZCLK_SEL_MASK);
1573 data |= (1 << MISC_CLK_CTRL__DEEP_SLEEP_CLK_SEL__SHIFT) |
1574 (1 << MISC_CLK_CTRL__ZCLK_SEL__SHIFT);
1575 if (orig != data)
1576 WREG32_SMC(ixMISC_CLK_CTRL, data);
1577
1578 orig = data = RREG32_SMC(ixCG_CLKPIN_CNTL);
1579 data &= ~CG_CLKPIN_CNTL__BCLK_AS_XCLK_MASK;
1580 if (orig != data)
1581 WREG32_SMC(ixCG_CLKPIN_CNTL, data);
1582
1583 orig = data = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
1584 data &= ~CG_CLKPIN_CNTL_2__FORCE_BIF_REFCLK_EN_MASK;
1585 if (orig != data)
1586 WREG32_SMC(ixCG_CLKPIN_CNTL_2, data);
1587
1588 orig = data = RREG32_SMC(ixMPLL_BYPASSCLK_SEL);
1589 data &= ~MPLL_BYPASSCLK_SEL__MPLL_CLKOUT_SEL_MASK;
1590 data |= (4 << MPLL_BYPASSCLK_SEL__MPLL_CLKOUT_SEL__SHIFT);
1591 if (orig != data)
1592 WREG32_SMC(ixMPLL_BYPASSCLK_SEL, data);
1593 }
1594 }
1595 } else {
1596 if (orig != data)
1597 WREG32_PCIE(ixPCIE_LC_CNTL, data);
1598 }
1599
1600 orig = data = RREG32_PCIE(ixPCIE_CNTL2);
1601 data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1602 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1603 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
1604 if (orig != data)
1605 WREG32_PCIE(ixPCIE_CNTL2, data);
1606
1607 if (!disable_l0s) {
1608 data = RREG32_PCIE(ixPCIE_LC_N_FTS_CNTL);
1609 if ((data & PCIE_LC_N_FTS_CNTL__LC_N_FTS_MASK) ==
1610 PCIE_LC_N_FTS_CNTL__LC_N_FTS_MASK) {
1611 data = RREG32_PCIE(ixPCIE_LC_STATUS1);
1612 if ((data & PCIE_LC_STATUS1__LC_REVERSE_XMIT_MASK) &&
1613 (data & PCIE_LC_STATUS1__LC_REVERSE_RCVR_MASK)) {
1614 orig = data = RREG32_PCIE(ixPCIE_LC_CNTL);
1615 data &= ~PCIE_LC_CNTL__LC_L0S_INACTIVITY_MASK;
1616 if (orig != data)
1617 WREG32_PCIE(ixPCIE_LC_CNTL, data);
1618 }
1619 }
1620 }
1621}
1622
1623static uint32_t cik_get_rev_id(struct amdgpu_device *adev)
1624{
1625 return (RREG32(mmCC_DRM_ID_STRAPS) & CC_DRM_ID_STRAPS__ATI_REV_ID_MASK)
1626 >> CC_DRM_ID_STRAPS__ATI_REV_ID__SHIFT;
1627}
1628
1629static const struct amdgpu_ip_block_version bonaire_ip_blocks[] =
1630{
1631 /* ORDER MATTERS! */
1632 {
1633 .type = AMD_IP_BLOCK_TYPE_COMMON,
1634 .major = 1,
1635 .minor = 0,
1636 .rev = 0,
1637 .funcs = &cik_common_ip_funcs,
1638 },
1639 {
1640 .type = AMD_IP_BLOCK_TYPE_GMC,
1641 .major = 7,
1642 .minor = 0,
1643 .rev = 0,
1644 .funcs = &gmc_v7_0_ip_funcs,
1645 },
1646 {
1647 .type = AMD_IP_BLOCK_TYPE_IH,
1648 .major = 2,
1649 .minor = 0,
1650 .rev = 0,
1651 .funcs = &cik_ih_ip_funcs,
1652 },
1653 {
1654 .type = AMD_IP_BLOCK_TYPE_SMC,
1655 .major = 7,
1656 .minor = 0,
1657 .rev = 0,
1658 .funcs = &amdgpu_pp_ip_funcs,
1659 },
1660 {
1661 .type = AMD_IP_BLOCK_TYPE_DCE,
1662 .major = 8,
1663 .minor = 2,
1664 .rev = 0,
1665 .funcs = &dce_v8_0_ip_funcs,
1666 },
1667 {
1668 .type = AMD_IP_BLOCK_TYPE_GFX,
1669 .major = 7,
1670 .minor = 2,
1671 .rev = 0,
1672 .funcs = &gfx_v7_0_ip_funcs,
1673 },
1674 {
1675 .type = AMD_IP_BLOCK_TYPE_SDMA,
1676 .major = 2,
1677 .minor = 0,
1678 .rev = 0,
1679 .funcs = &cik_sdma_ip_funcs,
1680 },
1681 {
1682 .type = AMD_IP_BLOCK_TYPE_UVD,
1683 .major = 4,
1684 .minor = 2,
1685 .rev = 0,
1686 .funcs = &uvd_v4_2_ip_funcs,
1687 },
1688 {
1689 .type = AMD_IP_BLOCK_TYPE_VCE,
1690 .major = 2,
1691 .minor = 0,
1692 .rev = 0,
1693 .funcs = &vce_v2_0_ip_funcs,
1694 },
1695};
1696
1697static const struct amdgpu_ip_block_version hawaii_ip_blocks[] =
1698{
1699 /* ORDER MATTERS! */
1700 {
1701 .type = AMD_IP_BLOCK_TYPE_COMMON,
1702 .major = 1,
1703 .minor = 0,
1704 .rev = 0,
1705 .funcs = &cik_common_ip_funcs,
1706 },
1707 {
1708 .type = AMD_IP_BLOCK_TYPE_GMC,
1709 .major = 7,
1710 .minor = 0,
1711 .rev = 0,
1712 .funcs = &gmc_v7_0_ip_funcs,
1713 },
1714 {
1715 .type = AMD_IP_BLOCK_TYPE_IH,
1716 .major = 2,
1717 .minor = 0,
1718 .rev = 0,
1719 .funcs = &cik_ih_ip_funcs,
1720 },
1721 {
1722 .type = AMD_IP_BLOCK_TYPE_SMC,
1723 .major = 7,
1724 .minor = 0,
1725 .rev = 0,
1726 .funcs = &amdgpu_pp_ip_funcs,
1727 },
1728 {
1729 .type = AMD_IP_BLOCK_TYPE_DCE,
1730 .major = 8,
1731 .minor = 5,
1732 .rev = 0,
1733 .funcs = &dce_v8_0_ip_funcs,
1734 },
1735 {
1736 .type = AMD_IP_BLOCK_TYPE_GFX,
1737 .major = 7,
1738 .minor = 3,
1739 .rev = 0,
1740 .funcs = &gfx_v7_0_ip_funcs,
1741 },
1742 {
1743 .type = AMD_IP_BLOCK_TYPE_SDMA,
1744 .major = 2,
1745 .minor = 0,
1746 .rev = 0,
1747 .funcs = &cik_sdma_ip_funcs,
1748 },
1749 {
1750 .type = AMD_IP_BLOCK_TYPE_UVD,
1751 .major = 4,
1752 .minor = 2,
1753 .rev = 0,
1754 .funcs = &uvd_v4_2_ip_funcs,
1755 },
1756 {
1757 .type = AMD_IP_BLOCK_TYPE_VCE,
1758 .major = 2,
1759 .minor = 0,
1760 .rev = 0,
1761 .funcs = &vce_v2_0_ip_funcs,
1762 },
1763};
1764
1765static const struct amdgpu_ip_block_version kabini_ip_blocks[] =
1766{
1767 /* ORDER MATTERS! */
1768 {
1769 .type = AMD_IP_BLOCK_TYPE_COMMON,
1770 .major = 1,
1771 .minor = 0,
1772 .rev = 0,
1773 .funcs = &cik_common_ip_funcs,
1774 },
1775 {
1776 .type = AMD_IP_BLOCK_TYPE_GMC,
1777 .major = 7,
1778 .minor = 0,
1779 .rev = 0,
1780 .funcs = &gmc_v7_0_ip_funcs,
1781 },
1782 {
1783 .type = AMD_IP_BLOCK_TYPE_IH,
1784 .major = 2,
1785 .minor = 0,
1786 .rev = 0,
1787 .funcs = &cik_ih_ip_funcs,
1788 },
1789 {
1790 .type = AMD_IP_BLOCK_TYPE_SMC,
1791 .major = 7,
1792 .minor = 0,
1793 .rev = 0,
1794 .funcs = &amdgpu_pp_ip_funcs,
1795 },
1796 {
1797 .type = AMD_IP_BLOCK_TYPE_DCE,
1798 .major = 8,
1799 .minor = 3,
1800 .rev = 0,
1801 .funcs = &dce_v8_0_ip_funcs,
1802 },
1803 {
1804 .type = AMD_IP_BLOCK_TYPE_GFX,
1805 .major = 7,
1806 .minor = 2,
1807 .rev = 0,
1808 .funcs = &gfx_v7_0_ip_funcs,
1809 },
1810 {
1811 .type = AMD_IP_BLOCK_TYPE_SDMA,
1812 .major = 2,
1813 .minor = 0,
1814 .rev = 0,
1815 .funcs = &cik_sdma_ip_funcs,
1816 },
1817 {
1818 .type = AMD_IP_BLOCK_TYPE_UVD,
1819 .major = 4,
1820 .minor = 2,
1821 .rev = 0,
1822 .funcs = &uvd_v4_2_ip_funcs,
1823 },
1824 {
1825 .type = AMD_IP_BLOCK_TYPE_VCE,
1826 .major = 2,
1827 .minor = 0,
1828 .rev = 0,
1829 .funcs = &vce_v2_0_ip_funcs,
1830 },
1831};
1832
1833static const struct amdgpu_ip_block_version mullins_ip_blocks[] =
1834{
1835 /* ORDER MATTERS! */
1836 {
1837 .type = AMD_IP_BLOCK_TYPE_COMMON,
1838 .major = 1,
1839 .minor = 0,
1840 .rev = 0,
1841 .funcs = &cik_common_ip_funcs,
1842 },
1843 {
1844 .type = AMD_IP_BLOCK_TYPE_GMC,
1845 .major = 7,
1846 .minor = 0,
1847 .rev = 0,
1848 .funcs = &gmc_v7_0_ip_funcs,
1849 },
1850 {
1851 .type = AMD_IP_BLOCK_TYPE_IH,
1852 .major = 2,
1853 .minor = 0,
1854 .rev = 0,
1855 .funcs = &cik_ih_ip_funcs,
1856 },
1857 {
1858 .type = AMD_IP_BLOCK_TYPE_SMC,
1859 .major = 7,
1860 .minor = 0,
1861 .rev = 0,
1862 .funcs = &amdgpu_pp_ip_funcs,
1863 },
1864 {
1865 .type = AMD_IP_BLOCK_TYPE_DCE,
1866 .major = 8,
1867 .minor = 3,
1868 .rev = 0,
1869 .funcs = &dce_v8_0_ip_funcs,
1870 },
1871 {
1872 .type = AMD_IP_BLOCK_TYPE_GFX,
1873 .major = 7,
1874 .minor = 2,
1875 .rev = 0,
1876 .funcs = &gfx_v7_0_ip_funcs,
1877 },
1878 {
1879 .type = AMD_IP_BLOCK_TYPE_SDMA,
1880 .major = 2,
1881 .minor = 0,
1882 .rev = 0,
1883 .funcs = &cik_sdma_ip_funcs,
1884 },
1885 {
1886 .type = AMD_IP_BLOCK_TYPE_UVD,
1887 .major = 4,
1888 .minor = 2,
1889 .rev = 0,
1890 .funcs = &uvd_v4_2_ip_funcs,
1891 },
1892 {
1893 .type = AMD_IP_BLOCK_TYPE_VCE,
1894 .major = 2,
1895 .minor = 0,
1896 .rev = 0,
1897 .funcs = &vce_v2_0_ip_funcs,
1898 },
1899};
1900
1901static const struct amdgpu_ip_block_version kaveri_ip_blocks[] =
1902{
1903 /* ORDER MATTERS! */
1904 {
1905 .type = AMD_IP_BLOCK_TYPE_COMMON,
1906 .major = 1,
1907 .minor = 0,
1908 .rev = 0,
1909 .funcs = &cik_common_ip_funcs,
1910 },
1911 {
1912 .type = AMD_IP_BLOCK_TYPE_GMC,
1913 .major = 7,
1914 .minor = 0,
1915 .rev = 0,
1916 .funcs = &gmc_v7_0_ip_funcs,
1917 },
1918 {
1919 .type = AMD_IP_BLOCK_TYPE_IH,
1920 .major = 2,
1921 .minor = 0,
1922 .rev = 0,
1923 .funcs = &cik_ih_ip_funcs,
1924 },
1925 {
1926 .type = AMD_IP_BLOCK_TYPE_SMC,
1927 .major = 7,
1928 .minor = 0,
1929 .rev = 0,
1930 .funcs = &amdgpu_pp_ip_funcs,
1931 },
1932 {
1933 .type = AMD_IP_BLOCK_TYPE_DCE,
1934 .major = 8,
1935 .minor = 1,
1936 .rev = 0,
1937 .funcs = &dce_v8_0_ip_funcs,
1938 },
1939 {
1940 .type = AMD_IP_BLOCK_TYPE_GFX,
1941 .major = 7,
1942 .minor = 1,
1943 .rev = 0,
1944 .funcs = &gfx_v7_0_ip_funcs,
1945 },
1946 {
1947 .type = AMD_IP_BLOCK_TYPE_SDMA,
1948 .major = 2,
1949 .minor = 0,
1950 .rev = 0,
1951 .funcs = &cik_sdma_ip_funcs,
1952 },
1953 {
1954 .type = AMD_IP_BLOCK_TYPE_UVD,
1955 .major = 4,
1956 .minor = 2,
1957 .rev = 0,
1958 .funcs = &uvd_v4_2_ip_funcs,
1959 },
1960 {
1961 .type = AMD_IP_BLOCK_TYPE_VCE,
1962 .major = 2,
1963 .minor = 0,
1964 .rev = 0,
1965 .funcs = &vce_v2_0_ip_funcs,
1966 },
1967};
1968
1969int cik_set_ip_blocks(struct amdgpu_device *adev)
1970{
1971 switch (adev->asic_type) {
1972 case CHIP_BONAIRE:
1973 adev->ip_blocks = bonaire_ip_blocks;
1974 adev->num_ip_blocks = ARRAY_SIZE(bonaire_ip_blocks);
1975 break;
1976 case CHIP_HAWAII:
1977 adev->ip_blocks = hawaii_ip_blocks;
1978 adev->num_ip_blocks = ARRAY_SIZE(hawaii_ip_blocks);
1979 break;
1980 case CHIP_KAVERI:
1981 adev->ip_blocks = kaveri_ip_blocks;
1982 adev->num_ip_blocks = ARRAY_SIZE(kaveri_ip_blocks);
1983 break;
1984 case CHIP_KABINI:
1985 adev->ip_blocks = kabini_ip_blocks;
1986 adev->num_ip_blocks = ARRAY_SIZE(kabini_ip_blocks);
1987 break;
1988 case CHIP_MULLINS:
1989 adev->ip_blocks = mullins_ip_blocks;
1990 adev->num_ip_blocks = ARRAY_SIZE(mullins_ip_blocks);
1991 break;
1992 default:
1993 /* FIXME: not supported yet */
1994 return -EINVAL;
1995 }
1996
1997 return 0;
1998}
1999
2000static const struct amdgpu_asic_funcs cik_asic_funcs =
2001{
2002 .read_disabled_bios = &cik_read_disabled_bios,
2003 .read_bios_from_rom = &cik_read_bios_from_rom,
2004 .read_register = &cik_read_register,
2005 .reset = &cik_asic_reset,
2006 .set_vga_state = &cik_vga_set_state,
2007 .get_xclk = &cik_get_xclk,
2008 .set_uvd_clocks = &cik_set_uvd_clocks,
2009 .set_vce_clocks = &cik_set_vce_clocks,
2010 .get_cu_info = &gfx_v7_0_get_cu_info,
2011 /* these should be moved to their own ip modules */
2012 .get_gpu_clock_counter = &gfx_v7_0_get_gpu_clock_counter,
2013 .wait_for_mc_idle = &gmc_v7_0_mc_wait_for_idle,
2014};
2015
2016static int cik_common_early_init(void *handle)
2017{
2018 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2019
2020 adev->smc_rreg = &cik_smc_rreg;
2021 adev->smc_wreg = &cik_smc_wreg;
2022 adev->pcie_rreg = &cik_pcie_rreg;
2023 adev->pcie_wreg = &cik_pcie_wreg;
2024 adev->uvd_ctx_rreg = &cik_uvd_ctx_rreg;
2025 adev->uvd_ctx_wreg = &cik_uvd_ctx_wreg;
2026 adev->didt_rreg = &cik_didt_rreg;
2027 adev->didt_wreg = &cik_didt_wreg;
2028
2029 adev->asic_funcs = &cik_asic_funcs;
2030
2031 adev->rev_id = cik_get_rev_id(adev);
2032 adev->external_rev_id = 0xFF;
2033 switch (adev->asic_type) {
2034 case CHIP_BONAIRE:
2035 adev->cg_flags =
2036 AMD_CG_SUPPORT_GFX_MGCG |
2037 AMD_CG_SUPPORT_GFX_MGLS |
2038 /*AMD_CG_SUPPORT_GFX_CGCG |*/
2039 AMD_CG_SUPPORT_GFX_CGLS |
2040 AMD_CG_SUPPORT_GFX_CGTS |
2041 AMD_CG_SUPPORT_GFX_CGTS_LS |
2042 AMD_CG_SUPPORT_GFX_CP_LS |
2043 AMD_CG_SUPPORT_MC_LS |
2044 AMD_CG_SUPPORT_MC_MGCG |
2045 AMD_CG_SUPPORT_SDMA_MGCG |
2046 AMD_CG_SUPPORT_SDMA_LS |
2047 AMD_CG_SUPPORT_BIF_LS |
2048 AMD_CG_SUPPORT_VCE_MGCG |
2049 AMD_CG_SUPPORT_UVD_MGCG |
2050 AMD_CG_SUPPORT_HDP_LS |
2051 AMD_CG_SUPPORT_HDP_MGCG;
2052 adev->pg_flags = 0;
2053 adev->external_rev_id = adev->rev_id + 0x14;
2054 break;
2055 case CHIP_HAWAII:
2056 adev->cg_flags =
2057 AMD_CG_SUPPORT_GFX_MGCG |
2058 AMD_CG_SUPPORT_GFX_MGLS |
2059 /*AMD_CG_SUPPORT_GFX_CGCG |*/
2060 AMD_CG_SUPPORT_GFX_CGLS |
2061 AMD_CG_SUPPORT_GFX_CGTS |
2062 AMD_CG_SUPPORT_GFX_CP_LS |
2063 AMD_CG_SUPPORT_MC_LS |
2064 AMD_CG_SUPPORT_MC_MGCG |
2065 AMD_CG_SUPPORT_SDMA_MGCG |
2066 AMD_CG_SUPPORT_SDMA_LS |
2067 AMD_CG_SUPPORT_BIF_LS |
2068 AMD_CG_SUPPORT_VCE_MGCG |
2069 AMD_CG_SUPPORT_UVD_MGCG |
2070 AMD_CG_SUPPORT_HDP_LS |
2071 AMD_CG_SUPPORT_HDP_MGCG;
2072 adev->pg_flags = 0;
2073 adev->external_rev_id = 0x28;
2074 break;
2075 case CHIP_KAVERI:
2076 adev->cg_flags =
2077 AMD_CG_SUPPORT_GFX_MGCG |
2078 AMD_CG_SUPPORT_GFX_MGLS |
2079 /*AMD_CG_SUPPORT_GFX_CGCG |*/
2080 AMD_CG_SUPPORT_GFX_CGLS |
2081 AMD_CG_SUPPORT_GFX_CGTS |
2082 AMD_CG_SUPPORT_GFX_CGTS_LS |
2083 AMD_CG_SUPPORT_GFX_CP_LS |
2084 AMD_CG_SUPPORT_SDMA_MGCG |
2085 AMD_CG_SUPPORT_SDMA_LS |
2086 AMD_CG_SUPPORT_BIF_LS |
2087 AMD_CG_SUPPORT_VCE_MGCG |
2088 AMD_CG_SUPPORT_UVD_MGCG |
2089 AMD_CG_SUPPORT_HDP_LS |
2090 AMD_CG_SUPPORT_HDP_MGCG;
2091 adev->pg_flags =
2092 /*AMD_PG_SUPPORT_GFX_PG |
2093 AMD_PG_SUPPORT_GFX_SMG |
2094 AMD_PG_SUPPORT_GFX_DMG |*/
2095 AMD_PG_SUPPORT_UVD |
2096 /*AMD_PG_SUPPORT_VCE |
2097 AMD_PG_SUPPORT_CP |
2098 AMD_PG_SUPPORT_GDS |
2099 AMD_PG_SUPPORT_RLC_SMU_HS |
2100 AMD_PG_SUPPORT_ACP |
2101 AMD_PG_SUPPORT_SAMU |*/
2102 0;
2103 if (adev->pdev->device == 0x1312 ||
2104 adev->pdev->device == 0x1316 ||
2105 adev->pdev->device == 0x1317)
2106 adev->external_rev_id = 0x41;
2107 else
2108 adev->external_rev_id = 0x1;
2109 break;
2110 case CHIP_KABINI:
2111 case CHIP_MULLINS:
2112 adev->cg_flags =
2113 AMD_CG_SUPPORT_GFX_MGCG |
2114 AMD_CG_SUPPORT_GFX_MGLS |
2115 /*AMD_CG_SUPPORT_GFX_CGCG |*/
2116 AMD_CG_SUPPORT_GFX_CGLS |
2117 AMD_CG_SUPPORT_GFX_CGTS |
2118 AMD_CG_SUPPORT_GFX_CGTS_LS |
2119 AMD_CG_SUPPORT_GFX_CP_LS |
2120 AMD_CG_SUPPORT_SDMA_MGCG |
2121 AMD_CG_SUPPORT_SDMA_LS |
2122 AMD_CG_SUPPORT_BIF_LS |
2123 AMD_CG_SUPPORT_VCE_MGCG |
2124 AMD_CG_SUPPORT_UVD_MGCG |
2125 AMD_CG_SUPPORT_HDP_LS |
2126 AMD_CG_SUPPORT_HDP_MGCG;
2127 adev->pg_flags =
2128 /*AMD_PG_SUPPORT_GFX_PG |
2129 AMD_PG_SUPPORT_GFX_SMG | */
2130 AMD_PG_SUPPORT_UVD |
2131 /*AMD_PG_SUPPORT_VCE |
2132 AMD_PG_SUPPORT_CP |
2133 AMD_PG_SUPPORT_GDS |
2134 AMD_PG_SUPPORT_RLC_SMU_HS |
2135 AMD_PG_SUPPORT_SAMU |*/
2136 0;
2137 if (adev->asic_type == CHIP_KABINI) {
2138 if (adev->rev_id == 0)
2139 adev->external_rev_id = 0x81;
2140 else if (adev->rev_id == 1)
2141 adev->external_rev_id = 0x82;
2142 else if (adev->rev_id == 2)
2143 adev->external_rev_id = 0x85;
2144 } else
2145 adev->external_rev_id = adev->rev_id + 0xa1;
2146 break;
2147 default:
2148 /* FIXME: not supported yet */
2149 return -EINVAL;
2150 }
2151
2152 amdgpu_get_pcie_info(adev);
2153
2154 return 0;
2155}
2156
2157static int cik_common_sw_init(void *handle)
2158{
2159 return 0;
2160}
2161
2162static int cik_common_sw_fini(void *handle)
2163{
2164 return 0;
2165}
2166
2167static int cik_common_hw_init(void *handle)
2168{
2169 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2170
2171 /* move the golden regs per IP block */
2172 cik_init_golden_registers(adev);
2173 /* enable pcie gen2/3 link */
2174 cik_pcie_gen3_enable(adev);
2175 /* enable aspm */
2176 cik_program_aspm(adev);
2177
2178 return 0;
2179}
2180
2181static int cik_common_hw_fini(void *handle)
2182{
2183 return 0;
2184}
2185
2186static int cik_common_suspend(void *handle)
2187{
2188 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2189
2190 amdgpu_amdkfd_suspend(adev);
2191
2192 return cik_common_hw_fini(adev);
2193}
2194
2195static int cik_common_resume(void *handle)
2196{
2197 int r;
2198 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2199
2200 r = cik_common_hw_init(adev);
2201 if (r)
2202 return r;
2203
2204 return amdgpu_amdkfd_resume(adev);
2205}
2206
2207static bool cik_common_is_idle(void *handle)
2208{
2209 return true;
2210}
2211
2212static int cik_common_wait_for_idle(void *handle)
2213{
2214 return 0;
2215}
2216
2217static void cik_common_print_status(void *handle)
2218{
2219
2220}
2221
2222static int cik_common_soft_reset(void *handle)
2223{
2224 /* XXX hard reset?? */
2225 return 0;
2226}
2227
2228static int cik_common_set_clockgating_state(void *handle,
2229 enum amd_clockgating_state state)
2230{
2231 return 0;
2232}
2233
2234static int cik_common_set_powergating_state(void *handle,
2235 enum amd_powergating_state state)
2236{
2237 return 0;
2238}
2239
2240const struct amd_ip_funcs cik_common_ip_funcs = {
2241 .early_init = cik_common_early_init,
2242 .late_init = NULL,
2243 .sw_init = cik_common_sw_init,
2244 .sw_fini = cik_common_sw_fini,
2245 .hw_init = cik_common_hw_init,
2246 .hw_fini = cik_common_hw_fini,
2247 .suspend = cik_common_suspend,
2248 .resume = cik_common_resume,
2249 .is_idle = cik_common_is_idle,
2250 .wait_for_idle = cik_common_wait_for_idle,
2251 .soft_reset = cik_common_soft_reset,
2252 .print_status = cik_common_print_status,
2253 .set_clockgating_state = cik_common_set_clockgating_state,
2254 .set_powergating_state = cik_common_set_powergating_state,
2255};
1/*
2 * Copyright 2012 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 * Authors: Alex Deucher
23 */
24#include <linux/firmware.h>
25#include <linux/slab.h>
26#include <linux/module.h>
27#include <linux/pci.h>
28
29#include <drm/amdgpu_drm.h>
30
31#include "amdgpu.h"
32#include "amdgpu_atombios.h"
33#include "amdgpu_ih.h"
34#include "amdgpu_uvd.h"
35#include "amdgpu_vce.h"
36#include "cikd.h"
37#include "atom.h"
38#include "amd_pcie.h"
39
40#include "cik.h"
41#include "gmc_v7_0.h"
42#include "cik_ih.h"
43#include "dce_v8_0.h"
44#include "gfx_v7_0.h"
45#include "cik_sdma.h"
46#include "uvd_v4_2.h"
47#include "vce_v2_0.h"
48#include "cik_dpm.h"
49
50#include "uvd/uvd_4_2_d.h"
51
52#include "smu/smu_7_0_1_d.h"
53#include "smu/smu_7_0_1_sh_mask.h"
54
55#include "dce/dce_8_0_d.h"
56#include "dce/dce_8_0_sh_mask.h"
57
58#include "bif/bif_4_1_d.h"
59#include "bif/bif_4_1_sh_mask.h"
60
61#include "gca/gfx_7_2_d.h"
62#include "gca/gfx_7_2_enum.h"
63#include "gca/gfx_7_2_sh_mask.h"
64
65#include "gmc/gmc_7_1_d.h"
66#include "gmc/gmc_7_1_sh_mask.h"
67
68#include "oss/oss_2_0_d.h"
69#include "oss/oss_2_0_sh_mask.h"
70
71#include "amdgpu_dm.h"
72#include "amdgpu_amdkfd.h"
73#include "amdgpu_vkms.h"
74
75static const struct amdgpu_video_codec_info cik_video_codecs_encode_array[] =
76{
77 {
78 .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC,
79 .max_width = 2048,
80 .max_height = 1152,
81 .max_pixels_per_frame = 2048 * 1152,
82 .max_level = 0,
83 },
84};
85
86static const struct amdgpu_video_codecs cik_video_codecs_encode =
87{
88 .codec_count = ARRAY_SIZE(cik_video_codecs_encode_array),
89 .codec_array = cik_video_codecs_encode_array,
90};
91
92static const struct amdgpu_video_codec_info cik_video_codecs_decode_array[] =
93{
94 {
95 .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2,
96 .max_width = 2048,
97 .max_height = 1152,
98 .max_pixels_per_frame = 2048 * 1152,
99 .max_level = 3,
100 },
101 {
102 .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4,
103 .max_width = 2048,
104 .max_height = 1152,
105 .max_pixels_per_frame = 2048 * 1152,
106 .max_level = 5,
107 },
108 {
109 .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC,
110 .max_width = 2048,
111 .max_height = 1152,
112 .max_pixels_per_frame = 2048 * 1152,
113 .max_level = 41,
114 },
115 {
116 .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1,
117 .max_width = 2048,
118 .max_height = 1152,
119 .max_pixels_per_frame = 2048 * 1152,
120 .max_level = 4,
121 },
122};
123
124static const struct amdgpu_video_codecs cik_video_codecs_decode =
125{
126 .codec_count = ARRAY_SIZE(cik_video_codecs_decode_array),
127 .codec_array = cik_video_codecs_decode_array,
128};
129
130static int cik_query_video_codecs(struct amdgpu_device *adev, bool encode,
131 const struct amdgpu_video_codecs **codecs)
132{
133 switch (adev->asic_type) {
134 case CHIP_BONAIRE:
135 case CHIP_HAWAII:
136 case CHIP_KAVERI:
137 case CHIP_KABINI:
138 case CHIP_MULLINS:
139 if (encode)
140 *codecs = &cik_video_codecs_encode;
141 else
142 *codecs = &cik_video_codecs_decode;
143 return 0;
144 default:
145 return -EINVAL;
146 }
147}
148
149/*
150 * Indirect registers accessor
151 */
152static u32 cik_pcie_rreg(struct amdgpu_device *adev, u32 reg)
153{
154 unsigned long flags;
155 u32 r;
156
157 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
158 WREG32(mmPCIE_INDEX, reg);
159 (void)RREG32(mmPCIE_INDEX);
160 r = RREG32(mmPCIE_DATA);
161 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
162 return r;
163}
164
165static void cik_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
166{
167 unsigned long flags;
168
169 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
170 WREG32(mmPCIE_INDEX, reg);
171 (void)RREG32(mmPCIE_INDEX);
172 WREG32(mmPCIE_DATA, v);
173 (void)RREG32(mmPCIE_DATA);
174 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
175}
176
177static u32 cik_smc_rreg(struct amdgpu_device *adev, u32 reg)
178{
179 unsigned long flags;
180 u32 r;
181
182 spin_lock_irqsave(&adev->smc_idx_lock, flags);
183 WREG32(mmSMC_IND_INDEX_0, (reg));
184 r = RREG32(mmSMC_IND_DATA_0);
185 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
186 return r;
187}
188
189static void cik_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
190{
191 unsigned long flags;
192
193 spin_lock_irqsave(&adev->smc_idx_lock, flags);
194 WREG32(mmSMC_IND_INDEX_0, (reg));
195 WREG32(mmSMC_IND_DATA_0, (v));
196 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
197}
198
199static u32 cik_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
200{
201 unsigned long flags;
202 u32 r;
203
204 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
205 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
206 r = RREG32(mmUVD_CTX_DATA);
207 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
208 return r;
209}
210
211static void cik_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
212{
213 unsigned long flags;
214
215 spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
216 WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
217 WREG32(mmUVD_CTX_DATA, (v));
218 spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
219}
220
221static u32 cik_didt_rreg(struct amdgpu_device *adev, u32 reg)
222{
223 unsigned long flags;
224 u32 r;
225
226 spin_lock_irqsave(&adev->didt_idx_lock, flags);
227 WREG32(mmDIDT_IND_INDEX, (reg));
228 r = RREG32(mmDIDT_IND_DATA);
229 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
230 return r;
231}
232
233static void cik_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
234{
235 unsigned long flags;
236
237 spin_lock_irqsave(&adev->didt_idx_lock, flags);
238 WREG32(mmDIDT_IND_INDEX, (reg));
239 WREG32(mmDIDT_IND_DATA, (v));
240 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
241}
242
243static const u32 bonaire_golden_spm_registers[] =
244{
245 0xc200, 0xe0ffffff, 0xe0000000
246};
247
248static const u32 bonaire_golden_common_registers[] =
249{
250 0x31dc, 0xffffffff, 0x00000800,
251 0x31dd, 0xffffffff, 0x00000800,
252 0x31e6, 0xffffffff, 0x00007fbf,
253 0x31e7, 0xffffffff, 0x00007faf
254};
255
256static const u32 bonaire_golden_registers[] =
257{
258 0xcd5, 0x00000333, 0x00000333,
259 0xcd4, 0x000c0fc0, 0x00040200,
260 0x2684, 0x00010000, 0x00058208,
261 0xf000, 0xffff1fff, 0x00140000,
262 0xf080, 0xfdfc0fff, 0x00000100,
263 0xf08d, 0x40000000, 0x40000200,
264 0x260c, 0xffffffff, 0x00000000,
265 0x260d, 0xf00fffff, 0x00000400,
266 0x260e, 0x0002021c, 0x00020200,
267 0x31e, 0x00000080, 0x00000000,
268 0x16ec, 0x000000f0, 0x00000070,
269 0x16f0, 0xf0311fff, 0x80300000,
270 0x263e, 0x73773777, 0x12010001,
271 0xd43, 0x00810000, 0x408af000,
272 0x1c0c, 0x31000111, 0x00000011,
273 0xbd2, 0x73773777, 0x12010001,
274 0x883, 0x00007fb6, 0x0021a1b1,
275 0x884, 0x00007fb6, 0x002021b1,
276 0x860, 0x00007fb6, 0x00002191,
277 0x886, 0x00007fb6, 0x002121b1,
278 0x887, 0x00007fb6, 0x002021b1,
279 0x877, 0x00007fb6, 0x00002191,
280 0x878, 0x00007fb6, 0x00002191,
281 0xd8a, 0x0000003f, 0x0000000a,
282 0xd8b, 0x0000003f, 0x0000000a,
283 0xab9, 0x00073ffe, 0x000022a2,
284 0x903, 0x000007ff, 0x00000000,
285 0x2285, 0xf000003f, 0x00000007,
286 0x22fc, 0x00002001, 0x00000001,
287 0x22c9, 0xffffffff, 0x00ffffff,
288 0xc281, 0x0000ff0f, 0x00000000,
289 0xa293, 0x07ffffff, 0x06000000,
290 0x136, 0x00000fff, 0x00000100,
291 0xf9e, 0x00000001, 0x00000002,
292 0x2440, 0x03000000, 0x0362c688,
293 0x2300, 0x000000ff, 0x00000001,
294 0x390, 0x00001fff, 0x00001fff,
295 0x2418, 0x0000007f, 0x00000020,
296 0x2542, 0x00010000, 0x00010000,
297 0x2b05, 0x000003ff, 0x000000f3,
298 0x2b03, 0xffffffff, 0x00001032
299};
300
301static const u32 bonaire_mgcg_cgcg_init[] =
302{
303 0x3108, 0xffffffff, 0xfffffffc,
304 0xc200, 0xffffffff, 0xe0000000,
305 0xf0a8, 0xffffffff, 0x00000100,
306 0xf082, 0xffffffff, 0x00000100,
307 0xf0b0, 0xffffffff, 0xc0000100,
308 0xf0b2, 0xffffffff, 0xc0000100,
309 0xf0b1, 0xffffffff, 0xc0000100,
310 0x1579, 0xffffffff, 0x00600100,
311 0xf0a0, 0xffffffff, 0x00000100,
312 0xf085, 0xffffffff, 0x06000100,
313 0xf088, 0xffffffff, 0x00000100,
314 0xf086, 0xffffffff, 0x06000100,
315 0xf081, 0xffffffff, 0x00000100,
316 0xf0b8, 0xffffffff, 0x00000100,
317 0xf089, 0xffffffff, 0x00000100,
318 0xf080, 0xffffffff, 0x00000100,
319 0xf08c, 0xffffffff, 0x00000100,
320 0xf08d, 0xffffffff, 0x00000100,
321 0xf094, 0xffffffff, 0x00000100,
322 0xf095, 0xffffffff, 0x00000100,
323 0xf096, 0xffffffff, 0x00000100,
324 0xf097, 0xffffffff, 0x00000100,
325 0xf098, 0xffffffff, 0x00000100,
326 0xf09f, 0xffffffff, 0x00000100,
327 0xf09e, 0xffffffff, 0x00000100,
328 0xf084, 0xffffffff, 0x06000100,
329 0xf0a4, 0xffffffff, 0x00000100,
330 0xf09d, 0xffffffff, 0x00000100,
331 0xf0ad, 0xffffffff, 0x00000100,
332 0xf0ac, 0xffffffff, 0x00000100,
333 0xf09c, 0xffffffff, 0x00000100,
334 0xc200, 0xffffffff, 0xe0000000,
335 0xf008, 0xffffffff, 0x00010000,
336 0xf009, 0xffffffff, 0x00030002,
337 0xf00a, 0xffffffff, 0x00040007,
338 0xf00b, 0xffffffff, 0x00060005,
339 0xf00c, 0xffffffff, 0x00090008,
340 0xf00d, 0xffffffff, 0x00010000,
341 0xf00e, 0xffffffff, 0x00030002,
342 0xf00f, 0xffffffff, 0x00040007,
343 0xf010, 0xffffffff, 0x00060005,
344 0xf011, 0xffffffff, 0x00090008,
345 0xf012, 0xffffffff, 0x00010000,
346 0xf013, 0xffffffff, 0x00030002,
347 0xf014, 0xffffffff, 0x00040007,
348 0xf015, 0xffffffff, 0x00060005,
349 0xf016, 0xffffffff, 0x00090008,
350 0xf017, 0xffffffff, 0x00010000,
351 0xf018, 0xffffffff, 0x00030002,
352 0xf019, 0xffffffff, 0x00040007,
353 0xf01a, 0xffffffff, 0x00060005,
354 0xf01b, 0xffffffff, 0x00090008,
355 0xf01c, 0xffffffff, 0x00010000,
356 0xf01d, 0xffffffff, 0x00030002,
357 0xf01e, 0xffffffff, 0x00040007,
358 0xf01f, 0xffffffff, 0x00060005,
359 0xf020, 0xffffffff, 0x00090008,
360 0xf021, 0xffffffff, 0x00010000,
361 0xf022, 0xffffffff, 0x00030002,
362 0xf023, 0xffffffff, 0x00040007,
363 0xf024, 0xffffffff, 0x00060005,
364 0xf025, 0xffffffff, 0x00090008,
365 0xf026, 0xffffffff, 0x00010000,
366 0xf027, 0xffffffff, 0x00030002,
367 0xf028, 0xffffffff, 0x00040007,
368 0xf029, 0xffffffff, 0x00060005,
369 0xf02a, 0xffffffff, 0x00090008,
370 0xf000, 0xffffffff, 0x96e00200,
371 0x21c2, 0xffffffff, 0x00900100,
372 0x3109, 0xffffffff, 0x0020003f,
373 0xe, 0xffffffff, 0x0140001c,
374 0xf, 0x000f0000, 0x000f0000,
375 0x88, 0xffffffff, 0xc060000c,
376 0x89, 0xc0000fff, 0x00000100,
377 0x3e4, 0xffffffff, 0x00000100,
378 0x3e6, 0x00000101, 0x00000000,
379 0x82a, 0xffffffff, 0x00000104,
380 0x1579, 0xff000fff, 0x00000100,
381 0xc33, 0xc0000fff, 0x00000104,
382 0x3079, 0x00000001, 0x00000001,
383 0x3403, 0xff000ff0, 0x00000100,
384 0x3603, 0xff000ff0, 0x00000100
385};
386
387static const u32 spectre_golden_spm_registers[] =
388{
389 0xc200, 0xe0ffffff, 0xe0000000
390};
391
392static const u32 spectre_golden_common_registers[] =
393{
394 0x31dc, 0xffffffff, 0x00000800,
395 0x31dd, 0xffffffff, 0x00000800,
396 0x31e6, 0xffffffff, 0x00007fbf,
397 0x31e7, 0xffffffff, 0x00007faf
398};
399
400static const u32 spectre_golden_registers[] =
401{
402 0xf000, 0xffff1fff, 0x96940200,
403 0xf003, 0xffff0001, 0xff000000,
404 0xf080, 0xfffc0fff, 0x00000100,
405 0x1bb6, 0x00010101, 0x00010000,
406 0x260d, 0xf00fffff, 0x00000400,
407 0x260e, 0xfffffffc, 0x00020200,
408 0x16ec, 0x000000f0, 0x00000070,
409 0x16f0, 0xf0311fff, 0x80300000,
410 0x263e, 0x73773777, 0x12010001,
411 0x26df, 0x00ff0000, 0x00fc0000,
412 0xbd2, 0x73773777, 0x12010001,
413 0x2285, 0xf000003f, 0x00000007,
414 0x22c9, 0xffffffff, 0x00ffffff,
415 0xa0d4, 0x3f3f3fff, 0x00000082,
416 0xa0d5, 0x0000003f, 0x00000000,
417 0xf9e, 0x00000001, 0x00000002,
418 0x244f, 0xffff03df, 0x00000004,
419 0x31da, 0x00000008, 0x00000008,
420 0x2300, 0x000008ff, 0x00000800,
421 0x2542, 0x00010000, 0x00010000,
422 0x2b03, 0xffffffff, 0x54763210,
423 0x853e, 0x01ff01ff, 0x00000002,
424 0x8526, 0x007ff800, 0x00200000,
425 0x8057, 0xffffffff, 0x00000f40,
426 0xc24d, 0xffffffff, 0x00000001
427};
428
429static const u32 spectre_mgcg_cgcg_init[] =
430{
431 0x3108, 0xffffffff, 0xfffffffc,
432 0xc200, 0xffffffff, 0xe0000000,
433 0xf0a8, 0xffffffff, 0x00000100,
434 0xf082, 0xffffffff, 0x00000100,
435 0xf0b0, 0xffffffff, 0x00000100,
436 0xf0b2, 0xffffffff, 0x00000100,
437 0xf0b1, 0xffffffff, 0x00000100,
438 0x1579, 0xffffffff, 0x00600100,
439 0xf0a0, 0xffffffff, 0x00000100,
440 0xf085, 0xffffffff, 0x06000100,
441 0xf088, 0xffffffff, 0x00000100,
442 0xf086, 0xffffffff, 0x06000100,
443 0xf081, 0xffffffff, 0x00000100,
444 0xf0b8, 0xffffffff, 0x00000100,
445 0xf089, 0xffffffff, 0x00000100,
446 0xf080, 0xffffffff, 0x00000100,
447 0xf08c, 0xffffffff, 0x00000100,
448 0xf08d, 0xffffffff, 0x00000100,
449 0xf094, 0xffffffff, 0x00000100,
450 0xf095, 0xffffffff, 0x00000100,
451 0xf096, 0xffffffff, 0x00000100,
452 0xf097, 0xffffffff, 0x00000100,
453 0xf098, 0xffffffff, 0x00000100,
454 0xf09f, 0xffffffff, 0x00000100,
455 0xf09e, 0xffffffff, 0x00000100,
456 0xf084, 0xffffffff, 0x06000100,
457 0xf0a4, 0xffffffff, 0x00000100,
458 0xf09d, 0xffffffff, 0x00000100,
459 0xf0ad, 0xffffffff, 0x00000100,
460 0xf0ac, 0xffffffff, 0x00000100,
461 0xf09c, 0xffffffff, 0x00000100,
462 0xc200, 0xffffffff, 0xe0000000,
463 0xf008, 0xffffffff, 0x00010000,
464 0xf009, 0xffffffff, 0x00030002,
465 0xf00a, 0xffffffff, 0x00040007,
466 0xf00b, 0xffffffff, 0x00060005,
467 0xf00c, 0xffffffff, 0x00090008,
468 0xf00d, 0xffffffff, 0x00010000,
469 0xf00e, 0xffffffff, 0x00030002,
470 0xf00f, 0xffffffff, 0x00040007,
471 0xf010, 0xffffffff, 0x00060005,
472 0xf011, 0xffffffff, 0x00090008,
473 0xf012, 0xffffffff, 0x00010000,
474 0xf013, 0xffffffff, 0x00030002,
475 0xf014, 0xffffffff, 0x00040007,
476 0xf015, 0xffffffff, 0x00060005,
477 0xf016, 0xffffffff, 0x00090008,
478 0xf017, 0xffffffff, 0x00010000,
479 0xf018, 0xffffffff, 0x00030002,
480 0xf019, 0xffffffff, 0x00040007,
481 0xf01a, 0xffffffff, 0x00060005,
482 0xf01b, 0xffffffff, 0x00090008,
483 0xf01c, 0xffffffff, 0x00010000,
484 0xf01d, 0xffffffff, 0x00030002,
485 0xf01e, 0xffffffff, 0x00040007,
486 0xf01f, 0xffffffff, 0x00060005,
487 0xf020, 0xffffffff, 0x00090008,
488 0xf021, 0xffffffff, 0x00010000,
489 0xf022, 0xffffffff, 0x00030002,
490 0xf023, 0xffffffff, 0x00040007,
491 0xf024, 0xffffffff, 0x00060005,
492 0xf025, 0xffffffff, 0x00090008,
493 0xf026, 0xffffffff, 0x00010000,
494 0xf027, 0xffffffff, 0x00030002,
495 0xf028, 0xffffffff, 0x00040007,
496 0xf029, 0xffffffff, 0x00060005,
497 0xf02a, 0xffffffff, 0x00090008,
498 0xf02b, 0xffffffff, 0x00010000,
499 0xf02c, 0xffffffff, 0x00030002,
500 0xf02d, 0xffffffff, 0x00040007,
501 0xf02e, 0xffffffff, 0x00060005,
502 0xf02f, 0xffffffff, 0x00090008,
503 0xf000, 0xffffffff, 0x96e00200,
504 0x21c2, 0xffffffff, 0x00900100,
505 0x3109, 0xffffffff, 0x0020003f,
506 0xe, 0xffffffff, 0x0140001c,
507 0xf, 0x000f0000, 0x000f0000,
508 0x88, 0xffffffff, 0xc060000c,
509 0x89, 0xc0000fff, 0x00000100,
510 0x3e4, 0xffffffff, 0x00000100,
511 0x3e6, 0x00000101, 0x00000000,
512 0x82a, 0xffffffff, 0x00000104,
513 0x1579, 0xff000fff, 0x00000100,
514 0xc33, 0xc0000fff, 0x00000104,
515 0x3079, 0x00000001, 0x00000001,
516 0x3403, 0xff000ff0, 0x00000100,
517 0x3603, 0xff000ff0, 0x00000100
518};
519
520static const u32 kalindi_golden_spm_registers[] =
521{
522 0xc200, 0xe0ffffff, 0xe0000000
523};
524
525static const u32 kalindi_golden_common_registers[] =
526{
527 0x31dc, 0xffffffff, 0x00000800,
528 0x31dd, 0xffffffff, 0x00000800,
529 0x31e6, 0xffffffff, 0x00007fbf,
530 0x31e7, 0xffffffff, 0x00007faf
531};
532
533static const u32 kalindi_golden_registers[] =
534{
535 0xf000, 0xffffdfff, 0x6e944040,
536 0x1579, 0xff607fff, 0xfc000100,
537 0xf088, 0xff000fff, 0x00000100,
538 0xf089, 0xff000fff, 0x00000100,
539 0xf080, 0xfffc0fff, 0x00000100,
540 0x1bb6, 0x00010101, 0x00010000,
541 0x260c, 0xffffffff, 0x00000000,
542 0x260d, 0xf00fffff, 0x00000400,
543 0x16ec, 0x000000f0, 0x00000070,
544 0x16f0, 0xf0311fff, 0x80300000,
545 0x263e, 0x73773777, 0x12010001,
546 0x263f, 0xffffffff, 0x00000010,
547 0x26df, 0x00ff0000, 0x00fc0000,
548 0x200c, 0x00001f0f, 0x0000100a,
549 0xbd2, 0x73773777, 0x12010001,
550 0x902, 0x000fffff, 0x000c007f,
551 0x2285, 0xf000003f, 0x00000007,
552 0x22c9, 0x3fff3fff, 0x00ffcfff,
553 0xc281, 0x0000ff0f, 0x00000000,
554 0xa293, 0x07ffffff, 0x06000000,
555 0x136, 0x00000fff, 0x00000100,
556 0xf9e, 0x00000001, 0x00000002,
557 0x31da, 0x00000008, 0x00000008,
558 0x2300, 0x000000ff, 0x00000003,
559 0x853e, 0x01ff01ff, 0x00000002,
560 0x8526, 0x007ff800, 0x00200000,
561 0x8057, 0xffffffff, 0x00000f40,
562 0x2231, 0x001f3ae3, 0x00000082,
563 0x2235, 0x0000001f, 0x00000010,
564 0xc24d, 0xffffffff, 0x00000000
565};
566
567static const u32 kalindi_mgcg_cgcg_init[] =
568{
569 0x3108, 0xffffffff, 0xfffffffc,
570 0xc200, 0xffffffff, 0xe0000000,
571 0xf0a8, 0xffffffff, 0x00000100,
572 0xf082, 0xffffffff, 0x00000100,
573 0xf0b0, 0xffffffff, 0x00000100,
574 0xf0b2, 0xffffffff, 0x00000100,
575 0xf0b1, 0xffffffff, 0x00000100,
576 0x1579, 0xffffffff, 0x00600100,
577 0xf0a0, 0xffffffff, 0x00000100,
578 0xf085, 0xffffffff, 0x06000100,
579 0xf088, 0xffffffff, 0x00000100,
580 0xf086, 0xffffffff, 0x06000100,
581 0xf081, 0xffffffff, 0x00000100,
582 0xf0b8, 0xffffffff, 0x00000100,
583 0xf089, 0xffffffff, 0x00000100,
584 0xf080, 0xffffffff, 0x00000100,
585 0xf08c, 0xffffffff, 0x00000100,
586 0xf08d, 0xffffffff, 0x00000100,
587 0xf094, 0xffffffff, 0x00000100,
588 0xf095, 0xffffffff, 0x00000100,
589 0xf096, 0xffffffff, 0x00000100,
590 0xf097, 0xffffffff, 0x00000100,
591 0xf098, 0xffffffff, 0x00000100,
592 0xf09f, 0xffffffff, 0x00000100,
593 0xf09e, 0xffffffff, 0x00000100,
594 0xf084, 0xffffffff, 0x06000100,
595 0xf0a4, 0xffffffff, 0x00000100,
596 0xf09d, 0xffffffff, 0x00000100,
597 0xf0ad, 0xffffffff, 0x00000100,
598 0xf0ac, 0xffffffff, 0x00000100,
599 0xf09c, 0xffffffff, 0x00000100,
600 0xc200, 0xffffffff, 0xe0000000,
601 0xf008, 0xffffffff, 0x00010000,
602 0xf009, 0xffffffff, 0x00030002,
603 0xf00a, 0xffffffff, 0x00040007,
604 0xf00b, 0xffffffff, 0x00060005,
605 0xf00c, 0xffffffff, 0x00090008,
606 0xf00d, 0xffffffff, 0x00010000,
607 0xf00e, 0xffffffff, 0x00030002,
608 0xf00f, 0xffffffff, 0x00040007,
609 0xf010, 0xffffffff, 0x00060005,
610 0xf011, 0xffffffff, 0x00090008,
611 0xf000, 0xffffffff, 0x96e00200,
612 0x21c2, 0xffffffff, 0x00900100,
613 0x3109, 0xffffffff, 0x0020003f,
614 0xe, 0xffffffff, 0x0140001c,
615 0xf, 0x000f0000, 0x000f0000,
616 0x88, 0xffffffff, 0xc060000c,
617 0x89, 0xc0000fff, 0x00000100,
618 0x82a, 0xffffffff, 0x00000104,
619 0x1579, 0xff000fff, 0x00000100,
620 0xc33, 0xc0000fff, 0x00000104,
621 0x3079, 0x00000001, 0x00000001,
622 0x3403, 0xff000ff0, 0x00000100,
623 0x3603, 0xff000ff0, 0x00000100
624};
625
626static const u32 hawaii_golden_spm_registers[] =
627{
628 0xc200, 0xe0ffffff, 0xe0000000
629};
630
631static const u32 hawaii_golden_common_registers[] =
632{
633 0xc200, 0xffffffff, 0xe0000000,
634 0xa0d4, 0xffffffff, 0x3a00161a,
635 0xa0d5, 0xffffffff, 0x0000002e,
636 0x2684, 0xffffffff, 0x00018208,
637 0x263e, 0xffffffff, 0x12011003
638};
639
640static const u32 hawaii_golden_registers[] =
641{
642 0xcd5, 0x00000333, 0x00000333,
643 0x2684, 0x00010000, 0x00058208,
644 0x260c, 0xffffffff, 0x00000000,
645 0x260d, 0xf00fffff, 0x00000400,
646 0x260e, 0x0002021c, 0x00020200,
647 0x31e, 0x00000080, 0x00000000,
648 0x16ec, 0x000000f0, 0x00000070,
649 0x16f0, 0xf0311fff, 0x80300000,
650 0xd43, 0x00810000, 0x408af000,
651 0x1c0c, 0x31000111, 0x00000011,
652 0xbd2, 0x73773777, 0x12010001,
653 0x848, 0x0000007f, 0x0000001b,
654 0x877, 0x00007fb6, 0x00002191,
655 0xd8a, 0x0000003f, 0x0000000a,
656 0xd8b, 0x0000003f, 0x0000000a,
657 0xab9, 0x00073ffe, 0x000022a2,
658 0x903, 0x000007ff, 0x00000000,
659 0x22fc, 0x00002001, 0x00000001,
660 0x22c9, 0xffffffff, 0x00ffffff,
661 0xc281, 0x0000ff0f, 0x00000000,
662 0xa293, 0x07ffffff, 0x06000000,
663 0xf9e, 0x00000001, 0x00000002,
664 0x31da, 0x00000008, 0x00000008,
665 0x31dc, 0x00000f00, 0x00000800,
666 0x31dd, 0x00000f00, 0x00000800,
667 0x31e6, 0x00ffffff, 0x00ff7fbf,
668 0x31e7, 0x00ffffff, 0x00ff7faf,
669 0x2300, 0x000000ff, 0x00000800,
670 0x390, 0x00001fff, 0x00001fff,
671 0x2418, 0x0000007f, 0x00000020,
672 0x2542, 0x00010000, 0x00010000,
673 0x2b80, 0x00100000, 0x000ff07c,
674 0x2b05, 0x000003ff, 0x0000000f,
675 0x2b04, 0xffffffff, 0x7564fdec,
676 0x2b03, 0xffffffff, 0x3120b9a8,
677 0x2b02, 0x20000000, 0x0f9c0000
678};
679
680static const u32 hawaii_mgcg_cgcg_init[] =
681{
682 0x3108, 0xffffffff, 0xfffffffd,
683 0xc200, 0xffffffff, 0xe0000000,
684 0xf0a8, 0xffffffff, 0x00000100,
685 0xf082, 0xffffffff, 0x00000100,
686 0xf0b0, 0xffffffff, 0x00000100,
687 0xf0b2, 0xffffffff, 0x00000100,
688 0xf0b1, 0xffffffff, 0x00000100,
689 0x1579, 0xffffffff, 0x00200100,
690 0xf0a0, 0xffffffff, 0x00000100,
691 0xf085, 0xffffffff, 0x06000100,
692 0xf088, 0xffffffff, 0x00000100,
693 0xf086, 0xffffffff, 0x06000100,
694 0xf081, 0xffffffff, 0x00000100,
695 0xf0b8, 0xffffffff, 0x00000100,
696 0xf089, 0xffffffff, 0x00000100,
697 0xf080, 0xffffffff, 0x00000100,
698 0xf08c, 0xffffffff, 0x00000100,
699 0xf08d, 0xffffffff, 0x00000100,
700 0xf094, 0xffffffff, 0x00000100,
701 0xf095, 0xffffffff, 0x00000100,
702 0xf096, 0xffffffff, 0x00000100,
703 0xf097, 0xffffffff, 0x00000100,
704 0xf098, 0xffffffff, 0x00000100,
705 0xf09f, 0xffffffff, 0x00000100,
706 0xf09e, 0xffffffff, 0x00000100,
707 0xf084, 0xffffffff, 0x06000100,
708 0xf0a4, 0xffffffff, 0x00000100,
709 0xf09d, 0xffffffff, 0x00000100,
710 0xf0ad, 0xffffffff, 0x00000100,
711 0xf0ac, 0xffffffff, 0x00000100,
712 0xf09c, 0xffffffff, 0x00000100,
713 0xc200, 0xffffffff, 0xe0000000,
714 0xf008, 0xffffffff, 0x00010000,
715 0xf009, 0xffffffff, 0x00030002,
716 0xf00a, 0xffffffff, 0x00040007,
717 0xf00b, 0xffffffff, 0x00060005,
718 0xf00c, 0xffffffff, 0x00090008,
719 0xf00d, 0xffffffff, 0x00010000,
720 0xf00e, 0xffffffff, 0x00030002,
721 0xf00f, 0xffffffff, 0x00040007,
722 0xf010, 0xffffffff, 0x00060005,
723 0xf011, 0xffffffff, 0x00090008,
724 0xf012, 0xffffffff, 0x00010000,
725 0xf013, 0xffffffff, 0x00030002,
726 0xf014, 0xffffffff, 0x00040007,
727 0xf015, 0xffffffff, 0x00060005,
728 0xf016, 0xffffffff, 0x00090008,
729 0xf017, 0xffffffff, 0x00010000,
730 0xf018, 0xffffffff, 0x00030002,
731 0xf019, 0xffffffff, 0x00040007,
732 0xf01a, 0xffffffff, 0x00060005,
733 0xf01b, 0xffffffff, 0x00090008,
734 0xf01c, 0xffffffff, 0x00010000,
735 0xf01d, 0xffffffff, 0x00030002,
736 0xf01e, 0xffffffff, 0x00040007,
737 0xf01f, 0xffffffff, 0x00060005,
738 0xf020, 0xffffffff, 0x00090008,
739 0xf021, 0xffffffff, 0x00010000,
740 0xf022, 0xffffffff, 0x00030002,
741 0xf023, 0xffffffff, 0x00040007,
742 0xf024, 0xffffffff, 0x00060005,
743 0xf025, 0xffffffff, 0x00090008,
744 0xf026, 0xffffffff, 0x00010000,
745 0xf027, 0xffffffff, 0x00030002,
746 0xf028, 0xffffffff, 0x00040007,
747 0xf029, 0xffffffff, 0x00060005,
748 0xf02a, 0xffffffff, 0x00090008,
749 0xf02b, 0xffffffff, 0x00010000,
750 0xf02c, 0xffffffff, 0x00030002,
751 0xf02d, 0xffffffff, 0x00040007,
752 0xf02e, 0xffffffff, 0x00060005,
753 0xf02f, 0xffffffff, 0x00090008,
754 0xf030, 0xffffffff, 0x00010000,
755 0xf031, 0xffffffff, 0x00030002,
756 0xf032, 0xffffffff, 0x00040007,
757 0xf033, 0xffffffff, 0x00060005,
758 0xf034, 0xffffffff, 0x00090008,
759 0xf035, 0xffffffff, 0x00010000,
760 0xf036, 0xffffffff, 0x00030002,
761 0xf037, 0xffffffff, 0x00040007,
762 0xf038, 0xffffffff, 0x00060005,
763 0xf039, 0xffffffff, 0x00090008,
764 0xf03a, 0xffffffff, 0x00010000,
765 0xf03b, 0xffffffff, 0x00030002,
766 0xf03c, 0xffffffff, 0x00040007,
767 0xf03d, 0xffffffff, 0x00060005,
768 0xf03e, 0xffffffff, 0x00090008,
769 0x30c6, 0xffffffff, 0x00020200,
770 0xcd4, 0xffffffff, 0x00000200,
771 0x570, 0xffffffff, 0x00000400,
772 0x157a, 0xffffffff, 0x00000000,
773 0xbd4, 0xffffffff, 0x00000902,
774 0xf000, 0xffffffff, 0x96940200,
775 0x21c2, 0xffffffff, 0x00900100,
776 0x3109, 0xffffffff, 0x0020003f,
777 0xe, 0xffffffff, 0x0140001c,
778 0xf, 0x000f0000, 0x000f0000,
779 0x88, 0xffffffff, 0xc060000c,
780 0x89, 0xc0000fff, 0x00000100,
781 0x3e4, 0xffffffff, 0x00000100,
782 0x3e6, 0x00000101, 0x00000000,
783 0x82a, 0xffffffff, 0x00000104,
784 0x1579, 0xff000fff, 0x00000100,
785 0xc33, 0xc0000fff, 0x00000104,
786 0x3079, 0x00000001, 0x00000001,
787 0x3403, 0xff000ff0, 0x00000100,
788 0x3603, 0xff000ff0, 0x00000100
789};
790
791static const u32 godavari_golden_registers[] =
792{
793 0x1579, 0xff607fff, 0xfc000100,
794 0x1bb6, 0x00010101, 0x00010000,
795 0x260c, 0xffffffff, 0x00000000,
796 0x260c0, 0xf00fffff, 0x00000400,
797 0x184c, 0xffffffff, 0x00010000,
798 0x16ec, 0x000000f0, 0x00000070,
799 0x16f0, 0xf0311fff, 0x80300000,
800 0x263e, 0x73773777, 0x12010001,
801 0x263f, 0xffffffff, 0x00000010,
802 0x200c, 0x00001f0f, 0x0000100a,
803 0xbd2, 0x73773777, 0x12010001,
804 0x902, 0x000fffff, 0x000c007f,
805 0x2285, 0xf000003f, 0x00000007,
806 0x22c9, 0xffffffff, 0x00ff0fff,
807 0xc281, 0x0000ff0f, 0x00000000,
808 0xa293, 0x07ffffff, 0x06000000,
809 0x136, 0x00000fff, 0x00000100,
810 0x3405, 0x00010000, 0x00810001,
811 0x3605, 0x00010000, 0x00810001,
812 0xf9e, 0x00000001, 0x00000002,
813 0x31da, 0x00000008, 0x00000008,
814 0x31dc, 0x00000f00, 0x00000800,
815 0x31dd, 0x00000f00, 0x00000800,
816 0x31e6, 0x00ffffff, 0x00ff7fbf,
817 0x31e7, 0x00ffffff, 0x00ff7faf,
818 0x2300, 0x000000ff, 0x00000001,
819 0x853e, 0x01ff01ff, 0x00000002,
820 0x8526, 0x007ff800, 0x00200000,
821 0x8057, 0xffffffff, 0x00000f40,
822 0x2231, 0x001f3ae3, 0x00000082,
823 0x2235, 0x0000001f, 0x00000010,
824 0xc24d, 0xffffffff, 0x00000000
825};
826
827static void cik_init_golden_registers(struct amdgpu_device *adev)
828{
829 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
830 mutex_lock(&adev->grbm_idx_mutex);
831
832 switch (adev->asic_type) {
833 case CHIP_BONAIRE:
834 amdgpu_device_program_register_sequence(adev,
835 bonaire_mgcg_cgcg_init,
836 ARRAY_SIZE(bonaire_mgcg_cgcg_init));
837 amdgpu_device_program_register_sequence(adev,
838 bonaire_golden_registers,
839 ARRAY_SIZE(bonaire_golden_registers));
840 amdgpu_device_program_register_sequence(adev,
841 bonaire_golden_common_registers,
842 ARRAY_SIZE(bonaire_golden_common_registers));
843 amdgpu_device_program_register_sequence(adev,
844 bonaire_golden_spm_registers,
845 ARRAY_SIZE(bonaire_golden_spm_registers));
846 break;
847 case CHIP_KABINI:
848 amdgpu_device_program_register_sequence(adev,
849 kalindi_mgcg_cgcg_init,
850 ARRAY_SIZE(kalindi_mgcg_cgcg_init));
851 amdgpu_device_program_register_sequence(adev,
852 kalindi_golden_registers,
853 ARRAY_SIZE(kalindi_golden_registers));
854 amdgpu_device_program_register_sequence(adev,
855 kalindi_golden_common_registers,
856 ARRAY_SIZE(kalindi_golden_common_registers));
857 amdgpu_device_program_register_sequence(adev,
858 kalindi_golden_spm_registers,
859 ARRAY_SIZE(kalindi_golden_spm_registers));
860 break;
861 case CHIP_MULLINS:
862 amdgpu_device_program_register_sequence(adev,
863 kalindi_mgcg_cgcg_init,
864 ARRAY_SIZE(kalindi_mgcg_cgcg_init));
865 amdgpu_device_program_register_sequence(adev,
866 godavari_golden_registers,
867 ARRAY_SIZE(godavari_golden_registers));
868 amdgpu_device_program_register_sequence(adev,
869 kalindi_golden_common_registers,
870 ARRAY_SIZE(kalindi_golden_common_registers));
871 amdgpu_device_program_register_sequence(adev,
872 kalindi_golden_spm_registers,
873 ARRAY_SIZE(kalindi_golden_spm_registers));
874 break;
875 case CHIP_KAVERI:
876 amdgpu_device_program_register_sequence(adev,
877 spectre_mgcg_cgcg_init,
878 ARRAY_SIZE(spectre_mgcg_cgcg_init));
879 amdgpu_device_program_register_sequence(adev,
880 spectre_golden_registers,
881 ARRAY_SIZE(spectre_golden_registers));
882 amdgpu_device_program_register_sequence(adev,
883 spectre_golden_common_registers,
884 ARRAY_SIZE(spectre_golden_common_registers));
885 amdgpu_device_program_register_sequence(adev,
886 spectre_golden_spm_registers,
887 ARRAY_SIZE(spectre_golden_spm_registers));
888 break;
889 case CHIP_HAWAII:
890 amdgpu_device_program_register_sequence(adev,
891 hawaii_mgcg_cgcg_init,
892 ARRAY_SIZE(hawaii_mgcg_cgcg_init));
893 amdgpu_device_program_register_sequence(adev,
894 hawaii_golden_registers,
895 ARRAY_SIZE(hawaii_golden_registers));
896 amdgpu_device_program_register_sequence(adev,
897 hawaii_golden_common_registers,
898 ARRAY_SIZE(hawaii_golden_common_registers));
899 amdgpu_device_program_register_sequence(adev,
900 hawaii_golden_spm_registers,
901 ARRAY_SIZE(hawaii_golden_spm_registers));
902 break;
903 default:
904 break;
905 }
906 mutex_unlock(&adev->grbm_idx_mutex);
907}
908
909/**
910 * cik_get_xclk - get the xclk
911 *
912 * @adev: amdgpu_device pointer
913 *
914 * Returns the reference clock used by the gfx engine
915 * (CIK).
916 */
917static u32 cik_get_xclk(struct amdgpu_device *adev)
918{
919 u32 reference_clock = adev->clock.spll.reference_freq;
920
921 if (adev->flags & AMD_IS_APU) {
922 if (RREG32_SMC(ixGENERAL_PWRMGT) & GENERAL_PWRMGT__GPU_COUNTER_CLK_MASK)
923 return reference_clock / 2;
924 } else {
925 if (RREG32_SMC(ixCG_CLKPIN_CNTL) & CG_CLKPIN_CNTL__XTALIN_DIVIDE_MASK)
926 return reference_clock / 4;
927 }
928 return reference_clock;
929}
930
931/**
932 * cik_srbm_select - select specific register instances
933 *
934 * @adev: amdgpu_device pointer
935 * @me: selected ME (micro engine)
936 * @pipe: pipe
937 * @queue: queue
938 * @vmid: VMID
939 *
940 * Switches the currently active registers instances. Some
941 * registers are instanced per VMID, others are instanced per
942 * me/pipe/queue combination.
943 */
944void cik_srbm_select(struct amdgpu_device *adev,
945 u32 me, u32 pipe, u32 queue, u32 vmid)
946{
947 u32 srbm_gfx_cntl =
948 (((pipe << SRBM_GFX_CNTL__PIPEID__SHIFT) & SRBM_GFX_CNTL__PIPEID_MASK)|
949 ((me << SRBM_GFX_CNTL__MEID__SHIFT) & SRBM_GFX_CNTL__MEID_MASK)|
950 ((vmid << SRBM_GFX_CNTL__VMID__SHIFT) & SRBM_GFX_CNTL__VMID_MASK)|
951 ((queue << SRBM_GFX_CNTL__QUEUEID__SHIFT) & SRBM_GFX_CNTL__QUEUEID_MASK));
952 WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
953}
954
955static void cik_vga_set_state(struct amdgpu_device *adev, bool state)
956{
957 uint32_t tmp;
958
959 tmp = RREG32(mmCONFIG_CNTL);
960 if (!state)
961 tmp |= CONFIG_CNTL__VGA_DIS_MASK;
962 else
963 tmp &= ~CONFIG_CNTL__VGA_DIS_MASK;
964 WREG32(mmCONFIG_CNTL, tmp);
965}
966
967static bool cik_read_disabled_bios(struct amdgpu_device *adev)
968{
969 u32 bus_cntl;
970 u32 d1vga_control = 0;
971 u32 d2vga_control = 0;
972 u32 vga_render_control = 0;
973 u32 rom_cntl;
974 bool r;
975
976 bus_cntl = RREG32(mmBUS_CNTL);
977 if (adev->mode_info.num_crtc) {
978 d1vga_control = RREG32(mmD1VGA_CONTROL);
979 d2vga_control = RREG32(mmD2VGA_CONTROL);
980 vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
981 }
982 rom_cntl = RREG32_SMC(ixROM_CNTL);
983
984 /* enable the rom */
985 WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
986 if (adev->mode_info.num_crtc) {
987 /* Disable VGA mode */
988 WREG32(mmD1VGA_CONTROL,
989 (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
990 D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
991 WREG32(mmD2VGA_CONTROL,
992 (d2vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
993 D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
994 WREG32(mmVGA_RENDER_CONTROL,
995 (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
996 }
997 WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
998
999 r = amdgpu_read_bios(adev);
1000
1001 /* restore regs */
1002 WREG32(mmBUS_CNTL, bus_cntl);
1003 if (adev->mode_info.num_crtc) {
1004 WREG32(mmD1VGA_CONTROL, d1vga_control);
1005 WREG32(mmD2VGA_CONTROL, d2vga_control);
1006 WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
1007 }
1008 WREG32_SMC(ixROM_CNTL, rom_cntl);
1009 return r;
1010}
1011
1012static bool cik_read_bios_from_rom(struct amdgpu_device *adev,
1013 u8 *bios, u32 length_bytes)
1014{
1015 u32 *dw_ptr;
1016 unsigned long flags;
1017 u32 i, length_dw;
1018
1019 if (bios == NULL)
1020 return false;
1021 if (length_bytes == 0)
1022 return false;
1023 /* APU vbios image is part of sbios image */
1024 if (adev->flags & AMD_IS_APU)
1025 return false;
1026
1027 dw_ptr = (u32 *)bios;
1028 length_dw = ALIGN(length_bytes, 4) / 4;
1029 /* take the smc lock since we are using the smc index */
1030 spin_lock_irqsave(&adev->smc_idx_lock, flags);
1031 /* set rom index to 0 */
1032 WREG32(mmSMC_IND_INDEX_0, ixROM_INDEX);
1033 WREG32(mmSMC_IND_DATA_0, 0);
1034 /* set index to data for continous read */
1035 WREG32(mmSMC_IND_INDEX_0, ixROM_DATA);
1036 for (i = 0; i < length_dw; i++)
1037 dw_ptr[i] = RREG32(mmSMC_IND_DATA_0);
1038 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
1039
1040 return true;
1041}
1042
1043static const struct amdgpu_allowed_register_entry cik_allowed_read_registers[] = {
1044 {mmGRBM_STATUS},
1045 {mmGRBM_STATUS2},
1046 {mmGRBM_STATUS_SE0},
1047 {mmGRBM_STATUS_SE1},
1048 {mmGRBM_STATUS_SE2},
1049 {mmGRBM_STATUS_SE3},
1050 {mmSRBM_STATUS},
1051 {mmSRBM_STATUS2},
1052 {mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET},
1053 {mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET},
1054 {mmCP_STAT},
1055 {mmCP_STALLED_STAT1},
1056 {mmCP_STALLED_STAT2},
1057 {mmCP_STALLED_STAT3},
1058 {mmCP_CPF_BUSY_STAT},
1059 {mmCP_CPF_STALLED_STAT1},
1060 {mmCP_CPF_STATUS},
1061 {mmCP_CPC_BUSY_STAT},
1062 {mmCP_CPC_STALLED_STAT1},
1063 {mmCP_CPC_STATUS},
1064 {mmGB_ADDR_CONFIG},
1065 {mmMC_ARB_RAMCFG},
1066 {mmGB_TILE_MODE0},
1067 {mmGB_TILE_MODE1},
1068 {mmGB_TILE_MODE2},
1069 {mmGB_TILE_MODE3},
1070 {mmGB_TILE_MODE4},
1071 {mmGB_TILE_MODE5},
1072 {mmGB_TILE_MODE6},
1073 {mmGB_TILE_MODE7},
1074 {mmGB_TILE_MODE8},
1075 {mmGB_TILE_MODE9},
1076 {mmGB_TILE_MODE10},
1077 {mmGB_TILE_MODE11},
1078 {mmGB_TILE_MODE12},
1079 {mmGB_TILE_MODE13},
1080 {mmGB_TILE_MODE14},
1081 {mmGB_TILE_MODE15},
1082 {mmGB_TILE_MODE16},
1083 {mmGB_TILE_MODE17},
1084 {mmGB_TILE_MODE18},
1085 {mmGB_TILE_MODE19},
1086 {mmGB_TILE_MODE20},
1087 {mmGB_TILE_MODE21},
1088 {mmGB_TILE_MODE22},
1089 {mmGB_TILE_MODE23},
1090 {mmGB_TILE_MODE24},
1091 {mmGB_TILE_MODE25},
1092 {mmGB_TILE_MODE26},
1093 {mmGB_TILE_MODE27},
1094 {mmGB_TILE_MODE28},
1095 {mmGB_TILE_MODE29},
1096 {mmGB_TILE_MODE30},
1097 {mmGB_TILE_MODE31},
1098 {mmGB_MACROTILE_MODE0},
1099 {mmGB_MACROTILE_MODE1},
1100 {mmGB_MACROTILE_MODE2},
1101 {mmGB_MACROTILE_MODE3},
1102 {mmGB_MACROTILE_MODE4},
1103 {mmGB_MACROTILE_MODE5},
1104 {mmGB_MACROTILE_MODE6},
1105 {mmGB_MACROTILE_MODE7},
1106 {mmGB_MACROTILE_MODE8},
1107 {mmGB_MACROTILE_MODE9},
1108 {mmGB_MACROTILE_MODE10},
1109 {mmGB_MACROTILE_MODE11},
1110 {mmGB_MACROTILE_MODE12},
1111 {mmGB_MACROTILE_MODE13},
1112 {mmGB_MACROTILE_MODE14},
1113 {mmGB_MACROTILE_MODE15},
1114 {mmCC_RB_BACKEND_DISABLE, true},
1115 {mmGC_USER_RB_BACKEND_DISABLE, true},
1116 {mmGB_BACKEND_MAP, false},
1117 {mmPA_SC_RASTER_CONFIG, true},
1118 {mmPA_SC_RASTER_CONFIG_1, true},
1119};
1120
1121
1122static uint32_t cik_get_register_value(struct amdgpu_device *adev,
1123 bool indexed, u32 se_num,
1124 u32 sh_num, u32 reg_offset)
1125{
1126 if (indexed) {
1127 uint32_t val;
1128 unsigned se_idx = (se_num == 0xffffffff) ? 0 : se_num;
1129 unsigned sh_idx = (sh_num == 0xffffffff) ? 0 : sh_num;
1130
1131 switch (reg_offset) {
1132 case mmCC_RB_BACKEND_DISABLE:
1133 return adev->gfx.config.rb_config[se_idx][sh_idx].rb_backend_disable;
1134 case mmGC_USER_RB_BACKEND_DISABLE:
1135 return adev->gfx.config.rb_config[se_idx][sh_idx].user_rb_backend_disable;
1136 case mmPA_SC_RASTER_CONFIG:
1137 return adev->gfx.config.rb_config[se_idx][sh_idx].raster_config;
1138 case mmPA_SC_RASTER_CONFIG_1:
1139 return adev->gfx.config.rb_config[se_idx][sh_idx].raster_config_1;
1140 }
1141
1142 mutex_lock(&adev->grbm_idx_mutex);
1143 if (se_num != 0xffffffff || sh_num != 0xffffffff)
1144 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff, 0);
1145
1146 val = RREG32(reg_offset);
1147
1148 if (se_num != 0xffffffff || sh_num != 0xffffffff)
1149 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
1150 mutex_unlock(&adev->grbm_idx_mutex);
1151 return val;
1152 } else {
1153 unsigned idx;
1154
1155 switch (reg_offset) {
1156 case mmGB_ADDR_CONFIG:
1157 return adev->gfx.config.gb_addr_config;
1158 case mmMC_ARB_RAMCFG:
1159 return adev->gfx.config.mc_arb_ramcfg;
1160 case mmGB_TILE_MODE0:
1161 case mmGB_TILE_MODE1:
1162 case mmGB_TILE_MODE2:
1163 case mmGB_TILE_MODE3:
1164 case mmGB_TILE_MODE4:
1165 case mmGB_TILE_MODE5:
1166 case mmGB_TILE_MODE6:
1167 case mmGB_TILE_MODE7:
1168 case mmGB_TILE_MODE8:
1169 case mmGB_TILE_MODE9:
1170 case mmGB_TILE_MODE10:
1171 case mmGB_TILE_MODE11:
1172 case mmGB_TILE_MODE12:
1173 case mmGB_TILE_MODE13:
1174 case mmGB_TILE_MODE14:
1175 case mmGB_TILE_MODE15:
1176 case mmGB_TILE_MODE16:
1177 case mmGB_TILE_MODE17:
1178 case mmGB_TILE_MODE18:
1179 case mmGB_TILE_MODE19:
1180 case mmGB_TILE_MODE20:
1181 case mmGB_TILE_MODE21:
1182 case mmGB_TILE_MODE22:
1183 case mmGB_TILE_MODE23:
1184 case mmGB_TILE_MODE24:
1185 case mmGB_TILE_MODE25:
1186 case mmGB_TILE_MODE26:
1187 case mmGB_TILE_MODE27:
1188 case mmGB_TILE_MODE28:
1189 case mmGB_TILE_MODE29:
1190 case mmGB_TILE_MODE30:
1191 case mmGB_TILE_MODE31:
1192 idx = (reg_offset - mmGB_TILE_MODE0);
1193 return adev->gfx.config.tile_mode_array[idx];
1194 case mmGB_MACROTILE_MODE0:
1195 case mmGB_MACROTILE_MODE1:
1196 case mmGB_MACROTILE_MODE2:
1197 case mmGB_MACROTILE_MODE3:
1198 case mmGB_MACROTILE_MODE4:
1199 case mmGB_MACROTILE_MODE5:
1200 case mmGB_MACROTILE_MODE6:
1201 case mmGB_MACROTILE_MODE7:
1202 case mmGB_MACROTILE_MODE8:
1203 case mmGB_MACROTILE_MODE9:
1204 case mmGB_MACROTILE_MODE10:
1205 case mmGB_MACROTILE_MODE11:
1206 case mmGB_MACROTILE_MODE12:
1207 case mmGB_MACROTILE_MODE13:
1208 case mmGB_MACROTILE_MODE14:
1209 case mmGB_MACROTILE_MODE15:
1210 idx = (reg_offset - mmGB_MACROTILE_MODE0);
1211 return adev->gfx.config.macrotile_mode_array[idx];
1212 default:
1213 return RREG32(reg_offset);
1214 }
1215 }
1216}
1217
1218static int cik_read_register(struct amdgpu_device *adev, u32 se_num,
1219 u32 sh_num, u32 reg_offset, u32 *value)
1220{
1221 uint32_t i;
1222
1223 *value = 0;
1224 for (i = 0; i < ARRAY_SIZE(cik_allowed_read_registers); i++) {
1225 bool indexed = cik_allowed_read_registers[i].grbm_indexed;
1226
1227 if (reg_offset != cik_allowed_read_registers[i].reg_offset)
1228 continue;
1229
1230 *value = cik_get_register_value(adev, indexed, se_num, sh_num,
1231 reg_offset);
1232 return 0;
1233 }
1234 return -EINVAL;
1235}
1236
1237struct kv_reset_save_regs {
1238 u32 gmcon_reng_execute;
1239 u32 gmcon_misc;
1240 u32 gmcon_misc3;
1241};
1242
1243static void kv_save_regs_for_reset(struct amdgpu_device *adev,
1244 struct kv_reset_save_regs *save)
1245{
1246 save->gmcon_reng_execute = RREG32(mmGMCON_RENG_EXECUTE);
1247 save->gmcon_misc = RREG32(mmGMCON_MISC);
1248 save->gmcon_misc3 = RREG32(mmGMCON_MISC3);
1249
1250 WREG32(mmGMCON_RENG_EXECUTE, save->gmcon_reng_execute &
1251 ~GMCON_RENG_EXECUTE__RENG_EXECUTE_ON_PWR_UP_MASK);
1252 WREG32(mmGMCON_MISC, save->gmcon_misc &
1253 ~(GMCON_MISC__RENG_EXECUTE_ON_REG_UPDATE_MASK |
1254 GMCON_MISC__STCTRL_STUTTER_EN_MASK));
1255}
1256
1257static void kv_restore_regs_for_reset(struct amdgpu_device *adev,
1258 struct kv_reset_save_regs *save)
1259{
1260 int i;
1261
1262 WREG32(mmGMCON_PGFSM_WRITE, 0);
1263 WREG32(mmGMCON_PGFSM_CONFIG, 0x200010ff);
1264
1265 for (i = 0; i < 5; i++)
1266 WREG32(mmGMCON_PGFSM_WRITE, 0);
1267
1268 WREG32(mmGMCON_PGFSM_WRITE, 0);
1269 WREG32(mmGMCON_PGFSM_CONFIG, 0x300010ff);
1270
1271 for (i = 0; i < 5; i++)
1272 WREG32(mmGMCON_PGFSM_WRITE, 0);
1273
1274 WREG32(mmGMCON_PGFSM_WRITE, 0x210000);
1275 WREG32(mmGMCON_PGFSM_CONFIG, 0xa00010ff);
1276
1277 for (i = 0; i < 5; i++)
1278 WREG32(mmGMCON_PGFSM_WRITE, 0);
1279
1280 WREG32(mmGMCON_PGFSM_WRITE, 0x21003);
1281 WREG32(mmGMCON_PGFSM_CONFIG, 0xb00010ff);
1282
1283 for (i = 0; i < 5; i++)
1284 WREG32(mmGMCON_PGFSM_WRITE, 0);
1285
1286 WREG32(mmGMCON_PGFSM_WRITE, 0x2b00);
1287 WREG32(mmGMCON_PGFSM_CONFIG, 0xc00010ff);
1288
1289 for (i = 0; i < 5; i++)
1290 WREG32(mmGMCON_PGFSM_WRITE, 0);
1291
1292 WREG32(mmGMCON_PGFSM_WRITE, 0);
1293 WREG32(mmGMCON_PGFSM_CONFIG, 0xd00010ff);
1294
1295 for (i = 0; i < 5; i++)
1296 WREG32(mmGMCON_PGFSM_WRITE, 0);
1297
1298 WREG32(mmGMCON_PGFSM_WRITE, 0x420000);
1299 WREG32(mmGMCON_PGFSM_CONFIG, 0x100010ff);
1300
1301 for (i = 0; i < 5; i++)
1302 WREG32(mmGMCON_PGFSM_WRITE, 0);
1303
1304 WREG32(mmGMCON_PGFSM_WRITE, 0x120202);
1305 WREG32(mmGMCON_PGFSM_CONFIG, 0x500010ff);
1306
1307 for (i = 0; i < 5; i++)
1308 WREG32(mmGMCON_PGFSM_WRITE, 0);
1309
1310 WREG32(mmGMCON_PGFSM_WRITE, 0x3e3e36);
1311 WREG32(mmGMCON_PGFSM_CONFIG, 0x600010ff);
1312
1313 for (i = 0; i < 5; i++)
1314 WREG32(mmGMCON_PGFSM_WRITE, 0);
1315
1316 WREG32(mmGMCON_PGFSM_WRITE, 0x373f3e);
1317 WREG32(mmGMCON_PGFSM_CONFIG, 0x700010ff);
1318
1319 for (i = 0; i < 5; i++)
1320 WREG32(mmGMCON_PGFSM_WRITE, 0);
1321
1322 WREG32(mmGMCON_PGFSM_WRITE, 0x3e1332);
1323 WREG32(mmGMCON_PGFSM_CONFIG, 0xe00010ff);
1324
1325 WREG32(mmGMCON_MISC3, save->gmcon_misc3);
1326 WREG32(mmGMCON_MISC, save->gmcon_misc);
1327 WREG32(mmGMCON_RENG_EXECUTE, save->gmcon_reng_execute);
1328}
1329
1330/**
1331 * cik_asic_pci_config_reset - soft reset GPU
1332 *
1333 * @adev: amdgpu_device pointer
1334 *
1335 * Use PCI Config method to reset the GPU.
1336 *
1337 * Returns 0 for success.
1338 */
1339static int cik_asic_pci_config_reset(struct amdgpu_device *adev)
1340{
1341 struct kv_reset_save_regs kv_save = { 0 };
1342 u32 i;
1343 int r = -EINVAL;
1344
1345 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
1346
1347 if (adev->flags & AMD_IS_APU)
1348 kv_save_regs_for_reset(adev, &kv_save);
1349
1350 /* disable BM */
1351 pci_clear_master(adev->pdev);
1352 /* reset */
1353 amdgpu_device_pci_config_reset(adev);
1354
1355 udelay(100);
1356
1357 /* wait for asic to come out of reset */
1358 for (i = 0; i < adev->usec_timeout; i++) {
1359 if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff) {
1360 /* enable BM */
1361 pci_set_master(adev->pdev);
1362 adev->has_hw_reset = true;
1363 r = 0;
1364 break;
1365 }
1366 udelay(1);
1367 }
1368
1369 /* does asic init need to be run first??? */
1370 if (adev->flags & AMD_IS_APU)
1371 kv_restore_regs_for_reset(adev, &kv_save);
1372
1373 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
1374
1375 return r;
1376}
1377
1378static bool cik_asic_supports_baco(struct amdgpu_device *adev)
1379{
1380 switch (adev->asic_type) {
1381 case CHIP_BONAIRE:
1382 case CHIP_HAWAII:
1383 return amdgpu_dpm_is_baco_supported(adev);
1384 default:
1385 return false;
1386 }
1387}
1388
1389static enum amd_reset_method
1390cik_asic_reset_method(struct amdgpu_device *adev)
1391{
1392 bool baco_reset;
1393
1394 if (amdgpu_reset_method == AMD_RESET_METHOD_LEGACY ||
1395 amdgpu_reset_method == AMD_RESET_METHOD_BACO)
1396 return amdgpu_reset_method;
1397
1398 if (amdgpu_reset_method != -1)
1399 dev_warn(adev->dev, "Specified reset:%d isn't supported, using AUTO instead.\n",
1400 amdgpu_reset_method);
1401
1402 switch (adev->asic_type) {
1403 case CHIP_BONAIRE:
1404 case CHIP_HAWAII:
1405 baco_reset = cik_asic_supports_baco(adev);
1406 break;
1407 default:
1408 baco_reset = false;
1409 break;
1410 }
1411
1412 if (baco_reset)
1413 return AMD_RESET_METHOD_BACO;
1414 else
1415 return AMD_RESET_METHOD_LEGACY;
1416}
1417
1418/**
1419 * cik_asic_reset - soft reset GPU
1420 *
1421 * @adev: amdgpu_device pointer
1422 *
1423 * Look up which blocks are hung and attempt
1424 * to reset them.
1425 * Returns 0 for success.
1426 */
1427static int cik_asic_reset(struct amdgpu_device *adev)
1428{
1429 int r;
1430
1431 /* APUs don't have full asic reset */
1432 if (adev->flags & AMD_IS_APU)
1433 return 0;
1434
1435 if (cik_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
1436 dev_info(adev->dev, "BACO reset\n");
1437 r = amdgpu_dpm_baco_reset(adev);
1438 } else {
1439 dev_info(adev->dev, "PCI CONFIG reset\n");
1440 r = cik_asic_pci_config_reset(adev);
1441 }
1442
1443 return r;
1444}
1445
1446static u32 cik_get_config_memsize(struct amdgpu_device *adev)
1447{
1448 return RREG32(mmCONFIG_MEMSIZE);
1449}
1450
1451static int cik_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
1452 u32 cntl_reg, u32 status_reg)
1453{
1454 int r, i;
1455 struct atom_clock_dividers dividers;
1456 uint32_t tmp;
1457
1458 r = amdgpu_atombios_get_clock_dividers(adev,
1459 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
1460 clock, false, ÷rs);
1461 if (r)
1462 return r;
1463
1464 tmp = RREG32_SMC(cntl_reg);
1465 tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
1466 CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
1467 tmp |= dividers.post_divider;
1468 WREG32_SMC(cntl_reg, tmp);
1469
1470 for (i = 0; i < 100; i++) {
1471 if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
1472 break;
1473 mdelay(10);
1474 }
1475 if (i == 100)
1476 return -ETIMEDOUT;
1477
1478 return 0;
1479}
1480
1481static int cik_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
1482{
1483 int r = 0;
1484
1485 r = cik_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
1486 if (r)
1487 return r;
1488
1489 r = cik_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
1490 return r;
1491}
1492
1493static int cik_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
1494{
1495 int r, i;
1496 struct atom_clock_dividers dividers;
1497 u32 tmp;
1498
1499 r = amdgpu_atombios_get_clock_dividers(adev,
1500 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
1501 ecclk, false, ÷rs);
1502 if (r)
1503 return r;
1504
1505 for (i = 0; i < 100; i++) {
1506 if (RREG32_SMC(ixCG_ECLK_STATUS) & CG_ECLK_STATUS__ECLK_STATUS_MASK)
1507 break;
1508 mdelay(10);
1509 }
1510 if (i == 100)
1511 return -ETIMEDOUT;
1512
1513 tmp = RREG32_SMC(ixCG_ECLK_CNTL);
1514 tmp &= ~(CG_ECLK_CNTL__ECLK_DIR_CNTL_EN_MASK |
1515 CG_ECLK_CNTL__ECLK_DIVIDER_MASK);
1516 tmp |= dividers.post_divider;
1517 WREG32_SMC(ixCG_ECLK_CNTL, tmp);
1518
1519 for (i = 0; i < 100; i++) {
1520 if (RREG32_SMC(ixCG_ECLK_STATUS) & CG_ECLK_STATUS__ECLK_STATUS_MASK)
1521 break;
1522 mdelay(10);
1523 }
1524 if (i == 100)
1525 return -ETIMEDOUT;
1526
1527 return 0;
1528}
1529
1530static void cik_pcie_gen3_enable(struct amdgpu_device *adev)
1531{
1532 struct pci_dev *root = adev->pdev->bus->self;
1533 u32 speed_cntl, current_data_rate;
1534 int i;
1535 u16 tmp16;
1536
1537 if (pci_is_root_bus(adev->pdev->bus))
1538 return;
1539
1540 if (amdgpu_pcie_gen2 == 0)
1541 return;
1542
1543 if (adev->flags & AMD_IS_APU)
1544 return;
1545
1546 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
1547 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
1548 return;
1549
1550 speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL);
1551 current_data_rate = (speed_cntl & PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK) >>
1552 PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
1553 if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) {
1554 if (current_data_rate == 2) {
1555 DRM_INFO("PCIE gen 3 link speeds already enabled\n");
1556 return;
1557 }
1558 DRM_INFO("enabling PCIE gen 3 link speeds, disable with amdgpu.pcie_gen2=0\n");
1559 } else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) {
1560 if (current_data_rate == 1) {
1561 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
1562 return;
1563 }
1564 DRM_INFO("enabling PCIE gen 2 link speeds, disable with amdgpu.pcie_gen2=0\n");
1565 }
1566
1567 if (!pci_is_pcie(root) || !pci_is_pcie(adev->pdev))
1568 return;
1569
1570 if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) {
1571 /* re-try equalization if gen3 is not already enabled */
1572 if (current_data_rate != 2) {
1573 u16 bridge_cfg, gpu_cfg;
1574 u16 bridge_cfg2, gpu_cfg2;
1575 u32 max_lw, current_lw, tmp;
1576
1577 pcie_capability_set_word(root, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_HAWD);
1578 pcie_capability_set_word(adev->pdev, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_HAWD);
1579
1580 tmp = RREG32_PCIE(ixPCIE_LC_STATUS1);
1581 max_lw = (tmp & PCIE_LC_STATUS1__LC_DETECTED_LINK_WIDTH_MASK) >>
1582 PCIE_LC_STATUS1__LC_DETECTED_LINK_WIDTH__SHIFT;
1583 current_lw = (tmp & PCIE_LC_STATUS1__LC_OPERATING_LINK_WIDTH_MASK)
1584 >> PCIE_LC_STATUS1__LC_OPERATING_LINK_WIDTH__SHIFT;
1585
1586 if (current_lw < max_lw) {
1587 tmp = RREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL);
1588 if (tmp & PCIE_LC_LINK_WIDTH_CNTL__LC_RENEGOTIATION_SUPPORT_MASK) {
1589 tmp &= ~(PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_MASK |
1590 PCIE_LC_LINK_WIDTH_CNTL__LC_UPCONFIGURE_DIS_MASK);
1591 tmp |= (max_lw <<
1592 PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH__SHIFT);
1593 tmp |= PCIE_LC_LINK_WIDTH_CNTL__LC_UPCONFIGURE_SUPPORT_MASK |
1594 PCIE_LC_LINK_WIDTH_CNTL__LC_RENEGOTIATE_EN_MASK |
1595 PCIE_LC_LINK_WIDTH_CNTL__LC_RECONFIG_NOW_MASK;
1596 WREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL, tmp);
1597 }
1598 }
1599
1600 for (i = 0; i < 10; i++) {
1601 /* check status */
1602 pcie_capability_read_word(adev->pdev,
1603 PCI_EXP_DEVSTA,
1604 &tmp16);
1605 if (tmp16 & PCI_EXP_DEVSTA_TRPND)
1606 break;
1607
1608 pcie_capability_read_word(root, PCI_EXP_LNKCTL,
1609 &bridge_cfg);
1610 pcie_capability_read_word(adev->pdev,
1611 PCI_EXP_LNKCTL,
1612 &gpu_cfg);
1613
1614 pcie_capability_read_word(root, PCI_EXP_LNKCTL2,
1615 &bridge_cfg2);
1616 pcie_capability_read_word(adev->pdev,
1617 PCI_EXP_LNKCTL2,
1618 &gpu_cfg2);
1619
1620 tmp = RREG32_PCIE(ixPCIE_LC_CNTL4);
1621 tmp |= PCIE_LC_CNTL4__LC_SET_QUIESCE_MASK;
1622 WREG32_PCIE(ixPCIE_LC_CNTL4, tmp);
1623
1624 tmp = RREG32_PCIE(ixPCIE_LC_CNTL4);
1625 tmp |= PCIE_LC_CNTL4__LC_REDO_EQ_MASK;
1626 WREG32_PCIE(ixPCIE_LC_CNTL4, tmp);
1627
1628 msleep(100);
1629
1630 /* linkctl */
1631 pcie_capability_clear_and_set_word(root, PCI_EXP_LNKCTL,
1632 PCI_EXP_LNKCTL_HAWD,
1633 bridge_cfg &
1634 PCI_EXP_LNKCTL_HAWD);
1635 pcie_capability_clear_and_set_word(adev->pdev, PCI_EXP_LNKCTL,
1636 PCI_EXP_LNKCTL_HAWD,
1637 gpu_cfg &
1638 PCI_EXP_LNKCTL_HAWD);
1639
1640 /* linkctl2 */
1641 pcie_capability_read_word(root, PCI_EXP_LNKCTL2,
1642 &tmp16);
1643 tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP |
1644 PCI_EXP_LNKCTL2_TX_MARGIN);
1645 tmp16 |= (bridge_cfg2 &
1646 (PCI_EXP_LNKCTL2_ENTER_COMP |
1647 PCI_EXP_LNKCTL2_TX_MARGIN));
1648 pcie_capability_write_word(root,
1649 PCI_EXP_LNKCTL2,
1650 tmp16);
1651
1652 pcie_capability_read_word(adev->pdev,
1653 PCI_EXP_LNKCTL2,
1654 &tmp16);
1655 tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP |
1656 PCI_EXP_LNKCTL2_TX_MARGIN);
1657 tmp16 |= (gpu_cfg2 &
1658 (PCI_EXP_LNKCTL2_ENTER_COMP |
1659 PCI_EXP_LNKCTL2_TX_MARGIN));
1660 pcie_capability_write_word(adev->pdev,
1661 PCI_EXP_LNKCTL2,
1662 tmp16);
1663
1664 tmp = RREG32_PCIE(ixPCIE_LC_CNTL4);
1665 tmp &= ~PCIE_LC_CNTL4__LC_SET_QUIESCE_MASK;
1666 WREG32_PCIE(ixPCIE_LC_CNTL4, tmp);
1667 }
1668 }
1669 }
1670
1671 /* set the link speed */
1672 speed_cntl |= PCIE_LC_SPEED_CNTL__LC_FORCE_EN_SW_SPEED_CHANGE_MASK |
1673 PCIE_LC_SPEED_CNTL__LC_FORCE_DIS_HW_SPEED_CHANGE_MASK;
1674 speed_cntl &= ~PCIE_LC_SPEED_CNTL__LC_FORCE_DIS_SW_SPEED_CHANGE_MASK;
1675 WREG32_PCIE(ixPCIE_LC_SPEED_CNTL, speed_cntl);
1676
1677 pcie_capability_read_word(adev->pdev, PCI_EXP_LNKCTL2, &tmp16);
1678 tmp16 &= ~PCI_EXP_LNKCTL2_TLS;
1679
1680 if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
1681 tmp16 |= PCI_EXP_LNKCTL2_TLS_8_0GT; /* gen3 */
1682 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2)
1683 tmp16 |= PCI_EXP_LNKCTL2_TLS_5_0GT; /* gen2 */
1684 else
1685 tmp16 |= PCI_EXP_LNKCTL2_TLS_2_5GT; /* gen1 */
1686 pcie_capability_write_word(adev->pdev, PCI_EXP_LNKCTL2, tmp16);
1687
1688 speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL);
1689 speed_cntl |= PCIE_LC_SPEED_CNTL__LC_INITIATE_LINK_SPEED_CHANGE_MASK;
1690 WREG32_PCIE(ixPCIE_LC_SPEED_CNTL, speed_cntl);
1691
1692 for (i = 0; i < adev->usec_timeout; i++) {
1693 speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL);
1694 if ((speed_cntl & PCIE_LC_SPEED_CNTL__LC_INITIATE_LINK_SPEED_CHANGE_MASK) == 0)
1695 break;
1696 udelay(1);
1697 }
1698}
1699
1700static void cik_program_aspm(struct amdgpu_device *adev)
1701{
1702 u32 data, orig;
1703 bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
1704 bool disable_clkreq = false;
1705
1706 if (!amdgpu_device_should_use_aspm(adev))
1707 return;
1708
1709 if (pci_is_root_bus(adev->pdev->bus))
1710 return;
1711
1712 orig = data = RREG32_PCIE(ixPCIE_LC_N_FTS_CNTL);
1713 data &= ~PCIE_LC_N_FTS_CNTL__LC_XMIT_N_FTS_MASK;
1714 data |= (0x24 << PCIE_LC_N_FTS_CNTL__LC_XMIT_N_FTS__SHIFT) |
1715 PCIE_LC_N_FTS_CNTL__LC_XMIT_N_FTS_OVERRIDE_EN_MASK;
1716 if (orig != data)
1717 WREG32_PCIE(ixPCIE_LC_N_FTS_CNTL, data);
1718
1719 orig = data = RREG32_PCIE(ixPCIE_LC_CNTL3);
1720 data |= PCIE_LC_CNTL3__LC_GO_TO_RECOVERY_MASK;
1721 if (orig != data)
1722 WREG32_PCIE(ixPCIE_LC_CNTL3, data);
1723
1724 orig = data = RREG32_PCIE(ixPCIE_P_CNTL);
1725 data |= PCIE_P_CNTL__P_IGNORE_EDB_ERR_MASK;
1726 if (orig != data)
1727 WREG32_PCIE(ixPCIE_P_CNTL, data);
1728
1729 orig = data = RREG32_PCIE(ixPCIE_LC_CNTL);
1730 data &= ~(PCIE_LC_CNTL__LC_L0S_INACTIVITY_MASK |
1731 PCIE_LC_CNTL__LC_L1_INACTIVITY_MASK);
1732 data |= PCIE_LC_CNTL__LC_PMI_TO_L1_DIS_MASK;
1733 if (!disable_l0s)
1734 data |= (7 << PCIE_LC_CNTL__LC_L0S_INACTIVITY__SHIFT);
1735
1736 if (!disable_l1) {
1737 data |= (7 << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT);
1738 data &= ~PCIE_LC_CNTL__LC_PMI_TO_L1_DIS_MASK;
1739 if (orig != data)
1740 WREG32_PCIE(ixPCIE_LC_CNTL, data);
1741
1742 if (!disable_plloff_in_l1) {
1743 bool clk_req_support;
1744
1745 orig = data = RREG32_PCIE(ixPB0_PIF_PWRDOWN_0);
1746 data &= ~(PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0_MASK |
1747 PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0_MASK);
1748 data |= (7 << PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0__SHIFT) |
1749 (7 << PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0__SHIFT);
1750 if (orig != data)
1751 WREG32_PCIE(ixPB0_PIF_PWRDOWN_0, data);
1752
1753 orig = data = RREG32_PCIE(ixPB0_PIF_PWRDOWN_1);
1754 data &= ~(PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1_MASK |
1755 PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1_MASK);
1756 data |= (7 << PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1__SHIFT) |
1757 (7 << PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1__SHIFT);
1758 if (orig != data)
1759 WREG32_PCIE(ixPB0_PIF_PWRDOWN_1, data);
1760
1761 orig = data = RREG32_PCIE(ixPB1_PIF_PWRDOWN_0);
1762 data &= ~(PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0_MASK |
1763 PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0_MASK);
1764 data |= (7 << PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0__SHIFT) |
1765 (7 << PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0__SHIFT);
1766 if (orig != data)
1767 WREG32_PCIE(ixPB1_PIF_PWRDOWN_0, data);
1768
1769 orig = data = RREG32_PCIE(ixPB1_PIF_PWRDOWN_1);
1770 data &= ~(PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1_MASK |
1771 PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1_MASK);
1772 data |= (7 << PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1__SHIFT) |
1773 (7 << PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1__SHIFT);
1774 if (orig != data)
1775 WREG32_PCIE(ixPB1_PIF_PWRDOWN_1, data);
1776
1777 orig = data = RREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL);
1778 data &= ~PCIE_LC_LINK_WIDTH_CNTL__LC_DYN_LANES_PWR_STATE_MASK;
1779 data |= ~(3 << PCIE_LC_LINK_WIDTH_CNTL__LC_DYN_LANES_PWR_STATE__SHIFT);
1780 if (orig != data)
1781 WREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL, data);
1782
1783 if (!disable_clkreq) {
1784 struct pci_dev *root = adev->pdev->bus->self;
1785 u32 lnkcap;
1786
1787 clk_req_support = false;
1788 pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
1789 if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
1790 clk_req_support = true;
1791 } else {
1792 clk_req_support = false;
1793 }
1794
1795 if (clk_req_support) {
1796 orig = data = RREG32_PCIE(ixPCIE_LC_CNTL2);
1797 data |= PCIE_LC_CNTL2__LC_ALLOW_PDWN_IN_L1_MASK |
1798 PCIE_LC_CNTL2__LC_ALLOW_PDWN_IN_L23_MASK;
1799 if (orig != data)
1800 WREG32_PCIE(ixPCIE_LC_CNTL2, data);
1801
1802 orig = data = RREG32_SMC(ixTHM_CLK_CNTL);
1803 data &= ~(THM_CLK_CNTL__CMON_CLK_SEL_MASK |
1804 THM_CLK_CNTL__TMON_CLK_SEL_MASK);
1805 data |= (1 << THM_CLK_CNTL__CMON_CLK_SEL__SHIFT) |
1806 (1 << THM_CLK_CNTL__TMON_CLK_SEL__SHIFT);
1807 if (orig != data)
1808 WREG32_SMC(ixTHM_CLK_CNTL, data);
1809
1810 orig = data = RREG32_SMC(ixMISC_CLK_CTRL);
1811 data &= ~(MISC_CLK_CTRL__DEEP_SLEEP_CLK_SEL_MASK |
1812 MISC_CLK_CTRL__ZCLK_SEL_MASK);
1813 data |= (1 << MISC_CLK_CTRL__DEEP_SLEEP_CLK_SEL__SHIFT) |
1814 (1 << MISC_CLK_CTRL__ZCLK_SEL__SHIFT);
1815 if (orig != data)
1816 WREG32_SMC(ixMISC_CLK_CTRL, data);
1817
1818 orig = data = RREG32_SMC(ixCG_CLKPIN_CNTL);
1819 data &= ~CG_CLKPIN_CNTL__BCLK_AS_XCLK_MASK;
1820 if (orig != data)
1821 WREG32_SMC(ixCG_CLKPIN_CNTL, data);
1822
1823 orig = data = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
1824 data &= ~CG_CLKPIN_CNTL_2__FORCE_BIF_REFCLK_EN_MASK;
1825 if (orig != data)
1826 WREG32_SMC(ixCG_CLKPIN_CNTL_2, data);
1827
1828 orig = data = RREG32_SMC(ixMPLL_BYPASSCLK_SEL);
1829 data &= ~MPLL_BYPASSCLK_SEL__MPLL_CLKOUT_SEL_MASK;
1830 data |= (4 << MPLL_BYPASSCLK_SEL__MPLL_CLKOUT_SEL__SHIFT);
1831 if (orig != data)
1832 WREG32_SMC(ixMPLL_BYPASSCLK_SEL, data);
1833 }
1834 }
1835 } else {
1836 if (orig != data)
1837 WREG32_PCIE(ixPCIE_LC_CNTL, data);
1838 }
1839
1840 orig = data = RREG32_PCIE(ixPCIE_CNTL2);
1841 data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
1842 PCIE_CNTL2__MST_MEM_LS_EN_MASK |
1843 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
1844 if (orig != data)
1845 WREG32_PCIE(ixPCIE_CNTL2, data);
1846
1847 if (!disable_l0s) {
1848 data = RREG32_PCIE(ixPCIE_LC_N_FTS_CNTL);
1849 if ((data & PCIE_LC_N_FTS_CNTL__LC_N_FTS_MASK) ==
1850 PCIE_LC_N_FTS_CNTL__LC_N_FTS_MASK) {
1851 data = RREG32_PCIE(ixPCIE_LC_STATUS1);
1852 if ((data & PCIE_LC_STATUS1__LC_REVERSE_XMIT_MASK) &&
1853 (data & PCIE_LC_STATUS1__LC_REVERSE_RCVR_MASK)) {
1854 orig = data = RREG32_PCIE(ixPCIE_LC_CNTL);
1855 data &= ~PCIE_LC_CNTL__LC_L0S_INACTIVITY_MASK;
1856 if (orig != data)
1857 WREG32_PCIE(ixPCIE_LC_CNTL, data);
1858 }
1859 }
1860 }
1861}
1862
1863static uint32_t cik_get_rev_id(struct amdgpu_device *adev)
1864{
1865 return (RREG32(mmCC_DRM_ID_STRAPS) & CC_DRM_ID_STRAPS__ATI_REV_ID_MASK)
1866 >> CC_DRM_ID_STRAPS__ATI_REV_ID__SHIFT;
1867}
1868
1869static void cik_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
1870{
1871 if (!ring || !ring->funcs->emit_wreg) {
1872 WREG32(mmHDP_MEM_COHERENCY_FLUSH_CNTL, 1);
1873 RREG32(mmHDP_MEM_COHERENCY_FLUSH_CNTL);
1874 } else {
1875 amdgpu_ring_emit_wreg(ring, mmHDP_MEM_COHERENCY_FLUSH_CNTL, 1);
1876 }
1877}
1878
1879static void cik_invalidate_hdp(struct amdgpu_device *adev,
1880 struct amdgpu_ring *ring)
1881{
1882 if (!ring || !ring->funcs->emit_wreg) {
1883 WREG32(mmHDP_DEBUG0, 1);
1884 RREG32(mmHDP_DEBUG0);
1885 } else {
1886 amdgpu_ring_emit_wreg(ring, mmHDP_DEBUG0, 1);
1887 }
1888}
1889
1890static bool cik_need_full_reset(struct amdgpu_device *adev)
1891{
1892 /* change this when we support soft reset */
1893 return true;
1894}
1895
1896static void cik_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
1897 uint64_t *count1)
1898{
1899 uint32_t perfctr = 0;
1900 uint64_t cnt0_of, cnt1_of;
1901 int tmp;
1902
1903 /* This reports 0 on APUs, so return to avoid writing/reading registers
1904 * that may or may not be different from their GPU counterparts
1905 */
1906 if (adev->flags & AMD_IS_APU)
1907 return;
1908
1909 /* Set the 2 events that we wish to watch, defined above */
1910 /* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */
1911 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT0_SEL, 40);
1912 perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT1_SEL, 104);
1913
1914 /* Write to enable desired perf counters */
1915 WREG32_PCIE(ixPCIE_PERF_CNTL_TXCLK, perfctr);
1916 /* Zero out and enable the perf counters
1917 * Write 0x5:
1918 * Bit 0 = Start all counters(1)
1919 * Bit 2 = Global counter reset enable(1)
1920 */
1921 WREG32_PCIE(ixPCIE_PERF_COUNT_CNTL, 0x00000005);
1922
1923 msleep(1000);
1924
1925 /* Load the shadow and disable the perf counters
1926 * Write 0x2:
1927 * Bit 0 = Stop counters(0)
1928 * Bit 1 = Load the shadow counters(1)
1929 */
1930 WREG32_PCIE(ixPCIE_PERF_COUNT_CNTL, 0x00000002);
1931
1932 /* Read register values to get any >32bit overflow */
1933 tmp = RREG32_PCIE(ixPCIE_PERF_CNTL_TXCLK);
1934 cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER0_UPPER);
1935 cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER1_UPPER);
1936
1937 /* Get the values and add the overflow */
1938 *count0 = RREG32_PCIE(ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of << 32);
1939 *count1 = RREG32_PCIE(ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << 32);
1940}
1941
1942static bool cik_need_reset_on_init(struct amdgpu_device *adev)
1943{
1944 u32 clock_cntl, pc;
1945
1946 if (adev->flags & AMD_IS_APU)
1947 return false;
1948
1949 /* check if the SMC is already running */
1950 clock_cntl = RREG32_SMC(ixSMC_SYSCON_CLOCK_CNTL_0);
1951 pc = RREG32_SMC(ixSMC_PC_C);
1952 if ((0 == REG_GET_FIELD(clock_cntl, SMC_SYSCON_CLOCK_CNTL_0, ck_disable)) &&
1953 (0x20100 <= pc))
1954 return true;
1955
1956 return false;
1957}
1958
1959static uint64_t cik_get_pcie_replay_count(struct amdgpu_device *adev)
1960{
1961 uint64_t nak_r, nak_g;
1962
1963 /* Get the number of NAKs received and generated */
1964 nak_r = RREG32_PCIE(ixPCIE_RX_NUM_NAK);
1965 nak_g = RREG32_PCIE(ixPCIE_RX_NUM_NAK_GENERATED);
1966
1967 /* Add the total number of NAKs, i.e the number of replays */
1968 return (nak_r + nak_g);
1969}
1970
1971static void cik_pre_asic_init(struct amdgpu_device *adev)
1972{
1973}
1974
1975static const struct amdgpu_asic_funcs cik_asic_funcs =
1976{
1977 .read_disabled_bios = &cik_read_disabled_bios,
1978 .read_bios_from_rom = &cik_read_bios_from_rom,
1979 .read_register = &cik_read_register,
1980 .reset = &cik_asic_reset,
1981 .reset_method = &cik_asic_reset_method,
1982 .set_vga_state = &cik_vga_set_state,
1983 .get_xclk = &cik_get_xclk,
1984 .set_uvd_clocks = &cik_set_uvd_clocks,
1985 .set_vce_clocks = &cik_set_vce_clocks,
1986 .get_config_memsize = &cik_get_config_memsize,
1987 .flush_hdp = &cik_flush_hdp,
1988 .invalidate_hdp = &cik_invalidate_hdp,
1989 .need_full_reset = &cik_need_full_reset,
1990 .init_doorbell_index = &legacy_doorbell_index_init,
1991 .get_pcie_usage = &cik_get_pcie_usage,
1992 .need_reset_on_init = &cik_need_reset_on_init,
1993 .get_pcie_replay_count = &cik_get_pcie_replay_count,
1994 .supports_baco = &cik_asic_supports_baco,
1995 .pre_asic_init = &cik_pre_asic_init,
1996 .query_video_codecs = &cik_query_video_codecs,
1997};
1998
1999static int cik_common_early_init(void *handle)
2000{
2001 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2002
2003 adev->smc_rreg = &cik_smc_rreg;
2004 adev->smc_wreg = &cik_smc_wreg;
2005 adev->pcie_rreg = &cik_pcie_rreg;
2006 adev->pcie_wreg = &cik_pcie_wreg;
2007 adev->uvd_ctx_rreg = &cik_uvd_ctx_rreg;
2008 adev->uvd_ctx_wreg = &cik_uvd_ctx_wreg;
2009 adev->didt_rreg = &cik_didt_rreg;
2010 adev->didt_wreg = &cik_didt_wreg;
2011
2012 adev->asic_funcs = &cik_asic_funcs;
2013
2014 adev->rev_id = cik_get_rev_id(adev);
2015 adev->external_rev_id = 0xFF;
2016 switch (adev->asic_type) {
2017 case CHIP_BONAIRE:
2018 adev->cg_flags =
2019 AMD_CG_SUPPORT_GFX_MGCG |
2020 AMD_CG_SUPPORT_GFX_MGLS |
2021 /*AMD_CG_SUPPORT_GFX_CGCG |*/
2022 AMD_CG_SUPPORT_GFX_CGLS |
2023 AMD_CG_SUPPORT_GFX_CGTS |
2024 AMD_CG_SUPPORT_GFX_CGTS_LS |
2025 AMD_CG_SUPPORT_GFX_CP_LS |
2026 AMD_CG_SUPPORT_MC_LS |
2027 AMD_CG_SUPPORT_MC_MGCG |
2028 AMD_CG_SUPPORT_SDMA_MGCG |
2029 AMD_CG_SUPPORT_SDMA_LS |
2030 AMD_CG_SUPPORT_BIF_LS |
2031 AMD_CG_SUPPORT_VCE_MGCG |
2032 AMD_CG_SUPPORT_UVD_MGCG |
2033 AMD_CG_SUPPORT_HDP_LS |
2034 AMD_CG_SUPPORT_HDP_MGCG;
2035 adev->pg_flags = 0;
2036 adev->external_rev_id = adev->rev_id + 0x14;
2037 break;
2038 case CHIP_HAWAII:
2039 adev->cg_flags =
2040 AMD_CG_SUPPORT_GFX_MGCG |
2041 AMD_CG_SUPPORT_GFX_MGLS |
2042 /*AMD_CG_SUPPORT_GFX_CGCG |*/
2043 AMD_CG_SUPPORT_GFX_CGLS |
2044 AMD_CG_SUPPORT_GFX_CGTS |
2045 AMD_CG_SUPPORT_GFX_CP_LS |
2046 AMD_CG_SUPPORT_MC_LS |
2047 AMD_CG_SUPPORT_MC_MGCG |
2048 AMD_CG_SUPPORT_SDMA_MGCG |
2049 AMD_CG_SUPPORT_SDMA_LS |
2050 AMD_CG_SUPPORT_BIF_LS |
2051 AMD_CG_SUPPORT_VCE_MGCG |
2052 AMD_CG_SUPPORT_UVD_MGCG |
2053 AMD_CG_SUPPORT_HDP_LS |
2054 AMD_CG_SUPPORT_HDP_MGCG;
2055 adev->pg_flags = 0;
2056 adev->external_rev_id = 0x28;
2057 break;
2058 case CHIP_KAVERI:
2059 adev->cg_flags =
2060 AMD_CG_SUPPORT_GFX_MGCG |
2061 AMD_CG_SUPPORT_GFX_MGLS |
2062 /*AMD_CG_SUPPORT_GFX_CGCG |*/
2063 AMD_CG_SUPPORT_GFX_CGLS |
2064 AMD_CG_SUPPORT_GFX_CGTS |
2065 AMD_CG_SUPPORT_GFX_CGTS_LS |
2066 AMD_CG_SUPPORT_GFX_CP_LS |
2067 AMD_CG_SUPPORT_SDMA_MGCG |
2068 AMD_CG_SUPPORT_SDMA_LS |
2069 AMD_CG_SUPPORT_BIF_LS |
2070 AMD_CG_SUPPORT_VCE_MGCG |
2071 AMD_CG_SUPPORT_UVD_MGCG |
2072 AMD_CG_SUPPORT_HDP_LS |
2073 AMD_CG_SUPPORT_HDP_MGCG;
2074 adev->pg_flags =
2075 /*AMD_PG_SUPPORT_GFX_PG |
2076 AMD_PG_SUPPORT_GFX_SMG |
2077 AMD_PG_SUPPORT_GFX_DMG |*/
2078 AMD_PG_SUPPORT_UVD |
2079 AMD_PG_SUPPORT_VCE |
2080 /* AMD_PG_SUPPORT_CP |
2081 AMD_PG_SUPPORT_GDS |
2082 AMD_PG_SUPPORT_RLC_SMU_HS |
2083 AMD_PG_SUPPORT_ACP |
2084 AMD_PG_SUPPORT_SAMU |*/
2085 0;
2086 if (adev->pdev->device == 0x1312 ||
2087 adev->pdev->device == 0x1316 ||
2088 adev->pdev->device == 0x1317)
2089 adev->external_rev_id = 0x41;
2090 else
2091 adev->external_rev_id = 0x1;
2092 break;
2093 case CHIP_KABINI:
2094 case CHIP_MULLINS:
2095 adev->cg_flags =
2096 AMD_CG_SUPPORT_GFX_MGCG |
2097 AMD_CG_SUPPORT_GFX_MGLS |
2098 /*AMD_CG_SUPPORT_GFX_CGCG |*/
2099 AMD_CG_SUPPORT_GFX_CGLS |
2100 AMD_CG_SUPPORT_GFX_CGTS |
2101 AMD_CG_SUPPORT_GFX_CGTS_LS |
2102 AMD_CG_SUPPORT_GFX_CP_LS |
2103 AMD_CG_SUPPORT_SDMA_MGCG |
2104 AMD_CG_SUPPORT_SDMA_LS |
2105 AMD_CG_SUPPORT_BIF_LS |
2106 AMD_CG_SUPPORT_VCE_MGCG |
2107 AMD_CG_SUPPORT_UVD_MGCG |
2108 AMD_CG_SUPPORT_HDP_LS |
2109 AMD_CG_SUPPORT_HDP_MGCG;
2110 adev->pg_flags =
2111 /*AMD_PG_SUPPORT_GFX_PG |
2112 AMD_PG_SUPPORT_GFX_SMG | */
2113 AMD_PG_SUPPORT_UVD |
2114 /*AMD_PG_SUPPORT_VCE |
2115 AMD_PG_SUPPORT_CP |
2116 AMD_PG_SUPPORT_GDS |
2117 AMD_PG_SUPPORT_RLC_SMU_HS |
2118 AMD_PG_SUPPORT_SAMU |*/
2119 0;
2120 if (adev->asic_type == CHIP_KABINI) {
2121 if (adev->rev_id == 0)
2122 adev->external_rev_id = 0x81;
2123 else if (adev->rev_id == 1)
2124 adev->external_rev_id = 0x82;
2125 else if (adev->rev_id == 2)
2126 adev->external_rev_id = 0x85;
2127 } else
2128 adev->external_rev_id = adev->rev_id + 0xa1;
2129 break;
2130 default:
2131 /* FIXME: not supported yet */
2132 return -EINVAL;
2133 }
2134
2135 return 0;
2136}
2137
2138static int cik_common_sw_init(void *handle)
2139{
2140 return 0;
2141}
2142
2143static int cik_common_sw_fini(void *handle)
2144{
2145 return 0;
2146}
2147
2148static int cik_common_hw_init(void *handle)
2149{
2150 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2151
2152 /* move the golden regs per IP block */
2153 cik_init_golden_registers(adev);
2154 /* enable pcie gen2/3 link */
2155 cik_pcie_gen3_enable(adev);
2156 /* enable aspm */
2157 cik_program_aspm(adev);
2158
2159 return 0;
2160}
2161
2162static int cik_common_hw_fini(void *handle)
2163{
2164 return 0;
2165}
2166
2167static int cik_common_suspend(void *handle)
2168{
2169 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2170
2171 return cik_common_hw_fini(adev);
2172}
2173
2174static int cik_common_resume(void *handle)
2175{
2176 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2177
2178 return cik_common_hw_init(adev);
2179}
2180
2181static bool cik_common_is_idle(void *handle)
2182{
2183 return true;
2184}
2185
2186static int cik_common_wait_for_idle(void *handle)
2187{
2188 return 0;
2189}
2190
2191static int cik_common_soft_reset(void *handle)
2192{
2193 /* XXX hard reset?? */
2194 return 0;
2195}
2196
2197static int cik_common_set_clockgating_state(void *handle,
2198 enum amd_clockgating_state state)
2199{
2200 return 0;
2201}
2202
2203static int cik_common_set_powergating_state(void *handle,
2204 enum amd_powergating_state state)
2205{
2206 return 0;
2207}
2208
2209static const struct amd_ip_funcs cik_common_ip_funcs = {
2210 .name = "cik_common",
2211 .early_init = cik_common_early_init,
2212 .late_init = NULL,
2213 .sw_init = cik_common_sw_init,
2214 .sw_fini = cik_common_sw_fini,
2215 .hw_init = cik_common_hw_init,
2216 .hw_fini = cik_common_hw_fini,
2217 .suspend = cik_common_suspend,
2218 .resume = cik_common_resume,
2219 .is_idle = cik_common_is_idle,
2220 .wait_for_idle = cik_common_wait_for_idle,
2221 .soft_reset = cik_common_soft_reset,
2222 .set_clockgating_state = cik_common_set_clockgating_state,
2223 .set_powergating_state = cik_common_set_powergating_state,
2224};
2225
2226static const struct amdgpu_ip_block_version cik_common_ip_block =
2227{
2228 .type = AMD_IP_BLOCK_TYPE_COMMON,
2229 .major = 1,
2230 .minor = 0,
2231 .rev = 0,
2232 .funcs = &cik_common_ip_funcs,
2233};
2234
2235int cik_set_ip_blocks(struct amdgpu_device *adev)
2236{
2237 switch (adev->asic_type) {
2238 case CHIP_BONAIRE:
2239 amdgpu_device_ip_block_add(adev, &cik_common_ip_block);
2240 amdgpu_device_ip_block_add(adev, &gmc_v7_0_ip_block);
2241 amdgpu_device_ip_block_add(adev, &cik_ih_ip_block);
2242 amdgpu_device_ip_block_add(adev, &gfx_v7_2_ip_block);
2243 amdgpu_device_ip_block_add(adev, &cik_sdma_ip_block);
2244 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
2245 if (adev->enable_virtual_display)
2246 amdgpu_device_ip_block_add(adev, &amdgpu_vkms_ip_block);
2247#if defined(CONFIG_DRM_AMD_DC)
2248 else if (amdgpu_device_has_dc_support(adev))
2249 amdgpu_device_ip_block_add(adev, &dm_ip_block);
2250#endif
2251 else
2252 amdgpu_device_ip_block_add(adev, &dce_v8_2_ip_block);
2253 amdgpu_device_ip_block_add(adev, &uvd_v4_2_ip_block);
2254 amdgpu_device_ip_block_add(adev, &vce_v2_0_ip_block);
2255 break;
2256 case CHIP_HAWAII:
2257 amdgpu_device_ip_block_add(adev, &cik_common_ip_block);
2258 amdgpu_device_ip_block_add(adev, &gmc_v7_0_ip_block);
2259 amdgpu_device_ip_block_add(adev, &cik_ih_ip_block);
2260 amdgpu_device_ip_block_add(adev, &gfx_v7_3_ip_block);
2261 amdgpu_device_ip_block_add(adev, &cik_sdma_ip_block);
2262 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
2263 if (adev->enable_virtual_display)
2264 amdgpu_device_ip_block_add(adev, &amdgpu_vkms_ip_block);
2265#if defined(CONFIG_DRM_AMD_DC)
2266 else if (amdgpu_device_has_dc_support(adev))
2267 amdgpu_device_ip_block_add(adev, &dm_ip_block);
2268#endif
2269 else
2270 amdgpu_device_ip_block_add(adev, &dce_v8_5_ip_block);
2271 amdgpu_device_ip_block_add(adev, &uvd_v4_2_ip_block);
2272 amdgpu_device_ip_block_add(adev, &vce_v2_0_ip_block);
2273 break;
2274 case CHIP_KAVERI:
2275 amdgpu_device_ip_block_add(adev, &cik_common_ip_block);
2276 amdgpu_device_ip_block_add(adev, &gmc_v7_0_ip_block);
2277 amdgpu_device_ip_block_add(adev, &cik_ih_ip_block);
2278 amdgpu_device_ip_block_add(adev, &gfx_v7_1_ip_block);
2279 amdgpu_device_ip_block_add(adev, &cik_sdma_ip_block);
2280 amdgpu_device_ip_block_add(adev, &kv_smu_ip_block);
2281 if (adev->enable_virtual_display)
2282 amdgpu_device_ip_block_add(adev, &amdgpu_vkms_ip_block);
2283#if defined(CONFIG_DRM_AMD_DC)
2284 else if (amdgpu_device_has_dc_support(adev))
2285 amdgpu_device_ip_block_add(adev, &dm_ip_block);
2286#endif
2287 else
2288 amdgpu_device_ip_block_add(adev, &dce_v8_1_ip_block);
2289
2290 amdgpu_device_ip_block_add(adev, &uvd_v4_2_ip_block);
2291 amdgpu_device_ip_block_add(adev, &vce_v2_0_ip_block);
2292 break;
2293 case CHIP_KABINI:
2294 case CHIP_MULLINS:
2295 amdgpu_device_ip_block_add(adev, &cik_common_ip_block);
2296 amdgpu_device_ip_block_add(adev, &gmc_v7_0_ip_block);
2297 amdgpu_device_ip_block_add(adev, &cik_ih_ip_block);
2298 amdgpu_device_ip_block_add(adev, &gfx_v7_2_ip_block);
2299 amdgpu_device_ip_block_add(adev, &cik_sdma_ip_block);
2300 amdgpu_device_ip_block_add(adev, &kv_smu_ip_block);
2301 if (adev->enable_virtual_display)
2302 amdgpu_device_ip_block_add(adev, &amdgpu_vkms_ip_block);
2303#if defined(CONFIG_DRM_AMD_DC)
2304 else if (amdgpu_device_has_dc_support(adev))
2305 amdgpu_device_ip_block_add(adev, &dm_ip_block);
2306#endif
2307 else
2308 amdgpu_device_ip_block_add(adev, &dce_v8_3_ip_block);
2309 amdgpu_device_ip_block_add(adev, &uvd_v4_2_ip_block);
2310 amdgpu_device_ip_block_add(adev, &vce_v2_0_ip_block);
2311 break;
2312 default:
2313 /* FIXME: not supported yet */
2314 return -EINVAL;
2315 }
2316 return 0;
2317}