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/ctype.h>
33 #include <linux/list.h>
34 #include <linux/slab.h>
35 #include <linux/export.h>
37 #include <drm/drm_crtc.h>
38 #include <drm/drm_edid.h>
39 #include <drm/drm_fourcc.h>
42 * drm_modeset_lock_all - take all modeset locks
45 * This function takes all modeset locks, suitable where a more fine-grained
46 * scheme isn't (yet) implemented.
48 void drm_modeset_lock_all(struct drm_device
*dev
)
50 struct drm_crtc
*crtc
;
52 mutex_lock(&dev
->mode_config
.mutex
);
54 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
55 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
57 EXPORT_SYMBOL(drm_modeset_lock_all
);
60 * drm_modeset_unlock_all - drop all modeset locks
63 void drm_modeset_unlock_all(struct drm_device
*dev
)
65 struct drm_crtc
*crtc
;
67 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
68 mutex_unlock(&crtc
->mutex
);
70 mutex_unlock(&dev
->mode_config
.mutex
);
72 EXPORT_SYMBOL(drm_modeset_unlock_all
);
75 * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked
78 void drm_warn_on_modeset_not_all_locked(struct drm_device
*dev
)
80 struct drm_crtc
*crtc
;
82 /* Locking is currently fubar in the panic handler. */
86 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
87 WARN_ON(!mutex_is_locked(&crtc
->mutex
));
89 WARN_ON(!mutex_is_locked(&dev
->mode_config
.mutex
));
91 EXPORT_SYMBOL(drm_warn_on_modeset_not_all_locked
);
93 /* Avoid boilerplate. I'm tired of typing. */
94 #define DRM_ENUM_NAME_FN(fnname, list) \
95 const char *fnname(int val) \
98 for (i = 0; i < ARRAY_SIZE(list); i++) { \
99 if (list[i].type == val) \
100 return list[i].name; \
102 return "(unknown)"; \
108 static const struct drm_prop_enum_list drm_dpms_enum_list
[] =
109 { { DRM_MODE_DPMS_ON
, "On" },
110 { DRM_MODE_DPMS_STANDBY
, "Standby" },
111 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
112 { DRM_MODE_DPMS_OFF
, "Off" }
115 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
118 * Optional properties
120 static const struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
122 { DRM_MODE_SCALE_NONE
, "None" },
123 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
124 { DRM_MODE_SCALE_CENTER
, "Center" },
125 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
129 * Non-global properties, but "required" for certain connectors.
131 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
133 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
134 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
135 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
138 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
140 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
142 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
143 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
144 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
147 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
148 drm_dvi_i_subconnector_enum_list
)
150 static const struct drm_prop_enum_list drm_tv_select_enum_list
[] =
152 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
153 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
154 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
155 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
156 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
159 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
161 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
163 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
164 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
165 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
166 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
167 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
170 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
171 drm_tv_subconnector_enum_list
)
173 static const struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
174 { DRM_MODE_DIRTY_OFF
, "Off" },
175 { DRM_MODE_DIRTY_ON
, "On" },
176 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
179 struct drm_conn_prop_enum_list
{
186 * Connector and encoder types.
188 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
189 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown" },
190 { DRM_MODE_CONNECTOR_VGA
, "VGA" },
191 { DRM_MODE_CONNECTOR_DVII
, "DVI-I" },
192 { DRM_MODE_CONNECTOR_DVID
, "DVI-D" },
193 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A" },
194 { DRM_MODE_CONNECTOR_Composite
, "Composite" },
195 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO" },
196 { DRM_MODE_CONNECTOR_LVDS
, "LVDS" },
197 { DRM_MODE_CONNECTOR_Component
, "Component" },
198 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN" },
199 { DRM_MODE_CONNECTOR_DisplayPort
, "DP" },
200 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A" },
201 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B" },
202 { DRM_MODE_CONNECTOR_TV
, "TV" },
203 { DRM_MODE_CONNECTOR_eDP
, "eDP" },
204 { DRM_MODE_CONNECTOR_VIRTUAL
, "Virtual" },
207 static const struct drm_prop_enum_list drm_encoder_enum_list
[] =
208 { { DRM_MODE_ENCODER_NONE
, "None" },
209 { DRM_MODE_ENCODER_DAC
, "DAC" },
210 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
211 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
212 { DRM_MODE_ENCODER_TVDAC
, "TV" },
213 { DRM_MODE_ENCODER_VIRTUAL
, "Virtual" },
216 void drm_connector_ida_init(void)
220 for (i
= 0; i
< ARRAY_SIZE(drm_connector_enum_list
); i
++)
221 ida_init(&drm_connector_enum_list
[i
].ida
);
224 void drm_connector_ida_destroy(void)
228 for (i
= 0; i
< ARRAY_SIZE(drm_connector_enum_list
); i
++)
229 ida_destroy(&drm_connector_enum_list
[i
].ida
);
232 const char *drm_get_encoder_name(const struct drm_encoder
*encoder
)
236 snprintf(buf
, 32, "%s-%d",
237 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
241 EXPORT_SYMBOL(drm_get_encoder_name
);
243 const char *drm_get_connector_name(const struct drm_connector
*connector
)
247 snprintf(buf
, 32, "%s-%d",
248 drm_connector_enum_list
[connector
->connector_type
].name
,
249 connector
->connector_type_id
);
252 EXPORT_SYMBOL(drm_get_connector_name
);
254 const char *drm_get_connector_status_name(enum drm_connector_status status
)
256 if (status
== connector_status_connected
)
258 else if (status
== connector_status_disconnected
)
259 return "disconnected";
263 EXPORT_SYMBOL(drm_get_connector_status_name
);
265 static char printable_char(int c
)
267 return isascii(c
) && isprint(c
) ? c
: '?';
270 const char *drm_get_format_name(uint32_t format
)
274 snprintf(buf
, sizeof(buf
),
275 "%c%c%c%c %s-endian (0x%08x)",
276 printable_char(format
& 0xff),
277 printable_char((format
>> 8) & 0xff),
278 printable_char((format
>> 16) & 0xff),
279 printable_char((format
>> 24) & 0x7f),
280 format
& DRM_FORMAT_BIG_ENDIAN
? "big" : "little",
285 EXPORT_SYMBOL(drm_get_format_name
);
288 * drm_mode_object_get - allocate a new modeset identifier
290 * @obj: object pointer, used to generate unique ID
291 * @obj_type: object type
293 * Create a unique identifier based on @ptr in @dev's identifier space. Used
294 * for tracking modes, CRTCs and connectors.
297 * New unique (relative to other objects in @dev) integer identifier for the
300 static int drm_mode_object_get(struct drm_device
*dev
,
301 struct drm_mode_object
*obj
, uint32_t obj_type
)
305 mutex_lock(&dev
->mode_config
.idr_mutex
);
306 ret
= idr_alloc(&dev
->mode_config
.crtc_idr
, obj
, 1, 0, GFP_KERNEL
);
309 * Set up the object linking under the protection of the idr
310 * lock so that other users can't see inconsistent state.
313 obj
->type
= obj_type
;
315 mutex_unlock(&dev
->mode_config
.idr_mutex
);
317 return ret
< 0 ? ret
: 0;
321 * drm_mode_object_put - free a modeset identifer
323 * @object: object to free
325 * Free @id from @dev's unique identifier pool.
327 static void drm_mode_object_put(struct drm_device
*dev
,
328 struct drm_mode_object
*object
)
330 mutex_lock(&dev
->mode_config
.idr_mutex
);
331 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
332 mutex_unlock(&dev
->mode_config
.idr_mutex
);
336 * drm_mode_object_find - look up a drm object with static lifetime
338 * @id: id of the mode object
339 * @type: type of the mode object
341 * Note that framebuffers cannot be looked up with this functions - since those
342 * are reference counted, they need special treatment.
344 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
345 uint32_t id
, uint32_t type
)
347 struct drm_mode_object
*obj
= NULL
;
349 /* Framebuffers are reference counted and need their own lookup
351 WARN_ON(type
== DRM_MODE_OBJECT_FB
);
353 mutex_lock(&dev
->mode_config
.idr_mutex
);
354 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
355 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
357 mutex_unlock(&dev
->mode_config
.idr_mutex
);
361 EXPORT_SYMBOL(drm_mode_object_find
);
364 * drm_framebuffer_init - initialize a framebuffer
366 * @fb: framebuffer to be initialized
367 * @funcs: ... with these functions
369 * Allocates an ID for the framebuffer's parent mode object, sets its mode
370 * functions & device file and adds it to the master fd list.
373 * This functions publishes the fb and makes it available for concurrent access
374 * by other users. Which means by this point the fb _must_ be fully set up -
375 * since all the fb attributes are invariant over its lifetime, no further
376 * locking but only correct reference counting is required.
379 * Zero on success, error code on failure.
381 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
382 const struct drm_framebuffer_funcs
*funcs
)
386 mutex_lock(&dev
->mode_config
.fb_lock
);
387 kref_init(&fb
->refcount
);
388 INIT_LIST_HEAD(&fb
->filp_head
);
392 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
396 /* Grab the idr reference. */
397 drm_framebuffer_reference(fb
);
399 dev
->mode_config
.num_fb
++;
400 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
402 mutex_unlock(&dev
->mode_config
.fb_lock
);
406 EXPORT_SYMBOL(drm_framebuffer_init
);
408 static void drm_framebuffer_free(struct kref
*kref
)
410 struct drm_framebuffer
*fb
=
411 container_of(kref
, struct drm_framebuffer
, refcount
);
412 fb
->funcs
->destroy(fb
);
415 static struct drm_framebuffer
*__drm_framebuffer_lookup(struct drm_device
*dev
,
418 struct drm_mode_object
*obj
= NULL
;
419 struct drm_framebuffer
*fb
;
421 mutex_lock(&dev
->mode_config
.idr_mutex
);
422 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
423 if (!obj
|| (obj
->type
!= DRM_MODE_OBJECT_FB
) || (obj
->id
!= id
))
427 mutex_unlock(&dev
->mode_config
.idr_mutex
);
433 * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
435 * @id: id of the fb object
437 * If successful, this grabs an additional reference to the framebuffer -
438 * callers need to make sure to eventually unreference the returned framebuffer
441 struct drm_framebuffer
*drm_framebuffer_lookup(struct drm_device
*dev
,
444 struct drm_framebuffer
*fb
;
446 mutex_lock(&dev
->mode_config
.fb_lock
);
447 fb
= __drm_framebuffer_lookup(dev
, id
);
449 drm_framebuffer_reference(fb
);
450 mutex_unlock(&dev
->mode_config
.fb_lock
);
454 EXPORT_SYMBOL(drm_framebuffer_lookup
);
457 * drm_framebuffer_unreference - unref a framebuffer
458 * @fb: framebuffer to unref
460 * This functions decrements the fb's refcount and frees it if it drops to zero.
462 void drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
464 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
465 kref_put(&fb
->refcount
, drm_framebuffer_free
);
467 EXPORT_SYMBOL(drm_framebuffer_unreference
);
470 * drm_framebuffer_reference - incr the fb refcnt
473 void drm_framebuffer_reference(struct drm_framebuffer
*fb
)
475 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
476 kref_get(&fb
->refcount
);
478 EXPORT_SYMBOL(drm_framebuffer_reference
);
480 static void drm_framebuffer_free_bug(struct kref
*kref
)
485 static void __drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
487 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
488 kref_put(&fb
->refcount
, drm_framebuffer_free_bug
);
491 /* dev->mode_config.fb_lock must be held! */
492 static void __drm_framebuffer_unregister(struct drm_device
*dev
,
493 struct drm_framebuffer
*fb
)
495 mutex_lock(&dev
->mode_config
.idr_mutex
);
496 idr_remove(&dev
->mode_config
.crtc_idr
, fb
->base
.id
);
497 mutex_unlock(&dev
->mode_config
.idr_mutex
);
501 __drm_framebuffer_unreference(fb
);
505 * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
506 * @fb: fb to unregister
508 * Drivers need to call this when cleaning up driver-private framebuffers, e.g.
509 * those used for fbdev. Note that the caller must hold a reference of it's own,
510 * i.e. the object may not be destroyed through this call (since it'll lead to a
511 * locking inversion).
513 void drm_framebuffer_unregister_private(struct drm_framebuffer
*fb
)
515 struct drm_device
*dev
= fb
->dev
;
517 mutex_lock(&dev
->mode_config
.fb_lock
);
518 /* Mark fb as reaped and drop idr ref. */
519 __drm_framebuffer_unregister(dev
, fb
);
520 mutex_unlock(&dev
->mode_config
.fb_lock
);
522 EXPORT_SYMBOL(drm_framebuffer_unregister_private
);
525 * drm_framebuffer_cleanup - remove a framebuffer object
526 * @fb: framebuffer to remove
528 * Cleanup references to a user-created framebuffer. This function is intended
529 * to be used from the drivers ->destroy callback.
531 * Note that this function does not remove the fb from active usuage - if it is
532 * still used anywhere, hilarity can ensue since userspace could call getfb on
533 * the id and get back -EINVAL. Obviously no concern at driver unload time.
535 * Also, the framebuffer will not be removed from the lookup idr - for
536 * user-created framebuffers this will happen in in the rmfb ioctl. For
537 * driver-private objects (e.g. for fbdev) drivers need to explicitly call
538 * drm_framebuffer_unregister_private.
540 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
542 struct drm_device
*dev
= fb
->dev
;
544 mutex_lock(&dev
->mode_config
.fb_lock
);
546 dev
->mode_config
.num_fb
--;
547 mutex_unlock(&dev
->mode_config
.fb_lock
);
549 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
552 * drm_framebuffer_remove - remove and unreference a framebuffer object
553 * @fb: framebuffer to remove
555 * Scans all the CRTCs and planes in @dev's mode_config. If they're
556 * using @fb, removes it, setting it to NULL. Then drops the reference to the
557 * passed-in framebuffer. Might take the modeset locks.
559 * Note that this function optimizes the cleanup away if the caller holds the
560 * last reference to the framebuffer. It is also guaranteed to not take the
561 * modeset locks in this case.
563 void drm_framebuffer_remove(struct drm_framebuffer
*fb
)
565 struct drm_device
*dev
= fb
->dev
;
566 struct drm_crtc
*crtc
;
567 struct drm_plane
*plane
;
568 struct drm_mode_set set
;
571 WARN_ON(!list_empty(&fb
->filp_head
));
574 * drm ABI mandates that we remove any deleted framebuffers from active
575 * useage. But since most sane clients only remove framebuffers they no
576 * longer need, try to optimize this away.
578 * Since we're holding a reference ourselves, observing a refcount of 1
579 * means that we're the last holder and can skip it. Also, the refcount
580 * can never increase from 1 again, so we don't need any barriers or
583 * Note that userspace could try to race with use and instate a new
584 * usage _after_ we've cleared all current ones. End result will be an
585 * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
588 if (atomic_read(&fb
->refcount
.refcount
) > 1) {
589 drm_modeset_lock_all(dev
);
590 /* remove from any CRTC */
591 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
592 if (crtc
->fb
== fb
) {
593 /* should turn off the crtc */
594 memset(&set
, 0, sizeof(struct drm_mode_set
));
597 ret
= drm_mode_set_config_internal(&set
);
599 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
603 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
605 drm_plane_force_disable(plane
);
607 drm_modeset_unlock_all(dev
);
610 drm_framebuffer_unreference(fb
);
612 EXPORT_SYMBOL(drm_framebuffer_remove
);
615 * drm_crtc_init - Initialise a new CRTC object
617 * @crtc: CRTC object to init
618 * @funcs: callbacks for the new CRTC
620 * Inits a new object created as base part of a driver crtc object.
623 * Zero on success, error code on failure.
625 int drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
626 const struct drm_crtc_funcs
*funcs
)
632 crtc
->invert_dimensions
= false;
634 drm_modeset_lock_all(dev
);
635 mutex_init(&crtc
->mutex
);
636 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
638 ret
= drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
642 crtc
->base
.properties
= &crtc
->properties
;
644 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
645 dev
->mode_config
.num_crtc
++;
648 drm_modeset_unlock_all(dev
);
652 EXPORT_SYMBOL(drm_crtc_init
);
655 * drm_crtc_cleanup - Clean up the core crtc usage
656 * @crtc: CRTC to cleanup
658 * This function cleans up @crtc and removes it from the DRM mode setting
659 * core. Note that the function does *not* free the crtc structure itself,
660 * this is the responsibility of the caller.
662 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
664 struct drm_device
*dev
= crtc
->dev
;
666 kfree(crtc
->gamma_store
);
667 crtc
->gamma_store
= NULL
;
669 drm_mode_object_put(dev
, &crtc
->base
);
670 list_del(&crtc
->head
);
671 dev
->mode_config
.num_crtc
--;
673 EXPORT_SYMBOL(drm_crtc_cleanup
);
676 * drm_mode_probed_add - add a mode to a connector's probed mode list
677 * @connector: connector the new mode
680 * Add @mode to @connector's mode list for later use.
682 void drm_mode_probed_add(struct drm_connector
*connector
,
683 struct drm_display_mode
*mode
)
685 list_add_tail(&mode
->head
, &connector
->probed_modes
);
687 EXPORT_SYMBOL(drm_mode_probed_add
);
690 * drm_mode_remove - remove and free a mode
691 * @connector: connector list to modify
692 * @mode: mode to remove
694 * Remove @mode from @connector's mode list, then free it.
696 static void drm_mode_remove(struct drm_connector
*connector
,
697 struct drm_display_mode
*mode
)
699 list_del(&mode
->head
);
700 drm_mode_destroy(connector
->dev
, mode
);
704 * drm_connector_init - Init a preallocated connector
706 * @connector: the connector to init
707 * @funcs: callbacks for this connector
708 * @connector_type: user visible type of the connector
710 * Initialises a preallocated connector. Connectors should be
711 * subclassed as part of driver connector objects.
714 * Zero on success, error code on failure.
716 int drm_connector_init(struct drm_device
*dev
,
717 struct drm_connector
*connector
,
718 const struct drm_connector_funcs
*funcs
,
722 struct ida
*connector_ida
=
723 &drm_connector_enum_list
[connector_type
].ida
;
725 drm_modeset_lock_all(dev
);
727 ret
= drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
731 connector
->base
.properties
= &connector
->properties
;
732 connector
->dev
= dev
;
733 connector
->funcs
= funcs
;
734 connector
->connector_type
= connector_type
;
735 connector
->connector_type_id
=
736 ida_simple_get(connector_ida
, 1, 0, GFP_KERNEL
);
737 if (connector
->connector_type_id
< 0) {
738 ret
= connector
->connector_type_id
;
739 drm_mode_object_put(dev
, &connector
->base
);
742 INIT_LIST_HEAD(&connector
->probed_modes
);
743 INIT_LIST_HEAD(&connector
->modes
);
744 connector
->edid_blob_ptr
= NULL
;
745 connector
->status
= connector_status_unknown
;
747 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
748 dev
->mode_config
.num_connector
++;
750 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
751 drm_object_attach_property(&connector
->base
,
752 dev
->mode_config
.edid_property
,
755 drm_object_attach_property(&connector
->base
,
756 dev
->mode_config
.dpms_property
, 0);
759 drm_modeset_unlock_all(dev
);
763 EXPORT_SYMBOL(drm_connector_init
);
766 * drm_connector_cleanup - cleans up an initialised connector
767 * @connector: connector to cleanup
769 * Cleans up the connector but doesn't free the object.
771 void drm_connector_cleanup(struct drm_connector
*connector
)
773 struct drm_device
*dev
= connector
->dev
;
774 struct drm_display_mode
*mode
, *t
;
776 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
777 drm_mode_remove(connector
, mode
);
779 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
780 drm_mode_remove(connector
, mode
);
782 ida_remove(&drm_connector_enum_list
[connector
->connector_type
].ida
,
783 connector
->connector_type_id
);
785 drm_mode_object_put(dev
, &connector
->base
);
786 list_del(&connector
->head
);
787 dev
->mode_config
.num_connector
--;
789 EXPORT_SYMBOL(drm_connector_cleanup
);
791 void drm_connector_unplug_all(struct drm_device
*dev
)
793 struct drm_connector
*connector
;
795 /* taking the mode config mutex ends up in a clash with sysfs */
796 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
797 drm_sysfs_connector_remove(connector
);
800 EXPORT_SYMBOL(drm_connector_unplug_all
);
802 int drm_encoder_init(struct drm_device
*dev
,
803 struct drm_encoder
*encoder
,
804 const struct drm_encoder_funcs
*funcs
,
809 drm_modeset_lock_all(dev
);
811 ret
= drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
816 encoder
->encoder_type
= encoder_type
;
817 encoder
->funcs
= funcs
;
819 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
820 dev
->mode_config
.num_encoder
++;
823 drm_modeset_unlock_all(dev
);
827 EXPORT_SYMBOL(drm_encoder_init
);
829 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
831 struct drm_device
*dev
= encoder
->dev
;
832 drm_modeset_lock_all(dev
);
833 drm_mode_object_put(dev
, &encoder
->base
);
834 list_del(&encoder
->head
);
835 dev
->mode_config
.num_encoder
--;
836 drm_modeset_unlock_all(dev
);
838 EXPORT_SYMBOL(drm_encoder_cleanup
);
841 * drm_plane_init - Initialise a new plane object
843 * @plane: plane object to init
844 * @possible_crtcs: bitmask of possible CRTCs
845 * @funcs: callbacks for the new plane
846 * @formats: array of supported formats (%DRM_FORMAT_*)
847 * @format_count: number of elements in @formats
848 * @priv: plane is private (hidden from userspace)?
850 * Inits a new object created as base part of a driver plane object.
853 * Zero on success, error code on failure.
855 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
856 unsigned long possible_crtcs
,
857 const struct drm_plane_funcs
*funcs
,
858 const uint32_t *formats
, uint32_t format_count
,
863 drm_modeset_lock_all(dev
);
865 ret
= drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
869 plane
->base
.properties
= &plane
->properties
;
871 plane
->funcs
= funcs
;
872 plane
->format_types
= kmalloc(sizeof(uint32_t) * format_count
,
874 if (!plane
->format_types
) {
875 DRM_DEBUG_KMS("out of memory when allocating plane\n");
876 drm_mode_object_put(dev
, &plane
->base
);
881 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
882 plane
->format_count
= format_count
;
883 plane
->possible_crtcs
= possible_crtcs
;
885 /* private planes are not exposed to userspace, but depending on
886 * display hardware, might be convenient to allow sharing programming
887 * for the scanout engine with the crtc implementation.
890 list_add_tail(&plane
->head
, &dev
->mode_config
.plane_list
);
891 dev
->mode_config
.num_plane
++;
893 INIT_LIST_HEAD(&plane
->head
);
897 drm_modeset_unlock_all(dev
);
901 EXPORT_SYMBOL(drm_plane_init
);
904 * drm_plane_cleanup - Clean up the core plane usage
905 * @plane: plane to cleanup
907 * This function cleans up @plane and removes it from the DRM mode setting
908 * core. Note that the function does *not* free the plane structure itself,
909 * this is the responsibility of the caller.
911 void drm_plane_cleanup(struct drm_plane
*plane
)
913 struct drm_device
*dev
= plane
->dev
;
915 drm_modeset_lock_all(dev
);
916 kfree(plane
->format_types
);
917 drm_mode_object_put(dev
, &plane
->base
);
918 /* if not added to a list, it must be a private plane */
919 if (!list_empty(&plane
->head
)) {
920 list_del(&plane
->head
);
921 dev
->mode_config
.num_plane
--;
923 drm_modeset_unlock_all(dev
);
925 EXPORT_SYMBOL(drm_plane_cleanup
);
928 * drm_plane_force_disable - Forcibly disable a plane
929 * @plane: plane to disable
931 * Forces the plane to be disabled.
933 * Used when the plane's current framebuffer is destroyed,
934 * and when restoring fbdev mode.
936 void drm_plane_force_disable(struct drm_plane
*plane
)
943 ret
= plane
->funcs
->disable_plane(plane
);
945 DRM_ERROR("failed to disable plane with busy fb\n");
946 /* disconnect the plane from the fb and crtc: */
947 __drm_framebuffer_unreference(plane
->fb
);
951 EXPORT_SYMBOL(drm_plane_force_disable
);
954 * drm_mode_create - create a new display mode
957 * Create a new drm_display_mode, give it an ID, and return it.
960 * Pointer to new mode on success, NULL on error.
962 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
964 struct drm_display_mode
*nmode
;
966 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
970 if (drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
)) {
977 EXPORT_SYMBOL(drm_mode_create
);
980 * drm_mode_destroy - remove a mode
982 * @mode: mode to remove
984 * Free @mode's unique identifier, then free it.
986 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
991 drm_mode_object_put(dev
, &mode
->base
);
995 EXPORT_SYMBOL(drm_mode_destroy
);
997 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
999 struct drm_property
*edid
;
1000 struct drm_property
*dpms
;
1003 * Standard properties (apply to all connectors)
1005 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
1006 DRM_MODE_PROP_IMMUTABLE
,
1008 dev
->mode_config
.edid_property
= edid
;
1010 dpms
= drm_property_create_enum(dev
, 0,
1011 "DPMS", drm_dpms_enum_list
,
1012 ARRAY_SIZE(drm_dpms_enum_list
));
1013 dev
->mode_config
.dpms_property
= dpms
;
1019 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1022 * Called by a driver the first time a DVI-I connector is made.
1024 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
1026 struct drm_property
*dvi_i_selector
;
1027 struct drm_property
*dvi_i_subconnector
;
1029 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
1033 drm_property_create_enum(dev
, 0,
1034 "select subconnector",
1035 drm_dvi_i_select_enum_list
,
1036 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
1037 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
1039 dvi_i_subconnector
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1041 drm_dvi_i_subconnector_enum_list
,
1042 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
1043 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
1047 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
1050 * drm_create_tv_properties - create TV specific connector properties
1052 * @num_modes: number of different TV formats (modes) supported
1053 * @modes: array of pointers to strings containing name of each format
1055 * Called by a driver's TV initialization routine, this function creates
1056 * the TV specific connector properties for a given device. Caller is
1057 * responsible for allocating a list of format names and passing them to
1060 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
1063 struct drm_property
*tv_selector
;
1064 struct drm_property
*tv_subconnector
;
1067 if (dev
->mode_config
.tv_select_subconnector_property
)
1071 * Basic connector properties
1073 tv_selector
= drm_property_create_enum(dev
, 0,
1074 "select subconnector",
1075 drm_tv_select_enum_list
,
1076 ARRAY_SIZE(drm_tv_select_enum_list
));
1077 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
1080 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1082 drm_tv_subconnector_enum_list
,
1083 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
1084 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
1087 * Other, TV specific properties: margins & TV modes.
1089 dev
->mode_config
.tv_left_margin_property
=
1090 drm_property_create_range(dev
, 0, "left margin", 0, 100);
1092 dev
->mode_config
.tv_right_margin_property
=
1093 drm_property_create_range(dev
, 0, "right margin", 0, 100);
1095 dev
->mode_config
.tv_top_margin_property
=
1096 drm_property_create_range(dev
, 0, "top margin", 0, 100);
1098 dev
->mode_config
.tv_bottom_margin_property
=
1099 drm_property_create_range(dev
, 0, "bottom margin", 0, 100);
1101 dev
->mode_config
.tv_mode_property
=
1102 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
1104 for (i
= 0; i
< num_modes
; i
++)
1105 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
1108 dev
->mode_config
.tv_brightness_property
=
1109 drm_property_create_range(dev
, 0, "brightness", 0, 100);
1111 dev
->mode_config
.tv_contrast_property
=
1112 drm_property_create_range(dev
, 0, "contrast", 0, 100);
1114 dev
->mode_config
.tv_flicker_reduction_property
=
1115 drm_property_create_range(dev
, 0, "flicker reduction", 0, 100);
1117 dev
->mode_config
.tv_overscan_property
=
1118 drm_property_create_range(dev
, 0, "overscan", 0, 100);
1120 dev
->mode_config
.tv_saturation_property
=
1121 drm_property_create_range(dev
, 0, "saturation", 0, 100);
1123 dev
->mode_config
.tv_hue_property
=
1124 drm_property_create_range(dev
, 0, "hue", 0, 100);
1128 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
1131 * drm_mode_create_scaling_mode_property - create scaling mode property
1134 * Called by a driver the first time it's needed, must be attached to desired
1137 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
1139 struct drm_property
*scaling_mode
;
1141 if (dev
->mode_config
.scaling_mode_property
)
1145 drm_property_create_enum(dev
, 0, "scaling mode",
1146 drm_scaling_mode_enum_list
,
1147 ARRAY_SIZE(drm_scaling_mode_enum_list
));
1149 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
1153 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
1156 * drm_mode_create_dirty_property - create dirty property
1159 * Called by a driver the first time it's needed, must be attached to desired
1162 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
1164 struct drm_property
*dirty_info
;
1166 if (dev
->mode_config
.dirty_info_property
)
1170 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1172 drm_dirty_info_enum_list
,
1173 ARRAY_SIZE(drm_dirty_info_enum_list
));
1174 dev
->mode_config
.dirty_info_property
= dirty_info
;
1178 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
1180 static int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
1182 uint32_t total_objects
= 0;
1184 total_objects
+= dev
->mode_config
.num_crtc
;
1185 total_objects
+= dev
->mode_config
.num_connector
;
1186 total_objects
+= dev
->mode_config
.num_encoder
;
1188 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
1189 if (!group
->id_list
)
1192 group
->num_crtcs
= 0;
1193 group
->num_connectors
= 0;
1194 group
->num_encoders
= 0;
1198 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
1199 struct drm_mode_group
*group
)
1201 struct drm_crtc
*crtc
;
1202 struct drm_encoder
*encoder
;
1203 struct drm_connector
*connector
;
1206 if ((ret
= drm_mode_group_init(dev
, group
)))
1209 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
1210 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
1212 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
1213 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
1216 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
1217 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
1218 group
->num_connectors
++] = connector
->base
.id
;
1222 EXPORT_SYMBOL(drm_mode_group_init_legacy_group
);
1225 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1226 * @out: drm_mode_modeinfo struct to return to the user
1227 * @in: drm_display_mode to use
1229 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1232 static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
1233 const struct drm_display_mode
*in
)
1235 WARN(in
->hdisplay
> USHRT_MAX
|| in
->hsync_start
> USHRT_MAX
||
1236 in
->hsync_end
> USHRT_MAX
|| in
->htotal
> USHRT_MAX
||
1237 in
->hskew
> USHRT_MAX
|| in
->vdisplay
> USHRT_MAX
||
1238 in
->vsync_start
> USHRT_MAX
|| in
->vsync_end
> USHRT_MAX
||
1239 in
->vtotal
> USHRT_MAX
|| in
->vscan
> USHRT_MAX
,
1240 "timing values too large for mode info\n");
1242 out
->clock
= in
->clock
;
1243 out
->hdisplay
= in
->hdisplay
;
1244 out
->hsync_start
= in
->hsync_start
;
1245 out
->hsync_end
= in
->hsync_end
;
1246 out
->htotal
= in
->htotal
;
1247 out
->hskew
= in
->hskew
;
1248 out
->vdisplay
= in
->vdisplay
;
1249 out
->vsync_start
= in
->vsync_start
;
1250 out
->vsync_end
= in
->vsync_end
;
1251 out
->vtotal
= in
->vtotal
;
1252 out
->vscan
= in
->vscan
;
1253 out
->vrefresh
= in
->vrefresh
;
1254 out
->flags
= in
->flags
;
1255 out
->type
= in
->type
;
1256 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1257 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1261 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1262 * @out: drm_display_mode to return to the user
1263 * @in: drm_mode_modeinfo to use
1265 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1269 * Zero on success, errno on failure.
1271 static int drm_crtc_convert_umode(struct drm_display_mode
*out
,
1272 const struct drm_mode_modeinfo
*in
)
1274 if (in
->clock
> INT_MAX
|| in
->vrefresh
> INT_MAX
)
1277 out
->clock
= in
->clock
;
1278 out
->hdisplay
= in
->hdisplay
;
1279 out
->hsync_start
= in
->hsync_start
;
1280 out
->hsync_end
= in
->hsync_end
;
1281 out
->htotal
= in
->htotal
;
1282 out
->hskew
= in
->hskew
;
1283 out
->vdisplay
= in
->vdisplay
;
1284 out
->vsync_start
= in
->vsync_start
;
1285 out
->vsync_end
= in
->vsync_end
;
1286 out
->vtotal
= in
->vtotal
;
1287 out
->vscan
= in
->vscan
;
1288 out
->vrefresh
= in
->vrefresh
;
1289 out
->flags
= in
->flags
;
1290 out
->type
= in
->type
;
1291 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1292 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1298 * drm_mode_getresources - get graphics configuration
1299 * @dev: drm device for the ioctl
1300 * @data: data pointer for the ioctl
1301 * @file_priv: drm file for the ioctl call
1303 * Construct a set of configuration description structures and return
1304 * them to the user, including CRTC, connector and framebuffer configuration.
1306 * Called by the user via ioctl.
1309 * Zero on success, errno on failure.
1311 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1312 struct drm_file
*file_priv
)
1314 struct drm_mode_card_res
*card_res
= data
;
1315 struct list_head
*lh
;
1316 struct drm_framebuffer
*fb
;
1317 struct drm_connector
*connector
;
1318 struct drm_crtc
*crtc
;
1319 struct drm_encoder
*encoder
;
1321 int connector_count
= 0;
1324 int encoder_count
= 0;
1326 uint32_t __user
*fb_id
;
1327 uint32_t __user
*crtc_id
;
1328 uint32_t __user
*connector_id
;
1329 uint32_t __user
*encoder_id
;
1330 struct drm_mode_group
*mode_group
;
1332 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1336 mutex_lock(&file_priv
->fbs_lock
);
1338 * For the non-control nodes we need to limit the list of resources
1339 * by IDs in the group list for this node
1341 list_for_each(lh
, &file_priv
->fbs
)
1344 /* handle this in 4 parts */
1346 if (card_res
->count_fbs
>= fb_count
) {
1348 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1349 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1350 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1351 mutex_unlock(&file_priv
->fbs_lock
);
1357 card_res
->count_fbs
= fb_count
;
1358 mutex_unlock(&file_priv
->fbs_lock
);
1360 drm_modeset_lock_all(dev
);
1361 mode_group
= &file_priv
->master
->minor
->mode_group
;
1362 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1364 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1367 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1370 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1374 crtc_count
= mode_group
->num_crtcs
;
1375 connector_count
= mode_group
->num_connectors
;
1376 encoder_count
= mode_group
->num_encoders
;
1379 card_res
->max_height
= dev
->mode_config
.max_height
;
1380 card_res
->min_height
= dev
->mode_config
.min_height
;
1381 card_res
->max_width
= dev
->mode_config
.max_width
;
1382 card_res
->min_width
= dev
->mode_config
.min_width
;
1385 if (card_res
->count_crtcs
>= crtc_count
) {
1387 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1388 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1389 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1391 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1392 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1399 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1400 if (put_user(mode_group
->id_list
[i
],
1401 crtc_id
+ copied
)) {
1409 card_res
->count_crtcs
= crtc_count
;
1412 if (card_res
->count_encoders
>= encoder_count
) {
1414 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1415 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1416 list_for_each_entry(encoder
,
1417 &dev
->mode_config
.encoder_list
,
1419 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1420 drm_get_encoder_name(encoder
));
1421 if (put_user(encoder
->base
.id
, encoder_id
+
1429 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1430 if (put_user(mode_group
->id_list
[i
],
1431 encoder_id
+ copied
)) {
1440 card_res
->count_encoders
= encoder_count
;
1443 if (card_res
->count_connectors
>= connector_count
) {
1445 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1446 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1447 list_for_each_entry(connector
,
1448 &dev
->mode_config
.connector_list
,
1450 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1452 drm_get_connector_name(connector
));
1453 if (put_user(connector
->base
.id
,
1454 connector_id
+ copied
)) {
1461 int start
= mode_group
->num_crtcs
+
1462 mode_group
->num_encoders
;
1463 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1464 if (put_user(mode_group
->id_list
[i
],
1465 connector_id
+ copied
)) {
1473 card_res
->count_connectors
= connector_count
;
1475 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1476 card_res
->count_connectors
, card_res
->count_encoders
);
1479 drm_modeset_unlock_all(dev
);
1484 * drm_mode_getcrtc - get CRTC configuration
1485 * @dev: drm device for the ioctl
1486 * @data: data pointer for the ioctl
1487 * @file_priv: drm file for the ioctl call
1489 * Construct a CRTC configuration structure to return to the user.
1491 * Called by the user via ioctl.
1494 * Zero on success, errno on failure.
1496 int drm_mode_getcrtc(struct drm_device
*dev
,
1497 void *data
, struct drm_file
*file_priv
)
1499 struct drm_mode_crtc
*crtc_resp
= data
;
1500 struct drm_crtc
*crtc
;
1501 struct drm_mode_object
*obj
;
1504 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1507 drm_modeset_lock_all(dev
);
1509 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1510 DRM_MODE_OBJECT_CRTC
);
1515 crtc
= obj_to_crtc(obj
);
1517 crtc_resp
->x
= crtc
->x
;
1518 crtc_resp
->y
= crtc
->y
;
1519 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1521 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1523 crtc_resp
->fb_id
= 0;
1525 if (crtc
->enabled
) {
1527 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1528 crtc_resp
->mode_valid
= 1;
1531 crtc_resp
->mode_valid
= 0;
1535 drm_modeset_unlock_all(dev
);
1540 * drm_mode_getconnector - get connector configuration
1541 * @dev: drm device for the ioctl
1542 * @data: data pointer for the ioctl
1543 * @file_priv: drm file for the ioctl call
1545 * Construct a connector configuration structure to return to the user.
1547 * Called by the user via ioctl.
1550 * Zero on success, errno on failure.
1552 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1553 struct drm_file
*file_priv
)
1555 struct drm_mode_get_connector
*out_resp
= data
;
1556 struct drm_mode_object
*obj
;
1557 struct drm_connector
*connector
;
1558 struct drm_display_mode
*mode
;
1560 int props_count
= 0;
1561 int encoders_count
= 0;
1565 struct drm_mode_modeinfo u_mode
;
1566 struct drm_mode_modeinfo __user
*mode_ptr
;
1567 uint32_t __user
*prop_ptr
;
1568 uint64_t __user
*prop_values
;
1569 uint32_t __user
*encoder_ptr
;
1571 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1574 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1576 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1578 mutex_lock(&dev
->mode_config
.mutex
);
1580 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1581 DRM_MODE_OBJECT_CONNECTOR
);
1586 connector
= obj_to_connector(obj
);
1588 props_count
= connector
->properties
.count
;
1590 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1591 if (connector
->encoder_ids
[i
] != 0) {
1596 if (out_resp
->count_modes
== 0) {
1597 connector
->funcs
->fill_modes(connector
,
1598 dev
->mode_config
.max_width
,
1599 dev
->mode_config
.max_height
);
1602 /* delayed so we get modes regardless of pre-fill_modes state */
1603 list_for_each_entry(mode
, &connector
->modes
, head
)
1606 out_resp
->connector_id
= connector
->base
.id
;
1607 out_resp
->connector_type
= connector
->connector_type
;
1608 out_resp
->connector_type_id
= connector
->connector_type_id
;
1609 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1610 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1611 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1612 out_resp
->connection
= connector
->status
;
1613 if (connector
->encoder
)
1614 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1616 out_resp
->encoder_id
= 0;
1619 * This ioctl is called twice, once to determine how much space is
1620 * needed, and the 2nd time to fill it.
1622 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1624 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1625 list_for_each_entry(mode
, &connector
->modes
, head
) {
1626 drm_crtc_convert_to_umode(&u_mode
, mode
);
1627 if (copy_to_user(mode_ptr
+ copied
,
1628 &u_mode
, sizeof(u_mode
))) {
1635 out_resp
->count_modes
= mode_count
;
1637 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1639 prop_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
);
1640 prop_values
= (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
);
1641 for (i
= 0; i
< connector
->properties
.count
; i
++) {
1642 if (put_user(connector
->properties
.ids
[i
],
1643 prop_ptr
+ copied
)) {
1648 if (put_user(connector
->properties
.values
[i
],
1649 prop_values
+ copied
)) {
1656 out_resp
->count_props
= props_count
;
1658 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1660 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1661 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1662 if (connector
->encoder_ids
[i
] != 0) {
1663 if (put_user(connector
->encoder_ids
[i
],
1664 encoder_ptr
+ copied
)) {
1672 out_resp
->count_encoders
= encoders_count
;
1675 mutex_unlock(&dev
->mode_config
.mutex
);
1680 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1681 struct drm_file
*file_priv
)
1683 struct drm_mode_get_encoder
*enc_resp
= data
;
1684 struct drm_mode_object
*obj
;
1685 struct drm_encoder
*encoder
;
1688 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1691 drm_modeset_lock_all(dev
);
1692 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1693 DRM_MODE_OBJECT_ENCODER
);
1698 encoder
= obj_to_encoder(obj
);
1701 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1703 enc_resp
->crtc_id
= 0;
1704 enc_resp
->encoder_type
= encoder
->encoder_type
;
1705 enc_resp
->encoder_id
= encoder
->base
.id
;
1706 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1707 enc_resp
->possible_clones
= encoder
->possible_clones
;
1710 drm_modeset_unlock_all(dev
);
1715 * drm_mode_getplane_res - get plane info
1718 * @file_priv: DRM file info
1720 * Return an plane count and set of IDs.
1722 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
1723 struct drm_file
*file_priv
)
1725 struct drm_mode_get_plane_res
*plane_resp
= data
;
1726 struct drm_mode_config
*config
;
1727 struct drm_plane
*plane
;
1728 uint32_t __user
*plane_ptr
;
1729 int copied
= 0, ret
= 0;
1731 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1734 drm_modeset_lock_all(dev
);
1735 config
= &dev
->mode_config
;
1738 * This ioctl is called twice, once to determine how much space is
1739 * needed, and the 2nd time to fill it.
1741 if (config
->num_plane
&&
1742 (plane_resp
->count_planes
>= config
->num_plane
)) {
1743 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
1745 list_for_each_entry(plane
, &config
->plane_list
, head
) {
1746 if (put_user(plane
->base
.id
, plane_ptr
+ copied
)) {
1753 plane_resp
->count_planes
= config
->num_plane
;
1756 drm_modeset_unlock_all(dev
);
1761 * drm_mode_getplane - get plane info
1764 * @file_priv: DRM file info
1766 * Return plane info, including formats supported, gamma size, any
1769 int drm_mode_getplane(struct drm_device
*dev
, void *data
,
1770 struct drm_file
*file_priv
)
1772 struct drm_mode_get_plane
*plane_resp
= data
;
1773 struct drm_mode_object
*obj
;
1774 struct drm_plane
*plane
;
1775 uint32_t __user
*format_ptr
;
1778 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1781 drm_modeset_lock_all(dev
);
1782 obj
= drm_mode_object_find(dev
, plane_resp
->plane_id
,
1783 DRM_MODE_OBJECT_PLANE
);
1788 plane
= obj_to_plane(obj
);
1791 plane_resp
->crtc_id
= plane
->crtc
->base
.id
;
1793 plane_resp
->crtc_id
= 0;
1796 plane_resp
->fb_id
= plane
->fb
->base
.id
;
1798 plane_resp
->fb_id
= 0;
1800 plane_resp
->plane_id
= plane
->base
.id
;
1801 plane_resp
->possible_crtcs
= plane
->possible_crtcs
;
1802 plane_resp
->gamma_size
= 0;
1805 * This ioctl is called twice, once to determine how much space is
1806 * needed, and the 2nd time to fill it.
1808 if (plane
->format_count
&&
1809 (plane_resp
->count_format_types
>= plane
->format_count
)) {
1810 format_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->format_type_ptr
;
1811 if (copy_to_user(format_ptr
,
1812 plane
->format_types
,
1813 sizeof(uint32_t) * plane
->format_count
)) {
1818 plane_resp
->count_format_types
= plane
->format_count
;
1821 drm_modeset_unlock_all(dev
);
1826 * drm_mode_setplane - set up or tear down an plane
1828 * @data: ioctl data*
1829 * @file_priv: DRM file info
1831 * Set plane info, including placement, fb, scaling, and other factors.
1832 * Or pass a NULL fb to disable.
1834 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
1835 struct drm_file
*file_priv
)
1837 struct drm_mode_set_plane
*plane_req
= data
;
1838 struct drm_mode_object
*obj
;
1839 struct drm_plane
*plane
;
1840 struct drm_crtc
*crtc
;
1841 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
1843 unsigned int fb_width
, fb_height
;
1846 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1850 * First, find the plane, crtc, and fb objects. If not available,
1851 * we don't bother to call the driver.
1853 obj
= drm_mode_object_find(dev
, plane_req
->plane_id
,
1854 DRM_MODE_OBJECT_PLANE
);
1856 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1857 plane_req
->plane_id
);
1860 plane
= obj_to_plane(obj
);
1862 /* No fb means shut it down */
1863 if (!plane_req
->fb_id
) {
1864 drm_modeset_lock_all(dev
);
1866 plane
->funcs
->disable_plane(plane
);
1869 drm_modeset_unlock_all(dev
);
1873 obj
= drm_mode_object_find(dev
, plane_req
->crtc_id
,
1874 DRM_MODE_OBJECT_CRTC
);
1876 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1877 plane_req
->crtc_id
);
1881 crtc
= obj_to_crtc(obj
);
1883 fb
= drm_framebuffer_lookup(dev
, plane_req
->fb_id
);
1885 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1891 /* Check whether this plane supports the fb pixel format. */
1892 for (i
= 0; i
< plane
->format_count
; i
++)
1893 if (fb
->pixel_format
== plane
->format_types
[i
])
1895 if (i
== plane
->format_count
) {
1896 DRM_DEBUG_KMS("Invalid pixel format %s\n",
1897 drm_get_format_name(fb
->pixel_format
));
1902 fb_width
= fb
->width
<< 16;
1903 fb_height
= fb
->height
<< 16;
1905 /* Make sure source coordinates are inside the fb. */
1906 if (plane_req
->src_w
> fb_width
||
1907 plane_req
->src_x
> fb_width
- plane_req
->src_w
||
1908 plane_req
->src_h
> fb_height
||
1909 plane_req
->src_y
> fb_height
- plane_req
->src_h
) {
1910 DRM_DEBUG_KMS("Invalid source coordinates "
1911 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1912 plane_req
->src_w
>> 16,
1913 ((plane_req
->src_w
& 0xffff) * 15625) >> 10,
1914 plane_req
->src_h
>> 16,
1915 ((plane_req
->src_h
& 0xffff) * 15625) >> 10,
1916 plane_req
->src_x
>> 16,
1917 ((plane_req
->src_x
& 0xffff) * 15625) >> 10,
1918 plane_req
->src_y
>> 16,
1919 ((plane_req
->src_y
& 0xffff) * 15625) >> 10);
1924 /* Give drivers some help against integer overflows */
1925 if (plane_req
->crtc_w
> INT_MAX
||
1926 plane_req
->crtc_x
> INT_MAX
- (int32_t) plane_req
->crtc_w
||
1927 plane_req
->crtc_h
> INT_MAX
||
1928 plane_req
->crtc_y
> INT_MAX
- (int32_t) plane_req
->crtc_h
) {
1929 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
1930 plane_req
->crtc_w
, plane_req
->crtc_h
,
1931 plane_req
->crtc_x
, plane_req
->crtc_y
);
1936 drm_modeset_lock_all(dev
);
1937 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
1938 plane_req
->crtc_x
, plane_req
->crtc_y
,
1939 plane_req
->crtc_w
, plane_req
->crtc_h
,
1940 plane_req
->src_x
, plane_req
->src_y
,
1941 plane_req
->src_w
, plane_req
->src_h
);
1948 drm_modeset_unlock_all(dev
);
1952 drm_framebuffer_unreference(fb
);
1954 drm_framebuffer_unreference(old_fb
);
1960 * drm_mode_set_config_internal - helper to call ->set_config
1961 * @set: modeset config to set
1963 * This is a little helper to wrap internal calls to the ->set_config driver
1964 * interface. The only thing it adds is correct refcounting dance.
1966 int drm_mode_set_config_internal(struct drm_mode_set
*set
)
1968 struct drm_crtc
*crtc
= set
->crtc
;
1969 struct drm_framebuffer
*fb
;
1970 struct drm_crtc
*tmp
;
1974 * NOTE: ->set_config can also disable other crtcs (if we steal all
1975 * connectors from it), hence we need to refcount the fbs across all
1976 * crtcs. Atomic modeset will have saner semantics ...
1978 list_for_each_entry(tmp
, &crtc
->dev
->mode_config
.crtc_list
, head
)
1979 tmp
->old_fb
= tmp
->fb
;
1983 ret
= crtc
->funcs
->set_config(set
);
1985 /* crtc->fb must be updated by ->set_config, enforces this. */
1986 WARN_ON(fb
!= crtc
->fb
);
1989 list_for_each_entry(tmp
, &crtc
->dev
->mode_config
.crtc_list
, head
) {
1991 drm_framebuffer_reference(tmp
->fb
);
1993 drm_framebuffer_unreference(tmp
->old_fb
);
1998 EXPORT_SYMBOL(drm_mode_set_config_internal
);
2001 * drm_mode_setcrtc - set CRTC configuration
2002 * @dev: drm device for the ioctl
2003 * @data: data pointer for the ioctl
2004 * @file_priv: drm file for the ioctl call
2006 * Build a new CRTC configuration based on user request.
2008 * Called by the user via ioctl.
2011 * Zero on success, errno on failure.
2013 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
2014 struct drm_file
*file_priv
)
2016 struct drm_mode_config
*config
= &dev
->mode_config
;
2017 struct drm_mode_crtc
*crtc_req
= data
;
2018 struct drm_mode_object
*obj
;
2019 struct drm_crtc
*crtc
;
2020 struct drm_connector
**connector_set
= NULL
, *connector
;
2021 struct drm_framebuffer
*fb
= NULL
;
2022 struct drm_display_mode
*mode
= NULL
;
2023 struct drm_mode_set set
;
2024 uint32_t __user
*set_connectors_ptr
;
2028 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2031 /* For some reason crtc x/y offsets are signed internally. */
2032 if (crtc_req
->x
> INT_MAX
|| crtc_req
->y
> INT_MAX
)
2035 drm_modeset_lock_all(dev
);
2036 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
2037 DRM_MODE_OBJECT_CRTC
);
2039 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
2043 crtc
= obj_to_crtc(obj
);
2044 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
2046 if (crtc_req
->mode_valid
) {
2047 int hdisplay
, vdisplay
;
2048 /* If we have a mode we need a framebuffer. */
2049 /* If we pass -1, set the mode with the currently bound fb */
2050 if (crtc_req
->fb_id
== -1) {
2052 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
2057 /* Make refcounting symmetric with the lookup path. */
2058 drm_framebuffer_reference(fb
);
2060 fb
= drm_framebuffer_lookup(dev
, crtc_req
->fb_id
);
2062 DRM_DEBUG_KMS("Unknown FB ID%d\n",
2069 mode
= drm_mode_create(dev
);
2075 ret
= drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
2077 DRM_DEBUG_KMS("Invalid mode\n");
2081 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
2083 hdisplay
= mode
->hdisplay
;
2084 vdisplay
= mode
->vdisplay
;
2086 if (crtc
->invert_dimensions
)
2087 swap(hdisplay
, vdisplay
);
2089 if (hdisplay
> fb
->width
||
2090 vdisplay
> fb
->height
||
2091 crtc_req
->x
> fb
->width
- hdisplay
||
2092 crtc_req
->y
> fb
->height
- vdisplay
) {
2093 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
2094 fb
->width
, fb
->height
,
2095 hdisplay
, vdisplay
, crtc_req
->x
, crtc_req
->y
,
2096 crtc
->invert_dimensions
? " (inverted)" : "");
2102 if (crtc_req
->count_connectors
== 0 && mode
) {
2103 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
2108 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
2109 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
2110 crtc_req
->count_connectors
);
2115 if (crtc_req
->count_connectors
> 0) {
2118 /* Avoid unbounded kernel memory allocation */
2119 if (crtc_req
->count_connectors
> config
->num_connector
) {
2124 connector_set
= kmalloc(crtc_req
->count_connectors
*
2125 sizeof(struct drm_connector
*),
2127 if (!connector_set
) {
2132 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
2133 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
2134 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
2139 obj
= drm_mode_object_find(dev
, out_id
,
2140 DRM_MODE_OBJECT_CONNECTOR
);
2142 DRM_DEBUG_KMS("Connector id %d unknown\n",
2147 connector
= obj_to_connector(obj
);
2148 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2150 drm_get_connector_name(connector
));
2152 connector_set
[i
] = connector
;
2157 set
.x
= crtc_req
->x
;
2158 set
.y
= crtc_req
->y
;
2160 set
.connectors
= connector_set
;
2161 set
.num_connectors
= crtc_req
->count_connectors
;
2163 ret
= drm_mode_set_config_internal(&set
);
2167 drm_framebuffer_unreference(fb
);
2169 kfree(connector_set
);
2170 drm_mode_destroy(dev
, mode
);
2171 drm_modeset_unlock_all(dev
);
2175 static int drm_mode_cursor_common(struct drm_device
*dev
,
2176 struct drm_mode_cursor2
*req
,
2177 struct drm_file
*file_priv
)
2179 struct drm_mode_object
*obj
;
2180 struct drm_crtc
*crtc
;
2183 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2186 if (!req
->flags
|| (~DRM_MODE_CURSOR_FLAGS
& req
->flags
))
2189 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2191 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
2194 crtc
= obj_to_crtc(obj
);
2196 mutex_lock(&crtc
->mutex
);
2197 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
2198 if (!crtc
->funcs
->cursor_set
&& !crtc
->funcs
->cursor_set2
) {
2202 /* Turns off the cursor if handle is 0 */
2203 if (crtc
->funcs
->cursor_set2
)
2204 ret
= crtc
->funcs
->cursor_set2(crtc
, file_priv
, req
->handle
,
2205 req
->width
, req
->height
, req
->hot_x
, req
->hot_y
);
2207 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
2208 req
->width
, req
->height
);
2211 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
2212 if (crtc
->funcs
->cursor_move
) {
2213 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
2220 mutex_unlock(&crtc
->mutex
);
2225 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
2226 void *data
, struct drm_file
*file_priv
)
2228 struct drm_mode_cursor
*req
= data
;
2229 struct drm_mode_cursor2 new_req
;
2231 memcpy(&new_req
, req
, sizeof(struct drm_mode_cursor
));
2232 new_req
.hot_x
= new_req
.hot_y
= 0;
2234 return drm_mode_cursor_common(dev
, &new_req
, file_priv
);
2237 int drm_mode_cursor2_ioctl(struct drm_device
*dev
,
2238 void *data
, struct drm_file
*file_priv
)
2240 struct drm_mode_cursor2
*req
= data
;
2241 return drm_mode_cursor_common(dev
, req
, file_priv
);
2244 /* Original addfb only supported RGB formats, so figure out which one */
2245 uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
)
2251 fmt
= DRM_FORMAT_C8
;
2255 fmt
= DRM_FORMAT_XRGB1555
;
2257 fmt
= DRM_FORMAT_RGB565
;
2260 fmt
= DRM_FORMAT_RGB888
;
2264 fmt
= DRM_FORMAT_XRGB8888
;
2265 else if (depth
== 30)
2266 fmt
= DRM_FORMAT_XRGB2101010
;
2268 fmt
= DRM_FORMAT_ARGB8888
;
2271 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
2272 fmt
= DRM_FORMAT_XRGB8888
;
2278 EXPORT_SYMBOL(drm_mode_legacy_fb_format
);
2281 * drm_mode_addfb - add an FB to the graphics configuration
2282 * @dev: drm device for the ioctl
2283 * @data: data pointer for the ioctl
2284 * @file_priv: drm file for the ioctl call
2286 * Add a new FB to the specified CRTC, given a user request.
2288 * Called by the user via ioctl.
2291 * Zero on success, errno on failure.
2293 int drm_mode_addfb(struct drm_device
*dev
,
2294 void *data
, struct drm_file
*file_priv
)
2296 struct drm_mode_fb_cmd
*or = data
;
2297 struct drm_mode_fb_cmd2 r
= {};
2298 struct drm_mode_config
*config
= &dev
->mode_config
;
2299 struct drm_framebuffer
*fb
;
2302 /* Use new struct with format internally */
2303 r
.fb_id
= or->fb_id
;
2304 r
.width
= or->width
;
2305 r
.height
= or->height
;
2306 r
.pitches
[0] = or->pitch
;
2307 r
.pixel_format
= drm_mode_legacy_fb_format(or->bpp
, or->depth
);
2308 r
.handles
[0] = or->handle
;
2310 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2313 if ((config
->min_width
> r
.width
) || (r
.width
> config
->max_width
))
2316 if ((config
->min_height
> r
.height
) || (r
.height
> config
->max_height
))
2319 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, &r
);
2321 DRM_DEBUG_KMS("could not create framebuffer\n");
2325 mutex_lock(&file_priv
->fbs_lock
);
2326 or->fb_id
= fb
->base
.id
;
2327 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2328 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2329 mutex_unlock(&file_priv
->fbs_lock
);
2334 static int format_check(const struct drm_mode_fb_cmd2
*r
)
2336 uint32_t format
= r
->pixel_format
& ~DRM_FORMAT_BIG_ENDIAN
;
2340 case DRM_FORMAT_RGB332
:
2341 case DRM_FORMAT_BGR233
:
2342 case DRM_FORMAT_XRGB4444
:
2343 case DRM_FORMAT_XBGR4444
:
2344 case DRM_FORMAT_RGBX4444
:
2345 case DRM_FORMAT_BGRX4444
:
2346 case DRM_FORMAT_ARGB4444
:
2347 case DRM_FORMAT_ABGR4444
:
2348 case DRM_FORMAT_RGBA4444
:
2349 case DRM_FORMAT_BGRA4444
:
2350 case DRM_FORMAT_XRGB1555
:
2351 case DRM_FORMAT_XBGR1555
:
2352 case DRM_FORMAT_RGBX5551
:
2353 case DRM_FORMAT_BGRX5551
:
2354 case DRM_FORMAT_ARGB1555
:
2355 case DRM_FORMAT_ABGR1555
:
2356 case DRM_FORMAT_RGBA5551
:
2357 case DRM_FORMAT_BGRA5551
:
2358 case DRM_FORMAT_RGB565
:
2359 case DRM_FORMAT_BGR565
:
2360 case DRM_FORMAT_RGB888
:
2361 case DRM_FORMAT_BGR888
:
2362 case DRM_FORMAT_XRGB8888
:
2363 case DRM_FORMAT_XBGR8888
:
2364 case DRM_FORMAT_RGBX8888
:
2365 case DRM_FORMAT_BGRX8888
:
2366 case DRM_FORMAT_ARGB8888
:
2367 case DRM_FORMAT_ABGR8888
:
2368 case DRM_FORMAT_RGBA8888
:
2369 case DRM_FORMAT_BGRA8888
:
2370 case DRM_FORMAT_XRGB2101010
:
2371 case DRM_FORMAT_XBGR2101010
:
2372 case DRM_FORMAT_RGBX1010102
:
2373 case DRM_FORMAT_BGRX1010102
:
2374 case DRM_FORMAT_ARGB2101010
:
2375 case DRM_FORMAT_ABGR2101010
:
2376 case DRM_FORMAT_RGBA1010102
:
2377 case DRM_FORMAT_BGRA1010102
:
2378 case DRM_FORMAT_YUYV
:
2379 case DRM_FORMAT_YVYU
:
2380 case DRM_FORMAT_UYVY
:
2381 case DRM_FORMAT_VYUY
:
2382 case DRM_FORMAT_AYUV
:
2383 case DRM_FORMAT_NV12
:
2384 case DRM_FORMAT_NV21
:
2385 case DRM_FORMAT_NV16
:
2386 case DRM_FORMAT_NV61
:
2387 case DRM_FORMAT_NV24
:
2388 case DRM_FORMAT_NV42
:
2389 case DRM_FORMAT_YUV410
:
2390 case DRM_FORMAT_YVU410
:
2391 case DRM_FORMAT_YUV411
:
2392 case DRM_FORMAT_YVU411
:
2393 case DRM_FORMAT_YUV420
:
2394 case DRM_FORMAT_YVU420
:
2395 case DRM_FORMAT_YUV422
:
2396 case DRM_FORMAT_YVU422
:
2397 case DRM_FORMAT_YUV444
:
2398 case DRM_FORMAT_YVU444
:
2405 static int framebuffer_check(const struct drm_mode_fb_cmd2
*r
)
2407 int ret
, hsub
, vsub
, num_planes
, i
;
2409 ret
= format_check(r
);
2411 DRM_DEBUG_KMS("bad framebuffer format %s\n",
2412 drm_get_format_name(r
->pixel_format
));
2416 hsub
= drm_format_horz_chroma_subsampling(r
->pixel_format
);
2417 vsub
= drm_format_vert_chroma_subsampling(r
->pixel_format
);
2418 num_planes
= drm_format_num_planes(r
->pixel_format
);
2420 if (r
->width
== 0 || r
->width
% hsub
) {
2421 DRM_DEBUG_KMS("bad framebuffer width %u\n", r
->height
);
2425 if (r
->height
== 0 || r
->height
% vsub
) {
2426 DRM_DEBUG_KMS("bad framebuffer height %u\n", r
->height
);
2430 for (i
= 0; i
< num_planes
; i
++) {
2431 unsigned int width
= r
->width
/ (i
!= 0 ? hsub
: 1);
2432 unsigned int height
= r
->height
/ (i
!= 0 ? vsub
: 1);
2433 unsigned int cpp
= drm_format_plane_cpp(r
->pixel_format
, i
);
2435 if (!r
->handles
[i
]) {
2436 DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i
);
2440 if ((uint64_t) width
* cpp
> UINT_MAX
)
2443 if ((uint64_t) height
* r
->pitches
[i
] + r
->offsets
[i
] > UINT_MAX
)
2446 if (r
->pitches
[i
] < width
* cpp
) {
2447 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r
->pitches
[i
], i
);
2456 * drm_mode_addfb2 - add an FB to the graphics configuration
2457 * @dev: drm device for the ioctl
2458 * @data: data pointer for the ioctl
2459 * @file_priv: drm file for the ioctl call
2461 * Add a new FB to the specified CRTC, given a user request with format.
2463 * Called by the user via ioctl.
2466 * Zero on success, errno on failure.
2468 int drm_mode_addfb2(struct drm_device
*dev
,
2469 void *data
, struct drm_file
*file_priv
)
2471 struct drm_mode_fb_cmd2
*r
= data
;
2472 struct drm_mode_config
*config
= &dev
->mode_config
;
2473 struct drm_framebuffer
*fb
;
2476 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2479 if (r
->flags
& ~DRM_MODE_FB_INTERLACED
) {
2480 DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r
->flags
);
2484 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
2485 DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
2486 r
->width
, config
->min_width
, config
->max_width
);
2489 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
2490 DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
2491 r
->height
, config
->min_height
, config
->max_height
);
2495 ret
= framebuffer_check(r
);
2499 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
2501 DRM_DEBUG_KMS("could not create framebuffer\n");
2505 mutex_lock(&file_priv
->fbs_lock
);
2506 r
->fb_id
= fb
->base
.id
;
2507 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2508 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2509 mutex_unlock(&file_priv
->fbs_lock
);
2516 * drm_mode_rmfb - remove an FB from the configuration
2517 * @dev: drm device for the ioctl
2518 * @data: data pointer for the ioctl
2519 * @file_priv: drm file for the ioctl call
2521 * Remove the FB specified by the user.
2523 * Called by the user via ioctl.
2526 * Zero on success, errno on failure.
2528 int drm_mode_rmfb(struct drm_device
*dev
,
2529 void *data
, struct drm_file
*file_priv
)
2531 struct drm_framebuffer
*fb
= NULL
;
2532 struct drm_framebuffer
*fbl
= NULL
;
2533 uint32_t *id
= data
;
2536 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2539 mutex_lock(&file_priv
->fbs_lock
);
2540 mutex_lock(&dev
->mode_config
.fb_lock
);
2541 fb
= __drm_framebuffer_lookup(dev
, *id
);
2545 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
2551 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2552 __drm_framebuffer_unregister(dev
, fb
);
2554 list_del_init(&fb
->filp_head
);
2555 mutex_unlock(&dev
->mode_config
.fb_lock
);
2556 mutex_unlock(&file_priv
->fbs_lock
);
2558 drm_framebuffer_remove(fb
);
2563 mutex_unlock(&dev
->mode_config
.fb_lock
);
2564 mutex_unlock(&file_priv
->fbs_lock
);
2570 * drm_mode_getfb - get FB info
2571 * @dev: drm device for the ioctl
2572 * @data: data pointer for the ioctl
2573 * @file_priv: drm file for the ioctl call
2575 * Lookup the FB given its ID and return info about it.
2577 * Called by the user via ioctl.
2580 * Zero on success, errno on failure.
2582 int drm_mode_getfb(struct drm_device
*dev
,
2583 void *data
, struct drm_file
*file_priv
)
2585 struct drm_mode_fb_cmd
*r
= data
;
2586 struct drm_framebuffer
*fb
;
2589 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2592 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2596 r
->height
= fb
->height
;
2597 r
->width
= fb
->width
;
2598 r
->depth
= fb
->depth
;
2599 r
->bpp
= fb
->bits_per_pixel
;
2600 r
->pitch
= fb
->pitches
[0];
2601 if (fb
->funcs
->create_handle
)
2602 ret
= fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
2606 drm_framebuffer_unreference(fb
);
2611 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2612 void *data
, struct drm_file
*file_priv
)
2614 struct drm_clip_rect __user
*clips_ptr
;
2615 struct drm_clip_rect
*clips
= NULL
;
2616 struct drm_mode_fb_dirty_cmd
*r
= data
;
2617 struct drm_framebuffer
*fb
;
2622 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2625 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2629 num_clips
= r
->num_clips
;
2630 clips_ptr
= (struct drm_clip_rect __user
*)(unsigned long)r
->clips_ptr
;
2632 if (!num_clips
!= !clips_ptr
) {
2637 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
2639 /* If userspace annotates copy, clips must come in pairs */
2640 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
2645 if (num_clips
&& clips_ptr
) {
2646 if (num_clips
< 0 || num_clips
> DRM_MODE_FB_DIRTY_MAX_CLIPS
) {
2650 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
2656 ret
= copy_from_user(clips
, clips_ptr
,
2657 num_clips
* sizeof(*clips
));
2664 if (fb
->funcs
->dirty
) {
2665 drm_modeset_lock_all(dev
);
2666 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
2668 drm_modeset_unlock_all(dev
);
2676 drm_framebuffer_unreference(fb
);
2683 * drm_fb_release - remove and free the FBs on this file
2684 * @priv: drm file for the ioctl
2686 * Destroy all the FBs associated with @filp.
2688 * Called by the user via ioctl.
2691 * Zero on success, errno on failure.
2693 void drm_fb_release(struct drm_file
*priv
)
2695 struct drm_device
*dev
= priv
->minor
->dev
;
2696 struct drm_framebuffer
*fb
, *tfb
;
2698 mutex_lock(&priv
->fbs_lock
);
2699 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
2701 mutex_lock(&dev
->mode_config
.fb_lock
);
2702 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2703 __drm_framebuffer_unregister(dev
, fb
);
2704 mutex_unlock(&dev
->mode_config
.fb_lock
);
2706 list_del_init(&fb
->filp_head
);
2708 /* This will also drop the fpriv->fbs reference. */
2709 drm_framebuffer_remove(fb
);
2711 mutex_unlock(&priv
->fbs_lock
);
2714 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2715 const char *name
, int num_values
)
2717 struct drm_property
*property
= NULL
;
2720 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2725 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2726 if (!property
->values
)
2730 ret
= drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2734 property
->flags
= flags
;
2735 property
->num_values
= num_values
;
2736 INIT_LIST_HEAD(&property
->enum_blob_list
);
2739 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2740 property
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2743 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2746 kfree(property
->values
);
2750 EXPORT_SYMBOL(drm_property_create
);
2752 struct drm_property
*drm_property_create_enum(struct drm_device
*dev
, int flags
,
2754 const struct drm_prop_enum_list
*props
,
2757 struct drm_property
*property
;
2760 flags
|= DRM_MODE_PROP_ENUM
;
2762 property
= drm_property_create(dev
, flags
, name
, num_values
);
2766 for (i
= 0; i
< num_values
; i
++) {
2767 ret
= drm_property_add_enum(property
, i
,
2771 drm_property_destroy(dev
, property
);
2778 EXPORT_SYMBOL(drm_property_create_enum
);
2780 struct drm_property
*drm_property_create_bitmask(struct drm_device
*dev
,
2781 int flags
, const char *name
,
2782 const struct drm_prop_enum_list
*props
,
2785 struct drm_property
*property
;
2788 flags
|= DRM_MODE_PROP_BITMASK
;
2790 property
= drm_property_create(dev
, flags
, name
, num_values
);
2794 for (i
= 0; i
< num_values
; i
++) {
2795 ret
= drm_property_add_enum(property
, i
,
2799 drm_property_destroy(dev
, property
);
2806 EXPORT_SYMBOL(drm_property_create_bitmask
);
2808 struct drm_property
*drm_property_create_range(struct drm_device
*dev
, int flags
,
2810 uint64_t min
, uint64_t max
)
2812 struct drm_property
*property
;
2814 flags
|= DRM_MODE_PROP_RANGE
;
2816 property
= drm_property_create(dev
, flags
, name
, 2);
2820 property
->values
[0] = min
;
2821 property
->values
[1] = max
;
2825 EXPORT_SYMBOL(drm_property_create_range
);
2827 int drm_property_add_enum(struct drm_property
*property
, int index
,
2828 uint64_t value
, const char *name
)
2830 struct drm_property_enum
*prop_enum
;
2832 if (!(property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)))
2836 * Bitmask enum properties have the additional constraint of values
2839 if ((property
->flags
& DRM_MODE_PROP_BITMASK
) && (value
> 63))
2842 if (!list_empty(&property
->enum_blob_list
)) {
2843 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2844 if (prop_enum
->value
== value
) {
2845 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2846 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2852 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2856 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2857 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2858 prop_enum
->value
= value
;
2860 property
->values
[index
] = value
;
2861 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2864 EXPORT_SYMBOL(drm_property_add_enum
);
2866 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2868 struct drm_property_enum
*prop_enum
, *pt
;
2870 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2871 list_del(&prop_enum
->head
);
2875 if (property
->num_values
)
2876 kfree(property
->values
);
2877 drm_mode_object_put(dev
, &property
->base
);
2878 list_del(&property
->head
);
2881 EXPORT_SYMBOL(drm_property_destroy
);
2883 void drm_object_attach_property(struct drm_mode_object
*obj
,
2884 struct drm_property
*property
,
2887 int count
= obj
->properties
->count
;
2889 if (count
== DRM_OBJECT_MAX_PROPERTY
) {
2890 WARN(1, "Failed to attach object property (type: 0x%x). Please "
2891 "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time "
2892 "you see this message on the same object type.\n",
2897 obj
->properties
->ids
[count
] = property
->base
.id
;
2898 obj
->properties
->values
[count
] = init_val
;
2899 obj
->properties
->count
++;
2901 EXPORT_SYMBOL(drm_object_attach_property
);
2903 int drm_object_property_set_value(struct drm_mode_object
*obj
,
2904 struct drm_property
*property
, uint64_t val
)
2908 for (i
= 0; i
< obj
->properties
->count
; i
++) {
2909 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
2910 obj
->properties
->values
[i
] = val
;
2917 EXPORT_SYMBOL(drm_object_property_set_value
);
2919 int drm_object_property_get_value(struct drm_mode_object
*obj
,
2920 struct drm_property
*property
, uint64_t *val
)
2924 for (i
= 0; i
< obj
->properties
->count
; i
++) {
2925 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
2926 *val
= obj
->properties
->values
[i
];
2933 EXPORT_SYMBOL(drm_object_property_get_value
);
2935 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2936 void *data
, struct drm_file
*file_priv
)
2938 struct drm_mode_object
*obj
;
2939 struct drm_mode_get_property
*out_resp
= data
;
2940 struct drm_property
*property
;
2943 int value_count
= 0;
2946 struct drm_property_enum
*prop_enum
;
2947 struct drm_mode_property_enum __user
*enum_ptr
;
2948 struct drm_property_blob
*prop_blob
;
2949 uint32_t __user
*blob_id_ptr
;
2950 uint64_t __user
*values_ptr
;
2951 uint32_t __user
*blob_length_ptr
;
2953 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2956 drm_modeset_lock_all(dev
);
2957 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2962 property
= obj_to_property(obj
);
2964 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
2965 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
2967 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2968 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
2972 value_count
= property
->num_values
;
2974 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
2975 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
2976 out_resp
->flags
= property
->flags
;
2978 if ((out_resp
->count_values
>= value_count
) && value_count
) {
2979 values_ptr
= (uint64_t __user
*)(unsigned long)out_resp
->values_ptr
;
2980 for (i
= 0; i
< value_count
; i
++) {
2981 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
2987 out_resp
->count_values
= value_count
;
2989 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
2990 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
2992 enum_ptr
= (struct drm_mode_property_enum __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
2993 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2995 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
3000 if (copy_to_user(&enum_ptr
[copied
].name
,
3001 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
3008 out_resp
->count_enum_blobs
= enum_count
;
3011 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3012 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
3014 blob_id_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3015 blob_length_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->values_ptr
;
3017 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
3018 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
3023 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
3031 out_resp
->count_enum_blobs
= blob_count
;
3034 drm_modeset_unlock_all(dev
);
3038 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
3041 struct drm_property_blob
*blob
;
3044 if (!length
|| !data
)
3047 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
3051 ret
= drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
3057 blob
->length
= length
;
3059 memcpy(blob
->data
, data
, length
);
3061 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
3065 static void drm_property_destroy_blob(struct drm_device
*dev
,
3066 struct drm_property_blob
*blob
)
3068 drm_mode_object_put(dev
, &blob
->base
);
3069 list_del(&blob
->head
);
3073 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
3074 void *data
, struct drm_file
*file_priv
)
3076 struct drm_mode_object
*obj
;
3077 struct drm_mode_get_blob
*out_resp
= data
;
3078 struct drm_property_blob
*blob
;
3080 void __user
*blob_ptr
;
3082 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3085 drm_modeset_lock_all(dev
);
3086 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
3091 blob
= obj_to_blob(obj
);
3093 if (out_resp
->length
== blob
->length
) {
3094 blob_ptr
= (void __user
*)(unsigned long)out_resp
->data
;
3095 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
3100 out_resp
->length
= blob
->length
;
3103 drm_modeset_unlock_all(dev
);
3107 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
3110 struct drm_device
*dev
= connector
->dev
;
3113 if (connector
->edid_blob_ptr
)
3114 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
3116 /* Delete edid, when there is none. */
3118 connector
->edid_blob_ptr
= NULL
;
3119 ret
= drm_object_property_set_value(&connector
->base
, dev
->mode_config
.edid_property
, 0);
3123 size
= EDID_LENGTH
* (1 + edid
->extensions
);
3124 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
3126 if (!connector
->edid_blob_ptr
)
3129 ret
= drm_object_property_set_value(&connector
->base
,
3130 dev
->mode_config
.edid_property
,
3131 connector
->edid_blob_ptr
->base
.id
);
3135 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
3137 static bool drm_property_change_is_valid(struct drm_property
*property
,
3140 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
3142 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
3143 if (value
< property
->values
[0] || value
> property
->values
[1])
3146 } else if (property
->flags
& DRM_MODE_PROP_BITMASK
) {
3148 uint64_t valid_mask
= 0;
3149 for (i
= 0; i
< property
->num_values
; i
++)
3150 valid_mask
|= (1ULL << property
->values
[i
]);
3151 return !(value
& ~valid_mask
);
3152 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3153 /* Only the driver knows */
3157 for (i
= 0; i
< property
->num_values
; i
++)
3158 if (property
->values
[i
] == value
)
3164 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
3165 void *data
, struct drm_file
*file_priv
)
3167 struct drm_mode_connector_set_property
*conn_set_prop
= data
;
3168 struct drm_mode_obj_set_property obj_set_prop
= {
3169 .value
= conn_set_prop
->value
,
3170 .prop_id
= conn_set_prop
->prop_id
,
3171 .obj_id
= conn_set_prop
->connector_id
,
3172 .obj_type
= DRM_MODE_OBJECT_CONNECTOR
3175 /* It does all the locking and checking we need */
3176 return drm_mode_obj_set_property_ioctl(dev
, &obj_set_prop
, file_priv
);
3179 static int drm_mode_connector_set_obj_prop(struct drm_mode_object
*obj
,
3180 struct drm_property
*property
,
3184 struct drm_connector
*connector
= obj_to_connector(obj
);
3186 /* Do DPMS ourselves */
3187 if (property
== connector
->dev
->mode_config
.dpms_property
) {
3188 if (connector
->funcs
->dpms
)
3189 (*connector
->funcs
->dpms
)(connector
, (int)value
);
3191 } else if (connector
->funcs
->set_property
)
3192 ret
= connector
->funcs
->set_property(connector
, property
, value
);
3194 /* store the property value if successful */
3196 drm_object_property_set_value(&connector
->base
, property
, value
);
3200 static int drm_mode_crtc_set_obj_prop(struct drm_mode_object
*obj
,
3201 struct drm_property
*property
,
3205 struct drm_crtc
*crtc
= obj_to_crtc(obj
);
3207 if (crtc
->funcs
->set_property
)
3208 ret
= crtc
->funcs
->set_property(crtc
, property
, value
);
3210 drm_object_property_set_value(obj
, property
, value
);
3215 static int drm_mode_plane_set_obj_prop(struct drm_mode_object
*obj
,
3216 struct drm_property
*property
,
3220 struct drm_plane
*plane
= obj_to_plane(obj
);
3222 if (plane
->funcs
->set_property
)
3223 ret
= plane
->funcs
->set_property(plane
, property
, value
);
3225 drm_object_property_set_value(obj
, property
, value
);
3230 int drm_mode_obj_get_properties_ioctl(struct drm_device
*dev
, void *data
,
3231 struct drm_file
*file_priv
)
3233 struct drm_mode_obj_get_properties
*arg
= data
;
3234 struct drm_mode_object
*obj
;
3238 int props_count
= 0;
3239 uint32_t __user
*props_ptr
;
3240 uint64_t __user
*prop_values_ptr
;
3242 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3245 drm_modeset_lock_all(dev
);
3247 obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3252 if (!obj
->properties
) {
3257 props_count
= obj
->properties
->count
;
3259 /* This ioctl is called twice, once to determine how much space is
3260 * needed, and the 2nd time to fill it. */
3261 if ((arg
->count_props
>= props_count
) && props_count
) {
3263 props_ptr
= (uint32_t __user
*)(unsigned long)(arg
->props_ptr
);
3264 prop_values_ptr
= (uint64_t __user
*)(unsigned long)
3265 (arg
->prop_values_ptr
);
3266 for (i
= 0; i
< props_count
; i
++) {
3267 if (put_user(obj
->properties
->ids
[i
],
3268 props_ptr
+ copied
)) {
3272 if (put_user(obj
->properties
->values
[i
],
3273 prop_values_ptr
+ copied
)) {
3280 arg
->count_props
= props_count
;
3282 drm_modeset_unlock_all(dev
);
3286 int drm_mode_obj_set_property_ioctl(struct drm_device
*dev
, void *data
,
3287 struct drm_file
*file_priv
)
3289 struct drm_mode_obj_set_property
*arg
= data
;
3290 struct drm_mode_object
*arg_obj
;
3291 struct drm_mode_object
*prop_obj
;
3292 struct drm_property
*property
;
3296 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3299 drm_modeset_lock_all(dev
);
3301 arg_obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3304 if (!arg_obj
->properties
)
3307 for (i
= 0; i
< arg_obj
->properties
->count
; i
++)
3308 if (arg_obj
->properties
->ids
[i
] == arg
->prop_id
)
3311 if (i
== arg_obj
->properties
->count
)
3314 prop_obj
= drm_mode_object_find(dev
, arg
->prop_id
,
3315 DRM_MODE_OBJECT_PROPERTY
);
3318 property
= obj_to_property(prop_obj
);
3320 if (!drm_property_change_is_valid(property
, arg
->value
))
3323 switch (arg_obj
->type
) {
3324 case DRM_MODE_OBJECT_CONNECTOR
:
3325 ret
= drm_mode_connector_set_obj_prop(arg_obj
, property
,
3328 case DRM_MODE_OBJECT_CRTC
:
3329 ret
= drm_mode_crtc_set_obj_prop(arg_obj
, property
, arg
->value
);
3331 case DRM_MODE_OBJECT_PLANE
:
3332 ret
= drm_mode_plane_set_obj_prop(arg_obj
, property
, arg
->value
);
3337 drm_modeset_unlock_all(dev
);
3341 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
3342 struct drm_encoder
*encoder
)
3346 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3347 if (connector
->encoder_ids
[i
] == 0) {
3348 connector
->encoder_ids
[i
] = encoder
->base
.id
;
3354 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
3356 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
3357 struct drm_encoder
*encoder
)
3360 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3361 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
3362 connector
->encoder_ids
[i
] = 0;
3363 if (connector
->encoder
== encoder
)
3364 connector
->encoder
= NULL
;
3369 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
3371 int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
3374 crtc
->gamma_size
= gamma_size
;
3376 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
3377 if (!crtc
->gamma_store
) {
3378 crtc
->gamma_size
= 0;
3384 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
3386 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
3387 void *data
, struct drm_file
*file_priv
)
3389 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3390 struct drm_mode_object
*obj
;
3391 struct drm_crtc
*crtc
;
3392 void *r_base
, *g_base
, *b_base
;
3396 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3399 drm_modeset_lock_all(dev
);
3400 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3405 crtc
= obj_to_crtc(obj
);
3407 if (crtc
->funcs
->gamma_set
== NULL
) {
3412 /* memcpy into gamma store */
3413 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3418 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3419 r_base
= crtc
->gamma_store
;
3420 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
3425 g_base
= r_base
+ size
;
3426 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
3431 b_base
= g_base
+ size
;
3432 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
3437 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
3440 drm_modeset_unlock_all(dev
);
3445 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
3446 void *data
, struct drm_file
*file_priv
)
3448 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3449 struct drm_mode_object
*obj
;
3450 struct drm_crtc
*crtc
;
3451 void *r_base
, *g_base
, *b_base
;
3455 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3458 drm_modeset_lock_all(dev
);
3459 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3464 crtc
= obj_to_crtc(obj
);
3466 /* memcpy into gamma store */
3467 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3472 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3473 r_base
= crtc
->gamma_store
;
3474 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
3479 g_base
= r_base
+ size
;
3480 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
3485 b_base
= g_base
+ size
;
3486 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
3491 drm_modeset_unlock_all(dev
);
3495 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
3496 void *data
, struct drm_file
*file_priv
)
3498 struct drm_mode_crtc_page_flip
*page_flip
= data
;
3499 struct drm_mode_object
*obj
;
3500 struct drm_crtc
*crtc
;
3501 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
3502 struct drm_pending_vblank_event
*e
= NULL
;
3503 unsigned long flags
;
3504 int hdisplay
, vdisplay
;
3507 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
3508 page_flip
->reserved
!= 0)
3511 if ((page_flip
->flags
& DRM_MODE_PAGE_FLIP_ASYNC
) && !dev
->mode_config
.async_page_flip
)
3514 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3517 crtc
= obj_to_crtc(obj
);
3519 mutex_lock(&crtc
->mutex
);
3520 if (crtc
->fb
== NULL
) {
3521 /* The framebuffer is currently unbound, presumably
3522 * due to a hotplug event, that userspace has not
3529 if (crtc
->funcs
->page_flip
== NULL
)
3532 fb
= drm_framebuffer_lookup(dev
, page_flip
->fb_id
);
3536 hdisplay
= crtc
->mode
.hdisplay
;
3537 vdisplay
= crtc
->mode
.vdisplay
;
3539 if (crtc
->invert_dimensions
)
3540 swap(hdisplay
, vdisplay
);
3542 if (hdisplay
> fb
->width
||
3543 vdisplay
> fb
->height
||
3544 crtc
->x
> fb
->width
- hdisplay
||
3545 crtc
->y
> fb
->height
- vdisplay
) {
3546 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
3547 fb
->width
, fb
->height
, hdisplay
, vdisplay
, crtc
->x
, crtc
->y
,
3548 crtc
->invert_dimensions
? " (inverted)" : "");
3553 if (crtc
->fb
->pixel_format
!= fb
->pixel_format
) {
3554 DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n");
3559 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3561 spin_lock_irqsave(&dev
->event_lock
, flags
);
3562 if (file_priv
->event_space
< sizeof e
->event
) {
3563 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3566 file_priv
->event_space
-= sizeof e
->event
;
3567 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3569 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
3571 spin_lock_irqsave(&dev
->event_lock
, flags
);
3572 file_priv
->event_space
+= sizeof e
->event
;
3573 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3577 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
3578 e
->event
.base
.length
= sizeof e
->event
;
3579 e
->event
.user_data
= page_flip
->user_data
;
3580 e
->base
.event
= &e
->event
.base
;
3581 e
->base
.file_priv
= file_priv
;
3583 (void (*) (struct drm_pending_event
*)) kfree
;
3587 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
, page_flip
->flags
);
3589 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3590 spin_lock_irqsave(&dev
->event_lock
, flags
);
3591 file_priv
->event_space
+= sizeof e
->event
;
3592 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3595 /* Keep the old fb, don't unref it. */
3599 * Warn if the driver hasn't properly updated the crtc->fb
3600 * field to reflect that the new framebuffer is now used.
3601 * Failing to do so will screw with the reference counting
3604 WARN_ON(crtc
->fb
!= fb
);
3605 /* Unref only the old framebuffer. */
3611 drm_framebuffer_unreference(fb
);
3613 drm_framebuffer_unreference(old_fb
);
3614 mutex_unlock(&crtc
->mutex
);
3619 void drm_mode_config_reset(struct drm_device
*dev
)
3621 struct drm_crtc
*crtc
;
3622 struct drm_encoder
*encoder
;
3623 struct drm_connector
*connector
;
3625 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
3626 if (crtc
->funcs
->reset
)
3627 crtc
->funcs
->reset(crtc
);
3629 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
3630 if (encoder
->funcs
->reset
)
3631 encoder
->funcs
->reset(encoder
);
3633 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
3634 connector
->status
= connector_status_unknown
;
3636 if (connector
->funcs
->reset
)
3637 connector
->funcs
->reset(connector
);
3640 EXPORT_SYMBOL(drm_mode_config_reset
);
3642 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
3643 void *data
, struct drm_file
*file_priv
)
3645 struct drm_mode_create_dumb
*args
= data
;
3647 if (!dev
->driver
->dumb_create
)
3649 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
3652 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
3653 void *data
, struct drm_file
*file_priv
)
3655 struct drm_mode_map_dumb
*args
= data
;
3657 /* call driver ioctl to get mmap offset */
3658 if (!dev
->driver
->dumb_map_offset
)
3661 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
3664 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
3665 void *data
, struct drm_file
*file_priv
)
3667 struct drm_mode_destroy_dumb
*args
= data
;
3669 if (!dev
->driver
->dumb_destroy
)
3672 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
3676 * Just need to support RGB formats here for compat with code that doesn't
3677 * use pixel formats directly yet.
3679 void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
3684 case DRM_FORMAT_RGB332
:
3685 case DRM_FORMAT_BGR233
:
3689 case DRM_FORMAT_XRGB1555
:
3690 case DRM_FORMAT_XBGR1555
:
3691 case DRM_FORMAT_RGBX5551
:
3692 case DRM_FORMAT_BGRX5551
:
3693 case DRM_FORMAT_ARGB1555
:
3694 case DRM_FORMAT_ABGR1555
:
3695 case DRM_FORMAT_RGBA5551
:
3696 case DRM_FORMAT_BGRA5551
:
3700 case DRM_FORMAT_RGB565
:
3701 case DRM_FORMAT_BGR565
:
3705 case DRM_FORMAT_RGB888
:
3706 case DRM_FORMAT_BGR888
:
3710 case DRM_FORMAT_XRGB8888
:
3711 case DRM_FORMAT_XBGR8888
:
3712 case DRM_FORMAT_RGBX8888
:
3713 case DRM_FORMAT_BGRX8888
:
3717 case DRM_FORMAT_XRGB2101010
:
3718 case DRM_FORMAT_XBGR2101010
:
3719 case DRM_FORMAT_RGBX1010102
:
3720 case DRM_FORMAT_BGRX1010102
:
3721 case DRM_FORMAT_ARGB2101010
:
3722 case DRM_FORMAT_ABGR2101010
:
3723 case DRM_FORMAT_RGBA1010102
:
3724 case DRM_FORMAT_BGRA1010102
:
3728 case DRM_FORMAT_ARGB8888
:
3729 case DRM_FORMAT_ABGR8888
:
3730 case DRM_FORMAT_RGBA8888
:
3731 case DRM_FORMAT_BGRA8888
:
3736 DRM_DEBUG_KMS("unsupported pixel format\n");
3742 EXPORT_SYMBOL(drm_fb_get_bpp_depth
);
3745 * drm_format_num_planes - get the number of planes for format
3746 * @format: pixel format (DRM_FORMAT_*)
3749 * The number of planes used by the specified pixel format.
3751 int drm_format_num_planes(uint32_t format
)
3754 case DRM_FORMAT_YUV410
:
3755 case DRM_FORMAT_YVU410
:
3756 case DRM_FORMAT_YUV411
:
3757 case DRM_FORMAT_YVU411
:
3758 case DRM_FORMAT_YUV420
:
3759 case DRM_FORMAT_YVU420
:
3760 case DRM_FORMAT_YUV422
:
3761 case DRM_FORMAT_YVU422
:
3762 case DRM_FORMAT_YUV444
:
3763 case DRM_FORMAT_YVU444
:
3765 case DRM_FORMAT_NV12
:
3766 case DRM_FORMAT_NV21
:
3767 case DRM_FORMAT_NV16
:
3768 case DRM_FORMAT_NV61
:
3769 case DRM_FORMAT_NV24
:
3770 case DRM_FORMAT_NV42
:
3776 EXPORT_SYMBOL(drm_format_num_planes
);
3779 * drm_format_plane_cpp - determine the bytes per pixel value
3780 * @format: pixel format (DRM_FORMAT_*)
3781 * @plane: plane index
3784 * The bytes per pixel value for the specified plane.
3786 int drm_format_plane_cpp(uint32_t format
, int plane
)
3791 if (plane
>= drm_format_num_planes(format
))
3795 case DRM_FORMAT_YUYV
:
3796 case DRM_FORMAT_YVYU
:
3797 case DRM_FORMAT_UYVY
:
3798 case DRM_FORMAT_VYUY
:
3800 case DRM_FORMAT_NV12
:
3801 case DRM_FORMAT_NV21
:
3802 case DRM_FORMAT_NV16
:
3803 case DRM_FORMAT_NV61
:
3804 case DRM_FORMAT_NV24
:
3805 case DRM_FORMAT_NV42
:
3806 return plane
? 2 : 1;
3807 case DRM_FORMAT_YUV410
:
3808 case DRM_FORMAT_YVU410
:
3809 case DRM_FORMAT_YUV411
:
3810 case DRM_FORMAT_YVU411
:
3811 case DRM_FORMAT_YUV420
:
3812 case DRM_FORMAT_YVU420
:
3813 case DRM_FORMAT_YUV422
:
3814 case DRM_FORMAT_YVU422
:
3815 case DRM_FORMAT_YUV444
:
3816 case DRM_FORMAT_YVU444
:
3819 drm_fb_get_bpp_depth(format
, &depth
, &bpp
);
3823 EXPORT_SYMBOL(drm_format_plane_cpp
);
3826 * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
3827 * @format: pixel format (DRM_FORMAT_*)
3830 * The horizontal chroma subsampling factor for the
3831 * specified pixel format.
3833 int drm_format_horz_chroma_subsampling(uint32_t format
)
3836 case DRM_FORMAT_YUV411
:
3837 case DRM_FORMAT_YVU411
:
3838 case DRM_FORMAT_YUV410
:
3839 case DRM_FORMAT_YVU410
:
3841 case DRM_FORMAT_YUYV
:
3842 case DRM_FORMAT_YVYU
:
3843 case DRM_FORMAT_UYVY
:
3844 case DRM_FORMAT_VYUY
:
3845 case DRM_FORMAT_NV12
:
3846 case DRM_FORMAT_NV21
:
3847 case DRM_FORMAT_NV16
:
3848 case DRM_FORMAT_NV61
:
3849 case DRM_FORMAT_YUV422
:
3850 case DRM_FORMAT_YVU422
:
3851 case DRM_FORMAT_YUV420
:
3852 case DRM_FORMAT_YVU420
:
3858 EXPORT_SYMBOL(drm_format_horz_chroma_subsampling
);
3861 * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
3862 * @format: pixel format (DRM_FORMAT_*)
3865 * The vertical chroma subsampling factor for the
3866 * specified pixel format.
3868 int drm_format_vert_chroma_subsampling(uint32_t format
)
3871 case DRM_FORMAT_YUV410
:
3872 case DRM_FORMAT_YVU410
:
3874 case DRM_FORMAT_YUV420
:
3875 case DRM_FORMAT_YVU420
:
3876 case DRM_FORMAT_NV12
:
3877 case DRM_FORMAT_NV21
:
3883 EXPORT_SYMBOL(drm_format_vert_chroma_subsampling
);
3886 * drm_mode_config_init - initialize DRM mode_configuration structure
3889 * Initialize @dev's mode_config structure, used for tracking the graphics
3890 * configuration of @dev.
3892 * Since this initializes the modeset locks, no locking is possible. Which is no
3893 * problem, since this should happen single threaded at init time. It is the
3894 * driver's problem to ensure this guarantee.
3897 void drm_mode_config_init(struct drm_device
*dev
)
3899 mutex_init(&dev
->mode_config
.mutex
);
3900 mutex_init(&dev
->mode_config
.idr_mutex
);
3901 mutex_init(&dev
->mode_config
.fb_lock
);
3902 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
3903 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
3904 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
3905 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
3906 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
3907 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
3908 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
3909 idr_init(&dev
->mode_config
.crtc_idr
);
3911 drm_modeset_lock_all(dev
);
3912 drm_mode_create_standard_connector_properties(dev
);
3913 drm_modeset_unlock_all(dev
);
3915 /* Just to be sure */
3916 dev
->mode_config
.num_fb
= 0;
3917 dev
->mode_config
.num_connector
= 0;
3918 dev
->mode_config
.num_crtc
= 0;
3919 dev
->mode_config
.num_encoder
= 0;
3921 EXPORT_SYMBOL(drm_mode_config_init
);
3924 * drm_mode_config_cleanup - free up DRM mode_config info
3927 * Free up all the connectors and CRTCs associated with this DRM device, then
3928 * free up the framebuffers and associated buffer objects.
3930 * Note that since this /should/ happen single-threaded at driver/device
3931 * teardown time, no locking is required. It's the driver's job to ensure that
3932 * this guarantee actually holds true.
3934 * FIXME: cleanup any dangling user buffer objects too
3936 void drm_mode_config_cleanup(struct drm_device
*dev
)
3938 struct drm_connector
*connector
, *ot
;
3939 struct drm_crtc
*crtc
, *ct
;
3940 struct drm_encoder
*encoder
, *enct
;
3941 struct drm_framebuffer
*fb
, *fbt
;
3942 struct drm_property
*property
, *pt
;
3943 struct drm_property_blob
*blob
, *bt
;
3944 struct drm_plane
*plane
, *plt
;
3946 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
3948 encoder
->funcs
->destroy(encoder
);
3951 list_for_each_entry_safe(connector
, ot
,
3952 &dev
->mode_config
.connector_list
, head
) {
3953 connector
->funcs
->destroy(connector
);
3956 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
3958 drm_property_destroy(dev
, property
);
3961 list_for_each_entry_safe(blob
, bt
, &dev
->mode_config
.property_blob_list
,
3963 drm_property_destroy_blob(dev
, blob
);
3967 * Single-threaded teardown context, so it's not required to grab the
3968 * fb_lock to protect against concurrent fb_list access. Contrary, it
3969 * would actually deadlock with the drm_framebuffer_cleanup function.
3971 * Also, if there are any framebuffers left, that's a driver leak now,
3972 * so politely WARN about this.
3974 WARN_ON(!list_empty(&dev
->mode_config
.fb_list
));
3975 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
3976 drm_framebuffer_remove(fb
);
3979 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
3981 plane
->funcs
->destroy(plane
);
3984 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
3985 crtc
->funcs
->destroy(crtc
);
3988 idr_destroy(&dev
->mode_config
.crtc_idr
);
3990 EXPORT_SYMBOL(drm_mode_config_cleanup
);