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