blob: 30c4b46f35217a0a6492ea5e08d1bf438ecafe32 [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
Jerome Glissec010f802009-09-30 22:09:06 +020028/* RS600 / Radeon X1250/X1270 integrated GPU
29 *
30 * This file gather function specific to RS600 which is the IGP of
31 * the X1250/X1270 family supporting intel CPU (while RS690/RS740
32 * is the X1250/X1270 supporting AMD CPU). The display engine are
33 * the avivo one, bios is an atombios, 3D block are the one of the
34 * R4XX family. The GART is different from the RS400 one and is very
35 * close to the one of the R600 family (R600 likely being an evolution
36 * of the RS600 GART block).
37 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +020038#include "drmP.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020039#include "radeon.h"
Daniel Vettere6990372010-03-11 21:19:17 +000040#include "radeon_asic.h"
Jerome Glissec010f802009-09-30 22:09:06 +020041#include "atom.h"
42#include "rs600d.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020043
Dave Airlie3f7dc91a2009-08-27 11:10:15 +100044#include "rs600_reg_safe.h"
45
Jerome Glisse771fe6b2009-06-05 14:42:42 +020046void rs600_gpu_init(struct radeon_device *rdev);
47int rs600_mc_wait_for_idle(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020048
Alex Deucherdcfdd402009-12-04 15:04:19 -050049/* hpd for digital panel detect/disconnect */
50bool rs600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
51{
52 u32 tmp;
53 bool connected = false;
54
55 switch (hpd) {
56 case RADEON_HPD_1:
57 tmp = RREG32(R_007D04_DC_HOT_PLUG_DETECT1_INT_STATUS);
58 if (G_007D04_DC_HOT_PLUG_DETECT1_SENSE(tmp))
59 connected = true;
60 break;
61 case RADEON_HPD_2:
62 tmp = RREG32(R_007D14_DC_HOT_PLUG_DETECT2_INT_STATUS);
63 if (G_007D14_DC_HOT_PLUG_DETECT2_SENSE(tmp))
64 connected = true;
65 break;
66 default:
67 break;
68 }
69 return connected;
70}
71
72void rs600_hpd_set_polarity(struct radeon_device *rdev,
73 enum radeon_hpd_id hpd)
74{
75 u32 tmp;
76 bool connected = rs600_hpd_sense(rdev, hpd);
77
78 switch (hpd) {
79 case RADEON_HPD_1:
80 tmp = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL);
81 if (connected)
82 tmp &= ~S_007D08_DC_HOT_PLUG_DETECT1_INT_POLARITY(1);
83 else
84 tmp |= S_007D08_DC_HOT_PLUG_DETECT1_INT_POLARITY(1);
85 WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
86 break;
87 case RADEON_HPD_2:
88 tmp = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL);
89 if (connected)
90 tmp &= ~S_007D18_DC_HOT_PLUG_DETECT2_INT_POLARITY(1);
91 else
92 tmp |= S_007D18_DC_HOT_PLUG_DETECT2_INT_POLARITY(1);
93 WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
94 break;
95 default:
96 break;
97 }
98}
99
100void rs600_hpd_init(struct radeon_device *rdev)
101{
102 struct drm_device *dev = rdev->ddev;
103 struct drm_connector *connector;
104
105 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
106 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
107 switch (radeon_connector->hpd.hpd) {
108 case RADEON_HPD_1:
109 WREG32(R_007D00_DC_HOT_PLUG_DETECT1_CONTROL,
110 S_007D00_DC_HOT_PLUG_DETECT1_EN(1));
111 rdev->irq.hpd[0] = true;
112 break;
113 case RADEON_HPD_2:
114 WREG32(R_007D10_DC_HOT_PLUG_DETECT2_CONTROL,
115 S_007D10_DC_HOT_PLUG_DETECT2_EN(1));
116 rdev->irq.hpd[1] = true;
117 break;
118 default:
119 break;
120 }
121 }
Jerome Glisse003e69f2010-01-07 15:39:14 +0100122 if (rdev->irq.installed)
123 rs600_irq_set(rdev);
Alex Deucherdcfdd402009-12-04 15:04:19 -0500124}
125
126void rs600_hpd_fini(struct radeon_device *rdev)
127{
128 struct drm_device *dev = rdev->ddev;
129 struct drm_connector *connector;
130
131 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
132 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
133 switch (radeon_connector->hpd.hpd) {
134 case RADEON_HPD_1:
135 WREG32(R_007D00_DC_HOT_PLUG_DETECT1_CONTROL,
136 S_007D00_DC_HOT_PLUG_DETECT1_EN(0));
137 rdev->irq.hpd[0] = false;
138 break;
139 case RADEON_HPD_2:
140 WREG32(R_007D10_DC_HOT_PLUG_DETECT2_CONTROL,
141 S_007D10_DC_HOT_PLUG_DETECT2_EN(0));
142 rdev->irq.hpd[1] = false;
143 break;
144 default:
145 break;
146 }
147 }
148}
149
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200150/*
151 * GART.
152 */
153void rs600_gart_tlb_flush(struct radeon_device *rdev)
154{
155 uint32_t tmp;
156
Jerome Glissec010f802009-09-30 22:09:06 +0200157 tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
158 tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE;
159 WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200160
Jerome Glissec010f802009-09-30 22:09:06 +0200161 tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
162 tmp |= S_000100_INVALIDATE_ALL_L1_TLBS(1) & S_000100_INVALIDATE_L2_CACHE(1);
163 WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200164
Jerome Glissec010f802009-09-30 22:09:06 +0200165 tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
166 tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE;
167 WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
168 tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200169}
170
Jerome Glisse4aac0472009-09-14 18:29:49 +0200171int rs600_gart_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200172{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200173 int r;
174
Jerome Glisse4aac0472009-09-14 18:29:49 +0200175 if (rdev->gart.table.vram.robj) {
176 WARN(1, "RS600 GART already initialized.\n");
177 return 0;
178 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200179 /* Initialize common gart structure */
180 r = radeon_gart_init(rdev);
181 if (r) {
182 return r;
183 }
184 rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
Jerome Glisse4aac0472009-09-14 18:29:49 +0200185 return radeon_gart_table_vram_alloc(rdev);
186}
187
188int rs600_gart_enable(struct radeon_device *rdev)
189{
Jerome Glissec010f802009-09-30 22:09:06 +0200190 u32 tmp;
Jerome Glisse4aac0472009-09-14 18:29:49 +0200191 int r, i;
192
193 if (rdev->gart.table.vram.robj == NULL) {
194 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
195 return -EINVAL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200196 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200197 r = radeon_gart_table_vram_pin(rdev);
198 if (r)
199 return r;
Dave Airlie82568562010-02-05 16:00:07 +1000200 radeon_gart_restore(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200201 /* Enable bus master */
202 tmp = RREG32(R_00004C_BUS_CNTL) & C_00004C_BUS_MASTER_DIS;
203 WREG32(R_00004C_BUS_CNTL, tmp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200204 /* FIXME: setup default page */
Jerome Glissec010f802009-09-30 22:09:06 +0200205 WREG32_MC(R_000100_MC_PT0_CNTL,
Alex Deucher4f15d242009-12-05 17:55:37 -0500206 (S_000100_EFFECTIVE_L2_CACHE_SIZE(6) |
207 S_000100_EFFECTIVE_L2_QUEUE_SIZE(6)));
208
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200209 for (i = 0; i < 19; i++) {
Jerome Glissec010f802009-09-30 22:09:06 +0200210 WREG32_MC(R_00016C_MC_PT0_CLIENT0_CNTL + i,
Alex Deucher4f15d242009-12-05 17:55:37 -0500211 S_00016C_ENABLE_TRANSLATION_MODE_OVERRIDE(1) |
212 S_00016C_SYSTEM_ACCESS_MODE_MASK(
213 V_00016C_SYSTEM_ACCESS_MODE_NOT_IN_SYS) |
214 S_00016C_SYSTEM_APERTURE_UNMAPPED_ACCESS(
215 V_00016C_SYSTEM_APERTURE_UNMAPPED_PASSTHROUGH) |
216 S_00016C_EFFECTIVE_L1_CACHE_SIZE(3) |
217 S_00016C_ENABLE_FRAGMENT_PROCESSING(1) |
218 S_00016C_EFFECTIVE_L1_QUEUE_SIZE(3));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200219 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200220 /* enable first context */
Jerome Glissec010f802009-09-30 22:09:06 +0200221 WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL,
Alex Deucher4f15d242009-12-05 17:55:37 -0500222 S_000102_ENABLE_PAGE_TABLE(1) |
223 S_000102_PAGE_TABLE_DEPTH(V_000102_PAGE_TABLE_FLAT));
224
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200225 /* disable all other contexts */
Alex Deucher4f15d242009-12-05 17:55:37 -0500226 for (i = 1; i < 8; i++)
Jerome Glissec010f802009-09-30 22:09:06 +0200227 WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL + i, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200228
229 /* setup the page table */
Jerome Glissec010f802009-09-30 22:09:06 +0200230 WREG32_MC(R_00012C_MC_PT0_CONTEXT0_FLAT_BASE_ADDR,
Alex Deucher4f15d242009-12-05 17:55:37 -0500231 rdev->gart.table_addr);
232 WREG32_MC(R_00013C_MC_PT0_CONTEXT0_FLAT_START_ADDR, rdev->mc.gtt_start);
233 WREG32_MC(R_00014C_MC_PT0_CONTEXT0_FLAT_END_ADDR, rdev->mc.gtt_end);
Jerome Glissec010f802009-09-30 22:09:06 +0200234 WREG32_MC(R_00011C_MC_PT0_CONTEXT0_DEFAULT_READ_ADDR, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200235
Alex Deucher4f15d242009-12-05 17:55:37 -0500236 /* System context maps to VRAM space */
237 WREG32_MC(R_000112_MC_PT0_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start);
238 WREG32_MC(R_000114_MC_PT0_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end);
239
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200240 /* enable page tables */
Jerome Glissec010f802009-09-30 22:09:06 +0200241 tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
242 WREG32_MC(R_000100_MC_PT0_CNTL, (tmp | S_000100_ENABLE_PT(1)));
243 tmp = RREG32_MC(R_000009_MC_CNTL1);
244 WREG32_MC(R_000009_MC_CNTL1, (tmp | S_000009_ENABLE_PAGE_TABLES(1)));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200245 rs600_gart_tlb_flush(rdev);
246 rdev->gart.ready = true;
247 return 0;
248}
249
250void rs600_gart_disable(struct radeon_device *rdev)
251{
Jerome Glisse4c788672009-11-20 14:29:23 +0100252 u32 tmp;
253 int r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200254
255 /* FIXME: disable out of gart access */
Jerome Glissec010f802009-09-30 22:09:06 +0200256 WREG32_MC(R_000100_MC_PT0_CNTL, 0);
257 tmp = RREG32_MC(R_000009_MC_CNTL1);
258 WREG32_MC(R_000009_MC_CNTL1, tmp & C_000009_ENABLE_PAGE_TABLES);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200259 if (rdev->gart.table.vram.robj) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100260 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
261 if (r == 0) {
262 radeon_bo_kunmap(rdev->gart.table.vram.robj);
263 radeon_bo_unpin(rdev->gart.table.vram.robj);
264 radeon_bo_unreserve(rdev->gart.table.vram.robj);
265 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200266 }
267}
268
269void rs600_gart_fini(struct radeon_device *rdev)
270{
Jerome Glissef9274562010-03-17 14:44:29 +0000271 radeon_gart_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200272 rs600_gart_disable(rdev);
273 radeon_gart_table_vram_free(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200274}
275
276#define R600_PTE_VALID (1 << 0)
277#define R600_PTE_SYSTEM (1 << 1)
278#define R600_PTE_SNOOPED (1 << 2)
279#define R600_PTE_READABLE (1 << 5)
280#define R600_PTE_WRITEABLE (1 << 6)
281
282int rs600_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
283{
284 void __iomem *ptr = (void *)rdev->gart.table.vram.ptr;
285
286 if (i < 0 || i > rdev->gart.num_gpu_pages) {
287 return -EINVAL;
288 }
289 addr = addr & 0xFFFFFFFFFFFFF000ULL;
290 addr |= R600_PTE_VALID | R600_PTE_SYSTEM | R600_PTE_SNOOPED;
291 addr |= R600_PTE_READABLE | R600_PTE_WRITEABLE;
292 writeq(addr, ((void __iomem *)ptr) + (i * 8));
293 return 0;
294}
295
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200296int rs600_irq_set(struct radeon_device *rdev)
297{
298 uint32_t tmp = 0;
299 uint32_t mode_int = 0;
Alex Deucherdcfdd402009-12-04 15:04:19 -0500300 u32 hpd1 = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL) &
301 ~S_007D08_DC_HOT_PLUG_DETECT1_INT_EN(1);
302 u32 hpd2 = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL) &
303 ~S_007D18_DC_HOT_PLUG_DETECT2_INT_EN(1);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200304
Jerome Glisse003e69f2010-01-07 15:39:14 +0100305 if (!rdev->irq.installed) {
306 WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n");
307 WREG32(R_000040_GEN_INT_CNTL, 0);
308 return -EINVAL;
309 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200310 if (rdev->irq.sw_int) {
Jerome Glissec010f802009-09-30 22:09:06 +0200311 tmp |= S_000040_SW_INT_EN(1);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200312 }
313 if (rdev->irq.crtc_vblank_int[0]) {
Jerome Glissec010f802009-09-30 22:09:06 +0200314 mode_int |= S_006540_D1MODE_VBLANK_INT_MASK(1);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200315 }
316 if (rdev->irq.crtc_vblank_int[1]) {
Jerome Glissec010f802009-09-30 22:09:06 +0200317 mode_int |= S_006540_D2MODE_VBLANK_INT_MASK(1);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200318 }
Alex Deucherdcfdd402009-12-04 15:04:19 -0500319 if (rdev->irq.hpd[0]) {
320 hpd1 |= S_007D08_DC_HOT_PLUG_DETECT1_INT_EN(1);
321 }
322 if (rdev->irq.hpd[1]) {
323 hpd2 |= S_007D18_DC_HOT_PLUG_DETECT2_INT_EN(1);
324 }
Jerome Glissec010f802009-09-30 22:09:06 +0200325 WREG32(R_000040_GEN_INT_CNTL, tmp);
326 WREG32(R_006540_DxMODE_INT_MASK, mode_int);
Alex Deucherdcfdd402009-12-04 15:04:19 -0500327 WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
328 WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200329 return 0;
330}
331
332static inline uint32_t rs600_irq_ack(struct radeon_device *rdev, u32 *r500_disp_int)
333{
Jerome Glisse01ceae82009-10-07 11:08:22 +0200334 uint32_t irqs = RREG32(R_000044_GEN_INT_STATUS);
335 uint32_t irq_mask = ~C_000044_SW_INT;
Alex Deucherdcfdd402009-12-04 15:04:19 -0500336 u32 tmp;
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200337
Jerome Glisse01ceae82009-10-07 11:08:22 +0200338 if (G_000044_DISPLAY_INT_STAT(irqs)) {
Jerome Glissec010f802009-09-30 22:09:06 +0200339 *r500_disp_int = RREG32(R_007EDC_DISP_INTERRUPT_STATUS);
340 if (G_007EDC_LB_D1_VBLANK_INTERRUPT(*r500_disp_int)) {
341 WREG32(R_006534_D1MODE_VBLANK_STATUS,
342 S_006534_D1MODE_VBLANK_ACK(1));
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200343 }
Jerome Glissec010f802009-09-30 22:09:06 +0200344 if (G_007EDC_LB_D2_VBLANK_INTERRUPT(*r500_disp_int)) {
345 WREG32(R_006D34_D2MODE_VBLANK_STATUS,
346 S_006D34_D2MODE_VBLANK_ACK(1));
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200347 }
Alex Deucherdcfdd402009-12-04 15:04:19 -0500348 if (G_007EDC_DC_HOT_PLUG_DETECT1_INTERRUPT(*r500_disp_int)) {
349 tmp = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL);
350 tmp |= S_007D08_DC_HOT_PLUG_DETECT1_INT_ACK(1);
351 WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
352 }
353 if (G_007EDC_DC_HOT_PLUG_DETECT2_INTERRUPT(*r500_disp_int)) {
354 tmp = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL);
355 tmp |= S_007D18_DC_HOT_PLUG_DETECT2_INT_ACK(1);
356 WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
357 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200358 } else {
359 *r500_disp_int = 0;
360 }
361
362 if (irqs) {
Jerome Glisse01ceae82009-10-07 11:08:22 +0200363 WREG32(R_000044_GEN_INT_STATUS, irqs);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200364 }
365 return irqs & irq_mask;
366}
367
Jerome Glisseac447df2009-09-30 22:18:43 +0200368void rs600_irq_disable(struct radeon_device *rdev)
369{
370 u32 tmp;
371
372 WREG32(R_000040_GEN_INT_CNTL, 0);
373 WREG32(R_006540_DxMODE_INT_MASK, 0);
374 /* Wait and acknowledge irq */
375 mdelay(1);
376 rs600_irq_ack(rdev, &tmp);
377}
378
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200379int rs600_irq_process(struct radeon_device *rdev)
380{
Alex Deucher3e5cb982009-10-16 12:21:24 -0400381 uint32_t status, msi_rearm;
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200382 uint32_t r500_disp_int;
Alex Deucherd4877cf2009-12-04 16:56:37 -0500383 bool queue_hotplug = false;
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200384
385 status = rs600_irq_ack(rdev, &r500_disp_int);
386 if (!status && !r500_disp_int) {
387 return IRQ_NONE;
388 }
389 while (status || r500_disp_int) {
390 /* SW interrupt */
Luca Tettamanti43b19f12009-12-28 22:53:05 +0100391 if (G_000044_SW_INT(status))
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200392 radeon_fence_process(rdev);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200393 /* Vertical blank interrupts */
Rafał Miłeckic913e232009-12-22 23:02:16 +0100394 if (G_007EDC_LB_D1_VBLANK_INTERRUPT(r500_disp_int)) {
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200395 drm_handle_vblank(rdev->ddev, 0);
Rafał Miłecki839461d2010-03-02 22:06:51 +0100396 rdev->pm.vblank_sync = true;
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100397 wake_up(&rdev->irq.vblank_queue);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100398 }
399 if (G_007EDC_LB_D2_VBLANK_INTERRUPT(r500_disp_int)) {
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200400 drm_handle_vblank(rdev->ddev, 1);
Rafał Miłecki839461d2010-03-02 22:06:51 +0100401 rdev->pm.vblank_sync = true;
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100402 wake_up(&rdev->irq.vblank_queue);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100403 }
Alex Deucherdcfdd402009-12-04 15:04:19 -0500404 if (G_007EDC_DC_HOT_PLUG_DETECT1_INTERRUPT(r500_disp_int)) {
Alex Deucherd4877cf2009-12-04 16:56:37 -0500405 queue_hotplug = true;
406 DRM_DEBUG("HPD1\n");
Alex Deucherdcfdd402009-12-04 15:04:19 -0500407 }
408 if (G_007EDC_DC_HOT_PLUG_DETECT2_INTERRUPT(r500_disp_int)) {
Alex Deucherd4877cf2009-12-04 16:56:37 -0500409 queue_hotplug = true;
410 DRM_DEBUG("HPD2\n");
Alex Deucherdcfdd402009-12-04 15:04:19 -0500411 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200412 status = rs600_irq_ack(rdev, &r500_disp_int);
413 }
Alex Deucherd4877cf2009-12-04 16:56:37 -0500414 if (queue_hotplug)
415 queue_work(rdev->wq, &rdev->hotplug_work);
Alex Deucher3e5cb982009-10-16 12:21:24 -0400416 if (rdev->msi_enabled) {
417 switch (rdev->family) {
418 case CHIP_RS600:
419 case CHIP_RS690:
420 case CHIP_RS740:
421 msi_rearm = RREG32(RADEON_BUS_CNTL) & ~RS600_MSI_REARM;
422 WREG32(RADEON_BUS_CNTL, msi_rearm);
423 WREG32(RADEON_BUS_CNTL, msi_rearm | RS600_MSI_REARM);
424 break;
425 default:
426 msi_rearm = RREG32(RADEON_MSI_REARM_EN) & ~RV370_MSI_REARM_EN;
427 WREG32(RADEON_MSI_REARM_EN, msi_rearm);
428 WREG32(RADEON_MSI_REARM_EN, msi_rearm | RV370_MSI_REARM_EN);
429 break;
430 }
431 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200432 return IRQ_HANDLED;
433}
434
435u32 rs600_get_vblank_counter(struct radeon_device *rdev, int crtc)
436{
437 if (crtc == 0)
Jerome Glissec010f802009-09-30 22:09:06 +0200438 return RREG32(R_0060A4_D1CRTC_STATUS_FRAME_COUNT);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200439 else
Jerome Glissec010f802009-09-30 22:09:06 +0200440 return RREG32(R_0068A4_D2CRTC_STATUS_FRAME_COUNT);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200441}
442
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200443int rs600_mc_wait_for_idle(struct radeon_device *rdev)
444{
445 unsigned i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200446
447 for (i = 0; i < rdev->usec_timeout; i++) {
Jerome Glissec010f802009-09-30 22:09:06 +0200448 if (G_000000_MC_IDLE(RREG32_MC(R_000000_MC_STATUS)))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200449 return 0;
Jerome Glissec010f802009-09-30 22:09:06 +0200450 udelay(1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200451 }
452 return -1;
453}
454
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200455void rs600_gpu_init(struct radeon_device *rdev)
456{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200457 r100_hdp_reset(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200458 r420_pipes_init(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200459 /* Wait for mc idle */
460 if (rs600_mc_wait_for_idle(rdev))
461 dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200462}
463
Jerome Glissed594e462010-02-17 21:54:29 +0000464void rs600_mc_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200465{
Jerome Glissed594e462010-02-17 21:54:29 +0000466 u64 base;
467
Jerome Glisse51e5fcd2010-02-19 14:33:54 +0000468 rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
469 rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200470 rdev->mc.vram_is_ddr = true;
471 rdev->mc.vram_width = 128;
Alex Deucher722f2942009-12-03 16:18:19 -0500472 rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
473 rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
Jerome Glisse51e5fcd2010-02-19 14:33:54 +0000474 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Jerome Glissed594e462010-02-17 21:54:29 +0000475 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
476 base = RREG32_MC(R_000004_MC_FB_LOCATION);
477 base = G_000004_MC_FB_START(base) << 16;
Alex Deucherf47299c2010-03-16 20:54:38 -0400478 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
Jerome Glissed594e462010-02-17 21:54:29 +0000479 radeon_vram_location(rdev, &rdev->mc, base);
480 radeon_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -0400481 radeon_update_bandwidth_info(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200482}
483
Jerome Glissec93bb852009-07-13 21:04:08 +0200484void rs600_bandwidth_update(struct radeon_device *rdev)
485{
486 /* FIXME: implement, should this be like rs690 ? */
487}
488
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200489uint32_t rs600_mc_rreg(struct radeon_device *rdev, uint32_t reg)
490{
Jerome Glissec010f802009-09-30 22:09:06 +0200491 WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) |
492 S_000070_MC_IND_CITF_ARB0(1));
493 return RREG32(R_000074_MC_IND_DATA);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200494}
495
496void rs600_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
497{
Jerome Glissec010f802009-09-30 22:09:06 +0200498 WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) |
499 S_000070_MC_IND_CITF_ARB0(1) | S_000070_MC_IND_WR_EN(1));
500 WREG32(R_000074_MC_IND_DATA, v);
501}
502
503void rs600_debugfs(struct radeon_device *rdev)
504{
505 if (r100_debugfs_rbbm_init(rdev))
506 DRM_ERROR("Failed to register debugfs file for RBBM !\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200507}
Dave Airlie3f7dc91a2009-08-27 11:10:15 +1000508
Jerome Glisse3bc68532009-10-01 09:39:24 +0200509void rs600_set_safe_registers(struct radeon_device *rdev)
Dave Airlie3f7dc91a2009-08-27 11:10:15 +1000510{
511 rdev->config.r300.reg_safe_bm = rs600_reg_safe_bm;
512 rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(rs600_reg_safe_bm);
Jerome Glisse3bc68532009-10-01 09:39:24 +0200513}
514
Jerome Glissec010f802009-09-30 22:09:06 +0200515static void rs600_mc_program(struct radeon_device *rdev)
516{
517 struct rv515_mc_save save;
518
519 /* Stops all mc clients */
520 rv515_mc_stop(rdev, &save);
521
522 /* Wait for mc idle */
523 if (rs600_mc_wait_for_idle(rdev))
524 dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
525
526 /* FIXME: What does AGP means for such chipset ? */
527 WREG32_MC(R_000005_MC_AGP_LOCATION, 0x0FFFFFFF);
528 WREG32_MC(R_000006_AGP_BASE, 0);
529 WREG32_MC(R_000007_AGP_BASE_2, 0);
530 /* Program MC */
531 WREG32_MC(R_000004_MC_FB_LOCATION,
532 S_000004_MC_FB_START(rdev->mc.vram_start >> 16) |
533 S_000004_MC_FB_TOP(rdev->mc.vram_end >> 16));
534 WREG32(R_000134_HDP_FB_LOCATION,
535 S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
536
537 rv515_mc_resume(rdev, &save);
538}
539
540static int rs600_startup(struct radeon_device *rdev)
541{
542 int r;
543
544 rs600_mc_program(rdev);
545 /* Resume clock */
546 rv515_clock_startup(rdev);
547 /* Initialize GPU configuration (# pipes, ...) */
548 rs600_gpu_init(rdev);
549 /* Initialize GART (initialize after TTM so we can allocate
550 * memory through TTM but finalize after TTM) */
551 r = rs600_gart_enable(rdev);
552 if (r)
553 return r;
554 /* Enable IRQ */
Jerome Glissec010f802009-09-30 22:09:06 +0200555 rs600_irq_set(rdev);
Jerome Glissecafe6602010-01-07 12:39:21 +0100556 rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
Jerome Glissec010f802009-09-30 22:09:06 +0200557 /* 1M ring buffer */
558 r = r100_cp_init(rdev, 1024 * 1024);
559 if (r) {
560 dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
561 return r;
562 }
563 r = r100_wb_init(rdev);
564 if (r)
565 dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
566 r = r100_ib_init(rdev);
567 if (r) {
568 dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
569 return r;
570 }
571 return 0;
572}
573
574int rs600_resume(struct radeon_device *rdev)
575{
576 /* Make sur GART are not working */
577 rs600_gart_disable(rdev);
578 /* Resume clock before doing reset */
579 rv515_clock_startup(rdev);
580 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
581 if (radeon_gpu_reset(rdev)) {
582 dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
583 RREG32(R_000E40_RBBM_STATUS),
584 RREG32(R_0007C0_CP_STAT));
585 }
586 /* post */
587 atom_asic_init(rdev->mode_info.atom_context);
588 /* Resume clock after posting */
589 rv515_clock_startup(rdev);
Dave Airlie550e2d92009-12-09 14:15:38 +1000590 /* Initialize surface registers */
591 radeon_surface_init(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200592 return rs600_startup(rdev);
593}
594
595int rs600_suspend(struct radeon_device *rdev)
596{
597 r100_cp_disable(rdev);
598 r100_wb_disable(rdev);
Jerome Glisseac447df2009-09-30 22:18:43 +0200599 rs600_irq_disable(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200600 rs600_gart_disable(rdev);
601 return 0;
602}
603
604void rs600_fini(struct radeon_device *rdev)
605{
Alex Deucher29fb52c2010-03-11 10:01:17 -0500606 radeon_pm_fini(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200607 r100_cp_fini(rdev);
608 r100_wb_fini(rdev);
609 r100_ib_fini(rdev);
610 radeon_gem_fini(rdev);
611 rs600_gart_fini(rdev);
612 radeon_irq_kms_fini(rdev);
613 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +0100614 radeon_bo_fini(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200615 radeon_atombios_fini(rdev);
616 kfree(rdev->bios);
617 rdev->bios = NULL;
618}
619
Jerome Glisse3bc68532009-10-01 09:39:24 +0200620int rs600_init(struct radeon_device *rdev)
621{
Jerome Glissec010f802009-09-30 22:09:06 +0200622 int r;
623
Jerome Glissec010f802009-09-30 22:09:06 +0200624 /* Disable VGA */
625 rv515_vga_render_disable(rdev);
626 /* Initialize scratch registers */
627 radeon_scratch_init(rdev);
628 /* Initialize surface registers */
629 radeon_surface_init(rdev);
630 /* BIOS */
631 if (!radeon_get_bios(rdev)) {
632 if (ASIC_IS_AVIVO(rdev))
633 return -EINVAL;
634 }
635 if (rdev->is_atom_bios) {
636 r = radeon_atombios_init(rdev);
637 if (r)
638 return r;
639 } else {
640 dev_err(rdev->dev, "Expecting atombios for RS600 GPU\n");
641 return -EINVAL;
642 }
643 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
644 if (radeon_gpu_reset(rdev)) {
645 dev_warn(rdev->dev,
646 "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
647 RREG32(R_000E40_RBBM_STATUS),
648 RREG32(R_0007C0_CP_STAT));
649 }
650 /* check if cards are posted or not */
Dave Airlie72542d72009-12-01 14:06:31 +1000651 if (radeon_boot_test_post_card(rdev) == false)
652 return -EINVAL;
653
Jerome Glissec010f802009-09-30 22:09:06 +0200654 /* Initialize clocks */
655 radeon_get_clock_info(rdev->ddev);
Rafał Miłecki74338742009-11-03 00:53:02 +0100656 /* Initialize power management */
657 radeon_pm_init(rdev);
Jerome Glissed594e462010-02-17 21:54:29 +0000658 /* initialize memory controller */
659 rs600_mc_init(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200660 rs600_debugfs(rdev);
661 /* Fence driver */
662 r = radeon_fence_driver_init(rdev);
663 if (r)
664 return r;
665 r = radeon_irq_kms_init(rdev);
666 if (r)
667 return r;
668 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +0100669 r = radeon_bo_init(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200670 if (r)
671 return r;
672 r = rs600_gart_init(rdev);
673 if (r)
674 return r;
675 rs600_set_safe_registers(rdev);
676 rdev->accel_working = true;
677 r = rs600_startup(rdev);
678 if (r) {
679 /* Somethings want wront with the accel init stop accel */
680 dev_err(rdev->dev, "Disabling GPU acceleration\n");
Jerome Glissec010f802009-09-30 22:09:06 +0200681 r100_cp_fini(rdev);
682 r100_wb_fini(rdev);
683 r100_ib_fini(rdev);
684 rs600_gart_fini(rdev);
685 radeon_irq_kms_fini(rdev);
686 rdev->accel_working = false;
687 }
Dave Airlie3f7dc91a2009-08-27 11:10:15 +1000688 return 0;
689}