blob: c2bda4ad62e74092d348076dd67a848d09c7c379 [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 */
28#include <linux/seq_file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020030#include "drmP.h"
31#include "radeon_reg.h"
32#include "radeon.h"
Daniel Vettere6990372010-03-11 21:19:17 +000033#include "radeon_asic.h"
Jerome Glisse9f022dd2009-09-11 15:35:22 +020034#include "atom.h"
Corbin Simpson62cdc0c2010-01-06 19:28:48 +010035#include "r100d.h"
Jerome Glisse905b6822009-09-09 22:24:20 +020036#include "r420d.h"
Alex Deucher804c7552010-01-08 15:58:49 -050037#include "r420_reg_safe.h"
38
39static void r420_set_reg_safe(struct radeon_device *rdev)
40{
41 rdev->config.r300.reg_safe_bm = r420_reg_safe_bm;
42 rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(r420_reg_safe_bm);
43}
Jerome Glisse771fe6b2009-06-05 14:42:42 +020044
Jerome Glisse771fe6b2009-06-05 14:42:42 +020045void r420_pipes_init(struct radeon_device *rdev)
46{
47 unsigned tmp;
48 unsigned gb_pipe_select;
49 unsigned num_pipes;
50
51 /* GA_ENHANCE workaround TCL deadlock issue */
Alex Deucher4612dc92010-02-05 01:58:28 -050052 WREG32(R300_GA_ENHANCE, R300_GA_DEADLOCK_CNTL | R300_GA_FASTSYNC_CNTL |
53 (1 << 2) | (1 << 3));
Dave Airlie18a4cd2e2009-09-21 14:15:10 +100054 /* add idle wait as per freedesktop.org bug 24041 */
55 if (r100_gui_wait_for_idle(rdev)) {
56 printk(KERN_WARNING "Failed to wait GUI idle while "
57 "programming pipes. Bad things might happen.\n");
58 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +020059 /* get max number of pipes */
60 gb_pipe_select = RREG32(0x402C);
61 num_pipes = ((gb_pipe_select >> 12) & 3) + 1;
Tormod Volden94f7bf62010-04-22 16:57:32 -040062
63 /* SE chips have 1 pipe */
64 if ((rdev->pdev->device == 0x5e4c) ||
65 (rdev->pdev->device == 0x5e4f))
66 num_pipes = 1;
67
Jerome Glisse771fe6b2009-06-05 14:42:42 +020068 rdev->num_gb_pipes = num_pipes;
69 tmp = 0;
70 switch (num_pipes) {
71 default:
72 /* force to 1 pipe */
73 num_pipes = 1;
74 case 1:
75 tmp = (0 << 1);
76 break;
77 case 2:
78 tmp = (3 << 1);
79 break;
80 case 3:
81 tmp = (6 << 1);
82 break;
83 case 4:
84 tmp = (7 << 1);
85 break;
86 }
Alex Deucher4612dc92010-02-05 01:58:28 -050087 WREG32(R500_SU_REG_DEST, (1 << num_pipes) - 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020088 /* Sub pixel 1/12 so we can have 4K rendering according to doc */
Alex Deucher4612dc92010-02-05 01:58:28 -050089 tmp |= R300_TILE_SIZE_16 | R300_ENABLE_TILING;
90 WREG32(R300_GB_TILE_CONFIG, tmp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020091 if (r100_gui_wait_for_idle(rdev)) {
92 printk(KERN_WARNING "Failed to wait GUI idle while "
93 "programming pipes. Bad things might happen.\n");
94 }
95
Alex Deucher4612dc92010-02-05 01:58:28 -050096 tmp = RREG32(R300_DST_PIPE_CONFIG);
97 WREG32(R300_DST_PIPE_CONFIG, tmp | R300_PIPE_AUTO_CONFIG);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020098
99 WREG32(R300_RB2D_DSTCACHE_MODE,
100 RREG32(R300_RB2D_DSTCACHE_MODE) |
101 R300_DC_AUTOFLUSH_ENABLE |
102 R300_DC_DC_DISABLE_IGNORE_PE);
103
104 if (r100_gui_wait_for_idle(rdev)) {
105 printk(KERN_WARNING "Failed to wait GUI idle while "
106 "programming pipes. Bad things might happen.\n");
107 }
Alex Deucherf779b3e2009-08-19 19:11:39 -0400108
109 if (rdev->family == CHIP_RV530) {
110 tmp = RREG32(RV530_GB_PIPE_SELECT2);
111 if ((tmp & 3) == 3)
112 rdev->num_z_pipes = 2;
113 else
114 rdev->num_z_pipes = 1;
115 } else
116 rdev->num_z_pipes = 1;
117
118 DRM_INFO("radeon: %d quad pipes, %d z pipes initialized.\n",
119 rdev->num_gb_pipes, rdev->num_z_pipes);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200120}
121
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200122u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200123{
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200124 u32 r;
125
126 WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg));
127 r = RREG32(R_0001FC_MC_IND_DATA);
128 return r;
129}
130
131void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
132{
133 WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg) |
134 S_0001F8_MC_IND_WR_EN(1));
135 WREG32(R_0001FC_MC_IND_DATA, v);
136}
137
138static void r420_debugfs(struct radeon_device *rdev)
139{
140 if (r100_debugfs_rbbm_init(rdev)) {
141 DRM_ERROR("Failed to register debugfs file for RBBM !\n");
142 }
143 if (r420_debugfs_pipes_info_init(rdev)) {
144 DRM_ERROR("Failed to register debugfs file for pipes !\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200145 }
146}
147
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200148static void r420_clock_resume(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200149{
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200150 u32 sclk_cntl;
Jerome Glisseca6ffc62009-10-01 10:20:52 +0200151
152 if (radeon_dynclks != -1 && radeon_dynclks)
153 radeon_atom_set_clock_gating(rdev, 1);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200154 sclk_cntl = RREG32_PLL(R_00000D_SCLK_CNTL);
155 sclk_cntl |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
156 if (rdev->family == CHIP_R420)
157 sclk_cntl |= S_00000D_FORCE_PX(1) | S_00000D_FORCE_TX(1);
158 WREG32_PLL(R_00000D_SCLK_CNTL, sclk_cntl);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200159}
160
Corbin Simpson62cdc0c2010-01-06 19:28:48 +0100161static void r420_cp_errata_init(struct radeon_device *rdev)
162{
163 /* RV410 and R420 can lock up if CP DMA to host memory happens
164 * while the 2D engine is busy.
165 *
166 * The proper workaround is to queue a RESYNC at the beginning
167 * of the CP init, apparently.
168 */
169 radeon_scratch_get(rdev, &rdev->config.r300.resync_scratch);
170 radeon_ring_lock(rdev, 8);
171 radeon_ring_write(rdev, PACKET0(R300_CP_RESYNC_ADDR, 1));
172 radeon_ring_write(rdev, rdev->config.r300.resync_scratch);
173 radeon_ring_write(rdev, 0xDEADBEEF);
174 radeon_ring_unlock_commit(rdev);
175}
176
177static void r420_cp_errata_fini(struct radeon_device *rdev)
178{
179 /* Catch the RESYNC we dispatched all the way back,
180 * at the very beginning of the CP init.
181 */
182 radeon_ring_lock(rdev, 8);
183 radeon_ring_write(rdev, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
184 radeon_ring_write(rdev, R300_RB3D_DC_FINISH);
185 radeon_ring_unlock_commit(rdev);
186 radeon_scratch_free(rdev, rdev->config.r300.resync_scratch);
187}
188
Dave Airliefc30b8e2009-09-18 15:19:37 +1000189static int r420_startup(struct radeon_device *rdev)
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200190{
191 int r;
192
Alex Deucher92cde002009-12-04 10:55:12 -0500193 /* set common regs */
194 r100_set_common_regs(rdev);
195 /* program mc */
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200196 r300_mc_program(rdev);
Jerome Glisseca6ffc62009-10-01 10:20:52 +0200197 /* Resume clock */
198 r420_clock_resume(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200199 /* Initialize GART (initialize after TTM so we can allocate
200 * memory through TTM but finalize after TTM) */
Jerome Glisse4aac0472009-09-14 18:29:49 +0200201 if (rdev->flags & RADEON_IS_PCIE) {
202 r = rv370_pcie_gart_enable(rdev);
203 if (r)
204 return r;
205 }
206 if (rdev->flags & RADEON_IS_PCI) {
207 r = r100_pci_gart_enable(rdev);
208 if (r)
209 return r;
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200210 }
211 r420_pipes_init(rdev);
212 /* Enable IRQ */
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200213 r100_irq_set(rdev);
Jerome Glissecafe6602010-01-07 12:39:21 +0100214 rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200215 /* 1M ring buffer */
216 r = r100_cp_init(rdev, 1024 * 1024);
217 if (r) {
218 dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
219 return r;
220 }
Corbin Simpson62cdc0c2010-01-06 19:28:48 +0100221 r420_cp_errata_init(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200222 r = r100_wb_init(rdev);
223 if (r) {
224 dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
225 }
226 r = r100_ib_init(rdev);
227 if (r) {
228 dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
229 return r;
230 }
231 return 0;
232}
233
Dave Airliefc30b8e2009-09-18 15:19:37 +1000234int r420_resume(struct radeon_device *rdev)
235{
236 /* Make sur GART are not working */
237 if (rdev->flags & RADEON_IS_PCIE)
238 rv370_pcie_gart_disable(rdev);
239 if (rdev->flags & RADEON_IS_PCI)
240 r100_pci_gart_disable(rdev);
241 /* Resume clock before doing reset */
242 r420_clock_resume(rdev);
243 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
244 if (radeon_gpu_reset(rdev)) {
245 dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
246 RREG32(R_000E40_RBBM_STATUS),
247 RREG32(R_0007C0_CP_STAT));
248 }
249 /* check if cards are posted or not */
250 if (rdev->is_atom_bios) {
251 atom_asic_init(rdev->mode_info.atom_context);
252 } else {
253 radeon_combios_asic_init(rdev->ddev);
254 }
255 /* Resume clock after posting */
256 r420_clock_resume(rdev);
Dave Airlie550e2d92009-12-09 14:15:38 +1000257 /* Initialize surface registers */
258 radeon_surface_init(rdev);
Dave Airliefc30b8e2009-09-18 15:19:37 +1000259 return r420_startup(rdev);
260}
261
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200262int r420_suspend(struct radeon_device *rdev)
263{
Corbin Simpson62cdc0c2010-01-06 19:28:48 +0100264 r420_cp_errata_fini(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200265 r100_cp_disable(rdev);
266 r100_wb_disable(rdev);
267 r100_irq_disable(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200268 if (rdev->flags & RADEON_IS_PCIE)
269 rv370_pcie_gart_disable(rdev);
270 if (rdev->flags & RADEON_IS_PCI)
271 r100_pci_gart_disable(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200272 return 0;
273}
274
275void r420_fini(struct radeon_device *rdev)
276{
Alex Deucher29fb52c2010-03-11 10:01:17 -0500277 radeon_pm_fini(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200278 r100_cp_fini(rdev);
279 r100_wb_fini(rdev);
280 r100_ib_fini(rdev);
281 radeon_gem_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200282 if (rdev->flags & RADEON_IS_PCIE)
283 rv370_pcie_gart_fini(rdev);
284 if (rdev->flags & RADEON_IS_PCI)
285 r100_pci_gart_fini(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200286 radeon_agp_fini(rdev);
287 radeon_irq_kms_fini(rdev);
288 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +0100289 radeon_bo_fini(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200290 if (rdev->is_atom_bios) {
291 radeon_atombios_fini(rdev);
292 } else {
293 radeon_combios_fini(rdev);
294 }
295 kfree(rdev->bios);
296 rdev->bios = NULL;
297}
298
299int r420_init(struct radeon_device *rdev)
300{
301 int r;
302
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200303 /* Initialize scratch registers */
304 radeon_scratch_init(rdev);
305 /* Initialize surface registers */
306 radeon_surface_init(rdev);
307 /* TODO: disable VGA need to use VGA request */
308 /* BIOS*/
309 if (!radeon_get_bios(rdev)) {
310 if (ASIC_IS_AVIVO(rdev))
311 return -EINVAL;
312 }
313 if (rdev->is_atom_bios) {
314 r = radeon_atombios_init(rdev);
315 if (r) {
316 return r;
317 }
318 } else {
319 r = radeon_combios_init(rdev);
320 if (r) {
321 return r;
322 }
323 }
324 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
325 if (radeon_gpu_reset(rdev)) {
326 dev_warn(rdev->dev,
327 "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
328 RREG32(R_000E40_RBBM_STATUS),
329 RREG32(R_0007C0_CP_STAT));
330 }
331 /* check if cards are posted or not */
Dave Airlie72542d72009-12-01 14:06:31 +1000332 if (radeon_boot_test_post_card(rdev) == false)
333 return -EINVAL;
334
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200335 /* Initialize clocks */
336 radeon_get_clock_info(rdev->ddev);
Rafał Miłecki74338742009-11-03 00:53:02 +0100337 /* Initialize power management */
338 radeon_pm_init(rdev);
Jerome Glissed594e462010-02-17 21:54:29 +0000339 /* initialize AGP */
340 if (rdev->flags & RADEON_IS_AGP) {
341 r = radeon_agp_init(rdev);
342 if (r) {
343 radeon_agp_disable(rdev);
344 }
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200345 }
Jerome Glissed594e462010-02-17 21:54:29 +0000346 /* initialize memory controller */
347 r300_mc_init(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200348 r420_debugfs(rdev);
349 /* Fence driver */
350 r = radeon_fence_driver_init(rdev);
351 if (r) {
352 return r;
353 }
354 r = radeon_irq_kms_init(rdev);
355 if (r) {
356 return r;
357 }
358 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +0100359 r = radeon_bo_init(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200360 if (r) {
361 return r;
362 }
Dave Airlie17e15b02009-11-05 15:36:53 +1000363 if (rdev->family == CHIP_R420)
364 r100_enable_bm(rdev);
365
Jerome Glisse4aac0472009-09-14 18:29:49 +0200366 if (rdev->flags & RADEON_IS_PCIE) {
367 r = rv370_pcie_gart_init(rdev);
368 if (r)
369 return r;
370 }
371 if (rdev->flags & RADEON_IS_PCI) {
372 r = r100_pci_gart_init(rdev);
373 if (r)
374 return r;
375 }
Alex Deucher804c7552010-01-08 15:58:49 -0500376 r420_set_reg_safe(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +0200377 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +1000378 r = r420_startup(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200379 if (r) {
380 /* Somethings want wront with the accel init stop accel */
381 dev_err(rdev->dev, "Disabling GPU acceleration\n");
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200382 r100_cp_fini(rdev);
383 r100_wb_fini(rdev);
384 r100_ib_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +0100385 radeon_irq_kms_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200386 if (rdev->flags & RADEON_IS_PCIE)
387 rv370_pcie_gart_fini(rdev);
388 if (rdev->flags & RADEON_IS_PCI)
389 r100_pci_gart_fini(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200390 radeon_agp_fini(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +0200391 rdev->accel_working = false;
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200392 }
393 return 0;
394}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200395
396/*
397 * Debugfs info
398 */
399#if defined(CONFIG_DEBUG_FS)
400static int r420_debugfs_pipes_info(struct seq_file *m, void *data)
401{
402 struct drm_info_node *node = (struct drm_info_node *) m->private;
403 struct drm_device *dev = node->minor->dev;
404 struct radeon_device *rdev = dev->dev_private;
405 uint32_t tmp;
406
407 tmp = RREG32(R400_GB_PIPE_SELECT);
408 seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp);
409 tmp = RREG32(R300_GB_TILE_CONFIG);
410 seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp);
411 tmp = RREG32(R300_DST_PIPE_CONFIG);
412 seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp);
413 return 0;
414}
415
416static struct drm_info_list r420_pipes_info_list[] = {
417 {"r420_pipes_info", r420_debugfs_pipes_info, 0, NULL},
418};
419#endif
420
421int r420_debugfs_pipes_info_init(struct radeon_device *rdev)
422{
423#if defined(CONFIG_DEBUG_FS)
424 return radeon_debugfs_add_files(rdev, r420_pipes_info_list, 1);
425#else
426 return 0;
427#endif
428}