2 * Copyright (c) 2006-2008 Intel Corporation
3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
4 * Copyright (c) 2008 Red Hat Inc.
6 * DRM core CRTC related functions
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that copyright
11 * notice and this permission notice appear in supporting documentation, and
12 * that the name of the copyright holders not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission. The copyright holders make no representations
15 * about the suitability of this software for any purpose. It is provided "as
16 * is" without express or implied warranty.
18 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
28 * Eric Anholt <eric@anholt.net>
29 * Dave Airlie <airlied@linux.ie>
30 * Jesse Barnes <jesse.barnes@intel.com>
32 #include <linux/list.h>
33 #include <linux/slab.h>
34 #include <linux/export.h>
36 #include <drm/drm_crtc.h>
37 #include <drm/drm_edid.h>
38 #include <drm/drm_fourcc.h>
41 * drm_modeset_lock_all - take all modeset locks
44 * This function takes all modeset locks, suitable where a more fine-grained
45 * scheme isn't (yet) implemented.
47 void drm_modeset_lock_all(struct drm_device
*dev
)
49 struct drm_crtc
*crtc
;
51 mutex_lock(&dev
->mode_config
.mutex
);
53 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
54 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
56 EXPORT_SYMBOL(drm_modeset_lock_all
);
59 * drm_modeset_unlock_all - drop all modeset locks
62 void drm_modeset_unlock_all(struct drm_device
*dev
)
64 struct drm_crtc
*crtc
;
66 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
67 mutex_unlock(&crtc
->mutex
);
69 mutex_unlock(&dev
->mode_config
.mutex
);
71 EXPORT_SYMBOL(drm_modeset_unlock_all
);
74 * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked
77 void drm_warn_on_modeset_not_all_locked(struct drm_device
*dev
)
79 struct drm_crtc
*crtc
;
81 /* Locking is currently fubar in the panic handler. */
85 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
86 WARN_ON(!mutex_is_locked(&crtc
->mutex
));
88 WARN_ON(!mutex_is_locked(&dev
->mode_config
.mutex
));
90 EXPORT_SYMBOL(drm_warn_on_modeset_not_all_locked
);
92 /* Avoid boilerplate. I'm tired of typing. */
93 #define DRM_ENUM_NAME_FN(fnname, list) \
94 char *fnname(int val) \
97 for (i = 0; i < ARRAY_SIZE(list); i++) { \
98 if (list[i].type == val) \
99 return list[i].name; \
101 return "(unknown)"; \
107 static struct drm_prop_enum_list drm_dpms_enum_list
[] =
108 { { DRM_MODE_DPMS_ON
, "On" },
109 { DRM_MODE_DPMS_STANDBY
, "Standby" },
110 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
111 { DRM_MODE_DPMS_OFF
, "Off" }
114 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
117 * Optional properties
119 static struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
121 { DRM_MODE_SCALE_NONE
, "None" },
122 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
123 { DRM_MODE_SCALE_CENTER
, "Center" },
124 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
127 static struct drm_prop_enum_list drm_dithering_mode_enum_list
[] =
129 { DRM_MODE_DITHERING_OFF
, "Off" },
130 { DRM_MODE_DITHERING_ON
, "On" },
131 { DRM_MODE_DITHERING_AUTO
, "Automatic" },
135 * Non-global properties, but "required" for certain connectors.
137 static struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
139 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
140 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
141 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
144 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
146 static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
148 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
149 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
150 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
153 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
154 drm_dvi_i_subconnector_enum_list
)
156 static struct drm_prop_enum_list drm_tv_select_enum_list
[] =
158 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
159 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
160 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
161 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
162 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
165 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
167 static struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
169 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
170 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
171 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
172 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
173 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
176 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
177 drm_tv_subconnector_enum_list
)
179 static struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
180 { DRM_MODE_DIRTY_OFF
, "Off" },
181 { DRM_MODE_DIRTY_ON
, "On" },
182 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
185 DRM_ENUM_NAME_FN(drm_get_dirty_info_name
,
186 drm_dirty_info_enum_list
)
188 struct drm_conn_prop_enum_list
{
195 * Connector and encoder types.
197 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
198 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
199 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
200 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
201 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
202 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
203 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
204 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
205 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
206 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
207 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN", 0 },
208 { DRM_MODE_CONNECTOR_DisplayPort
, "DP", 0 },
209 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A", 0 },
210 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B", 0 },
211 { DRM_MODE_CONNECTOR_TV
, "TV", 0 },
212 { DRM_MODE_CONNECTOR_eDP
, "eDP", 0 },
213 { DRM_MODE_CONNECTOR_VIRTUAL
, "Virtual", 0},
216 static struct drm_prop_enum_list drm_encoder_enum_list
[] =
217 { { DRM_MODE_ENCODER_NONE
, "None" },
218 { DRM_MODE_ENCODER_DAC
, "DAC" },
219 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
220 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
221 { DRM_MODE_ENCODER_TVDAC
, "TV" },
222 { DRM_MODE_ENCODER_VIRTUAL
, "Virtual" },
225 char *drm_get_encoder_name(struct drm_encoder
*encoder
)
229 snprintf(buf
, 32, "%s-%d",
230 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
234 EXPORT_SYMBOL(drm_get_encoder_name
);
236 char *drm_get_connector_name(struct drm_connector
*connector
)
240 snprintf(buf
, 32, "%s-%d",
241 drm_connector_enum_list
[connector
->connector_type
].name
,
242 connector
->connector_type_id
);
245 EXPORT_SYMBOL(drm_get_connector_name
);
247 char *drm_get_connector_status_name(enum drm_connector_status status
)
249 if (status
== connector_status_connected
)
251 else if (status
== connector_status_disconnected
)
252 return "disconnected";
258 * drm_mode_object_get - allocate a new modeset identifier
260 * @obj: object pointer, used to generate unique ID
261 * @obj_type: object type
263 * Create a unique identifier based on @ptr in @dev's identifier space. Used
264 * for tracking modes, CRTCs and connectors.
267 * New unique (relative to other objects in @dev) integer identifier for the
270 static int drm_mode_object_get(struct drm_device
*dev
,
271 struct drm_mode_object
*obj
, uint32_t obj_type
)
275 mutex_lock(&dev
->mode_config
.idr_mutex
);
276 ret
= idr_alloc(&dev
->mode_config
.crtc_idr
, obj
, 1, 0, GFP_KERNEL
);
279 * Set up the object linking under the protection of the idr
280 * lock so that other users can't see inconsistent state.
283 obj
->type
= obj_type
;
285 mutex_unlock(&dev
->mode_config
.idr_mutex
);
287 return ret
< 0 ? ret
: 0;
291 * drm_mode_object_put - free a modeset identifer
293 * @object: object to free
295 * Free @id from @dev's unique identifier pool.
297 static void drm_mode_object_put(struct drm_device
*dev
,
298 struct drm_mode_object
*object
)
300 mutex_lock(&dev
->mode_config
.idr_mutex
);
301 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
302 mutex_unlock(&dev
->mode_config
.idr_mutex
);
306 * drm_mode_object_find - look up a drm object with static lifetime
308 * @id: id of the mode object
309 * @type: type of the mode object
311 * Note that framebuffers cannot be looked up with this functions - since those
312 * are reference counted, they need special treatment.
314 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
315 uint32_t id
, uint32_t type
)
317 struct drm_mode_object
*obj
= NULL
;
319 /* Framebuffers are reference counted and need their own lookup
321 WARN_ON(type
== DRM_MODE_OBJECT_FB
);
323 mutex_lock(&dev
->mode_config
.idr_mutex
);
324 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
325 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
327 mutex_unlock(&dev
->mode_config
.idr_mutex
);
331 EXPORT_SYMBOL(drm_mode_object_find
);
334 * drm_framebuffer_init - initialize a framebuffer
336 * @fb: framebuffer to be initialized
337 * @funcs: ... with these functions
339 * Allocates an ID for the framebuffer's parent mode object, sets its mode
340 * functions & device file and adds it to the master fd list.
343 * This functions publishes the fb and makes it available for concurrent access
344 * by other users. Which means by this point the fb _must_ be fully set up -
345 * since all the fb attributes are invariant over its lifetime, no further
346 * locking but only correct reference counting is required.
349 * Zero on success, error code on failure.
351 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
352 const struct drm_framebuffer_funcs
*funcs
)
356 mutex_lock(&dev
->mode_config
.fb_lock
);
357 kref_init(&fb
->refcount
);
358 INIT_LIST_HEAD(&fb
->filp_head
);
362 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
366 /* Grab the idr reference. */
367 drm_framebuffer_reference(fb
);
369 dev
->mode_config
.num_fb
++;
370 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
372 mutex_unlock(&dev
->mode_config
.fb_lock
);
376 EXPORT_SYMBOL(drm_framebuffer_init
);
378 static void drm_framebuffer_free(struct kref
*kref
)
380 struct drm_framebuffer
*fb
=
381 container_of(kref
, struct drm_framebuffer
, refcount
);
382 fb
->funcs
->destroy(fb
);
385 static struct drm_framebuffer
*__drm_framebuffer_lookup(struct drm_device
*dev
,
388 struct drm_mode_object
*obj
= NULL
;
389 struct drm_framebuffer
*fb
;
391 mutex_lock(&dev
->mode_config
.idr_mutex
);
392 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
393 if (!obj
|| (obj
->type
!= DRM_MODE_OBJECT_FB
) || (obj
->id
!= id
))
397 mutex_unlock(&dev
->mode_config
.idr_mutex
);
403 * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
405 * @id: id of the fb object
407 * If successful, this grabs an additional reference to the framebuffer -
408 * callers need to make sure to eventually unreference the returned framebuffer
411 struct drm_framebuffer
*drm_framebuffer_lookup(struct drm_device
*dev
,
414 struct drm_framebuffer
*fb
;
416 mutex_lock(&dev
->mode_config
.fb_lock
);
417 fb
= __drm_framebuffer_lookup(dev
, id
);
419 kref_get(&fb
->refcount
);
420 mutex_unlock(&dev
->mode_config
.fb_lock
);
424 EXPORT_SYMBOL(drm_framebuffer_lookup
);
427 * drm_framebuffer_unreference - unref a framebuffer
428 * @fb: framebuffer to unref
430 * This functions decrements the fb's refcount and frees it if it drops to zero.
432 void drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
434 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
435 kref_put(&fb
->refcount
, drm_framebuffer_free
);
437 EXPORT_SYMBOL(drm_framebuffer_unreference
);
440 * drm_framebuffer_reference - incr the fb refcnt
443 void drm_framebuffer_reference(struct drm_framebuffer
*fb
)
445 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
446 kref_get(&fb
->refcount
);
448 EXPORT_SYMBOL(drm_framebuffer_reference
);
450 static void drm_framebuffer_free_bug(struct kref
*kref
)
455 static void __drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
457 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
458 kref_put(&fb
->refcount
, drm_framebuffer_free_bug
);
461 /* dev->mode_config.fb_lock must be held! */
462 static void __drm_framebuffer_unregister(struct drm_device
*dev
,
463 struct drm_framebuffer
*fb
)
465 mutex_lock(&dev
->mode_config
.idr_mutex
);
466 idr_remove(&dev
->mode_config
.crtc_idr
, fb
->base
.id
);
467 mutex_unlock(&dev
->mode_config
.idr_mutex
);
471 __drm_framebuffer_unreference(fb
);
475 * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
476 * @fb: fb to unregister
478 * Drivers need to call this when cleaning up driver-private framebuffers, e.g.
479 * those used for fbdev. Note that the caller must hold a reference of it's own,
480 * i.e. the object may not be destroyed through this call (since it'll lead to a
481 * locking inversion).
483 void drm_framebuffer_unregister_private(struct drm_framebuffer
*fb
)
485 struct drm_device
*dev
= fb
->dev
;
487 mutex_lock(&dev
->mode_config
.fb_lock
);
488 /* Mark fb as reaped and drop idr ref. */
489 __drm_framebuffer_unregister(dev
, fb
);
490 mutex_unlock(&dev
->mode_config
.fb_lock
);
492 EXPORT_SYMBOL(drm_framebuffer_unregister_private
);
495 * drm_framebuffer_cleanup - remove a framebuffer object
496 * @fb: framebuffer to remove
498 * Cleanup references to a user-created framebuffer. This function is intended
499 * to be used from the drivers ->destroy callback.
501 * Note that this function does not remove the fb from active usuage - if it is
502 * still used anywhere, hilarity can ensue since userspace could call getfb on
503 * the id and get back -EINVAL. Obviously no concern at driver unload time.
505 * Also, the framebuffer will not be removed from the lookup idr - for
506 * user-created framebuffers this will happen in in the rmfb ioctl. For
507 * driver-private objects (e.g. for fbdev) drivers need to explicitly call
508 * drm_framebuffer_unregister_private.
510 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
512 struct drm_device
*dev
= fb
->dev
;
514 mutex_lock(&dev
->mode_config
.fb_lock
);
516 dev
->mode_config
.num_fb
--;
517 mutex_unlock(&dev
->mode_config
.fb_lock
);
519 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
522 * drm_framebuffer_remove - remove and unreference a framebuffer object
523 * @fb: framebuffer to remove
525 * Scans all the CRTCs and planes in @dev's mode_config. If they're
526 * using @fb, removes it, setting it to NULL. Then drops the reference to the
527 * passed-in framebuffer. Might take the modeset locks.
529 * Note that this function optimizes the cleanup away if the caller holds the
530 * last reference to the framebuffer. It is also guaranteed to not take the
531 * modeset locks in this case.
533 void drm_framebuffer_remove(struct drm_framebuffer
*fb
)
535 struct drm_device
*dev
= fb
->dev
;
536 struct drm_crtc
*crtc
;
537 struct drm_plane
*plane
;
538 struct drm_mode_set set
;
541 WARN_ON(!list_empty(&fb
->filp_head
));
544 * drm ABI mandates that we remove any deleted framebuffers from active
545 * useage. But since most sane clients only remove framebuffers they no
546 * longer need, try to optimize this away.
548 * Since we're holding a reference ourselves, observing a refcount of 1
549 * means that we're the last holder and can skip it. Also, the refcount
550 * can never increase from 1 again, so we don't need any barriers or
553 * Note that userspace could try to race with use and instate a new
554 * usage _after_ we've cleared all current ones. End result will be an
555 * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
558 if (atomic_read(&fb
->refcount
.refcount
) > 1) {
559 drm_modeset_lock_all(dev
);
560 /* remove from any CRTC */
561 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
562 if (crtc
->fb
== fb
) {
563 /* should turn off the crtc */
564 memset(&set
, 0, sizeof(struct drm_mode_set
));
567 ret
= drm_mode_set_config_internal(&set
);
569 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
573 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
574 if (plane
->fb
== fb
) {
575 /* should turn off the crtc */
576 ret
= plane
->funcs
->disable_plane(plane
);
578 DRM_ERROR("failed to disable plane with busy fb\n");
579 /* disconnect the plane from the fb and crtc: */
580 __drm_framebuffer_unreference(plane
->fb
);
585 drm_modeset_unlock_all(dev
);
588 drm_framebuffer_unreference(fb
);
590 EXPORT_SYMBOL(drm_framebuffer_remove
);
593 * drm_crtc_init - Initialise a new CRTC object
595 * @crtc: CRTC object to init
596 * @funcs: callbacks for the new CRTC
598 * Inits a new object created as base part of an driver crtc object.
601 * Zero on success, error code on failure.
603 int drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
604 const struct drm_crtc_funcs
*funcs
)
610 crtc
->invert_dimensions
= false;
612 drm_modeset_lock_all(dev
);
613 mutex_init(&crtc
->mutex
);
614 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
616 ret
= drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
620 crtc
->base
.properties
= &crtc
->properties
;
622 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
623 dev
->mode_config
.num_crtc
++;
626 drm_modeset_unlock_all(dev
);
630 EXPORT_SYMBOL(drm_crtc_init
);
633 * drm_crtc_cleanup - Cleans up the core crtc usage.
634 * @crtc: CRTC to cleanup
636 * Cleanup @crtc. Removes from drm modesetting space
637 * does NOT free object, caller does that.
639 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
641 struct drm_device
*dev
= crtc
->dev
;
643 kfree(crtc
->gamma_store
);
644 crtc
->gamma_store
= NULL
;
646 drm_mode_object_put(dev
, &crtc
->base
);
647 list_del(&crtc
->head
);
648 dev
->mode_config
.num_crtc
--;
650 EXPORT_SYMBOL(drm_crtc_cleanup
);
653 * drm_mode_probed_add - add a mode to a connector's probed mode list
654 * @connector: connector the new mode
657 * Add @mode to @connector's mode list for later use.
659 void drm_mode_probed_add(struct drm_connector
*connector
,
660 struct drm_display_mode
*mode
)
662 list_add(&mode
->head
, &connector
->probed_modes
);
664 EXPORT_SYMBOL(drm_mode_probed_add
);
667 * drm_mode_remove - remove and free a mode
668 * @connector: connector list to modify
669 * @mode: mode to remove
671 * Remove @mode from @connector's mode list, then free it.
673 void drm_mode_remove(struct drm_connector
*connector
,
674 struct drm_display_mode
*mode
)
676 list_del(&mode
->head
);
677 drm_mode_destroy(connector
->dev
, mode
);
679 EXPORT_SYMBOL(drm_mode_remove
);
682 * drm_connector_init - Init a preallocated connector
684 * @connector: the connector to init
685 * @funcs: callbacks for this connector
686 * @connector_type: user visible type of the connector
688 * Initialises a preallocated connector. Connectors should be
689 * subclassed as part of driver connector objects.
692 * Zero on success, error code on failure.
694 int drm_connector_init(struct drm_device
*dev
,
695 struct drm_connector
*connector
,
696 const struct drm_connector_funcs
*funcs
,
701 drm_modeset_lock_all(dev
);
703 ret
= drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
707 connector
->base
.properties
= &connector
->properties
;
708 connector
->dev
= dev
;
709 connector
->funcs
= funcs
;
710 connector
->connector_type
= connector_type
;
711 connector
->connector_type_id
=
712 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
713 INIT_LIST_HEAD(&connector
->user_modes
);
714 INIT_LIST_HEAD(&connector
->probed_modes
);
715 INIT_LIST_HEAD(&connector
->modes
);
716 connector
->edid_blob_ptr
= NULL
;
717 connector
->status
= connector_status_unknown
;
719 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
720 dev
->mode_config
.num_connector
++;
722 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
723 drm_object_attach_property(&connector
->base
,
724 dev
->mode_config
.edid_property
,
727 drm_object_attach_property(&connector
->base
,
728 dev
->mode_config
.dpms_property
, 0);
731 drm_modeset_unlock_all(dev
);
735 EXPORT_SYMBOL(drm_connector_init
);
738 * drm_connector_cleanup - cleans up an initialised connector
739 * @connector: connector to cleanup
741 * Cleans up the connector but doesn't free the object.
743 void drm_connector_cleanup(struct drm_connector
*connector
)
745 struct drm_device
*dev
= connector
->dev
;
746 struct drm_display_mode
*mode
, *t
;
748 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
749 drm_mode_remove(connector
, mode
);
751 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
752 drm_mode_remove(connector
, mode
);
754 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
755 drm_mode_remove(connector
, mode
);
757 drm_mode_object_put(dev
, &connector
->base
);
758 list_del(&connector
->head
);
759 dev
->mode_config
.num_connector
--;
761 EXPORT_SYMBOL(drm_connector_cleanup
);
763 void drm_connector_unplug_all(struct drm_device
*dev
)
765 struct drm_connector
*connector
;
767 /* taking the mode config mutex ends up in a clash with sysfs */
768 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
769 drm_sysfs_connector_remove(connector
);
772 EXPORT_SYMBOL(drm_connector_unplug_all
);
774 int drm_encoder_init(struct drm_device
*dev
,
775 struct drm_encoder
*encoder
,
776 const struct drm_encoder_funcs
*funcs
,
781 drm_modeset_lock_all(dev
);
783 ret
= drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
788 encoder
->encoder_type
= encoder_type
;
789 encoder
->funcs
= funcs
;
791 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
792 dev
->mode_config
.num_encoder
++;
795 drm_modeset_unlock_all(dev
);
799 EXPORT_SYMBOL(drm_encoder_init
);
801 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
803 struct drm_device
*dev
= encoder
->dev
;
804 drm_modeset_lock_all(dev
);
805 drm_mode_object_put(dev
, &encoder
->base
);
806 list_del(&encoder
->head
);
807 dev
->mode_config
.num_encoder
--;
808 drm_modeset_unlock_all(dev
);
810 EXPORT_SYMBOL(drm_encoder_cleanup
);
812 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
813 unsigned long possible_crtcs
,
814 const struct drm_plane_funcs
*funcs
,
815 const uint32_t *formats
, uint32_t format_count
,
820 drm_modeset_lock_all(dev
);
822 ret
= drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
826 plane
->base
.properties
= &plane
->properties
;
828 plane
->funcs
= funcs
;
829 plane
->format_types
= kmalloc(sizeof(uint32_t) * format_count
,
831 if (!plane
->format_types
) {
832 DRM_DEBUG_KMS("out of memory when allocating plane\n");
833 drm_mode_object_put(dev
, &plane
->base
);
838 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
839 plane
->format_count
= format_count
;
840 plane
->possible_crtcs
= possible_crtcs
;
842 /* private planes are not exposed to userspace, but depending on
843 * display hardware, might be convenient to allow sharing programming
844 * for the scanout engine with the crtc implementation.
847 list_add_tail(&plane
->head
, &dev
->mode_config
.plane_list
);
848 dev
->mode_config
.num_plane
++;
850 INIT_LIST_HEAD(&plane
->head
);
854 drm_modeset_unlock_all(dev
);
858 EXPORT_SYMBOL(drm_plane_init
);
860 void drm_plane_cleanup(struct drm_plane
*plane
)
862 struct drm_device
*dev
= plane
->dev
;
864 drm_modeset_lock_all(dev
);
865 kfree(plane
->format_types
);
866 drm_mode_object_put(dev
, &plane
->base
);
867 /* if not added to a list, it must be a private plane */
868 if (!list_empty(&plane
->head
)) {
869 list_del(&plane
->head
);
870 dev
->mode_config
.num_plane
--;
872 drm_modeset_unlock_all(dev
);
874 EXPORT_SYMBOL(drm_plane_cleanup
);
877 * drm_mode_create - create a new display mode
880 * Create a new drm_display_mode, give it an ID, and return it.
883 * Pointer to new mode on success, NULL on error.
885 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
887 struct drm_display_mode
*nmode
;
889 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
893 if (drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
)) {
900 EXPORT_SYMBOL(drm_mode_create
);
903 * drm_mode_destroy - remove a mode
905 * @mode: mode to remove
907 * Free @mode's unique identifier, then free it.
909 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
914 drm_mode_object_put(dev
, &mode
->base
);
918 EXPORT_SYMBOL(drm_mode_destroy
);
920 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
922 struct drm_property
*edid
;
923 struct drm_property
*dpms
;
926 * Standard properties (apply to all connectors)
928 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
929 DRM_MODE_PROP_IMMUTABLE
,
931 dev
->mode_config
.edid_property
= edid
;
933 dpms
= drm_property_create_enum(dev
, 0,
934 "DPMS", drm_dpms_enum_list
,
935 ARRAY_SIZE(drm_dpms_enum_list
));
936 dev
->mode_config
.dpms_property
= dpms
;
942 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
945 * Called by a driver the first time a DVI-I connector is made.
947 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
949 struct drm_property
*dvi_i_selector
;
950 struct drm_property
*dvi_i_subconnector
;
952 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
956 drm_property_create_enum(dev
, 0,
957 "select subconnector",
958 drm_dvi_i_select_enum_list
,
959 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
960 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
962 dvi_i_subconnector
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
964 drm_dvi_i_subconnector_enum_list
,
965 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
966 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
970 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
973 * drm_create_tv_properties - create TV specific connector properties
975 * @num_modes: number of different TV formats (modes) supported
976 * @modes: array of pointers to strings containing name of each format
978 * Called by a driver's TV initialization routine, this function creates
979 * the TV specific connector properties for a given device. Caller is
980 * responsible for allocating a list of format names and passing them to
983 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
986 struct drm_property
*tv_selector
;
987 struct drm_property
*tv_subconnector
;
990 if (dev
->mode_config
.tv_select_subconnector_property
)
994 * Basic connector properties
996 tv_selector
= drm_property_create_enum(dev
, 0,
997 "select subconnector",
998 drm_tv_select_enum_list
,
999 ARRAY_SIZE(drm_tv_select_enum_list
));
1000 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
1003 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1005 drm_tv_subconnector_enum_list
,
1006 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
1007 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
1010 * Other, TV specific properties: margins & TV modes.
1012 dev
->mode_config
.tv_left_margin_property
=
1013 drm_property_create_range(dev
, 0, "left margin", 0, 100);
1015 dev
->mode_config
.tv_right_margin_property
=
1016 drm_property_create_range(dev
, 0, "right margin", 0, 100);
1018 dev
->mode_config
.tv_top_margin_property
=
1019 drm_property_create_range(dev
, 0, "top margin", 0, 100);
1021 dev
->mode_config
.tv_bottom_margin_property
=
1022 drm_property_create_range(dev
, 0, "bottom margin", 0, 100);
1024 dev
->mode_config
.tv_mode_property
=
1025 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
1027 for (i
= 0; i
< num_modes
; i
++)
1028 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
1031 dev
->mode_config
.tv_brightness_property
=
1032 drm_property_create_range(dev
, 0, "brightness", 0, 100);
1034 dev
->mode_config
.tv_contrast_property
=
1035 drm_property_create_range(dev
, 0, "contrast", 0, 100);
1037 dev
->mode_config
.tv_flicker_reduction_property
=
1038 drm_property_create_range(dev
, 0, "flicker reduction", 0, 100);
1040 dev
->mode_config
.tv_overscan_property
=
1041 drm_property_create_range(dev
, 0, "overscan", 0, 100);
1043 dev
->mode_config
.tv_saturation_property
=
1044 drm_property_create_range(dev
, 0, "saturation", 0, 100);
1046 dev
->mode_config
.tv_hue_property
=
1047 drm_property_create_range(dev
, 0, "hue", 0, 100);
1051 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
1054 * drm_mode_create_scaling_mode_property - create scaling mode property
1057 * Called by a driver the first time it's needed, must be attached to desired
1060 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
1062 struct drm_property
*scaling_mode
;
1064 if (dev
->mode_config
.scaling_mode_property
)
1068 drm_property_create_enum(dev
, 0, "scaling mode",
1069 drm_scaling_mode_enum_list
,
1070 ARRAY_SIZE(drm_scaling_mode_enum_list
));
1072 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
1076 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
1079 * drm_mode_create_dithering_property - create dithering property
1082 * Called by a driver the first time it's needed, must be attached to desired
1085 int drm_mode_create_dithering_property(struct drm_device
*dev
)
1087 struct drm_property
*dithering_mode
;
1089 if (dev
->mode_config
.dithering_mode_property
)
1093 drm_property_create_enum(dev
, 0, "dithering",
1094 drm_dithering_mode_enum_list
,
1095 ARRAY_SIZE(drm_dithering_mode_enum_list
));
1096 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
1100 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
1103 * drm_mode_create_dirty_property - create dirty property
1106 * Called by a driver the first time it's needed, must be attached to desired
1109 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
1111 struct drm_property
*dirty_info
;
1113 if (dev
->mode_config
.dirty_info_property
)
1117 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1119 drm_dirty_info_enum_list
,
1120 ARRAY_SIZE(drm_dirty_info_enum_list
));
1121 dev
->mode_config
.dirty_info_property
= dirty_info
;
1125 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
1128 * drm_mode_config_init - initialize DRM mode_configuration structure
1131 * Initialize @dev's mode_config structure, used for tracking the graphics
1132 * configuration of @dev.
1134 * Since this initializes the modeset locks, no locking is possible. Which is no
1135 * problem, since this should happen single threaded at init time. It is the
1136 * driver's problem to ensure this guarantee.
1139 void drm_mode_config_init(struct drm_device
*dev
)
1141 mutex_init(&dev
->mode_config
.mutex
);
1142 mutex_init(&dev
->mode_config
.idr_mutex
);
1143 mutex_init(&dev
->mode_config
.fb_lock
);
1144 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
1145 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
1146 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
1147 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
1148 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
1149 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
1150 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
1151 idr_init(&dev
->mode_config
.crtc_idr
);
1153 drm_modeset_lock_all(dev
);
1154 drm_mode_create_standard_connector_properties(dev
);
1155 drm_modeset_unlock_all(dev
);
1157 /* Just to be sure */
1158 dev
->mode_config
.num_fb
= 0;
1159 dev
->mode_config
.num_connector
= 0;
1160 dev
->mode_config
.num_crtc
= 0;
1161 dev
->mode_config
.num_encoder
= 0;
1163 EXPORT_SYMBOL(drm_mode_config_init
);
1165 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
1167 uint32_t total_objects
= 0;
1169 total_objects
+= dev
->mode_config
.num_crtc
;
1170 total_objects
+= dev
->mode_config
.num_connector
;
1171 total_objects
+= dev
->mode_config
.num_encoder
;
1173 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
1174 if (!group
->id_list
)
1177 group
->num_crtcs
= 0;
1178 group
->num_connectors
= 0;
1179 group
->num_encoders
= 0;
1183 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
1184 struct drm_mode_group
*group
)
1186 struct drm_crtc
*crtc
;
1187 struct drm_encoder
*encoder
;
1188 struct drm_connector
*connector
;
1191 if ((ret
= drm_mode_group_init(dev
, group
)))
1194 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
1195 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
1197 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
1198 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
1201 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
1202 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
1203 group
->num_connectors
++] = connector
->base
.id
;
1207 EXPORT_SYMBOL(drm_mode_group_init_legacy_group
);
1210 * drm_mode_config_cleanup - free up DRM mode_config info
1213 * Free up all the connectors and CRTCs associated with this DRM device, then
1214 * free up the framebuffers and associated buffer objects.
1216 * Note that since this /should/ happen single-threaded at driver/device
1217 * teardown time, no locking is required. It's the driver's job to ensure that
1218 * this guarantee actually holds true.
1220 * FIXME: cleanup any dangling user buffer objects too
1222 void drm_mode_config_cleanup(struct drm_device
*dev
)
1224 struct drm_connector
*connector
, *ot
;
1225 struct drm_crtc
*crtc
, *ct
;
1226 struct drm_encoder
*encoder
, *enct
;
1227 struct drm_framebuffer
*fb
, *fbt
;
1228 struct drm_property
*property
, *pt
;
1229 struct drm_plane
*plane
, *plt
;
1231 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
1233 encoder
->funcs
->destroy(encoder
);
1236 list_for_each_entry_safe(connector
, ot
,
1237 &dev
->mode_config
.connector_list
, head
) {
1238 connector
->funcs
->destroy(connector
);
1241 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
1243 drm_property_destroy(dev
, property
);
1247 * Single-threaded teardown context, so it's not required to grab the
1248 * fb_lock to protect against concurrent fb_list access. Contrary, it
1249 * would actually deadlock with the drm_framebuffer_cleanup function.
1251 * Also, if there are any framebuffers left, that's a driver leak now,
1252 * so politely WARN about this.
1254 WARN_ON(!list_empty(&dev
->mode_config
.fb_list
));
1255 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
1256 drm_framebuffer_remove(fb
);
1259 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
1261 plane
->funcs
->destroy(plane
);
1264 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
1265 crtc
->funcs
->destroy(crtc
);
1268 idr_destroy(&dev
->mode_config
.crtc_idr
);
1270 EXPORT_SYMBOL(drm_mode_config_cleanup
);
1273 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1274 * @out: drm_mode_modeinfo struct to return to the user
1275 * @in: drm_display_mode to use
1277 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1280 static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
1281 const struct drm_display_mode
*in
)
1283 WARN(in
->hdisplay
> USHRT_MAX
|| in
->hsync_start
> USHRT_MAX
||
1284 in
->hsync_end
> USHRT_MAX
|| in
->htotal
> USHRT_MAX
||
1285 in
->hskew
> USHRT_MAX
|| in
->vdisplay
> USHRT_MAX
||
1286 in
->vsync_start
> USHRT_MAX
|| in
->vsync_end
> USHRT_MAX
||
1287 in
->vtotal
> USHRT_MAX
|| in
->vscan
> USHRT_MAX
,
1288 "timing values too large for mode info\n");
1290 out
->clock
= in
->clock
;
1291 out
->hdisplay
= in
->hdisplay
;
1292 out
->hsync_start
= in
->hsync_start
;
1293 out
->hsync_end
= in
->hsync_end
;
1294 out
->htotal
= in
->htotal
;
1295 out
->hskew
= in
->hskew
;
1296 out
->vdisplay
= in
->vdisplay
;
1297 out
->vsync_start
= in
->vsync_start
;
1298 out
->vsync_end
= in
->vsync_end
;
1299 out
->vtotal
= in
->vtotal
;
1300 out
->vscan
= in
->vscan
;
1301 out
->vrefresh
= in
->vrefresh
;
1302 out
->flags
= in
->flags
;
1303 out
->type
= in
->type
;
1304 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1305 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1309 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1310 * @out: drm_display_mode to return to the user
1311 * @in: drm_mode_modeinfo to use
1313 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1317 * Zero on success, errno on failure.
1319 static int drm_crtc_convert_umode(struct drm_display_mode
*out
,
1320 const struct drm_mode_modeinfo
*in
)
1322 if (in
->clock
> INT_MAX
|| in
->vrefresh
> INT_MAX
)
1325 out
->clock
= in
->clock
;
1326 out
->hdisplay
= in
->hdisplay
;
1327 out
->hsync_start
= in
->hsync_start
;
1328 out
->hsync_end
= in
->hsync_end
;
1329 out
->htotal
= in
->htotal
;
1330 out
->hskew
= in
->hskew
;
1331 out
->vdisplay
= in
->vdisplay
;
1332 out
->vsync_start
= in
->vsync_start
;
1333 out
->vsync_end
= in
->vsync_end
;
1334 out
->vtotal
= in
->vtotal
;
1335 out
->vscan
= in
->vscan
;
1336 out
->vrefresh
= in
->vrefresh
;
1337 out
->flags
= in
->flags
;
1338 out
->type
= in
->type
;
1339 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1340 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1346 * drm_mode_getresources - get graphics configuration
1347 * @dev: drm device for the ioctl
1348 * @data: data pointer for the ioctl
1349 * @file_priv: drm file for the ioctl call
1351 * Construct a set of configuration description structures and return
1352 * them to the user, including CRTC, connector and framebuffer configuration.
1354 * Called by the user via ioctl.
1357 * Zero on success, errno on failure.
1359 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1360 struct drm_file
*file_priv
)
1362 struct drm_mode_card_res
*card_res
= data
;
1363 struct list_head
*lh
;
1364 struct drm_framebuffer
*fb
;
1365 struct drm_connector
*connector
;
1366 struct drm_crtc
*crtc
;
1367 struct drm_encoder
*encoder
;
1369 int connector_count
= 0;
1372 int encoder_count
= 0;
1374 uint32_t __user
*fb_id
;
1375 uint32_t __user
*crtc_id
;
1376 uint32_t __user
*connector_id
;
1377 uint32_t __user
*encoder_id
;
1378 struct drm_mode_group
*mode_group
;
1380 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1384 mutex_lock(&file_priv
->fbs_lock
);
1386 * For the non-control nodes we need to limit the list of resources
1387 * by IDs in the group list for this node
1389 list_for_each(lh
, &file_priv
->fbs
)
1392 /* handle this in 4 parts */
1394 if (card_res
->count_fbs
>= fb_count
) {
1396 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1397 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1398 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1399 mutex_unlock(&file_priv
->fbs_lock
);
1405 card_res
->count_fbs
= fb_count
;
1406 mutex_unlock(&file_priv
->fbs_lock
);
1408 drm_modeset_lock_all(dev
);
1409 mode_group
= &file_priv
->master
->minor
->mode_group
;
1410 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1412 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1415 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1418 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1422 crtc_count
= mode_group
->num_crtcs
;
1423 connector_count
= mode_group
->num_connectors
;
1424 encoder_count
= mode_group
->num_encoders
;
1427 card_res
->max_height
= dev
->mode_config
.max_height
;
1428 card_res
->min_height
= dev
->mode_config
.min_height
;
1429 card_res
->max_width
= dev
->mode_config
.max_width
;
1430 card_res
->min_width
= dev
->mode_config
.min_width
;
1433 if (card_res
->count_crtcs
>= crtc_count
) {
1435 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1436 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1437 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1439 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1440 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1447 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1448 if (put_user(mode_group
->id_list
[i
],
1449 crtc_id
+ copied
)) {
1457 card_res
->count_crtcs
= crtc_count
;
1460 if (card_res
->count_encoders
>= encoder_count
) {
1462 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1463 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1464 list_for_each_entry(encoder
,
1465 &dev
->mode_config
.encoder_list
,
1467 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1468 drm_get_encoder_name(encoder
));
1469 if (put_user(encoder
->base
.id
, encoder_id
+
1477 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1478 if (put_user(mode_group
->id_list
[i
],
1479 encoder_id
+ copied
)) {
1488 card_res
->count_encoders
= encoder_count
;
1491 if (card_res
->count_connectors
>= connector_count
) {
1493 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1494 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1495 list_for_each_entry(connector
,
1496 &dev
->mode_config
.connector_list
,
1498 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1500 drm_get_connector_name(connector
));
1501 if (put_user(connector
->base
.id
,
1502 connector_id
+ copied
)) {
1509 int start
= mode_group
->num_crtcs
+
1510 mode_group
->num_encoders
;
1511 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1512 if (put_user(mode_group
->id_list
[i
],
1513 connector_id
+ copied
)) {
1521 card_res
->count_connectors
= connector_count
;
1523 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1524 card_res
->count_connectors
, card_res
->count_encoders
);
1527 drm_modeset_unlock_all(dev
);
1532 * drm_mode_getcrtc - get CRTC configuration
1533 * @dev: drm device for the ioctl
1534 * @data: data pointer for the ioctl
1535 * @file_priv: drm file for the ioctl call
1537 * Construct a CRTC configuration structure to return to the user.
1539 * Called by the user via ioctl.
1542 * Zero on success, errno on failure.
1544 int drm_mode_getcrtc(struct drm_device
*dev
,
1545 void *data
, struct drm_file
*file_priv
)
1547 struct drm_mode_crtc
*crtc_resp
= data
;
1548 struct drm_crtc
*crtc
;
1549 struct drm_mode_object
*obj
;
1552 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1555 drm_modeset_lock_all(dev
);
1557 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1558 DRM_MODE_OBJECT_CRTC
);
1563 crtc
= obj_to_crtc(obj
);
1565 crtc_resp
->x
= crtc
->x
;
1566 crtc_resp
->y
= crtc
->y
;
1567 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1569 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1571 crtc_resp
->fb_id
= 0;
1573 if (crtc
->enabled
) {
1575 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1576 crtc_resp
->mode_valid
= 1;
1579 crtc_resp
->mode_valid
= 0;
1583 drm_modeset_unlock_all(dev
);
1588 * drm_mode_getconnector - get connector configuration
1589 * @dev: drm device for the ioctl
1590 * @data: data pointer for the ioctl
1591 * @file_priv: drm file for the ioctl call
1593 * Construct a connector configuration structure to return to the user.
1595 * Called by the user via ioctl.
1598 * Zero on success, errno on failure.
1600 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1601 struct drm_file
*file_priv
)
1603 struct drm_mode_get_connector
*out_resp
= data
;
1604 struct drm_mode_object
*obj
;
1605 struct drm_connector
*connector
;
1606 struct drm_display_mode
*mode
;
1608 int props_count
= 0;
1609 int encoders_count
= 0;
1613 struct drm_mode_modeinfo u_mode
;
1614 struct drm_mode_modeinfo __user
*mode_ptr
;
1615 uint32_t __user
*prop_ptr
;
1616 uint64_t __user
*prop_values
;
1617 uint32_t __user
*encoder_ptr
;
1619 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1622 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1624 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1626 mutex_lock(&dev
->mode_config
.mutex
);
1628 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1629 DRM_MODE_OBJECT_CONNECTOR
);
1634 connector
= obj_to_connector(obj
);
1636 props_count
= connector
->properties
.count
;
1638 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1639 if (connector
->encoder_ids
[i
] != 0) {
1644 if (out_resp
->count_modes
== 0) {
1645 connector
->funcs
->fill_modes(connector
,
1646 dev
->mode_config
.max_width
,
1647 dev
->mode_config
.max_height
);
1650 /* delayed so we get modes regardless of pre-fill_modes state */
1651 list_for_each_entry(mode
, &connector
->modes
, head
)
1654 out_resp
->connector_id
= connector
->base
.id
;
1655 out_resp
->connector_type
= connector
->connector_type
;
1656 out_resp
->connector_type_id
= connector
->connector_type_id
;
1657 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1658 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1659 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1660 out_resp
->connection
= connector
->status
;
1661 if (connector
->encoder
)
1662 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1664 out_resp
->encoder_id
= 0;
1667 * This ioctl is called twice, once to determine how much space is
1668 * needed, and the 2nd time to fill it.
1670 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1672 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1673 list_for_each_entry(mode
, &connector
->modes
, head
) {
1674 drm_crtc_convert_to_umode(&u_mode
, mode
);
1675 if (copy_to_user(mode_ptr
+ copied
,
1676 &u_mode
, sizeof(u_mode
))) {
1683 out_resp
->count_modes
= mode_count
;
1685 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1687 prop_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
);
1688 prop_values
= (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
);
1689 for (i
= 0; i
< connector
->properties
.count
; i
++) {
1690 if (put_user(connector
->properties
.ids
[i
],
1691 prop_ptr
+ copied
)) {
1696 if (put_user(connector
->properties
.values
[i
],
1697 prop_values
+ copied
)) {
1704 out_resp
->count_props
= props_count
;
1706 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1708 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1709 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1710 if (connector
->encoder_ids
[i
] != 0) {
1711 if (put_user(connector
->encoder_ids
[i
],
1712 encoder_ptr
+ copied
)) {
1720 out_resp
->count_encoders
= encoders_count
;
1723 mutex_unlock(&dev
->mode_config
.mutex
);
1728 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1729 struct drm_file
*file_priv
)
1731 struct drm_mode_get_encoder
*enc_resp
= data
;
1732 struct drm_mode_object
*obj
;
1733 struct drm_encoder
*encoder
;
1736 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1739 drm_modeset_lock_all(dev
);
1740 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1741 DRM_MODE_OBJECT_ENCODER
);
1746 encoder
= obj_to_encoder(obj
);
1749 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1751 enc_resp
->crtc_id
= 0;
1752 enc_resp
->encoder_type
= encoder
->encoder_type
;
1753 enc_resp
->encoder_id
= encoder
->base
.id
;
1754 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1755 enc_resp
->possible_clones
= encoder
->possible_clones
;
1758 drm_modeset_unlock_all(dev
);
1763 * drm_mode_getplane_res - get plane info
1766 * @file_priv: DRM file info
1768 * Return an plane count and set of IDs.
1770 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
1771 struct drm_file
*file_priv
)
1773 struct drm_mode_get_plane_res
*plane_resp
= data
;
1774 struct drm_mode_config
*config
;
1775 struct drm_plane
*plane
;
1776 uint32_t __user
*plane_ptr
;
1777 int copied
= 0, ret
= 0;
1779 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1782 drm_modeset_lock_all(dev
);
1783 config
= &dev
->mode_config
;
1786 * This ioctl is called twice, once to determine how much space is
1787 * needed, and the 2nd time to fill it.
1789 if (config
->num_plane
&&
1790 (plane_resp
->count_planes
>= config
->num_plane
)) {
1791 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
1793 list_for_each_entry(plane
, &config
->plane_list
, head
) {
1794 if (put_user(plane
->base
.id
, plane_ptr
+ copied
)) {
1801 plane_resp
->count_planes
= config
->num_plane
;
1804 drm_modeset_unlock_all(dev
);
1809 * drm_mode_getplane - get plane info
1812 * @file_priv: DRM file info
1814 * Return plane info, including formats supported, gamma size, any
1817 int drm_mode_getplane(struct drm_device
*dev
, void *data
,
1818 struct drm_file
*file_priv
)
1820 struct drm_mode_get_plane
*plane_resp
= data
;
1821 struct drm_mode_object
*obj
;
1822 struct drm_plane
*plane
;
1823 uint32_t __user
*format_ptr
;
1826 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1829 drm_modeset_lock_all(dev
);
1830 obj
= drm_mode_object_find(dev
, plane_resp
->plane_id
,
1831 DRM_MODE_OBJECT_PLANE
);
1836 plane
= obj_to_plane(obj
);
1839 plane_resp
->crtc_id
= plane
->crtc
->base
.id
;
1841 plane_resp
->crtc_id
= 0;
1844 plane_resp
->fb_id
= plane
->fb
->base
.id
;
1846 plane_resp
->fb_id
= 0;
1848 plane_resp
->plane_id
= plane
->base
.id
;
1849 plane_resp
->possible_crtcs
= plane
->possible_crtcs
;
1850 plane_resp
->gamma_size
= plane
->gamma_size
;
1853 * This ioctl is called twice, once to determine how much space is
1854 * needed, and the 2nd time to fill it.
1856 if (plane
->format_count
&&
1857 (plane_resp
->count_format_types
>= plane
->format_count
)) {
1858 format_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->format_type_ptr
;
1859 if (copy_to_user(format_ptr
,
1860 plane
->format_types
,
1861 sizeof(uint32_t) * plane
->format_count
)) {
1866 plane_resp
->count_format_types
= plane
->format_count
;
1869 drm_modeset_unlock_all(dev
);
1874 * drm_mode_setplane - set up or tear down an plane
1876 * @data: ioctl data*
1877 * @file_priv: DRM file info
1879 * Set plane info, including placement, fb, scaling, and other factors.
1880 * Or pass a NULL fb to disable.
1882 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
1883 struct drm_file
*file_priv
)
1885 struct drm_mode_set_plane
*plane_req
= data
;
1886 struct drm_mode_object
*obj
;
1887 struct drm_plane
*plane
;
1888 struct drm_crtc
*crtc
;
1889 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
1891 unsigned int fb_width
, fb_height
;
1894 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1898 * First, find the plane, crtc, and fb objects. If not available,
1899 * we don't bother to call the driver.
1901 obj
= drm_mode_object_find(dev
, plane_req
->plane_id
,
1902 DRM_MODE_OBJECT_PLANE
);
1904 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1905 plane_req
->plane_id
);
1908 plane
= obj_to_plane(obj
);
1910 /* No fb means shut it down */
1911 if (!plane_req
->fb_id
) {
1912 drm_modeset_lock_all(dev
);
1914 plane
->funcs
->disable_plane(plane
);
1917 drm_modeset_unlock_all(dev
);
1921 obj
= drm_mode_object_find(dev
, plane_req
->crtc_id
,
1922 DRM_MODE_OBJECT_CRTC
);
1924 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1925 plane_req
->crtc_id
);
1929 crtc
= obj_to_crtc(obj
);
1931 fb
= drm_framebuffer_lookup(dev
, plane_req
->fb_id
);
1933 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1939 /* Check whether this plane supports the fb pixel format. */
1940 for (i
= 0; i
< plane
->format_count
; i
++)
1941 if (fb
->pixel_format
== plane
->format_types
[i
])
1943 if (i
== plane
->format_count
) {
1944 DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb
->pixel_format
);
1949 fb_width
= fb
->width
<< 16;
1950 fb_height
= fb
->height
<< 16;
1952 /* Make sure source coordinates are inside the fb. */
1953 if (plane_req
->src_w
> fb_width
||
1954 plane_req
->src_x
> fb_width
- plane_req
->src_w
||
1955 plane_req
->src_h
> fb_height
||
1956 plane_req
->src_y
> fb_height
- plane_req
->src_h
) {
1957 DRM_DEBUG_KMS("Invalid source coordinates "
1958 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1959 plane_req
->src_w
>> 16,
1960 ((plane_req
->src_w
& 0xffff) * 15625) >> 10,
1961 plane_req
->src_h
>> 16,
1962 ((plane_req
->src_h
& 0xffff) * 15625) >> 10,
1963 plane_req
->src_x
>> 16,
1964 ((plane_req
->src_x
& 0xffff) * 15625) >> 10,
1965 plane_req
->src_y
>> 16,
1966 ((plane_req
->src_y
& 0xffff) * 15625) >> 10);
1971 /* Give drivers some help against integer overflows */
1972 if (plane_req
->crtc_w
> INT_MAX
||
1973 plane_req
->crtc_x
> INT_MAX
- (int32_t) plane_req
->crtc_w
||
1974 plane_req
->crtc_h
> INT_MAX
||
1975 plane_req
->crtc_y
> INT_MAX
- (int32_t) plane_req
->crtc_h
) {
1976 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
1977 plane_req
->crtc_w
, plane_req
->crtc_h
,
1978 plane_req
->crtc_x
, plane_req
->crtc_y
);
1983 drm_modeset_lock_all(dev
);
1984 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
1985 plane_req
->crtc_x
, plane_req
->crtc_y
,
1986 plane_req
->crtc_w
, plane_req
->crtc_h
,
1987 plane_req
->src_x
, plane_req
->src_y
,
1988 plane_req
->src_w
, plane_req
->src_h
);
1995 drm_modeset_unlock_all(dev
);
1999 drm_framebuffer_unreference(fb
);
2001 drm_framebuffer_unreference(old_fb
);
2007 * drm_mode_set_config_internal - helper to call ->set_config
2008 * @set: modeset config to set
2010 * This is a little helper to wrap internal calls to the ->set_config driver
2011 * interface. The only thing it adds is correct refcounting dance.
2013 int drm_mode_set_config_internal(struct drm_mode_set
*set
)
2015 struct drm_crtc
*crtc
= set
->crtc
;
2016 struct drm_framebuffer
*fb
, *old_fb
;
2022 ret
= crtc
->funcs
->set_config(set
);
2025 drm_framebuffer_unreference(old_fb
);
2027 drm_framebuffer_reference(fb
);
2032 EXPORT_SYMBOL(drm_mode_set_config_internal
);
2035 * drm_mode_setcrtc - set CRTC configuration
2036 * @dev: drm device for the ioctl
2037 * @data: data pointer for the ioctl
2038 * @file_priv: drm file for the ioctl call
2040 * Build a new CRTC configuration based on user request.
2042 * Called by the user via ioctl.
2045 * Zero on success, errno on failure.
2047 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
2048 struct drm_file
*file_priv
)
2050 struct drm_mode_config
*config
= &dev
->mode_config
;
2051 struct drm_mode_crtc
*crtc_req
= data
;
2052 struct drm_mode_object
*obj
;
2053 struct drm_crtc
*crtc
;
2054 struct drm_connector
**connector_set
= NULL
, *connector
;
2055 struct drm_framebuffer
*fb
= NULL
;
2056 struct drm_display_mode
*mode
= NULL
;
2057 struct drm_mode_set set
;
2058 uint32_t __user
*set_connectors_ptr
;
2062 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2065 /* For some reason crtc x/y offsets are signed internally. */
2066 if (crtc_req
->x
> INT_MAX
|| crtc_req
->y
> INT_MAX
)
2069 drm_modeset_lock_all(dev
);
2070 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
2071 DRM_MODE_OBJECT_CRTC
);
2073 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
2077 crtc
= obj_to_crtc(obj
);
2078 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
2080 if (crtc_req
->mode_valid
) {
2081 int hdisplay
, vdisplay
;
2082 /* If we have a mode we need a framebuffer. */
2083 /* If we pass -1, set the mode with the currently bound fb */
2084 if (crtc_req
->fb_id
== -1) {
2086 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
2091 /* Make refcounting symmetric with the lookup path. */
2092 drm_framebuffer_reference(fb
);
2094 fb
= drm_framebuffer_lookup(dev
, crtc_req
->fb_id
);
2096 DRM_DEBUG_KMS("Unknown FB ID%d\n",
2103 mode
= drm_mode_create(dev
);
2109 ret
= drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
2111 DRM_DEBUG_KMS("Invalid mode\n");
2115 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
2117 hdisplay
= mode
->hdisplay
;
2118 vdisplay
= mode
->vdisplay
;
2120 if (crtc
->invert_dimensions
)
2121 swap(hdisplay
, vdisplay
);
2123 if (hdisplay
> fb
->width
||
2124 vdisplay
> fb
->height
||
2125 crtc_req
->x
> fb
->width
- hdisplay
||
2126 crtc_req
->y
> fb
->height
- vdisplay
) {
2127 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
2128 fb
->width
, fb
->height
,
2129 hdisplay
, vdisplay
, crtc_req
->x
, crtc_req
->y
,
2130 crtc
->invert_dimensions
? " (inverted)" : "");
2136 if (crtc_req
->count_connectors
== 0 && mode
) {
2137 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
2142 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
2143 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
2144 crtc_req
->count_connectors
);
2149 if (crtc_req
->count_connectors
> 0) {
2152 /* Avoid unbounded kernel memory allocation */
2153 if (crtc_req
->count_connectors
> config
->num_connector
) {
2158 connector_set
= kmalloc(crtc_req
->count_connectors
*
2159 sizeof(struct drm_connector
*),
2161 if (!connector_set
) {
2166 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
2167 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
2168 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
2173 obj
= drm_mode_object_find(dev
, out_id
,
2174 DRM_MODE_OBJECT_CONNECTOR
);
2176 DRM_DEBUG_KMS("Connector id %d unknown\n",
2181 connector
= obj_to_connector(obj
);
2182 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2184 drm_get_connector_name(connector
));
2186 connector_set
[i
] = connector
;
2191 set
.x
= crtc_req
->x
;
2192 set
.y
= crtc_req
->y
;
2194 set
.connectors
= connector_set
;
2195 set
.num_connectors
= crtc_req
->count_connectors
;
2197 ret
= drm_mode_set_config_internal(&set
);
2201 drm_framebuffer_unreference(fb
);
2203 kfree(connector_set
);
2204 drm_mode_destroy(dev
, mode
);
2205 drm_modeset_unlock_all(dev
);
2209 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
2210 void *data
, struct drm_file
*file_priv
)
2212 struct drm_mode_cursor
*req
= data
;
2213 struct drm_mode_object
*obj
;
2214 struct drm_crtc
*crtc
;
2217 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2220 if (!req
->flags
|| (~DRM_MODE_CURSOR_FLAGS
& req
->flags
))
2223 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2225 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
2228 crtc
= obj_to_crtc(obj
);
2230 mutex_lock(&crtc
->mutex
);
2231 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
2232 if (!crtc
->funcs
->cursor_set
) {
2236 /* Turns off the cursor if handle is 0 */
2237 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
2238 req
->width
, req
->height
);
2241 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
2242 if (crtc
->funcs
->cursor_move
) {
2243 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
2250 mutex_unlock(&crtc
->mutex
);
2255 /* Original addfb only supported RGB formats, so figure out which one */
2256 uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
)
2262 fmt
= DRM_FORMAT_C8
;
2266 fmt
= DRM_FORMAT_XRGB1555
;
2268 fmt
= DRM_FORMAT_RGB565
;
2271 fmt
= DRM_FORMAT_RGB888
;
2275 fmt
= DRM_FORMAT_XRGB8888
;
2276 else if (depth
== 30)
2277 fmt
= DRM_FORMAT_XRGB2101010
;
2279 fmt
= DRM_FORMAT_ARGB8888
;
2282 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
2283 fmt
= DRM_FORMAT_XRGB8888
;
2289 EXPORT_SYMBOL(drm_mode_legacy_fb_format
);
2292 * drm_mode_addfb - add an FB to the graphics configuration
2293 * @dev: drm device for the ioctl
2294 * @data: data pointer for the ioctl
2295 * @file_priv: drm file for the ioctl call
2297 * Add a new FB to the specified CRTC, given a user request.
2299 * Called by the user via ioctl.
2302 * Zero on success, errno on failure.
2304 int drm_mode_addfb(struct drm_device
*dev
,
2305 void *data
, struct drm_file
*file_priv
)
2307 struct drm_mode_fb_cmd
*or = data
;
2308 struct drm_mode_fb_cmd2 r
= {};
2309 struct drm_mode_config
*config
= &dev
->mode_config
;
2310 struct drm_framebuffer
*fb
;
2313 /* Use new struct with format internally */
2314 r
.fb_id
= or->fb_id
;
2315 r
.width
= or->width
;
2316 r
.height
= or->height
;
2317 r
.pitches
[0] = or->pitch
;
2318 r
.pixel_format
= drm_mode_legacy_fb_format(or->bpp
, or->depth
);
2319 r
.handles
[0] = or->handle
;
2321 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2324 if ((config
->min_width
> r
.width
) || (r
.width
> config
->max_width
))
2327 if ((config
->min_height
> r
.height
) || (r
.height
> config
->max_height
))
2330 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, &r
);
2332 DRM_DEBUG_KMS("could not create framebuffer\n");
2333 drm_modeset_unlock_all(dev
);
2337 mutex_lock(&file_priv
->fbs_lock
);
2338 or->fb_id
= fb
->base
.id
;
2339 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2340 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2341 mutex_unlock(&file_priv
->fbs_lock
);
2346 static int format_check(const struct drm_mode_fb_cmd2
*r
)
2348 uint32_t format
= r
->pixel_format
& ~DRM_FORMAT_BIG_ENDIAN
;
2352 case DRM_FORMAT_RGB332
:
2353 case DRM_FORMAT_BGR233
:
2354 case DRM_FORMAT_XRGB4444
:
2355 case DRM_FORMAT_XBGR4444
:
2356 case DRM_FORMAT_RGBX4444
:
2357 case DRM_FORMAT_BGRX4444
:
2358 case DRM_FORMAT_ARGB4444
:
2359 case DRM_FORMAT_ABGR4444
:
2360 case DRM_FORMAT_RGBA4444
:
2361 case DRM_FORMAT_BGRA4444
:
2362 case DRM_FORMAT_XRGB1555
:
2363 case DRM_FORMAT_XBGR1555
:
2364 case DRM_FORMAT_RGBX5551
:
2365 case DRM_FORMAT_BGRX5551
:
2366 case DRM_FORMAT_ARGB1555
:
2367 case DRM_FORMAT_ABGR1555
:
2368 case DRM_FORMAT_RGBA5551
:
2369 case DRM_FORMAT_BGRA5551
:
2370 case DRM_FORMAT_RGB565
:
2371 case DRM_FORMAT_BGR565
:
2372 case DRM_FORMAT_RGB888
:
2373 case DRM_FORMAT_BGR888
:
2374 case DRM_FORMAT_XRGB8888
:
2375 case DRM_FORMAT_XBGR8888
:
2376 case DRM_FORMAT_RGBX8888
:
2377 case DRM_FORMAT_BGRX8888
:
2378 case DRM_FORMAT_ARGB8888
:
2379 case DRM_FORMAT_ABGR8888
:
2380 case DRM_FORMAT_RGBA8888
:
2381 case DRM_FORMAT_BGRA8888
:
2382 case DRM_FORMAT_XRGB2101010
:
2383 case DRM_FORMAT_XBGR2101010
:
2384 case DRM_FORMAT_RGBX1010102
:
2385 case DRM_FORMAT_BGRX1010102
:
2386 case DRM_FORMAT_ARGB2101010
:
2387 case DRM_FORMAT_ABGR2101010
:
2388 case DRM_FORMAT_RGBA1010102
:
2389 case DRM_FORMAT_BGRA1010102
:
2390 case DRM_FORMAT_YUYV
:
2391 case DRM_FORMAT_YVYU
:
2392 case DRM_FORMAT_UYVY
:
2393 case DRM_FORMAT_VYUY
:
2394 case DRM_FORMAT_AYUV
:
2395 case DRM_FORMAT_NV12
:
2396 case DRM_FORMAT_NV21
:
2397 case DRM_FORMAT_NV16
:
2398 case DRM_FORMAT_NV61
:
2399 case DRM_FORMAT_NV24
:
2400 case DRM_FORMAT_NV42
:
2401 case DRM_FORMAT_YUV410
:
2402 case DRM_FORMAT_YVU410
:
2403 case DRM_FORMAT_YUV411
:
2404 case DRM_FORMAT_YVU411
:
2405 case DRM_FORMAT_YUV420
:
2406 case DRM_FORMAT_YVU420
:
2407 case DRM_FORMAT_YUV422
:
2408 case DRM_FORMAT_YVU422
:
2409 case DRM_FORMAT_YUV444
:
2410 case DRM_FORMAT_YVU444
:
2417 static int framebuffer_check(const struct drm_mode_fb_cmd2
*r
)
2419 int ret
, hsub
, vsub
, num_planes
, i
;
2421 ret
= format_check(r
);
2423 DRM_DEBUG_KMS("bad framebuffer format 0x%08x\n", r
->pixel_format
);
2427 hsub
= drm_format_horz_chroma_subsampling(r
->pixel_format
);
2428 vsub
= drm_format_vert_chroma_subsampling(r
->pixel_format
);
2429 num_planes
= drm_format_num_planes(r
->pixel_format
);
2431 if (r
->width
== 0 || r
->width
% hsub
) {
2432 DRM_DEBUG_KMS("bad framebuffer width %u\n", r
->height
);
2436 if (r
->height
== 0 || r
->height
% vsub
) {
2437 DRM_DEBUG_KMS("bad framebuffer height %u\n", r
->height
);
2441 for (i
= 0; i
< num_planes
; i
++) {
2442 unsigned int width
= r
->width
/ (i
!= 0 ? hsub
: 1);
2443 unsigned int height
= r
->height
/ (i
!= 0 ? vsub
: 1);
2444 unsigned int cpp
= drm_format_plane_cpp(r
->pixel_format
, i
);
2446 if (!r
->handles
[i
]) {
2447 DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i
);
2451 if ((uint64_t) width
* cpp
> UINT_MAX
)
2454 if ((uint64_t) height
* r
->pitches
[i
] + r
->offsets
[i
] > UINT_MAX
)
2457 if (r
->pitches
[i
] < width
* cpp
) {
2458 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r
->pitches
[i
], i
);
2467 * drm_mode_addfb2 - add an FB to the graphics configuration
2468 * @dev: drm device for the ioctl
2469 * @data: data pointer for the ioctl
2470 * @file_priv: drm file for the ioctl call
2472 * Add a new FB to the specified CRTC, given a user request with format.
2474 * Called by the user via ioctl.
2477 * Zero on success, errno on failure.
2479 int drm_mode_addfb2(struct drm_device
*dev
,
2480 void *data
, struct drm_file
*file_priv
)
2482 struct drm_mode_fb_cmd2
*r
= data
;
2483 struct drm_mode_config
*config
= &dev
->mode_config
;
2484 struct drm_framebuffer
*fb
;
2487 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2490 if (r
->flags
& ~DRM_MODE_FB_INTERLACED
) {
2491 DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r
->flags
);
2495 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
2496 DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
2497 r
->width
, config
->min_width
, config
->max_width
);
2500 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
2501 DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
2502 r
->height
, config
->min_height
, config
->max_height
);
2506 ret
= framebuffer_check(r
);
2510 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
2512 DRM_DEBUG_KMS("could not create framebuffer\n");
2513 drm_modeset_unlock_all(dev
);
2517 mutex_lock(&file_priv
->fbs_lock
);
2518 r
->fb_id
= fb
->base
.id
;
2519 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2520 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2521 mutex_unlock(&file_priv
->fbs_lock
);
2528 * drm_mode_rmfb - remove an FB from the configuration
2529 * @dev: drm device for the ioctl
2530 * @data: data pointer for the ioctl
2531 * @file_priv: drm file for the ioctl call
2533 * Remove the FB specified by the user.
2535 * Called by the user via ioctl.
2538 * Zero on success, errno on failure.
2540 int drm_mode_rmfb(struct drm_device
*dev
,
2541 void *data
, struct drm_file
*file_priv
)
2543 struct drm_framebuffer
*fb
= NULL
;
2544 struct drm_framebuffer
*fbl
= NULL
;
2545 uint32_t *id
= data
;
2548 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2551 mutex_lock(&file_priv
->fbs_lock
);
2552 mutex_lock(&dev
->mode_config
.fb_lock
);
2553 fb
= __drm_framebuffer_lookup(dev
, *id
);
2557 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
2563 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2564 __drm_framebuffer_unregister(dev
, fb
);
2566 list_del_init(&fb
->filp_head
);
2567 mutex_unlock(&dev
->mode_config
.fb_lock
);
2568 mutex_unlock(&file_priv
->fbs_lock
);
2570 drm_framebuffer_remove(fb
);
2575 mutex_unlock(&dev
->mode_config
.fb_lock
);
2576 mutex_unlock(&file_priv
->fbs_lock
);
2582 * drm_mode_getfb - get FB info
2583 * @dev: drm device for the ioctl
2584 * @data: data pointer for the ioctl
2585 * @file_priv: drm file for the ioctl call
2587 * Lookup the FB given its ID and return info about it.
2589 * Called by the user via ioctl.
2592 * Zero on success, errno on failure.
2594 int drm_mode_getfb(struct drm_device
*dev
,
2595 void *data
, struct drm_file
*file_priv
)
2597 struct drm_mode_fb_cmd
*r
= data
;
2598 struct drm_framebuffer
*fb
;
2601 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2604 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2608 r
->height
= fb
->height
;
2609 r
->width
= fb
->width
;
2610 r
->depth
= fb
->depth
;
2611 r
->bpp
= fb
->bits_per_pixel
;
2612 r
->pitch
= fb
->pitches
[0];
2613 if (fb
->funcs
->create_handle
)
2614 ret
= fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
2618 drm_framebuffer_unreference(fb
);
2623 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2624 void *data
, struct drm_file
*file_priv
)
2626 struct drm_clip_rect __user
*clips_ptr
;
2627 struct drm_clip_rect
*clips
= NULL
;
2628 struct drm_mode_fb_dirty_cmd
*r
= data
;
2629 struct drm_framebuffer
*fb
;
2634 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2637 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2641 num_clips
= r
->num_clips
;
2642 clips_ptr
= (struct drm_clip_rect __user
*)(unsigned long)r
->clips_ptr
;
2644 if (!num_clips
!= !clips_ptr
) {
2649 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
2651 /* If userspace annotates copy, clips must come in pairs */
2652 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
2657 if (num_clips
&& clips_ptr
) {
2658 if (num_clips
< 0 || num_clips
> DRM_MODE_FB_DIRTY_MAX_CLIPS
) {
2662 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
2668 ret
= copy_from_user(clips
, clips_ptr
,
2669 num_clips
* sizeof(*clips
));
2676 if (fb
->funcs
->dirty
) {
2677 drm_modeset_lock_all(dev
);
2678 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
2680 drm_modeset_unlock_all(dev
);
2688 drm_framebuffer_unreference(fb
);
2695 * drm_fb_release - remove and free the FBs on this file
2696 * @priv: drm file for the ioctl
2698 * Destroy all the FBs associated with @filp.
2700 * Called by the user via ioctl.
2703 * Zero on success, errno on failure.
2705 void drm_fb_release(struct drm_file
*priv
)
2707 struct drm_device
*dev
= priv
->minor
->dev
;
2708 struct drm_framebuffer
*fb
, *tfb
;
2710 mutex_lock(&priv
->fbs_lock
);
2711 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
2713 mutex_lock(&dev
->mode_config
.fb_lock
);
2714 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2715 __drm_framebuffer_unregister(dev
, fb
);
2716 mutex_unlock(&dev
->mode_config
.fb_lock
);
2718 list_del_init(&fb
->filp_head
);
2720 /* This will also drop the fpriv->fbs reference. */
2721 drm_framebuffer_remove(fb
);
2723 mutex_unlock(&priv
->fbs_lock
);
2727 * drm_mode_attachmode - add a mode to the user mode list
2729 * @connector: connector to add the mode to
2730 * @mode: mode to add
2732 * Add @mode to @connector's user mode list.
2734 static void drm_mode_attachmode(struct drm_device
*dev
,
2735 struct drm_connector
*connector
,
2736 struct drm_display_mode
*mode
)
2738 list_add_tail(&mode
->head
, &connector
->user_modes
);
2741 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
2742 const struct drm_display_mode
*mode
)
2744 struct drm_connector
*connector
;
2746 struct drm_display_mode
*dup_mode
, *next
;
2749 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2750 if (!connector
->encoder
)
2752 if (connector
->encoder
->crtc
== crtc
) {
2753 dup_mode
= drm_mode_duplicate(dev
, mode
);
2758 list_add_tail(&dup_mode
->head
, &list
);
2762 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2763 if (!connector
->encoder
)
2765 if (connector
->encoder
->crtc
== crtc
)
2766 list_move_tail(list
.next
, &connector
->user_modes
);
2769 WARN_ON(!list_empty(&list
));
2772 list_for_each_entry_safe(dup_mode
, next
, &list
, head
)
2773 drm_mode_destroy(dev
, dup_mode
);
2777 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
2779 static int drm_mode_detachmode(struct drm_device
*dev
,
2780 struct drm_connector
*connector
,
2781 struct drm_display_mode
*mode
)
2785 struct drm_display_mode
*match_mode
, *t
;
2787 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
2788 if (drm_mode_equal(match_mode
, mode
)) {
2789 list_del(&match_mode
->head
);
2790 drm_mode_destroy(dev
, match_mode
);
2802 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
2804 struct drm_connector
*connector
;
2806 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2807 drm_mode_detachmode(dev
, connector
, mode
);
2811 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
2814 * drm_fb_attachmode - Attach a user mode to an connector
2815 * @dev: drm device for the ioctl
2816 * @data: data pointer for the ioctl
2817 * @file_priv: drm file for the ioctl call
2819 * This attaches a user specified mode to an connector.
2820 * Called by the user via ioctl.
2823 * Zero on success, errno on failure.
2825 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
2826 void *data
, struct drm_file
*file_priv
)
2828 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2829 struct drm_connector
*connector
;
2830 struct drm_display_mode
*mode
;
2831 struct drm_mode_object
*obj
;
2832 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2835 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2838 drm_modeset_lock_all(dev
);
2840 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2845 connector
= obj_to_connector(obj
);
2847 mode
= drm_mode_create(dev
);
2853 ret
= drm_crtc_convert_umode(mode
, umode
);
2855 DRM_DEBUG_KMS("Invalid mode\n");
2856 drm_mode_destroy(dev
, mode
);
2860 drm_mode_attachmode(dev
, connector
, mode
);
2862 drm_modeset_unlock_all(dev
);
2868 * drm_fb_detachmode - Detach a user specified mode from an connector
2869 * @dev: drm device for the ioctl
2870 * @data: data pointer for the ioctl
2871 * @file_priv: drm file for the ioctl call
2873 * Called by the user via ioctl.
2876 * Zero on success, errno on failure.
2878 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
2879 void *data
, struct drm_file
*file_priv
)
2881 struct drm_mode_object
*obj
;
2882 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2883 struct drm_connector
*connector
;
2884 struct drm_display_mode mode
;
2885 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2888 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2891 drm_modeset_lock_all(dev
);
2893 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2898 connector
= obj_to_connector(obj
);
2900 ret
= drm_crtc_convert_umode(&mode
, umode
);
2902 DRM_DEBUG_KMS("Invalid mode\n");
2906 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
2908 drm_modeset_unlock_all(dev
);
2912 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2913 const char *name
, int num_values
)
2915 struct drm_property
*property
= NULL
;
2918 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2923 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2924 if (!property
->values
)
2928 ret
= drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2932 property
->flags
= flags
;
2933 property
->num_values
= num_values
;
2934 INIT_LIST_HEAD(&property
->enum_blob_list
);
2937 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2938 property
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2941 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2944 kfree(property
->values
);
2948 EXPORT_SYMBOL(drm_property_create
);
2950 struct drm_property
*drm_property_create_enum(struct drm_device
*dev
, int flags
,
2952 const struct drm_prop_enum_list
*props
,
2955 struct drm_property
*property
;
2958 flags
|= DRM_MODE_PROP_ENUM
;
2960 property
= drm_property_create(dev
, flags
, name
, num_values
);
2964 for (i
= 0; i
< num_values
; i
++) {
2965 ret
= drm_property_add_enum(property
, i
,
2969 drm_property_destroy(dev
, property
);
2976 EXPORT_SYMBOL(drm_property_create_enum
);
2978 struct drm_property
*drm_property_create_bitmask(struct drm_device
*dev
,
2979 int flags
, const char *name
,
2980 const struct drm_prop_enum_list
*props
,
2983 struct drm_property
*property
;
2986 flags
|= DRM_MODE_PROP_BITMASK
;
2988 property
= drm_property_create(dev
, flags
, name
, num_values
);
2992 for (i
= 0; i
< num_values
; i
++) {
2993 ret
= drm_property_add_enum(property
, i
,
2997 drm_property_destroy(dev
, property
);
3004 EXPORT_SYMBOL(drm_property_create_bitmask
);
3006 struct drm_property
*drm_property_create_range(struct drm_device
*dev
, int flags
,
3008 uint64_t min
, uint64_t max
)
3010 struct drm_property
*property
;
3012 flags
|= DRM_MODE_PROP_RANGE
;
3014 property
= drm_property_create(dev
, flags
, name
, 2);
3018 property
->values
[0] = min
;
3019 property
->values
[1] = max
;
3023 EXPORT_SYMBOL(drm_property_create_range
);
3025 int drm_property_add_enum(struct drm_property
*property
, int index
,
3026 uint64_t value
, const char *name
)
3028 struct drm_property_enum
*prop_enum
;
3030 if (!(property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)))
3034 * Bitmask enum properties have the additional constraint of values
3037 if ((property
->flags
& DRM_MODE_PROP_BITMASK
) && (value
> 63))
3040 if (!list_empty(&property
->enum_blob_list
)) {
3041 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
3042 if (prop_enum
->value
== value
) {
3043 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
3044 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
3050 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
3054 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
3055 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
3056 prop_enum
->value
= value
;
3058 property
->values
[index
] = value
;
3059 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
3062 EXPORT_SYMBOL(drm_property_add_enum
);
3064 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
3066 struct drm_property_enum
*prop_enum
, *pt
;
3068 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
3069 list_del(&prop_enum
->head
);
3073 if (property
->num_values
)
3074 kfree(property
->values
);
3075 drm_mode_object_put(dev
, &property
->base
);
3076 list_del(&property
->head
);
3079 EXPORT_SYMBOL(drm_property_destroy
);
3081 void drm_object_attach_property(struct drm_mode_object
*obj
,
3082 struct drm_property
*property
,
3085 int count
= obj
->properties
->count
;
3087 if (count
== DRM_OBJECT_MAX_PROPERTY
) {
3088 WARN(1, "Failed to attach object property (type: 0x%x). Please "
3089 "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time "
3090 "you see this message on the same object type.\n",
3095 obj
->properties
->ids
[count
] = property
->base
.id
;
3096 obj
->properties
->values
[count
] = init_val
;
3097 obj
->properties
->count
++;
3099 EXPORT_SYMBOL(drm_object_attach_property
);
3101 int drm_object_property_set_value(struct drm_mode_object
*obj
,
3102 struct drm_property
*property
, uint64_t val
)
3106 for (i
= 0; i
< obj
->properties
->count
; i
++) {
3107 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
3108 obj
->properties
->values
[i
] = val
;
3115 EXPORT_SYMBOL(drm_object_property_set_value
);
3117 int drm_object_property_get_value(struct drm_mode_object
*obj
,
3118 struct drm_property
*property
, uint64_t *val
)
3122 for (i
= 0; i
< obj
->properties
->count
; i
++) {
3123 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
3124 *val
= obj
->properties
->values
[i
];
3131 EXPORT_SYMBOL(drm_object_property_get_value
);
3133 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
3134 void *data
, struct drm_file
*file_priv
)
3136 struct drm_mode_object
*obj
;
3137 struct drm_mode_get_property
*out_resp
= data
;
3138 struct drm_property
*property
;
3141 int value_count
= 0;
3144 struct drm_property_enum
*prop_enum
;
3145 struct drm_mode_property_enum __user
*enum_ptr
;
3146 struct drm_property_blob
*prop_blob
;
3147 uint32_t __user
*blob_id_ptr
;
3148 uint64_t __user
*values_ptr
;
3149 uint32_t __user
*blob_length_ptr
;
3151 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3154 drm_modeset_lock_all(dev
);
3155 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
3160 property
= obj_to_property(obj
);
3162 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
3163 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
3165 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3166 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
3170 value_count
= property
->num_values
;
3172 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
3173 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
3174 out_resp
->flags
= property
->flags
;
3176 if ((out_resp
->count_values
>= value_count
) && value_count
) {
3177 values_ptr
= (uint64_t __user
*)(unsigned long)out_resp
->values_ptr
;
3178 for (i
= 0; i
< value_count
; i
++) {
3179 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
3185 out_resp
->count_values
= value_count
;
3187 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
3188 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
3190 enum_ptr
= (struct drm_mode_property_enum __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3191 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
3193 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
3198 if (copy_to_user(&enum_ptr
[copied
].name
,
3199 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
3206 out_resp
->count_enum_blobs
= enum_count
;
3209 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3210 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
3212 blob_id_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3213 blob_length_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->values_ptr
;
3215 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
3216 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
3221 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
3229 out_resp
->count_enum_blobs
= blob_count
;
3232 drm_modeset_unlock_all(dev
);
3236 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
3239 struct drm_property_blob
*blob
;
3242 if (!length
|| !data
)
3245 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
3249 ret
= drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
3255 blob
->length
= length
;
3257 memcpy(blob
->data
, data
, length
);
3259 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
3263 static void drm_property_destroy_blob(struct drm_device
*dev
,
3264 struct drm_property_blob
*blob
)
3266 drm_mode_object_put(dev
, &blob
->base
);
3267 list_del(&blob
->head
);
3271 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
3272 void *data
, struct drm_file
*file_priv
)
3274 struct drm_mode_object
*obj
;
3275 struct drm_mode_get_blob
*out_resp
= data
;
3276 struct drm_property_blob
*blob
;
3278 void __user
*blob_ptr
;
3280 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3283 drm_modeset_lock_all(dev
);
3284 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
3289 blob
= obj_to_blob(obj
);
3291 if (out_resp
->length
== blob
->length
) {
3292 blob_ptr
= (void __user
*)(unsigned long)out_resp
->data
;
3293 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
3298 out_resp
->length
= blob
->length
;
3301 drm_modeset_unlock_all(dev
);
3305 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
3308 struct drm_device
*dev
= connector
->dev
;
3311 if (connector
->edid_blob_ptr
)
3312 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
3314 /* Delete edid, when there is none. */
3316 connector
->edid_blob_ptr
= NULL
;
3317 ret
= drm_object_property_set_value(&connector
->base
, dev
->mode_config
.edid_property
, 0);
3321 size
= EDID_LENGTH
* (1 + edid
->extensions
);
3322 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
3324 if (!connector
->edid_blob_ptr
)
3327 ret
= drm_object_property_set_value(&connector
->base
,
3328 dev
->mode_config
.edid_property
,
3329 connector
->edid_blob_ptr
->base
.id
);
3333 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
3335 static bool drm_property_change_is_valid(struct drm_property
*property
,
3338 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
3340 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
3341 if (value
< property
->values
[0] || value
> property
->values
[1])
3344 } else if (property
->flags
& DRM_MODE_PROP_BITMASK
) {
3346 uint64_t valid_mask
= 0;
3347 for (i
= 0; i
< property
->num_values
; i
++)
3348 valid_mask
|= (1ULL << property
->values
[i
]);
3349 return !(value
& ~valid_mask
);
3350 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3351 /* Only the driver knows */
3355 for (i
= 0; i
< property
->num_values
; i
++)
3356 if (property
->values
[i
] == value
)
3362 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
3363 void *data
, struct drm_file
*file_priv
)
3365 struct drm_mode_connector_set_property
*conn_set_prop
= data
;
3366 struct drm_mode_obj_set_property obj_set_prop
= {
3367 .value
= conn_set_prop
->value
,
3368 .prop_id
= conn_set_prop
->prop_id
,
3369 .obj_id
= conn_set_prop
->connector_id
,
3370 .obj_type
= DRM_MODE_OBJECT_CONNECTOR
3373 /* It does all the locking and checking we need */
3374 return drm_mode_obj_set_property_ioctl(dev
, &obj_set_prop
, file_priv
);
3377 static int drm_mode_connector_set_obj_prop(struct drm_mode_object
*obj
,
3378 struct drm_property
*property
,
3382 struct drm_connector
*connector
= obj_to_connector(obj
);
3384 /* Do DPMS ourselves */
3385 if (property
== connector
->dev
->mode_config
.dpms_property
) {
3386 if (connector
->funcs
->dpms
)
3387 (*connector
->funcs
->dpms
)(connector
, (int)value
);
3389 } else if (connector
->funcs
->set_property
)
3390 ret
= connector
->funcs
->set_property(connector
, property
, value
);
3392 /* store the property value if successful */
3394 drm_object_property_set_value(&connector
->base
, property
, value
);
3398 static int drm_mode_crtc_set_obj_prop(struct drm_mode_object
*obj
,
3399 struct drm_property
*property
,
3403 struct drm_crtc
*crtc
= obj_to_crtc(obj
);
3405 if (crtc
->funcs
->set_property
)
3406 ret
= crtc
->funcs
->set_property(crtc
, property
, value
);
3408 drm_object_property_set_value(obj
, property
, value
);
3413 static int drm_mode_plane_set_obj_prop(struct drm_mode_object
*obj
,
3414 struct drm_property
*property
,
3418 struct drm_plane
*plane
= obj_to_plane(obj
);
3420 if (plane
->funcs
->set_property
)
3421 ret
= plane
->funcs
->set_property(plane
, property
, value
);
3423 drm_object_property_set_value(obj
, property
, value
);
3428 int drm_mode_obj_get_properties_ioctl(struct drm_device
*dev
, void *data
,
3429 struct drm_file
*file_priv
)
3431 struct drm_mode_obj_get_properties
*arg
= data
;
3432 struct drm_mode_object
*obj
;
3436 int props_count
= 0;
3437 uint32_t __user
*props_ptr
;
3438 uint64_t __user
*prop_values_ptr
;
3440 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3443 drm_modeset_lock_all(dev
);
3445 obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3450 if (!obj
->properties
) {
3455 props_count
= obj
->properties
->count
;
3457 /* This ioctl is called twice, once to determine how much space is
3458 * needed, and the 2nd time to fill it. */
3459 if ((arg
->count_props
>= props_count
) && props_count
) {
3461 props_ptr
= (uint32_t __user
*)(unsigned long)(arg
->props_ptr
);
3462 prop_values_ptr
= (uint64_t __user
*)(unsigned long)
3463 (arg
->prop_values_ptr
);
3464 for (i
= 0; i
< props_count
; i
++) {
3465 if (put_user(obj
->properties
->ids
[i
],
3466 props_ptr
+ copied
)) {
3470 if (put_user(obj
->properties
->values
[i
],
3471 prop_values_ptr
+ copied
)) {
3478 arg
->count_props
= props_count
;
3480 drm_modeset_unlock_all(dev
);
3484 int drm_mode_obj_set_property_ioctl(struct drm_device
*dev
, void *data
,
3485 struct drm_file
*file_priv
)
3487 struct drm_mode_obj_set_property
*arg
= data
;
3488 struct drm_mode_object
*arg_obj
;
3489 struct drm_mode_object
*prop_obj
;
3490 struct drm_property
*property
;
3494 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3497 drm_modeset_lock_all(dev
);
3499 arg_obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3502 if (!arg_obj
->properties
)
3505 for (i
= 0; i
< arg_obj
->properties
->count
; i
++)
3506 if (arg_obj
->properties
->ids
[i
] == arg
->prop_id
)
3509 if (i
== arg_obj
->properties
->count
)
3512 prop_obj
= drm_mode_object_find(dev
, arg
->prop_id
,
3513 DRM_MODE_OBJECT_PROPERTY
);
3516 property
= obj_to_property(prop_obj
);
3518 if (!drm_property_change_is_valid(property
, arg
->value
))
3521 switch (arg_obj
->type
) {
3522 case DRM_MODE_OBJECT_CONNECTOR
:
3523 ret
= drm_mode_connector_set_obj_prop(arg_obj
, property
,
3526 case DRM_MODE_OBJECT_CRTC
:
3527 ret
= drm_mode_crtc_set_obj_prop(arg_obj
, property
, arg
->value
);
3529 case DRM_MODE_OBJECT_PLANE
:
3530 ret
= drm_mode_plane_set_obj_prop(arg_obj
, property
, arg
->value
);
3535 drm_modeset_unlock_all(dev
);
3539 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
3540 struct drm_encoder
*encoder
)
3544 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3545 if (connector
->encoder_ids
[i
] == 0) {
3546 connector
->encoder_ids
[i
] = encoder
->base
.id
;
3552 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
3554 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
3555 struct drm_encoder
*encoder
)
3558 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3559 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
3560 connector
->encoder_ids
[i
] = 0;
3561 if (connector
->encoder
== encoder
)
3562 connector
->encoder
= NULL
;
3567 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
3569 int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
3572 crtc
->gamma_size
= gamma_size
;
3574 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
3575 if (!crtc
->gamma_store
) {
3576 crtc
->gamma_size
= 0;
3582 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
3584 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
3585 void *data
, struct drm_file
*file_priv
)
3587 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3588 struct drm_mode_object
*obj
;
3589 struct drm_crtc
*crtc
;
3590 void *r_base
, *g_base
, *b_base
;
3594 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3597 drm_modeset_lock_all(dev
);
3598 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3603 crtc
= obj_to_crtc(obj
);
3605 if (crtc
->funcs
->gamma_set
== NULL
) {
3610 /* memcpy into gamma store */
3611 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3616 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3617 r_base
= crtc
->gamma_store
;
3618 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
3623 g_base
= r_base
+ size
;
3624 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
3629 b_base
= g_base
+ size
;
3630 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
3635 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
3638 drm_modeset_unlock_all(dev
);
3643 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
3644 void *data
, struct drm_file
*file_priv
)
3646 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3647 struct drm_mode_object
*obj
;
3648 struct drm_crtc
*crtc
;
3649 void *r_base
, *g_base
, *b_base
;
3653 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3656 drm_modeset_lock_all(dev
);
3657 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3662 crtc
= obj_to_crtc(obj
);
3664 /* memcpy into gamma store */
3665 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3670 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3671 r_base
= crtc
->gamma_store
;
3672 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
3677 g_base
= r_base
+ size
;
3678 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
3683 b_base
= g_base
+ size
;
3684 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
3689 drm_modeset_unlock_all(dev
);
3693 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
3694 void *data
, struct drm_file
*file_priv
)
3696 struct drm_mode_crtc_page_flip
*page_flip
= data
;
3697 struct drm_mode_object
*obj
;
3698 struct drm_crtc
*crtc
;
3699 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
3700 struct drm_pending_vblank_event
*e
= NULL
;
3701 unsigned long flags
;
3702 int hdisplay
, vdisplay
;
3705 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
3706 page_flip
->reserved
!= 0)
3709 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3712 crtc
= obj_to_crtc(obj
);
3714 mutex_lock(&crtc
->mutex
);
3715 if (crtc
->fb
== NULL
) {
3716 /* The framebuffer is currently unbound, presumably
3717 * due to a hotplug event, that userspace has not
3724 if (crtc
->funcs
->page_flip
== NULL
)
3727 fb
= drm_framebuffer_lookup(dev
, page_flip
->fb_id
);
3731 hdisplay
= crtc
->mode
.hdisplay
;
3732 vdisplay
= crtc
->mode
.vdisplay
;
3734 if (crtc
->invert_dimensions
)
3735 swap(hdisplay
, vdisplay
);
3737 if (hdisplay
> fb
->width
||
3738 vdisplay
> fb
->height
||
3739 crtc
->x
> fb
->width
- hdisplay
||
3740 crtc
->y
> fb
->height
- vdisplay
) {
3741 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
3742 fb
->width
, fb
->height
, hdisplay
, vdisplay
, crtc
->x
, crtc
->y
,
3743 crtc
->invert_dimensions
? " (inverted)" : "");
3748 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3750 spin_lock_irqsave(&dev
->event_lock
, flags
);
3751 if (file_priv
->event_space
< sizeof e
->event
) {
3752 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3755 file_priv
->event_space
-= sizeof e
->event
;
3756 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3758 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
3760 spin_lock_irqsave(&dev
->event_lock
, flags
);
3761 file_priv
->event_space
+= sizeof e
->event
;
3762 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3766 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
3767 e
->event
.base
.length
= sizeof e
->event
;
3768 e
->event
.user_data
= page_flip
->user_data
;
3769 e
->base
.event
= &e
->event
.base
;
3770 e
->base
.file_priv
= file_priv
;
3772 (void (*) (struct drm_pending_event
*)) kfree
;
3776 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
);
3778 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3779 spin_lock_irqsave(&dev
->event_lock
, flags
);
3780 file_priv
->event_space
+= sizeof e
->event
;
3781 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3784 /* Keep the old fb, don't unref it. */
3788 * Warn if the driver hasn't properly updated the crtc->fb
3789 * field to reflect that the new framebuffer is now used.
3790 * Failing to do so will screw with the reference counting
3793 WARN_ON(crtc
->fb
!= fb
);
3794 /* Unref only the old framebuffer. */
3800 drm_framebuffer_unreference(fb
);
3802 drm_framebuffer_unreference(old_fb
);
3803 mutex_unlock(&crtc
->mutex
);
3808 void drm_mode_config_reset(struct drm_device
*dev
)
3810 struct drm_crtc
*crtc
;
3811 struct drm_encoder
*encoder
;
3812 struct drm_connector
*connector
;
3814 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
3815 if (crtc
->funcs
->reset
)
3816 crtc
->funcs
->reset(crtc
);
3818 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
3819 if (encoder
->funcs
->reset
)
3820 encoder
->funcs
->reset(encoder
);
3822 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
3823 connector
->status
= connector_status_unknown
;
3825 if (connector
->funcs
->reset
)
3826 connector
->funcs
->reset(connector
);
3829 EXPORT_SYMBOL(drm_mode_config_reset
);
3831 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
3832 void *data
, struct drm_file
*file_priv
)
3834 struct drm_mode_create_dumb
*args
= data
;
3836 if (!dev
->driver
->dumb_create
)
3838 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
3841 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
3842 void *data
, struct drm_file
*file_priv
)
3844 struct drm_mode_map_dumb
*args
= data
;
3846 /* call driver ioctl to get mmap offset */
3847 if (!dev
->driver
->dumb_map_offset
)
3850 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
3853 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
3854 void *data
, struct drm_file
*file_priv
)
3856 struct drm_mode_destroy_dumb
*args
= data
;
3858 if (!dev
->driver
->dumb_destroy
)
3861 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
3865 * Just need to support RGB formats here for compat with code that doesn't
3866 * use pixel formats directly yet.
3868 void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
3873 case DRM_FORMAT_RGB332
:
3874 case DRM_FORMAT_BGR233
:
3878 case DRM_FORMAT_XRGB1555
:
3879 case DRM_FORMAT_XBGR1555
:
3880 case DRM_FORMAT_RGBX5551
:
3881 case DRM_FORMAT_BGRX5551
:
3882 case DRM_FORMAT_ARGB1555
:
3883 case DRM_FORMAT_ABGR1555
:
3884 case DRM_FORMAT_RGBA5551
:
3885 case DRM_FORMAT_BGRA5551
:
3889 case DRM_FORMAT_RGB565
:
3890 case DRM_FORMAT_BGR565
:
3894 case DRM_FORMAT_RGB888
:
3895 case DRM_FORMAT_BGR888
:
3899 case DRM_FORMAT_XRGB8888
:
3900 case DRM_FORMAT_XBGR8888
:
3901 case DRM_FORMAT_RGBX8888
:
3902 case DRM_FORMAT_BGRX8888
:
3906 case DRM_FORMAT_XRGB2101010
:
3907 case DRM_FORMAT_XBGR2101010
:
3908 case DRM_FORMAT_RGBX1010102
:
3909 case DRM_FORMAT_BGRX1010102
:
3910 case DRM_FORMAT_ARGB2101010
:
3911 case DRM_FORMAT_ABGR2101010
:
3912 case DRM_FORMAT_RGBA1010102
:
3913 case DRM_FORMAT_BGRA1010102
:
3917 case DRM_FORMAT_ARGB8888
:
3918 case DRM_FORMAT_ABGR8888
:
3919 case DRM_FORMAT_RGBA8888
:
3920 case DRM_FORMAT_BGRA8888
:
3925 DRM_DEBUG_KMS("unsupported pixel format\n");
3931 EXPORT_SYMBOL(drm_fb_get_bpp_depth
);
3934 * drm_format_num_planes - get the number of planes for format
3935 * @format: pixel format (DRM_FORMAT_*)
3938 * The number of planes used by the specified pixel format.
3940 int drm_format_num_planes(uint32_t format
)
3943 case DRM_FORMAT_YUV410
:
3944 case DRM_FORMAT_YVU410
:
3945 case DRM_FORMAT_YUV411
:
3946 case DRM_FORMAT_YVU411
:
3947 case DRM_FORMAT_YUV420
:
3948 case DRM_FORMAT_YVU420
:
3949 case DRM_FORMAT_YUV422
:
3950 case DRM_FORMAT_YVU422
:
3951 case DRM_FORMAT_YUV444
:
3952 case DRM_FORMAT_YVU444
:
3954 case DRM_FORMAT_NV12
:
3955 case DRM_FORMAT_NV21
:
3956 case DRM_FORMAT_NV16
:
3957 case DRM_FORMAT_NV61
:
3958 case DRM_FORMAT_NV24
:
3959 case DRM_FORMAT_NV42
:
3965 EXPORT_SYMBOL(drm_format_num_planes
);
3968 * drm_format_plane_cpp - determine the bytes per pixel value
3969 * @format: pixel format (DRM_FORMAT_*)
3970 * @plane: plane index
3973 * The bytes per pixel value for the specified plane.
3975 int drm_format_plane_cpp(uint32_t format
, int plane
)
3980 if (plane
>= drm_format_num_planes(format
))
3984 case DRM_FORMAT_YUYV
:
3985 case DRM_FORMAT_YVYU
:
3986 case DRM_FORMAT_UYVY
:
3987 case DRM_FORMAT_VYUY
:
3989 case DRM_FORMAT_NV12
:
3990 case DRM_FORMAT_NV21
:
3991 case DRM_FORMAT_NV16
:
3992 case DRM_FORMAT_NV61
:
3993 case DRM_FORMAT_NV24
:
3994 case DRM_FORMAT_NV42
:
3995 return plane
? 2 : 1;
3996 case DRM_FORMAT_YUV410
:
3997 case DRM_FORMAT_YVU410
:
3998 case DRM_FORMAT_YUV411
:
3999 case DRM_FORMAT_YVU411
:
4000 case DRM_FORMAT_YUV420
:
4001 case DRM_FORMAT_YVU420
:
4002 case DRM_FORMAT_YUV422
:
4003 case DRM_FORMAT_YVU422
:
4004 case DRM_FORMAT_YUV444
:
4005 case DRM_FORMAT_YVU444
:
4008 drm_fb_get_bpp_depth(format
, &depth
, &bpp
);
4012 EXPORT_SYMBOL(drm_format_plane_cpp
);
4015 * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
4016 * @format: pixel format (DRM_FORMAT_*)
4019 * The horizontal chroma subsampling factor for the
4020 * specified pixel format.
4022 int drm_format_horz_chroma_subsampling(uint32_t format
)
4025 case DRM_FORMAT_YUV411
:
4026 case DRM_FORMAT_YVU411
:
4027 case DRM_FORMAT_YUV410
:
4028 case DRM_FORMAT_YVU410
:
4030 case DRM_FORMAT_YUYV
:
4031 case DRM_FORMAT_YVYU
:
4032 case DRM_FORMAT_UYVY
:
4033 case DRM_FORMAT_VYUY
:
4034 case DRM_FORMAT_NV12
:
4035 case DRM_FORMAT_NV21
:
4036 case DRM_FORMAT_NV16
:
4037 case DRM_FORMAT_NV61
:
4038 case DRM_FORMAT_YUV422
:
4039 case DRM_FORMAT_YVU422
:
4040 case DRM_FORMAT_YUV420
:
4041 case DRM_FORMAT_YVU420
:
4047 EXPORT_SYMBOL(drm_format_horz_chroma_subsampling
);
4050 * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
4051 * @format: pixel format (DRM_FORMAT_*)
4054 * The vertical chroma subsampling factor for the
4055 * specified pixel format.
4057 int drm_format_vert_chroma_subsampling(uint32_t format
)
4060 case DRM_FORMAT_YUV410
:
4061 case DRM_FORMAT_YVU410
:
4063 case DRM_FORMAT_YUV420
:
4064 case DRM_FORMAT_YVU420
:
4065 case DRM_FORMAT_NV12
:
4066 case DRM_FORMAT_NV21
:
4072 EXPORT_SYMBOL(drm_format_vert_chroma_subsampling
);