Super User's BSD Cross Reference: /OpenBSD/sys/dev/pci/drm/i915/display/intel_fbdev.c

1 /*
2 * Copyright �� 2007 David Airlie
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * David Airlie
25 */
26
27#include <linux/console.h>
28#include <linux/delay.h>
29#include <linux/errno.h>
30#include <linux/fb.h>
31#include <linux/init.h>
32#include <linux/kernel.h>
33#include <linux/mm.h>
34#include <linux/module.h>
35#include <linux/string.h>
36#include <linux/sysrq.h>
37#include <linux/tty.h>
38#include <linux/vga_switcheroo.h>
39
40#include <drm/drm_crtc.h>
41#include <drm/drm_crtc_helper.h>
42#include <drm/drm_fb_helper.h>
43#include <drm/drm_fourcc.h>
44#include <drm/drm_gem_framebuffer_helper.h>
45
46#include "gem/i915_gem_mman.h"
47#include "gem/i915_gem_object.h"
48
49#include "i915_drv.h"
50#include "intel_display_types.h"
51#include "intel_fb.h"
52#include "intel_fb_pin.h"
53#include "intel_fbdev.h"
54#include "intel_fbdev_fb.h"
55#include "intel_frontbuffer.h"
56
57 struct intel_fbdev {
58 struct drm_fb_helper helper;
59 struct intel_framebuffer *fb;
60 struct i915_vma *vma;
61 unsigned long vma_flags;
62 int preferred_bpp;
63
64 /* Whether or not fbdev hpd processing is temporarily suspended */
65 bool hpd_suspended: 1;
66 /* Set when a hotplug was received while HPD processing was suspended */
67 bool hpd_waiting: 1;
68
69 /* Protects hpd_suspended */
70 struct rwlock hpd_lock;
71};
72
73 static struct intel_fbdev *to_intel_fbdev(struct drm_fb_helper *fb_helper)
74{
75 return container_of(fb_helper, struct intel_fbdev, helper);
76}
77
78 static struct intel_frontbuffer *to_frontbuffer(struct intel_fbdev *ifbdev)
79{
80 return ifbdev->fb->frontbuffer;
81}
82
83 static void intel_fbdev_invalidate(struct intel_fbdev *ifbdev)
84{
85 intel_frontbuffer_invalidate(to_frontbuffer(ifbdev), ORIGIN_CPU);
86}
87
88 FB_GEN_DEFAULT_DEFERRED_IOMEM_OPS(intel_fbdev,
89 drm_fb_helper_damage_range,
90 drm_fb_helper_damage_area)
91
92 static int intel_fbdev_set_par(struct fb_info *info)
93{
94 struct intel_fbdev *ifbdev = to_intel_fbdev(info->par);
95 int ret;
96
97 ret = drm_fb_helper_set_par(info);
98 if (ret == 0)
99 intel_fbdev_invalidate(ifbdev);
100
101 return ret;
102}
103
104 static int intel_fbdev_blank(int blank, struct fb_info *info)
105{
106 struct intel_fbdev *ifbdev = to_intel_fbdev(info->par);
107 int ret;
108
109 ret = drm_fb_helper_blank(blank, info);
110 if (ret == 0)
111 intel_fbdev_invalidate(ifbdev);
112
113 return ret;
114}
115
116 static int intel_fbdev_pan_display(struct fb_var_screeninfo *var,
117 struct fb_info *info)
118{
119 struct intel_fbdev *ifbdev = to_intel_fbdev(info->par);
120 int ret;
121
122 ret = drm_fb_helper_pan_display(var, info);
123 if (ret == 0)
124 intel_fbdev_invalidate(ifbdev);
125
126 return ret;
127}
128
129#ifdef notyet
130 static int intel_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma)
131{
132 struct intel_fbdev *fbdev = to_intel_fbdev(info->par);
133 struct drm_gem_object *bo = drm_gem_fb_get_obj(&fbdev->fb->base, 0);
134 struct drm_i915_gem_object *obj = to_intel_bo(bo);
135
136 return i915_gem_fb_mmap(obj, vma);
137}
138
139 static void intel_fbdev_fb_destroy(struct fb_info *info)
140{
141 struct drm_fb_helper *fb_helper = info->par;
142 struct intel_fbdev *ifbdev = container_of(fb_helper, struct intel_fbdev, helper);
143
144 drm_fb_helper_fini(&ifbdev->helper);
145
146 /*
147 * We rely on the object-free to release the VMA pinning for
148 * the info->screen_base mmaping. Leaking the VMA is simpler than
149 * trying to rectify all the possible error paths leading here.
150 */
151 intel_fb_unpin_vma(ifbdev->vma, ifbdev->vma_flags);
152 drm_framebuffer_remove(&ifbdev->fb->base);
153
154 drm_client_release(&fb_helper->client);
155 drm_fb_helper_unprepare(&ifbdev->helper);
156 kfree(ifbdev);
157}
158
159 __diag_push();
160 __diag_ignore_all("-Woverride-init", "Allow field initialization overrides for fb ops");
161
162#endif /* notyet */
163
164 static const struct fb_ops intelfb_ops = {
165#ifdef notyet
166 .owner = THIS_MODULE,
167 __FB_DEFAULT_DEFERRED_OPS_RDWR(intel_fbdev),
168 DRM_FB_HELPER_DEFAULT_OPS,
169#endif
170 .fb_set_par = intel_fbdev_set_par,
171#ifdef notyet
172 .fb_blank = intel_fbdev_blank,
173 .fb_pan_display = intel_fbdev_pan_display,
174 __FB_DEFAULT_DEFERRED_OPS_DRAW(intel_fbdev),
175 .fb_mmap = intel_fbdev_mmap,
176 .fb_destroy = intel_fbdev_fb_destroy,
177#endif
178};
179
180 __diag_pop();
181
182 static int intelfb_create(struct drm_fb_helper *helper,
183 struct drm_fb_helper_surface_size *sizes)
184{
185 struct intel_fbdev *ifbdev = to_intel_fbdev(helper);
186 struct intel_framebuffer *fb = ifbdev->fb;
187 struct drm_device *dev = helper->dev;
188 struct drm_i915_private *dev_priv = to_i915(dev);
189 const struct i915_gtt_view view = {
190 .type = I915_GTT_VIEW_NORMAL,
191 };
192 intel_wakeref_t wakeref;
193 struct fb_info *info;
194 struct i915_vma *vma;
195 unsigned long flags = 0;
196 bool prealloc = false;
197 struct drm_i915_gem_object *obj;
198 int ret;
199
200 mutex_lock(&ifbdev->hpd_lock);
201 ret = ifbdev->hpd_suspended ? -EAGAIN : 0;
202 mutex_unlock(&ifbdev->hpd_lock);
203 if (ret)
204 return ret;
205
206 ifbdev->fb = NULL;
207
208 if (fb &&
209 (sizes->fb_width > fb->base.width ||
210 sizes->fb_height > fb->base.height)) {
211 drm_dbg_kms(&dev_priv->drm,
212 "BIOS fb too small (%dx%d), we require (%dx%d),"
213 " releasing it\n",
214 fb->base.width, fb->base.height,
215 sizes->fb_width, sizes->fb_height);
216 drm_framebuffer_put(&fb->base);
217 fb = NULL;
218 }
219 if (!fb || drm_WARN_ON(dev, !intel_fb_obj(&fb->base))) {
220 drm_dbg_kms(&dev_priv->drm,
221 "no BIOS fb, allocating a new one\n");
222 fb = intel_fbdev_fb_alloc(helper, sizes);
223 if (IS_ERR(fb))
224 return PTR_ERR(fb);
225 } else {
226 drm_dbg_kms(&dev_priv->drm, "re-using BIOS fb\n");
227 prealloc = true;
228 sizes->fb_width = fb->base.width;
229 sizes->fb_height = fb->base.height;
230 }
231
232 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
233
234 /* Pin the GGTT vma for our access via info->screen_base.
235 * This also validates that any existing fb inherited from the
236 * BIOS is suitable for own access.
237 */
238 vma = intel_fb_pin_to_ggtt(&fb->base, &view,
239 fb->min_alignment, 0,
240 false, &flags);
241 if (IS_ERR(vma)) {
242 ret = PTR_ERR(vma);
243 goto out_unlock;
244 }
245
246 info = drm_fb_helper_alloc_info(helper);
247 if (IS_ERR(info)) {
248 drm_err(&dev_priv->drm, "Failed to allocate fb_info (%pe)\n", info);
249 ret = PTR_ERR(info);
250 goto out_unpin;
251 }
252
253 ifbdev->helper.fb = &fb->base;
254
255 info->fbops = &intelfb_ops;
256
257 obj = intel_fb_obj(&fb->base);
258
259 ret = intel_fbdev_fb_fill_info(dev_priv, info, obj, vma);
260 if (ret)
261 goto out_unpin;
262
263 drm_fb_helper_fill_info(info, &ifbdev->helper, sizes);
264
265 /* If the object is shmemfs backed, it will have given us zeroed pages.
266 * If the object is stolen however, it will be full of whatever
267 * garbage was left in there.
268 */
269 if (!i915_gem_object_is_shmem(obj) && !prealloc)
270 memset_io(info->screen_base, 0, info->screen_size);
271
272 /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
273
274 drm_dbg_kms(&dev_priv->drm, "allocated %dx%d fb: 0x%08x\n",
275 fb->base.width, fb->base.height,
276 i915_ggtt_offset(vma));
277 ifbdev->fb = fb;
278 ifbdev->vma = vma;
279 ifbdev->vma_flags = flags;
280
281 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
282{
283 struct drm_framebuffer *fb = ifbdev->helper.fb;
284 struct rasops_info *ri = &dev_priv->ro;
285
286 ri->ri_bits = info->screen_base;
287 ri->ri_depth = fb->format->cpp[0] * 8;
288 ri->ri_stride = fb->pitches[0];
289 ri->ri_width = sizes->fb_width;
290 ri->ri_height = sizes->fb_height;
291
292 switch (fb->format->format) {
293 case DRM_FORMAT_XRGB8888:
294 ri->ri_rnum = 8;
295 ri->ri_rpos = 16;
296 ri->ri_gnum = 8;
297 ri->ri_gpos = 8;
298 ri->ri_bnum = 8;
299 ri->ri_bpos = 0;
300 break;
301 case DRM_FORMAT_RGB565:
302 ri->ri_rnum = 5;
303 ri->ri_rpos = 11;
304 ri->ri_gnum = 6;
305 ri->ri_gpos = 5;
306 ri->ri_bnum = 5;
307 ri->ri_bpos = 0;
308 break;
309 }
310 intel_fbdev_invalidate(ifbdev);
311}
312 return 0;
313
314 out_unpin:
315 intel_fb_unpin_vma(vma, flags);
316 out_unlock:
317 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
318 return ret;
319}
320
321 static int intelfb_dirty(struct drm_fb_helper *helper, struct drm_clip_rect *clip)
322{
323 if (!(clip->x1 < clip->x2 && clip->y1 < clip->y2))
324 return 0;
325
326 if (helper->fb->funcs->dirty)
327 return helper->fb->funcs->dirty(helper->fb, NULL, 0, 0, clip, 1);
328
329 return 0;
330}
331
332 static const struct drm_fb_helper_funcs intel_fb_helper_funcs = {
333 .fb_probe = intelfb_create,
334 .fb_dirty = intelfb_dirty,
335};
336
337 /*
338 * Build an intel_fbdev struct using a BIOS allocated framebuffer, if possible.
339 * The core display code will have read out the current plane configuration,
340 * so we use that to figure out if there's an object for us to use as the
341 * fb, and if so, we re-use it for the fbdev configuration.
342 *
343 * Note we only support a single fb shared across pipes for boot (mostly for
344 * fbcon), so we just find the biggest and use that.
345 */
346 static bool intel_fbdev_init_bios(struct drm_device *dev,
347 struct intel_fbdev *ifbdev)
348{
349 struct drm_i915_private *i915 = to_i915(dev);
350 struct intel_framebuffer *fb = NULL;
351 struct intel_crtc *crtc;
352 unsigned int max_size = 0;
353
354 /* Find the largest fb */
355 for_each_intel_crtc(dev, crtc) {
356 struct intel_crtc_state *crtc_state =
357 to_intel_crtc_state(crtc->base.state);
358 struct intel_plane *plane =
359 to_intel_plane(crtc->base.primary);
360 struct intel_plane_state *plane_state =
361 to_intel_plane_state(plane->base.state);
362 struct drm_i915_gem_object *obj =
363 intel_fb_obj(plane_state->uapi.fb);
364
365 if (!crtc_state->uapi.active) {
366 drm_dbg_kms(&i915->drm,
367 "[CRTC:%d:%s] not active, skipping\n",
368 crtc->base.base.id, crtc->base.name);
369 continue;
370 }
371
372 if (!obj) {
373 drm_dbg_kms(&i915->drm,
374 "[PLANE:%d:%s] no fb, skipping\n",
375 plane->base.base.id, plane->base.name);
376 continue;
377 }
378
379 if (intel_bo_to_drm_bo(obj)->size > max_size) {
380 drm_dbg_kms(&i915->drm,
381 "found possible fb from [PLANE:%d:%s]\n",
382 plane->base.base.id, plane->base.name);
383 fb = to_intel_framebuffer(plane_state->uapi.fb);
384 max_size = intel_bo_to_drm_bo(obj)->size;
385 }
386 }
387
388 if (!fb) {
389 drm_dbg_kms(&i915->drm,
390 "no active fbs found, not using BIOS config\n");
391 goto out;
392 }
393
394 /* Now make sure all the pipes will fit into it */
395 for_each_intel_crtc(dev, crtc) {
396 struct intel_crtc_state *crtc_state =
397 to_intel_crtc_state(crtc->base.state);
398 struct intel_plane *plane =
399 to_intel_plane(crtc->base.primary);
400 unsigned int cur_size;
401
402 if (!crtc_state->uapi.active) {
403 drm_dbg_kms(&i915->drm,
404 "[CRTC:%d:%s] not active, skipping\n",
405 crtc->base.base.id, crtc->base.name);
406 continue;
407 }
408
409 drm_dbg_kms(&i915->drm, "checking [PLANE:%d:%s] for BIOS fb\n",
410 plane->base.base.id, plane->base.name);
411
412 /*
413 * See if the plane fb we found above will fit on this
414 * pipe. Note we need to use the selected fb's pitch and bpp
415 * rather than the current pipe's, since they differ.
416 */
417 cur_size = crtc_state->uapi.adjusted_mode.crtc_hdisplay;
418 cur_size = cur_size * fb->base.format->cpp[0];
419 if (fb->base.pitches[0] < cur_size) {
420 drm_dbg_kms(&i915->drm,
421 "fb not wide enough for [PLANE:%d:%s] (%d vs %d)\n",
422 plane->base.base.id, plane->base.name,
423 cur_size, fb->base.pitches[0]);
424 fb = NULL;
425 break;
426 }
427
428 cur_size = crtc_state->uapi.adjusted_mode.crtc_vdisplay;
429 cur_size = intel_fb_align_height(&fb->base, 0, cur_size);
430 cur_size *= fb->base.pitches[0];
431 drm_dbg_kms(&i915->drm,
432 "[CRTC:%d:%s] area: %dx%d, bpp: %d, size: %d\n",
433 crtc->base.base.id, crtc->base.name,
434 crtc_state->uapi.adjusted_mode.crtc_hdisplay,
435 crtc_state->uapi.adjusted_mode.crtc_vdisplay,
436 fb->base.format->cpp[0] * 8,
437 cur_size);
438
439 if (cur_size > max_size) {
440 drm_dbg_kms(&i915->drm,
441 "fb not big enough for [PLANE:%d:%s] (%d vs %d)\n",
442 plane->base.base.id, plane->base.name,
443 cur_size, max_size);
444 fb = NULL;
445 break;
446 }
447
448 drm_dbg_kms(&i915->drm,
449 "fb big enough [PLANE:%d:%s] (%d >= %d)\n",
450 plane->base.base.id, plane->base.name,
451 max_size, cur_size);
452 }
453
454 if (!fb) {
455 drm_dbg_kms(&i915->drm,
456 "BIOS fb not suitable for all pipes, not using\n");
457 goto out;
458 }
459
460 ifbdev->preferred_bpp = fb->base.format->cpp[0] * 8;
461 ifbdev->fb = fb;
462
463 drm_framebuffer_get(&ifbdev->fb->base);
464
465 /* Final pass to check if any active pipes don't have fbs */
466 for_each_intel_crtc(dev, crtc) {
467 struct intel_crtc_state *crtc_state =
468 to_intel_crtc_state(crtc->base.state);
469 struct intel_plane *plane =
470 to_intel_plane(crtc->base.primary);
471 struct intel_plane_state *plane_state =
472 to_intel_plane_state(plane->base.state);
473
474 if (!crtc_state->uapi.active)
475 continue;
476
477 drm_WARN(dev, !plane_state->uapi.fb,
478 "re-used BIOS config but lost an fb on [PLANE:%d:%s]\n",
479 plane->base.base.id, plane->base.name);
480 }
481
482
483 drm_dbg_kms(&i915->drm, "using BIOS fb for initial console\n");
484 return true;
485
486 out:
487
488 return false;
489}
490
491 static void intel_fbdev_suspend_worker(struct work_struct *work)
492{
493 intel_fbdev_set_suspend(&container_of(work,
494 struct drm_i915_private,
495 display.fbdev.suspend_work)->drm,
496 FBINFO_STATE_RUNNING,
497 true);
498}
499
500 /* Suspends/resumes fbdev processing of incoming HPD events. When resuming HPD
501 * processing, fbdev will perform a full connector reprobe if a hotplug event
502 * was received while HPD was suspended.
503 */
504 static void intel_fbdev_hpd_set_suspend(struct drm_i915_private *i915, int state)
505{
506 struct intel_fbdev *ifbdev = i915->display.fbdev.fbdev;
507 bool send_hpd = false;
508
509 mutex_lock(&ifbdev->hpd_lock);
510 ifbdev->hpd_suspended = state == FBINFO_STATE_SUSPENDED;
511 send_hpd = !ifbdev->hpd_suspended && ifbdev->hpd_waiting;
512 ifbdev->hpd_waiting = false;
513 mutex_unlock(&ifbdev->hpd_lock);
514
515 if (send_hpd) {
516 drm_dbg_kms(&i915->drm, "Handling delayed fbcon HPD event\n");
517 drm_fb_helper_hotplug_event(&ifbdev->helper);
518 }
519}
520
521 void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous)
522{
523#ifdef __linux__
524 struct drm_i915_private *dev_priv = to_i915(dev);
525 struct intel_fbdev *ifbdev = dev_priv->display.fbdev.fbdev;
526 struct fb_info *info;
527
528 if (!ifbdev)
529 return;
530
531 if (drm_WARN_ON(&dev_priv->drm, !HAS_DISPLAY(dev_priv)))
532 return;
533
534 if (!ifbdev->vma)
535 goto set_suspend;
536
537 info = ifbdev->helper.info;
538
539 if (synchronous) {
540 /* Flush any pending work to turn the console on, and then
541 * wait to turn it off. It must be synchronous as we are
542 * about to suspend or unload the driver.
543 *
544 * Note that from within the work-handler, we cannot flush
545 * ourselves, so only flush outstanding work upon suspend!
546 */
547 if (state != FBINFO_STATE_RUNNING)
548 flush_work(&dev_priv->display.fbdev.suspend_work);
549
550 console_lock();
551 } else {
552 /*
553 * The console lock can be pretty contented on resume due
554 * to all the printk activity. Try to keep it out of the hot
555 * path of resume if possible.
556 */
557 drm_WARN_ON(dev, state != FBINFO_STATE_RUNNING);
558 if (!console_trylock()) {
559 /* Don't block our own workqueue as this can
560 * be run in parallel with other i915.ko tasks.
561 */
562 queue_work(dev_priv->unordered_wq,
563 &dev_priv->display.fbdev.suspend_work);
564 return;
565 }
566 }
567
568 /* On resume from hibernation: If the object is shmemfs backed, it has
569 * been restored from swap. If the object is stolen however, it will be
570 * full of whatever garbage was left in there.
571 */
572 if (state == FBINFO_STATE_RUNNING &&
573 !i915_gem_object_is_shmem(intel_fb_obj(&ifbdev->fb->base)))
574 memset_io(info->screen_base, 0, info->screen_size);
575
576 drm_fb_helper_set_suspend(&ifbdev->helper, state);
577 console_unlock();
578
579 set_suspend:
580 intel_fbdev_hpd_set_suspend(dev_priv, state);
581#endif
582}
583
584 static int intel_fbdev_output_poll_changed(struct drm_device *dev)
585{
586 struct intel_fbdev *ifbdev = to_i915(dev)->display.fbdev.fbdev;
587 bool send_hpd;
588
589 if (!ifbdev)
590 return -EINVAL;
591
592 mutex_lock(&ifbdev->hpd_lock);
593 send_hpd = !ifbdev->hpd_suspended;
594 ifbdev->hpd_waiting = true;
595 mutex_unlock(&ifbdev->hpd_lock);
596
597 if (send_hpd && (ifbdev->vma || ifbdev->helper.deferred_setup))
598 drm_fb_helper_hotplug_event(&ifbdev->helper);
599
600 return 0;
601}
602
603 static int intel_fbdev_restore_mode(struct drm_i915_private *dev_priv)
604{
605 struct intel_fbdev *ifbdev = dev_priv->display.fbdev.fbdev;
606 int ret;
607
608 if (!ifbdev)
609 return -EINVAL;
610
611 if (!ifbdev->vma)
612 return -ENOMEM;
613
614 ret = drm_fb_helper_restore_fbdev_mode_unlocked(&ifbdev->helper);
615 if (ret)
616 return ret;
617
618 intel_fbdev_invalidate(ifbdev);
619
620 return 0;
621}
622
623 /*
624 * Fbdev client and struct drm_client_funcs
625 */
626
627 static void intel_fbdev_client_unregister(struct drm_client_dev *client)
628{
629 struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client);
630 struct drm_device *dev = fb_helper->dev;
631 struct pci_dev *pdev = dev->pdev;
632
633 if (fb_helper->info) {
634 vga_switcheroo_client_fb_set(pdev, NULL);
635 drm_fb_helper_unregister_info(fb_helper);
636 } else {
637 drm_fb_helper_unprepare(fb_helper);
638 drm_client_release(&fb_helper->client);
639 kfree(fb_helper);
640 }
641}
642
643 static int intel_fbdev_client_restore(struct drm_client_dev *client)
644{
645 struct drm_i915_private *dev_priv = to_i915(client->dev);
646 int ret;
647
648 ret = intel_fbdev_restore_mode(dev_priv);
649 if (ret)
650 return ret;
651
652 vga_switcheroo_process_delayed_switch();
653
654 return 0;
655}
656
657 static int intel_fbdev_client_hotplug(struct drm_client_dev *client)
658{
659 struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client);
660 struct drm_device *dev = client->dev;
661 struct pci_dev *pdev = dev->pdev;
662 int ret;
663
664 if (dev->fb_helper)
665 return intel_fbdev_output_poll_changed(dev);
666
667 ret = drm_fb_helper_init(dev, fb_helper);
668 if (ret)
669 goto err_drm_err;
670
671 ret = drm_fb_helper_initial_config(fb_helper);
672 if (ret)
673 goto err_drm_fb_helper_fini;
674
675 vga_switcheroo_client_fb_set(pdev, fb_helper->info);
676
677 return 0;
678
679 err_drm_fb_helper_fini:
680 drm_fb_helper_fini(fb_helper);
681 err_drm_err:
682 drm_err(dev, "Failed to setup i915 fbdev emulation (ret=%d)\n", ret);
683 return ret;
684}
685
686 static const struct drm_client_funcs intel_fbdev_client_funcs = {
687 .owner = THIS_MODULE,
688 .unregister = intel_fbdev_client_unregister,
689 .restore = intel_fbdev_client_restore,
690 .hotplug = intel_fbdev_client_hotplug,
691};
692
693 void intel_fbdev_setup(struct drm_i915_private *i915)
694{
695 struct drm_device *dev = &i915->drm;
696 struct intel_fbdev *ifbdev;
697 int ret;
698
699 if (!HAS_DISPLAY(i915))
700 return;
701
702 ifbdev = kzalloc(sizeof(*ifbdev), GFP_KERNEL);
703 if (!ifbdev)
704 return;
705 drm_fb_helper_prepare(dev, &ifbdev->helper, 32, &intel_fb_helper_funcs);
706
707 i915->display.fbdev.fbdev = ifbdev;
708 INIT_WORK(&i915->display.fbdev.suspend_work, intel_fbdev_suspend_worker);
709 rw_init(&ifbdev->hpd_lock, "hdplk");
710 if (intel_fbdev_init_bios(dev, ifbdev))
711 ifbdev->helper.preferred_bpp = ifbdev->preferred_bpp;
712 else
713 ifbdev->preferred_bpp = ifbdev->helper.preferred_bpp;
714
715 ret = drm_client_init(dev, &ifbdev->helper.client, "intel-fbdev",
716 &intel_fbdev_client_funcs);
717 if (ret) {
718 drm_err(dev, "Failed to register client: %d\n", ret);
719 goto err_drm_fb_helper_unprepare;
720 }
721
722 drm_client_register(&ifbdev->helper.client);
723
724 return;
725
726 err_drm_fb_helper_unprepare:
727 drm_fb_helper_unprepare(&ifbdev->helper);
728 mutex_destroy(&ifbdev->hpd_lock);
729 kfree(ifbdev);
730}
731
732 struct intel_framebuffer *intel_fbdev_framebuffer(struct intel_fbdev *fbdev)
733{
734 if (!fbdev || !fbdev->helper.fb)
735 return NULL;
736
737 return to_intel_framebuffer(fbdev->helper.fb);
738}
739 

AltStyle によって変換されたページ (->オリジナル) /