Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
framebuffer.c
Go to the documentation of this file.
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>
24 #include <linux/mm.h>
25 #include <linux/tty.h>
26 #include <linux/slab.h>
27 #include <linux/delay.h>
28 #include <linux/fb.h>
29 #include <linux/init.h>
30 #include <linux/console.h>
31 
32 #include <drm/drmP.h>
33 #include <drm/drm.h>
34 #include <drm/drm_crtc.h>
35 #include <drm/drm_fb_helper.h>
36 
37 #include "psb_drv.h"
38 #include "psb_intel_reg.h"
39 #include "psb_intel_drv.h"
40 #include "framebuffer.h"
41 #include "gtt.h"
42 
43 static void psb_user_framebuffer_destroy(struct drm_framebuffer *fb);
44 static int psb_user_framebuffer_create_handle(struct drm_framebuffer *fb,
45  struct drm_file *file_priv,
46  unsigned int *handle);
47 
48 static const struct drm_framebuffer_funcs psb_fb_funcs = {
49  .destroy = psb_user_framebuffer_destroy,
50  .create_handle = psb_user_framebuffer_create_handle,
51 };
52 
53 #define CMAP_TOHW(_val, _width) ((((_val) << (_width)) + 0x7FFF - (_val)) >> 16)
54 
55 static int psbfb_setcolreg(unsigned regno, unsigned red, unsigned green,
56  unsigned blue, unsigned transp,
57  struct fb_info *info)
58 {
59  struct psb_fbdev *fbdev = info->par;
60  struct drm_framebuffer *fb = fbdev->psb_fb_helper.fb;
61  uint32_t v;
62 
63  if (!fb)
64  return -ENOMEM;
65 
66  if (regno > 255)
67  return 1;
68 
69  red = CMAP_TOHW(red, info->var.red.length);
70  blue = CMAP_TOHW(blue, info->var.blue.length);
71  green = CMAP_TOHW(green, info->var.green.length);
72  transp = CMAP_TOHW(transp, info->var.transp.length);
73 
74  v = (red << info->var.red.offset) |
75  (green << info->var.green.offset) |
76  (blue << info->var.blue.offset) |
77  (transp << info->var.transp.offset);
78 
79  if (regno < 16) {
80  switch (fb->bits_per_pixel) {
81  case 16:
82  ((uint32_t *) info->pseudo_palette)[regno] = v;
83  break;
84  case 24:
85  case 32:
86  ((uint32_t *) info->pseudo_palette)[regno] = v;
87  break;
88  }
89  }
90 
91  return 0;
92 }
93 
94 static int psbfb_pan(struct fb_var_screeninfo *var, struct fb_info *info)
95 {
96  struct psb_fbdev *fbdev = info->par;
97  struct psb_framebuffer *psbfb = &fbdev->pfb;
98  struct drm_device *dev = psbfb->base.dev;
99 
100  /*
101  * We have to poke our nose in here. The core fb code assumes
102  * panning is part of the hardware that can be invoked before
103  * the actual fb is mapped. In our case that isn't quite true.
104  */
105  if (psbfb->gtt->npage) {
106  /* GTT roll shifts in 4K pages, we need to shift the right
107  number of pages */
108  int pages = info->fix.line_length >> 12;
109  psb_gtt_roll(dev, psbfb->gtt, var->yoffset * pages);
110  }
111  return 0;
112 }
113 
114 static int psbfb_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
115 {
116  struct psb_framebuffer *psbfb = vma->vm_private_data;
117  struct drm_device *dev = psbfb->base.dev;
118  struct drm_psb_private *dev_priv = dev->dev_private;
119  int page_num;
120  int i;
121  unsigned long address;
122  int ret;
123  unsigned long pfn;
124  /* FIXME: assumes fb at stolen base which may not be true */
125  unsigned long phys_addr = (unsigned long)dev_priv->stolen_base;
126 
127  page_num = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
128  address = (unsigned long)vmf->virtual_address - (vmf->pgoff << PAGE_SHIFT);
129 
131 
132  for (i = 0; i < page_num; i++) {
133  pfn = (phys_addr >> PAGE_SHIFT);
134 
135  ret = vm_insert_mixed(vma, address, pfn);
136  if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0)))
137  break;
138  else if (unlikely(ret != 0)) {
139  ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
140  return ret;
141  }
142  address += PAGE_SIZE;
143  phys_addr += PAGE_SIZE;
144  }
145  return VM_FAULT_NOPAGE;
146 }
147 
148 static void psbfb_vm_open(struct vm_area_struct *vma)
149 {
150 }
151 
152 static void psbfb_vm_close(struct vm_area_struct *vma)
153 {
154 }
155 
156 static const struct vm_operations_struct psbfb_vm_ops = {
157  .fault = psbfb_vm_fault,
158  .open = psbfb_vm_open,
159  .close = psbfb_vm_close
160 };
161 
162 static int psbfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
163 {
164  struct psb_fbdev *fbdev = info->par;
165  struct psb_framebuffer *psbfb = &fbdev->pfb;
166 
167  if (vma->vm_pgoff != 0)
168  return -EINVAL;
169  if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
170  return -EINVAL;
171 
172  if (!psbfb->addr_space)
173  psbfb->addr_space = vma->vm_file->f_mapping;
174  /*
175  * If this is a GEM object then info->screen_base is the virtual
176  * kernel remapping of the object. FIXME: Review if this is
177  * suitable for our mmap work
178  */
179  vma->vm_ops = &psbfb_vm_ops;
180  vma->vm_private_data = (void *)psbfb;
181  vma->vm_flags |= VM_IO | VM_MIXEDMAP | VM_DONTEXPAND | VM_DONTDUMP;
182  return 0;
183 }
184 
185 static int psbfb_ioctl(struct fb_info *info, unsigned int cmd,
186  unsigned long arg)
187 {
188  return -ENOTTY;
189 }
190 
191 static struct fb_ops psbfb_ops = {
192  .owner = THIS_MODULE,
193  .fb_check_var = drm_fb_helper_check_var,
194  .fb_set_par = drm_fb_helper_set_par,
195  .fb_blank = drm_fb_helper_blank,
196  .fb_setcolreg = psbfb_setcolreg,
197  .fb_fillrect = cfb_fillrect,
198  .fb_copyarea = psbfb_copyarea,
199  .fb_imageblit = cfb_imageblit,
200  .fb_mmap = psbfb_mmap,
201  .fb_sync = psbfb_sync,
202  .fb_ioctl = psbfb_ioctl,
203 };
204 
205 static struct fb_ops psbfb_roll_ops = {
206  .owner = THIS_MODULE,
207  .fb_check_var = drm_fb_helper_check_var,
208  .fb_set_par = drm_fb_helper_set_par,
209  .fb_blank = drm_fb_helper_blank,
210  .fb_setcolreg = psbfb_setcolreg,
211  .fb_fillrect = cfb_fillrect,
212  .fb_copyarea = cfb_copyarea,
213  .fb_imageblit = cfb_imageblit,
214  .fb_pan_display = psbfb_pan,
215  .fb_mmap = psbfb_mmap,
216  .fb_ioctl = psbfb_ioctl,
217 };
218 
219 static struct fb_ops psbfb_unaccel_ops = {
220  .owner = THIS_MODULE,
221  .fb_check_var = drm_fb_helper_check_var,
222  .fb_set_par = drm_fb_helper_set_par,
223  .fb_blank = drm_fb_helper_blank,
224  .fb_setcolreg = psbfb_setcolreg,
225  .fb_fillrect = cfb_fillrect,
226  .fb_copyarea = cfb_copyarea,
227  .fb_imageblit = cfb_imageblit,
228  .fb_mmap = psbfb_mmap,
229  .fb_ioctl = psbfb_ioctl,
230 };
231 
242 static int psb_framebuffer_init(struct drm_device *dev,
243  struct psb_framebuffer *fb,
244  struct drm_mode_fb_cmd2 *mode_cmd,
245  struct gtt_range *gt)
246 {
247  u32 bpp, depth;
248  int ret;
249 
250  drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
251 
252  if (mode_cmd->pitches[0] & 63)
253  return -EINVAL;
254  switch (bpp) {
255  case 8:
256  case 16:
257  case 24:
258  case 32:
259  break;
260  default:
261  return -EINVAL;
262  }
263  ret = drm_framebuffer_init(dev, &fb->base, &psb_fb_funcs);
264  if (ret) {
265  dev_err(dev->dev, "framebuffer init failed: %d\n", ret);
266  return ret;
267  }
268  drm_helper_mode_fill_fb_struct(&fb->base, mode_cmd);
269  fb->gtt = gt;
270  return 0;
271 }
272 
285 static struct drm_framebuffer *psb_framebuffer_create
286  (struct drm_device *dev,
287  struct drm_mode_fb_cmd2 *mode_cmd,
288  struct gtt_range *gt)
289 {
290  struct psb_framebuffer *fb;
291  int ret;
292 
293  fb = kzalloc(sizeof(*fb), GFP_KERNEL);
294  if (!fb)
295  return ERR_PTR(-ENOMEM);
296 
297  ret = psb_framebuffer_init(dev, fb, mode_cmd, gt);
298  if (ret) {
299  kfree(fb);
300  return ERR_PTR(ret);
301  }
302  return &fb->base;
303 }
304 
318 static struct gtt_range *psbfb_alloc(struct drm_device *dev, int aligned_size)
319 {
320  struct gtt_range *backing;
321  /* Begin by trying to use stolen memory backing */
322  backing = psb_gtt_alloc_range(dev, aligned_size, "fb", 1);
323  if (backing) {
325  &backing->gem, aligned_size) == 0)
326  return backing;
327  psb_gtt_free_range(dev, backing);
328  }
329  return NULL;
330 }
331 
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;
347  struct drm_mode_fb_cmd2 mode_cmd;
348  struct device *device = &dev->pdev->dev;
349  int size;
350  int ret;
351  struct gtt_range *backing;
352  u32 bpp, depth;
353  int gtt_roll = 0;
354  int pitch_lines = 0;
355 
356  mode_cmd.width = sizes->surface_width;
357  mode_cmd.height = sizes->surface_height;
358  bpp = sizes->surface_bpp;
359  depth = sizes->surface_depth;
360 
361  /* No 24bit packed */
362  if (bpp == 24)
363  bpp = 32;
364 
365  do {
366  /*
367  * Acceleration via the GTT requires pitch to be
368  * power of two aligned. Preferably page but less
369  * is ok with some fonts
370  */
371  mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((bpp + 7) / 8), 4096 >> pitch_lines);
372 
373  size = mode_cmd.pitches[0] * mode_cmd.height;
374  size = ALIGN(size, PAGE_SIZE);
375 
376  /* Allocate the fb in the GTT with stolen page backing */
377  backing = psbfb_alloc(dev, size);
378 
379  if (pitch_lines)
380  pitch_lines *= 2;
381  else
382  pitch_lines = 1;
383  gtt_roll++;
384  } while (backing == NULL && pitch_lines <= 16);
385 
386  /* The final pitch we accepted if we succeeded */
387  pitch_lines /= 2;
388 
389  if (backing == NULL) {
390  /*
391  * We couldn't get the space we wanted, fall back to the
392  * display engine requirement instead. The HW requires
393  * the pitch to be 64 byte aligned
394  */
395 
396  gtt_roll = 0; /* Don't use GTT accelerated scrolling */
397  pitch_lines = 64;
398 
399  mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((bpp + 7) / 8), 64);
400 
401  size = mode_cmd.pitches[0] * mode_cmd.height;
402  size = ALIGN(size, PAGE_SIZE);
403 
404  /* Allocate the framebuffer in the GTT with stolen page backing */
405  backing = psbfb_alloc(dev, size);
406  if (backing == NULL)
407  return -ENOMEM;
408  }
409 
410  memset(dev_priv->vram_addr + backing->offset, 0, size);
411 
412  mutex_lock(&dev->struct_mutex);
413 
414  info = framebuffer_alloc(0, device);
415  if (!info) {
416  ret = -ENOMEM;
417  goto out_err1;
418  }
419  info->par = fbdev;
420 
421  mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
422 
423  ret = psb_framebuffer_init(dev, psbfb, &mode_cmd, backing);
424  if (ret)
425  goto out_unref;
426 
427  fb = &psbfb->base;
428  psbfb->fbdev = info;
429 
430  fbdev->psb_fb_helper.fb = fb;
431  fbdev->psb_fb_helper.fbdev = info;
432 
433  drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
434  strcpy(info->fix.id, "psbfb");
435 
436  info->flags = FBINFO_DEFAULT;
437  if (dev_priv->ops->accel_2d && pitch_lines > 8) /* 2D engine */
438  info->fbops = &psbfb_ops;
439  else if (gtt_roll) { /* GTT rolling seems best */
440  info->fbops = &psbfb_roll_ops;
441  info->flags |= FBINFO_HWACCEL_YPAN;
442  } else /* Software */
443  info->fbops = &psbfb_unaccel_ops;
444 
445  ret = fb_alloc_cmap(&info->cmap, 256, 0);
446  if (ret) {
447  ret = -ENOMEM;
448  goto out_unref;
449  }
450 
451  info->fix.smem_start = dev->mode_config.fb_base;
452  info->fix.smem_len = size;
453  info->fix.ywrapstep = gtt_roll;
454  info->fix.ypanstep = 0;
455 
456  /* Accessed stolen memory directly */
457  info->screen_base = dev_priv->vram_addr + backing->offset;
458  info->screen_size = size;
459 
460  if (dev_priv->gtt.stolen_size) {
461  info->apertures = alloc_apertures(1);
462  if (!info->apertures) {
463  ret = -ENOMEM;
464  goto out_unref;
465  }
466  info->apertures->ranges[0].base = dev->mode_config.fb_base;
467  info->apertures->ranges[0].size = dev_priv->gtt.stolen_size;
468  }
469 
471  sizes->fb_width, sizes->fb_height);
472 
473  info->fix.mmio_start = pci_resource_start(dev->pdev, 0);
474  info->fix.mmio_len = pci_resource_len(dev->pdev, 0);
475 
476  /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
477 
478  dev_dbg(dev->dev, "allocated %dx%d fb\n",
479  psbfb->base.width, psbfb->base.height);
480 
481  mutex_unlock(&dev->struct_mutex);
482  return 0;
483 out_unref:
484  if (backing->stolen)
485  psb_gtt_free_range(dev, backing);
486  else
487  drm_gem_object_unreference(&backing->gem);
488 out_err1:
489  mutex_unlock(&dev->struct_mutex);
490  psb_gtt_free_range(dev, backing);
491  return ret;
492 }
493 
502 static struct drm_framebuffer *psb_user_framebuffer_create
503  (struct drm_device *dev, struct drm_file *filp,
504  struct drm_mode_fb_cmd2 *cmd)
505 {
506  struct gtt_range *r;
507  struct drm_gem_object *obj;
508 
509  /*
510  * Find the GEM object and thus the gtt range object that is
511  * to back this space
512  */
513  obj = drm_gem_object_lookup(dev, filp, cmd->handles[0]);
514  if (obj == NULL)
515  return ERR_PTR(-ENOENT);
516 
517  /* Let the core code do all the work */
518  r = container_of(obj, struct gtt_range, gem);
519  return psb_framebuffer_create(dev, cmd, r);
520 }
521 
522 static void psbfb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
523  u16 blue, int regno)
524 {
526 
527  intel_crtc->lut_r[regno] = red >> 8;
528  intel_crtc->lut_g[regno] = green >> 8;
529  intel_crtc->lut_b[regno] = blue >> 8;
530 }
531 
532 static void psbfb_gamma_get(struct drm_crtc *crtc, u16 *red,
533  u16 *green, u16 *blue, int regno)
534 {
536 
537  *red = intel_crtc->lut_r[regno] << 8;
538  *green = intel_crtc->lut_g[regno] << 8;
539  *blue = intel_crtc->lut_b[regno] << 8;
540 }
541 
542 static int psbfb_probe(struct drm_fb_helper *helper,
543  struct drm_fb_helper_surface_size *sizes)
544 {
545  struct psb_fbdev *psb_fbdev = (struct psb_fbdev *)helper;
546  struct drm_device *dev = psb_fbdev->psb_fb_helper.dev;
547  struct drm_psb_private *dev_priv = dev->dev_private;
548  int new_fb = 0;
549  int bytespp;
550  int ret;
551 
552  bytespp = sizes->surface_bpp / 8;
553  if (bytespp == 3) /* no 24bit packed */
554  bytespp = 4;
555 
556  /* If the mode will not fit in 32bit then switch to 16bit to get
557  a console on full resolution. The X mode setting server will
558  allocate its own 32bit GEM framebuffer */
559  if (ALIGN(sizes->fb_width * bytespp, 64) * sizes->fb_height >
560  dev_priv->vram_stolen_size) {
561  sizes->surface_bpp = 16;
562  sizes->surface_depth = 16;
563  }
564 
565  if (!helper->fb) {
566  ret = psbfb_create(psb_fbdev, sizes);
567  if (ret)
568  return ret;
569  new_fb = 1;
570  }
571  return new_fb;
572 }
573 
574 static struct drm_fb_helper_funcs psb_fb_helper_funcs = {
575  .gamma_set = psbfb_gamma_set,
576  .gamma_get = psbfb_gamma_get,
577  .fb_probe = psbfb_probe,
578 };
579 
580 static int psb_fbdev_destroy(struct drm_device *dev, struct psb_fbdev *fbdev)
581 {
582  struct fb_info *info;
583  struct psb_framebuffer *psbfb = &fbdev->pfb;
584 
585  if (fbdev->psb_fb_helper.fbdev) {
586  info = fbdev->psb_fb_helper.fbdev;
588  if (info->cmap.len)
589  fb_dealloc_cmap(&info->cmap);
590  framebuffer_release(info);
591  }
593  drm_framebuffer_cleanup(&psbfb->base);
594 
595  if (psbfb->gtt)
596  drm_gem_object_unreference(&psbfb->gtt->gem);
597  return 0;
598 }
599 
600 int psb_fbdev_init(struct drm_device *dev)
601 {
602  struct psb_fbdev *fbdev;
603  struct drm_psb_private *dev_priv = dev->dev_private;
604 
605  fbdev = kzalloc(sizeof(struct psb_fbdev), GFP_KERNEL);
606  if (!fbdev) {
607  dev_err(dev->dev, "no memory\n");
608  return -ENOMEM;
609  }
610 
611  dev_priv->fbdev = fbdev;
612  fbdev->psb_fb_helper.funcs = &psb_fb_helper_funcs;
613 
614  drm_fb_helper_init(dev, &fbdev->psb_fb_helper, dev_priv->ops->crtcs,
616 
619  return 0;
620 }
621 
622 static void psb_fbdev_fini(struct drm_device *dev)
623 {
624  struct drm_psb_private *dev_priv = dev->dev_private;
625 
626  if (!dev_priv->fbdev)
627  return;
628 
629  psb_fbdev_destroy(dev, dev_priv->fbdev);
630  kfree(dev_priv->fbdev);
631  dev_priv->fbdev = NULL;
632 }
633 
634 static void psbfb_output_poll_changed(struct drm_device *dev)
635 {
636  struct drm_psb_private *dev_priv = dev->dev_private;
637  struct psb_fbdev *fbdev = (struct psb_fbdev *)dev_priv->fbdev;
639 }
640 
651 static int psb_user_framebuffer_create_handle(struct drm_framebuffer *fb,
652  struct drm_file *file_priv,
653  unsigned int *handle)
654 {
655  struct psb_framebuffer *psbfb = to_psb_fb(fb);
656  struct gtt_range *r = psbfb->gtt;
657  return drm_gem_handle_create(file_priv, &r->gem, handle);
658 }
659 
667 static void psb_user_framebuffer_destroy(struct drm_framebuffer *fb)
668 {
669  struct psb_framebuffer *psbfb = to_psb_fb(fb);
670  struct gtt_range *r = psbfb->gtt;
671  struct drm_device *dev = fb->dev;
672  struct drm_psb_private *dev_priv = dev->dev_private;
673  struct psb_fbdev *fbdev = dev_priv->fbdev;
674  struct drm_crtc *crtc;
675  int reset = 0;
676 
677  /* Should never get stolen memory for a user fb */
678  WARN_ON(r->stolen);
679 
680  /* Check if we are erroneously live */
681  list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
682  if (crtc->fb == fb)
683  reset = 1;
684 
685  if (reset)
686  /*
687  * Now force a sane response before we permit the DRM CRTC
688  * layer to do stupid things like blank the display. Instead
689  * we reset this framebuffer as if the user had forced a reset.
690  * We must do this before the cleanup so that the DRM layer
691  * doesn't get a chance to stick its oar in where it isn't
692  * wanted.
693  */
694  drm_fb_helper_restore_fbdev_mode(&fbdev->psb_fb_helper);
695 
696  /* Let DRM do its clean up */
698  /* We are no longer using the resource in GEM */
699  drm_gem_object_unreference_unlocked(&r->gem);
700  kfree(fb);
701 }
702 
703 static const struct drm_mode_config_funcs psb_mode_funcs = {
704  .fb_create = psb_user_framebuffer_create,
705  .output_poll_changed = psbfb_output_poll_changed,
706 };
707 
708 static int psb_create_backlight_property(struct drm_device *dev)
709 {
710  struct drm_psb_private *dev_priv = dev->dev_private;
711  struct drm_property *backlight;
712 
713  if (dev_priv->backlight_property)
714  return 0;
715 
716  backlight = drm_property_create_range(dev, 0, "backlight", 0, 100);
717 
718  dev_priv->backlight_property = backlight;
719 
720  return 0;
721 }
722 
723 static void psb_setup_outputs(struct drm_device *dev)
724 {
725  struct drm_psb_private *dev_priv = dev->dev_private;
726  struct drm_connector *connector;
727 
729  psb_create_backlight_property(dev);
730 
731  dev_priv->ops->output_init(dev);
732 
733  list_for_each_entry(connector, &dev->mode_config.connector_list,
734  head) {
736  psb_intel_attached_encoder(connector);
737  struct drm_encoder *encoder = &psb_intel_encoder->base;
738  int crtc_mask = 0, clone_mask = 0;
739 
740  /* valid crtcs */
741  switch (psb_intel_encoder->type) {
742  case INTEL_OUTPUT_ANALOG:
743  crtc_mask = (1 << 0);
744  clone_mask = (1 << INTEL_OUTPUT_ANALOG);
745  break;
746  case INTEL_OUTPUT_SDVO:
747  crtc_mask = ((1 << 0) | (1 << 1));
748  clone_mask = (1 << INTEL_OUTPUT_SDVO);
749  break;
750  case INTEL_OUTPUT_LVDS:
751  crtc_mask = dev_priv->ops->lvds_mask;
752  clone_mask = (1 << INTEL_OUTPUT_LVDS);
753  break;
754  case INTEL_OUTPUT_MIPI:
755  crtc_mask = (1 << 0);
756  clone_mask = (1 << INTEL_OUTPUT_MIPI);
757  break;
758  case INTEL_OUTPUT_MIPI2:
759  crtc_mask = (1 << 2);
760  clone_mask = (1 << INTEL_OUTPUT_MIPI2);
761  break;
762  case INTEL_OUTPUT_HDMI:
763  crtc_mask = dev_priv->ops->hdmi_mask;
764  clone_mask = (1 << INTEL_OUTPUT_HDMI);
765  break;
767  crtc_mask = (1 << 0) | (1 << 1);
768  clone_mask = (1 << INTEL_OUTPUT_DISPLAYPORT);
769  break;
770  case INTEL_OUTPUT_EDP:
771  crtc_mask = (1 << 1);
772  clone_mask = (1 << INTEL_OUTPUT_EDP);
773  }
774  encoder->possible_crtcs = crtc_mask;
775  encoder->possible_clones =
776  psb_intel_connector_clones(dev, clone_mask);
777  }
778 }
779 
780 void psb_modeset_init(struct drm_device *dev)
781 {
782  struct drm_psb_private *dev_priv = dev->dev_private;
783  struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
784  int i;
785 
787 
788  dev->mode_config.min_width = 0;
789  dev->mode_config.min_height = 0;
790 
791  dev->mode_config.funcs = &psb_mode_funcs;
792 
793  /* set memory base */
794  /* Oaktrail and Poulsbo should use BAR 2*/
795  pci_read_config_dword(dev->pdev, PSB_BSM, (u32 *)
796  &(dev->mode_config.fb_base));
797 
798  /* num pipes is 2 for PSB but 1 for Mrst */
799  for (i = 0; i < dev_priv->num_pipe; i++)
800  psb_intel_crtc_init(dev, i, mode_dev);
801 
802  dev->mode_config.max_width = 2048;
803  dev->mode_config.max_height = 2048;
804 
805  psb_setup_outputs(dev);
806 
807  if (dev_priv->ops->errata)
808  dev_priv->ops->errata(dev);
809 
810  dev_priv->modeset = true;
811 }
812 
814 {
815  struct drm_psb_private *dev_priv = dev->dev_private;
816  if (dev_priv->modeset) {
817  mutex_lock(&dev->struct_mutex);
818 
820  psb_fbdev_fini(dev);
822 
823  mutex_unlock(&dev->struct_mutex);
824  }
825 }