14d8d096eSAlan Cox /************************************************************************** 24d8d096eSAlan Cox * Copyright (c) 2007-2011, Intel Corporation. 34d8d096eSAlan Cox * All Rights Reserved. 44d8d096eSAlan Cox * 54d8d096eSAlan Cox * This program is free software; you can redistribute it and/or modify it 64d8d096eSAlan Cox * under the terms and conditions of the GNU General Public License, 74d8d096eSAlan Cox * version 2, as published by the Free Software Foundation. 84d8d096eSAlan Cox * 94d8d096eSAlan Cox * This program is distributed in the hope it will be useful, but WITHOUT 104d8d096eSAlan Cox * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 114d8d096eSAlan Cox * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 124d8d096eSAlan Cox * more details. 134d8d096eSAlan Cox * 144d8d096eSAlan Cox * You should have received a copy of the GNU General Public License along with 154d8d096eSAlan Cox * this program; if not, write to the Free Software Foundation, Inc., 164d8d096eSAlan Cox * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 174d8d096eSAlan Cox * 184d8d096eSAlan Cox **************************************************************************/ 194d8d096eSAlan Cox 204d8d096eSAlan Cox #include <linux/module.h> 214d8d096eSAlan Cox #include <linux/kernel.h> 224d8d096eSAlan Cox #include <linux/errno.h> 234d8d096eSAlan Cox #include <linux/string.h> 2401c8f1c4SDan Williams #include <linux/pfn_t.h> 254d8d096eSAlan Cox #include <linux/mm.h> 264d8d096eSAlan Cox #include <linux/tty.h> 274d8d096eSAlan Cox #include <linux/slab.h> 284d8d096eSAlan Cox #include <linux/delay.h> 294d8d096eSAlan Cox #include <linux/init.h> 304d8d096eSAlan Cox #include <linux/console.h> 314d8d096eSAlan Cox 324d8d096eSAlan Cox #include <drm/drmP.h> 334d8d096eSAlan Cox #include <drm/drm.h> 344d8d096eSAlan Cox #include <drm/drm_crtc.h> 35a9a644acSDave Airlie #include <drm/drm_fb_helper.h> 364d8d096eSAlan Cox 374d8d096eSAlan Cox #include "psb_drv.h" 384d8d096eSAlan Cox #include "psb_intel_reg.h" 394d8d096eSAlan Cox #include "psb_intel_drv.h" 404d8d096eSAlan Cox #include "framebuffer.h" 41a6ba582dSAlan Cox #include "gtt.h" 424d8d096eSAlan Cox 434d8d096eSAlan Cox static void psb_user_framebuffer_destroy(struct drm_framebuffer *fb); 444d8d096eSAlan Cox static int psb_user_framebuffer_create_handle(struct drm_framebuffer *fb, 454d8d096eSAlan Cox struct drm_file *file_priv, 464d8d096eSAlan Cox unsigned int *handle); 474d8d096eSAlan Cox 484d8d096eSAlan Cox static const struct drm_framebuffer_funcs psb_fb_funcs = { 494d8d096eSAlan Cox .destroy = psb_user_framebuffer_destroy, 504d8d096eSAlan Cox .create_handle = psb_user_framebuffer_create_handle, 514d8d096eSAlan Cox }; 524d8d096eSAlan Cox 534d8d096eSAlan Cox #define CMAP_TOHW(_val, _width) ((((_val) << (_width)) + 0x7FFF - (_val)) >> 16) 544d8d096eSAlan Cox 554d8d096eSAlan Cox static int psbfb_setcolreg(unsigned regno, unsigned red, unsigned green, 564d8d096eSAlan Cox unsigned blue, unsigned transp, 574d8d096eSAlan Cox struct fb_info *info) 584d8d096eSAlan Cox { 594d8d096eSAlan Cox struct psb_fbdev *fbdev = info->par; 604d8d096eSAlan Cox struct drm_framebuffer *fb = fbdev->psb_fb_helper.fb; 614d8d096eSAlan Cox uint32_t v; 624d8d096eSAlan Cox 634d8d096eSAlan Cox if (!fb) 644d8d096eSAlan Cox return -ENOMEM; 654d8d096eSAlan Cox 664d8d096eSAlan Cox if (regno > 255) 674d8d096eSAlan Cox return 1; 684d8d096eSAlan Cox 694d8d096eSAlan Cox red = CMAP_TOHW(red, info->var.red.length); 704d8d096eSAlan Cox blue = CMAP_TOHW(blue, info->var.blue.length); 714d8d096eSAlan Cox green = CMAP_TOHW(green, info->var.green.length); 724d8d096eSAlan Cox transp = CMAP_TOHW(transp, info->var.transp.length); 734d8d096eSAlan Cox 744d8d096eSAlan Cox v = (red << info->var.red.offset) | 754d8d096eSAlan Cox (green << info->var.green.offset) | 764d8d096eSAlan Cox (blue << info->var.blue.offset) | 774d8d096eSAlan Cox (transp << info->var.transp.offset); 784d8d096eSAlan Cox 794d8d096eSAlan Cox if (regno < 16) { 804d8d096eSAlan Cox switch (fb->bits_per_pixel) { 814d8d096eSAlan Cox case 16: 824d8d096eSAlan Cox ((uint32_t *) info->pseudo_palette)[regno] = v; 834d8d096eSAlan Cox break; 844d8d096eSAlan Cox case 24: 854d8d096eSAlan Cox case 32: 864d8d096eSAlan Cox ((uint32_t *) info->pseudo_palette)[regno] = v; 874d8d096eSAlan Cox break; 884d8d096eSAlan Cox } 894d8d096eSAlan Cox } 904d8d096eSAlan Cox 914d8d096eSAlan Cox return 0; 924d8d096eSAlan Cox } 934d8d096eSAlan Cox 94a6ba582dSAlan Cox static int psbfb_pan(struct fb_var_screeninfo *var, struct fb_info *info) 95a6ba582dSAlan Cox { 96a6ba582dSAlan Cox struct psb_fbdev *fbdev = info->par; 97a6ba582dSAlan Cox struct psb_framebuffer *psbfb = &fbdev->pfb; 98a6ba582dSAlan Cox struct drm_device *dev = psbfb->base.dev; 99a6ba582dSAlan Cox 100a6ba582dSAlan Cox /* 101a6ba582dSAlan Cox * We have to poke our nose in here. The core fb code assumes 102a6ba582dSAlan Cox * panning is part of the hardware that can be invoked before 103a6ba582dSAlan Cox * the actual fb is mapped. In our case that isn't quite true. 104a6ba582dSAlan Cox */ 105a6ba582dSAlan Cox if (psbfb->gtt->npage) { 106a6ba582dSAlan Cox /* GTT roll shifts in 4K pages, we need to shift the right 107a6ba582dSAlan Cox number of pages */ 108a6ba582dSAlan Cox int pages = info->fix.line_length >> 12; 109a6ba582dSAlan Cox psb_gtt_roll(dev, psbfb->gtt, var->yoffset * pages); 110a6ba582dSAlan Cox } 111a6ba582dSAlan Cox return 0; 112a6ba582dSAlan Cox } 1134d8d096eSAlan Cox 1144d8d096eSAlan Cox static int psbfb_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) 1154d8d096eSAlan Cox { 1164d8d096eSAlan Cox struct psb_framebuffer *psbfb = vma->vm_private_data; 1174d8d096eSAlan Cox struct drm_device *dev = psbfb->base.dev; 1184d8d096eSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 1194d8d096eSAlan Cox int page_num; 1204d8d096eSAlan Cox int i; 1214d8d096eSAlan Cox unsigned long address; 1224d8d096eSAlan Cox int ret; 1234d8d096eSAlan Cox unsigned long pfn; 12461bb3feaSPatrik Jakobsson unsigned long phys_addr = (unsigned long)dev_priv->stolen_base + 12561bb3feaSPatrik Jakobsson psbfb->gtt->offset; 1264d8d096eSAlan Cox 127024b6a63SShyam Saini page_num = vma_pages(vma); 1281278f7deSYoichi Yuasa address = (unsigned long)vmf->virtual_address - (vmf->pgoff << PAGE_SHIFT); 1294d8d096eSAlan Cox 1304d8d096eSAlan Cox vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 1314d8d096eSAlan Cox 1324d8d096eSAlan Cox for (i = 0; i < page_num; i++) { 1334d8d096eSAlan Cox pfn = (phys_addr >> PAGE_SHIFT); 1344d8d096eSAlan Cox 13501c8f1c4SDan Williams ret = vm_insert_mixed(vma, address, 13601c8f1c4SDan Williams __pfn_to_pfn_t(pfn, PFN_DEV)); 1374d8d096eSAlan Cox if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0))) 1384d8d096eSAlan Cox break; 1394d8d096eSAlan Cox else if (unlikely(ret != 0)) { 1404d8d096eSAlan Cox ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS; 1414d8d096eSAlan Cox return ret; 1424d8d096eSAlan Cox } 1434d8d096eSAlan Cox address += PAGE_SIZE; 1444d8d096eSAlan Cox phys_addr += PAGE_SIZE; 1454d8d096eSAlan Cox } 1464d8d096eSAlan Cox return VM_FAULT_NOPAGE; 1474d8d096eSAlan Cox } 1484d8d096eSAlan Cox 1494d8d096eSAlan Cox static void psbfb_vm_open(struct vm_area_struct *vma) 1504d8d096eSAlan Cox { 1514d8d096eSAlan Cox } 1524d8d096eSAlan Cox 1534d8d096eSAlan Cox static void psbfb_vm_close(struct vm_area_struct *vma) 1544d8d096eSAlan Cox { 1554d8d096eSAlan Cox } 1564d8d096eSAlan Cox 15778b68556SLaurent Pinchart static const struct vm_operations_struct psbfb_vm_ops = { 1584d8d096eSAlan Cox .fault = psbfb_vm_fault, 1594d8d096eSAlan Cox .open = psbfb_vm_open, 1604d8d096eSAlan Cox .close = psbfb_vm_close 1614d8d096eSAlan Cox }; 1624d8d096eSAlan Cox 1634d8d096eSAlan Cox static int psbfb_mmap(struct fb_info *info, struct vm_area_struct *vma) 1644d8d096eSAlan Cox { 1654d8d096eSAlan Cox struct psb_fbdev *fbdev = info->par; 1664d8d096eSAlan Cox struct psb_framebuffer *psbfb = &fbdev->pfb; 1674d8d096eSAlan Cox 1684d8d096eSAlan Cox if (vma->vm_pgoff != 0) 1694d8d096eSAlan Cox return -EINVAL; 1704d8d096eSAlan Cox if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) 1714d8d096eSAlan Cox return -EINVAL; 1724d8d096eSAlan Cox 1734d8d096eSAlan Cox if (!psbfb->addr_space) 1744d8d096eSAlan Cox psbfb->addr_space = vma->vm_file->f_mapping; 1754d8d096eSAlan Cox /* 1764d8d096eSAlan Cox * If this is a GEM object then info->screen_base is the virtual 1774d8d096eSAlan Cox * kernel remapping of the object. FIXME: Review if this is 1784d8d096eSAlan Cox * suitable for our mmap work 1794d8d096eSAlan Cox */ 1804d8d096eSAlan Cox vma->vm_ops = &psbfb_vm_ops; 1814d8d096eSAlan Cox vma->vm_private_data = (void *)psbfb; 182314e51b9SKonstantin Khlebnikov vma->vm_flags |= VM_IO | VM_MIXEDMAP | VM_DONTEXPAND | VM_DONTDUMP; 1834d8d096eSAlan Cox return 0; 1844d8d096eSAlan Cox } 1854d8d096eSAlan Cox 1864d8d096eSAlan Cox static struct fb_ops psbfb_ops = { 1874d8d096eSAlan Cox .owner = THIS_MODULE, 1884d8d096eSAlan Cox .fb_check_var = drm_fb_helper_check_var, 1894d8d096eSAlan Cox .fb_set_par = drm_fb_helper_set_par, 1904d8d096eSAlan Cox .fb_blank = drm_fb_helper_blank, 1914d8d096eSAlan Cox .fb_setcolreg = psbfb_setcolreg, 192546187c8SArchit Taneja .fb_fillrect = drm_fb_helper_cfb_fillrect, 1934d8d096eSAlan Cox .fb_copyarea = psbfb_copyarea, 194546187c8SArchit Taneja .fb_imageblit = drm_fb_helper_cfb_imageblit, 1954d8d096eSAlan Cox .fb_mmap = psbfb_mmap, 1964d8d096eSAlan Cox .fb_sync = psbfb_sync, 1974d8d096eSAlan Cox }; 1984d8d096eSAlan Cox 199a6ba582dSAlan Cox static struct fb_ops psbfb_roll_ops = { 200a6ba582dSAlan Cox .owner = THIS_MODULE, 201a6ba582dSAlan Cox .fb_check_var = drm_fb_helper_check_var, 202a6ba582dSAlan Cox .fb_set_par = drm_fb_helper_set_par, 203a6ba582dSAlan Cox .fb_blank = drm_fb_helper_blank, 204a6ba582dSAlan Cox .fb_setcolreg = psbfb_setcolreg, 205546187c8SArchit Taneja .fb_fillrect = drm_fb_helper_cfb_fillrect, 206546187c8SArchit Taneja .fb_copyarea = drm_fb_helper_cfb_copyarea, 207546187c8SArchit Taneja .fb_imageblit = drm_fb_helper_cfb_imageblit, 208a6ba582dSAlan Cox .fb_pan_display = psbfb_pan, 209a6ba582dSAlan Cox .fb_mmap = psbfb_mmap, 210a6ba582dSAlan Cox }; 211a6ba582dSAlan Cox 2124d8d096eSAlan Cox static struct fb_ops psbfb_unaccel_ops = { 2134d8d096eSAlan Cox .owner = THIS_MODULE, 2144d8d096eSAlan Cox .fb_check_var = drm_fb_helper_check_var, 2154d8d096eSAlan Cox .fb_set_par = drm_fb_helper_set_par, 2164d8d096eSAlan Cox .fb_blank = drm_fb_helper_blank, 2174d8d096eSAlan Cox .fb_setcolreg = psbfb_setcolreg, 218546187c8SArchit Taneja .fb_fillrect = drm_fb_helper_cfb_fillrect, 219546187c8SArchit Taneja .fb_copyarea = drm_fb_helper_cfb_copyarea, 220546187c8SArchit Taneja .fb_imageblit = drm_fb_helper_cfb_imageblit, 2214d8d096eSAlan Cox .fb_mmap = psbfb_mmap, 2224d8d096eSAlan Cox }; 2234d8d096eSAlan Cox 2244d8d096eSAlan Cox /** 2254d8d096eSAlan Cox * psb_framebuffer_init - initialize a framebuffer 2264d8d096eSAlan Cox * @dev: our DRM device 2274d8d096eSAlan Cox * @fb: framebuffer to set up 2284d8d096eSAlan Cox * @mode_cmd: mode description 2294d8d096eSAlan Cox * @gt: backing object 2304d8d096eSAlan Cox * 2314d8d096eSAlan Cox * Configure and fill in the boilerplate for our frame buffer. Return 2324d8d096eSAlan Cox * 0 on success or an error code if we fail. 2334d8d096eSAlan Cox */ 2344d8d096eSAlan Cox static int psb_framebuffer_init(struct drm_device *dev, 2354d8d096eSAlan Cox struct psb_framebuffer *fb, 2361eb83451SVille Syrjälä const struct drm_mode_fb_cmd2 *mode_cmd, 2374d8d096eSAlan Cox struct gtt_range *gt) 2384d8d096eSAlan Cox { 239a9a644acSDave Airlie u32 bpp, depth; 2404d8d096eSAlan Cox int ret; 2414d8d096eSAlan Cox 242248dbc23SDave Airlie drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp); 243a9a644acSDave Airlie 244a9a644acSDave Airlie if (mode_cmd->pitches[0] & 63) 2454d8d096eSAlan Cox return -EINVAL; 246a9a644acSDave Airlie switch (bpp) { 2474d8d096eSAlan Cox case 8: 2484d8d096eSAlan Cox case 16: 2494d8d096eSAlan Cox case 24: 2504d8d096eSAlan Cox case 32: 2514d8d096eSAlan Cox break; 2524d8d096eSAlan Cox default: 2534d8d096eSAlan Cox return -EINVAL; 2544d8d096eSAlan Cox } 255c7d73f6aSDaniel Vetter drm_helper_mode_fill_fb_struct(&fb->base, mode_cmd); 256c7d73f6aSDaniel Vetter fb->gtt = gt; 2574d8d096eSAlan Cox ret = drm_framebuffer_init(dev, &fb->base, &psb_fb_funcs); 2584d8d096eSAlan Cox if (ret) { 2594d8d096eSAlan Cox dev_err(dev->dev, "framebuffer init failed: %d\n", ret); 2604d8d096eSAlan Cox return ret; 2614d8d096eSAlan Cox } 2624d8d096eSAlan Cox return 0; 2634d8d096eSAlan Cox } 2644d8d096eSAlan Cox 2654d8d096eSAlan Cox /** 2664d8d096eSAlan Cox * psb_framebuffer_create - create a framebuffer backed by gt 2674d8d096eSAlan Cox * @dev: our DRM device 2684d8d096eSAlan Cox * @mode_cmd: the description of the requested mode 2694d8d096eSAlan Cox * @gt: the backing object 2704d8d096eSAlan Cox * 2714d8d096eSAlan Cox * Create a framebuffer object backed by the gt, and fill in the 2724d8d096eSAlan Cox * boilerplate required 2734d8d096eSAlan Cox * 2744d8d096eSAlan Cox * TODO: review object references 2754d8d096eSAlan Cox */ 2764d8d096eSAlan Cox 2774d8d096eSAlan Cox static struct drm_framebuffer *psb_framebuffer_create 2784d8d096eSAlan Cox (struct drm_device *dev, 2791eb83451SVille Syrjälä const struct drm_mode_fb_cmd2 *mode_cmd, 2804d8d096eSAlan Cox struct gtt_range *gt) 2814d8d096eSAlan Cox { 2824d8d096eSAlan Cox struct psb_framebuffer *fb; 2834d8d096eSAlan Cox int ret; 2844d8d096eSAlan Cox 2854d8d096eSAlan Cox fb = kzalloc(sizeof(*fb), GFP_KERNEL); 2864d8d096eSAlan Cox if (!fb) 2874d8d096eSAlan Cox return ERR_PTR(-ENOMEM); 2884d8d096eSAlan Cox 2894d8d096eSAlan Cox ret = psb_framebuffer_init(dev, fb, mode_cmd, gt); 2904d8d096eSAlan Cox if (ret) { 2914d8d096eSAlan Cox kfree(fb); 2924d8d096eSAlan Cox return ERR_PTR(ret); 2934d8d096eSAlan Cox } 2944d8d096eSAlan Cox return &fb->base; 2954d8d096eSAlan Cox } 2964d8d096eSAlan Cox 2974d8d096eSAlan Cox /** 2984d8d096eSAlan Cox * psbfb_alloc - allocate frame buffer memory 2994d8d096eSAlan Cox * @dev: the DRM device 3004d8d096eSAlan Cox * @aligned_size: space needed 301a6ba582dSAlan Cox * @force: fall back to GEM buffers if need be 3024d8d096eSAlan Cox * 3034d8d096eSAlan Cox * Allocate the frame buffer. In the usual case we get a GTT range that 3044d8d096eSAlan Cox * is stolen memory backed and life is simple. If there isn't sufficient 305dffc9cebSAlan Cox * we fail as we don't have the virtual mapping space to really vmap it 306dffc9cebSAlan Cox * and the kernel console code can't handle non linear framebuffers. 3074d8d096eSAlan Cox * 308dffc9cebSAlan Cox * Re-address this as and if the framebuffer layer grows this ability. 3094d8d096eSAlan Cox */ 3104d8d096eSAlan Cox static struct gtt_range *psbfb_alloc(struct drm_device *dev, int aligned_size) 3114d8d096eSAlan Cox { 3124d8d096eSAlan Cox struct gtt_range *backing; 3134d8d096eSAlan Cox /* Begin by trying to use stolen memory backing */ 314c269c685SPatrik Jakobsson backing = psb_gtt_alloc_range(dev, aligned_size, "fb", 1, PAGE_SIZE); 3154d8d096eSAlan Cox if (backing) { 31689c8233fSDavid Herrmann drm_gem_private_object_init(dev, &backing->gem, aligned_size); 3174d8d096eSAlan Cox return backing; 3184d8d096eSAlan Cox } 3194d8d096eSAlan Cox return NULL; 3204d8d096eSAlan Cox } 3214d8d096eSAlan Cox 3224d8d096eSAlan Cox /** 3234d8d096eSAlan Cox * psbfb_create - create a framebuffer 3244d8d096eSAlan Cox * @fbdev: the framebuffer device 3254d8d096eSAlan Cox * @sizes: specification of the layout 3264d8d096eSAlan Cox * 3274d8d096eSAlan Cox * Create a framebuffer to the specifications provided 3284d8d096eSAlan Cox */ 3294d8d096eSAlan Cox static int psbfb_create(struct psb_fbdev *fbdev, 3304d8d096eSAlan Cox struct drm_fb_helper_surface_size *sizes) 3314d8d096eSAlan Cox { 3324d8d096eSAlan Cox struct drm_device *dev = fbdev->psb_fb_helper.dev; 3334d8d096eSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 3344d8d096eSAlan Cox struct fb_info *info; 3354d8d096eSAlan Cox struct drm_framebuffer *fb; 3364d8d096eSAlan Cox struct psb_framebuffer *psbfb = &fbdev->pfb; 337a9a644acSDave Airlie struct drm_mode_fb_cmd2 mode_cmd; 3384d8d096eSAlan Cox int size; 3394d8d096eSAlan Cox int ret; 3404d8d096eSAlan Cox struct gtt_range *backing; 341a9a644acSDave Airlie u32 bpp, depth; 3421b223c9eSAlan Cox int gtt_roll = 0; 3431b223c9eSAlan Cox int pitch_lines = 0; 3444d8d096eSAlan Cox 3454d8d096eSAlan Cox mode_cmd.width = sizes->surface_width; 3464d8d096eSAlan Cox mode_cmd.height = sizes->surface_height; 347a9a644acSDave Airlie bpp = sizes->surface_bpp; 3486aa1ead1SKirill A. Shutemov depth = sizes->surface_depth; 3494d8d096eSAlan Cox 3504d8d096eSAlan Cox /* No 24bit packed */ 351a9a644acSDave Airlie if (bpp == 24) 352a9a644acSDave Airlie bpp = 32; 3534d8d096eSAlan Cox 3541b223c9eSAlan Cox do { 3551b223c9eSAlan Cox /* 3561b223c9eSAlan Cox * Acceleration via the GTT requires pitch to be 3571b223c9eSAlan Cox * power of two aligned. Preferably page but less 3581b223c9eSAlan Cox * is ok with some fonts 3591b223c9eSAlan Cox */ 3601b223c9eSAlan Cox mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((bpp + 7) / 8), 4096 >> pitch_lines); 3614d8d096eSAlan Cox 362a9a644acSDave Airlie size = mode_cmd.pitches[0] * mode_cmd.height; 3634d8d096eSAlan Cox size = ALIGN(size, PAGE_SIZE); 3644d8d096eSAlan Cox 3651b223c9eSAlan Cox /* Allocate the fb in the GTT with stolen page backing */ 366a6ba582dSAlan Cox backing = psbfb_alloc(dev, size); 3671b223c9eSAlan Cox 3681b223c9eSAlan Cox if (pitch_lines) 3691b223c9eSAlan Cox pitch_lines *= 2; 3701b223c9eSAlan Cox else 3711b223c9eSAlan Cox pitch_lines = 1; 3721b223c9eSAlan Cox gtt_roll++; 3731b223c9eSAlan Cox } while (backing == NULL && pitch_lines <= 16); 3741b223c9eSAlan Cox 3751b223c9eSAlan Cox /* The final pitch we accepted if we succeeded */ 3761b223c9eSAlan Cox pitch_lines /= 2; 3771b223c9eSAlan Cox 378a6ba582dSAlan Cox if (backing == NULL) { 379a6ba582dSAlan Cox /* 380a6ba582dSAlan Cox * We couldn't get the space we wanted, fall back to the 381a6ba582dSAlan Cox * display engine requirement instead. The HW requires 382a6ba582dSAlan Cox * the pitch to be 64 byte aligned 383a6ba582dSAlan Cox */ 384a6ba582dSAlan Cox 385a6ba582dSAlan Cox gtt_roll = 0; /* Don't use GTT accelerated scrolling */ 3861b223c9eSAlan Cox pitch_lines = 64; 387a6ba582dSAlan Cox 388a6ba582dSAlan Cox mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((bpp + 7) / 8), 64); 389a6ba582dSAlan Cox 390a6ba582dSAlan Cox size = mode_cmd.pitches[0] * mode_cmd.height; 391a6ba582dSAlan Cox size = ALIGN(size, PAGE_SIZE); 392a6ba582dSAlan Cox 3934d8d096eSAlan Cox /* Allocate the framebuffer in the GTT with stolen page backing */ 3944d8d096eSAlan Cox backing = psbfb_alloc(dev, size); 3954d8d096eSAlan Cox if (backing == NULL) 3964d8d096eSAlan Cox return -ENOMEM; 397a6ba582dSAlan Cox } 3984d8d096eSAlan Cox 399bb849779SAlan Cox memset(dev_priv->vram_addr + backing->offset, 0, size); 400bb849779SAlan Cox 401546187c8SArchit Taneja info = drm_fb_helper_alloc_fbi(&fbdev->psb_fb_helper); 402546187c8SArchit Taneja if (IS_ERR(info)) { 403546187c8SArchit Taneja ret = PTR_ERR(info); 4044cd54d98SSudip Mukherjee goto err_free_range; 4054d8d096eSAlan Cox } 4064d8d096eSAlan Cox info->par = fbdev; 4074d8d096eSAlan Cox 408a9a644acSDave Airlie mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); 409a9a644acSDave Airlie 4104d8d096eSAlan Cox ret = psb_framebuffer_init(dev, psbfb, &mode_cmd, backing); 4114d8d096eSAlan Cox if (ret) 4124cd54d98SSudip Mukherjee goto err_release; 4134d8d096eSAlan Cox 4144d8d096eSAlan Cox fb = &psbfb->base; 4154d8d096eSAlan Cox psbfb->fbdev = info; 4164d8d096eSAlan Cox 4174d8d096eSAlan Cox fbdev->psb_fb_helper.fb = fb; 4184d8d096eSAlan Cox 4194578240bSAlan Cox drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); 420f9d8149aSPatrik Jakobsson strcpy(info->fix.id, "psbdrmfb"); 4214d8d096eSAlan Cox 4224d8d096eSAlan Cox info->flags = FBINFO_DEFAULT; 4231b223c9eSAlan Cox if (dev_priv->ops->accel_2d && pitch_lines > 8) /* 2D engine */ 4241b223c9eSAlan Cox info->fbops = &psbfb_ops; 4251b223c9eSAlan Cox else if (gtt_roll) { /* GTT rolling seems best */ 426a6ba582dSAlan Cox info->fbops = &psbfb_roll_ops; 427a6ba582dSAlan Cox info->flags |= FBINFO_HWACCEL_YPAN; 4281b223c9eSAlan Cox } else /* Software */ 429a6ba582dSAlan Cox info->fbops = &psbfb_unaccel_ops; 4304d8d096eSAlan Cox 4314d8d096eSAlan Cox info->fix.smem_start = dev->mode_config.fb_base; 4324d8d096eSAlan Cox info->fix.smem_len = size; 433a6ba582dSAlan Cox info->fix.ywrapstep = gtt_roll; 434a6ba582dSAlan Cox info->fix.ypanstep = 0; 4354d8d096eSAlan Cox 4364d8d096eSAlan Cox /* Accessed stolen memory directly */ 43737214ca0SKirill A. Shutemov info->screen_base = dev_priv->vram_addr + backing->offset; 4384d8d096eSAlan Cox info->screen_size = size; 4394d8d096eSAlan Cox 4404d8d096eSAlan Cox if (dev_priv->gtt.stolen_size) { 4414d8d096eSAlan Cox info->apertures->ranges[0].base = dev->mode_config.fb_base; 4424d8d096eSAlan Cox info->apertures->ranges[0].size = dev_priv->gtt.stolen_size; 4434d8d096eSAlan Cox } 4444d8d096eSAlan Cox 4454d8d096eSAlan Cox drm_fb_helper_fill_var(info, &fbdev->psb_fb_helper, 4464d8d096eSAlan Cox sizes->fb_width, sizes->fb_height); 4474d8d096eSAlan Cox 4484d8d096eSAlan Cox info->fix.mmio_start = pci_resource_start(dev->pdev, 0); 4494d8d096eSAlan Cox info->fix.mmio_len = pci_resource_len(dev->pdev, 0); 4504d8d096eSAlan Cox 451fb2a99e1SSascha Hauer /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */ 4524d8d096eSAlan Cox 45331a0685aSAlan Cox dev_dbg(dev->dev, "allocated %dx%d fb\n", 4544d8d096eSAlan Cox psbfb->base.width, psbfb->base.height); 4554d8d096eSAlan Cox 4564d8d096eSAlan Cox return 0; 4574cd54d98SSudip Mukherjee err_release: 458546187c8SArchit Taneja drm_fb_helper_release_fbi(&fbdev->psb_fb_helper); 4594cd54d98SSudip Mukherjee err_free_range: 4604d8d096eSAlan Cox psb_gtt_free_range(dev, backing); 4614d8d096eSAlan Cox return ret; 4624d8d096eSAlan Cox } 4634d8d096eSAlan Cox 4644d8d096eSAlan Cox /** 4654d8d096eSAlan Cox * psb_user_framebuffer_create - create framebuffer 4664d8d096eSAlan Cox * @dev: our DRM device 4674d8d096eSAlan Cox * @filp: client file 4684d8d096eSAlan Cox * @cmd: mode request 4694d8d096eSAlan Cox * 4704d8d096eSAlan Cox * Create a new framebuffer backed by a userspace GEM object 4714d8d096eSAlan Cox */ 4724d8d096eSAlan Cox static struct drm_framebuffer *psb_user_framebuffer_create 4734d8d096eSAlan Cox (struct drm_device *dev, struct drm_file *filp, 4741eb83451SVille Syrjälä const struct drm_mode_fb_cmd2 *cmd) 4754d8d096eSAlan Cox { 4764d8d096eSAlan Cox struct gtt_range *r; 4774d8d096eSAlan Cox struct drm_gem_object *obj; 4784d8d096eSAlan Cox 4794d8d096eSAlan Cox /* 4804d8d096eSAlan Cox * Find the GEM object and thus the gtt range object that is 4814d8d096eSAlan Cox * to back this space 4824d8d096eSAlan Cox */ 483a8ad0bd8SChris Wilson obj = drm_gem_object_lookup(filp, cmd->handles[0]); 4844d8d096eSAlan Cox if (obj == NULL) 4854d8d096eSAlan Cox return ERR_PTR(-ENOENT); 4864d8d096eSAlan Cox 4874d8d096eSAlan Cox /* Let the core code do all the work */ 4884d8d096eSAlan Cox r = container_of(obj, struct gtt_range, gem); 4894d8d096eSAlan Cox return psb_framebuffer_create(dev, cmd, r); 4904d8d096eSAlan Cox } 4914d8d096eSAlan Cox 4924d8d096eSAlan Cox static void psbfb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, 4934d8d096eSAlan Cox u16 blue, int regno) 4944d8d096eSAlan Cox { 4956306865dSPatrik Jakobsson struct gma_crtc *gma_crtc = to_gma_crtc(crtc); 4963df546beSAlan Cox 4976306865dSPatrik Jakobsson gma_crtc->lut_r[regno] = red >> 8; 4986306865dSPatrik Jakobsson gma_crtc->lut_g[regno] = green >> 8; 4996306865dSPatrik Jakobsson gma_crtc->lut_b[regno] = blue >> 8; 5004d8d096eSAlan Cox } 5014d8d096eSAlan Cox 5024d8d096eSAlan Cox static void psbfb_gamma_get(struct drm_crtc *crtc, u16 *red, 5034d8d096eSAlan Cox u16 *green, u16 *blue, int regno) 5044d8d096eSAlan Cox { 5056306865dSPatrik Jakobsson struct gma_crtc *gma_crtc = to_gma_crtc(crtc); 5063df546beSAlan Cox 5076306865dSPatrik Jakobsson *red = gma_crtc->lut_r[regno] << 8; 5086306865dSPatrik Jakobsson *green = gma_crtc->lut_g[regno] << 8; 5096306865dSPatrik Jakobsson *blue = gma_crtc->lut_b[regno] << 8; 5104d8d096eSAlan Cox } 5114d8d096eSAlan Cox 5124d8d096eSAlan Cox static int psbfb_probe(struct drm_fb_helper *helper, 5134d8d096eSAlan Cox struct drm_fb_helper_surface_size *sizes) 5144d8d096eSAlan Cox { 515c39aa6a1SFabian Frederick struct psb_fbdev *psb_fbdev = 516c39aa6a1SFabian Frederick container_of(helper, struct psb_fbdev, psb_fb_helper); 5173aad16d2SAlan Cox struct drm_device *dev = psb_fbdev->psb_fb_helper.dev; 5183aad16d2SAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 5193aad16d2SAlan Cox int bytespp; 5204d8d096eSAlan Cox 5213aad16d2SAlan Cox bytespp = sizes->surface_bpp / 8; 5223aad16d2SAlan Cox if (bytespp == 3) /* no 24bit packed */ 5233aad16d2SAlan Cox bytespp = 4; 5243aad16d2SAlan Cox 5253aad16d2SAlan Cox /* If the mode will not fit in 32bit then switch to 16bit to get 5263aad16d2SAlan Cox a console on full resolution. The X mode setting server will 5273aad16d2SAlan Cox allocate its own 32bit GEM framebuffer */ 5283aad16d2SAlan Cox if (ALIGN(sizes->fb_width * bytespp, 64) * sizes->fb_height > 5293aad16d2SAlan Cox dev_priv->vram_stolen_size) { 5303aad16d2SAlan Cox sizes->surface_bpp = 16; 5313aad16d2SAlan Cox sizes->surface_depth = 16; 5323aad16d2SAlan Cox } 5333aad16d2SAlan Cox 534cd5428a5SDaniel Vetter return psbfb_create(psb_fbdev, sizes); 5354d8d096eSAlan Cox } 5364d8d096eSAlan Cox 5373a493879SThierry Reding static const struct drm_fb_helper_funcs psb_fb_helper_funcs = { 5384d8d096eSAlan Cox .gamma_set = psbfb_gamma_set, 5394d8d096eSAlan Cox .gamma_get = psbfb_gamma_get, 5404d8d096eSAlan Cox .fb_probe = psbfb_probe, 5414d8d096eSAlan Cox }; 5424d8d096eSAlan Cox 543bc7f2b08SKirill A. Shutemov static int psb_fbdev_destroy(struct drm_device *dev, struct psb_fbdev *fbdev) 5444d8d096eSAlan Cox { 5454d8d096eSAlan Cox struct psb_framebuffer *psbfb = &fbdev->pfb; 5464d8d096eSAlan Cox 547546187c8SArchit Taneja drm_fb_helper_unregister_fbi(&fbdev->psb_fb_helper); 548546187c8SArchit Taneja drm_fb_helper_release_fbi(&fbdev->psb_fb_helper); 549546187c8SArchit Taneja 5504d8d096eSAlan Cox drm_fb_helper_fini(&fbdev->psb_fb_helper); 55136206361SDaniel Vetter drm_framebuffer_unregister_private(&psbfb->base); 5524d8d096eSAlan Cox drm_framebuffer_cleanup(&psbfb->base); 5534d8d096eSAlan Cox 5544d8d096eSAlan Cox if (psbfb->gtt) 55546a0f223SDaniel Vetter drm_gem_object_unreference_unlocked(&psbfb->gtt->gem); 5564d8d096eSAlan Cox return 0; 5574d8d096eSAlan Cox } 5584d8d096eSAlan Cox 5594d8d096eSAlan Cox int psb_fbdev_init(struct drm_device *dev) 5604d8d096eSAlan Cox { 5614d8d096eSAlan Cox struct psb_fbdev *fbdev; 5624d8d096eSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 56301934c2aSThierry Reding int ret; 5644d8d096eSAlan Cox 5654d8d096eSAlan Cox fbdev = kzalloc(sizeof(struct psb_fbdev), GFP_KERNEL); 5664d8d096eSAlan Cox if (!fbdev) { 5674d8d096eSAlan Cox dev_err(dev->dev, "no memory\n"); 5684d8d096eSAlan Cox return -ENOMEM; 5694d8d096eSAlan Cox } 5704d8d096eSAlan Cox 5714d8d096eSAlan Cox dev_priv->fbdev = fbdev; 57210a23102SThierry Reding 57310a23102SThierry Reding drm_fb_helper_prepare(dev, &fbdev->psb_fb_helper, &psb_fb_helper_funcs); 5744d8d096eSAlan Cox 57501934c2aSThierry Reding ret = drm_fb_helper_init(dev, &fbdev->psb_fb_helper, 57601934c2aSThierry Reding dev_priv->ops->crtcs, INTELFB_CONN_LIMIT); 57701934c2aSThierry Reding if (ret) 57801934c2aSThierry Reding goto free; 5794d8d096eSAlan Cox 58001934c2aSThierry Reding ret = drm_fb_helper_single_add_all_connectors(&fbdev->psb_fb_helper); 58101934c2aSThierry Reding if (ret) 58201934c2aSThierry Reding goto fini; 58376a39dbfSDaniel Vetter 58476a39dbfSDaniel Vetter /* disable all the possible outputs/crtcs before entering KMS mode */ 58576a39dbfSDaniel Vetter drm_helper_disable_unused_functions(dev); 58676a39dbfSDaniel Vetter 58701934c2aSThierry Reding ret = drm_fb_helper_initial_config(&fbdev->psb_fb_helper, 32); 58801934c2aSThierry Reding if (ret) 58901934c2aSThierry Reding goto fini; 59001934c2aSThierry Reding 5914d8d096eSAlan Cox return 0; 59201934c2aSThierry Reding 59301934c2aSThierry Reding fini: 59401934c2aSThierry Reding drm_fb_helper_fini(&fbdev->psb_fb_helper); 59501934c2aSThierry Reding free: 59601934c2aSThierry Reding kfree(fbdev); 59701934c2aSThierry Reding return ret; 5984d8d096eSAlan Cox } 5994d8d096eSAlan Cox 600bc7f2b08SKirill A. Shutemov static void psb_fbdev_fini(struct drm_device *dev) 6014d8d096eSAlan Cox { 6024d8d096eSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 6034d8d096eSAlan Cox 6044d8d096eSAlan Cox if (!dev_priv->fbdev) 6054d8d096eSAlan Cox return; 6064d8d096eSAlan Cox 6074d8d096eSAlan Cox psb_fbdev_destroy(dev, dev_priv->fbdev); 6084d8d096eSAlan Cox kfree(dev_priv->fbdev); 6094d8d096eSAlan Cox dev_priv->fbdev = NULL; 6104d8d096eSAlan Cox } 6114d8d096eSAlan Cox 6124d8d096eSAlan Cox static void psbfb_output_poll_changed(struct drm_device *dev) 6134d8d096eSAlan Cox { 6144d8d096eSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 6154d8d096eSAlan Cox struct psb_fbdev *fbdev = (struct psb_fbdev *)dev_priv->fbdev; 6164d8d096eSAlan Cox drm_fb_helper_hotplug_event(&fbdev->psb_fb_helper); 6174d8d096eSAlan Cox } 6184d8d096eSAlan Cox 6194d8d096eSAlan Cox /** 6204d8d096eSAlan Cox * psb_user_framebuffer_create_handle - add hamdle to a framebuffer 6214d8d096eSAlan Cox * @fb: framebuffer 6224d8d096eSAlan Cox * @file_priv: our DRM file 6234d8d096eSAlan Cox * @handle: returned handle 6244d8d096eSAlan Cox * 6254d8d096eSAlan Cox * Our framebuffer object is a GTT range which also contains a GEM 6264d8d096eSAlan Cox * object. We need to turn it into a handle for userspace. GEM will do 6274d8d096eSAlan Cox * the work for us 6284d8d096eSAlan Cox */ 6294d8d096eSAlan Cox static int psb_user_framebuffer_create_handle(struct drm_framebuffer *fb, 6304d8d096eSAlan Cox struct drm_file *file_priv, 6314d8d096eSAlan Cox unsigned int *handle) 6324d8d096eSAlan Cox { 6334d8d096eSAlan Cox struct psb_framebuffer *psbfb = to_psb_fb(fb); 6344d8d096eSAlan Cox struct gtt_range *r = psbfb->gtt; 6354d8d096eSAlan Cox return drm_gem_handle_create(file_priv, &r->gem, handle); 6364d8d096eSAlan Cox } 6374d8d096eSAlan Cox 6384d8d096eSAlan Cox /** 6394d8d096eSAlan Cox * psb_user_framebuffer_destroy - destruct user created fb 6404d8d096eSAlan Cox * @fb: framebuffer 6414d8d096eSAlan Cox * 6424d8d096eSAlan Cox * User framebuffers are backed by GEM objects so all we have to do is 6434d8d096eSAlan Cox * clean up a bit and drop the reference, GEM will handle the fallout 6444d8d096eSAlan Cox */ 6454d8d096eSAlan Cox static void psb_user_framebuffer_destroy(struct drm_framebuffer *fb) 6464d8d096eSAlan Cox { 6474d8d096eSAlan Cox struct psb_framebuffer *psbfb = to_psb_fb(fb); 6484d8d096eSAlan Cox struct gtt_range *r = psbfb->gtt; 6494d8d096eSAlan Cox 6504d8d096eSAlan Cox /* Let DRM do its clean up */ 6514d8d096eSAlan Cox drm_framebuffer_cleanup(fb); 6524d8d096eSAlan Cox /* We are no longer using the resource in GEM */ 6534d8d096eSAlan Cox drm_gem_object_unreference_unlocked(&r->gem); 6544d8d096eSAlan Cox kfree(fb); 6554d8d096eSAlan Cox } 6564d8d096eSAlan Cox 6574d8d096eSAlan Cox static const struct drm_mode_config_funcs psb_mode_funcs = { 6584d8d096eSAlan Cox .fb_create = psb_user_framebuffer_create, 6594d8d096eSAlan Cox .output_poll_changed = psbfb_output_poll_changed, 6604d8d096eSAlan Cox }; 6614d8d096eSAlan Cox 6624d8d096eSAlan Cox static void psb_setup_outputs(struct drm_device *dev) 6634d8d096eSAlan Cox { 6644d8d096eSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 6654d8d096eSAlan Cox struct drm_connector *connector; 6664d8d096eSAlan Cox 6674d8d096eSAlan Cox drm_mode_create_scaling_mode_property(dev); 6684d8d096eSAlan Cox 66913619ce5SAlan Cox /* It is ok for this to fail - we just don't get backlight control */ 67013619ce5SAlan Cox if (!dev_priv->backlight_property) 67113619ce5SAlan Cox dev_priv->backlight_property = drm_property_create_range(dev, 0, 67213619ce5SAlan Cox "backlight", 0, 100); 6734d8d096eSAlan Cox dev_priv->ops->output_init(dev); 6744d8d096eSAlan Cox 6754d8d096eSAlan Cox list_for_each_entry(connector, &dev->mode_config.connector_list, 6764d8d096eSAlan Cox head) { 677367e4408SPatrik Jakobsson struct gma_encoder *gma_encoder = gma_attached_encoder(connector); 678367e4408SPatrik Jakobsson struct drm_encoder *encoder = &gma_encoder->base; 6794d8d096eSAlan Cox int crtc_mask = 0, clone_mask = 0; 6804d8d096eSAlan Cox 6814d8d096eSAlan Cox /* valid crtcs */ 682367e4408SPatrik Jakobsson switch (gma_encoder->type) { 6834d8d096eSAlan Cox case INTEL_OUTPUT_ANALOG: 6844d8d096eSAlan Cox crtc_mask = (1 << 0); 6854d8d096eSAlan Cox clone_mask = (1 << INTEL_OUTPUT_ANALOG); 6864d8d096eSAlan Cox break; 6874d8d096eSAlan Cox case INTEL_OUTPUT_SDVO: 688cf8efd3aSPatrik Jakobsson crtc_mask = dev_priv->ops->sdvo_mask; 6894d8d096eSAlan Cox clone_mask = (1 << INTEL_OUTPUT_SDVO); 6904d8d096eSAlan Cox break; 6914d8d096eSAlan Cox case INTEL_OUTPUT_LVDS: 692d235e64aSAlan Cox crtc_mask = dev_priv->ops->lvds_mask; 6934d8d096eSAlan Cox clone_mask = (1 << INTEL_OUTPUT_LVDS); 6944d8d096eSAlan Cox break; 6954d8d096eSAlan Cox case INTEL_OUTPUT_MIPI: 6964d8d096eSAlan Cox crtc_mask = (1 << 0); 6974d8d096eSAlan Cox clone_mask = (1 << INTEL_OUTPUT_MIPI); 6984d8d096eSAlan Cox break; 6994d8d096eSAlan Cox case INTEL_OUTPUT_MIPI2: 7004d8d096eSAlan Cox crtc_mask = (1 << 2); 7014d8d096eSAlan Cox clone_mask = (1 << INTEL_OUTPUT_MIPI2); 7024d8d096eSAlan Cox break; 7034d8d096eSAlan Cox case INTEL_OUTPUT_HDMI: 704d235e64aSAlan Cox crtc_mask = dev_priv->ops->hdmi_mask; 7054d8d096eSAlan Cox clone_mask = (1 << INTEL_OUTPUT_HDMI); 7064d8d096eSAlan Cox break; 707220801bdSAlan Cox case INTEL_OUTPUT_DISPLAYPORT: 708220801bdSAlan Cox crtc_mask = (1 << 0) | (1 << 1); 709220801bdSAlan Cox clone_mask = (1 << INTEL_OUTPUT_DISPLAYPORT); 710220801bdSAlan Cox break; 711d112a816SZhao Yakui case INTEL_OUTPUT_EDP: 712d112a816SZhao Yakui crtc_mask = (1 << 1); 713d112a816SZhao Yakui clone_mask = (1 << INTEL_OUTPUT_EDP); 7144d8d096eSAlan Cox } 7154d8d096eSAlan Cox encoder->possible_crtcs = crtc_mask; 7164d8d096eSAlan Cox encoder->possible_clones = 717a3d5d75fSPatrik Jakobsson gma_connector_clones(dev, clone_mask); 7184d8d096eSAlan Cox } 7194d8d096eSAlan Cox } 7204d8d096eSAlan Cox 7214d8d096eSAlan Cox void psb_modeset_init(struct drm_device *dev) 7224d8d096eSAlan Cox { 7234d8d096eSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 7244d8d096eSAlan Cox struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; 7254d8d096eSAlan Cox int i; 7264d8d096eSAlan Cox 7274d8d096eSAlan Cox drm_mode_config_init(dev); 7284d8d096eSAlan Cox 7294d8d096eSAlan Cox dev->mode_config.min_width = 0; 7304d8d096eSAlan Cox dev->mode_config.min_height = 0; 7314d8d096eSAlan Cox 732e6ecefaaSLaurent Pinchart dev->mode_config.funcs = &psb_mode_funcs; 7334d8d096eSAlan Cox 7344d8d096eSAlan Cox /* set memory base */ 735dffc9cebSAlan Cox /* Oaktrail and Poulsbo should use BAR 2*/ 7364d8d096eSAlan Cox pci_read_config_dword(dev->pdev, PSB_BSM, (u32 *) 7374d8d096eSAlan Cox &(dev->mode_config.fb_base)); 7384d8d096eSAlan Cox 7394d8d096eSAlan Cox /* num pipes is 2 for PSB but 1 for Mrst */ 7404d8d096eSAlan Cox for (i = 0; i < dev_priv->num_pipe; i++) 7414d8d096eSAlan Cox psb_intel_crtc_init(dev, i, mode_dev); 7424d8d096eSAlan Cox 743cbbd379aSPatrik Jakobsson dev->mode_config.max_width = 4096; 744cbbd379aSPatrik Jakobsson dev->mode_config.max_height = 4096; 7454d8d096eSAlan Cox 7464d8d096eSAlan Cox psb_setup_outputs(dev); 747d235e64aSAlan Cox 748d235e64aSAlan Cox if (dev_priv->ops->errata) 749d235e64aSAlan Cox dev_priv->ops->errata(dev); 7504ab2c7f1SAlan Cox 7514ab2c7f1SAlan Cox dev_priv->modeset = true; 7524d8d096eSAlan Cox } 7534d8d096eSAlan Cox 7544d8d096eSAlan Cox void psb_modeset_cleanup(struct drm_device *dev) 7554d8d096eSAlan Cox { 7564ab2c7f1SAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 7574ab2c7f1SAlan Cox if (dev_priv->modeset) { 7584d8d096eSAlan Cox drm_kms_helper_poll_fini(dev); 7594d8d096eSAlan Cox psb_fbdev_fini(dev); 7604d8d096eSAlan Cox drm_mode_config_cleanup(dev); 7614d8d096eSAlan Cox } 7624ab2c7f1SAlan Cox } 763