]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - include/drm/drm_crtc.h
drm: add plane support v3
[mirror_ubuntu-hirsute-kernel.git] / include / drm / drm_crtc.h
CommitLineData
f453ba04
DA
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
28#include <linux/i2c.h>
29#include <linux/spinlock.h>
30#include <linux/types.h>
31#include <linux/idr.h>
32
33#include <linux/fb.h>
34
35struct drm_device;
36struct drm_mode_set;
37struct drm_framebuffer;
38
39
40#define DRM_MODE_OBJECT_CRTC 0xcccccccc
41#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
42#define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
43#define DRM_MODE_OBJECT_MODE 0xdededede
44#define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
45#define DRM_MODE_OBJECT_FB 0xfbfbfbfb
46#define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
8cf5c917 47#define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
f453ba04
DA
48
49struct drm_mode_object {
50 uint32_t id;
51 uint32_t type;
52};
53
54/*
55 * Note on terminology: here, for brevity and convenience, we refer to connector
56 * control chips as 'CRTCs'. They can control any type of connector, VGA, LVDS,
57 * DVI, etc. And 'screen' refers to the whole of the visible display, which
58 * may span multiple monitors (and therefore multiple CRTC and connector
59 * structures).
60 */
61
62enum drm_mode_status {
63 MODE_OK = 0, /* Mode OK */
64 MODE_HSYNC, /* hsync out of range */
65 MODE_VSYNC, /* vsync out of range */
66 MODE_H_ILLEGAL, /* mode has illegal horizontal timings */
67 MODE_V_ILLEGAL, /* mode has illegal horizontal timings */
68 MODE_BAD_WIDTH, /* requires an unsupported linepitch */
25985edc 69 MODE_NOMODE, /* no mode with a matching name */
f453ba04
DA
70 MODE_NO_INTERLACE, /* interlaced mode not supported */
71 MODE_NO_DBLESCAN, /* doublescan mode not supported */
72 MODE_NO_VSCAN, /* multiscan mode not supported */
73 MODE_MEM, /* insufficient video memory */
74 MODE_VIRTUAL_X, /* mode width too large for specified virtual size */
75 MODE_VIRTUAL_Y, /* mode height too large for specified virtual size */
76 MODE_MEM_VIRT, /* insufficient video memory given virtual size */
77 MODE_NOCLOCK, /* no fixed clock available */
78 MODE_CLOCK_HIGH, /* clock required is too high */
79 MODE_CLOCK_LOW, /* clock required is too low */
80 MODE_CLOCK_RANGE, /* clock/mode isn't in a ClockRange */
81 MODE_BAD_HVALUE, /* horizontal timing was out of range */
82 MODE_BAD_VVALUE, /* vertical timing was out of range */
83 MODE_BAD_VSCAN, /* VScan value out of range */
84 MODE_HSYNC_NARROW, /* horizontal sync too narrow */
85 MODE_HSYNC_WIDE, /* horizontal sync too wide */
86 MODE_HBLANK_NARROW, /* horizontal blanking too narrow */
87 MODE_HBLANK_WIDE, /* horizontal blanking too wide */
88 MODE_VSYNC_NARROW, /* vertical sync too narrow */
89 MODE_VSYNC_WIDE, /* vertical sync too wide */
90 MODE_VBLANK_NARROW, /* vertical blanking too narrow */
91 MODE_VBLANK_WIDE, /* vertical blanking too wide */
92 MODE_PANEL, /* exceeds panel dimensions */
93 MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */
94 MODE_ONE_WIDTH, /* only one width is supported */
95 MODE_ONE_HEIGHT, /* only one height is supported */
96 MODE_ONE_SIZE, /* only one resolution is supported */
97 MODE_NO_REDUCED, /* monitor doesn't accept reduced blanking */
98 MODE_UNVERIFIED = -3, /* mode needs to reverified */
99 MODE_BAD = -2, /* unspecified reason */
100 MODE_ERROR = -1 /* error condition */
101};
102
103#define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \
104 DRM_MODE_TYPE_CRTC_C)
105
106#define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
107 .name = nm, .status = 0, .type = (t), .clock = (c), \
108 .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
109 .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
110 .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
111 .vscan = (vs), .flags = (f), .vrefresh = 0
112
113#define CRTC_INTERLACE_HALVE_V 0x1 /* halve V values for interlacing */
114
115struct drm_display_mode {
116 /* Header */
117 struct list_head head;
118 struct drm_mode_object base;
119
120 char name[DRM_DISPLAY_MODE_LEN];
121
122 int connector_count;
123 enum drm_mode_status status;
124 int type;
125
126 /* Proposed mode values */
7ac96a9c 127 int clock; /* in kHz */
f453ba04
DA
128 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
7ac96a9c
AJ
168 int vrefresh; /* in Hz */
169 int hsync; /* in kHz */
f453ba04
DA
170};
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
da05a5a7
JB
187#define DRM_COLOR_FORMAT_RGB444 (1<<0)
188#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
189#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
f453ba04
DA
190/*
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];
fb439640 195
f453ba04
DA
196 /* Physical size */
197 unsigned int width_mm;
198 unsigned int height_mm;
199
f453ba04
DA
200 /* Clock limits FIXME: storage format */
201 unsigned int min_vfreq, max_vfreq;
202 unsigned int min_hfreq, max_hfreq;
203 unsigned int pixel_clock;
3b11228b 204 unsigned int bpc;
f453ba04 205
f453ba04 206 enum subpixel_order subpixel_order;
da05a5a7 207 u32 color_formats;
f453ba04 208
ebec9a7b
JB
209 u8 cea_rev;
210
f453ba04
DA
211 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);
884840aa
JB
219 /**
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 */
02b00162
TH
231 int (*dirty)(struct drm_framebuffer *framebuffer,
232 struct drm_file *file_priv, unsigned flags,
884840aa
JB
233 unsigned color, struct drm_clip_rect *clips,
234 unsigned num_clips);
f453ba04
DA
235};
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;
f453ba04 249 struct list_head filp_head;
785b93ef
DA
250 /* if you are using the helper */
251 void *helper_private;
f453ba04
DA
252};
253
254struct drm_property_blob {
255 struct drm_mode_object base;
256 struct list_head head;
257 unsigned int length;
258 void *data;
259};
260
261struct drm_property_enum {
262 uint64_t value;
263 struct list_head head;
264 char name[DRM_PROP_NAME_LEN];
265};
266
267struct drm_property {
268 struct list_head head;
269 struct drm_mode_object base;
270 uint32_t flags;
271 char name[DRM_PROP_NAME_LEN];
272 uint32_t num_values;
273 uint64_t *values;
274
275 struct list_head enum_blob_list;
276};
277
278struct drm_crtc;
279struct drm_connector;
280struct drm_encoder;
d91d8a3f 281struct drm_pending_vblank_event;
8cf5c917 282struct drm_plane;
f453ba04
DA
283
284/**
285 * drm_crtc_funcs - control CRTCs for a given device
eb033556 286 * @reset: reset CRTC after state has been invalidate (e.g. resume)
f453ba04
DA
287 * @dpms: control display power levels
288 * @save: save CRTC state
289 * @resore: restore CRTC state
290 * @lock: lock the CRTC
291 * @unlock: unlock the CRTC
292 * @shadow_allocate: allocate shadow pixmap
293 * @shadow_create: create shadow pixmap for rotation support
294 * @shadow_destroy: free shadow pixmap
295 * @mode_fixup: fixup proposed mode
296 * @mode_set: set the desired mode on the CRTC
297 * @gamma_set: specify color ramp for CRTC
298 * @destroy: deinit and free object.
299 *
300 * The drm_crtc_funcs structure is the central CRTC management structure
301 * in the DRM. Each CRTC controls one or more connectors (note that the name
302 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
303 * connectors, not just CRTs).
304 *
305 * Each driver is responsible for filling out this structure at startup time,
306 * in addition to providing other modesetting features, like i2c and DDC
307 * bus accessors.
308 */
309struct drm_crtc_funcs {
310 /* Save CRTC state */
311 void (*save)(struct drm_crtc *crtc); /* suspend? */
312 /* Restore CRTC state */
313 void (*restore)(struct drm_crtc *crtc); /* resume? */
eb033556
CW
314 /* Reset CRTC state */
315 void (*reset)(struct drm_crtc *crtc);
f453ba04
DA
316
317 /* cursor controls */
318 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
319 uint32_t handle, uint32_t width, uint32_t height);
320 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
321
322 /* Set gamma on the CRTC */
323 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
7203425a 324 uint32_t start, uint32_t size);
f453ba04
DA
325 /* Object destroy routine */
326 void (*destroy)(struct drm_crtc *crtc);
327
328 int (*set_config)(struct drm_mode_set *set);
d91d8a3f
KH
329
330 /*
331 * Flip to the given framebuffer. This implements the page
25985edc 332 * flip ioctl described in drm_mode.h, specifically, the
d91d8a3f
KH
333 * implementation must return immediately and block all
334 * rendering to the current fb until the flip has completed.
335 * If userspace set the event flag in the ioctl, the event
336 * argument will point to an event to send back when the flip
337 * completes, otherwise it will be NULL.
338 */
339 int (*page_flip)(struct drm_crtc *crtc,
340 struct drm_framebuffer *fb,
341 struct drm_pending_vblank_event *event);
f453ba04
DA
342};
343
344/**
345 * drm_crtc - central CRTC control structure
346 * @enabled: is this CRTC enabled?
347 * @x: x position on screen
348 * @y: y position on screen
f453ba04
DA
349 * @funcs: CRTC control functions
350 *
351 * Each CRTC may have one or more connectors associated with it. This structure
352 * allows the CRTC to be controlled.
353 */
354struct drm_crtc {
355 struct drm_device *dev;
356 struct list_head head;
357
358 struct drm_mode_object base;
359
360 /* framebuffer the connector is currently bound to */
361 struct drm_framebuffer *fb;
362
363 bool enabled;
364
27641c3f 365 /* Requested mode from modesetting. */
f453ba04
DA
366 struct drm_display_mode mode;
367
27641c3f
MK
368 /* Programmed mode in hw, after adjustments for encoders,
369 * crtc, panel scaling etc. Needed for timestamping etc.
370 */
371 struct drm_display_mode hwmode;
372
f453ba04 373 int x, y;
f453ba04
DA
374 const struct drm_crtc_funcs *funcs;
375
376 /* CRTC gamma size for reporting to userspace */
377 uint32_t gamma_size;
378 uint16_t *gamma_store;
379
27641c3f
MK
380 /* Constants needed for precise vblank and swap timestamping. */
381 s64 framedur_ns, linedur_ns, pixeldur_ns;
382
f453ba04
DA
383 /* if you are using the helper */
384 void *helper_private;
385};
386
387
388/**
389 * drm_connector_funcs - control connectors on a given device
390 * @dpms: set power state (see drm_crtc_funcs above)
391 * @save: save connector state
392 * @restore: restore connector state
eb033556 393 * @reset: reset connector after state has been invalidate (e.g. resume)
f453ba04
DA
394 * @mode_valid: is this mode valid on the given connector?
395 * @mode_fixup: try to fixup proposed mode for this connector
396 * @mode_set: set this mode
397 * @detect: is this connector active?
398 * @get_modes: get mode list for this connector
399 * @set_property: property for this connector may need update
400 * @destroy: make object go away
d50ba256 401 * @force: notify the driver the connector is forced on
f453ba04
DA
402 *
403 * Each CRTC may have one or more connectors attached to it. The functions
404 * below allow the core DRM code to control connectors, enumerate available modes,
405 * etc.
406 */
407struct drm_connector_funcs {
408 void (*dpms)(struct drm_connector *connector, int mode);
409 void (*save)(struct drm_connector *connector);
410 void (*restore)(struct drm_connector *connector);
eb033556 411 void (*reset)(struct drm_connector *connector);
930a9e28
CW
412
413 /* Check to see if anything is attached to the connector.
414 * @force is set to false whilst polling, true when checking the
415 * connector due to user request. @force can be used by the driver
416 * to avoid expensive, destructive operations during automated
417 * probing.
418 */
7b334fcb 419 enum drm_connector_status (*detect)(struct drm_connector *connector,
930a9e28 420 bool force);
40a518d9 421 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
f453ba04
DA
422 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
423 uint64_t val);
424 void (*destroy)(struct drm_connector *connector);
d50ba256 425 void (*force)(struct drm_connector *connector);
f453ba04
DA
426};
427
428struct drm_encoder_funcs {
eb033556 429 void (*reset)(struct drm_encoder *encoder);
f453ba04
DA
430 void (*destroy)(struct drm_encoder *encoder);
431};
432
433#define DRM_CONNECTOR_MAX_UMODES 16
434#define DRM_CONNECTOR_MAX_PROPERTY 16
435#define DRM_CONNECTOR_LEN 32
436#define DRM_CONNECTOR_MAX_ENCODER 2
437
438/**
439 * drm_encoder - central DRM encoder structure
440 */
441struct drm_encoder {
442 struct drm_device *dev;
443 struct list_head head;
444
445 struct drm_mode_object base;
446 int encoder_type;
447 uint32_t possible_crtcs;
448 uint32_t possible_clones;
449
450 struct drm_crtc *crtc;
451 const struct drm_encoder_funcs *funcs;
452 void *helper_private;
453};
454
d50ba256
DA
455enum drm_connector_force {
456 DRM_FORCE_UNSPECIFIED,
457 DRM_FORCE_OFF,
458 DRM_FORCE_ON, /* force on analog part normally */
459 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
460};
461
eb1f8e4f
DA
462/* should we poll this connector for connects and disconnects */
463/* hot plug detectable */
464#define DRM_CONNECTOR_POLL_HPD (1 << 0)
465/* poll for connections */
466#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
467/* can cleanly poll for disconnections without flickering the screen */
468/* DACs should rarely do this without a lot of testing */
469#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
470
76adaa34
WF
471#define MAX_ELD_BYTES 128
472
f453ba04
DA
473/**
474 * drm_connector - central DRM connector control structure
475 * @crtc: CRTC this connector is currently connected to, NULL if none
476 * @interlace_allowed: can this connector handle interlaced modes?
477 * @doublescan_allowed: can this connector handle doublescan?
478 * @available_modes: modes available on this connector (from get_modes() + user)
479 * @initial_x: initial x position for this connector
480 * @initial_y: initial y position for this connector
481 * @status: connector connected?
482 * @funcs: connector control functions
483 *
484 * Each connector may be connected to one or more CRTCs, or may be clonable by
485 * another connector if they can share a CRTC. Each connector also has a specific
486 * position in the broader display (referred to as a 'screen' though it could
487 * span multiple monitors).
488 */
489struct drm_connector {
490 struct drm_device *dev;
491 struct device kdev;
492 struct device_attribute *attr;
493 struct list_head head;
494
495 struct drm_mode_object base;
496
497 int connector_type;
498 int connector_type_id;
499 bool interlace_allowed;
500 bool doublescan_allowed;
501 struct list_head modes; /* list of modes on this connector */
502
503 int initial_x, initial_y;
504 enum drm_connector_status status;
505
506 /* these are modes added by probing with DDC or the BIOS */
507 struct list_head probed_modes;
508
509 struct drm_display_info display_info;
510 const struct drm_connector_funcs *funcs;
511
512 struct list_head user_modes;
513 struct drm_property_blob *edid_blob_ptr;
514 u32 property_ids[DRM_CONNECTOR_MAX_PROPERTY];
515 uint64_t property_values[DRM_CONNECTOR_MAX_PROPERTY];
516
eb1f8e4f
DA
517 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
518
c9fb15f6
KP
519 /* requested DPMS state */
520 int dpms;
521
f453ba04
DA
522 void *helper_private;
523
d50ba256
DA
524 /* forced on connector */
525 enum drm_connector_force force;
f453ba04
DA
526 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
527 uint32_t force_encoder_id;
528 struct drm_encoder *encoder; /* currently active encoder */
4a9a8b71 529
76adaa34
WF
530 /* EDID bits */
531 uint8_t eld[MAX_ELD_BYTES];
532 bool dvi_dual;
533 int max_tmds_clock; /* in MHz */
534 bool latency_present[2];
535 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
536 int audio_latency[2];
4a9a8b71 537 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
f453ba04
DA
538};
539
8cf5c917
JB
540/**
541 * drm_plane_funcs - driver plane control functions
542 * @update_plane: update the plane configuration
543 * @disable_plane: shut down the plane
544 * @destroy: clean up plane resources
545 */
546struct drm_plane_funcs {
547 int (*update_plane)(struct drm_plane *plane,
548 struct drm_crtc *crtc, struct drm_framebuffer *fb,
549 int crtc_x, int crtc_y,
550 unsigned int crtc_w, unsigned int crtc_h,
551 uint32_t src_x, uint32_t src_y,
552 uint32_t src_w, uint32_t src_h);
553 int (*disable_plane)(struct drm_plane *plane);
554 void (*destroy)(struct drm_plane *plane);
555};
556
557/**
558 * drm_plane - central DRM plane control structure
559 * @dev: DRM device this plane belongs to
560 * @head: for list management
561 * @base: base mode object
562 * @possible_crtcs: pipes this plane can be bound to
563 * @format_types: array of formats supported by this plane
564 * @format_count: number of formats supported
565 * @crtc: currently bound CRTC
566 * @fb: currently bound fb
567 * @gamma_size: size of gamma table
568 * @gamma_store: gamma correction table
569 * @enabled: enabled flag
570 * @funcs: helper functions
571 * @helper_private: storage for drver layer
572 */
573struct drm_plane {
574 struct drm_device *dev;
575 struct list_head head;
576
577 struct drm_mode_object base;
578
579 uint32_t possible_crtcs;
580 uint32_t *format_types;
581 uint32_t format_count;
582
583 struct drm_crtc *crtc;
584 struct drm_framebuffer *fb;
585
586 /* CRTC gamma size for reporting to userspace */
587 uint32_t gamma_size;
588 uint16_t *gamma_store;
589
590 bool enabled;
591
592 const struct drm_plane_funcs *funcs;
593 void *helper_private;
594};
595
f453ba04
DA
596/**
597 * struct drm_mode_set
598 *
599 * Represents a single crtc the connectors that it drives with what mode
600 * and from which framebuffer it scans out from.
601 *
602 * This is used to set modes.
603 */
604struct drm_mode_set {
605 struct list_head head;
606
607 struct drm_framebuffer *fb;
608 struct drm_crtc *crtc;
609 struct drm_display_mode *mode;
610
611 uint32_t x;
612 uint32_t y;
613
614 struct drm_connector **connectors;
615 size_t num_connectors;
616};
617
618/**
619 * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
f453ba04
DA
620 */
621struct drm_mode_config_funcs {
f453ba04 622 struct drm_framebuffer *(*fb_create)(struct drm_device *dev, struct drm_file *file_priv, struct drm_mode_fb_cmd *mode_cmd);
eb1f8e4f 623 void (*output_poll_changed)(struct drm_device *dev);
f453ba04
DA
624};
625
626struct drm_mode_group {
627 uint32_t num_crtcs;
628 uint32_t num_encoders;
629 uint32_t num_connectors;
630
631 /* list of object IDs for this group */
632 uint32_t *id_list;
633};
634
635/**
636 * drm_mode_config - Mode configuration control structure
637 *
638 */
639struct drm_mode_config {
ad2563c2
JB
640 struct mutex mutex; /* protects configuration (mode lists etc.) */
641 struct mutex idr_mutex; /* for IDR management */
f453ba04
DA
642 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
643 /* this is limited to one for now */
644 int num_fb;
645 struct list_head fb_list;
646 int num_connector;
647 struct list_head connector_list;
648 int num_encoder;
649 struct list_head encoder_list;
8cf5c917
JB
650 int num_plane;
651 struct list_head plane_list;
f453ba04
DA
652
653 int num_crtc;
654 struct list_head crtc_list;
655
656 struct list_head property_list;
657
f453ba04
DA
658 int min_width, min_height;
659 int max_width, max_height;
660 struct drm_mode_config_funcs *funcs;
d883f7f1 661 resource_size_t fb_base;
f453ba04 662
eb1f8e4f
DA
663 /* output poll support */
664 bool poll_enabled;
991ea75c 665 struct delayed_work output_poll_work;
eb1f8e4f 666
f453ba04
DA
667 /* pointers to standard properties */
668 struct list_head property_blob_list;
669 struct drm_property *edid_property;
670 struct drm_property *dpms_property;
671
672 /* DVI-I properties */
673 struct drm_property *dvi_i_subconnector_property;
674 struct drm_property *dvi_i_select_subconnector_property;
675
676 /* TV properties */
677 struct drm_property *tv_subconnector_property;
678 struct drm_property *tv_select_subconnector_property;
679 struct drm_property *tv_mode_property;
680 struct drm_property *tv_left_margin_property;
681 struct drm_property *tv_right_margin_property;
682 struct drm_property *tv_top_margin_property;
683 struct drm_property *tv_bottom_margin_property;
b6b7902e
FJ
684 struct drm_property *tv_brightness_property;
685 struct drm_property *tv_contrast_property;
686 struct drm_property *tv_flicker_reduction_property;
a75f0236
FJ
687 struct drm_property *tv_overscan_property;
688 struct drm_property *tv_saturation_property;
689 struct drm_property *tv_hue_property;
f453ba04
DA
690
691 /* Optional properties */
692 struct drm_property *scaling_mode_property;
693 struct drm_property *dithering_mode_property;
884840aa 694 struct drm_property *dirty_info_property;
f453ba04
DA
695};
696
697#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
698#define obj_to_connector(x) container_of(x, struct drm_connector, base)
699#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
700#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
701#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
702#define obj_to_property(x) container_of(x, struct drm_property, base)
703#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
8cf5c917 704#define obj_to_plane(x) container_of(x, struct drm_plane, base)
f453ba04
DA
705
706
707extern void drm_crtc_init(struct drm_device *dev,
708 struct drm_crtc *crtc,
709 const struct drm_crtc_funcs *funcs);
710extern void drm_crtc_cleanup(struct drm_crtc *crtc);
711
712extern void drm_connector_init(struct drm_device *dev,
713 struct drm_connector *connector,
714 const struct drm_connector_funcs *funcs,
715 int connector_type);
716
717extern void drm_connector_cleanup(struct drm_connector *connector);
718
719extern void drm_encoder_init(struct drm_device *dev,
720 struct drm_encoder *encoder,
721 const struct drm_encoder_funcs *funcs,
722 int encoder_type);
723
8cf5c917
JB
724extern int drm_plane_init(struct drm_device *dev,
725 struct drm_plane *plane,
726 unsigned long possible_crtcs,
727 const struct drm_plane_funcs *funcs,
728 uint32_t *formats, uint32_t format_count);
729extern void drm_plane_cleanup(struct drm_plane *plane);
730
f453ba04
DA
731extern void drm_encoder_cleanup(struct drm_encoder *encoder);
732
733extern char *drm_get_connector_name(struct drm_connector *connector);
734extern char *drm_get_dpms_name(int val);
735extern char *drm_get_dvi_i_subconnector_name(int val);
736extern char *drm_get_dvi_i_select_name(int val);
737extern char *drm_get_tv_subconnector_name(int val);
738extern char *drm_get_tv_select_name(int val);
ea39f835 739extern void drm_fb_release(struct drm_file *file_priv);
f453ba04
DA
740extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
741extern struct edid *drm_get_edid(struct drm_connector *connector,
742 struct i2c_adapter *adapter);
f453ba04
DA
743extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
744extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
745extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode);
746extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
b1f559ec 747 const struct drm_display_mode *mode);
f453ba04
DA
748extern void drm_mode_debug_printmodeline(struct drm_display_mode *mode);
749extern void drm_mode_config_init(struct drm_device *dev);
eb033556 750extern void drm_mode_config_reset(struct drm_device *dev);
f453ba04
DA
751extern void drm_mode_config_cleanup(struct drm_device *dev);
752extern void drm_mode_set_name(struct drm_display_mode *mode);
753extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
754extern int drm_mode_width(struct drm_display_mode *mode);
755extern int drm_mode_height(struct drm_display_mode *mode);
756
757/* for us by fb module */
758extern int drm_mode_attachmode_crtc(struct drm_device *dev,
759 struct drm_crtc *crtc,
760 struct drm_display_mode *mode);
761extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
762
763extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
764extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
765extern void drm_mode_list_concat(struct list_head *head,
766 struct list_head *new);
767extern void drm_mode_validate_size(struct drm_device *dev,
768 struct list_head *mode_list,
769 int maxX, int maxY, int maxPitch);
770extern void drm_mode_prune_invalid(struct drm_device *dev,
771 struct list_head *mode_list, bool verbose);
772extern void drm_mode_sort(struct list_head *mode_list);
b1f559ec
CW
773extern int drm_mode_hsync(const struct drm_display_mode *mode);
774extern int drm_mode_vrefresh(const struct drm_display_mode *mode);
f453ba04
DA
775extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
776 int adjust_flags);
777extern void drm_mode_connector_list_update(struct drm_connector *connector);
778extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
779 struct edid *edid);
780extern int drm_connector_property_set_value(struct drm_connector *connector,
781 struct drm_property *property,
782 uint64_t value);
783extern int drm_connector_property_get_value(struct drm_connector *connector,
784 struct drm_property *property,
785 uint64_t *value);
786extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
787extern void drm_framebuffer_set_object(struct drm_device *dev,
788 unsigned long handle);
789extern int drm_framebuffer_init(struct drm_device *dev,
790 struct drm_framebuffer *fb,
791 const struct drm_framebuffer_funcs *funcs);
792extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
793extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
794extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
795extern void drm_crtc_probe_connector_modes(struct drm_device *dev, int maxX, int maxY);
796extern bool drm_crtc_in_use(struct drm_crtc *crtc);
797
798extern int drm_connector_attach_property(struct drm_connector *connector,
799 struct drm_property *property, uint64_t init_val);
800extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
801 const char *name, int num_values);
802extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
803extern int drm_property_add_enum(struct drm_property *property, int index,
804 uint64_t value, const char *name);
805extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
806extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
807 char *formats[]);
808extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
809extern int drm_mode_create_dithering_property(struct drm_device *dev);
884840aa 810extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
f453ba04
DA
811extern char *drm_get_encoder_name(struct drm_encoder *encoder);
812
813extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
814 struct drm_encoder *encoder);
815extern void drm_mode_connector_detach_encoder(struct drm_connector *connector,
816 struct drm_encoder *encoder);
817extern bool drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
818 int gamma_size);
7a9c9060
DV
819extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
820 uint32_t id, uint32_t type);
f453ba04
DA
821/* IOCTLs */
822extern int drm_mode_getresources(struct drm_device *dev,
823 void *data, struct drm_file *file_priv);
8cf5c917
JB
824extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
825 struct drm_file *file_priv);
f453ba04
DA
826extern int drm_mode_getcrtc(struct drm_device *dev,
827 void *data, struct drm_file *file_priv);
828extern int drm_mode_getconnector(struct drm_device *dev,
829 void *data, struct drm_file *file_priv);
830extern int drm_mode_setcrtc(struct drm_device *dev,
831 void *data, struct drm_file *file_priv);
8cf5c917
JB
832extern int drm_mode_getplane(struct drm_device *dev,
833 void *data, struct drm_file *file_priv);
834extern int drm_mode_setplane(struct drm_device *dev,
835 void *data, struct drm_file *file_priv);
f453ba04
DA
836extern int drm_mode_cursor_ioctl(struct drm_device *dev,
837 void *data, struct drm_file *file_priv);
838extern int drm_mode_addfb(struct drm_device *dev,
839 void *data, struct drm_file *file_priv);
840extern int drm_mode_rmfb(struct drm_device *dev,
841 void *data, struct drm_file *file_priv);
842extern int drm_mode_getfb(struct drm_device *dev,
843 void *data, struct drm_file *file_priv);
884840aa
JB
844extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
845 void *data, struct drm_file *file_priv);
f453ba04
DA
846extern int drm_mode_addmode_ioctl(struct drm_device *dev,
847 void *data, struct drm_file *file_priv);
848extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
849 void *data, struct drm_file *file_priv);
850extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
851 void *data, struct drm_file *file_priv);
852extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
853 void *data, struct drm_file *file_priv);
854
855extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
856 void *data, struct drm_file *file_priv);
857extern int drm_mode_getblob_ioctl(struct drm_device *dev,
858 void *data, struct drm_file *file_priv);
859extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
860 void *data, struct drm_file *file_priv);
861extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
862 void *data, struct drm_file *file_priv);
863extern int drm_mode_replacefb(struct drm_device *dev,
864 void *data, struct drm_file *file_priv);
865extern int drm_mode_getencoder(struct drm_device *dev,
866 void *data, struct drm_file *file_priv);
867extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
868 void *data, struct drm_file *file_priv);
869extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
870 void *data, struct drm_file *file_priv);
eccaca28 871extern u8 *drm_find_cea_extension(struct edid *edid);
f23c20c8 872extern bool drm_detect_hdmi_monitor(struct edid *edid);
8fe9790d 873extern bool drm_detect_monitor_audio(struct edid *edid);
d91d8a3f
KH
874extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
875 void *data, struct drm_file *file_priv);
d782c3f9
ZY
876extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
877 int hdisplay, int vdisplay, int vrefresh,
d50ba256 878 bool reduced, bool interlaced, bool margins);
26bbdada
ZY
879extern struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
880 int hdisplay, int vdisplay, int vrefresh,
881 bool interlaced, int margins);
7a374350
AJ
882extern struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
883 int hdisplay, int vdisplay, int vrefresh,
884 bool interlaced, int margins, int GTF_M,
885 int GTF_2C, int GTF_K, int GTF_2J);
f0fda0a4
ZY
886extern int drm_add_modes_noedid(struct drm_connector *connector,
887 int hdisplay, int vdisplay);
3c537889 888
051963d4 889extern int drm_edid_header_is_valid(const u8 *raw_edid);
3c537889 890extern bool drm_edid_is_valid(struct edid *edid);
1d42bbc8
DA
891struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
892 int hsize, int vsize, int fresh);
ff72145b
DA
893
894extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
895 void *data, struct drm_file *file_priv);
896extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
897 void *data, struct drm_file *file_priv);
898extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
899 void *data, struct drm_file *file_priv);
f453ba04 900#endif /* __DRM_CRTC_H__ */