drm_crtc.c 16.1 KB
Newer Older
D
Dave Airlie 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 * Copyright (c) 2006-2008 Intel Corporation
 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
 * Copyright (c) 2008 Red Hat Inc.
 *
 * DRM core CRTC related functions
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * that the name of the copyright holders not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  The copyright holders make no representations
 * about the suitability of this software for any purpose.  It is provided "as
 * is" without express or implied warranty.
 *
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 * OF THIS SOFTWARE.
 *
 * Authors:
 *      Keith Packard
 *	Eric Anholt <eric@anholt.net>
 *      Dave Airlie <airlied@linux.ie>
 *      Jesse Barnes <jesse.barnes@intel.com>
 */
32
#include <linux/ctype.h>
D
Dave Airlie 已提交
33
#include <linux/list.h>
34
#include <linux/slab.h>
35
#include <linux/export.h>
36 37 38 39
#include <drm/drmP.h>
#include <drm/drm_crtc.h>
#include <drm/drm_edid.h>
#include <drm/drm_fourcc.h>
40
#include <drm/drm_modeset_lock.h>
R
Rob Clark 已提交
41
#include <drm/drm_atomic.h>
D
Daniel Vetter 已提交
42
#include <drm/drm_auth.h>
43
#include <drm/drm_debugfs_crc.h>
D
Dave Airlie 已提交
44

45
#include "drm_crtc_internal.h"
46
#include "drm_internal.h"
47

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
/**
 * drm_crtc_force_disable - Forcibly turn off a CRTC
 * @crtc: CRTC to turn off
 *
 * Returns:
 * Zero on success, error code on failure.
 */
int drm_crtc_force_disable(struct drm_crtc *crtc)
{
	struct drm_mode_set set = {
		.crtc = crtc,
	};

	return drm_mode_set_config_internal(&set);
}
EXPORT_SYMBOL(drm_crtc_force_disable);

/**
 * drm_crtc_force_disable_all - Forcibly turn off all enabled CRTCs
 * @dev: DRM device whose CRTCs to turn off
 *
 * Drivers may want to call this on unload to ensure that all displays are
 * unlit and the GPU is in a consistent, low power state. Takes modeset locks.
 *
 * Returns:
 * Zero on success, error code on failure.
 */
int drm_crtc_force_disable_all(struct drm_device *dev)
{
	struct drm_crtc *crtc;
	int ret = 0;

	drm_modeset_lock_all(dev);
	drm_for_each_crtc(crtc, dev)
		if (crtc->enabled) {
			ret = drm_crtc_force_disable(crtc);
			if (ret)
				goto out;
		}
out:
	drm_modeset_unlock_all(dev);
	return ret;
}
EXPORT_SYMBOL(drm_crtc_force_disable_all);

93 94 95 96 97 98 99 100 101 102 103 104
static unsigned int drm_num_crtcs(struct drm_device *dev)
{
	unsigned int num = 0;
	struct drm_crtc *tmp;

	drm_for_each_crtc(tmp, dev) {
		num++;
	}

	return num;
}

D
Daniel Vetter 已提交
105
int drm_crtc_register_all(struct drm_device *dev)
106 107 108 109 110
{
	struct drm_crtc *crtc;
	int ret = 0;

	drm_for_each_crtc(crtc, dev) {
111 112 113 114
		if (drm_debugfs_crtc_add(crtc))
			DRM_ERROR("Failed to initialize debugfs entry for CRTC '%s'.\n",
				  crtc->name);

115 116 117 118 119 120 121 122 123
		if (crtc->funcs->late_register)
			ret = crtc->funcs->late_register(crtc);
		if (ret)
			return ret;
	}

	return 0;
}

