drm_crtc.h 37 KB

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