Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2007 David Airlie |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * David Airlie |
| 25 | */ |
| 26 | |
Jesse Barnes | d1d7067 | 2014-05-28 14:39:03 -0700 | [diff] [blame] | 27 | #include <linux/async.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/kernel.h> |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 30 | #include <linux/console.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 31 | #include <linux/errno.h> |
| 32 | #include <linux/string.h> |
| 33 | #include <linux/mm.h> |
| 34 | #include <linux/tty.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 35 | #include <linux/sysrq.h> |
| 36 | #include <linux/delay.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 37 | #include <linux/init.h> |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 38 | #include <linux/vga_switcheroo.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 39 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 40 | #include <drm/drmP.h> |
| 41 | #include <drm/drm_crtc.h> |
| 42 | #include <drm/drm_fb_helper.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 43 | #include "intel_drv.h" |
Chris Wilson | 5d723d7 | 2016-08-04 16:32:35 +0100 | [diff] [blame] | 44 | #include "intel_frontbuffer.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 45 | #include <drm/i915_drm.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 46 | #include "i915_drv.h" |
| 47 | |
Daniel Vetter | e991077 | 2014-06-18 15:05:19 +0200 | [diff] [blame] | 48 | static int intel_fbdev_set_par(struct fb_info *info) |
| 49 | { |
| 50 | struct drm_fb_helper *fb_helper = info->par; |
| 51 | struct intel_fbdev *ifbdev = |
| 52 | container_of(fb_helper, struct intel_fbdev, helper); |
| 53 | int ret; |
| 54 | |
| 55 | ret = drm_fb_helper_set_par(info); |
| 56 | |
| 57 | if (ret == 0) { |
Daniel Vetter | e991077 | 2014-06-18 15:05:19 +0200 | [diff] [blame] | 58 | mutex_lock(&fb_helper->dev->struct_mutex); |
Rodrigo Vivi | aba6da3 | 2015-07-09 09:56:41 -0700 | [diff] [blame] | 59 | intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT); |
Daniel Vetter | e991077 | 2014-06-18 15:05:19 +0200 | [diff] [blame] | 60 | mutex_unlock(&fb_helper->dev->struct_mutex); |
| 61 | } |
| 62 | |
| 63 | return ret; |
| 64 | } |
| 65 | |
Rodrigo Vivi | 03e515f | 2015-03-09 17:57:07 -0700 | [diff] [blame] | 66 | static int intel_fbdev_blank(int blank, struct fb_info *info) |
| 67 | { |
| 68 | struct drm_fb_helper *fb_helper = info->par; |
| 69 | struct intel_fbdev *ifbdev = |
| 70 | container_of(fb_helper, struct intel_fbdev, helper); |
| 71 | int ret; |
| 72 | |
| 73 | ret = drm_fb_helper_blank(blank, info); |
| 74 | |
| 75 | if (ret == 0) { |
Rodrigo Vivi | 03e515f | 2015-03-09 17:57:07 -0700 | [diff] [blame] | 76 | mutex_lock(&fb_helper->dev->struct_mutex); |
Rodrigo Vivi | 77a0d1c | 2015-06-18 11:43:24 -0700 | [diff] [blame] | 77 | intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT); |
Rodrigo Vivi | 03e515f | 2015-03-09 17:57:07 -0700 | [diff] [blame] | 78 | mutex_unlock(&fb_helper->dev->struct_mutex); |
| 79 | } |
| 80 | |
| 81 | return ret; |
| 82 | } |
| 83 | |
Rodrigo Vivi | d9a946b | 2015-05-28 10:26:58 -0700 | [diff] [blame] | 84 | static int intel_fbdev_pan_display(struct fb_var_screeninfo *var, |
| 85 | struct fb_info *info) |
| 86 | { |
| 87 | struct drm_fb_helper *fb_helper = info->par; |
| 88 | struct intel_fbdev *ifbdev = |
| 89 | container_of(fb_helper, struct intel_fbdev, helper); |
| 90 | |
| 91 | int ret; |
| 92 | ret = drm_fb_helper_pan_display(var, info); |
| 93 | |
| 94 | if (ret == 0) { |
Rodrigo Vivi | d9a946b | 2015-05-28 10:26:58 -0700 | [diff] [blame] | 95 | mutex_lock(&fb_helper->dev->struct_mutex); |
Rodrigo Vivi | 77a0d1c | 2015-06-18 11:43:24 -0700 | [diff] [blame] | 96 | intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT); |
Rodrigo Vivi | d9a946b | 2015-05-28 10:26:58 -0700 | [diff] [blame] | 97 | mutex_unlock(&fb_helper->dev->struct_mutex); |
| 98 | } |
| 99 | |
| 100 | return ret; |
| 101 | } |
| 102 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 103 | static struct fb_ops intelfb_ops = { |
| 104 | .owner = THIS_MODULE, |
Stefan Christ | a36384d | 2016-11-14 00:03:27 +0100 | [diff] [blame] | 105 | DRM_FB_HELPER_DEFAULT_OPS, |
Daniel Vetter | e991077 | 2014-06-18 15:05:19 +0200 | [diff] [blame] | 106 | .fb_set_par = intel_fbdev_set_par, |
Archit Taneja | 21cff14 | 2015-07-31 16:21:56 +0530 | [diff] [blame] | 107 | .fb_fillrect = drm_fb_helper_cfb_fillrect, |
| 108 | .fb_copyarea = drm_fb_helper_cfb_copyarea, |
| 109 | .fb_imageblit = drm_fb_helper_cfb_imageblit, |
Rodrigo Vivi | d9a946b | 2015-05-28 10:26:58 -0700 | [diff] [blame] | 110 | .fb_pan_display = intel_fbdev_pan_display, |
Rodrigo Vivi | 03e515f | 2015-03-09 17:57:07 -0700 | [diff] [blame] | 111 | .fb_blank = intel_fbdev_blank, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 112 | }; |
| 113 | |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 114 | static int intelfb_alloc(struct drm_fb_helper *helper, |
| 115 | struct drm_fb_helper_surface_size *sizes) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 116 | { |
Ville Syrjälä | 3430824 | 2013-05-31 20:07:05 +0300 | [diff] [blame] | 117 | struct intel_fbdev *ifbdev = |
| 118 | container_of(helper, struct intel_fbdev, helper); |
Lukas Wunner | 4601b93 | 2015-12-19 15:40:39 +0100 | [diff] [blame] | 119 | struct drm_framebuffer *fb; |
Ville Syrjälä | 3430824 | 2013-05-31 20:07:05 +0300 | [diff] [blame] | 120 | struct drm_device *dev = helper->dev; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 121 | struct drm_i915_private *dev_priv = to_i915(dev); |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 122 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Ville Syrjälä | 3a7f2f6 | 2012-05-24 21:08:56 +0300 | [diff] [blame] | 123 | struct drm_mode_fb_cmd2 mode_cmd = {}; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 124 | struct drm_i915_gem_object *obj = NULL; |
James Simmons | 57084d0 | 2010-12-20 19:10:39 +0000 | [diff] [blame] | 125 | int size, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 126 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 127 | /* we don't do packed 24bpp */ |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 128 | if (sizes->surface_bpp == 24) |
| 129 | sizes->surface_bpp = 32; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 130 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 131 | mode_cmd.width = sizes->surface_width; |
| 132 | mode_cmd.height = sizes->surface_height; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 133 | |
Paulo Zanoni | de45eaf | 2013-10-18 18:48:24 -0300 | [diff] [blame] | 134 | mode_cmd.pitches[0] = ALIGN(mode_cmd.width * |
| 135 | DIV_ROUND_UP(sizes->surface_bpp, 8), 64); |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 136 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, |
| 137 | sizes->surface_depth); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 138 | |
Tvrtko Ursulin | 51f1385 | 2015-06-30 10:06:27 +0100 | [diff] [blame] | 139 | mutex_lock(&dev->struct_mutex); |
| 140 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 141 | size = mode_cmd.pitches[0] * mode_cmd.height; |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 142 | size = PAGE_ALIGN(size); |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 143 | |
| 144 | /* If the FB is too big, just don't use it since fbdev is not very |
| 145 | * important and we should probably use that space with FBC or other |
| 146 | * features. */ |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 147 | if (size * 2 < ggtt->stolen_usable_size) |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 148 | obj = i915_gem_object_create_stolen(dev, size); |
Chris Wilson | 0ffb0ff | 2012-11-15 11:32:27 +0000 | [diff] [blame] | 149 | if (obj == NULL) |
Dave Gordon | d37cd8a | 2016-04-22 19:14:32 +0100 | [diff] [blame] | 150 | obj = i915_gem_object_create(dev, size); |
Chris Wilson | fe3db79 | 2016-04-25 13:32:13 +0100 | [diff] [blame] | 151 | if (IS_ERR(obj)) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 152 | DRM_ERROR("failed to allocate framebuffer\n"); |
Chris Wilson | fe3db79 | 2016-04-25 13:32:13 +0100 | [diff] [blame] | 153 | ret = PTR_ERR(obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 154 | goto out; |
| 155 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 156 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 157 | fb = __intel_framebuffer_create(dev, &mode_cmd, obj); |
| 158 | if (IS_ERR(fb)) { |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 159 | i915_gem_object_put(obj); |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 160 | ret = PTR_ERR(fb); |
Lukas Wunner | ca40ba85 | 2015-10-22 13:37:18 +0200 | [diff] [blame] | 161 | goto out; |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Tvrtko Ursulin | 51f1385 | 2015-06-30 10:06:27 +0100 | [diff] [blame] | 164 | mutex_unlock(&dev->struct_mutex); |
| 165 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 166 | ifbdev->fb = to_intel_framebuffer(fb); |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 167 | |
| 168 | return 0; |
| 169 | |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 170 | out: |
Tvrtko Ursulin | 51f1385 | 2015-06-30 10:06:27 +0100 | [diff] [blame] | 171 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 172 | return ret; |
| 173 | } |
| 174 | |
| 175 | static int intelfb_create(struct drm_fb_helper *helper, |
| 176 | struct drm_fb_helper_surface_size *sizes) |
| 177 | { |
| 178 | struct intel_fbdev *ifbdev = |
| 179 | container_of(helper, struct intel_fbdev, helper); |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 180 | struct intel_framebuffer *intel_fb = ifbdev->fb; |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 181 | struct drm_device *dev = helper->dev; |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 182 | struct drm_i915_private *dev_priv = to_i915(dev); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 183 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 184 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 185 | struct fb_info *info; |
| 186 | struct drm_framebuffer *fb; |
Chris Wilson | 8ef8561 | 2016-04-28 09:56:39 +0100 | [diff] [blame] | 187 | struct i915_vma *vma; |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 188 | bool prealloc = false; |
Chris Wilson | 406ea8d | 2016-07-20 13:31:55 +0100 | [diff] [blame] | 189 | void __iomem *vaddr; |
Chris Wilson | 8ef8561 | 2016-04-28 09:56:39 +0100 | [diff] [blame] | 190 | int ret; |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 191 | |
Chris Wilson | edd586f | 2014-04-23 08:54:31 +0100 | [diff] [blame] | 192 | if (intel_fb && |
| 193 | (sizes->fb_width > intel_fb->base.width || |
| 194 | sizes->fb_height > intel_fb->base.height)) { |
| 195 | DRM_DEBUG_KMS("BIOS fb too small (%dx%d), we require (%dx%d)," |
| 196 | " releasing it\n", |
| 197 | intel_fb->base.width, intel_fb->base.height, |
| 198 | sizes->fb_width, sizes->fb_height); |
| 199 | drm_framebuffer_unreference(&intel_fb->base); |
| 200 | intel_fb = ifbdev->fb = NULL; |
| 201 | } |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 202 | if (!intel_fb || WARN_ON(!intel_fb->obj)) { |
Jesse Barnes | 48e9212 | 2013-11-26 11:25:54 -0800 | [diff] [blame] | 203 | DRM_DEBUG_KMS("no BIOS fb, allocating a new one\n"); |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 204 | ret = intelfb_alloc(helper, sizes); |
| 205 | if (ret) |
Tvrtko Ursulin | 51f1385 | 2015-06-30 10:06:27 +0100 | [diff] [blame] | 206 | return ret; |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 207 | intel_fb = ifbdev->fb; |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 208 | } else { |
Jesse Barnes | 48e9212 | 2013-11-26 11:25:54 -0800 | [diff] [blame] | 209 | DRM_DEBUG_KMS("re-using BIOS fb\n"); |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 210 | prealloc = true; |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 211 | sizes->fb_width = intel_fb->base.width; |
| 212 | sizes->fb_height = intel_fb->base.height; |
| 213 | } |
| 214 | |
Tvrtko Ursulin | 51f1385 | 2015-06-30 10:06:27 +0100 | [diff] [blame] | 215 | mutex_lock(&dev->struct_mutex); |
| 216 | |
Chris Wilson | 0c82312 | 2015-12-04 16:05:26 +0000 | [diff] [blame] | 217 | /* Pin the GGTT vma for our access via info->screen_base. |
| 218 | * This also validates that any existing fb inherited from the |
| 219 | * BIOS is suitable for own access. |
| 220 | */ |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 221 | vma = intel_pin_and_fence_fb_obj(&ifbdev->fb->base, DRM_ROTATE_0); |
| 222 | if (IS_ERR(vma)) { |
| 223 | ret = PTR_ERR(vma); |
Chris Wilson | 0c82312 | 2015-12-04 16:05:26 +0000 | [diff] [blame] | 224 | goto out_unlock; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 225 | } |
Chris Wilson | 0c82312 | 2015-12-04 16:05:26 +0000 | [diff] [blame] | 226 | |
Archit Taneja | 21cff14 | 2015-07-31 16:21:56 +0530 | [diff] [blame] | 227 | info = drm_fb_helper_alloc_fbi(helper); |
| 228 | if (IS_ERR(info)) { |
Lukas Wunner | 366e39b | 2015-11-18 16:29:51 +0100 | [diff] [blame] | 229 | DRM_ERROR("Failed to allocate fb_info\n"); |
Archit Taneja | 21cff14 | 2015-07-31 16:21:56 +0530 | [diff] [blame] | 230 | ret = PTR_ERR(info); |
Chris Wilson | b4476f5 | 2009-02-11 14:26:36 +0000 | [diff] [blame] | 231 | goto out_unpin; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 232 | } |
| 233 | |
Ville Syrjälä | 3430824 | 2013-05-31 20:07:05 +0300 | [diff] [blame] | 234 | info->par = helper; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 235 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 236 | fb = &ifbdev->fb->base; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 237 | |
| 238 | ifbdev->helper.fb = fb; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 239 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 240 | strcpy(info->fix.id, "inteldrmfb"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 241 | |
Jesse Barnes | 8fd4bd2 | 2010-06-23 12:56:12 -0700 | [diff] [blame] | 242 | info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 243 | info->fbops = &intelfb_ops; |
| 244 | |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 245 | /* setup aperture base/size for vesafb takeover */ |
Marcin Slusarz | 1471ca9 | 2010-05-16 17:27:03 +0200 | [diff] [blame] | 246 | info->apertures->ranges[0].base = dev->mode_config.fb_base; |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 247 | info->apertures->ranges[0].size = ggtt->mappable_end; |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 248 | |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 249 | info->fix.smem_start = dev->mode_config.fb_base + i915_ggtt_offset(vma); |
Chris Wilson | 8ef8561 | 2016-04-28 09:56:39 +0100 | [diff] [blame] | 250 | info->fix.smem_len = vma->node.size; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 251 | |
Chris Wilson | 8ef8561 | 2016-04-28 09:56:39 +0100 | [diff] [blame] | 252 | vaddr = i915_vma_pin_iomap(vma); |
| 253 | if (IS_ERR(vaddr)) { |
Lukas Wunner | 366e39b | 2015-11-18 16:29:51 +0100 | [diff] [blame] | 254 | DRM_ERROR("Failed to remap framebuffer into virtual memory\n"); |
Chris Wilson | 8ef8561 | 2016-04-28 09:56:39 +0100 | [diff] [blame] | 255 | ret = PTR_ERR(vaddr); |
Archit Taneja | 21cff14 | 2015-07-31 16:21:56 +0530 | [diff] [blame] | 256 | goto out_destroy_fbi; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 257 | } |
Chris Wilson | 8ef8561 | 2016-04-28 09:56:39 +0100 | [diff] [blame] | 258 | info->screen_base = vaddr; |
| 259 | info->screen_size = vma->node.size; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 260 | |
Jesse Barnes | 24576d2 | 2013-03-26 09:25:45 -0700 | [diff] [blame] | 261 | /* This driver doesn't need a VT switch to restore the mode on resume */ |
| 262 | info->skip_vt_switch = true; |
| 263 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 264 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 265 | drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 266 | |
Chris Wilson | 88afe71 | 2012-12-16 12:15:41 +0000 | [diff] [blame] | 267 | /* If the object is shmemfs backed, it will have given us zeroed pages. |
| 268 | * If the object is stolen however, it will be full of whatever |
| 269 | * garbage was left in there. |
| 270 | */ |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 271 | if (intel_fb->obj->stolen && !prealloc) |
Chris Wilson | 88afe71 | 2012-12-16 12:15:41 +0000 | [diff] [blame] | 272 | memset_io(info->screen_base, 0, info->screen_size); |
| 273 | |
Sascha Hauer | fb2a99e | 2012-02-06 10:58:19 +0100 | [diff] [blame] | 274 | /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */ |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 275 | |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 276 | DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08x\n", |
| 277 | fb->width, fb->height, i915_ggtt_offset(vma)); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 278 | ifbdev->vma = vma; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 279 | |
| 280 | mutex_unlock(&dev->struct_mutex); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 281 | vga_switcheroo_client_fb_set(pdev, info); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 282 | return 0; |
| 283 | |
Archit Taneja | 21cff14 | 2015-07-31 16:21:56 +0530 | [diff] [blame] | 284 | out_destroy_fbi: |
| 285 | drm_fb_helper_release_fbi(helper); |
Chris Wilson | b4476f5 | 2009-02-11 14:26:36 +0000 | [diff] [blame] | 286 | out_unpin: |
Joonas Lahtinen | 31ad61e | 2016-07-29 08:50:05 +0300 | [diff] [blame] | 287 | intel_unpin_fb_obj(&ifbdev->fb->base, DRM_ROTATE_0); |
Chris Wilson | 0c82312 | 2015-12-04 16:05:26 +0000 | [diff] [blame] | 288 | out_unlock: |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 289 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 290 | return ret; |
| 291 | } |
| 292 | |
Paulo Zanoni | 6743768 | 2013-09-24 13:52:56 -0300 | [diff] [blame] | 293 | /** Sets the color ramps on behalf of RandR */ |
| 294 | static void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
| 295 | u16 blue, int regno) |
| 296 | { |
| 297 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 298 | |
| 299 | intel_crtc->lut_r[regno] = red >> 8; |
| 300 | intel_crtc->lut_g[regno] = green >> 8; |
| 301 | intel_crtc->lut_b[regno] = blue >> 8; |
| 302 | } |
| 303 | |
| 304 | static void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, |
| 305 | u16 *blue, int regno) |
| 306 | { |
| 307 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 308 | |
| 309 | *red = intel_crtc->lut_r[regno] << 8; |
| 310 | *green = intel_crtc->lut_g[regno] << 8; |
| 311 | *blue = intel_crtc->lut_b[regno] << 8; |
| 312 | } |
| 313 | |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 314 | static struct drm_fb_helper_crtc * |
| 315 | intel_fb_helper_crtc(struct drm_fb_helper *fb_helper, struct drm_crtc *crtc) |
| 316 | { |
| 317 | int i; |
| 318 | |
| 319 | for (i = 0; i < fb_helper->crtc_count; i++) |
| 320 | if (fb_helper->crtc_info[i].mode_set.crtc == crtc) |
| 321 | return &fb_helper->crtc_info[i]; |
| 322 | |
| 323 | return NULL; |
| 324 | } |
| 325 | |
| 326 | /* |
| 327 | * Try to read the BIOS display configuration and use it for the initial |
| 328 | * fb configuration. |
| 329 | * |
| 330 | * The BIOS or boot loader will generally create an initial display |
| 331 | * configuration for us that includes some set of active pipes and displays. |
| 332 | * This routine tries to figure out which pipes and connectors are active |
| 333 | * and stuffs them into the crtcs and modes array given to us by the |
| 334 | * drm_fb_helper code. |
| 335 | * |
| 336 | * The overall sequence is: |
| 337 | * intel_fbdev_init - from driver load |
| 338 | * intel_fbdev_init_bios - initialize the intel_fbdev using BIOS data |
| 339 | * drm_fb_helper_init - build fb helper structs |
| 340 | * drm_fb_helper_single_add_all_connectors - more fb helper structs |
| 341 | * intel_fbdev_initial_config - apply the config |
| 342 | * drm_fb_helper_initial_config - call ->probe then register_framebuffer() |
| 343 | * drm_setup_crtcs - build crtc config for fbdev |
| 344 | * intel_fb_initial_config - find active connectors etc |
| 345 | * drm_fb_helper_single_fb_probe - set up fbdev |
| 346 | * intelfb_create - re-use or alloc fb, build out fbdev structs |
| 347 | * |
| 348 | * Note that we don't make special consideration whether we could actually |
| 349 | * switch to the selected modes without a full modeset. E.g. when the display |
| 350 | * is in VGA mode we need to recalculate watermarks and set a new high-res |
| 351 | * framebuffer anyway. |
| 352 | */ |
| 353 | static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper, |
| 354 | struct drm_fb_helper_crtc **crtcs, |
| 355 | struct drm_display_mode **modes, |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 356 | struct drm_fb_offset *offsets, |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 357 | bool *enabled, int width, int height) |
| 358 | { |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 359 | struct drm_i915_private *dev_priv = to_i915(fb_helper->dev); |
Chris Wilson | 86f40bb | 2016-07-02 15:36:02 +0100 | [diff] [blame] | 360 | unsigned long conn_configured, mask; |
| 361 | unsigned int count = min(fb_helper->connector_count, BITS_PER_LONG); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 362 | int i, j; |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 363 | bool *save_enabled; |
Daniel Vetter | 7c2bb53 | 2014-03-04 21:08:41 +0100 | [diff] [blame] | 364 | bool fallback = true; |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 365 | int num_connectors_enabled = 0; |
| 366 | int num_connectors_detected = 0; |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 367 | int pass = 0; |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 368 | |
Chris Wilson | 86f40bb | 2016-07-02 15:36:02 +0100 | [diff] [blame] | 369 | save_enabled = kcalloc(count, sizeof(bool), GFP_KERNEL); |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 370 | if (!save_enabled) |
| 371 | return false; |
| 372 | |
Chris Wilson | 86f40bb | 2016-07-02 15:36:02 +0100 | [diff] [blame] | 373 | memcpy(save_enabled, enabled, count); |
| 374 | mask = BIT(count) - 1; |
| 375 | conn_configured = 0; |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 376 | retry: |
Chris Wilson | 86f40bb | 2016-07-02 15:36:02 +0100 | [diff] [blame] | 377 | for (i = 0; i < count; i++) { |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 378 | struct drm_fb_helper_connector *fb_conn; |
| 379 | struct drm_connector *connector; |
| 380 | struct drm_encoder *encoder; |
| 381 | struct drm_fb_helper_crtc *new_crtc; |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 382 | struct intel_crtc *intel_crtc; |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 383 | |
| 384 | fb_conn = fb_helper->connector_info[i]; |
| 385 | connector = fb_conn->connector; |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 386 | |
Chris Wilson | 86f40bb | 2016-07-02 15:36:02 +0100 | [diff] [blame] | 387 | if (conn_configured & BIT(i)) |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 388 | continue; |
| 389 | |
| 390 | if (pass == 0 && !connector->has_tile) |
| 391 | continue; |
| 392 | |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 393 | if (connector->status == connector_status_connected) |
| 394 | num_connectors_detected++; |
| 395 | |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 396 | if (!enabled[i]) { |
Chris Wilson | c0c9762 | 2014-05-13 13:45:09 +0100 | [diff] [blame] | 397 | DRM_DEBUG_KMS("connector %s not enabled, skipping\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 398 | connector->name); |
Chris Wilson | 86f40bb | 2016-07-02 15:36:02 +0100 | [diff] [blame] | 399 | conn_configured |= BIT(i); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 400 | continue; |
| 401 | } |
| 402 | |
Chris Wilson | d84a0f3 | 2014-08-18 10:35:29 -0700 | [diff] [blame] | 403 | if (connector->force == DRM_FORCE_OFF) { |
| 404 | DRM_DEBUG_KMS("connector %s is disabled by user, skipping\n", |
| 405 | connector->name); |
| 406 | enabled[i] = false; |
| 407 | continue; |
| 408 | } |
| 409 | |
Maarten Lankhorst | e28661b | 2016-02-17 09:18:39 +0100 | [diff] [blame] | 410 | encoder = connector->state->best_encoder; |
| 411 | if (!encoder || WARN_ON(!connector->state->crtc)) { |
Chris Wilson | d84a0f3 | 2014-08-18 10:35:29 -0700 | [diff] [blame] | 412 | if (connector->force > DRM_FORCE_OFF) |
| 413 | goto bail; |
| 414 | |
Chris Wilson | c0c9762 | 2014-05-13 13:45:09 +0100 | [diff] [blame] | 415 | DRM_DEBUG_KMS("connector %s has no encoder or crtc, skipping\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 416 | connector->name); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 417 | enabled[i] = false; |
Chris Wilson | 86f40bb | 2016-07-02 15:36:02 +0100 | [diff] [blame] | 418 | conn_configured |= BIT(i); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 419 | continue; |
| 420 | } |
| 421 | |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 422 | num_connectors_enabled++; |
| 423 | |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 424 | intel_crtc = to_intel_crtc(connector->state->crtc); |
| 425 | for (j = 0; j < 256; j++) { |
| 426 | intel_crtc->lut_r[j] = j; |
| 427 | intel_crtc->lut_g[j] = j; |
| 428 | intel_crtc->lut_b[j] = j; |
| 429 | } |
| 430 | |
Chris Wilson | 86f40bb | 2016-07-02 15:36:02 +0100 | [diff] [blame] | 431 | new_crtc = intel_fb_helper_crtc(fb_helper, |
| 432 | connector->state->crtc); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 433 | |
| 434 | /* |
| 435 | * Make sure we're not trying to drive multiple connectors |
| 436 | * with a single CRTC, since our cloning support may not |
| 437 | * match the BIOS. |
| 438 | */ |
Chris Wilson | 86f40bb | 2016-07-02 15:36:02 +0100 | [diff] [blame] | 439 | for (j = 0; j < count; j++) { |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 440 | if (crtcs[j] == new_crtc) { |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 441 | DRM_DEBUG_KMS("fallback: cloned configuration\n"); |
Chris Wilson | d84a0f3 | 2014-08-18 10:35:29 -0700 | [diff] [blame] | 442 | goto bail; |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 443 | } |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 444 | } |
| 445 | |
Chris Wilson | c0c9762 | 2014-05-13 13:45:09 +0100 | [diff] [blame] | 446 | DRM_DEBUG_KMS("looking for cmdline mode on connector %s\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 447 | connector->name); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 448 | |
| 449 | /* go for command line mode first */ |
| 450 | modes[i] = drm_pick_cmdline_mode(fb_conn, width, height); |
| 451 | |
| 452 | /* try for preferred next */ |
| 453 | if (!modes[i]) { |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 454 | DRM_DEBUG_KMS("looking for preferred mode on connector %s %d\n", |
| 455 | connector->name, connector->has_tile); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 456 | modes[i] = drm_has_preferred_mode(fb_conn, width, |
| 457 | height); |
| 458 | } |
| 459 | |
Chris Wilson | afba0b5 | 2014-05-13 16:07:37 +0100 | [diff] [blame] | 460 | /* No preferred mode marked by the EDID? Are there any modes? */ |
| 461 | if (!modes[i] && !list_empty(&connector->modes)) { |
| 462 | DRM_DEBUG_KMS("using first mode listed on connector %s\n", |
Dave Airlie | 8d4ad9d | 2014-06-05 20:28:59 +1000 | [diff] [blame] | 463 | connector->name); |
Chris Wilson | afba0b5 | 2014-05-13 16:07:37 +0100 | [diff] [blame] | 464 | modes[i] = list_first_entry(&connector->modes, |
| 465 | struct drm_display_mode, |
| 466 | head); |
| 467 | } |
| 468 | |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 469 | /* last resort: use current mode */ |
| 470 | if (!modes[i]) { |
| 471 | /* |
| 472 | * IMPORTANT: We want to use the adjusted mode (i.e. |
| 473 | * after the panel fitter upscaling) as the initial |
| 474 | * config, not the input mode, which is what crtc->mode |
Maarten Lankhorst | 5c1e342 | 2015-07-14 15:58:28 +0200 | [diff] [blame] | 475 | * usually contains. But since our current |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 476 | * code puts a mode derived from the post-pfit timings |
Maarten Lankhorst | 5c1e342 | 2015-07-14 15:58:28 +0200 | [diff] [blame] | 477 | * into crtc->mode this works out correctly. |
Maarten Lankhorst | e28661b | 2016-02-17 09:18:39 +0100 | [diff] [blame] | 478 | * |
| 479 | * This is crtc->mode and not crtc->state->mode for the |
| 480 | * fastboot check to work correctly. crtc_state->mode has |
| 481 | * I915_MODE_FLAG_INHERITED, which we clear to force check |
| 482 | * state. |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 483 | */ |
Chris Wilson | c0c9762 | 2014-05-13 13:45:09 +0100 | [diff] [blame] | 484 | DRM_DEBUG_KMS("looking for current mode on connector %s\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 485 | connector->name); |
Maarten Lankhorst | e28661b | 2016-02-17 09:18:39 +0100 | [diff] [blame] | 486 | modes[i] = &connector->state->crtc->mode; |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 487 | } |
| 488 | crtcs[i] = new_crtc; |
| 489 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 490 | DRM_DEBUG_KMS("connector %s on [CRTC:%d:%s]: %dx%d%s\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 491 | connector->name, |
Maarten Lankhorst | e28661b | 2016-02-17 09:18:39 +0100 | [diff] [blame] | 492 | connector->state->crtc->base.id, |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 493 | connector->state->crtc->name, |
Chris Wilson | c0c9762 | 2014-05-13 13:45:09 +0100 | [diff] [blame] | 494 | modes[i]->hdisplay, modes[i]->vdisplay, |
| 495 | modes[i]->flags & DRM_MODE_FLAG_INTERLACE ? "i" :""); |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 496 | |
Daniel Vetter | 7c2bb53 | 2014-03-04 21:08:41 +0100 | [diff] [blame] | 497 | fallback = false; |
Chris Wilson | 86f40bb | 2016-07-02 15:36:02 +0100 | [diff] [blame] | 498 | conn_configured |= BIT(i); |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | if ((conn_configured & mask) != mask) { |
| 502 | pass++; |
| 503 | goto retry; |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 504 | } |
| 505 | |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 506 | /* |
| 507 | * If the BIOS didn't enable everything it could, fall back to have the |
| 508 | * same user experiencing of lighting up as much as possible like the |
| 509 | * fbdev helper library. |
| 510 | */ |
| 511 | if (num_connectors_enabled != num_connectors_detected && |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 512 | num_connectors_enabled < INTEL_INFO(dev_priv)->num_pipes) { |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 513 | DRM_DEBUG_KMS("fallback: Not all outputs enabled\n"); |
| 514 | DRM_DEBUG_KMS("Enabled: %i, detected: %i\n", num_connectors_enabled, |
| 515 | num_connectors_detected); |
| 516 | fallback = true; |
| 517 | } |
| 518 | |
Daniel Vetter | 7c2bb53 | 2014-03-04 21:08:41 +0100 | [diff] [blame] | 519 | if (fallback) { |
Chris Wilson | d84a0f3 | 2014-08-18 10:35:29 -0700 | [diff] [blame] | 520 | bail: |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 521 | DRM_DEBUG_KMS("Not using firmware configuration\n"); |
Chris Wilson | 86f40bb | 2016-07-02 15:36:02 +0100 | [diff] [blame] | 522 | memcpy(enabled, save_enabled, count); |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 523 | kfree(save_enabled); |
| 524 | return false; |
| 525 | } |
| 526 | |
| 527 | kfree(save_enabled); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 528 | return true; |
| 529 | } |
| 530 | |
Thierry Reding | 3a49387 | 2014-06-27 17:19:23 +0200 | [diff] [blame] | 531 | static const struct drm_fb_helper_funcs intel_fb_helper_funcs = { |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 532 | .initial_config = intel_fb_initial_config, |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 533 | .gamma_set = intel_crtc_fb_gamma_set, |
| 534 | .gamma_get = intel_crtc_fb_gamma_get, |
Daniel Vetter | cd5428a | 2013-01-21 23:42:49 +0100 | [diff] [blame] | 535 | .fb_probe = intelfb_create, |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 536 | }; |
| 537 | |
Chris Wilson | 43cee31 | 2016-06-21 09:16:54 +0100 | [diff] [blame] | 538 | static void intel_fbdev_destroy(struct intel_fbdev *ifbdev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 539 | { |
Chris Wilson | 0c82312 | 2015-12-04 16:05:26 +0000 | [diff] [blame] | 540 | /* We rely on the object-free to release the VMA pinning for |
| 541 | * the info->screen_base mmaping. Leaking the VMA is simpler than |
| 542 | * trying to rectify all the possible error paths leading here. |
| 543 | */ |
Chris Wilson | ddfe156 | 2013-08-06 17:43:07 +0100 | [diff] [blame] | 544 | |
Archit Taneja | 21cff14 | 2015-07-31 16:21:56 +0530 | [diff] [blame] | 545 | drm_fb_helper_unregister_fbi(&ifbdev->helper); |
| 546 | drm_fb_helper_release_fbi(&ifbdev->helper); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 547 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 548 | drm_fb_helper_fini(&ifbdev->helper); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 549 | |
Lukas Wunner | 54632ab | 2015-11-18 13:43:20 +0100 | [diff] [blame] | 550 | if (ifbdev->fb) { |
Chris Wilson | 43cee31 | 2016-06-21 09:16:54 +0100 | [diff] [blame] | 551 | mutex_lock(&ifbdev->helper.dev->struct_mutex); |
Joonas Lahtinen | 31ad61e | 2016-07-29 08:50:05 +0300 | [diff] [blame] | 552 | intel_unpin_fb_obj(&ifbdev->fb->base, DRM_ROTATE_0); |
Chris Wilson | 43cee31 | 2016-06-21 09:16:54 +0100 | [diff] [blame] | 553 | mutex_unlock(&ifbdev->helper.dev->struct_mutex); |
Chris Wilson | fb4b8ce | 2016-04-28 09:56:35 +0100 | [diff] [blame] | 554 | |
Lukas Wunner | 54632ab | 2015-11-18 13:43:20 +0100 | [diff] [blame] | 555 | drm_framebuffer_remove(&ifbdev->fb->base); |
| 556 | } |
Chris Wilson | 43cee31 | 2016-06-21 09:16:54 +0100 | [diff] [blame] | 557 | |
| 558 | kfree(ifbdev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 559 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 560 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 561 | /* |
| 562 | * Build an intel_fbdev struct using a BIOS allocated framebuffer, if possible. |
| 563 | * The core display code will have read out the current plane configuration, |
| 564 | * so we use that to figure out if there's an object for us to use as the |
| 565 | * fb, and if so, we re-use it for the fbdev configuration. |
| 566 | * |
| 567 | * Note we only support a single fb shared across pipes for boot (mostly for |
| 568 | * fbcon), so we just find the biggest and use that. |
| 569 | */ |
| 570 | static bool intel_fbdev_init_bios(struct drm_device *dev, |
| 571 | struct intel_fbdev *ifbdev) |
| 572 | { |
| 573 | struct intel_framebuffer *fb = NULL; |
| 574 | struct drm_crtc *crtc; |
| 575 | struct intel_crtc *intel_crtc; |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 576 | unsigned int max_size = 0; |
| 577 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 578 | /* Find the largest fb */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 579 | for_each_crtc(dev, crtc) { |
Maarten Lankhorst | 8e9ba31 | 2015-07-13 16:30:16 +0200 | [diff] [blame] | 580 | struct drm_i915_gem_object *obj = |
| 581 | intel_fb_obj(crtc->primary->state->fb); |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 582 | intel_crtc = to_intel_crtc(crtc); |
| 583 | |
Maarten Lankhorst | d551599 | 2015-08-27 15:44:03 +0200 | [diff] [blame] | 584 | if (!crtc->state->active || !obj) { |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 585 | DRM_DEBUG_KMS("pipe %c not active or no fb, skipping\n", |
| 586 | pipe_name(intel_crtc->pipe)); |
| 587 | continue; |
| 588 | } |
| 589 | |
Maarten Lankhorst | 8e9ba31 | 2015-07-13 16:30:16 +0200 | [diff] [blame] | 590 | if (obj->base.size > max_size) { |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 591 | DRM_DEBUG_KMS("found possible fb from plane %c\n", |
| 592 | pipe_name(intel_crtc->pipe)); |
Maarten Lankhorst | 8e9ba31 | 2015-07-13 16:30:16 +0200 | [diff] [blame] | 593 | fb = to_intel_framebuffer(crtc->primary->state->fb); |
| 594 | max_size = obj->base.size; |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | |
| 598 | if (!fb) { |
| 599 | DRM_DEBUG_KMS("no active fbs found, not using BIOS config\n"); |
| 600 | goto out; |
| 601 | } |
| 602 | |
| 603 | /* Now make sure all the pipes will fit into it */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 604 | for_each_crtc(dev, crtc) { |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 605 | unsigned int cur_size; |
| 606 | |
| 607 | intel_crtc = to_intel_crtc(crtc); |
| 608 | |
Maarten Lankhorst | d551599 | 2015-08-27 15:44:03 +0200 | [diff] [blame] | 609 | if (!crtc->state->active) { |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 610 | DRM_DEBUG_KMS("pipe %c not active, skipping\n", |
| 611 | pipe_name(intel_crtc->pipe)); |
| 612 | continue; |
| 613 | } |
| 614 | |
| 615 | DRM_DEBUG_KMS("checking plane %c for BIOS fb\n", |
| 616 | pipe_name(intel_crtc->pipe)); |
| 617 | |
| 618 | /* |
| 619 | * See if the plane fb we found above will fit on this |
Chris Wilson | bc104d1 | 2014-03-20 15:11:21 +0000 | [diff] [blame] | 620 | * pipe. Note we need to use the selected fb's pitch and bpp |
| 621 | * rather than the current pipe's, since they differ. |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 622 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 623 | cur_size = intel_crtc->config->base.adjusted_mode.crtc_hdisplay; |
Chris Wilson | bc104d1 | 2014-03-20 15:11:21 +0000 | [diff] [blame] | 624 | cur_size = cur_size * fb->base.bits_per_pixel / 8; |
| 625 | if (fb->base.pitches[0] < cur_size) { |
| 626 | DRM_DEBUG_KMS("fb not wide enough for plane %c (%d vs %d)\n", |
| 627 | pipe_name(intel_crtc->pipe), |
| 628 | cur_size, fb->base.pitches[0]); |
Chris Wilson | bc104d1 | 2014-03-20 15:11:21 +0000 | [diff] [blame] | 629 | fb = NULL; |
| 630 | break; |
| 631 | } |
| 632 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 633 | cur_size = intel_crtc->config->base.adjusted_mode.crtc_vdisplay; |
Damien Lespiau | ec2c981 | 2015-01-20 12:51:45 +0000 | [diff] [blame] | 634 | cur_size = intel_fb_align_height(dev, cur_size, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 635 | fb->base.pixel_format, |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 636 | fb->base.modifier); |
Chris Wilson | bc104d1 | 2014-03-20 15:11:21 +0000 | [diff] [blame] | 637 | cur_size *= fb->base.pitches[0]; |
| 638 | DRM_DEBUG_KMS("pipe %c area: %dx%d, bpp: %d, size: %d\n", |
| 639 | pipe_name(intel_crtc->pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 640 | intel_crtc->config->base.adjusted_mode.crtc_hdisplay, |
| 641 | intel_crtc->config->base.adjusted_mode.crtc_vdisplay, |
Chris Wilson | bc104d1 | 2014-03-20 15:11:21 +0000 | [diff] [blame] | 642 | fb->base.bits_per_pixel, |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 643 | cur_size); |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 644 | |
| 645 | if (cur_size > max_size) { |
| 646 | DRM_DEBUG_KMS("fb not big enough for plane %c (%d vs %d)\n", |
| 647 | pipe_name(intel_crtc->pipe), |
| 648 | cur_size, max_size); |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 649 | fb = NULL; |
| 650 | break; |
| 651 | } |
| 652 | |
| 653 | DRM_DEBUG_KMS("fb big enough for plane %c (%d >= %d)\n", |
| 654 | pipe_name(intel_crtc->pipe), |
| 655 | max_size, cur_size); |
| 656 | } |
| 657 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 658 | if (!fb) { |
| 659 | DRM_DEBUG_KMS("BIOS fb not suitable for all pipes, not using\n"); |
| 660 | goto out; |
| 661 | } |
| 662 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 663 | ifbdev->preferred_bpp = fb->base.bits_per_pixel; |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 664 | ifbdev->fb = fb; |
| 665 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 666 | drm_framebuffer_reference(&ifbdev->fb->base); |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 667 | |
| 668 | /* Final pass to check if any active pipes don't have fbs */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 669 | for_each_crtc(dev, crtc) { |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 670 | intel_crtc = to_intel_crtc(crtc); |
| 671 | |
Maarten Lankhorst | d551599 | 2015-08-27 15:44:03 +0200 | [diff] [blame] | 672 | if (!crtc->state->active) |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 673 | continue; |
| 674 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 675 | WARN(!crtc->primary->fb, |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 676 | "re-used BIOS config but lost an fb on crtc %d\n", |
| 677 | crtc->base.id); |
| 678 | } |
| 679 | |
| 680 | |
| 681 | DRM_DEBUG_KMS("using BIOS fb for initial console\n"); |
| 682 | return true; |
| 683 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 684 | out: |
| 685 | |
| 686 | return false; |
| 687 | } |
| 688 | |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 689 | static void intel_fbdev_suspend_worker(struct work_struct *work) |
| 690 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 691 | intel_fbdev_set_suspend(&container_of(work, |
| 692 | struct drm_i915_private, |
| 693 | fbdev_suspend_work)->drm, |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 694 | FBINFO_STATE_RUNNING, |
| 695 | true); |
| 696 | } |
| 697 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 698 | int intel_fbdev_init(struct drm_device *dev) |
| 699 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 700 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 701 | struct intel_fbdev *ifbdev; |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 702 | int ret; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 703 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 704 | if (WARN_ON(INTEL_INFO(dev_priv)->num_pipes == 0)) |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 705 | return -ENODEV; |
| 706 | |
| 707 | ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL); |
| 708 | if (ifbdev == NULL) |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 709 | return -ENOMEM; |
| 710 | |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 711 | drm_fb_helper_prepare(dev, &ifbdev->helper, &intel_fb_helper_funcs); |
| 712 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 713 | if (!intel_fbdev_init_bios(dev, ifbdev)) |
| 714 | ifbdev->preferred_bpp = 32; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 715 | |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 716 | ret = drm_fb_helper_init(dev, &ifbdev->helper, |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 717 | INTEL_INFO(dev_priv)->num_pipes, 4); |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 718 | if (ret) { |
| 719 | kfree(ifbdev); |
| 720 | return ret; |
| 721 | } |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 722 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 723 | dev_priv->fbdev = ifbdev; |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 724 | INIT_WORK(&dev_priv->fbdev_suspend_work, intel_fbdev_suspend_worker); |
| 725 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 726 | drm_fb_helper_single_add_all_connectors(&ifbdev->helper); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 727 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 728 | return 0; |
| 729 | } |
| 730 | |
Ville Syrjälä | e00bf69 | 2015-11-06 15:08:33 +0200 | [diff] [blame] | 731 | static void intel_fbdev_initial_config(void *data, async_cookie_t cookie) |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 732 | { |
Chris Wilson | 43cee31 | 2016-06-21 09:16:54 +0100 | [diff] [blame] | 733 | struct intel_fbdev *ifbdev = data; |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 734 | |
| 735 | /* Due to peculiar init order wrt to hpd handling this is separate. */ |
Lukas Wunner | 366e39b | 2015-11-18 16:29:51 +0100 | [diff] [blame] | 736 | if (drm_fb_helper_initial_config(&ifbdev->helper, |
| 737 | ifbdev->preferred_bpp)) |
Chris Wilson | 43cee31 | 2016-06-21 09:16:54 +0100 | [diff] [blame] | 738 | intel_fbdev_fini(ifbdev->helper.dev); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 739 | } |
| 740 | |
Ville Syrjälä | e00bf69 | 2015-11-06 15:08:33 +0200 | [diff] [blame] | 741 | void intel_fbdev_initial_config_async(struct drm_device *dev) |
| 742 | { |
Chris Wilson | 43cee31 | 2016-06-21 09:16:54 +0100 | [diff] [blame] | 743 | struct intel_fbdev *ifbdev = to_i915(dev)->fbdev; |
| 744 | |
| 745 | ifbdev->cookie = async_schedule(intel_fbdev_initial_config, ifbdev); |
| 746 | } |
| 747 | |
| 748 | static void intel_fbdev_sync(struct intel_fbdev *ifbdev) |
| 749 | { |
| 750 | if (!ifbdev->cookie) |
| 751 | return; |
| 752 | |
| 753 | /* Only serialises with all preceding async calls, hence +1 */ |
| 754 | async_synchronize_cookie(ifbdev->cookie + 1); |
| 755 | ifbdev->cookie = 0; |
Ville Syrjälä | e00bf69 | 2015-11-06 15:08:33 +0200 | [diff] [blame] | 756 | } |
| 757 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 758 | void intel_fbdev_fini(struct drm_device *dev) |
| 759 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 760 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | 43cee31 | 2016-06-21 09:16:54 +0100 | [diff] [blame] | 761 | struct intel_fbdev *ifbdev = dev_priv->fbdev; |
| 762 | |
| 763 | if (!ifbdev) |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 764 | return; |
| 765 | |
Chris Wilson | 0b8c0e9 | 2016-07-13 18:34:44 +0100 | [diff] [blame] | 766 | cancel_work_sync(&dev_priv->fbdev_suspend_work); |
Lukas Wunner | 366e39b | 2015-11-18 16:29:51 +0100 | [diff] [blame] | 767 | if (!current_is_async()) |
Chris Wilson | 43cee31 | 2016-06-21 09:16:54 +0100 | [diff] [blame] | 768 | intel_fbdev_sync(ifbdev); |
| 769 | |
| 770 | intel_fbdev_destroy(ifbdev); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 771 | dev_priv->fbdev = NULL; |
| 772 | } |
Dave Airlie | 3fa016a | 2012-03-28 10:48:49 +0100 | [diff] [blame] | 773 | |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 774 | void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous) |
Dave Airlie | 3fa016a | 2012-03-28 10:48:49 +0100 | [diff] [blame] | 775 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 776 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 1ffc528 | 2013-05-07 18:54:05 +0300 | [diff] [blame] | 777 | struct intel_fbdev *ifbdev = dev_priv->fbdev; |
| 778 | struct fb_info *info; |
| 779 | |
Chris Wilson | c45eb4f | 2016-07-13 18:34:45 +0100 | [diff] [blame] | 780 | if (!ifbdev || !ifbdev->fb) |
Dave Airlie | 3fa016a | 2012-03-28 10:48:49 +0100 | [diff] [blame] | 781 | return; |
| 782 | |
Jani Nikula | 1ffc528 | 2013-05-07 18:54:05 +0300 | [diff] [blame] | 783 | info = ifbdev->helper.fbdev; |
| 784 | |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 785 | if (synchronous) { |
| 786 | /* Flush any pending work to turn the console on, and then |
| 787 | * wait to turn it off. It must be synchronous as we are |
| 788 | * about to suspend or unload the driver. |
| 789 | * |
| 790 | * Note that from within the work-handler, we cannot flush |
| 791 | * ourselves, so only flush outstanding work upon suspend! |
| 792 | */ |
| 793 | if (state != FBINFO_STATE_RUNNING) |
| 794 | flush_work(&dev_priv->fbdev_suspend_work); |
| 795 | console_lock(); |
| 796 | } else { |
| 797 | /* |
| 798 | * The console lock can be pretty contented on resume due |
| 799 | * to all the printk activity. Try to keep it out of the hot |
| 800 | * path of resume if possible. |
| 801 | */ |
| 802 | WARN_ON(state != FBINFO_STATE_RUNNING); |
| 803 | if (!console_trylock()) { |
| 804 | /* Don't block our own workqueue as this can |
| 805 | * be run in parallel with other i915.ko tasks. |
| 806 | */ |
| 807 | schedule_work(&dev_priv->fbdev_suspend_work); |
| 808 | return; |
| 809 | } |
| 810 | } |
| 811 | |
Jani Nikula | 1ffc528 | 2013-05-07 18:54:05 +0300 | [diff] [blame] | 812 | /* On resume from hibernation: If the object is shmemfs backed, it has |
| 813 | * been restored from swap. If the object is stolen however, it will be |
| 814 | * full of whatever garbage was left in there. |
| 815 | */ |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 816 | if (state == FBINFO_STATE_RUNNING && ifbdev->fb->obj->stolen) |
Jani Nikula | 1ffc528 | 2013-05-07 18:54:05 +0300 | [diff] [blame] | 817 | memset_io(info->screen_base, 0, info->screen_size); |
| 818 | |
Archit Taneja | 21cff14 | 2015-07-31 16:21:56 +0530 | [diff] [blame] | 819 | drm_fb_helper_set_suspend(&ifbdev->helper, state); |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 820 | console_unlock(); |
Dave Airlie | 3fa016a | 2012-03-28 10:48:49 +0100 | [diff] [blame] | 821 | } |
| 822 | |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 823 | void intel_fbdev_output_poll_changed(struct drm_device *dev) |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 824 | { |
Chris Wilson | c45eb4f | 2016-07-13 18:34:45 +0100 | [diff] [blame] | 825 | struct intel_fbdev *ifbdev = to_i915(dev)->fbdev; |
| 826 | |
| 827 | if (ifbdev && ifbdev->fb) |
| 828 | drm_fb_helper_hotplug_event(&ifbdev->helper); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 829 | } |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 830 | |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 831 | void intel_fbdev_restore_mode(struct drm_device *dev) |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 832 | { |
Chris Wilson | c45eb4f | 2016-07-13 18:34:45 +0100 | [diff] [blame] | 833 | struct intel_fbdev *ifbdev = to_i915(dev)->fbdev; |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 834 | |
Rodrigo Vivi | d04df73 | 2015-07-08 16:25:21 -0700 | [diff] [blame] | 835 | if (!ifbdev) |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 836 | return; |
| 837 | |
Chris Wilson | e77018f | 2016-06-21 09:16:55 +0100 | [diff] [blame] | 838 | intel_fbdev_sync(ifbdev); |
Chris Wilson | c45eb4f | 2016-07-13 18:34:45 +0100 | [diff] [blame] | 839 | if (!ifbdev->fb) |
| 840 | return; |
Chris Wilson | e77018f | 2016-06-21 09:16:55 +0100 | [diff] [blame] | 841 | |
Chris Wilson | c45eb4f | 2016-07-13 18:34:45 +0100 | [diff] [blame] | 842 | if (drm_fb_helper_restore_fbdev_mode_unlocked(&ifbdev->helper)) { |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 843 | DRM_DEBUG("failed to restore crtc mode\n"); |
Rodrigo Vivi | d04df73 | 2015-07-08 16:25:21 -0700 | [diff] [blame] | 844 | } else { |
Chris Wilson | c45eb4f | 2016-07-13 18:34:45 +0100 | [diff] [blame] | 845 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | d04df73 | 2015-07-08 16:25:21 -0700 | [diff] [blame] | 846 | intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT); |
Chris Wilson | c45eb4f | 2016-07-13 18:34:45 +0100 | [diff] [blame] | 847 | mutex_unlock(&dev->struct_mutex); |
Rodrigo Vivi | d04df73 | 2015-07-08 16:25:21 -0700 | [diff] [blame] | 848 | } |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 849 | } |