2 * Copyright (c) 2006-2008 Intel Corporation
3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
4 * Copyright (c) 2008 Red Hat Inc.
6 * DRM core CRTC related functions
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.
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
28 * Eric Anholt <eric@anholt.net>
29 * Dave Airlie <airlied@linux.ie>
30 * Jesse Barnes <jesse.barnes@intel.com>
32 #include <linux/list.h>
33 #include <linux/slab.h>
34 #include <linux/export.h>
36 #include <drm/drm_crtc.h>
37 #include <drm/drm_edid.h>
38 #include <drm/drm_fourcc.h>
41 * drm_modeset_lock_all - take all modeset locks
44 * This function takes all modeset locks, suitable where a more fine-grained
45 * scheme isn't (yet) implemented.
47 void drm_modeset_lock_all(struct drm_device
*dev
)
49 struct drm_crtc
*crtc
;
51 mutex_lock(&dev
->mode_config
.mutex
);
53 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
54 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
56 EXPORT_SYMBOL(drm_modeset_lock_all
);
59 * drm_modeset_unlock_all - drop all modeset locks
62 void drm_modeset_unlock_all(struct drm_device
*dev
)
64 struct drm_crtc
*crtc
;
66 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
67 mutex_unlock(&crtc
->mutex
);
69 mutex_unlock(&dev
->mode_config
.mutex
);
71 EXPORT_SYMBOL(drm_modeset_unlock_all
);
74 * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked
77 void drm_warn_on_modeset_not_all_locked(struct drm_device
*dev
)
79 struct drm_crtc
*crtc
;
81 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
82 WARN_ON(!mutex_is_locked(&crtc
->mutex
));
84 WARN_ON(!mutex_is_locked(&dev
->mode_config
.mutex
));
86 EXPORT_SYMBOL(drm_warn_on_modeset_not_all_locked
);
88 /* Avoid boilerplate. I'm tired of typing. */
89 #define DRM_ENUM_NAME_FN(fnname, list) \
90 char *fnname(int val) \
93 for (i = 0; i < ARRAY_SIZE(list); i++) { \
94 if (list[i].type == val) \
95 return list[i].name; \
103 static struct drm_prop_enum_list drm_dpms_enum_list
[] =
104 { { DRM_MODE_DPMS_ON
, "On" },
105 { DRM_MODE_DPMS_STANDBY
, "Standby" },
106 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
107 { DRM_MODE_DPMS_OFF
, "Off" }
110 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
113 * Optional properties
115 static struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
117 { DRM_MODE_SCALE_NONE
, "None" },
118 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
119 { DRM_MODE_SCALE_CENTER
, "Center" },
120 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
123 static struct drm_prop_enum_list drm_dithering_mode_enum_list
[] =
125 { DRM_MODE_DITHERING_OFF
, "Off" },
126 { DRM_MODE_DITHERING_ON
, "On" },
127 { DRM_MODE_DITHERING_AUTO
, "Automatic" },
131 * Non-global properties, but "required" for certain connectors.
133 static struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
135 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
136 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
137 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
140 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
142 static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
144 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
145 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
146 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
149 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
150 drm_dvi_i_subconnector_enum_list
)
152 static struct drm_prop_enum_list drm_tv_select_enum_list
[] =
154 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
155 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
156 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
157 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
158 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
161 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
163 static struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
165 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
166 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
167 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
168 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
169 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
172 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
173 drm_tv_subconnector_enum_list
)
175 static struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
176 { DRM_MODE_DIRTY_OFF
, "Off" },
177 { DRM_MODE_DIRTY_ON
, "On" },
178 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
181 DRM_ENUM_NAME_FN(drm_get_dirty_info_name
,
182 drm_dirty_info_enum_list
)
184 struct drm_conn_prop_enum_list
{
191 * Connector and encoder types.
193 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
194 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
195 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
196 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
197 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
198 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
199 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
200 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
201 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
202 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
203 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN", 0 },
204 { DRM_MODE_CONNECTOR_DisplayPort
, "DP", 0 },
205 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A", 0 },
206 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B", 0 },
207 { DRM_MODE_CONNECTOR_TV
, "TV", 0 },
208 { DRM_MODE_CONNECTOR_eDP
, "eDP", 0 },
209 { DRM_MODE_CONNECTOR_VIRTUAL
, "Virtual", 0},
212 static struct drm_prop_enum_list drm_encoder_enum_list
[] =
213 { { DRM_MODE_ENCODER_NONE
, "None" },
214 { DRM_MODE_ENCODER_DAC
, "DAC" },
215 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
216 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
217 { DRM_MODE_ENCODER_TVDAC
, "TV" },
218 { DRM_MODE_ENCODER_VIRTUAL
, "Virtual" },
221 char *drm_get_encoder_name(struct drm_encoder
*encoder
)
225 snprintf(buf
, 32, "%s-%d",
226 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
230 EXPORT_SYMBOL(drm_get_encoder_name
);
232 char *drm_get_connector_name(struct drm_connector
*connector
)
236 snprintf(buf
, 32, "%s-%d",
237 drm_connector_enum_list
[connector
->connector_type
].name
,
238 connector
->connector_type_id
);
241 EXPORT_SYMBOL(drm_get_connector_name
);
243 char *drm_get_connector_status_name(enum drm_connector_status status
)
245 if (status
== connector_status_connected
)
247 else if (status
== connector_status_disconnected
)
248 return "disconnected";
254 * drm_mode_object_get - allocate a new modeset identifier
256 * @obj: object pointer, used to generate unique ID
257 * @obj_type: object type
259 * Create a unique identifier based on @ptr in @dev's identifier space. Used
260 * for tracking modes, CRTCs and connectors.
263 * New unique (relative to other objects in @dev) integer identifier for the
266 static int drm_mode_object_get(struct drm_device
*dev
,
267 struct drm_mode_object
*obj
, uint32_t obj_type
)
271 mutex_lock(&dev
->mode_config
.idr_mutex
);
272 ret
= idr_alloc(&dev
->mode_config
.crtc_idr
, obj
, 1, 0, GFP_KERNEL
);
275 * Set up the object linking under the protection of the idr
276 * lock so that other users can't see inconsistent state.
279 obj
->type
= obj_type
;
281 mutex_unlock(&dev
->mode_config
.idr_mutex
);
283 return ret
< 0 ? ret
: 0;
287 * drm_mode_object_put - free a modeset identifer
289 * @object: object to free
291 * Free @id from @dev's unique identifier pool.
293 static void drm_mode_object_put(struct drm_device
*dev
,
294 struct drm_mode_object
*object
)
296 mutex_lock(&dev
->mode_config
.idr_mutex
);
297 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
298 mutex_unlock(&dev
->mode_config
.idr_mutex
);
302 * drm_mode_object_find - look up a drm object with static lifetime
304 * @id: id of the mode object
305 * @type: type of the mode object
307 * Note that framebuffers cannot be looked up with this functions - since those
308 * are reference counted, they need special treatment.
310 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
311 uint32_t id
, uint32_t type
)
313 struct drm_mode_object
*obj
= NULL
;
315 /* Framebuffers are reference counted and need their own lookup
317 WARN_ON(type
== DRM_MODE_OBJECT_FB
);
319 mutex_lock(&dev
->mode_config
.idr_mutex
);
320 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
321 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
323 mutex_unlock(&dev
->mode_config
.idr_mutex
);
327 EXPORT_SYMBOL(drm_mode_object_find
);
330 * drm_framebuffer_init - initialize a framebuffer
332 * @fb: framebuffer to be initialized
333 * @funcs: ... with these functions
335 * Allocates an ID for the framebuffer's parent mode object, sets its mode
336 * functions & device file and adds it to the master fd list.
339 * This functions publishes the fb and makes it available for concurrent access
340 * by other users. Which means by this point the fb _must_ be fully set up -
341 * since all the fb attributes are invariant over its lifetime, no further
342 * locking but only correct reference counting is required.
345 * Zero on success, error code on failure.
347 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
348 const struct drm_framebuffer_funcs
*funcs
)
352 mutex_lock(&dev
->mode_config
.fb_lock
);
353 kref_init(&fb
->refcount
);
354 INIT_LIST_HEAD(&fb
->filp_head
);
358 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
362 /* Grab the idr reference. */
363 drm_framebuffer_reference(fb
);
365 dev
->mode_config
.num_fb
++;
366 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
368 mutex_unlock(&dev
->mode_config
.fb_lock
);
372 EXPORT_SYMBOL(drm_framebuffer_init
);
374 static void drm_framebuffer_free(struct kref
*kref
)
376 struct drm_framebuffer
*fb
=
377 container_of(kref
, struct drm_framebuffer
, refcount
);
378 fb
->funcs
->destroy(fb
);
381 static struct drm_framebuffer
*__drm_framebuffer_lookup(struct drm_device
*dev
,
384 struct drm_mode_object
*obj
= NULL
;
385 struct drm_framebuffer
*fb
;
387 mutex_lock(&dev
->mode_config
.idr_mutex
);
388 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
389 if (!obj
|| (obj
->type
!= DRM_MODE_OBJECT_FB
) || (obj
->id
!= id
))
393 mutex_unlock(&dev
->mode_config
.idr_mutex
);
399 * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
401 * @id: id of the fb object
403 * If successful, this grabs an additional reference to the framebuffer -
404 * callers need to make sure to eventually unreference the returned framebuffer
407 struct drm_framebuffer
*drm_framebuffer_lookup(struct drm_device
*dev
,
410 struct drm_framebuffer
*fb
;
412 mutex_lock(&dev
->mode_config
.fb_lock
);
413 fb
= __drm_framebuffer_lookup(dev
, id
);
415 kref_get(&fb
->refcount
);
416 mutex_unlock(&dev
->mode_config
.fb_lock
);
420 EXPORT_SYMBOL(drm_framebuffer_lookup
);
423 * drm_framebuffer_unreference - unref a framebuffer
424 * @fb: framebuffer to unref
426 * This functions decrements the fb's refcount and frees it if it drops to zero.
428 void drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
430 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
431 kref_put(&fb
->refcount
, drm_framebuffer_free
);
433 EXPORT_SYMBOL(drm_framebuffer_unreference
);
436 * drm_framebuffer_reference - incr the fb refcnt
439 void drm_framebuffer_reference(struct drm_framebuffer
*fb
)
441 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
442 kref_get(&fb
->refcount
);
444 EXPORT_SYMBOL(drm_framebuffer_reference
);
446 static void drm_framebuffer_free_bug(struct kref
*kref
)
451 static void __drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
453 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
454 kref_put(&fb
->refcount
, drm_framebuffer_free_bug
);
457 /* dev->mode_config.fb_lock must be held! */
458 static void __drm_framebuffer_unregister(struct drm_device
*dev
,
459 struct drm_framebuffer
*fb
)
461 mutex_lock(&dev
->mode_config
.idr_mutex
);
462 idr_remove(&dev
->mode_config
.crtc_idr
, fb
->base
.id
);
463 mutex_unlock(&dev
->mode_config
.idr_mutex
);
467 __drm_framebuffer_unreference(fb
);
471 * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
472 * @fb: fb to unregister
474 * Drivers need to call this when cleaning up driver-private framebuffers, e.g.
475 * those used for fbdev. Note that the caller must hold a reference of it's own,
476 * i.e. the object may not be destroyed through this call (since it'll lead to a
477 * locking inversion).
479 void drm_framebuffer_unregister_private(struct drm_framebuffer
*fb
)
481 struct drm_device
*dev
= fb
->dev
;
483 mutex_lock(&dev
->mode_config
.fb_lock
);
484 /* Mark fb as reaped and drop idr ref. */
485 __drm_framebuffer_unregister(dev
, fb
);
486 mutex_unlock(&dev
->mode_config
.fb_lock
);
488 EXPORT_SYMBOL(drm_framebuffer_unregister_private
);
491 * drm_framebuffer_cleanup - remove a framebuffer object
492 * @fb: framebuffer to remove
494 * Cleanup references to a user-created framebuffer. This function is intended
495 * to be used from the drivers ->destroy callback.
497 * Note that this function does not remove the fb from active usuage - if it is
498 * still used anywhere, hilarity can ensue since userspace could call getfb on
499 * the id and get back -EINVAL. Obviously no concern at driver unload time.
501 * Also, the framebuffer will not be removed from the lookup idr - for
502 * user-created framebuffers this will happen in in the rmfb ioctl. For
503 * driver-private objects (e.g. for fbdev) drivers need to explicitly call
504 * drm_framebuffer_unregister_private.
506 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
508 struct drm_device
*dev
= fb
->dev
;
510 mutex_lock(&dev
->mode_config
.fb_lock
);
512 dev
->mode_config
.num_fb
--;
513 mutex_unlock(&dev
->mode_config
.fb_lock
);
515 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
518 * drm_framebuffer_remove - remove and unreference a framebuffer object
519 * @fb: framebuffer to remove
521 * Scans all the CRTCs and planes in @dev's mode_config. If they're
522 * using @fb, removes it, setting it to NULL. Then drops the reference to the
523 * passed-in framebuffer. Might take the modeset locks.
525 * Note that this function optimizes the cleanup away if the caller holds the
526 * last reference to the framebuffer. It is also guaranteed to not take the
527 * modeset locks in this case.
529 void drm_framebuffer_remove(struct drm_framebuffer
*fb
)
531 struct drm_device
*dev
= fb
->dev
;
532 struct drm_crtc
*crtc
;
533 struct drm_plane
*plane
;
534 struct drm_mode_set set
;
537 WARN_ON(!list_empty(&fb
->filp_head
));
540 * drm ABI mandates that we remove any deleted framebuffers from active
541 * useage. But since most sane clients only remove framebuffers they no
542 * longer need, try to optimize this away.
544 * Since we're holding a reference ourselves, observing a refcount of 1
545 * means that we're the last holder and can skip it. Also, the refcount
546 * can never increase from 1 again, so we don't need any barriers or
549 * Note that userspace could try to race with use and instate a new
550 * usage _after_ we've cleared all current ones. End result will be an
551 * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
554 if (atomic_read(&fb
->refcount
.refcount
) > 1) {
555 drm_modeset_lock_all(dev
);
556 /* remove from any CRTC */
557 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
558 if (crtc
->fb
== fb
) {
559 /* should turn off the crtc */
560 memset(&set
, 0, sizeof(struct drm_mode_set
));
563 ret
= drm_mode_set_config_internal(&set
);
565 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
569 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
570 if (plane
->fb
== fb
) {
571 /* should turn off the crtc */
572 ret
= plane
->funcs
->disable_plane(plane
);
574 DRM_ERROR("failed to disable plane with busy fb\n");
575 /* disconnect the plane from the fb and crtc: */
576 __drm_framebuffer_unreference(plane
->fb
);
581 drm_modeset_unlock_all(dev
);
584 drm_framebuffer_unreference(fb
);
586 EXPORT_SYMBOL(drm_framebuffer_remove
);
589 * drm_crtc_init - Initialise a new CRTC object
591 * @crtc: CRTC object to init
592 * @funcs: callbacks for the new CRTC
594 * Inits a new object created as base part of an driver crtc object.
597 * Zero on success, error code on failure.
599 int drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
600 const struct drm_crtc_funcs
*funcs
)
606 crtc
->invert_dimensions
= false;
608 drm_modeset_lock_all(dev
);
609 mutex_init(&crtc
->mutex
);
610 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
612 ret
= drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
616 crtc
->base
.properties
= &crtc
->properties
;
618 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
619 dev
->mode_config
.num_crtc
++;
622 drm_modeset_unlock_all(dev
);
626 EXPORT_SYMBOL(drm_crtc_init
);
629 * drm_crtc_cleanup - Cleans up the core crtc usage.
630 * @crtc: CRTC to cleanup
632 * Cleanup @crtc. Removes from drm modesetting space
633 * does NOT free object, caller does that.
635 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
637 struct drm_device
*dev
= crtc
->dev
;
639 kfree(crtc
->gamma_store
);
640 crtc
->gamma_store
= NULL
;
642 drm_mode_object_put(dev
, &crtc
->base
);
643 list_del(&crtc
->head
);
644 dev
->mode_config
.num_crtc
--;
646 EXPORT_SYMBOL(drm_crtc_cleanup
);
649 * drm_mode_probed_add - add a mode to a connector's probed mode list
650 * @connector: connector the new mode
653 * Add @mode to @connector's mode list for later use.
655 void drm_mode_probed_add(struct drm_connector
*connector
,
656 struct drm_display_mode
*mode
)
658 list_add(&mode
->head
, &connector
->probed_modes
);
660 EXPORT_SYMBOL(drm_mode_probed_add
);
663 * drm_mode_remove - remove and free a mode
664 * @connector: connector list to modify
665 * @mode: mode to remove
667 * Remove @mode from @connector's mode list, then free it.
669 void drm_mode_remove(struct drm_connector
*connector
,
670 struct drm_display_mode
*mode
)
672 list_del(&mode
->head
);
673 drm_mode_destroy(connector
->dev
, mode
);
675 EXPORT_SYMBOL(drm_mode_remove
);
678 * drm_connector_init - Init a preallocated connector
680 * @connector: the connector to init
681 * @funcs: callbacks for this connector
682 * @connector_type: user visible type of the connector
684 * Initialises a preallocated connector. Connectors should be
685 * subclassed as part of driver connector objects.
688 * Zero on success, error code on failure.
690 int drm_connector_init(struct drm_device
*dev
,
691 struct drm_connector
*connector
,
692 const struct drm_connector_funcs
*funcs
,
697 drm_modeset_lock_all(dev
);
699 ret
= drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
703 connector
->base
.properties
= &connector
->properties
;
704 connector
->dev
= dev
;
705 connector
->funcs
= funcs
;
706 connector
->connector_type
= connector_type
;
707 connector
->connector_type_id
=
708 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
709 INIT_LIST_HEAD(&connector
->user_modes
);
710 INIT_LIST_HEAD(&connector
->probed_modes
);
711 INIT_LIST_HEAD(&connector
->modes
);
712 connector
->edid_blob_ptr
= NULL
;
713 connector
->status
= connector_status_unknown
;
715 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
716 dev
->mode_config
.num_connector
++;
718 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
719 drm_object_attach_property(&connector
->base
,
720 dev
->mode_config
.edid_property
,
723 drm_object_attach_property(&connector
->base
,
724 dev
->mode_config
.dpms_property
, 0);
727 drm_modeset_unlock_all(dev
);
731 EXPORT_SYMBOL(drm_connector_init
);
734 * drm_connector_cleanup - cleans up an initialised connector
735 * @connector: connector to cleanup
737 * Cleans up the connector but doesn't free the object.
739 void drm_connector_cleanup(struct drm_connector
*connector
)
741 struct drm_device
*dev
= connector
->dev
;
742 struct drm_display_mode
*mode
, *t
;
744 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
745 drm_mode_remove(connector
, mode
);
747 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
748 drm_mode_remove(connector
, mode
);
750 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
751 drm_mode_remove(connector
, mode
);
753 drm_mode_object_put(dev
, &connector
->base
);
754 list_del(&connector
->head
);
755 dev
->mode_config
.num_connector
--;
757 EXPORT_SYMBOL(drm_connector_cleanup
);
759 void drm_connector_unplug_all(struct drm_device
*dev
)
761 struct drm_connector
*connector
;
763 /* taking the mode config mutex ends up in a clash with sysfs */
764 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
765 drm_sysfs_connector_remove(connector
);
768 EXPORT_SYMBOL(drm_connector_unplug_all
);
770 int drm_encoder_init(struct drm_device
*dev
,
771 struct drm_encoder
*encoder
,
772 const struct drm_encoder_funcs
*funcs
,
777 drm_modeset_lock_all(dev
);
779 ret
= drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
784 encoder
->encoder_type
= encoder_type
;
785 encoder
->funcs
= funcs
;
787 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
788 dev
->mode_config
.num_encoder
++;
791 drm_modeset_unlock_all(dev
);
795 EXPORT_SYMBOL(drm_encoder_init
);
797 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
799 struct drm_device
*dev
= encoder
->dev
;
800 drm_modeset_lock_all(dev
);
801 drm_mode_object_put(dev
, &encoder
->base
);
802 list_del(&encoder
->head
);
803 dev
->mode_config
.num_encoder
--;
804 drm_modeset_unlock_all(dev
);
806 EXPORT_SYMBOL(drm_encoder_cleanup
);
808 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
809 unsigned long possible_crtcs
,
810 const struct drm_plane_funcs
*funcs
,
811 const uint32_t *formats
, uint32_t format_count
,
816 drm_modeset_lock_all(dev
);
818 ret
= drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
822 plane
->base
.properties
= &plane
->properties
;
824 plane
->funcs
= funcs
;
825 plane
->format_types
= kmalloc(sizeof(uint32_t) * format_count
,
827 if (!plane
->format_types
) {
828 DRM_DEBUG_KMS("out of memory when allocating plane\n");
829 drm_mode_object_put(dev
, &plane
->base
);
834 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
835 plane
->format_count
= format_count
;
836 plane
->possible_crtcs
= possible_crtcs
;
838 /* private planes are not exposed to userspace, but depending on
839 * display hardware, might be convenient to allow sharing programming
840 * for the scanout engine with the crtc implementation.
843 list_add_tail(&plane
->head
, &dev
->mode_config
.plane_list
);
844 dev
->mode_config
.num_plane
++;
846 INIT_LIST_HEAD(&plane
->head
);
850 drm_modeset_unlock_all(dev
);
854 EXPORT_SYMBOL(drm_plane_init
);
856 void drm_plane_cleanup(struct drm_plane
*plane
)
858 struct drm_device
*dev
= plane
->dev
;
860 drm_modeset_lock_all(dev
);
861 kfree(plane
->format_types
);
862 drm_mode_object_put(dev
, &plane
->base
);
863 /* if not added to a list, it must be a private plane */
864 if (!list_empty(&plane
->head
)) {
865 list_del(&plane
->head
);
866 dev
->mode_config
.num_plane
--;
868 drm_modeset_unlock_all(dev
);
870 EXPORT_SYMBOL(drm_plane_cleanup
);
873 * drm_mode_create - create a new display mode
876 * Create a new drm_display_mode, give it an ID, and return it.
879 * Pointer to new mode on success, NULL on error.
881 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
883 struct drm_display_mode
*nmode
;
885 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
889 if (drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
)) {
896 EXPORT_SYMBOL(drm_mode_create
);
899 * drm_mode_destroy - remove a mode
901 * @mode: mode to remove
903 * Free @mode's unique identifier, then free it.
905 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
910 drm_mode_object_put(dev
, &mode
->base
);
914 EXPORT_SYMBOL(drm_mode_destroy
);
916 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
918 struct drm_property
*edid
;
919 struct drm_property
*dpms
;
922 * Standard properties (apply to all connectors)
924 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
925 DRM_MODE_PROP_IMMUTABLE
,
927 dev
->mode_config
.edid_property
= edid
;
929 dpms
= drm_property_create_enum(dev
, 0,
930 "DPMS", drm_dpms_enum_list
,
931 ARRAY_SIZE(drm_dpms_enum_list
));
932 dev
->mode_config
.dpms_property
= dpms
;
938 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
941 * Called by a driver the first time a DVI-I connector is made.
943 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
945 struct drm_property
*dvi_i_selector
;
946 struct drm_property
*dvi_i_subconnector
;
948 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
952 drm_property_create_enum(dev
, 0,
953 "select subconnector",
954 drm_dvi_i_select_enum_list
,
955 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
956 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
958 dvi_i_subconnector
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
960 drm_dvi_i_subconnector_enum_list
,
961 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
962 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
966 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
969 * drm_create_tv_properties - create TV specific connector properties
971 * @num_modes: number of different TV formats (modes) supported
972 * @modes: array of pointers to strings containing name of each format
974 * Called by a driver's TV initialization routine, this function creates
975 * the TV specific connector properties for a given device. Caller is
976 * responsible for allocating a list of format names and passing them to
979 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
982 struct drm_property
*tv_selector
;
983 struct drm_property
*tv_subconnector
;
986 if (dev
->mode_config
.tv_select_subconnector_property
)
990 * Basic connector properties
992 tv_selector
= drm_property_create_enum(dev
, 0,
993 "select subconnector",
994 drm_tv_select_enum_list
,
995 ARRAY_SIZE(drm_tv_select_enum_list
));
996 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
999 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1001 drm_tv_subconnector_enum_list
,
1002 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
1003 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
1006 * Other, TV specific properties: margins & TV modes.
1008 dev
->mode_config
.tv_left_margin_property
=
1009 drm_property_create_range(dev
, 0, "left margin", 0, 100);
1011 dev
->mode_config
.tv_right_margin_property
=
1012 drm_property_create_range(dev
, 0, "right margin", 0, 100);
1014 dev
->mode_config
.tv_top_margin_property
=
1015 drm_property_create_range(dev
, 0, "top margin", 0, 100);
1017 dev
->mode_config
.tv_bottom_margin_property
=
1018 drm_property_create_range(dev
, 0, "bottom margin", 0, 100);
1020 dev
->mode_config
.tv_mode_property
=
1021 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
1023 for (i
= 0; i
< num_modes
; i
++)
1024 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
1027 dev
->mode_config
.tv_brightness_property
=
1028 drm_property_create_range(dev
, 0, "brightness", 0, 100);
1030 dev
->mode_config
.tv_contrast_property
=
1031 drm_property_create_range(dev
, 0, "contrast", 0, 100);
1033 dev
->mode_config
.tv_flicker_reduction_property
=
1034 drm_property_create_range(dev
, 0, "flicker reduction", 0, 100);
1036 dev
->mode_config
.tv_overscan_property
=
1037 drm_property_create_range(dev
, 0, "overscan", 0, 100);
1039 dev
->mode_config
.tv_saturation_property
=
1040 drm_property_create_range(dev
, 0, "saturation", 0, 100);
1042 dev
->mode_config
.tv_hue_property
=
1043 drm_property_create_range(dev
, 0, "hue", 0, 100);
1047 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
1050 * drm_mode_create_scaling_mode_property - create scaling mode property
1053 * Called by a driver the first time it's needed, must be attached to desired
1056 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
1058 struct drm_property
*scaling_mode
;
1060 if (dev
->mode_config
.scaling_mode_property
)
1064 drm_property_create_enum(dev
, 0, "scaling mode",
1065 drm_scaling_mode_enum_list
,
1066 ARRAY_SIZE(drm_scaling_mode_enum_list
));
1068 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
1072 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
1075 * drm_mode_create_dithering_property - create dithering property
1078 * Called by a driver the first time it's needed, must be attached to desired
1081 int drm_mode_create_dithering_property(struct drm_device
*dev
)
1083 struct drm_property
*dithering_mode
;
1085 if (dev
->mode_config
.dithering_mode_property
)
1089 drm_property_create_enum(dev
, 0, "dithering",
1090 drm_dithering_mode_enum_list
,
1091 ARRAY_SIZE(drm_dithering_mode_enum_list
));
1092 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
1096 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
1099 * drm_mode_create_dirty_property - create dirty property
1102 * Called by a driver the first time it's needed, must be attached to desired
1105 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
1107 struct drm_property
*dirty_info
;
1109 if (dev
->mode_config
.dirty_info_property
)
1113 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1115 drm_dirty_info_enum_list
,
1116 ARRAY_SIZE(drm_dirty_info_enum_list
));
1117 dev
->mode_config
.dirty_info_property
= dirty_info
;
1121 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
1124 * drm_mode_config_init - initialize DRM mode_configuration structure
1127 * Initialize @dev's mode_config structure, used for tracking the graphics
1128 * configuration of @dev.
1130 * Since this initializes the modeset locks, no locking is possible. Which is no
1131 * problem, since this should happen single threaded at init time. It is the
1132 * driver's problem to ensure this guarantee.
1135 void drm_mode_config_init(struct drm_device
*dev
)
1137 mutex_init(&dev
->mode_config
.mutex
);
1138 mutex_init(&dev
->mode_config
.idr_mutex
);
1139 mutex_init(&dev
->mode_config
.fb_lock
);
1140 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
1141 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
1142 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
1143 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
1144 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
1145 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
1146 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
1147 idr_init(&dev
->mode_config
.crtc_idr
);
1149 drm_modeset_lock_all(dev
);
1150 drm_mode_create_standard_connector_properties(dev
);
1151 drm_modeset_unlock_all(dev
);
1153 /* Just to be sure */
1154 dev
->mode_config
.num_fb
= 0;
1155 dev
->mode_config
.num_connector
= 0;
1156 dev
->mode_config
.num_crtc
= 0;
1157 dev
->mode_config
.num_encoder
= 0;
1159 EXPORT_SYMBOL(drm_mode_config_init
);
1161 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
1163 uint32_t total_objects
= 0;
1165 total_objects
+= dev
->mode_config
.num_crtc
;
1166 total_objects
+= dev
->mode_config
.num_connector
;
1167 total_objects
+= dev
->mode_config
.num_encoder
;
1169 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
1170 if (!group
->id_list
)
1173 group
->num_crtcs
= 0;
1174 group
->num_connectors
= 0;
1175 group
->num_encoders
= 0;
1179 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
1180 struct drm_mode_group
*group
)
1182 struct drm_crtc
*crtc
;
1183 struct drm_encoder
*encoder
;
1184 struct drm_connector
*connector
;
1187 if ((ret
= drm_mode_group_init(dev
, group
)))
1190 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
1191 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
1193 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
1194 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
1197 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
1198 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
1199 group
->num_connectors
++] = connector
->base
.id
;
1203 EXPORT_SYMBOL(drm_mode_group_init_legacy_group
);
1206 * drm_mode_config_cleanup - free up DRM mode_config info
1209 * Free up all the connectors and CRTCs associated with this DRM device, then
1210 * free up the framebuffers and associated buffer objects.
1212 * Note that since this /should/ happen single-threaded at driver/device
1213 * teardown time, no locking is required. It's the driver's job to ensure that
1214 * this guarantee actually holds true.
1216 * FIXME: cleanup any dangling user buffer objects too
1218 void drm_mode_config_cleanup(struct drm_device
*dev
)
1220 struct drm_connector
*connector
, *ot
;
1221 struct drm_crtc
*crtc
, *ct
;
1222 struct drm_encoder
*encoder
, *enct
;
1223 struct drm_framebuffer
*fb
, *fbt
;
1224 struct drm_property
*property
, *pt
;
1225 struct drm_plane
*plane
, *plt
;
1227 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
1229 encoder
->funcs
->destroy(encoder
);
1232 list_for_each_entry_safe(connector
, ot
,
1233 &dev
->mode_config
.connector_list
, head
) {
1234 connector
->funcs
->destroy(connector
);
1237 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
1239 drm_property_destroy(dev
, property
);
1243 * Single-threaded teardown context, so it's not required to grab the
1244 * fb_lock to protect against concurrent fb_list access. Contrary, it
1245 * would actually deadlock with the drm_framebuffer_cleanup function.
1247 * Also, if there are any framebuffers left, that's a driver leak now,
1248 * so politely WARN about this.
1250 WARN_ON(!list_empty(&dev
->mode_config
.fb_list
));
1251 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
1252 drm_framebuffer_remove(fb
);
1255 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
1257 plane
->funcs
->destroy(plane
);
1260 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
1261 crtc
->funcs
->destroy(crtc
);
1264 idr_destroy(&dev
->mode_config
.crtc_idr
);
1266 EXPORT_SYMBOL(drm_mode_config_cleanup
);
1269 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1270 * @out: drm_mode_modeinfo struct to return to the user
1271 * @in: drm_display_mode to use
1273 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1276 static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
1277 const struct drm_display_mode
*in
)
1279 WARN(in
->hdisplay
> USHRT_MAX
|| in
->hsync_start
> USHRT_MAX
||
1280 in
->hsync_end
> USHRT_MAX
|| in
->htotal
> USHRT_MAX
||
1281 in
->hskew
> USHRT_MAX
|| in
->vdisplay
> USHRT_MAX
||
1282 in
->vsync_start
> USHRT_MAX
|| in
->vsync_end
> USHRT_MAX
||
1283 in
->vtotal
> USHRT_MAX
|| in
->vscan
> USHRT_MAX
,
1284 "timing values too large for mode info\n");
1286 out
->clock
= in
->clock
;
1287 out
->hdisplay
= in
->hdisplay
;
1288 out
->hsync_start
= in
->hsync_start
;
1289 out
->hsync_end
= in
->hsync_end
;
1290 out
->htotal
= in
->htotal
;
1291 out
->hskew
= in
->hskew
;
1292 out
->vdisplay
= in
->vdisplay
;
1293 out
->vsync_start
= in
->vsync_start
;
1294 out
->vsync_end
= in
->vsync_end
;
1295 out
->vtotal
= in
->vtotal
;
1296 out
->vscan
= in
->vscan
;
1297 out
->vrefresh
= in
->vrefresh
;
1298 out
->flags
= in
->flags
;
1299 out
->type
= in
->type
;
1300 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1301 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1305 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1306 * @out: drm_display_mode to return to the user
1307 * @in: drm_mode_modeinfo to use
1309 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1313 * Zero on success, errno on failure.
1315 static int drm_crtc_convert_umode(struct drm_display_mode
*out
,
1316 const struct drm_mode_modeinfo
*in
)
1318 if (in
->clock
> INT_MAX
|| in
->vrefresh
> INT_MAX
)
1321 out
->clock
= in
->clock
;
1322 out
->hdisplay
= in
->hdisplay
;
1323 out
->hsync_start
= in
->hsync_start
;
1324 out
->hsync_end
= in
->hsync_end
;
1325 out
->htotal
= in
->htotal
;
1326 out
->hskew
= in
->hskew
;
1327 out
->vdisplay
= in
->vdisplay
;
1328 out
->vsync_start
= in
->vsync_start
;
1329 out
->vsync_end
= in
->vsync_end
;
1330 out
->vtotal
= in
->vtotal
;
1331 out
->vscan
= in
->vscan
;
1332 out
->vrefresh
= in
->vrefresh
;
1333 out
->flags
= in
->flags
;
1334 out
->type
= in
->type
;
1335 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1336 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1342 * drm_mode_getresources - get graphics configuration
1343 * @dev: drm device for the ioctl
1344 * @data: data pointer for the ioctl
1345 * @file_priv: drm file for the ioctl call
1347 * Construct a set of configuration description structures and return
1348 * them to the user, including CRTC, connector and framebuffer configuration.
1350 * Called by the user via ioctl.
1353 * Zero on success, errno on failure.
1355 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1356 struct drm_file
*file_priv
)
1358 struct drm_mode_card_res
*card_res
= data
;
1359 struct list_head
*lh
;
1360 struct drm_framebuffer
*fb
;
1361 struct drm_connector
*connector
;
1362 struct drm_crtc
*crtc
;
1363 struct drm_encoder
*encoder
;
1365 int connector_count
= 0;
1368 int encoder_count
= 0;
1370 uint32_t __user
*fb_id
;
1371 uint32_t __user
*crtc_id
;
1372 uint32_t __user
*connector_id
;
1373 uint32_t __user
*encoder_id
;
1374 struct drm_mode_group
*mode_group
;
1376 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1380 mutex_lock(&file_priv
->fbs_lock
);
1382 * For the non-control nodes we need to limit the list of resources
1383 * by IDs in the group list for this node
1385 list_for_each(lh
, &file_priv
->fbs
)
1388 /* handle this in 4 parts */
1390 if (card_res
->count_fbs
>= fb_count
) {
1392 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1393 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1394 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1395 mutex_unlock(&file_priv
->fbs_lock
);
1401 card_res
->count_fbs
= fb_count
;
1402 mutex_unlock(&file_priv
->fbs_lock
);
1404 drm_modeset_lock_all(dev
);
1405 mode_group
= &file_priv
->master
->minor
->mode_group
;
1406 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1408 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1411 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1414 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1418 crtc_count
= mode_group
->num_crtcs
;
1419 connector_count
= mode_group
->num_connectors
;
1420 encoder_count
= mode_group
->num_encoders
;
1423 card_res
->max_height
= dev
->mode_config
.max_height
;
1424 card_res
->min_height
= dev
->mode_config
.min_height
;
1425 card_res
->max_width
= dev
->mode_config
.max_width
;
1426 card_res
->min_width
= dev
->mode_config
.min_width
;
1429 if (card_res
->count_crtcs
>= crtc_count
) {
1431 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1432 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1433 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1435 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1436 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1443 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1444 if (put_user(mode_group
->id_list
[i
],
1445 crtc_id
+ copied
)) {
1453 card_res
->count_crtcs
= crtc_count
;
1456 if (card_res
->count_encoders
>= encoder_count
) {
1458 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1459 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1460 list_for_each_entry(encoder
,
1461 &dev
->mode_config
.encoder_list
,
1463 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1464 drm_get_encoder_name(encoder
));
1465 if (put_user(encoder
->base
.id
, encoder_id
+
1473 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1474 if (put_user(mode_group
->id_list
[i
],
1475 encoder_id
+ copied
)) {
1484 card_res
->count_encoders
= encoder_count
;
1487 if (card_res
->count_connectors
>= connector_count
) {
1489 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1490 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1491 list_for_each_entry(connector
,
1492 &dev
->mode_config
.connector_list
,
1494 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1496 drm_get_connector_name(connector
));
1497 if (put_user(connector
->base
.id
,
1498 connector_id
+ copied
)) {
1505 int start
= mode_group
->num_crtcs
+
1506 mode_group
->num_encoders
;
1507 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1508 if (put_user(mode_group
->id_list
[i
],
1509 connector_id
+ copied
)) {
1517 card_res
->count_connectors
= connector_count
;
1519 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1520 card_res
->count_connectors
, card_res
->count_encoders
);
1523 drm_modeset_unlock_all(dev
);
1528 * drm_mode_getcrtc - get CRTC configuration
1529 * @dev: drm device for the ioctl
1530 * @data: data pointer for the ioctl
1531 * @file_priv: drm file for the ioctl call
1533 * Construct a CRTC configuration structure to return to the user.
1535 * Called by the user via ioctl.
1538 * Zero on success, errno on failure.
1540 int drm_mode_getcrtc(struct drm_device
*dev
,
1541 void *data
, struct drm_file
*file_priv
)
1543 struct drm_mode_crtc
*crtc_resp
= data
;
1544 struct drm_crtc
*crtc
;
1545 struct drm_mode_object
*obj
;
1548 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1551 drm_modeset_lock_all(dev
);
1553 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1554 DRM_MODE_OBJECT_CRTC
);
1559 crtc
= obj_to_crtc(obj
);
1561 crtc_resp
->x
= crtc
->x
;
1562 crtc_resp
->y
= crtc
->y
;
1563 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1565 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1567 crtc_resp
->fb_id
= 0;
1569 if (crtc
->enabled
) {
1571 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1572 crtc_resp
->mode_valid
= 1;
1575 crtc_resp
->mode_valid
= 0;
1579 drm_modeset_unlock_all(dev
);
1584 * drm_mode_getconnector - get connector configuration
1585 * @dev: drm device for the ioctl
1586 * @data: data pointer for the ioctl
1587 * @file_priv: drm file for the ioctl call
1589 * Construct a connector configuration structure to return to the user.
1591 * Called by the user via ioctl.
1594 * Zero on success, errno on failure.
1596 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1597 struct drm_file
*file_priv
)
1599 struct drm_mode_get_connector
*out_resp
= data
;
1600 struct drm_mode_object
*obj
;
1601 struct drm_connector
*connector
;
1602 struct drm_display_mode
*mode
;
1604 int props_count
= 0;
1605 int encoders_count
= 0;
1609 struct drm_mode_modeinfo u_mode
;
1610 struct drm_mode_modeinfo __user
*mode_ptr
;
1611 uint32_t __user
*prop_ptr
;
1612 uint64_t __user
*prop_values
;
1613 uint32_t __user
*encoder_ptr
;
1615 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1618 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1620 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1622 mutex_lock(&dev
->mode_config
.mutex
);
1624 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1625 DRM_MODE_OBJECT_CONNECTOR
);
1630 connector
= obj_to_connector(obj
);
1632 props_count
= connector
->properties
.count
;
1634 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1635 if (connector
->encoder_ids
[i
] != 0) {
1640 if (out_resp
->count_modes
== 0) {
1641 connector
->funcs
->fill_modes(connector
,
1642 dev
->mode_config
.max_width
,
1643 dev
->mode_config
.max_height
);
1646 /* delayed so we get modes regardless of pre-fill_modes state */
1647 list_for_each_entry(mode
, &connector
->modes
, head
)
1650 out_resp
->connector_id
= connector
->base
.id
;
1651 out_resp
->connector_type
= connector
->connector_type
;
1652 out_resp
->connector_type_id
= connector
->connector_type_id
;
1653 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1654 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1655 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1656 out_resp
->connection
= connector
->status
;
1657 if (connector
->encoder
)
1658 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1660 out_resp
->encoder_id
= 0;
1663 * This ioctl is called twice, once to determine how much space is
1664 * needed, and the 2nd time to fill it.
1666 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1668 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1669 list_for_each_entry(mode
, &connector
->modes
, head
) {
1670 drm_crtc_convert_to_umode(&u_mode
, mode
);
1671 if (copy_to_user(mode_ptr
+ copied
,
1672 &u_mode
, sizeof(u_mode
))) {
1679 out_resp
->count_modes
= mode_count
;
1681 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1683 prop_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
);
1684 prop_values
= (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
);
1685 for (i
= 0; i
< connector
->properties
.count
; i
++) {
1686 if (put_user(connector
->properties
.ids
[i
],
1687 prop_ptr
+ copied
)) {
1692 if (put_user(connector
->properties
.values
[i
],
1693 prop_values
+ copied
)) {
1700 out_resp
->count_props
= props_count
;
1702 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1704 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1705 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1706 if (connector
->encoder_ids
[i
] != 0) {
1707 if (put_user(connector
->encoder_ids
[i
],
1708 encoder_ptr
+ copied
)) {
1716 out_resp
->count_encoders
= encoders_count
;
1719 mutex_unlock(&dev
->mode_config
.mutex
);
1724 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1725 struct drm_file
*file_priv
)
1727 struct drm_mode_get_encoder
*enc_resp
= data
;
1728 struct drm_mode_object
*obj
;
1729 struct drm_encoder
*encoder
;
1732 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1735 drm_modeset_lock_all(dev
);
1736 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1737 DRM_MODE_OBJECT_ENCODER
);
1742 encoder
= obj_to_encoder(obj
);
1745 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1747 enc_resp
->crtc_id
= 0;
1748 enc_resp
->encoder_type
= encoder
->encoder_type
;
1749 enc_resp
->encoder_id
= encoder
->base
.id
;
1750 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1751 enc_resp
->possible_clones
= encoder
->possible_clones
;
1754 drm_modeset_unlock_all(dev
);
1759 * drm_mode_getplane_res - get plane info
1762 * @file_priv: DRM file info
1764 * Return an plane count and set of IDs.
1766 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
1767 struct drm_file
*file_priv
)
1769 struct drm_mode_get_plane_res
*plane_resp
= data
;
1770 struct drm_mode_config
*config
;
1771 struct drm_plane
*plane
;
1772 uint32_t __user
*plane_ptr
;
1773 int copied
= 0, ret
= 0;
1775 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1778 drm_modeset_lock_all(dev
);
1779 config
= &dev
->mode_config
;
1782 * This ioctl is called twice, once to determine how much space is
1783 * needed, and the 2nd time to fill it.
1785 if (config
->num_plane
&&
1786 (plane_resp
->count_planes
>= config
->num_plane
)) {
1787 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
1789 list_for_each_entry(plane
, &config
->plane_list
, head
) {
1790 if (put_user(plane
->base
.id
, plane_ptr
+ copied
)) {
1797 plane_resp
->count_planes
= config
->num_plane
;
1800 drm_modeset_unlock_all(dev
);
1805 * drm_mode_getplane - get plane info
1808 * @file_priv: DRM file info
1810 * Return plane info, including formats supported, gamma size, any
1813 int drm_mode_getplane(struct drm_device
*dev
, void *data
,
1814 struct drm_file
*file_priv
)
1816 struct drm_mode_get_plane
*plane_resp
= data
;
1817 struct drm_mode_object
*obj
;
1818 struct drm_plane
*plane
;
1819 uint32_t __user
*format_ptr
;
1822 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1825 drm_modeset_lock_all(dev
);
1826 obj
= drm_mode_object_find(dev
, plane_resp
->plane_id
,
1827 DRM_MODE_OBJECT_PLANE
);
1832 plane
= obj_to_plane(obj
);
1835 plane_resp
->crtc_id
= plane
->crtc
->base
.id
;
1837 plane_resp
->crtc_id
= 0;
1840 plane_resp
->fb_id
= plane
->fb
->base
.id
;
1842 plane_resp
->fb_id
= 0;
1844 plane_resp
->plane_id
= plane
->base
.id
;
1845 plane_resp
->possible_crtcs
= plane
->possible_crtcs
;
1846 plane_resp
->gamma_size
= plane
->gamma_size
;
1849 * This ioctl is called twice, once to determine how much space is
1850 * needed, and the 2nd time to fill it.
1852 if (plane
->format_count
&&
1853 (plane_resp
->count_format_types
>= plane
->format_count
)) {
1854 format_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->format_type_ptr
;
1855 if (copy_to_user(format_ptr
,
1856 plane
->format_types
,
1857 sizeof(uint32_t) * plane
->format_count
)) {
1862 plane_resp
->count_format_types
= plane
->format_count
;
1865 drm_modeset_unlock_all(dev
);
1870 * drm_mode_setplane - set up or tear down an plane
1872 * @data: ioctl data*
1873 * @file_priv: DRM file info
1875 * Set plane info, including placement, fb, scaling, and other factors.
1876 * Or pass a NULL fb to disable.
1878 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
1879 struct drm_file
*file_priv
)
1881 struct drm_mode_set_plane
*plane_req
= data
;
1882 struct drm_mode_object
*obj
;
1883 struct drm_plane
*plane
;
1884 struct drm_crtc
*crtc
;
1885 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
1887 unsigned int fb_width
, fb_height
;
1890 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1894 * First, find the plane, crtc, and fb objects. If not available,
1895 * we don't bother to call the driver.
1897 obj
= drm_mode_object_find(dev
, plane_req
->plane_id
,
1898 DRM_MODE_OBJECT_PLANE
);
1900 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1901 plane_req
->plane_id
);
1904 plane
= obj_to_plane(obj
);
1906 /* No fb means shut it down */
1907 if (!plane_req
->fb_id
) {
1908 drm_modeset_lock_all(dev
);
1910 plane
->funcs
->disable_plane(plane
);
1913 drm_modeset_unlock_all(dev
);
1917 obj
= drm_mode_object_find(dev
, plane_req
->crtc_id
,
1918 DRM_MODE_OBJECT_CRTC
);
1920 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1921 plane_req
->crtc_id
);
1925 crtc
= obj_to_crtc(obj
);
1927 fb
= drm_framebuffer_lookup(dev
, plane_req
->fb_id
);
1929 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1935 /* Check whether this plane supports the fb pixel format. */
1936 for (i
= 0; i
< plane
->format_count
; i
++)
1937 if (fb
->pixel_format
== plane
->format_types
[i
])
1939 if (i
== plane
->format_count
) {
1940 DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb
->pixel_format
);
1945 fb_width
= fb
->width
<< 16;
1946 fb_height
= fb
->height
<< 16;
1948 /* Make sure source coordinates are inside the fb. */
1949 if (plane_req
->src_w
> fb_width
||
1950 plane_req
->src_x
> fb_width
- plane_req
->src_w
||
1951 plane_req
->src_h
> fb_height
||
1952 plane_req
->src_y
> fb_height
- plane_req
->src_h
) {
1953 DRM_DEBUG_KMS("Invalid source coordinates "
1954 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1955 plane_req
->src_w
>> 16,
1956 ((plane_req
->src_w
& 0xffff) * 15625) >> 10,
1957 plane_req
->src_h
>> 16,
1958 ((plane_req
->src_h
& 0xffff) * 15625) >> 10,
1959 plane_req
->src_x
>> 16,
1960 ((plane_req
->src_x
& 0xffff) * 15625) >> 10,
1961 plane_req
->src_y
>> 16,
1962 ((plane_req
->src_y
& 0xffff) * 15625) >> 10);
1967 /* Give drivers some help against integer overflows */
1968 if (plane_req
->crtc_w
> INT_MAX
||
1969 plane_req
->crtc_x
> INT_MAX
- (int32_t) plane_req
->crtc_w
||
1970 plane_req
->crtc_h
> INT_MAX
||
1971 plane_req
->crtc_y
> INT_MAX
- (int32_t) plane_req
->crtc_h
) {
1972 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
1973 plane_req
->crtc_w
, plane_req
->crtc_h
,
1974 plane_req
->crtc_x
, plane_req
->crtc_y
);
1979 drm_modeset_lock_all(dev
);
1980 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
1981 plane_req
->crtc_x
, plane_req
->crtc_y
,
1982 plane_req
->crtc_w
, plane_req
->crtc_h
,
1983 plane_req
->src_x
, plane_req
->src_y
,
1984 plane_req
->src_w
, plane_req
->src_h
);
1991 drm_modeset_unlock_all(dev
);
1995 drm_framebuffer_unreference(fb
);
1997 drm_framebuffer_unreference(old_fb
);
2003 * drm_mode_set_config_internal - helper to call ->set_config
2004 * @set: modeset config to set
2006 * This is a little helper to wrap internal calls to the ->set_config driver
2007 * interface. The only thing it adds is correct refcounting dance.
2009 int drm_mode_set_config_internal(struct drm_mode_set
*set
)
2011 struct drm_crtc
*crtc
= set
->crtc
;
2012 struct drm_framebuffer
*fb
, *old_fb
;
2018 ret
= crtc
->funcs
->set_config(set
);
2021 drm_framebuffer_unreference(old_fb
);
2023 drm_framebuffer_reference(fb
);
2028 EXPORT_SYMBOL(drm_mode_set_config_internal
);
2031 * drm_mode_setcrtc - set CRTC configuration
2032 * @dev: drm device for the ioctl
2033 * @data: data pointer for the ioctl
2034 * @file_priv: drm file for the ioctl call
2036 * Build a new CRTC configuration based on user request.
2038 * Called by the user via ioctl.
2041 * Zero on success, errno on failure.
2043 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
2044 struct drm_file
*file_priv
)
2046 struct drm_mode_config
*config
= &dev
->mode_config
;
2047 struct drm_mode_crtc
*crtc_req
= data
;
2048 struct drm_mode_object
*obj
;
2049 struct drm_crtc
*crtc
;
2050 struct drm_connector
**connector_set
= NULL
, *connector
;
2051 struct drm_framebuffer
*fb
= NULL
;
2052 struct drm_display_mode
*mode
= NULL
;
2053 struct drm_mode_set set
;
2054 uint32_t __user
*set_connectors_ptr
;
2058 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2061 /* For some reason crtc x/y offsets are signed internally. */
2062 if (crtc_req
->x
> INT_MAX
|| crtc_req
->y
> INT_MAX
)
2065 drm_modeset_lock_all(dev
);
2066 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
2067 DRM_MODE_OBJECT_CRTC
);
2069 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
2073 crtc
= obj_to_crtc(obj
);
2074 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
2076 if (crtc_req
->mode_valid
) {
2077 int hdisplay
, vdisplay
;
2078 /* If we have a mode we need a framebuffer. */
2079 /* If we pass -1, set the mode with the currently bound fb */
2080 if (crtc_req
->fb_id
== -1) {
2082 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
2087 /* Make refcounting symmetric with the lookup path. */
2088 drm_framebuffer_reference(fb
);
2090 fb
= drm_framebuffer_lookup(dev
, crtc_req
->fb_id
);
2092 DRM_DEBUG_KMS("Unknown FB ID%d\n",
2099 mode
= drm_mode_create(dev
);
2105 ret
= drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
2107 DRM_DEBUG_KMS("Invalid mode\n");
2111 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
2113 hdisplay
= mode
->hdisplay
;
2114 vdisplay
= mode
->vdisplay
;
2116 if (crtc
->invert_dimensions
)
2117 swap(hdisplay
, vdisplay
);
2119 if (hdisplay
> fb
->width
||
2120 vdisplay
> fb
->height
||
2121 crtc_req
->x
> fb
->width
- hdisplay
||
2122 crtc_req
->y
> fb
->height
- vdisplay
) {
2123 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
2124 fb
->width
, fb
->height
,
2125 hdisplay
, vdisplay
, crtc_req
->x
, crtc_req
->y
,
2126 crtc
->invert_dimensions
? " (inverted)" : "");
2132 if (crtc_req
->count_connectors
== 0 && mode
) {
2133 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
2138 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
2139 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
2140 crtc_req
->count_connectors
);
2145 if (crtc_req
->count_connectors
> 0) {
2148 /* Avoid unbounded kernel memory allocation */
2149 if (crtc_req
->count_connectors
> config
->num_connector
) {
2154 connector_set
= kmalloc(crtc_req
->count_connectors
*
2155 sizeof(struct drm_connector
*),
2157 if (!connector_set
) {
2162 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
2163 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
2164 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
2169 obj
= drm_mode_object_find(dev
, out_id
,
2170 DRM_MODE_OBJECT_CONNECTOR
);
2172 DRM_DEBUG_KMS("Connector id %d unknown\n",
2177 connector
= obj_to_connector(obj
);
2178 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2180 drm_get_connector_name(connector
));
2182 connector_set
[i
] = connector
;
2187 set
.x
= crtc_req
->x
;
2188 set
.y
= crtc_req
->y
;
2190 set
.connectors
= connector_set
;
2191 set
.num_connectors
= crtc_req
->count_connectors
;
2193 ret
= drm_mode_set_config_internal(&set
);
2197 drm_framebuffer_unreference(fb
);
2199 kfree(connector_set
);
2200 drm_mode_destroy(dev
, mode
);
2201 drm_modeset_unlock_all(dev
);
2205 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
2206 void *data
, struct drm_file
*file_priv
)
2208 struct drm_mode_cursor
*req
= data
;
2209 struct drm_mode_object
*obj
;
2210 struct drm_crtc
*crtc
;
2213 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2216 if (!req
->flags
|| (~DRM_MODE_CURSOR_FLAGS
& req
->flags
))
2219 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2221 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
2224 crtc
= obj_to_crtc(obj
);
2226 mutex_lock(&crtc
->mutex
);
2227 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
2228 if (!crtc
->funcs
->cursor_set
) {
2232 /* Turns off the cursor if handle is 0 */
2233 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
2234 req
->width
, req
->height
);
2237 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
2238 if (crtc
->funcs
->cursor_move
) {
2239 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
2246 mutex_unlock(&crtc
->mutex
);
2251 /* Original addfb only supported RGB formats, so figure out which one */
2252 uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
)
2258 fmt
= DRM_FORMAT_C8
;
2262 fmt
= DRM_FORMAT_XRGB1555
;
2264 fmt
= DRM_FORMAT_RGB565
;
2267 fmt
= DRM_FORMAT_RGB888
;
2271 fmt
= DRM_FORMAT_XRGB8888
;
2272 else if (depth
== 30)
2273 fmt
= DRM_FORMAT_XRGB2101010
;
2275 fmt
= DRM_FORMAT_ARGB8888
;
2278 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
2279 fmt
= DRM_FORMAT_XRGB8888
;
2285 EXPORT_SYMBOL(drm_mode_legacy_fb_format
);
2288 * drm_mode_addfb - add an FB to the graphics configuration
2289 * @dev: drm device for the ioctl
2290 * @data: data pointer for the ioctl
2291 * @file_priv: drm file for the ioctl call
2293 * Add a new FB to the specified CRTC, given a user request.
2295 * Called by the user via ioctl.
2298 * Zero on success, errno on failure.
2300 int drm_mode_addfb(struct drm_device
*dev
,
2301 void *data
, struct drm_file
*file_priv
)
2303 struct drm_mode_fb_cmd
*or = data
;
2304 struct drm_mode_fb_cmd2 r
= {};
2305 struct drm_mode_config
*config
= &dev
->mode_config
;
2306 struct drm_framebuffer
*fb
;
2309 /* Use new struct with format internally */
2310 r
.fb_id
= or->fb_id
;
2311 r
.width
= or->width
;
2312 r
.height
= or->height
;
2313 r
.pitches
[0] = or->pitch
;
2314 r
.pixel_format
= drm_mode_legacy_fb_format(or->bpp
, or->depth
);
2315 r
.handles
[0] = or->handle
;
2317 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2320 if ((config
->min_width
> r
.width
) || (r
.width
> config
->max_width
))
2323 if ((config
->min_height
> r
.height
) || (r
.height
> config
->max_height
))
2326 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, &r
);
2328 DRM_DEBUG_KMS("could not create framebuffer\n");
2329 drm_modeset_unlock_all(dev
);
2333 mutex_lock(&file_priv
->fbs_lock
);
2334 or->fb_id
= fb
->base
.id
;
2335 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2336 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2337 mutex_unlock(&file_priv
->fbs_lock
);
2342 static int format_check(const struct drm_mode_fb_cmd2
*r
)
2344 uint32_t format
= r
->pixel_format
& ~DRM_FORMAT_BIG_ENDIAN
;
2348 case DRM_FORMAT_RGB332
:
2349 case DRM_FORMAT_BGR233
:
2350 case DRM_FORMAT_XRGB4444
:
2351 case DRM_FORMAT_XBGR4444
:
2352 case DRM_FORMAT_RGBX4444
:
2353 case DRM_FORMAT_BGRX4444
:
2354 case DRM_FORMAT_ARGB4444
:
2355 case DRM_FORMAT_ABGR4444
:
2356 case DRM_FORMAT_RGBA4444
:
2357 case DRM_FORMAT_BGRA4444
:
2358 case DRM_FORMAT_XRGB1555
:
2359 case DRM_FORMAT_XBGR1555
:
2360 case DRM_FORMAT_RGBX5551
:
2361 case DRM_FORMAT_BGRX5551
:
2362 case DRM_FORMAT_ARGB1555
:
2363 case DRM_FORMAT_ABGR1555
:
2364 case DRM_FORMAT_RGBA5551
:
2365 case DRM_FORMAT_BGRA5551
:
2366 case DRM_FORMAT_RGB565
:
2367 case DRM_FORMAT_BGR565
:
2368 case DRM_FORMAT_RGB888
:
2369 case DRM_FORMAT_BGR888
:
2370 case DRM_FORMAT_XRGB8888
:
2371 case DRM_FORMAT_XBGR8888
:
2372 case DRM_FORMAT_RGBX8888
:
2373 case DRM_FORMAT_BGRX8888
:
2374 case DRM_FORMAT_ARGB8888
:
2375 case DRM_FORMAT_ABGR8888
:
2376 case DRM_FORMAT_RGBA8888
:
2377 case DRM_FORMAT_BGRA8888
:
2378 case DRM_FORMAT_XRGB2101010
:
2379 case DRM_FORMAT_XBGR2101010
:
2380 case DRM_FORMAT_RGBX1010102
:
2381 case DRM_FORMAT_BGRX1010102
:
2382 case DRM_FORMAT_ARGB2101010
:
2383 case DRM_FORMAT_ABGR2101010
:
2384 case DRM_FORMAT_RGBA1010102
:
2385 case DRM_FORMAT_BGRA1010102
:
2386 case DRM_FORMAT_YUYV
:
2387 case DRM_FORMAT_YVYU
:
2388 case DRM_FORMAT_UYVY
:
2389 case DRM_FORMAT_VYUY
:
2390 case DRM_FORMAT_AYUV
:
2391 case DRM_FORMAT_NV12
:
2392 case DRM_FORMAT_NV21
:
2393 case DRM_FORMAT_NV16
:
2394 case DRM_FORMAT_NV61
:
2395 case DRM_FORMAT_NV24
:
2396 case DRM_FORMAT_NV42
:
2397 case DRM_FORMAT_YUV410
:
2398 case DRM_FORMAT_YVU410
:
2399 case DRM_FORMAT_YUV411
:
2400 case DRM_FORMAT_YVU411
:
2401 case DRM_FORMAT_YUV420
:
2402 case DRM_FORMAT_YVU420
:
2403 case DRM_FORMAT_YUV422
:
2404 case DRM_FORMAT_YVU422
:
2405 case DRM_FORMAT_YUV444
:
2406 case DRM_FORMAT_YVU444
:
2413 static int framebuffer_check(const struct drm_mode_fb_cmd2
*r
)
2415 int ret
, hsub
, vsub
, num_planes
, i
;
2417 ret
= format_check(r
);
2419 DRM_DEBUG_KMS("bad framebuffer format 0x%08x\n", r
->pixel_format
);
2423 hsub
= drm_format_horz_chroma_subsampling(r
->pixel_format
);
2424 vsub
= drm_format_vert_chroma_subsampling(r
->pixel_format
);
2425 num_planes
= drm_format_num_planes(r
->pixel_format
);
2427 if (r
->width
== 0 || r
->width
% hsub
) {
2428 DRM_DEBUG_KMS("bad framebuffer width %u\n", r
->height
);
2432 if (r
->height
== 0 || r
->height
% vsub
) {
2433 DRM_DEBUG_KMS("bad framebuffer height %u\n", r
->height
);
2437 for (i
= 0; i
< num_planes
; i
++) {
2438 unsigned int width
= r
->width
/ (i
!= 0 ? hsub
: 1);
2439 unsigned int height
= r
->height
/ (i
!= 0 ? vsub
: 1);
2440 unsigned int cpp
= drm_format_plane_cpp(r
->pixel_format
, i
);
2442 if (!r
->handles
[i
]) {
2443 DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i
);
2447 if ((uint64_t) width
* cpp
> UINT_MAX
)
2450 if ((uint64_t) height
* r
->pitches
[i
] + r
->offsets
[i
] > UINT_MAX
)
2453 if (r
->pitches
[i
] < width
* cpp
) {
2454 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r
->pitches
[i
], i
);
2463 * drm_mode_addfb2 - add an FB to the graphics configuration
2464 * @dev: drm device for the ioctl
2465 * @data: data pointer for the ioctl
2466 * @file_priv: drm file for the ioctl call
2468 * Add a new FB to the specified CRTC, given a user request with format.
2470 * Called by the user via ioctl.
2473 * Zero on success, errno on failure.
2475 int drm_mode_addfb2(struct drm_device
*dev
,
2476 void *data
, struct drm_file
*file_priv
)
2478 struct drm_mode_fb_cmd2
*r
= data
;
2479 struct drm_mode_config
*config
= &dev
->mode_config
;
2480 struct drm_framebuffer
*fb
;
2483 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2486 if (r
->flags
& ~DRM_MODE_FB_INTERLACED
) {
2487 DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r
->flags
);
2491 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
2492 DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
2493 r
->width
, config
->min_width
, config
->max_width
);
2496 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
2497 DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
2498 r
->height
, config
->min_height
, config
->max_height
);
2502 ret
= framebuffer_check(r
);
2506 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
2508 DRM_DEBUG_KMS("could not create framebuffer\n");
2509 drm_modeset_unlock_all(dev
);
2513 mutex_lock(&file_priv
->fbs_lock
);
2514 r
->fb_id
= fb
->base
.id
;
2515 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2516 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2517 mutex_unlock(&file_priv
->fbs_lock
);
2524 * drm_mode_rmfb - remove an FB from the configuration
2525 * @dev: drm device for the ioctl
2526 * @data: data pointer for the ioctl
2527 * @file_priv: drm file for the ioctl call
2529 * Remove the FB specified by the user.
2531 * Called by the user via ioctl.
2534 * Zero on success, errno on failure.
2536 int drm_mode_rmfb(struct drm_device
*dev
,
2537 void *data
, struct drm_file
*file_priv
)
2539 struct drm_framebuffer
*fb
= NULL
;
2540 struct drm_framebuffer
*fbl
= NULL
;
2541 uint32_t *id
= data
;
2544 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2547 mutex_lock(&file_priv
->fbs_lock
);
2548 mutex_lock(&dev
->mode_config
.fb_lock
);
2549 fb
= __drm_framebuffer_lookup(dev
, *id
);
2553 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
2559 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2560 __drm_framebuffer_unregister(dev
, fb
);
2562 list_del_init(&fb
->filp_head
);
2563 mutex_unlock(&dev
->mode_config
.fb_lock
);
2564 mutex_unlock(&file_priv
->fbs_lock
);
2566 drm_framebuffer_remove(fb
);
2571 mutex_unlock(&dev
->mode_config
.fb_lock
);
2572 mutex_unlock(&file_priv
->fbs_lock
);
2578 * drm_mode_getfb - get FB info
2579 * @dev: drm device for the ioctl
2580 * @data: data pointer for the ioctl
2581 * @file_priv: drm file for the ioctl call
2583 * Lookup the FB given its ID and return info about it.
2585 * Called by the user via ioctl.
2588 * Zero on success, errno on failure.
2590 int drm_mode_getfb(struct drm_device
*dev
,
2591 void *data
, struct drm_file
*file_priv
)
2593 struct drm_mode_fb_cmd
*r
= data
;
2594 struct drm_framebuffer
*fb
;
2597 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2600 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2604 r
->height
= fb
->height
;
2605 r
->width
= fb
->width
;
2606 r
->depth
= fb
->depth
;
2607 r
->bpp
= fb
->bits_per_pixel
;
2608 r
->pitch
= fb
->pitches
[0];
2609 if (fb
->funcs
->create_handle
)
2610 ret
= fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
2614 drm_framebuffer_unreference(fb
);
2619 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2620 void *data
, struct drm_file
*file_priv
)
2622 struct drm_clip_rect __user
*clips_ptr
;
2623 struct drm_clip_rect
*clips
= NULL
;
2624 struct drm_mode_fb_dirty_cmd
*r
= data
;
2625 struct drm_framebuffer
*fb
;
2630 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2633 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2637 num_clips
= r
->num_clips
;
2638 clips_ptr
= (struct drm_clip_rect __user
*)(unsigned long)r
->clips_ptr
;
2640 if (!num_clips
!= !clips_ptr
) {
2645 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
2647 /* If userspace annotates copy, clips must come in pairs */
2648 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
2653 if (num_clips
&& clips_ptr
) {
2654 if (num_clips
< 0 || num_clips
> DRM_MODE_FB_DIRTY_MAX_CLIPS
) {
2658 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
2664 ret
= copy_from_user(clips
, clips_ptr
,
2665 num_clips
* sizeof(*clips
));
2672 if (fb
->funcs
->dirty
) {
2673 drm_modeset_lock_all(dev
);
2674 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
2676 drm_modeset_unlock_all(dev
);
2684 drm_framebuffer_unreference(fb
);
2691 * drm_fb_release - remove and free the FBs on this file
2692 * @priv: drm file for the ioctl
2694 * Destroy all the FBs associated with @filp.
2696 * Called by the user via ioctl.
2699 * Zero on success, errno on failure.
2701 void drm_fb_release(struct drm_file
*priv
)
2703 struct drm_device
*dev
= priv
->minor
->dev
;
2704 struct drm_framebuffer
*fb
, *tfb
;
2706 mutex_lock(&priv
->fbs_lock
);
2707 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
2709 mutex_lock(&dev
->mode_config
.fb_lock
);
2710 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2711 __drm_framebuffer_unregister(dev
, fb
);
2712 mutex_unlock(&dev
->mode_config
.fb_lock
);
2714 list_del_init(&fb
->filp_head
);
2716 /* This will also drop the fpriv->fbs reference. */
2717 drm_framebuffer_remove(fb
);
2719 mutex_unlock(&priv
->fbs_lock
);
2723 * drm_mode_attachmode - add a mode to the user mode list
2725 * @connector: connector to add the mode to
2726 * @mode: mode to add
2728 * Add @mode to @connector's user mode list.
2730 static void drm_mode_attachmode(struct drm_device
*dev
,
2731 struct drm_connector
*connector
,
2732 struct drm_display_mode
*mode
)
2734 list_add_tail(&mode
->head
, &connector
->user_modes
);
2737 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
2738 const struct drm_display_mode
*mode
)
2740 struct drm_connector
*connector
;
2742 struct drm_display_mode
*dup_mode
, *next
;
2745 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2746 if (!connector
->encoder
)
2748 if (connector
->encoder
->crtc
== crtc
) {
2749 dup_mode
= drm_mode_duplicate(dev
, mode
);
2754 list_add_tail(&dup_mode
->head
, &list
);
2758 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2759 if (!connector
->encoder
)
2761 if (connector
->encoder
->crtc
== crtc
)
2762 list_move_tail(list
.next
, &connector
->user_modes
);
2765 WARN_ON(!list_empty(&list
));
2768 list_for_each_entry_safe(dup_mode
, next
, &list
, head
)
2769 drm_mode_destroy(dev
, dup_mode
);
2773 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
2775 static int drm_mode_detachmode(struct drm_device
*dev
,
2776 struct drm_connector
*connector
,
2777 struct drm_display_mode
*mode
)
2781 struct drm_display_mode
*match_mode
, *t
;
2783 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
2784 if (drm_mode_equal(match_mode
, mode
)) {
2785 list_del(&match_mode
->head
);
2786 drm_mode_destroy(dev
, match_mode
);
2798 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
2800 struct drm_connector
*connector
;
2802 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2803 drm_mode_detachmode(dev
, connector
, mode
);
2807 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
2810 * drm_fb_attachmode - Attach a user mode to an connector
2811 * @dev: drm device for the ioctl
2812 * @data: data pointer for the ioctl
2813 * @file_priv: drm file for the ioctl call
2815 * This attaches a user specified mode to an connector.
2816 * Called by the user via ioctl.
2819 * Zero on success, errno on failure.
2821 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
2822 void *data
, struct drm_file
*file_priv
)
2824 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2825 struct drm_connector
*connector
;
2826 struct drm_display_mode
*mode
;
2827 struct drm_mode_object
*obj
;
2828 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2831 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2834 drm_modeset_lock_all(dev
);
2836 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2841 connector
= obj_to_connector(obj
);
2843 mode
= drm_mode_create(dev
);
2849 ret
= drm_crtc_convert_umode(mode
, umode
);
2851 DRM_DEBUG_KMS("Invalid mode\n");
2852 drm_mode_destroy(dev
, mode
);
2856 drm_mode_attachmode(dev
, connector
, mode
);
2858 drm_modeset_unlock_all(dev
);
2864 * drm_fb_detachmode - Detach a user specified mode from an connector
2865 * @dev: drm device for the ioctl
2866 * @data: data pointer for the ioctl
2867 * @file_priv: drm file for the ioctl call
2869 * Called by the user via ioctl.
2872 * Zero on success, errno on failure.
2874 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
2875 void *data
, struct drm_file
*file_priv
)
2877 struct drm_mode_object
*obj
;
2878 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2879 struct drm_connector
*connector
;
2880 struct drm_display_mode mode
;
2881 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2884 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2887 drm_modeset_lock_all(dev
);
2889 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2894 connector
= obj_to_connector(obj
);
2896 ret
= drm_crtc_convert_umode(&mode
, umode
);
2898 DRM_DEBUG_KMS("Invalid mode\n");
2902 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
2904 drm_modeset_unlock_all(dev
);
2908 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2909 const char *name
, int num_values
)
2911 struct drm_property
*property
= NULL
;
2914 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2919 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2920 if (!property
->values
)
2924 ret
= drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2928 property
->flags
= flags
;
2929 property
->num_values
= num_values
;
2930 INIT_LIST_HEAD(&property
->enum_blob_list
);
2933 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2934 property
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2937 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2940 kfree(property
->values
);
2944 EXPORT_SYMBOL(drm_property_create
);
2946 struct drm_property
*drm_property_create_enum(struct drm_device
*dev
, int flags
,
2948 const struct drm_prop_enum_list
*props
,
2951 struct drm_property
*property
;
2954 flags
|= DRM_MODE_PROP_ENUM
;
2956 property
= drm_property_create(dev
, flags
, name
, num_values
);
2960 for (i
= 0; i
< num_values
; i
++) {
2961 ret
= drm_property_add_enum(property
, i
,
2965 drm_property_destroy(dev
, property
);
2972 EXPORT_SYMBOL(drm_property_create_enum
);
2974 struct drm_property
*drm_property_create_bitmask(struct drm_device
*dev
,
2975 int flags
, const char *name
,
2976 const struct drm_prop_enum_list
*props
,
2979 struct drm_property
*property
;
2982 flags
|= DRM_MODE_PROP_BITMASK
;
2984 property
= drm_property_create(dev
, flags
, name
, num_values
);
2988 for (i
= 0; i
< num_values
; i
++) {
2989 ret
= drm_property_add_enum(property
, i
,
2993 drm_property_destroy(dev
, property
);
3000 EXPORT_SYMBOL(drm_property_create_bitmask
);
3002 struct drm_property
*drm_property_create_range(struct drm_device
*dev
, int flags
,
3004 uint64_t min
, uint64_t max
)
3006 struct drm_property
*property
;
3008 flags
|= DRM_MODE_PROP_RANGE
;
3010 property
= drm_property_create(dev
, flags
, name
, 2);
3014 property
->values
[0] = min
;
3015 property
->values
[1] = max
;
3019 EXPORT_SYMBOL(drm_property_create_range
);
3021 int drm_property_add_enum(struct drm_property
*property
, int index
,
3022 uint64_t value
, const char *name
)
3024 struct drm_property_enum
*prop_enum
;
3026 if (!(property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)))
3030 * Bitmask enum properties have the additional constraint of values
3033 if ((property
->flags
& DRM_MODE_PROP_BITMASK
) && (value
> 63))
3036 if (!list_empty(&property
->enum_blob_list
)) {
3037 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
3038 if (prop_enum
->value
== value
) {
3039 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
3040 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
3046 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
3050 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
3051 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
3052 prop_enum
->value
= value
;
3054 property
->values
[index
] = value
;
3055 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
3058 EXPORT_SYMBOL(drm_property_add_enum
);
3060 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
3062 struct drm_property_enum
*prop_enum
, *pt
;
3064 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
3065 list_del(&prop_enum
->head
);
3069 if (property
->num_values
)
3070 kfree(property
->values
);
3071 drm_mode_object_put(dev
, &property
->base
);
3072 list_del(&property
->head
);
3075 EXPORT_SYMBOL(drm_property_destroy
);
3077 void drm_object_attach_property(struct drm_mode_object
*obj
,
3078 struct drm_property
*property
,
3081 int count
= obj
->properties
->count
;
3083 if (count
== DRM_OBJECT_MAX_PROPERTY
) {
3084 WARN(1, "Failed to attach object property (type: 0x%x). Please "
3085 "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time "
3086 "you see this message on the same object type.\n",
3091 obj
->properties
->ids
[count
] = property
->base
.id
;
3092 obj
->properties
->values
[count
] = init_val
;
3093 obj
->properties
->count
++;
3095 EXPORT_SYMBOL(drm_object_attach_property
);
3097 int drm_object_property_set_value(struct drm_mode_object
*obj
,
3098 struct drm_property
*property
, uint64_t val
)
3102 for (i
= 0; i
< obj
->properties
->count
; i
++) {
3103 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
3104 obj
->properties
->values
[i
] = val
;
3111 EXPORT_SYMBOL(drm_object_property_set_value
);
3113 int drm_object_property_get_value(struct drm_mode_object
*obj
,
3114 struct drm_property
*property
, uint64_t *val
)
3118 for (i
= 0; i
< obj
->properties
->count
; i
++) {
3119 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
3120 *val
= obj
->properties
->values
[i
];
3127 EXPORT_SYMBOL(drm_object_property_get_value
);
3129 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
3130 void *data
, struct drm_file
*file_priv
)
3132 struct drm_mode_object
*obj
;
3133 struct drm_mode_get_property
*out_resp
= data
;
3134 struct drm_property
*property
;
3137 int value_count
= 0;
3140 struct drm_property_enum
*prop_enum
;
3141 struct drm_mode_property_enum __user
*enum_ptr
;
3142 struct drm_property_blob
*prop_blob
;
3143 uint32_t __user
*blob_id_ptr
;
3144 uint64_t __user
*values_ptr
;
3145 uint32_t __user
*blob_length_ptr
;
3147 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3150 drm_modeset_lock_all(dev
);
3151 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
3156 property
= obj_to_property(obj
);
3158 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
3159 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
3161 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3162 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
3166 value_count
= property
->num_values
;
3168 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
3169 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
3170 out_resp
->flags
= property
->flags
;
3172 if ((out_resp
->count_values
>= value_count
) && value_count
) {
3173 values_ptr
= (uint64_t __user
*)(unsigned long)out_resp
->values_ptr
;
3174 for (i
= 0; i
< value_count
; i
++) {
3175 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
3181 out_resp
->count_values
= value_count
;
3183 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
3184 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
3186 enum_ptr
= (struct drm_mode_property_enum __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3187 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
3189 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
3194 if (copy_to_user(&enum_ptr
[copied
].name
,
3195 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
3202 out_resp
->count_enum_blobs
= enum_count
;
3205 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3206 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
3208 blob_id_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3209 blob_length_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->values_ptr
;
3211 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
3212 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
3217 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
3225 out_resp
->count_enum_blobs
= blob_count
;
3228 drm_modeset_unlock_all(dev
);
3232 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
3235 struct drm_property_blob
*blob
;
3238 if (!length
|| !data
)
3241 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
3245 ret
= drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
3251 blob
->length
= length
;
3253 memcpy(blob
->data
, data
, length
);
3255 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
3259 static void drm_property_destroy_blob(struct drm_device
*dev
,
3260 struct drm_property_blob
*blob
)
3262 drm_mode_object_put(dev
, &blob
->base
);
3263 list_del(&blob
->head
);
3267 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
3268 void *data
, struct drm_file
*file_priv
)
3270 struct drm_mode_object
*obj
;
3271 struct drm_mode_get_blob
*out_resp
= data
;
3272 struct drm_property_blob
*blob
;
3274 void __user
*blob_ptr
;
3276 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3279 drm_modeset_lock_all(dev
);
3280 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
3285 blob
= obj_to_blob(obj
);
3287 if (out_resp
->length
== blob
->length
) {
3288 blob_ptr
= (void __user
*)(unsigned long)out_resp
->data
;
3289 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
3294 out_resp
->length
= blob
->length
;
3297 drm_modeset_unlock_all(dev
);
3301 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
3304 struct drm_device
*dev
= connector
->dev
;
3307 if (connector
->edid_blob_ptr
)
3308 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
3310 /* Delete edid, when there is none. */
3312 connector
->edid_blob_ptr
= NULL
;
3313 ret
= drm_object_property_set_value(&connector
->base
, dev
->mode_config
.edid_property
, 0);
3317 size
= EDID_LENGTH
* (1 + edid
->extensions
);
3318 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
3320 if (!connector
->edid_blob_ptr
)
3323 ret
= drm_object_property_set_value(&connector
->base
,
3324 dev
->mode_config
.edid_property
,
3325 connector
->edid_blob_ptr
->base
.id
);
3329 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
3331 static bool drm_property_change_is_valid(struct drm_property
*property
,
3334 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
3336 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
3337 if (value
< property
->values
[0] || value
> property
->values
[1])
3340 } else if (property
->flags
& DRM_MODE_PROP_BITMASK
) {
3342 uint64_t valid_mask
= 0;
3343 for (i
= 0; i
< property
->num_values
; i
++)
3344 valid_mask
|= (1ULL << property
->values
[i
]);
3345 return !(value
& ~valid_mask
);
3346 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3347 /* Only the driver knows */
3351 for (i
= 0; i
< property
->num_values
; i
++)
3352 if (property
->values
[i
] == value
)
3358 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
3359 void *data
, struct drm_file
*file_priv
)
3361 struct drm_mode_connector_set_property
*conn_set_prop
= data
;
3362 struct drm_mode_obj_set_property obj_set_prop
= {
3363 .value
= conn_set_prop
->value
,
3364 .prop_id
= conn_set_prop
->prop_id
,
3365 .obj_id
= conn_set_prop
->connector_id
,
3366 .obj_type
= DRM_MODE_OBJECT_CONNECTOR
3369 /* It does all the locking and checking we need */
3370 return drm_mode_obj_set_property_ioctl(dev
, &obj_set_prop
, file_priv
);
3373 static int drm_mode_connector_set_obj_prop(struct drm_mode_object
*obj
,
3374 struct drm_property
*property
,
3378 struct drm_connector
*connector
= obj_to_connector(obj
);
3380 /* Do DPMS ourselves */
3381 if (property
== connector
->dev
->mode_config
.dpms_property
) {
3382 if (connector
->funcs
->dpms
)
3383 (*connector
->funcs
->dpms
)(connector
, (int)value
);
3385 } else if (connector
->funcs
->set_property
)
3386 ret
= connector
->funcs
->set_property(connector
, property
, value
);
3388 /* store the property value if successful */
3390 drm_object_property_set_value(&connector
->base
, property
, value
);
3394 static int drm_mode_crtc_set_obj_prop(struct drm_mode_object
*obj
,
3395 struct drm_property
*property
,
3399 struct drm_crtc
*crtc
= obj_to_crtc(obj
);
3401 if (crtc
->funcs
->set_property
)
3402 ret
= crtc
->funcs
->set_property(crtc
, property
, value
);
3404 drm_object_property_set_value(obj
, property
, value
);
3409 static int drm_mode_plane_set_obj_prop(struct drm_mode_object
*obj
,
3410 struct drm_property
*property
,
3414 struct drm_plane
*plane
= obj_to_plane(obj
);
3416 if (plane
->funcs
->set_property
)
3417 ret
= plane
->funcs
->set_property(plane
, property
, value
);
3419 drm_object_property_set_value(obj
, property
, value
);
3424 int drm_mode_obj_get_properties_ioctl(struct drm_device
*dev
, void *data
,
3425 struct drm_file
*file_priv
)
3427 struct drm_mode_obj_get_properties
*arg
= data
;
3428 struct drm_mode_object
*obj
;
3432 int props_count
= 0;
3433 uint32_t __user
*props_ptr
;
3434 uint64_t __user
*prop_values_ptr
;
3436 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3439 drm_modeset_lock_all(dev
);
3441 obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3446 if (!obj
->properties
) {
3451 props_count
= obj
->properties
->count
;
3453 /* This ioctl is called twice, once to determine how much space is
3454 * needed, and the 2nd time to fill it. */
3455 if ((arg
->count_props
>= props_count
) && props_count
) {
3457 props_ptr
= (uint32_t __user
*)(unsigned long)(arg
->props_ptr
);
3458 prop_values_ptr
= (uint64_t __user
*)(unsigned long)
3459 (arg
->prop_values_ptr
);
3460 for (i
= 0; i
< props_count
; i
++) {
3461 if (put_user(obj
->properties
->ids
[i
],
3462 props_ptr
+ copied
)) {
3466 if (put_user(obj
->properties
->values
[i
],
3467 prop_values_ptr
+ copied
)) {
3474 arg
->count_props
= props_count
;
3476 drm_modeset_unlock_all(dev
);
3480 int drm_mode_obj_set_property_ioctl(struct drm_device
*dev
, void *data
,
3481 struct drm_file
*file_priv
)
3483 struct drm_mode_obj_set_property
*arg
= data
;
3484 struct drm_mode_object
*arg_obj
;
3485 struct drm_mode_object
*prop_obj
;
3486 struct drm_property
*property
;
3490 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3493 drm_modeset_lock_all(dev
);
3495 arg_obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3498 if (!arg_obj
->properties
)
3501 for (i
= 0; i
< arg_obj
->properties
->count
; i
++)
3502 if (arg_obj
->properties
->ids
[i
] == arg
->prop_id
)
3505 if (i
== arg_obj
->properties
->count
)
3508 prop_obj
= drm_mode_object_find(dev
, arg
->prop_id
,
3509 DRM_MODE_OBJECT_PROPERTY
);
3512 property
= obj_to_property(prop_obj
);
3514 if (!drm_property_change_is_valid(property
, arg
->value
))
3517 switch (arg_obj
->type
) {
3518 case DRM_MODE_OBJECT_CONNECTOR
:
3519 ret
= drm_mode_connector_set_obj_prop(arg_obj
, property
,
3522 case DRM_MODE_OBJECT_CRTC
:
3523 ret
= drm_mode_crtc_set_obj_prop(arg_obj
, property
, arg
->value
);
3525 case DRM_MODE_OBJECT_PLANE
:
3526 ret
= drm_mode_plane_set_obj_prop(arg_obj
, property
, arg
->value
);
3531 drm_modeset_unlock_all(dev
);
3535 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
3536 struct drm_encoder
*encoder
)
3540 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3541 if (connector
->encoder_ids
[i
] == 0) {
3542 connector
->encoder_ids
[i
] = encoder
->base
.id
;
3548 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
3550 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
3551 struct drm_encoder
*encoder
)
3554 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3555 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
3556 connector
->encoder_ids
[i
] = 0;
3557 if (connector
->encoder
== encoder
)
3558 connector
->encoder
= NULL
;
3563 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
3565 int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
3568 crtc
->gamma_size
= gamma_size
;
3570 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
3571 if (!crtc
->gamma_store
) {
3572 crtc
->gamma_size
= 0;
3578 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
3580 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
3581 void *data
, struct drm_file
*file_priv
)
3583 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3584 struct drm_mode_object
*obj
;
3585 struct drm_crtc
*crtc
;
3586 void *r_base
, *g_base
, *b_base
;
3590 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3593 drm_modeset_lock_all(dev
);
3594 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3599 crtc
= obj_to_crtc(obj
);
3601 if (crtc
->funcs
->gamma_set
== NULL
) {
3606 /* memcpy into gamma store */
3607 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3612 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3613 r_base
= crtc
->gamma_store
;
3614 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
3619 g_base
= r_base
+ size
;
3620 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
3625 b_base
= g_base
+ size
;
3626 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
3631 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
3634 drm_modeset_unlock_all(dev
);
3639 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
3640 void *data
, struct drm_file
*file_priv
)
3642 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3643 struct drm_mode_object
*obj
;
3644 struct drm_crtc
*crtc
;
3645 void *r_base
, *g_base
, *b_base
;
3649 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3652 drm_modeset_lock_all(dev
);
3653 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3658 crtc
= obj_to_crtc(obj
);
3660 /* memcpy into gamma store */
3661 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3666 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3667 r_base
= crtc
->gamma_store
;
3668 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
3673 g_base
= r_base
+ size
;
3674 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
3679 b_base
= g_base
+ size
;
3680 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
3685 drm_modeset_unlock_all(dev
);
3689 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
3690 void *data
, struct drm_file
*file_priv
)
3692 struct drm_mode_crtc_page_flip
*page_flip
= data
;
3693 struct drm_mode_object
*obj
;
3694 struct drm_crtc
*crtc
;
3695 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
3696 struct drm_pending_vblank_event
*e
= NULL
;
3697 unsigned long flags
;
3698 int hdisplay
, vdisplay
;
3701 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
3702 page_flip
->reserved
!= 0)
3705 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3708 crtc
= obj_to_crtc(obj
);
3710 mutex_lock(&crtc
->mutex
);
3711 if (crtc
->fb
== NULL
) {
3712 /* The framebuffer is currently unbound, presumably
3713 * due to a hotplug event, that userspace has not
3720 if (crtc
->funcs
->page_flip
== NULL
)
3723 fb
= drm_framebuffer_lookup(dev
, page_flip
->fb_id
);
3727 hdisplay
= crtc
->mode
.hdisplay
;
3728 vdisplay
= crtc
->mode
.vdisplay
;
3730 if (crtc
->invert_dimensions
)
3731 swap(hdisplay
, vdisplay
);
3733 if (hdisplay
> fb
->width
||
3734 vdisplay
> fb
->height
||
3735 crtc
->x
> fb
->width
- hdisplay
||
3736 crtc
->y
> fb
->height
- vdisplay
) {
3737 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
3738 fb
->width
, fb
->height
, hdisplay
, vdisplay
, crtc
->x
, crtc
->y
,
3739 crtc
->invert_dimensions
? " (inverted)" : "");
3744 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3746 spin_lock_irqsave(&dev
->event_lock
, flags
);
3747 if (file_priv
->event_space
< sizeof e
->event
) {
3748 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3751 file_priv
->event_space
-= sizeof e
->event
;
3752 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3754 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
3756 spin_lock_irqsave(&dev
->event_lock
, flags
);
3757 file_priv
->event_space
+= sizeof e
->event
;
3758 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3762 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
3763 e
->event
.base
.length
= sizeof e
->event
;
3764 e
->event
.user_data
= page_flip
->user_data
;
3765 e
->base
.event
= &e
->event
.base
;
3766 e
->base
.file_priv
= file_priv
;
3768 (void (*) (struct drm_pending_event
*)) kfree
;
3772 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
);
3774 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3775 spin_lock_irqsave(&dev
->event_lock
, flags
);
3776 file_priv
->event_space
+= sizeof e
->event
;
3777 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3780 /* Keep the old fb, don't unref it. */
3784 * Warn if the driver hasn't properly updated the crtc->fb
3785 * field to reflect that the new framebuffer is now used.
3786 * Failing to do so will screw with the reference counting
3789 WARN_ON(crtc
->fb
!= fb
);
3790 /* Unref only the old framebuffer. */
3796 drm_framebuffer_unreference(fb
);
3798 drm_framebuffer_unreference(old_fb
);
3799 mutex_unlock(&crtc
->mutex
);
3804 void drm_mode_config_reset(struct drm_device
*dev
)
3806 struct drm_crtc
*crtc
;
3807 struct drm_encoder
*encoder
;
3808 struct drm_connector
*connector
;
3810 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
3811 if (crtc
->funcs
->reset
)
3812 crtc
->funcs
->reset(crtc
);
3814 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
3815 if (encoder
->funcs
->reset
)
3816 encoder
->funcs
->reset(encoder
);
3818 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
3819 connector
->status
= connector_status_unknown
;
3821 if (connector
->funcs
->reset
)
3822 connector
->funcs
->reset(connector
);
3825 EXPORT_SYMBOL(drm_mode_config_reset
);
3827 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
3828 void *data
, struct drm_file
*file_priv
)
3830 struct drm_mode_create_dumb
*args
= data
;
3832 if (!dev
->driver
->dumb_create
)
3834 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
3837 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
3838 void *data
, struct drm_file
*file_priv
)
3840 struct drm_mode_map_dumb
*args
= data
;
3842 /* call driver ioctl to get mmap offset */
3843 if (!dev
->driver
->dumb_map_offset
)
3846 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
3849 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
3850 void *data
, struct drm_file
*file_priv
)
3852 struct drm_mode_destroy_dumb
*args
= data
;
3854 if (!dev
->driver
->dumb_destroy
)
3857 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
3861 * Just need to support RGB formats here for compat with code that doesn't
3862 * use pixel formats directly yet.
3864 void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
3869 case DRM_FORMAT_RGB332
:
3870 case DRM_FORMAT_BGR233
:
3874 case DRM_FORMAT_XRGB1555
:
3875 case DRM_FORMAT_XBGR1555
:
3876 case DRM_FORMAT_RGBX5551
:
3877 case DRM_FORMAT_BGRX5551
:
3878 case DRM_FORMAT_ARGB1555
:
3879 case DRM_FORMAT_ABGR1555
:
3880 case DRM_FORMAT_RGBA5551
:
3881 case DRM_FORMAT_BGRA5551
:
3885 case DRM_FORMAT_RGB565
:
3886 case DRM_FORMAT_BGR565
:
3890 case DRM_FORMAT_RGB888
:
3891 case DRM_FORMAT_BGR888
:
3895 case DRM_FORMAT_XRGB8888
:
3896 case DRM_FORMAT_XBGR8888
:
3897 case DRM_FORMAT_RGBX8888
:
3898 case DRM_FORMAT_BGRX8888
:
3902 case DRM_FORMAT_XRGB2101010
:
3903 case DRM_FORMAT_XBGR2101010
:
3904 case DRM_FORMAT_RGBX1010102
:
3905 case DRM_FORMAT_BGRX1010102
:
3906 case DRM_FORMAT_ARGB2101010
:
3907 case DRM_FORMAT_ABGR2101010
:
3908 case DRM_FORMAT_RGBA1010102
:
3909 case DRM_FORMAT_BGRA1010102
:
3913 case DRM_FORMAT_ARGB8888
:
3914 case DRM_FORMAT_ABGR8888
:
3915 case DRM_FORMAT_RGBA8888
:
3916 case DRM_FORMAT_BGRA8888
:
3921 DRM_DEBUG_KMS("unsupported pixel format\n");
3927 EXPORT_SYMBOL(drm_fb_get_bpp_depth
);
3930 * drm_format_num_planes - get the number of planes for format
3931 * @format: pixel format (DRM_FORMAT_*)
3934 * The number of planes used by the specified pixel format.
3936 int drm_format_num_planes(uint32_t format
)
3939 case DRM_FORMAT_YUV410
:
3940 case DRM_FORMAT_YVU410
:
3941 case DRM_FORMAT_YUV411
:
3942 case DRM_FORMAT_YVU411
:
3943 case DRM_FORMAT_YUV420
:
3944 case DRM_FORMAT_YVU420
:
3945 case DRM_FORMAT_YUV422
:
3946 case DRM_FORMAT_YVU422
:
3947 case DRM_FORMAT_YUV444
:
3948 case DRM_FORMAT_YVU444
:
3950 case DRM_FORMAT_NV12
:
3951 case DRM_FORMAT_NV21
:
3952 case DRM_FORMAT_NV16
:
3953 case DRM_FORMAT_NV61
:
3954 case DRM_FORMAT_NV24
:
3955 case DRM_FORMAT_NV42
:
3961 EXPORT_SYMBOL(drm_format_num_planes
);
3964 * drm_format_plane_cpp - determine the bytes per pixel value
3965 * @format: pixel format (DRM_FORMAT_*)
3966 * @plane: plane index
3969 * The bytes per pixel value for the specified plane.
3971 int drm_format_plane_cpp(uint32_t format
, int plane
)
3976 if (plane
>= drm_format_num_planes(format
))
3980 case DRM_FORMAT_YUYV
:
3981 case DRM_FORMAT_YVYU
:
3982 case DRM_FORMAT_UYVY
:
3983 case DRM_FORMAT_VYUY
:
3985 case DRM_FORMAT_NV12
:
3986 case DRM_FORMAT_NV21
:
3987 case DRM_FORMAT_NV16
:
3988 case DRM_FORMAT_NV61
:
3989 case DRM_FORMAT_NV24
:
3990 case DRM_FORMAT_NV42
:
3991 return plane
? 2 : 1;
3992 case DRM_FORMAT_YUV410
:
3993 case DRM_FORMAT_YVU410
:
3994 case DRM_FORMAT_YUV411
:
3995 case DRM_FORMAT_YVU411
:
3996 case DRM_FORMAT_YUV420
:
3997 case DRM_FORMAT_YVU420
:
3998 case DRM_FORMAT_YUV422
:
3999 case DRM_FORMAT_YVU422
:
4000 case DRM_FORMAT_YUV444
:
4001 case DRM_FORMAT_YVU444
:
4004 drm_fb_get_bpp_depth(format
, &depth
, &bpp
);
4008 EXPORT_SYMBOL(drm_format_plane_cpp
);
4011 * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
4012 * @format: pixel format (DRM_FORMAT_*)
4015 * The horizontal chroma subsampling factor for the
4016 * specified pixel format.
4018 int drm_format_horz_chroma_subsampling(uint32_t format
)
4021 case DRM_FORMAT_YUV411
:
4022 case DRM_FORMAT_YVU411
:
4023 case DRM_FORMAT_YUV410
:
4024 case DRM_FORMAT_YVU410
:
4026 case DRM_FORMAT_YUYV
:
4027 case DRM_FORMAT_YVYU
:
4028 case DRM_FORMAT_UYVY
:
4029 case DRM_FORMAT_VYUY
:
4030 case DRM_FORMAT_NV12
:
4031 case DRM_FORMAT_NV21
:
4032 case DRM_FORMAT_NV16
:
4033 case DRM_FORMAT_NV61
:
4034 case DRM_FORMAT_YUV422
:
4035 case DRM_FORMAT_YVU422
:
4036 case DRM_FORMAT_YUV420
:
4037 case DRM_FORMAT_YVU420
:
4043 EXPORT_SYMBOL(drm_format_horz_chroma_subsampling
);
4046 * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
4047 * @format: pixel format (DRM_FORMAT_*)
4050 * The vertical chroma subsampling factor for the
4051 * specified pixel format.
4053 int drm_format_vert_chroma_subsampling(uint32_t format
)
4056 case DRM_FORMAT_YUV410
:
4057 case DRM_FORMAT_YVU410
:
4059 case DRM_FORMAT_YUV420
:
4060 case DRM_FORMAT_YVU420
:
4061 case DRM_FORMAT_NV12
:
4062 case DRM_FORMAT_NV21
:
4068 EXPORT_SYMBOL(drm_format_vert_chroma_subsampling
);