1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright © 2006 Keith Packard
3*4882a593Smuzhiyun * Copyright © 2007-2008 Dave Airlie
4*4882a593Smuzhiyun * Copyright © 2007-2008 Intel Corporation
5*4882a593Smuzhiyun * Jesse Barnes <jesse.barnes@intel.com>
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
8*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
9*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
10*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
12*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be included in
15*4882a593Smuzhiyun * all copies or substantial portions of the Software.
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20*4882a593Smuzhiyun * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21*4882a593Smuzhiyun * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22*4882a593Smuzhiyun * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23*4882a593Smuzhiyun * OTHER DEALINGS IN THE SOFTWARE.
24*4882a593Smuzhiyun */
25*4882a593Smuzhiyun #ifndef __DRM_CRTC_H__
26*4882a593Smuzhiyun #define __DRM_CRTC_H__
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun #include <linux/i2c.h>
29*4882a593Smuzhiyun #include <linux/spinlock.h>
30*4882a593Smuzhiyun #include <linux/types.h>
31*4882a593Smuzhiyun #include <linux/fb.h>
32*4882a593Smuzhiyun #include <linux/hdmi.h>
33*4882a593Smuzhiyun #include <linux/media-bus-format.h>
34*4882a593Smuzhiyun #include <uapi/drm/drm_mode.h>
35*4882a593Smuzhiyun #include <uapi/drm/drm_fourcc.h>
36*4882a593Smuzhiyun #include <drm/drm_modeset_lock.h>
37*4882a593Smuzhiyun #include <drm/drm_rect.h>
38*4882a593Smuzhiyun #include <drm/drm_mode_object.h>
39*4882a593Smuzhiyun #include <drm/drm_framebuffer.h>
40*4882a593Smuzhiyun #include <drm/drm_modes.h>
41*4882a593Smuzhiyun #include <drm/drm_connector.h>
42*4882a593Smuzhiyun #include <drm/drm_device.h>
43*4882a593Smuzhiyun #include <drm/drm_property.h>
44*4882a593Smuzhiyun #include <drm/drm_edid.h>
45*4882a593Smuzhiyun #include <drm/drm_plane.h>
46*4882a593Smuzhiyun #include <drm/drm_blend.h>
47*4882a593Smuzhiyun #include <drm/drm_color_mgmt.h>
48*4882a593Smuzhiyun #include <drm/drm_debugfs_crc.h>
49*4882a593Smuzhiyun #include <drm/drm_mode_config.h>
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun struct drm_device;
52*4882a593Smuzhiyun struct drm_mode_set;
53*4882a593Smuzhiyun struct drm_file;
54*4882a593Smuzhiyun struct drm_clip_rect;
55*4882a593Smuzhiyun struct drm_printer;
56*4882a593Smuzhiyun struct drm_self_refresh_data;
57*4882a593Smuzhiyun struct device_node;
58*4882a593Smuzhiyun struct dma_fence;
59*4882a593Smuzhiyun struct edid;
60*4882a593Smuzhiyun
U642I64(uint64_t val)61*4882a593Smuzhiyun static inline int64_t U642I64(uint64_t val)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun return (int64_t)*((int64_t *)&val);
64*4882a593Smuzhiyun }
I642U64(int64_t val)65*4882a593Smuzhiyun static inline uint64_t I642U64(int64_t val)
66*4882a593Smuzhiyun {
67*4882a593Smuzhiyun return (uint64_t)*((uint64_t *)&val);
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun struct drm_crtc;
71*4882a593Smuzhiyun struct drm_pending_vblank_event;
72*4882a593Smuzhiyun struct drm_plane;
73*4882a593Smuzhiyun struct drm_bridge;
74*4882a593Smuzhiyun struct drm_atomic_state;
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun struct drm_crtc_helper_funcs;
77*4882a593Smuzhiyun struct drm_plane_helper_funcs;
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun /**
80*4882a593Smuzhiyun * struct drm_crtc_state - mutable CRTC state
81*4882a593Smuzhiyun *
82*4882a593Smuzhiyun * Note that the distinction between @enable and @active is rather subtle:
83*4882a593Smuzhiyun * Flipping @active while @enable is set without changing anything else may
84*4882a593Smuzhiyun * never return in a failure from the &drm_mode_config_funcs.atomic_check
85*4882a593Smuzhiyun * callback. Userspace assumes that a DPMS On will always succeed. In other
86*4882a593Smuzhiyun * words: @enable controls resource assignment, @active controls the actual
87*4882a593Smuzhiyun * hardware state.
88*4882a593Smuzhiyun *
89*4882a593Smuzhiyun * The three booleans active_changed, connectors_changed and mode_changed are
90*4882a593Smuzhiyun * intended to indicate whether a full modeset is needed, rather than strictly
91*4882a593Smuzhiyun * describing what has changed in a commit. See also:
92*4882a593Smuzhiyun * drm_atomic_crtc_needs_modeset()
93*4882a593Smuzhiyun *
94*4882a593Smuzhiyun * WARNING: Transitional helpers (like drm_helper_crtc_mode_set() or
95*4882a593Smuzhiyun * drm_helper_crtc_mode_set_base()) do not maintain many of the derived control
96*4882a593Smuzhiyun * state like @plane_mask so drivers not converted over to atomic helpers should
97*4882a593Smuzhiyun * not rely on these being accurate!
98*4882a593Smuzhiyun */
99*4882a593Smuzhiyun struct drm_crtc_state {
100*4882a593Smuzhiyun /** @crtc: backpointer to the CRTC */
101*4882a593Smuzhiyun struct drm_crtc *crtc;
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /**
104*4882a593Smuzhiyun * @enable: Whether the CRTC should be enabled, gates all other state.
105*4882a593Smuzhiyun * This controls reservations of shared resources. Actual hardware state
106*4882a593Smuzhiyun * is controlled by @active.
107*4882a593Smuzhiyun */
108*4882a593Smuzhiyun bool enable;
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun /**
111*4882a593Smuzhiyun * @active: Whether the CRTC is actively displaying (used for DPMS).
112*4882a593Smuzhiyun * Implies that @enable is set. The driver must not release any shared
113*4882a593Smuzhiyun * resources if @active is set to false but @enable still true, because
114*4882a593Smuzhiyun * userspace expects that a DPMS ON always succeeds.
115*4882a593Smuzhiyun *
116*4882a593Smuzhiyun * Hence drivers must not consult @active in their various
117*4882a593Smuzhiyun * &drm_mode_config_funcs.atomic_check callback to reject an atomic
118*4882a593Smuzhiyun * commit. They can consult it to aid in the computation of derived
119*4882a593Smuzhiyun * hardware state, since even in the DPMS OFF state the display hardware
120*4882a593Smuzhiyun * should be as much powered down as when the CRTC is completely
121*4882a593Smuzhiyun * disabled through setting @enable to false.
122*4882a593Smuzhiyun */
123*4882a593Smuzhiyun bool active;
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /**
126*4882a593Smuzhiyun * @planes_changed: Planes on this crtc are updated. Used by the atomic
127*4882a593Smuzhiyun * helpers and drivers to steer the atomic commit control flow.
128*4882a593Smuzhiyun */
129*4882a593Smuzhiyun bool planes_changed : 1;
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun /**
132*4882a593Smuzhiyun * @mode_changed: @mode or @enable has been changed. Used by the atomic
133*4882a593Smuzhiyun * helpers and drivers to steer the atomic commit control flow. See also
134*4882a593Smuzhiyun * drm_atomic_crtc_needs_modeset().
135*4882a593Smuzhiyun *
136*4882a593Smuzhiyun * Drivers are supposed to set this for any CRTC state changes that
137*4882a593Smuzhiyun * require a full modeset. They can also reset it to false if e.g. a
138*4882a593Smuzhiyun * @mode change can be done without a full modeset by only changing
139*4882a593Smuzhiyun * scaler settings.
140*4882a593Smuzhiyun */
141*4882a593Smuzhiyun bool mode_changed : 1;
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun /**
144*4882a593Smuzhiyun * @active_changed: @active has been toggled. Used by the atomic
145*4882a593Smuzhiyun * helpers and drivers to steer the atomic commit control flow. See also
146*4882a593Smuzhiyun * drm_atomic_crtc_needs_modeset().
147*4882a593Smuzhiyun */
148*4882a593Smuzhiyun bool active_changed : 1;
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun /**
151*4882a593Smuzhiyun * @connectors_changed: Connectors to this crtc have been updated,
152*4882a593Smuzhiyun * either in their state or routing. Used by the atomic
153*4882a593Smuzhiyun * helpers and drivers to steer the atomic commit control flow. See also
154*4882a593Smuzhiyun * drm_atomic_crtc_needs_modeset().
155*4882a593Smuzhiyun *
156*4882a593Smuzhiyun * Drivers are supposed to set this as-needed from their own atomic
157*4882a593Smuzhiyun * check code, e.g. from &drm_encoder_helper_funcs.atomic_check
158*4882a593Smuzhiyun */
159*4882a593Smuzhiyun bool connectors_changed : 1;
160*4882a593Smuzhiyun /**
161*4882a593Smuzhiyun * @zpos_changed: zpos values of planes on this crtc have been updated.
162*4882a593Smuzhiyun * Used by the atomic helpers and drivers to steer the atomic commit
163*4882a593Smuzhiyun * control flow.
164*4882a593Smuzhiyun */
165*4882a593Smuzhiyun bool zpos_changed : 1;
166*4882a593Smuzhiyun /**
167*4882a593Smuzhiyun * @color_mgmt_changed: Color management properties have changed
168*4882a593Smuzhiyun * (@gamma_lut, @degamma_lut or @ctm). Used by the atomic helpers and
169*4882a593Smuzhiyun * drivers to steer the atomic commit control flow.
170*4882a593Smuzhiyun */
171*4882a593Smuzhiyun bool color_mgmt_changed : 1;
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun /**
174*4882a593Smuzhiyun * @no_vblank:
175*4882a593Smuzhiyun *
176*4882a593Smuzhiyun * Reflects the ability of a CRTC to send VBLANK events. This state
177*4882a593Smuzhiyun * usually depends on the pipeline configuration. If set to true, DRM
178*4882a593Smuzhiyun * atomic helpers will send out a fake VBLANK event during display
179*4882a593Smuzhiyun * updates after all hardware changes have been committed. This is
180*4882a593Smuzhiyun * implemented in drm_atomic_helper_fake_vblank().
181*4882a593Smuzhiyun *
182*4882a593Smuzhiyun * One usage is for drivers and/or hardware without support for VBLANK
183*4882a593Smuzhiyun * interrupts. Such drivers typically do not initialize vblanking
184*4882a593Smuzhiyun * (i.e., call drm_vblank_init() with the number of CRTCs). For CRTCs
185*4882a593Smuzhiyun * without initialized vblanking, this field is set to true in
186*4882a593Smuzhiyun * drm_atomic_helper_check_modeset(), and a fake VBLANK event will be
187*4882a593Smuzhiyun * send out on each update of the display pipeline by
188*4882a593Smuzhiyun * drm_atomic_helper_fake_vblank().
189*4882a593Smuzhiyun *
190*4882a593Smuzhiyun * Another usage is CRTCs feeding a writeback connector operating in
191*4882a593Smuzhiyun * oneshot mode. In this case the fake VBLANK event is only generated
192*4882a593Smuzhiyun * when a job is queued to the writeback connector, and we want the
193*4882a593Smuzhiyun * core to fake VBLANK events when this part of the pipeline hasn't
194*4882a593Smuzhiyun * changed but others had or when the CRTC and connectors are being
195*4882a593Smuzhiyun * disabled.
196*4882a593Smuzhiyun *
197*4882a593Smuzhiyun * __drm_atomic_helper_crtc_duplicate_state() will not reset the value
198*4882a593Smuzhiyun * from the current state, the CRTC driver is then responsible for
199*4882a593Smuzhiyun * updating this field when needed.
200*4882a593Smuzhiyun *
201*4882a593Smuzhiyun * Note that the combination of &drm_crtc_state.event == NULL and
202*4882a593Smuzhiyun * &drm_crtc_state.no_blank == true is valid and usually used when the
203*4882a593Smuzhiyun * writeback connector attached to the CRTC has a new job queued. In
204*4882a593Smuzhiyun * this case the driver will send the VBLANK event on its own when the
205*4882a593Smuzhiyun * writeback job is complete.
206*4882a593Smuzhiyun */
207*4882a593Smuzhiyun bool no_vblank : 1;
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun /**
210*4882a593Smuzhiyun * @plane_mask: Bitmask of drm_plane_mask(plane) of planes attached to
211*4882a593Smuzhiyun * this CRTC.
212*4882a593Smuzhiyun */
213*4882a593Smuzhiyun u32 plane_mask;
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun /**
216*4882a593Smuzhiyun * @connector_mask: Bitmask of drm_connector_mask(connector) of
217*4882a593Smuzhiyun * connectors attached to this CRTC.
218*4882a593Smuzhiyun */
219*4882a593Smuzhiyun u32 connector_mask;
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun /**
222*4882a593Smuzhiyun * @encoder_mask: Bitmask of drm_encoder_mask(encoder) of encoders
223*4882a593Smuzhiyun * attached to this CRTC.
224*4882a593Smuzhiyun */
225*4882a593Smuzhiyun u32 encoder_mask;
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun /**
228*4882a593Smuzhiyun * @adjusted_mode:
229*4882a593Smuzhiyun *
230*4882a593Smuzhiyun * Internal display timings which can be used by the driver to handle
231*4882a593Smuzhiyun * differences between the mode requested by userspace in @mode and what
232*4882a593Smuzhiyun * is actually programmed into the hardware.
233*4882a593Smuzhiyun *
234*4882a593Smuzhiyun * For drivers using &drm_bridge, this stores hardware display timings
235*4882a593Smuzhiyun * used between the CRTC and the first bridge. For other drivers, the
236*4882a593Smuzhiyun * meaning of the adjusted_mode field is purely driver implementation
237*4882a593Smuzhiyun * defined information, and will usually be used to store the hardware
238*4882a593Smuzhiyun * display timings used between the CRTC and encoder blocks.
239*4882a593Smuzhiyun */
240*4882a593Smuzhiyun struct drm_display_mode adjusted_mode;
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun /**
243*4882a593Smuzhiyun * @mode:
244*4882a593Smuzhiyun *
245*4882a593Smuzhiyun * Display timings requested by userspace. The driver should try to
246*4882a593Smuzhiyun * match the refresh rate as close as possible (but note that it's
247*4882a593Smuzhiyun * undefined what exactly is close enough, e.g. some of the HDMI modes
248*4882a593Smuzhiyun * only differ in less than 1% of the refresh rate). The active width
249*4882a593Smuzhiyun * and height as observed by userspace for positioning planes must match
250*4882a593Smuzhiyun * exactly.
251*4882a593Smuzhiyun *
252*4882a593Smuzhiyun * For external connectors where the sink isn't fixed (like with a
253*4882a593Smuzhiyun * built-in panel), this mode here should match the physical mode on the
254*4882a593Smuzhiyun * wire to the last details (i.e. including sync polarities and
255*4882a593Smuzhiyun * everything).
256*4882a593Smuzhiyun */
257*4882a593Smuzhiyun struct drm_display_mode mode;
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun /**
260*4882a593Smuzhiyun * @mode_blob: &drm_property_blob for @mode, for exposing the mode to
261*4882a593Smuzhiyun * atomic userspace.
262*4882a593Smuzhiyun */
263*4882a593Smuzhiyun struct drm_property_blob *mode_blob;
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun /**
266*4882a593Smuzhiyun * @degamma_lut:
267*4882a593Smuzhiyun *
268*4882a593Smuzhiyun * Lookup table for converting framebuffer pixel data before apply the
269*4882a593Smuzhiyun * color conversion matrix @ctm. See drm_crtc_enable_color_mgmt(). The
270*4882a593Smuzhiyun * blob (if not NULL) is an array of &struct drm_color_lut.
271*4882a593Smuzhiyun */
272*4882a593Smuzhiyun struct drm_property_blob *degamma_lut;
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun /**
275*4882a593Smuzhiyun * @ctm:
276*4882a593Smuzhiyun *
277*4882a593Smuzhiyun * Color transformation matrix. See drm_crtc_enable_color_mgmt(). The
278*4882a593Smuzhiyun * blob (if not NULL) is a &struct drm_color_ctm.
279*4882a593Smuzhiyun */
280*4882a593Smuzhiyun struct drm_property_blob *ctm;
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun /**
283*4882a593Smuzhiyun * @gamma_lut:
284*4882a593Smuzhiyun *
285*4882a593Smuzhiyun * Lookup table for converting pixel data after the color conversion
286*4882a593Smuzhiyun * matrix @ctm. See drm_crtc_enable_color_mgmt(). The blob (if not
287*4882a593Smuzhiyun * NULL) is an array of &struct drm_color_lut.
288*4882a593Smuzhiyun */
289*4882a593Smuzhiyun struct drm_property_blob *gamma_lut;
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun /**
292*4882a593Smuzhiyun * @target_vblank:
293*4882a593Smuzhiyun *
294*4882a593Smuzhiyun * Target vertical blank period when a page flip
295*4882a593Smuzhiyun * should take effect.
296*4882a593Smuzhiyun */
297*4882a593Smuzhiyun u32 target_vblank;
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun /**
300*4882a593Smuzhiyun * @async_flip:
301*4882a593Smuzhiyun *
302*4882a593Smuzhiyun * This is set when DRM_MODE_PAGE_FLIP_ASYNC is set in the legacy
303*4882a593Smuzhiyun * PAGE_FLIP IOCTL. It's not wired up for the atomic IOCTL itself yet.
304*4882a593Smuzhiyun */
305*4882a593Smuzhiyun bool async_flip;
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun /**
308*4882a593Smuzhiyun * @vrr_enabled:
309*4882a593Smuzhiyun *
310*4882a593Smuzhiyun * Indicates if variable refresh rate should be enabled for the CRTC.
311*4882a593Smuzhiyun * Support for the requested vrr state will depend on driver and
312*4882a593Smuzhiyun * hardware capabiltiy - lacking support is not treated as failure.
313*4882a593Smuzhiyun */
314*4882a593Smuzhiyun bool vrr_enabled;
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun /**
317*4882a593Smuzhiyun * @self_refresh_active:
318*4882a593Smuzhiyun *
319*4882a593Smuzhiyun * Used by the self refresh helpers to denote when a self refresh
320*4882a593Smuzhiyun * transition is occurring. This will be set on enable/disable callbacks
321*4882a593Smuzhiyun * when self refresh is being enabled or disabled. In some cases, it may
322*4882a593Smuzhiyun * not be desirable to fully shut off the crtc during self refresh.
323*4882a593Smuzhiyun * CRTC's can inspect this flag and determine the best course of action.
324*4882a593Smuzhiyun */
325*4882a593Smuzhiyun bool self_refresh_active;
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun /**
328*4882a593Smuzhiyun * @event:
329*4882a593Smuzhiyun *
330*4882a593Smuzhiyun * Optional pointer to a DRM event to signal upon completion of the
331*4882a593Smuzhiyun * state update. The driver must send out the event when the atomic
332*4882a593Smuzhiyun * commit operation completes. There are two cases:
333*4882a593Smuzhiyun *
334*4882a593Smuzhiyun * - The event is for a CRTC which is being disabled through this
335*4882a593Smuzhiyun * atomic commit. In that case the event can be send out any time
336*4882a593Smuzhiyun * after the hardware has stopped scanning out the current
337*4882a593Smuzhiyun * framebuffers. It should contain the timestamp and counter for the
338*4882a593Smuzhiyun * last vblank before the display pipeline was shut off. The simplest
339*4882a593Smuzhiyun * way to achieve that is calling drm_crtc_send_vblank_event()
340*4882a593Smuzhiyun * somewhen after drm_crtc_vblank_off() has been called.
341*4882a593Smuzhiyun *
342*4882a593Smuzhiyun * - For a CRTC which is enabled at the end of the commit (even when it
343*4882a593Smuzhiyun * undergoes an full modeset) the vblank timestamp and counter must
344*4882a593Smuzhiyun * be for the vblank right before the first frame that scans out the
345*4882a593Smuzhiyun * new set of buffers. Again the event can only be sent out after the
346*4882a593Smuzhiyun * hardware has stopped scanning out the old buffers.
347*4882a593Smuzhiyun *
348*4882a593Smuzhiyun * - Events for disabled CRTCs are not allowed, and drivers can ignore
349*4882a593Smuzhiyun * that case.
350*4882a593Smuzhiyun *
351*4882a593Smuzhiyun * For very simple hardware without VBLANK interrupt, enabling
352*4882a593Smuzhiyun * &struct drm_crtc_state.no_vblank makes DRM's atomic commit helpers
353*4882a593Smuzhiyun * send a fake VBLANK event at the end of the display update after all
354*4882a593Smuzhiyun * hardware changes have been applied. See
355*4882a593Smuzhiyun * drm_atomic_helper_fake_vblank().
356*4882a593Smuzhiyun *
357*4882a593Smuzhiyun * For more complex hardware this
358*4882a593Smuzhiyun * can be handled by the drm_crtc_send_vblank_event() function,
359*4882a593Smuzhiyun * which the driver should call on the provided event upon completion of
360*4882a593Smuzhiyun * the atomic commit. Note that if the driver supports vblank signalling
361*4882a593Smuzhiyun * and timestamping the vblank counters and timestamps must agree with
362*4882a593Smuzhiyun * the ones returned from page flip events. With the current vblank
363*4882a593Smuzhiyun * helper infrastructure this can be achieved by holding a vblank
364*4882a593Smuzhiyun * reference while the page flip is pending, acquired through
365*4882a593Smuzhiyun * drm_crtc_vblank_get() and released with drm_crtc_vblank_put().
366*4882a593Smuzhiyun * Drivers are free to implement their own vblank counter and timestamp
367*4882a593Smuzhiyun * tracking though, e.g. if they have accurate timestamp registers in
368*4882a593Smuzhiyun * hardware.
369*4882a593Smuzhiyun *
370*4882a593Smuzhiyun * For hardware which supports some means to synchronize vblank
371*4882a593Smuzhiyun * interrupt delivery with committing display state there's also
372*4882a593Smuzhiyun * drm_crtc_arm_vblank_event(). See the documentation of that function
373*4882a593Smuzhiyun * for a detailed discussion of the constraints it needs to be used
374*4882a593Smuzhiyun * safely.
375*4882a593Smuzhiyun *
376*4882a593Smuzhiyun * If the device can't notify of flip completion in a race-free way
377*4882a593Smuzhiyun * at all, then the event should be armed just after the page flip is
378*4882a593Smuzhiyun * committed. In the worst case the driver will send the event to
379*4882a593Smuzhiyun * userspace one frame too late. This doesn't allow for a real atomic
380*4882a593Smuzhiyun * update, but it should avoid tearing.
381*4882a593Smuzhiyun */
382*4882a593Smuzhiyun struct drm_pending_vblank_event *event;
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun /**
385*4882a593Smuzhiyun * @commit:
386*4882a593Smuzhiyun *
387*4882a593Smuzhiyun * This tracks how the commit for this update proceeds through the
388*4882a593Smuzhiyun * various phases. This is never cleared, except when we destroy the
389*4882a593Smuzhiyun * state, so that subsequent commits can synchronize with previous ones.
390*4882a593Smuzhiyun */
391*4882a593Smuzhiyun struct drm_crtc_commit *commit;
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun /** @state: backpointer to global drm_atomic_state */
394*4882a593Smuzhiyun struct drm_atomic_state *state;
395*4882a593Smuzhiyun };
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun /**
398*4882a593Smuzhiyun * struct drm_crtc_funcs - control CRTCs for a given device
399*4882a593Smuzhiyun *
400*4882a593Smuzhiyun * The drm_crtc_funcs structure is the central CRTC management structure
401*4882a593Smuzhiyun * in the DRM. Each CRTC controls one or more connectors (note that the name
402*4882a593Smuzhiyun * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
403*4882a593Smuzhiyun * connectors, not just CRTs).
404*4882a593Smuzhiyun *
405*4882a593Smuzhiyun * Each driver is responsible for filling out this structure at startup time,
406*4882a593Smuzhiyun * in addition to providing other modesetting features, like i2c and DDC
407*4882a593Smuzhiyun * bus accessors.
408*4882a593Smuzhiyun */
409*4882a593Smuzhiyun struct drm_crtc_funcs {
410*4882a593Smuzhiyun /**
411*4882a593Smuzhiyun * @reset:
412*4882a593Smuzhiyun *
413*4882a593Smuzhiyun * Reset CRTC hardware and software state to off. This function isn't
414*4882a593Smuzhiyun * called by the core directly, only through drm_mode_config_reset().
415*4882a593Smuzhiyun * It's not a helper hook only for historical reasons.
416*4882a593Smuzhiyun *
417*4882a593Smuzhiyun * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
418*4882a593Smuzhiyun * atomic state using this hook.
419*4882a593Smuzhiyun */
420*4882a593Smuzhiyun void (*reset)(struct drm_crtc *crtc);
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun /**
423*4882a593Smuzhiyun * @cursor_set:
424*4882a593Smuzhiyun *
425*4882a593Smuzhiyun * Update the cursor image. The cursor position is relative to the CRTC
426*4882a593Smuzhiyun * and can be partially or fully outside of the visible area.
427*4882a593Smuzhiyun *
428*4882a593Smuzhiyun * Note that contrary to all other KMS functions the legacy cursor entry
429*4882a593Smuzhiyun * points don't take a framebuffer object, but instead take directly a
430*4882a593Smuzhiyun * raw buffer object id from the driver's buffer manager (which is
431*4882a593Smuzhiyun * either GEM or TTM for current drivers).
432*4882a593Smuzhiyun *
433*4882a593Smuzhiyun * This entry point is deprecated, drivers should instead implement
434*4882a593Smuzhiyun * universal plane support and register a proper cursor plane using
435*4882a593Smuzhiyun * drm_crtc_init_with_planes().
436*4882a593Smuzhiyun *
437*4882a593Smuzhiyun * This callback is optional
438*4882a593Smuzhiyun *
439*4882a593Smuzhiyun * RETURNS:
440*4882a593Smuzhiyun *
441*4882a593Smuzhiyun * 0 on success or a negative error code on failure.
442*4882a593Smuzhiyun */
443*4882a593Smuzhiyun int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
444*4882a593Smuzhiyun uint32_t handle, uint32_t width, uint32_t height);
445*4882a593Smuzhiyun
446*4882a593Smuzhiyun /**
447*4882a593Smuzhiyun * @cursor_set2:
448*4882a593Smuzhiyun *
449*4882a593Smuzhiyun * Update the cursor image, including hotspot information. The hotspot
450*4882a593Smuzhiyun * must not affect the cursor position in CRTC coordinates, but is only
451*4882a593Smuzhiyun * meant as a hint for virtualized display hardware to coordinate the
452*4882a593Smuzhiyun * guests and hosts cursor position. The cursor hotspot is relative to
453*4882a593Smuzhiyun * the cursor image. Otherwise this works exactly like @cursor_set.
454*4882a593Smuzhiyun *
455*4882a593Smuzhiyun * This entry point is deprecated, drivers should instead implement
456*4882a593Smuzhiyun * universal plane support and register a proper cursor plane using
457*4882a593Smuzhiyun * drm_crtc_init_with_planes().
458*4882a593Smuzhiyun *
459*4882a593Smuzhiyun * This callback is optional.
460*4882a593Smuzhiyun *
461*4882a593Smuzhiyun * RETURNS:
462*4882a593Smuzhiyun *
463*4882a593Smuzhiyun * 0 on success or a negative error code on failure.
464*4882a593Smuzhiyun */
465*4882a593Smuzhiyun int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
466*4882a593Smuzhiyun uint32_t handle, uint32_t width, uint32_t height,
467*4882a593Smuzhiyun int32_t hot_x, int32_t hot_y);
468*4882a593Smuzhiyun
469*4882a593Smuzhiyun /**
470*4882a593Smuzhiyun * @cursor_move:
471*4882a593Smuzhiyun *
472*4882a593Smuzhiyun * Update the cursor position. The cursor does not need to be visible
473*4882a593Smuzhiyun * when this hook is called.
474*4882a593Smuzhiyun *
475*4882a593Smuzhiyun * This entry point is deprecated, drivers should instead implement
476*4882a593Smuzhiyun * universal plane support and register a proper cursor plane using
477*4882a593Smuzhiyun * drm_crtc_init_with_planes().
478*4882a593Smuzhiyun *
479*4882a593Smuzhiyun * This callback is optional.
480*4882a593Smuzhiyun *
481*4882a593Smuzhiyun * RETURNS:
482*4882a593Smuzhiyun *
483*4882a593Smuzhiyun * 0 on success or a negative error code on failure.
484*4882a593Smuzhiyun */
485*4882a593Smuzhiyun int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun /**
488*4882a593Smuzhiyun * @gamma_set:
489*4882a593Smuzhiyun *
490*4882a593Smuzhiyun * Set gamma on the CRTC.
491*4882a593Smuzhiyun *
492*4882a593Smuzhiyun * This callback is optional.
493*4882a593Smuzhiyun *
494*4882a593Smuzhiyun * Atomic drivers who want to support gamma tables should implement the
495*4882a593Smuzhiyun * atomic color management support, enabled by calling
496*4882a593Smuzhiyun * drm_crtc_enable_color_mgmt(), which then supports the legacy gamma
497*4882a593Smuzhiyun * interface through the drm_atomic_helper_legacy_gamma_set()
498*4882a593Smuzhiyun * compatibility implementation.
499*4882a593Smuzhiyun */
500*4882a593Smuzhiyun int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
501*4882a593Smuzhiyun uint32_t size,
502*4882a593Smuzhiyun struct drm_modeset_acquire_ctx *ctx);
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun /**
505*4882a593Smuzhiyun * @destroy:
506*4882a593Smuzhiyun *
507*4882a593Smuzhiyun * Clean up CRTC resources. This is only called at driver unload time
508*4882a593Smuzhiyun * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
509*4882a593Smuzhiyun * in DRM.
510*4882a593Smuzhiyun */
511*4882a593Smuzhiyun void (*destroy)(struct drm_crtc *crtc);
512*4882a593Smuzhiyun
513*4882a593Smuzhiyun /**
514*4882a593Smuzhiyun * @set_config:
515*4882a593Smuzhiyun *
516*4882a593Smuzhiyun * This is the main legacy entry point to change the modeset state on a
517*4882a593Smuzhiyun * CRTC. All the details of the desired configuration are passed in a
518*4882a593Smuzhiyun * &struct drm_mode_set - see there for details.
519*4882a593Smuzhiyun *
520*4882a593Smuzhiyun * Drivers implementing atomic modeset should use
521*4882a593Smuzhiyun * drm_atomic_helper_set_config() to implement this hook.
522*4882a593Smuzhiyun *
523*4882a593Smuzhiyun * RETURNS:
524*4882a593Smuzhiyun *
525*4882a593Smuzhiyun * 0 on success or a negative error code on failure.
526*4882a593Smuzhiyun */
527*4882a593Smuzhiyun int (*set_config)(struct drm_mode_set *set,
528*4882a593Smuzhiyun struct drm_modeset_acquire_ctx *ctx);
529*4882a593Smuzhiyun
530*4882a593Smuzhiyun /**
531*4882a593Smuzhiyun * @page_flip:
532*4882a593Smuzhiyun *
533*4882a593Smuzhiyun * Legacy entry point to schedule a flip to the given framebuffer.
534*4882a593Smuzhiyun *
535*4882a593Smuzhiyun * Page flipping is a synchronization mechanism that replaces the frame
536*4882a593Smuzhiyun * buffer being scanned out by the CRTC with a new frame buffer during
537*4882a593Smuzhiyun * vertical blanking, avoiding tearing (except when requested otherwise
538*4882a593Smuzhiyun * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
539*4882a593Smuzhiyun * requests a page flip the DRM core verifies that the new frame buffer
540*4882a593Smuzhiyun * is large enough to be scanned out by the CRTC in the currently
541*4882a593Smuzhiyun * configured mode and then calls this hook with a pointer to the new
542*4882a593Smuzhiyun * frame buffer.
543*4882a593Smuzhiyun *
544*4882a593Smuzhiyun * The driver must wait for any pending rendering to the new framebuffer
545*4882a593Smuzhiyun * to complete before executing the flip. It should also wait for any
546*4882a593Smuzhiyun * pending rendering from other drivers if the underlying buffer is a
547*4882a593Smuzhiyun * shared dma-buf.
548*4882a593Smuzhiyun *
549*4882a593Smuzhiyun * An application can request to be notified when the page flip has
550*4882a593Smuzhiyun * completed. The drm core will supply a &struct drm_event in the event
551*4882a593Smuzhiyun * parameter in this case. This can be handled by the
552*4882a593Smuzhiyun * drm_crtc_send_vblank_event() function, which the driver should call on
553*4882a593Smuzhiyun * the provided event upon completion of the flip. Note that if
554*4882a593Smuzhiyun * the driver supports vblank signalling and timestamping the vblank
555*4882a593Smuzhiyun * counters and timestamps must agree with the ones returned from page
556*4882a593Smuzhiyun * flip events. With the current vblank helper infrastructure this can
557*4882a593Smuzhiyun * be achieved by holding a vblank reference while the page flip is
558*4882a593Smuzhiyun * pending, acquired through drm_crtc_vblank_get() and released with
559*4882a593Smuzhiyun * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
560*4882a593Smuzhiyun * counter and timestamp tracking though, e.g. if they have accurate
561*4882a593Smuzhiyun * timestamp registers in hardware.
562*4882a593Smuzhiyun *
563*4882a593Smuzhiyun * This callback is optional.
564*4882a593Smuzhiyun *
565*4882a593Smuzhiyun * NOTE:
566*4882a593Smuzhiyun *
567*4882a593Smuzhiyun * Very early versions of the KMS ABI mandated that the driver must
568*4882a593Smuzhiyun * block (but not reject) any rendering to the old framebuffer until the
569*4882a593Smuzhiyun * flip operation has completed and the old framebuffer is no longer
570*4882a593Smuzhiyun * visible. This requirement has been lifted, and userspace is instead
571*4882a593Smuzhiyun * expected to request delivery of an event and wait with recycling old
572*4882a593Smuzhiyun * buffers until such has been received.
573*4882a593Smuzhiyun *
574*4882a593Smuzhiyun * RETURNS:
575*4882a593Smuzhiyun *
576*4882a593Smuzhiyun * 0 on success or a negative error code on failure. Note that if a
577*4882a593Smuzhiyun * page flip operation is already pending the callback should return
578*4882a593Smuzhiyun * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
579*4882a593Smuzhiyun * or just runtime disabled through DPMS respectively the new atomic
580*4882a593Smuzhiyun * "ACTIVE" state) should result in an -EINVAL error code. Note that
581*4882a593Smuzhiyun * drm_atomic_helper_page_flip() checks this already for atomic drivers.
582*4882a593Smuzhiyun */
583*4882a593Smuzhiyun int (*page_flip)(struct drm_crtc *crtc,
584*4882a593Smuzhiyun struct drm_framebuffer *fb,
585*4882a593Smuzhiyun struct drm_pending_vblank_event *event,
586*4882a593Smuzhiyun uint32_t flags,
587*4882a593Smuzhiyun struct drm_modeset_acquire_ctx *ctx);
588*4882a593Smuzhiyun
589*4882a593Smuzhiyun /**
590*4882a593Smuzhiyun * @page_flip_target:
591*4882a593Smuzhiyun *
592*4882a593Smuzhiyun * Same as @page_flip but with an additional parameter specifying the
593*4882a593Smuzhiyun * absolute target vertical blank period (as reported by
594*4882a593Smuzhiyun * drm_crtc_vblank_count()) when the flip should take effect.
595*4882a593Smuzhiyun *
596*4882a593Smuzhiyun * Note that the core code calls drm_crtc_vblank_get before this entry
597*4882a593Smuzhiyun * point, and will call drm_crtc_vblank_put if this entry point returns
598*4882a593Smuzhiyun * any non-0 error code. It's the driver's responsibility to call
599*4882a593Smuzhiyun * drm_crtc_vblank_put after this entry point returns 0, typically when
600*4882a593Smuzhiyun * the flip completes.
601*4882a593Smuzhiyun */
602*4882a593Smuzhiyun int (*page_flip_target)(struct drm_crtc *crtc,
603*4882a593Smuzhiyun struct drm_framebuffer *fb,
604*4882a593Smuzhiyun struct drm_pending_vblank_event *event,
605*4882a593Smuzhiyun uint32_t flags, uint32_t target,
606*4882a593Smuzhiyun struct drm_modeset_acquire_ctx *ctx);
607*4882a593Smuzhiyun
608*4882a593Smuzhiyun /**
609*4882a593Smuzhiyun * @set_property:
610*4882a593Smuzhiyun *
611*4882a593Smuzhiyun * This is the legacy entry point to update a property attached to the
612*4882a593Smuzhiyun * CRTC.
613*4882a593Smuzhiyun *
614*4882a593Smuzhiyun * This callback is optional if the driver does not support any legacy
615*4882a593Smuzhiyun * driver-private properties. For atomic drivers it is not used because
616*4882a593Smuzhiyun * property handling is done entirely in the DRM core.
617*4882a593Smuzhiyun *
618*4882a593Smuzhiyun * RETURNS:
619*4882a593Smuzhiyun *
620*4882a593Smuzhiyun * 0 on success or a negative error code on failure.
621*4882a593Smuzhiyun */
622*4882a593Smuzhiyun int (*set_property)(struct drm_crtc *crtc,
623*4882a593Smuzhiyun struct drm_property *property, uint64_t val);
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun /**
626*4882a593Smuzhiyun * @atomic_duplicate_state:
627*4882a593Smuzhiyun *
628*4882a593Smuzhiyun * Duplicate the current atomic state for this CRTC and return it.
629*4882a593Smuzhiyun * The core and helpers guarantee that any atomic state duplicated with
630*4882a593Smuzhiyun * this hook and still owned by the caller (i.e. not transferred to the
631*4882a593Smuzhiyun * driver by calling &drm_mode_config_funcs.atomic_commit) will be
632*4882a593Smuzhiyun * cleaned up by calling the @atomic_destroy_state hook in this
633*4882a593Smuzhiyun * structure.
634*4882a593Smuzhiyun *
635*4882a593Smuzhiyun * This callback is mandatory for atomic drivers.
636*4882a593Smuzhiyun *
637*4882a593Smuzhiyun * Atomic drivers which don't subclass &struct drm_crtc_state should use
638*4882a593Smuzhiyun * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
639*4882a593Smuzhiyun * state structure to extend it with driver-private state should use
640*4882a593Smuzhiyun * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
641*4882a593Smuzhiyun * duplicated in a consistent fashion across drivers.
642*4882a593Smuzhiyun *
643*4882a593Smuzhiyun * It is an error to call this hook before &drm_crtc.state has been
644*4882a593Smuzhiyun * initialized correctly.
645*4882a593Smuzhiyun *
646*4882a593Smuzhiyun * NOTE:
647*4882a593Smuzhiyun *
648*4882a593Smuzhiyun * If the duplicate state references refcounted resources this hook must
649*4882a593Smuzhiyun * acquire a reference for each of them. The driver must release these
650*4882a593Smuzhiyun * references again in @atomic_destroy_state.
651*4882a593Smuzhiyun *
652*4882a593Smuzhiyun * RETURNS:
653*4882a593Smuzhiyun *
654*4882a593Smuzhiyun * Duplicated atomic state or NULL when the allocation failed.
655*4882a593Smuzhiyun */
656*4882a593Smuzhiyun struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
657*4882a593Smuzhiyun
658*4882a593Smuzhiyun /**
659*4882a593Smuzhiyun * @atomic_destroy_state:
660*4882a593Smuzhiyun *
661*4882a593Smuzhiyun * Destroy a state duplicated with @atomic_duplicate_state and release
662*4882a593Smuzhiyun * or unreference all resources it references
663*4882a593Smuzhiyun *
664*4882a593Smuzhiyun * This callback is mandatory for atomic drivers.
665*4882a593Smuzhiyun */
666*4882a593Smuzhiyun void (*atomic_destroy_state)(struct drm_crtc *crtc,
667*4882a593Smuzhiyun struct drm_crtc_state *state);
668*4882a593Smuzhiyun
669*4882a593Smuzhiyun /**
670*4882a593Smuzhiyun * @atomic_set_property:
671*4882a593Smuzhiyun *
672*4882a593Smuzhiyun * Decode a driver-private property value and store the decoded value
673*4882a593Smuzhiyun * into the passed-in state structure. Since the atomic core decodes all
674*4882a593Smuzhiyun * standardized properties (even for extensions beyond the core set of
675*4882a593Smuzhiyun * properties which might not be implemented by all drivers) this
676*4882a593Smuzhiyun * requires drivers to subclass the state structure.
677*4882a593Smuzhiyun *
678*4882a593Smuzhiyun * Such driver-private properties should really only be implemented for
679*4882a593Smuzhiyun * truly hardware/vendor specific state. Instead it is preferred to
680*4882a593Smuzhiyun * standardize atomic extension and decode the properties used to expose
681*4882a593Smuzhiyun * such an extension in the core.
682*4882a593Smuzhiyun *
683*4882a593Smuzhiyun * Do not call this function directly, use
684*4882a593Smuzhiyun * drm_atomic_crtc_set_property() instead.
685*4882a593Smuzhiyun *
686*4882a593Smuzhiyun * This callback is optional if the driver does not support any
687*4882a593Smuzhiyun * driver-private atomic properties.
688*4882a593Smuzhiyun *
689*4882a593Smuzhiyun * NOTE:
690*4882a593Smuzhiyun *
691*4882a593Smuzhiyun * This function is called in the state assembly phase of atomic
692*4882a593Smuzhiyun * modesets, which can be aborted for any reason (including on
693*4882a593Smuzhiyun * userspace's request to just check whether a configuration would be
694*4882a593Smuzhiyun * possible). Drivers MUST NOT touch any persistent state (hardware or
695*4882a593Smuzhiyun * software) or data structures except the passed in @state parameter.
696*4882a593Smuzhiyun *
697*4882a593Smuzhiyun * Also since userspace controls in which order properties are set this
698*4882a593Smuzhiyun * function must not do any input validation (since the state update is
699*4882a593Smuzhiyun * incomplete and hence likely inconsistent). Instead any such input
700*4882a593Smuzhiyun * validation must be done in the various atomic_check callbacks.
701*4882a593Smuzhiyun *
702*4882a593Smuzhiyun * RETURNS:
703*4882a593Smuzhiyun *
704*4882a593Smuzhiyun * 0 if the property has been found, -EINVAL if the property isn't
705*4882a593Smuzhiyun * implemented by the driver (which should never happen, the core only
706*4882a593Smuzhiyun * asks for properties attached to this CRTC). No other validation is
707*4882a593Smuzhiyun * allowed by the driver. The core already checks that the property
708*4882a593Smuzhiyun * value is within the range (integer, valid enum value, ...) the driver
709*4882a593Smuzhiyun * set when registering the property.
710*4882a593Smuzhiyun */
711*4882a593Smuzhiyun int (*atomic_set_property)(struct drm_crtc *crtc,
712*4882a593Smuzhiyun struct drm_crtc_state *state,
713*4882a593Smuzhiyun struct drm_property *property,
714*4882a593Smuzhiyun uint64_t val);
715*4882a593Smuzhiyun /**
716*4882a593Smuzhiyun * @atomic_get_property:
717*4882a593Smuzhiyun *
718*4882a593Smuzhiyun * Reads out the decoded driver-private property. This is used to
719*4882a593Smuzhiyun * implement the GETCRTC IOCTL.
720*4882a593Smuzhiyun *
721*4882a593Smuzhiyun * Do not call this function directly, use
722*4882a593Smuzhiyun * drm_atomic_crtc_get_property() instead.
723*4882a593Smuzhiyun *
724*4882a593Smuzhiyun * This callback is optional if the driver does not support any
725*4882a593Smuzhiyun * driver-private atomic properties.
726*4882a593Smuzhiyun *
727*4882a593Smuzhiyun * RETURNS:
728*4882a593Smuzhiyun *
729*4882a593Smuzhiyun * 0 on success, -EINVAL if the property isn't implemented by the
730*4882a593Smuzhiyun * driver (which should never happen, the core only asks for
731*4882a593Smuzhiyun * properties attached to this CRTC).
732*4882a593Smuzhiyun */
733*4882a593Smuzhiyun int (*atomic_get_property)(struct drm_crtc *crtc,
734*4882a593Smuzhiyun const struct drm_crtc_state *state,
735*4882a593Smuzhiyun struct drm_property *property,
736*4882a593Smuzhiyun uint64_t *val);
737*4882a593Smuzhiyun
738*4882a593Smuzhiyun /**
739*4882a593Smuzhiyun * @late_register:
740*4882a593Smuzhiyun *
741*4882a593Smuzhiyun * This optional hook can be used to register additional userspace
742*4882a593Smuzhiyun * interfaces attached to the crtc like debugfs interfaces.
743*4882a593Smuzhiyun * It is called late in the driver load sequence from drm_dev_register().
744*4882a593Smuzhiyun * Everything added from this callback should be unregistered in
745*4882a593Smuzhiyun * the early_unregister callback.
746*4882a593Smuzhiyun *
747*4882a593Smuzhiyun * Returns:
748*4882a593Smuzhiyun *
749*4882a593Smuzhiyun * 0 on success, or a negative error code on failure.
750*4882a593Smuzhiyun */
751*4882a593Smuzhiyun int (*late_register)(struct drm_crtc *crtc);
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun /**
754*4882a593Smuzhiyun * @early_unregister:
755*4882a593Smuzhiyun *
756*4882a593Smuzhiyun * This optional hook should be used to unregister the additional
757*4882a593Smuzhiyun * userspace interfaces attached to the crtc from
758*4882a593Smuzhiyun * @late_register. It is called from drm_dev_unregister(),
759*4882a593Smuzhiyun * early in the driver unload sequence to disable userspace access
760*4882a593Smuzhiyun * before data structures are torndown.
761*4882a593Smuzhiyun */
762*4882a593Smuzhiyun void (*early_unregister)(struct drm_crtc *crtc);
763*4882a593Smuzhiyun
764*4882a593Smuzhiyun /**
765*4882a593Smuzhiyun * @set_crc_source:
766*4882a593Smuzhiyun *
767*4882a593Smuzhiyun * Changes the source of CRC checksums of frames at the request of
768*4882a593Smuzhiyun * userspace, typically for testing purposes. The sources available are
769*4882a593Smuzhiyun * specific of each driver and a %NULL value indicates that CRC
770*4882a593Smuzhiyun * generation is to be switched off.
771*4882a593Smuzhiyun *
772*4882a593Smuzhiyun * When CRC generation is enabled, the driver should call
773*4882a593Smuzhiyun * drm_crtc_add_crc_entry() at each frame, providing any information
774*4882a593Smuzhiyun * that characterizes the frame contents in the crcN arguments, as
775*4882a593Smuzhiyun * provided from the configured source. Drivers must accept an "auto"
776*4882a593Smuzhiyun * source name that will select a default source for this CRTC.
777*4882a593Smuzhiyun *
778*4882a593Smuzhiyun * This may trigger an atomic modeset commit if necessary, to enable CRC
779*4882a593Smuzhiyun * generation.
780*4882a593Smuzhiyun *
781*4882a593Smuzhiyun * Note that "auto" can depend upon the current modeset configuration,
782*4882a593Smuzhiyun * e.g. it could pick an encoder or output specific CRC sampling point.
783*4882a593Smuzhiyun *
784*4882a593Smuzhiyun * This callback is optional if the driver does not support any CRC
785*4882a593Smuzhiyun * generation functionality.
786*4882a593Smuzhiyun *
787*4882a593Smuzhiyun * RETURNS:
788*4882a593Smuzhiyun *
789*4882a593Smuzhiyun * 0 on success or a negative error code on failure.
790*4882a593Smuzhiyun */
791*4882a593Smuzhiyun int (*set_crc_source)(struct drm_crtc *crtc, const char *source);
792*4882a593Smuzhiyun
793*4882a593Smuzhiyun /**
794*4882a593Smuzhiyun * @verify_crc_source:
795*4882a593Smuzhiyun *
796*4882a593Smuzhiyun * verifies the source of CRC checksums of frames before setting the
797*4882a593Smuzhiyun * source for CRC and during crc open. Source parameter can be NULL
798*4882a593Smuzhiyun * while disabling crc source.
799*4882a593Smuzhiyun *
800*4882a593Smuzhiyun * This callback is optional if the driver does not support any CRC
801*4882a593Smuzhiyun * generation functionality.
802*4882a593Smuzhiyun *
803*4882a593Smuzhiyun * RETURNS:
804*4882a593Smuzhiyun *
805*4882a593Smuzhiyun * 0 on success or a negative error code on failure.
806*4882a593Smuzhiyun */
807*4882a593Smuzhiyun int (*verify_crc_source)(struct drm_crtc *crtc, const char *source,
808*4882a593Smuzhiyun size_t *values_cnt);
809*4882a593Smuzhiyun /**
810*4882a593Smuzhiyun * @get_crc_sources:
811*4882a593Smuzhiyun *
812*4882a593Smuzhiyun * Driver callback for getting a list of all the available sources for
813*4882a593Smuzhiyun * CRC generation. This callback depends upon verify_crc_source, So
814*4882a593Smuzhiyun * verify_crc_source callback should be implemented before implementing
815*4882a593Smuzhiyun * this. Driver can pass full list of available crc sources, this
816*4882a593Smuzhiyun * callback does the verification on each crc-source before passing it
817*4882a593Smuzhiyun * to userspace.
818*4882a593Smuzhiyun *
819*4882a593Smuzhiyun * This callback is optional if the driver does not support exporting of
820*4882a593Smuzhiyun * possible CRC sources list.
821*4882a593Smuzhiyun *
822*4882a593Smuzhiyun * RETURNS:
823*4882a593Smuzhiyun *
824*4882a593Smuzhiyun * a constant character pointer to the list of all the available CRC
825*4882a593Smuzhiyun * sources. On failure driver should return NULL. count should be
826*4882a593Smuzhiyun * updated with number of sources in list. if zero we don't process any
827*4882a593Smuzhiyun * source from the list.
828*4882a593Smuzhiyun */
829*4882a593Smuzhiyun const char *const *(*get_crc_sources)(struct drm_crtc *crtc,
830*4882a593Smuzhiyun size_t *count);
831*4882a593Smuzhiyun
832*4882a593Smuzhiyun /**
833*4882a593Smuzhiyun * @atomic_print_state:
834*4882a593Smuzhiyun *
835*4882a593Smuzhiyun * If driver subclasses &struct drm_crtc_state, it should implement
836*4882a593Smuzhiyun * this optional hook for printing additional driver specific state.
837*4882a593Smuzhiyun *
838*4882a593Smuzhiyun * Do not call this directly, use drm_atomic_crtc_print_state()
839*4882a593Smuzhiyun * instead.
840*4882a593Smuzhiyun */
841*4882a593Smuzhiyun void (*atomic_print_state)(struct drm_printer *p,
842*4882a593Smuzhiyun const struct drm_crtc_state *state);
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun /**
845*4882a593Smuzhiyun * @get_vblank_counter:
846*4882a593Smuzhiyun *
847*4882a593Smuzhiyun * Driver callback for fetching a raw hardware vblank counter for the
848*4882a593Smuzhiyun * CRTC. It's meant to be used by new drivers as the replacement of
849*4882a593Smuzhiyun * &drm_driver.get_vblank_counter hook.
850*4882a593Smuzhiyun *
851*4882a593Smuzhiyun * This callback is optional. If a device doesn't have a hardware
852*4882a593Smuzhiyun * counter, the driver can simply leave the hook as NULL. The DRM core
853*4882a593Smuzhiyun * will account for missed vblank events while interrupts where disabled
854*4882a593Smuzhiyun * based on system timestamps.
855*4882a593Smuzhiyun *
856*4882a593Smuzhiyun * Wraparound handling and loss of events due to modesetting is dealt
857*4882a593Smuzhiyun * with in the DRM core code, as long as drivers call
858*4882a593Smuzhiyun * drm_crtc_vblank_off() and drm_crtc_vblank_on() when disabling or
859*4882a593Smuzhiyun * enabling a CRTC.
860*4882a593Smuzhiyun *
861*4882a593Smuzhiyun * See also &drm_device.vblank_disable_immediate and
862*4882a593Smuzhiyun * &drm_device.max_vblank_count.
863*4882a593Smuzhiyun *
864*4882a593Smuzhiyun * Returns:
865*4882a593Smuzhiyun *
866*4882a593Smuzhiyun * Raw vblank counter value.
867*4882a593Smuzhiyun */
868*4882a593Smuzhiyun u32 (*get_vblank_counter)(struct drm_crtc *crtc);
869*4882a593Smuzhiyun
870*4882a593Smuzhiyun /**
871*4882a593Smuzhiyun * @enable_vblank:
872*4882a593Smuzhiyun *
873*4882a593Smuzhiyun * Enable vblank interrupts for the CRTC. It's meant to be used by
874*4882a593Smuzhiyun * new drivers as the replacement of &drm_driver.enable_vblank hook.
875*4882a593Smuzhiyun *
876*4882a593Smuzhiyun * Returns:
877*4882a593Smuzhiyun *
878*4882a593Smuzhiyun * Zero on success, appropriate errno if the vblank interrupt cannot
879*4882a593Smuzhiyun * be enabled.
880*4882a593Smuzhiyun */
881*4882a593Smuzhiyun int (*enable_vblank)(struct drm_crtc *crtc);
882*4882a593Smuzhiyun
883*4882a593Smuzhiyun /**
884*4882a593Smuzhiyun * @disable_vblank:
885*4882a593Smuzhiyun *
886*4882a593Smuzhiyun * Disable vblank interrupts for the CRTC. It's meant to be used by
887*4882a593Smuzhiyun * new drivers as the replacement of &drm_driver.disable_vblank hook.
888*4882a593Smuzhiyun */
889*4882a593Smuzhiyun void (*disable_vblank)(struct drm_crtc *crtc);
890*4882a593Smuzhiyun
891*4882a593Smuzhiyun /**
892*4882a593Smuzhiyun * @get_vblank_timestamp:
893*4882a593Smuzhiyun *
894*4882a593Smuzhiyun * Called by drm_get_last_vbltimestamp(). Should return a precise
895*4882a593Smuzhiyun * timestamp when the most recent vblank interval ended or will end.
896*4882a593Smuzhiyun *
897*4882a593Smuzhiyun * Specifically, the timestamp in @vblank_time should correspond as
898*4882a593Smuzhiyun * closely as possible to the time when the first video scanline of
899*4882a593Smuzhiyun * the video frame after the end of vblank will start scanning out,
900*4882a593Smuzhiyun * the time immediately after end of the vblank interval. If the
901*4882a593Smuzhiyun * @crtc is currently inside vblank, this will be a time in the future.
902*4882a593Smuzhiyun * If the @crtc is currently scanning out a frame, this will be the
903*4882a593Smuzhiyun * past start time of the current scanout. This is meant to adhere
904*4882a593Smuzhiyun * to the OpenML OML_sync_control extension specification.
905*4882a593Smuzhiyun *
906*4882a593Smuzhiyun * Parameters:
907*4882a593Smuzhiyun *
908*4882a593Smuzhiyun * crtc:
909*4882a593Smuzhiyun * CRTC for which timestamp should be returned.
910*4882a593Smuzhiyun * max_error:
911*4882a593Smuzhiyun * Maximum allowable timestamp error in nanoseconds.
912*4882a593Smuzhiyun * Implementation should strive to provide timestamp
913*4882a593Smuzhiyun * with an error of at most max_error nanoseconds.
914*4882a593Smuzhiyun * Returns true upper bound on error for timestamp.
915*4882a593Smuzhiyun * vblank_time:
916*4882a593Smuzhiyun * Target location for returned vblank timestamp.
917*4882a593Smuzhiyun * in_vblank_irq:
918*4882a593Smuzhiyun * True when called from drm_crtc_handle_vblank(). Some drivers
919*4882a593Smuzhiyun * need to apply some workarounds for gpu-specific vblank irq quirks
920*4882a593Smuzhiyun * if flag is set.
921*4882a593Smuzhiyun *
922*4882a593Smuzhiyun * Returns:
923*4882a593Smuzhiyun *
924*4882a593Smuzhiyun * True on success, false on failure, which means the core should
925*4882a593Smuzhiyun * fallback to a simple timestamp taken in drm_crtc_handle_vblank().
926*4882a593Smuzhiyun */
927*4882a593Smuzhiyun bool (*get_vblank_timestamp)(struct drm_crtc *crtc,
928*4882a593Smuzhiyun int *max_error,
929*4882a593Smuzhiyun ktime_t *vblank_time,
930*4882a593Smuzhiyun bool in_vblank_irq);
931*4882a593Smuzhiyun };
932*4882a593Smuzhiyun
933*4882a593Smuzhiyun /**
934*4882a593Smuzhiyun * struct drm_crtc - central CRTC control structure
935*4882a593Smuzhiyun *
936*4882a593Smuzhiyun * Each CRTC may have one or more connectors associated with it. This structure
937*4882a593Smuzhiyun * allows the CRTC to be controlled.
938*4882a593Smuzhiyun */
939*4882a593Smuzhiyun struct drm_crtc {
940*4882a593Smuzhiyun /** @dev: parent DRM device */
941*4882a593Smuzhiyun struct drm_device *dev;
942*4882a593Smuzhiyun /** @port: OF node used by drm_of_find_possible_crtcs(). */
943*4882a593Smuzhiyun struct device_node *port;
944*4882a593Smuzhiyun /**
945*4882a593Smuzhiyun * @head:
946*4882a593Smuzhiyun *
947*4882a593Smuzhiyun * List of all CRTCs on @dev, linked from &drm_mode_config.crtc_list.
948*4882a593Smuzhiyun * Invariant over the lifetime of @dev and therefore does not need
949*4882a593Smuzhiyun * locking.
950*4882a593Smuzhiyun */
951*4882a593Smuzhiyun struct list_head head;
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun /** @name: human readable name, can be overwritten by the driver */
954*4882a593Smuzhiyun char *name;
955*4882a593Smuzhiyun
956*4882a593Smuzhiyun /**
957*4882a593Smuzhiyun * @mutex:
958*4882a593Smuzhiyun *
959*4882a593Smuzhiyun * This provides a read lock for the overall CRTC state (mode, dpms
960*4882a593Smuzhiyun * state, ...) and a write lock for everything which can be update
961*4882a593Smuzhiyun * without a full modeset (fb, cursor data, CRTC properties ...). A full
962*4882a593Smuzhiyun * modeset also need to grab &drm_mode_config.connection_mutex.
963*4882a593Smuzhiyun *
964*4882a593Smuzhiyun * For atomic drivers specifically this protects @state.
965*4882a593Smuzhiyun */
966*4882a593Smuzhiyun struct drm_modeset_lock mutex;
967*4882a593Smuzhiyun
968*4882a593Smuzhiyun /** @base: base KMS object for ID tracking etc. */
969*4882a593Smuzhiyun struct drm_mode_object base;
970*4882a593Smuzhiyun
971*4882a593Smuzhiyun /**
972*4882a593Smuzhiyun * @primary:
973*4882a593Smuzhiyun * Primary plane for this CRTC. Note that this is only
974*4882a593Smuzhiyun * relevant for legacy IOCTL, it specifies the plane implicitly used by
975*4882a593Smuzhiyun * the SETCRTC and PAGE_FLIP IOCTLs. It does not have any significance
976*4882a593Smuzhiyun * beyond that.
977*4882a593Smuzhiyun */
978*4882a593Smuzhiyun struct drm_plane *primary;
979*4882a593Smuzhiyun
980*4882a593Smuzhiyun /**
981*4882a593Smuzhiyun * @cursor:
982*4882a593Smuzhiyun * Cursor plane for this CRTC. Note that this is only relevant for
983*4882a593Smuzhiyun * legacy IOCTL, it specifies the plane implicitly used by the SETCURSOR
984*4882a593Smuzhiyun * and SETCURSOR2 IOCTLs. It does not have any significance
985*4882a593Smuzhiyun * beyond that.
986*4882a593Smuzhiyun */
987*4882a593Smuzhiyun struct drm_plane *cursor;
988*4882a593Smuzhiyun
989*4882a593Smuzhiyun /**
990*4882a593Smuzhiyun * @index: Position inside the mode_config.list, can be used as an array
991*4882a593Smuzhiyun * index. It is invariant over the lifetime of the CRTC.
992*4882a593Smuzhiyun */
993*4882a593Smuzhiyun unsigned index;
994*4882a593Smuzhiyun
995*4882a593Smuzhiyun /**
996*4882a593Smuzhiyun * @cursor_x: Current x position of the cursor, used for universal
997*4882a593Smuzhiyun * cursor planes because the SETCURSOR IOCTL only can update the
998*4882a593Smuzhiyun * framebuffer without supplying the coordinates. Drivers should not use
999*4882a593Smuzhiyun * this directly, atomic drivers should look at &drm_plane_state.crtc_x
1000*4882a593Smuzhiyun * of the cursor plane instead.
1001*4882a593Smuzhiyun */
1002*4882a593Smuzhiyun int cursor_x;
1003*4882a593Smuzhiyun /**
1004*4882a593Smuzhiyun * @cursor_y: Current y position of the cursor, used for universal
1005*4882a593Smuzhiyun * cursor planes because the SETCURSOR IOCTL only can update the
1006*4882a593Smuzhiyun * framebuffer without supplying the coordinates. Drivers should not use
1007*4882a593Smuzhiyun * this directly, atomic drivers should look at &drm_plane_state.crtc_y
1008*4882a593Smuzhiyun * of the cursor plane instead.
1009*4882a593Smuzhiyun */
1010*4882a593Smuzhiyun int cursor_y;
1011*4882a593Smuzhiyun
1012*4882a593Smuzhiyun /**
1013*4882a593Smuzhiyun * @enabled:
1014*4882a593Smuzhiyun *
1015*4882a593Smuzhiyun * Is this CRTC enabled? Should only be used by legacy drivers, atomic
1016*4882a593Smuzhiyun * drivers should instead consult &drm_crtc_state.enable and
1017*4882a593Smuzhiyun * &drm_crtc_state.active. Atomic drivers can update this by calling
1018*4882a593Smuzhiyun * drm_atomic_helper_update_legacy_modeset_state().
1019*4882a593Smuzhiyun */
1020*4882a593Smuzhiyun bool enabled;
1021*4882a593Smuzhiyun
1022*4882a593Smuzhiyun /**
1023*4882a593Smuzhiyun * @mode:
1024*4882a593Smuzhiyun *
1025*4882a593Smuzhiyun * Current mode timings. Should only be used by legacy drivers, atomic
1026*4882a593Smuzhiyun * drivers should instead consult &drm_crtc_state.mode. Atomic drivers
1027*4882a593Smuzhiyun * can update this by calling
1028*4882a593Smuzhiyun * drm_atomic_helper_update_legacy_modeset_state().
1029*4882a593Smuzhiyun */
1030*4882a593Smuzhiyun struct drm_display_mode mode;
1031*4882a593Smuzhiyun
1032*4882a593Smuzhiyun /**
1033*4882a593Smuzhiyun * @hwmode:
1034*4882a593Smuzhiyun *
1035*4882a593Smuzhiyun * Programmed mode in hw, after adjustments for encoders, crtc, panel
1036*4882a593Smuzhiyun * scaling etc. Should only be used by legacy drivers, for high
1037*4882a593Smuzhiyun * precision vblank timestamps in
1038*4882a593Smuzhiyun * drm_crtc_vblank_helper_get_vblank_timestamp().
1039*4882a593Smuzhiyun *
1040*4882a593Smuzhiyun * Note that atomic drivers should not use this, but instead use
1041*4882a593Smuzhiyun * &drm_crtc_state.adjusted_mode. And for high-precision timestamps
1042*4882a593Smuzhiyun * drm_crtc_vblank_helper_get_vblank_timestamp() used
1043*4882a593Smuzhiyun * &drm_vblank_crtc.hwmode,
1044*4882a593Smuzhiyun * which is filled out by calling drm_calc_timestamping_constants().
1045*4882a593Smuzhiyun */
1046*4882a593Smuzhiyun struct drm_display_mode hwmode;
1047*4882a593Smuzhiyun
1048*4882a593Smuzhiyun /**
1049*4882a593Smuzhiyun * @x:
1050*4882a593Smuzhiyun * x position on screen. Should only be used by legacy drivers, atomic
1051*4882a593Smuzhiyun * drivers should look at &drm_plane_state.crtc_x of the primary plane
1052*4882a593Smuzhiyun * instead. Updated by calling
1053*4882a593Smuzhiyun * drm_atomic_helper_update_legacy_modeset_state().
1054*4882a593Smuzhiyun */
1055*4882a593Smuzhiyun int x;
1056*4882a593Smuzhiyun /**
1057*4882a593Smuzhiyun * @y:
1058*4882a593Smuzhiyun * y position on screen. Should only be used by legacy drivers, atomic
1059*4882a593Smuzhiyun * drivers should look at &drm_plane_state.crtc_y of the primary plane
1060*4882a593Smuzhiyun * instead. Updated by calling
1061*4882a593Smuzhiyun * drm_atomic_helper_update_legacy_modeset_state().
1062*4882a593Smuzhiyun */
1063*4882a593Smuzhiyun int y;
1064*4882a593Smuzhiyun
1065*4882a593Smuzhiyun /** @funcs: CRTC control functions */
1066*4882a593Smuzhiyun const struct drm_crtc_funcs *funcs;
1067*4882a593Smuzhiyun
1068*4882a593Smuzhiyun /**
1069*4882a593Smuzhiyun * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
1070*4882a593Smuzhiyun * by calling drm_mode_crtc_set_gamma_size().
1071*4882a593Smuzhiyun */
1072*4882a593Smuzhiyun uint32_t gamma_size;
1073*4882a593Smuzhiyun
1074*4882a593Smuzhiyun /**
1075*4882a593Smuzhiyun * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
1076*4882a593Smuzhiyun * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
1077*4882a593Smuzhiyun */
1078*4882a593Smuzhiyun uint16_t *gamma_store;
1079*4882a593Smuzhiyun
1080*4882a593Smuzhiyun /** @helper_private: mid-layer private data */
1081*4882a593Smuzhiyun const struct drm_crtc_helper_funcs *helper_private;
1082*4882a593Smuzhiyun
1083*4882a593Smuzhiyun /** @properties: property tracking for this CRTC */
1084*4882a593Smuzhiyun struct drm_object_properties properties;
1085*4882a593Smuzhiyun
1086*4882a593Smuzhiyun /**
1087*4882a593Smuzhiyun * @state:
1088*4882a593Smuzhiyun *
1089*4882a593Smuzhiyun * Current atomic state for this CRTC.
1090*4882a593Smuzhiyun *
1091*4882a593Smuzhiyun * This is protected by @mutex. Note that nonblocking atomic commits
1092*4882a593Smuzhiyun * access the current CRTC state without taking locks. Either by going
1093*4882a593Smuzhiyun * through the &struct drm_atomic_state pointers, see
1094*4882a593Smuzhiyun * for_each_oldnew_crtc_in_state(), for_each_old_crtc_in_state() and
1095*4882a593Smuzhiyun * for_each_new_crtc_in_state(). Or through careful ordering of atomic
1096*4882a593Smuzhiyun * commit operations as implemented in the atomic helpers, see
1097*4882a593Smuzhiyun * &struct drm_crtc_commit.
1098*4882a593Smuzhiyun */
1099*4882a593Smuzhiyun struct drm_crtc_state *state;
1100*4882a593Smuzhiyun
1101*4882a593Smuzhiyun /**
1102*4882a593Smuzhiyun * @commit_list:
1103*4882a593Smuzhiyun *
1104*4882a593Smuzhiyun * List of &drm_crtc_commit structures tracking pending commits.
1105*4882a593Smuzhiyun * Protected by @commit_lock. This list holds its own full reference,
1106*4882a593Smuzhiyun * as does the ongoing commit.
1107*4882a593Smuzhiyun *
1108*4882a593Smuzhiyun * "Note that the commit for a state change is also tracked in
1109*4882a593Smuzhiyun * &drm_crtc_state.commit. For accessing the immediately preceding
1110*4882a593Smuzhiyun * commit in an atomic update it is recommended to just use that
1111*4882a593Smuzhiyun * pointer in the old CRTC state, since accessing that doesn't need
1112*4882a593Smuzhiyun * any locking or list-walking. @commit_list should only be used to
1113*4882a593Smuzhiyun * stall for framebuffer cleanup that's signalled through
1114*4882a593Smuzhiyun * &drm_crtc_commit.cleanup_done."
1115*4882a593Smuzhiyun */
1116*4882a593Smuzhiyun struct list_head commit_list;
1117*4882a593Smuzhiyun
1118*4882a593Smuzhiyun /**
1119*4882a593Smuzhiyun * @commit_lock:
1120*4882a593Smuzhiyun *
1121*4882a593Smuzhiyun * Spinlock to protect @commit_list.
1122*4882a593Smuzhiyun */
1123*4882a593Smuzhiyun spinlock_t commit_lock;
1124*4882a593Smuzhiyun
1125*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_FS
1126*4882a593Smuzhiyun /**
1127*4882a593Smuzhiyun * @debugfs_entry:
1128*4882a593Smuzhiyun *
1129*4882a593Smuzhiyun * Debugfs directory for this CRTC.
1130*4882a593Smuzhiyun */
1131*4882a593Smuzhiyun struct dentry *debugfs_entry;
1132*4882a593Smuzhiyun #endif
1133*4882a593Smuzhiyun
1134*4882a593Smuzhiyun /**
1135*4882a593Smuzhiyun * @crc:
1136*4882a593Smuzhiyun *
1137*4882a593Smuzhiyun * Configuration settings of CRC capture.
1138*4882a593Smuzhiyun */
1139*4882a593Smuzhiyun struct drm_crtc_crc crc;
1140*4882a593Smuzhiyun
1141*4882a593Smuzhiyun /**
1142*4882a593Smuzhiyun * @fence_context:
1143*4882a593Smuzhiyun *
1144*4882a593Smuzhiyun * timeline context used for fence operations.
1145*4882a593Smuzhiyun */
1146*4882a593Smuzhiyun unsigned int fence_context;
1147*4882a593Smuzhiyun
1148*4882a593Smuzhiyun /**
1149*4882a593Smuzhiyun * @fence_lock:
1150*4882a593Smuzhiyun *
1151*4882a593Smuzhiyun * spinlock to protect the fences in the fence_context.
1152*4882a593Smuzhiyun */
1153*4882a593Smuzhiyun spinlock_t fence_lock;
1154*4882a593Smuzhiyun /**
1155*4882a593Smuzhiyun * @fence_seqno:
1156*4882a593Smuzhiyun *
1157*4882a593Smuzhiyun * Seqno variable used as monotonic counter for the fences
1158*4882a593Smuzhiyun * created on the CRTC's timeline.
1159*4882a593Smuzhiyun */
1160*4882a593Smuzhiyun unsigned long fence_seqno;
1161*4882a593Smuzhiyun
1162*4882a593Smuzhiyun /**
1163*4882a593Smuzhiyun * @timeline_name:
1164*4882a593Smuzhiyun *
1165*4882a593Smuzhiyun * The name of the CRTC's fence timeline.
1166*4882a593Smuzhiyun */
1167*4882a593Smuzhiyun char timeline_name[32];
1168*4882a593Smuzhiyun
1169*4882a593Smuzhiyun /**
1170*4882a593Smuzhiyun * @self_refresh_data: Holds the state for the self refresh helpers
1171*4882a593Smuzhiyun *
1172*4882a593Smuzhiyun * Initialized via drm_self_refresh_helper_init().
1173*4882a593Smuzhiyun */
1174*4882a593Smuzhiyun struct drm_self_refresh_data *self_refresh_data;
1175*4882a593Smuzhiyun };
1176*4882a593Smuzhiyun
1177*4882a593Smuzhiyun /**
1178*4882a593Smuzhiyun * struct drm_mode_set - new values for a CRTC config change
1179*4882a593Smuzhiyun * @fb: framebuffer to use for new config
1180*4882a593Smuzhiyun * @crtc: CRTC whose configuration we're about to change
1181*4882a593Smuzhiyun * @mode: mode timings to use
1182*4882a593Smuzhiyun * @x: position of this CRTC relative to @fb
1183*4882a593Smuzhiyun * @y: position of this CRTC relative to @fb
1184*4882a593Smuzhiyun * @connectors: array of connectors to drive with this CRTC if possible
1185*4882a593Smuzhiyun * @num_connectors: size of @connectors array
1186*4882a593Smuzhiyun *
1187*4882a593Smuzhiyun * This represents a modeset configuration for the legacy SETCRTC ioctl and is
1188*4882a593Smuzhiyun * also used internally. Atomic drivers instead use &drm_atomic_state.
1189*4882a593Smuzhiyun */
1190*4882a593Smuzhiyun struct drm_mode_set {
1191*4882a593Smuzhiyun struct drm_framebuffer *fb;
1192*4882a593Smuzhiyun struct drm_crtc *crtc;
1193*4882a593Smuzhiyun struct drm_display_mode *mode;
1194*4882a593Smuzhiyun
1195*4882a593Smuzhiyun uint32_t x;
1196*4882a593Smuzhiyun uint32_t y;
1197*4882a593Smuzhiyun
1198*4882a593Smuzhiyun struct drm_connector **connectors;
1199*4882a593Smuzhiyun size_t num_connectors;
1200*4882a593Smuzhiyun };
1201*4882a593Smuzhiyun
1202*4882a593Smuzhiyun #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
1203*4882a593Smuzhiyun
1204*4882a593Smuzhiyun __printf(6, 7)
1205*4882a593Smuzhiyun int drm_crtc_init_with_planes(struct drm_device *dev,
1206*4882a593Smuzhiyun struct drm_crtc *crtc,
1207*4882a593Smuzhiyun struct drm_plane *primary,
1208*4882a593Smuzhiyun struct drm_plane *cursor,
1209*4882a593Smuzhiyun const struct drm_crtc_funcs *funcs,
1210*4882a593Smuzhiyun const char *name, ...);
1211*4882a593Smuzhiyun void drm_crtc_cleanup(struct drm_crtc *crtc);
1212*4882a593Smuzhiyun
1213*4882a593Smuzhiyun /**
1214*4882a593Smuzhiyun * drm_crtc_index - find the index of a registered CRTC
1215*4882a593Smuzhiyun * @crtc: CRTC to find index for
1216*4882a593Smuzhiyun *
1217*4882a593Smuzhiyun * Given a registered CRTC, return the index of that CRTC within a DRM
1218*4882a593Smuzhiyun * device's list of CRTCs.
1219*4882a593Smuzhiyun */
drm_crtc_index(const struct drm_crtc * crtc)1220*4882a593Smuzhiyun static inline unsigned int drm_crtc_index(const struct drm_crtc *crtc)
1221*4882a593Smuzhiyun {
1222*4882a593Smuzhiyun return crtc->index;
1223*4882a593Smuzhiyun }
1224*4882a593Smuzhiyun
1225*4882a593Smuzhiyun /**
1226*4882a593Smuzhiyun * drm_crtc_mask - find the mask of a registered CRTC
1227*4882a593Smuzhiyun * @crtc: CRTC to find mask for
1228*4882a593Smuzhiyun *
1229*4882a593Smuzhiyun * Given a registered CRTC, return the mask bit of that CRTC for the
1230*4882a593Smuzhiyun * &drm_encoder.possible_crtcs and &drm_plane.possible_crtcs fields.
1231*4882a593Smuzhiyun */
drm_crtc_mask(const struct drm_crtc * crtc)1232*4882a593Smuzhiyun static inline uint32_t drm_crtc_mask(const struct drm_crtc *crtc)
1233*4882a593Smuzhiyun {
1234*4882a593Smuzhiyun return 1 << drm_crtc_index(crtc);
1235*4882a593Smuzhiyun }
1236*4882a593Smuzhiyun
1237*4882a593Smuzhiyun int drm_mode_set_config_internal(struct drm_mode_set *set);
1238*4882a593Smuzhiyun struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx);
1239*4882a593Smuzhiyun
1240*4882a593Smuzhiyun /**
1241*4882a593Smuzhiyun * drm_crtc_find - look up a CRTC object from its ID
1242*4882a593Smuzhiyun * @dev: DRM device
1243*4882a593Smuzhiyun * @file_priv: drm file to check for lease against.
1244*4882a593Smuzhiyun * @id: &drm_mode_object ID
1245*4882a593Smuzhiyun *
1246*4882a593Smuzhiyun * This can be used to look up a CRTC from its userspace ID. Only used by
1247*4882a593Smuzhiyun * drivers for legacy IOCTLs and interface, nowadays extensions to the KMS
1248*4882a593Smuzhiyun * userspace interface should be done using &drm_property.
1249*4882a593Smuzhiyun */
drm_crtc_find(struct drm_device * dev,struct drm_file * file_priv,uint32_t id)1250*4882a593Smuzhiyun static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1251*4882a593Smuzhiyun struct drm_file *file_priv,
1252*4882a593Smuzhiyun uint32_t id)
1253*4882a593Smuzhiyun {
1254*4882a593Smuzhiyun struct drm_mode_object *mo;
1255*4882a593Smuzhiyun mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_CRTC);
1256*4882a593Smuzhiyun return mo ? obj_to_crtc(mo) : NULL;
1257*4882a593Smuzhiyun }
1258*4882a593Smuzhiyun
1259*4882a593Smuzhiyun /**
1260*4882a593Smuzhiyun * drm_for_each_crtc - iterate over all CRTCs
1261*4882a593Smuzhiyun * @crtc: a &struct drm_crtc as the loop cursor
1262*4882a593Smuzhiyun * @dev: the &struct drm_device
1263*4882a593Smuzhiyun *
1264*4882a593Smuzhiyun * Iterate over all CRTCs of @dev.
1265*4882a593Smuzhiyun */
1266*4882a593Smuzhiyun #define drm_for_each_crtc(crtc, dev) \
1267*4882a593Smuzhiyun list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1268*4882a593Smuzhiyun
1269*4882a593Smuzhiyun #endif /* __DRM_CRTC_H__ */
1270