blob: cb2e599f769ff6ea9e6678948276801090692041 [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>
Vandana Kannan985e5dc2013-12-19 15:34:07 +053033#include <linux/hdmi.h>
David Howells19218e42012-10-02 18:01:03 +010034#include <drm/drm_mode.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080035#include <drm/drm_fourcc.h>
36
Dave Airlief453ba02008-11-07 14:05:41 -080037struct drm_device;
38struct drm_mode_set;
39struct drm_framebuffer;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030040struct drm_object_properties;
Thierry Reding595887e2012-11-21 15:00:47 +010041struct drm_file;
42struct drm_clip_rect;
Dave Airlief453ba02008-11-07 14:05:41 -080043
44#define DRM_MODE_OBJECT_CRTC 0xcccccccc
45#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
46#define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
47#define DRM_MODE_OBJECT_MODE 0xdededede
48#define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
49#define DRM_MODE_OBJECT_FB 0xfbfbfbfb
50#define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
Jesse Barnes8cf5c912011-11-14 14:51:27 -080051#define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
Sean Paul3b336ec2013-08-14 16:47:37 -040052#define DRM_MODE_OBJECT_BRIDGE 0xbdbdbdbd
Rob Clark98f75de2014-05-30 11:37:03 -040053#define DRM_MODE_OBJECT_ANY 0
Dave Airlief453ba02008-11-07 14:05:41 -080054
55struct drm_mode_object {
56 uint32_t id;
57 uint32_t type;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030058 struct drm_object_properties *properties;
59};
60
Paulo Zanonife456162012-06-12 11:27:01 -030061#define DRM_OBJECT_MAX_PROPERTY 24
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030062struct drm_object_properties {
Paulo Zanoni7f88a9b2012-05-15 18:09:04 -030063 int count;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030064 uint32_t ids[DRM_OBJECT_MAX_PROPERTY];
65 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
Dave Airlief453ba02008-11-07 14:05:41 -080066};
67
Daniel Vetter55310002014-01-23 15:52:20 +010068enum drm_connector_force {
69 DRM_FORCE_UNSPECIFIED,
70 DRM_FORCE_OFF,
71 DRM_FORCE_ON, /* force on analog part normally */
72 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
Dave Airlief453ba02008-11-07 14:05:41 -080073};
74
Daniel Vetter55310002014-01-23 15:52:20 +010075#include <drm/drm_modes.h>
Damien Lespiau4aa17cf2013-09-25 16:45:21 +010076
Dave Airlief453ba02008-11-07 14:05:41 -080077enum drm_connector_status {
78 connector_status_connected = 1,
79 connector_status_disconnected = 2,
80 connector_status_unknown = 3,
81};
82
83enum subpixel_order {
84 SubPixelUnknown = 0,
85 SubPixelHorizontalRGB,
86 SubPixelHorizontalBGR,
87 SubPixelVerticalRGB,
88 SubPixelVerticalBGR,
89 SubPixelNone,
90};
91
Jesse Barnesda05a5a72011-04-15 13:48:57 -070092#define DRM_COLOR_FORMAT_RGB444 (1<<0)
93#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
94#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
Dave Airlief453ba02008-11-07 14:05:41 -080095/*
96 * Describes a given display (e.g. CRT or flat panel) and its limitations.
97 */
98struct drm_display_info {
99 char name[DRM_DISPLAY_INFO_LEN];
Adam Jacksonfb439642010-08-03 14:38:16 -0400100
Dave Airlief453ba02008-11-07 14:05:41 -0800101 /* Physical size */
102 unsigned int width_mm;
103 unsigned int height_mm;
104
Dave Airlief453ba02008-11-07 14:05:41 -0800105 /* Clock limits FIXME: storage format */
106 unsigned int min_vfreq, max_vfreq;
107 unsigned int min_hfreq, max_hfreq;
108 unsigned int pixel_clock;
Jesse Barnes3b112282011-04-15 12:49:23 -0700109 unsigned int bpc;
Dave Airlief453ba02008-11-07 14:05:41 -0800110
Dave Airlief453ba02008-11-07 14:05:41 -0800111 enum subpixel_order subpixel_order;
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700112 u32 color_formats;
Dave Airlief453ba02008-11-07 14:05:41 -0800113
Jesse Barnesebec9a72011-08-03 09:22:54 -0700114 u8 cea_rev;
Dave Airlief453ba02008-11-07 14:05:41 -0800115};
116
117struct drm_framebuffer_funcs {
Rob Clarkf7eff602012-09-05 21:48:38 +0000118 /* note: use drm_framebuffer_remove() */
Dave Airlief453ba02008-11-07 14:05:41 -0800119 void (*destroy)(struct drm_framebuffer *framebuffer);
120 int (*create_handle)(struct drm_framebuffer *fb,
121 struct drm_file *file_priv,
122 unsigned int *handle);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000123 /**
124 * Optinal callback for the dirty fb ioctl.
125 *
126 * Userspace can notify the driver via this callback
127 * that a area of the framebuffer has changed and should
128 * be flushed to the display hardware.
129 *
130 * See documentation in drm_mode.h for the struct
131 * drm_mode_fb_dirty_cmd for more information as all
132 * the semantics and arguments have a one to one mapping
133 * on this function.
134 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200135 int (*dirty)(struct drm_framebuffer *framebuffer,
136 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000137 unsigned color, struct drm_clip_rect *clips,
138 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800139};
140
141struct drm_framebuffer {
142 struct drm_device *dev;
Rob Clarkf7eff602012-09-05 21:48:38 +0000143 /*
144 * Note that the fb is refcounted for the benefit of driver internals,
145 * for example some hw, disabling a CRTC/plane is asynchronous, and
146 * scanout does not actually complete until the next vblank. So some
147 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
148 * should be deferred. In cases like this, the driver would like to
149 * hold a ref to the fb even though it has already been removed from
150 * userspace perspective.
151 */
152 struct kref refcount;
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100153 /*
154 * Place on the dev->mode_config.fb_list, access protected by
155 * dev->mode_config.fb_lock.
156 */
Dave Airlief453ba02008-11-07 14:05:41 -0800157 struct list_head head;
158 struct drm_mode_object base;
159 const struct drm_framebuffer_funcs *funcs;
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200160 unsigned int pitches[4];
161 unsigned int offsets[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800162 unsigned int width;
163 unsigned int height;
164 /* depth can be 15 or 16 */
165 unsigned int depth;
166 int bits_per_pixel;
167 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800168 uint32_t pixel_format; /* fourcc format */
Dave Airlief453ba02008-11-07 14:05:41 -0800169 struct list_head filp_head;
Dave Airlie785b93e2009-08-28 15:46:53 +1000170 /* if you are using the helper */
171 void *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -0800172};
173
174struct drm_property_blob {
175 struct drm_mode_object base;
176 struct list_head head;
177 unsigned int length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +0200178 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -0800179};
180
181struct drm_property_enum {
182 uint64_t value;
183 struct list_head head;
184 char name[DRM_PROP_NAME_LEN];
185};
186
187struct drm_property {
188 struct list_head head;
189 struct drm_mode_object base;
190 uint32_t flags;
191 char name[DRM_PROP_NAME_LEN];
192 uint32_t num_values;
193 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400194 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800195
196 struct list_head enum_blob_list;
197};
198
199struct drm_crtc;
200struct drm_connector;
201struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500202struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800203struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400204struct drm_bridge;
Dave Airlief453ba02008-11-07 14:05:41 -0800205
206/**
207 * drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800208 * @save: save CRTC state
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200209 * @restore: restore CRTC state
Christopher Harvey715f59c2013-04-05 15:28:32 +0000210 * @reset: reset CRTC after state has been invalidated (e.g. resume)
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200211 * @cursor_set: setup the cursor
212 * @cursor_move: move the cursor
Dave Airlief453ba02008-11-07 14:05:41 -0800213 * @gamma_set: specify color ramp for CRTC
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300214 * @destroy: deinit and free object
215 * @set_property: called when a property is changed
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200216 * @set_config: apply a new CRTC configuration
217 * @page_flip: initiate a page flip
Dave Airlief453ba02008-11-07 14:05:41 -0800218 *
219 * The drm_crtc_funcs structure is the central CRTC management structure
220 * in the DRM. Each CRTC controls one or more connectors (note that the name
221 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
222 * connectors, not just CRTs).
223 *
224 * Each driver is responsible for filling out this structure at startup time,
225 * in addition to providing other modesetting features, like i2c and DDC
226 * bus accessors.
227 */
228struct drm_crtc_funcs {
229 /* Save CRTC state */
230 void (*save)(struct drm_crtc *crtc); /* suspend? */
231 /* Restore CRTC state */
232 void (*restore)(struct drm_crtc *crtc); /* resume? */
Chris Wilsoneb033552011-01-24 15:11:08 +0000233 /* Reset CRTC state */
234 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800235
236 /* cursor controls */
237 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
238 uint32_t handle, uint32_t width, uint32_t height);
Dave Airlie4c813d42013-06-20 11:48:52 +1000239 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
240 uint32_t handle, uint32_t width, uint32_t height,
241 int32_t hot_x, int32_t hot_y);
Dave Airlief453ba02008-11-07 14:05:41 -0800242 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
243
244 /* Set gamma on the CRTC */
245 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
James Simmons72034252010-08-03 01:33:19 +0100246 uint32_t start, uint32_t size);
Dave Airlief453ba02008-11-07 14:05:41 -0800247 /* Object destroy routine */
248 void (*destroy)(struct drm_crtc *crtc);
249
250 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500251
252 /*
253 * Flip to the given framebuffer. This implements the page
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300254 * flip ioctl described in drm_mode.h, specifically, the
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500255 * implementation must return immediately and block all
256 * rendering to the current fb until the flip has completed.
257 * If userspace set the event flag in the ioctl, the event
258 * argument will point to an event to send back when the flip
259 * completes, otherwise it will be NULL.
260 */
261 int (*page_flip)(struct drm_crtc *crtc,
262 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700263 struct drm_pending_vblank_event *event,
264 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300265
266 int (*set_property)(struct drm_crtc *crtc,
267 struct drm_property *property, uint64_t val);
Dave Airlief453ba02008-11-07 14:05:41 -0800268};
269
270/**
271 * drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800272 * @dev: parent DRM device
273 * @head: list management
274 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700275 * @primary: primary plane for this CRTC
276 * @cursor: cursor plane for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800277 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800278 * @mode: current mode timings
279 * @hwmode: mode timings as programmed to hw regs
Rob Clark7c80e122012-09-04 16:35:56 +0000280 * @invert_dimensions: for purposes of error checking crtc vs fb sizes,
281 * invert the width/height of the crtc. This is used if the driver
282 * is performing 90 or 270 degree rotated scanout
Dave Airlief453ba02008-11-07 14:05:41 -0800283 * @x: x position on screen
284 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800285 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800286 * @gamma_size: size of gamma ramp
287 * @gamma_store: gamma ramp values
288 * @framedur_ns: precise frame timing
289 * @framedur_ns: precise line timing
290 * @pixeldur_ns: precise pixel timing
291 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300292 * @properties: property tracking for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800293 *
294 * Each CRTC may have one or more connectors associated with it. This structure
295 * allows the CRTC to be controlled.
296 */
297struct drm_crtc {
298 struct drm_device *dev;
299 struct list_head head;
300
Daniel Vetter29494c12012-12-02 02:18:25 +0100301 /**
302 * crtc mutex
303 *
304 * This provides a read lock for the overall crtc state (mode, dpms
305 * state, ...) and a write lock for everything which can be update
306 * without a full modeset (fb, cursor data, ...)
307 */
308 struct mutex mutex;
309
Dave Airlief453ba02008-11-07 14:05:41 -0800310 struct drm_mode_object base;
311
Matt Ropere13161a2014-04-01 15:22:38 -0700312 /* primary and cursor planes for CRTC */
313 struct drm_plane *primary;
314 struct drm_plane *cursor;
315
Daniel Vetter5cef29a2013-06-15 00:13:16 +0200316 /* Temporary tracking of the old fb while a modeset is ongoing. Used
317 * by drm_mode_set_config_internal to implement correct refcounting. */
318 struct drm_framebuffer *old_fb;
319
Dave Airlief453ba02008-11-07 14:05:41 -0800320 bool enabled;
321
Mario Kleiner27641c32010-10-23 04:20:23 +0200322 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800323 struct drm_display_mode mode;
324
Mario Kleiner27641c32010-10-23 04:20:23 +0200325 /* Programmed mode in hw, after adjustments for encoders,
326 * crtc, panel scaling etc. Needed for timestamping etc.
327 */
328 struct drm_display_mode hwmode;
329
Rob Clark7c80e122012-09-04 16:35:56 +0000330 bool invert_dimensions;
331
Dave Airlief453ba02008-11-07 14:05:41 -0800332 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800333 const struct drm_crtc_funcs *funcs;
334
335 /* CRTC gamma size for reporting to userspace */
336 uint32_t gamma_size;
337 uint16_t *gamma_store;
338
Mario Kleiner27641c32010-10-23 04:20:23 +0200339 /* Constants needed for precise vblank and swap timestamping. */
Ville Syrjälä3c184f62013-10-26 17:38:52 +0300340 int framedur_ns, linedur_ns, pixeldur_ns;
Mario Kleiner27641c32010-10-23 04:20:23 +0200341
Dave Airlief453ba02008-11-07 14:05:41 -0800342 /* if you are using the helper */
343 void *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300344
345 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -0800346};
347
348
349/**
350 * drm_connector_funcs - control connectors on a given device
351 * @dpms: set power state (see drm_crtc_funcs above)
352 * @save: save connector state
353 * @restore: restore connector state
Christopher Harvey13bcf012013-03-07 10:42:25 -0500354 * @reset: reset connector after state has been invalidated (e.g. resume)
Dave Airlief453ba02008-11-07 14:05:41 -0800355 * @detect: is this connector active?
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200356 * @fill_modes: fill mode list for this connector
Christopher Harvey13bcf012013-03-07 10:42:25 -0500357 * @set_property: property for this connector may need an update
Dave Airlief453ba02008-11-07 14:05:41 -0800358 * @destroy: make object go away
Christopher Harvey13bcf012013-03-07 10:42:25 -0500359 * @force: notify the driver that the connector is forced on
Dave Airlief453ba02008-11-07 14:05:41 -0800360 *
361 * Each CRTC may have one or more connectors attached to it. The functions
362 * below allow the core DRM code to control connectors, enumerate available modes,
363 * etc.
364 */
365struct drm_connector_funcs {
366 void (*dpms)(struct drm_connector *connector, int mode);
367 void (*save)(struct drm_connector *connector);
368 void (*restore)(struct drm_connector *connector);
Chris Wilsoneb033552011-01-24 15:11:08 +0000369 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100370
371 /* Check to see if anything is attached to the connector.
372 * @force is set to false whilst polling, true when checking the
373 * connector due to user request. @force can be used by the driver
374 * to avoid expensive, destructive operations during automated
375 * probing.
376 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100377 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100378 bool force);
Jesse Barnes40a518d2009-01-12 12:05:32 -0800379 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Dave Airlief453ba02008-11-07 14:05:41 -0800380 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
381 uint64_t val);
382 void (*destroy)(struct drm_connector *connector);
Dave Airlied50ba252009-09-23 14:44:08 +1000383 void (*force)(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -0800384};
385
Jesse Barnes6c3db922011-11-07 12:03:16 -0800386/**
387 * drm_encoder_funcs - encoder controls
388 * @reset: reset state (e.g. at init or resume time)
389 * @destroy: cleanup and free associated data
390 *
391 * Encoders sit between CRTCs and connectors.
392 */
Dave Airlief453ba02008-11-07 14:05:41 -0800393struct drm_encoder_funcs {
Chris Wilsoneb033552011-01-24 15:11:08 +0000394 void (*reset)(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -0800395 void (*destroy)(struct drm_encoder *encoder);
396};
397
Ben Skeggsafe887d2012-01-12 16:00:57 +1000398#define DRM_CONNECTOR_MAX_ENCODER 3
Dave Airlief453ba02008-11-07 14:05:41 -0800399
400/**
401 * drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -0800402 * @dev: parent DRM device
403 * @head: list management
404 * @base: base KMS object
Jani Nikulae5748942014-05-14 16:58:20 +0300405 * @name: encoder name
Jesse Barnesdb3e4492011-11-07 12:03:17 -0800406 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
407 * @possible_crtcs: bitmask of potential CRTC bindings
408 * @possible_clones: bitmask of potential sibling encoders for cloning
409 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -0400410 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -0800411 * @funcs: control functions
412 * @helper_private: mid-layer private data
413 *
414 * CRTCs drive pixels to encoders, which convert them into signals
415 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -0800416 */
417struct drm_encoder {
418 struct drm_device *dev;
419 struct list_head head;
420
421 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +0300422 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -0800423 int encoder_type;
424 uint32_t possible_crtcs;
425 uint32_t possible_clones;
426
427 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -0400428 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -0800429 const struct drm_encoder_funcs *funcs;
430 void *helper_private;
431};
432
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000433/* should we poll this connector for connects and disconnects */
434/* hot plug detectable */
435#define DRM_CONNECTOR_POLL_HPD (1 << 0)
436/* poll for connections */
437#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
438/* can cleanly poll for disconnections without flickering the screen */
439/* DACs should rarely do this without a lot of testing */
440#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
441
Wu Fengguang76adaa342011-09-05 14:23:20 +0800442#define MAX_ELD_BYTES 128
443
Dave Airlief453ba02008-11-07 14:05:41 -0800444/**
445 * drm_connector - central DRM connector control structure
Jesse Barnes72252542011-11-07 12:03:18 -0800446 * @dev: parent DRM device
447 * @kdev: kernel device for sysfs attributes
448 * @attr: sysfs attributes
449 * @head: list management
450 * @base: base KMS object
Jani Nikula2abdd312014-05-14 16:58:19 +0300451 * @name: connector name
Jesse Barnes72252542011-11-07 12:03:18 -0800452 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
453 * @connector_type_id: index into connector type enum
Dave Airlief453ba02008-11-07 14:05:41 -0800454 * @interlace_allowed: can this connector handle interlaced modes?
455 * @doublescan_allowed: can this connector handle doublescan?
Jesse Barnes72252542011-11-07 12:03:18 -0800456 * @modes: modes available on this connector (from fill_modes() + user)
457 * @status: one of the drm_connector_status enums (connected, not, or unknown)
458 * @probed_modes: list of modes derived directly from the display
459 * @display_info: information about attached display (e.g. from EDID)
Dave Airlief453ba02008-11-07 14:05:41 -0800460 * @funcs: connector control functions
Jesse Barnes72252542011-11-07 12:03:18 -0800461 * @edid_blob_ptr: DRM property containing EDID if present
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -0300462 * @properties: property tracking for this connector
Jesse Barnes72252542011-11-07 12:03:18 -0800463 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
464 * @dpms: current dpms state
465 * @helper_private: mid-layer private data
466 * @force: a %DRM_FORCE_<foo> state for forced mode sets
467 * @encoder_ids: valid encoders for this connector
468 * @encoder: encoder driving this connector, if any
469 * @eld: EDID-like data, if present
470 * @dvi_dual: dual link DVI, if found
471 * @max_tmds_clock: max clock rate, if found
472 * @latency_present: AV delay info from ELD, if found
473 * @video_latency: video latency info from ELD, if found
474 * @audio_latency: audio latency info from ELD, if found
475 * @null_edid_counter: track sinks that give us all zeros for the EDID
Dave Airlief453ba02008-11-07 14:05:41 -0800476 *
477 * Each connector may be connected to one or more CRTCs, or may be clonable by
478 * another connector if they can share a CRTC. Each connector also has a specific
479 * position in the broader display (referred to as a 'screen' though it could
480 * span multiple monitors).
481 */
482struct drm_connector {
483 struct drm_device *dev;
Dave Airlie5bdebb12013-10-11 14:07:25 +1000484 struct device *kdev;
Dave Airlief453ba02008-11-07 14:05:41 -0800485 struct device_attribute *attr;
486 struct list_head head;
487
488 struct drm_mode_object base;
489
Jani Nikula2abdd312014-05-14 16:58:19 +0300490 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -0800491 int connector_type;
492 int connector_type_id;
493 bool interlace_allowed;
494 bool doublescan_allowed;
Damien Lespiau560a0672013-09-25 16:45:29 +0100495 bool stereo_allowed;
Dave Airlief453ba02008-11-07 14:05:41 -0800496 struct list_head modes; /* list of modes on this connector */
497
Dave Airlief453ba02008-11-07 14:05:41 -0800498 enum drm_connector_status status;
499
500 /* these are modes added by probing with DDC or the BIOS */
501 struct list_head probed_modes;
502
503 struct drm_display_info display_info;
504 const struct drm_connector_funcs *funcs;
505
Dave Airlief453ba02008-11-07 14:05:41 -0800506 struct drm_property_blob *edid_blob_ptr;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -0300507 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -0800508
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000509 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
510
Keith Packardc9fb15f2009-05-30 20:42:28 -0700511 /* requested DPMS state */
512 int dpms;
513
Dave Airlief453ba02008-11-07 14:05:41 -0800514 void *helper_private;
515
Dave Airlied50ba252009-09-23 14:44:08 +1000516 /* forced on connector */
517 enum drm_connector_force force;
Dave Airlief453ba02008-11-07 14:05:41 -0800518 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
Dave Airlief453ba02008-11-07 14:05:41 -0800519 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +0000520
Wu Fengguang76adaa342011-09-05 14:23:20 +0800521 /* EDID bits */
522 uint8_t eld[MAX_ELD_BYTES];
523 bool dvi_dual;
524 int max_tmds_clock; /* in MHz */
525 bool latency_present[2];
526 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
527 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +0000528 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Jerome Glisse0b2443e2012-08-09 11:25:51 -0400529 unsigned bad_edid_counter;
Dave Airlief453ba02008-11-07 14:05:41 -0800530};
531
532/**
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800533 * drm_plane_funcs - driver plane control functions
534 * @update_plane: update the plane configuration
535 * @disable_plane: shut down the plane
536 * @destroy: clean up plane resources
Rob Clark4d939142012-05-17 02:23:27 -0600537 * @set_property: called when a property is changed
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800538 */
539struct drm_plane_funcs {
540 int (*update_plane)(struct drm_plane *plane,
541 struct drm_crtc *crtc, struct drm_framebuffer *fb,
542 int crtc_x, int crtc_y,
543 unsigned int crtc_w, unsigned int crtc_h,
544 uint32_t src_x, uint32_t src_y,
545 uint32_t src_w, uint32_t src_h);
546 int (*disable_plane)(struct drm_plane *plane);
547 void (*destroy)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -0600548
549 int (*set_property)(struct drm_plane *plane,
550 struct drm_property *property, uint64_t val);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800551};
552
Matt Ropere27dde32014-04-01 15:22:30 -0700553enum drm_plane_type {
554 DRM_PLANE_TYPE_OVERLAY,
555 DRM_PLANE_TYPE_PRIMARY,
556 DRM_PLANE_TYPE_CURSOR,
557};
558
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800559/**
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
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800569 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -0600570 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -0700571 * @type: type of plane (overlay, primary, cursor)
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800572 */
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
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800586 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -0600587
588 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -0700589
590 enum drm_plane_type type;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800591};
592
593/**
Sean Paul3b336ec2013-08-14 16:47:37 -0400594 * drm_bridge_funcs - drm_bridge control functions
595 * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
596 * @disable: Called right before encoder prepare, disables the bridge
597 * @post_disable: Called right after encoder prepare, for lockstepped disable
598 * @mode_set: Set this mode to the bridge
599 * @pre_enable: Called right before encoder commit, for lockstepped commit
600 * @enable: Called right after encoder commit, enables the bridge
601 * @destroy: make object go away
602 */
603struct drm_bridge_funcs {
604 bool (*mode_fixup)(struct drm_bridge *bridge,
605 const struct drm_display_mode *mode,
606 struct drm_display_mode *adjusted_mode);
607 void (*disable)(struct drm_bridge *bridge);
608 void (*post_disable)(struct drm_bridge *bridge);
609 void (*mode_set)(struct drm_bridge *bridge,
610 struct drm_display_mode *mode,
611 struct drm_display_mode *adjusted_mode);
612 void (*pre_enable)(struct drm_bridge *bridge);
613 void (*enable)(struct drm_bridge *bridge);
614 void (*destroy)(struct drm_bridge *bridge);
615};
616
617/**
618 * drm_bridge - central DRM bridge control structure
619 * @dev: DRM device this bridge belongs to
620 * @head: list management
621 * @base: base mode object
622 * @funcs: control functions
623 * @driver_private: pointer to the bridge driver's internal context
624 */
625struct drm_bridge {
626 struct drm_device *dev;
627 struct list_head head;
628
629 struct drm_mode_object base;
630
631 const struct drm_bridge_funcs *funcs;
632 void *driver_private;
633};
634
635/**
Jesse Barnesef273512011-11-07 12:03:19 -0800636 * drm_mode_set - new values for a CRTC config change
637 * @head: list management
638 * @fb: framebuffer to use for new config
639 * @crtc: CRTC whose configuration we're about to change
640 * @mode: mode timings to use
641 * @x: position of this CRTC relative to @fb
642 * @y: position of this CRTC relative to @fb
643 * @connectors: array of connectors to drive with this CRTC if possible
644 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -0800645 *
646 * Represents a single crtc the connectors that it drives with what mode
647 * and from which framebuffer it scans out from.
648 *
649 * This is used to set modes.
650 */
651struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -0800652 struct drm_framebuffer *fb;
653 struct drm_crtc *crtc;
654 struct drm_display_mode *mode;
655
656 uint32_t x;
657 uint32_t y;
658
659 struct drm_connector **connectors;
660 size_t num_connectors;
661};
662
663/**
Jesse Barnes550cebc2011-11-07 12:03:20 -0800664 * struct drm_mode_config_funcs - basic driver provided mode setting functions
665 * @fb_create: create a new framebuffer object
666 * @output_poll_changed: function to handle output configuration changes
667 *
668 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
669 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -0800670 */
671struct drm_mode_config_funcs {
Jesse Barnes550cebc2011-11-07 12:03:20 -0800672 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
673 struct drm_file *file_priv,
674 struct drm_mode_fb_cmd2 *mode_cmd);
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000675 void (*output_poll_changed)(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800676};
677
Jesse Barnesc1aaca22011-11-07 12:03:21 -0800678/**
679 * drm_mode_group - group of mode setting resources for potential sub-grouping
680 * @num_crtcs: CRTC count
681 * @num_encoders: encoder count
682 * @num_connectors: connector count
683 * @id_list: list of KMS object IDs in this group
684 *
685 * Currently this simply tracks the global mode setting state. But in the
686 * future it could allow groups of objects to be set aside into independent
687 * control groups for use by different user level processes (e.g. two X servers
688 * running simultaneously on different heads, each with their own mode
689 * configuration and freedom of mode setting).
690 */
Dave Airlief453ba02008-11-07 14:05:41 -0800691struct drm_mode_group {
692 uint32_t num_crtcs;
693 uint32_t num_encoders;
694 uint32_t num_connectors;
Sean Paul3b336ec2013-08-14 16:47:37 -0400695 uint32_t num_bridges;
Dave Airlief453ba02008-11-07 14:05:41 -0800696
697 /* list of object IDs for this group */
698 uint32_t *id_list;
699};
700
701/**
702 * drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800703 * @mutex: mutex protecting KMS related lists and structures
704 * @idr_mutex: mutex for KMS ID allocation and management
705 * @crtc_idr: main KMS ID tracking object
706 * @num_fb: number of fbs available
707 * @fb_list: list of framebuffers available
708 * @num_connector: number of connectors on this device
709 * @connector_list: list of connector objects
Sean Paul3b336ec2013-08-14 16:47:37 -0400710 * @num_bridge: number of bridges on this device
711 * @bridge_list: list of bridge objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800712 * @num_encoder: number of encoders on this device
713 * @encoder_list: list of encoder objects
714 * @num_crtc: number of CRTCs on this device
715 * @crtc_list: list of CRTC objects
716 * @min_width: minimum pixel width on this device
717 * @min_height: minimum pixel height on this device
718 * @max_width: maximum pixel width on this device
719 * @max_height: maximum pixel height on this device
720 * @funcs: core driver provided mode setting functions
721 * @fb_base: base address of the framebuffer
722 * @poll_enabled: track polling status for this device
723 * @output_poll_work: delayed work for polling in process context
724 * @*_property: core property tracking
Dave Airlief453ba02008-11-07 14:05:41 -0800725 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800726 * Core mode resource tracking structure. All CRTC, encoders, and connectors
727 * enumerated by the driver are added here, as are global properties. Some
728 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -0800729 */
730struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +1000731 struct mutex mutex; /* protects configuration (mode lists etc.) */
732 struct mutex idr_mutex; /* for IDR management */
Dave Airlief453ba02008-11-07 14:05:41 -0800733 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
734 /* this is limited to one for now */
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100735
736
737 /**
738 * fb_lock - mutex to protect fb state
739 *
740 * Besides the global fb list his also protects the fbs list in the
741 * file_priv
742 */
743 struct mutex fb_lock;
Dave Airlief453ba02008-11-07 14:05:41 -0800744 int num_fb;
745 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100746
Dave Airlief453ba02008-11-07 14:05:41 -0800747 int num_connector;
748 struct list_head connector_list;
Sean Paul3b336ec2013-08-14 16:47:37 -0400749 int num_bridge;
750 struct list_head bridge_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800751 int num_encoder;
752 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -0700753
754 /*
755 * Track # of overlay planes separately from # of total planes. By
756 * default we only advertise overlay planes to userspace; if userspace
757 * sets the "universal plane" capability bit, we'll go ahead and
758 * expose all planes.
759 */
760 int num_overlay_plane;
761 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800762 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800763
764 int num_crtc;
765 struct list_head crtc_list;
766
767 struct list_head property_list;
768
Dave Airlief453ba02008-11-07 14:05:41 -0800769 int min_width, min_height;
770 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +0200771 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +1100772 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -0800773
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000774 /* output poll support */
775 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +0000776 bool poll_running;
Tejun Heo991ea752010-07-20 22:09:02 +0200777 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000778
Dave Airlief453ba02008-11-07 14:05:41 -0800779 /* pointers to standard properties */
780 struct list_head property_blob_list;
781 struct drm_property *edid_property;
782 struct drm_property *dpms_property;
Rob Clark9922ab52014-04-01 20:16:57 -0400783 struct drm_property *plane_type_property;
Dave Airlief453ba02008-11-07 14:05:41 -0800784
785 /* DVI-I properties */
786 struct drm_property *dvi_i_subconnector_property;
787 struct drm_property *dvi_i_select_subconnector_property;
788
789 /* TV properties */
790 struct drm_property *tv_subconnector_property;
791 struct drm_property *tv_select_subconnector_property;
792 struct drm_property *tv_mode_property;
793 struct drm_property *tv_left_margin_property;
794 struct drm_property *tv_right_margin_property;
795 struct drm_property *tv_top_margin_property;
796 struct drm_property *tv_bottom_margin_property;
Francisco Jerezb6b79022009-08-02 04:19:20 +0200797 struct drm_property *tv_brightness_property;
798 struct drm_property *tv_contrast_property;
799 struct drm_property *tv_flicker_reduction_property;
Francisco Jereza75f0232009-08-12 02:30:10 +0200800 struct drm_property *tv_overscan_property;
801 struct drm_property *tv_saturation_property;
802 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -0800803
804 /* Optional properties */
805 struct drm_property *scaling_mode_property;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000806 struct drm_property *dirty_info_property;
Dave Airlie019d96c2011-09-29 16:20:42 +0100807
808 /* dumb ioctl parameters */
809 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -0700810
811 /* whether async page flip is supported or not */
812 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -0500813
814 /* cursor size */
815 uint32_t cursor_width, cursor_height;
Dave Airlief453ba02008-11-07 14:05:41 -0800816};
817
818#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
819#define obj_to_connector(x) container_of(x, struct drm_connector, base)
820#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
821#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
822#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
823#define obj_to_property(x) container_of(x, struct drm_property, base)
824#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800825#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -0800826
Sascha Hauer4a67d392012-02-06 10:58:17 +0100827struct drm_prop_enum_list {
828 int type;
829 char *name;
830};
Dave Airlief453ba02008-11-07 14:05:41 -0800831
Daniel Vetter84849902012-12-02 00:28:11 +0100832extern void drm_modeset_lock_all(struct drm_device *dev);
833extern void drm_modeset_unlock_all(struct drm_device *dev);
Daniel Vetter6aed8ec2013-01-20 17:32:21 +0100834extern void drm_warn_on_modeset_not_all_locked(struct drm_device *dev);
Daniel Vetter84849902012-12-02 00:28:11 +0100835
Matt Ropere13161a2014-04-01 15:22:38 -0700836extern int drm_crtc_init_with_planes(struct drm_device *dev,
837 struct drm_crtc *crtc,
838 struct drm_plane *primary,
839 void *cursor,
840 const struct drm_crtc_funcs *funcs);
Ville Syrjälä6bfc56a2012-03-13 12:35:48 +0200841extern int drm_crtc_init(struct drm_device *dev,
842 struct drm_crtc *crtc,
843 const struct drm_crtc_funcs *funcs);
Dave Airlief453ba02008-11-07 14:05:41 -0800844extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Russell Kingdb5f7a62014-01-02 21:27:33 +0000845extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
846
847/**
848 * drm_crtc_mask - find the mask of a registered CRTC
849 * @crtc: CRTC to find mask for
850 *
851 * Given a registered CRTC, return the mask bit of that CRTC for an
852 * encoder's possible_crtcs field.
853 */
854static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
855{
856 return 1 << drm_crtc_index(crtc);
857}
Dave Airlief453ba02008-11-07 14:05:41 -0800858
Ilia Mirkinb21e3af2013-08-07 22:34:48 -0400859extern void drm_connector_ida_init(void);
860extern void drm_connector_ida_destroy(void);
Ville Syrjälä6bfc56a2012-03-13 12:35:48 +0200861extern int drm_connector_init(struct drm_device *dev,
862 struct drm_connector *connector,
863 const struct drm_connector_funcs *funcs,
864 int connector_type);
Dave Airlief453ba02008-11-07 14:05:41 -0800865
866extern void drm_connector_cleanup(struct drm_connector *connector);
Dave Airliecbc7e222012-02-20 14:16:40 +0000867/* helper to unplug all connectors from sysfs for device */
868extern void drm_connector_unplug_all(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800869
Sean Paul3b336ec2013-08-14 16:47:37 -0400870extern int drm_bridge_init(struct drm_device *dev, struct drm_bridge *bridge,
871 const struct drm_bridge_funcs *funcs);
872extern void drm_bridge_cleanup(struct drm_bridge *bridge);
873
Ville Syrjälä6bfc56a2012-03-13 12:35:48 +0200874extern int drm_encoder_init(struct drm_device *dev,
875 struct drm_encoder *encoder,
876 const struct drm_encoder_funcs *funcs,
877 int encoder_type);
Dave Airlief453ba02008-11-07 14:05:41 -0800878
Thierry Reding3d887362014-01-13 14:33:20 +0100879/**
880 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
881 * @encoder: encoder to test
882 * @crtc: crtc to test
883 *
884 * Return false if @encoder can't be driven by @crtc, true otherwise.
885 */
886static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
887 struct drm_crtc *crtc)
888{
889 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
890}
891
Matt Roperdc415ff2014-04-01 15:22:36 -0700892extern int drm_universal_plane_init(struct drm_device *dev,
893 struct drm_plane *plane,
894 unsigned long possible_crtcs,
895 const struct drm_plane_funcs *funcs,
896 const uint32_t *formats,
897 uint32_t format_count,
898 enum drm_plane_type type);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800899extern int drm_plane_init(struct drm_device *dev,
900 struct drm_plane *plane,
901 unsigned long possible_crtcs,
902 const struct drm_plane_funcs *funcs,
Rob Clark0a7eb242011-12-13 20:19:36 -0600903 const uint32_t *formats, uint32_t format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -0700904 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800905extern void drm_plane_cleanup(struct drm_plane *plane);
Ville Syrjälä9125e612013-06-03 16:10:40 +0300906extern void drm_plane_force_disable(struct drm_plane *plane);
Matt Roperaf936292014-04-01 15:22:34 -0700907extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
908 int x, int y,
909 const struct drm_display_mode *mode,
910 const struct drm_framebuffer *fb);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800911
Dave Airlief453ba02008-11-07 14:05:41 -0800912extern void drm_encoder_cleanup(struct drm_encoder *encoder);
913
Ville Syrjäläd20d3172013-06-07 15:43:07 +0000914extern const char *drm_get_connector_status_name(enum drm_connector_status status);
Jesse Barnesac1bb362014-02-10 15:32:44 -0800915extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
Ville Syrjäläd20d3172013-06-07 15:43:07 +0000916extern const char *drm_get_dpms_name(int val);
917extern const char *drm_get_dvi_i_subconnector_name(int val);
918extern const char *drm_get_dvi_i_select_name(int val);
919extern const char *drm_get_tv_subconnector_name(int val);
920extern const char *drm_get_tv_select_name(int val);
Kristian Høgsbergea39f832009-02-12 14:37:56 -0500921extern void drm_fb_release(struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -0800922extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
Dave Airliead222792014-05-02 13:22:19 +1000923extern void drm_mode_group_destroy(struct drm_mode_group *group);
Adam Jacksonfbff4692012-09-18 10:58:47 -0400924extern bool drm_probe_ddc(struct i2c_adapter *adapter);
Dave Airlief453ba02008-11-07 14:05:41 -0800925extern struct edid *drm_get_edid(struct drm_connector *connector,
926 struct i2c_adapter *adapter);
Jani Nikula51f8da52013-09-27 15:08:27 +0300927extern struct edid *drm_edid_duplicate(const struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -0800928extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -0800929extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +0000930extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800931extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800932
Dave Airlief453ba02008-11-07 14:05:41 -0800933extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
934 struct edid *edid);
Rob Clark5ea22f22014-05-30 11:34:01 -0400935
936static inline bool drm_property_type_is(struct drm_property *property,
937 uint32_t type)
938{
939 /* instanceof for props.. handles extended type vs original types: */
940 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
941 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
942 return property->flags & type;
943}
944
945static inline bool drm_property_type_valid(struct drm_property *property)
946{
947 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
948 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
949 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
950}
951
Paulo Zanonic5431882012-05-15 18:09:02 -0300952extern int drm_object_property_set_value(struct drm_mode_object *obj,
953 struct drm_property *property,
954 uint64_t val);
955extern int drm_object_property_get_value(struct drm_mode_object *obj,
956 struct drm_property *property,
957 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -0800958extern int drm_framebuffer_init(struct drm_device *dev,
959 struct drm_framebuffer *fb,
960 const struct drm_framebuffer_funcs *funcs);
Daniel Vetter786b99e2012-12-02 21:53:40 +0100961extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
962 uint32_t id);
Rob Clarkf7eff602012-09-05 21:48:38 +0000963extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
964extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
965extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -0800966extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
Daniel Vetter36206362012-12-10 20:42:17 +0100967extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -0800968
Paulo Zanonic5431882012-05-15 18:09:02 -0300969extern void drm_object_attach_property(struct drm_mode_object *obj,
970 struct drm_property *property,
971 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -0800972extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
973 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +0100974extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
975 const char *name,
976 const struct drm_prop_enum_list *props,
977 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -0600978struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
979 int flags, const char *name,
980 const struct drm_prop_enum_list *props,
981 int num_values);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100982struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
983 const char *name,
984 uint64_t min, uint64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -0400985struct drm_property *drm_property_create_object(struct drm_device *dev,
986 int flags, const char *name, uint32_t type);
Dave Airlief453ba02008-11-07 14:05:41 -0800987extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
988extern int drm_property_add_enum(struct drm_property *property, int index,
989 uint64_t value, const char *name);
990extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
991extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
992 char *formats[]);
993extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000994extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800995
996extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
997 struct drm_encoder *encoder);
Sascha Hauer4cae5b82012-02-01 11:38:23 +0100998extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -0800999 int gamma_size);
Daniel Vetter7a9c9062009-09-15 22:57:31 +02001000extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
1001 uint32_t id, uint32_t type);
Rob Clark98f75de2014-05-30 11:37:03 -04001002
Dave Airlief453ba02008-11-07 14:05:41 -08001003/* IOCTLs */
1004extern int drm_mode_getresources(struct drm_device *dev,
1005 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001006extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
1007 struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08001008extern int drm_mode_getcrtc(struct drm_device *dev,
1009 void *data, struct drm_file *file_priv);
1010extern int drm_mode_getconnector(struct drm_device *dev,
1011 void *data, struct drm_file *file_priv);
Daniel Vetter2d13b672012-12-11 13:47:23 +01001012extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Dave Airlief453ba02008-11-07 14:05:41 -08001013extern int drm_mode_setcrtc(struct drm_device *dev,
1014 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001015extern int drm_mode_getplane(struct drm_device *dev,
1016 void *data, struct drm_file *file_priv);
1017extern int drm_mode_setplane(struct drm_device *dev,
1018 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08001019extern int drm_mode_cursor_ioctl(struct drm_device *dev,
1020 void *data, struct drm_file *file_priv);
Dave Airlie4c813d42013-06-20 11:48:52 +10001021extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
1022 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08001023extern int drm_mode_addfb(struct drm_device *dev,
1024 void *data, struct drm_file *file_priv);
Jesse Barnes308e5bc2011-11-14 14:51:28 -08001025extern int drm_mode_addfb2(struct drm_device *dev,
1026 void *data, struct drm_file *file_priv);
1027extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlief453ba02008-11-07 14:05:41 -08001028extern int drm_mode_rmfb(struct drm_device *dev,
1029 void *data, struct drm_file *file_priv);
1030extern int drm_mode_getfb(struct drm_device *dev,
1031 void *data, struct drm_file *file_priv);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00001032extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
1033 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08001034
1035extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
1036 void *data, struct drm_file *file_priv);
1037extern int drm_mode_getblob_ioctl(struct drm_device *dev,
1038 void *data, struct drm_file *file_priv);
1039extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
1040 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08001041extern int drm_mode_getencoder(struct drm_device *dev,
1042 void *data, struct drm_file *file_priv);
1043extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
1044 void *data, struct drm_file *file_priv);
1045extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
1046 void *data, struct drm_file *file_priv);
Thierry Reding18316c82012-12-20 15:41:44 +01001047extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
Vandana Kannan0967e6a2014-04-01 16:26:59 +05301048extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
Ma Lingf23c20c2009-03-26 19:26:23 +08001049extern bool drm_detect_hdmi_monitor(struct edid *edid);
Zhenyu Wang8fe97902010-09-19 14:27:28 +08001050extern bool drm_detect_monitor_audio(struct edid *edid);
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02001051extern bool drm_rgb_quant_range_selectable(struct edid *edid);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -05001052extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
1053 void *data, struct drm_file *file_priv);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08001054extern int drm_add_modes_noedid(struct drm_connector *connector,
1055 int hdisplay, int vdisplay);
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02001056extern void drm_set_preferred_mode(struct drm_connector *connector,
1057 int hpref, int vpref);
Alex Deucher3c537882010-02-05 04:21:19 -05001058
Thomas Reim051963d2011-07-29 14:28:57 +00001059extern int drm_edid_header_is_valid(const u8 *raw_edid);
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001060extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid);
Alex Deucher3c537882010-02-05 04:21:19 -05001061extern bool drm_edid_is_valid(struct edid *edid);
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001062struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001063 int hsize, int vsize, int fresh,
1064 bool rb);
Dave Airlieff72145b2011-02-07 12:16:14 +10001065
1066extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
1067 void *data, struct drm_file *file_priv);
1068extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
1069 void *data, struct drm_file *file_priv);
1070extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
1071 void *data, struct drm_file *file_priv);
Paulo Zanonic5431882012-05-15 18:09:02 -03001072extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
1073 struct drm_file *file_priv);
1074extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
1075 struct drm_file *file_priv);
Dave Airlie248dbc22011-11-29 20:02:54 +00001076
1077extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
1078 int *bpp);
Ville Syrjälä141670e2012-04-05 21:35:15 +03001079extern int drm_format_num_planes(uint32_t format);
Ville Syrjälä5a86bd52012-04-05 21:35:16 +03001080extern int drm_format_plane_cpp(uint32_t format, int plane);
Ville Syrjälä01b68b02012-04-05 21:35:17 +03001081extern int drm_format_horz_chroma_subsampling(uint32_t format);
1082extern int drm_format_vert_chroma_subsampling(uint32_t format);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00001083extern const char *drm_get_format_name(uint32_t format);
Ville Syrjälä141670e2012-04-05 21:35:15 +03001084
Russell King96f60e32012-08-15 13:59:49 +01001085/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04001086
1087static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
1088 uint32_t id)
1089{
1090 struct drm_mode_object *mo;
1091 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
1092 return mo ? obj_to_plane(mo) : NULL;
1093}
1094
Russell King96f60e32012-08-15 13:59:49 +01001095static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1096 uint32_t id)
1097{
1098 struct drm_mode_object *mo;
1099 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1100 return mo ? obj_to_crtc(mo) : NULL;
1101}
1102
1103static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
1104 uint32_t id)
1105{
1106 struct drm_mode_object *mo;
1107 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
1108 return mo ? obj_to_encoder(mo) : NULL;
1109}
1110
Rob Clarka2b34e22013-10-05 16:36:52 -04001111static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
1112 uint32_t id)
1113{
1114 struct drm_mode_object *mo;
1115 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
1116 return mo ? obj_to_connector(mo) : NULL;
1117}
1118
1119static inline struct drm_property *drm_property_find(struct drm_device *dev,
1120 uint32_t id)
1121{
1122 struct drm_mode_object *mo;
1123 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
1124 return mo ? obj_to_property(mo) : NULL;
1125}
1126
1127static inline struct drm_property_blob *
1128drm_property_blob_find(struct drm_device *dev, uint32_t id)
1129{
1130 struct drm_mode_object *mo;
1131 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_BLOB);
1132 return mo ? obj_to_blob(mo) : NULL;
1133}
1134
Matt Ropere27dde32014-04-01 15:22:30 -07001135/* Plane list iterator for legacy (overlay only) planes. */
1136#define drm_for_each_legacy_plane(plane, planelist) \
1137 list_for_each_entry(plane, planelist, head) \
1138 if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1139
Dave Airlief453ba02008-11-07 14:05:41 -08001140#endif /* __DRM_CRTC_H__ */