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 | |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/kernel.h> |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 29 | #include <linux/console.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 30 | #include <linux/errno.h> |
| 31 | #include <linux/string.h> |
| 32 | #include <linux/mm.h> |
| 33 | #include <linux/tty.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 34 | #include <linux/sysrq.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/fb.h> |
| 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" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 44 | #include <drm/i915_drm.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 45 | #include "i915_drv.h" |
| 46 | |
Daniel Vetter | e991077 | 2014-06-18 15:05:19 +0200 | [diff] [blame] | 47 | static int intel_fbdev_set_par(struct fb_info *info) |
| 48 | { |
| 49 | struct drm_fb_helper *fb_helper = info->par; |
| 50 | struct intel_fbdev *ifbdev = |
| 51 | container_of(fb_helper, struct intel_fbdev, helper); |
| 52 | int ret; |
| 53 | |
| 54 | ret = drm_fb_helper_set_par(info); |
| 55 | |
| 56 | if (ret == 0) { |
| 57 | /* |
| 58 | * FIXME: fbdev presumes that all callbacks also work from |
| 59 | * atomic contexts and relies on that for emergency oops |
| 60 | * printing. KMS totally doesn't do that and the locking here is |
| 61 | * by far not the only place this goes wrong. Ignore this for |
| 62 | * now until we solve this for real. |
| 63 | */ |
| 64 | mutex_lock(&fb_helper->dev->struct_mutex); |
| 65 | ret = i915_gem_object_set_to_gtt_domain(ifbdev->fb->obj, |
| 66 | true); |
| 67 | mutex_unlock(&fb_helper->dev->struct_mutex); |
| 68 | } |
| 69 | |
| 70 | return ret; |
| 71 | } |
| 72 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 73 | static struct fb_ops intelfb_ops = { |
| 74 | .owner = THIS_MODULE, |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 75 | .fb_check_var = drm_fb_helper_check_var, |
Daniel Vetter | e991077 | 2014-06-18 15:05:19 +0200 | [diff] [blame] | 76 | .fb_set_par = intel_fbdev_set_par, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 77 | .fb_fillrect = cfb_fillrect, |
| 78 | .fb_copyarea = cfb_copyarea, |
| 79 | .fb_imageblit = cfb_imageblit, |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 80 | .fb_pan_display = drm_fb_helper_pan_display, |
| 81 | .fb_blank = drm_fb_helper_blank, |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 82 | .fb_setcmap = drm_fb_helper_setcmap, |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 83 | .fb_debug_enter = drm_fb_helper_debug_enter, |
| 84 | .fb_debug_leave = drm_fb_helper_debug_leave, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 87 | static int intelfb_alloc(struct drm_fb_helper *helper, |
| 88 | struct drm_fb_helper_surface_size *sizes) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 89 | { |
Ville Syrjälä | 3430824 | 2013-05-31 20:07:05 +0300 | [diff] [blame] | 90 | struct intel_fbdev *ifbdev = |
| 91 | container_of(helper, struct intel_fbdev, helper); |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 92 | struct drm_framebuffer *fb; |
Ville Syrjälä | 3430824 | 2013-05-31 20:07:05 +0300 | [diff] [blame] | 93 | struct drm_device *dev = helper->dev; |
Ville Syrjälä | 3a7f2f6 | 2012-05-24 21:08:56 +0300 | [diff] [blame] | 94 | struct drm_mode_fb_cmd2 mode_cmd = {}; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 95 | struct drm_i915_gem_object *obj; |
James Simmons | 57084d0 | 2010-12-20 19:10:39 +0000 | [diff] [blame] | 96 | int size, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 97 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 98 | /* we don't do packed 24bpp */ |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 99 | if (sizes->surface_bpp == 24) |
| 100 | sizes->surface_bpp = 32; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 101 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 102 | mode_cmd.width = sizes->surface_width; |
| 103 | mode_cmd.height = sizes->surface_height; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 104 | |
Paulo Zanoni | de45eaf | 2013-10-18 18:48:24 -0300 | [diff] [blame] | 105 | mode_cmd.pitches[0] = ALIGN(mode_cmd.width * |
| 106 | DIV_ROUND_UP(sizes->surface_bpp, 8), 64); |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 107 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, |
| 108 | sizes->surface_depth); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 109 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 110 | size = mode_cmd.pitches[0] * mode_cmd.height; |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 111 | size = PAGE_ALIGN(size); |
Chris Wilson | 0ffb0ff | 2012-11-15 11:32:27 +0000 | [diff] [blame] | 112 | obj = i915_gem_object_create_stolen(dev, size); |
| 113 | if (obj == NULL) |
| 114 | obj = i915_gem_alloc_object(dev, size); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 115 | if (!obj) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 116 | DRM_ERROR("failed to allocate framebuffer\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 117 | ret = -ENOMEM; |
| 118 | goto out; |
| 119 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 120 | |
Chris Wilson | 7213342 | 2010-09-13 23:56:38 +0100 | [diff] [blame] | 121 | /* Flush everything out, we'll be doing GTT only from now on */ |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 122 | ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 123 | if (ret) { |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 124 | DRM_ERROR("failed to pin obj: %d\n", ret); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 125 | goto out_unref; |
| 126 | } |
| 127 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 128 | fb = __intel_framebuffer_create(dev, &mode_cmd, obj); |
| 129 | if (IS_ERR(fb)) { |
| 130 | ret = PTR_ERR(fb); |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 131 | goto out_unpin; |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | ifbdev->fb = to_intel_framebuffer(fb); |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 135 | |
| 136 | return 0; |
| 137 | |
| 138 | out_unpin: |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 139 | i915_gem_object_ggtt_unpin(obj); |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 140 | out_unref: |
| 141 | drm_gem_object_unreference(&obj->base); |
| 142 | out: |
| 143 | return ret; |
| 144 | } |
| 145 | |
| 146 | static int intelfb_create(struct drm_fb_helper *helper, |
| 147 | struct drm_fb_helper_surface_size *sizes) |
| 148 | { |
| 149 | struct intel_fbdev *ifbdev = |
| 150 | container_of(helper, struct intel_fbdev, helper); |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 151 | struct intel_framebuffer *intel_fb = ifbdev->fb; |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 152 | struct drm_device *dev = helper->dev; |
| 153 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 154 | struct fb_info *info; |
| 155 | struct drm_framebuffer *fb; |
| 156 | struct drm_i915_gem_object *obj; |
| 157 | int size, ret; |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 158 | bool prealloc = false; |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 159 | |
| 160 | mutex_lock(&dev->struct_mutex); |
| 161 | |
Chris Wilson | edd586f | 2014-04-23 08:54:31 +0100 | [diff] [blame] | 162 | if (intel_fb && |
| 163 | (sizes->fb_width > intel_fb->base.width || |
| 164 | sizes->fb_height > intel_fb->base.height)) { |
| 165 | DRM_DEBUG_KMS("BIOS fb too small (%dx%d), we require (%dx%d)," |
| 166 | " releasing it\n", |
| 167 | intel_fb->base.width, intel_fb->base.height, |
| 168 | sizes->fb_width, sizes->fb_height); |
| 169 | drm_framebuffer_unreference(&intel_fb->base); |
| 170 | intel_fb = ifbdev->fb = NULL; |
| 171 | } |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 172 | if (!intel_fb || WARN_ON(!intel_fb->obj)) { |
Jesse Barnes | 48e9212 | 2013-11-26 11:25:54 -0800 | [diff] [blame] | 173 | DRM_DEBUG_KMS("no BIOS fb, allocating a new one\n"); |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 174 | ret = intelfb_alloc(helper, sizes); |
| 175 | if (ret) |
| 176 | goto out_unlock; |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 177 | intel_fb = ifbdev->fb; |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 178 | } else { |
Jesse Barnes | 48e9212 | 2013-11-26 11:25:54 -0800 | [diff] [blame] | 179 | DRM_DEBUG_KMS("re-using BIOS fb\n"); |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 180 | prealloc = true; |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 181 | sizes->fb_width = intel_fb->base.width; |
| 182 | sizes->fb_height = intel_fb->base.height; |
| 183 | } |
| 184 | |
| 185 | obj = intel_fb->obj; |
| 186 | size = obj->base.size; |
| 187 | |
| 188 | info = framebuffer_alloc(0, &dev->pdev->dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 189 | if (!info) { |
| 190 | ret = -ENOMEM; |
Chris Wilson | b4476f5 | 2009-02-11 14:26:36 +0000 | [diff] [blame] | 191 | goto out_unpin; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Ville Syrjälä | 3430824 | 2013-05-31 20:07:05 +0300 | [diff] [blame] | 194 | info->par = helper; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 195 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 196 | fb = &ifbdev->fb->base; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 197 | |
| 198 | ifbdev->helper.fb = fb; |
| 199 | ifbdev->helper.fbdev = info; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 200 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 201 | strcpy(info->fix.id, "inteldrmfb"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 202 | |
Jesse Barnes | 8fd4bd2 | 2010-06-23 12:56:12 -0700 | [diff] [blame] | 203 | info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 204 | info->fbops = &intelfb_ops; |
| 205 | |
Chris Wilson | 35c3047 | 2010-12-22 14:07:12 +0000 | [diff] [blame] | 206 | ret = fb_alloc_cmap(&info->cmap, 256, 0); |
| 207 | if (ret) { |
| 208 | ret = -ENOMEM; |
| 209 | goto out_unpin; |
| 210 | } |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 211 | /* setup aperture base/size for vesafb takeover */ |
Marcin Slusarz | 1471ca9 | 2010-05-16 17:27:03 +0200 | [diff] [blame] | 212 | info->apertures = alloc_apertures(1); |
| 213 | if (!info->apertures) { |
| 214 | ret = -ENOMEM; |
| 215 | goto out_unpin; |
| 216 | } |
| 217 | info->apertures->ranges[0].base = dev->mode_config.fb_base; |
Ben Widawsky | 93d1879 | 2013-01-17 12:45:17 -0800 | [diff] [blame] | 218 | info->apertures->ranges[0].size = dev_priv->gtt.mappable_end; |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 219 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 220 | info->fix.smem_start = dev->mode_config.fb_base + i915_gem_obj_ggtt_offset(obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 221 | info->fix.smem_len = size; |
| 222 | |
Daniel Vetter | dd2757f | 2012-06-07 15:55:57 +0200 | [diff] [blame] | 223 | info->screen_base = |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 224 | ioremap_wc(dev_priv->gtt.mappable_base + i915_gem_obj_ggtt_offset(obj), |
Daniel Vetter | dd2757f | 2012-06-07 15:55:57 +0200 | [diff] [blame] | 225 | size); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 226 | if (!info->screen_base) { |
| 227 | ret = -ENOSPC; |
Chris Wilson | b4476f5 | 2009-02-11 14:26:36 +0000 | [diff] [blame] | 228 | goto out_unpin; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 229 | } |
| 230 | info->screen_size = size; |
| 231 | |
Jesse Barnes | 24576d2 | 2013-03-26 09:25:45 -0700 | [diff] [blame] | 232 | /* This driver doesn't need a VT switch to restore the mode on resume */ |
| 233 | info->skip_vt_switch = true; |
| 234 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 235 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 236 | 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] | 237 | |
Chris Wilson | 88afe71 | 2012-12-16 12:15:41 +0000 | [diff] [blame] | 238 | /* If the object is shmemfs backed, it will have given us zeroed pages. |
| 239 | * If the object is stolen however, it will be full of whatever |
| 240 | * garbage was left in there. |
| 241 | */ |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 242 | if (ifbdev->fb->obj->stolen && !prealloc) |
Chris Wilson | 88afe71 | 2012-12-16 12:15:41 +0000 | [diff] [blame] | 243 | memset_io(info->screen_base, 0, info->screen_size); |
| 244 | |
Sascha Hauer | fb2a99e | 2012-02-06 10:58:19 +0100 | [diff] [blame] | 245 | /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */ |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 246 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 247 | DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08lx, bo %p\n", |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 248 | fb->width, fb->height, |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 249 | i915_gem_obj_ggtt_offset(obj), obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 250 | |
| 251 | mutex_unlock(&dev->struct_mutex); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 252 | vga_switcheroo_client_fb_set(dev->pdev, info); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 253 | return 0; |
| 254 | |
Chris Wilson | b4476f5 | 2009-02-11 14:26:36 +0000 | [diff] [blame] | 255 | out_unpin: |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 256 | i915_gem_object_ggtt_unpin(obj); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 257 | drm_gem_object_unreference(&obj->base); |
Jesse Barnes | 8b4f49e | 2013-11-25 15:51:16 -0800 | [diff] [blame] | 258 | out_unlock: |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 259 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 260 | return ret; |
| 261 | } |
| 262 | |
Paulo Zanoni | 6743768 | 2013-09-24 13:52:56 -0300 | [diff] [blame] | 263 | /** Sets the color ramps on behalf of RandR */ |
| 264 | static void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
| 265 | u16 blue, int regno) |
| 266 | { |
| 267 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 268 | |
| 269 | intel_crtc->lut_r[regno] = red >> 8; |
| 270 | intel_crtc->lut_g[regno] = green >> 8; |
| 271 | intel_crtc->lut_b[regno] = blue >> 8; |
| 272 | } |
| 273 | |
| 274 | static void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, |
| 275 | u16 *blue, int regno) |
| 276 | { |
| 277 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 278 | |
| 279 | *red = intel_crtc->lut_r[regno] << 8; |
| 280 | *green = intel_crtc->lut_g[regno] << 8; |
| 281 | *blue = intel_crtc->lut_b[regno] << 8; |
| 282 | } |
| 283 | |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 284 | static struct drm_fb_helper_crtc * |
| 285 | intel_fb_helper_crtc(struct drm_fb_helper *fb_helper, struct drm_crtc *crtc) |
| 286 | { |
| 287 | int i; |
| 288 | |
| 289 | for (i = 0; i < fb_helper->crtc_count; i++) |
| 290 | if (fb_helper->crtc_info[i].mode_set.crtc == crtc) |
| 291 | return &fb_helper->crtc_info[i]; |
| 292 | |
| 293 | return NULL; |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | * Try to read the BIOS display configuration and use it for the initial |
| 298 | * fb configuration. |
| 299 | * |
| 300 | * The BIOS or boot loader will generally create an initial display |
| 301 | * configuration for us that includes some set of active pipes and displays. |
| 302 | * This routine tries to figure out which pipes and connectors are active |
| 303 | * and stuffs them into the crtcs and modes array given to us by the |
| 304 | * drm_fb_helper code. |
| 305 | * |
| 306 | * The overall sequence is: |
| 307 | * intel_fbdev_init - from driver load |
| 308 | * intel_fbdev_init_bios - initialize the intel_fbdev using BIOS data |
| 309 | * drm_fb_helper_init - build fb helper structs |
| 310 | * drm_fb_helper_single_add_all_connectors - more fb helper structs |
| 311 | * intel_fbdev_initial_config - apply the config |
| 312 | * drm_fb_helper_initial_config - call ->probe then register_framebuffer() |
| 313 | * drm_setup_crtcs - build crtc config for fbdev |
| 314 | * intel_fb_initial_config - find active connectors etc |
| 315 | * drm_fb_helper_single_fb_probe - set up fbdev |
| 316 | * intelfb_create - re-use or alloc fb, build out fbdev structs |
| 317 | * |
| 318 | * Note that we don't make special consideration whether we could actually |
| 319 | * switch to the selected modes without a full modeset. E.g. when the display |
| 320 | * is in VGA mode we need to recalculate watermarks and set a new high-res |
| 321 | * framebuffer anyway. |
| 322 | */ |
| 323 | static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper, |
| 324 | struct drm_fb_helper_crtc **crtcs, |
| 325 | struct drm_display_mode **modes, |
| 326 | bool *enabled, int width, int height) |
| 327 | { |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 328 | struct drm_device *dev = fb_helper->dev; |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 329 | int i, j; |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 330 | bool *save_enabled; |
Daniel Vetter | 7c2bb53 | 2014-03-04 21:08:41 +0100 | [diff] [blame] | 331 | bool fallback = true; |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 332 | int num_connectors_enabled = 0; |
| 333 | int num_connectors_detected = 0; |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 334 | |
Jesse Barnes | ef34ab8 | 2014-02-20 12:28:07 -0800 | [diff] [blame] | 335 | /* |
| 336 | * If the user specified any force options, just bail here |
| 337 | * and use that config. |
| 338 | */ |
| 339 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 340 | struct drm_fb_helper_connector *fb_conn; |
| 341 | struct drm_connector *connector; |
| 342 | |
| 343 | fb_conn = fb_helper->connector_info[i]; |
| 344 | connector = fb_conn->connector; |
| 345 | |
| 346 | if (!enabled[i]) |
| 347 | continue; |
| 348 | |
| 349 | if (connector->force != DRM_FORCE_UNSPECIFIED) |
| 350 | return false; |
| 351 | } |
| 352 | |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 353 | save_enabled = kcalloc(dev->mode_config.num_connector, sizeof(bool), |
| 354 | GFP_KERNEL); |
| 355 | if (!save_enabled) |
| 356 | return false; |
| 357 | |
| 358 | memcpy(save_enabled, enabled, dev->mode_config.num_connector); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 359 | |
| 360 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 361 | struct drm_fb_helper_connector *fb_conn; |
| 362 | struct drm_connector *connector; |
| 363 | struct drm_encoder *encoder; |
| 364 | struct drm_fb_helper_crtc *new_crtc; |
| 365 | |
| 366 | fb_conn = fb_helper->connector_info[i]; |
| 367 | connector = fb_conn->connector; |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 368 | |
| 369 | if (connector->status == connector_status_connected) |
| 370 | num_connectors_detected++; |
| 371 | |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 372 | if (!enabled[i]) { |
Chris Wilson | c0c9762 | 2014-05-13 13:45:09 +0100 | [diff] [blame] | 373 | DRM_DEBUG_KMS("connector %s not enabled, skipping\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 374 | connector->name); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 375 | continue; |
| 376 | } |
| 377 | |
| 378 | encoder = connector->encoder; |
| 379 | if (!encoder || WARN_ON(!encoder->crtc)) { |
Chris Wilson | c0c9762 | 2014-05-13 13:45:09 +0100 | [diff] [blame] | 380 | DRM_DEBUG_KMS("connector %s has no encoder or crtc, skipping\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 381 | connector->name); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 382 | enabled[i] = false; |
| 383 | continue; |
| 384 | } |
| 385 | |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 386 | num_connectors_enabled++; |
| 387 | |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 388 | new_crtc = intel_fb_helper_crtc(fb_helper, encoder->crtc); |
| 389 | |
| 390 | /* |
| 391 | * Make sure we're not trying to drive multiple connectors |
| 392 | * with a single CRTC, since our cloning support may not |
| 393 | * match the BIOS. |
| 394 | */ |
| 395 | for (j = 0; j < fb_helper->connector_count; j++) { |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 396 | if (crtcs[j] == new_crtc) { |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 397 | DRM_DEBUG_KMS("fallback: cloned configuration\n"); |
Daniel Vetter | 7c2bb53 | 2014-03-04 21:08:41 +0100 | [diff] [blame] | 398 | fallback = true; |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 399 | goto out; |
| 400 | } |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 401 | } |
| 402 | |
Chris Wilson | c0c9762 | 2014-05-13 13:45:09 +0100 | [diff] [blame] | 403 | DRM_DEBUG_KMS("looking for cmdline mode on connector %s\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 404 | connector->name); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 405 | |
| 406 | /* go for command line mode first */ |
| 407 | modes[i] = drm_pick_cmdline_mode(fb_conn, width, height); |
| 408 | |
| 409 | /* try for preferred next */ |
| 410 | if (!modes[i]) { |
Chris Wilson | c0c9762 | 2014-05-13 13:45:09 +0100 | [diff] [blame] | 411 | DRM_DEBUG_KMS("looking for preferred mode on connector %s\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 412 | connector->name); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 413 | modes[i] = drm_has_preferred_mode(fb_conn, width, |
| 414 | height); |
| 415 | } |
| 416 | |
Chris Wilson | afba0b5 | 2014-05-13 16:07:37 +0100 | [diff] [blame] | 417 | /* No preferred mode marked by the EDID? Are there any modes? */ |
| 418 | if (!modes[i] && !list_empty(&connector->modes)) { |
| 419 | DRM_DEBUG_KMS("using first mode listed on connector %s\n", |
Dave Airlie | 8d4ad9d | 2014-06-05 20:28:59 +1000 | [diff] [blame] | 420 | connector->name); |
Chris Wilson | afba0b5 | 2014-05-13 16:07:37 +0100 | [diff] [blame] | 421 | modes[i] = list_first_entry(&connector->modes, |
| 422 | struct drm_display_mode, |
| 423 | head); |
| 424 | } |
| 425 | |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 426 | /* last resort: use current mode */ |
| 427 | if (!modes[i]) { |
| 428 | /* |
| 429 | * IMPORTANT: We want to use the adjusted mode (i.e. |
| 430 | * after the panel fitter upscaling) as the initial |
| 431 | * config, not the input mode, which is what crtc->mode |
| 432 | * usually contains. But since our current fastboot |
| 433 | * code puts a mode derived from the post-pfit timings |
| 434 | * into crtc->mode this works out correctly. We don't |
| 435 | * use hwmode anywhere right now, so use it for this |
| 436 | * since the fb helper layer wants a pointer to |
| 437 | * something we own. |
| 438 | */ |
Chris Wilson | c0c9762 | 2014-05-13 13:45:09 +0100 | [diff] [blame] | 439 | DRM_DEBUG_KMS("looking for current mode on connector %s\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 440 | connector->name); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 441 | intel_mode_from_pipe_config(&encoder->crtc->hwmode, |
| 442 | &to_intel_crtc(encoder->crtc)->config); |
| 443 | modes[i] = &encoder->crtc->hwmode; |
| 444 | } |
| 445 | crtcs[i] = new_crtc; |
| 446 | |
Damien Lespiau | fdaf66d | 2014-06-06 18:22:06 +0100 | [diff] [blame] | 447 | DRM_DEBUG_KMS("connector %s on pipe %c [CRTC:%d]: %dx%d%s\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 448 | connector->name, |
Chris Wilson | c0c9762 | 2014-05-13 13:45:09 +0100 | [diff] [blame] | 449 | pipe_name(to_intel_crtc(encoder->crtc)->pipe), |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 450 | encoder->crtc->base.id, |
Chris Wilson | c0c9762 | 2014-05-13 13:45:09 +0100 | [diff] [blame] | 451 | modes[i]->hdisplay, modes[i]->vdisplay, |
| 452 | modes[i]->flags & DRM_MODE_FLAG_INTERLACE ? "i" :""); |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 453 | |
Daniel Vetter | 7c2bb53 | 2014-03-04 21:08:41 +0100 | [diff] [blame] | 454 | fallback = false; |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 455 | } |
| 456 | |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 457 | /* |
| 458 | * If the BIOS didn't enable everything it could, fall back to have the |
| 459 | * same user experiencing of lighting up as much as possible like the |
| 460 | * fbdev helper library. |
| 461 | */ |
| 462 | if (num_connectors_enabled != num_connectors_detected && |
| 463 | num_connectors_enabled < INTEL_INFO(dev)->num_pipes) { |
| 464 | DRM_DEBUG_KMS("fallback: Not all outputs enabled\n"); |
| 465 | DRM_DEBUG_KMS("Enabled: %i, detected: %i\n", num_connectors_enabled, |
| 466 | num_connectors_detected); |
| 467 | fallback = true; |
| 468 | } |
| 469 | |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 470 | out: |
Daniel Vetter | 7c2bb53 | 2014-03-04 21:08:41 +0100 | [diff] [blame] | 471 | if (fallback) { |
Daniel Vetter | 7e696e4 | 2014-03-04 21:08:42 +0100 | [diff] [blame] | 472 | DRM_DEBUG_KMS("Not using firmware configuration\n"); |
Jesse Barnes | 02f5eeb | 2014-02-12 15:03:40 -0800 | [diff] [blame] | 473 | memcpy(enabled, save_enabled, dev->mode_config.num_connector); |
| 474 | kfree(save_enabled); |
| 475 | return false; |
| 476 | } |
| 477 | |
| 478 | kfree(save_enabled); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 479 | return true; |
| 480 | } |
| 481 | |
Thierry Reding | 3a49387 | 2014-06-27 17:19:23 +0200 | [diff] [blame] | 482 | static const struct drm_fb_helper_funcs intel_fb_helper_funcs = { |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 483 | .initial_config = intel_fb_initial_config, |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 484 | .gamma_set = intel_crtc_fb_gamma_set, |
| 485 | .gamma_get = intel_crtc_fb_gamma_get, |
Daniel Vetter | cd5428a | 2013-01-21 23:42:49 +0100 | [diff] [blame] | 486 | .fb_probe = intelfb_create, |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 487 | }; |
| 488 | |
Chris Wilson | 7b4f399 | 2010-10-04 15:33:04 +0100 | [diff] [blame] | 489 | static void intel_fbdev_destroy(struct drm_device *dev, |
| 490 | struct intel_fbdev *ifbdev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 491 | { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 492 | if (ifbdev->helper.fbdev) { |
Chris Wilson | ddfe156 | 2013-08-06 17:43:07 +0100 | [diff] [blame] | 493 | struct fb_info *info = ifbdev->helper.fbdev; |
| 494 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 495 | unregister_framebuffer(info); |
| 496 | iounmap(info->screen_base); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 497 | if (info->cmap.len) |
| 498 | fb_dealloc_cmap(&info->cmap); |
Chris Wilson | ddfe156 | 2013-08-06 17:43:07 +0100 | [diff] [blame] | 499 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 500 | framebuffer_release(info); |
| 501 | } |
| 502 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 503 | drm_fb_helper_fini(&ifbdev->helper); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 504 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 505 | drm_framebuffer_unregister_private(&ifbdev->fb->base); |
Imre Deak | 9d66125 | 2014-02-12 00:01:10 +0200 | [diff] [blame] | 506 | drm_framebuffer_remove(&ifbdev->fb->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 507 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 508 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 509 | /* |
| 510 | * Build an intel_fbdev struct using a BIOS allocated framebuffer, if possible. |
| 511 | * The core display code will have read out the current plane configuration, |
| 512 | * so we use that to figure out if there's an object for us to use as the |
| 513 | * fb, and if so, we re-use it for the fbdev configuration. |
| 514 | * |
| 515 | * Note we only support a single fb shared across pipes for boot (mostly for |
| 516 | * fbcon), so we just find the biggest and use that. |
| 517 | */ |
| 518 | static bool intel_fbdev_init_bios(struct drm_device *dev, |
| 519 | struct intel_fbdev *ifbdev) |
| 520 | { |
| 521 | struct intel_framebuffer *fb = NULL; |
| 522 | struct drm_crtc *crtc; |
| 523 | struct intel_crtc *intel_crtc; |
| 524 | struct intel_plane_config *plane_config = NULL; |
| 525 | unsigned int max_size = 0; |
| 526 | |
| 527 | if (!i915.fastboot) |
| 528 | return false; |
| 529 | |
| 530 | /* Find the largest fb */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 531 | for_each_crtc(dev, crtc) { |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 532 | intel_crtc = to_intel_crtc(crtc); |
| 533 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 534 | if (!intel_crtc->active || !crtc->primary->fb) { |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 535 | DRM_DEBUG_KMS("pipe %c not active or no fb, skipping\n", |
| 536 | pipe_name(intel_crtc->pipe)); |
| 537 | continue; |
| 538 | } |
| 539 | |
| 540 | if (intel_crtc->plane_config.size > max_size) { |
| 541 | DRM_DEBUG_KMS("found possible fb from plane %c\n", |
| 542 | pipe_name(intel_crtc->pipe)); |
| 543 | plane_config = &intel_crtc->plane_config; |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 544 | fb = to_intel_framebuffer(crtc->primary->fb); |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 545 | max_size = plane_config->size; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | if (!fb) { |
| 550 | DRM_DEBUG_KMS("no active fbs found, not using BIOS config\n"); |
| 551 | goto out; |
| 552 | } |
| 553 | |
| 554 | /* Now make sure all the pipes will fit into it */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 555 | for_each_crtc(dev, crtc) { |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 556 | unsigned int cur_size; |
| 557 | |
| 558 | intel_crtc = to_intel_crtc(crtc); |
| 559 | |
| 560 | if (!intel_crtc->active) { |
| 561 | DRM_DEBUG_KMS("pipe %c not active, skipping\n", |
| 562 | pipe_name(intel_crtc->pipe)); |
| 563 | continue; |
| 564 | } |
| 565 | |
| 566 | DRM_DEBUG_KMS("checking plane %c for BIOS fb\n", |
| 567 | pipe_name(intel_crtc->pipe)); |
| 568 | |
| 569 | /* |
| 570 | * See if the plane fb we found above will fit on this |
Chris Wilson | bc104d1 | 2014-03-20 15:11:21 +0000 | [diff] [blame] | 571 | * pipe. Note we need to use the selected fb's pitch and bpp |
| 572 | * rather than the current pipe's, since they differ. |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 573 | */ |
Chris Wilson | bc104d1 | 2014-03-20 15:11:21 +0000 | [diff] [blame] | 574 | cur_size = intel_crtc->config.adjusted_mode.crtc_hdisplay; |
| 575 | cur_size = cur_size * fb->base.bits_per_pixel / 8; |
| 576 | if (fb->base.pitches[0] < cur_size) { |
| 577 | DRM_DEBUG_KMS("fb not wide enough for plane %c (%d vs %d)\n", |
| 578 | pipe_name(intel_crtc->pipe), |
| 579 | cur_size, fb->base.pitches[0]); |
| 580 | plane_config = NULL; |
| 581 | fb = NULL; |
| 582 | break; |
| 583 | } |
| 584 | |
| 585 | cur_size = intel_crtc->config.adjusted_mode.crtc_vdisplay; |
| 586 | cur_size = ALIGN(cur_size, plane_config->tiled ? (IS_GEN2(dev) ? 16 : 8) : 1); |
| 587 | cur_size *= fb->base.pitches[0]; |
| 588 | DRM_DEBUG_KMS("pipe %c area: %dx%d, bpp: %d, size: %d\n", |
| 589 | pipe_name(intel_crtc->pipe), |
| 590 | intel_crtc->config.adjusted_mode.crtc_hdisplay, |
| 591 | intel_crtc->config.adjusted_mode.crtc_vdisplay, |
| 592 | fb->base.bits_per_pixel, |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 593 | cur_size); |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 594 | |
| 595 | if (cur_size > max_size) { |
| 596 | DRM_DEBUG_KMS("fb not big enough for plane %c (%d vs %d)\n", |
| 597 | pipe_name(intel_crtc->pipe), |
| 598 | cur_size, max_size); |
| 599 | plane_config = NULL; |
| 600 | fb = NULL; |
| 601 | break; |
| 602 | } |
| 603 | |
| 604 | DRM_DEBUG_KMS("fb big enough for plane %c (%d >= %d)\n", |
| 605 | pipe_name(intel_crtc->pipe), |
| 606 | max_size, cur_size); |
| 607 | } |
| 608 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 609 | if (!fb) { |
| 610 | DRM_DEBUG_KMS("BIOS fb not suitable for all pipes, not using\n"); |
| 611 | goto out; |
| 612 | } |
| 613 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 614 | ifbdev->preferred_bpp = fb->base.bits_per_pixel; |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 615 | ifbdev->fb = fb; |
| 616 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 617 | drm_framebuffer_reference(&ifbdev->fb->base); |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 618 | |
| 619 | /* Final pass to check if any active pipes don't have fbs */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 620 | for_each_crtc(dev, crtc) { |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 621 | intel_crtc = to_intel_crtc(crtc); |
| 622 | |
| 623 | if (!intel_crtc->active) |
| 624 | continue; |
| 625 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 626 | WARN(!crtc->primary->fb, |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 627 | "re-used BIOS config but lost an fb on crtc %d\n", |
| 628 | crtc->base.id); |
| 629 | } |
| 630 | |
| 631 | |
| 632 | DRM_DEBUG_KMS("using BIOS fb for initial console\n"); |
| 633 | return true; |
| 634 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 635 | out: |
| 636 | |
| 637 | return false; |
| 638 | } |
| 639 | |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 640 | static void intel_fbdev_suspend_worker(struct work_struct *work) |
| 641 | { |
| 642 | intel_fbdev_set_suspend(container_of(work, |
| 643 | struct drm_i915_private, |
| 644 | fbdev_suspend_work)->dev, |
| 645 | FBINFO_STATE_RUNNING, |
| 646 | true); |
| 647 | } |
| 648 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 649 | int intel_fbdev_init(struct drm_device *dev) |
| 650 | { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 651 | struct intel_fbdev *ifbdev; |
Ville Syrjälä | b51b32c | 2013-05-31 20:07:06 +0300 | [diff] [blame] | 652 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 653 | int ret; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 654 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 655 | if (WARN_ON(INTEL_INFO(dev)->num_pipes == 0)) |
| 656 | return -ENODEV; |
| 657 | |
| 658 | ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL); |
| 659 | if (ifbdev == NULL) |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 660 | return -ENOMEM; |
| 661 | |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 662 | drm_fb_helper_prepare(dev, &ifbdev->helper, &intel_fb_helper_funcs); |
| 663 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 664 | if (!intel_fbdev_init_bios(dev, ifbdev)) |
| 665 | ifbdev->preferred_bpp = 32; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 666 | |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 667 | ret = drm_fb_helper_init(dev, &ifbdev->helper, |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 668 | INTEL_INFO(dev)->num_pipes, 4); |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 669 | if (ret) { |
| 670 | kfree(ifbdev); |
| 671 | return ret; |
| 672 | } |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 673 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 674 | dev_priv->fbdev = ifbdev; |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 675 | INIT_WORK(&dev_priv->fbdev_suspend_work, intel_fbdev_suspend_worker); |
| 676 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 677 | drm_fb_helper_single_add_all_connectors(&ifbdev->helper); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 678 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 679 | return 0; |
| 680 | } |
| 681 | |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 682 | void intel_fbdev_initial_config(struct drm_device *dev) |
| 683 | { |
Ville Syrjälä | b51b32c | 2013-05-31 20:07:06 +0300 | [diff] [blame] | 684 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 685 | struct intel_fbdev *ifbdev = dev_priv->fbdev; |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 686 | |
| 687 | /* Due to peculiar init order wrt to hpd handling this is separate. */ |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 688 | drm_fb_helper_initial_config(&ifbdev->helper, ifbdev->preferred_bpp); |
Daniel Vetter | 20afbda | 2012-12-11 14:05:07 +0100 | [diff] [blame] | 689 | } |
| 690 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 691 | void intel_fbdev_fini(struct drm_device *dev) |
| 692 | { |
Ville Syrjälä | b51b32c | 2013-05-31 20:07:06 +0300 | [diff] [blame] | 693 | struct drm_i915_private *dev_priv = dev->dev_private; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 694 | if (!dev_priv->fbdev) |
| 695 | return; |
| 696 | |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 697 | flush_work(&dev_priv->fbdev_suspend_work); |
| 698 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 699 | intel_fbdev_destroy(dev, dev_priv->fbdev); |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 700 | kfree(dev_priv->fbdev); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 701 | dev_priv->fbdev = NULL; |
| 702 | } |
Dave Airlie | 3fa016a | 2012-03-28 10:48:49 +0100 | [diff] [blame] | 703 | |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 704 | 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] | 705 | { |
Ville Syrjälä | b51b32c | 2013-05-31 20:07:06 +0300 | [diff] [blame] | 706 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 1ffc528 | 2013-05-07 18:54:05 +0300 | [diff] [blame] | 707 | struct intel_fbdev *ifbdev = dev_priv->fbdev; |
| 708 | struct fb_info *info; |
| 709 | |
| 710 | if (!ifbdev) |
Dave Airlie | 3fa016a | 2012-03-28 10:48:49 +0100 | [diff] [blame] | 711 | return; |
| 712 | |
Jani Nikula | 1ffc528 | 2013-05-07 18:54:05 +0300 | [diff] [blame] | 713 | info = ifbdev->helper.fbdev; |
| 714 | |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 715 | if (synchronous) { |
| 716 | /* Flush any pending work to turn the console on, and then |
| 717 | * wait to turn it off. It must be synchronous as we are |
| 718 | * about to suspend or unload the driver. |
| 719 | * |
| 720 | * Note that from within the work-handler, we cannot flush |
| 721 | * ourselves, so only flush outstanding work upon suspend! |
| 722 | */ |
| 723 | if (state != FBINFO_STATE_RUNNING) |
| 724 | flush_work(&dev_priv->fbdev_suspend_work); |
| 725 | console_lock(); |
| 726 | } else { |
| 727 | /* |
| 728 | * The console lock can be pretty contented on resume due |
| 729 | * to all the printk activity. Try to keep it out of the hot |
| 730 | * path of resume if possible. |
| 731 | */ |
| 732 | WARN_ON(state != FBINFO_STATE_RUNNING); |
| 733 | if (!console_trylock()) { |
| 734 | /* Don't block our own workqueue as this can |
| 735 | * be run in parallel with other i915.ko tasks. |
| 736 | */ |
| 737 | schedule_work(&dev_priv->fbdev_suspend_work); |
| 738 | return; |
| 739 | } |
| 740 | } |
| 741 | |
Jani Nikula | 1ffc528 | 2013-05-07 18:54:05 +0300 | [diff] [blame] | 742 | /* On resume from hibernation: If the object is shmemfs backed, it has |
| 743 | * been restored from swap. If the object is stolen however, it will be |
| 744 | * full of whatever garbage was left in there. |
| 745 | */ |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 746 | if (state == FBINFO_STATE_RUNNING && ifbdev->fb->obj->stolen) |
Jani Nikula | 1ffc528 | 2013-05-07 18:54:05 +0300 | [diff] [blame] | 747 | memset_io(info->screen_base, 0, info->screen_size); |
| 748 | |
| 749 | fb_set_suspend(info, state); |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 750 | console_unlock(); |
Dave Airlie | 3fa016a | 2012-03-28 10:48:49 +0100 | [diff] [blame] | 751 | } |
| 752 | |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 753 | void intel_fbdev_output_poll_changed(struct drm_device *dev) |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 754 | { |
Ville Syrjälä | b51b32c | 2013-05-31 20:07:06 +0300 | [diff] [blame] | 755 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 756 | if (dev_priv->fbdev) |
| 757 | drm_fb_helper_hotplug_event(&dev_priv->fbdev->helper); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 758 | } |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 759 | |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 760 | void intel_fbdev_restore_mode(struct drm_device *dev) |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 761 | { |
| 762 | int ret; |
Ville Syrjälä | b51b32c | 2013-05-31 20:07:06 +0300 | [diff] [blame] | 763 | struct drm_i915_private *dev_priv = dev->dev_private; |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 764 | |
Jesse Barnes | d978ef1 | 2014-03-07 08:57:51 -0800 | [diff] [blame] | 765 | if (!dev_priv->fbdev) |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 766 | return; |
| 767 | |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 768 | ret = drm_fb_helper_restore_fbdev_mode_unlocked(&dev_priv->fbdev->helper); |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 769 | if (ret) |
| 770 | DRM_DEBUG("failed to restore crtc mode\n"); |
| 771 | } |