drm_crtc.h 57 KB

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