drm_crtc.h 41 KB

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