D
Daniel Vetter 已提交
124
void drm_crtc_unregister_all(struct drm_device *dev)
125 126 127 128 129 130
{
	struct drm_crtc *crtc;

	drm_for_each_crtc(crtc, dev) {
		if (crtc->funcs->early_unregister)
			crtc->funcs->early_unregister(crtc);
131
		drm_debugfs_crtc_remove(crtc);
132 133 134
	}
}

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
static int drm_crtc_crc_init(struct drm_crtc *crtc)
{
#ifdef CONFIG_DEBUG_FS
	spin_lock_init(&crtc->crc.lock);
	init_waitqueue_head(&crtc->crc.wq);
	crtc->crc.source = kstrdup("auto", GFP_KERNEL);
	if (!crtc->crc.source)
		return -ENOMEM;
#endif
	return 0;
}

static void drm_crtc_crc_fini(struct drm_crtc *crtc)
{
#ifdef CONFIG_DEBUG_FS
	kfree(crtc->crc.source);
#endif
}

D
Dave Airlie 已提交
154
/**
155 156
 * drm_crtc_init_with_planes - Initialise a new CRTC object with
 *    specified primary and cursor planes.
D
Dave Airlie 已提交
157 158
 * @dev: DRM device
 * @crtc: CRTC object to init
159 160
 * @primary: Primary plane for CRTC
 * @cursor: Cursor plane for CRTC
D
Dave Airlie 已提交
161
 * @funcs: callbacks for the new CRTC
162
 * @name: printf style format string for the CRTC name, or NULL for default name
D
Dave Airlie 已提交
163
 *
164 165 166 167 168
 * Inits a new object created as base part of a driver crtc object. Drivers
 * should use this function instead of drm_crtc_init(), which is only provided
 * for backwards compatibility with drivers which do not yet support universal
 * planes). For really simple hardware which has only 1 plane look at
 * drm_simple_display_pipe_init() instead.
169
 *
170
 * Returns:
171
 * Zero on success, error code on failure.
D
Dave Airlie 已提交
172
 */
173 174
int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
			      struct drm_plane *primary,
175
			      struct drm_plane *cursor,
176 177
			      const struct drm_crtc_funcs *funcs,
			      const char *name, ...)
D
Dave Airlie 已提交
178
{
179
	struct drm_mode_config *config = &dev->mode_config;
180 181
	int ret;

182 183 184
	WARN_ON(primary && primary->type != DRM_PLANE_TYPE_PRIMARY);
	WARN_ON(cursor && cursor->type != DRM_PLANE_TYPE_CURSOR);

D
Dave Airlie 已提交
185 186 187
	crtc->dev = dev;
	crtc->funcs = funcs;

188 189 190
	INIT_LIST_HEAD(&crtc->commit_list);
	spin_lock_init(&crtc->commit_lock);

191
	drm_modeset_lock_init(&crtc->mutex);
192 193
	ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC);
	if (ret)
194
		return ret;
D
Dave Airlie 已提交
195

196 197 198 199 200 201 202 203 204 205 206
	if (name) {
		va_list ap;

		va_start(ap, name);
		crtc->name = kvasprintf(GFP_KERNEL, name, ap);
		va_end(ap);
	} else {
		crtc->name = kasprintf(GFP_KERNEL, "crtc-%d",
				       drm_num_crtcs(dev));
	}
	if (!crtc->name) {
207
		drm_mode_object_unregister(dev, &crtc->base);
208 209 210
		return -ENOMEM;
	}

P
Paulo Zanoni 已提交
211 212
	crtc->base.properties = &crtc->properties;

213
	list_add_tail(&crtc->head, &config->crtc_list);
C
Chris Wilson 已提交
214
	crtc->index = config->num_crtc++;
215

216
	crtc->primary = primary;
217
	crtc->cursor = cursor;
218
	if (primary && !primary->possible_crtcs)
219
		primary->possible_crtcs = 1 << drm_crtc_index(crtc);
220
	if (cursor && !cursor->possible_crtcs)
221
		cursor->possible_crtcs = 1 << drm_crtc_index(crtc);
222

223 224 225 226 227 228
	ret = drm_crtc_crc_init(crtc);
	if (ret) {
		drm_mode_object_unregister(dev, &crtc->base);
		return ret;
	}

