drm_connector.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911
  1. /*
  2. * Copyright (c) 2016 Intel Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that copyright
  7. * notice and this permission notice appear in supporting documentation, and
  8. * that the name of the copyright holders not be used in advertising or
  9. * publicity pertaining to distribution of the software without specific,
  10. * written prior permission. The copyright holders make no representations
  11. * about the suitability of this software for any purpose. It is provided "as
  12. * is" without express or implied warranty.
  13. *
  14. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THIS SOFTWARE.
  21. */
  22. #include <drm/drmP.h>
  23. #include <drm/drm_connector.h>
  24. #include <drm/drm_edid.h>
  25. #include <drm/drm_encoder.h>
  26. #include <drm/drm_utils.h>
  27. #include "drm_crtc_internal.h"
  28. #include "drm_internal.h"
  29. /**
  30. * DOC: overview
  31. *
  32. * In DRM connectors are the general abstraction for display sinks, and include
  33. * als fixed panels or anything else that can display pixels in some form. As
  34. * opposed to all other KMS objects representing hardware (like CRTC, encoder or
  35. * plane abstractions) connectors can be hotplugged and unplugged at runtime.
  36. * Hence they are reference-counted using drm_connector_get() and
  37. * drm_connector_put().
  38. *
  39. * KMS driver must create, initialize, register and attach at a &struct
  40. * drm_connector for each such sink. The instance is created as other KMS
  41. * objects and initialized by setting the following fields. The connector is
  42. * initialized with a call to drm_connector_init() with a pointer to the
  43. * &struct drm_connector_funcs and a connector type, and then exposed to
  44. * userspace with a call to drm_connector_register().
  45. *
  46. * Connectors must be attached to an encoder to be used. For devices that map
  47. * connectors to encoders 1:1, the connector should be attached at
  48. * initialization time with a call to drm_mode_connector_attach_encoder(). The
  49. * driver must also set the &drm_connector.encoder field to point to the
  50. * attached encoder.
  51. *
  52. * For connectors which are not fixed (like built-in panels) the driver needs to
  53. * support hotplug notifications. The simplest way to do that is by using the
  54. * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
  55. * hardware support for hotplug interrupts. Connectors with hardware hotplug
  56. * support can instead use e.g. drm_helper_hpd_irq_event().
  57. */
  58. struct drm_conn_prop_enum_list {
  59. int type;
  60. const char *name;
  61. struct ida ida;
  62. };
  63. /*
  64. * Connector and encoder types.
  65. */
  66. static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
  67. { DRM_MODE_CONNECTOR_Unknown, "Unknown" },
  68. { DRM_MODE_CONNECTOR_VGA, "VGA" },
  69. { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
  70. { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
  71. { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
  72. { DRM_MODE_CONNECTOR_Composite, "Composite" },
  73. { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
  74. { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
  75. { DRM_MODE_CONNECTOR_Component, "Component" },
  76. { DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
  77. { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
  78. { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
  79. { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
  80. { DRM_MODE_CONNECTOR_TV, "TV" },
  81. { DRM_MODE_CONNECTOR_eDP, "eDP" },
  82. { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
  83. { DRM_MODE_CONNECTOR_DSI, "DSI" },
  84. { DRM_MODE_CONNECTOR_DPI, "DPI" },
  85. { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
  86. };
  87. void drm_connector_ida_init(void)
  88. {
  89. int i;
  90. for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
  91. ida_init(&drm_connector_enum_list[i].ida);
  92. }
  93. void drm_connector_ida_destroy(void)
  94. {
  95. int i;
  96. for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
  97. ida_destroy(&drm_connector_enum_list[i].ida);
  98. }
  99. /**
  100. * drm_connector_get_cmdline_mode - reads the user's cmdline mode
  101. * @connector: connector to quwery
  102. *
  103. * The kernel supports per-connector configuration of its consoles through
  104. * use of the video= parameter. This function parses that option and
  105. * extracts the user's specified mode (or enable/disable status) for a
  106. * particular connector. This is typically only used during the early fbdev
  107. * setup.
  108. */
  109. static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
  110. {
  111. struct drm_cmdline_mode *mode = &connector->cmdline_mode;
  112. char *option = NULL;
  113. if (fb_get_options(connector->name, &option))
  114. return;
  115. if (!drm_mode_parse_command_line_for_connector(option,
  116. connector,
  117. mode))
  118. return;
  119. if (mode->force) {
  120. DRM_INFO("forcing %s connector %s\n", connector->name,
  121. drm_get_connector_force_name(mode->force));
  122. connector->force = mode->force;
  123. }
  124. DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
  125. connector->name,
  126. mode->xres, mode->yres,
  127. mode->refresh_specified ? mode->refresh : 60,
  128. mode->rb ? " reduced blanking" : "",
  129. mode->margins ? " with margins" : "",
  130. mode->interlace ? " interlaced" : "");
  131. }
  132. static void drm_connector_free(struct kref *kref)
  133. {
  134. struct drm_connector *connector =
  135. container_of(kref, struct drm_connector, base.refcount);
  136. struct drm_device *dev = connector->dev;
  137. drm_mode_object_unregister(dev, &connector->base);
  138. connector->funcs->destroy(connector);
  139. }
  140. void drm_connector_free_work_fn(struct work_struct *work)
  141. {
  142. struct drm_connector *connector, *n;
  143. struct drm_device *dev =
  144. container_of(work, struct drm_device, mode_config.connector_free_work);
  145. struct drm_mode_config *config = &dev->mode_config;
  146. unsigned long flags;
  147. struct llist_node *freed;
  148. spin_lock_irqsave(&config->connector_list_lock, flags);
  149. freed = llist_del_all(&config->connector_free_list);
  150. spin_unlock_irqrestore(&config->connector_list_lock, flags);
  151. llist_for_each_entry_safe(connector, n, freed, free_node) {
  152. drm_mode_object_unregister(dev, &connector->base);
  153. connector->funcs->destroy(connector);
  154. }
  155. }
  156. /**
  157. * drm_connector_init - Init a preallocated connector
  158. * @dev: DRM device
  159. * @connector: the connector to init
  160. * @funcs: callbacks for this connector
  161. * @connector_type: user visible type of the connector
  162. *
  163. * Initialises a preallocated connector. Connectors should be
  164. * subclassed as part of driver connector objects.
  165. *
  166. * Returns:
  167. * Zero on success, error code on failure.
  168. */
  169. int drm_connector_init(struct drm_device *dev,
  170. struct drm_connector *connector,
  171. const struct drm_connector_funcs *funcs,
  172. int connector_type)
  173. {
  174. struct drm_mode_config *config = &dev->mode_config;
  175. int ret;
  176. struct ida *connector_ida =
  177. &drm_connector_enum_list[connector_type].ida;
  178. WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
  179. (!funcs->atomic_destroy_state ||
  180. !funcs->atomic_duplicate_state));
  181. ret = __drm_mode_object_add(dev, &connector->base,
  182. DRM_MODE_OBJECT_CONNECTOR,
  183. false, drm_connector_free);
  184. if (ret)
  185. return ret;
  186. connector->base.properties = &connector->properties;
  187. connector->dev = dev;
  188. connector->funcs = funcs;
  189. /* connector index is used with 32bit bitmasks */
  190. ret = ida_simple_get(&config->connector_ida, 0, 32, GFP_KERNEL);
  191. if (ret < 0) {
  192. DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
  193. drm_connector_enum_list[connector_type].name,
  194. ret);
  195. goto out_put;
  196. }
  197. connector->index = ret;
  198. ret = 0;
  199. connector->connector_type = connector_type;
  200. connector->connector_type_id =
  201. ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
  202. if (connector->connector_type_id < 0) {
  203. ret = connector->connector_type_id;
  204. goto out_put_id;
  205. }
  206. connector->name =
  207. kasprintf(GFP_KERNEL, "%s-%d",
  208. drm_connector_enum_list[connector_type].name,
  209. connector->connector_type_id);
  210. if (!connector->name) {
  211. ret = -ENOMEM;
  212. goto out_put_type_id;
  213. }
  214. INIT_LIST_HEAD(&connector->probed_modes);
  215. INIT_LIST_HEAD(&connector->modes);
  216. mutex_init(&connector->mutex);
  217. connector->edid_blob_ptr = NULL;
  218. connector->status = connector_status_unknown;
  219. connector->display_info.panel_orientation =
  220. DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
  221. drm_connector_get_cmdline_mode(connector);
  222. /* We should add connectors at the end to avoid upsetting the connector
  223. * index too much. */
  224. spin_lock_irq(&config->connector_list_lock);
  225. list_add_tail(&connector->head, &config->connector_list);
  226. config->num_connector++;
  227. spin_unlock_irq(&config->connector_list_lock);
  228. if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
  229. connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
  230. drm_object_attach_property(&connector->base,
  231. config->edid_property,
  232. 0);
  233. drm_object_attach_property(&connector->base,
  234. config->dpms_property, 0);
  235. drm_object_attach_property(&connector->base,
  236. config->link_status_property,
  237. 0);
  238. drm_object_attach_property(&connector->base,
  239. config->non_desktop_property,
  240. 0);
  241. if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
  242. drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
  243. }
  244. connector->debugfs_entry = NULL;
  245. out_put_type_id:
  246. if (ret)
  247. ida_simple_remove(connector_ida, connector->connector_type_id);
  248. out_put_id:
  249. if (ret)
  250. ida_simple_remove(&config->connector_ida, connector->index);
  251. out_put:
  252. if (ret)
  253. drm_mode_object_unregister(dev, &connector->base);
  254. return ret;
  255. }
  256. EXPORT_SYMBOL(drm_connector_init);
  257. /**
  258. * drm_mode_connector_attach_encoder - attach a connector to an encoder
  259. * @connector: connector to attach
  260. * @encoder: encoder to attach @connector to
  261. *
  262. * This function links up a connector to an encoder. Note that the routing
  263. * restrictions between encoders and crtcs are exposed to userspace through the
  264. * possible_clones and possible_crtcs bitmasks.
  265. *
  266. * Returns:
  267. * Zero on success, negative errno on failure.
  268. */
  269. int drm_mode_connector_attach_encoder(struct drm_connector *connector,
  270. struct drm_encoder *encoder)
  271. {
  272. int i;
  273. /*
  274. * In the past, drivers have attempted to model the static association
  275. * of connector to encoder in simple connector/encoder devices using a
  276. * direct assignment of connector->encoder = encoder. This connection
  277. * is a logical one and the responsibility of the core, so drivers are
  278. * expected not to mess with this.
  279. *
  280. * Note that the error return should've been enough here, but a large
  281. * majority of drivers ignores the return value, so add in a big WARN
  282. * to get people's attention.
  283. */
  284. if (WARN_ON(connector->encoder))
  285. return -EINVAL;
  286. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  287. if (connector->encoder_ids[i] == 0) {
  288. connector->encoder_ids[i] = encoder->base.id;
  289. return 0;
  290. }
  291. }
  292. return -ENOMEM;
  293. }
  294. EXPORT_SYMBOL(drm_mode_connector_attach_encoder);
  295. static void drm_mode_remove(struct drm_connector *connector,
  296. struct drm_display_mode *mode)
  297. {
  298. list_del(&mode->head);
  299. drm_mode_destroy(connector->dev, mode);
  300. }
  301. /**
  302. * drm_connector_cleanup - cleans up an initialised connector
  303. * @connector: connector to cleanup
  304. *
  305. * Cleans up the connector but doesn't free the object.
  306. */
  307. void drm_connector_cleanup(struct drm_connector *connector)
  308. {
  309. struct drm_device *dev = connector->dev;
  310. struct drm_display_mode *mode, *t;
  311. /* The connector should have been removed from userspace long before
  312. * it is finally destroyed.
  313. */
  314. if (WARN_ON(connector->registered))
  315. drm_connector_unregister(connector);
  316. if (connector->tile_group) {
  317. drm_mode_put_tile_group(dev, connector->tile_group);
  318. connector->tile_group = NULL;
  319. }
  320. list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
  321. drm_mode_remove(connector, mode);
  322. list_for_each_entry_safe(mode, t, &connector->modes, head)
  323. drm_mode_remove(connector, mode);
  324. ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida,
  325. connector->connector_type_id);
  326. ida_simple_remove(&dev->mode_config.connector_ida,
  327. connector->index);
  328. kfree(connector->display_info.bus_formats);
  329. drm_mode_object_unregister(dev, &connector->base);
  330. kfree(connector->name);
  331. connector->name = NULL;
  332. spin_lock_irq(&dev->mode_config.connector_list_lock);
  333. list_del(&connector->head);
  334. dev->mode_config.num_connector--;
  335. spin_unlock_irq(&dev->mode_config.connector_list_lock);
  336. WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
  337. if (connector->state && connector->funcs->atomic_destroy_state)
  338. connector->funcs->atomic_destroy_state(connector,
  339. connector->state);
  340. mutex_destroy(&connector->mutex);
  341. memset(connector, 0, sizeof(*connector));
  342. }
  343. EXPORT_SYMBOL(drm_connector_cleanup);
  344. /**
  345. * drm_connector_register - register a connector
  346. * @connector: the connector to register
  347. *
  348. * Register userspace interfaces for a connector
  349. *
  350. * Returns:
  351. * Zero on success, error code on failure.
  352. */
  353. int drm_connector_register(struct drm_connector *connector)
  354. {
  355. int ret = 0;
  356. if (!connector->dev->registered)
  357. return 0;
  358. mutex_lock(&connector->mutex);
  359. if (connector->registered)
  360. goto unlock;
  361. ret = drm_sysfs_connector_add(connector);
  362. if (ret)
  363. goto unlock;
  364. ret = drm_debugfs_connector_add(connector);
  365. if (ret) {
  366. goto err_sysfs;
  367. }
  368. if (connector->funcs->late_register) {
  369. ret = connector->funcs->late_register(connector);
  370. if (ret)
  371. goto err_debugfs;
  372. }
  373. drm_mode_object_register(connector->dev, &connector->base);
  374. connector->registered = true;
  375. goto unlock;
  376. err_debugfs:
  377. drm_debugfs_connector_remove(connector);
  378. err_sysfs:
  379. drm_sysfs_connector_remove(connector);
  380. unlock:
  381. mutex_unlock(&connector->mutex);
  382. return ret;
  383. }
  384. EXPORT_SYMBOL(drm_connector_register);
  385. /**
  386. * drm_connector_unregister - unregister a connector
  387. * @connector: the connector to unregister
  388. *
  389. * Unregister userspace interfaces for a connector
  390. */
  391. void drm_connector_unregister(struct drm_connector *connector)
  392. {
  393. mutex_lock(&connector->mutex);
  394. if (!connector->registered) {
  395. mutex_unlock(&connector->mutex);
  396. return;
  397. }
  398. if (connector->funcs->early_unregister)
  399. connector->funcs->early_unregister(connector);
  400. drm_sysfs_connector_remove(connector);
  401. drm_debugfs_connector_remove(connector);
  402. connector->registered = false;
  403. mutex_unlock(&connector->mutex);
  404. }
  405. EXPORT_SYMBOL(drm_connector_unregister);
  406. void drm_connector_unregister_all(struct drm_device *dev)
  407. {
  408. struct drm_connector *connector;
  409. struct drm_connector_list_iter conn_iter;
  410. drm_connector_list_iter_begin(dev, &conn_iter);
  411. drm_for_each_connector_iter(connector, &conn_iter)
  412. drm_connector_unregister(connector);
  413. drm_connector_list_iter_end(&conn_iter);
  414. }
  415. int drm_connector_register_all(struct drm_device *dev)
  416. {
  417. struct drm_connector *connector;
  418. struct drm_connector_list_iter conn_iter;
  419. int ret = 0;
  420. drm_connector_list_iter_begin(dev, &conn_iter);
  421. drm_for_each_connector_iter(connector, &conn_iter) {
  422. ret = drm_connector_register(connector);
  423. if (ret)
  424. break;
  425. }
  426. drm_connector_list_iter_end(&conn_iter);
  427. if (ret)
  428. drm_connector_unregister_all(dev);
  429. return ret;
  430. }
  431. /**
  432. * drm_get_connector_status_name - return a string for connector status
  433. * @status: connector status to compute name of
  434. *
  435. * In contrast to the other drm_get_*_name functions this one here returns a
  436. * const pointer and hence is threadsafe.
  437. */
  438. const char *drm_get_connector_status_name(enum drm_connector_status status)
  439. {
  440. if (status == connector_status_connected)
  441. return "connected";
  442. else if (status == connector_status_disconnected)
  443. return "disconnected";
  444. else
  445. return "unknown";
  446. }
  447. EXPORT_SYMBOL(drm_get_connector_status_name);
  448. /**
  449. * drm_get_connector_force_name - return a string for connector force
  450. * @force: connector force to get name of
  451. *
  452. * Returns: const pointer to name.
  453. */
  454. const char *drm_get_connector_force_name(enum drm_connector_force force)
  455. {
  456. switch (force) {
  457. case DRM_FORCE_UNSPECIFIED:
  458. return "unspecified";
  459. case DRM_FORCE_OFF:
  460. return "off";
  461. case DRM_FORCE_ON:
  462. return "on";
  463. case DRM_FORCE_ON_DIGITAL:
  464. return "digital";
  465. default:
  466. return "unknown";
  467. }
  468. }
  469. #ifdef CONFIG_LOCKDEP
  470. static struct lockdep_map connector_list_iter_dep_map = {
  471. .name = "drm_connector_list_iter"
  472. };
  473. #endif
  474. /**
  475. * drm_connector_list_iter_begin - initialize a connector_list iterator
  476. * @dev: DRM device
  477. * @iter: connector_list iterator
  478. *
  479. * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
  480. * must always be cleaned up again by calling drm_connector_list_iter_end().
  481. * Iteration itself happens using drm_connector_list_iter_next() or
  482. * drm_for_each_connector_iter().
  483. */
  484. void drm_connector_list_iter_begin(struct drm_device *dev,
  485. struct drm_connector_list_iter *iter)
  486. {
  487. iter->dev = dev;
  488. iter->conn = NULL;
  489. lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
  490. }
  491. EXPORT_SYMBOL(drm_connector_list_iter_begin);
  492. /*
  493. * Extra-safe connector put function that works in any context. Should only be
  494. * used from the connector_iter functions, where we never really expect to
  495. * actually release the connector when dropping our final reference.
  496. */
  497. static void
  498. __drm_connector_put_safe(struct drm_connector *conn)
  499. {
  500. struct drm_mode_config *config = &conn->dev->mode_config;
  501. lockdep_assert_held(&config->connector_list_lock);
  502. if (!refcount_dec_and_test(&conn->base.refcount.refcount))
  503. return;
  504. llist_add(&conn->free_node, &config->connector_free_list);
  505. schedule_work(&config->connector_free_work);
  506. }
  507. /**
  508. * drm_connector_list_iter_next - return next connector
  509. * @iter: connectr_list iterator
  510. *
  511. * Returns the next connector for @iter, or NULL when the list walk has
  512. * completed.
  513. */
  514. struct drm_connector *
  515. drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
  516. {
  517. struct drm_connector *old_conn = iter->conn;
  518. struct drm_mode_config *config = &iter->dev->mode_config;
  519. struct list_head *lhead;
  520. unsigned long flags;
  521. spin_lock_irqsave(&config->connector_list_lock, flags);
  522. lhead = old_conn ? &old_conn->head : &config->connector_list;
  523. do {
  524. if (lhead->next == &config->connector_list) {
  525. iter->conn = NULL;
  526. break;
  527. }
  528. lhead = lhead->next;
  529. iter->conn = list_entry(lhead, struct drm_connector, head);
  530. /* loop until it's not a zombie connector */
  531. } while (!kref_get_unless_zero(&iter->conn->base.refcount));
  532. if (old_conn)
  533. __drm_connector_put_safe(old_conn);
  534. spin_unlock_irqrestore(&config->connector_list_lock, flags);
  535. return iter->conn;
  536. }
  537. EXPORT_SYMBOL(drm_connector_list_iter_next);
  538. /**
  539. * drm_connector_list_iter_end - tear down a connector_list iterator
  540. * @iter: connector_list iterator
  541. *
  542. * Tears down @iter and releases any resources (like &drm_connector references)
  543. * acquired while walking the list. This must always be called, both when the
  544. * iteration completes fully or when it was aborted without walking the entire
  545. * list.
  546. */
  547. void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
  548. {
  549. struct drm_mode_config *config = &iter->dev->mode_config;
  550. unsigned long flags;
  551. iter->dev = NULL;
  552. if (iter->conn) {
  553. spin_lock_irqsave(&config->connector_list_lock, flags);
  554. __drm_connector_put_safe(iter->conn);
  555. spin_unlock_irqrestore(&config->connector_list_lock, flags);
  556. }
  557. lock_release(&connector_list_iter_dep_map, 0, _RET_IP_);
  558. }
  559. EXPORT_SYMBOL(drm_connector_list_iter_end);
  560. static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
  561. { SubPixelUnknown, "Unknown" },
  562. { SubPixelHorizontalRGB, "Horizontal RGB" },
  563. { SubPixelHorizontalBGR, "Horizontal BGR" },
  564. { SubPixelVerticalRGB, "Vertical RGB" },
  565. { SubPixelVerticalBGR, "Vertical BGR" },
  566. { SubPixelNone, "None" },
  567. };
  568. /**
  569. * drm_get_subpixel_order_name - return a string for a given subpixel enum
  570. * @order: enum of subpixel_order
  571. *
  572. * Note you could abuse this and return something out of bounds, but that
  573. * would be a caller error. No unscrubbed user data should make it here.
  574. */
  575. const char *drm_get_subpixel_order_name(enum subpixel_order order)
  576. {
  577. return drm_subpixel_enum_list[order].name;
  578. }
  579. EXPORT_SYMBOL(drm_get_subpixel_order_name);
  580. static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
  581. { DRM_MODE_DPMS_ON, "On" },
  582. { DRM_MODE_DPMS_STANDBY, "Standby" },
  583. { DRM_MODE_DPMS_SUSPEND, "Suspend" },
  584. { DRM_MODE_DPMS_OFF, "Off" }
  585. };
  586. DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
  587. static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
  588. { DRM_MODE_LINK_STATUS_GOOD, "Good" },
  589. { DRM_MODE_LINK_STATUS_BAD, "Bad" },
  590. };
  591. /**
  592. * drm_display_info_set_bus_formats - set the supported bus formats
  593. * @info: display info to store bus formats in
  594. * @formats: array containing the supported bus formats
  595. * @num_formats: the number of entries in the fmts array
  596. *
  597. * Store the supported bus formats in display info structure.
  598. * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
  599. * a full list of available formats.
  600. */
  601. int drm_display_info_set_bus_formats(struct drm_display_info *info,
  602. const u32 *formats,
  603. unsigned int num_formats)
  604. {
  605. u32 *fmts = NULL;
  606. if (!formats && num_formats)
  607. return -EINVAL;
  608. if (formats && num_formats) {
  609. fmts = kmemdup(formats, sizeof(*formats) * num_formats,
  610. GFP_KERNEL);
  611. if (!fmts)
  612. return -ENOMEM;
  613. }
  614. kfree(info->bus_formats);
  615. info->bus_formats = fmts;
  616. info->num_bus_formats = num_formats;
  617. return 0;
  618. }
  619. EXPORT_SYMBOL(drm_display_info_set_bus_formats);
  620. /* Optional connector properties. */
  621. static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
  622. { DRM_MODE_SCALE_NONE, "None" },
  623. { DRM_MODE_SCALE_FULLSCREEN, "Full" },
  624. { DRM_MODE_SCALE_CENTER, "Center" },
  625. { DRM_MODE_SCALE_ASPECT, "Full aspect" },
  626. };
  627. static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
  628. { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
  629. { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
  630. { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
  631. };
  632. static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
  633. { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
  634. { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
  635. { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
  636. { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
  637. { DRM_MODE_CONTENT_TYPE_GAME, "Game" },
  638. };
  639. static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
  640. { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" },
  641. { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" },
  642. { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" },
  643. { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" },
  644. };
  645. static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
  646. { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
  647. { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
  648. { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
  649. };
  650. DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
  651. static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
  652. { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
  653. { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
  654. { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
  655. };
  656. DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
  657. drm_dvi_i_subconnector_enum_list)
  658. static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
  659. { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
  660. { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
  661. { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
  662. { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
  663. { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
  664. };
  665. DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
  666. static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
  667. { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
  668. { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
  669. { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
  670. { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
  671. { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
  672. };
  673. DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
  674. drm_tv_subconnector_enum_list)
  675. static struct drm_prop_enum_list drm_cp_enum_list[] = {
  676. { DRM_MODE_CONTENT_PROTECTION_UNDESIRED, "Undesired" },
  677. { DRM_MODE_CONTENT_PROTECTION_DESIRED, "Desired" },
  678. { DRM_MODE_CONTENT_PROTECTION_ENABLED, "Enabled" },
  679. };
  680. DRM_ENUM_NAME_FN(drm_get_content_protection_name, drm_cp_enum_list)
  681. /**
  682. * DOC: standard connector properties
  683. *
  684. * DRM connectors have a few standardized properties:
  685. *
  686. * EDID:
  687. * Blob property which contains the current EDID read from the sink. This
  688. * is useful to parse sink identification information like vendor, model
  689. * and serial. Drivers should update this property by calling
  690. * drm_mode_connector_update_edid_property(), usually after having parsed
  691. * the EDID using drm_add_edid_modes(). Userspace cannot change this
  692. * property.
  693. * DPMS:
  694. * Legacy property for setting the power state of the connector. For atomic
  695. * drivers this is only provided for backwards compatibility with existing
  696. * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
  697. * connector is linked to. Drivers should never set this property directly,
  698. * it is handled by the DRM core by calling the &drm_connector_funcs.dpms
  699. * callback. For atomic drivers the remapping to the "ACTIVE" property is
  700. * implemented in the DRM core. This is the only standard connector
  701. * property that userspace can change.
  702. *
  703. * Note that this property cannot be set through the MODE_ATOMIC ioctl,
  704. * userspace must use "ACTIVE" on the CRTC instead.
  705. *
  706. * WARNING:
  707. *
  708. * For userspace also running on legacy drivers the "DPMS" semantics are a
  709. * lot more complicated. First, userspace cannot rely on the "DPMS" value
  710. * returned by the GETCONNECTOR actually reflecting reality, because many
  711. * drivers fail to update it. For atomic drivers this is taken care of in
  712. * drm_atomic_helper_update_legacy_modeset_state().
  713. *
  714. * The second issue is that the DPMS state is only well-defined when the
  715. * connector is connected to a CRTC. In atomic the DRM core enforces that
  716. * "ACTIVE" is off in such a case, no such checks exists for "DPMS".
  717. *
  718. * Finally, when enabling an output using the legacy SETCONFIG ioctl then
  719. * "DPMS" is forced to ON. But see above, that might not be reflected in
  720. * the software value on legacy drivers.
  721. *
  722. * Summarizing: Only set "DPMS" when the connector is known to be enabled,
  723. * assume that a successful SETCONFIG call also sets "DPMS" to on, and
  724. * never read back the value of "DPMS" because it can be incorrect.
  725. * PATH:
  726. * Connector path property to identify how this sink is physically
  727. * connected. Used by DP MST. This should be set by calling
  728. * drm_mode_connector_set_path_property(), in the case of DP MST with the
  729. * path property the MST manager created. Userspace cannot change this
  730. * property.
  731. * TILE:
  732. * Connector tile group property to indicate how a set of DRM connector
  733. * compose together into one logical screen. This is used by both high-res
  734. * external screens (often only using a single cable, but exposing multiple
  735. * DP MST sinks), or high-res integrated panels (like dual-link DSI) which
  736. * are not gen-locked. Note that for tiled panels which are genlocked, like
  737. * dual-link LVDS or dual-link DSI, the driver should try to not expose the
  738. * tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
  739. * should update this value using drm_mode_connector_set_tile_property().
  740. * Userspace cannot change this property.
  741. * link-status:
  742. * Connector link-status property to indicate the status of link. The
  743. * default value of link-status is "GOOD". If something fails during or
  744. * after modeset, the kernel driver may set this to "BAD" and issue a
  745. * hotplug uevent. Drivers should update this value using
  746. * drm_mode_connector_set_link_status_property().
  747. * non_desktop:
  748. * Indicates the output should be ignored for purposes of displaying a
  749. * standard desktop environment or console. This is most likely because
  750. * the output device is not rectilinear.
  751. * Content Protection:
  752. * This property is used by userspace to request the kernel protect future
  753. * content communicated over the link. When requested, kernel will apply
  754. * the appropriate means of protection (most often HDCP), and use the
  755. * property to tell userspace the protection is active.
  756. *
  757. * Drivers can set this up by calling
  758. * drm_connector_attach_content_protection_property() on initialization.
  759. *
  760. * The value of this property can be one of the following:
  761. *
  762. * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
  763. * The link is not protected, content is transmitted in the clear.
  764. * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
  765. * Userspace has requested content protection, but the link is not
  766. * currently protected. When in this state, kernel should enable
  767. * Content Protection as soon as possible.
  768. * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
  769. * Userspace has requested content protection, and the link is
  770. * protected. Only the driver can set the property to this value.
  771. * If userspace attempts to set to ENABLED, kernel will return
  772. * -EINVAL.
  773. *
  774. * A few guidelines:
  775. *
  776. * - DESIRED state should be preserved until userspace de-asserts it by
  777. * setting the property to UNDESIRED. This means ENABLED should only
  778. * transition to UNDESIRED when the user explicitly requests it.
  779. * - If the state is DESIRED, kernel should attempt to re-authenticate the
  780. * link whenever possible. This includes across disable/enable, dpms,
  781. * hotplug, downstream device changes, link status failures, etc..
  782. * - Userspace is responsible for polling the property to determine when
  783. * the value transitions from ENABLED to DESIRED. This signifies the link
  784. * is no longer protected and userspace should take appropriate action
  785. * (whatever that might be).
  786. *
  787. * Connectors also have one standardized atomic property:
  788. *
  789. * CRTC_ID:
  790. * Mode object ID of the &drm_crtc this connector should be connected to.
  791. *
  792. * Connectors for LCD panels may also have one standardized property:
  793. *
  794. * panel orientation:
  795. * On some devices the LCD panel is mounted in the casing in such a way
  796. * that the up/top side of the panel does not match with the top side of
  797. * the device. Userspace can use this property to check for this.
  798. * Note that input coordinates from touchscreens (input devices with
  799. * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
  800. * coordinates, so if userspace rotates the picture to adjust for
  801. * the orientation it must also apply the same transformation to the
  802. * touchscreen input coordinates. This property is initialized by calling
  803. * drm_connector_init_panel_orientation_property().
  804. *
  805. * scaling mode:
  806. * This property defines how a non-native mode is upscaled to the native
  807. * mode of an LCD panel:
  808. *
  809. * None:
  810. * No upscaling happens, scaling is left to the panel. Not all
  811. * drivers expose this mode.
  812. * Full:
  813. * The output is upscaled to the full resolution of the panel,
  814. * ignoring the aspect ratio.
  815. * Center:
  816. * No upscaling happens, the output is centered within the native
  817. * resolution the panel.
  818. * Full aspect:
  819. * The output is upscaled to maximize either the width or height
  820. * while retaining the aspect ratio.
  821. *
  822. * This property should be set up by calling
  823. * drm_connector_attach_scaling_mode_property(). Note that drivers
  824. * can also expose this property to external outputs, in which case they
  825. * must support "None", which should be the default (since external screens
  826. * have a built-in scaler).
  827. */
  828. int drm_connector_create_standard_properties(struct drm_device *dev)
  829. {
  830. struct drm_property *prop;
  831. prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
  832. DRM_MODE_PROP_IMMUTABLE,
  833. "EDID", 0);
  834. if (!prop)
  835. return -ENOMEM;
  836. dev->mode_config.edid_property = prop;
  837. prop = drm_property_create_enum(dev, 0,
  838. "DPMS", drm_dpms_enum_list,
  839. ARRAY_SIZE(drm_dpms_enum_list));
  840. if (!prop)
  841. return -ENOMEM;
  842. dev->mode_config.dpms_property = prop;
  843. prop = drm_property_create(dev,
  844. DRM_MODE_PROP_BLOB |
  845. DRM_MODE_PROP_IMMUTABLE,
  846. "PATH", 0);
  847. if (!prop)
  848. return -ENOMEM;
  849. dev->mode_config.path_property = prop;
  850. prop = drm_property_create(dev,
  851. DRM_MODE_PROP_BLOB |
  852. DRM_MODE_PROP_IMMUTABLE,
  853. "TILE", 0);
  854. if (!prop)
  855. return -ENOMEM;
  856. dev->mode_config.tile_property = prop;
  857. prop = drm_property_create_enum(dev, 0, "link-status",
  858. drm_link_status_enum_list,
  859. ARRAY_SIZE(drm_link_status_enum_list));
  860. if (!prop)
  861. return -ENOMEM;
  862. dev->mode_config.link_status_property = prop;
  863. prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
  864. if (!prop)
  865. return -ENOMEM;
  866. dev->mode_config.non_desktop_property = prop;
  867. return 0;
  868. }
  869. /**
  870. * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
  871. * @dev: DRM device
  872. *
  873. * Called by a driver the first time a DVI-I connector is made.
  874. */
  875. int drm_mode_create_dvi_i_properties(struct drm_device *dev)
  876. {
  877. struct drm_property *dvi_i_selector;
  878. struct drm_property *dvi_i_subconnector;
  879. if (dev->mode_config.dvi_i_select_subconnector_property)
  880. return 0;
  881. dvi_i_selector =
  882. drm_property_create_enum(dev, 0,
  883. "select subconnector",
  884. drm_dvi_i_select_enum_list,
  885. ARRAY_SIZE(drm_dvi_i_select_enum_list));
  886. dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
  887. dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
  888. "subconnector",
  889. drm_dvi_i_subconnector_enum_list,
  890. ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
  891. dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
  892. return 0;
  893. }
  894. EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
  895. /**
  896. * DOC: HDMI connector properties
  897. *
  898. * content type (HDMI specific):
  899. * Indicates content type setting to be used in HDMI infoframes to indicate
  900. * content type for the external device, so that it adjusts it's display
  901. * settings accordingly.
  902. *
  903. * The value of this property can be one of the following:
  904. *
  905. * No Data:
  906. * Content type is unknown
  907. * Graphics:
  908. * Content type is graphics
  909. * Photo:
  910. * Content type is photo
  911. * Cinema:
  912. * Content type is cinema
  913. * Game:
  914. * Content type is game
  915. *
  916. * Drivers can set up this property by calling
  917. * drm_connector_attach_content_type_property(). Decoding to
  918. * infoframe values is done through
  919. * drm_hdmi_get_content_type_from_property() and
  920. * drm_hdmi_get_itc_bit_from_property().
  921. */
  922. /**
  923. * drm_connector_attach_content_type_property - attach content-type property
  924. * @connector: connector to attach content type property on.
  925. *
  926. * Called by a driver the first time a HDMI connector is made.
  927. */
  928. int drm_connector_attach_content_type_property(struct drm_connector *connector)
  929. {
  930. if (!drm_mode_create_content_type_property(connector->dev))
  931. drm_object_attach_property(&connector->base,
  932. connector->dev->mode_config.content_type_property,
  933. DRM_MODE_CONTENT_TYPE_NO_DATA);
  934. return 0;
  935. }
  936. EXPORT_SYMBOL(drm_connector_attach_content_type_property);
  937. /**
  938. * drm_hdmi_avi_infoframe_content_type() - fill the HDMI AVI infoframe
  939. * content type information, based
  940. * on correspondent DRM property.
  941. * @frame: HDMI AVI infoframe
  942. * @conn_state: DRM display connector state
  943. *
  944. */
  945. void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame,
  946. const struct drm_connector_state *conn_state)
  947. {
  948. switch (conn_state->content_type) {
  949. case DRM_MODE_CONTENT_TYPE_GRAPHICS:
  950. frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
  951. break;
  952. case DRM_MODE_CONTENT_TYPE_CINEMA:
  953. frame->content_type = HDMI_CONTENT_TYPE_CINEMA;
  954. break;
  955. case DRM_MODE_CONTENT_TYPE_GAME:
  956. frame->content_type = HDMI_CONTENT_TYPE_GAME;
  957. break;
  958. case DRM_MODE_CONTENT_TYPE_PHOTO:
  959. frame->content_type = HDMI_CONTENT_TYPE_PHOTO;
  960. break;
  961. default:
  962. /* Graphics is the default(0) */
  963. frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
  964. }
  965. frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA;
  966. }
  967. EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type);
  968. /**
  969. * drm_create_tv_properties - create TV specific connector properties
  970. * @dev: DRM device
  971. * @num_modes: number of different TV formats (modes) supported
  972. * @modes: array of pointers to strings containing name of each format
  973. *
  974. * Called by a driver's TV initialization routine, this function creates
  975. * the TV specific connector properties for a given device. Caller is
  976. * responsible for allocating a list of format names and passing them to
  977. * this routine.
  978. */
  979. int drm_mode_create_tv_properties(struct drm_device *dev,
  980. unsigned int num_modes,
  981. const char * const modes[])
  982. {
  983. struct drm_property *tv_selector;
  984. struct drm_property *tv_subconnector;
  985. unsigned int i;
  986. if (dev->mode_config.tv_select_subconnector_property)
  987. return 0;
  988. /*
  989. * Basic connector properties
  990. */
  991. tv_selector = drm_property_create_enum(dev, 0,
  992. "select subconnector",
  993. drm_tv_select_enum_list,
  994. ARRAY_SIZE(drm_tv_select_enum_list));
  995. if (!tv_selector)
  996. goto nomem;
  997. dev->mode_config.tv_select_subconnector_property = tv_selector;
  998. tv_subconnector =
  999. drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
  1000. "subconnector",
  1001. drm_tv_subconnector_enum_list,
  1002. ARRAY_SIZE(drm_tv_subconnector_enum_list));
  1003. if (!tv_subconnector)
  1004. goto nomem;
  1005. dev->mode_config.tv_subconnector_property = tv_subconnector;
  1006. /*
  1007. * Other, TV specific properties: margins & TV modes.
  1008. */
  1009. dev->mode_config.tv_left_margin_property =
  1010. drm_property_create_range(dev, 0, "left margin", 0, 100);
  1011. if (!dev->mode_config.tv_left_margin_property)
  1012. goto nomem;
  1013. dev->mode_config.tv_right_margin_property =
  1014. drm_property_create_range(dev, 0, "right margin", 0, 100);
  1015. if (!dev->mode_config.tv_right_margin_property)
  1016. goto nomem;
  1017. dev->mode_config.tv_top_margin_property =
  1018. drm_property_create_range(dev, 0, "top margin", 0, 100);
  1019. if (!dev->mode_config.tv_top_margin_property)
  1020. goto nomem;
  1021. dev->mode_config.tv_bottom_margin_property =
  1022. drm_property_create_range(dev, 0, "bottom margin", 0, 100);
  1023. if (!dev->mode_config.tv_bottom_margin_property)
  1024. goto nomem;
  1025. dev->mode_config.tv_mode_property =
  1026. drm_property_create(dev, DRM_MODE_PROP_ENUM,
  1027. "mode", num_modes);
  1028. if (!dev->mode_config.tv_mode_property)
  1029. goto nomem;
  1030. for (i = 0; i < num_modes; i++)
  1031. drm_property_add_enum(dev->mode_config.tv_mode_property,
  1032. i, modes[i]);
  1033. dev->mode_config.tv_brightness_property =
  1034. drm_property_create_range(dev, 0, "brightness", 0, 100);
  1035. if (!dev->mode_config.tv_brightness_property)
  1036. goto nomem;
  1037. dev->mode_config.tv_contrast_property =
  1038. drm_property_create_range(dev, 0, "contrast", 0, 100);
  1039. if (!dev->mode_config.tv_contrast_property)
  1040. goto nomem;
  1041. dev->mode_config.tv_flicker_reduction_property =
  1042. drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
  1043. if (!dev->mode_config.tv_flicker_reduction_property)
  1044. goto nomem;
  1045. dev->mode_config.tv_overscan_property =
  1046. drm_property_create_range(dev, 0, "overscan", 0, 100);
  1047. if (!dev->mode_config.tv_overscan_property)
  1048. goto nomem;
  1049. dev->mode_config.tv_saturation_property =
  1050. drm_property_create_range(dev, 0, "saturation", 0, 100);
  1051. if (!dev->mode_config.tv_saturation_property)
  1052. goto nomem;
  1053. dev->mode_config.tv_hue_property =
  1054. drm_property_create_range(dev, 0, "hue", 0, 100);
  1055. if (!dev->mode_config.tv_hue_property)
  1056. goto nomem;
  1057. return 0;
  1058. nomem:
  1059. return -ENOMEM;
  1060. }
  1061. EXPORT_SYMBOL(drm_mode_create_tv_properties);
  1062. /**
  1063. * drm_mode_create_scaling_mode_property - create scaling mode property
  1064. * @dev: DRM device
  1065. *
  1066. * Called by a driver the first time it's needed, must be attached to desired
  1067. * connectors.
  1068. *
  1069. * Atomic drivers should use drm_connector_attach_scaling_mode_property()
  1070. * instead to correctly assign &drm_connector_state.picture_aspect_ratio
  1071. * in the atomic state.
  1072. */
  1073. int drm_mode_create_scaling_mode_property(struct drm_device *dev)
  1074. {
  1075. struct drm_property *scaling_mode;
  1076. if (dev->mode_config.scaling_mode_property)
  1077. return 0;
  1078. scaling_mode =
  1079. drm_property_create_enum(dev, 0, "scaling mode",
  1080. drm_scaling_mode_enum_list,
  1081. ARRAY_SIZE(drm_scaling_mode_enum_list));
  1082. dev->mode_config.scaling_mode_property = scaling_mode;
  1083. return 0;
  1084. }
  1085. EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
  1086. /**
  1087. * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
  1088. * @connector: connector to attach scaling mode property on.
  1089. * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
  1090. *
  1091. * This is used to add support for scaling mode to atomic drivers.
  1092. * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio
  1093. * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
  1094. *
  1095. * This is the atomic version of drm_mode_create_scaling_mode_property().
  1096. *
  1097. * Returns:
  1098. * Zero on success, negative errno on failure.
  1099. */
  1100. int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
  1101. u32 scaling_mode_mask)
  1102. {
  1103. struct drm_device *dev = connector->dev;
  1104. struct drm_property *scaling_mode_property;
  1105. int i;
  1106. const unsigned valid_scaling_mode_mask =
  1107. (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
  1108. if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
  1109. scaling_mode_mask & ~valid_scaling_mode_mask))
  1110. return -EINVAL;
  1111. scaling_mode_property =
  1112. drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
  1113. hweight32(scaling_mode_mask));
  1114. if (!scaling_mode_property)
  1115. return -ENOMEM;
  1116. for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
  1117. int ret;
  1118. if (!(BIT(i) & scaling_mode_mask))
  1119. continue;
  1120. ret = drm_property_add_enum(scaling_mode_property,
  1121. drm_scaling_mode_enum_list[i].type,
  1122. drm_scaling_mode_enum_list[i].name);
  1123. if (ret) {
  1124. drm_property_destroy(dev, scaling_mode_property);
  1125. return ret;
  1126. }
  1127. }
  1128. drm_object_attach_property(&connector->base,
  1129. scaling_mode_property, 0);
  1130. connector->scaling_mode_property = scaling_mode_property;
  1131. return 0;
  1132. }
  1133. EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
  1134. /**
  1135. * drm_connector_attach_content_protection_property - attach content protection
  1136. * property
  1137. *
  1138. * @connector: connector to attach CP property on.
  1139. *
  1140. * This is used to add support for content protection on select connectors.
  1141. * Content Protection is intentionally vague to allow for different underlying
  1142. * technologies, however it is most implemented by HDCP.
  1143. *
  1144. * The content protection will be set to &drm_connector_state.content_protection
  1145. *
  1146. * Returns:
  1147. * Zero on success, negative errno on failure.
  1148. */
  1149. int drm_connector_attach_content_protection_property(
  1150. struct drm_connector *connector)
  1151. {
  1152. struct drm_device *dev = connector->dev;
  1153. struct drm_property *prop;
  1154. prop = drm_property_create_enum(dev, 0, "Content Protection",
  1155. drm_cp_enum_list,
  1156. ARRAY_SIZE(drm_cp_enum_list));
  1157. if (!prop)
  1158. return -ENOMEM;
  1159. drm_object_attach_property(&connector->base, prop,
  1160. DRM_MODE_CONTENT_PROTECTION_UNDESIRED);
  1161. connector->content_protection_property = prop;
  1162. return 0;
  1163. }
  1164. EXPORT_SYMBOL(drm_connector_attach_content_protection_property);
  1165. /**
  1166. * drm_mode_create_aspect_ratio_property - create aspect ratio property
  1167. * @dev: DRM device
  1168. *
  1169. * Called by a driver the first time it's needed, must be attached to desired
  1170. * connectors.
  1171. *
  1172. * Returns:
  1173. * Zero on success, negative errno on failure.
  1174. */
  1175. int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
  1176. {
  1177. if (dev->mode_config.aspect_ratio_property)
  1178. return 0;
  1179. dev->mode_config.aspect_ratio_property =
  1180. drm_property_create_enum(dev, 0, "aspect ratio",
  1181. drm_aspect_ratio_enum_list,
  1182. ARRAY_SIZE(drm_aspect_ratio_enum_list));
  1183. if (dev->mode_config.aspect_ratio_property == NULL)
  1184. return -ENOMEM;
  1185. return 0;
  1186. }
  1187. EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
  1188. /**
  1189. * drm_mode_create_content_type_property - create content type property
  1190. * @dev: DRM device
  1191. *
  1192. * Called by a driver the first time it's needed, must be attached to desired
  1193. * connectors.
  1194. *
  1195. * Returns:
  1196. * Zero on success, negative errno on failure.
  1197. */
  1198. int drm_mode_create_content_type_property(struct drm_device *dev)
  1199. {
  1200. if (dev->mode_config.content_type_property)
  1201. return 0;
  1202. dev->mode_config.content_type_property =
  1203. drm_property_create_enum(dev, 0, "content type",
  1204. drm_content_type_enum_list,
  1205. ARRAY_SIZE(drm_content_type_enum_list));
  1206. if (dev->mode_config.content_type_property == NULL)
  1207. return -ENOMEM;
  1208. return 0;
  1209. }
  1210. EXPORT_SYMBOL(drm_mode_create_content_type_property);
  1211. /**
  1212. * drm_mode_create_suggested_offset_properties - create suggests offset properties
  1213. * @dev: DRM device
  1214. *
  1215. * Create the the suggested x/y offset property for connectors.
  1216. */
  1217. int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
  1218. {
  1219. if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
  1220. return 0;
  1221. dev->mode_config.suggested_x_property =
  1222. drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
  1223. dev->mode_config.suggested_y_property =
  1224. drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
  1225. if (dev->mode_config.suggested_x_property == NULL ||
  1226. dev->mode_config.suggested_y_property == NULL)
  1227. return -ENOMEM;
  1228. return 0;
  1229. }
  1230. EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
  1231. /**
  1232. * drm_mode_connector_set_path_property - set tile property on connector
  1233. * @connector: connector to set property on.
  1234. * @path: path to use for property; must not be NULL.
  1235. *
  1236. * This creates a property to expose to userspace to specify a
  1237. * connector path. This is mainly used for DisplayPort MST where
  1238. * connectors have a topology and we want to allow userspace to give
  1239. * them more meaningful names.
  1240. *
  1241. * Returns:
  1242. * Zero on success, negative errno on failure.
  1243. */
  1244. int drm_mode_connector_set_path_property(struct drm_connector *connector,
  1245. const char *path)
  1246. {
  1247. struct drm_device *dev = connector->dev;
  1248. int ret;
  1249. ret = drm_property_replace_global_blob(dev,
  1250. &connector->path_blob_ptr,
  1251. strlen(path) + 1,
  1252. path,
  1253. &connector->base,
  1254. dev->mode_config.path_property);
  1255. return ret;
  1256. }
  1257. EXPORT_SYMBOL(drm_mode_connector_set_path_property);
  1258. /**
  1259. * drm_mode_connector_set_tile_property - set tile property on connector
  1260. * @connector: connector to set property on.
  1261. *
  1262. * This looks up the tile information for a connector, and creates a
  1263. * property for userspace to parse if it exists. The property is of
  1264. * the form of 8 integers using ':' as a separator.
  1265. *
  1266. * Returns:
  1267. * Zero on success, errno on failure.
  1268. */
  1269. int drm_mode_connector_set_tile_property(struct drm_connector *connector)
  1270. {
  1271. struct drm_device *dev = connector->dev;
  1272. char tile[256];
  1273. int ret;
  1274. if (!connector->has_tile) {
  1275. ret = drm_property_replace_global_blob(dev,
  1276. &connector->tile_blob_ptr,
  1277. 0,
  1278. NULL,
  1279. &connector->base,
  1280. dev->mode_config.tile_property);
  1281. return ret;
  1282. }
  1283. snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
  1284. connector->tile_group->id, connector->tile_is_single_monitor,
  1285. connector->num_h_tile, connector->num_v_tile,
  1286. connector->tile_h_loc, connector->tile_v_loc,
  1287. connector->tile_h_size, connector->tile_v_size);
  1288. ret = drm_property_replace_global_blob(dev,
  1289. &connector->tile_blob_ptr,
  1290. strlen(tile) + 1,
  1291. tile,
  1292. &connector->base,
  1293. dev->mode_config.tile_property);
  1294. return ret;
  1295. }
  1296. EXPORT_SYMBOL(drm_mode_connector_set_tile_property);
  1297. /**
  1298. * drm_mode_connector_update_edid_property - update the edid property of a connector
  1299. * @connector: drm connector
  1300. * @edid: new value of the edid property
  1301. *
  1302. * This function creates a new blob modeset object and assigns its id to the
  1303. * connector's edid property.
  1304. *
  1305. * Returns:
  1306. * Zero on success, negative errno on failure.
  1307. */
  1308. int drm_mode_connector_update_edid_property(struct drm_connector *connector,
  1309. const struct edid *edid)
  1310. {
  1311. struct drm_device *dev = connector->dev;
  1312. size_t size = 0;
  1313. int ret;
  1314. /* ignore requests to set edid when overridden */
  1315. if (connector->override_edid)
  1316. return 0;
  1317. if (edid)
  1318. size = EDID_LENGTH * (1 + edid->extensions);
  1319. /* Set the display info, using edid if available, otherwise
  1320. * reseting the values to defaults. This duplicates the work
  1321. * done in drm_add_edid_modes, but that function is not
  1322. * consistently called before this one in all drivers and the
  1323. * computation is cheap enough that it seems better to
  1324. * duplicate it rather than attempt to ensure some arbitrary
  1325. * ordering of calls.
  1326. */
  1327. if (edid)
  1328. drm_add_display_info(connector, edid);
  1329. else
  1330. drm_reset_display_info(connector);
  1331. drm_object_property_set_value(&connector->base,
  1332. dev->mode_config.non_desktop_property,
  1333. connector->display_info.non_desktop);
  1334. ret = drm_property_replace_global_blob(dev,
  1335. &connector->edid_blob_ptr,
  1336. size,
  1337. edid,
  1338. &connector->base,
  1339. dev->mode_config.edid_property);
  1340. return ret;
  1341. }
  1342. EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
  1343. /**
  1344. * drm_mode_connector_set_link_status_property - Set link status property of a connector
  1345. * @connector: drm connector
  1346. * @link_status: new value of link status property (0: Good, 1: Bad)
  1347. *
  1348. * In usual working scenario, this link status property will always be set to
  1349. * "GOOD". If something fails during or after a mode set, the kernel driver
  1350. * may set this link status property to "BAD". The caller then needs to send a
  1351. * hotplug uevent for userspace to re-check the valid modes through
  1352. * GET_CONNECTOR_IOCTL and retry modeset.
  1353. *
  1354. * Note: Drivers cannot rely on userspace to support this property and
  1355. * issue a modeset. As such, they may choose to handle issues (like
  1356. * re-training a link) without userspace's intervention.
  1357. *
  1358. * The reason for adding this property is to handle link training failures, but
  1359. * it is not limited to DP or link training. For example, if we implement
  1360. * asynchronous setcrtc, this property can be used to report any failures in that.
  1361. */
  1362. void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
  1363. uint64_t link_status)
  1364. {
  1365. struct drm_device *dev = connector->dev;
  1366. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  1367. connector->state->link_status = link_status;
  1368. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  1369. }
  1370. EXPORT_SYMBOL(drm_mode_connector_set_link_status_property);
  1371. /**
  1372. * drm_connector_init_panel_orientation_property -
  1373. * initialize the connecters panel_orientation property
  1374. * @connector: connector for which to init the panel-orientation property.
  1375. * @width: width in pixels of the panel, used for panel quirk detection
  1376. * @height: height in pixels of the panel, used for panel quirk detection
  1377. *
  1378. * This function should only be called for built-in panels, after setting
  1379. * connector->display_info.panel_orientation first (if known).
  1380. *
  1381. * This function will check for platform specific (e.g. DMI based) quirks
  1382. * overriding display_info.panel_orientation first, then if panel_orientation
  1383. * is not DRM_MODE_PANEL_ORIENTATION_UNKNOWN it will attach the
  1384. * "panel orientation" property to the connector.
  1385. *
  1386. * Returns:
  1387. * Zero on success, negative errno on failure.
  1388. */
  1389. int drm_connector_init_panel_orientation_property(
  1390. struct drm_connector *connector, int width, int height)
  1391. {
  1392. struct drm_device *dev = connector->dev;
  1393. struct drm_display_info *info = &connector->display_info;
  1394. struct drm_property *prop;
  1395. int orientation_quirk;
  1396. orientation_quirk = drm_get_panel_orientation_quirk(width, height);
  1397. if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
  1398. info->panel_orientation = orientation_quirk;
  1399. if (info->panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
  1400. return 0;
  1401. prop = dev->mode_config.panel_orientation_property;
  1402. if (!prop) {
  1403. prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
  1404. "panel orientation",
  1405. drm_panel_orientation_enum_list,
  1406. ARRAY_SIZE(drm_panel_orientation_enum_list));
  1407. if (!prop)
  1408. return -ENOMEM;
  1409. dev->mode_config.panel_orientation_property = prop;
  1410. }
  1411. drm_object_attach_property(&connector->base, prop,
  1412. info->panel_orientation);
  1413. return 0;
  1414. }
  1415. EXPORT_SYMBOL(drm_connector_init_panel_orientation_property);
  1416. int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,
  1417. struct drm_property *property,
  1418. uint64_t value)
  1419. {
  1420. int ret = -EINVAL;
  1421. struct drm_connector *connector = obj_to_connector(obj);
  1422. /* Do DPMS ourselves */
  1423. if (property == connector->dev->mode_config.dpms_property) {
  1424. ret = (*connector->funcs->dpms)(connector, (int)value);
  1425. } else if (connector->funcs->set_property)
  1426. ret = connector->funcs->set_property(connector, property, value);
  1427. if (!ret)
  1428. drm_object_property_set_value(&connector->base, property, value);
  1429. return ret;
  1430. }
  1431. int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
  1432. void *data, struct drm_file *file_priv)
  1433. {
  1434. struct drm_mode_connector_set_property *conn_set_prop = data;
  1435. struct drm_mode_obj_set_property obj_set_prop = {
  1436. .value = conn_set_prop->value,
  1437. .prop_id = conn_set_prop->prop_id,
  1438. .obj_id = conn_set_prop->connector_id,
  1439. .obj_type = DRM_MODE_OBJECT_CONNECTOR
  1440. };
  1441. /* It does all the locking and checking we need */
  1442. return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
  1443. }
  1444. static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
  1445. {
  1446. /* For atomic drivers only state objects are synchronously updated and
  1447. * protected by modeset locks, so check those first. */
  1448. if (connector->state)
  1449. return connector->state->best_encoder;
  1450. return connector->encoder;
  1451. }
  1452. static bool
  1453. drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
  1454. const struct list_head *export_list,
  1455. const struct drm_file *file_priv)
  1456. {
  1457. /*
  1458. * If user-space hasn't configured the driver to expose the stereo 3D
  1459. * modes, don't expose them.
  1460. */
  1461. if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
  1462. return false;
  1463. /*
  1464. * If user-space hasn't configured the driver to expose the modes
  1465. * with aspect-ratio, don't expose them. However if such a mode
  1466. * is unique, let it be exposed, but reset the aspect-ratio flags
  1467. * while preparing the list of user-modes.
  1468. */
  1469. if (!file_priv->aspect_ratio_allowed) {
  1470. struct drm_display_mode *mode_itr;
  1471. list_for_each_entry(mode_itr, export_list, export_head)
  1472. if (drm_mode_match(mode_itr, mode,
  1473. DRM_MODE_MATCH_TIMINGS |
  1474. DRM_MODE_MATCH_CLOCK |
  1475. DRM_MODE_MATCH_FLAGS |
  1476. DRM_MODE_MATCH_3D_FLAGS))
  1477. return false;
  1478. }
  1479. return true;
  1480. }
  1481. int drm_mode_getconnector(struct drm_device *dev, void *data,
  1482. struct drm_file *file_priv)
  1483. {
  1484. struct drm_mode_get_connector *out_resp = data;
  1485. struct drm_connector *connector;
  1486. struct drm_encoder *encoder;
  1487. struct drm_display_mode *mode;
  1488. int mode_count = 0;
  1489. int encoders_count = 0;
  1490. int ret = 0;
  1491. int copied = 0;
  1492. int i;
  1493. struct drm_mode_modeinfo u_mode;
  1494. struct drm_mode_modeinfo __user *mode_ptr;
  1495. uint32_t __user *encoder_ptr;
  1496. LIST_HEAD(export_list);
  1497. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  1498. return -EINVAL;
  1499. memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
  1500. connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
  1501. if (!connector)
  1502. return -ENOENT;
  1503. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++)
  1504. if (connector->encoder_ids[i] != 0)
  1505. encoders_count++;
  1506. if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
  1507. copied = 0;
  1508. encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
  1509. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  1510. if (connector->encoder_ids[i] != 0) {
  1511. if (put_user(connector->encoder_ids[i],
  1512. encoder_ptr + copied)) {
  1513. ret = -EFAULT;
  1514. goto out;
  1515. }
  1516. copied++;
  1517. }
  1518. }
  1519. }
  1520. out_resp->count_encoders = encoders_count;
  1521. out_resp->connector_id = connector->base.id;
  1522. out_resp->connector_type = connector->connector_type;
  1523. out_resp->connector_type_id = connector->connector_type_id;
  1524. mutex_lock(&dev->mode_config.mutex);
  1525. if (out_resp->count_modes == 0) {
  1526. connector->funcs->fill_modes(connector,
  1527. dev->mode_config.max_width,
  1528. dev->mode_config.max_height);
  1529. }
  1530. out_resp->mm_width = connector->display_info.width_mm;
  1531. out_resp->mm_height = connector->display_info.height_mm;
  1532. out_resp->subpixel = connector->display_info.subpixel_order;
  1533. out_resp->connection = connector->status;
  1534. /* delayed so we get modes regardless of pre-fill_modes state */
  1535. list_for_each_entry(mode, &connector->modes, head)
  1536. if (drm_mode_expose_to_userspace(mode, &export_list,
  1537. file_priv)) {
  1538. list_add_tail(&mode->export_head, &export_list);
  1539. mode_count++;
  1540. }
  1541. /*
  1542. * This ioctl is called twice, once to determine how much space is
  1543. * needed, and the 2nd time to fill it.
  1544. * The modes that need to be exposed to the user are maintained in the
  1545. * 'export_list'. When the ioctl is called first time to determine the,
  1546. * space, the export_list gets filled, to find the no.of modes. In the
  1547. * 2nd time, the user modes are filled, one by one from the export_list.
  1548. */
  1549. if ((out_resp->count_modes >= mode_count) && mode_count) {
  1550. copied = 0;
  1551. mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
  1552. list_for_each_entry(mode, &export_list, export_head) {
  1553. drm_mode_convert_to_umode(&u_mode, mode);
  1554. /*
  1555. * Reset aspect ratio flags of user-mode, if modes with
  1556. * aspect-ratio are not supported.
  1557. */
  1558. if (!file_priv->aspect_ratio_allowed)
  1559. u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
  1560. if (copy_to_user(mode_ptr + copied,
  1561. &u_mode, sizeof(u_mode))) {
  1562. ret = -EFAULT;
  1563. mutex_unlock(&dev->mode_config.mutex);
  1564. goto out;
  1565. }
  1566. copied++;
  1567. }
  1568. }
  1569. out_resp->count_modes = mode_count;
  1570. mutex_unlock(&dev->mode_config.mutex);
  1571. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  1572. encoder = drm_connector_get_encoder(connector);
  1573. if (encoder)
  1574. out_resp->encoder_id = encoder->base.id;
  1575. else
  1576. out_resp->encoder_id = 0;
  1577. /* Only grab properties after probing, to make sure EDID and other
  1578. * properties reflect the latest status. */
  1579. ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
  1580. (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
  1581. (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
  1582. &out_resp->count_props);
  1583. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  1584. out:
  1585. drm_connector_put(connector);
  1586. return ret;
  1587. }
  1588. /**
  1589. * DOC: Tile group
  1590. *
  1591. * Tile groups are used to represent tiled monitors with a unique integer
  1592. * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
  1593. * we store this in a tile group, so we have a common identifier for all tiles
  1594. * in a monitor group. The property is called "TILE". Drivers can manage tile
  1595. * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
  1596. * drm_mode_get_tile_group(). But this is only needed for internal panels where
  1597. * the tile group information is exposed through a non-standard way.
  1598. */
  1599. static void drm_tile_group_free(struct kref *kref)
  1600. {
  1601. struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
  1602. struct drm_device *dev = tg->dev;
  1603. mutex_lock(&dev->mode_config.idr_mutex);
  1604. idr_remove(&dev->mode_config.tile_idr, tg->id);
  1605. mutex_unlock(&dev->mode_config.idr_mutex);
  1606. kfree(tg);
  1607. }
  1608. /**
  1609. * drm_mode_put_tile_group - drop a reference to a tile group.
  1610. * @dev: DRM device
  1611. * @tg: tile group to drop reference to.
  1612. *
  1613. * drop reference to tile group and free if 0.
  1614. */
  1615. void drm_mode_put_tile_group(struct drm_device *dev,
  1616. struct drm_tile_group *tg)
  1617. {
  1618. kref_put(&tg->refcount, drm_tile_group_free);
  1619. }
  1620. EXPORT_SYMBOL(drm_mode_put_tile_group);
  1621. /**
  1622. * drm_mode_get_tile_group - get a reference to an existing tile group
  1623. * @dev: DRM device
  1624. * @topology: 8-bytes unique per monitor.
  1625. *
  1626. * Use the unique bytes to get a reference to an existing tile group.
  1627. *
  1628. * RETURNS:
  1629. * tile group or NULL if not found.
  1630. */
  1631. struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
  1632. char topology[8])
  1633. {
  1634. struct drm_tile_group *tg;
  1635. int id;
  1636. mutex_lock(&dev->mode_config.idr_mutex);
  1637. idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
  1638. if (!memcmp(tg->group_data, topology, 8)) {
  1639. if (!kref_get_unless_zero(&tg->refcount))
  1640. tg = NULL;
  1641. mutex_unlock(&dev->mode_config.idr_mutex);
  1642. return tg;
  1643. }
  1644. }
  1645. mutex_unlock(&dev->mode_config.idr_mutex);
  1646. return NULL;
  1647. }
  1648. EXPORT_SYMBOL(drm_mode_get_tile_group);
  1649. /**
  1650. * drm_mode_create_tile_group - create a tile group from a displayid description
  1651. * @dev: DRM device
  1652. * @topology: 8-bytes unique per monitor.
  1653. *
  1654. * Create a tile group for the unique monitor, and get a unique
  1655. * identifier for the tile group.
  1656. *
  1657. * RETURNS:
  1658. * new tile group or error.
  1659. */
  1660. struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
  1661. char topology[8])
  1662. {
  1663. struct drm_tile_group *tg;
  1664. int ret;
  1665. tg = kzalloc(sizeof(*tg), GFP_KERNEL);
  1666. if (!tg)
  1667. return ERR_PTR(-ENOMEM);
  1668. kref_init(&tg->refcount);
  1669. memcpy(tg->group_data, topology, 8);
  1670. tg->dev = dev;
  1671. mutex_lock(&dev->mode_config.idr_mutex);
  1672. ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
  1673. if (ret >= 0) {
  1674. tg->id = ret;
  1675. } else {
  1676. kfree(tg);
  1677. tg = ERR_PTR(ret);
  1678. }
  1679. mutex_unlock(&dev->mode_config.idr_mutex);
  1680. return tg;
  1681. }
  1682. EXPORT_SYMBOL(drm_mode_create_tile_group);