drm_crtc.h 92 KB

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