diff options
Diffstat (limited to 'drivers/gpu/drm/i915/intel_display.c')
-rw-r--r-- | drivers/gpu/drm/i915/intel_display.c | 699 |
1 files changed, 515 insertions, 184 deletions
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 21b6f93fe919..b5b15bda71d9 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c | |||
@@ -24,6 +24,7 @@ | |||
24 | * Eric Anholt <eric@anholt.net> | 24 | * Eric Anholt <eric@anholt.net> |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include <linux/cpufreq.h> | ||
27 | #include <linux/module.h> | 28 | #include <linux/module.h> |
28 | #include <linux/input.h> | 29 | #include <linux/input.h> |
29 | #include <linux/i2c.h> | 30 | #include <linux/i2c.h> |
@@ -1157,12 +1158,15 @@ static void intel_enable_transcoder(struct drm_i915_private *dev_priv, | |||
1157 | 1158 | ||
1158 | reg = TRANSCONF(pipe); | 1159 | reg = TRANSCONF(pipe); |
1159 | val = I915_READ(reg); | 1160 | val = I915_READ(reg); |
1160 | /* | 1161 | |
1161 | * make the BPC in transcoder be consistent with | 1162 | if (HAS_PCH_IBX(dev_priv->dev)) { |
1162 | * that in pipeconf reg. | 1163 | /* |
1163 | */ | 1164 | * make the BPC in transcoder be consistent with |
1164 | val &= ~PIPE_BPC_MASK; | 1165 | * that in pipeconf reg. |
1165 | val |= I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK; | 1166 | */ |
1167 | val &= ~PIPE_BPC_MASK; | ||
1168 | val |= I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK; | ||
1169 | } | ||
1166 | I915_WRITE(reg, val | TRANS_ENABLE); | 1170 | I915_WRITE(reg, val | TRANS_ENABLE); |
1167 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) | 1171 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
1168 | DRM_ERROR("failed to enable transcoder %d\n", pipe); | 1172 | DRM_ERROR("failed to enable transcoder %d\n", pipe); |
@@ -1380,6 +1384,28 @@ static void intel_disable_pch_ports(struct drm_i915_private *dev_priv, | |||
1380 | disable_pch_hdmi(dev_priv, pipe, HDMID); | 1384 | disable_pch_hdmi(dev_priv, pipe, HDMID); |
1381 | } | 1385 | } |
1382 | 1386 | ||
1387 | static void i8xx_disable_fbc(struct drm_device *dev) | ||
1388 | { | ||
1389 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
1390 | u32 fbc_ctl; | ||
1391 | |||
1392 | /* Disable compression */ | ||
1393 | fbc_ctl = I915_READ(FBC_CONTROL); | ||
1394 | if ((fbc_ctl & FBC_CTL_EN) == 0) | ||
1395 | return; | ||
1396 | |||
1397 | fbc_ctl &= ~FBC_CTL_EN; | ||
1398 | I915_WRITE(FBC_CONTROL, fbc_ctl); | ||
1399 | |||
1400 | /* Wait for compressing bit to clear */ | ||
1401 | if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) { | ||
1402 | DRM_DEBUG_KMS("FBC idle timed out\n"); | ||
1403 | return; | ||
1404 | } | ||
1405 | |||
1406 | DRM_DEBUG_KMS("disabled FBC\n"); | ||
1407 | } | ||
1408 | |||
1383 | static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval) | 1409 | static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval) |
1384 | { | 1410 | { |
1385 | struct drm_device *dev = crtc->dev; | 1411 | struct drm_device *dev = crtc->dev; |
@@ -1388,36 +1414,25 @@ static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval) | |||
1388 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | 1414 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
1389 | struct drm_i915_gem_object *obj = intel_fb->obj; | 1415 | struct drm_i915_gem_object *obj = intel_fb->obj; |
1390 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | 1416 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
1417 | int cfb_pitch; | ||
1391 | int plane, i; | 1418 | int plane, i; |
1392 | u32 fbc_ctl, fbc_ctl2; | 1419 | u32 fbc_ctl, fbc_ctl2; |
1393 | 1420 | ||
1394 | if (fb->pitch == dev_priv->cfb_pitch && | 1421 | cfb_pitch = dev_priv->cfb_size / FBC_LL_SIZE; |
1395 | obj->fence_reg == dev_priv->cfb_fence && | 1422 | if (fb->pitch < cfb_pitch) |
1396 | intel_crtc->plane == dev_priv->cfb_plane && | 1423 | cfb_pitch = fb->pitch; |
1397 | I915_READ(FBC_CONTROL) & FBC_CTL_EN) | ||
1398 | return; | ||
1399 | |||
1400 | i8xx_disable_fbc(dev); | ||
1401 | |||
1402 | dev_priv->cfb_pitch = dev_priv->cfb_size / FBC_LL_SIZE; | ||
1403 | |||
1404 | if (fb->pitch < dev_priv->cfb_pitch) | ||
1405 | dev_priv->cfb_pitch = fb->pitch; | ||
1406 | 1424 | ||
1407 | /* FBC_CTL wants 64B units */ | 1425 | /* FBC_CTL wants 64B units */ |
1408 | dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1; | 1426 | cfb_pitch = (cfb_pitch / 64) - 1; |
1409 | dev_priv->cfb_fence = obj->fence_reg; | 1427 | plane = intel_crtc->plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB; |
1410 | dev_priv->cfb_plane = intel_crtc->plane; | ||
1411 | plane = dev_priv->cfb_plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB; | ||
1412 | 1428 | ||
1413 | /* Clear old tags */ | 1429 | /* Clear old tags */ |
1414 | for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++) | 1430 | for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++) |
1415 | I915_WRITE(FBC_TAG + (i * 4), 0); | 1431 | I915_WRITE(FBC_TAG + (i * 4), 0); |
1416 | 1432 | ||
1417 | /* Set it up... */ | 1433 | /* Set it up... */ |
1418 | fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | plane; | 1434 | fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | FBC_CTL_CPU_FENCE; |
1419 | if (obj->tiling_mode != I915_TILING_NONE) | 1435 | fbc_ctl2 |= plane; |
1420 | fbc_ctl2 |= FBC_CTL_CPU_FENCE; | ||
1421 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); | 1436 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); |
1422 | I915_WRITE(FBC_FENCE_OFF, crtc->y); | 1437 | I915_WRITE(FBC_FENCE_OFF, crtc->y); |
1423 | 1438 | ||
@@ -1425,36 +1440,13 @@ static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval) | |||
1425 | fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC; | 1440 | fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC; |
1426 | if (IS_I945GM(dev)) | 1441 | if (IS_I945GM(dev)) |
1427 | fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ | 1442 | fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ |
1428 | fbc_ctl |= (dev_priv->cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; | 1443 | fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; |
1429 | fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT; | 1444 | fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT; |
1430 | if (obj->tiling_mode != I915_TILING_NONE) | 1445 | fbc_ctl |= obj->fence_reg; |
1431 | fbc_ctl |= dev_priv->cfb_fence; | ||
1432 | I915_WRITE(FBC_CONTROL, fbc_ctl); | ||
1433 | |||
1434 | DRM_DEBUG_KMS("enabled FBC, pitch %ld, yoff %d, plane %d, ", | ||
1435 | dev_priv->cfb_pitch, crtc->y, dev_priv->cfb_plane); | ||
1436 | } | ||
1437 | |||
1438 | void i8xx_disable_fbc(struct drm_device *dev) | ||
1439 | { | ||
1440 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
1441 | u32 fbc_ctl; | ||
1442 | |||
1443 | /* Disable compression */ | ||
1444 | fbc_ctl = I915_READ(FBC_CONTROL); | ||
1445 | if ((fbc_ctl & FBC_CTL_EN) == 0) | ||
1446 | return; | ||
1447 | |||
1448 | fbc_ctl &= ~FBC_CTL_EN; | ||
1449 | I915_WRITE(FBC_CONTROL, fbc_ctl); | 1446 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
1450 | 1447 | ||
1451 | /* Wait for compressing bit to clear */ | 1448 | DRM_DEBUG_KMS("enabled FBC, pitch %d, yoff %d, plane %d, ", |
1452 | if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) { | 1449 | cfb_pitch, crtc->y, intel_crtc->plane); |
1453 | DRM_DEBUG_KMS("FBC idle timed out\n"); | ||
1454 | return; | ||
1455 | } | ||
1456 | |||
1457 | DRM_DEBUG_KMS("disabled FBC\n"); | ||
1458 | } | 1450 | } |
1459 | 1451 | ||
1460 | static bool i8xx_fbc_enabled(struct drm_device *dev) | 1452 | static bool i8xx_fbc_enabled(struct drm_device *dev) |
@@ -1476,30 +1468,9 @@ static void g4x_enable_fbc(struct drm_crtc *crtc, unsigned long interval) | |||
1476 | unsigned long stall_watermark = 200; | 1468 | unsigned long stall_watermark = 200; |
1477 | u32 dpfc_ctl; | 1469 | u32 dpfc_ctl; |
1478 | 1470 | ||
1479 | dpfc_ctl = I915_READ(DPFC_CONTROL); | ||
1480 | if (dpfc_ctl & DPFC_CTL_EN) { | ||
1481 | if (dev_priv->cfb_pitch == dev_priv->cfb_pitch / 64 - 1 && | ||
1482 | dev_priv->cfb_fence == obj->fence_reg && | ||
1483 | dev_priv->cfb_plane == intel_crtc->plane && | ||
1484 | dev_priv->cfb_y == crtc->y) | ||
1485 | return; | ||
1486 | |||
1487 | I915_WRITE(DPFC_CONTROL, dpfc_ctl & ~DPFC_CTL_EN); | ||
1488 | intel_wait_for_vblank(dev, intel_crtc->pipe); | ||
1489 | } | ||
1490 | |||
1491 | dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1; | ||
1492 | dev_priv->cfb_fence = obj->fence_reg; | ||
1493 | dev_priv->cfb_plane = intel_crtc->plane; | ||
1494 | dev_priv->cfb_y = crtc->y; | ||
1495 | |||
1496 | dpfc_ctl = plane | DPFC_SR_EN | DPFC_CTL_LIMIT_1X; | 1471 | dpfc_ctl = plane | DPFC_SR_EN | DPFC_CTL_LIMIT_1X; |
1497 | if (obj->tiling_mode != I915_TILING_NONE) { | 1472 | dpfc_ctl |= DPFC_CTL_FENCE_EN | obj->fence_reg; |
1498 | dpfc_ctl |= DPFC_CTL_FENCE_EN | dev_priv->cfb_fence; | 1473 | I915_WRITE(DPFC_CHICKEN, DPFC_HT_MODIFY); |
1499 | I915_WRITE(DPFC_CHICKEN, DPFC_HT_MODIFY); | ||
1500 | } else { | ||
1501 | I915_WRITE(DPFC_CHICKEN, ~DPFC_HT_MODIFY); | ||
1502 | } | ||
1503 | 1474 | ||
1504 | I915_WRITE(DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN | | 1475 | I915_WRITE(DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN | |
1505 | (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) | | 1476 | (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) | |
@@ -1512,7 +1483,7 @@ static void g4x_enable_fbc(struct drm_crtc *crtc, unsigned long interval) | |||
1512 | DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane); | 1483 | DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane); |
1513 | } | 1484 | } |
1514 | 1485 | ||
1515 | void g4x_disable_fbc(struct drm_device *dev) | 1486 | static void g4x_disable_fbc(struct drm_device *dev) |
1516 | { | 1487 | { |
1517 | struct drm_i915_private *dev_priv = dev->dev_private; | 1488 | struct drm_i915_private *dev_priv = dev->dev_private; |
1518 | u32 dpfc_ctl; | 1489 | u32 dpfc_ctl; |
@@ -1567,32 +1538,12 @@ static void ironlake_enable_fbc(struct drm_crtc *crtc, unsigned long interval) | |||
1567 | u32 dpfc_ctl; | 1538 | u32 dpfc_ctl; |
1568 | 1539 | ||
1569 | dpfc_ctl = I915_READ(ILK_DPFC_CONTROL); | 1540 | dpfc_ctl = I915_READ(ILK_DPFC_CONTROL); |
1570 | if (dpfc_ctl & DPFC_CTL_EN) { | ||
1571 | if (dev_priv->cfb_pitch == dev_priv->cfb_pitch / 64 - 1 && | ||
1572 | dev_priv->cfb_fence == obj->fence_reg && | ||
1573 | dev_priv->cfb_plane == intel_crtc->plane && | ||
1574 | dev_priv->cfb_offset == obj->gtt_offset && | ||
1575 | dev_priv->cfb_y == crtc->y) | ||
1576 | return; | ||
1577 | |||
1578 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl & ~DPFC_CTL_EN); | ||
1579 | intel_wait_for_vblank(dev, intel_crtc->pipe); | ||
1580 | } | ||
1581 | |||
1582 | dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1; | ||
1583 | dev_priv->cfb_fence = obj->fence_reg; | ||
1584 | dev_priv->cfb_plane = intel_crtc->plane; | ||
1585 | dev_priv->cfb_offset = obj->gtt_offset; | ||
1586 | dev_priv->cfb_y = crtc->y; | ||
1587 | |||
1588 | dpfc_ctl &= DPFC_RESERVED; | 1541 | dpfc_ctl &= DPFC_RESERVED; |
1589 | dpfc_ctl |= (plane | DPFC_CTL_LIMIT_1X); | 1542 | dpfc_ctl |= (plane | DPFC_CTL_LIMIT_1X); |
1590 | if (obj->tiling_mode != I915_TILING_NONE) { | 1543 | /* Set persistent mode for front-buffer rendering, ala X. */ |
1591 | dpfc_ctl |= (DPFC_CTL_FENCE_EN | dev_priv->cfb_fence); | 1544 | dpfc_ctl |= DPFC_CTL_PERSISTENT_MODE; |
1592 | I915_WRITE(ILK_DPFC_CHICKEN, DPFC_HT_MODIFY); | 1545 | dpfc_ctl |= (DPFC_CTL_FENCE_EN | obj->fence_reg); |
1593 | } else { | 1546 | I915_WRITE(ILK_DPFC_CHICKEN, DPFC_HT_MODIFY); |
1594 | I915_WRITE(ILK_DPFC_CHICKEN, ~DPFC_HT_MODIFY); | ||
1595 | } | ||
1596 | 1547 | ||
1597 | I915_WRITE(ILK_DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN | | 1548 | I915_WRITE(ILK_DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN | |
1598 | (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) | | 1549 | (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) | |
@@ -1604,7 +1555,7 @@ static void ironlake_enable_fbc(struct drm_crtc *crtc, unsigned long interval) | |||
1604 | 1555 | ||
1605 | if (IS_GEN6(dev)) { | 1556 | if (IS_GEN6(dev)) { |
1606 | I915_WRITE(SNB_DPFC_CTL_SA, | 1557 | I915_WRITE(SNB_DPFC_CTL_SA, |
1607 | SNB_CPU_FENCE_ENABLE | dev_priv->cfb_fence); | 1558 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
1608 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); | 1559 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
1609 | sandybridge_blit_fbc_update(dev); | 1560 | sandybridge_blit_fbc_update(dev); |
1610 | } | 1561 | } |
@@ -1612,7 +1563,7 @@ static void ironlake_enable_fbc(struct drm_crtc *crtc, unsigned long interval) | |||
1612 | DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane); | 1563 | DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane); |
1613 | } | 1564 | } |
1614 | 1565 | ||
1615 | void ironlake_disable_fbc(struct drm_device *dev) | 1566 | static void ironlake_disable_fbc(struct drm_device *dev) |
1616 | { | 1567 | { |
1617 | struct drm_i915_private *dev_priv = dev->dev_private; | 1568 | struct drm_i915_private *dev_priv = dev->dev_private; |
1618 | u32 dpfc_ctl; | 1569 | u32 dpfc_ctl; |
@@ -1644,24 +1595,109 @@ bool intel_fbc_enabled(struct drm_device *dev) | |||
1644 | return dev_priv->display.fbc_enabled(dev); | 1595 | return dev_priv->display.fbc_enabled(dev); |
1645 | } | 1596 | } |
1646 | 1597 | ||
1647 | void intel_enable_fbc(struct drm_crtc *crtc, unsigned long interval) | 1598 | static void intel_fbc_work_fn(struct work_struct *__work) |
1648 | { | 1599 | { |
1649 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; | 1600 | struct intel_fbc_work *work = |
1601 | container_of(to_delayed_work(__work), | ||
1602 | struct intel_fbc_work, work); | ||
1603 | struct drm_device *dev = work->crtc->dev; | ||
1604 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
1605 | |||
1606 | mutex_lock(&dev->struct_mutex); | ||
1607 | if (work == dev_priv->fbc_work) { | ||
1608 | /* Double check that we haven't switched fb without cancelling | ||
1609 | * the prior work. | ||
1610 | */ | ||
1611 | if (work->crtc->fb == work->fb) { | ||
1612 | dev_priv->display.enable_fbc(work->crtc, | ||
1613 | work->interval); | ||
1614 | |||
1615 | dev_priv->cfb_plane = to_intel_crtc(work->crtc)->plane; | ||
1616 | dev_priv->cfb_fb = work->crtc->fb->base.id; | ||
1617 | dev_priv->cfb_y = work->crtc->y; | ||
1618 | } | ||
1619 | |||
1620 | dev_priv->fbc_work = NULL; | ||
1621 | } | ||
1622 | mutex_unlock(&dev->struct_mutex); | ||
1623 | |||
1624 | kfree(work); | ||
1625 | } | ||
1626 | |||
1627 | static void intel_cancel_fbc_work(struct drm_i915_private *dev_priv) | ||
1628 | { | ||
1629 | if (dev_priv->fbc_work == NULL) | ||
1630 | return; | ||
1631 | |||
1632 | DRM_DEBUG_KMS("cancelling pending FBC enable\n"); | ||
1633 | |||
1634 | /* Synchronisation is provided by struct_mutex and checking of | ||
1635 | * dev_priv->fbc_work, so we can perform the cancellation | ||
1636 | * entirely asynchronously. | ||
1637 | */ | ||
1638 | if (cancel_delayed_work(&dev_priv->fbc_work->work)) | ||
1639 | /* tasklet was killed before being run, clean up */ | ||
1640 | kfree(dev_priv->fbc_work); | ||
1641 | |||
1642 | /* Mark the work as no longer wanted so that if it does | ||
1643 | * wake-up (because the work was already running and waiting | ||
1644 | * for our mutex), it will discover that is no longer | ||
1645 | * necessary to run. | ||
1646 | */ | ||
1647 | dev_priv->fbc_work = NULL; | ||
1648 | } | ||
1649 | |||
1650 | static void intel_enable_fbc(struct drm_crtc *crtc, unsigned long interval) | ||
1651 | { | ||
1652 | struct intel_fbc_work *work; | ||
1653 | struct drm_device *dev = crtc->dev; | ||
1654 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
1650 | 1655 | ||
1651 | if (!dev_priv->display.enable_fbc) | 1656 | if (!dev_priv->display.enable_fbc) |
1652 | return; | 1657 | return; |
1653 | 1658 | ||
1654 | dev_priv->display.enable_fbc(crtc, interval); | 1659 | intel_cancel_fbc_work(dev_priv); |
1660 | |||
1661 | work = kzalloc(sizeof *work, GFP_KERNEL); | ||
1662 | if (work == NULL) { | ||
1663 | dev_priv->display.enable_fbc(crtc, interval); | ||
1664 | return; | ||
1665 | } | ||
1666 | |||
1667 | work->crtc = crtc; | ||
1668 | work->fb = crtc->fb; | ||
1669 | work->interval = interval; | ||
1670 | INIT_DELAYED_WORK(&work->work, intel_fbc_work_fn); | ||
1671 | |||
1672 | dev_priv->fbc_work = work; | ||
1673 | |||
1674 | DRM_DEBUG_KMS("scheduling delayed FBC enable\n"); | ||
1675 | |||
1676 | /* Delay the actual enabling to let pageflipping cease and the | ||
1677 | * display to settle before starting the compression. Note that | ||
1678 | * this delay also serves a second purpose: it allows for a | ||
1679 | * vblank to pass after disabling the FBC before we attempt | ||
1680 | * to modify the control registers. | ||
1681 | * | ||
1682 | * A more complicated solution would involve tracking vblanks | ||
1683 | * following the termination of the page-flipping sequence | ||
1684 | * and indeed performing the enable as a co-routine and not | ||
1685 | * waiting synchronously upon the vblank. | ||
1686 | */ | ||
1687 | schedule_delayed_work(&work->work, msecs_to_jiffies(50)); | ||
1655 | } | 1688 | } |
1656 | 1689 | ||
1657 | void intel_disable_fbc(struct drm_device *dev) | 1690 | void intel_disable_fbc(struct drm_device *dev) |
1658 | { | 1691 | { |
1659 | struct drm_i915_private *dev_priv = dev->dev_private; | 1692 | struct drm_i915_private *dev_priv = dev->dev_private; |
1660 | 1693 | ||
1694 | intel_cancel_fbc_work(dev_priv); | ||
1695 | |||
1661 | if (!dev_priv->display.disable_fbc) | 1696 | if (!dev_priv->display.disable_fbc) |
1662 | return; | 1697 | return; |
1663 | 1698 | ||
1664 | dev_priv->display.disable_fbc(dev); | 1699 | dev_priv->display.disable_fbc(dev); |
1700 | dev_priv->cfb_plane = -1; | ||
1665 | } | 1701 | } |
1666 | 1702 | ||
1667 | /** | 1703 | /** |
@@ -1760,8 +1796,13 @@ static void intel_update_fbc(struct drm_device *dev) | |||
1760 | dev_priv->no_fbc_reason = FBC_BAD_PLANE; | 1796 | dev_priv->no_fbc_reason = FBC_BAD_PLANE; |
1761 | goto out_disable; | 1797 | goto out_disable; |
1762 | } | 1798 | } |
1763 | if (obj->tiling_mode != I915_TILING_X) { | 1799 | |
1764 | DRM_DEBUG_KMS("framebuffer not tiled, disabling compression\n"); | 1800 | /* The use of a CPU fence is mandatory in order to detect writes |
1801 | * by the CPU to the scanout and trigger updates to the FBC. | ||
1802 | */ | ||
1803 | if (obj->tiling_mode != I915_TILING_X || | ||
1804 | obj->fence_reg == I915_FENCE_REG_NONE) { | ||
1805 | DRM_DEBUG_KMS("framebuffer not tiled or fenced, disabling compression\n"); | ||
1765 | dev_priv->no_fbc_reason = FBC_NOT_TILED; | 1806 | dev_priv->no_fbc_reason = FBC_NOT_TILED; |
1766 | goto out_disable; | 1807 | goto out_disable; |
1767 | } | 1808 | } |
@@ -1770,6 +1811,44 @@ static void intel_update_fbc(struct drm_device *dev) | |||
1770 | if (in_dbg_master()) | 1811 | if (in_dbg_master()) |
1771 | goto out_disable; | 1812 | goto out_disable; |
1772 | 1813 | ||
1814 | /* If the scanout has not changed, don't modify the FBC settings. | ||
1815 | * Note that we make the fundamental assumption that the fb->obj | ||
1816 | * cannot be unpinned (and have its GTT offset and fence revoked) | ||
1817 | * without first being decoupled from the scanout and FBC disabled. | ||
1818 | */ | ||
1819 | if (dev_priv->cfb_plane == intel_crtc->plane && | ||
1820 | dev_priv->cfb_fb == fb->base.id && | ||
1821 | dev_priv->cfb_y == crtc->y) | ||
1822 | return; | ||
1823 | |||
1824 | if (intel_fbc_enabled(dev)) { | ||
1825 | /* We update FBC along two paths, after changing fb/crtc | ||
1826 | * configuration (modeswitching) and after page-flipping | ||
1827 | * finishes. For the latter, we know that not only did | ||
1828 | * we disable the FBC at the start of the page-flip | ||
1829 | * sequence, but also more than one vblank has passed. | ||
1830 | * | ||
1831 | * For the former case of modeswitching, it is possible | ||
1832 | * to switch between two FBC valid configurations | ||
1833 | * instantaneously so we do need to disable the FBC | ||
1834 | * before we can modify its control registers. We also | ||
1835 | * have to wait for the next vblank for that to take | ||
1836 | * effect. However, since we delay enabling FBC we can | ||
1837 | * assume that a vblank has passed since disabling and | ||
1838 | * that we can safely alter the registers in the deferred | ||
1839 | * callback. | ||
1840 | * | ||
1841 | * In the scenario that we go from a valid to invalid | ||
1842 | * and then back to valid FBC configuration we have | ||
1843 | * no strict enforcement that a vblank occurred since | ||
1844 | * disabling the FBC. However, along all current pipe | ||
1845 | * disabling paths we do need to wait for a vblank at | ||
1846 | * some point. And we wait before enabling FBC anyway. | ||
1847 | */ | ||
1848 | DRM_DEBUG_KMS("disabling active FBC for update\n"); | ||
1849 | intel_disable_fbc(dev); | ||
1850 | } | ||
1851 | |||
1773 | intel_enable_fbc(crtc, 500); | 1852 | intel_enable_fbc(crtc, 500); |
1774 | return; | 1853 | return; |
1775 | 1854 | ||
@@ -1812,14 +1891,10 @@ intel_pin_and_fence_fb_obj(struct drm_device *dev, | |||
1812 | } | 1891 | } |
1813 | 1892 | ||
1814 | dev_priv->mm.interruptible = false; | 1893 | dev_priv->mm.interruptible = false; |
1815 | ret = i915_gem_object_pin(obj, alignment, true); | 1894 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined); |
1816 | if (ret) | 1895 | if (ret) |
1817 | goto err_interruptible; | 1896 | goto err_interruptible; |
1818 | 1897 | ||
1819 | ret = i915_gem_object_set_to_display_plane(obj, pipelined); | ||
1820 | if (ret) | ||
1821 | goto err_unpin; | ||
1822 | |||
1823 | /* Install a fence for tiled scan-out. Pre-i965 always needs a | 1898 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
1824 | * fence, whereas 965+ only requires a fence if using | 1899 | * fence, whereas 965+ only requires a fence if using |
1825 | * framebuffer compression. For simplicity, we always install | 1900 | * framebuffer compression. For simplicity, we always install |
@@ -1841,10 +1916,8 @@ err_interruptible: | |||
1841 | return ret; | 1916 | return ret; |
1842 | } | 1917 | } |
1843 | 1918 | ||
1844 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ | 1919 | static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
1845 | static int | 1920 | int x, int y) |
1846 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | ||
1847 | int x, int y, enum mode_set_atomic state) | ||
1848 | { | 1921 | { |
1849 | struct drm_device *dev = crtc->dev; | 1922 | struct drm_device *dev = crtc->dev; |
1850 | struct drm_i915_private *dev_priv = dev->dev_private; | 1923 | struct drm_i915_private *dev_priv = dev->dev_private; |
@@ -1887,7 +1960,7 @@ intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |||
1887 | dspcntr |= DISPPLANE_32BPP_NO_ALPHA; | 1960 | dspcntr |= DISPPLANE_32BPP_NO_ALPHA; |
1888 | break; | 1961 | break; |
1889 | default: | 1962 | default: |
1890 | DRM_ERROR("Unknown color depth\n"); | 1963 | DRM_ERROR("Unknown color depth %d\n", fb->bits_per_pixel); |
1891 | return -EINVAL; | 1964 | return -EINVAL; |
1892 | } | 1965 | } |
1893 | if (INTEL_INFO(dev)->gen >= 4) { | 1966 | if (INTEL_INFO(dev)->gen >= 4) { |
@@ -1897,10 +1970,6 @@ intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |||
1897 | dspcntr &= ~DISPPLANE_TILED; | 1970 | dspcntr &= ~DISPPLANE_TILED; |
1898 | } | 1971 | } |
1899 | 1972 | ||
1900 | if (HAS_PCH_SPLIT(dev)) | ||
1901 | /* must disable */ | ||
1902 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | ||
1903 | |||
1904 | I915_WRITE(reg, dspcntr); | 1973 | I915_WRITE(reg, dspcntr); |
1905 | 1974 | ||
1906 | Start = obj->gtt_offset; | 1975 | Start = obj->gtt_offset; |
@@ -1917,6 +1986,99 @@ intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |||
1917 | I915_WRITE(DSPADDR(plane), Start + Offset); | 1986 | I915_WRITE(DSPADDR(plane), Start + Offset); |
1918 | POSTING_READ(reg); | 1987 | POSTING_READ(reg); |
1919 | 1988 | ||
1989 | return 0; | ||
1990 | } | ||
1991 | |||
1992 | static int ironlake_update_plane(struct drm_crtc *crtc, | ||
1993 | struct drm_framebuffer *fb, int x, int y) | ||
1994 | { | ||
1995 | struct drm_device *dev = crtc->dev; | ||
1996 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
1997 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | ||
1998 | struct intel_framebuffer *intel_fb; | ||
1999 | struct drm_i915_gem_object *obj; | ||
2000 | int plane = intel_crtc->plane; | ||
2001 | unsigned long Start, Offset; | ||
2002 | u32 dspcntr; | ||
2003 | u32 reg; | ||
2004 | |||
2005 | switch (plane) { | ||
2006 | case 0: | ||
2007 | case 1: | ||
2008 | break; | ||
2009 | default: | ||
2010 | DRM_ERROR("Can't update plane %d in SAREA\n", plane); | ||
2011 | return -EINVAL; | ||
2012 | } | ||
2013 | |||
2014 | intel_fb = to_intel_framebuffer(fb); | ||
2015 | obj = intel_fb->obj; | ||
2016 | |||
2017 | reg = DSPCNTR(plane); | ||
2018 | dspcntr = I915_READ(reg); | ||
2019 | /* Mask out pixel format bits in case we change it */ | ||
2020 | dspcntr &= ~DISPPLANE_PIXFORMAT_MASK; | ||
2021 | switch (fb->bits_per_pixel) { | ||
2022 | case 8: | ||
2023 | dspcntr |= DISPPLANE_8BPP; | ||
2024 | break; | ||
2025 | case 16: | ||
2026 | if (fb->depth != 16) | ||
2027 | return -EINVAL; | ||
2028 | |||
2029 | dspcntr |= DISPPLANE_16BPP; | ||
2030 | break; | ||
2031 | case 24: | ||
2032 | case 32: | ||
2033 | if (fb->depth == 24) | ||
2034 | dspcntr |= DISPPLANE_32BPP_NO_ALPHA; | ||
2035 | else if (fb->depth == 30) | ||
2036 | dspcntr |= DISPPLANE_32BPP_30BIT_NO_ALPHA; | ||
2037 | else | ||
2038 | return -EINVAL; | ||
2039 | break; | ||
2040 | default: | ||
2041 | DRM_ERROR("Unknown color depth %d\n", fb->bits_per_pixel); | ||
2042 | return -EINVAL; | ||
2043 | } | ||
2044 | |||
2045 | if (obj->tiling_mode != I915_TILING_NONE) | ||
2046 | dspcntr |= DISPPLANE_TILED; | ||
2047 | else | ||
2048 | dspcntr &= ~DISPPLANE_TILED; | ||
2049 | |||
2050 | /* must disable */ | ||
2051 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | ||
2052 | |||
2053 | I915_WRITE(reg, dspcntr); | ||
2054 | |||
2055 | Start = obj->gtt_offset; | ||
2056 | Offset = y * fb->pitch + x * (fb->bits_per_pixel / 8); | ||
2057 | |||
2058 | DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n", | ||
2059 | Start, Offset, x, y, fb->pitch); | ||
2060 | I915_WRITE(DSPSTRIDE(plane), fb->pitch); | ||
2061 | I915_WRITE(DSPSURF(plane), Start); | ||
2062 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); | ||
2063 | I915_WRITE(DSPADDR(plane), Offset); | ||
2064 | POSTING_READ(reg); | ||
2065 | |||
2066 | return 0; | ||
2067 | } | ||
2068 | |||
2069 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ | ||
2070 | static int | ||
2071 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | ||
2072 | int x, int y, enum mode_set_atomic state) | ||
2073 | { | ||
2074 | struct drm_device *dev = crtc->dev; | ||
2075 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
2076 | int ret; | ||
2077 | |||
2078 | ret = dev_priv->display.update_plane(crtc, fb, x, y); | ||
2079 | if (ret) | ||
2080 | return ret; | ||
2081 | |||
1920 | intel_update_fbc(dev); | 2082 | intel_update_fbc(dev); |
1921 | intel_increase_pllclock(crtc); | 2083 | intel_increase_pllclock(crtc); |
1922 | 2084 | ||
@@ -1971,7 +2133,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, | |||
1971 | * This should only fail upon a hung GPU, in which case we | 2133 | * This should only fail upon a hung GPU, in which case we |
1972 | * can safely continue. | 2134 | * can safely continue. |
1973 | */ | 2135 | */ |
1974 | ret = i915_gem_object_flush_gpu(obj); | 2136 | ret = i915_gem_object_finish_gpu(obj); |
1975 | (void) ret; | 2137 | (void) ret; |
1976 | } | 2138 | } |
1977 | 2139 | ||
@@ -2622,6 +2784,7 @@ static void ironlake_pch_enable(struct drm_crtc *crtc) | |||
2622 | /* For PCH DP, enable TRANS_DP_CTL */ | 2784 | /* For PCH DP, enable TRANS_DP_CTL */ |
2623 | if (HAS_PCH_CPT(dev) && | 2785 | if (HAS_PCH_CPT(dev) && |
2624 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { | 2786 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
2787 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) >> 5; | ||
2625 | reg = TRANS_DP_CTL(pipe); | 2788 | reg = TRANS_DP_CTL(pipe); |
2626 | temp = I915_READ(reg); | 2789 | temp = I915_READ(reg); |
2627 | temp &= ~(TRANS_DP_PORT_SEL_MASK | | 2790 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
@@ -2629,7 +2792,7 @@ static void ironlake_pch_enable(struct drm_crtc *crtc) | |||
2629 | TRANS_DP_BPC_MASK); | 2792 | TRANS_DP_BPC_MASK); |
2630 | temp |= (TRANS_DP_OUTPUT_ENABLE | | 2793 | temp |= (TRANS_DP_OUTPUT_ENABLE | |
2631 | TRANS_DP_ENH_FRAMING); | 2794 | TRANS_DP_ENH_FRAMING); |
2632 | temp |= TRANS_DP_8BPC; | 2795 | temp |= bpc << 9; /* same format but at 11:9 */ |
2633 | 2796 | ||
2634 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) | 2797 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) |
2635 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; | 2798 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
@@ -2732,9 +2895,8 @@ static void ironlake_crtc_disable(struct drm_crtc *crtc) | |||
2732 | 2895 | ||
2733 | intel_disable_plane(dev_priv, plane, pipe); | 2896 | intel_disable_plane(dev_priv, plane, pipe); |
2734 | 2897 | ||
2735 | if (dev_priv->cfb_plane == plane && | 2898 | if (dev_priv->cfb_plane == plane) |
2736 | dev_priv->display.disable_fbc) | 2899 | intel_disable_fbc(dev); |
2737 | dev_priv->display.disable_fbc(dev); | ||
2738 | 2900 | ||
2739 | intel_disable_pipe(dev_priv, pipe); | 2901 | intel_disable_pipe(dev_priv, pipe); |
2740 | 2902 | ||
@@ -2898,9 +3060,8 @@ static void i9xx_crtc_disable(struct drm_crtc *crtc) | |||
2898 | intel_crtc_dpms_overlay(intel_crtc, false); | 3060 | intel_crtc_dpms_overlay(intel_crtc, false); |
2899 | intel_crtc_update_cursor(crtc, false); | 3061 | intel_crtc_update_cursor(crtc, false); |
2900 | 3062 | ||
2901 | if (dev_priv->cfb_plane == plane && | 3063 | if (dev_priv->cfb_plane == plane) |
2902 | dev_priv->display.disable_fbc) | 3064 | intel_disable_fbc(dev); |
2903 | dev_priv->display.disable_fbc(dev); | ||
2904 | 3065 | ||
2905 | intel_disable_plane(dev_priv, plane, pipe); | 3066 | intel_disable_plane(dev_priv, plane, pipe); |
2906 | intel_disable_pipe(dev_priv, pipe); | 3067 | intel_disable_pipe(dev_priv, pipe); |
@@ -4308,6 +4469,133 @@ static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) | |||
4308 | return dev_priv->lvds_use_ssc && i915_panel_use_ssc; | 4469 | return dev_priv->lvds_use_ssc && i915_panel_use_ssc; |
4309 | } | 4470 | } |
4310 | 4471 | ||
4472 | /** | ||
4473 | * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send | ||
4474 | * @crtc: CRTC structure | ||
4475 | * | ||
4476 | * A pipe may be connected to one or more outputs. Based on the depth of the | ||
4477 | * attached framebuffer, choose a good color depth to use on the pipe. | ||
4478 | * | ||
4479 | * If possible, match the pipe depth to the fb depth. In some cases, this | ||
4480 | * isn't ideal, because the connected output supports a lesser or restricted | ||
4481 | * set of depths. Resolve that here: | ||
4482 | * LVDS typically supports only 6bpc, so clamp down in that case | ||
4483 | * HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc | ||
4484 | * Displays may support a restricted set as well, check EDID and clamp as | ||
4485 | * appropriate. | ||
4486 | * | ||
4487 | * RETURNS: | ||
4488 | * Dithering requirement (i.e. false if display bpc and pipe bpc match, | ||
4489 | * true if they don't match). | ||
4490 | */ | ||
4491 | static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc, | ||
4492 | unsigned int *pipe_bpp) | ||
4493 | { | ||
4494 | struct drm_device *dev = crtc->dev; | ||
4495 | struct drm_i915_private *dev_priv = dev->dev_private; | ||
4496 | struct drm_encoder *encoder; | ||
4497 | struct drm_connector *connector; | ||
4498 | unsigned int display_bpc = UINT_MAX, bpc; | ||
4499 | |||
4500 | /* Walk the encoders & connectors on this crtc, get min bpc */ | ||
4501 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | ||
4502 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); | ||
4503 | |||
4504 | if (encoder->crtc != crtc) | ||
4505 | continue; | ||
4506 | |||
4507 | if (intel_encoder->type == INTEL_OUTPUT_LVDS) { | ||
4508 | unsigned int lvds_bpc; | ||
4509 | |||
4510 | if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) == | ||
4511 | LVDS_A3_POWER_UP) | ||
4512 | lvds_bpc = 8; | ||
4513 | else | ||
4514 | lvds_bpc = 6; | ||
4515 | |||
4516 | if (lvds_bpc < display_bpc) { | ||
4517 | DRM_DEBUG_DRIVER("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc); | ||
4518 | display_bpc = lvds_bpc; | ||
4519 | } | ||
4520 | continue; | ||
4521 | } | ||
4522 | |||
4523 | if (intel_encoder->type == INTEL_OUTPUT_EDP) { | ||
4524 | /* Use VBT settings if we have an eDP panel */ | ||
4525 | unsigned int edp_bpc = dev_priv->edp.bpp / 3; | ||
4526 | |||
4527 | if (edp_bpc < display_bpc) { | ||
4528 | DRM_DEBUG_DRIVER("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc); | ||
4529 | display_bpc = edp_bpc; | ||
4530 | } | ||
4531 | continue; | ||
4532 | } | ||
4533 | |||
4534 | /* Not one of the known troublemakers, check the EDID */ | ||
4535 | list_for_each_entry(connector, &dev->mode_config.connector_list, | ||
4536 | head) { | ||
4537 | if (connector->encoder != encoder) | ||
4538 | continue; | ||
4539 | |||
4540 | if (connector->display_info.bpc < display_bpc) { | ||
4541 | DRM_DEBUG_DRIVER("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc); | ||
4542 | display_bpc = connector->display_info.bpc; | ||
4543 | } | ||
4544 | } | ||
4545 | |||
4546 | /* | ||
4547 | * HDMI is either 12 or 8, so if the display lets 10bpc sneak | ||
4548 | * through, clamp it down. (Note: >12bpc will be caught below.) | ||
4549 | */ | ||
4550 | if (intel_encoder->type == INTEL_OUTPUT_HDMI) { | ||
4551 | if (display_bpc > 8 && display_bpc < 12) { | ||
4552 | DRM_DEBUG_DRIVER("forcing bpc to 12 for HDMI\n"); | ||
4553 | display_bpc = 12; | ||
4554 | } else { | ||
4555 | DRM_DEBUG_DRIVER("forcing bpc to 8 for HDMI\n"); | ||
4556 | display_bpc = 8; | ||
4557 | } | ||
4558 | } | ||
4559 | } | ||
4560 | |||
4561 | /* | ||
4562 | * We could just drive the pipe at the highest bpc all the time and | ||
4563 | * enable dithering as needed, but that costs bandwidth. So choose | ||
4564 | * the minimum value that expresses the full color range of the fb but | ||
4565 | * also stays within the max display bpc discovered above. | ||
4566 | */ | ||
4567 | |||
4568 | switch (crtc->fb->depth) { | ||
4569 | case 8: | ||
4570 | bpc = 8; /* since we go through a colormap */ | ||
4571 | break; | ||
4572 | case 15: | ||
4573 | case 16: | ||
4574 | bpc = 6; /* min is 18bpp */ | ||
4575 | break; | ||
4576 | case 24: | ||
4577 | bpc = min((unsigned int)8, display_bpc); | ||
4578 | break; | ||
4579 | case 30: | ||
4580 | bpc = min((unsigned int)10, display_bpc); | ||
4581 | break; | ||
4582 | case 48: | ||
4583 | bpc = min((unsigned int)12, display_bpc); | ||
4584 | break; | ||
4585 | default: | ||
4586 | DRM_DEBUG("unsupported depth, assuming 24 bits\n"); | ||
4587 | bpc = min((unsigned int)8, display_bpc); | ||
4588 | break; | ||
4589 | } | ||
4590 | |||
4591 | DRM_DEBUG_DRIVER("setting pipe bpc to %d (max display bpc %d)\n", | ||
4592 | bpc, display_bpc); | ||
4593 | |||
4594 | *pipe_bpp = bpc * 3; | ||
4595 | |||
4596 | return display_bpc != bpc; | ||
4597 | } | ||
4598 | |||
4311 | static int i9xx_crtc_mode_set(struct drm_crtc *crtc, | 4599 | static int i9xx_crtc_mode_set(struct drm_crtc *crtc, |
4312 | struct drm_display_mode *mode, | 4600 | struct drm_display_mode *mode, |
4313 | struct drm_display_mode *adjusted_mode, | 4601 | struct drm_display_mode *adjusted_mode, |
@@ -4720,7 +5008,9 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc, | |||
4720 | struct fdi_m_n m_n = {0}; | 5008 | struct fdi_m_n m_n = {0}; |
4721 | u32 temp; | 5009 | u32 temp; |
4722 | u32 lvds_sync = 0; | 5010 | u32 lvds_sync = 0; |
4723 | int target_clock, pixel_multiplier, lane, link_bw, bpp, factor; | 5011 | int target_clock, pixel_multiplier, lane, link_bw, factor; |
5012 | unsigned int pipe_bpp; | ||
5013 | bool dither; | ||
4724 | 5014 | ||
4725 | list_for_each_entry(encoder, &mode_config->encoder_list, base.head) { | 5015 | list_for_each_entry(encoder, &mode_config->encoder_list, base.head) { |
4726 | if (encoder->base.crtc != crtc) | 5016 | if (encoder->base.crtc != crtc) |
@@ -4847,56 +5137,37 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc, | |||
4847 | /* determine panel color depth */ | 5137 | /* determine panel color depth */ |
4848 | temp = I915_READ(PIPECONF(pipe)); | 5138 | temp = I915_READ(PIPECONF(pipe)); |
4849 | temp &= ~PIPE_BPC_MASK; | 5139 | temp &= ~PIPE_BPC_MASK; |
4850 | if (is_lvds) { | 5140 | dither = intel_choose_pipe_bpp_dither(crtc, &pipe_bpp); |
4851 | /* the BPC will be 6 if it is 18-bit LVDS panel */ | 5141 | switch (pipe_bpp) { |
4852 | if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) == LVDS_A3_POWER_UP) | 5142 | case 18: |
4853 | temp |= PIPE_8BPC; | 5143 | temp |= PIPE_6BPC; |
4854 | else | ||
4855 | temp |= PIPE_6BPC; | ||
4856 | } else if (has_edp_encoder) { | ||
4857 | switch (dev_priv->edp.bpp/3) { | ||
4858 | case 8: | ||
4859 | temp |= PIPE_8BPC; | ||
4860 | break; | ||
4861 | case 10: | ||
4862 | temp |= PIPE_10BPC; | ||
4863 | break; | ||
4864 | case 6: | ||
4865 | temp |= PIPE_6BPC; | ||
4866 | break; | ||
4867 | case 12: | ||
4868 | temp |= PIPE_12BPC; | ||
4869 | break; | ||
4870 | } | ||
4871 | } else | ||
4872 | temp |= PIPE_8BPC; | ||
4873 | I915_WRITE(PIPECONF(pipe), temp); | ||
4874 | |||
4875 | switch (temp & PIPE_BPC_MASK) { | ||
4876 | case PIPE_8BPC: | ||
4877 | bpp = 24; | ||
4878 | break; | 5144 | break; |
4879 | case PIPE_10BPC: | 5145 | case 24: |
4880 | bpp = 30; | 5146 | temp |= PIPE_8BPC; |
4881 | break; | 5147 | break; |
4882 | case PIPE_6BPC: | 5148 | case 30: |
4883 | bpp = 18; | 5149 | temp |= PIPE_10BPC; |
4884 | break; | 5150 | break; |
4885 | case PIPE_12BPC: | 5151 | case 36: |
4886 | bpp = 36; | 5152 | temp |= PIPE_12BPC; |
4887 | break; | 5153 | break; |
4888 | default: | 5154 | default: |
4889 | DRM_ERROR("unknown pipe bpc value\n"); | 5155 | WARN(1, "intel_choose_pipe_bpp returned invalid value\n"); |
4890 | bpp = 24; | 5156 | temp |= PIPE_8BPC; |
5157 | pipe_bpp = 24; | ||
5158 | break; | ||
4891 | } | 5159 | } |
4892 | 5160 | ||
5161 | intel_crtc->bpp = pipe_bpp; | ||
5162 | I915_WRITE(PIPECONF(pipe), temp); | ||
5163 | |||
4893 | if (!lane) { | 5164 | if (!lane) { |
4894 | /* | 5165 | /* |
4895 | * Account for spread spectrum to avoid | 5166 | * Account for spread spectrum to avoid |
4896 | * oversubscribing the link. Max center spread | 5167 | * oversubscribing the link. Max center spread |
4897 | * is 2.5%; use 5% for safety's sake. | 5168 | * is 2.5%; use 5% for safety's sake. |
4898 | */ | 5169 | */ |
4899 | u32 bps = target_clock * bpp * 21 / 20; | 5170 | u32 bps = target_clock * intel_crtc->bpp * 21 / 20; |
4900 | lane = bps / (link_bw * 8) + 1; | 5171 | lane = bps / (link_bw * 8) + 1; |
4901 | } | 5172 | } |
4902 | 5173 | ||
@@ -4904,7 +5175,8 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc, | |||
4904 | 5175 | ||
4905 | if (pixel_multiplier > 1) | 5176 | if (pixel_multiplier > 1) |
4906 | link_bw *= pixel_multiplier; | 5177 | link_bw *= pixel_multiplier; |
4907 | ironlake_compute_m_n(bpp, lane, target_clock, link_bw, &m_n); | 5178 | ironlake_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw, |
5179 | &m_n); | ||
4908 | 5180 | ||
4909 | /* Ironlake: try to setup display ref clock before DPLL | 5181 | /* Ironlake: try to setup display ref clock before DPLL |
4910 | * enabling. This is only under driver's control after | 5182 | * enabling. This is only under driver's control after |
@@ -5107,14 +5379,12 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc, | |||
5107 | I915_WRITE(PCH_LVDS, temp); | 5379 | I915_WRITE(PCH_LVDS, temp); |
5108 | } | 5380 | } |
5109 | 5381 | ||
5110 | /* set the dithering flag and clear for anything other than a panel. */ | ||
5111 | pipeconf &= ~PIPECONF_DITHER_EN; | 5382 | pipeconf &= ~PIPECONF_DITHER_EN; |
5112 | pipeconf &= ~PIPECONF_DITHER_TYPE_MASK; | 5383 | pipeconf &= ~PIPECONF_DITHER_TYPE_MASK; |
5113 | if (dev_priv->lvds_dither && (is_lvds || has_edp_encoder)) { | 5384 | if ((is_lvds && dev_priv->lvds_dither) || dither) { |
5114 | pipeconf |= PIPECONF_DITHER_EN; | 5385 | pipeconf |= PIPECONF_DITHER_EN; |
5115 | pipeconf |= PIPECONF_DITHER_TYPE_ST1; | 5386 | pipeconf |= PIPECONF_DITHER_TYPE_ST1; |
5116 | } | 5387 | } |
5117 | |||
5118 | if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base)) { | 5388 | if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base)) { |
5119 | intel_dp_set_m_n(crtc, mode, adjusted_mode); | 5389 | intel_dp_set_m_n(crtc, mode, adjusted_mode); |
5120 | } else { | 5390 | } else { |
@@ -5434,21 +5704,15 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc, | |||
5434 | goto fail_locked; | 5704 | goto fail_locked; |
5435 | } | 5705 | } |
5436 | 5706 | ||
5437 | ret = i915_gem_object_pin(obj, PAGE_SIZE, true); | 5707 | ret = i915_gem_object_pin_to_display_plane(obj, 0, NULL); |
5438 | if (ret) { | ||
5439 | DRM_ERROR("failed to pin cursor bo\n"); | ||
5440 | goto fail_locked; | ||
5441 | } | ||
5442 | |||
5443 | ret = i915_gem_object_set_to_gtt_domain(obj, 0); | ||
5444 | if (ret) { | 5708 | if (ret) { |
5445 | DRM_ERROR("failed to move cursor bo into the GTT\n"); | 5709 | DRM_ERROR("failed to move cursor bo into the GTT\n"); |
5446 | goto fail_unpin; | 5710 | goto fail_locked; |
5447 | } | 5711 | } |
5448 | 5712 | ||
5449 | ret = i915_gem_object_put_fence(obj); | 5713 | ret = i915_gem_object_put_fence(obj); |
5450 | if (ret) { | 5714 | if (ret) { |
5451 | DRM_ERROR("failed to move cursor bo into the GTT\n"); | 5715 | DRM_ERROR("failed to release fence for cursor"); |
5452 | goto fail_unpin; | 5716 | goto fail_unpin; |
5453 | } | 5717 | } |
5454 | 5718 | ||
@@ -6151,6 +6415,7 @@ static void intel_unpin_work_fn(struct work_struct *__work) | |||
6151 | drm_gem_object_unreference(&work->pending_flip_obj->base); | 6415 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
6152 | drm_gem_object_unreference(&work->old_fb_obj->base); | 6416 | drm_gem_object_unreference(&work->old_fb_obj->base); |
6153 | 6417 | ||
6418 | intel_update_fbc(work->dev); | ||
6154 | mutex_unlock(&work->dev->struct_mutex); | 6419 | mutex_unlock(&work->dev->struct_mutex); |
6155 | kfree(work); | 6420 | kfree(work); |
6156 | } | 6421 | } |
@@ -6515,6 +6780,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, | |||
6515 | if (ret) | 6780 | if (ret) |
6516 | goto cleanup_pending; | 6781 | goto cleanup_pending; |
6517 | 6782 | ||
6783 | intel_disable_fbc(dev); | ||
6518 | mutex_unlock(&dev->struct_mutex); | 6784 | mutex_unlock(&dev->struct_mutex); |
6519 | 6785 | ||
6520 | trace_i915_flip_request(intel_crtc->plane, obj); | 6786 | trace_i915_flip_request(intel_crtc->plane, obj); |
@@ -6643,6 +6909,7 @@ static void intel_crtc_init(struct drm_device *dev, int pipe) | |||
6643 | 6909 | ||
6644 | intel_crtc_reset(&intel_crtc->base); | 6910 | intel_crtc_reset(&intel_crtc->base); |
6645 | intel_crtc->active = true; /* force the pipe off on setup_init_config */ | 6911 | intel_crtc->active = true; /* force the pipe off on setup_init_config */ |
6912 | intel_crtc->bpp = 24; /* default for pre-Ironlake */ | ||
6646 | 6913 | ||
6647 | if (HAS_PCH_SPLIT(dev)) { | 6914 | if (HAS_PCH_SPLIT(dev)) { |
6648 | intel_helper_funcs.prepare = ironlake_crtc_prepare; | 6915 | intel_helper_funcs.prepare = ironlake_crtc_prepare; |
@@ -6869,6 +7136,11 @@ int intel_framebuffer_init(struct drm_device *dev, | |||
6869 | switch (mode_cmd->bpp) { | 7136 | switch (mode_cmd->bpp) { |
6870 | case 8: | 7137 | case 8: |
6871 | case 16: | 7138 | case 16: |
7139 | /* Only pre-ILK can handle 5:5:5 */ | ||
7140 | if (mode_cmd->depth == 15 && !HAS_PCH_SPLIT(dev)) | ||
7141 | return -EINVAL; | ||
7142 | break; | ||
7143 | |||
6872 | case 24: | 7144 | case 24: |
6873 | case 32: | 7145 | case 32: |
6874 | break; | 7146 | break; |
@@ -7283,6 +7555,59 @@ void gen6_enable_rps(struct drm_i915_private *dev_priv) | |||
7283 | mutex_unlock(&dev_priv->dev->struct_mutex); | 7555 | mutex_unlock(&dev_priv->dev->struct_mutex); |
7284 | } | 7556 | } |
7285 | 7557 | ||
7558 | void gen6_update_ring_freq(struct drm_i915_private *dev_priv) | ||
7559 | { | ||
7560 | int min_freq = 15; | ||
7561 | int gpu_freq, ia_freq, max_ia_freq; | ||
7562 | int scaling_factor = 180; | ||
7563 | |||
7564 | max_ia_freq = cpufreq_quick_get_max(0); | ||
7565 | /* | ||
7566 | * Default to measured freq if none found, PCU will ensure we don't go | ||
7567 | * over | ||
7568 | */ | ||
7569 | if (!max_ia_freq) | ||
7570 | max_ia_freq = tsc_khz; | ||
7571 | |||
7572 | /* Convert from kHz to MHz */ | ||
7573 | max_ia_freq /= 1000; | ||
7574 | |||
7575 | mutex_lock(&dev_priv->dev->struct_mutex); | ||
7576 | |||
7577 | /* | ||
7578 | * For each potential GPU frequency, load a ring frequency we'd like | ||
7579 | * to use for memory access. We do this by specifying the IA frequency | ||
7580 | * the PCU should use as a reference to determine the ring frequency. | ||
7581 | */ | ||
7582 | for (gpu_freq = dev_priv->max_delay; gpu_freq >= dev_priv->min_delay; | ||
7583 | gpu_freq--) { | ||
7584 | int diff = dev_priv->max_delay - gpu_freq; | ||
7585 | |||
7586 | /* | ||
7587 | * For GPU frequencies less than 750MHz, just use the lowest | ||
7588 | * ring freq. | ||
7589 | */ | ||
7590 | if (gpu_freq < min_freq) | ||
7591 | ia_freq = 800; | ||
7592 | else | ||
7593 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); | ||
7594 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); | ||
7595 | |||
7596 | I915_WRITE(GEN6_PCODE_DATA, | ||
7597 | (ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT) | | ||
7598 | gpu_freq); | ||
7599 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | | ||
7600 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE); | ||
7601 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & | ||
7602 | GEN6_PCODE_READY) == 0, 10)) { | ||
7603 | DRM_ERROR("pcode write of freq table timed out\n"); | ||
7604 | continue; | ||
7605 | } | ||
7606 | } | ||
7607 | |||
7608 | mutex_unlock(&dev_priv->dev->struct_mutex); | ||
7609 | } | ||
7610 | |||
7286 | static void ironlake_init_clock_gating(struct drm_device *dev) | 7611 | static void ironlake_init_clock_gating(struct drm_device *dev) |
7287 | { | 7612 | { |
7288 | struct drm_i915_private *dev_priv = dev->dev_private; | 7613 | struct drm_i915_private *dev_priv = dev->dev_private; |
@@ -7639,9 +7964,11 @@ static void intel_init_display(struct drm_device *dev) | |||
7639 | if (HAS_PCH_SPLIT(dev)) { | 7964 | if (HAS_PCH_SPLIT(dev)) { |
7640 | dev_priv->display.dpms = ironlake_crtc_dpms; | 7965 | dev_priv->display.dpms = ironlake_crtc_dpms; |
7641 | dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set; | 7966 | dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set; |
7967 | dev_priv->display.update_plane = ironlake_update_plane; | ||
7642 | } else { | 7968 | } else { |
7643 | dev_priv->display.dpms = i9xx_crtc_dpms; | 7969 | dev_priv->display.dpms = i9xx_crtc_dpms; |
7644 | dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set; | 7970 | dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set; |
7971 | dev_priv->display.update_plane = i9xx_update_plane; | ||
7645 | } | 7972 | } |
7646 | 7973 | ||
7647 | if (I915_HAS_FBC(dev)) { | 7974 | if (I915_HAS_FBC(dev)) { |
@@ -7926,8 +8253,10 @@ void intel_modeset_init(struct drm_device *dev) | |||
7926 | intel_init_emon(dev); | 8253 | intel_init_emon(dev); |
7927 | } | 8254 | } |
7928 | 8255 | ||
7929 | if (IS_GEN6(dev)) | 8256 | if (IS_GEN6(dev) || IS_GEN7(dev)) { |
7930 | gen6_enable_rps(dev_priv); | 8257 | gen6_enable_rps(dev_priv); |
8258 | gen6_update_ring_freq(dev_priv); | ||
8259 | } | ||
7931 | 8260 | ||
7932 | INIT_WORK(&dev_priv->idle_work, intel_idle_update); | 8261 | INIT_WORK(&dev_priv->idle_work, intel_idle_update); |
7933 | setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer, | 8262 | setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer, |
@@ -7963,12 +8292,11 @@ void intel_modeset_cleanup(struct drm_device *dev) | |||
7963 | intel_increase_pllclock(crtc); | 8292 | intel_increase_pllclock(crtc); |
7964 | } | 8293 | } |
7965 | 8294 | ||
7966 | if (dev_priv->display.disable_fbc) | 8295 | intel_disable_fbc(dev); |
7967 | dev_priv->display.disable_fbc(dev); | ||
7968 | 8296 | ||
7969 | if (IS_IRONLAKE_M(dev)) | 8297 | if (IS_IRONLAKE_M(dev)) |
7970 | ironlake_disable_drps(dev); | 8298 | ironlake_disable_drps(dev); |
7971 | if (IS_GEN6(dev)) | 8299 | if (IS_GEN6(dev) || IS_GEN7(dev)) |
7972 | gen6_disable_rps(dev); | 8300 | gen6_disable_rps(dev); |
7973 | 8301 | ||
7974 | if (IS_IRONLAKE_M(dev)) | 8302 | if (IS_IRONLAKE_M(dev)) |
@@ -7981,6 +8309,9 @@ void intel_modeset_cleanup(struct drm_device *dev) | |||
7981 | drm_irq_uninstall(dev); | 8309 | drm_irq_uninstall(dev); |
7982 | cancel_work_sync(&dev_priv->hotplug_work); | 8310 | cancel_work_sync(&dev_priv->hotplug_work); |
7983 | 8311 | ||
8312 | /* flush any delayed tasks or pending work */ | ||
8313 | flush_scheduled_work(); | ||
8314 | |||
7984 | /* Shut off idle work before the crtcs get freed. */ | 8315 | /* Shut off idle work before the crtcs get freed. */ |
7985 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { | 8316 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
7986 | intel_crtc = to_intel_crtc(crtc); | 8317 | intel_crtc = to_intel_crtc(crtc); |