drm_crtc.h 38 KB

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