blob: f46502a253ec332302ab86dd9a7ec729223ca88f [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>
29#include "drmP.h"
30#include "radeon_reg.h"
31#include "radeon.h"
Jerome Glisse9f022dd2009-09-11 15:35:22 +020032#include "atom.h"
Corbin Simpson62cdc0c2010-01-06 19:28:48 +010033#include "r100d.h"
Jerome Glisse905b6822009-09-09 22:24:20 +020034#include "r420d.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020035
Jerome Glisse771fe6b2009-06-05 14:42:42 +020036int r420_mc_init(struct radeon_device *rdev)
37{
38 int r;
39
Jerome Glisse771fe6b2009-06-05 14:42:42 +020040 /* Setup GPU memory space */
41 rdev->mc.vram_location = 0xFFFFFFFFUL;
42 rdev->mc.gtt_location = 0xFFFFFFFFUL;
43 if (rdev->flags & RADEON_IS_AGP) {
44 r = radeon_agp_init(rdev);
45 if (r) {
46 printk(KERN_WARNING "[drm] Disabling AGP\n");
47 rdev->flags &= ~RADEON_IS_AGP;
48 rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024;
49 } else {
50 rdev->mc.gtt_location = rdev->mc.agp_base;
51 }
52 }
53 r = radeon_mc_setup(rdev);
54 if (r) {
55 return r;
56 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +020057 return 0;
58}
59
Jerome Glisse771fe6b2009-06-05 14:42:42 +020060void r420_pipes_init(struct radeon_device *rdev)
61{
62 unsigned tmp;
63 unsigned gb_pipe_select;
64 unsigned num_pipes;
65
66 /* GA_ENHANCE workaround TCL deadlock issue */
67 WREG32(0x4274, (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
Dave Airlie18a4cd2e2009-09-21 14:15:10 +100068 /* add idle wait as per freedesktop.org bug 24041 */
69 if (r100_gui_wait_for_idle(rdev)) {
70 printk(KERN_WARNING "Failed to wait GUI idle while "
71 "programming pipes. Bad things might happen.\n");
72 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +020073 /* get max number of pipes */
74 gb_pipe_select = RREG32(0x402C);
75 num_pipes = ((gb_pipe_select >> 12) & 3) + 1;
76 rdev->num_gb_pipes = num_pipes;
77 tmp = 0;
78 switch (num_pipes) {
79 default:
80 /* force to 1 pipe */
81 num_pipes = 1;
82 case 1:
83 tmp = (0 << 1);
84 break;
85 case 2:
86 tmp = (3 << 1);
87 break;
88 case 3:
89 tmp = (6 << 1);
90 break;
91 case 4:
92 tmp = (7 << 1);
93 break;
94 }
95 WREG32(0x42C8, (1 << num_pipes) - 1);
96 /* Sub pixel 1/12 so we can have 4K rendering according to doc */
97 tmp |= (1 << 4) | (1 << 0);
98 WREG32(0x4018, tmp);
99 if (r100_gui_wait_for_idle(rdev)) {
100 printk(KERN_WARNING "Failed to wait GUI idle while "
101 "programming pipes. Bad things might happen.\n");
102 }
103
104 tmp = RREG32(0x170C);
105 WREG32(0x170C, tmp | (1 << 31));
106
107 WREG32(R300_RB2D_DSTCACHE_MODE,
108 RREG32(R300_RB2D_DSTCACHE_MODE) |
109 R300_DC_AUTOFLUSH_ENABLE |
110 R300_DC_DC_DISABLE_IGNORE_PE);
111
112 if (r100_gui_wait_for_idle(rdev)) {
113 printk(KERN_WARNING "Failed to wait GUI idle while "
114 "programming pipes. Bad things might happen.\n");
115 }
Alex Deucherf779b3e2009-08-19 19:11:39 -0400116
117 if (rdev->family == CHIP_RV530) {
118 tmp = RREG32(RV530_GB_PIPE_SELECT2);
119 if ((tmp & 3) == 3)
120 rdev->num_z_pipes = 2;
121 else
122 rdev->num_z_pipes = 1;
123 } else
124 rdev->num_z_pipes = 1;
125
126 DRM_INFO("radeon: %d quad pipes, %d z pipes initialized.\n",
127 rdev->num_gb_pipes, rdev->num_z_pipes);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200128}
129
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200130u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200131{
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200132 u32 r;
133
134 WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg));
135 r = RREG32(R_0001FC_MC_IND_DATA);
136 return r;
137}
138
139void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
140{
141 WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg) |
142 S_0001F8_MC_IND_WR_EN(1));
143 WREG32(R_0001FC_MC_IND_DATA, v);
144}
145
146static void r420_debugfs(struct radeon_device *rdev)
147{
148 if (r100_debugfs_rbbm_init(rdev)) {
149 DRM_ERROR("Failed to register debugfs file for RBBM !\n");
150 }
151 if (r420_debugfs_pipes_info_init(rdev)) {
152 DRM_ERROR("Failed to register debugfs file for pipes !\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200153 }
154}
155
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200156static void r420_clock_resume(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200157{
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200158 u32 sclk_cntl;
Jerome Glisseca6ffc62009-10-01 10:20:52 +0200159
160 if (radeon_dynclks != -1 && radeon_dynclks)
161 radeon_atom_set_clock_gating(rdev, 1);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200162 sclk_cntl = RREG32_PLL(R_00000D_SCLK_CNTL);
163 sclk_cntl |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
164 if (rdev->family == CHIP_R420)
165 sclk_cntl |= S_00000D_FORCE_PX(1) | S_00000D_FORCE_TX(1);
166 WREG32_PLL(R_00000D_SCLK_CNTL, sclk_cntl);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200167}
168
Corbin Simpson62cdc0c2010-01-06 19:28:48 +0100169static void r420_cp_errata_init(struct radeon_device *rdev)
170{
171 /* RV410 and R420 can lock up if CP DMA to host memory happens
172 * while the 2D engine is busy.
173 *
174 * The proper workaround is to queue a RESYNC at the beginning
175 * of the CP init, apparently.
176 */
177 radeon_scratch_get(rdev, &rdev->config.r300.resync_scratch);
178 radeon_ring_lock(rdev, 8);
179 radeon_ring_write(rdev, PACKET0(R300_CP_RESYNC_ADDR, 1));
180 radeon_ring_write(rdev, rdev->config.r300.resync_scratch);
181 radeon_ring_write(rdev, 0xDEADBEEF);
182 radeon_ring_unlock_commit(rdev);
183}
184
185static void r420_cp_errata_fini(struct radeon_device *rdev)
186{
187 /* Catch the RESYNC we dispatched all the way back,
188 * at the very beginning of the CP init.
189 */
190 radeon_ring_lock(rdev, 8);
191 radeon_ring_write(rdev, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
192 radeon_ring_write(rdev, R300_RB3D_DC_FINISH);
193 radeon_ring_unlock_commit(rdev);
194 radeon_scratch_free(rdev, rdev->config.r300.resync_scratch);
195}
196
Dave Airliefc30b8e2009-09-18 15:19:37 +1000197static int r420_startup(struct radeon_device *rdev)
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200198{
199 int r;
200
Alex Deucher92cde002009-12-04 10:55:12 -0500201 /* set common regs */
202 r100_set_common_regs(rdev);
203 /* program mc */
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200204 r300_mc_program(rdev);
Jerome Glisseca6ffc62009-10-01 10:20:52 +0200205 /* Resume clock */
206 r420_clock_resume(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200207 /* Initialize GART (initialize after TTM so we can allocate
208 * memory through TTM but finalize after TTM) */
Jerome Glisse4aac0472009-09-14 18:29:49 +0200209 if (rdev->flags & RADEON_IS_PCIE) {
210 r = rv370_pcie_gart_enable(rdev);
211 if (r)
212 return r;
213 }
214 if (rdev->flags & RADEON_IS_PCI) {
215 r = r100_pci_gart_enable(rdev);
216 if (r)
217 return r;
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200218 }
219 r420_pipes_init(rdev);
220 /* Enable IRQ */
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200221 r100_irq_set(rdev);
222 /* 1M ring buffer */
223 r = r100_cp_init(rdev, 1024 * 1024);
224 if (r) {
225 dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
226 return r;
227 }
Corbin Simpson62cdc0c2010-01-06 19:28:48 +0100228 r420_cp_errata_init(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200229 r = r100_wb_init(rdev);
230 if (r) {
231 dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
232 }
233 r = r100_ib_init(rdev);
234 if (r) {
235 dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
236 return r;
237 }
238 return 0;
239}
240
Dave Airliefc30b8e2009-09-18 15:19:37 +1000241int r420_resume(struct radeon_device *rdev)
242{
243 /* Make sur GART are not working */
244 if (rdev->flags & RADEON_IS_PCIE)
245 rv370_pcie_gart_disable(rdev);
246 if (rdev->flags & RADEON_IS_PCI)
247 r100_pci_gart_disable(rdev);
248 /* Resume clock before doing reset */
249 r420_clock_resume(rdev);
250 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
251 if (radeon_gpu_reset(rdev)) {
252 dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
253 RREG32(R_000E40_RBBM_STATUS),
254 RREG32(R_0007C0_CP_STAT));
255 }
256 /* check if cards are posted or not */
257 if (rdev->is_atom_bios) {
258 atom_asic_init(rdev->mode_info.atom_context);
259 } else {
260 radeon_combios_asic_init(rdev->ddev);
261 }
262 /* Resume clock after posting */
263 r420_clock_resume(rdev);
Dave Airlie550e2d92009-12-09 14:15:38 +1000264 /* Initialize surface registers */
265 radeon_surface_init(rdev);
Dave Airliefc30b8e2009-09-18 15:19:37 +1000266 return r420_startup(rdev);
267}
268
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200269int r420_suspend(struct radeon_device *rdev)
270{
Corbin Simpson62cdc0c2010-01-06 19:28:48 +0100271 r420_cp_errata_fini(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200272 r100_cp_disable(rdev);
273 r100_wb_disable(rdev);
274 r100_irq_disable(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200275 if (rdev->flags & RADEON_IS_PCIE)
276 rv370_pcie_gart_disable(rdev);
277 if (rdev->flags & RADEON_IS_PCI)
278 r100_pci_gart_disable(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200279 return 0;
280}
281
282void r420_fini(struct radeon_device *rdev)
283{
284 r100_cp_fini(rdev);
285 r100_wb_fini(rdev);
286 r100_ib_fini(rdev);
287 radeon_gem_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200288 if (rdev->flags & RADEON_IS_PCIE)
289 rv370_pcie_gart_fini(rdev);
290 if (rdev->flags & RADEON_IS_PCI)
291 r100_pci_gart_fini(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200292 radeon_agp_fini(rdev);
293 radeon_irq_kms_fini(rdev);
294 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +0100295 radeon_bo_fini(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200296 if (rdev->is_atom_bios) {
297 radeon_atombios_fini(rdev);
298 } else {
299 radeon_combios_fini(rdev);
300 }
301 kfree(rdev->bios);
302 rdev->bios = NULL;
303}
304
305int r420_init(struct radeon_device *rdev)
306{
307 int r;
308
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200309 /* Initialize scratch registers */
310 radeon_scratch_init(rdev);
311 /* Initialize surface registers */
312 radeon_surface_init(rdev);
313 /* TODO: disable VGA need to use VGA request */
314 /* BIOS*/
315 if (!radeon_get_bios(rdev)) {
316 if (ASIC_IS_AVIVO(rdev))
317 return -EINVAL;
318 }
319 if (rdev->is_atom_bios) {
320 r = radeon_atombios_init(rdev);
321 if (r) {
322 return r;
323 }
324 } else {
325 r = radeon_combios_init(rdev);
326 if (r) {
327 return r;
328 }
329 }
330 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
331 if (radeon_gpu_reset(rdev)) {
332 dev_warn(rdev->dev,
333 "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
334 RREG32(R_000E40_RBBM_STATUS),
335 RREG32(R_0007C0_CP_STAT));
336 }
337 /* check if cards are posted or not */
Dave Airlie72542d72009-12-01 14:06:31 +1000338 if (radeon_boot_test_post_card(rdev) == false)
339 return -EINVAL;
340
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200341 /* Initialize clocks */
342 radeon_get_clock_info(rdev->ddev);
Rafał Miłecki74338742009-11-03 00:53:02 +0100343 /* Initialize power management */
344 radeon_pm_init(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200345 /* Get vram informations */
346 r300_vram_info(rdev);
347 /* Initialize memory controller (also test AGP) */
348 r = r420_mc_init(rdev);
349 if (r) {
350 return r;
351 }
352 r420_debugfs(rdev);
353 /* Fence driver */
354 r = radeon_fence_driver_init(rdev);
355 if (r) {
356 return r;
357 }
358 r = radeon_irq_kms_init(rdev);
359 if (r) {
360 return r;
361 }
362 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +0100363 r = radeon_bo_init(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200364 if (r) {
365 return r;
366 }
Dave Airlie17e15b02009-11-05 15:36:53 +1000367 if (rdev->family == CHIP_R420)
368 r100_enable_bm(rdev);
369
Jerome Glisse4aac0472009-09-14 18:29:49 +0200370 if (rdev->flags & RADEON_IS_PCIE) {
371 r = rv370_pcie_gart_init(rdev);
372 if (r)
373 return r;
374 }
375 if (rdev->flags & RADEON_IS_PCI) {
376 r = r100_pci_gart_init(rdev);
377 if (r)
378 return r;
379 }
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200380 r300_set_reg_safe(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +0200381 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +1000382 r = r420_startup(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200383 if (r) {
384 /* Somethings want wront with the accel init stop accel */
385 dev_err(rdev->dev, "Disabling GPU acceleration\n");
386 r420_suspend(rdev);
387 r100_cp_fini(rdev);
388 r100_wb_fini(rdev);
389 r100_ib_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200390 if (rdev->flags & RADEON_IS_PCIE)
391 rv370_pcie_gart_fini(rdev);
392 if (rdev->flags & RADEON_IS_PCI)
393 r100_pci_gart_fini(rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200394 radeon_agp_fini(rdev);
395 radeon_irq_kms_fini(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +0200396 rdev->accel_working = false;
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200397 }
398 return 0;
399}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200400
401/*
402 * Debugfs info
403 */
404#if defined(CONFIG_DEBUG_FS)
405static int r420_debugfs_pipes_info(struct seq_file *m, void *data)
406{
407 struct drm_info_node *node = (struct drm_info_node *) m->private;
408 struct drm_device *dev = node->minor->dev;
409 struct radeon_device *rdev = dev->dev_private;
410 uint32_t tmp;
411
412 tmp = RREG32(R400_GB_PIPE_SELECT);
413 seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp);
414 tmp = RREG32(R300_GB_TILE_CONFIG);
415 seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp);
416 tmp = RREG32(R300_DST_PIPE_CONFIG);
417 seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp);
418 return 0;
419}
420
421static struct drm_info_list r420_pipes_info_list[] = {
422 {"r420_pipes_info", r420_debugfs_pipes_info, 0, NULL},
423};
424#endif
425
426int r420_debugfs_pipes_info_init(struct radeon_device *rdev)
427{
428#if defined(CONFIG_DEBUG_FS)
429 return radeon_debugfs_add_files(rdev, r420_pipes_info_list, 1);
430#else
431 return 0;
432#endif
433}