blob: 1531f167d152a3e24284e976bde657c28b31e8fe [file] [log] [blame]
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001/*
2 * Copyright 2010 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/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
David Howells760285e2012-10-02 18:01:07 +010027#include <drm/drmP.h>
Alex Deucherbcc1c2a2010-01-12 17:54:34 -050028#include "radeon.h"
Daniel Vettere6990372010-03-11 21:19:17 +000029#include "radeon_asic.h"
David Howells760285e2012-10-02 18:01:07 +010030#include <drm/radeon_drm.h>
Alex Deucher0fcdb612010-03-24 13:20:41 -040031#include "evergreend.h"
Alex Deucherbcc1c2a2010-01-12 17:54:34 -050032#include "atom.h"
33#include "avivod.h"
34#include "evergreen_reg.h"
Alex Deucher2281a372010-10-21 13:31:38 -040035#include "evergreen_blit_shaders.h"
Alex Deucherbcc1c2a2010-01-12 17:54:34 -050036
Alex Deucherfe251e22010-03-24 13:36:43 -040037#define EVERGREEN_PFP_UCODE_SIZE 1120
38#define EVERGREEN_PM4_UCODE_SIZE 1376
39
Alex Deucher4a159032012-08-15 17:13:53 -040040static const u32 crtc_offsets[6] =
41{
42 EVERGREEN_CRTC0_REGISTER_OFFSET,
43 EVERGREEN_CRTC1_REGISTER_OFFSET,
44 EVERGREEN_CRTC2_REGISTER_OFFSET,
45 EVERGREEN_CRTC3_REGISTER_OFFSET,
46 EVERGREEN_CRTC4_REGISTER_OFFSET,
47 EVERGREEN_CRTC5_REGISTER_OFFSET
48};
49
Alex Deucherbcc1c2a2010-01-12 17:54:34 -050050static void evergreen_gpu_init(struct radeon_device *rdev);
51void evergreen_fini(struct radeon_device *rdev);
Ilija Hadzicb07759b2011-09-20 10:22:58 -040052void evergreen_pcie_gen2_enable(struct radeon_device *rdev);
Alex Deucher1b370782011-11-17 20:13:28 -050053extern void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
54 int ring, u32 cp_int_cntl);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -050055
Alex Deucherd4788db2013-02-28 14:40:09 -050056static const u32 evergreen_golden_registers[] =
57{
58 0x3f90, 0xffff0000, 0xff000000,
59 0x9148, 0xffff0000, 0xff000000,
60 0x3f94, 0xffff0000, 0xff000000,
61 0x914c, 0xffff0000, 0xff000000,
62 0x9b7c, 0xffffffff, 0x00000000,
63 0x8a14, 0xffffffff, 0x00000007,
64 0x8b10, 0xffffffff, 0x00000000,
65 0x960c, 0xffffffff, 0x54763210,
66 0x88c4, 0xffffffff, 0x000000c2,
67 0x88d4, 0xffffffff, 0x00000010,
68 0x8974, 0xffffffff, 0x00000000,
69 0xc78, 0x00000080, 0x00000080,
70 0x5eb4, 0xffffffff, 0x00000002,
71 0x5e78, 0xffffffff, 0x001000f0,
72 0x6104, 0x01000300, 0x00000000,
73 0x5bc0, 0x00300000, 0x00000000,
74 0x7030, 0xffffffff, 0x00000011,
75 0x7c30, 0xffffffff, 0x00000011,
76 0x10830, 0xffffffff, 0x00000011,
77 0x11430, 0xffffffff, 0x00000011,
78 0x12030, 0xffffffff, 0x00000011,
79 0x12c30, 0xffffffff, 0x00000011,
80 0xd02c, 0xffffffff, 0x08421000,
81 0x240c, 0xffffffff, 0x00000380,
82 0x8b24, 0xffffffff, 0x00ff0fff,
83 0x28a4c, 0x06000000, 0x06000000,
84 0x10c, 0x00000001, 0x00000001,
85 0x8d00, 0xffffffff, 0x100e4848,
86 0x8d04, 0xffffffff, 0x00164745,
87 0x8c00, 0xffffffff, 0xe4000003,
88 0x8c04, 0xffffffff, 0x40600060,
89 0x8c08, 0xffffffff, 0x001c001c,
90 0x8cf0, 0xffffffff, 0x08e00620,
91 0x8c20, 0xffffffff, 0x00800080,
92 0x8c24, 0xffffffff, 0x00800080,
93 0x8c18, 0xffffffff, 0x20202078,
94 0x8c1c, 0xffffffff, 0x00001010,
95 0x28350, 0xffffffff, 0x00000000,
96 0xa008, 0xffffffff, 0x00010000,
97 0x5cc, 0xffffffff, 0x00000001,
98 0x9508, 0xffffffff, 0x00000002,
99 0x913c, 0x0000000f, 0x0000000a
100};
101
102static const u32 evergreen_golden_registers2[] =
103{
104 0x2f4c, 0xffffffff, 0x00000000,
105 0x54f4, 0xffffffff, 0x00000000,
106 0x54f0, 0xffffffff, 0x00000000,
107 0x5498, 0xffffffff, 0x00000000,
108 0x549c, 0xffffffff, 0x00000000,
109 0x5494, 0xffffffff, 0x00000000,
110 0x53cc, 0xffffffff, 0x00000000,
111 0x53c8, 0xffffffff, 0x00000000,
112 0x53c4, 0xffffffff, 0x00000000,
113 0x53c0, 0xffffffff, 0x00000000,
114 0x53bc, 0xffffffff, 0x00000000,
115 0x53b8, 0xffffffff, 0x00000000,
116 0x53b4, 0xffffffff, 0x00000000,
117 0x53b0, 0xffffffff, 0x00000000
118};
119
120static const u32 cypress_mgcg_init[] =
121{
122 0x802c, 0xffffffff, 0xc0000000,
123 0x5448, 0xffffffff, 0x00000100,
124 0x55e4, 0xffffffff, 0x00000100,
125 0x160c, 0xffffffff, 0x00000100,
126 0x5644, 0xffffffff, 0x00000100,
127 0xc164, 0xffffffff, 0x00000100,
128 0x8a18, 0xffffffff, 0x00000100,
129 0x897c, 0xffffffff, 0x06000100,
130 0x8b28, 0xffffffff, 0x00000100,
131 0x9144, 0xffffffff, 0x00000100,
132 0x9a60, 0xffffffff, 0x00000100,
133 0x9868, 0xffffffff, 0x00000100,
134 0x8d58, 0xffffffff, 0x00000100,
135 0x9510, 0xffffffff, 0x00000100,
136 0x949c, 0xffffffff, 0x00000100,
137 0x9654, 0xffffffff, 0x00000100,
138 0x9030, 0xffffffff, 0x00000100,
139 0x9034, 0xffffffff, 0x00000100,
140 0x9038, 0xffffffff, 0x00000100,
141 0x903c, 0xffffffff, 0x00000100,
142 0x9040, 0xffffffff, 0x00000100,
143 0xa200, 0xffffffff, 0x00000100,
144 0xa204, 0xffffffff, 0x00000100,
145 0xa208, 0xffffffff, 0x00000100,
146 0xa20c, 0xffffffff, 0x00000100,
147 0x971c, 0xffffffff, 0x00000100,
148 0x977c, 0xffffffff, 0x00000100,
149 0x3f80, 0xffffffff, 0x00000100,
150 0xa210, 0xffffffff, 0x00000100,
151 0xa214, 0xffffffff, 0x00000100,
152 0x4d8, 0xffffffff, 0x00000100,
153 0x9784, 0xffffffff, 0x00000100,
154 0x9698, 0xffffffff, 0x00000100,
155 0x4d4, 0xffffffff, 0x00000200,
156 0x30cc, 0xffffffff, 0x00000100,
157 0xd0c0, 0xffffffff, 0xff000100,
158 0x802c, 0xffffffff, 0x40000000,
159 0x915c, 0xffffffff, 0x00010000,
160 0x9160, 0xffffffff, 0x00030002,
161 0x9178, 0xffffffff, 0x00070000,
162 0x917c, 0xffffffff, 0x00030002,
163 0x9180, 0xffffffff, 0x00050004,
164 0x918c, 0xffffffff, 0x00010006,
165 0x9190, 0xffffffff, 0x00090008,
166 0x9194, 0xffffffff, 0x00070000,
167 0x9198, 0xffffffff, 0x00030002,
168 0x919c, 0xffffffff, 0x00050004,
169 0x91a8, 0xffffffff, 0x00010006,
170 0x91ac, 0xffffffff, 0x00090008,
171 0x91b0, 0xffffffff, 0x00070000,
172 0x91b4, 0xffffffff, 0x00030002,
173 0x91b8, 0xffffffff, 0x00050004,
174 0x91c4, 0xffffffff, 0x00010006,
175 0x91c8, 0xffffffff, 0x00090008,
176 0x91cc, 0xffffffff, 0x00070000,
177 0x91d0, 0xffffffff, 0x00030002,
178 0x91d4, 0xffffffff, 0x00050004,
179 0x91e0, 0xffffffff, 0x00010006,
180 0x91e4, 0xffffffff, 0x00090008,
181 0x91e8, 0xffffffff, 0x00000000,
182 0x91ec, 0xffffffff, 0x00070000,
183 0x91f0, 0xffffffff, 0x00030002,
184 0x91f4, 0xffffffff, 0x00050004,
185 0x9200, 0xffffffff, 0x00010006,
186 0x9204, 0xffffffff, 0x00090008,
187 0x9208, 0xffffffff, 0x00070000,
188 0x920c, 0xffffffff, 0x00030002,
189 0x9210, 0xffffffff, 0x00050004,
190 0x921c, 0xffffffff, 0x00010006,
191 0x9220, 0xffffffff, 0x00090008,
192 0x9224, 0xffffffff, 0x00070000,
193 0x9228, 0xffffffff, 0x00030002,
194 0x922c, 0xffffffff, 0x00050004,
195 0x9238, 0xffffffff, 0x00010006,
196 0x923c, 0xffffffff, 0x00090008,
197 0x9240, 0xffffffff, 0x00070000,
198 0x9244, 0xffffffff, 0x00030002,
199 0x9248, 0xffffffff, 0x00050004,
200 0x9254, 0xffffffff, 0x00010006,
201 0x9258, 0xffffffff, 0x00090008,
202 0x925c, 0xffffffff, 0x00070000,
203 0x9260, 0xffffffff, 0x00030002,
204 0x9264, 0xffffffff, 0x00050004,
205 0x9270, 0xffffffff, 0x00010006,
206 0x9274, 0xffffffff, 0x00090008,
207 0x9278, 0xffffffff, 0x00070000,
208 0x927c, 0xffffffff, 0x00030002,
209 0x9280, 0xffffffff, 0x00050004,
210 0x928c, 0xffffffff, 0x00010006,
211 0x9290, 0xffffffff, 0x00090008,
212 0x9294, 0xffffffff, 0x00000000,
213 0x929c, 0xffffffff, 0x00000001,
214 0x802c, 0xffffffff, 0x40010000,
215 0x915c, 0xffffffff, 0x00010000,
216 0x9160, 0xffffffff, 0x00030002,
217 0x9178, 0xffffffff, 0x00070000,
218 0x917c, 0xffffffff, 0x00030002,
219 0x9180, 0xffffffff, 0x00050004,
220 0x918c, 0xffffffff, 0x00010006,
221 0x9190, 0xffffffff, 0x00090008,
222 0x9194, 0xffffffff, 0x00070000,
223 0x9198, 0xffffffff, 0x00030002,
224 0x919c, 0xffffffff, 0x00050004,
225 0x91a8, 0xffffffff, 0x00010006,
226 0x91ac, 0xffffffff, 0x00090008,
227 0x91b0, 0xffffffff, 0x00070000,
228 0x91b4, 0xffffffff, 0x00030002,
229 0x91b8, 0xffffffff, 0x00050004,
230 0x91c4, 0xffffffff, 0x00010006,
231 0x91c8, 0xffffffff, 0x00090008,
232 0x91cc, 0xffffffff, 0x00070000,
233 0x91d0, 0xffffffff, 0x00030002,
234 0x91d4, 0xffffffff, 0x00050004,
235 0x91e0, 0xffffffff, 0x00010006,
236 0x91e4, 0xffffffff, 0x00090008,
237 0x91e8, 0xffffffff, 0x00000000,
238 0x91ec, 0xffffffff, 0x00070000,
239 0x91f0, 0xffffffff, 0x00030002,
240 0x91f4, 0xffffffff, 0x00050004,
241 0x9200, 0xffffffff, 0x00010006,
242 0x9204, 0xffffffff, 0x00090008,
243 0x9208, 0xffffffff, 0x00070000,
244 0x920c, 0xffffffff, 0x00030002,
245 0x9210, 0xffffffff, 0x00050004,
246 0x921c, 0xffffffff, 0x00010006,
247 0x9220, 0xffffffff, 0x00090008,
248 0x9224, 0xffffffff, 0x00070000,
249 0x9228, 0xffffffff, 0x00030002,
250 0x922c, 0xffffffff, 0x00050004,
251 0x9238, 0xffffffff, 0x00010006,
252 0x923c, 0xffffffff, 0x00090008,
253 0x9240, 0xffffffff, 0x00070000,
254 0x9244, 0xffffffff, 0x00030002,
255 0x9248, 0xffffffff, 0x00050004,
256 0x9254, 0xffffffff, 0x00010006,
257 0x9258, 0xffffffff, 0x00090008,
258 0x925c, 0xffffffff, 0x00070000,
259 0x9260, 0xffffffff, 0x00030002,
260 0x9264, 0xffffffff, 0x00050004,
261 0x9270, 0xffffffff, 0x00010006,
262 0x9274, 0xffffffff, 0x00090008,
263 0x9278, 0xffffffff, 0x00070000,
264 0x927c, 0xffffffff, 0x00030002,
265 0x9280, 0xffffffff, 0x00050004,
266 0x928c, 0xffffffff, 0x00010006,
267 0x9290, 0xffffffff, 0x00090008,
268 0x9294, 0xffffffff, 0x00000000,
269 0x929c, 0xffffffff, 0x00000001,
270 0x802c, 0xffffffff, 0xc0000000
271};
272
273static const u32 redwood_mgcg_init[] =
274{
275 0x802c, 0xffffffff, 0xc0000000,
276 0x5448, 0xffffffff, 0x00000100,
277 0x55e4, 0xffffffff, 0x00000100,
278 0x160c, 0xffffffff, 0x00000100,
279 0x5644, 0xffffffff, 0x00000100,
280 0xc164, 0xffffffff, 0x00000100,
281 0x8a18, 0xffffffff, 0x00000100,
282 0x897c, 0xffffffff, 0x06000100,
283 0x8b28, 0xffffffff, 0x00000100,
284 0x9144, 0xffffffff, 0x00000100,
285 0x9a60, 0xffffffff, 0x00000100,
286 0x9868, 0xffffffff, 0x00000100,
287 0x8d58, 0xffffffff, 0x00000100,
288 0x9510, 0xffffffff, 0x00000100,
289 0x949c, 0xffffffff, 0x00000100,
290 0x9654, 0xffffffff, 0x00000100,
291 0x9030, 0xffffffff, 0x00000100,
292 0x9034, 0xffffffff, 0x00000100,
293 0x9038, 0xffffffff, 0x00000100,
294 0x903c, 0xffffffff, 0x00000100,
295 0x9040, 0xffffffff, 0x00000100,
296 0xa200, 0xffffffff, 0x00000100,
297 0xa204, 0xffffffff, 0x00000100,
298 0xa208, 0xffffffff, 0x00000100,
299 0xa20c, 0xffffffff, 0x00000100,
300 0x971c, 0xffffffff, 0x00000100,
301 0x977c, 0xffffffff, 0x00000100,
302 0x3f80, 0xffffffff, 0x00000100,
303 0xa210, 0xffffffff, 0x00000100,
304 0xa214, 0xffffffff, 0x00000100,
305 0x4d8, 0xffffffff, 0x00000100,
306 0x9784, 0xffffffff, 0x00000100,
307 0x9698, 0xffffffff, 0x00000100,
308 0x4d4, 0xffffffff, 0x00000200,
309 0x30cc, 0xffffffff, 0x00000100,
310 0xd0c0, 0xffffffff, 0xff000100,
311 0x802c, 0xffffffff, 0x40000000,
312 0x915c, 0xffffffff, 0x00010000,
313 0x9160, 0xffffffff, 0x00030002,
314 0x9178, 0xffffffff, 0x00070000,
315 0x917c, 0xffffffff, 0x00030002,
316 0x9180, 0xffffffff, 0x00050004,
317 0x918c, 0xffffffff, 0x00010006,
318 0x9190, 0xffffffff, 0x00090008,
319 0x9194, 0xffffffff, 0x00070000,
320 0x9198, 0xffffffff, 0x00030002,
321 0x919c, 0xffffffff, 0x00050004,
322 0x91a8, 0xffffffff, 0x00010006,
323 0x91ac, 0xffffffff, 0x00090008,
324 0x91b0, 0xffffffff, 0x00070000,
325 0x91b4, 0xffffffff, 0x00030002,
326 0x91b8, 0xffffffff, 0x00050004,
327 0x91c4, 0xffffffff, 0x00010006,
328 0x91c8, 0xffffffff, 0x00090008,
329 0x91cc, 0xffffffff, 0x00070000,
330 0x91d0, 0xffffffff, 0x00030002,
331 0x91d4, 0xffffffff, 0x00050004,
332 0x91e0, 0xffffffff, 0x00010006,
333 0x91e4, 0xffffffff, 0x00090008,
334 0x91e8, 0xffffffff, 0x00000000,
335 0x91ec, 0xffffffff, 0x00070000,
336 0x91f0, 0xffffffff, 0x00030002,
337 0x91f4, 0xffffffff, 0x00050004,
338 0x9200, 0xffffffff, 0x00010006,
339 0x9204, 0xffffffff, 0x00090008,
340 0x9294, 0xffffffff, 0x00000000,
341 0x929c, 0xffffffff, 0x00000001,
342 0x802c, 0xffffffff, 0xc0000000
343};
344
345static const u32 cedar_golden_registers[] =
346{
347 0x3f90, 0xffff0000, 0xff000000,
348 0x9148, 0xffff0000, 0xff000000,
349 0x3f94, 0xffff0000, 0xff000000,
350 0x914c, 0xffff0000, 0xff000000,
351 0x9b7c, 0xffffffff, 0x00000000,
352 0x8a14, 0xffffffff, 0x00000007,
353 0x8b10, 0xffffffff, 0x00000000,
354 0x960c, 0xffffffff, 0x54763210,
355 0x88c4, 0xffffffff, 0x000000c2,
356 0x88d4, 0xffffffff, 0x00000000,
357 0x8974, 0xffffffff, 0x00000000,
358 0xc78, 0x00000080, 0x00000080,
359 0x5eb4, 0xffffffff, 0x00000002,
360 0x5e78, 0xffffffff, 0x001000f0,
361 0x6104, 0x01000300, 0x00000000,
362 0x5bc0, 0x00300000, 0x00000000,
363 0x7030, 0xffffffff, 0x00000011,
364 0x7c30, 0xffffffff, 0x00000011,
365 0x10830, 0xffffffff, 0x00000011,
366 0x11430, 0xffffffff, 0x00000011,
367 0xd02c, 0xffffffff, 0x08421000,
368 0x240c, 0xffffffff, 0x00000380,
369 0x8b24, 0xffffffff, 0x00ff0fff,
370 0x28a4c, 0x06000000, 0x06000000,
371 0x10c, 0x00000001, 0x00000001,
372 0x8d00, 0xffffffff, 0x100e4848,
373 0x8d04, 0xffffffff, 0x00164745,
374 0x8c00, 0xffffffff, 0xe4000003,
375 0x8c04, 0xffffffff, 0x40600060,
376 0x8c08, 0xffffffff, 0x001c001c,
377 0x8cf0, 0xffffffff, 0x08e00410,
378 0x8c20, 0xffffffff, 0x00800080,
379 0x8c24, 0xffffffff, 0x00800080,
380 0x8c18, 0xffffffff, 0x20202078,
381 0x8c1c, 0xffffffff, 0x00001010,
382 0x28350, 0xffffffff, 0x00000000,
383 0xa008, 0xffffffff, 0x00010000,
384 0x5cc, 0xffffffff, 0x00000001,
385 0x9508, 0xffffffff, 0x00000002
386};
387
388static const u32 cedar_mgcg_init[] =
389{
390 0x802c, 0xffffffff, 0xc0000000,
391 0x5448, 0xffffffff, 0x00000100,
392 0x55e4, 0xffffffff, 0x00000100,
393 0x160c, 0xffffffff, 0x00000100,
394 0x5644, 0xffffffff, 0x00000100,
395 0xc164, 0xffffffff, 0x00000100,
396 0x8a18, 0xffffffff, 0x00000100,
397 0x897c, 0xffffffff, 0x06000100,
398 0x8b28, 0xffffffff, 0x00000100,
399 0x9144, 0xffffffff, 0x00000100,
400 0x9a60, 0xffffffff, 0x00000100,
401 0x9868, 0xffffffff, 0x00000100,
402 0x8d58, 0xffffffff, 0x00000100,
403 0x9510, 0xffffffff, 0x00000100,
404 0x949c, 0xffffffff, 0x00000100,
405 0x9654, 0xffffffff, 0x00000100,
406 0x9030, 0xffffffff, 0x00000100,
407 0x9034, 0xffffffff, 0x00000100,
408 0x9038, 0xffffffff, 0x00000100,
409 0x903c, 0xffffffff, 0x00000100,
410 0x9040, 0xffffffff, 0x00000100,
411 0xa200, 0xffffffff, 0x00000100,
412 0xa204, 0xffffffff, 0x00000100,
413 0xa208, 0xffffffff, 0x00000100,
414 0xa20c, 0xffffffff, 0x00000100,
415 0x971c, 0xffffffff, 0x00000100,
416 0x977c, 0xffffffff, 0x00000100,
417 0x3f80, 0xffffffff, 0x00000100,
418 0xa210, 0xffffffff, 0x00000100,
419 0xa214, 0xffffffff, 0x00000100,
420 0x4d8, 0xffffffff, 0x00000100,
421 0x9784, 0xffffffff, 0x00000100,
422 0x9698, 0xffffffff, 0x00000100,
423 0x4d4, 0xffffffff, 0x00000200,
424 0x30cc, 0xffffffff, 0x00000100,
425 0xd0c0, 0xffffffff, 0xff000100,
426 0x802c, 0xffffffff, 0x40000000,
427 0x915c, 0xffffffff, 0x00010000,
428 0x9178, 0xffffffff, 0x00050000,
429 0x917c, 0xffffffff, 0x00030002,
430 0x918c, 0xffffffff, 0x00010004,
431 0x9190, 0xffffffff, 0x00070006,
432 0x9194, 0xffffffff, 0x00050000,
433 0x9198, 0xffffffff, 0x00030002,
434 0x91a8, 0xffffffff, 0x00010004,
435 0x91ac, 0xffffffff, 0x00070006,
436 0x91e8, 0xffffffff, 0x00000000,
437 0x9294, 0xffffffff, 0x00000000,
438 0x929c, 0xffffffff, 0x00000001,
439 0x802c, 0xffffffff, 0xc0000000
440};
441
442static const u32 juniper_mgcg_init[] =
443{
444 0x802c, 0xffffffff, 0xc0000000,
445 0x5448, 0xffffffff, 0x00000100,
446 0x55e4, 0xffffffff, 0x00000100,
447 0x160c, 0xffffffff, 0x00000100,
448 0x5644, 0xffffffff, 0x00000100,
449 0xc164, 0xffffffff, 0x00000100,
450 0x8a18, 0xffffffff, 0x00000100,
451 0x897c, 0xffffffff, 0x06000100,
452 0x8b28, 0xffffffff, 0x00000100,
453 0x9144, 0xffffffff, 0x00000100,
454 0x9a60, 0xffffffff, 0x00000100,
455 0x9868, 0xffffffff, 0x00000100,
456 0x8d58, 0xffffffff, 0x00000100,
457 0x9510, 0xffffffff, 0x00000100,
458 0x949c, 0xffffffff, 0x00000100,
459 0x9654, 0xffffffff, 0x00000100,
460 0x9030, 0xffffffff, 0x00000100,
461 0x9034, 0xffffffff, 0x00000100,
462 0x9038, 0xffffffff, 0x00000100,
463 0x903c, 0xffffffff, 0x00000100,
464 0x9040, 0xffffffff, 0x00000100,
465 0xa200, 0xffffffff, 0x00000100,
466 0xa204, 0xffffffff, 0x00000100,
467 0xa208, 0xffffffff, 0x00000100,
468 0xa20c, 0xffffffff, 0x00000100,
469 0x971c, 0xffffffff, 0x00000100,
470 0xd0c0, 0xffffffff, 0xff000100,
471 0x802c, 0xffffffff, 0x40000000,
472 0x915c, 0xffffffff, 0x00010000,
473 0x9160, 0xffffffff, 0x00030002,
474 0x9178, 0xffffffff, 0x00070000,
475 0x917c, 0xffffffff, 0x00030002,
476 0x9180, 0xffffffff, 0x00050004,
477 0x918c, 0xffffffff, 0x00010006,
478 0x9190, 0xffffffff, 0x00090008,
479 0x9194, 0xffffffff, 0x00070000,
480 0x9198, 0xffffffff, 0x00030002,
481 0x919c, 0xffffffff, 0x00050004,
482 0x91a8, 0xffffffff, 0x00010006,
483 0x91ac, 0xffffffff, 0x00090008,
484 0x91b0, 0xffffffff, 0x00070000,
485 0x91b4, 0xffffffff, 0x00030002,
486 0x91b8, 0xffffffff, 0x00050004,
487 0x91c4, 0xffffffff, 0x00010006,
488 0x91c8, 0xffffffff, 0x00090008,
489 0x91cc, 0xffffffff, 0x00070000,
490 0x91d0, 0xffffffff, 0x00030002,
491 0x91d4, 0xffffffff, 0x00050004,
492 0x91e0, 0xffffffff, 0x00010006,
493 0x91e4, 0xffffffff, 0x00090008,
494 0x91e8, 0xffffffff, 0x00000000,
495 0x91ec, 0xffffffff, 0x00070000,
496 0x91f0, 0xffffffff, 0x00030002,
497 0x91f4, 0xffffffff, 0x00050004,
498 0x9200, 0xffffffff, 0x00010006,
499 0x9204, 0xffffffff, 0x00090008,
500 0x9208, 0xffffffff, 0x00070000,
501 0x920c, 0xffffffff, 0x00030002,
502 0x9210, 0xffffffff, 0x00050004,
503 0x921c, 0xffffffff, 0x00010006,
504 0x9220, 0xffffffff, 0x00090008,
505 0x9224, 0xffffffff, 0x00070000,
506 0x9228, 0xffffffff, 0x00030002,
507 0x922c, 0xffffffff, 0x00050004,
508 0x9238, 0xffffffff, 0x00010006,
509 0x923c, 0xffffffff, 0x00090008,
510 0x9240, 0xffffffff, 0x00070000,
511 0x9244, 0xffffffff, 0x00030002,
512 0x9248, 0xffffffff, 0x00050004,
513 0x9254, 0xffffffff, 0x00010006,
514 0x9258, 0xffffffff, 0x00090008,
515 0x925c, 0xffffffff, 0x00070000,
516 0x9260, 0xffffffff, 0x00030002,
517 0x9264, 0xffffffff, 0x00050004,
518 0x9270, 0xffffffff, 0x00010006,
519 0x9274, 0xffffffff, 0x00090008,
520 0x9278, 0xffffffff, 0x00070000,
521 0x927c, 0xffffffff, 0x00030002,
522 0x9280, 0xffffffff, 0x00050004,
523 0x928c, 0xffffffff, 0x00010006,
524 0x9290, 0xffffffff, 0x00090008,
525 0x9294, 0xffffffff, 0x00000000,
526 0x929c, 0xffffffff, 0x00000001,
527 0x802c, 0xffffffff, 0xc0000000,
528 0x977c, 0xffffffff, 0x00000100,
529 0x3f80, 0xffffffff, 0x00000100,
530 0xa210, 0xffffffff, 0x00000100,
531 0xa214, 0xffffffff, 0x00000100,
532 0x4d8, 0xffffffff, 0x00000100,
533 0x9784, 0xffffffff, 0x00000100,
534 0x9698, 0xffffffff, 0x00000100,
535 0x4d4, 0xffffffff, 0x00000200,
536 0x30cc, 0xffffffff, 0x00000100,
537 0x802c, 0xffffffff, 0xc0000000
538};
539
540static const u32 supersumo_golden_registers[] =
541{
542 0x5eb4, 0xffffffff, 0x00000002,
543 0x5cc, 0xffffffff, 0x00000001,
544 0x7030, 0xffffffff, 0x00000011,
545 0x7c30, 0xffffffff, 0x00000011,
546 0x6104, 0x01000300, 0x00000000,
547 0x5bc0, 0x00300000, 0x00000000,
548 0x8c04, 0xffffffff, 0x40600060,
549 0x8c08, 0xffffffff, 0x001c001c,
550 0x8c20, 0xffffffff, 0x00800080,
551 0x8c24, 0xffffffff, 0x00800080,
552 0x8c18, 0xffffffff, 0x20202078,
553 0x8c1c, 0xffffffff, 0x00001010,
554 0x918c, 0xffffffff, 0x00010006,
555 0x91a8, 0xffffffff, 0x00010006,
556 0x91c4, 0xffffffff, 0x00010006,
557 0x91e0, 0xffffffff, 0x00010006,
558 0x9200, 0xffffffff, 0x00010006,
559 0x9150, 0xffffffff, 0x6e944040,
560 0x917c, 0xffffffff, 0x00030002,
561 0x9180, 0xffffffff, 0x00050004,
562 0x9198, 0xffffffff, 0x00030002,
563 0x919c, 0xffffffff, 0x00050004,
564 0x91b4, 0xffffffff, 0x00030002,
565 0x91b8, 0xffffffff, 0x00050004,
566 0x91d0, 0xffffffff, 0x00030002,
567 0x91d4, 0xffffffff, 0x00050004,
568 0x91f0, 0xffffffff, 0x00030002,
569 0x91f4, 0xffffffff, 0x00050004,
570 0x915c, 0xffffffff, 0x00010000,
571 0x9160, 0xffffffff, 0x00030002,
572 0x3f90, 0xffff0000, 0xff000000,
573 0x9178, 0xffffffff, 0x00070000,
574 0x9194, 0xffffffff, 0x00070000,
575 0x91b0, 0xffffffff, 0x00070000,
576 0x91cc, 0xffffffff, 0x00070000,
577 0x91ec, 0xffffffff, 0x00070000,
578 0x9148, 0xffff0000, 0xff000000,
579 0x9190, 0xffffffff, 0x00090008,
580 0x91ac, 0xffffffff, 0x00090008,
581 0x91c8, 0xffffffff, 0x00090008,
582 0x91e4, 0xffffffff, 0x00090008,
583 0x9204, 0xffffffff, 0x00090008,
584 0x3f94, 0xffff0000, 0xff000000,
585 0x914c, 0xffff0000, 0xff000000,
586 0x929c, 0xffffffff, 0x00000001,
587 0x8a18, 0xffffffff, 0x00000100,
588 0x8b28, 0xffffffff, 0x00000100,
589 0x9144, 0xffffffff, 0x00000100,
590 0x5644, 0xffffffff, 0x00000100,
591 0x9b7c, 0xffffffff, 0x00000000,
592 0x8030, 0xffffffff, 0x0000100a,
593 0x8a14, 0xffffffff, 0x00000007,
594 0x8b24, 0xffffffff, 0x00ff0fff,
595 0x8b10, 0xffffffff, 0x00000000,
596 0x28a4c, 0x06000000, 0x06000000,
597 0x4d8, 0xffffffff, 0x00000100,
598 0x913c, 0xffff000f, 0x0100000a,
599 0x960c, 0xffffffff, 0x54763210,
600 0x88c4, 0xffffffff, 0x000000c2,
601 0x88d4, 0xffffffff, 0x00000010,
602 0x8974, 0xffffffff, 0x00000000,
603 0xc78, 0x00000080, 0x00000080,
604 0x5e78, 0xffffffff, 0x001000f0,
605 0xd02c, 0xffffffff, 0x08421000,
606 0xa008, 0xffffffff, 0x00010000,
607 0x8d00, 0xffffffff, 0x100e4848,
608 0x8d04, 0xffffffff, 0x00164745,
609 0x8c00, 0xffffffff, 0xe4000003,
610 0x8cf0, 0x1fffffff, 0x08e00620,
611 0x28350, 0xffffffff, 0x00000000,
612 0x9508, 0xffffffff, 0x00000002
613};
614
615static const u32 sumo_golden_registers[] =
616{
617 0x900c, 0x00ffffff, 0x0017071f,
618 0x8c18, 0xffffffff, 0x10101060,
619 0x8c1c, 0xffffffff, 0x00001010,
620 0x8c30, 0x0000000f, 0x00000005,
621 0x9688, 0x0000000f, 0x00000007
622};
623
624static const u32 wrestler_golden_registers[] =
625{
626 0x5eb4, 0xffffffff, 0x00000002,
627 0x5cc, 0xffffffff, 0x00000001,
628 0x7030, 0xffffffff, 0x00000011,
629 0x7c30, 0xffffffff, 0x00000011,
630 0x6104, 0x01000300, 0x00000000,
631 0x5bc0, 0x00300000, 0x00000000,
632 0x918c, 0xffffffff, 0x00010006,
633 0x91a8, 0xffffffff, 0x00010006,
634 0x9150, 0xffffffff, 0x6e944040,
635 0x917c, 0xffffffff, 0x00030002,
636 0x9198, 0xffffffff, 0x00030002,
637 0x915c, 0xffffffff, 0x00010000,
638 0x3f90, 0xffff0000, 0xff000000,
639 0x9178, 0xffffffff, 0x00070000,
640 0x9194, 0xffffffff, 0x00070000,
641 0x9148, 0xffff0000, 0xff000000,
642 0x9190, 0xffffffff, 0x00090008,
643 0x91ac, 0xffffffff, 0x00090008,
644 0x3f94, 0xffff0000, 0xff000000,
645 0x914c, 0xffff0000, 0xff000000,
646 0x929c, 0xffffffff, 0x00000001,
647 0x8a18, 0xffffffff, 0x00000100,
648 0x8b28, 0xffffffff, 0x00000100,
649 0x9144, 0xffffffff, 0x00000100,
650 0x9b7c, 0xffffffff, 0x00000000,
651 0x8030, 0xffffffff, 0x0000100a,
652 0x8a14, 0xffffffff, 0x00000001,
653 0x8b24, 0xffffffff, 0x00ff0fff,
654 0x8b10, 0xffffffff, 0x00000000,
655 0x28a4c, 0x06000000, 0x06000000,
656 0x4d8, 0xffffffff, 0x00000100,
657 0x913c, 0xffff000f, 0x0100000a,
658 0x960c, 0xffffffff, 0x54763210,
659 0x88c4, 0xffffffff, 0x000000c2,
660 0x88d4, 0xffffffff, 0x00000010,
661 0x8974, 0xffffffff, 0x00000000,
662 0xc78, 0x00000080, 0x00000080,
663 0x5e78, 0xffffffff, 0x001000f0,
664 0xd02c, 0xffffffff, 0x08421000,
665 0xa008, 0xffffffff, 0x00010000,
666 0x8d00, 0xffffffff, 0x100e4848,
667 0x8d04, 0xffffffff, 0x00164745,
668 0x8c00, 0xffffffff, 0xe4000003,
669 0x8cf0, 0x1fffffff, 0x08e00410,
670 0x28350, 0xffffffff, 0x00000000,
671 0x9508, 0xffffffff, 0x00000002,
672 0x900c, 0xffffffff, 0x0017071f,
673 0x8c18, 0xffffffff, 0x10101060,
674 0x8c1c, 0xffffffff, 0x00001010
675};
676
677static const u32 barts_golden_registers[] =
678{
679 0x5eb4, 0xffffffff, 0x00000002,
680 0x5e78, 0x8f311ff1, 0x001000f0,
681 0x3f90, 0xffff0000, 0xff000000,
682 0x9148, 0xffff0000, 0xff000000,
683 0x3f94, 0xffff0000, 0xff000000,
684 0x914c, 0xffff0000, 0xff000000,
685 0xc78, 0x00000080, 0x00000080,
686 0xbd4, 0x70073777, 0x00010001,
687 0xd02c, 0xbfffff1f, 0x08421000,
688 0xd0b8, 0x03773777, 0x02011003,
689 0x5bc0, 0x00200000, 0x50100000,
690 0x98f8, 0x33773777, 0x02011003,
691 0x98fc, 0xffffffff, 0x76543210,
692 0x7030, 0x31000311, 0x00000011,
693 0x2f48, 0x00000007, 0x02011003,
694 0x6b28, 0x00000010, 0x00000012,
695 0x7728, 0x00000010, 0x00000012,
696 0x10328, 0x00000010, 0x00000012,
697 0x10f28, 0x00000010, 0x00000012,
698 0x11b28, 0x00000010, 0x00000012,
699 0x12728, 0x00000010, 0x00000012,
700 0x240c, 0x000007ff, 0x00000380,
701 0x8a14, 0xf000001f, 0x00000007,
702 0x8b24, 0x3fff3fff, 0x00ff0fff,
703 0x8b10, 0x0000ff0f, 0x00000000,
704 0x28a4c, 0x07ffffff, 0x06000000,
705 0x10c, 0x00000001, 0x00010003,
706 0xa02c, 0xffffffff, 0x0000009b,
707 0x913c, 0x0000000f, 0x0100000a,
708 0x8d00, 0xffff7f7f, 0x100e4848,
709 0x8d04, 0x00ffffff, 0x00164745,
710 0x8c00, 0xfffc0003, 0xe4000003,
711 0x8c04, 0xf8ff00ff, 0x40600060,
712 0x8c08, 0x00ff00ff, 0x001c001c,
713 0x8cf0, 0x1fff1fff, 0x08e00620,
714 0x8c20, 0x0fff0fff, 0x00800080,
715 0x8c24, 0x0fff0fff, 0x00800080,
716 0x8c18, 0xffffffff, 0x20202078,
717 0x8c1c, 0x0000ffff, 0x00001010,
718 0x28350, 0x00000f01, 0x00000000,
719 0x9508, 0x3700001f, 0x00000002,
720 0x960c, 0xffffffff, 0x54763210,
721 0x88c4, 0x001f3ae3, 0x000000c2,
722 0x88d4, 0x0000001f, 0x00000010,
723 0x8974, 0xffffffff, 0x00000000
724};
725
726static const u32 turks_golden_registers[] =
727{
728 0x5eb4, 0xffffffff, 0x00000002,
729 0x5e78, 0x8f311ff1, 0x001000f0,
730 0x8c8, 0x00003000, 0x00001070,
731 0x8cc, 0x000fffff, 0x00040035,
732 0x3f90, 0xffff0000, 0xfff00000,
733 0x9148, 0xffff0000, 0xfff00000,
734 0x3f94, 0xffff0000, 0xfff00000,
735 0x914c, 0xffff0000, 0xfff00000,
736 0xc78, 0x00000080, 0x00000080,
737 0xbd4, 0x00073007, 0x00010002,
738 0xd02c, 0xbfffff1f, 0x08421000,
739 0xd0b8, 0x03773777, 0x02010002,
740 0x5bc0, 0x00200000, 0x50100000,
741 0x98f8, 0x33773777, 0x00010002,
742 0x98fc, 0xffffffff, 0x33221100,
743 0x7030, 0x31000311, 0x00000011,
744 0x2f48, 0x33773777, 0x00010002,
745 0x6b28, 0x00000010, 0x00000012,
746 0x7728, 0x00000010, 0x00000012,
747 0x10328, 0x00000010, 0x00000012,
748 0x10f28, 0x00000010, 0x00000012,
749 0x11b28, 0x00000010, 0x00000012,
750 0x12728, 0x00000010, 0x00000012,
751 0x240c, 0x000007ff, 0x00000380,
752 0x8a14, 0xf000001f, 0x00000007,
753 0x8b24, 0x3fff3fff, 0x00ff0fff,
754 0x8b10, 0x0000ff0f, 0x00000000,
755 0x28a4c, 0x07ffffff, 0x06000000,
756 0x10c, 0x00000001, 0x00010003,
757 0xa02c, 0xffffffff, 0x0000009b,
758 0x913c, 0x0000000f, 0x0100000a,
759 0x8d00, 0xffff7f7f, 0x100e4848,
760 0x8d04, 0x00ffffff, 0x00164745,
761 0x8c00, 0xfffc0003, 0xe4000003,
762 0x8c04, 0xf8ff00ff, 0x40600060,
763 0x8c08, 0x00ff00ff, 0x001c001c,
764 0x8cf0, 0x1fff1fff, 0x08e00410,
765 0x8c20, 0x0fff0fff, 0x00800080,
766 0x8c24, 0x0fff0fff, 0x00800080,
767 0x8c18, 0xffffffff, 0x20202078,
768 0x8c1c, 0x0000ffff, 0x00001010,
769 0x28350, 0x00000f01, 0x00000000,
770 0x9508, 0x3700001f, 0x00000002,
771 0x960c, 0xffffffff, 0x54763210,
772 0x88c4, 0x001f3ae3, 0x000000c2,
773 0x88d4, 0x0000001f, 0x00000010,
774 0x8974, 0xffffffff, 0x00000000
775};
776
777static const u32 caicos_golden_registers[] =
778{
779 0x5eb4, 0xffffffff, 0x00000002,
780 0x5e78, 0x8f311ff1, 0x001000f0,
781 0x8c8, 0x00003420, 0x00001450,
782 0x8cc, 0x000fffff, 0x00040035,
783 0x3f90, 0xffff0000, 0xfffc0000,
784 0x9148, 0xffff0000, 0xfffc0000,
785 0x3f94, 0xffff0000, 0xfffc0000,
786 0x914c, 0xffff0000, 0xfffc0000,
787 0xc78, 0x00000080, 0x00000080,
788 0xbd4, 0x00073007, 0x00010001,
789 0xd02c, 0xbfffff1f, 0x08421000,
790 0xd0b8, 0x03773777, 0x02010001,
791 0x5bc0, 0x00200000, 0x50100000,
792 0x98f8, 0x33773777, 0x02010001,
793 0x98fc, 0xffffffff, 0x33221100,
794 0x7030, 0x31000311, 0x00000011,
795 0x2f48, 0x33773777, 0x02010001,
796 0x6b28, 0x00000010, 0x00000012,
797 0x7728, 0x00000010, 0x00000012,
798 0x10328, 0x00000010, 0x00000012,
799 0x10f28, 0x00000010, 0x00000012,
800 0x11b28, 0x00000010, 0x00000012,
801 0x12728, 0x00000010, 0x00000012,
802 0x240c, 0x000007ff, 0x00000380,
803 0x8a14, 0xf000001f, 0x00000001,
804 0x8b24, 0x3fff3fff, 0x00ff0fff,
805 0x8b10, 0x0000ff0f, 0x00000000,
806 0x28a4c, 0x07ffffff, 0x06000000,
807 0x10c, 0x00000001, 0x00010003,
808 0xa02c, 0xffffffff, 0x0000009b,
809 0x913c, 0x0000000f, 0x0100000a,
810 0x8d00, 0xffff7f7f, 0x100e4848,
811 0x8d04, 0x00ffffff, 0x00164745,
812 0x8c00, 0xfffc0003, 0xe4000003,
813 0x8c04, 0xf8ff00ff, 0x40600060,
814 0x8c08, 0x00ff00ff, 0x001c001c,
815 0x8cf0, 0x1fff1fff, 0x08e00410,
816 0x8c20, 0x0fff0fff, 0x00800080,
817 0x8c24, 0x0fff0fff, 0x00800080,
818 0x8c18, 0xffffffff, 0x20202078,
819 0x8c1c, 0x0000ffff, 0x00001010,
820 0x28350, 0x00000f01, 0x00000000,
821 0x9508, 0x3700001f, 0x00000002,
822 0x960c, 0xffffffff, 0x54763210,
823 0x88c4, 0x001f3ae3, 0x000000c2,
824 0x88d4, 0x0000001f, 0x00000010,
825 0x8974, 0xffffffff, 0x00000000
826};
827
828static void evergreen_init_golden_registers(struct radeon_device *rdev)
829{
830 switch (rdev->family) {
831 case CHIP_CYPRESS:
832 case CHIP_HEMLOCK:
833 radeon_program_register_sequence(rdev,
834 evergreen_golden_registers,
835 (const u32)ARRAY_SIZE(evergreen_golden_registers));
836 radeon_program_register_sequence(rdev,
837 evergreen_golden_registers2,
838 (const u32)ARRAY_SIZE(evergreen_golden_registers2));
839 radeon_program_register_sequence(rdev,
840 cypress_mgcg_init,
841 (const u32)ARRAY_SIZE(cypress_mgcg_init));
842 break;
843 case CHIP_JUNIPER:
844 radeon_program_register_sequence(rdev,
845 evergreen_golden_registers,
846 (const u32)ARRAY_SIZE(evergreen_golden_registers));
847 radeon_program_register_sequence(rdev,
848 evergreen_golden_registers2,
849 (const u32)ARRAY_SIZE(evergreen_golden_registers2));
850 radeon_program_register_sequence(rdev,
851 juniper_mgcg_init,
852 (const u32)ARRAY_SIZE(juniper_mgcg_init));
853 break;
854 case CHIP_REDWOOD:
855 radeon_program_register_sequence(rdev,
856 evergreen_golden_registers,
857 (const u32)ARRAY_SIZE(evergreen_golden_registers));
858 radeon_program_register_sequence(rdev,
859 evergreen_golden_registers2,
860 (const u32)ARRAY_SIZE(evergreen_golden_registers2));
861 radeon_program_register_sequence(rdev,
862 redwood_mgcg_init,
863 (const u32)ARRAY_SIZE(redwood_mgcg_init));
864 break;
865 case CHIP_CEDAR:
866 radeon_program_register_sequence(rdev,
867 cedar_golden_registers,
868 (const u32)ARRAY_SIZE(cedar_golden_registers));
869 radeon_program_register_sequence(rdev,
870 evergreen_golden_registers2,
871 (const u32)ARRAY_SIZE(evergreen_golden_registers2));
872 radeon_program_register_sequence(rdev,
873 cedar_mgcg_init,
874 (const u32)ARRAY_SIZE(cedar_mgcg_init));
875 break;
876 case CHIP_PALM:
877 radeon_program_register_sequence(rdev,
878 wrestler_golden_registers,
879 (const u32)ARRAY_SIZE(wrestler_golden_registers));
880 break;
881 case CHIP_SUMO:
882 radeon_program_register_sequence(rdev,
883 supersumo_golden_registers,
884 (const u32)ARRAY_SIZE(supersumo_golden_registers));
885 break;
886 case CHIP_SUMO2:
887 radeon_program_register_sequence(rdev,
888 supersumo_golden_registers,
889 (const u32)ARRAY_SIZE(supersumo_golden_registers));
890 radeon_program_register_sequence(rdev,
891 sumo_golden_registers,
892 (const u32)ARRAY_SIZE(sumo_golden_registers));
893 break;
894 case CHIP_BARTS:
895 radeon_program_register_sequence(rdev,
896 barts_golden_registers,
897 (const u32)ARRAY_SIZE(barts_golden_registers));
898 break;
899 case CHIP_TURKS:
900 radeon_program_register_sequence(rdev,
901 turks_golden_registers,
902 (const u32)ARRAY_SIZE(turks_golden_registers));
903 break;
904 case CHIP_CAICOS:
905 radeon_program_register_sequence(rdev,
906 caicos_golden_registers,
907 (const u32)ARRAY_SIZE(caicos_golden_registers));
908 break;
909 default:
910 break;
911 }
912}
913
Jerome Glisse285484e2011-12-16 17:03:42 -0500914void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
915 unsigned *bankh, unsigned *mtaspect,
916 unsigned *tile_split)
917{
918 *bankw = (tiling_flags >> RADEON_TILING_EG_BANKW_SHIFT) & RADEON_TILING_EG_BANKW_MASK;
919 *bankh = (tiling_flags >> RADEON_TILING_EG_BANKH_SHIFT) & RADEON_TILING_EG_BANKH_MASK;
920 *mtaspect = (tiling_flags >> RADEON_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & RADEON_TILING_EG_MACRO_TILE_ASPECT_MASK;
921 *tile_split = (tiling_flags >> RADEON_TILING_EG_TILE_SPLIT_SHIFT) & RADEON_TILING_EG_TILE_SPLIT_MASK;
922 switch (*bankw) {
923 default:
924 case 1: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_1; break;
925 case 2: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_2; break;
926 case 4: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_4; break;
927 case 8: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_8; break;
928 }
929 switch (*bankh) {
930 default:
931 case 1: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_1; break;
932 case 2: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_2; break;
933 case 4: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_4; break;
934 case 8: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_8; break;
935 }
936 switch (*mtaspect) {
937 default:
938 case 1: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_1; break;
939 case 2: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_2; break;
940 case 4: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_4; break;
941 case 8: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_8; break;
942 }
943}
944
Alex Deucher23d33ba2013-04-08 12:41:32 +0200945static int sumo_set_uvd_clock(struct radeon_device *rdev, u32 clock,
946 u32 cntl_reg, u32 status_reg)
947{
948 int r, i;
949 struct atom_clock_dividers dividers;
950
951 r = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
952 clock, false, &dividers);
953 if (r)
954 return r;
955
956 WREG32_P(cntl_reg, dividers.post_div, ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK));
957
958 for (i = 0; i < 100; i++) {
959 if (RREG32(status_reg) & DCLK_STATUS)
960 break;
961 mdelay(10);
962 }
963 if (i == 100)
964 return -ETIMEDOUT;
965
966 return 0;
967}
968
969int sumo_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
970{
971 int r = 0;
972 u32 cg_scratch = RREG32(CG_SCRATCH1);
973
974 r = sumo_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
975 if (r)
976 goto done;
977 cg_scratch &= 0xffff0000;
978 cg_scratch |= vclk / 100; /* Mhz */
979
980 r = sumo_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
981 if (r)
982 goto done;
983 cg_scratch &= 0x0000ffff;
984 cg_scratch |= (dclk / 100) << 16; /* Mhz */
985
986done:
987 WREG32(CG_SCRATCH1, cg_scratch);
988
989 return r;
990}
991
Alex Deuchera8b49252013-04-08 12:41:33 +0200992static int evergreen_uvd_calc_post_div(unsigned target_freq,
993 unsigned vco_freq,
994 unsigned *div)
995{
996 /* target larger than vco frequency ? */
997 if (vco_freq < target_freq)
998 return -1; /* forget it */
999
1000 /* Fclk = Fvco / PDIV */
1001 *div = vco_freq / target_freq;
1002
1003 /* we alway need a frequency less than or equal the target */
1004 if ((vco_freq / *div) > target_freq)
1005 *div += 1;
1006
1007 /* dividers above 5 must be even */
1008 if (*div > 5 && *div % 2)
1009 *div += 1;
1010
1011 /* out of range ? */
1012 if (*div >= 128)
1013 return -1; /* forget it */
1014
1015 return vco_freq / *div;
1016}
1017
1018static int evergreen_uvd_send_upll_ctlreq(struct radeon_device *rdev)
1019{
1020 unsigned i;
1021
1022 /* assert UPLL_CTLREQ */
1023 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_CTLREQ_MASK, ~UPLL_CTLREQ_MASK);
1024
1025 /* wait for CTLACK and CTLACK2 to get asserted */
1026 for (i = 0; i < 100; ++i) {
1027 uint32_t mask = UPLL_CTLACK_MASK | UPLL_CTLACK2_MASK;
1028 if ((RREG32(CG_UPLL_FUNC_CNTL) & mask) == mask)
1029 break;
1030 mdelay(10);
1031 }
1032 if (i == 100)
1033 return -ETIMEDOUT;
1034
1035 /* deassert UPLL_CTLREQ */
1036 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_CTLREQ_MASK);
1037
1038 return 0;
1039}
1040
1041int evergreen_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
1042{
1043 /* start off with something large */
1044 int optimal_diff_score = 0x7FFFFFF;
1045 unsigned optimal_fb_div = 0, optimal_vclk_div = 0;
1046 unsigned optimal_dclk_div = 0, optimal_vco_freq = 0;
1047 unsigned vco_freq;
1048 int r;
1049
Christian König4ed10832013-04-18 15:25:58 +02001050 /* bypass vclk and dclk with bclk */
1051 WREG32_P(CG_UPLL_FUNC_CNTL_2,
1052 VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
1053 ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
1054
1055 /* put PLL in bypass mode */
1056 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
1057
1058 if (!vclk || !dclk) {
1059 /* keep the Bypass mode, put PLL to sleep */
1060 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
1061 return 0;
1062 }
1063
Alex Deuchera8b49252013-04-08 12:41:33 +02001064 /* loop through vco from low to high */
1065 for (vco_freq = 125000; vco_freq <= 250000; vco_freq += 100) {
1066 unsigned fb_div = vco_freq / rdev->clock.spll.reference_freq * 16384;
1067 int calc_clk, diff_score, diff_vclk, diff_dclk;
1068 unsigned vclk_div, dclk_div;
1069
1070 /* fb div out of range ? */
1071 if (fb_div > 0x03FFFFFF)
1072 break; /* it can oly get worse */
1073
1074 /* calc vclk with current vco freq. */
1075 calc_clk = evergreen_uvd_calc_post_div(vclk, vco_freq, &vclk_div);
1076 if (calc_clk == -1)
1077 break; /* vco is too big, it has to stop. */
1078 diff_vclk = vclk - calc_clk;
1079
1080 /* calc dclk with current vco freq. */
1081 calc_clk = evergreen_uvd_calc_post_div(dclk, vco_freq, &dclk_div);
1082 if (calc_clk == -1)
1083 break; /* vco is too big, it has to stop. */
1084 diff_dclk = dclk - calc_clk;
1085
1086 /* determine if this vco setting is better than current optimal settings */
1087 diff_score = abs(diff_vclk) + abs(diff_dclk);
1088 if (diff_score < optimal_diff_score) {
1089 optimal_fb_div = fb_div;
1090 optimal_vclk_div = vclk_div;
1091 optimal_dclk_div = dclk_div;
1092 optimal_vco_freq = vco_freq;
1093 optimal_diff_score = diff_score;
1094 if (optimal_diff_score == 0)
1095 break; /* it can't get better than this */
1096 }
1097 }
1098
1099 /* set VCO_MODE to 1 */
1100 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
1101
1102 /* toggle UPLL_SLEEP to 1 then back to 0 */
1103 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
1104 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
1105
1106 /* deassert UPLL_RESET */
1107 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
1108
1109 mdelay(1);
1110
Alex Deuchera8b49252013-04-08 12:41:33 +02001111 r = evergreen_uvd_send_upll_ctlreq(rdev);
1112 if (r)
1113 return r;
1114
1115 /* assert UPLL_RESET again */
1116 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
1117
1118 /* disable spread spectrum. */
1119 WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
1120
1121 /* set feedback divider */
1122 WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(optimal_fb_div), ~UPLL_FB_DIV_MASK);
1123
1124 /* set ref divider to 0 */
1125 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
1126
1127 if (optimal_vco_freq < 187500)
1128 WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
1129 else
1130 WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
1131
1132 /* set PDIV_A and PDIV_B */
1133 WREG32_P(CG_UPLL_FUNC_CNTL_2,
1134 UPLL_PDIV_A(optimal_vclk_div) | UPLL_PDIV_B(optimal_dclk_div),
1135 ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
1136
1137 /* give the PLL some time to settle */
1138 mdelay(15);
1139
1140 /* deassert PLL_RESET */
1141 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
1142
1143 mdelay(15);
1144
1145 /* switch from bypass mode to normal mode */
1146 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
1147
1148 r = evergreen_uvd_send_upll_ctlreq(rdev);
1149 if (r)
1150 return r;
1151
1152 /* switch VCLK and DCLK selection */
1153 WREG32_P(CG_UPLL_FUNC_CNTL_2,
1154 VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
1155 ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
1156
1157 mdelay(100);
1158
1159 return 0;
1160}
1161
Alex Deucherd054ac12011-09-01 17:46:15 +00001162void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev)
1163{
1164 u16 ctl, v;
Jiang Liu32195ae2012-07-24 17:20:30 +08001165 int err;
Alex Deucherd054ac12011-09-01 17:46:15 +00001166
Jiang Liu32195ae2012-07-24 17:20:30 +08001167 err = pcie_capability_read_word(rdev->pdev, PCI_EXP_DEVCTL, &ctl);
Alex Deucherd054ac12011-09-01 17:46:15 +00001168 if (err)
1169 return;
1170
1171 v = (ctl & PCI_EXP_DEVCTL_READRQ) >> 12;
1172
1173 /* if bios or OS sets MAX_READ_REQUEST_SIZE to an invalid value, fix it
1174 * to avoid hangs or perfomance issues
1175 */
1176 if ((v == 0) || (v == 6) || (v == 7)) {
1177 ctl &= ~PCI_EXP_DEVCTL_READRQ;
1178 ctl |= (2 << 12);
Jiang Liu32195ae2012-07-24 17:20:30 +08001179 pcie_capability_write_word(rdev->pdev, PCI_EXP_DEVCTL, ctl);
Alex Deucherd054ac12011-09-01 17:46:15 +00001180 }
1181}
1182
Alex Deucher10257a62013-04-09 18:49:59 -04001183static bool dce4_is_in_vblank(struct radeon_device *rdev, int crtc)
1184{
1185 if (RREG32(EVERGREEN_CRTC_STATUS + crtc_offsets[crtc]) & EVERGREEN_CRTC_V_BLANK)
1186 return true;
1187 else
1188 return false;
1189}
1190
1191static bool dce4_is_counter_moving(struct radeon_device *rdev, int crtc)
1192{
1193 u32 pos1, pos2;
1194
1195 pos1 = RREG32(EVERGREEN_CRTC_STATUS_POSITION + crtc_offsets[crtc]);
1196 pos2 = RREG32(EVERGREEN_CRTC_STATUS_POSITION + crtc_offsets[crtc]);
1197
1198 if (pos1 != pos2)
1199 return true;
1200 else
1201 return false;
1202}
1203
Alex Deucher377edc82012-07-17 14:02:42 -04001204/**
1205 * dce4_wait_for_vblank - vblank wait asic callback.
1206 *
1207 * @rdev: radeon_device pointer
1208 * @crtc: crtc to wait for vblank on
1209 *
1210 * Wait for vblank on the requested crtc (evergreen+).
1211 */
Alex Deucher3ae19b72012-02-23 17:53:37 -05001212void dce4_wait_for_vblank(struct radeon_device *rdev, int crtc)
1213{
Alex Deucher10257a62013-04-09 18:49:59 -04001214 unsigned i = 0;
Alex Deucher3ae19b72012-02-23 17:53:37 -05001215
Alex Deucher4a159032012-08-15 17:13:53 -04001216 if (crtc >= rdev->num_crtc)
1217 return;
1218
Alex Deucher10257a62013-04-09 18:49:59 -04001219 if (!(RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[crtc]) & EVERGREEN_CRTC_MASTER_EN))
1220 return;
1221
1222 /* depending on when we hit vblank, we may be close to active; if so,
1223 * wait for another frame.
1224 */
1225 while (dce4_is_in_vblank(rdev, crtc)) {
1226 if (i++ % 100 == 0) {
1227 if (!dce4_is_counter_moving(rdev, crtc))
Alex Deucher3ae19b72012-02-23 17:53:37 -05001228 break;
Alex Deucher3ae19b72012-02-23 17:53:37 -05001229 }
Alex Deucher10257a62013-04-09 18:49:59 -04001230 }
1231
1232 while (!dce4_is_in_vblank(rdev, crtc)) {
1233 if (i++ % 100 == 0) {
1234 if (!dce4_is_counter_moving(rdev, crtc))
Alex Deucher3ae19b72012-02-23 17:53:37 -05001235 break;
Alex Deucher3ae19b72012-02-23 17:53:37 -05001236 }
1237 }
1238}
1239
Alex Deucher377edc82012-07-17 14:02:42 -04001240/**
1241 * radeon_irq_kms_pflip_irq_get - pre-pageflip callback.
1242 *
1243 * @rdev: radeon_device pointer
1244 * @crtc: crtc to prepare for pageflip on
1245 *
1246 * Pre-pageflip callback (evergreen+).
1247 * Enables the pageflip irq (vblank irq).
1248 */
Alex Deucher6f34be52010-11-21 10:59:01 -05001249void evergreen_pre_page_flip(struct radeon_device *rdev, int crtc)
1250{
Alex Deucher6f34be52010-11-21 10:59:01 -05001251 /* enable the pflip int */
1252 radeon_irq_kms_pflip_irq_get(rdev, crtc);
1253}
1254
Alex Deucher377edc82012-07-17 14:02:42 -04001255/**
1256 * evergreen_post_page_flip - pos-pageflip callback.
1257 *
1258 * @rdev: radeon_device pointer
1259 * @crtc: crtc to cleanup pageflip on
1260 *
1261 * Post-pageflip callback (evergreen+).
1262 * Disables the pageflip irq (vblank irq).
1263 */
Alex Deucher6f34be52010-11-21 10:59:01 -05001264void evergreen_post_page_flip(struct radeon_device *rdev, int crtc)
1265{
1266 /* disable the pflip int */
1267 radeon_irq_kms_pflip_irq_put(rdev, crtc);
1268}
1269
Alex Deucher377edc82012-07-17 14:02:42 -04001270/**
1271 * evergreen_page_flip - pageflip callback.
1272 *
1273 * @rdev: radeon_device pointer
1274 * @crtc_id: crtc to cleanup pageflip on
1275 * @crtc_base: new address of the crtc (GPU MC address)
1276 *
1277 * Does the actual pageflip (evergreen+).
1278 * During vblank we take the crtc lock and wait for the update_pending
1279 * bit to go high, when it does, we release the lock, and allow the
1280 * double buffered update to take place.
1281 * Returns the current update pending status.
1282 */
Alex Deucher6f34be52010-11-21 10:59:01 -05001283u32 evergreen_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
1284{
1285 struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
1286 u32 tmp = RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset);
Alex Deucherf6496472011-11-28 14:49:26 -05001287 int i;
Alex Deucher6f34be52010-11-21 10:59:01 -05001288
1289 /* Lock the graphics update lock */
1290 tmp |= EVERGREEN_GRPH_UPDATE_LOCK;
1291 WREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
1292
1293 /* update the scanout addresses */
1294 WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
1295 upper_32_bits(crtc_base));
1296 WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
1297 (u32)crtc_base);
1298
1299 WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
1300 upper_32_bits(crtc_base));
1301 WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
1302 (u32)crtc_base);
1303
1304 /* Wait for update_pending to go high. */
Alex Deucherf6496472011-11-28 14:49:26 -05001305 for (i = 0; i < rdev->usec_timeout; i++) {
1306 if (RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING)
1307 break;
1308 udelay(1);
1309 }
Alex Deucher6f34be52010-11-21 10:59:01 -05001310 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
1311
1312 /* Unlock the lock, so double-buffering can take place inside vblank */
1313 tmp &= ~EVERGREEN_GRPH_UPDATE_LOCK;
1314 WREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
1315
1316 /* Return current update_pending status: */
1317 return RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING;
1318}
1319
Alex Deucher21a81222010-07-02 12:58:16 -04001320/* get temperature in millidegrees */
Alex Deucher20d391d2011-02-01 16:12:34 -05001321int evergreen_get_temp(struct radeon_device *rdev)
Alex Deucher21a81222010-07-02 12:58:16 -04001322{
Alex Deucher1c88d742011-06-14 19:15:53 +00001323 u32 temp, toffset;
1324 int actual_temp = 0;
Alex Deucher21a81222010-07-02 12:58:16 -04001325
Alex Deucher67b3f822011-05-25 18:45:37 -04001326 if (rdev->family == CHIP_JUNIPER) {
1327 toffset = (RREG32(CG_THERMAL_CTRL) & TOFFSET_MASK) >>
1328 TOFFSET_SHIFT;
1329 temp = (RREG32(CG_TS0_STATUS) & TS0_ADC_DOUT_MASK) >>
1330 TS0_ADC_DOUT_SHIFT;
Alex Deucher21a81222010-07-02 12:58:16 -04001331
Alex Deucher67b3f822011-05-25 18:45:37 -04001332 if (toffset & 0x100)
1333 actual_temp = temp / 2 - (0x200 - toffset);
1334 else
1335 actual_temp = temp / 2 + toffset;
1336
1337 actual_temp = actual_temp * 1000;
1338
1339 } else {
1340 temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >>
1341 ASIC_T_SHIFT;
1342
1343 if (temp & 0x400)
1344 actual_temp = -256;
1345 else if (temp & 0x200)
1346 actual_temp = 255;
1347 else if (temp & 0x100) {
1348 actual_temp = temp & 0x1ff;
1349 actual_temp |= ~0x1ff;
1350 } else
1351 actual_temp = temp & 0xff;
1352
1353 actual_temp = (actual_temp * 1000) / 2;
1354 }
1355
1356 return actual_temp;
Alex Deucher21a81222010-07-02 12:58:16 -04001357}
1358
Alex Deucher20d391d2011-02-01 16:12:34 -05001359int sumo_get_temp(struct radeon_device *rdev)
Alex Deuchere33df252010-11-22 17:56:32 -05001360{
1361 u32 temp = RREG32(CG_THERMAL_STATUS) & 0xff;
Alex Deucher20d391d2011-02-01 16:12:34 -05001362 int actual_temp = temp - 49;
Alex Deuchere33df252010-11-22 17:56:32 -05001363
1364 return actual_temp * 1000;
1365}
1366
Alex Deucher377edc82012-07-17 14:02:42 -04001367/**
1368 * sumo_pm_init_profile - Initialize power profiles callback.
1369 *
1370 * @rdev: radeon_device pointer
1371 *
1372 * Initialize the power states used in profile mode
1373 * (sumo, trinity, SI).
1374 * Used for profile mode only.
1375 */
Alex Deuchera4c9e2e2011-11-04 10:09:41 -04001376void sumo_pm_init_profile(struct radeon_device *rdev)
1377{
1378 int idx;
1379
1380 /* default */
1381 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
1382 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
1383 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
1384 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
1385
1386 /* low,mid sh/mh */
1387 if (rdev->flags & RADEON_IS_MOBILITY)
1388 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
1389 else
1390 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
1391
1392 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
1393 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
1394 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
1395 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
1396
1397 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
1398 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
1399 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
1400 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
1401
1402 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
1403 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
1404 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
1405 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
1406
1407 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
1408 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
1409 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
1410 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
1411
1412 /* high sh/mh */
1413 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
1414 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
1415 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
1416 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
1417 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx =
1418 rdev->pm.power_state[idx].num_clock_modes - 1;
1419
1420 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
1421 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
1422 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
1423 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx =
1424 rdev->pm.power_state[idx].num_clock_modes - 1;
1425}
1426
Alex Deucher377edc82012-07-17 14:02:42 -04001427/**
Alex Deucher27810fb2012-10-01 19:25:11 -04001428 * btc_pm_init_profile - Initialize power profiles callback.
1429 *
1430 * @rdev: radeon_device pointer
1431 *
1432 * Initialize the power states used in profile mode
1433 * (BTC, cayman).
1434 * Used for profile mode only.
1435 */
1436void btc_pm_init_profile(struct radeon_device *rdev)
1437{
1438 int idx;
1439
1440 /* default */
1441 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
1442 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
1443 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
1444 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
1445 /* starting with BTC, there is one state that is used for both
1446 * MH and SH. Difference is that we always use the high clock index for
1447 * mclk.
1448 */
1449 if (rdev->flags & RADEON_IS_MOBILITY)
1450 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
1451 else
1452 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
1453 /* low sh */
1454 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
1455 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
1456 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
1457 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
1458 /* mid sh */
1459 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
1460 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
1461 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
1462 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
1463 /* high sh */
1464 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
1465 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
1466 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
1467 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
1468 /* low mh */
1469 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
1470 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
1471 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
1472 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
1473 /* mid mh */
1474 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
1475 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
1476 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
1477 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
1478 /* high mh */
1479 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
1480 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
1481 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
1482 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
1483}
1484
1485/**
Alex Deucher377edc82012-07-17 14:02:42 -04001486 * evergreen_pm_misc - set additional pm hw parameters callback.
1487 *
1488 * @rdev: radeon_device pointer
1489 *
1490 * Set non-clock parameters associated with a power state
1491 * (voltage, etc.) (evergreen+).
1492 */
Alex Deucher49e02b72010-04-23 17:57:27 -04001493void evergreen_pm_misc(struct radeon_device *rdev)
1494{
Rafał Miłeckia081a9d2010-06-07 18:20:25 -04001495 int req_ps_idx = rdev->pm.requested_power_state_index;
1496 int req_cm_idx = rdev->pm.requested_clock_mode_index;
1497 struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
1498 struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
Alex Deucher49e02b72010-04-23 17:57:27 -04001499
Alex Deucher2feea492011-04-12 14:49:24 -04001500 if (voltage->type == VOLTAGE_SW) {
Alex Deuchera377e182011-06-20 13:00:31 -04001501 /* 0xff01 is a flag rather then an actual voltage */
1502 if (voltage->voltage == 0xff01)
1503 return;
Alex Deucher2feea492011-04-12 14:49:24 -04001504 if (voltage->voltage && (voltage->voltage != rdev->pm.current_vddc)) {
Alex Deucher8a83ec52011-04-12 14:49:23 -04001505 radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
Alex Deucher4d601732010-06-07 18:15:18 -04001506 rdev->pm.current_vddc = voltage->voltage;
Alex Deucher2feea492011-04-12 14:49:24 -04001507 DRM_DEBUG("Setting: vddc: %d\n", voltage->voltage);
1508 }
Alex Deucher7ae764b2013-02-11 08:44:48 -05001509
1510 /* starting with BTC, there is one state that is used for both
1511 * MH and SH. Difference is that we always use the high clock index for
1512 * mclk and vddci.
1513 */
1514 if ((rdev->pm.pm_method == PM_METHOD_PROFILE) &&
1515 (rdev->family >= CHIP_BARTS) &&
1516 rdev->pm.active_crtc_count &&
1517 ((rdev->pm.profile_index == PM_PROFILE_MID_MH_IDX) ||
1518 (rdev->pm.profile_index == PM_PROFILE_LOW_MH_IDX)))
1519 voltage = &rdev->pm.power_state[req_ps_idx].
1520 clock_info[rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx].voltage;
1521
Alex Deuchera377e182011-06-20 13:00:31 -04001522 /* 0xff01 is a flag rather then an actual voltage */
1523 if (voltage->vddci == 0xff01)
1524 return;
Alex Deucher2feea492011-04-12 14:49:24 -04001525 if (voltage->vddci && (voltage->vddci != rdev->pm.current_vddci)) {
1526 radeon_atom_set_voltage(rdev, voltage->vddci, SET_VOLTAGE_TYPE_ASIC_VDDCI);
1527 rdev->pm.current_vddci = voltage->vddci;
1528 DRM_DEBUG("Setting: vddci: %d\n", voltage->vddci);
Alex Deucher4d601732010-06-07 18:15:18 -04001529 }
1530 }
Alex Deucher49e02b72010-04-23 17:57:27 -04001531}
1532
Alex Deucher377edc82012-07-17 14:02:42 -04001533/**
1534 * evergreen_pm_prepare - pre-power state change callback.
1535 *
1536 * @rdev: radeon_device pointer
1537 *
1538 * Prepare for a power state change (evergreen+).
1539 */
Alex Deucher49e02b72010-04-23 17:57:27 -04001540void evergreen_pm_prepare(struct radeon_device *rdev)
1541{
1542 struct drm_device *ddev = rdev->ddev;
1543 struct drm_crtc *crtc;
1544 struct radeon_crtc *radeon_crtc;
1545 u32 tmp;
1546
1547 /* disable any active CRTCs */
1548 list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
1549 radeon_crtc = to_radeon_crtc(crtc);
1550 if (radeon_crtc->enabled) {
1551 tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
1552 tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
1553 WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
1554 }
1555 }
1556}
1557
Alex Deucher377edc82012-07-17 14:02:42 -04001558/**
1559 * evergreen_pm_finish - post-power state change callback.
1560 *
1561 * @rdev: radeon_device pointer
1562 *
1563 * Clean up after a power state change (evergreen+).
1564 */
Alex Deucher49e02b72010-04-23 17:57:27 -04001565void evergreen_pm_finish(struct radeon_device *rdev)
1566{
1567 struct drm_device *ddev = rdev->ddev;
1568 struct drm_crtc *crtc;
1569 struct radeon_crtc *radeon_crtc;
1570 u32 tmp;
1571
1572 /* enable any active CRTCs */
1573 list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
1574 radeon_crtc = to_radeon_crtc(crtc);
1575 if (radeon_crtc->enabled) {
1576 tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
1577 tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
1578 WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
1579 }
1580 }
1581}
1582
Alex Deucher377edc82012-07-17 14:02:42 -04001583/**
1584 * evergreen_hpd_sense - hpd sense callback.
1585 *
1586 * @rdev: radeon_device pointer
1587 * @hpd: hpd (hotplug detect) pin
1588 *
1589 * Checks if a digital monitor is connected (evergreen+).
1590 * Returns true if connected, false if not connected.
1591 */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001592bool evergreen_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
1593{
1594 bool connected = false;
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001595
1596 switch (hpd) {
1597 case RADEON_HPD_1:
1598 if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
1599 connected = true;
1600 break;
1601 case RADEON_HPD_2:
1602 if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
1603 connected = true;
1604 break;
1605 case RADEON_HPD_3:
1606 if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
1607 connected = true;
1608 break;
1609 case RADEON_HPD_4:
1610 if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
1611 connected = true;
1612 break;
1613 case RADEON_HPD_5:
1614 if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
1615 connected = true;
1616 break;
1617 case RADEON_HPD_6:
1618 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
1619 connected = true;
1620 break;
1621 default:
1622 break;
1623 }
1624
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001625 return connected;
1626}
1627
Alex Deucher377edc82012-07-17 14:02:42 -04001628/**
1629 * evergreen_hpd_set_polarity - hpd set polarity callback.
1630 *
1631 * @rdev: radeon_device pointer
1632 * @hpd: hpd (hotplug detect) pin
1633 *
1634 * Set the polarity of the hpd pin (evergreen+).
1635 */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001636void evergreen_hpd_set_polarity(struct radeon_device *rdev,
1637 enum radeon_hpd_id hpd)
1638{
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001639 u32 tmp;
1640 bool connected = evergreen_hpd_sense(rdev, hpd);
1641
1642 switch (hpd) {
1643 case RADEON_HPD_1:
1644 tmp = RREG32(DC_HPD1_INT_CONTROL);
1645 if (connected)
1646 tmp &= ~DC_HPDx_INT_POLARITY;
1647 else
1648 tmp |= DC_HPDx_INT_POLARITY;
1649 WREG32(DC_HPD1_INT_CONTROL, tmp);
1650 break;
1651 case RADEON_HPD_2:
1652 tmp = RREG32(DC_HPD2_INT_CONTROL);
1653 if (connected)
1654 tmp &= ~DC_HPDx_INT_POLARITY;
1655 else
1656 tmp |= DC_HPDx_INT_POLARITY;
1657 WREG32(DC_HPD2_INT_CONTROL, tmp);
1658 break;
1659 case RADEON_HPD_3:
1660 tmp = RREG32(DC_HPD3_INT_CONTROL);
1661 if (connected)
1662 tmp &= ~DC_HPDx_INT_POLARITY;
1663 else
1664 tmp |= DC_HPDx_INT_POLARITY;
1665 WREG32(DC_HPD3_INT_CONTROL, tmp);
1666 break;
1667 case RADEON_HPD_4:
1668 tmp = RREG32(DC_HPD4_INT_CONTROL);
1669 if (connected)
1670 tmp &= ~DC_HPDx_INT_POLARITY;
1671 else
1672 tmp |= DC_HPDx_INT_POLARITY;
1673 WREG32(DC_HPD4_INT_CONTROL, tmp);
1674 break;
1675 case RADEON_HPD_5:
1676 tmp = RREG32(DC_HPD5_INT_CONTROL);
1677 if (connected)
1678 tmp &= ~DC_HPDx_INT_POLARITY;
1679 else
1680 tmp |= DC_HPDx_INT_POLARITY;
1681 WREG32(DC_HPD5_INT_CONTROL, tmp);
1682 break;
1683 case RADEON_HPD_6:
1684 tmp = RREG32(DC_HPD6_INT_CONTROL);
1685 if (connected)
1686 tmp &= ~DC_HPDx_INT_POLARITY;
1687 else
1688 tmp |= DC_HPDx_INT_POLARITY;
1689 WREG32(DC_HPD6_INT_CONTROL, tmp);
1690 break;
1691 default:
1692 break;
1693 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001694}
1695
Alex Deucher377edc82012-07-17 14:02:42 -04001696/**
1697 * evergreen_hpd_init - hpd setup callback.
1698 *
1699 * @rdev: radeon_device pointer
1700 *
1701 * Setup the hpd pins used by the card (evergreen+).
1702 * Enable the pin, set the polarity, and enable the hpd interrupts.
1703 */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001704void evergreen_hpd_init(struct radeon_device *rdev)
1705{
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001706 struct drm_device *dev = rdev->ddev;
1707 struct drm_connector *connector;
Christian Koenigfb982572012-05-17 01:33:30 +02001708 unsigned enabled = 0;
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001709 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) |
1710 DC_HPDx_RX_INT_TIMER(0xfa) | DC_HPDx_EN;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001711
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001712 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1713 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher2e97be72013-04-11 12:45:34 -04001714
1715 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
1716 connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
1717 /* don't try to enable hpd on eDP or LVDS avoid breaking the
1718 * aux dp channel on imac and help (but not completely fix)
1719 * https://bugzilla.redhat.com/show_bug.cgi?id=726143
1720 * also avoid interrupt storms during dpms.
1721 */
1722 continue;
1723 }
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001724 switch (radeon_connector->hpd.hpd) {
1725 case RADEON_HPD_1:
1726 WREG32(DC_HPD1_CONTROL, tmp);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001727 break;
1728 case RADEON_HPD_2:
1729 WREG32(DC_HPD2_CONTROL, tmp);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001730 break;
1731 case RADEON_HPD_3:
1732 WREG32(DC_HPD3_CONTROL, tmp);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001733 break;
1734 case RADEON_HPD_4:
1735 WREG32(DC_HPD4_CONTROL, tmp);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001736 break;
1737 case RADEON_HPD_5:
1738 WREG32(DC_HPD5_CONTROL, tmp);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001739 break;
1740 case RADEON_HPD_6:
1741 WREG32(DC_HPD6_CONTROL, tmp);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001742 break;
1743 default:
1744 break;
1745 }
Alex Deucher64912e92011-11-03 11:21:39 -04001746 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
Christian Koenigfb982572012-05-17 01:33:30 +02001747 enabled |= 1 << radeon_connector->hpd.hpd;
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001748 }
Christian Koenigfb982572012-05-17 01:33:30 +02001749 radeon_irq_kms_enable_hpd(rdev, enabled);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001750}
1751
Alex Deucher377edc82012-07-17 14:02:42 -04001752/**
1753 * evergreen_hpd_fini - hpd tear down callback.
1754 *
1755 * @rdev: radeon_device pointer
1756 *
1757 * Tear down the hpd pins used by the card (evergreen+).
1758 * Disable the hpd interrupts.
1759 */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001760void evergreen_hpd_fini(struct radeon_device *rdev)
1761{
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001762 struct drm_device *dev = rdev->ddev;
1763 struct drm_connector *connector;
Christian Koenigfb982572012-05-17 01:33:30 +02001764 unsigned disabled = 0;
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001765
1766 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1767 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1768 switch (radeon_connector->hpd.hpd) {
1769 case RADEON_HPD_1:
1770 WREG32(DC_HPD1_CONTROL, 0);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001771 break;
1772 case RADEON_HPD_2:
1773 WREG32(DC_HPD2_CONTROL, 0);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001774 break;
1775 case RADEON_HPD_3:
1776 WREG32(DC_HPD3_CONTROL, 0);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001777 break;
1778 case RADEON_HPD_4:
1779 WREG32(DC_HPD4_CONTROL, 0);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001780 break;
1781 case RADEON_HPD_5:
1782 WREG32(DC_HPD5_CONTROL, 0);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001783 break;
1784 case RADEON_HPD_6:
1785 WREG32(DC_HPD6_CONTROL, 0);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001786 break;
1787 default:
1788 break;
1789 }
Christian Koenigfb982572012-05-17 01:33:30 +02001790 disabled |= 1 << radeon_connector->hpd.hpd;
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001791 }
Christian Koenigfb982572012-05-17 01:33:30 +02001792 radeon_irq_kms_disable_hpd(rdev, disabled);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001793}
1794
Alex Deucherf9d9c362010-10-22 02:51:05 -04001795/* watermark setup */
1796
1797static u32 evergreen_line_buffer_adjust(struct radeon_device *rdev,
1798 struct radeon_crtc *radeon_crtc,
1799 struct drm_display_mode *mode,
1800 struct drm_display_mode *other_mode)
1801{
Alex Deucher12dfc842011-04-14 19:07:34 -04001802 u32 tmp;
Alex Deucherf9d9c362010-10-22 02:51:05 -04001803 /*
1804 * Line Buffer Setup
1805 * There are 3 line buffers, each one shared by 2 display controllers.
1806 * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
1807 * the display controllers. The paritioning is done via one of four
1808 * preset allocations specified in bits 2:0:
1809 * first display controller
1810 * 0 - first half of lb (3840 * 2)
1811 * 1 - first 3/4 of lb (5760 * 2)
Alex Deucher12dfc842011-04-14 19:07:34 -04001812 * 2 - whole lb (7680 * 2), other crtc must be disabled
Alex Deucherf9d9c362010-10-22 02:51:05 -04001813 * 3 - first 1/4 of lb (1920 * 2)
1814 * second display controller
1815 * 4 - second half of lb (3840 * 2)
1816 * 5 - second 3/4 of lb (5760 * 2)
Alex Deucher12dfc842011-04-14 19:07:34 -04001817 * 6 - whole lb (7680 * 2), other crtc must be disabled
Alex Deucherf9d9c362010-10-22 02:51:05 -04001818 * 7 - last 1/4 of lb (1920 * 2)
1819 */
Alex Deucher12dfc842011-04-14 19:07:34 -04001820 /* this can get tricky if we have two large displays on a paired group
1821 * of crtcs. Ideally for multiple large displays we'd assign them to
1822 * non-linked crtcs for maximum line buffer allocation.
1823 */
1824 if (radeon_crtc->base.enabled && mode) {
1825 if (other_mode)
Alex Deucherf9d9c362010-10-22 02:51:05 -04001826 tmp = 0; /* 1/2 */
Alex Deucher12dfc842011-04-14 19:07:34 -04001827 else
1828 tmp = 2; /* whole */
1829 } else
1830 tmp = 0;
Alex Deucherf9d9c362010-10-22 02:51:05 -04001831
1832 /* second controller of the pair uses second half of the lb */
1833 if (radeon_crtc->crtc_id % 2)
1834 tmp += 4;
1835 WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset, tmp);
1836
Alex Deucher12dfc842011-04-14 19:07:34 -04001837 if (radeon_crtc->base.enabled && mode) {
1838 switch (tmp) {
1839 case 0:
1840 case 4:
1841 default:
1842 if (ASIC_IS_DCE5(rdev))
1843 return 4096 * 2;
1844 else
1845 return 3840 * 2;
1846 case 1:
1847 case 5:
1848 if (ASIC_IS_DCE5(rdev))
1849 return 6144 * 2;
1850 else
1851 return 5760 * 2;
1852 case 2:
1853 case 6:
1854 if (ASIC_IS_DCE5(rdev))
1855 return 8192 * 2;
1856 else
1857 return 7680 * 2;
1858 case 3:
1859 case 7:
1860 if (ASIC_IS_DCE5(rdev))
1861 return 2048 * 2;
1862 else
1863 return 1920 * 2;
1864 }
Alex Deucherf9d9c362010-10-22 02:51:05 -04001865 }
Alex Deucher12dfc842011-04-14 19:07:34 -04001866
1867 /* controller not enabled, so no lb used */
1868 return 0;
Alex Deucherf9d9c362010-10-22 02:51:05 -04001869}
1870
Alex Deucherca7db222012-03-20 17:18:30 -04001871u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev)
Alex Deucherf9d9c362010-10-22 02:51:05 -04001872{
1873 u32 tmp = RREG32(MC_SHARED_CHMAP);
1874
1875 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1876 case 0:
1877 default:
1878 return 1;
1879 case 1:
1880 return 2;
1881 case 2:
1882 return 4;
1883 case 3:
1884 return 8;
1885 }
1886}
1887
1888struct evergreen_wm_params {
1889 u32 dram_channels; /* number of dram channels */
1890 u32 yclk; /* bandwidth per dram data pin in kHz */
1891 u32 sclk; /* engine clock in kHz */
1892 u32 disp_clk; /* display clock in kHz */
1893 u32 src_width; /* viewport width */
1894 u32 active_time; /* active display time in ns */
1895 u32 blank_time; /* blank time in ns */
1896 bool interlaced; /* mode is interlaced */
1897 fixed20_12 vsc; /* vertical scale ratio */
1898 u32 num_heads; /* number of active crtcs */
1899 u32 bytes_per_pixel; /* bytes per pixel display + overlay */
1900 u32 lb_size; /* line buffer allocated to pipe */
1901 u32 vtaps; /* vertical scaler taps */
1902};
1903
1904static u32 evergreen_dram_bandwidth(struct evergreen_wm_params *wm)
1905{
1906 /* Calculate DRAM Bandwidth and the part allocated to display. */
1907 fixed20_12 dram_efficiency; /* 0.7 */
1908 fixed20_12 yclk, dram_channels, bandwidth;
1909 fixed20_12 a;
1910
1911 a.full = dfixed_const(1000);
1912 yclk.full = dfixed_const(wm->yclk);
1913 yclk.full = dfixed_div(yclk, a);
1914 dram_channels.full = dfixed_const(wm->dram_channels * 4);
1915 a.full = dfixed_const(10);
1916 dram_efficiency.full = dfixed_const(7);
1917 dram_efficiency.full = dfixed_div(dram_efficiency, a);
1918 bandwidth.full = dfixed_mul(dram_channels, yclk);
1919 bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
1920
1921 return dfixed_trunc(bandwidth);
1922}
1923
1924static u32 evergreen_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
1925{
1926 /* Calculate DRAM Bandwidth and the part allocated to display. */
1927 fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
1928 fixed20_12 yclk, dram_channels, bandwidth;
1929 fixed20_12 a;
1930
1931 a.full = dfixed_const(1000);
1932 yclk.full = dfixed_const(wm->yclk);
1933 yclk.full = dfixed_div(yclk, a);
1934 dram_channels.full = dfixed_const(wm->dram_channels * 4);
1935 a.full = dfixed_const(10);
1936 disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
1937 disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
1938 bandwidth.full = dfixed_mul(dram_channels, yclk);
1939 bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
1940
1941 return dfixed_trunc(bandwidth);
1942}
1943
1944static u32 evergreen_data_return_bandwidth(struct evergreen_wm_params *wm)
1945{
1946 /* Calculate the display Data return Bandwidth */
1947 fixed20_12 return_efficiency; /* 0.8 */
1948 fixed20_12 sclk, bandwidth;
1949 fixed20_12 a;
1950
1951 a.full = dfixed_const(1000);
1952 sclk.full = dfixed_const(wm->sclk);
1953 sclk.full = dfixed_div(sclk, a);
1954 a.full = dfixed_const(10);
1955 return_efficiency.full = dfixed_const(8);
1956 return_efficiency.full = dfixed_div(return_efficiency, a);
1957 a.full = dfixed_const(32);
1958 bandwidth.full = dfixed_mul(a, sclk);
1959 bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
1960
1961 return dfixed_trunc(bandwidth);
1962}
1963
1964static u32 evergreen_dmif_request_bandwidth(struct evergreen_wm_params *wm)
1965{
1966 /* Calculate the DMIF Request Bandwidth */
1967 fixed20_12 disp_clk_request_efficiency; /* 0.8 */
1968 fixed20_12 disp_clk, bandwidth;
1969 fixed20_12 a;
1970
1971 a.full = dfixed_const(1000);
1972 disp_clk.full = dfixed_const(wm->disp_clk);
1973 disp_clk.full = dfixed_div(disp_clk, a);
1974 a.full = dfixed_const(10);
1975 disp_clk_request_efficiency.full = dfixed_const(8);
1976 disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
1977 a.full = dfixed_const(32);
1978 bandwidth.full = dfixed_mul(a, disp_clk);
1979 bandwidth.full = dfixed_mul(bandwidth, disp_clk_request_efficiency);
1980
1981 return dfixed_trunc(bandwidth);
1982}
1983
1984static u32 evergreen_available_bandwidth(struct evergreen_wm_params *wm)
1985{
1986 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
1987 u32 dram_bandwidth = evergreen_dram_bandwidth(wm);
1988 u32 data_return_bandwidth = evergreen_data_return_bandwidth(wm);
1989 u32 dmif_req_bandwidth = evergreen_dmif_request_bandwidth(wm);
1990
1991 return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
1992}
1993
1994static u32 evergreen_average_bandwidth(struct evergreen_wm_params *wm)
1995{
1996 /* Calculate the display mode Average Bandwidth
1997 * DisplayMode should contain the source and destination dimensions,
1998 * timing, etc.
1999 */
2000 fixed20_12 bpp;
2001 fixed20_12 line_time;
2002 fixed20_12 src_width;
2003 fixed20_12 bandwidth;
2004 fixed20_12 a;
2005
2006 a.full = dfixed_const(1000);
2007 line_time.full = dfixed_const(wm->active_time + wm->blank_time);
2008 line_time.full = dfixed_div(line_time, a);
2009 bpp.full = dfixed_const(wm->bytes_per_pixel);
2010 src_width.full = dfixed_const(wm->src_width);
2011 bandwidth.full = dfixed_mul(src_width, bpp);
2012 bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
2013 bandwidth.full = dfixed_div(bandwidth, line_time);
2014
2015 return dfixed_trunc(bandwidth);
2016}
2017
2018static u32 evergreen_latency_watermark(struct evergreen_wm_params *wm)
2019{
2020 /* First calcualte the latency in ns */
2021 u32 mc_latency = 2000; /* 2000 ns. */
2022 u32 available_bandwidth = evergreen_available_bandwidth(wm);
2023 u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
2024 u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
2025 u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
2026 u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
2027 (wm->num_heads * cursor_line_pair_return_time);
2028 u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
2029 u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
2030 fixed20_12 a, b, c;
2031
2032 if (wm->num_heads == 0)
2033 return 0;
2034
2035 a.full = dfixed_const(2);
2036 b.full = dfixed_const(1);
2037 if ((wm->vsc.full > a.full) ||
2038 ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
2039 (wm->vtaps >= 5) ||
2040 ((wm->vsc.full >= a.full) && wm->interlaced))
2041 max_src_lines_per_dst_line = 4;
2042 else
2043 max_src_lines_per_dst_line = 2;
2044
2045 a.full = dfixed_const(available_bandwidth);
2046 b.full = dfixed_const(wm->num_heads);
2047 a.full = dfixed_div(a, b);
2048
2049 b.full = dfixed_const(1000);
2050 c.full = dfixed_const(wm->disp_clk);
2051 b.full = dfixed_div(c, b);
2052 c.full = dfixed_const(wm->bytes_per_pixel);
2053 b.full = dfixed_mul(b, c);
2054
2055 lb_fill_bw = min(dfixed_trunc(a), dfixed_trunc(b));
2056
2057 a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
2058 b.full = dfixed_const(1000);
2059 c.full = dfixed_const(lb_fill_bw);
2060 b.full = dfixed_div(c, b);
2061 a.full = dfixed_div(a, b);
2062 line_fill_time = dfixed_trunc(a);
2063
2064 if (line_fill_time < wm->active_time)
2065 return latency;
2066 else
2067 return latency + (line_fill_time - wm->active_time);
2068
2069}
2070
2071static bool evergreen_average_bandwidth_vs_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
2072{
2073 if (evergreen_average_bandwidth(wm) <=
2074 (evergreen_dram_bandwidth_for_display(wm) / wm->num_heads))
2075 return true;
2076 else
2077 return false;
2078};
2079
2080static bool evergreen_average_bandwidth_vs_available_bandwidth(struct evergreen_wm_params *wm)
2081{
2082 if (evergreen_average_bandwidth(wm) <=
2083 (evergreen_available_bandwidth(wm) / wm->num_heads))
2084 return true;
2085 else
2086 return false;
2087};
2088
2089static bool evergreen_check_latency_hiding(struct evergreen_wm_params *wm)
2090{
2091 u32 lb_partitions = wm->lb_size / wm->src_width;
2092 u32 line_time = wm->active_time + wm->blank_time;
2093 u32 latency_tolerant_lines;
2094 u32 latency_hiding;
2095 fixed20_12 a;
2096
2097 a.full = dfixed_const(1);
2098 if (wm->vsc.full > a.full)
2099 latency_tolerant_lines = 1;
2100 else {
2101 if (lb_partitions <= (wm->vtaps + 1))
2102 latency_tolerant_lines = 1;
2103 else
2104 latency_tolerant_lines = 2;
2105 }
2106
2107 latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
2108
2109 if (evergreen_latency_watermark(wm) <= latency_hiding)
2110 return true;
2111 else
2112 return false;
2113}
2114
2115static void evergreen_program_watermarks(struct radeon_device *rdev,
2116 struct radeon_crtc *radeon_crtc,
2117 u32 lb_size, u32 num_heads)
2118{
2119 struct drm_display_mode *mode = &radeon_crtc->base.mode;
2120 struct evergreen_wm_params wm;
2121 u32 pixel_period;
2122 u32 line_time = 0;
2123 u32 latency_watermark_a = 0, latency_watermark_b = 0;
2124 u32 priority_a_mark = 0, priority_b_mark = 0;
2125 u32 priority_a_cnt = PRIORITY_OFF;
2126 u32 priority_b_cnt = PRIORITY_OFF;
2127 u32 pipe_offset = radeon_crtc->crtc_id * 16;
2128 u32 tmp, arb_control3;
2129 fixed20_12 a, b, c;
2130
2131 if (radeon_crtc->base.enabled && num_heads && mode) {
2132 pixel_period = 1000000 / (u32)mode->clock;
2133 line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
2134 priority_a_cnt = 0;
2135 priority_b_cnt = 0;
2136
2137 wm.yclk = rdev->pm.current_mclk * 10;
2138 wm.sclk = rdev->pm.current_sclk * 10;
2139 wm.disp_clk = mode->clock;
2140 wm.src_width = mode->crtc_hdisplay;
2141 wm.active_time = mode->crtc_hdisplay * pixel_period;
2142 wm.blank_time = line_time - wm.active_time;
2143 wm.interlaced = false;
2144 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2145 wm.interlaced = true;
2146 wm.vsc = radeon_crtc->vsc;
2147 wm.vtaps = 1;
2148 if (radeon_crtc->rmx_type != RMX_OFF)
2149 wm.vtaps = 2;
2150 wm.bytes_per_pixel = 4; /* XXX: get this from fb config */
2151 wm.lb_size = lb_size;
2152 wm.dram_channels = evergreen_get_number_of_dram_channels(rdev);
2153 wm.num_heads = num_heads;
2154
2155 /* set for high clocks */
2156 latency_watermark_a = min(evergreen_latency_watermark(&wm), (u32)65535);
2157 /* set for low clocks */
2158 /* wm.yclk = low clk; wm.sclk = low clk */
2159 latency_watermark_b = min(evergreen_latency_watermark(&wm), (u32)65535);
2160
2161 /* possibly force display priority to high */
2162 /* should really do this at mode validation time... */
2163 if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm) ||
2164 !evergreen_average_bandwidth_vs_available_bandwidth(&wm) ||
2165 !evergreen_check_latency_hiding(&wm) ||
2166 (rdev->disp_priority == 2)) {
Alex Deucher92bdfd42011-08-04 17:28:40 +00002167 DRM_DEBUG_KMS("force priority to high\n");
Alex Deucherf9d9c362010-10-22 02:51:05 -04002168 priority_a_cnt |= PRIORITY_ALWAYS_ON;
2169 priority_b_cnt |= PRIORITY_ALWAYS_ON;
2170 }
2171
2172 a.full = dfixed_const(1000);
2173 b.full = dfixed_const(mode->clock);
2174 b.full = dfixed_div(b, a);
2175 c.full = dfixed_const(latency_watermark_a);
2176 c.full = dfixed_mul(c, b);
2177 c.full = dfixed_mul(c, radeon_crtc->hsc);
2178 c.full = dfixed_div(c, a);
2179 a.full = dfixed_const(16);
2180 c.full = dfixed_div(c, a);
2181 priority_a_mark = dfixed_trunc(c);
2182 priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
2183
2184 a.full = dfixed_const(1000);
2185 b.full = dfixed_const(mode->clock);
2186 b.full = dfixed_div(b, a);
2187 c.full = dfixed_const(latency_watermark_b);
2188 c.full = dfixed_mul(c, b);
2189 c.full = dfixed_mul(c, radeon_crtc->hsc);
2190 c.full = dfixed_div(c, a);
2191 a.full = dfixed_const(16);
2192 c.full = dfixed_div(c, a);
2193 priority_b_mark = dfixed_trunc(c);
2194 priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
2195 }
2196
2197 /* select wm A */
2198 arb_control3 = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
2199 tmp = arb_control3;
2200 tmp &= ~LATENCY_WATERMARK_MASK(3);
2201 tmp |= LATENCY_WATERMARK_MASK(1);
2202 WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
2203 WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
2204 (LATENCY_LOW_WATERMARK(latency_watermark_a) |
2205 LATENCY_HIGH_WATERMARK(line_time)));
2206 /* select wm B */
2207 tmp = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
2208 tmp &= ~LATENCY_WATERMARK_MASK(3);
2209 tmp |= LATENCY_WATERMARK_MASK(2);
2210 WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
2211 WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
2212 (LATENCY_LOW_WATERMARK(latency_watermark_b) |
2213 LATENCY_HIGH_WATERMARK(line_time)));
2214 /* restore original selection */
2215 WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, arb_control3);
2216
2217 /* write the priority marks */
2218 WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
2219 WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
2220
2221}
2222
Alex Deucher377edc82012-07-17 14:02:42 -04002223/**
2224 * evergreen_bandwidth_update - update display watermarks callback.
2225 *
2226 * @rdev: radeon_device pointer
2227 *
2228 * Update the display watermarks based on the requested mode(s)
2229 * (evergreen+).
2230 */
Alex Deucher0ca2ab52010-02-26 13:57:45 -05002231void evergreen_bandwidth_update(struct radeon_device *rdev)
2232{
Alex Deucherf9d9c362010-10-22 02:51:05 -04002233 struct drm_display_mode *mode0 = NULL;
2234 struct drm_display_mode *mode1 = NULL;
2235 u32 num_heads = 0, lb_size;
2236 int i;
2237
2238 radeon_update_display_priority(rdev);
2239
2240 for (i = 0; i < rdev->num_crtc; i++) {
2241 if (rdev->mode_info.crtcs[i]->base.enabled)
2242 num_heads++;
2243 }
2244 for (i = 0; i < rdev->num_crtc; i += 2) {
2245 mode0 = &rdev->mode_info.crtcs[i]->base.mode;
2246 mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
2247 lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
2248 evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
2249 lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
2250 evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
2251 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002252}
2253
Alex Deucher377edc82012-07-17 14:02:42 -04002254/**
2255 * evergreen_mc_wait_for_idle - wait for MC idle callback.
2256 *
2257 * @rdev: radeon_device pointer
2258 *
2259 * Wait for the MC (memory controller) to be idle.
2260 * (evergreen+).
2261 * Returns 0 if the MC is idle, -1 if not.
2262 */
Alex Deucherb9952a82011-03-02 20:07:33 -05002263int evergreen_mc_wait_for_idle(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002264{
2265 unsigned i;
2266 u32 tmp;
2267
2268 for (i = 0; i < rdev->usec_timeout; i++) {
2269 /* read MC_STATUS */
2270 tmp = RREG32(SRBM_STATUS) & 0x1F00;
2271 if (!tmp)
2272 return 0;
2273 udelay(1);
2274 }
2275 return -1;
2276}
2277
2278/*
2279 * GART
2280 */
Alex Deucher0fcdb612010-03-24 13:20:41 -04002281void evergreen_pcie_gart_tlb_flush(struct radeon_device *rdev)
2282{
2283 unsigned i;
2284 u32 tmp;
2285
Alex Deucher6f2f48a2010-12-15 11:01:56 -05002286 WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
2287
Alex Deucher0fcdb612010-03-24 13:20:41 -04002288 WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
2289 for (i = 0; i < rdev->usec_timeout; i++) {
2290 /* read MC_STATUS */
2291 tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
2292 tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
2293 if (tmp == 2) {
2294 printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
2295 return;
2296 }
2297 if (tmp) {
2298 return;
2299 }
2300 udelay(1);
2301 }
2302}
2303
Lauri Kasanen1109ca02012-08-31 13:43:50 -04002304static int evergreen_pcie_gart_enable(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002305{
2306 u32 tmp;
Alex Deucher0fcdb612010-03-24 13:20:41 -04002307 int r;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002308
Jerome Glissec9a1be92011-11-03 11:16:49 -04002309 if (rdev->gart.robj == NULL) {
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002310 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
2311 return -EINVAL;
2312 }
2313 r = radeon_gart_table_vram_pin(rdev);
2314 if (r)
2315 return r;
Dave Airlie82568562010-02-05 16:00:07 +10002316 radeon_gart_restore(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002317 /* Setup L2 cache */
2318 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
2319 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
2320 EFFECTIVE_L2_QUEUE_SIZE(7));
2321 WREG32(VM_L2_CNTL2, 0);
2322 WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
2323 /* Setup TLB control */
2324 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
2325 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
2326 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
2327 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
Alex Deucher8aeb96f82011-05-03 19:28:02 -04002328 if (rdev->flags & RADEON_IS_IGP) {
2329 WREG32(FUS_MC_VM_MD_L1_TLB0_CNTL, tmp);
2330 WREG32(FUS_MC_VM_MD_L1_TLB1_CNTL, tmp);
2331 WREG32(FUS_MC_VM_MD_L1_TLB2_CNTL, tmp);
2332 } else {
2333 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
2334 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
2335 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
Alex Deucher0b8c30b2012-05-31 18:54:43 -04002336 if ((rdev->family == CHIP_JUNIPER) ||
2337 (rdev->family == CHIP_CYPRESS) ||
2338 (rdev->family == CHIP_HEMLOCK) ||
2339 (rdev->family == CHIP_BARTS))
2340 WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp);
Alex Deucher8aeb96f82011-05-03 19:28:02 -04002341 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002342 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
2343 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
2344 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
2345 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
2346 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
2347 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
2348 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
2349 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
2350 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
2351 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
2352 (u32)(rdev->dummy_page.addr >> 12));
Alex Deucher0fcdb612010-03-24 13:20:41 -04002353 WREG32(VM_CONTEXT1_CNTL, 0);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002354
Alex Deucher0fcdb612010-03-24 13:20:41 -04002355 evergreen_pcie_gart_tlb_flush(rdev);
Tormod Voldenfcf4de52011-08-31 21:54:07 +00002356 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
2357 (unsigned)(rdev->mc.gtt_size >> 20),
2358 (unsigned long long)rdev->gart.table_addr);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002359 rdev->gart.ready = true;
2360 return 0;
2361}
2362
Lauri Kasanen1109ca02012-08-31 13:43:50 -04002363static void evergreen_pcie_gart_disable(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002364{
2365 u32 tmp;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002366
2367 /* Disable all tables */
Alex Deucher0fcdb612010-03-24 13:20:41 -04002368 WREG32(VM_CONTEXT0_CNTL, 0);
2369 WREG32(VM_CONTEXT1_CNTL, 0);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002370
2371 /* Setup L2 cache */
2372 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
2373 EFFECTIVE_L2_QUEUE_SIZE(7));
2374 WREG32(VM_L2_CNTL2, 0);
2375 WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
2376 /* Setup TLB control */
2377 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
2378 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
2379 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
2380 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
2381 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
2382 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
2383 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
2384 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
Jerome Glissec9a1be92011-11-03 11:16:49 -04002385 radeon_gart_table_vram_unpin(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002386}
2387
Lauri Kasanen1109ca02012-08-31 13:43:50 -04002388static void evergreen_pcie_gart_fini(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002389{
2390 evergreen_pcie_gart_disable(rdev);
2391 radeon_gart_table_vram_free(rdev);
2392 radeon_gart_fini(rdev);
2393}
2394
2395
Lauri Kasanen1109ca02012-08-31 13:43:50 -04002396static void evergreen_agp_enable(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002397{
2398 u32 tmp;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002399
2400 /* Setup L2 cache */
2401 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
2402 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
2403 EFFECTIVE_L2_QUEUE_SIZE(7));
2404 WREG32(VM_L2_CNTL2, 0);
2405 WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
2406 /* Setup TLB control */
2407 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
2408 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
2409 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
2410 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
2411 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
2412 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
2413 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
2414 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
2415 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
2416 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
2417 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
Alex Deucher0fcdb612010-03-24 13:20:41 -04002418 WREG32(VM_CONTEXT0_CNTL, 0);
2419 WREG32(VM_CONTEXT1_CNTL, 0);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002420}
2421
Alex Deucherb9952a82011-03-02 20:07:33 -05002422void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002423{
Alex Deucher62444b72012-08-15 17:18:42 -04002424 u32 crtc_enabled, tmp, frame_count, blackout;
2425 int i, j;
2426
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002427 save->vga_render_control = RREG32(VGA_RENDER_CONTROL);
2428 save->vga_hdp_control = RREG32(VGA_HDP_CONTROL);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002429
Alex Deucher62444b72012-08-15 17:18:42 -04002430 /* disable VGA render */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002431 WREG32(VGA_RENDER_CONTROL, 0);
Alex Deucher62444b72012-08-15 17:18:42 -04002432 /* blank the display controllers */
2433 for (i = 0; i < rdev->num_crtc; i++) {
2434 crtc_enabled = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN;
2435 if (crtc_enabled) {
2436 save->crtc_enabled[i] = true;
2437 if (ASIC_IS_DCE6(rdev)) {
2438 tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
2439 if (!(tmp & EVERGREEN_CRTC_BLANK_DATA_EN)) {
2440 radeon_wait_for_vblank(rdev, i);
Alex Deucherabf14572013-04-10 19:08:14 -04002441 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
Alex Deucher62444b72012-08-15 17:18:42 -04002442 tmp |= EVERGREEN_CRTC_BLANK_DATA_EN;
2443 WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
2444 }
2445 } else {
2446 tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
2447 if (!(tmp & EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE)) {
2448 radeon_wait_for_vblank(rdev, i);
Alex Deucherabf14572013-04-10 19:08:14 -04002449 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
Alex Deucher62444b72012-08-15 17:18:42 -04002450 tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
2451 WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
Alex Deucherabf14572013-04-10 19:08:14 -04002452 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
Alex Deucher62444b72012-08-15 17:18:42 -04002453 }
2454 }
2455 /* wait for the next frame */
2456 frame_count = radeon_get_vblank_counter(rdev, i);
2457 for (j = 0; j < rdev->usec_timeout; j++) {
2458 if (radeon_get_vblank_counter(rdev, i) != frame_count)
2459 break;
2460 udelay(1);
2461 }
Alex Deucherabf14572013-04-10 19:08:14 -04002462
2463 /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
2464 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
2465 tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
2466 tmp &= ~EVERGREEN_CRTC_MASTER_EN;
2467 WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
2468 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
2469 save->crtc_enabled[i] = false;
2470 /* ***** */
Alex Deucher804cc4a02012-11-19 09:11:27 -05002471 } else {
2472 save->crtc_enabled[i] = false;
Alex Deucher62444b72012-08-15 17:18:42 -04002473 }
Alex Deucher18007402010-11-22 17:56:28 -05002474 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002475
Alex Deucher62444b72012-08-15 17:18:42 -04002476 radeon_mc_wait_for_idle(rdev);
2477
2478 blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
2479 if ((blackout & BLACKOUT_MODE_MASK) != 1) {
2480 /* Block CPU access */
2481 WREG32(BIF_FB_EN, 0);
2482 /* blackout the MC */
2483 blackout &= ~BLACKOUT_MODE_MASK;
2484 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
Alex Deucherb7eff392011-07-08 11:44:56 -04002485 }
Alex Deuchered39fad2013-01-31 09:00:52 -05002486 /* wait for the MC to settle */
2487 udelay(100);
Alex Deucher968c0162013-04-10 09:58:42 -04002488
2489 /* lock double buffered regs */
2490 for (i = 0; i < rdev->num_crtc; i++) {
2491 if (save->crtc_enabled[i]) {
2492 tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
2493 if (!(tmp & EVERGREEN_GRPH_UPDATE_LOCK)) {
2494 tmp |= EVERGREEN_GRPH_UPDATE_LOCK;
2495 WREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i], tmp);
2496 }
2497 tmp = RREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i]);
2498 if (!(tmp & 1)) {
2499 tmp |= 1;
2500 WREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
2501 }
2502 }
2503 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002504}
2505
Alex Deucherb9952a82011-03-02 20:07:33 -05002506void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002507{
Alex Deucher62444b72012-08-15 17:18:42 -04002508 u32 tmp, frame_count;
2509 int i, j;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002510
Alex Deucher62444b72012-08-15 17:18:42 -04002511 /* update crtc base addresses */
2512 for (i = 0; i < rdev->num_crtc; i++) {
2513 WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
Alex Deucher18007402010-11-22 17:56:28 -05002514 upper_32_bits(rdev->mc.vram_start));
Alex Deucher62444b72012-08-15 17:18:42 -04002515 WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
Alex Deucher18007402010-11-22 17:56:28 -05002516 upper_32_bits(rdev->mc.vram_start));
Alex Deucher62444b72012-08-15 17:18:42 -04002517 WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
Alex Deucher18007402010-11-22 17:56:28 -05002518 (u32)rdev->mc.vram_start);
Alex Deucher62444b72012-08-15 17:18:42 -04002519 WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i],
Alex Deucher18007402010-11-22 17:56:28 -05002520 (u32)rdev->mc.vram_start);
Alex Deucherb7eff392011-07-08 11:44:56 -04002521 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002522 WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(rdev->mc.vram_start));
2523 WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS, (u32)rdev->mc.vram_start);
Alex Deucher62444b72012-08-15 17:18:42 -04002524
Alex Deucher968c0162013-04-10 09:58:42 -04002525 /* unlock regs and wait for update */
2526 for (i = 0; i < rdev->num_crtc; i++) {
2527 if (save->crtc_enabled[i]) {
2528 tmp = RREG32(EVERGREEN_MASTER_UPDATE_MODE + crtc_offsets[i]);
2529 if ((tmp & 0x3) != 0) {
2530 tmp &= ~0x3;
2531 WREG32(EVERGREEN_MASTER_UPDATE_MODE + crtc_offsets[i], tmp);
2532 }
2533 tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
2534 if (tmp & EVERGREEN_GRPH_UPDATE_LOCK) {
2535 tmp &= ~EVERGREEN_GRPH_UPDATE_LOCK;
2536 WREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i], tmp);
2537 }
2538 tmp = RREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i]);
2539 if (tmp & 1) {
2540 tmp &= ~1;
2541 WREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
2542 }
2543 for (j = 0; j < rdev->usec_timeout; j++) {
2544 tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
2545 if ((tmp & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING) == 0)
2546 break;
2547 udelay(1);
2548 }
2549 }
2550 }
2551
Alex Deucher62444b72012-08-15 17:18:42 -04002552 /* unblackout the MC */
2553 tmp = RREG32(MC_SHARED_BLACKOUT_CNTL);
2554 tmp &= ~BLACKOUT_MODE_MASK;
2555 WREG32(MC_SHARED_BLACKOUT_CNTL, tmp);
2556 /* allow CPU access */
2557 WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
2558
2559 for (i = 0; i < rdev->num_crtc; i++) {
Alex Deucher695ddeb2012-11-05 16:34:58 +00002560 if (save->crtc_enabled[i]) {
Alex Deucher62444b72012-08-15 17:18:42 -04002561 if (ASIC_IS_DCE6(rdev)) {
2562 tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
2563 tmp |= EVERGREEN_CRTC_BLANK_DATA_EN;
Christopher Staitebb5888202013-01-26 11:10:58 -05002564 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
Alex Deucher62444b72012-08-15 17:18:42 -04002565 WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
Christopher Staitebb5888202013-01-26 11:10:58 -05002566 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
Alex Deucher62444b72012-08-15 17:18:42 -04002567 } else {
2568 tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
2569 tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
Christopher Staitebb5888202013-01-26 11:10:58 -05002570 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
Alex Deucher62444b72012-08-15 17:18:42 -04002571 WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
Christopher Staitebb5888202013-01-26 11:10:58 -05002572 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
Alex Deucher62444b72012-08-15 17:18:42 -04002573 }
2574 /* wait for the next frame */
2575 frame_count = radeon_get_vblank_counter(rdev, i);
2576 for (j = 0; j < rdev->usec_timeout; j++) {
2577 if (radeon_get_vblank_counter(rdev, i) != frame_count)
2578 break;
2579 udelay(1);
2580 }
2581 }
2582 }
2583 /* Unlock vga access */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002584 WREG32(VGA_HDP_CONTROL, save->vga_hdp_control);
2585 mdelay(1);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002586 WREG32(VGA_RENDER_CONTROL, save->vga_render_control);
2587}
2588
Alex Deucher755d8192011-03-02 20:07:34 -05002589void evergreen_mc_program(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002590{
2591 struct evergreen_mc_save save;
2592 u32 tmp;
2593 int i, j;
2594
2595 /* Initialize HDP */
2596 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
2597 WREG32((0x2c14 + j), 0x00000000);
2598 WREG32((0x2c18 + j), 0x00000000);
2599 WREG32((0x2c1c + j), 0x00000000);
2600 WREG32((0x2c20 + j), 0x00000000);
2601 WREG32((0x2c24 + j), 0x00000000);
2602 }
2603 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
2604
2605 evergreen_mc_stop(rdev, &save);
2606 if (evergreen_mc_wait_for_idle(rdev)) {
2607 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
2608 }
2609 /* Lockout access through VGA aperture*/
2610 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
2611 /* Update configuration */
2612 if (rdev->flags & RADEON_IS_AGP) {
2613 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
2614 /* VRAM before AGP */
2615 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
2616 rdev->mc.vram_start >> 12);
2617 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
2618 rdev->mc.gtt_end >> 12);
2619 } else {
2620 /* VRAM after AGP */
2621 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
2622 rdev->mc.gtt_start >> 12);
2623 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
2624 rdev->mc.vram_end >> 12);
2625 }
2626 } else {
2627 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
2628 rdev->mc.vram_start >> 12);
2629 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
2630 rdev->mc.vram_end >> 12);
2631 }
Alex Deucher3b9832f2011-11-10 08:59:39 -05002632 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
Alex Deucher05b3ef62012-03-20 17:18:37 -04002633 /* llano/ontario only */
2634 if ((rdev->family == CHIP_PALM) ||
2635 (rdev->family == CHIP_SUMO) ||
2636 (rdev->family == CHIP_SUMO2)) {
Alex Deucherb4183e32010-12-15 11:04:10 -05002637 tmp = RREG32(MC_FUS_VM_FB_OFFSET) & 0x000FFFFF;
2638 tmp |= ((rdev->mc.vram_end >> 20) & 0xF) << 24;
2639 tmp |= ((rdev->mc.vram_start >> 20) & 0xF) << 20;
2640 WREG32(MC_FUS_VM_FB_OFFSET, tmp);
2641 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002642 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
2643 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
2644 WREG32(MC_VM_FB_LOCATION, tmp);
2645 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
Alex Deucherc46cb4d2011-01-06 19:12:37 -05002646 WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
Jerome Glisse46fcd2b2010-06-03 19:34:48 +02002647 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002648 if (rdev->flags & RADEON_IS_AGP) {
2649 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16);
2650 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16);
2651 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
2652 } else {
2653 WREG32(MC_VM_AGP_BASE, 0);
2654 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
2655 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
2656 }
2657 if (evergreen_mc_wait_for_idle(rdev)) {
2658 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
2659 }
2660 evergreen_mc_resume(rdev, &save);
2661 /* we need to own VRAM, so turn off the VGA renderer here
2662 * to stop it overwriting our objects */
2663 rv515_vga_render_disable(rdev);
2664}
2665
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002666/*
2667 * CP.
2668 */
Alex Deucher12920592011-02-02 12:37:40 -05002669void evergreen_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
2670{
Christian König876dc9f2012-05-08 14:24:01 +02002671 struct radeon_ring *ring = &rdev->ring[ib->ring];
Alex Deucher89d35802012-07-17 14:02:31 -04002672 u32 next_rptr;
Christian König7b1f2482011-09-23 15:11:23 +02002673
Alex Deucher12920592011-02-02 12:37:40 -05002674 /* set to DX10/11 mode */
Christian Könige32eb502011-10-23 12:56:27 +02002675 radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
2676 radeon_ring_write(ring, 1);
Christian König45df6802012-07-06 16:22:55 +02002677
2678 if (ring->rptr_save_reg) {
Alex Deucher89d35802012-07-17 14:02:31 -04002679 next_rptr = ring->wptr + 3 + 4;
Christian König45df6802012-07-06 16:22:55 +02002680 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2681 radeon_ring_write(ring, ((ring->rptr_save_reg -
2682 PACKET3_SET_CONFIG_REG_START) >> 2));
2683 radeon_ring_write(ring, next_rptr);
Alex Deucher89d35802012-07-17 14:02:31 -04002684 } else if (rdev->wb.enabled) {
2685 next_rptr = ring->wptr + 5 + 4;
2686 radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3));
2687 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
2688 radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18));
2689 radeon_ring_write(ring, next_rptr);
2690 radeon_ring_write(ring, 0);
Christian König45df6802012-07-06 16:22:55 +02002691 }
2692
Christian Könige32eb502011-10-23 12:56:27 +02002693 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
2694 radeon_ring_write(ring,
Alex Deucher0f234f5f2011-02-13 19:06:33 -05002695#ifdef __BIG_ENDIAN
2696 (2 << 0) |
2697#endif
2698 (ib->gpu_addr & 0xFFFFFFFC));
Christian Könige32eb502011-10-23 12:56:27 +02002699 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
2700 radeon_ring_write(ring, ib->length_dw);
Alex Deucher12920592011-02-02 12:37:40 -05002701}
2702
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002703
2704static int evergreen_cp_load_microcode(struct radeon_device *rdev)
2705{
Alex Deucherfe251e22010-03-24 13:36:43 -04002706 const __be32 *fw_data;
2707 int i;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002708
Alex Deucherfe251e22010-03-24 13:36:43 -04002709 if (!rdev->me_fw || !rdev->pfp_fw)
2710 return -EINVAL;
2711
2712 r700_cp_stop(rdev);
Alex Deucher0f234f5f2011-02-13 19:06:33 -05002713 WREG32(CP_RB_CNTL,
2714#ifdef __BIG_ENDIAN
2715 BUF_SWAP_32BIT |
2716#endif
2717 RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
Alex Deucherfe251e22010-03-24 13:36:43 -04002718
2719 fw_data = (const __be32 *)rdev->pfp_fw->data;
2720 WREG32(CP_PFP_UCODE_ADDR, 0);
2721 for (i = 0; i < EVERGREEN_PFP_UCODE_SIZE; i++)
2722 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
2723 WREG32(CP_PFP_UCODE_ADDR, 0);
2724
2725 fw_data = (const __be32 *)rdev->me_fw->data;
2726 WREG32(CP_ME_RAM_WADDR, 0);
2727 for (i = 0; i < EVERGREEN_PM4_UCODE_SIZE; i++)
2728 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
2729
2730 WREG32(CP_PFP_UCODE_ADDR, 0);
2731 WREG32(CP_ME_RAM_WADDR, 0);
2732 WREG32(CP_ME_RAM_RADDR, 0);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002733 return 0;
2734}
2735
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002736static int evergreen_cp_start(struct radeon_device *rdev)
2737{
Christian Könige32eb502011-10-23 12:56:27 +02002738 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher2281a372010-10-21 13:31:38 -04002739 int r, i;
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002740 uint32_t cp_me;
2741
Christian Könige32eb502011-10-23 12:56:27 +02002742 r = radeon_ring_lock(rdev, ring, 7);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002743 if (r) {
2744 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2745 return r;
2746 }
Christian Könige32eb502011-10-23 12:56:27 +02002747 radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
2748 radeon_ring_write(ring, 0x1);
2749 radeon_ring_write(ring, 0x0);
2750 radeon_ring_write(ring, rdev->config.evergreen.max_hw_contexts - 1);
2751 radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
2752 radeon_ring_write(ring, 0);
2753 radeon_ring_write(ring, 0);
2754 radeon_ring_unlock_commit(rdev, ring);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002755
2756 cp_me = 0xff;
2757 WREG32(CP_ME_CNTL, cp_me);
2758
Christian Könige32eb502011-10-23 12:56:27 +02002759 r = radeon_ring_lock(rdev, ring, evergreen_default_size + 19);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002760 if (r) {
2761 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2762 return r;
2763 }
Alex Deucher2281a372010-10-21 13:31:38 -04002764
2765 /* setup clear context state */
Christian Könige32eb502011-10-23 12:56:27 +02002766 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
2767 radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
Alex Deucher2281a372010-10-21 13:31:38 -04002768
2769 for (i = 0; i < evergreen_default_size; i++)
Christian Könige32eb502011-10-23 12:56:27 +02002770 radeon_ring_write(ring, evergreen_default_state[i]);
Alex Deucher2281a372010-10-21 13:31:38 -04002771
Christian Könige32eb502011-10-23 12:56:27 +02002772 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
2773 radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
Alex Deucher2281a372010-10-21 13:31:38 -04002774
2775 /* set clear context state */
Christian Könige32eb502011-10-23 12:56:27 +02002776 radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
2777 radeon_ring_write(ring, 0);
Alex Deucher2281a372010-10-21 13:31:38 -04002778
2779 /* SQ_VTX_BASE_VTX_LOC */
Christian Könige32eb502011-10-23 12:56:27 +02002780 radeon_ring_write(ring, 0xc0026f00);
2781 radeon_ring_write(ring, 0x00000000);
2782 radeon_ring_write(ring, 0x00000000);
2783 radeon_ring_write(ring, 0x00000000);
Alex Deucher2281a372010-10-21 13:31:38 -04002784
2785 /* Clear consts */
Christian Könige32eb502011-10-23 12:56:27 +02002786 radeon_ring_write(ring, 0xc0036f00);
2787 radeon_ring_write(ring, 0x00000bc4);
2788 radeon_ring_write(ring, 0xffffffff);
2789 radeon_ring_write(ring, 0xffffffff);
2790 radeon_ring_write(ring, 0xffffffff);
Alex Deucher2281a372010-10-21 13:31:38 -04002791
Christian Könige32eb502011-10-23 12:56:27 +02002792 radeon_ring_write(ring, 0xc0026900);
2793 radeon_ring_write(ring, 0x00000316);
2794 radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
2795 radeon_ring_write(ring, 0x00000010); /* */
Alex Deucher18ff84d2011-02-02 12:37:41 -05002796
Christian Könige32eb502011-10-23 12:56:27 +02002797 radeon_ring_unlock_commit(rdev, ring);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002798
2799 return 0;
2800}
2801
Lauri Kasanen1109ca02012-08-31 13:43:50 -04002802static int evergreen_cp_resume(struct radeon_device *rdev)
Alex Deucherfe251e22010-03-24 13:36:43 -04002803{
Christian Könige32eb502011-10-23 12:56:27 +02002804 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucherfe251e22010-03-24 13:36:43 -04002805 u32 tmp;
2806 u32 rb_bufsz;
2807 int r;
2808
2809 /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
2810 WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
2811 SOFT_RESET_PA |
2812 SOFT_RESET_SH |
2813 SOFT_RESET_VGT |
Jerome Glissea49a50d2011-08-24 20:00:17 +00002814 SOFT_RESET_SPI |
Alex Deucherfe251e22010-03-24 13:36:43 -04002815 SOFT_RESET_SX));
2816 RREG32(GRBM_SOFT_RESET);
2817 mdelay(15);
2818 WREG32(GRBM_SOFT_RESET, 0);
2819 RREG32(GRBM_SOFT_RESET);
2820
2821 /* Set ring buffer size */
Christian Könige32eb502011-10-23 12:56:27 +02002822 rb_bufsz = drm_order(ring->ring_size / 8);
Alex Deucher724c80e2010-08-27 18:25:25 -04002823 tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Alex Deucherfe251e22010-03-24 13:36:43 -04002824#ifdef __BIG_ENDIAN
2825 tmp |= BUF_SWAP_32BIT;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002826#endif
Alex Deucherfe251e22010-03-24 13:36:43 -04002827 WREG32(CP_RB_CNTL, tmp);
Christian König15d33322011-09-15 19:02:22 +02002828 WREG32(CP_SEM_WAIT_TIMER, 0x0);
Alex Deucher11ef3f1f2012-01-20 14:47:43 -05002829 WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
Alex Deucherfe251e22010-03-24 13:36:43 -04002830
2831 /* Set the write pointer delay */
2832 WREG32(CP_RB_WPTR_DELAY, 0);
2833
2834 /* Initialize the ring buffer's read and write pointers */
2835 WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
2836 WREG32(CP_RB_RPTR_WR, 0);
Christian Könige32eb502011-10-23 12:56:27 +02002837 ring->wptr = 0;
2838 WREG32(CP_RB_WPTR, ring->wptr);
Alex Deucher724c80e2010-08-27 18:25:25 -04002839
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04002840 /* set the wb address whether it's enabled or not */
Alex Deucher0f234f5f2011-02-13 19:06:33 -05002841 WREG32(CP_RB_RPTR_ADDR,
Alex Deucher0f234f5f2011-02-13 19:06:33 -05002842 ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
Alex Deucher724c80e2010-08-27 18:25:25 -04002843 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
2844 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
2845
2846 if (rdev->wb.enabled)
2847 WREG32(SCRATCH_UMSK, 0xff);
2848 else {
2849 tmp |= RB_NO_UPDATE;
2850 WREG32(SCRATCH_UMSK, 0);
2851 }
2852
Alex Deucherfe251e22010-03-24 13:36:43 -04002853 mdelay(1);
2854 WREG32(CP_RB_CNTL, tmp);
2855
Christian Könige32eb502011-10-23 12:56:27 +02002856 WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
Alex Deucherfe251e22010-03-24 13:36:43 -04002857 WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
2858
Christian Könige32eb502011-10-23 12:56:27 +02002859 ring->rptr = RREG32(CP_RB_RPTR);
Alex Deucherfe251e22010-03-24 13:36:43 -04002860
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002861 evergreen_cp_start(rdev);
Christian Könige32eb502011-10-23 12:56:27 +02002862 ring->ready = true;
Alex Deucherf7128122012-02-23 17:53:45 -05002863 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
Alex Deucherfe251e22010-03-24 13:36:43 -04002864 if (r) {
Christian Könige32eb502011-10-23 12:56:27 +02002865 ring->ready = false;
Alex Deucherfe251e22010-03-24 13:36:43 -04002866 return r;
2867 }
2868 return 0;
2869}
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002870
2871/*
2872 * Core functions
2873 */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002874static void evergreen_gpu_init(struct radeon_device *rdev)
2875{
Alex Deucher416a2bd2012-05-31 19:00:25 -04002876 u32 gb_addr_config;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002877 u32 mc_shared_chmap, mc_arb_ramcfg;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002878 u32 sx_debug_1;
2879 u32 smx_dc_ctl0;
2880 u32 sq_config;
2881 u32 sq_lds_resource_mgmt;
2882 u32 sq_gpr_resource_mgmt_1;
2883 u32 sq_gpr_resource_mgmt_2;
2884 u32 sq_gpr_resource_mgmt_3;
2885 u32 sq_thread_resource_mgmt;
2886 u32 sq_thread_resource_mgmt_2;
2887 u32 sq_stack_resource_mgmt_1;
2888 u32 sq_stack_resource_mgmt_2;
2889 u32 sq_stack_resource_mgmt_3;
2890 u32 vgt_cache_invalidation;
Alex Deucherf25a5c62011-05-19 11:07:57 -04002891 u32 hdp_host_path_cntl, tmp;
Alex Deucher416a2bd2012-05-31 19:00:25 -04002892 u32 disabled_rb_mask;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002893 int i, j, num_shader_engines, ps_thread_count;
2894
2895 switch (rdev->family) {
2896 case CHIP_CYPRESS:
2897 case CHIP_HEMLOCK:
2898 rdev->config.evergreen.num_ses = 2;
2899 rdev->config.evergreen.max_pipes = 4;
2900 rdev->config.evergreen.max_tile_pipes = 8;
2901 rdev->config.evergreen.max_simds = 10;
2902 rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
2903 rdev->config.evergreen.max_gprs = 256;
2904 rdev->config.evergreen.max_threads = 248;
2905 rdev->config.evergreen.max_gs_threads = 32;
2906 rdev->config.evergreen.max_stack_entries = 512;
2907 rdev->config.evergreen.sx_num_of_sets = 4;
2908 rdev->config.evergreen.sx_max_export_size = 256;
2909 rdev->config.evergreen.sx_max_export_pos_size = 64;
2910 rdev->config.evergreen.sx_max_export_smx_size = 192;
2911 rdev->config.evergreen.max_hw_contexts = 8;
2912 rdev->config.evergreen.sq_num_cf_insts = 2;
2913
2914 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
2915 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
2916 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04002917 gb_addr_config = CYPRESS_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002918 break;
2919 case CHIP_JUNIPER:
2920 rdev->config.evergreen.num_ses = 1;
2921 rdev->config.evergreen.max_pipes = 4;
2922 rdev->config.evergreen.max_tile_pipes = 4;
2923 rdev->config.evergreen.max_simds = 10;
2924 rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
2925 rdev->config.evergreen.max_gprs = 256;
2926 rdev->config.evergreen.max_threads = 248;
2927 rdev->config.evergreen.max_gs_threads = 32;
2928 rdev->config.evergreen.max_stack_entries = 512;
2929 rdev->config.evergreen.sx_num_of_sets = 4;
2930 rdev->config.evergreen.sx_max_export_size = 256;
2931 rdev->config.evergreen.sx_max_export_pos_size = 64;
2932 rdev->config.evergreen.sx_max_export_smx_size = 192;
2933 rdev->config.evergreen.max_hw_contexts = 8;
2934 rdev->config.evergreen.sq_num_cf_insts = 2;
2935
2936 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
2937 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
2938 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04002939 gb_addr_config = JUNIPER_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002940 break;
2941 case CHIP_REDWOOD:
2942 rdev->config.evergreen.num_ses = 1;
2943 rdev->config.evergreen.max_pipes = 4;
2944 rdev->config.evergreen.max_tile_pipes = 4;
2945 rdev->config.evergreen.max_simds = 5;
2946 rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
2947 rdev->config.evergreen.max_gprs = 256;
2948 rdev->config.evergreen.max_threads = 248;
2949 rdev->config.evergreen.max_gs_threads = 32;
2950 rdev->config.evergreen.max_stack_entries = 256;
2951 rdev->config.evergreen.sx_num_of_sets = 4;
2952 rdev->config.evergreen.sx_max_export_size = 256;
2953 rdev->config.evergreen.sx_max_export_pos_size = 64;
2954 rdev->config.evergreen.sx_max_export_smx_size = 192;
2955 rdev->config.evergreen.max_hw_contexts = 8;
2956 rdev->config.evergreen.sq_num_cf_insts = 2;
2957
2958 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
2959 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
2960 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04002961 gb_addr_config = REDWOOD_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002962 break;
2963 case CHIP_CEDAR:
2964 default:
2965 rdev->config.evergreen.num_ses = 1;
2966 rdev->config.evergreen.max_pipes = 2;
2967 rdev->config.evergreen.max_tile_pipes = 2;
2968 rdev->config.evergreen.max_simds = 2;
2969 rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
2970 rdev->config.evergreen.max_gprs = 256;
2971 rdev->config.evergreen.max_threads = 192;
2972 rdev->config.evergreen.max_gs_threads = 16;
2973 rdev->config.evergreen.max_stack_entries = 256;
2974 rdev->config.evergreen.sx_num_of_sets = 4;
2975 rdev->config.evergreen.sx_max_export_size = 128;
2976 rdev->config.evergreen.sx_max_export_pos_size = 32;
2977 rdev->config.evergreen.sx_max_export_smx_size = 96;
2978 rdev->config.evergreen.max_hw_contexts = 4;
2979 rdev->config.evergreen.sq_num_cf_insts = 1;
2980
2981 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
2982 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
2983 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04002984 gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002985 break;
Alex Deucherd5e455e2010-11-22 17:56:29 -05002986 case CHIP_PALM:
2987 rdev->config.evergreen.num_ses = 1;
2988 rdev->config.evergreen.max_pipes = 2;
2989 rdev->config.evergreen.max_tile_pipes = 2;
2990 rdev->config.evergreen.max_simds = 2;
2991 rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
2992 rdev->config.evergreen.max_gprs = 256;
2993 rdev->config.evergreen.max_threads = 192;
2994 rdev->config.evergreen.max_gs_threads = 16;
2995 rdev->config.evergreen.max_stack_entries = 256;
2996 rdev->config.evergreen.sx_num_of_sets = 4;
2997 rdev->config.evergreen.sx_max_export_size = 128;
2998 rdev->config.evergreen.sx_max_export_pos_size = 32;
2999 rdev->config.evergreen.sx_max_export_smx_size = 96;
3000 rdev->config.evergreen.max_hw_contexts = 4;
3001 rdev->config.evergreen.sq_num_cf_insts = 1;
3002
3003 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
3004 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
3005 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04003006 gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
Alex Deucherd5e455e2010-11-22 17:56:29 -05003007 break;
Alex Deucherd5c5a722011-05-31 15:42:48 -04003008 case CHIP_SUMO:
3009 rdev->config.evergreen.num_ses = 1;
3010 rdev->config.evergreen.max_pipes = 4;
Jerome Glissebd25f072012-12-11 11:56:52 -05003011 rdev->config.evergreen.max_tile_pipes = 4;
Alex Deucherd5c5a722011-05-31 15:42:48 -04003012 if (rdev->pdev->device == 0x9648)
3013 rdev->config.evergreen.max_simds = 3;
3014 else if ((rdev->pdev->device == 0x9647) ||
3015 (rdev->pdev->device == 0x964a))
3016 rdev->config.evergreen.max_simds = 4;
3017 else
3018 rdev->config.evergreen.max_simds = 5;
3019 rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
3020 rdev->config.evergreen.max_gprs = 256;
3021 rdev->config.evergreen.max_threads = 248;
3022 rdev->config.evergreen.max_gs_threads = 32;
3023 rdev->config.evergreen.max_stack_entries = 256;
3024 rdev->config.evergreen.sx_num_of_sets = 4;
3025 rdev->config.evergreen.sx_max_export_size = 256;
3026 rdev->config.evergreen.sx_max_export_pos_size = 64;
3027 rdev->config.evergreen.sx_max_export_smx_size = 192;
3028 rdev->config.evergreen.max_hw_contexts = 8;
3029 rdev->config.evergreen.sq_num_cf_insts = 2;
3030
3031 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
3032 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
3033 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Jerome Glissebd25f072012-12-11 11:56:52 -05003034 gb_addr_config = SUMO_GB_ADDR_CONFIG_GOLDEN;
Alex Deucherd5c5a722011-05-31 15:42:48 -04003035 break;
3036 case CHIP_SUMO2:
3037 rdev->config.evergreen.num_ses = 1;
3038 rdev->config.evergreen.max_pipes = 4;
3039 rdev->config.evergreen.max_tile_pipes = 4;
3040 rdev->config.evergreen.max_simds = 2;
3041 rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
3042 rdev->config.evergreen.max_gprs = 256;
3043 rdev->config.evergreen.max_threads = 248;
3044 rdev->config.evergreen.max_gs_threads = 32;
3045 rdev->config.evergreen.max_stack_entries = 512;
3046 rdev->config.evergreen.sx_num_of_sets = 4;
3047 rdev->config.evergreen.sx_max_export_size = 256;
3048 rdev->config.evergreen.sx_max_export_pos_size = 64;
3049 rdev->config.evergreen.sx_max_export_smx_size = 192;
3050 rdev->config.evergreen.max_hw_contexts = 8;
3051 rdev->config.evergreen.sq_num_cf_insts = 2;
3052
3053 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
3054 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
3055 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Jerome Glissebd25f072012-12-11 11:56:52 -05003056 gb_addr_config = SUMO2_GB_ADDR_CONFIG_GOLDEN;
Alex Deucherd5c5a722011-05-31 15:42:48 -04003057 break;
Alex Deucheradb68fa2011-01-06 21:19:24 -05003058 case CHIP_BARTS:
3059 rdev->config.evergreen.num_ses = 2;
3060 rdev->config.evergreen.max_pipes = 4;
3061 rdev->config.evergreen.max_tile_pipes = 8;
3062 rdev->config.evergreen.max_simds = 7;
3063 rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
3064 rdev->config.evergreen.max_gprs = 256;
3065 rdev->config.evergreen.max_threads = 248;
3066 rdev->config.evergreen.max_gs_threads = 32;
3067 rdev->config.evergreen.max_stack_entries = 512;
3068 rdev->config.evergreen.sx_num_of_sets = 4;
3069 rdev->config.evergreen.sx_max_export_size = 256;
3070 rdev->config.evergreen.sx_max_export_pos_size = 64;
3071 rdev->config.evergreen.sx_max_export_smx_size = 192;
3072 rdev->config.evergreen.max_hw_contexts = 8;
3073 rdev->config.evergreen.sq_num_cf_insts = 2;
3074
3075 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
3076 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
3077 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04003078 gb_addr_config = BARTS_GB_ADDR_CONFIG_GOLDEN;
Alex Deucheradb68fa2011-01-06 21:19:24 -05003079 break;
3080 case CHIP_TURKS:
3081 rdev->config.evergreen.num_ses = 1;
3082 rdev->config.evergreen.max_pipes = 4;
3083 rdev->config.evergreen.max_tile_pipes = 4;
3084 rdev->config.evergreen.max_simds = 6;
3085 rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
3086 rdev->config.evergreen.max_gprs = 256;
3087 rdev->config.evergreen.max_threads = 248;
3088 rdev->config.evergreen.max_gs_threads = 32;
3089 rdev->config.evergreen.max_stack_entries = 256;
3090 rdev->config.evergreen.sx_num_of_sets = 4;
3091 rdev->config.evergreen.sx_max_export_size = 256;
3092 rdev->config.evergreen.sx_max_export_pos_size = 64;
3093 rdev->config.evergreen.sx_max_export_smx_size = 192;
3094 rdev->config.evergreen.max_hw_contexts = 8;
3095 rdev->config.evergreen.sq_num_cf_insts = 2;
3096
3097 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
3098 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
3099 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04003100 gb_addr_config = TURKS_GB_ADDR_CONFIG_GOLDEN;
Alex Deucheradb68fa2011-01-06 21:19:24 -05003101 break;
3102 case CHIP_CAICOS:
3103 rdev->config.evergreen.num_ses = 1;
Jerome Glissebd25f072012-12-11 11:56:52 -05003104 rdev->config.evergreen.max_pipes = 2;
Alex Deucheradb68fa2011-01-06 21:19:24 -05003105 rdev->config.evergreen.max_tile_pipes = 2;
3106 rdev->config.evergreen.max_simds = 2;
3107 rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
3108 rdev->config.evergreen.max_gprs = 256;
3109 rdev->config.evergreen.max_threads = 192;
3110 rdev->config.evergreen.max_gs_threads = 16;
3111 rdev->config.evergreen.max_stack_entries = 256;
3112 rdev->config.evergreen.sx_num_of_sets = 4;
3113 rdev->config.evergreen.sx_max_export_size = 128;
3114 rdev->config.evergreen.sx_max_export_pos_size = 32;
3115 rdev->config.evergreen.sx_max_export_smx_size = 96;
3116 rdev->config.evergreen.max_hw_contexts = 4;
3117 rdev->config.evergreen.sq_num_cf_insts = 1;
3118
3119 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
3120 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
3121 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04003122 gb_addr_config = CAICOS_GB_ADDR_CONFIG_GOLDEN;
Alex Deucheradb68fa2011-01-06 21:19:24 -05003123 break;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003124 }
3125
3126 /* Initialize HDP */
3127 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
3128 WREG32((0x2c14 + j), 0x00000000);
3129 WREG32((0x2c18 + j), 0x00000000);
3130 WREG32((0x2c1c + j), 0x00000000);
3131 WREG32((0x2c20 + j), 0x00000000);
3132 WREG32((0x2c24 + j), 0x00000000);
3133 }
3134
3135 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
3136
Alex Deucherd054ac12011-09-01 17:46:15 +00003137 evergreen_fix_pci_max_read_req_size(rdev);
3138
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003139 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
Alex Deucher05b3ef62012-03-20 17:18:37 -04003140 if ((rdev->family == CHIP_PALM) ||
3141 (rdev->family == CHIP_SUMO) ||
3142 (rdev->family == CHIP_SUMO2))
Alex Deucherd9282fc2011-05-11 03:15:24 -04003143 mc_arb_ramcfg = RREG32(FUS_MC_ARB_RAMCFG);
3144 else
3145 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003146
Alex Deucher1aa52bd2010-11-17 12:11:03 -05003147 /* setup tiling info dword. gb_addr_config is not adequate since it does
3148 * not have bank info, so create a custom tiling dword.
3149 * bits 3:0 num_pipes
3150 * bits 7:4 num_banks
3151 * bits 11:8 group_size
3152 * bits 15:12 row_size
3153 */
3154 rdev->config.evergreen.tile_config = 0;
3155 switch (rdev->config.evergreen.max_tile_pipes) {
3156 case 1:
3157 default:
3158 rdev->config.evergreen.tile_config |= (0 << 0);
3159 break;
3160 case 2:
3161 rdev->config.evergreen.tile_config |= (1 << 0);
3162 break;
3163 case 4:
3164 rdev->config.evergreen.tile_config |= (2 << 0);
3165 break;
3166 case 8:
3167 rdev->config.evergreen.tile_config |= (3 << 0);
3168 break;
3169 }
Alex Deucherd698a342011-06-23 00:49:29 -04003170 /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
Alex Deucher5bfa4872011-05-20 12:35:22 -04003171 if (rdev->flags & RADEON_IS_IGP)
Alex Deucherd698a342011-06-23 00:49:29 -04003172 rdev->config.evergreen.tile_config |= 1 << 4;
Alex Deucher29d65402012-05-31 18:53:36 -04003173 else {
Alex Deucherc8d15ed2012-07-31 11:01:10 -04003174 switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
3175 case 0: /* four banks */
Alex Deucher29d65402012-05-31 18:53:36 -04003176 rdev->config.evergreen.tile_config |= 0 << 4;
Alex Deucherc8d15ed2012-07-31 11:01:10 -04003177 break;
3178 case 1: /* eight banks */
3179 rdev->config.evergreen.tile_config |= 1 << 4;
3180 break;
3181 case 2: /* sixteen banks */
3182 default:
3183 rdev->config.evergreen.tile_config |= 2 << 4;
3184 break;
3185 }
Alex Deucher29d65402012-05-31 18:53:36 -04003186 }
Alex Deucher416a2bd2012-05-31 19:00:25 -04003187 rdev->config.evergreen.tile_config |= 0 << 8;
Alex Deucher1aa52bd2010-11-17 12:11:03 -05003188 rdev->config.evergreen.tile_config |=
3189 ((gb_addr_config & 0x30000000) >> 28) << 12;
3190
Alex Deucher416a2bd2012-05-31 19:00:25 -04003191 num_shader_engines = (gb_addr_config & NUM_SHADER_ENGINES(3) >> 12) + 1;
3192
3193 if ((rdev->family >= CHIP_CEDAR) && (rdev->family <= CHIP_HEMLOCK)) {
3194 u32 efuse_straps_4;
3195 u32 efuse_straps_3;
3196
3197 WREG32(RCU_IND_INDEX, 0x204);
3198 efuse_straps_4 = RREG32(RCU_IND_DATA);
3199 WREG32(RCU_IND_INDEX, 0x203);
3200 efuse_straps_3 = RREG32(RCU_IND_DATA);
3201 tmp = (((efuse_straps_4 & 0xf) << 4) |
3202 ((efuse_straps_3 & 0xf0000000) >> 28));
3203 } else {
3204 tmp = 0;
3205 for (i = (rdev->config.evergreen.num_ses - 1); i >= 0; i--) {
3206 u32 rb_disable_bitmap;
3207
3208 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
3209 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
3210 rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16;
3211 tmp <<= 4;
3212 tmp |= rb_disable_bitmap;
3213 }
3214 }
3215 /* enabled rb are just the one not disabled :) */
3216 disabled_rb_mask = tmp;
Alex Deuchercedb6552013-04-09 10:13:22 -04003217 tmp = 0;
3218 for (i = 0; i < rdev->config.evergreen.max_backends; i++)
3219 tmp |= (1 << i);
3220 /* if all the backends are disabled, fix it up here */
3221 if ((disabled_rb_mask & tmp) == tmp) {
3222 for (i = 0; i < rdev->config.evergreen.max_backends; i++)
3223 disabled_rb_mask &= ~(1 << i);
3224 }
Alex Deucher416a2bd2012-05-31 19:00:25 -04003225
3226 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
3227 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
3228
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003229 WREG32(GB_ADDR_CONFIG, gb_addr_config);
3230 WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
3231 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
Alex Deucher233d1ad2012-12-04 15:25:59 -05003232 WREG32(DMA_TILING_CONFIG, gb_addr_config);
Christian König9a210592013-04-08 12:41:37 +02003233 WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
3234 WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
3235 WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003236
Alex Deucherf7eb9732013-01-30 13:57:40 -05003237 if ((rdev->config.evergreen.max_backends == 1) &&
3238 (rdev->flags & RADEON_IS_IGP)) {
3239 if ((disabled_rb_mask & 3) == 1) {
3240 /* RB0 disabled, RB1 enabled */
3241 tmp = 0x11111111;
3242 } else {
3243 /* RB1 disabled, RB0 enabled */
3244 tmp = 0x00000000;
3245 }
3246 } else {
3247 tmp = gb_addr_config & NUM_PIPES_MASK;
3248 tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.evergreen.max_backends,
3249 EVERGREEN_MAX_BACKENDS, disabled_rb_mask);
3250 }
Alex Deucher416a2bd2012-05-31 19:00:25 -04003251 WREG32(GB_BACKEND_MAP, tmp);
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003252
3253 WREG32(CGTS_SYS_TCC_DISABLE, 0);
3254 WREG32(CGTS_TCC_DISABLE, 0);
3255 WREG32(CGTS_USER_SYS_TCC_DISABLE, 0);
3256 WREG32(CGTS_USER_TCC_DISABLE, 0);
3257
3258 /* set HW defaults for 3D engine */
3259 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
3260 ROQ_IB2_START(0x2b)));
3261
3262 WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30));
3263
3264 WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO |
3265 SYNC_GRADIENT |
3266 SYNC_WALKER |
3267 SYNC_ALIGNER));
3268
3269 sx_debug_1 = RREG32(SX_DEBUG_1);
3270 sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
3271 WREG32(SX_DEBUG_1, sx_debug_1);
3272
3273
3274 smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
3275 smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff);
3276 smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.evergreen.sx_num_of_sets);
3277 WREG32(SMX_DC_CTL0, smx_dc_ctl0);
3278
Alex Deucherb866d132012-06-14 22:06:36 +02003279 if (rdev->family <= CHIP_SUMO2)
3280 WREG32(SMX_SAR_CTL0, 0x00010000);
3281
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003282 WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_size / 4) - 1) |
3283 POSITION_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_pos_size / 4) - 1) |
3284 SMX_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_smx_size / 4) - 1)));
3285
3286 WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.evergreen.sc_prim_fifo_size) |
3287 SC_HIZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_hiz_tile_fifo_size) |
3288 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_earlyz_tile_fifo_size)));
3289
3290 WREG32(VGT_NUM_INSTANCES, 1);
3291 WREG32(SPI_CONFIG_CNTL, 0);
3292 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
3293 WREG32(CP_PERFMON_CNTL, 0);
3294
3295 WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.evergreen.sq_num_cf_insts) |
3296 FETCH_FIFO_HIWATER(0x4) |
3297 DONE_FIFO_HIWATER(0xe0) |
3298 ALU_UPDATE_FIFO_HIWATER(0x8)));
3299
3300 sq_config = RREG32(SQ_CONFIG);
3301 sq_config &= ~(PS_PRIO(3) |
3302 VS_PRIO(3) |
3303 GS_PRIO(3) |
3304 ES_PRIO(3));
3305 sq_config |= (VC_ENABLE |
3306 EXPORT_SRC_C |
3307 PS_PRIO(0) |
3308 VS_PRIO(1) |
3309 GS_PRIO(2) |
3310 ES_PRIO(3));
3311
Alex Deucherd5e455e2010-11-22 17:56:29 -05003312 switch (rdev->family) {
3313 case CHIP_CEDAR:
3314 case CHIP_PALM:
Alex Deucherd5c5a722011-05-31 15:42:48 -04003315 case CHIP_SUMO:
3316 case CHIP_SUMO2:
Alex Deucheradb68fa2011-01-06 21:19:24 -05003317 case CHIP_CAICOS:
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003318 /* no vertex cache */
3319 sq_config &= ~VC_ENABLE;
Alex Deucherd5e455e2010-11-22 17:56:29 -05003320 break;
3321 default:
3322 break;
3323 }
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003324
3325 sq_lds_resource_mgmt = RREG32(SQ_LDS_RESOURCE_MGMT);
3326
3327 sq_gpr_resource_mgmt_1 = NUM_PS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2))* 12 / 32);
3328 sq_gpr_resource_mgmt_1 |= NUM_VS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 6 / 32);
3329 sq_gpr_resource_mgmt_1 |= NUM_CLAUSE_TEMP_GPRS(4);
3330 sq_gpr_resource_mgmt_2 = NUM_GS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
3331 sq_gpr_resource_mgmt_2 |= NUM_ES_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
3332 sq_gpr_resource_mgmt_3 = NUM_HS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
3333 sq_gpr_resource_mgmt_3 |= NUM_LS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
3334
Alex Deucherd5e455e2010-11-22 17:56:29 -05003335 switch (rdev->family) {
3336 case CHIP_CEDAR:
3337 case CHIP_PALM:
Alex Deucherd5c5a722011-05-31 15:42:48 -04003338 case CHIP_SUMO:
3339 case CHIP_SUMO2:
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003340 ps_thread_count = 96;
Alex Deucherd5e455e2010-11-22 17:56:29 -05003341 break;
3342 default:
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003343 ps_thread_count = 128;
Alex Deucherd5e455e2010-11-22 17:56:29 -05003344 break;
3345 }
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003346
3347 sq_thread_resource_mgmt = NUM_PS_THREADS(ps_thread_count);
Alex Deucherf96b35c2010-06-16 12:24:07 -04003348 sq_thread_resource_mgmt |= NUM_VS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
3349 sq_thread_resource_mgmt |= NUM_GS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
3350 sq_thread_resource_mgmt |= NUM_ES_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
3351 sq_thread_resource_mgmt_2 = NUM_HS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
3352 sq_thread_resource_mgmt_2 |= NUM_LS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003353
3354 sq_stack_resource_mgmt_1 = NUM_PS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
3355 sq_stack_resource_mgmt_1 |= NUM_VS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
3356 sq_stack_resource_mgmt_2 = NUM_GS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
3357 sq_stack_resource_mgmt_2 |= NUM_ES_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
3358 sq_stack_resource_mgmt_3 = NUM_HS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
3359 sq_stack_resource_mgmt_3 |= NUM_LS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
3360
3361 WREG32(SQ_CONFIG, sq_config);
3362 WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
3363 WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
3364 WREG32(SQ_GPR_RESOURCE_MGMT_3, sq_gpr_resource_mgmt_3);
3365 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
3366 WREG32(SQ_THREAD_RESOURCE_MGMT_2, sq_thread_resource_mgmt_2);
3367 WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
3368 WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
3369 WREG32(SQ_STACK_RESOURCE_MGMT_3, sq_stack_resource_mgmt_3);
3370 WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0);
3371 WREG32(SQ_LDS_RESOURCE_MGMT, sq_lds_resource_mgmt);
3372
3373 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
3374 FORCE_EOV_MAX_REZ_CNT(255)));
3375
Alex Deucherd5e455e2010-11-22 17:56:29 -05003376 switch (rdev->family) {
3377 case CHIP_CEDAR:
3378 case CHIP_PALM:
Alex Deucherd5c5a722011-05-31 15:42:48 -04003379 case CHIP_SUMO:
3380 case CHIP_SUMO2:
Alex Deucheradb68fa2011-01-06 21:19:24 -05003381 case CHIP_CAICOS:
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003382 vgt_cache_invalidation = CACHE_INVALIDATION(TC_ONLY);
Alex Deucherd5e455e2010-11-22 17:56:29 -05003383 break;
3384 default:
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003385 vgt_cache_invalidation = CACHE_INVALIDATION(VC_AND_TC);
Alex Deucherd5e455e2010-11-22 17:56:29 -05003386 break;
3387 }
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003388 vgt_cache_invalidation |= AUTO_INVLD_EN(ES_AND_GS_AUTO);
3389 WREG32(VGT_CACHE_INVALIDATION, vgt_cache_invalidation);
3390
3391 WREG32(VGT_GS_VERTEX_REUSE, 16);
Alex Deucher12920592011-02-02 12:37:40 -05003392 WREG32(PA_SU_LINE_STIPPLE_VALUE, 0);
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003393 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
3394
Alex Deucher60a4a3e2010-06-29 17:03:35 -04003395 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, 14);
3396 WREG32(VGT_OUT_DEALLOC_CNTL, 16);
3397
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003398 WREG32(CB_PERF_CTR0_SEL_0, 0);
3399 WREG32(CB_PERF_CTR0_SEL_1, 0);
3400 WREG32(CB_PERF_CTR1_SEL_0, 0);
3401 WREG32(CB_PERF_CTR1_SEL_1, 0);
3402 WREG32(CB_PERF_CTR2_SEL_0, 0);
3403 WREG32(CB_PERF_CTR2_SEL_1, 0);
3404 WREG32(CB_PERF_CTR3_SEL_0, 0);
3405 WREG32(CB_PERF_CTR3_SEL_1, 0);
3406
Alex Deucher60a4a3e2010-06-29 17:03:35 -04003407 /* clear render buffer base addresses */
3408 WREG32(CB_COLOR0_BASE, 0);
3409 WREG32(CB_COLOR1_BASE, 0);
3410 WREG32(CB_COLOR2_BASE, 0);
3411 WREG32(CB_COLOR3_BASE, 0);
3412 WREG32(CB_COLOR4_BASE, 0);
3413 WREG32(CB_COLOR5_BASE, 0);
3414 WREG32(CB_COLOR6_BASE, 0);
3415 WREG32(CB_COLOR7_BASE, 0);
3416 WREG32(CB_COLOR8_BASE, 0);
3417 WREG32(CB_COLOR9_BASE, 0);
3418 WREG32(CB_COLOR10_BASE, 0);
3419 WREG32(CB_COLOR11_BASE, 0);
3420
3421 /* set the shader const cache sizes to 0 */
3422 for (i = SQ_ALU_CONST_BUFFER_SIZE_PS_0; i < 0x28200; i += 4)
3423 WREG32(i, 0);
3424 for (i = SQ_ALU_CONST_BUFFER_SIZE_HS_0; i < 0x29000; i += 4)
3425 WREG32(i, 0);
3426
Alex Deucherf25a5c62011-05-19 11:07:57 -04003427 tmp = RREG32(HDP_MISC_CNTL);
3428 tmp |= HDP_FLUSH_INVALIDATE_CACHE;
3429 WREG32(HDP_MISC_CNTL, tmp);
3430
Alex Deucher32fcdbf2010-03-24 13:33:47 -04003431 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
3432 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
3433
3434 WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
3435
3436 udelay(50);
3437
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003438}
3439
3440int evergreen_mc_init(struct radeon_device *rdev)
3441{
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003442 u32 tmp;
3443 int chansize, numchan;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003444
3445 /* Get VRAM informations */
3446 rdev->mc.vram_is_ddr = true;
Alex Deucher05b3ef62012-03-20 17:18:37 -04003447 if ((rdev->family == CHIP_PALM) ||
3448 (rdev->family == CHIP_SUMO) ||
3449 (rdev->family == CHIP_SUMO2))
Alex Deucher82084412011-07-01 13:18:28 -04003450 tmp = RREG32(FUS_MC_ARB_RAMCFG);
3451 else
3452 tmp = RREG32(MC_ARB_RAMCFG);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003453 if (tmp & CHANSIZE_OVERRIDE) {
3454 chansize = 16;
3455 } else if (tmp & CHANSIZE_MASK) {
3456 chansize = 64;
3457 } else {
3458 chansize = 32;
3459 }
3460 tmp = RREG32(MC_SHARED_CHMAP);
3461 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
3462 case 0:
3463 default:
3464 numchan = 1;
3465 break;
3466 case 1:
3467 numchan = 2;
3468 break;
3469 case 2:
3470 numchan = 4;
3471 break;
3472 case 3:
3473 numchan = 8;
3474 break;
3475 }
3476 rdev->mc.vram_width = numchan * chansize;
3477 /* Could aper size report 0 ? */
Jordan Crouse01d73a62010-05-27 13:40:24 -06003478 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
3479 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003480 /* Setup GPU memory space */
Alex Deucher05b3ef62012-03-20 17:18:37 -04003481 if ((rdev->family == CHIP_PALM) ||
3482 (rdev->family == CHIP_SUMO) ||
3483 (rdev->family == CHIP_SUMO2)) {
Alex Deucher6eb18f82010-11-22 17:56:27 -05003484 /* size in bytes on fusion */
3485 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
3486 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
3487 } else {
Alex Deucher05b3ef62012-03-20 17:18:37 -04003488 /* size in MB on evergreen/cayman/tn */
Alex Deucher6eb18f82010-11-22 17:56:27 -05003489 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024;
3490 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024;
3491 }
Jerome Glisse51e5fcd2010-02-19 14:33:54 +00003492 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Alex Deucher0ef0c1f2010-11-22 17:56:26 -05003493 r700_vram_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -04003494 radeon_update_bandwidth_info(rdev);
3495
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003496 return 0;
3497}
Jerome Glissed594e462010-02-17 21:54:29 +00003498
Alex Deucher187e3592013-01-18 14:51:38 -05003499void evergreen_print_gpu_status_regs(struct radeon_device *rdev)
Alex Deucher747943e2010-03-24 13:26:36 -04003500{
Jerome Glisse64c56e82013-01-02 17:30:35 -05003501 dev_info(rdev->dev, " GRBM_STATUS = 0x%08X\n",
Alex Deucher747943e2010-03-24 13:26:36 -04003502 RREG32(GRBM_STATUS));
Jerome Glisse64c56e82013-01-02 17:30:35 -05003503 dev_info(rdev->dev, " GRBM_STATUS_SE0 = 0x%08X\n",
Alex Deucher747943e2010-03-24 13:26:36 -04003504 RREG32(GRBM_STATUS_SE0));
Jerome Glisse64c56e82013-01-02 17:30:35 -05003505 dev_info(rdev->dev, " GRBM_STATUS_SE1 = 0x%08X\n",
Alex Deucher747943e2010-03-24 13:26:36 -04003506 RREG32(GRBM_STATUS_SE1));
Jerome Glisse64c56e82013-01-02 17:30:35 -05003507 dev_info(rdev->dev, " SRBM_STATUS = 0x%08X\n",
Alex Deucher747943e2010-03-24 13:26:36 -04003508 RREG32(SRBM_STATUS));
Alex Deuchera65a4362013-01-18 18:55:54 -05003509 dev_info(rdev->dev, " SRBM_STATUS2 = 0x%08X\n",
3510 RREG32(SRBM_STATUS2));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04003511 dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
3512 RREG32(CP_STALLED_STAT1));
3513 dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
3514 RREG32(CP_STALLED_STAT2));
3515 dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
3516 RREG32(CP_BUSY_STAT));
3517 dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
3518 RREG32(CP_STAT));
Alex Deucher0ecebb92013-01-03 12:40:13 -05003519 dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
3520 RREG32(DMA_STATUS_REG));
Alex Deucher168757e2013-01-18 19:17:22 -05003521 if (rdev->family >= CHIP_CAYMAN) {
3522 dev_info(rdev->dev, " R_00D834_DMA_STATUS_REG = 0x%08X\n",
3523 RREG32(DMA_STATUS_REG + 0x800));
3524 }
Alex Deucher0ecebb92013-01-03 12:40:13 -05003525}
3526
Alex Deucher168757e2013-01-18 19:17:22 -05003527bool evergreen_is_display_hung(struct radeon_device *rdev)
Alex Deuchera65a4362013-01-18 18:55:54 -05003528{
3529 u32 crtc_hung = 0;
3530 u32 crtc_status[6];
3531 u32 i, j, tmp;
3532
3533 for (i = 0; i < rdev->num_crtc; i++) {
3534 if (RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN) {
3535 crtc_status[i] = RREG32(EVERGREEN_CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
3536 crtc_hung |= (1 << i);
3537 }
3538 }
3539
3540 for (j = 0; j < 10; j++) {
3541 for (i = 0; i < rdev->num_crtc; i++) {
3542 if (crtc_hung & (1 << i)) {
3543 tmp = RREG32(EVERGREEN_CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
3544 if (tmp != crtc_status[i])
3545 crtc_hung &= ~(1 << i);
3546 }
3547 }
3548 if (crtc_hung == 0)
3549 return false;
3550 udelay(100);
3551 }
3552
3553 return true;
3554}
3555
3556static u32 evergreen_gpu_check_soft_reset(struct radeon_device *rdev)
3557{
3558 u32 reset_mask = 0;
3559 u32 tmp;
3560
3561 /* GRBM_STATUS */
3562 tmp = RREG32(GRBM_STATUS);
3563 if (tmp & (PA_BUSY | SC_BUSY |
3564 SH_BUSY | SX_BUSY |
3565 TA_BUSY | VGT_BUSY |
3566 DB_BUSY | CB_BUSY |
3567 SPI_BUSY | VGT_BUSY_NO_DMA))
3568 reset_mask |= RADEON_RESET_GFX;
3569
3570 if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
3571 CP_BUSY | CP_COHERENCY_BUSY))
3572 reset_mask |= RADEON_RESET_CP;
3573
3574 if (tmp & GRBM_EE_BUSY)
3575 reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
3576
3577 /* DMA_STATUS_REG */
3578 tmp = RREG32(DMA_STATUS_REG);
3579 if (!(tmp & DMA_IDLE))
3580 reset_mask |= RADEON_RESET_DMA;
3581
3582 /* SRBM_STATUS2 */
3583 tmp = RREG32(SRBM_STATUS2);
3584 if (tmp & DMA_BUSY)
3585 reset_mask |= RADEON_RESET_DMA;
3586
3587 /* SRBM_STATUS */
3588 tmp = RREG32(SRBM_STATUS);
3589 if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
3590 reset_mask |= RADEON_RESET_RLC;
3591
3592 if (tmp & IH_BUSY)
3593 reset_mask |= RADEON_RESET_IH;
3594
3595 if (tmp & SEM_BUSY)
3596 reset_mask |= RADEON_RESET_SEM;
3597
3598 if (tmp & GRBM_RQ_PENDING)
3599 reset_mask |= RADEON_RESET_GRBM;
3600
3601 if (tmp & VMC_BUSY)
3602 reset_mask |= RADEON_RESET_VMC;
3603
3604 if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
3605 MCC_BUSY | MCD_BUSY))
3606 reset_mask |= RADEON_RESET_MC;
3607
3608 if (evergreen_is_display_hung(rdev))
3609 reset_mask |= RADEON_RESET_DISPLAY;
3610
3611 /* VM_L2_STATUS */
3612 tmp = RREG32(VM_L2_STATUS);
3613 if (tmp & L2_BUSY)
3614 reset_mask |= RADEON_RESET_VMC;
3615
Alex Deucherd808fc82013-02-28 10:03:08 -05003616 /* Skip MC reset as it's mostly likely not hung, just busy */
3617 if (reset_mask & RADEON_RESET_MC) {
3618 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
3619 reset_mask &= ~RADEON_RESET_MC;
3620 }
3621
Alex Deuchera65a4362013-01-18 18:55:54 -05003622 return reset_mask;
3623}
3624
3625static void evergreen_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
Alex Deucher0ecebb92013-01-03 12:40:13 -05003626{
3627 struct evergreen_mc_save save;
Alex Deucherb7630472013-01-18 14:28:41 -05003628 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
3629 u32 tmp;
Alex Deucher19fc42e2013-01-14 11:04:39 -05003630
Alex Deucher0ecebb92013-01-03 12:40:13 -05003631 if (reset_mask == 0)
Alex Deuchera65a4362013-01-18 18:55:54 -05003632 return;
Alex Deucher0ecebb92013-01-03 12:40:13 -05003633
3634 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
3635
Alex Deucherb7630472013-01-18 14:28:41 -05003636 evergreen_print_gpu_status_regs(rdev);
3637
Alex Deucherb7630472013-01-18 14:28:41 -05003638 /* Disable CP parsing/prefetching */
3639 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
3640
3641 if (reset_mask & RADEON_RESET_DMA) {
3642 /* Disable DMA */
3643 tmp = RREG32(DMA_RB_CNTL);
3644 tmp &= ~DMA_RB_ENABLE;
3645 WREG32(DMA_RB_CNTL, tmp);
3646 }
3647
Alex Deucherb21b6e72013-01-23 18:57:56 -05003648 udelay(50);
3649
3650 evergreen_mc_stop(rdev, &save);
3651 if (evergreen_mc_wait_for_idle(rdev)) {
3652 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
3653 }
3654
Alex Deucherb7630472013-01-18 14:28:41 -05003655 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
3656 grbm_soft_reset |= SOFT_RESET_DB |
3657 SOFT_RESET_CB |
3658 SOFT_RESET_PA |
3659 SOFT_RESET_SC |
3660 SOFT_RESET_SPI |
3661 SOFT_RESET_SX |
3662 SOFT_RESET_SH |
3663 SOFT_RESET_TC |
3664 SOFT_RESET_TA |
3665 SOFT_RESET_VC |
3666 SOFT_RESET_VGT;
3667 }
3668
3669 if (reset_mask & RADEON_RESET_CP) {
3670 grbm_soft_reset |= SOFT_RESET_CP |
3671 SOFT_RESET_VGT;
3672
3673 srbm_soft_reset |= SOFT_RESET_GRBM;
3674 }
Alex Deucher0ecebb92013-01-03 12:40:13 -05003675
3676 if (reset_mask & RADEON_RESET_DMA)
Alex Deucherb7630472013-01-18 14:28:41 -05003677 srbm_soft_reset |= SOFT_RESET_DMA;
3678
Alex Deuchera65a4362013-01-18 18:55:54 -05003679 if (reset_mask & RADEON_RESET_DISPLAY)
3680 srbm_soft_reset |= SOFT_RESET_DC;
3681
3682 if (reset_mask & RADEON_RESET_RLC)
3683 srbm_soft_reset |= SOFT_RESET_RLC;
3684
3685 if (reset_mask & RADEON_RESET_SEM)
3686 srbm_soft_reset |= SOFT_RESET_SEM;
3687
3688 if (reset_mask & RADEON_RESET_IH)
3689 srbm_soft_reset |= SOFT_RESET_IH;
3690
3691 if (reset_mask & RADEON_RESET_GRBM)
3692 srbm_soft_reset |= SOFT_RESET_GRBM;
3693
3694 if (reset_mask & RADEON_RESET_VMC)
3695 srbm_soft_reset |= SOFT_RESET_VMC;
3696
Alex Deucher24178ec2013-01-24 15:00:17 -05003697 if (!(rdev->flags & RADEON_IS_IGP)) {
3698 if (reset_mask & RADEON_RESET_MC)
3699 srbm_soft_reset |= SOFT_RESET_MC;
3700 }
Alex Deuchera65a4362013-01-18 18:55:54 -05003701
Alex Deucherb7630472013-01-18 14:28:41 -05003702 if (grbm_soft_reset) {
3703 tmp = RREG32(GRBM_SOFT_RESET);
3704 tmp |= grbm_soft_reset;
3705 dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
3706 WREG32(GRBM_SOFT_RESET, tmp);
3707 tmp = RREG32(GRBM_SOFT_RESET);
3708
3709 udelay(50);
3710
3711 tmp &= ~grbm_soft_reset;
3712 WREG32(GRBM_SOFT_RESET, tmp);
3713 tmp = RREG32(GRBM_SOFT_RESET);
3714 }
3715
3716 if (srbm_soft_reset) {
3717 tmp = RREG32(SRBM_SOFT_RESET);
3718 tmp |= srbm_soft_reset;
3719 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
3720 WREG32(SRBM_SOFT_RESET, tmp);
3721 tmp = RREG32(SRBM_SOFT_RESET);
3722
3723 udelay(50);
3724
3725 tmp &= ~srbm_soft_reset;
3726 WREG32(SRBM_SOFT_RESET, tmp);
3727 tmp = RREG32(SRBM_SOFT_RESET);
3728 }
Alex Deucher0ecebb92013-01-03 12:40:13 -05003729
3730 /* Wait a little for things to settle down */
3731 udelay(50);
3732
Alex Deucher747943e2010-03-24 13:26:36 -04003733 evergreen_mc_resume(rdev, &save);
Alex Deucherb7630472013-01-18 14:28:41 -05003734 udelay(50);
Alex Deucher410a3412013-01-18 13:05:39 -05003735
Alex Deucherb7630472013-01-18 14:28:41 -05003736 evergreen_print_gpu_status_regs(rdev);
Alex Deucher747943e2010-03-24 13:26:36 -04003737}
3738
Jerome Glissea2d07b72010-03-09 14:45:11 +00003739int evergreen_asic_reset(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003740{
Alex Deuchera65a4362013-01-18 18:55:54 -05003741 u32 reset_mask;
3742
3743 reset_mask = evergreen_gpu_check_soft_reset(rdev);
3744
3745 if (reset_mask)
3746 r600_set_bios_scratch_engine_hung(rdev, true);
3747
3748 evergreen_gpu_soft_reset(rdev, reset_mask);
3749
3750 reset_mask = evergreen_gpu_check_soft_reset(rdev);
3751
3752 if (!reset_mask)
3753 r600_set_bios_scratch_engine_hung(rdev, false);
3754
3755 return 0;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003756}
3757
Alex Deucher123bc182013-01-24 11:37:19 -05003758/**
3759 * evergreen_gfx_is_lockup - Check if the GFX engine is locked up
3760 *
3761 * @rdev: radeon_device pointer
3762 * @ring: radeon_ring structure holding ring information
3763 *
3764 * Check if the GFX engine is locked up.
3765 * Returns true if the engine appears to be locked up, false if not.
3766 */
3767bool evergreen_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
3768{
3769 u32 reset_mask = evergreen_gpu_check_soft_reset(rdev);
3770
3771 if (!(reset_mask & (RADEON_RESET_GFX |
3772 RADEON_RESET_COMPUTE |
3773 RADEON_RESET_CP))) {
3774 radeon_ring_lockup_update(ring);
3775 return false;
3776 }
3777 /* force CP activities */
3778 radeon_ring_force_activity(rdev, ring);
3779 return radeon_ring_test_lockup(rdev, ring);
3780}
3781
3782/**
3783 * evergreen_dma_is_lockup - Check if the DMA engine is locked up
3784 *
3785 * @rdev: radeon_device pointer
3786 * @ring: radeon_ring structure holding ring information
3787 *
3788 * Check if the async DMA engine is locked up.
3789 * Returns true if the engine appears to be locked up, false if not.
3790 */
3791bool evergreen_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
3792{
3793 u32 reset_mask = evergreen_gpu_check_soft_reset(rdev);
3794
3795 if (!(reset_mask & RADEON_RESET_DMA)) {
3796 radeon_ring_lockup_update(ring);
3797 return false;
3798 }
3799 /* force ring activities */
3800 radeon_ring_force_activity(rdev, ring);
3801 return radeon_ring_test_lockup(rdev, ring);
3802}
3803
Alex Deucher45f9a392010-03-24 13:55:51 -04003804/* Interrupts */
3805
3806u32 evergreen_get_vblank_counter(struct radeon_device *rdev, int crtc)
3807{
Alex Deucher46437052012-08-15 17:10:32 -04003808 if (crtc >= rdev->num_crtc)
Alex Deucher45f9a392010-03-24 13:55:51 -04003809 return 0;
Alex Deucher46437052012-08-15 17:10:32 -04003810 else
3811 return RREG32(CRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
Alex Deucher45f9a392010-03-24 13:55:51 -04003812}
3813
3814void evergreen_disable_interrupt_state(struct radeon_device *rdev)
3815{
3816 u32 tmp;
3817
Alex Deucher1b370782011-11-17 20:13:28 -05003818 if (rdev->family >= CHIP_CAYMAN) {
3819 cayman_cp_int_cntl_setup(rdev, 0,
3820 CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
3821 cayman_cp_int_cntl_setup(rdev, 1, 0);
3822 cayman_cp_int_cntl_setup(rdev, 2, 0);
Alex Deucherf60cbd12012-12-04 15:27:33 -05003823 tmp = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE;
3824 WREG32(CAYMAN_DMA1_CNTL, tmp);
Alex Deucher1b370782011-11-17 20:13:28 -05003825 } else
3826 WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
Alex Deucher233d1ad2012-12-04 15:25:59 -05003827 tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
3828 WREG32(DMA_CNTL, tmp);
Alex Deucher45f9a392010-03-24 13:55:51 -04003829 WREG32(GRBM_INT_CNTL, 0);
3830 WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
3831 WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
Alex Deucherb7eff392011-07-08 11:44:56 -04003832 if (rdev->num_crtc >= 4) {
Alex Deucher18007402010-11-22 17:56:28 -05003833 WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
3834 WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
Alex Deucherb7eff392011-07-08 11:44:56 -04003835 }
3836 if (rdev->num_crtc >= 6) {
Alex Deucher18007402010-11-22 17:56:28 -05003837 WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
3838 WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
3839 }
Alex Deucher45f9a392010-03-24 13:55:51 -04003840
3841 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
3842 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
Alex Deucherb7eff392011-07-08 11:44:56 -04003843 if (rdev->num_crtc >= 4) {
Alex Deucher18007402010-11-22 17:56:28 -05003844 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
3845 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
Alex Deucherb7eff392011-07-08 11:44:56 -04003846 }
3847 if (rdev->num_crtc >= 6) {
Alex Deucher18007402010-11-22 17:56:28 -05003848 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
3849 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
3850 }
Alex Deucher45f9a392010-03-24 13:55:51 -04003851
Alex Deucher05b3ef62012-03-20 17:18:37 -04003852 /* only one DAC on DCE6 */
3853 if (!ASIC_IS_DCE6(rdev))
3854 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
Alex Deucher45f9a392010-03-24 13:55:51 -04003855 WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
3856
3857 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3858 WREG32(DC_HPD1_INT_CONTROL, tmp);
3859 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3860 WREG32(DC_HPD2_INT_CONTROL, tmp);
3861 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3862 WREG32(DC_HPD3_INT_CONTROL, tmp);
3863 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3864 WREG32(DC_HPD4_INT_CONTROL, tmp);
3865 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3866 WREG32(DC_HPD5_INT_CONTROL, tmp);
3867 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3868 WREG32(DC_HPD6_INT_CONTROL, tmp);
3869
3870}
3871
3872int evergreen_irq_set(struct radeon_device *rdev)
3873{
3874 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
Alex Deucher1b370782011-11-17 20:13:28 -05003875 u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
Alex Deucher45f9a392010-03-24 13:55:51 -04003876 u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
3877 u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
Alex Deucher2031f772010-04-22 12:52:11 -04003878 u32 grbm_int_cntl = 0;
Alex Deucher6f34be52010-11-21 10:59:01 -05003879 u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
Alex Deucherf122c612012-03-30 08:59:57 -04003880 u32 afmt1 = 0, afmt2 = 0, afmt3 = 0, afmt4 = 0, afmt5 = 0, afmt6 = 0;
Alex Deucherf60cbd12012-12-04 15:27:33 -05003881 u32 dma_cntl, dma_cntl1 = 0;
Alex Deucher45f9a392010-03-24 13:55:51 -04003882
3883 if (!rdev->irq.installed) {
Joe Perchesfce7d612010-10-30 21:08:30 +00003884 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
Alex Deucher45f9a392010-03-24 13:55:51 -04003885 return -EINVAL;
3886 }
3887 /* don't enable anything if the ih is disabled */
3888 if (!rdev->ih.enabled) {
3889 r600_disable_interrupts(rdev);
3890 /* force the active interrupt state to all disabled */
3891 evergreen_disable_interrupt_state(rdev);
3892 return 0;
3893 }
3894
3895 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3896 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3897 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
3898 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
3899 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
3900 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
3901
Alex Deucherf122c612012-03-30 08:59:57 -04003902 afmt1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
3903 afmt2 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
3904 afmt3 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
3905 afmt4 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
3906 afmt5 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
3907 afmt6 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
3908
Alex Deucher233d1ad2012-12-04 15:25:59 -05003909 dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
3910
Alex Deucher1b370782011-11-17 20:13:28 -05003911 if (rdev->family >= CHIP_CAYMAN) {
3912 /* enable CP interrupts on all rings */
Christian Koenig736fc372012-05-17 19:52:00 +02003913 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
Alex Deucher1b370782011-11-17 20:13:28 -05003914 DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
3915 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
3916 }
Christian Koenig736fc372012-05-17 19:52:00 +02003917 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
Alex Deucher1b370782011-11-17 20:13:28 -05003918 DRM_DEBUG("evergreen_irq_set: sw int cp1\n");
3919 cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
3920 }
Christian Koenig736fc372012-05-17 19:52:00 +02003921 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
Alex Deucher1b370782011-11-17 20:13:28 -05003922 DRM_DEBUG("evergreen_irq_set: sw int cp2\n");
3923 cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
3924 }
3925 } else {
Christian Koenig736fc372012-05-17 19:52:00 +02003926 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
Alex Deucher1b370782011-11-17 20:13:28 -05003927 DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
3928 cp_int_cntl |= RB_INT_ENABLE;
3929 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
3930 }
Alex Deucher45f9a392010-03-24 13:55:51 -04003931 }
Alex Deucher1b370782011-11-17 20:13:28 -05003932
Alex Deucher233d1ad2012-12-04 15:25:59 -05003933 if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
3934 DRM_DEBUG("r600_irq_set: sw int dma\n");
3935 dma_cntl |= TRAP_ENABLE;
3936 }
3937
Alex Deucherf60cbd12012-12-04 15:27:33 -05003938 if (rdev->family >= CHIP_CAYMAN) {
3939 dma_cntl1 = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE;
3940 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
3941 DRM_DEBUG("r600_irq_set: sw int dma1\n");
3942 dma_cntl1 |= TRAP_ENABLE;
3943 }
3944 }
3945
Alex Deucher6f34be52010-11-21 10:59:01 -05003946 if (rdev->irq.crtc_vblank_int[0] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003947 atomic_read(&rdev->irq.pflip[0])) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003948 DRM_DEBUG("evergreen_irq_set: vblank 0\n");
3949 crtc1 |= VBLANK_INT_MASK;
3950 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003951 if (rdev->irq.crtc_vblank_int[1] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003952 atomic_read(&rdev->irq.pflip[1])) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003953 DRM_DEBUG("evergreen_irq_set: vblank 1\n");
3954 crtc2 |= VBLANK_INT_MASK;
3955 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003956 if (rdev->irq.crtc_vblank_int[2] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003957 atomic_read(&rdev->irq.pflip[2])) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003958 DRM_DEBUG("evergreen_irq_set: vblank 2\n");
3959 crtc3 |= VBLANK_INT_MASK;
3960 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003961 if (rdev->irq.crtc_vblank_int[3] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003962 atomic_read(&rdev->irq.pflip[3])) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003963 DRM_DEBUG("evergreen_irq_set: vblank 3\n");
3964 crtc4 |= VBLANK_INT_MASK;
3965 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003966 if (rdev->irq.crtc_vblank_int[4] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003967 atomic_read(&rdev->irq.pflip[4])) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003968 DRM_DEBUG("evergreen_irq_set: vblank 4\n");
3969 crtc5 |= VBLANK_INT_MASK;
3970 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003971 if (rdev->irq.crtc_vblank_int[5] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003972 atomic_read(&rdev->irq.pflip[5])) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003973 DRM_DEBUG("evergreen_irq_set: vblank 5\n");
3974 crtc6 |= VBLANK_INT_MASK;
3975 }
3976 if (rdev->irq.hpd[0]) {
3977 DRM_DEBUG("evergreen_irq_set: hpd 1\n");
3978 hpd1 |= DC_HPDx_INT_EN;
3979 }
3980 if (rdev->irq.hpd[1]) {
3981 DRM_DEBUG("evergreen_irq_set: hpd 2\n");
3982 hpd2 |= DC_HPDx_INT_EN;
3983 }
3984 if (rdev->irq.hpd[2]) {
3985 DRM_DEBUG("evergreen_irq_set: hpd 3\n");
3986 hpd3 |= DC_HPDx_INT_EN;
3987 }
3988 if (rdev->irq.hpd[3]) {
3989 DRM_DEBUG("evergreen_irq_set: hpd 4\n");
3990 hpd4 |= DC_HPDx_INT_EN;
3991 }
3992 if (rdev->irq.hpd[4]) {
3993 DRM_DEBUG("evergreen_irq_set: hpd 5\n");
3994 hpd5 |= DC_HPDx_INT_EN;
3995 }
3996 if (rdev->irq.hpd[5]) {
3997 DRM_DEBUG("evergreen_irq_set: hpd 6\n");
3998 hpd6 |= DC_HPDx_INT_EN;
3999 }
Alex Deucherf122c612012-03-30 08:59:57 -04004000 if (rdev->irq.afmt[0]) {
4001 DRM_DEBUG("evergreen_irq_set: hdmi 0\n");
4002 afmt1 |= AFMT_AZ_FORMAT_WTRIG_MASK;
4003 }
4004 if (rdev->irq.afmt[1]) {
4005 DRM_DEBUG("evergreen_irq_set: hdmi 1\n");
4006 afmt2 |= AFMT_AZ_FORMAT_WTRIG_MASK;
4007 }
4008 if (rdev->irq.afmt[2]) {
4009 DRM_DEBUG("evergreen_irq_set: hdmi 2\n");
4010 afmt3 |= AFMT_AZ_FORMAT_WTRIG_MASK;
4011 }
4012 if (rdev->irq.afmt[3]) {
4013 DRM_DEBUG("evergreen_irq_set: hdmi 3\n");
4014 afmt4 |= AFMT_AZ_FORMAT_WTRIG_MASK;
4015 }
4016 if (rdev->irq.afmt[4]) {
4017 DRM_DEBUG("evergreen_irq_set: hdmi 4\n");
4018 afmt5 |= AFMT_AZ_FORMAT_WTRIG_MASK;
4019 }
4020 if (rdev->irq.afmt[5]) {
4021 DRM_DEBUG("evergreen_irq_set: hdmi 5\n");
4022 afmt6 |= AFMT_AZ_FORMAT_WTRIG_MASK;
4023 }
Alex Deucher45f9a392010-03-24 13:55:51 -04004024
Alex Deucher1b370782011-11-17 20:13:28 -05004025 if (rdev->family >= CHIP_CAYMAN) {
4026 cayman_cp_int_cntl_setup(rdev, 0, cp_int_cntl);
4027 cayman_cp_int_cntl_setup(rdev, 1, cp_int_cntl1);
4028 cayman_cp_int_cntl_setup(rdev, 2, cp_int_cntl2);
4029 } else
4030 WREG32(CP_INT_CNTL, cp_int_cntl);
Alex Deucher233d1ad2012-12-04 15:25:59 -05004031
4032 WREG32(DMA_CNTL, dma_cntl);
4033
Alex Deucherf60cbd12012-12-04 15:27:33 -05004034 if (rdev->family >= CHIP_CAYMAN)
4035 WREG32(CAYMAN_DMA1_CNTL, dma_cntl1);
4036
Alex Deucher2031f772010-04-22 12:52:11 -04004037 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
Alex Deucher45f9a392010-03-24 13:55:51 -04004038
4039 WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
4040 WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
Alex Deucherb7eff392011-07-08 11:44:56 -04004041 if (rdev->num_crtc >= 4) {
Alex Deucher18007402010-11-22 17:56:28 -05004042 WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
4043 WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
Alex Deucherb7eff392011-07-08 11:44:56 -04004044 }
4045 if (rdev->num_crtc >= 6) {
Alex Deucher18007402010-11-22 17:56:28 -05004046 WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
4047 WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
4048 }
Alex Deucher45f9a392010-03-24 13:55:51 -04004049
Alex Deucher6f34be52010-11-21 10:59:01 -05004050 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1);
4051 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2);
Alex Deucherb7eff392011-07-08 11:44:56 -04004052 if (rdev->num_crtc >= 4) {
4053 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3);
4054 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4);
4055 }
4056 if (rdev->num_crtc >= 6) {
4057 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5);
4058 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6);
4059 }
Alex Deucher6f34be52010-11-21 10:59:01 -05004060
Alex Deucher45f9a392010-03-24 13:55:51 -04004061 WREG32(DC_HPD1_INT_CONTROL, hpd1);
4062 WREG32(DC_HPD2_INT_CONTROL, hpd2);
4063 WREG32(DC_HPD3_INT_CONTROL, hpd3);
4064 WREG32(DC_HPD4_INT_CONTROL, hpd4);
4065 WREG32(DC_HPD5_INT_CONTROL, hpd5);
4066 WREG32(DC_HPD6_INT_CONTROL, hpd6);
4067
Alex Deucherf122c612012-03-30 08:59:57 -04004068 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, afmt1);
4069 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, afmt2);
4070 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, afmt3);
4071 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, afmt4);
4072 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, afmt5);
4073 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, afmt6);
4074
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004075 return 0;
4076}
4077
Andi Kleencbdd4502011-10-13 16:08:46 -07004078static void evergreen_irq_ack(struct radeon_device *rdev)
Alex Deucher45f9a392010-03-24 13:55:51 -04004079{
4080 u32 tmp;
4081
Alex Deucher6f34be52010-11-21 10:59:01 -05004082 rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
4083 rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
4084 rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
4085 rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
4086 rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
4087 rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
4088 rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
4089 rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
Alex Deucherb7eff392011-07-08 11:44:56 -04004090 if (rdev->num_crtc >= 4) {
4091 rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
4092 rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
4093 }
4094 if (rdev->num_crtc >= 6) {
4095 rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
4096 rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
4097 }
Alex Deucher45f9a392010-03-24 13:55:51 -04004098
Alex Deucherf122c612012-03-30 08:59:57 -04004099 rdev->irq.stat_regs.evergreen.afmt_status1 = RREG32(AFMT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
4100 rdev->irq.stat_regs.evergreen.afmt_status2 = RREG32(AFMT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
4101 rdev->irq.stat_regs.evergreen.afmt_status3 = RREG32(AFMT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
4102 rdev->irq.stat_regs.evergreen.afmt_status4 = RREG32(AFMT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
4103 rdev->irq.stat_regs.evergreen.afmt_status5 = RREG32(AFMT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
4104 rdev->irq.stat_regs.evergreen.afmt_status6 = RREG32(AFMT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
4105
Alex Deucher6f34be52010-11-21 10:59:01 -05004106 if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
4107 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
4108 if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
4109 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
Alex Deucher6f34be52010-11-21 10:59:01 -05004110 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
Alex Deucher45f9a392010-03-24 13:55:51 -04004111 WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05004112 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
Alex Deucher45f9a392010-03-24 13:55:51 -04004113 WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05004114 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
Alex Deucher45f9a392010-03-24 13:55:51 -04004115 WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05004116 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
Alex Deucher45f9a392010-03-24 13:55:51 -04004117 WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
4118
Alex Deucherb7eff392011-07-08 11:44:56 -04004119 if (rdev->num_crtc >= 4) {
4120 if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
4121 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
4122 if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
4123 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
4124 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
4125 WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
4126 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
4127 WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
4128 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
4129 WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
4130 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
4131 WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
4132 }
Alex Deucher45f9a392010-03-24 13:55:51 -04004133
Alex Deucherb7eff392011-07-08 11:44:56 -04004134 if (rdev->num_crtc >= 6) {
4135 if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
4136 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
4137 if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
4138 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
4139 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
4140 WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
4141 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
4142 WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
4143 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
4144 WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
4145 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
4146 WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
4147 }
Alex Deucher45f9a392010-03-24 13:55:51 -04004148
Alex Deucher6f34be52010-11-21 10:59:01 -05004149 if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
Alex Deucher45f9a392010-03-24 13:55:51 -04004150 tmp = RREG32(DC_HPD1_INT_CONTROL);
4151 tmp |= DC_HPDx_INT_ACK;
4152 WREG32(DC_HPD1_INT_CONTROL, tmp);
4153 }
Alex Deucher6f34be52010-11-21 10:59:01 -05004154 if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
Alex Deucher45f9a392010-03-24 13:55:51 -04004155 tmp = RREG32(DC_HPD2_INT_CONTROL);
4156 tmp |= DC_HPDx_INT_ACK;
4157 WREG32(DC_HPD2_INT_CONTROL, tmp);
4158 }
Alex Deucher6f34be52010-11-21 10:59:01 -05004159 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
Alex Deucher45f9a392010-03-24 13:55:51 -04004160 tmp = RREG32(DC_HPD3_INT_CONTROL);
4161 tmp |= DC_HPDx_INT_ACK;
4162 WREG32(DC_HPD3_INT_CONTROL, tmp);
4163 }
Alex Deucher6f34be52010-11-21 10:59:01 -05004164 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
Alex Deucher45f9a392010-03-24 13:55:51 -04004165 tmp = RREG32(DC_HPD4_INT_CONTROL);
4166 tmp |= DC_HPDx_INT_ACK;
4167 WREG32(DC_HPD4_INT_CONTROL, tmp);
4168 }
Alex Deucher6f34be52010-11-21 10:59:01 -05004169 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
Alex Deucher45f9a392010-03-24 13:55:51 -04004170 tmp = RREG32(DC_HPD5_INT_CONTROL);
4171 tmp |= DC_HPDx_INT_ACK;
4172 WREG32(DC_HPD5_INT_CONTROL, tmp);
4173 }
Alex Deucher6f34be52010-11-21 10:59:01 -05004174 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
Alex Deucher45f9a392010-03-24 13:55:51 -04004175 tmp = RREG32(DC_HPD5_INT_CONTROL);
4176 tmp |= DC_HPDx_INT_ACK;
4177 WREG32(DC_HPD6_INT_CONTROL, tmp);
4178 }
Alex Deucherf122c612012-03-30 08:59:57 -04004179 if (rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG) {
4180 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET);
4181 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
4182 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, tmp);
4183 }
4184 if (rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG) {
4185 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET);
4186 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
4187 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, tmp);
4188 }
4189 if (rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG) {
4190 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET);
4191 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
4192 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, tmp);
4193 }
4194 if (rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG) {
4195 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET);
4196 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
4197 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, tmp);
4198 }
4199 if (rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG) {
4200 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET);
4201 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
4202 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, tmp);
4203 }
4204 if (rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG) {
4205 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET);
4206 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
4207 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, tmp);
4208 }
Alex Deucher45f9a392010-03-24 13:55:51 -04004209}
4210
Lauri Kasanen1109ca02012-08-31 13:43:50 -04004211static void evergreen_irq_disable(struct radeon_device *rdev)
Alex Deucher45f9a392010-03-24 13:55:51 -04004212{
Alex Deucher45f9a392010-03-24 13:55:51 -04004213 r600_disable_interrupts(rdev);
4214 /* Wait and acknowledge irq */
4215 mdelay(1);
Alex Deucher6f34be52010-11-21 10:59:01 -05004216 evergreen_irq_ack(rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -04004217 evergreen_disable_interrupt_state(rdev);
4218}
4219
Alex Deucher755d8192011-03-02 20:07:34 -05004220void evergreen_irq_suspend(struct radeon_device *rdev)
Alex Deucher45f9a392010-03-24 13:55:51 -04004221{
4222 evergreen_irq_disable(rdev);
4223 r600_rlc_stop(rdev);
4224}
4225
Andi Kleencbdd4502011-10-13 16:08:46 -07004226static u32 evergreen_get_ih_wptr(struct radeon_device *rdev)
Alex Deucher45f9a392010-03-24 13:55:51 -04004227{
4228 u32 wptr, tmp;
4229
Alex Deucher724c80e2010-08-27 18:25:25 -04004230 if (rdev->wb.enabled)
Cédric Cano204ae242011-04-19 11:07:13 -04004231 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
Alex Deucher724c80e2010-08-27 18:25:25 -04004232 else
4233 wptr = RREG32(IH_RB_WPTR);
Alex Deucher45f9a392010-03-24 13:55:51 -04004234
4235 if (wptr & RB_OVERFLOW) {
4236 /* When a ring buffer overflow happen start parsing interrupt
4237 * from the last not overwritten vector (wptr + 16). Hopefully
4238 * this should allow us to catchup.
4239 */
4240 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
4241 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
4242 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
4243 tmp = RREG32(IH_RB_CNTL);
4244 tmp |= IH_WPTR_OVERFLOW_CLEAR;
4245 WREG32(IH_RB_CNTL, tmp);
4246 }
4247 return (wptr & rdev->ih.ptr_mask);
4248}
4249
4250int evergreen_irq_process(struct radeon_device *rdev)
4251{
Dave Airlie682f1a52011-06-18 03:59:51 +00004252 u32 wptr;
4253 u32 rptr;
Alex Deucher45f9a392010-03-24 13:55:51 -04004254 u32 src_id, src_data;
4255 u32 ring_index;
Alex Deucher45f9a392010-03-24 13:55:51 -04004256 bool queue_hotplug = false;
Alex Deucherf122c612012-03-30 08:59:57 -04004257 bool queue_hdmi = false;
Alex Deucher45f9a392010-03-24 13:55:51 -04004258
Dave Airlie682f1a52011-06-18 03:59:51 +00004259 if (!rdev->ih.enabled || rdev->shutdown)
Alex Deucher45f9a392010-03-24 13:55:51 -04004260 return IRQ_NONE;
4261
Dave Airlie682f1a52011-06-18 03:59:51 +00004262 wptr = evergreen_get_ih_wptr(rdev);
Christian Koenigc20dc362012-05-16 21:45:24 +02004263
4264restart_ih:
4265 /* is somebody else already processing irqs? */
4266 if (atomic_xchg(&rdev->ih.lock, 1))
4267 return IRQ_NONE;
4268
Dave Airlie682f1a52011-06-18 03:59:51 +00004269 rptr = rdev->ih.rptr;
4270 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
Alex Deucher45f9a392010-03-24 13:55:51 -04004271
Benjamin Herrenschmidt964f6642011-07-13 16:28:19 +10004272 /* Order reading of wptr vs. reading of IH ring data */
4273 rmb();
4274
Alex Deucher45f9a392010-03-24 13:55:51 -04004275 /* display interrupts */
Alex Deucher6f34be52010-11-21 10:59:01 -05004276 evergreen_irq_ack(rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -04004277
Alex Deucher45f9a392010-03-24 13:55:51 -04004278 while (rptr != wptr) {
4279 /* wptr/rptr are in bytes! */
4280 ring_index = rptr / 4;
Alex Deucher0f234f5f2011-02-13 19:06:33 -05004281 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
4282 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
Alex Deucher45f9a392010-03-24 13:55:51 -04004283
4284 switch (src_id) {
4285 case 1: /* D1 vblank/vline */
4286 switch (src_data) {
4287 case 0: /* D1 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05004288 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
Alex Deucher6f34be52010-11-21 10:59:01 -05004289 if (rdev->irq.crtc_vblank_int[0]) {
4290 drm_handle_vblank(rdev->ddev, 0);
4291 rdev->pm.vblank_sync = true;
4292 wake_up(&rdev->irq.vblank_queue);
4293 }
Christian Koenig736fc372012-05-17 19:52:00 +02004294 if (atomic_read(&rdev->irq.pflip[0]))
Mario Kleiner3e4ea742010-11-21 10:59:02 -05004295 radeon_crtc_handle_flip(rdev, 0);
Alex Deucher6f34be52010-11-21 10:59:01 -05004296 rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004297 DRM_DEBUG("IH: D1 vblank\n");
4298 }
4299 break;
4300 case 1: /* D1 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05004301 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
4302 rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004303 DRM_DEBUG("IH: D1 vline\n");
4304 }
4305 break;
4306 default:
4307 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
4308 break;
4309 }
4310 break;
4311 case 2: /* D2 vblank/vline */
4312 switch (src_data) {
4313 case 0: /* D2 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05004314 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
Alex Deucher6f34be52010-11-21 10:59:01 -05004315 if (rdev->irq.crtc_vblank_int[1]) {
4316 drm_handle_vblank(rdev->ddev, 1);
4317 rdev->pm.vblank_sync = true;
4318 wake_up(&rdev->irq.vblank_queue);
4319 }
Christian Koenig736fc372012-05-17 19:52:00 +02004320 if (atomic_read(&rdev->irq.pflip[1]))
Mario Kleiner3e4ea742010-11-21 10:59:02 -05004321 radeon_crtc_handle_flip(rdev, 1);
Alex Deucher6f34be52010-11-21 10:59:01 -05004322 rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004323 DRM_DEBUG("IH: D2 vblank\n");
4324 }
4325 break;
4326 case 1: /* D2 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05004327 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
4328 rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004329 DRM_DEBUG("IH: D2 vline\n");
4330 }
4331 break;
4332 default:
4333 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
4334 break;
4335 }
4336 break;
4337 case 3: /* D3 vblank/vline */
4338 switch (src_data) {
4339 case 0: /* D3 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05004340 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
4341 if (rdev->irq.crtc_vblank_int[2]) {
4342 drm_handle_vblank(rdev->ddev, 2);
4343 rdev->pm.vblank_sync = true;
4344 wake_up(&rdev->irq.vblank_queue);
4345 }
Christian Koenig736fc372012-05-17 19:52:00 +02004346 if (atomic_read(&rdev->irq.pflip[2]))
Alex Deucher6f34be52010-11-21 10:59:01 -05004347 radeon_crtc_handle_flip(rdev, 2);
4348 rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004349 DRM_DEBUG("IH: D3 vblank\n");
4350 }
4351 break;
4352 case 1: /* D3 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05004353 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
4354 rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004355 DRM_DEBUG("IH: D3 vline\n");
4356 }
4357 break;
4358 default:
4359 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
4360 break;
4361 }
4362 break;
4363 case 4: /* D4 vblank/vline */
4364 switch (src_data) {
4365 case 0: /* D4 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05004366 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
4367 if (rdev->irq.crtc_vblank_int[3]) {
4368 drm_handle_vblank(rdev->ddev, 3);
4369 rdev->pm.vblank_sync = true;
4370 wake_up(&rdev->irq.vblank_queue);
4371 }
Christian Koenig736fc372012-05-17 19:52:00 +02004372 if (atomic_read(&rdev->irq.pflip[3]))
Alex Deucher6f34be52010-11-21 10:59:01 -05004373 radeon_crtc_handle_flip(rdev, 3);
4374 rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004375 DRM_DEBUG("IH: D4 vblank\n");
4376 }
4377 break;
4378 case 1: /* D4 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05004379 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
4380 rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004381 DRM_DEBUG("IH: D4 vline\n");
4382 }
4383 break;
4384 default:
4385 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
4386 break;
4387 }
4388 break;
4389 case 5: /* D5 vblank/vline */
4390 switch (src_data) {
4391 case 0: /* D5 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05004392 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
4393 if (rdev->irq.crtc_vblank_int[4]) {
4394 drm_handle_vblank(rdev->ddev, 4);
4395 rdev->pm.vblank_sync = true;
4396 wake_up(&rdev->irq.vblank_queue);
4397 }
Christian Koenig736fc372012-05-17 19:52:00 +02004398 if (atomic_read(&rdev->irq.pflip[4]))
Alex Deucher6f34be52010-11-21 10:59:01 -05004399 radeon_crtc_handle_flip(rdev, 4);
4400 rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004401 DRM_DEBUG("IH: D5 vblank\n");
4402 }
4403 break;
4404 case 1: /* D5 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05004405 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
4406 rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004407 DRM_DEBUG("IH: D5 vline\n");
4408 }
4409 break;
4410 default:
4411 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
4412 break;
4413 }
4414 break;
4415 case 6: /* D6 vblank/vline */
4416 switch (src_data) {
4417 case 0: /* D6 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05004418 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
4419 if (rdev->irq.crtc_vblank_int[5]) {
4420 drm_handle_vblank(rdev->ddev, 5);
4421 rdev->pm.vblank_sync = true;
4422 wake_up(&rdev->irq.vblank_queue);
4423 }
Christian Koenig736fc372012-05-17 19:52:00 +02004424 if (atomic_read(&rdev->irq.pflip[5]))
Alex Deucher6f34be52010-11-21 10:59:01 -05004425 radeon_crtc_handle_flip(rdev, 5);
4426 rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004427 DRM_DEBUG("IH: D6 vblank\n");
4428 }
4429 break;
4430 case 1: /* D6 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05004431 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
4432 rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004433 DRM_DEBUG("IH: D6 vline\n");
4434 }
4435 break;
4436 default:
4437 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
4438 break;
4439 }
4440 break;
4441 case 42: /* HPD hotplug */
4442 switch (src_data) {
4443 case 0:
Alex Deucher6f34be52010-11-21 10:59:01 -05004444 if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
4445 rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004446 queue_hotplug = true;
4447 DRM_DEBUG("IH: HPD1\n");
4448 }
4449 break;
4450 case 1:
Alex Deucher6f34be52010-11-21 10:59:01 -05004451 if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
4452 rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004453 queue_hotplug = true;
4454 DRM_DEBUG("IH: HPD2\n");
4455 }
4456 break;
4457 case 2:
Alex Deucher6f34be52010-11-21 10:59:01 -05004458 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
4459 rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004460 queue_hotplug = true;
4461 DRM_DEBUG("IH: HPD3\n");
4462 }
4463 break;
4464 case 3:
Alex Deucher6f34be52010-11-21 10:59:01 -05004465 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
4466 rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004467 queue_hotplug = true;
4468 DRM_DEBUG("IH: HPD4\n");
4469 }
4470 break;
4471 case 4:
Alex Deucher6f34be52010-11-21 10:59:01 -05004472 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
4473 rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004474 queue_hotplug = true;
4475 DRM_DEBUG("IH: HPD5\n");
4476 }
4477 break;
4478 case 5:
Alex Deucher6f34be52010-11-21 10:59:01 -05004479 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
4480 rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04004481 queue_hotplug = true;
4482 DRM_DEBUG("IH: HPD6\n");
4483 }
4484 break;
4485 default:
4486 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
4487 break;
4488 }
4489 break;
Alex Deucherf122c612012-03-30 08:59:57 -04004490 case 44: /* hdmi */
4491 switch (src_data) {
4492 case 0:
4493 if (rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG) {
4494 rdev->irq.stat_regs.evergreen.afmt_status1 &= ~AFMT_AZ_FORMAT_WTRIG;
4495 queue_hdmi = true;
4496 DRM_DEBUG("IH: HDMI0\n");
4497 }
4498 break;
4499 case 1:
4500 if (rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG) {
4501 rdev->irq.stat_regs.evergreen.afmt_status2 &= ~AFMT_AZ_FORMAT_WTRIG;
4502 queue_hdmi = true;
4503 DRM_DEBUG("IH: HDMI1\n");
4504 }
4505 break;
4506 case 2:
4507 if (rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG) {
4508 rdev->irq.stat_regs.evergreen.afmt_status3 &= ~AFMT_AZ_FORMAT_WTRIG;
4509 queue_hdmi = true;
4510 DRM_DEBUG("IH: HDMI2\n");
4511 }
4512 break;
4513 case 3:
4514 if (rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG) {
4515 rdev->irq.stat_regs.evergreen.afmt_status4 &= ~AFMT_AZ_FORMAT_WTRIG;
4516 queue_hdmi = true;
4517 DRM_DEBUG("IH: HDMI3\n");
4518 }
4519 break;
4520 case 4:
4521 if (rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG) {
4522 rdev->irq.stat_regs.evergreen.afmt_status5 &= ~AFMT_AZ_FORMAT_WTRIG;
4523 queue_hdmi = true;
4524 DRM_DEBUG("IH: HDMI4\n");
4525 }
4526 break;
4527 case 5:
4528 if (rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG) {
4529 rdev->irq.stat_regs.evergreen.afmt_status6 &= ~AFMT_AZ_FORMAT_WTRIG;
4530 queue_hdmi = true;
4531 DRM_DEBUG("IH: HDMI5\n");
4532 }
4533 break;
4534 default:
4535 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
4536 break;
4537 }
Christian Königf2ba57b2013-04-08 12:41:29 +02004538 case 124: /* UVD */
4539 DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
4540 radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
Alex Deucherf122c612012-03-30 08:59:57 -04004541 break;
Christian Königae133a12012-09-18 15:30:44 -04004542 case 146:
4543 case 147:
4544 dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
4545 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
4546 RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
4547 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
4548 RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
4549 /* reset addr and status */
4550 WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
4551 break;
Alex Deucher45f9a392010-03-24 13:55:51 -04004552 case 176: /* CP_INT in ring buffer */
4553 case 177: /* CP_INT in IB1 */
4554 case 178: /* CP_INT in IB2 */
4555 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
Alex Deucher74652802011-08-25 13:39:48 -04004556 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
Alex Deucher45f9a392010-03-24 13:55:51 -04004557 break;
4558 case 181: /* CP EOP event */
4559 DRM_DEBUG("IH: CP EOP\n");
Alex Deucher1b370782011-11-17 20:13:28 -05004560 if (rdev->family >= CHIP_CAYMAN) {
4561 switch (src_data) {
4562 case 0:
4563 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
4564 break;
4565 case 1:
4566 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
4567 break;
4568 case 2:
4569 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
4570 break;
4571 }
4572 } else
4573 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
Alex Deucher45f9a392010-03-24 13:55:51 -04004574 break;
Alex Deucher233d1ad2012-12-04 15:25:59 -05004575 case 224: /* DMA trap event */
4576 DRM_DEBUG("IH: DMA trap\n");
4577 radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
4578 break;
Alex Deucher2031f772010-04-22 12:52:11 -04004579 case 233: /* GUI IDLE */
Ilija Hadzic303c8052011-06-07 14:54:48 -04004580 DRM_DEBUG("IH: GUI idle\n");
Alex Deucher2031f772010-04-22 12:52:11 -04004581 break;
Alex Deucherf60cbd12012-12-04 15:27:33 -05004582 case 244: /* DMA trap event */
4583 if (rdev->family >= CHIP_CAYMAN) {
4584 DRM_DEBUG("IH: DMA1 trap\n");
4585 radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
4586 }
4587 break;
Alex Deucher45f9a392010-03-24 13:55:51 -04004588 default:
4589 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
4590 break;
4591 }
4592
4593 /* wptr/rptr are in bytes! */
4594 rptr += 16;
4595 rptr &= rdev->ih.ptr_mask;
4596 }
Alex Deucher45f9a392010-03-24 13:55:51 -04004597 if (queue_hotplug)
Tejun Heo32c87fc2011-01-03 14:49:32 +01004598 schedule_work(&rdev->hotplug_work);
Alex Deucherf122c612012-03-30 08:59:57 -04004599 if (queue_hdmi)
4600 schedule_work(&rdev->audio_work);
Alex Deucher45f9a392010-03-24 13:55:51 -04004601 rdev->ih.rptr = rptr;
4602 WREG32(IH_RB_RPTR, rdev->ih.rptr);
Christian Koenigc20dc362012-05-16 21:45:24 +02004603 atomic_set(&rdev->ih.lock, 0);
4604
4605 /* make sure wptr hasn't changed while processing */
4606 wptr = evergreen_get_ih_wptr(rdev);
4607 if (wptr != rptr)
4608 goto restart_ih;
4609
Alex Deucher45f9a392010-03-24 13:55:51 -04004610 return IRQ_HANDLED;
4611}
4612
Alex Deucher233d1ad2012-12-04 15:25:59 -05004613/**
4614 * evergreen_dma_fence_ring_emit - emit a fence on the DMA ring
4615 *
4616 * @rdev: radeon_device pointer
4617 * @fence: radeon fence object
4618 *
4619 * Add a DMA fence packet to the ring to write
4620 * the fence seq number and DMA trap packet to generate
4621 * an interrupt if needed (evergreen-SI).
4622 */
4623void evergreen_dma_fence_ring_emit(struct radeon_device *rdev,
4624 struct radeon_fence *fence)
4625{
4626 struct radeon_ring *ring = &rdev->ring[fence->ring];
4627 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
4628 /* write the fence */
Jerome Glisse0fcb6152013-01-14 11:32:27 -05004629 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_FENCE, 0, 0));
Alex Deucher233d1ad2012-12-04 15:25:59 -05004630 radeon_ring_write(ring, addr & 0xfffffffc);
4631 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff));
4632 radeon_ring_write(ring, fence->seq);
4633 /* generate an interrupt */
Jerome Glisse0fcb6152013-01-14 11:32:27 -05004634 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_TRAP, 0, 0));
Alex Deucher233d1ad2012-12-04 15:25:59 -05004635 /* flush HDP */
Jerome Glisse0fcb6152013-01-14 11:32:27 -05004636 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0));
Alex Deucher4b681c22013-01-03 19:54:34 -05004637 radeon_ring_write(ring, (0xf << 16) | (HDP_MEM_COHERENCY_FLUSH_CNTL >> 2));
Alex Deucher233d1ad2012-12-04 15:25:59 -05004638 radeon_ring_write(ring, 1);
4639}
4640
4641/**
4642 * evergreen_dma_ring_ib_execute - schedule an IB on the DMA engine
4643 *
4644 * @rdev: radeon_device pointer
4645 * @ib: IB object to schedule
4646 *
4647 * Schedule an IB in the DMA ring (evergreen).
4648 */
4649void evergreen_dma_ring_ib_execute(struct radeon_device *rdev,
4650 struct radeon_ib *ib)
4651{
4652 struct radeon_ring *ring = &rdev->ring[ib->ring];
4653
4654 if (rdev->wb.enabled) {
4655 u32 next_rptr = ring->wptr + 4;
4656 while ((next_rptr & 7) != 5)
4657 next_rptr++;
4658 next_rptr += 3;
Jerome Glisse0fcb6152013-01-14 11:32:27 -05004659 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 1));
Alex Deucher233d1ad2012-12-04 15:25:59 -05004660 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
4661 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xff);
4662 radeon_ring_write(ring, next_rptr);
4663 }
4664
4665 /* The indirect buffer packet must end on an 8 DW boundary in the DMA ring.
4666 * Pad as necessary with NOPs.
4667 */
4668 while ((ring->wptr & 7) != 5)
Jerome Glisse0fcb6152013-01-14 11:32:27 -05004669 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_NOP, 0, 0));
4670 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_INDIRECT_BUFFER, 0, 0));
Alex Deucher233d1ad2012-12-04 15:25:59 -05004671 radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFE0));
4672 radeon_ring_write(ring, (ib->length_dw << 12) | (upper_32_bits(ib->gpu_addr) & 0xFF));
4673
4674}
4675
4676/**
4677 * evergreen_copy_dma - copy pages using the DMA engine
4678 *
4679 * @rdev: radeon_device pointer
4680 * @src_offset: src GPU address
4681 * @dst_offset: dst GPU address
4682 * @num_gpu_pages: number of GPU pages to xfer
4683 * @fence: radeon fence object
4684 *
4685 * Copy GPU paging using the DMA engine (evergreen-cayman).
4686 * Used by the radeon ttm implementation to move pages if
4687 * registered as the asic copy callback.
4688 */
4689int evergreen_copy_dma(struct radeon_device *rdev,
4690 uint64_t src_offset, uint64_t dst_offset,
4691 unsigned num_gpu_pages,
4692 struct radeon_fence **fence)
4693{
4694 struct radeon_semaphore *sem = NULL;
4695 int ring_index = rdev->asic->copy.dma_ring_index;
4696 struct radeon_ring *ring = &rdev->ring[ring_index];
4697 u32 size_in_dw, cur_size_in_dw;
4698 int i, num_loops;
4699 int r = 0;
4700
4701 r = radeon_semaphore_create(rdev, &sem);
4702 if (r) {
4703 DRM_ERROR("radeon: moving bo (%d).\n", r);
4704 return r;
4705 }
4706
4707 size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4;
4708 num_loops = DIV_ROUND_UP(size_in_dw, 0xfffff);
4709 r = radeon_ring_lock(rdev, ring, num_loops * 5 + 11);
4710 if (r) {
4711 DRM_ERROR("radeon: moving bo (%d).\n", r);
4712 radeon_semaphore_free(rdev, &sem, NULL);
4713 return r;
4714 }
4715
4716 if (radeon_fence_need_sync(*fence, ring->idx)) {
4717 radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring,
4718 ring->idx);
4719 radeon_fence_note_sync(*fence, ring->idx);
4720 } else {
4721 radeon_semaphore_free(rdev, &sem, NULL);
4722 }
4723
4724 for (i = 0; i < num_loops; i++) {
4725 cur_size_in_dw = size_in_dw;
4726 if (cur_size_in_dw > 0xFFFFF)
4727 cur_size_in_dw = 0xFFFFF;
4728 size_in_dw -= cur_size_in_dw;
Jerome Glisse0fcb6152013-01-14 11:32:27 -05004729 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, cur_size_in_dw));
Alex Deucher233d1ad2012-12-04 15:25:59 -05004730 radeon_ring_write(ring, dst_offset & 0xfffffffc);
4731 radeon_ring_write(ring, src_offset & 0xfffffffc);
4732 radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
4733 radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff);
4734 src_offset += cur_size_in_dw * 4;
4735 dst_offset += cur_size_in_dw * 4;
4736 }
4737
4738 r = radeon_fence_emit(rdev, fence, ring->idx);
4739 if (r) {
4740 radeon_ring_unlock_undo(rdev, ring);
4741 return r;
4742 }
4743
4744 radeon_ring_unlock_commit(rdev, ring);
4745 radeon_semaphore_free(rdev, &sem, *fence);
4746
4747 return r;
4748}
4749
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004750static int evergreen_startup(struct radeon_device *rdev)
4751{
Christian Königf2ba57b2013-04-08 12:41:29 +02004752 struct radeon_ring *ring;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004753 int r;
4754
Alex Deucher9e46a482011-01-06 18:49:35 -05004755 /* enable pcie gen2 link */
Ilija Hadziccd540332011-09-20 10:22:57 -04004756 evergreen_pcie_gen2_enable(rdev);
Alex Deucher9e46a482011-01-06 18:49:35 -05004757
Alex Deucher0af62b02011-01-06 21:19:31 -05004758 if (ASIC_IS_DCE5(rdev)) {
4759 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
4760 r = ni_init_microcode(rdev);
4761 if (r) {
4762 DRM_ERROR("Failed to load firmware!\n");
4763 return r;
4764 }
4765 }
Alex Deucher755d8192011-03-02 20:07:34 -05004766 r = ni_mc_load_microcode(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004767 if (r) {
Alex Deucher0af62b02011-01-06 21:19:31 -05004768 DRM_ERROR("Failed to load MC firmware!\n");
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004769 return r;
4770 }
Alex Deucher0af62b02011-01-06 21:19:31 -05004771 } else {
4772 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
4773 r = r600_init_microcode(rdev);
4774 if (r) {
4775 DRM_ERROR("Failed to load firmware!\n");
4776 return r;
4777 }
4778 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004779 }
Alex Deucherfe251e22010-03-24 13:36:43 -04004780
Alex Deucher16cdf042011-10-28 10:30:02 -04004781 r = r600_vram_scratch_init(rdev);
4782 if (r)
4783 return r;
4784
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004785 evergreen_mc_program(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004786 if (rdev->flags & RADEON_IS_AGP) {
Alex Deucher0fcdb612010-03-24 13:20:41 -04004787 evergreen_agp_enable(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004788 } else {
4789 r = evergreen_pcie_gart_enable(rdev);
4790 if (r)
4791 return r;
4792 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004793 evergreen_gpu_init(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004794
Alex Deucherd7ccd8f2010-09-09 11:33:36 -04004795 r = evergreen_blit_init(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004796 if (r) {
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -04004797 r600_blit_fini(rdev);
Alex Deucher27cd7762012-02-23 17:53:42 -05004798 rdev->asic->copy.copy = NULL;
Alex Deucherd7ccd8f2010-09-09 11:33:36 -04004799 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004800 }
4801
Alex Deucher724c80e2010-08-27 18:25:25 -04004802 /* allocate wb buffer */
4803 r = radeon_wb_init(rdev);
4804 if (r)
4805 return r;
4806
Jerome Glisse30eb77f2011-11-20 20:45:34 +00004807 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
4808 if (r) {
4809 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
4810 return r;
4811 }
4812
Alex Deucher233d1ad2012-12-04 15:25:59 -05004813 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
4814 if (r) {
4815 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
4816 return r;
4817 }
4818
Christian Königf2ba57b2013-04-08 12:41:29 +02004819 r = rv770_uvd_resume(rdev);
4820 if (!r) {
4821 r = radeon_fence_driver_start_ring(rdev,
4822 R600_RING_TYPE_UVD_INDEX);
4823 if (r)
4824 dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
4825 }
4826
4827 if (r)
4828 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
4829
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004830 /* Enable IRQ */
4831 r = r600_irq_init(rdev);
4832 if (r) {
4833 DRM_ERROR("radeon: IH init failed (%d).\n", r);
4834 radeon_irq_kms_fini(rdev);
4835 return r;
4836 }
Alex Deucher45f9a392010-03-24 13:55:51 -04004837 evergreen_irq_set(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004838
Christian Königf2ba57b2013-04-08 12:41:29 +02004839 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Christian Könige32eb502011-10-23 12:56:27 +02004840 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
Alex Deucher78c55602011-11-17 14:25:56 -05004841 R600_CP_RB_RPTR, R600_CP_RB_WPTR,
4842 0, 0xfffff, RADEON_CP_PACKET2);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004843 if (r)
4844 return r;
Alex Deucher233d1ad2012-12-04 15:25:59 -05004845
4846 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
4847 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
4848 DMA_RB_RPTR, DMA_RB_WPTR,
Jerome Glisse0fcb6152013-01-14 11:32:27 -05004849 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0));
Alex Deucher233d1ad2012-12-04 15:25:59 -05004850 if (r)
4851 return r;
4852
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004853 r = evergreen_cp_load_microcode(rdev);
4854 if (r)
4855 return r;
Alex Deucherfe251e22010-03-24 13:36:43 -04004856 r = evergreen_cp_resume(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004857 if (r)
4858 return r;
Alex Deucher233d1ad2012-12-04 15:25:59 -05004859 r = r600_dma_resume(rdev);
4860 if (r)
4861 return r;
Alex Deucherfe251e22010-03-24 13:36:43 -04004862
Christian Königf2ba57b2013-04-08 12:41:29 +02004863 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
4864 if (ring->ring_size) {
4865 r = radeon_ring_init(rdev, ring, ring->ring_size,
4866 R600_WB_UVD_RPTR_OFFSET,
4867 UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR,
4868 0, 0xfffff, RADEON_CP_PACKET2);
4869 if (!r)
4870 r = r600_uvd_init(rdev);
4871
4872 if (r)
4873 DRM_ERROR("radeon: error initializing UVD (%d).\n", r);
4874 }
4875
Christian König2898c342012-07-05 11:55:34 +02004876 r = radeon_ib_pool_init(rdev);
4877 if (r) {
4878 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisseb15ba512011-11-15 11:48:34 -05004879 return r;
Christian König2898c342012-07-05 11:55:34 +02004880 }
Jerome Glisseb15ba512011-11-15 11:48:34 -05004881
Rafał Miłecki69d2ae52011-12-07 23:32:24 +01004882 r = r600_audio_init(rdev);
4883 if (r) {
4884 DRM_ERROR("radeon: audio init failed\n");
Jerome Glisseb15ba512011-11-15 11:48:34 -05004885 return r;
4886 }
4887
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004888 return 0;
4889}
4890
4891int evergreen_resume(struct radeon_device *rdev)
4892{
4893 int r;
4894
Alex Deucher86f5c9e2010-12-20 12:35:04 -05004895 /* reset the asic, the gfx blocks are often in a bad state
4896 * after the driver is unloaded or after a resume
4897 */
4898 if (radeon_asic_reset(rdev))
4899 dev_warn(rdev->dev, "GPU reset failed !\n");
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004900 /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
4901 * posting will perform necessary task to bring back GPU into good
4902 * shape.
4903 */
4904 /* post card */
4905 atom_asic_init(rdev->mode_info.atom_context);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004906
Alex Deucherd4788db2013-02-28 14:40:09 -05004907 /* init golden registers */
4908 evergreen_init_golden_registers(rdev);
4909
Jerome Glisseb15ba512011-11-15 11:48:34 -05004910 rdev->accel_working = true;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004911 r = evergreen_startup(rdev);
4912 if (r) {
Alex Deucher755d8192011-03-02 20:07:34 -05004913 DRM_ERROR("evergreen startup failed on resume\n");
Jerome Glisse6b7746e2012-02-20 17:57:20 -05004914 rdev->accel_working = false;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004915 return r;
4916 }
Alex Deucherfe251e22010-03-24 13:36:43 -04004917
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004918 return r;
4919
4920}
4921
4922int evergreen_suspend(struct radeon_device *rdev)
4923{
Rafał Miłecki69d2ae52011-12-07 23:32:24 +01004924 r600_audio_fini(rdev);
Christian Königf2ba57b2013-04-08 12:41:29 +02004925 radeon_uvd_suspend(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004926 r700_cp_stop(rdev);
Alex Deucher233d1ad2012-12-04 15:25:59 -05004927 r600_dma_stop(rdev);
Christian Königf2ba57b2013-04-08 12:41:29 +02004928 r600_uvd_rbc_stop(rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -04004929 evergreen_irq_suspend(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04004930 radeon_wb_disable(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004931 evergreen_pcie_gart_disable(rdev);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -04004932
4933 return 0;
4934}
4935
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004936/* Plan is to move initialization in that function and use
4937 * helper function so that radeon_device_init pretty much
4938 * do nothing more than calling asic specific function. This
4939 * should also allow to remove a bunch of callback function
4940 * like vram_info.
4941 */
4942int evergreen_init(struct radeon_device *rdev)
4943{
4944 int r;
4945
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004946 /* Read BIOS */
4947 if (!radeon_get_bios(rdev)) {
4948 if (ASIC_IS_AVIVO(rdev))
4949 return -EINVAL;
4950 }
4951 /* Must be an ATOMBIOS */
4952 if (!rdev->is_atom_bios) {
Alex Deucher755d8192011-03-02 20:07:34 -05004953 dev_err(rdev->dev, "Expecting atombios for evergreen GPU\n");
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004954 return -EINVAL;
4955 }
4956 r = radeon_atombios_init(rdev);
4957 if (r)
4958 return r;
Alex Deucher86f5c9e2010-12-20 12:35:04 -05004959 /* reset the asic, the gfx blocks are often in a bad state
4960 * after the driver is unloaded or after a resume
4961 */
4962 if (radeon_asic_reset(rdev))
4963 dev_warn(rdev->dev, "GPU reset failed !\n");
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004964 /* Post card if necessary */
Alex Deucherfd909c32011-01-11 18:08:59 -05004965 if (!radeon_card_posted(rdev)) {
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004966 if (!rdev->bios) {
4967 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
4968 return -EINVAL;
4969 }
4970 DRM_INFO("GPU not posted. posting now...\n");
4971 atom_asic_init(rdev->mode_info.atom_context);
4972 }
Alex Deucherd4788db2013-02-28 14:40:09 -05004973 /* init golden registers */
4974 evergreen_init_golden_registers(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004975 /* Initialize scratch registers */
4976 r600_scratch_init(rdev);
4977 /* Initialize surface registers */
4978 radeon_surface_init(rdev);
4979 /* Initialize clocks */
4980 radeon_get_clock_info(rdev->ddev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004981 /* Fence driver */
4982 r = radeon_fence_driver_init(rdev);
4983 if (r)
4984 return r;
Jerome Glissed594e462010-02-17 21:54:29 +00004985 /* initialize AGP */
4986 if (rdev->flags & RADEON_IS_AGP) {
4987 r = radeon_agp_init(rdev);
4988 if (r)
4989 radeon_agp_disable(rdev);
4990 }
4991 /* initialize memory controller */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004992 r = evergreen_mc_init(rdev);
4993 if (r)
4994 return r;
4995 /* Memory manager */
4996 r = radeon_bo_init(rdev);
4997 if (r)
4998 return r;
Alex Deucher45f9a392010-03-24 13:55:51 -04004999
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05005000 r = radeon_irq_kms_init(rdev);
5001 if (r)
5002 return r;
5003
Christian Könige32eb502011-10-23 12:56:27 +02005004 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
5005 r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05005006
Alex Deucher233d1ad2012-12-04 15:25:59 -05005007 rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL;
5008 r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024);
5009
Christian Königf2ba57b2013-04-08 12:41:29 +02005010 r = radeon_uvd_init(rdev);
5011 if (!r) {
5012 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
5013 r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX],
5014 4096);
5015 }
5016
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05005017 rdev->ih.ring_obj = NULL;
5018 r600_ih_ring_init(rdev, 64 * 1024);
5019
5020 r = r600_pcie_gart_init(rdev);
5021 if (r)
5022 return r;
Alex Deucher0fcdb612010-03-24 13:20:41 -04005023
Alex Deucher148a03b2010-06-03 19:00:03 -04005024 rdev->accel_working = true;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05005025 r = evergreen_startup(rdev);
5026 if (r) {
Alex Deucherfe251e22010-03-24 13:36:43 -04005027 dev_err(rdev->dev, "disabling GPU acceleration\n");
5028 r700_cp_fini(rdev);
Alex Deucher233d1ad2012-12-04 15:25:59 -05005029 r600_dma_fini(rdev);
Alex Deucherfe251e22010-03-24 13:36:43 -04005030 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04005031 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02005032 radeon_ib_pool_fini(rdev);
Alex Deucherfe251e22010-03-24 13:36:43 -04005033 radeon_irq_kms_fini(rdev);
Alex Deucher0fcdb612010-03-24 13:20:41 -04005034 evergreen_pcie_gart_fini(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05005035 rdev->accel_working = false;
5036 }
Alex Deucher77e00f22011-12-21 11:58:17 -05005037
5038 /* Don't start up if the MC ucode is missing on BTC parts.
5039 * The default clocks and voltages before the MC ucode
5040 * is loaded are not suffient for advanced operations.
5041 */
5042 if (ASIC_IS_DCE5(rdev)) {
5043 if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
5044 DRM_ERROR("radeon: MC ucode required for NI+.\n");
5045 return -EINVAL;
5046 }
5047 }
5048
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05005049 return 0;
5050}
5051
5052void evergreen_fini(struct radeon_device *rdev)
5053{
Rafał Miłecki69d2ae52011-12-07 23:32:24 +01005054 r600_audio_fini(rdev);
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -04005055 r600_blit_fini(rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -04005056 r700_cp_fini(rdev);
Alex Deucher233d1ad2012-12-04 15:25:59 -05005057 r600_dma_fini(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05005058 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04005059 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02005060 radeon_ib_pool_fini(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05005061 radeon_irq_kms_fini(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05005062 evergreen_pcie_gart_fini(rdev);
Christian Königf2ba57b2013-04-08 12:41:29 +02005063 radeon_uvd_fini(rdev);
Alex Deucher16cdf042011-10-28 10:30:02 -04005064 r600_vram_scratch_fini(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05005065 radeon_gem_fini(rdev);
5066 radeon_fence_driver_fini(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05005067 radeon_agp_fini(rdev);
5068 radeon_bo_fini(rdev);
5069 radeon_atombios_fini(rdev);
5070 kfree(rdev->bios);
5071 rdev->bios = NULL;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05005072}
Alex Deucher9e46a482011-01-06 18:49:35 -05005073
Ilija Hadzicb07759b2011-09-20 10:22:58 -04005074void evergreen_pcie_gen2_enable(struct radeon_device *rdev)
Alex Deucher9e46a482011-01-06 18:49:35 -05005075{
Dave Airlie197bbb32012-06-27 08:35:54 +01005076 u32 link_width_cntl, speed_cntl, mask;
5077 int ret;
Alex Deucher9e46a482011-01-06 18:49:35 -05005078
Alex Deucherd42dd572011-01-12 20:05:11 -05005079 if (radeon_pcie_gen2 == 0)
5080 return;
5081
Alex Deucher9e46a482011-01-06 18:49:35 -05005082 if (rdev->flags & RADEON_IS_IGP)
5083 return;
5084
5085 if (!(rdev->flags & RADEON_IS_PCIE))
5086 return;
5087
5088 /* x2 cards have a special sequence */
5089 if (ASIC_IS_X2(rdev))
5090 return;
5091
Dave Airlie197bbb32012-06-27 08:35:54 +01005092 ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
5093 if (ret != 0)
5094 return;
5095
5096 if (!(mask & DRM_PCIE_SPEED_50))
5097 return;
5098
Alex Deucher492d2b62012-10-25 16:06:59 -04005099 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher3691fee2012-10-08 17:46:27 -04005100 if (speed_cntl & LC_CURRENT_DATA_RATE) {
5101 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
5102 return;
5103 }
5104
Dave Airlie197bbb32012-06-27 08:35:54 +01005105 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
5106
Alex Deucher9e46a482011-01-06 18:49:35 -05005107 if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) ||
5108 (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
5109
Alex Deucher492d2b62012-10-25 16:06:59 -04005110 link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05005111 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
Alex Deucher492d2b62012-10-25 16:06:59 -04005112 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05005113
Alex Deucher492d2b62012-10-25 16:06:59 -04005114 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05005115 speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
Alex Deucher492d2b62012-10-25 16:06:59 -04005116 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05005117
Alex Deucher492d2b62012-10-25 16:06:59 -04005118 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05005119 speed_cntl |= LC_CLR_FAILED_SPD_CHANGE_CNT;
Alex Deucher492d2b62012-10-25 16:06:59 -04005120 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05005121
Alex Deucher492d2b62012-10-25 16:06:59 -04005122 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05005123 speed_cntl &= ~LC_CLR_FAILED_SPD_CHANGE_CNT;
Alex Deucher492d2b62012-10-25 16:06:59 -04005124 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05005125
Alex Deucher492d2b62012-10-25 16:06:59 -04005126 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05005127 speed_cntl |= LC_GEN2_EN_STRAP;
Alex Deucher492d2b62012-10-25 16:06:59 -04005128 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05005129
5130 } else {
Alex Deucher492d2b62012-10-25 16:06:59 -04005131 link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05005132 /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
5133 if (1)
5134 link_width_cntl |= LC_UPCONFIGURE_DIS;
5135 else
5136 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
Alex Deucher492d2b62012-10-25 16:06:59 -04005137 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05005138 }
5139}