229 230
	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
		drm_object_attach_property(&crtc->base, config->prop_active, 0);
D
Daniel Stone 已提交
231
		drm_object_attach_property(&crtc->base, config->prop_mode_id, 0);
232 233
	}

234
	return 0;
D
Dave Airlie 已提交
235
}
236
EXPORT_SYMBOL(drm_crtc_init_with_planes);
D
Dave Airlie 已提交
237 238

/**
239
 * drm_crtc_cleanup - Clean up the core crtc usage
D
Dave Airlie 已提交
240 241
 * @crtc: CRTC to cleanup
 *
242 243 244
 * This function cleans up @crtc and removes it from the DRM mode setting
 * core. Note that the function does *not* free the crtc structure itself,
 * this is the responsibility of the caller.
D
Dave Airlie 已提交
245 246 247 248 249
 */
void drm_crtc_cleanup(struct drm_crtc *crtc)
{
	struct drm_device *dev = crtc->dev;

C
Chris Wilson 已提交
250 251 252 253 254
	/* Note that the crtc_list is considered to be static; should we
	 * remove the drm_crtc at runtime we would have to decrement all
	 * the indices on the drm_crtc after us in the crtc_list.
	 */

255 256
	drm_crtc_crc_fini(crtc);

257 258
	kfree(crtc->gamma_store);
	crtc->gamma_store = NULL;
D
Dave Airlie 已提交
259

260 261
	drm_modeset_lock_fini(&crtc->mutex);

262
	drm_mode_object_unregister(dev, &crtc->base);
D
Dave Airlie 已提交
263 264
	list_del(&crtc->head);
	dev->mode_config.num_crtc--;
265 266 267 268

	WARN_ON(crtc->state && !crtc->funcs->atomic_destroy_state);
	if (crtc->state && crtc->funcs->atomic_destroy_state)
		crtc->funcs->atomic_destroy_state(crtc, crtc->state);
269

270 271
	kfree(crtc->name);

272
	memset(crtc, 0, sizeof(*crtc));
D
Dave Airlie 已提交
273 274 275 276 277
}
EXPORT_SYMBOL(drm_crtc_cleanup);

/**
 * drm_mode_getcrtc - get CRTC configuration
278 279 280
 * @dev: drm device for the ioctl
 * @data: data pointer for the ioctl
 * @file_priv: drm file for the ioctl call
D
Dave Airlie 已提交
281 282 283 284 285
 *
 * Construct a CRTC configuration structure to return to the user.
 *
 * Called by the user via ioctl.
 *
286
 * Returns:
D
Daniel Vetter 已提交
287
 * Zero on success, negative errno on failure.
D
Dave Airlie 已提交
288 289 290 291 292 293 294
 */
int drm_mode_getcrtc(struct drm_device *dev,
		     void *data, struct drm_file *file_priv)
{
	struct drm_mode_crtc *crtc_resp = data;
	struct drm_crtc *crtc;

295 296 297
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
		return -EINVAL;

R
Rob Clark 已提交
298
	crtc = drm_crtc_find(dev, crtc_resp->crtc_id);
299 300
	if (!crtc)
		return -ENOENT;
D
Dave Airlie 已提交
301

302
	drm_modeset_lock_crtc(crtc, crtc->primary);
D
Dave Airlie 已提交
303
	crtc_resp->gamma_size = crtc->gamma_size;
304 305
	if (crtc->primary->fb)
		crtc_resp->fb_id = crtc->primary->fb->base.id;
D
Dave Airlie 已提交
306 307 308
	else
		crtc_resp->fb_id = 0;

309 310 311 312
	if (crtc->state) {
		crtc_resp->x = crtc->primary->state->src_x >> 16;
		crtc_resp->y = crtc->primary->state->src_y >> 16;
		if (crtc->state->enable) {
313
			drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode);
314
			crtc_resp->mode_valid = 1;
D
Dave Airlie 已提交
315

316 317 318
		} else {
			crtc_resp->mode_valid = 0;
		}
D
Dave Airlie 已提交
319
	} else {
320 321 322
		crtc_resp->x = crtc->x;
		crtc_resp->y = crtc->y;
		if (crtc->enabled) {
323
			drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode);
324 325 326 327 328
			crtc_resp->mode_valid = 1;

		} else {
			crtc_resp->mode_valid = 0;
		}
