nouveau_fbcon.c revision 1.3 1 /* $NetBSD: nouveau_fbcon.c,v 1.3 2018/08/27 04:58:24 riastradh Exp $ */
2
3 /*
4 * Copyright 2007 David Airlie
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * David Airlie
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: nouveau_fbcon.c,v 1.3 2018/08/27 04:58:24 riastradh Exp $");
31
32 #include <linux/module.h>
33 #include <linux/kernel.h>
34 #include <linux/errno.h>
35 #include <linux/string.h>
36 #include <linux/mm.h>
37 #include <linux/tty.h>
38 #include <linux/sysrq.h>
39 #include <linux/delay.h>
40 #include <linux/fb.h>
41 #include <linux/init.h>
42 #include <linux/screen_info.h>
43 #include <linux/vga_switcheroo.h>
44 #include <linux/console.h>
45
46 #include <drm/drmP.h>
47 #include <drm/drm_crtc.h>
48 #include <drm/drm_crtc_helper.h>
49 #include <drm/drm_fb_helper.h>
50
51 #include "nouveau_drm.h"
52 #include "nouveau_gem.h"
53 #include "nouveau_bo.h"
54 #include "nouveau_fbcon.h"
55 #include "nouveau_chan.h"
56
57 #include "nouveau_crtc.h"
58
59 #ifdef __NetBSD__
60 #include "nouveaufb.h"
61 #endif
62
63 #ifdef __NetBSD__ /* XXX nouveau fbaccel */
64 static const int nouveau_nofbaccel = 1;
65 #else
66 MODULE_PARM_DESC(nofbaccel, "Disable fbcon acceleration");
67 int nouveau_nofbaccel = 0;
68 module_param_named(nofbaccel, nouveau_nofbaccel, int, 0400);
69
70 static void
71 nouveau_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
72 {
73 struct nouveau_fbdev *fbcon = info->par;
74 struct nouveau_drm *drm = nouveau_drm(fbcon->dev);
75 struct nvif_device *device = &drm->device;
76 int ret;
77
78 if (info->state != FBINFO_STATE_RUNNING)
79 return;
80
81 ret = -ENODEV;
82 if (!in_interrupt() && !(info->flags & FBINFO_HWACCEL_DISABLED) &&
83 mutex_trylock(&drm->client.mutex)) {
84 if (device->info.family < NV_DEVICE_INFO_V0_TESLA)
85 ret = nv04_fbcon_fillrect(info, rect);
86 else
87 if (device->info.family < NV_DEVICE_INFO_V0_FERMI)
88 ret = nv50_fbcon_fillrect(info, rect);
89 else
90 ret = nvc0_fbcon_fillrect(info, rect);
91 mutex_unlock(&drm->client.mutex);
92 }
93
94 if (ret == 0)
95 return;
96
97 if (ret != -ENODEV)
98 nouveau_fbcon_gpu_lockup(info);
99 drm_fb_helper_cfb_fillrect(info, rect);
100 }
101
102 static void
103 nouveau_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *image)
104 {
105 struct nouveau_fbdev *fbcon = info->par;
106 struct nouveau_drm *drm = nouveau_drm(fbcon->dev);
107 struct nvif_device *device = &drm->device;
108 int ret;
109
110 if (info->state != FBINFO_STATE_RUNNING)
111 return;
112
113 ret = -ENODEV;
114 if (!in_interrupt() && !(info->flags & FBINFO_HWACCEL_DISABLED) &&
115 mutex_trylock(&drm->client.mutex)) {
116 if (device->info.family < NV_DEVICE_INFO_V0_TESLA)
117 ret = nv04_fbcon_copyarea(info, image);
118 else
119 if (device->info.family < NV_DEVICE_INFO_V0_FERMI)
120 ret = nv50_fbcon_copyarea(info, image);
121 else
122 ret = nvc0_fbcon_copyarea(info, image);
123 mutex_unlock(&drm->client.mutex);
124 }
125
126 if (ret == 0)
127 return;
128
129 if (ret != -ENODEV)
130 nouveau_fbcon_gpu_lockup(info);
131 drm_fb_helper_cfb_copyarea(info, image);
132 }
133
134 static void
135 nouveau_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
136 {
137 struct nouveau_fbdev *fbcon = info->par;
138 struct nouveau_drm *drm = nouveau_drm(fbcon->dev);
139 struct nvif_device *device = &drm->device;
140 int ret;
141
142 if (info->state != FBINFO_STATE_RUNNING)
143 return;
144
145 ret = -ENODEV;
146 if (!in_interrupt() && !(info->flags & FBINFO_HWACCEL_DISABLED) &&
147 mutex_trylock(&drm->client.mutex)) {
148 if (device->info.family < NV_DEVICE_INFO_V0_TESLA)
149 ret = nv04_fbcon_imageblit(info, image);
150 else
151 if (device->info.family < NV_DEVICE_INFO_V0_FERMI)
152 ret = nv50_fbcon_imageblit(info, image);
153 else
154 ret = nvc0_fbcon_imageblit(info, image);
155 mutex_unlock(&drm->client.mutex);
156 }
157
158 if (ret == 0)
159 return;
160
161 if (ret != -ENODEV)
162 nouveau_fbcon_gpu_lockup(info);
163 drm_fb_helper_cfb_imageblit(info, image);
164 }
165
166 static int
167 nouveau_fbcon_sync(struct fb_info *info)
168 {
169 struct nouveau_fbdev *fbcon = info->par;
170 struct nouveau_drm *drm = nouveau_drm(fbcon->dev);
171 struct nouveau_channel *chan = drm->channel;
172 int ret;
173
174 if (!chan || !chan->accel_done || in_interrupt() ||
175 info->state != FBINFO_STATE_RUNNING ||
176 info->flags & FBINFO_HWACCEL_DISABLED)
177 return 0;
178
179 if (!mutex_trylock(&drm->client.mutex))
180 return 0;
181
182 ret = nouveau_channel_idle(chan);
183 mutex_unlock(&drm->client.mutex);
184 if (ret) {
185 nouveau_fbcon_gpu_lockup(info);
186 return 0;
187 }
188
189 chan->accel_done = false;
190 return 0;
191 }
192
193 static int
194 nouveau_fbcon_open(struct fb_info *info, int user)
195 {
196 struct nouveau_fbdev *fbcon = info->par;
197 struct nouveau_drm *drm = nouveau_drm(fbcon->dev);
198 int ret = pm_runtime_get_sync(drm->dev->dev);
199 if (ret < 0 && ret != -EACCES)
200 return ret;
201 return 0;
202 }
203
204 static int
205 nouveau_fbcon_release(struct fb_info *info, int user)
206 {
207 struct nouveau_fbdev *fbcon = info->par;
208 struct nouveau_drm *drm = nouveau_drm(fbcon->dev);
209 pm_runtime_put(drm->dev->dev);
210 return 0;
211 }
212
213 static struct fb_ops nouveau_fbcon_ops = {
214 .owner = THIS_MODULE,
215 .fb_open = nouveau_fbcon_open,
216 .fb_release = nouveau_fbcon_release,
217 .fb_check_var = drm_fb_helper_check_var,
218 .fb_set_par = drm_fb_helper_set_par,
219 .fb_fillrect = nouveau_fbcon_fillrect,
220 .fb_copyarea = nouveau_fbcon_copyarea,
221 .fb_imageblit = nouveau_fbcon_imageblit,
222 .fb_sync = nouveau_fbcon_sync,
223 .fb_pan_display = drm_fb_helper_pan_display,
224 .fb_blank = drm_fb_helper_blank,
225 .fb_setcmap = drm_fb_helper_setcmap,
226 .fb_debug_enter = drm_fb_helper_debug_enter,
227 .fb_debug_leave = drm_fb_helper_debug_leave,
228 };
229
230 static struct fb_ops nouveau_fbcon_sw_ops = {
231 .owner = THIS_MODULE,
232 .fb_open = nouveau_fbcon_open,
233 .fb_release = nouveau_fbcon_release,
234 .fb_check_var = drm_fb_helper_check_var,
235 .fb_set_par = drm_fb_helper_set_par,
236 .fb_fillrect = drm_fb_helper_cfb_fillrect,
237 .fb_copyarea = drm_fb_helper_cfb_copyarea,
238 .fb_imageblit = drm_fb_helper_cfb_imageblit,
239 .fb_pan_display = drm_fb_helper_pan_display,
240 .fb_blank = drm_fb_helper_blank,
241 .fb_setcmap = drm_fb_helper_setcmap,
242 .fb_debug_enter = drm_fb_helper_debug_enter,
243 .fb_debug_leave = drm_fb_helper_debug_leave,
244 };
245 #endif /* XXX nouveau fbaccel */
246
247 void
248 nouveau_fbcon_accel_save_disable(struct drm_device *dev)
249 {
250 struct nouveau_drm *drm = nouveau_drm(dev);
251 if (drm->fbcon) {
252 drm->fbcon->saved_flags = drm->fbcon->helper.fbdev->flags;
253 drm->fbcon->helper.fbdev->flags |= FBINFO_HWACCEL_DISABLED;
254 }
255 }
256
257 void
258 nouveau_fbcon_accel_restore(struct drm_device *dev)
259 {
260 struct nouveau_drm *drm = nouveau_drm(dev);
261 if (drm->fbcon) {
262 drm->fbcon->helper.fbdev->flags = drm->fbcon->saved_flags;
263 }
264 }
265
266 static void
267 nouveau_fbcon_accel_fini(struct drm_device *dev)
268 {
269 struct nouveau_drm *drm = nouveau_drm(dev);
270 struct nouveau_fbdev *fbcon = drm->fbcon;
271 if (fbcon && drm->channel) {
272 console_lock();
273 fbcon->helper.fbdev->flags |= FBINFO_HWACCEL_DISABLED;
274 console_unlock();
275 nouveau_channel_idle(drm->channel);
276 nvif_object_fini(&fbcon->twod);
277 nvif_object_fini(&fbcon->blit);
278 nvif_object_fini(&fbcon->gdi);
279 nvif_object_fini(&fbcon->patt);
280 nvif_object_fini(&fbcon->rop);
281 nvif_object_fini(&fbcon->clip);
282 nvif_object_fini(&fbcon->surf2d);
283 }
284 }
285
286 static void
287 nouveau_fbcon_accel_init(struct drm_device *dev)
288 {
289 struct nouveau_drm *drm = nouveau_drm(dev);
290 struct nouveau_fbdev *fbcon = drm->fbcon;
291 struct fb_info *info = fbcon->helper.fbdev;
292 int ret;
293
294 if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA)
295 ret = nv04_fbcon_accel_init(info);
296 else
297 if (drm->device.info.family < NV_DEVICE_INFO_V0_FERMI)
298 ret = nv50_fbcon_accel_init(info);
299 else
300 ret = nvc0_fbcon_accel_init(info);
301
302 if (ret == 0)
303 info->fbops = &nouveau_fbcon_ops;
304 }
305
306 static void nouveau_fbcon_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
307 u16 blue, int regno)
308 {
309 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
310
311 nv_crtc->lut.r[regno] = red;
312 nv_crtc->lut.g[regno] = green;
313 nv_crtc->lut.b[regno] = blue;
314 }
315
316 static void nouveau_fbcon_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
317 u16 *blue, int regno)
318 {
319 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
320
321 *red = nv_crtc->lut.r[regno];
322 *green = nv_crtc->lut.g[regno];
323 *blue = nv_crtc->lut.b[regno];
324 }
325
326 static void
327 nouveau_fbcon_zfill(struct drm_device *dev, struct nouveau_fbdev *fbcon)
328 {
329 #ifdef __NetBSD__ /* XXX nouveau fbaccel */
330 struct nouveau_bo *const nvbo = fbcon->nouveau_fb.nvbo;
331
332 (void)memset(__UNVOLATILE(nvbo_kmap_obj_iovirtual(nvbo)), 0,
333 nvbo->bo.num_pages << PAGE_SHIFT);
334 #else
335 struct fb_info *info = fbcon->helper.fbdev;
336 struct fb_fillrect rect;
337
338 /* Clear the entire fbcon. The drm will program every connector
339 * with it's preferred mode. If the sizes differ, one display will
340 * quite likely have garbage around the console.
341 */
342 rect.dx = rect.dy = 0;
343 rect.width = info->var.xres_virtual;
344 rect.height = info->var.yres_virtual;
345 rect.color = 0;
346 rect.rop = ROP_COPY;
347 info->fbops->fb_fillrect(info, &rect);
348 #endif
349 }
350
351 static int
352 nouveau_fbcon_create(struct drm_fb_helper *helper,
353 struct drm_fb_helper_surface_size *sizes)
354 {
355 struct nouveau_fbdev *fbcon =
356 container_of(helper, struct nouveau_fbdev, helper);
357 struct drm_device *dev = fbcon->dev;
358 struct nouveau_drm *drm = nouveau_drm(dev);
359 struct nvif_device *device = &drm->device;
360 #ifndef __NetBSD__
361 struct fb_info *info;
362 #endif
363 struct drm_framebuffer *fb;
364 struct nouveau_framebuffer *nouveau_fb;
365 struct nouveau_channel *chan;
366 struct nouveau_bo *nvbo;
367 struct drm_mode_fb_cmd2 mode_cmd;
368 int size, ret;
369
370 mode_cmd.width = sizes->surface_width;
371 mode_cmd.height = sizes->surface_height;
372
373 mode_cmd.pitches[0] = mode_cmd.width * (sizes->surface_bpp >> 3);
374 mode_cmd.pitches[0] = roundup(mode_cmd.pitches[0], 256);
375
376 mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
377 sizes->surface_depth);
378
379 size = mode_cmd.pitches[0] * mode_cmd.height;
380 size = roundup(size, PAGE_SIZE);
381
382 ret = nouveau_gem_new(dev, size, 0, NOUVEAU_GEM_DOMAIN_VRAM,
383 0, 0x0000, &nvbo);
384 if (ret) {
385 NV_ERROR(drm, "failed to allocate framebuffer\n");
386 goto out;
387 }
388
389 ret = nouveau_bo_pin(nvbo, TTM_PL_FLAG_VRAM, false);
390 if (ret) {
391 NV_ERROR(drm, "failed to pin fb: %d\n", ret);
392 goto out_unref;
393 }
394
395 ret = nouveau_bo_map(nvbo);
396 if (ret) {
397 NV_ERROR(drm, "failed to map fb: %d\n", ret);
398 goto out_unpin;
399 }
400
401 chan = nouveau_nofbaccel ? NULL : drm->channel;
402 if (chan && device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
403 ret = nouveau_bo_vma_add(nvbo, drm->client.vm,
404 &fbcon->nouveau_fb.vma);
405 if (ret) {
406 NV_ERROR(drm, "failed to map fb into chan: %d\n", ret);
407 chan = NULL;
408 }
409 }
410
411 #ifdef __NetBSD__
412 nouveau_framebuffer_init(dev, &fbcon->nouveau_fb, &mode_cmd, nvbo);
413 nouveau_fb = &fbcon->nouveau_fb;
414 fb = &nouveau_fb->base;
415
416 nouveau_fbcon_zfill(dev, fbcon);
417
418 {
419 static const struct nouveaufb_attach_args zero_nfa;
420 struct nouveaufb_attach_args nfa = zero_nfa;
421
422 nfa.nfa_fb_helper = helper;
423 nfa.nfa_fb_sizes = *sizes;
424 nfa.nfa_fb_ptr = nvbo_kmap_obj_iovirtual(nvbo);
425 nfa.nfa_fb_linebytes = mode_cmd.pitches[0];
426
427 helper->fbdev = config_found_ia(dev->dev, "nouveaufbbus", &nfa, NULL);
428 if (helper->fbdev == NULL) {
429 DRM_ERROR("failed to attach nouveaufb\n");
430 goto out_unlock;
431 }
432 }
433 helper->fb = fb;
434
435 return 0;
436 #else
437 mutex_lock(&dev->struct_mutex);
438
439 info = drm_fb_helper_alloc_fbi(helper);
440 if (IS_ERR(info)) {
441 ret = PTR_ERR(info);
442 goto out_unlock;
443 }
444 info->skip_vt_switch = 1;
445
446 info->par = fbcon;
447
448 nouveau_framebuffer_init(dev, &fbcon->nouveau_fb, &mode_cmd, nvbo);
449
450 nouveau_fb = &fbcon->nouveau_fb;
451 fb = &nouveau_fb->base;
452
453 /* setup helper */
454 fbcon->helper.fb = fb;
455
456 strcpy(info->fix.id, "nouveaufb");
457 if (!chan)
458 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_DISABLED;
459 else
460 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA |
461 FBINFO_HWACCEL_FILLRECT |
462 FBINFO_HWACCEL_IMAGEBLIT;
463 info->flags |= FBINFO_CAN_FORCE_OUTPUT;
464 info->fbops = &nouveau_fbcon_sw_ops;
465 info->fix.smem_start = nvbo->bo.mem.bus.base +
466 nvbo->bo.mem.bus.offset;
467 info->fix.smem_len = size;
468
469 info->screen_base = nvbo_kmap_obj_iovirtual(nouveau_fb->nvbo);
470 info->screen_size = size;
471
472 drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
473 drm_fb_helper_fill_var(info, &fbcon->helper, sizes->fb_width, sizes->fb_height);
474
475 /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
476
477 mutex_unlock(&dev->struct_mutex);
478
479 if (chan)
480 nouveau_fbcon_accel_init(dev);
481 nouveau_fbcon_zfill(dev, fbcon);
482
483 /* To allow resizeing without swapping buffers */
484 NV_INFO(drm, "allocated %dx%d fb: 0x%jx, bo %p\n",
485 nouveau_fb->base.width, nouveau_fb->base.height,
486 (uintmax_t)nvbo->bo.offset, nvbo);
487
488 vga_switcheroo_client_fb_set(dev->pdev, info);
489 return 0;
490 #endif /* defined(__NetBSD__) */
491
492 out_unlock:
493 #ifndef __NetBSD__
494 mutex_unlock(&dev->struct_mutex);
495 #endif
496 if (chan)
497 nouveau_bo_vma_del(nvbo, &fbcon->nouveau_fb.vma);
498 nouveau_bo_unmap(nvbo);
499 out_unpin:
500 nouveau_bo_unpin(nvbo);
501 out_unref:
502 nouveau_bo_ref(NULL, &nvbo);
503 out:
504 return ret;
505 }
506
507 void
508 nouveau_fbcon_output_poll_changed(struct drm_device *dev)
509 {
510 struct nouveau_drm *drm = nouveau_drm(dev);
511 if (drm->fbcon)
512 drm_fb_helper_hotplug_event(&drm->fbcon->helper);
513 }
514
515 static int
516 nouveau_fbcon_destroy(struct drm_device *dev, struct nouveau_fbdev *fbcon)
517 {
518 struct nouveau_framebuffer *nouveau_fb = &fbcon->nouveau_fb;
519
520 #ifdef __NetBSD__
521 if (fbcon->helper.fbdev) {
522 int ret;
523
524 /* XXX errno NetBSD->Linux */
525 ret = -config_detach(fbcon->helper.fbdev, DETACH_FORCE);
526 if (ret)
527 DRM_ERROR("failed to detach nouveaufb: %d\n", ret);
528 fbcon->helper.fbdev = NULL;
529 }
530 #else
531 drm_fb_helper_unregister_fbi(&fbcon->helper);
532 drm_fb_helper_release_fbi(&fbcon->helper);
533 #endif
534
535 if (nouveau_fb->nvbo) {
536 nouveau_bo_unmap(nouveau_fb->nvbo);
537 nouveau_bo_vma_del(nouveau_fb->nvbo, &nouveau_fb->vma);
538 nouveau_bo_unpin(nouveau_fb->nvbo);
539 drm_gem_object_unreference_unlocked(&nouveau_fb->nvbo->gem);
540 nouveau_fb->nvbo = NULL;
541 }
542 drm_fb_helper_fini(&fbcon->helper);
543 drm_framebuffer_unregister_private(&nouveau_fb->base);
544 drm_framebuffer_cleanup(&nouveau_fb->base);
545 return 0;
546 }
547
548 #ifndef __NetBSD__ /* XXX nouveau fbaccel */
549 void nouveau_fbcon_gpu_lockup(struct fb_info *info)
550 {
551 struct nouveau_fbdev *fbcon = info->par;
552 struct nouveau_drm *drm = nouveau_drm(fbcon->dev);
553
554 NV_ERROR(drm, "GPU lockup - switching to software fbcon\n");
555 info->flags |= FBINFO_HWACCEL_DISABLED;
556 }
557 #endif
558
559 static const struct drm_fb_helper_funcs nouveau_fbcon_helper_funcs = {
560 .gamma_set = nouveau_fbcon_gamma_set,
561 .gamma_get = nouveau_fbcon_gamma_get,
562 .fb_probe = nouveau_fbcon_create,
563 };
564
565 void
566 nouveau_fbcon_set_suspend(struct drm_device *dev, int state)
567 {
568 struct nouveau_drm *drm = nouveau_drm(dev);
569 if (drm->fbcon) {
570 console_lock();
571 if (state == FBINFO_STATE_RUNNING)
572 nouveau_fbcon_accel_restore(dev);
573 drm_fb_helper_set_suspend(&drm->fbcon->helper, state);
574 if (state != FBINFO_STATE_RUNNING)
575 nouveau_fbcon_accel_save_disable(dev);
576 console_unlock();
577 }
578 }
579
580 int
581 nouveau_fbcon_init(struct drm_device *dev)
582 {
583 struct nouveau_drm *drm = nouveau_drm(dev);
584 struct nouveau_fbdev *fbcon;
585 int preferred_bpp;
586 int ret;
587
588 if (!dev->mode_config.num_crtc ||
589 (dev->pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
590 return 0;
591
592 fbcon = kzalloc(sizeof(struct nouveau_fbdev), GFP_KERNEL);
593 if (!fbcon)
594 return -ENOMEM;
595
596 fbcon->dev = dev;
597 drm->fbcon = fbcon;
598
599 drm_fb_helper_prepare(dev, &fbcon->helper, &nouveau_fbcon_helper_funcs);
600
601 ret = drm_fb_helper_init(dev, &fbcon->helper,
602 dev->mode_config.num_crtc, 4);
603 if (ret)
604 goto free;
605
606 ret = drm_fb_helper_single_add_all_connectors(&fbcon->helper);
607 if (ret)
608 goto fini;
609
610 if (drm->device.info.ram_size <= 32 * 1024 * 1024)
611 preferred_bpp = 8;
612 else
613 if (drm->device.info.ram_size <= 64 * 1024 * 1024)
614 preferred_bpp = 16;
615 else
616 preferred_bpp = 32;
617
618 /* disable all the possible outputs/crtcs before entering KMS mode */
619 drm_helper_disable_unused_functions(dev);
620
621 ret = drm_fb_helper_initial_config(&fbcon->helper, preferred_bpp);
622 if (ret)
623 goto fini;
624
625 if (fbcon->helper.fbdev)
626 fbcon->helper.fbdev->pixmap.buf_align = 4;
627 return 0;
628
629 fini:
630 drm_fb_helper_fini(&fbcon->helper);
631 free:
632 kfree(fbcon);
633 return ret;
634 }
635
636 void
637 nouveau_fbcon_fini(struct drm_device *dev)
638 {
639 struct nouveau_drm *drm = nouveau_drm(dev);
640
641 if (!drm->fbcon)
642 return;
643
644 nouveau_fbcon_accel_fini(dev);
645 nouveau_fbcon_destroy(dev, drm->fbcon);
646 kfree(drm->fbcon);
647 drm->fbcon = NULL;
648 }
649