drm_fb_helper.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786
  1. /*
  2. * Copyright (c) 2006-2009 Red Hat Inc.
  3. * Copyright (c) 2006-2008 Intel Corporation
  4. * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
  5. *
  6. * DRM framebuffer helper functions
  7. *
  8. * Permission to use, copy, modify, distribute, and sell this software and its
  9. * documentation for any purpose is hereby granted without fee, provided that
  10. * the above copyright notice appear in all copies and that both that copyright
  11. * notice and this permission notice appear in supporting documentation, and
  12. * that the name of the copyright holders not be used in advertising or
  13. * publicity pertaining to distribution of the software without specific,
  14. * written prior permission. The copyright holders make no representations
  15. * about the suitability of this software for any purpose. It is provided "as
  16. * is" without express or implied warranty.
  17. *
  18. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  19. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  20. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  22. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  23. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  24. * OF THIS SOFTWARE.
  25. *
  26. * Authors:
  27. * Dave Airlie <airlied@linux.ie>
  28. * Jesse Barnes <jesse.barnes@intel.com>
  29. */
  30. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  31. #include <linux/kernel.h>
  32. #include <linux/sysrq.h>
  33. #include <linux/slab.h>
  34. #include <linux/fb.h>
  35. #include <linux/module.h>
  36. #include <drm/drmP.h>
  37. #include <drm/drm_crtc.h>
  38. #include <drm/drm_fb_helper.h>
  39. #include <drm/drm_crtc_helper.h>
  40. static LIST_HEAD(kernel_fb_helper_list);
  41. /**
  42. * DOC: fbdev helpers
  43. *
  44. * The fb helper functions are useful to provide an fbdev on top of a drm kernel
  45. * mode setting driver. They can be used mostly independently from the crtc
  46. * helper functions used by many drivers to implement the kernel mode setting
  47. * interfaces.
  48. *
  49. * Initialization is done as a four-step process with drm_fb_helper_prepare(),
  50. * drm_fb_helper_init(), drm_fb_helper_single_add_all_connectors() and
  51. * drm_fb_helper_initial_config(). Drivers with fancier requirements than the
  52. * default behaviour can override the third step with their own code.
  53. * Teardown is done with drm_fb_helper_fini().
  54. *
  55. * At runtime drivers should restore the fbdev console by calling
  56. * drm_fb_helper_restore_fbdev_mode() from their ->lastclose callback. They
  57. * should also notify the fb helper code from updates to the output
  58. * configuration by calling drm_fb_helper_hotplug_event(). For easier
  59. * integration with the output polling code in drm_crtc_helper.c the modeset
  60. * code provides a ->output_poll_changed callback.
  61. *
  62. * All other functions exported by the fb helper library can be used to
  63. * implement the fbdev driver interface by the driver.
  64. *
  65. * It is possible, though perhaps somewhat tricky, to implement race-free
  66. * hotplug detection using the fbdev helpers. The drm_fb_helper_prepare()
  67. * helper must be called first to initialize the minimum required to make
  68. * hotplug detection work. Drivers also need to make sure to properly set up
  69. * the dev->mode_config.funcs member. After calling drm_kms_helper_poll_init()
  70. * it is safe to enable interrupts and start processing hotplug events. At the
  71. * same time, drivers should initialize all modeset objects such as CRTCs,
  72. * encoders and connectors. To finish up the fbdev helper initialization, the
  73. * drm_fb_helper_init() function is called. To probe for all attached displays
  74. * and set up an initial configuration using the detected hardware, drivers
  75. * should call drm_fb_helper_single_add_all_connectors() followed by
  76. * drm_fb_helper_initial_config().
  77. */
  78. /**
  79. * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
  80. * emulation helper
  81. * @fb_helper: fbdev initialized with drm_fb_helper_init
  82. *
  83. * This functions adds all the available connectors for use with the given
  84. * fb_helper. This is a separate step to allow drivers to freely assign
  85. * connectors to the fbdev, e.g. if some are reserved for special purposes or
  86. * not adequate to be used for the fbcon.
  87. *
  88. * Since this is part of the initial setup before the fbdev is published, no
  89. * locking is required.
  90. */
  91. int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
  92. {
  93. struct drm_device *dev = fb_helper->dev;
  94. struct drm_connector *connector;
  95. int i;
  96. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  97. struct drm_fb_helper_connector *fb_helper_connector;
  98. fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
  99. if (!fb_helper_connector)
  100. goto fail;
  101. fb_helper_connector->connector = connector;
  102. fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
  103. }
  104. return 0;
  105. fail:
  106. for (i = 0; i < fb_helper->connector_count; i++) {
  107. kfree(fb_helper->connector_info[i]);
  108. fb_helper->connector_info[i] = NULL;
  109. }
  110. fb_helper->connector_count = 0;
  111. return -ENOMEM;
  112. }
  113. EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors);
  114. int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_connector *connector)
  115. {
  116. struct drm_fb_helper_connector **temp;
  117. struct drm_fb_helper_connector *fb_helper_connector;
  118. WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex));
  119. if (fb_helper->connector_count + 1 > fb_helper->connector_info_alloc_count) {
  120. temp = krealloc(fb_helper->connector_info, sizeof(struct drm_fb_helper_connector *) * (fb_helper->connector_count + 1), GFP_KERNEL);
  121. if (!temp)
  122. return -ENOMEM;
  123. fb_helper->connector_info_alloc_count = fb_helper->connector_count + 1;
  124. fb_helper->connector_info = temp;
  125. }
  126. fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
  127. if (!fb_helper_connector)
  128. return -ENOMEM;
  129. fb_helper_connector->connector = connector;
  130. fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
  131. return 0;
  132. }
  133. EXPORT_SYMBOL(drm_fb_helper_add_one_connector);
  134. int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
  135. struct drm_connector *connector)
  136. {
  137. struct drm_fb_helper_connector *fb_helper_connector;
  138. int i, j;
  139. WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex));
  140. for (i = 0; i < fb_helper->connector_count; i++) {
  141. if (fb_helper->connector_info[i]->connector == connector)
  142. break;
  143. }
  144. if (i == fb_helper->connector_count)
  145. return -EINVAL;
  146. fb_helper_connector = fb_helper->connector_info[i];
  147. for (j = i + 1; j < fb_helper->connector_count; j++) {
  148. fb_helper->connector_info[j - 1] = fb_helper->connector_info[j];
  149. }
  150. fb_helper->connector_count--;
  151. kfree(fb_helper_connector);
  152. return 0;
  153. }
  154. EXPORT_SYMBOL(drm_fb_helper_remove_one_connector);
  155. static void drm_fb_helper_save_lut_atomic(struct drm_crtc *crtc, struct drm_fb_helper *helper)
  156. {
  157. uint16_t *r_base, *g_base, *b_base;
  158. int i;
  159. if (helper->funcs->gamma_get == NULL)
  160. return;
  161. r_base = crtc->gamma_store;
  162. g_base = r_base + crtc->gamma_size;
  163. b_base = g_base + crtc->gamma_size;
  164. for (i = 0; i < crtc->gamma_size; i++)
  165. helper->funcs->gamma_get(crtc, &r_base[i], &g_base[i], &b_base[i], i);
  166. }
  167. static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc)
  168. {
  169. uint16_t *r_base, *g_base, *b_base;
  170. if (crtc->funcs->gamma_set == NULL)
  171. return;
  172. r_base = crtc->gamma_store;
  173. g_base = r_base + crtc->gamma_size;
  174. b_base = g_base + crtc->gamma_size;
  175. crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
  176. }
  177. /**
  178. * drm_fb_helper_debug_enter - implementation for ->fb_debug_enter
  179. * @info: fbdev registered by the helper
  180. */
  181. int drm_fb_helper_debug_enter(struct fb_info *info)
  182. {
  183. struct drm_fb_helper *helper = info->par;
  184. struct drm_crtc_helper_funcs *funcs;
  185. int i;
  186. list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
  187. for (i = 0; i < helper->crtc_count; i++) {
  188. struct drm_mode_set *mode_set =
  189. &helper->crtc_info[i].mode_set;
  190. if (!mode_set->crtc->enabled)
  191. continue;
  192. funcs = mode_set->crtc->helper_private;
  193. drm_fb_helper_save_lut_atomic(mode_set->crtc, helper);
  194. funcs->mode_set_base_atomic(mode_set->crtc,
  195. mode_set->fb,
  196. mode_set->x,
  197. mode_set->y,
  198. ENTER_ATOMIC_MODE_SET);
  199. }
  200. }
  201. return 0;
  202. }
  203. EXPORT_SYMBOL(drm_fb_helper_debug_enter);
  204. /* Find the real fb for a given fb helper CRTC */
  205. static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc)
  206. {
  207. struct drm_device *dev = crtc->dev;
  208. struct drm_crtc *c;
  209. list_for_each_entry(c, &dev->mode_config.crtc_list, head) {
  210. if (crtc->base.id == c->base.id)
  211. return c->primary->fb;
  212. }
  213. return NULL;
  214. }
  215. /**
  216. * drm_fb_helper_debug_leave - implementation for ->fb_debug_leave
  217. * @info: fbdev registered by the helper
  218. */
  219. int drm_fb_helper_debug_leave(struct fb_info *info)
  220. {
  221. struct drm_fb_helper *helper = info->par;
  222. struct drm_crtc *crtc;
  223. struct drm_crtc_helper_funcs *funcs;
  224. struct drm_framebuffer *fb;
  225. int i;
  226. for (i = 0; i < helper->crtc_count; i++) {
  227. struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set;
  228. crtc = mode_set->crtc;
  229. funcs = crtc->helper_private;
  230. fb = drm_mode_config_fb(crtc);
  231. if (!crtc->enabled)
  232. continue;
  233. if (!fb) {
  234. DRM_ERROR("no fb to restore??\n");
  235. continue;
  236. }
  237. drm_fb_helper_restore_lut_atomic(mode_set->crtc);
  238. funcs->mode_set_base_atomic(mode_set->crtc, fb, crtc->x,
  239. crtc->y, LEAVE_ATOMIC_MODE_SET);
  240. }
  241. return 0;
  242. }
  243. EXPORT_SYMBOL(drm_fb_helper_debug_leave);
  244. static bool restore_fbdev_mode(struct drm_fb_helper *fb_helper)
  245. {
  246. struct drm_device *dev = fb_helper->dev;
  247. struct drm_plane *plane;
  248. bool error = false;
  249. int i;
  250. drm_warn_on_modeset_not_all_locked(dev);
  251. list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
  252. if (plane->type != DRM_PLANE_TYPE_PRIMARY)
  253. drm_plane_force_disable(plane);
  254. if (dev->mode_config.rotation_property) {
  255. drm_mode_plane_set_obj_prop(plane,
  256. dev->mode_config.rotation_property,
  257. BIT(DRM_ROTATE_0));
  258. }
  259. }
  260. for (i = 0; i < fb_helper->crtc_count; i++) {
  261. struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set;
  262. struct drm_crtc *crtc = mode_set->crtc;
  263. int ret;
  264. if (crtc->funcs->cursor_set) {
  265. ret = crtc->funcs->cursor_set(crtc, NULL, 0, 0, 0);
  266. if (ret)
  267. error = true;
  268. }
  269. ret = drm_mode_set_config_internal(mode_set);
  270. if (ret)
  271. error = true;
  272. }
  273. return error;
  274. }
  275. /**
  276. * drm_fb_helper_restore_fbdev_mode - restore fbdev configuration
  277. * @fb_helper: fbcon to restore
  278. *
  279. * This should be called from driver's drm ->lastclose callback
  280. * when implementing an fbcon on top of kms using this helper. This ensures that
  281. * the user isn't greeted with a black screen when e.g. X dies.
  282. *
  283. * Use this variant if you need to bypass locking (panic), or already
  284. * hold all modeset locks. Otherwise use drm_fb_helper_restore_fbdev_mode_unlocked()
  285. */
  286. static bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper)
  287. {
  288. return restore_fbdev_mode(fb_helper);
  289. }
  290. /**
  291. * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration
  292. * @fb_helper: fbcon to restore
  293. *
  294. * This should be called from driver's drm ->lastclose callback
  295. * when implementing an fbcon on top of kms using this helper. This ensures that
  296. * the user isn't greeted with a black screen when e.g. X dies.
  297. */
  298. bool drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
  299. {
  300. struct drm_device *dev = fb_helper->dev;
  301. bool ret;
  302. bool do_delayed = false;
  303. drm_modeset_lock_all(dev);
  304. ret = restore_fbdev_mode(fb_helper);
  305. do_delayed = fb_helper->delayed_hotplug;
  306. if (do_delayed)
  307. fb_helper->delayed_hotplug = false;
  308. drm_modeset_unlock_all(dev);
  309. if (do_delayed)
  310. drm_fb_helper_hotplug_event(fb_helper);
  311. return ret;
  312. }
  313. EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode_unlocked);
  314. /*
  315. * restore fbcon display for all kms driver's using this helper, used for sysrq
  316. * and panic handling.
  317. */
  318. static bool drm_fb_helper_force_kernel_mode(void)
  319. {
  320. bool ret, error = false;
  321. struct drm_fb_helper *helper;
  322. if (list_empty(&kernel_fb_helper_list))
  323. return false;
  324. list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
  325. struct drm_device *dev = helper->dev;
  326. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  327. continue;
  328. /*
  329. * NOTE: Use trylock mode to avoid deadlocks and sleeping in
  330. * panic context.
  331. */
  332. if (__drm_modeset_lock_all(dev, true) != 0) {
  333. error = true;
  334. continue;
  335. }
  336. ret = drm_fb_helper_restore_fbdev_mode(helper);
  337. if (ret)
  338. error = true;
  339. drm_modeset_unlock_all(dev);
  340. }
  341. return error;
  342. }
  343. static int drm_fb_helper_panic(struct notifier_block *n, unsigned long ununsed,
  344. void *panic_str)
  345. {
  346. /*
  347. * It's a waste of time and effort to switch back to text console
  348. * if the kernel should reboot before panic messages can be seen.
  349. */
  350. if (panic_timeout < 0)
  351. return 0;
  352. pr_err("panic occurred, switching back to text console\n");
  353. return drm_fb_helper_force_kernel_mode();
  354. }
  355. static struct notifier_block paniced = {
  356. .notifier_call = drm_fb_helper_panic,
  357. };
  358. static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper)
  359. {
  360. struct drm_device *dev = fb_helper->dev;
  361. struct drm_crtc *crtc;
  362. int bound = 0, crtcs_bound = 0;
  363. /* Sometimes user space wants everything disabled, so don't steal the
  364. * display if there's a master. */
  365. if (dev->primary->master)
  366. return false;
  367. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  368. if (crtc->primary->fb)
  369. crtcs_bound++;
  370. if (crtc->primary->fb == fb_helper->fb)
  371. bound++;
  372. }
  373. if (bound < crtcs_bound)
  374. return false;
  375. return true;
  376. }
  377. #ifdef CONFIG_MAGIC_SYSRQ
  378. static void drm_fb_helper_restore_work_fn(struct work_struct *ignored)
  379. {
  380. bool ret;
  381. ret = drm_fb_helper_force_kernel_mode();
  382. if (ret == true)
  383. DRM_ERROR("Failed to restore crtc configuration\n");
  384. }
  385. static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn);
  386. static void drm_fb_helper_sysrq(int dummy1)
  387. {
  388. schedule_work(&drm_fb_helper_restore_work);
  389. }
  390. static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = {
  391. .handler = drm_fb_helper_sysrq,
  392. .help_msg = "force-fb(V)",
  393. .action_msg = "Restore framebuffer console",
  394. };
  395. #else
  396. static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { };
  397. #endif
  398. static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
  399. {
  400. struct drm_fb_helper *fb_helper = info->par;
  401. struct drm_device *dev = fb_helper->dev;
  402. struct drm_crtc *crtc;
  403. struct drm_connector *connector;
  404. int i, j;
  405. /*
  406. * fbdev->blank can be called from irq context in case of a panic.
  407. * Since we already have our own special panic handler which will
  408. * restore the fbdev console mode completely, just bail out early.
  409. */
  410. if (oops_in_progress)
  411. return;
  412. /*
  413. * For each CRTC in this fb, turn the connectors on/off.
  414. */
  415. drm_modeset_lock_all(dev);
  416. if (!drm_fb_helper_is_bound(fb_helper)) {
  417. drm_modeset_unlock_all(dev);
  418. return;
  419. }
  420. for (i = 0; i < fb_helper->crtc_count; i++) {
  421. crtc = fb_helper->crtc_info[i].mode_set.crtc;
  422. if (!crtc->enabled)
  423. continue;
  424. /* Walk the connectors & encoders on this fb turning them on/off */
  425. for (j = 0; j < fb_helper->connector_count; j++) {
  426. connector = fb_helper->connector_info[j]->connector;
  427. connector->funcs->dpms(connector, dpms_mode);
  428. drm_object_property_set_value(&connector->base,
  429. dev->mode_config.dpms_property, dpms_mode);
  430. }
  431. }
  432. drm_modeset_unlock_all(dev);
  433. }
  434. /**
  435. * drm_fb_helper_blank - implementation for ->fb_blank
  436. * @blank: desired blanking state
  437. * @info: fbdev registered by the helper
  438. */
  439. int drm_fb_helper_blank(int blank, struct fb_info *info)
  440. {
  441. switch (blank) {
  442. /* Display: On; HSync: On, VSync: On */
  443. case FB_BLANK_UNBLANK:
  444. drm_fb_helper_dpms(info, DRM_MODE_DPMS_ON);
  445. break;
  446. /* Display: Off; HSync: On, VSync: On */
  447. case FB_BLANK_NORMAL:
  448. drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
  449. break;
  450. /* Display: Off; HSync: Off, VSync: On */
  451. case FB_BLANK_HSYNC_SUSPEND:
  452. drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
  453. break;
  454. /* Display: Off; HSync: On, VSync: Off */
  455. case FB_BLANK_VSYNC_SUSPEND:
  456. drm_fb_helper_dpms(info, DRM_MODE_DPMS_SUSPEND);
  457. break;
  458. /* Display: Off; HSync: Off, VSync: Off */
  459. case FB_BLANK_POWERDOWN:
  460. drm_fb_helper_dpms(info, DRM_MODE_DPMS_OFF);
  461. break;
  462. }
  463. return 0;
  464. }
  465. EXPORT_SYMBOL(drm_fb_helper_blank);
  466. static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
  467. {
  468. int i;
  469. for (i = 0; i < helper->connector_count; i++)
  470. kfree(helper->connector_info[i]);
  471. kfree(helper->connector_info);
  472. for (i = 0; i < helper->crtc_count; i++) {
  473. kfree(helper->crtc_info[i].mode_set.connectors);
  474. if (helper->crtc_info[i].mode_set.mode)
  475. drm_mode_destroy(helper->dev, helper->crtc_info[i].mode_set.mode);
  476. }
  477. kfree(helper->crtc_info);
  478. }
  479. /**
  480. * drm_fb_helper_prepare - setup a drm_fb_helper structure
  481. * @dev: DRM device
  482. * @helper: driver-allocated fbdev helper structure to set up
  483. * @funcs: pointer to structure of functions associate with this helper
  484. *
  485. * Sets up the bare minimum to make the framebuffer helper usable. This is
  486. * useful to implement race-free initialization of the polling helpers.
  487. */
  488. void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
  489. const struct drm_fb_helper_funcs *funcs)
  490. {
  491. INIT_LIST_HEAD(&helper->kernel_fb_list);
  492. helper->funcs = funcs;
  493. helper->dev = dev;
  494. }
  495. EXPORT_SYMBOL(drm_fb_helper_prepare);
  496. /**
  497. * drm_fb_helper_init - initialize a drm_fb_helper structure
  498. * @dev: drm device
  499. * @fb_helper: driver-allocated fbdev helper structure to initialize
  500. * @crtc_count: maximum number of crtcs to support in this fbdev emulation
  501. * @max_conn_count: max connector count
  502. *
  503. * This allocates the structures for the fbdev helper with the given limits.
  504. * Note that this won't yet touch the hardware (through the driver interfaces)
  505. * nor register the fbdev. This is only done in drm_fb_helper_initial_config()
  506. * to allow driver writes more control over the exact init sequence.
  507. *
  508. * Drivers must call drm_fb_helper_prepare() before calling this function.
  509. *
  510. * RETURNS:
  511. * Zero if everything went ok, nonzero otherwise.
  512. */
  513. int drm_fb_helper_init(struct drm_device *dev,
  514. struct drm_fb_helper *fb_helper,
  515. int crtc_count, int max_conn_count)
  516. {
  517. struct drm_crtc *crtc;
  518. int i;
  519. if (!max_conn_count)
  520. return -EINVAL;
  521. fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL);
  522. if (!fb_helper->crtc_info)
  523. return -ENOMEM;
  524. fb_helper->crtc_count = crtc_count;
  525. fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL);
  526. if (!fb_helper->connector_info) {
  527. kfree(fb_helper->crtc_info);
  528. return -ENOMEM;
  529. }
  530. fb_helper->connector_info_alloc_count = dev->mode_config.num_connector;
  531. fb_helper->connector_count = 0;
  532. for (i = 0; i < crtc_count; i++) {
  533. fb_helper->crtc_info[i].mode_set.connectors =
  534. kcalloc(max_conn_count,
  535. sizeof(struct drm_connector *),
  536. GFP_KERNEL);
  537. if (!fb_helper->crtc_info[i].mode_set.connectors)
  538. goto out_free;
  539. fb_helper->crtc_info[i].mode_set.num_connectors = 0;
  540. }
  541. i = 0;
  542. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  543. fb_helper->crtc_info[i].mode_set.crtc = crtc;
  544. i++;
  545. }
  546. return 0;
  547. out_free:
  548. drm_fb_helper_crtc_free(fb_helper);
  549. return -ENOMEM;
  550. }
  551. EXPORT_SYMBOL(drm_fb_helper_init);
  552. void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
  553. {
  554. if (!list_empty(&fb_helper->kernel_fb_list)) {
  555. list_del(&fb_helper->kernel_fb_list);
  556. if (list_empty(&kernel_fb_helper_list)) {
  557. pr_info("drm: unregistered panic notifier\n");
  558. atomic_notifier_chain_unregister(&panic_notifier_list,
  559. &paniced);
  560. unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
  561. }
  562. }
  563. drm_fb_helper_crtc_free(fb_helper);
  564. }
  565. EXPORT_SYMBOL(drm_fb_helper_fini);
  566. static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
  567. u16 blue, u16 regno, struct fb_info *info)
  568. {
  569. struct drm_fb_helper *fb_helper = info->par;
  570. struct drm_framebuffer *fb = fb_helper->fb;
  571. int pindex;
  572. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  573. u32 *palette;
  574. u32 value;
  575. /* place color in psuedopalette */
  576. if (regno > 16)
  577. return -EINVAL;
  578. palette = (u32 *)info->pseudo_palette;
  579. red >>= (16 - info->var.red.length);
  580. green >>= (16 - info->var.green.length);
  581. blue >>= (16 - info->var.blue.length);
  582. value = (red << info->var.red.offset) |
  583. (green << info->var.green.offset) |
  584. (blue << info->var.blue.offset);
  585. if (info->var.transp.length > 0) {
  586. u32 mask = (1 << info->var.transp.length) - 1;
  587. mask <<= info->var.transp.offset;
  588. value |= mask;
  589. }
  590. palette[regno] = value;
  591. return 0;
  592. }
  593. /*
  594. * The driver really shouldn't advertise pseudo/directcolor
  595. * visuals if it can't deal with the palette.
  596. */
  597. if (WARN_ON(!fb_helper->funcs->gamma_set ||
  598. !fb_helper->funcs->gamma_get))
  599. return -EINVAL;
  600. pindex = regno;
  601. if (fb->bits_per_pixel == 16) {
  602. pindex = regno << 3;
  603. if (fb->depth == 16 && regno > 63)
  604. return -EINVAL;
  605. if (fb->depth == 15 && regno > 31)
  606. return -EINVAL;
  607. if (fb->depth == 16) {
  608. u16 r, g, b;
  609. int i;
  610. if (regno < 32) {
  611. for (i = 0; i < 8; i++)
  612. fb_helper->funcs->gamma_set(crtc, red,
  613. green, blue, pindex + i);
  614. }
  615. fb_helper->funcs->gamma_get(crtc, &r,
  616. &g, &b,
  617. pindex >> 1);
  618. for (i = 0; i < 4; i++)
  619. fb_helper->funcs->gamma_set(crtc, r,
  620. green, b,
  621. (pindex >> 1) + i);
  622. }
  623. }
  624. if (fb->depth != 16)
  625. fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex);
  626. return 0;
  627. }
  628. /**
  629. * drm_fb_helper_setcmap - implementation for ->fb_setcmap
  630. * @cmap: cmap to set
  631. * @info: fbdev registered by the helper
  632. */
  633. int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
  634. {
  635. struct drm_fb_helper *fb_helper = info->par;
  636. struct drm_device *dev = fb_helper->dev;
  637. struct drm_crtc_helper_funcs *crtc_funcs;
  638. u16 *red, *green, *blue, *transp;
  639. struct drm_crtc *crtc;
  640. int i, j, rc = 0;
  641. int start;
  642. if (__drm_modeset_lock_all(dev, !!oops_in_progress)) {
  643. return -EBUSY;
  644. }
  645. if (!drm_fb_helper_is_bound(fb_helper)) {
  646. drm_modeset_unlock_all(dev);
  647. return -EBUSY;
  648. }
  649. for (i = 0; i < fb_helper->crtc_count; i++) {
  650. crtc = fb_helper->crtc_info[i].mode_set.crtc;
  651. crtc_funcs = crtc->helper_private;
  652. red = cmap->red;
  653. green = cmap->green;
  654. blue = cmap->blue;
  655. transp = cmap->transp;
  656. start = cmap->start;
  657. for (j = 0; j < cmap->len; j++) {
  658. u16 hred, hgreen, hblue, htransp = 0xffff;
  659. hred = *red++;
  660. hgreen = *green++;
  661. hblue = *blue++;
  662. if (transp)
  663. htransp = *transp++;
  664. rc = setcolreg(crtc, hred, hgreen, hblue, start++, info);
  665. if (rc)
  666. goto out;
  667. }
  668. if (crtc_funcs->load_lut)
  669. crtc_funcs->load_lut(crtc);
  670. }
  671. out:
  672. drm_modeset_unlock_all(dev);
  673. return rc;
  674. }
  675. EXPORT_SYMBOL(drm_fb_helper_setcmap);
  676. /**
  677. * drm_fb_helper_check_var - implementation for ->fb_check_var
  678. * @var: screeninfo to check
  679. * @info: fbdev registered by the helper
  680. */
  681. int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
  682. struct fb_info *info)
  683. {
  684. struct drm_fb_helper *fb_helper = info->par;
  685. struct drm_framebuffer *fb = fb_helper->fb;
  686. int depth;
  687. if (var->pixclock != 0 || in_dbg_master())
  688. return -EINVAL;
  689. /* Need to resize the fb object !!! */
  690. if (var->bits_per_pixel > fb->bits_per_pixel ||
  691. var->xres > fb->width || var->yres > fb->height ||
  692. var->xres_virtual > fb->width || var->yres_virtual > fb->height) {
  693. DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
  694. "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
  695. var->xres, var->yres, var->bits_per_pixel,
  696. var->xres_virtual, var->yres_virtual,
  697. fb->width, fb->height, fb->bits_per_pixel);
  698. return -EINVAL;
  699. }
  700. switch (var->bits_per_pixel) {
  701. case 16:
  702. depth = (var->green.length == 6) ? 16 : 15;
  703. break;
  704. case 32:
  705. depth = (var->transp.length > 0) ? 32 : 24;
  706. break;
  707. default:
  708. depth = var->bits_per_pixel;
  709. break;
  710. }
  711. switch (depth) {
  712. case 8:
  713. var->red.offset = 0;
  714. var->green.offset = 0;
  715. var->blue.offset = 0;
  716. var->red.length = 8;
  717. var->green.length = 8;
  718. var->blue.length = 8;
  719. var->transp.length = 0;
  720. var->transp.offset = 0;
  721. break;
  722. case 15:
  723. var->red.offset = 10;
  724. var->green.offset = 5;
  725. var->blue.offset = 0;
  726. var->red.length = 5;
  727. var->green.length = 5;
  728. var->blue.length = 5;
  729. var->transp.length = 1;
  730. var->transp.offset = 15;
  731. break;
  732. case 16:
  733. var->red.offset = 11;
  734. var->green.offset = 5;
  735. var->blue.offset = 0;
  736. var->red.length = 5;
  737. var->green.length = 6;
  738. var->blue.length = 5;
  739. var->transp.length = 0;
  740. var->transp.offset = 0;
  741. break;
  742. case 24:
  743. var->red.offset = 16;
  744. var->green.offset = 8;
  745. var->blue.offset = 0;
  746. var->red.length = 8;
  747. var->green.length = 8;
  748. var->blue.length = 8;
  749. var->transp.length = 0;
  750. var->transp.offset = 0;
  751. break;
  752. case 32:
  753. var->red.offset = 16;
  754. var->green.offset = 8;
  755. var->blue.offset = 0;
  756. var->red.length = 8;
  757. var->green.length = 8;
  758. var->blue.length = 8;
  759. var->transp.length = 8;
  760. var->transp.offset = 24;
  761. break;
  762. default:
  763. return -EINVAL;
  764. }
  765. return 0;
  766. }
  767. EXPORT_SYMBOL(drm_fb_helper_check_var);
  768. /**
  769. * drm_fb_helper_set_par - implementation for ->fb_set_par
  770. * @info: fbdev registered by the helper
  771. *
  772. * This will let fbcon do the mode init and is called at initialization time by
  773. * the fbdev core when registering the driver, and later on through the hotplug
  774. * callback.
  775. */
  776. int drm_fb_helper_set_par(struct fb_info *info)
  777. {
  778. struct drm_fb_helper *fb_helper = info->par;
  779. struct fb_var_screeninfo *var = &info->var;
  780. if (var->pixclock != 0) {
  781. DRM_ERROR("PIXEL CLOCK SET\n");
  782. return -EINVAL;
  783. }
  784. drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper);
  785. return 0;
  786. }
  787. EXPORT_SYMBOL(drm_fb_helper_set_par);
  788. /**
  789. * drm_fb_helper_pan_display - implementation for ->fb_pan_display
  790. * @var: updated screen information
  791. * @info: fbdev registered by the helper
  792. */
  793. int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
  794. struct fb_info *info)
  795. {
  796. struct drm_fb_helper *fb_helper = info->par;
  797. struct drm_device *dev = fb_helper->dev;
  798. struct drm_mode_set *modeset;
  799. int ret = 0;
  800. int i;
  801. if (__drm_modeset_lock_all(dev, !!oops_in_progress)) {
  802. return -EBUSY;
  803. }
  804. if (!drm_fb_helper_is_bound(fb_helper)) {
  805. drm_modeset_unlock_all(dev);
  806. return -EBUSY;
  807. }
  808. for (i = 0; i < fb_helper->crtc_count; i++) {
  809. modeset = &fb_helper->crtc_info[i].mode_set;
  810. modeset->x = var->xoffset;
  811. modeset->y = var->yoffset;
  812. if (modeset->num_connectors) {
  813. ret = drm_mode_set_config_internal(modeset);
  814. if (!ret) {
  815. info->var.xoffset = var->xoffset;
  816. info->var.yoffset = var->yoffset;
  817. }
  818. }
  819. }
  820. drm_modeset_unlock_all(dev);
  821. return ret;
  822. }
  823. EXPORT_SYMBOL(drm_fb_helper_pan_display);
  824. /*
  825. * Allocates the backing storage and sets up the fbdev info structure through
  826. * the ->fb_probe callback and then registers the fbdev and sets up the panic
  827. * notifier.
  828. */
  829. static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
  830. int preferred_bpp)
  831. {
  832. int ret = 0;
  833. int crtc_count = 0;
  834. int i;
  835. struct fb_info *info;
  836. struct drm_fb_helper_surface_size sizes;
  837. int gamma_size = 0;
  838. memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
  839. sizes.surface_depth = 24;
  840. sizes.surface_bpp = 32;
  841. sizes.fb_width = (unsigned)-1;
  842. sizes.fb_height = (unsigned)-1;
  843. /* if driver picks 8 or 16 by default use that
  844. for both depth/bpp */
  845. if (preferred_bpp != sizes.surface_bpp)
  846. sizes.surface_depth = sizes.surface_bpp = preferred_bpp;
  847. /* first up get a count of crtcs now in use and new min/maxes width/heights */
  848. for (i = 0; i < fb_helper->connector_count; i++) {
  849. struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i];
  850. struct drm_cmdline_mode *cmdline_mode;
  851. cmdline_mode = &fb_helper_conn->connector->cmdline_mode;
  852. if (cmdline_mode->bpp_specified) {
  853. switch (cmdline_mode->bpp) {
  854. case 8:
  855. sizes.surface_depth = sizes.surface_bpp = 8;
  856. break;
  857. case 15:
  858. sizes.surface_depth = 15;
  859. sizes.surface_bpp = 16;
  860. break;
  861. case 16:
  862. sizes.surface_depth = sizes.surface_bpp = 16;
  863. break;
  864. case 24:
  865. sizes.surface_depth = sizes.surface_bpp = 24;
  866. break;
  867. case 32:
  868. sizes.surface_depth = 24;
  869. sizes.surface_bpp = 32;
  870. break;
  871. }
  872. break;
  873. }
  874. }
  875. crtc_count = 0;
  876. for (i = 0; i < fb_helper->crtc_count; i++) {
  877. struct drm_display_mode *desired_mode;
  878. int x, y;
  879. desired_mode = fb_helper->crtc_info[i].desired_mode;
  880. x = fb_helper->crtc_info[i].x;
  881. y = fb_helper->crtc_info[i].y;
  882. if (desired_mode) {
  883. if (gamma_size == 0)
  884. gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size;
  885. if (desired_mode->hdisplay + x < sizes.fb_width)
  886. sizes.fb_width = desired_mode->hdisplay + x;
  887. if (desired_mode->vdisplay + y < sizes.fb_height)
  888. sizes.fb_height = desired_mode->vdisplay + y;
  889. if (desired_mode->hdisplay + x > sizes.surface_width)
  890. sizes.surface_width = desired_mode->hdisplay + x;
  891. if (desired_mode->vdisplay + y > sizes.surface_height)
  892. sizes.surface_height = desired_mode->vdisplay + y;
  893. crtc_count++;
  894. }
  895. }
  896. if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) {
  897. /* hmm everyone went away - assume VGA cable just fell out
  898. and will come back later. */
  899. DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
  900. sizes.fb_width = sizes.surface_width = 1024;
  901. sizes.fb_height = sizes.surface_height = 768;
  902. }
  903. /* push down into drivers */
  904. ret = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
  905. if (ret < 0)
  906. return ret;
  907. info = fb_helper->fbdev;
  908. /*
  909. * Set the fb pointer - usually drm_setup_crtcs does this for hotplug
  910. * events, but at init time drm_setup_crtcs needs to be called before
  911. * the fb is allocated (since we need to figure out the desired size of
  912. * the fb before we can allocate it ...). Hence we need to fix things up
  913. * here again.
  914. */
  915. for (i = 0; i < fb_helper->crtc_count; i++)
  916. if (fb_helper->crtc_info[i].mode_set.num_connectors)
  917. fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
  918. info->var.pixclock = 0;
  919. if (register_framebuffer(info) < 0)
  920. return -EINVAL;
  921. dev_info(fb_helper->dev->dev, "fb%d: %s frame buffer device\n",
  922. info->node, info->fix.id);
  923. /* Switch back to kernel console on panic */
  924. /* multi card linked list maybe */
  925. if (list_empty(&kernel_fb_helper_list)) {
  926. dev_info(fb_helper->dev->dev, "registered panic notifier\n");
  927. atomic_notifier_chain_register(&panic_notifier_list,
  928. &paniced);
  929. register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
  930. }
  931. list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
  932. return 0;
  933. }
  934. /**
  935. * drm_fb_helper_fill_fix - initializes fixed fbdev information
  936. * @info: fbdev registered by the helper
  937. * @pitch: desired pitch
  938. * @depth: desired depth
  939. *
  940. * Helper to fill in the fixed fbdev information useful for a non-accelerated
  941. * fbdev emulations. Drivers which support acceleration methods which impose
  942. * additional constraints need to set up their own limits.
  943. *
  944. * Drivers should call this (or their equivalent setup code) from their
  945. * ->fb_probe callback.
  946. */
  947. void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
  948. uint32_t depth)
  949. {
  950. info->fix.type = FB_TYPE_PACKED_PIXELS;
  951. info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR :
  952. FB_VISUAL_TRUECOLOR;
  953. info->fix.mmio_start = 0;
  954. info->fix.mmio_len = 0;
  955. info->fix.type_aux = 0;
  956. info->fix.xpanstep = 1; /* doing it in hw */
  957. info->fix.ypanstep = 1; /* doing it in hw */
  958. info->fix.ywrapstep = 0;
  959. info->fix.accel = FB_ACCEL_NONE;
  960. info->fix.line_length = pitch;
  961. return;
  962. }
  963. EXPORT_SYMBOL(drm_fb_helper_fill_fix);
  964. /**
  965. * drm_fb_helper_fill_var - initalizes variable fbdev information
  966. * @info: fbdev instance to set up
  967. * @fb_helper: fb helper instance to use as template
  968. * @fb_width: desired fb width
  969. * @fb_height: desired fb height
  970. *
  971. * Sets up the variable fbdev metainformation from the given fb helper instance
  972. * and the drm framebuffer allocated in fb_helper->fb.
  973. *
  974. * Drivers should call this (or their equivalent setup code) from their
  975. * ->fb_probe callback after having allocated the fbdev backing
  976. * storage framebuffer.
  977. */
  978. void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
  979. uint32_t fb_width, uint32_t fb_height)
  980. {
  981. struct drm_framebuffer *fb = fb_helper->fb;
  982. info->pseudo_palette = fb_helper->pseudo_palette;
  983. info->var.xres_virtual = fb->width;
  984. info->var.yres_virtual = fb->height;
  985. info->var.bits_per_pixel = fb->bits_per_pixel;
  986. info->var.accel_flags = FB_ACCELF_TEXT;
  987. info->var.xoffset = 0;
  988. info->var.yoffset = 0;
  989. info->var.activate = FB_ACTIVATE_NOW;
  990. info->var.height = -1;
  991. info->var.width = -1;
  992. switch (fb->depth) {
  993. case 8:
  994. info->var.red.offset = 0;
  995. info->var.green.offset = 0;
  996. info->var.blue.offset = 0;
  997. info->var.red.length = 8; /* 8bit DAC */
  998. info->var.green.length = 8;
  999. info->var.blue.length = 8;
  1000. info->var.transp.offset = 0;
  1001. info->var.transp.length = 0;
  1002. break;
  1003. case 15:
  1004. info->var.red.offset = 10;
  1005. info->var.green.offset = 5;
  1006. info->var.blue.offset = 0;
  1007. info->var.red.length = 5;
  1008. info->var.green.length = 5;
  1009. info->var.blue.length = 5;
  1010. info->var.transp.offset = 15;
  1011. info->var.transp.length = 1;
  1012. break;
  1013. case 16:
  1014. info->var.red.offset = 11;
  1015. info->var.green.offset = 5;
  1016. info->var.blue.offset = 0;
  1017. info->var.red.length = 5;
  1018. info->var.green.length = 6;
  1019. info->var.blue.length = 5;
  1020. info->var.transp.offset = 0;
  1021. break;
  1022. case 24:
  1023. info->var.red.offset = 16;
  1024. info->var.green.offset = 8;
  1025. info->var.blue.offset = 0;
  1026. info->var.red.length = 8;
  1027. info->var.green.length = 8;
  1028. info->var.blue.length = 8;
  1029. info->var.transp.offset = 0;
  1030. info->var.transp.length = 0;
  1031. break;
  1032. case 32:
  1033. info->var.red.offset = 16;
  1034. info->var.green.offset = 8;
  1035. info->var.blue.offset = 0;
  1036. info->var.red.length = 8;
  1037. info->var.green.length = 8;
  1038. info->var.blue.length = 8;
  1039. info->var.transp.offset = 24;
  1040. info->var.transp.length = 8;
  1041. break;
  1042. default:
  1043. break;
  1044. }
  1045. info->var.xres = fb_width;
  1046. info->var.yres = fb_height;
  1047. }
  1048. EXPORT_SYMBOL(drm_fb_helper_fill_var);
  1049. static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper,
  1050. uint32_t maxX,
  1051. uint32_t maxY)
  1052. {
  1053. struct drm_connector *connector;
  1054. int count = 0;
  1055. int i;
  1056. for (i = 0; i < fb_helper->connector_count; i++) {
  1057. connector = fb_helper->connector_info[i]->connector;
  1058. count += connector->funcs->fill_modes(connector, maxX, maxY);
  1059. }
  1060. return count;
  1061. }
  1062. struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height)
  1063. {
  1064. struct drm_display_mode *mode;
  1065. list_for_each_entry(mode, &fb_connector->connector->modes, head) {
  1066. if (mode->hdisplay > width ||
  1067. mode->vdisplay > height)
  1068. continue;
  1069. if (mode->type & DRM_MODE_TYPE_PREFERRED)
  1070. return mode;
  1071. }
  1072. return NULL;
  1073. }
  1074. EXPORT_SYMBOL(drm_has_preferred_mode);
  1075. static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector)
  1076. {
  1077. return fb_connector->connector->cmdline_mode.specified;
  1078. }
  1079. struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
  1080. int width, int height)
  1081. {
  1082. struct drm_cmdline_mode *cmdline_mode;
  1083. struct drm_display_mode *mode = NULL;
  1084. bool prefer_non_interlace;
  1085. cmdline_mode = &fb_helper_conn->connector->cmdline_mode;
  1086. if (cmdline_mode->specified == false)
  1087. return mode;
  1088. /* attempt to find a matching mode in the list of modes
  1089. * we have gotten so far, if not add a CVT mode that conforms
  1090. */
  1091. if (cmdline_mode->rb || cmdline_mode->margins)
  1092. goto create_mode;
  1093. prefer_non_interlace = !cmdline_mode->interlace;
  1094. again:
  1095. list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
  1096. /* check width/height */
  1097. if (mode->hdisplay != cmdline_mode->xres ||
  1098. mode->vdisplay != cmdline_mode->yres)
  1099. continue;
  1100. if (cmdline_mode->refresh_specified) {
  1101. if (mode->vrefresh != cmdline_mode->refresh)
  1102. continue;
  1103. }
  1104. if (cmdline_mode->interlace) {
  1105. if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
  1106. continue;
  1107. } else if (prefer_non_interlace) {
  1108. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1109. continue;
  1110. }
  1111. return mode;
  1112. }
  1113. if (prefer_non_interlace) {
  1114. prefer_non_interlace = false;
  1115. goto again;
  1116. }
  1117. create_mode:
  1118. mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev,
  1119. cmdline_mode);
  1120. list_add(&mode->head, &fb_helper_conn->connector->modes);
  1121. return mode;
  1122. }
  1123. EXPORT_SYMBOL(drm_pick_cmdline_mode);
  1124. static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
  1125. {
  1126. bool enable;
  1127. if (strict)
  1128. enable = connector->status == connector_status_connected;
  1129. else
  1130. enable = connector->status != connector_status_disconnected;
  1131. return enable;
  1132. }
  1133. static void drm_enable_connectors(struct drm_fb_helper *fb_helper,
  1134. bool *enabled)
  1135. {
  1136. bool any_enabled = false;
  1137. struct drm_connector *connector;
  1138. int i = 0;
  1139. for (i = 0; i < fb_helper->connector_count; i++) {
  1140. connector = fb_helper->connector_info[i]->connector;
  1141. enabled[i] = drm_connector_enabled(connector, true);
  1142. DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
  1143. enabled[i] ? "yes" : "no");
  1144. any_enabled |= enabled[i];
  1145. }
  1146. if (any_enabled)
  1147. return;
  1148. for (i = 0; i < fb_helper->connector_count; i++) {
  1149. connector = fb_helper->connector_info[i]->connector;
  1150. enabled[i] = drm_connector_enabled(connector, false);
  1151. }
  1152. }
  1153. static bool drm_target_cloned(struct drm_fb_helper *fb_helper,
  1154. struct drm_display_mode **modes,
  1155. struct drm_fb_offset *offsets,
  1156. bool *enabled, int width, int height)
  1157. {
  1158. int count, i, j;
  1159. bool can_clone = false;
  1160. struct drm_fb_helper_connector *fb_helper_conn;
  1161. struct drm_display_mode *dmt_mode, *mode;
  1162. /* only contemplate cloning in the single crtc case */
  1163. if (fb_helper->crtc_count > 1)
  1164. return false;
  1165. count = 0;
  1166. for (i = 0; i < fb_helper->connector_count; i++) {
  1167. if (enabled[i])
  1168. count++;
  1169. }
  1170. /* only contemplate cloning if more than one connector is enabled */
  1171. if (count <= 1)
  1172. return false;
  1173. /* check the command line or if nothing common pick 1024x768 */
  1174. can_clone = true;
  1175. for (i = 0; i < fb_helper->connector_count; i++) {
  1176. if (!enabled[i])
  1177. continue;
  1178. fb_helper_conn = fb_helper->connector_info[i];
  1179. modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
  1180. if (!modes[i]) {
  1181. can_clone = false;
  1182. break;
  1183. }
  1184. for (j = 0; j < i; j++) {
  1185. if (!enabled[j])
  1186. continue;
  1187. if (!drm_mode_equal(modes[j], modes[i]))
  1188. can_clone = false;
  1189. }
  1190. }
  1191. if (can_clone) {
  1192. DRM_DEBUG_KMS("can clone using command line\n");
  1193. return true;
  1194. }
  1195. /* try and find a 1024x768 mode on each connector */
  1196. can_clone = true;
  1197. dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60, false);
  1198. for (i = 0; i < fb_helper->connector_count; i++) {
  1199. if (!enabled[i])
  1200. continue;
  1201. fb_helper_conn = fb_helper->connector_info[i];
  1202. list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
  1203. if (drm_mode_equal(mode, dmt_mode))
  1204. modes[i] = mode;
  1205. }
  1206. if (!modes[i])
  1207. can_clone = false;
  1208. }
  1209. if (can_clone) {
  1210. DRM_DEBUG_KMS("can clone using 1024x768\n");
  1211. return true;
  1212. }
  1213. DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
  1214. return false;
  1215. }
  1216. static int drm_get_tile_offsets(struct drm_fb_helper *fb_helper,
  1217. struct drm_display_mode **modes,
  1218. struct drm_fb_offset *offsets,
  1219. int idx,
  1220. int h_idx, int v_idx)
  1221. {
  1222. struct drm_fb_helper_connector *fb_helper_conn;
  1223. int i;
  1224. int hoffset = 0, voffset = 0;
  1225. for (i = 0; i < fb_helper->connector_count; i++) {
  1226. fb_helper_conn = fb_helper->connector_info[i];
  1227. if (!fb_helper_conn->connector->has_tile)
  1228. continue;
  1229. if (!modes[i] && (h_idx || v_idx)) {
  1230. DRM_DEBUG_KMS("no modes for connector tiled %d %d\n", i,
  1231. fb_helper_conn->connector->base.id);
  1232. continue;
  1233. }
  1234. if (fb_helper_conn->connector->tile_h_loc < h_idx)
  1235. hoffset += modes[i]->hdisplay;
  1236. if (fb_helper_conn->connector->tile_v_loc < v_idx)
  1237. voffset += modes[i]->vdisplay;
  1238. }
  1239. offsets[idx].x = hoffset;
  1240. offsets[idx].y = voffset;
  1241. DRM_DEBUG_KMS("returned %d %d for %d %d\n", hoffset, voffset, h_idx, v_idx);
  1242. return 0;
  1243. }
  1244. static bool drm_target_preferred(struct drm_fb_helper *fb_helper,
  1245. struct drm_display_mode **modes,
  1246. struct drm_fb_offset *offsets,
  1247. bool *enabled, int width, int height)
  1248. {
  1249. struct drm_fb_helper_connector *fb_helper_conn;
  1250. int i;
  1251. uint64_t conn_configured = 0, mask;
  1252. int tile_pass = 0;
  1253. mask = (1 << fb_helper->connector_count) - 1;
  1254. retry:
  1255. for (i = 0; i < fb_helper->connector_count; i++) {
  1256. fb_helper_conn = fb_helper->connector_info[i];
  1257. if (conn_configured & (1 << i))
  1258. continue;
  1259. if (enabled[i] == false) {
  1260. conn_configured |= (1 << i);
  1261. continue;
  1262. }
  1263. /* first pass over all the untiled connectors */
  1264. if (tile_pass == 0 && fb_helper_conn->connector->has_tile)
  1265. continue;
  1266. if (tile_pass == 1) {
  1267. if (fb_helper_conn->connector->tile_h_loc != 0 ||
  1268. fb_helper_conn->connector->tile_v_loc != 0)
  1269. continue;
  1270. } else {
  1271. if (fb_helper_conn->connector->tile_h_loc != tile_pass -1 &&
  1272. fb_helper_conn->connector->tile_v_loc != tile_pass - 1)
  1273. /* if this tile_pass doesn't cover any of the tiles - keep going */
  1274. continue;
  1275. /* find the tile offsets for this pass - need
  1276. to find all tiles left and above */
  1277. drm_get_tile_offsets(fb_helper, modes, offsets,
  1278. i, fb_helper_conn->connector->tile_h_loc, fb_helper_conn->connector->tile_v_loc);
  1279. }
  1280. DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
  1281. fb_helper_conn->connector->base.id);
  1282. /* got for command line mode first */
  1283. modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
  1284. if (!modes[i]) {
  1285. DRM_DEBUG_KMS("looking for preferred mode on connector %d %d\n",
  1286. fb_helper_conn->connector->base.id, fb_helper_conn->connector->tile_group ? fb_helper_conn->connector->tile_group->id : 0);
  1287. modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height);
  1288. }
  1289. /* No preferred modes, pick one off the list */
  1290. if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) {
  1291. list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head)
  1292. break;
  1293. }
  1294. DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name :
  1295. "none");
  1296. conn_configured |= (1 << i);
  1297. }
  1298. if ((conn_configured & mask) != mask) {
  1299. tile_pass++;
  1300. goto retry;
  1301. }
  1302. return true;
  1303. }
  1304. static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
  1305. struct drm_fb_helper_crtc **best_crtcs,
  1306. struct drm_display_mode **modes,
  1307. int n, int width, int height)
  1308. {
  1309. int c, o;
  1310. struct drm_device *dev = fb_helper->dev;
  1311. struct drm_connector *connector;
  1312. struct drm_connector_helper_funcs *connector_funcs;
  1313. struct drm_encoder *encoder;
  1314. int my_score, best_score, score;
  1315. struct drm_fb_helper_crtc **crtcs, *crtc;
  1316. struct drm_fb_helper_connector *fb_helper_conn;
  1317. if (n == fb_helper->connector_count)
  1318. return 0;
  1319. fb_helper_conn = fb_helper->connector_info[n];
  1320. connector = fb_helper_conn->connector;
  1321. best_crtcs[n] = NULL;
  1322. best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height);
  1323. if (modes[n] == NULL)
  1324. return best_score;
  1325. crtcs = kzalloc(dev->mode_config.num_connector *
  1326. sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
  1327. if (!crtcs)
  1328. return best_score;
  1329. my_score = 1;
  1330. if (connector->status == connector_status_connected)
  1331. my_score++;
  1332. if (drm_has_cmdline_mode(fb_helper_conn))
  1333. my_score++;
  1334. if (drm_has_preferred_mode(fb_helper_conn, width, height))
  1335. my_score++;
  1336. connector_funcs = connector->helper_private;
  1337. encoder = connector_funcs->best_encoder(connector);
  1338. if (!encoder)
  1339. goto out;
  1340. /* select a crtc for this connector and then attempt to configure
  1341. remaining connectors */
  1342. for (c = 0; c < fb_helper->crtc_count; c++) {
  1343. crtc = &fb_helper->crtc_info[c];
  1344. if ((encoder->possible_crtcs & (1 << c)) == 0)
  1345. continue;
  1346. for (o = 0; o < n; o++)
  1347. if (best_crtcs[o] == crtc)
  1348. break;
  1349. if (o < n) {
  1350. /* ignore cloning unless only a single crtc */
  1351. if (fb_helper->crtc_count > 1)
  1352. continue;
  1353. if (!drm_mode_equal(modes[o], modes[n]))
  1354. continue;
  1355. }
  1356. crtcs[n] = crtc;
  1357. memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *));
  1358. score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1,
  1359. width, height);
  1360. if (score > best_score) {
  1361. best_score = score;
  1362. memcpy(best_crtcs, crtcs,
  1363. dev->mode_config.num_connector *
  1364. sizeof(struct drm_fb_helper_crtc *));
  1365. }
  1366. }
  1367. out:
  1368. kfree(crtcs);
  1369. return best_score;
  1370. }
  1371. static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
  1372. {
  1373. struct drm_device *dev = fb_helper->dev;
  1374. struct drm_fb_helper_crtc **crtcs;
  1375. struct drm_display_mode **modes;
  1376. struct drm_fb_offset *offsets;
  1377. struct drm_mode_set *modeset;
  1378. bool *enabled;
  1379. int width, height;
  1380. int i;
  1381. DRM_DEBUG_KMS("\n");
  1382. width = dev->mode_config.max_width;
  1383. height = dev->mode_config.max_height;
  1384. crtcs = kcalloc(dev->mode_config.num_connector,
  1385. sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
  1386. modes = kcalloc(dev->mode_config.num_connector,
  1387. sizeof(struct drm_display_mode *), GFP_KERNEL);
  1388. offsets = kcalloc(dev->mode_config.num_connector,
  1389. sizeof(struct drm_fb_offset), GFP_KERNEL);
  1390. enabled = kcalloc(dev->mode_config.num_connector,
  1391. sizeof(bool), GFP_KERNEL);
  1392. if (!crtcs || !modes || !enabled || !offsets) {
  1393. DRM_ERROR("Memory allocation failed\n");
  1394. goto out;
  1395. }
  1396. drm_enable_connectors(fb_helper, enabled);
  1397. if (!(fb_helper->funcs->initial_config &&
  1398. fb_helper->funcs->initial_config(fb_helper, crtcs, modes,
  1399. offsets,
  1400. enabled, width, height))) {
  1401. memset(modes, 0, dev->mode_config.num_connector*sizeof(modes[0]));
  1402. memset(crtcs, 0, dev->mode_config.num_connector*sizeof(crtcs[0]));
  1403. memset(offsets, 0, dev->mode_config.num_connector*sizeof(offsets[0]));
  1404. if (!drm_target_cloned(fb_helper, modes, offsets,
  1405. enabled, width, height) &&
  1406. !drm_target_preferred(fb_helper, modes, offsets,
  1407. enabled, width, height))
  1408. DRM_ERROR("Unable to find initial modes\n");
  1409. DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n",
  1410. width, height);
  1411. drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
  1412. }
  1413. /* need to set the modesets up here for use later */
  1414. /* fill out the connector<->crtc mappings into the modesets */
  1415. for (i = 0; i < fb_helper->crtc_count; i++) {
  1416. modeset = &fb_helper->crtc_info[i].mode_set;
  1417. modeset->num_connectors = 0;
  1418. modeset->fb = NULL;
  1419. }
  1420. for (i = 0; i < fb_helper->connector_count; i++) {
  1421. struct drm_display_mode *mode = modes[i];
  1422. struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
  1423. struct drm_fb_offset *offset = &offsets[i];
  1424. modeset = &fb_crtc->mode_set;
  1425. if (mode && fb_crtc) {
  1426. DRM_DEBUG_KMS("desired mode %s set on crtc %d (%d,%d)\n",
  1427. mode->name, fb_crtc->mode_set.crtc->base.id, offset->x, offset->y);
  1428. fb_crtc->desired_mode = mode;
  1429. fb_crtc->x = offset->x;
  1430. fb_crtc->y = offset->y;
  1431. if (modeset->mode)
  1432. drm_mode_destroy(dev, modeset->mode);
  1433. modeset->mode = drm_mode_duplicate(dev,
  1434. fb_crtc->desired_mode);
  1435. modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector;
  1436. modeset->fb = fb_helper->fb;
  1437. modeset->x = offset->x;
  1438. modeset->y = offset->y;
  1439. }
  1440. }
  1441. /* Clear out any old modes if there are no more connected outputs. */
  1442. for (i = 0; i < fb_helper->crtc_count; i++) {
  1443. modeset = &fb_helper->crtc_info[i].mode_set;
  1444. if (modeset->num_connectors == 0) {
  1445. BUG_ON(modeset->fb);
  1446. if (modeset->mode)
  1447. drm_mode_destroy(dev, modeset->mode);
  1448. modeset->mode = NULL;
  1449. }
  1450. }
  1451. out:
  1452. kfree(crtcs);
  1453. kfree(modes);
  1454. kfree(offsets);
  1455. kfree(enabled);
  1456. }
  1457. /**
  1458. * drm_fb_helper_initial_config - setup a sane initial connector configuration
  1459. * @fb_helper: fb_helper device struct
  1460. * @bpp_sel: bpp value to use for the framebuffer configuration
  1461. *
  1462. * Scans the CRTCs and connectors and tries to put together an initial setup.
  1463. * At the moment, this is a cloned configuration across all heads with
  1464. * a new framebuffer object as the backing store.
  1465. *
  1466. * Note that this also registers the fbdev and so allows userspace to call into
  1467. * the driver through the fbdev interfaces.
  1468. *
  1469. * This function will call down into the ->fb_probe callback to let
  1470. * the driver allocate and initialize the fbdev info structure and the drm
  1471. * framebuffer used to back the fbdev. drm_fb_helper_fill_var() and
  1472. * drm_fb_helper_fill_fix() are provided as helpers to setup simple default
  1473. * values for the fbdev info structure.
  1474. *
  1475. * RETURNS:
  1476. * Zero if everything went ok, nonzero otherwise.
  1477. */
  1478. bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel)
  1479. {
  1480. struct drm_device *dev = fb_helper->dev;
  1481. int count = 0;
  1482. mutex_lock(&dev->mode_config.mutex);
  1483. count = drm_fb_helper_probe_connector_modes(fb_helper,
  1484. dev->mode_config.max_width,
  1485. dev->mode_config.max_height);
  1486. mutex_unlock(&dev->mode_config.mutex);
  1487. /*
  1488. * we shouldn't end up with no modes here.
  1489. */
  1490. if (count == 0)
  1491. dev_info(fb_helper->dev->dev, "No connectors reported connected with modes\n");
  1492. drm_setup_crtcs(fb_helper);
  1493. return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
  1494. }
  1495. EXPORT_SYMBOL(drm_fb_helper_initial_config);
  1496. /**
  1497. * drm_fb_helper_hotplug_event - respond to a hotplug notification by
  1498. * probing all the outputs attached to the fb
  1499. * @fb_helper: the drm_fb_helper
  1500. *
  1501. * Scan the connectors attached to the fb_helper and try to put together a
  1502. * setup after *notification of a change in output configuration.
  1503. *
  1504. * Called at runtime, takes the mode config locks to be able to check/change the
  1505. * modeset configuration. Must be run from process context (which usually means
  1506. * either the output polling work or a work item launched from the driver's
  1507. * hotplug interrupt).
  1508. *
  1509. * Note that drivers may call this even before calling
  1510. * drm_fb_helper_initial_config but only aftert drm_fb_helper_init. This allows
  1511. * for a race-free fbcon setup and will make sure that the fbdev emulation will
  1512. * not miss any hotplug events.
  1513. *
  1514. * RETURNS:
  1515. * 0 on success and a non-zero error code otherwise.
  1516. */
  1517. int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
  1518. {
  1519. struct drm_device *dev = fb_helper->dev;
  1520. u32 max_width, max_height;
  1521. mutex_lock(&fb_helper->dev->mode_config.mutex);
  1522. if (!fb_helper->fb || !drm_fb_helper_is_bound(fb_helper)) {
  1523. fb_helper->delayed_hotplug = true;
  1524. mutex_unlock(&fb_helper->dev->mode_config.mutex);
  1525. return 0;
  1526. }
  1527. DRM_DEBUG_KMS("\n");
  1528. max_width = fb_helper->fb->width;
  1529. max_height = fb_helper->fb->height;
  1530. drm_fb_helper_probe_connector_modes(fb_helper, max_width, max_height);
  1531. mutex_unlock(&fb_helper->dev->mode_config.mutex);
  1532. drm_modeset_lock_all(dev);
  1533. drm_setup_crtcs(fb_helper);
  1534. drm_modeset_unlock_all(dev);
  1535. drm_fb_helper_set_par(fb_helper->fbdev);
  1536. return 0;
  1537. }
  1538. EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
  1539. /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT)
  1540. * but the module doesn't depend on any fb console symbols. At least
  1541. * attempt to load fbcon to avoid leaving the system without a usable console.
  1542. */
  1543. #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT)
  1544. static int __init drm_fb_helper_modinit(void)
  1545. {
  1546. const char *name = "fbcon";
  1547. struct module *fbcon;
  1548. mutex_lock(&module_mutex);
  1549. fbcon = find_module(name);
  1550. mutex_unlock(&module_mutex);
  1551. if (!fbcon)
  1552. request_module_nowait(name);
  1553. return 0;
  1554. }
  1555. module_init(drm_fb_helper_modinit);
  1556. #endif