drm_crtc.h 54 KB

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