drm_connector.c 99 KB

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