drm_crtc.h 37 KB

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