blob: a581fdead4dd811659069107347334dcef1bfeb8 [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"
Jerome Glissec010f802009-09-30 22:09:06 +020040#include "atom.h"
41#include "rs600d.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020042
Dave Airlie3f7dc91a2009-08-27 11:10:15 +100043#include "rs600_reg_safe.h"
44
Jerome Glisse771fe6b2009-06-05 14:42:42 +020045void rs600_gpu_init(struct radeon_device *rdev);
46int rs600_mc_wait_for_idle(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020047
Dave Airlie64bffd02009-12-07 13:29:51 +100048int rs600_mc_init(struct radeon_device *rdev)
49{
50 /* read back the MC value from the hw */
Dave Airlie64bffd02009-12-07 13:29:51 +100051 int r;
Alex Deucher22dd5012009-12-06 19:45:17 -050052 u32 tmp;
Dave Airlie64bffd02009-12-07 13:29:51 +100053
Alex Deucher22dd5012009-12-06 19:45:17 -050054 /* Setup GPU memory space */
55 tmp = RREG32_MC(R_000004_MC_FB_LOCATION);
56 rdev->mc.vram_location = G_000004_MC_FB_START(tmp) << 16;
Dave Airlie64bffd02009-12-07 13:29:51 +100057 rdev->mc.gtt_location = 0xffffffffUL;
58 r = radeon_mc_setup(rdev);
Alex Deucher06b64762010-01-05 11:27:29 -050059 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
Dave Airlie64bffd02009-12-07 13:29:51 +100060 if (r)
61 return r;
62 return 0;
63}
Alex Deucherdcfdd402009-12-04 15:04:19 -050064
65/* hpd for digital panel detect/disconnect */
66bool rs600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
67{
68 u32 tmp;
69 bool connected = false;
70
71 switch (hpd) {
72 case RADEON_HPD_1:
73 tmp = RREG32(R_007D04_DC_HOT_PLUG_DETECT1_INT_STATUS);
74 if (G_007D04_DC_HOT_PLUG_DETECT1_SENSE(tmp))
75 connected = true;
76 break;
77 case RADEON_HPD_2:
78 tmp = RREG32(R_007D14_DC_HOT_PLUG_DETECT2_INT_STATUS);
79 if (G_007D14_DC_HOT_PLUG_DETECT2_SENSE(tmp))
80 connected = true;
81 break;
82 default:
83 break;
84 }
85 return connected;
86}
87
88void rs600_hpd_set_polarity(struct radeon_device *rdev,
89 enum radeon_hpd_id hpd)
90{
91 u32 tmp;
92 bool connected = rs600_hpd_sense(rdev, hpd);
93
94 switch (hpd) {
95 case RADEON_HPD_1:
96 tmp = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL);
97 if (connected)
98 tmp &= ~S_007D08_DC_HOT_PLUG_DETECT1_INT_POLARITY(1);
99 else
100 tmp |= S_007D08_DC_HOT_PLUG_DETECT1_INT_POLARITY(1);
101 WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
102 break;
103 case RADEON_HPD_2:
104 tmp = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL);
105 if (connected)
106 tmp &= ~S_007D18_DC_HOT_PLUG_DETECT2_INT_POLARITY(1);
107 else
108 tmp |= S_007D18_DC_HOT_PLUG_DETECT2_INT_POLARITY(1);
109 WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
110 break;
111 default:
112 break;
113 }
114}
115
116void rs600_hpd_init(struct radeon_device *rdev)
117{
118 struct drm_device *dev = rdev->ddev;
119 struct drm_connector *connector;
120
121 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
122 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
123 switch (radeon_connector->hpd.hpd) {
124 case RADEON_HPD_1:
125 WREG32(R_007D00_DC_HOT_PLUG_DETECT1_CONTROL,
126 S_007D00_DC_HOT_PLUG_DETECT1_EN(1));
127 rdev->irq.hpd[0] = true;
128 break;
129 case RADEON_HPD_2:
130 WREG32(R_007D10_DC_HOT_PLUG_DETECT2_CONTROL,
131 S_007D10_DC_HOT_PLUG_DETECT2_EN(1));
132 rdev->irq.hpd[1] = true;
133 break;
134 default:
135 break;
136 }
137 }
Jerome Glisse003e69f2010-01-07 15:39:14 +0100138 if (rdev->irq.installed)
139 rs600_irq_set(rdev);
Alex Deucherdcfdd402009-12-04 15:04:19 -0500140}
141
142void rs600_hpd_fini(struct radeon_device *rdev)
143{
144 struct drm_device *dev = rdev->ddev;
145 struct drm_connector *connector;
146
147 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
148 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
149 switch (radeon_connector->hpd.hpd) {
150 case RADEON_HPD_1:
151 WREG32(R_007D00_DC_HOT_PLUG_DETECT1_CONTROL,
152 S_007D00_DC_HOT_PLUG_DETECT1_EN(0));
153 rdev->irq.hpd[0] = false;
154 break;
155 case RADEON_HPD_2:
156 WREG32(R_007D10_DC_HOT_PLUG_DETECT2_CONTROL,
157 S_007D10_DC_HOT_PLUG_DETECT2_EN(0));
158 rdev->irq.hpd[1] = false;
159 break;
160 default:
161 break;
162 }
163 }
164}
165
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200166/*
167 * GART.
168 */
169void rs600_gart_tlb_flush(struct radeon_device *rdev)
170{
171 uint32_t tmp;
172
Jerome Glissec010f802009-09-30 22:09:06 +0200173 tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
174 tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE;
175 WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200176
Jerome Glissec010f802009-09-30 22:09:06 +0200177 tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
178 tmp |= S_000100_INVALIDATE_ALL_L1_TLBS(1) & S_000100_INVALIDATE_L2_CACHE(1);
179 WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200180
Jerome Glissec010f802009-09-30 22:09:06 +0200181 tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
182 tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE;
183 WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
184 tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200185}
186
Jerome Glisse4aac0472009-09-14 18:29:49 +0200187int rs600_gart_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200188{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200189 int r;
190
Jerome Glisse4aac0472009-09-14 18:29:49 +0200191 if (rdev->gart.table.vram.robj) {
192 WARN(1, "RS600 GART already initialized.\n");
193 return 0;
194 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200195 /* Initialize common gart structure */
196 r = radeon_gart_init(rdev);
197 if (r) {
198 return r;
199 }
200 rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
Jerome Glisse4aac0472009-09-14 18:29:49 +0200201 return radeon_gart_table_vram_alloc(rdev);
202}
203
204int rs600_gart_enable(struct radeon_device *rdev)
205{
Jerome Glissec010f802009-09-30 22:09:06 +0200206 u32 tmp;
Jerome Glisse4aac0472009-09-14 18:29:49 +0200207 int r, i;
208
209 if (rdev->gart.table.vram.robj == NULL) {
210 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
211 return -EINVAL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200212 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200213 r = radeon_gart_table_vram_pin(rdev);
214 if (r)
215 return r;
Jerome Glissec010f802009-09-30 22:09:06 +0200216 /* Enable bus master */
217 tmp = RREG32(R_00004C_BUS_CNTL) & C_00004C_BUS_MASTER_DIS;
218 WREG32(R_00004C_BUS_CNTL, tmp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200219 /* FIXME: setup default page */
Jerome Glissec010f802009-09-30 22:09:06 +0200220 WREG32_MC(R_000100_MC_PT0_CNTL,
Alex Deucher4f15d242009-12-05 17:55:37 -0500221 (S_000100_EFFECTIVE_L2_CACHE_SIZE(6) |
222 S_000100_EFFECTIVE_L2_QUEUE_SIZE(6)));
223
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200224 for (i = 0; i < 19; i++) {
Jerome Glissec010f802009-09-30 22:09:06 +0200225 WREG32_MC(R_00016C_MC_PT0_CLIENT0_CNTL + i,
Alex Deucher4f15d242009-12-05 17:55:37 -0500226 S_00016C_ENABLE_TRANSLATION_MODE_OVERRIDE(1) |
227 S_00016C_SYSTEM_ACCESS_MODE_MASK(
228 V_00016C_SYSTEM_ACCESS_MODE_NOT_IN_SYS) |
229 S_00016C_SYSTEM_APERTURE_UNMAPPED_ACCESS(
230 V_00016C_SYSTEM_APERTURE_UNMAPPED_PASSTHROUGH) |
231 S_00016C_EFFECTIVE_L1_CACHE_SIZE(3) |
232 S_00016C_ENABLE_FRAGMENT_PROCESSING(1) |
233 S_00016C_EFFECTIVE_L1_QUEUE_SIZE(3));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200234 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200235 /* enable first context */
Jerome Glissec010f802009-09-30 22:09:06 +0200236 WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL,
Alex Deucher4f15d242009-12-05 17:55:37 -0500237 S_000102_ENABLE_PAGE_TABLE(1) |
238 S_000102_PAGE_TABLE_DEPTH(V_000102_PAGE_TABLE_FLAT));
239
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200240 /* disable all other contexts */
Alex Deucher4f15d242009-12-05 17:55:37 -0500241 for (i = 1; i < 8; i++)
Jerome Glissec010f802009-09-30 22:09:06 +0200242 WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL + i, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200243
244 /* setup the page table */
Jerome Glissec010f802009-09-30 22:09:06 +0200245 WREG32_MC(R_00012C_MC_PT0_CONTEXT0_FLAT_BASE_ADDR,
Alex Deucher4f15d242009-12-05 17:55:37 -0500246 rdev->gart.table_addr);
247 WREG32_MC(R_00013C_MC_PT0_CONTEXT0_FLAT_START_ADDR, rdev->mc.gtt_start);
248 WREG32_MC(R_00014C_MC_PT0_CONTEXT0_FLAT_END_ADDR, rdev->mc.gtt_end);
Jerome Glissec010f802009-09-30 22:09:06 +0200249 WREG32_MC(R_00011C_MC_PT0_CONTEXT0_DEFAULT_READ_ADDR, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200250
Alex Deucher4f15d242009-12-05 17:55:37 -0500251 /* System context maps to VRAM space */
252 WREG32_MC(R_000112_MC_PT0_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start);
253 WREG32_MC(R_000114_MC_PT0_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end);
254
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200255 /* enable page tables */
Jerome Glissec010f802009-09-30 22:09:06 +0200256 tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
257 WREG32_MC(R_000100_MC_PT0_CNTL, (tmp | S_000100_ENABLE_PT(1)));
258 tmp = RREG32_MC(R_000009_MC_CNTL1);
259 WREG32_MC(R_000009_MC_CNTL1, (tmp | S_000009_ENABLE_PAGE_TABLES(1)));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200260 rs600_gart_tlb_flush(rdev);
261 rdev->gart.ready = true;
262 return 0;
263}
264
265void rs600_gart_disable(struct radeon_device *rdev)
266{
Jerome Glisse4c788672009-11-20 14:29:23 +0100267 u32 tmp;
268 int r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200269
270 /* FIXME: disable out of gart access */
Jerome Glissec010f802009-09-30 22:09:06 +0200271 WREG32_MC(R_000100_MC_PT0_CNTL, 0);
272 tmp = RREG32_MC(R_000009_MC_CNTL1);
273 WREG32_MC(R_000009_MC_CNTL1, tmp & C_000009_ENABLE_PAGE_TABLES);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200274 if (rdev->gart.table.vram.robj) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100275 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
276 if (r == 0) {
277 radeon_bo_kunmap(rdev->gart.table.vram.robj);
278 radeon_bo_unpin(rdev->gart.table.vram.robj);
279 radeon_bo_unreserve(rdev->gart.table.vram.robj);
280 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200281 }
282}
283
284void rs600_gart_fini(struct radeon_device *rdev)
285{
286 rs600_gart_disable(rdev);
287 radeon_gart_table_vram_free(rdev);
288 radeon_gart_fini(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200289}
290
291#define R600_PTE_VALID (1 << 0)
292#define R600_PTE_SYSTEM (1 << 1)
293#define R600_PTE_SNOOPED (1 << 2)
294#define R600_PTE_READABLE (1 << 5)
295#define R600_PTE_WRITEABLE (1 << 6)
296
297int rs600_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
298{
299 void __iomem *ptr = (void *)rdev->gart.table.vram.ptr;
300
301 if (i < 0 || i > rdev->gart.num_gpu_pages) {
302 return -EINVAL;
303 }
304 addr = addr & 0xFFFFFFFFFFFFF000ULL;
305 addr |= R600_PTE_VALID | R600_PTE_SYSTEM | R600_PTE_SNOOPED;
306 addr |= R600_PTE_READABLE | R600_PTE_WRITEABLE;
307 writeq(addr, ((void __iomem *)ptr) + (i * 8));
308 return 0;
309}
310
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200311int rs600_irq_set(struct radeon_device *rdev)
312{
313 uint32_t tmp = 0;
314 uint32_t mode_int = 0;
Alex Deucherdcfdd402009-12-04 15:04:19 -0500315 u32 hpd1 = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL) &
316 ~S_007D08_DC_HOT_PLUG_DETECT1_INT_EN(1);
317 u32 hpd2 = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL) &
318 ~S_007D18_DC_HOT_PLUG_DETECT2_INT_EN(1);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200319
Jerome Glisse003e69f2010-01-07 15:39:14 +0100320 if (!rdev->irq.installed) {
321 WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n");
322 WREG32(R_000040_GEN_INT_CNTL, 0);
323 return -EINVAL;
324 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200325 if (rdev->irq.sw_int) {
Jerome Glissec010f802009-09-30 22:09:06 +0200326 tmp |= S_000040_SW_INT_EN(1);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200327 }
328 if (rdev->irq.crtc_vblank_int[0]) {
Jerome Glissec010f802009-09-30 22:09:06 +0200329 mode_int |= S_006540_D1MODE_VBLANK_INT_MASK(1);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200330 }
331 if (rdev->irq.crtc_vblank_int[1]) {
Jerome Glissec010f802009-09-30 22:09:06 +0200332 mode_int |= S_006540_D2MODE_VBLANK_INT_MASK(1);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200333 }
Alex Deucherdcfdd402009-12-04 15:04:19 -0500334 if (rdev->irq.hpd[0]) {
335 hpd1 |= S_007D08_DC_HOT_PLUG_DETECT1_INT_EN(1);
336 }
337 if (rdev->irq.hpd[1]) {
338 hpd2 |= S_007D18_DC_HOT_PLUG_DETECT2_INT_EN(1);
339 }
Jerome Glissec010f802009-09-30 22:09:06 +0200340 WREG32(R_000040_GEN_INT_CNTL, tmp);
341 WREG32(R_006540_DxMODE_INT_MASK, mode_int);
Alex Deucherdcfdd402009-12-04 15:04:19 -0500342 WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
343 WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200344 return 0;
345}
346
347static inline uint32_t rs600_irq_ack(struct radeon_device *rdev, u32 *r500_disp_int)
348{
Jerome Glisse01ceae82009-10-07 11:08:22 +0200349 uint32_t irqs = RREG32(R_000044_GEN_INT_STATUS);
350 uint32_t irq_mask = ~C_000044_SW_INT;
Alex Deucherdcfdd402009-12-04 15:04:19 -0500351 u32 tmp;
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200352
Jerome Glisse01ceae82009-10-07 11:08:22 +0200353 if (G_000044_DISPLAY_INT_STAT(irqs)) {
Jerome Glissec010f802009-09-30 22:09:06 +0200354 *r500_disp_int = RREG32(R_007EDC_DISP_INTERRUPT_STATUS);
355 if (G_007EDC_LB_D1_VBLANK_INTERRUPT(*r500_disp_int)) {
356 WREG32(R_006534_D1MODE_VBLANK_STATUS,
357 S_006534_D1MODE_VBLANK_ACK(1));
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200358 }
Jerome Glissec010f802009-09-30 22:09:06 +0200359 if (G_007EDC_LB_D2_VBLANK_INTERRUPT(*r500_disp_int)) {
360 WREG32(R_006D34_D2MODE_VBLANK_STATUS,
361 S_006D34_D2MODE_VBLANK_ACK(1));
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200362 }
Alex Deucherdcfdd402009-12-04 15:04:19 -0500363 if (G_007EDC_DC_HOT_PLUG_DETECT1_INTERRUPT(*r500_disp_int)) {
364 tmp = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL);
365 tmp |= S_007D08_DC_HOT_PLUG_DETECT1_INT_ACK(1);
366 WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
367 }
368 if (G_007EDC_DC_HOT_PLUG_DETECT2_INTERRUPT(*r500_disp_int)) {
369 tmp = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL);
370 tmp |= S_007D18_DC_HOT_PLUG_DETECT2_INT_ACK(1);
371 WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
372 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200373 } else {
374 *r500_disp_int = 0;
375 }
376
377 if (irqs) {
Jerome Glisse01ceae82009-10-07 11:08:22 +0200378 WREG32(R_000044_GEN_INT_STATUS, irqs);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200379 }
380 return irqs & irq_mask;
381}
382
Jerome Glisseac447df2009-09-30 22:18:43 +0200383void rs600_irq_disable(struct radeon_device *rdev)
384{
385 u32 tmp;
386
387 WREG32(R_000040_GEN_INT_CNTL, 0);
388 WREG32(R_006540_DxMODE_INT_MASK, 0);
389 /* Wait and acknowledge irq */
390 mdelay(1);
391 rs600_irq_ack(rdev, &tmp);
392}
393
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200394int rs600_irq_process(struct radeon_device *rdev)
395{
Alex Deucher3e5cb982009-10-16 12:21:24 -0400396 uint32_t status, msi_rearm;
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200397 uint32_t r500_disp_int;
Alex Deucherd4877cf2009-12-04 16:56:37 -0500398 bool queue_hotplug = false;
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200399
400 status = rs600_irq_ack(rdev, &r500_disp_int);
401 if (!status && !r500_disp_int) {
402 return IRQ_NONE;
403 }
404 while (status || r500_disp_int) {
405 /* SW interrupt */
Luca Tettamanti43b19f12009-12-28 22:53:05 +0100406 if (G_000044_SW_INT(status))
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200407 radeon_fence_process(rdev);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200408 /* Vertical blank interrupts */
Rafał Miłeckic913e232009-12-22 23:02:16 +0100409 if (G_007EDC_LB_D1_VBLANK_INTERRUPT(r500_disp_int)) {
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200410 drm_handle_vblank(rdev->ddev, 0);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100411 if (rdev->pm.vblank_callback)
412 queue_work(rdev->wq, &rdev->pm.reclock_work);
413 }
414 if (G_007EDC_LB_D2_VBLANK_INTERRUPT(r500_disp_int)) {
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200415 drm_handle_vblank(rdev->ddev, 1);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100416 if (rdev->pm.vblank_callback)
417 queue_work(rdev->wq, &rdev->pm.reclock_work);
418 }
Alex Deucherdcfdd402009-12-04 15:04:19 -0500419 if (G_007EDC_DC_HOT_PLUG_DETECT1_INTERRUPT(r500_disp_int)) {
Alex Deucherd4877cf2009-12-04 16:56:37 -0500420 queue_hotplug = true;
421 DRM_DEBUG("HPD1\n");
Alex Deucherdcfdd402009-12-04 15:04:19 -0500422 }
423 if (G_007EDC_DC_HOT_PLUG_DETECT2_INTERRUPT(r500_disp_int)) {
Alex Deucherd4877cf2009-12-04 16:56:37 -0500424 queue_hotplug = true;
425 DRM_DEBUG("HPD2\n");
Alex Deucherdcfdd402009-12-04 15:04:19 -0500426 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200427 status = rs600_irq_ack(rdev, &r500_disp_int);
428 }
Alex Deucherd4877cf2009-12-04 16:56:37 -0500429 if (queue_hotplug)
430 queue_work(rdev->wq, &rdev->hotplug_work);
Alex Deucher3e5cb982009-10-16 12:21:24 -0400431 if (rdev->msi_enabled) {
432 switch (rdev->family) {
433 case CHIP_RS600:
434 case CHIP_RS690:
435 case CHIP_RS740:
436 msi_rearm = RREG32(RADEON_BUS_CNTL) & ~RS600_MSI_REARM;
437 WREG32(RADEON_BUS_CNTL, msi_rearm);
438 WREG32(RADEON_BUS_CNTL, msi_rearm | RS600_MSI_REARM);
439 break;
440 default:
441 msi_rearm = RREG32(RADEON_MSI_REARM_EN) & ~RV370_MSI_REARM_EN;
442 WREG32(RADEON_MSI_REARM_EN, msi_rearm);
443 WREG32(RADEON_MSI_REARM_EN, msi_rearm | RV370_MSI_REARM_EN);
444 break;
445 }
446 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200447 return IRQ_HANDLED;
448}
449
450u32 rs600_get_vblank_counter(struct radeon_device *rdev, int crtc)
451{
452 if (crtc == 0)
Jerome Glissec010f802009-09-30 22:09:06 +0200453 return RREG32(R_0060A4_D1CRTC_STATUS_FRAME_COUNT);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200454 else
Jerome Glissec010f802009-09-30 22:09:06 +0200455 return RREG32(R_0068A4_D2CRTC_STATUS_FRAME_COUNT);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200456}
457
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200458int rs600_mc_wait_for_idle(struct radeon_device *rdev)
459{
460 unsigned i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200461
462 for (i = 0; i < rdev->usec_timeout; i++) {
Jerome Glissec010f802009-09-30 22:09:06 +0200463 if (G_000000_MC_IDLE(RREG32_MC(R_000000_MC_STATUS)))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200464 return 0;
Jerome Glissec010f802009-09-30 22:09:06 +0200465 udelay(1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200466 }
467 return -1;
468}
469
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200470void rs600_gpu_init(struct radeon_device *rdev)
471{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200472 r100_hdp_reset(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200473 r420_pipes_init(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200474 /* Wait for mc idle */
475 if (rs600_mc_wait_for_idle(rdev))
476 dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200477}
478
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200479void rs600_vram_info(struct radeon_device *rdev)
480{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200481 rdev->mc.vram_is_ddr = true;
482 rdev->mc.vram_width = 128;
Alex Deucher722f2942009-12-03 16:18:19 -0500483
484 rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
485 rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
486
487 rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
488 rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
Alex Deucher0088dbd2009-12-03 16:28:02 -0500489
490 if (rdev->mc.mc_vram_size > rdev->mc.aper_size)
491 rdev->mc.mc_vram_size = rdev->mc.aper_size;
492
493 if (rdev->mc.real_vram_size > rdev->mc.aper_size)
494 rdev->mc.real_vram_size = rdev->mc.aper_size;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200495}
496
Jerome Glissec93bb852009-07-13 21:04:08 +0200497void rs600_bandwidth_update(struct radeon_device *rdev)
498{
499 /* FIXME: implement, should this be like rs690 ? */
500}
501
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200502uint32_t rs600_mc_rreg(struct radeon_device *rdev, uint32_t reg)
503{
Jerome Glissec010f802009-09-30 22:09:06 +0200504 WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) |
505 S_000070_MC_IND_CITF_ARB0(1));
506 return RREG32(R_000074_MC_IND_DATA);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200507}
508
509void rs600_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
510{
Jerome Glissec010f802009-09-30 22:09:06 +0200511 WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) |
512 S_000070_MC_IND_CITF_ARB0(1) | S_000070_MC_IND_WR_EN(1));
513 WREG32(R_000074_MC_IND_DATA, v);
514}
515
516void rs600_debugfs(struct radeon_device *rdev)
517{
518 if (r100_debugfs_rbbm_init(rdev))
519 DRM_ERROR("Failed to register debugfs file for RBBM !\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200520}
Dave Airlie3f7dc91a2009-08-27 11:10:15 +1000521
Jerome Glisse3bc68532009-10-01 09:39:24 +0200522void rs600_set_safe_registers(struct radeon_device *rdev)
Dave Airlie3f7dc91a2009-08-27 11:10:15 +1000523{
524 rdev->config.r300.reg_safe_bm = rs600_reg_safe_bm;
525 rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(rs600_reg_safe_bm);
Jerome Glisse3bc68532009-10-01 09:39:24 +0200526}
527
Jerome Glissec010f802009-09-30 22:09:06 +0200528static void rs600_mc_program(struct radeon_device *rdev)
529{
530 struct rv515_mc_save save;
531
532 /* Stops all mc clients */
533 rv515_mc_stop(rdev, &save);
534
535 /* Wait for mc idle */
536 if (rs600_mc_wait_for_idle(rdev))
537 dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
538
539 /* FIXME: What does AGP means for such chipset ? */
540 WREG32_MC(R_000005_MC_AGP_LOCATION, 0x0FFFFFFF);
541 WREG32_MC(R_000006_AGP_BASE, 0);
542 WREG32_MC(R_000007_AGP_BASE_2, 0);
543 /* Program MC */
544 WREG32_MC(R_000004_MC_FB_LOCATION,
545 S_000004_MC_FB_START(rdev->mc.vram_start >> 16) |
546 S_000004_MC_FB_TOP(rdev->mc.vram_end >> 16));
547 WREG32(R_000134_HDP_FB_LOCATION,
548 S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
549
550 rv515_mc_resume(rdev, &save);
551}
552
553static int rs600_startup(struct radeon_device *rdev)
554{
555 int r;
556
557 rs600_mc_program(rdev);
558 /* Resume clock */
559 rv515_clock_startup(rdev);
560 /* Initialize GPU configuration (# pipes, ...) */
561 rs600_gpu_init(rdev);
562 /* Initialize GART (initialize after TTM so we can allocate
563 * memory through TTM but finalize after TTM) */
564 r = rs600_gart_enable(rdev);
565 if (r)
566 return r;
567 /* Enable IRQ */
Jerome Glissec010f802009-09-30 22:09:06 +0200568 rs600_irq_set(rdev);
Jerome Glissecafe6602010-01-07 12:39:21 +0100569 rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
Jerome Glissec010f802009-09-30 22:09:06 +0200570 /* 1M ring buffer */
571 r = r100_cp_init(rdev, 1024 * 1024);
572 if (r) {
573 dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
574 return r;
575 }
576 r = r100_wb_init(rdev);
577 if (r)
578 dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
579 r = r100_ib_init(rdev);
580 if (r) {
581 dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
582 return r;
583 }
584 return 0;
585}
586
587int rs600_resume(struct radeon_device *rdev)
588{
589 /* Make sur GART are not working */
590 rs600_gart_disable(rdev);
591 /* Resume clock before doing reset */
592 rv515_clock_startup(rdev);
593 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
594 if (radeon_gpu_reset(rdev)) {
595 dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
596 RREG32(R_000E40_RBBM_STATUS),
597 RREG32(R_0007C0_CP_STAT));
598 }
599 /* post */
600 atom_asic_init(rdev->mode_info.atom_context);
601 /* Resume clock after posting */
602 rv515_clock_startup(rdev);
Dave Airlie550e2d92009-12-09 14:15:38 +1000603 /* Initialize surface registers */
604 radeon_surface_init(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200605 return rs600_startup(rdev);
606}
607
608int rs600_suspend(struct radeon_device *rdev)
609{
610 r100_cp_disable(rdev);
611 r100_wb_disable(rdev);
Jerome Glisseac447df2009-09-30 22:18:43 +0200612 rs600_irq_disable(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200613 rs600_gart_disable(rdev);
614 return 0;
615}
616
617void rs600_fini(struct radeon_device *rdev)
618{
Jerome Glissec010f802009-09-30 22:09:06 +0200619 r100_cp_fini(rdev);
620 r100_wb_fini(rdev);
621 r100_ib_fini(rdev);
622 radeon_gem_fini(rdev);
623 rs600_gart_fini(rdev);
624 radeon_irq_kms_fini(rdev);
625 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +0100626 radeon_bo_fini(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200627 radeon_atombios_fini(rdev);
628 kfree(rdev->bios);
629 rdev->bios = NULL;
630}
631
Jerome Glisse3bc68532009-10-01 09:39:24 +0200632int rs600_init(struct radeon_device *rdev)
633{
Jerome Glissec010f802009-09-30 22:09:06 +0200634 int r;
635
Jerome Glissec010f802009-09-30 22:09:06 +0200636 /* Disable VGA */
637 rv515_vga_render_disable(rdev);
638 /* Initialize scratch registers */
639 radeon_scratch_init(rdev);
640 /* Initialize surface registers */
641 radeon_surface_init(rdev);
642 /* BIOS */
643 if (!radeon_get_bios(rdev)) {
644 if (ASIC_IS_AVIVO(rdev))
645 return -EINVAL;
646 }
647 if (rdev->is_atom_bios) {
648 r = radeon_atombios_init(rdev);
649 if (r)
650 return r;
651 } else {
652 dev_err(rdev->dev, "Expecting atombios for RS600 GPU\n");
653 return -EINVAL;
654 }
655 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
656 if (radeon_gpu_reset(rdev)) {
657 dev_warn(rdev->dev,
658 "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
659 RREG32(R_000E40_RBBM_STATUS),
660 RREG32(R_0007C0_CP_STAT));
661 }
662 /* check if cards are posted or not */
Dave Airlie72542d72009-12-01 14:06:31 +1000663 if (radeon_boot_test_post_card(rdev) == false)
664 return -EINVAL;
665
Jerome Glissec010f802009-09-30 22:09:06 +0200666 /* Initialize clocks */
667 radeon_get_clock_info(rdev->ddev);
Rafał Miłecki74338742009-11-03 00:53:02 +0100668 /* Initialize power management */
669 radeon_pm_init(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200670 /* Get vram informations */
671 rs600_vram_info(rdev);
672 /* Initialize memory controller (also test AGP) */
Dave Airlie64bffd02009-12-07 13:29:51 +1000673 r = rs600_mc_init(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200674 if (r)
675 return r;
676 rs600_debugfs(rdev);
677 /* Fence driver */
678 r = radeon_fence_driver_init(rdev);
679 if (r)
680 return r;
681 r = radeon_irq_kms_init(rdev);
682 if (r)
683 return r;
684 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +0100685 r = radeon_bo_init(rdev);
Jerome Glissec010f802009-09-30 22:09:06 +0200686 if (r)
687 return r;
688 r = rs600_gart_init(rdev);
689 if (r)
690 return r;
691 rs600_set_safe_registers(rdev);
692 rdev->accel_working = true;
693 r = rs600_startup(rdev);
694 if (r) {
695 /* Somethings want wront with the accel init stop accel */
696 dev_err(rdev->dev, "Disabling GPU acceleration\n");
Jerome Glissec010f802009-09-30 22:09:06 +0200697 r100_cp_fini(rdev);
698 r100_wb_fini(rdev);
699 r100_ib_fini(rdev);
700 rs600_gart_fini(rdev);
701 radeon_irq_kms_fini(rdev);
702 rdev->accel_working = false;
703 }
Dave Airlie3f7dc91a2009-08-27 11:10:15 +1000704 return 0;
705}