Revert "drm: make DRI1 drivers depend on BROKEN"
[deliverable/linux.git] / drivers / gpu / drm / drm_fb_helper.c
index 7c2eb75db60f102d9526aebab1a6f7993e124f9b..c4d350086def84372c30aa44e7990d0e58be5e66 100644 (file)
  */
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/console.h>
 #include <linux/kernel.h>
 #include <linux/sysrq.h>
 #include <linux/slab.h>
-#include <linux/fb.h>
 #include <linux/module.h>
 #include <drm/drmP.h>
 #include <drm/drm_crtc.h>
@@ -227,7 +227,7 @@ static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc)
        g_base = r_base + crtc->gamma_size;
        b_base = g_base + crtc->gamma_size;
 
-       crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
+       crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, crtc->gamma_size);
 }
 
 /**
@@ -335,7 +335,7 @@ retry:
                        goto fail;
                }
 
-               plane_state->rotation = BIT(DRM_ROTATE_0);
+               plane_state->rotation = DRM_ROTATE_0;
 
                plane->old_fb = plane->fb;
                plane_mask |= 1 << drm_plane_index(plane);
@@ -385,7 +385,7 @@ static int restore_fbdev_mode(struct drm_fb_helper *fb_helper)
 
        drm_warn_on_modeset_not_all_locked(dev);
 
-       if (fb_helper->atomic)
+       if (dev->mode_config.funcs->atomic_commit)
                return restore_fbdev_mode_atomic(fb_helper);
 
        drm_for_each_plane(plane, dev) {
@@ -395,7 +395,7 @@ static int restore_fbdev_mode(struct drm_fb_helper *fb_helper)
                if (dev->mode_config.rotation_property) {
                        drm_mode_plane_set_obj_prop(plane,
                                                    dev->mode_config.rotation_property,
-                                                   BIT(DRM_ROTATE_0));
+                                                   DRM_ROTATE_0);
                }
        }
 
@@ -464,7 +464,7 @@ static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper)
 
        /* Sometimes user space wants everything disabled, so don't steal the
         * display if there's a master. */
-       if (dev->primary->master)
+       if (lockless_dereference(dev->master))
                return false;
 
        drm_for_each_crtc(crtc, dev) {
@@ -618,6 +618,16 @@ static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
        kfree(helper->crtc_info);
 }
 
+static void drm_fb_helper_resume_worker(struct work_struct *work)
+{
+       struct drm_fb_helper *helper = container_of(work, struct drm_fb_helper,
+                                                   resume_work);
+
+       console_lock();
+       fb_set_suspend(helper->fbdev, 0);
+       console_unlock();
+}
+
 static void drm_fb_helper_dirty_work(struct work_struct *work)
 {
        struct drm_fb_helper *helper = container_of(work, struct drm_fb_helper,
@@ -649,6 +659,7 @@ void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
 {
        INIT_LIST_HEAD(&helper->kernel_fb_list);
        spin_lock_init(&helper->dirty_lock);
+       INIT_WORK(&helper->resume_work, drm_fb_helper_resume_worker);
        INIT_WORK(&helper->dirty_work, drm_fb_helper_dirty_work);
        helper->dirty_clip.x1 = helper->dirty_clip.y1 = ~0;
        helper->funcs = funcs;
@@ -716,8 +727,6 @@ int drm_fb_helper_init(struct drm_device *dev,
                i++;
        }
 
-       fb_helper->atomic = !!drm_core_check_feature(dev, DRIVER_ATOMIC);
-
        return 0;
 out_free:
        drm_fb_helper_crtc_free(fb_helper);
@@ -1026,23 +1035,70 @@ EXPORT_SYMBOL(drm_fb_helper_cfb_imageblit);
 /**
  * drm_fb_helper_set_suspend - wrapper around fb_set_suspend
  * @fb_helper: driver-allocated fbdev helper
- * @state: desired state, zero to resume, non-zero to suspend
+ * @suspend: whether to suspend or resume
  *
- * A wrapper around fb_set_suspend implemented by fbdev core
+ * A wrapper around fb_set_suspend implemented by fbdev core.
+ * Use drm_fb_helper_set_suspend_unlocked() if you don't need to take
+ * the lock yourself
  */
-void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, int state)
+void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, bool suspend)
 {
        if (fb_helper && fb_helper->fbdev)
-               fb_set_suspend(fb_helper->fbdev, state);
+               fb_set_suspend(fb_helper->fbdev, suspend);
 }
 EXPORT_SYMBOL(drm_fb_helper_set_suspend);
 
+/**
+ * drm_fb_helper_set_suspend_unlocked - wrapper around fb_set_suspend that also
+ *                                      takes the console lock
+ * @fb_helper: driver-allocated fbdev helper
+ * @suspend: whether to suspend or resume
+ *
+ * A wrapper around fb_set_suspend() that takes the console lock. If the lock
+ * isn't available on resume, a worker is tasked with waiting for the lock
+ * to become available. The console lock can be pretty contented on resume
+ * due to all the printk activity.
+ *
+ * This function can be called multiple times with the same state since
+ * &fb_info->state is checked to see if fbdev is running or not before locking.
+ *
+ * Use drm_fb_helper_set_suspend() if you need to take the lock yourself.
+ */
+void drm_fb_helper_set_suspend_unlocked(struct drm_fb_helper *fb_helper,
+                                       bool suspend)
+{
+       if (!fb_helper || !fb_helper->fbdev)
+               return;
+
+       /* make sure there's no pending/ongoing resume */
+       flush_work(&fb_helper->resume_work);
+
+       if (suspend) {
+               if (fb_helper->fbdev->state != FBINFO_STATE_RUNNING)
+                       return;
+
+               console_lock();
+
+       } else {
+               if (fb_helper->fbdev->state == FBINFO_STATE_RUNNING)
+                       return;
+
+               if (!console_trylock()) {
+                       schedule_work(&fb_helper->resume_work);
+                       return;
+               }
+       }
+
+       fb_set_suspend(fb_helper->fbdev, suspend);
+       console_unlock();
+}
+EXPORT_SYMBOL(drm_fb_helper_set_suspend_unlocked);
+
 static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
                     u16 blue, u16 regno, struct fb_info *info)
 {
        struct drm_fb_helper *fb_helper = info->par;
        struct drm_framebuffer *fb = fb_helper->fb;
-       int pindex;
 
        if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
                u32 *palette;
@@ -1074,38 +1130,10 @@ static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
                    !fb_helper->funcs->gamma_get))
                return -EINVAL;
 
