drm_crtc.h 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597
  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. /* rotation property bits */
  82. #define DRM_ROTATE_0 0
  83. #define DRM_ROTATE_90 1
  84. #define DRM_ROTATE_180 2
  85. #define DRM_ROTATE_270 3
  86. #define DRM_REFLECT_X 4
  87. #define DRM_REFLECT_Y 5
  88. enum drm_connector_force {
  89. DRM_FORCE_UNSPECIFIED,
  90. DRM_FORCE_OFF,
  91. DRM_FORCE_ON, /* force on analog part normally */
  92. DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
  93. };
  94. #include <drm/drm_modes.h>
  95. enum drm_connector_status {
  96. connector_status_connected = 1,
  97. connector_status_disconnected = 2,
  98. connector_status_unknown = 3,
  99. };
  100. enum subpixel_order {
  101. SubPixelUnknown = 0,
  102. SubPixelHorizontalRGB,
  103. SubPixelHorizontalBGR,
  104. SubPixelVerticalRGB,
  105. SubPixelVerticalBGR,
  106. SubPixelNone,
  107. };
  108. #define DRM_COLOR_FORMAT_RGB444 (1<<0)
  109. #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
  110. #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
  111. /*
  112. * Describes a given display (e.g. CRT or flat panel) and its limitations.
  113. */
  114. struct drm_display_info {
  115. char name[DRM_DISPLAY_INFO_LEN];
  116. /* Physical size */
  117. unsigned int width_mm;
  118. unsigned int height_mm;
  119. /* Clock limits FIXME: storage format */
  120. unsigned int min_vfreq, max_vfreq;
  121. unsigned int min_hfreq, max_hfreq;
  122. unsigned int pixel_clock;
  123. unsigned int bpc;
  124. enum subpixel_order subpixel_order;
  125. u32 color_formats;
  126. const u32 *bus_formats;
  127. unsigned int num_bus_formats;
  128. /* Mask of supported hdmi deep color modes */
  129. u8 edid_hdmi_dc_modes;
  130. u8 cea_rev;
  131. };
  132. /* data corresponds to displayid vend/prod/serial */
  133. struct drm_tile_group {
  134. struct kref refcount;
  135. struct drm_device *dev;
  136. int id;
  137. u8 group_data[8];
  138. };
  139. struct drm_framebuffer_funcs {
  140. /* note: use drm_framebuffer_remove() */
  141. void (*destroy)(struct drm_framebuffer *framebuffer);
  142. int (*create_handle)(struct drm_framebuffer *fb,
  143. struct drm_file *file_priv,
  144. unsigned int *handle);
  145. /*
  146. * Optional callback for the dirty fb ioctl.
  147. *
  148. * Userspace can notify the driver via this callback
  149. * that a area of the framebuffer has changed and should
  150. * be flushed to the display hardware.
  151. *
  152. * See documentation in drm_mode.h for the struct
  153. * drm_mode_fb_dirty_cmd for more information as all
  154. * the semantics and arguments have a one to one mapping
  155. * on this function.
  156. */
  157. int (*dirty)(struct drm_framebuffer *framebuffer,
  158. struct drm_file *file_priv, unsigned flags,
  159. unsigned color, struct drm_clip_rect *clips,
  160. unsigned num_clips);
  161. };
  162. struct drm_framebuffer {
  163. struct drm_device *dev;
  164. /*
  165. * Note that the fb is refcounted for the benefit of driver internals,
  166. * for example some hw, disabling a CRTC/plane is asynchronous, and
  167. * scanout does not actually complete until the next vblank. So some
  168. * cleanup (like releasing the reference(s) on the backing GEM bo(s))
  169. * should be deferred. In cases like this, the driver would like to
  170. * hold a ref to the fb even though it has already been removed from
  171. * userspace perspective.
  172. */
  173. struct kref refcount;
  174. /*
  175. * Place on the dev->mode_config.fb_list, access protected by
  176. * dev->mode_config.fb_lock.
  177. */
  178. struct list_head head;
  179. struct drm_mode_object base;
  180. const struct drm_framebuffer_funcs *funcs;
  181. unsigned int pitches[4];
  182. unsigned int offsets[4];
  183. uint64_t modifier[4];
  184. unsigned int width;
  185. unsigned int height;
  186. /* depth can be 15 or 16 */
  187. unsigned int depth;
  188. int bits_per_pixel;
  189. int flags;
  190. uint32_t pixel_format; /* fourcc format */
  191. struct list_head filp_head;
  192. /* if you are using the helper */
  193. void *helper_private;
  194. };
  195. struct drm_property_blob {
  196. struct drm_mode_object base;
  197. struct drm_device *dev;
  198. struct kref refcount;
  199. struct list_head head_global;
  200. struct list_head head_file;
  201. size_t length;
  202. unsigned char data[];
  203. };
  204. struct drm_property_enum {
  205. uint64_t value;
  206. struct list_head head;
  207. char name[DRM_PROP_NAME_LEN];
  208. };
  209. struct drm_property {
  210. struct list_head head;
  211. struct drm_mode_object base;
  212. uint32_t flags;
  213. char name[DRM_PROP_NAME_LEN];
  214. uint32_t num_values;
  215. uint64_t *values;
  216. struct drm_device *dev;
  217. struct list_head enum_list;
  218. };
  219. struct drm_crtc;
  220. struct drm_connector;
  221. struct drm_encoder;
  222. struct drm_pending_vblank_event;
  223. struct drm_plane;
  224. struct drm_bridge;
  225. struct drm_atomic_state;
  226. /**
  227. * struct drm_crtc_state - mutable CRTC state
  228. * @crtc: backpointer to the CRTC
  229. * @enable: whether the CRTC should be enabled, gates all other state
  230. * @active: whether the CRTC is actively displaying (used for DPMS)
  231. * @planes_changed: planes on this crtc are updated
  232. * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
  233. * @active_changed: crtc_state->active has been toggled.
  234. * @connectors_changed: connectors to this crtc have been updated
  235. * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
  236. * @last_vblank_count: for helpers and drivers to capture the vblank of the
  237. * update to ensure framebuffer cleanup isn't done too early
  238. * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
  239. * @mode: current mode timings
  240. * @event: optional pointer to a DRM event to signal upon completion of the
  241. * state update
  242. * @state: backpointer to global drm_atomic_state
  243. *
  244. * Note that the distinction between @enable and @active is rather subtile:
  245. * Flipping @active while @enable is set without changing anything else may
  246. * never return in a failure from the ->atomic_check callback. Userspace assumes
  247. * that a DPMS On will always succeed. In other words: @enable controls resource
  248. * assignment, @active controls the actual hardware state.
  249. */
  250. struct drm_crtc_state {
  251. struct drm_crtc *crtc;
  252. bool enable;
  253. bool active;
  254. /* computed state bits used by helpers and drivers */
  255. bool planes_changed : 1;
  256. bool mode_changed : 1;
  257. bool active_changed : 1;
  258. bool connectors_changed : 1;
  259. /* attached planes bitmask:
  260. * WARNING: transitional helpers do not maintain plane_mask so
  261. * drivers not converted over to atomic helpers should not rely
  262. * on plane_mask being accurate!
  263. */
  264. u32 plane_mask;
  265. /* last_vblank_count: for vblank waits before cleanup */
  266. u32 last_vblank_count;
  267. /* adjusted_mode: for use by helpers and drivers */
  268. struct drm_display_mode adjusted_mode;
  269. struct drm_display_mode mode;
  270. /* blob property to expose current mode to atomic userspace */
  271. struct drm_property_blob *mode_blob;
  272. struct drm_pending_vblank_event *event;
  273. struct drm_atomic_state *state;
  274. };
  275. /**
  276. * struct drm_crtc_funcs - control CRTCs for a given device
  277. * @save: save CRTC state
  278. * @restore: restore CRTC state
  279. * @reset: reset CRTC after state has been invalidated (e.g. resume)
  280. * @cursor_set: setup the cursor
  281. * @cursor_set2: setup the cursor with hotspot, superseeds @cursor_set if set
  282. * @cursor_move: move the cursor
  283. * @gamma_set: specify color ramp for CRTC
  284. * @destroy: deinit and free object
  285. * @set_property: called when a property is changed
  286. * @set_config: apply a new CRTC configuration
  287. * @page_flip: initiate a page flip
  288. * @atomic_duplicate_state: duplicate the atomic state for this CRTC
  289. * @atomic_destroy_state: destroy an atomic state for this CRTC
  290. * @atomic_set_property: set a property on an atomic state for this CRTC
  291. * (do not call directly, use drm_atomic_crtc_set_property())
  292. * @atomic_get_property: get a property on an atomic state for this CRTC
  293. * (do not call directly, use drm_atomic_crtc_get_property())
  294. *
  295. * The drm_crtc_funcs structure is the central CRTC management structure
  296. * in the DRM. Each CRTC controls one or more connectors (note that the name
  297. * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
  298. * connectors, not just CRTs).
  299. *
  300. * Each driver is responsible for filling out this structure at startup time,
  301. * in addition to providing other modesetting features, like i2c and DDC
  302. * bus accessors.
  303. */
  304. struct drm_crtc_funcs {
  305. /* Save CRTC state */
  306. void (*save)(struct drm_crtc *crtc); /* suspend? */
  307. /* Restore CRTC state */
  308. void (*restore)(struct drm_crtc *crtc); /* resume? */
  309. /* Reset CRTC state */
  310. void (*reset)(struct drm_crtc *crtc);
  311. /* cursor controls */
  312. int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
  313. uint32_t handle, uint32_t width, uint32_t height);
  314. int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
  315. uint32_t handle, uint32_t width, uint32_t height,
  316. int32_t hot_x, int32_t hot_y);
  317. int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
  318. /* Set gamma on the CRTC */
  319. void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  320. uint32_t start, uint32_t size);
  321. /* Object destroy routine */
  322. void (*destroy)(struct drm_crtc *crtc);
  323. int (*set_config)(struct drm_mode_set *set);
  324. /*
  325. * Flip to the given framebuffer. This implements the page
  326. * flip ioctl described in drm_mode.h, specifically, the
  327. * implementation must return immediately and block all
  328. * rendering to the current fb until the flip has completed.
  329. * If userspace set the event flag in the ioctl, the event
  330. * argument will point to an event to send back when the flip
  331. * completes, otherwise it will be NULL.
  332. */
  333. int (*page_flip)(struct drm_crtc *crtc,
  334. struct drm_framebuffer *fb,
  335. struct drm_pending_vblank_event *event,
  336. uint32_t flags);
  337. int (*set_property)(struct drm_crtc *crtc,
  338. struct drm_property *property, uint64_t val);
  339. /* atomic update handling */
  340. struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
  341. void (*atomic_destroy_state)(struct drm_crtc *crtc,
  342. struct drm_crtc_state *state);
  343. int (*atomic_set_property)(struct drm_crtc *crtc,
  344. struct drm_crtc_state *state,
  345. struct drm_property *property,
  346. uint64_t val);
  347. int (*atomic_get_property)(struct drm_crtc *crtc,
  348. const struct drm_crtc_state *state,
  349. struct drm_property *property,
  350. uint64_t *val);
  351. };
  352. /**
  353. * struct drm_crtc - central CRTC control structure
  354. * @dev: parent DRM device
  355. * @port: OF node used by drm_of_find_possible_crtcs()
  356. * @head: list management
  357. * @mutex: per-CRTC locking
  358. * @base: base KMS object for ID tracking etc.
  359. * @primary: primary plane for this CRTC
  360. * @cursor: cursor plane for this CRTC
  361. * @cursor_x: current x position of the cursor, used for universal cursor planes
  362. * @cursor_y: current y position of the cursor, used for universal cursor planes
  363. * @enabled: is this CRTC enabled?
  364. * @mode: current mode timings
  365. * @hwmode: mode timings as programmed to hw regs
  366. * @invert_dimensions: for purposes of error checking crtc vs fb sizes,
  367. * invert the width/height of the crtc. This is used if the driver
  368. * is performing 90 or 270 degree rotated scanout
  369. * @x: x position on screen
  370. * @y: y position on screen
  371. * @funcs: CRTC control functions
  372. * @gamma_size: size of gamma ramp
  373. * @gamma_store: gamma ramp values
  374. * @framedur_ns: precise frame timing
  375. * @linedur_ns: precise line timing
  376. * @pixeldur_ns: precise pixel timing
  377. * @helper_private: mid-layer private data
  378. * @properties: property tracking for this CRTC
  379. * @state: current atomic state for this CRTC
  380. * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
  381. * legacy ioctls
  382. *
  383. * Each CRTC may have one or more connectors associated with it. This structure
  384. * allows the CRTC to be controlled.
  385. */
  386. struct drm_crtc {
  387. struct drm_device *dev;
  388. struct device_node *port;
  389. struct list_head head;
  390. /*
  391. * crtc mutex
  392. *
  393. * This provides a read lock for the overall crtc state (mode, dpms
  394. * state, ...) and a write lock for everything which can be update
  395. * without a full modeset (fb, cursor data, ...)
  396. */
  397. struct drm_modeset_lock mutex;
  398. struct drm_mode_object base;
  399. /* primary and cursor planes for CRTC */
  400. struct drm_plane *primary;
  401. struct drm_plane *cursor;
  402. /* position of cursor plane on crtc */
  403. int cursor_x;
  404. int cursor_y;
  405. bool enabled;
  406. /* Requested mode from modesetting. */
  407. struct drm_display_mode mode;
  408. /* Programmed mode in hw, after adjustments for encoders,
  409. * crtc, panel scaling etc. Needed for timestamping etc.
  410. */
  411. struct drm_display_mode hwmode;
  412. bool invert_dimensions;
  413. int x, y;
  414. const struct drm_crtc_funcs *funcs;
  415. /* CRTC gamma size for reporting to userspace */
  416. uint32_t gamma_size;
  417. uint16_t *gamma_store;
  418. /* Constants needed for precise vblank and swap timestamping. */
  419. int framedur_ns, linedur_ns, pixeldur_ns;
  420. /* if you are using the helper */
  421. const void *helper_private;
  422. struct drm_object_properties properties;
  423. struct drm_crtc_state *state;
  424. /*
  425. * For legacy crtc ioctls so that atomic drivers can get at the locking
  426. * acquire context.
  427. */
  428. struct drm_modeset_acquire_ctx *acquire_ctx;
  429. };
  430. /**
  431. * struct drm_connector_state - mutable connector state
  432. * @connector: backpointer to the connector
  433. * @crtc: CRTC to connect connector to, NULL if disabled
  434. * @best_encoder: can be used by helpers and drivers to select the encoder
  435. * @state: backpointer to global drm_atomic_state
  436. */
  437. struct drm_connector_state {
  438. struct drm_connector *connector;
  439. struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
  440. struct drm_encoder *best_encoder;
  441. struct drm_atomic_state *state;
  442. };
  443. /**
  444. * struct drm_connector_funcs - control connectors on a given device
  445. * @dpms: set power state
  446. * @save: save connector state
  447. * @restore: restore connector state
  448. * @reset: reset connector after state has been invalidated (e.g. resume)
  449. * @detect: is this connector active?
  450. * @fill_modes: fill mode list for this connector
  451. * @set_property: property for this connector may need an update
  452. * @destroy: make object go away
  453. * @force: notify the driver that the connector is forced on
  454. * @atomic_duplicate_state: duplicate the atomic state for this connector
  455. * @atomic_destroy_state: destroy an atomic state for this connector
  456. * @atomic_set_property: set a property on an atomic state for this connector
  457. * (do not call directly, use drm_atomic_connector_set_property())
  458. * @atomic_get_property: get a property on an atomic state for this connector
  459. * (do not call directly, use drm_atomic_connector_get_property())
  460. *
  461. * Each CRTC may have one or more connectors attached to it. The functions
  462. * below allow the core DRM code to control connectors, enumerate available modes,
  463. * etc.
  464. */
  465. struct drm_connector_funcs {
  466. int (*dpms)(struct drm_connector *connector, int mode);
  467. void (*save)(struct drm_connector *connector);
  468. void (*restore)(struct drm_connector *connector);
  469. void (*reset)(struct drm_connector *connector);
  470. /* Check to see if anything is attached to the connector.
  471. * @force is set to false whilst polling, true when checking the
  472. * connector due to user request. @force can be used by the driver
  473. * to avoid expensive, destructive operations during automated
  474. * probing.
  475. */
  476. enum drm_connector_status (*detect)(struct drm_connector *connector,
  477. bool force);
  478. int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
  479. int (*set_property)(struct drm_connector *connector, struct drm_property *property,
  480. uint64_t val);
  481. void (*destroy)(struct drm_connector *connector);
  482. void (*force)(struct drm_connector *connector);
  483. /* atomic update handling */
  484. struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
  485. void (*atomic_destroy_state)(struct drm_connector *connector,
  486. struct drm_connector_state *state);
  487. int (*atomic_set_property)(struct drm_connector *connector,
  488. struct drm_connector_state *state,
  489. struct drm_property *property,
  490. uint64_t val);
  491. int (*atomic_get_property)(struct drm_connector *connector,
  492. const struct drm_connector_state *state,
  493. struct drm_property *property,
  494. uint64_t *val);
  495. };
  496. /**
  497. * struct drm_encoder_funcs - encoder controls
  498. * @reset: reset state (e.g. at init or resume time)
  499. * @destroy: cleanup and free associated data
  500. *
  501. * Encoders sit between CRTCs and connectors.
  502. */
  503. struct drm_encoder_funcs {
  504. void (*reset)(struct drm_encoder *encoder);
  505. void (*destroy)(struct drm_encoder *encoder);
  506. };
  507. #define DRM_CONNECTOR_MAX_ENCODER 3
  508. /**
  509. * struct drm_encoder - central DRM encoder structure
  510. * @dev: parent DRM device
  511. * @head: list management
  512. * @base: base KMS object
  513. * @name: encoder name
  514. * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
  515. * @possible_crtcs: bitmask of potential CRTC bindings
  516. * @possible_clones: bitmask of potential sibling encoders for cloning
  517. * @crtc: currently bound CRTC
  518. * @bridge: bridge associated to the encoder
  519. * @funcs: control functions
  520. * @helper_private: mid-layer private data
  521. *
  522. * CRTCs drive pixels to encoders, which convert them into signals
  523. * appropriate for a given connector or set of connectors.
  524. */
  525. struct drm_encoder {
  526. struct drm_device *dev;
  527. struct list_head head;
  528. struct drm_mode_object base;
  529. char *name;
  530. int encoder_type;
  531. uint32_t possible_crtcs;
  532. uint32_t possible_clones;
  533. struct drm_crtc *crtc;
  534. struct drm_bridge *bridge;
  535. const struct drm_encoder_funcs *funcs;
  536. const void *helper_private;
  537. };
  538. /* should we poll this connector for connects and disconnects */
  539. /* hot plug detectable */
  540. #define DRM_CONNECTOR_POLL_HPD (1 << 0)
  541. /* poll for connections */
  542. #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
  543. /* can cleanly poll for disconnections without flickering the screen */
  544. /* DACs should rarely do this without a lot of testing */
  545. #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
  546. #define MAX_ELD_BYTES 128
  547. /**
  548. * struct drm_connector - central DRM connector control structure
  549. * @dev: parent DRM device
  550. * @kdev: kernel device for sysfs attributes
  551. * @attr: sysfs attributes
  552. * @head: list management
  553. * @base: base KMS object
  554. * @name: connector name
  555. * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
  556. * @connector_type_id: index into connector type enum
  557. * @interlace_allowed: can this connector handle interlaced modes?
  558. * @doublescan_allowed: can this connector handle doublescan?
  559. * @stereo_allowed: can this connector handle stereo modes?
  560. * @modes: modes available on this connector (from fill_modes() + user)
  561. * @status: one of the drm_connector_status enums (connected, not, or unknown)
  562. * @probed_modes: list of modes derived directly from the display
  563. * @display_info: information about attached display (e.g. from EDID)
  564. * @funcs: connector control functions
  565. * @edid_blob_ptr: DRM property containing EDID if present
  566. * @properties: property tracking for this connector
  567. * @path_blob_ptr: DRM blob property data for the DP MST path property
  568. * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
  569. * @dpms: current dpms state
  570. * @helper_private: mid-layer private data
  571. * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
  572. * @force: a %DRM_FORCE_<foo> state for forced mode sets
  573. * @override_edid: has the EDID been overwritten through debugfs for testing?
  574. * @encoder_ids: valid encoders for this connector
  575. * @encoder: encoder driving this connector, if any
  576. * @eld: EDID-like data, if present
  577. * @dvi_dual: dual link DVI, if found
  578. * @max_tmds_clock: max clock rate, if found
  579. * @latency_present: AV delay info from ELD, if found
  580. * @video_latency: video latency info from ELD, if found
  581. * @audio_latency: audio latency info from ELD, if found
  582. * @null_edid_counter: track sinks that give us all zeros for the EDID
  583. * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
  584. * @edid_corrupt: indicates whether the last read EDID was corrupt
  585. * @debugfs_entry: debugfs directory for this connector
  586. * @state: current atomic state for this connector
  587. * @has_tile: is this connector connected to a tiled monitor
  588. * @tile_group: tile group for the connected monitor
  589. * @tile_is_single_monitor: whether the tile is one monitor housing
  590. * @num_h_tile: number of horizontal tiles in the tile group
  591. * @num_v_tile: number of vertical tiles in the tile group
  592. * @tile_h_loc: horizontal location of this tile
  593. * @tile_v_loc: vertical location of this tile
  594. * @tile_h_size: horizontal size of this tile.
  595. * @tile_v_size: vertical size of this tile.
  596. *
  597. * Each connector may be connected to one or more CRTCs, or may be clonable by
  598. * another connector if they can share a CRTC. Each connector also has a specific
  599. * position in the broader display (referred to as a 'screen' though it could
  600. * span multiple monitors).
  601. */
  602. struct drm_connector {
  603. struct drm_device *dev;
  604. struct device *kdev;
  605. struct device_attribute *attr;
  606. struct list_head head;
  607. struct drm_mode_object base;
  608. char *name;
  609. int connector_type;
  610. int connector_type_id;
  611. bool interlace_allowed;
  612. bool doublescan_allowed;
  613. bool stereo_allowed;
  614. struct list_head modes; /* list of modes on this connector */
  615. enum drm_connector_status status;
  616. /* these are modes added by probing with DDC or the BIOS */
  617. struct list_head probed_modes;
  618. struct drm_display_info display_info;
  619. const struct drm_connector_funcs *funcs;
  620. struct drm_property_blob *edid_blob_ptr;
  621. struct drm_object_properties properties;
  622. struct drm_property_blob *path_blob_ptr;
  623. struct drm_property_blob *tile_blob_ptr;
  624. uint8_t polled; /* DRM_CONNECTOR_POLL_* */
  625. /* requested DPMS state */
  626. int dpms;
  627. const void *helper_private;
  628. /* forced on connector */
  629. struct drm_cmdline_mode cmdline_mode;
  630. enum drm_connector_force force;
  631. bool override_edid;
  632. uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
  633. struct drm_encoder *encoder; /* currently active encoder */
  634. /* EDID bits */
  635. uint8_t eld[MAX_ELD_BYTES];
  636. bool dvi_dual;
  637. int max_tmds_clock; /* in MHz */
  638. bool latency_present[2];
  639. int video_latency[2]; /* [0]: progressive, [1]: interlaced */
  640. int audio_latency[2];
  641. int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
  642. unsigned bad_edid_counter;
  643. /* Flag for raw EDID header corruption - used in Displayport
  644. * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
  645. */
  646. bool edid_corrupt;
  647. struct dentry *debugfs_entry;
  648. struct drm_connector_state *state;
  649. /* DisplayID bits */
  650. bool has_tile;
  651. struct drm_tile_group *tile_group;
  652. bool tile_is_single_monitor;
  653. uint8_t num_h_tile, num_v_tile;
  654. uint8_t tile_h_loc, tile_v_loc;
  655. uint16_t tile_h_size, tile_v_size;
  656. };
  657. /**
  658. * struct drm_plane_state - mutable plane state
  659. * @plane: backpointer to the plane
  660. * @crtc: currently bound CRTC, NULL if disabled
  661. * @fb: currently bound framebuffer
  662. * @fence: optional fence to wait for before scanning out @fb
  663. * @crtc_x: left position of visible portion of plane on crtc
  664. * @crtc_y: upper position of visible portion of plane on crtc
  665. * @crtc_w: width of visible portion of plane on crtc
  666. * @crtc_h: height of visible portion of plane on crtc
  667. * @src_x: left position of visible portion of plane within
  668. * plane (in 16.16)
  669. * @src_y: upper position of visible portion of plane within
  670. * plane (in 16.16)
  671. * @src_w: width of visible portion of plane (in 16.16)
  672. * @src_h: height of visible portion of plane (in 16.16)
  673. * @state: backpointer to global drm_atomic_state
  674. */
  675. struct drm_plane_state {
  676. struct drm_plane *plane;
  677. struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
  678. struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
  679. struct fence *fence;
  680. /* Signed dest location allows it to be partially off screen */
  681. int32_t crtc_x, crtc_y;
  682. uint32_t crtc_w, crtc_h;
  683. /* Source values are 16.16 fixed point */
  684. uint32_t src_x, src_y;
  685. uint32_t src_h, src_w;
  686. /* Plane rotation */
  687. unsigned int rotation;
  688. struct drm_atomic_state *state;
  689. };
  690. /**
  691. * struct drm_plane_funcs - driver plane control functions
  692. * @update_plane: update the plane configuration
  693. * @disable_plane: shut down the plane
  694. * @destroy: clean up plane resources
  695. * @reset: reset plane after state has been invalidated (e.g. resume)
  696. * @set_property: called when a property is changed
  697. * @atomic_duplicate_state: duplicate the atomic state for this plane
  698. * @atomic_destroy_state: destroy an atomic state for this plane
  699. * @atomic_set_property: set a property on an atomic state for this plane
  700. * (do not call directly, use drm_atomic_plane_set_property())
  701. * @atomic_get_property: get a property on an atomic state for this plane
  702. * (do not call directly, use drm_atomic_plane_get_property())
  703. */
  704. struct drm_plane_funcs {
  705. int (*update_plane)(struct drm_plane *plane,
  706. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  707. int crtc_x, int crtc_y,
  708. unsigned int crtc_w, unsigned int crtc_h,
  709. uint32_t src_x, uint32_t src_y,
  710. uint32_t src_w, uint32_t src_h);
  711. int (*disable_plane)(struct drm_plane *plane);
  712. void (*destroy)(struct drm_plane *plane);
  713. void (*reset)(struct drm_plane *plane);
  714. int (*set_property)(struct drm_plane *plane,
  715. struct drm_property *property, uint64_t val);
  716. /* atomic update handling */
  717. struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
  718. void (*atomic_destroy_state)(struct drm_plane *plane,
  719. struct drm_plane_state *state);
  720. int (*atomic_set_property)(struct drm_plane *plane,
  721. struct drm_plane_state *state,
  722. struct drm_property *property,
  723. uint64_t val);
  724. int (*atomic_get_property)(struct drm_plane *plane,
  725. const struct drm_plane_state *state,
  726. struct drm_property *property,
  727. uint64_t *val);
  728. };
  729. enum drm_plane_type {
  730. DRM_PLANE_TYPE_OVERLAY,
  731. DRM_PLANE_TYPE_PRIMARY,
  732. DRM_PLANE_TYPE_CURSOR,
  733. };
  734. /**
  735. * struct drm_plane - central DRM plane control structure
  736. * @dev: DRM device this plane belongs to
  737. * @head: for list management
  738. * @base: base mode object
  739. * @possible_crtcs: pipes this plane can be bound to
  740. * @format_types: array of formats supported by this plane
  741. * @format_count: number of formats supported
  742. * @format_default: driver hasn't supplied supported formats for the plane
  743. * @crtc: currently bound CRTC
  744. * @fb: currently bound fb
  745. * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
  746. * drm_mode_set_config_internal() to implement correct refcounting.
  747. * @funcs: helper functions
  748. * @properties: property tracking for this plane
  749. * @type: type of plane (overlay, primary, cursor)
  750. * @state: current atomic state for this plane
  751. */
  752. struct drm_plane {
  753. struct drm_device *dev;
  754. struct list_head head;
  755. struct drm_modeset_lock mutex;
  756. struct drm_mode_object base;
  757. uint32_t possible_crtcs;
  758. uint32_t *format_types;
  759. unsigned int format_count;
  760. bool format_default;
  761. struct drm_crtc *crtc;
  762. struct drm_framebuffer *fb;
  763. struct drm_framebuffer *old_fb;
  764. const struct drm_plane_funcs *funcs;
  765. struct drm_object_properties properties;
  766. enum drm_plane_type type;
  767. const void *helper_private;
  768. struct drm_plane_state *state;
  769. };
  770. /**
  771. * struct drm_bridge_funcs - drm_bridge control functions
  772. * @attach: Called during drm_bridge_attach
  773. * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
  774. * @disable: Called right before encoder prepare, disables the bridge
  775. * @post_disable: Called right after encoder prepare, for lockstepped disable
  776. * @mode_set: Set this mode to the bridge
  777. * @pre_enable: Called right before encoder commit, for lockstepped commit
  778. * @enable: Called right after encoder commit, enables the bridge
  779. */
  780. struct drm_bridge_funcs {
  781. int (*attach)(struct drm_bridge *bridge);
  782. bool (*mode_fixup)(struct drm_bridge *bridge,
  783. const struct drm_display_mode *mode,
  784. struct drm_display_mode *adjusted_mode);
  785. void (*disable)(struct drm_bridge *bridge);
  786. void (*post_disable)(struct drm_bridge *bridge);
  787. void (*mode_set)(struct drm_bridge *bridge,
  788. struct drm_display_mode *mode,
  789. struct drm_display_mode *adjusted_mode);
  790. void (*pre_enable)(struct drm_bridge *bridge);
  791. void (*enable)(struct drm_bridge *bridge);
  792. };
  793. /**
  794. * struct drm_bridge - central DRM bridge control structure
  795. * @dev: DRM device this bridge belongs to
  796. * @encoder: encoder to which this bridge is connected
  797. * @next: the next bridge in the encoder chain
  798. * @of_node: device node pointer to the bridge
  799. * @list: to keep track of all added bridges
  800. * @base: base mode object
  801. * @funcs: control functions
  802. * @driver_private: pointer to the bridge driver's internal context
  803. */
  804. struct drm_bridge {
  805. struct drm_device *dev;
  806. struct drm_encoder *encoder;
  807. struct drm_bridge *next;
  808. #ifdef CONFIG_OF
  809. struct device_node *of_node;
  810. #endif
  811. struct list_head list;
  812. const struct drm_bridge_funcs *funcs;
  813. void *driver_private;
  814. };
  815. /**
  816. * struct drm_atomic_state - the global state object for atomic updates
  817. * @dev: parent DRM device
  818. * @allow_modeset: allow full modeset
  819. * @legacy_cursor_update: hint to enforce legacy cursor ioctl semantics
  820. * @planes: pointer to array of plane pointers
  821. * @plane_states: pointer to array of plane states pointers
  822. * @crtcs: pointer to array of CRTC pointers
  823. * @crtc_states: pointer to array of CRTC states pointers
  824. * @num_connector: size of the @connectors and @connector_states arrays
  825. * @connectors: pointer to array of connector pointers
  826. * @connector_states: pointer to array of connector states pointers
  827. * @acquire_ctx: acquire context for this atomic modeset state update
  828. */
  829. struct drm_atomic_state {
  830. struct drm_device *dev;
  831. bool allow_modeset : 1;
  832. bool legacy_cursor_update : 1;
  833. struct drm_plane **planes;
  834. struct drm_plane_state **plane_states;
  835. struct drm_crtc **crtcs;
  836. struct drm_crtc_state **crtc_states;
  837. int num_connector;
  838. struct drm_connector **connectors;
  839. struct drm_connector_state **connector_states;
  840. struct drm_modeset_acquire_ctx *acquire_ctx;
  841. };
  842. /**
  843. * struct drm_mode_set - new values for a CRTC config change
  844. * @fb: framebuffer to use for new config
  845. * @crtc: CRTC whose configuration we're about to change
  846. * @mode: mode timings to use
  847. * @x: position of this CRTC relative to @fb
  848. * @y: position of this CRTC relative to @fb
  849. * @connectors: array of connectors to drive with this CRTC if possible
  850. * @num_connectors: size of @connectors array
  851. *
  852. * Represents a single crtc the connectors that it drives with what mode
  853. * and from which framebuffer it scans out from.
  854. *
  855. * This is used to set modes.
  856. */
  857. struct drm_mode_set {
  858. struct drm_framebuffer *fb;
  859. struct drm_crtc *crtc;
  860. struct drm_display_mode *mode;
  861. uint32_t x;
  862. uint32_t y;
  863. struct drm_connector **connectors;
  864. size_t num_connectors;
  865. };
  866. /**
  867. * struct drm_mode_config_funcs - basic driver provided mode setting functions
  868. * @fb_create: create a new framebuffer object
  869. * @output_poll_changed: function to handle output configuration changes
  870. * @atomic_check: check whether a given atomic state update is possible
  871. * @atomic_commit: commit an atomic state update previously verified with
  872. * atomic_check()
  873. * @atomic_state_alloc: allocate a new atomic state
  874. * @atomic_state_clear: clear the atomic state
  875. * @atomic_state_free: free the atomic state
  876. *
  877. * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
  878. * involve drivers.
  879. */
  880. struct drm_mode_config_funcs {
  881. struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
  882. struct drm_file *file_priv,
  883. struct drm_mode_fb_cmd2 *mode_cmd);
  884. void (*output_poll_changed)(struct drm_device *dev);
  885. int (*atomic_check)(struct drm_device *dev,
  886. struct drm_atomic_state *a);
  887. int (*atomic_commit)(struct drm_device *dev,
  888. struct drm_atomic_state *a,
  889. bool async);
  890. struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
  891. void (*atomic_state_clear)(struct drm_atomic_state *state);
  892. void (*atomic_state_free)(struct drm_atomic_state *state);
  893. };
  894. /**
  895. * struct drm_mode_config - Mode configuration control structure
  896. * @mutex: mutex protecting KMS related lists and structures
  897. * @connection_mutex: ww mutex protecting connector state and routing
  898. * @acquire_ctx: global implicit acquire context used by atomic drivers for
  899. * legacy ioctls
  900. * @idr_mutex: mutex for KMS ID allocation and management
  901. * @crtc_idr: main KMS ID tracking object
  902. * @fb_lock: mutex to protect fb state and lists
  903. * @num_fb: number of fbs available
  904. * @fb_list: list of framebuffers available
  905. * @num_connector: number of connectors on this device
  906. * @connector_list: list of connector objects
  907. * @num_encoder: number of encoders on this device
  908. * @encoder_list: list of encoder objects
  909. * @num_overlay_plane: number of overlay planes on this device
  910. * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
  911. * @plane_list: list of plane objects
  912. * @num_crtc: number of CRTCs on this device
  913. * @crtc_list: list of CRTC objects
  914. * @property_list: list of property objects
  915. * @min_width: minimum pixel width on this device
  916. * @min_height: minimum pixel height on this device
  917. * @max_width: maximum pixel width on this device
  918. * @max_height: maximum pixel height on this device
  919. * @funcs: core driver provided mode setting functions
  920. * @fb_base: base address of the framebuffer
  921. * @poll_enabled: track polling support for this device
  922. * @poll_running: track polling status for this device
  923. * @output_poll_work: delayed work for polling in process context
  924. * @property_blob_list: list of all the blob property objects
  925. * @blob_lock: mutex for blob property allocation and management
  926. * @*_property: core property tracking
  927. * @preferred_depth: preferred RBG pixel depth, used by fb helpers
  928. * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
  929. * @async_page_flip: does this device support async flips on the primary plane?
  930. * @cursor_width: hint to userspace for max cursor width
  931. * @cursor_height: hint to userspace for max cursor height
  932. *
  933. * Core mode resource tracking structure. All CRTC, encoders, and connectors
  934. * enumerated by the driver are added here, as are global properties. Some
  935. * global restrictions are also here, e.g. dimension restrictions.
  936. */
  937. struct drm_mode_config {
  938. struct mutex mutex; /* protects configuration (mode lists etc.) */
  939. struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
  940. struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
  941. struct mutex idr_mutex; /* for IDR management */
  942. struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
  943. struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
  944. /* this is limited to one for now */
  945. struct mutex fb_lock; /* proctects global and per-file fb lists */
  946. int num_fb;
  947. struct list_head fb_list;
  948. int num_connector;
  949. struct list_head connector_list;
  950. int num_encoder;
  951. struct list_head encoder_list;
  952. /*
  953. * Track # of overlay planes separately from # of total planes. By
  954. * default we only advertise overlay planes to userspace; if userspace
  955. * sets the "universal plane" capability bit, we'll go ahead and
  956. * expose all planes.
  957. */
  958. int num_overlay_plane;
  959. int num_total_plane;
  960. struct list_head plane_list;
  961. int num_crtc;
  962. struct list_head crtc_list;
  963. struct list_head property_list;
  964. int min_width, min_height;
  965. int max_width, max_height;
  966. const struct drm_mode_config_funcs *funcs;
  967. resource_size_t fb_base;
  968. /* output poll support */
  969. bool poll_enabled;
  970. bool poll_running;
  971. bool delayed_event;
  972. struct delayed_work output_poll_work;
  973. struct mutex blob_lock;
  974. /* pointers to standard properties */
  975. struct list_head property_blob_list;
  976. struct drm_property *edid_property;
  977. struct drm_property *dpms_property;
  978. struct drm_property *path_property;
  979. struct drm_property *tile_property;
  980. struct drm_property *plane_type_property;
  981. struct drm_property *rotation_property;
  982. struct drm_property *prop_src_x;
  983. struct drm_property *prop_src_y;
  984. struct drm_property *prop_src_w;
  985. struct drm_property *prop_src_h;
  986. struct drm_property *prop_crtc_x;
  987. struct drm_property *prop_crtc_y;
  988. struct drm_property *prop_crtc_w;
  989. struct drm_property *prop_crtc_h;
  990. struct drm_property *prop_fb_id;
  991. struct drm_property *prop_crtc_id;
  992. struct drm_property *prop_active;
  993. struct drm_property *prop_mode_id;
  994. /* DVI-I properties */
  995. struct drm_property *dvi_i_subconnector_property;
  996. struct drm_property *dvi_i_select_subconnector_property;
  997. /* TV properties */
  998. struct drm_property *tv_subconnector_property;
  999. struct drm_property *tv_select_subconnector_property;
  1000. struct drm_property *tv_mode_property;
  1001. struct drm_property *tv_left_margin_property;
  1002. struct drm_property *tv_right_margin_property;
  1003. struct drm_property *tv_top_margin_property;
  1004. struct drm_property *tv_bottom_margin_property;
  1005. struct drm_property *tv_brightness_property;
  1006. struct drm_property *tv_contrast_property;
  1007. struct drm_property *tv_flicker_reduction_property;
  1008. struct drm_property *tv_overscan_property;
  1009. struct drm_property *tv_saturation_property;
  1010. struct drm_property *tv_hue_property;
  1011. /* Optional properties */
  1012. struct drm_property *scaling_mode_property;
  1013. struct drm_property *aspect_ratio_property;
  1014. struct drm_property *dirty_info_property;
  1015. /* properties for virtual machine layout */
  1016. struct drm_property *suggested_x_property;
  1017. struct drm_property *suggested_y_property;
  1018. /* dumb ioctl parameters */
  1019. uint32_t preferred_depth, prefer_shadow;
  1020. /* whether async page flip is supported or not */
  1021. bool async_page_flip;
  1022. /* whether the driver supports fb modifiers */
  1023. bool allow_fb_modifiers;
  1024. /* cursor size */
  1025. uint32_t cursor_width, cursor_height;
  1026. };
  1027. /**
  1028. * drm_for_each_plane_mask - iterate over planes specified by bitmask
  1029. * @plane: the loop cursor
  1030. * @dev: the DRM device
  1031. * @plane_mask: bitmask of plane indices
  1032. *
  1033. * Iterate over all planes specified by bitmask.
  1034. */
  1035. #define drm_for_each_plane_mask(plane, dev, plane_mask) \
  1036. list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
  1037. if ((plane_mask) & (1 << drm_plane_index(plane)))
  1038. #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
  1039. #define obj_to_connector(x) container_of(x, struct drm_connector, base)
  1040. #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
  1041. #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
  1042. #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
  1043. #define obj_to_property(x) container_of(x, struct drm_property, base)
  1044. #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
  1045. #define obj_to_plane(x) container_of(x, struct drm_plane, base)
  1046. struct drm_prop_enum_list {
  1047. int type;
  1048. char *name;
  1049. };
  1050. extern int drm_crtc_init_with_planes(struct drm_device *dev,
  1051. struct drm_crtc *crtc,
  1052. struct drm_plane *primary,
  1053. struct drm_plane *cursor,
  1054. const struct drm_crtc_funcs *funcs);
  1055. extern void drm_crtc_cleanup(struct drm_crtc *crtc);
  1056. extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
  1057. /**
  1058. * drm_crtc_mask - find the mask of a registered CRTC
  1059. * @crtc: CRTC to find mask for
  1060. *
  1061. * Given a registered CRTC, return the mask bit of that CRTC for an
  1062. * encoder's possible_crtcs field.
  1063. */
  1064. static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
  1065. {
  1066. return 1 << drm_crtc_index(crtc);
  1067. }
  1068. extern void drm_connector_ida_init(void);
  1069. extern void drm_connector_ida_destroy(void);
  1070. extern int drm_connector_init(struct drm_device *dev,
  1071. struct drm_connector *connector,
  1072. const struct drm_connector_funcs *funcs,
  1073. int connector_type);
  1074. int drm_connector_register(struct drm_connector *connector);
  1075. void drm_connector_unregister(struct drm_connector *connector);
  1076. extern void drm_connector_cleanup(struct drm_connector *connector);
  1077. extern unsigned int drm_connector_index(struct drm_connector *connector);
  1078. /* helper to unplug all connectors from sysfs for device */
  1079. extern void drm_connector_unplug_all(struct drm_device *dev);
  1080. extern int drm_bridge_add(struct drm_bridge *bridge);
  1081. extern void drm_bridge_remove(struct drm_bridge *bridge);
  1082. extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
  1083. extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
  1084. bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
  1085. const struct drm_display_mode *mode,
  1086. struct drm_display_mode *adjusted_mode);
  1087. void drm_bridge_disable(struct drm_bridge *bridge);
  1088. void drm_bridge_post_disable(struct drm_bridge *bridge);
  1089. void drm_bridge_mode_set(struct drm_bridge *bridge,
  1090. struct drm_display_mode *mode,
  1091. struct drm_display_mode *adjusted_mode);
  1092. void drm_bridge_pre_enable(struct drm_bridge *bridge);
  1093. void drm_bridge_enable(struct drm_bridge *bridge);
  1094. extern int drm_encoder_init(struct drm_device *dev,
  1095. struct drm_encoder *encoder,
  1096. const struct drm_encoder_funcs *funcs,
  1097. int encoder_type);
  1098. /**
  1099. * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
  1100. * @encoder: encoder to test
  1101. * @crtc: crtc to test
  1102. *
  1103. * Return false if @encoder can't be driven by @crtc, true otherwise.
  1104. */
  1105. static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
  1106. struct drm_crtc *crtc)
  1107. {
  1108. return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
  1109. }
  1110. extern int drm_universal_plane_init(struct drm_device *dev,
  1111. struct drm_plane *plane,
  1112. unsigned long possible_crtcs,
  1113. const struct drm_plane_funcs *funcs,
  1114. const uint32_t *formats,
  1115. unsigned int format_count,
  1116. enum drm_plane_type type);
  1117. extern int drm_plane_init(struct drm_device *dev,
  1118. struct drm_plane *plane,
  1119. unsigned long possible_crtcs,
  1120. const struct drm_plane_funcs *funcs,
  1121. const uint32_t *formats, unsigned int format_count,
  1122. bool is_primary);
  1123. extern void drm_plane_cleanup(struct drm_plane *plane);
  1124. extern unsigned int drm_plane_index(struct drm_plane *plane);
  1125. extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
  1126. extern void drm_plane_force_disable(struct drm_plane *plane);
  1127. extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
  1128. u32 format);
  1129. extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
  1130. int *hdisplay, int *vdisplay);
  1131. extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
  1132. int x, int y,
  1133. const struct drm_display_mode *mode,
  1134. const struct drm_framebuffer *fb);
  1135. extern void drm_encoder_cleanup(struct drm_encoder *encoder);
  1136. extern const char *drm_get_connector_status_name(enum drm_connector_status status);
  1137. extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
  1138. extern const char *drm_get_dpms_name(int val);
  1139. extern const char *drm_get_dvi_i_subconnector_name(int val);
  1140. extern const char *drm_get_dvi_i_select_name(int val);
  1141. extern const char *drm_get_tv_subconnector_name(int val);
  1142. extern const char *drm_get_tv_select_name(int val);
  1143. extern void drm_fb_release(struct drm_file *file_priv);
  1144. extern void drm_property_destroy_user_blobs(struct drm_device *dev,
  1145. struct drm_file *file_priv);
  1146. extern bool drm_probe_ddc(struct i2c_adapter *adapter);
  1147. extern struct edid *drm_get_edid(struct drm_connector *connector,
  1148. struct i2c_adapter *adapter);
  1149. extern struct edid *drm_edid_duplicate(const struct edid *edid);
  1150. extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
  1151. extern void drm_mode_config_init(struct drm_device *dev);
  1152. extern void drm_mode_config_reset(struct drm_device *dev);
  1153. extern void drm_mode_config_cleanup(struct drm_device *dev);
  1154. extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
  1155. const char *path);
  1156. int drm_mode_connector_set_tile_property(struct drm_connector *connector);
  1157. extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
  1158. const struct edid *edid);
  1159. extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
  1160. const u32 *formats,
  1161. unsigned int num_formats);
  1162. static inline bool drm_property_type_is(struct drm_property *property,
  1163. uint32_t type)
  1164. {
  1165. /* instanceof for props.. handles extended type vs original types: */
  1166. if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
  1167. return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
  1168. return property->flags & type;
  1169. }
  1170. static inline bool drm_property_type_valid(struct drm_property *property)
  1171. {
  1172. if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
  1173. return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
  1174. return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
  1175. }
  1176. extern int drm_object_property_set_value(struct drm_mode_object *obj,
  1177. struct drm_property *property,
  1178. uint64_t val);
  1179. extern int drm_object_property_get_value(struct drm_mode_object *obj,
  1180. struct drm_property *property,
  1181. uint64_t *value);
  1182. extern int drm_framebuffer_init(struct drm_device *dev,
  1183. struct drm_framebuffer *fb,
  1184. const struct drm_framebuffer_funcs *funcs);
  1185. extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
  1186. uint32_t id);
  1187. extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
  1188. extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
  1189. extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
  1190. extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
  1191. extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
  1192. extern void drm_object_attach_property(struct drm_mode_object *obj,
  1193. struct drm_property *property,
  1194. uint64_t init_val);
  1195. extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
  1196. const char *name, int num_values);
  1197. extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
  1198. const char *name,
  1199. const struct drm_prop_enum_list *props,
  1200. int num_values);
  1201. struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
  1202. int flags, const char *name,
  1203. const struct drm_prop_enum_list *props,
  1204. int num_props,
  1205. uint64_t supported_bits);
  1206. struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
  1207. const char *name,
  1208. uint64_t min, uint64_t max);
  1209. struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
  1210. int flags, const char *name,
  1211. int64_t min, int64_t max);
  1212. struct drm_property *drm_property_create_object(struct drm_device *dev,
  1213. int flags, const char *name, uint32_t type);
  1214. struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
  1215. const char *name);
  1216. struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
  1217. size_t length,
  1218. const void *data);
  1219. struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
  1220. uint32_t id);
  1221. struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
  1222. void drm_property_unreference_blob(struct drm_property_blob *blob);
  1223. extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
  1224. extern int drm_property_add_enum(struct drm_property *property, int index,
  1225. uint64_t value, const char *name);
  1226. extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
  1227. extern int drm_mode_create_tv_properties(struct drm_device *dev,
  1228. unsigned int num_modes,
  1229. char *modes[]);
  1230. extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
  1231. extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
  1232. extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
  1233. extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
  1234. extern bool drm_property_change_valid_get(struct drm_property *property,
  1235. uint64_t value, struct drm_mode_object **ref);
  1236. extern void drm_property_change_valid_put(struct drm_property *property,
  1237. struct drm_mode_object *ref);
  1238. extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
  1239. struct drm_encoder *encoder);
  1240. extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
  1241. int gamma_size);
  1242. extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
  1243. uint32_t id, uint32_t type);
  1244. /* IOCTLs */
  1245. extern int drm_mode_getresources(struct drm_device *dev,
  1246. void *data, struct drm_file *file_priv);
  1247. extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
  1248. struct drm_file *file_priv);
  1249. extern int drm_mode_getcrtc(struct drm_device *dev,
  1250. void *data, struct drm_file *file_priv);
  1251. extern int drm_mode_getconnector(struct drm_device *dev,
  1252. void *data, struct drm_file *file_priv);
  1253. extern int drm_mode_set_config_internal(struct drm_mode_set *set);
  1254. extern int drm_mode_setcrtc(struct drm_device *dev,
  1255. void *data, struct drm_file *file_priv);
  1256. extern int drm_mode_getplane(struct drm_device *dev,
  1257. void *data, struct drm_file *file_priv);
  1258. extern int drm_mode_setplane(struct drm_device *dev,
  1259. void *data, struct drm_file *file_priv);
  1260. extern int drm_mode_cursor_ioctl(struct drm_device *dev,
  1261. void *data, struct drm_file *file_priv);
  1262. extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
  1263. void *data, struct drm_file *file_priv);
  1264. extern int drm_mode_addfb(struct drm_device *dev,
  1265. void *data, struct drm_file *file_priv);
  1266. extern int drm_mode_addfb2(struct drm_device *dev,
  1267. void *data, struct drm_file *file_priv);
  1268. extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
  1269. extern int drm_mode_rmfb(struct drm_device *dev,
  1270. void *data, struct drm_file *file_priv);
  1271. extern int drm_mode_getfb(struct drm_device *dev,
  1272. void *data, struct drm_file *file_priv);
  1273. extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
  1274. void *data, struct drm_file *file_priv);
  1275. extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
  1276. void *data, struct drm_file *file_priv);
  1277. extern int drm_mode_getblob_ioctl(struct drm_device *dev,
  1278. void *data, struct drm_file *file_priv);
  1279. extern int drm_mode_createblob_ioctl(struct drm_device *dev,
  1280. void *data, struct drm_file *file_priv);
  1281. extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
  1282. void *data, struct drm_file *file_priv);
  1283. extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
  1284. void *data, struct drm_file *file_priv);
  1285. extern int drm_mode_getencoder(struct drm_device *dev,
  1286. void *data, struct drm_file *file_priv);
  1287. extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
  1288. void *data, struct drm_file *file_priv);
  1289. extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
  1290. void *data, struct drm_file *file_priv);
  1291. extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
  1292. extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
  1293. extern bool drm_detect_hdmi_monitor(struct edid *edid);
  1294. extern bool drm_detect_monitor_audio(struct edid *edid);
  1295. extern bool drm_rgb_quant_range_selectable(struct edid *edid);
  1296. extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
  1297. void *data, struct drm_file *file_priv);
  1298. extern int drm_add_modes_noedid(struct drm_connector *connector,
  1299. int hdisplay, int vdisplay);
  1300. extern void drm_set_preferred_mode(struct drm_connector *connector,
  1301. int hpref, int vpref);
  1302. extern int drm_edid_header_is_valid(const u8 *raw_edid);
  1303. extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
  1304. bool *edid_corrupt);
  1305. extern bool drm_edid_is_valid(struct edid *edid);
  1306. extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
  1307. char topology[8]);
  1308. extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
  1309. char topology[8]);
  1310. extern void drm_mode_put_tile_group(struct drm_device *dev,
  1311. struct drm_tile_group *tg);
  1312. struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
  1313. int hsize, int vsize, int fresh,
  1314. bool rb);
  1315. extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
  1316. void *data, struct drm_file *file_priv);
  1317. extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
  1318. void *data, struct drm_file *file_priv);
  1319. extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
  1320. void *data, struct drm_file *file_priv);
  1321. extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
  1322. struct drm_file *file_priv);
  1323. extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
  1324. struct drm_file *file_priv);
  1325. extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
  1326. struct drm_property *property,
  1327. uint64_t value);
  1328. extern int drm_mode_atomic_ioctl(struct drm_device *dev,
  1329. void *data, struct drm_file *file_priv);
  1330. extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
  1331. int *bpp);
  1332. extern int drm_format_num_planes(uint32_t format);
  1333. extern int drm_format_plane_cpp(uint32_t format, int plane);
  1334. extern int drm_format_horz_chroma_subsampling(uint32_t format);
  1335. extern int drm_format_vert_chroma_subsampling(uint32_t format);
  1336. extern const char *drm_get_format_name(uint32_t format);
  1337. extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
  1338. unsigned int supported_rotations);
  1339. extern unsigned int drm_rotation_simplify(unsigned int rotation,
  1340. unsigned int supported_rotations);
  1341. /* Helpers */
  1342. static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
  1343. uint32_t id)
  1344. {
  1345. struct drm_mode_object *mo;
  1346. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
  1347. return mo ? obj_to_plane(mo) : NULL;
  1348. }
  1349. static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
  1350. uint32_t id)
  1351. {
  1352. struct drm_mode_object *mo;
  1353. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
  1354. return mo ? obj_to_crtc(mo) : NULL;
  1355. }
  1356. static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
  1357. uint32_t id)
  1358. {
  1359. struct drm_mode_object *mo;
  1360. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
  1361. return mo ? obj_to_encoder(mo) : NULL;
  1362. }
  1363. static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
  1364. uint32_t id)
  1365. {
  1366. struct drm_mode_object *mo;
  1367. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
  1368. return mo ? obj_to_connector(mo) : NULL;
  1369. }
  1370. static inline struct drm_property *drm_property_find(struct drm_device *dev,
  1371. uint32_t id)
  1372. {
  1373. struct drm_mode_object *mo;
  1374. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
  1375. return mo ? obj_to_property(mo) : NULL;
  1376. }
  1377. /* Plane list iterator for legacy (overlay only) planes. */
  1378. #define drm_for_each_legacy_plane(plane, dev) \
  1379. list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
  1380. if (plane->type == DRM_PLANE_TYPE_OVERLAY)
  1381. #define drm_for_each_plane(plane, dev) \
  1382. list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
  1383. #define drm_for_each_crtc(crtc, dev) \
  1384. list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
  1385. static inline void
  1386. assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
  1387. {
  1388. /*
  1389. * The connector hotadd/remove code currently grabs both locks when
  1390. * updating lists. Hence readers need only hold either of them to be
  1391. * safe and the check amounts to
  1392. *
  1393. * WARN_ON(not_holding(A) && not_holding(B)).
  1394. */
  1395. WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
  1396. !drm_modeset_is_locked(&mode_config->connection_mutex));
  1397. }
  1398. #define drm_for_each_connector(connector, dev) \
  1399. for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
  1400. connector = list_first_entry(&(dev)->mode_config.connector_list, \
  1401. struct drm_connector, head); \
  1402. &connector->head != (&(dev)->mode_config.connector_list); \
  1403. connector = list_next_entry(connector, head))
  1404. #define drm_for_each_encoder(encoder, dev) \
  1405. list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
  1406. #define drm_for_each_fb(fb, dev) \
  1407. for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
  1408. fb = list_first_entry(&(dev)->mode_config.fb_list, \
  1409. struct drm_framebuffer, head); \
  1410. &fb->head != (&(dev)->mode_config.fb_list); \
  1411. fb = list_next_entry(fb, head))
  1412. #endif /* __DRM_CRTC_H__ */