drm_crtc.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  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 <drm/drm_mode.h>
  34. #include <drm/drm_fourcc.h>
  35. struct drm_device;
  36. struct drm_mode_set;
  37. struct drm_framebuffer;
  38. struct drm_object_properties;
  39. struct drm_file;
  40. struct drm_clip_rect;
  41. #define DRM_MODE_OBJECT_CRTC 0xcccccccc
  42. #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
  43. #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
  44. #define DRM_MODE_OBJECT_MODE 0xdededede
  45. #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
  46. #define DRM_MODE_OBJECT_FB 0xfbfbfbfb
  47. #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
  48. #define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
  49. #define DRM_MODE_OBJECT_BRIDGE 0xbdbdbdbd
  50. struct drm_mode_object {
  51. uint32_t id;
  52. uint32_t type;
  53. struct drm_object_properties *properties;
  54. };
  55. #define DRM_OBJECT_MAX_PROPERTY 24
  56. struct drm_object_properties {
  57. int count;
  58. uint32_t ids[DRM_OBJECT_MAX_PROPERTY];
  59. uint64_t values[DRM_OBJECT_MAX_PROPERTY];
  60. };
  61. enum drm_connector_force {
  62. DRM_FORCE_UNSPECIFIED,
  63. DRM_FORCE_OFF,
  64. DRM_FORCE_ON, /* force on analog part normally */
  65. DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
  66. };
  67. #include <drm/drm_modes.h>
  68. enum drm_connector_status {
  69. connector_status_connected = 1,
  70. connector_status_disconnected = 2,
  71. connector_status_unknown = 3,
  72. };
  73. enum subpixel_order {
  74. SubPixelUnknown = 0,
  75. SubPixelHorizontalRGB,
  76. SubPixelHorizontalBGR,
  77. SubPixelVerticalRGB,
  78. SubPixelVerticalBGR,
  79. SubPixelNone,
  80. };
  81. #define DRM_COLOR_FORMAT_RGB444 (1<<0)
  82. #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
  83. #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
  84. /*
  85. * Describes a given display (e.g. CRT or flat panel) and its limitations.
  86. */
  87. struct drm_display_info {
  88. char name[DRM_DISPLAY_INFO_LEN];
  89. /* Physical size */
  90. unsigned int width_mm;
  91. unsigned int height_mm;
  92. /* Clock limits FIXME: storage format */
  93. unsigned int min_vfreq, max_vfreq;
  94. unsigned int min_hfreq, max_hfreq;
  95. unsigned int pixel_clock;
  96. unsigned int bpc;
  97. enum subpixel_order subpixel_order;
  98. u32 color_formats;
  99. u8 cea_rev;
  100. };
  101. struct drm_framebuffer_funcs {
  102. /* note: use drm_framebuffer_remove() */
  103. void (*destroy)(struct drm_framebuffer *framebuffer);
  104. int (*create_handle)(struct drm_framebuffer *fb,
  105. struct drm_file *file_priv,
  106. unsigned int *handle);
  107. /**
  108. * Optinal callback for the dirty fb ioctl.
  109. *
  110. * Userspace can notify the driver via this callback
  111. * that a area of the framebuffer has changed and should
  112. * be flushed to the display hardware.
  113. *
  114. * See documentation in drm_mode.h for the struct
  115. * drm_mode_fb_dirty_cmd for more information as all
  116. * the semantics and arguments have a one to one mapping
  117. * on this function.
  118. */
  119. int (*dirty)(struct drm_framebuffer *framebuffer,
  120. struct drm_file *file_priv, unsigned flags,
  121. unsigned color, struct drm_clip_rect *clips,
  122. unsigned num_clips);
  123. };
  124. struct drm_framebuffer {
  125. struct drm_device *dev;
  126. /*
  127. * Note that the fb is refcounted for the benefit of driver internals,
  128. * for example some hw, disabling a CRTC/plane is asynchronous, and
  129. * scanout does not actually complete until the next vblank. So some
  130. * cleanup (like releasing the reference(s) on the backing GEM bo(s))
  131. * should be deferred. In cases like this, the driver would like to
  132. * hold a ref to the fb even though it has already been removed from
  133. * userspace perspective.
  134. */
  135. struct kref refcount;
  136. /*
  137. * Place on the dev->mode_config.fb_list, access protected by
  138. * dev->mode_config.fb_lock.
  139. */
  140. struct list_head head;
  141. struct drm_mode_object base;
  142. const struct drm_framebuffer_funcs *funcs;
  143. unsigned int pitches[4];
  144. unsigned int offsets[4];
  145. unsigned int width;
  146. unsigned int height;
  147. /* depth can be 15 or 16 */
  148. unsigned int depth;
  149. int bits_per_pixel;
  150. int flags;
  151. uint32_t pixel_format; /* fourcc format */
  152. struct list_head filp_head;
  153. /* if you are using the helper */
  154. void *helper_private;
  155. };
  156. struct drm_property_blob {
  157. struct drm_mode_object base;
  158. struct list_head head;
  159. unsigned int length;
  160. unsigned char data[];
  161. };
  162. struct drm_property_enum {
  163. uint64_t value;
  164. struct list_head head;
  165. char name[DRM_PROP_NAME_LEN];
  166. };
  167. struct drm_property {
  168. struct list_head head;
  169. struct drm_mode_object base;
  170. uint32_t flags;
  171. char name[DRM_PROP_NAME_LEN];
  172. uint32_t num_values;
  173. uint64_t *values;
  174. struct list_head enum_blob_list;
  175. };
  176. struct drm_crtc;
  177. struct drm_connector;
  178. struct drm_encoder;
  179. struct drm_pending_vblank_event;
  180. struct drm_plane;
  181. struct drm_bridge;
  182. /**
  183. * drm_crtc_funcs - control CRTCs for a given device
  184. * @save: save CRTC state
  185. * @restore: restore CRTC state
  186. * @reset: reset CRTC after state has been invalidated (e.g. resume)
  187. * @cursor_set: setup the cursor
  188. * @cursor_move: move the cursor
  189. * @gamma_set: specify color ramp for CRTC
  190. * @destroy: deinit and free object
  191. * @set_property: called when a property is changed
  192. * @set_config: apply a new CRTC configuration
  193. * @page_flip: initiate a page flip
  194. *
  195. * The drm_crtc_funcs structure is the central CRTC management structure
  196. * in the DRM. Each CRTC controls one or more connectors (note that the name
  197. * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
  198. * connectors, not just CRTs).
  199. *
  200. * Each driver is responsible for filling out this structure at startup time,
  201. * in addition to providing other modesetting features, like i2c and DDC
  202. * bus accessors.
  203. */
  204. struct drm_crtc_funcs {
  205. /* Save CRTC state */
  206. void (*save)(struct drm_crtc *crtc); /* suspend? */
  207. /* Restore CRTC state */
  208. void (*restore)(struct drm_crtc *crtc); /* resume? */
  209. /* Reset CRTC state */
  210. void (*reset)(struct drm_crtc *crtc);
  211. /* cursor controls */
  212. int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
  213. uint32_t handle, uint32_t width, uint32_t height);
  214. int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
  215. uint32_t handle, uint32_t width, uint32_t height,
  216. int32_t hot_x, int32_t hot_y);
  217. int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
  218. /* Set gamma on the CRTC */
  219. void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  220. uint32_t start, uint32_t size);
  221. /* Object destroy routine */
  222. void (*destroy)(struct drm_crtc *crtc);
  223. int (*set_config)(struct drm_mode_set *set);
  224. /*
  225. * Flip to the given framebuffer. This implements the page
  226. * flip ioctl described in drm_mode.h, specifically, the
  227. * implementation must return immediately and block all
  228. * rendering to the current fb until the flip has completed.
  229. * If userspace set the event flag in the ioctl, the event
  230. * argument will point to an event to send back when the flip
  231. * completes, otherwise it will be NULL.
  232. */
  233. int (*page_flip)(struct drm_crtc *crtc,
  234. struct drm_framebuffer *fb,
  235. struct drm_pending_vblank_event *event,
  236. uint32_t flags);
  237. int (*set_property)(struct drm_crtc *crtc,
  238. struct drm_property *property, uint64_t val);
  239. };
  240. /**
  241. * drm_crtc - central CRTC control structure
  242. * @dev: parent DRM device
  243. * @head: list management
  244. * @base: base KMS object for ID tracking etc.
  245. * @primary: primary plane for this CRTC
  246. * @cursor: cursor plane for this CRTC
  247. * @enabled: is this CRTC enabled?
  248. * @mode: current mode timings
  249. * @hwmode: mode timings as programmed to hw regs
  250. * @invert_dimensions: for purposes of error checking crtc vs fb sizes,
  251. * invert the width/height of the crtc. This is used if the driver
  252. * is performing 90 or 270 degree rotated scanout
  253. * @x: x position on screen
  254. * @y: y position on screen
  255. * @funcs: CRTC control functions
  256. * @gamma_size: size of gamma ramp
  257. * @gamma_store: gamma ramp values
  258. * @framedur_ns: precise frame timing
  259. * @framedur_ns: precise line timing
  260. * @pixeldur_ns: precise pixel timing
  261. * @helper_private: mid-layer private data
  262. * @properties: property tracking for this CRTC
  263. *
  264. * Each CRTC may have one or more connectors associated with it. This structure
  265. * allows the CRTC to be controlled.
  266. */
  267. struct drm_crtc {
  268. struct drm_device *dev;
  269. struct list_head head;
  270. /**
  271. * crtc mutex
  272. *
  273. * This provides a read lock for the overall crtc state (mode, dpms
  274. * state, ...) and a write lock for everything which can be update
  275. * without a full modeset (fb, cursor data, ...)
  276. */
  277. struct mutex mutex;
  278. struct drm_mode_object base;
  279. /* primary and cursor planes for CRTC */
  280. struct drm_plane *primary;
  281. struct drm_plane *cursor;
  282. /* Temporary tracking of the old fb while a modeset is ongoing. Used
  283. * by drm_mode_set_config_internal to implement correct refcounting. */
  284. struct drm_framebuffer *old_fb;
  285. bool enabled;
  286. /* Requested mode from modesetting. */
  287. struct drm_display_mode mode;
  288. /* Programmed mode in hw, after adjustments for encoders,
  289. * crtc, panel scaling etc. Needed for timestamping etc.
  290. */
  291. struct drm_display_mode hwmode;
  292. bool invert_dimensions;
  293. int x, y;
  294. const struct drm_crtc_funcs *funcs;
  295. /* CRTC gamma size for reporting to userspace */
  296. uint32_t gamma_size;
  297. uint16_t *gamma_store;
  298. /* Constants needed for precise vblank and swap timestamping. */
  299. int framedur_ns, linedur_ns, pixeldur_ns;
  300. /* if you are using the helper */
  301. void *helper_private;
  302. struct drm_object_properties properties;
  303. };
  304. /**
  305. * drm_connector_funcs - control connectors on a given device
  306. * @dpms: set power state (see drm_crtc_funcs above)
  307. * @save: save connector state
  308. * @restore: restore connector state
  309. * @reset: reset connector after state has been invalidated (e.g. resume)
  310. * @detect: is this connector active?
  311. * @fill_modes: fill mode list for this connector
  312. * @set_property: property for this connector may need an update
  313. * @destroy: make object go away
  314. * @force: notify the driver that the connector is forced on
  315. *
  316. * Each CRTC may have one or more connectors attached to it. The functions
  317. * below allow the core DRM code to control connectors, enumerate available modes,
  318. * etc.
  319. */
  320. struct drm_connector_funcs {
  321. void (*dpms)(struct drm_connector *connector, int mode);
  322. void (*save)(struct drm_connector *connector);
  323. void (*restore)(struct drm_connector *connector);
  324. void (*reset)(struct drm_connector *connector);
  325. /* Check to see if anything is attached to the connector.
  326. * @force is set to false whilst polling, true when checking the
  327. * connector due to user request. @force can be used by the driver
  328. * to avoid expensive, destructive operations during automated
  329. * probing.
  330. */
  331. enum drm_connector_status (*detect)(struct drm_connector *connector,
  332. bool force);
  333. int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
  334. int (*set_property)(struct drm_connector *connector, struct drm_property *property,
  335. uint64_t val);
  336. void (*destroy)(struct drm_connector *connector);
  337. void (*force)(struct drm_connector *connector);
  338. };
  339. /**
  340. * drm_encoder_funcs - encoder controls
  341. * @reset: reset state (e.g. at init or resume time)
  342. * @destroy: cleanup and free associated data
  343. *
  344. * Encoders sit between CRTCs and connectors.
  345. */
  346. struct drm_encoder_funcs {
  347. void (*reset)(struct drm_encoder *encoder);
  348. void (*destroy)(struct drm_encoder *encoder);
  349. };
  350. #define DRM_CONNECTOR_MAX_ENCODER 3
  351. /**
  352. * drm_encoder - central DRM encoder structure
  353. * @dev: parent DRM device
  354. * @head: list management
  355. * @base: base KMS object
  356. * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
  357. * @possible_crtcs: bitmask of potential CRTC bindings
  358. * @possible_clones: bitmask of potential sibling encoders for cloning
  359. * @crtc: currently bound CRTC
  360. * @bridge: bridge associated to the encoder
  361. * @funcs: control functions
  362. * @helper_private: mid-layer private data
  363. *
  364. * CRTCs drive pixels to encoders, which convert them into signals
  365. * appropriate for a given connector or set of connectors.
  366. */
  367. struct drm_encoder {
  368. struct drm_device *dev;
  369. struct list_head head;
  370. struct drm_mode_object base;
  371. int encoder_type;
  372. uint32_t possible_crtcs;
  373. uint32_t possible_clones;
  374. struct drm_crtc *crtc;
  375. struct drm_bridge *bridge;
  376. const struct drm_encoder_funcs *funcs;
  377. void *helper_private;
  378. };
  379. /* should we poll this connector for connects and disconnects */
  380. /* hot plug detectable */
  381. #define DRM_CONNECTOR_POLL_HPD (1 << 0)
  382. /* poll for connections */
  383. #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
  384. /* can cleanly poll for disconnections without flickering the screen */
  385. /* DACs should rarely do this without a lot of testing */
  386. #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
  387. #define MAX_ELD_BYTES 128
  388. /**
  389. * drm_connector - central DRM connector control structure
  390. * @dev: parent DRM device
  391. * @kdev: kernel device for sysfs attributes
  392. * @attr: sysfs attributes
  393. * @head: list management
  394. * @base: base KMS object
  395. * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
  396. * @connector_type_id: index into connector type enum
  397. * @interlace_allowed: can this connector handle interlaced modes?
  398. * @doublescan_allowed: can this connector handle doublescan?
  399. * @modes: modes available on this connector (from fill_modes() + user)
  400. * @status: one of the drm_connector_status enums (connected, not, or unknown)
  401. * @probed_modes: list of modes derived directly from the display
  402. * @display_info: information about attached display (e.g. from EDID)
  403. * @funcs: connector control functions
  404. * @edid_blob_ptr: DRM property containing EDID if present
  405. * @properties: property tracking for this connector
  406. * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
  407. * @dpms: current dpms state
  408. * @helper_private: mid-layer private data
  409. * @force: a %DRM_FORCE_<foo> state for forced mode sets
  410. * @encoder_ids: valid encoders for this connector
  411. * @encoder: encoder driving this connector, if any
  412. * @eld: EDID-like data, if present
  413. * @dvi_dual: dual link DVI, if found
  414. * @max_tmds_clock: max clock rate, if found
  415. * @latency_present: AV delay info from ELD, if found
  416. * @video_latency: video latency info from ELD, if found
  417. * @audio_latency: audio latency info from ELD, if found
  418. * @null_edid_counter: track sinks that give us all zeros for the EDID
  419. *
  420. * Each connector may be connected to one or more CRTCs, or may be clonable by
  421. * another connector if they can share a CRTC. Each connector also has a specific
  422. * position in the broader display (referred to as a 'screen' though it could
  423. * span multiple monitors).
  424. */
  425. struct drm_connector {
  426. struct drm_device *dev;
  427. struct device *kdev;
  428. struct device_attribute *attr;
  429. struct list_head head;
  430. struct drm_mode_object base;
  431. int connector_type;
  432. int connector_type_id;
  433. bool interlace_allowed;
  434. bool doublescan_allowed;
  435. bool stereo_allowed;
  436. struct list_head modes; /* list of modes on this connector */
  437. enum drm_connector_status status;
  438. /* these are modes added by probing with DDC or the BIOS */
  439. struct list_head probed_modes;
  440. struct drm_display_info display_info;
  441. const struct drm_connector_funcs *funcs;
  442. struct drm_property_blob *edid_blob_ptr;
  443. struct drm_object_properties properties;
  444. uint8_t polled; /* DRM_CONNECTOR_POLL_* */
  445. /* requested DPMS state */
  446. int dpms;
  447. void *helper_private;
  448. /* forced on connector */
  449. enum drm_connector_force force;
  450. uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
  451. struct drm_encoder *encoder; /* currently active encoder */
  452. /* EDID bits */
  453. uint8_t eld[MAX_ELD_BYTES];
  454. bool dvi_dual;
  455. int max_tmds_clock; /* in MHz */
  456. bool latency_present[2];
  457. int video_latency[2]; /* [0]: progressive, [1]: interlaced */
  458. int audio_latency[2];
  459. int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
  460. unsigned bad_edid_counter;
  461. };
  462. /**
  463. * drm_plane_funcs - driver plane control functions
  464. * @update_plane: update the plane configuration
  465. * @disable_plane: shut down the plane
  466. * @destroy: clean up plane resources
  467. * @set_property: called when a property is changed
  468. */
  469. struct drm_plane_funcs {
  470. int (*update_plane)(struct drm_plane *plane,
  471. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  472. int crtc_x, int crtc_y,
  473. unsigned int crtc_w, unsigned int crtc_h,
  474. uint32_t src_x, uint32_t src_y,
  475. uint32_t src_w, uint32_t src_h);
  476. int (*disable_plane)(struct drm_plane *plane);
  477. void (*destroy)(struct drm_plane *plane);
  478. int (*set_property)(struct drm_plane *plane,
  479. struct drm_property *property, uint64_t val);
  480. };
  481. enum drm_plane_type {
  482. DRM_PLANE_TYPE_OVERLAY,
  483. DRM_PLANE_TYPE_PRIMARY,
  484. DRM_PLANE_TYPE_CURSOR,
  485. };
  486. /**
  487. * drm_plane - central DRM plane control structure
  488. * @dev: DRM device this plane belongs to
  489. * @head: for list management
  490. * @base: base mode object
  491. * @possible_crtcs: pipes this plane can be bound to
  492. * @format_types: array of formats supported by this plane
  493. * @format_count: number of formats supported
  494. * @crtc: currently bound CRTC
  495. * @fb: currently bound fb
  496. * @funcs: helper functions
  497. * @properties: property tracking for this plane
  498. * @type: type of plane (overlay, primary, cursor)
  499. */
  500. struct drm_plane {
  501. struct drm_device *dev;
  502. struct list_head head;
  503. struct drm_mode_object base;
  504. uint32_t possible_crtcs;
  505. uint32_t *format_types;
  506. uint32_t format_count;
  507. struct drm_crtc *crtc;
  508. struct drm_framebuffer *fb;
  509. const struct drm_plane_funcs *funcs;
  510. struct drm_object_properties properties;
  511. enum drm_plane_type type;
  512. };
  513. /**
  514. * drm_bridge_funcs - drm_bridge control functions
  515. * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
  516. * @disable: Called right before encoder prepare, disables the bridge
  517. * @post_disable: Called right after encoder prepare, for lockstepped disable
  518. * @mode_set: Set this mode to the bridge
  519. * @pre_enable: Called right before encoder commit, for lockstepped commit
  520. * @enable: Called right after encoder commit, enables the bridge
  521. * @destroy: make object go away
  522. */
  523. struct drm_bridge_funcs {
  524. bool (*mode_fixup)(struct drm_bridge *bridge,
  525. const struct drm_display_mode *mode,
  526. struct drm_display_mode *adjusted_mode);
  527. void (*disable)(struct drm_bridge *bridge);
  528. void (*post_disable)(struct drm_bridge *bridge);
  529. void (*mode_set)(struct drm_bridge *bridge,
  530. struct drm_display_mode *mode,
  531. struct drm_display_mode *adjusted_mode);
  532. void (*pre_enable)(struct drm_bridge *bridge);
  533. void (*enable)(struct drm_bridge *bridge);
  534. void (*destroy)(struct drm_bridge *bridge);
  535. };
  536. /**
  537. * drm_bridge - central DRM bridge control structure
  538. * @dev: DRM device this bridge belongs to
  539. * @head: list management
  540. * @base: base mode object
  541. * @funcs: control functions
  542. * @driver_private: pointer to the bridge driver's internal context
  543. */
  544. struct drm_bridge {
  545. struct drm_device *dev;
  546. struct list_head head;
  547. struct drm_mode_object base;
  548. const struct drm_bridge_funcs *funcs;
  549. void *driver_private;
  550. };
  551. /**
  552. * drm_mode_set - new values for a CRTC config change
  553. * @head: list management
  554. * @fb: framebuffer to use for new config
  555. * @crtc: CRTC whose configuration we're about to change
  556. * @mode: mode timings to use
  557. * @x: position of this CRTC relative to @fb
  558. * @y: position of this CRTC relative to @fb
  559. * @connectors: array of connectors to drive with this CRTC if possible
  560. * @num_connectors: size of @connectors array
  561. *
  562. * Represents a single crtc the connectors that it drives with what mode
  563. * and from which framebuffer it scans out from.
  564. *
  565. * This is used to set modes.
  566. */
  567. struct drm_mode_set {
  568. struct drm_framebuffer *fb;
  569. struct drm_crtc *crtc;
  570. struct drm_display_mode *mode;
  571. uint32_t x;
  572. uint32_t y;
  573. struct drm_connector **connectors;
  574. size_t num_connectors;
  575. };
  576. /**
  577. * struct drm_mode_config_funcs - basic driver provided mode setting functions
  578. * @fb_create: create a new framebuffer object
  579. * @output_poll_changed: function to handle output configuration changes
  580. *
  581. * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
  582. * involve drivers.
  583. */
  584. struct drm_mode_config_funcs {
  585. struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
  586. struct drm_file *file_priv,
  587. struct drm_mode_fb_cmd2 *mode_cmd);
  588. void (*output_poll_changed)(struct drm_device *dev);
  589. };
  590. /**
  591. * drm_mode_group - group of mode setting resources for potential sub-grouping
  592. * @num_crtcs: CRTC count
  593. * @num_encoders: encoder count
  594. * @num_connectors: connector count
  595. * @id_list: list of KMS object IDs in this group
  596. *
  597. * Currently this simply tracks the global mode setting state. But in the
  598. * future it could allow groups of objects to be set aside into independent
  599. * control groups for use by different user level processes (e.g. two X servers
  600. * running simultaneously on different heads, each with their own mode
  601. * configuration and freedom of mode setting).
  602. */
  603. struct drm_mode_group {
  604. uint32_t num_crtcs;
  605. uint32_t num_encoders;
  606. uint32_t num_connectors;
  607. uint32_t num_bridges;
  608. /* list of object IDs for this group */
  609. uint32_t *id_list;
  610. };
  611. /**
  612. * drm_mode_config - Mode configuration control structure
  613. * @mutex: mutex protecting KMS related lists and structures
  614. * @idr_mutex: mutex for KMS ID allocation and management
  615. * @crtc_idr: main KMS ID tracking object
  616. * @num_fb: number of fbs available
  617. * @fb_list: list of framebuffers available
  618. * @num_connector: number of connectors on this device
  619. * @connector_list: list of connector objects
  620. * @num_bridge: number of bridges on this device
  621. * @bridge_list: list of bridge objects
  622. * @num_encoder: number of encoders on this device
  623. * @encoder_list: list of encoder objects
  624. * @num_crtc: number of CRTCs on this device
  625. * @crtc_list: list of CRTC objects
  626. * @min_width: minimum pixel width on this device
  627. * @min_height: minimum pixel height on this device
  628. * @max_width: maximum pixel width on this device
  629. * @max_height: maximum pixel height on this device
  630. * @funcs: core driver provided mode setting functions
  631. * @fb_base: base address of the framebuffer
  632. * @poll_enabled: track polling status for this device
  633. * @output_poll_work: delayed work for polling in process context
  634. * @*_property: core property tracking
  635. *
  636. * Core mode resource tracking structure. All CRTC, encoders, and connectors
  637. * enumerated by the driver are added here, as are global properties. Some
  638. * global restrictions are also here, e.g. dimension restrictions.
  639. */
  640. struct drm_mode_config {
  641. struct mutex mutex; /* protects configuration (mode lists etc.) */
  642. struct mutex idr_mutex; /* for IDR management */
  643. struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
  644. /* this is limited to one for now */
  645. /**
  646. * fb_lock - mutex to protect fb state
  647. *
  648. * Besides the global fb list his also protects the fbs list in the
  649. * file_priv
  650. */
  651. struct mutex fb_lock;
  652. int num_fb;
  653. struct list_head fb_list;
  654. int num_connector;
  655. struct list_head connector_list;
  656. int num_bridge;
  657. struct list_head bridge_list;
  658. int num_encoder;
  659. struct list_head encoder_list;
  660. /*
  661. * Track # of overlay planes separately from # of total planes. By
  662. * default we only advertise overlay planes to userspace; if userspace
  663. * sets the "universal plane" capability bit, we'll go ahead and
  664. * expose all planes.
  665. */
  666. int num_overlay_plane;
  667. int num_total_plane;
  668. struct list_head plane_list;
  669. int num_crtc;
  670. struct list_head crtc_list;
  671. struct list_head property_list;
  672. int min_width, min_height;
  673. int max_width, max_height;
  674. const struct drm_mode_config_funcs *funcs;
  675. resource_size_t fb_base;
  676. /* output poll support */
  677. bool poll_enabled;
  678. bool poll_running;
  679. struct delayed_work output_poll_work;
  680. /* pointers to standard properties */
  681. struct list_head property_blob_list;
  682. struct drm_property *edid_property;
  683. struct drm_property *dpms_property;
  684. struct drm_property *plane_type_property;
  685. /* DVI-I properties */
  686. struct drm_property *dvi_i_subconnector_property;
  687. struct drm_property *dvi_i_select_subconnector_property;
  688. /* TV properties */
  689. struct drm_property *tv_subconnector_property;
  690. struct drm_property *tv_select_subconnector_property;
  691. struct drm_property *tv_mode_property;
  692. struct drm_property *tv_left_margin_property;
  693. struct drm_property *tv_right_margin_property;
  694. struct drm_property *tv_top_margin_property;
  695. struct drm_property *tv_bottom_margin_property;
  696. struct drm_property *tv_brightness_property;
  697. struct drm_property *tv_contrast_property;
  698. struct drm_property *tv_flicker_reduction_property;
  699. struct drm_property *tv_overscan_property;
  700. struct drm_property *tv_saturation_property;
  701. struct drm_property *tv_hue_property;
  702. /* Optional properties */
  703. struct drm_property *scaling_mode_property;
  704. struct drm_property *dirty_info_property;
  705. /* dumb ioctl parameters */
  706. uint32_t preferred_depth, prefer_shadow;
  707. /* whether async page flip is supported or not */
  708. bool async_page_flip;
  709. /* cursor size */
  710. uint32_t cursor_width, cursor_height;
  711. };
  712. #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
  713. #define obj_to_connector(x) container_of(x, struct drm_connector, base)
  714. #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
  715. #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
  716. #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
  717. #define obj_to_property(x) container_of(x, struct drm_property, base)
  718. #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
  719. #define obj_to_plane(x) container_of(x, struct drm_plane, base)
  720. struct drm_prop_enum_list {
  721. int type;
  722. char *name;
  723. };
  724. extern void drm_modeset_lock_all(struct drm_device *dev);
  725. extern void drm_modeset_unlock_all(struct drm_device *dev);
  726. extern void drm_warn_on_modeset_not_all_locked(struct drm_device *dev);
  727. extern int drm_crtc_init_with_planes(struct drm_device *dev,
  728. struct drm_crtc *crtc,
  729. struct drm_plane *primary,
  730. void *cursor,
  731. const struct drm_crtc_funcs *funcs);
  732. extern int drm_crtc_init(struct drm_device *dev,
  733. struct drm_crtc *crtc,
  734. const struct drm_crtc_funcs *funcs);
  735. extern void drm_crtc_cleanup(struct drm_crtc *crtc);
  736. extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
  737. /**
  738. * drm_crtc_mask - find the mask of a registered CRTC
  739. * @crtc: CRTC to find mask for
  740. *
  741. * Given a registered CRTC, return the mask bit of that CRTC for an
  742. * encoder's possible_crtcs field.
  743. */
  744. static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
  745. {
  746. return 1 << drm_crtc_index(crtc);
  747. }
  748. extern void drm_connector_ida_init(void);
  749. extern void drm_connector_ida_destroy(void);
  750. extern int drm_connector_init(struct drm_device *dev,
  751. struct drm_connector *connector,
  752. const struct drm_connector_funcs *funcs,
  753. int connector_type);
  754. extern void drm_connector_cleanup(struct drm_connector *connector);
  755. /* helper to unplug all connectors from sysfs for device */
  756. extern void drm_connector_unplug_all(struct drm_device *dev);
  757. extern int drm_bridge_init(struct drm_device *dev, struct drm_bridge *bridge,
  758. const struct drm_bridge_funcs *funcs);
  759. extern void drm_bridge_cleanup(struct drm_bridge *bridge);
  760. extern int drm_encoder_init(struct drm_device *dev,
  761. struct drm_encoder *encoder,
  762. const struct drm_encoder_funcs *funcs,
  763. int encoder_type);
  764. /**
  765. * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
  766. * @encoder: encoder to test
  767. * @crtc: crtc to test
  768. *
  769. * Return false if @encoder can't be driven by @crtc, true otherwise.
  770. */
  771. static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
  772. struct drm_crtc *crtc)
  773. {
  774. return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
  775. }
  776. extern int drm_universal_plane_init(struct drm_device *dev,
  777. struct drm_plane *plane,
  778. unsigned long possible_crtcs,
  779. const struct drm_plane_funcs *funcs,
  780. const uint32_t *formats,
  781. uint32_t format_count,
  782. enum drm_plane_type type);
  783. extern int drm_plane_init(struct drm_device *dev,
  784. struct drm_plane *plane,
  785. unsigned long possible_crtcs,
  786. const struct drm_plane_funcs *funcs,
  787. const uint32_t *formats, uint32_t format_count,
  788. bool is_primary);
  789. extern void drm_plane_cleanup(struct drm_plane *plane);
  790. extern void drm_plane_force_disable(struct drm_plane *plane);
  791. extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
  792. int x, int y,
  793. const struct drm_display_mode *mode,
  794. const struct drm_framebuffer *fb);
  795. extern void drm_encoder_cleanup(struct drm_encoder *encoder);
  796. extern const char *drm_get_connector_name(const struct drm_connector *connector);
  797. extern const char *drm_get_connector_status_name(enum drm_connector_status status);
  798. extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
  799. extern const char *drm_get_dpms_name(int val);
  800. extern const char *drm_get_dvi_i_subconnector_name(int val);
  801. extern const char *drm_get_dvi_i_select_name(int val);
  802. extern const char *drm_get_tv_subconnector_name(int val);
  803. extern const char *drm_get_tv_select_name(int val);
  804. extern void drm_fb_release(struct drm_file *file_priv);
  805. extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
  806. extern bool drm_probe_ddc(struct i2c_adapter *adapter);
  807. extern struct edid *drm_get_edid(struct drm_connector *connector,
  808. struct i2c_adapter *adapter);
  809. extern struct edid *drm_edid_duplicate(const struct edid *edid);
  810. extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
  811. extern void drm_mode_config_init(struct drm_device *dev);
  812. extern void drm_mode_config_reset(struct drm_device *dev);
  813. extern void drm_mode_config_cleanup(struct drm_device *dev);
  814. extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
  815. struct edid *edid);
  816. extern int drm_object_property_set_value(struct drm_mode_object *obj,
  817. struct drm_property *property,
  818. uint64_t val);
  819. extern int drm_object_property_get_value(struct drm_mode_object *obj,
  820. struct drm_property *property,
  821. uint64_t *value);
  822. extern int drm_framebuffer_init(struct drm_device *dev,
  823. struct drm_framebuffer *fb,
  824. const struct drm_framebuffer_funcs *funcs);
  825. extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
  826. uint32_t id);
  827. extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
  828. extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
  829. extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
  830. extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
  831. extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
  832. extern void drm_object_attach_property(struct drm_mode_object *obj,
  833. struct drm_property *property,
  834. uint64_t init_val);
  835. extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
  836. const char *name, int num_values);
  837. extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
  838. const char *name,
  839. const struct drm_prop_enum_list *props,
  840. int num_values);
  841. struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
  842. int flags, const char *name,
  843. const struct drm_prop_enum_list *props,
  844. int num_values);
  845. struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
  846. const char *name,
  847. uint64_t min, uint64_t max);
  848. extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
  849. extern int drm_property_add_enum(struct drm_property *property, int index,
  850. uint64_t value, const char *name);
  851. extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
  852. extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
  853. char *formats[]);
  854. extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
  855. extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
  856. extern const char *drm_get_encoder_name(const struct drm_encoder *encoder);
  857. extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
  858. struct drm_encoder *encoder);
  859. extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
  860. int gamma_size);
  861. extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
  862. uint32_t id, uint32_t type);
  863. /* IOCTLs */
  864. extern int drm_mode_getresources(struct drm_device *dev,
  865. void *data, struct drm_file *file_priv);
  866. extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
  867. struct drm_file *file_priv);
  868. extern int drm_mode_getcrtc(struct drm_device *dev,
  869. void *data, struct drm_file *file_priv);
  870. extern int drm_mode_getconnector(struct drm_device *dev,
  871. void *data, struct drm_file *file_priv);
  872. extern int drm_mode_set_config_internal(struct drm_mode_set *set);
  873. extern int drm_mode_setcrtc(struct drm_device *dev,
  874. void *data, struct drm_file *file_priv);
  875. extern int drm_mode_getplane(struct drm_device *dev,
  876. void *data, struct drm_file *file_priv);
  877. extern int drm_mode_setplane(struct drm_device *dev,
  878. void *data, struct drm_file *file_priv);
  879. extern int drm_mode_cursor_ioctl(struct drm_device *dev,
  880. void *data, struct drm_file *file_priv);
  881. extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
  882. void *data, struct drm_file *file_priv);
  883. extern int drm_mode_addfb(struct drm_device *dev,
  884. void *data, struct drm_file *file_priv);
  885. extern int drm_mode_addfb2(struct drm_device *dev,
  886. void *data, struct drm_file *file_priv);
  887. extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
  888. extern int drm_mode_rmfb(struct drm_device *dev,
  889. void *data, struct drm_file *file_priv);
  890. extern int drm_mode_getfb(struct drm_device *dev,
  891. void *data, struct drm_file *file_priv);
  892. extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
  893. void *data, struct drm_file *file_priv);
  894. extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
  895. void *data, struct drm_file *file_priv);
  896. extern int drm_mode_getblob_ioctl(struct drm_device *dev,
  897. void *data, struct drm_file *file_priv);
  898. extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
  899. void *data, struct drm_file *file_priv);
  900. extern int drm_mode_getencoder(struct drm_device *dev,
  901. void *data, struct drm_file *file_priv);
  902. extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
  903. void *data, struct drm_file *file_priv);
  904. extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
  905. void *data, struct drm_file *file_priv);
  906. extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
  907. extern bool drm_detect_hdmi_monitor(struct edid *edid);
  908. extern bool drm_detect_monitor_audio(struct edid *edid);
  909. extern bool drm_rgb_quant_range_selectable(struct edid *edid);
  910. extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
  911. void *data, struct drm_file *file_priv);
  912. extern int drm_add_modes_noedid(struct drm_connector *connector,
  913. int hdisplay, int vdisplay);
  914. extern void drm_set_preferred_mode(struct drm_connector *connector,
  915. int hpref, int vpref);
  916. extern int drm_edid_header_is_valid(const u8 *raw_edid);
  917. extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid);
  918. extern bool drm_edid_is_valid(struct edid *edid);
  919. struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
  920. int hsize, int vsize, int fresh,
  921. bool rb);
  922. extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
  923. void *data, struct drm_file *file_priv);
  924. extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
  925. void *data, struct drm_file *file_priv);
  926. extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
  927. void *data, struct drm_file *file_priv);
  928. extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
  929. struct drm_file *file_priv);
  930. extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
  931. struct drm_file *file_priv);
  932. extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
  933. int *bpp);
  934. extern int drm_format_num_planes(uint32_t format);
  935. extern int drm_format_plane_cpp(uint32_t format, int plane);
  936. extern int drm_format_horz_chroma_subsampling(uint32_t format);
  937. extern int drm_format_vert_chroma_subsampling(uint32_t format);
  938. extern const char *drm_get_format_name(uint32_t format);
  939. /* Helpers */
  940. static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
  941. uint32_t id)
  942. {
  943. struct drm_mode_object *mo;
  944. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
  945. return mo ? obj_to_crtc(mo) : NULL;
  946. }
  947. static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
  948. uint32_t id)
  949. {
  950. struct drm_mode_object *mo;
  951. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
  952. return mo ? obj_to_encoder(mo) : NULL;
  953. }
  954. /* Plane list iterator for legacy (overlay only) planes. */
  955. #define drm_for_each_legacy_plane(plane, planelist) \
  956. list_for_each_entry(plane, planelist, head) \
  957. if (plane->type == DRM_PLANE_TYPE_OVERLAY)
  958. #endif /* __DRM_CRTC_H__ */