drm_connector.c 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565
  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/drm_connector.h>
  23. #include <drm/drm_edid.h>
  24. #include <drm/drm_encoder.h>
  25. #include <drm/drm_utils.h>
  26. #include <drm/drm_print.h>
  27. #include <drm/drm_drv.h>
  28. #include <drm/drm_file.h>
  29. #include <drm/drm_sysfs.h>
  30. #include <linux/uaccess.h>
  31. #include "drm_crtc_internal.h"
  32. #include "drm_internal.h"
  33. /**
  34. * DOC: overview
  35. *
  36. * In DRM connectors are the general abstraction for display sinks, and include
  37. * also fixed panels or anything else that can display pixels in some form. As
  38. * opposed to all other KMS objects representing hardware (like CRTC, encoder or
  39. * plane abstractions) connectors can be hotplugged and unplugged at runtime.
  40. * Hence they are reference-counted using drm_connector_get() and
  41. * drm_connector_put().
  42. *
  43. * KMS driver must create, initialize, register and attach at a &struct
  44. * drm_connector for each such sink. The instance is created as other KMS
  45. * objects and initialized by setting the following fields. The connector is
  46. * initialized with a call to drm_connector_init() with a pointer to the
  47. * &struct drm_connector_funcs and a connector type, and then exposed to
  48. * userspace with a call to drm_connector_register().
  49. *
  50. * Connectors must be attached to an encoder to be used. For devices that map
  51. * connectors to encoders 1:1, the connector should be attached at
  52. * initialization time with a call to drm_connector_attach_encoder(). The
  53. * driver must also set the &drm_connector.encoder field to point to the
  54. * attached encoder.
  55. *
  56. * For connectors which are not fixed (like built-in panels) the driver needs to
  57. * support hotplug notifications. The simplest way to do that is by using the
  58. * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
  59. * hardware support for hotplug interrupts. Connectors with hardware hotplug
  60. * support can instead use e.g. drm_helper_hpd_irq_event().
  61. */
  62. struct drm_conn_prop_enum_list {
  63. int type;
  64. const char *name;
  65. struct ida ida;
  66. };
  67. /*
  68. * Connector and encoder types.
  69. */
  70. static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
  71. { DRM_MODE_CONNECTOR_Unknown, "Unknown" },
  72. { DRM_MODE_CONNECTOR_VGA, "VGA" },
  73. { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
  74. { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
  75. { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
  76. { DRM_MODE_CONNECTOR_Composite, "Composite" },
  77. { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
  78. { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
  79. { DRM_MODE_CONNECTOR_Component, "Component" },
  80. { DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
  81. { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
  82. { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
  83. { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
  84. { DRM_MODE_CONNECTOR_TV, "TV" },
  85. { DRM_MODE_CONNECTOR_eDP, "eDP" },
  86. { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
  87. { DRM_MODE_CONNECTOR_DSI, "DSI" },
  88. { DRM_MODE_CONNECTOR_DPI, "DPI" },
  89. { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
  90. { DRM_MODE_CONNECTOR_SPI, "SPI" },
  91. };
  92. void drm_connector_ida_init(void)
  93. {
  94. int i;
  95. for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
  96. ida_init(&drm_connector_enum_list[i].ida);
  97. }
  98. void drm_connector_ida_destroy(void)
  99. {
  100. int i;
  101. for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
  102. ida_destroy(&drm_connector_enum_list[i].ida);
  103. }
  104. /**
  105. * drm_get_connector_type_name - return a string for connector type
  106. * @type: The connector type (DRM_MODE_CONNECTOR_*)
  107. *
  108. * Returns: the name of the connector type, or NULL if the type is not valid.
  109. */
  110. const char *drm_get_connector_type_name(unsigned int type)
  111. {
  112. if (type < ARRAY_SIZE(drm_connector_enum_list))
  113. return drm_connector_enum_list[type].name;
  114. return NULL;
  115. }
  116. EXPORT_SYMBOL(drm_get_connector_type_name);
  117. /**
  118. * drm_connector_get_cmdline_mode - reads the user's cmdline mode
  119. * @connector: connector to query
  120. *
  121. * The kernel supports per-connector configuration of its consoles through
  122. * use of the video= parameter. This function parses that option and
  123. * extracts the user's specified mode (or enable/disable status) for a
  124. * particular connector. This is typically only used during the early fbdev
  125. * setup.
  126. */
  127. static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
  128. {
  129. struct drm_cmdline_mode *mode = &connector->cmdline_mode;
  130. char *option = NULL;
  131. if (fb_get_options(connector->name, &option))
  132. return;
  133. if (!drm_mode_parse_command_line_for_connector(option,
  134. connector,
  135. mode))
  136. return;
  137. if (mode->force) {
  138. DRM_INFO("forcing %s connector %s\n", connector->name,
  139. drm_get_connector_force_name(mode->force));
  140. connector->force = mode->force;
  141. }
  142. if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) {
  143. DRM_INFO("cmdline forces connector %s panel_orientation to %d\n",
  144. connector->name, mode->panel_orientation);
  145. drm_connector_set_panel_orientation(connector,
  146. mode->panel_orientation);
  147. }
  148. DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
  149. connector->name, mode->name,
  150. mode->xres, mode->yres,
  151. mode->refresh_specified ? mode->refresh : 60,
  152. mode->rb ? " reduced blanking" : "",
  153. mode->margins ? " with margins" : "",
  154. mode->interlace ? " interlaced" : "");
  155. }
  156. static void drm_connector_free(struct kref *kref)
  157. {
  158. struct drm_connector *connector =
  159. container_of(kref, struct drm_connector, base.refcount);
  160. struct drm_device *dev = connector->dev;
  161. drm_mode_object_unregister(dev, &connector->base);
  162. connector->funcs->destroy(connector);
  163. }
  164. void drm_connector_free_work_fn(struct work_struct *work)
  165. {
  166. struct drm_connector *connector, *n;
  167. struct drm_device *dev =
  168. container_of(work, struct drm_device, mode_config.connector_free_work);
  169. struct drm_mode_config *config = &dev->mode_config;
  170. unsigned long flags;
  171. struct llist_node *freed;
  172. spin_lock_irqsave(&config->connector_list_lock, flags);
  173. freed = llist_del_all(&config->connector_free_list);
  174. spin_unlock_irqrestore(&config->connector_list_lock, flags);
  175. llist_for_each_entry_safe(connector, n, freed, free_node) {
  176. drm_mode_object_unregister(dev, &connector->base);
  177. connector->funcs->destroy(connector);
  178. }
  179. }
  180. /**
  181. * drm_connector_init - Init a preallocated connector
  182. * @dev: DRM device
  183. * @connector: the connector to init
  184. * @funcs: callbacks for this connector
  185. * @connector_type: user visible type of the connector
  186. *
  187. * Initialises a preallocated connector. Connectors should be
  188. * subclassed as part of driver connector objects.
  189. *
  190. * Returns:
  191. * Zero on success, error code on failure.
  192. */
  193. int drm_connector_init(struct drm_device *dev,
  194. struct drm_connector *connector,
  195. const struct drm_connector_funcs *funcs,
  196. int connector_type)
  197. {
  198. struct drm_mode_config *config = &dev->mode_config;
  199. int ret;
  200. struct ida *connector_ida =
  201. &drm_connector_enum_list[connector_type].ida;
  202. WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
  203. (!funcs->atomic_destroy_state ||
  204. !funcs->atomic_duplicate_state));
  205. ret = __drm_mode_object_add(dev, &connector->base,
  206. DRM_MODE_OBJECT_CONNECTOR,
  207. false, drm_connector_free);
  208. if (ret)
  209. return ret;
  210. connector->base.properties = &connector->properties;
  211. connector->dev = dev;
  212. connector->funcs = funcs;
  213. /* connector index is used with 32bit bitmasks */
  214. ret = ida_simple_get(&config->connector_ida, 0, 32, GFP_KERNEL);
  215. if (ret < 0) {
  216. DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
  217. drm_connector_enum_list[connector_type].name,
  218. ret);
  219. goto out_put;
  220. }
  221. connector->index = ret;
  222. ret = 0;
  223. connector->connector_type = connector_type;
  224. connector->connector_type_id =
  225. ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
  226. if (connector->connector_type_id < 0) {
  227. ret = connector->connector_type_id;
  228. goto out_put_id;
  229. }
  230. connector->name =
  231. kasprintf(GFP_KERNEL, "%s-%d",
  232. drm_connector_enum_list[connector_type].name,
  233. connector->connector_type_id);
  234. if (!connector->name) {
  235. ret = -ENOMEM;
  236. goto out_put_type_id;
  237. }
  238. INIT_LIST_HEAD(&connector->probed_modes);
  239. INIT_LIST_HEAD(&connector->modes);
  240. mutex_init(&connector->mutex);
  241. connector->edid_blob_ptr = NULL;
  242. connector->epoch_counter = 0;
  243. connector->tile_blob_ptr = NULL;
  244. connector->status = connector_status_unknown;
  245. connector->display_info.panel_orientation =
  246. DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
  247. drm_connector_get_cmdline_mode(connector);
  248. /* We should add connectors at the end to avoid upsetting the connector
  249. * index too much. */
  250. spin_lock_irq(&config->connector_list_lock);
  251. list_add_tail(&connector->head, &config->connector_list);
  252. config->num_connector++;
  253. spin_unlock_irq(&config->connector_list_lock);
  254. if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
  255. connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
  256. drm_connector_attach_edid_property(connector);
  257. drm_object_attach_property(&connector->base,
  258. config->dpms_property, 0);
  259. drm_object_attach_property(&connector->base,
  260. config->link_status_property,
  261. 0);
  262. drm_object_attach_property(&connector->base,
  263. config->non_desktop_property,
  264. 0);
  265. drm_object_attach_property(&connector->base,
  266. config->tile_property,
  267. 0);
  268. if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
  269. drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
  270. }
  271. connector->debugfs_entry = NULL;
  272. out_put_type_id:
  273. if (ret)
  274. ida_simple_remove(connector_ida, connector->connector_type_id);
  275. out_put_id:
  276. if (ret)
  277. ida_simple_remove(&config->connector_ida, connector->index);
  278. out_put:
  279. if (ret)
  280. drm_mode_object_unregister(dev, &connector->base);
  281. return ret;
  282. }
  283. EXPORT_SYMBOL(drm_connector_init);
  284. /**
  285. * drm_connector_init_with_ddc - Init a preallocated connector
  286. * @dev: DRM device
  287. * @connector: the connector to init
  288. * @funcs: callbacks for this connector
  289. * @connector_type: user visible type of the connector
  290. * @ddc: pointer to the associated ddc adapter
  291. *
  292. * Initialises a preallocated connector. Connectors should be
  293. * subclassed as part of driver connector objects.
  294. *
  295. * Ensures that the ddc field of the connector is correctly set.
  296. *
  297. * Returns:
  298. * Zero on success, error code on failure.
  299. */
  300. int drm_connector_init_with_ddc(struct drm_device *dev,
  301. struct drm_connector *connector,
  302. const struct drm_connector_funcs *funcs,
  303. int connector_type,
  304. struct i2c_adapter *ddc)
  305. {
  306. int ret;
  307. ret = drm_connector_init(dev, connector, funcs, connector_type);
  308. if (ret)
  309. return ret;
  310. /* provide ddc symlink in sysfs */
  311. connector->ddc = ddc;
  312. return ret;
  313. }
  314. EXPORT_SYMBOL(drm_connector_init_with_ddc);
  315. /**
  316. * drm_connector_attach_edid_property - attach edid property.
  317. * @connector: the connector
  318. *
  319. * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
  320. * edid property attached by default. This function can be used to
  321. * explicitly enable the edid property in these cases.
  322. */
  323. void drm_connector_attach_edid_property(struct drm_connector *connector)
  324. {
  325. struct drm_mode_config *config = &connector->dev->mode_config;
  326. drm_object_attach_property(&connector->base,
  327. config->edid_property,
  328. 0);
  329. }
  330. EXPORT_SYMBOL(drm_connector_attach_edid_property);
  331. /**
  332. * drm_connector_attach_encoder - attach a connector to an encoder
  333. * @connector: connector to attach
  334. * @encoder: encoder to attach @connector to
  335. *
  336. * This function links up a connector to an encoder. Note that the routing
  337. * restrictions between encoders and crtcs are exposed to userspace through the
  338. * possible_clones and possible_crtcs bitmasks.
  339. *
  340. * Returns:
  341. * Zero on success, negative errno on failure.
  342. */
  343. int drm_connector_attach_encoder(struct drm_connector *connector,
  344. struct drm_encoder *encoder)
  345. {
  346. /*
  347. * In the past, drivers have attempted to model the static association
  348. * of connector to encoder in simple connector/encoder devices using a
  349. * direct assignment of connector->encoder = encoder. This connection
  350. * is a logical one and the responsibility of the core, so drivers are
  351. * expected not to mess with this.
  352. *
  353. * Note that the error return should've been enough here, but a large
  354. * majority of drivers ignores the return value, so add in a big WARN
  355. * to get people's attention.
  356. */
  357. if (WARN_ON(connector->encoder))
  358. return -EINVAL;
  359. connector->possible_encoders |= drm_encoder_mask(encoder);
  360. return 0;
  361. }
  362. EXPORT_SYMBOL(drm_connector_attach_encoder);
  363. /**
  364. * drm_connector_has_possible_encoder - check if the connector and encoder are
  365. * associated with each other
  366. * @connector: the connector
  367. * @encoder: the encoder
  368. *
  369. * Returns:
  370. * True if @encoder is one of the possible encoders for @connector.
  371. */
  372. bool drm_connector_has_possible_encoder(struct drm_connector *connector,
  373. struct drm_encoder *encoder)
  374. {
  375. return connector->possible_encoders & drm_encoder_mask(encoder);
  376. }
  377. EXPORT_SYMBOL(drm_connector_has_possible_encoder);
  378. static void drm_mode_remove(struct drm_connector *connector,
  379. struct drm_display_mode *mode)
  380. {
  381. list_del(&mode->head);
  382. drm_mode_destroy(connector->dev, mode);
  383. }
  384. /**
  385. * drm_connector_cleanup - cleans up an initialised connector
  386. * @connector: connector to cleanup
  387. *
  388. * Cleans up the connector but doesn't free the object.
  389. */
  390. void drm_connector_cleanup(struct drm_connector *connector)
  391. {
  392. struct drm_device *dev = connector->dev;
  393. struct drm_display_mode *mode, *t;
  394. /* The connector should have been removed from userspace long before
  395. * it is finally destroyed.
  396. */
  397. if (WARN_ON(connector->registration_state ==
  398. DRM_CONNECTOR_REGISTERED))
  399. drm_connector_unregister(connector);
  400. if (connector->tile_group) {
  401. drm_mode_put_tile_group(dev, connector->tile_group);
  402. connector->tile_group = NULL;
  403. }
  404. list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
  405. drm_mode_remove(connector, mode);
  406. list_for_each_entry_safe(mode, t, &connector->modes, head)
  407. drm_mode_remove(connector, mode);
  408. ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida,
  409. connector->connector_type_id);
  410. ida_simple_remove(&dev->mode_config.connector_ida,
  411. connector->index);
  412. kfree(connector->display_info.bus_formats);
  413. drm_mode_object_unregister(dev, &connector->base);
  414. kfree(connector->name);
  415. connector->name = NULL;
  416. spin_lock_irq(&dev->mode_config.connector_list_lock);
  417. list_del(&connector->head);
  418. dev->mode_config.num_connector--;
  419. spin_unlock_irq(&dev->mode_config.connector_list_lock);
  420. WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
  421. if (connector->state && connector->funcs->atomic_destroy_state)
  422. connector->funcs->atomic_destroy_state(connector,
  423. connector->state);
  424. mutex_destroy(&connector->mutex);
  425. memset(connector, 0, sizeof(*connector));
  426. }
  427. EXPORT_SYMBOL(drm_connector_cleanup);
  428. /**
  429. * drm_connector_register - register a connector
  430. * @connector: the connector to register
  431. *
  432. * Register userspace interfaces for a connector. Only call this for connectors
  433. * which can be hotplugged after drm_dev_register() has been called already,
  434. * e.g. DP MST connectors. All other connectors will be registered automatically
  435. * when calling drm_dev_register().
  436. *
  437. * Returns:
  438. * Zero on success, error code on failure.
  439. */
  440. int drm_connector_register(struct drm_connector *connector)
  441. {
  442. int ret = 0;
  443. if (!connector->dev->registered)
  444. return 0;
  445. mutex_lock(&connector->mutex);
  446. if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
  447. goto unlock;
  448. ret = drm_sysfs_connector_add(connector);
  449. if (ret)
  450. goto unlock;
  451. drm_debugfs_connector_add(connector);
  452. if (connector->funcs->late_register) {
  453. ret = connector->funcs->late_register(connector);
  454. if (ret)
  455. goto err_debugfs;
  456. }
  457. drm_mode_object_register(connector->dev, &connector->base);
  458. connector->registration_state = DRM_CONNECTOR_REGISTERED;
  459. /* Let userspace know we have a new connector */
  460. drm_sysfs_hotplug_event(connector->dev);
  461. goto unlock;
  462. err_debugfs:
  463. drm_debugfs_connector_remove(connector);
  464. drm_sysfs_connector_remove(connector);
  465. unlock:
  466. mutex_unlock(&connector->mutex);
  467. return ret;
  468. }
  469. EXPORT_SYMBOL(drm_connector_register);
  470. /**
  471. * drm_connector_unregister - unregister a connector
  472. * @connector: the connector to unregister
  473. *
  474. * Unregister userspace interfaces for a connector. Only call this for
  475. * connectors which have registered explicitly by calling drm_dev_register(),
  476. * since connectors are unregistered automatically when drm_dev_unregister() is
  477. * called.
  478. */
  479. void drm_connector_unregister(struct drm_connector *connector)
  480. {
  481. mutex_lock(&connector->mutex);
  482. if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
  483. mutex_unlock(&connector->mutex);
  484. return;
  485. }
  486. if (connector->funcs->early_unregister)
  487. connector->funcs->early_unregister(connector);
  488. drm_sysfs_connector_remove(connector);
  489. drm_debugfs_connector_remove(connector);
  490. connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
  491. mutex_unlock(&connector->mutex);
  492. }
  493. EXPORT_SYMBOL(drm_connector_unregister);
  494. void drm_connector_unregister_all(struct drm_device *dev)
  495. {
  496. struct drm_connector *connector;
  497. struct drm_connector_list_iter conn_iter;
  498. drm_connector_list_iter_begin(dev, &conn_iter);
  499. drm_for_each_connector_iter(connector, &conn_iter)
  500. drm_connector_unregister(connector);
  501. drm_connector_list_iter_end(&conn_iter);
  502. }
  503. int drm_connector_register_all(struct drm_device *dev)
  504. {
  505. struct drm_connector *connector;
  506. struct drm_connector_list_iter conn_iter;
  507. int ret = 0;
  508. drm_connector_list_iter_begin(dev, &conn_iter);
  509. drm_for_each_connector_iter(connector, &conn_iter) {
  510. ret = drm_connector_register(connector);
  511. if (ret)
  512. break;
  513. }
  514. drm_connector_list_iter_end(&conn_iter);
  515. if (ret)
  516. drm_connector_unregister_all(dev);
  517. return ret;
  518. }
  519. /**
  520. * drm_get_connector_status_name - return a string for connector status
  521. * @status: connector status to compute name of
  522. *
  523. * In contrast to the other drm_get_*_name functions this one here returns a
  524. * const pointer and hence is threadsafe.
  525. */
  526. const char *drm_get_connector_status_name(enum drm_connector_status status)
  527. {
  528. if (status == connector_status_connected)
  529. return "connected";
  530. else if (status == connector_status_disconnected)
  531. return "disconnected";
  532. else
  533. return "unknown";
  534. }
  535. EXPORT_SYMBOL(drm_get_connector_status_name);
  536. /**
  537. * drm_get_connector_force_name - return a string for connector force
  538. * @force: connector force to get name of
  539. *
  540. * Returns: const pointer to name.
  541. */
  542. const char *drm_get_connector_force_name(enum drm_connector_force force)
  543. {
  544. switch (force) {
  545. case DRM_FORCE_UNSPECIFIED:
  546. return "unspecified";
  547. case DRM_FORCE_OFF:
  548. return "off";
  549. case DRM_FORCE_ON:
  550. return "on";
  551. case DRM_FORCE_ON_DIGITAL:
  552. return "digital";
  553. default:
  554. return "unknown";
  555. }
  556. }
  557. #ifdef CONFIG_LOCKDEP
  558. static struct lockdep_map connector_list_iter_dep_map = {
  559. .name = "drm_connector_list_iter"
  560. };
  561. #endif
  562. /**
  563. * drm_connector_list_iter_begin - initialize a connector_list iterator
  564. * @dev: DRM device
  565. * @iter: connector_list iterator
  566. *
  567. * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
  568. * must always be cleaned up again by calling drm_connector_list_iter_end().
  569. * Iteration itself happens using drm_connector_list_iter_next() or
  570. * drm_for_each_connector_iter().
  571. */
  572. void drm_connector_list_iter_begin(struct drm_device *dev,
  573. struct drm_connector_list_iter *iter)
  574. {
  575. iter->dev = dev;
  576. iter->conn = NULL;
  577. lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
  578. }
  579. EXPORT_SYMBOL(drm_connector_list_iter_begin);
  580. /*
  581. * Extra-safe connector put function that works in any context. Should only be
  582. * used from the connector_iter functions, where we never really expect to
  583. * actually release the connector when dropping our final reference.
  584. */
  585. static void
  586. __drm_connector_put_safe(struct drm_connector *conn)
  587. {
  588. struct drm_mode_config *config = &conn->dev->mode_config;
  589. lockdep_assert_held(&config->connector_list_lock);
  590. if (!refcount_dec_and_test(&conn->base.refcount.refcount))
  591. return;
  592. llist_add(&conn->free_node, &config->connector_free_list);
  593. schedule_work(&config->connector_free_work);
  594. }
  595. /**
  596. * drm_connector_list_iter_next - return next connector
  597. * @iter: connector_list iterator
  598. *
  599. * Returns the next connector for @iter, or NULL when the list walk has
  600. * completed.
  601. */
  602. struct drm_connector *
  603. drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
  604. {
  605. struct drm_connector *old_conn = iter->conn;
  606. struct drm_mode_config *config = &iter->dev->mode_config;
  607. struct list_head *lhead;
  608. unsigned long flags;
  609. spin_lock_irqsave(&config->connector_list_lock, flags);
  610. lhead = old_conn ? &old_conn->head : &config->connector_list;
  611. do {
  612. if (lhead->next == &config->connector_list) {
  613. iter->conn = NULL;
  614. break;
  615. }
  616. lhead = lhead->next;
  617. iter->conn = list_entry(lhead, struct drm_connector, head);
  618. /* loop until it's not a zombie connector */
  619. } while (!kref_get_unless_zero(&iter->conn->base.refcount));
  620. if (old_conn)
  621. __drm_connector_put_safe(old_conn);
  622. spin_unlock_irqrestore(&config->connector_list_lock, flags);
  623. return iter->conn;
  624. }
  625. EXPORT_SYMBOL(drm_connector_list_iter_next);
  626. /**
  627. * drm_connector_list_iter_end - tear down a connector_list iterator
  628. * @iter: connector_list iterator
  629. *
  630. * Tears down @iter and releases any resources (like &drm_connector references)
  631. * acquired while walking the list. This must always be called, both when the
  632. * iteration completes fully or when it was aborted without walking the entire
  633. * list.
  634. */
  635. void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
  636. {
  637. struct drm_mode_config *config = &iter->dev->mode_config;
  638. unsigned long flags;
  639. iter->dev = NULL;
  640. if (iter->conn) {
  641. spin_lock_irqsave(&config->connector_list_lock, flags);
  642. __drm_connector_put_safe(iter->conn);
  643. spin_unlock_irqrestore(&config->connector_list_lock, flags);
  644. }
  645. lock_release(&connector_list_iter_dep_map, _RET_IP_);
  646. }
  647. EXPORT_SYMBOL(drm_connector_list_iter_end);
  648. static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
  649. { SubPixelUnknown, "Unknown" },
  650. { SubPixelHorizontalRGB, "Horizontal RGB" },
  651. { SubPixelHorizontalBGR, "Horizontal BGR" },
  652. { SubPixelVerticalRGB, "Vertical RGB" },
  653. { SubPixelVerticalBGR, "Vertical BGR" },
  654. { SubPixelNone, "None" },
  655. };
  656. /**
  657. * drm_get_subpixel_order_name - return a string for a given subpixel enum
  658. * @order: enum of subpixel_order
  659. *
  660. * Note you could abuse this and return something out of bounds, but that
  661. * would be a caller error. No unscrubbed user data should make it here.
  662. */
  663. const char *drm_get_subpixel_order_name(enum subpixel_order order)
  664. {
  665. return drm_subpixel_enum_list[order].name;
  666. }
  667. EXPORT_SYMBOL(drm_get_subpixel_order_name);
  668. static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
  669. { DRM_MODE_DPMS_ON, "On" },
  670. { DRM_MODE_DPMS_STANDBY, "Standby" },
  671. { DRM_MODE_DPMS_SUSPEND, "Suspend" },
  672. { DRM_MODE_DPMS_OFF, "Off" }
  673. };
  674. DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
  675. static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
  676. { DRM_MODE_LINK_STATUS_GOOD, "Good" },
  677. { DRM_MODE_LINK_STATUS_BAD, "Bad" },
  678. };
  679. /**
  680. * drm_display_info_set_bus_formats - set the supported bus formats
  681. * @info: display info to store bus formats in
  682. * @formats: array containing the supported bus formats
  683. * @num_formats: the number of entries in the fmts array
  684. *
  685. * Store the supported bus formats in display info structure.
  686. * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
  687. * a full list of available formats.
  688. */
  689. int drm_display_info_set_bus_formats(struct drm_display_info *info,
  690. const u32 *formats,
  691. unsigned int num_formats)
  692. {
  693. u32 *fmts = NULL;
  694. if (!formats && num_formats)
  695. return -EINVAL;
  696. if (formats && num_formats) {
  697. fmts = kmemdup(formats, sizeof(*formats) * num_formats,
  698. GFP_KERNEL);
  699. if (!fmts)
  700. return -ENOMEM;
  701. }
  702. kfree(info->bus_formats);
  703. info->bus_formats = fmts;
  704. info->num_bus_formats = num_formats;
  705. return 0;
  706. }
  707. EXPORT_SYMBOL(drm_display_info_set_bus_formats);
  708. /* Optional connector properties. */
  709. static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
  710. { DRM_MODE_SCALE_NONE, "None" },
  711. { DRM_MODE_SCALE_FULLSCREEN, "Full" },
  712. { DRM_MODE_SCALE_CENTER, "Center" },
  713. { DRM_MODE_SCALE_ASPECT, "Full aspect" },
  714. };
  715. static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
  716. { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
  717. { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
  718. { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
  719. };
  720. static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
  721. { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
  722. { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
  723. { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
  724. { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
  725. { DRM_MODE_CONTENT_TYPE_GAME, "Game" },
  726. };
  727. static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
  728. { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" },
  729. { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" },
  730. { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" },
  731. { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" },
  732. };
  733. static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
  734. { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
  735. { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
  736. { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
  737. };
  738. DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
  739. static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
  740. { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */
  741. { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
  742. { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
  743. };
  744. DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
  745. drm_dvi_i_subconnector_enum_list)
  746. static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
  747. { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
  748. { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
  749. { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
  750. { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
  751. { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
  752. };
  753. DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
  754. static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
  755. { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */
  756. { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
  757. { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
  758. { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
  759. { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
  760. };
  761. DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
  762. drm_tv_subconnector_enum_list)
  763. static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = {
  764. { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */
  765. { DRM_MODE_SUBCONNECTOR_VGA, "VGA" }, /* DP */
  766. { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DP */
  767. { DRM_MODE_SUBCONNECTOR_HDMIA, "HDMI" }, /* DP */
  768. { DRM_MODE_SUBCONNECTOR_DisplayPort, "DP" }, /* DP */
  769. { DRM_MODE_SUBCONNECTOR_Wireless, "Wireless" }, /* DP */
  770. { DRM_MODE_SUBCONNECTOR_Native, "Native" }, /* DP */
  771. };
  772. DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name,
  773. drm_dp_subconnector_enum_list)
  774. static const struct drm_prop_enum_list hdmi_colorspaces[] = {
  775. /* For Default case, driver will set the colorspace */
  776. { DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
  777. /* Standard Definition Colorimetry based on CEA 861 */
  778. { DRM_MODE_COLORIMETRY_SMPTE_170M_YCC, "SMPTE_170M_YCC" },
  779. { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
  780. /* Standard Definition Colorimetry based on IEC 61966-2-4 */
  781. { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
  782. /* High Definition Colorimetry based on IEC 61966-2-4 */
  783. { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
  784. /* Colorimetry based on IEC 61966-2-1/Amendment 1 */
  785. { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
  786. /* Colorimetry based on IEC 61966-2-5 [33] */
  787. { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
  788. /* Colorimetry based on IEC 61966-2-5 */
  789. { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
  790. /* Colorimetry based on ITU-R BT.2020 */
  791. { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
  792. /* Colorimetry based on ITU-R BT.2020 */
  793. { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
  794. /* Colorimetry based on ITU-R BT.2020 */
  795. { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
  796. /* Added as part of Additional Colorimetry Extension in 861.G */
  797. { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
  798. { DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, "DCI-P3_RGB_Theater" },
  799. };
  800. /*
  801. * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
  802. * Format Table 2-120
  803. */
  804. static const struct drm_prop_enum_list dp_colorspaces[] = {
  805. /* For Default case, driver will set the colorspace */
  806. { DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
  807. { DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED, "RGB_Wide_Gamut_Fixed_Point" },
  808. /* Colorimetry based on scRGB (IEC 61966-2-2) */
  809. { DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT, "RGB_Wide_Gamut_Floating_Point" },
  810. /* Colorimetry based on IEC 61966-2-5 */
  811. { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
  812. /* Colorimetry based on SMPTE RP 431-2 */
  813. { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
  814. /* Colorimetry based on ITU-R BT.2020 */
  815. { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
  816. { DRM_MODE_COLORIMETRY_BT601_YCC, "BT601_YCC" },
  817. { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
  818. /* Standard Definition Colorimetry based on IEC 61966-2-4 */
  819. { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
  820. /* High Definition Colorimetry based on IEC 61966-2-4 */
  821. { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
  822. /* Colorimetry based on IEC 61966-2-1/Amendment 1 */
  823. { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
  824. /* Colorimetry based on IEC 61966-2-5 [33] */
  825. { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
  826. /* Colorimetry based on ITU-R BT.2020 */
  827. { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
  828. /* Colorimetry based on ITU-R BT.2020 */
  829. { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
  830. };
  831. /**
  832. * DOC: standard connector properties
  833. *
  834. * DRM connectors have a few standardized properties:
  835. *
  836. * EDID:
  837. * Blob property which contains the current EDID read from the sink. This
  838. * is useful to parse sink identification information like vendor, model
  839. * and serial. Drivers should update this property by calling
  840. * drm_connector_update_edid_property(), usually after having parsed
  841. * the EDID using drm_add_edid_modes(). Userspace cannot change this
  842. * property.
  843. * DPMS:
  844. * Legacy property for setting the power state of the connector. For atomic
  845. * drivers this is only provided for backwards compatibility with existing
  846. * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
  847. * connector is linked to. Drivers should never set this property directly,
  848. * it is handled by the DRM core by calling the &drm_connector_funcs.dpms
  849. * callback. For atomic drivers the remapping to the "ACTIVE" property is
  850. * implemented in the DRM core.
  851. *
  852. * Note that this property cannot be set through the MODE_ATOMIC ioctl,
  853. * userspace must use "ACTIVE" on the CRTC instead.
  854. *
  855. * WARNING:
  856. *
  857. * For userspace also running on legacy drivers the "DPMS" semantics are a
  858. * lot more complicated. First, userspace cannot rely on the "DPMS" value
  859. * returned by the GETCONNECTOR actually reflecting reality, because many
  860. * drivers fail to update it. For atomic drivers this is taken care of in
  861. * drm_atomic_helper_update_legacy_modeset_state().
  862. *
  863. * The second issue is that the DPMS state is only well-defined when the
  864. * connector is connected to a CRTC. In atomic the DRM core enforces that
  865. * "ACTIVE" is off in such a case, no such checks exists for "DPMS".
  866. *
  867. * Finally, when enabling an output using the legacy SETCONFIG ioctl then
  868. * "DPMS" is forced to ON. But see above, that might not be reflected in
  869. * the software value on legacy drivers.
  870. *
  871. * Summarizing: Only set "DPMS" when the connector is known to be enabled,
  872. * assume that a successful SETCONFIG call also sets "DPMS" to on, and
  873. * never read back the value of "DPMS" because it can be incorrect.
  874. * PATH:
  875. * Connector path property to identify how this sink is physically
  876. * connected. Used by DP MST. This should be set by calling
  877. * drm_connector_set_path_property(), in the case of DP MST with the
  878. * path property the MST manager created. Userspace cannot change this
  879. * property.
  880. * TILE:
  881. * Connector tile group property to indicate how a set of DRM connector
  882. * compose together into one logical screen. This is used by both high-res
  883. * external screens (often only using a single cable, but exposing multiple
  884. * DP MST sinks), or high-res integrated panels (like dual-link DSI) which
  885. * are not gen-locked. Note that for tiled panels which are genlocked, like
  886. * dual-link LVDS or dual-link DSI, the driver should try to not expose the
  887. * tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers
  888. * should update this value using drm_connector_set_tile_property().
  889. * Userspace cannot change this property.
  890. * link-status:
  891. * Connector link-status property to indicate the status of link. The
  892. * default value of link-status is "GOOD". If something fails during or
  893. * after modeset, the kernel driver may set this to "BAD" and issue a
  894. * hotplug uevent. Drivers should update this value using
  895. * drm_connector_set_link_status_property().
  896. *
  897. * When user-space receives the hotplug uevent and detects a "BAD"
  898. * link-status, the sink doesn't receive pixels anymore (e.g. the screen
  899. * becomes completely black). The list of available modes may have
  900. * changed. User-space is expected to pick a new mode if the current one
  901. * has disappeared and perform a new modeset with link-status set to
  902. * "GOOD" to re-enable the connector.
  903. *
  904. * If multiple connectors share the same CRTC and one of them gets a "BAD"
  905. * link-status, the other are unaffected (ie. the sinks still continue to
  906. * receive pixels).
  907. *
  908. * When user-space performs an atomic commit on a connector with a "BAD"
  909. * link-status without resetting the property to "GOOD", the sink may
  910. * still not receive pixels. When user-space performs an atomic commit
  911. * which resets the link-status property to "GOOD" without the
  912. * ALLOW_MODESET flag set, it might fail because a modeset is required.
  913. *
  914. * User-space can only change link-status to "GOOD", changing it to "BAD"
  915. * is a no-op.
  916. *
  917. * For backwards compatibility with non-atomic userspace the kernel
  918. * tries to automatically set the link-status back to "GOOD" in the
  919. * SETCRTC IOCTL. This might fail if the mode is no longer valid, similar
  920. * to how it might fail if a different screen has been connected in the
  921. * interim.
  922. * non_desktop:
  923. * Indicates the output should be ignored for purposes of displaying a
  924. * standard desktop environment or console. This is most likely because
  925. * the output device is not rectilinear.
  926. * Content Protection:
  927. * This property is used by userspace to request the kernel protect future
  928. * content communicated over the link. When requested, kernel will apply
  929. * the appropriate means of protection (most often HDCP), and use the
  930. * property to tell userspace the protection is active.
  931. *
  932. * Drivers can set this up by calling
  933. * drm_connector_attach_content_protection_property() on initialization.
  934. *
  935. * The value of this property can be one of the following:
  936. *
  937. * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
  938. * The link is not protected, content is transmitted in the clear.
  939. * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
  940. * Userspace has requested content protection, but the link is not
  941. * currently protected. When in this state, kernel should enable
  942. * Content Protection as soon as possible.
  943. * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
  944. * Userspace has requested content protection, and the link is
  945. * protected. Only the driver can set the property to this value.
  946. * If userspace attempts to set to ENABLED, kernel will return
  947. * -EINVAL.
  948. *
  949. * A few guidelines:
  950. *
  951. * - DESIRED state should be preserved until userspace de-asserts it by
  952. * setting the property to UNDESIRED. This means ENABLED should only
  953. * transition to UNDESIRED when the user explicitly requests it.
  954. * - If the state is DESIRED, kernel should attempt to re-authenticate the
  955. * link whenever possible. This includes across disable/enable, dpms,
  956. * hotplug, downstream device changes, link status failures, etc..
  957. * - Kernel sends uevent with the connector id and property id through
  958. * @drm_hdcp_update_content_protection, upon below kernel triggered
  959. * scenarios:
  960. *
  961. * - DESIRED -> ENABLED (authentication success)
  962. * - ENABLED -> DESIRED (termination of authentication)
  963. * - Please note no uevents for userspace triggered property state changes,
  964. * which can't fail such as
  965. *
  966. * - DESIRED/ENABLED -> UNDESIRED
  967. * - UNDESIRED -> DESIRED
  968. * - Userspace is responsible for polling the property or listen to uevents
  969. * to determine when the value transitions from ENABLED to DESIRED.
  970. * This signifies the link is no longer protected and userspace should
  971. * take appropriate action (whatever that might be).
  972. *
  973. * HDCP Content Type:
  974. * This Enum property is used by the userspace to declare the content type
  975. * of the display stream, to kernel. Here display stream stands for any
  976. * display content that userspace intended to display through HDCP
  977. * encryption.
  978. *
  979. * Content Type of a stream is decided by the owner of the stream, as
  980. * "HDCP Type0" or "HDCP Type1".
  981. *
  982. * The value of the property can be one of the below:
  983. * - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0
  984. * - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1
  985. *
  986. * When kernel starts the HDCP authentication (see "Content Protection"
  987. * for details), it uses the content type in "HDCP Content Type"
  988. * for performing the HDCP authentication with the display sink.
  989. *
  990. * Please note in HDCP spec versions, a link can be authenticated with
  991. * HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be
  992. * authenticated with HDCP1.4 only for Content Type 0(though it is implicit
  993. * in nature. As there is no reference for Content Type in HDCP1.4).
  994. *
  995. * HDCP2.2 authentication protocol itself takes the "Content Type" as a
  996. * parameter, which is a input for the DP HDCP2.2 encryption algo.
  997. *
  998. * In case of Type 0 content protection request, kernel driver can choose
  999. * either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for
  1000. * "HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send
  1001. * that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).
  1002. * But if the content is classified as "HDCP Type 1", above mentioned
  1003. * HDCP 2.2 repeater wont send the content to the HDCP sink as it can't
  1004. * authenticate the HDCP1.4 capable sink for "HDCP Type 1".
  1005. *
  1006. * Please note userspace can be ignorant of the HDCP versions used by the
  1007. * kernel driver to achieve the "HDCP Content Type".
  1008. *
  1009. * At current scenario, classifying a content as Type 1 ensures that the
  1010. * content will be displayed only through the HDCP2.2 encrypted link.
  1011. *
  1012. * Note that the HDCP Content Type property is introduced at HDCP 2.2, and
  1013. * defaults to type 0. It is only exposed by drivers supporting HDCP 2.2
  1014. * (hence supporting Type 0 and Type 1). Based on how next versions of
  1015. * HDCP specs are defined content Type could be used for higher versions
  1016. * too.
  1017. *
  1018. * If content type is changed when "Content Protection" is not UNDESIRED,
  1019. * then kernel will disable the HDCP and re-enable with new type in the
  1020. * same atomic commit. And when "Content Protection" is ENABLED, it means
  1021. * that link is HDCP authenticated and encrypted, for the transmission of
  1022. * the Type of stream mentioned at "HDCP Content Type".
  1023. *
  1024. * HDR_OUTPUT_METADATA:
  1025. * Connector property to enable userspace to send HDR Metadata to
  1026. * driver. This metadata is based on the composition and blending
  1027. * policies decided by user, taking into account the hardware and
  1028. * sink capabilities. The driver gets this metadata and creates a
  1029. * Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,
  1030. * SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then
  1031. * sent to sink. This notifies the sink of the upcoming frame's Color
  1032. * Encoding and Luminance parameters.
  1033. *
  1034. * Userspace first need to detect the HDR capabilities of sink by
  1035. * reading and parsing the EDID. Details of HDR metadata for HDMI
  1036. * are added in CTA 861.G spec. For DP , its defined in VESA DP
  1037. * Standard v1.4. It needs to then get the metadata information
  1038. * of the video/game/app content which are encoded in HDR (basically
  1039. * using HDR transfer functions). With this information it needs to
  1040. * decide on a blending policy and compose the relevant
  1041. * layers/overlays into a common format. Once this blending is done,
  1042. * userspace will be aware of the metadata of the composed frame to
  1043. * be send to sink. It then uses this property to communicate this
  1044. * metadata to driver which then make a Infoframe packet and sends
  1045. * to sink based on the type of encoder connected.
  1046. *
  1047. * Userspace will be responsible to do Tone mapping operation in case:
  1048. * - Some layers are HDR and others are SDR
  1049. * - HDR layers luminance is not same as sink
  1050. *
  1051. * It will even need to do colorspace conversion and get all layers
  1052. * to one common colorspace for blending. It can use either GL, Media
  1053. * or display engine to get this done based on the capabilities of the
  1054. * associated hardware.
  1055. *
  1056. * Driver expects metadata to be put in &struct hdr_output_metadata
  1057. * structure from userspace. This is received as blob and stored in
  1058. * &drm_connector_state.hdr_output_metadata. It parses EDID and saves the
  1059. * sink metadata in &struct hdr_sink_metadata, as
  1060. * &drm_connector.hdr_sink_metadata. Driver uses
  1061. * drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,
  1062. * hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of
  1063. * HDMI encoder.
  1064. *
  1065. * max bpc:
  1066. * This range property is used by userspace to limit the bit depth. When
  1067. * used the driver would limit the bpc in accordance with the valid range
  1068. * supported by the hardware and sink. Drivers to use the function
  1069. * drm_connector_attach_max_bpc_property() to create and attach the
  1070. * property to the connector during initialization.
  1071. *
  1072. * Connectors also have one standardized atomic property:
  1073. *
  1074. * CRTC_ID:
  1075. * Mode object ID of the &drm_crtc this connector should be connected to.
  1076. *
  1077. * Connectors for LCD panels may also have one standardized property:
  1078. *
  1079. * panel orientation:
  1080. * On some devices the LCD panel is mounted in the casing in such a way
  1081. * that the up/top side of the panel does not match with the top side of
  1082. * the device. Userspace can use this property to check for this.
  1083. * Note that input coordinates from touchscreens (input devices with
  1084. * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
  1085. * coordinates, so if userspace rotates the picture to adjust for
  1086. * the orientation it must also apply the same transformation to the
  1087. * touchscreen input coordinates. This property is initialized by calling
  1088. * drm_connector_set_panel_orientation() or
  1089. * drm_connector_set_panel_orientation_with_quirk()
  1090. *
  1091. * scaling mode:
  1092. * This property defines how a non-native mode is upscaled to the native
  1093. * mode of an LCD panel:
  1094. *
  1095. * None:
  1096. * No upscaling happens, scaling is left to the panel. Not all
  1097. * drivers expose this mode.
  1098. * Full:
  1099. * The output is upscaled to the full resolution of the panel,
  1100. * ignoring the aspect ratio.
  1101. * Center:
  1102. * No upscaling happens, the output is centered within the native
  1103. * resolution the panel.
  1104. * Full aspect:
  1105. * The output is upscaled to maximize either the width or height
  1106. * while retaining the aspect ratio.
  1107. *
  1108. * This property should be set up by calling
  1109. * drm_connector_attach_scaling_mode_property(). Note that drivers
  1110. * can also expose this property to external outputs, in which case they
  1111. * must support "None", which should be the default (since external screens
  1112. * have a built-in scaler).
  1113. *
  1114. * subconnector:
  1115. * This property is used by DVI-I, TVout and DisplayPort to indicate different
  1116. * connector subtypes. Enum values more or less match with those from main
  1117. * connector types.
  1118. * For DVI-I and TVout there is also a matching property "select subconnector"
  1119. * allowing to switch between signal types.
  1120. * DP subconnector corresponds to a downstream port.
  1121. */
  1122. int drm_connector_create_standard_properties(struct drm_device *dev)
  1123. {
  1124. struct drm_property *prop;
  1125. prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
  1126. DRM_MODE_PROP_IMMUTABLE,
  1127. "EDID", 0);
  1128. if (!prop)
  1129. return -ENOMEM;
  1130. dev->mode_config.edid_property = prop;
  1131. prop = drm_property_create_enum(dev, 0,
  1132. "DPMS", drm_dpms_enum_list,
  1133. ARRAY_SIZE(drm_dpms_enum_list));
  1134. if (!prop)
  1135. return -ENOMEM;
  1136. dev->mode_config.dpms_property = prop;
  1137. prop = drm_property_create(dev,
  1138. DRM_MODE_PROP_BLOB |
  1139. DRM_MODE_PROP_IMMUTABLE,
  1140. "PATH", 0);
  1141. if (!prop)
  1142. return -ENOMEM;
  1143. dev->mode_config.path_property = prop;
  1144. prop = drm_property_create(dev,
  1145. DRM_MODE_PROP_BLOB |
  1146. DRM_MODE_PROP_IMMUTABLE,
  1147. "TILE", 0);
  1148. if (!prop)
  1149. return -ENOMEM;
  1150. dev->mode_config.tile_property = prop;
  1151. prop = drm_property_create_enum(dev, 0, "link-status",
  1152. drm_link_status_enum_list,
  1153. ARRAY_SIZE(drm_link_status_enum_list));
  1154. if (!prop)
  1155. return -ENOMEM;
  1156. dev->mode_config.link_status_property = prop;
  1157. prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
  1158. if (!prop)
  1159. return -ENOMEM;
  1160. dev->mode_config.non_desktop_property = prop;
  1161. prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
  1162. "HDR_OUTPUT_METADATA", 0);
  1163. if (!prop)
  1164. return -ENOMEM;
  1165. dev->mode_config.hdr_output_metadata_property = prop;
  1166. return 0;
  1167. }
  1168. /**
  1169. * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
  1170. * @dev: DRM device
  1171. *
  1172. * Called by a driver the first time a DVI-I connector is made.
  1173. */
  1174. int drm_mode_create_dvi_i_properties(struct drm_device *dev)
  1175. {
  1176. struct drm_property *dvi_i_selector;
  1177. struct drm_property *dvi_i_subconnector;
  1178. if (dev->mode_config.dvi_i_select_subconnector_property)
  1179. return 0;
  1180. dvi_i_selector =
  1181. drm_property_create_enum(dev, 0,
  1182. "select subconnector",
  1183. drm_dvi_i_select_enum_list,
  1184. ARRAY_SIZE(drm_dvi_i_select_enum_list));
  1185. dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
  1186. dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
  1187. "subconnector",
  1188. drm_dvi_i_subconnector_enum_list,
  1189. ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
  1190. dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
  1191. return 0;
  1192. }
  1193. EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
  1194. /**
  1195. * drm_connector_attach_dp_subconnector_property - create subconnector property for DP
  1196. * @connector: drm_connector to attach property
  1197. *
  1198. * Called by a driver when DP connector is created.
  1199. */
  1200. void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector)
  1201. {
  1202. struct drm_mode_config *mode_config = &connector->dev->mode_config;
  1203. if (!mode_config->dp_subconnector_property)
  1204. mode_config->dp_subconnector_property =
  1205. drm_property_create_enum(connector->dev,
  1206. DRM_MODE_PROP_IMMUTABLE,
  1207. "subconnector",
  1208. drm_dp_subconnector_enum_list,
  1209. ARRAY_SIZE(drm_dp_subconnector_enum_list));
  1210. drm_object_attach_property(&connector->base,
  1211. mode_config->dp_subconnector_property,
  1212. DRM_MODE_SUBCONNECTOR_Unknown);
  1213. }
  1214. EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property);
  1215. /**
  1216. * DOC: HDMI connector properties
  1217. *
  1218. * content type (HDMI specific):
  1219. * Indicates content type setting to be used in HDMI infoframes to indicate
  1220. * content type for the external device, so that it adjusts its display
  1221. * settings accordingly.
  1222. *
  1223. * The value of this property can be one of the following:
  1224. *
  1225. * No Data:
  1226. * Content type is unknown
  1227. * Graphics:
  1228. * Content type is graphics
  1229. * Photo:
  1230. * Content type is photo
  1231. * Cinema:
  1232. * Content type is cinema
  1233. * Game:
  1234. * Content type is game
  1235. *
  1236. * Drivers can set up this property by calling
  1237. * drm_connector_attach_content_type_property(). Decoding to
  1238. * infoframe values is done through drm_hdmi_avi_infoframe_content_type().
  1239. */
  1240. /**
  1241. * drm_connector_attach_content_type_property - attach content-type property
  1242. * @connector: connector to attach content type property on.
  1243. *
  1244. * Called by a driver the first time a HDMI connector is made.
  1245. */
  1246. int drm_connector_attach_content_type_property(struct drm_connector *connector)
  1247. {
  1248. if (!drm_mode_create_content_type_property(connector->dev))
  1249. drm_object_attach_property(&connector->base,
  1250. connector->dev->mode_config.content_type_property,
  1251. DRM_MODE_CONTENT_TYPE_NO_DATA);
  1252. return 0;
  1253. }
  1254. EXPORT_SYMBOL(drm_connector_attach_content_type_property);
  1255. /**
  1256. * drm_hdmi_avi_infoframe_content_type() - fill the HDMI AVI infoframe
  1257. * content type information, based
  1258. * on correspondent DRM property.
  1259. * @frame: HDMI AVI infoframe
  1260. * @conn_state: DRM display connector state
  1261. *
  1262. */
  1263. void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame,
  1264. const struct drm_connector_state *conn_state)
  1265. {
  1266. switch (conn_state->content_type) {
  1267. case DRM_MODE_CONTENT_TYPE_GRAPHICS:
  1268. frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
  1269. break;
  1270. case DRM_MODE_CONTENT_TYPE_CINEMA:
  1271. frame->content_type = HDMI_CONTENT_TYPE_CINEMA;
  1272. break;
  1273. case DRM_MODE_CONTENT_TYPE_GAME:
  1274. frame->content_type = HDMI_CONTENT_TYPE_GAME;
  1275. break;
  1276. case DRM_MODE_CONTENT_TYPE_PHOTO:
  1277. frame->content_type = HDMI_CONTENT_TYPE_PHOTO;
  1278. break;
  1279. default:
  1280. /* Graphics is the default(0) */
  1281. frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
  1282. }
  1283. frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA;
  1284. }
  1285. EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type);
  1286. /**
  1287. * drm_mode_attach_tv_margin_properties - attach TV connector margin properties
  1288. * @connector: DRM connector
  1289. *
  1290. * Called by a driver when it needs to attach TV margin props to a connector.
  1291. * Typically used on SDTV and HDMI connectors.
  1292. */
  1293. void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
  1294. {
  1295. struct drm_device *dev = connector->dev;
  1296. drm_object_attach_property(&connector->base,
  1297. dev->mode_config.tv_left_margin_property,
  1298. 0);
  1299. drm_object_attach_property(&connector->base,
  1300. dev->mode_config.tv_right_margin_property,
  1301. 0);
  1302. drm_object_attach_property(&connector->base,
  1303. dev->mode_config.tv_top_margin_property,
  1304. 0);
  1305. drm_object_attach_property(&connector->base,
  1306. dev->mode_config.tv_bottom_margin_property,
  1307. 0);
  1308. }
  1309. EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
  1310. /**
  1311. * drm_mode_create_tv_margin_properties - create TV connector margin properties
  1312. * @dev: DRM device
  1313. *
  1314. * Called by a driver's HDMI connector initialization routine, this function
  1315. * creates the TV margin properties for a given device. No need to call this
  1316. * function for an SDTV connector, it's already called from
  1317. * drm_mode_create_tv_properties().
  1318. */
  1319. int drm_mode_create_tv_margin_properties(struct drm_device *dev)
  1320. {
  1321. if (dev->mode_config.tv_left_margin_property)
  1322. return 0;
  1323. dev->mode_config.tv_left_margin_property =
  1324. drm_property_create_range(dev, 0, "left margin", 0, 100);
  1325. if (!dev->mode_config.tv_left_margin_property)
  1326. return -ENOMEM;
  1327. dev->mode_config.tv_right_margin_property =
  1328. drm_property_create_range(dev, 0, "right margin", 0, 100);
  1329. if (!dev->mode_config.tv_right_margin_property)
  1330. return -ENOMEM;
  1331. dev->mode_config.tv_top_margin_property =
  1332. drm_property_create_range(dev, 0, "top margin", 0, 100);
  1333. if (!dev->mode_config.tv_top_margin_property)
  1334. return -ENOMEM;
  1335. dev->mode_config.tv_bottom_margin_property =
  1336. drm_property_create_range(dev, 0, "bottom margin", 0, 100);
  1337. if (!dev->mode_config.tv_bottom_margin_property)
  1338. return -ENOMEM;
  1339. return 0;
  1340. }
  1341. EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
  1342. /**
  1343. * drm_mode_create_tv_properties - create TV specific connector properties
  1344. * @dev: DRM device
  1345. * @num_modes: number of different TV formats (modes) supported
  1346. * @modes: array of pointers to strings containing name of each format
  1347. *
  1348. * Called by a driver's TV initialization routine, this function creates
  1349. * the TV specific connector properties for a given device. Caller is
  1350. * responsible for allocating a list of format names and passing them to
  1351. * this routine.
  1352. */
  1353. int drm_mode_create_tv_properties(struct drm_device *dev,
  1354. unsigned int num_modes,
  1355. const char * const modes[])
  1356. {
  1357. struct drm_property *tv_selector;
  1358. struct drm_property *tv_subconnector;
  1359. unsigned int i;
  1360. if (dev->mode_config.tv_select_subconnector_property)
  1361. return 0;
  1362. /*
  1363. * Basic connector properties
  1364. */
  1365. tv_selector = drm_property_create_enum(dev, 0,
  1366. "select subconnector",
  1367. drm_tv_select_enum_list,
  1368. ARRAY_SIZE(drm_tv_select_enum_list));
  1369. if (!tv_selector)
  1370. goto nomem;
  1371. dev->mode_config.tv_select_subconnector_property = tv_selector;
  1372. tv_subconnector =
  1373. drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
  1374. "subconnector",
  1375. drm_tv_subconnector_enum_list,
  1376. ARRAY_SIZE(drm_tv_subconnector_enum_list));
  1377. if (!tv_subconnector)
  1378. goto nomem;
  1379. dev->mode_config.tv_subconnector_property = tv_subconnector;
  1380. /*
  1381. * Other, TV specific properties: margins & TV modes.
  1382. */
  1383. if (drm_mode_create_tv_margin_properties(dev))
  1384. goto nomem;
  1385. dev->mode_config.tv_mode_property =
  1386. drm_property_create(dev, DRM_MODE_PROP_ENUM,
  1387. "mode", num_modes);
  1388. if (!dev->mode_config.tv_mode_property)
  1389. goto nomem;
  1390. for (i = 0; i < num_modes; i++)
  1391. drm_property_add_enum(dev->mode_config.tv_mode_property,
  1392. i, modes[i]);
  1393. dev->mode_config.tv_brightness_property =
  1394. drm_property_create_range(dev, 0, "brightness", 0, 100);
  1395. if (!dev->mode_config.tv_brightness_property)
  1396. goto nomem;
  1397. dev->mode_config.tv_contrast_property =
  1398. drm_property_create_range(dev, 0, "contrast", 0, 100);
  1399. if (!dev->mode_config.tv_contrast_property)
  1400. goto nomem;
  1401. dev->mode_config.tv_flicker_reduction_property =
  1402. drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
  1403. if (!dev->mode_config.tv_flicker_reduction_property)
  1404. goto nomem;
  1405. dev->mode_config.tv_overscan_property =
  1406. drm_property_create_range(dev, 0, "overscan", 0, 100);
  1407. if (!dev->mode_config.tv_overscan_property)
  1408. goto nomem;
  1409. dev->mode_config.tv_saturation_property =
  1410. drm_property_create_range(dev, 0, "saturation", 0, 100);
  1411. if (!dev->mode_config.tv_saturation_property)
  1412. goto nomem;
  1413. dev->mode_config.tv_hue_property =
  1414. drm_property_create_range(dev, 0, "hue", 0, 100);
  1415. if (!dev->mode_config.tv_hue_property)
  1416. goto nomem;
  1417. return 0;
  1418. nomem:
  1419. return -ENOMEM;
  1420. }
  1421. EXPORT_SYMBOL(drm_mode_create_tv_properties);
  1422. /**
  1423. * drm_mode_create_scaling_mode_property - create scaling mode property
  1424. * @dev: DRM device
  1425. *
  1426. * Called by a driver the first time it's needed, must be attached to desired
  1427. * connectors.
  1428. *
  1429. * Atomic drivers should use drm_connector_attach_scaling_mode_property()
  1430. * instead to correctly assign &drm_connector_state.picture_aspect_ratio
  1431. * in the atomic state.
  1432. */
  1433. int drm_mode_create_scaling_mode_property(struct drm_device *dev)
  1434. {
  1435. struct drm_property *scaling_mode;
  1436. if (dev->mode_config.scaling_mode_property)
  1437. return 0;
  1438. scaling_mode =
  1439. drm_property_create_enum(dev, 0, "scaling mode",
  1440. drm_scaling_mode_enum_list,
  1441. ARRAY_SIZE(drm_scaling_mode_enum_list));
  1442. dev->mode_config.scaling_mode_property = scaling_mode;
  1443. return 0;
  1444. }
  1445. EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
  1446. /**
  1447. * DOC: Variable refresh properties
  1448. *
  1449. * Variable refresh rate capable displays can dynamically adjust their
  1450. * refresh rate by extending the duration of their vertical front porch
  1451. * until page flip or timeout occurs. This can reduce or remove stuttering
  1452. * and latency in scenarios where the page flip does not align with the
  1453. * vblank interval.
  1454. *
  1455. * An example scenario would be an application flipping at a constant rate
  1456. * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
  1457. * interval and the same contents will be displayed twice. This can be
  1458. * observed as stuttering for content with motion.
  1459. *
  1460. * If variable refresh rate was active on a display that supported a
  1461. * variable refresh range from 35Hz to 60Hz no stuttering would be observable
  1462. * for the example scenario. The minimum supported variable refresh rate of
  1463. * 35Hz is below the page flip frequency and the vertical front porch can
  1464. * be extended until the page flip occurs. The vblank interval will be
  1465. * directly aligned to the page flip rate.
  1466. *
  1467. * Not all userspace content is suitable for use with variable refresh rate.
  1468. * Large and frequent changes in vertical front porch duration may worsen
  1469. * perceived stuttering for input sensitive applications.
  1470. *
  1471. * Panel brightness will also vary with vertical front porch duration. Some
  1472. * panels may have noticeable differences in brightness between the minimum
  1473. * vertical front porch duration and the maximum vertical front porch duration.
  1474. * Large and frequent changes in vertical front porch duration may produce
  1475. * observable flickering for such panels.
  1476. *
  1477. * Userspace control for variable refresh rate is supported via properties
  1478. * on the &drm_connector and &drm_crtc objects.
  1479. *
  1480. * "vrr_capable":
  1481. * Optional &drm_connector boolean property that drivers should attach
  1482. * with drm_connector_attach_vrr_capable_property() on connectors that
  1483. * could support variable refresh rates. Drivers should update the
  1484. * property value by calling drm_connector_set_vrr_capable_property().
  1485. *
  1486. * Absence of the property should indicate absence of support.
  1487. *
  1488. * "VRR_ENABLED":
  1489. * Default &drm_crtc boolean property that notifies the driver that the
  1490. * content on the CRTC is suitable for variable refresh rate presentation.
  1491. * The driver will take this property as a hint to enable variable
  1492. * refresh rate support if the receiver supports it, ie. if the
  1493. * "vrr_capable" property is true on the &drm_connector object. The
  1494. * vertical front porch duration will be extended until page-flip or
  1495. * timeout when enabled.
  1496. *
  1497. * The minimum vertical front porch duration is defined as the vertical
  1498. * front porch duration for the current mode.
  1499. *
  1500. * The maximum vertical front porch duration is greater than or equal to
  1501. * the minimum vertical front porch duration. The duration is derived
  1502. * from the minimum supported variable refresh rate for the connector.
  1503. *
  1504. * The driver may place further restrictions within these minimum
  1505. * and maximum bounds.
  1506. */
  1507. /**
  1508. * drm_connector_attach_vrr_capable_property - creates the
  1509. * vrr_capable property
  1510. * @connector: connector to create the vrr_capable property on.
  1511. *
  1512. * This is used by atomic drivers to add support for querying
  1513. * variable refresh rate capability for a connector.
  1514. *
  1515. * Returns:
  1516. * Zero on success, negative errno on failure.
  1517. */
  1518. int drm_connector_attach_vrr_capable_property(
  1519. struct drm_connector *connector)
  1520. {
  1521. struct drm_device *dev = connector->dev;
  1522. struct drm_property *prop;
  1523. if (!connector->vrr_capable_property) {
  1524. prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
  1525. "vrr_capable");
  1526. if (!prop)
  1527. return -ENOMEM;
  1528. connector->vrr_capable_property = prop;
  1529. drm_object_attach_property(&connector->base, prop, 0);
  1530. }
  1531. return 0;
  1532. }
  1533. EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
  1534. /**
  1535. * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
  1536. * @connector: connector to attach scaling mode property on.
  1537. * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
  1538. *
  1539. * This is used to add support for scaling mode to atomic drivers.
  1540. * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio
  1541. * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
  1542. *
  1543. * This is the atomic version of drm_mode_create_scaling_mode_property().
  1544. *
  1545. * Returns:
  1546. * Zero on success, negative errno on failure.
  1547. */
  1548. int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
  1549. u32 scaling_mode_mask)
  1550. {
  1551. struct drm_device *dev = connector->dev;
  1552. struct drm_property *scaling_mode_property;
  1553. int i;
  1554. const unsigned valid_scaling_mode_mask =
  1555. (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
  1556. if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
  1557. scaling_mode_mask & ~valid_scaling_mode_mask))
  1558. return -EINVAL;
  1559. scaling_mode_property =
  1560. drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
  1561. hweight32(scaling_mode_mask));
  1562. if (!scaling_mode_property)
  1563. return -ENOMEM;
  1564. for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
  1565. int ret;
  1566. if (!(BIT(i) & scaling_mode_mask))
  1567. continue;
  1568. ret = drm_property_add_enum(scaling_mode_property,
  1569. drm_scaling_mode_enum_list[i].type,
  1570. drm_scaling_mode_enum_list[i].name);
  1571. if (ret) {
  1572. drm_property_destroy(dev, scaling_mode_property);
  1573. return ret;
  1574. }
  1575. }
  1576. drm_object_attach_property(&connector->base,
  1577. scaling_mode_property, 0);
  1578. connector->scaling_mode_property = scaling_mode_property;
  1579. return 0;
  1580. }
  1581. EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
  1582. /**
  1583. * drm_mode_create_aspect_ratio_property - create aspect ratio property
  1584. * @dev: DRM device
  1585. *
  1586. * Called by a driver the first time it's needed, must be attached to desired
  1587. * connectors.
  1588. *
  1589. * Returns:
  1590. * Zero on success, negative errno on failure.
  1591. */
  1592. int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
  1593. {
  1594. if (dev->mode_config.aspect_ratio_property)
  1595. return 0;
  1596. dev->mode_config.aspect_ratio_property =
  1597. drm_property_create_enum(dev, 0, "aspect ratio",
  1598. drm_aspect_ratio_enum_list,
  1599. ARRAY_SIZE(drm_aspect_ratio_enum_list));
  1600. if (dev->mode_config.aspect_ratio_property == NULL)
  1601. return -ENOMEM;
  1602. return 0;
  1603. }
  1604. EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
  1605. /**
  1606. * DOC: standard connector properties
  1607. *
  1608. * Colorspace:
  1609. * This property helps select a suitable colorspace based on the sink
  1610. * capability. Modern sink devices support wider gamut like BT2020.
  1611. * This helps switch to BT2020 mode if the BT2020 encoded video stream
  1612. * is being played by the user, same for any other colorspace. Thereby
  1613. * giving a good visual experience to users.
  1614. *
  1615. * The expectation from userspace is that it should parse the EDID
  1616. * and get supported colorspaces. Use this property and switch to the
  1617. * one supported. Sink supported colorspaces should be retrieved by
  1618. * userspace from EDID and driver will not explicitly expose them.
  1619. *
  1620. * Basically the expectation from userspace is:
  1621. * - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink
  1622. * colorspace
  1623. * - Set this new property to let the sink know what it
  1624. * converted the CRTC output to.
  1625. * - This property is just to inform sink what colorspace
  1626. * source is trying to drive.
  1627. *
  1628. * Because between HDMI and DP have different colorspaces,
  1629. * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and
  1630. * drm_mode_create_dp_colorspace_property() is used for DP connector.
  1631. */
  1632. /**
  1633. * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
  1634. * @connector: connector to create the Colorspace property on.
  1635. *
  1636. * Called by a driver the first time it's needed, must be attached to desired
  1637. * HDMI connectors.
  1638. *
  1639. * Returns:
  1640. * Zero on success, negative errno on failure.
  1641. */
  1642. int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector)
  1643. {
  1644. struct drm_device *dev = connector->dev;
  1645. if (connector->colorspace_property)
  1646. return 0;
  1647. connector->colorspace_property =
  1648. drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
  1649. hdmi_colorspaces,
  1650. ARRAY_SIZE(hdmi_colorspaces));
  1651. if (!connector->colorspace_property)
  1652. return -ENOMEM;
  1653. return 0;
  1654. }
  1655. EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
  1656. /**
  1657. * drm_mode_create_dp_colorspace_property - create dp colorspace property
  1658. * @connector: connector to create the Colorspace property on.
  1659. *
  1660. * Called by a driver the first time it's needed, must be attached to desired
  1661. * DP connectors.
  1662. *
  1663. * Returns:
  1664. * Zero on success, negative errno on failure.
  1665. */
  1666. int drm_mode_create_dp_colorspace_property(struct drm_connector *connector)
  1667. {
  1668. struct drm_device *dev = connector->dev;
  1669. if (connector->colorspace_property)
  1670. return 0;
  1671. connector->colorspace_property =
  1672. drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
  1673. dp_colorspaces,
  1674. ARRAY_SIZE(dp_colorspaces));
  1675. if (!connector->colorspace_property)
  1676. return -ENOMEM;
  1677. return 0;
  1678. }
  1679. EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
  1680. /**
  1681. * drm_mode_create_content_type_property - create content type property
  1682. * @dev: DRM device
  1683. *
  1684. * Called by a driver the first time it's needed, must be attached to desired
  1685. * connectors.
  1686. *
  1687. * Returns:
  1688. * Zero on success, negative errno on failure.
  1689. */
  1690. int drm_mode_create_content_type_property(struct drm_device *dev)
  1691. {
  1692. if (dev->mode_config.content_type_property)
  1693. return 0;
  1694. dev->mode_config.content_type_property =
  1695. drm_property_create_enum(dev, 0, "content type",
  1696. drm_content_type_enum_list,
  1697. ARRAY_SIZE(drm_content_type_enum_list));
  1698. if (dev->mode_config.content_type_property == NULL)
  1699. return -ENOMEM;
  1700. return 0;
  1701. }
  1702. EXPORT_SYMBOL(drm_mode_create_content_type_property);
  1703. /**
  1704. * drm_mode_create_suggested_offset_properties - create suggests offset properties
  1705. * @dev: DRM device
  1706. *
  1707. * Create the suggested x/y offset property for connectors.
  1708. */
  1709. int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
  1710. {
  1711. if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
  1712. return 0;
  1713. dev->mode_config.suggested_x_property =
  1714. drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
  1715. dev->mode_config.suggested_y_property =
  1716. drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
  1717. if (dev->mode_config.suggested_x_property == NULL ||
  1718. dev->mode_config.suggested_y_property == NULL)
  1719. return -ENOMEM;
  1720. return 0;
  1721. }
  1722. EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
  1723. /**
  1724. * drm_connector_set_path_property - set tile property on connector
  1725. * @connector: connector to set property on.
  1726. * @path: path to use for property; must not be NULL.
  1727. *
  1728. * This creates a property to expose to userspace to specify a
  1729. * connector path. This is mainly used for DisplayPort MST where
  1730. * connectors have a topology and we want to allow userspace to give
  1731. * them more meaningful names.
  1732. *
  1733. * Returns:
  1734. * Zero on success, negative errno on failure.
  1735. */
  1736. int drm_connector_set_path_property(struct drm_connector *connector,
  1737. const char *path)
  1738. {
  1739. struct drm_device *dev = connector->dev;
  1740. int ret;
  1741. ret = drm_property_replace_global_blob(dev,
  1742. &connector->path_blob_ptr,
  1743. strlen(path) + 1,
  1744. path,
  1745. &connector->base,
  1746. dev->mode_config.path_property);
  1747. return ret;
  1748. }
  1749. EXPORT_SYMBOL(drm_connector_set_path_property);
  1750. /**
  1751. * drm_connector_set_tile_property - set tile property on connector
  1752. * @connector: connector to set property on.
  1753. *
  1754. * This looks up the tile information for a connector, and creates a
  1755. * property for userspace to parse if it exists. The property is of
  1756. * the form of 8 integers using ':' as a separator.
  1757. * This is used for dual port tiled displays with DisplayPort SST
  1758. * or DisplayPort MST connectors.
  1759. *
  1760. * Returns:
  1761. * Zero on success, errno on failure.
  1762. */
  1763. int drm_connector_set_tile_property(struct drm_connector *connector)
  1764. {
  1765. struct drm_device *dev = connector->dev;
  1766. char tile[256];
  1767. int ret;
  1768. if (!connector->has_tile) {
  1769. ret = drm_property_replace_global_blob(dev,
  1770. &connector->tile_blob_ptr,
  1771. 0,
  1772. NULL,
  1773. &connector->base,
  1774. dev->mode_config.tile_property);
  1775. return ret;
  1776. }
  1777. snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
  1778. connector->tile_group->id, connector->tile_is_single_monitor,
  1779. connector->num_h_tile, connector->num_v_tile,
  1780. connector->tile_h_loc, connector->tile_v_loc,
  1781. connector->tile_h_size, connector->tile_v_size);
  1782. ret = drm_property_replace_global_blob(dev,
  1783. &connector->tile_blob_ptr,
  1784. strlen(tile) + 1,
  1785. tile,
  1786. &connector->base,
  1787. dev->mode_config.tile_property);
  1788. return ret;
  1789. }
  1790. EXPORT_SYMBOL(drm_connector_set_tile_property);
  1791. /**
  1792. * drm_connector_update_edid_property - update the edid property of a connector
  1793. * @connector: drm connector
  1794. * @edid: new value of the edid property
  1795. *
  1796. * This function creates a new blob modeset object and assigns its id to the
  1797. * connector's edid property.
  1798. * Since we also parse tile information from EDID's displayID block, we also
  1799. * set the connector's tile property here. See drm_connector_set_tile_property()
  1800. * for more details.
  1801. *
  1802. * Returns:
  1803. * Zero on success, negative errno on failure.
  1804. */
  1805. int drm_connector_update_edid_property(struct drm_connector *connector,
  1806. const struct edid *edid)
  1807. {
  1808. struct drm_device *dev = connector->dev;
  1809. size_t size = 0;
  1810. int ret;
  1811. const struct edid *old_edid;
  1812. /* ignore requests to set edid when overridden */
  1813. if (connector->override_edid)
  1814. return 0;
  1815. if (edid)
  1816. size = EDID_LENGTH * (1 + edid->extensions);
  1817. /* Set the display info, using edid if available, otherwise
  1818. * resetting the values to defaults. This duplicates the work
  1819. * done in drm_add_edid_modes, but that function is not
  1820. * consistently called before this one in all drivers and the
  1821. * computation is cheap enough that it seems better to
  1822. * duplicate it rather than attempt to ensure some arbitrary
  1823. * ordering of calls.
  1824. */
  1825. if (edid)
  1826. drm_add_display_info(connector, edid);
  1827. drm_update_tile_info(connector, edid);
  1828. if (connector->edid_blob_ptr) {
  1829. old_edid = (const struct edid *)connector->edid_blob_ptr->data;
  1830. if (old_edid) {
  1831. if (!drm_edid_are_equal(edid, old_edid)) {
  1832. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Edid was changed.\n",
  1833. connector->base.id, connector->name);
  1834. connector->epoch_counter += 1;
  1835. DRM_DEBUG_KMS("Updating change counter to %llu\n",
  1836. connector->epoch_counter);
  1837. }
  1838. }
  1839. }
  1840. drm_object_property_set_value(&connector->base,
  1841. dev->mode_config.non_desktop_property,
  1842. connector->display_info.non_desktop);
  1843. ret = drm_property_replace_global_blob(dev,
  1844. &connector->edid_blob_ptr,
  1845. size,
  1846. edid,
  1847. &connector->base,
  1848. dev->mode_config.edid_property);
  1849. if (ret)
  1850. return ret;
  1851. return drm_connector_set_tile_property(connector);
  1852. }
  1853. EXPORT_SYMBOL(drm_connector_update_edid_property);
  1854. /**
  1855. * drm_connector_set_link_status_property - Set link status property of a connector
  1856. * @connector: drm connector
  1857. * @link_status: new value of link status property (0: Good, 1: Bad)
  1858. *
  1859. * In usual working scenario, this link status property will always be set to
  1860. * "GOOD". If something fails during or after a mode set, the kernel driver
  1861. * may set this link status property to "BAD". The caller then needs to send a
  1862. * hotplug uevent for userspace to re-check the valid modes through
  1863. * GET_CONNECTOR_IOCTL and retry modeset.
  1864. *
  1865. * Note: Drivers cannot rely on userspace to support this property and
  1866. * issue a modeset. As such, they may choose to handle issues (like
  1867. * re-training a link) without userspace's intervention.
  1868. *
  1869. * The reason for adding this property is to handle link training failures, but
  1870. * it is not limited to DP or link training. For example, if we implement
  1871. * asynchronous setcrtc, this property can be used to report any failures in that.
  1872. */
  1873. void drm_connector_set_link_status_property(struct drm_connector *connector,
  1874. uint64_t link_status)
  1875. {
  1876. struct drm_device *dev = connector->dev;
  1877. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  1878. connector->state->link_status = link_status;
  1879. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  1880. }
  1881. EXPORT_SYMBOL(drm_connector_set_link_status_property);
  1882. /**
  1883. * drm_connector_attach_max_bpc_property - attach "max bpc" property
  1884. * @connector: connector to attach max bpc property on.
  1885. * @min: The minimum bit depth supported by the connector.
  1886. * @max: The maximum bit depth supported by the connector.
  1887. *
  1888. * This is used to add support for limiting the bit depth on a connector.
  1889. *
  1890. * Returns:
  1891. * Zero on success, negative errno on failure.
  1892. */
  1893. int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
  1894. int min, int max)
  1895. {
  1896. struct drm_device *dev = connector->dev;
  1897. struct drm_property *prop;
  1898. prop = connector->max_bpc_property;
  1899. if (!prop) {
  1900. prop = drm_property_create_range(dev, 0, "max bpc", min, max);
  1901. if (!prop)
  1902. return -ENOMEM;
  1903. connector->max_bpc_property = prop;
  1904. }
  1905. drm_object_attach_property(&connector->base, prop, max);
  1906. connector->state->max_requested_bpc = max;
  1907. connector->state->max_bpc = max;
  1908. return 0;
  1909. }
  1910. EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
  1911. /**
  1912. * drm_connector_set_vrr_capable_property - sets the variable refresh rate
  1913. * capable property for a connector
  1914. * @connector: drm connector
  1915. * @capable: True if the connector is variable refresh rate capable
  1916. *
  1917. * Should be used by atomic drivers to update the indicated support for
  1918. * variable refresh rate over a connector.
  1919. */
  1920. void drm_connector_set_vrr_capable_property(
  1921. struct drm_connector *connector, bool capable)
  1922. {
  1923. if (!connector->vrr_capable_property)
  1924. return;
  1925. drm_object_property_set_value(&connector->base,
  1926. connector->vrr_capable_property,
  1927. capable);
  1928. }
  1929. EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
  1930. /**
  1931. * drm_connector_set_panel_orientation - sets the connector's panel_orientation
  1932. * @connector: connector for which to set the panel-orientation property.
  1933. * @panel_orientation: drm_panel_orientation value to set
  1934. *
  1935. * This function sets the connector's panel_orientation and attaches
  1936. * a "panel orientation" property to the connector.
  1937. *
  1938. * Calling this function on a connector where the panel_orientation has
  1939. * already been set is a no-op (e.g. the orientation has been overridden with
  1940. * a kernel commandline option).
  1941. *
  1942. * It is allowed to call this function with a panel_orientation of
  1943. * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
  1944. *
  1945. * Returns:
  1946. * Zero on success, negative errno on failure.
  1947. */
  1948. int drm_connector_set_panel_orientation(
  1949. struct drm_connector *connector,
  1950. enum drm_panel_orientation panel_orientation)
  1951. {
  1952. struct drm_device *dev = connector->dev;
  1953. struct drm_display_info *info = &connector->display_info;
  1954. struct drm_property *prop;
  1955. /* Already set? */
  1956. if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
  1957. return 0;
  1958. /* Don't attach the property if the orientation is unknown */
  1959. if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
  1960. return 0;
  1961. info->panel_orientation = panel_orientation;
  1962. prop = dev->mode_config.panel_orientation_property;
  1963. if (!prop) {
  1964. prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
  1965. "panel orientation",
  1966. drm_panel_orientation_enum_list,
  1967. ARRAY_SIZE(drm_panel_orientation_enum_list));
  1968. if (!prop)
  1969. return -ENOMEM;
  1970. dev->mode_config.panel_orientation_property = prop;
  1971. }
  1972. drm_object_attach_property(&connector->base, prop,
  1973. info->panel_orientation);
  1974. return 0;
  1975. }
  1976. EXPORT_SYMBOL(drm_connector_set_panel_orientation);
  1977. /**
  1978. * drm_connector_set_panel_orientation_with_quirk -
  1979. * set the connector's panel_orientation after checking for quirks
  1980. * @connector: connector for which to init the panel-orientation property.
  1981. * @panel_orientation: drm_panel_orientation value to set
  1982. * @width: width in pixels of the panel, used for panel quirk detection
  1983. * @height: height in pixels of the panel, used for panel quirk detection
  1984. *
  1985. * Like drm_connector_set_panel_orientation(), but with a check for platform
  1986. * specific (e.g. DMI based) quirks overriding the passed in panel_orientation.
  1987. *
  1988. * Returns:
  1989. * Zero on success, negative errno on failure.
  1990. */
  1991. int drm_connector_set_panel_orientation_with_quirk(
  1992. struct drm_connector *connector,
  1993. enum drm_panel_orientation panel_orientation,
  1994. int width, int height)
  1995. {
  1996. int orientation_quirk;
  1997. orientation_quirk = drm_get_panel_orientation_quirk(width, height);
  1998. if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
  1999. panel_orientation = orientation_quirk;
  2000. return drm_connector_set_panel_orientation(connector,
  2001. panel_orientation);
  2002. }
  2003. EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
  2004. int drm_connector_set_obj_prop(struct drm_mode_object *obj,
  2005. struct drm_property *property,
  2006. uint64_t value)
  2007. {
  2008. int ret = -EINVAL;
  2009. struct drm_connector *connector = obj_to_connector(obj);
  2010. /* Do DPMS ourselves */
  2011. if (property == connector->dev->mode_config.dpms_property) {
  2012. ret = (*connector->funcs->dpms)(connector, (int)value);
  2013. } else if (connector->funcs->set_property)
  2014. ret = connector->funcs->set_property(connector, property, value);
  2015. if (!ret)
  2016. drm_object_property_set_value(&connector->base, property, value);
  2017. return ret;
  2018. }
  2019. int drm_connector_property_set_ioctl(struct drm_device *dev,
  2020. void *data, struct drm_file *file_priv)
  2021. {
  2022. struct drm_mode_connector_set_property *conn_set_prop = data;
  2023. struct drm_mode_obj_set_property obj_set_prop = {
  2024. .value = conn_set_prop->value,
  2025. .prop_id = conn_set_prop->prop_id,
  2026. .obj_id = conn_set_prop->connector_id,
  2027. .obj_type = DRM_MODE_OBJECT_CONNECTOR
  2028. };
  2029. /* It does all the locking and checking we need */
  2030. return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
  2031. }
  2032. static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
  2033. {
  2034. /* For atomic drivers only state objects are synchronously updated and
  2035. * protected by modeset locks, so check those first. */
  2036. if (connector->state)
  2037. return connector->state->best_encoder;
  2038. return connector->encoder;
  2039. }
  2040. static bool
  2041. drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
  2042. const struct list_head *modes,
  2043. const struct drm_file *file_priv)
  2044. {
  2045. /*
  2046. * If user-space hasn't configured the driver to expose the stereo 3D
  2047. * modes, don't expose them.
  2048. */
  2049. if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
  2050. return false;
  2051. /*
  2052. * If user-space hasn't configured the driver to expose the modes
  2053. * with aspect-ratio, don't expose them. However if such a mode
  2054. * is unique, let it be exposed, but reset the aspect-ratio flags
  2055. * while preparing the list of user-modes.
  2056. */
  2057. if (!file_priv->aspect_ratio_allowed) {
  2058. const struct drm_display_mode *mode_itr;
  2059. list_for_each_entry(mode_itr, modes, head) {
  2060. if (mode_itr->expose_to_userspace &&
  2061. drm_mode_match(mode_itr, mode,
  2062. DRM_MODE_MATCH_TIMINGS |
  2063. DRM_MODE_MATCH_CLOCK |
  2064. DRM_MODE_MATCH_FLAGS |
  2065. DRM_MODE_MATCH_3D_FLAGS))
  2066. return false;
  2067. }
  2068. }
  2069. return true;
  2070. }
  2071. int drm_mode_getconnector(struct drm_device *dev, void *data,
  2072. struct drm_file *file_priv)
  2073. {
  2074. struct drm_mode_get_connector *out_resp = data;
  2075. struct drm_connector *connector;
  2076. struct drm_encoder *encoder;
  2077. struct drm_display_mode *mode;
  2078. int mode_count = 0;
  2079. int encoders_count = 0;
  2080. int ret = 0;
  2081. int copied = 0;
  2082. struct drm_mode_modeinfo u_mode;
  2083. struct drm_mode_modeinfo __user *mode_ptr;
  2084. uint32_t __user *encoder_ptr;
  2085. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  2086. return -EOPNOTSUPP;
  2087. memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
  2088. connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
  2089. if (!connector)
  2090. return -ENOENT;
  2091. encoders_count = hweight32(connector->possible_encoders);
  2092. if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
  2093. copied = 0;
  2094. encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
  2095. drm_connector_for_each_possible_encoder(connector, encoder) {
  2096. if (put_user(encoder->base.id, encoder_ptr + copied)) {
  2097. ret = -EFAULT;
  2098. goto out;
  2099. }
  2100. copied++;
  2101. }
  2102. }
  2103. out_resp->count_encoders = encoders_count;
  2104. out_resp->connector_id = connector->base.id;
  2105. out_resp->connector_type = connector->connector_type;
  2106. out_resp->connector_type_id = connector->connector_type_id;
  2107. mutex_lock(&dev->mode_config.mutex);
  2108. if (out_resp->count_modes == 0) {
  2109. connector->funcs->fill_modes(connector,
  2110. dev->mode_config.max_width,
  2111. dev->mode_config.max_height);
  2112. }
  2113. out_resp->mm_width = connector->display_info.width_mm;
  2114. out_resp->mm_height = connector->display_info.height_mm;
  2115. out_resp->subpixel = connector->display_info.subpixel_order;
  2116. out_resp->connection = connector->status;
  2117. /* delayed so we get modes regardless of pre-fill_modes state */
  2118. list_for_each_entry(mode, &connector->modes, head) {
  2119. WARN_ON(mode->expose_to_userspace);
  2120. if (drm_mode_expose_to_userspace(mode, &connector->modes,
  2121. file_priv)) {
  2122. mode->expose_to_userspace = true;
  2123. mode_count++;
  2124. }
  2125. }
  2126. /*
  2127. * This ioctl is called twice, once to determine how much space is
  2128. * needed, and the 2nd time to fill it.
  2129. */
  2130. if ((out_resp->count_modes >= mode_count) && mode_count) {
  2131. copied = 0;
  2132. mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
  2133. list_for_each_entry(mode, &connector->modes, head) {
  2134. if (!mode->expose_to_userspace)
  2135. continue;
  2136. /* Clear the tag for the next time around */
  2137. mode->expose_to_userspace = false;
  2138. drm_mode_convert_to_umode(&u_mode, mode);
  2139. /*
  2140. * Reset aspect ratio flags of user-mode, if modes with
  2141. * aspect-ratio are not supported.
  2142. */
  2143. if (!file_priv->aspect_ratio_allowed)
  2144. u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
  2145. if (copy_to_user(mode_ptr + copied,
  2146. &u_mode, sizeof(u_mode))) {
  2147. ret = -EFAULT;
  2148. /*
  2149. * Clear the tag for the rest of
  2150. * the modes for the next time around.
  2151. */
  2152. list_for_each_entry_continue(mode, &connector->modes, head)
  2153. mode->expose_to_userspace = false;
  2154. mutex_unlock(&dev->mode_config.mutex);
  2155. goto out;
  2156. }
  2157. copied++;
  2158. }
  2159. } else {
  2160. /* Clear the tag for the next time around */
  2161. list_for_each_entry(mode, &connector->modes, head)
  2162. mode->expose_to_userspace = false;
  2163. }
  2164. out_resp->count_modes = mode_count;
  2165. mutex_unlock(&dev->mode_config.mutex);
  2166. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  2167. encoder = drm_connector_get_encoder(connector);
  2168. if (encoder)
  2169. out_resp->encoder_id = encoder->base.id;
  2170. else
  2171. out_resp->encoder_id = 0;
  2172. /* Only grab properties after probing, to make sure EDID and other
  2173. * properties reflect the latest status. */
  2174. ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
  2175. (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
  2176. (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
  2177. &out_resp->count_props);
  2178. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  2179. out:
  2180. drm_connector_put(connector);
  2181. return ret;
  2182. }
  2183. /**
  2184. * DOC: Tile group
  2185. *
  2186. * Tile groups are used to represent tiled monitors with a unique integer
  2187. * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
  2188. * we store this in a tile group, so we have a common identifier for all tiles
  2189. * in a monitor group. The property is called "TILE". Drivers can manage tile
  2190. * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
  2191. * drm_mode_get_tile_group(). But this is only needed for internal panels where
  2192. * the tile group information is exposed through a non-standard way.
  2193. */
  2194. static void drm_tile_group_free(struct kref *kref)
  2195. {
  2196. struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
  2197. struct drm_device *dev = tg->dev;
  2198. mutex_lock(&dev->mode_config.idr_mutex);
  2199. idr_remove(&dev->mode_config.tile_idr, tg->id);
  2200. mutex_unlock(&dev->mode_config.idr_mutex);
  2201. kfree(tg);
  2202. }
  2203. /**
  2204. * drm_mode_put_tile_group - drop a reference to a tile group.
  2205. * @dev: DRM device
  2206. * @tg: tile group to drop reference to.
  2207. *
  2208. * drop reference to tile group and free if 0.
  2209. */
  2210. void drm_mode_put_tile_group(struct drm_device *dev,
  2211. struct drm_tile_group *tg)
  2212. {
  2213. kref_put(&tg->refcount, drm_tile_group_free);
  2214. }
  2215. EXPORT_SYMBOL(drm_mode_put_tile_group);
  2216. /**
  2217. * drm_mode_get_tile_group - get a reference to an existing tile group
  2218. * @dev: DRM device
  2219. * @topology: 8-bytes unique per monitor.
  2220. *
  2221. * Use the unique bytes to get a reference to an existing tile group.
  2222. *
  2223. * RETURNS:
  2224. * tile group or NULL if not found.
  2225. */
  2226. struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
  2227. const char topology[8])
  2228. {
  2229. struct drm_tile_group *tg;
  2230. int id;
  2231. mutex_lock(&dev->mode_config.idr_mutex);
  2232. idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
  2233. if (!memcmp(tg->group_data, topology, 8)) {
  2234. if (!kref_get_unless_zero(&tg->refcount))
  2235. tg = NULL;
  2236. mutex_unlock(&dev->mode_config.idr_mutex);
  2237. return tg;
  2238. }
  2239. }
  2240. mutex_unlock(&dev->mode_config.idr_mutex);
  2241. return NULL;
  2242. }
  2243. EXPORT_SYMBOL(drm_mode_get_tile_group);
  2244. /**
  2245. * drm_mode_create_tile_group - create a tile group from a displayid description
  2246. * @dev: DRM device
  2247. * @topology: 8-bytes unique per monitor.
  2248. *
  2249. * Create a tile group for the unique monitor, and get a unique
  2250. * identifier for the tile group.
  2251. *
  2252. * RETURNS:
  2253. * new tile group or NULL.
  2254. */
  2255. struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
  2256. const char topology[8])
  2257. {
  2258. struct drm_tile_group *tg;
  2259. int ret;
  2260. tg = kzalloc(sizeof(*tg), GFP_KERNEL);
  2261. if (!tg)
  2262. return NULL;
  2263. kref_init(&tg->refcount);
  2264. memcpy(tg->group_data, topology, 8);
  2265. tg->dev = dev;
  2266. mutex_lock(&dev->mode_config.idr_mutex);
  2267. ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
  2268. if (ret >= 0) {
  2269. tg->id = ret;
  2270. } else {
  2271. kfree(tg);
  2272. tg = NULL;
  2273. }
  2274. mutex_unlock(&dev->mode_config.idr_mutex);
  2275. return tg;
  2276. }
  2277. EXPORT_SYMBOL(drm_mode_create_tile_group);