drm_fb_helper.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782
  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. drm_modeset_lock_all(dev);
  643. if (!drm_fb_helper_is_bound(fb_helper)) {
  644. drm_modeset_unlock_all(dev);
  645. return -EBUSY;
  646. }
  647. for (i = 0; i < fb_helper->crtc_count; i++) {
  648. crtc = fb_helper->crtc_info[i].mode_set.crtc;
  649. crtc_funcs = crtc->helper_private;
  650. red = cmap->red;
  651. green = cmap->green;
  652. blue = cmap->blue;
  653. transp = cmap->transp;
  654. start = cmap->start;
  655. for (j = 0; j < cmap->len; j++) {
  656. u16 hred, hgreen, hblue, htransp = 0xffff;
  657. hred = *red++;
  658. hgreen = *green++;
  659. hblue = *blue++;
  660. if (transp)
  661. htransp = *transp++;
  662. rc = setcolreg(crtc, hred, hgreen, hblue, start++, info);
  663. if (rc)
  664. goto out;
  665. }
  666. if (crtc_funcs->load_lut)
  667. crtc_funcs->load_lut(crtc);
  668. }
  669. out:
  670. drm_modeset_unlock_all(dev);
  671. return rc;
  672. }
  673. EXPORT_SYMBOL(drm_fb_helper_setcmap);
  674. /**
  675. * drm_fb_helper_check_var - implementation for ->fb_check_var
  676. * @var: screeninfo to check
  677. * @info: fbdev registered by the helper
  678. */
  679. int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
  680. struct fb_info *info)
  681. {
  682. struct drm_fb_helper *fb_helper = info->par;
  683. struct drm_framebuffer *fb = fb_helper->fb;
  684. int depth;
  685. if (var->pixclock != 0 || in_dbg_master())
  686. return -EINVAL;
  687. /* Need to resize the fb object !!! */
  688. if (var->bits_per_pixel > fb->bits_per_pixel ||
  689. var->xres > fb->width || var->yres > fb->height ||
  690. var->xres_virtual > fb->width || var->yres_virtual > fb->height) {
  691. DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
  692. "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
  693. var->xres, var->yres, var->bits_per_pixel,
  694. var->xres_virtual, var->yres_virtual,
  695. fb->width, fb->height, fb->bits_per_pixel);
  696. return -EINVAL;
  697. }
  698. switch (var->bits_per_pixel) {
  699. case 16:
  700. depth = (var->green.length == 6) ? 16 : 15;
  701. break;
  702. case 32:
  703. depth = (var->transp.length > 0) ? 32 : 24;
  704. break;
  705. default:
  706. depth = var->bits_per_pixel;
  707. break;
  708. }
  709. switch (depth) {
  710. case 8:
  711. var->red.offset = 0;
  712. var->green.offset = 0;
  713. var->blue.offset = 0;
  714. var->red.length = 8;
  715. var->green.length = 8;
  716. var->blue.length = 8;
  717. var->transp.length = 0;
  718. var->transp.offset = 0;
  719. break;
  720. case 15:
  721. var->red.offset = 10;
  722. var->green.offset = 5;
  723. var->blue.offset = 0;
  724. var->red.length = 5;
  725. var->green.length = 5;
  726. var->blue.length = 5;
  727. var->transp.length = 1;
  728. var->transp.offset = 15;
  729. break;
  730. case 16:
  731. var->red.offset = 11;
  732. var->green.offset = 5;
  733. var->blue.offset = 0;
  734. var->red.length = 5;
  735. var->green.length = 6;
  736. var->blue.length = 5;
  737. var->transp.length = 0;
  738. var->transp.offset = 0;
  739. break;
  740. case 24:
  741. var->red.offset = 16;
  742. var->green.offset = 8;
  743. var->blue.offset = 0;
  744. var->red.length = 8;
  745. var->green.length = 8;
  746. var->blue.length = 8;
  747. var->transp.length = 0;
  748. var->transp.offset = 0;
  749. break;
  750. case 32:
  751. var->red.offset = 16;
  752. var->green.offset = 8;
  753. var->blue.offset = 0;
  754. var->red.length = 8;
  755. var->green.length = 8;
  756. var->blue.length = 8;
  757. var->transp.length = 8;
  758. var->transp.offset = 24;
  759. break;
  760. default:
  761. return -EINVAL;
  762. }
  763. return 0;
  764. }
  765. EXPORT_SYMBOL(drm_fb_helper_check_var);
  766. /**
  767. * drm_fb_helper_set_par - implementation for ->fb_set_par
  768. * @info: fbdev registered by the helper
  769. *
  770. * This will let fbcon do the mode init and is called at initialization time by
  771. * the fbdev core when registering the driver, and later on through the hotplug
  772. * callback.
  773. */
  774. int drm_fb_helper_set_par(struct fb_info *info)
  775. {
  776. struct drm_fb_helper *fb_helper = info->par;
  777. struct fb_var_screeninfo *var = &info->var;
  778. if (var->pixclock != 0) {
  779. DRM_ERROR("PIXEL CLOCK SET\n");
  780. return -EINVAL;
  781. }
  782. drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper);
  783. return 0;
  784. }
  785. EXPORT_SYMBOL(drm_fb_helper_set_par);
  786. /**
  787. * drm_fb_helper_pan_display - implementation for ->fb_pan_display
  788. * @var: updated screen information
  789. * @info: fbdev registered by the helper
  790. */
  791. int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
  792. struct fb_info *info)
  793. {
  794. struct drm_fb_helper *fb_helper = info->par;
  795. struct drm_device *dev = fb_helper->dev;
  796. struct drm_mode_set *modeset;
  797. int ret = 0;
  798. int i;
  799. drm_modeset_lock_all(dev);
  800. if (!drm_fb_helper_is_bound(fb_helper)) {
  801. drm_modeset_unlock_all(dev);
  802. return -EBUSY;
  803. }
  804. for (i = 0; i < fb_helper->crtc_count; i++) {
  805. modeset = &fb_helper->crtc_info[i].mode_set;
  806. modeset->x = var->xoffset;
  807. modeset->y = var->yoffset;
  808. if (modeset->num_connectors) {
  809. ret = drm_mode_set_config_internal(modeset);
  810. if (!ret) {
  811. info->var.xoffset = var->xoffset;
  812. info->var.yoffset = var->yoffset;
  813. }
  814. }
  815. }
  816. drm_modeset_unlock_all(dev);
  817. return ret;
  818. }
  819. EXPORT_SYMBOL(drm_fb_helper_pan_display);
  820. /*
  821. * Allocates the backing storage and sets up the fbdev info structure through
  822. * the ->fb_probe callback and then registers the fbdev and sets up the panic
  823. * notifier.
  824. */
  825. static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
  826. int preferred_bpp)
  827. {
  828. int ret = 0;
  829. int crtc_count = 0;
  830. int i;
  831. struct fb_info *info;
  832. struct drm_fb_helper_surface_size sizes;
  833. int gamma_size = 0;
  834. memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
  835. sizes.surface_depth = 24;
  836. sizes.surface_bpp = 32;
  837. sizes.fb_width = (unsigned)-1;
  838. sizes.fb_height = (unsigned)-1;
  839. /* if driver picks 8 or 16 by default use that
  840. for both depth/bpp */
  841. if (preferred_bpp != sizes.surface_bpp)
  842. sizes.surface_depth = sizes.surface_bpp = preferred_bpp;
  843. /* first up get a count of crtcs now in use and new min/maxes width/heights */
  844. for (i = 0; i < fb_helper->connector_count; i++) {
  845. struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i];
  846. struct drm_cmdline_mode *cmdline_mode;
  847. cmdline_mode = &fb_helper_conn->connector->cmdline_mode;
  848. if (cmdline_mode->bpp_specified) {
  849. switch (cmdline_mode->bpp) {
  850. case 8:
  851. sizes.surface_depth = sizes.surface_bpp = 8;
  852. break;
  853. case 15:
  854. sizes.surface_depth = 15;
  855. sizes.surface_bpp = 16;
  856. break;
  857. case 16:
  858. sizes.surface_depth = sizes.surface_bpp = 16;
  859. break;
  860. case 24:
  861. sizes.surface_depth = sizes.surface_bpp = 24;
  862. break;
  863. case 32:
  864. sizes.surface_depth = 24;
  865. sizes.surface_bpp = 32;
  866. break;
  867. }
  868. break;
  869. }
  870. }
  871. crtc_count = 0;
  872. for (i = 0; i < fb_helper->crtc_count; i++) {
  873. struct drm_display_mode *desired_mode;
  874. int x, y;
  875. desired_mode = fb_helper->crtc_info[i].desired_mode;
  876. x = fb_helper->crtc_info[i].x;
  877. y = fb_helper->crtc_info[i].y;
  878. if (desired_mode) {
  879. if (gamma_size == 0)
  880. gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size;
  881. if (desired_mode->hdisplay + x < sizes.fb_width)
  882. sizes.fb_width = desired_mode->hdisplay + x;
  883. if (desired_mode->vdisplay + y < sizes.fb_height)
  884. sizes.fb_height = desired_mode->vdisplay + y;
  885. if (desired_mode->hdisplay + x > sizes.surface_width)
  886. sizes.surface_width = desired_mode->hdisplay + x;
  887. if (desired_mode->vdisplay + y > sizes.surface_height)
  888. sizes.surface_height = desired_mode->vdisplay + y;
  889. crtc_count++;
  890. }
  891. }
  892. if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) {
  893. /* hmm everyone went away - assume VGA cable just fell out
  894. and will come back later. */
  895. DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
  896. sizes.fb_width = sizes.surface_width = 1024;
  897. sizes.fb_height = sizes.surface_height = 768;
  898. }
  899. /* push down into drivers */
  900. ret = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
  901. if (ret < 0)
  902. return ret;
  903. info = fb_helper->fbdev;
  904. /*
  905. * Set the fb pointer - usually drm_setup_crtcs does this for hotplug
  906. * events, but at init time drm_setup_crtcs needs to be called before
  907. * the fb is allocated (since we need to figure out the desired size of
  908. * the fb before we can allocate it ...). Hence we need to fix things up
  909. * here again.
  910. */
  911. for (i = 0; i < fb_helper->crtc_count; i++)
  912. if (fb_helper->crtc_info[i].mode_set.num_connectors)
  913. fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
  914. info->var.pixclock = 0;
  915. if (register_framebuffer(info) < 0)
  916. return -EINVAL;
  917. dev_info(fb_helper->dev->dev, "fb%d: %s frame buffer device\n",
  918. info->node, info->fix.id);
  919. /* Switch back to kernel console on panic */
  920. /* multi card linked list maybe */
  921. if (list_empty(&kernel_fb_helper_list)) {
  922. dev_info(fb_helper->dev->dev, "registered panic notifier\n");
  923. atomic_notifier_chain_register(&panic_notifier_list,
  924. &paniced);
  925. register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
  926. }
  927. list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
  928. return 0;
  929. }
  930. /**
  931. * drm_fb_helper_fill_fix - initializes fixed fbdev information
  932. * @info: fbdev registered by the helper
  933. * @pitch: desired pitch
  934. * @depth: desired depth
  935. *
  936. * Helper to fill in the fixed fbdev information useful for a non-accelerated
  937. * fbdev emulations. Drivers which support acceleration methods which impose
  938. * additional constraints need to set up their own limits.
  939. *
  940. * Drivers should call this (or their equivalent setup code) from their
  941. * ->fb_probe callback.
  942. */
  943. void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
  944. uint32_t depth)
  945. {
  946. info->fix.type = FB_TYPE_PACKED_PIXELS;
  947. info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR :
  948. FB_VISUAL_TRUECOLOR;
  949. info->fix.mmio_start = 0;
  950. info->fix.mmio_len = 0;
  951. info->fix.type_aux = 0;
  952. info->fix.xpanstep = 1; /* doing it in hw */
  953. info->fix.ypanstep = 1; /* doing it in hw */
  954. info->fix.ywrapstep = 0;
  955. info->fix.accel = FB_ACCEL_NONE;
  956. info->fix.line_length = pitch;
  957. return;
  958. }
  959. EXPORT_SYMBOL(drm_fb_helper_fill_fix);
  960. /**
  961. * drm_fb_helper_fill_var - initalizes variable fbdev information
  962. * @info: fbdev instance to set up
  963. * @fb_helper: fb helper instance to use as template
  964. * @fb_width: desired fb width
  965. * @fb_height: desired fb height
  966. *
  967. * Sets up the variable fbdev metainformation from the given fb helper instance
  968. * and the drm framebuffer allocated in fb_helper->fb.
  969. *
  970. * Drivers should call this (or their equivalent setup code) from their
  971. * ->fb_probe callback after having allocated the fbdev backing
  972. * storage framebuffer.
  973. */
  974. void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
  975. uint32_t fb_width, uint32_t fb_height)
  976. {
  977. struct drm_framebuffer *fb = fb_helper->fb;
  978. info->pseudo_palette = fb_helper->pseudo_palette;
  979. info->var.xres_virtual = fb->width;
  980. info->var.yres_virtual = fb->height;
  981. info->var.bits_per_pixel = fb->bits_per_pixel;
  982. info->var.accel_flags = FB_ACCELF_TEXT;
  983. info->var.xoffset = 0;
  984. info->var.yoffset = 0;
  985. info->var.activate = FB_ACTIVATE_NOW;
  986. info->var.height = -1;
  987. info->var.width = -1;
  988. switch (fb->depth) {
  989. case 8:
  990. info->var.red.offset = 0;
  991. info->var.green.offset = 0;
  992. info->var.blue.offset = 0;
  993. info->var.red.length = 8; /* 8bit DAC */
  994. info->var.green.length = 8;
  995. info->var.blue.length = 8;
  996. info->var.transp.offset = 0;
  997. info->var.transp.length = 0;
  998. break;
  999. case 15:
  1000. info->var.red.offset = 10;
  1001. info->var.green.offset = 5;
  1002. info->var.blue.offset = 0;
  1003. info->var.red.length = 5;
  1004. info->var.green.length = 5;
  1005. info->var.blue.length = 5;
  1006. info->var.transp.offset = 15;
  1007. info->var.transp.length = 1;
  1008. break;
  1009. case 16:
  1010. info->var.red.offset = 11;
  1011. info->var.green.offset = 5;
  1012. info->var.blue.offset = 0;
  1013. info->var.red.length = 5;
  1014. info->var.green.length = 6;
  1015. info->var.blue.length = 5;
  1016. info->var.transp.offset = 0;
  1017. break;
  1018. case 24:
  1019. info->var.red.offset = 16;
  1020. info->var.green.offset = 8;
  1021. info->var.blue.offset = 0;
  1022. info->var.red.length = 8;
  1023. info->var.green.length = 8;
  1024. info->var.blue.length = 8;
  1025. info->var.transp.offset = 0;
  1026. info->var.transp.length = 0;
  1027. break;
  1028. case 32:
  1029. info->var.red.offset = 16;
  1030. info->var.green.offset = 8;
  1031. info->var.blue.offset = 0;
  1032. info->var.red.length = 8;
  1033. info->var.green.length = 8;
  1034. info->var.blue.length = 8;
  1035. info->var.transp.offset = 24;
  1036. info->var.transp.length = 8;
  1037. break;
  1038. default:
  1039. break;
  1040. }
  1041. info->var.xres = fb_width;
  1042. info->var.yres = fb_height;
  1043. }
  1044. EXPORT_SYMBOL(drm_fb_helper_fill_var);
  1045. static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper,
  1046. uint32_t maxX,
  1047. uint32_t maxY)
  1048. {
  1049. struct drm_connector *connector;
  1050. int count = 0;
  1051. int i;
  1052. for (i = 0; i < fb_helper->connector_count; i++) {
  1053. connector = fb_helper->connector_info[i]->connector;
  1054. count += connector->funcs->fill_modes(connector, maxX, maxY);
  1055. }
  1056. return count;
  1057. }
  1058. struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height)
  1059. {
  1060. struct drm_display_mode *mode;
  1061. list_for_each_entry(mode, &fb_connector->connector->modes, head) {
  1062. if (mode->hdisplay > width ||
  1063. mode->vdisplay > height)
  1064. continue;
  1065. if (mode->type & DRM_MODE_TYPE_PREFERRED)
  1066. return mode;
  1067. }
  1068. return NULL;
  1069. }
  1070. EXPORT_SYMBOL(drm_has_preferred_mode);
  1071. static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector)
  1072. {
  1073. return fb_connector->connector->cmdline_mode.specified;
  1074. }
  1075. struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
  1076. int width, int height)
  1077. {
  1078. struct drm_cmdline_mode *cmdline_mode;
  1079. struct drm_display_mode *mode = NULL;
  1080. bool prefer_non_interlace;
  1081. cmdline_mode = &fb_helper_conn->connector->cmdline_mode;
  1082. if (cmdline_mode->specified == false)
  1083. return mode;
  1084. /* attempt to find a matching mode in the list of modes
  1085. * we have gotten so far, if not add a CVT mode that conforms
  1086. */
  1087. if (cmdline_mode->rb || cmdline_mode->margins)
  1088. goto create_mode;
  1089. prefer_non_interlace = !cmdline_mode->interlace;
  1090. again:
  1091. list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
  1092. /* check width/height */
  1093. if (mode->hdisplay != cmdline_mode->xres ||
  1094. mode->vdisplay != cmdline_mode->yres)
  1095. continue;
  1096. if (cmdline_mode->refresh_specified) {
  1097. if (mode->vrefresh != cmdline_mode->refresh)
  1098. continue;
  1099. }
  1100. if (cmdline_mode->interlace) {
  1101. if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
  1102. continue;
  1103. } else if (prefer_non_interlace) {
  1104. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1105. continue;
  1106. }
  1107. return mode;
  1108. }
  1109. if (prefer_non_interlace) {
  1110. prefer_non_interlace = false;
  1111. goto again;
  1112. }
  1113. create_mode:
  1114. mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev,
  1115. cmdline_mode);
  1116. list_add(&mode->head, &fb_helper_conn->connector->modes);
  1117. return mode;
  1118. }
  1119. EXPORT_SYMBOL(drm_pick_cmdline_mode);
  1120. static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
  1121. {
  1122. bool enable;
  1123. if (strict)
  1124. enable = connector->status == connector_status_connected;
  1125. else
  1126. enable = connector->status != connector_status_disconnected;
  1127. return enable;
  1128. }
  1129. static void drm_enable_connectors(struct drm_fb_helper *fb_helper,
  1130. bool *enabled)
  1131. {
  1132. bool any_enabled = false;
  1133. struct drm_connector *connector;
  1134. int i = 0;
  1135. for (i = 0; i < fb_helper->connector_count; i++) {
  1136. connector = fb_helper->connector_info[i]->connector;
  1137. enabled[i] = drm_connector_enabled(connector, true);
  1138. DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
  1139. enabled[i] ? "yes" : "no");
  1140. any_enabled |= enabled[i];
  1141. }
  1142. if (any_enabled)
  1143. return;
  1144. for (i = 0; i < fb_helper->connector_count; i++) {
  1145. connector = fb_helper->connector_info[i]->connector;
  1146. enabled[i] = drm_connector_enabled(connector, false);
  1147. }
  1148. }
  1149. static bool drm_target_cloned(struct drm_fb_helper *fb_helper,
  1150. struct drm_display_mode **modes,
  1151. struct drm_fb_offset *offsets,
  1152. bool *enabled, int width, int height)
  1153. {
  1154. int count, i, j;
  1155. bool can_clone = false;
  1156. struct drm_fb_helper_connector *fb_helper_conn;
  1157. struct drm_display_mode *dmt_mode, *mode;
  1158. /* only contemplate cloning in the single crtc case */
  1159. if (fb_helper->crtc_count > 1)
  1160. return false;
  1161. count = 0;
  1162. for (i = 0; i < fb_helper->connector_count; i++) {
  1163. if (enabled[i])
  1164. count++;
  1165. }
  1166. /* only contemplate cloning if more than one connector is enabled */
  1167. if (count <= 1)
  1168. return false;
  1169. /* check the command line or if nothing common pick 1024x768 */
  1170. can_clone = true;
  1171. for (i = 0; i < fb_helper->connector_count; i++) {
  1172. if (!enabled[i])
  1173. continue;
  1174. fb_helper_conn = fb_helper->connector_info[i];
  1175. modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
  1176. if (!modes[i]) {
  1177. can_clone = false;
  1178. break;
  1179. }
  1180. for (j = 0; j < i; j++) {
  1181. if (!enabled[j])
  1182. continue;
  1183. if (!drm_mode_equal(modes[j], modes[i]))
  1184. can_clone = false;
  1185. }
  1186. }
  1187. if (can_clone) {
  1188. DRM_DEBUG_KMS("can clone using command line\n");
  1189. return true;
  1190. }
  1191. /* try and find a 1024x768 mode on each connector */
  1192. can_clone = true;
  1193. dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60, false);
  1194. for (i = 0; i < fb_helper->connector_count; i++) {
  1195. if (!enabled[i])
  1196. continue;
  1197. fb_helper_conn = fb_helper->connector_info[i];
  1198. list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
  1199. if (drm_mode_equal(mode, dmt_mode))
  1200. modes[i] = mode;
  1201. }
  1202. if (!modes[i])
  1203. can_clone = false;
  1204. }
  1205. if (can_clone) {
  1206. DRM_DEBUG_KMS("can clone using 1024x768\n");
  1207. return true;
  1208. }
  1209. DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
  1210. return false;
  1211. }
  1212. static int drm_get_tile_offsets(struct drm_fb_helper *fb_helper,
  1213. struct drm_display_mode **modes,
  1214. struct drm_fb_offset *offsets,
  1215. int idx,
  1216. int h_idx, int v_idx)
  1217. {
  1218. struct drm_fb_helper_connector *fb_helper_conn;
  1219. int i;
  1220. int hoffset = 0, voffset = 0;
  1221. for (i = 0; i < fb_helper->connector_count; i++) {
  1222. fb_helper_conn = fb_helper->connector_info[i];
  1223. if (!fb_helper_conn->connector->has_tile)
  1224. continue;
  1225. if (!modes[i] && (h_idx || v_idx)) {
  1226. DRM_DEBUG_KMS("no modes for connector tiled %d %d\n", i,
  1227. fb_helper_conn->connector->base.id);
  1228. continue;
  1229. }
  1230. if (fb_helper_conn->connector->tile_h_loc < h_idx)
  1231. hoffset += modes[i]->hdisplay;
  1232. if (fb_helper_conn->connector->tile_v_loc < v_idx)
  1233. voffset += modes[i]->vdisplay;
  1234. }
  1235. offsets[idx].x = hoffset;
  1236. offsets[idx].y = voffset;
  1237. DRM_DEBUG_KMS("returned %d %d for %d %d\n", hoffset, voffset, h_idx, v_idx);
  1238. return 0;
  1239. }
  1240. static bool drm_target_preferred(struct drm_fb_helper *fb_helper,
  1241. struct drm_display_mode **modes,
  1242. struct drm_fb_offset *offsets,
  1243. bool *enabled, int width, int height)
  1244. {
  1245. struct drm_fb_helper_connector *fb_helper_conn;
  1246. int i;
  1247. uint64_t conn_configured = 0, mask;
  1248. int tile_pass = 0;
  1249. mask = (1 << fb_helper->connector_count) - 1;
  1250. retry:
  1251. for (i = 0; i < fb_helper->connector_count; i++) {
  1252. fb_helper_conn = fb_helper->connector_info[i];
  1253. if (conn_configured & (1 << i))
  1254. continue;
  1255. if (enabled[i] == false) {
  1256. conn_configured |= (1 << i);
  1257. continue;
  1258. }
  1259. /* first pass over all the untiled connectors */
  1260. if (tile_pass == 0 && fb_helper_conn->connector->has_tile)
  1261. continue;
  1262. if (tile_pass == 1) {
  1263. if (fb_helper_conn->connector->tile_h_loc != 0 ||
  1264. fb_helper_conn->connector->tile_v_loc != 0)
  1265. continue;
  1266. } else {
  1267. if (fb_helper_conn->connector->tile_h_loc != tile_pass -1 &&
  1268. fb_helper_conn->connector->tile_v_loc != tile_pass - 1)
  1269. /* if this tile_pass doesn't cover any of the tiles - keep going */
  1270. continue;
  1271. /* find the tile offsets for this pass - need
  1272. to find all tiles left and above */
  1273. drm_get_tile_offsets(fb_helper, modes, offsets,
  1274. i, fb_helper_conn->connector->tile_h_loc, fb_helper_conn->connector->tile_v_loc);
  1275. }
  1276. DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
  1277. fb_helper_conn->connector->base.id);
  1278. /* got for command line mode first */
  1279. modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
  1280. if (!modes[i]) {
  1281. DRM_DEBUG_KMS("looking for preferred mode on connector %d %d\n",
  1282. fb_helper_conn->connector->base.id, fb_helper_conn->connector->tile_group ? fb_helper_conn->connector->tile_group->id : 0);
  1283. modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height);
  1284. }
  1285. /* No preferred modes, pick one off the list */
  1286. if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) {
  1287. list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head)
  1288. break;
  1289. }
  1290. DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name :
  1291. "none");
  1292. conn_configured |= (1 << i);
  1293. }
  1294. if ((conn_configured & mask) != mask) {
  1295. tile_pass++;
  1296. goto retry;
  1297. }
  1298. return true;
  1299. }
  1300. static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
  1301. struct drm_fb_helper_crtc **best_crtcs,
  1302. struct drm_display_mode **modes,
  1303. int n, int width, int height)
  1304. {
  1305. int c, o;
  1306. struct drm_device *dev = fb_helper->dev;
  1307. struct drm_connector *connector;
  1308. struct drm_connector_helper_funcs *connector_funcs;
  1309. struct drm_encoder *encoder;
  1310. int my_score, best_score, score;
  1311. struct drm_fb_helper_crtc **crtcs, *crtc;
  1312. struct drm_fb_helper_connector *fb_helper_conn;
  1313. if (n == fb_helper->connector_count)
  1314. return 0;
  1315. fb_helper_conn = fb_helper->connector_info[n];
  1316. connector = fb_helper_conn->connector;
  1317. best_crtcs[n] = NULL;
  1318. best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height);
  1319. if (modes[n] == NULL)
  1320. return best_score;
  1321. crtcs = kzalloc(dev->mode_config.num_connector *
  1322. sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
  1323. if (!crtcs)
  1324. return best_score;
  1325. my_score = 1;
  1326. if (connector->status == connector_status_connected)
  1327. my_score++;
  1328. if (drm_has_cmdline_mode(fb_helper_conn))
  1329. my_score++;
  1330. if (drm_has_preferred_mode(fb_helper_conn, width, height))
  1331. my_score++;
  1332. connector_funcs = connector->helper_private;
  1333. encoder = connector_funcs->best_encoder(connector);
  1334. if (!encoder)
  1335. goto out;
  1336. /* select a crtc for this connector and then attempt to configure
  1337. remaining connectors */
  1338. for (c = 0; c < fb_helper->crtc_count; c++) {
  1339. crtc = &fb_helper->crtc_info[c];
  1340. if ((encoder->possible_crtcs & (1 << c)) == 0)
  1341. continue;
  1342. for (o = 0; o < n; o++)
  1343. if (best_crtcs[o] == crtc)
  1344. break;
  1345. if (o < n) {
  1346. /* ignore cloning unless only a single crtc */
  1347. if (fb_helper->crtc_count > 1)
  1348. continue;
  1349. if (!drm_mode_equal(modes[o], modes[n]))
  1350. continue;
  1351. }
  1352. crtcs[n] = crtc;
  1353. memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *));
  1354. score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1,
  1355. width, height);
  1356. if (score > best_score) {
  1357. best_score = score;
  1358. memcpy(best_crtcs, crtcs,
  1359. dev->mode_config.num_connector *
  1360. sizeof(struct drm_fb_helper_crtc *));
  1361. }
  1362. }
  1363. out:
  1364. kfree(crtcs);
  1365. return best_score;
  1366. }
  1367. static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
  1368. {
  1369. struct drm_device *dev = fb_helper->dev;
  1370. struct drm_fb_helper_crtc **crtcs;
  1371. struct drm_display_mode **modes;
  1372. struct drm_fb_offset *offsets;
  1373. struct drm_mode_set *modeset;
  1374. bool *enabled;
  1375. int width, height;
  1376. int i;
  1377. DRM_DEBUG_KMS("\n");
  1378. width = dev->mode_config.max_width;
  1379. height = dev->mode_config.max_height;
  1380. crtcs = kcalloc(dev->mode_config.num_connector,
  1381. sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
  1382. modes = kcalloc(dev->mode_config.num_connector,
  1383. sizeof(struct drm_display_mode *), GFP_KERNEL);
  1384. offsets = kcalloc(dev->mode_config.num_connector,
  1385. sizeof(struct drm_fb_offset), GFP_KERNEL);
  1386. enabled = kcalloc(dev->mode_config.num_connector,
  1387. sizeof(bool), GFP_KERNEL);
  1388. if (!crtcs || !modes || !enabled || !offsets) {
  1389. DRM_ERROR("Memory allocation failed\n");
  1390. goto out;
  1391. }
  1392. drm_enable_connectors(fb_helper, enabled);
  1393. if (!(fb_helper->funcs->initial_config &&
  1394. fb_helper->funcs->initial_config(fb_helper, crtcs, modes,
  1395. offsets,
  1396. enabled, width, height))) {
  1397. memset(modes, 0, dev->mode_config.num_connector*sizeof(modes[0]));
  1398. memset(crtcs, 0, dev->mode_config.num_connector*sizeof(crtcs[0]));
  1399. memset(offsets, 0, dev->mode_config.num_connector*sizeof(offsets[0]));
  1400. if (!drm_target_cloned(fb_helper, modes, offsets,
  1401. enabled, width, height) &&
  1402. !drm_target_preferred(fb_helper, modes, offsets,
  1403. enabled, width, height))
  1404. DRM_ERROR("Unable to find initial modes\n");
  1405. DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n",
  1406. width, height);
  1407. drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
  1408. }
  1409. /* need to set the modesets up here for use later */
  1410. /* fill out the connector<->crtc mappings into the modesets */
  1411. for (i = 0; i < fb_helper->crtc_count; i++) {
  1412. modeset = &fb_helper->crtc_info[i].mode_set;
  1413. modeset->num_connectors = 0;
  1414. modeset->fb = NULL;
  1415. }
  1416. for (i = 0; i < fb_helper->connector_count; i++) {
  1417. struct drm_display_mode *mode = modes[i];
  1418. struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
  1419. struct drm_fb_offset *offset = &offsets[i];
  1420. modeset = &fb_crtc->mode_set;
  1421. if (mode && fb_crtc) {
  1422. DRM_DEBUG_KMS("desired mode %s set on crtc %d (%d,%d)\n",
  1423. mode->name, fb_crtc->mode_set.crtc->base.id, offset->x, offset->y);
  1424. fb_crtc->desired_mode = mode;
  1425. fb_crtc->x = offset->x;
  1426. fb_crtc->y = offset->y;
  1427. if (modeset->mode)
  1428. drm_mode_destroy(dev, modeset->mode);
  1429. modeset->mode = drm_mode_duplicate(dev,
  1430. fb_crtc->desired_mode);
  1431. modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector;
  1432. modeset->fb = fb_helper->fb;
  1433. modeset->x = offset->x;
  1434. modeset->y = offset->y;
  1435. }
  1436. }
  1437. /* Clear out any old modes if there are no more connected outputs. */
  1438. for (i = 0; i < fb_helper->crtc_count; i++) {
  1439. modeset = &fb_helper->crtc_info[i].mode_set;
  1440. if (modeset->num_connectors == 0) {
  1441. BUG_ON(modeset->fb);
  1442. if (modeset->mode)
  1443. drm_mode_destroy(dev, modeset->mode);
  1444. modeset->mode = NULL;
  1445. }
  1446. }
  1447. out:
  1448. kfree(crtcs);
  1449. kfree(modes);
  1450. kfree(offsets);
  1451. kfree(enabled);
  1452. }
  1453. /**
  1454. * drm_fb_helper_initial_config - setup a sane initial connector configuration
  1455. * @fb_helper: fb_helper device struct
  1456. * @bpp_sel: bpp value to use for the framebuffer configuration
  1457. *
  1458. * Scans the CRTCs and connectors and tries to put together an initial setup.
  1459. * At the moment, this is a cloned configuration across all heads with
  1460. * a new framebuffer object as the backing store.
  1461. *
  1462. * Note that this also registers the fbdev and so allows userspace to call into
  1463. * the driver through the fbdev interfaces.
  1464. *
  1465. * This function will call down into the ->fb_probe callback to let
  1466. * the driver allocate and initialize the fbdev info structure and the drm
  1467. * framebuffer used to back the fbdev. drm_fb_helper_fill_var() and
  1468. * drm_fb_helper_fill_fix() are provided as helpers to setup simple default
  1469. * values for the fbdev info structure.
  1470. *
  1471. * RETURNS:
  1472. * Zero if everything went ok, nonzero otherwise.
  1473. */
  1474. bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel)
  1475. {
  1476. struct drm_device *dev = fb_helper->dev;
  1477. int count = 0;
  1478. mutex_lock(&dev->mode_config.mutex);
  1479. count = drm_fb_helper_probe_connector_modes(fb_helper,
  1480. dev->mode_config.max_width,
  1481. dev->mode_config.max_height);
  1482. mutex_unlock(&dev->mode_config.mutex);
  1483. /*
  1484. * we shouldn't end up with no modes here.
  1485. */
  1486. if (count == 0)
  1487. dev_info(fb_helper->dev->dev, "No connectors reported connected with modes\n");
  1488. drm_setup_crtcs(fb_helper);
  1489. return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
  1490. }
  1491. EXPORT_SYMBOL(drm_fb_helper_initial_config);
  1492. /**
  1493. * drm_fb_helper_hotplug_event - respond to a hotplug notification by
  1494. * probing all the outputs attached to the fb
  1495. * @fb_helper: the drm_fb_helper
  1496. *
  1497. * Scan the connectors attached to the fb_helper and try to put together a
  1498. * setup after *notification of a change in output configuration.
  1499. *
  1500. * Called at runtime, takes the mode config locks to be able to check/change the
  1501. * modeset configuration. Must be run from process context (which usually means
  1502. * either the output polling work or a work item launched from the driver's
  1503. * hotplug interrupt).
  1504. *
  1505. * Note that drivers may call this even before calling
  1506. * drm_fb_helper_initial_config but only aftert drm_fb_helper_init. This allows
  1507. * for a race-free fbcon setup and will make sure that the fbdev emulation will
  1508. * not miss any hotplug events.
  1509. *
  1510. * RETURNS:
  1511. * 0 on success and a non-zero error code otherwise.
  1512. */
  1513. int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
  1514. {
  1515. struct drm_device *dev = fb_helper->dev;
  1516. u32 max_width, max_height;
  1517. mutex_lock(&fb_helper->dev->mode_config.mutex);
  1518. if (!fb_helper->fb || !drm_fb_helper_is_bound(fb_helper)) {
  1519. fb_helper->delayed_hotplug = true;
  1520. mutex_unlock(&fb_helper->dev->mode_config.mutex);
  1521. return 0;
  1522. }
  1523. DRM_DEBUG_KMS("\n");
  1524. max_width = fb_helper->fb->width;
  1525. max_height = fb_helper->fb->height;
  1526. drm_fb_helper_probe_connector_modes(fb_helper, max_width, max_height);
  1527. mutex_unlock(&fb_helper->dev->mode_config.mutex);
  1528. drm_modeset_lock_all(dev);
  1529. drm_setup_crtcs(fb_helper);
  1530. drm_modeset_unlock_all(dev);
  1531. drm_fb_helper_set_par(fb_helper->fbdev);
  1532. return 0;
  1533. }
  1534. EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
  1535. /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT)
  1536. * but the module doesn't depend on any fb console symbols. At least
  1537. * attempt to load fbcon to avoid leaving the system without a usable console.
  1538. */
  1539. #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT)
  1540. static int __init drm_fb_helper_modinit(void)
  1541. {
  1542. const char *name = "fbcon";
  1543. struct module *fbcon;
  1544. mutex_lock(&module_mutex);
  1545. fbcon = find_module(name);
  1546. mutex_unlock(&module_mutex);
  1547. if (!fbcon)
  1548. request_module_nowait(name);
  1549. return 0;
  1550. }
  1551. module_init(drm_fb_helper_modinit);
  1552. #endif