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