blob: 0c065f425c845e16d76d033d41673050b75c5504 [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +100028#include <linux/seq_file.h>
29#include <linux/firmware.h>
30#include <linux/platform_device.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020031#include "drmP.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100032#include "radeon_drm.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020033#include "radeon.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100034#include "radeon_mode.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100035#include "r600d.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100036#include "atom.h"
Jerome Glissed39c3b82009-09-28 18:34:43 +020037#include "avivod.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020038
Jerome Glisse3ce0a232009-09-08 10:10:24 +100039#define PFP_UCODE_SIZE 576
40#define PM4_UCODE_SIZE 1792
Alex Deucherd8f60cf2009-12-01 13:43:46 -050041#define RLC_UCODE_SIZE 768
Jerome Glisse3ce0a232009-09-08 10:10:24 +100042#define R700_PFP_UCODE_SIZE 848
43#define R700_PM4_UCODE_SIZE 1360
Alex Deucherd8f60cf2009-12-01 13:43:46 -050044#define R700_RLC_UCODE_SIZE 1024
Jerome Glisse3ce0a232009-09-08 10:10:24 +100045
46/* Firmware Names */
47MODULE_FIRMWARE("radeon/R600_pfp.bin");
48MODULE_FIRMWARE("radeon/R600_me.bin");
49MODULE_FIRMWARE("radeon/RV610_pfp.bin");
50MODULE_FIRMWARE("radeon/RV610_me.bin");
51MODULE_FIRMWARE("radeon/RV630_pfp.bin");
52MODULE_FIRMWARE("radeon/RV630_me.bin");
53MODULE_FIRMWARE("radeon/RV620_pfp.bin");
54MODULE_FIRMWARE("radeon/RV620_me.bin");
55MODULE_FIRMWARE("radeon/RV635_pfp.bin");
56MODULE_FIRMWARE("radeon/RV635_me.bin");
57MODULE_FIRMWARE("radeon/RV670_pfp.bin");
58MODULE_FIRMWARE("radeon/RV670_me.bin");
59MODULE_FIRMWARE("radeon/RS780_pfp.bin");
60MODULE_FIRMWARE("radeon/RS780_me.bin");
61MODULE_FIRMWARE("radeon/RV770_pfp.bin");
62MODULE_FIRMWARE("radeon/RV770_me.bin");
63MODULE_FIRMWARE("radeon/RV730_pfp.bin");
64MODULE_FIRMWARE("radeon/RV730_me.bin");
65MODULE_FIRMWARE("radeon/RV710_pfp.bin");
66MODULE_FIRMWARE("radeon/RV710_me.bin");
Alex Deucherd8f60cf2009-12-01 13:43:46 -050067MODULE_FIRMWARE("radeon/R600_rlc.bin");
68MODULE_FIRMWARE("radeon/R700_rlc.bin");
Jerome Glisse3ce0a232009-09-08 10:10:24 +100069
70int r600_debugfs_mc_info_init(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020071
Jerome Glisse1a029b72009-10-06 19:04:30 +020072/* r600,rv610,rv630,rv620,rv635,rv670 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +020073int r600_mc_wait_for_idle(struct radeon_device *rdev);
74void r600_gpu_init(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100075void r600_fini(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020076
Alex Deuchere0df1ac2009-12-04 15:12:21 -050077/* hpd for digital panel detect/disconnect */
78bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
79{
80 bool connected = false;
81
82 if (ASIC_IS_DCE3(rdev)) {
83 switch (hpd) {
84 case RADEON_HPD_1:
85 if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
86 connected = true;
87 break;
88 case RADEON_HPD_2:
89 if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
90 connected = true;
91 break;
92 case RADEON_HPD_3:
93 if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
94 connected = true;
95 break;
96 case RADEON_HPD_4:
97 if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
98 connected = true;
99 break;
100 /* DCE 3.2 */
101 case RADEON_HPD_5:
102 if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
103 connected = true;
104 break;
105 case RADEON_HPD_6:
106 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
107 connected = true;
108 break;
109 default:
110 break;
111 }
112 } else {
113 switch (hpd) {
114 case RADEON_HPD_1:
115 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
116 connected = true;
117 break;
118 case RADEON_HPD_2:
119 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
120 connected = true;
121 break;
122 case RADEON_HPD_3:
123 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
124 connected = true;
125 break;
126 default:
127 break;
128 }
129 }
130 return connected;
131}
132
133void r600_hpd_set_polarity(struct radeon_device *rdev,
Alex Deucher429770b2009-12-04 15:26:55 -0500134 enum radeon_hpd_id hpd)
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500135{
136 u32 tmp;
137 bool connected = r600_hpd_sense(rdev, hpd);
138
139 if (ASIC_IS_DCE3(rdev)) {
140 switch (hpd) {
141 case RADEON_HPD_1:
142 tmp = RREG32(DC_HPD1_INT_CONTROL);
143 if (connected)
144 tmp &= ~DC_HPDx_INT_POLARITY;
145 else
146 tmp |= DC_HPDx_INT_POLARITY;
147 WREG32(DC_HPD1_INT_CONTROL, tmp);
148 break;
149 case RADEON_HPD_2:
150 tmp = RREG32(DC_HPD2_INT_CONTROL);
151 if (connected)
152 tmp &= ~DC_HPDx_INT_POLARITY;
153 else
154 tmp |= DC_HPDx_INT_POLARITY;
155 WREG32(DC_HPD2_INT_CONTROL, tmp);
156 break;
157 case RADEON_HPD_3:
158 tmp = RREG32(DC_HPD3_INT_CONTROL);
159 if (connected)
160 tmp &= ~DC_HPDx_INT_POLARITY;
161 else
162 tmp |= DC_HPDx_INT_POLARITY;
163 WREG32(DC_HPD3_INT_CONTROL, tmp);
164 break;
165 case RADEON_HPD_4:
166 tmp = RREG32(DC_HPD4_INT_CONTROL);
167 if (connected)
168 tmp &= ~DC_HPDx_INT_POLARITY;
169 else
170 tmp |= DC_HPDx_INT_POLARITY;
171 WREG32(DC_HPD4_INT_CONTROL, tmp);
172 break;
173 case RADEON_HPD_5:
174 tmp = RREG32(DC_HPD5_INT_CONTROL);
175 if (connected)
176 tmp &= ~DC_HPDx_INT_POLARITY;
177 else
178 tmp |= DC_HPDx_INT_POLARITY;
179 WREG32(DC_HPD5_INT_CONTROL, tmp);
180 break;
181 /* DCE 3.2 */
182 case RADEON_HPD_6:
183 tmp = RREG32(DC_HPD6_INT_CONTROL);
184 if (connected)
185 tmp &= ~DC_HPDx_INT_POLARITY;
186 else
187 tmp |= DC_HPDx_INT_POLARITY;
188 WREG32(DC_HPD6_INT_CONTROL, tmp);
189 break;
190 default:
191 break;
192 }
193 } else {
194 switch (hpd) {
195 case RADEON_HPD_1:
196 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
197 if (connected)
198 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
199 else
200 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
201 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
202 break;
203 case RADEON_HPD_2:
204 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
205 if (connected)
206 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
207 else
208 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
209 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
210 break;
211 case RADEON_HPD_3:
212 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
213 if (connected)
214 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
215 else
216 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
217 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
218 break;
219 default:
220 break;
221 }
222 }
223}
224
225void r600_hpd_init(struct radeon_device *rdev)
226{
227 struct drm_device *dev = rdev->ddev;
228 struct drm_connector *connector;
229
230 if (ASIC_IS_DCE3(rdev)) {
231 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
232 if (ASIC_IS_DCE32(rdev))
233 tmp |= DC_HPDx_EN;
234
235 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
236 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
237 switch (radeon_connector->hpd.hpd) {
238 case RADEON_HPD_1:
239 WREG32(DC_HPD1_CONTROL, tmp);
240 rdev->irq.hpd[0] = true;
241 break;
242 case RADEON_HPD_2:
243 WREG32(DC_HPD2_CONTROL, tmp);
244 rdev->irq.hpd[1] = true;
245 break;
246 case RADEON_HPD_3:
247 WREG32(DC_HPD3_CONTROL, tmp);
248 rdev->irq.hpd[2] = true;
249 break;
250 case RADEON_HPD_4:
251 WREG32(DC_HPD4_CONTROL, tmp);
252 rdev->irq.hpd[3] = true;
253 break;
254 /* DCE 3.2 */
255 case RADEON_HPD_5:
256 WREG32(DC_HPD5_CONTROL, tmp);
257 rdev->irq.hpd[4] = true;
258 break;
259 case RADEON_HPD_6:
260 WREG32(DC_HPD6_CONTROL, tmp);
261 rdev->irq.hpd[5] = true;
262 break;
263 default:
264 break;
265 }
266 }
267 } else {
268 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
269 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
270 switch (radeon_connector->hpd.hpd) {
271 case RADEON_HPD_1:
272 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
273 rdev->irq.hpd[0] = true;
274 break;
275 case RADEON_HPD_2:
276 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
277 rdev->irq.hpd[1] = true;
278 break;
279 case RADEON_HPD_3:
280 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
281 rdev->irq.hpd[2] = true;
282 break;
283 default:
284 break;
285 }
286 }
287 }
288 r600_irq_set(rdev);
289}
290
291void r600_hpd_fini(struct radeon_device *rdev)
292{
293 struct drm_device *dev = rdev->ddev;
294 struct drm_connector *connector;
295
296 if (ASIC_IS_DCE3(rdev)) {
297 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
298 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
299 switch (radeon_connector->hpd.hpd) {
300 case RADEON_HPD_1:
301 WREG32(DC_HPD1_CONTROL, 0);
302 rdev->irq.hpd[0] = false;
303 break;
304 case RADEON_HPD_2:
305 WREG32(DC_HPD2_CONTROL, 0);
306 rdev->irq.hpd[1] = false;
307 break;
308 case RADEON_HPD_3:
309 WREG32(DC_HPD3_CONTROL, 0);
310 rdev->irq.hpd[2] = false;
311 break;
312 case RADEON_HPD_4:
313 WREG32(DC_HPD4_CONTROL, 0);
314 rdev->irq.hpd[3] = false;
315 break;
316 /* DCE 3.2 */
317 case RADEON_HPD_5:
318 WREG32(DC_HPD5_CONTROL, 0);
319 rdev->irq.hpd[4] = false;
320 break;
321 case RADEON_HPD_6:
322 WREG32(DC_HPD6_CONTROL, 0);
323 rdev->irq.hpd[5] = false;
324 break;
325 default:
326 break;
327 }
328 }
329 } else {
330 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
331 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
332 switch (radeon_connector->hpd.hpd) {
333 case RADEON_HPD_1:
334 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
335 rdev->irq.hpd[0] = false;
336 break;
337 case RADEON_HPD_2:
338 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
339 rdev->irq.hpd[1] = false;
340 break;
341 case RADEON_HPD_3:
342 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
343 rdev->irq.hpd[2] = false;
344 break;
345 default:
346 break;
347 }
348 }
349 }
350}
351
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200352/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000353 * R600 PCIE GART
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200354 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000355int r600_gart_clear_page(struct radeon_device *rdev, int i)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200356{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000357 void __iomem *ptr = (void *)rdev->gart.table.vram.ptr;
358 u64 pte;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200359
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000360 if (i < 0 || i > rdev->gart.num_gpu_pages)
361 return -EINVAL;
362 pte = 0;
363 writeq(pte, ((void __iomem *)ptr) + (i * 8));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200364 return 0;
365}
366
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000367void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200368{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000369 unsigned i;
370 u32 tmp;
371
372 WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
373 WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
374 WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
375 for (i = 0; i < rdev->usec_timeout; i++) {
376 /* read MC_STATUS */
377 tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
378 tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
379 if (tmp == 2) {
380 printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
381 return;
382 }
383 if (tmp) {
384 return;
385 }
386 udelay(1);
387 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200388}
389
Jerome Glisse4aac0472009-09-14 18:29:49 +0200390int r600_pcie_gart_init(struct radeon_device *rdev)
391{
392 int r;
393
394 if (rdev->gart.table.vram.robj) {
395 WARN(1, "R600 PCIE GART already initialized.\n");
396 return 0;
397 }
398 /* Initialize common gart structure */
399 r = radeon_gart_init(rdev);
400 if (r)
401 return r;
402 rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
403 return radeon_gart_table_vram_alloc(rdev);
404}
405
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000406int r600_pcie_gart_enable(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200407{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000408 u32 tmp;
409 int r, i;
410
Jerome Glisse4aac0472009-09-14 18:29:49 +0200411 if (rdev->gart.table.vram.robj == NULL) {
412 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
413 return -EINVAL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000414 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200415 r = radeon_gart_table_vram_pin(rdev);
416 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000417 return r;
Dave Airliebc1a6312009-09-15 11:07:52 +1000418
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000419 /* Setup L2 cache */
420 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
421 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
422 EFFECTIVE_L2_QUEUE_SIZE(7));
423 WREG32(VM_L2_CNTL2, 0);
424 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
425 /* Setup TLB control */
426 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
427 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
428 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
429 ENABLE_WAIT_L2_QUERY;
430 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
431 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
432 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
433 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
434 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
435 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
436 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
437 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
438 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
439 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
440 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
441 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
442 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
443 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
444 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200445 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000446 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
447 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
448 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
449 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
450 (u32)(rdev->dummy_page.addr >> 12));
451 for (i = 1; i < 7; i++)
452 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
453
454 r600_pcie_gart_tlb_flush(rdev);
455 rdev->gart.ready = true;
456 return 0;
457}
458
459void r600_pcie_gart_disable(struct radeon_device *rdev)
460{
461 u32 tmp;
Jerome Glisse4c788672009-11-20 14:29:23 +0100462 int i, r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000463
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000464 /* Disable all tables */
465 for (i = 0; i < 7; i++)
466 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
467
468 /* Disable L2 cache */
469 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
470 EFFECTIVE_L2_QUEUE_SIZE(7));
471 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
472 /* Setup L1 TLB control */
473 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
474 ENABLE_WAIT_L2_QUERY;
475 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
476 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
477 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
478 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
479 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
480 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
481 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
482 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
483 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
484 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
485 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
486 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
487 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
488 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200489 if (rdev->gart.table.vram.robj) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100490 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
491 if (likely(r == 0)) {
492 radeon_bo_kunmap(rdev->gart.table.vram.robj);
493 radeon_bo_unpin(rdev->gart.table.vram.robj);
494 radeon_bo_unreserve(rdev->gart.table.vram.robj);
495 }
Jerome Glisse4aac0472009-09-14 18:29:49 +0200496 }
497}
498
499void r600_pcie_gart_fini(struct radeon_device *rdev)
500{
501 r600_pcie_gart_disable(rdev);
502 radeon_gart_table_vram_free(rdev);
503 radeon_gart_fini(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200504}
505
Jerome Glisse1a029b72009-10-06 19:04:30 +0200506void r600_agp_enable(struct radeon_device *rdev)
507{
508 u32 tmp;
509 int i;
510
511 /* Setup L2 cache */
512 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
513 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
514 EFFECTIVE_L2_QUEUE_SIZE(7));
515 WREG32(VM_L2_CNTL2, 0);
516 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
517 /* Setup TLB control */
518 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
519 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
520 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
521 ENABLE_WAIT_L2_QUERY;
522 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
523 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
524 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
525 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
526 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
527 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
528 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
529 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
530 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
531 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
532 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
533 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
534 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
535 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
536 for (i = 0; i < 7; i++)
537 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
538}
539
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200540int r600_mc_wait_for_idle(struct radeon_device *rdev)
541{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000542 unsigned i;
543 u32 tmp;
544
545 for (i = 0; i < rdev->usec_timeout; i++) {
546 /* read MC_STATUS */
547 tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
548 if (!tmp)
549 return 0;
550 udelay(1);
551 }
552 return -1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200553}
554
Jerome Glissea3c19452009-10-01 18:02:13 +0200555static void r600_mc_program(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200556{
Jerome Glissea3c19452009-10-01 18:02:13 +0200557 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000558 u32 tmp;
559 int i, j;
560
561 /* Initialize HDP */
562 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
563 WREG32((0x2c14 + j), 0x00000000);
564 WREG32((0x2c18 + j), 0x00000000);
565 WREG32((0x2c1c + j), 0x00000000);
566 WREG32((0x2c20 + j), 0x00000000);
567 WREG32((0x2c24 + j), 0x00000000);
568 }
569 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
570
Jerome Glissea3c19452009-10-01 18:02:13 +0200571 rv515_mc_stop(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000572 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +0200573 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000574 }
Jerome Glissea3c19452009-10-01 18:02:13 +0200575 /* Lockout access through VGA aperture (doesn't exist before R600) */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000576 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000577 /* Update configuration */
Jerome Glisse1a029b72009-10-06 19:04:30 +0200578 if (rdev->flags & RADEON_IS_AGP) {
579 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
580 /* VRAM before AGP */
581 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
582 rdev->mc.vram_start >> 12);
583 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
584 rdev->mc.gtt_end >> 12);
585 } else {
586 /* VRAM after AGP */
587 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
588 rdev->mc.gtt_start >> 12);
589 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
590 rdev->mc.vram_end >> 12);
591 }
592 } else {
593 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
594 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
595 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000596 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200597 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000598 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
599 WREG32(MC_VM_FB_LOCATION, tmp);
600 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
601 WREG32(HDP_NONSURFACE_INFO, (2 << 7));
Jerome Glisse1a029b72009-10-06 19:04:30 +0200602 WREG32(HDP_NONSURFACE_SIZE, rdev->mc.mc_vram_size | 0x3FF);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000603 if (rdev->flags & RADEON_IS_AGP) {
Jerome Glisse1a029b72009-10-06 19:04:30 +0200604 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
605 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000606 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
607 } else {
608 WREG32(MC_VM_AGP_BASE, 0);
609 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
610 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
611 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000612 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +0200613 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000614 }
Jerome Glissea3c19452009-10-01 18:02:13 +0200615 rv515_mc_resume(rdev, &save);
Dave Airlie698443d2009-09-18 14:16:38 +1000616 /* we need to own VRAM, so turn off the VGA renderer here
617 * to stop it overwriting our objects */
Jerome Glissed39c3b82009-09-28 18:34:43 +0200618 rv515_vga_render_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200619}
620
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000621int r600_mc_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200622{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000623 fixed20_12 a;
624 u32 tmp;
Alex Deucher5885b7a2009-10-19 17:23:33 -0400625 int chansize, numchan;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000626 int r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200627
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000628 /* Get VRAM informations */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200629 rdev->mc.vram_is_ddr = true;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000630 tmp = RREG32(RAMCFG);
631 if (tmp & CHANSIZE_OVERRIDE) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200632 chansize = 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000633 } else if (tmp & CHANSIZE_MASK) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200634 chansize = 64;
635 } else {
636 chansize = 32;
637 }
Alex Deucher5885b7a2009-10-19 17:23:33 -0400638 tmp = RREG32(CHMAP);
639 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
640 case 0:
641 default:
642 numchan = 1;
643 break;
644 case 1:
645 numchan = 2;
646 break;
647 case 2:
648 numchan = 4;
649 break;
650 case 3:
651 numchan = 8;
652 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200653 }
Alex Deucher5885b7a2009-10-19 17:23:33 -0400654 rdev->mc.vram_width = numchan * chansize;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200655 /* Could aper size report 0 ? */
656 rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
657 rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000658 /* Setup GPU memory space */
659 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
660 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
Alex Deucher974b16e2009-09-25 10:06:39 -0400661
662 if (rdev->mc.mc_vram_size > rdev->mc.aper_size)
663 rdev->mc.mc_vram_size = rdev->mc.aper_size;
664
665 if (rdev->mc.real_vram_size > rdev->mc.aper_size)
666 rdev->mc.real_vram_size = rdev->mc.aper_size;
667
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000668 if (rdev->flags & RADEON_IS_AGP) {
669 r = radeon_agp_init(rdev);
670 if (r)
671 return r;
672 /* gtt_size is setup by radeon_agp_init */
673 rdev->mc.gtt_location = rdev->mc.agp_base;
674 tmp = 0xFFFFFFFFUL - rdev->mc.agp_base - rdev->mc.gtt_size;
675 /* Try to put vram before or after AGP because we
676 * we want SYSTEM_APERTURE to cover both VRAM and
677 * AGP so that GPU can catch out of VRAM/AGP access
678 */
679 if (rdev->mc.gtt_location > rdev->mc.mc_vram_size) {
680 /* Enought place before */
681 rdev->mc.vram_location = rdev->mc.gtt_location -
682 rdev->mc.mc_vram_size;
683 } else if (tmp > rdev->mc.mc_vram_size) {
684 /* Enought place after */
685 rdev->mc.vram_location = rdev->mc.gtt_location +
686 rdev->mc.gtt_size;
687 } else {
688 /* Try to setup VRAM then AGP might not
689 * not work on some card
690 */
691 rdev->mc.vram_location = 0x00000000UL;
692 rdev->mc.gtt_location = rdev->mc.mc_vram_size;
693 }
694 } else {
Dave Airlie4d357ab2009-11-03 14:54:36 +1000695 rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024;
696 rdev->mc.vram_location = (RREG32(MC_VM_FB_LOCATION) &
697 0xFFFF) << 24;
698 tmp = rdev->mc.vram_location + rdev->mc.mc_vram_size;
699 if ((0xFFFFFFFFUL - tmp) >= rdev->mc.gtt_size) {
700 /* Enough place after vram */
701 rdev->mc.gtt_location = tmp;
702 } else if (rdev->mc.vram_location >= rdev->mc.gtt_size) {
703 /* Enough place before vram */
704 rdev->mc.gtt_location = 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000705 } else {
Dave Airlie4d357ab2009-11-03 14:54:36 +1000706 /* Not enough place after or before shrink
707 * gart size
708 */
709 if (rdev->mc.vram_location > (0xFFFFFFFFUL - tmp)) {
710 rdev->mc.gtt_location = 0;
711 rdev->mc.gtt_size = rdev->mc.vram_location;
712 } else {
713 rdev->mc.gtt_location = tmp;
714 rdev->mc.gtt_size = 0xFFFFFFFFUL - tmp;
715 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000716 }
Dave Airlie4d357ab2009-11-03 14:54:36 +1000717 rdev->mc.gtt_location = rdev->mc.mc_vram_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000718 }
719 rdev->mc.vram_start = rdev->mc.vram_location;
Jerome Glisse1a029b72009-10-06 19:04:30 +0200720 rdev->mc.vram_end = rdev->mc.vram_location + rdev->mc.mc_vram_size - 1;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000721 rdev->mc.gtt_start = rdev->mc.gtt_location;
Jerome Glisse1a029b72009-10-06 19:04:30 +0200722 rdev->mc.gtt_end = rdev->mc.gtt_location + rdev->mc.gtt_size - 1;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000723 /* FIXME: we should enforce default clock in case GPU is not in
724 * default setup
725 */
726 a.full = rfixed_const(100);
727 rdev->pm.sclk.full = rfixed_const(rdev->clock.default_sclk);
728 rdev->pm.sclk.full = rfixed_div(rdev->pm.sclk, a);
Alex Deucher06b64762010-01-05 11:27:29 -0500729
730 if (rdev->flags & RADEON_IS_IGP)
731 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
732
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000733 return 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200734}
735
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000736/* We doesn't check that the GPU really needs a reset we simply do the
737 * reset, it's up to the caller to determine if the GPU needs one. We
738 * might add an helper function to check that.
739 */
740int r600_gpu_soft_reset(struct radeon_device *rdev)
741{
Jerome Glissea3c19452009-10-01 18:02:13 +0200742 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000743 u32 grbm_busy_mask = S_008010_VC_BUSY(1) | S_008010_VGT_BUSY_NO_DMA(1) |
744 S_008010_VGT_BUSY(1) | S_008010_TA03_BUSY(1) |
745 S_008010_TC_BUSY(1) | S_008010_SX_BUSY(1) |
746 S_008010_SH_BUSY(1) | S_008010_SPI03_BUSY(1) |
747 S_008010_SMX_BUSY(1) | S_008010_SC_BUSY(1) |
748 S_008010_PA_BUSY(1) | S_008010_DB03_BUSY(1) |
749 S_008010_CR_BUSY(1) | S_008010_CB03_BUSY(1) |
750 S_008010_GUI_ACTIVE(1);
751 u32 grbm2_busy_mask = S_008014_SPI0_BUSY(1) | S_008014_SPI1_BUSY(1) |
752 S_008014_SPI2_BUSY(1) | S_008014_SPI3_BUSY(1) |
753 S_008014_TA0_BUSY(1) | S_008014_TA1_BUSY(1) |
754 S_008014_TA2_BUSY(1) | S_008014_TA3_BUSY(1) |
755 S_008014_DB0_BUSY(1) | S_008014_DB1_BUSY(1) |
756 S_008014_DB2_BUSY(1) | S_008014_DB3_BUSY(1) |
757 S_008014_CB0_BUSY(1) | S_008014_CB1_BUSY(1) |
758 S_008014_CB2_BUSY(1) | S_008014_CB3_BUSY(1);
759 u32 srbm_reset = 0;
Jerome Glissea3c19452009-10-01 18:02:13 +0200760 u32 tmp;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000761
Jerome Glisse1a029b72009-10-06 19:04:30 +0200762 dev_info(rdev->dev, "GPU softreset \n");
763 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
764 RREG32(R_008010_GRBM_STATUS));
765 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
Jerome Glissea3c19452009-10-01 18:02:13 +0200766 RREG32(R_008014_GRBM_STATUS2));
Jerome Glisse1a029b72009-10-06 19:04:30 +0200767 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
768 RREG32(R_000E50_SRBM_STATUS));
Jerome Glissea3c19452009-10-01 18:02:13 +0200769 rv515_mc_stop(rdev, &save);
770 if (r600_mc_wait_for_idle(rdev)) {
771 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
772 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000773 /* Disable CP parsing/prefetching */
774 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(0xff));
775 /* Check if any of the rendering block is busy and reset it */
776 if ((RREG32(R_008010_GRBM_STATUS) & grbm_busy_mask) ||
777 (RREG32(R_008014_GRBM_STATUS2) & grbm2_busy_mask)) {
Jerome Glissea3c19452009-10-01 18:02:13 +0200778 tmp = S_008020_SOFT_RESET_CR(1) |
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000779 S_008020_SOFT_RESET_DB(1) |
780 S_008020_SOFT_RESET_CB(1) |
781 S_008020_SOFT_RESET_PA(1) |
782 S_008020_SOFT_RESET_SC(1) |
783 S_008020_SOFT_RESET_SMX(1) |
784 S_008020_SOFT_RESET_SPI(1) |
785 S_008020_SOFT_RESET_SX(1) |
786 S_008020_SOFT_RESET_SH(1) |
787 S_008020_SOFT_RESET_TC(1) |
788 S_008020_SOFT_RESET_TA(1) |
789 S_008020_SOFT_RESET_VC(1) |
Jerome Glissea3c19452009-10-01 18:02:13 +0200790 S_008020_SOFT_RESET_VGT(1);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200791 dev_info(rdev->dev, " R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
Jerome Glissea3c19452009-10-01 18:02:13 +0200792 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000793 (void)RREG32(R_008020_GRBM_SOFT_RESET);
794 udelay(50);
795 WREG32(R_008020_GRBM_SOFT_RESET, 0);
796 (void)RREG32(R_008020_GRBM_SOFT_RESET);
797 }
798 /* Reset CP (we always reset CP) */
Jerome Glissea3c19452009-10-01 18:02:13 +0200799 tmp = S_008020_SOFT_RESET_CP(1);
800 dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
801 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000802 (void)RREG32(R_008020_GRBM_SOFT_RESET);
803 udelay(50);
804 WREG32(R_008020_GRBM_SOFT_RESET, 0);
805 (void)RREG32(R_008020_GRBM_SOFT_RESET);
806 /* Reset others GPU block if necessary */
807 if (G_000E50_RLC_BUSY(RREG32(R_000E50_SRBM_STATUS)))
808 srbm_reset |= S_000E60_SOFT_RESET_RLC(1);
809 if (G_000E50_GRBM_RQ_PENDING(RREG32(R_000E50_SRBM_STATUS)))
810 srbm_reset |= S_000E60_SOFT_RESET_GRBM(1);
811 if (G_000E50_HI_RQ_PENDING(RREG32(R_000E50_SRBM_STATUS)))
812 srbm_reset |= S_000E60_SOFT_RESET_IH(1);
813 if (G_000E50_VMC_BUSY(RREG32(R_000E50_SRBM_STATUS)))
814 srbm_reset |= S_000E60_SOFT_RESET_VMC(1);
815 if (G_000E50_MCB_BUSY(RREG32(R_000E50_SRBM_STATUS)))
816 srbm_reset |= S_000E60_SOFT_RESET_MC(1);
817 if (G_000E50_MCDZ_BUSY(RREG32(R_000E50_SRBM_STATUS)))
818 srbm_reset |= S_000E60_SOFT_RESET_MC(1);
819 if (G_000E50_MCDY_BUSY(RREG32(R_000E50_SRBM_STATUS)))
820 srbm_reset |= S_000E60_SOFT_RESET_MC(1);
821 if (G_000E50_MCDX_BUSY(RREG32(R_000E50_SRBM_STATUS)))
822 srbm_reset |= S_000E60_SOFT_RESET_MC(1);
823 if (G_000E50_MCDW_BUSY(RREG32(R_000E50_SRBM_STATUS)))
824 srbm_reset |= S_000E60_SOFT_RESET_MC(1);
825 if (G_000E50_RLC_BUSY(RREG32(R_000E50_SRBM_STATUS)))
826 srbm_reset |= S_000E60_SOFT_RESET_RLC(1);
827 if (G_000E50_SEM_BUSY(RREG32(R_000E50_SRBM_STATUS)))
828 srbm_reset |= S_000E60_SOFT_RESET_SEM(1);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200829 if (G_000E50_BIF_BUSY(RREG32(R_000E50_SRBM_STATUS)))
830 srbm_reset |= S_000E60_SOFT_RESET_BIF(1);
831 dev_info(rdev->dev, " R_000E60_SRBM_SOFT_RESET=0x%08X\n", srbm_reset);
832 WREG32(R_000E60_SRBM_SOFT_RESET, srbm_reset);
833 (void)RREG32(R_000E60_SRBM_SOFT_RESET);
834 udelay(50);
835 WREG32(R_000E60_SRBM_SOFT_RESET, 0);
836 (void)RREG32(R_000E60_SRBM_SOFT_RESET);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000837 WREG32(R_000E60_SRBM_SOFT_RESET, srbm_reset);
838 (void)RREG32(R_000E60_SRBM_SOFT_RESET);
839 udelay(50);
840 WREG32(R_000E60_SRBM_SOFT_RESET, 0);
841 (void)RREG32(R_000E60_SRBM_SOFT_RESET);
842 /* Wait a little for things to settle down */
843 udelay(50);
Jerome Glisse1a029b72009-10-06 19:04:30 +0200844 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
845 RREG32(R_008010_GRBM_STATUS));
846 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
847 RREG32(R_008014_GRBM_STATUS2));
848 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
849 RREG32(R_000E50_SRBM_STATUS));
Jerome Glissea3c19452009-10-01 18:02:13 +0200850 /* After reset we need to reinit the asic as GPU often endup in an
851 * incoherent state.
852 */
853 atom_asic_init(rdev->mode_info.atom_context);
854 rv515_mc_resume(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000855 return 0;
856}
857
858int r600_gpu_reset(struct radeon_device *rdev)
859{
860 return r600_gpu_soft_reset(rdev);
861}
862
863static u32 r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes,
864 u32 num_backends,
865 u32 backend_disable_mask)
866{
867 u32 backend_map = 0;
868 u32 enabled_backends_mask;
869 u32 enabled_backends_count;
870 u32 cur_pipe;
871 u32 swizzle_pipe[R6XX_MAX_PIPES];
872 u32 cur_backend;
873 u32 i;
874
875 if (num_tile_pipes > R6XX_MAX_PIPES)
876 num_tile_pipes = R6XX_MAX_PIPES;
877 if (num_tile_pipes < 1)
878 num_tile_pipes = 1;
879 if (num_backends > R6XX_MAX_BACKENDS)
880 num_backends = R6XX_MAX_BACKENDS;
881 if (num_backends < 1)
882 num_backends = 1;
883
884 enabled_backends_mask = 0;
885 enabled_backends_count = 0;
886 for (i = 0; i < R6XX_MAX_BACKENDS; ++i) {
887 if (((backend_disable_mask >> i) & 1) == 0) {
888 enabled_backends_mask |= (1 << i);
889 ++enabled_backends_count;
890 }
891 if (enabled_backends_count == num_backends)
892 break;
893 }
894
895 if (enabled_backends_count == 0) {
896 enabled_backends_mask = 1;
897 enabled_backends_count = 1;
898 }
899
900 if (enabled_backends_count != num_backends)
901 num_backends = enabled_backends_count;
902
903 memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R6XX_MAX_PIPES);
904 switch (num_tile_pipes) {
905 case 1:
906 swizzle_pipe[0] = 0;
907 break;
908 case 2:
909 swizzle_pipe[0] = 0;
910 swizzle_pipe[1] = 1;
911 break;
912 case 3:
913 swizzle_pipe[0] = 0;
914 swizzle_pipe[1] = 1;
915 swizzle_pipe[2] = 2;
916 break;
917 case 4:
918 swizzle_pipe[0] = 0;
919 swizzle_pipe[1] = 1;
920 swizzle_pipe[2] = 2;
921 swizzle_pipe[3] = 3;
922 break;
923 case 5:
924 swizzle_pipe[0] = 0;
925 swizzle_pipe[1] = 1;
926 swizzle_pipe[2] = 2;
927 swizzle_pipe[3] = 3;
928 swizzle_pipe[4] = 4;
929 break;
930 case 6:
931 swizzle_pipe[0] = 0;
932 swizzle_pipe[1] = 2;
933 swizzle_pipe[2] = 4;
934 swizzle_pipe[3] = 5;
935 swizzle_pipe[4] = 1;
936 swizzle_pipe[5] = 3;
937 break;
938 case 7:
939 swizzle_pipe[0] = 0;
940 swizzle_pipe[1] = 2;
941 swizzle_pipe[2] = 4;
942 swizzle_pipe[3] = 6;
943 swizzle_pipe[4] = 1;
944 swizzle_pipe[5] = 3;
945 swizzle_pipe[6] = 5;
946 break;
947 case 8:
948 swizzle_pipe[0] = 0;
949 swizzle_pipe[1] = 2;
950 swizzle_pipe[2] = 4;
951 swizzle_pipe[3] = 6;
952 swizzle_pipe[4] = 1;
953 swizzle_pipe[5] = 3;
954 swizzle_pipe[6] = 5;
955 swizzle_pipe[7] = 7;
956 break;
957 }
958
959 cur_backend = 0;
960 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
961 while (((1 << cur_backend) & enabled_backends_mask) == 0)
962 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
963
964 backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
965
966 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
967 }
968
969 return backend_map;
970}
971
972int r600_count_pipe_bits(uint32_t val)
973{
974 int i, ret = 0;
975
976 for (i = 0; i < 32; i++) {
977 ret += val & 1;
978 val >>= 1;
979 }
980 return ret;
981}
982
983void r600_gpu_init(struct radeon_device *rdev)
984{
985 u32 tiling_config;
986 u32 ramcfg;
987 u32 tmp;
988 int i, j;
989 u32 sq_config;
990 u32 sq_gpr_resource_mgmt_1 = 0;
991 u32 sq_gpr_resource_mgmt_2 = 0;
992 u32 sq_thread_resource_mgmt = 0;
993 u32 sq_stack_resource_mgmt_1 = 0;
994 u32 sq_stack_resource_mgmt_2 = 0;
995
996 /* FIXME: implement */
997 switch (rdev->family) {
998 case CHIP_R600:
999 rdev->config.r600.max_pipes = 4;
1000 rdev->config.r600.max_tile_pipes = 8;
1001 rdev->config.r600.max_simds = 4;
1002 rdev->config.r600.max_backends = 4;
1003 rdev->config.r600.max_gprs = 256;
1004 rdev->config.r600.max_threads = 192;
1005 rdev->config.r600.max_stack_entries = 256;
1006 rdev->config.r600.max_hw_contexts = 8;
1007 rdev->config.r600.max_gs_threads = 16;
1008 rdev->config.r600.sx_max_export_size = 128;
1009 rdev->config.r600.sx_max_export_pos_size = 16;
1010 rdev->config.r600.sx_max_export_smx_size = 128;
1011 rdev->config.r600.sq_num_cf_insts = 2;
1012 break;
1013 case CHIP_RV630:
1014 case CHIP_RV635:
1015 rdev->config.r600.max_pipes = 2;
1016 rdev->config.r600.max_tile_pipes = 2;
1017 rdev->config.r600.max_simds = 3;
1018 rdev->config.r600.max_backends = 1;
1019 rdev->config.r600.max_gprs = 128;
1020 rdev->config.r600.max_threads = 192;
1021 rdev->config.r600.max_stack_entries = 128;
1022 rdev->config.r600.max_hw_contexts = 8;
1023 rdev->config.r600.max_gs_threads = 4;
1024 rdev->config.r600.sx_max_export_size = 128;
1025 rdev->config.r600.sx_max_export_pos_size = 16;
1026 rdev->config.r600.sx_max_export_smx_size = 128;
1027 rdev->config.r600.sq_num_cf_insts = 2;
1028 break;
1029 case CHIP_RV610:
1030 case CHIP_RV620:
1031 case CHIP_RS780:
1032 case CHIP_RS880:
1033 rdev->config.r600.max_pipes = 1;
1034 rdev->config.r600.max_tile_pipes = 1;
1035 rdev->config.r600.max_simds = 2;
1036 rdev->config.r600.max_backends = 1;
1037 rdev->config.r600.max_gprs = 128;
1038 rdev->config.r600.max_threads = 192;
1039 rdev->config.r600.max_stack_entries = 128;
1040 rdev->config.r600.max_hw_contexts = 4;
1041 rdev->config.r600.max_gs_threads = 4;
1042 rdev->config.r600.sx_max_export_size = 128;
1043 rdev->config.r600.sx_max_export_pos_size = 16;
1044 rdev->config.r600.sx_max_export_smx_size = 128;
1045 rdev->config.r600.sq_num_cf_insts = 1;
1046 break;
1047 case CHIP_RV670:
1048 rdev->config.r600.max_pipes = 4;
1049 rdev->config.r600.max_tile_pipes = 4;
1050 rdev->config.r600.max_simds = 4;
1051 rdev->config.r600.max_backends = 4;
1052 rdev->config.r600.max_gprs = 192;
1053 rdev->config.r600.max_threads = 192;
1054 rdev->config.r600.max_stack_entries = 256;
1055 rdev->config.r600.max_hw_contexts = 8;
1056 rdev->config.r600.max_gs_threads = 16;
1057 rdev->config.r600.sx_max_export_size = 128;
1058 rdev->config.r600.sx_max_export_pos_size = 16;
1059 rdev->config.r600.sx_max_export_smx_size = 128;
1060 rdev->config.r600.sq_num_cf_insts = 2;
1061 break;
1062 default:
1063 break;
1064 }
1065
1066 /* Initialize HDP */
1067 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1068 WREG32((0x2c14 + j), 0x00000000);
1069 WREG32((0x2c18 + j), 0x00000000);
1070 WREG32((0x2c1c + j), 0x00000000);
1071 WREG32((0x2c20 + j), 0x00000000);
1072 WREG32((0x2c24 + j), 0x00000000);
1073 }
1074
1075 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
1076
1077 /* Setup tiling */
1078 tiling_config = 0;
1079 ramcfg = RREG32(RAMCFG);
1080 switch (rdev->config.r600.max_tile_pipes) {
1081 case 1:
1082 tiling_config |= PIPE_TILING(0);
1083 break;
1084 case 2:
1085 tiling_config |= PIPE_TILING(1);
1086 break;
1087 case 4:
1088 tiling_config |= PIPE_TILING(2);
1089 break;
1090 case 8:
1091 tiling_config |= PIPE_TILING(3);
1092 break;
1093 default:
1094 break;
1095 }
1096 tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
1097 tiling_config |= GROUP_SIZE(0);
1098 tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
1099 if (tmp > 3) {
1100 tiling_config |= ROW_TILING(3);
1101 tiling_config |= SAMPLE_SPLIT(3);
1102 } else {
1103 tiling_config |= ROW_TILING(tmp);
1104 tiling_config |= SAMPLE_SPLIT(tmp);
1105 }
1106 tiling_config |= BANK_SWAPS(1);
1107 tmp = r600_get_tile_pipe_to_backend_map(rdev->config.r600.max_tile_pipes,
1108 rdev->config.r600.max_backends,
1109 (0xff << rdev->config.r600.max_backends) & 0xff);
1110 tiling_config |= BACKEND_MAP(tmp);
1111 WREG32(GB_TILING_CONFIG, tiling_config);
1112 WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
1113 WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
1114
1115 tmp = BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK << rdev->config.r600.max_backends) & R6XX_MAX_BACKENDS_MASK);
1116 WREG32(CC_RB_BACKEND_DISABLE, tmp);
1117
1118 /* Setup pipes */
1119 tmp = INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK << rdev->config.r600.max_pipes) & R6XX_MAX_PIPES_MASK);
1120 tmp |= INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK << rdev->config.r600.max_simds) & R6XX_MAX_SIMDS_MASK);
1121 WREG32(CC_GC_SHADER_PIPE_CONFIG, tmp);
1122 WREG32(GC_USER_SHADER_PIPE_CONFIG, tmp);
1123
1124 tmp = R6XX_MAX_BACKENDS - r600_count_pipe_bits(tmp & INACTIVE_QD_PIPES_MASK);
1125 WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
1126 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
1127
1128 /* Setup some CP states */
1129 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
1130 WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
1131
1132 WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
1133 SYNC_WALKER | SYNC_ALIGNER));
1134 /* Setup various GPU states */
1135 if (rdev->family == CHIP_RV670)
1136 WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
1137
1138 tmp = RREG32(SX_DEBUG_1);
1139 tmp |= SMX_EVENT_RELEASE;
1140 if ((rdev->family > CHIP_R600))
1141 tmp |= ENABLE_NEW_SMX_ADDRESS;
1142 WREG32(SX_DEBUG_1, tmp);
1143
1144 if (((rdev->family) == CHIP_R600) ||
1145 ((rdev->family) == CHIP_RV630) ||
1146 ((rdev->family) == CHIP_RV610) ||
1147 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001148 ((rdev->family) == CHIP_RS780) ||
1149 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001150 WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
1151 } else {
1152 WREG32(DB_DEBUG, 0);
1153 }
1154 WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
1155 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
1156
1157 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1158 WREG32(VGT_NUM_INSTANCES, 0);
1159
1160 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
1161 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
1162
1163 tmp = RREG32(SQ_MS_FIFO_SIZES);
1164 if (((rdev->family) == CHIP_RV610) ||
1165 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001166 ((rdev->family) == CHIP_RS780) ||
1167 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001168 tmp = (CACHE_FIFO_SIZE(0xa) |
1169 FETCH_FIFO_HIWATER(0xa) |
1170 DONE_FIFO_HIWATER(0xe0) |
1171 ALU_UPDATE_FIFO_HIWATER(0x8));
1172 } else if (((rdev->family) == CHIP_R600) ||
1173 ((rdev->family) == CHIP_RV630)) {
1174 tmp &= ~DONE_FIFO_HIWATER(0xff);
1175 tmp |= DONE_FIFO_HIWATER(0x4);
1176 }
1177 WREG32(SQ_MS_FIFO_SIZES, tmp);
1178
1179 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
1180 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
1181 */
1182 sq_config = RREG32(SQ_CONFIG);
1183 sq_config &= ~(PS_PRIO(3) |
1184 VS_PRIO(3) |
1185 GS_PRIO(3) |
1186 ES_PRIO(3));
1187 sq_config |= (DX9_CONSTS |
1188 VC_ENABLE |
1189 PS_PRIO(0) |
1190 VS_PRIO(1) |
1191 GS_PRIO(2) |
1192 ES_PRIO(3));
1193
1194 if ((rdev->family) == CHIP_R600) {
1195 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
1196 NUM_VS_GPRS(124) |
1197 NUM_CLAUSE_TEMP_GPRS(4));
1198 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
1199 NUM_ES_GPRS(0));
1200 sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
1201 NUM_VS_THREADS(48) |
1202 NUM_GS_THREADS(4) |
1203 NUM_ES_THREADS(4));
1204 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
1205 NUM_VS_STACK_ENTRIES(128));
1206 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
1207 NUM_ES_STACK_ENTRIES(0));
1208 } else if (((rdev->family) == CHIP_RV610) ||
1209 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001210 ((rdev->family) == CHIP_RS780) ||
1211 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001212 /* no vertex cache */
1213 sq_config &= ~VC_ENABLE;
1214
1215 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1216 NUM_VS_GPRS(44) |
1217 NUM_CLAUSE_TEMP_GPRS(2));
1218 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1219 NUM_ES_GPRS(17));
1220 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1221 NUM_VS_THREADS(78) |
1222 NUM_GS_THREADS(4) |
1223 NUM_ES_THREADS(31));
1224 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1225 NUM_VS_STACK_ENTRIES(40));
1226 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1227 NUM_ES_STACK_ENTRIES(16));
1228 } else if (((rdev->family) == CHIP_RV630) ||
1229 ((rdev->family) == CHIP_RV635)) {
1230 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1231 NUM_VS_GPRS(44) |
1232 NUM_CLAUSE_TEMP_GPRS(2));
1233 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
1234 NUM_ES_GPRS(18));
1235 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1236 NUM_VS_THREADS(78) |
1237 NUM_GS_THREADS(4) |
1238 NUM_ES_THREADS(31));
1239 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1240 NUM_VS_STACK_ENTRIES(40));
1241 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1242 NUM_ES_STACK_ENTRIES(16));
1243 } else if ((rdev->family) == CHIP_RV670) {
1244 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1245 NUM_VS_GPRS(44) |
1246 NUM_CLAUSE_TEMP_GPRS(2));
1247 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1248 NUM_ES_GPRS(17));
1249 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1250 NUM_VS_THREADS(78) |
1251 NUM_GS_THREADS(4) |
1252 NUM_ES_THREADS(31));
1253 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
1254 NUM_VS_STACK_ENTRIES(64));
1255 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
1256 NUM_ES_STACK_ENTRIES(64));
1257 }
1258
1259 WREG32(SQ_CONFIG, sq_config);
1260 WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
1261 WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
1262 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
1263 WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
1264 WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
1265
1266 if (((rdev->family) == CHIP_RV610) ||
1267 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05001268 ((rdev->family) == CHIP_RS780) ||
1269 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001270 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
1271 } else {
1272 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
1273 }
1274
1275 /* More default values. 2D/3D driver should adjust as needed */
1276 WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
1277 S1_X(0x4) | S1_Y(0xc)));
1278 WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
1279 S1_X(0x2) | S1_Y(0x2) |
1280 S2_X(0xa) | S2_Y(0x6) |
1281 S3_X(0x6) | S3_Y(0xa)));
1282 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
1283 S1_X(0x4) | S1_Y(0xc) |
1284 S2_X(0x1) | S2_Y(0x6) |
1285 S3_X(0xa) | S3_Y(0xe)));
1286 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
1287 S5_X(0x0) | S5_Y(0x0) |
1288 S6_X(0xb) | S6_Y(0x4) |
1289 S7_X(0x7) | S7_Y(0x8)));
1290
1291 WREG32(VGT_STRMOUT_EN, 0);
1292 tmp = rdev->config.r600.max_pipes * 16;
1293 switch (rdev->family) {
1294 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001295 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05001296 case CHIP_RS780:
1297 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001298 tmp += 32;
1299 break;
1300 case CHIP_RV670:
1301 tmp += 128;
1302 break;
1303 default:
1304 break;
1305 }
1306 if (tmp > 256) {
1307 tmp = 256;
1308 }
1309 WREG32(VGT_ES_PER_GS, 128);
1310 WREG32(VGT_GS_PER_ES, tmp);
1311 WREG32(VGT_GS_PER_VS, 2);
1312 WREG32(VGT_GS_VERTEX_REUSE, 16);
1313
1314 /* more default values. 2D/3D driver should adjust as needed */
1315 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
1316 WREG32(VGT_STRMOUT_EN, 0);
1317 WREG32(SX_MISC, 0);
1318 WREG32(PA_SC_MODE_CNTL, 0);
1319 WREG32(PA_SC_AA_CONFIG, 0);
1320 WREG32(PA_SC_LINE_STIPPLE, 0);
1321 WREG32(SPI_INPUT_Z, 0);
1322 WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
1323 WREG32(CB_COLOR7_FRAG, 0);
1324
1325 /* Clear render buffer base addresses */
1326 WREG32(CB_COLOR0_BASE, 0);
1327 WREG32(CB_COLOR1_BASE, 0);
1328 WREG32(CB_COLOR2_BASE, 0);
1329 WREG32(CB_COLOR3_BASE, 0);
1330 WREG32(CB_COLOR4_BASE, 0);
1331 WREG32(CB_COLOR5_BASE, 0);
1332 WREG32(CB_COLOR6_BASE, 0);
1333 WREG32(CB_COLOR7_BASE, 0);
1334 WREG32(CB_COLOR7_FRAG, 0);
1335
1336 switch (rdev->family) {
1337 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001338 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05001339 case CHIP_RS780:
1340 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001341 tmp = TC_L2_SIZE(8);
1342 break;
1343 case CHIP_RV630:
1344 case CHIP_RV635:
1345 tmp = TC_L2_SIZE(4);
1346 break;
1347 case CHIP_R600:
1348 tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
1349 break;
1350 default:
1351 tmp = TC_L2_SIZE(0);
1352 break;
1353 }
1354 WREG32(TC_CNTL, tmp);
1355
1356 tmp = RREG32(HDP_HOST_PATH_CNTL);
1357 WREG32(HDP_HOST_PATH_CNTL, tmp);
1358
1359 tmp = RREG32(ARB_POP);
1360 tmp |= ENABLE_TC128;
1361 WREG32(ARB_POP, tmp);
1362
1363 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1364 WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
1365 NUM_CLIP_SEQ(3)));
1366 WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
1367}
1368
1369
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001370/*
1371 * Indirect registers accessor
1372 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001373u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001374{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001375 u32 r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001376
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001377 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1378 (void)RREG32(PCIE_PORT_INDEX);
1379 r = RREG32(PCIE_PORT_DATA);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001380 return r;
1381}
1382
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001383void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001384{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001385 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1386 (void)RREG32(PCIE_PORT_INDEX);
1387 WREG32(PCIE_PORT_DATA, (v));
1388 (void)RREG32(PCIE_PORT_DATA);
1389}
1390
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001391/*
1392 * CP & Ring
1393 */
1394void r600_cp_stop(struct radeon_device *rdev)
1395{
1396 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
1397}
1398
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001399int r600_init_microcode(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001400{
1401 struct platform_device *pdev;
1402 const char *chip_name;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001403 const char *rlc_chip_name;
1404 size_t pfp_req_size, me_req_size, rlc_req_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001405 char fw_name[30];
1406 int err;
1407
1408 DRM_DEBUG("\n");
1409
1410 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
1411 err = IS_ERR(pdev);
1412 if (err) {
1413 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
1414 return -EINVAL;
1415 }
1416
1417 switch (rdev->family) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001418 case CHIP_R600:
1419 chip_name = "R600";
1420 rlc_chip_name = "R600";
1421 break;
1422 case CHIP_RV610:
1423 chip_name = "RV610";
1424 rlc_chip_name = "R600";
1425 break;
1426 case CHIP_RV630:
1427 chip_name = "RV630";
1428 rlc_chip_name = "R600";
1429 break;
1430 case CHIP_RV620:
1431 chip_name = "RV620";
1432 rlc_chip_name = "R600";
1433 break;
1434 case CHIP_RV635:
1435 chip_name = "RV635";
1436 rlc_chip_name = "R600";
1437 break;
1438 case CHIP_RV670:
1439 chip_name = "RV670";
1440 rlc_chip_name = "R600";
1441 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001442 case CHIP_RS780:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001443 case CHIP_RS880:
1444 chip_name = "RS780";
1445 rlc_chip_name = "R600";
1446 break;
1447 case CHIP_RV770:
1448 chip_name = "RV770";
1449 rlc_chip_name = "R700";
1450 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001451 case CHIP_RV730:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001452 case CHIP_RV740:
1453 chip_name = "RV730";
1454 rlc_chip_name = "R700";
1455 break;
1456 case CHIP_RV710:
1457 chip_name = "RV710";
1458 rlc_chip_name = "R700";
1459 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001460 default: BUG();
1461 }
1462
1463 if (rdev->family >= CHIP_RV770) {
1464 pfp_req_size = R700_PFP_UCODE_SIZE * 4;
1465 me_req_size = R700_PM4_UCODE_SIZE * 4;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001466 rlc_req_size = R700_RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001467 } else {
1468 pfp_req_size = PFP_UCODE_SIZE * 4;
1469 me_req_size = PM4_UCODE_SIZE * 12;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001470 rlc_req_size = RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001471 }
1472
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001473 DRM_INFO("Loading %s Microcode\n", chip_name);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001474
1475 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
1476 err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
1477 if (err)
1478 goto out;
1479 if (rdev->pfp_fw->size != pfp_req_size) {
1480 printk(KERN_ERR
1481 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
1482 rdev->pfp_fw->size, fw_name);
1483 err = -EINVAL;
1484 goto out;
1485 }
1486
1487 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
1488 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
1489 if (err)
1490 goto out;
1491 if (rdev->me_fw->size != me_req_size) {
1492 printk(KERN_ERR
1493 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
1494 rdev->me_fw->size, fw_name);
1495 err = -EINVAL;
1496 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001497
1498 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
1499 err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
1500 if (err)
1501 goto out;
1502 if (rdev->rlc_fw->size != rlc_req_size) {
1503 printk(KERN_ERR
1504 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
1505 rdev->rlc_fw->size, fw_name);
1506 err = -EINVAL;
1507 }
1508
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001509out:
1510 platform_device_unregister(pdev);
1511
1512 if (err) {
1513 if (err != -EINVAL)
1514 printk(KERN_ERR
1515 "r600_cp: Failed to load firmware \"%s\"\n",
1516 fw_name);
1517 release_firmware(rdev->pfp_fw);
1518 rdev->pfp_fw = NULL;
1519 release_firmware(rdev->me_fw);
1520 rdev->me_fw = NULL;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001521 release_firmware(rdev->rlc_fw);
1522 rdev->rlc_fw = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001523 }
1524 return err;
1525}
1526
1527static int r600_cp_load_microcode(struct radeon_device *rdev)
1528{
1529 const __be32 *fw_data;
1530 int i;
1531
1532 if (!rdev->me_fw || !rdev->pfp_fw)
1533 return -EINVAL;
1534
1535 r600_cp_stop(rdev);
1536
1537 WREG32(CP_RB_CNTL, RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
1538
1539 /* Reset cp */
1540 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
1541 RREG32(GRBM_SOFT_RESET);
1542 mdelay(15);
1543 WREG32(GRBM_SOFT_RESET, 0);
1544
1545 WREG32(CP_ME_RAM_WADDR, 0);
1546
1547 fw_data = (const __be32 *)rdev->me_fw->data;
1548 WREG32(CP_ME_RAM_WADDR, 0);
1549 for (i = 0; i < PM4_UCODE_SIZE * 3; i++)
1550 WREG32(CP_ME_RAM_DATA,
1551 be32_to_cpup(fw_data++));
1552
1553 fw_data = (const __be32 *)rdev->pfp_fw->data;
1554 WREG32(CP_PFP_UCODE_ADDR, 0);
1555 for (i = 0; i < PFP_UCODE_SIZE; i++)
1556 WREG32(CP_PFP_UCODE_DATA,
1557 be32_to_cpup(fw_data++));
1558
1559 WREG32(CP_PFP_UCODE_ADDR, 0);
1560 WREG32(CP_ME_RAM_WADDR, 0);
1561 WREG32(CP_ME_RAM_RADDR, 0);
1562 return 0;
1563}
1564
1565int r600_cp_start(struct radeon_device *rdev)
1566{
1567 int r;
1568 uint32_t cp_me;
1569
1570 r = radeon_ring_lock(rdev, 7);
1571 if (r) {
1572 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
1573 return r;
1574 }
1575 radeon_ring_write(rdev, PACKET3(PACKET3_ME_INITIALIZE, 5));
1576 radeon_ring_write(rdev, 0x1);
1577 if (rdev->family < CHIP_RV770) {
1578 radeon_ring_write(rdev, 0x3);
1579 radeon_ring_write(rdev, rdev->config.r600.max_hw_contexts - 1);
1580 } else {
1581 radeon_ring_write(rdev, 0x0);
1582 radeon_ring_write(rdev, rdev->config.rv770.max_hw_contexts - 1);
1583 }
1584 radeon_ring_write(rdev, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
1585 radeon_ring_write(rdev, 0);
1586 radeon_ring_write(rdev, 0);
1587 radeon_ring_unlock_commit(rdev);
1588
1589 cp_me = 0xff;
1590 WREG32(R_0086D8_CP_ME_CNTL, cp_me);
1591 return 0;
1592}
1593
1594int r600_cp_resume(struct radeon_device *rdev)
1595{
1596 u32 tmp;
1597 u32 rb_bufsz;
1598 int r;
1599
1600 /* Reset cp */
1601 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
1602 RREG32(GRBM_SOFT_RESET);
1603 mdelay(15);
1604 WREG32(GRBM_SOFT_RESET, 0);
1605
1606 /* Set ring buffer size */
1607 rb_bufsz = drm_order(rdev->cp.ring_size / 8);
Alex Deucherd6f28932009-11-02 16:01:27 -05001608 tmp = RB_NO_UPDATE | (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001609#ifdef __BIG_ENDIAN
Alex Deucherd6f28932009-11-02 16:01:27 -05001610 tmp |= BUF_SWAP_32BIT;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001611#endif
Alex Deucherd6f28932009-11-02 16:01:27 -05001612 WREG32(CP_RB_CNTL, tmp);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001613 WREG32(CP_SEM_WAIT_TIMER, 0x4);
1614
1615 /* Set the write pointer delay */
1616 WREG32(CP_RB_WPTR_DELAY, 0);
1617
1618 /* Initialize the ring buffer's read and write pointers */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001619 WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
1620 WREG32(CP_RB_RPTR_WR, 0);
1621 WREG32(CP_RB_WPTR, 0);
1622 WREG32(CP_RB_RPTR_ADDR, rdev->cp.gpu_addr & 0xFFFFFFFF);
1623 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->cp.gpu_addr));
1624 mdelay(1);
1625 WREG32(CP_RB_CNTL, tmp);
1626
1627 WREG32(CP_RB_BASE, rdev->cp.gpu_addr >> 8);
1628 WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
1629
1630 rdev->cp.rptr = RREG32(CP_RB_RPTR);
1631 rdev->cp.wptr = RREG32(CP_RB_WPTR);
1632
1633 r600_cp_start(rdev);
1634 rdev->cp.ready = true;
1635 r = radeon_ring_test(rdev);
1636 if (r) {
1637 rdev->cp.ready = false;
1638 return r;
1639 }
1640 return 0;
1641}
1642
1643void r600_cp_commit(struct radeon_device *rdev)
1644{
1645 WREG32(CP_RB_WPTR, rdev->cp.wptr);
1646 (void)RREG32(CP_RB_WPTR);
1647}
1648
1649void r600_ring_init(struct radeon_device *rdev, unsigned ring_size)
1650{
1651 u32 rb_bufsz;
1652
1653 /* Align ring size */
1654 rb_bufsz = drm_order(ring_size / 8);
1655 ring_size = (1 << (rb_bufsz + 1)) * 4;
1656 rdev->cp.ring_size = ring_size;
1657 rdev->cp.align_mask = 16 - 1;
1658}
1659
1660
1661/*
1662 * GPU scratch registers helpers function.
1663 */
1664void r600_scratch_init(struct radeon_device *rdev)
1665{
1666 int i;
1667
1668 rdev->scratch.num_reg = 7;
1669 for (i = 0; i < rdev->scratch.num_reg; i++) {
1670 rdev->scratch.free[i] = true;
1671 rdev->scratch.reg[i] = SCRATCH_REG0 + (i * 4);
1672 }
1673}
1674
1675int r600_ring_test(struct radeon_device *rdev)
1676{
1677 uint32_t scratch;
1678 uint32_t tmp = 0;
1679 unsigned i;
1680 int r;
1681
1682 r = radeon_scratch_get(rdev, &scratch);
1683 if (r) {
1684 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
1685 return r;
1686 }
1687 WREG32(scratch, 0xCAFEDEAD);
1688 r = radeon_ring_lock(rdev, 3);
1689 if (r) {
1690 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
1691 radeon_scratch_free(rdev, scratch);
1692 return r;
1693 }
1694 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
1695 radeon_ring_write(rdev, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
1696 radeon_ring_write(rdev, 0xDEADBEEF);
1697 radeon_ring_unlock_commit(rdev);
1698 for (i = 0; i < rdev->usec_timeout; i++) {
1699 tmp = RREG32(scratch);
1700 if (tmp == 0xDEADBEEF)
1701 break;
1702 DRM_UDELAY(1);
1703 }
1704 if (i < rdev->usec_timeout) {
1705 DRM_INFO("ring test succeeded in %d usecs\n", i);
1706 } else {
1707 DRM_ERROR("radeon: ring test failed (scratch(0x%04X)=0x%08X)\n",
1708 scratch, tmp);
1709 r = -EINVAL;
1710 }
1711 radeon_scratch_free(rdev, scratch);
1712 return r;
1713}
1714
Jerome Glisse81cc35b2009-10-01 18:02:12 +02001715void r600_wb_disable(struct radeon_device *rdev)
1716{
Jerome Glisse4c788672009-11-20 14:29:23 +01001717 int r;
1718
Jerome Glisse81cc35b2009-10-01 18:02:12 +02001719 WREG32(SCRATCH_UMSK, 0);
1720 if (rdev->wb.wb_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01001721 r = radeon_bo_reserve(rdev->wb.wb_obj, false);
1722 if (unlikely(r != 0))
1723 return;
1724 radeon_bo_kunmap(rdev->wb.wb_obj);
1725 radeon_bo_unpin(rdev->wb.wb_obj);
1726 radeon_bo_unreserve(rdev->wb.wb_obj);
Jerome Glisse81cc35b2009-10-01 18:02:12 +02001727 }
1728}
1729
1730void r600_wb_fini(struct radeon_device *rdev)
1731{
1732 r600_wb_disable(rdev);
1733 if (rdev->wb.wb_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01001734 radeon_bo_unref(&rdev->wb.wb_obj);
Jerome Glisse81cc35b2009-10-01 18:02:12 +02001735 rdev->wb.wb = NULL;
1736 rdev->wb.wb_obj = NULL;
1737 }
1738}
1739
1740int r600_wb_enable(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001741{
1742 int r;
1743
1744 if (rdev->wb.wb_obj == NULL) {
Jerome Glisse4c788672009-11-20 14:29:23 +01001745 r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, true,
1746 RADEON_GEM_DOMAIN_GTT, &rdev->wb.wb_obj);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001747 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01001748 dev_warn(rdev->dev, "(%d) create WB bo failed\n", r);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001749 return r;
1750 }
Jerome Glisse4c788672009-11-20 14:29:23 +01001751 r = radeon_bo_reserve(rdev->wb.wb_obj, false);
1752 if (unlikely(r != 0)) {
Jerome Glisse81cc35b2009-10-01 18:02:12 +02001753 r600_wb_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001754 return r;
1755 }
Jerome Glisse4c788672009-11-20 14:29:23 +01001756 r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT,
1757 &rdev->wb.gpu_addr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001758 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01001759 radeon_bo_unreserve(rdev->wb.wb_obj);
1760 dev_warn(rdev->dev, "(%d) pin WB bo failed\n", r);
1761 r600_wb_fini(rdev);
1762 return r;
1763 }
1764 r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb);
1765 radeon_bo_unreserve(rdev->wb.wb_obj);
1766 if (r) {
1767 dev_warn(rdev->dev, "(%d) map WB bo failed\n", r);
Jerome Glisse81cc35b2009-10-01 18:02:12 +02001768 r600_wb_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001769 return r;
1770 }
1771 }
1772 WREG32(SCRATCH_ADDR, (rdev->wb.gpu_addr >> 8) & 0xFFFFFFFF);
1773 WREG32(CP_RB_RPTR_ADDR, (rdev->wb.gpu_addr + 1024) & 0xFFFFFFFC);
1774 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + 1024) & 0xFF);
1775 WREG32(SCRATCH_UMSK, 0xff);
1776 return 0;
1777}
1778
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001779void r600_fence_ring_emit(struct radeon_device *rdev,
1780 struct radeon_fence *fence)
1781{
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001782 /* Also consider EVENT_WRITE_EOP. it handles the interrupts + timestamps + events */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001783 /* Emit fence sequence & fire IRQ */
1784 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
1785 radeon_ring_write(rdev, ((rdev->fence_drv.scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
1786 radeon_ring_write(rdev, fence->seq);
Jerome Glissecafe6602010-01-07 12:39:21 +01001787 radeon_ring_write(rdev, PACKET0(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0));
1788 radeon_ring_write(rdev, 1);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001789 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
1790 radeon_ring_write(rdev, PACKET0(CP_INT_STATUS, 0));
1791 radeon_ring_write(rdev, RB_INT_STAT);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001792}
1793
1794int r600_copy_dma(struct radeon_device *rdev,
1795 uint64_t src_offset,
1796 uint64_t dst_offset,
1797 unsigned num_pages,
1798 struct radeon_fence *fence)
1799{
1800 /* FIXME: implement */
1801 return 0;
1802}
1803
1804int r600_copy_blit(struct radeon_device *rdev,
1805 uint64_t src_offset, uint64_t dst_offset,
1806 unsigned num_pages, struct radeon_fence *fence)
1807{
Matt Turnera77f1712009-10-14 00:34:41 -04001808 r600_blit_prepare_copy(rdev, num_pages * RADEON_GPU_PAGE_SIZE);
1809 r600_kms_blit_copy(rdev, src_offset, dst_offset, num_pages * RADEON_GPU_PAGE_SIZE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001810 r600_blit_done_copy(rdev, fence);
1811 return 0;
1812}
1813
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001814int r600_set_surface_reg(struct radeon_device *rdev, int reg,
1815 uint32_t tiling_flags, uint32_t pitch,
1816 uint32_t offset, uint32_t obj_size)
1817{
1818 /* FIXME: implement */
1819 return 0;
1820}
1821
1822void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
1823{
1824 /* FIXME: implement */
1825}
1826
1827
1828bool r600_card_posted(struct radeon_device *rdev)
1829{
1830 uint32_t reg;
1831
1832 /* first check CRTCs */
1833 reg = RREG32(D1CRTC_CONTROL) |
1834 RREG32(D2CRTC_CONTROL);
1835 if (reg & CRTC_EN)
1836 return true;
1837
1838 /* then check MEM_SIZE, in case the crtcs are off */
1839 if (RREG32(CONFIG_MEMSIZE))
1840 return true;
1841
1842 return false;
1843}
1844
Dave Airliefc30b8e2009-09-18 15:19:37 +10001845int r600_startup(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001846{
1847 int r;
1848
Alex Deucher779720a2009-12-09 19:31:44 -05001849 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
1850 r = r600_init_microcode(rdev);
1851 if (r) {
1852 DRM_ERROR("Failed to load firmware!\n");
1853 return r;
1854 }
1855 }
1856
Jerome Glissea3c19452009-10-01 18:02:13 +02001857 r600_mc_program(rdev);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001858 if (rdev->flags & RADEON_IS_AGP) {
1859 r600_agp_enable(rdev);
1860 } else {
1861 r = r600_pcie_gart_enable(rdev);
1862 if (r)
1863 return r;
1864 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001865 r600_gpu_init(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +10001866
Alex Deucher7923c612009-12-15 17:15:07 -05001867 if (!rdev->r600_blit.shader_obj) {
1868 r = r600_blit_init(rdev);
1869 if (r) {
1870 DRM_ERROR("radeon: failed blitter (%d).\n", r);
1871 return r;
1872 }
1873 }
1874
Jerome Glisse4c788672009-11-20 14:29:23 +01001875 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
1876 if (unlikely(r != 0))
1877 return r;
1878 r = radeon_bo_pin(rdev->r600_blit.shader_obj, RADEON_GEM_DOMAIN_VRAM,
1879 &rdev->r600_blit.shader_gpu_addr);
1880 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
Dave Airliebc1a6312009-09-15 11:07:52 +10001881 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01001882 dev_err(rdev->dev, "(%d) pin blit object failed\n", r);
Dave Airliebc1a6312009-09-15 11:07:52 +10001883 return r;
1884 }
1885
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001886 /* Enable IRQ */
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001887 r = r600_irq_init(rdev);
1888 if (r) {
1889 DRM_ERROR("radeon: IH init failed (%d).\n", r);
1890 radeon_irq_kms_fini(rdev);
1891 return r;
1892 }
1893 r600_irq_set(rdev);
1894
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001895 r = radeon_ring_init(rdev, rdev->cp.ring_size);
1896 if (r)
1897 return r;
1898 r = r600_cp_load_microcode(rdev);
1899 if (r)
1900 return r;
1901 r = r600_cp_resume(rdev);
1902 if (r)
1903 return r;
Jerome Glisse81cc35b2009-10-01 18:02:12 +02001904 /* write back buffer are not vital so don't worry about failure */
1905 r600_wb_enable(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001906 return 0;
1907}
1908
Dave Airlie28d52042009-09-21 14:33:58 +10001909void r600_vga_set_state(struct radeon_device *rdev, bool state)
1910{
1911 uint32_t temp;
1912
1913 temp = RREG32(CONFIG_CNTL);
1914 if (state == false) {
1915 temp &= ~(1<<0);
1916 temp |= (1<<1);
1917 } else {
1918 temp &= ~(1<<1);
1919 }
1920 WREG32(CONFIG_CNTL, temp);
1921}
1922
Dave Airliefc30b8e2009-09-18 15:19:37 +10001923int r600_resume(struct radeon_device *rdev)
1924{
1925 int r;
1926
Jerome Glisse1a029b72009-10-06 19:04:30 +02001927 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
1928 * posting will perform necessary task to bring back GPU into good
1929 * shape.
1930 */
Dave Airliefc30b8e2009-09-18 15:19:37 +10001931 /* post card */
Jerome Glissee7d40b92009-10-01 18:02:15 +02001932 atom_asic_init(rdev->mode_info.atom_context);
Dave Airliefc30b8e2009-09-18 15:19:37 +10001933 /* Initialize clocks */
1934 r = radeon_clocks_init(rdev);
1935 if (r) {
1936 return r;
1937 }
1938
1939 r = r600_startup(rdev);
1940 if (r) {
1941 DRM_ERROR("r600 startup failed on resume\n");
1942 return r;
1943 }
1944
Jerome Glisse62a8ea32009-10-01 18:02:11 +02001945 r = r600_ib_test(rdev);
Dave Airliefc30b8e2009-09-18 15:19:37 +10001946 if (r) {
1947 DRM_ERROR("radeon: failled testing IB (%d).\n", r);
1948 return r;
1949 }
1950 return r;
1951}
1952
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001953int r600_suspend(struct radeon_device *rdev)
1954{
Jerome Glisse4c788672009-11-20 14:29:23 +01001955 int r;
1956
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001957 /* FIXME: we should wait for ring to be empty */
1958 r600_cp_stop(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +10001959 rdev->cp.ready = false;
Jerome Glisse81cc35b2009-10-01 18:02:12 +02001960 r600_wb_disable(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001961 r600_pcie_gart_disable(rdev);
Dave Airliebc1a6312009-09-15 11:07:52 +10001962 /* unpin shaders bo */
Jerome Glisse4c788672009-11-20 14:29:23 +01001963 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
1964 if (unlikely(r != 0))
1965 return r;
1966 radeon_bo_unpin(rdev->r600_blit.shader_obj);
1967 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001968 return 0;
1969}
1970
1971/* Plan is to move initialization in that function and use
1972 * helper function so that radeon_device_init pretty much
1973 * do nothing more than calling asic specific function. This
1974 * should also allow to remove a bunch of callback function
1975 * like vram_info.
1976 */
1977int r600_init(struct radeon_device *rdev)
1978{
1979 int r;
1980
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001981 r = radeon_dummy_page_init(rdev);
1982 if (r)
1983 return r;
1984 if (r600_debugfs_mc_info_init(rdev)) {
1985 DRM_ERROR("Failed to register debugfs file for mc !\n");
1986 }
1987 /* This don't do much */
1988 r = radeon_gem_init(rdev);
1989 if (r)
1990 return r;
1991 /* Read BIOS */
1992 if (!radeon_get_bios(rdev)) {
1993 if (ASIC_IS_AVIVO(rdev))
1994 return -EINVAL;
1995 }
1996 /* Must be an ATOMBIOS */
Jerome Glissee7d40b92009-10-01 18:02:15 +02001997 if (!rdev->is_atom_bios) {
1998 dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001999 return -EINVAL;
Jerome Glissee7d40b92009-10-01 18:02:15 +02002000 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002001 r = radeon_atombios_init(rdev);
2002 if (r)
2003 return r;
2004 /* Post card if necessary */
Dave Airlie72542d72009-12-01 14:06:31 +10002005 if (!r600_card_posted(rdev)) {
2006 if (!rdev->bios) {
2007 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
2008 return -EINVAL;
2009 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002010 DRM_INFO("GPU not posted. posting now...\n");
2011 atom_asic_init(rdev->mode_info.atom_context);
2012 }
2013 /* Initialize scratch registers */
2014 r600_scratch_init(rdev);
2015 /* Initialize surface registers */
2016 radeon_surface_init(rdev);
Rafał Miłecki74338742009-11-03 00:53:02 +01002017 /* Initialize clocks */
Michel Dänzer5e6dde72009-09-17 09:42:28 +02002018 radeon_get_clock_info(rdev->ddev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002019 r = radeon_clocks_init(rdev);
2020 if (r)
2021 return r;
Rafał Miłecki74338742009-11-03 00:53:02 +01002022 /* Initialize power management */
2023 radeon_pm_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002024 /* Fence driver */
2025 r = radeon_fence_driver_init(rdev);
2026 if (r)
2027 return r;
2028 r = r600_mc_init(rdev);
Jerome Glisseb574f252009-10-06 19:04:29 +02002029 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002030 return r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002031 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01002032 r = radeon_bo_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002033 if (r)
2034 return r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002035
2036 r = radeon_irq_kms_init(rdev);
2037 if (r)
2038 return r;
2039
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002040 rdev->cp.ring_obj = NULL;
2041 r600_ring_init(rdev, 1024 * 1024);
2042
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002043 rdev->ih.ring_obj = NULL;
2044 r600_ih_ring_init(rdev, 64 * 1024);
2045
Jerome Glisse4aac0472009-09-14 18:29:49 +02002046 r = r600_pcie_gart_init(rdev);
2047 if (r)
2048 return r;
2049
Alex Deucher779720a2009-12-09 19:31:44 -05002050 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10002051 r = r600_startup(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002052 if (r) {
Jerome Glisse75c81292009-10-01 18:02:14 +02002053 r600_suspend(rdev);
2054 r600_wb_fini(rdev);
Jerome Glisse75c81292009-10-01 18:02:14 +02002055 radeon_ring_fini(rdev);
2056 r600_pcie_gart_fini(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +02002057 rdev->accel_working = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002058 }
Jerome Glisse733289c2009-09-16 15:24:21 +02002059 if (rdev->accel_working) {
2060 r = radeon_ib_pool_init(rdev);
2061 if (r) {
Alex Deucher779720a2009-12-09 19:31:44 -05002062 DRM_ERROR("radeon: failed initializing IB pool (%d).\n", r);
Jerome Glisse733289c2009-09-16 15:24:21 +02002063 rdev->accel_working = false;
2064 }
Jerome Glisse62a8ea32009-10-01 18:02:11 +02002065 r = r600_ib_test(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +02002066 if (r) {
Alex Deucher779720a2009-12-09 19:31:44 -05002067 DRM_ERROR("radeon: failed testing IB (%d).\n", r);
Jerome Glisse733289c2009-09-16 15:24:21 +02002068 rdev->accel_working = false;
2069 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002070 }
Christian Koenigdafc3bd2009-10-11 23:49:13 +02002071
2072 r = r600_audio_init(rdev);
2073 if (r)
2074 return r; /* TODO error handling */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002075 return 0;
2076}
2077
2078void r600_fini(struct radeon_device *rdev)
2079{
2080 /* Suspend operations */
2081 r600_suspend(rdev);
2082
Christian Koenigdafc3bd2009-10-11 23:49:13 +02002083 r600_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002084 r600_blit_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002085 r600_irq_fini(rdev);
2086 radeon_irq_kms_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002087 radeon_ring_fini(rdev);
Jerome Glisse81cc35b2009-10-01 18:02:12 +02002088 r600_wb_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02002089 r600_pcie_gart_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002090 radeon_gem_fini(rdev);
2091 radeon_fence_driver_fini(rdev);
2092 radeon_clocks_fini(rdev);
Jerome Glissed0269ed2010-01-07 16:08:32 +01002093 radeon_agp_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01002094 radeon_bo_fini(rdev);
Jerome Glissee7d40b92009-10-01 18:02:15 +02002095 radeon_atombios_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002096 kfree(rdev->bios);
2097 rdev->bios = NULL;
2098 radeon_dummy_page_fini(rdev);
2099}
2100
2101
2102/*
2103 * CS stuff
2104 */
2105void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
2106{
2107 /* FIXME: implement */
2108 radeon_ring_write(rdev, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
2109 radeon_ring_write(rdev, ib->gpu_addr & 0xFFFFFFFC);
2110 radeon_ring_write(rdev, upper_32_bits(ib->gpu_addr) & 0xFF);
2111 radeon_ring_write(rdev, ib->length_dw);
2112}
2113
2114int r600_ib_test(struct radeon_device *rdev)
2115{
2116 struct radeon_ib *ib;
2117 uint32_t scratch;
2118 uint32_t tmp = 0;
2119 unsigned i;
2120 int r;
2121
2122 r = radeon_scratch_get(rdev, &scratch);
2123 if (r) {
2124 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
2125 return r;
2126 }
2127 WREG32(scratch, 0xCAFEDEAD);
2128 r = radeon_ib_get(rdev, &ib);
2129 if (r) {
2130 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
2131 return r;
2132 }
2133 ib->ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
2134 ib->ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2135 ib->ptr[2] = 0xDEADBEEF;
2136 ib->ptr[3] = PACKET2(0);
2137 ib->ptr[4] = PACKET2(0);
2138 ib->ptr[5] = PACKET2(0);
2139 ib->ptr[6] = PACKET2(0);
2140 ib->ptr[7] = PACKET2(0);
2141 ib->ptr[8] = PACKET2(0);
2142 ib->ptr[9] = PACKET2(0);
2143 ib->ptr[10] = PACKET2(0);
2144 ib->ptr[11] = PACKET2(0);
2145 ib->ptr[12] = PACKET2(0);
2146 ib->ptr[13] = PACKET2(0);
2147 ib->ptr[14] = PACKET2(0);
2148 ib->ptr[15] = PACKET2(0);
2149 ib->length_dw = 16;
2150 r = radeon_ib_schedule(rdev, ib);
2151 if (r) {
2152 radeon_scratch_free(rdev, scratch);
2153 radeon_ib_free(rdev, &ib);
2154 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
2155 return r;
2156 }
2157 r = radeon_fence_wait(ib->fence, false);
2158 if (r) {
2159 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
2160 return r;
2161 }
2162 for (i = 0; i < rdev->usec_timeout; i++) {
2163 tmp = RREG32(scratch);
2164 if (tmp == 0xDEADBEEF)
2165 break;
2166 DRM_UDELAY(1);
2167 }
2168 if (i < rdev->usec_timeout) {
2169 DRM_INFO("ib test succeeded in %u usecs\n", i);
2170 } else {
2171 DRM_ERROR("radeon: ib test failed (sracth(0x%04X)=0x%08X)\n",
2172 scratch, tmp);
2173 r = -EINVAL;
2174 }
2175 radeon_scratch_free(rdev, scratch);
2176 radeon_ib_free(rdev, &ib);
2177 return r;
2178}
2179
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002180/*
2181 * Interrupts
2182 *
2183 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
2184 * the same as the CP ring buffer, but in reverse. Rather than the CPU
2185 * writing to the ring and the GPU consuming, the GPU writes to the ring
2186 * and host consumes. As the host irq handler processes interrupts, it
2187 * increments the rptr. When the rptr catches up with the wptr, all the
2188 * current interrupts have been processed.
2189 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002190
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002191void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
2192{
2193 u32 rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002194
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002195 /* Align ring size */
2196 rb_bufsz = drm_order(ring_size / 4);
2197 ring_size = (1 << rb_bufsz) * 4;
2198 rdev->ih.ring_size = ring_size;
2199 rdev->ih.align_mask = 4 - 1;
2200}
2201
2202static int r600_ih_ring_alloc(struct radeon_device *rdev, unsigned ring_size)
2203{
2204 int r;
2205
2206 rdev->ih.ring_size = ring_size;
2207 /* Allocate ring buffer */
2208 if (rdev->ih.ring_obj == NULL) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002209 r = radeon_bo_create(rdev, NULL, rdev->ih.ring_size,
2210 true,
2211 RADEON_GEM_DOMAIN_GTT,
2212 &rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002213 if (r) {
2214 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
2215 return r;
2216 }
Jerome Glisse4c788672009-11-20 14:29:23 +01002217 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
2218 if (unlikely(r != 0))
2219 return r;
2220 r = radeon_bo_pin(rdev->ih.ring_obj,
2221 RADEON_GEM_DOMAIN_GTT,
2222 &rdev->ih.gpu_addr);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002223 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002224 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002225 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
2226 return r;
2227 }
Jerome Glisse4c788672009-11-20 14:29:23 +01002228 r = radeon_bo_kmap(rdev->ih.ring_obj,
2229 (void **)&rdev->ih.ring);
2230 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002231 if (r) {
2232 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
2233 return r;
2234 }
2235 }
2236 rdev->ih.ptr_mask = (rdev->cp.ring_size / 4) - 1;
2237 rdev->ih.rptr = 0;
2238
2239 return 0;
2240}
2241
2242static void r600_ih_ring_fini(struct radeon_device *rdev)
2243{
Jerome Glisse4c788672009-11-20 14:29:23 +01002244 int r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002245 if (rdev->ih.ring_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01002246 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
2247 if (likely(r == 0)) {
2248 radeon_bo_kunmap(rdev->ih.ring_obj);
2249 radeon_bo_unpin(rdev->ih.ring_obj);
2250 radeon_bo_unreserve(rdev->ih.ring_obj);
2251 }
2252 radeon_bo_unref(&rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002253 rdev->ih.ring = NULL;
2254 rdev->ih.ring_obj = NULL;
2255 }
2256}
2257
2258static void r600_rlc_stop(struct radeon_device *rdev)
2259{
2260
2261 if (rdev->family >= CHIP_RV770) {
2262 /* r7xx asics need to soft reset RLC before halting */
2263 WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
2264 RREG32(SRBM_SOFT_RESET);
2265 udelay(15000);
2266 WREG32(SRBM_SOFT_RESET, 0);
2267 RREG32(SRBM_SOFT_RESET);
2268 }
2269
2270 WREG32(RLC_CNTL, 0);
2271}
2272
2273static void r600_rlc_start(struct radeon_device *rdev)
2274{
2275 WREG32(RLC_CNTL, RLC_ENABLE);
2276}
2277
2278static int r600_rlc_init(struct radeon_device *rdev)
2279{
2280 u32 i;
2281 const __be32 *fw_data;
2282
2283 if (!rdev->rlc_fw)
2284 return -EINVAL;
2285
2286 r600_rlc_stop(rdev);
2287
2288 WREG32(RLC_HB_BASE, 0);
2289 WREG32(RLC_HB_CNTL, 0);
2290 WREG32(RLC_HB_RPTR, 0);
2291 WREG32(RLC_HB_WPTR, 0);
2292 WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
2293 WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
2294 WREG32(RLC_MC_CNTL, 0);
2295 WREG32(RLC_UCODE_CNTL, 0);
2296
2297 fw_data = (const __be32 *)rdev->rlc_fw->data;
2298 if (rdev->family >= CHIP_RV770) {
2299 for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
2300 WREG32(RLC_UCODE_ADDR, i);
2301 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2302 }
2303 } else {
2304 for (i = 0; i < RLC_UCODE_SIZE; i++) {
2305 WREG32(RLC_UCODE_ADDR, i);
2306 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2307 }
2308 }
2309 WREG32(RLC_UCODE_ADDR, 0);
2310
2311 r600_rlc_start(rdev);
2312
2313 return 0;
2314}
2315
2316static void r600_enable_interrupts(struct radeon_device *rdev)
2317{
2318 u32 ih_cntl = RREG32(IH_CNTL);
2319 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
2320
2321 ih_cntl |= ENABLE_INTR;
2322 ih_rb_cntl |= IH_RB_ENABLE;
2323 WREG32(IH_CNTL, ih_cntl);
2324 WREG32(IH_RB_CNTL, ih_rb_cntl);
2325 rdev->ih.enabled = true;
2326}
2327
2328static void r600_disable_interrupts(struct radeon_device *rdev)
2329{
2330 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
2331 u32 ih_cntl = RREG32(IH_CNTL);
2332
2333 ih_rb_cntl &= ~IH_RB_ENABLE;
2334 ih_cntl &= ~ENABLE_INTR;
2335 WREG32(IH_RB_CNTL, ih_rb_cntl);
2336 WREG32(IH_CNTL, ih_cntl);
2337 /* set rptr, wptr to 0 */
2338 WREG32(IH_RB_RPTR, 0);
2339 WREG32(IH_RB_WPTR, 0);
2340 rdev->ih.enabled = false;
2341 rdev->ih.wptr = 0;
2342 rdev->ih.rptr = 0;
2343}
2344
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002345static void r600_disable_interrupt_state(struct radeon_device *rdev)
2346{
2347 u32 tmp;
2348
2349 WREG32(CP_INT_CNTL, 0);
2350 WREG32(GRBM_INT_CNTL, 0);
2351 WREG32(DxMODE_INT_MASK, 0);
2352 if (ASIC_IS_DCE3(rdev)) {
2353 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
2354 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
2355 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2356 WREG32(DC_HPD1_INT_CONTROL, tmp);
2357 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2358 WREG32(DC_HPD2_INT_CONTROL, tmp);
2359 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2360 WREG32(DC_HPD3_INT_CONTROL, tmp);
2361 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2362 WREG32(DC_HPD4_INT_CONTROL, tmp);
2363 if (ASIC_IS_DCE32(rdev)) {
2364 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2365 WREG32(DC_HPD5_INT_CONTROL, 0);
2366 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2367 WREG32(DC_HPD6_INT_CONTROL, 0);
2368 }
2369 } else {
2370 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
2371 WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
2372 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
2373 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, 0);
2374 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
2375 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, 0);
2376 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
2377 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, 0);
2378 }
2379}
2380
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002381int r600_irq_init(struct radeon_device *rdev)
2382{
2383 int ret = 0;
2384 int rb_bufsz;
2385 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
2386
2387 /* allocate ring */
2388 ret = r600_ih_ring_alloc(rdev, rdev->ih.ring_size);
2389 if (ret)
2390 return ret;
2391
2392 /* disable irqs */
2393 r600_disable_interrupts(rdev);
2394
2395 /* init rlc */
2396 ret = r600_rlc_init(rdev);
2397 if (ret) {
2398 r600_ih_ring_fini(rdev);
2399 return ret;
2400 }
2401
2402 /* setup interrupt control */
2403 /* set dummy read address to ring address */
2404 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
2405 interrupt_cntl = RREG32(INTERRUPT_CNTL);
2406 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
2407 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
2408 */
2409 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
2410 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
2411 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
2412 WREG32(INTERRUPT_CNTL, interrupt_cntl);
2413
2414 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
2415 rb_bufsz = drm_order(rdev->ih.ring_size / 4);
2416
2417 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
2418 IH_WPTR_OVERFLOW_CLEAR |
2419 (rb_bufsz << 1));
2420 /* WPTR writeback, not yet */
2421 /*ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;*/
2422 WREG32(IH_RB_WPTR_ADDR_LO, 0);
2423 WREG32(IH_RB_WPTR_ADDR_HI, 0);
2424
2425 WREG32(IH_RB_CNTL, ih_rb_cntl);
2426
2427 /* set rptr, wptr to 0 */
2428 WREG32(IH_RB_RPTR, 0);
2429 WREG32(IH_RB_WPTR, 0);
2430
2431 /* Default settings for IH_CNTL (disabled at first) */
2432 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
2433 /* RPTR_REARM only works if msi's are enabled */
2434 if (rdev->msi_enabled)
2435 ih_cntl |= RPTR_REARM;
2436
2437#ifdef __BIG_ENDIAN
2438 ih_cntl |= IH_MC_SWAP(IH_MC_SWAP_32BIT);
2439#endif
2440 WREG32(IH_CNTL, ih_cntl);
2441
2442 /* force the active interrupt state to all disabled */
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002443 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002444
2445 /* enable irqs */
2446 r600_enable_interrupts(rdev);
2447
2448 return ret;
2449}
2450
2451void r600_irq_fini(struct radeon_device *rdev)
2452{
2453 r600_disable_interrupts(rdev);
2454 r600_rlc_stop(rdev);
2455 r600_ih_ring_fini(rdev);
2456}
2457
2458int r600_irq_set(struct radeon_device *rdev)
2459{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002460 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
2461 u32 mode_int = 0;
2462 u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002463
2464 /* don't enable anything if the ih is disabled */
2465 if (!rdev->ih.enabled)
2466 return 0;
2467
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002468 if (ASIC_IS_DCE3(rdev)) {
2469 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
2470 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
2471 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
2472 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
2473 if (ASIC_IS_DCE32(rdev)) {
2474 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
2475 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
2476 }
2477 } else {
2478 hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
2479 hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
2480 hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
2481 }
2482
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002483 if (rdev->irq.sw_int) {
2484 DRM_DEBUG("r600_irq_set: sw int\n");
2485 cp_int_cntl |= RB_INT_ENABLE;
2486 }
2487 if (rdev->irq.crtc_vblank_int[0]) {
2488 DRM_DEBUG("r600_irq_set: vblank 0\n");
2489 mode_int |= D1MODE_VBLANK_INT_MASK;
2490 }
2491 if (rdev->irq.crtc_vblank_int[1]) {
2492 DRM_DEBUG("r600_irq_set: vblank 1\n");
2493 mode_int |= D2MODE_VBLANK_INT_MASK;
2494 }
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002495 if (rdev->irq.hpd[0]) {
2496 DRM_DEBUG("r600_irq_set: hpd 1\n");
2497 hpd1 |= DC_HPDx_INT_EN;
2498 }
2499 if (rdev->irq.hpd[1]) {
2500 DRM_DEBUG("r600_irq_set: hpd 2\n");
2501 hpd2 |= DC_HPDx_INT_EN;
2502 }
2503 if (rdev->irq.hpd[2]) {
2504 DRM_DEBUG("r600_irq_set: hpd 3\n");
2505 hpd3 |= DC_HPDx_INT_EN;
2506 }
2507 if (rdev->irq.hpd[3]) {
2508 DRM_DEBUG("r600_irq_set: hpd 4\n");
2509 hpd4 |= DC_HPDx_INT_EN;
2510 }
2511 if (rdev->irq.hpd[4]) {
2512 DRM_DEBUG("r600_irq_set: hpd 5\n");
2513 hpd5 |= DC_HPDx_INT_EN;
2514 }
2515 if (rdev->irq.hpd[5]) {
2516 DRM_DEBUG("r600_irq_set: hpd 6\n");
2517 hpd6 |= DC_HPDx_INT_EN;
2518 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002519
2520 WREG32(CP_INT_CNTL, cp_int_cntl);
2521 WREG32(DxMODE_INT_MASK, mode_int);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002522 if (ASIC_IS_DCE3(rdev)) {
2523 WREG32(DC_HPD1_INT_CONTROL, hpd1);
2524 WREG32(DC_HPD2_INT_CONTROL, hpd2);
2525 WREG32(DC_HPD3_INT_CONTROL, hpd3);
2526 WREG32(DC_HPD4_INT_CONTROL, hpd4);
2527 if (ASIC_IS_DCE32(rdev)) {
2528 WREG32(DC_HPD5_INT_CONTROL, hpd5);
2529 WREG32(DC_HPD6_INT_CONTROL, hpd6);
2530 }
2531 } else {
2532 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
2533 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
2534 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
2535 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002536
2537 return 0;
2538}
2539
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002540static inline void r600_irq_ack(struct radeon_device *rdev,
2541 u32 *disp_int,
2542 u32 *disp_int_cont,
2543 u32 *disp_int_cont2)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002544{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002545 u32 tmp;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002546
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002547 if (ASIC_IS_DCE3(rdev)) {
2548 *disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
2549 *disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
2550 *disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
2551 } else {
2552 *disp_int = RREG32(DISP_INTERRUPT_STATUS);
2553 *disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
2554 *disp_int_cont2 = 0;
2555 }
2556
2557 if (*disp_int & LB_D1_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002558 WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002559 if (*disp_int & LB_D1_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002560 WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002561 if (*disp_int & LB_D2_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002562 WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002563 if (*disp_int & LB_D2_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002564 WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002565 if (*disp_int & DC_HPD1_INTERRUPT) {
2566 if (ASIC_IS_DCE3(rdev)) {
2567 tmp = RREG32(DC_HPD1_INT_CONTROL);
2568 tmp |= DC_HPDx_INT_ACK;
2569 WREG32(DC_HPD1_INT_CONTROL, tmp);
2570 } else {
2571 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
2572 tmp |= DC_HPDx_INT_ACK;
2573 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
2574 }
2575 }
2576 if (*disp_int & DC_HPD2_INTERRUPT) {
2577 if (ASIC_IS_DCE3(rdev)) {
2578 tmp = RREG32(DC_HPD2_INT_CONTROL);
2579 tmp |= DC_HPDx_INT_ACK;
2580 WREG32(DC_HPD2_INT_CONTROL, tmp);
2581 } else {
2582 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
2583 tmp |= DC_HPDx_INT_ACK;
2584 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
2585 }
2586 }
2587 if (*disp_int_cont & DC_HPD3_INTERRUPT) {
2588 if (ASIC_IS_DCE3(rdev)) {
2589 tmp = RREG32(DC_HPD3_INT_CONTROL);
2590 tmp |= DC_HPDx_INT_ACK;
2591 WREG32(DC_HPD3_INT_CONTROL, tmp);
2592 } else {
2593 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
2594 tmp |= DC_HPDx_INT_ACK;
2595 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
2596 }
2597 }
2598 if (*disp_int_cont & DC_HPD4_INTERRUPT) {
2599 tmp = RREG32(DC_HPD4_INT_CONTROL);
2600 tmp |= DC_HPDx_INT_ACK;
2601 WREG32(DC_HPD4_INT_CONTROL, tmp);
2602 }
2603 if (ASIC_IS_DCE32(rdev)) {
2604 if (*disp_int_cont2 & DC_HPD5_INTERRUPT) {
2605 tmp = RREG32(DC_HPD5_INT_CONTROL);
2606 tmp |= DC_HPDx_INT_ACK;
2607 WREG32(DC_HPD5_INT_CONTROL, tmp);
2608 }
2609 if (*disp_int_cont2 & DC_HPD6_INTERRUPT) {
2610 tmp = RREG32(DC_HPD5_INT_CONTROL);
2611 tmp |= DC_HPDx_INT_ACK;
2612 WREG32(DC_HPD6_INT_CONTROL, tmp);
2613 }
2614 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002615}
2616
2617void r600_irq_disable(struct radeon_device *rdev)
2618{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002619 u32 disp_int, disp_int_cont, disp_int_cont2;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002620
2621 r600_disable_interrupts(rdev);
2622 /* Wait and acknowledge irq */
2623 mdelay(1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002624 r600_irq_ack(rdev, &disp_int, &disp_int_cont, &disp_int_cont2);
2625 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002626}
2627
2628static inline u32 r600_get_ih_wptr(struct radeon_device *rdev)
2629{
2630 u32 wptr, tmp;
2631
2632 /* XXX use writeback */
2633 wptr = RREG32(IH_RB_WPTR);
2634
2635 if (wptr & RB_OVERFLOW) {
2636 WARN_ON(1);
2637 /* XXX deal with overflow */
2638 DRM_ERROR("IH RB overflow\n");
2639 tmp = RREG32(IH_RB_CNTL);
2640 tmp |= IH_WPTR_OVERFLOW_CLEAR;
2641 WREG32(IH_RB_CNTL, tmp);
2642 }
2643 wptr = wptr & WPTR_OFFSET_MASK;
2644
2645 return wptr;
2646}
2647
2648/* r600 IV Ring
2649 * Each IV ring entry is 128 bits:
2650 * [7:0] - interrupt source id
2651 * [31:8] - reserved
2652 * [59:32] - interrupt source data
2653 * [127:60] - reserved
2654 *
2655 * The basic interrupt vector entries
2656 * are decoded as follows:
2657 * src_id src_data description
2658 * 1 0 D1 Vblank
2659 * 1 1 D1 Vline
2660 * 5 0 D2 Vblank
2661 * 5 1 D2 Vline
2662 * 19 0 FP Hot plug detection A
2663 * 19 1 FP Hot plug detection B
2664 * 19 2 DAC A auto-detection
2665 * 19 3 DAC B auto-detection
2666 * 176 - CP_INT RB
2667 * 177 - CP_INT IB1
2668 * 178 - CP_INT IB2
2669 * 181 - EOP Interrupt
2670 * 233 - GUI Idle
2671 *
2672 * Note, these are based on r600 and may need to be
2673 * adjusted or added to on newer asics
2674 */
2675
2676int r600_irq_process(struct radeon_device *rdev)
2677{
2678 u32 wptr = r600_get_ih_wptr(rdev);
2679 u32 rptr = rdev->ih.rptr;
2680 u32 src_id, src_data;
2681 u32 last_entry = rdev->ih.ring_size - 16;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002682 u32 ring_index, disp_int, disp_int_cont, disp_int_cont2;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002683 unsigned long flags;
Alex Deucherd4877cf2009-12-04 16:56:37 -05002684 bool queue_hotplug = false;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002685
2686 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
2687
2688 spin_lock_irqsave(&rdev->ih.lock, flags);
2689
2690 if (rptr == wptr) {
2691 spin_unlock_irqrestore(&rdev->ih.lock, flags);
2692 return IRQ_NONE;
2693 }
2694 if (rdev->shutdown) {
2695 spin_unlock_irqrestore(&rdev->ih.lock, flags);
2696 return IRQ_NONE;
2697 }
2698
2699restart_ih:
2700 /* display interrupts */
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002701 r600_irq_ack(rdev, &disp_int, &disp_int_cont, &disp_int_cont2);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002702
2703 rdev->ih.wptr = wptr;
2704 while (rptr != wptr) {
2705 /* wptr/rptr are in bytes! */
2706 ring_index = rptr / 4;
2707 src_id = rdev->ih.ring[ring_index] & 0xff;
2708 src_data = rdev->ih.ring[ring_index + 1] & 0xfffffff;
2709
2710 switch (src_id) {
2711 case 1: /* D1 vblank/vline */
2712 switch (src_data) {
2713 case 0: /* D1 vblank */
2714 if (disp_int & LB_D1_VBLANK_INTERRUPT) {
2715 drm_handle_vblank(rdev->ddev, 0);
2716 disp_int &= ~LB_D1_VBLANK_INTERRUPT;
2717 DRM_DEBUG("IH: D1 vblank\n");
2718 }
2719 break;
2720 case 1: /* D1 vline */
2721 if (disp_int & LB_D1_VLINE_INTERRUPT) {
2722 disp_int &= ~LB_D1_VLINE_INTERRUPT;
2723 DRM_DEBUG("IH: D1 vline\n");
2724 }
2725 break;
2726 default:
2727 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
2728 break;
2729 }
2730 break;
2731 case 5: /* D2 vblank/vline */
2732 switch (src_data) {
2733 case 0: /* D2 vblank */
2734 if (disp_int & LB_D2_VBLANK_INTERRUPT) {
2735 drm_handle_vblank(rdev->ddev, 1);
2736 disp_int &= ~LB_D2_VBLANK_INTERRUPT;
2737 DRM_DEBUG("IH: D2 vblank\n");
2738 }
2739 break;
2740 case 1: /* D1 vline */
2741 if (disp_int & LB_D2_VLINE_INTERRUPT) {
2742 disp_int &= ~LB_D2_VLINE_INTERRUPT;
2743 DRM_DEBUG("IH: D2 vline\n");
2744 }
2745 break;
2746 default:
2747 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
2748 break;
2749 }
2750 break;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002751 case 19: /* HPD/DAC hotplug */
2752 switch (src_data) {
2753 case 0:
2754 if (disp_int & DC_HPD1_INTERRUPT) {
2755 disp_int &= ~DC_HPD1_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05002756 queue_hotplug = true;
2757 DRM_DEBUG("IH: HPD1\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002758 }
2759 break;
2760 case 1:
2761 if (disp_int & DC_HPD2_INTERRUPT) {
2762 disp_int &= ~DC_HPD2_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05002763 queue_hotplug = true;
2764 DRM_DEBUG("IH: HPD2\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002765 }
2766 break;
2767 case 4:
2768 if (disp_int_cont & DC_HPD3_INTERRUPT) {
2769 disp_int_cont &= ~DC_HPD3_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05002770 queue_hotplug = true;
2771 DRM_DEBUG("IH: HPD3\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002772 }
2773 break;
2774 case 5:
2775 if (disp_int_cont & DC_HPD4_INTERRUPT) {
2776 disp_int_cont &= ~DC_HPD4_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05002777 queue_hotplug = true;
2778 DRM_DEBUG("IH: HPD4\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002779 }
2780 break;
2781 case 10:
2782 if (disp_int_cont2 & DC_HPD5_INTERRUPT) {
2783 disp_int_cont &= ~DC_HPD5_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05002784 queue_hotplug = true;
2785 DRM_DEBUG("IH: HPD5\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002786 }
2787 break;
2788 case 12:
2789 if (disp_int_cont2 & DC_HPD6_INTERRUPT) {
2790 disp_int_cont &= ~DC_HPD6_INTERRUPT;
Alex Deucherd4877cf2009-12-04 16:56:37 -05002791 queue_hotplug = true;
2792 DRM_DEBUG("IH: HPD6\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05002793 }
2794 break;
2795 default:
2796 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
2797 break;
2798 }
2799 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002800 case 176: /* CP_INT in ring buffer */
2801 case 177: /* CP_INT in IB1 */
2802 case 178: /* CP_INT in IB2 */
2803 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
2804 radeon_fence_process(rdev);
2805 break;
2806 case 181: /* CP EOP event */
2807 DRM_DEBUG("IH: CP EOP\n");
2808 break;
2809 default:
2810 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
2811 break;
2812 }
2813
2814 /* wptr/rptr are in bytes! */
2815 if (rptr == last_entry)
2816 rptr = 0;
2817 else
2818 rptr += 16;
2819 }
2820 /* make sure wptr hasn't changed while processing */
2821 wptr = r600_get_ih_wptr(rdev);
2822 if (wptr != rdev->ih.wptr)
2823 goto restart_ih;
Alex Deucherd4877cf2009-12-04 16:56:37 -05002824 if (queue_hotplug)
2825 queue_work(rdev->wq, &rdev->hotplug_work);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002826 rdev->ih.rptr = rptr;
2827 WREG32(IH_RB_RPTR, rdev->ih.rptr);
2828 spin_unlock_irqrestore(&rdev->ih.lock, flags);
2829 return IRQ_HANDLED;
2830}
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002831
2832/*
2833 * Debugfs info
2834 */
2835#if defined(CONFIG_DEBUG_FS)
2836
2837static int r600_debugfs_cp_ring_info(struct seq_file *m, void *data)
2838{
2839 struct drm_info_node *node = (struct drm_info_node *) m->private;
2840 struct drm_device *dev = node->minor->dev;
2841 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002842 unsigned count, i, j;
2843
2844 radeon_ring_free_size(rdev);
Rafał Miłeckid6840762009-11-10 22:26:21 +01002845 count = (rdev->cp.ring_size / 4) - rdev->cp.ring_free_dw;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002846 seq_printf(m, "CP_STAT 0x%08x\n", RREG32(CP_STAT));
Rafał Miłeckid6840762009-11-10 22:26:21 +01002847 seq_printf(m, "CP_RB_WPTR 0x%08x\n", RREG32(CP_RB_WPTR));
2848 seq_printf(m, "CP_RB_RPTR 0x%08x\n", RREG32(CP_RB_RPTR));
2849 seq_printf(m, "driver's copy of the CP_RB_WPTR 0x%08x\n", rdev->cp.wptr);
2850 seq_printf(m, "driver's copy of the CP_RB_RPTR 0x%08x\n", rdev->cp.rptr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002851 seq_printf(m, "%u free dwords in ring\n", rdev->cp.ring_free_dw);
2852 seq_printf(m, "%u dwords in ring\n", count);
Rafał Miłeckid6840762009-11-10 22:26:21 +01002853 i = rdev->cp.rptr;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002854 for (j = 0; j <= count; j++) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002855 seq_printf(m, "r[%04d]=0x%08x\n", i, rdev->cp.ring[i]);
Rafał Miłeckid6840762009-11-10 22:26:21 +01002856 i = (i + 1) & rdev->cp.ptr_mask;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002857 }
2858 return 0;
2859}
2860
2861static int r600_debugfs_mc_info(struct seq_file *m, void *data)
2862{
2863 struct drm_info_node *node = (struct drm_info_node *) m->private;
2864 struct drm_device *dev = node->minor->dev;
2865 struct radeon_device *rdev = dev->dev_private;
2866
2867 DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
2868 DREG32_SYS(m, rdev, VM_L2_STATUS);
2869 return 0;
2870}
2871
2872static struct drm_info_list r600_mc_info_list[] = {
2873 {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
2874 {"r600_ring_info", r600_debugfs_cp_ring_info, 0, NULL},
2875};
2876#endif
2877
2878int r600_debugfs_mc_info_init(struct radeon_device *rdev)
2879{
2880#if defined(CONFIG_DEBUG_FS)
2881 return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
2882#else
2883 return 0;
2884#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002885}