blob: 645aa1fd76111ffdb2f2f3e22426cb6cb098fd6e [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);
44
Alex Deucher6f34be52010-11-21 10:59:01 -050045u32 rv770_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
46{
47 struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
48 u32 tmp = RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset);
49
50 /* Lock the graphics update lock */
51 tmp |= AVIVO_D1GRPH_UPDATE_LOCK;
52 WREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
53
54 /* update the scanout addresses */
55 if (radeon_crtc->crtc_id) {
56 WREG32(D2GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
57 WREG32(D2GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
58 } else {
59 WREG32(D1GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
60 WREG32(D1GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(crtc_base));
61 }
62 WREG32(D1GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
63 (u32)crtc_base);
64 WREG32(D1GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
65 (u32)crtc_base);
66
67 /* Wait for update_pending to go high. */
68 while (!(RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING));
69 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
70
71 /* Unlock the lock, so double-buffering can take place inside vblank */
72 tmp &= ~AVIVO_D1GRPH_UPDATE_LOCK;
73 WREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
74
75 /* Return current update_pending status: */
76 return RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING;
77}
78
Alex Deucher21a81222010-07-02 12:58:16 -040079/* get temperature in millidegrees */
80u32 rv770_get_temp(struct radeon_device *rdev)
81{
82 u32 temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >>
83 ASIC_T_SHIFT;
84 u32 actual_temp = 0;
85
86 if ((temp >> 9) & 1)
87 actual_temp = 0;
88 else
89 actual_temp = (temp >> 1) & 0xff;
90
91 return actual_temp * 1000;
92}
93
Alex Deucher49e02b72010-04-23 17:57:27 -040094void rv770_pm_misc(struct radeon_device *rdev)
95{
Rafał Miłeckia081a9d2010-06-07 18:20:25 -040096 int req_ps_idx = rdev->pm.requested_power_state_index;
97 int req_cm_idx = rdev->pm.requested_clock_mode_index;
98 struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
99 struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
Alex Deucher4d601732010-06-07 18:15:18 -0400100
101 if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
102 if (voltage->voltage != rdev->pm.current_vddc) {
103 radeon_atom_set_voltage(rdev, voltage->voltage);
104 rdev->pm.current_vddc = voltage->voltage;
Rafał Miłecki0fcbe942010-06-07 18:25:21 -0400105 DRM_DEBUG("Setting: v: %d\n", voltage->voltage);
Alex Deucher4d601732010-06-07 18:15:18 -0400106 }
107 }
Alex Deucher49e02b72010-04-23 17:57:27 -0400108}
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000109
110/*
111 * GART
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200112 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000113int rv770_pcie_gart_enable(struct radeon_device *rdev)
114{
115 u32 tmp;
116 int r, i;
117
Jerome Glisse4aac0472009-09-14 18:29:49 +0200118 if (rdev->gart.table.vram.robj == NULL) {
119 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
120 return -EINVAL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000121 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200122 r = radeon_gart_table_vram_pin(rdev);
123 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000124 return r;
Dave Airlie82568562010-02-05 16:00:07 +1000125 radeon_gart_restore(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000126 /* Setup L2 cache */
127 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
128 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
129 EFFECTIVE_L2_QUEUE_SIZE(7));
130 WREG32(VM_L2_CNTL2, 0);
131 WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
132 /* Setup TLB control */
133 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
134 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
135 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
136 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
137 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
138 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
139 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
140 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
141 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
142 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
143 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
144 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200145 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000146 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
147 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
148 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
149 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
150 (u32)(rdev->dummy_page.addr >> 12));
151 for (i = 1; i < 7; i++)
152 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
153
154 r600_pcie_gart_tlb_flush(rdev);
155 rdev->gart.ready = true;
156 return 0;
157}
158
159void rv770_pcie_gart_disable(struct radeon_device *rdev)
160{
161 u32 tmp;
Jerome Glisse4c788672009-11-20 14:29:23 +0100162 int i, r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000163
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000164 /* Disable all tables */
165 for (i = 0; i < 7; i++)
166 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
167
168 /* Setup L2 cache */
169 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
170 EFFECTIVE_L2_QUEUE_SIZE(7));
171 WREG32(VM_L2_CNTL2, 0);
172 WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
173 /* Setup TLB control */
174 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
175 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
176 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
177 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
178 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
179 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
180 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
181 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200182 if (rdev->gart.table.vram.robj) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100183 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
184 if (likely(r == 0)) {
185 radeon_bo_kunmap(rdev->gart.table.vram.robj);
186 radeon_bo_unpin(rdev->gart.table.vram.robj);
187 radeon_bo_unreserve(rdev->gart.table.vram.robj);
188 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200189 }
190}
191
192void rv770_pcie_gart_fini(struct radeon_device *rdev)
193{
Jerome Glissef9274562010-03-17 14:44:29 +0000194 radeon_gart_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200195 rv770_pcie_gart_disable(rdev);
196 radeon_gart_table_vram_free(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000197}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200198
199
Jerome Glisse1a029b72009-10-06 19:04:30 +0200200void rv770_agp_enable(struct radeon_device *rdev)
201{
202 u32 tmp;
203 int i;
204
205 /* Setup L2 cache */
206 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
207 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
208 EFFECTIVE_L2_QUEUE_SIZE(7));
209 WREG32(VM_L2_CNTL2, 0);
210 WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
211 /* Setup TLB control */
212 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
213 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
214 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
215 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
216 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
217 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
218 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
219 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
220 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
221 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
222 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
223 for (i = 0; i < 7; i++)
224 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
225}
226
Jerome Glissea3c19452009-10-01 18:02:13 +0200227static void rv770_mc_program(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200228{
Jerome Glissea3c19452009-10-01 18:02:13 +0200229 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000230 u32 tmp;
231 int i, j;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200232
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000233 /* Initialize HDP */
234 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
235 WREG32((0x2c14 + j), 0x00000000);
236 WREG32((0x2c18 + j), 0x00000000);
237 WREG32((0x2c1c + j), 0x00000000);
238 WREG32((0x2c20 + j), 0x00000000);
239 WREG32((0x2c24 + j), 0x00000000);
240 }
Alex Deucher812d0462010-07-26 18:51:53 -0400241 /* r7xx hw bug. Read from HDP_DEBUG1 rather
242 * than writing to HDP_REG_COHERENCY_FLUSH_CNTL
243 */
244 tmp = RREG32(HDP_DEBUG1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200245
Jerome Glissea3c19452009-10-01 18:02:13 +0200246 rv515_mc_stop(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000247 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +0200248 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200249 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000250 /* Lockout access through VGA aperture*/
251 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000252 /* Update configuration */
Jerome Glisse1a029b72009-10-06 19:04:30 +0200253 if (rdev->flags & RADEON_IS_AGP) {
254 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
255 /* VRAM before AGP */
256 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
257 rdev->mc.vram_start >> 12);
258 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
259 rdev->mc.gtt_end >> 12);
260 } else {
261 /* VRAM after AGP */
262 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
263 rdev->mc.gtt_start >> 12);
264 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
265 rdev->mc.vram_end >> 12);
266 }
267 } else {
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.vram_end >> 12);
272 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000273 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200274 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000275 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
276 WREG32(MC_VM_FB_LOCATION, tmp);
277 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
278 WREG32(HDP_NONSURFACE_INFO, (2 << 7));
Jerome Glisse46fcd2b2010-06-03 19:34:48 +0200279 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000280 if (rdev->flags & RADEON_IS_AGP) {
Jerome Glisse1a029b72009-10-06 19:04:30 +0200281 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000282 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16);
283 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
284 } else {
285 WREG32(MC_VM_AGP_BASE, 0);
286 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
287 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
288 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000289 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +0200290 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000291 }
Jerome Glissea3c19452009-10-01 18:02:13 +0200292 rv515_mc_resume(rdev, &save);
Dave Airlie698443d2009-09-18 14:16:38 +1000293 /* we need to own VRAM, so turn off the VGA renderer here
294 * to stop it overwriting our objects */
Jerome Glissed39c3b82009-09-28 18:34:43 +0200295 rv515_vga_render_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200296}
297
298
299/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000300 * CP.
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200301 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000302void r700_cp_stop(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200303{
Jerome Glissec919b372010-08-10 17:41:31 -0400304 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000305 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT));
Alex Deucher724c80e2010-08-27 18:25:25 -0400306 WREG32(SCRATCH_UMSK, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200307}
308
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000309static int rv770_cp_load_microcode(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200310{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000311 const __be32 *fw_data;
312 int i;
313
314 if (!rdev->me_fw || !rdev->pfp_fw)
315 return -EINVAL;
316
317 r700_cp_stop(rdev);
318 WREG32(CP_RB_CNTL, RB_NO_UPDATE | (15 << 8) | (3 << 0));
319
320 /* Reset cp */
321 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
322 RREG32(GRBM_SOFT_RESET);
323 mdelay(15);
324 WREG32(GRBM_SOFT_RESET, 0);
325
326 fw_data = (const __be32 *)rdev->pfp_fw->data;
327 WREG32(CP_PFP_UCODE_ADDR, 0);
328 for (i = 0; i < R700_PFP_UCODE_SIZE; i++)
329 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
330 WREG32(CP_PFP_UCODE_ADDR, 0);
331
332 fw_data = (const __be32 *)rdev->me_fw->data;
333 WREG32(CP_ME_RAM_WADDR, 0);
334 for (i = 0; i < R700_PM4_UCODE_SIZE; i++)
335 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
336
337 WREG32(CP_PFP_UCODE_ADDR, 0);
338 WREG32(CP_ME_RAM_WADDR, 0);
339 WREG32(CP_ME_RAM_RADDR, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200340 return 0;
341}
342
Alex Deucherfe251e22010-03-24 13:36:43 -0400343void r700_cp_fini(struct radeon_device *rdev)
344{
345 r700_cp_stop(rdev);
346 radeon_ring_fini(rdev);
347}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200348
349/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000350 * Core functions
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200351 */
Alex Deucherd03f5d52010-02-19 16:22:31 -0500352static u32 r700_get_tile_pipe_to_backend_map(struct radeon_device *rdev,
353 u32 num_tile_pipes,
354 u32 num_backends,
355 u32 backend_disable_mask)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200356{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000357 u32 backend_map = 0;
358 u32 enabled_backends_mask;
359 u32 enabled_backends_count;
360 u32 cur_pipe;
361 u32 swizzle_pipe[R7XX_MAX_PIPES];
362 u32 cur_backend;
363 u32 i;
Alex Deucherd03f5d52010-02-19 16:22:31 -0500364 bool force_no_swizzle;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000365
366 if (num_tile_pipes > R7XX_MAX_PIPES)
367 num_tile_pipes = R7XX_MAX_PIPES;
368 if (num_tile_pipes < 1)
369 num_tile_pipes = 1;
370 if (num_backends > R7XX_MAX_BACKENDS)
371 num_backends = R7XX_MAX_BACKENDS;
372 if (num_backends < 1)
373 num_backends = 1;
374
375 enabled_backends_mask = 0;
376 enabled_backends_count = 0;
377 for (i = 0; i < R7XX_MAX_BACKENDS; ++i) {
378 if (((backend_disable_mask >> i) & 1) == 0) {
379 enabled_backends_mask |= (1 << i);
380 ++enabled_backends_count;
381 }
382 if (enabled_backends_count == num_backends)
383 break;
384 }
385
386 if (enabled_backends_count == 0) {
387 enabled_backends_mask = 1;
388 enabled_backends_count = 1;
389 }
390
391 if (enabled_backends_count != num_backends)
392 num_backends = enabled_backends_count;
393
Alex Deucherd03f5d52010-02-19 16:22:31 -0500394 switch (rdev->family) {
395 case CHIP_RV770:
396 case CHIP_RV730:
397 force_no_swizzle = false;
398 break;
399 case CHIP_RV710:
400 case CHIP_RV740:
401 default:
402 force_no_swizzle = true;
403 break;
404 }
405
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000406 memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R7XX_MAX_PIPES);
407 switch (num_tile_pipes) {
408 case 1:
409 swizzle_pipe[0] = 0;
410 break;
411 case 2:
412 swizzle_pipe[0] = 0;
413 swizzle_pipe[1] = 1;
414 break;
415 case 3:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500416 if (force_no_swizzle) {
417 swizzle_pipe[0] = 0;
418 swizzle_pipe[1] = 1;
419 swizzle_pipe[2] = 2;
420 } else {
421 swizzle_pipe[0] = 0;
422 swizzle_pipe[1] = 2;
423 swizzle_pipe[2] = 1;
424 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000425 break;
426 case 4:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500427 if (force_no_swizzle) {
428 swizzle_pipe[0] = 0;
429 swizzle_pipe[1] = 1;
430 swizzle_pipe[2] = 2;
431 swizzle_pipe[3] = 3;
432 } else {
433 swizzle_pipe[0] = 0;
434 swizzle_pipe[1] = 2;
435 swizzle_pipe[2] = 3;
436 swizzle_pipe[3] = 1;
437 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000438 break;
439 case 5:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500440 if (force_no_swizzle) {
441 swizzle_pipe[0] = 0;
442 swizzle_pipe[1] = 1;
443 swizzle_pipe[2] = 2;
444 swizzle_pipe[3] = 3;
445 swizzle_pipe[4] = 4;
446 } else {
447 swizzle_pipe[0] = 0;
448 swizzle_pipe[1] = 2;
449 swizzle_pipe[2] = 4;
450 swizzle_pipe[3] = 1;
451 swizzle_pipe[4] = 3;
452 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000453 break;
454 case 6:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500455 if (force_no_swizzle) {
456 swizzle_pipe[0] = 0;
457 swizzle_pipe[1] = 1;
458 swizzle_pipe[2] = 2;
459 swizzle_pipe[3] = 3;
460 swizzle_pipe[4] = 4;
461 swizzle_pipe[5] = 5;
462 } else {
463 swizzle_pipe[0] = 0;
464 swizzle_pipe[1] = 2;
465 swizzle_pipe[2] = 4;
466 swizzle_pipe[3] = 5;
467 swizzle_pipe[4] = 3;
468 swizzle_pipe[5] = 1;
469 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000470 break;
471 case 7:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500472 if (force_no_swizzle) {
473 swizzle_pipe[0] = 0;
474 swizzle_pipe[1] = 1;
475 swizzle_pipe[2] = 2;
476 swizzle_pipe[3] = 3;
477 swizzle_pipe[4] = 4;
478 swizzle_pipe[5] = 5;
479 swizzle_pipe[6] = 6;
480 } else {
481 swizzle_pipe[0] = 0;
482 swizzle_pipe[1] = 2;
483 swizzle_pipe[2] = 4;
484 swizzle_pipe[3] = 6;
485 swizzle_pipe[4] = 3;
486 swizzle_pipe[5] = 1;
487 swizzle_pipe[6] = 5;
488 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000489 break;
490 case 8:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500491 if (force_no_swizzle) {
492 swizzle_pipe[0] = 0;
493 swizzle_pipe[1] = 1;
494 swizzle_pipe[2] = 2;
495 swizzle_pipe[3] = 3;
496 swizzle_pipe[4] = 4;
497 swizzle_pipe[5] = 5;
498 swizzle_pipe[6] = 6;
499 swizzle_pipe[7] = 7;
500 } else {
501 swizzle_pipe[0] = 0;
502 swizzle_pipe[1] = 2;
503 swizzle_pipe[2] = 4;
504 swizzle_pipe[3] = 6;
505 swizzle_pipe[4] = 3;
506 swizzle_pipe[5] = 1;
507 swizzle_pipe[6] = 7;
508 swizzle_pipe[7] = 5;
509 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000510 break;
511 }
512
513 cur_backend = 0;
514 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
515 while (((1 << cur_backend) & enabled_backends_mask) == 0)
516 cur_backend = (cur_backend + 1) % R7XX_MAX_BACKENDS;
517
518 backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
519
520 cur_backend = (cur_backend + 1) % R7XX_MAX_BACKENDS;
521 }
522
523 return backend_map;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200524}
525
Alex Deucher9535ab72010-11-22 17:56:18 -0500526static void rv770_program_channel_remap(struct radeon_device *rdev)
527{
528 u32 tcp_chan_steer, mc_shared_chremap, tmp;
529 bool force_no_swizzle;
530
531 switch (rdev->family) {
532 case CHIP_RV770:
533 case CHIP_RV730:
534 force_no_swizzle = false;
535 break;
536 case CHIP_RV710:
537 case CHIP_RV740:
538 default:
539 force_no_swizzle = true;
540 break;
541 }
542
543 tmp = RREG32(MC_SHARED_CHMAP);
544 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
545 case 0:
546 case 1:
547 default:
548 /* default mapping */
549 mc_shared_chremap = 0x00fac688;
550 break;
551 case 2:
552 case 3:
553 if (force_no_swizzle)
554 mc_shared_chremap = 0x00fac688;
555 else
556 mc_shared_chremap = 0x00bbc298;
557 break;
558 }
559
560 if (rdev->family == CHIP_RV740)
561 tcp_chan_steer = 0x00ef2a60;
562 else
563 tcp_chan_steer = 0x00fac688;
564
565 WREG32(TCP_CHAN_STEER, tcp_chan_steer);
566 WREG32(MC_SHARED_CHREMAP, mc_shared_chremap);
567}
568
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000569static void rv770_gpu_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200570{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000571 int i, j, num_qd_pipes;
Alex Deucherd03f5d52010-02-19 16:22:31 -0500572 u32 ta_aux_cntl;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000573 u32 sx_debug_1;
574 u32 smx_dc_ctl0;
Alex Deucherd03f5d52010-02-19 16:22:31 -0500575 u32 db_debug3;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000576 u32 num_gs_verts_per_thread;
577 u32 vgt_gs_per_es;
578 u32 gs_prim_buffer_depth = 0;
579 u32 sq_ms_fifo_sizes;
580 u32 sq_config;
581 u32 sq_thread_resource_mgmt;
582 u32 hdp_host_path_cntl;
583 u32 sq_dyn_gpr_size_simd_ab_0;
584 u32 backend_map;
585 u32 gb_tiling_config = 0;
586 u32 cc_rb_backend_disable = 0;
587 u32 cc_gc_shader_pipe_config = 0;
588 u32 mc_arb_ramcfg;
589 u32 db_debug4;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200590
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000591 /* setup chip specs */
592 switch (rdev->family) {
593 case CHIP_RV770:
594 rdev->config.rv770.max_pipes = 4;
595 rdev->config.rv770.max_tile_pipes = 8;
596 rdev->config.rv770.max_simds = 10;
597 rdev->config.rv770.max_backends = 4;
598 rdev->config.rv770.max_gprs = 256;
599 rdev->config.rv770.max_threads = 248;
600 rdev->config.rv770.max_stack_entries = 512;
601 rdev->config.rv770.max_hw_contexts = 8;
602 rdev->config.rv770.max_gs_threads = 16 * 2;
603 rdev->config.rv770.sx_max_export_size = 128;
604 rdev->config.rv770.sx_max_export_pos_size = 16;
605 rdev->config.rv770.sx_max_export_smx_size = 112;
606 rdev->config.rv770.sq_num_cf_insts = 2;
607
608 rdev->config.rv770.sx_num_of_sets = 7;
609 rdev->config.rv770.sc_prim_fifo_size = 0xF9;
610 rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
611 rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
612 break;
613 case CHIP_RV730:
614 rdev->config.rv770.max_pipes = 2;
615 rdev->config.rv770.max_tile_pipes = 4;
616 rdev->config.rv770.max_simds = 8;
617 rdev->config.rv770.max_backends = 2;
618 rdev->config.rv770.max_gprs = 128;
619 rdev->config.rv770.max_threads = 248;
620 rdev->config.rv770.max_stack_entries = 256;
621 rdev->config.rv770.max_hw_contexts = 8;
622 rdev->config.rv770.max_gs_threads = 16 * 2;
623 rdev->config.rv770.sx_max_export_size = 256;
624 rdev->config.rv770.sx_max_export_pos_size = 32;
625 rdev->config.rv770.sx_max_export_smx_size = 224;
626 rdev->config.rv770.sq_num_cf_insts = 2;
627
628 rdev->config.rv770.sx_num_of_sets = 7;
629 rdev->config.rv770.sc_prim_fifo_size = 0xf9;
630 rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
631 rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
632 if (rdev->config.rv770.sx_max_export_pos_size > 16) {
633 rdev->config.rv770.sx_max_export_pos_size -= 16;
634 rdev->config.rv770.sx_max_export_smx_size += 16;
635 }
636 break;
637 case CHIP_RV710:
638 rdev->config.rv770.max_pipes = 2;
639 rdev->config.rv770.max_tile_pipes = 2;
640 rdev->config.rv770.max_simds = 2;
641 rdev->config.rv770.max_backends = 1;
642 rdev->config.rv770.max_gprs = 256;
643 rdev->config.rv770.max_threads = 192;
644 rdev->config.rv770.max_stack_entries = 256;
645 rdev->config.rv770.max_hw_contexts = 4;
646 rdev->config.rv770.max_gs_threads = 8 * 2;
647 rdev->config.rv770.sx_max_export_size = 128;
648 rdev->config.rv770.sx_max_export_pos_size = 16;
649 rdev->config.rv770.sx_max_export_smx_size = 112;
650 rdev->config.rv770.sq_num_cf_insts = 1;
651
652 rdev->config.rv770.sx_num_of_sets = 7;
653 rdev->config.rv770.sc_prim_fifo_size = 0x40;
654 rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
655 rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
656 break;
657 case CHIP_RV740:
658 rdev->config.rv770.max_pipes = 4;
659 rdev->config.rv770.max_tile_pipes = 4;
660 rdev->config.rv770.max_simds = 8;
661 rdev->config.rv770.max_backends = 4;
662 rdev->config.rv770.max_gprs = 256;
663 rdev->config.rv770.max_threads = 248;
664 rdev->config.rv770.max_stack_entries = 512;
665 rdev->config.rv770.max_hw_contexts = 8;
666 rdev->config.rv770.max_gs_threads = 16 * 2;
667 rdev->config.rv770.sx_max_export_size = 256;
668 rdev->config.rv770.sx_max_export_pos_size = 32;
669 rdev->config.rv770.sx_max_export_smx_size = 224;
670 rdev->config.rv770.sq_num_cf_insts = 2;
671
672 rdev->config.rv770.sx_num_of_sets = 7;
673 rdev->config.rv770.sc_prim_fifo_size = 0x100;
674 rdev->config.rv770.sc_hiz_tile_fifo_size = 0x30;
675 rdev->config.rv770.sc_earlyz_tile_fifo_fize = 0x130;
676
677 if (rdev->config.rv770.sx_max_export_pos_size > 16) {
678 rdev->config.rv770.sx_max_export_pos_size -= 16;
679 rdev->config.rv770.sx_max_export_smx_size += 16;
680 }
681 break;
682 default:
683 break;
684 }
685
686 /* Initialize HDP */
687 j = 0;
688 for (i = 0; i < 32; i++) {
689 WREG32((0x2c14 + j), 0x00000000);
690 WREG32((0x2c18 + j), 0x00000000);
691 WREG32((0x2c1c + j), 0x00000000);
692 WREG32((0x2c20 + j), 0x00000000);
693 WREG32((0x2c24 + j), 0x00000000);
694 j += 0x18;
695 }
696
697 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
698
699 /* setup tiling, simd, pipe config */
700 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
701
702 switch (rdev->config.rv770.max_tile_pipes) {
703 case 1:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500704 default:
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000705 gb_tiling_config |= PIPE_TILING(0);
706 break;
707 case 2:
708 gb_tiling_config |= PIPE_TILING(1);
709 break;
710 case 4:
711 gb_tiling_config |= PIPE_TILING(2);
712 break;
713 case 8:
714 gb_tiling_config |= PIPE_TILING(3);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000715 break;
716 }
Alex Deucherd03f5d52010-02-19 16:22:31 -0500717 rdev->config.rv770.tiling_npipes = rdev->config.rv770.max_tile_pipes;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000718
719 if (rdev->family == CHIP_RV770)
720 gb_tiling_config |= BANK_TILING(1);
721 else
Alex Deuchere29649d2009-11-03 10:04:01 -0500722 gb_tiling_config |= BANK_TILING((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Jerome Glisse961fb592010-02-10 22:30:05 +0000723 rdev->config.rv770.tiling_nbanks = 4 << ((gb_tiling_config >> 4) & 0x3);
Alex Deucher881fe6c2010-10-18 23:54:56 -0400724 gb_tiling_config |= GROUP_SIZE((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
725 if ((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT)
726 rdev->config.rv770.tiling_group_size = 512;
727 else
728 rdev->config.rv770.tiling_group_size = 256;
Alex Deuchere29649d2009-11-03 10:04:01 -0500729 if (((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT) > 3) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000730 gb_tiling_config |= ROW_TILING(3);
731 gb_tiling_config |= SAMPLE_SPLIT(3);
732 } else {
733 gb_tiling_config |=
734 ROW_TILING(((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT));
735 gb_tiling_config |=
736 SAMPLE_SPLIT(((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT));
737 }
738
739 gb_tiling_config |= BANK_SWAPS(1);
740
Alex Deucherd03f5d52010-02-19 16:22:31 -0500741 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
742 cc_rb_backend_disable |=
743 BACKEND_DISABLE((R7XX_MAX_BACKENDS_MASK << rdev->config.rv770.max_backends) & R7XX_MAX_BACKENDS_MASK);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000744
Alex Deucherd03f5d52010-02-19 16:22:31 -0500745 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
746 cc_gc_shader_pipe_config |=
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000747 INACTIVE_QD_PIPES((R7XX_MAX_PIPES_MASK << rdev->config.rv770.max_pipes) & R7XX_MAX_PIPES_MASK);
748 cc_gc_shader_pipe_config |=
749 INACTIVE_SIMDS((R7XX_MAX_SIMDS_MASK << rdev->config.rv770.max_simds) & R7XX_MAX_SIMDS_MASK);
750
Alex Deucherd03f5d52010-02-19 16:22:31 -0500751 if (rdev->family == CHIP_RV740)
752 backend_map = 0x28;
753 else
754 backend_map = r700_get_tile_pipe_to_backend_map(rdev,
755 rdev->config.rv770.max_tile_pipes,
756 (R7XX_MAX_BACKENDS -
757 r600_count_pipe_bits((cc_rb_backend_disable &
758 R7XX_MAX_BACKENDS_MASK) >> 16)),
759 (cc_rb_backend_disable >> 16));
Alex Deucherd03f5d52010-02-19 16:22:31 -0500760
Alex Deuchere7aeeba2010-06-04 13:10:12 -0400761 rdev->config.rv770.tile_config = gb_tiling_config;
762 gb_tiling_config |= BACKEND_MAP(backend_map);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000763
764 WREG32(GB_TILING_CONFIG, gb_tiling_config);
765 WREG32(DCP_TILING_CONFIG, (gb_tiling_config & 0xffff));
766 WREG32(HDP_TILING_CONFIG, (gb_tiling_config & 0xffff));
767
Alex Deucher9535ab72010-11-22 17:56:18 -0500768 rv770_program_channel_remap(rdev);
769
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000770 WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
771 WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
Alex Deucherf867c60d2010-03-05 14:50:37 -0500772 WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
Alex Deucherd03f5d52010-02-19 16:22:31 -0500773 WREG32(CC_SYS_RB_BACKEND_DISABLE, cc_rb_backend_disable);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000774
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000775 WREG32(CGTS_SYS_TCC_DISABLE, 0);
776 WREG32(CGTS_TCC_DISABLE, 0);
Alex Deucherf867c60d2010-03-05 14:50:37 -0500777 WREG32(CGTS_USER_SYS_TCC_DISABLE, 0);
778 WREG32(CGTS_USER_TCC_DISABLE, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000779
780 num_qd_pipes =
Alex Deucherd03f5d52010-02-19 16:22:31 -0500781 R7XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000782 WREG32(VGT_OUT_DEALLOC_CNTL, (num_qd_pipes * 4) & DEALLOC_DIST_MASK);
783 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((num_qd_pipes * 4) - 2) & VTX_REUSE_DEPTH_MASK);
784
785 /* set HW defaults for 3D engine */
786 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
Alex Deuchere29649d2009-11-03 10:04:01 -0500787 ROQ_IB2_START(0x2b)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000788
789 WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30));
790
Alex Deucherd03f5d52010-02-19 16:22:31 -0500791 ta_aux_cntl = RREG32(TA_CNTL_AUX);
792 WREG32(TA_CNTL_AUX, ta_aux_cntl | DISABLE_CUBE_ANISO);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000793
794 sx_debug_1 = RREG32(SX_DEBUG_1);
795 sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
796 WREG32(SX_DEBUG_1, sx_debug_1);
797
798 smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
799 smx_dc_ctl0 &= ~CACHE_DEPTH(0x1ff);
800 smx_dc_ctl0 |= CACHE_DEPTH((rdev->config.rv770.sx_num_of_sets * 64) - 1);
801 WREG32(SMX_DC_CTL0, smx_dc_ctl0);
802
Alex Deucherd03f5d52010-02-19 16:22:31 -0500803 if (rdev->family != CHIP_RV740)
804 WREG32(SMX_EVENT_CTL, (ES_FLUSH_CTL(4) |
805 GS_FLUSH_CTL(4) |
806 ACK_FLUSH_CTL(3) |
807 SYNC_FLUSH_CTL));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000808
Alex Deucherd03f5d52010-02-19 16:22:31 -0500809 db_debug3 = RREG32(DB_DEBUG3);
810 db_debug3 &= ~DB_CLK_OFF_DELAY(0x1f);
811 switch (rdev->family) {
812 case CHIP_RV770:
813 case CHIP_RV740:
814 db_debug3 |= DB_CLK_OFF_DELAY(0x1f);
815 break;
816 case CHIP_RV710:
817 case CHIP_RV730:
818 default:
819 db_debug3 |= DB_CLK_OFF_DELAY(2);
820 break;
821 }
822 WREG32(DB_DEBUG3, db_debug3);
823
824 if (rdev->family != CHIP_RV770) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000825 db_debug4 = RREG32(DB_DEBUG4);
826 db_debug4 |= DISABLE_TILE_COVERED_FOR_PS_ITER;
827 WREG32(DB_DEBUG4, db_debug4);
828 }
829
830 WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.rv770.sx_max_export_size / 4) - 1) |
Alex Deuchere29649d2009-11-03 10:04:01 -0500831 POSITION_BUFFER_SIZE((rdev->config.rv770.sx_max_export_pos_size / 4) - 1) |
832 SMX_BUFFER_SIZE((rdev->config.rv770.sx_max_export_smx_size / 4) - 1)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000833
834 WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.rv770.sc_prim_fifo_size) |
Alex Deuchere29649d2009-11-03 10:04:01 -0500835 SC_HIZ_TILE_FIFO_SIZE(rdev->config.rv770.sc_hiz_tile_fifo_size) |
836 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.rv770.sc_earlyz_tile_fifo_fize)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000837
838 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
839
840 WREG32(VGT_NUM_INSTANCES, 1);
841
842 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
843
844 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
845
846 WREG32(CP_PERFMON_CNTL, 0);
847
848 sq_ms_fifo_sizes = (CACHE_FIFO_SIZE(16 * rdev->config.rv770.sq_num_cf_insts) |
849 DONE_FIFO_HIWATER(0xe0) |
850 ALU_UPDATE_FIFO_HIWATER(0x8));
851 switch (rdev->family) {
852 case CHIP_RV770:
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000853 case CHIP_RV730:
854 case CHIP_RV710:
Alex Deucherd03f5d52010-02-19 16:22:31 -0500855 sq_ms_fifo_sizes |= FETCH_FIFO_HIWATER(0x1);
856 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000857 case CHIP_RV740:
858 default:
859 sq_ms_fifo_sizes |= FETCH_FIFO_HIWATER(0x4);
860 break;
861 }
862 WREG32(SQ_MS_FIFO_SIZES, sq_ms_fifo_sizes);
863
864 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
865 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
866 */
867 sq_config = RREG32(SQ_CONFIG);
868 sq_config &= ~(PS_PRIO(3) |
869 VS_PRIO(3) |
870 GS_PRIO(3) |
871 ES_PRIO(3));
872 sq_config |= (DX9_CONSTS |
873 VC_ENABLE |
874 EXPORT_SRC_C |
875 PS_PRIO(0) |
876 VS_PRIO(1) |
877 GS_PRIO(2) |
878 ES_PRIO(3));
879 if (rdev->family == CHIP_RV710)
880 /* no vertex cache */
881 sq_config &= ~VC_ENABLE;
882
883 WREG32(SQ_CONFIG, sq_config);
884
885 WREG32(SQ_GPR_RESOURCE_MGMT_1, (NUM_PS_GPRS((rdev->config.rv770.max_gprs * 24)/64) |
Dave Airliefe62e1a2009-09-21 14:06:30 +1000886 NUM_VS_GPRS((rdev->config.rv770.max_gprs * 24)/64) |
887 NUM_CLAUSE_TEMP_GPRS(((rdev->config.rv770.max_gprs * 24)/64)/2)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000888
889 WREG32(SQ_GPR_RESOURCE_MGMT_2, (NUM_GS_GPRS((rdev->config.rv770.max_gprs * 7)/64) |
Dave Airliefe62e1a2009-09-21 14:06:30 +1000890 NUM_ES_GPRS((rdev->config.rv770.max_gprs * 7)/64)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000891
892 sq_thread_resource_mgmt = (NUM_PS_THREADS((rdev->config.rv770.max_threads * 4)/8) |
893 NUM_VS_THREADS((rdev->config.rv770.max_threads * 2)/8) |
894 NUM_ES_THREADS((rdev->config.rv770.max_threads * 1)/8));
895 if (((rdev->config.rv770.max_threads * 1) / 8) > rdev->config.rv770.max_gs_threads)
896 sq_thread_resource_mgmt |= NUM_GS_THREADS(rdev->config.rv770.max_gs_threads);
897 else
898 sq_thread_resource_mgmt |= NUM_GS_THREADS((rdev->config.rv770.max_gs_threads * 1)/8);
899 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
900
901 WREG32(SQ_STACK_RESOURCE_MGMT_1, (NUM_PS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4) |
902 NUM_VS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4)));
903
904 WREG32(SQ_STACK_RESOURCE_MGMT_2, (NUM_GS_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4) |
905 NUM_ES_STACK_ENTRIES((rdev->config.rv770.max_stack_entries * 1)/4)));
906
907 sq_dyn_gpr_size_simd_ab_0 = (SIMDA_RING0((rdev->config.rv770.max_gprs * 38)/64) |
908 SIMDA_RING1((rdev->config.rv770.max_gprs * 38)/64) |
909 SIMDB_RING0((rdev->config.rv770.max_gprs * 38)/64) |
910 SIMDB_RING1((rdev->config.rv770.max_gprs * 38)/64));
911
912 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_0, sq_dyn_gpr_size_simd_ab_0);
913 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_1, sq_dyn_gpr_size_simd_ab_0);
914 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_2, sq_dyn_gpr_size_simd_ab_0);
915 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_3, sq_dyn_gpr_size_simd_ab_0);
916 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_4, sq_dyn_gpr_size_simd_ab_0);
917 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_5, sq_dyn_gpr_size_simd_ab_0);
918 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_6, sq_dyn_gpr_size_simd_ab_0);
919 WREG32(SQ_DYN_GPR_SIZE_SIMD_AB_7, sq_dyn_gpr_size_simd_ab_0);
920
921 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
Dave Airliefe62e1a2009-09-21 14:06:30 +1000922 FORCE_EOV_MAX_REZ_CNT(255)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000923
924 if (rdev->family == CHIP_RV710)
925 WREG32(VGT_CACHE_INVALIDATION, (CACHE_INVALIDATION(TC_ONLY) |
Dave Airliefe62e1a2009-09-21 14:06:30 +1000926 AUTO_INVLD_EN(ES_AND_GS_AUTO)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000927 else
928 WREG32(VGT_CACHE_INVALIDATION, (CACHE_INVALIDATION(VC_AND_TC) |
Dave Airliefe62e1a2009-09-21 14:06:30 +1000929 AUTO_INVLD_EN(ES_AND_GS_AUTO)));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000930
931 switch (rdev->family) {
932 case CHIP_RV770:
933 case CHIP_RV730:
934 case CHIP_RV740:
935 gs_prim_buffer_depth = 384;
936 break;
937 case CHIP_RV710:
938 gs_prim_buffer_depth = 128;
939 break;
940 default:
941 break;
942 }
943
944 num_gs_verts_per_thread = rdev->config.rv770.max_pipes * 16;
945 vgt_gs_per_es = gs_prim_buffer_depth + num_gs_verts_per_thread;
946 /* Max value for this is 256 */
947 if (vgt_gs_per_es > 256)
948 vgt_gs_per_es = 256;
949
950 WREG32(VGT_ES_PER_GS, 128);
951 WREG32(VGT_GS_PER_ES, vgt_gs_per_es);
952 WREG32(VGT_GS_PER_VS, 2);
953
954 /* more default values. 2D/3D driver should adjust as needed */
955 WREG32(VGT_GS_VERTEX_REUSE, 16);
956 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
957 WREG32(VGT_STRMOUT_EN, 0);
958 WREG32(SX_MISC, 0);
959 WREG32(PA_SC_MODE_CNTL, 0);
960 WREG32(PA_SC_EDGERULE, 0xaaaaaaaa);
961 WREG32(PA_SC_AA_CONFIG, 0);
962 WREG32(PA_SC_CLIPRECT_RULE, 0xffff);
963 WREG32(PA_SC_LINE_STIPPLE, 0);
964 WREG32(SPI_INPUT_Z, 0);
965 WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
966 WREG32(CB_COLOR7_FRAG, 0);
967
968 /* clear render buffer base addresses */
969 WREG32(CB_COLOR0_BASE, 0);
970 WREG32(CB_COLOR1_BASE, 0);
971 WREG32(CB_COLOR2_BASE, 0);
972 WREG32(CB_COLOR3_BASE, 0);
973 WREG32(CB_COLOR4_BASE, 0);
974 WREG32(CB_COLOR5_BASE, 0);
975 WREG32(CB_COLOR6_BASE, 0);
976 WREG32(CB_COLOR7_BASE, 0);
977
978 WREG32(TCP_CNTL, 0);
979
980 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
981 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
982
983 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
984
985 WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
986 NUM_CLIP_SEQ(3)));
987
988}
989
Alex Deucher87cbf8f2010-08-27 13:59:54 -0400990static int rv770_vram_scratch_init(struct radeon_device *rdev)
991{
992 int r;
993 u64 gpu_addr;
994
995 if (rdev->vram_scratch.robj == NULL) {
996 r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE,
Alex Deucher268b2512010-11-17 19:00:26 -0500997 PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
998 &rdev->vram_scratch.robj);
Alex Deucher87cbf8f2010-08-27 13:59:54 -0400999 if (r) {
1000 return r;
1001 }
1002 }
1003
1004 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1005 if (unlikely(r != 0))
1006 return r;
1007 r = radeon_bo_pin(rdev->vram_scratch.robj,
1008 RADEON_GEM_DOMAIN_VRAM, &gpu_addr);
1009 if (r) {
1010 radeon_bo_unreserve(rdev->vram_scratch.robj);
1011 return r;
1012 }
1013 r = radeon_bo_kmap(rdev->vram_scratch.robj,
1014 (void **)&rdev->vram_scratch.ptr);
1015 if (r)
1016 radeon_bo_unpin(rdev->vram_scratch.robj);
1017 radeon_bo_unreserve(rdev->vram_scratch.robj);
1018
1019 return r;
1020}
1021
1022static void rv770_vram_scratch_fini(struct radeon_device *rdev)
1023{
1024 int r;
1025
1026 if (rdev->vram_scratch.robj == NULL) {
1027 return;
1028 }
1029 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1030 if (likely(r == 0)) {
1031 radeon_bo_kunmap(rdev->vram_scratch.robj);
1032 radeon_bo_unpin(rdev->vram_scratch.robj);
1033 radeon_bo_unreserve(rdev->vram_scratch.robj);
1034 }
1035 radeon_bo_unref(&rdev->vram_scratch.robj);
1036}
1037
Alex Deucher0ef0c1f2010-11-22 17:56:26 -05001038void r700_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
1039{
1040 u64 size_bf, size_af;
1041
1042 if (mc->mc_vram_size > 0xE0000000) {
1043 /* leave room for at least 512M GTT */
1044 dev_warn(rdev->dev, "limiting VRAM\n");
1045 mc->real_vram_size = 0xE0000000;
1046 mc->mc_vram_size = 0xE0000000;
1047 }
1048 if (rdev->flags & RADEON_IS_AGP) {
1049 size_bf = mc->gtt_start;
1050 size_af = 0xFFFFFFFF - mc->gtt_end + 1;
1051 if (size_bf > size_af) {
1052 if (mc->mc_vram_size > size_bf) {
1053 dev_warn(rdev->dev, "limiting VRAM\n");
1054 mc->real_vram_size = size_bf;
1055 mc->mc_vram_size = size_bf;
1056 }
1057 mc->vram_start = mc->gtt_start - mc->mc_vram_size;
1058 } else {
1059 if (mc->mc_vram_size > size_af) {
1060 dev_warn(rdev->dev, "limiting VRAM\n");
1061 mc->real_vram_size = size_af;
1062 mc->mc_vram_size = size_af;
1063 }
1064 mc->vram_start = mc->gtt_end;
1065 }
1066 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
1067 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
1068 mc->mc_vram_size >> 20, mc->vram_start,
1069 mc->vram_end, mc->real_vram_size >> 20);
1070 } else {
Alex Deucherb4183e32010-12-15 11:04:10 -05001071 radeon_vram_location(rdev, &rdev->mc, 0);
Alex Deucher0ef0c1f2010-11-22 17:56:26 -05001072 rdev->mc.gtt_base_align = 0;
1073 radeon_gtt_location(rdev, mc);
1074 }
1075}
1076
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001077int rv770_mc_init(struct radeon_device *rdev)
1078{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001079 u32 tmp;
Alex Deucher5885b7a2009-10-19 17:23:33 -04001080 int chansize, numchan;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001081
1082 /* Get VRAM informations */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001083 rdev->mc.vram_is_ddr = true;
Alex Deucher5885b7a2009-10-19 17:23:33 -04001084 tmp = RREG32(MC_ARB_RAMCFG);
1085 if (tmp & CHANSIZE_OVERRIDE) {
1086 chansize = 16;
1087 } else if (tmp & CHANSIZE_MASK) {
1088 chansize = 64;
1089 } else {
1090 chansize = 32;
1091 }
1092 tmp = RREG32(MC_SHARED_CHMAP);
1093 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1094 case 0:
1095 default:
1096 numchan = 1;
1097 break;
1098 case 1:
1099 numchan = 2;
1100 break;
1101 case 2:
1102 numchan = 4;
1103 break;
1104 case 3:
1105 numchan = 8;
1106 break;
1107 }
1108 rdev->mc.vram_width = numchan * chansize;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001109 /* Could aper size report 0 ? */
Jordan Crouse01d73a62010-05-27 13:40:24 -06001110 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
1111 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001112 /* Setup GPU memory space */
1113 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
1114 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
Jerome Glisse51e5fcd2010-02-19 14:33:54 +00001115 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Jerome Glissec919b372010-08-10 17:41:31 -04001116 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
Alex Deucher0ef0c1f2010-11-22 17:56:26 -05001117 r700_vram_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -04001118 radeon_update_bandwidth_info(rdev);
1119
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001120 return 0;
1121}
Jerome Glissed594e462010-02-17 21:54:29 +00001122
Dave Airliefc30b8e2009-09-18 15:19:37 +10001123static int rv770_startup(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001124{
1125 int r;
1126
Alex Deucher779720a2009-12-09 19:31:44 -05001127 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
1128 r = r600_init_microcode(rdev);
1129 if (r) {
1130 DRM_ERROR("Failed to load firmware!\n");
1131 return r;
1132 }
1133 }
1134
Jerome Glissea3c19452009-10-01 18:02:13 +02001135 rv770_mc_program(rdev);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001136 if (rdev->flags & RADEON_IS_AGP) {
1137 rv770_agp_enable(rdev);
1138 } else {
1139 r = rv770_pcie_gart_enable(rdev);
1140 if (r)
1141 return r;
1142 }
Alex Deucher87cbf8f2010-08-27 13:59:54 -04001143 r = rv770_vram_scratch_init(rdev);
1144 if (r)
1145 return r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001146 rv770_gpu_init(rdev);
Jerome Glissec38c7b62010-02-04 17:27:27 +01001147 r = r600_blit_init(rdev);
1148 if (r) {
1149 r600_blit_fini(rdev);
1150 rdev->asic->copy = NULL;
1151 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
1152 }
Alex Deucherb70d6bb2010-08-06 21:36:58 -04001153
Alex Deucher724c80e2010-08-27 18:25:25 -04001154 /* allocate wb buffer */
1155 r = radeon_wb_init(rdev);
1156 if (r)
1157 return r;
1158
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001159 /* Enable IRQ */
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001160 r = r600_irq_init(rdev);
1161 if (r) {
1162 DRM_ERROR("radeon: IH init failed (%d).\n", r);
1163 radeon_irq_kms_fini(rdev);
1164 return r;
1165 }
1166 r600_irq_set(rdev);
1167
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001168 r = radeon_ring_init(rdev, rdev->cp.ring_size);
1169 if (r)
1170 return r;
1171 r = rv770_cp_load_microcode(rdev);
1172 if (r)
1173 return r;
1174 r = r600_cp_resume(rdev);
1175 if (r)
1176 return r;
Alex Deucher724c80e2010-08-27 18:25:25 -04001177
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001178 return 0;
1179}
1180
Dave Airliefc30b8e2009-09-18 15:19:37 +10001181int rv770_resume(struct radeon_device *rdev)
1182{
1183 int r;
1184
Jerome Glisse1a029b72009-10-06 19:04:30 +02001185 /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
1186 * posting will perform necessary task to bring back GPU into good
1187 * shape.
1188 */
Dave Airliefc30b8e2009-09-18 15:19:37 +10001189 /* post card */
Jerome Glissee7d40b92009-10-01 18:02:15 +02001190 atom_asic_init(rdev->mode_info.atom_context);
Dave Airliefc30b8e2009-09-18 15:19:37 +10001191
1192 r = rv770_startup(rdev);
1193 if (r) {
1194 DRM_ERROR("r600 startup failed on resume\n");
1195 return r;
1196 }
1197
Jerome Glisse62a8ea32009-10-01 18:02:11 +02001198 r = r600_ib_test(rdev);
Dave Airliefc30b8e2009-09-18 15:19:37 +10001199 if (r) {
1200 DRM_ERROR("radeon: failled testing IB (%d).\n", r);
1201 return r;
1202 }
Rafał Miłecki8a8c6e72010-03-06 13:03:36 +00001203
1204 r = r600_audio_init(rdev);
1205 if (r) {
1206 dev_err(rdev->dev, "radeon: audio init failed\n");
1207 return r;
1208 }
1209
Dave Airliefc30b8e2009-09-18 15:19:37 +10001210 return r;
1211
1212}
1213
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001214int rv770_suspend(struct radeon_device *rdev)
1215{
Jerome Glisse4c788672009-11-20 14:29:23 +01001216 int r;
1217
Rafał Miłecki8a8c6e72010-03-06 13:03:36 +00001218 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001219 /* FIXME: we should wait for ring to be empty */
1220 r700_cp_stop(rdev);
Dave Airlie4153e582009-09-18 18:41:24 +10001221 rdev->cp.ready = false;
Jerome Glisse0c452492010-01-15 14:44:37 +01001222 r600_irq_suspend(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04001223 radeon_wb_disable(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001224 rv770_pcie_gart_disable(rdev);
Dave Airlie4153e582009-09-18 18:41:24 +10001225 /* unpin shaders bo */
Jerome Glisse30d2d9a2010-01-13 10:29:27 +01001226 if (rdev->r600_blit.shader_obj) {
1227 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
1228 if (likely(r == 0)) {
1229 radeon_bo_unpin(rdev->r600_blit.shader_obj);
1230 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
1231 }
Jerome Glisse4c788672009-11-20 14:29:23 +01001232 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001233 return 0;
1234}
1235
1236/* Plan is to move initialization in that function and use
1237 * helper function so that radeon_device_init pretty much
1238 * do nothing more than calling asic specific function. This
1239 * should also allow to remove a bunch of callback function
1240 * like vram_info.
1241 */
1242int rv770_init(struct radeon_device *rdev)
1243{
1244 int r;
1245
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001246 r = radeon_dummy_page_init(rdev);
1247 if (r)
1248 return r;
1249 /* This don't do much */
1250 r = radeon_gem_init(rdev);
1251 if (r)
1252 return r;
1253 /* Read BIOS */
1254 if (!radeon_get_bios(rdev)) {
1255 if (ASIC_IS_AVIVO(rdev))
1256 return -EINVAL;
1257 }
1258 /* Must be an ATOMBIOS */
Jerome Glissee7d40b92009-10-01 18:02:15 +02001259 if (!rdev->is_atom_bios) {
1260 dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001261 return -EINVAL;
Jerome Glissee7d40b92009-10-01 18:02:15 +02001262 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001263 r = radeon_atombios_init(rdev);
1264 if (r)
1265 return r;
1266 /* Post card if necessary */
Dave Airlie72542d72009-12-01 14:06:31 +10001267 if (!r600_card_posted(rdev)) {
1268 if (!rdev->bios) {
1269 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
1270 return -EINVAL;
1271 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001272 DRM_INFO("GPU not posted. posting now...\n");
1273 atom_asic_init(rdev->mode_info.atom_context);
1274 }
1275 /* Initialize scratch registers */
1276 r600_scratch_init(rdev);
1277 /* Initialize surface registers */
1278 radeon_surface_init(rdev);
Rafał Miłecki74338742009-11-03 00:53:02 +01001279 /* Initialize clocks */
Michel Dänzer5e6dde72009-09-17 09:42:28 +02001280 radeon_get_clock_info(rdev->ddev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001281 /* Fence driver */
1282 r = radeon_fence_driver_init(rdev);
1283 if (r)
1284 return r;
Jerome Glissed594e462010-02-17 21:54:29 +00001285 /* initialize AGP */
Jerome Glisse700a0cc2010-01-13 15:16:38 +01001286 if (rdev->flags & RADEON_IS_AGP) {
1287 r = radeon_agp_init(rdev);
1288 if (r)
1289 radeon_agp_disable(rdev);
1290 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001291 r = rv770_mc_init(rdev);
Jerome Glisseb574f252009-10-06 19:04:29 +02001292 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001293 return r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001294 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01001295 r = radeon_bo_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001296 if (r)
1297 return r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001298
1299 r = radeon_irq_kms_init(rdev);
1300 if (r)
1301 return r;
1302
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001303 rdev->cp.ring_obj = NULL;
1304 r600_ring_init(rdev, 1024 * 1024);
1305
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001306 rdev->ih.ring_obj = NULL;
1307 r600_ih_ring_init(rdev, 64 * 1024);
1308
Jerome Glisse4aac0472009-09-14 18:29:49 +02001309 r = r600_pcie_gart_init(rdev);
1310 if (r)
1311 return r;
1312
Alex Deucher779720a2009-12-09 19:31:44 -05001313 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10001314 r = rv770_startup(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001315 if (r) {
Jerome Glisse655efd32010-02-02 11:51:45 +01001316 dev_err(rdev->dev, "disabling GPU acceleration\n");
Alex Deucherfe251e22010-03-24 13:36:43 -04001317 r700_cp_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01001318 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04001319 radeon_wb_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01001320 radeon_irq_kms_fini(rdev);
Jerome Glisse75c81292009-10-01 18:02:14 +02001321 rv770_pcie_gart_fini(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +02001322 rdev->accel_working = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001323 }
Jerome Glisse733289c2009-09-16 15:24:21 +02001324 if (rdev->accel_working) {
Jerome Glisse733289c2009-09-16 15:24:21 +02001325 r = radeon_ib_pool_init(rdev);
1326 if (r) {
Jerome Glissedb963802010-01-17 21:21:56 +01001327 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisse733289c2009-09-16 15:24:21 +02001328 rdev->accel_working = false;
Jerome Glissedb963802010-01-17 21:21:56 +01001329 } else {
1330 r = r600_ib_test(rdev);
1331 if (r) {
1332 dev_err(rdev->dev, "IB test failed (%d).\n", r);
1333 rdev->accel_working = false;
1334 }
Jerome Glisse733289c2009-09-16 15:24:21 +02001335 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001336 }
Rafał Miłecki8a8c6e72010-03-06 13:03:36 +00001337
1338 r = r600_audio_init(rdev);
1339 if (r) {
1340 dev_err(rdev->dev, "radeon: audio init failed\n");
1341 return r;
1342 }
1343
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001344 return 0;
1345}
1346
1347void rv770_fini(struct radeon_device *rdev)
1348{
1349 r600_blit_fini(rdev);
Alex Deucherfe251e22010-03-24 13:36:43 -04001350 r700_cp_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001351 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04001352 radeon_wb_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001353 radeon_irq_kms_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001354 rv770_pcie_gart_fini(rdev);
Alex Deucher87cbf8f2010-08-27 13:59:54 -04001355 rv770_vram_scratch_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001356 radeon_gem_fini(rdev);
1357 radeon_fence_driver_fini(rdev);
Jerome Glissed0269ed2010-01-07 16:08:32 +01001358 radeon_agp_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01001359 radeon_bo_fini(rdev);
Jerome Glissee7d40b92009-10-01 18:02:15 +02001360 radeon_atombios_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001361 kfree(rdev->bios);
1362 rdev->bios = NULL;
1363 radeon_dummy_page_fini(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001364}