Merge branch 'vendor/GDB'
[dragonfly.git] / sys / dev / drm / include / drm / drm_crtc.h
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  * $FreeBSD: src/sys/dev/drm2/drm_crtc.h,v 1.1 2012/05/22 11:07:44 kib Exp $
26  */
27 #ifndef __DRM_CRTC_H__
28 #define __DRM_CRTC_H__
29
30 #include <linux/idr.h>
31
32 #include "drm_gem_names.h"
33 #include <uapi_drm/drm_fourcc.h>
34
35 struct drm_device;
36 struct drm_mode_set;
37 struct drm_framebuffer;
38 struct i2c_adapter;
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
47 #define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
48
49 struct 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
62 enum drm_mode_status {
63     MODE_OK     = 0,    /* Mode OK */
64     MODE_HSYNC,         /* hsync out of range */
65     MODE_VSYNC,         /* vsync out of range */
66     MODE_H_ILLEGAL,     /* mode has illegal horizontal timings */
67     MODE_V_ILLEGAL,     /* mode has illegal horizontal timings */
68     MODE_BAD_WIDTH,     /* requires an unsupported linepitch */
69     MODE_NOMODE,        /* no mode with a maching name */
70     MODE_NO_INTERLACE,  /* interlaced mode not supported */
71     MODE_NO_DBLESCAN,   /* doublescan mode not supported */
72     MODE_NO_VSCAN,      /* multiscan mode not supported */
73     MODE_MEM,           /* insufficient video memory */
74     MODE_VIRTUAL_X,     /* mode width too large for specified virtual size */
75     MODE_VIRTUAL_Y,     /* mode height too large for specified virtual size */
76     MODE_MEM_VIRT,      /* insufficient video memory given virtual size */
77     MODE_NOCLOCK,       /* no fixed clock available */
78     MODE_CLOCK_HIGH,    /* clock required is too high */
79     MODE_CLOCK_LOW,     /* clock required is too low */
80     MODE_CLOCK_RANGE,   /* clock/mode isn't in a ClockRange */
81     MODE_BAD_HVALUE,    /* horizontal timing was out of range */
82     MODE_BAD_VVALUE,    /* vertical timing was out of range */
83     MODE_BAD_VSCAN,     /* VScan value out of range */
84     MODE_HSYNC_NARROW,  /* horizontal sync too narrow */
85     MODE_HSYNC_WIDE,    /* horizontal sync too wide */
86     MODE_HBLANK_NARROW, /* horizontal blanking too narrow */
87     MODE_HBLANK_WIDE,   /* horizontal blanking too wide */
88     MODE_VSYNC_NARROW,  /* vertical sync too narrow */
89     MODE_VSYNC_WIDE,    /* vertical sync too wide */
90     MODE_VBLANK_NARROW, /* vertical blanking too narrow */
91     MODE_VBLANK_WIDE,   /* vertical blanking too wide */
92     MODE_PANEL,         /* exceeds panel dimensions */
93     MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */
94     MODE_ONE_WIDTH,     /* only one width is supported */
95     MODE_ONE_HEIGHT,    /* only one height is supported */
96     MODE_ONE_SIZE,      /* only one resolution is supported */
97     MODE_NO_REDUCED,    /* monitor doesn't accept reduced blanking */
98     MODE_UNVERIFIED = -3, /* mode needs to reverified */
99     MODE_BAD = -2,      /* unspecified reason */
100     MODE_ERROR  = -1    /* error condition */
101 };
102
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
115 struct 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 */
127         int clock;              /* in kHz */
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
168         int vrefresh;           /* in Hz */
169         int hsync;              /* in kHz */
170 };
171
172 enum drm_connector_status {
173         connector_status_connected = 1,
174         connector_status_disconnected = 2,
175         connector_status_unknown = 3,
176 };
177
178 enum subpixel_order {
179         SubPixelUnknown = 0,
180         SubPixelHorizontalRGB,
181         SubPixelHorizontalBGR,
182         SubPixelVerticalRGB,
183         SubPixelVerticalBGR,
184         SubPixelNone,
185 };
186
187 #define DRM_COLOR_FORMAT_RGB444         (1<<0)
188 #define DRM_COLOR_FORMAT_YCRCB444       (1<<1)
189 #define DRM_COLOR_FORMAT_YCRCB422       (1<<2)
190 /*
191  * Describes a given display (e.g. CRT or flat panel) and its limitations.
192  */
193 struct drm_display_info {
194         char name[DRM_DISPLAY_INFO_LEN];
195
196         /* Physical size */
197         unsigned int width_mm;
198         unsigned int height_mm;
199
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;
204         unsigned int bpc;
205
206         enum subpixel_order subpixel_order;
207         u32 color_formats;
208
209         u8 cea_rev;
210
211         char *raw_edid; /* if any */
212 };
213
214 struct 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);
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          */
231         int (*dirty)(struct drm_framebuffer *framebuffer,
232                      struct drm_file *file_priv, unsigned flags,
233                      unsigned color, struct drm_clip_rect *clips,
234                      unsigned num_clips);
235 };
236
237 struct 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 pitches[4];
243         unsigned int offsets[4];
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;
250         uint32_t pixel_format; /* fourcc format */
251         struct list_head filp_head;
252         /* if you are using the helper */
253         void *helper_private;
254 };
255
256 struct drm_property_blob {
257         struct drm_mode_object base;
258         struct list_head head;
259         unsigned int length;
260         unsigned char data[];
261 };
262
263 struct drm_property_enum {
264         uint64_t value;
265         struct list_head head;
266         char name[DRM_PROP_NAME_LEN];
267 };
268
269 struct 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
280 struct drm_crtc;
281 struct drm_connector;
282 struct drm_encoder;
283 struct drm_pending_vblank_event;
284 struct drm_plane;
285
286 /**
287  * drm_crtc_funcs - control CRTCs for a given device
288  * @reset: reset CRTC after state has been invalidate (e.g. resume)
289  * @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  */
311 struct 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? */
316         /* Reset CRTC state */
317         void (*reset)(struct drm_crtc *crtc);
318
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,
326                           uint32_t start, uint32_t size);
327         /* Object destroy routine */
328         void (*destroy)(struct drm_crtc *crtc);
329
330         int (*set_config)(struct drm_mode_set *set);
331
332         /*
333          * Flip to the given framebuffer.  This implements the page
334          * flip ioctl descibed in drm_mode.h, specifically, the
335          * 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);
344 };
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
351  * @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  */
356 struct 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
367         /* Requested mode from modesetting. */
368         struct drm_display_mode mode;
369
370         /* 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
375         int x, y;
376         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
382         /* Constants needed for precise vblank and swap timestamping. */
383         int64_t framedur_ns, linedur_ns, pixeldur_ns;
384
385         /* 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
395  * @reset: reset connector after state has been invalidate (e.g. resume)
396  * @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
403  * @force: notify the driver the connector is forced on
404  *
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  */
409 struct 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);
413         void (*reset)(struct drm_connector *connector);
414
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          */
421         enum drm_connector_status (*detect)(struct drm_connector *connector,
422                                             bool force);
423         int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
424         int (*set_property)(struct drm_connector *connector, struct drm_property *property,
425                              uint64_t val);
426         void (*destroy)(struct drm_connector *connector);
427         void (*force)(struct drm_connector *connector);
428 };
429
430 struct drm_encoder_funcs {
431         void (*reset)(struct drm_encoder *encoder);
432         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  */
443 struct 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
457 enum 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
464 /* 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
473 #define MAX_ELD_BYTES   128
474
475 /**
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  */
491 struct drm_connector {
492         struct drm_device *dev;
493         /* struct device kdev; XXXKIB */
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
519         uint8_t polled; /* DRM_CONNECTOR_POLL_* */
520
521         /* requested DPMS state */
522         int dpms;
523
524         void *helper_private;
525
526         /* forced on connector */
527         enum drm_connector_force force;
528         uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
529         uint32_t force_encoder_id;
530         struct drm_encoder *encoder; /* currently active encoder */
531
532         /* 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];
539
540         int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
541 };
542
543 /**
544  * drm_plane_funcs - driver plane control functions
545  * @update_plane: update the plane configuration
546  * @disable_plane: shut down the plane
547  * @destroy: clean up plane resources
548  */
549 struct drm_plane_funcs {
550         int (*update_plane)(struct drm_plane *plane,
551                             struct drm_crtc *crtc, struct drm_framebuffer *fb,
552                             int crtc_x, int crtc_y,
553                             unsigned int crtc_w, unsigned int crtc_h,
554                             uint32_t src_x, uint32_t src_y,
555                             uint32_t src_w, uint32_t src_h);
556         int (*disable_plane)(struct drm_plane *plane);
557         void (*destroy)(struct drm_plane *plane);
558 };
559
560 /**
561  * drm_plane - central DRM plane control structure
562  * @dev: DRM device this plane belongs to
563  * @head: for list management
564  * @base: base mode object
565  * @possible_crtcs: pipes this plane can be bound to
566  * @format_types: array of formats supported by this plane
567  * @format_count: number of formats supported
568  * @crtc: currently bound CRTC
569  * @fb: currently bound fb
570  * @gamma_size: size of gamma table
571  * @gamma_store: gamma correction table
572  * @enabled: enabled flag
573  * @funcs: helper functions
574  * @helper_private: storage for drver layer
575  */
576 struct drm_plane {
577         struct drm_device *dev;
578         struct list_head head;
579
580         struct drm_mode_object base;
581
582         uint32_t possible_crtcs;
583         uint32_t *format_types;
584         uint32_t format_count;
585
586         struct drm_crtc *crtc;
587         struct drm_framebuffer *fb;
588
589         /* CRTC gamma size for reporting to userspace */
590         uint32_t gamma_size;
591         uint16_t *gamma_store;
592
593         bool enabled;
594
595         const struct drm_plane_funcs *funcs;
596         void *helper_private;
597 };
598
599 /**
600  * struct drm_mode_set
601  *
602  * Represents a single crtc the connectors that it drives with what mode
603  * and from which framebuffer it scans out from.
604  *
605  * This is used to set modes.
606  */
607 struct drm_mode_set {
608         struct list_head head;
609
610         struct drm_framebuffer *fb;
611         struct drm_crtc *crtc;
612         struct drm_display_mode *mode;
613
614         uint32_t x;
615         uint32_t y;
616
617         struct drm_connector **connectors;
618         size_t num_connectors;
619 };
620
621 /**
622  * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
623  */
624 struct drm_mode_config_funcs {
625         int (*fb_create)(struct drm_device *dev,
626             struct drm_file *file_priv, struct drm_mode_fb_cmd2 *mode_cmd,
627             struct drm_framebuffer **res);
628         void (*output_poll_changed)(struct drm_device *dev);
629 };
630
631 struct drm_mode_group {
632         uint32_t num_crtcs;
633         uint32_t num_encoders;
634         uint32_t num_connectors;
635
636         /* list of object IDs for this group */
637         uint32_t *id_list;
638 };
639
640 /**
641  * drm_mode_config - Mode configuration control structure
642  * @mutex: mutex protecting KMS related lists and structures
643  * @idr_mutex: mutex for KMS ID allocation and management
644  * @crtc_idr: main KMS ID tracking object
645  * @num_fb: number of fbs available
646  * @fb_list: list of framebuffers available
647  * @num_connector: number of connectors on this device
648  * @connector_list: list of connector objects
649  * @num_encoder: number of encoders on this device
650  * @encoder_list: list of encoder objects
651  * @num_crtc: number of CRTCs on this device
652  * @crtc_list: list of CRTC objects
653  * @min_width: minimum pixel width on this device
654  * @min_height: minimum pixel height on this device
655  * @max_width: maximum pixel width on this device
656  * @max_height: maximum pixel height on this device
657  * @funcs: core driver provided mode setting functions
658  * @fb_base: base address of the framebuffer
659  * @poll_enabled: track polling status for this device
660  * @output_poll_work: delayed work for polling in process context
661  * @*_property: core property tracking
662  *
663  * Core mode resource tracking structure.  All CRTC, encoders, and connectors
664  * enumerated by the driver are added here, as are global properties.  Some
665  * global restrictions are also here, e.g. dimension restrictions.
666  */
667 struct drm_mode_config {
668         struct lock lock; /* protects configuration (mode lists etc.) */
669         struct spinlock idr_mutex; /* for IDR management */
670         struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
671         /* this is limited to one for now */
672         int num_fb;
673         struct list_head fb_list;
674         int num_connector;
675         struct list_head connector_list;
676         int num_encoder;
677         struct list_head encoder_list;
678         int num_plane;
679         struct list_head plane_list;
680
681         int num_crtc;
682         struct list_head crtc_list;
683
684         struct list_head property_list;
685
686         int min_width, min_height;
687         int max_width, max_height;
688         const struct drm_mode_config_funcs *funcs;
689         resource_size_t fb_base;
690
691         /* output poll support */
692         bool poll_enabled;
693         struct timeout_task output_poll_task;
694
695         /* pointers to standard properties */
696         struct list_head property_blob_list;
697         struct drm_property *edid_property;
698         struct drm_property *dpms_property;
699
700         /* DVI-I properties */
701         struct drm_property *dvi_i_subconnector_property;
702         struct drm_property *dvi_i_select_subconnector_property;
703
704         /* TV properties */
705         struct drm_property *tv_subconnector_property;
706         struct drm_property *tv_select_subconnector_property;
707         struct drm_property *tv_mode_property;
708         struct drm_property *tv_left_margin_property;
709         struct drm_property *tv_right_margin_property;
710         struct drm_property *tv_top_margin_property;
711         struct drm_property *tv_bottom_margin_property;
712         struct drm_property *tv_brightness_property;
713         struct drm_property *tv_contrast_property;
714         struct drm_property *tv_flicker_reduction_property;
715         struct drm_property *tv_overscan_property;
716         struct drm_property *tv_saturation_property;
717         struct drm_property *tv_hue_property;
718
719         /* Optional properties */
720         struct drm_property *scaling_mode_property;
721         struct drm_property *dithering_mode_property;
722         struct drm_property *dirty_info_property;
723
724         /* dumb ioctl parameters */
725         uint32_t preferred_depth, prefer_shadow;
726 };
727
728 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
729 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
730 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
731 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
732 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
733 #define obj_to_property(x) container_of(x, struct drm_property, base)
734 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
735 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
736
737 struct drm_prop_enum_list {
738         int type;
739         char *name;
740 };
741
742 #if defined(MODE_SETTING_LOCKING_IS_NOT_BROKEN)
743 #define DRM_MODE_CONFIG_ASSERT_LOCKED(dev) \
744         sx_assert(&dev->mode_config.mutex, SA_XLOCKED)
745 #else
746 #define DRM_MODE_CONFIG_ASSERT_LOCKED(dev)
747 #endif
748
749 extern char *drm_get_dirty_info_name(int val);
750 extern char *drm_get_connector_status_name(enum drm_connector_status status);
751
752 extern int drm_crtc_init(struct drm_device *dev,
753                          struct drm_crtc *crtc,
754                          const struct drm_crtc_funcs *funcs);
755 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
756
757 extern int drm_connector_init(struct drm_device *dev,
758                               struct drm_connector *connector,
759                               const struct drm_connector_funcs *funcs,
760                               int connector_type);
761
762 extern void drm_connector_cleanup(struct drm_connector *connector);
763
764 extern int drm_encoder_init(struct drm_device *dev,
765                             struct drm_encoder *encoder,
766                             const struct drm_encoder_funcs *funcs,
767                             int encoder_type);
768
769 extern int drm_plane_init(struct drm_device *dev,
770                           struct drm_plane *plane,
771                           unsigned long possible_crtcs,
772                           const struct drm_plane_funcs *funcs,
773                           const uint32_t *formats, uint32_t format_count,
774                           bool priv);
775 extern void drm_plane_cleanup(struct drm_plane *plane);
776
777 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
778
779 extern char *drm_get_connector_name(struct drm_connector *connector);
780 extern char *drm_get_dpms_name(int val);
781 extern char *drm_get_dvi_i_subconnector_name(int val);
782 extern char *drm_get_dvi_i_select_name(int val);
783 extern char *drm_get_tv_subconnector_name(int val);
784 extern char *drm_get_tv_select_name(int val);
785 extern void drm_fb_release(struct drm_file *file_priv);
786 extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
787 extern struct edid *drm_get_edid(struct drm_connector *connector,
788                                  device_t adapter);
789 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
790 extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
791 extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode);
792 extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
793     const struct drm_display_mode *mode);
794 extern void drm_mode_debug_printmodeline(struct drm_display_mode *mode);
795 extern void drm_mode_config_init(struct drm_device *dev);
796 extern void drm_mode_config_reset(struct drm_device *dev);
797 extern void drm_mode_config_cleanup(struct drm_device *dev);
798 extern void drm_mode_set_name(struct drm_display_mode *mode);
799 extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
800 extern int drm_mode_width(struct drm_display_mode *mode);
801 extern int drm_mode_height(struct drm_display_mode *mode);
802
803 /* for us by fb module */
804 extern int drm_mode_attachmode_crtc(struct drm_device *dev,
805                                     struct drm_crtc *crtc,
806                                     const struct drm_display_mode *mode);
807 extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
808
809 extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
810 extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
811 extern void drm_mode_list_concat(struct list_head *head,
812                                  struct list_head *new);
813 extern void drm_mode_validate_size(struct drm_device *dev,
814                                    struct list_head *mode_list,
815                                    int maxX, int maxY, int maxPitch);
816 extern void drm_mode_validate_clocks(struct drm_device *dev,
817                               struct list_head *mode_list,
818                               int *min, int *max, int n_ranges);
819 extern void drm_mode_prune_invalid(struct drm_device *dev,
820                                    struct list_head *mode_list, bool verbose);
821 extern void drm_mode_sort(struct list_head *mode_list);
822 extern int drm_mode_hsync(const struct drm_display_mode *mode);
823 extern int drm_mode_vrefresh(const struct drm_display_mode *mode);
824 extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
825                                   int adjust_flags);
826 extern void drm_mode_connector_list_update(struct drm_connector *connector);
827 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
828                                                 struct edid *edid);
829 extern int drm_connector_property_set_value(struct drm_connector *connector,
830                                          struct drm_property *property,
831                                          uint64_t value);
832 extern int drm_connector_property_get_value(struct drm_connector *connector,
833                                          struct drm_property *property,
834                                          uint64_t *value);
835 extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
836 extern void drm_framebuffer_set_object(struct drm_device *dev,
837                                        unsigned long handle);
838 extern int drm_framebuffer_init(struct drm_device *dev,
839                                 struct drm_framebuffer *fb,
840                                 const struct drm_framebuffer_funcs *funcs);
841 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
842 extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
843 extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
844 extern void drm_crtc_probe_connector_modes(struct drm_device *dev, int maxX, int maxY);
845 extern bool drm_crtc_in_use(struct drm_crtc *crtc);
846
847 extern int drm_connector_attach_property(struct drm_connector *connector,
848                                       struct drm_property *property, uint64_t init_val);
849 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
850                                                 const char *name, int num_values);
851 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
852                                          const char *name,
853                                          const struct drm_prop_enum_list *props,
854                                          int num_values);
855 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
856                                          const char *name,
857                                          uint64_t min, uint64_t max);
858 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
859 extern int drm_property_add_enum(struct drm_property *property, int index,
860                                  uint64_t value, const char *name);
861 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
862 extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
863                                      char *formats[]);
864 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
865 extern int drm_mode_create_dithering_property(struct drm_device *dev);
866 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
867 extern char *drm_get_encoder_name(struct drm_encoder *encoder);
868
869 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
870                                              struct drm_encoder *encoder);
871 extern void drm_mode_connector_detach_encoder(struct drm_connector *connector,
872                                            struct drm_encoder *encoder);
873 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
874                                          int gamma_size);
875 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
876                 uint32_t id, uint32_t type);
877 /* IOCTLs */
878 extern int drm_mode_getresources(struct drm_device *dev,
879                                  void *data, struct drm_file *file_priv);
880 extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
881                                    struct drm_file *file_priv);
882 extern int drm_mode_getcrtc(struct drm_device *dev,
883                             void *data, struct drm_file *file_priv);
884 extern int drm_mode_getconnector(struct drm_device *dev,
885                               void *data, struct drm_file *file_priv);
886 extern int drm_mode_setcrtc(struct drm_device *dev,
887                             void *data, struct drm_file *file_priv);
888 extern int drm_mode_getplane(struct drm_device *dev,
889                                void *data, struct drm_file *file_priv);
890 extern int drm_mode_setplane(struct drm_device *dev,
891                                void *data, struct drm_file *file_priv);
892 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
893                                 void *data, struct drm_file *file_priv);
894 extern int drm_mode_addfb(struct drm_device *dev,
895                           void *data, struct drm_file *file_priv);
896 extern int drm_mode_addfb2(struct drm_device *dev,
897                            void *data, struct drm_file *file_priv);
898 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
899 extern int drm_mode_rmfb(struct drm_device *dev,
900                          void *data, struct drm_file *file_priv);
901 extern int drm_mode_getfb(struct drm_device *dev,
902                           void *data, struct drm_file *file_priv);
903 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
904                                   void *data, struct drm_file *file_priv);
905 extern int drm_mode_addmode_ioctl(struct drm_device *dev,
906                                   void *data, struct drm_file *file_priv);
907 extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
908                                  void *data, struct drm_file *file_priv);
909 extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
910                                      void *data, struct drm_file *file_priv);
911 extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
912                                      void *data, struct drm_file *file_priv);
913
914 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
915                                       void *data, struct drm_file *file_priv);
916 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
917                                   void *data, struct drm_file *file_priv);
918 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
919                                               void *data, struct drm_file *file_priv);
920 extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
921                                   void *data, struct drm_file *file_priv);
922 extern int drm_mode_replacefb(struct drm_device *dev,
923                               void *data, struct drm_file *file_priv);
924 extern int drm_mode_getencoder(struct drm_device *dev,
925                                void *data, struct drm_file *file_priv);
926 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
927                                     void *data, struct drm_file *file_priv);
928 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
929                                     void *data, struct drm_file *file_priv);
930 extern bool drm_detect_hdmi_monitor(struct edid *edid);
931 extern bool drm_detect_monitor_audio(struct edid *edid);
932 extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
933                                     void *data, struct drm_file *file_priv);
934 extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
935                                 int hdisplay, int vdisplay, int vrefresh,
936                                 bool reduced, bool interlaced, bool margins);
937 extern struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
938                                 int hdisplay, int vdisplay, int vrefresh,
939                                 bool interlaced, int margins);
940 extern struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
941                                 int hdisplay, int vdisplay, int vrefresh,
942                                 bool interlaced, int margins, int GTF_M,
943                                 int GTF_2C, int GTF_K, int GTF_2J);
944 extern int drm_add_modes_noedid(struct drm_connector *connector,
945                                 int hdisplay, int vdisplay);
946
947 extern int drm_edid_header_is_valid(const u8 *raw_edid);
948 extern bool drm_edid_is_valid(struct edid *edid);
949 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
950                                            int hsize, int vsize, int fresh);
951
952 extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
953                                       void *data, struct drm_file *file_priv);
954 extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
955                                     void *data, struct drm_file *file_priv);
956 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
957                                       void *data, struct drm_file *file_priv);
958
959 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
960                                  int *bpp);
961 #endif /* __DRM_CRTC_H__ */