drm_connector.c 114 KB

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