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