^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (c) 2006-2008 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2008 Red Hat Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * DRM core CRTC related functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Permission to use, copy, modify, distribute, and sell this software and its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * documentation for any purpose is hereby granted without fee, provided that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * the above copyright notice appear in all copies and that both that copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * notice and this permission notice appear in supporting documentation, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * that the name of the copyright holders not be used in advertising or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * publicity pertaining to distribution of the software without specific,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * written prior permission. The copyright holders make no representations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * about the suitability of this software for any purpose. It is provided "as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * is" without express or implied warranty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * OF THIS SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Keith Packard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Eric Anholt <eric@anholt.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * Dave Airlie <airlied@linux.ie>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Jesse Barnes <jesse.barnes@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/dma-fence.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <drm/drm_crtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <drm/drm_edid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <drm/drm_fourcc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <drm/drm_modeset_lock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <drm/drm_atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <drm/drm_auth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <drm/drm_debugfs_crc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <drm/drm_drv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <drm/drm_print.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <drm/drm_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include "drm_crtc_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include "drm_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * DOC: overview
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * A CRTC represents the overall display pipeline. It receives pixel data from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * &drm_plane and blends them together. The &drm_display_mode is also attached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * to the CRTC, specifying display timings. On the output side the data is fed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * to one or more &drm_encoder, which are then each connected to one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * &drm_connector.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * To create a CRTC, a KMS drivers allocates and zeroes an instances of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * &struct drm_crtc (possibly as part of a larger structure) and registers it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * with a call to drm_crtc_init_with_planes().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * The CRTC is also the entry point for legacy modeset operations, see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * &drm_crtc_funcs.set_config, legacy plane operations, see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * &drm_crtc_funcs.page_flip and &drm_crtc_funcs.cursor_set2, and other legacy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * operations like &drm_crtc_funcs.gamma_set. For atomic drivers all these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * features are controlled through &drm_property and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * &drm_mode_config_funcs.atomic_check and &drm_mode_config_funcs.atomic_check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * drm_crtc_from_index - find the registered CRTC at an index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * @dev: DRM device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * @idx: index of registered CRTC to find for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Given a CRTC index, return the registered CRTC from DRM device's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * list of CRTCs with matching index. This is the inverse of drm_crtc_index().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * It's useful in the vblank callbacks (like &drm_driver.enable_vblank or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * &drm_driver.disable_vblank), since that still deals with indices instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * of pointers to &struct drm_crtc."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct drm_crtc *crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) drm_for_each_crtc(crtc, dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (idx == crtc->index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) EXPORT_SYMBOL(drm_crtc_from_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int drm_crtc_force_disable(struct drm_crtc *crtc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct drm_mode_set set = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .crtc = crtc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) WARN_ON(drm_drv_uses_atomic_modeset(crtc->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return drm_mode_set_config_internal(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static unsigned int drm_num_crtcs(struct drm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned int num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct drm_crtc *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) drm_for_each_crtc(tmp, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int drm_crtc_register_all(struct drm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct drm_crtc *crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) drm_for_each_crtc(crtc, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) drm_debugfs_crtc_add(crtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (crtc->funcs->late_register)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ret = crtc->funcs->late_register(crtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) void drm_crtc_unregister_all(struct drm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct drm_crtc *crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) drm_for_each_crtc(crtc, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (crtc->funcs->early_unregister)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) crtc->funcs->early_unregister(crtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) drm_debugfs_crtc_remove(crtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static int drm_crtc_crc_init(struct drm_crtc *crtc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) spin_lock_init(&crtc->crc.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) init_waitqueue_head(&crtc->crc.wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) crtc->crc.source = kstrdup("auto", GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (!crtc->crc.source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static void drm_crtc_crc_fini(struct drm_crtc *crtc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) kfree(crtc->crc.source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static const struct dma_fence_ops drm_crtc_fence_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static struct drm_crtc *fence_to_crtc(struct dma_fence *fence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) BUG_ON(fence->ops != &drm_crtc_fence_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return container_of(fence->lock, struct drm_crtc, fence_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static const char *drm_crtc_fence_get_driver_name(struct dma_fence *fence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct drm_crtc *crtc = fence_to_crtc(fence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return crtc->dev->driver->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static const char *drm_crtc_fence_get_timeline_name(struct dma_fence *fence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct drm_crtc *crtc = fence_to_crtc(fence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return crtc->timeline_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static const struct dma_fence_ops drm_crtc_fence_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) .get_driver_name = drm_crtc_fence_get_driver_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) .get_timeline_name = drm_crtc_fence_get_timeline_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct dma_fence *drm_crtc_create_fence(struct drm_crtc *crtc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct dma_fence *fence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) fence = kzalloc(sizeof(*fence), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (!fence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) dma_fence_init(fence, &drm_crtc_fence_ops, &crtc->fence_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) crtc->fence_context, ++crtc->fence_seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return fence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * DOC: standard CRTC properties
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * DRM CRTCs have a few standardized properties:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * ACTIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * Atomic property for setting the power state of the CRTC. When set to 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * the CRTC will actively display content. When set to 0 the CRTC will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * powered off. There is no expectation that user-space will reset CRTC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * resources like the mode and planes when setting ACTIVE to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * User-space can rely on an ACTIVE change to 1 to never fail an atomic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * test as long as no other property has changed. If a change to ACTIVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * fails an atomic test, this is a driver bug. For this reason setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * ACTIVE to 0 must not release internal resources (like reserved memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * bandwidth or clock generators).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * Note that the legacy DPMS property on connectors is internally routed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * to control this property for atomic drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * MODE_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * Atomic property for setting the CRTC display timings. The value is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * ID of a blob containing the DRM mode info. To disable the CRTC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * user-space must set this property to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * Setting MODE_ID to 0 will release reserved resources for the CRTC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * drm_crtc_init_with_planes - Initialise a new CRTC object with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * specified primary and cursor planes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * @dev: DRM device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * @crtc: CRTC object to init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * @primary: Primary plane for CRTC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * @cursor: Cursor plane for CRTC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * @funcs: callbacks for the new CRTC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * @name: printf style format string for the CRTC name, or NULL for default name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * Inits a new object created as base part of a driver crtc object. Drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * should use this function instead of drm_crtc_init(), which is only provided
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * for backwards compatibility with drivers which do not yet support universal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * planes). For really simple hardware which has only 1 plane look at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * drm_simple_display_pipe_init() instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * Zero on success, error code on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct drm_plane *primary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct drm_plane *cursor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) const struct drm_crtc_funcs *funcs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) const char *name, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct drm_mode_config *config = &dev->mode_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) WARN_ON(primary && primary->type != DRM_PLANE_TYPE_PRIMARY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) WARN_ON(cursor && cursor->type != DRM_PLANE_TYPE_CURSOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) /* crtc index is used with 32bit bitmasks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (WARN_ON(config->num_crtc >= 32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) (!funcs->atomic_destroy_state ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) !funcs->atomic_duplicate_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) crtc->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) crtc->funcs = funcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) INIT_LIST_HEAD(&crtc->commit_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) spin_lock_init(&crtc->commit_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) drm_modeset_lock_init(&crtc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ret = drm_mode_object_add(dev, &crtc->base, DRM_MODE_OBJECT_CRTC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) va_list ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) va_start(ap, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) crtc->name = kvasprintf(GFP_KERNEL, name, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) va_end(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) crtc->name = kasprintf(GFP_KERNEL, "crtc-%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) drm_num_crtcs(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (!crtc->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) drm_mode_object_unregister(dev, &crtc->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) crtc->fence_context = dma_fence_context_alloc(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) spin_lock_init(&crtc->fence_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) snprintf(crtc->timeline_name, sizeof(crtc->timeline_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) "CRTC:%d-%s", crtc->base.id, crtc->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) crtc->base.properties = &crtc->properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) list_add_tail(&crtc->head, &config->crtc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) crtc->index = config->num_crtc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) crtc->primary = primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) crtc->cursor = cursor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (primary && !primary->possible_crtcs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) primary->possible_crtcs = drm_crtc_mask(crtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (cursor && !cursor->possible_crtcs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) cursor->possible_crtcs = drm_crtc_mask(crtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) ret = drm_crtc_crc_init(crtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) drm_mode_object_unregister(dev, &crtc->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) drm_object_attach_property(&crtc->base, config->prop_active, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) drm_object_attach_property(&crtc->base, config->prop_mode_id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) drm_object_attach_property(&crtc->base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) config->prop_out_fence_ptr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) drm_object_attach_property(&crtc->base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) config->prop_vrr_enabled, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) EXPORT_SYMBOL(drm_crtc_init_with_planes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * drm_crtc_cleanup - Clean up the core crtc usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * @crtc: CRTC to cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * This function cleans up @crtc and removes it from the DRM mode setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * core. Note that the function does *not* free the crtc structure itself,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) * this is the responsibility of the caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) void drm_crtc_cleanup(struct drm_crtc *crtc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct drm_device *dev = crtc->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) /* Note that the crtc_list is considered to be static; should we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * remove the drm_crtc at runtime we would have to decrement all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * the indices on the drm_crtc after us in the crtc_list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) drm_crtc_crc_fini(crtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) kfree(crtc->gamma_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) crtc->gamma_store = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) drm_modeset_lock_fini(&crtc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) drm_mode_object_unregister(dev, &crtc->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) list_del(&crtc->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) dev->mode_config.num_crtc--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) WARN_ON(crtc->state && !crtc->funcs->atomic_destroy_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (crtc->state && crtc->funcs->atomic_destroy_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) crtc->funcs->atomic_destroy_state(crtc, crtc->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) kfree(crtc->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) memset(crtc, 0, sizeof(*crtc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) EXPORT_SYMBOL(drm_crtc_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * drm_mode_getcrtc - get CRTC configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) * @dev: drm device for the ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * @data: data pointer for the ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * @file_priv: drm file for the ioctl call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * Construct a CRTC configuration structure to return to the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * Called by the user via ioctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * Zero on success, negative errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) int drm_mode_getcrtc(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) void *data, struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct drm_mode_crtc *crtc_resp = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) struct drm_crtc *crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct drm_plane *plane;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (!drm_core_check_feature(dev, DRIVER_MODESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) crtc = drm_crtc_find(dev, file_priv, crtc_resp->crtc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (!crtc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) plane = crtc->primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) crtc_resp->gamma_size = crtc->gamma_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) drm_modeset_lock(&plane->mutex, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (plane->state && plane->state->fb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) crtc_resp->fb_id = plane->state->fb->base.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) else if (!plane->state && plane->fb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) crtc_resp->fb_id = plane->fb->base.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) crtc_resp->fb_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (plane->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) crtc_resp->x = plane->state->src_x >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) crtc_resp->y = plane->state->src_y >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) drm_modeset_unlock(&plane->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) drm_modeset_lock(&crtc->mutex, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (crtc->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (crtc->state->enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) crtc_resp->mode_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) crtc_resp->mode_valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) crtc_resp->x = crtc->x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) crtc_resp->y = crtc->y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (crtc->enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) crtc_resp->mode_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) crtc_resp->mode_valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (!file_priv->aspect_ratio_allowed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) crtc_resp->mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) drm_modeset_unlock(&crtc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static int __drm_mode_set_config_internal(struct drm_mode_set *set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct drm_modeset_acquire_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct drm_crtc *crtc = set->crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct drm_framebuffer *fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) struct drm_crtc *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) WARN_ON(drm_drv_uses_atomic_modeset(crtc->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * NOTE: ->set_config can also disable other crtcs (if we steal all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * connectors from it), hence we need to refcount the fbs across all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * crtcs. Atomic modeset will have saner semantics ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) drm_for_each_crtc(tmp, crtc->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct drm_plane *plane = tmp->primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) plane->old_fb = plane->fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) fb = set->fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) ret = crtc->funcs->set_config(set, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct drm_plane *plane = crtc->primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) plane->crtc = fb ? crtc : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) plane->fb = fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) drm_for_each_crtc(tmp, crtc->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) struct drm_plane *plane = tmp->primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) if (plane->fb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) drm_framebuffer_get(plane->fb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (plane->old_fb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) drm_framebuffer_put(plane->old_fb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) plane->old_fb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) * drm_mode_set_config_internal - helper to call &drm_mode_config_funcs.set_config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * @set: modeset config to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * This is a little helper to wrap internal calls to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * &drm_mode_config_funcs.set_config driver interface. The only thing it adds is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * correct refcounting dance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * This should only be used by non-atomic legacy drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * Zero on success, negative errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) int drm_mode_set_config_internal(struct drm_mode_set *set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) WARN_ON(drm_drv_uses_atomic_modeset(set->crtc->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) return __drm_mode_set_config_internal(set, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) EXPORT_SYMBOL(drm_mode_set_config_internal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) * CRTC viewport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * @crtc: CRTC that framebuffer will be displayed on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * @x: x panning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * @y: y panning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * @mode: mode that framebuffer will be displayed under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) * @fb: framebuffer to check size of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) int drm_crtc_check_viewport(const struct drm_crtc *crtc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) int x, int y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) const struct drm_display_mode *mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) const struct drm_framebuffer *fb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) int hdisplay, vdisplay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) drm_mode_get_hv_timing(mode, &hdisplay, &vdisplay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (crtc->state &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) drm_rotation_90_or_270(crtc->primary->state->rotation))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) swap(hdisplay, vdisplay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) return drm_framebuffer_check_src_coords(x << 16, y << 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) hdisplay << 16, vdisplay << 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) fb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) EXPORT_SYMBOL(drm_crtc_check_viewport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * drm_mode_setcrtc - set CRTC configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) * @dev: drm device for the ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) * @data: data pointer for the ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) * @file_priv: drm file for the ioctl call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * Build a new CRTC configuration based on user request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * Called by the user via ioctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * Zero on success, negative errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) int drm_mode_setcrtc(struct drm_device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) struct drm_mode_config *config = &dev->mode_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) struct drm_mode_crtc *crtc_req = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) struct drm_crtc *crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) struct drm_plane *plane;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) struct drm_connector **connector_set = NULL, *connector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct drm_framebuffer *fb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) struct drm_display_mode *mode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct drm_mode_set set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) uint32_t __user *set_connectors_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) struct drm_modeset_acquire_ctx ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (!drm_core_check_feature(dev, DRIVER_MODESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) * Universal plane src offsets are only 16.16, prevent havoc for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * drivers using universal plane code internally.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (crtc_req->x & 0xffff0000 || crtc_req->y & 0xffff0000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) crtc = drm_crtc_find(dev, file_priv, crtc_req->crtc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) if (!crtc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) plane = crtc->primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /* allow disabling with the primary plane leased */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (crtc_req->mode_valid && !drm_lease_held(file_priv, plane->base.id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) DRM_MODESET_ACQUIRE_INTERRUPTIBLE, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (crtc_req->mode_valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) /* If we have a mode we need a framebuffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /* If we pass -1, set the mode with the currently bound fb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (crtc_req->fb_id == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) struct drm_framebuffer *old_fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (plane->state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) old_fb = plane->state->fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) old_fb = plane->fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (!old_fb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) fb = old_fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) /* Make refcounting symmetric with the lookup path. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) drm_framebuffer_get(fb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) fb = drm_framebuffer_lookup(dev, file_priv, crtc_req->fb_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (!fb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) DRM_DEBUG_KMS("Unknown FB ID%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) crtc_req->fb_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) mode = drm_mode_create(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) if (!mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (!file_priv->aspect_ratio_allowed &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) (crtc_req->mode.flags & DRM_MODE_FLAG_PIC_AR_MASK) != DRM_MODE_FLAG_PIC_AR_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) DRM_DEBUG_KMS("Unexpected aspect-ratio flag bits\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) ret = drm_mode_convert_umode(dev, mode, &crtc_req->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) DRM_DEBUG_KMS("Invalid mode (ret=%d, status=%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) ret, drm_get_mode_status_name(mode->status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) drm_mode_debug_printmodeline(mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * Check whether the primary plane supports the fb pixel format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) * Drivers not implementing the universal planes API use a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) * default formats list provided by the DRM core which doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) * match real hardware capabilities. Skip the check in that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) * case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) if (!plane->format_default) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) ret = drm_plane_check_pixel_format(plane,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) fb->format->format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) fb->modifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) struct drm_format_name_buf format_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) DRM_DEBUG_KMS("Invalid pixel format %s, modifier 0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) drm_get_format_name(fb->format->format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) &format_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) fb->modifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) mode, fb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (crtc_req->count_connectors == 0 && mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (crtc_req->count_connectors > 0 && (!mode || !fb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) crtc_req->count_connectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (crtc_req->count_connectors > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) u32 out_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) /* Avoid unbounded kernel memory allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) if (crtc_req->count_connectors > config->num_connector) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) connector_set = kmalloc_array(crtc_req->count_connectors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) sizeof(struct drm_connector *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) if (!connector_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) for (i = 0; i < crtc_req->count_connectors; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) connector_set[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) if (get_user(out_id, &set_connectors_ptr[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) connector = drm_connector_lookup(dev, file_priv, out_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) if (!connector) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) DRM_DEBUG_KMS("Connector id %d unknown\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) out_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) connector->base.id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) connector->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) connector_set[i] = connector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) set.crtc = crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) set.x = crtc_req->x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) set.y = crtc_req->y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) set.mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) set.connectors = connector_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) set.num_connectors = crtc_req->count_connectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) set.fb = fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (drm_drv_uses_atomic_modeset(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) ret = crtc->funcs->set_config(&set, &ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) ret = __drm_mode_set_config_internal(&set, &ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (fb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) drm_framebuffer_put(fb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (connector_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) for (i = 0; i < crtc_req->count_connectors; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) if (connector_set[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) drm_connector_put(connector_set[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) kfree(connector_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) drm_mode_destroy(dev, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) /* In case we need to retry... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) connector_set = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) fb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) mode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) struct drm_property *property,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) uint64_t value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) struct drm_crtc *crtc = obj_to_crtc(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (crtc->funcs->set_property)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) ret = crtc->funcs->set_property(crtc, property, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) drm_object_property_set_value(obj, property, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) }