drm_crtc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /*
  2. * Copyright (c) 2006-2008 Intel Corporation
  3. * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
  4. * Copyright (c) 2008 Red Hat Inc.
  5. *
  6. * DRM core CRTC related functions
  7. *
  8. * Permission to use, copy, modify, distribute, and sell this software and its
  9. * documentation for any purpose is hereby granted without fee, provided that
  10. * the above copyright notice appear in all copies and that both that copyright
  11. * notice and this permission notice appear in supporting documentation, and
  12. * that the name of the copyright holders not be used in advertising or
  13. * publicity pertaining to distribution of the software without specific,
  14. * written prior permission. The copyright holders make no representations
  15. * about the suitability of this software for any purpose. It is provided "as
  16. * is" without express or implied warranty.
  17. *
  18. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  19. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  20. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  22. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  23. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  24. * OF THIS SOFTWARE.
  25. *
  26. * Authors:
  27. * Keith Packard
  28. * Eric Anholt <eric@anholt.net>
  29. * Dave Airlie <airlied@linux.ie>
  30. * Jesse Barnes <jesse.barnes@intel.com>
  31. */
  32. #include <linux/ctype.h>
  33. #include <linux/list.h>
  34. #include <linux/slab.h>
  35. #include <linux/export.h>
  36. #include <linux/dma-fence.h>
  37. #include <drm/drmP.h>
  38. #include <drm/drm_crtc.h>
  39. #include <drm/drm_edid.h>
  40. #include <drm/drm_fourcc.h>
  41. #include <drm/drm_modeset_lock.h>
  42. #include <drm/drm_atomic.h>
  43. #include <drm/drm_auth.h>
  44. #include <drm/drm_debugfs_crc.h>
  45. #include "drm_crtc_internal.h"
  46. #include "drm_internal.h"
  47. /**
  48. * drm_crtc_force_disable - Forcibly turn off a CRTC
  49. * @crtc: CRTC to turn off
  50. *
  51. * Returns:
  52. * Zero on success, error code on failure.
  53. */
  54. int drm_crtc_force_disable(struct drm_crtc *crtc)
  55. {
  56. struct drm_mode_set set = {
  57. .crtc = crtc,
  58. };
  59. return drm_mode_set_config_internal(&set);
  60. }
  61. EXPORT_SYMBOL(drm_crtc_force_disable);
  62. /**
  63. * drm_crtc_force_disable_all - Forcibly turn off all enabled CRTCs
  64. * @dev: DRM device whose CRTCs to turn off
  65. *
  66. * Drivers may want to call this on unload to ensure that all displays are
  67. * unlit and the GPU is in a consistent, low power state. Takes modeset locks.
  68. *
  69. * Returns:
  70. * Zero on success, error code on failure.
  71. */
  72. int drm_crtc_force_disable_all(struct drm_device *dev)
  73. {
  74. struct drm_crtc *crtc;
  75. int ret = 0;
  76. drm_modeset_lock_all(dev);
  77. drm_for_each_crtc(crtc, dev)
  78. if (crtc->enabled) {
  79. ret = drm_crtc_force_disable(crtc);
  80. if (ret)
  81. goto out;
  82. }
  83. out:
  84. drm_modeset_unlock_all(dev);
  85. return ret;
  86. }
  87. EXPORT_SYMBOL(drm_crtc_force_disable_all);
  88. static unsigned int drm_num_crtcs(struct drm_device *dev)
  89. {
  90. unsigned int num = 0;
  91. struct drm_crtc *tmp;
  92. drm_for_each_crtc(tmp, dev) {
  93. num++;
  94. }
  95. return num;
  96. }
  97. int drm_crtc_register_all(struct drm_device *dev)
  98. {
  99. struct drm_crtc *crtc;
  100. int ret = 0;
  101. drm_for_each_crtc(crtc, dev) {
  102. if (drm_debugfs_crtc_add(crtc))
  103. DRM_ERROR("Failed to initialize debugfs entry for CRTC '%s'.\n",
  104. crtc->name);
  105. if (crtc->funcs->late_register)
  106. ret = crtc->funcs->late_register(crtc);
  107. if (ret)
  108. return ret;
  109. }
  110. return 0;
  111. }
  112. void drm_crtc_unregister_all(struct drm_device *dev)
  113. {
  114. struct drm_crtc *crtc;
  115. drm_for_each_crtc(crtc, dev) {
  116. if (crtc->funcs->early_unregister)
  117. crtc->funcs->early_unregister(crtc);
  118. drm_debugfs_crtc_remove(crtc);
  119. }
  120. }
  121. static int drm_crtc_crc_init(struct drm_crtc *crtc)
  122. {
  123. #ifdef CONFIG_DEBUG_FS
  124. spin_lock_init(&crtc->crc.lock);
  125. init_waitqueue_head(&crtc->crc.wq);
  126. crtc->crc.source = kstrdup("auto", GFP_KERNEL);
  127. if (!crtc->crc.source)
  128. return -ENOMEM;
  129. #endif
  130. return 0;
  131. }
  132. static void drm_crtc_crc_fini(struct drm_crtc *crtc)
  133. {
  134. #ifdef CONFIG_DEBUG_FS
  135. kfree(crtc->crc.source);
  136. #endif
  137. }
  138. static const struct dma_fence_ops drm_crtc_fence_ops;
  139. static struct drm_crtc *fence_to_crtc(struct dma_fence *fence)
  140. {
  141. BUG_ON(fence->ops != &drm_crtc_fence_ops);
  142. return container_of(fence->lock, struct drm_crtc, fence_lock);
  143. }
  144. static const char *drm_crtc_fence_get_driver_name(struct dma_fence *fence)
  145. {
  146. struct drm_crtc *crtc = fence_to_crtc(fence);
  147. return crtc->dev->driver->name;
  148. }
  149. static const char *drm_crtc_fence_get_timeline_name(struct dma_fence *fence)
  150. {
  151. struct drm_crtc *crtc = fence_to_crtc(fence);
  152. return crtc->timeline_name;
  153. }
  154. static bool drm_crtc_fence_enable_signaling(struct dma_fence *fence)
  155. {
  156. return true;
  157. }
  158. static const struct dma_fence_ops drm_crtc_fence_ops = {
  159. .get_driver_name = drm_crtc_fence_get_driver_name,
  160. .get_timeline_name = drm_crtc_fence_get_timeline_name,
  161. .enable_signaling = drm_crtc_fence_enable_signaling,
  162. .wait = dma_fence_default_wait,
  163. };
  164. struct dma_fence *drm_crtc_create_fence(struct drm_crtc *crtc)
  165. {
  166. struct dma_fence *fence;
  167. fence = kzalloc(sizeof(*fence), GFP_KERNEL);
  168. if (!fence)
  169. return NULL;
  170. dma_fence_init(fence, &drm_crtc_fence_ops, &crtc->fence_lock,
  171. crtc->fence_context, ++crtc->fence_seqno);
  172. return fence;
  173. }
  174. /**
  175. * drm_crtc_init_with_planes - Initialise a new CRTC object with
  176. * specified primary and cursor planes.
  177. * @dev: DRM device
  178. * @crtc: CRTC object to init
  179. * @primary: Primary plane for CRTC
  180. * @cursor: Cursor plane for CRTC
  181. * @funcs: callbacks for the new CRTC
  182. * @name: printf style format string for the CRTC name, or NULL for default name
  183. *
  184. * Inits a new object created as base part of a driver crtc object. Drivers
  185. * should use this function instead of drm_crtc_init(), which is only provided
  186. * for backwards compatibility with drivers which do not yet support universal
  187. * planes). For really simple hardware which has only 1 plane look at
  188. * drm_simple_display_pipe_init() instead.
  189. *
  190. * Returns:
  191. * Zero on success, error code on failure.
  192. */
  193. int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
  194. struct drm_plane *primary,
  195. struct drm_plane *cursor,
  196. const struct drm_crtc_funcs *funcs,
  197. const char *name, ...)
  198. {
  199. struct drm_mode_config *config = &dev->mode_config;
  200. int ret;
  201. WARN_ON(primary && primary->type != DRM_PLANE_TYPE_PRIMARY);
  202. WARN_ON(cursor && cursor->type != DRM_PLANE_TYPE_CURSOR);
  203. crtc->dev = dev;
  204. crtc->funcs = funcs;
  205. INIT_LIST_HEAD(&crtc->commit_list);
  206. spin_lock_init(&crtc->commit_lock);
  207. drm_modeset_lock_init(&crtc->mutex);
  208. ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC);
  209. if (ret)
  210. return ret;
  211. if (name) {
  212. va_list ap;
  213. va_start(ap, name);
  214. crtc->name = kvasprintf(GFP_KERNEL, name, ap);
  215. va_end(ap);
  216. } else {
  217. crtc->name = kasprintf(GFP_KERNEL, "crtc-%d",
  218. drm_num_crtcs(dev));
  219. }
  220. if (!crtc->name) {
  221. drm_mode_object_unregister(dev, &crtc->base);
  222. return -ENOMEM;
  223. }
  224. crtc->fence_context = dma_fence_context_alloc(1);
  225. spin_lock_init(&crtc->fence_lock);
  226. snprintf(crtc->timeline_name, sizeof(crtc->timeline_name),
  227. "CRTC:%d-%s", crtc->base.id, crtc->name);
  228. crtc->base.properties = &crtc->properties;
  229. list_add_tail(&crtc->head, &config->crtc_list);
  230. crtc->index = config->num_crtc++;
  231. crtc->primary = primary;
  232. crtc->cursor = cursor;
  233. if (primary && !primary->possible_crtcs)
  234. primary->possible_crtcs = 1 << drm_crtc_index(crtc);
  235. if (cursor && !cursor->possible_crtcs)
  236. cursor->possible_crtcs = 1 << drm_crtc_index(crtc);
  237. ret = drm_crtc_crc_init(crtc);
  238. if (ret) {
  239. drm_mode_object_unregister(dev, &crtc->base);
  240. return ret;
  241. }
  242. if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
  243. drm_object_attach_property(&crtc->base, config->prop_active, 0);
  244. drm_object_attach_property(&crtc->base, config->prop_mode_id, 0);
  245. drm_object_attach_property(&crtc->base,
  246. config->prop_out_fence_ptr, 0);
  247. }
  248. return 0;
  249. }
  250. EXPORT_SYMBOL(drm_crtc_init_with_planes);
  251. /**
  252. * drm_crtc_cleanup - Clean up the core crtc usage
  253. * @crtc: CRTC to cleanup
  254. *
  255. * This function cleans up @crtc and removes it from the DRM mode setting
  256. * core. Note that the function does *not* free the crtc structure itself,
  257. * this is the responsibility of the caller.
  258. */
  259. void drm_crtc_cleanup(struct drm_crtc *crtc)
  260. {
  261. struct drm_device *dev = crtc->dev;
  262. /* Note that the crtc_list is considered to be static; should we
  263. * remove the drm_crtc at runtime we would have to decrement all
  264. * the indices on the drm_crtc after us in the crtc_list.
  265. */
  266. drm_crtc_crc_fini(crtc);
  267. kfree(crtc->gamma_store);
  268. crtc->gamma_store = NULL;
  269. drm_modeset_lock_fini(&crtc->mutex);
  270. drm_mode_object_unregister(dev, &crtc->base);
  271. list_del(&crtc->head);
  272. dev->mode_config.num_crtc--;
  273. WARN_ON(crtc->state && !crtc->funcs->atomic_destroy_state);
  274. if (crtc->state && crtc->funcs->atomic_destroy_state)
  275. crtc->funcs->atomic_destroy_state(crtc, crtc->state);
  276. kfree(crtc->name);
  277. memset(crtc, 0, sizeof(*crtc));
  278. }
  279. EXPORT_SYMBOL(drm_crtc_cleanup);
  280. /**
  281. * drm_mode_getcrtc - get CRTC configuration
  282. * @dev: drm device for the ioctl
  283. * @data: data pointer for the ioctl
  284. * @file_priv: drm file for the ioctl call
  285. *
  286. * Construct a CRTC configuration structure to return to the user.
  287. *
  288. * Called by the user via ioctl.
  289. *
  290. * Returns:
  291. * Zero on success, negative errno on failure.
  292. */
  293. int drm_mode_getcrtc(struct drm_device *dev,
  294. void *data, struct drm_file *file_priv)
  295. {
  296. struct drm_mode_crtc *crtc_resp = data;
  297. struct drm_crtc *crtc;
  298. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  299. return -EINVAL;
  300. crtc = drm_crtc_find(dev, crtc_resp->crtc_id);
  301. if (!crtc)
  302. return -ENOENT;
  303. drm_modeset_lock_crtc(crtc, crtc->primary);
  304. crtc_resp->gamma_size = crtc->gamma_size;
  305. if (crtc->primary->fb)
  306. crtc_resp->fb_id = crtc->primary->fb->base.id;
  307. else
  308. crtc_resp->fb_id = 0;
  309. if (crtc->state) {
  310. crtc_resp->x = crtc->primary->state->src_x >> 16;
  311. crtc_resp->y = crtc->primary->state->src_y >> 16;
  312. if (crtc->state->enable) {
  313. drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode);
  314. crtc_resp->mode_valid = 1;
  315. } else {
  316. crtc_resp->mode_valid = 0;
  317. }
  318. } else {
  319. crtc_resp->x = crtc->x;
  320. crtc_resp->y = crtc->y;
  321. if (crtc->enabled) {
  322. drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode);
  323. crtc_resp->mode_valid = 1;
  324. } else {
  325. crtc_resp->mode_valid = 0;
  326. }
  327. }
  328. drm_modeset_unlock_crtc(crtc);
  329. return 0;
  330. }
  331. /**
  332. * drm_mode_set_config_internal - helper to call ->set_config
  333. * @set: modeset config to set
  334. *
  335. * This is a little helper to wrap internal calls to the ->set_config driver
  336. * interface. The only thing it adds is correct refcounting dance.
  337. *
  338. * Returns:
  339. * Zero on success, negative errno on failure.
  340. */
  341. int drm_mode_set_config_internal(struct drm_mode_set *set)
  342. {
  343. struct drm_crtc *crtc = set->crtc;
  344. struct drm_framebuffer *fb;
  345. struct drm_crtc *tmp;
  346. int ret;
  347. /*
  348. * NOTE: ->set_config can also disable other crtcs (if we steal all
  349. * connectors from it), hence we need to refcount the fbs across all
  350. * crtcs. Atomic modeset will have saner semantics ...
  351. */
  352. drm_for_each_crtc(tmp, crtc->dev)
  353. tmp->primary->old_fb = tmp->primary->fb;
  354. fb = set->fb;
  355. ret = crtc->funcs->set_config(set);
  356. if (ret == 0) {
  357. crtc->primary->crtc = crtc;
  358. crtc->primary->fb = fb;
  359. }
  360. drm_for_each_crtc(tmp, crtc->dev) {
  361. if (tmp->primary->fb)
  362. drm_framebuffer_reference(tmp->primary->fb);
  363. if (tmp->primary->old_fb)
  364. drm_framebuffer_unreference(tmp->primary->old_fb);
  365. tmp->primary->old_fb = NULL;
  366. }
  367. return ret;
  368. }
  369. EXPORT_SYMBOL(drm_mode_set_config_internal);
  370. /**
  371. * drm_crtc_get_hv_timing - Fetches hdisplay/vdisplay for given mode
  372. * @mode: mode to query
  373. * @hdisplay: hdisplay value to fill in
  374. * @vdisplay: vdisplay value to fill in
  375. *
  376. * The vdisplay value will be doubled if the specified mode is a stereo mode of
  377. * the appropriate layout.
  378. */
  379. void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
  380. int *hdisplay, int *vdisplay)
  381. {
  382. struct drm_display_mode adjusted;
  383. drm_mode_copy(&adjusted, mode);
  384. drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE_ONLY);
  385. *hdisplay = adjusted.crtc_hdisplay;
  386. *vdisplay = adjusted.crtc_vdisplay;
  387. }
  388. EXPORT_SYMBOL(drm_crtc_get_hv_timing);
  389. /**
  390. * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the
  391. * CRTC viewport
  392. * @crtc: CRTC that framebuffer will be displayed on
  393. * @x: x panning
  394. * @y: y panning
  395. * @mode: mode that framebuffer will be displayed under
  396. * @fb: framebuffer to check size of
  397. */
  398. int drm_crtc_check_viewport(const struct drm_crtc *crtc,
  399. int x, int y,
  400. const struct drm_display_mode *mode,
  401. const struct drm_framebuffer *fb)
  402. {
  403. int hdisplay, vdisplay;
  404. drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay);
  405. if (crtc->state &&
  406. drm_rotation_90_or_270(crtc->primary->state->rotation))
  407. swap(hdisplay, vdisplay);
  408. return drm_framebuffer_check_src_coords(x << 16, y << 16,
  409. hdisplay << 16, vdisplay << 16,
  410. fb);
  411. }
  412. EXPORT_SYMBOL(drm_crtc_check_viewport);
  413. /**
  414. * drm_mode_setcrtc - set CRTC configuration
  415. * @dev: drm device for the ioctl
  416. * @data: data pointer for the ioctl
  417. * @file_priv: drm file for the ioctl call
  418. *
  419. * Build a new CRTC configuration based on user request.
  420. *
  421. * Called by the user via ioctl.
  422. *
  423. * Returns:
  424. * Zero on success, negative errno on failure.
  425. */
  426. int drm_mode_setcrtc(struct drm_device *dev, void *data,
  427. struct drm_file *file_priv)
  428. {
  429. struct drm_mode_config *config = &dev->mode_config;
  430. struct drm_mode_crtc *crtc_req = data;
  431. struct drm_crtc *crtc;
  432. struct drm_connector **connector_set = NULL, *connector;
  433. struct drm_framebuffer *fb = NULL;
  434. struct drm_display_mode *mode = NULL;
  435. struct drm_mode_set set;
  436. uint32_t __user *set_connectors_ptr;
  437. int ret;
  438. int i;
  439. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  440. return -EINVAL;
  441. /*
  442. * Universal plane src offsets are only 16.16, prevent havoc for
  443. * drivers using universal plane code internally.
  444. */
  445. if (crtc_req->x & 0xffff0000 || crtc_req->y & 0xffff0000)
  446. return -ERANGE;
  447. drm_modeset_lock_all(dev);
  448. crtc = drm_crtc_find(dev, crtc_req->crtc_id);
  449. if (!crtc) {
  450. DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
  451. ret = -ENOENT;
  452. goto out;
  453. }
  454. DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
  455. if (crtc_req->mode_valid) {
  456. /* If we have a mode we need a framebuffer. */
  457. /* If we pass -1, set the mode with the currently bound fb */
  458. if (crtc_req->fb_id == -1) {
  459. if (!crtc->primary->fb) {
  460. DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
  461. ret = -EINVAL;
  462. goto out;
  463. }
  464. fb = crtc->primary->fb;
  465. /* Make refcounting symmetric with the lookup path. */
  466. drm_framebuffer_reference(fb);
  467. } else {
  468. fb = drm_framebuffer_lookup(dev, crtc_req->fb_id);
  469. if (!fb) {
  470. DRM_DEBUG_KMS("Unknown FB ID%d\n",
  471. crtc_req->fb_id);
  472. ret = -ENOENT;
  473. goto out;
  474. }
  475. }
  476. mode = drm_mode_create(dev);
  477. if (!mode) {
  478. ret = -ENOMEM;
  479. goto out;
  480. }
  481. ret = drm_mode_convert_umode(mode, &crtc_req->mode);
  482. if (ret) {
  483. DRM_DEBUG_KMS("Invalid mode\n");
  484. goto out;
  485. }
  486. /*
  487. * Check whether the primary plane supports the fb pixel format.
  488. * Drivers not implementing the universal planes API use a
  489. * default formats list provided by the DRM core which doesn't
  490. * match real hardware capabilities. Skip the check in that
  491. * case.
  492. */
  493. if (!crtc->primary->format_default) {
  494. ret = drm_plane_check_pixel_format(crtc->primary,
  495. fb->pixel_format);
  496. if (ret) {
  497. struct drm_format_name_buf format_name;
  498. DRM_DEBUG_KMS("Invalid pixel format %s\n",
  499. drm_get_format_name(fb->pixel_format,
  500. &format_name));
  501. goto out;
  502. }
  503. }
  504. ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y,
  505. mode, fb);
  506. if (ret)
  507. goto out;
  508. }
  509. if (crtc_req->count_connectors == 0 && mode) {
  510. DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
  511. ret = -EINVAL;
  512. goto out;
  513. }
  514. if (crtc_req->count_connectors > 0 && (!mode || !fb)) {
  515. DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
  516. crtc_req->count_connectors);
  517. ret = -EINVAL;
  518. goto out;
  519. }
  520. if (crtc_req->count_connectors > 0) {
  521. u32 out_id;
  522. /* Avoid unbounded kernel memory allocation */
  523. if (crtc_req->count_connectors > config->num_connector) {
  524. ret = -EINVAL;
  525. goto out;
  526. }
  527. connector_set = kmalloc_array(crtc_req->count_connectors,
  528. sizeof(struct drm_connector *),
  529. GFP_KERNEL);
  530. if (!connector_set) {
  531. ret = -ENOMEM;
  532. goto out;
  533. }
  534. for (i = 0; i < crtc_req->count_connectors; i++) {
  535. connector_set[i] = NULL;
  536. set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
  537. if (get_user(out_id, &set_connectors_ptr[i])) {
  538. ret = -EFAULT;
  539. goto out;
  540. }
  541. connector = drm_connector_lookup(dev, out_id);
  542. if (!connector) {
  543. DRM_DEBUG_KMS("Connector id %d unknown\n",
  544. out_id);
  545. ret = -ENOENT;
  546. goto out;
  547. }
  548. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  549. connector->base.id,
  550. connector->name);
  551. connector_set[i] = connector;
  552. }
  553. }
  554. set.crtc = crtc;
  555. set.x = crtc_req->x;
  556. set.y = crtc_req->y;
  557. set.mode = mode;
  558. set.connectors = connector_set;
  559. set.num_connectors = crtc_req->count_connectors;
  560. set.fb = fb;
  561. ret = drm_mode_set_config_internal(&set);
  562. out:
  563. if (fb)
  564. drm_framebuffer_unreference(fb);
  565. if (connector_set) {
  566. for (i = 0; i < crtc_req->count_connectors; i++) {
  567. if (connector_set[i])
  568. drm_connector_unreference(connector_set[i]);
  569. }
  570. }
  571. kfree(connector_set);
  572. drm_mode_destroy(dev, mode);
  573. drm_modeset_unlock_all(dev);
  574. return ret;
  575. }
  576. int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj,
  577. struct drm_property *property,
  578. uint64_t value)
  579. {
  580. int ret = -EINVAL;
  581. struct drm_crtc *crtc = obj_to_crtc(obj);
  582. if (crtc->funcs->set_property)
  583. ret = crtc->funcs->set_property(crtc, property, value);
  584. if (!ret)
  585. drm_object_property_set_value(obj, property, value);
  586. return ret;
  587. }