drm_fb_helper.c 51 KB

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