D
Dave Airlie 已提交
329
	}
330
	drm_modeset_unlock_crtc(crtc);
D
Dave Airlie 已提交
331

332
	return 0;
D
Dave Airlie 已提交
333 334
}

335 336 337 338 339 340
/**
 * drm_mode_set_config_internal - helper to call ->set_config
 * @set: modeset config to set
 *
 * This is a little helper to wrap internal calls to the ->set_config driver
 * interface. The only thing it adds is correct refcounting dance.
341
 *
342
 * Returns:
D
Daniel Vetter 已提交
343
 * Zero on success, negative errno on failure.
344 345 346 347
 */
int drm_mode_set_config_internal(struct drm_mode_set *set)
{
	struct drm_crtc *crtc = set->crtc;
D
Daniel Vetter 已提交
348 349
	struct drm_framebuffer *fb;
	struct drm_crtc *tmp;
350 351
	int ret;

D
Daniel Vetter 已提交
352 353 354 355 356
	/*
	 * NOTE: ->set_config can also disable other crtcs (if we steal all
	 * connectors from it), hence we need to refcount the fbs across all
	 * crtcs. Atomic modeset will have saner semantics ...
	 */
357
	drm_for_each_crtc(tmp, crtc->dev)
358
		tmp->primary->old_fb = tmp->primary->fb;
D
Daniel Vetter 已提交
359

360
	fb = set->fb;
361

362 363
	ret = crtc->funcs->set_config(set);
	if (ret == 0) {
364
		crtc->primary->crtc = crtc;
365
		crtc->primary->fb = fb;
D
Daniel Vetter 已提交
366
	}
367

368
	drm_for_each_crtc(tmp, crtc->dev) {
369 370
		if (tmp->primary->fb)
			drm_framebuffer_reference(tmp->primary->fb);
371 372 373
		if (tmp->primary->old_fb)
			drm_framebuffer_unreference(tmp->primary->old_fb);
		tmp->primary->old_fb = NULL;
374 375 376
	}

	return ret;
377 378 379
}
EXPORT_SYMBOL(drm_mode_set_config_internal);

380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
/**
 * drm_crtc_get_hv_timing - Fetches hdisplay/vdisplay for given mode
 * @mode: mode to query
 * @hdisplay: hdisplay value to fill in
 * @vdisplay: vdisplay value to fill in
 *
 * The vdisplay value will be doubled if the specified mode is a stereo mode of
 * the appropriate layout.
 */
void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
			    int *hdisplay, int *vdisplay)
{
	struct drm_display_mode adjusted;

	drm_mode_copy(&adjusted, mode);
	drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE_ONLY);
	*hdisplay = adjusted.crtc_hdisplay;
	*vdisplay = adjusted.crtc_vdisplay;
}
EXPORT_SYMBOL(drm_crtc_get_hv_timing);

401 402 403 404 405 406 407 408
/**
 * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the
 *     CRTC viewport
 * @crtc: CRTC that framebuffer will be displayed on
 * @x: x panning
 * @y: y panning
 * @mode: mode that framebuffer will be displayed under
 * @fb: framebuffer to check size of
409
 */
410 411 412 413
int drm_crtc_check_viewport(const struct drm_crtc *crtc,
			    int x, int y,
			    const struct drm_display_mode *mode,
			    const struct drm_framebuffer *fb)
414 415 416 417

{
	int hdisplay, vdisplay;

418
	drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay);
419

