drm_fb_helper.c 51 KB

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