drm_crtc.h 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  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 24
  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. * @save: save CRTC state
  262. * @restore: restore CRTC state
  263. * @reset: reset CRTC after state has been invalidate (e.g. resume)
  264. * @cursor_set: setup the cursor
  265. * @cursor_move: move the cursor
  266. * @gamma_set: specify color ramp for CRTC
  267. * @destroy: deinit and free object
  268. * @set_property: called when a property is changed
  269. * @set_config: apply a new CRTC configuration
  270. * @page_flip: initiate a page flip
  271. *
  272. * The drm_crtc_funcs structure is the central CRTC management structure
  273. * in the DRM. Each CRTC controls one or more connectors (note that the name
  274. * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
  275. * connectors, not just CRTs).
  276. *
  277. * Each driver is responsible for filling out this structure at startup time,
  278. * in addition to providing other modesetting features, like i2c and DDC
  279. * bus accessors.
  280. */
  281. struct drm_crtc_funcs {
  282. /* Save CRTC state */
  283. void (*save)(struct drm_crtc *crtc); /* suspend? */
  284. /* Restore CRTC state */
  285. void (*restore)(struct drm_crtc *crtc); /* resume? */
  286. /* Reset CRTC state */
  287. void (*reset)(struct drm_crtc *crtc);
  288. /* cursor controls */
  289. int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
  290. uint32_t handle, uint32_t width, uint32_t height);
  291. int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
  292. /* Set gamma on the CRTC */
  293. void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  294. uint32_t start, uint32_t size);
  295. /* Object destroy routine */
  296. void (*destroy)(struct drm_crtc *crtc);
  297. int (*set_config)(struct drm_mode_set *set);
  298. /*
  299. * Flip to the given framebuffer. This implements the page
  300. * flip ioctl described in drm_mode.h, specifically, the
  301. * implementation must return immediately and block all
  302. * rendering to the current fb until the flip has completed.
  303. * If userspace set the event flag in the ioctl, the event
  304. * argument will point to an event to send back when the flip
  305. * completes, otherwise it will be NULL.
  306. */
  307. int (*page_flip)(struct drm_crtc *crtc,
  308. struct drm_framebuffer *fb,
  309. struct drm_pending_vblank_event *event);
  310. int (*set_property)(struct drm_crtc *crtc,
  311. struct drm_property *property, uint64_t val);
  312. };
  313. /**
  314. * drm_crtc - central CRTC control structure
  315. * @dev: parent DRM device
  316. * @head: list management
  317. * @base: base KMS object for ID tracking etc.
  318. * @enabled: is this CRTC enabled?
  319. * @mode: current mode timings
  320. * @hwmode: mode timings as programmed to hw regs
  321. * @x: x position on screen
  322. * @y: y position on screen
  323. * @funcs: CRTC control functions
  324. * @gamma_size: size of gamma ramp
  325. * @gamma_store: gamma ramp values
  326. * @framedur_ns: precise frame timing
  327. * @framedur_ns: precise line timing
  328. * @pixeldur_ns: precise pixel timing
  329. * @helper_private: mid-layer private data
  330. * @properties: property tracking for this CRTC
  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. struct drm_object_properties properties;
  358. };
  359. /**
  360. * drm_connector_funcs - control connectors on a given device
  361. * @dpms: set power state (see drm_crtc_funcs above)
  362. * @save: save connector state
  363. * @restore: restore connector state
  364. * @reset: reset connector after state has been invalidate (e.g. resume)
  365. * @detect: is this connector active?
  366. * @fill_modes: fill mode list for this connector
  367. * @set_property: property for this connector may need update
  368. * @destroy: make object go away
  369. * @force: notify the driver the connector is forced on
  370. *
  371. * Each CRTC may have one or more connectors attached to it. The functions
  372. * below allow the core DRM code to control connectors, enumerate available modes,
  373. * etc.
  374. */
  375. struct drm_connector_funcs {
  376. void (*dpms)(struct drm_connector *connector, int mode);
  377. void (*save)(struct drm_connector *connector);
  378. void (*restore)(struct drm_connector *connector);
  379. void (*reset)(struct drm_connector *connector);
  380. /* Check to see if anything is attached to the connector.
  381. * @force is set to false whilst polling, true when checking the
  382. * connector due to user request. @force can be used by the driver
  383. * to avoid expensive, destructive operations during automated
  384. * probing.
  385. */
  386. enum drm_connector_status (*detect)(struct drm_connector *connector,
  387. bool force);
  388. int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
  389. int (*set_property)(struct drm_connector *connector, struct drm_property *property,
  390. uint64_t val);
  391. void (*destroy)(struct drm_connector *connector);
  392. void (*force)(struct drm_connector *connector);
  393. };
  394. /**
  395. * drm_encoder_funcs - encoder controls
  396. * @reset: reset state (e.g. at init or resume time)
  397. * @destroy: cleanup and free associated data
  398. *
  399. * Encoders sit between CRTCs and connectors.
  400. */
  401. struct drm_encoder_funcs {
  402. void (*reset)(struct drm_encoder *encoder);
  403. void (*destroy)(struct drm_encoder *encoder);
  404. };
  405. #define DRM_CONNECTOR_MAX_UMODES 16
  406. #define DRM_CONNECTOR_LEN 32
  407. #define DRM_CONNECTOR_MAX_ENCODER 3
  408. /**
  409. * drm_encoder - central DRM encoder structure
  410. * @dev: parent DRM device
  411. * @head: list management
  412. * @base: base KMS object
  413. * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
  414. * @possible_crtcs: bitmask of potential CRTC bindings
  415. * @possible_clones: bitmask of potential sibling encoders for cloning
  416. * @crtc: currently bound CRTC
  417. * @funcs: control functions
  418. * @helper_private: mid-layer private data
  419. *
  420. * CRTCs drive pixels to encoders, which convert them into signals
  421. * appropriate for a given connector or set of connectors.
  422. */
  423. struct drm_encoder {
  424. struct drm_device *dev;
  425. struct list_head head;
  426. struct drm_mode_object base;
  427. int encoder_type;
  428. uint32_t possible_crtcs;
  429. uint32_t possible_clones;
  430. struct drm_crtc *crtc;
  431. const struct drm_encoder_funcs *funcs;
  432. void *helper_private;
  433. };
  434. enum drm_connector_force {
  435. DRM_FORCE_UNSPECIFIED,
  436. DRM_FORCE_OFF,
  437. DRM_FORCE_ON, /* force on analog part normally */
  438. DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
  439. };
  440. /* should we poll this connector for connects and disconnects */
  441. /* hot plug detectable */
  442. #define DRM_CONNECTOR_POLL_HPD (1 << 0)
  443. /* poll for connections */
  444. #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
  445. /* can cleanly poll for disconnections without flickering the screen */
  446. /* DACs should rarely do this without a lot of testing */
  447. #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
  448. #define MAX_ELD_BYTES 128
  449. /**
  450. * drm_connector - central DRM connector control structure
  451. * @dev: parent DRM device
  452. * @kdev: kernel device for sysfs attributes
  453. * @attr: sysfs attributes
  454. * @head: list management
  455. * @base: base KMS object
  456. * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
  457. * @connector_type_id: index into connector type enum
  458. * @interlace_allowed: can this connector handle interlaced modes?
  459. * @doublescan_allowed: can this connector handle doublescan?
  460. * @modes: modes available on this connector (from fill_modes() + user)
  461. * @status: one of the drm_connector_status enums (connected, not, or unknown)
  462. * @probed_modes: list of modes derived directly from the display
  463. * @display_info: information about attached display (e.g. from EDID)
  464. * @funcs: connector control functions
  465. * @user_modes: user added mode list
  466. * @edid_blob_ptr: DRM property containing EDID if present
  467. * @properties: property tracking for this connector
  468. * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
  469. * @dpms: current dpms state
  470. * @helper_private: mid-layer private data
  471. * @force: a %DRM_FORCE_<foo> state for forced mode sets
  472. * @encoder_ids: valid encoders for this connector
  473. * @encoder: encoder driving this connector, if any
  474. * @eld: EDID-like data, if present
  475. * @dvi_dual: dual link DVI, if found
  476. * @max_tmds_clock: max clock rate, if found
  477. * @latency_present: AV delay info from ELD, if found
  478. * @video_latency: video latency info from ELD, if found
  479. * @audio_latency: audio latency info from ELD, if found
  480. * @null_edid_counter: track sinks that give us all zeros for the EDID
  481. *
  482. * Each connector may be connected to one or more CRTCs, or may be clonable by
  483. * another connector if they can share a CRTC. Each connector also has a specific
  484. * position in the broader display (referred to as a 'screen' though it could
  485. * span multiple monitors).
  486. */
  487. struct drm_connector {
  488. struct drm_device *dev;
  489. struct device kdev;
  490. struct device_attribute *attr;
  491. struct list_head head;
  492. struct drm_mode_object base;
  493. int connector_type;
  494. int connector_type_id;
  495. bool interlace_allowed;
  496. bool doublescan_allowed;
  497. struct list_head modes; /* list of modes on this connector */
  498. enum drm_connector_status status;
  499. /* these are modes added by probing with DDC or the BIOS */
  500. struct list_head probed_modes;
  501. struct drm_display_info display_info;
  502. const struct drm_connector_funcs *funcs;
  503. struct list_head user_modes;
  504. struct drm_property_blob *edid_blob_ptr;
  505. struct drm_object_properties properties;
  506. uint8_t polled; /* DRM_CONNECTOR_POLL_* */
  507. /* requested DPMS state */
  508. int dpms;
  509. void *helper_private;
  510. /* forced on connector */
  511. enum drm_connector_force force;
  512. uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
  513. struct drm_encoder *encoder; /* currently active encoder */
  514. /* EDID bits */
  515. uint8_t eld[MAX_ELD_BYTES];
  516. bool dvi_dual;
  517. int max_tmds_clock; /* in MHz */
  518. bool latency_present[2];
  519. int video_latency[2]; /* [0]: progressive, [1]: interlaced */
  520. int audio_latency[2];
  521. int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
  522. };
  523. /**
  524. * drm_plane_funcs - driver plane control functions
  525. * @update_plane: update the plane configuration
  526. * @disable_plane: shut down the plane
  527. * @destroy: clean up plane resources
  528. * @set_property: called when a property is changed
  529. */
  530. struct drm_plane_funcs {
  531. int (*update_plane)(struct drm_plane *plane,
  532. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  533. int crtc_x, int crtc_y,
  534. unsigned int crtc_w, unsigned int crtc_h,
  535. uint32_t src_x, uint32_t src_y,
  536. uint32_t src_w, uint32_t src_h);
  537. int (*disable_plane)(struct drm_plane *plane);
  538. void (*destroy)(struct drm_plane *plane);
  539. int (*set_property)(struct drm_plane *plane,
  540. struct drm_property *property, uint64_t val);
  541. };
  542. /**
  543. * drm_plane - central DRM plane control structure
  544. * @dev: DRM device this plane belongs to
  545. * @head: for list management
  546. * @base: base mode object
  547. * @possible_crtcs: pipes this plane can be bound to
  548. * @format_types: array of formats supported by this plane
  549. * @format_count: number of formats supported
  550. * @crtc: currently bound CRTC
  551. * @fb: currently bound fb
  552. * @gamma_size: size of gamma table
  553. * @gamma_store: gamma correction table
  554. * @enabled: enabled flag
  555. * @funcs: helper functions
  556. * @helper_private: storage for drver layer
  557. * @properties: property tracking for this plane
  558. */
  559. struct drm_plane {
  560. struct drm_device *dev;
  561. struct list_head head;
  562. struct drm_mode_object base;
  563. uint32_t possible_crtcs;
  564. uint32_t *format_types;
  565. uint32_t format_count;
  566. struct drm_crtc *crtc;
  567. struct drm_framebuffer *fb;
  568. /* CRTC gamma size for reporting to userspace */
  569. uint32_t gamma_size;
  570. uint16_t *gamma_store;
  571. bool enabled;
  572. const struct drm_plane_funcs *funcs;
  573. void *helper_private;
  574. struct drm_object_properties properties;
  575. };
  576. /**
  577. * drm_mode_set - new values for a CRTC config change
  578. * @head: list management
  579. * @fb: framebuffer to use for new config
  580. * @crtc: CRTC whose configuration we're about to change
  581. * @mode: mode timings to use
  582. * @x: position of this CRTC relative to @fb
  583. * @y: position of this CRTC relative to @fb
  584. * @connectors: array of connectors to drive with this CRTC if possible
  585. * @num_connectors: size of @connectors array
  586. *
  587. * Represents a single crtc the connectors that it drives with what mode
  588. * and from which framebuffer it scans out from.
  589. *
  590. * This is used to set modes.
  591. */
  592. struct drm_mode_set {
  593. struct drm_framebuffer *fb;
  594. struct drm_crtc *crtc;
  595. struct drm_display_mode *mode;
  596. uint32_t x;
  597. uint32_t y;
  598. struct drm_connector **connectors;
  599. size_t num_connectors;
  600. };
  601. /**
  602. * struct drm_mode_config_funcs - basic driver provided mode setting functions
  603. * @fb_create: create a new framebuffer object
  604. * @output_poll_changed: function to handle output configuration changes
  605. *
  606. * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
  607. * involve drivers.
  608. */
  609. struct drm_mode_config_funcs {
  610. struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
  611. struct drm_file *file_priv,
  612. struct drm_mode_fb_cmd2 *mode_cmd);
  613. void (*output_poll_changed)(struct drm_device *dev);
  614. };
  615. /**
  616. * drm_mode_group - group of mode setting resources for potential sub-grouping
  617. * @num_crtcs: CRTC count
  618. * @num_encoders: encoder count
  619. * @num_connectors: connector count
  620. * @id_list: list of KMS object IDs in this group
  621. *
  622. * Currently this simply tracks the global mode setting state. But in the
  623. * future it could allow groups of objects to be set aside into independent
  624. * control groups for use by different user level processes (e.g. two X servers
  625. * running simultaneously on different heads, each with their own mode
  626. * configuration and freedom of mode setting).
  627. */
  628. struct drm_mode_group {
  629. uint32_t num_crtcs;
  630. uint32_t num_encoders;
  631. uint32_t num_connectors;
  632. /* list of object IDs for this group */
  633. uint32_t *id_list;
  634. };
  635. /**
  636. * drm_mode_config - Mode configuration control structure
  637. * @mutex: mutex protecting KMS related lists and structures
  638. * @idr_mutex: mutex for KMS ID allocation and management
  639. * @crtc_idr: main KMS ID tracking object
  640. * @num_fb: number of fbs available
  641. * @fb_list: list of framebuffers available
  642. * @num_connector: number of connectors on this device
  643. * @connector_list: list of connector objects
  644. * @num_encoder: number of encoders on this device
  645. * @encoder_list: list of encoder objects
  646. * @num_crtc: number of CRTCs on this device
  647. * @crtc_list: list of CRTC objects
  648. * @min_width: minimum pixel width on this device
  649. * @min_height: minimum pixel height on this device
  650. * @max_width: maximum pixel width on this device
  651. * @max_height: maximum pixel height on this device
  652. * @funcs: core driver provided mode setting functions
  653. * @fb_base: base address of the framebuffer
  654. * @poll_enabled: track polling status for this device
  655. * @output_poll_work: delayed work for polling in process context
  656. * @*_property: core property tracking
  657. *
  658. * Core mode resource tracking structure. All CRTC, encoders, and connectors
  659. * enumerated by the driver are added here, as are global properties. Some
  660. * global restrictions are also here, e.g. dimension restrictions.
  661. */
  662. struct drm_mode_config {
  663. struct mutex mutex; /* protects configuration (mode lists etc.) */
  664. struct mutex idr_mutex; /* for IDR management */
  665. struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
  666. /* this is limited to one for now */
  667. int num_fb;
  668. struct list_head fb_list;
  669. int num_connector;
  670. struct list_head connector_list;
  671. int num_encoder;
  672. struct list_head encoder_list;
  673. int num_plane;
  674. struct list_head plane_list;
  675. int num_crtc;
  676. struct list_head crtc_list;
  677. struct list_head property_list;
  678. int min_width, min_height;
  679. int max_width, max_height;
  680. const struct drm_mode_config_funcs *funcs;
  681. resource_size_t fb_base;
  682. /* output poll support */
  683. bool poll_enabled;
  684. struct delayed_work output_poll_work;
  685. /* pointers to standard properties */
  686. struct list_head property_blob_list;
  687. struct drm_property *edid_property;
  688. struct drm_property *dpms_property;
  689. /* DVI-I properties */
  690. struct drm_property *dvi_i_subconnector_property;
  691. struct drm_property *dvi_i_select_subconnector_property;
  692. /* TV properties */
  693. struct drm_property *tv_subconnector_property;
  694. struct drm_property *tv_select_subconnector_property;
  695. struct drm_property *tv_mode_property;
  696. struct drm_property *tv_left_margin_property;
  697. struct drm_property *tv_right_margin_property;
  698. struct drm_property *tv_top_margin_property;
  699. struct drm_property *tv_bottom_margin_property;
  700. struct drm_property *tv_brightness_property;
  701. struct drm_property *tv_contrast_property;
  702. struct drm_property *tv_flicker_reduction_property;
  703. struct drm_property *tv_overscan_property;
  704. struct drm_property *tv_saturation_property;
  705. struct drm_property *tv_hue_property;
  706. /* Optional properties */
  707. struct drm_property *scaling_mode_property;
  708. struct drm_property *dithering_mode_property;
  709. struct drm_property *dirty_info_property;
  710. /* dumb ioctl parameters */
  711. uint32_t preferred_depth, prefer_shadow;
  712. };
  713. #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
  714. #define obj_to_connector(x) container_of(x, struct drm_connector, base)
  715. #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
  716. #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
  717. #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
  718. #define obj_to_property(x) container_of(x, struct drm_property, base)
  719. #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
  720. #define obj_to_plane(x) container_of(x, struct drm_plane, base)
  721. struct drm_prop_enum_list {
  722. int type;
  723. char *name;
  724. };
  725. extern int drm_crtc_init(struct drm_device *dev,
  726. struct drm_crtc *crtc,
  727. const struct drm_crtc_funcs *funcs);
  728. extern void drm_crtc_cleanup(struct drm_crtc *crtc);
  729. extern int drm_connector_init(struct drm_device *dev,
  730. struct drm_connector *connector,
  731. const struct drm_connector_funcs *funcs,
  732. int connector_type);
  733. extern void drm_connector_cleanup(struct drm_connector *connector);
  734. /* helper to unplug all connectors from sysfs for device */
  735. extern void drm_connector_unplug_all(struct drm_device *dev);
  736. extern int drm_encoder_init(struct drm_device *dev,
  737. struct drm_encoder *encoder,
  738. const struct drm_encoder_funcs *funcs,
  739. int encoder_type);
  740. extern int drm_plane_init(struct drm_device *dev,
  741. struct drm_plane *plane,
  742. unsigned long possible_crtcs,
  743. const struct drm_plane_funcs *funcs,
  744. const uint32_t *formats, uint32_t format_count,
  745. bool priv);
  746. extern void drm_plane_cleanup(struct drm_plane *plane);
  747. extern void drm_encoder_cleanup(struct drm_encoder *encoder);
  748. extern char *drm_get_connector_name(struct drm_connector *connector);
  749. extern char *drm_get_dpms_name(int val);
  750. extern char *drm_get_dvi_i_subconnector_name(int val);
  751. extern char *drm_get_dvi_i_select_name(int val);
  752. extern char *drm_get_tv_subconnector_name(int val);
  753. extern char *drm_get_tv_select_name(int val);
  754. extern void drm_fb_release(struct drm_file *file_priv);
  755. extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
  756. extern struct edid *drm_get_edid(struct drm_connector *connector,
  757. struct i2c_adapter *adapter);
  758. extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
  759. extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
  760. extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode);
  761. extern void drm_mode_copy(struct drm_display_mode *dst, const struct drm_display_mode *src);
  762. extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
  763. const struct drm_display_mode *mode);
  764. extern void drm_mode_debug_printmodeline(struct drm_display_mode *mode);
  765. extern void drm_mode_config_init(struct drm_device *dev);
  766. extern void drm_mode_config_reset(struct drm_device *dev);
  767. extern void drm_mode_config_cleanup(struct drm_device *dev);
  768. extern void drm_mode_set_name(struct drm_display_mode *mode);
  769. extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
  770. extern int drm_mode_width(struct drm_display_mode *mode);
  771. extern int drm_mode_height(struct drm_display_mode *mode);
  772. /* for us by fb module */
  773. extern int drm_mode_attachmode_crtc(struct drm_device *dev,
  774. struct drm_crtc *crtc,
  775. const struct drm_display_mode *mode);
  776. extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
  777. extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
  778. extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
  779. extern void drm_mode_list_concat(struct list_head *head,
  780. struct list_head *new);
  781. extern void drm_mode_validate_size(struct drm_device *dev,
  782. struct list_head *mode_list,
  783. int maxX, int maxY, int maxPitch);
  784. extern void drm_mode_prune_invalid(struct drm_device *dev,
  785. struct list_head *mode_list, bool verbose);
  786. extern void drm_mode_sort(struct list_head *mode_list);
  787. extern int drm_mode_hsync(const struct drm_display_mode *mode);
  788. extern int drm_mode_vrefresh(const struct drm_display_mode *mode);
  789. extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
  790. int adjust_flags);
  791. extern void drm_mode_connector_list_update(struct drm_connector *connector);
  792. extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
  793. struct edid *edid);
  794. extern int drm_connector_property_set_value(struct drm_connector *connector,
  795. struct drm_property *property,
  796. uint64_t value);
  797. extern int drm_connector_property_get_value(struct drm_connector *connector,
  798. struct drm_property *property,
  799. uint64_t *value);
  800. extern int drm_object_property_set_value(struct drm_mode_object *obj,
  801. struct drm_property *property,
  802. uint64_t val);
  803. extern int drm_object_property_get_value(struct drm_mode_object *obj,
  804. struct drm_property *property,
  805. uint64_t *value);
  806. extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
  807. extern void drm_framebuffer_set_object(struct drm_device *dev,
  808. unsigned long handle);
  809. extern int drm_framebuffer_init(struct drm_device *dev,
  810. struct drm_framebuffer *fb,
  811. const struct drm_framebuffer_funcs *funcs);
  812. extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
  813. extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
  814. extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
  815. extern void drm_crtc_probe_connector_modes(struct drm_device *dev, int maxX, int maxY);
  816. extern bool drm_crtc_in_use(struct drm_crtc *crtc);
  817. extern void drm_connector_attach_property(struct drm_connector *connector,
  818. struct drm_property *property, uint64_t init_val);
  819. extern void drm_object_attach_property(struct drm_mode_object *obj,
  820. struct drm_property *property,
  821. uint64_t init_val);
  822. extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
  823. const char *name, int num_values);
  824. extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
  825. const char *name,
  826. const struct drm_prop_enum_list *props,
  827. int num_values);
  828. struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
  829. int flags, const char *name,
  830. const struct drm_prop_enum_list *props,
  831. int num_values);
  832. struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
  833. const char *name,
  834. uint64_t min, uint64_t max);
  835. extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
  836. extern int drm_property_add_enum(struct drm_property *property, int index,
  837. uint64_t value, const char *name);
  838. extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
  839. extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
  840. char *formats[]);
  841. extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
  842. extern int drm_mode_create_dithering_property(struct drm_device *dev);
  843. extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
  844. extern char *drm_get_encoder_name(struct drm_encoder *encoder);
  845. extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
  846. struct drm_encoder *encoder);
  847. extern void drm_mode_connector_detach_encoder(struct drm_connector *connector,
  848. struct drm_encoder *encoder);
  849. extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
  850. int gamma_size);
  851. extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
  852. uint32_t id, uint32_t type);
  853. /* IOCTLs */
  854. extern int drm_mode_getresources(struct drm_device *dev,
  855. void *data, struct drm_file *file_priv);
  856. extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
  857. struct drm_file *file_priv);
  858. extern int drm_mode_getcrtc(struct drm_device *dev,
  859. void *data, struct drm_file *file_priv);
  860. extern int drm_mode_getconnector(struct drm_device *dev,
  861. void *data, struct drm_file *file_priv);
  862. extern int drm_mode_setcrtc(struct drm_device *dev,
  863. void *data, struct drm_file *file_priv);
  864. extern int drm_mode_getplane(struct drm_device *dev,
  865. void *data, struct drm_file *file_priv);
  866. extern int drm_mode_setplane(struct drm_device *dev,
  867. void *data, struct drm_file *file_priv);
  868. extern int drm_mode_cursor_ioctl(struct drm_device *dev,
  869. void *data, struct drm_file *file_priv);
  870. extern int drm_mode_addfb(struct drm_device *dev,
  871. void *data, struct drm_file *file_priv);
  872. extern int drm_mode_addfb2(struct drm_device *dev,
  873. void *data, struct drm_file *file_priv);
  874. extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
  875. extern int drm_mode_rmfb(struct drm_device *dev,
  876. void *data, struct drm_file *file_priv);
  877. extern int drm_mode_getfb(struct drm_device *dev,
  878. void *data, struct drm_file *file_priv);
  879. extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
  880. void *data, struct drm_file *file_priv);
  881. extern int drm_mode_addmode_ioctl(struct drm_device *dev,
  882. void *data, struct drm_file *file_priv);
  883. extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
  884. void *data, struct drm_file *file_priv);
  885. extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
  886. void *data, struct drm_file *file_priv);
  887. extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
  888. void *data, struct drm_file *file_priv);
  889. extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
  890. void *data, struct drm_file *file_priv);
  891. extern int drm_mode_getblob_ioctl(struct drm_device *dev,
  892. void *data, struct drm_file *file_priv);
  893. extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
  894. void *data, struct drm_file *file_priv);
  895. extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
  896. void *data, struct drm_file *file_priv);
  897. extern int drm_mode_replacefb(struct drm_device *dev,
  898. void *data, struct drm_file *file_priv);
  899. extern int drm_mode_getencoder(struct drm_device *dev,
  900. void *data, struct drm_file *file_priv);
  901. extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
  902. void *data, struct drm_file *file_priv);
  903. extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
  904. void *data, struct drm_file *file_priv);
  905. extern u8 *drm_find_cea_extension(struct edid *edid);
  906. extern bool drm_detect_hdmi_monitor(struct edid *edid);
  907. extern bool drm_detect_monitor_audio(struct edid *edid);
  908. extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
  909. void *data, struct drm_file *file_priv);
  910. extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
  911. int hdisplay, int vdisplay, int vrefresh,
  912. bool reduced, bool interlaced, bool margins);
  913. extern struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
  914. int hdisplay, int vdisplay, int vrefresh,
  915. bool interlaced, int margins);
  916. extern struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
  917. int hdisplay, int vdisplay, int vrefresh,
  918. bool interlaced, int margins, int GTF_M,
  919. int GTF_2C, int GTF_K, int GTF_2J);
  920. extern int drm_add_modes_noedid(struct drm_connector *connector,
  921. int hdisplay, int vdisplay);
  922. extern int drm_edid_header_is_valid(const u8 *raw_edid);
  923. extern bool drm_edid_block_valid(u8 *raw_edid, int block);
  924. extern bool drm_edid_is_valid(struct edid *edid);
  925. struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
  926. int hsize, int vsize, int fresh,
  927. bool rb);
  928. extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
  929. void *data, struct drm_file *file_priv);
  930. extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
  931. void *data, struct drm_file *file_priv);
  932. extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
  933. void *data, struct drm_file *file_priv);
  934. extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
  935. struct drm_file *file_priv);
  936. extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
  937. struct drm_file *file_priv);
  938. extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
  939. int *bpp);
  940. extern int drm_format_num_planes(uint32_t format);
  941. extern int drm_format_plane_cpp(uint32_t format, int plane);
  942. extern int drm_format_horz_chroma_subsampling(uint32_t format);
  943. extern int drm_format_vert_chroma_subsampling(uint32_t format);
  944. #endif /* __DRM_CRTC_H__ */