Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * Copyright (c) 2007-2011, Intel Corporation. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | * |
| 18 | **************************************************************************/ |
| 19 | |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/string.h> |
Dan Williams | 01c8f1c | 2016-01-15 16:56:40 -0800 | [diff] [blame] | 24 | #include <linux/pfn_t.h> |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 25 | #include <linux/mm.h> |
| 26 | #include <linux/tty.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/delay.h> |
| 29 | #include <linux/fb.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/console.h> |
| 32 | |
| 33 | #include <drm/drmP.h> |
| 34 | #include <drm/drm.h> |
| 35 | #include <drm/drm_crtc.h> |
Dave Airlie | a9a644a | 2011-11-28 14:08:46 +0000 | [diff] [blame] | 36 | #include <drm/drm_fb_helper.h> |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 37 | |
| 38 | #include "psb_drv.h" |
| 39 | #include "psb_intel_reg.h" |
| 40 | #include "psb_intel_drv.h" |
| 41 | #include "framebuffer.h" |
Alan Cox | a6ba582 | 2011-11-29 22:27:22 +0000 | [diff] [blame] | 42 | #include "gtt.h" |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 43 | |
| 44 | static void psb_user_framebuffer_destroy(struct drm_framebuffer *fb); |
| 45 | static int psb_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
| 46 | struct drm_file *file_priv, |
| 47 | unsigned int *handle); |
| 48 | |
| 49 | static const struct drm_framebuffer_funcs psb_fb_funcs = { |
| 50 | .destroy = psb_user_framebuffer_destroy, |
| 51 | .create_handle = psb_user_framebuffer_create_handle, |
| 52 | }; |
| 53 | |
| 54 | #define CMAP_TOHW(_val, _width) ((((_val) << (_width)) + 0x7FFF - (_val)) >> 16) |
| 55 | |
| 56 | static int psbfb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 57 | unsigned blue, unsigned transp, |
| 58 | struct fb_info *info) |
| 59 | { |
| 60 | struct psb_fbdev *fbdev = info->par; |
| 61 | struct drm_framebuffer *fb = fbdev->psb_fb_helper.fb; |
| 62 | uint32_t v; |
| 63 | |
| 64 | if (!fb) |
| 65 | return -ENOMEM; |
| 66 | |
| 67 | if (regno > 255) |
| 68 | return 1; |
| 69 | |
| 70 | red = CMAP_TOHW(red, info->var.red.length); |
| 71 | blue = CMAP_TOHW(blue, info->var.blue.length); |
| 72 | green = CMAP_TOHW(green, info->var.green.length); |
| 73 | transp = CMAP_TOHW(transp, info->var.transp.length); |
| 74 | |
| 75 | v = (red << info->var.red.offset) | |
| 76 | (green << info->var.green.offset) | |
| 77 | (blue << info->var.blue.offset) | |
| 78 | (transp << info->var.transp.offset); |
| 79 | |
| 80 | if (regno < 16) { |
| 81 | switch (fb->bits_per_pixel) { |
| 82 | case 16: |
| 83 | ((uint32_t *) info->pseudo_palette)[regno] = v; |
| 84 | break; |
| 85 | case 24: |
| 86 | case 32: |
| 87 | ((uint32_t *) info->pseudo_palette)[regno] = v; |
| 88 | break; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
Alan Cox | a6ba582 | 2011-11-29 22:27:22 +0000 | [diff] [blame] | 95 | static int psbfb_pan(struct fb_var_screeninfo *var, struct fb_info *info) |
| 96 | { |
| 97 | struct psb_fbdev *fbdev = info->par; |
| 98 | struct psb_framebuffer *psbfb = &fbdev->pfb; |
| 99 | struct drm_device *dev = psbfb->base.dev; |
| 100 | |
| 101 | /* |
| 102 | * We have to poke our nose in here. The core fb code assumes |
| 103 | * panning is part of the hardware that can be invoked before |
| 104 | * the actual fb is mapped. In our case that isn't quite true. |
| 105 | */ |
| 106 | if (psbfb->gtt->npage) { |
| 107 | /* GTT roll shifts in 4K pages, we need to shift the right |
| 108 | number of pages */ |
| 109 | int pages = info->fix.line_length >> 12; |
| 110 | psb_gtt_roll(dev, psbfb->gtt, var->yoffset * pages); |
| 111 | } |
| 112 | return 0; |
| 113 | } |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 114 | |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 115 | static int psbfb_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
| 116 | { |
| 117 | struct psb_framebuffer *psbfb = vma->vm_private_data; |
| 118 | struct drm_device *dev = psbfb->base.dev; |
| 119 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 120 | int page_num; |
| 121 | int i; |
| 122 | unsigned long address; |
| 123 | int ret; |
| 124 | unsigned long pfn; |
Patrik Jakobsson | 61bb3fe | 2013-05-14 14:37:10 +0200 | [diff] [blame] | 125 | unsigned long phys_addr = (unsigned long)dev_priv->stolen_base + |
| 126 | psbfb->gtt->offset; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 127 | |
| 128 | page_num = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; |
Yoichi Yuasa | 1278f7d | 2012-03-15 14:50:16 +0000 | [diff] [blame] | 129 | address = (unsigned long)vmf->virtual_address - (vmf->pgoff << PAGE_SHIFT); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 130 | |
| 131 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 132 | |
| 133 | for (i = 0; i < page_num; i++) { |
| 134 | pfn = (phys_addr >> PAGE_SHIFT); |
| 135 | |
Dan Williams | 01c8f1c | 2016-01-15 16:56:40 -0800 | [diff] [blame] | 136 | ret = vm_insert_mixed(vma, address, |
| 137 | __pfn_to_pfn_t(pfn, PFN_DEV)); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 138 | if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0))) |
| 139 | break; |
| 140 | else if (unlikely(ret != 0)) { |
| 141 | ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS; |
| 142 | return ret; |
| 143 | } |
| 144 | address += PAGE_SIZE; |
| 145 | phys_addr += PAGE_SIZE; |
| 146 | } |
| 147 | return VM_FAULT_NOPAGE; |
| 148 | } |
| 149 | |
| 150 | static void psbfb_vm_open(struct vm_area_struct *vma) |
| 151 | { |
| 152 | } |
| 153 | |
| 154 | static void psbfb_vm_close(struct vm_area_struct *vma) |
| 155 | { |
| 156 | } |
| 157 | |
Laurent Pinchart | 78b6855 | 2012-05-17 13:27:22 +0200 | [diff] [blame] | 158 | static const struct vm_operations_struct psbfb_vm_ops = { |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 159 | .fault = psbfb_vm_fault, |
| 160 | .open = psbfb_vm_open, |
| 161 | .close = psbfb_vm_close |
| 162 | }; |
| 163 | |
| 164 | static int psbfb_mmap(struct fb_info *info, struct vm_area_struct *vma) |
| 165 | { |
| 166 | struct psb_fbdev *fbdev = info->par; |
| 167 | struct psb_framebuffer *psbfb = &fbdev->pfb; |
| 168 | |
| 169 | if (vma->vm_pgoff != 0) |
| 170 | return -EINVAL; |
| 171 | if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) |
| 172 | return -EINVAL; |
| 173 | |
| 174 | if (!psbfb->addr_space) |
| 175 | psbfb->addr_space = vma->vm_file->f_mapping; |
| 176 | /* |
| 177 | * If this is a GEM object then info->screen_base is the virtual |
| 178 | * kernel remapping of the object. FIXME: Review if this is |
| 179 | * suitable for our mmap work |
| 180 | */ |
| 181 | vma->vm_ops = &psbfb_vm_ops; |
| 182 | vma->vm_private_data = (void *)psbfb; |
Konstantin Khlebnikov | 314e51b | 2012-10-08 16:29:02 -0700 | [diff] [blame] | 183 | vma->vm_flags |= VM_IO | VM_MIXEDMAP | VM_DONTEXPAND | VM_DONTDUMP; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | static int psbfb_ioctl(struct fb_info *info, unsigned int cmd, |
| 188 | unsigned long arg) |
| 189 | { |
| 190 | return -ENOTTY; |
| 191 | } |
| 192 | |
| 193 | static struct fb_ops psbfb_ops = { |
| 194 | .owner = THIS_MODULE, |
| 195 | .fb_check_var = drm_fb_helper_check_var, |
| 196 | .fb_set_par = drm_fb_helper_set_par, |
| 197 | .fb_blank = drm_fb_helper_blank, |
| 198 | .fb_setcolreg = psbfb_setcolreg, |
Archit Taneja | 546187c | 2015-07-22 14:58:10 +0530 | [diff] [blame] | 199 | .fb_fillrect = drm_fb_helper_cfb_fillrect, |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 200 | .fb_copyarea = psbfb_copyarea, |
Archit Taneja | 546187c | 2015-07-22 14:58:10 +0530 | [diff] [blame] | 201 | .fb_imageblit = drm_fb_helper_cfb_imageblit, |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 202 | .fb_mmap = psbfb_mmap, |
| 203 | .fb_sync = psbfb_sync, |
| 204 | .fb_ioctl = psbfb_ioctl, |
| 205 | }; |
| 206 | |
Alan Cox | a6ba582 | 2011-11-29 22:27:22 +0000 | [diff] [blame] | 207 | static struct fb_ops psbfb_roll_ops = { |
| 208 | .owner = THIS_MODULE, |
| 209 | .fb_check_var = drm_fb_helper_check_var, |
| 210 | .fb_set_par = drm_fb_helper_set_par, |
| 211 | .fb_blank = drm_fb_helper_blank, |
| 212 | .fb_setcolreg = psbfb_setcolreg, |
Archit Taneja | 546187c | 2015-07-22 14:58:10 +0530 | [diff] [blame] | 213 | .fb_fillrect = drm_fb_helper_cfb_fillrect, |
| 214 | .fb_copyarea = drm_fb_helper_cfb_copyarea, |
| 215 | .fb_imageblit = drm_fb_helper_cfb_imageblit, |
Alan Cox | a6ba582 | 2011-11-29 22:27:22 +0000 | [diff] [blame] | 216 | .fb_pan_display = psbfb_pan, |
| 217 | .fb_mmap = psbfb_mmap, |
Alan Cox | a6ba582 | 2011-11-29 22:27:22 +0000 | [diff] [blame] | 218 | .fb_ioctl = psbfb_ioctl, |
| 219 | }; |
| 220 | |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 221 | static struct fb_ops psbfb_unaccel_ops = { |
| 222 | .owner = THIS_MODULE, |
| 223 | .fb_check_var = drm_fb_helper_check_var, |
| 224 | .fb_set_par = drm_fb_helper_set_par, |
| 225 | .fb_blank = drm_fb_helper_blank, |
| 226 | .fb_setcolreg = psbfb_setcolreg, |
Archit Taneja | 546187c | 2015-07-22 14:58:10 +0530 | [diff] [blame] | 227 | .fb_fillrect = drm_fb_helper_cfb_fillrect, |
| 228 | .fb_copyarea = drm_fb_helper_cfb_copyarea, |
| 229 | .fb_imageblit = drm_fb_helper_cfb_imageblit, |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 230 | .fb_mmap = psbfb_mmap, |
| 231 | .fb_ioctl = psbfb_ioctl, |
| 232 | }; |
| 233 | |
| 234 | /** |
| 235 | * psb_framebuffer_init - initialize a framebuffer |
| 236 | * @dev: our DRM device |
| 237 | * @fb: framebuffer to set up |
| 238 | * @mode_cmd: mode description |
| 239 | * @gt: backing object |
| 240 | * |
| 241 | * Configure and fill in the boilerplate for our frame buffer. Return |
| 242 | * 0 on success or an error code if we fail. |
| 243 | */ |
| 244 | static int psb_framebuffer_init(struct drm_device *dev, |
| 245 | struct psb_framebuffer *fb, |
Ville Syrjälä | 1eb8345 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 246 | const struct drm_mode_fb_cmd2 *mode_cmd, |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 247 | struct gtt_range *gt) |
| 248 | { |
Dave Airlie | a9a644a | 2011-11-28 14:08:46 +0000 | [diff] [blame] | 249 | u32 bpp, depth; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 250 | int ret; |
| 251 | |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 252 | drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp); |
Dave Airlie | a9a644a | 2011-11-28 14:08:46 +0000 | [diff] [blame] | 253 | |
| 254 | if (mode_cmd->pitches[0] & 63) |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 255 | return -EINVAL; |
Dave Airlie | a9a644a | 2011-11-28 14:08:46 +0000 | [diff] [blame] | 256 | switch (bpp) { |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 257 | case 8: |
| 258 | case 16: |
| 259 | case 24: |
| 260 | case 32: |
| 261 | break; |
| 262 | default: |
| 263 | return -EINVAL; |
| 264 | } |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 265 | drm_helper_mode_fill_fb_struct(&fb->base, mode_cmd); |
| 266 | fb->gtt = gt; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 267 | ret = drm_framebuffer_init(dev, &fb->base, &psb_fb_funcs); |
| 268 | if (ret) { |
| 269 | dev_err(dev->dev, "framebuffer init failed: %d\n", ret); |
| 270 | return ret; |
| 271 | } |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * psb_framebuffer_create - create a framebuffer backed by gt |
| 277 | * @dev: our DRM device |
| 278 | * @mode_cmd: the description of the requested mode |
| 279 | * @gt: the backing object |
| 280 | * |
| 281 | * Create a framebuffer object backed by the gt, and fill in the |
| 282 | * boilerplate required |
| 283 | * |
| 284 | * TODO: review object references |
| 285 | */ |
| 286 | |
| 287 | static struct drm_framebuffer *psb_framebuffer_create |
| 288 | (struct drm_device *dev, |
Ville Syrjälä | 1eb8345 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 289 | const struct drm_mode_fb_cmd2 *mode_cmd, |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 290 | struct gtt_range *gt) |
| 291 | { |
| 292 | struct psb_framebuffer *fb; |
| 293 | int ret; |
| 294 | |
| 295 | fb = kzalloc(sizeof(*fb), GFP_KERNEL); |
| 296 | if (!fb) |
| 297 | return ERR_PTR(-ENOMEM); |
| 298 | |
| 299 | ret = psb_framebuffer_init(dev, fb, mode_cmd, gt); |
| 300 | if (ret) { |
| 301 | kfree(fb); |
| 302 | return ERR_PTR(ret); |
| 303 | } |
| 304 | return &fb->base; |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * psbfb_alloc - allocate frame buffer memory |
| 309 | * @dev: the DRM device |
| 310 | * @aligned_size: space needed |
Alan Cox | a6ba582 | 2011-11-29 22:27:22 +0000 | [diff] [blame] | 311 | * @force: fall back to GEM buffers if need be |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 312 | * |
| 313 | * Allocate the frame buffer. In the usual case we get a GTT range that |
| 314 | * is stolen memory backed and life is simple. If there isn't sufficient |
Alan Cox | dffc9ce | 2011-11-29 22:19:47 +0000 | [diff] [blame] | 315 | * we fail as we don't have the virtual mapping space to really vmap it |
| 316 | * and the kernel console code can't handle non linear framebuffers. |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 317 | * |
Alan Cox | dffc9ce | 2011-11-29 22:19:47 +0000 | [diff] [blame] | 318 | * Re-address this as and if the framebuffer layer grows this ability. |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 319 | */ |
| 320 | static struct gtt_range *psbfb_alloc(struct drm_device *dev, int aligned_size) |
| 321 | { |
| 322 | struct gtt_range *backing; |
| 323 | /* Begin by trying to use stolen memory backing */ |
Patrik Jakobsson | c269c68 | 2014-01-06 02:39:10 +0100 | [diff] [blame] | 324 | backing = psb_gtt_alloc_range(dev, aligned_size, "fb", 1, PAGE_SIZE); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 325 | if (backing) { |
David Herrmann | 89c8233 | 2013-07-11 11:56:32 +0200 | [diff] [blame] | 326 | drm_gem_private_object_init(dev, &backing->gem, aligned_size); |
| 327 | return backing; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 328 | } |
Alan Cox | dffc9ce | 2011-11-29 22:19:47 +0000 | [diff] [blame] | 329 | return NULL; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /** |
| 333 | * psbfb_create - create a framebuffer |
| 334 | * @fbdev: the framebuffer device |
| 335 | * @sizes: specification of the layout |
| 336 | * |
| 337 | * Create a framebuffer to the specifications provided |
| 338 | */ |
| 339 | static int psbfb_create(struct psb_fbdev *fbdev, |
| 340 | struct drm_fb_helper_surface_size *sizes) |
| 341 | { |
| 342 | struct drm_device *dev = fbdev->psb_fb_helper.dev; |
| 343 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 344 | struct fb_info *info; |
| 345 | struct drm_framebuffer *fb; |
| 346 | struct psb_framebuffer *psbfb = &fbdev->pfb; |
Dave Airlie | a9a644a | 2011-11-28 14:08:46 +0000 | [diff] [blame] | 347 | struct drm_mode_fb_cmd2 mode_cmd; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 348 | int size; |
| 349 | int ret; |
| 350 | struct gtt_range *backing; |
Dave Airlie | a9a644a | 2011-11-28 14:08:46 +0000 | [diff] [blame] | 351 | u32 bpp, depth; |
Alan Cox | 1b223c9 | 2011-11-29 22:27:34 +0000 | [diff] [blame] | 352 | int gtt_roll = 0; |
| 353 | int pitch_lines = 0; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 354 | |
| 355 | mode_cmd.width = sizes->surface_width; |
| 356 | mode_cmd.height = sizes->surface_height; |
Dave Airlie | a9a644a | 2011-11-28 14:08:46 +0000 | [diff] [blame] | 357 | bpp = sizes->surface_bpp; |
Kirill A. Shutemov | 6aa1ead | 2012-03-08 16:02:36 +0000 | [diff] [blame] | 358 | depth = sizes->surface_depth; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 359 | |
| 360 | /* No 24bit packed */ |
Dave Airlie | a9a644a | 2011-11-28 14:08:46 +0000 | [diff] [blame] | 361 | if (bpp == 24) |
| 362 | bpp = 32; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 363 | |
Alan Cox | 1b223c9 | 2011-11-29 22:27:34 +0000 | [diff] [blame] | 364 | do { |
| 365 | /* |
| 366 | * Acceleration via the GTT requires pitch to be |
| 367 | * power of two aligned. Preferably page but less |
| 368 | * is ok with some fonts |
| 369 | */ |
| 370 | mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((bpp + 7) / 8), 4096 >> pitch_lines); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 371 | |
Alan Cox | 1b223c9 | 2011-11-29 22:27:34 +0000 | [diff] [blame] | 372 | size = mode_cmd.pitches[0] * mode_cmd.height; |
| 373 | size = ALIGN(size, PAGE_SIZE); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 374 | |
Alan Cox | 1b223c9 | 2011-11-29 22:27:34 +0000 | [diff] [blame] | 375 | /* Allocate the fb in the GTT with stolen page backing */ |
| 376 | backing = psbfb_alloc(dev, size); |
| 377 | |
| 378 | if (pitch_lines) |
| 379 | pitch_lines *= 2; |
| 380 | else |
| 381 | pitch_lines = 1; |
| 382 | gtt_roll++; |
| 383 | } while (backing == NULL && pitch_lines <= 16); |
| 384 | |
| 385 | /* The final pitch we accepted if we succeeded */ |
| 386 | pitch_lines /= 2; |
| 387 | |
Alan Cox | a6ba582 | 2011-11-29 22:27:22 +0000 | [diff] [blame] | 388 | if (backing == NULL) { |
| 389 | /* |
| 390 | * We couldn't get the space we wanted, fall back to the |
| 391 | * display engine requirement instead. The HW requires |
| 392 | * the pitch to be 64 byte aligned |
Alan Cox | a6ba582 | 2011-11-29 22:27:22 +0000 | [diff] [blame] | 393 | */ |
| 394 | |
| 395 | gtt_roll = 0; /* Don't use GTT accelerated scrolling */ |
Alan Cox | 1b223c9 | 2011-11-29 22:27:34 +0000 | [diff] [blame] | 396 | pitch_lines = 64; |
Alan Cox | a6ba582 | 2011-11-29 22:27:22 +0000 | [diff] [blame] | 397 | |
| 398 | mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((bpp + 7) / 8), 64); |
| 399 | |
| 400 | size = mode_cmd.pitches[0] * mode_cmd.height; |
| 401 | size = ALIGN(size, PAGE_SIZE); |
| 402 | |
| 403 | /* Allocate the framebuffer in the GTT with stolen page backing */ |
| 404 | backing = psbfb_alloc(dev, size); |
| 405 | if (backing == NULL) |
| 406 | return -ENOMEM; |
| 407 | } |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 408 | |
Alan Cox | bb84977 | 2012-05-03 15:05:53 +0100 | [diff] [blame] | 409 | memset(dev_priv->vram_addr + backing->offset, 0, size); |
| 410 | |
Archit Taneja | 546187c | 2015-07-22 14:58:10 +0530 | [diff] [blame] | 411 | info = drm_fb_helper_alloc_fbi(&fbdev->psb_fb_helper); |
| 412 | if (IS_ERR(info)) { |
| 413 | ret = PTR_ERR(info); |
Sudip Mukherjee | 4cd54d9 | 2015-10-08 18:17:48 +0530 | [diff] [blame] | 414 | goto err_free_range; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 415 | } |
| 416 | info->par = fbdev; |
| 417 | |
Dave Airlie | a9a644a | 2011-11-28 14:08:46 +0000 | [diff] [blame] | 418 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
| 419 | |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 420 | ret = psb_framebuffer_init(dev, psbfb, &mode_cmd, backing); |
| 421 | if (ret) |
Sudip Mukherjee | 4cd54d9 | 2015-10-08 18:17:48 +0530 | [diff] [blame] | 422 | goto err_release; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 423 | |
| 424 | fb = &psbfb->base; |
| 425 | psbfb->fbdev = info; |
| 426 | |
| 427 | fbdev->psb_fb_helper.fb = fb; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 428 | |
Alan Cox | 4578240 | 2012-03-08 16:01:39 +0000 | [diff] [blame] | 429 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); |
Patrik Jakobsson | f9d8149 | 2013-04-03 23:52:04 +0200 | [diff] [blame] | 430 | strcpy(info->fix.id, "psbdrmfb"); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 431 | |
| 432 | info->flags = FBINFO_DEFAULT; |
Alan Cox | 1b223c9 | 2011-11-29 22:27:34 +0000 | [diff] [blame] | 433 | if (dev_priv->ops->accel_2d && pitch_lines > 8) /* 2D engine */ |
| 434 | info->fbops = &psbfb_ops; |
| 435 | else if (gtt_roll) { /* GTT rolling seems best */ |
Alan Cox | a6ba582 | 2011-11-29 22:27:22 +0000 | [diff] [blame] | 436 | info->fbops = &psbfb_roll_ops; |
| 437 | info->flags |= FBINFO_HWACCEL_YPAN; |
Alan Cox | 1b223c9 | 2011-11-29 22:27:34 +0000 | [diff] [blame] | 438 | } else /* Software */ |
Alan Cox | a6ba582 | 2011-11-29 22:27:22 +0000 | [diff] [blame] | 439 | info->fbops = &psbfb_unaccel_ops; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 440 | |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 441 | info->fix.smem_start = dev->mode_config.fb_base; |
| 442 | info->fix.smem_len = size; |
Alan Cox | a6ba582 | 2011-11-29 22:27:22 +0000 | [diff] [blame] | 443 | info->fix.ywrapstep = gtt_roll; |
| 444 | info->fix.ypanstep = 0; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 445 | |
Alan Cox | dffc9ce | 2011-11-29 22:19:47 +0000 | [diff] [blame] | 446 | /* Accessed stolen memory directly */ |
Kirill A. Shutemov | 37214ca | 2012-05-03 15:08:26 +0100 | [diff] [blame] | 447 | info->screen_base = dev_priv->vram_addr + backing->offset; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 448 | info->screen_size = size; |
| 449 | |
| 450 | if (dev_priv->gtt.stolen_size) { |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 451 | info->apertures->ranges[0].base = dev->mode_config.fb_base; |
| 452 | info->apertures->ranges[0].size = dev_priv->gtt.stolen_size; |
| 453 | } |
| 454 | |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 455 | drm_fb_helper_fill_var(info, &fbdev->psb_fb_helper, |
| 456 | sizes->fb_width, sizes->fb_height); |
| 457 | |
| 458 | info->fix.mmio_start = pci_resource_start(dev->pdev, 0); |
| 459 | info->fix.mmio_len = pci_resource_len(dev->pdev, 0); |
| 460 | |
Sascha Hauer | fb2a99e | 2012-02-06 10:58:19 +0100 | [diff] [blame] | 461 | /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */ |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 462 | |
Alan Cox | 31a0685 | 2012-05-11 11:32:31 +0100 | [diff] [blame] | 463 | dev_dbg(dev->dev, "allocated %dx%d fb\n", |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 464 | psbfb->base.width, psbfb->base.height); |
| 465 | |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 466 | return 0; |
Sudip Mukherjee | 4cd54d9 | 2015-10-08 18:17:48 +0530 | [diff] [blame] | 467 | err_release: |
Archit Taneja | 546187c | 2015-07-22 14:58:10 +0530 | [diff] [blame] | 468 | drm_fb_helper_release_fbi(&fbdev->psb_fb_helper); |
Sudip Mukherjee | 4cd54d9 | 2015-10-08 18:17:48 +0530 | [diff] [blame] | 469 | err_free_range: |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 470 | psb_gtt_free_range(dev, backing); |
| 471 | return ret; |
| 472 | } |
| 473 | |
| 474 | /** |
| 475 | * psb_user_framebuffer_create - create framebuffer |
| 476 | * @dev: our DRM device |
| 477 | * @filp: client file |
| 478 | * @cmd: mode request |
| 479 | * |
| 480 | * Create a new framebuffer backed by a userspace GEM object |
| 481 | */ |
| 482 | static struct drm_framebuffer *psb_user_framebuffer_create |
| 483 | (struct drm_device *dev, struct drm_file *filp, |
Ville Syrjälä | 1eb8345 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 484 | const struct drm_mode_fb_cmd2 *cmd) |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 485 | { |
| 486 | struct gtt_range *r; |
| 487 | struct drm_gem_object *obj; |
| 488 | |
| 489 | /* |
| 490 | * Find the GEM object and thus the gtt range object that is |
| 491 | * to back this space |
| 492 | */ |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame^] | 493 | obj = drm_gem_object_lookup(filp, cmd->handles[0]); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 494 | if (obj == NULL) |
| 495 | return ERR_PTR(-ENOENT); |
| 496 | |
| 497 | /* Let the core code do all the work */ |
| 498 | r = container_of(obj, struct gtt_range, gem); |
| 499 | return psb_framebuffer_create(dev, cmd, r); |
| 500 | } |
| 501 | |
| 502 | static void psbfb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
| 503 | u16 blue, int regno) |
| 504 | { |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame] | 505 | struct gma_crtc *gma_crtc = to_gma_crtc(crtc); |
Alan Cox | 3df546b | 2012-03-08 16:00:00 +0000 | [diff] [blame] | 506 | |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame] | 507 | gma_crtc->lut_r[regno] = red >> 8; |
| 508 | gma_crtc->lut_g[regno] = green >> 8; |
| 509 | gma_crtc->lut_b[regno] = blue >> 8; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | static void psbfb_gamma_get(struct drm_crtc *crtc, u16 *red, |
| 513 | u16 *green, u16 *blue, int regno) |
| 514 | { |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame] | 515 | struct gma_crtc *gma_crtc = to_gma_crtc(crtc); |
Alan Cox | 3df546b | 2012-03-08 16:00:00 +0000 | [diff] [blame] | 516 | |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame] | 517 | *red = gma_crtc->lut_r[regno] << 8; |
| 518 | *green = gma_crtc->lut_g[regno] << 8; |
| 519 | *blue = gma_crtc->lut_b[regno] << 8; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static int psbfb_probe(struct drm_fb_helper *helper, |
| 523 | struct drm_fb_helper_surface_size *sizes) |
| 524 | { |
Fabian Frederick | c39aa6a | 2014-09-14 18:40:20 +0200 | [diff] [blame] | 525 | struct psb_fbdev *psb_fbdev = |
| 526 | container_of(helper, struct psb_fbdev, psb_fb_helper); |
Alan Cox | 3aad16d | 2012-04-25 14:37:40 +0100 | [diff] [blame] | 527 | struct drm_device *dev = psb_fbdev->psb_fb_helper.dev; |
| 528 | struct drm_psb_private *dev_priv = dev->dev_private; |
Alan Cox | 3aad16d | 2012-04-25 14:37:40 +0100 | [diff] [blame] | 529 | int bytespp; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 530 | |
Alan Cox | 3aad16d | 2012-04-25 14:37:40 +0100 | [diff] [blame] | 531 | bytespp = sizes->surface_bpp / 8; |
| 532 | if (bytespp == 3) /* no 24bit packed */ |
| 533 | bytespp = 4; |
| 534 | |
| 535 | /* If the mode will not fit in 32bit then switch to 16bit to get |
| 536 | a console on full resolution. The X mode setting server will |
| 537 | allocate its own 32bit GEM framebuffer */ |
| 538 | if (ALIGN(sizes->fb_width * bytespp, 64) * sizes->fb_height > |
| 539 | dev_priv->vram_stolen_size) { |
| 540 | sizes->surface_bpp = 16; |
| 541 | sizes->surface_depth = 16; |
| 542 | } |
| 543 | |
Daniel Vetter | cd5428a | 2013-01-21 23:42:49 +0100 | [diff] [blame] | 544 | return psbfb_create(psb_fbdev, sizes); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Thierry Reding | 3a49387 | 2014-06-27 17:19:23 +0200 | [diff] [blame] | 547 | static const struct drm_fb_helper_funcs psb_fb_helper_funcs = { |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 548 | .gamma_set = psbfb_gamma_set, |
| 549 | .gamma_get = psbfb_gamma_get, |
| 550 | .fb_probe = psbfb_probe, |
| 551 | }; |
| 552 | |
Kirill A. Shutemov | bc7f2b0 | 2012-03-08 16:03:44 +0000 | [diff] [blame] | 553 | static int psb_fbdev_destroy(struct drm_device *dev, struct psb_fbdev *fbdev) |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 554 | { |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 555 | struct psb_framebuffer *psbfb = &fbdev->pfb; |
| 556 | |
Archit Taneja | 546187c | 2015-07-22 14:58:10 +0530 | [diff] [blame] | 557 | drm_fb_helper_unregister_fbi(&fbdev->psb_fb_helper); |
| 558 | drm_fb_helper_release_fbi(&fbdev->psb_fb_helper); |
| 559 | |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 560 | drm_fb_helper_fini(&fbdev->psb_fb_helper); |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 561 | drm_framebuffer_unregister_private(&psbfb->base); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 562 | drm_framebuffer_cleanup(&psbfb->base); |
| 563 | |
| 564 | if (psbfb->gtt) |
Daniel Vetter | 46a0f22 | 2015-11-23 10:32:51 +0100 | [diff] [blame] | 565 | drm_gem_object_unreference_unlocked(&psbfb->gtt->gem); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | int psb_fbdev_init(struct drm_device *dev) |
| 570 | { |
| 571 | struct psb_fbdev *fbdev; |
| 572 | struct drm_psb_private *dev_priv = dev->dev_private; |
Thierry Reding | 01934c2 | 2014-12-19 11:21:32 +0100 | [diff] [blame] | 573 | int ret; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 574 | |
| 575 | fbdev = kzalloc(sizeof(struct psb_fbdev), GFP_KERNEL); |
| 576 | if (!fbdev) { |
| 577 | dev_err(dev->dev, "no memory\n"); |
| 578 | return -ENOMEM; |
| 579 | } |
| 580 | |
| 581 | dev_priv->fbdev = fbdev; |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 582 | |
| 583 | drm_fb_helper_prepare(dev, &fbdev->psb_fb_helper, &psb_fb_helper_funcs); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 584 | |
Thierry Reding | 01934c2 | 2014-12-19 11:21:32 +0100 | [diff] [blame] | 585 | ret = drm_fb_helper_init(dev, &fbdev->psb_fb_helper, |
| 586 | dev_priv->ops->crtcs, INTELFB_CONN_LIMIT); |
| 587 | if (ret) |
| 588 | goto free; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 589 | |
Thierry Reding | 01934c2 | 2014-12-19 11:21:32 +0100 | [diff] [blame] | 590 | ret = drm_fb_helper_single_add_all_connectors(&fbdev->psb_fb_helper); |
| 591 | if (ret) |
| 592 | goto fini; |
Daniel Vetter | 76a39db | 2013-01-20 23:12:54 +0100 | [diff] [blame] | 593 | |
| 594 | /* disable all the possible outputs/crtcs before entering KMS mode */ |
| 595 | drm_helper_disable_unused_functions(dev); |
| 596 | |
Thierry Reding | 01934c2 | 2014-12-19 11:21:32 +0100 | [diff] [blame] | 597 | ret = drm_fb_helper_initial_config(&fbdev->psb_fb_helper, 32); |
| 598 | if (ret) |
| 599 | goto fini; |
| 600 | |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 601 | return 0; |
Thierry Reding | 01934c2 | 2014-12-19 11:21:32 +0100 | [diff] [blame] | 602 | |
| 603 | fini: |
| 604 | drm_fb_helper_fini(&fbdev->psb_fb_helper); |
| 605 | free: |
| 606 | kfree(fbdev); |
| 607 | return ret; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 608 | } |
| 609 | |
Kirill A. Shutemov | bc7f2b0 | 2012-03-08 16:03:44 +0000 | [diff] [blame] | 610 | static void psb_fbdev_fini(struct drm_device *dev) |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 611 | { |
| 612 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 613 | |
| 614 | if (!dev_priv->fbdev) |
| 615 | return; |
| 616 | |
| 617 | psb_fbdev_destroy(dev, dev_priv->fbdev); |
| 618 | kfree(dev_priv->fbdev); |
| 619 | dev_priv->fbdev = NULL; |
| 620 | } |
| 621 | |
| 622 | static void psbfb_output_poll_changed(struct drm_device *dev) |
| 623 | { |
| 624 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 625 | struct psb_fbdev *fbdev = (struct psb_fbdev *)dev_priv->fbdev; |
| 626 | drm_fb_helper_hotplug_event(&fbdev->psb_fb_helper); |
| 627 | } |
| 628 | |
| 629 | /** |
| 630 | * psb_user_framebuffer_create_handle - add hamdle to a framebuffer |
| 631 | * @fb: framebuffer |
| 632 | * @file_priv: our DRM file |
| 633 | * @handle: returned handle |
| 634 | * |
| 635 | * Our framebuffer object is a GTT range which also contains a GEM |
| 636 | * object. We need to turn it into a handle for userspace. GEM will do |
| 637 | * the work for us |
| 638 | */ |
| 639 | static int psb_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
| 640 | struct drm_file *file_priv, |
| 641 | unsigned int *handle) |
| 642 | { |
| 643 | struct psb_framebuffer *psbfb = to_psb_fb(fb); |
| 644 | struct gtt_range *r = psbfb->gtt; |
| 645 | return drm_gem_handle_create(file_priv, &r->gem, handle); |
| 646 | } |
| 647 | |
| 648 | /** |
| 649 | * psb_user_framebuffer_destroy - destruct user created fb |
| 650 | * @fb: framebuffer |
| 651 | * |
| 652 | * User framebuffers are backed by GEM objects so all we have to do is |
| 653 | * clean up a bit and drop the reference, GEM will handle the fallout |
| 654 | */ |
| 655 | static void psb_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 656 | { |
| 657 | struct psb_framebuffer *psbfb = to_psb_fb(fb); |
| 658 | struct gtt_range *r = psbfb->gtt; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 659 | |
| 660 | /* Let DRM do its clean up */ |
| 661 | drm_framebuffer_cleanup(fb); |
| 662 | /* We are no longer using the resource in GEM */ |
| 663 | drm_gem_object_unreference_unlocked(&r->gem); |
| 664 | kfree(fb); |
| 665 | } |
| 666 | |
| 667 | static const struct drm_mode_config_funcs psb_mode_funcs = { |
| 668 | .fb_create = psb_user_framebuffer_create, |
| 669 | .output_poll_changed = psbfb_output_poll_changed, |
| 670 | }; |
| 671 | |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 672 | static void psb_setup_outputs(struct drm_device *dev) |
| 673 | { |
| 674 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 675 | struct drm_connector *connector; |
| 676 | |
| 677 | drm_mode_create_scaling_mode_property(dev); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 678 | |
Alan Cox | 13619ce | 2016-01-29 19:37:48 +0000 | [diff] [blame] | 679 | /* It is ok for this to fail - we just don't get backlight control */ |
| 680 | if (!dev_priv->backlight_property) |
| 681 | dev_priv->backlight_property = drm_property_create_range(dev, 0, |
| 682 | "backlight", 0, 100); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 683 | dev_priv->ops->output_init(dev); |
| 684 | |
| 685 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 686 | head) { |
Patrik Jakobsson | 367e440 | 2013-07-22 17:45:26 +0200 | [diff] [blame] | 687 | struct gma_encoder *gma_encoder = gma_attached_encoder(connector); |
| 688 | struct drm_encoder *encoder = &gma_encoder->base; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 689 | int crtc_mask = 0, clone_mask = 0; |
| 690 | |
| 691 | /* valid crtcs */ |
Patrik Jakobsson | 367e440 | 2013-07-22 17:45:26 +0200 | [diff] [blame] | 692 | switch (gma_encoder->type) { |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 693 | case INTEL_OUTPUT_ANALOG: |
| 694 | crtc_mask = (1 << 0); |
| 695 | clone_mask = (1 << INTEL_OUTPUT_ANALOG); |
| 696 | break; |
| 697 | case INTEL_OUTPUT_SDVO: |
Patrik Jakobsson | cf8efd3 | 2013-09-16 17:54:54 +0200 | [diff] [blame] | 698 | crtc_mask = dev_priv->ops->sdvo_mask; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 699 | clone_mask = (1 << INTEL_OUTPUT_SDVO); |
| 700 | break; |
| 701 | case INTEL_OUTPUT_LVDS: |
Alan Cox | d235e64 | 2012-04-25 14:38:07 +0100 | [diff] [blame] | 702 | crtc_mask = dev_priv->ops->lvds_mask; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 703 | clone_mask = (1 << INTEL_OUTPUT_LVDS); |
| 704 | break; |
| 705 | case INTEL_OUTPUT_MIPI: |
| 706 | crtc_mask = (1 << 0); |
| 707 | clone_mask = (1 << INTEL_OUTPUT_MIPI); |
| 708 | break; |
| 709 | case INTEL_OUTPUT_MIPI2: |
| 710 | crtc_mask = (1 << 2); |
| 711 | clone_mask = (1 << INTEL_OUTPUT_MIPI2); |
| 712 | break; |
| 713 | case INTEL_OUTPUT_HDMI: |
Alan Cox | d235e64 | 2012-04-25 14:38:07 +0100 | [diff] [blame] | 714 | crtc_mask = dev_priv->ops->hdmi_mask; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 715 | clone_mask = (1 << INTEL_OUTPUT_HDMI); |
| 716 | break; |
Alan Cox | 220801b | 2012-08-08 13:54:41 +0000 | [diff] [blame] | 717 | case INTEL_OUTPUT_DISPLAYPORT: |
| 718 | crtc_mask = (1 << 0) | (1 << 1); |
| 719 | clone_mask = (1 << INTEL_OUTPUT_DISPLAYPORT); |
| 720 | break; |
Zhao Yakui | d112a81 | 2012-08-08 13:55:55 +0000 | [diff] [blame] | 721 | case INTEL_OUTPUT_EDP: |
| 722 | crtc_mask = (1 << 1); |
| 723 | clone_mask = (1 << INTEL_OUTPUT_EDP); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 724 | } |
| 725 | encoder->possible_crtcs = crtc_mask; |
| 726 | encoder->possible_clones = |
Patrik Jakobsson | a3d5d75 | 2013-07-22 17:05:25 +0200 | [diff] [blame] | 727 | gma_connector_clones(dev, clone_mask); |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
| 731 | void psb_modeset_init(struct drm_device *dev) |
| 732 | { |
| 733 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 734 | struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; |
| 735 | int i; |
| 736 | |
| 737 | drm_mode_config_init(dev); |
| 738 | |
| 739 | dev->mode_config.min_width = 0; |
| 740 | dev->mode_config.min_height = 0; |
| 741 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 742 | dev->mode_config.funcs = &psb_mode_funcs; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 743 | |
| 744 | /* set memory base */ |
Alan Cox | dffc9ce | 2011-11-29 22:19:47 +0000 | [diff] [blame] | 745 | /* Oaktrail and Poulsbo should use BAR 2*/ |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 746 | pci_read_config_dword(dev->pdev, PSB_BSM, (u32 *) |
| 747 | &(dev->mode_config.fb_base)); |
| 748 | |
| 749 | /* num pipes is 2 for PSB but 1 for Mrst */ |
| 750 | for (i = 0; i < dev_priv->num_pipe; i++) |
| 751 | psb_intel_crtc_init(dev, i, mode_dev); |
| 752 | |
Patrik Jakobsson | cbbd379 | 2013-04-25 22:23:36 +0200 | [diff] [blame] | 753 | dev->mode_config.max_width = 4096; |
| 754 | dev->mode_config.max_height = 4096; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 755 | |
| 756 | psb_setup_outputs(dev); |
Alan Cox | d235e64 | 2012-04-25 14:38:07 +0100 | [diff] [blame] | 757 | |
| 758 | if (dev_priv->ops->errata) |
| 759 | dev_priv->ops->errata(dev); |
Alan Cox | 4ab2c7f | 2012-05-14 12:04:00 +0100 | [diff] [blame] | 760 | |
| 761 | dev_priv->modeset = true; |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | void psb_modeset_cleanup(struct drm_device *dev) |
| 765 | { |
Alan Cox | 4ab2c7f | 2012-05-14 12:04:00 +0100 | [diff] [blame] | 766 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 767 | if (dev_priv->modeset) { |
Alan Cox | 4ab2c7f | 2012-05-14 12:04:00 +0100 | [diff] [blame] | 768 | drm_kms_helper_poll_fini(dev); |
| 769 | psb_fbdev_fini(dev); |
| 770 | drm_mode_config_cleanup(dev); |
Alan Cox | 4ab2c7f | 2012-05-14 12:04:00 +0100 | [diff] [blame] | 771 | } |
Alan Cox | 4d8d096 | 2011-11-03 18:21:20 +0000 | [diff] [blame] | 772 | } |