nouveau_fbcon.c 16 KB

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