26 #include <linux/slab.h>
37 #define EVERGREEN_PFP_UCODE_SIZE 1120
38 #define EVERGREEN_PM4_UCODE_SIZE 1376
40 static const u32 crtc_offsets[6] =
57 unsigned *bankh,
unsigned *mtaspect,
101 if ((v == 0) || (v == 6) || (v == 7)) {
207 DRM_DEBUG(
"Update pending now high. Unlocking vupdate_lock.\n");
230 actual_temp = temp / 2 - (0x200 - toffset);
232 actual_temp = temp / 2 + toffset;
234 actual_temp = actual_temp * 1000;
242 else if (temp & 0x200)
244 else if (temp & 0x100) {
245 actual_temp = temp & 0x1ff;
246 actual_temp |= ~0x1ff;
248 actual_temp = temp & 0xff;
250 actual_temp = (actual_temp * 1000) / 2;
259 int actual_temp = temp - 49;
261 return actual_temp * 1000;
315 rdev->
pm.power_state[
idx].num_clock_modes - 1;
321 rdev->
pm.power_state[
idx].num_clock_modes - 1;
392 int req_ps_idx = rdev->
pm.requested_power_state_index;
393 int req_cm_idx = rdev->
pm.requested_clock_mode_index;
399 if (voltage->
voltage == 0xff01)
403 rdev->
pm.current_vddc = voltage->
voltage;
404 DRM_DEBUG(
"Setting: vddc: %d\n", voltage->
voltage);
407 if (voltage->
vddci == 0xff01)
409 if (voltage->
vddci && (voltage->
vddci != rdev->
pm.current_vddci)) {
411 rdev->
pm.current_vddci = voltage->
vddci;
412 DRM_DEBUG(
"Setting: vddci: %d\n", voltage->
vddci);
478 bool connected =
false;
598 switch (radeon_connector->
hpd.hpd) {
621 enabled |= 1 << radeon_connector->
hpd.hpd;
638 unsigned disabled = 0;
642 switch (radeon_connector->
hpd.hpd) {
664 disabled |= 1 << radeon_connector->
hpd.hpd;
698 if (radeon_crtc->
base.enabled && mode) {
711 if (radeon_crtc->
base.enabled && mode) {
787 yclk.
full = dfixed_div(yclk, a);
791 dram_efficiency.
full = dfixed_div(dram_efficiency, a);
807 yclk.
full = dfixed_div(yclk, a);
811 disp_dram_allocation.
full = dfixed_div(disp_dram_allocation, a);
827 sclk.
full = dfixed_div(sclk, a);
830 return_efficiency.
full = dfixed_div(return_efficiency, a);
847 disp_clk.
full = dfixed_div(disp_clk, a);
850 disp_clk_request_efficiency.
full = dfixed_div(disp_clk_request_efficiency, a);
853 bandwidth.
full =
dfixed_mul(bandwidth, disp_clk_request_efficiency);
861 u32 dram_bandwidth = evergreen_dram_bandwidth(wm);
862 u32 data_return_bandwidth = evergreen_data_return_bandwidth(wm);
863 u32 dmif_req_bandwidth = evergreen_dmif_request_bandwidth(wm);
865 return min(dram_bandwidth,
min(data_return_bandwidth, dmif_req_bandwidth));
882 line_time.
full = dfixed_div(line_time, a);
887 bandwidth.
full = dfixed_div(bandwidth, line_time);
895 u32 mc_latency = 2000;
896 u32 available_bandwidth = evergreen_available_bandwidth(wm);
897 u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
898 u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
900 u32 other_heads_data_return_time = ((wm->
num_heads + 1) * worst_chunk_return_time) +
901 (wm->
num_heads * cursor_line_pair_return_time);
902 u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
903 u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
915 max_src_lines_per_dst_line = 4;
917 max_src_lines_per_dst_line = 2;
921 a.
full = dfixed_div(a, b);
925 b.
full = dfixed_div(c, b);
934 b.
full = dfixed_div(c, b);
935 a.
full = dfixed_div(a, b);
938 if (line_fill_time < wm->active_time)
941 return latency + (line_fill_time - wm->
active_time);
945 static bool evergreen_average_bandwidth_vs_dram_bandwidth_for_display(
struct evergreen_wm_params *wm)
947 if (evergreen_average_bandwidth(wm) <=
948 (evergreen_dram_bandwidth_for_display(wm) / wm->
num_heads))
954 static bool evergreen_average_bandwidth_vs_available_bandwidth(
struct evergreen_wm_params *wm)
956 if (evergreen_average_bandwidth(wm) <=
957 (evergreen_available_bandwidth(wm) / wm->
num_heads))
967 u32 latency_tolerant_lines;
973 latency_tolerant_lines = 1;
975 if (lb_partitions <= (wm->
vtaps + 1))
976 latency_tolerant_lines = 1;
978 latency_tolerant_lines = 2;
981 latency_hiding = (latency_tolerant_lines * line_time + wm->
blank_time);
983 if (evergreen_latency_watermark(wm) <= latency_hiding)
989 static void evergreen_program_watermarks(
struct radeon_device *rdev,
990 struct radeon_crtc *radeon_crtc,
991 u32 lb_size,
u32 num_heads)
997 u32 latency_watermark_a = 0, latency_watermark_b = 0;
998 u32 priority_a_mark = 0, priority_b_mark = 0;
1005 if (radeon_crtc->
base.enabled && num_heads && mode) {
1006 pixel_period = 1000000 / (
u32)mode->
clock;
1011 wm.
yclk = rdev->
pm.current_mclk * 10;
1012 wm.
sclk = rdev->
pm.current_sclk * 10;
1020 wm.
vsc = radeon_crtc->
vsc;
1030 latency_watermark_a =
min(evergreen_latency_watermark(&wm), (
u32)65535);
1033 latency_watermark_b =
min(evergreen_latency_watermark(&wm), (
u32)65535);
1037 if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm) ||
1038 !evergreen_average_bandwidth_vs_available_bandwidth(&wm) ||
1039 !evergreen_check_latency_hiding(&wm) ||
1041 DRM_DEBUG_KMS(
"force priority to high\n");
1048 b.
full = dfixed_div(b, a);
1052 c.
full = dfixed_div(c, a);
1054 c.
full = dfixed_div(c, a);
1060 b.
full = dfixed_div(b, a);
1064 c.
full = dfixed_div(c, a);
1066 c.
full = dfixed_div(c, a);
1109 u32 num_heads = 0, lb_size;
1114 for (i = 0; i < rdev->
num_crtc; i++) {
1115 if (rdev->
mode_info.crtcs[i]->base.enabled)
1118 for (i = 0; i < rdev->
num_crtc; i += 2) {
1119 mode0 = &rdev->
mode_info.crtcs[
i]->base.mode;
1120 mode1 = &rdev->
mode_info.crtcs[i+1]->base.mode;
1121 lb_size = evergreen_line_buffer_adjust(rdev, rdev->
mode_info.crtcs[i], mode0, mode1);
1122 evergreen_program_watermarks(rdev, rdev->
mode_info.crtcs[i], lb_size, num_heads);
1123 lb_size = evergreen_line_buffer_adjust(rdev, rdev->
mode_info.crtcs[i+1], mode1, mode0);
1124 evergreen_program_watermarks(rdev, rdev->
mode_info.crtcs[i+1], lb_size, num_heads);
1178 static int evergreen_pcie_gart_enable(
struct radeon_device *rdev)
1184 dev_err(rdev->
dev,
"No VRAM object for PCIE GART.\n");
1230 DRM_INFO(
"PCIE GART of %uM enabled (table at 0x%016llX).\n",
1231 (
unsigned)(rdev->
mc.gtt_size >> 20),
1232 (
unsigned long long)rdev->
gart.table_addr);
1233 rdev->
gart.ready =
true;
1237 static void evergreen_pcie_gart_disable(
struct radeon_device *rdev)
1262 static void evergreen_pcie_gart_fini(
struct radeon_device *rdev)
1264 evergreen_pcie_gart_disable(rdev);
1270 static void evergreen_agp_enable(
struct radeon_device *rdev)
1307 for (i = 0; i < rdev->
num_crtc; i++) {
1345 blackout &= ~BLACKOUT_MODE_MASK;
1356 for (i = 0; i < rdev->
num_crtc; i++) {
1362 (
u32)rdev->
mc.vram_start);
1364 (
u32)rdev->
mc.vram_start);
1376 for (i = 0; i < rdev->
num_crtc; i++) {
1409 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1410 WREG32((0x2c14 + j), 0x00000000);
1411 WREG32((0x2c18 + j), 0x00000000);
1412 WREG32((0x2c1c + j), 0x00000000);
1413 WREG32((0x2c20 + j), 0x00000000);
1414 WREG32((0x2c24 + j), 0x00000000);
1420 dev_warn(rdev->
dev,
"Wait for MC idle timedout !\n");
1426 if (rdev->
mc.vram_start < rdev->
mc.gtt_start) {
1429 rdev->
mc.vram_start >> 12);
1431 rdev->
mc.gtt_end >> 12);
1435 rdev->
mc.gtt_start >> 12);
1437 rdev->
mc.vram_end >> 12);
1441 rdev->
mc.vram_start >> 12);
1443 rdev->
mc.vram_end >> 12);
1451 tmp |= ((rdev->
mc.vram_end >> 20) & 0xF) << 24;
1452 tmp |= ((rdev->
mc.vram_start >> 20) & 0xF) << 20;
1455 tmp = ((rdev->
mc.vram_end >> 24) & 0xFFFF) << 16;
1456 tmp |= ((rdev->
mc.vram_start >> 24) & 0xFFFF);
1471 dev_warn(rdev->
dev,
"Wait for MC idle timedout !\n");
1492 next_rptr = ring->
wptr + 3 + 4;
1497 }
else if (rdev->
wb.enabled) {
1498 next_rptr = ring->
wptr + 5 + 4;
1517 static int evergreen_cp_load_microcode(
struct radeon_device *rdev)
1557 DRM_ERROR(
"radeon: cp failed to lock ring (%d).\n", r);
1574 DRM_ERROR(
"radeon: cp failed to lock ring (%d).\n", r);
1659 if (rdev->
wb.enabled)
1674 evergreen_cp_start(rdev);
1678 ring->
ready =
false;
1690 u32 mc_shared_chmap, mc_arb_ramcfg;
1694 u32 sq_lds_resource_mgmt;
1695 u32 sq_gpr_resource_mgmt_1;
1696 u32 sq_gpr_resource_mgmt_2;
1697 u32 sq_gpr_resource_mgmt_3;
1698 u32 sq_thread_resource_mgmt;
1699 u32 sq_thread_resource_mgmt_2;
1700 u32 sq_stack_resource_mgmt_1;
1701 u32 sq_stack_resource_mgmt_2;
1702 u32 sq_stack_resource_mgmt_3;
1703 u32 vgt_cache_invalidation;
1704 u32 hdp_host_path_cntl,
tmp;
1705 u32 disabled_rb_mask;
1706 int i,
j, num_shader_engines, ps_thread_count;
1825 if (rdev->
pdev->device == 0x9648)
1827 else if ((rdev->
pdev->device == 0x9647) ||
1828 (rdev->
pdev->device == 0x964a))
1940 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1941 WREG32((0x2c14 + j), 0x00000000);
1942 WREG32((0x2c18 + j), 0x00000000);
1943 WREG32((0x2c1c + j), 0x00000000);
1944 WREG32((0x2c20 + j), 0x00000000);
1945 WREG32((0x2c24 + j), 0x00000000);
2002 ((gb_addr_config & 0x30000000) >> 28) << 12;
2014 tmp = (((efuse_straps_4 & 0xf) << 4) |
2015 ((efuse_straps_3 & 0xf0000000) >> 28));
2019 u32 rb_disable_bitmap;
2025 tmp |= rb_disable_bitmap;
2029 disabled_rb_mask =
tmp;
2130 ps_thread_count = 96;
2133 ps_thread_count = 128;
2233 int chansize, numchan;
2236 rdev->
mc.vram_is_ddr =
true;
2266 rdev->
mc.vram_width = numchan * chansize;
2282 rdev->
mc.visible_vram_size = rdev->
mc.aper_size;
2293 u32 grbm_status_se0, grbm_status_se1;
2308 static int evergreen_gpu_soft_reset(
struct radeon_device *rdev)
2325 dev_info(rdev->
dev,
" R_008674_CP_STALLED_STAT1 = 0x%08X\n",
2327 dev_info(rdev->
dev,
" R_008678_CP_STALLED_STAT2 = 0x%08X\n",
2329 dev_info(rdev->
dev,
" R_00867C_CP_BUSY_STAT = 0x%08X\n",
2331 dev_info(rdev->
dev,
" R_008680_CP_STAT = 0x%08X\n",
2335 dev_warn(rdev->
dev,
"Wait for MC idle timedout !\n");
2354 dev_info(rdev->
dev,
" GRBM_SOFT_RESET=0x%08X\n", grbm_reset);
2370 dev_info(rdev->
dev,
" R_008674_CP_STALLED_STAT1 = 0x%08X\n",
2372 dev_info(rdev->
dev,
" R_008678_CP_STALLED_STAT2 = 0x%08X\n",
2374 dev_info(rdev->
dev,
" R_00867C_CP_BUSY_STAT = 0x%08X\n",
2376 dev_info(rdev->
dev,
" R_008680_CP_STAT = 0x%08X\n",
2384 return evergreen_gpu_soft_reset(rdev);
2454 u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
2455 u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
2456 u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
2457 u32 grbm_int_cntl = 0;
2458 u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
2459 u32 afmt1 = 0, afmt2 = 0, afmt3 = 0, afmt4 = 0, afmt5 = 0, afmt6 = 0;
2461 if (!rdev->
irq.installed) {
2462 WARN(1,
"Can't enable IRQ/MSI because no handler is installed\n");
2466 if (!rdev->
ih.enabled) {
2490 DRM_DEBUG(
"evergreen_irq_set: sw int gfx\n");
2494 DRM_DEBUG(
"evergreen_irq_set: sw int cp1\n");
2498 DRM_DEBUG(
"evergreen_irq_set: sw int cp2\n");
2503 DRM_DEBUG(
"evergreen_irq_set: sw int gfx\n");
2509 if (rdev->
irq.crtc_vblank_int[0] ||
2511 DRM_DEBUG(
"evergreen_irq_set: vblank 0\n");
2514 if (rdev->
irq.crtc_vblank_int[1] ||
2516 DRM_DEBUG(
"evergreen_irq_set: vblank 1\n");
2519 if (rdev->
irq.crtc_vblank_int[2] ||
2521 DRM_DEBUG(
"evergreen_irq_set: vblank 2\n");
2524 if (rdev->
irq.crtc_vblank_int[3] ||
2526 DRM_DEBUG(
"evergreen_irq_set: vblank 3\n");
2529 if (rdev->
irq.crtc_vblank_int[4] ||
2531 DRM_DEBUG(
"evergreen_irq_set: vblank 4\n");
2534 if (rdev->
irq.crtc_vblank_int[5] ||
2536 DRM_DEBUG(
"evergreen_irq_set: vblank 5\n");
2539 if (rdev->
irq.hpd[0]) {
2540 DRM_DEBUG(
"evergreen_irq_set: hpd 1\n");
2543 if (rdev->
irq.hpd[1]) {
2544 DRM_DEBUG(
"evergreen_irq_set: hpd 2\n");
2547 if (rdev->
irq.hpd[2]) {
2548 DRM_DEBUG(
"evergreen_irq_set: hpd 3\n");
2551 if (rdev->
irq.hpd[3]) {
2552 DRM_DEBUG(
"evergreen_irq_set: hpd 4\n");
2555 if (rdev->
irq.hpd[4]) {
2556 DRM_DEBUG(
"evergreen_irq_set: hpd 5\n");
2559 if (rdev->
irq.hpd[5]) {
2560 DRM_DEBUG(
"evergreen_irq_set: hpd 6\n");
2563 if (rdev->
irq.afmt[0]) {
2564 DRM_DEBUG(
"evergreen_irq_set: hdmi 0\n");
2567 if (rdev->
irq.afmt[1]) {
2568 DRM_DEBUG(
"evergreen_irq_set: hdmi 1\n");
2571 if (rdev->
irq.afmt[2]) {
2572 DRM_DEBUG(
"evergreen_irq_set: hdmi 2\n");
2575 if (rdev->
irq.afmt[3]) {
2576 DRM_DEBUG(
"evergreen_irq_set: hdmi 3\n");
2579 if (rdev->
irq.afmt[4]) {
2580 DRM_DEBUG(
"evergreen_irq_set: hdmi 4\n");
2583 if (rdev->
irq.afmt[5]) {
2584 DRM_DEBUG(
"evergreen_irq_set: hdmi 5\n");
2768 static void evergreen_irq_disable(
struct radeon_device *rdev)
2773 evergreen_irq_ack(rdev);
2779 evergreen_irq_disable(rdev);
2787 if (rdev->
wb.enabled)
2797 dev_warn(rdev->
dev,
"IH ring buffer overflow (0x%08X, %d, %d)\n",
2798 wptr, rdev->
ih.rptr, (wptr + 16) + rdev->
ih.ptr_mask);
2799 rdev->
ih.rptr = (wptr + 16) & rdev->
ih.ptr_mask;
2804 return (wptr & rdev->
ih.ptr_mask);
2811 u32 src_id, src_data;
2813 bool queue_hotplug =
false;
2814 bool queue_hdmi =
false;
2819 wptr = evergreen_get_ih_wptr(rdev);
2826 rptr = rdev->
ih.rptr;
2827 DRM_DEBUG(
"r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
2833 evergreen_irq_ack(rdev);
2835 while (rptr != wptr) {
2837 ring_index = rptr / 4;
2839 src_data =
le32_to_cpu(rdev->
ih.ring[ring_index + 1]) & 0xfffffff;
2846 if (rdev->
irq.crtc_vblank_int[0]) {
2848 rdev->
pm.vblank_sync =
true;
2854 DRM_DEBUG(
"IH: D1 vblank\n");
2860 DRM_DEBUG(
"IH: D1 vline\n");
2864 DRM_DEBUG(
"Unhandled interrupt: %d %d\n", src_id, src_data);
2872 if (rdev->
irq.crtc_vblank_int[1]) {
2874 rdev->
pm.vblank_sync =
true;
2880 DRM_DEBUG(
"IH: D2 vblank\n");
2886 DRM_DEBUG(
"IH: D2 vline\n");
2890 DRM_DEBUG(
"Unhandled interrupt: %d %d\n", src_id, src_data);
2898 if (rdev->
irq.crtc_vblank_int[2]) {
2900 rdev->
pm.vblank_sync =
true;
2906 DRM_DEBUG(
"IH: D3 vblank\n");
2912 DRM_DEBUG(
"IH: D3 vline\n");
2916 DRM_DEBUG(
"Unhandled interrupt: %d %d\n", src_id, src_data);
2924 if (rdev->
irq.crtc_vblank_int[3]) {
2926 rdev->
pm.vblank_sync =
true;
2932 DRM_DEBUG(
"IH: D4 vblank\n");
2938 DRM_DEBUG(
"IH: D4 vline\n");
2942 DRM_DEBUG(
"Unhandled interrupt: %d %d\n", src_id, src_data);
2950 if (rdev->
irq.crtc_vblank_int[4]) {
2952 rdev->
pm.vblank_sync =
true;
2958 DRM_DEBUG(
"IH: D5 vblank\n");
2964 DRM_DEBUG(
"IH: D5 vline\n");
2968 DRM_DEBUG(
"Unhandled interrupt: %d %d\n", src_id, src_data);
2976 if (rdev->
irq.crtc_vblank_int[5]) {
2978 rdev->
pm.vblank_sync =
true;
2984 DRM_DEBUG(
"IH: D6 vblank\n");
2990 DRM_DEBUG(
"IH: D6 vline\n");
2994 DRM_DEBUG(
"Unhandled interrupt: %d %d\n", src_id, src_data);
3003 queue_hotplug =
true;
3004 DRM_DEBUG(
"IH: HPD1\n");
3010 queue_hotplug =
true;
3011 DRM_DEBUG(
"IH: HPD2\n");
3017 queue_hotplug =
true;
3018 DRM_DEBUG(
"IH: HPD3\n");
3024 queue_hotplug =
true;
3025 DRM_DEBUG(
"IH: HPD4\n");
3031 queue_hotplug =
true;
3032 DRM_DEBUG(
"IH: HPD5\n");
3038 queue_hotplug =
true;
3039 DRM_DEBUG(
"IH: HPD6\n");
3043 DRM_DEBUG(
"Unhandled interrupt: %d %d\n", src_id, src_data);
3053 DRM_DEBUG(
"IH: HDMI0\n");
3060 DRM_DEBUG(
"IH: HDMI1\n");
3067 DRM_DEBUG(
"IH: HDMI2\n");
3074 DRM_DEBUG(
"IH: HDMI3\n");
3081 DRM_DEBUG(
"IH: HDMI4\n");
3088 DRM_DEBUG(
"IH: HDMI5\n");
3092 DRM_ERROR(
"Unhandled interrupt: %d %d\n", src_id, src_data);
3099 DRM_DEBUG(
"IH: CP int: 0x%08x\n", src_data);
3103 DRM_DEBUG(
"IH: CP EOP\n");
3120 DRM_DEBUG(
"IH: GUI idle\n");
3123 DRM_DEBUG(
"Unhandled interrupt: %d %d\n", src_id, src_data);
3129 rptr &= rdev->
ih.ptr_mask;
3140 wptr = evergreen_get_ih_wptr(rdev);
3159 DRM_ERROR(
"Failed to load firmware!\n");
3165 DRM_ERROR(
"Failed to load MC firmware!\n");
3172 DRM_ERROR(
"Failed to load firmware!\n");
3184 evergreen_agp_enable(rdev);
3186 r = evergreen_pcie_gart_enable(rdev);
3190 evergreen_gpu_init(rdev);
3196 dev_warn(rdev->
dev,
"failed blitter (%d) falling back to memcpy\n", r);
3206 dev_err(rdev->
dev,
"failed initializing CP fences (%d).\n", r);
3213 DRM_ERROR(
"radeon: IH init failed (%d).\n", r);
3224 r = evergreen_cp_load_microcode(rdev);
3227 r = evergreen_cp_resume(rdev);
3233 dev_err(rdev->
dev,
"IB initialization failed (%d).\n", r);
3239 DRM_ERROR(
"radeon: audio init failed\n");
3263 r = evergreen_startup(rdev);
3265 DRM_ERROR(
"evergreen startup failed on resume\n");
3280 ring->
ready =
false;
3283 evergreen_pcie_gart_disable(rdev);
3305 dev_err(rdev->
dev,
"Expecting atombios for evergreen GPU\n");
3319 dev_err(rdev->
dev,
"Card not posted and no BIOS - ignoring\n");
3322 DRM_INFO(
"GPU not posted. posting now...\n");
3357 rdev->
ih.ring_obj =
NULL;
3365 r = evergreen_startup(rdev);
3367 dev_err(rdev->
dev,
"disabling GPU acceleration\n");
3373 evergreen_pcie_gart_fini(rdev);
3383 DRM_ERROR(
"radeon: MC ucode required for NI+.\n");
3400 evergreen_pcie_gart_fini(rdev);
3413 u32 link_width_cntl, speed_cntl,
mask;
3433 if (!(mask & DRM_PCIE_SPEED_50))
3438 DRM_INFO(
"PCIE gen 2 link speeds already enabled\n");
3442 DRM_INFO(
"enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");