drm_crtc.h 95 KB

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