blob: a09049d1590180b56c50f4e2cb6ee9600b79a8c1 [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 Glisse3ce0a232009-09-08 10:10:24 +100028#include <linux/firmware.h>
29#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020031#include "drmP.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020032#include "radeon.h"
Daniel Vettere6990372010-03-11 21:19:17 +000033#include "radeon_asic.h"
Dave Airlie4153e582009-09-18 18:41:24 +100034#include "radeon_drm.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100035#include "rv770d.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100036#include "atom.h"
Jerome Glissed39c3b82009-09-28 18:34:43 +020037#include "avivod.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020038
Jerome Glisse3ce0a232009-09-08 10:10:24 +100039#define R700_PFP_UCODE_SIZE 848
40#define R700_PM4_UCODE_SIZE 1360
Jerome Glisse771fe6b2009-06-05 14:42:42 +020041
Jerome Glisse3ce0a232009-09-08 10:10:24 +100042static void rv770_gpu_init(struct radeon_device *rdev);
43void rv770_fini(struct radeon_device *rdev);
Alex Deucher9e46a482011-01-06 18:49:35 -050044static void rv770_pcie_gen2_enable(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100045
Alex Deucher6f34be52010-11-21 10:59:01 -050046u32 rv770_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
47{
48 struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
49 u32 tmp = RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset);
50
51 /* Lock the graphics update lock */
52 tmp |= AVIVO_D1GRPH_UPDATE_LOCK;
53 WREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
54
55 /* update the scanout addresses */
56 if (radeon_crtc->crtc_id) {
57 WREG32(D2GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
58 WREG32(D2GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
59 } else {
60 WREG32(D1GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
61 WREG32(D1GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
62 }
63 WREG32(D1GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
64 (u32)crtc_base);
65 WREG32(D1GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
66 (u32)crtc_base);
67
68 /* Wait for update_pending to go high. */
69 while (!(RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING));
70 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
71
72 /* Unlock the lock, so double-buffering can take place inside vblank */
73 tmp &= ~AVIVO_D1GRPH_UPDATE_LOCK;
74 WREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
75
76 /* Return current update_pending status: */
77 return RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING;
78}
79
Alex Deucher21a81222010-07-02 12:58:16 -040080/* get temperature in millidegrees */
Alex Deucher20d391d2011-02-01 16:12:34 -050081int rv770_get_temp(struct radeon_device *rdev)
Alex Deucher21a81222010-07-02 12:58:16 -040082{
83 u32 temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >>
84 ASIC_T_SHIFT;
Alex Deucher20d391d2011-02-01 16:12:34 -050085 int actual_temp;
Alex Deucher21a81222010-07-02 12:58:16 -040086
Alex Deucher20d391d2011-02-01 16:12:34 -050087 if (temp & 0x400)
88 actual_temp = -256;
89 else if (temp & 0x200)
90 actual_temp = 255;
91 else if (temp & 0x100) {
92 actual_temp = temp & 0x1ff;
93 actual_temp |= ~0x1ff;
94 } else
95 actual_temp = temp & 0xff;
Alex Deucher21a81222010-07-02 12:58:16 -040096
Alex Deucher20d391d2011-02-01 16:12:34 -050097 return (actual_temp * 1000) / 2;
Alex Deucher21a81222010-07-02 12:58:16 -040098}
99
Alex Deucher49e02b72010-04-23 17:57:27 -0400100void rv770_pm_misc(struct radeon_device *rdev)
101{
Rafał Miłeckia081a9d2010-06-07 18:20:25 -0400102 int req_ps_idx = rdev->pm.requested_power_state_index;
103 int req_cm_idx = rdev->pm.requested_clock_mode_index;
104 struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
105 struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
Alex Deucher4d601732010-06-07 18:15:18 -0400106
107 if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
Alex Deuchera377e182011-06-20 13:00:31 -0400108 /* 0xff01 is a flag rather then an actual voltage */
109 if (voltage->voltage == 0xff01)
110 return;
Alex Deucher4d601732010-06-07 18:15:18 -0400111 if (voltage->voltage != rdev->pm.current_vddc) {
Alex Deucher8a83ec52011-04-12 14:49:23 -0400112 radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
Alex Deucher4d601732010-06-07 18:15:18 -0400113 rdev->pm.current_vddc = voltage->voltage;
Rafał Miłecki0fcbe942010-06-07 18:25:21 -0400114 DRM_DEBUG("Setting: v: %d\n", voltage->voltage);
Alex Deucher4d601732010-06-07 18:15:18 -0400115 }
116 }
Alex Deucher49e02b72010-04-23 17:57:27 -0400117}
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000118
119/*
120 * GART
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200121 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000122int rv770_pcie_gart_enable(struct radeon_device *rdev)
123{
124 u32 tmp;
125 int r, i;
126
Jerome Glisse4aac0472009-09-14 18:29:49 +0200127 if (rdev->gart.table.vram.robj == NULL) {
128 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
129 return -EINVAL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000130 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200131 r = radeon_gart_table_vram_pin(rdev);
132 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000133 return r;
Dave Airlie82568562010-02-05 16:00:07 +1000134 radeon_gart_restore(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000135 /* Setup L2 cache */
136 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
137 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
138 EFFECTIVE_L2_QUEUE_SIZE(7));
139 WREG32(VM_L2_CNTL2, 0);
140 WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
141 /* Setup TLB control */
142 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
143 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
144 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
145 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
146 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
147 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
148 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
149 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
150 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
151 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
152 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
153 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200154 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000155 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
156 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
157 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
158 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
159 (u32)(rdev->dummy_page.addr >> 12));
160 for (i = 1; i < 7; i++)
161 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
162
163 r600_pcie_gart_tlb_flush(rdev);
Tormod Voldenfcf4de52011-08-31 21:54:07 +0000164 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
165 (unsigned)(rdev->mc.gtt_size >> 20),
166 (unsigned long long)rdev->gart.table_addr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000167 rdev->gart.ready = true;
168 return 0;
169}
170
171void rv770_pcie_gart_disable(struct radeon_device *rdev)
172{
173 u32 tmp;
Jerome Glisse4c788672009-11-20 14:29:23 +0100174 int i, r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000175
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000176 /* Disable all tables */
177 for (i = 0; i < 7; i++)
178 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
179
180 /* Setup L2 cache */
181 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
182 EFFECTIVE_L2_QUEUE_SIZE(7));
183 WREG32(VM_L2_CNTL2, 0);
184 WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
185 /* Setup TLB control */
186 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
187 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
188 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
189 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
190 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
191 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
192 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
193 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200194 if (rdev->gart.table.vram.robj) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100195 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
196 if (likely(r == 0)) {
197 radeon_bo_kunmap(rdev->gart.table.vram.robj);
198 radeon_bo_unpin(rdev->gart.table.vram.robj);
199 radeon_bo_unreserve(rdev->gart.table.vram.robj);
200 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200201 }
202}
203
204void rv770_pcie_gart_fini(struct radeon_device *rdev)
205{
Jerome Glissef9274562010-03-17 14:44:29 +0000206 radeon_gart_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200207 rv770_pcie_gart_disable(rdev);
208 radeon_gart_table_vram_free(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000209}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200210
211
Jerome Glisse1a029b72009-10-06 19:04:30 +0200212void rv770_agp_enable(struct radeon_device *rdev)
213{
214 u32 tmp;
215 int i;
216
217 /* Setup L2 cache */
218 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
219 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
220 EFFECTIVE_L2_QUEUE_SIZE(7));
221 WREG32(VM_L2_CNTL2, 0);
222 WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
223 /* Setup TLB control */
224 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
225 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
226 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
227 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
228 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
229 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
230 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
231 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
232 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
233 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
234 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
235 for (i = 0; i < 7; i++)
236 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
237}
238
Jerome Glissea3c19452009-10-01 18:02:13 +0200239static void rv770_mc_program(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200240{
Jerome Glissea3c19452009-10-01 18:02:13 +0200241 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000242 u32 tmp;
243 int i, j;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200244
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000245 /* Initialize HDP */
246 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
247 WREG32((0x2c14 + j), 0x00000000);
248 WREG32((0x2c18 + j), 0x00000000);
249 WREG32((0x2c1c + j), 0x00000000);
250 WREG32((0x2c20 + j), 0x00000000);
251 WREG32((0x2c24 + j), 0x00000000);
252 }
Alex Deucher812d0462010-07-26 18:51:53 -0400253 /* r7xx hw bug. Read from HDP_DEBUG1 rather
254 * than writing to HDP_REG_COHERENCY_FLUSH_CNTL
255 */
256 tmp = RREG32(HDP_DEBUG1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200257
Jerome Glissea3c19452009-10-01 18:02:13 +0200258 rv515_mc_stop(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000259 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +0200260 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200261 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000262 /* Lockout access through VGA aperture*/
263 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000264 /* Update configuration */
Jerome Glisse1a029b72009-10-06 19:04:30 +0200265 if (rdev->flags & RADEON_IS_AGP) {
266 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
267 /* VRAM before AGP */
268 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
269 rdev->mc.vram_start >> 12);
270 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
271 rdev->mc.gtt_end >> 12);
272 } else {
273 /* VRAM after AGP */
274 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
275 rdev->mc.gtt_start >> 12);
276 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
277 rdev->mc.vram_end >> 12);
278 }
279 } else {
280 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
281 rdev->mc.vram_start >> 12);
282 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
283 rdev->mc.vram_end >> 12);
284 }
Alex Deucher16cdf042011-10-28 10:30:02 -0400285 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200286 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000287 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
288 WREG32(MC_VM_FB_LOCATION, tmp);
289 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
290 WREG32(HDP_NONSURFACE_INFO, (2 << 7));
Jerome Glisse46fcd2b2010-06-03 19:34:48 +0200291 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000292 if (rdev->flags & RADEON_IS_AGP) {
Jerome Glisse1a029b72009-10-06 19:04:30 +0200293 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000294 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16);
295 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
296 } else {
297 WREG32(MC_VM_AGP_BASE, 0);
298 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
299 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
300 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000301 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +0200302 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000303 }
Jerome Glissea3c19452009-10-01 18:02:13 +0200304 rv515_mc_resume(rdev, &save);
Dave Airlie698443d2009-09-18 14:16:38 +1000305 /* we need to own VRAM, so turn off the VGA renderer here
306 * to stop it overwriting our objects */
Jerome Glissed39c3b82009-09-28 18:34:43 +0200307 rv515_vga_render_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200308}
309
310
311/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000312 * CP.
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200313 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000314void r700_cp_stop(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200315{
Dave Airlie53595332011-03-14 09:47:24 +1000316 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000317 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT));
Alex Deucher724c80e2010-08-27 18:25:25 -0400318 WREG32(SCRATCH_UMSK, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200319}
320
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000321static int rv770_cp_load_microcode(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200322{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000323 const __be32 *fw_data;
324 int i;
325
326 if (!rdev->me_fw || !rdev->pfp_fw)
327 return -EINVAL;
328
329 r700_cp_stop(rdev);
Cédric Cano4eace7f2011-02-11 19:45:38 -0500330 WREG32(CP_RB_CNTL,
331#ifdef __BIG_ENDIAN
332 BUF_SWAP_32BIT |
333#endif
334 RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000335
336 /* Reset cp */
337 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
338 RREG32(GRBM_SOFT_RESET);
339 mdelay(15);
340 WREG32(GRBM_SOFT_RESET, 0);
341
342 fw_data = (const __be32 *)rdev->pfp_fw->data;
343 WREG32(CP_PFP_UCODE_ADDR, 0);
344 for (i = 0; i < R700_PFP_UCODE_SIZE; i++)
345 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
346 WREG32(CP_PFP_UCODE_ADDR, 0);
347
348 fw_data = (const __be32 *)rdev->me_fw->data;
349 WREG32(CP_ME_RAM_WADDR, 0);
350 for (i = 0; i < R700_PM4_UCODE_SIZE; i++)
351 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
352
353 WREG32(CP_PFP_UCODE_ADDR, 0);
354 WREG32(CP_ME_RAM_WADDR, 0);
355 WREG32(CP_ME_RAM_RADDR, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200356 return 0;
357}
358
Alex Deucherfe251e22010-03-24 13:36:43 -0400359void r700_cp_fini(struct radeon_device *rdev)
360{
361 r700_cp_stop(rdev);
362 radeon_ring_fini(rdev);
363}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200364
365/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000366 * Core functions
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200367 */
Alex Deucherd03f5d52010-02-19 16:22:31 -0500368static u32 r700_get_tile_pipe_to_backend_map(struct radeon_device *rdev,
369 u32 num_tile_pipes,
370 u32 num_backends,
371 u32 backend_disable_mask)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200372{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000373 u32 backend_map = 0;
374 u32 enabled_backends_mask;
375 u32 enabled_backends_count;
376 u32 cur_pipe;
377 u32 swizzle_pipe[R7XX_MAX_PIPES];
378 u32 cur_backend;
379 u32 i;
Alex Deucherd03f5d52010-02-19 16:22:31 -0500380 bool force_no_swizzle;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000381
382 if (num_tile_pipes > R7XX_MAX_PIPES)
383 num_tile_pipes = R7XX_MAX_PIPES;
384 if (num_tile_pipes < 1)
385 num_tile_pipes = 1;
386 if (num_backends > R7XX_MAX_BACKENDS)
387 num_backends = R7XX_MAX_BACKENDS;
388 if (num_backends < 1)
389 num_backends = 1;
390
391 enabled_backends_mask = 0;
392 enabled_backends_count = 0;
393 for (i = 0; i < R7XX_MAX_BACKENDS; ++i) {
394 if (((backend_disable_mask >> i) & 1) == 0) {
395 enabled_backends_mask |= (1 << i);
396 ++enabled_backends_count;
397 }
398 if (enabled_backends_count == num_backends)
399 break;
400 }
401
402 if (enabled_backends_count == 0) {
403 enabled_backends_mask = 1;
404 enabled_backends_count = 1;
405 }
406
407 if (enabled_backends_count != num_backends)
408 num_backends = enabled_backends_count;
409
Alex Deucherd03f5d52010-02-19 16:22:31 -0500410 switch (rdev->family) {
411 case CHIP_RV770:
412 case CHIP_RV730:
413 force_no_swizzle = false;
414 break;
415 case CHIP_RV710:
416 case CHIP_RV740:
417 default:
418 force_no_swizzle = true;
419 break;
420 }
421
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000422 memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R7XX_MAX_PIPES);
423 switch (num_tile_pipes) {
424 case 1:
425 swizzle_pipe[0] = 0;
426 break;
427 case 2:
428 swizzle_pipe[0] = 0;
429 swizzle_pipe[1] = 1;
430 break;
431 case 3:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500432 if (force_no_swizzle) {
433 swizzle_pipe[0] = 0;
434 swizzle_pipe[1] = 1;
435 swizzle_pipe[2] = 2;
436 } else {
437 swizzle_pipe[0] = 0;
438 swizzle_pipe[1] = 2;
439 swizzle_pipe[2] = 1;
440 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000441 break;
442 case 4:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500443 if (force_no_swizzle) {
444 swizzle_pipe[0] = 0;
445 swizzle_pipe[1] = 1;
446 swizzle_pipe[2] = 2;
447 swizzle_pipe[3] = 3;
448 } else {
449 swizzle_pipe[0] = 0;
450 swizzle_pipe[1] = 2;
451 swizzle_pipe[2] = 3;
452 swizzle_pipe[3] = 1;
453 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000454 break;
455 case 5:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500456 if (force_no_swizzle) {
457 swizzle_pipe[0] = 0;
458 swizzle_pipe[1] = 1;
459 swizzle_pipe[2] = 2;
460 swizzle_pipe[3] = 3;
461 swizzle_pipe[4] = 4;
462 } else {
463 swizzle_pipe[0] = 0;
464 swizzle_pipe[1] = 2;
465 swizzle_pipe[2] = 4;
466 swizzle_pipe[3] = 1;
467 swizzle_pipe[4] = 3;
468 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000469 break;
470 case 6:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500471 if (force_no_swizzle) {
472 swizzle_pipe[0] = 0;
473 swizzle_pipe[1] = 1;
474 swizzle_pipe[2] = 2;
475 swizzle_pipe[3] = 3;
476 swizzle_pipe[4] = 4;
477 swizzle_pipe[5] = 5;
478 } else {
479 swizzle_pipe[0] = 0;
480 swizzle_pipe[1] = 2;
481 swizzle_pipe[2] = 4;
482 swizzle_pipe[3] = 5;
483 swizzle_pipe[4] = 3;
484 swizzle_pipe[5] = 1;
485 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000486 break;
487 case 7:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500488 if (force_no_swizzle) {
489 swizzle_pipe[0] = 0;
490 swizzle_pipe[1] = 1;
491 swizzle_pipe[2] = 2;
492 swizzle_pipe[3] = 3;
493 swizzle_pipe[4] = 4;
494 swizzle_pipe[5] = 5;
495 swizzle_pipe[6] = 6;
496 } else {
497 swizzle_pipe[0] = 0;
498 swizzle_pipe[1] = 2;
499 swizzle_pipe[2] = 4;
500 swizzle_pipe[3] = 6;
501 swizzle_pipe[4] = 3;
502 swizzle_pipe[5] = 1;
503 swizzle_pipe[6] = 5;
504 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000505 break;
506 case 8:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500507 if (force_no_swizzle) {
508 swizzle_pipe[0] = 0;
509 swizzle_pipe[1] = 1;
510 swizzle_pipe[2] = 2;
511 swizzle_pipe[3] = 3;
512 swizzle_pipe[4] = 4;
513 swizzle_pipe[5] = 5;
514 swizzle_pipe[6] = 6;
515 swizzle_pipe[7] = 7;
516 } else {
517 swizzle_pipe[0] = 0;
518 swizzle_pipe[1] = 2;
519 swizzle_pipe[2] = 4;
520 swizzle_pipe[3] = 6;
521 swizzle_pipe[4] = 3;
522 swizzle_pipe[5] = 1;
523 swizzle_pipe[6] = 7;
524 swizzle_pipe[7] = 5;
525 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000526 break;
527 }
528
529 cur_backend = 0;
530 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
531 while (((1 << cur_backend) & enabled_backends_mask) == 0)
532 cur_backend = (cur_backend + 1) % R7XX_MAX_BACKENDS;
533
534 backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
535
536 cur_backend = (cur_backend + 1) % R7XX_MAX_BACKENDS;
537 }
538
539 return backend_map;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200540}
541
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000542static void rv770_gpu_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200543{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000544 int i, j, num_qd_pipes;
Alex Deucherd03f5d52010-02-19 16:22:31 -0500545 u32 ta_aux_cntl;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000546 u32 sx_debug_1;
547 u32 smx_dc_ctl0;
Alex Deucherd03f5d52010-02-19 16:22:31 -0500548 u32 db_debug3;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000549 u32 num_gs_verts_per_thread;
550 u32 vgt_gs_per_es;
551 u32 gs_prim_buffer_depth = 0;
552 u32 sq_ms_fifo_sizes;
553 u32 sq_config;
554 u32 sq_thread_resource_mgmt;
555 u32 hdp_host_path_cntl;
556 u32 sq_dyn_gpr_size_simd_ab_0;
557 u32 backend_map;
558 u32 gb_tiling_config = 0;
559 u32 cc_rb_backend_disable = 0;
560 u32 cc_gc_shader_pipe_config = 0;
561 u32 mc_arb_ramcfg;
562 u32 db_debug4;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200563
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000564 /* setup chip specs */
565 switch (rdev->family) {
566 case CHIP_RV770:
567 rdev->config.rv770.max_pipes = 4;
568 rdev->config.rv770.max_tile_pipes = 8;
569 rdev->config.rv770.max_simds = 10;
570 rdev->config.rv770.max_backends = 4;
571 rdev->config.rv770.max_gprs = 256;
572 rdev->config.rv770.max_threads = 248;
573 rdev->config.rv770.max_stack_entries = 512;
574 rdev->config.rv770.max_hw_contexts = 8;
575 rdev->config.rv770.max_gs_threads = 16 * 2;
576 rdev->config.rv770.sx_max_export_size = 128;
577 rdev->config.rv770.sx_max_export_pos_size = 16;
578 rdev->config.rv770.sx_max_export_smx_size = 112;
579 rdev->config.rv770.sq_num_cf_insts = 2;
580
581 rdev->config.rv770.sx_num_of_sets = 7;
582 rdev->config.rv770.sc_prim_fifo_size = 0xF9;
583 rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
584 rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
585 break;
586 case CHIP_RV730:
587 rdev->config.rv770.max_pipes = 2;
588 rdev->config.rv770.max_tile_pipes = 4;
589 rdev->config.rv770.max_simds = 8;
590 rdev->config.rv770.max_backends = 2;
591 rdev->config.rv770.max_gprs = 128;
592 rdev->config.rv770.max_threads = 248;
593 rdev->config.rv770.max_stack_entries = 256;
594 rdev->config.rv770.max_hw_contexts = 8;
595 rdev->config.rv770.max_gs_threads = 16 * 2;
596 rdev->config.rv770.sx_max_export_size = 256;
597 rdev->config.rv770.sx_max_export_pos_size = 32;
598 rdev->config.rv770.sx_max_export_smx_size = 224;
599 rdev->config.rv770.sq_num_cf_insts = 2;
600
601 rdev->config.rv770.sx_num_of_sets = 7;
602 rdev->config.rv770.sc_prim_fifo_size = 0xf9;
603 rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
604 rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
605 if (rdev->config.rv770.sx_max_export_pos_size > 16) {
606 rdev->config.rv770.sx_max_export_pos_size -= 16;
607 rdev->config.rv770.sx_max_export_smx_size += 16;
608 }
609 break;
610 case CHIP_RV710:
611 rdev->config.rv770.max_pipes = 2;
612 rdev->config.rv770.max_tile_pipes = 2;
613 rdev->config.rv770.max_simds = 2;
614 rdev->config.rv770.max_backends = 1;
615 rdev->config.rv770.max_gprs = 256;
616 rdev->config.rv770.max_threads = 192;
617 rdev->config.rv770.max_stack_entries = 256;
618 rdev->config.rv770.max_hw_contexts = 4;
619 rdev->config.rv770.max_gs_threads = 8 * 2;
620 rdev->config.rv770.sx_max_export_size = 128;
621 rdev->config.rv770.sx_max_export_pos_size = 16;
622 rdev->config.rv770.sx_max_export_smx_size = 112;
623 rdev->config.rv770.sq_num_cf_insts = 1;
624
625 rdev->config.rv770.sx_num_of_sets = 7;
626 rdev->config.rv770.sc_prim_fifo_size = 0x40;
627 rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
628 rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
629 break;
630 case CHIP_RV740:
631 rdev->config.rv770.max_pipes = 4;
632 rdev->config.rv770.max_tile_pipes = 4;
633 rdev->config.rv770.max_simds = 8;
634 rdev->config.rv770.max_backends = 4;
635 rdev->config.rv770.max_gprs = 256;
636 rdev->config.rv770.max_threads = 248;
637 rdev->config.rv770.max_stack_entries = 512;
638 rdev->config.rv770.max_hw_contexts = 8;
639 rdev->config.rv770.max_gs_threads = 16 * 2;
640 rdev->config.rv770.sx_max_export_size = 256;
641 rdev->config.rv770.sx_max_export_pos_size = 32;
642 rdev->config.rv770.sx_max_export_smx_size = 224;
643 rdev->config.rv770.sq_num_cf_insts = 2;
644
645 rdev->config.rv770.sx_num_of_sets = 7;
646 rdev->config.rv770.sc_prim_fifo_size = 0x100;
647 rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
648 rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
649
650 if (rdev->config.rv770.sx_max_export_pos_size > 16) {
651 rdev->config.rv770.sx_max_export_pos_size -= 16;
652 rdev->config.rv770.sx_max_export_smx_size += 16;
653 }
654 break;
655 default:
656 break;
657 }
658
659 /* Initialize HDP */
660 j = 0;
661 for (i = 0; i < 32; i++) {
662 WREG32((0x2c14 + j), 0x00000000);
663 WREG32((0x2c18 + j), 0x00000000);
664 WREG32((0x2c1c + j), 0x00000000);
665 WREG32((0x2c20 + j), 0x00000000);
666 WREG32((0x2c24 + j), 0x00000000);
667 j += 0x18;
668 }
669
670 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
671
672 /* setup tiling, simd, pipe config */
673 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
674
675 switch (rdev->config.rv770.max_tile_pipes) {
676 case 1:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500677 default:
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000678 gb_tiling_config |= PIPE_TILING(0);
679 break;
680 case 2:
681 gb_tiling_config |= PIPE_TILING(1);
682 break;
683 case 4:
684 gb_tiling_config |= PIPE_TILING(2);
685 break;
686 case 8:
687 gb_tiling_config |= PIPE_TILING(3);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000688 break;
689 }
Alex Deucherd03f5d52010-02-19 16:22:31 -0500690 rdev->config.rv770.tiling_npipes = rdev->config.rv770.max_tile_pipes;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000691
692 if (rdev->family == CHIP_RV770)
693 gb_tiling_config |= BANK_TILING(1);
694 else
Alex Deuchere29649d2009-11-03 10:04:01 -0500695 gb_tiling_config |= BANK_TILING((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Jerome Glisse961fb592010-02-10 22:30:05 +0000696 rdev->config.rv770.tiling_nbanks = 4 << ((gb_tiling_config >> 4) & 0x3);
Alex Deucher881fe6c2010-10-18 23:54:56 -0400697 gb_tiling_config |= GROUP_SIZE((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
698 if ((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT)
699 rdev->config.rv770.tiling_group_size = 512;
700 else
701 rdev->config.rv770.tiling_group_size = 256;
Alex Deuchere29649d2009-11-03 10:04:01 -0500702 if (((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT) > 3) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000703 gb_tiling_config |= ROW_TILING(3);
704 gb_tiling_config |= SAMPLE_SPLIT(3);
705 } else {
706 gb_tiling_config |=
707 ROW_TILING(((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT));
708 gb_tiling_config |=
709 SAMPLE_SPLIT(((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT));
710 }
711
712 gb_tiling_config |= BANK_SWAPS(1);
713
Alex Deucherd03f5d52010-02-19 16:22:31 -0500714 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
715 cc_rb_backend_disable |=
716 BACKEND_DISABLE((R7XX_MAX_BACKENDS_MASK << rdev->config.rv770.max_backends) & R7XX_MAX_BACKENDS_MASK);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000717
Alex Deucherd03f5d52010-02-19 16:22:31 -0500718 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
719 cc_gc_shader_pipe_config |=
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000720 INACTIVE_QD_PIPES((R7XX_MAX_PIPES_MASK << rdev->config.rv770.max_pipes) & R7XX_MAX_PIPES_MASK);
721 cc_gc_shader_pipe_config |=
722 INACTIVE_SIMDS((R7XX_MAX_SIMDS_MASK << rdev->config.rv770.max_simds) & R7XX_MAX_SIMDS_MASK);
723
Alex Deucherd03f5d52010-02-19 16:22:31 -0500724 if (rdev->family == CHIP_RV740)
725 backend_map = 0x28;
726 else
727 backend_map = r700_get_tile_pipe_to_backend_map(rdev,
728 rdev->config.rv770.max_tile_pipes,
729 (R7XX_MAX_BACKENDS -
730 r600_count_pipe_bits((cc_rb_backend_disable &
731 R7XX_MAX_BACKENDS_MASK) >> 16)),
732 (cc_rb_backend_disable >> 16));
Alex Deucherd03f5d52010-02-19 16:22:31 -0500733
Alex Deuchere7aeeba62010-06-04 13:10:12 -0400734 rdev->config.rv770.tile_config = gb_tiling_config;
Alex Deuchere55b9422011-07-15 19:53:52 +0000735 rdev->config.rv770.backend_map = backend_map;
Alex Deuchere7aeeba62010-06-04 13:10:12 -0400736 gb_tiling_config |= BACKEND_MAP(backend_map);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000737
738 WREG32(GB_TILING_CONFIG, gb_tiling_config);
739 WREG32(DCP_TILING_CONFIG, (gb_tiling_config & 0xffff));
740 WREG32(HDP_TILING_CONFIG, (gb_tiling_config & 0xffff));
741
742 WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
743 WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
Alex Deucherf867c60d2010-03-05 14:50:37 -0500744 WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
Alex Deucherd03f5d52010-02-19 16:22:31 -0500745 WREG32(CC_SYS_RB_BACKEND_DISABLE, cc_rb_backend_disable);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000746
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000747 WREG32(CGTS_SYS_TCC_DISABLE, 0);
748 WREG32(CGTS_TCC_DISABLE, 0);
Alex Deucherf867c60d2010-03-05 14:50:37 -0500749 WREG32(CGTS_USER_SYS_TCC_DISABLE, 0);
750 WREG32(CGTS_USER_TCC_DISABLE, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000751
752 num_qd_pipes =
Alex Deucherd03f5d52010-02-19 16:22:31 -0500753 R7XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000754 WREG32(VGT_OUT_DEALLOC_CNTL, (num_qd_pipes * 4) & DEALLOC_DIST_MASK);
755 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((num_qd_pipes * 4) - 2) & VTX_REUSE_DEPTH_MASK);
756
757 /* set HW defaults for 3D engine */
758 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
Alex Deuchere29649d2009-11-03 10:04:01 -0500759 ROQ_IB2_START(0x2b)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000760
761 WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30));
762
Alex Deucherd03f5d52010-02-19 16:22:31 -0500763 ta_aux_cntl = RREG32(TA_CNTL_AUX);
764 WREG32(TA_CNTL_AUX, ta_aux_cntl | DISABLE_CUBE_ANISO);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000765
766 sx_debug_1 = RREG32(SX_DEBUG_1);
767 sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
768 WREG32(SX_DEBUG_1, sx_debug_1);
769
770 smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
771 smx_dc_ctl0 &= ~CACHE_DEPTH(0x1ff);
772 smx_dc_ctl0 |= CACHE_DEPTH((rdev->config.rv770.sx_num_of_sets * 64) - 1);
773 WREG32(SMX_DC_CTL0, smx_dc_ctl0);
774
Alex Deucherd03f5d52010-02-19 16:22:31 -0500775 if (rdev->family != CHIP_RV740)
776 WREG32(SMX_EVENT_CTL, (ES_FLUSH_CTL(4) |
777 GS_FLUSH_CTL(4) |
778 ACK_FLUSH_CTL(3) |
779 SYNC_FLUSH_CTL));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000780
Alex Deucherd03f5d52010-02-19 16:22:31 -0500781 db_debug3 = RREG32(DB_DEBUG3);
782 db_debug3 &= ~DB_CLK_OFF_DELAY(0x1f);
783 switch (rdev->family) {
784 case CHIP_RV770:
785 case CHIP_RV740:
786 db_debug3 |= DB_CLK_OFF_DELAY(0x1f);
787 break;
788 case CHIP_RV710:
789 case CHIP_RV730:
790 default:
791 db_debug3 |= DB_CLK_OFF_DELAY(2);
792 break;
793 }
794 WREG32(DB_DEBUG3, db_debug3);
795
796 if (rdev->family != CHIP_RV770) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000797 db_debug4 = RREG32(DB_DEBUG4);
798 db_debug4 |= DISABLE_TILE_COVERED_FOR_PS_ITER;
799 WREG32(DB_DEBUG4, db_debug4);
800 }
801
802 WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.rv770.sx_max_export_size / 4) - 1) |
Alex Deuchere29649d2009-11-03 10:04:01 -0500803 POSITION_BUFFER_SIZE((rdev->config.rv770.sx_max_export_pos_size / 4) - 1) |
804 SMX_BUFFER_SIZE((rdev->config.rv770.sx_max_export_smx_size / 4) - 1)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000805
806 WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.rv770.sc_prim_fifo_size) |
Alex Deuchere29649d2009-11-03 10:04:01 -0500807 SC_HIZ_TILE_FIFO_SIZE(rdev->config.rv770.sc_hiz_tile_fifo_size) |
808 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.rv770.sc_earlyz_tile_fifo_fize)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000809
810 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
811
812 WREG32(VGT_NUM_INSTANCES, 1);
813
814 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
815
816 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
817
818 WREG32(CP_PERFMON_CNTL, 0);
819
820 sq_ms_fifo_sizes = (CACHE_FIFO_SIZE(16 * rdev->config.rv770.sq_num_cf_insts) |
821 DONE_FIFO_HIWATER(0xe0) |
822 ALU_UPDATE_FIFO_HIWATER(0x8));
823 switch (rdev->family) {
824 case CHIP_RV770:
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000825 case CHIP_RV730:
826 case CHIP_RV710:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500827 sq_ms_fifo_sizes |= FETCH_FIFO_HIWATER(0x1);
828 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000829 case CHIP_RV740:
830 default:
831 sq_ms_fifo_sizes |= FETCH_FIFO_HIWATER(0x4);
832 break;
833 }
834 WREG32(SQ_MS_FIFO_SIZES, sq_ms_fifo_sizes);
835
836 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
837 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
838 */
839 sq_config = RREG32(SQ_CONFIG);
840 sq_config &= ~(PS_PRIO(3) |
841 VS_PRIO(3) |
842 GS_PRIO(3) |
843 ES_PRIO(3));
844 sq_config |= (DX9_CONSTS |
845 VC_ENABLE |
846 EXPORT_SRC_C |
847 PS_PRIO(0) |
848 VS_PRIO(1) |
849 GS_PRIO(2) |
850 ES_PRIO(3));
851 if (rdev->family == CHIP_RV710)
852 /* no vertex cache */
853 sq_config &= ~VC_ENABLE;
854
855 WREG32(SQ_CONFIG, sq_config);
856
857 WREG32(SQ_GPR_RESOURCE_MGMT_1, (NUM_PS_GPRS((rdev->config.rv770.max_gprs * 24)/64) |
Dave Airliefe62e1a2009-09-21 14:06:30 +1000858 NUM_VS_GPRS((rdev->config.rv770.max_gprs * 24)/64) |
859 NUM_CLAUSE_TEMP_GPRS(((rdev->config.rv770.max_gprs * 24)/64)/2)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000860
861 WREG32(SQ_GPR_RESOURCE_MGMT_2, (NUM_GS_GPRS((rdev->config.rv770.max_gprs * 7)/64) |
Dave Airliefe62e1a2009-09-21 14:06:30 +1000862 NUM_ES_GPRS((rdev->config.rv770.max_gprs * 7)/64)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000863
864 sq_thread_resource_mgmt = (NUM_PS_THREADS((rdev->config.rv770.max_threads * 4)/8) |
865 NUM_VS_THREADS((rdev->config.rv770.max_threads * 2)/8) |
866 NUM_ES_THREADS((rdev->config.rv770.max_threads * 1)/8));
867 if (((rdev->config.rv770.max_threads * 1) / 8) > rdev->config.rv770.max_gs_threads)
868 sq_thread_resource_mgmt |= NUM_GS_THREADS(rdev->config.rv770.max_gs_threads);
869 else
870 sq_thread_resource_mgmt |= NUM_GS_THREADS((rdev->config.rv770.max_gs_threads * 1)/8);
871 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
872
873 WREG32(SQ_STACK_RESOURCE_MGMT_1, (NUM_PS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4) |
874 NUM_VS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4)));
875
876 WREG32(SQ_STACK_RESOURCE_MGMT_2, (NUM_GS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4) |
877 NUM_ES_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4)));
878
879 sq_dyn_gpr_size_simd_ab_0 = (SIMDA_RING0((rdev->config.rv770.max_gprs * 38)/64) |
880 SIMDA_RING1((rdev->config.rv770.max_gprs * 38)/64) |
881 SIMDB_RING0((rdev->config.rv770.max_gprs * 38)/64) |
882 SIMDB_RING1((rdev->config.rv770.max_gprs * 38)/64));
883
884 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_0, sq_dyn_gpr_size_simd_ab_0);
885 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_1, sq_dyn_gpr_size_simd_ab_0);
886 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_2, sq_dyn_gpr_size_simd_ab_0);
887 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_3, sq_dyn_gpr_size_simd_ab_0);
888 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_4, sq_dyn_gpr_size_simd_ab_0);
889 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_5, sq_dyn_gpr_size_simd_ab_0);
890 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_6, sq_dyn_gpr_size_simd_ab_0);
891 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_7, sq_dyn_gpr_size_simd_ab_0);
892
893 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
Dave Airliefe62e1a2009-09-21 14:06:30 +1000894 FORCE_EOV_MAX_REZ_CNT(255)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000895
896 if (rdev->family == CHIP_RV710)
897 WREG32(VGT_CACHE_INVALIDATION, (CACHE_INVALIDATION(TC_ONLY) |
Dave Airliefe62e1a2009-09-21 14:06:30 +1000898 AUTO_INVLD_EN(ES_AND_GS_AUTO)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000899 else
900 WREG32(VGT_CACHE_INVALIDATION, (CACHE_INVALIDATION(VC_AND_TC) |
Dave Airliefe62e1a2009-09-21 14:06:30 +1000901 AUTO_INVLD_EN(ES_AND_GS_AUTO)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000902
903 switch (rdev->family) {
904 case CHIP_RV770:
905 case CHIP_RV730:
906 case CHIP_RV740:
907 gs_prim_buffer_depth = 384;
908 break;
909 case CHIP_RV710:
910 gs_prim_buffer_depth = 128;
911 break;
912 default:
913 break;
914 }
915
916 num_gs_verts_per_thread = rdev->config.rv770.max_pipes * 16;
917 vgt_gs_per_es = gs_prim_buffer_depth + num_gs_verts_per_thread;
918 /* Max value for this is 256 */
919 if (vgt_gs_per_es > 256)
920 vgt_gs_per_es = 256;
921
922 WREG32(VGT_ES_PER_GS, 128);
923 WREG32(VGT_GS_PER_ES, vgt_gs_per_es);
924 WREG32(VGT_GS_PER_VS, 2);
925
926 /* more default values. 2D/3D driver should adjust as needed */
927 WREG32(VGT_GS_VERTEX_REUSE, 16);
928 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
929 WREG32(VGT_STRMOUT_EN, 0);
930 WREG32(SX_MISC, 0);
931 WREG32(PA_SC_MODE_CNTL, 0);
932 WREG32(PA_SC_EDGERULE, 0xaaaaaaaa);
933 WREG32(PA_SC_AA_CONFIG, 0);
934 WREG32(PA_SC_CLIPRECT_RULE, 0xffff);
935 WREG32(PA_SC_LINE_STIPPLE, 0);
936 WREG32(SPI_INPUT_Z, 0);
937 WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
938 WREG32(CB_COLOR7_FRAG, 0);
939
940 /* clear render buffer base addresses */
941 WREG32(CB_COLOR0_BASE, 0);
942 WREG32(CB_COLOR1_BASE, 0);
943 WREG32(CB_COLOR2_BASE, 0);
944 WREG32(CB_COLOR3_BASE, 0);
945 WREG32(CB_COLOR4_BASE, 0);
946 WREG32(CB_COLOR5_BASE, 0);
947 WREG32(CB_COLOR6_BASE, 0);
948 WREG32(CB_COLOR7_BASE, 0);
949
950 WREG32(TCP_CNTL, 0);
951
952 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
953 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
954
955 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
956
957 WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
958 NUM_CLIP_SEQ(3)));
959
960}
961
Alex Deucher0ef0c1f2010-11-22 17:56:26 -0500962void r700_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
963{
964 u64 size_bf, size_af;
965
966 if (mc->mc_vram_size > 0xE0000000) {
967 /* leave room for at least 512M GTT */
968 dev_warn(rdev->dev, "limiting VRAM\n");
969 mc->real_vram_size = 0xE0000000;
970 mc->mc_vram_size = 0xE0000000;
971 }
972 if (rdev->flags & RADEON_IS_AGP) {
973 size_bf = mc->gtt_start;
974 size_af = 0xFFFFFFFF - mc->gtt_end + 1;
975 if (size_bf > size_af) {
976 if (mc->mc_vram_size > size_bf) {
977 dev_warn(rdev->dev, "limiting VRAM\n");
978 mc->real_vram_size = size_bf;
979 mc->mc_vram_size = size_bf;
980 }
981 mc->vram_start = mc->gtt_start - mc->mc_vram_size;
982 } else {
983 if (mc->mc_vram_size > size_af) {
984 dev_warn(rdev->dev, "limiting VRAM\n");
985 mc->real_vram_size = size_af;
986 mc->mc_vram_size = size_af;
987 }
988 mc->vram_start = mc->gtt_end;
989 }
990 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
991 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
992 mc->mc_vram_size >> 20, mc->vram_start,
993 mc->vram_end, mc->real_vram_size >> 20);
994 } else {
Alex Deucherb4183e32010-12-15 11:04:10 -0500995 radeon_vram_location(rdev, &rdev->mc, 0);
Alex Deucher0ef0c1f2010-11-22 17:56:26 -0500996 rdev->mc.gtt_base_align = 0;
997 radeon_gtt_location(rdev, mc);
998 }
999}
1000
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001001int rv770_mc_init(struct radeon_device *rdev)
1002{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001003 u32 tmp;
Alex Deucher5885b7a2009-10-19 17:23:33 -04001004 int chansize, numchan;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001005
1006 /* Get VRAM informations */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001007 rdev->mc.vram_is_ddr = true;
Alex Deucher5885b7a2009-10-19 17:23:33 -04001008 tmp = RREG32(MC_ARB_RAMCFG);
1009 if (tmp & CHANSIZE_OVERRIDE) {
1010 chansize = 16;
1011 } else if (tmp & CHANSIZE_MASK) {
1012 chansize = 64;
1013 } else {
1014 chansize = 32;
1015 }
1016 tmp = RREG32(MC_SHARED_CHMAP);
1017 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1018 case 0:
1019 default:
1020 numchan = 1;
1021 break;
1022 case 1:
1023 numchan = 2;
1024 break;
1025 case 2:
1026 numchan = 4;
1027 break;
1028 case 3:
1029 numchan = 8;
1030 break;
1031 }
1032 rdev->mc.vram_width = numchan * chansize;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001033 /* Could aper size report 0 ? */
Jordan Crouse01d73a62010-05-27 13:40:24 -06001034 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
1035 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001036 /* Setup GPU memory space */
1037 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
1038 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
Jerome Glisse51e5fcd2010-02-19 14:33:54 +00001039 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Alex Deucher0ef0c1f2010-11-22 17:56:26 -05001040 r700_vram_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -04001041 radeon_update_bandwidth_info(rdev);
1042
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001043 return 0;
1044}
Jerome Glissed594e462010-02-17 21:54:29 +00001045
Dave Airliefc30b8e2009-09-18 15:19:37 +10001046static int rv770_startup(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001047{
1048 int r;
1049
Alex Deucher9e46a482011-01-06 18:49:35 -05001050 /* enable pcie gen2 link */
1051 rv770_pcie_gen2_enable(rdev);
1052
Alex Deucher779720a2009-12-09 19:31:44 -05001053 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
1054 r = r600_init_microcode(rdev);
1055 if (r) {
1056 DRM_ERROR("Failed to load firmware!\n");
1057 return r;
1058 }
1059 }
1060
Alex Deucher16cdf042011-10-28 10:30:02 -04001061 r = r600_vram_scratch_init(rdev);
1062 if (r)
1063 return r;
1064
Jerome Glissea3c19452009-10-01 18:02:13 +02001065 rv770_mc_program(rdev);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001066 if (rdev->flags & RADEON_IS_AGP) {
1067 rv770_agp_enable(rdev);
1068 } else {
1069 r = rv770_pcie_gart_enable(rdev);
1070 if (r)
1071 return r;
1072 }
Alex Deucher16cdf042011-10-28 10:30:02 -04001073
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001074 rv770_gpu_init(rdev);
Jerome Glissec38c7b62010-02-04 17:27:27 +01001075 r = r600_blit_init(rdev);
1076 if (r) {
1077 r600_blit_fini(rdev);
1078 rdev->asic->copy = NULL;
1079 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
1080 }
Alex Deucherb70d6bb2010-08-06 21:36:58 -04001081
Alex Deucher724c80e2010-08-27 18:25:25 -04001082 /* allocate wb buffer */
1083 r = radeon_wb_init(rdev);
1084 if (r)
1085 return r;
1086
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001087 /* Enable IRQ */
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001088 r = r600_irq_init(rdev);
1089 if (r) {
1090 DRM_ERROR("radeon: IH init failed (%d).\n", r);
1091 radeon_irq_kms_fini(rdev);
1092 return r;
1093 }
1094 r600_irq_set(rdev);
1095
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001096 r = radeon_ring_init(rdev, rdev->cp.ring_size);
1097 if (r)
1098 return r;
1099 r = rv770_cp_load_microcode(rdev);
1100 if (r)
1101 return r;
1102 r = r600_cp_resume(rdev);
1103 if (r)
1104 return r;
Alex Deucher724c80e2010-08-27 18:25:25 -04001105
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001106 return 0;
1107}
1108
Dave Airliefc30b8e2009-09-18 15:19:37 +10001109int rv770_resume(struct radeon_device *rdev)
1110{
1111 int r;
1112
Jerome Glisse1a029b72009-10-06 19:04:30 +02001113 /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
1114 * posting will perform necessary task to bring back GPU into good
1115 * shape.
1116 */
Dave Airliefc30b8e2009-09-18 15:19:37 +10001117 /* post card */
Jerome Glissee7d40b92009-10-01 18:02:15 +02001118 atom_asic_init(rdev->mode_info.atom_context);
Dave Airliefc30b8e2009-09-18 15:19:37 +10001119
1120 r = rv770_startup(rdev);
1121 if (r) {
1122 DRM_ERROR("r600 startup failed on resume\n");
1123 return r;
1124 }
1125
Jerome Glisse62a8ea32009-10-01 18:02:11 +02001126 r = r600_ib_test(rdev);
Dave Airliefc30b8e2009-09-18 15:19:37 +10001127 if (r) {
Paul Bolleec4f2ac2011-01-28 23:32:04 +01001128 DRM_ERROR("radeon: failed testing IB (%d).\n", r);
Dave Airliefc30b8e2009-09-18 15:19:37 +10001129 return r;
1130 }
Rafał Miłecki8a8c6e72010-03-06 13:03:36 +00001131
1132 r = r600_audio_init(rdev);
1133 if (r) {
1134 dev_err(rdev->dev, "radeon: audio init failed\n");
1135 return r;
1136 }
1137
Dave Airliefc30b8e2009-09-18 15:19:37 +10001138 return r;
1139
1140}
1141
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001142int rv770_suspend(struct radeon_device *rdev)
1143{
Rafał Miłecki8a8c6e72010-03-06 13:03:36 +00001144 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001145 /* FIXME: we should wait for ring to be empty */
1146 r700_cp_stop(rdev);
Dave Airlie4153e582009-09-18 18:41:24 +10001147 rdev->cp.ready = false;
Jerome Glisse0c452492010-01-15 14:44:37 +01001148 r600_irq_suspend(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04001149 radeon_wb_disable(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001150 rv770_pcie_gart_disable(rdev);
Alex Deucher6ddddfe2011-10-14 10:51:22 -04001151 r600_blit_suspend(rdev);
1152
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001153 return 0;
1154}
1155
1156/* Plan is to move initialization in that function and use
1157 * helper function so that radeon_device_init pretty much
1158 * do nothing more than calling asic specific function. This
1159 * should also allow to remove a bunch of callback function
1160 * like vram_info.
1161 */
1162int rv770_init(struct radeon_device *rdev)
1163{
1164 int r;
1165
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001166 /* This don't do much */
1167 r = radeon_gem_init(rdev);
1168 if (r)
1169 return r;
1170 /* Read BIOS */
1171 if (!radeon_get_bios(rdev)) {
1172 if (ASIC_IS_AVIVO(rdev))
1173 return -EINVAL;
1174 }
1175 /* Must be an ATOMBIOS */
Jerome Glissee7d40b92009-10-01 18:02:15 +02001176 if (!rdev->is_atom_bios) {
1177 dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001178 return -EINVAL;
Jerome Glissee7d40b92009-10-01 18:02:15 +02001179 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001180 r = radeon_atombios_init(rdev);
1181 if (r)
1182 return r;
1183 /* Post card if necessary */
Alex Deucherfd909c32011-01-11 18:08:59 -05001184 if (!radeon_card_posted(rdev)) {
Dave Airlie72542d72009-12-01 14:06:31 +10001185 if (!rdev->bios) {
1186 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
1187 return -EINVAL;
1188 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001189 DRM_INFO("GPU not posted. posting now...\n");
1190 atom_asic_init(rdev->mode_info.atom_context);
1191 }
1192 /* Initialize scratch registers */
1193 r600_scratch_init(rdev);
1194 /* Initialize surface registers */
1195 radeon_surface_init(rdev);
Rafał Miłecki74338742009-11-03 00:53:02 +01001196 /* Initialize clocks */
Michel Dänzer5e6dde72009-09-17 09:42:28 +02001197 radeon_get_clock_info(rdev->ddev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001198 /* Fence driver */
1199 r = radeon_fence_driver_init(rdev);
1200 if (r)
1201 return r;
Jerome Glissed594e462010-02-17 21:54:29 +00001202 /* initialize AGP */
Jerome Glisse700a0cc2010-01-13 15:16:38 +01001203 if (rdev->flags & RADEON_IS_AGP) {
1204 r = radeon_agp_init(rdev);
1205 if (r)
1206 radeon_agp_disable(rdev);
1207 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001208 r = rv770_mc_init(rdev);
Jerome Glisseb574f252009-10-06 19:04:29 +02001209 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001210 return r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001211 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01001212 r = radeon_bo_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001213 if (r)
1214 return r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001215
1216 r = radeon_irq_kms_init(rdev);
1217 if (r)
1218 return r;
1219
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001220 rdev->cp.ring_obj = NULL;
1221 r600_ring_init(rdev, 1024 * 1024);
1222
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001223 rdev->ih.ring_obj = NULL;
1224 r600_ih_ring_init(rdev, 64 * 1024);
1225
Jerome Glisse4aac0472009-09-14 18:29:49 +02001226 r = r600_pcie_gart_init(rdev);
1227 if (r)
1228 return r;
1229
Alex Deucher779720a2009-12-09 19:31:44 -05001230 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10001231 r = rv770_startup(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001232 if (r) {
Jerome Glisse655efd32010-02-02 11:51:45 +01001233 dev_err(rdev->dev, "disabling GPU acceleration\n");
Alex Deucherfe251e22010-03-24 13:36:43 -04001234 r700_cp_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01001235 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04001236 radeon_wb_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01001237 radeon_irq_kms_fini(rdev);
Jerome Glisse75c81292009-10-01 18:02:14 +02001238 rv770_pcie_gart_fini(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +02001239 rdev->accel_working = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001240 }
Jerome Glisse733289c2009-09-16 15:24:21 +02001241 if (rdev->accel_working) {
Jerome Glisse733289c2009-09-16 15:24:21 +02001242 r = radeon_ib_pool_init(rdev);
1243 if (r) {
Jerome Glissedb963802010-01-17 21:21:56 +01001244 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisse733289c2009-09-16 15:24:21 +02001245 rdev->accel_working = false;
Jerome Glissedb963802010-01-17 21:21:56 +01001246 } else {
1247 r = r600_ib_test(rdev);
1248 if (r) {
1249 dev_err(rdev->dev, "IB test failed (%d).\n", r);
1250 rdev->accel_working = false;
1251 }
Jerome Glisse733289c2009-09-16 15:24:21 +02001252 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001253 }
Rafał Miłecki8a8c6e72010-03-06 13:03:36 +00001254
1255 r = r600_audio_init(rdev);
1256 if (r) {
1257 dev_err(rdev->dev, "radeon: audio init failed\n");
1258 return r;
1259 }
1260
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001261 return 0;
1262}
1263
1264void rv770_fini(struct radeon_device *rdev)
1265{
1266 r600_blit_fini(rdev);
Alex Deucherfe251e22010-03-24 13:36:43 -04001267 r700_cp_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001268 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04001269 radeon_wb_fini(rdev);
Jerome Glisseccd68952011-07-06 18:30:09 +00001270 radeon_ib_pool_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001271 radeon_irq_kms_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001272 rv770_pcie_gart_fini(rdev);
Alex Deucher16cdf042011-10-28 10:30:02 -04001273 r600_vram_scratch_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001274 radeon_gem_fini(rdev);
1275 radeon_fence_driver_fini(rdev);
Jerome Glissed0269ed2010-01-07 16:08:32 +01001276 radeon_agp_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01001277 radeon_bo_fini(rdev);
Jerome Glissee7d40b92009-10-01 18:02:15 +02001278 radeon_atombios_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001279 kfree(rdev->bios);
1280 rdev->bios = NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001281}
Alex Deucher9e46a482011-01-06 18:49:35 -05001282
1283static void rv770_pcie_gen2_enable(struct radeon_device *rdev)
1284{
1285 u32 link_width_cntl, lanes, speed_cntl, tmp;
1286 u16 link_cntl2;
1287
Alex Deucherd42dd572011-01-12 20:05:11 -05001288 if (radeon_pcie_gen2 == 0)
1289 return;
1290
Alex Deucher9e46a482011-01-06 18:49:35 -05001291 if (rdev->flags & RADEON_IS_IGP)
1292 return;
1293
1294 if (!(rdev->flags & RADEON_IS_PCIE))
1295 return;
1296
1297 /* x2 cards have a special sequence */
1298 if (ASIC_IS_X2(rdev))
1299 return;
1300
1301 /* advertise upconfig capability */
1302 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
1303 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
1304 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
1305 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
1306 if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) {
1307 lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT;
1308 link_width_cntl &= ~(LC_LINK_WIDTH_MASK |
1309 LC_RECONFIG_ARC_MISSING_ESCAPE);
1310 link_width_cntl |= lanes | LC_RECONFIG_NOW |
1311 LC_RENEGOTIATE_EN | LC_UPCONFIGURE_SUPPORT;
1312 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
1313 } else {
1314 link_width_cntl |= LC_UPCONFIGURE_DIS;
1315 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
1316 }
1317
1318 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
1319 if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
1320 (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
1321
1322 tmp = RREG32(0x541c);
1323 WREG32(0x541c, tmp | 0x8);
1324 WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN);
1325 link_cntl2 = RREG16(0x4088);
1326 link_cntl2 &= ~TARGET_LINK_SPEED_MASK;
1327 link_cntl2 |= 0x2;
1328 WREG16(0x4088, link_cntl2);
1329 WREG32(MM_CFGREGS_CNTL, 0);
1330
1331 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
1332 speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
1333 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
1334
1335 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
1336 speed_cntl |= LC_CLR_FAILED_SPD_CHANGE_CNT;
1337 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
1338
1339 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
1340 speed_cntl &= ~LC_CLR_FAILED_SPD_CHANGE_CNT;
1341 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
1342
1343 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
1344 speed_cntl |= LC_GEN2_EN_STRAP;
1345 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
1346
1347 } else {
1348 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
1349 /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
1350 if (1)
1351 link_width_cntl |= LC_UPCONFIGURE_DIS;
1352 else
1353 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
1354 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
1355 }
1356}