blob: a6e71864ee8318e5a7e26238758d8ad5c37b0783 [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
Jerome Glisse285484e2011-12-16 17:03:42 -050056void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
57 unsigned *bankh, unsigned *mtaspect,
58 unsigned *tile_split)
59{
60 *bankw = (tiling_flags >> RADEON_TILING_EG_BANKW_SHIFT) & RADEON_TILING_EG_BANKW_MASK;
61 *bankh = (tiling_flags >> RADEON_TILING_EG_BANKH_SHIFT) & RADEON_TILING_EG_BANKH_MASK;
62 *mtaspect = (tiling_flags >> RADEON_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & RADEON_TILING_EG_MACRO_TILE_ASPECT_MASK;
63 *tile_split = (tiling_flags >> RADEON_TILING_EG_TILE_SPLIT_SHIFT) & RADEON_TILING_EG_TILE_SPLIT_MASK;
64 switch (*bankw) {
65 default:
66 case 1: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_1; break;
67 case 2: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_2; break;
68 case 4: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_4; break;
69 case 8: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_8; break;
70 }
71 switch (*bankh) {
72 default:
73 case 1: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_1; break;
74 case 2: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_2; break;
75 case 4: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_4; break;
76 case 8: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_8; break;
77 }
78 switch (*mtaspect) {
79 default:
80 case 1: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_1; break;
81 case 2: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_2; break;
82 case 4: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_4; break;
83 case 8: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_8; break;
84 }
85}
86
Alex Deucher23d33ba2013-04-08 12:41:32 +020087static int sumo_set_uvd_clock(struct radeon_device *rdev, u32 clock,
88 u32 cntl_reg, u32 status_reg)
89{
90 int r, i;
91 struct atom_clock_dividers dividers;
92
93 r = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
94 clock, false, &dividers);
95 if (r)
96 return r;
97
98 WREG32_P(cntl_reg, dividers.post_div, ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK));
99
100 for (i = 0; i < 100; i++) {
101 if (RREG32(status_reg) & DCLK_STATUS)
102 break;
103 mdelay(10);
104 }
105 if (i == 100)
106 return -ETIMEDOUT;
107
108 return 0;
109}
110
111int sumo_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
112{
113 int r = 0;
114 u32 cg_scratch = RREG32(CG_SCRATCH1);
115
116 r = sumo_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
117 if (r)
118 goto done;
119 cg_scratch &= 0xffff0000;
120 cg_scratch |= vclk / 100; /* Mhz */
121
122 r = sumo_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
123 if (r)
124 goto done;
125 cg_scratch &= 0x0000ffff;
126 cg_scratch |= (dclk / 100) << 16; /* Mhz */
127
128done:
129 WREG32(CG_SCRATCH1, cg_scratch);
130
131 return r;
132}
133
Alex Deuchera8b49252013-04-08 12:41:33 +0200134static int evergreen_uvd_calc_post_div(unsigned target_freq,
135 unsigned vco_freq,
136 unsigned *div)
137{
138 /* target larger than vco frequency ? */
139 if (vco_freq < target_freq)
140 return -1; /* forget it */
141
142 /* Fclk = Fvco / PDIV */
143 *div = vco_freq / target_freq;
144
145 /* we alway need a frequency less than or equal the target */
146 if ((vco_freq / *div) > target_freq)
147 *div += 1;
148
149 /* dividers above 5 must be even */
150 if (*div > 5 && *div % 2)
151 *div += 1;
152
153 /* out of range ? */
154 if (*div >= 128)
155 return -1; /* forget it */
156
157 return vco_freq / *div;
158}
159
160static int evergreen_uvd_send_upll_ctlreq(struct radeon_device *rdev)
161{
162 unsigned i;
163
164 /* assert UPLL_CTLREQ */
165 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_CTLREQ_MASK, ~UPLL_CTLREQ_MASK);
166
167 /* wait for CTLACK and CTLACK2 to get asserted */
168 for (i = 0; i < 100; ++i) {
169 uint32_t mask = UPLL_CTLACK_MASK | UPLL_CTLACK2_MASK;
170 if ((RREG32(CG_UPLL_FUNC_CNTL) & mask) == mask)
171 break;
172 mdelay(10);
173 }
174 if (i == 100)
175 return -ETIMEDOUT;
176
177 /* deassert UPLL_CTLREQ */
178 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_CTLREQ_MASK);
179
180 return 0;
181}
182
183int evergreen_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
184{
185 /* start off with something large */
186 int optimal_diff_score = 0x7FFFFFF;
187 unsigned optimal_fb_div = 0, optimal_vclk_div = 0;
188 unsigned optimal_dclk_div = 0, optimal_vco_freq = 0;
189 unsigned vco_freq;
190 int r;
191
192 /* loop through vco from low to high */
193 for (vco_freq = 125000; vco_freq <= 250000; vco_freq += 100) {
194 unsigned fb_div = vco_freq / rdev->clock.spll.reference_freq * 16384;
195 int calc_clk, diff_score, diff_vclk, diff_dclk;
196 unsigned vclk_div, dclk_div;
197
198 /* fb div out of range ? */
199 if (fb_div > 0x03FFFFFF)
200 break; /* it can oly get worse */
201
202 /* calc vclk with current vco freq. */
203 calc_clk = evergreen_uvd_calc_post_div(vclk, vco_freq, &vclk_div);
204 if (calc_clk == -1)
205 break; /* vco is too big, it has to stop. */
206 diff_vclk = vclk - calc_clk;
207
208 /* calc dclk with current vco freq. */
209 calc_clk = evergreen_uvd_calc_post_div(dclk, vco_freq, &dclk_div);
210 if (calc_clk == -1)
211 break; /* vco is too big, it has to stop. */
212 diff_dclk = dclk - calc_clk;
213
214 /* determine if this vco setting is better than current optimal settings */
215 diff_score = abs(diff_vclk) + abs(diff_dclk);
216 if (diff_score < optimal_diff_score) {
217 optimal_fb_div = fb_div;
218 optimal_vclk_div = vclk_div;
219 optimal_dclk_div = dclk_div;
220 optimal_vco_freq = vco_freq;
221 optimal_diff_score = diff_score;
222 if (optimal_diff_score == 0)
223 break; /* it can't get better than this */
224 }
225 }
226
227 /* set VCO_MODE to 1 */
228 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
229
230 /* toggle UPLL_SLEEP to 1 then back to 0 */
231 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
232 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
233
234 /* deassert UPLL_RESET */
235 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
236
237 mdelay(1);
238
239 /* bypass vclk and dclk with bclk */
240 WREG32_P(CG_UPLL_FUNC_CNTL_2,
241 VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
242 ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
243
244 /* put PLL in bypass mode */
245 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
246
247 r = evergreen_uvd_send_upll_ctlreq(rdev);
248 if (r)
249 return r;
250
251 /* assert UPLL_RESET again */
252 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
253
254 /* disable spread spectrum. */
255 WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
256
257 /* set feedback divider */
258 WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(optimal_fb_div), ~UPLL_FB_DIV_MASK);
259
260 /* set ref divider to 0 */
261 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
262
263 if (optimal_vco_freq < 187500)
264 WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
265 else
266 WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
267
268 /* set PDIV_A and PDIV_B */
269 WREG32_P(CG_UPLL_FUNC_CNTL_2,
270 UPLL_PDIV_A(optimal_vclk_div) | UPLL_PDIV_B(optimal_dclk_div),
271 ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
272
273 /* give the PLL some time to settle */
274 mdelay(15);
275
276 /* deassert PLL_RESET */
277 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
278
279 mdelay(15);
280
281 /* switch from bypass mode to normal mode */
282 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
283
284 r = evergreen_uvd_send_upll_ctlreq(rdev);
285 if (r)
286 return r;
287
288 /* switch VCLK and DCLK selection */
289 WREG32_P(CG_UPLL_FUNC_CNTL_2,
290 VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
291 ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
292
293 mdelay(100);
294
295 return 0;
296}
297
Alex Deucherd054ac12011-09-01 17:46:15 +0000298void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev)
299{
300 u16 ctl, v;
Jiang Liu32195ae2012-07-24 17:20:30 +0800301 int err;
Alex Deucherd054ac12011-09-01 17:46:15 +0000302
Jiang Liu32195ae2012-07-24 17:20:30 +0800303 err = pcie_capability_read_word(rdev->pdev, PCI_EXP_DEVCTL, &ctl);
Alex Deucherd054ac12011-09-01 17:46:15 +0000304 if (err)
305 return;
306
307 v = (ctl & PCI_EXP_DEVCTL_READRQ) >> 12;
308
309 /* if bios or OS sets MAX_READ_REQUEST_SIZE to an invalid value, fix it
310 * to avoid hangs or perfomance issues
311 */
312 if ((v == 0) || (v == 6) || (v == 7)) {
313 ctl &= ~PCI_EXP_DEVCTL_READRQ;
314 ctl |= (2 << 12);
Jiang Liu32195ae2012-07-24 17:20:30 +0800315 pcie_capability_write_word(rdev->pdev, PCI_EXP_DEVCTL, ctl);
Alex Deucherd054ac12011-09-01 17:46:15 +0000316 }
317}
318
Alex Deucher377edc82012-07-17 14:02:42 -0400319/**
320 * dce4_wait_for_vblank - vblank wait asic callback.
321 *
322 * @rdev: radeon_device pointer
323 * @crtc: crtc to wait for vblank on
324 *
325 * Wait for vblank on the requested crtc (evergreen+).
326 */
Alex Deucher3ae19b72012-02-23 17:53:37 -0500327void dce4_wait_for_vblank(struct radeon_device *rdev, int crtc)
328{
Alex Deucher3ae19b72012-02-23 17:53:37 -0500329 int i;
330
Alex Deucher4a159032012-08-15 17:13:53 -0400331 if (crtc >= rdev->num_crtc)
332 return;
333
334 if (RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[crtc]) & EVERGREEN_CRTC_MASTER_EN) {
Alex Deucher3ae19b72012-02-23 17:53:37 -0500335 for (i = 0; i < rdev->usec_timeout; i++) {
Alex Deucher4a159032012-08-15 17:13:53 -0400336 if (!(RREG32(EVERGREEN_CRTC_STATUS + crtc_offsets[crtc]) & EVERGREEN_CRTC_V_BLANK))
Alex Deucher3ae19b72012-02-23 17:53:37 -0500337 break;
338 udelay(1);
339 }
340 for (i = 0; i < rdev->usec_timeout; i++) {
Alex Deucher4a159032012-08-15 17:13:53 -0400341 if (RREG32(EVERGREEN_CRTC_STATUS + crtc_offsets[crtc]) & EVERGREEN_CRTC_V_BLANK)
Alex Deucher3ae19b72012-02-23 17:53:37 -0500342 break;
343 udelay(1);
344 }
345 }
346}
347
Alex Deucher377edc82012-07-17 14:02:42 -0400348/**
349 * radeon_irq_kms_pflip_irq_get - pre-pageflip callback.
350 *
351 * @rdev: radeon_device pointer
352 * @crtc: crtc to prepare for pageflip on
353 *
354 * Pre-pageflip callback (evergreen+).
355 * Enables the pageflip irq (vblank irq).
356 */
Alex Deucher6f34be52010-11-21 10:59:01 -0500357void evergreen_pre_page_flip(struct radeon_device *rdev, int crtc)
358{
Alex Deucher6f34be52010-11-21 10:59:01 -0500359 /* enable the pflip int */
360 radeon_irq_kms_pflip_irq_get(rdev, crtc);
361}
362
Alex Deucher377edc82012-07-17 14:02:42 -0400363/**
364 * evergreen_post_page_flip - pos-pageflip callback.
365 *
366 * @rdev: radeon_device pointer
367 * @crtc: crtc to cleanup pageflip on
368 *
369 * Post-pageflip callback (evergreen+).
370 * Disables the pageflip irq (vblank irq).
371 */
Alex Deucher6f34be52010-11-21 10:59:01 -0500372void evergreen_post_page_flip(struct radeon_device *rdev, int crtc)
373{
374 /* disable the pflip int */
375 radeon_irq_kms_pflip_irq_put(rdev, crtc);
376}
377
Alex Deucher377edc82012-07-17 14:02:42 -0400378/**
379 * evergreen_page_flip - pageflip callback.
380 *
381 * @rdev: radeon_device pointer
382 * @crtc_id: crtc to cleanup pageflip on
383 * @crtc_base: new address of the crtc (GPU MC address)
384 *
385 * Does the actual pageflip (evergreen+).
386 * During vblank we take the crtc lock and wait for the update_pending
387 * bit to go high, when it does, we release the lock, and allow the
388 * double buffered update to take place.
389 * Returns the current update pending status.
390 */
Alex Deucher6f34be52010-11-21 10:59:01 -0500391u32 evergreen_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
392{
393 struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
394 u32 tmp = RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset);
Alex Deucherf6496472011-11-28 14:49:26 -0500395 int i;
Alex Deucher6f34be52010-11-21 10:59:01 -0500396
397 /* Lock the graphics update lock */
398 tmp |= EVERGREEN_GRPH_UPDATE_LOCK;
399 WREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
400
401 /* update the scanout addresses */
402 WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
403 upper_32_bits(crtc_base));
404 WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
405 (u32)crtc_base);
406
407 WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
408 upper_32_bits(crtc_base));
409 WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
410 (u32)crtc_base);
411
412 /* Wait for update_pending to go high. */
Alex Deucherf6496472011-11-28 14:49:26 -0500413 for (i = 0; i < rdev->usec_timeout; i++) {
414 if (RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING)
415 break;
416 udelay(1);
417 }
Alex Deucher6f34be52010-11-21 10:59:01 -0500418 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
419
420 /* Unlock the lock, so double-buffering can take place inside vblank */
421 tmp &= ~EVERGREEN_GRPH_UPDATE_LOCK;
422 WREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
423
424 /* Return current update_pending status: */
425 return RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING;
426}
427
Alex Deucher21a81222010-07-02 12:58:16 -0400428/* get temperature in millidegrees */
Alex Deucher20d391d2011-02-01 16:12:34 -0500429int evergreen_get_temp(struct radeon_device *rdev)
Alex Deucher21a81222010-07-02 12:58:16 -0400430{
Alex Deucher1c88d742011-06-14 19:15:53 +0000431 u32 temp, toffset;
432 int actual_temp = 0;
Alex Deucher21a81222010-07-02 12:58:16 -0400433
Alex Deucher67b3f822011-05-25 18:45:37 -0400434 if (rdev->family == CHIP_JUNIPER) {
435 toffset = (RREG32(CG_THERMAL_CTRL) & TOFFSET_MASK) >>
436 TOFFSET_SHIFT;
437 temp = (RREG32(CG_TS0_STATUS) & TS0_ADC_DOUT_MASK) >>
438 TS0_ADC_DOUT_SHIFT;
Alex Deucher21a81222010-07-02 12:58:16 -0400439
Alex Deucher67b3f822011-05-25 18:45:37 -0400440 if (toffset & 0x100)
441 actual_temp = temp / 2 - (0x200 - toffset);
442 else
443 actual_temp = temp / 2 + toffset;
444
445 actual_temp = actual_temp * 1000;
446
447 } else {
448 temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >>
449 ASIC_T_SHIFT;
450
451 if (temp & 0x400)
452 actual_temp = -256;
453 else if (temp & 0x200)
454 actual_temp = 255;
455 else if (temp & 0x100) {
456 actual_temp = temp & 0x1ff;
457 actual_temp |= ~0x1ff;
458 } else
459 actual_temp = temp & 0xff;
460
461 actual_temp = (actual_temp * 1000) / 2;
462 }
463
464 return actual_temp;
Alex Deucher21a81222010-07-02 12:58:16 -0400465}
466
Alex Deucher20d391d2011-02-01 16:12:34 -0500467int sumo_get_temp(struct radeon_device *rdev)
Alex Deuchere33df252010-11-22 17:56:32 -0500468{
469 u32 temp = RREG32(CG_THERMAL_STATUS) & 0xff;
Alex Deucher20d391d2011-02-01 16:12:34 -0500470 int actual_temp = temp - 49;
Alex Deuchere33df252010-11-22 17:56:32 -0500471
472 return actual_temp * 1000;
473}
474
Alex Deucher377edc82012-07-17 14:02:42 -0400475/**
476 * sumo_pm_init_profile - Initialize power profiles callback.
477 *
478 * @rdev: radeon_device pointer
479 *
480 * Initialize the power states used in profile mode
481 * (sumo, trinity, SI).
482 * Used for profile mode only.
483 */
Alex Deuchera4c9e2e2011-11-04 10:09:41 -0400484void sumo_pm_init_profile(struct radeon_device *rdev)
485{
486 int idx;
487
488 /* default */
489 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
490 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
491 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
492 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
493
494 /* low,mid sh/mh */
495 if (rdev->flags & RADEON_IS_MOBILITY)
496 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
497 else
498 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
499
500 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
501 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
502 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
503 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
504
505 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
506 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
507 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
508 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
509
510 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
511 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
512 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
513 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
514
515 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
516 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
517 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
518 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
519
520 /* high sh/mh */
521 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
522 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
523 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
524 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
525 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx =
526 rdev->pm.power_state[idx].num_clock_modes - 1;
527
528 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
529 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
530 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
531 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx =
532 rdev->pm.power_state[idx].num_clock_modes - 1;
533}
534
Alex Deucher377edc82012-07-17 14:02:42 -0400535/**
Alex Deucher27810fb2012-10-01 19:25:11 -0400536 * btc_pm_init_profile - Initialize power profiles callback.
537 *
538 * @rdev: radeon_device pointer
539 *
540 * Initialize the power states used in profile mode
541 * (BTC, cayman).
542 * Used for profile mode only.
543 */
544void btc_pm_init_profile(struct radeon_device *rdev)
545{
546 int idx;
547
548 /* default */
549 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
550 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
551 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
552 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
553 /* starting with BTC, there is one state that is used for both
554 * MH and SH. Difference is that we always use the high clock index for
555 * mclk.
556 */
557 if (rdev->flags & RADEON_IS_MOBILITY)
558 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
559 else
560 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
561 /* low sh */
562 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
563 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
564 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
565 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
566 /* mid sh */
567 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
568 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
569 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
570 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
571 /* high sh */
572 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
573 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
574 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
575 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
576 /* low mh */
577 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
578 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
579 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
580 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
581 /* mid mh */
582 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
583 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
584 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
585 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
586 /* high mh */
587 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
588 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
589 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
590 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
591}
592
593/**
Alex Deucher377edc82012-07-17 14:02:42 -0400594 * evergreen_pm_misc - set additional pm hw parameters callback.
595 *
596 * @rdev: radeon_device pointer
597 *
598 * Set non-clock parameters associated with a power state
599 * (voltage, etc.) (evergreen+).
600 */
Alex Deucher49e02b72010-04-23 17:57:27 -0400601void evergreen_pm_misc(struct radeon_device *rdev)
602{
Rafał Miłeckia081a9d2010-06-07 18:20:25 -0400603 int req_ps_idx = rdev->pm.requested_power_state_index;
604 int req_cm_idx = rdev->pm.requested_clock_mode_index;
605 struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
606 struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
Alex Deucher49e02b72010-04-23 17:57:27 -0400607
Alex Deucher2feea492011-04-12 14:49:24 -0400608 if (voltage->type == VOLTAGE_SW) {
Alex Deuchera377e182011-06-20 13:00:31 -0400609 /* 0xff01 is a flag rather then an actual voltage */
610 if (voltage->voltage == 0xff01)
611 return;
Alex Deucher2feea492011-04-12 14:49:24 -0400612 if (voltage->voltage && (voltage->voltage != rdev->pm.current_vddc)) {
Alex Deucher8a83ec52011-04-12 14:49:23 -0400613 radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
Alex Deucher4d601732010-06-07 18:15:18 -0400614 rdev->pm.current_vddc = voltage->voltage;
Alex Deucher2feea492011-04-12 14:49:24 -0400615 DRM_DEBUG("Setting: vddc: %d\n", voltage->voltage);
616 }
Alex Deucher7ae764b2013-02-11 08:44:48 -0500617
618 /* starting with BTC, there is one state that is used for both
619 * MH and SH. Difference is that we always use the high clock index for
620 * mclk and vddci.
621 */
622 if ((rdev->pm.pm_method == PM_METHOD_PROFILE) &&
623 (rdev->family >= CHIP_BARTS) &&
624 rdev->pm.active_crtc_count &&
625 ((rdev->pm.profile_index == PM_PROFILE_MID_MH_IDX) ||
626 (rdev->pm.profile_index == PM_PROFILE_LOW_MH_IDX)))
627 voltage = &rdev->pm.power_state[req_ps_idx].
628 clock_info[rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx].voltage;
629
Alex Deuchera377e182011-06-20 13:00:31 -0400630 /* 0xff01 is a flag rather then an actual voltage */
631 if (voltage->vddci == 0xff01)
632 return;
Alex Deucher2feea492011-04-12 14:49:24 -0400633 if (voltage->vddci && (voltage->vddci != rdev->pm.current_vddci)) {
634 radeon_atom_set_voltage(rdev, voltage->vddci, SET_VOLTAGE_TYPE_ASIC_VDDCI);
635 rdev->pm.current_vddci = voltage->vddci;
636 DRM_DEBUG("Setting: vddci: %d\n", voltage->vddci);
Alex Deucher4d601732010-06-07 18:15:18 -0400637 }
638 }
Alex Deucher49e02b72010-04-23 17:57:27 -0400639}
640
Alex Deucher377edc82012-07-17 14:02:42 -0400641/**
642 * evergreen_pm_prepare - pre-power state change callback.
643 *
644 * @rdev: radeon_device pointer
645 *
646 * Prepare for a power state change (evergreen+).
647 */
Alex Deucher49e02b72010-04-23 17:57:27 -0400648void evergreen_pm_prepare(struct radeon_device *rdev)
649{
650 struct drm_device *ddev = rdev->ddev;
651 struct drm_crtc *crtc;
652 struct radeon_crtc *radeon_crtc;
653 u32 tmp;
654
655 /* disable any active CRTCs */
656 list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
657 radeon_crtc = to_radeon_crtc(crtc);
658 if (radeon_crtc->enabled) {
659 tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
660 tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
661 WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
662 }
663 }
664}
665
Alex Deucher377edc82012-07-17 14:02:42 -0400666/**
667 * evergreen_pm_finish - post-power state change callback.
668 *
669 * @rdev: radeon_device pointer
670 *
671 * Clean up after a power state change (evergreen+).
672 */
Alex Deucher49e02b72010-04-23 17:57:27 -0400673void evergreen_pm_finish(struct radeon_device *rdev)
674{
675 struct drm_device *ddev = rdev->ddev;
676 struct drm_crtc *crtc;
677 struct radeon_crtc *radeon_crtc;
678 u32 tmp;
679
680 /* enable any active CRTCs */
681 list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
682 radeon_crtc = to_radeon_crtc(crtc);
683 if (radeon_crtc->enabled) {
684 tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
685 tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
686 WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
687 }
688 }
689}
690
Alex Deucher377edc82012-07-17 14:02:42 -0400691/**
692 * evergreen_hpd_sense - hpd sense callback.
693 *
694 * @rdev: radeon_device pointer
695 * @hpd: hpd (hotplug detect) pin
696 *
697 * Checks if a digital monitor is connected (evergreen+).
698 * Returns true if connected, false if not connected.
699 */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500700bool evergreen_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
701{
702 bool connected = false;
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500703
704 switch (hpd) {
705 case RADEON_HPD_1:
706 if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
707 connected = true;
708 break;
709 case RADEON_HPD_2:
710 if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
711 connected = true;
712 break;
713 case RADEON_HPD_3:
714 if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
715 connected = true;
716 break;
717 case RADEON_HPD_4:
718 if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
719 connected = true;
720 break;
721 case RADEON_HPD_5:
722 if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
723 connected = true;
724 break;
725 case RADEON_HPD_6:
726 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
727 connected = true;
728 break;
729 default:
730 break;
731 }
732
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500733 return connected;
734}
735
Alex Deucher377edc82012-07-17 14:02:42 -0400736/**
737 * evergreen_hpd_set_polarity - hpd set polarity callback.
738 *
739 * @rdev: radeon_device pointer
740 * @hpd: hpd (hotplug detect) pin
741 *
742 * Set the polarity of the hpd pin (evergreen+).
743 */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500744void evergreen_hpd_set_polarity(struct radeon_device *rdev,
745 enum radeon_hpd_id hpd)
746{
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500747 u32 tmp;
748 bool connected = evergreen_hpd_sense(rdev, hpd);
749
750 switch (hpd) {
751 case RADEON_HPD_1:
752 tmp = RREG32(DC_HPD1_INT_CONTROL);
753 if (connected)
754 tmp &= ~DC_HPDx_INT_POLARITY;
755 else
756 tmp |= DC_HPDx_INT_POLARITY;
757 WREG32(DC_HPD1_INT_CONTROL, tmp);
758 break;
759 case RADEON_HPD_2:
760 tmp = RREG32(DC_HPD2_INT_CONTROL);
761 if (connected)
762 tmp &= ~DC_HPDx_INT_POLARITY;
763 else
764 tmp |= DC_HPDx_INT_POLARITY;
765 WREG32(DC_HPD2_INT_CONTROL, tmp);
766 break;
767 case RADEON_HPD_3:
768 tmp = RREG32(DC_HPD3_INT_CONTROL);
769 if (connected)
770 tmp &= ~DC_HPDx_INT_POLARITY;
771 else
772 tmp |= DC_HPDx_INT_POLARITY;
773 WREG32(DC_HPD3_INT_CONTROL, tmp);
774 break;
775 case RADEON_HPD_4:
776 tmp = RREG32(DC_HPD4_INT_CONTROL);
777 if (connected)
778 tmp &= ~DC_HPDx_INT_POLARITY;
779 else
780 tmp |= DC_HPDx_INT_POLARITY;
781 WREG32(DC_HPD4_INT_CONTROL, tmp);
782 break;
783 case RADEON_HPD_5:
784 tmp = RREG32(DC_HPD5_INT_CONTROL);
785 if (connected)
786 tmp &= ~DC_HPDx_INT_POLARITY;
787 else
788 tmp |= DC_HPDx_INT_POLARITY;
789 WREG32(DC_HPD5_INT_CONTROL, tmp);
790 break;
791 case RADEON_HPD_6:
792 tmp = RREG32(DC_HPD6_INT_CONTROL);
793 if (connected)
794 tmp &= ~DC_HPDx_INT_POLARITY;
795 else
796 tmp |= DC_HPDx_INT_POLARITY;
797 WREG32(DC_HPD6_INT_CONTROL, tmp);
798 break;
799 default:
800 break;
801 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500802}
803
Alex Deucher377edc82012-07-17 14:02:42 -0400804/**
805 * evergreen_hpd_init - hpd setup callback.
806 *
807 * @rdev: radeon_device pointer
808 *
809 * Setup the hpd pins used by the card (evergreen+).
810 * Enable the pin, set the polarity, and enable the hpd interrupts.
811 */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500812void evergreen_hpd_init(struct radeon_device *rdev)
813{
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500814 struct drm_device *dev = rdev->ddev;
815 struct drm_connector *connector;
Christian Koenigfb982572012-05-17 01:33:30 +0200816 unsigned enabled = 0;
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500817 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) |
818 DC_HPDx_RX_INT_TIMER(0xfa) | DC_HPDx_EN;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500819
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500820 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
821 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
822 switch (radeon_connector->hpd.hpd) {
823 case RADEON_HPD_1:
824 WREG32(DC_HPD1_CONTROL, tmp);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500825 break;
826 case RADEON_HPD_2:
827 WREG32(DC_HPD2_CONTROL, tmp);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500828 break;
829 case RADEON_HPD_3:
830 WREG32(DC_HPD3_CONTROL, tmp);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500831 break;
832 case RADEON_HPD_4:
833 WREG32(DC_HPD4_CONTROL, tmp);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500834 break;
835 case RADEON_HPD_5:
836 WREG32(DC_HPD5_CONTROL, tmp);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500837 break;
838 case RADEON_HPD_6:
839 WREG32(DC_HPD6_CONTROL, tmp);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500840 break;
841 default:
842 break;
843 }
Alex Deucher64912e92011-11-03 11:21:39 -0400844 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
Christian Koenigfb982572012-05-17 01:33:30 +0200845 enabled |= 1 << radeon_connector->hpd.hpd;
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500846 }
Christian Koenigfb982572012-05-17 01:33:30 +0200847 radeon_irq_kms_enable_hpd(rdev, enabled);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500848}
849
Alex Deucher377edc82012-07-17 14:02:42 -0400850/**
851 * evergreen_hpd_fini - hpd tear down callback.
852 *
853 * @rdev: radeon_device pointer
854 *
855 * Tear down the hpd pins used by the card (evergreen+).
856 * Disable the hpd interrupts.
857 */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500858void evergreen_hpd_fini(struct radeon_device *rdev)
859{
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500860 struct drm_device *dev = rdev->ddev;
861 struct drm_connector *connector;
Christian Koenigfb982572012-05-17 01:33:30 +0200862 unsigned disabled = 0;
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500863
864 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
865 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
866 switch (radeon_connector->hpd.hpd) {
867 case RADEON_HPD_1:
868 WREG32(DC_HPD1_CONTROL, 0);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500869 break;
870 case RADEON_HPD_2:
871 WREG32(DC_HPD2_CONTROL, 0);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500872 break;
873 case RADEON_HPD_3:
874 WREG32(DC_HPD3_CONTROL, 0);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500875 break;
876 case RADEON_HPD_4:
877 WREG32(DC_HPD4_CONTROL, 0);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500878 break;
879 case RADEON_HPD_5:
880 WREG32(DC_HPD5_CONTROL, 0);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500881 break;
882 case RADEON_HPD_6:
883 WREG32(DC_HPD6_CONTROL, 0);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500884 break;
885 default:
886 break;
887 }
Christian Koenigfb982572012-05-17 01:33:30 +0200888 disabled |= 1 << radeon_connector->hpd.hpd;
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500889 }
Christian Koenigfb982572012-05-17 01:33:30 +0200890 radeon_irq_kms_disable_hpd(rdev, disabled);
Alex Deucher0ca2ab52010-02-26 13:57:45 -0500891}
892
Alex Deucherf9d9c362010-10-22 02:51:05 -0400893/* watermark setup */
894
895static u32 evergreen_line_buffer_adjust(struct radeon_device *rdev,
896 struct radeon_crtc *radeon_crtc,
897 struct drm_display_mode *mode,
898 struct drm_display_mode *other_mode)
899{
Alex Deucher12dfc842011-04-14 19:07:34 -0400900 u32 tmp;
Alex Deucherf9d9c362010-10-22 02:51:05 -0400901 /*
902 * Line Buffer Setup
903 * There are 3 line buffers, each one shared by 2 display controllers.
904 * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
905 * the display controllers. The paritioning is done via one of four
906 * preset allocations specified in bits 2:0:
907 * first display controller
908 * 0 - first half of lb (3840 * 2)
909 * 1 - first 3/4 of lb (5760 * 2)
Alex Deucher12dfc842011-04-14 19:07:34 -0400910 * 2 - whole lb (7680 * 2), other crtc must be disabled
Alex Deucherf9d9c362010-10-22 02:51:05 -0400911 * 3 - first 1/4 of lb (1920 * 2)
912 * second display controller
913 * 4 - second half of lb (3840 * 2)
914 * 5 - second 3/4 of lb (5760 * 2)
Alex Deucher12dfc842011-04-14 19:07:34 -0400915 * 6 - whole lb (7680 * 2), other crtc must be disabled
Alex Deucherf9d9c362010-10-22 02:51:05 -0400916 * 7 - last 1/4 of lb (1920 * 2)
917 */
Alex Deucher12dfc842011-04-14 19:07:34 -0400918 /* this can get tricky if we have two large displays on a paired group
919 * of crtcs. Ideally for multiple large displays we'd assign them to
920 * non-linked crtcs for maximum line buffer allocation.
921 */
922 if (radeon_crtc->base.enabled && mode) {
923 if (other_mode)
Alex Deucherf9d9c362010-10-22 02:51:05 -0400924 tmp = 0; /* 1/2 */
Alex Deucher12dfc842011-04-14 19:07:34 -0400925 else
926 tmp = 2; /* whole */
927 } else
928 tmp = 0;
Alex Deucherf9d9c362010-10-22 02:51:05 -0400929
930 /* second controller of the pair uses second half of the lb */
931 if (radeon_crtc->crtc_id % 2)
932 tmp += 4;
933 WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset, tmp);
934
Alex Deucher12dfc842011-04-14 19:07:34 -0400935 if (radeon_crtc->base.enabled && mode) {
936 switch (tmp) {
937 case 0:
938 case 4:
939 default:
940 if (ASIC_IS_DCE5(rdev))
941 return 4096 * 2;
942 else
943 return 3840 * 2;
944 case 1:
945 case 5:
946 if (ASIC_IS_DCE5(rdev))
947 return 6144 * 2;
948 else
949 return 5760 * 2;
950 case 2:
951 case 6:
952 if (ASIC_IS_DCE5(rdev))
953 return 8192 * 2;
954 else
955 return 7680 * 2;
956 case 3:
957 case 7:
958 if (ASIC_IS_DCE5(rdev))
959 return 2048 * 2;
960 else
961 return 1920 * 2;
962 }
Alex Deucherf9d9c362010-10-22 02:51:05 -0400963 }
Alex Deucher12dfc842011-04-14 19:07:34 -0400964
965 /* controller not enabled, so no lb used */
966 return 0;
Alex Deucherf9d9c362010-10-22 02:51:05 -0400967}
968
Alex Deucherca7db222012-03-20 17:18:30 -0400969u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev)
Alex Deucherf9d9c362010-10-22 02:51:05 -0400970{
971 u32 tmp = RREG32(MC_SHARED_CHMAP);
972
973 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
974 case 0:
975 default:
976 return 1;
977 case 1:
978 return 2;
979 case 2:
980 return 4;
981 case 3:
982 return 8;
983 }
984}
985
986struct evergreen_wm_params {
987 u32 dram_channels; /* number of dram channels */
988 u32 yclk; /* bandwidth per dram data pin in kHz */
989 u32 sclk; /* engine clock in kHz */
990 u32 disp_clk; /* display clock in kHz */
991 u32 src_width; /* viewport width */
992 u32 active_time; /* active display time in ns */
993 u32 blank_time; /* blank time in ns */
994 bool interlaced; /* mode is interlaced */
995 fixed20_12 vsc; /* vertical scale ratio */
996 u32 num_heads; /* number of active crtcs */
997 u32 bytes_per_pixel; /* bytes per pixel display + overlay */
998 u32 lb_size; /* line buffer allocated to pipe */
999 u32 vtaps; /* vertical scaler taps */
1000};
1001
1002static u32 evergreen_dram_bandwidth(struct evergreen_wm_params *wm)
1003{
1004 /* Calculate DRAM Bandwidth and the part allocated to display. */
1005 fixed20_12 dram_efficiency; /* 0.7 */
1006 fixed20_12 yclk, dram_channels, bandwidth;
1007 fixed20_12 a;
1008
1009 a.full = dfixed_const(1000);
1010 yclk.full = dfixed_const(wm->yclk);
1011 yclk.full = dfixed_div(yclk, a);
1012 dram_channels.full = dfixed_const(wm->dram_channels * 4);
1013 a.full = dfixed_const(10);
1014 dram_efficiency.full = dfixed_const(7);
1015 dram_efficiency.full = dfixed_div(dram_efficiency, a);
1016 bandwidth.full = dfixed_mul(dram_channels, yclk);
1017 bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
1018
1019 return dfixed_trunc(bandwidth);
1020}
1021
1022static u32 evergreen_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
1023{
1024 /* Calculate DRAM Bandwidth and the part allocated to display. */
1025 fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
1026 fixed20_12 yclk, dram_channels, bandwidth;
1027 fixed20_12 a;
1028
1029 a.full = dfixed_const(1000);
1030 yclk.full = dfixed_const(wm->yclk);
1031 yclk.full = dfixed_div(yclk, a);
1032 dram_channels.full = dfixed_const(wm->dram_channels * 4);
1033 a.full = dfixed_const(10);
1034 disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
1035 disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
1036 bandwidth.full = dfixed_mul(dram_channels, yclk);
1037 bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
1038
1039 return dfixed_trunc(bandwidth);
1040}
1041
1042static u32 evergreen_data_return_bandwidth(struct evergreen_wm_params *wm)
1043{
1044 /* Calculate the display Data return Bandwidth */
1045 fixed20_12 return_efficiency; /* 0.8 */
1046 fixed20_12 sclk, bandwidth;
1047 fixed20_12 a;
1048
1049 a.full = dfixed_const(1000);
1050 sclk.full = dfixed_const(wm->sclk);
1051 sclk.full = dfixed_div(sclk, a);
1052 a.full = dfixed_const(10);
1053 return_efficiency.full = dfixed_const(8);
1054 return_efficiency.full = dfixed_div(return_efficiency, a);
1055 a.full = dfixed_const(32);
1056 bandwidth.full = dfixed_mul(a, sclk);
1057 bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
1058
1059 return dfixed_trunc(bandwidth);
1060}
1061
1062static u32 evergreen_dmif_request_bandwidth(struct evergreen_wm_params *wm)
1063{
1064 /* Calculate the DMIF Request Bandwidth */
1065 fixed20_12 disp_clk_request_efficiency; /* 0.8 */
1066 fixed20_12 disp_clk, bandwidth;
1067 fixed20_12 a;
1068
1069 a.full = dfixed_const(1000);
1070 disp_clk.full = dfixed_const(wm->disp_clk);
1071 disp_clk.full = dfixed_div(disp_clk, a);
1072 a.full = dfixed_const(10);
1073 disp_clk_request_efficiency.full = dfixed_const(8);
1074 disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
1075 a.full = dfixed_const(32);
1076 bandwidth.full = dfixed_mul(a, disp_clk);
1077 bandwidth.full = dfixed_mul(bandwidth, disp_clk_request_efficiency);
1078
1079 return dfixed_trunc(bandwidth);
1080}
1081
1082static u32 evergreen_available_bandwidth(struct evergreen_wm_params *wm)
1083{
1084 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
1085 u32 dram_bandwidth = evergreen_dram_bandwidth(wm);
1086 u32 data_return_bandwidth = evergreen_data_return_bandwidth(wm);
1087 u32 dmif_req_bandwidth = evergreen_dmif_request_bandwidth(wm);
1088
1089 return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
1090}
1091
1092static u32 evergreen_average_bandwidth(struct evergreen_wm_params *wm)
1093{
1094 /* Calculate the display mode Average Bandwidth
1095 * DisplayMode should contain the source and destination dimensions,
1096 * timing, etc.
1097 */
1098 fixed20_12 bpp;
1099 fixed20_12 line_time;
1100 fixed20_12 src_width;
1101 fixed20_12 bandwidth;
1102 fixed20_12 a;
1103
1104 a.full = dfixed_const(1000);
1105 line_time.full = dfixed_const(wm->active_time + wm->blank_time);
1106 line_time.full = dfixed_div(line_time, a);
1107 bpp.full = dfixed_const(wm->bytes_per_pixel);
1108 src_width.full = dfixed_const(wm->src_width);
1109 bandwidth.full = dfixed_mul(src_width, bpp);
1110 bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
1111 bandwidth.full = dfixed_div(bandwidth, line_time);
1112
1113 return dfixed_trunc(bandwidth);
1114}
1115
1116static u32 evergreen_latency_watermark(struct evergreen_wm_params *wm)
1117{
1118 /* First calcualte the latency in ns */
1119 u32 mc_latency = 2000; /* 2000 ns. */
1120 u32 available_bandwidth = evergreen_available_bandwidth(wm);
1121 u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
1122 u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
1123 u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
1124 u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
1125 (wm->num_heads * cursor_line_pair_return_time);
1126 u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
1127 u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
1128 fixed20_12 a, b, c;
1129
1130 if (wm->num_heads == 0)
1131 return 0;
1132
1133 a.full = dfixed_const(2);
1134 b.full = dfixed_const(1);
1135 if ((wm->vsc.full > a.full) ||
1136 ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
1137 (wm->vtaps >= 5) ||
1138 ((wm->vsc.full >= a.full) && wm->interlaced))
1139 max_src_lines_per_dst_line = 4;
1140 else
1141 max_src_lines_per_dst_line = 2;
1142
1143 a.full = dfixed_const(available_bandwidth);
1144 b.full = dfixed_const(wm->num_heads);
1145 a.full = dfixed_div(a, b);
1146
1147 b.full = dfixed_const(1000);
1148 c.full = dfixed_const(wm->disp_clk);
1149 b.full = dfixed_div(c, b);
1150 c.full = dfixed_const(wm->bytes_per_pixel);
1151 b.full = dfixed_mul(b, c);
1152
1153 lb_fill_bw = min(dfixed_trunc(a), dfixed_trunc(b));
1154
1155 a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
1156 b.full = dfixed_const(1000);
1157 c.full = dfixed_const(lb_fill_bw);
1158 b.full = dfixed_div(c, b);
1159 a.full = dfixed_div(a, b);
1160 line_fill_time = dfixed_trunc(a);
1161
1162 if (line_fill_time < wm->active_time)
1163 return latency;
1164 else
1165 return latency + (line_fill_time - wm->active_time);
1166
1167}
1168
1169static bool evergreen_average_bandwidth_vs_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
1170{
1171 if (evergreen_average_bandwidth(wm) <=
1172 (evergreen_dram_bandwidth_for_display(wm) / wm->num_heads))
1173 return true;
1174 else
1175 return false;
1176};
1177
1178static bool evergreen_average_bandwidth_vs_available_bandwidth(struct evergreen_wm_params *wm)
1179{
1180 if (evergreen_average_bandwidth(wm) <=
1181 (evergreen_available_bandwidth(wm) / wm->num_heads))
1182 return true;
1183 else
1184 return false;
1185};
1186
1187static bool evergreen_check_latency_hiding(struct evergreen_wm_params *wm)
1188{
1189 u32 lb_partitions = wm->lb_size / wm->src_width;
1190 u32 line_time = wm->active_time + wm->blank_time;
1191 u32 latency_tolerant_lines;
1192 u32 latency_hiding;
1193 fixed20_12 a;
1194
1195 a.full = dfixed_const(1);
1196 if (wm->vsc.full > a.full)
1197 latency_tolerant_lines = 1;
1198 else {
1199 if (lb_partitions <= (wm->vtaps + 1))
1200 latency_tolerant_lines = 1;
1201 else
1202 latency_tolerant_lines = 2;
1203 }
1204
1205 latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
1206
1207 if (evergreen_latency_watermark(wm) <= latency_hiding)
1208 return true;
1209 else
1210 return false;
1211}
1212
1213static void evergreen_program_watermarks(struct radeon_device *rdev,
1214 struct radeon_crtc *radeon_crtc,
1215 u32 lb_size, u32 num_heads)
1216{
1217 struct drm_display_mode *mode = &radeon_crtc->base.mode;
1218 struct evergreen_wm_params wm;
1219 u32 pixel_period;
1220 u32 line_time = 0;
1221 u32 latency_watermark_a = 0, latency_watermark_b = 0;
1222 u32 priority_a_mark = 0, priority_b_mark = 0;
1223 u32 priority_a_cnt = PRIORITY_OFF;
1224 u32 priority_b_cnt = PRIORITY_OFF;
1225 u32 pipe_offset = radeon_crtc->crtc_id * 16;
1226 u32 tmp, arb_control3;
1227 fixed20_12 a, b, c;
1228
1229 if (radeon_crtc->base.enabled && num_heads && mode) {
1230 pixel_period = 1000000 / (u32)mode->clock;
1231 line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
1232 priority_a_cnt = 0;
1233 priority_b_cnt = 0;
1234
1235 wm.yclk = rdev->pm.current_mclk * 10;
1236 wm.sclk = rdev->pm.current_sclk * 10;
1237 wm.disp_clk = mode->clock;
1238 wm.src_width = mode->crtc_hdisplay;
1239 wm.active_time = mode->crtc_hdisplay * pixel_period;
1240 wm.blank_time = line_time - wm.active_time;
1241 wm.interlaced = false;
1242 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1243 wm.interlaced = true;
1244 wm.vsc = radeon_crtc->vsc;
1245 wm.vtaps = 1;
1246 if (radeon_crtc->rmx_type != RMX_OFF)
1247 wm.vtaps = 2;
1248 wm.bytes_per_pixel = 4; /* XXX: get this from fb config */
1249 wm.lb_size = lb_size;
1250 wm.dram_channels = evergreen_get_number_of_dram_channels(rdev);
1251 wm.num_heads = num_heads;
1252
1253 /* set for high clocks */
1254 latency_watermark_a = min(evergreen_latency_watermark(&wm), (u32)65535);
1255 /* set for low clocks */
1256 /* wm.yclk = low clk; wm.sclk = low clk */
1257 latency_watermark_b = min(evergreen_latency_watermark(&wm), (u32)65535);
1258
1259 /* possibly force display priority to high */
1260 /* should really do this at mode validation time... */
1261 if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm) ||
1262 !evergreen_average_bandwidth_vs_available_bandwidth(&wm) ||
1263 !evergreen_check_latency_hiding(&wm) ||
1264 (rdev->disp_priority == 2)) {
Alex Deucher92bdfd42011-08-04 17:28:40 +00001265 DRM_DEBUG_KMS("force priority to high\n");
Alex Deucherf9d9c362010-10-22 02:51:05 -04001266 priority_a_cnt |= PRIORITY_ALWAYS_ON;
1267 priority_b_cnt |= PRIORITY_ALWAYS_ON;
1268 }
1269
1270 a.full = dfixed_const(1000);
1271 b.full = dfixed_const(mode->clock);
1272 b.full = dfixed_div(b, a);
1273 c.full = dfixed_const(latency_watermark_a);
1274 c.full = dfixed_mul(c, b);
1275 c.full = dfixed_mul(c, radeon_crtc->hsc);
1276 c.full = dfixed_div(c, a);
1277 a.full = dfixed_const(16);
1278 c.full = dfixed_div(c, a);
1279 priority_a_mark = dfixed_trunc(c);
1280 priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
1281
1282 a.full = dfixed_const(1000);
1283 b.full = dfixed_const(mode->clock);
1284 b.full = dfixed_div(b, a);
1285 c.full = dfixed_const(latency_watermark_b);
1286 c.full = dfixed_mul(c, b);
1287 c.full = dfixed_mul(c, radeon_crtc->hsc);
1288 c.full = dfixed_div(c, a);
1289 a.full = dfixed_const(16);
1290 c.full = dfixed_div(c, a);
1291 priority_b_mark = dfixed_trunc(c);
1292 priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
1293 }
1294
1295 /* select wm A */
1296 arb_control3 = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
1297 tmp = arb_control3;
1298 tmp &= ~LATENCY_WATERMARK_MASK(3);
1299 tmp |= LATENCY_WATERMARK_MASK(1);
1300 WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
1301 WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
1302 (LATENCY_LOW_WATERMARK(latency_watermark_a) |
1303 LATENCY_HIGH_WATERMARK(line_time)));
1304 /* select wm B */
1305 tmp = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
1306 tmp &= ~LATENCY_WATERMARK_MASK(3);
1307 tmp |= LATENCY_WATERMARK_MASK(2);
1308 WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
1309 WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
1310 (LATENCY_LOW_WATERMARK(latency_watermark_b) |
1311 LATENCY_HIGH_WATERMARK(line_time)));
1312 /* restore original selection */
1313 WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, arb_control3);
1314
1315 /* write the priority marks */
1316 WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
1317 WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
1318
1319}
1320
Alex Deucher377edc82012-07-17 14:02:42 -04001321/**
1322 * evergreen_bandwidth_update - update display watermarks callback.
1323 *
1324 * @rdev: radeon_device pointer
1325 *
1326 * Update the display watermarks based on the requested mode(s)
1327 * (evergreen+).
1328 */
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001329void evergreen_bandwidth_update(struct radeon_device *rdev)
1330{
Alex Deucherf9d9c362010-10-22 02:51:05 -04001331 struct drm_display_mode *mode0 = NULL;
1332 struct drm_display_mode *mode1 = NULL;
1333 u32 num_heads = 0, lb_size;
1334 int i;
1335
1336 radeon_update_display_priority(rdev);
1337
1338 for (i = 0; i < rdev->num_crtc; i++) {
1339 if (rdev->mode_info.crtcs[i]->base.enabled)
1340 num_heads++;
1341 }
1342 for (i = 0; i < rdev->num_crtc; i += 2) {
1343 mode0 = &rdev->mode_info.crtcs[i]->base.mode;
1344 mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
1345 lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
1346 evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
1347 lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
1348 evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
1349 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001350}
1351
Alex Deucher377edc82012-07-17 14:02:42 -04001352/**
1353 * evergreen_mc_wait_for_idle - wait for MC idle callback.
1354 *
1355 * @rdev: radeon_device pointer
1356 *
1357 * Wait for the MC (memory controller) to be idle.
1358 * (evergreen+).
1359 * Returns 0 if the MC is idle, -1 if not.
1360 */
Alex Deucherb9952a82011-03-02 20:07:33 -05001361int evergreen_mc_wait_for_idle(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001362{
1363 unsigned i;
1364 u32 tmp;
1365
1366 for (i = 0; i < rdev->usec_timeout; i++) {
1367 /* read MC_STATUS */
1368 tmp = RREG32(SRBM_STATUS) & 0x1F00;
1369 if (!tmp)
1370 return 0;
1371 udelay(1);
1372 }
1373 return -1;
1374}
1375
1376/*
1377 * GART
1378 */
Alex Deucher0fcdb612010-03-24 13:20:41 -04001379void evergreen_pcie_gart_tlb_flush(struct radeon_device *rdev)
1380{
1381 unsigned i;
1382 u32 tmp;
1383
Alex Deucher6f2f48a2010-12-15 11:01:56 -05001384 WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
1385
Alex Deucher0fcdb612010-03-24 13:20:41 -04001386 WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
1387 for (i = 0; i < rdev->usec_timeout; i++) {
1388 /* read MC_STATUS */
1389 tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
1390 tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
1391 if (tmp == 2) {
1392 printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
1393 return;
1394 }
1395 if (tmp) {
1396 return;
1397 }
1398 udelay(1);
1399 }
1400}
1401
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001402static int evergreen_pcie_gart_enable(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001403{
1404 u32 tmp;
Alex Deucher0fcdb612010-03-24 13:20:41 -04001405 int r;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001406
Jerome Glissec9a1be92011-11-03 11:16:49 -04001407 if (rdev->gart.robj == NULL) {
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001408 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
1409 return -EINVAL;
1410 }
1411 r = radeon_gart_table_vram_pin(rdev);
1412 if (r)
1413 return r;
Dave Airlie82568562010-02-05 16:00:07 +10001414 radeon_gart_restore(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001415 /* Setup L2 cache */
1416 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
1417 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
1418 EFFECTIVE_L2_QUEUE_SIZE(7));
1419 WREG32(VM_L2_CNTL2, 0);
1420 WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
1421 /* Setup TLB control */
1422 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
1423 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
1424 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
1425 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
Alex Deucher8aeb96f2011-05-03 19:28:02 -04001426 if (rdev->flags & RADEON_IS_IGP) {
1427 WREG32(FUS_MC_VM_MD_L1_TLB0_CNTL, tmp);
1428 WREG32(FUS_MC_VM_MD_L1_TLB1_CNTL, tmp);
1429 WREG32(FUS_MC_VM_MD_L1_TLB2_CNTL, tmp);
1430 } else {
1431 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
1432 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
1433 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
Alex Deucher0b8c30b2012-05-31 18:54:43 -04001434 if ((rdev->family == CHIP_JUNIPER) ||
1435 (rdev->family == CHIP_CYPRESS) ||
1436 (rdev->family == CHIP_HEMLOCK) ||
1437 (rdev->family == CHIP_BARTS))
1438 WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp);
Alex Deucher8aeb96f2011-05-03 19:28:02 -04001439 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001440 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
1441 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
1442 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
1443 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
1444 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
1445 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
1446 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
1447 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
1448 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
1449 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
1450 (u32)(rdev->dummy_page.addr >> 12));
Alex Deucher0fcdb612010-03-24 13:20:41 -04001451 WREG32(VM_CONTEXT1_CNTL, 0);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001452
Alex Deucher0fcdb612010-03-24 13:20:41 -04001453 evergreen_pcie_gart_tlb_flush(rdev);
Tormod Voldenfcf4de52011-08-31 21:54:07 +00001454 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
1455 (unsigned)(rdev->mc.gtt_size >> 20),
1456 (unsigned long long)rdev->gart.table_addr);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001457 rdev->gart.ready = true;
1458 return 0;
1459}
1460
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001461static void evergreen_pcie_gart_disable(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001462{
1463 u32 tmp;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001464
1465 /* Disable all tables */
Alex Deucher0fcdb612010-03-24 13:20:41 -04001466 WREG32(VM_CONTEXT0_CNTL, 0);
1467 WREG32(VM_CONTEXT1_CNTL, 0);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001468
1469 /* Setup L2 cache */
1470 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
1471 EFFECTIVE_L2_QUEUE_SIZE(7));
1472 WREG32(VM_L2_CNTL2, 0);
1473 WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
1474 /* Setup TLB control */
1475 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
1476 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
1477 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
1478 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
1479 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
1480 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
1481 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
1482 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
Jerome Glissec9a1be92011-11-03 11:16:49 -04001483 radeon_gart_table_vram_unpin(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001484}
1485
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001486static void evergreen_pcie_gart_fini(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001487{
1488 evergreen_pcie_gart_disable(rdev);
1489 radeon_gart_table_vram_free(rdev);
1490 radeon_gart_fini(rdev);
1491}
1492
1493
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001494static void evergreen_agp_enable(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001495{
1496 u32 tmp;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001497
1498 /* Setup L2 cache */
1499 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
1500 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
1501 EFFECTIVE_L2_QUEUE_SIZE(7));
1502 WREG32(VM_L2_CNTL2, 0);
1503 WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
1504 /* Setup TLB control */
1505 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
1506 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
1507 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
1508 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
1509 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
1510 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
1511 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
1512 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
1513 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
1514 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
1515 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
Alex Deucher0fcdb612010-03-24 13:20:41 -04001516 WREG32(VM_CONTEXT0_CNTL, 0);
1517 WREG32(VM_CONTEXT1_CNTL, 0);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001518}
1519
Alex Deucherb9952a82011-03-02 20:07:33 -05001520void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001521{
Alex Deucher62444b72012-08-15 17:18:42 -04001522 u32 crtc_enabled, tmp, frame_count, blackout;
1523 int i, j;
1524
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001525 save->vga_render_control = RREG32(VGA_RENDER_CONTROL);
1526 save->vga_hdp_control = RREG32(VGA_HDP_CONTROL);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001527
Alex Deucher62444b72012-08-15 17:18:42 -04001528 /* disable VGA render */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001529 WREG32(VGA_RENDER_CONTROL, 0);
Alex Deucher62444b72012-08-15 17:18:42 -04001530 /* blank the display controllers */
1531 for (i = 0; i < rdev->num_crtc; i++) {
1532 crtc_enabled = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN;
1533 if (crtc_enabled) {
1534 save->crtc_enabled[i] = true;
1535 if (ASIC_IS_DCE6(rdev)) {
1536 tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
1537 if (!(tmp & EVERGREEN_CRTC_BLANK_DATA_EN)) {
1538 radeon_wait_for_vblank(rdev, i);
1539 tmp |= EVERGREEN_CRTC_BLANK_DATA_EN;
Christopher Staitebb5888202013-01-26 11:10:58 -05001540 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
Alex Deucher62444b72012-08-15 17:18:42 -04001541 WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
Christopher Staitebb5888202013-01-26 11:10:58 -05001542 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
Alex Deucher62444b72012-08-15 17:18:42 -04001543 }
1544 } else {
1545 tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
1546 if (!(tmp & EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE)) {
1547 radeon_wait_for_vblank(rdev, i);
1548 tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
Christopher Staitebb5888202013-01-26 11:10:58 -05001549 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
Alex Deucher62444b72012-08-15 17:18:42 -04001550 WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
Christopher Staitebb5888202013-01-26 11:10:58 -05001551 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
Alex Deucher62444b72012-08-15 17:18:42 -04001552 }
1553 }
1554 /* wait for the next frame */
1555 frame_count = radeon_get_vblank_counter(rdev, i);
1556 for (j = 0; j < rdev->usec_timeout; j++) {
1557 if (radeon_get_vblank_counter(rdev, i) != frame_count)
1558 break;
1559 udelay(1);
1560 }
Alex Deucher804cc4a2012-11-19 09:11:27 -05001561 } else {
1562 save->crtc_enabled[i] = false;
Alex Deucher62444b72012-08-15 17:18:42 -04001563 }
Alex Deucher18007402010-11-22 17:56:28 -05001564 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001565
Alex Deucher62444b72012-08-15 17:18:42 -04001566 radeon_mc_wait_for_idle(rdev);
1567
1568 blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
1569 if ((blackout & BLACKOUT_MODE_MASK) != 1) {
1570 /* Block CPU access */
1571 WREG32(BIF_FB_EN, 0);
1572 /* blackout the MC */
1573 blackout &= ~BLACKOUT_MODE_MASK;
1574 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
Alex Deucherb7eff392011-07-08 11:44:56 -04001575 }
Alex Deuchered39fad2013-01-31 09:00:52 -05001576 /* wait for the MC to settle */
1577 udelay(100);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001578}
1579
Alex Deucherb9952a82011-03-02 20:07:33 -05001580void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001581{
Alex Deucher62444b72012-08-15 17:18:42 -04001582 u32 tmp, frame_count;
1583 int i, j;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001584
Alex Deucher62444b72012-08-15 17:18:42 -04001585 /* update crtc base addresses */
1586 for (i = 0; i < rdev->num_crtc; i++) {
1587 WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
Alex Deucher18007402010-11-22 17:56:28 -05001588 upper_32_bits(rdev->mc.vram_start));
Alex Deucher62444b72012-08-15 17:18:42 -04001589 WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
Alex Deucher18007402010-11-22 17:56:28 -05001590 upper_32_bits(rdev->mc.vram_start));
Alex Deucher62444b72012-08-15 17:18:42 -04001591 WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
Alex Deucher18007402010-11-22 17:56:28 -05001592 (u32)rdev->mc.vram_start);
Alex Deucher62444b72012-08-15 17:18:42 -04001593 WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i],
Alex Deucher18007402010-11-22 17:56:28 -05001594 (u32)rdev->mc.vram_start);
Alex Deucherb7eff392011-07-08 11:44:56 -04001595 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001596 WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(rdev->mc.vram_start));
1597 WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS, (u32)rdev->mc.vram_start);
Alex Deucher62444b72012-08-15 17:18:42 -04001598
1599 /* unblackout the MC */
1600 tmp = RREG32(MC_SHARED_BLACKOUT_CNTL);
1601 tmp &= ~BLACKOUT_MODE_MASK;
1602 WREG32(MC_SHARED_BLACKOUT_CNTL, tmp);
1603 /* allow CPU access */
1604 WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
1605
1606 for (i = 0; i < rdev->num_crtc; i++) {
Alex Deucher695ddeb2012-11-05 16:34:58 +00001607 if (save->crtc_enabled[i]) {
Alex Deucher62444b72012-08-15 17:18:42 -04001608 if (ASIC_IS_DCE6(rdev)) {
1609 tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
1610 tmp |= EVERGREEN_CRTC_BLANK_DATA_EN;
Christopher Staitebb5888202013-01-26 11:10:58 -05001611 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
Alex Deucher62444b72012-08-15 17:18:42 -04001612 WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
Christopher Staitebb5888202013-01-26 11:10:58 -05001613 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
Alex Deucher62444b72012-08-15 17:18:42 -04001614 } else {
1615 tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
1616 tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
Christopher Staitebb5888202013-01-26 11:10:58 -05001617 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
Alex Deucher62444b72012-08-15 17:18:42 -04001618 WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
Christopher Staitebb5888202013-01-26 11:10:58 -05001619 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
Alex Deucher62444b72012-08-15 17:18:42 -04001620 }
1621 /* wait for the next frame */
1622 frame_count = radeon_get_vblank_counter(rdev, i);
1623 for (j = 0; j < rdev->usec_timeout; j++) {
1624 if (radeon_get_vblank_counter(rdev, i) != frame_count)
1625 break;
1626 udelay(1);
1627 }
1628 }
1629 }
1630 /* Unlock vga access */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001631 WREG32(VGA_HDP_CONTROL, save->vga_hdp_control);
1632 mdelay(1);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001633 WREG32(VGA_RENDER_CONTROL, save->vga_render_control);
1634}
1635
Alex Deucher755d8192011-03-02 20:07:34 -05001636void evergreen_mc_program(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001637{
1638 struct evergreen_mc_save save;
1639 u32 tmp;
1640 int i, j;
1641
1642 /* Initialize HDP */
1643 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1644 WREG32((0x2c14 + j), 0x00000000);
1645 WREG32((0x2c18 + j), 0x00000000);
1646 WREG32((0x2c1c + j), 0x00000000);
1647 WREG32((0x2c20 + j), 0x00000000);
1648 WREG32((0x2c24 + j), 0x00000000);
1649 }
1650 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
1651
1652 evergreen_mc_stop(rdev, &save);
1653 if (evergreen_mc_wait_for_idle(rdev)) {
1654 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1655 }
1656 /* Lockout access through VGA aperture*/
1657 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
1658 /* Update configuration */
1659 if (rdev->flags & RADEON_IS_AGP) {
1660 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
1661 /* VRAM before AGP */
1662 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1663 rdev->mc.vram_start >> 12);
1664 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1665 rdev->mc.gtt_end >> 12);
1666 } else {
1667 /* VRAM after AGP */
1668 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1669 rdev->mc.gtt_start >> 12);
1670 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1671 rdev->mc.vram_end >> 12);
1672 }
1673 } else {
1674 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1675 rdev->mc.vram_start >> 12);
1676 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1677 rdev->mc.vram_end >> 12);
1678 }
Alex Deucher3b9832f2011-11-10 08:59:39 -05001679 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
Alex Deucher05b3ef62012-03-20 17:18:37 -04001680 /* llano/ontario only */
1681 if ((rdev->family == CHIP_PALM) ||
1682 (rdev->family == CHIP_SUMO) ||
1683 (rdev->family == CHIP_SUMO2)) {
Alex Deucherb4183e32010-12-15 11:04:10 -05001684 tmp = RREG32(MC_FUS_VM_FB_OFFSET) & 0x000FFFFF;
1685 tmp |= ((rdev->mc.vram_end >> 20) & 0xF) << 24;
1686 tmp |= ((rdev->mc.vram_start >> 20) & 0xF) << 20;
1687 WREG32(MC_FUS_VM_FB_OFFSET, tmp);
1688 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001689 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
1690 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
1691 WREG32(MC_VM_FB_LOCATION, tmp);
1692 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
Alex Deucherc46cb4d2011-01-06 19:12:37 -05001693 WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
Jerome Glisse46fcd2b2010-06-03 19:34:48 +02001694 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001695 if (rdev->flags & RADEON_IS_AGP) {
1696 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16);
1697 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16);
1698 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
1699 } else {
1700 WREG32(MC_VM_AGP_BASE, 0);
1701 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
1702 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
1703 }
1704 if (evergreen_mc_wait_for_idle(rdev)) {
1705 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1706 }
1707 evergreen_mc_resume(rdev, &save);
1708 /* we need to own VRAM, so turn off the VGA renderer here
1709 * to stop it overwriting our objects */
1710 rv515_vga_render_disable(rdev);
1711}
1712
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001713/*
1714 * CP.
1715 */
Alex Deucher12920592011-02-02 12:37:40 -05001716void evergreen_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
1717{
Christian König876dc9f2012-05-08 14:24:01 +02001718 struct radeon_ring *ring = &rdev->ring[ib->ring];
Alex Deucher89d35802012-07-17 14:02:31 -04001719 u32 next_rptr;
Christian König7b1f2482011-09-23 15:11:23 +02001720
Alex Deucher12920592011-02-02 12:37:40 -05001721 /* set to DX10/11 mode */
Christian Könige32eb502011-10-23 12:56:27 +02001722 radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
1723 radeon_ring_write(ring, 1);
Christian König45df6802012-07-06 16:22:55 +02001724
1725 if (ring->rptr_save_reg) {
Alex Deucher89d35802012-07-17 14:02:31 -04001726 next_rptr = ring->wptr + 3 + 4;
Christian König45df6802012-07-06 16:22:55 +02001727 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
1728 radeon_ring_write(ring, ((ring->rptr_save_reg -
1729 PACKET3_SET_CONFIG_REG_START) >> 2));
1730 radeon_ring_write(ring, next_rptr);
Alex Deucher89d35802012-07-17 14:02:31 -04001731 } else if (rdev->wb.enabled) {
1732 next_rptr = ring->wptr + 5 + 4;
1733 radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3));
1734 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
1735 radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18));
1736 radeon_ring_write(ring, next_rptr);
1737 radeon_ring_write(ring, 0);
Christian König45df6802012-07-06 16:22:55 +02001738 }
1739
Christian Könige32eb502011-10-23 12:56:27 +02001740 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
1741 radeon_ring_write(ring,
Alex Deucher0f234f5f2011-02-13 19:06:33 -05001742#ifdef __BIG_ENDIAN
1743 (2 << 0) |
1744#endif
1745 (ib->gpu_addr & 0xFFFFFFFC));
Christian Könige32eb502011-10-23 12:56:27 +02001746 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
1747 radeon_ring_write(ring, ib->length_dw);
Alex Deucher12920592011-02-02 12:37:40 -05001748}
1749
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001750
1751static int evergreen_cp_load_microcode(struct radeon_device *rdev)
1752{
Alex Deucherfe251e22010-03-24 13:36:43 -04001753 const __be32 *fw_data;
1754 int i;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001755
Alex Deucherfe251e22010-03-24 13:36:43 -04001756 if (!rdev->me_fw || !rdev->pfp_fw)
1757 return -EINVAL;
1758
1759 r700_cp_stop(rdev);
Alex Deucher0f234f5f2011-02-13 19:06:33 -05001760 WREG32(CP_RB_CNTL,
1761#ifdef __BIG_ENDIAN
1762 BUF_SWAP_32BIT |
1763#endif
1764 RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
Alex Deucherfe251e22010-03-24 13:36:43 -04001765
1766 fw_data = (const __be32 *)rdev->pfp_fw->data;
1767 WREG32(CP_PFP_UCODE_ADDR, 0);
1768 for (i = 0; i < EVERGREEN_PFP_UCODE_SIZE; i++)
1769 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
1770 WREG32(CP_PFP_UCODE_ADDR, 0);
1771
1772 fw_data = (const __be32 *)rdev->me_fw->data;
1773 WREG32(CP_ME_RAM_WADDR, 0);
1774 for (i = 0; i < EVERGREEN_PM4_UCODE_SIZE; i++)
1775 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
1776
1777 WREG32(CP_PFP_UCODE_ADDR, 0);
1778 WREG32(CP_ME_RAM_WADDR, 0);
1779 WREG32(CP_ME_RAM_RADDR, 0);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001780 return 0;
1781}
1782
Alex Deucher7e7b41d2010-09-02 21:32:32 -04001783static int evergreen_cp_start(struct radeon_device *rdev)
1784{
Christian Könige32eb502011-10-23 12:56:27 +02001785 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher2281a372010-10-21 13:31:38 -04001786 int r, i;
Alex Deucher7e7b41d2010-09-02 21:32:32 -04001787 uint32_t cp_me;
1788
Christian Könige32eb502011-10-23 12:56:27 +02001789 r = radeon_ring_lock(rdev, ring, 7);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04001790 if (r) {
1791 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
1792 return r;
1793 }
Christian Könige32eb502011-10-23 12:56:27 +02001794 radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
1795 radeon_ring_write(ring, 0x1);
1796 radeon_ring_write(ring, 0x0);
1797 radeon_ring_write(ring, rdev->config.evergreen.max_hw_contexts - 1);
1798 radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
1799 radeon_ring_write(ring, 0);
1800 radeon_ring_write(ring, 0);
1801 radeon_ring_unlock_commit(rdev, ring);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04001802
1803 cp_me = 0xff;
1804 WREG32(CP_ME_CNTL, cp_me);
1805
Christian Könige32eb502011-10-23 12:56:27 +02001806 r = radeon_ring_lock(rdev, ring, evergreen_default_size + 19);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04001807 if (r) {
1808 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
1809 return r;
1810 }
Alex Deucher2281a372010-10-21 13:31:38 -04001811
1812 /* setup clear context state */
Christian Könige32eb502011-10-23 12:56:27 +02001813 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
1814 radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
Alex Deucher2281a372010-10-21 13:31:38 -04001815
1816 for (i = 0; i < evergreen_default_size; i++)
Christian Könige32eb502011-10-23 12:56:27 +02001817 radeon_ring_write(ring, evergreen_default_state[i]);
Alex Deucher2281a372010-10-21 13:31:38 -04001818
Christian Könige32eb502011-10-23 12:56:27 +02001819 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
1820 radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
Alex Deucher2281a372010-10-21 13:31:38 -04001821
1822 /* set clear context state */
Christian Könige32eb502011-10-23 12:56:27 +02001823 radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
1824 radeon_ring_write(ring, 0);
Alex Deucher2281a372010-10-21 13:31:38 -04001825
1826 /* SQ_VTX_BASE_VTX_LOC */
Christian Könige32eb502011-10-23 12:56:27 +02001827 radeon_ring_write(ring, 0xc0026f00);
1828 radeon_ring_write(ring, 0x00000000);
1829 radeon_ring_write(ring, 0x00000000);
1830 radeon_ring_write(ring, 0x00000000);
Alex Deucher2281a372010-10-21 13:31:38 -04001831
1832 /* Clear consts */
Christian Könige32eb502011-10-23 12:56:27 +02001833 radeon_ring_write(ring, 0xc0036f00);
1834 radeon_ring_write(ring, 0x00000bc4);
1835 radeon_ring_write(ring, 0xffffffff);
1836 radeon_ring_write(ring, 0xffffffff);
1837 radeon_ring_write(ring, 0xffffffff);
Alex Deucher2281a372010-10-21 13:31:38 -04001838
Christian Könige32eb502011-10-23 12:56:27 +02001839 radeon_ring_write(ring, 0xc0026900);
1840 radeon_ring_write(ring, 0x00000316);
1841 radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
1842 radeon_ring_write(ring, 0x00000010); /* */
Alex Deucher18ff84d2011-02-02 12:37:41 -05001843
Christian Könige32eb502011-10-23 12:56:27 +02001844 radeon_ring_unlock_commit(rdev, ring);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04001845
1846 return 0;
1847}
1848
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001849static int evergreen_cp_resume(struct radeon_device *rdev)
Alex Deucherfe251e22010-03-24 13:36:43 -04001850{
Christian Könige32eb502011-10-23 12:56:27 +02001851 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucherfe251e22010-03-24 13:36:43 -04001852 u32 tmp;
1853 u32 rb_bufsz;
1854 int r;
1855
1856 /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
1857 WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
1858 SOFT_RESET_PA |
1859 SOFT_RESET_SH |
1860 SOFT_RESET_VGT |
Jerome Glissea49a50d2011-08-24 20:00:17 +00001861 SOFT_RESET_SPI |
Alex Deucherfe251e22010-03-24 13:36:43 -04001862 SOFT_RESET_SX));
1863 RREG32(GRBM_SOFT_RESET);
1864 mdelay(15);
1865 WREG32(GRBM_SOFT_RESET, 0);
1866 RREG32(GRBM_SOFT_RESET);
1867
1868 /* Set ring buffer size */
Christian Könige32eb502011-10-23 12:56:27 +02001869 rb_bufsz = drm_order(ring->ring_size / 8);
Alex Deucher724c80e2010-08-27 18:25:25 -04001870 tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Alex Deucherfe251e22010-03-24 13:36:43 -04001871#ifdef __BIG_ENDIAN
1872 tmp |= BUF_SWAP_32BIT;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04001873#endif
Alex Deucherfe251e22010-03-24 13:36:43 -04001874 WREG32(CP_RB_CNTL, tmp);
Christian König15d33322011-09-15 19:02:22 +02001875 WREG32(CP_SEM_WAIT_TIMER, 0x0);
Alex Deucher11ef3f12012-01-20 14:47:43 -05001876 WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
Alex Deucherfe251e22010-03-24 13:36:43 -04001877
1878 /* Set the write pointer delay */
1879 WREG32(CP_RB_WPTR_DELAY, 0);
1880
1881 /* Initialize the ring buffer's read and write pointers */
1882 WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
1883 WREG32(CP_RB_RPTR_WR, 0);
Christian Könige32eb502011-10-23 12:56:27 +02001884 ring->wptr = 0;
1885 WREG32(CP_RB_WPTR, ring->wptr);
Alex Deucher724c80e2010-08-27 18:25:25 -04001886
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04001887 /* set the wb address whether it's enabled or not */
Alex Deucher0f234f5f2011-02-13 19:06:33 -05001888 WREG32(CP_RB_RPTR_ADDR,
Alex Deucher0f234f5f2011-02-13 19:06:33 -05001889 ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
Alex Deucher724c80e2010-08-27 18:25:25 -04001890 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
1891 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
1892
1893 if (rdev->wb.enabled)
1894 WREG32(SCRATCH_UMSK, 0xff);
1895 else {
1896 tmp |= RB_NO_UPDATE;
1897 WREG32(SCRATCH_UMSK, 0);
1898 }
1899
Alex Deucherfe251e22010-03-24 13:36:43 -04001900 mdelay(1);
1901 WREG32(CP_RB_CNTL, tmp);
1902
Christian Könige32eb502011-10-23 12:56:27 +02001903 WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
Alex Deucherfe251e22010-03-24 13:36:43 -04001904 WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
1905
Christian Könige32eb502011-10-23 12:56:27 +02001906 ring->rptr = RREG32(CP_RB_RPTR);
Alex Deucherfe251e22010-03-24 13:36:43 -04001907
Alex Deucher7e7b41d2010-09-02 21:32:32 -04001908 evergreen_cp_start(rdev);
Christian Könige32eb502011-10-23 12:56:27 +02001909 ring->ready = true;
Alex Deucherf7128122012-02-23 17:53:45 -05001910 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
Alex Deucherfe251e22010-03-24 13:36:43 -04001911 if (r) {
Christian Könige32eb502011-10-23 12:56:27 +02001912 ring->ready = false;
Alex Deucherfe251e22010-03-24 13:36:43 -04001913 return r;
1914 }
1915 return 0;
1916}
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001917
1918/*
1919 * Core functions
1920 */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001921static void evergreen_gpu_init(struct radeon_device *rdev)
1922{
Alex Deucher416a2bd2012-05-31 19:00:25 -04001923 u32 gb_addr_config;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04001924 u32 mc_shared_chmap, mc_arb_ramcfg;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04001925 u32 sx_debug_1;
1926 u32 smx_dc_ctl0;
1927 u32 sq_config;
1928 u32 sq_lds_resource_mgmt;
1929 u32 sq_gpr_resource_mgmt_1;
1930 u32 sq_gpr_resource_mgmt_2;
1931 u32 sq_gpr_resource_mgmt_3;
1932 u32 sq_thread_resource_mgmt;
1933 u32 sq_thread_resource_mgmt_2;
1934 u32 sq_stack_resource_mgmt_1;
1935 u32 sq_stack_resource_mgmt_2;
1936 u32 sq_stack_resource_mgmt_3;
1937 u32 vgt_cache_invalidation;
Alex Deucherf25a5c62011-05-19 11:07:57 -04001938 u32 hdp_host_path_cntl, tmp;
Alex Deucher416a2bd2012-05-31 19:00:25 -04001939 u32 disabled_rb_mask;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04001940 int i, j, num_shader_engines, ps_thread_count;
1941
1942 switch (rdev->family) {
1943 case CHIP_CYPRESS:
1944 case CHIP_HEMLOCK:
1945 rdev->config.evergreen.num_ses = 2;
1946 rdev->config.evergreen.max_pipes = 4;
1947 rdev->config.evergreen.max_tile_pipes = 8;
1948 rdev->config.evergreen.max_simds = 10;
1949 rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
1950 rdev->config.evergreen.max_gprs = 256;
1951 rdev->config.evergreen.max_threads = 248;
1952 rdev->config.evergreen.max_gs_threads = 32;
1953 rdev->config.evergreen.max_stack_entries = 512;
1954 rdev->config.evergreen.sx_num_of_sets = 4;
1955 rdev->config.evergreen.sx_max_export_size = 256;
1956 rdev->config.evergreen.sx_max_export_pos_size = 64;
1957 rdev->config.evergreen.sx_max_export_smx_size = 192;
1958 rdev->config.evergreen.max_hw_contexts = 8;
1959 rdev->config.evergreen.sq_num_cf_insts = 2;
1960
1961 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
1962 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
1963 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04001964 gb_addr_config = CYPRESS_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04001965 break;
1966 case CHIP_JUNIPER:
1967 rdev->config.evergreen.num_ses = 1;
1968 rdev->config.evergreen.max_pipes = 4;
1969 rdev->config.evergreen.max_tile_pipes = 4;
1970 rdev->config.evergreen.max_simds = 10;
1971 rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
1972 rdev->config.evergreen.max_gprs = 256;
1973 rdev->config.evergreen.max_threads = 248;
1974 rdev->config.evergreen.max_gs_threads = 32;
1975 rdev->config.evergreen.max_stack_entries = 512;
1976 rdev->config.evergreen.sx_num_of_sets = 4;
1977 rdev->config.evergreen.sx_max_export_size = 256;
1978 rdev->config.evergreen.sx_max_export_pos_size = 64;
1979 rdev->config.evergreen.sx_max_export_smx_size = 192;
1980 rdev->config.evergreen.max_hw_contexts = 8;
1981 rdev->config.evergreen.sq_num_cf_insts = 2;
1982
1983 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
1984 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
1985 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04001986 gb_addr_config = JUNIPER_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04001987 break;
1988 case CHIP_REDWOOD:
1989 rdev->config.evergreen.num_ses = 1;
1990 rdev->config.evergreen.max_pipes = 4;
1991 rdev->config.evergreen.max_tile_pipes = 4;
1992 rdev->config.evergreen.max_simds = 5;
1993 rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
1994 rdev->config.evergreen.max_gprs = 256;
1995 rdev->config.evergreen.max_threads = 248;
1996 rdev->config.evergreen.max_gs_threads = 32;
1997 rdev->config.evergreen.max_stack_entries = 256;
1998 rdev->config.evergreen.sx_num_of_sets = 4;
1999 rdev->config.evergreen.sx_max_export_size = 256;
2000 rdev->config.evergreen.sx_max_export_pos_size = 64;
2001 rdev->config.evergreen.sx_max_export_smx_size = 192;
2002 rdev->config.evergreen.max_hw_contexts = 8;
2003 rdev->config.evergreen.sq_num_cf_insts = 2;
2004
2005 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
2006 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
2007 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04002008 gb_addr_config = REDWOOD_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002009 break;
2010 case CHIP_CEDAR:
2011 default:
2012 rdev->config.evergreen.num_ses = 1;
2013 rdev->config.evergreen.max_pipes = 2;
2014 rdev->config.evergreen.max_tile_pipes = 2;
2015 rdev->config.evergreen.max_simds = 2;
2016 rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
2017 rdev->config.evergreen.max_gprs = 256;
2018 rdev->config.evergreen.max_threads = 192;
2019 rdev->config.evergreen.max_gs_threads = 16;
2020 rdev->config.evergreen.max_stack_entries = 256;
2021 rdev->config.evergreen.sx_num_of_sets = 4;
2022 rdev->config.evergreen.sx_max_export_size = 128;
2023 rdev->config.evergreen.sx_max_export_pos_size = 32;
2024 rdev->config.evergreen.sx_max_export_smx_size = 96;
2025 rdev->config.evergreen.max_hw_contexts = 4;
2026 rdev->config.evergreen.sq_num_cf_insts = 1;
2027
2028 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
2029 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
2030 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04002031 gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002032 break;
Alex Deucherd5e455e2010-11-22 17:56:29 -05002033 case CHIP_PALM:
2034 rdev->config.evergreen.num_ses = 1;
2035 rdev->config.evergreen.max_pipes = 2;
2036 rdev->config.evergreen.max_tile_pipes = 2;
2037 rdev->config.evergreen.max_simds = 2;
2038 rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
2039 rdev->config.evergreen.max_gprs = 256;
2040 rdev->config.evergreen.max_threads = 192;
2041 rdev->config.evergreen.max_gs_threads = 16;
2042 rdev->config.evergreen.max_stack_entries = 256;
2043 rdev->config.evergreen.sx_num_of_sets = 4;
2044 rdev->config.evergreen.sx_max_export_size = 128;
2045 rdev->config.evergreen.sx_max_export_pos_size = 32;
2046 rdev->config.evergreen.sx_max_export_smx_size = 96;
2047 rdev->config.evergreen.max_hw_contexts = 4;
2048 rdev->config.evergreen.sq_num_cf_insts = 1;
2049
2050 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
2051 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
2052 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04002053 gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
Alex Deucherd5e455e2010-11-22 17:56:29 -05002054 break;
Alex Deucherd5c5a722011-05-31 15:42:48 -04002055 case CHIP_SUMO:
2056 rdev->config.evergreen.num_ses = 1;
2057 rdev->config.evergreen.max_pipes = 4;
Jerome Glissebd25f072012-12-11 11:56:52 -05002058 rdev->config.evergreen.max_tile_pipes = 4;
Alex Deucherd5c5a722011-05-31 15:42:48 -04002059 if (rdev->pdev->device == 0x9648)
2060 rdev->config.evergreen.max_simds = 3;
2061 else if ((rdev->pdev->device == 0x9647) ||
2062 (rdev->pdev->device == 0x964a))
2063 rdev->config.evergreen.max_simds = 4;
2064 else
2065 rdev->config.evergreen.max_simds = 5;
2066 rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
2067 rdev->config.evergreen.max_gprs = 256;
2068 rdev->config.evergreen.max_threads = 248;
2069 rdev->config.evergreen.max_gs_threads = 32;
2070 rdev->config.evergreen.max_stack_entries = 256;
2071 rdev->config.evergreen.sx_num_of_sets = 4;
2072 rdev->config.evergreen.sx_max_export_size = 256;
2073 rdev->config.evergreen.sx_max_export_pos_size = 64;
2074 rdev->config.evergreen.sx_max_export_smx_size = 192;
2075 rdev->config.evergreen.max_hw_contexts = 8;
2076 rdev->config.evergreen.sq_num_cf_insts = 2;
2077
2078 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
2079 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
2080 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Jerome Glissebd25f072012-12-11 11:56:52 -05002081 gb_addr_config = SUMO_GB_ADDR_CONFIG_GOLDEN;
Alex Deucherd5c5a722011-05-31 15:42:48 -04002082 break;
2083 case CHIP_SUMO2:
2084 rdev->config.evergreen.num_ses = 1;
2085 rdev->config.evergreen.max_pipes = 4;
2086 rdev->config.evergreen.max_tile_pipes = 4;
2087 rdev->config.evergreen.max_simds = 2;
2088 rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
2089 rdev->config.evergreen.max_gprs = 256;
2090 rdev->config.evergreen.max_threads = 248;
2091 rdev->config.evergreen.max_gs_threads = 32;
2092 rdev->config.evergreen.max_stack_entries = 512;
2093 rdev->config.evergreen.sx_num_of_sets = 4;
2094 rdev->config.evergreen.sx_max_export_size = 256;
2095 rdev->config.evergreen.sx_max_export_pos_size = 64;
2096 rdev->config.evergreen.sx_max_export_smx_size = 192;
2097 rdev->config.evergreen.max_hw_contexts = 8;
2098 rdev->config.evergreen.sq_num_cf_insts = 2;
2099
2100 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
2101 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
2102 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Jerome Glissebd25f072012-12-11 11:56:52 -05002103 gb_addr_config = SUMO2_GB_ADDR_CONFIG_GOLDEN;
Alex Deucherd5c5a722011-05-31 15:42:48 -04002104 break;
Alex Deucheradb68fa2011-01-06 21:19:24 -05002105 case CHIP_BARTS:
2106 rdev->config.evergreen.num_ses = 2;
2107 rdev->config.evergreen.max_pipes = 4;
2108 rdev->config.evergreen.max_tile_pipes = 8;
2109 rdev->config.evergreen.max_simds = 7;
2110 rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
2111 rdev->config.evergreen.max_gprs = 256;
2112 rdev->config.evergreen.max_threads = 248;
2113 rdev->config.evergreen.max_gs_threads = 32;
2114 rdev->config.evergreen.max_stack_entries = 512;
2115 rdev->config.evergreen.sx_num_of_sets = 4;
2116 rdev->config.evergreen.sx_max_export_size = 256;
2117 rdev->config.evergreen.sx_max_export_pos_size = 64;
2118 rdev->config.evergreen.sx_max_export_smx_size = 192;
2119 rdev->config.evergreen.max_hw_contexts = 8;
2120 rdev->config.evergreen.sq_num_cf_insts = 2;
2121
2122 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
2123 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
2124 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04002125 gb_addr_config = BARTS_GB_ADDR_CONFIG_GOLDEN;
Alex Deucheradb68fa2011-01-06 21:19:24 -05002126 break;
2127 case CHIP_TURKS:
2128 rdev->config.evergreen.num_ses = 1;
2129 rdev->config.evergreen.max_pipes = 4;
2130 rdev->config.evergreen.max_tile_pipes = 4;
2131 rdev->config.evergreen.max_simds = 6;
2132 rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
2133 rdev->config.evergreen.max_gprs = 256;
2134 rdev->config.evergreen.max_threads = 248;
2135 rdev->config.evergreen.max_gs_threads = 32;
2136 rdev->config.evergreen.max_stack_entries = 256;
2137 rdev->config.evergreen.sx_num_of_sets = 4;
2138 rdev->config.evergreen.sx_max_export_size = 256;
2139 rdev->config.evergreen.sx_max_export_pos_size = 64;
2140 rdev->config.evergreen.sx_max_export_smx_size = 192;
2141 rdev->config.evergreen.max_hw_contexts = 8;
2142 rdev->config.evergreen.sq_num_cf_insts = 2;
2143
2144 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
2145 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
2146 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04002147 gb_addr_config = TURKS_GB_ADDR_CONFIG_GOLDEN;
Alex Deucheradb68fa2011-01-06 21:19:24 -05002148 break;
2149 case CHIP_CAICOS:
2150 rdev->config.evergreen.num_ses = 1;
Jerome Glissebd25f072012-12-11 11:56:52 -05002151 rdev->config.evergreen.max_pipes = 2;
Alex Deucheradb68fa2011-01-06 21:19:24 -05002152 rdev->config.evergreen.max_tile_pipes = 2;
2153 rdev->config.evergreen.max_simds = 2;
2154 rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
2155 rdev->config.evergreen.max_gprs = 256;
2156 rdev->config.evergreen.max_threads = 192;
2157 rdev->config.evergreen.max_gs_threads = 16;
2158 rdev->config.evergreen.max_stack_entries = 256;
2159 rdev->config.evergreen.sx_num_of_sets = 4;
2160 rdev->config.evergreen.sx_max_export_size = 128;
2161 rdev->config.evergreen.sx_max_export_pos_size = 32;
2162 rdev->config.evergreen.sx_max_export_smx_size = 96;
2163 rdev->config.evergreen.max_hw_contexts = 4;
2164 rdev->config.evergreen.sq_num_cf_insts = 1;
2165
2166 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
2167 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
2168 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -04002169 gb_addr_config = CAICOS_GB_ADDR_CONFIG_GOLDEN;
Alex Deucheradb68fa2011-01-06 21:19:24 -05002170 break;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002171 }
2172
2173 /* Initialize HDP */
2174 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
2175 WREG32((0x2c14 + j), 0x00000000);
2176 WREG32((0x2c18 + j), 0x00000000);
2177 WREG32((0x2c1c + j), 0x00000000);
2178 WREG32((0x2c20 + j), 0x00000000);
2179 WREG32((0x2c24 + j), 0x00000000);
2180 }
2181
2182 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
2183
Alex Deucherd054ac12011-09-01 17:46:15 +00002184 evergreen_fix_pci_max_read_req_size(rdev);
2185
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002186 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
Alex Deucher05b3ef62012-03-20 17:18:37 -04002187 if ((rdev->family == CHIP_PALM) ||
2188 (rdev->family == CHIP_SUMO) ||
2189 (rdev->family == CHIP_SUMO2))
Alex Deucherd9282fc2011-05-11 03:15:24 -04002190 mc_arb_ramcfg = RREG32(FUS_MC_ARB_RAMCFG);
2191 else
2192 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002193
Alex Deucher1aa52bd2010-11-17 12:11:03 -05002194 /* setup tiling info dword. gb_addr_config is not adequate since it does
2195 * not have bank info, so create a custom tiling dword.
2196 * bits 3:0 num_pipes
2197 * bits 7:4 num_banks
2198 * bits 11:8 group_size
2199 * bits 15:12 row_size
2200 */
2201 rdev->config.evergreen.tile_config = 0;
2202 switch (rdev->config.evergreen.max_tile_pipes) {
2203 case 1:
2204 default:
2205 rdev->config.evergreen.tile_config |= (0 << 0);
2206 break;
2207 case 2:
2208 rdev->config.evergreen.tile_config |= (1 << 0);
2209 break;
2210 case 4:
2211 rdev->config.evergreen.tile_config |= (2 << 0);
2212 break;
2213 case 8:
2214 rdev->config.evergreen.tile_config |= (3 << 0);
2215 break;
2216 }
Alex Deucherd698a342011-06-23 00:49:29 -04002217 /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
Alex Deucher5bfa4872011-05-20 12:35:22 -04002218 if (rdev->flags & RADEON_IS_IGP)
Alex Deucherd698a342011-06-23 00:49:29 -04002219 rdev->config.evergreen.tile_config |= 1 << 4;
Alex Deucher29d65402012-05-31 18:53:36 -04002220 else {
Alex Deucherc8d15ed2012-07-31 11:01:10 -04002221 switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
2222 case 0: /* four banks */
Alex Deucher29d65402012-05-31 18:53:36 -04002223 rdev->config.evergreen.tile_config |= 0 << 4;
Alex Deucherc8d15ed2012-07-31 11:01:10 -04002224 break;
2225 case 1: /* eight banks */
2226 rdev->config.evergreen.tile_config |= 1 << 4;
2227 break;
2228 case 2: /* sixteen banks */
2229 default:
2230 rdev->config.evergreen.tile_config |= 2 << 4;
2231 break;
2232 }
Alex Deucher29d65402012-05-31 18:53:36 -04002233 }
Alex Deucher416a2bd2012-05-31 19:00:25 -04002234 rdev->config.evergreen.tile_config |= 0 << 8;
Alex Deucher1aa52bd2010-11-17 12:11:03 -05002235 rdev->config.evergreen.tile_config |=
2236 ((gb_addr_config & 0x30000000) >> 28) << 12;
2237
Alex Deucher416a2bd2012-05-31 19:00:25 -04002238 num_shader_engines = (gb_addr_config & NUM_SHADER_ENGINES(3) >> 12) + 1;
2239
2240 if ((rdev->family >= CHIP_CEDAR) && (rdev->family <= CHIP_HEMLOCK)) {
2241 u32 efuse_straps_4;
2242 u32 efuse_straps_3;
2243
2244 WREG32(RCU_IND_INDEX, 0x204);
2245 efuse_straps_4 = RREG32(RCU_IND_DATA);
2246 WREG32(RCU_IND_INDEX, 0x203);
2247 efuse_straps_3 = RREG32(RCU_IND_DATA);
2248 tmp = (((efuse_straps_4 & 0xf) << 4) |
2249 ((efuse_straps_3 & 0xf0000000) >> 28));
2250 } else {
2251 tmp = 0;
2252 for (i = (rdev->config.evergreen.num_ses - 1); i >= 0; i--) {
2253 u32 rb_disable_bitmap;
2254
2255 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
2256 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
2257 rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16;
2258 tmp <<= 4;
2259 tmp |= rb_disable_bitmap;
2260 }
2261 }
2262 /* enabled rb are just the one not disabled :) */
2263 disabled_rb_mask = tmp;
2264
2265 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
2266 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
2267
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002268 WREG32(GB_ADDR_CONFIG, gb_addr_config);
2269 WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
2270 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
Alex Deucher233d1ad2012-12-04 15:25:59 -05002271 WREG32(DMA_TILING_CONFIG, gb_addr_config);
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002272
Alex Deucherf7eb9732013-01-30 13:57:40 -05002273 if ((rdev->config.evergreen.max_backends == 1) &&
2274 (rdev->flags & RADEON_IS_IGP)) {
2275 if ((disabled_rb_mask & 3) == 1) {
2276 /* RB0 disabled, RB1 enabled */
2277 tmp = 0x11111111;
2278 } else {
2279 /* RB1 disabled, RB0 enabled */
2280 tmp = 0x00000000;
2281 }
2282 } else {
2283 tmp = gb_addr_config & NUM_PIPES_MASK;
2284 tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.evergreen.max_backends,
2285 EVERGREEN_MAX_BACKENDS, disabled_rb_mask);
2286 }
Alex Deucher416a2bd2012-05-31 19:00:25 -04002287 WREG32(GB_BACKEND_MAP, tmp);
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002288
2289 WREG32(CGTS_SYS_TCC_DISABLE, 0);
2290 WREG32(CGTS_TCC_DISABLE, 0);
2291 WREG32(CGTS_USER_SYS_TCC_DISABLE, 0);
2292 WREG32(CGTS_USER_TCC_DISABLE, 0);
2293
2294 /* set HW defaults for 3D engine */
2295 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
2296 ROQ_IB2_START(0x2b)));
2297
2298 WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30));
2299
2300 WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO |
2301 SYNC_GRADIENT |
2302 SYNC_WALKER |
2303 SYNC_ALIGNER));
2304
2305 sx_debug_1 = RREG32(SX_DEBUG_1);
2306 sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
2307 WREG32(SX_DEBUG_1, sx_debug_1);
2308
2309
2310 smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
2311 smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff);
2312 smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.evergreen.sx_num_of_sets);
2313 WREG32(SMX_DC_CTL0, smx_dc_ctl0);
2314
Alex Deucherb866d132012-06-14 22:06:36 +02002315 if (rdev->family <= CHIP_SUMO2)
2316 WREG32(SMX_SAR_CTL0, 0x00010000);
2317
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002318 WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_size / 4) - 1) |
2319 POSITION_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_pos_size / 4) - 1) |
2320 SMX_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_smx_size / 4) - 1)));
2321
2322 WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.evergreen.sc_prim_fifo_size) |
2323 SC_HIZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_hiz_tile_fifo_size) |
2324 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_earlyz_tile_fifo_size)));
2325
2326 WREG32(VGT_NUM_INSTANCES, 1);
2327 WREG32(SPI_CONFIG_CNTL, 0);
2328 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
2329 WREG32(CP_PERFMON_CNTL, 0);
2330
2331 WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.evergreen.sq_num_cf_insts) |
2332 FETCH_FIFO_HIWATER(0x4) |
2333 DONE_FIFO_HIWATER(0xe0) |
2334 ALU_UPDATE_FIFO_HIWATER(0x8)));
2335
2336 sq_config = RREG32(SQ_CONFIG);
2337 sq_config &= ~(PS_PRIO(3) |
2338 VS_PRIO(3) |
2339 GS_PRIO(3) |
2340 ES_PRIO(3));
2341 sq_config |= (VC_ENABLE |
2342 EXPORT_SRC_C |
2343 PS_PRIO(0) |
2344 VS_PRIO(1) |
2345 GS_PRIO(2) |
2346 ES_PRIO(3));
2347
Alex Deucherd5e455e2010-11-22 17:56:29 -05002348 switch (rdev->family) {
2349 case CHIP_CEDAR:
2350 case CHIP_PALM:
Alex Deucherd5c5a722011-05-31 15:42:48 -04002351 case CHIP_SUMO:
2352 case CHIP_SUMO2:
Alex Deucheradb68fa2011-01-06 21:19:24 -05002353 case CHIP_CAICOS:
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002354 /* no vertex cache */
2355 sq_config &= ~VC_ENABLE;
Alex Deucherd5e455e2010-11-22 17:56:29 -05002356 break;
2357 default:
2358 break;
2359 }
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002360
2361 sq_lds_resource_mgmt = RREG32(SQ_LDS_RESOURCE_MGMT);
2362
2363 sq_gpr_resource_mgmt_1 = NUM_PS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2))* 12 / 32);
2364 sq_gpr_resource_mgmt_1 |= NUM_VS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 6 / 32);
2365 sq_gpr_resource_mgmt_1 |= NUM_CLAUSE_TEMP_GPRS(4);
2366 sq_gpr_resource_mgmt_2 = NUM_GS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
2367 sq_gpr_resource_mgmt_2 |= NUM_ES_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
2368 sq_gpr_resource_mgmt_3 = NUM_HS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
2369 sq_gpr_resource_mgmt_3 |= NUM_LS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
2370
Alex Deucherd5e455e2010-11-22 17:56:29 -05002371 switch (rdev->family) {
2372 case CHIP_CEDAR:
2373 case CHIP_PALM:
Alex Deucherd5c5a722011-05-31 15:42:48 -04002374 case CHIP_SUMO:
2375 case CHIP_SUMO2:
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002376 ps_thread_count = 96;
Alex Deucherd5e455e2010-11-22 17:56:29 -05002377 break;
2378 default:
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002379 ps_thread_count = 128;
Alex Deucherd5e455e2010-11-22 17:56:29 -05002380 break;
2381 }
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002382
2383 sq_thread_resource_mgmt = NUM_PS_THREADS(ps_thread_count);
Alex Deucherf96b35c2010-06-16 12:24:07 -04002384 sq_thread_resource_mgmt |= NUM_VS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
2385 sq_thread_resource_mgmt |= NUM_GS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
2386 sq_thread_resource_mgmt |= NUM_ES_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
2387 sq_thread_resource_mgmt_2 = NUM_HS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
2388 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 -04002389
2390 sq_stack_resource_mgmt_1 = NUM_PS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
2391 sq_stack_resource_mgmt_1 |= NUM_VS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
2392 sq_stack_resource_mgmt_2 = NUM_GS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
2393 sq_stack_resource_mgmt_2 |= NUM_ES_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
2394 sq_stack_resource_mgmt_3 = NUM_HS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
2395 sq_stack_resource_mgmt_3 |= NUM_LS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
2396
2397 WREG32(SQ_CONFIG, sq_config);
2398 WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
2399 WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
2400 WREG32(SQ_GPR_RESOURCE_MGMT_3, sq_gpr_resource_mgmt_3);
2401 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
2402 WREG32(SQ_THREAD_RESOURCE_MGMT_2, sq_thread_resource_mgmt_2);
2403 WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
2404 WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
2405 WREG32(SQ_STACK_RESOURCE_MGMT_3, sq_stack_resource_mgmt_3);
2406 WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0);
2407 WREG32(SQ_LDS_RESOURCE_MGMT, sq_lds_resource_mgmt);
2408
2409 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
2410 FORCE_EOV_MAX_REZ_CNT(255)));
2411
Alex Deucherd5e455e2010-11-22 17:56:29 -05002412 switch (rdev->family) {
2413 case CHIP_CEDAR:
2414 case CHIP_PALM:
Alex Deucherd5c5a722011-05-31 15:42:48 -04002415 case CHIP_SUMO:
2416 case CHIP_SUMO2:
Alex Deucheradb68fa2011-01-06 21:19:24 -05002417 case CHIP_CAICOS:
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002418 vgt_cache_invalidation = CACHE_INVALIDATION(TC_ONLY);
Alex Deucherd5e455e2010-11-22 17:56:29 -05002419 break;
2420 default:
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002421 vgt_cache_invalidation = CACHE_INVALIDATION(VC_AND_TC);
Alex Deucherd5e455e2010-11-22 17:56:29 -05002422 break;
2423 }
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002424 vgt_cache_invalidation |= AUTO_INVLD_EN(ES_AND_GS_AUTO);
2425 WREG32(VGT_CACHE_INVALIDATION, vgt_cache_invalidation);
2426
2427 WREG32(VGT_GS_VERTEX_REUSE, 16);
Alex Deucher12920592011-02-02 12:37:40 -05002428 WREG32(PA_SU_LINE_STIPPLE_VALUE, 0);
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002429 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
2430
Alex Deucher60a4a3e2010-06-29 17:03:35 -04002431 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, 14);
2432 WREG32(VGT_OUT_DEALLOC_CNTL, 16);
2433
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002434 WREG32(CB_PERF_CTR0_SEL_0, 0);
2435 WREG32(CB_PERF_CTR0_SEL_1, 0);
2436 WREG32(CB_PERF_CTR1_SEL_0, 0);
2437 WREG32(CB_PERF_CTR1_SEL_1, 0);
2438 WREG32(CB_PERF_CTR2_SEL_0, 0);
2439 WREG32(CB_PERF_CTR2_SEL_1, 0);
2440 WREG32(CB_PERF_CTR3_SEL_0, 0);
2441 WREG32(CB_PERF_CTR3_SEL_1, 0);
2442
Alex Deucher60a4a3e2010-06-29 17:03:35 -04002443 /* clear render buffer base addresses */
2444 WREG32(CB_COLOR0_BASE, 0);
2445 WREG32(CB_COLOR1_BASE, 0);
2446 WREG32(CB_COLOR2_BASE, 0);
2447 WREG32(CB_COLOR3_BASE, 0);
2448 WREG32(CB_COLOR4_BASE, 0);
2449 WREG32(CB_COLOR5_BASE, 0);
2450 WREG32(CB_COLOR6_BASE, 0);
2451 WREG32(CB_COLOR7_BASE, 0);
2452 WREG32(CB_COLOR8_BASE, 0);
2453 WREG32(CB_COLOR9_BASE, 0);
2454 WREG32(CB_COLOR10_BASE, 0);
2455 WREG32(CB_COLOR11_BASE, 0);
2456
2457 /* set the shader const cache sizes to 0 */
2458 for (i = SQ_ALU_CONST_BUFFER_SIZE_PS_0; i < 0x28200; i += 4)
2459 WREG32(i, 0);
2460 for (i = SQ_ALU_CONST_BUFFER_SIZE_HS_0; i < 0x29000; i += 4)
2461 WREG32(i, 0);
2462
Alex Deucherf25a5c62011-05-19 11:07:57 -04002463 tmp = RREG32(HDP_MISC_CNTL);
2464 tmp |= HDP_FLUSH_INVALIDATE_CACHE;
2465 WREG32(HDP_MISC_CNTL, tmp);
2466
Alex Deucher32fcdbf2010-03-24 13:33:47 -04002467 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
2468 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
2469
2470 WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
2471
2472 udelay(50);
2473
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002474}
2475
2476int evergreen_mc_init(struct radeon_device *rdev)
2477{
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002478 u32 tmp;
2479 int chansize, numchan;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002480
2481 /* Get VRAM informations */
2482 rdev->mc.vram_is_ddr = true;
Alex Deucher05b3ef62012-03-20 17:18:37 -04002483 if ((rdev->family == CHIP_PALM) ||
2484 (rdev->family == CHIP_SUMO) ||
2485 (rdev->family == CHIP_SUMO2))
Alex Deucher82084412011-07-01 13:18:28 -04002486 tmp = RREG32(FUS_MC_ARB_RAMCFG);
2487 else
2488 tmp = RREG32(MC_ARB_RAMCFG);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002489 if (tmp & CHANSIZE_OVERRIDE) {
2490 chansize = 16;
2491 } else if (tmp & CHANSIZE_MASK) {
2492 chansize = 64;
2493 } else {
2494 chansize = 32;
2495 }
2496 tmp = RREG32(MC_SHARED_CHMAP);
2497 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
2498 case 0:
2499 default:
2500 numchan = 1;
2501 break;
2502 case 1:
2503 numchan = 2;
2504 break;
2505 case 2:
2506 numchan = 4;
2507 break;
2508 case 3:
2509 numchan = 8;
2510 break;
2511 }
2512 rdev->mc.vram_width = numchan * chansize;
2513 /* Could aper size report 0 ? */
Jordan Crouse01d73a62010-05-27 13:40:24 -06002514 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
2515 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002516 /* Setup GPU memory space */
Alex Deucher05b3ef62012-03-20 17:18:37 -04002517 if ((rdev->family == CHIP_PALM) ||
2518 (rdev->family == CHIP_SUMO) ||
2519 (rdev->family == CHIP_SUMO2)) {
Alex Deucher6eb18f82010-11-22 17:56:27 -05002520 /* size in bytes on fusion */
2521 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
2522 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
2523 } else {
Alex Deucher05b3ef62012-03-20 17:18:37 -04002524 /* size in MB on evergreen/cayman/tn */
Alex Deucher6eb18f82010-11-22 17:56:27 -05002525 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024;
2526 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024;
2527 }
Jerome Glisse51e5fcd2010-02-19 14:33:54 +00002528 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Alex Deucher0ef0c1f2010-11-22 17:56:26 -05002529 r700_vram_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -04002530 radeon_update_bandwidth_info(rdev);
2531
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002532 return 0;
2533}
Jerome Glissed594e462010-02-17 21:54:29 +00002534
Alex Deucher187e3592013-01-18 14:51:38 -05002535void evergreen_print_gpu_status_regs(struct radeon_device *rdev)
Alex Deucher747943e2010-03-24 13:26:36 -04002536{
Jerome Glisse64c56e82013-01-02 17:30:35 -05002537 dev_info(rdev->dev, " GRBM_STATUS = 0x%08X\n",
Alex Deucher747943e2010-03-24 13:26:36 -04002538 RREG32(GRBM_STATUS));
Jerome Glisse64c56e82013-01-02 17:30:35 -05002539 dev_info(rdev->dev, " GRBM_STATUS_SE0 = 0x%08X\n",
Alex Deucher747943e2010-03-24 13:26:36 -04002540 RREG32(GRBM_STATUS_SE0));
Jerome Glisse64c56e82013-01-02 17:30:35 -05002541 dev_info(rdev->dev, " GRBM_STATUS_SE1 = 0x%08X\n",
Alex Deucher747943e2010-03-24 13:26:36 -04002542 RREG32(GRBM_STATUS_SE1));
Jerome Glisse64c56e82013-01-02 17:30:35 -05002543 dev_info(rdev->dev, " SRBM_STATUS = 0x%08X\n",
Alex Deucher747943e2010-03-24 13:26:36 -04002544 RREG32(SRBM_STATUS));
Alex Deuchera65a4362013-01-18 18:55:54 -05002545 dev_info(rdev->dev, " SRBM_STATUS2 = 0x%08X\n",
2546 RREG32(SRBM_STATUS2));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04002547 dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
2548 RREG32(CP_STALLED_STAT1));
2549 dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
2550 RREG32(CP_STALLED_STAT2));
2551 dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
2552 RREG32(CP_BUSY_STAT));
2553 dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
2554 RREG32(CP_STAT));
Alex Deucher0ecebb92013-01-03 12:40:13 -05002555 dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
2556 RREG32(DMA_STATUS_REG));
Alex Deucher168757e2013-01-18 19:17:22 -05002557 if (rdev->family >= CHIP_CAYMAN) {
2558 dev_info(rdev->dev, " R_00D834_DMA_STATUS_REG = 0x%08X\n",
2559 RREG32(DMA_STATUS_REG + 0x800));
2560 }
Alex Deucher0ecebb92013-01-03 12:40:13 -05002561}
2562
Alex Deucher168757e2013-01-18 19:17:22 -05002563bool evergreen_is_display_hung(struct radeon_device *rdev)
Alex Deuchera65a4362013-01-18 18:55:54 -05002564{
2565 u32 crtc_hung = 0;
2566 u32 crtc_status[6];
2567 u32 i, j, tmp;
2568
2569 for (i = 0; i < rdev->num_crtc; i++) {
2570 if (RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN) {
2571 crtc_status[i] = RREG32(EVERGREEN_CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
2572 crtc_hung |= (1 << i);
2573 }
2574 }
2575
2576 for (j = 0; j < 10; j++) {
2577 for (i = 0; i < rdev->num_crtc; i++) {
2578 if (crtc_hung & (1 << i)) {
2579 tmp = RREG32(EVERGREEN_CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
2580 if (tmp != crtc_status[i])
2581 crtc_hung &= ~(1 << i);
2582 }
2583 }
2584 if (crtc_hung == 0)
2585 return false;
2586 udelay(100);
2587 }
2588
2589 return true;
2590}
2591
2592static u32 evergreen_gpu_check_soft_reset(struct radeon_device *rdev)
2593{
2594 u32 reset_mask = 0;
2595 u32 tmp;
2596
2597 /* GRBM_STATUS */
2598 tmp = RREG32(GRBM_STATUS);
2599 if (tmp & (PA_BUSY | SC_BUSY |
2600 SH_BUSY | SX_BUSY |
2601 TA_BUSY | VGT_BUSY |
2602 DB_BUSY | CB_BUSY |
2603 SPI_BUSY | VGT_BUSY_NO_DMA))
2604 reset_mask |= RADEON_RESET_GFX;
2605
2606 if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
2607 CP_BUSY | CP_COHERENCY_BUSY))
2608 reset_mask |= RADEON_RESET_CP;
2609
2610 if (tmp & GRBM_EE_BUSY)
2611 reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
2612
2613 /* DMA_STATUS_REG */
2614 tmp = RREG32(DMA_STATUS_REG);
2615 if (!(tmp & DMA_IDLE))
2616 reset_mask |= RADEON_RESET_DMA;
2617
2618 /* SRBM_STATUS2 */
2619 tmp = RREG32(SRBM_STATUS2);
2620 if (tmp & DMA_BUSY)
2621 reset_mask |= RADEON_RESET_DMA;
2622
2623 /* SRBM_STATUS */
2624 tmp = RREG32(SRBM_STATUS);
2625 if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
2626 reset_mask |= RADEON_RESET_RLC;
2627
2628 if (tmp & IH_BUSY)
2629 reset_mask |= RADEON_RESET_IH;
2630
2631 if (tmp & SEM_BUSY)
2632 reset_mask |= RADEON_RESET_SEM;
2633
2634 if (tmp & GRBM_RQ_PENDING)
2635 reset_mask |= RADEON_RESET_GRBM;
2636
2637 if (tmp & VMC_BUSY)
2638 reset_mask |= RADEON_RESET_VMC;
2639
2640 if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
2641 MCC_BUSY | MCD_BUSY))
2642 reset_mask |= RADEON_RESET_MC;
2643
2644 if (evergreen_is_display_hung(rdev))
2645 reset_mask |= RADEON_RESET_DISPLAY;
2646
2647 /* VM_L2_STATUS */
2648 tmp = RREG32(VM_L2_STATUS);
2649 if (tmp & L2_BUSY)
2650 reset_mask |= RADEON_RESET_VMC;
2651
Alex Deucherd808fc82013-02-28 10:03:08 -05002652 /* Skip MC reset as it's mostly likely not hung, just busy */
2653 if (reset_mask & RADEON_RESET_MC) {
2654 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
2655 reset_mask &= ~RADEON_RESET_MC;
2656 }
2657
Alex Deuchera65a4362013-01-18 18:55:54 -05002658 return reset_mask;
2659}
2660
2661static void evergreen_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
Alex Deucher0ecebb92013-01-03 12:40:13 -05002662{
2663 struct evergreen_mc_save save;
Alex Deucherb7630472013-01-18 14:28:41 -05002664 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
2665 u32 tmp;
Alex Deucher19fc42e2013-01-14 11:04:39 -05002666
Alex Deucher0ecebb92013-01-03 12:40:13 -05002667 if (reset_mask == 0)
Alex Deuchera65a4362013-01-18 18:55:54 -05002668 return;
Alex Deucher0ecebb92013-01-03 12:40:13 -05002669
2670 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
2671
Alex Deucherb7630472013-01-18 14:28:41 -05002672 evergreen_print_gpu_status_regs(rdev);
2673
Alex Deucherb7630472013-01-18 14:28:41 -05002674 /* Disable CP parsing/prefetching */
2675 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
2676
2677 if (reset_mask & RADEON_RESET_DMA) {
2678 /* Disable DMA */
2679 tmp = RREG32(DMA_RB_CNTL);
2680 tmp &= ~DMA_RB_ENABLE;
2681 WREG32(DMA_RB_CNTL, tmp);
2682 }
2683
Alex Deucherb21b6e72013-01-23 18:57:56 -05002684 udelay(50);
2685
2686 evergreen_mc_stop(rdev, &save);
2687 if (evergreen_mc_wait_for_idle(rdev)) {
2688 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
2689 }
2690
Alex Deucherb7630472013-01-18 14:28:41 -05002691 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
2692 grbm_soft_reset |= SOFT_RESET_DB |
2693 SOFT_RESET_CB |
2694 SOFT_RESET_PA |
2695 SOFT_RESET_SC |
2696 SOFT_RESET_SPI |
2697 SOFT_RESET_SX |
2698 SOFT_RESET_SH |
2699 SOFT_RESET_TC |
2700 SOFT_RESET_TA |
2701 SOFT_RESET_VC |
2702 SOFT_RESET_VGT;
2703 }
2704
2705 if (reset_mask & RADEON_RESET_CP) {
2706 grbm_soft_reset |= SOFT_RESET_CP |
2707 SOFT_RESET_VGT;
2708
2709 srbm_soft_reset |= SOFT_RESET_GRBM;
2710 }
Alex Deucher0ecebb92013-01-03 12:40:13 -05002711
2712 if (reset_mask & RADEON_RESET_DMA)
Alex Deucherb7630472013-01-18 14:28:41 -05002713 srbm_soft_reset |= SOFT_RESET_DMA;
2714
Alex Deuchera65a4362013-01-18 18:55:54 -05002715 if (reset_mask & RADEON_RESET_DISPLAY)
2716 srbm_soft_reset |= SOFT_RESET_DC;
2717
2718 if (reset_mask & RADEON_RESET_RLC)
2719 srbm_soft_reset |= SOFT_RESET_RLC;
2720
2721 if (reset_mask & RADEON_RESET_SEM)
2722 srbm_soft_reset |= SOFT_RESET_SEM;
2723
2724 if (reset_mask & RADEON_RESET_IH)
2725 srbm_soft_reset |= SOFT_RESET_IH;
2726
2727 if (reset_mask & RADEON_RESET_GRBM)
2728 srbm_soft_reset |= SOFT_RESET_GRBM;
2729
2730 if (reset_mask & RADEON_RESET_VMC)
2731 srbm_soft_reset |= SOFT_RESET_VMC;
2732
Alex Deucher24178ec2013-01-24 15:00:17 -05002733 if (!(rdev->flags & RADEON_IS_IGP)) {
2734 if (reset_mask & RADEON_RESET_MC)
2735 srbm_soft_reset |= SOFT_RESET_MC;
2736 }
Alex Deuchera65a4362013-01-18 18:55:54 -05002737
Alex Deucherb7630472013-01-18 14:28:41 -05002738 if (grbm_soft_reset) {
2739 tmp = RREG32(GRBM_SOFT_RESET);
2740 tmp |= grbm_soft_reset;
2741 dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
2742 WREG32(GRBM_SOFT_RESET, tmp);
2743 tmp = RREG32(GRBM_SOFT_RESET);
2744
2745 udelay(50);
2746
2747 tmp &= ~grbm_soft_reset;
2748 WREG32(GRBM_SOFT_RESET, tmp);
2749 tmp = RREG32(GRBM_SOFT_RESET);
2750 }
2751
2752 if (srbm_soft_reset) {
2753 tmp = RREG32(SRBM_SOFT_RESET);
2754 tmp |= srbm_soft_reset;
2755 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
2756 WREG32(SRBM_SOFT_RESET, tmp);
2757 tmp = RREG32(SRBM_SOFT_RESET);
2758
2759 udelay(50);
2760
2761 tmp &= ~srbm_soft_reset;
2762 WREG32(SRBM_SOFT_RESET, tmp);
2763 tmp = RREG32(SRBM_SOFT_RESET);
2764 }
Alex Deucher0ecebb92013-01-03 12:40:13 -05002765
2766 /* Wait a little for things to settle down */
2767 udelay(50);
2768
Alex Deucher747943e2010-03-24 13:26:36 -04002769 evergreen_mc_resume(rdev, &save);
Alex Deucherb7630472013-01-18 14:28:41 -05002770 udelay(50);
Alex Deucher410a3412013-01-18 13:05:39 -05002771
Alex Deucherb7630472013-01-18 14:28:41 -05002772 evergreen_print_gpu_status_regs(rdev);
Alex Deucher747943e2010-03-24 13:26:36 -04002773}
2774
Jerome Glissea2d07b72010-03-09 14:45:11 +00002775int evergreen_asic_reset(struct radeon_device *rdev)
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002776{
Alex Deuchera65a4362013-01-18 18:55:54 -05002777 u32 reset_mask;
2778
2779 reset_mask = evergreen_gpu_check_soft_reset(rdev);
2780
2781 if (reset_mask)
2782 r600_set_bios_scratch_engine_hung(rdev, true);
2783
2784 evergreen_gpu_soft_reset(rdev, reset_mask);
2785
2786 reset_mask = evergreen_gpu_check_soft_reset(rdev);
2787
2788 if (!reset_mask)
2789 r600_set_bios_scratch_engine_hung(rdev, false);
2790
2791 return 0;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05002792}
2793
Alex Deucher123bc182013-01-24 11:37:19 -05002794/**
2795 * evergreen_gfx_is_lockup - Check if the GFX engine is locked up
2796 *
2797 * @rdev: radeon_device pointer
2798 * @ring: radeon_ring structure holding ring information
2799 *
2800 * Check if the GFX engine is locked up.
2801 * Returns true if the engine appears to be locked up, false if not.
2802 */
2803bool evergreen_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
2804{
2805 u32 reset_mask = evergreen_gpu_check_soft_reset(rdev);
2806
2807 if (!(reset_mask & (RADEON_RESET_GFX |
2808 RADEON_RESET_COMPUTE |
2809 RADEON_RESET_CP))) {
2810 radeon_ring_lockup_update(ring);
2811 return false;
2812 }
2813 /* force CP activities */
2814 radeon_ring_force_activity(rdev, ring);
2815 return radeon_ring_test_lockup(rdev, ring);
2816}
2817
2818/**
2819 * evergreen_dma_is_lockup - Check if the DMA engine is locked up
2820 *
2821 * @rdev: radeon_device pointer
2822 * @ring: radeon_ring structure holding ring information
2823 *
2824 * Check if the async DMA engine is locked up.
2825 * Returns true if the engine appears to be locked up, false if not.
2826 */
2827bool evergreen_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
2828{
2829 u32 reset_mask = evergreen_gpu_check_soft_reset(rdev);
2830
2831 if (!(reset_mask & RADEON_RESET_DMA)) {
2832 radeon_ring_lockup_update(ring);
2833 return false;
2834 }
2835 /* force ring activities */
2836 radeon_ring_force_activity(rdev, ring);
2837 return radeon_ring_test_lockup(rdev, ring);
2838}
2839
Alex Deucher45f9a392010-03-24 13:55:51 -04002840/* Interrupts */
2841
2842u32 evergreen_get_vblank_counter(struct radeon_device *rdev, int crtc)
2843{
Alex Deucher46437052012-08-15 17:10:32 -04002844 if (crtc >= rdev->num_crtc)
Alex Deucher45f9a392010-03-24 13:55:51 -04002845 return 0;
Alex Deucher46437052012-08-15 17:10:32 -04002846 else
2847 return RREG32(CRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
Alex Deucher45f9a392010-03-24 13:55:51 -04002848}
2849
2850void evergreen_disable_interrupt_state(struct radeon_device *rdev)
2851{
2852 u32 tmp;
2853
Alex Deucher1b370782011-11-17 20:13:28 -05002854 if (rdev->family >= CHIP_CAYMAN) {
2855 cayman_cp_int_cntl_setup(rdev, 0,
2856 CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
2857 cayman_cp_int_cntl_setup(rdev, 1, 0);
2858 cayman_cp_int_cntl_setup(rdev, 2, 0);
Alex Deucherf60cbd12012-12-04 15:27:33 -05002859 tmp = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE;
2860 WREG32(CAYMAN_DMA1_CNTL, tmp);
Alex Deucher1b370782011-11-17 20:13:28 -05002861 } else
2862 WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
Alex Deucher233d1ad2012-12-04 15:25:59 -05002863 tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
2864 WREG32(DMA_CNTL, tmp);
Alex Deucher45f9a392010-03-24 13:55:51 -04002865 WREG32(GRBM_INT_CNTL, 0);
2866 WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
2867 WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
Alex Deucherb7eff392011-07-08 11:44:56 -04002868 if (rdev->num_crtc >= 4) {
Alex Deucher18007402010-11-22 17:56:28 -05002869 WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
2870 WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
Alex Deucherb7eff392011-07-08 11:44:56 -04002871 }
2872 if (rdev->num_crtc >= 6) {
Alex Deucher18007402010-11-22 17:56:28 -05002873 WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
2874 WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
2875 }
Alex Deucher45f9a392010-03-24 13:55:51 -04002876
2877 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
2878 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
Alex Deucherb7eff392011-07-08 11:44:56 -04002879 if (rdev->num_crtc >= 4) {
Alex Deucher18007402010-11-22 17:56:28 -05002880 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
2881 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
Alex Deucherb7eff392011-07-08 11:44:56 -04002882 }
2883 if (rdev->num_crtc >= 6) {
Alex Deucher18007402010-11-22 17:56:28 -05002884 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
2885 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
2886 }
Alex Deucher45f9a392010-03-24 13:55:51 -04002887
Alex Deucher05b3ef62012-03-20 17:18:37 -04002888 /* only one DAC on DCE6 */
2889 if (!ASIC_IS_DCE6(rdev))
2890 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
Alex Deucher45f9a392010-03-24 13:55:51 -04002891 WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
2892
2893 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2894 WREG32(DC_HPD1_INT_CONTROL, tmp);
2895 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2896 WREG32(DC_HPD2_INT_CONTROL, tmp);
2897 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2898 WREG32(DC_HPD3_INT_CONTROL, tmp);
2899 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2900 WREG32(DC_HPD4_INT_CONTROL, tmp);
2901 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2902 WREG32(DC_HPD5_INT_CONTROL, tmp);
2903 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2904 WREG32(DC_HPD6_INT_CONTROL, tmp);
2905
2906}
2907
2908int evergreen_irq_set(struct radeon_device *rdev)
2909{
2910 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
Alex Deucher1b370782011-11-17 20:13:28 -05002911 u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
Alex Deucher45f9a392010-03-24 13:55:51 -04002912 u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
2913 u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
Alex Deucher2031f772010-04-22 12:52:11 -04002914 u32 grbm_int_cntl = 0;
Alex Deucher6f34be52010-11-21 10:59:01 -05002915 u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
Alex Deucherf122c612012-03-30 08:59:57 -04002916 u32 afmt1 = 0, afmt2 = 0, afmt3 = 0, afmt4 = 0, afmt5 = 0, afmt6 = 0;
Alex Deucherf60cbd12012-12-04 15:27:33 -05002917 u32 dma_cntl, dma_cntl1 = 0;
Alex Deucher45f9a392010-03-24 13:55:51 -04002918
2919 if (!rdev->irq.installed) {
Joe Perchesfce7d612010-10-30 21:08:30 +00002920 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
Alex Deucher45f9a392010-03-24 13:55:51 -04002921 return -EINVAL;
2922 }
2923 /* don't enable anything if the ih is disabled */
2924 if (!rdev->ih.enabled) {
2925 r600_disable_interrupts(rdev);
2926 /* force the active interrupt state to all disabled */
2927 evergreen_disable_interrupt_state(rdev);
2928 return 0;
2929 }
2930
2931 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
2932 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
2933 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
2934 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
2935 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
2936 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
2937
Alex Deucherf122c612012-03-30 08:59:57 -04002938 afmt1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
2939 afmt2 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
2940 afmt3 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
2941 afmt4 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
2942 afmt5 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
2943 afmt6 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
2944
Alex Deucher233d1ad2012-12-04 15:25:59 -05002945 dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
2946
Alex Deucher1b370782011-11-17 20:13:28 -05002947 if (rdev->family >= CHIP_CAYMAN) {
2948 /* enable CP interrupts on all rings */
Christian Koenig736fc372012-05-17 19:52:00 +02002949 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
Alex Deucher1b370782011-11-17 20:13:28 -05002950 DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
2951 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
2952 }
Christian Koenig736fc372012-05-17 19:52:00 +02002953 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
Alex Deucher1b370782011-11-17 20:13:28 -05002954 DRM_DEBUG("evergreen_irq_set: sw int cp1\n");
2955 cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
2956 }
Christian Koenig736fc372012-05-17 19:52:00 +02002957 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
Alex Deucher1b370782011-11-17 20:13:28 -05002958 DRM_DEBUG("evergreen_irq_set: sw int cp2\n");
2959 cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
2960 }
2961 } else {
Christian Koenig736fc372012-05-17 19:52:00 +02002962 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
Alex Deucher1b370782011-11-17 20:13:28 -05002963 DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
2964 cp_int_cntl |= RB_INT_ENABLE;
2965 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
2966 }
Alex Deucher45f9a392010-03-24 13:55:51 -04002967 }
Alex Deucher1b370782011-11-17 20:13:28 -05002968
Alex Deucher233d1ad2012-12-04 15:25:59 -05002969 if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
2970 DRM_DEBUG("r600_irq_set: sw int dma\n");
2971 dma_cntl |= TRAP_ENABLE;
2972 }
2973
Alex Deucherf60cbd12012-12-04 15:27:33 -05002974 if (rdev->family >= CHIP_CAYMAN) {
2975 dma_cntl1 = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE;
2976 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
2977 DRM_DEBUG("r600_irq_set: sw int dma1\n");
2978 dma_cntl1 |= TRAP_ENABLE;
2979 }
2980 }
2981
Alex Deucher6f34be52010-11-21 10:59:01 -05002982 if (rdev->irq.crtc_vblank_int[0] ||
Christian Koenig736fc372012-05-17 19:52:00 +02002983 atomic_read(&rdev->irq.pflip[0])) {
Alex Deucher45f9a392010-03-24 13:55:51 -04002984 DRM_DEBUG("evergreen_irq_set: vblank 0\n");
2985 crtc1 |= VBLANK_INT_MASK;
2986 }
Alex Deucher6f34be52010-11-21 10:59:01 -05002987 if (rdev->irq.crtc_vblank_int[1] ||
Christian Koenig736fc372012-05-17 19:52:00 +02002988 atomic_read(&rdev->irq.pflip[1])) {
Alex Deucher45f9a392010-03-24 13:55:51 -04002989 DRM_DEBUG("evergreen_irq_set: vblank 1\n");
2990 crtc2 |= VBLANK_INT_MASK;
2991 }
Alex Deucher6f34be52010-11-21 10:59:01 -05002992 if (rdev->irq.crtc_vblank_int[2] ||
Christian Koenig736fc372012-05-17 19:52:00 +02002993 atomic_read(&rdev->irq.pflip[2])) {
Alex Deucher45f9a392010-03-24 13:55:51 -04002994 DRM_DEBUG("evergreen_irq_set: vblank 2\n");
2995 crtc3 |= VBLANK_INT_MASK;
2996 }
Alex Deucher6f34be52010-11-21 10:59:01 -05002997 if (rdev->irq.crtc_vblank_int[3] ||
Christian Koenig736fc372012-05-17 19:52:00 +02002998 atomic_read(&rdev->irq.pflip[3])) {
Alex Deucher45f9a392010-03-24 13:55:51 -04002999 DRM_DEBUG("evergreen_irq_set: vblank 3\n");
3000 crtc4 |= VBLANK_INT_MASK;
3001 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003002 if (rdev->irq.crtc_vblank_int[4] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003003 atomic_read(&rdev->irq.pflip[4])) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003004 DRM_DEBUG("evergreen_irq_set: vblank 4\n");
3005 crtc5 |= VBLANK_INT_MASK;
3006 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003007 if (rdev->irq.crtc_vblank_int[5] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003008 atomic_read(&rdev->irq.pflip[5])) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003009 DRM_DEBUG("evergreen_irq_set: vblank 5\n");
3010 crtc6 |= VBLANK_INT_MASK;
3011 }
3012 if (rdev->irq.hpd[0]) {
3013 DRM_DEBUG("evergreen_irq_set: hpd 1\n");
3014 hpd1 |= DC_HPDx_INT_EN;
3015 }
3016 if (rdev->irq.hpd[1]) {
3017 DRM_DEBUG("evergreen_irq_set: hpd 2\n");
3018 hpd2 |= DC_HPDx_INT_EN;
3019 }
3020 if (rdev->irq.hpd[2]) {
3021 DRM_DEBUG("evergreen_irq_set: hpd 3\n");
3022 hpd3 |= DC_HPDx_INT_EN;
3023 }
3024 if (rdev->irq.hpd[3]) {
3025 DRM_DEBUG("evergreen_irq_set: hpd 4\n");
3026 hpd4 |= DC_HPDx_INT_EN;
3027 }
3028 if (rdev->irq.hpd[4]) {
3029 DRM_DEBUG("evergreen_irq_set: hpd 5\n");
3030 hpd5 |= DC_HPDx_INT_EN;
3031 }
3032 if (rdev->irq.hpd[5]) {
3033 DRM_DEBUG("evergreen_irq_set: hpd 6\n");
3034 hpd6 |= DC_HPDx_INT_EN;
3035 }
Alex Deucherf122c612012-03-30 08:59:57 -04003036 if (rdev->irq.afmt[0]) {
3037 DRM_DEBUG("evergreen_irq_set: hdmi 0\n");
3038 afmt1 |= AFMT_AZ_FORMAT_WTRIG_MASK;
3039 }
3040 if (rdev->irq.afmt[1]) {
3041 DRM_DEBUG("evergreen_irq_set: hdmi 1\n");
3042 afmt2 |= AFMT_AZ_FORMAT_WTRIG_MASK;
3043 }
3044 if (rdev->irq.afmt[2]) {
3045 DRM_DEBUG("evergreen_irq_set: hdmi 2\n");
3046 afmt3 |= AFMT_AZ_FORMAT_WTRIG_MASK;
3047 }
3048 if (rdev->irq.afmt[3]) {
3049 DRM_DEBUG("evergreen_irq_set: hdmi 3\n");
3050 afmt4 |= AFMT_AZ_FORMAT_WTRIG_MASK;
3051 }
3052 if (rdev->irq.afmt[4]) {
3053 DRM_DEBUG("evergreen_irq_set: hdmi 4\n");
3054 afmt5 |= AFMT_AZ_FORMAT_WTRIG_MASK;
3055 }
3056 if (rdev->irq.afmt[5]) {
3057 DRM_DEBUG("evergreen_irq_set: hdmi 5\n");
3058 afmt6 |= AFMT_AZ_FORMAT_WTRIG_MASK;
3059 }
Alex Deucher45f9a392010-03-24 13:55:51 -04003060
Alex Deucher1b370782011-11-17 20:13:28 -05003061 if (rdev->family >= CHIP_CAYMAN) {
3062 cayman_cp_int_cntl_setup(rdev, 0, cp_int_cntl);
3063 cayman_cp_int_cntl_setup(rdev, 1, cp_int_cntl1);
3064 cayman_cp_int_cntl_setup(rdev, 2, cp_int_cntl2);
3065 } else
3066 WREG32(CP_INT_CNTL, cp_int_cntl);
Alex Deucher233d1ad2012-12-04 15:25:59 -05003067
3068 WREG32(DMA_CNTL, dma_cntl);
3069
Alex Deucherf60cbd12012-12-04 15:27:33 -05003070 if (rdev->family >= CHIP_CAYMAN)
3071 WREG32(CAYMAN_DMA1_CNTL, dma_cntl1);
3072
Alex Deucher2031f772010-04-22 12:52:11 -04003073 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
Alex Deucher45f9a392010-03-24 13:55:51 -04003074
3075 WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
3076 WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
Alex Deucherb7eff392011-07-08 11:44:56 -04003077 if (rdev->num_crtc >= 4) {
Alex Deucher18007402010-11-22 17:56:28 -05003078 WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
3079 WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
Alex Deucherb7eff392011-07-08 11:44:56 -04003080 }
3081 if (rdev->num_crtc >= 6) {
Alex Deucher18007402010-11-22 17:56:28 -05003082 WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
3083 WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
3084 }
Alex Deucher45f9a392010-03-24 13:55:51 -04003085
Alex Deucher6f34be52010-11-21 10:59:01 -05003086 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1);
3087 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2);
Alex Deucherb7eff392011-07-08 11:44:56 -04003088 if (rdev->num_crtc >= 4) {
3089 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3);
3090 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4);
3091 }
3092 if (rdev->num_crtc >= 6) {
3093 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5);
3094 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6);
3095 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003096
Alex Deucher45f9a392010-03-24 13:55:51 -04003097 WREG32(DC_HPD1_INT_CONTROL, hpd1);
3098 WREG32(DC_HPD2_INT_CONTROL, hpd2);
3099 WREG32(DC_HPD3_INT_CONTROL, hpd3);
3100 WREG32(DC_HPD4_INT_CONTROL, hpd4);
3101 WREG32(DC_HPD5_INT_CONTROL, hpd5);
3102 WREG32(DC_HPD6_INT_CONTROL, hpd6);
3103
Alex Deucherf122c612012-03-30 08:59:57 -04003104 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, afmt1);
3105 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, afmt2);
3106 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, afmt3);
3107 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, afmt4);
3108 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, afmt5);
3109 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, afmt6);
3110
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003111 return 0;
3112}
3113
Andi Kleencbdd4502011-10-13 16:08:46 -07003114static void evergreen_irq_ack(struct radeon_device *rdev)
Alex Deucher45f9a392010-03-24 13:55:51 -04003115{
3116 u32 tmp;
3117
Alex Deucher6f34be52010-11-21 10:59:01 -05003118 rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
3119 rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
3120 rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
3121 rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
3122 rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
3123 rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
3124 rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
3125 rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
Alex Deucherb7eff392011-07-08 11:44:56 -04003126 if (rdev->num_crtc >= 4) {
3127 rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
3128 rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
3129 }
3130 if (rdev->num_crtc >= 6) {
3131 rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
3132 rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
3133 }
Alex Deucher45f9a392010-03-24 13:55:51 -04003134
Alex Deucherf122c612012-03-30 08:59:57 -04003135 rdev->irq.stat_regs.evergreen.afmt_status1 = RREG32(AFMT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
3136 rdev->irq.stat_regs.evergreen.afmt_status2 = RREG32(AFMT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
3137 rdev->irq.stat_regs.evergreen.afmt_status3 = RREG32(AFMT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
3138 rdev->irq.stat_regs.evergreen.afmt_status4 = RREG32(AFMT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
3139 rdev->irq.stat_regs.evergreen.afmt_status5 = RREG32(AFMT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
3140 rdev->irq.stat_regs.evergreen.afmt_status6 = RREG32(AFMT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
3141
Alex Deucher6f34be52010-11-21 10:59:01 -05003142 if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
3143 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
3144 if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
3145 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
Alex Deucher6f34be52010-11-21 10:59:01 -05003146 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
Alex Deucher45f9a392010-03-24 13:55:51 -04003147 WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003148 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
Alex Deucher45f9a392010-03-24 13:55:51 -04003149 WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003150 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
Alex Deucher45f9a392010-03-24 13:55:51 -04003151 WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003152 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
Alex Deucher45f9a392010-03-24 13:55:51 -04003153 WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
3154
Alex Deucherb7eff392011-07-08 11:44:56 -04003155 if (rdev->num_crtc >= 4) {
3156 if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
3157 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
3158 if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
3159 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
3160 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
3161 WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
3162 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
3163 WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
3164 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
3165 WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
3166 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
3167 WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
3168 }
Alex Deucher45f9a392010-03-24 13:55:51 -04003169
Alex Deucherb7eff392011-07-08 11:44:56 -04003170 if (rdev->num_crtc >= 6) {
3171 if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
3172 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
3173 if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
3174 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
3175 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
3176 WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
3177 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
3178 WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
3179 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
3180 WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
3181 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
3182 WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
3183 }
Alex Deucher45f9a392010-03-24 13:55:51 -04003184
Alex Deucher6f34be52010-11-21 10:59:01 -05003185 if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003186 tmp = RREG32(DC_HPD1_INT_CONTROL);
3187 tmp |= DC_HPDx_INT_ACK;
3188 WREG32(DC_HPD1_INT_CONTROL, tmp);
3189 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003190 if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003191 tmp = RREG32(DC_HPD2_INT_CONTROL);
3192 tmp |= DC_HPDx_INT_ACK;
3193 WREG32(DC_HPD2_INT_CONTROL, tmp);
3194 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003195 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003196 tmp = RREG32(DC_HPD3_INT_CONTROL);
3197 tmp |= DC_HPDx_INT_ACK;
3198 WREG32(DC_HPD3_INT_CONTROL, tmp);
3199 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003200 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003201 tmp = RREG32(DC_HPD4_INT_CONTROL);
3202 tmp |= DC_HPDx_INT_ACK;
3203 WREG32(DC_HPD4_INT_CONTROL, tmp);
3204 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003205 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003206 tmp = RREG32(DC_HPD5_INT_CONTROL);
3207 tmp |= DC_HPDx_INT_ACK;
3208 WREG32(DC_HPD5_INT_CONTROL, tmp);
3209 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003210 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
Alex Deucher45f9a392010-03-24 13:55:51 -04003211 tmp = RREG32(DC_HPD5_INT_CONTROL);
3212 tmp |= DC_HPDx_INT_ACK;
3213 WREG32(DC_HPD6_INT_CONTROL, tmp);
3214 }
Alex Deucherf122c612012-03-30 08:59:57 -04003215 if (rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG) {
3216 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET);
3217 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
3218 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, tmp);
3219 }
3220 if (rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG) {
3221 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET);
3222 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
3223 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, tmp);
3224 }
3225 if (rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG) {
3226 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET);
3227 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
3228 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, tmp);
3229 }
3230 if (rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG) {
3231 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET);
3232 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
3233 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, tmp);
3234 }
3235 if (rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG) {
3236 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET);
3237 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
3238 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, tmp);
3239 }
3240 if (rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG) {
3241 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET);
3242 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
3243 WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, tmp);
3244 }
Alex Deucher45f9a392010-03-24 13:55:51 -04003245}
3246
Lauri Kasanen1109ca02012-08-31 13:43:50 -04003247static void evergreen_irq_disable(struct radeon_device *rdev)
Alex Deucher45f9a392010-03-24 13:55:51 -04003248{
Alex Deucher45f9a392010-03-24 13:55:51 -04003249 r600_disable_interrupts(rdev);
3250 /* Wait and acknowledge irq */
3251 mdelay(1);
Alex Deucher6f34be52010-11-21 10:59:01 -05003252 evergreen_irq_ack(rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -04003253 evergreen_disable_interrupt_state(rdev);
3254}
3255
Alex Deucher755d8192011-03-02 20:07:34 -05003256void evergreen_irq_suspend(struct radeon_device *rdev)
Alex Deucher45f9a392010-03-24 13:55:51 -04003257{
3258 evergreen_irq_disable(rdev);
3259 r600_rlc_stop(rdev);
3260}
3261
Andi Kleencbdd4502011-10-13 16:08:46 -07003262static u32 evergreen_get_ih_wptr(struct radeon_device *rdev)
Alex Deucher45f9a392010-03-24 13:55:51 -04003263{
3264 u32 wptr, tmp;
3265
Alex Deucher724c80e2010-08-27 18:25:25 -04003266 if (rdev->wb.enabled)
Cédric Cano204ae242011-04-19 11:07:13 -04003267 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
Alex Deucher724c80e2010-08-27 18:25:25 -04003268 else
3269 wptr = RREG32(IH_RB_WPTR);
Alex Deucher45f9a392010-03-24 13:55:51 -04003270
3271 if (wptr & RB_OVERFLOW) {
3272 /* When a ring buffer overflow happen start parsing interrupt
3273 * from the last not overwritten vector (wptr + 16). Hopefully
3274 * this should allow us to catchup.
3275 */
3276 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
3277 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
3278 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
3279 tmp = RREG32(IH_RB_CNTL);
3280 tmp |= IH_WPTR_OVERFLOW_CLEAR;
3281 WREG32(IH_RB_CNTL, tmp);
3282 }
3283 return (wptr & rdev->ih.ptr_mask);
3284}
3285
3286int evergreen_irq_process(struct radeon_device *rdev)
3287{
Dave Airlie682f1a52011-06-18 03:59:51 +00003288 u32 wptr;
3289 u32 rptr;
Alex Deucher45f9a392010-03-24 13:55:51 -04003290 u32 src_id, src_data;
3291 u32 ring_index;
Alex Deucher45f9a392010-03-24 13:55:51 -04003292 bool queue_hotplug = false;
Alex Deucherf122c612012-03-30 08:59:57 -04003293 bool queue_hdmi = false;
Alex Deucher45f9a392010-03-24 13:55:51 -04003294
Dave Airlie682f1a52011-06-18 03:59:51 +00003295 if (!rdev->ih.enabled || rdev->shutdown)
Alex Deucher45f9a392010-03-24 13:55:51 -04003296 return IRQ_NONE;
3297
Dave Airlie682f1a52011-06-18 03:59:51 +00003298 wptr = evergreen_get_ih_wptr(rdev);
Christian Koenigc20dc362012-05-16 21:45:24 +02003299
3300restart_ih:
3301 /* is somebody else already processing irqs? */
3302 if (atomic_xchg(&rdev->ih.lock, 1))
3303 return IRQ_NONE;
3304
Dave Airlie682f1a52011-06-18 03:59:51 +00003305 rptr = rdev->ih.rptr;
3306 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
Alex Deucher45f9a392010-03-24 13:55:51 -04003307
Benjamin Herrenschmidt964f6642011-07-13 16:28:19 +10003308 /* Order reading of wptr vs. reading of IH ring data */
3309 rmb();
3310
Alex Deucher45f9a392010-03-24 13:55:51 -04003311 /* display interrupts */
Alex Deucher6f34be52010-11-21 10:59:01 -05003312 evergreen_irq_ack(rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -04003313
Alex Deucher45f9a392010-03-24 13:55:51 -04003314 while (rptr != wptr) {
3315 /* wptr/rptr are in bytes! */
3316 ring_index = rptr / 4;
Alex Deucher0f234f5f2011-02-13 19:06:33 -05003317 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
3318 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
Alex Deucher45f9a392010-03-24 13:55:51 -04003319
3320 switch (src_id) {
3321 case 1: /* D1 vblank/vline */
3322 switch (src_data) {
3323 case 0: /* D1 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003324 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003325 if (rdev->irq.crtc_vblank_int[0]) {
3326 drm_handle_vblank(rdev->ddev, 0);
3327 rdev->pm.vblank_sync = true;
3328 wake_up(&rdev->irq.vblank_queue);
3329 }
Christian Koenig736fc372012-05-17 19:52:00 +02003330 if (atomic_read(&rdev->irq.pflip[0]))
Mario Kleiner3e4ea742010-11-21 10:59:02 -05003331 radeon_crtc_handle_flip(rdev, 0);
Alex Deucher6f34be52010-11-21 10:59:01 -05003332 rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003333 DRM_DEBUG("IH: D1 vblank\n");
3334 }
3335 break;
3336 case 1: /* D1 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05003337 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
3338 rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003339 DRM_DEBUG("IH: D1 vline\n");
3340 }
3341 break;
3342 default:
3343 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
3344 break;
3345 }
3346 break;
3347 case 2: /* D2 vblank/vline */
3348 switch (src_data) {
3349 case 0: /* D2 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003350 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003351 if (rdev->irq.crtc_vblank_int[1]) {
3352 drm_handle_vblank(rdev->ddev, 1);
3353 rdev->pm.vblank_sync = true;
3354 wake_up(&rdev->irq.vblank_queue);
3355 }
Christian Koenig736fc372012-05-17 19:52:00 +02003356 if (atomic_read(&rdev->irq.pflip[1]))
Mario Kleiner3e4ea742010-11-21 10:59:02 -05003357 radeon_crtc_handle_flip(rdev, 1);
Alex Deucher6f34be52010-11-21 10:59:01 -05003358 rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003359 DRM_DEBUG("IH: D2 vblank\n");
3360 }
3361 break;
3362 case 1: /* D2 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05003363 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
3364 rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003365 DRM_DEBUG("IH: D2 vline\n");
3366 }
3367 break;
3368 default:
3369 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
3370 break;
3371 }
3372 break;
3373 case 3: /* D3 vblank/vline */
3374 switch (src_data) {
3375 case 0: /* D3 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003376 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
3377 if (rdev->irq.crtc_vblank_int[2]) {
3378 drm_handle_vblank(rdev->ddev, 2);
3379 rdev->pm.vblank_sync = true;
3380 wake_up(&rdev->irq.vblank_queue);
3381 }
Christian Koenig736fc372012-05-17 19:52:00 +02003382 if (atomic_read(&rdev->irq.pflip[2]))
Alex Deucher6f34be52010-11-21 10:59:01 -05003383 radeon_crtc_handle_flip(rdev, 2);
3384 rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003385 DRM_DEBUG("IH: D3 vblank\n");
3386 }
3387 break;
3388 case 1: /* D3 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05003389 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
3390 rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003391 DRM_DEBUG("IH: D3 vline\n");
3392 }
3393 break;
3394 default:
3395 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
3396 break;
3397 }
3398 break;
3399 case 4: /* D4 vblank/vline */
3400 switch (src_data) {
3401 case 0: /* D4 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003402 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
3403 if (rdev->irq.crtc_vblank_int[3]) {
3404 drm_handle_vblank(rdev->ddev, 3);
3405 rdev->pm.vblank_sync = true;
3406 wake_up(&rdev->irq.vblank_queue);
3407 }
Christian Koenig736fc372012-05-17 19:52:00 +02003408 if (atomic_read(&rdev->irq.pflip[3]))
Alex Deucher6f34be52010-11-21 10:59:01 -05003409 radeon_crtc_handle_flip(rdev, 3);
3410 rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003411 DRM_DEBUG("IH: D4 vblank\n");
3412 }
3413 break;
3414 case 1: /* D4 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05003415 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
3416 rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003417 DRM_DEBUG("IH: D4 vline\n");
3418 }
3419 break;
3420 default:
3421 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
3422 break;
3423 }
3424 break;
3425 case 5: /* D5 vblank/vline */
3426 switch (src_data) {
3427 case 0: /* D5 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003428 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
3429 if (rdev->irq.crtc_vblank_int[4]) {
3430 drm_handle_vblank(rdev->ddev, 4);
3431 rdev->pm.vblank_sync = true;
3432 wake_up(&rdev->irq.vblank_queue);
3433 }
Christian Koenig736fc372012-05-17 19:52:00 +02003434 if (atomic_read(&rdev->irq.pflip[4]))
Alex Deucher6f34be52010-11-21 10:59:01 -05003435 radeon_crtc_handle_flip(rdev, 4);
3436 rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003437 DRM_DEBUG("IH: D5 vblank\n");
3438 }
3439 break;
3440 case 1: /* D5 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05003441 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
3442 rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003443 DRM_DEBUG("IH: D5 vline\n");
3444 }
3445 break;
3446 default:
3447 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
3448 break;
3449 }
3450 break;
3451 case 6: /* D6 vblank/vline */
3452 switch (src_data) {
3453 case 0: /* D6 vblank */
Alex Deucher6f34be52010-11-21 10:59:01 -05003454 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
3455 if (rdev->irq.crtc_vblank_int[5]) {
3456 drm_handle_vblank(rdev->ddev, 5);
3457 rdev->pm.vblank_sync = true;
3458 wake_up(&rdev->irq.vblank_queue);
3459 }
Christian Koenig736fc372012-05-17 19:52:00 +02003460 if (atomic_read(&rdev->irq.pflip[5]))
Alex Deucher6f34be52010-11-21 10:59:01 -05003461 radeon_crtc_handle_flip(rdev, 5);
3462 rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003463 DRM_DEBUG("IH: D6 vblank\n");
3464 }
3465 break;
3466 case 1: /* D6 vline */
Alex Deucher6f34be52010-11-21 10:59:01 -05003467 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
3468 rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003469 DRM_DEBUG("IH: D6 vline\n");
3470 }
3471 break;
3472 default:
3473 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
3474 break;
3475 }
3476 break;
3477 case 42: /* HPD hotplug */
3478 switch (src_data) {
3479 case 0:
Alex Deucher6f34be52010-11-21 10:59:01 -05003480 if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
3481 rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003482 queue_hotplug = true;
3483 DRM_DEBUG("IH: HPD1\n");
3484 }
3485 break;
3486 case 1:
Alex Deucher6f34be52010-11-21 10:59:01 -05003487 if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
3488 rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003489 queue_hotplug = true;
3490 DRM_DEBUG("IH: HPD2\n");
3491 }
3492 break;
3493 case 2:
Alex Deucher6f34be52010-11-21 10:59:01 -05003494 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
3495 rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003496 queue_hotplug = true;
3497 DRM_DEBUG("IH: HPD3\n");
3498 }
3499 break;
3500 case 3:
Alex Deucher6f34be52010-11-21 10:59:01 -05003501 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
3502 rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003503 queue_hotplug = true;
3504 DRM_DEBUG("IH: HPD4\n");
3505 }
3506 break;
3507 case 4:
Alex Deucher6f34be52010-11-21 10:59:01 -05003508 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
3509 rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003510 queue_hotplug = true;
3511 DRM_DEBUG("IH: HPD5\n");
3512 }
3513 break;
3514 case 5:
Alex Deucher6f34be52010-11-21 10:59:01 -05003515 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
3516 rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
Alex Deucher45f9a392010-03-24 13:55:51 -04003517 queue_hotplug = true;
3518 DRM_DEBUG("IH: HPD6\n");
3519 }
3520 break;
3521 default:
3522 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
3523 break;
3524 }
3525 break;
Alex Deucherf122c612012-03-30 08:59:57 -04003526 case 44: /* hdmi */
3527 switch (src_data) {
3528 case 0:
3529 if (rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG) {
3530 rdev->irq.stat_regs.evergreen.afmt_status1 &= ~AFMT_AZ_FORMAT_WTRIG;
3531 queue_hdmi = true;
3532 DRM_DEBUG("IH: HDMI0\n");
3533 }
3534 break;
3535 case 1:
3536 if (rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG) {
3537 rdev->irq.stat_regs.evergreen.afmt_status2 &= ~AFMT_AZ_FORMAT_WTRIG;
3538 queue_hdmi = true;
3539 DRM_DEBUG("IH: HDMI1\n");
3540 }
3541 break;
3542 case 2:
3543 if (rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG) {
3544 rdev->irq.stat_regs.evergreen.afmt_status3 &= ~AFMT_AZ_FORMAT_WTRIG;
3545 queue_hdmi = true;
3546 DRM_DEBUG("IH: HDMI2\n");
3547 }
3548 break;
3549 case 3:
3550 if (rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG) {
3551 rdev->irq.stat_regs.evergreen.afmt_status4 &= ~AFMT_AZ_FORMAT_WTRIG;
3552 queue_hdmi = true;
3553 DRM_DEBUG("IH: HDMI3\n");
3554 }
3555 break;
3556 case 4:
3557 if (rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG) {
3558 rdev->irq.stat_regs.evergreen.afmt_status5 &= ~AFMT_AZ_FORMAT_WTRIG;
3559 queue_hdmi = true;
3560 DRM_DEBUG("IH: HDMI4\n");
3561 }
3562 break;
3563 case 5:
3564 if (rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG) {
3565 rdev->irq.stat_regs.evergreen.afmt_status6 &= ~AFMT_AZ_FORMAT_WTRIG;
3566 queue_hdmi = true;
3567 DRM_DEBUG("IH: HDMI5\n");
3568 }
3569 break;
3570 default:
3571 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
3572 break;
3573 }
Christian Königf2ba57b2013-04-08 12:41:29 +02003574 case 124: /* UVD */
3575 DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
3576 radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
Alex Deucherf122c612012-03-30 08:59:57 -04003577 break;
Christian Königae133a12012-09-18 15:30:44 -04003578 case 146:
3579 case 147:
3580 dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
3581 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
3582 RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
3583 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
3584 RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
3585 /* reset addr and status */
3586 WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
3587 break;
Alex Deucher45f9a392010-03-24 13:55:51 -04003588 case 176: /* CP_INT in ring buffer */
3589 case 177: /* CP_INT in IB1 */
3590 case 178: /* CP_INT in IB2 */
3591 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
Alex Deucher74652802011-08-25 13:39:48 -04003592 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
Alex Deucher45f9a392010-03-24 13:55:51 -04003593 break;
3594 case 181: /* CP EOP event */
3595 DRM_DEBUG("IH: CP EOP\n");
Alex Deucher1b370782011-11-17 20:13:28 -05003596 if (rdev->family >= CHIP_CAYMAN) {
3597 switch (src_data) {
3598 case 0:
3599 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
3600 break;
3601 case 1:
3602 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
3603 break;
3604 case 2:
3605 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
3606 break;
3607 }
3608 } else
3609 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
Alex Deucher45f9a392010-03-24 13:55:51 -04003610 break;
Alex Deucher233d1ad2012-12-04 15:25:59 -05003611 case 224: /* DMA trap event */
3612 DRM_DEBUG("IH: DMA trap\n");
3613 radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
3614 break;
Alex Deucher2031f772010-04-22 12:52:11 -04003615 case 233: /* GUI IDLE */
Ilija Hadzic303c8052011-06-07 14:54:48 -04003616 DRM_DEBUG("IH: GUI idle\n");
Alex Deucher2031f772010-04-22 12:52:11 -04003617 break;
Alex Deucherf60cbd12012-12-04 15:27:33 -05003618 case 244: /* DMA trap event */
3619 if (rdev->family >= CHIP_CAYMAN) {
3620 DRM_DEBUG("IH: DMA1 trap\n");
3621 radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
3622 }
3623 break;
Alex Deucher45f9a392010-03-24 13:55:51 -04003624 default:
3625 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
3626 break;
3627 }
3628
3629 /* wptr/rptr are in bytes! */
3630 rptr += 16;
3631 rptr &= rdev->ih.ptr_mask;
3632 }
Alex Deucher45f9a392010-03-24 13:55:51 -04003633 if (queue_hotplug)
Tejun Heo32c87fc2011-01-03 14:49:32 +01003634 schedule_work(&rdev->hotplug_work);
Alex Deucherf122c612012-03-30 08:59:57 -04003635 if (queue_hdmi)
3636 schedule_work(&rdev->audio_work);
Alex Deucher45f9a392010-03-24 13:55:51 -04003637 rdev->ih.rptr = rptr;
3638 WREG32(IH_RB_RPTR, rdev->ih.rptr);
Christian Koenigc20dc362012-05-16 21:45:24 +02003639 atomic_set(&rdev->ih.lock, 0);
3640
3641 /* make sure wptr hasn't changed while processing */
3642 wptr = evergreen_get_ih_wptr(rdev);
3643 if (wptr != rptr)
3644 goto restart_ih;
3645
Alex Deucher45f9a392010-03-24 13:55:51 -04003646 return IRQ_HANDLED;
3647}
3648
Alex Deucher233d1ad2012-12-04 15:25:59 -05003649/**
3650 * evergreen_dma_fence_ring_emit - emit a fence on the DMA ring
3651 *
3652 * @rdev: radeon_device pointer
3653 * @fence: radeon fence object
3654 *
3655 * Add a DMA fence packet to the ring to write
3656 * the fence seq number and DMA trap packet to generate
3657 * an interrupt if needed (evergreen-SI).
3658 */
3659void evergreen_dma_fence_ring_emit(struct radeon_device *rdev,
3660 struct radeon_fence *fence)
3661{
3662 struct radeon_ring *ring = &rdev->ring[fence->ring];
3663 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
3664 /* write the fence */
Jerome Glisse0fcb6152013-01-14 11:32:27 -05003665 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_FENCE, 0, 0));
Alex Deucher233d1ad2012-12-04 15:25:59 -05003666 radeon_ring_write(ring, addr & 0xfffffffc);
3667 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff));
3668 radeon_ring_write(ring, fence->seq);
3669 /* generate an interrupt */
Jerome Glisse0fcb6152013-01-14 11:32:27 -05003670 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_TRAP, 0, 0));
Alex Deucher233d1ad2012-12-04 15:25:59 -05003671 /* flush HDP */
Jerome Glisse0fcb6152013-01-14 11:32:27 -05003672 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0));
Alex Deucher4b681c22013-01-03 19:54:34 -05003673 radeon_ring_write(ring, (0xf << 16) | (HDP_MEM_COHERENCY_FLUSH_CNTL >> 2));
Alex Deucher233d1ad2012-12-04 15:25:59 -05003674 radeon_ring_write(ring, 1);
3675}
3676
3677/**
3678 * evergreen_dma_ring_ib_execute - schedule an IB on the DMA engine
3679 *
3680 * @rdev: radeon_device pointer
3681 * @ib: IB object to schedule
3682 *
3683 * Schedule an IB in the DMA ring (evergreen).
3684 */
3685void evergreen_dma_ring_ib_execute(struct radeon_device *rdev,
3686 struct radeon_ib *ib)
3687{
3688 struct radeon_ring *ring = &rdev->ring[ib->ring];
3689
3690 if (rdev->wb.enabled) {
3691 u32 next_rptr = ring->wptr + 4;
3692 while ((next_rptr & 7) != 5)
3693 next_rptr++;
3694 next_rptr += 3;
Jerome Glisse0fcb6152013-01-14 11:32:27 -05003695 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 1));
Alex Deucher233d1ad2012-12-04 15:25:59 -05003696 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
3697 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xff);
3698 radeon_ring_write(ring, next_rptr);
3699 }
3700
3701 /* The indirect buffer packet must end on an 8 DW boundary in the DMA ring.
3702 * Pad as necessary with NOPs.
3703 */
3704 while ((ring->wptr & 7) != 5)
Jerome Glisse0fcb6152013-01-14 11:32:27 -05003705 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_NOP, 0, 0));
3706 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_INDIRECT_BUFFER, 0, 0));
Alex Deucher233d1ad2012-12-04 15:25:59 -05003707 radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFE0));
3708 radeon_ring_write(ring, (ib->length_dw << 12) | (upper_32_bits(ib->gpu_addr) & 0xFF));
3709
3710}
3711
3712/**
3713 * evergreen_copy_dma - copy pages using the DMA engine
3714 *
3715 * @rdev: radeon_device pointer
3716 * @src_offset: src GPU address
3717 * @dst_offset: dst GPU address
3718 * @num_gpu_pages: number of GPU pages to xfer
3719 * @fence: radeon fence object
3720 *
3721 * Copy GPU paging using the DMA engine (evergreen-cayman).
3722 * Used by the radeon ttm implementation to move pages if
3723 * registered as the asic copy callback.
3724 */
3725int evergreen_copy_dma(struct radeon_device *rdev,
3726 uint64_t src_offset, uint64_t dst_offset,
3727 unsigned num_gpu_pages,
3728 struct radeon_fence **fence)
3729{
3730 struct radeon_semaphore *sem = NULL;
3731 int ring_index = rdev->asic->copy.dma_ring_index;
3732 struct radeon_ring *ring = &rdev->ring[ring_index];
3733 u32 size_in_dw, cur_size_in_dw;
3734 int i, num_loops;
3735 int r = 0;
3736
3737 r = radeon_semaphore_create(rdev, &sem);
3738 if (r) {
3739 DRM_ERROR("radeon: moving bo (%d).\n", r);
3740 return r;
3741 }
3742
3743 size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4;
3744 num_loops = DIV_ROUND_UP(size_in_dw, 0xfffff);
3745 r = radeon_ring_lock(rdev, ring, num_loops * 5 + 11);
3746 if (r) {
3747 DRM_ERROR("radeon: moving bo (%d).\n", r);
3748 radeon_semaphore_free(rdev, &sem, NULL);
3749 return r;
3750 }
3751
3752 if (radeon_fence_need_sync(*fence, ring->idx)) {
3753 radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring,
3754 ring->idx);
3755 radeon_fence_note_sync(*fence, ring->idx);
3756 } else {
3757 radeon_semaphore_free(rdev, &sem, NULL);
3758 }
3759
3760 for (i = 0; i < num_loops; i++) {
3761 cur_size_in_dw = size_in_dw;
3762 if (cur_size_in_dw > 0xFFFFF)
3763 cur_size_in_dw = 0xFFFFF;
3764 size_in_dw -= cur_size_in_dw;
Jerome Glisse0fcb6152013-01-14 11:32:27 -05003765 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, cur_size_in_dw));
Alex Deucher233d1ad2012-12-04 15:25:59 -05003766 radeon_ring_write(ring, dst_offset & 0xfffffffc);
3767 radeon_ring_write(ring, src_offset & 0xfffffffc);
3768 radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
3769 radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff);
3770 src_offset += cur_size_in_dw * 4;
3771 dst_offset += cur_size_in_dw * 4;
3772 }
3773
3774 r = radeon_fence_emit(rdev, fence, ring->idx);
3775 if (r) {
3776 radeon_ring_unlock_undo(rdev, ring);
3777 return r;
3778 }
3779
3780 radeon_ring_unlock_commit(rdev, ring);
3781 radeon_semaphore_free(rdev, &sem, *fence);
3782
3783 return r;
3784}
3785
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003786static int evergreen_startup(struct radeon_device *rdev)
3787{
Christian Königf2ba57b2013-04-08 12:41:29 +02003788 struct radeon_ring *ring;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003789 int r;
3790
Alex Deucher9e46a482011-01-06 18:49:35 -05003791 /* enable pcie gen2 link */
Ilija Hadziccd540332011-09-20 10:22:57 -04003792 evergreen_pcie_gen2_enable(rdev);
Alex Deucher9e46a482011-01-06 18:49:35 -05003793
Alex Deucher0af62b02011-01-06 21:19:31 -05003794 if (ASIC_IS_DCE5(rdev)) {
3795 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
3796 r = ni_init_microcode(rdev);
3797 if (r) {
3798 DRM_ERROR("Failed to load firmware!\n");
3799 return r;
3800 }
3801 }
Alex Deucher755d8192011-03-02 20:07:34 -05003802 r = ni_mc_load_microcode(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003803 if (r) {
Alex Deucher0af62b02011-01-06 21:19:31 -05003804 DRM_ERROR("Failed to load MC firmware!\n");
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003805 return r;
3806 }
Alex Deucher0af62b02011-01-06 21:19:31 -05003807 } else {
3808 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
3809 r = r600_init_microcode(rdev);
3810 if (r) {
3811 DRM_ERROR("Failed to load firmware!\n");
3812 return r;
3813 }
3814 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003815 }
Alex Deucherfe251e22010-03-24 13:36:43 -04003816
Alex Deucher16cdf042011-10-28 10:30:02 -04003817 r = r600_vram_scratch_init(rdev);
3818 if (r)
3819 return r;
3820
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003821 evergreen_mc_program(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003822 if (rdev->flags & RADEON_IS_AGP) {
Alex Deucher0fcdb612010-03-24 13:20:41 -04003823 evergreen_agp_enable(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003824 } else {
3825 r = evergreen_pcie_gart_enable(rdev);
3826 if (r)
3827 return r;
3828 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003829 evergreen_gpu_init(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003830
Alex Deucherd7ccd8f2010-09-09 11:33:36 -04003831 r = evergreen_blit_init(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003832 if (r) {
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -04003833 r600_blit_fini(rdev);
Alex Deucher27cd7762012-02-23 17:53:42 -05003834 rdev->asic->copy.copy = NULL;
Alex Deucherd7ccd8f2010-09-09 11:33:36 -04003835 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003836 }
3837
Alex Deucher724c80e2010-08-27 18:25:25 -04003838 /* allocate wb buffer */
3839 r = radeon_wb_init(rdev);
3840 if (r)
3841 return r;
3842
Jerome Glisse30eb77f2011-11-20 20:45:34 +00003843 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
3844 if (r) {
3845 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
3846 return r;
3847 }
3848
Alex Deucher233d1ad2012-12-04 15:25:59 -05003849 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
3850 if (r) {
3851 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
3852 return r;
3853 }
3854
Christian Königf2ba57b2013-04-08 12:41:29 +02003855 r = rv770_uvd_resume(rdev);
3856 if (!r) {
3857 r = radeon_fence_driver_start_ring(rdev,
3858 R600_RING_TYPE_UVD_INDEX);
3859 if (r)
3860 dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
3861 }
3862
3863 if (r)
3864 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
3865
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003866 /* Enable IRQ */
3867 r = r600_irq_init(rdev);
3868 if (r) {
3869 DRM_ERROR("radeon: IH init failed (%d).\n", r);
3870 radeon_irq_kms_fini(rdev);
3871 return r;
3872 }
Alex Deucher45f9a392010-03-24 13:55:51 -04003873 evergreen_irq_set(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003874
Christian Königf2ba57b2013-04-08 12:41:29 +02003875 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Christian Könige32eb502011-10-23 12:56:27 +02003876 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
Alex Deucher78c55602011-11-17 14:25:56 -05003877 R600_CP_RB_RPTR, R600_CP_RB_WPTR,
3878 0, 0xfffff, RADEON_CP_PACKET2);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003879 if (r)
3880 return r;
Alex Deucher233d1ad2012-12-04 15:25:59 -05003881
3882 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
3883 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
3884 DMA_RB_RPTR, DMA_RB_WPTR,
Jerome Glisse0fcb6152013-01-14 11:32:27 -05003885 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0));
Alex Deucher233d1ad2012-12-04 15:25:59 -05003886 if (r)
3887 return r;
3888
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003889 r = evergreen_cp_load_microcode(rdev);
3890 if (r)
3891 return r;
Alex Deucherfe251e22010-03-24 13:36:43 -04003892 r = evergreen_cp_resume(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003893 if (r)
3894 return r;
Alex Deucher233d1ad2012-12-04 15:25:59 -05003895 r = r600_dma_resume(rdev);
3896 if (r)
3897 return r;
Alex Deucherfe251e22010-03-24 13:36:43 -04003898
Christian Königf2ba57b2013-04-08 12:41:29 +02003899 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
3900 if (ring->ring_size) {
3901 r = radeon_ring_init(rdev, ring, ring->ring_size,
3902 R600_WB_UVD_RPTR_OFFSET,
3903 UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR,
3904 0, 0xfffff, RADEON_CP_PACKET2);
3905 if (!r)
3906 r = r600_uvd_init(rdev);
3907
3908 if (r)
3909 DRM_ERROR("radeon: error initializing UVD (%d).\n", r);
3910 }
3911
Christian König2898c342012-07-05 11:55:34 +02003912 r = radeon_ib_pool_init(rdev);
3913 if (r) {
3914 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisseb15ba512011-11-15 11:48:34 -05003915 return r;
Christian König2898c342012-07-05 11:55:34 +02003916 }
Jerome Glisseb15ba512011-11-15 11:48:34 -05003917
Rafał Miłecki69d2ae52011-12-07 23:32:24 +01003918 r = r600_audio_init(rdev);
3919 if (r) {
3920 DRM_ERROR("radeon: audio init failed\n");
Jerome Glisseb15ba512011-11-15 11:48:34 -05003921 return r;
3922 }
3923
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003924 return 0;
3925}
3926
3927int evergreen_resume(struct radeon_device *rdev)
3928{
3929 int r;
3930
Alex Deucher86f5c9e2010-12-20 12:35:04 -05003931 /* reset the asic, the gfx blocks are often in a bad state
3932 * after the driver is unloaded or after a resume
3933 */
3934 if (radeon_asic_reset(rdev))
3935 dev_warn(rdev->dev, "GPU reset failed !\n");
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003936 /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
3937 * posting will perform necessary task to bring back GPU into good
3938 * shape.
3939 */
3940 /* post card */
3941 atom_asic_init(rdev->mode_info.atom_context);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003942
Jerome Glisseb15ba512011-11-15 11:48:34 -05003943 rdev->accel_working = true;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003944 r = evergreen_startup(rdev);
3945 if (r) {
Alex Deucher755d8192011-03-02 20:07:34 -05003946 DRM_ERROR("evergreen startup failed on resume\n");
Jerome Glisse6b7746e2012-02-20 17:57:20 -05003947 rdev->accel_working = false;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003948 return r;
3949 }
Alex Deucherfe251e22010-03-24 13:36:43 -04003950
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003951 return r;
3952
3953}
3954
3955int evergreen_suspend(struct radeon_device *rdev)
3956{
Rafał Miłecki69d2ae52011-12-07 23:32:24 +01003957 r600_audio_fini(rdev);
Christian Königf2ba57b2013-04-08 12:41:29 +02003958 radeon_uvd_suspend(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003959 r700_cp_stop(rdev);
Alex Deucher233d1ad2012-12-04 15:25:59 -05003960 r600_dma_stop(rdev);
Christian Königf2ba57b2013-04-08 12:41:29 +02003961 r600_uvd_rbc_stop(rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -04003962 evergreen_irq_suspend(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04003963 radeon_wb_disable(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003964 evergreen_pcie_gart_disable(rdev);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -04003965
3966 return 0;
3967}
3968
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003969/* Plan is to move initialization in that function and use
3970 * helper function so that radeon_device_init pretty much
3971 * do nothing more than calling asic specific function. This
3972 * should also allow to remove a bunch of callback function
3973 * like vram_info.
3974 */
3975int evergreen_init(struct radeon_device *rdev)
3976{
3977 int r;
3978
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003979 /* Read BIOS */
3980 if (!radeon_get_bios(rdev)) {
3981 if (ASIC_IS_AVIVO(rdev))
3982 return -EINVAL;
3983 }
3984 /* Must be an ATOMBIOS */
3985 if (!rdev->is_atom_bios) {
Alex Deucher755d8192011-03-02 20:07:34 -05003986 dev_err(rdev->dev, "Expecting atombios for evergreen GPU\n");
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003987 return -EINVAL;
3988 }
3989 r = radeon_atombios_init(rdev);
3990 if (r)
3991 return r;
Alex Deucher86f5c9e2010-12-20 12:35:04 -05003992 /* reset the asic, the gfx blocks are often in a bad state
3993 * after the driver is unloaded or after a resume
3994 */
3995 if (radeon_asic_reset(rdev))
3996 dev_warn(rdev->dev, "GPU reset failed !\n");
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003997 /* Post card if necessary */
Alex Deucherfd909c32011-01-11 18:08:59 -05003998 if (!radeon_card_posted(rdev)) {
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05003999 if (!rdev->bios) {
4000 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
4001 return -EINVAL;
4002 }
4003 DRM_INFO("GPU not posted. posting now...\n");
4004 atom_asic_init(rdev->mode_info.atom_context);
4005 }
4006 /* Initialize scratch registers */
4007 r600_scratch_init(rdev);
4008 /* Initialize surface registers */
4009 radeon_surface_init(rdev);
4010 /* Initialize clocks */
4011 radeon_get_clock_info(rdev->ddev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004012 /* Fence driver */
4013 r = radeon_fence_driver_init(rdev);
4014 if (r)
4015 return r;
Jerome Glissed594e462010-02-17 21:54:29 +00004016 /* initialize AGP */
4017 if (rdev->flags & RADEON_IS_AGP) {
4018 r = radeon_agp_init(rdev);
4019 if (r)
4020 radeon_agp_disable(rdev);
4021 }
4022 /* initialize memory controller */
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004023 r = evergreen_mc_init(rdev);
4024 if (r)
4025 return r;
4026 /* Memory manager */
4027 r = radeon_bo_init(rdev);
4028 if (r)
4029 return r;
Alex Deucher45f9a392010-03-24 13:55:51 -04004030
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004031 r = radeon_irq_kms_init(rdev);
4032 if (r)
4033 return r;
4034
Christian Könige32eb502011-10-23 12:56:27 +02004035 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
4036 r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004037
Alex Deucher233d1ad2012-12-04 15:25:59 -05004038 rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL;
4039 r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024);
4040
Christian Königf2ba57b2013-04-08 12:41:29 +02004041 r = radeon_uvd_init(rdev);
4042 if (!r) {
4043 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
4044 r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX],
4045 4096);
4046 }
4047
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004048 rdev->ih.ring_obj = NULL;
4049 r600_ih_ring_init(rdev, 64 * 1024);
4050
4051 r = r600_pcie_gart_init(rdev);
4052 if (r)
4053 return r;
Alex Deucher0fcdb612010-03-24 13:20:41 -04004054
Alex Deucher148a03b2010-06-03 19:00:03 -04004055 rdev->accel_working = true;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004056 r = evergreen_startup(rdev);
4057 if (r) {
Alex Deucherfe251e22010-03-24 13:36:43 -04004058 dev_err(rdev->dev, "disabling GPU acceleration\n");
4059 r700_cp_fini(rdev);
Alex Deucher233d1ad2012-12-04 15:25:59 -05004060 r600_dma_fini(rdev);
Alex Deucherfe251e22010-03-24 13:36:43 -04004061 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04004062 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02004063 radeon_ib_pool_fini(rdev);
Alex Deucherfe251e22010-03-24 13:36:43 -04004064 radeon_irq_kms_fini(rdev);
Alex Deucher0fcdb612010-03-24 13:20:41 -04004065 evergreen_pcie_gart_fini(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004066 rdev->accel_working = false;
4067 }
Alex Deucher77e00f22011-12-21 11:58:17 -05004068
4069 /* Don't start up if the MC ucode is missing on BTC parts.
4070 * The default clocks and voltages before the MC ucode
4071 * is loaded are not suffient for advanced operations.
4072 */
4073 if (ASIC_IS_DCE5(rdev)) {
4074 if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
4075 DRM_ERROR("radeon: MC ucode required for NI+.\n");
4076 return -EINVAL;
4077 }
4078 }
4079
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004080 return 0;
4081}
4082
4083void evergreen_fini(struct radeon_device *rdev)
4084{
Rafał Miłecki69d2ae52011-12-07 23:32:24 +01004085 r600_audio_fini(rdev);
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -04004086 r600_blit_fini(rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -04004087 r700_cp_fini(rdev);
Alex Deucher233d1ad2012-12-04 15:25:59 -05004088 r600_dma_fini(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004089 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04004090 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02004091 radeon_ib_pool_fini(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004092 radeon_irq_kms_fini(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004093 evergreen_pcie_gart_fini(rdev);
Christian Königf2ba57b2013-04-08 12:41:29 +02004094 radeon_uvd_fini(rdev);
Alex Deucher16cdf042011-10-28 10:30:02 -04004095 r600_vram_scratch_fini(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004096 radeon_gem_fini(rdev);
4097 radeon_fence_driver_fini(rdev);
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004098 radeon_agp_fini(rdev);
4099 radeon_bo_fini(rdev);
4100 radeon_atombios_fini(rdev);
4101 kfree(rdev->bios);
4102 rdev->bios = NULL;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05004103}
Alex Deucher9e46a482011-01-06 18:49:35 -05004104
Ilija Hadzicb07759b2011-09-20 10:22:58 -04004105void evergreen_pcie_gen2_enable(struct radeon_device *rdev)
Alex Deucher9e46a482011-01-06 18:49:35 -05004106{
Dave Airlie197bbb32012-06-27 08:35:54 +01004107 u32 link_width_cntl, speed_cntl, mask;
4108 int ret;
Alex Deucher9e46a482011-01-06 18:49:35 -05004109
Alex Deucherd42dd572011-01-12 20:05:11 -05004110 if (radeon_pcie_gen2 == 0)
4111 return;
4112
Alex Deucher9e46a482011-01-06 18:49:35 -05004113 if (rdev->flags & RADEON_IS_IGP)
4114 return;
4115
4116 if (!(rdev->flags & RADEON_IS_PCIE))
4117 return;
4118
4119 /* x2 cards have a special sequence */
4120 if (ASIC_IS_X2(rdev))
4121 return;
4122
Dave Airlie197bbb32012-06-27 08:35:54 +01004123 ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
4124 if (ret != 0)
4125 return;
4126
4127 if (!(mask & DRM_PCIE_SPEED_50))
4128 return;
4129
Alex Deucher3691fee2012-10-08 17:46:27 -04004130 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4131 if (speed_cntl & LC_CURRENT_DATA_RATE) {
4132 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
4133 return;
4134 }
4135
Dave Airlie197bbb32012-06-27 08:35:54 +01004136 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
4137
Alex Deucher9e46a482011-01-06 18:49:35 -05004138 if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) ||
4139 (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
4140
4141 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
4142 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
4143 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4144
4145 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4146 speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
4147 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
4148
4149 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4150 speed_cntl |= LC_CLR_FAILED_SPD_CHANGE_CNT;
4151 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
4152
4153 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4154 speed_cntl &= ~LC_CLR_FAILED_SPD_CHANGE_CNT;
4155 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
4156
4157 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4158 speed_cntl |= LC_GEN2_EN_STRAP;
4159 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
4160
4161 } else {
4162 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
4163 /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
4164 if (1)
4165 link_width_cntl |= LC_UPCONFIGURE_DIS;
4166 else
4167 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
4168 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4169 }
4170}