blob: 7db2ce52c5a49713e06665442aec08fdceda7f6e [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
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
28#include <linux/i2c.h>
29#include <linux/spinlock.h>
30#include <linux/types.h>
31#include <linux/idr.h>
Dave Airlief453ba02008-11-07 14:05:41 -080032#include <linux/fb.h>
33
Jesse Barnes308e5bc2011-11-14 14:51:28 -080034#include <drm/drm_fourcc.h>
35
Dave Airlief453ba02008-11-07 14:05:41 -080036struct drm_device;
37struct drm_mode_set;
38struct drm_framebuffer;
39
40
41#define DRM_MODE_OBJECT_CRTC 0xcccccccc
42#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
43#define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
44#define DRM_MODE_OBJECT_MODE 0xdededede
45#define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
46#define DRM_MODE_OBJECT_FB 0xfbfbfbfb
47#define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
Jesse Barnes8cf5c912011-11-14 14:51:27 -080048#define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
Dave Airlief453ba02008-11-07 14:05:41 -080049
50struct drm_mode_object {
51 uint32_t id;
52 uint32_t type;
53};
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
63enum 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 */
Lucas De Marchi25985ed2011-03-30 22:57:33 -030070 MODE_NOMODE, /* no mode with a matching name */
Dave Airlief453ba02008-11-07 14:05:41 -080071 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
104#define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \
105 DRM_MODE_TYPE_CRTC_C)
106
107#define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
108 .name = nm, .status = 0, .type = (t), .clock = (c), \
109 .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
110 .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
111 .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
112 .vscan = (vs), .flags = (f), .vrefresh = 0
113
114#define CRTC_INTERLACE_HALVE_V 0x1 /* halve V values for interlacing */
115
116struct drm_display_mode {
117 /* Header */
118 struct list_head head;
119 struct drm_mode_object base;
120
121 char name[DRM_DISPLAY_MODE_LEN];
122
Dave Airlief453ba02008-11-07 14:05:41 -0800123 enum drm_mode_status status;
124 int type;
125
126 /* Proposed mode values */
Adam Jackson7ac96a92009-12-03 17:44:37 -0500127 int clock; /* in kHz */
Dave Airlief453ba02008-11-07 14:05:41 -0800128 int hdisplay;
129 int hsync_start;
130 int hsync_end;
131 int htotal;
132 int hskew;
133 int vdisplay;
134 int vsync_start;
135 int vsync_end;
136 int vtotal;
137 int vscan;
138 unsigned int flags;
139
140 /* Addressable image size (may be 0 for projectors, etc.) */
141 int width_mm;
142 int height_mm;
143
144 /* Actual mode we give to hw */
145 int clock_index;
146 int synth_clock;
147 int crtc_hdisplay;
148 int crtc_hblank_start;
149 int crtc_hblank_end;
150 int crtc_hsync_start;
151 int crtc_hsync_end;
152 int crtc_htotal;
153 int crtc_hskew;
154 int crtc_vdisplay;
155 int crtc_vblank_start;
156 int crtc_vblank_end;
157 int crtc_vsync_start;
158 int crtc_vsync_end;
159 int crtc_vtotal;
160 int crtc_hadjusted;
161 int crtc_vadjusted;
162
163 /* Driver private mode info */
164 int private_size;
165 int *private;
166 int private_flags;
167
Adam Jackson7ac96a92009-12-03 17:44:37 -0500168 int vrefresh; /* in Hz */
169 int hsync; /* in kHz */
Dave Airlief453ba02008-11-07 14:05:41 -0800170};
171
172enum drm_connector_status {
173 connector_status_connected = 1,
174 connector_status_disconnected = 2,
175 connector_status_unknown = 3,
176};
177
178enum subpixel_order {
179 SubPixelUnknown = 0,
180 SubPixelHorizontalRGB,
181 SubPixelHorizontalBGR,
182 SubPixelVerticalRGB,
183 SubPixelVerticalBGR,
184 SubPixelNone,
185};
186
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700187#define DRM_COLOR_FORMAT_RGB444 (1<<0)
188#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
189#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
Dave Airlief453ba02008-11-07 14:05:41 -0800190/*
191 * Describes a given display (e.g. CRT or flat panel) and its limitations.
192 */
193struct drm_display_info {
194 char name[DRM_DISPLAY_INFO_LEN];
Adam Jacksonfb439642010-08-03 14:38:16 -0400195
Dave Airlief453ba02008-11-07 14:05:41 -0800196 /* Physical size */
197 unsigned int width_mm;
198 unsigned int height_mm;
199
Dave Airlief453ba02008-11-07 14:05:41 -0800200 /* Clock limits FIXME: storage format */
201 unsigned int min_vfreq, max_vfreq;
202 unsigned int min_hfreq, max_hfreq;
203 unsigned int pixel_clock;
Jesse Barnes3b112282011-04-15 12:49:23 -0700204 unsigned int bpc;
Dave Airlief453ba02008-11-07 14:05:41 -0800205
Dave Airlief453ba02008-11-07 14:05:41 -0800206 enum subpixel_order subpixel_order;
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700207 u32 color_formats;
Dave Airlief453ba02008-11-07 14:05:41 -0800208
Jesse Barnesebec9a72011-08-03 09:22:54 -0700209 u8 cea_rev;
210
Dave Airlief453ba02008-11-07 14:05:41 -0800211 char *raw_edid; /* if any */
212};
213
214struct drm_framebuffer_funcs {
215 void (*destroy)(struct drm_framebuffer *framebuffer);
216 int (*create_handle)(struct drm_framebuffer *fb,
217 struct drm_file *file_priv,
218 unsigned int *handle);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000219 /**
220 * Optinal callback for the dirty fb ioctl.
221 *
222 * Userspace can notify the driver via this callback
223 * that a area of the framebuffer has changed and should
224 * be flushed to the display hardware.
225 *
226 * See documentation in drm_mode.h for the struct
227 * drm_mode_fb_dirty_cmd for more information as all
228 * the semantics and arguments have a one to one mapping
229 * on this function.
230 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200231 int (*dirty)(struct drm_framebuffer *framebuffer,
232 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000233 unsigned color, struct drm_clip_rect *clips,
234 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800235};
236
237struct drm_framebuffer {
238 struct drm_device *dev;
239 struct list_head head;
240 struct drm_mode_object base;
241 const struct drm_framebuffer_funcs *funcs;
242 unsigned int pitch;
243 unsigned int width;
244 unsigned int height;
245 /* depth can be 15 or 16 */
246 unsigned int depth;
247 int bits_per_pixel;
248 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800249 uint32_t pixel_format; /* fourcc format */
Dave Airlief453ba02008-11-07 14:05:41 -0800250 struct list_head filp_head;
Dave Airlie785b93e2009-08-28 15:46:53 +1000251 /* if you are using the helper */
252 void *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -0800253};
254
255struct drm_property_blob {
256 struct drm_mode_object base;
257 struct list_head head;
258 unsigned int length;
259 void *data;
260};
261
262struct drm_property_enum {
263 uint64_t value;
264 struct list_head head;
265 char name[DRM_PROP_NAME_LEN];
266};
267
268struct drm_property {
269 struct list_head head;
270 struct drm_mode_object base;
271 uint32_t flags;
272 char name[DRM_PROP_NAME_LEN];
273 uint32_t num_values;
274 uint64_t *values;
275
276 struct list_head enum_blob_list;
277};
278
279struct drm_crtc;
280struct drm_connector;
281struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500282struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800283struct drm_plane;
Dave Airlief453ba02008-11-07 14:05:41 -0800284
285/**
286 * drm_crtc_funcs - control CRTCs for a given device
Chris Wilsoneb033552011-01-24 15:11:08 +0000287 * @reset: reset CRTC after state has been invalidate (e.g. resume)
Dave Airlief453ba02008-11-07 14:05:41 -0800288 * @dpms: control display power levels
289 * @save: save CRTC state
290 * @resore: restore CRTC state
291 * @lock: lock the CRTC
292 * @unlock: unlock the CRTC
293 * @shadow_allocate: allocate shadow pixmap
294 * @shadow_create: create shadow pixmap for rotation support
295 * @shadow_destroy: free shadow pixmap
296 * @mode_fixup: fixup proposed mode
297 * @mode_set: set the desired mode on the CRTC
298 * @gamma_set: specify color ramp for CRTC
299 * @destroy: deinit and free object.
300 *
301 * The drm_crtc_funcs structure is the central CRTC management structure
302 * in the DRM. Each CRTC controls one or more connectors (note that the name
303 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
304 * connectors, not just CRTs).
305 *
306 * Each driver is responsible for filling out this structure at startup time,
307 * in addition to providing other modesetting features, like i2c and DDC
308 * bus accessors.
309 */
310struct drm_crtc_funcs {
311 /* Save CRTC state */
312 void (*save)(struct drm_crtc *crtc); /* suspend? */
313 /* Restore CRTC state */
314 void (*restore)(struct drm_crtc *crtc); /* resume? */
Chris Wilsoneb033552011-01-24 15:11:08 +0000315 /* Reset CRTC state */
316 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800317
318 /* cursor controls */
319 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
320 uint32_t handle, uint32_t width, uint32_t height);
321 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
322
323 /* Set gamma on the CRTC */
324 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
James Simmons72034252010-08-03 01:33:19 +0100325 uint32_t start, uint32_t size);
Dave Airlief453ba02008-11-07 14:05:41 -0800326 /* Object destroy routine */
327 void (*destroy)(struct drm_crtc *crtc);
328
329 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500330
331 /*
332 * Flip to the given framebuffer. This implements the page
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300333 * flip ioctl described in drm_mode.h, specifically, the
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500334 * implementation must return immediately and block all
335 * rendering to the current fb until the flip has completed.
336 * If userspace set the event flag in the ioctl, the event
337 * argument will point to an event to send back when the flip
338 * completes, otherwise it will be NULL.
339 */
340 int (*page_flip)(struct drm_crtc *crtc,
341 struct drm_framebuffer *fb,
342 struct drm_pending_vblank_event *event);
Dave Airlief453ba02008-11-07 14:05:41 -0800343};
344
345/**
346 * drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800347 * @dev: parent DRM device
348 * @head: list management
349 * @base: base KMS object for ID tracking etc.
Dave Airlief453ba02008-11-07 14:05:41 -0800350 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800351 * @mode: current mode timings
352 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800353 * @x: x position on screen
354 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800355 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800356 * @gamma_size: size of gamma ramp
357 * @gamma_store: gamma ramp values
358 * @framedur_ns: precise frame timing
359 * @framedur_ns: precise line timing
360 * @pixeldur_ns: precise pixel timing
361 * @helper_private: mid-layer private data
Dave Airlief453ba02008-11-07 14:05:41 -0800362 *
363 * Each CRTC may have one or more connectors associated with it. This structure
364 * allows the CRTC to be controlled.
365 */
366struct drm_crtc {
367 struct drm_device *dev;
368 struct list_head head;
369
370 struct drm_mode_object base;
371
372 /* framebuffer the connector is currently bound to */
373 struct drm_framebuffer *fb;
374
375 bool enabled;
376
Mario Kleiner27641c32010-10-23 04:20:23 +0200377 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800378 struct drm_display_mode mode;
379
Mario Kleiner27641c32010-10-23 04:20:23 +0200380 /* Programmed mode in hw, after adjustments for encoders,
381 * crtc, panel scaling etc. Needed for timestamping etc.
382 */
383 struct drm_display_mode hwmode;
384
Dave Airlief453ba02008-11-07 14:05:41 -0800385 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800386 const struct drm_crtc_funcs *funcs;
387
388 /* CRTC gamma size for reporting to userspace */
389 uint32_t gamma_size;
390 uint16_t *gamma_store;
391
Mario Kleiner27641c32010-10-23 04:20:23 +0200392 /* Constants needed for precise vblank and swap timestamping. */
393 s64 framedur_ns, linedur_ns, pixeldur_ns;
394
Dave Airlief453ba02008-11-07 14:05:41 -0800395 /* if you are using the helper */
396 void *helper_private;
397};
398
399
400/**
401 * drm_connector_funcs - control connectors on a given device
402 * @dpms: set power state (see drm_crtc_funcs above)
403 * @save: save connector state
404 * @restore: restore connector state
Chris Wilsoneb033552011-01-24 15:11:08 +0000405 * @reset: reset connector after state has been invalidate (e.g. resume)
Dave Airlief453ba02008-11-07 14:05:41 -0800406 * @mode_valid: is this mode valid on the given connector?
407 * @mode_fixup: try to fixup proposed mode for this connector
408 * @mode_set: set this mode
409 * @detect: is this connector active?
410 * @get_modes: get mode list for this connector
411 * @set_property: property for this connector may need update
412 * @destroy: make object go away
Dave Airlied50ba252009-09-23 14:44:08 +1000413 * @force: notify the driver the connector is forced on
Dave Airlief453ba02008-11-07 14:05:41 -0800414 *
415 * Each CRTC may have one or more connectors attached to it. The functions
416 * below allow the core DRM code to control connectors, enumerate available modes,
417 * etc.
418 */
419struct drm_connector_funcs {
420 void (*dpms)(struct drm_connector *connector, int mode);
421 void (*save)(struct drm_connector *connector);
422 void (*restore)(struct drm_connector *connector);
Chris Wilsoneb033552011-01-24 15:11:08 +0000423 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100424
425 /* Check to see if anything is attached to the connector.
426 * @force is set to false whilst polling, true when checking the
427 * connector due to user request. @force can be used by the driver
428 * to avoid expensive, destructive operations during automated
429 * probing.
430 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100431 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100432 bool force);
Jesse Barnes40a518d2009-01-12 12:05:32 -0800433 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Dave Airlief453ba02008-11-07 14:05:41 -0800434 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
435 uint64_t val);
436 void (*destroy)(struct drm_connector *connector);
Dave Airlied50ba252009-09-23 14:44:08 +1000437 void (*force)(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -0800438};
439
Jesse Barnes6c3db922011-11-07 12:03:16 -0800440/**
441 * drm_encoder_funcs - encoder controls
442 * @reset: reset state (e.g. at init or resume time)
443 * @destroy: cleanup and free associated data
444 *
445 * Encoders sit between CRTCs and connectors.
446 */
Dave Airlief453ba02008-11-07 14:05:41 -0800447struct drm_encoder_funcs {
Chris Wilsoneb033552011-01-24 15:11:08 +0000448 void (*reset)(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -0800449 void (*destroy)(struct drm_encoder *encoder);
450};
451
452#define DRM_CONNECTOR_MAX_UMODES 16
453#define DRM_CONNECTOR_MAX_PROPERTY 16
454#define DRM_CONNECTOR_LEN 32
455#define DRM_CONNECTOR_MAX_ENCODER 2
456
457/**
458 * drm_encoder - central DRM encoder structure
459 */
460struct drm_encoder {
461 struct drm_device *dev;
462 struct list_head head;
463
464 struct drm_mode_object base;
465 int encoder_type;
466 uint32_t possible_crtcs;
467 uint32_t possible_clones;
468
469 struct drm_crtc *crtc;
470 const struct drm_encoder_funcs *funcs;
471 void *helper_private;
472};
473
Dave Airlied50ba252009-09-23 14:44:08 +1000474enum drm_connector_force {
475 DRM_FORCE_UNSPECIFIED,
476 DRM_FORCE_OFF,
477 DRM_FORCE_ON, /* force on analog part normally */
478 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
479};
480
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000481/* should we poll this connector for connects and disconnects */
482/* hot plug detectable */
483#define DRM_CONNECTOR_POLL_HPD (1 << 0)
484/* poll for connections */
485#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
486/* can cleanly poll for disconnections without flickering the screen */
487/* DACs should rarely do this without a lot of testing */
488#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
489
Wu Fengguang76adaa342011-09-05 14:23:20 +0800490#define MAX_ELD_BYTES 128
491
Dave Airlief453ba02008-11-07 14:05:41 -0800492/**
493 * drm_connector - central DRM connector control structure
494 * @crtc: CRTC this connector is currently connected to, NULL if none
495 * @interlace_allowed: can this connector handle interlaced modes?
496 * @doublescan_allowed: can this connector handle doublescan?
497 * @available_modes: modes available on this connector (from get_modes() + user)
498 * @initial_x: initial x position for this connector
499 * @initial_y: initial y position for this connector
500 * @status: connector connected?
501 * @funcs: connector control functions
502 *
503 * Each connector may be connected to one or more CRTCs, or may be clonable by
504 * another connector if they can share a CRTC. Each connector also has a specific
505 * position in the broader display (referred to as a 'screen' though it could
506 * span multiple monitors).
507 */
508struct drm_connector {
509 struct drm_device *dev;
510 struct device kdev;
511 struct device_attribute *attr;
512 struct list_head head;
513
514 struct drm_mode_object base;
515
516 int connector_type;
517 int connector_type_id;
518 bool interlace_allowed;
519 bool doublescan_allowed;
520 struct list_head modes; /* list of modes on this connector */
521
522 int initial_x, initial_y;
523 enum drm_connector_status status;
524
525 /* these are modes added by probing with DDC or the BIOS */
526 struct list_head probed_modes;
527
528 struct drm_display_info display_info;
529 const struct drm_connector_funcs *funcs;
530
531 struct list_head user_modes;
532 struct drm_property_blob *edid_blob_ptr;
533 u32 property_ids[DRM_CONNECTOR_MAX_PROPERTY];
534 uint64_t property_values[DRM_CONNECTOR_MAX_PROPERTY];
535
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000536 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
537
Keith Packardc9fb15f2009-05-30 20:42:28 -0700538 /* requested DPMS state */
539 int dpms;
540
Dave Airlief453ba02008-11-07 14:05:41 -0800541 void *helper_private;
542
Dave Airlied50ba252009-09-23 14:44:08 +1000543 /* forced on connector */
544 enum drm_connector_force force;
Dave Airlief453ba02008-11-07 14:05:41 -0800545 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
546 uint32_t force_encoder_id;
547 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +0000548
Wu Fengguang76adaa342011-09-05 14:23:20 +0800549 /* EDID bits */
550 uint8_t eld[MAX_ELD_BYTES];
551 bool dvi_dual;
552 int max_tmds_clock; /* in MHz */
553 bool latency_present[2];
554 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
555 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +0000556 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Dave Airlief453ba02008-11-07 14:05:41 -0800557};
558
559/**
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800560 * drm_plane_funcs - driver plane control functions
561 * @update_plane: update the plane configuration
562 * @disable_plane: shut down the plane
563 * @destroy: clean up plane resources
564 */
565struct drm_plane_funcs {
566 int (*update_plane)(struct drm_plane *plane,
567 struct drm_crtc *crtc, struct drm_framebuffer *fb,
568 int crtc_x, int crtc_y,
569 unsigned int crtc_w, unsigned int crtc_h,
570 uint32_t src_x, uint32_t src_y,
571 uint32_t src_w, uint32_t src_h);
572 int (*disable_plane)(struct drm_plane *plane);
573 void (*destroy)(struct drm_plane *plane);
574};
575
576/**
577 * drm_plane - central DRM plane control structure
578 * @dev: DRM device this plane belongs to
579 * @head: for list management
580 * @base: base mode object
581 * @possible_crtcs: pipes this plane can be bound to
582 * @format_types: array of formats supported by this plane
583 * @format_count: number of formats supported
584 * @crtc: currently bound CRTC
585 * @fb: currently bound fb
586 * @gamma_size: size of gamma table
587 * @gamma_store: gamma correction table
588 * @enabled: enabled flag
589 * @funcs: helper functions
590 * @helper_private: storage for drver layer
591 */
592struct drm_plane {
593 struct drm_device *dev;
594 struct list_head head;
595
596 struct drm_mode_object base;
597
598 uint32_t possible_crtcs;
599 uint32_t *format_types;
600 uint32_t format_count;
601
602 struct drm_crtc *crtc;
603 struct drm_framebuffer *fb;
604
605 /* CRTC gamma size for reporting to userspace */
606 uint32_t gamma_size;
607 uint16_t *gamma_store;
608
609 bool enabled;
610
611 const struct drm_plane_funcs *funcs;
612 void *helper_private;
613};
614
615/**
Dave Airlief453ba02008-11-07 14:05:41 -0800616 * struct drm_mode_set
617 *
618 * Represents a single crtc the connectors that it drives with what mode
619 * and from which framebuffer it scans out from.
620 *
621 * This is used to set modes.
622 */
623struct drm_mode_set {
624 struct list_head head;
625
626 struct drm_framebuffer *fb;
627 struct drm_crtc *crtc;
628 struct drm_display_mode *mode;
629
630 uint32_t x;
631 uint32_t y;
632
633 struct drm_connector **connectors;
634 size_t num_connectors;
635};
636
637/**
638 * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
Dave Airlief453ba02008-11-07 14:05:41 -0800639 */
640struct drm_mode_config_funcs {
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800641 struct drm_framebuffer *(*fb_create)(struct drm_device *dev, struct drm_file *file_priv, struct drm_mode_fb_cmd2 *mode_cmd);
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000642 void (*output_poll_changed)(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800643};
644
645struct drm_mode_group {
646 uint32_t num_crtcs;
647 uint32_t num_encoders;
648 uint32_t num_connectors;
649
650 /* list of object IDs for this group */
651 uint32_t *id_list;
652};
653
654/**
655 * drm_mode_config - Mode configuration control structure
656 *
657 */
658struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +1000659 struct mutex mutex; /* protects configuration (mode lists etc.) */
660 struct mutex idr_mutex; /* for IDR management */
Dave Airlief453ba02008-11-07 14:05:41 -0800661 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
662 /* this is limited to one for now */
663 int num_fb;
664 struct list_head fb_list;
665 int num_connector;
666 struct list_head connector_list;
667 int num_encoder;
668 struct list_head encoder_list;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800669 int num_plane;
670 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800671
672 int num_crtc;
673 struct list_head crtc_list;
674
675 struct list_head property_list;
676
Dave Airlief453ba02008-11-07 14:05:41 -0800677 int min_width, min_height;
678 int max_width, max_height;
679 struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +1100680 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -0800681
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000682 /* output poll support */
683 bool poll_enabled;
Tejun Heo991ea752010-07-20 22:09:02 +0200684 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000685
Dave Airlief453ba02008-11-07 14:05:41 -0800686 /* pointers to standard properties */
687 struct list_head property_blob_list;
688 struct drm_property *edid_property;
689 struct drm_property *dpms_property;
690
691 /* DVI-I properties */
692 struct drm_property *dvi_i_subconnector_property;
693 struct drm_property *dvi_i_select_subconnector_property;
694
695 /* TV properties */
696 struct drm_property *tv_subconnector_property;
697 struct drm_property *tv_select_subconnector_property;
698 struct drm_property *tv_mode_property;
699 struct drm_property *tv_left_margin_property;
700 struct drm_property *tv_right_margin_property;
701 struct drm_property *tv_top_margin_property;
702 struct drm_property *tv_bottom_margin_property;
Francisco Jerezb6b79022009-08-02 04:19:20 +0200703 struct drm_property *tv_brightness_property;
704 struct drm_property *tv_contrast_property;
705 struct drm_property *tv_flicker_reduction_property;
Francisco Jereza75f0232009-08-12 02:30:10 +0200706 struct drm_property *tv_overscan_property;
707 struct drm_property *tv_saturation_property;
708 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -0800709
710 /* Optional properties */
711 struct drm_property *scaling_mode_property;
712 struct drm_property *dithering_mode_property;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000713 struct drm_property *dirty_info_property;
Dave Airlief453ba02008-11-07 14:05:41 -0800714};
715
716#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
717#define obj_to_connector(x) container_of(x, struct drm_connector, base)
718#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
719#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
720#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
721#define obj_to_property(x) container_of(x, struct drm_property, base)
722#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800723#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -0800724
725
726extern void drm_crtc_init(struct drm_device *dev,
727 struct drm_crtc *crtc,
728 const struct drm_crtc_funcs *funcs);
729extern void drm_crtc_cleanup(struct drm_crtc *crtc);
730
731extern void drm_connector_init(struct drm_device *dev,
732 struct drm_connector *connector,
733 const struct drm_connector_funcs *funcs,
734 int connector_type);
735
736extern void drm_connector_cleanup(struct drm_connector *connector);
737
738extern void drm_encoder_init(struct drm_device *dev,
739 struct drm_encoder *encoder,
740 const struct drm_encoder_funcs *funcs,
741 int encoder_type);
742
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800743extern int drm_plane_init(struct drm_device *dev,
744 struct drm_plane *plane,
745 unsigned long possible_crtcs,
746 const struct drm_plane_funcs *funcs,
747 uint32_t *formats, uint32_t format_count);
748extern void drm_plane_cleanup(struct drm_plane *plane);
749
Dave Airlief453ba02008-11-07 14:05:41 -0800750extern void drm_encoder_cleanup(struct drm_encoder *encoder);
751
752extern char *drm_get_connector_name(struct drm_connector *connector);
753extern char *drm_get_dpms_name(int val);
754extern char *drm_get_dvi_i_subconnector_name(int val);
755extern char *drm_get_dvi_i_select_name(int val);
756extern char *drm_get_tv_subconnector_name(int val);
757extern char *drm_get_tv_select_name(int val);
Kristian Høgsbergea39f832009-02-12 14:37:56 -0500758extern void drm_fb_release(struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -0800759extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
760extern struct edid *drm_get_edid(struct drm_connector *connector,
761 struct i2c_adapter *adapter);
Dave Airlief453ba02008-11-07 14:05:41 -0800762extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
763extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
764extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode);
765extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
Chris Wilsonb1f559e2011-01-26 09:49:47 +0000766 const struct drm_display_mode *mode);
Dave Airlief453ba02008-11-07 14:05:41 -0800767extern void drm_mode_debug_printmodeline(struct drm_display_mode *mode);
768extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +0000769extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800770extern void drm_mode_config_cleanup(struct drm_device *dev);
771extern void drm_mode_set_name(struct drm_display_mode *mode);
772extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
773extern int drm_mode_width(struct drm_display_mode *mode);
774extern int drm_mode_height(struct drm_display_mode *mode);
775
776/* for us by fb module */
777extern int drm_mode_attachmode_crtc(struct drm_device *dev,
778 struct drm_crtc *crtc,
779 struct drm_display_mode *mode);
780extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
781
782extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
783extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
784extern void drm_mode_list_concat(struct list_head *head,
785 struct list_head *new);
786extern void drm_mode_validate_size(struct drm_device *dev,
787 struct list_head *mode_list,
788 int maxX, int maxY, int maxPitch);
789extern void drm_mode_prune_invalid(struct drm_device *dev,
790 struct list_head *mode_list, bool verbose);
791extern void drm_mode_sort(struct list_head *mode_list);
Chris Wilsonb1f559e2011-01-26 09:49:47 +0000792extern int drm_mode_hsync(const struct drm_display_mode *mode);
793extern int drm_mode_vrefresh(const struct drm_display_mode *mode);
Dave Airlief453ba02008-11-07 14:05:41 -0800794extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
795 int adjust_flags);
796extern void drm_mode_connector_list_update(struct drm_connector *connector);
797extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
798 struct edid *edid);
799extern int drm_connector_property_set_value(struct drm_connector *connector,
800 struct drm_property *property,
801 uint64_t value);
802extern int drm_connector_property_get_value(struct drm_connector *connector,
803 struct drm_property *property,
804 uint64_t *value);
805extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
806extern void drm_framebuffer_set_object(struct drm_device *dev,
807 unsigned long handle);
808extern int drm_framebuffer_init(struct drm_device *dev,
809 struct drm_framebuffer *fb,
810 const struct drm_framebuffer_funcs *funcs);
811extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
812extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
813extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
814extern void drm_crtc_probe_connector_modes(struct drm_device *dev, int maxX, int maxY);
815extern bool drm_crtc_in_use(struct drm_crtc *crtc);
816
817extern int drm_connector_attach_property(struct drm_connector *connector,
818 struct drm_property *property, uint64_t init_val);
819extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
820 const char *name, int num_values);
821extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
822extern int drm_property_add_enum(struct drm_property *property, int index,
823 uint64_t value, const char *name);
824extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
825extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
826 char *formats[]);
827extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
828extern int drm_mode_create_dithering_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000829extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800830extern char *drm_get_encoder_name(struct drm_encoder *encoder);
831
832extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
833 struct drm_encoder *encoder);
834extern void drm_mode_connector_detach_encoder(struct drm_connector *connector,
835 struct drm_encoder *encoder);
836extern bool drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
837 int gamma_size);
Daniel Vetter7a9c9062009-09-15 22:57:31 +0200838extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
839 uint32_t id, uint32_t type);
Dave Airlief453ba02008-11-07 14:05:41 -0800840/* IOCTLs */
841extern int drm_mode_getresources(struct drm_device *dev,
842 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800843extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
844 struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -0800845extern int drm_mode_getcrtc(struct drm_device *dev,
846 void *data, struct drm_file *file_priv);
847extern int drm_mode_getconnector(struct drm_device *dev,
848 void *data, struct drm_file *file_priv);
849extern int drm_mode_setcrtc(struct drm_device *dev,
850 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800851extern int drm_mode_getplane(struct drm_device *dev,
852 void *data, struct drm_file *file_priv);
853extern int drm_mode_setplane(struct drm_device *dev,
854 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -0800855extern int drm_mode_cursor_ioctl(struct drm_device *dev,
856 void *data, struct drm_file *file_priv);
857extern int drm_mode_addfb(struct drm_device *dev,
858 void *data, struct drm_file *file_priv);
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800859extern int drm_mode_addfb2(struct drm_device *dev,
860 void *data, struct drm_file *file_priv);
861extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlief453ba02008-11-07 14:05:41 -0800862extern int drm_mode_rmfb(struct drm_device *dev,
863 void *data, struct drm_file *file_priv);
864extern int drm_mode_getfb(struct drm_device *dev,
865 void *data, struct drm_file *file_priv);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000866extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
867 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -0800868extern int drm_mode_addmode_ioctl(struct drm_device *dev,
869 void *data, struct drm_file *file_priv);
870extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
871 void *data, struct drm_file *file_priv);
872extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
873 void *data, struct drm_file *file_priv);
874extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
875 void *data, struct drm_file *file_priv);
876
877extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
878 void *data, struct drm_file *file_priv);
879extern int drm_mode_getblob_ioctl(struct drm_device *dev,
880 void *data, struct drm_file *file_priv);
881extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
882 void *data, struct drm_file *file_priv);
883extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
884 void *data, struct drm_file *file_priv);
885extern int drm_mode_replacefb(struct drm_device *dev,
886 void *data, struct drm_file *file_priv);
887extern int drm_mode_getencoder(struct drm_device *dev,
888 void *data, struct drm_file *file_priv);
889extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
890 void *data, struct drm_file *file_priv);
891extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
892 void *data, struct drm_file *file_priv);
Ben Skeggseccaca22011-03-30 05:03:47 +0000893extern u8 *drm_find_cea_extension(struct edid *edid);
Ma Lingf23c20c2009-03-26 19:26:23 +0800894extern bool drm_detect_hdmi_monitor(struct edid *edid);
Zhenyu Wang8fe97902010-09-19 14:27:28 +0800895extern bool drm_detect_monitor_audio(struct edid *edid);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500896extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
897 void *data, struct drm_file *file_priv);
Zhao Yakuid782c3f2009-06-22 13:17:08 +0800898extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
899 int hdisplay, int vdisplay, int vrefresh,
Dave Airlied50ba252009-09-23 14:44:08 +1000900 bool reduced, bool interlaced, bool margins);
Zhao Yakui26bbdad2009-06-22 13:17:09 +0800901extern struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
902 int hdisplay, int vdisplay, int vrefresh,
903 bool interlaced, int margins);
Adam Jackson7a374352010-03-29 21:43:30 +0000904extern struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
905 int hdisplay, int vdisplay, int vrefresh,
906 bool interlaced, int margins, int GTF_M,
907 int GTF_2C, int GTF_K, int GTF_2J);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +0800908extern int drm_add_modes_noedid(struct drm_connector *connector,
909 int hdisplay, int vdisplay);
Alex Deucher3c537882010-02-05 04:21:19 -0500910
Thomas Reim051963d2011-07-29 14:28:57 +0000911extern int drm_edid_header_is_valid(const u8 *raw_edid);
Alex Deucher3c537882010-02-05 04:21:19 -0500912extern bool drm_edid_is_valid(struct edid *edid);
Dave Airlie1d42bbc2010-05-07 05:02:30 +0000913struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
914 int hsize, int vsize, int fresh);
Dave Airlieff72145b2011-02-07 12:16:14 +1000915
916extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
917 void *data, struct drm_file *file_priv);
918extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
919 void *data, struct drm_file *file_priv);
920extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
921 void *data, struct drm_file *file_priv);
Dave Airlie248dbc22011-11-29 20:02:54 +0000922
923extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
924 int *bpp);
Dave Airlief453ba02008-11-07 14:05:41 -0800925#endif /* __DRM_CRTC_H__ */