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" },
128 static const struct drm_prop_enum_list drm_dithering_mode_enum_list
[] =
130 { DRM_MODE_DITHERING_OFF
, "Off" },
131 { DRM_MODE_DITHERING_ON
, "On" },
132 { DRM_MODE_DITHERING_AUTO
, "Automatic" },
136 * Non-global properties, but "required" for certain connectors.
138 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
140 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
141 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
142 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
145 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
147 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
149 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
150 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
151 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
154 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
155 drm_dvi_i_subconnector_enum_list
)
157 static const struct drm_prop_enum_list drm_tv_select_enum_list
[] =
159 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
160 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
161 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
162 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
163 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
166 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
168 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
170 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
171 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
172 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
173 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
174 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
177 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
178 drm_tv_subconnector_enum_list
)
180 static const struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
181 { DRM_MODE_DIRTY_OFF
, "Off" },
182 { DRM_MODE_DIRTY_ON
, "On" },
183 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
186 struct drm_conn_prop_enum_list
{
193 * Connector and encoder types.
195 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
196 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
197 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
198 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
199 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
200 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
201 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
202 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
203 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
204 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
205 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN", 0 },
206 { DRM_MODE_CONNECTOR_DisplayPort
, "DP", 0 },
207 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A", 0 },
208 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B", 0 },
209 { DRM_MODE_CONNECTOR_TV
, "TV", 0 },
210 { DRM_MODE_CONNECTOR_eDP
, "eDP", 0 },
211 { DRM_MODE_CONNECTOR_VIRTUAL
, "Virtual", 0},
214 static const struct drm_prop_enum_list drm_encoder_enum_list
[] =
215 { { DRM_MODE_ENCODER_NONE
, "None" },
216 { DRM_MODE_ENCODER_DAC
, "DAC" },
217 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
218 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
219 { DRM_MODE_ENCODER_TVDAC
, "TV" },
220 { DRM_MODE_ENCODER_VIRTUAL
, "Virtual" },
223 const char *drm_get_encoder_name(const struct drm_encoder
*encoder
)
227 snprintf(buf
, 32, "%s-%d",
228 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
232 EXPORT_SYMBOL(drm_get_encoder_name
);
234 const char *drm_get_connector_name(const struct drm_connector
*connector
)
238 snprintf(buf
, 32, "%s-%d",
239 drm_connector_enum_list
[connector
->connector_type
].name
,
240 connector
->connector_type_id
);
243 EXPORT_SYMBOL(drm_get_connector_name
);
245 const char *drm_get_connector_status_name(enum drm_connector_status status
)
247 if (status
== connector_status_connected
)
249 else if (status
== connector_status_disconnected
)
250 return "disconnected";
254 EXPORT_SYMBOL(drm_get_connector_status_name
);
256 static char printable_char(int c
)
258 return isascii(c
) && isprint(c
) ? c
: '?';
261 const char *drm_get_format_name(uint32_t format
)
265 snprintf(buf
, sizeof(buf
),
266 "%c%c%c%c %s-endian (0x%08x)",
267 printable_char(format
& 0xff),
268 printable_char((format
>> 8) & 0xff),
269 printable_char((format
>> 16) & 0xff),
270 printable_char((format
>> 24) & 0x7f),
271 format
& DRM_FORMAT_BIG_ENDIAN
? "big" : "little",
276 EXPORT_SYMBOL(drm_get_format_name
);
279 * drm_mode_object_get - allocate a new modeset identifier
281 * @obj: object pointer, used to generate unique ID
282 * @obj_type: object type
284 * Create a unique identifier based on @ptr in @dev's identifier space. Used
285 * for tracking modes, CRTCs and connectors.
288 * New unique (relative to other objects in @dev) integer identifier for the
291 static int drm_mode_object_get(struct drm_device
*dev
,
292 struct drm_mode_object
*obj
, uint32_t obj_type
)
296 mutex_lock(&dev
->mode_config
.idr_mutex
);
297 ret
= idr_alloc(&dev
->mode_config
.crtc_idr
, obj
, 1, 0, GFP_KERNEL
);
300 * Set up the object linking under the protection of the idr
301 * lock so that other users can't see inconsistent state.
304 obj
->type
= obj_type
;
306 mutex_unlock(&dev
->mode_config
.idr_mutex
);
308 return ret
< 0 ? ret
: 0;
312 * drm_mode_object_put - free a modeset identifer
314 * @object: object to free
316 * Free @id from @dev's unique identifier pool.
318 static void drm_mode_object_put(struct drm_device
*dev
,
319 struct drm_mode_object
*object
)
321 mutex_lock(&dev
->mode_config
.idr_mutex
);
322 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
323 mutex_unlock(&dev
->mode_config
.idr_mutex
);
327 * drm_mode_object_find - look up a drm object with static lifetime
329 * @id: id of the mode object
330 * @type: type of the mode object
332 * Note that framebuffers cannot be looked up with this functions - since those
333 * are reference counted, they need special treatment.
335 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
336 uint32_t id
, uint32_t type
)
338 struct drm_mode_object
*obj
= NULL
;
340 /* Framebuffers are reference counted and need their own lookup
342 WARN_ON(type
== DRM_MODE_OBJECT_FB
);
344 mutex_lock(&dev
->mode_config
.idr_mutex
);
345 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
346 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
348 mutex_unlock(&dev
->mode_config
.idr_mutex
);
352 EXPORT_SYMBOL(drm_mode_object_find
);
355 * drm_framebuffer_init - initialize a framebuffer
357 * @fb: framebuffer to be initialized
358 * @funcs: ... with these functions
360 * Allocates an ID for the framebuffer's parent mode object, sets its mode
361 * functions & device file and adds it to the master fd list.
364 * This functions publishes the fb and makes it available for concurrent access
365 * by other users. Which means by this point the fb _must_ be fully set up -
366 * since all the fb attributes are invariant over its lifetime, no further
367 * locking but only correct reference counting is required.
370 * Zero on success, error code on failure.
372 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
373 const struct drm_framebuffer_funcs
*funcs
)
377 mutex_lock(&dev
->mode_config
.fb_lock
);
378 kref_init(&fb
->refcount
);
379 INIT_LIST_HEAD(&fb
->filp_head
);
383 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
387 /* Grab the idr reference. */
388 drm_framebuffer_reference(fb
);
390 dev
->mode_config
.num_fb
++;
391 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
393 mutex_unlock(&dev
->mode_config
.fb_lock
);
397 EXPORT_SYMBOL(drm_framebuffer_init
);
399 static void drm_framebuffer_free(struct kref
*kref
)
401 struct drm_framebuffer
*fb
=
402 container_of(kref
, struct drm_framebuffer
, refcount
);
403 fb
->funcs
->destroy(fb
);
406 static struct drm_framebuffer
*__drm_framebuffer_lookup(struct drm_device
*dev
,
409 struct drm_mode_object
*obj
= NULL
;
410 struct drm_framebuffer
*fb
;
412 mutex_lock(&dev
->mode_config
.idr_mutex
);
413 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
414 if (!obj
|| (obj
->type
!= DRM_MODE_OBJECT_FB
) || (obj
->id
!= id
))
418 mutex_unlock(&dev
->mode_config
.idr_mutex
);
424 * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
426 * @id: id of the fb object
428 * If successful, this grabs an additional reference to the framebuffer -
429 * callers need to make sure to eventually unreference the returned framebuffer
432 struct drm_framebuffer
*drm_framebuffer_lookup(struct drm_device
*dev
,
435 struct drm_framebuffer
*fb
;
437 mutex_lock(&dev
->mode_config
.fb_lock
);
438 fb
= __drm_framebuffer_lookup(dev
, id
);
440 drm_framebuffer_reference(fb
);
441 mutex_unlock(&dev
->mode_config
.fb_lock
);
445 EXPORT_SYMBOL(drm_framebuffer_lookup
);
448 * drm_framebuffer_unreference - unref a framebuffer
449 * @fb: framebuffer to unref
451 * This functions decrements the fb's refcount and frees it if it drops to zero.
453 void drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
455 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
456 kref_put(&fb
->refcount
, drm_framebuffer_free
);
458 EXPORT_SYMBOL(drm_framebuffer_unreference
);
461 * drm_framebuffer_reference - incr the fb refcnt
464 void drm_framebuffer_reference(struct drm_framebuffer
*fb
)
466 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
467 kref_get(&fb
->refcount
);
469 EXPORT_SYMBOL(drm_framebuffer_reference
);
471 static void drm_framebuffer_free_bug(struct kref
*kref
)
476 static void __drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
478 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
479 kref_put(&fb
->refcount
, drm_framebuffer_free_bug
);
482 /* dev->mode_config.fb_lock must be held! */
483 static void __drm_framebuffer_unregister(struct drm_device
*dev
,
484 struct drm_framebuffer
*fb
)
486 mutex_lock(&dev
->mode_config
.idr_mutex
);
487 idr_remove(&dev
->mode_config
.crtc_idr
, fb
->base
.id
);
488 mutex_unlock(&dev
->mode_config
.idr_mutex
);
492 __drm_framebuffer_unreference(fb
);
496 * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
497 * @fb: fb to unregister
499 * Drivers need to call this when cleaning up driver-private framebuffers, e.g.
500 * those used for fbdev. Note that the caller must hold a reference of it's own,
501 * i.e. the object may not be destroyed through this call (since it'll lead to a
502 * locking inversion).
504 void drm_framebuffer_unregister_private(struct drm_framebuffer
*fb
)
506 struct drm_device
*dev
= fb
->dev
;
508 mutex_lock(&dev
->mode_config
.fb_lock
);
509 /* Mark fb as reaped and drop idr ref. */
510 __drm_framebuffer_unregister(dev
, fb
);
511 mutex_unlock(&dev
->mode_config
.fb_lock
);
513 EXPORT_SYMBOL(drm_framebuffer_unregister_private
);
516 * drm_framebuffer_cleanup - remove a framebuffer object
517 * @fb: framebuffer to remove
519 * Cleanup references to a user-created framebuffer. This function is intended
520 * to be used from the drivers ->destroy callback.
522 * Note that this function does not remove the fb from active usuage - if it is
523 * still used anywhere, hilarity can ensue since userspace could call getfb on
524 * the id and get back -EINVAL. Obviously no concern at driver unload time.
526 * Also, the framebuffer will not be removed from the lookup idr - for
527 * user-created framebuffers this will happen in in the rmfb ioctl. For
528 * driver-private objects (e.g. for fbdev) drivers need to explicitly call
529 * drm_framebuffer_unregister_private.
531 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
533 struct drm_device
*dev
= fb
->dev
;
535 mutex_lock(&dev
->mode_config
.fb_lock
);
537 dev
->mode_config
.num_fb
--;
538 mutex_unlock(&dev
->mode_config
.fb_lock
);
540 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
543 * drm_framebuffer_remove - remove and unreference a framebuffer object
544 * @fb: framebuffer to remove
546 * Scans all the CRTCs and planes in @dev's mode_config. If they're
547 * using @fb, removes it, setting it to NULL. Then drops the reference to the
548 * passed-in framebuffer. Might take the modeset locks.
550 * Note that this function optimizes the cleanup away if the caller holds the
551 * last reference to the framebuffer. It is also guaranteed to not take the
552 * modeset locks in this case.
554 void drm_framebuffer_remove(struct drm_framebuffer
*fb
)
556 struct drm_device
*dev
= fb
->dev
;
557 struct drm_crtc
*crtc
;
558 struct drm_plane
*plane
;
559 struct drm_mode_set set
;
562 WARN_ON(!list_empty(&fb
->filp_head
));
565 * drm ABI mandates that we remove any deleted framebuffers from active
566 * useage. But since most sane clients only remove framebuffers they no
567 * longer need, try to optimize this away.
569 * Since we're holding a reference ourselves, observing a refcount of 1
570 * means that we're the last holder and can skip it. Also, the refcount
571 * can never increase from 1 again, so we don't need any barriers or
574 * Note that userspace could try to race with use and instate a new
575 * usage _after_ we've cleared all current ones. End result will be an
576 * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
579 if (atomic_read(&fb
->refcount
.refcount
) > 1) {
580 drm_modeset_lock_all(dev
);
581 /* remove from any CRTC */
582 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
583 if (crtc
->fb
== fb
) {
584 /* should turn off the crtc */
585 memset(&set
, 0, sizeof(struct drm_mode_set
));
588 ret
= drm_mode_set_config_internal(&set
);
590 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
594 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
596 drm_plane_force_disable(plane
);
598 drm_modeset_unlock_all(dev
);
601 drm_framebuffer_unreference(fb
);
603 EXPORT_SYMBOL(drm_framebuffer_remove
);
606 * drm_crtc_init - Initialise a new CRTC object
608 * @crtc: CRTC object to init
609 * @funcs: callbacks for the new CRTC
611 * Inits a new object created as base part of a driver crtc object.
614 * Zero on success, error code on failure.
616 int drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
617 const struct drm_crtc_funcs
*funcs
)
623 crtc
->invert_dimensions
= false;
625 drm_modeset_lock_all(dev
);
626 mutex_init(&crtc
->mutex
);
627 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
629 ret
= drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
633 crtc
->base
.properties
= &crtc
->properties
;
635 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
636 dev
->mode_config
.num_crtc
++;
639 drm_modeset_unlock_all(dev
);
643 EXPORT_SYMBOL(drm_crtc_init
);
646 * drm_crtc_cleanup - Clean up the core crtc usage
647 * @crtc: CRTC to cleanup
649 * This function cleans up @crtc and removes it from the DRM mode setting
650 * core. Note that the function does *not* free the crtc structure itself,
651 * this is the responsibility of the caller.
653 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
655 struct drm_device
*dev
= crtc
->dev
;
657 kfree(crtc
->gamma_store
);
658 crtc
->gamma_store
= NULL
;
660 drm_mode_object_put(dev
, &crtc
->base
);
661 list_del(&crtc
->head
);
662 dev
->mode_config
.num_crtc
--;
664 EXPORT_SYMBOL(drm_crtc_cleanup
);
667 * drm_mode_probed_add - add a mode to a connector's probed mode list
668 * @connector: connector the new mode
671 * Add @mode to @connector's mode list for later use.
673 void drm_mode_probed_add(struct drm_connector
*connector
,
674 struct drm_display_mode
*mode
)
676 list_add_tail(&mode
->head
, &connector
->probed_modes
);
678 EXPORT_SYMBOL(drm_mode_probed_add
);
681 * drm_mode_remove - remove and free a mode
682 * @connector: connector list to modify
683 * @mode: mode to remove
685 * Remove @mode from @connector's mode list, then free it.
687 void drm_mode_remove(struct drm_connector
*connector
,
688 struct drm_display_mode
*mode
)
690 list_del(&mode
->head
);
691 drm_mode_destroy(connector
->dev
, mode
);
693 EXPORT_SYMBOL(drm_mode_remove
);
696 * drm_connector_init - Init a preallocated connector
698 * @connector: the connector to init
699 * @funcs: callbacks for this connector
700 * @connector_type: user visible type of the connector
702 * Initialises a preallocated connector. Connectors should be
703 * subclassed as part of driver connector objects.
706 * Zero on success, error code on failure.
708 int drm_connector_init(struct drm_device
*dev
,
709 struct drm_connector
*connector
,
710 const struct drm_connector_funcs
*funcs
,
715 drm_modeset_lock_all(dev
);
717 ret
= drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
721 connector
->base
.properties
= &connector
->properties
;
722 connector
->dev
= dev
;
723 connector
->funcs
= funcs
;
724 connector
->connector_type
= connector_type
;
725 connector
->connector_type_id
=
726 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
727 INIT_LIST_HEAD(&connector
->probed_modes
);
728 INIT_LIST_HEAD(&connector
->modes
);
729 connector
->edid_blob_ptr
= NULL
;
730 connector
->status
= connector_status_unknown
;
732 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
733 dev
->mode_config
.num_connector
++;
735 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
736 drm_object_attach_property(&connector
->base
,
737 dev
->mode_config
.edid_property
,
740 drm_object_attach_property(&connector
->base
,
741 dev
->mode_config
.dpms_property
, 0);
744 drm_modeset_unlock_all(dev
);
748 EXPORT_SYMBOL(drm_connector_init
);
751 * drm_connector_cleanup - cleans up an initialised connector
752 * @connector: connector to cleanup
754 * Cleans up the connector but doesn't free the object.
756 void drm_connector_cleanup(struct drm_connector
*connector
)
758 struct drm_device
*dev
= connector
->dev
;
759 struct drm_display_mode
*mode
, *t
;
761 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
762 drm_mode_remove(connector
, mode
);
764 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
765 drm_mode_remove(connector
, mode
);
767 drm_mode_object_put(dev
, &connector
->base
);
768 list_del(&connector
->head
);
769 dev
->mode_config
.num_connector
--;
771 EXPORT_SYMBOL(drm_connector_cleanup
);
773 void drm_connector_unplug_all(struct drm_device
*dev
)
775 struct drm_connector
*connector
;
777 /* taking the mode config mutex ends up in a clash with sysfs */
778 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
779 drm_sysfs_connector_remove(connector
);
782 EXPORT_SYMBOL(drm_connector_unplug_all
);
784 int drm_encoder_init(struct drm_device
*dev
,
785 struct drm_encoder
*encoder
,
786 const struct drm_encoder_funcs
*funcs
,
791 drm_modeset_lock_all(dev
);
793 ret
= drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
798 encoder
->encoder_type
= encoder_type
;
799 encoder
->funcs
= funcs
;
801 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
802 dev
->mode_config
.num_encoder
++;
805 drm_modeset_unlock_all(dev
);
809 EXPORT_SYMBOL(drm_encoder_init
);
811 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
813 struct drm_device
*dev
= encoder
->dev
;
814 drm_modeset_lock_all(dev
);
815 drm_mode_object_put(dev
, &encoder
->base
);
816 list_del(&encoder
->head
);
817 dev
->mode_config
.num_encoder
--;
818 drm_modeset_unlock_all(dev
);
820 EXPORT_SYMBOL(drm_encoder_cleanup
);
823 * drm_plane_init - Initialise a new plane object
825 * @plane: plane object to init
826 * @possible_crtcs: bitmask of possible CRTCs
827 * @funcs: callbacks for the new plane
828 * @formats: array of supported formats (%DRM_FORMAT_*)
829 * @format_count: number of elements in @formats
830 * @priv: plane is private (hidden from userspace)?
832 * Inits a new object created as base part of a driver plane object.
835 * Zero on success, error code on failure.
837 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
838 unsigned long possible_crtcs
,
839 const struct drm_plane_funcs
*funcs
,
840 const uint32_t *formats
, uint32_t format_count
,
845 drm_modeset_lock_all(dev
);
847 ret
= drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
851 plane
->base
.properties
= &plane
->properties
;
853 plane
->funcs
= funcs
;
854 plane
->format_types
= kmalloc(sizeof(uint32_t) * format_count
,
856 if (!plane
->format_types
) {
857 DRM_DEBUG_KMS("out of memory when allocating plane\n");
858 drm_mode_object_put(dev
, &plane
->base
);
863 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
864 plane
->format_count
= format_count
;
865 plane
->possible_crtcs
= possible_crtcs
;
867 /* private planes are not exposed to userspace, but depending on
868 * display hardware, might be convenient to allow sharing programming
869 * for the scanout engine with the crtc implementation.
872 list_add_tail(&plane
->head
, &dev
->mode_config
.plane_list
);
873 dev
->mode_config
.num_plane
++;
875 INIT_LIST_HEAD(&plane
->head
);
879 drm_modeset_unlock_all(dev
);
883 EXPORT_SYMBOL(drm_plane_init
);
886 * drm_plane_cleanup - Clean up the core plane usage
887 * @plane: plane to cleanup
889 * This function cleans up @plane and removes it from the DRM mode setting
890 * core. Note that the function does *not* free the plane structure itself,
891 * this is the responsibility of the caller.
893 void drm_plane_cleanup(struct drm_plane
*plane
)
895 struct drm_device
*dev
= plane
->dev
;
897 drm_modeset_lock_all(dev
);
898 kfree(plane
->format_types
);
899 drm_mode_object_put(dev
, &plane
->base
);
900 /* if not added to a list, it must be a private plane */
901 if (!list_empty(&plane
->head
)) {
902 list_del(&plane
->head
);
903 dev
->mode_config
.num_plane
--;
905 drm_modeset_unlock_all(dev
);
907 EXPORT_SYMBOL(drm_plane_cleanup
);
910 * drm_plane_force_disable - Forcibly disable a plane
911 * @plane: plane to disable
913 * Forces the plane to be disabled.
915 * Used when the plane's current framebuffer is destroyed,
916 * and when restoring fbdev mode.
918 void drm_plane_force_disable(struct drm_plane
*plane
)
925 ret
= plane
->funcs
->disable_plane(plane
);
927 DRM_ERROR("failed to disable plane with busy fb\n");
928 /* disconnect the plane from the fb and crtc: */
929 __drm_framebuffer_unreference(plane
->fb
);
933 EXPORT_SYMBOL(drm_plane_force_disable
);
936 * drm_mode_create - create a new display mode
939 * Create a new drm_display_mode, give it an ID, and return it.
942 * Pointer to new mode on success, NULL on error.
944 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
946 struct drm_display_mode
*nmode
;
948 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
952 if (drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
)) {
959 EXPORT_SYMBOL(drm_mode_create
);
962 * drm_mode_destroy - remove a mode
964 * @mode: mode to remove
966 * Free @mode's unique identifier, then free it.
968 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
973 drm_mode_object_put(dev
, &mode
->base
);
977 EXPORT_SYMBOL(drm_mode_destroy
);
979 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
981 struct drm_property
*edid
;
982 struct drm_property
*dpms
;
985 * Standard properties (apply to all connectors)
987 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
988 DRM_MODE_PROP_IMMUTABLE
,
990 dev
->mode_config
.edid_property
= edid
;
992 dpms
= drm_property_create_enum(dev
, 0,
993 "DPMS", drm_dpms_enum_list
,
994 ARRAY_SIZE(drm_dpms_enum_list
));
995 dev
->mode_config
.dpms_property
= dpms
;
1001 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1004 * Called by a driver the first time a DVI-I connector is made.
1006 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
1008 struct drm_property
*dvi_i_selector
;
1009 struct drm_property
*dvi_i_subconnector
;
1011 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
1015 drm_property_create_enum(dev
, 0,
1016 "select subconnector",
1017 drm_dvi_i_select_enum_list
,
1018 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
1019 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
1021 dvi_i_subconnector
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1023 drm_dvi_i_subconnector_enum_list
,
1024 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
1025 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
1029 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
1032 * drm_create_tv_properties - create TV specific connector properties
1034 * @num_modes: number of different TV formats (modes) supported
1035 * @modes: array of pointers to strings containing name of each format
1037 * Called by a driver's TV initialization routine, this function creates
1038 * the TV specific connector properties for a given device. Caller is
1039 * responsible for allocating a list of format names and passing them to
1042 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
1045 struct drm_property
*tv_selector
;
1046 struct drm_property
*tv_subconnector
;
1049 if (dev
->mode_config
.tv_select_subconnector_property
)
1053 * Basic connector properties
1055 tv_selector
= drm_property_create_enum(dev
, 0,
1056 "select subconnector",
1057 drm_tv_select_enum_list
,
1058 ARRAY_SIZE(drm_tv_select_enum_list
));
1059 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
1062 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1064 drm_tv_subconnector_enum_list
,
1065 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
1066 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
1069 * Other, TV specific properties: margins & TV modes.
1071 dev
->mode_config
.tv_left_margin_property
=
1072 drm_property_create_range(dev
, 0, "left margin", 0, 100);
1074 dev
->mode_config
.tv_right_margin_property
=
1075 drm_property_create_range(dev
, 0, "right margin", 0, 100);
1077 dev
->mode_config
.tv_top_margin_property
=
1078 drm_property_create_range(dev
, 0, "top margin", 0, 100);
1080 dev
->mode_config
.tv_bottom_margin_property
=
1081 drm_property_create_range(dev
, 0, "bottom margin", 0, 100);
1083 dev
->mode_config
.tv_mode_property
=
1084 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
1086 for (i
= 0; i
< num_modes
; i
++)
1087 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
1090 dev
->mode_config
.tv_brightness_property
=
1091 drm_property_create_range(dev
, 0, "brightness", 0, 100);
1093 dev
->mode_config
.tv_contrast_property
=
1094 drm_property_create_range(dev
, 0, "contrast", 0, 100);
1096 dev
->mode_config
.tv_flicker_reduction_property
=
1097 drm_property_create_range(dev
, 0, "flicker reduction", 0, 100);
1099 dev
->mode_config
.tv_overscan_property
=
1100 drm_property_create_range(dev
, 0, "overscan", 0, 100);
1102 dev
->mode_config
.tv_saturation_property
=
1103 drm_property_create_range(dev
, 0, "saturation", 0, 100);
1105 dev
->mode_config
.tv_hue_property
=
1106 drm_property_create_range(dev
, 0, "hue", 0, 100);
1110 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
1113 * drm_mode_create_scaling_mode_property - create scaling mode property
1116 * Called by a driver the first time it's needed, must be attached to desired
1119 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
1121 struct drm_property
*scaling_mode
;
1123 if (dev
->mode_config
.scaling_mode_property
)
1127 drm_property_create_enum(dev
, 0, "scaling mode",
1128 drm_scaling_mode_enum_list
,
1129 ARRAY_SIZE(drm_scaling_mode_enum_list
));
1131 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
1135 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
1138 * drm_mode_create_dithering_property - create dithering property
1141 * Called by a driver the first time it's needed, must be attached to desired
1144 int drm_mode_create_dithering_property(struct drm_device
*dev
)
1146 struct drm_property
*dithering_mode
;
1148 if (dev
->mode_config
.dithering_mode_property
)
1152 drm_property_create_enum(dev
, 0, "dithering",
1153 drm_dithering_mode_enum_list
,
1154 ARRAY_SIZE(drm_dithering_mode_enum_list
));
1155 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
1159 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
1162 * drm_mode_create_dirty_property - create dirty property
1165 * Called by a driver the first time it's needed, must be attached to desired
1168 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
1170 struct drm_property
*dirty_info
;
1172 if (dev
->mode_config
.dirty_info_property
)
1176 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1178 drm_dirty_info_enum_list
,
1179 ARRAY_SIZE(drm_dirty_info_enum_list
));
1180 dev
->mode_config
.dirty_info_property
= dirty_info
;
1184 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
1186 static int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
1188 uint32_t total_objects
= 0;
1190 total_objects
+= dev
->mode_config
.num_crtc
;
1191 total_objects
+= dev
->mode_config
.num_connector
;
1192 total_objects
+= dev
->mode_config
.num_encoder
;
1194 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
1195 if (!group
->id_list
)
1198 group
->num_crtcs
= 0;
1199 group
->num_connectors
= 0;
1200 group
->num_encoders
= 0;
1204 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
1205 struct drm_mode_group
*group
)
1207 struct drm_crtc
*crtc
;
1208 struct drm_encoder
*encoder
;
1209 struct drm_connector
*connector
;
1212 if ((ret
= drm_mode_group_init(dev
, group
)))
1215 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
1216 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
1218 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
1219 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
1222 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
1223 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
1224 group
->num_connectors
++] = connector
->base
.id
;
1228 EXPORT_SYMBOL(drm_mode_group_init_legacy_group
);
1231 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1232 * @out: drm_mode_modeinfo struct to return to the user
1233 * @in: drm_display_mode to use
1235 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1238 static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
1239 const struct drm_display_mode
*in
)
1241 WARN(in
->hdisplay
> USHRT_MAX
|| in
->hsync_start
> USHRT_MAX
||
1242 in
->hsync_end
> USHRT_MAX
|| in
->htotal
> USHRT_MAX
||
1243 in
->hskew
> USHRT_MAX
|| in
->vdisplay
> USHRT_MAX
||
1244 in
->vsync_start
> USHRT_MAX
|| in
->vsync_end
> USHRT_MAX
||
1245 in
->vtotal
> USHRT_MAX
|| in
->vscan
> USHRT_MAX
,
1246 "timing values too large for mode info\n");
1248 out
->clock
= in
->clock
;
1249 out
->hdisplay
= in
->hdisplay
;
1250 out
->hsync_start
= in
->hsync_start
;
1251 out
->hsync_end
= in
->hsync_end
;
1252 out
->htotal
= in
->htotal
;
1253 out
->hskew
= in
->hskew
;
1254 out
->vdisplay
= in
->vdisplay
;
1255 out
->vsync_start
= in
->vsync_start
;
1256 out
->vsync_end
= in
->vsync_end
;
1257 out
->vtotal
= in
->vtotal
;
1258 out
->vscan
= in
->vscan
;
1259 out
->vrefresh
= in
->vrefresh
;
1260 out
->flags
= in
->flags
;
1261 out
->type
= in
->type
;
1262 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1263 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1267 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1268 * @out: drm_display_mode to return to the user
1269 * @in: drm_mode_modeinfo to use
1271 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1275 * Zero on success, errno on failure.
1277 static int drm_crtc_convert_umode(struct drm_display_mode
*out
,
1278 const struct drm_mode_modeinfo
*in
)
1280 if (in
->clock
> INT_MAX
|| in
->vrefresh
> INT_MAX
)
1283 out
->clock
= in
->clock
;
1284 out
->hdisplay
= in
->hdisplay
;
1285 out
->hsync_start
= in
->hsync_start
;
1286 out
->hsync_end
= in
->hsync_end
;
1287 out
->htotal
= in
->htotal
;
1288 out
->hskew
= in
->hskew
;
1289 out
->vdisplay
= in
->vdisplay
;
1290 out
->vsync_start
= in
->vsync_start
;
1291 out
->vsync_end
= in
->vsync_end
;
1292 out
->vtotal
= in
->vtotal
;
1293 out
->vscan
= in
->vscan
;
1294 out
->vrefresh
= in
->vrefresh
;
1295 out
->flags
= in
->flags
;
1296 out
->type
= in
->type
;
1297 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1298 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1304 * drm_mode_getresources - get graphics configuration
1305 * @dev: drm device for the ioctl
1306 * @data: data pointer for the ioctl
1307 * @file_priv: drm file for the ioctl call
1309 * Construct a set of configuration description structures and return
1310 * them to the user, including CRTC, connector and framebuffer configuration.
1312 * Called by the user via ioctl.
1315 * Zero on success, errno on failure.
1317 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1318 struct drm_file
*file_priv
)
1320 struct drm_mode_card_res
*card_res
= data
;
1321 struct list_head
*lh
;
1322 struct drm_framebuffer
*fb
;
1323 struct drm_connector
*connector
;
1324 struct drm_crtc
*crtc
;
1325 struct drm_encoder
*encoder
;
1327 int connector_count
= 0;
1330 int encoder_count
= 0;
1332 uint32_t __user
*fb_id
;
1333 uint32_t __user
*crtc_id
;
1334 uint32_t __user
*connector_id
;
1335 uint32_t __user
*encoder_id
;
1336 struct drm_mode_group
*mode_group
;
1338 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1342 mutex_lock(&file_priv
->fbs_lock
);
1344 * For the non-control nodes we need to limit the list of resources
1345 * by IDs in the group list for this node
1347 list_for_each(lh
, &file_priv
->fbs
)
1350 /* handle this in 4 parts */
1352 if (card_res
->count_fbs
>= fb_count
) {
1354 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1355 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1356 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1357 mutex_unlock(&file_priv
->fbs_lock
);
1363 card_res
->count_fbs
= fb_count
;
1364 mutex_unlock(&file_priv
->fbs_lock
);
1366 drm_modeset_lock_all(dev
);
1367 mode_group
= &file_priv
->master
->minor
->mode_group
;
1368 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1370 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1373 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1376 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1380 crtc_count
= mode_group
->num_crtcs
;
1381 connector_count
= mode_group
->num_connectors
;
1382 encoder_count
= mode_group
->num_encoders
;
1385 card_res
->max_height
= dev
->mode_config
.max_height
;
1386 card_res
->min_height
= dev
->mode_config
.min_height
;
1387 card_res
->max_width
= dev
->mode_config
.max_width
;
1388 card_res
->min_width
= dev
->mode_config
.min_width
;
1391 if (card_res
->count_crtcs
>= crtc_count
) {
1393 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1394 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1395 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1397 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1398 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1405 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1406 if (put_user(mode_group
->id_list
[i
],
1407 crtc_id
+ copied
)) {
1415 card_res
->count_crtcs
= crtc_count
;
1418 if (card_res
->count_encoders
>= encoder_count
) {
1420 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1421 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1422 list_for_each_entry(encoder
,
1423 &dev
->mode_config
.encoder_list
,
1425 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1426 drm_get_encoder_name(encoder
));
1427 if (put_user(encoder
->base
.id
, encoder_id
+
1435 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1436 if (put_user(mode_group
->id_list
[i
],
1437 encoder_id
+ copied
)) {
1446 card_res
->count_encoders
= encoder_count
;
1449 if (card_res
->count_connectors
>= connector_count
) {
1451 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1452 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1453 list_for_each_entry(connector
,
1454 &dev
->mode_config
.connector_list
,
1456 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1458 drm_get_connector_name(connector
));
1459 if (put_user(connector
->base
.id
,
1460 connector_id
+ copied
)) {
1467 int start
= mode_group
->num_crtcs
+
1468 mode_group
->num_encoders
;
1469 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1470 if (put_user(mode_group
->id_list
[i
],
1471 connector_id
+ copied
)) {
1479 card_res
->count_connectors
= connector_count
;
1481 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1482 card_res
->count_connectors
, card_res
->count_encoders
);
1485 drm_modeset_unlock_all(dev
);
1490 * drm_mode_getcrtc - get CRTC configuration
1491 * @dev: drm device for the ioctl
1492 * @data: data pointer for the ioctl
1493 * @file_priv: drm file for the ioctl call
1495 * Construct a CRTC configuration structure to return to the user.
1497 * Called by the user via ioctl.
1500 * Zero on success, errno on failure.
1502 int drm_mode_getcrtc(struct drm_device
*dev
,
1503 void *data
, struct drm_file
*file_priv
)
1505 struct drm_mode_crtc
*crtc_resp
= data
;
1506 struct drm_crtc
*crtc
;
1507 struct drm_mode_object
*obj
;
1510 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1513 drm_modeset_lock_all(dev
);
1515 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1516 DRM_MODE_OBJECT_CRTC
);
1521 crtc
= obj_to_crtc(obj
);
1523 crtc_resp
->x
= crtc
->x
;
1524 crtc_resp
->y
= crtc
->y
;
1525 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1527 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1529 crtc_resp
->fb_id
= 0;
1531 if (crtc
->enabled
) {
1533 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1534 crtc_resp
->mode_valid
= 1;
1537 crtc_resp
->mode_valid
= 0;
1541 drm_modeset_unlock_all(dev
);
1546 * drm_mode_getconnector - get connector configuration
1547 * @dev: drm device for the ioctl
1548 * @data: data pointer for the ioctl
1549 * @file_priv: drm file for the ioctl call
1551 * Construct a connector configuration structure to return to the user.
1553 * Called by the user via ioctl.
1556 * Zero on success, errno on failure.
1558 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1559 struct drm_file
*file_priv
)
1561 struct drm_mode_get_connector
*out_resp
= data
;
1562 struct drm_mode_object
*obj
;
1563 struct drm_connector
*connector
;
1564 struct drm_display_mode
*mode
;
1566 int props_count
= 0;
1567 int encoders_count
= 0;
1571 struct drm_mode_modeinfo u_mode
;
1572 struct drm_mode_modeinfo __user
*mode_ptr
;
1573 uint32_t __user
*prop_ptr
;
1574 uint64_t __user
*prop_values
;
1575 uint32_t __user
*encoder_ptr
;
1577 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1580 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1582 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1584 mutex_lock(&dev
->mode_config
.mutex
);
1586 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1587 DRM_MODE_OBJECT_CONNECTOR
);
1592 connector
= obj_to_connector(obj
);
1594 props_count
= connector
->properties
.count
;
1596 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1597 if (connector
->encoder_ids
[i
] != 0) {
1602 if (out_resp
->count_modes
== 0) {
1603 connector
->funcs
->fill_modes(connector
,
1604 dev
->mode_config
.max_width
,
1605 dev
->mode_config
.max_height
);
1608 /* delayed so we get modes regardless of pre-fill_modes state */
1609 list_for_each_entry(mode
, &connector
->modes
, head
)
1612 out_resp
->connector_id
= connector
->base
.id
;
1613 out_resp
->connector_type
= connector
->connector_type
;
1614 out_resp
->connector_type_id
= connector
->connector_type_id
;
1615 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1616 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1617 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1618 out_resp
->connection
= connector
->status
;
1619 if (connector
->encoder
)
1620 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1622 out_resp
->encoder_id
= 0;
1625 * This ioctl is called twice, once to determine how much space is
1626 * needed, and the 2nd time to fill it.
1628 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1630 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1631 list_for_each_entry(mode
, &connector
->modes
, head
) {
1632 drm_crtc_convert_to_umode(&u_mode
, mode
);
1633 if (copy_to_user(mode_ptr
+ copied
,
1634 &u_mode
, sizeof(u_mode
))) {
1641 out_resp
->count_modes
= mode_count
;
1643 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1645 prop_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
);
1646 prop_values
= (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
);
1647 for (i
= 0; i
< connector
->properties
.count
; i
++) {
1648 if (put_user(connector
->properties
.ids
[i
],
1649 prop_ptr
+ copied
)) {
1654 if (put_user(connector
->properties
.values
[i
],
1655 prop_values
+ copied
)) {
1662 out_resp
->count_props
= props_count
;
1664 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1666 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1667 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1668 if (connector
->encoder_ids
[i
] != 0) {
1669 if (put_user(connector
->encoder_ids
[i
],
1670 encoder_ptr
+ copied
)) {
1678 out_resp
->count_encoders
= encoders_count
;
1681 mutex_unlock(&dev
->mode_config
.mutex
);
1686 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1687 struct drm_file
*file_priv
)
1689 struct drm_mode_get_encoder
*enc_resp
= data
;
1690 struct drm_mode_object
*obj
;
1691 struct drm_encoder
*encoder
;
1694 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1697 drm_modeset_lock_all(dev
);
1698 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1699 DRM_MODE_OBJECT_ENCODER
);
1704 encoder
= obj_to_encoder(obj
);
1707 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1709 enc_resp
->crtc_id
= 0;
1710 enc_resp
->encoder_type
= encoder
->encoder_type
;
1711 enc_resp
->encoder_id
= encoder
->base
.id
;
1712 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1713 enc_resp
->possible_clones
= encoder
->possible_clones
;
1716 drm_modeset_unlock_all(dev
);
1721 * drm_mode_getplane_res - get plane info
1724 * @file_priv: DRM file info
1726 * Return an plane count and set of IDs.
1728 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
1729 struct drm_file
*file_priv
)
1731 struct drm_mode_get_plane_res
*plane_resp
= data
;
1732 struct drm_mode_config
*config
;
1733 struct drm_plane
*plane
;
1734 uint32_t __user
*plane_ptr
;
1735 int copied
= 0, ret
= 0;
1737 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1740 drm_modeset_lock_all(dev
);
1741 config
= &dev
->mode_config
;
1744 * This ioctl is called twice, once to determine how much space is
1745 * needed, and the 2nd time to fill it.
1747 if (config
->num_plane
&&
1748 (plane_resp
->count_planes
>= config
->num_plane
)) {
1749 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
1751 list_for_each_entry(plane
, &config
->plane_list
, head
) {
1752 if (put_user(plane
->base
.id
, plane_ptr
+ copied
)) {
1759 plane_resp
->count_planes
= config
->num_plane
;
1762 drm_modeset_unlock_all(dev
);
1767 * drm_mode_getplane - get plane info
1770 * @file_priv: DRM file info
1772 * Return plane info, including formats supported, gamma size, any
1775 int drm_mode_getplane(struct drm_device
*dev
, void *data
,
1776 struct drm_file
*file_priv
)
1778 struct drm_mode_get_plane
*plane_resp
= data
;
1779 struct drm_mode_object
*obj
;
1780 struct drm_plane
*plane
;
1781 uint32_t __user
*format_ptr
;
1784 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1787 drm_modeset_lock_all(dev
);
1788 obj
= drm_mode_object_find(dev
, plane_resp
->plane_id
,
1789 DRM_MODE_OBJECT_PLANE
);
1794 plane
= obj_to_plane(obj
);
1797 plane_resp
->crtc_id
= plane
->crtc
->base
.id
;
1799 plane_resp
->crtc_id
= 0;
1802 plane_resp
->fb_id
= plane
->fb
->base
.id
;
1804 plane_resp
->fb_id
= 0;
1806 plane_resp
->plane_id
= plane
->base
.id
;
1807 plane_resp
->possible_crtcs
= plane
->possible_crtcs
;
1808 plane_resp
->gamma_size
= 0;
1811 * This ioctl is called twice, once to determine how much space is
1812 * needed, and the 2nd time to fill it.
1814 if (plane
->format_count
&&
1815 (plane_resp
->count_format_types
>= plane
->format_count
)) {
1816 format_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->format_type_ptr
;
1817 if (copy_to_user(format_ptr
,
1818 plane
->format_types
,
1819 sizeof(uint32_t) * plane
->format_count
)) {
1824 plane_resp
->count_format_types
= plane
->format_count
;
1827 drm_modeset_unlock_all(dev
);
1832 * drm_mode_setplane - set up or tear down an plane
1834 * @data: ioctl data*
1835 * @file_priv: DRM file info
1837 * Set plane info, including placement, fb, scaling, and other factors.
1838 * Or pass a NULL fb to disable.
1840 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
1841 struct drm_file
*file_priv
)
1843 struct drm_mode_set_plane
*plane_req
= data
;
1844 struct drm_mode_object
*obj
;
1845 struct drm_plane
*plane
;
1846 struct drm_crtc
*crtc
;
1847 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
1849 unsigned int fb_width
, fb_height
;
1852 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1856 * First, find the plane, crtc, and fb objects. If not available,
1857 * we don't bother to call the driver.
1859 obj
= drm_mode_object_find(dev
, plane_req
->plane_id
,
1860 DRM_MODE_OBJECT_PLANE
);
1862 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1863 plane_req
->plane_id
);
1866 plane
= obj_to_plane(obj
);
1868 /* No fb means shut it down */
1869 if (!plane_req
->fb_id
) {
1870 drm_modeset_lock_all(dev
);
1872 plane
->funcs
->disable_plane(plane
);
1875 drm_modeset_unlock_all(dev
);
1879 obj
= drm_mode_object_find(dev
, plane_req
->crtc_id
,
1880 DRM_MODE_OBJECT_CRTC
);
1882 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1883 plane_req
->crtc_id
);
1887 crtc
= obj_to_crtc(obj
);
1889 fb
= drm_framebuffer_lookup(dev
, plane_req
->fb_id
);
1891 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1897 /* Check whether this plane supports the fb pixel format. */
1898 for (i
= 0; i
< plane
->format_count
; i
++)
1899 if (fb
->pixel_format
== plane
->format_types
[i
])
1901 if (i
== plane
->format_count
) {
1902 DRM_DEBUG_KMS("Invalid pixel format %s\n",
1903 drm_get_format_name(fb
->pixel_format
));
1908 fb_width
= fb
->width
<< 16;
1909 fb_height
= fb
->height
<< 16;
1911 /* Make sure source coordinates are inside the fb. */
1912 if (plane_req
->src_w
> fb_width
||
1913 plane_req
->src_x
> fb_width
- plane_req
->src_w
||
1914 plane_req
->src_h
> fb_height
||
1915 plane_req
->src_y
> fb_height
- plane_req
->src_h
) {
1916 DRM_DEBUG_KMS("Invalid source coordinates "
1917 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1918 plane_req
->src_w
>> 16,
1919 ((plane_req
->src_w
& 0xffff) * 15625) >> 10,
1920 plane_req
->src_h
>> 16,
1921 ((plane_req
->src_h
& 0xffff) * 15625) >> 10,
1922 plane_req
->src_x
>> 16,
1923 ((plane_req
->src_x
& 0xffff) * 15625) >> 10,
1924 plane_req
->src_y
>> 16,
1925 ((plane_req
->src_y
& 0xffff) * 15625) >> 10);
1930 /* Give drivers some help against integer overflows */
1931 if (plane_req
->crtc_w
> INT_MAX
||
1932 plane_req
->crtc_x
> INT_MAX
- (int32_t) plane_req
->crtc_w
||
1933 plane_req
->crtc_h
> INT_MAX
||
1934 plane_req
->crtc_y
> INT_MAX
- (int32_t) plane_req
->crtc_h
) {
1935 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
1936 plane_req
->crtc_w
, plane_req
->crtc_h
,
1937 plane_req
->crtc_x
, plane_req
->crtc_y
);
1942 drm_modeset_lock_all(dev
);
1943 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
1944 plane_req
->crtc_x
, plane_req
->crtc_y
,
1945 plane_req
->crtc_w
, plane_req
->crtc_h
,
1946 plane_req
->src_x
, plane_req
->src_y
,
1947 plane_req
->src_w
, plane_req
->src_h
);
1954 drm_modeset_unlock_all(dev
);
1958 drm_framebuffer_unreference(fb
);
1960 drm_framebuffer_unreference(old_fb
);
1966 * drm_mode_set_config_internal - helper to call ->set_config
1967 * @set: modeset config to set
1969 * This is a little helper to wrap internal calls to the ->set_config driver
1970 * interface. The only thing it adds is correct refcounting dance.
1972 int drm_mode_set_config_internal(struct drm_mode_set
*set
)
1974 struct drm_crtc
*crtc
= set
->crtc
;
1975 struct drm_framebuffer
*fb
;
1976 struct drm_crtc
*tmp
;
1980 * NOTE: ->set_config can also disable other crtcs (if we steal all
1981 * connectors from it), hence we need to refcount the fbs across all
1982 * crtcs. Atomic modeset will have saner semantics ...
1984 list_for_each_entry(tmp
, &crtc
->dev
->mode_config
.crtc_list
, head
)
1985 tmp
->old_fb
= tmp
->fb
;
1989 ret
= crtc
->funcs
->set_config(set
);
1991 /* crtc->fb must be updated by ->set_config, enforces this. */
1992 WARN_ON(fb
!= crtc
->fb
);
1995 list_for_each_entry(tmp
, &crtc
->dev
->mode_config
.crtc_list
, head
) {
1997 drm_framebuffer_reference(tmp
->fb
);
1999 drm_framebuffer_unreference(tmp
->old_fb
);
2004 EXPORT_SYMBOL(drm_mode_set_config_internal
);
2007 * drm_mode_setcrtc - set CRTC configuration
2008 * @dev: drm device for the ioctl
2009 * @data: data pointer for the ioctl
2010 * @file_priv: drm file for the ioctl call
2012 * Build a new CRTC configuration based on user request.
2014 * Called by the user via ioctl.
2017 * Zero on success, errno on failure.
2019 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
2020 struct drm_file
*file_priv
)
2022 struct drm_mode_config
*config
= &dev
->mode_config
;
2023 struct drm_mode_crtc
*crtc_req
= data
;
2024 struct drm_mode_object
*obj
;
2025 struct drm_crtc
*crtc
;
2026 struct drm_connector
**connector_set
= NULL
, *connector
;
2027 struct drm_framebuffer
*fb
= NULL
;
2028 struct drm_display_mode
*mode
= NULL
;
2029 struct drm_mode_set set
;
2030 uint32_t __user
*set_connectors_ptr
;
2034 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2037 /* For some reason crtc x/y offsets are signed internally. */
2038 if (crtc_req
->x
> INT_MAX
|| crtc_req
->y
> INT_MAX
)
2041 drm_modeset_lock_all(dev
);
2042 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
2043 DRM_MODE_OBJECT_CRTC
);
2045 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
2049 crtc
= obj_to_crtc(obj
);
2050 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
2052 if (crtc_req
->mode_valid
) {
2053 int hdisplay
, vdisplay
;
2054 /* If we have a mode we need a framebuffer. */
2055 /* If we pass -1, set the mode with the currently bound fb */
2056 if (crtc_req
->fb_id
== -1) {
2058 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
2063 /* Make refcounting symmetric with the lookup path. */
2064 drm_framebuffer_reference(fb
);
2066 fb
= drm_framebuffer_lookup(dev
, crtc_req
->fb_id
);
2068 DRM_DEBUG_KMS("Unknown FB ID%d\n",
2075 mode
= drm_mode_create(dev
);
2081 ret
= drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
2083 DRM_DEBUG_KMS("Invalid mode\n");
2087 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
2089 hdisplay
= mode
->hdisplay
;
2090 vdisplay
= mode
->vdisplay
;
2092 if (crtc
->invert_dimensions
)
2093 swap(hdisplay
, vdisplay
);
2095 if (hdisplay
> fb
->width
||
2096 vdisplay
> fb
->height
||
2097 crtc_req
->x
> fb
->width
- hdisplay
||
2098 crtc_req
->y
> fb
->height
- vdisplay
) {
2099 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
2100 fb
->width
, fb
->height
,
2101 hdisplay
, vdisplay
, crtc_req
->x
, crtc_req
->y
,
2102 crtc
->invert_dimensions
? " (inverted)" : "");
2108 if (crtc_req
->count_connectors
== 0 && mode
) {
2109 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
2114 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
2115 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
2116 crtc_req
->count_connectors
);
2121 if (crtc_req
->count_connectors
> 0) {
2124 /* Avoid unbounded kernel memory allocation */
2125 if (crtc_req
->count_connectors
> config
->num_connector
) {
2130 connector_set
= kmalloc(crtc_req
->count_connectors
*
2131 sizeof(struct drm_connector
*),
2133 if (!connector_set
) {
2138 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
2139 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
2140 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
2145 obj
= drm_mode_object_find(dev
, out_id
,
2146 DRM_MODE_OBJECT_CONNECTOR
);
2148 DRM_DEBUG_KMS("Connector id %d unknown\n",
2153 connector
= obj_to_connector(obj
);
2154 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2156 drm_get_connector_name(connector
));
2158 connector_set
[i
] = connector
;
2163 set
.x
= crtc_req
->x
;
2164 set
.y
= crtc_req
->y
;
2166 set
.connectors
= connector_set
;
2167 set
.num_connectors
= crtc_req
->count_connectors
;
2169 ret
= drm_mode_set_config_internal(&set
);
2173 drm_framebuffer_unreference(fb
);
2175 kfree(connector_set
);
2176 drm_mode_destroy(dev
, mode
);
2177 drm_modeset_unlock_all(dev
);
2181 static int drm_mode_cursor_common(struct drm_device
*dev
,
2182 struct drm_mode_cursor2
*req
,
2183 struct drm_file
*file_priv
)
2185 struct drm_mode_object
*obj
;
2186 struct drm_crtc
*crtc
;
2189 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2192 if (!req
->flags
|| (~DRM_MODE_CURSOR_FLAGS
& req
->flags
))
2195 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2197 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
2200 crtc
= obj_to_crtc(obj
);
2202 mutex_lock(&crtc
->mutex
);
2203 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
2204 if (!crtc
->funcs
->cursor_set
&& !crtc
->funcs
->cursor_set2
) {
2208 /* Turns off the cursor if handle is 0 */
2209 if (crtc
->funcs
->cursor_set2
)
2210 ret
= crtc
->funcs
->cursor_set2(crtc
, file_priv
, req
->handle
,
2211 req
->width
, req
->height
, req
->hot_x
, req
->hot_y
);
2213 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
2214 req
->width
, req
->height
);
2217 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
2218 if (crtc
->funcs
->cursor_move
) {
2219 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
2226 mutex_unlock(&crtc
->mutex
);
2231 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
2232 void *data
, struct drm_file
*file_priv
)
2234 struct drm_mode_cursor
*req
= data
;
2235 struct drm_mode_cursor2 new_req
;
2237 memcpy(&new_req
, req
, sizeof(struct drm_mode_cursor
));
2238 new_req
.hot_x
= new_req
.hot_y
= 0;
2240 return drm_mode_cursor_common(dev
, &new_req
, file_priv
);
2243 int drm_mode_cursor2_ioctl(struct drm_device
*dev
,
2244 void *data
, struct drm_file
*file_priv
)
2246 struct drm_mode_cursor2
*req
= data
;
2247 return drm_mode_cursor_common(dev
, req
, file_priv
);
2250 /* Original addfb only supported RGB formats, so figure out which one */
2251 uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
)
2257 fmt
= DRM_FORMAT_C8
;
2261 fmt
= DRM_FORMAT_XRGB1555
;
2263 fmt
= DRM_FORMAT_RGB565
;
2266 fmt
= DRM_FORMAT_RGB888
;
2270 fmt
= DRM_FORMAT_XRGB8888
;
2271 else if (depth
== 30)
2272 fmt
= DRM_FORMAT_XRGB2101010
;
2274 fmt
= DRM_FORMAT_ARGB8888
;
2277 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
2278 fmt
= DRM_FORMAT_XRGB8888
;
2284 EXPORT_SYMBOL(drm_mode_legacy_fb_format
);
2287 * drm_mode_addfb - add an FB to the graphics configuration
2288 * @dev: drm device for the ioctl
2289 * @data: data pointer for the ioctl
2290 * @file_priv: drm file for the ioctl call
2292 * Add a new FB to the specified CRTC, given a user request.
2294 * Called by the user via ioctl.
2297 * Zero on success, errno on failure.
2299 int drm_mode_addfb(struct drm_device
*dev
,
2300 void *data
, struct drm_file
*file_priv
)
2302 struct drm_mode_fb_cmd
*or = data
;
2303 struct drm_mode_fb_cmd2 r
= {};
2304 struct drm_mode_config
*config
= &dev
->mode_config
;
2305 struct drm_framebuffer
*fb
;
2308 /* Use new struct with format internally */
2309 r
.fb_id
= or->fb_id
;
2310 r
.width
= or->width
;
2311 r
.height
= or->height
;
2312 r
.pitches
[0] = or->pitch
;
2313 r
.pixel_format
= drm_mode_legacy_fb_format(or->bpp
, or->depth
);
2314 r
.handles
[0] = or->handle
;
2316 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2319 if ((config
->min_width
> r
.width
) || (r
.width
> config
->max_width
))
2322 if ((config
->min_height
> r
.height
) || (r
.height
> config
->max_height
))
2325 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, &r
);
2327 DRM_DEBUG_KMS("could not create framebuffer\n");
2331 mutex_lock(&file_priv
->fbs_lock
);
2332 or->fb_id
= fb
->base
.id
;
2333 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2334 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2335 mutex_unlock(&file_priv
->fbs_lock
);
2340 static int format_check(const struct drm_mode_fb_cmd2
*r
)
2342 uint32_t format
= r
->pixel_format
& ~DRM_FORMAT_BIG_ENDIAN
;
2346 case DRM_FORMAT_RGB332
:
2347 case DRM_FORMAT_BGR233
:
2348 case DRM_FORMAT_XRGB4444
:
2349 case DRM_FORMAT_XBGR4444
:
2350 case DRM_FORMAT_RGBX4444
:
2351 case DRM_FORMAT_BGRX4444
:
2352 case DRM_FORMAT_ARGB4444
:
2353 case DRM_FORMAT_ABGR4444
:
2354 case DRM_FORMAT_RGBA4444
:
2355 case DRM_FORMAT_BGRA4444
:
2356 case DRM_FORMAT_XRGB1555
:
2357 case DRM_FORMAT_XBGR1555
:
2358 case DRM_FORMAT_RGBX5551
:
2359 case DRM_FORMAT_BGRX5551
:
2360 case DRM_FORMAT_ARGB1555
:
2361 case DRM_FORMAT_ABGR1555
:
2362 case DRM_FORMAT_RGBA5551
:
2363 case DRM_FORMAT_BGRA5551
:
2364 case DRM_FORMAT_RGB565
:
2365 case DRM_FORMAT_BGR565
:
2366 case DRM_FORMAT_RGB888
:
2367 case DRM_FORMAT_BGR888
:
2368 case DRM_FORMAT_XRGB8888
:
2369 case DRM_FORMAT_XBGR8888
:
2370 case DRM_FORMAT_RGBX8888
:
2371 case DRM_FORMAT_BGRX8888
:
2372 case DRM_FORMAT_ARGB8888
:
2373 case DRM_FORMAT_ABGR8888
:
2374 case DRM_FORMAT_RGBA8888
:
2375 case DRM_FORMAT_BGRA8888
:
2376 case DRM_FORMAT_XRGB2101010
:
2377 case DRM_FORMAT_XBGR2101010
:
2378 case DRM_FORMAT_RGBX1010102
:
2379 case DRM_FORMAT_BGRX1010102
:
2380 case DRM_FORMAT_ARGB2101010
:
2381 case DRM_FORMAT_ABGR2101010
:
2382 case DRM_FORMAT_RGBA1010102
:
2383 case DRM_FORMAT_BGRA1010102
:
2384 case DRM_FORMAT_YUYV
:
2385 case DRM_FORMAT_YVYU
:
2386 case DRM_FORMAT_UYVY
:
2387 case DRM_FORMAT_VYUY
:
2388 case DRM_FORMAT_AYUV
:
2389 case DRM_FORMAT_NV12
:
2390 case DRM_FORMAT_NV21
:
2391 case DRM_FORMAT_NV16
:
2392 case DRM_FORMAT_NV61
:
2393 case DRM_FORMAT_NV24
:
2394 case DRM_FORMAT_NV42
:
2395 case DRM_FORMAT_YUV410
:
2396 case DRM_FORMAT_YVU410
:
2397 case DRM_FORMAT_YUV411
:
2398 case DRM_FORMAT_YVU411
:
2399 case DRM_FORMAT_YUV420
:
2400 case DRM_FORMAT_YVU420
:
2401 case DRM_FORMAT_YUV422
:
2402 case DRM_FORMAT_YVU422
:
2403 case DRM_FORMAT_YUV444
:
2404 case DRM_FORMAT_YVU444
:
2411 static int framebuffer_check(const struct drm_mode_fb_cmd2
*r
)
2413 int ret
, hsub
, vsub
, num_planes
, i
;
2415 ret
= format_check(r
);
2417 DRM_DEBUG_KMS("bad framebuffer format %s\n",
2418 drm_get_format_name(r
->pixel_format
));
2422 hsub
= drm_format_horz_chroma_subsampling(r
->pixel_format
);
2423 vsub
= drm_format_vert_chroma_subsampling(r
->pixel_format
);
2424 num_planes
= drm_format_num_planes(r
->pixel_format
);
2426 if (r
->width
== 0 || r
->width
% hsub
) {
2427 DRM_DEBUG_KMS("bad framebuffer width %u\n", r
->height
);
2431 if (r
->height
== 0 || r
->height
% vsub
) {
2432 DRM_DEBUG_KMS("bad framebuffer height %u\n", r
->height
);
2436 for (i
= 0; i
< num_planes
; i
++) {
2437 unsigned int width
= r
->width
/ (i
!= 0 ? hsub
: 1);
2438 unsigned int height
= r
->height
/ (i
!= 0 ? vsub
: 1);
2439 unsigned int cpp
= drm_format_plane_cpp(r
->pixel_format
, i
);
2441 if (!r
->handles
[i
]) {
2442 DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i
);
2446 if ((uint64_t) width
* cpp
> UINT_MAX
)
2449 if ((uint64_t) height
* r
->pitches
[i
] + r
->offsets
[i
] > UINT_MAX
)
2452 if (r
->pitches
[i
] < width
* cpp
) {
2453 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r
->pitches
[i
], i
);
2462 * drm_mode_addfb2 - add an FB to the graphics configuration
2463 * @dev: drm device for the ioctl
2464 * @data: data pointer for the ioctl
2465 * @file_priv: drm file for the ioctl call
2467 * Add a new FB to the specified CRTC, given a user request with format.
2469 * Called by the user via ioctl.
2472 * Zero on success, errno on failure.
2474 int drm_mode_addfb2(struct drm_device
*dev
,
2475 void *data
, struct drm_file
*file_priv
)
2477 struct drm_mode_fb_cmd2
*r
= data
;
2478 struct drm_mode_config
*config
= &dev
->mode_config
;
2479 struct drm_framebuffer
*fb
;
2482 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2485 if (r
->flags
& ~DRM_MODE_FB_INTERLACED
) {
2486 DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r
->flags
);
2490 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
2491 DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
2492 r
->width
, config
->min_width
, config
->max_width
);
2495 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
2496 DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
2497 r
->height
, config
->min_height
, config
->max_height
);
2501 ret
= framebuffer_check(r
);
2505 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
2507 DRM_DEBUG_KMS("could not create framebuffer\n");
2511 mutex_lock(&file_priv
->fbs_lock
);
2512 r
->fb_id
= fb
->base
.id
;
2513 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2514 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2515 mutex_unlock(&file_priv
->fbs_lock
);
2522 * drm_mode_rmfb - remove an FB from the configuration
2523 * @dev: drm device for the ioctl
2524 * @data: data pointer for the ioctl
2525 * @file_priv: drm file for the ioctl call
2527 * Remove the FB specified by the user.
2529 * Called by the user via ioctl.
2532 * Zero on success, errno on failure.
2534 int drm_mode_rmfb(struct drm_device
*dev
,
2535 void *data
, struct drm_file
*file_priv
)
2537 struct drm_framebuffer
*fb
= NULL
;
2538 struct drm_framebuffer
*fbl
= NULL
;
2539 uint32_t *id
= data
;
2542 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2545 mutex_lock(&file_priv
->fbs_lock
);
2546 mutex_lock(&dev
->mode_config
.fb_lock
);
2547 fb
= __drm_framebuffer_lookup(dev
, *id
);
2551 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
2557 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2558 __drm_framebuffer_unregister(dev
, fb
);
2560 list_del_init(&fb
->filp_head
);
2561 mutex_unlock(&dev
->mode_config
.fb_lock
);
2562 mutex_unlock(&file_priv
->fbs_lock
);
2564 drm_framebuffer_remove(fb
);
2569 mutex_unlock(&dev
->mode_config
.fb_lock
);
2570 mutex_unlock(&file_priv
->fbs_lock
);
2576 * drm_mode_getfb - get FB info
2577 * @dev: drm device for the ioctl
2578 * @data: data pointer for the ioctl
2579 * @file_priv: drm file for the ioctl call
2581 * Lookup the FB given its ID and return info about it.
2583 * Called by the user via ioctl.
2586 * Zero on success, errno on failure.
2588 int drm_mode_getfb(struct drm_device
*dev
,
2589 void *data
, struct drm_file
*file_priv
)
2591 struct drm_mode_fb_cmd
*r
= data
;
2592 struct drm_framebuffer
*fb
;
2595 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2598 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2602 r
->height
= fb
->height
;
2603 r
->width
= fb
->width
;
2604 r
->depth
= fb
->depth
;
2605 r
->bpp
= fb
->bits_per_pixel
;
2606 r
->pitch
= fb
->pitches
[0];
2607 if (fb
->funcs
->create_handle
)
2608 ret
= fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
2612 drm_framebuffer_unreference(fb
);
2617 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2618 void *data
, struct drm_file
*file_priv
)
2620 struct drm_clip_rect __user
*clips_ptr
;
2621 struct drm_clip_rect
*clips
= NULL
;
2622 struct drm_mode_fb_dirty_cmd
*r
= data
;
2623 struct drm_framebuffer
*fb
;
2628 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2631 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2635 num_clips
= r
->num_clips
;
2636 clips_ptr
= (struct drm_clip_rect __user
*)(unsigned long)r
->clips_ptr
;
2638 if (!num_clips
!= !clips_ptr
) {
2643 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
2645 /* If userspace annotates copy, clips must come in pairs */
2646 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
2651 if (num_clips
&& clips_ptr
) {
2652 if (num_clips
< 0 || num_clips
> DRM_MODE_FB_DIRTY_MAX_CLIPS
) {
2656 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
2662 ret
= copy_from_user(clips
, clips_ptr
,
2663 num_clips
* sizeof(*clips
));
2670 if (fb
->funcs
->dirty
) {
2671 drm_modeset_lock_all(dev
);
2672 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
2674 drm_modeset_unlock_all(dev
);
2682 drm_framebuffer_unreference(fb
);
2689 * drm_fb_release - remove and free the FBs on this file
2690 * @priv: drm file for the ioctl
2692 * Destroy all the FBs associated with @filp.
2694 * Called by the user via ioctl.
2697 * Zero on success, errno on failure.
2699 void drm_fb_release(struct drm_file
*priv
)
2701 struct drm_device
*dev
= priv
->minor
->dev
;
2702 struct drm_framebuffer
*fb
, *tfb
;
2704 mutex_lock(&priv
->fbs_lock
);
2705 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
2707 mutex_lock(&dev
->mode_config
.fb_lock
);
2708 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2709 __drm_framebuffer_unregister(dev
, fb
);
2710 mutex_unlock(&dev
->mode_config
.fb_lock
);
2712 list_del_init(&fb
->filp_head
);
2714 /* This will also drop the fpriv->fbs reference. */
2715 drm_framebuffer_remove(fb
);
2717 mutex_unlock(&priv
->fbs_lock
);
2720 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2721 const char *name
, int num_values
)
2723 struct drm_property
*property
= NULL
;
2726 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2731 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2732 if (!property
->values
)
2736 ret
= drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2740 property
->flags
= flags
;
2741 property
->num_values
= num_values
;
2742 INIT_LIST_HEAD(&property
->enum_blob_list
);
2745 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2746 property
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2749 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2752 kfree(property
->values
);
2756 EXPORT_SYMBOL(drm_property_create
);
2758 struct drm_property
*drm_property_create_enum(struct drm_device
*dev
, int flags
,
2760 const struct drm_prop_enum_list
*props
,
2763 struct drm_property
*property
;
2766 flags
|= DRM_MODE_PROP_ENUM
;
2768 property
= drm_property_create(dev
, flags
, name
, num_values
);
2772 for (i
= 0; i
< num_values
; i
++) {
2773 ret
= drm_property_add_enum(property
, i
,
2777 drm_property_destroy(dev
, property
);
2784 EXPORT_SYMBOL(drm_property_create_enum
);
2786 struct drm_property
*drm_property_create_bitmask(struct drm_device
*dev
,
2787 int flags
, const char *name
,
2788 const struct drm_prop_enum_list
*props
,
2791 struct drm_property
*property
;
2794 flags
|= DRM_MODE_PROP_BITMASK
;
2796 property
= drm_property_create(dev
, flags
, name
, num_values
);
2800 for (i
= 0; i
< num_values
; i
++) {
2801 ret
= drm_property_add_enum(property
, i
,
2805 drm_property_destroy(dev
, property
);
2812 EXPORT_SYMBOL(drm_property_create_bitmask
);
2814 struct drm_property
*drm_property_create_range(struct drm_device
*dev
, int flags
,
2816 uint64_t min
, uint64_t max
)
2818 struct drm_property
*property
;
2820 flags
|= DRM_MODE_PROP_RANGE
;
2822 property
= drm_property_create(dev
, flags
, name
, 2);
2826 property
->values
[0] = min
;
2827 property
->values
[1] = max
;
2831 EXPORT_SYMBOL(drm_property_create_range
);
2833 int drm_property_add_enum(struct drm_property
*property
, int index
,
2834 uint64_t value
, const char *name
)
2836 struct drm_property_enum
*prop_enum
;
2838 if (!(property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)))
2842 * Bitmask enum properties have the additional constraint of values
2845 if ((property
->flags
& DRM_MODE_PROP_BITMASK
) && (value
> 63))
2848 if (!list_empty(&property
->enum_blob_list
)) {
2849 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2850 if (prop_enum
->value
== value
) {
2851 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2852 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2858 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2862 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2863 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2864 prop_enum
->value
= value
;
2866 property
->values
[index
] = value
;
2867 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2870 EXPORT_SYMBOL(drm_property_add_enum
);
2872 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2874 struct drm_property_enum
*prop_enum
, *pt
;
2876 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2877 list_del(&prop_enum
->head
);
2881 if (property
->num_values
)
2882 kfree(property
->values
);
2883 drm_mode_object_put(dev
, &property
->base
);
2884 list_del(&property
->head
);
2887 EXPORT_SYMBOL(drm_property_destroy
);
2889 void drm_object_attach_property(struct drm_mode_object
*obj
,
2890 struct drm_property
*property
,
2893 int count
= obj
->properties
->count
;
2895 if (count
== DRM_OBJECT_MAX_PROPERTY
) {
2896 WARN(1, "Failed to attach object property (type: 0x%x). Please "
2897 "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time "
2898 "you see this message on the same object type.\n",
2903 obj
->properties
->ids
[count
] = property
->base
.id
;
2904 obj
->properties
->values
[count
] = init_val
;
2905 obj
->properties
->count
++;
2907 EXPORT_SYMBOL(drm_object_attach_property
);
2909 int drm_object_property_set_value(struct drm_mode_object
*obj
,
2910 struct drm_property
*property
, uint64_t val
)
2914 for (i
= 0; i
< obj
->properties
->count
; i
++) {
2915 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
2916 obj
->properties
->values
[i
] = val
;
2923 EXPORT_SYMBOL(drm_object_property_set_value
);
2925 int drm_object_property_get_value(struct drm_mode_object
*obj
,
2926 struct drm_property
*property
, uint64_t *val
)
2930 for (i
= 0; i
< obj
->properties
->count
; i
++) {
2931 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
2932 *val
= obj
->properties
->values
[i
];
2939 EXPORT_SYMBOL(drm_object_property_get_value
);
2941 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2942 void *data
, struct drm_file
*file_priv
)
2944 struct drm_mode_object
*obj
;
2945 struct drm_mode_get_property
*out_resp
= data
;
2946 struct drm_property
*property
;
2949 int value_count
= 0;
2952 struct drm_property_enum
*prop_enum
;
2953 struct drm_mode_property_enum __user
*enum_ptr
;
2954 struct drm_property_blob
*prop_blob
;
2955 uint32_t __user
*blob_id_ptr
;
2956 uint64_t __user
*values_ptr
;
2957 uint32_t __user
*blob_length_ptr
;
2959 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2962 drm_modeset_lock_all(dev
);
2963 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2968 property
= obj_to_property(obj
);
2970 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
2971 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
2973 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2974 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
2978 value_count
= property
->num_values
;
2980 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
2981 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
2982 out_resp
->flags
= property
->flags
;
2984 if ((out_resp
->count_values
>= value_count
) && value_count
) {
2985 values_ptr
= (uint64_t __user
*)(unsigned long)out_resp
->values_ptr
;
2986 for (i
= 0; i
< value_count
; i
++) {
2987 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
2993 out_resp
->count_values
= value_count
;
2995 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
2996 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
2998 enum_ptr
= (struct drm_mode_property_enum __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
2999 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
3001 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
3006 if (copy_to_user(&enum_ptr
[copied
].name
,
3007 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
3014 out_resp
->count_enum_blobs
= enum_count
;
3017 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3018 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
3020 blob_id_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3021 blob_length_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->values_ptr
;
3023 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
3024 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
3029 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
3037 out_resp
->count_enum_blobs
= blob_count
;
3040 drm_modeset_unlock_all(dev
);
3044 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
3047 struct drm_property_blob
*blob
;
3050 if (!length
|| !data
)
3053 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
3057 ret
= drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
3063 blob
->length
= length
;
3065 memcpy(blob
->data
, data
, length
);
3067 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
3071 static void drm_property_destroy_blob(struct drm_device
*dev
,
3072 struct drm_property_blob
*blob
)
3074 drm_mode_object_put(dev
, &blob
->base
);
3075 list_del(&blob
->head
);
3079 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
3080 void *data
, struct drm_file
*file_priv
)
3082 struct drm_mode_object
*obj
;
3083 struct drm_mode_get_blob
*out_resp
= data
;
3084 struct drm_property_blob
*blob
;
3086 void __user
*blob_ptr
;
3088 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3091 drm_modeset_lock_all(dev
);
3092 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
3097 blob
= obj_to_blob(obj
);
3099 if (out_resp
->length
== blob
->length
) {
3100 blob_ptr
= (void __user
*)(unsigned long)out_resp
->data
;
3101 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
3106 out_resp
->length
= blob
->length
;
3109 drm_modeset_unlock_all(dev
);
3113 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
3116 struct drm_device
*dev
= connector
->dev
;
3119 if (connector
->edid_blob_ptr
)
3120 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
3122 /* Delete edid, when there is none. */
3124 connector
->edid_blob_ptr
= NULL
;
3125 ret
= drm_object_property_set_value(&connector
->base
, dev
->mode_config
.edid_property
, 0);
3129 size
= EDID_LENGTH
* (1 + edid
->extensions
);
3130 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
3132 if (!connector
->edid_blob_ptr
)
3135 ret
= drm_object_property_set_value(&connector
->base
,
3136 dev
->mode_config
.edid_property
,
3137 connector
->edid_blob_ptr
->base
.id
);
3141 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
3143 static bool drm_property_change_is_valid(struct drm_property
*property
,
3146 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
3148 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
3149 if (value
< property
->values
[0] || value
> property
->values
[1])
3152 } else if (property
->flags
& DRM_MODE_PROP_BITMASK
) {
3154 uint64_t valid_mask
= 0;
3155 for (i
= 0; i
< property
->num_values
; i
++)
3156 valid_mask
|= (1ULL << property
->values
[i
]);
3157 return !(value
& ~valid_mask
);
3158 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3159 /* Only the driver knows */
3163 for (i
= 0; i
< property
->num_values
; i
++)
3164 if (property
->values
[i
] == value
)
3170 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
3171 void *data
, struct drm_file
*file_priv
)
3173 struct drm_mode_connector_set_property
*conn_set_prop
= data
;
3174 struct drm_mode_obj_set_property obj_set_prop
= {
3175 .value
= conn_set_prop
->value
,
3176 .prop_id
= conn_set_prop
->prop_id
,
3177 .obj_id
= conn_set_prop
->connector_id
,
3178 .obj_type
= DRM_MODE_OBJECT_CONNECTOR
3181 /* It does all the locking and checking we need */
3182 return drm_mode_obj_set_property_ioctl(dev
, &obj_set_prop
, file_priv
);
3185 static int drm_mode_connector_set_obj_prop(struct drm_mode_object
*obj
,
3186 struct drm_property
*property
,
3190 struct drm_connector
*connector
= obj_to_connector(obj
);
3192 /* Do DPMS ourselves */
3193 if (property
== connector
->dev
->mode_config
.dpms_property
) {
3194 if (connector
->funcs
->dpms
)
3195 (*connector
->funcs
->dpms
)(connector
, (int)value
);
3197 } else if (connector
->funcs
->set_property
)
3198 ret
= connector
->funcs
->set_property(connector
, property
, value
);
3200 /* store the property value if successful */
3202 drm_object_property_set_value(&connector
->base
, property
, value
);
3206 static int drm_mode_crtc_set_obj_prop(struct drm_mode_object
*obj
,
3207 struct drm_property
*property
,
3211 struct drm_crtc
*crtc
= obj_to_crtc(obj
);
3213 if (crtc
->funcs
->set_property
)
3214 ret
= crtc
->funcs
->set_property(crtc
, property
, value
);
3216 drm_object_property_set_value(obj
, property
, value
);
3221 static int drm_mode_plane_set_obj_prop(struct drm_mode_object
*obj
,
3222 struct drm_property
*property
,
3226 struct drm_plane
*plane
= obj_to_plane(obj
);
3228 if (plane
->funcs
->set_property
)
3229 ret
= plane
->funcs
->set_property(plane
, property
, value
);
3231 drm_object_property_set_value(obj
, property
, value
);
3236 int drm_mode_obj_get_properties_ioctl(struct drm_device
*dev
, void *data
,
3237 struct drm_file
*file_priv
)
3239 struct drm_mode_obj_get_properties
*arg
= data
;
3240 struct drm_mode_object
*obj
;
3244 int props_count
= 0;
3245 uint32_t __user
*props_ptr
;
3246 uint64_t __user
*prop_values_ptr
;
3248 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3251 drm_modeset_lock_all(dev
);
3253 obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3258 if (!obj
->properties
) {
3263 props_count
= obj
->properties
->count
;
3265 /* This ioctl is called twice, once to determine how much space is
3266 * needed, and the 2nd time to fill it. */
3267 if ((arg
->count_props
>= props_count
) && props_count
) {
3269 props_ptr
= (uint32_t __user
*)(unsigned long)(arg
->props_ptr
);
3270 prop_values_ptr
= (uint64_t __user
*)(unsigned long)
3271 (arg
->prop_values_ptr
);
3272 for (i
= 0; i
< props_count
; i
++) {
3273 if (put_user(obj
->properties
->ids
[i
],
3274 props_ptr
+ copied
)) {
3278 if (put_user(obj
->properties
->values
[i
],
3279 prop_values_ptr
+ copied
)) {
3286 arg
->count_props
= props_count
;
3288 drm_modeset_unlock_all(dev
);
3292 int drm_mode_obj_set_property_ioctl(struct drm_device
*dev
, void *data
,
3293 struct drm_file
*file_priv
)
3295 struct drm_mode_obj_set_property
*arg
= data
;
3296 struct drm_mode_object
*arg_obj
;
3297 struct drm_mode_object
*prop_obj
;
3298 struct drm_property
*property
;
3302 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3305 drm_modeset_lock_all(dev
);
3307 arg_obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3310 if (!arg_obj
->properties
)
3313 for (i
= 0; i
< arg_obj
->properties
->count
; i
++)
3314 if (arg_obj
->properties
->ids
[i
] == arg
->prop_id
)
3317 if (i
== arg_obj
->properties
->count
)
3320 prop_obj
= drm_mode_object_find(dev
, arg
->prop_id
,
3321 DRM_MODE_OBJECT_PROPERTY
);
3324 property
= obj_to_property(prop_obj
);
3326 if (!drm_property_change_is_valid(property
, arg
->value
))
3329 switch (arg_obj
->type
) {
3330 case DRM_MODE_OBJECT_CONNECTOR
:
3331 ret
= drm_mode_connector_set_obj_prop(arg_obj
, property
,
3334 case DRM_MODE_OBJECT_CRTC
:
3335 ret
= drm_mode_crtc_set_obj_prop(arg_obj
, property
, arg
->value
);
3337 case DRM_MODE_OBJECT_PLANE
:
3338 ret
= drm_mode_plane_set_obj_prop(arg_obj
, property
, arg
->value
);
3343 drm_modeset_unlock_all(dev
);
3347 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
3348 struct drm_encoder
*encoder
)
3352 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3353 if (connector
->encoder_ids
[i
] == 0) {
3354 connector
->encoder_ids
[i
] = encoder
->base
.id
;
3360 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
3362 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
3363 struct drm_encoder
*encoder
)
3366 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3367 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
3368 connector
->encoder_ids
[i
] = 0;
3369 if (connector
->encoder
== encoder
)
3370 connector
->encoder
= NULL
;
3375 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
3377 int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
3380 crtc
->gamma_size
= gamma_size
;
3382 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
3383 if (!crtc
->gamma_store
) {
3384 crtc
->gamma_size
= 0;
3390 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
3392 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
3393 void *data
, struct drm_file
*file_priv
)
3395 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3396 struct drm_mode_object
*obj
;
3397 struct drm_crtc
*crtc
;
3398 void *r_base
, *g_base
, *b_base
;
3402 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3405 drm_modeset_lock_all(dev
);
3406 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3411 crtc
= obj_to_crtc(obj
);
3413 if (crtc
->funcs
->gamma_set
== NULL
) {
3418 /* memcpy into gamma store */
3419 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3424 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3425 r_base
= crtc
->gamma_store
;
3426 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
3431 g_base
= r_base
+ size
;
3432 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
3437 b_base
= g_base
+ size
;
3438 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
3443 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
3446 drm_modeset_unlock_all(dev
);
3451 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
3452 void *data
, struct drm_file
*file_priv
)
3454 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3455 struct drm_mode_object
*obj
;
3456 struct drm_crtc
*crtc
;
3457 void *r_base
, *g_base
, *b_base
;
3461 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3464 drm_modeset_lock_all(dev
);
3465 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3470 crtc
= obj_to_crtc(obj
);
3472 /* memcpy into gamma store */
3473 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3478 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3479 r_base
= crtc
->gamma_store
;
3480 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
3485 g_base
= r_base
+ size
;
3486 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
3491 b_base
= g_base
+ size
;
3492 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
3497 drm_modeset_unlock_all(dev
);
3501 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
3502 void *data
, struct drm_file
*file_priv
)
3504 struct drm_mode_crtc_page_flip
*page_flip
= data
;
3505 struct drm_mode_object
*obj
;
3506 struct drm_crtc
*crtc
;
3507 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
3508 struct drm_pending_vblank_event
*e
= NULL
;
3509 unsigned long flags
;
3510 int hdisplay
, vdisplay
;
3513 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
3514 page_flip
->reserved
!= 0)
3517 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3520 crtc
= obj_to_crtc(obj
);
3522 mutex_lock(&crtc
->mutex
);
3523 if (crtc
->fb
== NULL
) {
3524 /* The framebuffer is currently unbound, presumably
3525 * due to a hotplug event, that userspace has not
3532 if (crtc
->funcs
->page_flip
== NULL
)
3535 fb
= drm_framebuffer_lookup(dev
, page_flip
->fb_id
);
3539 hdisplay
= crtc
->mode
.hdisplay
;
3540 vdisplay
= crtc
->mode
.vdisplay
;
3542 if (crtc
->invert_dimensions
)
3543 swap(hdisplay
, vdisplay
);
3545 if (hdisplay
> fb
->width
||
3546 vdisplay
> fb
->height
||
3547 crtc
->x
> fb
->width
- hdisplay
||
3548 crtc
->y
> fb
->height
- vdisplay
) {
3549 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
3550 fb
->width
, fb
->height
, hdisplay
, vdisplay
, crtc
->x
, crtc
->y
,
3551 crtc
->invert_dimensions
? " (inverted)" : "");
3556 if (crtc
->fb
->pixel_format
!= fb
->pixel_format
) {
3557 DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n");
3562 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3564 spin_lock_irqsave(&dev
->event_lock
, flags
);
3565 if (file_priv
->event_space
< sizeof e
->event
) {
3566 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3569 file_priv
->event_space
-= sizeof e
->event
;
3570 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3572 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
3574 spin_lock_irqsave(&dev
->event_lock
, flags
);
3575 file_priv
->event_space
+= sizeof e
->event
;
3576 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3580 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
3581 e
->event
.base
.length
= sizeof e
->event
;
3582 e
->event
.user_data
= page_flip
->user_data
;
3583 e
->base
.event
= &e
->event
.base
;
3584 e
->base
.file_priv
= file_priv
;
3586 (void (*) (struct drm_pending_event
*)) kfree
;
3590 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
);
3592 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3593 spin_lock_irqsave(&dev
->event_lock
, flags
);
3594 file_priv
->event_space
+= sizeof e
->event
;
3595 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3598 /* Keep the old fb, don't unref it. */
3602 * Warn if the driver hasn't properly updated the crtc->fb
3603 * field to reflect that the new framebuffer is now used.
3604 * Failing to do so will screw with the reference counting
3607 WARN_ON(crtc
->fb
!= fb
);
3608 /* Unref only the old framebuffer. */
3614 drm_framebuffer_unreference(fb
);
3616 drm_framebuffer_unreference(old_fb
);
3617 mutex_unlock(&crtc
->mutex
);
3622 void drm_mode_config_reset(struct drm_device
*dev
)
3624 struct drm_crtc
*crtc
;
3625 struct drm_encoder
*encoder
;
3626 struct drm_connector
*connector
;
3628 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
3629 if (crtc
->funcs
->reset
)
3630 crtc
->funcs
->reset(crtc
);
3632 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
3633 if (encoder
->funcs
->reset
)
3634 encoder
->funcs
->reset(encoder
);
3636 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
3637 connector
->status
= connector_status_unknown
;
3639 if (connector
->funcs
->reset
)
3640 connector
->funcs
->reset(connector
);
3643 EXPORT_SYMBOL(drm_mode_config_reset
);
3645 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
3646 void *data
, struct drm_file
*file_priv
)
3648 struct drm_mode_create_dumb
*args
= data
;
3650 if (!dev
->driver
->dumb_create
)
3652 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
3655 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
3656 void *data
, struct drm_file
*file_priv
)
3658 struct drm_mode_map_dumb
*args
= data
;
3660 /* call driver ioctl to get mmap offset */
3661 if (!dev
->driver
->dumb_map_offset
)
3664 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
3667 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
3668 void *data
, struct drm_file
*file_priv
)
3670 struct drm_mode_destroy_dumb
*args
= data
;
3672 if (!dev
->driver
->dumb_destroy
)
3675 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
3679 * Just need to support RGB formats here for compat with code that doesn't
3680 * use pixel formats directly yet.
3682 void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
3687 case DRM_FORMAT_RGB332
:
3688 case DRM_FORMAT_BGR233
:
3692 case DRM_FORMAT_XRGB1555
:
3693 case DRM_FORMAT_XBGR1555
:
3694 case DRM_FORMAT_RGBX5551
:
3695 case DRM_FORMAT_BGRX5551
:
3696 case DRM_FORMAT_ARGB1555
:
3697 case DRM_FORMAT_ABGR1555
:
3698 case DRM_FORMAT_RGBA5551
:
3699 case DRM_FORMAT_BGRA5551
:
3703 case DRM_FORMAT_RGB565
:
3704 case DRM_FORMAT_BGR565
:
3708 case DRM_FORMAT_RGB888
:
3709 case DRM_FORMAT_BGR888
:
3713 case DRM_FORMAT_XRGB8888
:
3714 case DRM_FORMAT_XBGR8888
:
3715 case DRM_FORMAT_RGBX8888
:
3716 case DRM_FORMAT_BGRX8888
:
3720 case DRM_FORMAT_XRGB2101010
:
3721 case DRM_FORMAT_XBGR2101010
:
3722 case DRM_FORMAT_RGBX1010102
:
3723 case DRM_FORMAT_BGRX1010102
:
3724 case DRM_FORMAT_ARGB2101010
:
3725 case DRM_FORMAT_ABGR2101010
:
3726 case DRM_FORMAT_RGBA1010102
:
3727 case DRM_FORMAT_BGRA1010102
:
3731 case DRM_FORMAT_ARGB8888
:
3732 case DRM_FORMAT_ABGR8888
:
3733 case DRM_FORMAT_RGBA8888
:
3734 case DRM_FORMAT_BGRA8888
:
3739 DRM_DEBUG_KMS("unsupported pixel format\n");
3745 EXPORT_SYMBOL(drm_fb_get_bpp_depth
);
3748 * drm_format_num_planes - get the number of planes for format
3749 * @format: pixel format (DRM_FORMAT_*)
3752 * The number of planes used by the specified pixel format.
3754 int drm_format_num_planes(uint32_t format
)
3757 case DRM_FORMAT_YUV410
:
3758 case DRM_FORMAT_YVU410
:
3759 case DRM_FORMAT_YUV411
:
3760 case DRM_FORMAT_YVU411
:
3761 case DRM_FORMAT_YUV420
:
3762 case DRM_FORMAT_YVU420
:
3763 case DRM_FORMAT_YUV422
:
3764 case DRM_FORMAT_YVU422
:
3765 case DRM_FORMAT_YUV444
:
3766 case DRM_FORMAT_YVU444
:
3768 case DRM_FORMAT_NV12
:
3769 case DRM_FORMAT_NV21
:
3770 case DRM_FORMAT_NV16
:
3771 case DRM_FORMAT_NV61
:
3772 case DRM_FORMAT_NV24
:
3773 case DRM_FORMAT_NV42
:
3779 EXPORT_SYMBOL(drm_format_num_planes
);
3782 * drm_format_plane_cpp - determine the bytes per pixel value
3783 * @format: pixel format (DRM_FORMAT_*)
3784 * @plane: plane index
3787 * The bytes per pixel value for the specified plane.
3789 int drm_format_plane_cpp(uint32_t format
, int plane
)
3794 if (plane
>= drm_format_num_planes(format
))
3798 case DRM_FORMAT_YUYV
:
3799 case DRM_FORMAT_YVYU
:
3800 case DRM_FORMAT_UYVY
:
3801 case DRM_FORMAT_VYUY
:
3803 case DRM_FORMAT_NV12
:
3804 case DRM_FORMAT_NV21
:
3805 case DRM_FORMAT_NV16
:
3806 case DRM_FORMAT_NV61
:
3807 case DRM_FORMAT_NV24
:
3808 case DRM_FORMAT_NV42
:
3809 return plane
? 2 : 1;
3810 case DRM_FORMAT_YUV410
:
3811 case DRM_FORMAT_YVU410
:
3812 case DRM_FORMAT_YUV411
:
3813 case DRM_FORMAT_YVU411
:
3814 case DRM_FORMAT_YUV420
:
3815 case DRM_FORMAT_YVU420
:
3816 case DRM_FORMAT_YUV422
:
3817 case DRM_FORMAT_YVU422
:
3818 case DRM_FORMAT_YUV444
:
3819 case DRM_FORMAT_YVU444
:
3822 drm_fb_get_bpp_depth(format
, &depth
, &bpp
);
3826 EXPORT_SYMBOL(drm_format_plane_cpp
);
3829 * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
3830 * @format: pixel format (DRM_FORMAT_*)
3833 * The horizontal chroma subsampling factor for the
3834 * specified pixel format.
3836 int drm_format_horz_chroma_subsampling(uint32_t format
)
3839 case DRM_FORMAT_YUV411
:
3840 case DRM_FORMAT_YVU411
:
3841 case DRM_FORMAT_YUV410
:
3842 case DRM_FORMAT_YVU410
:
3844 case DRM_FORMAT_YUYV
:
3845 case DRM_FORMAT_YVYU
:
3846 case DRM_FORMAT_UYVY
:
3847 case DRM_FORMAT_VYUY
:
3848 case DRM_FORMAT_NV12
:
3849 case DRM_FORMAT_NV21
:
3850 case DRM_FORMAT_NV16
:
3851 case DRM_FORMAT_NV61
:
3852 case DRM_FORMAT_YUV422
:
3853 case DRM_FORMAT_YVU422
:
3854 case DRM_FORMAT_YUV420
:
3855 case DRM_FORMAT_YVU420
:
3861 EXPORT_SYMBOL(drm_format_horz_chroma_subsampling
);
3864 * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
3865 * @format: pixel format (DRM_FORMAT_*)
3868 * The vertical chroma subsampling factor for the
3869 * specified pixel format.
3871 int drm_format_vert_chroma_subsampling(uint32_t format
)
3874 case DRM_FORMAT_YUV410
:
3875 case DRM_FORMAT_YVU410
:
3877 case DRM_FORMAT_YUV420
:
3878 case DRM_FORMAT_YVU420
:
3879 case DRM_FORMAT_NV12
:
3880 case DRM_FORMAT_NV21
:
3886 EXPORT_SYMBOL(drm_format_vert_chroma_subsampling
);
3889 * drm_mode_config_init - initialize DRM mode_configuration structure
3892 * Initialize @dev's mode_config structure, used for tracking the graphics
3893 * configuration of @dev.
3895 * Since this initializes the modeset locks, no locking is possible. Which is no
3896 * problem, since this should happen single threaded at init time. It is the
3897 * driver's problem to ensure this guarantee.
3900 void drm_mode_config_init(struct drm_device
*dev
)
3902 mutex_init(&dev
->mode_config
.mutex
);
3903 mutex_init(&dev
->mode_config
.idr_mutex
);
3904 mutex_init(&dev
->mode_config
.fb_lock
);
3905 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
3906 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
3907 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
3908 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
3909 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
3910 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
3911 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
3912 idr_init(&dev
->mode_config
.crtc_idr
);
3914 drm_modeset_lock_all(dev
);
3915 drm_mode_create_standard_connector_properties(dev
);
3916 drm_modeset_unlock_all(dev
);
3918 /* Just to be sure */
3919 dev
->mode_config
.num_fb
= 0;
3920 dev
->mode_config
.num_connector
= 0;
3921 dev
->mode_config
.num_crtc
= 0;
3922 dev
->mode_config
.num_encoder
= 0;
3924 EXPORT_SYMBOL(drm_mode_config_init
);
3927 * drm_mode_config_cleanup - free up DRM mode_config info
3930 * Free up all the connectors and CRTCs associated with this DRM device, then
3931 * free up the framebuffers and associated buffer objects.
3933 * Note that since this /should/ happen single-threaded at driver/device
3934 * teardown time, no locking is required. It's the driver's job to ensure that
3935 * this guarantee actually holds true.
3937 * FIXME: cleanup any dangling user buffer objects too
3939 void drm_mode_config_cleanup(struct drm_device
*dev
)
3941 struct drm_connector
*connector
, *ot
;
3942 struct drm_crtc
*crtc
, *ct
;
3943 struct drm_encoder
*encoder
, *enct
;
3944 struct drm_framebuffer
*fb
, *fbt
;
3945 struct drm_property
*property
, *pt
;
3946 struct drm_property_blob
*blob
, *bt
;
3947 struct drm_plane
*plane
, *plt
;
3949 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
3951 encoder
->funcs
->destroy(encoder
);
3954 list_for_each_entry_safe(connector
, ot
,
3955 &dev
->mode_config
.connector_list
, head
) {
3956 connector
->funcs
->destroy(connector
);
3959 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
3961 drm_property_destroy(dev
, property
);
3964 list_for_each_entry_safe(blob
, bt
, &dev
->mode_config
.property_blob_list
,
3966 drm_property_destroy_blob(dev
, blob
);
3970 * Single-threaded teardown context, so it's not required to grab the
3971 * fb_lock to protect against concurrent fb_list access. Contrary, it
3972 * would actually deadlock with the drm_framebuffer_cleanup function.
3974 * Also, if there are any framebuffers left, that's a driver leak now,
3975 * so politely WARN about this.
3977 WARN_ON(!list_empty(&dev
->mode_config
.fb_list
));
3978 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
3979 drm_framebuffer_remove(fb
);
3982 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
3984 plane
->funcs
->destroy(plane
);
3987 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
3988 crtc
->funcs
->destroy(crtc
);
3991 idr_destroy(&dev
->mode_config
.crtc_idr
);
3993 EXPORT_SYMBOL(drm_mode_config_cleanup
);