420
	if (crtc->state &&
421
	    drm_rotation_90_or_270(crtc->primary->state->rotation))
422 423
		swap(hdisplay, vdisplay);

D
Daniel Vetter 已提交
424 425 426
	return drm_framebuffer_check_src_coords(x << 16, y << 16,
						hdisplay << 16, vdisplay << 16,
						fb);
427
}
428
EXPORT_SYMBOL(drm_crtc_check_viewport);
429

D
Dave Airlie 已提交
430 431
/**
 * drm_mode_setcrtc - set CRTC configuration
432 433 434
 * @dev: drm device for the ioctl
 * @data: data pointer for the ioctl
 * @file_priv: drm file for the ioctl call
D
Dave Airlie 已提交
435 436 437 438 439
 *
 * Build a new CRTC configuration based on user request.
 *
 * Called by the user via ioctl.
 *
440
 * Returns:
D
Daniel Vetter 已提交
441
 * Zero on success, negative errno on failure.
D
Dave Airlie 已提交
442 443 444 445 446 447
 */
int drm_mode_setcrtc(struct drm_device *dev, void *data,
		     struct drm_file *file_priv)
{
	struct drm_mode_config *config = &dev->mode_config;
	struct drm_mode_crtc *crtc_req = data;
448
	struct drm_crtc *crtc;
D
Dave Airlie 已提交
449 450 451 452 453
	struct drm_connector **connector_set = NULL, *connector;
	struct drm_framebuffer *fb = NULL;
	struct drm_display_mode *mode = NULL;
	struct drm_mode_set set;
	uint32_t __user *set_connectors_ptr;
454
	int ret;
D
Dave Airlie 已提交
455 456
	int i;

457 458 459
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
		return -EINVAL;

460 461 462 463 464
	/*
	 * Universal plane src offsets are only 16.16, prevent havoc for
	 * drivers using universal plane code internally.
	 */
	if (crtc_req->x & 0xffff0000 || crtc_req->y & 0xffff0000)
465 466
		return -ERANGE;

467
	drm_modeset_lock_all(dev);
R
Rob Clark 已提交
468 469
	crtc = drm_crtc_find(dev, crtc_req->crtc_id);
	if (!crtc) {
470
		DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
471
		ret = -ENOENT;
D
Dave Airlie 已提交
472 473
		goto out;
	}
474
	DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
D
Dave Airlie 已提交
475 476 477 478 479

	if (crtc_req->mode_valid) {
		/* If we have a mode we need a framebuffer. */
		/* If we pass -1, set the mode with the currently bound fb */
		if (crtc_req->fb_id == -1) {
480
			if (!crtc->primary->fb) {
481 482 483
				DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
				ret = -EINVAL;
				goto out;
D
Dave Airlie 已提交
484
			}
485
			fb = crtc->primary->fb;
486 487
			/* Make refcounting symmetric with the lookup path. */
			drm_framebuffer_reference(fb);
D
Dave Airlie 已提交
488
		} else {
489 490
			fb = drm_framebuffer_lookup(dev, crtc_req->fb_id);
			if (!fb) {
491 492
				DRM_DEBUG_KMS("Unknown FB ID%d\n",
						crtc_req->fb_id);
493
				ret = -ENOENT;
D
Dave Airlie 已提交
494 495 496 497 498
				goto out;
			}
		}

		mode = drm_mode_create(dev);
499 500 501 502 503
		if (!mode) {
			ret = -ENOMEM;
			goto out;
		}

504
		ret = drm_mode_convert_umode(mode, &crtc_req->mode);
505 506 507 508 509
		if (ret) {
			DRM_DEBUG_KMS("Invalid mode\n");
			goto out;
		}

510 511 512 513 514 515 516 517 518 519 520
		/*
		 * Check whether the primary plane supports the fb pixel format.
		 * Drivers not implementing the universal planes API use a
		 * default formats list provided by the DRM core which doesn't
		 * match real hardware capabilities. Skip the check in that
		 * case.
		 */
		if (!crtc->primary->format_default) {
			ret = drm_plane_check_pixel_format(crtc->primary,
							   fb->pixel_format);
			if (ret) {
521 522 523 524
				struct drm_format_name_buf format_name;
				DRM_DEBUG_KMS("Invalid pixel format %s\n",
				              drm_get_format_name(fb->pixel_format,
				                                  &format_name));
525 526 527 528
				goto out;
			}
		}

529 530 531
		ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y,
					      mode, fb);
		if (ret)
532
			goto out;
533

D
Dave Airlie 已提交
534 535 536
	}

	if (crtc_req->count_connectors == 0 && mode) {
537
		DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
D
Dave Airlie 已提交
538 539 540 541
		ret = -EINVAL;
		goto out;
	}

