blob: 74dbfcadc072427be5b4ac8aa21074b008eb3ffa [file] [log] [blame]
Ken Wang62a37552016-01-19 14:08:49 +08001/*
2 * Copyright 2015 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 */
23
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 "atom.h"
34#include "amdgpu_powerplay.h"
35#include "si/sid.h"
36#include "si_ih.h"
37#include "gfx_v6_0.h"
38#include "gmc_v6_0.h"
39#include "si_dma.h"
40#include "dce_v6_0.h"
41#include "si.h"
42
43static const u32 tahiti_golden_registers[] =
44{
45 0x2684, 0x00010000, 0x00018208,
46 0x260c, 0xffffffff, 0x00000000,
47 0x260d, 0xf00fffff, 0x00000400,
48 0x260e, 0x0002021c, 0x00020200,
49 0x031e, 0x00000080, 0x00000000,
50 0x340c, 0x000300c0, 0x00800040,
51 0x360c, 0x000300c0, 0x00800040,
52 0x16ec, 0x000000f0, 0x00000070,
53 0x16f0, 0x00200000, 0x50100000,
54 0x1c0c, 0x31000311, 0x00000011,
55 0x09df, 0x00000003, 0x000007ff,
56 0x0903, 0x000007ff, 0x00000000,
57 0x2285, 0xf000001f, 0x00000007,
58 0x22c9, 0xffffffff, 0x00ffffff,
59 0x22c4, 0x0000ff0f, 0x00000000,
60 0xa293, 0x07ffffff, 0x4e000000,
61 0xa0d4, 0x3f3f3fff, 0x2a00126a,
62 0x000c, 0x000000ff, 0x0040,
63 0x000d, 0x00000040, 0x00004040,
64 0x2440, 0x07ffffff, 0x03000000,
65 0x23a2, 0x01ff1f3f, 0x00000000,
66 0x23a1, 0x01ff1f3f, 0x00000000,
67 0x2418, 0x0000007f, 0x00000020,
68 0x2542, 0x00010000, 0x00010000,
69 0x2b05, 0x00000200, 0x000002fb,
70 0x2b04, 0xffffffff, 0x0000543b,
71 0x2b03, 0xffffffff, 0xa9210876,
72 0x2234, 0xffffffff, 0x000fff40,
73 0x2235, 0x0000001f, 0x00000010,
74 0x0504, 0x20000000, 0x20fffed8,
75 0x0570, 0x000c0fc0, 0x000c0400
76};
77
78static const u32 tahiti_golden_registers2[] =
79{
80 0x0319, 0x00000001, 0x00000001
81};
82
83static const u32 tahiti_golden_rlc_registers[] =
84{
85 0x3109, 0xffffffff, 0x00601005,
86 0x311f, 0xffffffff, 0x10104040,
87 0x3122, 0xffffffff, 0x0100000a,
88 0x30c5, 0xffffffff, 0x00000800,
89 0x30c3, 0xffffffff, 0x800000f4,
90 0x3d2a, 0xffffffff, 0x00000000
91};
92
93static const u32 pitcairn_golden_registers[] =
94{
95 0x2684, 0x00010000, 0x00018208,
96 0x260c, 0xffffffff, 0x00000000,
97 0x260d, 0xf00fffff, 0x00000400,
98 0x260e, 0x0002021c, 0x00020200,
99 0x031e, 0x00000080, 0x00000000,
100 0x340c, 0x000300c0, 0x00800040,
101 0x360c, 0x000300c0, 0x00800040,
102 0x16ec, 0x000000f0, 0x00000070,
103 0x16f0, 0x00200000, 0x50100000,
104 0x1c0c, 0x31000311, 0x00000011,
105 0x0ab9, 0x00073ffe, 0x000022a2,
106 0x0903, 0x000007ff, 0x00000000,
107 0x2285, 0xf000001f, 0x00000007,
108 0x22c9, 0xffffffff, 0x00ffffff,
109 0x22c4, 0x0000ff0f, 0x00000000,
110 0xa293, 0x07ffffff, 0x4e000000,
111 0xa0d4, 0x3f3f3fff, 0x2a00126a,
112 0x000c, 0x000000ff, 0x0040,
113 0x000d, 0x00000040, 0x00004040,
114 0x2440, 0x07ffffff, 0x03000000,
115 0x2418, 0x0000007f, 0x00000020,
116 0x2542, 0x00010000, 0x00010000,
117 0x2b05, 0x000003ff, 0x000000f7,
118 0x2b04, 0xffffffff, 0x00000000,
119 0x2b03, 0xffffffff, 0x32761054,
120 0x2235, 0x0000001f, 0x00000010,
121 0x0570, 0x000c0fc0, 0x000c0400
122};
123
124static const u32 pitcairn_golden_rlc_registers[] =
125{
126 0x3109, 0xffffffff, 0x00601004,
127 0x311f, 0xffffffff, 0x10102020,
128 0x3122, 0xffffffff, 0x01000020,
129 0x30c5, 0xffffffff, 0x00000800,
130 0x30c3, 0xffffffff, 0x800000a4
131};
132
133static const u32 verde_pg_init[] =
134{
135 0xd4f, 0xffffffff, 0x40000,
136 0xd4e, 0xffffffff, 0x200010ff,
137 0xd4f, 0xffffffff, 0x0,
138 0xd4f, 0xffffffff, 0x0,
139 0xd4f, 0xffffffff, 0x0,
140 0xd4f, 0xffffffff, 0x0,
141 0xd4f, 0xffffffff, 0x0,
142 0xd4f, 0xffffffff, 0x7007,
143 0xd4e, 0xffffffff, 0x300010ff,
144 0xd4f, 0xffffffff, 0x0,
145 0xd4f, 0xffffffff, 0x0,
146 0xd4f, 0xffffffff, 0x0,
147 0xd4f, 0xffffffff, 0x0,
148 0xd4f, 0xffffffff, 0x0,
149 0xd4f, 0xffffffff, 0x400000,
150 0xd4e, 0xffffffff, 0x100010ff,
151 0xd4f, 0xffffffff, 0x0,
152 0xd4f, 0xffffffff, 0x0,
153 0xd4f, 0xffffffff, 0x0,
154 0xd4f, 0xffffffff, 0x0,
155 0xd4f, 0xffffffff, 0x0,
156 0xd4f, 0xffffffff, 0x120200,
157 0xd4e, 0xffffffff, 0x500010ff,
158 0xd4f, 0xffffffff, 0x0,
159 0xd4f, 0xffffffff, 0x0,
160 0xd4f, 0xffffffff, 0x0,
161 0xd4f, 0xffffffff, 0x0,
162 0xd4f, 0xffffffff, 0x0,
163 0xd4f, 0xffffffff, 0x1e1e16,
164 0xd4e, 0xffffffff, 0x600010ff,
165 0xd4f, 0xffffffff, 0x0,
166 0xd4f, 0xffffffff, 0x0,
167 0xd4f, 0xffffffff, 0x0,
168 0xd4f, 0xffffffff, 0x0,
169 0xd4f, 0xffffffff, 0x0,
170 0xd4f, 0xffffffff, 0x171f1e,
171 0xd4e, 0xffffffff, 0x700010ff,
172 0xd4f, 0xffffffff, 0x0,
173 0xd4f, 0xffffffff, 0x0,
174 0xd4f, 0xffffffff, 0x0,
175 0xd4f, 0xffffffff, 0x0,
176 0xd4f, 0xffffffff, 0x0,
177 0xd4f, 0xffffffff, 0x0,
178 0xd4e, 0xffffffff, 0x9ff,
179 0xd40, 0xffffffff, 0x0,
180 0xd41, 0xffffffff, 0x10000800,
181 0xd41, 0xffffffff, 0xf,
182 0xd41, 0xffffffff, 0xf,
183 0xd40, 0xffffffff, 0x4,
184 0xd41, 0xffffffff, 0x1000051e,
185 0xd41, 0xffffffff, 0xffff,
186 0xd41, 0xffffffff, 0xffff,
187 0xd40, 0xffffffff, 0x8,
188 0xd41, 0xffffffff, 0x80500,
189 0xd40, 0xffffffff, 0x12,
190 0xd41, 0xffffffff, 0x9050c,
191 0xd40, 0xffffffff, 0x1d,
192 0xd41, 0xffffffff, 0xb052c,
193 0xd40, 0xffffffff, 0x2a,
194 0xd41, 0xffffffff, 0x1053e,
195 0xd40, 0xffffffff, 0x2d,
196 0xd41, 0xffffffff, 0x10546,
197 0xd40, 0xffffffff, 0x30,
198 0xd41, 0xffffffff, 0xa054e,
199 0xd40, 0xffffffff, 0x3c,
200 0xd41, 0xffffffff, 0x1055f,
201 0xd40, 0xffffffff, 0x3f,
202 0xd41, 0xffffffff, 0x10567,
203 0xd40, 0xffffffff, 0x42,
204 0xd41, 0xffffffff, 0x1056f,
205 0xd40, 0xffffffff, 0x45,
206 0xd41, 0xffffffff, 0x10572,
207 0xd40, 0xffffffff, 0x48,
208 0xd41, 0xffffffff, 0x20575,
209 0xd40, 0xffffffff, 0x4c,
210 0xd41, 0xffffffff, 0x190801,
211 0xd40, 0xffffffff, 0x67,
212 0xd41, 0xffffffff, 0x1082a,
213 0xd40, 0xffffffff, 0x6a,
214 0xd41, 0xffffffff, 0x1b082d,
215 0xd40, 0xffffffff, 0x87,
216 0xd41, 0xffffffff, 0x310851,
217 0xd40, 0xffffffff, 0xba,
218 0xd41, 0xffffffff, 0x891,
219 0xd40, 0xffffffff, 0xbc,
220 0xd41, 0xffffffff, 0x893,
221 0xd40, 0xffffffff, 0xbe,
222 0xd41, 0xffffffff, 0x20895,
223 0xd40, 0xffffffff, 0xc2,
224 0xd41, 0xffffffff, 0x20899,
225 0xd40, 0xffffffff, 0xc6,
226 0xd41, 0xffffffff, 0x2089d,
227 0xd40, 0xffffffff, 0xca,
228 0xd41, 0xffffffff, 0x8a1,
229 0xd40, 0xffffffff, 0xcc,
230 0xd41, 0xffffffff, 0x8a3,
231 0xd40, 0xffffffff, 0xce,
232 0xd41, 0xffffffff, 0x308a5,
233 0xd40, 0xffffffff, 0xd3,
234 0xd41, 0xffffffff, 0x6d08cd,
235 0xd40, 0xffffffff, 0x142,
236 0xd41, 0xffffffff, 0x2000095a,
237 0xd41, 0xffffffff, 0x1,
238 0xd40, 0xffffffff, 0x144,
239 0xd41, 0xffffffff, 0x301f095b,
240 0xd40, 0xffffffff, 0x165,
241 0xd41, 0xffffffff, 0xc094d,
242 0xd40, 0xffffffff, 0x173,
243 0xd41, 0xffffffff, 0xf096d,
244 0xd40, 0xffffffff, 0x184,
245 0xd41, 0xffffffff, 0x15097f,
246 0xd40, 0xffffffff, 0x19b,
247 0xd41, 0xffffffff, 0xc0998,
248 0xd40, 0xffffffff, 0x1a9,
249 0xd41, 0xffffffff, 0x409a7,
250 0xd40, 0xffffffff, 0x1af,
251 0xd41, 0xffffffff, 0xcdc,
252 0xd40, 0xffffffff, 0x1b1,
253 0xd41, 0xffffffff, 0x800,
254 0xd42, 0xffffffff, 0x6c9b2000,
255 0xd44, 0xfc00, 0x2000,
256 0xd51, 0xffffffff, 0xfc0,
257 0xa35, 0x00000100, 0x100
258};
259
260static const u32 verde_golden_rlc_registers[] =
261{
262 0x3109, 0xffffffff, 0x033f1005,
263 0x311f, 0xffffffff, 0x10808020,
264 0x3122, 0xffffffff, 0x00800008,
265 0x30c5, 0xffffffff, 0x00001000,
266 0x30c3, 0xffffffff, 0x80010014
267};
268
269static const u32 verde_golden_registers[] =
270{
271 0x2684, 0x00010000, 0x00018208,
272 0x260c, 0xffffffff, 0x00000000,
273 0x260d, 0xf00fffff, 0x00000400,
274 0x260e, 0x0002021c, 0x00020200,
275 0x031e, 0x00000080, 0x00000000,
276 0x340c, 0x000300c0, 0x00800040,
277 0x340c, 0x000300c0, 0x00800040,
278 0x360c, 0x000300c0, 0x00800040,
279 0x360c, 0x000300c0, 0x00800040,
280 0x16ec, 0x000000f0, 0x00000070,
281 0x16f0, 0x00200000, 0x50100000,
282
283 0x1c0c, 0x31000311, 0x00000011,
284 0x0ab9, 0x00073ffe, 0x000022a2,
285 0x0ab9, 0x00073ffe, 0x000022a2,
286 0x0ab9, 0x00073ffe, 0x000022a2,
287 0x0903, 0x000007ff, 0x00000000,
288 0x0903, 0x000007ff, 0x00000000,
289 0x0903, 0x000007ff, 0x00000000,
290 0x2285, 0xf000001f, 0x00000007,
291 0x2285, 0xf000001f, 0x00000007,
292 0x2285, 0xf000001f, 0x00000007,
293 0x2285, 0xffffffff, 0x00ffffff,
294 0x22c4, 0x0000ff0f, 0x00000000,
295
296 0xa293, 0x07ffffff, 0x4e000000,
297 0xa0d4, 0x3f3f3fff, 0x0000124a,
298 0xa0d4, 0x3f3f3fff, 0x0000124a,
299 0xa0d4, 0x3f3f3fff, 0x0000124a,
300 0x000c, 0x000000ff, 0x0040,
301 0x000d, 0x00000040, 0x00004040,
302 0x2440, 0x07ffffff, 0x03000000,
303 0x2440, 0x07ffffff, 0x03000000,
304 0x23a2, 0x01ff1f3f, 0x00000000,
305 0x23a3, 0x01ff1f3f, 0x00000000,
306 0x23a2, 0x01ff1f3f, 0x00000000,
307 0x23a1, 0x01ff1f3f, 0x00000000,
308 0x23a1, 0x01ff1f3f, 0x00000000,
309
310 0x23a1, 0x01ff1f3f, 0x00000000,
311 0x2418, 0x0000007f, 0x00000020,
312 0x2542, 0x00010000, 0x00010000,
313 0x2b01, 0x000003ff, 0x00000003,
314 0x2b05, 0x000003ff, 0x00000003,
315 0x2b05, 0x000003ff, 0x00000003,
316 0x2b04, 0xffffffff, 0x00000000,
317 0x2b04, 0xffffffff, 0x00000000,
318 0x2b04, 0xffffffff, 0x00000000,
319 0x2b03, 0xffffffff, 0x00001032,
320 0x2b03, 0xffffffff, 0x00001032,
321 0x2b03, 0xffffffff, 0x00001032,
322 0x2235, 0x0000001f, 0x00000010,
323 0x2235, 0x0000001f, 0x00000010,
324 0x2235, 0x0000001f, 0x00000010,
325 0x0570, 0x000c0fc0, 0x000c0400
326};
327
328static const u32 oland_golden_registers[] =
329{
330 0x2684, 0x00010000, 0x00018208,
331 0x260c, 0xffffffff, 0x00000000,
332 0x260d, 0xf00fffff, 0x00000400,
333 0x260e, 0x0002021c, 0x00020200,
334 0x031e, 0x00000080, 0x00000000,
335 0x340c, 0x000300c0, 0x00800040,
336 0x360c, 0x000300c0, 0x00800040,
337 0x16ec, 0x000000f0, 0x00000070,
338 0x16f9, 0x00200000, 0x50100000,
339 0x1c0c, 0x31000311, 0x00000011,
340 0x0ab9, 0x00073ffe, 0x000022a2,
341 0x0903, 0x000007ff, 0x00000000,
342 0x2285, 0xf000001f, 0x00000007,
343 0x22c9, 0xffffffff, 0x00ffffff,
344 0x22c4, 0x0000ff0f, 0x00000000,
345 0xa293, 0x07ffffff, 0x4e000000,
346 0xa0d4, 0x3f3f3fff, 0x00000082,
347 0x000c, 0x000000ff, 0x0040,
348 0x000d, 0x00000040, 0x00004040,
349 0x2440, 0x07ffffff, 0x03000000,
350 0x2418, 0x0000007f, 0x00000020,
351 0x2542, 0x00010000, 0x00010000,
352 0x2b05, 0x000003ff, 0x000000f3,
353 0x2b04, 0xffffffff, 0x00000000,
354 0x2b03, 0xffffffff, 0x00003210,
355 0x2235, 0x0000001f, 0x00000010,
356 0x0570, 0x000c0fc0, 0x000c0400
357};
358
359static const u32 oland_golden_rlc_registers[] =
360{
361 0x3109, 0xffffffff, 0x00601005,
362 0x311f, 0xffffffff, 0x10104040,
363 0x3122, 0xffffffff, 0x0100000a,
364 0x30c5, 0xffffffff, 0x00000800,
365 0x30c3, 0xffffffff, 0x800000f4
366};
367
368static const u32 hainan_golden_registers[] =
369{
370 0x2684, 0x00010000, 0x00018208,
371 0x260c, 0xffffffff, 0x00000000,
372 0x260d, 0xf00fffff, 0x00000400,
373 0x260e, 0x0002021c, 0x00020200,
374 0x4595, 0xff000fff, 0x00000100,
375 0x340c, 0x000300c0, 0x00800040,
376 0x3630, 0xff000fff, 0x00000100,
377 0x360c, 0x000300c0, 0x00800040,
378 0x0ab9, 0x00073ffe, 0x000022a2,
379 0x0903, 0x000007ff, 0x00000000,
380 0x2285, 0xf000001f, 0x00000007,
381 0x22c9, 0xffffffff, 0x00ffffff,
382 0x22c4, 0x0000ff0f, 0x00000000,
383 0xa393, 0x07ffffff, 0x4e000000,
384 0xa0d4, 0x3f3f3fff, 0x00000000,
385 0x000c, 0x000000ff, 0x0040,
386 0x000d, 0x00000040, 0x00004040,
387 0x2440, 0x03e00000, 0x03600000,
388 0x2418, 0x0000007f, 0x00000020,
389 0x2542, 0x00010000, 0x00010000,
390 0x2b05, 0x000003ff, 0x000000f1,
391 0x2b04, 0xffffffff, 0x00000000,
392 0x2b03, 0xffffffff, 0x00003210,
393 0x2235, 0x0000001f, 0x00000010,
394 0x0570, 0x000c0fc0, 0x000c0400
395};
396
397static const u32 hainan_golden_registers2[] =
398{
399 0x263e, 0xffffffff, 0x02010001
400};
401
402static const u32 tahiti_mgcg_cgcg_init[] =
403{
404 0x3100, 0xffffffff, 0xfffffffc,
405 0x200b, 0xffffffff, 0xe0000000,
406 0x2698, 0xffffffff, 0x00000100,
407 0x24a9, 0xffffffff, 0x00000100,
408 0x3059, 0xffffffff, 0x00000100,
409 0x25dd, 0xffffffff, 0x00000100,
410 0x2261, 0xffffffff, 0x06000100,
411 0x2286, 0xffffffff, 0x00000100,
412 0x24a8, 0xffffffff, 0x00000100,
413 0x30e0, 0xffffffff, 0x00000100,
414 0x22ca, 0xffffffff, 0x00000100,
415 0x2451, 0xffffffff, 0x00000100,
416 0x2362, 0xffffffff, 0x00000100,
417 0x2363, 0xffffffff, 0x00000100,
418 0x240c, 0xffffffff, 0x00000100,
419 0x240d, 0xffffffff, 0x00000100,
420 0x240e, 0xffffffff, 0x00000100,
421 0x240f, 0xffffffff, 0x00000100,
422 0x2b60, 0xffffffff, 0x00000100,
423 0x2b15, 0xffffffff, 0x00000100,
424 0x225f, 0xffffffff, 0x06000100,
425 0x261a, 0xffffffff, 0x00000100,
426 0x2544, 0xffffffff, 0x00000100,
427 0x2bc1, 0xffffffff, 0x00000100,
428 0x2b81, 0xffffffff, 0x00000100,
429 0x2527, 0xffffffff, 0x00000100,
430 0x200b, 0xffffffff, 0xe0000000,
431 0x2458, 0xffffffff, 0x00010000,
432 0x2459, 0xffffffff, 0x00030002,
433 0x245a, 0xffffffff, 0x00040007,
434 0x245b, 0xffffffff, 0x00060005,
435 0x245c, 0xffffffff, 0x00090008,
436 0x245d, 0xffffffff, 0x00020001,
437 0x245e, 0xffffffff, 0x00040003,
438 0x245f, 0xffffffff, 0x00000007,
439 0x2460, 0xffffffff, 0x00060005,
440 0x2461, 0xffffffff, 0x00090008,
441 0x2462, 0xffffffff, 0x00030002,
442 0x2463, 0xffffffff, 0x00050004,
443 0x2464, 0xffffffff, 0x00000008,
444 0x2465, 0xffffffff, 0x00070006,
445 0x2466, 0xffffffff, 0x000a0009,
446 0x2467, 0xffffffff, 0x00040003,
447 0x2468, 0xffffffff, 0x00060005,
448 0x2469, 0xffffffff, 0x00000009,
449 0x246a, 0xffffffff, 0x00080007,
450 0x246b, 0xffffffff, 0x000b000a,
451 0x246c, 0xffffffff, 0x00050004,
452 0x246d, 0xffffffff, 0x00070006,
453 0x246e, 0xffffffff, 0x0008000b,
454 0x246f, 0xffffffff, 0x000a0009,
455 0x2470, 0xffffffff, 0x000d000c,
456 0x2471, 0xffffffff, 0x00060005,
457 0x2472, 0xffffffff, 0x00080007,
458 0x2473, 0xffffffff, 0x0000000b,
459 0x2474, 0xffffffff, 0x000a0009,
460 0x2475, 0xffffffff, 0x000d000c,
461 0x2476, 0xffffffff, 0x00070006,
462 0x2477, 0xffffffff, 0x00090008,
463 0x2478, 0xffffffff, 0x0000000c,
464 0x2479, 0xffffffff, 0x000b000a,
465 0x247a, 0xffffffff, 0x000e000d,
466 0x247b, 0xffffffff, 0x00080007,
467 0x247c, 0xffffffff, 0x000a0009,
468 0x247d, 0xffffffff, 0x0000000d,
469 0x247e, 0xffffffff, 0x000c000b,
470 0x247f, 0xffffffff, 0x000f000e,
471 0x2480, 0xffffffff, 0x00090008,
472 0x2481, 0xffffffff, 0x000b000a,
473 0x2482, 0xffffffff, 0x000c000f,
474 0x2483, 0xffffffff, 0x000e000d,
475 0x2484, 0xffffffff, 0x00110010,
476 0x2485, 0xffffffff, 0x000a0009,
477 0x2486, 0xffffffff, 0x000c000b,
478 0x2487, 0xffffffff, 0x0000000f,
479 0x2488, 0xffffffff, 0x000e000d,
480 0x2489, 0xffffffff, 0x00110010,
481 0x248a, 0xffffffff, 0x000b000a,
482 0x248b, 0xffffffff, 0x000d000c,
483 0x248c, 0xffffffff, 0x00000010,
484 0x248d, 0xffffffff, 0x000f000e,
485 0x248e, 0xffffffff, 0x00120011,
486 0x248f, 0xffffffff, 0x000c000b,
487 0x2490, 0xffffffff, 0x000e000d,
488 0x2491, 0xffffffff, 0x00000011,
489 0x2492, 0xffffffff, 0x0010000f,
490 0x2493, 0xffffffff, 0x00130012,
491 0x2494, 0xffffffff, 0x000d000c,
492 0x2495, 0xffffffff, 0x000f000e,
493 0x2496, 0xffffffff, 0x00100013,
494 0x2497, 0xffffffff, 0x00120011,
495 0x2498, 0xffffffff, 0x00150014,
496 0x2499, 0xffffffff, 0x000e000d,
497 0x249a, 0xffffffff, 0x0010000f,
498 0x249b, 0xffffffff, 0x00000013,
499 0x249c, 0xffffffff, 0x00120011,
500 0x249d, 0xffffffff, 0x00150014,
501 0x249e, 0xffffffff, 0x000f000e,
502 0x249f, 0xffffffff, 0x00110010,
503 0x24a0, 0xffffffff, 0x00000014,
504 0x24a1, 0xffffffff, 0x00130012,
505 0x24a2, 0xffffffff, 0x00160015,
506 0x24a3, 0xffffffff, 0x0010000f,
507 0x24a4, 0xffffffff, 0x00120011,
508 0x24a5, 0xffffffff, 0x00000015,
509 0x24a6, 0xffffffff, 0x00140013,
510 0x24a7, 0xffffffff, 0x00170016,
511 0x2454, 0xffffffff, 0x96940200,
512 0x21c2, 0xffffffff, 0x00900100,
513 0x311e, 0xffffffff, 0x00000080,
514 0x3101, 0xffffffff, 0x0020003f,
515 0xc, 0xffffffff, 0x0000001c,
516 0xd, 0x000f0000, 0x000f0000,
517 0x583, 0xffffffff, 0x00000100,
518 0x409, 0xffffffff, 0x00000100,
519 0x40b, 0x00000101, 0x00000000,
520 0x82a, 0xffffffff, 0x00000104,
521 0x993, 0x000c0000, 0x000c0000,
522 0x992, 0x000c0000, 0x000c0000,
523 0x1579, 0xff000fff, 0x00000100,
524 0x157a, 0x00000001, 0x00000001,
525 0xbd4, 0x00000001, 0x00000001,
526 0xc33, 0xc0000fff, 0x00000104,
527 0x3079, 0x00000001, 0x00000001,
528 0x3430, 0xfffffff0, 0x00000100,
529 0x3630, 0xfffffff0, 0x00000100
530};
531static const u32 pitcairn_mgcg_cgcg_init[] =
532{
533 0x3100, 0xffffffff, 0xfffffffc,
534 0x200b, 0xffffffff, 0xe0000000,
535 0x2698, 0xffffffff, 0x00000100,
536 0x24a9, 0xffffffff, 0x00000100,
537 0x3059, 0xffffffff, 0x00000100,
538 0x25dd, 0xffffffff, 0x00000100,
539 0x2261, 0xffffffff, 0x06000100,
540 0x2286, 0xffffffff, 0x00000100,
541 0x24a8, 0xffffffff, 0x00000100,
542 0x30e0, 0xffffffff, 0x00000100,
543 0x22ca, 0xffffffff, 0x00000100,
544 0x2451, 0xffffffff, 0x00000100,
545 0x2362, 0xffffffff, 0x00000100,
546 0x2363, 0xffffffff, 0x00000100,
547 0x240c, 0xffffffff, 0x00000100,
548 0x240d, 0xffffffff, 0x00000100,
549 0x240e, 0xffffffff, 0x00000100,
550 0x240f, 0xffffffff, 0x00000100,
551 0x2b60, 0xffffffff, 0x00000100,
552 0x2b15, 0xffffffff, 0x00000100,
553 0x225f, 0xffffffff, 0x06000100,
554 0x261a, 0xffffffff, 0x00000100,
555 0x2544, 0xffffffff, 0x00000100,
556 0x2bc1, 0xffffffff, 0x00000100,
557 0x2b81, 0xffffffff, 0x00000100,
558 0x2527, 0xffffffff, 0x00000100,
559 0x200b, 0xffffffff, 0xe0000000,
560 0x2458, 0xffffffff, 0x00010000,
561 0x2459, 0xffffffff, 0x00030002,
562 0x245a, 0xffffffff, 0x00040007,
563 0x245b, 0xffffffff, 0x00060005,
564 0x245c, 0xffffffff, 0x00090008,
565 0x245d, 0xffffffff, 0x00020001,
566 0x245e, 0xffffffff, 0x00040003,
567 0x245f, 0xffffffff, 0x00000007,
568 0x2460, 0xffffffff, 0x00060005,
569 0x2461, 0xffffffff, 0x00090008,
570 0x2462, 0xffffffff, 0x00030002,
571 0x2463, 0xffffffff, 0x00050004,
572 0x2464, 0xffffffff, 0x00000008,
573 0x2465, 0xffffffff, 0x00070006,
574 0x2466, 0xffffffff, 0x000a0009,
575 0x2467, 0xffffffff, 0x00040003,
576 0x2468, 0xffffffff, 0x00060005,
577 0x2469, 0xffffffff, 0x00000009,
578 0x246a, 0xffffffff, 0x00080007,
579 0x246b, 0xffffffff, 0x000b000a,
580 0x246c, 0xffffffff, 0x00050004,
581 0x246d, 0xffffffff, 0x00070006,
582 0x246e, 0xffffffff, 0x0008000b,
583 0x246f, 0xffffffff, 0x000a0009,
584 0x2470, 0xffffffff, 0x000d000c,
585 0x2480, 0xffffffff, 0x00090008,
586 0x2481, 0xffffffff, 0x000b000a,
587 0x2482, 0xffffffff, 0x000c000f,
588 0x2483, 0xffffffff, 0x000e000d,
589 0x2484, 0xffffffff, 0x00110010,
590 0x2485, 0xffffffff, 0x000a0009,
591 0x2486, 0xffffffff, 0x000c000b,
592 0x2487, 0xffffffff, 0x0000000f,
593 0x2488, 0xffffffff, 0x000e000d,
594 0x2489, 0xffffffff, 0x00110010,
595 0x248a, 0xffffffff, 0x000b000a,
596 0x248b, 0xffffffff, 0x000d000c,
597 0x248c, 0xffffffff, 0x00000010,
598 0x248d, 0xffffffff, 0x000f000e,
599 0x248e, 0xffffffff, 0x00120011,
600 0x248f, 0xffffffff, 0x000c000b,
601 0x2490, 0xffffffff, 0x000e000d,
602 0x2491, 0xffffffff, 0x00000011,
603 0x2492, 0xffffffff, 0x0010000f,
604 0x2493, 0xffffffff, 0x00130012,
605 0x2494, 0xffffffff, 0x000d000c,
606 0x2495, 0xffffffff, 0x000f000e,
607 0x2496, 0xffffffff, 0x00100013,
608 0x2497, 0xffffffff, 0x00120011,
609 0x2498, 0xffffffff, 0x00150014,
610 0x2454, 0xffffffff, 0x96940200,
611 0x21c2, 0xffffffff, 0x00900100,
612 0x311e, 0xffffffff, 0x00000080,
613 0x3101, 0xffffffff, 0x0020003f,
614 0xc, 0xffffffff, 0x0000001c,
615 0xd, 0x000f0000, 0x000f0000,
616 0x583, 0xffffffff, 0x00000100,
617 0x409, 0xffffffff, 0x00000100,
618 0x40b, 0x00000101, 0x00000000,
619 0x82a, 0xffffffff, 0x00000104,
620 0x1579, 0xff000fff, 0x00000100,
621 0x157a, 0x00000001, 0x00000001,
622 0xbd4, 0x00000001, 0x00000001,
623 0xc33, 0xc0000fff, 0x00000104,
624 0x3079, 0x00000001, 0x00000001,
625 0x3430, 0xfffffff0, 0x00000100,
626 0x3630, 0xfffffff0, 0x00000100
627};
628static const u32 verde_mgcg_cgcg_init[] =
629{
630 0x3100, 0xffffffff, 0xfffffffc,
631 0x200b, 0xffffffff, 0xe0000000,
632 0x2698, 0xffffffff, 0x00000100,
633 0x24a9, 0xffffffff, 0x00000100,
634 0x3059, 0xffffffff, 0x00000100,
635 0x25dd, 0xffffffff, 0x00000100,
636 0x2261, 0xffffffff, 0x06000100,
637 0x2286, 0xffffffff, 0x00000100,
638 0x24a8, 0xffffffff, 0x00000100,
639 0x30e0, 0xffffffff, 0x00000100,
640 0x22ca, 0xffffffff, 0x00000100,
641 0x2451, 0xffffffff, 0x00000100,
642 0x2362, 0xffffffff, 0x00000100,
643 0x2363, 0xffffffff, 0x00000100,
644 0x240c, 0xffffffff, 0x00000100,
645 0x240d, 0xffffffff, 0x00000100,
646 0x240e, 0xffffffff, 0x00000100,
647 0x240f, 0xffffffff, 0x00000100,
648 0x2b60, 0xffffffff, 0x00000100,
649 0x2b15, 0xffffffff, 0x00000100,
650 0x225f, 0xffffffff, 0x06000100,
651 0x261a, 0xffffffff, 0x00000100,
652 0x2544, 0xffffffff, 0x00000100,
653 0x2bc1, 0xffffffff, 0x00000100,
654 0x2b81, 0xffffffff, 0x00000100,
655 0x2527, 0xffffffff, 0x00000100,
656 0x200b, 0xffffffff, 0xe0000000,
657 0x2458, 0xffffffff, 0x00010000,
658 0x2459, 0xffffffff, 0x00030002,
659 0x245a, 0xffffffff, 0x00040007,
660 0x245b, 0xffffffff, 0x00060005,
661 0x245c, 0xffffffff, 0x00090008,
662 0x245d, 0xffffffff, 0x00020001,
663 0x245e, 0xffffffff, 0x00040003,
664 0x245f, 0xffffffff, 0x00000007,
665 0x2460, 0xffffffff, 0x00060005,
666 0x2461, 0xffffffff, 0x00090008,
667 0x2462, 0xffffffff, 0x00030002,
668 0x2463, 0xffffffff, 0x00050004,
669 0x2464, 0xffffffff, 0x00000008,
670 0x2465, 0xffffffff, 0x00070006,
671 0x2466, 0xffffffff, 0x000a0009,
672 0x2467, 0xffffffff, 0x00040003,
673 0x2468, 0xffffffff, 0x00060005,
674 0x2469, 0xffffffff, 0x00000009,
675 0x246a, 0xffffffff, 0x00080007,
676 0x246b, 0xffffffff, 0x000b000a,
677 0x246c, 0xffffffff, 0x00050004,
678 0x246d, 0xffffffff, 0x00070006,
679 0x246e, 0xffffffff, 0x0008000b,
680 0x246f, 0xffffffff, 0x000a0009,
681 0x2470, 0xffffffff, 0x000d000c,
682 0x2480, 0xffffffff, 0x00090008,
683 0x2481, 0xffffffff, 0x000b000a,
684 0x2482, 0xffffffff, 0x000c000f,
685 0x2483, 0xffffffff, 0x000e000d,
686 0x2484, 0xffffffff, 0x00110010,
687 0x2485, 0xffffffff, 0x000a0009,
688 0x2486, 0xffffffff, 0x000c000b,
689 0x2487, 0xffffffff, 0x0000000f,
690 0x2488, 0xffffffff, 0x000e000d,
691 0x2489, 0xffffffff, 0x00110010,
692 0x248a, 0xffffffff, 0x000b000a,
693 0x248b, 0xffffffff, 0x000d000c,
694 0x248c, 0xffffffff, 0x00000010,
695 0x248d, 0xffffffff, 0x000f000e,
696 0x248e, 0xffffffff, 0x00120011,
697 0x248f, 0xffffffff, 0x000c000b,
698 0x2490, 0xffffffff, 0x000e000d,
699 0x2491, 0xffffffff, 0x00000011,
700 0x2492, 0xffffffff, 0x0010000f,
701 0x2493, 0xffffffff, 0x00130012,
702 0x2494, 0xffffffff, 0x000d000c,
703 0x2495, 0xffffffff, 0x000f000e,
704 0x2496, 0xffffffff, 0x00100013,
705 0x2497, 0xffffffff, 0x00120011,
706 0x2498, 0xffffffff, 0x00150014,
707 0x2454, 0xffffffff, 0x96940200,
708 0x21c2, 0xffffffff, 0x00900100,
709 0x311e, 0xffffffff, 0x00000080,
710 0x3101, 0xffffffff, 0x0020003f,
711 0xc, 0xffffffff, 0x0000001c,
712 0xd, 0x000f0000, 0x000f0000,
713 0x583, 0xffffffff, 0x00000100,
714 0x409, 0xffffffff, 0x00000100,
715 0x40b, 0x00000101, 0x00000000,
716 0x82a, 0xffffffff, 0x00000104,
717 0x993, 0x000c0000, 0x000c0000,
718 0x992, 0x000c0000, 0x000c0000,
719 0x1579, 0xff000fff, 0x00000100,
720 0x157a, 0x00000001, 0x00000001,
721 0xbd4, 0x00000001, 0x00000001,
722 0xc33, 0xc0000fff, 0x00000104,
723 0x3079, 0x00000001, 0x00000001,
724 0x3430, 0xfffffff0, 0x00000100,
725 0x3630, 0xfffffff0, 0x00000100
726};
727static const u32 oland_mgcg_cgcg_init[] =
728{
729 0x3100, 0xffffffff, 0xfffffffc,
730 0x200b, 0xffffffff, 0xe0000000,
731 0x2698, 0xffffffff, 0x00000100,
732 0x24a9, 0xffffffff, 0x00000100,
733 0x3059, 0xffffffff, 0x00000100,
734 0x25dd, 0xffffffff, 0x00000100,
735 0x2261, 0xffffffff, 0x06000100,
736 0x2286, 0xffffffff, 0x00000100,
737 0x24a8, 0xffffffff, 0x00000100,
738 0x30e0, 0xffffffff, 0x00000100,
739 0x22ca, 0xffffffff, 0x00000100,
740 0x2451, 0xffffffff, 0x00000100,
741 0x2362, 0xffffffff, 0x00000100,
742 0x2363, 0xffffffff, 0x00000100,
743 0x240c, 0xffffffff, 0x00000100,
744 0x240d, 0xffffffff, 0x00000100,
745 0x240e, 0xffffffff, 0x00000100,
746 0x240f, 0xffffffff, 0x00000100,
747 0x2b60, 0xffffffff, 0x00000100,
748 0x2b15, 0xffffffff, 0x00000100,
749 0x225f, 0xffffffff, 0x06000100,
750 0x261a, 0xffffffff, 0x00000100,
751 0x2544, 0xffffffff, 0x00000100,
752 0x2bc1, 0xffffffff, 0x00000100,
753 0x2b81, 0xffffffff, 0x00000100,
754 0x2527, 0xffffffff, 0x00000100,
755 0x200b, 0xffffffff, 0xe0000000,
756 0x2458, 0xffffffff, 0x00010000,
757 0x2459, 0xffffffff, 0x00030002,
758 0x245a, 0xffffffff, 0x00040007,
759 0x245b, 0xffffffff, 0x00060005,
760 0x245c, 0xffffffff, 0x00090008,
761 0x245d, 0xffffffff, 0x00020001,
762 0x245e, 0xffffffff, 0x00040003,
763 0x245f, 0xffffffff, 0x00000007,
764 0x2460, 0xffffffff, 0x00060005,
765 0x2461, 0xffffffff, 0x00090008,
766 0x2462, 0xffffffff, 0x00030002,
767 0x2463, 0xffffffff, 0x00050004,
768 0x2464, 0xffffffff, 0x00000008,
769 0x2465, 0xffffffff, 0x00070006,
770 0x2466, 0xffffffff, 0x000a0009,
771 0x2467, 0xffffffff, 0x00040003,
772 0x2468, 0xffffffff, 0x00060005,
773 0x2469, 0xffffffff, 0x00000009,
774 0x246a, 0xffffffff, 0x00080007,
775 0x246b, 0xffffffff, 0x000b000a,
776 0x246c, 0xffffffff, 0x00050004,
777 0x246d, 0xffffffff, 0x00070006,
778 0x246e, 0xffffffff, 0x0008000b,
779 0x246f, 0xffffffff, 0x000a0009,
780 0x2470, 0xffffffff, 0x000d000c,
781 0x2471, 0xffffffff, 0x00060005,
782 0x2472, 0xffffffff, 0x00080007,
783 0x2473, 0xffffffff, 0x0000000b,
784 0x2474, 0xffffffff, 0x000a0009,
785 0x2475, 0xffffffff, 0x000d000c,
786 0x2454, 0xffffffff, 0x96940200,
787 0x21c2, 0xffffffff, 0x00900100,
788 0x311e, 0xffffffff, 0x00000080,
789 0x3101, 0xffffffff, 0x0020003f,
790 0xc, 0xffffffff, 0x0000001c,
791 0xd, 0x000f0000, 0x000f0000,
792 0x583, 0xffffffff, 0x00000100,
793 0x409, 0xffffffff, 0x00000100,
794 0x40b, 0x00000101, 0x00000000,
795 0x82a, 0xffffffff, 0x00000104,
796 0x993, 0x000c0000, 0x000c0000,
797 0x992, 0x000c0000, 0x000c0000,
798 0x1579, 0xff000fff, 0x00000100,
799 0x157a, 0x00000001, 0x00000001,
800 0xbd4, 0x00000001, 0x00000001,
801 0xc33, 0xc0000fff, 0x00000104,
802 0x3079, 0x00000001, 0x00000001,
803 0x3430, 0xfffffff0, 0x00000100,
804 0x3630, 0xfffffff0, 0x00000100
805};
806static const u32 hainan_mgcg_cgcg_init[] =
807{
808 0x3100, 0xffffffff, 0xfffffffc,
809 0x200b, 0xffffffff, 0xe0000000,
810 0x2698, 0xffffffff, 0x00000100,
811 0x24a9, 0xffffffff, 0x00000100,
812 0x3059, 0xffffffff, 0x00000100,
813 0x25dd, 0xffffffff, 0x00000100,
814 0x2261, 0xffffffff, 0x06000100,
815 0x2286, 0xffffffff, 0x00000100,
816 0x24a8, 0xffffffff, 0x00000100,
817 0x30e0, 0xffffffff, 0x00000100,
818 0x22ca, 0xffffffff, 0x00000100,
819 0x2451, 0xffffffff, 0x00000100,
820 0x2362, 0xffffffff, 0x00000100,
821 0x2363, 0xffffffff, 0x00000100,
822 0x240c, 0xffffffff, 0x00000100,
823 0x240d, 0xffffffff, 0x00000100,
824 0x240e, 0xffffffff, 0x00000100,
825 0x240f, 0xffffffff, 0x00000100,
826 0x2b60, 0xffffffff, 0x00000100,
827 0x2b15, 0xffffffff, 0x00000100,
828 0x225f, 0xffffffff, 0x06000100,
829 0x261a, 0xffffffff, 0x00000100,
830 0x2544, 0xffffffff, 0x00000100,
831 0x2bc1, 0xffffffff, 0x00000100,
832 0x2b81, 0xffffffff, 0x00000100,
833 0x2527, 0xffffffff, 0x00000100,
834 0x200b, 0xffffffff, 0xe0000000,
835 0x2458, 0xffffffff, 0x00010000,
836 0x2459, 0xffffffff, 0x00030002,
837 0x245a, 0xffffffff, 0x00040007,
838 0x245b, 0xffffffff, 0x00060005,
839 0x245c, 0xffffffff, 0x00090008,
840 0x245d, 0xffffffff, 0x00020001,
841 0x245e, 0xffffffff, 0x00040003,
842 0x245f, 0xffffffff, 0x00000007,
843 0x2460, 0xffffffff, 0x00060005,
844 0x2461, 0xffffffff, 0x00090008,
845 0x2462, 0xffffffff, 0x00030002,
846 0x2463, 0xffffffff, 0x00050004,
847 0x2464, 0xffffffff, 0x00000008,
848 0x2465, 0xffffffff, 0x00070006,
849 0x2466, 0xffffffff, 0x000a0009,
850 0x2467, 0xffffffff, 0x00040003,
851 0x2468, 0xffffffff, 0x00060005,
852 0x2469, 0xffffffff, 0x00000009,
853 0x246a, 0xffffffff, 0x00080007,
854 0x246b, 0xffffffff, 0x000b000a,
855 0x246c, 0xffffffff, 0x00050004,
856 0x246d, 0xffffffff, 0x00070006,
857 0x246e, 0xffffffff, 0x0008000b,
858 0x246f, 0xffffffff, 0x000a0009,
859 0x2470, 0xffffffff, 0x000d000c,
860 0x2471, 0xffffffff, 0x00060005,
861 0x2472, 0xffffffff, 0x00080007,
862 0x2473, 0xffffffff, 0x0000000b,
863 0x2474, 0xffffffff, 0x000a0009,
864 0x2475, 0xffffffff, 0x000d000c,
865 0x2454, 0xffffffff, 0x96940200,
866 0x21c2, 0xffffffff, 0x00900100,
867 0x311e, 0xffffffff, 0x00000080,
868 0x3101, 0xffffffff, 0x0020003f,
869 0xc, 0xffffffff, 0x0000001c,
870 0xd, 0x000f0000, 0x000f0000,
871 0x583, 0xffffffff, 0x00000100,
872 0x409, 0xffffffff, 0x00000100,
873 0x82a, 0xffffffff, 0x00000104,
874 0x993, 0x000c0000, 0x000c0000,
875 0x992, 0x000c0000, 0x000c0000,
876 0xbd4, 0x00000001, 0x00000001,
877 0xc33, 0xc0000fff, 0x00000104,
878 0x3079, 0x00000001, 0x00000001,
879 0x3430, 0xfffffff0, 0x00000100,
880 0x3630, 0xfffffff0, 0x00000100
881};
882
883static u32 si_pcie_rreg(struct amdgpu_device *adev, u32 reg)
884{
885 unsigned long flags;
886 u32 r;
887
888 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
889 WREG32(AMDGPU_PCIE_INDEX, reg);
890 (void)RREG32(AMDGPU_PCIE_INDEX);
891 r = RREG32(AMDGPU_PCIE_DATA);
892 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
893 return r;
894}
895
896static void si_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
897{
898 unsigned long flags;
899
900 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
901 WREG32(AMDGPU_PCIE_INDEX, reg);
902 (void)RREG32(AMDGPU_PCIE_INDEX);
903 WREG32(AMDGPU_PCIE_DATA, v);
904 (void)RREG32(AMDGPU_PCIE_DATA);
905 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
906}
907
908static u32 si_smc_rreg(struct amdgpu_device *adev, u32 reg)
909{
910 unsigned long flags;
911 u32 r;
912
913 spin_lock_irqsave(&adev->smc_idx_lock, flags);
914 WREG32(SMC_IND_INDEX_0, (reg));
915 r = RREG32(SMC_IND_DATA_0);
916 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
917 return r;
918}
919
920static void si_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
921{
922 unsigned long flags;
923
924 spin_lock_irqsave(&adev->smc_idx_lock, flags);
925 WREG32(SMC_IND_INDEX_0, (reg));
926 WREG32(SMC_IND_DATA_0, (v));
927 spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
928}
929
930static u32 si_get_virtual_caps(struct amdgpu_device *adev)
931{
932 /* SI does not support SR-IOV */
933 return 0;
934}
935
936static struct amdgpu_allowed_register_entry si_allowed_read_registers[] = {
937 {GRBM_STATUS, false},
938 {GB_ADDR_CONFIG, false},
939 {MC_ARB_RAMCFG, false},
940 {GB_TILE_MODE0, false},
941 {GB_TILE_MODE1, false},
942 {GB_TILE_MODE2, false},
943 {GB_TILE_MODE3, false},
944 {GB_TILE_MODE4, false},
945 {GB_TILE_MODE5, false},
946 {GB_TILE_MODE6, false},
947 {GB_TILE_MODE7, false},
948 {GB_TILE_MODE8, false},
949 {GB_TILE_MODE9, false},
950 {GB_TILE_MODE10, false},
951 {GB_TILE_MODE11, false},
952 {GB_TILE_MODE12, false},
953 {GB_TILE_MODE13, false},
954 {GB_TILE_MODE14, false},
955 {GB_TILE_MODE15, false},
956 {GB_TILE_MODE16, false},
957 {GB_TILE_MODE17, false},
958 {GB_TILE_MODE18, false},
959 {GB_TILE_MODE19, false},
960 {GB_TILE_MODE20, false},
961 {GB_TILE_MODE21, false},
962 {GB_TILE_MODE22, false},
963 {GB_TILE_MODE23, false},
964 {GB_TILE_MODE24, false},
965 {GB_TILE_MODE25, false},
966 {GB_TILE_MODE26, false},
967 {GB_TILE_MODE27, false},
968 {GB_TILE_MODE28, false},
969 {GB_TILE_MODE29, false},
970 {GB_TILE_MODE30, false},
971 {GB_TILE_MODE31, false},
972 {CC_RB_BACKEND_DISABLE, false, true},
973 {GC_USER_RB_BACKEND_DISABLE, false, true},
974 {PA_SC_RASTER_CONFIG, false, true},
975};
976
977static uint32_t si_read_indexed_register(struct amdgpu_device *adev,
978 u32 se_num, u32 sh_num,
979 u32 reg_offset)
980{
981 uint32_t val;
982
983 mutex_lock(&adev->grbm_idx_mutex);
984 if (se_num != 0xffffffff || sh_num != 0xffffffff)
985 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
986
987 val = RREG32(reg_offset);
988
989 if (se_num != 0xffffffff || sh_num != 0xffffffff)
990 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
991 mutex_unlock(&adev->grbm_idx_mutex);
992 return val;
993}
994
995static int si_read_register(struct amdgpu_device *adev, u32 se_num,
996 u32 sh_num, u32 reg_offset, u32 *value)
997{
998 uint32_t i;
999
1000 *value = 0;
1001 for (i = 0; i < ARRAY_SIZE(si_allowed_read_registers); i++) {
1002 if (reg_offset != si_allowed_read_registers[i].reg_offset)
1003 continue;
1004
1005 if (!si_allowed_read_registers[i].untouched)
1006 *value = si_allowed_read_registers[i].grbm_indexed ?
1007 si_read_indexed_register(adev, se_num,
1008 sh_num, reg_offset) :
1009 RREG32(reg_offset);
1010 return 0;
1011 }
1012 return -EINVAL;
1013}
1014
1015static bool si_read_disabled_bios(struct amdgpu_device *adev)
1016{
1017 u32 bus_cntl;
1018 u32 d1vga_control = 0;
1019 u32 d2vga_control = 0;
1020 u32 vga_render_control = 0;
1021 u32 rom_cntl;
1022 bool r;
1023
1024 bus_cntl = RREG32(R600_BUS_CNTL);
1025 if (adev->mode_info.num_crtc) {
1026 d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
1027 d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
1028 vga_render_control = RREG32(VGA_RENDER_CONTROL);
1029 }
1030 rom_cntl = RREG32(R600_ROM_CNTL);
1031
1032 /* enable the rom */
1033 WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS));
1034 if (adev->mode_info.num_crtc) {
1035 /* Disable VGA mode */
1036 WREG32(AVIVO_D1VGA_CONTROL,
1037 (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
1038 AVIVO_DVGA_CONTROL_TIMING_SELECT)));
1039 WREG32(AVIVO_D2VGA_CONTROL,
1040 (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
1041 AVIVO_DVGA_CONTROL_TIMING_SELECT)));
1042 WREG32(VGA_RENDER_CONTROL,
1043 (vga_render_control & C_000300_VGA_VSTATUS_CNTL));
1044 }
1045 WREG32(R600_ROM_CNTL, rom_cntl | R600_SCK_OVERWRITE);
1046
1047 r = amdgpu_read_bios(adev);
1048
1049 /* restore regs */
1050 WREG32(R600_BUS_CNTL, bus_cntl);
1051 if (adev->mode_info.num_crtc) {
1052 WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
1053 WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
1054 WREG32(VGA_RENDER_CONTROL, vga_render_control);
1055 }
1056 WREG32(R600_ROM_CNTL, rom_cntl);
1057 return r;
1058}
1059
1060//xxx: not implemented
1061static int si_asic_reset(struct amdgpu_device *adev)
1062{
1063 return 0;
1064}
1065
1066static void si_vga_set_state(struct amdgpu_device *adev, bool state)
1067{
1068 uint32_t temp;
1069
1070 temp = RREG32(CONFIG_CNTL);
1071 if (state == false) {
1072 temp &= ~(1<<0);
1073 temp |= (1<<1);
1074 } else {
1075 temp &= ~(1<<1);
1076 }
1077 WREG32(CONFIG_CNTL, temp);
1078}
1079
1080static u32 si_get_xclk(struct amdgpu_device *adev)
1081{
1082 u32 reference_clock = adev->clock.spll.reference_freq;
1083 u32 tmp;
1084
1085 tmp = RREG32(CG_CLKPIN_CNTL_2);
1086 if (tmp & MUX_TCLK_TO_XCLK)
1087 return TCLK;
1088
1089 tmp = RREG32(CG_CLKPIN_CNTL);
1090 if (tmp & XTALIN_DIVIDE)
1091 return reference_clock / 4;
1092
1093 return reference_clock;
1094}
1095//xxx:not implemented
1096static int si_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
1097{
1098 return 0;
1099}
1100
1101static const struct amdgpu_asic_funcs si_asic_funcs =
1102{
1103 .read_disabled_bios = &si_read_disabled_bios,
1104 .read_register = &si_read_register,
1105 .reset = &si_asic_reset,
1106 .set_vga_state = &si_vga_set_state,
1107 .get_xclk = &si_get_xclk,
1108 .set_uvd_clocks = &si_set_uvd_clocks,
1109 .set_vce_clocks = NULL,
1110 .get_virtual_caps = &si_get_virtual_caps,
1111};
1112
1113static uint32_t si_get_rev_id(struct amdgpu_device *adev)
1114{
1115 return (RREG32(CC_DRM_ID_STRAPS) & CC_DRM_ID_STRAPS__ATI_REV_ID_MASK)
1116 >> CC_DRM_ID_STRAPS__ATI_REV_ID__SHIFT;
1117}
1118
1119static int si_common_early_init(void *handle)
1120{
1121 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1122
1123 adev->smc_rreg = &si_smc_rreg;
1124 adev->smc_wreg = &si_smc_wreg;
1125 adev->pcie_rreg = &si_pcie_rreg;
1126 adev->pcie_wreg = &si_pcie_wreg;
1127 adev->uvd_ctx_rreg = NULL;
1128 adev->uvd_ctx_wreg = NULL;
1129 adev->didt_rreg = NULL;
1130 adev->didt_wreg = NULL;
1131
1132 adev->asic_funcs = &si_asic_funcs;
1133
1134 adev->rev_id = si_get_rev_id(adev);
1135 adev->external_rev_id = 0xFF;
1136 switch (adev->asic_type) {
1137 case CHIP_TAHITI:
1138 adev->cg_flags =
1139 AMD_CG_SUPPORT_GFX_MGCG |
1140 AMD_CG_SUPPORT_GFX_MGLS |
1141 /*AMD_CG_SUPPORT_GFX_CGCG |*/
1142 AMD_CG_SUPPORT_GFX_CGLS |
1143 AMD_CG_SUPPORT_GFX_CGTS |
1144 AMD_CG_SUPPORT_GFX_CP_LS |
1145 AMD_CG_SUPPORT_MC_MGCG |
1146 AMD_CG_SUPPORT_SDMA_MGCG |
1147 AMD_CG_SUPPORT_BIF_LS |
1148 AMD_CG_SUPPORT_VCE_MGCG |
1149 AMD_CG_SUPPORT_UVD_MGCG |
1150 AMD_CG_SUPPORT_HDP_LS |
1151 AMD_CG_SUPPORT_HDP_MGCG;
1152 adev->pg_flags = 0;
1153 break;
1154 case CHIP_PITCAIRN:
1155 adev->cg_flags =
1156 AMD_CG_SUPPORT_GFX_MGCG |
1157 AMD_CG_SUPPORT_GFX_MGLS |
1158 /*AMD_CG_SUPPORT_GFX_CGCG |*/
1159 AMD_CG_SUPPORT_GFX_CGLS |
1160 AMD_CG_SUPPORT_GFX_CGTS |
1161 AMD_CG_SUPPORT_GFX_CP_LS |
1162 AMD_CG_SUPPORT_GFX_RLC_LS |
1163 AMD_CG_SUPPORT_MC_LS |
1164 AMD_CG_SUPPORT_MC_MGCG |
1165 AMD_CG_SUPPORT_SDMA_MGCG |
1166 AMD_CG_SUPPORT_BIF_LS |
1167 AMD_CG_SUPPORT_VCE_MGCG |
1168 AMD_CG_SUPPORT_UVD_MGCG |
1169 AMD_CG_SUPPORT_HDP_LS |
1170 AMD_CG_SUPPORT_HDP_MGCG;
1171 adev->pg_flags = 0;
1172 break;
1173
1174 case CHIP_VERDE:
1175 adev->cg_flags =
1176 AMD_CG_SUPPORT_GFX_MGCG |
1177 AMD_CG_SUPPORT_GFX_MGLS |
1178 AMD_CG_SUPPORT_GFX_CGLS |
1179 AMD_CG_SUPPORT_GFX_CGTS |
1180 AMD_CG_SUPPORT_GFX_CGTS_LS |
1181 AMD_CG_SUPPORT_GFX_CP_LS |
1182 AMD_CG_SUPPORT_MC_LS |
1183 AMD_CG_SUPPORT_MC_MGCG |
1184 AMD_CG_SUPPORT_SDMA_MGCG |
1185 AMD_CG_SUPPORT_SDMA_LS |
1186 AMD_CG_SUPPORT_BIF_LS |
1187 AMD_CG_SUPPORT_VCE_MGCG |
1188 AMD_CG_SUPPORT_UVD_MGCG |
1189 AMD_CG_SUPPORT_HDP_LS |
1190 AMD_CG_SUPPORT_HDP_MGCG;
1191 adev->pg_flags = 0;
1192 //???
1193 adev->external_rev_id = adev->rev_id + 0x14;
1194 break;
1195 case CHIP_OLAND:
1196 adev->cg_flags =
1197 AMD_CG_SUPPORT_GFX_MGCG |
1198 AMD_CG_SUPPORT_GFX_MGLS |
1199 /*AMD_CG_SUPPORT_GFX_CGCG |*/
1200 AMD_CG_SUPPORT_GFX_CGLS |
1201 AMD_CG_SUPPORT_GFX_CGTS |
1202 AMD_CG_SUPPORT_GFX_CP_LS |
1203 AMD_CG_SUPPORT_GFX_RLC_LS |
1204 AMD_CG_SUPPORT_MC_LS |
1205 AMD_CG_SUPPORT_MC_MGCG |
1206 AMD_CG_SUPPORT_SDMA_MGCG |
1207 AMD_CG_SUPPORT_BIF_LS |
1208 AMD_CG_SUPPORT_UVD_MGCG |
1209 AMD_CG_SUPPORT_HDP_LS |
1210 AMD_CG_SUPPORT_HDP_MGCG;
1211 adev->pg_flags = 0;
1212 break;
1213 case CHIP_HAINAN:
1214 adev->cg_flags =
1215 AMD_CG_SUPPORT_GFX_MGCG |
1216 AMD_CG_SUPPORT_GFX_MGLS |
1217 /*AMD_CG_SUPPORT_GFX_CGCG |*/
1218 AMD_CG_SUPPORT_GFX_CGLS |
1219 AMD_CG_SUPPORT_GFX_CGTS |
1220 AMD_CG_SUPPORT_GFX_CP_LS |
1221 AMD_CG_SUPPORT_GFX_RLC_LS |
1222 AMD_CG_SUPPORT_MC_LS |
1223 AMD_CG_SUPPORT_MC_MGCG |
1224 AMD_CG_SUPPORT_SDMA_MGCG |
1225 AMD_CG_SUPPORT_BIF_LS |
1226 AMD_CG_SUPPORT_HDP_LS |
1227 AMD_CG_SUPPORT_HDP_MGCG;
1228 adev->pg_flags = 0;
1229 break;
1230
1231 default:
1232 return -EINVAL;
1233 }
1234
1235 return 0;
1236}
1237
1238static int si_common_sw_init(void *handle)
1239{
1240 return 0;
1241}
1242
1243static int si_common_sw_fini(void *handle)
1244{
1245 return 0;
1246}
1247
1248
1249static void si_init_golden_registers(struct amdgpu_device *adev)
1250{
1251 switch (adev->asic_type) {
1252 case CHIP_TAHITI:
1253 amdgpu_program_register_sequence(adev,
1254 tahiti_golden_registers,
1255 (const u32)ARRAY_SIZE(tahiti_golden_registers));
1256 amdgpu_program_register_sequence(adev,
1257 tahiti_golden_rlc_registers,
1258 (const u32)ARRAY_SIZE(tahiti_golden_rlc_registers));
1259 amdgpu_program_register_sequence(adev,
1260 tahiti_mgcg_cgcg_init,
1261 (const u32)ARRAY_SIZE(tahiti_mgcg_cgcg_init));
1262 amdgpu_program_register_sequence(adev,
1263 tahiti_golden_registers2,
1264 (const u32)ARRAY_SIZE(tahiti_golden_registers2));
1265 break;
1266 case CHIP_PITCAIRN:
1267 amdgpu_program_register_sequence(adev,
1268 pitcairn_golden_registers,
1269 (const u32)ARRAY_SIZE(pitcairn_golden_registers));
1270 amdgpu_program_register_sequence(adev,
1271 pitcairn_golden_rlc_registers,
1272 (const u32)ARRAY_SIZE(pitcairn_golden_rlc_registers));
1273 amdgpu_program_register_sequence(adev,
1274 pitcairn_mgcg_cgcg_init,
1275 (const u32)ARRAY_SIZE(pitcairn_mgcg_cgcg_init));
1276 case CHIP_VERDE:
1277 amdgpu_program_register_sequence(adev,
1278 verde_golden_registers,
1279 (const u32)ARRAY_SIZE(verde_golden_registers));
1280 amdgpu_program_register_sequence(adev,
1281 verde_golden_rlc_registers,
1282 (const u32)ARRAY_SIZE(verde_golden_rlc_registers));
1283 amdgpu_program_register_sequence(adev,
1284 verde_mgcg_cgcg_init,
1285 (const u32)ARRAY_SIZE(verde_mgcg_cgcg_init));
1286 amdgpu_program_register_sequence(adev,
1287 verde_pg_init,
1288 (const u32)ARRAY_SIZE(verde_pg_init));
1289 break;
1290 case CHIP_OLAND:
1291 amdgpu_program_register_sequence(adev,
1292 oland_golden_registers,
1293 (const u32)ARRAY_SIZE(oland_golden_registers));
1294 amdgpu_program_register_sequence(adev,
1295 oland_golden_rlc_registers,
1296 (const u32)ARRAY_SIZE(oland_golden_rlc_registers));
1297 amdgpu_program_register_sequence(adev,
1298 oland_mgcg_cgcg_init,
1299 (const u32)ARRAY_SIZE(oland_mgcg_cgcg_init));
1300 case CHIP_HAINAN:
1301 amdgpu_program_register_sequence(adev,
1302 hainan_golden_registers,
1303 (const u32)ARRAY_SIZE(hainan_golden_registers));
1304 amdgpu_program_register_sequence(adev,
1305 hainan_golden_registers2,
1306 (const u32)ARRAY_SIZE(hainan_golden_registers2));
1307 amdgpu_program_register_sequence(adev,
1308 hainan_mgcg_cgcg_init,
1309 (const u32)ARRAY_SIZE(hainan_mgcg_cgcg_init));
1310 break;
1311
1312
1313 default:
1314 BUG();
1315 }
1316}
1317
1318u32 si_pciep_rreg(struct amdgpu_device *adev, u32 reg)
1319{
1320 unsigned long flags;
1321 u32 r;
1322
1323 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1324 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1325 (void)RREG32(PCIE_PORT_INDEX);
1326 r = RREG32(PCIE_PORT_DATA);
1327 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1328 return r;
1329}
1330
1331void si_pciep_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
1332{
1333 unsigned long flags;
1334
1335 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1336 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1337 (void)RREG32(PCIE_PORT_INDEX);
1338 WREG32(PCIE_PORT_DATA, (v));
1339 (void)RREG32(PCIE_PORT_DATA);
1340 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1341}
1342
1343static void si_pcie_gen3_enable(struct amdgpu_device *adev)
1344{
1345 struct pci_dev *root = adev->pdev->bus->self;
1346 int bridge_pos, gpu_pos;
1347 u32 speed_cntl, mask, current_data_rate;
1348 int ret, i;
1349 u16 tmp16;
1350
1351 if (pci_is_root_bus(adev->pdev->bus))
1352 return;
1353
1354 if (amdgpu_pcie_gen2 == 0)
1355 return;
1356
1357 if (adev->flags & AMD_IS_APU)
1358 return;
1359
1360 ret = drm_pcie_get_speed_cap_mask(adev->ddev, &mask);
1361 if (ret != 0)
1362 return;
1363
1364 if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
1365 return;
1366
1367 speed_cntl = si_pciep_rreg(adev,PCIE_LC_SPEED_CNTL);
1368 current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
1369 LC_CURRENT_DATA_RATE_SHIFT;
1370 if (mask & DRM_PCIE_SPEED_80) {
1371 if (current_data_rate == 2) {
1372 DRM_INFO("PCIE gen 3 link speeds already enabled\n");
1373 return;
1374 }
1375 DRM_INFO("enabling PCIE gen 3 link speeds, disable with amdgpu.pcie_gen2=0\n");
1376 } else if (mask & DRM_PCIE_SPEED_50) {
1377 if (current_data_rate == 1) {
1378 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
1379 return;
1380 }
1381 DRM_INFO("enabling PCIE gen 2 link speeds, disable with amdgpu.pcie_gen2=0\n");
1382 }
1383
1384 bridge_pos = pci_pcie_cap(root);
1385 if (!bridge_pos)
1386 return;
1387
1388 gpu_pos = pci_pcie_cap(adev->pdev);
1389 if (!gpu_pos)
1390 return;
1391
1392 if (mask & DRM_PCIE_SPEED_80) {
1393 if (current_data_rate != 2) {
1394 u16 bridge_cfg, gpu_cfg;
1395 u16 bridge_cfg2, gpu_cfg2;
1396 u32 max_lw, current_lw, tmp;
1397
1398 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
1399 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
1400
1401 tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
1402 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
1403
1404 tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
1405 pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
1406
1407 tmp = RREG32_PCIE(PCIE_LC_STATUS1);
1408 max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
1409 current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
1410
1411 if (current_lw < max_lw) {
1412 tmp = si_pciep_rreg(adev, PCIE_LC_LINK_WIDTH_CNTL);
1413 if (tmp & LC_RENEGOTIATION_SUPPORT) {
1414 tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
1415 tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
1416 tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
1417 si_pciep_wreg(adev, PCIE_LC_LINK_WIDTH_CNTL, tmp);
1418 }
1419 }
1420
1421 for (i = 0; i < 10; i++) {
1422 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
1423 if (tmp16 & PCI_EXP_DEVSTA_TRPND)
1424 break;
1425
1426 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
1427 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
1428
1429 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
1430 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
1431
1432 tmp = si_pciep_rreg(adev, PCIE_LC_CNTL4);
1433 tmp |= LC_SET_QUIESCE;
1434 si_pciep_wreg(adev,PCIE_LC_CNTL4, tmp);
1435
1436 tmp = si_pciep_rreg(adev, PCIE_LC_CNTL4);
1437 tmp |= LC_REDO_EQ;
1438 si_pciep_wreg(adev, PCIE_LC_CNTL4, tmp);
1439
1440 mdelay(100);
1441
1442 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
1443 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
1444 tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
1445 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
1446
1447 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
1448 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
1449 tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
1450 pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
1451
1452 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
1453 tmp16 &= ~((1 << 4) | (7 << 9));
1454 tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
1455 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
1456
1457 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
1458 tmp16 &= ~((1 << 4) | (7 << 9));
1459 tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
1460 pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
1461
1462 tmp = si_pciep_rreg(adev, PCIE_LC_CNTL4);
1463 tmp &= ~LC_SET_QUIESCE;
1464 si_pciep_wreg(adev, PCIE_LC_CNTL4, tmp);
1465 }
1466 }
1467 }
1468
1469 speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
1470 speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
1471 si_pciep_wreg(adev, PCIE_LC_SPEED_CNTL, speed_cntl);
1472
1473 pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
1474 tmp16 &= ~0xf;
1475 if (mask & DRM_PCIE_SPEED_80)
1476 tmp16 |= 3;
1477 else if (mask & DRM_PCIE_SPEED_50)
1478 tmp16 |= 2;
1479 else
1480 tmp16 |= 1;
1481 pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
1482
1483 speed_cntl = si_pciep_rreg(adev, PCIE_LC_SPEED_CNTL);
1484 speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
1485 si_pciep_wreg(adev, PCIE_LC_SPEED_CNTL, speed_cntl);
1486
1487 for (i = 0; i < adev->usec_timeout; i++) {
1488 speed_cntl = si_pciep_rreg(adev, PCIE_LC_SPEED_CNTL);
1489 if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
1490 break;
1491 udelay(1);
1492 }
1493}
1494
1495static inline u32 si_pif_phy0_rreg(struct amdgpu_device *adev, u32 reg)
1496{
1497 unsigned long flags;
1498 u32 r;
1499
1500 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1501 WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
1502 r = RREG32(EVERGREEN_PIF_PHY0_DATA);
1503 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1504 return r;
1505}
1506
1507static inline void si_pif_phy0_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
1508{
1509 unsigned long flags;
1510
1511 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1512 WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
1513 WREG32(EVERGREEN_PIF_PHY0_DATA, (v));
1514 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1515}
1516
1517static inline u32 si_pif_phy1_rreg(struct amdgpu_device *adev, u32 reg)
1518{
1519 unsigned long flags;
1520 u32 r;
1521
1522 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1523 WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
1524 r = RREG32(EVERGREEN_PIF_PHY1_DATA);
1525 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1526 return r;
1527}
1528
1529static inline void si_pif_phy1_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
1530{
1531 unsigned long flags;
1532
1533 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
1534 WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
1535 WREG32(EVERGREEN_PIF_PHY1_DATA, (v));
1536 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
1537}
1538static void si_program_aspm(struct amdgpu_device *adev)
1539{
1540 u32 data, orig;
1541 bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
1542 bool disable_clkreq = false;
1543
1544 if (amdgpu_aspm == 0)
1545 return;
1546
1547 if (adev->flags & AMD_IS_APU)
1548 return;
1549 orig = data = si_pciep_rreg(adev, PCIE_LC_N_FTS_CNTL);
1550 data &= ~LC_XMIT_N_FTS_MASK;
1551 data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
1552 if (orig != data)
1553 si_pciep_wreg(adev, PCIE_LC_N_FTS_CNTL, data);
1554
1555 orig = data = si_pciep_rreg(adev, PCIE_LC_CNTL3);
1556 data |= LC_GO_TO_RECOVERY;
1557 if (orig != data)
1558 si_pciep_wreg(adev, PCIE_LC_CNTL3, data);
1559
1560 orig = data = RREG32_PCIE(PCIE_P_CNTL);
1561 data |= P_IGNORE_EDB_ERR;
1562 if (orig != data)
1563 WREG32_PCIE(PCIE_P_CNTL, data);
1564
1565 orig = data = si_pciep_rreg(adev, PCIE_LC_CNTL);
1566 data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
1567 data |= LC_PMI_TO_L1_DIS;
1568 if (!disable_l0s)
1569 data |= LC_L0S_INACTIVITY(7);
1570
1571 if (!disable_l1) {
1572 data |= LC_L1_INACTIVITY(7);
1573 data &= ~LC_PMI_TO_L1_DIS;
1574 if (orig != data)
1575 si_pciep_wreg(adev, PCIE_LC_CNTL, data);
1576
1577 if (!disable_plloff_in_l1) {
1578 bool clk_req_support;
1579
1580 orig = data = si_pif_phy0_rreg(adev,PB0_PIF_PWRDOWN_0);
1581 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
1582 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
1583 if (orig != data)
1584 si_pif_phy0_wreg(adev,PB0_PIF_PWRDOWN_0, data);
1585
1586 orig = data = si_pif_phy0_rreg(adev,PB0_PIF_PWRDOWN_1);
1587 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
1588 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
1589 if (orig != data)
1590 si_pif_phy0_wreg(adev,PB0_PIF_PWRDOWN_1, data);
1591
1592 orig = data = si_pif_phy1_rreg(adev,PB1_PIF_PWRDOWN_0);
1593 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
1594 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
1595 if (orig != data)
1596 si_pif_phy1_wreg(adev,PB1_PIF_PWRDOWN_0, data);
1597
1598 orig = data = si_pif_phy1_rreg(adev,PB1_PIF_PWRDOWN_1);
1599 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
1600 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
1601 if (orig != data)
1602 si_pif_phy1_wreg(adev,PB1_PIF_PWRDOWN_1, data);
1603
1604 if ((adev->family != CHIP_OLAND) && (adev->family != CHIP_HAINAN)) {
1605 orig = data = si_pif_phy0_rreg(adev,PB0_PIF_PWRDOWN_0);
1606 data &= ~PLL_RAMP_UP_TIME_0_MASK;
1607 if (orig != data)
1608 si_pif_phy0_wreg(adev,PB0_PIF_PWRDOWN_0, data);
1609
1610 orig = data = si_pif_phy0_rreg(adev,PB0_PIF_PWRDOWN_1);
1611 data &= ~PLL_RAMP_UP_TIME_1_MASK;
1612 if (orig != data)
1613 si_pif_phy0_wreg(adev,PB0_PIF_PWRDOWN_1, data);
1614
1615 orig = data = si_pif_phy0_rreg(adev,PB0_PIF_PWRDOWN_2);
1616 data &= ~PLL_RAMP_UP_TIME_2_MASK;
1617 if (orig != data)
1618 si_pif_phy0_wreg(adev,PB0_PIF_PWRDOWN_2, data);
1619
1620 orig = data = si_pif_phy0_rreg(adev,PB0_PIF_PWRDOWN_3);
1621 data &= ~PLL_RAMP_UP_TIME_3_MASK;
1622 if (orig != data)
1623 si_pif_phy0_wreg(adev,PB0_PIF_PWRDOWN_3, data);
1624
1625 orig = data = si_pif_phy1_rreg(adev,PB1_PIF_PWRDOWN_0);
1626 data &= ~PLL_RAMP_UP_TIME_0_MASK;
1627 if (orig != data)
1628 si_pif_phy1_wreg(adev,PB1_PIF_PWRDOWN_0, data);
1629
1630 orig = data = si_pif_phy1_rreg(adev,PB1_PIF_PWRDOWN_1);
1631 data &= ~PLL_RAMP_UP_TIME_1_MASK;
1632 if (orig != data)
1633 si_pif_phy1_wreg(adev,PB1_PIF_PWRDOWN_1, data);
1634
1635 orig = data = si_pif_phy1_rreg(adev,PB1_PIF_PWRDOWN_2);
1636 data &= ~PLL_RAMP_UP_TIME_2_MASK;
1637 if (orig != data)
1638 si_pif_phy1_wreg(adev,PB1_PIF_PWRDOWN_2, data);
1639
1640 orig = data = si_pif_phy1_rreg(adev,PB1_PIF_PWRDOWN_3);
1641 data &= ~PLL_RAMP_UP_TIME_3_MASK;
1642 if (orig != data)
1643 si_pif_phy1_wreg(adev,PB1_PIF_PWRDOWN_3, data);
1644 }
1645 orig = data = si_pciep_rreg(adev, PCIE_LC_LINK_WIDTH_CNTL);
1646 data &= ~LC_DYN_LANES_PWR_STATE_MASK;
1647 data |= LC_DYN_LANES_PWR_STATE(3);
1648 if (orig != data)
1649 si_pciep_wreg(adev, PCIE_LC_LINK_WIDTH_CNTL, data);
1650
1651 orig = data = si_pif_phy0_rreg(adev,PB0_PIF_CNTL);
1652 data &= ~LS2_EXIT_TIME_MASK;
1653 if ((adev->family == CHIP_OLAND) || (adev->family == CHIP_HAINAN))
1654 data |= LS2_EXIT_TIME(5);
1655 if (orig != data)
1656 si_pif_phy0_wreg(adev,PB0_PIF_CNTL, data);
1657
1658 orig = data = si_pif_phy1_rreg(adev,PB1_PIF_CNTL);
1659 data &= ~LS2_EXIT_TIME_MASK;
1660 if ((adev->family == CHIP_OLAND) || (adev->family == CHIP_HAINAN))
1661 data |= LS2_EXIT_TIME(5);
1662 if (orig != data)
1663 si_pif_phy1_wreg(adev,PB1_PIF_CNTL, data);
1664
1665 if (!disable_clkreq &&
1666 !pci_is_root_bus(adev->pdev->bus)) {
1667 struct pci_dev *root = adev->pdev->bus->self;
1668 u32 lnkcap;
1669
1670 clk_req_support = false;
1671 pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
1672 if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
1673 clk_req_support = true;
1674 } else {
1675 clk_req_support = false;
1676 }
1677
1678 if (clk_req_support) {
1679 orig = data = si_pciep_rreg(adev, PCIE_LC_CNTL2);
1680 data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
1681 if (orig != data)
1682 si_pciep_wreg(adev, PCIE_LC_CNTL2, data);
1683
1684 orig = data = RREG32(THM_CLK_CNTL);
1685 data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
1686 data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
1687 if (orig != data)
1688 WREG32(THM_CLK_CNTL, data);
1689
1690 orig = data = RREG32(MISC_CLK_CNTL);
1691 data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
1692 data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
1693 if (orig != data)
1694 WREG32(MISC_CLK_CNTL, data);
1695
1696 orig = data = RREG32(CG_CLKPIN_CNTL);
1697 data &= ~BCLK_AS_XCLK;
1698 if (orig != data)
1699 WREG32(CG_CLKPIN_CNTL, data);
1700
1701 orig = data = RREG32(CG_CLKPIN_CNTL_2);
1702 data &= ~FORCE_BIF_REFCLK_EN;
1703 if (orig != data)
1704 WREG32(CG_CLKPIN_CNTL_2, data);
1705
1706 orig = data = RREG32(MPLL_BYPASSCLK_SEL);
1707 data &= ~MPLL_CLKOUT_SEL_MASK;
1708 data |= MPLL_CLKOUT_SEL(4);
1709 if (orig != data)
1710 WREG32(MPLL_BYPASSCLK_SEL, data);
1711
1712 orig = data = RREG32(SPLL_CNTL_MODE);
1713 data &= ~SPLL_REFCLK_SEL_MASK;
1714 if (orig != data)
1715 WREG32(SPLL_CNTL_MODE, data);
1716 }
1717 }
1718 } else {
1719 if (orig != data)
1720 si_pciep_wreg(adev, PCIE_LC_CNTL, data);
1721 }
1722
1723 orig = data = RREG32_PCIE(PCIE_CNTL2);
1724 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
1725 if (orig != data)
1726 WREG32_PCIE(PCIE_CNTL2, data);
1727
1728 if (!disable_l0s) {
1729 data = si_pciep_rreg(adev, PCIE_LC_N_FTS_CNTL);
1730 if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
1731 data = RREG32_PCIE(PCIE_LC_STATUS1);
1732 if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
1733 orig = data = si_pciep_rreg(adev, PCIE_LC_CNTL);
1734 data &= ~LC_L0S_INACTIVITY_MASK;
1735 if (orig != data)
1736 si_pciep_wreg(adev, PCIE_LC_CNTL, data);
1737 }
1738 }
1739 }
1740}
1741
1742static void si_fix_pci_max_read_req_size(struct amdgpu_device *adev)
1743{
1744 int readrq;
1745 u16 v;
1746
1747 readrq = pcie_get_readrq(adev->pdev);
1748 v = ffs(readrq) - 8;
1749 if ((v == 0) || (v == 6) || (v == 7))
1750 pcie_set_readrq(adev->pdev, 512);
1751}
1752
1753static int si_common_hw_init(void *handle)
1754{
1755 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1756
1757 si_fix_pci_max_read_req_size(adev);
1758 si_init_golden_registers(adev);
1759 si_pcie_gen3_enable(adev);
1760 si_program_aspm(adev);
1761
1762 return 0;
1763}
1764
1765static int si_common_hw_fini(void *handle)
1766{
1767 return 0;
1768}
1769
1770static int si_common_suspend(void *handle)
1771{
1772 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1773
1774 return si_common_hw_fini(adev);
1775}
1776
1777static int si_common_resume(void *handle)
1778{
1779 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1780
1781 return si_common_hw_init(adev);
1782}
1783
1784static bool si_common_is_idle(void *handle)
1785{
1786 return true;
1787}
1788
1789static int si_common_wait_for_idle(void *handle)
1790{
1791 return 0;
1792}
1793
1794static int si_common_soft_reset(void *handle)
1795{
1796 return 0;
1797}
1798
1799static int si_common_set_clockgating_state(void *handle,
1800 enum amd_clockgating_state state)
1801{
1802 return 0;
1803}
1804
1805static int si_common_set_powergating_state(void *handle,
1806 enum amd_powergating_state state)
1807{
1808 return 0;
1809}
1810
1811const struct amd_ip_funcs si_common_ip_funcs = {
1812 .name = "si_common",
1813 .early_init = si_common_early_init,
1814 .late_init = NULL,
1815 .sw_init = si_common_sw_init,
1816 .sw_fini = si_common_sw_fini,
1817 .hw_init = si_common_hw_init,
1818 .hw_fini = si_common_hw_fini,
1819 .suspend = si_common_suspend,
1820 .resume = si_common_resume,
1821 .is_idle = si_common_is_idle,
1822 .wait_for_idle = si_common_wait_for_idle,
1823 .soft_reset = si_common_soft_reset,
1824 .set_clockgating_state = si_common_set_clockgating_state,
1825 .set_powergating_state = si_common_set_powergating_state,
1826};
1827
1828static const struct amdgpu_ip_block_version verde_ip_blocks[] =
1829{
1830 {
1831 .type = AMD_IP_BLOCK_TYPE_COMMON,
1832 .major = 1,
1833 .minor = 0,
1834 .rev = 0,
1835 .funcs = &si_common_ip_funcs,
1836 },
1837 {
1838 .type = AMD_IP_BLOCK_TYPE_GMC,
1839 .major = 6,
1840 .minor = 0,
1841 .rev = 0,
1842 .funcs = &gmc_v6_0_ip_funcs,
1843 },
1844 {
1845 .type = AMD_IP_BLOCK_TYPE_IH,
1846 .major = 1,
1847 .minor = 0,
1848 .rev = 0,
1849 .funcs = &si_ih_ip_funcs,
1850 },
1851/* {
1852 .type = AMD_IP_BLOCK_TYPE_SMC,
1853 .major = 6,
1854 .minor = 0,
1855 .rev = 0,
1856 .funcs = &si_null_ip_funcs,
1857 },
1858 */
1859 {
1860 .type = AMD_IP_BLOCK_TYPE_DCE,
1861 .major = 6,
1862 .minor = 0,
1863 .rev = 0,
1864 .funcs = &dce_v6_0_ip_funcs,
1865 },
1866 {
1867 .type = AMD_IP_BLOCK_TYPE_GFX,
1868 .major = 6,
1869 .minor = 0,
1870 .rev = 0,
1871 .funcs = &gfx_v6_0_ip_funcs,
1872 },
1873 {
1874 .type = AMD_IP_BLOCK_TYPE_SDMA,
1875 .major = 1,
1876 .minor = 0,
1877 .rev = 0,
1878 .funcs = &si_dma_ip_funcs,
1879 },
1880/* {
1881 .type = AMD_IP_BLOCK_TYPE_UVD,
1882 .major = 3,
1883 .minor = 1,
1884 .rev = 0,
1885 .funcs = &si_null_ip_funcs,
1886 },
1887 {
1888 .type = AMD_IP_BLOCK_TYPE_VCE,
1889 .major = 1,
1890 .minor = 0,
1891 .rev = 0,
1892 .funcs = &si_null_ip_funcs,
1893 },
1894 */
1895};
1896
1897
1898static const struct amdgpu_ip_block_version hainan_ip_blocks[] =
1899{
1900 {
1901 .type = AMD_IP_BLOCK_TYPE_COMMON,
1902 .major = 1,
1903 .minor = 0,
1904 .rev = 0,
1905 .funcs = &si_common_ip_funcs,
1906 },
1907 {
1908 .type = AMD_IP_BLOCK_TYPE_GMC,
1909 .major = 6,
1910 .minor = 0,
1911 .rev = 0,
1912 .funcs = &gmc_v6_0_ip_funcs,
1913 },
1914 {
1915 .type = AMD_IP_BLOCK_TYPE_IH,
1916 .major = 1,
1917 .minor = 0,
1918 .rev = 0,
1919 .funcs = &si_ih_ip_funcs,
1920 },
1921 {
1922 .type = AMD_IP_BLOCK_TYPE_SMC,
1923 .major = 6,
1924 .minor = 0,
1925 .rev = 0,
1926 .funcs = &si_null_ip_funcs,
1927 },
1928 {
1929 .type = AMD_IP_BLOCK_TYPE_GFX,
1930 .major = 6,
1931 .minor = 0,
1932 .rev = 0,
1933 .funcs = &gfx_v6_0_ip_funcs,
1934 },
1935 {
1936 .type = AMD_IP_BLOCK_TYPE_SDMA,
1937 .major = 1,
1938 .minor = 0,
1939 .rev = 0,
1940 .funcs = &si_dma_ip_funcs,
1941 },
1942};
1943
1944int si_set_ip_blocks(struct amdgpu_device *adev)
1945{
1946 switch (adev->asic_type) {
1947 case CHIP_VERDE:
1948 case CHIP_TAHITI:
1949 case CHIP_PITCAIRN:
1950 case CHIP_OLAND:
1951 adev->ip_blocks = verde_ip_blocks;
1952 adev->num_ip_blocks = ARRAY_SIZE(verde_ip_blocks);
1953 break;
1954 case CHIP_HAINAN:
1955 adev->ip_blocks = hainan_ip_blocks;
1956 adev->num_ip_blocks = ARRAY_SIZE(hainan_ip_blocks);
1957 break;
1958 default:
1959 BUG();
1960 }
1961 return 0;
1962}
1963