2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 * Authors: Dave Airlie
28 #include <linux/seq_file.h>
29 #include <linux/firmware.h>
30 #include <linux/platform_device.h>
32 #include "radeon_drm.h"
34 #include "radeon_asic.h"
35 #include "radeon_mode.h"
40 #define PFP_UCODE_SIZE 576
41 #define PM4_UCODE_SIZE 1792
42 #define RLC_UCODE_SIZE 768
43 #define R700_PFP_UCODE_SIZE 848
44 #define R700_PM4_UCODE_SIZE 1360
45 #define R700_RLC_UCODE_SIZE 1024
48 MODULE_FIRMWARE("radeon/R600_pfp.bin");
49 MODULE_FIRMWARE("radeon/R600_me.bin");
50 MODULE_FIRMWARE("radeon/RV610_pfp.bin");
51 MODULE_FIRMWARE("radeon/RV610_me.bin");
52 MODULE_FIRMWARE("radeon/RV630_pfp.bin");
53 MODULE_FIRMWARE("radeon/RV630_me.bin");
54 MODULE_FIRMWARE("radeon/RV620_pfp.bin");
55 MODULE_FIRMWARE("radeon/RV620_me.bin");
56 MODULE_FIRMWARE("radeon/RV635_pfp.bin");
57 MODULE_FIRMWARE("radeon/RV635_me.bin");
58 MODULE_FIRMWARE("radeon/RV670_pfp.bin");
59 MODULE_FIRMWARE("radeon/RV670_me.bin");
60 MODULE_FIRMWARE("radeon/RS780_pfp.bin");
61 MODULE_FIRMWARE("radeon/RS780_me.bin");
62 MODULE_FIRMWARE("radeon/RV770_pfp.bin");
63 MODULE_FIRMWARE("radeon/RV770_me.bin");
64 MODULE_FIRMWARE("radeon/RV730_pfp.bin");
65 MODULE_FIRMWARE("radeon/RV730_me.bin");
66 MODULE_FIRMWARE("radeon/RV710_pfp.bin");
67 MODULE_FIRMWARE("radeon/RV710_me.bin");
68 MODULE_FIRMWARE("radeon/R600_rlc.bin");
69 MODULE_FIRMWARE("radeon/R700_rlc.bin");
71 int r600_debugfs_mc_info_init(struct radeon_device *rdev);
73 /* r600,rv610,rv630,rv620,rv635,rv670 */
74 int r600_mc_wait_for_idle(struct radeon_device *rdev);
75 void r600_gpu_init(struct radeon_device *rdev);
76 void r600_fini(struct radeon_device *rdev);
78 /* hpd for digital panel detect/disconnect */
79 bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
81 bool connected = false;
83 if (ASIC_IS_DCE3(rdev)) {
86 if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
90 if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
94 if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
98 if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
103 if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
107 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
116 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
120 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
124 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
134 void r600_hpd_set_polarity(struct radeon_device *rdev,
135 enum radeon_hpd_id hpd)
138 bool connected = r600_hpd_sense(rdev, hpd);
140 if (ASIC_IS_DCE3(rdev)) {
143 tmp = RREG32(DC_HPD1_INT_CONTROL);
145 tmp &= ~DC_HPDx_INT_POLARITY;
147 tmp |= DC_HPDx_INT_POLARITY;
148 WREG32(DC_HPD1_INT_CONTROL, tmp);
151 tmp = RREG32(DC_HPD2_INT_CONTROL);
153 tmp &= ~DC_HPDx_INT_POLARITY;
155 tmp |= DC_HPDx_INT_POLARITY;
156 WREG32(DC_HPD2_INT_CONTROL, tmp);
159 tmp = RREG32(DC_HPD3_INT_CONTROL);
161 tmp &= ~DC_HPDx_INT_POLARITY;
163 tmp |= DC_HPDx_INT_POLARITY;
164 WREG32(DC_HPD3_INT_CONTROL, tmp);
167 tmp = RREG32(DC_HPD4_INT_CONTROL);
169 tmp &= ~DC_HPDx_INT_POLARITY;
171 tmp |= DC_HPDx_INT_POLARITY;
172 WREG32(DC_HPD4_INT_CONTROL, tmp);
175 tmp = RREG32(DC_HPD5_INT_CONTROL);
177 tmp &= ~DC_HPDx_INT_POLARITY;
179 tmp |= DC_HPDx_INT_POLARITY;
180 WREG32(DC_HPD5_INT_CONTROL, tmp);
184 tmp = RREG32(DC_HPD6_INT_CONTROL);
186 tmp &= ~DC_HPDx_INT_POLARITY;
188 tmp |= DC_HPDx_INT_POLARITY;
189 WREG32(DC_HPD6_INT_CONTROL, tmp);
197 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
199 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
201 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
202 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
205 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
207 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
209 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
210 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
213 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
215 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
217 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
218 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
226 void r600_hpd_init(struct radeon_device *rdev)
228 struct drm_device *dev = rdev->ddev;
229 struct drm_connector *connector;
231 if (ASIC_IS_DCE3(rdev)) {
232 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
233 if (ASIC_IS_DCE32(rdev))
236 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
237 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
238 switch (radeon_connector->hpd.hpd) {
240 WREG32(DC_HPD1_CONTROL, tmp);
241 rdev->irq.hpd[0] = true;
244 WREG32(DC_HPD2_CONTROL, tmp);
245 rdev->irq.hpd[1] = true;
248 WREG32(DC_HPD3_CONTROL, tmp);
249 rdev->irq.hpd[2] = true;
252 WREG32(DC_HPD4_CONTROL, tmp);
253 rdev->irq.hpd[3] = true;
257 WREG32(DC_HPD5_CONTROL, tmp);
258 rdev->irq.hpd[4] = true;
261 WREG32(DC_HPD6_CONTROL, tmp);
262 rdev->irq.hpd[5] = true;
269 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
270 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
271 switch (radeon_connector->hpd.hpd) {
273 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
274 rdev->irq.hpd[0] = true;
277 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
278 rdev->irq.hpd[1] = true;
281 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
282 rdev->irq.hpd[2] = true;
289 if (rdev->irq.installed)
293 void r600_hpd_fini(struct radeon_device *rdev)
295 struct drm_device *dev = rdev->ddev;
296 struct drm_connector *connector;
298 if (ASIC_IS_DCE3(rdev)) {
299 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
300 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
301 switch (radeon_connector->hpd.hpd) {
303 WREG32(DC_HPD1_CONTROL, 0);
304 rdev->irq.hpd[0] = false;
307 WREG32(DC_HPD2_CONTROL, 0);
308 rdev->irq.hpd[1] = false;
311 WREG32(DC_HPD3_CONTROL, 0);
312 rdev->irq.hpd[2] = false;
315 WREG32(DC_HPD4_CONTROL, 0);
316 rdev->irq.hpd[3] = false;
320 WREG32(DC_HPD5_CONTROL, 0);
321 rdev->irq.hpd[4] = false;
324 WREG32(DC_HPD6_CONTROL, 0);
325 rdev->irq.hpd[5] = false;
332 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
333 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
334 switch (radeon_connector->hpd.hpd) {
336 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
337 rdev->irq.hpd[0] = false;
340 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
341 rdev->irq.hpd[1] = false;
344 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
345 rdev->irq.hpd[2] = false;
357 void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
362 /* flush hdp cache so updates hit vram */
363 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
365 WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
366 WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
367 WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
368 for (i = 0; i < rdev->usec_timeout; i++) {
370 tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
371 tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
373 printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
383 int r600_pcie_gart_init(struct radeon_device *rdev)
387 if (rdev->gart.table.vram.robj) {
388 WARN(1, "R600 PCIE GART already initialized.\n");
391 /* Initialize common gart structure */
392 r = radeon_gart_init(rdev);
395 rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
396 return radeon_gart_table_vram_alloc(rdev);
399 int r600_pcie_gart_enable(struct radeon_device *rdev)
404 if (rdev->gart.table.vram.robj == NULL) {
405 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
408 r = radeon_gart_table_vram_pin(rdev);
411 radeon_gart_restore(rdev);
414 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
415 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
416 EFFECTIVE_L2_QUEUE_SIZE(7));
417 WREG32(VM_L2_CNTL2, 0);
418 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
419 /* Setup TLB control */
420 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
421 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
422 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
423 ENABLE_WAIT_L2_QUERY;
424 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
425 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
426 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
427 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
428 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
429 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
430 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
431 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
432 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
433 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
434 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
435 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
436 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
437 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
438 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
439 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
440 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
441 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
442 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
443 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
444 (u32)(rdev->dummy_page.addr >> 12));
445 for (i = 1; i < 7; i++)
446 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
448 r600_pcie_gart_tlb_flush(rdev);
449 rdev->gart.ready = true;
453 void r600_pcie_gart_disable(struct radeon_device *rdev)
458 /* Disable all tables */
459 for (i = 0; i < 7; i++)
460 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
462 /* Disable L2 cache */
463 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
464 EFFECTIVE_L2_QUEUE_SIZE(7));
465 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
466 /* Setup L1 TLB control */
467 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
468 ENABLE_WAIT_L2_QUERY;
469 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
470 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
471 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
472 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
473 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
474 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
475 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
476 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
477 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
478 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
479 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
480 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
481 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
482 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
483 if (rdev->gart.table.vram.robj) {
484 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
485 if (likely(r == 0)) {
486 radeon_bo_kunmap(rdev->gart.table.vram.robj);
487 radeon_bo_unpin(rdev->gart.table.vram.robj);
488 radeon_bo_unreserve(rdev->gart.table.vram.robj);
493 void r600_pcie_gart_fini(struct radeon_device *rdev)
495 radeon_gart_fini(rdev);
496 r600_pcie_gart_disable(rdev);
497 radeon_gart_table_vram_free(rdev);
500 void r600_agp_enable(struct radeon_device *rdev)
506 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
507 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
508 EFFECTIVE_L2_QUEUE_SIZE(7));
509 WREG32(VM_L2_CNTL2, 0);
510 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
511 /* Setup TLB control */
512 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
513 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
514 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
515 ENABLE_WAIT_L2_QUERY;
516 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
517 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
518 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
519 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
520 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
521 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
522 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
523 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
524 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
525 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
526 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
527 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
528 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
529 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
530 for (i = 0; i < 7; i++)
531 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
534 int r600_mc_wait_for_idle(struct radeon_device *rdev)
539 for (i = 0; i < rdev->usec_timeout; i++) {
541 tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
549 static void r600_mc_program(struct radeon_device *rdev)
551 struct rv515_mc_save save;
556 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
557 WREG32((0x2c14 + j), 0x00000000);
558 WREG32((0x2c18 + j), 0x00000000);
559 WREG32((0x2c1c + j), 0x00000000);
560 WREG32((0x2c20 + j), 0x00000000);
561 WREG32((0x2c24 + j), 0x00000000);
563 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
565 rv515_mc_stop(rdev, &save);
566 if (r600_mc_wait_for_idle(rdev)) {
567 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
569 /* Lockout access through VGA aperture (doesn't exist before R600) */
570 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
571 /* Update configuration */
572 if (rdev->flags & RADEON_IS_AGP) {
573 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
574 /* VRAM before AGP */
575 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
576 rdev->mc.vram_start >> 12);
577 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
578 rdev->mc.gtt_end >> 12);
581 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
582 rdev->mc.gtt_start >> 12);
583 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
584 rdev->mc.vram_end >> 12);
587 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
588 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
590 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0);
591 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
592 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
593 WREG32(MC_VM_FB_LOCATION, tmp);
594 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
595 WREG32(HDP_NONSURFACE_INFO, (2 << 7));
596 WREG32(HDP_NONSURFACE_SIZE, rdev->mc.mc_vram_size | 0x3FF);
597 if (rdev->flags & RADEON_IS_AGP) {
598 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
599 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
600 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
602 WREG32(MC_VM_AGP_BASE, 0);
603 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
604 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
606 if (r600_mc_wait_for_idle(rdev)) {
607 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
609 rv515_mc_resume(rdev, &save);
610 /* we need to own VRAM, so turn off the VGA renderer here
611 * to stop it overwriting our objects */
612 rv515_vga_render_disable(rdev);
616 * r600_vram_gtt_location - try to find VRAM & GTT location
617 * @rdev: radeon device structure holding all necessary informations
618 * @mc: memory controller structure holding memory informations
620 * Function will place try to place VRAM at same place as in CPU (PCI)
621 * address space as some GPU seems to have issue when we reprogram at
622 * different address space.
624 * If there is not enough space to fit the unvisible VRAM after the
625 * aperture then we limit the VRAM size to the aperture.
627 * If we are using AGP then place VRAM adjacent to AGP aperture are we need
628 * them to be in one from GPU point of view so that we can program GPU to
629 * catch access outside them (weird GPU policy see ??).
631 * This function will never fails, worst case are limiting VRAM or GTT.
633 * Note: GTT start, end, size should be initialized before calling this
634 * function on AGP platform.
636 void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
638 u64 size_bf, size_af;
640 if (mc->mc_vram_size > 0xE0000000) {
641 /* leave room for at least 512M GTT */
642 dev_warn(rdev->dev, "limiting VRAM\n");
643 mc->real_vram_size = 0xE0000000;
644 mc->mc_vram_size = 0xE0000000;
646 if (rdev->flags & RADEON_IS_AGP) {
647 size_bf = mc->gtt_start;
648 size_af = 0xFFFFFFFF - mc->gtt_end + 1;
649 if (size_bf > size_af) {
650 if (mc->mc_vram_size > size_bf) {
651 dev_warn(rdev->dev, "limiting VRAM\n");
652 mc->real_vram_size = size_bf;
653 mc->mc_vram_size = size_bf;
655 mc->vram_start = mc->gtt_start - mc->mc_vram_size;
657 if (mc->mc_vram_size > size_af) {
658 dev_warn(rdev->dev, "limiting VRAM\n");
659 mc->real_vram_size = size_af;
660 mc->mc_vram_size = size_af;
662 mc->vram_start = mc->gtt_end;
664 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
665 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
666 mc->mc_vram_size >> 20, mc->vram_start,
667 mc->vram_end, mc->real_vram_size >> 20);
670 if (rdev->flags & RADEON_IS_IGP)
671 base = (RREG32(MC_VM_FB_LOCATION) & 0xFFFF) << 24;
672 radeon_vram_location(rdev, &rdev->mc, base);
673 radeon_gtt_location(rdev, mc);
677 int r600_mc_init(struct radeon_device *rdev)
680 int chansize, numchan;
682 /* Get VRAM informations */
683 rdev->mc.vram_is_ddr = true;
684 tmp = RREG32(RAMCFG);
685 if (tmp & CHANSIZE_OVERRIDE) {
687 } else if (tmp & CHANSIZE_MASK) {
693 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
708 rdev->mc.vram_width = numchan * chansize;
709 /* Could aper size report 0 ? */
710 rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
711 rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
712 /* Setup GPU memory space */
713 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
714 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
715 rdev->mc.visible_vram_size = rdev->mc.aper_size;
716 /* FIXME remove this once we support unmappable VRAM */
717 if (rdev->mc.mc_vram_size > rdev->mc.aper_size) {
718 rdev->mc.mc_vram_size = rdev->mc.aper_size;
719 rdev->mc.real_vram_size = rdev->mc.aper_size;
721 r600_vram_gtt_location(rdev, &rdev->mc);
723 if (rdev->flags & RADEON_IS_IGP)
724 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
725 radeon_update_bandwidth_info(rdev);
729 /* We doesn't check that the GPU really needs a reset we simply do the
730 * reset, it's up to the caller to determine if the GPU needs one. We
731 * might add an helper function to check that.
733 int r600_gpu_soft_reset(struct radeon_device *rdev)
735 struct rv515_mc_save save;
736 u32 grbm_busy_mask = S_008010_VC_BUSY(1) | S_008010_VGT_BUSY_NO_DMA(1) |
737 S_008010_VGT_BUSY(1) | S_008010_TA03_BUSY(1) |
738 S_008010_TC_BUSY(1) | S_008010_SX_BUSY(1) |
739 S_008010_SH_BUSY(1) | S_008010_SPI03_BUSY(1) |
740 S_008010_SMX_BUSY(1) | S_008010_SC_BUSY(1) |
741 S_008010_PA_BUSY(1) | S_008010_DB03_BUSY(1) |
742 S_008010_CR_BUSY(1) | S_008010_CB03_BUSY(1) |
743 S_008010_GUI_ACTIVE(1);
744 u32 grbm2_busy_mask = S_008014_SPI0_BUSY(1) | S_008014_SPI1_BUSY(1) |
745 S_008014_SPI2_BUSY(1) | S_008014_SPI3_BUSY(1) |
746 S_008014_TA0_BUSY(1) | S_008014_TA1_BUSY(1) |
747 S_008014_TA2_BUSY(1) | S_008014_TA3_BUSY(1) |
748 S_008014_DB0_BUSY(1) | S_008014_DB1_BUSY(1) |
749 S_008014_DB2_BUSY(1) | S_008014_DB3_BUSY(1) |
750 S_008014_CB0_BUSY(1) | S_008014_CB1_BUSY(1) |
751 S_008014_CB2_BUSY(1) | S_008014_CB3_BUSY(1);
754 dev_info(rdev->dev, "GPU softreset \n");
755 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
756 RREG32(R_008010_GRBM_STATUS));
757 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
758 RREG32(R_008014_GRBM_STATUS2));
759 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
760 RREG32(R_000E50_SRBM_STATUS));
761 rv515_mc_stop(rdev, &save);
762 if (r600_mc_wait_for_idle(rdev)) {
763 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
765 /* Disable CP parsing/prefetching */
766 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
767 /* Check if any of the rendering block is busy and reset it */
768 if ((RREG32(R_008010_GRBM_STATUS) & grbm_busy_mask) ||
769 (RREG32(R_008014_GRBM_STATUS2) & grbm2_busy_mask)) {
770 tmp = S_008020_SOFT_RESET_CR(1) |
771 S_008020_SOFT_RESET_DB(1) |
772 S_008020_SOFT_RESET_CB(1) |
773 S_008020_SOFT_RESET_PA(1) |
774 S_008020_SOFT_RESET_SC(1) |
775 S_008020_SOFT_RESET_SMX(1) |
776 S_008020_SOFT_RESET_SPI(1) |
777 S_008020_SOFT_RESET_SX(1) |
778 S_008020_SOFT_RESET_SH(1) |
779 S_008020_SOFT_RESET_TC(1) |
780 S_008020_SOFT_RESET_TA(1) |
781 S_008020_SOFT_RESET_VC(1) |
782 S_008020_SOFT_RESET_VGT(1);
783 dev_info(rdev->dev, " R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
784 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
785 RREG32(R_008020_GRBM_SOFT_RESET);
787 WREG32(R_008020_GRBM_SOFT_RESET, 0);
789 /* Reset CP (we always reset CP) */
790 tmp = S_008020_SOFT_RESET_CP(1);
791 dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
792 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
793 RREG32(R_008020_GRBM_SOFT_RESET);
795 WREG32(R_008020_GRBM_SOFT_RESET, 0);
796 /* Wait a little for things to settle down */
798 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
799 RREG32(R_008010_GRBM_STATUS));
800 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
801 RREG32(R_008014_GRBM_STATUS2));
802 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
803 RREG32(R_000E50_SRBM_STATUS));
804 rv515_mc_resume(rdev, &save);
808 bool r600_gpu_is_lockup(struct radeon_device *rdev)
815 srbm_status = RREG32(R_000E50_SRBM_STATUS);
816 grbm_status = RREG32(R_008010_GRBM_STATUS);
817 grbm_status2 = RREG32(R_008014_GRBM_STATUS2);
818 if (!G_008010_GUI_ACTIVE(grbm_status)) {
819 r100_gpu_lockup_update(&rdev->config.r300.lockup, &rdev->cp);
822 /* force CP activities */
823 r = radeon_ring_lock(rdev, 2);
826 radeon_ring_write(rdev, 0x80000000);
827 radeon_ring_write(rdev, 0x80000000);
828 radeon_ring_unlock_commit(rdev);
830 rdev->cp.rptr = RREG32(R600_CP_RB_RPTR);
831 return r100_gpu_cp_is_lockup(rdev, &rdev->config.r300.lockup, &rdev->cp);
834 int r600_asic_reset(struct radeon_device *rdev)
836 return r600_gpu_soft_reset(rdev);
839 static u32 r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes,
841 u32 backend_disable_mask)
844 u32 enabled_backends_mask;
845 u32 enabled_backends_count;
847 u32 swizzle_pipe[R6XX_MAX_PIPES];
851 if (num_tile_pipes > R6XX_MAX_PIPES)
852 num_tile_pipes = R6XX_MAX_PIPES;
853 if (num_tile_pipes < 1)
855 if (num_backends > R6XX_MAX_BACKENDS)
856 num_backends = R6XX_MAX_BACKENDS;
857 if (num_backends < 1)
860 enabled_backends_mask = 0;
861 enabled_backends_count = 0;
862 for (i = 0; i < R6XX_MAX_BACKENDS; ++i) {
863 if (((backend_disable_mask >> i) & 1) == 0) {
864 enabled_backends_mask |= (1 << i);
865 ++enabled_backends_count;
867 if (enabled_backends_count == num_backends)
871 if (enabled_backends_count == 0) {
872 enabled_backends_mask = 1;
873 enabled_backends_count = 1;
876 if (enabled_backends_count != num_backends)
877 num_backends = enabled_backends_count;
879 memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R6XX_MAX_PIPES);
880 switch (num_tile_pipes) {
936 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
937 while (((1 << cur_backend) & enabled_backends_mask) == 0)
938 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
940 backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
942 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
948 int r600_count_pipe_bits(uint32_t val)
952 for (i = 0; i < 32; i++) {
959 void r600_gpu_init(struct radeon_device *rdev)
964 u32 cc_rb_backend_disable;
965 u32 cc_gc_shader_pipe_config;
969 u32 sq_gpr_resource_mgmt_1 = 0;
970 u32 sq_gpr_resource_mgmt_2 = 0;
971 u32 sq_thread_resource_mgmt = 0;
972 u32 sq_stack_resource_mgmt_1 = 0;
973 u32 sq_stack_resource_mgmt_2 = 0;
975 /* FIXME: implement */
976 switch (rdev->family) {
978 rdev->config.r600.max_pipes = 4;
979 rdev->config.r600.max_tile_pipes = 8;
980 rdev->config.r600.max_simds = 4;
981 rdev->config.r600.max_backends = 4;
982 rdev->config.r600.max_gprs = 256;
983 rdev->config.r600.max_threads = 192;
984 rdev->config.r600.max_stack_entries = 256;
985 rdev->config.r600.max_hw_contexts = 8;
986 rdev->config.r600.max_gs_threads = 16;
987 rdev->config.r600.sx_max_export_size = 128;
988 rdev->config.r600.sx_max_export_pos_size = 16;
989 rdev->config.r600.sx_max_export_smx_size = 128;
990 rdev->config.r600.sq_num_cf_insts = 2;
994 rdev->config.r600.max_pipes = 2;
995 rdev->config.r600.max_tile_pipes = 2;
996 rdev->config.r600.max_simds = 3;
997 rdev->config.r600.max_backends = 1;
998 rdev->config.r600.max_gprs = 128;
999 rdev->config.r600.max_threads = 192;
1000 rdev->config.r600.max_stack_entries = 128;
1001 rdev->config.r600.max_hw_contexts = 8;
1002 rdev->config.r600.max_gs_threads = 4;
1003 rdev->config.r600.sx_max_export_size = 128;
1004 rdev->config.r600.sx_max_export_pos_size = 16;
1005 rdev->config.r600.sx_max_export_smx_size = 128;
1006 rdev->config.r600.sq_num_cf_insts = 2;
1012 rdev->config.r600.max_pipes = 1;
1013 rdev->config.r600.max_tile_pipes = 1;
1014 rdev->config.r600.max_simds = 2;
1015 rdev->config.r600.max_backends = 1;
1016 rdev->config.r600.max_gprs = 128;
1017 rdev->config.r600.max_threads = 192;
1018 rdev->config.r600.max_stack_entries = 128;
1019 rdev->config.r600.max_hw_contexts = 4;
1020 rdev->config.r600.max_gs_threads = 4;
1021 rdev->config.r600.sx_max_export_size = 128;
1022 rdev->config.r600.sx_max_export_pos_size = 16;
1023 rdev->config.r600.sx_max_export_smx_size = 128;
1024 rdev->config.r600.sq_num_cf_insts = 1;
1027 rdev->config.r600.max_pipes = 4;
1028 rdev->config.r600.max_tile_pipes = 4;
1029 rdev->config.r600.max_simds = 4;
1030 rdev->config.r600.max_backends = 4;
1031 rdev->config.r600.max_gprs = 192;
1032 rdev->config.r600.max_threads = 192;
1033 rdev->config.r600.max_stack_entries = 256;
1034 rdev->config.r600.max_hw_contexts = 8;
1035 rdev->config.r600.max_gs_threads = 16;
1036 rdev->config.r600.sx_max_export_size = 128;
1037 rdev->config.r600.sx_max_export_pos_size = 16;
1038 rdev->config.r600.sx_max_export_smx_size = 128;
1039 rdev->config.r600.sq_num_cf_insts = 2;
1045 /* Initialize HDP */
1046 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1047 WREG32((0x2c14 + j), 0x00000000);
1048 WREG32((0x2c18 + j), 0x00000000);
1049 WREG32((0x2c1c + j), 0x00000000);
1050 WREG32((0x2c20 + j), 0x00000000);
1051 WREG32((0x2c24 + j), 0x00000000);
1054 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
1058 ramcfg = RREG32(RAMCFG);
1059 switch (rdev->config.r600.max_tile_pipes) {
1061 tiling_config |= PIPE_TILING(0);
1064 tiling_config |= PIPE_TILING(1);
1067 tiling_config |= PIPE_TILING(2);
1070 tiling_config |= PIPE_TILING(3);
1075 rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
1076 rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
1077 tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
1078 tiling_config |= GROUP_SIZE(0);
1079 rdev->config.r600.tiling_group_size = 256;
1080 tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
1082 tiling_config |= ROW_TILING(3);
1083 tiling_config |= SAMPLE_SPLIT(3);
1085 tiling_config |= ROW_TILING(tmp);
1086 tiling_config |= SAMPLE_SPLIT(tmp);
1088 tiling_config |= BANK_SWAPS(1);
1090 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
1091 cc_rb_backend_disable |=
1092 BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK << rdev->config.r600.max_backends) & R6XX_MAX_BACKENDS_MASK);
1094 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
1095 cc_gc_shader_pipe_config |=
1096 INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK << rdev->config.r600.max_pipes) & R6XX_MAX_PIPES_MASK);
1097 cc_gc_shader_pipe_config |=
1098 INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK << rdev->config.r600.max_simds) & R6XX_MAX_SIMDS_MASK);
1100 backend_map = r600_get_tile_pipe_to_backend_map(rdev->config.r600.max_tile_pipes,
1101 (R6XX_MAX_BACKENDS -
1102 r600_count_pipe_bits((cc_rb_backend_disable &
1103 R6XX_MAX_BACKENDS_MASK) >> 16)),
1104 (cc_rb_backend_disable >> 16));
1106 tiling_config |= BACKEND_MAP(backend_map);
1107 WREG32(GB_TILING_CONFIG, tiling_config);
1108 WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
1109 WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
1112 WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
1113 WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
1114 WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
1116 tmp = R6XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
1117 WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
1118 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
1120 /* Setup some CP states */
1121 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
1122 WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
1124 WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
1125 SYNC_WALKER | SYNC_ALIGNER));
1126 /* Setup various GPU states */
1127 if (rdev->family == CHIP_RV670)
1128 WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
1130 tmp = RREG32(SX_DEBUG_1);
1131 tmp |= SMX_EVENT_RELEASE;
1132 if ((rdev->family > CHIP_R600))
1133 tmp |= ENABLE_NEW_SMX_ADDRESS;
1134 WREG32(SX_DEBUG_1, tmp);
1136 if (((rdev->family) == CHIP_R600) ||
1137 ((rdev->family) == CHIP_RV630) ||
1138 ((rdev->family) == CHIP_RV610) ||
1139 ((rdev->family) == CHIP_RV620) ||
1140 ((rdev->family) == CHIP_RS780) ||
1141 ((rdev->family) == CHIP_RS880)) {
1142 WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
1144 WREG32(DB_DEBUG, 0);
1146 WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
1147 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
1149 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1150 WREG32(VGT_NUM_INSTANCES, 0);
1152 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
1153 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
1155 tmp = RREG32(SQ_MS_FIFO_SIZES);
1156 if (((rdev->family) == CHIP_RV610) ||
1157 ((rdev->family) == CHIP_RV620) ||
1158 ((rdev->family) == CHIP_RS780) ||
1159 ((rdev->family) == CHIP_RS880)) {
1160 tmp = (CACHE_FIFO_SIZE(0xa) |
1161 FETCH_FIFO_HIWATER(0xa) |
1162 DONE_FIFO_HIWATER(0xe0) |
1163 ALU_UPDATE_FIFO_HIWATER(0x8));
1164 } else if (((rdev->family) == CHIP_R600) ||
1165 ((rdev->family) == CHIP_RV630)) {
1166 tmp &= ~DONE_FIFO_HIWATER(0xff);
1167 tmp |= DONE_FIFO_HIWATER(0x4);
1169 WREG32(SQ_MS_FIFO_SIZES, tmp);
1171 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
1172 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
1174 sq_config = RREG32(SQ_CONFIG);
1175 sq_config &= ~(PS_PRIO(3) |
1179 sq_config |= (DX9_CONSTS |
1186 if ((rdev->family) == CHIP_R600) {
1187 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
1189 NUM_CLAUSE_TEMP_GPRS(4));
1190 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
1192 sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
1193 NUM_VS_THREADS(48) |
1196 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
1197 NUM_VS_STACK_ENTRIES(128));
1198 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
1199 NUM_ES_STACK_ENTRIES(0));
1200 } else if (((rdev->family) == CHIP_RV610) ||
1201 ((rdev->family) == CHIP_RV620) ||
1202 ((rdev->family) == CHIP_RS780) ||
1203 ((rdev->family) == CHIP_RS880)) {
1204 /* no vertex cache */
1205 sq_config &= ~VC_ENABLE;
1207 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1209 NUM_CLAUSE_TEMP_GPRS(2));
1210 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1212 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1213 NUM_VS_THREADS(78) |
1215 NUM_ES_THREADS(31));
1216 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1217 NUM_VS_STACK_ENTRIES(40));
1218 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1219 NUM_ES_STACK_ENTRIES(16));
1220 } else if (((rdev->family) == CHIP_RV630) ||
1221 ((rdev->family) == CHIP_RV635)) {
1222 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1224 NUM_CLAUSE_TEMP_GPRS(2));
1225 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
1227 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1228 NUM_VS_THREADS(78) |
1230 NUM_ES_THREADS(31));
1231 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1232 NUM_VS_STACK_ENTRIES(40));
1233 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1234 NUM_ES_STACK_ENTRIES(16));
1235 } else if ((rdev->family) == CHIP_RV670) {
1236 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1238 NUM_CLAUSE_TEMP_GPRS(2));
1239 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1241 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1242 NUM_VS_THREADS(78) |
1244 NUM_ES_THREADS(31));
1245 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
1246 NUM_VS_STACK_ENTRIES(64));
1247 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
1248 NUM_ES_STACK_ENTRIES(64));
1251 WREG32(SQ_CONFIG, sq_config);
1252 WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
1253 WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
1254 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
1255 WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
1256 WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
1258 if (((rdev->family) == CHIP_RV610) ||
1259 ((rdev->family) == CHIP_RV620) ||
1260 ((rdev->family) == CHIP_RS780) ||
1261 ((rdev->family) == CHIP_RS880)) {
1262 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
1264 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
1267 /* More default values. 2D/3D driver should adjust as needed */
1268 WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
1269 S1_X(0x4) | S1_Y(0xc)));
1270 WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
1271 S1_X(0x2) | S1_Y(0x2) |
1272 S2_X(0xa) | S2_Y(0x6) |
1273 S3_X(0x6) | S3_Y(0xa)));
1274 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
1275 S1_X(0x4) | S1_Y(0xc) |
1276 S2_X(0x1) | S2_Y(0x6) |
1277 S3_X(0xa) | S3_Y(0xe)));
1278 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
1279 S5_X(0x0) | S5_Y(0x0) |
1280 S6_X(0xb) | S6_Y(0x4) |
1281 S7_X(0x7) | S7_Y(0x8)));
1283 WREG32(VGT_STRMOUT_EN, 0);
1284 tmp = rdev->config.r600.max_pipes * 16;
1285 switch (rdev->family) {
1301 WREG32(VGT_ES_PER_GS, 128);
1302 WREG32(VGT_GS_PER_ES, tmp);
1303 WREG32(VGT_GS_PER_VS, 2);
1304 WREG32(VGT_GS_VERTEX_REUSE, 16);
1306 /* more default values. 2D/3D driver should adjust as needed */
1307 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
1308 WREG32(VGT_STRMOUT_EN, 0);
1310 WREG32(PA_SC_MODE_CNTL, 0);
1311 WREG32(PA_SC_AA_CONFIG, 0);
1312 WREG32(PA_SC_LINE_STIPPLE, 0);
1313 WREG32(SPI_INPUT_Z, 0);
1314 WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
1315 WREG32(CB_COLOR7_FRAG, 0);
1317 /* Clear render buffer base addresses */
1318 WREG32(CB_COLOR0_BASE, 0);
1319 WREG32(CB_COLOR1_BASE, 0);
1320 WREG32(CB_COLOR2_BASE, 0);
1321 WREG32(CB_COLOR3_BASE, 0);
1322 WREG32(CB_COLOR4_BASE, 0);
1323 WREG32(CB_COLOR5_BASE, 0);
1324 WREG32(CB_COLOR6_BASE, 0);
1325 WREG32(CB_COLOR7_BASE, 0);
1326 WREG32(CB_COLOR7_FRAG, 0);
1328 switch (rdev->family) {
1333 tmp = TC_L2_SIZE(8);
1337 tmp = TC_L2_SIZE(4);
1340 tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
1343 tmp = TC_L2_SIZE(0);
1346 WREG32(TC_CNTL, tmp);
1348 tmp = RREG32(HDP_HOST_PATH_CNTL);
1349 WREG32(HDP_HOST_PATH_CNTL, tmp);
1351 tmp = RREG32(ARB_POP);
1352 tmp |= ENABLE_TC128;
1353 WREG32(ARB_POP, tmp);
1355 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1356 WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
1358 WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
1363 * Indirect registers accessor
1365 u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
1369 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1370 (void)RREG32(PCIE_PORT_INDEX);
1371 r = RREG32(PCIE_PORT_DATA);
1375 void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
1377 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1378 (void)RREG32(PCIE_PORT_INDEX);
1379 WREG32(PCIE_PORT_DATA, (v));
1380 (void)RREG32(PCIE_PORT_DATA);
1386 void r600_cp_stop(struct radeon_device *rdev)
1388 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
1391 int r600_init_microcode(struct radeon_device *rdev)
1393 struct platform_device *pdev;
1394 const char *chip_name;
1395 const char *rlc_chip_name;
1396 size_t pfp_req_size, me_req_size, rlc_req_size;
1402 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
1405 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
1409 switch (rdev->family) {
1412 rlc_chip_name = "R600";
1415 chip_name = "RV610";
1416 rlc_chip_name = "R600";
1419 chip_name = "RV630";
1420 rlc_chip_name = "R600";
1423 chip_name = "RV620";
1424 rlc_chip_name = "R600";
1427 chip_name = "RV635";
1428 rlc_chip_name = "R600";
1431 chip_name = "RV670";
1432 rlc_chip_name = "R600";
1436 chip_name = "RS780";
1437 rlc_chip_name = "R600";
1440 chip_name = "RV770";
1441 rlc_chip_name = "R700";
1445 chip_name = "RV730";
1446 rlc_chip_name = "R700";
1449 chip_name = "RV710";
1450 rlc_chip_name = "R700";
1455 if (rdev->family >= CHIP_RV770) {
1456 pfp_req_size = R700_PFP_UCODE_SIZE * 4;
1457 me_req_size = R700_PM4_UCODE_SIZE * 4;
1458 rlc_req_size = R700_RLC_UCODE_SIZE * 4;
1460 pfp_req_size = PFP_UCODE_SIZE * 4;
1461 me_req_size = PM4_UCODE_SIZE * 12;
1462 rlc_req_size = RLC_UCODE_SIZE * 4;
1465 DRM_INFO("Loading %s Microcode\n", chip_name);
1467 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
1468 err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
1471 if (rdev->pfp_fw->size != pfp_req_size) {
1473 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
1474 rdev->pfp_fw->size, fw_name);
1479 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
1480 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
1483 if (rdev->me_fw->size != me_req_size) {
1485 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
1486 rdev->me_fw->size, fw_name);
1490 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
1491 err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
1494 if (rdev->rlc_fw->size != rlc_req_size) {
1496 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
1497 rdev->rlc_fw->size, fw_name);
1502 platform_device_unregister(pdev);
1507 "r600_cp: Failed to load firmware \"%s\"\n",
1509 release_firmware(rdev->pfp_fw);
1510 rdev->pfp_fw = NULL;
1511 release_firmware(rdev->me_fw);
1513 release_firmware(rdev->rlc_fw);
1514 rdev->rlc_fw = NULL;
1519 static int r600_cp_load_microcode(struct radeon_device *rdev)
1521 const __be32 *fw_data;
1524 if (!rdev->me_fw || !rdev->pfp_fw)
1529 WREG32(CP_RB_CNTL, RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
1532 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
1533 RREG32(GRBM_SOFT_RESET);
1535 WREG32(GRBM_SOFT_RESET, 0);
1537 WREG32(CP_ME_RAM_WADDR, 0);
1539 fw_data = (const __be32 *)rdev->me_fw->data;
1540 WREG32(CP_ME_RAM_WADDR, 0);
1541 for (i = 0; i < PM4_UCODE_SIZE * 3; i++)
1542 WREG32(CP_ME_RAM_DATA,
1543 be32_to_cpup(fw_data++));
1545 fw_data = (const __be32 *)rdev->pfp_fw->data;
1546 WREG32(CP_PFP_UCODE_ADDR, 0);
1547 for (i = 0; i < PFP_UCODE_SIZE; i++)
1548 WREG32(CP_PFP_UCODE_DATA,
1549 be32_to_cpup(fw_data++));
1551 WREG32(CP_PFP_UCODE_ADDR, 0);
1552 WREG32(CP_ME_RAM_WADDR, 0);
1553 WREG32(CP_ME_RAM_RADDR, 0);
1557 int r600_cp_start(struct radeon_device *rdev)
1562 r = radeon_ring_lock(rdev, 7);
1564 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
1567 radeon_ring_write(rdev, PACKET3(PACKET3_ME_INITIALIZE, 5));
1568 radeon_ring_write(rdev, 0x1);
1569 if (rdev->family < CHIP_RV770) {
1570 radeon_ring_write(rdev, 0x3);
1571 radeon_ring_write(rdev, rdev->config.r600.max_hw_contexts - 1);
1573 radeon_ring_write(rdev, 0x0);
1574 radeon_ring_write(rdev, rdev->config.rv770.max_hw_contexts - 1);
1576 radeon_ring_write(rdev, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
1577 radeon_ring_write(rdev, 0);
1578 radeon_ring_write(rdev, 0);
1579 radeon_ring_unlock_commit(rdev);
1582 WREG32(R_0086D8_CP_ME_CNTL, cp_me);
1586 int r600_cp_resume(struct radeon_device *rdev)
1593 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
1594 RREG32(GRBM_SOFT_RESET);
1596 WREG32(GRBM_SOFT_RESET, 0);
1598 /* Set ring buffer size */
1599 rb_bufsz = drm_order(rdev->cp.ring_size / 8);
1600 tmp = RB_NO_UPDATE | (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
1602 tmp |= BUF_SWAP_32BIT;
1604 WREG32(CP_RB_CNTL, tmp);
1605 WREG32(CP_SEM_WAIT_TIMER, 0x4);
1607 /* Set the write pointer delay */
1608 WREG32(CP_RB_WPTR_DELAY, 0);
1610 /* Initialize the ring buffer's read and write pointers */
1611 WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
1612 WREG32(CP_RB_RPTR_WR, 0);
1613 WREG32(CP_RB_WPTR, 0);
1614 WREG32(CP_RB_RPTR_ADDR, rdev->cp.gpu_addr & 0xFFFFFFFF);
1615 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->cp.gpu_addr));
1617 WREG32(CP_RB_CNTL, tmp);
1619 WREG32(CP_RB_BASE, rdev->cp.gpu_addr >> 8);
1620 WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
1622 rdev->cp.rptr = RREG32(CP_RB_RPTR);
1623 rdev->cp.wptr = RREG32(CP_RB_WPTR);
1625 r600_cp_start(rdev);
1626 rdev->cp.ready = true;
1627 r = radeon_ring_test(rdev);
1629 rdev->cp.ready = false;
1635 void r600_cp_commit(struct radeon_device *rdev)
1637 WREG32(CP_RB_WPTR, rdev->cp.wptr);
1638 (void)RREG32(CP_RB_WPTR);
1641 void r600_ring_init(struct radeon_device *rdev, unsigned ring_size)
1645 /* Align ring size */
1646 rb_bufsz = drm_order(ring_size / 8);
1647 ring_size = (1 << (rb_bufsz + 1)) * 4;
1648 rdev->cp.ring_size = ring_size;
1649 rdev->cp.align_mask = 16 - 1;
1652 void r600_cp_fini(struct radeon_device *rdev)
1655 radeon_ring_fini(rdev);
1660 * GPU scratch registers helpers function.
1662 void r600_scratch_init(struct radeon_device *rdev)
1666 rdev->scratch.num_reg = 7;
1667 for (i = 0; i < rdev->scratch.num_reg; i++) {
1668 rdev->scratch.free[i] = true;
1669 rdev->scratch.reg[i] = SCRATCH_REG0 + (i * 4);
1673 int r600_ring_test(struct radeon_device *rdev)
1680 r = radeon_scratch_get(rdev, &scratch);
1682 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
1685 WREG32(scratch, 0xCAFEDEAD);
1686 r = radeon_ring_lock(rdev, 3);
1688 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
1689 radeon_scratch_free(rdev, scratch);
1692 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
1693 radeon_ring_write(rdev, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
1694 radeon_ring_write(rdev, 0xDEADBEEF);
1695 radeon_ring_unlock_commit(rdev);
1696 for (i = 0; i < rdev->usec_timeout; i++) {
1697 tmp = RREG32(scratch);
1698 if (tmp == 0xDEADBEEF)
1702 if (i < rdev->usec_timeout) {
1703 DRM_INFO("ring test succeeded in %d usecs\n", i);
1705 DRM_ERROR("radeon: ring test failed (scratch(0x%04X)=0x%08X)\n",
1709 radeon_scratch_free(rdev, scratch);
1713 void r600_wb_disable(struct radeon_device *rdev)
1717 WREG32(SCRATCH_UMSK, 0);
1718 if (rdev->wb.wb_obj) {
1719 r = radeon_bo_reserve(rdev->wb.wb_obj, false);
1720 if (unlikely(r != 0))
1722 radeon_bo_kunmap(rdev->wb.wb_obj);
1723 radeon_bo_unpin(rdev->wb.wb_obj);
1724 radeon_bo_unreserve(rdev->wb.wb_obj);
1728 void r600_wb_fini(struct radeon_device *rdev)
1730 r600_wb_disable(rdev);
1731 if (rdev->wb.wb_obj) {
1732 radeon_bo_unref(&rdev->wb.wb_obj);
1734 rdev->wb.wb_obj = NULL;
1738 int r600_wb_enable(struct radeon_device *rdev)
1742 if (rdev->wb.wb_obj == NULL) {
1743 r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, true,
1744 RADEON_GEM_DOMAIN_GTT, &rdev->wb.wb_obj);
1746 dev_warn(rdev->dev, "(%d) create WB bo failed\n", r);
1749 r = radeon_bo_reserve(rdev->wb.wb_obj, false);
1750 if (unlikely(r != 0)) {
1754 r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT,
1755 &rdev->wb.gpu_addr);
1757 radeon_bo_unreserve(rdev->wb.wb_obj);
1758 dev_warn(rdev->dev, "(%d) pin WB bo failed\n", r);
1762 r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb);
1763 radeon_bo_unreserve(rdev->wb.wb_obj);
1765 dev_warn(rdev->dev, "(%d) map WB bo failed\n", r);
1770 WREG32(SCRATCH_ADDR, (rdev->wb.gpu_addr >> 8) & 0xFFFFFFFF);
1771 WREG32(CP_RB_RPTR_ADDR, (rdev->wb.gpu_addr + 1024) & 0xFFFFFFFC);
1772 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + 1024) & 0xFF);
1773 WREG32(SCRATCH_UMSK, 0xff);
1777 void r600_fence_ring_emit(struct radeon_device *rdev,
1778 struct radeon_fence *fence)
1780 /* Also consider EVENT_WRITE_EOP. it handles the interrupts + timestamps + events */
1782 radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE, 0));
1783 radeon_ring_write(rdev, CACHE_FLUSH_AND_INV_EVENT);
1784 /* wait for 3D idle clean */
1785 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
1786 radeon_ring_write(rdev, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
1787 radeon_ring_write(rdev, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
1788 /* Emit fence sequence & fire IRQ */
1789 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
1790 radeon_ring_write(rdev, ((rdev->fence_drv.scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
1791 radeon_ring_write(rdev, fence->seq);
1792 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
1793 radeon_ring_write(rdev, PACKET0(CP_INT_STATUS, 0));
1794 radeon_ring_write(rdev, RB_INT_STAT);
1797 int r600_copy_blit(struct radeon_device *rdev,
1798 uint64_t src_offset, uint64_t dst_offset,
1799 unsigned num_pages, struct radeon_fence *fence)
1803 mutex_lock(&rdev->r600_blit.mutex);
1804 rdev->r600_blit.vb_ib = NULL;
1805 r = r600_blit_prepare_copy(rdev, num_pages * RADEON_GPU_PAGE_SIZE);
1807 if (rdev->r600_blit.vb_ib)
1808 radeon_ib_free(rdev, &rdev->r600_blit.vb_ib);
1809 mutex_unlock(&rdev->r600_blit.mutex);
1812 r600_kms_blit_copy(rdev, src_offset, dst_offset, num_pages * RADEON_GPU_PAGE_SIZE);
1813 r600_blit_done_copy(rdev, fence);
1814 mutex_unlock(&rdev->r600_blit.mutex);
1818 int r600_set_surface_reg(struct radeon_device *rdev, int reg,
1819 uint32_t tiling_flags, uint32_t pitch,
1820 uint32_t offset, uint32_t obj_size)
1822 /* FIXME: implement */
1826 void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
1828 /* FIXME: implement */
1832 bool r600_card_posted(struct radeon_device *rdev)
1836 /* first check CRTCs */
1837 reg = RREG32(D1CRTC_CONTROL) |
1838 RREG32(D2CRTC_CONTROL);
1842 /* then check MEM_SIZE, in case the crtcs are off */
1843 if (RREG32(CONFIG_MEMSIZE))
1849 int r600_startup(struct radeon_device *rdev)
1853 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
1854 r = r600_init_microcode(rdev);
1856 DRM_ERROR("Failed to load firmware!\n");
1861 r600_mc_program(rdev);
1862 if (rdev->flags & RADEON_IS_AGP) {
1863 r600_agp_enable(rdev);
1865 r = r600_pcie_gart_enable(rdev);
1869 r600_gpu_init(rdev);
1870 r = r600_blit_init(rdev);
1872 r600_blit_fini(rdev);
1873 rdev->asic->copy = NULL;
1874 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
1876 /* pin copy shader into vram */
1877 if (rdev->r600_blit.shader_obj) {
1878 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
1879 if (unlikely(r != 0))
1881 r = radeon_bo_pin(rdev->r600_blit.shader_obj, RADEON_GEM_DOMAIN_VRAM,
1882 &rdev->r600_blit.shader_gpu_addr);
1883 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
1885 dev_err(rdev->dev, "(%d) pin blit object failed\n", r);
1890 r = r600_irq_init(rdev);
1892 DRM_ERROR("radeon: IH init failed (%d).\n", r);
1893 radeon_irq_kms_fini(rdev);
1898 r = radeon_ring_init(rdev, rdev->cp.ring_size);
1901 r = r600_cp_load_microcode(rdev);
1904 r = r600_cp_resume(rdev);
1907 /* write back buffer are not vital so don't worry about failure */
1908 r600_wb_enable(rdev);
1912 void r600_vga_set_state(struct radeon_device *rdev, bool state)
1916 temp = RREG32(CONFIG_CNTL);
1917 if (state == false) {
1923 WREG32(CONFIG_CNTL, temp);
1926 int r600_resume(struct radeon_device *rdev)
1930 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
1931 * posting will perform necessary task to bring back GPU into good
1935 atom_asic_init(rdev->mode_info.atom_context);
1936 /* Initialize clocks */
1937 r = radeon_clocks_init(rdev);
1942 r = r600_startup(rdev);
1944 DRM_ERROR("r600 startup failed on resume\n");
1948 r = r600_ib_test(rdev);
1950 DRM_ERROR("radeon: failled testing IB (%d).\n", r);
1954 r = r600_audio_init(rdev);
1956 DRM_ERROR("radeon: audio resume failed\n");
1963 int r600_suspend(struct radeon_device *rdev)
1967 r600_audio_fini(rdev);
1968 /* FIXME: we should wait for ring to be empty */
1970 rdev->cp.ready = false;
1971 r600_irq_suspend(rdev);
1972 r600_wb_disable(rdev);
1973 r600_pcie_gart_disable(rdev);
1974 /* unpin shaders bo */
1975 if (rdev->r600_blit.shader_obj) {
1976 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
1978 radeon_bo_unpin(rdev->r600_blit.shader_obj);
1979 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
1985 /* Plan is to move initialization in that function and use
1986 * helper function so that radeon_device_init pretty much
1987 * do nothing more than calling asic specific function. This
1988 * should also allow to remove a bunch of callback function
1991 int r600_init(struct radeon_device *rdev)
1995 r = radeon_dummy_page_init(rdev);
1998 if (r600_debugfs_mc_info_init(rdev)) {
1999 DRM_ERROR("Failed to register debugfs file for mc !\n");
2001 /* This don't do much */
2002 r = radeon_gem_init(rdev);
2006 if (!radeon_get_bios(rdev)) {
2007 if (ASIC_IS_AVIVO(rdev))
2010 /* Must be an ATOMBIOS */
2011 if (!rdev->is_atom_bios) {
2012 dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
2015 r = radeon_atombios_init(rdev);
2018 /* Post card if necessary */
2019 if (!r600_card_posted(rdev)) {
2021 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
2024 DRM_INFO("GPU not posted. posting now...\n");
2025 atom_asic_init(rdev->mode_info.atom_context);
2027 /* Initialize scratch registers */
2028 r600_scratch_init(rdev);
2029 /* Initialize surface registers */
2030 radeon_surface_init(rdev);
2031 /* Initialize clocks */
2032 radeon_get_clock_info(rdev->ddev);
2033 r = radeon_clocks_init(rdev);
2036 /* Initialize power management */
2037 radeon_pm_init(rdev);
2039 r = radeon_fence_driver_init(rdev);
2042 if (rdev->flags & RADEON_IS_AGP) {
2043 r = radeon_agp_init(rdev);
2045 radeon_agp_disable(rdev);
2047 r = r600_mc_init(rdev);
2050 /* Memory manager */
2051 r = radeon_bo_init(rdev);
2055 r = radeon_irq_kms_init(rdev);
2059 rdev->cp.ring_obj = NULL;
2060 r600_ring_init(rdev, 1024 * 1024);
2062 rdev->ih.ring_obj = NULL;
2063 r600_ih_ring_init(rdev, 64 * 1024);
2065 r = r600_pcie_gart_init(rdev);
2069 rdev->accel_working = true;
2070 r = r600_startup(rdev);
2072 dev_err(rdev->dev, "disabling GPU acceleration\n");
2075 r600_irq_fini(rdev);
2076 radeon_irq_kms_fini(rdev);
2077 r600_pcie_gart_fini(rdev);
2078 rdev->accel_working = false;
2080 if (rdev->accel_working) {
2081 r = radeon_ib_pool_init(rdev);
2083 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
2084 rdev->accel_working = false;
2086 r = r600_ib_test(rdev);
2088 dev_err(rdev->dev, "IB test failed (%d).\n", r);
2089 rdev->accel_working = false;
2094 r = r600_audio_init(rdev);
2096 return r; /* TODO error handling */
2100 void r600_fini(struct radeon_device *rdev)
2102 radeon_pm_fini(rdev);
2103 r600_audio_fini(rdev);
2104 r600_blit_fini(rdev);
2107 r600_irq_fini(rdev);
2108 radeon_irq_kms_fini(rdev);
2109 r600_pcie_gart_fini(rdev);
2110 radeon_agp_fini(rdev);
2111 radeon_gem_fini(rdev);
2112 radeon_fence_driver_fini(rdev);
2113 radeon_clocks_fini(rdev);
2114 radeon_bo_fini(rdev);
2115 radeon_atombios_fini(rdev);
2118 radeon_dummy_page_fini(rdev);
2125 void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
2127 /* FIXME: implement */
2128 radeon_ring_write(rdev, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
2129 radeon_ring_write(rdev, ib->gpu_addr & 0xFFFFFFFC);
2130 radeon_ring_write(rdev, upper_32_bits(ib->gpu_addr) & 0xFF);
2131 radeon_ring_write(rdev, ib->length_dw);
2134 int r600_ib_test(struct radeon_device *rdev)
2136 struct radeon_ib *ib;
2142 r = radeon_scratch_get(rdev, &scratch);
2144 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
2147 WREG32(scratch, 0xCAFEDEAD);
2148 r = radeon_ib_get(rdev, &ib);
2150 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
2153 ib->ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
2154 ib->ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2155 ib->ptr[2] = 0xDEADBEEF;
2156 ib->ptr[3] = PACKET2(0);
2157 ib->ptr[4] = PACKET2(0);
2158 ib->ptr[5] = PACKET2(0);
2159 ib->ptr[6] = PACKET2(0);
2160 ib->ptr[7] = PACKET2(0);
2161 ib->ptr[8] = PACKET2(0);
2162 ib->ptr[9] = PACKET2(0);
2163 ib->ptr[10] = PACKET2(0);
2164 ib->ptr[11] = PACKET2(0);
2165 ib->ptr[12] = PACKET2(0);
2166 ib->ptr[13] = PACKET2(0);
2167 ib->ptr[14] = PACKET2(0);
2168 ib->ptr[15] = PACKET2(0);
2170 r = radeon_ib_schedule(rdev, ib);
2172 radeon_scratch_free(rdev, scratch);
2173 radeon_ib_free(rdev, &ib);
2174 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
2177 r = radeon_fence_wait(ib->fence, false);
2179 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
2182 for (i = 0; i < rdev->usec_timeout; i++) {
2183 tmp = RREG32(scratch);
2184 if (tmp == 0xDEADBEEF)
2188 if (i < rdev->usec_timeout) {
2189 DRM_INFO("ib test succeeded in %u usecs\n", i);
2191 DRM_ERROR("radeon: ib test failed (sracth(0x%04X)=0x%08X)\n",
2195 radeon_scratch_free(rdev, scratch);
2196 radeon_ib_free(rdev, &ib);
2203 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
2204 * the same as the CP ring buffer, but in reverse. Rather than the CPU
2205 * writing to the ring and the GPU consuming, the GPU writes to the ring
2206 * and host consumes. As the host irq handler processes interrupts, it
2207 * increments the rptr. When the rptr catches up with the wptr, all the
2208 * current interrupts have been processed.
2211 void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
2215 /* Align ring size */
2216 rb_bufsz = drm_order(ring_size / 4);
2217 ring_size = (1 << rb_bufsz) * 4;
2218 rdev->ih.ring_size = ring_size;
2219 rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
2223 static int r600_ih_ring_alloc(struct radeon_device *rdev)
2227 /* Allocate ring buffer */
2228 if (rdev->ih.ring_obj == NULL) {
2229 r = radeon_bo_create(rdev, NULL, rdev->ih.ring_size,
2231 RADEON_GEM_DOMAIN_GTT,
2232 &rdev->ih.ring_obj);
2234 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
2237 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
2238 if (unlikely(r != 0))
2240 r = radeon_bo_pin(rdev->ih.ring_obj,
2241 RADEON_GEM_DOMAIN_GTT,
2242 &rdev->ih.gpu_addr);
2244 radeon_bo_unreserve(rdev->ih.ring_obj);
2245 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
2248 r = radeon_bo_kmap(rdev->ih.ring_obj,
2249 (void **)&rdev->ih.ring);
2250 radeon_bo_unreserve(rdev->ih.ring_obj);
2252 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
2259 static void r600_ih_ring_fini(struct radeon_device *rdev)
2262 if (rdev->ih.ring_obj) {
2263 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
2264 if (likely(r == 0)) {
2265 radeon_bo_kunmap(rdev->ih.ring_obj);
2266 radeon_bo_unpin(rdev->ih.ring_obj);
2267 radeon_bo_unreserve(rdev->ih.ring_obj);
2269 radeon_bo_unref(&rdev->ih.ring_obj);
2270 rdev->ih.ring = NULL;
2271 rdev->ih.ring_obj = NULL;
2275 static void r600_rlc_stop(struct radeon_device *rdev)
2278 if (rdev->family >= CHIP_RV770) {
2279 /* r7xx asics need to soft reset RLC before halting */
2280 WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
2281 RREG32(SRBM_SOFT_RESET);
2283 WREG32(SRBM_SOFT_RESET, 0);
2284 RREG32(SRBM_SOFT_RESET);
2287 WREG32(RLC_CNTL, 0);
2290 static void r600_rlc_start(struct radeon_device *rdev)
2292 WREG32(RLC_CNTL, RLC_ENABLE);
2295 static int r600_rlc_init(struct radeon_device *rdev)
2298 const __be32 *fw_data;
2303 r600_rlc_stop(rdev);
2305 WREG32(RLC_HB_BASE, 0);
2306 WREG32(RLC_HB_CNTL, 0);
2307 WREG32(RLC_HB_RPTR, 0);
2308 WREG32(RLC_HB_WPTR, 0);
2309 WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
2310 WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
2311 WREG32(RLC_MC_CNTL, 0);
2312 WREG32(RLC_UCODE_CNTL, 0);
2314 fw_data = (const __be32 *)rdev->rlc_fw->data;
2315 if (rdev->family >= CHIP_RV770) {
2316 for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
2317 WREG32(RLC_UCODE_ADDR, i);
2318 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2321 for (i = 0; i < RLC_UCODE_SIZE; i++) {
2322 WREG32(RLC_UCODE_ADDR, i);
2323 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
2326 WREG32(RLC_UCODE_ADDR, 0);
2328 r600_rlc_start(rdev);
2333 static void r600_enable_interrupts(struct radeon_device *rdev)
2335 u32 ih_cntl = RREG32(IH_CNTL);
2336 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
2338 ih_cntl |= ENABLE_INTR;
2339 ih_rb_cntl |= IH_RB_ENABLE;
2340 WREG32(IH_CNTL, ih_cntl);
2341 WREG32(IH_RB_CNTL, ih_rb_cntl);
2342 rdev->ih.enabled = true;
2345 static void r600_disable_interrupts(struct radeon_device *rdev)
2347 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
2348 u32 ih_cntl = RREG32(IH_CNTL);
2350 ih_rb_cntl &= ~IH_RB_ENABLE;
2351 ih_cntl &= ~ENABLE_INTR;
2352 WREG32(IH_RB_CNTL, ih_rb_cntl);
2353 WREG32(IH_CNTL, ih_cntl);
2354 /* set rptr, wptr to 0 */
2355 WREG32(IH_RB_RPTR, 0);
2356 WREG32(IH_RB_WPTR, 0);
2357 rdev->ih.enabled = false;
2362 static void r600_disable_interrupt_state(struct radeon_device *rdev)
2366 WREG32(CP_INT_CNTL, 0);
2367 WREG32(GRBM_INT_CNTL, 0);
2368 WREG32(DxMODE_INT_MASK, 0);
2369 if (ASIC_IS_DCE3(rdev)) {
2370 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
2371 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
2372 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2373 WREG32(DC_HPD1_INT_CONTROL, tmp);
2374 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2375 WREG32(DC_HPD2_INT_CONTROL, tmp);
2376 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2377 WREG32(DC_HPD3_INT_CONTROL, tmp);
2378 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2379 WREG32(DC_HPD4_INT_CONTROL, tmp);
2380 if (ASIC_IS_DCE32(rdev)) {
2381 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2382 WREG32(DC_HPD5_INT_CONTROL, tmp);
2383 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
2384 WREG32(DC_HPD6_INT_CONTROL, tmp);
2387 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
2388 WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
2389 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
2390 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
2391 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
2392 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
2393 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
2394 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
2398 int r600_irq_init(struct radeon_device *rdev)
2402 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
2405 ret = r600_ih_ring_alloc(rdev);
2410 r600_disable_interrupts(rdev);
2413 ret = r600_rlc_init(rdev);
2415 r600_ih_ring_fini(rdev);
2419 /* setup interrupt control */
2420 /* set dummy read address to ring address */
2421 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
2422 interrupt_cntl = RREG32(INTERRUPT_CNTL);
2423 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
2424 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
2426 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
2427 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
2428 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
2429 WREG32(INTERRUPT_CNTL, interrupt_cntl);
2431 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
2432 rb_bufsz = drm_order(rdev->ih.ring_size / 4);
2434 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
2435 IH_WPTR_OVERFLOW_CLEAR |
2437 /* WPTR writeback, not yet */
2438 /*ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;*/
2439 WREG32(IH_RB_WPTR_ADDR_LO, 0);
2440 WREG32(IH_RB_WPTR_ADDR_HI, 0);
2442 WREG32(IH_RB_CNTL, ih_rb_cntl);
2444 /* set rptr, wptr to 0 */
2445 WREG32(IH_RB_RPTR, 0);
2446 WREG32(IH_RB_WPTR, 0);
2448 /* Default settings for IH_CNTL (disabled at first) */
2449 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
2450 /* RPTR_REARM only works if msi's are enabled */
2451 if (rdev->msi_enabled)
2452 ih_cntl |= RPTR_REARM;
2455 ih_cntl |= IH_MC_SWAP(IH_MC_SWAP_32BIT);
2457 WREG32(IH_CNTL, ih_cntl);
2459 /* force the active interrupt state to all disabled */
2460 r600_disable_interrupt_state(rdev);
2463 r600_enable_interrupts(rdev);
2468 void r600_irq_suspend(struct radeon_device *rdev)
2470 r600_disable_interrupts(rdev);
2471 r600_rlc_stop(rdev);
2474 void r600_irq_fini(struct radeon_device *rdev)
2476 r600_irq_suspend(rdev);
2477 r600_ih_ring_fini(rdev);
2480 int r600_irq_set(struct radeon_device *rdev)
2482 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
2484 u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
2486 if (!rdev->irq.installed) {
2487 WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n");
2490 /* don't enable anything if the ih is disabled */
2491 if (!rdev->ih.enabled) {
2492 r600_disable_interrupts(rdev);
2493 /* force the active interrupt state to all disabled */
2494 r600_disable_interrupt_state(rdev);
2498 if (ASIC_IS_DCE3(rdev)) {
2499 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
2500 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
2501 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
2502 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
2503 if (ASIC_IS_DCE32(rdev)) {
2504 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
2505 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
2508 hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
2509 hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
2510 hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
2513 if (rdev->irq.sw_int) {
2514 DRM_DEBUG("r600_irq_set: sw int\n");
2515 cp_int_cntl |= RB_INT_ENABLE;
2517 if (rdev->irq.crtc_vblank_int[0]) {
2518 DRM_DEBUG("r600_irq_set: vblank 0\n");
2519 mode_int |= D1MODE_VBLANK_INT_MASK;
2521 if (rdev->irq.crtc_vblank_int[1]) {
2522 DRM_DEBUG("r600_irq_set: vblank 1\n");
2523 mode_int |= D2MODE_VBLANK_INT_MASK;
2525 if (rdev->irq.hpd[0]) {
2526 DRM_DEBUG("r600_irq_set: hpd 1\n");
2527 hpd1 |= DC_HPDx_INT_EN;
2529 if (rdev->irq.hpd[1]) {
2530 DRM_DEBUG("r600_irq_set: hpd 2\n");
2531 hpd2 |= DC_HPDx_INT_EN;
2533 if (rdev->irq.hpd[2]) {
2534 DRM_DEBUG("r600_irq_set: hpd 3\n");
2535 hpd3 |= DC_HPDx_INT_EN;
2537 if (rdev->irq.hpd[3]) {
2538 DRM_DEBUG("r600_irq_set: hpd 4\n");
2539 hpd4 |= DC_HPDx_INT_EN;
2541 if (rdev->irq.hpd[4]) {
2542 DRM_DEBUG("r600_irq_set: hpd 5\n");
2543 hpd5 |= DC_HPDx_INT_EN;
2545 if (rdev->irq.hpd[5]) {
2546 DRM_DEBUG("r600_irq_set: hpd 6\n");
2547 hpd6 |= DC_HPDx_INT_EN;
2550 WREG32(CP_INT_CNTL, cp_int_cntl);
2551 WREG32(DxMODE_INT_MASK, mode_int);
2552 if (ASIC_IS_DCE3(rdev)) {
2553 WREG32(DC_HPD1_INT_CONTROL, hpd1);
2554 WREG32(DC_HPD2_INT_CONTROL, hpd2);
2555 WREG32(DC_HPD3_INT_CONTROL, hpd3);
2556 WREG32(DC_HPD4_INT_CONTROL, hpd4);
2557 if (ASIC_IS_DCE32(rdev)) {
2558 WREG32(DC_HPD5_INT_CONTROL, hpd5);
2559 WREG32(DC_HPD6_INT_CONTROL, hpd6);
2562 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
2563 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
2564 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
2570 static inline void r600_irq_ack(struct radeon_device *rdev,
2573 u32 *disp_int_cont2)
2577 if (ASIC_IS_DCE3(rdev)) {
2578 *disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
2579 *disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
2580 *disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
2582 *disp_int = RREG32(DISP_INTERRUPT_STATUS);
2583 *disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
2584 *disp_int_cont2 = 0;
2587 if (*disp_int & LB_D1_VBLANK_INTERRUPT)
2588 WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
2589 if (*disp_int & LB_D1_VLINE_INTERRUPT)
2590 WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
2591 if (*disp_int & LB_D2_VBLANK_INTERRUPT)
2592 WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
2593 if (*disp_int & LB_D2_VLINE_INTERRUPT)
2594 WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
2595 if (*disp_int & DC_HPD1_INTERRUPT) {
2596 if (ASIC_IS_DCE3(rdev)) {
2597 tmp = RREG32(DC_HPD1_INT_CONTROL);
2598 tmp |= DC_HPDx_INT_ACK;
2599 WREG32(DC_HPD1_INT_CONTROL, tmp);
2601 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
2602 tmp |= DC_HPDx_INT_ACK;
2603 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
2606 if (*disp_int & DC_HPD2_INTERRUPT) {
2607 if (ASIC_IS_DCE3(rdev)) {
2608 tmp = RREG32(DC_HPD2_INT_CONTROL);
2609 tmp |= DC_HPDx_INT_ACK;
2610 WREG32(DC_HPD2_INT_CONTROL, tmp);
2612 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
2613 tmp |= DC_HPDx_INT_ACK;
2614 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
2617 if (*disp_int_cont & DC_HPD3_INTERRUPT) {
2618 if (ASIC_IS_DCE3(rdev)) {
2619 tmp = RREG32(DC_HPD3_INT_CONTROL);
2620 tmp |= DC_HPDx_INT_ACK;
2621 WREG32(DC_HPD3_INT_CONTROL, tmp);
2623 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
2624 tmp |= DC_HPDx_INT_ACK;
2625 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
2628 if (*disp_int_cont & DC_HPD4_INTERRUPT) {
2629 tmp = RREG32(DC_HPD4_INT_CONTROL);
2630 tmp |= DC_HPDx_INT_ACK;
2631 WREG32(DC_HPD4_INT_CONTROL, tmp);
2633 if (ASIC_IS_DCE32(rdev)) {
2634 if (*disp_int_cont2 & DC_HPD5_INTERRUPT) {
2635 tmp = RREG32(DC_HPD5_INT_CONTROL);
2636 tmp |= DC_HPDx_INT_ACK;
2637 WREG32(DC_HPD5_INT_CONTROL, tmp);
2639 if (*disp_int_cont2 & DC_HPD6_INTERRUPT) {
2640 tmp = RREG32(DC_HPD5_INT_CONTROL);
2641 tmp |= DC_HPDx_INT_ACK;
2642 WREG32(DC_HPD6_INT_CONTROL, tmp);
2647 void r600_irq_disable(struct radeon_device *rdev)
2649 u32 disp_int, disp_int_cont, disp_int_cont2;
2651 r600_disable_interrupts(rdev);
2652 /* Wait and acknowledge irq */
2654 r600_irq_ack(rdev, &disp_int, &disp_int_cont, &disp_int_cont2);
2655 r600_disable_interrupt_state(rdev);
2658 static inline u32 r600_get_ih_wptr(struct radeon_device *rdev)
2662 /* XXX use writeback */
2663 wptr = RREG32(IH_RB_WPTR);
2665 if (wptr & RB_OVERFLOW) {
2666 /* When a ring buffer overflow happen start parsing interrupt
2667 * from the last not overwritten vector (wptr + 16). Hopefully
2668 * this should allow us to catchup.
2670 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
2671 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
2672 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
2673 tmp = RREG32(IH_RB_CNTL);
2674 tmp |= IH_WPTR_OVERFLOW_CLEAR;
2675 WREG32(IH_RB_CNTL, tmp);
2677 return (wptr & rdev->ih.ptr_mask);
2681 * Each IV ring entry is 128 bits:
2682 * [7:0] - interrupt source id
2684 * [59:32] - interrupt source data
2685 * [127:60] - reserved
2687 * The basic interrupt vector entries
2688 * are decoded as follows:
2689 * src_id src_data description
2694 * 19 0 FP Hot plug detection A
2695 * 19 1 FP Hot plug detection B
2696 * 19 2 DAC A auto-detection
2697 * 19 3 DAC B auto-detection
2701 * 181 - EOP Interrupt
2704 * Note, these are based on r600 and may need to be
2705 * adjusted or added to on newer asics
2708 int r600_irq_process(struct radeon_device *rdev)
2710 u32 wptr = r600_get_ih_wptr(rdev);
2711 u32 rptr = rdev->ih.rptr;
2712 u32 src_id, src_data;
2713 u32 ring_index, disp_int, disp_int_cont, disp_int_cont2;
2714 unsigned long flags;
2715 bool queue_hotplug = false;
2717 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
2718 if (!rdev->ih.enabled)
2721 spin_lock_irqsave(&rdev->ih.lock, flags);
2724 spin_unlock_irqrestore(&rdev->ih.lock, flags);
2727 if (rdev->shutdown) {
2728 spin_unlock_irqrestore(&rdev->ih.lock, flags);
2733 /* display interrupts */
2734 r600_irq_ack(rdev, &disp_int, &disp_int_cont, &disp_int_cont2);
2736 rdev->ih.wptr = wptr;
2737 while (rptr != wptr) {
2738 /* wptr/rptr are in bytes! */
2739 ring_index = rptr / 4;
2740 src_id = rdev->ih.ring[ring_index] & 0xff;
2741 src_data = rdev->ih.ring[ring_index + 1] & 0xfffffff;
2744 case 1: /* D1 vblank/vline */
2746 case 0: /* D1 vblank */
2747 if (disp_int & LB_D1_VBLANK_INTERRUPT) {
2748 drm_handle_vblank(rdev->ddev, 0);
2749 rdev->pm.vblank_sync = true;
2750 wake_up(&rdev->irq.vblank_queue);
2751 disp_int &= ~LB_D1_VBLANK_INTERRUPT;
2752 DRM_DEBUG("IH: D1 vblank\n");
2755 case 1: /* D1 vline */
2756 if (disp_int & LB_D1_VLINE_INTERRUPT) {
2757 disp_int &= ~LB_D1_VLINE_INTERRUPT;
2758 DRM_DEBUG("IH: D1 vline\n");
2762 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
2766 case 5: /* D2 vblank/vline */
2768 case 0: /* D2 vblank */
2769 if (disp_int & LB_D2_VBLANK_INTERRUPT) {
2770 drm_handle_vblank(rdev->ddev, 1);
2771 rdev->pm.vblank_sync = true;
2772 wake_up(&rdev->irq.vblank_queue);
2773 disp_int &= ~LB_D2_VBLANK_INTERRUPT;
2774 DRM_DEBUG("IH: D2 vblank\n");
2777 case 1: /* D1 vline */
2778 if (disp_int & LB_D2_VLINE_INTERRUPT) {
2779 disp_int &= ~LB_D2_VLINE_INTERRUPT;
2780 DRM_DEBUG("IH: D2 vline\n");
2784 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
2788 case 19: /* HPD/DAC hotplug */
2791 if (disp_int & DC_HPD1_INTERRUPT) {
2792 disp_int &= ~DC_HPD1_INTERRUPT;
2793 queue_hotplug = true;
2794 DRM_DEBUG("IH: HPD1\n");
2798 if (disp_int & DC_HPD2_INTERRUPT) {
2799 disp_int &= ~DC_HPD2_INTERRUPT;
2800 queue_hotplug = true;
2801 DRM_DEBUG("IH: HPD2\n");
2805 if (disp_int_cont & DC_HPD3_INTERRUPT) {
2806 disp_int_cont &= ~DC_HPD3_INTERRUPT;
2807 queue_hotplug = true;
2808 DRM_DEBUG("IH: HPD3\n");
2812 if (disp_int_cont & DC_HPD4_INTERRUPT) {
2813 disp_int_cont &= ~DC_HPD4_INTERRUPT;
2814 queue_hotplug = true;
2815 DRM_DEBUG("IH: HPD4\n");
2819 if (disp_int_cont2 & DC_HPD5_INTERRUPT) {
2820 disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
2821 queue_hotplug = true;
2822 DRM_DEBUG("IH: HPD5\n");
2826 if (disp_int_cont2 & DC_HPD6_INTERRUPT) {
2827 disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
2828 queue_hotplug = true;
2829 DRM_DEBUG("IH: HPD6\n");
2833 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
2837 case 176: /* CP_INT in ring buffer */
2838 case 177: /* CP_INT in IB1 */
2839 case 178: /* CP_INT in IB2 */
2840 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
2841 radeon_fence_process(rdev);
2843 case 181: /* CP EOP event */
2844 DRM_DEBUG("IH: CP EOP\n");
2847 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
2851 /* wptr/rptr are in bytes! */
2853 rptr &= rdev->ih.ptr_mask;
2855 /* make sure wptr hasn't changed while processing */
2856 wptr = r600_get_ih_wptr(rdev);
2857 if (wptr != rdev->ih.wptr)
2860 queue_work(rdev->wq, &rdev->hotplug_work);
2861 rdev->ih.rptr = rptr;
2862 WREG32(IH_RB_RPTR, rdev->ih.rptr);
2863 spin_unlock_irqrestore(&rdev->ih.lock, flags);
2870 #if defined(CONFIG_DEBUG_FS)
2872 static int r600_debugfs_cp_ring_info(struct seq_file *m, void *data)
2874 struct drm_info_node *node = (struct drm_info_node *) m->private;
2875 struct drm_device *dev = node->minor->dev;
2876 struct radeon_device *rdev = dev->dev_private;
2877 unsigned count, i, j;
2879 radeon_ring_free_size(rdev);
2880 count = (rdev->cp.ring_size / 4) - rdev->cp.ring_free_dw;
2881 seq_printf(m, "CP_STAT 0x%08x\n", RREG32(CP_STAT));
2882 seq_printf(m, "CP_RB_WPTR 0x%08x\n", RREG32(CP_RB_WPTR));
2883 seq_printf(m, "CP_RB_RPTR 0x%08x\n", RREG32(CP_RB_RPTR));
2884 seq_printf(m, "driver's copy of the CP_RB_WPTR 0x%08x\n", rdev->cp.wptr);
2885 seq_printf(m, "driver's copy of the CP_RB_RPTR 0x%08x\n", rdev->cp.rptr);
2886 seq_printf(m, "%u free dwords in ring\n", rdev->cp.ring_free_dw);
2887 seq_printf(m, "%u dwords in ring\n", count);
2889 for (j = 0; j <= count; j++) {
2890 seq_printf(m, "r[%04d]=0x%08x\n", i, rdev->cp.ring[i]);
2891 i = (i + 1) & rdev->cp.ptr_mask;
2896 static int r600_debugfs_mc_info(struct seq_file *m, void *data)
2898 struct drm_info_node *node = (struct drm_info_node *) m->private;
2899 struct drm_device *dev = node->minor->dev;
2900 struct radeon_device *rdev = dev->dev_private;
2902 DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
2903 DREG32_SYS(m, rdev, VM_L2_STATUS);
2907 static struct drm_info_list r600_mc_info_list[] = {
2908 {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
2909 {"r600_ring_info", r600_debugfs_cp_ring_info, 0, NULL},
2913 int r600_debugfs_mc_info_init(struct radeon_device *rdev)
2915 #if defined(CONFIG_DEBUG_FS)
2916 return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
2923 * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
2924 * rdev: radeon device structure
2925 * bo: buffer object struct which userspace is waiting for idle
2927 * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
2928 * through ring buffer, this leads to corruption in rendering, see
2929 * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
2930 * directly perform HDP flush by writing register through MMIO.
2932 void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
2934 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);