31 #include "../../../platform/x86/intel_ips.h"
32 #include <linux/module.h>
34 #define FORCEWAKE_ACK_TIMEOUT_MS 2
57 fbc_ctl &= ~FBC_CTL_EN;
62 DRM_DEBUG_KMS(
"FBC idle timed out\n");
66 DRM_DEBUG_KMS(
"disabled FBC\n");
79 u32 fbc_ctl, fbc_ctl2;
86 cfb_pitch = (cfb_pitch / 64) - 1;
108 DRM_DEBUG_KMS(
"enabled FBC, pitch %d, yoff %d, plane %d, ",
109 cfb_pitch, crtc->
y, intel_crtc->
plane);
112 static bool i8xx_fbc_enabled(
struct drm_device *dev)
119 static void g4x_enable_fbc(
struct drm_crtc *crtc,
unsigned long interval)
128 unsigned long stall_watermark = 200;
143 DRM_DEBUG_KMS(
"enabled fbc on plane %d\n", intel_crtc->
plane);
146 static void g4x_disable_fbc(
struct drm_device *dev)
154 dpfc_ctl &= ~DPFC_CTL_EN;
157 DRM_DEBUG_KMS(
"disabled FBC\n");
161 static bool g4x_fbc_enabled(
struct drm_device *dev)
168 static void sandybridge_blit_fbc_update(
struct drm_device *dev)
188 static void ironlake_enable_fbc(
struct drm_crtc *crtc,
unsigned long interval)
197 unsigned long stall_watermark = 200;
220 sandybridge_blit_fbc_update(dev);
223 DRM_DEBUG_KMS(
"enabled fbc on plane %d\n", intel_crtc->
plane);
226 static void ironlake_disable_fbc(
struct drm_device *dev)
234 dpfc_ctl &= ~DPFC_CTL_EN;
237 DRM_DEBUG_KMS(
"disabled FBC\n");
241 static bool ironlake_fbc_enabled(
struct drm_device *dev)
252 if (!dev_priv->
display.fbc_enabled)
255 return dev_priv->
display.fbc_enabled(dev);
258 static void intel_fbc_work_fn(
struct work_struct *__work)
271 if (work->
crtc->fb == work->
fb) {
292 DRM_DEBUG_KMS(
"cancelling pending FBC enable\n");
316 if (!dev_priv->
display.enable_fbc)
319 intel_cancel_fbc_work(dev_priv);
323 dev_priv->
display.enable_fbc(crtc, interval);
334 DRM_DEBUG_KMS(
"scheduling delayed FBC enable\n");
354 intel_cancel_fbc_work(dev_priv);
356 if (!dev_priv->
display.disable_fbc)
359 dev_priv->
display.disable_fbc(dev);
386 struct intel_crtc *intel_crtc;
408 if (tmp_crtc->enabled &&
412 DRM_DEBUG_KMS(
"more than one pipe active, disabling compression\n");
420 if (!crtc || crtc->
fb ==
NULL) {
421 DRM_DEBUG_KMS(
"no output, disabling\n");
431 enable_fbc = i915_enable_fbc;
432 if (enable_fbc < 0) {
433 DRM_DEBUG_KMS(
"fbc set to per-chip default\n");
439 DRM_DEBUG_KMS(
"fbc disabled per module param\n");
443 if (intel_fb->
obj->base.size > dev_priv->
cfb_size) {
444 DRM_DEBUG_KMS(
"framebuffer too large, disabling "
451 DRM_DEBUG_KMS(
"mode incompatible with compression, "
456 if ((crtc->
mode.hdisplay > 2048) ||
457 (crtc->
mode.vdisplay > 1536)) {
458 DRM_DEBUG_KMS(
"mode too large for compression, disabling\n");
463 DRM_DEBUG_KMS(
"plane not 0, disabling compression\n");
473 DRM_DEBUG_KMS(
"framebuffer not tiled or fenced, disabling compression\n");
489 dev_priv->
cfb_y == crtc->
y)
516 DRM_DEBUG_KMS(
"disabling active FBC for update\n");
526 DRM_DEBUG_KMS(
"unsupported config, disabling FBC\n");
531 static void i915_pineview_get_mem_freq(
struct drm_device *dev)
570 static void i915_ironlake_get_mem_freq(
struct drm_device *dev)
578 switch (ddrpll & 0xff) {
592 DRM_DEBUG_DRIVER(
"unknown memory frequency 0x%02x\n",
600 switch (csipll & 0x3ff) {
623 DRM_DEBUG_DRIVER(
"unknown fsb frequency 0x%04x\n",
630 dev_priv->
ips.c_m = 0;
632 dev_priv->
ips.c_m = 1;
634 dev_priv->
ips.c_m = 2;
638 static const struct cxsr_latency cxsr_latency_table[] = {
639 {1, 0, 800, 400, 3382, 33382, 3983, 33983},
640 {1, 0, 800, 667, 3354, 33354, 3807, 33807},
641 {1, 0, 800, 800, 3347, 33347, 3763, 33763},
642 {1, 1, 800, 667, 6420, 36420, 6873, 36873},
643 {1, 1, 800, 800, 5902, 35902, 6318, 36318},
645 {1, 0, 667, 400, 3400, 33400, 4021, 34021},
646 {1, 0, 667, 667, 3372, 33372, 3845, 33845},
647 {1, 0, 667, 800, 3386, 33386, 3822, 33822},
648 {1, 1, 667, 667, 6438, 36438, 6911, 36911},
649 {1, 1, 667, 800, 5941, 35941, 6377, 36377},
651 {1, 0, 400, 400, 3472, 33472, 4173, 34173},
652 {1, 0, 400, 667, 3443, 33443, 3996, 33996},
653 {1, 0, 400, 800, 3430, 33430, 3946, 33946},
654 {1, 1, 400, 667, 6509, 36509, 7062, 37062},
655 {1, 1, 400, 800, 5985, 35985, 6501, 36501},
657 {0, 0, 800, 400, 3438, 33438, 4065, 34065},
658 {0, 0, 800, 667, 3410, 33410, 3889, 33889},
659 {0, 0, 800, 800, 3403, 33403, 3845, 33845},
660 {0, 1, 800, 667, 6476, 36476, 6955, 36955},
661 {0, 1, 800, 800, 5958, 35958, 6400, 36400},
663 {0, 0, 667, 400, 3456, 33456, 4103, 34106},
664 {0, 0, 667, 667, 3428, 33428, 3927, 33927},
665 {0, 0, 667, 800, 3443, 33443, 3905, 33905},
666 {0, 1, 667, 667, 6494, 36494, 6993, 36993},
667 {0, 1, 667, 800, 5998, 35998, 6460, 36460},
669 {0, 0, 400, 400, 3528, 33528, 4255, 34255},
670 {0, 0, 400, 667, 3500, 33500, 4079, 34079},
671 {0, 0, 400, 800, 3487, 33487, 4029, 34029},
672 {0, 1, 400, 667, 6566, 36566, 7145, 37145},
673 {0, 1, 400, 800, 6042, 36042, 6584, 36584},
684 if (fsb == 0 || mem == 0)
687 for (i = 0; i <
ARRAY_SIZE(cxsr_latency_table); i++) {
688 latency = &cxsr_latency_table[
i];
695 DRM_DEBUG_KMS(
"Unknown FSB/MEM found, disable CxSR\n");
700 static void pineview_disable_cxsr(
struct drm_device *dev)
722 static const int latency_ns = 5000;
724 static int i9xx_get_fifo_size(
struct drm_device *dev,
int plane)
730 size = dsparb & 0x7f;
734 DRM_DEBUG_KMS(
"FIFO size - (0x%08x) %s: %d\n", dsparb,
735 plane ?
"B" :
"A", size);
740 static int i85x_get_fifo_size(
struct drm_device *dev,
int plane)
746 size = dsparb & 0x1ff;
751 DRM_DEBUG_KMS(
"FIFO size - (0x%08x) %s: %d\n", dsparb,
752 plane ?
"B" :
"A", size);
757 static int i845_get_fifo_size(
struct drm_device *dev,
int plane)
763 size = dsparb & 0x7f;
766 DRM_DEBUG_KMS(
"FIFO size - (0x%08x) %s: %d\n", dsparb,
773 static int i830_get_fifo_size(
struct drm_device *dev,
int plane)
779 size = dsparb & 0x7f;
782 DRM_DEBUG_KMS(
"FIFO size - (0x%08x) %s: %d\n", dsparb,
783 plane ?
"B" :
"A", size);
958 static unsigned long intel_calculate_wm(
unsigned long clock_in_khz,
962 unsigned long latency_ns)
964 long entries_required, wm_size;
972 entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) /
976 DRM_DEBUG_KMS(
"FIFO entries required for mode: %ld\n", entries_required);
978 wm_size = fifo_size - (entries_required + wm->
guard_size);
980 DRM_DEBUG_KMS(
"FIFO watermark level: %ld\n", wm_size);
983 if (wm_size > (
long)wm->
max_wm)
1005 static void pineview_update_wm(
struct drm_device *dev)
1016 DRM_DEBUG_KMS(
"Unknown FSB/MEM found, disable CxSR\n");
1017 pineview_disable_cxsr(dev);
1021 crtc = single_enabled_crtc(dev);
1024 int pixel_size = crtc->
fb->bits_per_pixel / 8;
1027 wm = intel_calculate_wm(clock, &pineview_display_wm,
1034 DRM_DEBUG_KMS(
"DSPFW1 register is %x\n", reg);
1037 wm = intel_calculate_wm(clock, &pineview_cursor_wm,
1046 wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm,
1055 wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm,
1062 DRM_DEBUG_KMS(
"DSPFW3 register is %x\n", reg);
1067 DRM_DEBUG_KMS(
"Self-refresh is enabled\n");
1069 pineview_disable_cxsr(dev);
1070 DRM_DEBUG_KMS(
"Self-refresh is disabled\n");
1074 static bool g4x_compute_wm0(
struct drm_device *dev,
1077 int display_latency_ns,
1079 int cursor_latency_ns,
1085 int line_time_us, line_count;
1088 crtc = intel_get_crtc_for_plane(dev, plane);
1095 htotal = crtc->
mode.htotal;
1096 hdisplay = crtc->
mode.hdisplay;
1097 clock = crtc->
mode.clock;
1098 pixel_size = crtc->
fb->bits_per_pixel / 8;
1101 entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000;
1104 entries += tlb_miss;
1107 if (*plane_wm > (
int)display->
max_wm)
1108 *plane_wm = display->
max_wm;
1111 line_time_us = ((htotal * 1000) / clock);
1112 line_count = (cursor_latency_ns / line_time_us + 1000) / 1000;
1116 entries += tlb_miss;
1119 if (*cursor_wm > (
int)cursor->
max_wm)
1132 static bool g4x_check_srwm(
struct drm_device *dev,
1133 int display_wm,
int cursor_wm,
1137 DRM_DEBUG_KMS(
"SR watermark: display plane %d, cursor %d\n",
1138 display_wm, cursor_wm);
1140 if (display_wm > display->
max_wm) {
1141 DRM_DEBUG_KMS(
"display watermark is too large(%d/%ld), disabling\n",
1142 display_wm, display->
max_wm);
1146 if (cursor_wm > cursor->
max_wm) {
1147 DRM_DEBUG_KMS(
"cursor watermark is too large(%d/%ld), disabling\n",
1148 cursor_wm, cursor->
max_wm);
1152 if (!(display_wm || cursor_wm)) {
1153 DRM_DEBUG_KMS(
"SR latency is 0, disabling\n");
1160 static bool g4x_compute_srwm(
struct drm_device *dev,
1165 int *display_wm,
int *cursor_wm)
1169 unsigned long line_time_us;
1170 int line_count, line_size;
1175 *display_wm = *cursor_wm = 0;
1179 crtc = intel_get_crtc_for_plane(dev, plane);
1180 hdisplay = crtc->
mode.hdisplay;
1181 htotal = crtc->
mode.htotal;
1182 clock = crtc->
mode.clock;
1183 pixel_size = crtc->
fb->bits_per_pixel / 8;
1185 line_time_us = (htotal * 1000) / clock;
1186 line_count = (latency_ns / line_time_us + 1000) / 1000;
1190 small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
1191 large = line_count * line_size;
1197 entries = line_count * pixel_size * 64;
1201 return g4x_check_srwm(dev,
1202 *display_wm, *cursor_wm,
1206 static bool vlv_compute_drain_latency(
struct drm_device *dev,
1208 int *plane_prec_mult,
1210 int *cursor_prec_mult,
1217 crtc = intel_get_crtc_for_plane(dev, plane);
1221 clock = crtc->
mode.clock;
1222 pixel_size = crtc->
fb->bits_per_pixel / 8;
1224 entries = (clock / 1000) * pixel_size;
1225 *plane_prec_mult = (entries > 256) ?
1227 *plane_dl = (64 * (*plane_prec_mult) * 4) / ((clock / 1000) *
1230 entries = (clock / 1000) * 4;
1231 *cursor_prec_mult = (entries > 256) ?
1233 *cursor_dl = (64 * (*cursor_prec_mult) * 4) / ((clock / 1000) * 4);
1246 static void vlv_update_drain_latency(
struct drm_device *dev)
1249 int planea_prec, planea_dl, planeb_prec, planeb_dl;
1250 int cursora_prec, cursora_dl, cursorb_prec, cursorb_dl;
1251 int plane_prec_mult, cursor_prec_mult;
1255 if (vlv_compute_drain_latency(dev, 0, &plane_prec_mult, &planea_dl,
1256 &cursor_prec_mult, &cursora_dl)) {
1264 planea_prec | planea_dl);
1268 if (vlv_compute_drain_latency(dev, 1, &plane_prec_mult, &planeb_dl,
1269 &cursor_prec_mult, &cursorb_dl)) {
1277 planeb_prec | planeb_dl);
1281 #define single_plane_enabled(mask) is_power_of_2(mask)
1283 static void valleyview_update_wm(
struct drm_device *dev)
1285 static const int sr_latency_ns = 12000;
1287 int planea_wm, planeb_wm, cursora_wm, cursorb_wm;
1288 int plane_sr, cursor_sr;
1289 unsigned int enabled = 0;
1291 vlv_update_drain_latency(dev);
1293 if (g4x_compute_wm0(dev, 0,
1294 &valleyview_wm_info, latency_ns,
1295 &valleyview_cursor_wm_info, latency_ns,
1296 &planea_wm, &cursora_wm))
1299 if (g4x_compute_wm0(dev, 1,
1300 &valleyview_wm_info, latency_ns,
1301 &valleyview_cursor_wm_info, latency_ns,
1302 &planeb_wm, &cursorb_wm))
1305 plane_sr = cursor_sr = 0;
1307 g4x_compute_srwm(dev,
ffs(enabled) - 1,
1309 &valleyview_wm_info,
1310 &valleyview_cursor_wm_info,
1311 &plane_sr, &cursor_sr))
1317 DRM_DEBUG_KMS(
"Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
1318 planea_wm, cursora_wm,
1319 planeb_wm, cursorb_wm,
1320 plane_sr, cursor_sr);
1334 static void g4x_update_wm(
struct drm_device *dev)
1336 static const int sr_latency_ns = 12000;
1338 int planea_wm, planeb_wm, cursora_wm, cursorb_wm;
1339 int plane_sr, cursor_sr;
1340 unsigned int enabled = 0;
1342 if (g4x_compute_wm0(dev, 0,
1343 &g4x_wm_info, latency_ns,
1344 &g4x_cursor_wm_info, latency_ns,
1345 &planea_wm, &cursora_wm))
1348 if (g4x_compute_wm0(dev, 1,
1349 &g4x_wm_info, latency_ns,
1350 &g4x_cursor_wm_info, latency_ns,
1351 &planeb_wm, &cursorb_wm))
1354 plane_sr = cursor_sr = 0;
1356 g4x_compute_srwm(dev,
ffs(enabled) - 1,
1359 &g4x_cursor_wm_info,
1360 &plane_sr, &cursor_sr))
1366 DRM_DEBUG_KMS(
"Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
1367 planea_wm, cursora_wm,
1368 planeb_wm, cursorb_wm,
1369 plane_sr, cursor_sr);
1385 static void i965_update_wm(
struct drm_device *dev)
1393 crtc = single_enabled_crtc(dev);
1396 static const int sr_latency_ns = 12000;
1397 int clock = crtc->
mode.clock;
1398 int htotal = crtc->
mode.htotal;
1399 int hdisplay = crtc->
mode.hdisplay;
1400 int pixel_size = crtc->
fb->bits_per_pixel / 8;
1401 unsigned long line_time_us;
1404 line_time_us = ((htotal * 1000) / clock);
1407 entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
1408 pixel_size * hdisplay;
1414 DRM_DEBUG_KMS(
"self-refresh entries: %d, wm: %d\n",
1417 entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
1421 cursor_sr = i965_cursor_wm_info.
fifo_size -
1424 if (cursor_sr > i965_cursor_wm_info.
max_wm)
1425 cursor_sr = i965_cursor_wm_info.
max_wm;
1427 DRM_DEBUG_KMS(
"self-refresh watermark: display plane %d "
1428 "cursor %d\n", srwm, cursor_sr);
1439 DRM_DEBUG_KMS(
"Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
1444 (8 << 16) | (8 << 8) | (8 << 0));
1450 static void i9xx_update_wm(
struct drm_device *dev)
1458 int planea_wm, planeb_wm;
1462 wm_info = &i945_wm_info;
1464 wm_info = &i915_wm_info;
1466 wm_info = &i855_wm_info;
1468 fifo_size = dev_priv->
display.get_fifo_size(dev, 0);
1469 crtc = intel_get_crtc_for_plane(dev, 0);
1471 planea_wm = intel_calculate_wm(crtc->
mode.clock,
1473 crtc->
fb->bits_per_pixel / 8,
1479 fifo_size = dev_priv->
display.get_fifo_size(dev, 1);
1480 crtc = intel_get_crtc_for_plane(dev, 1);
1482 planeb_wm = intel_calculate_wm(crtc->
mode.clock,
1484 crtc->
fb->bits_per_pixel / 8,
1486 if (enabled ==
NULL)
1493 DRM_DEBUG_KMS(
"FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
1509 static const int sr_latency_ns = 6000;
1510 int clock = enabled->
mode.clock;
1511 int htotal = enabled->
mode.htotal;
1512 int hdisplay = enabled->
mode.hdisplay;
1513 int pixel_size = enabled->
fb->bits_per_pixel / 8;
1514 unsigned long line_time_us;
1517 line_time_us = (htotal * 1000) / clock;
1520 entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
1521 pixel_size * hdisplay;
1523 DRM_DEBUG_KMS(
"self-refresh entries: %d\n", entries);
1535 DRM_DEBUG_KMS(
"Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
1536 planea_wm, planeb_wm, cwm, srwm);
1538 fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
1539 fwater_hi = (cwm & 0x1f);
1542 fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
1543 fwater_hi = fwater_hi | (1 << 8);
1555 DRM_DEBUG_KMS(
"memory self refresh enabled\n");
1557 DRM_DEBUG_KMS(
"memory self refresh disabled\n");
1561 static void i830_update_wm(
struct drm_device *dev)
1568 crtc = single_enabled_crtc(dev);
1572 planea_wm = intel_calculate_wm(crtc->
mode.clock, &i830_wm_info,
1573 dev_priv->
display.get_fifo_size(dev, 0),
1574 crtc->
fb->bits_per_pixel / 8,
1577 fwater_lo |= (3<<8) | planea_wm;
1579 DRM_DEBUG_KMS(
"Setting FIFO watermarks - A: %d\n", planea_wm);
1584 #define ILK_LP0_PLANE_LATENCY 700
1585 #define ILK_LP0_CURSOR_LATENCY 1300
1595 int fbc_wm,
int display_wm,
int cursor_wm,
1601 DRM_DEBUG_KMS(
"watermark %d: display plane %d, fbc lines %d,"
1602 " cursor %d\n", level, display_wm, fbc_wm, cursor_wm);
1605 DRM_DEBUG_KMS(
"fbc watermark(%d) is too large(%d), disabling wm%d+\n",
1614 if (display_wm > display->
max_wm) {
1615 DRM_DEBUG_KMS(
"display watermark(%d) is too large(%d), disabling wm%d+\n",
1620 if (cursor_wm > cursor->
max_wm) {
1621 DRM_DEBUG_KMS(
"cursor watermark(%d) is too large(%d), disabling wm%d+\n",
1626 if (!(fbc_wm || display_wm || cursor_wm)) {
1627 DRM_DEBUG_KMS(
"latency %d is 0, disabling wm%d+\n", level, level);
1637 static bool ironlake_compute_srwm(
struct drm_device *dev,
int level,
int plane,
1641 int *fbc_wm,
int *display_wm,
int *cursor_wm)
1644 unsigned long line_time_us;
1646 int line_count, line_size;
1651 *fbc_wm = *display_wm = *cursor_wm = 0;
1655 crtc = intel_get_crtc_for_plane(dev, plane);
1656 hdisplay = crtc->
mode.hdisplay;
1657 htotal = crtc->
mode.htotal;
1658 clock = crtc->
mode.clock;
1659 pixel_size = crtc->
fb->bits_per_pixel / 8;
1661 line_time_us = (htotal * 1000) / clock;
1662 line_count = (latency_ns / line_time_us + 1000) / 1000;
1666 small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
1667 large = line_count * line_size;
1676 *fbc_wm =
DIV_ROUND_UP(*display_wm * 64, line_size) + 2;
1679 entries = line_count * pixel_size * 64;
1683 return ironlake_check_srwm(dev, level,
1684 *fbc_wm, *display_wm, *cursor_wm,
1688 static void ironlake_update_wm(
struct drm_device *dev)
1691 int fbc_wm, plane_wm, cursor_wm;
1695 if (g4x_compute_wm0(dev, 0,
1696 &ironlake_display_wm_info,
1698 &ironlake_cursor_wm_info,
1700 &plane_wm, &cursor_wm)) {
1703 DRM_DEBUG_KMS(
"FIFO watermarks For pipe A -"
1704 " plane %d, " "cursor: %d\n",
1705 plane_wm, cursor_wm);
1709 if (g4x_compute_wm0(dev, 1,
1710 &ironlake_display_wm_info,
1712 &ironlake_cursor_wm_info,
1714 &plane_wm, &cursor_wm)) {
1717 DRM_DEBUG_KMS(
"FIFO watermarks For pipe B -"
1718 " plane %d, cursor: %d\n",
1719 plane_wm, cursor_wm);
1733 enabled =
ffs(enabled) - 1;
1736 if (!ironlake_compute_srwm(dev, 1, enabled,
1738 &ironlake_display_srwm_info,
1739 &ironlake_cursor_srwm_info,
1740 &fbc_wm, &plane_wm, &cursor_wm))
1751 if (!ironlake_compute_srwm(dev, 2, enabled,
1753 &ironlake_display_srwm_info,
1754 &ironlake_cursor_srwm_info,
1755 &fbc_wm, &plane_wm, &cursor_wm))
1771 static void sandybridge_update_wm(
struct drm_device *dev)
1776 int fbc_wm, plane_wm, cursor_wm;
1780 if (g4x_compute_wm0(dev, 0,
1781 &sandybridge_display_wm_info, latency,
1782 &sandybridge_cursor_wm_info, latency,
1783 &plane_wm, &cursor_wm)) {
1788 DRM_DEBUG_KMS(
"FIFO watermarks For pipe A -"
1789 " plane %d, " "cursor: %d\n",
1790 plane_wm, cursor_wm);
1794 if (g4x_compute_wm0(dev, 1,
1795 &sandybridge_display_wm_info, latency,
1796 &sandybridge_cursor_wm_info, latency,
1797 &plane_wm, &cursor_wm)) {
1802 DRM_DEBUG_KMS(
"FIFO watermarks For pipe B -"
1803 " plane %d, cursor: %d\n",
1804 plane_wm, cursor_wm);
1809 g4x_compute_wm0(dev, 2,
1810 &sandybridge_display_wm_info, latency,
1811 &sandybridge_cursor_wm_info, latency,
1812 &plane_wm, &cursor_wm)) {
1817 DRM_DEBUG_KMS(
"FIFO watermarks For pipe C -"
1818 " plane %d, cursor: %d\n",
1819 plane_wm, cursor_wm);
1840 enabled =
ffs(enabled) - 1;
1843 if (!ironlake_compute_srwm(dev, 1, enabled,
1845 &sandybridge_display_srwm_info,
1846 &sandybridge_cursor_srwm_info,
1847 &fbc_wm, &plane_wm, &cursor_wm))
1858 if (!ironlake_compute_srwm(dev, 2, enabled,
1860 &sandybridge_display_srwm_info,
1861 &sandybridge_cursor_srwm_info,
1862 &fbc_wm, &plane_wm, &cursor_wm))
1873 if (!ironlake_compute_srwm(dev, 3, enabled,
1875 &sandybridge_display_srwm_info,
1876 &sandybridge_cursor_srwm_info,
1877 &fbc_wm, &plane_wm, &cursor_wm))
1916 sandybridge_compute_sprite_wm(
struct drm_device *dev,
int plane,
1917 uint32_t sprite_width,
int pixel_size,
1919 int display_latency_ns,
int *sprite_wm)
1925 crtc = intel_get_crtc_for_plane(dev, plane);
1931 clock = crtc->
mode.clock;
1934 entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000;
1938 entries += tlb_miss;
1941 if (*sprite_wm > (
int)display->
max_wm)
1942 *sprite_wm = display->
max_wm;
1948 sandybridge_compute_sprite_srwm(
struct drm_device *dev,
int plane,
1949 uint32_t sprite_width,
int pixel_size,
1951 int latency_ns,
int *sprite_wm)
1954 unsigned long line_time_us;
1956 int line_count, line_size;
1965 crtc = intel_get_crtc_for_plane(dev, plane);
1966 clock = crtc->
mode.clock;
1972 line_time_us = (sprite_width * 1000) / clock;
1973 if (!line_time_us) {
1978 line_count = (latency_ns / line_time_us + 1000) / 1000;
1982 small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
1983 large = line_count * line_size;
1988 return *sprite_wm > 0x3ff ?
false :
true;
1991 static void sandybridge_update_sprite_wm(
struct drm_device *dev,
int pipe,
1992 uint32_t sprite_width,
int pixel_size)
2014 ret = sandybridge_compute_sprite_wm(dev, pipe, sprite_width, pixel_size,
2015 &sandybridge_display_wm_info,
2016 latency, &sprite_wm);
2018 DRM_DEBUG_KMS(
"failed to compute sprite wm for pipe %d\n",
2026 DRM_DEBUG_KMS(
"sprite watermarks For pipe %d - %d\n", pipe, sprite_wm);
2029 ret = sandybridge_compute_sprite_srwm(dev, pipe, sprite_width,
2031 &sandybridge_display_srwm_info,
2035 DRM_DEBUG_KMS(
"failed to compute sprite lp1 wm on pipe %d\n",
2045 ret = sandybridge_compute_sprite_srwm(dev, pipe, sprite_width,
2047 &sandybridge_display_srwm_info,
2051 DRM_DEBUG_KMS(
"failed to compute sprite lp2 wm on pipe %d\n",
2057 ret = sandybridge_compute_sprite_srwm(dev, pipe, sprite_width,
2059 &sandybridge_display_srwm_info,
2063 DRM_DEBUG_KMS(
"failed to compute sprite lp3 wm on pipe %d\n",
2106 if (dev_priv->
display.update_wm)
2107 dev_priv->
display.update_wm(dev);
2115 if (dev_priv->
display.update_linetime_wm)
2116 dev_priv->
display.update_linetime_wm(dev, pipe, mode);
2120 uint32_t sprite_width,
int pixel_size)
2124 if (dev_priv->
display.update_sprite_wm)
2125 dev_priv->
display.update_sprite_wm(dev, pipe, sprite_width,
2130 intel_alloc_context_page(
struct drm_device *dev)
2135 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2139 DRM_DEBUG(
"failed to alloc power context, RC6 disabled\n");
2145 DRM_ERROR(
"failed to pin power context: %d\n", ret);
2151 DRM_ERROR(
"failed to set-domain on power context: %d\n", ret);
2160 drm_gem_object_unreference(&ctx->
base);
2183 DRM_DEBUG(
"gpu busy, RCS change rejected\n");
2198 static void ironlake_enable_drps(
struct drm_device *dev)
2204 spin_lock_irq(&mchdev_lock);
2233 dev_priv->
ips.min_delay = fmin;
2236 DRM_DEBUG_DRIVER(
"fmax: %d, fmin: %d, fstart: %d\n",
2237 fmax, fmin, fstart);
2252 DRM_ERROR(
"stuck trying to change perf mode\n");
2263 spin_unlock_irq(&mchdev_lock);
2266 static void ironlake_disable_drps(
struct drm_device *dev)
2271 spin_lock_irq(&mchdev_lock);
2289 spin_unlock_irq(&mchdev_lock);
2303 if (*val >= dev_priv->
rps.max_delay)
2304 *val = dev_priv->
rps.max_delay;
2305 limits |= dev_priv->
rps.max_delay << 24;
2313 if (*val <= dev_priv->
rps.min_delay) {
2314 *val = dev_priv->
rps.min_delay;
2315 limits |= dev_priv->
rps.min_delay << 16;
2324 u32 limits = gen6_rps_limits(dev_priv, &val);
2326 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2330 if (val == dev_priv->
rps.cur_delay)
2345 dev_priv->
rps.cur_delay =
val;
2347 trace_intel_gpu_freq_change(val * 50);
2350 static void gen6_disable_rps(
struct drm_device *dev)
2363 spin_lock_irq(&dev_priv->
rps.lock);
2364 dev_priv->
rps.pm_iir = 0;
2365 spin_unlock_irq(&dev_priv->
rps.lock);
2373 if (i915_enable_rc6 >= 0)
2374 return i915_enable_rc6;
2381 DRM_DEBUG_DRIVER(
"Haswell: only RC6 available\n");
2387 DRM_DEBUG_DRIVER(
"Sandybridge: deep RC6 disabled\n");
2391 DRM_DEBUG_DRIVER(
"RC6 and deep RC6 enabled\n");
2395 static void gen6_enable_rps(
struct drm_device *dev)
2401 u32 pcu_mbox, rc6_mask = 0;
2406 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2418 DRM_ERROR(
"GT fifo had a previous error %x\n", gtfifodbg);
2428 dev_priv->
rps.max_delay = rp_state_cap & 0xff;
2429 dev_priv->
rps.min_delay = (rp_state_cap & 0xff0000) >> 16;
2430 dev_priv->
rps.cur_delay = 0;
2464 DRM_INFO(
"Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n",
2465 (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ?
"on" :
"off",
2483 dev_priv->
rps.max_delay << 24 |
2484 dev_priv->
rps.min_delay << 16);
2502 DRM_ERROR(
"timeout waiting for pcode mailbox to become idle\n");
2510 DRM_ERROR(
"timeout waiting for pcode mailbox to finish\n");
2515 DRM_ERROR(
"timeout waiting for pcode mailbox to become idle\n");
2520 DRM_ERROR(
"timeout waiting for pcode mailbox to finish\n");
2521 if (pcu_mbox & (1<<31)) {
2522 dev_priv->
rps.max_delay = pcu_mbox & 0xff;
2523 DRM_DEBUG_DRIVER(
"overclocking supported, adjusting frequency max to %dMHz\n", pcu_mbox * 50);
2530 spin_lock_irq(&dev_priv->
rps.lock);
2533 spin_unlock_irq(&dev_priv->
rps.lock);
2540 static void gen6_update_ring_freq(
struct drm_device *dev)
2544 int gpu_freq, ia_freq, max_ia_freq;
2547 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2558 max_ia_freq /= 1000;
2565 for (gpu_freq = dev_priv->
rps.max_delay; gpu_freq >= dev_priv->
rps.min_delay;
2567 int diff = dev_priv->
rps.max_delay - gpu_freq;
2573 if (gpu_freq < min_freq)
2585 GEN6_PCODE_READY) == 0, 10)) {
2586 DRM_ERROR(
"pcode write of freq table timed out\n");
2598 drm_gem_object_unreference(&dev_priv->
renderctx->base);
2604 drm_gem_object_unreference(&dev_priv->
pwrctx->base);
2609 static void ironlake_disable_rc6(
struct drm_device *dev)
2627 static int ironlake_setup_rc6(
struct drm_device *dev)
2632 dev_priv->
renderctx = intel_alloc_context_page(dev);
2637 dev_priv->
pwrctx = intel_alloc_context_page(dev);
2646 static void ironlake_enable_rc6(
struct drm_device *dev)
2658 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2660 ret = ironlake_setup_rc6(dev);
2676 intel_ring_emit(ring, dev_priv->
renderctx->gtt_offset |
2682 intel_ring_emit(ring,
MI_NOOP);
2691 ret = intel_wait_ring_idle(ring);
2693 DRM_ERROR(
"failed to enable ironlake power power savings\n");
2702 static unsigned long intel_pxfreq(
u32 vidfreq)
2705 int div = (vidfreq & 0x3f0000) >> 16;
2706 int post = (vidfreq & 0x3000) >> 12;
2707 int pre = (vidfreq & 0x7);
2712 freq = ((div * 133333) / ((1<<post) * pre));
2717 static const struct cparams {
2723 { 1, 1333, 301, 28664 },
2724 { 1, 1066, 294, 24460 },
2725 { 1, 800, 294, 25192 },
2726 { 0, 1333, 276, 27605 },
2727 { 0, 1066, 276, 27605 },
2728 { 0, 800, 231, 23784 },
2733 u64 total_count, diff,
ret;
2740 diff1 = now - dev_priv->
ips.last_time1;
2748 return dev_priv->
ips.chipset_power;
2754 total_count = count1 + count2 +
count3;
2757 if (total_count < dev_priv->ips.last_count1) {
2758 diff = ~0
UL - dev_priv->
ips.last_count1;
2759 diff += total_count;
2761 diff = total_count - dev_priv->
ips.last_count1;
2765 if (cparams[i].i == dev_priv->
ips.c_m &&
2766 cparams[i].t == dev_priv->
ips.r_t) {
2773 diff = div_u64(diff, diff1);
2774 ret = ((m * diff) +
c);
2775 ret = div_u64(ret, 10);
2777 dev_priv->
ips.last_count1 = total_count;
2778 dev_priv->
ips.last_time1 = now;
2780 dev_priv->
ips.chipset_power =
ret;
2789 if (dev_priv->
info->gen != 5)
2794 val = __i915_chipset_val(dev_priv);
2803 unsigned long m,
x,
b;
2813 return ((m * x) / 127) -
b;
2818 static const struct v_table {
2951 if (dev_priv->
info->is_mobile)
2952 return v_table[pxvid].vm;
2954 return v_table[pxvid].vd;
2961 unsigned long diffms;
2967 diff1 = timespec_sub(now, dev_priv->
ips.last_time2);
2970 diffms = diff1.tv_sec * 1000 + diff1.tv_nsec / 1000000;
2976 if (count < dev_priv->ips.last_count2) {
2977 diff = ~0
UL - dev_priv->
ips.last_count2;
2980 diff = count - dev_priv->
ips.last_count2;
2984 dev_priv->
ips.last_time2 = now;
2988 diff = div_u64(diff, diffms * 10);
2989 dev_priv->
ips.gfx_power = diff;
2994 if (dev_priv->
info->gen != 5)
2999 __i915_update_gfx_val(dev_priv);
3012 pxvid = (pxvid >> 24) & 0x7f;
3013 ext_v = pvid_to_extvid(dev_priv, pxvid);
3023 corr = ((t * 2349) + 135940);
3025 corr = ((t * 964) + 29317);
3027 corr = ((t * 301) + 1004);
3029 corr = corr * ((150142 *
state1) / 10000 - 78642);
3031 corr2 = (corr * dev_priv->
ips.corr);
3033 state2 = (corr2 *
state1) / 10000;
3036 __i915_update_gfx_val(dev_priv);
3038 return dev_priv->
ips.gfx_power +
state2;
3045 if (dev_priv->
info->gen != 5)
3050 val = __i915_gfx_val(dev_priv);
3066 unsigned long chipset_val, graphics_val, ret = 0;
3071 dev_priv = i915_mch_dev;
3073 chipset_val = __i915_chipset_val(dev_priv);
3074 graphics_val = __i915_gfx_val(dev_priv);
3076 ret = chipset_val + graphics_val;
3096 if (!i915_mch_dev) {
3100 dev_priv = i915_mch_dev;
3102 if (dev_priv->
ips.max_delay > dev_priv->
ips.fmax)
3103 dev_priv->
ips.max_delay--;
3124 if (!i915_mch_dev) {
3128 dev_priv = i915_mch_dev;
3130 if (dev_priv->
ips.max_delay < dev_priv->
ips.min_delay)
3131 dev_priv->
ips.max_delay++;
3155 dev_priv = i915_mch_dev;
3179 if (!i915_mch_dev) {
3183 dev_priv = i915_mch_dev;
3185 dev_priv->
ips.max_delay = dev_priv->
ips.fstart;
3206 ips_ping_for_i915_load(
void)
3222 i915_mch_dev = dev_priv;
3225 ips_ping_for_i915_load();
3231 i915_mch_dev =
NULL;
3234 static void intel_init_emon(
struct drm_device *dev)
3251 for (i = 0; i < 5; i++)
3253 for (i = 0; i < 3; i++)
3257 for (i = 0; i < 16; i++) {
3259 unsigned long freq = intel_pxfreq(pxvidfreq);
3265 val *= (freq / 1000);
3267 val /= (127*127*900);
3269 DRM_ERROR(
"bad pxval: %ld\n", val);
3276 for (i = 0; i < 4; i++) {
3277 u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) |
3278 (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]);
3294 for (i = 0; i < 8; i++)
3308 ironlake_disable_drps(dev);
3309 ironlake_disable_rc6(dev);
3311 gen6_disable_rps(dev);
3318 ironlake_enable_drps(dev);
3319 ironlake_enable_rc6(dev);
3320 intel_init_emon(dev);
3322 gen6_enable_rps(dev);
3323 gen6_update_ring_freq(dev);
3327 static void ironlake_init_clock_gating(
struct drm_device *dev)
3396 static void gen6_init_clock_gating(
struct drm_device *dev)
3478 static void gen7_setup_fixed_func_scheduler(
struct drm_i915_private *dev_priv)
3490 static void haswell_init_clock_gating(
struct drm_device *dev)
3535 gen7_setup_fixed_func_scheduler(dev_priv);
3552 static void ivybridge_init_clock_gating(
struct drm_device *dev)
3613 gen7_setup_fixed_func_scheduler(dev_priv);
3625 static void valleyview_init_clock_gating(
struct drm_device *dev)
3709 static void g4x_init_clock_gating(
struct drm_device *dev)
3727 static void crestline_init_clock_gating(
struct drm_device *dev)
3738 static void broadwater_init_clock_gating(
struct drm_device *dev)
3750 static void gen3_init_clock_gating(
struct drm_device *dev)
3766 static void i85x_init_clock_gating(
struct drm_device *dev)
3773 static void i830_init_clock_gating(
struct drm_device *dev)
3780 static void ibx_init_clock_gating(
struct drm_device *dev)
3792 static void cpt_init_clock_gating(
struct drm_device *dev)
3814 dev_priv->
display.init_clock_gating(dev);
3816 if (dev_priv->
display.init_pch_clock_gating)
3817 dev_priv->
display.init_pch_clock_gating(dev);
3826 unsigned long power_wells[] = {
3838 for (i = 0; i <
ARRAY_SIZE(power_wells); i++) {
3844 DRM_ERROR(
"Error enabling power well %lx\n", power_wells[i]);
3858 dev_priv->
display.fbc_enabled = ironlake_fbc_enabled;
3859 dev_priv->
display.enable_fbc = ironlake_enable_fbc;
3860 dev_priv->
display.disable_fbc = ironlake_disable_fbc;
3862 dev_priv->
display.fbc_enabled = g4x_fbc_enabled;
3863 dev_priv->
display.enable_fbc = g4x_enable_fbc;
3864 dev_priv->
display.disable_fbc = g4x_disable_fbc;
3866 dev_priv->
display.fbc_enabled = i8xx_fbc_enabled;
3867 dev_priv->
display.enable_fbc = i8xx_enable_fbc;
3868 dev_priv->
display.disable_fbc = i8xx_disable_fbc;
3875 i915_pineview_get_mem_freq(dev);
3877 i915_ironlake_get_mem_freq(dev);
3882 dev_priv->
display.init_pch_clock_gating = ibx_init_clock_gating;
3884 dev_priv->
display.init_pch_clock_gating = cpt_init_clock_gating;
3888 dev_priv->
display.update_wm = ironlake_update_wm;
3890 DRM_DEBUG_KMS(
"Failed to get proper latency. "
3894 dev_priv->
display.init_clock_gating = ironlake_init_clock_gating;
3897 dev_priv->
display.update_wm = sandybridge_update_wm;
3898 dev_priv->
display.update_sprite_wm = sandybridge_update_sprite_wm;
3900 DRM_DEBUG_KMS(
"Failed to read display plane latency. "
3904 dev_priv->
display.init_clock_gating = gen6_init_clock_gating;
3908 dev_priv->
display.update_wm = sandybridge_update_wm;
3909 dev_priv->
display.update_sprite_wm = sandybridge_update_sprite_wm;
3911 DRM_DEBUG_KMS(
"Failed to read display plane latency. "
3915 dev_priv->
display.init_clock_gating = ivybridge_init_clock_gating;
3918 dev_priv->
display.update_wm = sandybridge_update_wm;
3919 dev_priv->
display.update_sprite_wm = sandybridge_update_sprite_wm;
3920 dev_priv->
display.update_linetime_wm = haswell_update_linetime_wm;
3922 DRM_DEBUG_KMS(
"Failed to read display plane latency. "
3926 dev_priv->
display.init_clock_gating = haswell_init_clock_gating;
3930 dev_priv->
display.update_wm = valleyview_update_wm;
3931 dev_priv->
display.init_clock_gating =
3932 valleyview_init_clock_gating;
3938 DRM_INFO(
"failed to find known CxSR latency "
3939 "(found ddr%s fsb freq %d, mem freq %d), "
3941 (dev_priv->
is_ddr3 == 1) ?
"3" :
"2",
3944 pineview_disable_cxsr(dev);
3947 dev_priv->
display.update_wm = pineview_update_wm;
3948 dev_priv->
display.init_clock_gating = gen3_init_clock_gating;
3949 }
else if (
IS_G4X(dev)) {
3950 dev_priv->
display.update_wm = g4x_update_wm;
3951 dev_priv->
display.init_clock_gating = g4x_init_clock_gating;
3953 dev_priv->
display.update_wm = i965_update_wm;
3955 dev_priv->
display.init_clock_gating = crestline_init_clock_gating;
3957 dev_priv->
display.init_clock_gating = broadwater_init_clock_gating;
3959 dev_priv->
display.update_wm = i9xx_update_wm;
3960 dev_priv->
display.get_fifo_size = i9xx_get_fifo_size;
3961 dev_priv->
display.init_clock_gating = gen3_init_clock_gating;
3963 dev_priv->
display.update_wm = i830_update_wm;
3964 dev_priv->
display.init_clock_gating = i85x_init_clock_gating;
3965 dev_priv->
display.get_fifo_size = i830_get_fifo_size;
3967 dev_priv->
display.update_wm = i9xx_update_wm;
3968 dev_priv->
display.get_fifo_size = i85x_get_fifo_size;
3969 dev_priv->
display.init_clock_gating = i85x_init_clock_gating;
3971 dev_priv->
display.update_wm = i830_update_wm;
3972 dev_priv->
display.init_clock_gating = i830_init_clock_gating;
3974 dev_priv->
display.get_fifo_size = i845_get_fifo_size;
3976 dev_priv->
display.get_fifo_size = i830_get_fifo_size;
3980 static void __gen6_gt_wait_for_thread_c0(
struct drm_i915_private *dev_priv)
3982 u32 gt_thread_status_mask;
3993 DRM_ERROR(
"GT thread status wait timed out\n");
4007 DRM_ERROR(
"Timed out waiting for forcewake old ack to clear.\n");
4014 DRM_ERROR(
"Timed out waiting for forcewake to ack request.\n");
4016 __gen6_gt_wait_for_thread_c0(dev_priv);
4030 DRM_ERROR(
"Timed out waiting for forcewake old ack to clear.\n");
4037 DRM_ERROR(
"Timed out waiting for forcewake to ack request.\n");
4039 __gen6_gt_wait_for_thread_c0(dev_priv);
4050 unsigned long irqflags;
4054 dev_priv->
gt.force_wake_get(dev_priv);
4055 spin_unlock_irqrestore(&dev_priv->
gt_lock, irqflags);
4063 "MMIO read or write has been dropped %x\n", gtfifodbg))
4086 unsigned long irqflags;
4090 dev_priv->
gt.force_wake_put(dev_priv);
4091 spin_unlock_irqrestore(&dev_priv->
gt_lock, irqflags);
4118 DRM_ERROR(
"Timed out waiting for forcewake old ack to clear.\n");
4124 DRM_ERROR(
"Timed out waiting for forcewake to ack request.\n");
4126 __gen6_gt_wait_for_thread_c0(dev_priv);
4143 dev_priv->
gt.force_wake_get = vlv_force_wake_get;
4144 dev_priv->
gt.force_wake_put = vlv_force_wake_put;
4146 dev_priv->
gt.force_wake_get = __gen6_gt_force_wake_get;
4147 dev_priv->
gt.force_wake_put = __gen6_gt_force_wake_put;
4161 __gen6_gt_force_wake_mt_get(dev_priv);
4163 __gen6_gt_force_wake_mt_put(dev_priv);
4167 DRM_DEBUG_KMS(
"Using MT version of forcewake\n");
4168 dev_priv->
gt.force_wake_get =
4169 __gen6_gt_force_wake_mt_get;
4170 dev_priv->
gt.force_wake_put =
4171 __gen6_gt_force_wake_mt_put;