-       pindex = regno;
+       WARN_ON(fb->bits_per_pixel != 8);
 
-       if (fb->bits_per_pixel == 16) {
-               pindex = regno << 3;
-
-               if (fb->depth == 16 && regno > 63)
-                       return -EINVAL;
-               if (fb->depth == 15 && regno > 31)
-                       return -EINVAL;
-
-               if (fb->depth == 16) {
-                       u16 r, g, b;
-                       int i;
-                       if (regno < 32) {
-                               for (i = 0; i < 8; i++)
-                                       fb_helper->funcs->gamma_set(crtc, red,
-                                               green, blue, pindex + i);
-                       }
+       fb_helper->funcs->gamma_set(crtc, red, green, blue, regno);
 
-                       fb_helper->funcs->gamma_get(crtc, &r,
-                                                   &g, &b,
-                                                   pindex >> 1);
-
-                       for (i = 0; i < 4; i++)
-                               fb_helper->funcs->gamma_set(crtc, r,
-                                                           green, b,
-                                                           (pindex >> 1) + i);
-               }
-       }
-
-       if (fb->depth != 16)
-               fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex);
        return 0;
 }
 
@@ -1373,7 +1401,7 @@ int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
                return -EBUSY;
        }
 
-       if (fb_helper->atomic) {
+       if (dev->mode_config.funcs->atomic_commit) {
                ret = pan_display_atomic(var, info);
                goto unlock;
        }
@@ -2000,7 +2028,18 @@ static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
                my_score++;
 
        connector_funcs = connector->helper_private;
-       encoder = connector_funcs->best_encoder(connector);
+
+       /*
+        * If the DRM device implements atomic hooks and ->best_encoder() is
+        * NULL we fallback to the default drm_atomic_helper_best_encoder()
+        * helper.
+        */
+       if (fb_helper->dev->mode_config.funcs->atomic_commit &&
+           !connector_funcs->best_encoder)
+               encoder = drm_atomic_helper_best_encoder(connector);
+       else
+               encoder = connector_funcs->best_encoder(connector);
+
        if (!encoder)
                goto out;
 
@@ -2214,7 +2253,7 @@ EXPORT_SYMBOL(drm_fb_helper_initial_config);
  * @fb_helper: the drm_fb_helper
  *
  * Scan the connectors attached to the fb_helper and try to put together a
- * setup after *notification of a change in output configuration.
+ * setup after notification of a change in output configuration.
  *
  * Called at runtime, takes the mode config locks to be able to check/change the
  * modeset configuration. Must be run from process context (which usually means
This page took 0.02739 seconds and 5 git commands to generate.