drm_crtc.h 42 KB

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