drm_crtc.h 38 KB

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