drm_crtc.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  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. 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 pitch;
  214. unsigned int width;
  215. unsigned int height;
  216. /* depth can be 15 or 16 */
  217. unsigned int depth;
  218. int bits_per_pixel;
  219. int flags;
  220. uint32_t pixel_format; /* fourcc format */
  221. struct list_head filp_head;
  222. /* if you are using the helper */
  223. void *helper_private;
  224. };
  225. struct drm_property_blob {
  226. struct drm_mode_object base;
  227. struct list_head head;
  228. unsigned int length;
  229. void *data;
  230. };
  231. struct drm_property_enum {
  232. uint64_t value;
  233. struct list_head head;
  234. char name[DRM_PROP_NAME_LEN];
  235. };
  236. struct drm_property {
  237. struct list_head head;
  238. struct drm_mode_object base;
  239. uint32_t flags;
  240. char name[DRM_PROP_NAME_LEN];
  241. uint32_t num_values;
  242. uint64_t *values;
  243. struct list_head enum_blob_list;
  244. };
  245. struct drm_crtc;
  246. struct drm_connector;
  247. struct drm_encoder;
  248. struct drm_pending_vblank_event;
  249. struct drm_plane;
  250. /**
  251. * drm_crtc_funcs - control CRTCs for a given device
  252. * @reset: reset CRTC after state has been invalidate (e.g. resume)
  253. * @dpms: control display power levels
  254. * @save: save CRTC state
  255. * @resore: restore CRTC state
  256. * @lock: lock the CRTC
  257. * @unlock: unlock the CRTC
  258. * @shadow_allocate: allocate shadow pixmap
  259. * @shadow_create: create shadow pixmap for rotation support
  260. * @shadow_destroy: free shadow pixmap
  261. * @mode_fixup: fixup proposed mode
  262. * @mode_set: set the desired mode on the CRTC
  263. * @gamma_set: specify color ramp for CRTC
  264. * @destroy: deinit and free object.
  265. *
  266. * The drm_crtc_funcs structure is the central CRTC management structure
  267. * in the DRM. Each CRTC controls one or more connectors (note that the name
  268. * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
  269. * connectors, not just CRTs).
  270. *
  271. * Each driver is responsible for filling out this structure at startup time,
  272. * in addition to providing other modesetting features, like i2c and DDC
  273. * bus accessors.
  274. */
  275. struct drm_crtc_funcs {
  276. /* Save CRTC state */
  277. void (*save)(struct drm_crtc *crtc); /* suspend? */
  278. /* Restore CRTC state */
  279. void (*restore)(struct drm_crtc *crtc); /* resume? */
  280. /* Reset CRTC state */
  281. void (*reset)(struct drm_crtc *crtc);
  282. /* cursor controls */
  283. int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
  284. uint32_t handle, uint32_t width, uint32_t height);
  285. int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
  286. /* Set gamma on the CRTC */
  287. void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  288. uint32_t start, uint32_t size);
  289. /* Object destroy routine */
  290. void (*destroy)(struct drm_crtc *crtc);
  291. int (*set_config)(struct drm_mode_set *set);
  292. /*
  293. * Flip to the given framebuffer. This implements the page
  294. * flip ioctl described in drm_mode.h, specifically, the
  295. * implementation must return immediately and block all
  296. * rendering to the current fb until the flip has completed.
  297. * If userspace set the event flag in the ioctl, the event
  298. * argument will point to an event to send back when the flip
  299. * completes, otherwise it will be NULL.
  300. */
  301. int (*page_flip)(struct drm_crtc *crtc,
  302. struct drm_framebuffer *fb,
  303. struct drm_pending_vblank_event *event);
  304. };
  305. /**
  306. * drm_crtc - central CRTC control structure
  307. * @dev: parent DRM device
  308. * @head: list management
  309. * @base: base KMS object for ID tracking etc.
  310. * @enabled: is this CRTC enabled?
  311. * @mode: current mode timings
  312. * @hwmode: mode timings as programmed to hw regs
  313. * @x: x position on screen
  314. * @y: y position on screen
  315. * @funcs: CRTC control functions
  316. * @gamma_size: size of gamma ramp
  317. * @gamma_store: gamma ramp values
  318. * @framedur_ns: precise frame timing
  319. * @framedur_ns: precise line timing
  320. * @pixeldur_ns: precise pixel timing
  321. * @helper_private: mid-layer private data
  322. *
  323. * Each CRTC may have one or more connectors associated with it. This structure
  324. * allows the CRTC to be controlled.
  325. */
  326. struct drm_crtc {
  327. struct drm_device *dev;
  328. struct list_head head;
  329. struct drm_mode_object base;
  330. /* framebuffer the connector is currently bound to */
  331. struct drm_framebuffer *fb;
  332. bool enabled;
  333. /* Requested mode from modesetting. */
  334. struct drm_display_mode mode;
  335. /* Programmed mode in hw, after adjustments for encoders,
  336. * crtc, panel scaling etc. Needed for timestamping etc.
  337. */
  338. struct drm_display_mode hwmode;
  339. int x, y;
  340. const struct drm_crtc_funcs *funcs;
  341. /* CRTC gamma size for reporting to userspace */
  342. uint32_t gamma_size;
  343. uint16_t *gamma_store;
  344. /* Constants needed for precise vblank and swap timestamping. */
  345. s64 framedur_ns, linedur_ns, pixeldur_ns;
  346. /* if you are using the helper */
  347. void *helper_private;
  348. };
  349. /**
  350. * drm_connector_funcs - control connectors on a given device
  351. * @dpms: set power state (see drm_crtc_funcs above)
  352. * @save: save connector state
  353. * @restore: restore connector state
  354. * @reset: reset connector after state has been invalidate (e.g. resume)
  355. * @mode_valid: is this mode valid on the given connector?
  356. * @mode_fixup: try to fixup proposed mode for this connector
  357. * @mode_set: set this mode
  358. * @detect: is this connector active?
  359. * @get_modes: get mode list for this connector
  360. * @set_property: property for this connector may need update
  361. * @destroy: make object go away
  362. * @force: notify the driver the connector is forced on
  363. *
  364. * Each CRTC may have one or more connectors attached to it. The functions
  365. * below allow the core DRM code to control connectors, enumerate available modes,
  366. * etc.
  367. */
  368. struct drm_connector_funcs {
  369. void (*dpms)(struct drm_connector *connector, int mode);
  370. void (*save)(struct drm_connector *connector);
  371. void (*restore)(struct drm_connector *connector);
  372. void (*reset)(struct drm_connector *connector);
  373. /* Check to see if anything is attached to the connector.
  374. * @force is set to false whilst polling, true when checking the
  375. * connector due to user request. @force can be used by the driver
  376. * to avoid expensive, destructive operations during automated
  377. * probing.
  378. */
  379. enum drm_connector_status (*detect)(struct drm_connector *connector,
  380. bool force);
  381. int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
  382. int (*set_property)(struct drm_connector *connector, struct drm_property *property,
  383. uint64_t val);
  384. void (*destroy)(struct drm_connector *connector);
  385. void (*force)(struct drm_connector *connector);
  386. };
  387. /**
  388. * drm_encoder_funcs - encoder controls
  389. * @reset: reset state (e.g. at init or resume time)
  390. * @destroy: cleanup and free associated data
  391. *
  392. * Encoders sit between CRTCs and connectors.
  393. */
  394. struct drm_encoder_funcs {
  395. void (*reset)(struct drm_encoder *encoder);
  396. void (*destroy)(struct drm_encoder *encoder);
  397. };
  398. #define DRM_CONNECTOR_MAX_UMODES 16
  399. #define DRM_CONNECTOR_MAX_PROPERTY 16
  400. #define DRM_CONNECTOR_LEN 32
  401. #define DRM_CONNECTOR_MAX_ENCODER 2
  402. /**
  403. * drm_encoder - central DRM encoder structure
  404. * @dev: parent DRM device
  405. * @head: list management
  406. * @base: base KMS object
  407. * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
  408. * @possible_crtcs: bitmask of potential CRTC bindings
  409. * @possible_clones: bitmask of potential sibling encoders for cloning
  410. * @crtc: currently bound CRTC
  411. * @funcs: control functions
  412. * @helper_private: mid-layer private data
  413. *
  414. * CRTCs drive pixels to encoders, which convert them into signals
  415. * appropriate for a given connector or set of connectors.
  416. */
  417. struct drm_encoder {
  418. struct drm_device *dev;
  419. struct list_head head;
  420. struct drm_mode_object base;
  421. int encoder_type;
  422. uint32_t possible_crtcs;
  423. uint32_t possible_clones;
  424. struct drm_crtc *crtc;
  425. const struct drm_encoder_funcs *funcs;
  426. void *helper_private;
  427. };
  428. enum drm_connector_force {
  429. DRM_FORCE_UNSPECIFIED,
  430. DRM_FORCE_OFF,
  431. DRM_FORCE_ON, /* force on analog part normally */
  432. DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
  433. };
  434. /* should we poll this connector for connects and disconnects */
  435. /* hot plug detectable */
  436. #define DRM_CONNECTOR_POLL_HPD (1 << 0)
  437. /* poll for connections */
  438. #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
  439. /* can cleanly poll for disconnections without flickering the screen */
  440. /* DACs should rarely do this without a lot of testing */
  441. #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
  442. #define MAX_ELD_BYTES 128
  443. /**
  444. * drm_connector - central DRM connector control structure
  445. * @dev: parent DRM device
  446. * @kdev: kernel device for sysfs attributes
  447. * @attr: sysfs attributes
  448. * @head: list management
  449. * @base: base KMS object
  450. * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
  451. * @connector_type_id: index into connector type enum
  452. * @interlace_allowed: can this connector handle interlaced modes?
  453. * @doublescan_allowed: can this connector handle doublescan?
  454. * @modes: modes available on this connector (from fill_modes() + user)
  455. * @status: one of the drm_connector_status enums (connected, not, or unknown)
  456. * @probed_modes: list of modes derived directly from the display
  457. * @display_info: information about attached display (e.g. from EDID)
  458. * @funcs: connector control functions
  459. * @user_modes: user added mode list
  460. * @edid_blob_ptr: DRM property containing EDID if present
  461. * @property_ids: property tracking for this connector
  462. * @property_values: value pointers or data for properties
  463. * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
  464. * @dpms: current dpms state
  465. * @helper_private: mid-layer private data
  466. * @force: a %DRM_FORCE_<foo> state for forced mode sets
  467. * @encoder_ids: valid encoders for this connector
  468. * @encoder: encoder driving this connector, if any
  469. * @eld: EDID-like data, if present
  470. * @dvi_dual: dual link DVI, if found
  471. * @max_tmds_clock: max clock rate, if found
  472. * @latency_present: AV delay info from ELD, if found
  473. * @video_latency: video latency info from ELD, if found
  474. * @audio_latency: audio latency info from ELD, if found
  475. * @null_edid_counter: track sinks that give us all zeros for the EDID
  476. *
  477. * Each connector may be connected to one or more CRTCs, or may be clonable by
  478. * another connector if they can share a CRTC. Each connector also has a specific
  479. * position in the broader display (referred to as a 'screen' though it could
  480. * span multiple monitors).
  481. */
  482. struct drm_connector {
  483. struct drm_device *dev;
  484. struct device kdev;
  485. struct device_attribute *attr;
  486. struct list_head head;
  487. struct drm_mode_object base;
  488. int connector_type;
  489. int connector_type_id;
  490. bool interlace_allowed;
  491. bool doublescan_allowed;
  492. struct list_head modes; /* list of modes on this connector */
  493. enum drm_connector_status status;
  494. /* these are modes added by probing with DDC or the BIOS */
  495. struct list_head probed_modes;
  496. struct drm_display_info display_info;
  497. const struct drm_connector_funcs *funcs;
  498. struct list_head user_modes;
  499. struct drm_property_blob *edid_blob_ptr;
  500. u32 property_ids[DRM_CONNECTOR_MAX_PROPERTY];
  501. uint64_t property_values[DRM_CONNECTOR_MAX_PROPERTY];
  502. uint8_t polled; /* DRM_CONNECTOR_POLL_* */
  503. /* requested DPMS state */
  504. int dpms;
  505. void *helper_private;
  506. /* forced on connector */
  507. enum drm_connector_force force;
  508. uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
  509. struct drm_encoder *encoder; /* currently active encoder */
  510. /* EDID bits */
  511. uint8_t eld[MAX_ELD_BYTES];
  512. bool dvi_dual;
  513. int max_tmds_clock; /* in MHz */
  514. bool latency_present[2];
  515. int video_latency[2]; /* [0]: progressive, [1]: interlaced */
  516. int audio_latency[2];
  517. int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
  518. };
  519. /**
  520. * drm_plane_funcs - driver plane control functions
  521. * @update_plane: update the plane configuration
  522. * @disable_plane: shut down the plane
  523. * @destroy: clean up plane resources
  524. */
  525. struct drm_plane_funcs {
  526. int (*update_plane)(struct drm_plane *plane,
  527. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  528. int crtc_x, int crtc_y,
  529. unsigned int crtc_w, unsigned int crtc_h,
  530. uint32_t src_x, uint32_t src_y,
  531. uint32_t src_w, uint32_t src_h);
  532. int (*disable_plane)(struct drm_plane *plane);
  533. void (*destroy)(struct drm_plane *plane);
  534. };
  535. /**
  536. * drm_plane - central DRM plane control structure
  537. * @dev: DRM device this plane belongs to
  538. * @head: for list management
  539. * @base: base mode object
  540. * @possible_crtcs: pipes this plane can be bound to
  541. * @format_types: array of formats supported by this plane
  542. * @format_count: number of formats supported
  543. * @crtc: currently bound CRTC
  544. * @fb: currently bound fb
  545. * @gamma_size: size of gamma table
  546. * @gamma_store: gamma correction table
  547. * @enabled: enabled flag
  548. * @funcs: helper functions
  549. * @helper_private: storage for drver layer
  550. */
  551. struct drm_plane {
  552. struct drm_device *dev;
  553. struct list_head head;
  554. struct drm_mode_object base;
  555. uint32_t possible_crtcs;
  556. uint32_t *format_types;
  557. uint32_t format_count;
  558. struct drm_crtc *crtc;
  559. struct drm_framebuffer *fb;
  560. /* CRTC gamma size for reporting to userspace */
  561. uint32_t gamma_size;
  562. uint16_t *gamma_store;
  563. bool enabled;
  564. const struct drm_plane_funcs *funcs;
  565. void *helper_private;
  566. };
  567. /**
  568. * struct drm_mode_set
  569. *
  570. * Represents a single crtc the connectors that it drives with what mode
  571. * and from which framebuffer it scans out from.
  572. *
  573. * This is used to set modes.
  574. */
  575. struct drm_mode_set {
  576. struct list_head head;
  577. struct drm_framebuffer *fb;
  578. struct drm_crtc *crtc;
  579. struct drm_display_mode *mode;
  580. uint32_t x;
  581. uint32_t y;
  582. struct drm_connector **connectors;
  583. size_t num_connectors;
  584. };
  585. /**
  586. * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
  587. */
  588. struct drm_mode_config_funcs {
  589. struct drm_framebuffer *(*fb_create)(struct drm_device *dev, struct drm_file *file_priv, struct drm_mode_fb_cmd2 *mode_cmd);
  590. void (*output_poll_changed)(struct drm_device *dev);
  591. };
  592. struct drm_mode_group {
  593. uint32_t num_crtcs;
  594. uint32_t num_encoders;
  595. uint32_t num_connectors;
  596. /* list of object IDs for this group */
  597. uint32_t *id_list;
  598. };
  599. /**
  600. * drm_mode_config - Mode configuration control structure
  601. *
  602. */
  603. struct drm_mode_config {
  604. struct mutex mutex; /* protects configuration (mode lists etc.) */
  605. struct mutex idr_mutex; /* for IDR management */
  606. struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
  607. /* this is limited to one for now */
  608. int num_fb;
  609. struct list_head fb_list;
  610. int num_connector;
  611. struct list_head connector_list;
  612. int num_encoder;
  613. struct list_head encoder_list;
  614. int num_plane;
  615. struct list_head plane_list;
  616. int num_crtc;
  617. struct list_head crtc_list;
  618. struct list_head property_list;
  619. int min_width, min_height;
  620. int max_width, max_height;
  621. struct drm_mode_config_funcs *funcs;
  622. resource_size_t fb_base;
  623. /* output poll support */
  624. bool poll_enabled;
  625. struct delayed_work output_poll_work;
  626. /* pointers to standard properties */
  627. struct list_head property_blob_list;
  628. struct drm_property *edid_property;
  629. struct drm_property *dpms_property;
  630. /* DVI-I properties */
  631. struct drm_property *dvi_i_subconnector_property;
  632. struct drm_property *dvi_i_select_subconnector_property;
  633. /* TV properties */
  634. struct drm_property *tv_subconnector_property;
  635. struct drm_property *tv_select_subconnector_property;
  636. struct drm_property *tv_mode_property;
  637. struct drm_property *tv_left_margin_property;
  638. struct drm_property *tv_right_margin_property;
  639. struct drm_property *tv_top_margin_property;
  640. struct drm_property *tv_bottom_margin_property;
  641. struct drm_property *tv_brightness_property;
  642. struct drm_property *tv_contrast_property;
  643. struct drm_property *tv_flicker_reduction_property;
  644. struct drm_property *tv_overscan_property;
  645. struct drm_property *tv_saturation_property;
  646. struct drm_property *tv_hue_property;
  647. /* Optional properties */
  648. struct drm_property *scaling_mode_property;
  649. struct drm_property *dithering_mode_property;
  650. struct drm_property *dirty_info_property;
  651. };
  652. #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
  653. #define obj_to_connector(x) container_of(x, struct drm_connector, base)
  654. #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
  655. #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
  656. #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
  657. #define obj_to_property(x) container_of(x, struct drm_property, base)
  658. #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
  659. #define obj_to_plane(x) container_of(x, struct drm_plane, base)
  660. extern void drm_crtc_init(struct drm_device *dev,
  661. struct drm_crtc *crtc,
  662. const struct drm_crtc_funcs *funcs);
  663. extern void drm_crtc_cleanup(struct drm_crtc *crtc);
  664. extern void drm_connector_init(struct drm_device *dev,
  665. struct drm_connector *connector,
  666. const struct drm_connector_funcs *funcs,
  667. int connector_type);
  668. extern void drm_connector_cleanup(struct drm_connector *connector);
  669. extern void drm_encoder_init(struct drm_device *dev,
  670. struct drm_encoder *encoder,
  671. const struct drm_encoder_funcs *funcs,
  672. int encoder_type);
  673. extern int drm_plane_init(struct drm_device *dev,
  674. struct drm_plane *plane,
  675. unsigned long possible_crtcs,
  676. const struct drm_plane_funcs *funcs,
  677. uint32_t *formats, uint32_t format_count);
  678. extern void drm_plane_cleanup(struct drm_plane *plane);
  679. extern void drm_encoder_cleanup(struct drm_encoder *encoder);
  680. extern char *drm_get_connector_name(struct drm_connector *connector);
  681. extern char *drm_get_dpms_name(int val);
  682. extern char *drm_get_dvi_i_subconnector_name(int val);
  683. extern char *drm_get_dvi_i_select_name(int val);
  684. extern char *drm_get_tv_subconnector_name(int val);
  685. extern char *drm_get_tv_select_name(int val);
  686. extern void drm_fb_release(struct drm_file *file_priv);
  687. extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
  688. extern struct edid *drm_get_edid(struct drm_connector *connector,
  689. struct i2c_adapter *adapter);
  690. extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
  691. extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
  692. extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode);
  693. extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
  694. const struct drm_display_mode *mode);
  695. extern void drm_mode_debug_printmodeline(struct drm_display_mode *mode);
  696. extern void drm_mode_config_init(struct drm_device *dev);
  697. extern void drm_mode_config_reset(struct drm_device *dev);
  698. extern void drm_mode_config_cleanup(struct drm_device *dev);
  699. extern void drm_mode_set_name(struct drm_display_mode *mode);
  700. extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
  701. extern int drm_mode_width(struct drm_display_mode *mode);
  702. extern int drm_mode_height(struct drm_display_mode *mode);
  703. /* for us by fb module */
  704. extern int drm_mode_attachmode_crtc(struct drm_device *dev,
  705. struct drm_crtc *crtc,
  706. struct drm_display_mode *mode);
  707. extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
  708. extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
  709. extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
  710. extern void drm_mode_list_concat(struct list_head *head,
  711. struct list_head *new);
  712. extern void drm_mode_validate_size(struct drm_device *dev,
  713. struct list_head *mode_list,
  714. int maxX, int maxY, int maxPitch);
  715. extern void drm_mode_prune_invalid(struct drm_device *dev,
  716. struct list_head *mode_list, bool verbose);
  717. extern void drm_mode_sort(struct list_head *mode_list);
  718. extern int drm_mode_hsync(const struct drm_display_mode *mode);
  719. extern int drm_mode_vrefresh(const struct drm_display_mode *mode);
  720. extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
  721. int adjust_flags);
  722. extern void drm_mode_connector_list_update(struct drm_connector *connector);
  723. extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
  724. struct edid *edid);
  725. extern int drm_connector_property_set_value(struct drm_connector *connector,
  726. struct drm_property *property,
  727. uint64_t value);
  728. extern int drm_connector_property_get_value(struct drm_connector *connector,
  729. struct drm_property *property,
  730. uint64_t *value);
  731. extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
  732. extern void drm_framebuffer_set_object(struct drm_device *dev,
  733. unsigned long handle);
  734. extern int drm_framebuffer_init(struct drm_device *dev,
  735. struct drm_framebuffer *fb,
  736. const struct drm_framebuffer_funcs *funcs);
  737. extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
  738. extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
  739. extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
  740. extern void drm_crtc_probe_connector_modes(struct drm_device *dev, int maxX, int maxY);
  741. extern bool drm_crtc_in_use(struct drm_crtc *crtc);
  742. extern int drm_connector_attach_property(struct drm_connector *connector,
  743. struct drm_property *property, uint64_t init_val);
  744. extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
  745. const char *name, int num_values);
  746. extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
  747. extern int drm_property_add_enum(struct drm_property *property, int index,
  748. uint64_t value, const char *name);
  749. extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
  750. extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
  751. char *formats[]);
  752. extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
  753. extern int drm_mode_create_dithering_property(struct drm_device *dev);
  754. extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
  755. extern char *drm_get_encoder_name(struct drm_encoder *encoder);
  756. extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
  757. struct drm_encoder *encoder);
  758. extern void drm_mode_connector_detach_encoder(struct drm_connector *connector,
  759. struct drm_encoder *encoder);
  760. extern bool drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
  761. int gamma_size);
  762. extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
  763. uint32_t id, uint32_t type);
  764. /* IOCTLs */
  765. extern int drm_mode_getresources(struct drm_device *dev,
  766. void *data, struct drm_file *file_priv);
  767. extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
  768. struct drm_file *file_priv);
  769. extern int drm_mode_getcrtc(struct drm_device *dev,
  770. void *data, struct drm_file *file_priv);
  771. extern int drm_mode_getconnector(struct drm_device *dev,
  772. void *data, struct drm_file *file_priv);
  773. extern int drm_mode_setcrtc(struct drm_device *dev,
  774. void *data, struct drm_file *file_priv);
  775. extern int drm_mode_getplane(struct drm_device *dev,
  776. void *data, struct drm_file *file_priv);
  777. extern int drm_mode_setplane(struct drm_device *dev,
  778. void *data, struct drm_file *file_priv);
  779. extern int drm_mode_cursor_ioctl(struct drm_device *dev,
  780. void *data, struct drm_file *file_priv);
  781. extern int drm_mode_addfb(struct drm_device *dev,
  782. void *data, struct drm_file *file_priv);
  783. extern int drm_mode_addfb2(struct drm_device *dev,
  784. void *data, struct drm_file *file_priv);
  785. extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
  786. extern int drm_mode_rmfb(struct drm_device *dev,
  787. void *data, struct drm_file *file_priv);
  788. extern int drm_mode_getfb(struct drm_device *dev,
  789. void *data, struct drm_file *file_priv);
  790. extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
  791. void *data, struct drm_file *file_priv);
  792. extern int drm_mode_addmode_ioctl(struct drm_device *dev,
  793. void *data, struct drm_file *file_priv);
  794. extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
  795. void *data, struct drm_file *file_priv);
  796. extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
  797. void *data, struct drm_file *file_priv);
  798. extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
  799. void *data, struct drm_file *file_priv);
  800. extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
  801. void *data, struct drm_file *file_priv);
  802. extern int drm_mode_getblob_ioctl(struct drm_device *dev,
  803. void *data, struct drm_file *file_priv);
  804. extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
  805. void *data, struct drm_file *file_priv);
  806. extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
  807. void *data, struct drm_file *file_priv);
  808. extern int drm_mode_replacefb(struct drm_device *dev,
  809. void *data, struct drm_file *file_priv);
  810. extern int drm_mode_getencoder(struct drm_device *dev,
  811. void *data, struct drm_file *file_priv);
  812. extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
  813. void *data, struct drm_file *file_priv);
  814. extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
  815. void *data, struct drm_file *file_priv);
  816. extern u8 *drm_find_cea_extension(struct edid *edid);
  817. extern bool drm_detect_hdmi_monitor(struct edid *edid);
  818. extern bool drm_detect_monitor_audio(struct edid *edid);
  819. extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
  820. void *data, struct drm_file *file_priv);
  821. extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
  822. int hdisplay, int vdisplay, int vrefresh,
  823. bool reduced, bool interlaced, bool margins);
  824. extern struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
  825. int hdisplay, int vdisplay, int vrefresh,
  826. bool interlaced, int margins);
  827. extern struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
  828. int hdisplay, int vdisplay, int vrefresh,
  829. bool interlaced, int margins, int GTF_M,
  830. int GTF_2C, int GTF_K, int GTF_2J);
  831. extern int drm_add_modes_noedid(struct drm_connector *connector,
  832. int hdisplay, int vdisplay);
  833. extern int drm_edid_header_is_valid(const u8 *raw_edid);
  834. extern bool drm_edid_is_valid(struct edid *edid);
  835. struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
  836. int hsize, int vsize, int fresh);
  837. extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
  838. void *data, struct drm_file *file_priv);
  839. extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
  840. void *data, struct drm_file *file_priv);
  841. extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
  842. void *data, struct drm_file *file_priv);
  843. extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
  844. int *bpp);
  845. #endif /* __DRM_CRTC_H__ */