blob: b076b96f8b6c23b6c5cd7d60a9b576a8f2794128 [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
28#include <linux/seq_file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020030#include "drmP.h"
31#include "drm.h"
32#include "radeon_drm.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020033#include "radeon_reg.h"
34#include "radeon.h"
Daniel Vettere6990372010-03-11 21:19:17 +000035#include "radeon_asic.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100036#include "r100d.h"
Jerome Glissed4550902009-10-01 10:12:06 +020037#include "rs100d.h"
38#include "rv200d.h"
39#include "rv250d.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100040
Ben Hutchings70967ab2009-08-29 14:53:51 +010041#include <linux/firmware.h>
42#include <linux/platform_device.h>
43
Dave Airlie551ebd82009-09-01 15:25:57 +100044#include "r100_reg_safe.h"
45#include "rn50_reg_safe.h"
46
Ben Hutchings70967ab2009-08-29 14:53:51 +010047/* Firmware Names */
48#define FIRMWARE_R100 "radeon/R100_cp.bin"
49#define FIRMWARE_R200 "radeon/R200_cp.bin"
50#define FIRMWARE_R300 "radeon/R300_cp.bin"
51#define FIRMWARE_R420 "radeon/R420_cp.bin"
52#define FIRMWARE_RS690 "radeon/RS690_cp.bin"
53#define FIRMWARE_RS600 "radeon/RS600_cp.bin"
54#define FIRMWARE_R520 "radeon/R520_cp.bin"
55
56MODULE_FIRMWARE(FIRMWARE_R100);
57MODULE_FIRMWARE(FIRMWARE_R200);
58MODULE_FIRMWARE(FIRMWARE_R300);
59MODULE_FIRMWARE(FIRMWARE_R420);
60MODULE_FIRMWARE(FIRMWARE_RS690);
61MODULE_FIRMWARE(FIRMWARE_RS600);
62MODULE_FIRMWARE(FIRMWARE_R520);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020063
Dave Airlie551ebd82009-09-01 15:25:57 +100064#include "r100_track.h"
65
Jerome Glisse771fe6b2009-06-05 14:42:42 +020066/* This files gather functions specifics to:
67 * r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280
Jerome Glisse771fe6b2009-06-05 14:42:42 +020068 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +020069
Alex Deucherbae6b5622010-04-22 13:38:05 -040070void r100_set_power_state(struct radeon_device *rdev)
71{
72 /* if *_clock_mode are the same, *_power_state are as well */
73 if (rdev->pm.requested_clock_mode == rdev->pm.current_clock_mode)
74 return;
75
76 DRM_INFO("Setting: e: %d m: %d p: %d\n",
77 rdev->pm.requested_clock_mode->sclk,
78 rdev->pm.requested_clock_mode->mclk,
79 rdev->pm.requested_power_state->non_clock_info.pcie_lanes);
80
81 /* set pcie lanes */
82 /* TODO */
83
84 /* set voltage */
85 /* TODO */
86
87 /* set engine clock */
88 radeon_sync_with_vblank(rdev);
89 radeon_pm_debug_check_in_vbl(rdev, false);
90 radeon_set_engine_clock(rdev, rdev->pm.requested_clock_mode->sclk);
91 radeon_pm_debug_check_in_vbl(rdev, true);
92
93#if 0
94 /* set memory clock */
95 if (rdev->asic->set_memory_clock) {
96 radeon_sync_with_vblank(rdev);
97 radeon_pm_debug_check_in_vbl(rdev, false);
98 radeon_set_memory_clock(rdev, rdev->pm.requested_clock_mode->mclk);
99 radeon_pm_debug_check_in_vbl(rdev, true);
100 }
101#endif
102
103 rdev->pm.current_power_state = rdev->pm.requested_power_state;
104 rdev->pm.current_clock_mode = rdev->pm.requested_clock_mode;
105}
106
Alex Deucherdef9ba92010-04-22 12:39:58 -0400107bool r100_gui_idle(struct radeon_device *rdev)
108{
109 if (RREG32(RADEON_RBBM_STATUS) & RADEON_RBBM_ACTIVE)
110 return false;
111 else
112 return true;
113}
114
Alex Deucher05a05c52009-12-04 14:53:41 -0500115/* hpd for digital panel detect/disconnect */
116bool r100_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
117{
118 bool connected = false;
119
120 switch (hpd) {
121 case RADEON_HPD_1:
122 if (RREG32(RADEON_FP_GEN_CNTL) & RADEON_FP_DETECT_SENSE)
123 connected = true;
124 break;
125 case RADEON_HPD_2:
126 if (RREG32(RADEON_FP2_GEN_CNTL) & RADEON_FP2_DETECT_SENSE)
127 connected = true;
128 break;
129 default:
130 break;
131 }
132 return connected;
133}
134
135void r100_hpd_set_polarity(struct radeon_device *rdev,
136 enum radeon_hpd_id hpd)
137{
138 u32 tmp;
139 bool connected = r100_hpd_sense(rdev, hpd);
140
141 switch (hpd) {
142 case RADEON_HPD_1:
143 tmp = RREG32(RADEON_FP_GEN_CNTL);
144 if (connected)
145 tmp &= ~RADEON_FP_DETECT_INT_POL;
146 else
147 tmp |= RADEON_FP_DETECT_INT_POL;
148 WREG32(RADEON_FP_GEN_CNTL, tmp);
149 break;
150 case RADEON_HPD_2:
151 tmp = RREG32(RADEON_FP2_GEN_CNTL);
152 if (connected)
153 tmp &= ~RADEON_FP2_DETECT_INT_POL;
154 else
155 tmp |= RADEON_FP2_DETECT_INT_POL;
156 WREG32(RADEON_FP2_GEN_CNTL, tmp);
157 break;
158 default:
159 break;
160 }
161}
162
163void r100_hpd_init(struct radeon_device *rdev)
164{
165 struct drm_device *dev = rdev->ddev;
166 struct drm_connector *connector;
167
168 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
169 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
170 switch (radeon_connector->hpd.hpd) {
171 case RADEON_HPD_1:
172 rdev->irq.hpd[0] = true;
173 break;
174 case RADEON_HPD_2:
175 rdev->irq.hpd[1] = true;
176 break;
177 default:
178 break;
179 }
180 }
Jerome Glisse003e69f2010-01-07 15:39:14 +0100181 if (rdev->irq.installed)
182 r100_irq_set(rdev);
Alex Deucher05a05c52009-12-04 14:53:41 -0500183}
184
185void r100_hpd_fini(struct radeon_device *rdev)
186{
187 struct drm_device *dev = rdev->ddev;
188 struct drm_connector *connector;
189
190 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
191 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
192 switch (radeon_connector->hpd.hpd) {
193 case RADEON_HPD_1:
194 rdev->irq.hpd[0] = false;
195 break;
196 case RADEON_HPD_2:
197 rdev->irq.hpd[1] = false;
198 break;
199 default:
200 break;
201 }
202 }
203}
204
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200205/*
206 * PCI GART
207 */
208void r100_pci_gart_tlb_flush(struct radeon_device *rdev)
209{
210 /* TODO: can we do somethings here ? */
211 /* It seems hw only cache one entry so we should discard this
212 * entry otherwise if first GPU GART read hit this entry it
213 * could end up in wrong address. */
214}
215
Jerome Glisse4aac0472009-09-14 18:29:49 +0200216int r100_pci_gart_init(struct radeon_device *rdev)
217{
218 int r;
219
220 if (rdev->gart.table.ram.ptr) {
221 WARN(1, "R100 PCI GART already initialized.\n");
222 return 0;
223 }
224 /* Initialize common gart structure */
225 r = radeon_gart_init(rdev);
226 if (r)
227 return r;
228 rdev->gart.table_size = rdev->gart.num_gpu_pages * 4;
229 rdev->asic->gart_tlb_flush = &r100_pci_gart_tlb_flush;
230 rdev->asic->gart_set_page = &r100_pci_gart_set_page;
231 return radeon_gart_table_ram_alloc(rdev);
232}
233
Dave Airlie17e15b02009-11-05 15:36:53 +1000234/* required on r1xx, r2xx, r300, r(v)350, r420/r481, rs400/rs480 */
235void r100_enable_bm(struct radeon_device *rdev)
236{
237 uint32_t tmp;
238 /* Enable bus mastering */
239 tmp = RREG32(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS;
240 WREG32(RADEON_BUS_CNTL, tmp);
241}
242
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200243int r100_pci_gart_enable(struct radeon_device *rdev)
244{
245 uint32_t tmp;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200246
Dave Airlie82568562010-02-05 16:00:07 +1000247 radeon_gart_restore(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200248 /* discard memory request outside of configured range */
249 tmp = RREG32(RADEON_AIC_CNTL) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS;
250 WREG32(RADEON_AIC_CNTL, tmp);
251 /* set address range for PCI address translate */
Jerome Glissed594e462010-02-17 21:54:29 +0000252 WREG32(RADEON_AIC_LO_ADDR, rdev->mc.gtt_start);
253 WREG32(RADEON_AIC_HI_ADDR, rdev->mc.gtt_end);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200254 /* set PCI GART page-table base address */
255 WREG32(RADEON_AIC_PT_BASE, rdev->gart.table_addr);
256 tmp = RREG32(RADEON_AIC_CNTL) | RADEON_PCIGART_TRANSLATE_EN;
257 WREG32(RADEON_AIC_CNTL, tmp);
258 r100_pci_gart_tlb_flush(rdev);
259 rdev->gart.ready = true;
260 return 0;
261}
262
263void r100_pci_gart_disable(struct radeon_device *rdev)
264{
265 uint32_t tmp;
266
267 /* discard memory request outside of configured range */
268 tmp = RREG32(RADEON_AIC_CNTL) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS;
269 WREG32(RADEON_AIC_CNTL, tmp & ~RADEON_PCIGART_TRANSLATE_EN);
270 WREG32(RADEON_AIC_LO_ADDR, 0);
271 WREG32(RADEON_AIC_HI_ADDR, 0);
272}
273
274int r100_pci_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
275{
276 if (i < 0 || i > rdev->gart.num_gpu_pages) {
277 return -EINVAL;
278 }
Dave Airlieed10f952009-06-29 18:29:11 +1000279 rdev->gart.table.ram.ptr[i] = cpu_to_le32(lower_32_bits(addr));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200280 return 0;
281}
282
Jerome Glisse4aac0472009-09-14 18:29:49 +0200283void r100_pci_gart_fini(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200284{
Jerome Glissef9274562010-03-17 14:44:29 +0000285 radeon_gart_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200286 r100_pci_gart_disable(rdev);
287 radeon_gart_table_ram_free(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200288}
289
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200290int r100_irq_set(struct radeon_device *rdev)
291{
292 uint32_t tmp = 0;
293
Jerome Glisse003e69f2010-01-07 15:39:14 +0100294 if (!rdev->irq.installed) {
295 WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n");
296 WREG32(R_000040_GEN_INT_CNTL, 0);
297 return -EINVAL;
298 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200299 if (rdev->irq.sw_int) {
300 tmp |= RADEON_SW_INT_ENABLE;
301 }
Alex Deucher2031f772010-04-22 12:52:11 -0400302 if (rdev->irq.gui_idle) {
303 tmp |= RADEON_GUI_IDLE_MASK;
304 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200305 if (rdev->irq.crtc_vblank_int[0]) {
306 tmp |= RADEON_CRTC_VBLANK_MASK;
307 }
308 if (rdev->irq.crtc_vblank_int[1]) {
309 tmp |= RADEON_CRTC2_VBLANK_MASK;
310 }
Alex Deucher05a05c52009-12-04 14:53:41 -0500311 if (rdev->irq.hpd[0]) {
312 tmp |= RADEON_FP_DETECT_MASK;
313 }
314 if (rdev->irq.hpd[1]) {
315 tmp |= RADEON_FP2_DETECT_MASK;
316 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200317 WREG32(RADEON_GEN_INT_CNTL, tmp);
318 return 0;
319}
320
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200321void r100_irq_disable(struct radeon_device *rdev)
322{
323 u32 tmp;
324
325 WREG32(R_000040_GEN_INT_CNTL, 0);
326 /* Wait and acknowledge irq */
327 mdelay(1);
328 tmp = RREG32(R_000044_GEN_INT_STATUS);
329 WREG32(R_000044_GEN_INT_STATUS, tmp);
330}
331
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200332static inline uint32_t r100_irq_ack(struct radeon_device *rdev)
333{
334 uint32_t irqs = RREG32(RADEON_GEN_INT_STATUS);
Alex Deucher05a05c52009-12-04 14:53:41 -0500335 uint32_t irq_mask = RADEON_SW_INT_TEST |
336 RADEON_CRTC_VBLANK_STAT | RADEON_CRTC2_VBLANK_STAT |
337 RADEON_FP_DETECT_STAT | RADEON_FP2_DETECT_STAT;
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200338
Alex Deucher2031f772010-04-22 12:52:11 -0400339 /* the interrupt works, but the status bit is permanently asserted */
340 if (rdev->irq.gui_idle && radeon_gui_idle(rdev)) {
341 if (!rdev->irq.gui_idle_acked)
342 irq_mask |= RADEON_GUI_IDLE_STAT;
343 }
344
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200345 if (irqs) {
346 WREG32(RADEON_GEN_INT_STATUS, irqs);
347 }
348 return irqs & irq_mask;
349}
350
351int r100_irq_process(struct radeon_device *rdev)
352{
Alex Deucher3e5cb982009-10-16 12:21:24 -0400353 uint32_t status, msi_rearm;
Alex Deucherd4877cf2009-12-04 16:56:37 -0500354 bool queue_hotplug = false;
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200355
Alex Deucher2031f772010-04-22 12:52:11 -0400356 /* reset gui idle ack. the status bit is broken */
357 rdev->irq.gui_idle_acked = false;
358
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200359 status = r100_irq_ack(rdev);
360 if (!status) {
361 return IRQ_NONE;
362 }
Jerome Glissea513c182009-09-09 22:23:07 +0200363 if (rdev->shutdown) {
364 return IRQ_NONE;
365 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200366 while (status) {
367 /* SW interrupt */
368 if (status & RADEON_SW_INT_TEST) {
369 radeon_fence_process(rdev);
370 }
Alex Deucher2031f772010-04-22 12:52:11 -0400371 /* gui idle interrupt */
372 if (status & RADEON_GUI_IDLE_STAT) {
373 rdev->irq.gui_idle_acked = true;
374 rdev->pm.gui_idle = true;
375 wake_up(&rdev->irq.idle_queue);
376 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200377 /* Vertical blank interrupts */
378 if (status & RADEON_CRTC_VBLANK_STAT) {
379 drm_handle_vblank(rdev->ddev, 0);
Rafał Miłecki839461d2010-03-02 22:06:51 +0100380 rdev->pm.vblank_sync = true;
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100381 wake_up(&rdev->irq.vblank_queue);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200382 }
383 if (status & RADEON_CRTC2_VBLANK_STAT) {
384 drm_handle_vblank(rdev->ddev, 1);
Rafał Miłecki839461d2010-03-02 22:06:51 +0100385 rdev->pm.vblank_sync = true;
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100386 wake_up(&rdev->irq.vblank_queue);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200387 }
Alex Deucher05a05c52009-12-04 14:53:41 -0500388 if (status & RADEON_FP_DETECT_STAT) {
Alex Deucherd4877cf2009-12-04 16:56:37 -0500389 queue_hotplug = true;
390 DRM_DEBUG("HPD1\n");
Alex Deucher05a05c52009-12-04 14:53:41 -0500391 }
392 if (status & RADEON_FP2_DETECT_STAT) {
Alex Deucherd4877cf2009-12-04 16:56:37 -0500393 queue_hotplug = true;
394 DRM_DEBUG("HPD2\n");
Alex Deucher05a05c52009-12-04 14:53:41 -0500395 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200396 status = r100_irq_ack(rdev);
397 }
Alex Deucher2031f772010-04-22 12:52:11 -0400398 /* reset gui idle ack. the status bit is broken */
399 rdev->irq.gui_idle_acked = false;
Alex Deucherd4877cf2009-12-04 16:56:37 -0500400 if (queue_hotplug)
401 queue_work(rdev->wq, &rdev->hotplug_work);
Alex Deucher3e5cb982009-10-16 12:21:24 -0400402 if (rdev->msi_enabled) {
403 switch (rdev->family) {
404 case CHIP_RS400:
405 case CHIP_RS480:
406 msi_rearm = RREG32(RADEON_AIC_CNTL) & ~RS400_MSI_REARM;
407 WREG32(RADEON_AIC_CNTL, msi_rearm);
408 WREG32(RADEON_AIC_CNTL, msi_rearm | RS400_MSI_REARM);
409 break;
410 default:
411 msi_rearm = RREG32(RADEON_MSI_REARM_EN) & ~RV370_MSI_REARM_EN;
412 WREG32(RADEON_MSI_REARM_EN, msi_rearm);
413 WREG32(RADEON_MSI_REARM_EN, msi_rearm | RV370_MSI_REARM_EN);
414 break;
415 }
416 }
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200417 return IRQ_HANDLED;
418}
419
420u32 r100_get_vblank_counter(struct radeon_device *rdev, int crtc)
421{
422 if (crtc == 0)
423 return RREG32(RADEON_CRTC_CRNT_FRAME);
424 else
425 return RREG32(RADEON_CRTC2_CRNT_FRAME);
426}
427
Pauli Nieminen9e5b2af2010-02-04 19:20:53 +0200428/* Who ever call radeon_fence_emit should call ring_lock and ask
429 * for enough space (today caller are ib schedule and buffer move) */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200430void r100_fence_ring_emit(struct radeon_device *rdev,
431 struct radeon_fence *fence)
432{
Pauli Nieminen9e5b2af2010-02-04 19:20:53 +0200433 /* We have to make sure that caches are flushed before
434 * CPU might read something from VRAM. */
435 radeon_ring_write(rdev, PACKET0(RADEON_RB3D_DSTCACHE_CTLSTAT, 0));
436 radeon_ring_write(rdev, RADEON_RB3D_DC_FLUSH_ALL);
437 radeon_ring_write(rdev, PACKET0(RADEON_RB3D_ZCACHE_CTLSTAT, 0));
438 radeon_ring_write(rdev, RADEON_RB3D_ZC_FLUSH_ALL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200439 /* Wait until IDLE & CLEAN */
Alex Deucher4612dc92010-02-05 01:58:28 -0500440 radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0));
441 radeon_ring_write(rdev, RADEON_WAIT_2D_IDLECLEAN | RADEON_WAIT_3D_IDLECLEAN);
Jerome Glissecafe6602010-01-07 12:39:21 +0100442 radeon_ring_write(rdev, PACKET0(RADEON_HOST_PATH_CNTL, 0));
443 radeon_ring_write(rdev, rdev->config.r100.hdp_cntl |
444 RADEON_HDP_READ_BUFFER_INVALIDATE);
445 radeon_ring_write(rdev, PACKET0(RADEON_HOST_PATH_CNTL, 0));
446 radeon_ring_write(rdev, rdev->config.r100.hdp_cntl);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200447 /* Emit fence sequence & fire IRQ */
448 radeon_ring_write(rdev, PACKET0(rdev->fence_drv.scratch_reg, 0));
449 radeon_ring_write(rdev, fence->seq);
450 radeon_ring_write(rdev, PACKET0(RADEON_GEN_INT_STATUS, 0));
451 radeon_ring_write(rdev, RADEON_SW_INT_FIRE);
452}
453
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200454int r100_wb_init(struct radeon_device *rdev)
455{
456 int r;
457
458 if (rdev->wb.wb_obj == NULL) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100459 r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, true,
460 RADEON_GEM_DOMAIN_GTT,
461 &rdev->wb.wb_obj);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200462 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100463 dev_err(rdev->dev, "(%d) create WB buffer failed\n", r);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200464 return r;
465 }
Jerome Glisse4c788672009-11-20 14:29:23 +0100466 r = radeon_bo_reserve(rdev->wb.wb_obj, false);
467 if (unlikely(r != 0))
468 return r;
469 r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT,
470 &rdev->wb.gpu_addr);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200471 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100472 dev_err(rdev->dev, "(%d) pin WB buffer failed\n", r);
473 radeon_bo_unreserve(rdev->wb.wb_obj);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200474 return r;
475 }
Jerome Glisse4c788672009-11-20 14:29:23 +0100476 r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb);
477 radeon_bo_unreserve(rdev->wb.wb_obj);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200478 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100479 dev_err(rdev->dev, "(%d) map WB buffer failed\n", r);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200480 return r;
481 }
482 }
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200483 WREG32(R_000774_SCRATCH_ADDR, rdev->wb.gpu_addr);
484 WREG32(R_00070C_CP_RB_RPTR_ADDR,
485 S_00070C_RB_RPTR_ADDR((rdev->wb.gpu_addr + 1024) >> 2));
486 WREG32(R_000770_SCRATCH_UMSK, 0xff);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200487 return 0;
488}
489
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200490void r100_wb_disable(struct radeon_device *rdev)
491{
492 WREG32(R_000770_SCRATCH_UMSK, 0);
493}
494
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200495void r100_wb_fini(struct radeon_device *rdev)
496{
Jerome Glisse4c788672009-11-20 14:29:23 +0100497 int r;
498
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200499 r100_wb_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200500 if (rdev->wb.wb_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100501 r = radeon_bo_reserve(rdev->wb.wb_obj, false);
502 if (unlikely(r != 0)) {
503 dev_err(rdev->dev, "(%d) can't finish WB\n", r);
504 return;
505 }
506 radeon_bo_kunmap(rdev->wb.wb_obj);
507 radeon_bo_unpin(rdev->wb.wb_obj);
508 radeon_bo_unreserve(rdev->wb.wb_obj);
509 radeon_bo_unref(&rdev->wb.wb_obj);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200510 rdev->wb.wb = NULL;
511 rdev->wb.wb_obj = NULL;
512 }
513}
514
515int r100_copy_blit(struct radeon_device *rdev,
516 uint64_t src_offset,
517 uint64_t dst_offset,
518 unsigned num_pages,
519 struct radeon_fence *fence)
520{
521 uint32_t cur_pages;
522 uint32_t stride_bytes = PAGE_SIZE;
523 uint32_t pitch;
524 uint32_t stride_pixels;
525 unsigned ndw;
526 int num_loops;
527 int r = 0;
528
529 /* radeon limited to 16k stride */
530 stride_bytes &= 0x3fff;
531 /* radeon pitch is /64 */
532 pitch = stride_bytes / 64;
533 stride_pixels = stride_bytes / 4;
534 num_loops = DIV_ROUND_UP(num_pages, 8191);
535
536 /* Ask for enough room for blit + flush + fence */
537 ndw = 64 + (10 * num_loops);
538 r = radeon_ring_lock(rdev, ndw);
539 if (r) {
540 DRM_ERROR("radeon: moving bo (%d) asking for %u dw.\n", r, ndw);
541 return -EINVAL;
542 }
543 while (num_pages > 0) {
544 cur_pages = num_pages;
545 if (cur_pages > 8191) {
546 cur_pages = 8191;
547 }
548 num_pages -= cur_pages;
549
550 /* pages are in Y direction - height
551 page width in X direction - width */
552 radeon_ring_write(rdev, PACKET3(PACKET3_BITBLT_MULTI, 8));
553 radeon_ring_write(rdev,
554 RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
555 RADEON_GMC_DST_PITCH_OFFSET_CNTL |
556 RADEON_GMC_SRC_CLIPPING |
557 RADEON_GMC_DST_CLIPPING |
558 RADEON_GMC_BRUSH_NONE |
559 (RADEON_COLOR_FORMAT_ARGB8888 << 8) |
560 RADEON_GMC_SRC_DATATYPE_COLOR |
561 RADEON_ROP3_S |
562 RADEON_DP_SRC_SOURCE_MEMORY |
563 RADEON_GMC_CLR_CMP_CNTL_DIS |
564 RADEON_GMC_WR_MSK_DIS);
565 radeon_ring_write(rdev, (pitch << 22) | (src_offset >> 10));
566 radeon_ring_write(rdev, (pitch << 22) | (dst_offset >> 10));
567 radeon_ring_write(rdev, (0x1fff) | (0x1fff << 16));
568 radeon_ring_write(rdev, 0);
569 radeon_ring_write(rdev, (0x1fff) | (0x1fff << 16));
570 radeon_ring_write(rdev, num_pages);
571 radeon_ring_write(rdev, num_pages);
572 radeon_ring_write(rdev, cur_pages | (stride_pixels << 16));
573 }
574 radeon_ring_write(rdev, PACKET0(RADEON_DSTCACHE_CTLSTAT, 0));
575 radeon_ring_write(rdev, RADEON_RB2D_DC_FLUSH_ALL);
576 radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0));
577 radeon_ring_write(rdev,
578 RADEON_WAIT_2D_IDLECLEAN |
579 RADEON_WAIT_HOST_IDLECLEAN |
580 RADEON_WAIT_DMA_GUI_IDLE);
581 if (fence) {
582 r = radeon_fence_emit(rdev, fence);
583 }
584 radeon_ring_unlock_commit(rdev);
585 return r;
586}
587
Jerome Glisse45600232009-09-09 22:23:45 +0200588static int r100_cp_wait_for_idle(struct radeon_device *rdev)
589{
590 unsigned i;
591 u32 tmp;
592
593 for (i = 0; i < rdev->usec_timeout; i++) {
594 tmp = RREG32(R_000E40_RBBM_STATUS);
595 if (!G_000E40_CP_CMDSTRM_BUSY(tmp)) {
596 return 0;
597 }
598 udelay(1);
599 }
600 return -1;
601}
602
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200603void r100_ring_start(struct radeon_device *rdev)
604{
605 int r;
606
607 r = radeon_ring_lock(rdev, 2);
608 if (r) {
609 return;
610 }
611 radeon_ring_write(rdev, PACKET0(RADEON_ISYNC_CNTL, 0));
612 radeon_ring_write(rdev,
613 RADEON_ISYNC_ANY2D_IDLE3D |
614 RADEON_ISYNC_ANY3D_IDLE2D |
615 RADEON_ISYNC_WAIT_IDLEGUI |
616 RADEON_ISYNC_CPSCRATCH_IDLEGUI);
617 radeon_ring_unlock_commit(rdev);
618}
619
Ben Hutchings70967ab2009-08-29 14:53:51 +0100620
621/* Load the microcode for the CP */
622static int r100_cp_init_microcode(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200623{
Ben Hutchings70967ab2009-08-29 14:53:51 +0100624 struct platform_device *pdev;
625 const char *fw_name = NULL;
626 int err;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200627
Ben Hutchings70967ab2009-08-29 14:53:51 +0100628 DRM_DEBUG("\n");
629
630 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
631 err = IS_ERR(pdev);
632 if (err) {
633 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
634 return -EINVAL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200635 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200636 if ((rdev->family == CHIP_R100) || (rdev->family == CHIP_RV100) ||
637 (rdev->family == CHIP_RV200) || (rdev->family == CHIP_RS100) ||
638 (rdev->family == CHIP_RS200)) {
639 DRM_INFO("Loading R100 Microcode\n");
Ben Hutchings70967ab2009-08-29 14:53:51 +0100640 fw_name = FIRMWARE_R100;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200641 } else if ((rdev->family == CHIP_R200) ||
642 (rdev->family == CHIP_RV250) ||
643 (rdev->family == CHIP_RV280) ||
644 (rdev->family == CHIP_RS300)) {
645 DRM_INFO("Loading R200 Microcode\n");
Ben Hutchings70967ab2009-08-29 14:53:51 +0100646 fw_name = FIRMWARE_R200;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200647 } else if ((rdev->family == CHIP_R300) ||
648 (rdev->family == CHIP_R350) ||
649 (rdev->family == CHIP_RV350) ||
650 (rdev->family == CHIP_RV380) ||
651 (rdev->family == CHIP_RS400) ||
652 (rdev->family == CHIP_RS480)) {
653 DRM_INFO("Loading R300 Microcode\n");
Ben Hutchings70967ab2009-08-29 14:53:51 +0100654 fw_name = FIRMWARE_R300;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200655 } else if ((rdev->family == CHIP_R420) ||
656 (rdev->family == CHIP_R423) ||
657 (rdev->family == CHIP_RV410)) {
658 DRM_INFO("Loading R400 Microcode\n");
Ben Hutchings70967ab2009-08-29 14:53:51 +0100659 fw_name = FIRMWARE_R420;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200660 } else if ((rdev->family == CHIP_RS690) ||
661 (rdev->family == CHIP_RS740)) {
662 DRM_INFO("Loading RS690/RS740 Microcode\n");
Ben Hutchings70967ab2009-08-29 14:53:51 +0100663 fw_name = FIRMWARE_RS690;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200664 } else if (rdev->family == CHIP_RS600) {
665 DRM_INFO("Loading RS600 Microcode\n");
Ben Hutchings70967ab2009-08-29 14:53:51 +0100666 fw_name = FIRMWARE_RS600;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200667 } else if ((rdev->family == CHIP_RV515) ||
668 (rdev->family == CHIP_R520) ||
669 (rdev->family == CHIP_RV530) ||
670 (rdev->family == CHIP_R580) ||
671 (rdev->family == CHIP_RV560) ||
672 (rdev->family == CHIP_RV570)) {
673 DRM_INFO("Loading R500 Microcode\n");
Ben Hutchings70967ab2009-08-29 14:53:51 +0100674 fw_name = FIRMWARE_R520;
675 }
676
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000677 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
Ben Hutchings70967ab2009-08-29 14:53:51 +0100678 platform_device_unregister(pdev);
679 if (err) {
680 printk(KERN_ERR "radeon_cp: Failed to load firmware \"%s\"\n",
681 fw_name);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000682 } else if (rdev->me_fw->size % 8) {
Ben Hutchings70967ab2009-08-29 14:53:51 +0100683 printk(KERN_ERR
684 "radeon_cp: Bogus length %zu in firmware \"%s\"\n",
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000685 rdev->me_fw->size, fw_name);
Ben Hutchings70967ab2009-08-29 14:53:51 +0100686 err = -EINVAL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000687 release_firmware(rdev->me_fw);
688 rdev->me_fw = NULL;
Ben Hutchings70967ab2009-08-29 14:53:51 +0100689 }
690 return err;
691}
Jerome Glissed4550902009-10-01 10:12:06 +0200692
Ben Hutchings70967ab2009-08-29 14:53:51 +0100693static void r100_cp_load_microcode(struct radeon_device *rdev)
694{
695 const __be32 *fw_data;
696 int i, size;
697
698 if (r100_gui_wait_for_idle(rdev)) {
699 printk(KERN_WARNING "Failed to wait GUI idle while "
700 "programming pipes. Bad things might happen.\n");
701 }
702
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000703 if (rdev->me_fw) {
704 size = rdev->me_fw->size / 4;
705 fw_data = (const __be32 *)&rdev->me_fw->data[0];
Ben Hutchings70967ab2009-08-29 14:53:51 +0100706 WREG32(RADEON_CP_ME_RAM_ADDR, 0);
707 for (i = 0; i < size; i += 2) {
708 WREG32(RADEON_CP_ME_RAM_DATAH,
709 be32_to_cpup(&fw_data[i]));
710 WREG32(RADEON_CP_ME_RAM_DATAL,
711 be32_to_cpup(&fw_data[i + 1]));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200712 }
713 }
714}
715
716int r100_cp_init(struct radeon_device *rdev, unsigned ring_size)
717{
718 unsigned rb_bufsz;
719 unsigned rb_blksz;
720 unsigned max_fetch;
721 unsigned pre_write_timer;
722 unsigned pre_write_limit;
723 unsigned indirect2_start;
724 unsigned indirect1_start;
725 uint32_t tmp;
726 int r;
727
728 if (r100_debugfs_cp_init(rdev)) {
729 DRM_ERROR("Failed to register debugfs file for CP !\n");
730 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000731 if (!rdev->me_fw) {
Ben Hutchings70967ab2009-08-29 14:53:51 +0100732 r = r100_cp_init_microcode(rdev);
733 if (r) {
734 DRM_ERROR("Failed to load firmware!\n");
735 return r;
736 }
737 }
738
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200739 /* Align ring size */
740 rb_bufsz = drm_order(ring_size / 8);
741 ring_size = (1 << (rb_bufsz + 1)) * 4;
742 r100_cp_load_microcode(rdev);
743 r = radeon_ring_init(rdev, ring_size);
744 if (r) {
745 return r;
746 }
747 /* Each time the cp read 1024 bytes (16 dword/quadword) update
748 * the rptr copy in system ram */
749 rb_blksz = 9;
750 /* cp will read 128bytes at a time (4 dwords) */
751 max_fetch = 1;
752 rdev->cp.align_mask = 16 - 1;
753 /* Write to CP_RB_WPTR will be delayed for pre_write_timer clocks */
754 pre_write_timer = 64;
755 /* Force CP_RB_WPTR write if written more than one time before the
756 * delay expire
757 */
758 pre_write_limit = 0;
759 /* Setup the cp cache like this (cache size is 96 dwords) :
760 * RING 0 to 15
761 * INDIRECT1 16 to 79
762 * INDIRECT2 80 to 95
763 * So ring cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords))
764 * indirect1 cache size is 64dwords (> (2 * max_fetch = 2 * 4dwords))
765 * indirect2 cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords))
766 * Idea being that most of the gpu cmd will be through indirect1 buffer
767 * so it gets the bigger cache.
768 */
769 indirect2_start = 80;
770 indirect1_start = 16;
771 /* cp setup */
772 WREG32(0x718, pre_write_timer | (pre_write_limit << 28));
Alex Deucherd6f28932009-11-02 16:01:27 -0500773 tmp = (REG_SET(RADEON_RB_BUFSZ, rb_bufsz) |
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200774 REG_SET(RADEON_RB_BLKSZ, rb_blksz) |
775 REG_SET(RADEON_MAX_FETCH, max_fetch) |
776 RADEON_RB_NO_UPDATE);
Alex Deucherd6f28932009-11-02 16:01:27 -0500777#ifdef __BIG_ENDIAN
778 tmp |= RADEON_BUF_SWAP_32BIT;
779#endif
780 WREG32(RADEON_CP_RB_CNTL, tmp);
781
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200782 /* Set ring address */
783 DRM_INFO("radeon: ring at 0x%016lX\n", (unsigned long)rdev->cp.gpu_addr);
784 WREG32(RADEON_CP_RB_BASE, rdev->cp.gpu_addr);
785 /* Force read & write ptr to 0 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200786 WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA);
787 WREG32(RADEON_CP_RB_RPTR_WR, 0);
788 WREG32(RADEON_CP_RB_WPTR, 0);
789 WREG32(RADEON_CP_RB_CNTL, tmp);
790 udelay(10);
791 rdev->cp.rptr = RREG32(RADEON_CP_RB_RPTR);
792 rdev->cp.wptr = RREG32(RADEON_CP_RB_WPTR);
Dave Airlie9e5786b2010-03-31 13:38:56 +1000793 /* protect against crazy HW on resume */
794 rdev->cp.wptr &= rdev->cp.ptr_mask;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200795 /* Set cp mode to bus mastering & enable cp*/
796 WREG32(RADEON_CP_CSQ_MODE,
797 REG_SET(RADEON_INDIRECT2_START, indirect2_start) |
798 REG_SET(RADEON_INDIRECT1_START, indirect1_start));
799 WREG32(0x718, 0);
800 WREG32(0x744, 0x00004D4D);
801 WREG32(RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIBM_INDBM);
802 radeon_ring_start(rdev);
803 r = radeon_ring_test(rdev);
804 if (r) {
805 DRM_ERROR("radeon: cp isn't working (%d).\n", r);
806 return r;
807 }
808 rdev->cp.ready = true;
809 return 0;
810}
811
812void r100_cp_fini(struct radeon_device *rdev)
813{
Jerome Glisse45600232009-09-09 22:23:45 +0200814 if (r100_cp_wait_for_idle(rdev)) {
815 DRM_ERROR("Wait for CP idle timeout, shutting down CP.\n");
816 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200817 /* Disable ring */
Jerome Glissea18d7ea2009-09-09 22:23:27 +0200818 r100_cp_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200819 radeon_ring_fini(rdev);
820 DRM_INFO("radeon: cp finalized\n");
821}
822
823void r100_cp_disable(struct radeon_device *rdev)
824{
825 /* Disable ring */
826 rdev->cp.ready = false;
827 WREG32(RADEON_CP_CSQ_MODE, 0);
828 WREG32(RADEON_CP_CSQ_CNTL, 0);
829 if (r100_gui_wait_for_idle(rdev)) {
830 printk(KERN_WARNING "Failed to wait GUI idle while "
831 "programming pipes. Bad things might happen.\n");
832 }
833}
834
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000835void r100_cp_commit(struct radeon_device *rdev)
836{
837 WREG32(RADEON_CP_RB_WPTR, rdev->cp.wptr);
838 (void)RREG32(RADEON_CP_RB_WPTR);
839}
840
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200841
842/*
843 * CS functions
844 */
845int r100_cs_parse_packet0(struct radeon_cs_parser *p,
846 struct radeon_cs_packet *pkt,
Jerome Glisse068a1172009-06-17 13:28:30 +0200847 const unsigned *auth, unsigned n,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200848 radeon_packet0_check_t check)
849{
850 unsigned reg;
851 unsigned i, j, m;
852 unsigned idx;
853 int r;
854
855 idx = pkt->idx + 1;
856 reg = pkt->reg;
Jerome Glisse068a1172009-06-17 13:28:30 +0200857 /* Check that register fall into register range
858 * determined by the number of entry (n) in the
859 * safe register bitmap.
860 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200861 if (pkt->one_reg_wr) {
862 if ((reg >> 7) > n) {
863 return -EINVAL;
864 }
865 } else {
866 if (((reg + (pkt->count << 2)) >> 7) > n) {
867 return -EINVAL;
868 }
869 }
870 for (i = 0; i <= pkt->count; i++, idx++) {
871 j = (reg >> 7);
872 m = 1 << ((reg >> 2) & 31);
873 if (auth[j] & m) {
874 r = check(p, pkt, idx, reg);
875 if (r) {
876 return r;
877 }
878 }
879 if (pkt->one_reg_wr) {
880 if (!(auth[j] & m)) {
881 break;
882 }
883 } else {
884 reg += 4;
885 }
886 }
887 return 0;
888}
889
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200890void r100_cs_dump_packet(struct radeon_cs_parser *p,
891 struct radeon_cs_packet *pkt)
892{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200893 volatile uint32_t *ib;
894 unsigned i;
895 unsigned idx;
896
897 ib = p->ib->ptr;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200898 idx = pkt->idx;
899 for (i = 0; i <= (pkt->count + 1); i++, idx++) {
900 DRM_INFO("ib[%d]=0x%08X\n", idx, ib[idx]);
901 }
902}
903
904/**
905 * r100_cs_packet_parse() - parse cp packet and point ib index to next packet
906 * @parser: parser structure holding parsing context.
907 * @pkt: where to store packet informations
908 *
909 * Assume that chunk_ib_index is properly set. Will return -EINVAL
910 * if packet is bigger than remaining ib size. or if packets is unknown.
911 **/
912int r100_cs_packet_parse(struct radeon_cs_parser *p,
913 struct radeon_cs_packet *pkt,
914 unsigned idx)
915{
916 struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx];
Roel Kluinfa992392009-08-03 14:20:32 +0200917 uint32_t header;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200918
919 if (idx >= ib_chunk->length_dw) {
920 DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
921 idx, ib_chunk->length_dw);
922 return -EINVAL;
923 }
Dave Airlie513bcb42009-09-23 16:56:27 +1000924 header = radeon_get_ib_value(p, idx);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200925 pkt->idx = idx;
926 pkt->type = CP_PACKET_GET_TYPE(header);
927 pkt->count = CP_PACKET_GET_COUNT(header);
928 switch (pkt->type) {
929 case PACKET_TYPE0:
930 pkt->reg = CP_PACKET0_GET_REG(header);
931 pkt->one_reg_wr = CP_PACKET0_GET_ONE_REG_WR(header);
932 break;
933 case PACKET_TYPE3:
934 pkt->opcode = CP_PACKET3_GET_OPCODE(header);
935 break;
936 case PACKET_TYPE2:
937 pkt->count = -1;
938 break;
939 default:
940 DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx);
941 return -EINVAL;
942 }
943 if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) {
944 DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
945 pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw);
946 return -EINVAL;
947 }
948 return 0;
949}
950
951/**
Dave Airlie531369e2009-06-29 11:21:25 +1000952 * r100_cs_packet_next_vline() - parse userspace VLINE packet
953 * @parser: parser structure holding parsing context.
954 *
955 * Userspace sends a special sequence for VLINE waits.
956 * PACKET0 - VLINE_START_END + value
957 * PACKET0 - WAIT_UNTIL +_value
958 * RELOC (P3) - crtc_id in reloc.
959 *
960 * This function parses this and relocates the VLINE START END
961 * and WAIT UNTIL packets to the correct crtc.
962 * It also detects a switched off crtc and nulls out the
963 * wait in that case.
964 */
965int r100_cs_packet_parse_vline(struct radeon_cs_parser *p)
966{
Dave Airlie531369e2009-06-29 11:21:25 +1000967 struct drm_mode_object *obj;
968 struct drm_crtc *crtc;
969 struct radeon_crtc *radeon_crtc;
970 struct radeon_cs_packet p3reloc, waitreloc;
971 int crtc_id;
972 int r;
973 uint32_t header, h_idx, reg;
Dave Airlie513bcb42009-09-23 16:56:27 +1000974 volatile uint32_t *ib;
Dave Airlie531369e2009-06-29 11:21:25 +1000975
Dave Airlie513bcb42009-09-23 16:56:27 +1000976 ib = p->ib->ptr;
Dave Airlie531369e2009-06-29 11:21:25 +1000977
978 /* parse the wait until */
979 r = r100_cs_packet_parse(p, &waitreloc, p->idx);
980 if (r)
981 return r;
982
983 /* check its a wait until and only 1 count */
984 if (waitreloc.reg != RADEON_WAIT_UNTIL ||
985 waitreloc.count != 0) {
986 DRM_ERROR("vline wait had illegal wait until segment\n");
987 r = -EINVAL;
988 return r;
989 }
990
Dave Airlie513bcb42009-09-23 16:56:27 +1000991 if (radeon_get_ib_value(p, waitreloc.idx + 1) != RADEON_WAIT_CRTC_VLINE) {
Dave Airlie531369e2009-06-29 11:21:25 +1000992 DRM_ERROR("vline wait had illegal wait until\n");
993 r = -EINVAL;
994 return r;
995 }
996
997 /* jump over the NOP */
Alex Deucher90ebd062009-09-25 16:39:24 -0400998 r = r100_cs_packet_parse(p, &p3reloc, p->idx + waitreloc.count + 2);
Dave Airlie531369e2009-06-29 11:21:25 +1000999 if (r)
1000 return r;
1001
1002 h_idx = p->idx - 2;
Alex Deucher90ebd062009-09-25 16:39:24 -04001003 p->idx += waitreloc.count + 2;
1004 p->idx += p3reloc.count + 2;
Dave Airlie531369e2009-06-29 11:21:25 +10001005
Dave Airlie513bcb42009-09-23 16:56:27 +10001006 header = radeon_get_ib_value(p, h_idx);
1007 crtc_id = radeon_get_ib_value(p, h_idx + 5);
Dave Airlied4ac6a02009-10-08 11:32:49 +10001008 reg = CP_PACKET0_GET_REG(header);
Dave Airlie531369e2009-06-29 11:21:25 +10001009 mutex_lock(&p->rdev->ddev->mode_config.mutex);
1010 obj = drm_mode_object_find(p->rdev->ddev, crtc_id, DRM_MODE_OBJECT_CRTC);
1011 if (!obj) {
1012 DRM_ERROR("cannot find crtc %d\n", crtc_id);
1013 r = -EINVAL;
1014 goto out;
1015 }
1016 crtc = obj_to_crtc(obj);
1017 radeon_crtc = to_radeon_crtc(crtc);
1018 crtc_id = radeon_crtc->crtc_id;
1019
1020 if (!crtc->enabled) {
1021 /* if the CRTC isn't enabled - we need to nop out the wait until */
Dave Airlie513bcb42009-09-23 16:56:27 +10001022 ib[h_idx + 2] = PACKET2(0);
1023 ib[h_idx + 3] = PACKET2(0);
Dave Airlie531369e2009-06-29 11:21:25 +10001024 } else if (crtc_id == 1) {
1025 switch (reg) {
1026 case AVIVO_D1MODE_VLINE_START_END:
Alex Deucher90ebd062009-09-25 16:39:24 -04001027 header &= ~R300_CP_PACKET0_REG_MASK;
Dave Airlie531369e2009-06-29 11:21:25 +10001028 header |= AVIVO_D2MODE_VLINE_START_END >> 2;
1029 break;
1030 case RADEON_CRTC_GUI_TRIG_VLINE:
Alex Deucher90ebd062009-09-25 16:39:24 -04001031 header &= ~R300_CP_PACKET0_REG_MASK;
Dave Airlie531369e2009-06-29 11:21:25 +10001032 header |= RADEON_CRTC2_GUI_TRIG_VLINE >> 2;
1033 break;
1034 default:
1035 DRM_ERROR("unknown crtc reloc\n");
1036 r = -EINVAL;
1037 goto out;
1038 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001039 ib[h_idx] = header;
1040 ib[h_idx + 3] |= RADEON_ENG_DISPLAY_SELECT_CRTC1;
Dave Airlie531369e2009-06-29 11:21:25 +10001041 }
1042out:
1043 mutex_unlock(&p->rdev->ddev->mode_config.mutex);
1044 return r;
1045}
1046
1047/**
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001048 * r100_cs_packet_next_reloc() - parse next packet which should be reloc packet3
1049 * @parser: parser structure holding parsing context.
1050 * @data: pointer to relocation data
1051 * @offset_start: starting offset
1052 * @offset_mask: offset mask (to align start offset on)
1053 * @reloc: reloc informations
1054 *
1055 * Check next packet is relocation packet3, do bo validation and compute
1056 * GPU offset using the provided start.
1057 **/
1058int r100_cs_packet_next_reloc(struct radeon_cs_parser *p,
1059 struct radeon_cs_reloc **cs_reloc)
1060{
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001061 struct radeon_cs_chunk *relocs_chunk;
1062 struct radeon_cs_packet p3reloc;
1063 unsigned idx;
1064 int r;
1065
1066 if (p->chunk_relocs_idx == -1) {
1067 DRM_ERROR("No relocation chunk !\n");
1068 return -EINVAL;
1069 }
1070 *cs_reloc = NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001071 relocs_chunk = &p->chunks[p->chunk_relocs_idx];
1072 r = r100_cs_packet_parse(p, &p3reloc, p->idx);
1073 if (r) {
1074 return r;
1075 }
1076 p->idx += p3reloc.count + 2;
1077 if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) {
1078 DRM_ERROR("No packet3 for relocation for packet at %d.\n",
1079 p3reloc.idx);
1080 r100_cs_dump_packet(p, &p3reloc);
1081 return -EINVAL;
1082 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001083 idx = radeon_get_ib_value(p, p3reloc.idx + 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001084 if (idx >= relocs_chunk->length_dw) {
1085 DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
1086 idx, relocs_chunk->length_dw);
1087 r100_cs_dump_packet(p, &p3reloc);
1088 return -EINVAL;
1089 }
1090 /* FIXME: we assume reloc size is 4 dwords */
1091 *cs_reloc = p->relocs_ptr[(idx / 4)];
1092 return 0;
1093}
1094
Dave Airlie551ebd82009-09-01 15:25:57 +10001095static int r100_get_vtx_size(uint32_t vtx_fmt)
1096{
1097 int vtx_size;
1098 vtx_size = 2;
1099 /* ordered according to bits in spec */
1100 if (vtx_fmt & RADEON_SE_VTX_FMT_W0)
1101 vtx_size++;
1102 if (vtx_fmt & RADEON_SE_VTX_FMT_FPCOLOR)
1103 vtx_size += 3;
1104 if (vtx_fmt & RADEON_SE_VTX_FMT_FPALPHA)
1105 vtx_size++;
1106 if (vtx_fmt & RADEON_SE_VTX_FMT_PKCOLOR)
1107 vtx_size++;
1108 if (vtx_fmt & RADEON_SE_VTX_FMT_FPSPEC)
1109 vtx_size += 3;
1110 if (vtx_fmt & RADEON_SE_VTX_FMT_FPFOG)
1111 vtx_size++;
1112 if (vtx_fmt & RADEON_SE_VTX_FMT_PKSPEC)
1113 vtx_size++;
1114 if (vtx_fmt & RADEON_SE_VTX_FMT_ST0)
1115 vtx_size += 2;
1116 if (vtx_fmt & RADEON_SE_VTX_FMT_ST1)
1117 vtx_size += 2;
1118 if (vtx_fmt & RADEON_SE_VTX_FMT_Q1)
1119 vtx_size++;
1120 if (vtx_fmt & RADEON_SE_VTX_FMT_ST2)
1121 vtx_size += 2;
1122 if (vtx_fmt & RADEON_SE_VTX_FMT_Q2)
1123 vtx_size++;
1124 if (vtx_fmt & RADEON_SE_VTX_FMT_ST3)
1125 vtx_size += 2;
1126 if (vtx_fmt & RADEON_SE_VTX_FMT_Q3)
1127 vtx_size++;
1128 if (vtx_fmt & RADEON_SE_VTX_FMT_Q0)
1129 vtx_size++;
1130 /* blend weight */
1131 if (vtx_fmt & (0x7 << 15))
1132 vtx_size += (vtx_fmt >> 15) & 0x7;
1133 if (vtx_fmt & RADEON_SE_VTX_FMT_N0)
1134 vtx_size += 3;
1135 if (vtx_fmt & RADEON_SE_VTX_FMT_XY1)
1136 vtx_size += 2;
1137 if (vtx_fmt & RADEON_SE_VTX_FMT_Z1)
1138 vtx_size++;
1139 if (vtx_fmt & RADEON_SE_VTX_FMT_W1)
1140 vtx_size++;
1141 if (vtx_fmt & RADEON_SE_VTX_FMT_N1)
1142 vtx_size++;
1143 if (vtx_fmt & RADEON_SE_VTX_FMT_Z)
1144 vtx_size++;
1145 return vtx_size;
1146}
1147
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001148static int r100_packet0_check(struct radeon_cs_parser *p,
Dave Airlie551ebd82009-09-01 15:25:57 +10001149 struct radeon_cs_packet *pkt,
1150 unsigned idx, unsigned reg)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001151{
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001152 struct radeon_cs_reloc *reloc;
Dave Airlie551ebd82009-09-01 15:25:57 +10001153 struct r100_cs_track *track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001154 volatile uint32_t *ib;
1155 uint32_t tmp;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001156 int r;
Dave Airlie551ebd82009-09-01 15:25:57 +10001157 int i, face;
Dave Airliee024e112009-06-24 09:48:08 +10001158 u32 tile_flags = 0;
Dave Airlie513bcb42009-09-23 16:56:27 +10001159 u32 idx_value;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001160
1161 ib = p->ib->ptr;
Dave Airlie551ebd82009-09-01 15:25:57 +10001162 track = (struct r100_cs_track *)p->track;
1163
Dave Airlie513bcb42009-09-23 16:56:27 +10001164 idx_value = radeon_get_ib_value(p, idx);
1165
Dave Airlie551ebd82009-09-01 15:25:57 +10001166 switch (reg) {
1167 case RADEON_CRTC_GUI_TRIG_VLINE:
1168 r = r100_cs_packet_parse_vline(p);
1169 if (r) {
1170 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1171 idx, reg);
1172 r100_cs_dump_packet(p, pkt);
1173 return r;
1174 }
1175 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001176 /* FIXME: only allow PACKET3 blit? easier to check for out of
1177 * range access */
Dave Airlie551ebd82009-09-01 15:25:57 +10001178 case RADEON_DST_PITCH_OFFSET:
1179 case RADEON_SRC_PITCH_OFFSET:
1180 r = r100_reloc_pitch_offset(p, pkt, idx, reg);
1181 if (r)
1182 return r;
1183 break;
1184 case RADEON_RB3D_DEPTHOFFSET:
1185 r = r100_cs_packet_next_reloc(p, &reloc);
1186 if (r) {
1187 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1188 idx, reg);
1189 r100_cs_dump_packet(p, pkt);
1190 return r;
1191 }
1192 track->zb.robj = reloc->robj;
Dave Airlie513bcb42009-09-23 16:56:27 +10001193 track->zb.offset = idx_value;
1194 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Dave Airlie551ebd82009-09-01 15:25:57 +10001195 break;
1196 case RADEON_RB3D_COLOROFFSET:
1197 r = r100_cs_packet_next_reloc(p, &reloc);
1198 if (r) {
1199 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1200 idx, reg);
1201 r100_cs_dump_packet(p, pkt);
1202 return r;
1203 }
1204 track->cb[0].robj = reloc->robj;
Dave Airlie513bcb42009-09-23 16:56:27 +10001205 track->cb[0].offset = idx_value;
1206 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Dave Airlie551ebd82009-09-01 15:25:57 +10001207 break;
1208 case RADEON_PP_TXOFFSET_0:
1209 case RADEON_PP_TXOFFSET_1:
1210 case RADEON_PP_TXOFFSET_2:
1211 i = (reg - RADEON_PP_TXOFFSET_0) / 24;
1212 r = r100_cs_packet_next_reloc(p, &reloc);
1213 if (r) {
1214 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1215 idx, reg);
1216 r100_cs_dump_packet(p, pkt);
1217 return r;
1218 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001219 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Dave Airlie551ebd82009-09-01 15:25:57 +10001220 track->textures[i].robj = reloc->robj;
1221 break;
1222 case RADEON_PP_CUBIC_OFFSET_T0_0:
1223 case RADEON_PP_CUBIC_OFFSET_T0_1:
1224 case RADEON_PP_CUBIC_OFFSET_T0_2:
1225 case RADEON_PP_CUBIC_OFFSET_T0_3:
1226 case RADEON_PP_CUBIC_OFFSET_T0_4:
1227 i = (reg - RADEON_PP_CUBIC_OFFSET_T0_0) / 4;
1228 r = r100_cs_packet_next_reloc(p, &reloc);
1229 if (r) {
1230 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1231 idx, reg);
1232 r100_cs_dump_packet(p, pkt);
1233 return r;
1234 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001235 track->textures[0].cube_info[i].offset = idx_value;
1236 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Dave Airlie551ebd82009-09-01 15:25:57 +10001237 track->textures[0].cube_info[i].robj = reloc->robj;
1238 break;
1239 case RADEON_PP_CUBIC_OFFSET_T1_0:
1240 case RADEON_PP_CUBIC_OFFSET_T1_1:
1241 case RADEON_PP_CUBIC_OFFSET_T1_2:
1242 case RADEON_PP_CUBIC_OFFSET_T1_3:
1243 case RADEON_PP_CUBIC_OFFSET_T1_4:
1244 i = (reg - RADEON_PP_CUBIC_OFFSET_T1_0) / 4;
1245 r = r100_cs_packet_next_reloc(p, &reloc);
1246 if (r) {
1247 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1248 idx, reg);
1249 r100_cs_dump_packet(p, pkt);
1250 return r;
1251 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001252 track->textures[1].cube_info[i].offset = idx_value;
1253 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Dave Airlie551ebd82009-09-01 15:25:57 +10001254 track->textures[1].cube_info[i].robj = reloc->robj;
1255 break;
1256 case RADEON_PP_CUBIC_OFFSET_T2_0:
1257 case RADEON_PP_CUBIC_OFFSET_T2_1:
1258 case RADEON_PP_CUBIC_OFFSET_T2_2:
1259 case RADEON_PP_CUBIC_OFFSET_T2_3:
1260 case RADEON_PP_CUBIC_OFFSET_T2_4:
1261 i = (reg - RADEON_PP_CUBIC_OFFSET_T2_0) / 4;
1262 r = r100_cs_packet_next_reloc(p, &reloc);
1263 if (r) {
1264 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1265 idx, reg);
1266 r100_cs_dump_packet(p, pkt);
1267 return r;
1268 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001269 track->textures[2].cube_info[i].offset = idx_value;
1270 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Dave Airlie551ebd82009-09-01 15:25:57 +10001271 track->textures[2].cube_info[i].robj = reloc->robj;
1272 break;
1273 case RADEON_RE_WIDTH_HEIGHT:
Dave Airlie513bcb42009-09-23 16:56:27 +10001274 track->maxy = ((idx_value >> 16) & 0x7FF);
Dave Airlie551ebd82009-09-01 15:25:57 +10001275 break;
1276 case RADEON_RB3D_COLORPITCH:
1277 r = r100_cs_packet_next_reloc(p, &reloc);
1278 if (r) {
1279 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1280 idx, reg);
1281 r100_cs_dump_packet(p, pkt);
1282 return r;
1283 }
Dave Airliee024e112009-06-24 09:48:08 +10001284
Dave Airlie551ebd82009-09-01 15:25:57 +10001285 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
1286 tile_flags |= RADEON_COLOR_TILE_ENABLE;
1287 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
1288 tile_flags |= RADEON_COLOR_MICROTILE_ENABLE;
Dave Airliee024e112009-06-24 09:48:08 +10001289
Dave Airlie513bcb42009-09-23 16:56:27 +10001290 tmp = idx_value & ~(0x7 << 16);
Dave Airlie551ebd82009-09-01 15:25:57 +10001291 tmp |= tile_flags;
1292 ib[idx] = tmp;
1293
Dave Airlie513bcb42009-09-23 16:56:27 +10001294 track->cb[0].pitch = idx_value & RADEON_COLORPITCH_MASK;
Dave Airlie551ebd82009-09-01 15:25:57 +10001295 break;
1296 case RADEON_RB3D_DEPTHPITCH:
Dave Airlie513bcb42009-09-23 16:56:27 +10001297 track->zb.pitch = idx_value & RADEON_DEPTHPITCH_MASK;
Dave Airlie551ebd82009-09-01 15:25:57 +10001298 break;
1299 case RADEON_RB3D_CNTL:
Dave Airlie513bcb42009-09-23 16:56:27 +10001300 switch ((idx_value >> RADEON_RB3D_COLOR_FORMAT_SHIFT) & 0x1f) {
Dave Airlie551ebd82009-09-01 15:25:57 +10001301 case 7:
1302 case 8:
1303 case 9:
1304 case 11:
1305 case 12:
1306 track->cb[0].cpp = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001307 break;
Dave Airlie551ebd82009-09-01 15:25:57 +10001308 case 3:
1309 case 4:
1310 case 15:
1311 track->cb[0].cpp = 2;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001312 break;
Dave Airlie551ebd82009-09-01 15:25:57 +10001313 case 6:
1314 track->cb[0].cpp = 4;
Dave Airlie17782d92009-08-21 10:07:54 +10001315 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001316 default:
Dave Airlie551ebd82009-09-01 15:25:57 +10001317 DRM_ERROR("Invalid color buffer format (%d) !\n",
Dave Airlie513bcb42009-09-23 16:56:27 +10001318 ((idx_value >> RADEON_RB3D_COLOR_FORMAT_SHIFT) & 0x1f));
Dave Airlie551ebd82009-09-01 15:25:57 +10001319 return -EINVAL;
1320 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001321 track->z_enabled = !!(idx_value & RADEON_Z_ENABLE);
Dave Airlie551ebd82009-09-01 15:25:57 +10001322 break;
1323 case RADEON_RB3D_ZSTENCILCNTL:
Dave Airlie513bcb42009-09-23 16:56:27 +10001324 switch (idx_value & 0xf) {
Dave Airlie551ebd82009-09-01 15:25:57 +10001325 case 0:
1326 track->zb.cpp = 2;
1327 break;
1328 case 2:
1329 case 3:
1330 case 4:
1331 case 5:
1332 case 9:
1333 case 11:
1334 track->zb.cpp = 4;
1335 break;
1336 default:
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001337 break;
1338 }
Dave Airlie551ebd82009-09-01 15:25:57 +10001339 break;
1340 case RADEON_RB3D_ZPASS_ADDR:
1341 r = r100_cs_packet_next_reloc(p, &reloc);
1342 if (r) {
1343 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1344 idx, reg);
1345 r100_cs_dump_packet(p, pkt);
1346 return r;
1347 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001348 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Dave Airlie551ebd82009-09-01 15:25:57 +10001349 break;
1350 case RADEON_PP_CNTL:
1351 {
Dave Airlie513bcb42009-09-23 16:56:27 +10001352 uint32_t temp = idx_value >> 4;
Dave Airlie551ebd82009-09-01 15:25:57 +10001353 for (i = 0; i < track->num_texture; i++)
1354 track->textures[i].enabled = !!(temp & (1 << i));
1355 }
1356 break;
1357 case RADEON_SE_VF_CNTL:
Dave Airlie513bcb42009-09-23 16:56:27 +10001358 track->vap_vf_cntl = idx_value;
Dave Airlie551ebd82009-09-01 15:25:57 +10001359 break;
1360 case RADEON_SE_VTX_FMT:
Dave Airlie513bcb42009-09-23 16:56:27 +10001361 track->vtx_size = r100_get_vtx_size(idx_value);
Dave Airlie551ebd82009-09-01 15:25:57 +10001362 break;
1363 case RADEON_PP_TEX_SIZE_0:
1364 case RADEON_PP_TEX_SIZE_1:
1365 case RADEON_PP_TEX_SIZE_2:
1366 i = (reg - RADEON_PP_TEX_SIZE_0) / 8;
Dave Airlie513bcb42009-09-23 16:56:27 +10001367 track->textures[i].width = (idx_value & RADEON_TEX_USIZE_MASK) + 1;
1368 track->textures[i].height = ((idx_value & RADEON_TEX_VSIZE_MASK) >> RADEON_TEX_VSIZE_SHIFT) + 1;
Dave Airlie551ebd82009-09-01 15:25:57 +10001369 break;
1370 case RADEON_PP_TEX_PITCH_0:
1371 case RADEON_PP_TEX_PITCH_1:
1372 case RADEON_PP_TEX_PITCH_2:
1373 i = (reg - RADEON_PP_TEX_PITCH_0) / 8;
Dave Airlie513bcb42009-09-23 16:56:27 +10001374 track->textures[i].pitch = idx_value + 32;
Dave Airlie551ebd82009-09-01 15:25:57 +10001375 break;
1376 case RADEON_PP_TXFILTER_0:
1377 case RADEON_PP_TXFILTER_1:
1378 case RADEON_PP_TXFILTER_2:
1379 i = (reg - RADEON_PP_TXFILTER_0) / 24;
Dave Airlie513bcb42009-09-23 16:56:27 +10001380 track->textures[i].num_levels = ((idx_value & RADEON_MAX_MIP_LEVEL_MASK)
Dave Airlie551ebd82009-09-01 15:25:57 +10001381 >> RADEON_MAX_MIP_LEVEL_SHIFT);
Dave Airlie513bcb42009-09-23 16:56:27 +10001382 tmp = (idx_value >> 23) & 0x7;
Dave Airlie551ebd82009-09-01 15:25:57 +10001383 if (tmp == 2 || tmp == 6)
1384 track->textures[i].roundup_w = false;
Dave Airlie513bcb42009-09-23 16:56:27 +10001385 tmp = (idx_value >> 27) & 0x7;
Dave Airlie551ebd82009-09-01 15:25:57 +10001386 if (tmp == 2 || tmp == 6)
1387 track->textures[i].roundup_h = false;
1388 break;
1389 case RADEON_PP_TXFORMAT_0:
1390 case RADEON_PP_TXFORMAT_1:
1391 case RADEON_PP_TXFORMAT_2:
1392 i = (reg - RADEON_PP_TXFORMAT_0) / 24;
Dave Airlie513bcb42009-09-23 16:56:27 +10001393 if (idx_value & RADEON_TXFORMAT_NON_POWER2) {
Dave Airlie551ebd82009-09-01 15:25:57 +10001394 track->textures[i].use_pitch = 1;
1395 } else {
1396 track->textures[i].use_pitch = 0;
Dave Airlie513bcb42009-09-23 16:56:27 +10001397 track->textures[i].width = 1 << ((idx_value >> RADEON_TXFORMAT_WIDTH_SHIFT) & RADEON_TXFORMAT_WIDTH_MASK);
1398 track->textures[i].height = 1 << ((idx_value >> RADEON_TXFORMAT_HEIGHT_SHIFT) & RADEON_TXFORMAT_HEIGHT_MASK);
Dave Airlie551ebd82009-09-01 15:25:57 +10001399 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001400 if (idx_value & RADEON_TXFORMAT_CUBIC_MAP_ENABLE)
Dave Airlie551ebd82009-09-01 15:25:57 +10001401 track->textures[i].tex_coord_type = 2;
Dave Airlie513bcb42009-09-23 16:56:27 +10001402 switch ((idx_value & RADEON_TXFORMAT_FORMAT_MASK)) {
Dave Airlie551ebd82009-09-01 15:25:57 +10001403 case RADEON_TXFORMAT_I8:
1404 case RADEON_TXFORMAT_RGB332:
1405 case RADEON_TXFORMAT_Y8:
1406 track->textures[i].cpp = 1;
1407 break;
1408 case RADEON_TXFORMAT_AI88:
1409 case RADEON_TXFORMAT_ARGB1555:
1410 case RADEON_TXFORMAT_RGB565:
1411 case RADEON_TXFORMAT_ARGB4444:
1412 case RADEON_TXFORMAT_VYUY422:
1413 case RADEON_TXFORMAT_YVYU422:
Dave Airlie551ebd82009-09-01 15:25:57 +10001414 case RADEON_TXFORMAT_SHADOW16:
1415 case RADEON_TXFORMAT_LDUDV655:
1416 case RADEON_TXFORMAT_DUDV88:
1417 track->textures[i].cpp = 2;
1418 break;
1419 case RADEON_TXFORMAT_ARGB8888:
1420 case RADEON_TXFORMAT_RGBA8888:
Dave Airlie551ebd82009-09-01 15:25:57 +10001421 case RADEON_TXFORMAT_SHADOW32:
1422 case RADEON_TXFORMAT_LDUDUV8888:
1423 track->textures[i].cpp = 4;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001424 break;
Dave Airlied785d782009-12-07 13:16:06 +10001425 case RADEON_TXFORMAT_DXT1:
1426 track->textures[i].cpp = 1;
1427 track->textures[i].compress_format = R100_TRACK_COMP_DXT1;
1428 break;
1429 case RADEON_TXFORMAT_DXT23:
1430 case RADEON_TXFORMAT_DXT45:
1431 track->textures[i].cpp = 1;
1432 track->textures[i].compress_format = R100_TRACK_COMP_DXT35;
1433 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001434 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001435 track->textures[i].cube_info[4].width = 1 << ((idx_value >> 16) & 0xf);
1436 track->textures[i].cube_info[4].height = 1 << ((idx_value >> 20) & 0xf);
Dave Airlie551ebd82009-09-01 15:25:57 +10001437 break;
1438 case RADEON_PP_CUBIC_FACES_0:
1439 case RADEON_PP_CUBIC_FACES_1:
1440 case RADEON_PP_CUBIC_FACES_2:
Dave Airlie513bcb42009-09-23 16:56:27 +10001441 tmp = idx_value;
Dave Airlie551ebd82009-09-01 15:25:57 +10001442 i = (reg - RADEON_PP_CUBIC_FACES_0) / 4;
1443 for (face = 0; face < 4; face++) {
1444 track->textures[i].cube_info[face].width = 1 << ((tmp >> (face * 8)) & 0xf);
1445 track->textures[i].cube_info[face].height = 1 << ((tmp >> ((face * 8) + 4)) & 0xf);
1446 }
1447 break;
1448 default:
1449 printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n",
1450 reg, idx);
1451 return -EINVAL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001452 }
1453 return 0;
1454}
1455
Jerome Glisse068a1172009-06-17 13:28:30 +02001456int r100_cs_track_check_pkt3_indx_buffer(struct radeon_cs_parser *p,
1457 struct radeon_cs_packet *pkt,
Jerome Glisse4c788672009-11-20 14:29:23 +01001458 struct radeon_bo *robj)
Jerome Glisse068a1172009-06-17 13:28:30 +02001459{
Jerome Glisse068a1172009-06-17 13:28:30 +02001460 unsigned idx;
Dave Airlie513bcb42009-09-23 16:56:27 +10001461 u32 value;
Jerome Glisse068a1172009-06-17 13:28:30 +02001462 idx = pkt->idx + 1;
Dave Airlie513bcb42009-09-23 16:56:27 +10001463 value = radeon_get_ib_value(p, idx + 2);
Jerome Glisse4c788672009-11-20 14:29:23 +01001464 if ((value + 1) > radeon_bo_size(robj)) {
Jerome Glisse068a1172009-06-17 13:28:30 +02001465 DRM_ERROR("[drm] Buffer too small for PACKET3 INDX_BUFFER "
1466 "(need %u have %lu) !\n",
Dave Airlie513bcb42009-09-23 16:56:27 +10001467 value + 1,
Jerome Glisse4c788672009-11-20 14:29:23 +01001468 radeon_bo_size(robj));
Jerome Glisse068a1172009-06-17 13:28:30 +02001469 return -EINVAL;
1470 }
1471 return 0;
1472}
1473
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001474static int r100_packet3_check(struct radeon_cs_parser *p,
1475 struct radeon_cs_packet *pkt)
1476{
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001477 struct radeon_cs_reloc *reloc;
Dave Airlie551ebd82009-09-01 15:25:57 +10001478 struct r100_cs_track *track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001479 unsigned idx;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001480 volatile uint32_t *ib;
1481 int r;
1482
1483 ib = p->ib->ptr;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001484 idx = pkt->idx + 1;
Dave Airlie551ebd82009-09-01 15:25:57 +10001485 track = (struct r100_cs_track *)p->track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001486 switch (pkt->opcode) {
1487 case PACKET3_3D_LOAD_VBPNTR:
Dave Airlie513bcb42009-09-23 16:56:27 +10001488 r = r100_packet3_load_vbpntr(p, pkt, idx);
1489 if (r)
1490 return r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001491 break;
1492 case PACKET3_INDX_BUFFER:
1493 r = r100_cs_packet_next_reloc(p, &reloc);
1494 if (r) {
1495 DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode);
1496 r100_cs_dump_packet(p, pkt);
1497 return r;
1498 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001499 ib[idx+1] = radeon_get_ib_value(p, idx+1) + ((u32)reloc->lobj.gpu_offset);
Jerome Glisse068a1172009-06-17 13:28:30 +02001500 r = r100_cs_track_check_pkt3_indx_buffer(p, pkt, reloc->robj);
1501 if (r) {
1502 return r;
1503 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001504 break;
1505 case 0x23:
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001506 /* 3D_RNDR_GEN_INDX_PRIM on r100/r200 */
1507 r = r100_cs_packet_next_reloc(p, &reloc);
1508 if (r) {
1509 DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode);
1510 r100_cs_dump_packet(p, pkt);
1511 return r;
1512 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001513 ib[idx] = radeon_get_ib_value(p, idx) + ((u32)reloc->lobj.gpu_offset);
Dave Airlie551ebd82009-09-01 15:25:57 +10001514 track->num_arrays = 1;
Dave Airlie513bcb42009-09-23 16:56:27 +10001515 track->vtx_size = r100_get_vtx_size(radeon_get_ib_value(p, idx + 2));
Dave Airlie551ebd82009-09-01 15:25:57 +10001516
1517 track->arrays[0].robj = reloc->robj;
1518 track->arrays[0].esize = track->vtx_size;
1519
Dave Airlie513bcb42009-09-23 16:56:27 +10001520 track->max_indx = radeon_get_ib_value(p, idx+1);
Dave Airlie551ebd82009-09-01 15:25:57 +10001521
Dave Airlie513bcb42009-09-23 16:56:27 +10001522 track->vap_vf_cntl = radeon_get_ib_value(p, idx+3);
Dave Airlie551ebd82009-09-01 15:25:57 +10001523 track->immd_dwords = pkt->count - 1;
1524 r = r100_cs_track_check(p->rdev, track);
1525 if (r)
1526 return r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001527 break;
1528 case PACKET3_3D_DRAW_IMMD:
Dave Airlie513bcb42009-09-23 16:56:27 +10001529 if (((radeon_get_ib_value(p, idx + 1) >> 4) & 0x3) != 3) {
Dave Airlie551ebd82009-09-01 15:25:57 +10001530 DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
1531 return -EINVAL;
1532 }
Alex Deuchercf57fc72010-01-18 20:20:07 -05001533 track->vtx_size = r100_get_vtx_size(radeon_get_ib_value(p, idx + 0));
Dave Airlie513bcb42009-09-23 16:56:27 +10001534 track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
Dave Airlie551ebd82009-09-01 15:25:57 +10001535 track->immd_dwords = pkt->count - 1;
1536 r = r100_cs_track_check(p->rdev, track);
1537 if (r)
1538 return r;
1539 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001540 /* triggers drawing using in-packet vertex data */
1541 case PACKET3_3D_DRAW_IMMD_2:
Dave Airlie513bcb42009-09-23 16:56:27 +10001542 if (((radeon_get_ib_value(p, idx) >> 4) & 0x3) != 3) {
Dave Airlie551ebd82009-09-01 15:25:57 +10001543 DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
1544 return -EINVAL;
1545 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001546 track->vap_vf_cntl = radeon_get_ib_value(p, idx);
Dave Airlie551ebd82009-09-01 15:25:57 +10001547 track->immd_dwords = pkt->count;
1548 r = r100_cs_track_check(p->rdev, track);
1549 if (r)
1550 return r;
1551 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001552 /* triggers drawing using in-packet vertex data */
1553 case PACKET3_3D_DRAW_VBUF_2:
Dave Airlie513bcb42009-09-23 16:56:27 +10001554 track->vap_vf_cntl = radeon_get_ib_value(p, idx);
Dave Airlie551ebd82009-09-01 15:25:57 +10001555 r = r100_cs_track_check(p->rdev, track);
1556 if (r)
1557 return r;
1558 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001559 /* triggers drawing of vertex buffers setup elsewhere */
1560 case PACKET3_3D_DRAW_INDX_2:
Dave Airlie513bcb42009-09-23 16:56:27 +10001561 track->vap_vf_cntl = radeon_get_ib_value(p, idx);
Dave Airlie551ebd82009-09-01 15:25:57 +10001562 r = r100_cs_track_check(p->rdev, track);
1563 if (r)
1564 return r;
1565 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001566 /* triggers drawing using indices to vertex buffer */
1567 case PACKET3_3D_DRAW_VBUF:
Dave Airlie513bcb42009-09-23 16:56:27 +10001568 track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
Dave Airlie551ebd82009-09-01 15:25:57 +10001569 r = r100_cs_track_check(p->rdev, track);
1570 if (r)
1571 return r;
1572 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001573 /* triggers drawing of vertex buffers setup elsewhere */
1574 case PACKET3_3D_DRAW_INDX:
Dave Airlie513bcb42009-09-23 16:56:27 +10001575 track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
Dave Airlie551ebd82009-09-01 15:25:57 +10001576 r = r100_cs_track_check(p->rdev, track);
1577 if (r)
1578 return r;
1579 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001580 /* triggers drawing using indices to vertex buffer */
1581 case PACKET3_NOP:
1582 break;
1583 default:
1584 DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
1585 return -EINVAL;
1586 }
1587 return 0;
1588}
1589
1590int r100_cs_parse(struct radeon_cs_parser *p)
1591{
1592 struct radeon_cs_packet pkt;
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001593 struct r100_cs_track *track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001594 int r;
1595
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001596 track = kzalloc(sizeof(*track), GFP_KERNEL);
1597 r100_cs_track_clear(p->rdev, track);
1598 p->track = track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001599 do {
1600 r = r100_cs_packet_parse(p, &pkt, p->idx);
1601 if (r) {
1602 return r;
1603 }
1604 p->idx += pkt.count + 2;
1605 switch (pkt.type) {
Jerome Glisse068a1172009-06-17 13:28:30 +02001606 case PACKET_TYPE0:
Dave Airlie551ebd82009-09-01 15:25:57 +10001607 if (p->rdev->family >= CHIP_R200)
1608 r = r100_cs_parse_packet0(p, &pkt,
1609 p->rdev->config.r100.reg_safe_bm,
1610 p->rdev->config.r100.reg_safe_bm_size,
1611 &r200_packet0_check);
1612 else
1613 r = r100_cs_parse_packet0(p, &pkt,
1614 p->rdev->config.r100.reg_safe_bm,
1615 p->rdev->config.r100.reg_safe_bm_size,
1616 &r100_packet0_check);
Jerome Glisse068a1172009-06-17 13:28:30 +02001617 break;
1618 case PACKET_TYPE2:
1619 break;
1620 case PACKET_TYPE3:
1621 r = r100_packet3_check(p, &pkt);
1622 break;
1623 default:
1624 DRM_ERROR("Unknown packet type %d !\n",
1625 pkt.type);
1626 return -EINVAL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001627 }
1628 if (r) {
1629 return r;
1630 }
1631 } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
1632 return 0;
1633}
1634
1635
1636/*
1637 * Global GPU functions
1638 */
1639void r100_errata(struct radeon_device *rdev)
1640{
1641 rdev->pll_errata = 0;
1642
1643 if (rdev->family == CHIP_RV200 || rdev->family == CHIP_RS200) {
1644 rdev->pll_errata |= CHIP_ERRATA_PLL_DUMMYREADS;
1645 }
1646
1647 if (rdev->family == CHIP_RV100 ||
1648 rdev->family == CHIP_RS100 ||
1649 rdev->family == CHIP_RS200) {
1650 rdev->pll_errata |= CHIP_ERRATA_PLL_DELAY;
1651 }
1652}
1653
1654/* Wait for vertical sync on primary CRTC */
1655void r100_gpu_wait_for_vsync(struct radeon_device *rdev)
1656{
1657 uint32_t crtc_gen_cntl, tmp;
1658 int i;
1659
1660 crtc_gen_cntl = RREG32(RADEON_CRTC_GEN_CNTL);
1661 if ((crtc_gen_cntl & RADEON_CRTC_DISP_REQ_EN_B) ||
1662 !(crtc_gen_cntl & RADEON_CRTC_EN)) {
1663 return;
1664 }
1665 /* Clear the CRTC_VBLANK_SAVE bit */
1666 WREG32(RADEON_CRTC_STATUS, RADEON_CRTC_VBLANK_SAVE_CLEAR);
1667 for (i = 0; i < rdev->usec_timeout; i++) {
1668 tmp = RREG32(RADEON_CRTC_STATUS);
1669 if (tmp & RADEON_CRTC_VBLANK_SAVE) {
1670 return;
1671 }
1672 DRM_UDELAY(1);
1673 }
1674}
1675
1676/* Wait for vertical sync on secondary CRTC */
1677void r100_gpu_wait_for_vsync2(struct radeon_device *rdev)
1678{
1679 uint32_t crtc2_gen_cntl, tmp;
1680 int i;
1681
1682 crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
1683 if ((crtc2_gen_cntl & RADEON_CRTC2_DISP_REQ_EN_B) ||
1684 !(crtc2_gen_cntl & RADEON_CRTC2_EN))
1685 return;
1686
1687 /* Clear the CRTC_VBLANK_SAVE bit */
1688 WREG32(RADEON_CRTC2_STATUS, RADEON_CRTC2_VBLANK_SAVE_CLEAR);
1689 for (i = 0; i < rdev->usec_timeout; i++) {
1690 tmp = RREG32(RADEON_CRTC2_STATUS);
1691 if (tmp & RADEON_CRTC2_VBLANK_SAVE) {
1692 return;
1693 }
1694 DRM_UDELAY(1);
1695 }
1696}
1697
1698int r100_rbbm_fifo_wait_for_entry(struct radeon_device *rdev, unsigned n)
1699{
1700 unsigned i;
1701 uint32_t tmp;
1702
1703 for (i = 0; i < rdev->usec_timeout; i++) {
1704 tmp = RREG32(RADEON_RBBM_STATUS) & RADEON_RBBM_FIFOCNT_MASK;
1705 if (tmp >= n) {
1706 return 0;
1707 }
1708 DRM_UDELAY(1);
1709 }
1710 return -1;
1711}
1712
1713int r100_gui_wait_for_idle(struct radeon_device *rdev)
1714{
1715 unsigned i;
1716 uint32_t tmp;
1717
1718 if (r100_rbbm_fifo_wait_for_entry(rdev, 64)) {
1719 printk(KERN_WARNING "radeon: wait for empty RBBM fifo failed !"
1720 " Bad things might happen.\n");
1721 }
1722 for (i = 0; i < rdev->usec_timeout; i++) {
1723 tmp = RREG32(RADEON_RBBM_STATUS);
Alex Deucher4612dc92010-02-05 01:58:28 -05001724 if (!(tmp & RADEON_RBBM_ACTIVE)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001725 return 0;
1726 }
1727 DRM_UDELAY(1);
1728 }
1729 return -1;
1730}
1731
1732int r100_mc_wait_for_idle(struct radeon_device *rdev)
1733{
1734 unsigned i;
1735 uint32_t tmp;
1736
1737 for (i = 0; i < rdev->usec_timeout; i++) {
1738 /* read MC_STATUS */
Alex Deucher4612dc92010-02-05 01:58:28 -05001739 tmp = RREG32(RADEON_MC_STATUS);
1740 if (tmp & RADEON_MC_IDLE) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001741 return 0;
1742 }
1743 DRM_UDELAY(1);
1744 }
1745 return -1;
1746}
1747
Jerome Glisse225758d2010-03-09 14:45:10 +00001748void r100_gpu_lockup_update(struct r100_gpu_lockup *lockup, struct radeon_cp *cp)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001749{
Jerome Glisse225758d2010-03-09 14:45:10 +00001750 lockup->last_cp_rptr = cp->rptr;
1751 lockup->last_jiffies = jiffies;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001752}
1753
Jerome Glisse225758d2010-03-09 14:45:10 +00001754/**
1755 * r100_gpu_cp_is_lockup() - check if CP is lockup by recording information
1756 * @rdev: radeon device structure
1757 * @lockup: r100_gpu_lockup structure holding CP lockup tracking informations
1758 * @cp: radeon_cp structure holding CP information
1759 *
1760 * We don't need to initialize the lockup tracking information as we will either
1761 * have CP rptr to a different value of jiffies wrap around which will force
1762 * initialization of the lockup tracking informations.
1763 *
1764 * A possible false positivie is if we get call after while and last_cp_rptr ==
1765 * the current CP rptr, even if it's unlikely it might happen. To avoid this
1766 * if the elapsed time since last call is bigger than 2 second than we return
1767 * false and update the tracking information. Due to this the caller must call
1768 * r100_gpu_cp_is_lockup several time in less than 2sec for lockup to be reported
1769 * the fencing code should be cautious about that.
1770 *
1771 * Caller should write to the ring to force CP to do something so we don't get
1772 * false positive when CP is just gived nothing to do.
1773 *
1774 **/
1775bool r100_gpu_cp_is_lockup(struct radeon_device *rdev, struct r100_gpu_lockup *lockup, struct radeon_cp *cp)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001776{
Jerome Glisse225758d2010-03-09 14:45:10 +00001777 unsigned long cjiffies, elapsed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001778
Jerome Glisse225758d2010-03-09 14:45:10 +00001779 cjiffies = jiffies;
1780 if (!time_after(cjiffies, lockup->last_jiffies)) {
1781 /* likely a wrap around */
1782 lockup->last_cp_rptr = cp->rptr;
1783 lockup->last_jiffies = jiffies;
1784 return false;
1785 }
1786 if (cp->rptr != lockup->last_cp_rptr) {
1787 /* CP is still working no lockup */
1788 lockup->last_cp_rptr = cp->rptr;
1789 lockup->last_jiffies = jiffies;
1790 return false;
1791 }
1792 elapsed = jiffies_to_msecs(cjiffies - lockup->last_jiffies);
1793 if (elapsed >= 3000) {
1794 /* very likely the improbable case where current
1795 * rptr is equal to last recorded, a while ago, rptr
1796 * this is more likely a false positive update tracking
1797 * information which should force us to be recall at
1798 * latter point
1799 */
1800 lockup->last_cp_rptr = cp->rptr;
1801 lockup->last_jiffies = jiffies;
1802 return false;
1803 }
1804 if (elapsed >= 1000) {
1805 dev_err(rdev->dev, "GPU lockup CP stall for more than %lumsec\n", elapsed);
1806 return true;
1807 }
1808 /* give a chance to the GPU ... */
1809 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001810}
1811
Jerome Glisse225758d2010-03-09 14:45:10 +00001812bool r100_gpu_is_lockup(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001813{
Jerome Glisse225758d2010-03-09 14:45:10 +00001814 u32 rbbm_status;
1815 int r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001816
Jerome Glisse225758d2010-03-09 14:45:10 +00001817 rbbm_status = RREG32(R_000E40_RBBM_STATUS);
1818 if (!G_000E40_GUI_ACTIVE(rbbm_status)) {
1819 r100_gpu_lockup_update(&rdev->config.r100.lockup, &rdev->cp);
1820 return false;
1821 }
1822 /* force CP activities */
1823 r = radeon_ring_lock(rdev, 2);
1824 if (!r) {
1825 /* PACKET2 NOP */
1826 radeon_ring_write(rdev, 0x80000000);
1827 radeon_ring_write(rdev, 0x80000000);
1828 radeon_ring_unlock_commit(rdev);
1829 }
1830 rdev->cp.rptr = RREG32(RADEON_CP_RB_RPTR);
1831 return r100_gpu_cp_is_lockup(rdev, &rdev->config.r100.lockup, &rdev->cp);
1832}
1833
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001834void r100_bm_disable(struct radeon_device *rdev)
1835{
1836 u32 tmp;
1837
1838 /* disable bus mastering */
1839 tmp = RREG32(R_000030_BUS_CNTL);
1840 WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000044);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001841 mdelay(1);
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001842 WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000042);
1843 mdelay(1);
1844 WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000040);
1845 tmp = RREG32(RADEON_BUS_CNTL);
1846 mdelay(1);
1847 pci_read_config_word(rdev->pdev, 0x4, (u16*)&tmp);
1848 pci_write_config_word(rdev->pdev, 0x4, tmp & 0xFFFB);
1849 mdelay(1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001850}
1851
Jerome Glissea2d07b72010-03-09 14:45:11 +00001852int r100_asic_reset(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001853{
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001854 struct r100_mc_save save;
1855 u32 status, tmp;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001856
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001857 r100_mc_stop(rdev, &save);
1858 status = RREG32(R_000E40_RBBM_STATUS);
1859 if (!G_000E40_GUI_ACTIVE(status)) {
1860 return 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001861 }
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001862 status = RREG32(R_000E40_RBBM_STATUS);
1863 dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
1864 /* stop CP */
1865 WREG32(RADEON_CP_CSQ_CNTL, 0);
1866 tmp = RREG32(RADEON_CP_RB_CNTL);
1867 WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA);
1868 WREG32(RADEON_CP_RB_RPTR_WR, 0);
1869 WREG32(RADEON_CP_RB_WPTR, 0);
1870 WREG32(RADEON_CP_RB_CNTL, tmp);
1871 /* save PCI state */
1872 pci_save_state(rdev->pdev);
1873 /* disable bus mastering */
1874 r100_bm_disable(rdev);
1875 WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_SE(1) |
1876 S_0000F0_SOFT_RESET_RE(1) |
1877 S_0000F0_SOFT_RESET_PP(1) |
1878 S_0000F0_SOFT_RESET_RB(1));
1879 RREG32(R_0000F0_RBBM_SOFT_RESET);
1880 mdelay(500);
1881 WREG32(R_0000F0_RBBM_SOFT_RESET, 0);
1882 mdelay(1);
1883 status = RREG32(R_000E40_RBBM_STATUS);
1884 dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001885 /* reset CP */
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001886 WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_CP(1));
1887 RREG32(R_0000F0_RBBM_SOFT_RESET);
1888 mdelay(500);
1889 WREG32(R_0000F0_RBBM_SOFT_RESET, 0);
1890 mdelay(1);
1891 status = RREG32(R_000E40_RBBM_STATUS);
1892 dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
1893 /* restore PCI & busmastering */
1894 pci_restore_state(rdev->pdev);
1895 r100_enable_bm(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001896 /* Check if GPU is idle */
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001897 if (G_000E40_SE_BUSY(status) || G_000E40_RE_BUSY(status) ||
1898 G_000E40_TAM_BUSY(status) || G_000E40_PB_BUSY(status)) {
1899 dev_err(rdev->dev, "failed to reset GPU\n");
1900 rdev->gpu_lockup = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001901 return -1;
1902 }
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001903 r100_mc_resume(rdev, &save);
1904 dev_info(rdev->dev, "GPU reset succeed\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001905 return 0;
1906}
1907
Alex Deucher92cde002009-12-04 10:55:12 -05001908void r100_set_common_regs(struct radeon_device *rdev)
1909{
Alex Deucher2739d492010-02-05 03:34:16 -05001910 struct drm_device *dev = rdev->ddev;
1911 bool force_dac2 = false;
Dave Airlied6680462010-03-31 13:41:35 +10001912 u32 tmp;
Alex Deucher2739d492010-02-05 03:34:16 -05001913
Alex Deucher92cde002009-12-04 10:55:12 -05001914 /* set these so they don't interfere with anything */
1915 WREG32(RADEON_OV0_SCALE_CNTL, 0);
1916 WREG32(RADEON_SUBPIC_CNTL, 0);
1917 WREG32(RADEON_VIPH_CONTROL, 0);
1918 WREG32(RADEON_I2C_CNTL_1, 0);
1919 WREG32(RADEON_DVI_I2C_CNTL_1, 0);
1920 WREG32(RADEON_CAP0_TRIG_CNTL, 0);
1921 WREG32(RADEON_CAP1_TRIG_CNTL, 0);
Alex Deucher2739d492010-02-05 03:34:16 -05001922
1923 /* always set up dac2 on rn50 and some rv100 as lots
1924 * of servers seem to wire it up to a VGA port but
1925 * don't report it in the bios connector
1926 * table.
1927 */
1928 switch (dev->pdev->device) {
1929 /* RN50 */
1930 case 0x515e:
1931 case 0x5969:
1932 force_dac2 = true;
1933 break;
1934 /* RV100*/
1935 case 0x5159:
1936 case 0x515a:
1937 /* DELL triple head servers */
1938 if ((dev->pdev->subsystem_vendor == 0x1028 /* DELL */) &&
1939 ((dev->pdev->subsystem_device == 0x016c) ||
1940 (dev->pdev->subsystem_device == 0x016d) ||
1941 (dev->pdev->subsystem_device == 0x016e) ||
1942 (dev->pdev->subsystem_device == 0x016f) ||
1943 (dev->pdev->subsystem_device == 0x0170) ||
1944 (dev->pdev->subsystem_device == 0x017d) ||
1945 (dev->pdev->subsystem_device == 0x017e) ||
1946 (dev->pdev->subsystem_device == 0x0183) ||
1947 (dev->pdev->subsystem_device == 0x018a) ||
1948 (dev->pdev->subsystem_device == 0x019a)))
1949 force_dac2 = true;
1950 break;
1951 }
1952
1953 if (force_dac2) {
1954 u32 disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG);
1955 u32 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
1956 u32 dac2_cntl = RREG32(RADEON_DAC_CNTL2);
1957
1958 /* For CRT on DAC2, don't turn it on if BIOS didn't
1959 enable it, even it's detected.
1960 */
1961
1962 /* force it to crtc0 */
1963 dac2_cntl &= ~RADEON_DAC2_DAC_CLK_SEL;
1964 dac2_cntl |= RADEON_DAC2_DAC2_CLK_SEL;
1965 disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
1966
1967 /* set up the TV DAC */
1968 tv_dac_cntl &= ~(RADEON_TV_DAC_PEDESTAL |
1969 RADEON_TV_DAC_STD_MASK |
1970 RADEON_TV_DAC_RDACPD |
1971 RADEON_TV_DAC_GDACPD |
1972 RADEON_TV_DAC_BDACPD |
1973 RADEON_TV_DAC_BGADJ_MASK |
1974 RADEON_TV_DAC_DACADJ_MASK);
1975 tv_dac_cntl |= (RADEON_TV_DAC_NBLANK |
1976 RADEON_TV_DAC_NHOLD |
1977 RADEON_TV_DAC_STD_PS2 |
1978 (0x58 << 16));
1979
1980 WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1981 WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug);
1982 WREG32(RADEON_DAC_CNTL2, dac2_cntl);
1983 }
Dave Airlied6680462010-03-31 13:41:35 +10001984
1985 /* switch PM block to ACPI mode */
1986 tmp = RREG32_PLL(RADEON_PLL_PWRMGT_CNTL);
1987 tmp &= ~RADEON_PM_MODE_SEL;
1988 WREG32_PLL(RADEON_PLL_PWRMGT_CNTL, tmp);
1989
Alex Deucher92cde002009-12-04 10:55:12 -05001990}
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001991
1992/*
1993 * VRAM info
1994 */
1995static void r100_vram_get_type(struct radeon_device *rdev)
1996{
1997 uint32_t tmp;
1998
1999 rdev->mc.vram_is_ddr = false;
2000 if (rdev->flags & RADEON_IS_IGP)
2001 rdev->mc.vram_is_ddr = true;
2002 else if (RREG32(RADEON_MEM_SDRAM_MODE_REG) & RADEON_MEM_CFG_TYPE_DDR)
2003 rdev->mc.vram_is_ddr = true;
2004 if ((rdev->family == CHIP_RV100) ||
2005 (rdev->family == CHIP_RS100) ||
2006 (rdev->family == CHIP_RS200)) {
2007 tmp = RREG32(RADEON_MEM_CNTL);
2008 if (tmp & RV100_HALF_MODE) {
2009 rdev->mc.vram_width = 32;
2010 } else {
2011 rdev->mc.vram_width = 64;
2012 }
2013 if (rdev->flags & RADEON_SINGLE_CRTC) {
2014 rdev->mc.vram_width /= 4;
2015 rdev->mc.vram_is_ddr = true;
2016 }
2017 } else if (rdev->family <= CHIP_RV280) {
2018 tmp = RREG32(RADEON_MEM_CNTL);
2019 if (tmp & RADEON_MEM_NUM_CHANNELS_MASK) {
2020 rdev->mc.vram_width = 128;
2021 } else {
2022 rdev->mc.vram_width = 64;
2023 }
2024 } else {
2025 /* newer IGPs */
2026 rdev->mc.vram_width = 128;
2027 }
2028}
2029
Dave Airlie2a0f8912009-07-11 04:44:47 +10002030static u32 r100_get_accessible_vram(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002031{
Dave Airlie2a0f8912009-07-11 04:44:47 +10002032 u32 aper_size;
2033 u8 byte;
2034
2035 aper_size = RREG32(RADEON_CONFIG_APER_SIZE);
2036
2037 /* Set HDP_APER_CNTL only on cards that are known not to be broken,
2038 * that is has the 2nd generation multifunction PCI interface
2039 */
2040 if (rdev->family == CHIP_RV280 ||
2041 rdev->family >= CHIP_RV350) {
2042 WREG32_P(RADEON_HOST_PATH_CNTL, RADEON_HDP_APER_CNTL,
2043 ~RADEON_HDP_APER_CNTL);
2044 DRM_INFO("Generation 2 PCI interface, using max accessible memory\n");
2045 return aper_size * 2;
2046 }
2047
2048 /* Older cards have all sorts of funny issues to deal with. First
2049 * check if it's a multifunction card by reading the PCI config
2050 * header type... Limit those to one aperture size
2051 */
2052 pci_read_config_byte(rdev->pdev, 0xe, &byte);
2053 if (byte & 0x80) {
2054 DRM_INFO("Generation 1 PCI interface in multifunction mode\n");
2055 DRM_INFO("Limiting VRAM to one aperture\n");
2056 return aper_size;
2057 }
2058
2059 /* Single function older card. We read HDP_APER_CNTL to see how the BIOS
2060 * have set it up. We don't write this as it's broken on some ASICs but
2061 * we expect the BIOS to have done the right thing (might be too optimistic...)
2062 */
2063 if (RREG32(RADEON_HOST_PATH_CNTL) & RADEON_HDP_APER_CNTL)
2064 return aper_size * 2;
2065 return aper_size;
2066}
2067
2068void r100_vram_init_sizes(struct radeon_device *rdev)
2069{
2070 u64 config_aper_size;
Dave Airlie2a0f8912009-07-11 04:44:47 +10002071
Jerome Glissed594e462010-02-17 21:54:29 +00002072 /* work out accessible VRAM */
Jerome Glissed594e462010-02-17 21:54:29 +00002073 rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
2074 rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
Jerome Glisse51e5fcd2010-02-19 14:33:54 +00002075 rdev->mc.visible_vram_size = r100_get_accessible_vram(rdev);
2076 /* FIXME we don't use the second aperture yet when we could use it */
2077 if (rdev->mc.visible_vram_size > rdev->mc.aper_size)
2078 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Dave Airlie2a0f8912009-07-11 04:44:47 +10002079 config_aper_size = RREG32(RADEON_CONFIG_APER_SIZE);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002080 if (rdev->flags & RADEON_IS_IGP) {
2081 uint32_t tom;
2082 /* read NB_TOM to get the amount of ram stolen for the GPU */
2083 tom = RREG32(RADEON_NB_TOM);
Dave Airlie7a50f012009-07-21 20:39:30 +10002084 rdev->mc.real_vram_size = (((tom >> 16) - (tom & 0xffff) + 1) << 16);
Dave Airlie7a50f012009-07-21 20:39:30 +10002085 WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size);
2086 rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002087 } else {
Dave Airlie7a50f012009-07-21 20:39:30 +10002088 rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002089 /* Some production boards of m6 will report 0
2090 * if it's 8 MB
2091 */
Dave Airlie7a50f012009-07-21 20:39:30 +10002092 if (rdev->mc.real_vram_size == 0) {
2093 rdev->mc.real_vram_size = 8192 * 1024;
2094 WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002095 }
Jerome Glissed594e462010-02-17 21:54:29 +00002096 /* Fix for RN50, M6, M7 with 8/16/32(??) MBs of VRAM -
2097 * Novell bug 204882 + along with lots of ubuntu ones
2098 */
Dave Airlie7a50f012009-07-21 20:39:30 +10002099 if (config_aper_size > rdev->mc.real_vram_size)
2100 rdev->mc.mc_vram_size = config_aper_size;
2101 else
2102 rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002103 }
Dave Airlie2a0f8912009-07-11 04:44:47 +10002104}
2105
Dave Airlie28d52042009-09-21 14:33:58 +10002106void r100_vga_set_state(struct radeon_device *rdev, bool state)
2107{
2108 uint32_t temp;
2109
2110 temp = RREG32(RADEON_CONFIG_CNTL);
2111 if (state == false) {
2112 temp &= ~(1<<8);
2113 temp |= (1<<9);
2114 } else {
2115 temp &= ~(1<<9);
2116 }
2117 WREG32(RADEON_CONFIG_CNTL, temp);
2118}
2119
Jerome Glissed594e462010-02-17 21:54:29 +00002120void r100_mc_init(struct radeon_device *rdev)
Dave Airlie2a0f8912009-07-11 04:44:47 +10002121{
Jerome Glissed594e462010-02-17 21:54:29 +00002122 u64 base;
Dave Airlie2a0f8912009-07-11 04:44:47 +10002123
Jerome Glissed594e462010-02-17 21:54:29 +00002124 r100_vram_get_type(rdev);
Dave Airlie2a0f8912009-07-11 04:44:47 +10002125 r100_vram_init_sizes(rdev);
Jerome Glissed594e462010-02-17 21:54:29 +00002126 base = rdev->mc.aper_base;
2127 if (rdev->flags & RADEON_IS_IGP)
2128 base = (RREG32(RADEON_NB_TOM) & 0xffff) << 16;
2129 radeon_vram_location(rdev, &rdev->mc, base);
2130 if (!(rdev->flags & RADEON_IS_AGP))
2131 radeon_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -04002132 radeon_update_bandwidth_info(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002133}
2134
2135
2136/*
2137 * Indirect registers accessor
2138 */
2139void r100_pll_errata_after_index(struct radeon_device *rdev)
2140{
2141 if (!(rdev->pll_errata & CHIP_ERRATA_PLL_DUMMYREADS)) {
2142 return;
2143 }
2144 (void)RREG32(RADEON_CLOCK_CNTL_DATA);
2145 (void)RREG32(RADEON_CRTC_GEN_CNTL);
2146}
2147
2148static void r100_pll_errata_after_data(struct radeon_device *rdev)
2149{
2150 /* This workarounds is necessary on RV100, RS100 and RS200 chips
2151 * or the chip could hang on a subsequent access
2152 */
2153 if (rdev->pll_errata & CHIP_ERRATA_PLL_DELAY) {
2154 udelay(5000);
2155 }
2156
2157 /* This function is required to workaround a hardware bug in some (all?)
2158 * revisions of the R300. This workaround should be called after every
2159 * CLOCK_CNTL_INDEX register access. If not, register reads afterward
2160 * may not be correct.
2161 */
2162 if (rdev->pll_errata & CHIP_ERRATA_R300_CG) {
2163 uint32_t save, tmp;
2164
2165 save = RREG32(RADEON_CLOCK_CNTL_INDEX);
2166 tmp = save & ~(0x3f | RADEON_PLL_WR_EN);
2167 WREG32(RADEON_CLOCK_CNTL_INDEX, tmp);
2168 tmp = RREG32(RADEON_CLOCK_CNTL_DATA);
2169 WREG32(RADEON_CLOCK_CNTL_INDEX, save);
2170 }
2171}
2172
2173uint32_t r100_pll_rreg(struct radeon_device *rdev, uint32_t reg)
2174{
2175 uint32_t data;
2176
2177 WREG8(RADEON_CLOCK_CNTL_INDEX, reg & 0x3f);
2178 r100_pll_errata_after_index(rdev);
2179 data = RREG32(RADEON_CLOCK_CNTL_DATA);
2180 r100_pll_errata_after_data(rdev);
2181 return data;
2182}
2183
2184void r100_pll_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
2185{
2186 WREG8(RADEON_CLOCK_CNTL_INDEX, ((reg & 0x3f) | RADEON_PLL_WR_EN));
2187 r100_pll_errata_after_index(rdev);
2188 WREG32(RADEON_CLOCK_CNTL_DATA, v);
2189 r100_pll_errata_after_data(rdev);
2190}
2191
Jerome Glissed4550902009-10-01 10:12:06 +02002192void r100_set_safe_registers(struct radeon_device *rdev)
Jerome Glisse068a1172009-06-17 13:28:30 +02002193{
Dave Airlie551ebd82009-09-01 15:25:57 +10002194 if (ASIC_IS_RN50(rdev)) {
2195 rdev->config.r100.reg_safe_bm = rn50_reg_safe_bm;
2196 rdev->config.r100.reg_safe_bm_size = ARRAY_SIZE(rn50_reg_safe_bm);
2197 } else if (rdev->family < CHIP_R200) {
2198 rdev->config.r100.reg_safe_bm = r100_reg_safe_bm;
2199 rdev->config.r100.reg_safe_bm_size = ARRAY_SIZE(r100_reg_safe_bm);
2200 } else {
Jerome Glissed4550902009-10-01 10:12:06 +02002201 r200_set_safe_registers(rdev);
Dave Airlie551ebd82009-09-01 15:25:57 +10002202 }
Jerome Glisse068a1172009-06-17 13:28:30 +02002203}
2204
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002205/*
2206 * Debugfs info
2207 */
2208#if defined(CONFIG_DEBUG_FS)
2209static int r100_debugfs_rbbm_info(struct seq_file *m, void *data)
2210{
2211 struct drm_info_node *node = (struct drm_info_node *) m->private;
2212 struct drm_device *dev = node->minor->dev;
2213 struct radeon_device *rdev = dev->dev_private;
2214 uint32_t reg, value;
2215 unsigned i;
2216
2217 seq_printf(m, "RBBM_STATUS 0x%08x\n", RREG32(RADEON_RBBM_STATUS));
2218 seq_printf(m, "RBBM_CMDFIFO_STAT 0x%08x\n", RREG32(0xE7C));
2219 seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT));
2220 for (i = 0; i < 64; i++) {
2221 WREG32(RADEON_RBBM_CMDFIFO_ADDR, i | 0x100);
2222 reg = (RREG32(RADEON_RBBM_CMDFIFO_DATA) - 1) >> 2;
2223 WREG32(RADEON_RBBM_CMDFIFO_ADDR, i);
2224 value = RREG32(RADEON_RBBM_CMDFIFO_DATA);
2225 seq_printf(m, "[0x%03X] 0x%04X=0x%08X\n", i, reg, value);
2226 }
2227 return 0;
2228}
2229
2230static int r100_debugfs_cp_ring_info(struct seq_file *m, void *data)
2231{
2232 struct drm_info_node *node = (struct drm_info_node *) m->private;
2233 struct drm_device *dev = node->minor->dev;
2234 struct radeon_device *rdev = dev->dev_private;
2235 uint32_t rdp, wdp;
2236 unsigned count, i, j;
2237
2238 radeon_ring_free_size(rdev);
2239 rdp = RREG32(RADEON_CP_RB_RPTR);
2240 wdp = RREG32(RADEON_CP_RB_WPTR);
2241 count = (rdp + rdev->cp.ring_size - wdp) & rdev->cp.ptr_mask;
2242 seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT));
2243 seq_printf(m, "CP_RB_WPTR 0x%08x\n", wdp);
2244 seq_printf(m, "CP_RB_RPTR 0x%08x\n", rdp);
2245 seq_printf(m, "%u free dwords in ring\n", rdev->cp.ring_free_dw);
2246 seq_printf(m, "%u dwords in ring\n", count);
2247 for (j = 0; j <= count; j++) {
2248 i = (rdp + j) & rdev->cp.ptr_mask;
2249 seq_printf(m, "r[%04d]=0x%08x\n", i, rdev->cp.ring[i]);
2250 }
2251 return 0;
2252}
2253
2254
2255static int r100_debugfs_cp_csq_fifo(struct seq_file *m, void *data)
2256{
2257 struct drm_info_node *node = (struct drm_info_node *) m->private;
2258 struct drm_device *dev = node->minor->dev;
2259 struct radeon_device *rdev = dev->dev_private;
2260 uint32_t csq_stat, csq2_stat, tmp;
2261 unsigned r_rptr, r_wptr, ib1_rptr, ib1_wptr, ib2_rptr, ib2_wptr;
2262 unsigned i;
2263
2264 seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT));
2265 seq_printf(m, "CP_CSQ_MODE 0x%08x\n", RREG32(RADEON_CP_CSQ_MODE));
2266 csq_stat = RREG32(RADEON_CP_CSQ_STAT);
2267 csq2_stat = RREG32(RADEON_CP_CSQ2_STAT);
2268 r_rptr = (csq_stat >> 0) & 0x3ff;
2269 r_wptr = (csq_stat >> 10) & 0x3ff;
2270 ib1_rptr = (csq_stat >> 20) & 0x3ff;
2271 ib1_wptr = (csq2_stat >> 0) & 0x3ff;
2272 ib2_rptr = (csq2_stat >> 10) & 0x3ff;
2273 ib2_wptr = (csq2_stat >> 20) & 0x3ff;
2274 seq_printf(m, "CP_CSQ_STAT 0x%08x\n", csq_stat);
2275 seq_printf(m, "CP_CSQ2_STAT 0x%08x\n", csq2_stat);
2276 seq_printf(m, "Ring rptr %u\n", r_rptr);
2277 seq_printf(m, "Ring wptr %u\n", r_wptr);
2278 seq_printf(m, "Indirect1 rptr %u\n", ib1_rptr);
2279 seq_printf(m, "Indirect1 wptr %u\n", ib1_wptr);
2280 seq_printf(m, "Indirect2 rptr %u\n", ib2_rptr);
2281 seq_printf(m, "Indirect2 wptr %u\n", ib2_wptr);
2282 /* FIXME: 0, 128, 640 depends on fifo setup see cp_init_kms
2283 * 128 = indirect1_start * 8 & 640 = indirect2_start * 8 */
2284 seq_printf(m, "Ring fifo:\n");
2285 for (i = 0; i < 256; i++) {
2286 WREG32(RADEON_CP_CSQ_ADDR, i << 2);
2287 tmp = RREG32(RADEON_CP_CSQ_DATA);
2288 seq_printf(m, "rfifo[%04d]=0x%08X\n", i, tmp);
2289 }
2290 seq_printf(m, "Indirect1 fifo:\n");
2291 for (i = 256; i <= 512; i++) {
2292 WREG32(RADEON_CP_CSQ_ADDR, i << 2);
2293 tmp = RREG32(RADEON_CP_CSQ_DATA);
2294 seq_printf(m, "ib1fifo[%04d]=0x%08X\n", i, tmp);
2295 }
2296 seq_printf(m, "Indirect2 fifo:\n");
2297 for (i = 640; i < ib1_wptr; i++) {
2298 WREG32(RADEON_CP_CSQ_ADDR, i << 2);
2299 tmp = RREG32(RADEON_CP_CSQ_DATA);
2300 seq_printf(m, "ib2fifo[%04d]=0x%08X\n", i, tmp);
2301 }
2302 return 0;
2303}
2304
2305static int r100_debugfs_mc_info(struct seq_file *m, void *data)
2306{
2307 struct drm_info_node *node = (struct drm_info_node *) m->private;
2308 struct drm_device *dev = node->minor->dev;
2309 struct radeon_device *rdev = dev->dev_private;
2310 uint32_t tmp;
2311
2312 tmp = RREG32(RADEON_CONFIG_MEMSIZE);
2313 seq_printf(m, "CONFIG_MEMSIZE 0x%08x\n", tmp);
2314 tmp = RREG32(RADEON_MC_FB_LOCATION);
2315 seq_printf(m, "MC_FB_LOCATION 0x%08x\n", tmp);
2316 tmp = RREG32(RADEON_BUS_CNTL);
2317 seq_printf(m, "BUS_CNTL 0x%08x\n", tmp);
2318 tmp = RREG32(RADEON_MC_AGP_LOCATION);
2319 seq_printf(m, "MC_AGP_LOCATION 0x%08x\n", tmp);
2320 tmp = RREG32(RADEON_AGP_BASE);
2321 seq_printf(m, "AGP_BASE 0x%08x\n", tmp);
2322 tmp = RREG32(RADEON_HOST_PATH_CNTL);
2323 seq_printf(m, "HOST_PATH_CNTL 0x%08x\n", tmp);
2324 tmp = RREG32(0x01D0);
2325 seq_printf(m, "AIC_CTRL 0x%08x\n", tmp);
2326 tmp = RREG32(RADEON_AIC_LO_ADDR);
2327 seq_printf(m, "AIC_LO_ADDR 0x%08x\n", tmp);
2328 tmp = RREG32(RADEON_AIC_HI_ADDR);
2329 seq_printf(m, "AIC_HI_ADDR 0x%08x\n", tmp);
2330 tmp = RREG32(0x01E4);
2331 seq_printf(m, "AIC_TLB_ADDR 0x%08x\n", tmp);
2332 return 0;
2333}
2334
2335static struct drm_info_list r100_debugfs_rbbm_list[] = {
2336 {"r100_rbbm_info", r100_debugfs_rbbm_info, 0, NULL},
2337};
2338
2339static struct drm_info_list r100_debugfs_cp_list[] = {
2340 {"r100_cp_ring_info", r100_debugfs_cp_ring_info, 0, NULL},
2341 {"r100_cp_csq_fifo", r100_debugfs_cp_csq_fifo, 0, NULL},
2342};
2343
2344static struct drm_info_list r100_debugfs_mc_info_list[] = {
2345 {"r100_mc_info", r100_debugfs_mc_info, 0, NULL},
2346};
2347#endif
2348
2349int r100_debugfs_rbbm_init(struct radeon_device *rdev)
2350{
2351#if defined(CONFIG_DEBUG_FS)
2352 return radeon_debugfs_add_files(rdev, r100_debugfs_rbbm_list, 1);
2353#else
2354 return 0;
2355#endif
2356}
2357
2358int r100_debugfs_cp_init(struct radeon_device *rdev)
2359{
2360#if defined(CONFIG_DEBUG_FS)
2361 return radeon_debugfs_add_files(rdev, r100_debugfs_cp_list, 2);
2362#else
2363 return 0;
2364#endif
2365}
2366
2367int r100_debugfs_mc_info_init(struct radeon_device *rdev)
2368{
2369#if defined(CONFIG_DEBUG_FS)
2370 return radeon_debugfs_add_files(rdev, r100_debugfs_mc_info_list, 1);
2371#else
2372 return 0;
2373#endif
2374}
Dave Airliee024e112009-06-24 09:48:08 +10002375
2376int r100_set_surface_reg(struct radeon_device *rdev, int reg,
2377 uint32_t tiling_flags, uint32_t pitch,
2378 uint32_t offset, uint32_t obj_size)
2379{
2380 int surf_index = reg * 16;
2381 int flags = 0;
2382
2383 /* r100/r200 divide by 16 */
2384 if (rdev->family < CHIP_R300)
2385 flags = pitch / 16;
2386 else
2387 flags = pitch / 8;
2388
2389 if (rdev->family <= CHIP_RS200) {
2390 if ((tiling_flags & (RADEON_TILING_MACRO|RADEON_TILING_MICRO))
2391 == (RADEON_TILING_MACRO|RADEON_TILING_MICRO))
2392 flags |= RADEON_SURF_TILE_COLOR_BOTH;
2393 if (tiling_flags & RADEON_TILING_MACRO)
2394 flags |= RADEON_SURF_TILE_COLOR_MACRO;
2395 } else if (rdev->family <= CHIP_RV280) {
2396 if (tiling_flags & (RADEON_TILING_MACRO))
2397 flags |= R200_SURF_TILE_COLOR_MACRO;
2398 if (tiling_flags & RADEON_TILING_MICRO)
2399 flags |= R200_SURF_TILE_COLOR_MICRO;
2400 } else {
2401 if (tiling_flags & RADEON_TILING_MACRO)
2402 flags |= R300_SURF_TILE_MACRO;
2403 if (tiling_flags & RADEON_TILING_MICRO)
2404 flags |= R300_SURF_TILE_MICRO;
2405 }
2406
Michel Dänzerc88f9f02009-09-15 17:09:30 +02002407 if (tiling_flags & RADEON_TILING_SWAP_16BIT)
2408 flags |= RADEON_SURF_AP0_SWP_16BPP | RADEON_SURF_AP1_SWP_16BPP;
2409 if (tiling_flags & RADEON_TILING_SWAP_32BIT)
2410 flags |= RADEON_SURF_AP0_SWP_32BPP | RADEON_SURF_AP1_SWP_32BPP;
2411
Dave Airliee024e112009-06-24 09:48:08 +10002412 DRM_DEBUG("writing surface %d %d %x %x\n", reg, flags, offset, offset+obj_size-1);
2413 WREG32(RADEON_SURFACE0_INFO + surf_index, flags);
2414 WREG32(RADEON_SURFACE0_LOWER_BOUND + surf_index, offset);
2415 WREG32(RADEON_SURFACE0_UPPER_BOUND + surf_index, offset + obj_size - 1);
2416 return 0;
2417}
2418
2419void r100_clear_surface_reg(struct radeon_device *rdev, int reg)
2420{
2421 int surf_index = reg * 16;
2422 WREG32(RADEON_SURFACE0_INFO + surf_index, 0);
2423}
Jerome Glissec93bb852009-07-13 21:04:08 +02002424
2425void r100_bandwidth_update(struct radeon_device *rdev)
2426{
2427 fixed20_12 trcd_ff, trp_ff, tras_ff, trbs_ff, tcas_ff;
2428 fixed20_12 sclk_ff, mclk_ff, sclk_eff_ff, sclk_delay_ff;
2429 fixed20_12 peak_disp_bw, mem_bw, pix_clk, pix_clk2, temp_ff, crit_point_ff;
2430 uint32_t temp, data, mem_trcd, mem_trp, mem_tras;
2431 fixed20_12 memtcas_ff[8] = {
2432 fixed_init(1),
2433 fixed_init(2),
2434 fixed_init(3),
2435 fixed_init(0),
2436 fixed_init_half(1),
2437 fixed_init_half(2),
2438 fixed_init(0),
2439 };
2440 fixed20_12 memtcas_rs480_ff[8] = {
2441 fixed_init(0),
2442 fixed_init(1),
2443 fixed_init(2),
2444 fixed_init(3),
2445 fixed_init(0),
2446 fixed_init_half(1),
2447 fixed_init_half(2),
2448 fixed_init_half(3),
2449 };
2450 fixed20_12 memtcas2_ff[8] = {
2451 fixed_init(0),
2452 fixed_init(1),
2453 fixed_init(2),
2454 fixed_init(3),
2455 fixed_init(4),
2456 fixed_init(5),
2457 fixed_init(6),
2458 fixed_init(7),
2459 };
2460 fixed20_12 memtrbs[8] = {
2461 fixed_init(1),
2462 fixed_init_half(1),
2463 fixed_init(2),
2464 fixed_init_half(2),
2465 fixed_init(3),
2466 fixed_init_half(3),
2467 fixed_init(4),
2468 fixed_init_half(4)
2469 };
2470 fixed20_12 memtrbs_r4xx[8] = {
2471 fixed_init(4),
2472 fixed_init(5),
2473 fixed_init(6),
2474 fixed_init(7),
2475 fixed_init(8),
2476 fixed_init(9),
2477 fixed_init(10),
2478 fixed_init(11)
2479 };
2480 fixed20_12 min_mem_eff;
2481 fixed20_12 mc_latency_sclk, mc_latency_mclk, k1;
2482 fixed20_12 cur_latency_mclk, cur_latency_sclk;
2483 fixed20_12 disp_latency, disp_latency_overhead, disp_drain_rate,
2484 disp_drain_rate2, read_return_rate;
2485 fixed20_12 time_disp1_drop_priority;
2486 int c;
2487 int cur_size = 16; /* in octawords */
2488 int critical_point = 0, critical_point2;
2489/* uint32_t read_return_rate, time_disp1_drop_priority; */
2490 int stop_req, max_stop_req;
2491 struct drm_display_mode *mode1 = NULL;
2492 struct drm_display_mode *mode2 = NULL;
2493 uint32_t pixel_bytes1 = 0;
2494 uint32_t pixel_bytes2 = 0;
2495
Alex Deucherf46c0122010-03-31 00:33:27 -04002496 radeon_update_display_priority(rdev);
2497
Jerome Glissec93bb852009-07-13 21:04:08 +02002498 if (rdev->mode_info.crtcs[0]->base.enabled) {
2499 mode1 = &rdev->mode_info.crtcs[0]->base.mode;
2500 pixel_bytes1 = rdev->mode_info.crtcs[0]->base.fb->bits_per_pixel / 8;
2501 }
Dave Airliedfee5612009-10-02 09:19:09 +10002502 if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
2503 if (rdev->mode_info.crtcs[1]->base.enabled) {
2504 mode2 = &rdev->mode_info.crtcs[1]->base.mode;
2505 pixel_bytes2 = rdev->mode_info.crtcs[1]->base.fb->bits_per_pixel / 8;
2506 }
Jerome Glissec93bb852009-07-13 21:04:08 +02002507 }
2508
2509 min_mem_eff.full = rfixed_const_8(0);
2510 /* get modes */
2511 if ((rdev->disp_priority == 2) && ASIC_IS_R300(rdev)) {
2512 uint32_t mc_init_misc_lat_timer = RREG32(R300_MC_INIT_MISC_LAT_TIMER);
2513 mc_init_misc_lat_timer &= ~(R300_MC_DISP1R_INIT_LAT_MASK << R300_MC_DISP1R_INIT_LAT_SHIFT);
2514 mc_init_misc_lat_timer &= ~(R300_MC_DISP0R_INIT_LAT_MASK << R300_MC_DISP0R_INIT_LAT_SHIFT);
2515 /* check crtc enables */
2516 if (mode2)
2517 mc_init_misc_lat_timer |= (1 << R300_MC_DISP1R_INIT_LAT_SHIFT);
2518 if (mode1)
2519 mc_init_misc_lat_timer |= (1 << R300_MC_DISP0R_INIT_LAT_SHIFT);
2520 WREG32(R300_MC_INIT_MISC_LAT_TIMER, mc_init_misc_lat_timer);
2521 }
2522
2523 /*
2524 * determine is there is enough bw for current mode
2525 */
Alex Deucherf47299c2010-03-16 20:54:38 -04002526 sclk_ff = rdev->pm.sclk;
2527 mclk_ff = rdev->pm.mclk;
Jerome Glissec93bb852009-07-13 21:04:08 +02002528
2529 temp = (rdev->mc.vram_width / 8) * (rdev->mc.vram_is_ddr ? 2 : 1);
2530 temp_ff.full = rfixed_const(temp);
2531 mem_bw.full = rfixed_mul(mclk_ff, temp_ff);
2532
2533 pix_clk.full = 0;
2534 pix_clk2.full = 0;
2535 peak_disp_bw.full = 0;
2536 if (mode1) {
2537 temp_ff.full = rfixed_const(1000);
2538 pix_clk.full = rfixed_const(mode1->clock); /* convert to fixed point */
2539 pix_clk.full = rfixed_div(pix_clk, temp_ff);
2540 temp_ff.full = rfixed_const(pixel_bytes1);
2541 peak_disp_bw.full += rfixed_mul(pix_clk, temp_ff);
2542 }
2543 if (mode2) {
2544 temp_ff.full = rfixed_const(1000);
2545 pix_clk2.full = rfixed_const(mode2->clock); /* convert to fixed point */
2546 pix_clk2.full = rfixed_div(pix_clk2, temp_ff);
2547 temp_ff.full = rfixed_const(pixel_bytes2);
2548 peak_disp_bw.full += rfixed_mul(pix_clk2, temp_ff);
2549 }
2550
2551 mem_bw.full = rfixed_mul(mem_bw, min_mem_eff);
2552 if (peak_disp_bw.full >= mem_bw.full) {
2553 DRM_ERROR("You may not have enough display bandwidth for current mode\n"
2554 "If you have flickering problem, try to lower resolution, refresh rate, or color depth\n");
2555 }
2556
2557 /* Get values from the EXT_MEM_CNTL register...converting its contents. */
2558 temp = RREG32(RADEON_MEM_TIMING_CNTL);
2559 if ((rdev->family == CHIP_RV100) || (rdev->flags & RADEON_IS_IGP)) { /* RV100, M6, IGPs */
2560 mem_trcd = ((temp >> 2) & 0x3) + 1;
2561 mem_trp = ((temp & 0x3)) + 1;
2562 mem_tras = ((temp & 0x70) >> 4) + 1;
2563 } else if (rdev->family == CHIP_R300 ||
2564 rdev->family == CHIP_R350) { /* r300, r350 */
2565 mem_trcd = (temp & 0x7) + 1;
2566 mem_trp = ((temp >> 8) & 0x7) + 1;
2567 mem_tras = ((temp >> 11) & 0xf) + 4;
2568 } else if (rdev->family == CHIP_RV350 ||
2569 rdev->family <= CHIP_RV380) {
2570 /* rv3x0 */
2571 mem_trcd = (temp & 0x7) + 3;
2572 mem_trp = ((temp >> 8) & 0x7) + 3;
2573 mem_tras = ((temp >> 11) & 0xf) + 6;
2574 } else if (rdev->family == CHIP_R420 ||
2575 rdev->family == CHIP_R423 ||
2576 rdev->family == CHIP_RV410) {
2577 /* r4xx */
2578 mem_trcd = (temp & 0xf) + 3;
2579 if (mem_trcd > 15)
2580 mem_trcd = 15;
2581 mem_trp = ((temp >> 8) & 0xf) + 3;
2582 if (mem_trp > 15)
2583 mem_trp = 15;
2584 mem_tras = ((temp >> 12) & 0x1f) + 6;
2585 if (mem_tras > 31)
2586 mem_tras = 31;
2587 } else { /* RV200, R200 */
2588 mem_trcd = (temp & 0x7) + 1;
2589 mem_trp = ((temp >> 8) & 0x7) + 1;
2590 mem_tras = ((temp >> 12) & 0xf) + 4;
2591 }
2592 /* convert to FF */
2593 trcd_ff.full = rfixed_const(mem_trcd);
2594 trp_ff.full = rfixed_const(mem_trp);
2595 tras_ff.full = rfixed_const(mem_tras);
2596
2597 /* Get values from the MEM_SDRAM_MODE_REG register...converting its */
2598 temp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
2599 data = (temp & (7 << 20)) >> 20;
2600 if ((rdev->family == CHIP_RV100) || rdev->flags & RADEON_IS_IGP) {
2601 if (rdev->family == CHIP_RS480) /* don't think rs400 */
2602 tcas_ff = memtcas_rs480_ff[data];
2603 else
2604 tcas_ff = memtcas_ff[data];
2605 } else
2606 tcas_ff = memtcas2_ff[data];
2607
2608 if (rdev->family == CHIP_RS400 ||
2609 rdev->family == CHIP_RS480) {
2610 /* extra cas latency stored in bits 23-25 0-4 clocks */
2611 data = (temp >> 23) & 0x7;
2612 if (data < 5)
2613 tcas_ff.full += rfixed_const(data);
2614 }
2615
2616 if (ASIC_IS_R300(rdev) && !(rdev->flags & RADEON_IS_IGP)) {
2617 /* on the R300, Tcas is included in Trbs.
2618 */
2619 temp = RREG32(RADEON_MEM_CNTL);
2620 data = (R300_MEM_NUM_CHANNELS_MASK & temp);
2621 if (data == 1) {
2622 if (R300_MEM_USE_CD_CH_ONLY & temp) {
2623 temp = RREG32(R300_MC_IND_INDEX);
2624 temp &= ~R300_MC_IND_ADDR_MASK;
2625 temp |= R300_MC_READ_CNTL_CD_mcind;
2626 WREG32(R300_MC_IND_INDEX, temp);
2627 temp = RREG32(R300_MC_IND_DATA);
2628 data = (R300_MEM_RBS_POSITION_C_MASK & temp);
2629 } else {
2630 temp = RREG32(R300_MC_READ_CNTL_AB);
2631 data = (R300_MEM_RBS_POSITION_A_MASK & temp);
2632 }
2633 } else {
2634 temp = RREG32(R300_MC_READ_CNTL_AB);
2635 data = (R300_MEM_RBS_POSITION_A_MASK & temp);
2636 }
2637 if (rdev->family == CHIP_RV410 ||
2638 rdev->family == CHIP_R420 ||
2639 rdev->family == CHIP_R423)
2640 trbs_ff = memtrbs_r4xx[data];
2641 else
2642 trbs_ff = memtrbs[data];
2643 tcas_ff.full += trbs_ff.full;
2644 }
2645
2646 sclk_eff_ff.full = sclk_ff.full;
2647
2648 if (rdev->flags & RADEON_IS_AGP) {
2649 fixed20_12 agpmode_ff;
2650 agpmode_ff.full = rfixed_const(radeon_agpmode);
2651 temp_ff.full = rfixed_const_666(16);
2652 sclk_eff_ff.full -= rfixed_mul(agpmode_ff, temp_ff);
2653 }
2654 /* TODO PCIE lanes may affect this - agpmode == 16?? */
2655
2656 if (ASIC_IS_R300(rdev)) {
2657 sclk_delay_ff.full = rfixed_const(250);
2658 } else {
2659 if ((rdev->family == CHIP_RV100) ||
2660 rdev->flags & RADEON_IS_IGP) {
2661 if (rdev->mc.vram_is_ddr)
2662 sclk_delay_ff.full = rfixed_const(41);
2663 else
2664 sclk_delay_ff.full = rfixed_const(33);
2665 } else {
2666 if (rdev->mc.vram_width == 128)
2667 sclk_delay_ff.full = rfixed_const(57);
2668 else
2669 sclk_delay_ff.full = rfixed_const(41);
2670 }
2671 }
2672
2673 mc_latency_sclk.full = rfixed_div(sclk_delay_ff, sclk_eff_ff);
2674
2675 if (rdev->mc.vram_is_ddr) {
2676 if (rdev->mc.vram_width == 32) {
2677 k1.full = rfixed_const(40);
2678 c = 3;
2679 } else {
2680 k1.full = rfixed_const(20);
2681 c = 1;
2682 }
2683 } else {
2684 k1.full = rfixed_const(40);
2685 c = 3;
2686 }
2687
2688 temp_ff.full = rfixed_const(2);
2689 mc_latency_mclk.full = rfixed_mul(trcd_ff, temp_ff);
2690 temp_ff.full = rfixed_const(c);
2691 mc_latency_mclk.full += rfixed_mul(tcas_ff, temp_ff);
2692 temp_ff.full = rfixed_const(4);
2693 mc_latency_mclk.full += rfixed_mul(tras_ff, temp_ff);
2694 mc_latency_mclk.full += rfixed_mul(trp_ff, temp_ff);
2695 mc_latency_mclk.full += k1.full;
2696
2697 mc_latency_mclk.full = rfixed_div(mc_latency_mclk, mclk_ff);
2698 mc_latency_mclk.full += rfixed_div(temp_ff, sclk_eff_ff);
2699
2700 /*
2701 HW cursor time assuming worst case of full size colour cursor.
2702 */
2703 temp_ff.full = rfixed_const((2 * (cur_size - (rdev->mc.vram_is_ddr + 1))));
2704 temp_ff.full += trcd_ff.full;
2705 if (temp_ff.full < tras_ff.full)
2706 temp_ff.full = tras_ff.full;
2707 cur_latency_mclk.full = rfixed_div(temp_ff, mclk_ff);
2708
2709 temp_ff.full = rfixed_const(cur_size);
2710 cur_latency_sclk.full = rfixed_div(temp_ff, sclk_eff_ff);
2711 /*
2712 Find the total latency for the display data.
2713 */
Michel Dänzerb5fc9012009-10-08 10:44:10 +02002714 disp_latency_overhead.full = rfixed_const(8);
Jerome Glissec93bb852009-07-13 21:04:08 +02002715 disp_latency_overhead.full = rfixed_div(disp_latency_overhead, sclk_ff);
2716 mc_latency_mclk.full += disp_latency_overhead.full + cur_latency_mclk.full;
2717 mc_latency_sclk.full += disp_latency_overhead.full + cur_latency_sclk.full;
2718
2719 if (mc_latency_mclk.full > mc_latency_sclk.full)
2720 disp_latency.full = mc_latency_mclk.full;
2721 else
2722 disp_latency.full = mc_latency_sclk.full;
2723
2724 /* setup Max GRPH_STOP_REQ default value */
2725 if (ASIC_IS_RV100(rdev))
2726 max_stop_req = 0x5c;
2727 else
2728 max_stop_req = 0x7c;
2729
2730 if (mode1) {
2731 /* CRTC1
2732 Set GRPH_BUFFER_CNTL register using h/w defined optimal values.
2733 GRPH_STOP_REQ <= MIN[ 0x7C, (CRTC_H_DISP + 1) * (bit depth) / 0x10 ]
2734 */
2735 stop_req = mode1->hdisplay * pixel_bytes1 / 16;
2736
2737 if (stop_req > max_stop_req)
2738 stop_req = max_stop_req;
2739
2740 /*
2741 Find the drain rate of the display buffer.
2742 */
2743 temp_ff.full = rfixed_const((16/pixel_bytes1));
2744 disp_drain_rate.full = rfixed_div(pix_clk, temp_ff);
2745
2746 /*
2747 Find the critical point of the display buffer.
2748 */
2749 crit_point_ff.full = rfixed_mul(disp_drain_rate, disp_latency);
2750 crit_point_ff.full += rfixed_const_half(0);
2751
2752 critical_point = rfixed_trunc(crit_point_ff);
2753
2754 if (rdev->disp_priority == 2) {
2755 critical_point = 0;
2756 }
2757
2758 /*
2759 The critical point should never be above max_stop_req-4. Setting
2760 GRPH_CRITICAL_CNTL = 0 will thus force high priority all the time.
2761 */
2762 if (max_stop_req - critical_point < 4)
2763 critical_point = 0;
2764
2765 if (critical_point == 0 && mode2 && rdev->family == CHIP_R300) {
2766 /* some R300 cards have problem with this set to 0, when CRTC2 is enabled.*/
2767 critical_point = 0x10;
2768 }
2769
2770 temp = RREG32(RADEON_GRPH_BUFFER_CNTL);
2771 temp &= ~(RADEON_GRPH_STOP_REQ_MASK);
2772 temp |= (stop_req << RADEON_GRPH_STOP_REQ_SHIFT);
2773 temp &= ~(RADEON_GRPH_START_REQ_MASK);
2774 if ((rdev->family == CHIP_R350) &&
2775 (stop_req > 0x15)) {
2776 stop_req -= 0x10;
2777 }
2778 temp |= (stop_req << RADEON_GRPH_START_REQ_SHIFT);
2779 temp |= RADEON_GRPH_BUFFER_SIZE;
2780 temp &= ~(RADEON_GRPH_CRITICAL_CNTL |
2781 RADEON_GRPH_CRITICAL_AT_SOF |
2782 RADEON_GRPH_STOP_CNTL);
2783 /*
2784 Write the result into the register.
2785 */
2786 WREG32(RADEON_GRPH_BUFFER_CNTL, ((temp & ~RADEON_GRPH_CRITICAL_POINT_MASK) |
2787 (critical_point << RADEON_GRPH_CRITICAL_POINT_SHIFT)));
2788
2789#if 0
2790 if ((rdev->family == CHIP_RS400) ||
2791 (rdev->family == CHIP_RS480)) {
2792 /* attempt to program RS400 disp regs correctly ??? */
2793 temp = RREG32(RS400_DISP1_REG_CNTL);
2794 temp &= ~(RS400_DISP1_START_REQ_LEVEL_MASK |
2795 RS400_DISP1_STOP_REQ_LEVEL_MASK);
2796 WREG32(RS400_DISP1_REQ_CNTL1, (temp |
2797 (critical_point << RS400_DISP1_START_REQ_LEVEL_SHIFT) |
2798 (critical_point << RS400_DISP1_STOP_REQ_LEVEL_SHIFT)));
2799 temp = RREG32(RS400_DMIF_MEM_CNTL1);
2800 temp &= ~(RS400_DISP1_CRITICAL_POINT_START_MASK |
2801 RS400_DISP1_CRITICAL_POINT_STOP_MASK);
2802 WREG32(RS400_DMIF_MEM_CNTL1, (temp |
2803 (critical_point << RS400_DISP1_CRITICAL_POINT_START_SHIFT) |
2804 (critical_point << RS400_DISP1_CRITICAL_POINT_STOP_SHIFT)));
2805 }
2806#endif
2807
2808 DRM_DEBUG("GRPH_BUFFER_CNTL from to %x\n",
2809 /* (unsigned int)info->SavedReg->grph_buffer_cntl, */
2810 (unsigned int)RREG32(RADEON_GRPH_BUFFER_CNTL));
2811 }
2812
2813 if (mode2) {
2814 u32 grph2_cntl;
2815 stop_req = mode2->hdisplay * pixel_bytes2 / 16;
2816
2817 if (stop_req > max_stop_req)
2818 stop_req = max_stop_req;
2819
2820 /*
2821 Find the drain rate of the display buffer.
2822 */
2823 temp_ff.full = rfixed_const((16/pixel_bytes2));
2824 disp_drain_rate2.full = rfixed_div(pix_clk2, temp_ff);
2825
2826 grph2_cntl = RREG32(RADEON_GRPH2_BUFFER_CNTL);
2827 grph2_cntl &= ~(RADEON_GRPH_STOP_REQ_MASK);
2828 grph2_cntl |= (stop_req << RADEON_GRPH_STOP_REQ_SHIFT);
2829 grph2_cntl &= ~(RADEON_GRPH_START_REQ_MASK);
2830 if ((rdev->family == CHIP_R350) &&
2831 (stop_req > 0x15)) {
2832 stop_req -= 0x10;
2833 }
2834 grph2_cntl |= (stop_req << RADEON_GRPH_START_REQ_SHIFT);
2835 grph2_cntl |= RADEON_GRPH_BUFFER_SIZE;
2836 grph2_cntl &= ~(RADEON_GRPH_CRITICAL_CNTL |
2837 RADEON_GRPH_CRITICAL_AT_SOF |
2838 RADEON_GRPH_STOP_CNTL);
2839
2840 if ((rdev->family == CHIP_RS100) ||
2841 (rdev->family == CHIP_RS200))
2842 critical_point2 = 0;
2843 else {
2844 temp = (rdev->mc.vram_width * rdev->mc.vram_is_ddr + 1)/128;
2845 temp_ff.full = rfixed_const(temp);
2846 temp_ff.full = rfixed_mul(mclk_ff, temp_ff);
2847 if (sclk_ff.full < temp_ff.full)
2848 temp_ff.full = sclk_ff.full;
2849
2850 read_return_rate.full = temp_ff.full;
2851
2852 if (mode1) {
2853 temp_ff.full = read_return_rate.full - disp_drain_rate.full;
2854 time_disp1_drop_priority.full = rfixed_div(crit_point_ff, temp_ff);
2855 } else {
2856 time_disp1_drop_priority.full = 0;
2857 }
2858 crit_point_ff.full = disp_latency.full + time_disp1_drop_priority.full + disp_latency.full;
2859 crit_point_ff.full = rfixed_mul(crit_point_ff, disp_drain_rate2);
2860 crit_point_ff.full += rfixed_const_half(0);
2861
2862 critical_point2 = rfixed_trunc(crit_point_ff);
2863
2864 if (rdev->disp_priority == 2) {
2865 critical_point2 = 0;
2866 }
2867
2868 if (max_stop_req - critical_point2 < 4)
2869 critical_point2 = 0;
2870
2871 }
2872
2873 if (critical_point2 == 0 && rdev->family == CHIP_R300) {
2874 /* some R300 cards have problem with this set to 0 */
2875 critical_point2 = 0x10;
2876 }
2877
2878 WREG32(RADEON_GRPH2_BUFFER_CNTL, ((grph2_cntl & ~RADEON_GRPH_CRITICAL_POINT_MASK) |
2879 (critical_point2 << RADEON_GRPH_CRITICAL_POINT_SHIFT)));
2880
2881 if ((rdev->family == CHIP_RS400) ||
2882 (rdev->family == CHIP_RS480)) {
2883#if 0
2884 /* attempt to program RS400 disp2 regs correctly ??? */
2885 temp = RREG32(RS400_DISP2_REQ_CNTL1);
2886 temp &= ~(RS400_DISP2_START_REQ_LEVEL_MASK |
2887 RS400_DISP2_STOP_REQ_LEVEL_MASK);
2888 WREG32(RS400_DISP2_REQ_CNTL1, (temp |
2889 (critical_point2 << RS400_DISP1_START_REQ_LEVEL_SHIFT) |
2890 (critical_point2 << RS400_DISP1_STOP_REQ_LEVEL_SHIFT)));
2891 temp = RREG32(RS400_DISP2_REQ_CNTL2);
2892 temp &= ~(RS400_DISP2_CRITICAL_POINT_START_MASK |
2893 RS400_DISP2_CRITICAL_POINT_STOP_MASK);
2894 WREG32(RS400_DISP2_REQ_CNTL2, (temp |
2895 (critical_point2 << RS400_DISP2_CRITICAL_POINT_START_SHIFT) |
2896 (critical_point2 << RS400_DISP2_CRITICAL_POINT_STOP_SHIFT)));
2897#endif
2898 WREG32(RS400_DISP2_REQ_CNTL1, 0x105DC1CC);
2899 WREG32(RS400_DISP2_REQ_CNTL2, 0x2749D000);
2900 WREG32(RS400_DMIF_MEM_CNTL1, 0x29CA71DC);
2901 WREG32(RS400_DISP1_REQ_CNTL1, 0x28FBC3AC);
2902 }
2903
2904 DRM_DEBUG("GRPH2_BUFFER_CNTL from to %x\n",
2905 (unsigned int)RREG32(RADEON_GRPH2_BUFFER_CNTL));
2906 }
2907}
Dave Airlie551ebd82009-09-01 15:25:57 +10002908
2909static inline void r100_cs_track_texture_print(struct r100_cs_track_texture *t)
2910{
2911 DRM_ERROR("pitch %d\n", t->pitch);
Mathias Fröhlichceb776b2009-10-19 12:50:41 -04002912 DRM_ERROR("use_pitch %d\n", t->use_pitch);
Dave Airlie551ebd82009-09-01 15:25:57 +10002913 DRM_ERROR("width %d\n", t->width);
Mathias Fröhlichceb776b2009-10-19 12:50:41 -04002914 DRM_ERROR("width_11 %d\n", t->width_11);
Dave Airlie551ebd82009-09-01 15:25:57 +10002915 DRM_ERROR("height %d\n", t->height);
Mathias Fröhlichceb776b2009-10-19 12:50:41 -04002916 DRM_ERROR("height_11 %d\n", t->height_11);
Dave Airlie551ebd82009-09-01 15:25:57 +10002917 DRM_ERROR("num levels %d\n", t->num_levels);
2918 DRM_ERROR("depth %d\n", t->txdepth);
2919 DRM_ERROR("bpp %d\n", t->cpp);
2920 DRM_ERROR("coordinate type %d\n", t->tex_coord_type);
2921 DRM_ERROR("width round to power of 2 %d\n", t->roundup_w);
2922 DRM_ERROR("height round to power of 2 %d\n", t->roundup_h);
Dave Airlied785d782009-12-07 13:16:06 +10002923 DRM_ERROR("compress format %d\n", t->compress_format);
Dave Airlie551ebd82009-09-01 15:25:57 +10002924}
2925
2926static int r100_cs_track_cube(struct radeon_device *rdev,
2927 struct r100_cs_track *track, unsigned idx)
2928{
2929 unsigned face, w, h;
Jerome Glisse4c788672009-11-20 14:29:23 +01002930 struct radeon_bo *cube_robj;
Dave Airlie551ebd82009-09-01 15:25:57 +10002931 unsigned long size;
2932
2933 for (face = 0; face < 5; face++) {
2934 cube_robj = track->textures[idx].cube_info[face].robj;
2935 w = track->textures[idx].cube_info[face].width;
2936 h = track->textures[idx].cube_info[face].height;
2937
2938 size = w * h;
2939 size *= track->textures[idx].cpp;
2940
2941 size += track->textures[idx].cube_info[face].offset;
2942
Jerome Glisse4c788672009-11-20 14:29:23 +01002943 if (size > radeon_bo_size(cube_robj)) {
Dave Airlie551ebd82009-09-01 15:25:57 +10002944 DRM_ERROR("Cube texture offset greater than object size %lu %lu\n",
Jerome Glisse4c788672009-11-20 14:29:23 +01002945 size, radeon_bo_size(cube_robj));
Dave Airlie551ebd82009-09-01 15:25:57 +10002946 r100_cs_track_texture_print(&track->textures[idx]);
2947 return -1;
2948 }
2949 }
2950 return 0;
2951}
2952
Dave Airlied785d782009-12-07 13:16:06 +10002953static int r100_track_compress_size(int compress_format, int w, int h)
2954{
2955 int block_width, block_height, block_bytes;
2956 int wblocks, hblocks;
2957 int min_wblocks;
2958 int sz;
2959
2960 block_width = 4;
2961 block_height = 4;
2962
2963 switch (compress_format) {
2964 case R100_TRACK_COMP_DXT1:
2965 block_bytes = 8;
2966 min_wblocks = 4;
2967 break;
2968 default:
2969 case R100_TRACK_COMP_DXT35:
2970 block_bytes = 16;
2971 min_wblocks = 2;
2972 break;
2973 }
2974
2975 hblocks = (h + block_height - 1) / block_height;
2976 wblocks = (w + block_width - 1) / block_width;
2977 if (wblocks < min_wblocks)
2978 wblocks = min_wblocks;
2979 sz = wblocks * hblocks * block_bytes;
2980 return sz;
2981}
2982
Dave Airlie551ebd82009-09-01 15:25:57 +10002983static int r100_cs_track_texture_check(struct radeon_device *rdev,
2984 struct r100_cs_track *track)
2985{
Jerome Glisse4c788672009-11-20 14:29:23 +01002986 struct radeon_bo *robj;
Dave Airlie551ebd82009-09-01 15:25:57 +10002987 unsigned long size;
Marek Olšákb73c5f82010-04-11 03:18:52 +02002988 unsigned u, i, w, h, d;
Dave Airlie551ebd82009-09-01 15:25:57 +10002989 int ret;
2990
2991 for (u = 0; u < track->num_texture; u++) {
2992 if (!track->textures[u].enabled)
2993 continue;
2994 robj = track->textures[u].robj;
2995 if (robj == NULL) {
2996 DRM_ERROR("No texture bound to unit %u\n", u);
2997 return -EINVAL;
2998 }
2999 size = 0;
3000 for (i = 0; i <= track->textures[u].num_levels; i++) {
3001 if (track->textures[u].use_pitch) {
3002 if (rdev->family < CHIP_R300)
3003 w = (track->textures[u].pitch / track->textures[u].cpp) / (1 << i);
3004 else
3005 w = track->textures[u].pitch / (1 << i);
3006 } else {
Mathias Fröhlichceb776b2009-10-19 12:50:41 -04003007 w = track->textures[u].width;
Dave Airlie551ebd82009-09-01 15:25:57 +10003008 if (rdev->family >= CHIP_RV515)
3009 w |= track->textures[u].width_11;
Mathias Fröhlichceb776b2009-10-19 12:50:41 -04003010 w = w / (1 << i);
Dave Airlie551ebd82009-09-01 15:25:57 +10003011 if (track->textures[u].roundup_w)
3012 w = roundup_pow_of_two(w);
3013 }
Mathias Fröhlichceb776b2009-10-19 12:50:41 -04003014 h = track->textures[u].height;
Dave Airlie551ebd82009-09-01 15:25:57 +10003015 if (rdev->family >= CHIP_RV515)
3016 h |= track->textures[u].height_11;
Mathias Fröhlichceb776b2009-10-19 12:50:41 -04003017 h = h / (1 << i);
Dave Airlie551ebd82009-09-01 15:25:57 +10003018 if (track->textures[u].roundup_h)
3019 h = roundup_pow_of_two(h);
Marek Olšákb73c5f82010-04-11 03:18:52 +02003020 if (track->textures[u].tex_coord_type == 1) {
3021 d = (1 << track->textures[u].txdepth) / (1 << i);
3022 if (!d)
3023 d = 1;
3024 } else {
3025 d = 1;
3026 }
Dave Airlied785d782009-12-07 13:16:06 +10003027 if (track->textures[u].compress_format) {
3028
Marek Olšákb73c5f82010-04-11 03:18:52 +02003029 size += r100_track_compress_size(track->textures[u].compress_format, w, h) * d;
Dave Airlied785d782009-12-07 13:16:06 +10003030 /* compressed textures are block based */
3031 } else
Marek Olšákb73c5f82010-04-11 03:18:52 +02003032 size += w * h * d;
Dave Airlie551ebd82009-09-01 15:25:57 +10003033 }
3034 size *= track->textures[u].cpp;
Dave Airlied785d782009-12-07 13:16:06 +10003035
Dave Airlie551ebd82009-09-01 15:25:57 +10003036 switch (track->textures[u].tex_coord_type) {
3037 case 0:
Dave Airlie551ebd82009-09-01 15:25:57 +10003038 case 1:
Dave Airlie551ebd82009-09-01 15:25:57 +10003039 break;
3040 case 2:
3041 if (track->separate_cube) {
3042 ret = r100_cs_track_cube(rdev, track, u);
3043 if (ret)
3044 return ret;
3045 } else
3046 size *= 6;
3047 break;
3048 default:
3049 DRM_ERROR("Invalid texture coordinate type %u for unit "
3050 "%u\n", track->textures[u].tex_coord_type, u);
3051 return -EINVAL;
3052 }
Jerome Glisse4c788672009-11-20 14:29:23 +01003053 if (size > radeon_bo_size(robj)) {
Dave Airlie551ebd82009-09-01 15:25:57 +10003054 DRM_ERROR("Texture of unit %u needs %lu bytes but is "
Jerome Glisse4c788672009-11-20 14:29:23 +01003055 "%lu\n", u, size, radeon_bo_size(robj));
Dave Airlie551ebd82009-09-01 15:25:57 +10003056 r100_cs_track_texture_print(&track->textures[u]);
3057 return -EINVAL;
3058 }
3059 }
3060 return 0;
3061}
3062
3063int r100_cs_track_check(struct radeon_device *rdev, struct r100_cs_track *track)
3064{
3065 unsigned i;
3066 unsigned long size;
3067 unsigned prim_walk;
3068 unsigned nverts;
3069
3070 for (i = 0; i < track->num_cb; i++) {
3071 if (track->cb[i].robj == NULL) {
Marek Olšák46c64d42009-12-17 06:02:28 +01003072 if (!(track->fastfill || track->color_channel_mask ||
3073 track->blend_read_enable)) {
3074 continue;
3075 }
Dave Airlie551ebd82009-09-01 15:25:57 +10003076 DRM_ERROR("[drm] No buffer for color buffer %d !\n", i);
3077 return -EINVAL;
3078 }
3079 size = track->cb[i].pitch * track->cb[i].cpp * track->maxy;
3080 size += track->cb[i].offset;
Jerome Glisse4c788672009-11-20 14:29:23 +01003081 if (size > radeon_bo_size(track->cb[i].robj)) {
Dave Airlie551ebd82009-09-01 15:25:57 +10003082 DRM_ERROR("[drm] Buffer too small for color buffer %d "
3083 "(need %lu have %lu) !\n", i, size,
Jerome Glisse4c788672009-11-20 14:29:23 +01003084 radeon_bo_size(track->cb[i].robj));
Dave Airlie551ebd82009-09-01 15:25:57 +10003085 DRM_ERROR("[drm] color buffer %d (%u %u %u %u)\n",
3086 i, track->cb[i].pitch, track->cb[i].cpp,
3087 track->cb[i].offset, track->maxy);
3088 return -EINVAL;
3089 }
3090 }
3091 if (track->z_enabled) {
3092 if (track->zb.robj == NULL) {
3093 DRM_ERROR("[drm] No buffer for z buffer !\n");
3094 return -EINVAL;
3095 }
3096 size = track->zb.pitch * track->zb.cpp * track->maxy;
3097 size += track->zb.offset;
Jerome Glisse4c788672009-11-20 14:29:23 +01003098 if (size > radeon_bo_size(track->zb.robj)) {
Dave Airlie551ebd82009-09-01 15:25:57 +10003099 DRM_ERROR("[drm] Buffer too small for z buffer "
3100 "(need %lu have %lu) !\n", size,
Jerome Glisse4c788672009-11-20 14:29:23 +01003101 radeon_bo_size(track->zb.robj));
Dave Airlie551ebd82009-09-01 15:25:57 +10003102 DRM_ERROR("[drm] zbuffer (%u %u %u %u)\n",
3103 track->zb.pitch, track->zb.cpp,
3104 track->zb.offset, track->maxy);
3105 return -EINVAL;
3106 }
3107 }
3108 prim_walk = (track->vap_vf_cntl >> 4) & 0x3;
Marek Olšákcae94b02010-02-21 21:24:15 +01003109 if (track->vap_vf_cntl & (1 << 14)) {
3110 nverts = track->vap_alt_nverts;
3111 } else {
3112 nverts = (track->vap_vf_cntl >> 16) & 0xFFFF;
3113 }
Dave Airlie551ebd82009-09-01 15:25:57 +10003114 switch (prim_walk) {
3115 case 1:
3116 for (i = 0; i < track->num_arrays; i++) {
3117 size = track->arrays[i].esize * track->max_indx * 4;
3118 if (track->arrays[i].robj == NULL) {
3119 DRM_ERROR("(PW %u) Vertex array %u no buffer "
3120 "bound\n", prim_walk, i);
3121 return -EINVAL;
3122 }
Jerome Glisse4c788672009-11-20 14:29:23 +01003123 if (size > radeon_bo_size(track->arrays[i].robj)) {
3124 dev_err(rdev->dev, "(PW %u) Vertex array %u "
3125 "need %lu dwords have %lu dwords\n",
3126 prim_walk, i, size >> 2,
3127 radeon_bo_size(track->arrays[i].robj)
3128 >> 2);
Dave Airlie551ebd82009-09-01 15:25:57 +10003129 DRM_ERROR("Max indices %u\n", track->max_indx);
3130 return -EINVAL;
3131 }
3132 }
3133 break;
3134 case 2:
3135 for (i = 0; i < track->num_arrays; i++) {
3136 size = track->arrays[i].esize * (nverts - 1) * 4;
3137 if (track->arrays[i].robj == NULL) {
3138 DRM_ERROR("(PW %u) Vertex array %u no buffer "
3139 "bound\n", prim_walk, i);
3140 return -EINVAL;
3141 }
Jerome Glisse4c788672009-11-20 14:29:23 +01003142 if (size > radeon_bo_size(track->arrays[i].robj)) {
3143 dev_err(rdev->dev, "(PW %u) Vertex array %u "
3144 "need %lu dwords have %lu dwords\n",
3145 prim_walk, i, size >> 2,
3146 radeon_bo_size(track->arrays[i].robj)
3147 >> 2);
Dave Airlie551ebd82009-09-01 15:25:57 +10003148 return -EINVAL;
3149 }
3150 }
3151 break;
3152 case 3:
3153 size = track->vtx_size * nverts;
3154 if (size != track->immd_dwords) {
3155 DRM_ERROR("IMMD draw %u dwors but needs %lu dwords\n",
3156 track->immd_dwords, size);
3157 DRM_ERROR("VAP_VF_CNTL.NUM_VERTICES %u, VTX_SIZE %u\n",
3158 nverts, track->vtx_size);
3159 return -EINVAL;
3160 }
3161 break;
3162 default:
3163 DRM_ERROR("[drm] Invalid primitive walk %d for VAP_VF_CNTL\n",
3164 prim_walk);
3165 return -EINVAL;
3166 }
3167 return r100_cs_track_texture_check(rdev, track);
3168}
3169
3170void r100_cs_track_clear(struct radeon_device *rdev, struct r100_cs_track *track)
3171{
3172 unsigned i, face;
3173
3174 if (rdev->family < CHIP_R300) {
3175 track->num_cb = 1;
3176 if (rdev->family <= CHIP_RS200)
3177 track->num_texture = 3;
3178 else
3179 track->num_texture = 6;
3180 track->maxy = 2048;
3181 track->separate_cube = 1;
3182 } else {
3183 track->num_cb = 4;
3184 track->num_texture = 16;
3185 track->maxy = 4096;
3186 track->separate_cube = 0;
3187 }
3188
3189 for (i = 0; i < track->num_cb; i++) {
3190 track->cb[i].robj = NULL;
3191 track->cb[i].pitch = 8192;
3192 track->cb[i].cpp = 16;
3193 track->cb[i].offset = 0;
3194 }
3195 track->z_enabled = true;
3196 track->zb.robj = NULL;
3197 track->zb.pitch = 8192;
3198 track->zb.cpp = 4;
3199 track->zb.offset = 0;
3200 track->vtx_size = 0x7F;
3201 track->immd_dwords = 0xFFFFFFFFUL;
3202 track->num_arrays = 11;
3203 track->max_indx = 0x00FFFFFFUL;
3204 for (i = 0; i < track->num_arrays; i++) {
3205 track->arrays[i].robj = NULL;
3206 track->arrays[i].esize = 0x7F;
3207 }
3208 for (i = 0; i < track->num_texture; i++) {
Dave Airlied785d782009-12-07 13:16:06 +10003209 track->textures[i].compress_format = R100_TRACK_COMP_NONE;
Dave Airlie551ebd82009-09-01 15:25:57 +10003210 track->textures[i].pitch = 16536;
3211 track->textures[i].width = 16536;
3212 track->textures[i].height = 16536;
3213 track->textures[i].width_11 = 1 << 11;
3214 track->textures[i].height_11 = 1 << 11;
3215 track->textures[i].num_levels = 12;
3216 if (rdev->family <= CHIP_RS200) {
3217 track->textures[i].tex_coord_type = 0;
3218 track->textures[i].txdepth = 0;
3219 } else {
3220 track->textures[i].txdepth = 16;
3221 track->textures[i].tex_coord_type = 1;
3222 }
3223 track->textures[i].cpp = 64;
3224 track->textures[i].robj = NULL;
3225 /* CS IB emission code makes sure texture unit are disabled */
3226 track->textures[i].enabled = false;
3227 track->textures[i].roundup_w = true;
3228 track->textures[i].roundup_h = true;
3229 if (track->separate_cube)
3230 for (face = 0; face < 5; face++) {
3231 track->textures[i].cube_info[face].robj = NULL;
3232 track->textures[i].cube_info[face].width = 16536;
3233 track->textures[i].cube_info[face].height = 16536;
3234 track->textures[i].cube_info[face].offset = 0;
3235 }
3236 }
3237}
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003238
3239int r100_ring_test(struct radeon_device *rdev)
3240{
3241 uint32_t scratch;
3242 uint32_t tmp = 0;
3243 unsigned i;
3244 int r;
3245
3246 r = radeon_scratch_get(rdev, &scratch);
3247 if (r) {
3248 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
3249 return r;
3250 }
3251 WREG32(scratch, 0xCAFEDEAD);
3252 r = radeon_ring_lock(rdev, 2);
3253 if (r) {
3254 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
3255 radeon_scratch_free(rdev, scratch);
3256 return r;
3257 }
3258 radeon_ring_write(rdev, PACKET0(scratch, 0));
3259 radeon_ring_write(rdev, 0xDEADBEEF);
3260 radeon_ring_unlock_commit(rdev);
3261 for (i = 0; i < rdev->usec_timeout; i++) {
3262 tmp = RREG32(scratch);
3263 if (tmp == 0xDEADBEEF) {
3264 break;
3265 }
3266 DRM_UDELAY(1);
3267 }
3268 if (i < rdev->usec_timeout) {
3269 DRM_INFO("ring test succeeded in %d usecs\n", i);
3270 } else {
3271 DRM_ERROR("radeon: ring test failed (sracth(0x%04X)=0x%08X)\n",
3272 scratch, tmp);
3273 r = -EINVAL;
3274 }
3275 radeon_scratch_free(rdev, scratch);
3276 return r;
3277}
3278
3279void r100_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
3280{
3281 radeon_ring_write(rdev, PACKET0(RADEON_CP_IB_BASE, 1));
3282 radeon_ring_write(rdev, ib->gpu_addr);
3283 radeon_ring_write(rdev, ib->length_dw);
3284}
3285
3286int r100_ib_test(struct radeon_device *rdev)
3287{
3288 struct radeon_ib *ib;
3289 uint32_t scratch;
3290 uint32_t tmp = 0;
3291 unsigned i;
3292 int r;
3293
3294 r = radeon_scratch_get(rdev, &scratch);
3295 if (r) {
3296 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
3297 return r;
3298 }
3299 WREG32(scratch, 0xCAFEDEAD);
3300 r = radeon_ib_get(rdev, &ib);
3301 if (r) {
3302 return r;
3303 }
3304 ib->ptr[0] = PACKET0(scratch, 0);
3305 ib->ptr[1] = 0xDEADBEEF;
3306 ib->ptr[2] = PACKET2(0);
3307 ib->ptr[3] = PACKET2(0);
3308 ib->ptr[4] = PACKET2(0);
3309 ib->ptr[5] = PACKET2(0);
3310 ib->ptr[6] = PACKET2(0);
3311 ib->ptr[7] = PACKET2(0);
3312 ib->length_dw = 8;
3313 r = radeon_ib_schedule(rdev, ib);
3314 if (r) {
3315 radeon_scratch_free(rdev, scratch);
3316 radeon_ib_free(rdev, &ib);
3317 return r;
3318 }
3319 r = radeon_fence_wait(ib->fence, false);
3320 if (r) {
3321 return r;
3322 }
3323 for (i = 0; i < rdev->usec_timeout; i++) {
3324 tmp = RREG32(scratch);
3325 if (tmp == 0xDEADBEEF) {
3326 break;
3327 }
3328 DRM_UDELAY(1);
3329 }
3330 if (i < rdev->usec_timeout) {
3331 DRM_INFO("ib test succeeded in %u usecs\n", i);
3332 } else {
3333 DRM_ERROR("radeon: ib test failed (sracth(0x%04X)=0x%08X)\n",
3334 scratch, tmp);
3335 r = -EINVAL;
3336 }
3337 radeon_scratch_free(rdev, scratch);
3338 radeon_ib_free(rdev, &ib);
3339 return r;
3340}
Jerome Glisse9f022dd2009-09-11 15:35:22 +02003341
3342void r100_ib_fini(struct radeon_device *rdev)
3343{
3344 radeon_ib_pool_fini(rdev);
3345}
3346
3347int r100_ib_init(struct radeon_device *rdev)
3348{
3349 int r;
3350
3351 r = radeon_ib_pool_init(rdev);
3352 if (r) {
3353 dev_err(rdev->dev, "failled initializing IB pool (%d).\n", r);
3354 r100_ib_fini(rdev);
3355 return r;
3356 }
3357 r = r100_ib_test(rdev);
3358 if (r) {
3359 dev_err(rdev->dev, "failled testing IB (%d).\n", r);
3360 r100_ib_fini(rdev);
3361 return r;
3362 }
3363 return 0;
3364}
3365
3366void r100_mc_stop(struct radeon_device *rdev, struct r100_mc_save *save)
3367{
3368 /* Shutdown CP we shouldn't need to do that but better be safe than
3369 * sorry
3370 */
3371 rdev->cp.ready = false;
3372 WREG32(R_000740_CP_CSQ_CNTL, 0);
3373
3374 /* Save few CRTC registers */
Jerome Glisseca6ffc62009-10-01 10:20:52 +02003375 save->GENMO_WT = RREG8(R_0003C2_GENMO_WT);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02003376 save->CRTC_EXT_CNTL = RREG32(R_000054_CRTC_EXT_CNTL);
3377 save->CRTC_GEN_CNTL = RREG32(R_000050_CRTC_GEN_CNTL);
3378 save->CUR_OFFSET = RREG32(R_000260_CUR_OFFSET);
3379 if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
3380 save->CRTC2_GEN_CNTL = RREG32(R_0003F8_CRTC2_GEN_CNTL);
3381 save->CUR2_OFFSET = RREG32(R_000360_CUR2_OFFSET);
3382 }
3383
3384 /* Disable VGA aperture access */
Jerome Glisseca6ffc62009-10-01 10:20:52 +02003385 WREG8(R_0003C2_GENMO_WT, C_0003C2_VGA_RAM_EN & save->GENMO_WT);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02003386 /* Disable cursor, overlay, crtc */
3387 WREG32(R_000260_CUR_OFFSET, save->CUR_OFFSET | S_000260_CUR_LOCK(1));
3388 WREG32(R_000054_CRTC_EXT_CNTL, save->CRTC_EXT_CNTL |
3389 S_000054_CRTC_DISPLAY_DIS(1));
3390 WREG32(R_000050_CRTC_GEN_CNTL,
3391 (C_000050_CRTC_CUR_EN & save->CRTC_GEN_CNTL) |
3392 S_000050_CRTC_DISP_REQ_EN_B(1));
3393 WREG32(R_000420_OV0_SCALE_CNTL,
3394 C_000420_OV0_OVERLAY_EN & RREG32(R_000420_OV0_SCALE_CNTL));
3395 WREG32(R_000260_CUR_OFFSET, C_000260_CUR_LOCK & save->CUR_OFFSET);
3396 if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
3397 WREG32(R_000360_CUR2_OFFSET, save->CUR2_OFFSET |
3398 S_000360_CUR2_LOCK(1));
3399 WREG32(R_0003F8_CRTC2_GEN_CNTL,
3400 (C_0003F8_CRTC2_CUR_EN & save->CRTC2_GEN_CNTL) |
3401 S_0003F8_CRTC2_DISPLAY_DIS(1) |
3402 S_0003F8_CRTC2_DISP_REQ_EN_B(1));
3403 WREG32(R_000360_CUR2_OFFSET,
3404 C_000360_CUR2_LOCK & save->CUR2_OFFSET);
3405 }
3406}
3407
3408void r100_mc_resume(struct radeon_device *rdev, struct r100_mc_save *save)
3409{
3410 /* Update base address for crtc */
Jerome Glissed594e462010-02-17 21:54:29 +00003411 WREG32(R_00023C_DISPLAY_BASE_ADDR, rdev->mc.vram_start);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02003412 if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
Jerome Glissed594e462010-02-17 21:54:29 +00003413 WREG32(R_00033C_CRTC2_DISPLAY_BASE_ADDR, rdev->mc.vram_start);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02003414 }
3415 /* Restore CRTC registers */
Jerome Glisseca6ffc62009-10-01 10:20:52 +02003416 WREG8(R_0003C2_GENMO_WT, save->GENMO_WT);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02003417 WREG32(R_000054_CRTC_EXT_CNTL, save->CRTC_EXT_CNTL);
3418 WREG32(R_000050_CRTC_GEN_CNTL, save->CRTC_GEN_CNTL);
3419 if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
3420 WREG32(R_0003F8_CRTC2_GEN_CNTL, save->CRTC2_GEN_CNTL);
3421 }
3422}
Jerome Glisseca6ffc62009-10-01 10:20:52 +02003423
3424void r100_vga_render_disable(struct radeon_device *rdev)
3425{
Jerome Glissed4550902009-10-01 10:12:06 +02003426 u32 tmp;
Jerome Glisseca6ffc62009-10-01 10:20:52 +02003427
Jerome Glissed4550902009-10-01 10:12:06 +02003428 tmp = RREG8(R_0003C2_GENMO_WT);
Jerome Glisseca6ffc62009-10-01 10:20:52 +02003429 WREG8(R_0003C2_GENMO_WT, C_0003C2_VGA_RAM_EN & tmp);
3430}
Jerome Glissed4550902009-10-01 10:12:06 +02003431
3432static void r100_debugfs(struct radeon_device *rdev)
3433{
3434 int r;
3435
3436 r = r100_debugfs_mc_info_init(rdev);
3437 if (r)
3438 dev_warn(rdev->dev, "Failed to create r100_mc debugfs file.\n");
3439}
3440
3441static void r100_mc_program(struct radeon_device *rdev)
3442{
3443 struct r100_mc_save save;
3444
3445 /* Stops all mc clients */
3446 r100_mc_stop(rdev, &save);
3447 if (rdev->flags & RADEON_IS_AGP) {
3448 WREG32(R_00014C_MC_AGP_LOCATION,
3449 S_00014C_MC_AGP_START(rdev->mc.gtt_start >> 16) |
3450 S_00014C_MC_AGP_TOP(rdev->mc.gtt_end >> 16));
3451 WREG32(R_000170_AGP_BASE, lower_32_bits(rdev->mc.agp_base));
3452 if (rdev->family > CHIP_RV200)
3453 WREG32(R_00015C_AGP_BASE_2,
3454 upper_32_bits(rdev->mc.agp_base) & 0xff);
3455 } else {
3456 WREG32(R_00014C_MC_AGP_LOCATION, 0x0FFFFFFF);
3457 WREG32(R_000170_AGP_BASE, 0);
3458 if (rdev->family > CHIP_RV200)
3459 WREG32(R_00015C_AGP_BASE_2, 0);
3460 }
3461 /* Wait for mc idle */
3462 if (r100_mc_wait_for_idle(rdev))
3463 dev_warn(rdev->dev, "Wait for MC idle timeout.\n");
3464 /* Program MC, should be a 32bits limited address space */
3465 WREG32(R_000148_MC_FB_LOCATION,
3466 S_000148_MC_FB_START(rdev->mc.vram_start >> 16) |
3467 S_000148_MC_FB_TOP(rdev->mc.vram_end >> 16));
3468 r100_mc_resume(rdev, &save);
3469}
3470
3471void r100_clock_startup(struct radeon_device *rdev)
3472{
3473 u32 tmp;
3474
3475 if (radeon_dynclks != -1 && radeon_dynclks)
3476 radeon_legacy_set_clock_gating(rdev, 1);
3477 /* We need to force on some of the block */
3478 tmp = RREG32_PLL(R_00000D_SCLK_CNTL);
3479 tmp |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
3480 if ((rdev->family == CHIP_RV250) || (rdev->family == CHIP_RV280))
3481 tmp |= S_00000D_FORCE_DISP1(1) | S_00000D_FORCE_DISP2(1);
3482 WREG32_PLL(R_00000D_SCLK_CNTL, tmp);
3483}
3484
3485static int r100_startup(struct radeon_device *rdev)
3486{
3487 int r;
3488
Alex Deucher92cde002009-12-04 10:55:12 -05003489 /* set common regs */
3490 r100_set_common_regs(rdev);
3491 /* program mc */
Jerome Glissed4550902009-10-01 10:12:06 +02003492 r100_mc_program(rdev);
3493 /* Resume clock */
3494 r100_clock_startup(rdev);
3495 /* Initialize GPU configuration (# pipes, ...) */
Jerome Glisse90aca4d2010-03-09 14:45:12 +00003496// r100_gpu_init(rdev);
Jerome Glissed4550902009-10-01 10:12:06 +02003497 /* Initialize GART (initialize after TTM so we can allocate
3498 * memory through TTM but finalize after TTM) */
Dave Airlie17e15b02009-11-05 15:36:53 +10003499 r100_enable_bm(rdev);
Jerome Glissed4550902009-10-01 10:12:06 +02003500 if (rdev->flags & RADEON_IS_PCI) {
3501 r = r100_pci_gart_enable(rdev);
3502 if (r)
3503 return r;
3504 }
3505 /* Enable IRQ */
Jerome Glissed4550902009-10-01 10:12:06 +02003506 r100_irq_set(rdev);
Jerome Glissecafe6602010-01-07 12:39:21 +01003507 rdev->config.r100.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
Jerome Glissed4550902009-10-01 10:12:06 +02003508 /* 1M ring buffer */
3509 r = r100_cp_init(rdev, 1024 * 1024);
3510 if (r) {
3511 dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
3512 return r;
3513 }
3514 r = r100_wb_init(rdev);
3515 if (r)
3516 dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
3517 r = r100_ib_init(rdev);
3518 if (r) {
3519 dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
3520 return r;
3521 }
3522 return 0;
3523}
3524
3525int r100_resume(struct radeon_device *rdev)
3526{
3527 /* Make sur GART are not working */
3528 if (rdev->flags & RADEON_IS_PCI)
3529 r100_pci_gart_disable(rdev);
3530 /* Resume clock before doing reset */
3531 r100_clock_startup(rdev);
3532 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
Jerome Glissea2d07b72010-03-09 14:45:11 +00003533 if (radeon_asic_reset(rdev)) {
Jerome Glissed4550902009-10-01 10:12:06 +02003534 dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
3535 RREG32(R_000E40_RBBM_STATUS),
3536 RREG32(R_0007C0_CP_STAT));
3537 }
3538 /* post */
3539 radeon_combios_asic_init(rdev->ddev);
3540 /* Resume clock after posting */
3541 r100_clock_startup(rdev);
Dave Airlie550e2d92009-12-09 14:15:38 +10003542 /* Initialize surface registers */
3543 radeon_surface_init(rdev);
Jerome Glissed4550902009-10-01 10:12:06 +02003544 return r100_startup(rdev);
3545}
3546
3547int r100_suspend(struct radeon_device *rdev)
3548{
3549 r100_cp_disable(rdev);
3550 r100_wb_disable(rdev);
3551 r100_irq_disable(rdev);
3552 if (rdev->flags & RADEON_IS_PCI)
3553 r100_pci_gart_disable(rdev);
3554 return 0;
3555}
3556
3557void r100_fini(struct radeon_device *rdev)
3558{
Alex Deucher29fb52c2010-03-11 10:01:17 -05003559 radeon_pm_fini(rdev);
Jerome Glissed4550902009-10-01 10:12:06 +02003560 r100_cp_fini(rdev);
3561 r100_wb_fini(rdev);
3562 r100_ib_fini(rdev);
3563 radeon_gem_fini(rdev);
3564 if (rdev->flags & RADEON_IS_PCI)
3565 r100_pci_gart_fini(rdev);
Jerome Glissed0269ed2010-01-07 16:08:32 +01003566 radeon_agp_fini(rdev);
Jerome Glissed4550902009-10-01 10:12:06 +02003567 radeon_irq_kms_fini(rdev);
3568 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01003569 radeon_bo_fini(rdev);
Jerome Glissed4550902009-10-01 10:12:06 +02003570 radeon_atombios_fini(rdev);
3571 kfree(rdev->bios);
3572 rdev->bios = NULL;
3573}
3574
Jerome Glissed4550902009-10-01 10:12:06 +02003575int r100_init(struct radeon_device *rdev)
3576{
3577 int r;
3578
Jerome Glissed4550902009-10-01 10:12:06 +02003579 /* Register debugfs file specific to this group of asics */
3580 r100_debugfs(rdev);
3581 /* Disable VGA */
3582 r100_vga_render_disable(rdev);
3583 /* Initialize scratch registers */
3584 radeon_scratch_init(rdev);
3585 /* Initialize surface registers */
3586 radeon_surface_init(rdev);
3587 /* TODO: disable VGA need to use VGA request */
3588 /* BIOS*/
3589 if (!radeon_get_bios(rdev)) {
3590 if (ASIC_IS_AVIVO(rdev))
3591 return -EINVAL;
3592 }
3593 if (rdev->is_atom_bios) {
3594 dev_err(rdev->dev, "Expecting combios for RS400/RS480 GPU\n");
3595 return -EINVAL;
3596 } else {
3597 r = radeon_combios_init(rdev);
3598 if (r)
3599 return r;
3600 }
3601 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
Jerome Glissea2d07b72010-03-09 14:45:11 +00003602 if (radeon_asic_reset(rdev)) {
Jerome Glissed4550902009-10-01 10:12:06 +02003603 dev_warn(rdev->dev,
3604 "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
3605 RREG32(R_000E40_RBBM_STATUS),
3606 RREG32(R_0007C0_CP_STAT));
3607 }
3608 /* check if cards are posted or not */
Dave Airlie72542d72009-12-01 14:06:31 +10003609 if (radeon_boot_test_post_card(rdev) == false)
3610 return -EINVAL;
Jerome Glissed4550902009-10-01 10:12:06 +02003611 /* Set asic errata */
3612 r100_errata(rdev);
3613 /* Initialize clocks */
3614 radeon_get_clock_info(rdev->ddev);
Rafał Miłecki62340772009-12-15 21:46:58 +01003615 /* Initialize power management */
3616 radeon_pm_init(rdev);
Jerome Glissed594e462010-02-17 21:54:29 +00003617 /* initialize AGP */
3618 if (rdev->flags & RADEON_IS_AGP) {
3619 r = radeon_agp_init(rdev);
3620 if (r) {
3621 radeon_agp_disable(rdev);
3622 }
3623 }
3624 /* initialize VRAM */
3625 r100_mc_init(rdev);
Jerome Glissed4550902009-10-01 10:12:06 +02003626 /* Fence driver */
3627 r = radeon_fence_driver_init(rdev);
3628 if (r)
3629 return r;
3630 r = radeon_irq_kms_init(rdev);
3631 if (r)
3632 return r;
3633 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01003634 r = radeon_bo_init(rdev);
Jerome Glissed4550902009-10-01 10:12:06 +02003635 if (r)
3636 return r;
3637 if (rdev->flags & RADEON_IS_PCI) {
3638 r = r100_pci_gart_init(rdev);
3639 if (r)
3640 return r;
3641 }
3642 r100_set_safe_registers(rdev);
3643 rdev->accel_working = true;
3644 r = r100_startup(rdev);
3645 if (r) {
3646 /* Somethings want wront with the accel init stop accel */
3647 dev_err(rdev->dev, "Disabling GPU acceleration\n");
Jerome Glissed4550902009-10-01 10:12:06 +02003648 r100_cp_fini(rdev);
3649 r100_wb_fini(rdev);
3650 r100_ib_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01003651 radeon_irq_kms_fini(rdev);
Jerome Glissed4550902009-10-01 10:12:06 +02003652 if (rdev->flags & RADEON_IS_PCI)
3653 r100_pci_gart_fini(rdev);
Jerome Glissed4550902009-10-01 10:12:06 +02003654 rdev->accel_working = false;
3655 }
3656 return 0;
3657}