drm_crtc.h 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959
  1. /*
  2. * Copyright © 2006 Keith Packard
  3. * Copyright © 2007-2008 Dave Airlie
  4. * Copyright © 2007-2008 Intel Corporation
  5. * Jesse Barnes <jesse.barnes@intel.com>
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. * OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef __DRM_CRTC_H__
  26. #define __DRM_CRTC_H__
  27. #include <linux/i2c.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/types.h>
  30. #include <linux/idr.h>
  31. #include <linux/fb.h>
  32. #include <linux/hdmi.h>
  33. #include <linux/media-bus-format.h>
  34. #include <uapi/drm/drm_mode.h>
  35. #include <uapi/drm/drm_fourcc.h>
  36. #include <drm/drm_modeset_lock.h>
  37. struct drm_device;
  38. struct drm_mode_set;
  39. struct drm_framebuffer;
  40. struct drm_object_properties;
  41. struct drm_file;
  42. struct drm_clip_rect;
  43. struct device_node;
  44. struct fence;
  45. struct drm_mode_object {
  46. uint32_t id;
  47. uint32_t type;
  48. struct drm_object_properties *properties;
  49. struct kref refcount;
  50. void (*free_cb)(struct kref *kref);
  51. };
  52. #define DRM_OBJECT_MAX_PROPERTY 24
  53. struct drm_object_properties {
  54. int count, atomic_count;
  55. /* NOTE: if we ever start dynamically destroying properties (ie.
  56. * not at drm_mode_config_cleanup() time), then we'd have to do
  57. * a better job of detaching property from mode objects to avoid
  58. * dangling property pointers:
  59. */
  60. struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
  61. /* do not read/write values directly, but use drm_object_property_get_value()
  62. * and drm_object_property_set_value():
  63. */
  64. uint64_t values[DRM_OBJECT_MAX_PROPERTY];
  65. };
  66. static inline int64_t U642I64(uint64_t val)
  67. {
  68. return (int64_t)*((int64_t *)&val);
  69. }
  70. static inline uint64_t I642U64(int64_t val)
  71. {
  72. return (uint64_t)*((uint64_t *)&val);
  73. }
  74. /*
  75. * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
  76. * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
  77. * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
  78. */
  79. #define DRM_ROTATE_MASK 0x0f
  80. #define DRM_ROTATE_0 0
  81. #define DRM_ROTATE_90 1
  82. #define DRM_ROTATE_180 2
  83. #define DRM_ROTATE_270 3
  84. #define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
  85. #define DRM_REFLECT_X 4
  86. #define DRM_REFLECT_Y 5
  87. enum drm_connector_force {
  88. DRM_FORCE_UNSPECIFIED,
  89. DRM_FORCE_OFF,
  90. DRM_FORCE_ON, /* force on analog part normally */
  91. DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
  92. };
  93. #include <drm/drm_modes.h>
  94. enum drm_connector_status {
  95. connector_status_connected = 1,
  96. connector_status_disconnected = 2,
  97. connector_status_unknown = 3,
  98. };
  99. enum subpixel_order {
  100. SubPixelUnknown = 0,
  101. SubPixelHorizontalRGB,
  102. SubPixelHorizontalBGR,
  103. SubPixelVerticalRGB,
  104. SubPixelVerticalBGR,
  105. SubPixelNone,
  106. };
  107. #define DRM_COLOR_FORMAT_RGB444 (1<<0)
  108. #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
  109. #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
  110. #define DRM_BUS_FLAG_DE_LOW (1<<0)
  111. #define DRM_BUS_FLAG_DE_HIGH (1<<1)
  112. /* drive data on pos. edge */
  113. #define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
  114. /* drive data on neg. edge */
  115. #define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
  116. /*
  117. * Describes a given display (e.g. CRT or flat panel) and its limitations.
  118. */
  119. struct drm_display_info {
  120. char name[DRM_DISPLAY_INFO_LEN];
  121. /* Physical size */
  122. unsigned int width_mm;
  123. unsigned int height_mm;
  124. /* Clock limits FIXME: storage format */
  125. unsigned int min_vfreq, max_vfreq;
  126. unsigned int min_hfreq, max_hfreq;
  127. unsigned int pixel_clock;
  128. unsigned int bpc;
  129. enum subpixel_order subpixel_order;
  130. u32 color_formats;
  131. const u32 *bus_formats;
  132. unsigned int num_bus_formats;
  133. u32 bus_flags;
  134. /* Mask of supported hdmi deep color modes */
  135. u8 edid_hdmi_dc_modes;
  136. u8 cea_rev;
  137. };
  138. /* data corresponds to displayid vend/prod/serial */
  139. struct drm_tile_group {
  140. struct kref refcount;
  141. struct drm_device *dev;
  142. int id;
  143. u8 group_data[8];
  144. };
  145. /**
  146. * struct drm_framebuffer_funcs - framebuffer hooks
  147. */
  148. struct drm_framebuffer_funcs {
  149. /**
  150. * @destroy:
  151. *
  152. * Clean up framebuffer resources, specifically also unreference the
  153. * backing storage. The core guarantees to call this function for every
  154. * framebuffer successfully created by ->fb_create() in
  155. * &drm_mode_config_funcs. Drivers must also call
  156. * drm_framebuffer_cleanup() to release DRM core resources for this
  157. * framebuffer.
  158. */
  159. void (*destroy)(struct drm_framebuffer *framebuffer);
  160. /**
  161. * @create_handle:
  162. *
  163. * Create a buffer handle in the driver-specific buffer manager (either
  164. * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
  165. * the core to implement the GETFB IOCTL, which returns (for
  166. * sufficiently priviledged user) also a native buffer handle. This can
  167. * be used for seamless transitions between modesetting clients by
  168. * copying the current screen contents to a private buffer and blending
  169. * between that and the new contents.
  170. *
  171. * GEM based drivers should call drm_gem_handle_create() to create the
  172. * handle.
  173. *
  174. * RETURNS:
  175. *
  176. * 0 on success or a negative error code on failure.
  177. */
  178. int (*create_handle)(struct drm_framebuffer *fb,
  179. struct drm_file *file_priv,
  180. unsigned int *handle);
  181. /**
  182. * @dirty:
  183. *
  184. * Optional callback for the dirty fb IOCTL.
  185. *
  186. * Userspace can notify the driver via this callback that an area of the
  187. * framebuffer has changed and should be flushed to the display
  188. * hardware. This can also be used internally, e.g. by the fbdev
  189. * emulation, though that's not the case currently.
  190. *
  191. * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
  192. * for more information as all the semantics and arguments have a one to
  193. * one mapping on this function.
  194. *
  195. * RETURNS:
  196. *
  197. * 0 on success or a negative error code on failure.
  198. */
  199. int (*dirty)(struct drm_framebuffer *framebuffer,
  200. struct drm_file *file_priv, unsigned flags,
  201. unsigned color, struct drm_clip_rect *clips,
  202. unsigned num_clips);
  203. };
  204. struct drm_framebuffer {
  205. struct drm_device *dev;
  206. /*
  207. * Note that the fb is refcounted for the benefit of driver internals,
  208. * for example some hw, disabling a CRTC/plane is asynchronous, and
  209. * scanout does not actually complete until the next vblank. So some
  210. * cleanup (like releasing the reference(s) on the backing GEM bo(s))
  211. * should be deferred. In cases like this, the driver would like to
  212. * hold a ref to the fb even though it has already been removed from
  213. * userspace perspective.
  214. * The refcount is stored inside the mode object.
  215. */
  216. /*
  217. * Place on the dev->mode_config.fb_list, access protected by
  218. * dev->mode_config.fb_lock.
  219. */
  220. struct list_head head;
  221. struct drm_mode_object base;
  222. const struct drm_framebuffer_funcs *funcs;
  223. unsigned int pitches[4];
  224. unsigned int offsets[4];
  225. uint64_t modifier[4];
  226. unsigned int width;
  227. unsigned int height;
  228. /* depth can be 15 or 16 */
  229. unsigned int depth;
  230. int bits_per_pixel;
  231. int flags;
  232. uint32_t pixel_format; /* fourcc format */
  233. int hot_x;
  234. int hot_y;
  235. struct list_head filp_head;
  236. };
  237. struct drm_property_blob {
  238. struct drm_mode_object base;
  239. struct drm_device *dev;
  240. struct list_head head_global;
  241. struct list_head head_file;
  242. size_t length;
  243. unsigned char data[];
  244. };
  245. struct drm_property_enum {
  246. uint64_t value;
  247. struct list_head head;
  248. char name[DRM_PROP_NAME_LEN];
  249. };
  250. struct drm_property {
  251. struct list_head head;
  252. struct drm_mode_object base;
  253. uint32_t flags;
  254. char name[DRM_PROP_NAME_LEN];
  255. uint32_t num_values;
  256. uint64_t *values;
  257. struct drm_device *dev;
  258. struct list_head enum_list;
  259. };
  260. struct drm_crtc;
  261. struct drm_connector;
  262. struct drm_encoder;
  263. struct drm_pending_vblank_event;
  264. struct drm_plane;
  265. struct drm_bridge;
  266. struct drm_atomic_state;
  267. struct drm_crtc_helper_funcs;
  268. struct drm_encoder_helper_funcs;
  269. struct drm_connector_helper_funcs;
  270. struct drm_plane_helper_funcs;
  271. /**
  272. * struct drm_crtc_state - mutable CRTC state
  273. * @crtc: backpointer to the CRTC
  274. * @enable: whether the CRTC should be enabled, gates all other state
  275. * @active: whether the CRTC is actively displaying (used for DPMS)
  276. * @planes_changed: planes on this crtc are updated
  277. * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
  278. * @active_changed: crtc_state->active has been toggled.
  279. * @connectors_changed: connectors to this crtc have been updated
  280. * @color_mgmt_changed: color management properties have changed (degamma or
  281. * gamma LUT or CSC matrix)
  282. * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
  283. * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
  284. * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
  285. * @last_vblank_count: for helpers and drivers to capture the vblank of the
  286. * update to ensure framebuffer cleanup isn't done too early
  287. * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
  288. * @mode: current mode timings
  289. * @mode_blob: &drm_property_blob for @mode
  290. * @degamma_lut: Lookup table for converting framebuffer pixel data
  291. * before apply the conversion matrix
  292. * @ctm: Transformation matrix
  293. * @gamma_lut: Lookup table for converting pixel data after the
  294. * conversion matrix
  295. * @event: optional pointer to a DRM event to signal upon completion of the
  296. * state update
  297. * @state: backpointer to global drm_atomic_state
  298. *
  299. * Note that the distinction between @enable and @active is rather subtile:
  300. * Flipping @active while @enable is set without changing anything else may
  301. * never return in a failure from the ->atomic_check callback. Userspace assumes
  302. * that a DPMS On will always succeed. In other words: @enable controls resource
  303. * assignment, @active controls the actual hardware state.
  304. */
  305. struct drm_crtc_state {
  306. struct drm_crtc *crtc;
  307. bool enable;
  308. bool active;
  309. /* computed state bits used by helpers and drivers */
  310. bool planes_changed : 1;
  311. bool mode_changed : 1;
  312. bool active_changed : 1;
  313. bool connectors_changed : 1;
  314. bool color_mgmt_changed : 1;
  315. /* attached planes bitmask:
  316. * WARNING: transitional helpers do not maintain plane_mask so
  317. * drivers not converted over to atomic helpers should not rely
  318. * on plane_mask being accurate!
  319. */
  320. u32 plane_mask;
  321. u32 connector_mask;
  322. u32 encoder_mask;
  323. /* last_vblank_count: for vblank waits before cleanup */
  324. u32 last_vblank_count;
  325. /* adjusted_mode: for use by helpers and drivers */
  326. struct drm_display_mode adjusted_mode;
  327. struct drm_display_mode mode;
  328. /* blob property to expose current mode to atomic userspace */
  329. struct drm_property_blob *mode_blob;
  330. /* blob property to expose color management to userspace */
  331. struct drm_property_blob *degamma_lut;
  332. struct drm_property_blob *ctm;
  333. struct drm_property_blob *gamma_lut;
  334. struct drm_pending_vblank_event *event;
  335. struct drm_atomic_state *state;
  336. };
  337. /**
  338. * struct drm_crtc_funcs - control CRTCs for a given device
  339. *
  340. * The drm_crtc_funcs structure is the central CRTC management structure
  341. * in the DRM. Each CRTC controls one or more connectors (note that the name
  342. * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
  343. * connectors, not just CRTs).
  344. *
  345. * Each driver is responsible for filling out this structure at startup time,
  346. * in addition to providing other modesetting features, like i2c and DDC
  347. * bus accessors.
  348. */
  349. struct drm_crtc_funcs {
  350. /**
  351. * @reset:
  352. *
  353. * Reset CRTC hardware and software state to off. This function isn't
  354. * called by the core directly, only through drm_mode_config_reset().
  355. * It's not a helper hook only for historical reasons.
  356. *
  357. * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
  358. * atomic state using this hook.
  359. */
  360. void (*reset)(struct drm_crtc *crtc);
  361. /**
  362. * @cursor_set:
  363. *
  364. * Update the cursor image. The cursor position is relative to the CRTC
  365. * and can be partially or fully outside of the visible area.
  366. *
  367. * Note that contrary to all other KMS functions the legacy cursor entry
  368. * points don't take a framebuffer object, but instead take directly a
  369. * raw buffer object id from the driver's buffer manager (which is
  370. * either GEM or TTM for current drivers).
  371. *
  372. * This entry point is deprecated, drivers should instead implement
  373. * universal plane support and register a proper cursor plane using
  374. * drm_crtc_init_with_planes().
  375. *
  376. * This callback is optional
  377. *
  378. * RETURNS:
  379. *
  380. * 0 on success or a negative error code on failure.
  381. */
  382. int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
  383. uint32_t handle, uint32_t width, uint32_t height);
  384. /**
  385. * @cursor_set2:
  386. *
  387. * Update the cursor image, including hotspot information. The hotspot
  388. * must not affect the cursor position in CRTC coordinates, but is only
  389. * meant as a hint for virtualized display hardware to coordinate the
  390. * guests and hosts cursor position. The cursor hotspot is relative to
  391. * the cursor image. Otherwise this works exactly like @cursor_set.
  392. *
  393. * This entry point is deprecated, drivers should instead implement
  394. * universal plane support and register a proper cursor plane using
  395. * drm_crtc_init_with_planes().
  396. *
  397. * This callback is optional.
  398. *
  399. * RETURNS:
  400. *
  401. * 0 on success or a negative error code on failure.
  402. */
  403. int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
  404. uint32_t handle, uint32_t width, uint32_t height,
  405. int32_t hot_x, int32_t hot_y);
  406. /**
  407. * @cursor_move:
  408. *
  409. * Update the cursor position. The cursor does not need to be visible
  410. * when this hook is called.
  411. *
  412. * This entry point is deprecated, drivers should instead implement
  413. * universal plane support and register a proper cursor plane using
  414. * drm_crtc_init_with_planes().
  415. *
  416. * This callback is optional.
  417. *
  418. * RETURNS:
  419. *
  420. * 0 on success or a negative error code on failure.
  421. */
  422. int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
  423. /**
  424. * @gamma_set:
  425. *
  426. * Set gamma on the CRTC.
  427. *
  428. * This callback is optional.
  429. *
  430. * NOTE:
  431. *
  432. * Drivers that support gamma tables and also fbdev emulation through
  433. * the provided helper library need to take care to fill out the gamma
  434. * hooks for both. Currently there's a bit an unfortunate duplication
  435. * going on, which should eventually be unified to just one set of
  436. * hooks.
  437. */
  438. int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  439. uint32_t size);
  440. /**
  441. * @destroy:
  442. *
  443. * Clean up plane resources. This is only called at driver unload time
  444. * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
  445. * in DRM.
  446. */
  447. void (*destroy)(struct drm_crtc *crtc);
  448. /**
  449. * @set_config:
  450. *
  451. * This is the main legacy entry point to change the modeset state on a
  452. * CRTC. All the details of the desired configuration are passed in a
  453. * struct &drm_mode_set - see there for details.
  454. *
  455. * Drivers implementing atomic modeset should use
  456. * drm_atomic_helper_set_config() to implement this hook.
  457. *
  458. * RETURNS:
  459. *
  460. * 0 on success or a negative error code on failure.
  461. */
  462. int (*set_config)(struct drm_mode_set *set);
  463. /**
  464. * @page_flip:
  465. *
  466. * Legacy entry point to schedule a flip to the given framebuffer.
  467. *
  468. * Page flipping is a synchronization mechanism that replaces the frame
  469. * buffer being scanned out by the CRTC with a new frame buffer during
  470. * vertical blanking, avoiding tearing (except when requested otherwise
  471. * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
  472. * requests a page flip the DRM core verifies that the new frame buffer
  473. * is large enough to be scanned out by the CRTC in the currently
  474. * configured mode and then calls the CRTC ->page_flip() operation with a
  475. * pointer to the new frame buffer.
  476. *
  477. * The driver must wait for any pending rendering to the new framebuffer
  478. * to complete before executing the flip. It should also wait for any
  479. * pending rendering from other drivers if the underlying buffer is a
  480. * shared dma-buf.
  481. *
  482. * An application can request to be notified when the page flip has
  483. * completed. The drm core will supply a struct &drm_event in the event
  484. * parameter in this case. This can be handled by the
  485. * drm_crtc_send_vblank_event() function, which the driver should call on
  486. * the provided event upon completion of the flip. Note that if
  487. * the driver supports vblank signalling and timestamping the vblank
  488. * counters and timestamps must agree with the ones returned from page
  489. * flip events. With the current vblank helper infrastructure this can
  490. * be achieved by holding a vblank reference while the page flip is
  491. * pending, acquired through drm_crtc_vblank_get() and released with
  492. * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
  493. * counter and timestamp tracking though, e.g. if they have accurate
  494. * timestamp registers in hardware.
  495. *
  496. * FIXME:
  497. *
  498. * Up to that point drivers need to manage events themselves and can use
  499. * even->base.list freely for that. Specifically they need to ensure
  500. * that they don't send out page flip (or vblank) events for which the
  501. * corresponding drm file has been closed already. The drm core
  502. * unfortunately does not (yet) take care of that. Therefore drivers
  503. * currently must clean up and release pending events in their
  504. * ->preclose driver function.
  505. *
  506. * This callback is optional.
  507. *
  508. * NOTE:
  509. *
  510. * Very early versions of the KMS ABI mandated that the driver must
  511. * block (but not reject) any rendering to the old framebuffer until the
  512. * flip operation has completed and the old framebuffer is no longer
  513. * visible. This requirement has been lifted, and userspace is instead
  514. * expected to request delivery of an event and wait with recycling old
  515. * buffers until such has been received.
  516. *
  517. * RETURNS:
  518. *
  519. * 0 on success or a negative error code on failure. Note that if a
  520. * ->page_flip() operation is already pending the callback should return
  521. * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
  522. * or just runtime disabled through DPMS respectively the new atomic
  523. * "ACTIVE" state) should result in an -EINVAL error code. Note that
  524. * drm_atomic_helper_page_flip() checks this already for atomic drivers.
  525. */
  526. int (*page_flip)(struct drm_crtc *crtc,
  527. struct drm_framebuffer *fb,
  528. struct drm_pending_vblank_event *event,
  529. uint32_t flags);
  530. /**
  531. * @set_property:
  532. *
  533. * This is the legacy entry point to update a property attached to the
  534. * CRTC.
  535. *
  536. * Drivers implementing atomic modeset should use
  537. * drm_atomic_helper_crtc_set_property() to implement this hook.
  538. *
  539. * This callback is optional if the driver does not support any legacy
  540. * driver-private properties.
  541. *
  542. * RETURNS:
  543. *
  544. * 0 on success or a negative error code on failure.
  545. */
  546. int (*set_property)(struct drm_crtc *crtc,
  547. struct drm_property *property, uint64_t val);
  548. /**
  549. * @atomic_duplicate_state:
  550. *
  551. * Duplicate the current atomic state for this CRTC and return it.
  552. * The core and helpers gurantee that any atomic state duplicated with
  553. * this hook and still owned by the caller (i.e. not transferred to the
  554. * driver by calling ->atomic_commit() from struct
  555. * &drm_mode_config_funcs) will be cleaned up by calling the
  556. * @atomic_destroy_state hook in this structure.
  557. *
  558. * Atomic drivers which don't subclass struct &drm_crtc should use
  559. * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
  560. * state structure to extend it with driver-private state should use
  561. * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
  562. * duplicated in a consistent fashion across drivers.
  563. *
  564. * It is an error to call this hook before crtc->state has been
  565. * initialized correctly.
  566. *
  567. * NOTE:
  568. *
  569. * If the duplicate state references refcounted resources this hook must
  570. * acquire a reference for each of them. The driver must release these
  571. * references again in @atomic_destroy_state.
  572. *
  573. * RETURNS:
  574. *
  575. * Duplicated atomic state or NULL when the allocation failed.
  576. */
  577. struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
  578. /**
  579. * @atomic_destroy_state:
  580. *
  581. * Destroy a state duplicated with @atomic_duplicate_state and release
  582. * or unreference all resources it references
  583. */
  584. void (*atomic_destroy_state)(struct drm_crtc *crtc,
  585. struct drm_crtc_state *state);
  586. /**
  587. * @atomic_set_property:
  588. *
  589. * Decode a driver-private property value and store the decoded value
  590. * into the passed-in state structure. Since the atomic core decodes all
  591. * standardized properties (even for extensions beyond the core set of
  592. * properties which might not be implemented by all drivers) this
  593. * requires drivers to subclass the state structure.
  594. *
  595. * Such driver-private properties should really only be implemented for
  596. * truly hardware/vendor specific state. Instead it is preferred to
  597. * standardize atomic extension and decode the properties used to expose
  598. * such an extension in the core.
  599. *
  600. * Do not call this function directly, use
  601. * drm_atomic_crtc_set_property() instead.
  602. *
  603. * This callback is optional if the driver does not support any
  604. * driver-private atomic properties.
  605. *
  606. * NOTE:
  607. *
  608. * This function is called in the state assembly phase of atomic
  609. * modesets, which can be aborted for any reason (including on
  610. * userspace's request to just check whether a configuration would be
  611. * possible). Drivers MUST NOT touch any persistent state (hardware or
  612. * software) or data structures except the passed in @state parameter.
  613. *
  614. * Also since userspace controls in which order properties are set this
  615. * function must not do any input validation (since the state update is
  616. * incomplete and hence likely inconsistent). Instead any such input
  617. * validation must be done in the various atomic_check callbacks.
  618. *
  619. * RETURNS:
  620. *
  621. * 0 if the property has been found, -EINVAL if the property isn't
  622. * implemented by the driver (which should never happen, the core only
  623. * asks for properties attached to this CRTC). No other validation is
  624. * allowed by the driver. The core already checks that the property
  625. * value is within the range (integer, valid enum value, ...) the driver
  626. * set when registering the property.
  627. */
  628. int (*atomic_set_property)(struct drm_crtc *crtc,
  629. struct drm_crtc_state *state,
  630. struct drm_property *property,
  631. uint64_t val);
  632. /**
  633. * @atomic_get_property:
  634. *
  635. * Reads out the decoded driver-private property. This is used to
  636. * implement the GETCRTC IOCTL.
  637. *
  638. * Do not call this function directly, use
  639. * drm_atomic_crtc_get_property() instead.
  640. *
  641. * This callback is optional if the driver does not support any
  642. * driver-private atomic properties.
  643. *
  644. * RETURNS:
  645. *
  646. * 0 on success, -EINVAL if the property isn't implemented by the
  647. * driver (which should never happen, the core only asks for
  648. * properties attached to this CRTC).
  649. */
  650. int (*atomic_get_property)(struct drm_crtc *crtc,
  651. const struct drm_crtc_state *state,
  652. struct drm_property *property,
  653. uint64_t *val);
  654. };
  655. /**
  656. * struct drm_crtc - central CRTC control structure
  657. * @dev: parent DRM device
  658. * @port: OF node used by drm_of_find_possible_crtcs()
  659. * @head: list management
  660. * @name: human readable name, can be overwritten by the driver
  661. * @mutex: per-CRTC locking
  662. * @base: base KMS object for ID tracking etc.
  663. * @primary: primary plane for this CRTC
  664. * @cursor: cursor plane for this CRTC
  665. * @cursor_x: current x position of the cursor, used for universal cursor planes
  666. * @cursor_y: current y position of the cursor, used for universal cursor planes
  667. * @enabled: is this CRTC enabled?
  668. * @mode: current mode timings
  669. * @hwmode: mode timings as programmed to hw regs
  670. * @x: x position on screen
  671. * @y: y position on screen
  672. * @funcs: CRTC control functions
  673. * @gamma_size: size of gamma ramp
  674. * @gamma_store: gamma ramp values
  675. * @helper_private: mid-layer private data
  676. * @properties: property tracking for this CRTC
  677. *
  678. * Each CRTC may have one or more connectors associated with it. This structure
  679. * allows the CRTC to be controlled.
  680. */
  681. struct drm_crtc {
  682. struct drm_device *dev;
  683. struct device_node *port;
  684. struct list_head head;
  685. char *name;
  686. /**
  687. * @mutex:
  688. *
  689. * This provides a read lock for the overall crtc state (mode, dpms
  690. * state, ...) and a write lock for everything which can be update
  691. * without a full modeset (fb, cursor data, crtc properties ...). Full
  692. * modeset also need to grab dev->mode_config.connection_mutex.
  693. */
  694. struct drm_modeset_lock mutex;
  695. struct drm_mode_object base;
  696. /* primary and cursor planes for CRTC */
  697. struct drm_plane *primary;
  698. struct drm_plane *cursor;
  699. /* position inside the mode_config.list, can be used as a [] idx */
  700. unsigned index;
  701. /* position of cursor plane on crtc */
  702. int cursor_x;
  703. int cursor_y;
  704. bool enabled;
  705. /* Requested mode from modesetting. */
  706. struct drm_display_mode mode;
  707. /* Programmed mode in hw, after adjustments for encoders,
  708. * crtc, panel scaling etc. Needed for timestamping etc.
  709. */
  710. struct drm_display_mode hwmode;
  711. int x, y;
  712. const struct drm_crtc_funcs *funcs;
  713. /* Legacy FB CRTC gamma size for reporting to userspace */
  714. uint32_t gamma_size;
  715. uint16_t *gamma_store;
  716. /* if you are using the helper */
  717. const struct drm_crtc_helper_funcs *helper_private;
  718. struct drm_object_properties properties;
  719. /**
  720. * @state:
  721. *
  722. * Current atomic state for this CRTC.
  723. */
  724. struct drm_crtc_state *state;
  725. /**
  726. * @commit_list:
  727. *
  728. * List of &drm_crtc_commit structures tracking pending commits.
  729. * Protected by @commit_lock. This list doesn't hold its own full
  730. * reference, but burrows it from the ongoing commit. Commit entries
  731. * must be removed from this list once the commit is fully completed,
  732. * but before it's correspoding &drm_atomic_state gets destroyed.
  733. */
  734. struct list_head commit_list;
  735. /**
  736. * @commit_lock:
  737. *
  738. * Spinlock to protect @commit_list.
  739. */
  740. spinlock_t commit_lock;
  741. /**
  742. * @acquire_ctx:
  743. *
  744. * Per-CRTC implicit acquire context used by atomic drivers for legacy
  745. * IOCTLs, so that atomic drivers can get at the locking acquire
  746. * context.
  747. */
  748. struct drm_modeset_acquire_ctx *acquire_ctx;
  749. };
  750. /**
  751. * struct drm_connector_state - mutable connector state
  752. * @connector: backpointer to the connector
  753. * @crtc: CRTC to connect connector to, NULL if disabled
  754. * @best_encoder: can be used by helpers and drivers to select the encoder
  755. * @state: backpointer to global drm_atomic_state
  756. */
  757. struct drm_connector_state {
  758. struct drm_connector *connector;
  759. struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
  760. struct drm_encoder *best_encoder;
  761. struct drm_atomic_state *state;
  762. };
  763. /**
  764. * struct drm_connector_funcs - control connectors on a given device
  765. *
  766. * Each CRTC may have one or more connectors attached to it. The functions
  767. * below allow the core DRM code to control connectors, enumerate available modes,
  768. * etc.
  769. */
  770. struct drm_connector_funcs {
  771. /**
  772. * @dpms:
  773. *
  774. * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
  775. * is exposed as a standard property on the connector, but diverted to
  776. * this callback in the drm core. Note that atomic drivers don't
  777. * implement the 4 level DPMS support on the connector any more, but
  778. * instead only have an on/off "ACTIVE" property on the CRTC object.
  779. *
  780. * Drivers implementing atomic modeset should use
  781. * drm_atomic_helper_connector_dpms() to implement this hook.
  782. *
  783. * RETURNS:
  784. *
  785. * 0 on success or a negative error code on failure.
  786. */
  787. int (*dpms)(struct drm_connector *connector, int mode);
  788. /**
  789. * @reset:
  790. *
  791. * Reset connector hardware and software state to off. This function isn't
  792. * called by the core directly, only through drm_mode_config_reset().
  793. * It's not a helper hook only for historical reasons.
  794. *
  795. * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
  796. * atomic state using this hook.
  797. */
  798. void (*reset)(struct drm_connector *connector);
  799. /**
  800. * @detect:
  801. *
  802. * Check to see if anything is attached to the connector. The parameter
  803. * force is set to false whilst polling, true when checking the
  804. * connector due to a user request. force can be used by the driver to
  805. * avoid expensive, destructive operations during automated probing.
  806. *
  807. * FIXME:
  808. *
  809. * Note that this hook is only called by the probe helper. It's not in
  810. * the helper library vtable purely for historical reasons. The only DRM
  811. * core entry point to probe connector state is @fill_modes.
  812. *
  813. * RETURNS:
  814. *
  815. * drm_connector_status indicating the connector's status.
  816. */
  817. enum drm_connector_status (*detect)(struct drm_connector *connector,
  818. bool force);
  819. /**
  820. * @force:
  821. *
  822. * This function is called to update internal encoder state when the
  823. * connector is forced to a certain state by userspace, either through
  824. * the sysfs interfaces or on the kernel cmdline. In that case the
  825. * @detect callback isn't called.
  826. *
  827. * FIXME:
  828. *
  829. * Note that this hook is only called by the probe helper. It's not in
  830. * the helper library vtable purely for historical reasons. The only DRM
  831. * core entry point to probe connector state is @fill_modes.
  832. */
  833. void (*force)(struct drm_connector *connector);
  834. /**
  835. * @fill_modes:
  836. *
  837. * Entry point for output detection and basic mode validation. The
  838. * driver should reprobe the output if needed (e.g. when hotplug
  839. * handling is unreliable), add all detected modes to connector->modes
  840. * and filter out any the device can't support in any configuration. It
  841. * also needs to filter out any modes wider or higher than the
  842. * parameters max_width and max_height indicate.
  843. *
  844. * The drivers must also prune any modes no longer valid from
  845. * connector->modes. Furthermore it must update connector->status and
  846. * connector->edid. If no EDID has been received for this output
  847. * connector->edid must be NULL.
  848. *
  849. * Drivers using the probe helpers should use
  850. * drm_helper_probe_single_connector_modes() or
  851. * drm_helper_probe_single_connector_modes_nomerge() to implement this
  852. * function.
  853. *
  854. * RETURNS:
  855. *
  856. * The number of modes detected and filled into connector->modes.
  857. */
  858. int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
  859. /**
  860. * @set_property:
  861. *
  862. * This is the legacy entry point to update a property attached to the
  863. * connector.
  864. *
  865. * Drivers implementing atomic modeset should use
  866. * drm_atomic_helper_connector_set_property() to implement this hook.
  867. *
  868. * This callback is optional if the driver does not support any legacy
  869. * driver-private properties.
  870. *
  871. * RETURNS:
  872. *
  873. * 0 on success or a negative error code on failure.
  874. */
  875. int (*set_property)(struct drm_connector *connector, struct drm_property *property,
  876. uint64_t val);
  877. /**
  878. * @destroy:
  879. *
  880. * Clean up connector resources. This is called at driver unload time
  881. * through drm_mode_config_cleanup(). It can also be called at runtime
  882. * when a connector is being hot-unplugged for drivers that support
  883. * connector hotplugging (e.g. DisplayPort MST).
  884. */
  885. void (*destroy)(struct drm_connector *connector);
  886. /**
  887. * @atomic_duplicate_state:
  888. *
  889. * Duplicate the current atomic state for this connector and return it.
  890. * The core and helpers gurantee that any atomic state duplicated with
  891. * this hook and still owned by the caller (i.e. not transferred to the
  892. * driver by calling ->atomic_commit() from struct
  893. * &drm_mode_config_funcs) will be cleaned up by calling the
  894. * @atomic_destroy_state hook in this structure.
  895. *
  896. * Atomic drivers which don't subclass struct &drm_connector_state should use
  897. * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
  898. * state structure to extend it with driver-private state should use
  899. * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
  900. * duplicated in a consistent fashion across drivers.
  901. *
  902. * It is an error to call this hook before connector->state has been
  903. * initialized correctly.
  904. *
  905. * NOTE:
  906. *
  907. * If the duplicate state references refcounted resources this hook must
  908. * acquire a reference for each of them. The driver must release these
  909. * references again in @atomic_destroy_state.
  910. *
  911. * RETURNS:
  912. *
  913. * Duplicated atomic state or NULL when the allocation failed.
  914. */
  915. struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
  916. /**
  917. * @atomic_destroy_state:
  918. *
  919. * Destroy a state duplicated with @atomic_duplicate_state and release
  920. * or unreference all resources it references
  921. */
  922. void (*atomic_destroy_state)(struct drm_connector *connector,
  923. struct drm_connector_state *state);
  924. /**
  925. * @atomic_set_property:
  926. *
  927. * Decode a driver-private property value and store the decoded value
  928. * into the passed-in state structure. Since the atomic core decodes all
  929. * standardized properties (even for extensions beyond the core set of
  930. * properties which might not be implemented by all drivers) this
  931. * requires drivers to subclass the state structure.
  932. *
  933. * Such driver-private properties should really only be implemented for
  934. * truly hardware/vendor specific state. Instead it is preferred to
  935. * standardize atomic extension and decode the properties used to expose
  936. * such an extension in the core.
  937. *
  938. * Do not call this function directly, use
  939. * drm_atomic_connector_set_property() instead.
  940. *
  941. * This callback is optional if the driver does not support any
  942. * driver-private atomic properties.
  943. *
  944. * NOTE:
  945. *
  946. * This function is called in the state assembly phase of atomic
  947. * modesets, which can be aborted for any reason (including on
  948. * userspace's request to just check whether a configuration would be
  949. * possible). Drivers MUST NOT touch any persistent state (hardware or
  950. * software) or data structures except the passed in @state parameter.
  951. *
  952. * Also since userspace controls in which order properties are set this
  953. * function must not do any input validation (since the state update is
  954. * incomplete and hence likely inconsistent). Instead any such input
  955. * validation must be done in the various atomic_check callbacks.
  956. *
  957. * RETURNS:
  958. *
  959. * 0 if the property has been found, -EINVAL if the property isn't
  960. * implemented by the driver (which shouldn't ever happen, the core only
  961. * asks for properties attached to this connector). No other validation
  962. * is allowed by the driver. The core already checks that the property
  963. * value is within the range (integer, valid enum value, ...) the driver
  964. * set when registering the property.
  965. */
  966. int (*atomic_set_property)(struct drm_connector *connector,
  967. struct drm_connector_state *state,
  968. struct drm_property *property,
  969. uint64_t val);
  970. /**
  971. * @atomic_get_property:
  972. *
  973. * Reads out the decoded driver-private property. This is used to
  974. * implement the GETCONNECTOR IOCTL.
  975. *
  976. * Do not call this function directly, use
  977. * drm_atomic_connector_get_property() instead.
  978. *
  979. * This callback is optional if the driver does not support any
  980. * driver-private atomic properties.
  981. *
  982. * RETURNS:
  983. *
  984. * 0 on success, -EINVAL if the property isn't implemented by the
  985. * driver (which shouldn't ever happen, the core only asks for
  986. * properties attached to this connector).
  987. */
  988. int (*atomic_get_property)(struct drm_connector *connector,
  989. const struct drm_connector_state *state,
  990. struct drm_property *property,
  991. uint64_t *val);
  992. };
  993. /**
  994. * struct drm_encoder_funcs - encoder controls
  995. *
  996. * Encoders sit between CRTCs and connectors.
  997. */
  998. struct drm_encoder_funcs {
  999. /**
  1000. * @reset:
  1001. *
  1002. * Reset encoder hardware and software state to off. This function isn't
  1003. * called by the core directly, only through drm_mode_config_reset().
  1004. * It's not a helper hook only for historical reasons.
  1005. */
  1006. void (*reset)(struct drm_encoder *encoder);
  1007. /**
  1008. * @destroy:
  1009. *
  1010. * Clean up encoder resources. This is only called at driver unload time
  1011. * through drm_mode_config_cleanup() since an encoder cannot be
  1012. * hotplugged in DRM.
  1013. */
  1014. void (*destroy)(struct drm_encoder *encoder);
  1015. };
  1016. #define DRM_CONNECTOR_MAX_ENCODER 3
  1017. /**
  1018. * struct drm_encoder - central DRM encoder structure
  1019. * @dev: parent DRM device
  1020. * @head: list management
  1021. * @base: base KMS object
  1022. * @name: human readable name, can be overwritten by the driver
  1023. * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
  1024. * @possible_crtcs: bitmask of potential CRTC bindings
  1025. * @possible_clones: bitmask of potential sibling encoders for cloning
  1026. * @crtc: currently bound CRTC
  1027. * @bridge: bridge associated to the encoder
  1028. * @funcs: control functions
  1029. * @helper_private: mid-layer private data
  1030. *
  1031. * CRTCs drive pixels to encoders, which convert them into signals
  1032. * appropriate for a given connector or set of connectors.
  1033. */
  1034. struct drm_encoder {
  1035. struct drm_device *dev;
  1036. struct list_head head;
  1037. struct drm_mode_object base;
  1038. char *name;
  1039. int encoder_type;
  1040. /* position inside the mode_config.list, can be used as a [] idx */
  1041. unsigned index;
  1042. uint32_t possible_crtcs;
  1043. uint32_t possible_clones;
  1044. struct drm_crtc *crtc;
  1045. struct drm_bridge *bridge;
  1046. const struct drm_encoder_funcs *funcs;
  1047. const struct drm_encoder_helper_funcs *helper_private;
  1048. };
  1049. /* should we poll this connector for connects and disconnects */
  1050. /* hot plug detectable */
  1051. #define DRM_CONNECTOR_POLL_HPD (1 << 0)
  1052. /* poll for connections */
  1053. #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
  1054. /* can cleanly poll for disconnections without flickering the screen */
  1055. /* DACs should rarely do this without a lot of testing */
  1056. #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
  1057. #define MAX_ELD_BYTES 128
  1058. /**
  1059. * struct drm_connector - central DRM connector control structure
  1060. * @dev: parent DRM device
  1061. * @kdev: kernel device for sysfs attributes
  1062. * @attr: sysfs attributes
  1063. * @head: list management
  1064. * @base: base KMS object
  1065. * @name: human readable name, can be overwritten by the driver
  1066. * @connector_id: compacted connector id useful indexing arrays
  1067. * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
  1068. * @connector_type_id: index into connector type enum
  1069. * @interlace_allowed: can this connector handle interlaced modes?
  1070. * @doublescan_allowed: can this connector handle doublescan?
  1071. * @stereo_allowed: can this connector handle stereo modes?
  1072. * @modes: modes available on this connector (from fill_modes() + user)
  1073. * @status: one of the drm_connector_status enums (connected, not, or unknown)
  1074. * @probed_modes: list of modes derived directly from the display
  1075. * @display_info: information about attached display (e.g. from EDID)
  1076. * @funcs: connector control functions
  1077. * @edid_blob_ptr: DRM property containing EDID if present
  1078. * @properties: property tracking for this connector
  1079. * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
  1080. * @dpms: current dpms state
  1081. * @helper_private: mid-layer private data
  1082. * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
  1083. * @force: a %DRM_FORCE_<foo> state for forced mode sets
  1084. * @override_edid: has the EDID been overwritten through debugfs for testing?
  1085. * @encoder_ids: valid encoders for this connector
  1086. * @encoder: encoder driving this connector, if any
  1087. * @eld: EDID-like data, if present
  1088. * @dvi_dual: dual link DVI, if found
  1089. * @max_tmds_clock: max clock rate, if found
  1090. * @latency_present: AV delay info from ELD, if found
  1091. * @video_latency: video latency info from ELD, if found
  1092. * @audio_latency: audio latency info from ELD, if found
  1093. * @null_edid_counter: track sinks that give us all zeros for the EDID
  1094. * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
  1095. * @edid_corrupt: indicates whether the last read EDID was corrupt
  1096. * @debugfs_entry: debugfs directory for this connector
  1097. * @state: current atomic state for this connector
  1098. * @has_tile: is this connector connected to a tiled monitor
  1099. * @tile_group: tile group for the connected monitor
  1100. * @tile_is_single_monitor: whether the tile is one monitor housing
  1101. * @num_h_tile: number of horizontal tiles in the tile group
  1102. * @num_v_tile: number of vertical tiles in the tile group
  1103. * @tile_h_loc: horizontal location of this tile
  1104. * @tile_v_loc: vertical location of this tile
  1105. * @tile_h_size: horizontal size of this tile.
  1106. * @tile_v_size: vertical size of this tile.
  1107. *
  1108. * Each connector may be connected to one or more CRTCs, or may be clonable by
  1109. * another connector if they can share a CRTC. Each connector also has a specific
  1110. * position in the broader display (referred to as a 'screen' though it could
  1111. * span multiple monitors).
  1112. */
  1113. struct drm_connector {
  1114. struct drm_device *dev;
  1115. struct device *kdev;
  1116. struct device_attribute *attr;
  1117. struct list_head head;
  1118. struct drm_mode_object base;
  1119. char *name;
  1120. int connector_id;
  1121. int connector_type;
  1122. int connector_type_id;
  1123. bool interlace_allowed;
  1124. bool doublescan_allowed;
  1125. bool stereo_allowed;
  1126. struct list_head modes; /* list of modes on this connector */
  1127. enum drm_connector_status status;
  1128. /* these are modes added by probing with DDC or the BIOS */
  1129. struct list_head probed_modes;
  1130. struct drm_display_info display_info;
  1131. const struct drm_connector_funcs *funcs;
  1132. struct drm_property_blob *edid_blob_ptr;
  1133. struct drm_object_properties properties;
  1134. /**
  1135. * @path_blob_ptr:
  1136. *
  1137. * DRM blob property data for the DP MST path property.
  1138. */
  1139. struct drm_property_blob *path_blob_ptr;
  1140. /**
  1141. * @tile_blob_ptr:
  1142. *
  1143. * DRM blob property data for the tile property (used mostly by DP MST).
  1144. * This is meant for screens which are driven through separate display
  1145. * pipelines represented by &drm_crtc, which might not be running with
  1146. * genlocked clocks. For tiled panels which are genlocked, like
  1147. * dual-link LVDS or dual-link DSI, the driver should try to not expose
  1148. * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
  1149. */
  1150. struct drm_property_blob *tile_blob_ptr;
  1151. uint8_t polled; /* DRM_CONNECTOR_POLL_* */
  1152. /* requested DPMS state */
  1153. int dpms;
  1154. const struct drm_connector_helper_funcs *helper_private;
  1155. /* forced on connector */
  1156. struct drm_cmdline_mode cmdline_mode;
  1157. enum drm_connector_force force;
  1158. bool override_edid;
  1159. uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
  1160. struct drm_encoder *encoder; /* currently active encoder */
  1161. /* EDID bits */
  1162. uint8_t eld[MAX_ELD_BYTES];
  1163. bool dvi_dual;
  1164. int max_tmds_clock; /* in MHz */
  1165. bool latency_present[2];
  1166. int video_latency[2]; /* [0]: progressive, [1]: interlaced */
  1167. int audio_latency[2];
  1168. int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
  1169. unsigned bad_edid_counter;
  1170. /* Flag for raw EDID header corruption - used in Displayport
  1171. * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
  1172. */
  1173. bool edid_corrupt;
  1174. struct dentry *debugfs_entry;
  1175. struct drm_connector_state *state;
  1176. /* DisplayID bits */
  1177. bool has_tile;
  1178. struct drm_tile_group *tile_group;
  1179. bool tile_is_single_monitor;
  1180. uint8_t num_h_tile, num_v_tile;
  1181. uint8_t tile_h_loc, tile_v_loc;
  1182. uint16_t tile_h_size, tile_v_size;
  1183. };
  1184. /**
  1185. * struct drm_plane_state - mutable plane state
  1186. * @plane: backpointer to the plane
  1187. * @crtc: currently bound CRTC, NULL if disabled
  1188. * @fb: currently bound framebuffer
  1189. * @fence: optional fence to wait for before scanning out @fb
  1190. * @crtc_x: left position of visible portion of plane on crtc
  1191. * @crtc_y: upper position of visible portion of plane on crtc
  1192. * @crtc_w: width of visible portion of plane on crtc
  1193. * @crtc_h: height of visible portion of plane on crtc
  1194. * @src_x: left position of visible portion of plane within
  1195. * plane (in 16.16)
  1196. * @src_y: upper position of visible portion of plane within
  1197. * plane (in 16.16)
  1198. * @src_w: width of visible portion of plane (in 16.16)
  1199. * @src_h: height of visible portion of plane (in 16.16)
  1200. * @rotation: rotation of the plane
  1201. * @state: backpointer to global drm_atomic_state
  1202. */
  1203. struct drm_plane_state {
  1204. struct drm_plane *plane;
  1205. struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
  1206. struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
  1207. struct fence *fence;
  1208. /* Signed dest location allows it to be partially off screen */
  1209. int32_t crtc_x, crtc_y;
  1210. uint32_t crtc_w, crtc_h;
  1211. /* Source values are 16.16 fixed point */
  1212. uint32_t src_x, src_y;
  1213. uint32_t src_h, src_w;
  1214. /* Plane rotation */
  1215. unsigned int rotation;
  1216. struct drm_atomic_state *state;
  1217. };
  1218. /**
  1219. * struct drm_plane_funcs - driver plane control functions
  1220. */
  1221. struct drm_plane_funcs {
  1222. /**
  1223. * @update_plane:
  1224. *
  1225. * This is the legacy entry point to enable and configure the plane for
  1226. * the given CRTC and framebuffer. It is never called to disable the
  1227. * plane, i.e. the passed-in crtc and fb paramters are never NULL.
  1228. *
  1229. * The source rectangle in frame buffer memory coordinates is given by
  1230. * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
  1231. * values). Devices that don't support subpixel plane coordinates can
  1232. * ignore the fractional part.
  1233. *
  1234. * The destination rectangle in CRTC coordinates is given by the
  1235. * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
  1236. * Devices scale the source rectangle to the destination rectangle. If
  1237. * scaling is not supported, and the source rectangle size doesn't match
  1238. * the destination rectangle size, the driver must return a
  1239. * -<errorname>EINVAL</errorname> error.
  1240. *
  1241. * Drivers implementing atomic modeset should use
  1242. * drm_atomic_helper_update_plane() to implement this hook.
  1243. *
  1244. * RETURNS:
  1245. *
  1246. * 0 on success or a negative error code on failure.
  1247. */
  1248. int (*update_plane)(struct drm_plane *plane,
  1249. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1250. int crtc_x, int crtc_y,
  1251. unsigned int crtc_w, unsigned int crtc_h,
  1252. uint32_t src_x, uint32_t src_y,
  1253. uint32_t src_w, uint32_t src_h);
  1254. /**
  1255. * @disable_plane:
  1256. *
  1257. * This is the legacy entry point to disable the plane. The DRM core
  1258. * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
  1259. * with the frame buffer ID set to 0. Disabled planes must not be
  1260. * processed by the CRTC.
  1261. *
  1262. * Drivers implementing atomic modeset should use
  1263. * drm_atomic_helper_disable_plane() to implement this hook.
  1264. *
  1265. * RETURNS:
  1266. *
  1267. * 0 on success or a negative error code on failure.
  1268. */
  1269. int (*disable_plane)(struct drm_plane *plane);
  1270. /**
  1271. * @destroy:
  1272. *
  1273. * Clean up plane resources. This is only called at driver unload time
  1274. * through drm_mode_config_cleanup() since a plane cannot be hotplugged
  1275. * in DRM.
  1276. */
  1277. void (*destroy)(struct drm_plane *plane);
  1278. /**
  1279. * @reset:
  1280. *
  1281. * Reset plane hardware and software state to off. This function isn't
  1282. * called by the core directly, only through drm_mode_config_reset().
  1283. * It's not a helper hook only for historical reasons.
  1284. *
  1285. * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
  1286. * atomic state using this hook.
  1287. */
  1288. void (*reset)(struct drm_plane *plane);
  1289. /**
  1290. * @set_property:
  1291. *
  1292. * This is the legacy entry point to update a property attached to the
  1293. * plane.
  1294. *
  1295. * Drivers implementing atomic modeset should use
  1296. * drm_atomic_helper_plane_set_property() to implement this hook.
  1297. *
  1298. * This callback is optional if the driver does not support any legacy
  1299. * driver-private properties.
  1300. *
  1301. * RETURNS:
  1302. *
  1303. * 0 on success or a negative error code on failure.
  1304. */
  1305. int (*set_property)(struct drm_plane *plane,
  1306. struct drm_property *property, uint64_t val);
  1307. /**
  1308. * @atomic_duplicate_state:
  1309. *
  1310. * Duplicate the current atomic state for this plane and return it.
  1311. * The core and helpers gurantee that any atomic state duplicated with
  1312. * this hook and still owned by the caller (i.e. not transferred to the
  1313. * driver by calling ->atomic_commit() from struct
  1314. * &drm_mode_config_funcs) will be cleaned up by calling the
  1315. * @atomic_destroy_state hook in this structure.
  1316. *
  1317. * Atomic drivers which don't subclass struct &drm_plane_state should use
  1318. * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
  1319. * state structure to extend it with driver-private state should use
  1320. * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
  1321. * duplicated in a consistent fashion across drivers.
  1322. *
  1323. * It is an error to call this hook before plane->state has been
  1324. * initialized correctly.
  1325. *
  1326. * NOTE:
  1327. *
  1328. * If the duplicate state references refcounted resources this hook must
  1329. * acquire a reference for each of them. The driver must release these
  1330. * references again in @atomic_destroy_state.
  1331. *
  1332. * RETURNS:
  1333. *
  1334. * Duplicated atomic state or NULL when the allocation failed.
  1335. */
  1336. struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
  1337. /**
  1338. * @atomic_destroy_state:
  1339. *
  1340. * Destroy a state duplicated with @atomic_duplicate_state and release
  1341. * or unreference all resources it references
  1342. */
  1343. void (*atomic_destroy_state)(struct drm_plane *plane,
  1344. struct drm_plane_state *state);
  1345. /**
  1346. * @atomic_set_property:
  1347. *
  1348. * Decode a driver-private property value and store the decoded value
  1349. * into the passed-in state structure. Since the atomic core decodes all
  1350. * standardized properties (even for extensions beyond the core set of
  1351. * properties which might not be implemented by all drivers) this
  1352. * requires drivers to subclass the state structure.
  1353. *
  1354. * Such driver-private properties should really only be implemented for
  1355. * truly hardware/vendor specific state. Instead it is preferred to
  1356. * standardize atomic extension and decode the properties used to expose
  1357. * such an extension in the core.
  1358. *
  1359. * Do not call this function directly, use
  1360. * drm_atomic_plane_set_property() instead.
  1361. *
  1362. * This callback is optional if the driver does not support any
  1363. * driver-private atomic properties.
  1364. *
  1365. * NOTE:
  1366. *
  1367. * This function is called in the state assembly phase of atomic
  1368. * modesets, which can be aborted for any reason (including on
  1369. * userspace's request to just check whether a configuration would be
  1370. * possible). Drivers MUST NOT touch any persistent state (hardware or
  1371. * software) or data structures except the passed in @state parameter.
  1372. *
  1373. * Also since userspace controls in which order properties are set this
  1374. * function must not do any input validation (since the state update is
  1375. * incomplete and hence likely inconsistent). Instead any such input
  1376. * validation must be done in the various atomic_check callbacks.
  1377. *
  1378. * RETURNS:
  1379. *
  1380. * 0 if the property has been found, -EINVAL if the property isn't
  1381. * implemented by the driver (which shouldn't ever happen, the core only
  1382. * asks for properties attached to this plane). No other validation is
  1383. * allowed by the driver. The core already checks that the property
  1384. * value is within the range (integer, valid enum value, ...) the driver
  1385. * set when registering the property.
  1386. */
  1387. int (*atomic_set_property)(struct drm_plane *plane,
  1388. struct drm_plane_state *state,
  1389. struct drm_property *property,
  1390. uint64_t val);
  1391. /**
  1392. * @atomic_get_property:
  1393. *
  1394. * Reads out the decoded driver-private property. This is used to
  1395. * implement the GETPLANE IOCTL.
  1396. *
  1397. * Do not call this function directly, use
  1398. * drm_atomic_plane_get_property() instead.
  1399. *
  1400. * This callback is optional if the driver does not support any
  1401. * driver-private atomic properties.
  1402. *
  1403. * RETURNS:
  1404. *
  1405. * 0 on success, -EINVAL if the property isn't implemented by the
  1406. * driver (which should never happen, the core only asks for
  1407. * properties attached to this plane).
  1408. */
  1409. int (*atomic_get_property)(struct drm_plane *plane,
  1410. const struct drm_plane_state *state,
  1411. struct drm_property *property,
  1412. uint64_t *val);
  1413. };
  1414. enum drm_plane_type {
  1415. DRM_PLANE_TYPE_OVERLAY,
  1416. DRM_PLANE_TYPE_PRIMARY,
  1417. DRM_PLANE_TYPE_CURSOR,
  1418. };
  1419. /**
  1420. * struct drm_plane - central DRM plane control structure
  1421. * @dev: DRM device this plane belongs to
  1422. * @head: for list management
  1423. * @name: human readable name, can be overwritten by the driver
  1424. * @base: base mode object
  1425. * @possible_crtcs: pipes this plane can be bound to
  1426. * @format_types: array of formats supported by this plane
  1427. * @format_count: number of formats supported
  1428. * @format_default: driver hasn't supplied supported formats for the plane
  1429. * @crtc: currently bound CRTC
  1430. * @fb: currently bound fb
  1431. * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
  1432. * drm_mode_set_config_internal() to implement correct refcounting.
  1433. * @funcs: helper functions
  1434. * @properties: property tracking for this plane
  1435. * @type: type of plane (overlay, primary, cursor)
  1436. * @state: current atomic state for this plane
  1437. * @helper_private: mid-layer private data
  1438. */
  1439. struct drm_plane {
  1440. struct drm_device *dev;
  1441. struct list_head head;
  1442. char *name;
  1443. /**
  1444. * @mutex:
  1445. *
  1446. * Protects modeset plane state, together with the mutex of &drm_crtc
  1447. * this plane is linked to (when active, getting actived or getting
  1448. * disabled).
  1449. */
  1450. struct drm_modeset_lock mutex;
  1451. struct drm_mode_object base;
  1452. uint32_t possible_crtcs;
  1453. uint32_t *format_types;
  1454. unsigned int format_count;
  1455. bool format_default;
  1456. struct drm_crtc *crtc;
  1457. struct drm_framebuffer *fb;
  1458. struct drm_framebuffer *old_fb;
  1459. const struct drm_plane_funcs *funcs;
  1460. struct drm_object_properties properties;
  1461. enum drm_plane_type type;
  1462. /* position inside the mode_config.list, can be used as a [] idx */
  1463. unsigned index;
  1464. const struct drm_plane_helper_funcs *helper_private;
  1465. struct drm_plane_state *state;
  1466. };
  1467. /**
  1468. * struct drm_bridge_funcs - drm_bridge control functions
  1469. * @attach: Called during drm_bridge_attach
  1470. */
  1471. struct drm_bridge_funcs {
  1472. int (*attach)(struct drm_bridge *bridge);
  1473. /**
  1474. * @mode_fixup:
  1475. *
  1476. * This callback is used to validate and adjust a mode. The paramater
  1477. * mode is the display mode that should be fed to the next element in
  1478. * the display chain, either the final &drm_connector or the next
  1479. * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
  1480. * requires. It can be modified by this callback and does not need to
  1481. * match mode.
  1482. *
  1483. * This is the only hook that allows a bridge to reject a modeset. If
  1484. * this function passes all other callbacks must succeed for this
  1485. * configuration.
  1486. *
  1487. * NOTE:
  1488. *
  1489. * This function is called in the check phase of atomic modesets, which
  1490. * can be aborted for any reason (including on userspace's request to
  1491. * just check whether a configuration would be possible). Drivers MUST
  1492. * NOT touch any persistent state (hardware or software) or data
  1493. * structures except the passed in @state parameter.
  1494. *
  1495. * RETURNS:
  1496. *
  1497. * True if an acceptable configuration is possible, false if the modeset
  1498. * operation should be rejected.
  1499. */
  1500. bool (*mode_fixup)(struct drm_bridge *bridge,
  1501. const struct drm_display_mode *mode,
  1502. struct drm_display_mode *adjusted_mode);
  1503. /**
  1504. * @disable:
  1505. *
  1506. * This callback should disable the bridge. It is called right before
  1507. * the preceding element in the display pipe is disabled. If the
  1508. * preceding element is a bridge this means it's called before that
  1509. * bridge's ->disable() function. If the preceding element is a
  1510. * &drm_encoder it's called right before the encoder's ->disable(),
  1511. * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
  1512. *
  1513. * The bridge can assume that the display pipe (i.e. clocks and timing
  1514. * signals) feeding it is still running when this callback is called.
  1515. *
  1516. * The disable callback is optional.
  1517. */
  1518. void (*disable)(struct drm_bridge *bridge);
  1519. /**
  1520. * @post_disable:
  1521. *
  1522. * This callback should disable the bridge. It is called right after
  1523. * the preceding element in the display pipe is disabled. If the
  1524. * preceding element is a bridge this means it's called after that
  1525. * bridge's ->post_disable() function. If the preceding element is a
  1526. * &drm_encoder it's called right after the encoder's ->disable(),
  1527. * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
  1528. *
  1529. * The bridge must assume that the display pipe (i.e. clocks and timing
  1530. * singals) feeding it is no longer running when this callback is
  1531. * called.
  1532. *
  1533. * The post_disable callback is optional.
  1534. */
  1535. void (*post_disable)(struct drm_bridge *bridge);
  1536. /**
  1537. * @mode_set:
  1538. *
  1539. * This callback should set the given mode on the bridge. It is called
  1540. * after the ->mode_set() callback for the preceding element in the
  1541. * display pipeline has been called already. The display pipe (i.e.
  1542. * clocks and timing signals) is off when this function is called.
  1543. */
  1544. void (*mode_set)(struct drm_bridge *bridge,
  1545. struct drm_display_mode *mode,
  1546. struct drm_display_mode *adjusted_mode);
  1547. /**
  1548. * @pre_enable:
  1549. *
  1550. * This callback should enable the bridge. It is called right before
  1551. * the preceding element in the display pipe is enabled. If the
  1552. * preceding element is a bridge this means it's called before that
  1553. * bridge's ->pre_enable() function. If the preceding element is a
  1554. * &drm_encoder it's called right before the encoder's ->enable(),
  1555. * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
  1556. *
  1557. * The display pipe (i.e. clocks and timing signals) feeding this bridge
  1558. * will not yet be running when this callback is called. The bridge must
  1559. * not enable the display link feeding the next bridge in the chain (if
  1560. * there is one) when this callback is called.
  1561. *
  1562. * The pre_enable callback is optional.
  1563. */
  1564. void (*pre_enable)(struct drm_bridge *bridge);
  1565. /**
  1566. * @enable:
  1567. *
  1568. * This callback should enable the bridge. It is called right after
  1569. * the preceding element in the display pipe is enabled. If the
  1570. * preceding element is a bridge this means it's called after that
  1571. * bridge's ->enable() function. If the preceding element is a
  1572. * &drm_encoder it's called right after the encoder's ->enable(),
  1573. * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
  1574. *
  1575. * The bridge can assume that the display pipe (i.e. clocks and timing
  1576. * signals) feeding it is running when this callback is called. This
  1577. * callback must enable the display link feeding the next bridge in the
  1578. * chain if there is one.
  1579. *
  1580. * The enable callback is optional.
  1581. */
  1582. void (*enable)(struct drm_bridge *bridge);
  1583. };
  1584. /**
  1585. * struct drm_bridge - central DRM bridge control structure
  1586. * @dev: DRM device this bridge belongs to
  1587. * @encoder: encoder to which this bridge is connected
  1588. * @next: the next bridge in the encoder chain
  1589. * @of_node: device node pointer to the bridge
  1590. * @list: to keep track of all added bridges
  1591. * @funcs: control functions
  1592. * @driver_private: pointer to the bridge driver's internal context
  1593. */
  1594. struct drm_bridge {
  1595. struct drm_device *dev;
  1596. struct drm_encoder *encoder;
  1597. struct drm_bridge *next;
  1598. #ifdef CONFIG_OF
  1599. struct device_node *of_node;
  1600. #endif
  1601. struct list_head list;
  1602. const struct drm_bridge_funcs *funcs;
  1603. void *driver_private;
  1604. };
  1605. /**
  1606. * struct drm_crtc_commit - track modeset commits on a CRTC
  1607. *
  1608. * This structure is used to track pending modeset changes and atomic commit on
  1609. * a per-CRTC basis. Since updating the list should never block this structure
  1610. * is reference counted to allow waiters to safely wait on an event to complete,
  1611. * without holding any locks.
  1612. *
  1613. * It has 3 different events in total to allow a fine-grained synchronization
  1614. * between outstanding updates::
  1615. *
  1616. * atomic commit thread hardware
  1617. *
  1618. * write new state into hardware ----> ...
  1619. * signal hw_done
  1620. * switch to new state on next
  1621. * ... v/hblank
  1622. *
  1623. * wait for buffers to show up ...
  1624. *
  1625. * ... send completion irq
  1626. * irq handler signals flip_done
  1627. * cleanup old buffers
  1628. *
  1629. * signal cleanup_done
  1630. *
  1631. * wait for flip_done <----
  1632. * clean up atomic state
  1633. *
  1634. * The important bit to know is that cleanup_done is the terminal event, but the
  1635. * ordering between flip_done and hw_done is entirely up to the specific driver
  1636. * and modeset state change.
  1637. *
  1638. * For an implementation of how to use this look at
  1639. * drm_atomic_helper_setup_commit() from the atomic helper library.
  1640. */
  1641. struct drm_crtc_commit {
  1642. /**
  1643. * @crtc:
  1644. *
  1645. * DRM CRTC for this commit.
  1646. */
  1647. struct drm_crtc *crtc;
  1648. /**
  1649. * @ref:
  1650. *
  1651. * Reference count for this structure. Needed to allow blocking on
  1652. * completions without the risk of the completion disappearing
  1653. * meanwhile.
  1654. */
  1655. struct kref ref;
  1656. /**
  1657. * @flip_done:
  1658. *
  1659. * Will be signaled when the hardware has flipped to the new set of
  1660. * buffers. Signals at the same time as when the drm event for this
  1661. * commit is sent to userspace, or when an out-fence is singalled. Note
  1662. * that for most hardware, in most cases this happens after @hw_done is
  1663. * signalled.
  1664. */
  1665. struct completion flip_done;
  1666. /**
  1667. * @hw_done:
  1668. *
  1669. * Will be signalled when all hw register changes for this commit have
  1670. * been written out. Especially when disabling a pipe this can be much
  1671. * later than than @flip_done, since that can signal already when the
  1672. * screen goes black, whereas to fully shut down a pipe more register
  1673. * I/O is required.
  1674. *
  1675. * Note that this does not need to include separately reference-counted
  1676. * resources like backing storage buffer pinning, or runtime pm
  1677. * management.
  1678. */
  1679. struct completion hw_done;
  1680. /**
  1681. * @cleanup_done:
  1682. *
  1683. * Will be signalled after old buffers have been cleaned up by calling
  1684. * drm_atomic_helper_cleanup_planes(). Since this can only happen after
  1685. * a vblank wait completed it might be a bit later. This completion is
  1686. * useful to throttle updates and avoid hardware updates getting ahead
  1687. * of the buffer cleanup too much.
  1688. */
  1689. struct completion cleanup_done;
  1690. /**
  1691. * @commit_entry:
  1692. *
  1693. * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
  1694. */
  1695. struct list_head commit_entry;
  1696. /**
  1697. * @event:
  1698. *
  1699. * &drm_pending_vblank_event pointer to clean up private events.
  1700. */
  1701. struct drm_pending_vblank_event *event;
  1702. };
  1703. struct __drm_planes_state {
  1704. struct drm_plane *ptr;
  1705. struct drm_plane_state *state;
  1706. };
  1707. struct __drm_crtcs_state {
  1708. struct drm_crtc *ptr;
  1709. struct drm_crtc_state *state;
  1710. struct drm_crtc_commit *commit;
  1711. };
  1712. struct __drm_connnectors_state {
  1713. struct drm_connector *ptr;
  1714. struct drm_connector_state *state;
  1715. };
  1716. /**
  1717. * struct drm_atomic_state - the global state object for atomic updates
  1718. * @dev: parent DRM device
  1719. * @allow_modeset: allow full modeset
  1720. * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
  1721. * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
  1722. * @planes: pointer to array of structures with per-plane data
  1723. * @crtcs: pointer to array of CRTC pointers
  1724. * @num_connector: size of the @connectors and @connector_states arrays
  1725. * @connectors: pointer to array of structures with per-connector data
  1726. * @acquire_ctx: acquire context for this atomic modeset state update
  1727. */
  1728. struct drm_atomic_state {
  1729. struct drm_device *dev;
  1730. bool allow_modeset : 1;
  1731. bool legacy_cursor_update : 1;
  1732. bool legacy_set_config : 1;
  1733. struct __drm_planes_state *planes;
  1734. struct __drm_crtcs_state *crtcs;
  1735. int num_connector;
  1736. struct __drm_connnectors_state *connectors;
  1737. struct drm_modeset_acquire_ctx *acquire_ctx;
  1738. /**
  1739. * @commit_work:
  1740. *
  1741. * Work item which can be used by the driver or helpers to execute the
  1742. * commit without blocking.
  1743. */
  1744. struct work_struct commit_work;
  1745. };
  1746. /**
  1747. * struct drm_mode_set - new values for a CRTC config change
  1748. * @fb: framebuffer to use for new config
  1749. * @crtc: CRTC whose configuration we're about to change
  1750. * @mode: mode timings to use
  1751. * @x: position of this CRTC relative to @fb
  1752. * @y: position of this CRTC relative to @fb
  1753. * @connectors: array of connectors to drive with this CRTC if possible
  1754. * @num_connectors: size of @connectors array
  1755. *
  1756. * Represents a single crtc the connectors that it drives with what mode
  1757. * and from which framebuffer it scans out from.
  1758. *
  1759. * This is used to set modes.
  1760. */
  1761. struct drm_mode_set {
  1762. struct drm_framebuffer *fb;
  1763. struct drm_crtc *crtc;
  1764. struct drm_display_mode *mode;
  1765. uint32_t x;
  1766. uint32_t y;
  1767. struct drm_connector **connectors;
  1768. size_t num_connectors;
  1769. };
  1770. /**
  1771. * struct drm_mode_config_funcs - basic driver provided mode setting functions
  1772. *
  1773. * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
  1774. * involve drivers.
  1775. */
  1776. struct drm_mode_config_funcs {
  1777. /**
  1778. * @fb_create:
  1779. *
  1780. * Create a new framebuffer object. The core does basic checks on the
  1781. * requested metadata, but most of that is left to the driver. See
  1782. * struct &drm_mode_fb_cmd2 for details.
  1783. *
  1784. * If the parameters are deemed valid and the backing storage objects in
  1785. * the underlying memory manager all exist, then the driver allocates
  1786. * a new &drm_framebuffer structure, subclassed to contain
  1787. * driver-specific information (like the internal native buffer object
  1788. * references). It also needs to fill out all relevant metadata, which
  1789. * should be done by calling drm_helper_mode_fill_fb_struct().
  1790. *
  1791. * The initialization is finalized by calling drm_framebuffer_init(),
  1792. * which registers the framebuffer and makes it accessible to other
  1793. * threads.
  1794. *
  1795. * RETURNS:
  1796. *
  1797. * A new framebuffer with an initial reference count of 1 or a negative
  1798. * error code encoded with ERR_PTR().
  1799. */
  1800. struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
  1801. struct drm_file *file_priv,
  1802. const struct drm_mode_fb_cmd2 *mode_cmd);
  1803. /**
  1804. * @output_poll_changed:
  1805. *
  1806. * Callback used by helpers to inform the driver of output configuration
  1807. * changes.
  1808. *
  1809. * Drivers implementing fbdev emulation with the helpers can call
  1810. * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
  1811. * helper of output changes.
  1812. *
  1813. * FIXME:
  1814. *
  1815. * Except that there's no vtable for device-level helper callbacks
  1816. * there's no reason this is a core function.
  1817. */
  1818. void (*output_poll_changed)(struct drm_device *dev);
  1819. /**
  1820. * @atomic_check:
  1821. *
  1822. * This is the only hook to validate an atomic modeset update. This
  1823. * function must reject any modeset and state changes which the hardware
  1824. * or driver doesn't support. This includes but is of course not limited
  1825. * to:
  1826. *
  1827. * - Checking that the modes, framebuffers, scaling and placement
  1828. * requirements and so on are within the limits of the hardware.
  1829. *
  1830. * - Checking that any hidden shared resources are not oversubscribed.
  1831. * This can be shared PLLs, shared lanes, overall memory bandwidth,
  1832. * display fifo space (where shared between planes or maybe even
  1833. * CRTCs).
  1834. *
  1835. * - Checking that virtualized resources exported to userspace are not
  1836. * oversubscribed. For various reasons it can make sense to expose
  1837. * more planes, crtcs or encoders than which are physically there. One
  1838. * example is dual-pipe operations (which generally should be hidden
  1839. * from userspace if when lockstepped in hardware, exposed otherwise),
  1840. * where a plane might need 1 hardware plane (if it's just on one
  1841. * pipe), 2 hardware planes (when it spans both pipes) or maybe even
  1842. * shared a hardware plane with a 2nd plane (if there's a compatible
  1843. * plane requested on the area handled by the other pipe).
  1844. *
  1845. * - Check that any transitional state is possible and that if
  1846. * requested, the update can indeed be done in the vblank period
  1847. * without temporarily disabling some functions.
  1848. *
  1849. * - Check any other constraints the driver or hardware might have.
  1850. *
  1851. * - This callback also needs to correctly fill out the &drm_crtc_state
  1852. * in this update to make sure that drm_atomic_crtc_needs_modeset()
  1853. * reflects the nature of the possible update and returns true if and
  1854. * only if the update cannot be applied without tearing within one
  1855. * vblank on that CRTC. The core uses that information to reject
  1856. * updates which require a full modeset (i.e. blanking the screen, or
  1857. * at least pausing updates for a substantial amount of time) if
  1858. * userspace has disallowed that in its request.
  1859. *
  1860. * - The driver also does not need to repeat basic input validation
  1861. * like done for the corresponding legacy entry points. The core does
  1862. * that before calling this hook.
  1863. *
  1864. * See the documentation of @atomic_commit for an exhaustive list of
  1865. * error conditions which don't have to be checked at the
  1866. * ->atomic_check() stage?
  1867. *
  1868. * See the documentation for struct &drm_atomic_state for how exactly
  1869. * an atomic modeset update is described.
  1870. *
  1871. * Drivers using the atomic helpers can implement this hook using
  1872. * drm_atomic_helper_check(), or one of the exported sub-functions of
  1873. * it.
  1874. *
  1875. * RETURNS:
  1876. *
  1877. * 0 on success or one of the below negative error codes:
  1878. *
  1879. * - -EINVAL, if any of the above constraints are violated.
  1880. *
  1881. * - -EDEADLK, when returned from an attempt to acquire an additional
  1882. * &drm_modeset_lock through drm_modeset_lock().
  1883. *
  1884. * - -ENOMEM, if allocating additional state sub-structures failed due
  1885. * to lack of memory.
  1886. *
  1887. * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
  1888. * This can either be due to a pending signal, or because the driver
  1889. * needs to completely bail out to recover from an exceptional
  1890. * situation like a GPU hang. From a userspace point all errors are
  1891. * treated equally.
  1892. */
  1893. int (*atomic_check)(struct drm_device *dev,
  1894. struct drm_atomic_state *state);
  1895. /**
  1896. * @atomic_commit:
  1897. *
  1898. * This is the only hook to commit an atomic modeset update. The core
  1899. * guarantees that @atomic_check has been called successfully before
  1900. * calling this function, and that nothing has been changed in the
  1901. * interim.
  1902. *
  1903. * See the documentation for struct &drm_atomic_state for how exactly
  1904. * an atomic modeset update is described.
  1905. *
  1906. * Drivers using the atomic helpers can implement this hook using
  1907. * drm_atomic_helper_commit(), or one of the exported sub-functions of
  1908. * it.
  1909. *
  1910. * Nonblocking commits (as indicated with the nonblock parameter) must
  1911. * do any preparatory work which might result in an unsuccessful commit
  1912. * in the context of this callback. The only exceptions are hardware
  1913. * errors resulting in -EIO. But even in that case the driver must
  1914. * ensure that the display pipe is at least running, to avoid
  1915. * compositors crashing when pageflips don't work. Anything else,
  1916. * specifically committing the update to the hardware, should be done
  1917. * without blocking the caller. For updates which do not require a
  1918. * modeset this must be guaranteed.
  1919. *
  1920. * The driver must wait for any pending rendering to the new
  1921. * framebuffers to complete before executing the flip. It should also
  1922. * wait for any pending rendering from other drivers if the underlying
  1923. * buffer is a shared dma-buf. Nonblocking commits must not wait for
  1924. * rendering in the context of this callback.
  1925. *
  1926. * An application can request to be notified when the atomic commit has
  1927. * completed. These events are per-CRTC and can be distinguished by the
  1928. * CRTC index supplied in &drm_event to userspace.
  1929. *
  1930. * The drm core will supply a struct &drm_event in the event
  1931. * member of each CRTC's &drm_crtc_state structure. This can be handled by the
  1932. * drm_crtc_send_vblank_event() function, which the driver should call on
  1933. * the provided event upon completion of the atomic commit. Note that if
  1934. * the driver supports vblank signalling and timestamping the vblank
  1935. * counters and timestamps must agree with the ones returned from page
  1936. * flip events. With the current vblank helper infrastructure this can
  1937. * be achieved by holding a vblank reference while the page flip is
  1938. * pending, acquired through drm_crtc_vblank_get() and released with
  1939. * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
  1940. * counter and timestamp tracking though, e.g. if they have accurate
  1941. * timestamp registers in hardware.
  1942. *
  1943. * NOTE:
  1944. *
  1945. * Drivers are not allowed to shut down any display pipe successfully
  1946. * enabled through an atomic commit on their own. Doing so can result in
  1947. * compositors crashing if a page flip is suddenly rejected because the
  1948. * pipe is off.
  1949. *
  1950. * RETURNS:
  1951. *
  1952. * 0 on success or one of the below negative error codes:
  1953. *
  1954. * - -EBUSY, if a nonblocking updated is requested and there is
  1955. * an earlier updated pending. Drivers are allowed to support a queue
  1956. * of outstanding updates, but currently no driver supports that.
  1957. * Note that drivers must wait for preceding updates to complete if a
  1958. * synchronous update is requested, they are not allowed to fail the
  1959. * commit in that case.
  1960. *
  1961. * - -ENOMEM, if the driver failed to allocate memory. Specifically
  1962. * this can happen when trying to pin framebuffers, which must only
  1963. * be done when committing the state.
  1964. *
  1965. * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
  1966. * that the driver has run out of vram, iommu space or similar GPU
  1967. * address space needed for framebuffer.
  1968. *
  1969. * - -EIO, if the hardware completely died.
  1970. *
  1971. * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
  1972. * This can either be due to a pending signal, or because the driver
  1973. * needs to completely bail out to recover from an exceptional
  1974. * situation like a GPU hang. From a userspace point of view all errors are
  1975. * treated equally.
  1976. *
  1977. * This list is exhaustive. Specifically this hook is not allowed to
  1978. * return -EINVAL (any invalid requests should be caught in
  1979. * @atomic_check) or -EDEADLK (this function must not acquire
  1980. * additional modeset locks).
  1981. */
  1982. int (*atomic_commit)(struct drm_device *dev,
  1983. struct drm_atomic_state *state,
  1984. bool nonblock);
  1985. /**
  1986. * @atomic_state_alloc:
  1987. *
  1988. * This optional hook can be used by drivers that want to subclass struct
  1989. * &drm_atomic_state to be able to track their own driver-private global
  1990. * state easily. If this hook is implemented, drivers must also
  1991. * implement @atomic_state_clear and @atomic_state_free.
  1992. *
  1993. * RETURNS:
  1994. *
  1995. * A new &drm_atomic_state on success or NULL on failure.
  1996. */
  1997. struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
  1998. /**
  1999. * @atomic_state_clear:
  2000. *
  2001. * This hook must clear any driver private state duplicated into the
  2002. * passed-in &drm_atomic_state. This hook is called when the caller
  2003. * encountered a &drm_modeset_lock deadlock and needs to drop all
  2004. * already acquired locks as part of the deadlock avoidance dance
  2005. * implemented in drm_modeset_lock_backoff().
  2006. *
  2007. * Any duplicated state must be invalidated since a concurrent atomic
  2008. * update might change it, and the drm atomic interfaces always apply
  2009. * updates as relative changes to the current state.
  2010. *
  2011. * Drivers that implement this must call drm_atomic_state_default_clear()
  2012. * to clear common state.
  2013. */
  2014. void (*atomic_state_clear)(struct drm_atomic_state *state);
  2015. /**
  2016. * @atomic_state_free:
  2017. *
  2018. * This hook needs driver private resources and the &drm_atomic_state
  2019. * itself. Note that the core first calls drm_atomic_state_clear() to
  2020. * avoid code duplicate between the clear and free hooks.
  2021. *
  2022. * Drivers that implement this must call drm_atomic_state_default_free()
  2023. * to release common resources.
  2024. */
  2025. void (*atomic_state_free)(struct drm_atomic_state *state);
  2026. };
  2027. /**
  2028. * struct drm_mode_config - Mode configuration control structure
  2029. * @mutex: mutex protecting KMS related lists and structures
  2030. * @connection_mutex: ww mutex protecting connector state and routing
  2031. * @acquire_ctx: global implicit acquire context used by atomic drivers for
  2032. * legacy IOCTLs
  2033. * @fb_lock: mutex to protect fb state and lists
  2034. * @num_fb: number of fbs available
  2035. * @fb_list: list of framebuffers available
  2036. * @num_connector: number of connectors on this device
  2037. * @connector_list: list of connector objects
  2038. * @num_encoder: number of encoders on this device
  2039. * @encoder_list: list of encoder objects
  2040. * @num_overlay_plane: number of overlay planes on this device
  2041. * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
  2042. * @plane_list: list of plane objects
  2043. * @num_crtc: number of CRTCs on this device
  2044. * @crtc_list: list of CRTC objects
  2045. * @property_list: list of property objects
  2046. * @min_width: minimum pixel width on this device
  2047. * @min_height: minimum pixel height on this device
  2048. * @max_width: maximum pixel width on this device
  2049. * @max_height: maximum pixel height on this device
  2050. * @funcs: core driver provided mode setting functions
  2051. * @fb_base: base address of the framebuffer
  2052. * @poll_enabled: track polling support for this device
  2053. * @poll_running: track polling status for this device
  2054. * @delayed_event: track delayed poll uevent deliver for this device
  2055. * @output_poll_work: delayed work for polling in process context
  2056. * @property_blob_list: list of all the blob property objects
  2057. * @blob_lock: mutex for blob property allocation and management
  2058. * @*_property: core property tracking
  2059. * @degamma_lut_property: LUT used to convert the framebuffer's colors to linear
  2060. * gamma
  2061. * @degamma_lut_size_property: size of the degamma LUT as supported by the
  2062. * driver (read-only)
  2063. * @ctm_property: Matrix used to convert colors after the lookup in the
  2064. * degamma LUT
  2065. * @gamma_lut_property: LUT used to convert the colors, after the CSC matrix, to
  2066. * the gamma space of the connected screen (read-only)
  2067. * @gamma_lut_size_property: size of the gamma LUT as supported by the driver
  2068. * @preferred_depth: preferred RBG pixel depth, used by fb helpers
  2069. * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
  2070. * @async_page_flip: does this device support async flips on the primary plane?
  2071. * @cursor_width: hint to userspace for max cursor width
  2072. * @cursor_height: hint to userspace for max cursor height
  2073. *
  2074. * Core mode resource tracking structure. All CRTC, encoders, and connectors
  2075. * enumerated by the driver are added here, as are global properties. Some
  2076. * global restrictions are also here, e.g. dimension restrictions.
  2077. */
  2078. struct drm_mode_config {
  2079. struct mutex mutex; /* protects configuration (mode lists etc.) */
  2080. struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
  2081. struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
  2082. /**
  2083. * @idr_mutex:
  2084. *
  2085. * Mutex for KMS ID allocation and management. Protects both @crtc_idr
  2086. * and @tile_idr.
  2087. */
  2088. struct mutex idr_mutex;
  2089. /**
  2090. * @crtc_idr:
  2091. *
  2092. * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
  2093. * connector, modes - just makes life easier to have only one.
  2094. */
  2095. struct idr crtc_idr;
  2096. /**
  2097. * @tile_idr:
  2098. *
  2099. * Use this idr for allocating new IDs for tiled sinks like use in some
  2100. * high-res DP MST screens.
  2101. */
  2102. struct idr tile_idr;
  2103. struct mutex fb_lock; /* proctects global and per-file fb lists */
  2104. int num_fb;
  2105. struct list_head fb_list;
  2106. int num_connector;
  2107. struct ida connector_ida;
  2108. struct list_head connector_list;
  2109. int num_encoder;
  2110. struct list_head encoder_list;
  2111. /*
  2112. * Track # of overlay planes separately from # of total planes. By
  2113. * default we only advertise overlay planes to userspace; if userspace
  2114. * sets the "universal plane" capability bit, we'll go ahead and
  2115. * expose all planes.
  2116. */
  2117. int num_overlay_plane;
  2118. int num_total_plane;
  2119. struct list_head plane_list;
  2120. int num_crtc;
  2121. struct list_head crtc_list;
  2122. struct list_head property_list;
  2123. int min_width, min_height;
  2124. int max_width, max_height;
  2125. const struct drm_mode_config_funcs *funcs;
  2126. resource_size_t fb_base;
  2127. /* output poll support */
  2128. bool poll_enabled;
  2129. bool poll_running;
  2130. bool delayed_event;
  2131. struct delayed_work output_poll_work;
  2132. struct mutex blob_lock;
  2133. /* pointers to standard properties */
  2134. struct list_head property_blob_list;
  2135. struct drm_property *edid_property;
  2136. struct drm_property *dpms_property;
  2137. struct drm_property *path_property;
  2138. struct drm_property *tile_property;
  2139. struct drm_property *plane_type_property;
  2140. struct drm_property *rotation_property;
  2141. struct drm_property *prop_src_x;
  2142. struct drm_property *prop_src_y;
  2143. struct drm_property *prop_src_w;
  2144. struct drm_property *prop_src_h;
  2145. struct drm_property *prop_crtc_x;
  2146. struct drm_property *prop_crtc_y;
  2147. struct drm_property *prop_crtc_w;
  2148. struct drm_property *prop_crtc_h;
  2149. struct drm_property *prop_fb_id;
  2150. struct drm_property *prop_crtc_id;
  2151. struct drm_property *prop_active;
  2152. struct drm_property *prop_mode_id;
  2153. /* DVI-I properties */
  2154. struct drm_property *dvi_i_subconnector_property;
  2155. struct drm_property *dvi_i_select_subconnector_property;
  2156. /* TV properties */
  2157. struct drm_property *tv_subconnector_property;
  2158. struct drm_property *tv_select_subconnector_property;
  2159. struct drm_property *tv_mode_property;
  2160. struct drm_property *tv_left_margin_property;
  2161. struct drm_property *tv_right_margin_property;
  2162. struct drm_property *tv_top_margin_property;
  2163. struct drm_property *tv_bottom_margin_property;
  2164. struct drm_property *tv_brightness_property;
  2165. struct drm_property *tv_contrast_property;
  2166. struct drm_property *tv_flicker_reduction_property;
  2167. struct drm_property *tv_overscan_property;
  2168. struct drm_property *tv_saturation_property;
  2169. struct drm_property *tv_hue_property;
  2170. /* Optional properties */
  2171. struct drm_property *scaling_mode_property;
  2172. struct drm_property *aspect_ratio_property;
  2173. struct drm_property *dirty_info_property;
  2174. /* Optional color correction properties */
  2175. struct drm_property *degamma_lut_property;
  2176. struct drm_property *degamma_lut_size_property;
  2177. struct drm_property *ctm_property;
  2178. struct drm_property *gamma_lut_property;
  2179. struct drm_property *gamma_lut_size_property;
  2180. /* properties for virtual machine layout */
  2181. struct drm_property *suggested_x_property;
  2182. struct drm_property *suggested_y_property;
  2183. /* dumb ioctl parameters */
  2184. uint32_t preferred_depth, prefer_shadow;
  2185. /* whether async page flip is supported or not */
  2186. bool async_page_flip;
  2187. /**
  2188. * @allow_fb_modifiers:
  2189. *
  2190. * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
  2191. */
  2192. bool allow_fb_modifiers;
  2193. /* cursor size */
  2194. uint32_t cursor_width, cursor_height;
  2195. };
  2196. /**
  2197. * drm_for_each_plane_mask - iterate over planes specified by bitmask
  2198. * @plane: the loop cursor
  2199. * @dev: the DRM device
  2200. * @plane_mask: bitmask of plane indices
  2201. *
  2202. * Iterate over all planes specified by bitmask.
  2203. */
  2204. #define drm_for_each_plane_mask(plane, dev, plane_mask) \
  2205. list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
  2206. for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
  2207. /**
  2208. * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
  2209. * @encoder: the loop cursor
  2210. * @dev: the DRM device
  2211. * @encoder_mask: bitmask of encoder indices
  2212. *
  2213. * Iterate over all encoders specified by bitmask.
  2214. */
  2215. #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
  2216. list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
  2217. for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
  2218. #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
  2219. #define obj_to_connector(x) container_of(x, struct drm_connector, base)
  2220. #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
  2221. #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
  2222. #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
  2223. #define obj_to_property(x) container_of(x, struct drm_property, base)
  2224. #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
  2225. #define obj_to_plane(x) container_of(x, struct drm_plane, base)
  2226. struct drm_prop_enum_list {
  2227. int type;
  2228. char *name;
  2229. };
  2230. extern __printf(6, 7)
  2231. int drm_crtc_init_with_planes(struct drm_device *dev,
  2232. struct drm_crtc *crtc,
  2233. struct drm_plane *primary,
  2234. struct drm_plane *cursor,
  2235. const struct drm_crtc_funcs *funcs,
  2236. const char *name, ...);
  2237. extern void drm_crtc_cleanup(struct drm_crtc *crtc);
  2238. /**
  2239. * drm_crtc_index - find the index of a registered CRTC
  2240. * @crtc: CRTC to find index for
  2241. *
  2242. * Given a registered CRTC, return the index of that CRTC within a DRM
  2243. * device's list of CRTCs.
  2244. */
  2245. static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
  2246. {
  2247. return crtc->index;
  2248. }
  2249. /**
  2250. * drm_crtc_mask - find the mask of a registered CRTC
  2251. * @crtc: CRTC to find mask for
  2252. *
  2253. * Given a registered CRTC, return the mask bit of that CRTC for an
  2254. * encoder's possible_crtcs field.
  2255. */
  2256. static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
  2257. {
  2258. return 1 << drm_crtc_index(crtc);
  2259. }
  2260. extern void drm_connector_ida_init(void);
  2261. extern void drm_connector_ida_destroy(void);
  2262. extern int drm_connector_init(struct drm_device *dev,
  2263. struct drm_connector *connector,
  2264. const struct drm_connector_funcs *funcs,
  2265. int connector_type);
  2266. int drm_connector_register(struct drm_connector *connector);
  2267. void drm_connector_unregister(struct drm_connector *connector);
  2268. extern void drm_connector_cleanup(struct drm_connector *connector);
  2269. static inline unsigned drm_connector_index(struct drm_connector *connector)
  2270. {
  2271. return connector->connector_id;
  2272. }
  2273. /* helpers to {un}register all connectors from sysfs for device */
  2274. extern int drm_connector_register_all(struct drm_device *dev);
  2275. extern void drm_connector_unregister_all(struct drm_device *dev);
  2276. extern int drm_bridge_add(struct drm_bridge *bridge);
  2277. extern void drm_bridge_remove(struct drm_bridge *bridge);
  2278. extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
  2279. extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
  2280. bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
  2281. const struct drm_display_mode *mode,
  2282. struct drm_display_mode *adjusted_mode);
  2283. void drm_bridge_disable(struct drm_bridge *bridge);
  2284. void drm_bridge_post_disable(struct drm_bridge *bridge);
  2285. void drm_bridge_mode_set(struct drm_bridge *bridge,
  2286. struct drm_display_mode *mode,
  2287. struct drm_display_mode *adjusted_mode);
  2288. void drm_bridge_pre_enable(struct drm_bridge *bridge);
  2289. void drm_bridge_enable(struct drm_bridge *bridge);
  2290. extern __printf(5, 6)
  2291. int drm_encoder_init(struct drm_device *dev,
  2292. struct drm_encoder *encoder,
  2293. const struct drm_encoder_funcs *funcs,
  2294. int encoder_type, const char *name, ...);
  2295. /**
  2296. * drm_encoder_index - find the index of a registered encoder
  2297. * @encoder: encoder to find index for
  2298. *
  2299. * Given a registered encoder, return the index of that encoder within a DRM
  2300. * device's list of encoders.
  2301. */
  2302. static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
  2303. {
  2304. return encoder->index;
  2305. }
  2306. /**
  2307. * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
  2308. * @encoder: encoder to test
  2309. * @crtc: crtc to test
  2310. *
  2311. * Return false if @encoder can't be driven by @crtc, true otherwise.
  2312. */
  2313. static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
  2314. struct drm_crtc *crtc)
  2315. {
  2316. return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
  2317. }
  2318. extern __printf(8, 9)
  2319. int drm_universal_plane_init(struct drm_device *dev,
  2320. struct drm_plane *plane,
  2321. unsigned long possible_crtcs,
  2322. const struct drm_plane_funcs *funcs,
  2323. const uint32_t *formats,
  2324. unsigned int format_count,
  2325. enum drm_plane_type type,
  2326. const char *name, ...);
  2327. extern int drm_plane_init(struct drm_device *dev,
  2328. struct drm_plane *plane,
  2329. unsigned long possible_crtcs,
  2330. const struct drm_plane_funcs *funcs,
  2331. const uint32_t *formats, unsigned int format_count,
  2332. bool is_primary);
  2333. extern void drm_plane_cleanup(struct drm_plane *plane);
  2334. /**
  2335. * drm_plane_index - find the index of a registered plane
  2336. * @plane: plane to find index for
  2337. *
  2338. * Given a registered plane, return the index of that plane within a DRM
  2339. * device's list of planes.
  2340. */
  2341. static inline unsigned int drm_plane_index(struct drm_plane *plane)
  2342. {
  2343. return plane->index;
  2344. }
  2345. extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
  2346. extern void drm_plane_force_disable(struct drm_plane *plane);
  2347. extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
  2348. u32 format);
  2349. extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
  2350. int *hdisplay, int *vdisplay);
  2351. extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
  2352. int x, int y,
  2353. const struct drm_display_mode *mode,
  2354. const struct drm_framebuffer *fb);
  2355. extern void drm_encoder_cleanup(struct drm_encoder *encoder);
  2356. extern const char *drm_get_connector_status_name(enum drm_connector_status status);
  2357. extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
  2358. extern const char *drm_get_dpms_name(int val);
  2359. extern const char *drm_get_dvi_i_subconnector_name(int val);
  2360. extern const char *drm_get_dvi_i_select_name(int val);
  2361. extern const char *drm_get_tv_subconnector_name(int val);
  2362. extern const char *drm_get_tv_select_name(int val);
  2363. extern void drm_fb_release(struct drm_file *file_priv);
  2364. extern void drm_property_destroy_user_blobs(struct drm_device *dev,
  2365. struct drm_file *file_priv);
  2366. extern bool drm_probe_ddc(struct i2c_adapter *adapter);
  2367. extern struct edid *drm_get_edid(struct drm_connector *connector,
  2368. struct i2c_adapter *adapter);
  2369. extern struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
  2370. struct i2c_adapter *adapter);
  2371. extern struct edid *drm_edid_duplicate(const struct edid *edid);
  2372. extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
  2373. extern void drm_mode_config_init(struct drm_device *dev);
  2374. extern void drm_mode_config_reset(struct drm_device *dev);
  2375. extern void drm_mode_config_cleanup(struct drm_device *dev);
  2376. extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
  2377. const char *path);
  2378. int drm_mode_connector_set_tile_property(struct drm_connector *connector);
  2379. extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
  2380. const struct edid *edid);
  2381. extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
  2382. const u32 *formats,
  2383. unsigned int num_formats);
  2384. static inline bool drm_property_type_is(struct drm_property *property,
  2385. uint32_t type)
  2386. {
  2387. /* instanceof for props.. handles extended type vs original types: */
  2388. if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
  2389. return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
  2390. return property->flags & type;
  2391. }
  2392. static inline bool drm_property_type_valid(struct drm_property *property)
  2393. {
  2394. if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
  2395. return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
  2396. return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
  2397. }
  2398. extern int drm_object_property_set_value(struct drm_mode_object *obj,
  2399. struct drm_property *property,
  2400. uint64_t val);
  2401. extern int drm_object_property_get_value(struct drm_mode_object *obj,
  2402. struct drm_property *property,
  2403. uint64_t *value);
  2404. extern int drm_framebuffer_init(struct drm_device *dev,
  2405. struct drm_framebuffer *fb,
  2406. const struct drm_framebuffer_funcs *funcs);
  2407. extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
  2408. uint32_t id);
  2409. extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
  2410. extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
  2411. extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
  2412. extern void drm_object_attach_property(struct drm_mode_object *obj,
  2413. struct drm_property *property,
  2414. uint64_t init_val);
  2415. extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
  2416. const char *name, int num_values);
  2417. extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
  2418. const char *name,
  2419. const struct drm_prop_enum_list *props,
  2420. int num_values);
  2421. struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
  2422. int flags, const char *name,
  2423. const struct drm_prop_enum_list *props,
  2424. int num_props,
  2425. uint64_t supported_bits);
  2426. struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
  2427. const char *name,
  2428. uint64_t min, uint64_t max);
  2429. struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
  2430. int flags, const char *name,
  2431. int64_t min, int64_t max);
  2432. struct drm_property *drm_property_create_object(struct drm_device *dev,
  2433. int flags, const char *name, uint32_t type);
  2434. struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
  2435. const char *name);
  2436. struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
  2437. size_t length,
  2438. const void *data);
  2439. struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
  2440. uint32_t id);
  2441. struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
  2442. void drm_property_unreference_blob(struct drm_property_blob *blob);
  2443. extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
  2444. extern int drm_property_add_enum(struct drm_property *property, int index,
  2445. uint64_t value, const char *name);
  2446. extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
  2447. extern int drm_mode_create_tv_properties(struct drm_device *dev,
  2448. unsigned int num_modes,
  2449. const char * const modes[]);
  2450. extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
  2451. extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
  2452. extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
  2453. extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
  2454. extern bool drm_property_change_valid_get(struct drm_property *property,
  2455. uint64_t value, struct drm_mode_object **ref);
  2456. extern void drm_property_change_valid_put(struct drm_property *property,
  2457. struct drm_mode_object *ref);
  2458. extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
  2459. struct drm_encoder *encoder);
  2460. extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
  2461. int gamma_size);
  2462. extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
  2463. uint32_t id, uint32_t type);
  2464. void drm_mode_object_reference(struct drm_mode_object *obj);
  2465. void drm_mode_object_unreference(struct drm_mode_object *obj);
  2466. /* IOCTLs */
  2467. extern int drm_mode_getresources(struct drm_device *dev,
  2468. void *data, struct drm_file *file_priv);
  2469. extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
  2470. struct drm_file *file_priv);
  2471. extern int drm_mode_getcrtc(struct drm_device *dev,
  2472. void *data, struct drm_file *file_priv);
  2473. extern int drm_mode_getconnector(struct drm_device *dev,
  2474. void *data, struct drm_file *file_priv);
  2475. extern int drm_mode_set_config_internal(struct drm_mode_set *set);
  2476. extern int drm_mode_setcrtc(struct drm_device *dev,
  2477. void *data, struct drm_file *file_priv);
  2478. extern int drm_mode_getplane(struct drm_device *dev,
  2479. void *data, struct drm_file *file_priv);
  2480. extern int drm_mode_setplane(struct drm_device *dev,
  2481. void *data, struct drm_file *file_priv);
  2482. extern int drm_mode_cursor_ioctl(struct drm_device *dev,
  2483. void *data, struct drm_file *file_priv);
  2484. extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
  2485. void *data, struct drm_file *file_priv);
  2486. extern int drm_mode_addfb(struct drm_device *dev,
  2487. void *data, struct drm_file *file_priv);
  2488. extern int drm_mode_addfb2(struct drm_device *dev,
  2489. void *data, struct drm_file *file_priv);
  2490. extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
  2491. extern int drm_mode_rmfb(struct drm_device *dev,
  2492. void *data, struct drm_file *file_priv);
  2493. extern int drm_mode_getfb(struct drm_device *dev,
  2494. void *data, struct drm_file *file_priv);
  2495. extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
  2496. void *data, struct drm_file *file_priv);
  2497. extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
  2498. void *data, struct drm_file *file_priv);
  2499. extern int drm_mode_getblob_ioctl(struct drm_device *dev,
  2500. void *data, struct drm_file *file_priv);
  2501. extern int drm_mode_createblob_ioctl(struct drm_device *dev,
  2502. void *data, struct drm_file *file_priv);
  2503. extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
  2504. void *data, struct drm_file *file_priv);
  2505. extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
  2506. void *data, struct drm_file *file_priv);
  2507. extern int drm_mode_getencoder(struct drm_device *dev,
  2508. void *data, struct drm_file *file_priv);
  2509. extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
  2510. void *data, struct drm_file *file_priv);
  2511. extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
  2512. void *data, struct drm_file *file_priv);
  2513. extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
  2514. extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
  2515. extern bool drm_detect_hdmi_monitor(struct edid *edid);
  2516. extern bool drm_detect_monitor_audio(struct edid *edid);
  2517. extern bool drm_rgb_quant_range_selectable(struct edid *edid);
  2518. extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
  2519. void *data, struct drm_file *file_priv);
  2520. extern int drm_add_modes_noedid(struct drm_connector *connector,
  2521. int hdisplay, int vdisplay);
  2522. extern void drm_set_preferred_mode(struct drm_connector *connector,
  2523. int hpref, int vpref);
  2524. extern int drm_edid_header_is_valid(const u8 *raw_edid);
  2525. extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
  2526. bool *edid_corrupt);
  2527. extern bool drm_edid_is_valid(struct edid *edid);
  2528. extern void drm_edid_get_monitor_name(struct edid *edid, char *name,
  2529. int buflen);
  2530. extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
  2531. char topology[8]);
  2532. extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
  2533. char topology[8]);
  2534. extern void drm_mode_put_tile_group(struct drm_device *dev,
  2535. struct drm_tile_group *tg);
  2536. struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
  2537. int hsize, int vsize, int fresh,
  2538. bool rb);
  2539. extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
  2540. void *data, struct drm_file *file_priv);
  2541. extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
  2542. void *data, struct drm_file *file_priv);
  2543. extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
  2544. void *data, struct drm_file *file_priv);
  2545. extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
  2546. struct drm_file *file_priv);
  2547. extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
  2548. struct drm_file *file_priv);
  2549. extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
  2550. struct drm_property *property,
  2551. uint64_t value);
  2552. extern int drm_mode_atomic_ioctl(struct drm_device *dev,
  2553. void *data, struct drm_file *file_priv);
  2554. extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
  2555. unsigned int supported_rotations);
  2556. extern unsigned int drm_rotation_simplify(unsigned int rotation,
  2557. unsigned int supported_rotations);
  2558. extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
  2559. uint degamma_lut_size,
  2560. bool has_ctm,
  2561. uint gamma_lut_size);
  2562. /* Helpers */
  2563. static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
  2564. uint32_t id)
  2565. {
  2566. struct drm_mode_object *mo;
  2567. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
  2568. return mo ? obj_to_plane(mo) : NULL;
  2569. }
  2570. static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
  2571. uint32_t id)
  2572. {
  2573. struct drm_mode_object *mo;
  2574. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
  2575. return mo ? obj_to_crtc(mo) : NULL;
  2576. }
  2577. static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
  2578. uint32_t id)
  2579. {
  2580. struct drm_mode_object *mo;
  2581. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
  2582. return mo ? obj_to_encoder(mo) : NULL;
  2583. }
  2584. /**
  2585. * drm_connector_lookup - lookup connector object
  2586. * @dev: DRM device
  2587. * @id: connector object id
  2588. *
  2589. * This function looks up the connector object specified by id
  2590. * add takes a reference to it.
  2591. */
  2592. static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
  2593. uint32_t id)
  2594. {
  2595. struct drm_mode_object *mo;
  2596. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
  2597. return mo ? obj_to_connector(mo) : NULL;
  2598. }
  2599. static inline struct drm_property *drm_property_find(struct drm_device *dev,
  2600. uint32_t id)
  2601. {
  2602. struct drm_mode_object *mo;
  2603. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
  2604. return mo ? obj_to_property(mo) : NULL;
  2605. }
  2606. /*
  2607. * Extract a degamma/gamma LUT value provided by user and round it to the
  2608. * precision supported by the hardware.
  2609. */
  2610. static inline uint32_t drm_color_lut_extract(uint32_t user_input,
  2611. uint32_t bit_precision)
  2612. {
  2613. uint32_t val = user_input;
  2614. uint32_t max = 0xffff >> (16 - bit_precision);
  2615. /* Round only if we're not using full precision. */
  2616. if (bit_precision < 16) {
  2617. val += 1UL << (16 - bit_precision - 1);
  2618. val >>= 16 - bit_precision;
  2619. }
  2620. return clamp_val(val, 0, max);
  2621. }
  2622. /**
  2623. * drm_framebuffer_reference - incr the fb refcnt
  2624. * @fb: framebuffer
  2625. *
  2626. * This functions increments the fb's refcount.
  2627. */
  2628. static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
  2629. {
  2630. drm_mode_object_reference(&fb->base);
  2631. }
  2632. /**
  2633. * drm_framebuffer_unreference - unref a framebuffer
  2634. * @fb: framebuffer to unref
  2635. *
  2636. * This functions decrements the fb's refcount and frees it if it drops to zero.
  2637. */
  2638. static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
  2639. {
  2640. drm_mode_object_unreference(&fb->base);
  2641. }
  2642. /**
  2643. * drm_framebuffer_read_refcount - read the framebuffer reference count.
  2644. * @fb: framebuffer
  2645. *
  2646. * This functions returns the framebuffer's reference count.
  2647. */
  2648. static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
  2649. {
  2650. return atomic_read(&fb->base.refcount.refcount);
  2651. }
  2652. /**
  2653. * drm_connector_reference - incr the connector refcnt
  2654. * @connector: connector
  2655. *
  2656. * This function increments the connector's refcount.
  2657. */
  2658. static inline void drm_connector_reference(struct drm_connector *connector)
  2659. {
  2660. drm_mode_object_reference(&connector->base);
  2661. }
  2662. /**
  2663. * drm_connector_unreference - unref a connector
  2664. * @connector: connector to unref
  2665. *
  2666. * This function decrements the connector's refcount and frees it if it drops to zero.
  2667. */
  2668. static inline void drm_connector_unreference(struct drm_connector *connector)
  2669. {
  2670. drm_mode_object_unreference(&connector->base);
  2671. }
  2672. /* Plane list iterator for legacy (overlay only) planes. */
  2673. #define drm_for_each_legacy_plane(plane, dev) \
  2674. list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
  2675. for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
  2676. #define drm_for_each_plane(plane, dev) \
  2677. list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
  2678. #define drm_for_each_crtc(crtc, dev) \
  2679. list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
  2680. static inline void
  2681. assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
  2682. {
  2683. /*
  2684. * The connector hotadd/remove code currently grabs both locks when
  2685. * updating lists. Hence readers need only hold either of them to be
  2686. * safe and the check amounts to
  2687. *
  2688. * WARN_ON(not_holding(A) && not_holding(B)).
  2689. */
  2690. WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
  2691. !drm_modeset_is_locked(&mode_config->connection_mutex));
  2692. }
  2693. #define drm_for_each_connector(connector, dev) \
  2694. for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
  2695. connector = list_first_entry(&(dev)->mode_config.connector_list, \
  2696. struct drm_connector, head); \
  2697. &connector->head != (&(dev)->mode_config.connector_list); \
  2698. connector = list_next_entry(connector, head))
  2699. #define drm_for_each_encoder(encoder, dev) \
  2700. list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
  2701. #define drm_for_each_fb(fb, dev) \
  2702. for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
  2703. fb = list_first_entry(&(dev)->mode_config.fb_list, \
  2704. struct drm_framebuffer, head); \
  2705. &fb->head != (&(dev)->mode_config.fb_list); \
  2706. fb = list_next_entry(fb, head))
  2707. #endif /* __DRM_CRTC_H__ */