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>
41 #include "drm_crtc_internal.h"
44 * drm_modeset_lock_all - take all modeset locks
47 * This function takes all modeset locks, suitable where a more fine-grained
48 * scheme isn't (yet) implemented.
50 void drm_modeset_lock_all(struct drm_device
*dev
)
52 struct drm_crtc
*crtc
;
54 mutex_lock(&dev
->mode_config
.mutex
);
56 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
57 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
59 EXPORT_SYMBOL(drm_modeset_lock_all
);
62 * drm_modeset_unlock_all - drop all modeset locks
65 void drm_modeset_unlock_all(struct drm_device
*dev
)
67 struct drm_crtc
*crtc
;
69 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
70 mutex_unlock(&crtc
->mutex
);
72 mutex_unlock(&dev
->mode_config
.mutex
);
74 EXPORT_SYMBOL(drm_modeset_unlock_all
);
77 * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked
80 void drm_warn_on_modeset_not_all_locked(struct drm_device
*dev
)
82 struct drm_crtc
*crtc
;
84 /* Locking is currently fubar in the panic handler. */
88 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
89 WARN_ON(!mutex_is_locked(&crtc
->mutex
));
91 WARN_ON(!mutex_is_locked(&dev
->mode_config
.mutex
));
93 EXPORT_SYMBOL(drm_warn_on_modeset_not_all_locked
);
95 /* Avoid boilerplate. I'm tired of typing. */
96 #define DRM_ENUM_NAME_FN(fnname, list) \
97 const char *fnname(int val) \
100 for (i = 0; i < ARRAY_SIZE(list); i++) { \
101 if (list[i].type == val) \
102 return list[i].name; \
104 return "(unknown)"; \
110 static const struct drm_prop_enum_list drm_dpms_enum_list
[] =
111 { { DRM_MODE_DPMS_ON
, "On" },
112 { DRM_MODE_DPMS_STANDBY
, "Standby" },
113 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
114 { DRM_MODE_DPMS_OFF
, "Off" }
117 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
120 * Optional properties
122 static const struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
124 { DRM_MODE_SCALE_NONE
, "None" },
125 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
126 { DRM_MODE_SCALE_CENTER
, "Center" },
127 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
131 * Non-global properties, but "required" for certain connectors.
133 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
135 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
136 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
137 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
140 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
142 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
144 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
145 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
146 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
149 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
150 drm_dvi_i_subconnector_enum_list
)
152 static const struct drm_prop_enum_list drm_tv_select_enum_list
[] =
154 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
155 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
156 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
157 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
158 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
161 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
163 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
165 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
166 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
167 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
168 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
169 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
172 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
173 drm_tv_subconnector_enum_list
)
175 static const struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
176 { DRM_MODE_DIRTY_OFF
, "Off" },
177 { DRM_MODE_DIRTY_ON
, "On" },
178 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
181 struct drm_conn_prop_enum_list
{
188 * Connector and encoder types.
190 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
191 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown" },
192 { DRM_MODE_CONNECTOR_VGA
, "VGA" },
193 { DRM_MODE_CONNECTOR_DVII
, "DVI-I" },
194 { DRM_MODE_CONNECTOR_DVID
, "DVI-D" },
195 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A" },
196 { DRM_MODE_CONNECTOR_Composite
, "Composite" },
197 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO" },
198 { DRM_MODE_CONNECTOR_LVDS
, "LVDS" },
199 { DRM_MODE_CONNECTOR_Component
, "Component" },
200 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN" },
201 { DRM_MODE_CONNECTOR_DisplayPort
, "DP" },
202 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A" },
203 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B" },
204 { DRM_MODE_CONNECTOR_TV
, "TV" },
205 { DRM_MODE_CONNECTOR_eDP
, "eDP" },
206 { DRM_MODE_CONNECTOR_VIRTUAL
, "Virtual" },
207 { DRM_MODE_CONNECTOR_DSI
, "DSI" },
210 static const struct drm_prop_enum_list drm_encoder_enum_list
[] =
211 { { DRM_MODE_ENCODER_NONE
, "None" },
212 { DRM_MODE_ENCODER_DAC
, "DAC" },
213 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
214 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
215 { DRM_MODE_ENCODER_TVDAC
, "TV" },
216 { DRM_MODE_ENCODER_VIRTUAL
, "Virtual" },
217 { DRM_MODE_ENCODER_DSI
, "DSI" },
220 static const struct drm_prop_enum_list drm_subpixel_enum_list
[] =
222 { SubPixelUnknown
, "Unknown" },
223 { SubPixelHorizontalRGB
, "Horizontal RGB" },
224 { SubPixelHorizontalBGR
, "Horizontal BGR" },
225 { SubPixelVerticalRGB
, "Vertical RGB" },
226 { SubPixelVerticalBGR
, "Vertical BGR" },
227 { SubPixelNone
, "None" },
230 void drm_connector_ida_init(void)
234 for (i
= 0; i
< ARRAY_SIZE(drm_connector_enum_list
); i
++)
235 ida_init(&drm_connector_enum_list
[i
].ida
);
238 void drm_connector_ida_destroy(void)
242 for (i
= 0; i
< ARRAY_SIZE(drm_connector_enum_list
); i
++)
243 ida_destroy(&drm_connector_enum_list
[i
].ida
);
246 const char *drm_get_encoder_name(const struct drm_encoder
*encoder
)
250 snprintf(buf
, 32, "%s-%d",
251 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
255 EXPORT_SYMBOL(drm_get_encoder_name
);
257 const char *drm_get_connector_name(const struct drm_connector
*connector
)
261 snprintf(buf
, 32, "%s-%d",
262 drm_connector_enum_list
[connector
->connector_type
].name
,
263 connector
->connector_type_id
);
266 EXPORT_SYMBOL(drm_get_connector_name
);
268 const char *drm_get_connector_status_name(enum drm_connector_status status
)
270 if (status
== connector_status_connected
)
272 else if (status
== connector_status_disconnected
)
273 return "disconnected";
277 EXPORT_SYMBOL(drm_get_connector_status_name
);
280 * drm_get_subpixel_order_name - return a string for a given subpixel enum
281 * @order: enum of subpixel_order
283 * Note you could abuse this and return something out of bounds, but that
284 * would be a caller error. No unscrubbed user data should make it here.
286 const char *drm_get_subpixel_order_name(enum subpixel_order order
)
288 return drm_subpixel_enum_list
[order
].name
;
290 EXPORT_SYMBOL(drm_get_subpixel_order_name
);
292 static char printable_char(int c
)
294 return isascii(c
) && isprint(c
) ? c
: '?';
297 const char *drm_get_format_name(uint32_t format
)
301 snprintf(buf
, sizeof(buf
),
302 "%c%c%c%c %s-endian (0x%08x)",
303 printable_char(format
& 0xff),
304 printable_char((format
>> 8) & 0xff),
305 printable_char((format
>> 16) & 0xff),
306 printable_char((format
>> 24) & 0x7f),
307 format
& DRM_FORMAT_BIG_ENDIAN
? "big" : "little",
312 EXPORT_SYMBOL(drm_get_format_name
);
315 * drm_mode_object_get - allocate a new modeset identifier
317 * @obj: object pointer, used to generate unique ID
318 * @obj_type: object type
320 * Create a unique identifier based on @ptr in @dev's identifier space. Used
321 * for tracking modes, CRTCs and connectors.
324 * New unique (relative to other objects in @dev) integer identifier for the
327 int drm_mode_object_get(struct drm_device
*dev
,
328 struct drm_mode_object
*obj
, uint32_t obj_type
)
332 mutex_lock(&dev
->mode_config
.idr_mutex
);
333 ret
= idr_alloc(&dev
->mode_config
.crtc_idr
, obj
, 1, 0, GFP_KERNEL
);
336 * Set up the object linking under the protection of the idr
337 * lock so that other users can't see inconsistent state.
340 obj
->type
= obj_type
;
342 mutex_unlock(&dev
->mode_config
.idr_mutex
);
344 return ret
< 0 ? ret
: 0;
348 * drm_mode_object_put - free a modeset identifer
350 * @object: object to free
352 * Free @id from @dev's unique identifier pool.
354 void drm_mode_object_put(struct drm_device
*dev
,
355 struct drm_mode_object
*object
)
357 mutex_lock(&dev
->mode_config
.idr_mutex
);
358 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
359 mutex_unlock(&dev
->mode_config
.idr_mutex
);
363 * drm_mode_object_find - look up a drm object with static lifetime
365 * @id: id of the mode object
366 * @type: type of the mode object
368 * Note that framebuffers cannot be looked up with this functions - since those
369 * are reference counted, they need special treatment.
371 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
372 uint32_t id
, uint32_t type
)
374 struct drm_mode_object
*obj
= NULL
;
376 /* Framebuffers are reference counted and need their own lookup
378 WARN_ON(type
== DRM_MODE_OBJECT_FB
);
380 mutex_lock(&dev
->mode_config
.idr_mutex
);
381 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
382 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
384 mutex_unlock(&dev
->mode_config
.idr_mutex
);
388 EXPORT_SYMBOL(drm_mode_object_find
);
391 * drm_framebuffer_init - initialize a framebuffer
393 * @fb: framebuffer to be initialized
394 * @funcs: ... with these functions
396 * Allocates an ID for the framebuffer's parent mode object, sets its mode
397 * functions & device file and adds it to the master fd list.
400 * This functions publishes the fb and makes it available for concurrent access
401 * by other users. Which means by this point the fb _must_ be fully set up -
402 * since all the fb attributes are invariant over its lifetime, no further
403 * locking but only correct reference counting is required.
406 * Zero on success, error code on failure.
408 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
409 const struct drm_framebuffer_funcs
*funcs
)
413 mutex_lock(&dev
->mode_config
.fb_lock
);
414 kref_init(&fb
->refcount
);
415 INIT_LIST_HEAD(&fb
->filp_head
);
419 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
423 /* Grab the idr reference. */
424 drm_framebuffer_reference(fb
);
426 dev
->mode_config
.num_fb
++;
427 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
429 mutex_unlock(&dev
->mode_config
.fb_lock
);
433 EXPORT_SYMBOL(drm_framebuffer_init
);
435 static void drm_framebuffer_free(struct kref
*kref
)
437 struct drm_framebuffer
*fb
=
438 container_of(kref
, struct drm_framebuffer
, refcount
);
439 fb
->funcs
->destroy(fb
);
442 static struct drm_framebuffer
*__drm_framebuffer_lookup(struct drm_device
*dev
,
445 struct drm_mode_object
*obj
= NULL
;
446 struct drm_framebuffer
*fb
;
448 mutex_lock(&dev
->mode_config
.idr_mutex
);
449 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
450 if (!obj
|| (obj
->type
!= DRM_MODE_OBJECT_FB
) || (obj
->id
!= id
))
454 mutex_unlock(&dev
->mode_config
.idr_mutex
);
460 * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
462 * @id: id of the fb object
464 * If successful, this grabs an additional reference to the framebuffer -
465 * callers need to make sure to eventually unreference the returned framebuffer
468 struct drm_framebuffer
*drm_framebuffer_lookup(struct drm_device
*dev
,
471 struct drm_framebuffer
*fb
;
473 mutex_lock(&dev
->mode_config
.fb_lock
);
474 fb
= __drm_framebuffer_lookup(dev
, id
);
476 drm_framebuffer_reference(fb
);
477 mutex_unlock(&dev
->mode_config
.fb_lock
);
481 EXPORT_SYMBOL(drm_framebuffer_lookup
);
484 * drm_framebuffer_unreference - unref a framebuffer
485 * @fb: framebuffer to unref
487 * This functions decrements the fb's refcount and frees it if it drops to zero.
489 void drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
491 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
492 kref_put(&fb
->refcount
, drm_framebuffer_free
);
494 EXPORT_SYMBOL(drm_framebuffer_unreference
);
497 * drm_framebuffer_reference - incr the fb refcnt
500 void drm_framebuffer_reference(struct drm_framebuffer
*fb
)
502 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
503 kref_get(&fb
->refcount
);
505 EXPORT_SYMBOL(drm_framebuffer_reference
);
507 static void drm_framebuffer_free_bug(struct kref
*kref
)
512 static void __drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
514 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
515 kref_put(&fb
->refcount
, drm_framebuffer_free_bug
);
518 /* dev->mode_config.fb_lock must be held! */
519 static void __drm_framebuffer_unregister(struct drm_device
*dev
,
520 struct drm_framebuffer
*fb
)
522 mutex_lock(&dev
->mode_config
.idr_mutex
);
523 idr_remove(&dev
->mode_config
.crtc_idr
, fb
->base
.id
);
524 mutex_unlock(&dev
->mode_config
.idr_mutex
);
528 __drm_framebuffer_unreference(fb
);
532 * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
533 * @fb: fb to unregister
535 * Drivers need to call this when cleaning up driver-private framebuffers, e.g.
536 * those used for fbdev. Note that the caller must hold a reference of it's own,
537 * i.e. the object may not be destroyed through this call (since it'll lead to a
538 * locking inversion).
540 void drm_framebuffer_unregister_private(struct drm_framebuffer
*fb
)
542 struct drm_device
*dev
= fb
->dev
;
544 mutex_lock(&dev
->mode_config
.fb_lock
);
545 /* Mark fb as reaped and drop idr ref. */
546 __drm_framebuffer_unregister(dev
, fb
);
547 mutex_unlock(&dev
->mode_config
.fb_lock
);
549 EXPORT_SYMBOL(drm_framebuffer_unregister_private
);
552 * drm_framebuffer_cleanup - remove a framebuffer object
553 * @fb: framebuffer to remove
555 * Cleanup references to a user-created framebuffer. This function is intended
556 * to be used from the drivers ->destroy callback.
558 * Note that this function does not remove the fb from active usuage - if it is
559 * still used anywhere, hilarity can ensue since userspace could call getfb on
560 * the id and get back -EINVAL. Obviously no concern at driver unload time.
562 * Also, the framebuffer will not be removed from the lookup idr - for
563 * user-created framebuffers this will happen in in the rmfb ioctl. For
564 * driver-private objects (e.g. for fbdev) drivers need to explicitly call
565 * drm_framebuffer_unregister_private.
567 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
569 struct drm_device
*dev
= fb
->dev
;
571 mutex_lock(&dev
->mode_config
.fb_lock
);
573 dev
->mode_config
.num_fb
--;
574 mutex_unlock(&dev
->mode_config
.fb_lock
);
576 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
579 * drm_framebuffer_remove - remove and unreference a framebuffer object
580 * @fb: framebuffer to remove
582 * Scans all the CRTCs and planes in @dev's mode_config. If they're
583 * using @fb, removes it, setting it to NULL. Then drops the reference to the
584 * passed-in framebuffer. Might take the modeset locks.
586 * Note that this function optimizes the cleanup away if the caller holds the
587 * last reference to the framebuffer. It is also guaranteed to not take the
588 * modeset locks in this case.
590 void drm_framebuffer_remove(struct drm_framebuffer
*fb
)
592 struct drm_device
*dev
= fb
->dev
;
593 struct drm_crtc
*crtc
;
594 struct drm_plane
*plane
;
595 struct drm_mode_set set
;
598 WARN_ON(!list_empty(&fb
->filp_head
));
601 * drm ABI mandates that we remove any deleted framebuffers from active
602 * useage. But since most sane clients only remove framebuffers they no
603 * longer need, try to optimize this away.
605 * Since we're holding a reference ourselves, observing a refcount of 1
606 * means that we're the last holder and can skip it. Also, the refcount
607 * can never increase from 1 again, so we don't need any barriers or
610 * Note that userspace could try to race with use and instate a new
611 * usage _after_ we've cleared all current ones. End result will be an
612 * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
615 if (atomic_read(&fb
->refcount
.refcount
) > 1) {
616 drm_modeset_lock_all(dev
);
617 /* remove from any CRTC */
618 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
619 if (crtc
->fb
== fb
) {
620 /* should turn off the crtc */
621 memset(&set
, 0, sizeof(struct drm_mode_set
));
624 ret
= drm_mode_set_config_internal(&set
);
626 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
630 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
632 drm_plane_force_disable(plane
);
634 drm_modeset_unlock_all(dev
);
637 drm_framebuffer_unreference(fb
);
639 EXPORT_SYMBOL(drm_framebuffer_remove
);
642 * drm_crtc_init - Initialise a new CRTC object
644 * @crtc: CRTC object to init
645 * @funcs: callbacks for the new CRTC
647 * Inits a new object created as base part of a driver crtc object.
650 * Zero on success, error code on failure.
652 int drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
653 const struct drm_crtc_funcs
*funcs
)
659 crtc
->invert_dimensions
= false;
661 drm_modeset_lock_all(dev
);
662 mutex_init(&crtc
->mutex
);
663 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
665 ret
= drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
669 crtc
->base
.properties
= &crtc
->properties
;
671 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
672 dev
->mode_config
.num_crtc
++;
675 drm_modeset_unlock_all(dev
);
679 EXPORT_SYMBOL(drm_crtc_init
);
682 * drm_crtc_cleanup - Clean up the core crtc usage
683 * @crtc: CRTC to cleanup
685 * This function cleans up @crtc and removes it from the DRM mode setting
686 * core. Note that the function does *not* free the crtc structure itself,
687 * this is the responsibility of the caller.
689 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
691 struct drm_device
*dev
= crtc
->dev
;
693 kfree(crtc
->gamma_store
);
694 crtc
->gamma_store
= NULL
;
696 drm_mode_object_put(dev
, &crtc
->base
);
697 list_del(&crtc
->head
);
698 dev
->mode_config
.num_crtc
--;
700 EXPORT_SYMBOL(drm_crtc_cleanup
);
703 * drm_crtc_index - find the index of a registered CRTC
704 * @crtc: CRTC to find index for
706 * Given a registered CRTC, return the index of that CRTC within a DRM
707 * device's list of CRTCs.
709 unsigned int drm_crtc_index(struct drm_crtc
*crtc
)
711 unsigned int index
= 0;
712 struct drm_crtc
*tmp
;
714 list_for_each_entry(tmp
, &crtc
->dev
->mode_config
.crtc_list
, head
) {
723 EXPORT_SYMBOL(drm_crtc_index
);
726 * drm_mode_remove - remove and free a mode
727 * @connector: connector list to modify
728 * @mode: mode to remove
730 * Remove @mode from @connector's mode list, then free it.
732 static void drm_mode_remove(struct drm_connector
*connector
,
733 struct drm_display_mode
*mode
)
735 list_del(&mode
->head
);
736 drm_mode_destroy(connector
->dev
, mode
);
740 * drm_connector_init - Init a preallocated connector
742 * @connector: the connector to init
743 * @funcs: callbacks for this connector
744 * @connector_type: user visible type of the connector
746 * Initialises a preallocated connector. Connectors should be
747 * subclassed as part of driver connector objects.
750 * Zero on success, error code on failure.
752 int drm_connector_init(struct drm_device
*dev
,
753 struct drm_connector
*connector
,
754 const struct drm_connector_funcs
*funcs
,
758 struct ida
*connector_ida
=
759 &drm_connector_enum_list
[connector_type
].ida
;
761 drm_modeset_lock_all(dev
);
763 ret
= drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
767 connector
->base
.properties
= &connector
->properties
;
768 connector
->dev
= dev
;
769 connector
->funcs
= funcs
;
770 connector
->connector_type
= connector_type
;
771 connector
->connector_type_id
=
772 ida_simple_get(connector_ida
, 1, 0, GFP_KERNEL
);
773 if (connector
->connector_type_id
< 0) {
774 ret
= connector
->connector_type_id
;
775 drm_mode_object_put(dev
, &connector
->base
);
778 INIT_LIST_HEAD(&connector
->probed_modes
);
779 INIT_LIST_HEAD(&connector
->modes
);
780 connector
->edid_blob_ptr
= NULL
;
781 connector
->status
= connector_status_unknown
;
783 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
784 dev
->mode_config
.num_connector
++;
786 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
787 drm_object_attach_property(&connector
->base
,
788 dev
->mode_config
.edid_property
,
791 drm_object_attach_property(&connector
->base
,
792 dev
->mode_config
.dpms_property
, 0);
795 drm_modeset_unlock_all(dev
);
799 EXPORT_SYMBOL(drm_connector_init
);
802 * drm_connector_cleanup - cleans up an initialised connector
803 * @connector: connector to cleanup
805 * Cleans up the connector but doesn't free the object.
807 void drm_connector_cleanup(struct drm_connector
*connector
)
809 struct drm_device
*dev
= connector
->dev
;
810 struct drm_display_mode
*mode
, *t
;
812 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
813 drm_mode_remove(connector
, mode
);
815 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
816 drm_mode_remove(connector
, mode
);
818 ida_remove(&drm_connector_enum_list
[connector
->connector_type
].ida
,
819 connector
->connector_type_id
);
821 drm_mode_object_put(dev
, &connector
->base
);
822 list_del(&connector
->head
);
823 dev
->mode_config
.num_connector
--;
825 EXPORT_SYMBOL(drm_connector_cleanup
);
827 void drm_connector_unplug_all(struct drm_device
*dev
)
829 struct drm_connector
*connector
;
831 /* taking the mode config mutex ends up in a clash with sysfs */
832 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
833 drm_sysfs_connector_remove(connector
);
836 EXPORT_SYMBOL(drm_connector_unplug_all
);
838 int drm_bridge_init(struct drm_device
*dev
, struct drm_bridge
*bridge
,
839 const struct drm_bridge_funcs
*funcs
)
843 drm_modeset_lock_all(dev
);
845 ret
= drm_mode_object_get(dev
, &bridge
->base
, DRM_MODE_OBJECT_BRIDGE
);
850 bridge
->funcs
= funcs
;
852 list_add_tail(&bridge
->head
, &dev
->mode_config
.bridge_list
);
853 dev
->mode_config
.num_bridge
++;
856 drm_modeset_unlock_all(dev
);
859 EXPORT_SYMBOL(drm_bridge_init
);
861 void drm_bridge_cleanup(struct drm_bridge
*bridge
)
863 struct drm_device
*dev
= bridge
->dev
;
865 drm_modeset_lock_all(dev
);
866 drm_mode_object_put(dev
, &bridge
->base
);
867 list_del(&bridge
->head
);
868 dev
->mode_config
.num_bridge
--;
869 drm_modeset_unlock_all(dev
);
871 EXPORT_SYMBOL(drm_bridge_cleanup
);
873 int drm_encoder_init(struct drm_device
*dev
,
874 struct drm_encoder
*encoder
,
875 const struct drm_encoder_funcs
*funcs
,
880 drm_modeset_lock_all(dev
);
882 ret
= drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
887 encoder
->encoder_type
= encoder_type
;
888 encoder
->funcs
= funcs
;
890 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
891 dev
->mode_config
.num_encoder
++;
894 drm_modeset_unlock_all(dev
);
898 EXPORT_SYMBOL(drm_encoder_init
);
900 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
902 struct drm_device
*dev
= encoder
->dev
;
903 drm_modeset_lock_all(dev
);
904 drm_mode_object_put(dev
, &encoder
->base
);
905 list_del(&encoder
->head
);
906 dev
->mode_config
.num_encoder
--;
907 drm_modeset_unlock_all(dev
);
909 EXPORT_SYMBOL(drm_encoder_cleanup
);
912 * drm_plane_init - Initialise a new plane object
914 * @plane: plane object to init
915 * @possible_crtcs: bitmask of possible CRTCs
916 * @funcs: callbacks for the new plane
917 * @formats: array of supported formats (%DRM_FORMAT_*)
918 * @format_count: number of elements in @formats
919 * @priv: plane is private (hidden from userspace)?
921 * Inits a new object created as base part of a driver plane object.
924 * Zero on success, error code on failure.
926 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
927 unsigned long possible_crtcs
,
928 const struct drm_plane_funcs
*funcs
,
929 const uint32_t *formats
, uint32_t format_count
,
934 drm_modeset_lock_all(dev
);
936 ret
= drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
940 plane
->base
.properties
= &plane
->properties
;
942 plane
->funcs
= funcs
;
943 plane
->format_types
= kmalloc(sizeof(uint32_t) * format_count
,
945 if (!plane
->format_types
) {
946 DRM_DEBUG_KMS("out of memory when allocating plane\n");
947 drm_mode_object_put(dev
, &plane
->base
);
952 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
953 plane
->format_count
= format_count
;
954 plane
->possible_crtcs
= possible_crtcs
;
956 /* private planes are not exposed to userspace, but depending on
957 * display hardware, might be convenient to allow sharing programming
958 * for the scanout engine with the crtc implementation.
961 list_add_tail(&plane
->head
, &dev
->mode_config
.plane_list
);
962 dev
->mode_config
.num_plane
++;
964 INIT_LIST_HEAD(&plane
->head
);
968 drm_modeset_unlock_all(dev
);
972 EXPORT_SYMBOL(drm_plane_init
);
975 * drm_plane_cleanup - Clean up the core plane usage
976 * @plane: plane to cleanup
978 * This function cleans up @plane and removes it from the DRM mode setting
979 * core. Note that the function does *not* free the plane structure itself,
980 * this is the responsibility of the caller.
982 void drm_plane_cleanup(struct drm_plane
*plane
)
984 struct drm_device
*dev
= plane
->dev
;
986 drm_modeset_lock_all(dev
);
987 kfree(plane
->format_types
);
988 drm_mode_object_put(dev
, &plane
->base
);
989 /* if not added to a list, it must be a private plane */
990 if (!list_empty(&plane
->head
)) {
991 list_del(&plane
->head
);
992 dev
->mode_config
.num_plane
--;
994 drm_modeset_unlock_all(dev
);
996 EXPORT_SYMBOL(drm_plane_cleanup
);
999 * drm_plane_force_disable - Forcibly disable a plane
1000 * @plane: plane to disable
1002 * Forces the plane to be disabled.
1004 * Used when the plane's current framebuffer is destroyed,
1005 * and when restoring fbdev mode.
1007 void drm_plane_force_disable(struct drm_plane
*plane
)
1014 ret
= plane
->funcs
->disable_plane(plane
);
1016 DRM_ERROR("failed to disable plane with busy fb\n");
1017 /* disconnect the plane from the fb and crtc: */
1018 __drm_framebuffer_unreference(plane
->fb
);
1022 EXPORT_SYMBOL(drm_plane_force_disable
);
1024 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
1026 struct drm_property
*edid
;
1027 struct drm_property
*dpms
;
1030 * Standard properties (apply to all connectors)
1032 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
1033 DRM_MODE_PROP_IMMUTABLE
,
1035 dev
->mode_config
.edid_property
= edid
;
1037 dpms
= drm_property_create_enum(dev
, 0,
1038 "DPMS", drm_dpms_enum_list
,
1039 ARRAY_SIZE(drm_dpms_enum_list
));
1040 dev
->mode_config
.dpms_property
= dpms
;
1046 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1049 * Called by a driver the first time a DVI-I connector is made.
1051 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
1053 struct drm_property
*dvi_i_selector
;
1054 struct drm_property
*dvi_i_subconnector
;
1056 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
1060 drm_property_create_enum(dev
, 0,
1061 "select subconnector",
1062 drm_dvi_i_select_enum_list
,
1063 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
1064 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
1066 dvi_i_subconnector
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1068 drm_dvi_i_subconnector_enum_list
,
1069 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
1070 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
1074 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
1077 * drm_create_tv_properties - create TV specific connector properties
1079 * @num_modes: number of different TV formats (modes) supported
1080 * @modes: array of pointers to strings containing name of each format
1082 * Called by a driver's TV initialization routine, this function creates
1083 * the TV specific connector properties for a given device. Caller is
1084 * responsible for allocating a list of format names and passing them to
1087 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
1090 struct drm_property
*tv_selector
;
1091 struct drm_property
*tv_subconnector
;
1094 if (dev
->mode_config
.tv_select_subconnector_property
)
1098 * Basic connector properties
1100 tv_selector
= drm_property_create_enum(dev
, 0,
1101 "select subconnector",
1102 drm_tv_select_enum_list
,
1103 ARRAY_SIZE(drm_tv_select_enum_list
));
1104 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
1107 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1109 drm_tv_subconnector_enum_list
,
1110 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
1111 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
1114 * Other, TV specific properties: margins & TV modes.
1116 dev
->mode_config
.tv_left_margin_property
=
1117 drm_property_create_range(dev
, 0, "left margin", 0, 100);
1119 dev
->mode_config
.tv_right_margin_property
=
1120 drm_property_create_range(dev
, 0, "right margin", 0, 100);
1122 dev
->mode_config
.tv_top_margin_property
=
1123 drm_property_create_range(dev
, 0, "top margin", 0, 100);
1125 dev
->mode_config
.tv_bottom_margin_property
=
1126 drm_property_create_range(dev
, 0, "bottom margin", 0, 100);
1128 dev
->mode_config
.tv_mode_property
=
1129 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
1131 for (i
= 0; i
< num_modes
; i
++)
1132 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
1135 dev
->mode_config
.tv_brightness_property
=
1136 drm_property_create_range(dev
, 0, "brightness", 0, 100);
1138 dev
->mode_config
.tv_contrast_property
=
1139 drm_property_create_range(dev
, 0, "contrast", 0, 100);
1141 dev
->mode_config
.tv_flicker_reduction_property
=
1142 drm_property_create_range(dev
, 0, "flicker reduction", 0, 100);
1144 dev
->mode_config
.tv_overscan_property
=
1145 drm_property_create_range(dev
, 0, "overscan", 0, 100);
1147 dev
->mode_config
.tv_saturation_property
=
1148 drm_property_create_range(dev
, 0, "saturation", 0, 100);
1150 dev
->mode_config
.tv_hue_property
=
1151 drm_property_create_range(dev
, 0, "hue", 0, 100);
1155 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
1158 * drm_mode_create_scaling_mode_property - create scaling mode property
1161 * Called by a driver the first time it's needed, must be attached to desired
1164 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
1166 struct drm_property
*scaling_mode
;
1168 if (dev
->mode_config
.scaling_mode_property
)
1172 drm_property_create_enum(dev
, 0, "scaling mode",
1173 drm_scaling_mode_enum_list
,
1174 ARRAY_SIZE(drm_scaling_mode_enum_list
));
1176 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
1180 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
1183 * drm_mode_create_dirty_property - create dirty property
1186 * Called by a driver the first time it's needed, must be attached to desired
1189 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
1191 struct drm_property
*dirty_info
;
1193 if (dev
->mode_config
.dirty_info_property
)
1197 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1199 drm_dirty_info_enum_list
,
1200 ARRAY_SIZE(drm_dirty_info_enum_list
));
1201 dev
->mode_config
.dirty_info_property
= dirty_info
;
1205 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
1207 static int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
1209 uint32_t total_objects
= 0;
1211 total_objects
+= dev
->mode_config
.num_crtc
;
1212 total_objects
+= dev
->mode_config
.num_connector
;
1213 total_objects
+= dev
->mode_config
.num_encoder
;
1214 total_objects
+= dev
->mode_config
.num_bridge
;
1216 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
1217 if (!group
->id_list
)
1220 group
->num_crtcs
= 0;
1221 group
->num_connectors
= 0;
1222 group
->num_encoders
= 0;
1223 group
->num_bridges
= 0;
1227 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
1228 struct drm_mode_group
*group
)
1230 struct drm_crtc
*crtc
;
1231 struct drm_encoder
*encoder
;
1232 struct drm_connector
*connector
;
1233 struct drm_bridge
*bridge
;
1236 if ((ret
= drm_mode_group_init(dev
, group
)))
1239 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
1240 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
1242 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
1243 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
1246 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
1247 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
1248 group
->num_connectors
++] = connector
->base
.id
;
1250 list_for_each_entry(bridge
, &dev
->mode_config
.bridge_list
, head
)
1251 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
1252 group
->num_connectors
+ group
->num_bridges
++] =
1257 EXPORT_SYMBOL(drm_mode_group_init_legacy_group
);
1260 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1261 * @out: drm_mode_modeinfo struct to return to the user
1262 * @in: drm_display_mode to use
1264 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1267 static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
1268 const struct drm_display_mode
*in
)
1270 WARN(in
->hdisplay
> USHRT_MAX
|| in
->hsync_start
> USHRT_MAX
||
1271 in
->hsync_end
> USHRT_MAX
|| in
->htotal
> USHRT_MAX
||
1272 in
->hskew
> USHRT_MAX
|| in
->vdisplay
> USHRT_MAX
||
1273 in
->vsync_start
> USHRT_MAX
|| in
->vsync_end
> USHRT_MAX
||
1274 in
->vtotal
> USHRT_MAX
|| in
->vscan
> USHRT_MAX
,
1275 "timing values too large for mode info\n");
1277 out
->clock
= in
->clock
;
1278 out
->hdisplay
= in
->hdisplay
;
1279 out
->hsync_start
= in
->hsync_start
;
1280 out
->hsync_end
= in
->hsync_end
;
1281 out
->htotal
= in
->htotal
;
1282 out
->hskew
= in
->hskew
;
1283 out
->vdisplay
= in
->vdisplay
;
1284 out
->vsync_start
= in
->vsync_start
;
1285 out
->vsync_end
= in
->vsync_end
;
1286 out
->vtotal
= in
->vtotal
;
1287 out
->vscan
= in
->vscan
;
1288 out
->vrefresh
= in
->vrefresh
;
1289 out
->flags
= in
->flags
;
1290 out
->type
= in
->type
;
1291 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1292 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1296 * drm_crtc_convert_umode - convert a modeinfo into a drm_display_mode
1297 * @out: drm_display_mode to return to the user
1298 * @in: drm_mode_modeinfo to use
1300 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1304 * Zero on success, errno on failure.
1306 static int drm_crtc_convert_umode(struct drm_display_mode
*out
,
1307 const struct drm_mode_modeinfo
*in
)
1309 if (in
->clock
> INT_MAX
|| in
->vrefresh
> INT_MAX
)
1312 if ((in
->flags
& DRM_MODE_FLAG_3D_MASK
) > DRM_MODE_FLAG_3D_MAX
)
1315 out
->clock
= in
->clock
;
1316 out
->hdisplay
= in
->hdisplay
;
1317 out
->hsync_start
= in
->hsync_start
;
1318 out
->hsync_end
= in
->hsync_end
;
1319 out
->htotal
= in
->htotal
;
1320 out
->hskew
= in
->hskew
;
1321 out
->vdisplay
= in
->vdisplay
;
1322 out
->vsync_start
= in
->vsync_start
;
1323 out
->vsync_end
= in
->vsync_end
;
1324 out
->vtotal
= in
->vtotal
;
1325 out
->vscan
= in
->vscan
;
1326 out
->vrefresh
= in
->vrefresh
;
1327 out
->flags
= in
->flags
;
1328 out
->type
= in
->type
;
1329 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1330 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1336 * drm_mode_getresources - get graphics configuration
1337 * @dev: drm device for the ioctl
1338 * @data: data pointer for the ioctl
1339 * @file_priv: drm file for the ioctl call
1341 * Construct a set of configuration description structures and return
1342 * them to the user, including CRTC, connector and framebuffer configuration.
1344 * Called by the user via ioctl.
1347 * Zero on success, errno on failure.
1349 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1350 struct drm_file
*file_priv
)
1352 struct drm_mode_card_res
*card_res
= data
;
1353 struct list_head
*lh
;
1354 struct drm_framebuffer
*fb
;
1355 struct drm_connector
*connector
;
1356 struct drm_crtc
*crtc
;
1357 struct drm_encoder
*encoder
;
1359 int connector_count
= 0;
1362 int encoder_count
= 0;
1364 uint32_t __user
*fb_id
;
1365 uint32_t __user
*crtc_id
;
1366 uint32_t __user
*connector_id
;
1367 uint32_t __user
*encoder_id
;
1368 struct drm_mode_group
*mode_group
;
1370 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1374 mutex_lock(&file_priv
->fbs_lock
);
1376 * For the non-control nodes we need to limit the list of resources
1377 * by IDs in the group list for this node
1379 list_for_each(lh
, &file_priv
->fbs
)
1382 /* handle this in 4 parts */
1384 if (card_res
->count_fbs
>= fb_count
) {
1386 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1387 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1388 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1389 mutex_unlock(&file_priv
->fbs_lock
);
1395 card_res
->count_fbs
= fb_count
;
1396 mutex_unlock(&file_priv
->fbs_lock
);
1398 drm_modeset_lock_all(dev
);
1399 mode_group
= &file_priv
->master
->minor
->mode_group
;
1400 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1402 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1405 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1408 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1412 crtc_count
= mode_group
->num_crtcs
;
1413 connector_count
= mode_group
->num_connectors
;
1414 encoder_count
= mode_group
->num_encoders
;
1417 card_res
->max_height
= dev
->mode_config
.max_height
;
1418 card_res
->min_height
= dev
->mode_config
.min_height
;
1419 card_res
->max_width
= dev
->mode_config
.max_width
;
1420 card_res
->min_width
= dev
->mode_config
.min_width
;
1423 if (card_res
->count_crtcs
>= crtc_count
) {
1425 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1426 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1427 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1429 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1430 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1437 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1438 if (put_user(mode_group
->id_list
[i
],
1439 crtc_id
+ copied
)) {
1447 card_res
->count_crtcs
= crtc_count
;
1450 if (card_res
->count_encoders
>= encoder_count
) {
1452 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1453 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1454 list_for_each_entry(encoder
,
1455 &dev
->mode_config
.encoder_list
,
1457 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1458 drm_get_encoder_name(encoder
));
1459 if (put_user(encoder
->base
.id
, encoder_id
+
1467 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1468 if (put_user(mode_group
->id_list
[i
],
1469 encoder_id
+ copied
)) {
1478 card_res
->count_encoders
= encoder_count
;
1481 if (card_res
->count_connectors
>= connector_count
) {
1483 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1484 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1485 list_for_each_entry(connector
,
1486 &dev
->mode_config
.connector_list
,
1488 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1490 drm_get_connector_name(connector
));
1491 if (put_user(connector
->base
.id
,
1492 connector_id
+ copied
)) {
1499 int start
= mode_group
->num_crtcs
+
1500 mode_group
->num_encoders
;
1501 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1502 if (put_user(mode_group
->id_list
[i
],
1503 connector_id
+ copied
)) {
1511 card_res
->count_connectors
= connector_count
;
1513 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1514 card_res
->count_connectors
, card_res
->count_encoders
);
1517 drm_modeset_unlock_all(dev
);
1522 * drm_mode_getcrtc - get CRTC configuration
1523 * @dev: drm device for the ioctl
1524 * @data: data pointer for the ioctl
1525 * @file_priv: drm file for the ioctl call
1527 * Construct a CRTC configuration structure to return to the user.
1529 * Called by the user via ioctl.
1532 * Zero on success, errno on failure.
1534 int drm_mode_getcrtc(struct drm_device
*dev
,
1535 void *data
, struct drm_file
*file_priv
)
1537 struct drm_mode_crtc
*crtc_resp
= data
;
1538 struct drm_crtc
*crtc
;
1539 struct drm_mode_object
*obj
;
1542 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1545 drm_modeset_lock_all(dev
);
1547 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1548 DRM_MODE_OBJECT_CRTC
);
1553 crtc
= obj_to_crtc(obj
);
1555 crtc_resp
->x
= crtc
->x
;
1556 crtc_resp
->y
= crtc
->y
;
1557 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1559 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1561 crtc_resp
->fb_id
= 0;
1563 if (crtc
->enabled
) {
1565 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1566 crtc_resp
->mode_valid
= 1;
1569 crtc_resp
->mode_valid
= 0;
1573 drm_modeset_unlock_all(dev
);
1577 static bool drm_mode_expose_to_userspace(const struct drm_display_mode
*mode
,
1578 const struct drm_file
*file_priv
)
1581 * If user-space hasn't configured the driver to expose the stereo 3D
1582 * modes, don't expose them.
1584 if (!file_priv
->stereo_allowed
&& drm_mode_is_stereo(mode
))
1591 * drm_mode_getconnector - get connector configuration
1592 * @dev: drm device for the ioctl
1593 * @data: data pointer for the ioctl
1594 * @file_priv: drm file for the ioctl call
1596 * Construct a connector configuration structure to return to the user.
1598 * Called by the user via ioctl.
1601 * Zero on success, errno on failure.
1603 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1604 struct drm_file
*file_priv
)
1606 struct drm_mode_get_connector
*out_resp
= data
;
1607 struct drm_mode_object
*obj
;
1608 struct drm_connector
*connector
;
1609 struct drm_display_mode
*mode
;
1611 int props_count
= 0;
1612 int encoders_count
= 0;
1616 struct drm_mode_modeinfo u_mode
;
1617 struct drm_mode_modeinfo __user
*mode_ptr
;
1618 uint32_t __user
*prop_ptr
;
1619 uint64_t __user
*prop_values
;
1620 uint32_t __user
*encoder_ptr
;
1622 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1625 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1627 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1629 mutex_lock(&dev
->mode_config
.mutex
);
1631 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1632 DRM_MODE_OBJECT_CONNECTOR
);
1637 connector
= obj_to_connector(obj
);
1639 props_count
= connector
->properties
.count
;
1641 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1642 if (connector
->encoder_ids
[i
] != 0) {
1647 if (out_resp
->count_modes
== 0) {
1648 connector
->funcs
->fill_modes(connector
,
1649 dev
->mode_config
.max_width
,
1650 dev
->mode_config
.max_height
);
1653 /* delayed so we get modes regardless of pre-fill_modes state */
1654 list_for_each_entry(mode
, &connector
->modes
, head
)
1655 if (drm_mode_expose_to_userspace(mode
, file_priv
))
1658 out_resp
->connector_id
= connector
->base
.id
;
1659 out_resp
->connector_type
= connector
->connector_type
;
1660 out_resp
->connector_type_id
= connector
->connector_type_id
;
1661 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1662 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1663 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1664 out_resp
->connection
= connector
->status
;
1665 if (connector
->encoder
)
1666 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1668 out_resp
->encoder_id
= 0;
1671 * This ioctl is called twice, once to determine how much space is
1672 * needed, and the 2nd time to fill it.
1674 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1676 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1677 list_for_each_entry(mode
, &connector
->modes
, head
) {
1678 if (!drm_mode_expose_to_userspace(mode
, file_priv
))
1681 drm_crtc_convert_to_umode(&u_mode
, mode
);
1682 if (copy_to_user(mode_ptr
+ copied
,
1683 &u_mode
, sizeof(u_mode
))) {
1690 out_resp
->count_modes
= mode_count
;
1692 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1694 prop_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
);
1695 prop_values
= (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
);
1696 for (i
= 0; i
< connector
->properties
.count
; i
++) {
1697 if (put_user(connector
->properties
.ids
[i
],
1698 prop_ptr
+ copied
)) {
1703 if (put_user(connector
->properties
.values
[i
],
1704 prop_values
+ copied
)) {
1711 out_resp
->count_props
= props_count
;
1713 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1715 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1716 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1717 if (connector
->encoder_ids
[i
] != 0) {
1718 if (put_user(connector
->encoder_ids
[i
],
1719 encoder_ptr
+ copied
)) {
1727 out_resp
->count_encoders
= encoders_count
;
1730 mutex_unlock(&dev
->mode_config
.mutex
);
1735 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1736 struct drm_file
*file_priv
)
1738 struct drm_mode_get_encoder
*enc_resp
= data
;
1739 struct drm_mode_object
*obj
;
1740 struct drm_encoder
*encoder
;
1743 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1746 drm_modeset_lock_all(dev
);
1747 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1748 DRM_MODE_OBJECT_ENCODER
);
1753 encoder
= obj_to_encoder(obj
);
1756 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1758 enc_resp
->crtc_id
= 0;
1759 enc_resp
->encoder_type
= encoder
->encoder_type
;
1760 enc_resp
->encoder_id
= encoder
->base
.id
;
1761 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1762 enc_resp
->possible_clones
= encoder
->possible_clones
;
1765 drm_modeset_unlock_all(dev
);
1770 * drm_mode_getplane_res - get plane info
1773 * @file_priv: DRM file info
1775 * Return an plane count and set of IDs.
1777 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
1778 struct drm_file
*file_priv
)
1780 struct drm_mode_get_plane_res
*plane_resp
= data
;
1781 struct drm_mode_config
*config
;
1782 struct drm_plane
*plane
;
1783 uint32_t __user
*plane_ptr
;
1784 int copied
= 0, ret
= 0;
1786 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1789 drm_modeset_lock_all(dev
);
1790 config
= &dev
->mode_config
;
1793 * This ioctl is called twice, once to determine how much space is
1794 * needed, and the 2nd time to fill it.
1796 if (config
->num_plane
&&
1797 (plane_resp
->count_planes
>= config
->num_plane
)) {
1798 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
1800 list_for_each_entry(plane
, &config
->plane_list
, head
) {
1801 if (put_user(plane
->base
.id
, plane_ptr
+ copied
)) {
1808 plane_resp
->count_planes
= config
->num_plane
;
1811 drm_modeset_unlock_all(dev
);
1816 * drm_mode_getplane - get plane info
1819 * @file_priv: DRM file info
1821 * Return plane info, including formats supported, gamma size, any
1824 int drm_mode_getplane(struct drm_device
*dev
, void *data
,
1825 struct drm_file
*file_priv
)
1827 struct drm_mode_get_plane
*plane_resp
= data
;
1828 struct drm_mode_object
*obj
;
1829 struct drm_plane
*plane
;
1830 uint32_t __user
*format_ptr
;
1833 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1836 drm_modeset_lock_all(dev
);
1837 obj
= drm_mode_object_find(dev
, plane_resp
->plane_id
,
1838 DRM_MODE_OBJECT_PLANE
);
1843 plane
= obj_to_plane(obj
);
1846 plane_resp
->crtc_id
= plane
->crtc
->base
.id
;
1848 plane_resp
->crtc_id
= 0;
1851 plane_resp
->fb_id
= plane
->fb
->base
.id
;
1853 plane_resp
->fb_id
= 0;
1855 plane_resp
->plane_id
= plane
->base
.id
;
1856 plane_resp
->possible_crtcs
= plane
->possible_crtcs
;
1857 plane_resp
->gamma_size
= 0;
1860 * This ioctl is called twice, once to determine how much space is
1861 * needed, and the 2nd time to fill it.
1863 if (plane
->format_count
&&
1864 (plane_resp
->count_format_types
>= plane
->format_count
)) {
1865 format_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->format_type_ptr
;
1866 if (copy_to_user(format_ptr
,
1867 plane
->format_types
,
1868 sizeof(uint32_t) * plane
->format_count
)) {
1873 plane_resp
->count_format_types
= plane
->format_count
;
1876 drm_modeset_unlock_all(dev
);
1881 * drm_mode_setplane - set up or tear down an plane
1883 * @data: ioctl data*
1884 * @file_priv: DRM file info
1886 * Set plane info, including placement, fb, scaling, and other factors.
1887 * Or pass a NULL fb to disable.
1889 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
1890 struct drm_file
*file_priv
)
1892 struct drm_mode_set_plane
*plane_req
= data
;
1893 struct drm_mode_object
*obj
;
1894 struct drm_plane
*plane
;
1895 struct drm_crtc
*crtc
;
1896 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
1898 unsigned int fb_width
, fb_height
;
1901 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1905 * First, find the plane, crtc, and fb objects. If not available,
1906 * we don't bother to call the driver.
1908 obj
= drm_mode_object_find(dev
, plane_req
->plane_id
,
1909 DRM_MODE_OBJECT_PLANE
);
1911 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1912 plane_req
->plane_id
);
1915 plane
= obj_to_plane(obj
);
1917 /* No fb means shut it down */
1918 if (!plane_req
->fb_id
) {
1919 drm_modeset_lock_all(dev
);
1921 plane
->funcs
->disable_plane(plane
);
1924 drm_modeset_unlock_all(dev
);
1928 obj
= drm_mode_object_find(dev
, plane_req
->crtc_id
,
1929 DRM_MODE_OBJECT_CRTC
);
1931 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1932 plane_req
->crtc_id
);
1936 crtc
= obj_to_crtc(obj
);
1938 fb
= drm_framebuffer_lookup(dev
, plane_req
->fb_id
);
1940 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1946 /* Check whether this plane supports the fb pixel format. */
1947 for (i
= 0; i
< plane
->format_count
; i
++)
1948 if (fb
->pixel_format
== plane
->format_types
[i
])
1950 if (i
== plane
->format_count
) {
1951 DRM_DEBUG_KMS("Invalid pixel format %s\n",
1952 drm_get_format_name(fb
->pixel_format
));
1957 fb_width
= fb
->width
<< 16;
1958 fb_height
= fb
->height
<< 16;
1960 /* Make sure source coordinates are inside the fb. */
1961 if (plane_req
->src_w
> fb_width
||
1962 plane_req
->src_x
> fb_width
- plane_req
->src_w
||
1963 plane_req
->src_h
> fb_height
||
1964 plane_req
->src_y
> fb_height
- plane_req
->src_h
) {
1965 DRM_DEBUG_KMS("Invalid source coordinates "
1966 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1967 plane_req
->src_w
>> 16,
1968 ((plane_req
->src_w
& 0xffff) * 15625) >> 10,
1969 plane_req
->src_h
>> 16,
1970 ((plane_req
->src_h
& 0xffff) * 15625) >> 10,
1971 plane_req
->src_x
>> 16,
1972 ((plane_req
->src_x
& 0xffff) * 15625) >> 10,
1973 plane_req
->src_y
>> 16,
1974 ((plane_req
->src_y
& 0xffff) * 15625) >> 10);
1979 /* Give drivers some help against integer overflows */
1980 if (plane_req
->crtc_w
> INT_MAX
||
1981 plane_req
->crtc_x
> INT_MAX
- (int32_t) plane_req
->crtc_w
||
1982 plane_req
->crtc_h
> INT_MAX
||
1983 plane_req
->crtc_y
> INT_MAX
- (int32_t) plane_req
->crtc_h
) {
1984 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
1985 plane_req
->crtc_w
, plane_req
->crtc_h
,
1986 plane_req
->crtc_x
, plane_req
->crtc_y
);
1991 drm_modeset_lock_all(dev
);
1992 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
1993 plane_req
->crtc_x
, plane_req
->crtc_y
,
1994 plane_req
->crtc_w
, plane_req
->crtc_h
,
1995 plane_req
->src_x
, plane_req
->src_y
,
1996 plane_req
->src_w
, plane_req
->src_h
);
2003 drm_modeset_unlock_all(dev
);
2007 drm_framebuffer_unreference(fb
);
2009 drm_framebuffer_unreference(old_fb
);
2015 * drm_mode_set_config_internal - helper to call ->set_config
2016 * @set: modeset config to set
2018 * This is a little helper to wrap internal calls to the ->set_config driver
2019 * interface. The only thing it adds is correct refcounting dance.
2021 int drm_mode_set_config_internal(struct drm_mode_set
*set
)
2023 struct drm_crtc
*crtc
= set
->crtc
;
2024 struct drm_framebuffer
*fb
;
2025 struct drm_crtc
*tmp
;
2029 * NOTE: ->set_config can also disable other crtcs (if we steal all
2030 * connectors from it), hence we need to refcount the fbs across all
2031 * crtcs. Atomic modeset will have saner semantics ...
2033 list_for_each_entry(tmp
, &crtc
->dev
->mode_config
.crtc_list
, head
)
2034 tmp
->old_fb
= tmp
->fb
;
2038 ret
= crtc
->funcs
->set_config(set
);
2040 /* crtc->fb must be updated by ->set_config, enforces this. */
2041 WARN_ON(fb
!= crtc
->fb
);
2044 list_for_each_entry(tmp
, &crtc
->dev
->mode_config
.crtc_list
, head
) {
2046 drm_framebuffer_reference(tmp
->fb
);
2048 drm_framebuffer_unreference(tmp
->old_fb
);
2053 EXPORT_SYMBOL(drm_mode_set_config_internal
);
2056 * Checks that the framebuffer is big enough for the CRTC viewport
2057 * (x, y, hdisplay, vdisplay)
2059 static int drm_crtc_check_viewport(const struct drm_crtc
*crtc
,
2061 const struct drm_display_mode
*mode
,
2062 const struct drm_framebuffer
*fb
)
2065 int hdisplay
, vdisplay
;
2067 hdisplay
= mode
->hdisplay
;
2068 vdisplay
= mode
->vdisplay
;
2070 if (drm_mode_is_stereo(mode
)) {
2071 struct drm_display_mode adjusted
= *mode
;
2073 drm_mode_set_crtcinfo(&adjusted
, CRTC_STEREO_DOUBLE
);
2074 hdisplay
= adjusted
.crtc_hdisplay
;
2075 vdisplay
= adjusted
.crtc_vdisplay
;
2078 if (crtc
->invert_dimensions
)
2079 swap(hdisplay
, vdisplay
);
2081 if (hdisplay
> fb
->width
||
2082 vdisplay
> fb
->height
||
2083 x
> fb
->width
- hdisplay
||
2084 y
> fb
->height
- vdisplay
) {
2085 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
2086 fb
->width
, fb
->height
, hdisplay
, vdisplay
, x
, y
,
2087 crtc
->invert_dimensions
? " (inverted)" : "");
2095 * drm_mode_setcrtc - set CRTC configuration
2096 * @dev: drm device for the ioctl
2097 * @data: data pointer for the ioctl
2098 * @file_priv: drm file for the ioctl call
2100 * Build a new CRTC configuration based on user request.
2102 * Called by the user via ioctl.
2105 * Zero on success, errno on failure.
2107 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
2108 struct drm_file
*file_priv
)
2110 struct drm_mode_config
*config
= &dev
->mode_config
;
2111 struct drm_mode_crtc
*crtc_req
= data
;
2112 struct drm_mode_object
*obj
;
2113 struct drm_crtc
*crtc
;
2114 struct drm_connector
**connector_set
= NULL
, *connector
;
2115 struct drm_framebuffer
*fb
= NULL
;
2116 struct drm_display_mode
*mode
= NULL
;
2117 struct drm_mode_set set
;
2118 uint32_t __user
*set_connectors_ptr
;
2122 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2125 /* For some reason crtc x/y offsets are signed internally. */
2126 if (crtc_req
->x
> INT_MAX
|| crtc_req
->y
> INT_MAX
)
2129 drm_modeset_lock_all(dev
);
2130 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
2131 DRM_MODE_OBJECT_CRTC
);
2133 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
2137 crtc
= obj_to_crtc(obj
);
2138 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
2140 if (crtc_req
->mode_valid
) {
2141 /* If we have a mode we need a framebuffer. */
2142 /* If we pass -1, set the mode with the currently bound fb */
2143 if (crtc_req
->fb_id
== -1) {
2145 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
2150 /* Make refcounting symmetric with the lookup path. */
2151 drm_framebuffer_reference(fb
);
2153 fb
= drm_framebuffer_lookup(dev
, crtc_req
->fb_id
);
2155 DRM_DEBUG_KMS("Unknown FB ID%d\n",
2162 mode
= drm_mode_create(dev
);
2168 ret
= drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
2170 DRM_DEBUG_KMS("Invalid mode\n");
2174 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
2176 ret
= drm_crtc_check_viewport(crtc
, crtc_req
->x
, crtc_req
->y
,
2183 if (crtc_req
->count_connectors
== 0 && mode
) {
2184 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
2189 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
2190 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
2191 crtc_req
->count_connectors
);
2196 if (crtc_req
->count_connectors
> 0) {
2199 /* Avoid unbounded kernel memory allocation */
2200 if (crtc_req
->count_connectors
> config
->num_connector
) {
2205 connector_set
= kmalloc(crtc_req
->count_connectors
*
2206 sizeof(struct drm_connector
*),
2208 if (!connector_set
) {
2213 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
2214 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
2215 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
2220 obj
= drm_mode_object_find(dev
, out_id
,
2221 DRM_MODE_OBJECT_CONNECTOR
);
2223 DRM_DEBUG_KMS("Connector id %d unknown\n",
2228 connector
= obj_to_connector(obj
);
2229 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2231 drm_get_connector_name(connector
));
2233 connector_set
[i
] = connector
;
2238 set
.x
= crtc_req
->x
;
2239 set
.y
= crtc_req
->y
;
2241 set
.connectors
= connector_set
;
2242 set
.num_connectors
= crtc_req
->count_connectors
;
2244 ret
= drm_mode_set_config_internal(&set
);
2248 drm_framebuffer_unreference(fb
);
2250 kfree(connector_set
);
2251 drm_mode_destroy(dev
, mode
);
2252 drm_modeset_unlock_all(dev
);
2256 static int drm_mode_cursor_common(struct drm_device
*dev
,
2257 struct drm_mode_cursor2
*req
,
2258 struct drm_file
*file_priv
)
2260 struct drm_mode_object
*obj
;
2261 struct drm_crtc
*crtc
;
2264 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2267 if (!req
->flags
|| (~DRM_MODE_CURSOR_FLAGS
& req
->flags
))
2270 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2272 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
2275 crtc
= obj_to_crtc(obj
);
2277 mutex_lock(&crtc
->mutex
);
2278 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
2279 if (!crtc
->funcs
->cursor_set
&& !crtc
->funcs
->cursor_set2
) {
2283 /* Turns off the cursor if handle is 0 */
2284 if (crtc
->funcs
->cursor_set2
)
2285 ret
= crtc
->funcs
->cursor_set2(crtc
, file_priv
, req
->handle
,
2286 req
->width
, req
->height
, req
->hot_x
, req
->hot_y
);
2288 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
2289 req
->width
, req
->height
);
2292 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
2293 if (crtc
->funcs
->cursor_move
) {
2294 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
2301 mutex_unlock(&crtc
->mutex
);
2306 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
2307 void *data
, struct drm_file
*file_priv
)
2309 struct drm_mode_cursor
*req
= data
;
2310 struct drm_mode_cursor2 new_req
;
2312 memcpy(&new_req
, req
, sizeof(struct drm_mode_cursor
));
2313 new_req
.hot_x
= new_req
.hot_y
= 0;
2315 return drm_mode_cursor_common(dev
, &new_req
, file_priv
);
2318 int drm_mode_cursor2_ioctl(struct drm_device
*dev
,
2319 void *data
, struct drm_file
*file_priv
)
2321 struct drm_mode_cursor2
*req
= data
;
2322 return drm_mode_cursor_common(dev
, req
, file_priv
);
2325 /* Original addfb only supported RGB formats, so figure out which one */
2326 uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
)
2332 fmt
= DRM_FORMAT_C8
;
2336 fmt
= DRM_FORMAT_XRGB1555
;
2338 fmt
= DRM_FORMAT_RGB565
;
2341 fmt
= DRM_FORMAT_RGB888
;
2345 fmt
= DRM_FORMAT_XRGB8888
;
2346 else if (depth
== 30)
2347 fmt
= DRM_FORMAT_XRGB2101010
;
2349 fmt
= DRM_FORMAT_ARGB8888
;
2352 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
2353 fmt
= DRM_FORMAT_XRGB8888
;
2359 EXPORT_SYMBOL(drm_mode_legacy_fb_format
);
2362 * drm_mode_addfb - add an FB to the graphics configuration
2363 * @dev: drm device for the ioctl
2364 * @data: data pointer for the ioctl
2365 * @file_priv: drm file for the ioctl call
2367 * Add a new FB to the specified CRTC, given a user request.
2369 * Called by the user via ioctl.
2372 * Zero on success, errno on failure.
2374 int drm_mode_addfb(struct drm_device
*dev
,
2375 void *data
, struct drm_file
*file_priv
)
2377 struct drm_mode_fb_cmd
*or = data
;
2378 struct drm_mode_fb_cmd2 r
= {};
2379 struct drm_mode_config
*config
= &dev
->mode_config
;
2380 struct drm_framebuffer
*fb
;
2383 /* Use new struct with format internally */
2384 r
.fb_id
= or->fb_id
;
2385 r
.width
= or->width
;
2386 r
.height
= or->height
;
2387 r
.pitches
[0] = or->pitch
;
2388 r
.pixel_format
= drm_mode_legacy_fb_format(or->bpp
, or->depth
);
2389 r
.handles
[0] = or->handle
;
2391 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2394 if ((config
->min_width
> r
.width
) || (r
.width
> config
->max_width
))
2397 if ((config
->min_height
> r
.height
) || (r
.height
> config
->max_height
))
2400 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, &r
);
2402 DRM_DEBUG_KMS("could not create framebuffer\n");
2406 mutex_lock(&file_priv
->fbs_lock
);
2407 or->fb_id
= fb
->base
.id
;
2408 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2409 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2410 mutex_unlock(&file_priv
->fbs_lock
);
2415 static int format_check(const struct drm_mode_fb_cmd2
*r
)
2417 uint32_t format
= r
->pixel_format
& ~DRM_FORMAT_BIG_ENDIAN
;
2421 case DRM_FORMAT_RGB332
:
2422 case DRM_FORMAT_BGR233
:
2423 case DRM_FORMAT_XRGB4444
:
2424 case DRM_FORMAT_XBGR4444
:
2425 case DRM_FORMAT_RGBX4444
:
2426 case DRM_FORMAT_BGRX4444
:
2427 case DRM_FORMAT_ARGB4444
:
2428 case DRM_FORMAT_ABGR4444
:
2429 case DRM_FORMAT_RGBA4444
:
2430 case DRM_FORMAT_BGRA4444
:
2431 case DRM_FORMAT_XRGB1555
:
2432 case DRM_FORMAT_XBGR1555
:
2433 case DRM_FORMAT_RGBX5551
:
2434 case DRM_FORMAT_BGRX5551
:
2435 case DRM_FORMAT_ARGB1555
:
2436 case DRM_FORMAT_ABGR1555
:
2437 case DRM_FORMAT_RGBA5551
:
2438 case DRM_FORMAT_BGRA5551
:
2439 case DRM_FORMAT_RGB565
:
2440 case DRM_FORMAT_BGR565
:
2441 case DRM_FORMAT_RGB888
:
2442 case DRM_FORMAT_BGR888
:
2443 case DRM_FORMAT_XRGB8888
:
2444 case DRM_FORMAT_XBGR8888
:
2445 case DRM_FORMAT_RGBX8888
:
2446 case DRM_FORMAT_BGRX8888
:
2447 case DRM_FORMAT_ARGB8888
:
2448 case DRM_FORMAT_ABGR8888
:
2449 case DRM_FORMAT_RGBA8888
:
2450 case DRM_FORMAT_BGRA8888
:
2451 case DRM_FORMAT_XRGB2101010
:
2452 case DRM_FORMAT_XBGR2101010
:
2453 case DRM_FORMAT_RGBX1010102
:
2454 case DRM_FORMAT_BGRX1010102
:
2455 case DRM_FORMAT_ARGB2101010
:
2456 case DRM_FORMAT_ABGR2101010
:
2457 case DRM_FORMAT_RGBA1010102
:
2458 case DRM_FORMAT_BGRA1010102
:
2459 case DRM_FORMAT_YUYV
:
2460 case DRM_FORMAT_YVYU
:
2461 case DRM_FORMAT_UYVY
:
2462 case DRM_FORMAT_VYUY
:
2463 case DRM_FORMAT_AYUV
:
2464 case DRM_FORMAT_NV12
:
2465 case DRM_FORMAT_NV21
:
2466 case DRM_FORMAT_NV16
:
2467 case DRM_FORMAT_NV61
:
2468 case DRM_FORMAT_NV24
:
2469 case DRM_FORMAT_NV42
:
2470 case DRM_FORMAT_YUV410
:
2471 case DRM_FORMAT_YVU410
:
2472 case DRM_FORMAT_YUV411
:
2473 case DRM_FORMAT_YVU411
:
2474 case DRM_FORMAT_YUV420
:
2475 case DRM_FORMAT_YVU420
:
2476 case DRM_FORMAT_YUV422
:
2477 case DRM_FORMAT_YVU422
:
2478 case DRM_FORMAT_YUV444
:
2479 case DRM_FORMAT_YVU444
:
2482 DRM_DEBUG_KMS("invalid pixel format %s\n",
2483 drm_get_format_name(r
->pixel_format
));
2488 static int framebuffer_check(const struct drm_mode_fb_cmd2
*r
)
2490 int ret
, hsub
, vsub
, num_planes
, i
;
2492 ret
= format_check(r
);
2494 DRM_DEBUG_KMS("bad framebuffer format %s\n",
2495 drm_get_format_name(r
->pixel_format
));
2499 hsub
= drm_format_horz_chroma_subsampling(r
->pixel_format
);
2500 vsub
= drm_format_vert_chroma_subsampling(r
->pixel_format
);
2501 num_planes
= drm_format_num_planes(r
->pixel_format
);
2503 if (r
->width
== 0 || r
->width
% hsub
) {
2504 DRM_DEBUG_KMS("bad framebuffer width %u\n", r
->height
);
2508 if (r
->height
== 0 || r
->height
% vsub
) {
2509 DRM_DEBUG_KMS("bad framebuffer height %u\n", r
->height
);
2513 for (i
= 0; i
< num_planes
; i
++) {
2514 unsigned int width
= r
->width
/ (i
!= 0 ? hsub
: 1);
2515 unsigned int height
= r
->height
/ (i
!= 0 ? vsub
: 1);
2516 unsigned int cpp
= drm_format_plane_cpp(r
->pixel_format
, i
);
2518 if (!r
->handles
[i
]) {
2519 DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i
);
2523 if ((uint64_t) width
* cpp
> UINT_MAX
)
2526 if ((uint64_t) height
* r
->pitches
[i
] + r
->offsets
[i
] > UINT_MAX
)
2529 if (r
->pitches
[i
] < width
* cpp
) {
2530 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r
->pitches
[i
], i
);
2539 * drm_mode_addfb2 - add an FB to the graphics configuration
2540 * @dev: drm device for the ioctl
2541 * @data: data pointer for the ioctl
2542 * @file_priv: drm file for the ioctl call
2544 * Add a new FB to the specified CRTC, given a user request with format.
2546 * Called by the user via ioctl.
2549 * Zero on success, errno on failure.
2551 int drm_mode_addfb2(struct drm_device
*dev
,
2552 void *data
, struct drm_file
*file_priv
)
2554 struct drm_mode_fb_cmd2
*r
= data
;
2555 struct drm_mode_config
*config
= &dev
->mode_config
;
2556 struct drm_framebuffer
*fb
;
2559 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2562 if (r
->flags
& ~DRM_MODE_FB_INTERLACED
) {
2563 DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r
->flags
);
2567 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
2568 DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
2569 r
->width
, config
->min_width
, config
->max_width
);
2572 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
2573 DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
2574 r
->height
, config
->min_height
, config
->max_height
);
2578 ret
= framebuffer_check(r
);
2582 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
2584 DRM_DEBUG_KMS("could not create framebuffer\n");
2588 mutex_lock(&file_priv
->fbs_lock
);
2589 r
->fb_id
= fb
->base
.id
;
2590 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2591 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2592 mutex_unlock(&file_priv
->fbs_lock
);
2599 * drm_mode_rmfb - remove an FB from the configuration
2600 * @dev: drm device for the ioctl
2601 * @data: data pointer for the ioctl
2602 * @file_priv: drm file for the ioctl call
2604 * Remove the FB specified by the user.
2606 * Called by the user via ioctl.
2609 * Zero on success, errno on failure.
2611 int drm_mode_rmfb(struct drm_device
*dev
,
2612 void *data
, struct drm_file
*file_priv
)
2614 struct drm_framebuffer
*fb
= NULL
;
2615 struct drm_framebuffer
*fbl
= NULL
;
2616 uint32_t *id
= data
;
2619 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2622 mutex_lock(&file_priv
->fbs_lock
);
2623 mutex_lock(&dev
->mode_config
.fb_lock
);
2624 fb
= __drm_framebuffer_lookup(dev
, *id
);
2628 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
2634 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2635 __drm_framebuffer_unregister(dev
, fb
);
2637 list_del_init(&fb
->filp_head
);
2638 mutex_unlock(&dev
->mode_config
.fb_lock
);
2639 mutex_unlock(&file_priv
->fbs_lock
);
2641 drm_framebuffer_remove(fb
);
2646 mutex_unlock(&dev
->mode_config
.fb_lock
);
2647 mutex_unlock(&file_priv
->fbs_lock
);
2653 * drm_mode_getfb - get FB info
2654 * @dev: drm device for the ioctl
2655 * @data: data pointer for the ioctl
2656 * @file_priv: drm file for the ioctl call
2658 * Lookup the FB given its ID and return info about it.
2660 * Called by the user via ioctl.
2663 * Zero on success, errno on failure.
2665 int drm_mode_getfb(struct drm_device
*dev
,
2666 void *data
, struct drm_file
*file_priv
)
2668 struct drm_mode_fb_cmd
*r
= data
;
2669 struct drm_framebuffer
*fb
;
2672 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2675 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2679 r
->height
= fb
->height
;
2680 r
->width
= fb
->width
;
2681 r
->depth
= fb
->depth
;
2682 r
->bpp
= fb
->bits_per_pixel
;
2683 r
->pitch
= fb
->pitches
[0];
2684 if (fb
->funcs
->create_handle
) {
2685 if (file_priv
->is_master
|| capable(CAP_SYS_ADMIN
)) {
2686 ret
= fb
->funcs
->create_handle(fb
, file_priv
,
2689 /* GET_FB() is an unprivileged ioctl so we must not
2690 * return a buffer-handle to non-master processes! For
2691 * backwards-compatibility reasons, we cannot make
2692 * GET_FB() privileged, so just return an invalid handle
2693 * for non-masters. */
2701 drm_framebuffer_unreference(fb
);
2706 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2707 void *data
, struct drm_file
*file_priv
)
2709 struct drm_clip_rect __user
*clips_ptr
;
2710 struct drm_clip_rect
*clips
= NULL
;
2711 struct drm_mode_fb_dirty_cmd
*r
= data
;
2712 struct drm_framebuffer
*fb
;
2717 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2720 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2724 num_clips
= r
->num_clips
;
2725 clips_ptr
= (struct drm_clip_rect __user
*)(unsigned long)r
->clips_ptr
;
2727 if (!num_clips
!= !clips_ptr
) {
2732 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
2734 /* If userspace annotates copy, clips must come in pairs */
2735 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
2740 if (num_clips
&& clips_ptr
) {
2741 if (num_clips
< 0 || num_clips
> DRM_MODE_FB_DIRTY_MAX_CLIPS
) {
2745 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
2751 ret
= copy_from_user(clips
, clips_ptr
,
2752 num_clips
* sizeof(*clips
));
2759 if (fb
->funcs
->dirty
) {
2760 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
2769 drm_framebuffer_unreference(fb
);
2776 * drm_fb_release - remove and free the FBs on this file
2777 * @priv: drm file for the ioctl
2779 * Destroy all the FBs associated with @filp.
2781 * Called by the user via ioctl.
2784 * Zero on success, errno on failure.
2786 void drm_fb_release(struct drm_file
*priv
)
2788 struct drm_device
*dev
= priv
->minor
->dev
;
2789 struct drm_framebuffer
*fb
, *tfb
;
2791 mutex_lock(&priv
->fbs_lock
);
2792 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
2794 mutex_lock(&dev
->mode_config
.fb_lock
);
2795 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2796 __drm_framebuffer_unregister(dev
, fb
);
2797 mutex_unlock(&dev
->mode_config
.fb_lock
);
2799 list_del_init(&fb
->filp_head
);
2801 /* This will also drop the fpriv->fbs reference. */
2802 drm_framebuffer_remove(fb
);
2804 mutex_unlock(&priv
->fbs_lock
);
2807 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2808 const char *name
, int num_values
)
2810 struct drm_property
*property
= NULL
;
2813 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2818 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2819 if (!property
->values
)
2823 ret
= drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2827 property
->flags
= flags
;
2828 property
->num_values
= num_values
;
2829 INIT_LIST_HEAD(&property
->enum_blob_list
);
2832 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2833 property
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2836 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2839 kfree(property
->values
);
2843 EXPORT_SYMBOL(drm_property_create
);
2845 struct drm_property
*drm_property_create_enum(struct drm_device
*dev
, int flags
,
2847 const struct drm_prop_enum_list
*props
,
2850 struct drm_property
*property
;
2853 flags
|= DRM_MODE_PROP_ENUM
;
2855 property
= drm_property_create(dev
, flags
, name
, num_values
);
2859 for (i
= 0; i
< num_values
; i
++) {
2860 ret
= drm_property_add_enum(property
, i
,
2864 drm_property_destroy(dev
, property
);
2871 EXPORT_SYMBOL(drm_property_create_enum
);
2873 struct drm_property
*drm_property_create_bitmask(struct drm_device
*dev
,
2874 int flags
, const char *name
,
2875 const struct drm_prop_enum_list
*props
,
2878 struct drm_property
*property
;
2881 flags
|= DRM_MODE_PROP_BITMASK
;
2883 property
= drm_property_create(dev
, flags
, name
, num_values
);
2887 for (i
= 0; i
< num_values
; i
++) {
2888 ret
= drm_property_add_enum(property
, i
,
2892 drm_property_destroy(dev
, property
);
2899 EXPORT_SYMBOL(drm_property_create_bitmask
);
2901 struct drm_property
*drm_property_create_range(struct drm_device
*dev
, int flags
,
2903 uint64_t min
, uint64_t max
)
2905 struct drm_property
*property
;
2907 flags
|= DRM_MODE_PROP_RANGE
;
2909 property
= drm_property_create(dev
, flags
, name
, 2);
2913 property
->values
[0] = min
;
2914 property
->values
[1] = max
;
2918 EXPORT_SYMBOL(drm_property_create_range
);
2920 int drm_property_add_enum(struct drm_property
*property
, int index
,
2921 uint64_t value
, const char *name
)
2923 struct drm_property_enum
*prop_enum
;
2925 if (!(property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)))
2929 * Bitmask enum properties have the additional constraint of values
2932 if ((property
->flags
& DRM_MODE_PROP_BITMASK
) && (value
> 63))
2935 if (!list_empty(&property
->enum_blob_list
)) {
2936 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2937 if (prop_enum
->value
== value
) {
2938 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2939 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2945 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2949 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2950 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2951 prop_enum
->value
= value
;
2953 property
->values
[index
] = value
;
2954 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2957 EXPORT_SYMBOL(drm_property_add_enum
);
2959 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2961 struct drm_property_enum
*prop_enum
, *pt
;
2963 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2964 list_del(&prop_enum
->head
);
2968 if (property
->num_values
)
2969 kfree(property
->values
);
2970 drm_mode_object_put(dev
, &property
->base
);
2971 list_del(&property
->head
);
2974 EXPORT_SYMBOL(drm_property_destroy
);
2976 void drm_object_attach_property(struct drm_mode_object
*obj
,
2977 struct drm_property
*property
,
2980 int count
= obj
->properties
->count
;
2982 if (count
== DRM_OBJECT_MAX_PROPERTY
) {
2983 WARN(1, "Failed to attach object property (type: 0x%x). Please "
2984 "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time "
2985 "you see this message on the same object type.\n",
2990 obj
->properties
->ids
[count
] = property
->base
.id
;
2991 obj
->properties
->values
[count
] = init_val
;
2992 obj
->properties
->count
++;
2994 EXPORT_SYMBOL(drm_object_attach_property
);
2996 int drm_object_property_set_value(struct drm_mode_object
*obj
,
2997 struct drm_property
*property
, uint64_t val
)
3001 for (i
= 0; i
< obj
->properties
->count
; i
++) {
3002 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
3003 obj
->properties
->values
[i
] = val
;
3010 EXPORT_SYMBOL(drm_object_property_set_value
);
3012 int drm_object_property_get_value(struct drm_mode_object
*obj
,
3013 struct drm_property
*property
, uint64_t *val
)
3017 for (i
= 0; i
< obj
->properties
->count
; i
++) {
3018 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
3019 *val
= obj
->properties
->values
[i
];
3026 EXPORT_SYMBOL(drm_object_property_get_value
);
3028 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
3029 void *data
, struct drm_file
*file_priv
)
3031 struct drm_mode_object
*obj
;
3032 struct drm_mode_get_property
*out_resp
= data
;
3033 struct drm_property
*property
;
3036 int value_count
= 0;
3039 struct drm_property_enum
*prop_enum
;
3040 struct drm_mode_property_enum __user
*enum_ptr
;
3041 struct drm_property_blob
*prop_blob
;
3042 uint32_t __user
*blob_id_ptr
;
3043 uint64_t __user
*values_ptr
;
3044 uint32_t __user
*blob_length_ptr
;
3046 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3049 drm_modeset_lock_all(dev
);
3050 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
3055 property
= obj_to_property(obj
);
3057 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
3058 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
3060 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3061 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
3065 value_count
= property
->num_values
;
3067 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
3068 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
3069 out_resp
->flags
= property
->flags
;
3071 if ((out_resp
->count_values
>= value_count
) && value_count
) {
3072 values_ptr
= (uint64_t __user
*)(unsigned long)out_resp
->values_ptr
;
3073 for (i
= 0; i
< value_count
; i
++) {
3074 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
3080 out_resp
->count_values
= value_count
;
3082 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
3083 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
3085 enum_ptr
= (struct drm_mode_property_enum __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3086 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
3088 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
3093 if (copy_to_user(&enum_ptr
[copied
].name
,
3094 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
3101 out_resp
->count_enum_blobs
= enum_count
;
3104 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3105 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
3107 blob_id_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3108 blob_length_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->values_ptr
;
3110 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
3111 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
3116 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
3124 out_resp
->count_enum_blobs
= blob_count
;
3127 drm_modeset_unlock_all(dev
);
3131 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
3134 struct drm_property_blob
*blob
;
3137 if (!length
|| !data
)
3140 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
3144 ret
= drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
3150 blob
->length
= length
;
3152 memcpy(blob
->data
, data
, length
);
3154 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
3158 static void drm_property_destroy_blob(struct drm_device
*dev
,
3159 struct drm_property_blob
*blob
)
3161 drm_mode_object_put(dev
, &blob
->base
);
3162 list_del(&blob
->head
);
3166 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
3167 void *data
, struct drm_file
*file_priv
)
3169 struct drm_mode_object
*obj
;
3170 struct drm_mode_get_blob
*out_resp
= data
;
3171 struct drm_property_blob
*blob
;
3173 void __user
*blob_ptr
;
3175 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3178 drm_modeset_lock_all(dev
);
3179 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
3184 blob
= obj_to_blob(obj
);
3186 if (out_resp
->length
== blob
->length
) {
3187 blob_ptr
= (void __user
*)(unsigned long)out_resp
->data
;
3188 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
3193 out_resp
->length
= blob
->length
;
3196 drm_modeset_unlock_all(dev
);
3200 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
3203 struct drm_device
*dev
= connector
->dev
;
3206 if (connector
->edid_blob_ptr
)
3207 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
3209 /* Delete edid, when there is none. */
3211 connector
->edid_blob_ptr
= NULL
;
3212 ret
= drm_object_property_set_value(&connector
->base
, dev
->mode_config
.edid_property
, 0);
3216 size
= EDID_LENGTH
* (1 + edid
->extensions
);
3217 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
3219 if (!connector
->edid_blob_ptr
)
3222 ret
= drm_object_property_set_value(&connector
->base
,
3223 dev
->mode_config
.edid_property
,
3224 connector
->edid_blob_ptr
->base
.id
);
3228 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
3230 static bool drm_property_change_is_valid(struct drm_property
*property
,
3233 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
3235 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
3236 if (value
< property
->values
[0] || value
> property
->values
[1])
3239 } else if (property
->flags
& DRM_MODE_PROP_BITMASK
) {
3241 uint64_t valid_mask
= 0;
3242 for (i
= 0; i
< property
->num_values
; i
++)
3243 valid_mask
|= (1ULL << property
->values
[i
]);
3244 return !(value
& ~valid_mask
);
3245 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3246 /* Only the driver knows */
3250 for (i
= 0; i
< property
->num_values
; i
++)
3251 if (property
->values
[i
] == value
)
3257 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
3258 void *data
, struct drm_file
*file_priv
)
3260 struct drm_mode_connector_set_property
*conn_set_prop
= data
;
3261 struct drm_mode_obj_set_property obj_set_prop
= {
3262 .value
= conn_set_prop
->value
,
3263 .prop_id
= conn_set_prop
->prop_id
,
3264 .obj_id
= conn_set_prop
->connector_id
,
3265 .obj_type
= DRM_MODE_OBJECT_CONNECTOR
3268 /* It does all the locking and checking we need */
3269 return drm_mode_obj_set_property_ioctl(dev
, &obj_set_prop
, file_priv
);
3272 static int drm_mode_connector_set_obj_prop(struct drm_mode_object
*obj
,
3273 struct drm_property
*property
,
3277 struct drm_connector
*connector
= obj_to_connector(obj
);
3279 /* Do DPMS ourselves */
3280 if (property
== connector
->dev
->mode_config
.dpms_property
) {
3281 if (connector
->funcs
->dpms
)
3282 (*connector
->funcs
->dpms
)(connector
, (int)value
);
3284 } else if (connector
->funcs
->set_property
)
3285 ret
= connector
->funcs
->set_property(connector
, property
, value
);
3287 /* store the property value if successful */
3289 drm_object_property_set_value(&connector
->base
, property
, value
);
3293 static int drm_mode_crtc_set_obj_prop(struct drm_mode_object
*obj
,
3294 struct drm_property
*property
,
3298 struct drm_crtc
*crtc
= obj_to_crtc(obj
);
3300 if (crtc
->funcs
->set_property
)
3301 ret
= crtc
->funcs
->set_property(crtc
, property
, value
);
3303 drm_object_property_set_value(obj
, property
, value
);
3308 static int drm_mode_plane_set_obj_prop(struct drm_mode_object
*obj
,
3309 struct drm_property
*property
,
3313 struct drm_plane
*plane
= obj_to_plane(obj
);
3315 if (plane
->funcs
->set_property
)
3316 ret
= plane
->funcs
->set_property(plane
, property
, value
);
3318 drm_object_property_set_value(obj
, property
, value
);
3323 int drm_mode_obj_get_properties_ioctl(struct drm_device
*dev
, void *data
,
3324 struct drm_file
*file_priv
)
3326 struct drm_mode_obj_get_properties
*arg
= data
;
3327 struct drm_mode_object
*obj
;
3331 int props_count
= 0;
3332 uint32_t __user
*props_ptr
;
3333 uint64_t __user
*prop_values_ptr
;
3335 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3338 drm_modeset_lock_all(dev
);
3340 obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3345 if (!obj
->properties
) {
3350 props_count
= obj
->properties
->count
;
3352 /* This ioctl is called twice, once to determine how much space is
3353 * needed, and the 2nd time to fill it. */
3354 if ((arg
->count_props
>= props_count
) && props_count
) {
3356 props_ptr
= (uint32_t __user
*)(unsigned long)(arg
->props_ptr
);
3357 prop_values_ptr
= (uint64_t __user
*)(unsigned long)
3358 (arg
->prop_values_ptr
);
3359 for (i
= 0; i
< props_count
; i
++) {
3360 if (put_user(obj
->properties
->ids
[i
],
3361 props_ptr
+ copied
)) {
3365 if (put_user(obj
->properties
->values
[i
],
3366 prop_values_ptr
+ copied
)) {
3373 arg
->count_props
= props_count
;
3375 drm_modeset_unlock_all(dev
);
3379 int drm_mode_obj_set_property_ioctl(struct drm_device
*dev
, void *data
,
3380 struct drm_file
*file_priv
)
3382 struct drm_mode_obj_set_property
*arg
= data
;
3383 struct drm_mode_object
*arg_obj
;
3384 struct drm_mode_object
*prop_obj
;
3385 struct drm_property
*property
;
3389 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3392 drm_modeset_lock_all(dev
);
3394 arg_obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3399 if (!arg_obj
->properties
)
3402 for (i
= 0; i
< arg_obj
->properties
->count
; i
++)
3403 if (arg_obj
->properties
->ids
[i
] == arg
->prop_id
)
3406 if (i
== arg_obj
->properties
->count
)
3409 prop_obj
= drm_mode_object_find(dev
, arg
->prop_id
,
3410 DRM_MODE_OBJECT_PROPERTY
);
3415 property
= obj_to_property(prop_obj
);
3417 if (!drm_property_change_is_valid(property
, arg
->value
))
3420 switch (arg_obj
->type
) {
3421 case DRM_MODE_OBJECT_CONNECTOR
:
3422 ret
= drm_mode_connector_set_obj_prop(arg_obj
, property
,
3425 case DRM_MODE_OBJECT_CRTC
:
3426 ret
= drm_mode_crtc_set_obj_prop(arg_obj
, property
, arg
->value
);
3428 case DRM_MODE_OBJECT_PLANE
:
3429 ret
= drm_mode_plane_set_obj_prop(arg_obj
, property
, arg
->value
);
3434 drm_modeset_unlock_all(dev
);
3438 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
3439 struct drm_encoder
*encoder
)
3443 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3444 if (connector
->encoder_ids
[i
] == 0) {
3445 connector
->encoder_ids
[i
] = encoder
->base
.id
;
3451 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
3453 int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
3456 crtc
->gamma_size
= gamma_size
;
3458 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
3459 if (!crtc
->gamma_store
) {
3460 crtc
->gamma_size
= 0;
3466 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
3468 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
3469 void *data
, struct drm_file
*file_priv
)
3471 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3472 struct drm_mode_object
*obj
;
3473 struct drm_crtc
*crtc
;
3474 void *r_base
, *g_base
, *b_base
;
3478 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3481 drm_modeset_lock_all(dev
);
3482 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3487 crtc
= obj_to_crtc(obj
);
3489 if (crtc
->funcs
->gamma_set
== NULL
) {
3494 /* memcpy into gamma store */
3495 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3500 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3501 r_base
= crtc
->gamma_store
;
3502 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
3507 g_base
= r_base
+ size
;
3508 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
3513 b_base
= g_base
+ size
;
3514 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
3519 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
3522 drm_modeset_unlock_all(dev
);
3527 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
3528 void *data
, struct drm_file
*file_priv
)
3530 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3531 struct drm_mode_object
*obj
;
3532 struct drm_crtc
*crtc
;
3533 void *r_base
, *g_base
, *b_base
;
3537 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3540 drm_modeset_lock_all(dev
);
3541 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3546 crtc
= obj_to_crtc(obj
);
3548 /* memcpy into gamma store */
3549 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3554 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3555 r_base
= crtc
->gamma_store
;
3556 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
3561 g_base
= r_base
+ size
;
3562 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
3567 b_base
= g_base
+ size
;
3568 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
3573 drm_modeset_unlock_all(dev
);
3577 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
3578 void *data
, struct drm_file
*file_priv
)
3580 struct drm_mode_crtc_page_flip
*page_flip
= data
;
3581 struct drm_mode_object
*obj
;
3582 struct drm_crtc
*crtc
;
3583 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
3584 struct drm_pending_vblank_event
*e
= NULL
;
3585 unsigned long flags
;
3588 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
3589 page_flip
->reserved
!= 0)
3592 if ((page_flip
->flags
& DRM_MODE_PAGE_FLIP_ASYNC
) && !dev
->mode_config
.async_page_flip
)
3595 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3598 crtc
= obj_to_crtc(obj
);
3600 mutex_lock(&crtc
->mutex
);
3601 if (crtc
->fb
== NULL
) {
3602 /* The framebuffer is currently unbound, presumably
3603 * due to a hotplug event, that userspace has not
3610 if (crtc
->funcs
->page_flip
== NULL
)
3613 fb
= drm_framebuffer_lookup(dev
, page_flip
->fb_id
);
3619 ret
= drm_crtc_check_viewport(crtc
, crtc
->x
, crtc
->y
, &crtc
->mode
, fb
);
3623 if (crtc
->fb
->pixel_format
!= fb
->pixel_format
) {
3624 DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n");
3629 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3631 spin_lock_irqsave(&dev
->event_lock
, flags
);
3632 if (file_priv
->event_space
< sizeof e
->event
) {
3633 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3636 file_priv
->event_space
-= sizeof e
->event
;
3637 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3639 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
3641 spin_lock_irqsave(&dev
->event_lock
, flags
);
3642 file_priv
->event_space
+= sizeof e
->event
;
3643 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3647 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
3648 e
->event
.base
.length
= sizeof e
->event
;
3649 e
->event
.user_data
= page_flip
->user_data
;
3650 e
->base
.event
= &e
->event
.base
;
3651 e
->base
.file_priv
= file_priv
;
3653 (void (*) (struct drm_pending_event
*)) kfree
;
3657 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
, page_flip
->flags
);
3659 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3660 spin_lock_irqsave(&dev
->event_lock
, flags
);
3661 file_priv
->event_space
+= sizeof e
->event
;
3662 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3665 /* Keep the old fb, don't unref it. */
3669 * Warn if the driver hasn't properly updated the crtc->fb
3670 * field to reflect that the new framebuffer is now used.
3671 * Failing to do so will screw with the reference counting
3674 WARN_ON(crtc
->fb
!= fb
);
3675 /* Unref only the old framebuffer. */
3681 drm_framebuffer_unreference(fb
);
3683 drm_framebuffer_unreference(old_fb
);
3684 mutex_unlock(&crtc
->mutex
);
3689 void drm_mode_config_reset(struct drm_device
*dev
)
3691 struct drm_crtc
*crtc
;
3692 struct drm_encoder
*encoder
;
3693 struct drm_connector
*connector
;
3695 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
3696 if (crtc
->funcs
->reset
)
3697 crtc
->funcs
->reset(crtc
);
3699 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
3700 if (encoder
->funcs
->reset
)
3701 encoder
->funcs
->reset(encoder
);
3703 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
3704 connector
->status
= connector_status_unknown
;
3706 if (connector
->funcs
->reset
)
3707 connector
->funcs
->reset(connector
);
3710 EXPORT_SYMBOL(drm_mode_config_reset
);
3712 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
3713 void *data
, struct drm_file
*file_priv
)
3715 struct drm_mode_create_dumb
*args
= data
;
3717 if (!dev
->driver
->dumb_create
)
3719 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
3722 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
3723 void *data
, struct drm_file
*file_priv
)
3725 struct drm_mode_map_dumb
*args
= data
;
3727 /* call driver ioctl to get mmap offset */
3728 if (!dev
->driver
->dumb_map_offset
)
3731 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
3734 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
3735 void *data
, struct drm_file
*file_priv
)
3737 struct drm_mode_destroy_dumb
*args
= data
;
3739 if (!dev
->driver
->dumb_destroy
)
3742 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
3746 * Just need to support RGB formats here for compat with code that doesn't
3747 * use pixel formats directly yet.
3749 void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
3754 case DRM_FORMAT_RGB332
:
3755 case DRM_FORMAT_BGR233
:
3759 case DRM_FORMAT_XRGB1555
:
3760 case DRM_FORMAT_XBGR1555
:
3761 case DRM_FORMAT_RGBX5551
:
3762 case DRM_FORMAT_BGRX5551
:
3763 case DRM_FORMAT_ARGB1555
:
3764 case DRM_FORMAT_ABGR1555
:
3765 case DRM_FORMAT_RGBA5551
:
3766 case DRM_FORMAT_BGRA5551
:
3770 case DRM_FORMAT_RGB565
:
3771 case DRM_FORMAT_BGR565
:
3775 case DRM_FORMAT_RGB888
:
3776 case DRM_FORMAT_BGR888
:
3780 case DRM_FORMAT_XRGB8888
:
3781 case DRM_FORMAT_XBGR8888
:
3782 case DRM_FORMAT_RGBX8888
:
3783 case DRM_FORMAT_BGRX8888
:
3787 case DRM_FORMAT_XRGB2101010
:
3788 case DRM_FORMAT_XBGR2101010
:
3789 case DRM_FORMAT_RGBX1010102
:
3790 case DRM_FORMAT_BGRX1010102
:
3791 case DRM_FORMAT_ARGB2101010
:
3792 case DRM_FORMAT_ABGR2101010
:
3793 case DRM_FORMAT_RGBA1010102
:
3794 case DRM_FORMAT_BGRA1010102
:
3798 case DRM_FORMAT_ARGB8888
:
3799 case DRM_FORMAT_ABGR8888
:
3800 case DRM_FORMAT_RGBA8888
:
3801 case DRM_FORMAT_BGRA8888
:
3806 DRM_DEBUG_KMS("unsupported pixel format %s\n",
3807 drm_get_format_name(format
));
3813 EXPORT_SYMBOL(drm_fb_get_bpp_depth
);
3816 * drm_format_num_planes - get the number of planes for format
3817 * @format: pixel format (DRM_FORMAT_*)
3820 * The number of planes used by the specified pixel format.
3822 int drm_format_num_planes(uint32_t format
)
3825 case DRM_FORMAT_YUV410
:
3826 case DRM_FORMAT_YVU410
:
3827 case DRM_FORMAT_YUV411
:
3828 case DRM_FORMAT_YVU411
:
3829 case DRM_FORMAT_YUV420
:
3830 case DRM_FORMAT_YVU420
:
3831 case DRM_FORMAT_YUV422
:
3832 case DRM_FORMAT_YVU422
:
3833 case DRM_FORMAT_YUV444
:
3834 case DRM_FORMAT_YVU444
:
3836 case DRM_FORMAT_NV12
:
3837 case DRM_FORMAT_NV21
:
3838 case DRM_FORMAT_NV16
:
3839 case DRM_FORMAT_NV61
:
3840 case DRM_FORMAT_NV24
:
3841 case DRM_FORMAT_NV42
:
3847 EXPORT_SYMBOL(drm_format_num_planes
);
3850 * drm_format_plane_cpp - determine the bytes per pixel value
3851 * @format: pixel format (DRM_FORMAT_*)
3852 * @plane: plane index
3855 * The bytes per pixel value for the specified plane.
3857 int drm_format_plane_cpp(uint32_t format
, int plane
)
3862 if (plane
>= drm_format_num_planes(format
))
3866 case DRM_FORMAT_YUYV
:
3867 case DRM_FORMAT_YVYU
:
3868 case DRM_FORMAT_UYVY
:
3869 case DRM_FORMAT_VYUY
:
3871 case DRM_FORMAT_NV12
:
3872 case DRM_FORMAT_NV21
:
3873 case DRM_FORMAT_NV16
:
3874 case DRM_FORMAT_NV61
:
3875 case DRM_FORMAT_NV24
:
3876 case DRM_FORMAT_NV42
:
3877 return plane
? 2 : 1;
3878 case DRM_FORMAT_YUV410
:
3879 case DRM_FORMAT_YVU410
:
3880 case DRM_FORMAT_YUV411
:
3881 case DRM_FORMAT_YVU411
:
3882 case DRM_FORMAT_YUV420
:
3883 case DRM_FORMAT_YVU420
:
3884 case DRM_FORMAT_YUV422
:
3885 case DRM_FORMAT_YVU422
:
3886 case DRM_FORMAT_YUV444
:
3887 case DRM_FORMAT_YVU444
:
3890 drm_fb_get_bpp_depth(format
, &depth
, &bpp
);
3894 EXPORT_SYMBOL(drm_format_plane_cpp
);
3897 * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
3898 * @format: pixel format (DRM_FORMAT_*)
3901 * The horizontal chroma subsampling factor for the
3902 * specified pixel format.
3904 int drm_format_horz_chroma_subsampling(uint32_t format
)
3907 case DRM_FORMAT_YUV411
:
3908 case DRM_FORMAT_YVU411
:
3909 case DRM_FORMAT_YUV410
:
3910 case DRM_FORMAT_YVU410
:
3912 case DRM_FORMAT_YUYV
:
3913 case DRM_FORMAT_YVYU
:
3914 case DRM_FORMAT_UYVY
:
3915 case DRM_FORMAT_VYUY
:
3916 case DRM_FORMAT_NV12
:
3917 case DRM_FORMAT_NV21
:
3918 case DRM_FORMAT_NV16
:
3919 case DRM_FORMAT_NV61
:
3920 case DRM_FORMAT_YUV422
:
3921 case DRM_FORMAT_YVU422
:
3922 case DRM_FORMAT_YUV420
:
3923 case DRM_FORMAT_YVU420
:
3929 EXPORT_SYMBOL(drm_format_horz_chroma_subsampling
);
3932 * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
3933 * @format: pixel format (DRM_FORMAT_*)
3936 * The vertical chroma subsampling factor for the
3937 * specified pixel format.
3939 int drm_format_vert_chroma_subsampling(uint32_t format
)
3942 case DRM_FORMAT_YUV410
:
3943 case DRM_FORMAT_YVU410
:
3945 case DRM_FORMAT_YUV420
:
3946 case DRM_FORMAT_YVU420
:
3947 case DRM_FORMAT_NV12
:
3948 case DRM_FORMAT_NV21
:
3954 EXPORT_SYMBOL(drm_format_vert_chroma_subsampling
);
3957 * drm_mode_config_init - initialize DRM mode_configuration structure
3960 * Initialize @dev's mode_config structure, used for tracking the graphics
3961 * configuration of @dev.
3963 * Since this initializes the modeset locks, no locking is possible. Which is no
3964 * problem, since this should happen single threaded at init time. It is the
3965 * driver's problem to ensure this guarantee.
3968 void drm_mode_config_init(struct drm_device
*dev
)
3970 mutex_init(&dev
->mode_config
.mutex
);
3971 mutex_init(&dev
->mode_config
.idr_mutex
);
3972 mutex_init(&dev
->mode_config
.fb_lock
);
3973 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
3974 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
3975 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
3976 INIT_LIST_HEAD(&dev
->mode_config
.bridge_list
);
3977 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
3978 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
3979 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
3980 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
3981 idr_init(&dev
->mode_config
.crtc_idr
);
3983 drm_modeset_lock_all(dev
);
3984 drm_mode_create_standard_connector_properties(dev
);
3985 drm_modeset_unlock_all(dev
);
3987 /* Just to be sure */
3988 dev
->mode_config
.num_fb
= 0;
3989 dev
->mode_config
.num_connector
= 0;
3990 dev
->mode_config
.num_crtc
= 0;
3991 dev
->mode_config
.num_encoder
= 0;
3993 EXPORT_SYMBOL(drm_mode_config_init
);
3996 * drm_mode_config_cleanup - free up DRM mode_config info
3999 * Free up all the connectors and CRTCs associated with this DRM device, then
4000 * free up the framebuffers and associated buffer objects.
4002 * Note that since this /should/ happen single-threaded at driver/device
4003 * teardown time, no locking is required. It's the driver's job to ensure that
4004 * this guarantee actually holds true.
4006 * FIXME: cleanup any dangling user buffer objects too
4008 void drm_mode_config_cleanup(struct drm_device
*dev
)
4010 struct drm_connector
*connector
, *ot
;
4011 struct drm_crtc
*crtc
, *ct
;
4012 struct drm_encoder
*encoder
, *enct
;
4013 struct drm_bridge
*bridge
, *brt
;
4014 struct drm_framebuffer
*fb
, *fbt
;
4015 struct drm_property
*property
, *pt
;
4016 struct drm_property_blob
*blob
, *bt
;
4017 struct drm_plane
*plane
, *plt
;
4019 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
4021 encoder
->funcs
->destroy(encoder
);
4024 list_for_each_entry_safe(bridge
, brt
,
4025 &dev
->mode_config
.bridge_list
, head
) {
4026 bridge
->funcs
->destroy(bridge
);
4029 list_for_each_entry_safe(connector
, ot
,
4030 &dev
->mode_config
.connector_list
, head
) {
4031 connector
->funcs
->destroy(connector
);
4034 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
4036 drm_property_destroy(dev
, property
);
4039 list_for_each_entry_safe(blob
, bt
, &dev
->mode_config
.property_blob_list
,
4041 drm_property_destroy_blob(dev
, blob
);
4045 * Single-threaded teardown context, so it's not required to grab the
4046 * fb_lock to protect against concurrent fb_list access. Contrary, it
4047 * would actually deadlock with the drm_framebuffer_cleanup function.
4049 * Also, if there are any framebuffers left, that's a driver leak now,
4050 * so politely WARN about this.
4052 WARN_ON(!list_empty(&dev
->mode_config
.fb_list
));
4053 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
4054 drm_framebuffer_remove(fb
);
4057 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
4059 plane
->funcs
->destroy(plane
);
4062 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
4063 crtc
->funcs
->destroy(crtc
);
4066 idr_destroy(&dev
->mode_config
.crtc_idr
);
4068 EXPORT_SYMBOL(drm_mode_config_cleanup
);