drm_crtc.h 37 KB

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