nouveau_fbcon.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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. #include <linux/module.h>
  27. #include <linux/kernel.h>
  28. #include <linux/errno.h>
  29. #include <linux/string.h>
  30. #include <linux/mm.h>
  31. #include <linux/tty.h>
  32. #include <linux/sysrq.h>
  33. #include <linux/delay.h>
  34. #include <linux/init.h>
  35. #include <linux/screen_info.h>
  36. #include <linux/vga_switcheroo.h>
  37. #include <linux/console.h>
  38. #include <drm/drm_crtc.h>
  39. #include <drm/drm_crtc_helper.h>
  40. #include <drm/drm_fb_helper.h>
  41. #include <drm/drm_fourcc.h>
  42. #include <drm/drm_atomic.h>
  43. #include "nouveau_drv.h"
  44. #include "nouveau_gem.h"
  45. #include "nouveau_bo.h"
  46. #include "nouveau_fbcon.h"
  47. #include "nouveau_chan.h"
  48. #include "nouveau_vmm.h"
  49. #include "nouveau_crtc.h"
  50. MODULE_PARM_DESC(nofbaccel, "Disable fbcon acceleration");
  51. int nouveau_nofbaccel = 0;
  52. module_param_named(nofbaccel, nouveau_nofbaccel, int, 0400);
  53. MODULE_PARM_DESC(fbcon_bpp, "fbcon bits-per-pixel (default: auto)");
  54. static int nouveau_fbcon_bpp;
  55. module_param_named(fbcon_bpp, nouveau_fbcon_bpp, int, 0400);
  56. static void
  57. nouveau_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  58. {
  59. struct nouveau_fbdev *fbcon = info->par;
  60. struct nouveau_drm *drm = nouveau_drm(fbcon->helper.dev);
  61. struct nvif_device *device = &drm->client.device;
  62. int ret;
  63. if (info->state != FBINFO_STATE_RUNNING)
  64. return;
  65. ret = -ENODEV;
  66. if (!in_interrupt() && !(info->flags & FBINFO_HWACCEL_DISABLED) &&
  67. mutex_trylock(&drm->client.mutex)) {
  68. if (device->info.family < NV_DEVICE_INFO_V0_TESLA)
  69. ret = nv04_fbcon_fillrect(info, rect);
  70. else
  71. if (device->info.family < NV_DEVICE_INFO_V0_FERMI)
  72. ret = nv50_fbcon_fillrect(info, rect);
  73. else
  74. ret = nvc0_fbcon_fillrect(info, rect);
  75. mutex_unlock(&drm->client.mutex);
  76. }
  77. if (ret == 0)
  78. return;
  79. if (ret != -ENODEV)
  80. nouveau_fbcon_gpu_lockup(info);
  81. drm_fb_helper_cfb_fillrect(info, rect);
  82. }
  83. static void
  84. nouveau_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *image)
  85. {
  86. struct nouveau_fbdev *fbcon = info->par;
  87. struct nouveau_drm *drm = nouveau_drm(fbcon->helper.dev);
  88. struct nvif_device *device = &drm->client.device;
  89. int ret;
  90. if (info->state != FBINFO_STATE_RUNNING)
  91. return;
  92. ret = -ENODEV;
  93. if (!in_interrupt() && !(info->flags & FBINFO_HWACCEL_DISABLED) &&
  94. mutex_trylock(&drm->client.mutex)) {
  95. if (device->info.family < NV_DEVICE_INFO_V0_TESLA)
  96. ret = nv04_fbcon_copyarea(info, image);
  97. else
  98. if (device->info.family < NV_DEVICE_INFO_V0_FERMI)
  99. ret = nv50_fbcon_copyarea(info, image);
  100. else
  101. ret = nvc0_fbcon_copyarea(info, image);
  102. mutex_unlock(&drm->client.mutex);
  103. }
  104. if (ret == 0)
  105. return;
  106. if (ret != -ENODEV)
  107. nouveau_fbcon_gpu_lockup(info);
  108. drm_fb_helper_cfb_copyarea(info, image);
  109. }
  110. static void
  111. nouveau_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
  112. {
  113. struct nouveau_fbdev *fbcon = info->par;
  114. struct nouveau_drm *drm = nouveau_drm(fbcon->helper.dev);
  115. struct nvif_device *device = &drm->client.device;
  116. int ret;
  117. if (info->state != FBINFO_STATE_RUNNING)
  118. return;
  119. ret = -ENODEV;
  120. if (!in_interrupt() && !(info->flags & FBINFO_HWACCEL_DISABLED) &&
  121. mutex_trylock(&drm->client.mutex)) {
  122. if (device->info.family < NV_DEVICE_INFO_V0_TESLA)
  123. ret = nv04_fbcon_imageblit(info, image);
  124. else
  125. if (device->info.family < NV_DEVICE_INFO_V0_FERMI)
  126. ret = nv50_fbcon_imageblit(info, image);
  127. else
  128. ret = nvc0_fbcon_imageblit(info, image);
  129. mutex_unlock(&drm->client.mutex);
  130. }
  131. if (ret == 0)
  132. return;
  133. if (ret != -ENODEV)
  134. nouveau_fbcon_gpu_lockup(info);
  135. drm_fb_helper_cfb_imageblit(info, image);
  136. }
  137. static int
  138. nouveau_fbcon_sync(struct fb_info *info)
  139. {
  140. struct nouveau_fbdev *fbcon = info->par;
  141. struct nouveau_drm *drm = nouveau_drm(fbcon->helper.dev);
  142. struct nouveau_channel *chan = drm->channel;
  143. int ret;
  144. if (!chan || !chan->accel_done || in_interrupt() ||
  145. info->state != FBINFO_STATE_RUNNING ||
  146. info->flags & FBINFO_HWACCEL_DISABLED)
  147. return 0;
  148. if (!mutex_trylock(&drm->client.mutex))
  149. return 0;
  150. ret = nouveau_channel_idle(chan);
  151. mutex_unlock(&drm->client.mutex);
  152. if (ret) {
  153. nouveau_fbcon_gpu_lockup(info);
  154. return 0;
  155. }
  156. chan->accel_done = false;
  157. return 0;
  158. }
  159. static int
  160. nouveau_fbcon_open(struct fb_info *info, int user)
  161. {
  162. struct nouveau_fbdev *fbcon = info->par;
  163. struct nouveau_drm *drm = nouveau_drm(fbcon->helper.dev);
  164. int ret = pm_runtime_get_sync(drm->dev->dev);
  165. if (ret < 0 && ret != -EACCES) {
  166. pm_runtime_put(drm->dev->dev);
  167. return ret;
  168. }
  169. return 0;
  170. }
  171. static int
  172. nouveau_fbcon_release(struct fb_info *info, int user)
  173. {
  174. struct nouveau_fbdev *fbcon = info->par;
  175. struct nouveau_drm *drm = nouveau_drm(fbcon->helper.dev);
  176. pm_runtime_put(drm->dev->dev);
  177. return 0;
  178. }
  179. static const struct fb_ops nouveau_fbcon_ops = {
  180. .owner = THIS_MODULE,
  181. DRM_FB_HELPER_DEFAULT_OPS,
  182. .fb_open = nouveau_fbcon_open,
  183. .fb_release = nouveau_fbcon_release,
  184. .fb_fillrect = nouveau_fbcon_fillrect,
  185. .fb_copyarea = nouveau_fbcon_copyarea,
  186. .fb_imageblit = nouveau_fbcon_imageblit,
  187. .fb_sync = nouveau_fbcon_sync,
  188. };
  189. static const struct fb_ops nouveau_fbcon_sw_ops = {
  190. .owner = THIS_MODULE,
  191. DRM_FB_HELPER_DEFAULT_OPS,
  192. .fb_open = nouveau_fbcon_open,
  193. .fb_release = nouveau_fbcon_release,
  194. .fb_fillrect = drm_fb_helper_cfb_fillrect,
  195. .fb_copyarea = drm_fb_helper_cfb_copyarea,
  196. .fb_imageblit = drm_fb_helper_cfb_imageblit,
  197. };
  198. void
  199. nouveau_fbcon_accel_save_disable(struct drm_device *dev)
  200. {
  201. struct nouveau_drm *drm = nouveau_drm(dev);
  202. if (drm->fbcon && drm->fbcon->helper.fbdev) {
  203. drm->fbcon->saved_flags = drm->fbcon->helper.fbdev->flags;
  204. drm->fbcon->helper.fbdev->flags |= FBINFO_HWACCEL_DISABLED;
  205. }
  206. }
  207. void
  208. nouveau_fbcon_accel_restore(struct drm_device *dev)
  209. {
  210. struct nouveau_drm *drm = nouveau_drm(dev);
  211. if (drm->fbcon && drm->fbcon->helper.fbdev) {
  212. drm->fbcon->helper.fbdev->flags = drm->fbcon->saved_flags;
  213. }
  214. }
  215. static void
  216. nouveau_fbcon_accel_fini(struct drm_device *dev)
  217. {
  218. struct nouveau_drm *drm = nouveau_drm(dev);
  219. struct nouveau_fbdev *fbcon = drm->fbcon;
  220. if (fbcon && drm->channel) {
  221. console_lock();
  222. if (fbcon->helper.fbdev)
  223. fbcon->helper.fbdev->flags |= FBINFO_HWACCEL_DISABLED;
  224. console_unlock();
  225. nouveau_channel_idle(drm->channel);
  226. nvif_object_dtor(&fbcon->twod);
  227. nvif_object_dtor(&fbcon->blit);
  228. nvif_object_dtor(&fbcon->gdi);
  229. nvif_object_dtor(&fbcon->patt);
  230. nvif_object_dtor(&fbcon->rop);
  231. nvif_object_dtor(&fbcon->clip);
  232. nvif_object_dtor(&fbcon->surf2d);
  233. }
  234. }
  235. static void
  236. nouveau_fbcon_accel_init(struct drm_device *dev)
  237. {
  238. struct nouveau_drm *drm = nouveau_drm(dev);
  239. struct nouveau_fbdev *fbcon = drm->fbcon;
  240. struct fb_info *info = fbcon->helper.fbdev;
  241. int ret;
  242. if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA)
  243. ret = nv04_fbcon_accel_init(info);
  244. else
  245. if (drm->client.device.info.family < NV_DEVICE_INFO_V0_FERMI)
  246. ret = nv50_fbcon_accel_init(info);
  247. else
  248. ret = nvc0_fbcon_accel_init(info);
  249. if (ret == 0)
  250. info->fbops = &nouveau_fbcon_ops;
  251. }
  252. static void
  253. nouveau_fbcon_zfill(struct drm_device *dev, struct nouveau_fbdev *fbcon)
  254. {
  255. struct fb_info *info = fbcon->helper.fbdev;
  256. struct fb_fillrect rect;
  257. /* Clear the entire fbcon. The drm will program every connector
  258. * with it's preferred mode. If the sizes differ, one display will
  259. * quite likely have garbage around the console.
  260. */
  261. rect.dx = rect.dy = 0;
  262. rect.width = info->var.xres_virtual;
  263. rect.height = info->var.yres_virtual;
  264. rect.color = 0;
  265. rect.rop = ROP_COPY;
  266. info->fbops->fb_fillrect(info, &rect);
  267. }
  268. static int
  269. nouveau_fbcon_create(struct drm_fb_helper *helper,
  270. struct drm_fb_helper_surface_size *sizes)
  271. {
  272. struct nouveau_fbdev *fbcon =
  273. container_of(helper, struct nouveau_fbdev, helper);
  274. struct drm_device *dev = fbcon->helper.dev;
  275. struct nouveau_drm *drm = nouveau_drm(dev);
  276. struct nvif_device *device = &drm->client.device;
  277. struct fb_info *info;
  278. struct drm_framebuffer *fb;
  279. struct nouveau_channel *chan;
  280. struct nouveau_bo *nvbo;
  281. struct drm_mode_fb_cmd2 mode_cmd = {};
  282. int ret;
  283. mode_cmd.width = sizes->surface_width;
  284. mode_cmd.height = sizes->surface_height;
  285. mode_cmd.pitches[0] = mode_cmd.width * (sizes->surface_bpp >> 3);
  286. mode_cmd.pitches[0] = roundup(mode_cmd.pitches[0], 256);
  287. mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
  288. sizes->surface_depth);
  289. ret = nouveau_gem_new(&drm->client, mode_cmd.pitches[0] *
  290. mode_cmd.height, 0, NOUVEAU_GEM_DOMAIN_VRAM,
  291. 0, 0x0000, &nvbo);
  292. if (ret) {
  293. NV_ERROR(drm, "failed to allocate framebuffer\n");
  294. goto out;
  295. }
  296. ret = nouveau_framebuffer_new(dev, &mode_cmd, &nvbo->bo.base, &fb);
  297. if (ret)
  298. goto out_unref;
  299. ret = nouveau_bo_pin(nvbo, NOUVEAU_GEM_DOMAIN_VRAM, false);
  300. if (ret) {
  301. NV_ERROR(drm, "failed to pin fb: %d\n", ret);
  302. goto out_unref;
  303. }
  304. ret = nouveau_bo_map(nvbo);
  305. if (ret) {
  306. NV_ERROR(drm, "failed to map fb: %d\n", ret);
  307. goto out_unpin;
  308. }
  309. chan = nouveau_nofbaccel ? NULL : drm->channel;
  310. if (chan && device->info.family >= NV_DEVICE_INFO_V0_TESLA) {
  311. ret = nouveau_vma_new(nvbo, chan->vmm, &fbcon->vma);
  312. if (ret) {
  313. NV_ERROR(drm, "failed to map fb into chan: %d\n", ret);
  314. chan = NULL;
  315. }
  316. }
  317. info = drm_fb_helper_alloc_fbi(helper);
  318. if (IS_ERR(info)) {
  319. ret = PTR_ERR(info);
  320. goto out_unlock;
  321. }
  322. /* setup helper */
  323. fbcon->helper.fb = fb;
  324. if (!chan)
  325. info->flags = FBINFO_HWACCEL_DISABLED;
  326. else
  327. info->flags = FBINFO_HWACCEL_COPYAREA |
  328. FBINFO_HWACCEL_FILLRECT |
  329. FBINFO_HWACCEL_IMAGEBLIT;
  330. info->fbops = &nouveau_fbcon_sw_ops;
  331. info->fix.smem_start = nvbo->bo.mem.bus.offset;
  332. info->fix.smem_len = nvbo->bo.mem.num_pages << PAGE_SHIFT;
  333. info->screen_base = nvbo_kmap_obj_iovirtual(nvbo);
  334. info->screen_size = nvbo->bo.mem.num_pages << PAGE_SHIFT;
  335. drm_fb_helper_fill_info(info, &fbcon->helper, sizes);
  336. /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
  337. if (chan)
  338. nouveau_fbcon_accel_init(dev);
  339. nouveau_fbcon_zfill(dev, fbcon);
  340. /* To allow resizeing without swapping buffers */
  341. NV_INFO(drm, "allocated %dx%d fb: 0x%llx, bo %p\n",
  342. fb->width, fb->height, nvbo->offset, nvbo);
  343. vga_switcheroo_client_fb_set(dev->pdev, info);
  344. return 0;
  345. out_unlock:
  346. if (chan)
  347. nouveau_vma_del(&fbcon->vma);
  348. nouveau_bo_unmap(nvbo);
  349. out_unpin:
  350. nouveau_bo_unpin(nvbo);
  351. out_unref:
  352. nouveau_bo_ref(NULL, &nvbo);
  353. out:
  354. return ret;
  355. }
  356. static int
  357. nouveau_fbcon_destroy(struct drm_device *dev, struct nouveau_fbdev *fbcon)
  358. {
  359. struct drm_framebuffer *fb = fbcon->helper.fb;
  360. struct nouveau_bo *nvbo;
  361. drm_fb_helper_unregister_fbi(&fbcon->helper);
  362. drm_fb_helper_fini(&fbcon->helper);
  363. if (fb && fb->obj[0]) {
  364. nvbo = nouveau_gem_object(fb->obj[0]);
  365. nouveau_vma_del(&fbcon->vma);
  366. nouveau_bo_unmap(nvbo);
  367. nouveau_bo_unpin(nvbo);
  368. drm_framebuffer_put(fb);
  369. }
  370. return 0;
  371. }
  372. void nouveau_fbcon_gpu_lockup(struct fb_info *info)
  373. {
  374. struct nouveau_fbdev *fbcon = info->par;
  375. struct nouveau_drm *drm = nouveau_drm(fbcon->helper.dev);
  376. NV_ERROR(drm, "GPU lockup - switching to software fbcon\n");
  377. info->flags |= FBINFO_HWACCEL_DISABLED;
  378. }
  379. static const struct drm_fb_helper_funcs nouveau_fbcon_helper_funcs = {
  380. .fb_probe = nouveau_fbcon_create,
  381. };
  382. static void
  383. nouveau_fbcon_set_suspend_work(struct work_struct *work)
  384. {
  385. struct nouveau_drm *drm = container_of(work, typeof(*drm), fbcon_work);
  386. int state = READ_ONCE(drm->fbcon_new_state);
  387. if (state == FBINFO_STATE_RUNNING)
  388. pm_runtime_get_sync(drm->dev->dev);
  389. console_lock();
  390. if (state == FBINFO_STATE_RUNNING)
  391. nouveau_fbcon_accel_restore(drm->dev);
  392. drm_fb_helper_set_suspend(&drm->fbcon->helper, state);
  393. if (state != FBINFO_STATE_RUNNING)
  394. nouveau_fbcon_accel_save_disable(drm->dev);
  395. console_unlock();
  396. if (state == FBINFO_STATE_RUNNING) {
  397. nouveau_fbcon_hotplug_resume(drm->fbcon);
  398. pm_runtime_mark_last_busy(drm->dev->dev);
  399. pm_runtime_put_sync(drm->dev->dev);
  400. }
  401. }
  402. void
  403. nouveau_fbcon_set_suspend(struct drm_device *dev, int state)
  404. {
  405. struct nouveau_drm *drm = nouveau_drm(dev);
  406. if (!drm->fbcon)
  407. return;
  408. drm->fbcon_new_state = state;
  409. /* Since runtime resume can happen as a result of a sysfs operation,
  410. * it's possible we already have the console locked. So handle fbcon
  411. * init/deinit from a seperate work thread
  412. */
  413. schedule_work(&drm->fbcon_work);
  414. }
  415. void
  416. nouveau_fbcon_output_poll_changed(struct drm_device *dev)
  417. {
  418. struct nouveau_drm *drm = nouveau_drm(dev);
  419. struct nouveau_fbdev *fbcon = drm->fbcon;
  420. int ret;
  421. if (!fbcon)
  422. return;
  423. mutex_lock(&fbcon->hotplug_lock);
  424. ret = pm_runtime_get(dev->dev);
  425. if (ret == 1 || ret == -EACCES) {
  426. drm_fb_helper_hotplug_event(&fbcon->helper);
  427. pm_runtime_mark_last_busy(dev->dev);
  428. pm_runtime_put_autosuspend(dev->dev);
  429. } else if (ret == 0) {
  430. /* If the GPU was already in the process of suspending before
  431. * this event happened, then we can't block here as we'll
  432. * deadlock the runtime pmops since they wait for us to
  433. * finish. So, just defer this event for when we runtime
  434. * resume again. It will be handled by fbcon_work.
  435. */
  436. NV_DEBUG(drm, "fbcon HPD event deferred until runtime resume\n");
  437. fbcon->hotplug_waiting = true;
  438. pm_runtime_put_noidle(drm->dev->dev);
  439. } else {
  440. DRM_WARN("fbcon HPD event lost due to RPM failure: %d\n",
  441. ret);
  442. }
  443. mutex_unlock(&fbcon->hotplug_lock);
  444. }
  445. void
  446. nouveau_fbcon_hotplug_resume(struct nouveau_fbdev *fbcon)
  447. {
  448. struct nouveau_drm *drm;
  449. if (!fbcon)
  450. return;
  451. drm = nouveau_drm(fbcon->helper.dev);
  452. mutex_lock(&fbcon->hotplug_lock);
  453. if (fbcon->hotplug_waiting) {
  454. fbcon->hotplug_waiting = false;
  455. NV_DEBUG(drm, "Handling deferred fbcon HPD events\n");
  456. drm_fb_helper_hotplug_event(&fbcon->helper);
  457. }
  458. mutex_unlock(&fbcon->hotplug_lock);
  459. }
  460. int
  461. nouveau_fbcon_init(struct drm_device *dev)
  462. {
  463. struct nouveau_drm *drm = nouveau_drm(dev);
  464. struct nouveau_fbdev *fbcon;
  465. int preferred_bpp = nouveau_fbcon_bpp;
  466. int ret;
  467. if (!dev->mode_config.num_crtc ||
  468. (dev->pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
  469. return 0;
  470. fbcon = kzalloc(sizeof(struct nouveau_fbdev), GFP_KERNEL);
  471. if (!fbcon)
  472. return -ENOMEM;
  473. drm->fbcon = fbcon;
  474. INIT_WORK(&drm->fbcon_work, nouveau_fbcon_set_suspend_work);
  475. mutex_init(&fbcon->hotplug_lock);
  476. drm_fb_helper_prepare(dev, &fbcon->helper, &nouveau_fbcon_helper_funcs);
  477. ret = drm_fb_helper_init(dev, &fbcon->helper);
  478. if (ret)
  479. goto free;
  480. if (preferred_bpp != 8 && preferred_bpp != 16 && preferred_bpp != 32) {
  481. if (drm->client.device.info.ram_size <= 32 * 1024 * 1024)
  482. preferred_bpp = 8;
  483. else
  484. if (drm->client.device.info.ram_size <= 64 * 1024 * 1024)
  485. preferred_bpp = 16;
  486. else
  487. preferred_bpp = 32;
  488. }
  489. /* disable all the possible outputs/crtcs before entering KMS mode */
  490. if (!drm_drv_uses_atomic_modeset(dev))
  491. drm_helper_disable_unused_functions(dev);
  492. ret = drm_fb_helper_initial_config(&fbcon->helper, preferred_bpp);
  493. if (ret)
  494. goto fini;
  495. if (fbcon->helper.fbdev)
  496. fbcon->helper.fbdev->pixmap.buf_align = 4;
  497. return 0;
  498. fini:
  499. drm_fb_helper_fini(&fbcon->helper);
  500. free:
  501. kfree(fbcon);
  502. drm->fbcon = NULL;
  503. return ret;
  504. }
  505. void
  506. nouveau_fbcon_fini(struct drm_device *dev)
  507. {
  508. struct nouveau_drm *drm = nouveau_drm(dev);
  509. if (!drm->fbcon)
  510. return;
  511. nouveau_fbcon_accel_fini(dev);
  512. nouveau_fbcon_destroy(dev, drm->fbcon);
  513. kfree(drm->fbcon);
  514. drm->fbcon = NULL;
  515. }