drm_connector.c 119 KB

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