blob: 6718b1873dfc34a00e64681b926f3246c0e6c7ec [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
123 int connector_count;
124 enum drm_mode_status status;
125 int type;
126
127 /* Proposed mode values */
Adam Jackson7ac96a92009-12-03 17:44:37 -0500128 int clock; /* in kHz */
Dave Airlief453ba02008-11-07 14:05:41 -0800129 int hdisplay;
130 int hsync_start;
131 int hsync_end;
132 int htotal;
133 int hskew;
134 int vdisplay;
135 int vsync_start;
136 int vsync_end;
137 int vtotal;
138 int vscan;
139 unsigned int flags;
140
141 /* Addressable image size (may be 0 for projectors, etc.) */
142 int width_mm;
143 int height_mm;
144
145 /* Actual mode we give to hw */
146 int clock_index;
147 int synth_clock;
148 int crtc_hdisplay;
149 int crtc_hblank_start;
150 int crtc_hblank_end;
151 int crtc_hsync_start;
152 int crtc_hsync_end;
153 int crtc_htotal;
154 int crtc_hskew;
155 int crtc_vdisplay;
156 int crtc_vblank_start;
157 int crtc_vblank_end;
158 int crtc_vsync_start;
159 int crtc_vsync_end;
160 int crtc_vtotal;
161 int crtc_hadjusted;
162 int crtc_vadjusted;
163
164 /* Driver private mode info */
165 int private_size;
166 int *private;
167 int private_flags;
168
Adam Jackson7ac96a92009-12-03 17:44:37 -0500169 int vrefresh; /* in Hz */
170 int hsync; /* in kHz */
Dave Airlief453ba02008-11-07 14:05:41 -0800171};
172
173enum drm_connector_status {
174 connector_status_connected = 1,
175 connector_status_disconnected = 2,
176 connector_status_unknown = 3,
177};
178
179enum subpixel_order {
180 SubPixelUnknown = 0,
181 SubPixelHorizontalRGB,
182 SubPixelHorizontalBGR,
183 SubPixelVerticalRGB,
184 SubPixelVerticalBGR,
185 SubPixelNone,
186};
187
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700188#define DRM_COLOR_FORMAT_RGB444 (1<<0)
189#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
190#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
Dave Airlief453ba02008-11-07 14:05:41 -0800191/*
192 * Describes a given display (e.g. CRT or flat panel) and its limitations.
193 */
194struct drm_display_info {
195 char name[DRM_DISPLAY_INFO_LEN];
Adam Jacksonfb439642010-08-03 14:38:16 -0400196
Dave Airlief453ba02008-11-07 14:05:41 -0800197 /* Physical size */
198 unsigned int width_mm;
199 unsigned int height_mm;
200
Dave Airlief453ba02008-11-07 14:05:41 -0800201 /* Clock limits FIXME: storage format */
202 unsigned int min_vfreq, max_vfreq;
203 unsigned int min_hfreq, max_hfreq;
204 unsigned int pixel_clock;
Jesse Barnes3b112282011-04-15 12:49:23 -0700205 unsigned int bpc;
Dave Airlief453ba02008-11-07 14:05:41 -0800206
Dave Airlief453ba02008-11-07 14:05:41 -0800207 enum subpixel_order subpixel_order;
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700208 u32 color_formats;
Dave Airlief453ba02008-11-07 14:05:41 -0800209
Jesse Barnesebec9a7b2011-08-03 09:22:54 -0700210 u8 cea_rev;
211
Dave Airlief453ba02008-11-07 14:05:41 -0800212 char *raw_edid; /* if any */
213};
214
215struct drm_framebuffer_funcs {
216 void (*destroy)(struct drm_framebuffer *framebuffer);
217 int (*create_handle)(struct drm_framebuffer *fb,
218 struct drm_file *file_priv,
219 unsigned int *handle);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000220 /**
221 * Optinal callback for the dirty fb ioctl.
222 *
223 * Userspace can notify the driver via this callback
224 * that a area of the framebuffer has changed and should
225 * be flushed to the display hardware.
226 *
227 * See documentation in drm_mode.h for the struct
228 * drm_mode_fb_dirty_cmd for more information as all
229 * the semantics and arguments have a one to one mapping
230 * on this function.
231 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200232 int (*dirty)(struct drm_framebuffer *framebuffer,
233 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000234 unsigned color, struct drm_clip_rect *clips,
235 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800236};
237
238struct drm_framebuffer {
239 struct drm_device *dev;
240 struct list_head head;
241 struct drm_mode_object base;
242 const struct drm_framebuffer_funcs *funcs;
243 unsigned int pitch;
244 unsigned int width;
245 unsigned int height;
246 /* depth can be 15 or 16 */
247 unsigned int depth;
248 int bits_per_pixel;
249 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800250 uint32_t pixel_format; /* fourcc format */
Dave Airlief453ba02008-11-07 14:05:41 -0800251 struct list_head filp_head;
Dave Airlie785b93e2009-08-28 15:46:53 +1000252 /* if you are using the helper */
253 void *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -0800254};
255
256struct drm_property_blob {
257 struct drm_mode_object base;
258 struct list_head head;
259 unsigned int length;
260 void *data;
261};
262
263struct drm_property_enum {
264 uint64_t value;
265 struct list_head head;
266 char name[DRM_PROP_NAME_LEN];
267};
268
269struct drm_property {
270 struct list_head head;
271 struct drm_mode_object base;
272 uint32_t flags;
273 char name[DRM_PROP_NAME_LEN];
274 uint32_t num_values;
275 uint64_t *values;
276
277 struct list_head enum_blob_list;
278};
279
280struct drm_crtc;
281struct drm_connector;
282struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500283struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800284struct drm_plane;
Dave Airlief453ba02008-11-07 14:05:41 -0800285
286/**
287 * drm_crtc_funcs - control CRTCs for a given device
Chris Wilsoneb033552011-01-24 15:11:08 +0000288 * @reset: reset CRTC after state has been invalidate (e.g. resume)
Dave Airlief453ba02008-11-07 14:05:41 -0800289 * @dpms: control display power levels
290 * @save: save CRTC state
291 * @resore: restore CRTC state
292 * @lock: lock the CRTC
293 * @unlock: unlock the CRTC
294 * @shadow_allocate: allocate shadow pixmap
295 * @shadow_create: create shadow pixmap for rotation support
296 * @shadow_destroy: free shadow pixmap
297 * @mode_fixup: fixup proposed mode
298 * @mode_set: set the desired mode on the CRTC
299 * @gamma_set: specify color ramp for CRTC
300 * @destroy: deinit and free object.
301 *
302 * The drm_crtc_funcs structure is the central CRTC management structure
303 * in the DRM. Each CRTC controls one or more connectors (note that the name
304 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
305 * connectors, not just CRTs).
306 *
307 * Each driver is responsible for filling out this structure at startup time,
308 * in addition to providing other modesetting features, like i2c and DDC
309 * bus accessors.
310 */
311struct drm_crtc_funcs {
312 /* Save CRTC state */
313 void (*save)(struct drm_crtc *crtc); /* suspend? */
314 /* Restore CRTC state */
315 void (*restore)(struct drm_crtc *crtc); /* resume? */
Chris Wilsoneb033552011-01-24 15:11:08 +0000316 /* Reset CRTC state */
317 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800318
319 /* cursor controls */
320 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
321 uint32_t handle, uint32_t width, uint32_t height);
322 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
323
324 /* Set gamma on the CRTC */
325 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
James Simmons72034252010-08-03 01:33:19 +0100326 uint32_t start, uint32_t size);
Dave Airlief453ba02008-11-07 14:05:41 -0800327 /* Object destroy routine */
328 void (*destroy)(struct drm_crtc *crtc);
329
330 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500331
332 /*
333 * Flip to the given framebuffer. This implements the page
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300334 * flip ioctl described in drm_mode.h, specifically, the
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500335 * implementation must return immediately and block all
336 * rendering to the current fb until the flip has completed.
337 * If userspace set the event flag in the ioctl, the event
338 * argument will point to an event to send back when the flip
339 * completes, otherwise it will be NULL.
340 */
341 int (*page_flip)(struct drm_crtc *crtc,
342 struct drm_framebuffer *fb,
343 struct drm_pending_vblank_event *event);
Dave Airlief453ba02008-11-07 14:05:41 -0800344};
345
346/**
347 * drm_crtc - central CRTC control structure
348 * @enabled: is this CRTC enabled?
349 * @x: x position on screen
350 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800351 * @funcs: CRTC control functions
352 *
353 * Each CRTC may have one or more connectors associated with it. This structure
354 * allows the CRTC to be controlled.
355 */
356struct drm_crtc {
357 struct drm_device *dev;
358 struct list_head head;
359
360 struct drm_mode_object base;
361
362 /* framebuffer the connector is currently bound to */
363 struct drm_framebuffer *fb;
364
365 bool enabled;
366
Mario Kleiner27641c32010-10-23 04:20:23 +0200367 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800368 struct drm_display_mode mode;
369
Mario Kleiner27641c32010-10-23 04:20:23 +0200370 /* Programmed mode in hw, after adjustments for encoders,
371 * crtc, panel scaling etc. Needed for timestamping etc.
372 */
373 struct drm_display_mode hwmode;
374
Dave Airlief453ba02008-11-07 14:05:41 -0800375 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800376 const struct drm_crtc_funcs *funcs;
377
378 /* CRTC gamma size for reporting to userspace */
379 uint32_t gamma_size;
380 uint16_t *gamma_store;
381
Mario Kleiner27641c32010-10-23 04:20:23 +0200382 /* Constants needed for precise vblank and swap timestamping. */
383 s64 framedur_ns, linedur_ns, pixeldur_ns;
384
Dave Airlief453ba02008-11-07 14:05:41 -0800385 /* if you are using the helper */
386 void *helper_private;
387};
388
389
390/**
391 * drm_connector_funcs - control connectors on a given device
392 * @dpms: set power state (see drm_crtc_funcs above)
393 * @save: save connector state
394 * @restore: restore connector state
Chris Wilsoneb033552011-01-24 15:11:08 +0000395 * @reset: reset connector after state has been invalidate (e.g. resume)
Dave Airlief453ba02008-11-07 14:05:41 -0800396 * @mode_valid: is this mode valid on the given connector?
397 * @mode_fixup: try to fixup proposed mode for this connector
398 * @mode_set: set this mode
399 * @detect: is this connector active?
400 * @get_modes: get mode list for this connector
401 * @set_property: property for this connector may need update
402 * @destroy: make object go away
Dave Airlied50ba252009-09-23 14:44:08 +1000403 * @force: notify the driver the connector is forced on
Dave Airlief453ba02008-11-07 14:05:41 -0800404 *
405 * Each CRTC may have one or more connectors attached to it. The functions
406 * below allow the core DRM code to control connectors, enumerate available modes,
407 * etc.
408 */
409struct drm_connector_funcs {
410 void (*dpms)(struct drm_connector *connector, int mode);
411 void (*save)(struct drm_connector *connector);
412 void (*restore)(struct drm_connector *connector);
Chris Wilsoneb033552011-01-24 15:11:08 +0000413 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100414
415 /* Check to see if anything is attached to the connector.
416 * @force is set to false whilst polling, true when checking the
417 * connector due to user request. @force can be used by the driver
418 * to avoid expensive, destructive operations during automated
419 * probing.
420 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100421 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100422 bool force);
Jesse Barnes40a518d2009-01-12 12:05:32 -0800423 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Dave Airlief453ba02008-11-07 14:05:41 -0800424 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
425 uint64_t val);
426 void (*destroy)(struct drm_connector *connector);
Dave Airlied50ba252009-09-23 14:44:08 +1000427 void (*force)(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -0800428};
429
430struct drm_encoder_funcs {
Chris Wilsoneb033552011-01-24 15:11:08 +0000431 void (*reset)(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -0800432 void (*destroy)(struct drm_encoder *encoder);
433};
434
435#define DRM_CONNECTOR_MAX_UMODES 16
436#define DRM_CONNECTOR_MAX_PROPERTY 16
437#define DRM_CONNECTOR_LEN 32
438#define DRM_CONNECTOR_MAX_ENCODER 2
439
440/**
441 * drm_encoder - central DRM encoder structure
442 */
443struct drm_encoder {
444 struct drm_device *dev;
445 struct list_head head;
446
447 struct drm_mode_object base;
448 int encoder_type;
449 uint32_t possible_crtcs;
450 uint32_t possible_clones;
451
452 struct drm_crtc *crtc;
453 const struct drm_encoder_funcs *funcs;
454 void *helper_private;
455};
456
Dave Airlied50ba252009-09-23 14:44:08 +1000457enum drm_connector_force {
458 DRM_FORCE_UNSPECIFIED,
459 DRM_FORCE_OFF,
460 DRM_FORCE_ON, /* force on analog part normally */
461 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
462};
463
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000464/* should we poll this connector for connects and disconnects */
465/* hot plug detectable */
466#define DRM_CONNECTOR_POLL_HPD (1 << 0)
467/* poll for connections */
468#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
469/* can cleanly poll for disconnections without flickering the screen */
470/* DACs should rarely do this without a lot of testing */
471#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
472
Wu Fengguang76adaa342011-09-05 14:23:20 +0800473#define MAX_ELD_BYTES 128
474
Dave Airlief453ba02008-11-07 14:05:41 -0800475/**
476 * drm_connector - central DRM connector control structure
477 * @crtc: CRTC this connector is currently connected to, NULL if none
478 * @interlace_allowed: can this connector handle interlaced modes?
479 * @doublescan_allowed: can this connector handle doublescan?
480 * @available_modes: modes available on this connector (from get_modes() + user)
481 * @initial_x: initial x position for this connector
482 * @initial_y: initial y position for this connector
483 * @status: connector connected?
484 * @funcs: connector control functions
485 *
486 * Each connector may be connected to one or more CRTCs, or may be clonable by
487 * another connector if they can share a CRTC. Each connector also has a specific
488 * position in the broader display (referred to as a 'screen' though it could
489 * span multiple monitors).
490 */
491struct drm_connector {
492 struct drm_device *dev;
493 struct device kdev;
494 struct device_attribute *attr;
495 struct list_head head;
496
497 struct drm_mode_object base;
498
499 int connector_type;
500 int connector_type_id;
501 bool interlace_allowed;
502 bool doublescan_allowed;
503 struct list_head modes; /* list of modes on this connector */
504
505 int initial_x, initial_y;
506 enum drm_connector_status status;
507
508 /* these are modes added by probing with DDC or the BIOS */
509 struct list_head probed_modes;
510
511 struct drm_display_info display_info;
512 const struct drm_connector_funcs *funcs;
513
514 struct list_head user_modes;
515 struct drm_property_blob *edid_blob_ptr;
516 u32 property_ids[DRM_CONNECTOR_MAX_PROPERTY];
517 uint64_t property_values[DRM_CONNECTOR_MAX_PROPERTY];
518
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000519 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
520
Keith Packardc9fb15f2009-05-30 20:42:28 -0700521 /* requested DPMS state */
522 int dpms;
523
Dave Airlief453ba02008-11-07 14:05:41 -0800524 void *helper_private;
525
Dave Airlied50ba252009-09-23 14:44:08 +1000526 /* forced on connector */
527 enum drm_connector_force force;
Dave Airlief453ba02008-11-07 14:05:41 -0800528 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
529 uint32_t force_encoder_id;
530 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +0000531
Wu Fengguang76adaa342011-09-05 14:23:20 +0800532 /* EDID bits */
533 uint8_t eld[MAX_ELD_BYTES];
534 bool dvi_dual;
535 int max_tmds_clock; /* in MHz */
536 bool latency_present[2];
537 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
538 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +0000539 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Dave Airlief453ba02008-11-07 14:05:41 -0800540};
541
542/**
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800543 * drm_plane_funcs - driver plane control functions
544 * @update_plane: update the plane configuration
545 * @disable_plane: shut down the plane
546 * @destroy: clean up plane resources
547 */
548struct drm_plane_funcs {
549 int (*update_plane)(struct drm_plane *plane,
550 struct drm_crtc *crtc, struct drm_framebuffer *fb,
551 int crtc_x, int crtc_y,
552 unsigned int crtc_w, unsigned int crtc_h,
553 uint32_t src_x, uint32_t src_y,
554 uint32_t src_w, uint32_t src_h);
555 int (*disable_plane)(struct drm_plane *plane);
556 void (*destroy)(struct drm_plane *plane);
557};
558
559/**
560 * drm_plane - central DRM plane control structure
561 * @dev: DRM device this plane belongs to
562 * @head: for list management
563 * @base: base mode object
564 * @possible_crtcs: pipes this plane can be bound to
565 * @format_types: array of formats supported by this plane
566 * @format_count: number of formats supported
567 * @crtc: currently bound CRTC
568 * @fb: currently bound fb
569 * @gamma_size: size of gamma table
570 * @gamma_store: gamma correction table
571 * @enabled: enabled flag
572 * @funcs: helper functions
573 * @helper_private: storage for drver layer
574 */
575struct drm_plane {
576 struct drm_device *dev;
577 struct list_head head;
578
579 struct drm_mode_object base;
580
581 uint32_t possible_crtcs;
582 uint32_t *format_types;
583 uint32_t format_count;
584
585 struct drm_crtc *crtc;
586 struct drm_framebuffer *fb;
587
588 /* CRTC gamma size for reporting to userspace */
589 uint32_t gamma_size;
590 uint16_t *gamma_store;
591
592 bool enabled;
593
594 const struct drm_plane_funcs *funcs;
595 void *helper_private;
596};
597
598/**
Dave Airlief453ba02008-11-07 14:05:41 -0800599 * struct drm_mode_set
600 *
601 * Represents a single crtc the connectors that it drives with what mode
602 * and from which framebuffer it scans out from.
603 *
604 * This is used to set modes.
605 */
606struct drm_mode_set {
607 struct list_head head;
608
609 struct drm_framebuffer *fb;
610 struct drm_crtc *crtc;
611 struct drm_display_mode *mode;
612
613 uint32_t x;
614 uint32_t y;
615
616 struct drm_connector **connectors;
617 size_t num_connectors;
618};
619
620/**
621 * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
Dave Airlief453ba02008-11-07 14:05:41 -0800622 */
623struct drm_mode_config_funcs {
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800624 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 +0000625 void (*output_poll_changed)(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800626};
627
628struct drm_mode_group {
629 uint32_t num_crtcs;
630 uint32_t num_encoders;
631 uint32_t num_connectors;
632
633 /* list of object IDs for this group */
634 uint32_t *id_list;
635};
636
637/**
638 * drm_mode_config - Mode configuration control structure
639 *
640 */
641struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +1000642 struct mutex mutex; /* protects configuration (mode lists etc.) */
643 struct mutex idr_mutex; /* for IDR management */
Dave Airlief453ba02008-11-07 14:05:41 -0800644 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
645 /* this is limited to one for now */
646 int num_fb;
647 struct list_head fb_list;
648 int num_connector;
649 struct list_head connector_list;
650 int num_encoder;
651 struct list_head encoder_list;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800652 int num_plane;
653 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800654
655 int num_crtc;
656 struct list_head crtc_list;
657
658 struct list_head property_list;
659
Dave Airlief453ba02008-11-07 14:05:41 -0800660 int min_width, min_height;
661 int max_width, max_height;
662 struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +1100663 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -0800664
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000665 /* output poll support */
666 bool poll_enabled;
Tejun Heo991ea752010-07-20 22:09:02 +0200667 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000668
Dave Airlief453ba02008-11-07 14:05:41 -0800669 /* pointers to standard properties */
670 struct list_head property_blob_list;
671 struct drm_property *edid_property;
672 struct drm_property *dpms_property;
673
674 /* DVI-I properties */
675 struct drm_property *dvi_i_subconnector_property;
676 struct drm_property *dvi_i_select_subconnector_property;
677
678 /* TV properties */
679 struct drm_property *tv_subconnector_property;
680 struct drm_property *tv_select_subconnector_property;
681 struct drm_property *tv_mode_property;
682 struct drm_property *tv_left_margin_property;
683 struct drm_property *tv_right_margin_property;
684 struct drm_property *tv_top_margin_property;
685 struct drm_property *tv_bottom_margin_property;
Francisco Jerezb6b79022009-08-02 04:19:20 +0200686 struct drm_property *tv_brightness_property;
687 struct drm_property *tv_contrast_property;
688 struct drm_property *tv_flicker_reduction_property;
Francisco Jereza75f0232009-08-12 02:30:10 +0200689 struct drm_property *tv_overscan_property;
690 struct drm_property *tv_saturation_property;
691 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -0800692
693 /* Optional properties */
694 struct drm_property *scaling_mode_property;
695 struct drm_property *dithering_mode_property;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000696 struct drm_property *dirty_info_property;
Dave Airlief453ba02008-11-07 14:05:41 -0800697};
698
699#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
700#define obj_to_connector(x) container_of(x, struct drm_connector, base)
701#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
702#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
703#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
704#define obj_to_property(x) container_of(x, struct drm_property, base)
705#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800706#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -0800707
708
709extern void drm_crtc_init(struct drm_device *dev,
710 struct drm_crtc *crtc,
711 const struct drm_crtc_funcs *funcs);
712extern void drm_crtc_cleanup(struct drm_crtc *crtc);
713
714extern void drm_connector_init(struct drm_device *dev,
715 struct drm_connector *connector,
716 const struct drm_connector_funcs *funcs,
717 int connector_type);
718
719extern void drm_connector_cleanup(struct drm_connector *connector);
720
721extern void drm_encoder_init(struct drm_device *dev,
722 struct drm_encoder *encoder,
723 const struct drm_encoder_funcs *funcs,
724 int encoder_type);
725
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800726extern int drm_plane_init(struct drm_device *dev,
727 struct drm_plane *plane,
728 unsigned long possible_crtcs,
729 const struct drm_plane_funcs *funcs,
730 uint32_t *formats, uint32_t format_count);
731extern void drm_plane_cleanup(struct drm_plane *plane);
732
Dave Airlief453ba02008-11-07 14:05:41 -0800733extern void drm_encoder_cleanup(struct drm_encoder *encoder);
734
735extern char *drm_get_connector_name(struct drm_connector *connector);
736extern char *drm_get_dpms_name(int val);
737extern char *drm_get_dvi_i_subconnector_name(int val);
738extern char *drm_get_dvi_i_select_name(int val);
739extern char *drm_get_tv_subconnector_name(int val);
740extern char *drm_get_tv_select_name(int val);
Kristian Høgsbergea39f832009-02-12 14:37:56 -0500741extern void drm_fb_release(struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -0800742extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
743extern struct edid *drm_get_edid(struct drm_connector *connector,
744 struct i2c_adapter *adapter);
Dave Airlief453ba02008-11-07 14:05:41 -0800745extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
746extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
747extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode);
748extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
Chris Wilsonb1f559e2011-01-26 09:49:47 +0000749 const struct drm_display_mode *mode);
Dave Airlief453ba02008-11-07 14:05:41 -0800750extern void drm_mode_debug_printmodeline(struct drm_display_mode *mode);
751extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +0000752extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800753extern void drm_mode_config_cleanup(struct drm_device *dev);
754extern void drm_mode_set_name(struct drm_display_mode *mode);
755extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
756extern int drm_mode_width(struct drm_display_mode *mode);
757extern int drm_mode_height(struct drm_display_mode *mode);
758
759/* for us by fb module */
760extern int drm_mode_attachmode_crtc(struct drm_device *dev,
761 struct drm_crtc *crtc,
762 struct drm_display_mode *mode);
763extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
764
765extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
766extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
767extern void drm_mode_list_concat(struct list_head *head,
768 struct list_head *new);
769extern void drm_mode_validate_size(struct drm_device *dev,
770 struct list_head *mode_list,
771 int maxX, int maxY, int maxPitch);
772extern void drm_mode_prune_invalid(struct drm_device *dev,
773 struct list_head *mode_list, bool verbose);
774extern void drm_mode_sort(struct list_head *mode_list);
Chris Wilsonb1f559e2011-01-26 09:49:47 +0000775extern int drm_mode_hsync(const struct drm_display_mode *mode);
776extern int drm_mode_vrefresh(const struct drm_display_mode *mode);
Dave Airlief453ba02008-11-07 14:05:41 -0800777extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
778 int adjust_flags);
779extern void drm_mode_connector_list_update(struct drm_connector *connector);
780extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
781 struct edid *edid);
782extern int drm_connector_property_set_value(struct drm_connector *connector,
783 struct drm_property *property,
784 uint64_t value);
785extern int drm_connector_property_get_value(struct drm_connector *connector,
786 struct drm_property *property,
787 uint64_t *value);
788extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
789extern void drm_framebuffer_set_object(struct drm_device *dev,
790 unsigned long handle);
791extern int drm_framebuffer_init(struct drm_device *dev,
792 struct drm_framebuffer *fb,
793 const struct drm_framebuffer_funcs *funcs);
794extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
795extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
796extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
797extern void drm_crtc_probe_connector_modes(struct drm_device *dev, int maxX, int maxY);
798extern bool drm_crtc_in_use(struct drm_crtc *crtc);
799
800extern int drm_connector_attach_property(struct drm_connector *connector,
801 struct drm_property *property, uint64_t init_val);
802extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
803 const char *name, int num_values);
804extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
805extern int drm_property_add_enum(struct drm_property *property, int index,
806 uint64_t value, const char *name);
807extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
808extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
809 char *formats[]);
810extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
811extern int drm_mode_create_dithering_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000812extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800813extern char *drm_get_encoder_name(struct drm_encoder *encoder);
814
815extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
816 struct drm_encoder *encoder);
817extern void drm_mode_connector_detach_encoder(struct drm_connector *connector,
818 struct drm_encoder *encoder);
819extern bool drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
820 int gamma_size);
Daniel Vetter7a9c9062009-09-15 22:57:31 +0200821extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
822 uint32_t id, uint32_t type);
Dave Airlief453ba02008-11-07 14:05:41 -0800823/* IOCTLs */
824extern int drm_mode_getresources(struct drm_device *dev,
825 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800826extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
827 struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -0800828extern int drm_mode_getcrtc(struct drm_device *dev,
829 void *data, struct drm_file *file_priv);
830extern int drm_mode_getconnector(struct drm_device *dev,
831 void *data, struct drm_file *file_priv);
832extern int drm_mode_setcrtc(struct drm_device *dev,
833 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800834extern int drm_mode_getplane(struct drm_device *dev,
835 void *data, struct drm_file *file_priv);
836extern int drm_mode_setplane(struct drm_device *dev,
837 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -0800838extern int drm_mode_cursor_ioctl(struct drm_device *dev,
839 void *data, struct drm_file *file_priv);
840extern int drm_mode_addfb(struct drm_device *dev,
841 void *data, struct drm_file *file_priv);
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800842extern int drm_mode_addfb2(struct drm_device *dev,
843 void *data, struct drm_file *file_priv);
844extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlief453ba02008-11-07 14:05:41 -0800845extern int drm_mode_rmfb(struct drm_device *dev,
846 void *data, struct drm_file *file_priv);
847extern int drm_mode_getfb(struct drm_device *dev,
848 void *data, struct drm_file *file_priv);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000849extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
850 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -0800851extern int drm_mode_addmode_ioctl(struct drm_device *dev,
852 void *data, struct drm_file *file_priv);
853extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
854 void *data, struct drm_file *file_priv);
855extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
856 void *data, struct drm_file *file_priv);
857extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
858 void *data, struct drm_file *file_priv);
859
860extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
861 void *data, struct drm_file *file_priv);
862extern int drm_mode_getblob_ioctl(struct drm_device *dev,
863 void *data, struct drm_file *file_priv);
864extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
865 void *data, struct drm_file *file_priv);
866extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
867 void *data, struct drm_file *file_priv);
868extern int drm_mode_replacefb(struct drm_device *dev,
869 void *data, struct drm_file *file_priv);
870extern int drm_mode_getencoder(struct drm_device *dev,
871 void *data, struct drm_file *file_priv);
872extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
873 void *data, struct drm_file *file_priv);
874extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
875 void *data, struct drm_file *file_priv);
Ben Skeggseccaca22011-03-30 05:03:47 +0000876extern u8 *drm_find_cea_extension(struct edid *edid);
Ma Lingf23c20c2009-03-26 19:26:23 +0800877extern bool drm_detect_hdmi_monitor(struct edid *edid);
Zhenyu Wang8fe97902010-09-19 14:27:28 +0800878extern bool drm_detect_monitor_audio(struct edid *edid);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500879extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
880 void *data, struct drm_file *file_priv);
Zhao Yakuid782c3f2009-06-22 13:17:08 +0800881extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
882 int hdisplay, int vdisplay, int vrefresh,
Dave Airlied50ba252009-09-23 14:44:08 +1000883 bool reduced, bool interlaced, bool margins);
Zhao Yakui26bbdad2009-06-22 13:17:09 +0800884extern struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
885 int hdisplay, int vdisplay, int vrefresh,
886 bool interlaced, int margins);
Adam Jackson7a374352010-03-29 21:43:30 +0000887extern struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
888 int hdisplay, int vdisplay, int vrefresh,
889 bool interlaced, int margins, int GTF_M,
890 int GTF_2C, int GTF_K, int GTF_2J);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +0800891extern int drm_add_modes_noedid(struct drm_connector *connector,
892 int hdisplay, int vdisplay);
Alex Deucher3c537882010-02-05 04:21:19 -0500893
Thomas Reim051963d2011-07-29 14:28:57 +0000894extern int drm_edid_header_is_valid(const u8 *raw_edid);
Alex Deucher3c537882010-02-05 04:21:19 -0500895extern bool drm_edid_is_valid(struct edid *edid);
Dave Airlie1d42bbc2010-05-07 05:02:30 +0000896struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
897 int hsize, int vsize, int fresh);
Dave Airlieff72145b2011-02-07 12:16:14 +1000898
899extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
900 void *data, struct drm_file *file_priv);
901extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
902 void *data, struct drm_file *file_priv);
903extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
904 void *data, struct drm_file *file_priv);
Dave Airlie248dbc22011-11-29 20:02:54 +0000905
906extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
907 int *bpp);
Dave Airlief453ba02008-11-07 14:05:41 -0800908#endif /* __DRM_CRTC_H__ */