542
	if (crtc_req->count_connectors > 0 && (!mode || !fb)) {
543
		DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
D
Dave Airlie 已提交
544 545 546 547 548 549 550 551 552 553 554 555 556 557
			  crtc_req->count_connectors);
		ret = -EINVAL;
		goto out;
	}

	if (crtc_req->count_connectors > 0) {
		u32 out_id;

		/* Avoid unbounded kernel memory allocation */
		if (crtc_req->count_connectors > config->num_connector) {
			ret = -EINVAL;
			goto out;
		}

558 559 560
		connector_set = kmalloc_array(crtc_req->count_connectors,
					      sizeof(struct drm_connector *),
					      GFP_KERNEL);
D
Dave Airlie 已提交
561 562 563 564 565 566
		if (!connector_set) {
			ret = -ENOMEM;
			goto out;
		}

		for (i = 0; i < crtc_req->count_connectors; i++) {
567
			connector_set[i] = NULL;
V
Ville Syrjälä 已提交
568
			set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
D
Dave Airlie 已提交
569 570 571 572 573
			if (get_user(out_id, &set_connectors_ptr[i])) {
				ret = -EFAULT;
				goto out;
			}

574
			connector = drm_connector_lookup(dev, out_id);
R
Rob Clark 已提交
575
			if (!connector) {
576 577
				DRM_DEBUG_KMS("Connector id %d unknown\n",
						out_id);
578
				ret = -ENOENT;
D
Dave Airlie 已提交
579 580
				goto out;
			}
581 582
			DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
					connector->base.id,
583
					connector->name);
D
Dave Airlie 已提交
584 585 586 587 588 589 590 591 592 593 594

			connector_set[i] = connector;
		}
	}

	set.crtc = crtc;
	set.x = crtc_req->x;
	set.y = crtc_req->y;
	set.mode = mode;
	set.connectors = connector_set;
	set.num_connectors = crtc_req->count_connectors;
595
	set.fb = fb;
596
	ret = drm_mode_set_config_internal(&set);
D
Dave Airlie 已提交
597 598

out:
599 600 601
	if (fb)
		drm_framebuffer_unreference(fb);

602 603 604 605 606 607
	if (connector_set) {
		for (i = 0; i < crtc_req->count_connectors; i++) {
			if (connector_set[i])
				drm_connector_unreference(connector_set[i]);
		}
	}
D
Dave Airlie 已提交
608
	kfree(connector_set);
609
	drm_mode_destroy(dev, mode);
610
	drm_modeset_unlock_all(dev);
D
Dave Airlie 已提交
611 612 613
	return ret;
}

614 615 616
int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj,
			       struct drm_property *property,
			       uint64_t value)
617
{
P
Paulo Zanoni 已提交
618 619
	int ret = -EINVAL;
	struct drm_crtc *crtc = obj_to_crtc(obj);
620

P
Paulo Zanoni 已提交
621 622 623 624
	if (crtc->funcs->set_property)
		ret = crtc->funcs->set_property(crtc, property, value);
	if (!ret)
		drm_object_property_set_value(obj, property, value);
625

P
Paulo Zanoni 已提交
626
	return ret;
627
}