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
);
73 /* Avoid boilerplate. I'm tired of typing. */
74 #define DRM_ENUM_NAME_FN(fnname, list) \
75 char *fnname(int val) \
78 for (i = 0; i < ARRAY_SIZE(list); i++) { \
79 if (list[i].type == val) \
80 return list[i].name; \
88 static struct drm_prop_enum_list drm_dpms_enum_list
[] =
89 { { DRM_MODE_DPMS_ON
, "On" },
90 { DRM_MODE_DPMS_STANDBY
, "Standby" },
91 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
92 { DRM_MODE_DPMS_OFF
, "Off" }
95 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
100 static struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
102 { DRM_MODE_SCALE_NONE
, "None" },
103 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
104 { DRM_MODE_SCALE_CENTER
, "Center" },
105 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
108 static struct drm_prop_enum_list drm_dithering_mode_enum_list
[] =
110 { DRM_MODE_DITHERING_OFF
, "Off" },
111 { DRM_MODE_DITHERING_ON
, "On" },
112 { DRM_MODE_DITHERING_AUTO
, "Automatic" },
116 * Non-global properties, but "required" for certain connectors.
118 static struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
120 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
121 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
122 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
125 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
127 static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
129 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
130 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
131 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
134 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
135 drm_dvi_i_subconnector_enum_list
)
137 static struct drm_prop_enum_list drm_tv_select_enum_list
[] =
139 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
140 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
141 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
142 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
143 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
146 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
148 static struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
150 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
151 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
152 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
153 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
154 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
157 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
158 drm_tv_subconnector_enum_list
)
160 static struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
161 { DRM_MODE_DIRTY_OFF
, "Off" },
162 { DRM_MODE_DIRTY_ON
, "On" },
163 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
166 DRM_ENUM_NAME_FN(drm_get_dirty_info_name
,
167 drm_dirty_info_enum_list
)
169 struct drm_conn_prop_enum_list
{
176 * Connector and encoder types.
178 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
179 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
180 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
181 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
182 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
183 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
184 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
185 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
186 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
187 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
188 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN", 0 },
189 { DRM_MODE_CONNECTOR_DisplayPort
, "DP", 0 },
190 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A", 0 },
191 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B", 0 },
192 { DRM_MODE_CONNECTOR_TV
, "TV", 0 },
193 { DRM_MODE_CONNECTOR_eDP
, "eDP", 0 },
194 { DRM_MODE_CONNECTOR_VIRTUAL
, "Virtual", 0},
197 static struct drm_prop_enum_list drm_encoder_enum_list
[] =
198 { { DRM_MODE_ENCODER_NONE
, "None" },
199 { DRM_MODE_ENCODER_DAC
, "DAC" },
200 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
201 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
202 { DRM_MODE_ENCODER_TVDAC
, "TV" },
203 { DRM_MODE_ENCODER_VIRTUAL
, "Virtual" },
206 char *drm_get_encoder_name(struct drm_encoder
*encoder
)
210 snprintf(buf
, 32, "%s-%d",
211 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
215 EXPORT_SYMBOL(drm_get_encoder_name
);
217 char *drm_get_connector_name(struct drm_connector
*connector
)
221 snprintf(buf
, 32, "%s-%d",
222 drm_connector_enum_list
[connector
->connector_type
].name
,
223 connector
->connector_type_id
);
226 EXPORT_SYMBOL(drm_get_connector_name
);
228 char *drm_get_connector_status_name(enum drm_connector_status status
)
230 if (status
== connector_status_connected
)
232 else if (status
== connector_status_disconnected
)
233 return "disconnected";
239 * drm_mode_object_get - allocate a new modeset identifier
241 * @obj: object pointer, used to generate unique ID
242 * @obj_type: object type
244 * Create a unique identifier based on @ptr in @dev's identifier space. Used
245 * for tracking modes, CRTCs and connectors.
248 * New unique (relative to other objects in @dev) integer identifier for the
251 static int drm_mode_object_get(struct drm_device
*dev
,
252 struct drm_mode_object
*obj
, uint32_t obj_type
)
258 if (idr_pre_get(&dev
->mode_config
.crtc_idr
, GFP_KERNEL
) == 0) {
259 DRM_ERROR("Ran out memory getting a mode number\n");
263 mutex_lock(&dev
->mode_config
.idr_mutex
);
264 ret
= idr_get_new_above(&dev
->mode_config
.crtc_idr
, obj
, 1, &new_id
);
268 * Set up the object linking under the protection of the idr
269 * lock so that other users can't see inconsistent state.
272 obj
->type
= obj_type
;
274 mutex_unlock(&dev
->mode_config
.idr_mutex
);
283 * drm_mode_object_put - free a modeset identifer
285 * @object: object to free
287 * Free @id from @dev's unique identifier pool.
289 static void drm_mode_object_put(struct drm_device
*dev
,
290 struct drm_mode_object
*object
)
292 mutex_lock(&dev
->mode_config
.idr_mutex
);
293 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
294 mutex_unlock(&dev
->mode_config
.idr_mutex
);
297 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
298 uint32_t id
, uint32_t type
)
300 struct drm_mode_object
*obj
= NULL
;
302 mutex_lock(&dev
->mode_config
.idr_mutex
);
303 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
304 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
306 mutex_unlock(&dev
->mode_config
.idr_mutex
);
310 EXPORT_SYMBOL(drm_mode_object_find
);
313 * drm_framebuffer_init - initialize a framebuffer
315 * @fb: framebuffer to be initialized
316 * @funcs: ... with these functions
318 * Allocates an ID for the framebuffer's parent mode object, sets its mode
319 * functions & device file and adds it to the master fd list.
322 * This functions publishes the fb and makes it available for concurrent access
323 * by other users. Which means by this point the fb _must_ be fully set up -
324 * since all the fb attributes are invariant over its lifetime, no further
325 * locking but only correct reference counting is required.
328 * Zero on success, error code on failure.
330 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
331 const struct drm_framebuffer_funcs
*funcs
)
335 mutex_lock(&dev
->mode_config
.fb_lock
);
336 kref_init(&fb
->refcount
);
337 INIT_LIST_HEAD(&fb
->filp_head
);
341 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
345 dev
->mode_config
.num_fb
++;
346 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
348 mutex_unlock(&dev
->mode_config
.fb_lock
);
352 EXPORT_SYMBOL(drm_framebuffer_init
);
354 static void drm_framebuffer_free(struct kref
*kref
)
356 struct drm_framebuffer
*fb
=
357 container_of(kref
, struct drm_framebuffer
, refcount
);
358 fb
->funcs
->destroy(fb
);
362 * drm_framebuffer_unreference - unref a framebuffer
363 * @fb: framebuffer to unref
365 * This functions decrements the fb's refcount and frees it if it drops to zero.
367 void drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
369 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
370 kref_put(&fb
->refcount
, drm_framebuffer_free
);
372 EXPORT_SYMBOL(drm_framebuffer_unreference
);
375 * drm_framebuffer_reference - incr the fb refcnt
378 void drm_framebuffer_reference(struct drm_framebuffer
*fb
)
380 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
381 kref_get(&fb
->refcount
);
383 EXPORT_SYMBOL(drm_framebuffer_reference
);
386 * drm_framebuffer_cleanup - remove a framebuffer object
387 * @fb: framebuffer to remove
389 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes
390 * it, setting it to NULL.
392 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
394 struct drm_device
*dev
= fb
->dev
;
397 * This could be moved to drm_framebuffer_remove(), but for
398 * debugging is nice to keep around the list of fb's that are
399 * no longer associated w/ a drm_file but are not unreferenced
400 * yet. (i915 and omapdrm have debugfs files which will show
403 drm_mode_object_put(dev
, &fb
->base
);
404 mutex_lock(&dev
->mode_config
.fb_lock
);
406 dev
->mode_config
.num_fb
--;
407 mutex_unlock(&dev
->mode_config
.fb_lock
);
409 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
412 * drm_framebuffer_remove - remove and unreference a framebuffer object
413 * @fb: framebuffer to remove
415 * Scans all the CRTCs and planes in @dev's mode_config. If they're
416 * using @fb, removes it, setting it to NULL.
418 void drm_framebuffer_remove(struct drm_framebuffer
*fb
)
420 struct drm_device
*dev
= fb
->dev
;
421 struct drm_crtc
*crtc
;
422 struct drm_plane
*plane
;
423 struct drm_mode_set set
;
426 WARN_ON(!drm_modeset_is_locked(dev
));
427 WARN_ON(!list_empty(&fb
->filp_head
));
429 /* remove from any CRTC */
430 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
431 if (crtc
->fb
== fb
) {
432 /* should turn off the crtc */
433 memset(&set
, 0, sizeof(struct drm_mode_set
));
436 ret
= drm_mode_set_config_internal(&set
);
438 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
442 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
443 if (plane
->fb
== fb
) {
444 /* should turn off the crtc */
445 ret
= plane
->funcs
->disable_plane(plane
);
447 DRM_ERROR("failed to disable plane with busy fb\n");
448 /* disconnect the plane from the fb and crtc: */
454 drm_framebuffer_unreference(fb
);
456 EXPORT_SYMBOL(drm_framebuffer_remove
);
459 * drm_crtc_init - Initialise a new CRTC object
461 * @crtc: CRTC object to init
462 * @funcs: callbacks for the new CRTC
464 * Inits a new object created as base part of an driver crtc object.
467 * Zero on success, error code on failure.
469 int drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
470 const struct drm_crtc_funcs
*funcs
)
476 crtc
->invert_dimensions
= false;
478 drm_modeset_lock_all(dev
);
479 mutex_init(&crtc
->mutex
);
480 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
482 ret
= drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
486 crtc
->base
.properties
= &crtc
->properties
;
488 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
489 dev
->mode_config
.num_crtc
++;
492 drm_modeset_unlock_all(dev
);
496 EXPORT_SYMBOL(drm_crtc_init
);
499 * drm_crtc_cleanup - Cleans up the core crtc usage.
500 * @crtc: CRTC to cleanup
502 * Cleanup @crtc. Removes from drm modesetting space
503 * does NOT free object, caller does that.
505 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
507 struct drm_device
*dev
= crtc
->dev
;
509 kfree(crtc
->gamma_store
);
510 crtc
->gamma_store
= NULL
;
512 drm_mode_object_put(dev
, &crtc
->base
);
513 list_del(&crtc
->head
);
514 dev
->mode_config
.num_crtc
--;
516 EXPORT_SYMBOL(drm_crtc_cleanup
);
519 * drm_mode_probed_add - add a mode to a connector's probed mode list
520 * @connector: connector the new mode
523 * Add @mode to @connector's mode list for later use.
525 void drm_mode_probed_add(struct drm_connector
*connector
,
526 struct drm_display_mode
*mode
)
528 list_add(&mode
->head
, &connector
->probed_modes
);
530 EXPORT_SYMBOL(drm_mode_probed_add
);
533 * drm_mode_remove - remove and free a mode
534 * @connector: connector list to modify
535 * @mode: mode to remove
537 * Remove @mode from @connector's mode list, then free it.
539 void drm_mode_remove(struct drm_connector
*connector
,
540 struct drm_display_mode
*mode
)
542 list_del(&mode
->head
);
543 drm_mode_destroy(connector
->dev
, mode
);
545 EXPORT_SYMBOL(drm_mode_remove
);
548 * drm_connector_init - Init a preallocated connector
550 * @connector: the connector to init
551 * @funcs: callbacks for this connector
552 * @connector_type: user visible type of the connector
554 * Initialises a preallocated connector. Connectors should be
555 * subclassed as part of driver connector objects.
558 * Zero on success, error code on failure.
560 int drm_connector_init(struct drm_device
*dev
,
561 struct drm_connector
*connector
,
562 const struct drm_connector_funcs
*funcs
,
567 drm_modeset_lock_all(dev
);
569 ret
= drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
573 connector
->base
.properties
= &connector
->properties
;
574 connector
->dev
= dev
;
575 connector
->funcs
= funcs
;
576 connector
->connector_type
= connector_type
;
577 connector
->connector_type_id
=
578 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
579 INIT_LIST_HEAD(&connector
->user_modes
);
580 INIT_LIST_HEAD(&connector
->probed_modes
);
581 INIT_LIST_HEAD(&connector
->modes
);
582 connector
->edid_blob_ptr
= NULL
;
583 connector
->status
= connector_status_unknown
;
585 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
586 dev
->mode_config
.num_connector
++;
588 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
589 drm_object_attach_property(&connector
->base
,
590 dev
->mode_config
.edid_property
,
593 drm_object_attach_property(&connector
->base
,
594 dev
->mode_config
.dpms_property
, 0);
597 drm_modeset_unlock_all(dev
);
601 EXPORT_SYMBOL(drm_connector_init
);
604 * drm_connector_cleanup - cleans up an initialised connector
605 * @connector: connector to cleanup
607 * Cleans up the connector but doesn't free the object.
609 void drm_connector_cleanup(struct drm_connector
*connector
)
611 struct drm_device
*dev
= connector
->dev
;
612 struct drm_display_mode
*mode
, *t
;
614 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
615 drm_mode_remove(connector
, mode
);
617 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
618 drm_mode_remove(connector
, mode
);
620 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
621 drm_mode_remove(connector
, mode
);
623 drm_mode_object_put(dev
, &connector
->base
);
624 list_del(&connector
->head
);
625 dev
->mode_config
.num_connector
--;
627 EXPORT_SYMBOL(drm_connector_cleanup
);
629 void drm_connector_unplug_all(struct drm_device
*dev
)
631 struct drm_connector
*connector
;
633 /* taking the mode config mutex ends up in a clash with sysfs */
634 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
635 drm_sysfs_connector_remove(connector
);
638 EXPORT_SYMBOL(drm_connector_unplug_all
);
640 int drm_encoder_init(struct drm_device
*dev
,
641 struct drm_encoder
*encoder
,
642 const struct drm_encoder_funcs
*funcs
,
647 drm_modeset_lock_all(dev
);
649 ret
= drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
654 encoder
->encoder_type
= encoder_type
;
655 encoder
->funcs
= funcs
;
657 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
658 dev
->mode_config
.num_encoder
++;
661 drm_modeset_unlock_all(dev
);
665 EXPORT_SYMBOL(drm_encoder_init
);
667 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
669 struct drm_device
*dev
= encoder
->dev
;
670 drm_modeset_lock_all(dev
);
671 drm_mode_object_put(dev
, &encoder
->base
);
672 list_del(&encoder
->head
);
673 dev
->mode_config
.num_encoder
--;
674 drm_modeset_unlock_all(dev
);
676 EXPORT_SYMBOL(drm_encoder_cleanup
);
678 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
679 unsigned long possible_crtcs
,
680 const struct drm_plane_funcs
*funcs
,
681 const uint32_t *formats
, uint32_t format_count
,
686 drm_modeset_lock_all(dev
);
688 ret
= drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
692 plane
->base
.properties
= &plane
->properties
;
694 plane
->funcs
= funcs
;
695 plane
->format_types
= kmalloc(sizeof(uint32_t) * format_count
,
697 if (!plane
->format_types
) {
698 DRM_DEBUG_KMS("out of memory when allocating plane\n");
699 drm_mode_object_put(dev
, &plane
->base
);
704 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
705 plane
->format_count
= format_count
;
706 plane
->possible_crtcs
= possible_crtcs
;
708 /* private planes are not exposed to userspace, but depending on
709 * display hardware, might be convenient to allow sharing programming
710 * for the scanout engine with the crtc implementation.
713 list_add_tail(&plane
->head
, &dev
->mode_config
.plane_list
);
714 dev
->mode_config
.num_plane
++;
716 INIT_LIST_HEAD(&plane
->head
);
720 drm_modeset_unlock_all(dev
);
724 EXPORT_SYMBOL(drm_plane_init
);
726 void drm_plane_cleanup(struct drm_plane
*plane
)
728 struct drm_device
*dev
= plane
->dev
;
730 drm_modeset_lock_all(dev
);
731 kfree(plane
->format_types
);
732 drm_mode_object_put(dev
, &plane
->base
);
733 /* if not added to a list, it must be a private plane */
734 if (!list_empty(&plane
->head
)) {
735 list_del(&plane
->head
);
736 dev
->mode_config
.num_plane
--;
738 drm_modeset_unlock_all(dev
);
740 EXPORT_SYMBOL(drm_plane_cleanup
);
743 * drm_mode_create - create a new display mode
746 * Create a new drm_display_mode, give it an ID, and return it.
749 * Pointer to new mode on success, NULL on error.
751 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
753 struct drm_display_mode
*nmode
;
755 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
759 if (drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
)) {
766 EXPORT_SYMBOL(drm_mode_create
);
769 * drm_mode_destroy - remove a mode
771 * @mode: mode to remove
773 * Free @mode's unique identifier, then free it.
775 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
780 drm_mode_object_put(dev
, &mode
->base
);
784 EXPORT_SYMBOL(drm_mode_destroy
);
786 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
788 struct drm_property
*edid
;
789 struct drm_property
*dpms
;
792 * Standard properties (apply to all connectors)
794 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
795 DRM_MODE_PROP_IMMUTABLE
,
797 dev
->mode_config
.edid_property
= edid
;
799 dpms
= drm_property_create_enum(dev
, 0,
800 "DPMS", drm_dpms_enum_list
,
801 ARRAY_SIZE(drm_dpms_enum_list
));
802 dev
->mode_config
.dpms_property
= dpms
;
808 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
811 * Called by a driver the first time a DVI-I connector is made.
813 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
815 struct drm_property
*dvi_i_selector
;
816 struct drm_property
*dvi_i_subconnector
;
818 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
822 drm_property_create_enum(dev
, 0,
823 "select subconnector",
824 drm_dvi_i_select_enum_list
,
825 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
826 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
828 dvi_i_subconnector
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
830 drm_dvi_i_subconnector_enum_list
,
831 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
832 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
836 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
839 * drm_create_tv_properties - create TV specific connector properties
841 * @num_modes: number of different TV formats (modes) supported
842 * @modes: array of pointers to strings containing name of each format
844 * Called by a driver's TV initialization routine, this function creates
845 * the TV specific connector properties for a given device. Caller is
846 * responsible for allocating a list of format names and passing them to
849 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
852 struct drm_property
*tv_selector
;
853 struct drm_property
*tv_subconnector
;
856 if (dev
->mode_config
.tv_select_subconnector_property
)
860 * Basic connector properties
862 tv_selector
= drm_property_create_enum(dev
, 0,
863 "select subconnector",
864 drm_tv_select_enum_list
,
865 ARRAY_SIZE(drm_tv_select_enum_list
));
866 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
869 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
871 drm_tv_subconnector_enum_list
,
872 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
873 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
876 * Other, TV specific properties: margins & TV modes.
878 dev
->mode_config
.tv_left_margin_property
=
879 drm_property_create_range(dev
, 0, "left margin", 0, 100);
881 dev
->mode_config
.tv_right_margin_property
=
882 drm_property_create_range(dev
, 0, "right margin", 0, 100);
884 dev
->mode_config
.tv_top_margin_property
=
885 drm_property_create_range(dev
, 0, "top margin", 0, 100);
887 dev
->mode_config
.tv_bottom_margin_property
=
888 drm_property_create_range(dev
, 0, "bottom margin", 0, 100);
890 dev
->mode_config
.tv_mode_property
=
891 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
893 for (i
= 0; i
< num_modes
; i
++)
894 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
897 dev
->mode_config
.tv_brightness_property
=
898 drm_property_create_range(dev
, 0, "brightness", 0, 100);
900 dev
->mode_config
.tv_contrast_property
=
901 drm_property_create_range(dev
, 0, "contrast", 0, 100);
903 dev
->mode_config
.tv_flicker_reduction_property
=
904 drm_property_create_range(dev
, 0, "flicker reduction", 0, 100);
906 dev
->mode_config
.tv_overscan_property
=
907 drm_property_create_range(dev
, 0, "overscan", 0, 100);
909 dev
->mode_config
.tv_saturation_property
=
910 drm_property_create_range(dev
, 0, "saturation", 0, 100);
912 dev
->mode_config
.tv_hue_property
=
913 drm_property_create_range(dev
, 0, "hue", 0, 100);
917 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
920 * drm_mode_create_scaling_mode_property - create scaling mode property
923 * Called by a driver the first time it's needed, must be attached to desired
926 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
928 struct drm_property
*scaling_mode
;
930 if (dev
->mode_config
.scaling_mode_property
)
934 drm_property_create_enum(dev
, 0, "scaling mode",
935 drm_scaling_mode_enum_list
,
936 ARRAY_SIZE(drm_scaling_mode_enum_list
));
938 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
942 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
945 * drm_mode_create_dithering_property - create dithering property
948 * Called by a driver the first time it's needed, must be attached to desired
951 int drm_mode_create_dithering_property(struct drm_device
*dev
)
953 struct drm_property
*dithering_mode
;
955 if (dev
->mode_config
.dithering_mode_property
)
959 drm_property_create_enum(dev
, 0, "dithering",
960 drm_dithering_mode_enum_list
,
961 ARRAY_SIZE(drm_dithering_mode_enum_list
));
962 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
966 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
969 * drm_mode_create_dirty_property - create dirty property
972 * Called by a driver the first time it's needed, must be attached to desired
975 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
977 struct drm_property
*dirty_info
;
979 if (dev
->mode_config
.dirty_info_property
)
983 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
985 drm_dirty_info_enum_list
,
986 ARRAY_SIZE(drm_dirty_info_enum_list
));
987 dev
->mode_config
.dirty_info_property
= dirty_info
;
991 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
994 * drm_mode_config_init - initialize DRM mode_configuration structure
997 * Initialize @dev's mode_config structure, used for tracking the graphics
998 * configuration of @dev.
1000 * Since this initializes the modeset locks, no locking is possible. Which is no
1001 * problem, since this should happen single threaded at init time. It is the
1002 * driver's problem to ensure this guarantee.
1005 void drm_mode_config_init(struct drm_device
*dev
)
1007 mutex_init(&dev
->mode_config
.mutex
);
1008 mutex_init(&dev
->mode_config
.idr_mutex
);
1009 mutex_init(&dev
->mode_config
.fb_lock
);
1010 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
1011 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
1012 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
1013 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
1014 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
1015 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
1016 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
1017 idr_init(&dev
->mode_config
.crtc_idr
);
1019 drm_modeset_lock_all(dev
);
1020 drm_mode_create_standard_connector_properties(dev
);
1021 drm_modeset_unlock_all(dev
);
1023 /* Just to be sure */
1024 dev
->mode_config
.num_fb
= 0;
1025 dev
->mode_config
.num_connector
= 0;
1026 dev
->mode_config
.num_crtc
= 0;
1027 dev
->mode_config
.num_encoder
= 0;
1029 EXPORT_SYMBOL(drm_mode_config_init
);
1031 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
1033 uint32_t total_objects
= 0;
1035 total_objects
+= dev
->mode_config
.num_crtc
;
1036 total_objects
+= dev
->mode_config
.num_connector
;
1037 total_objects
+= dev
->mode_config
.num_encoder
;
1039 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
1040 if (!group
->id_list
)
1043 group
->num_crtcs
= 0;
1044 group
->num_connectors
= 0;
1045 group
->num_encoders
= 0;
1049 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
1050 struct drm_mode_group
*group
)
1052 struct drm_crtc
*crtc
;
1053 struct drm_encoder
*encoder
;
1054 struct drm_connector
*connector
;
1057 if ((ret
= drm_mode_group_init(dev
, group
)))
1060 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
1061 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
1063 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
1064 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
1067 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
1068 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
1069 group
->num_connectors
++] = connector
->base
.id
;
1073 EXPORT_SYMBOL(drm_mode_group_init_legacy_group
);
1076 * drm_mode_config_cleanup - free up DRM mode_config info
1079 * Free up all the connectors and CRTCs associated with this DRM device, then
1080 * free up the framebuffers and associated buffer objects.
1082 * Note that since this /should/ happen single-threaded at driver/device
1083 * teardown time, no locking is required. It's the driver's job to ensure that
1084 * this guarantee actually holds true.
1086 * FIXME: cleanup any dangling user buffer objects too
1088 void drm_mode_config_cleanup(struct drm_device
*dev
)
1090 struct drm_connector
*connector
, *ot
;
1091 struct drm_crtc
*crtc
, *ct
;
1092 struct drm_encoder
*encoder
, *enct
;
1093 struct drm_framebuffer
*fb
, *fbt
;
1094 struct drm_property
*property
, *pt
;
1095 struct drm_plane
*plane
, *plt
;
1097 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
1099 encoder
->funcs
->destroy(encoder
);
1102 list_for_each_entry_safe(connector
, ot
,
1103 &dev
->mode_config
.connector_list
, head
) {
1104 connector
->funcs
->destroy(connector
);
1107 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
1109 drm_property_destroy(dev
, property
);
1112 /* Single-threaded teardown context, so it's not requied to grab the
1113 * fb_lock to protect against concurrent fb_list access. Contrary, it
1114 * would actually deadlock with the drm_framebuffer_cleanup function. */
1115 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
1116 drm_framebuffer_remove(fb
);
1119 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
1121 plane
->funcs
->destroy(plane
);
1124 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
1125 crtc
->funcs
->destroy(crtc
);
1128 idr_remove_all(&dev
->mode_config
.crtc_idr
);
1129 idr_destroy(&dev
->mode_config
.crtc_idr
);
1131 EXPORT_SYMBOL(drm_mode_config_cleanup
);
1134 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1135 * @out: drm_mode_modeinfo struct to return to the user
1136 * @in: drm_display_mode to use
1138 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1141 static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
1142 const struct drm_display_mode
*in
)
1144 WARN(in
->hdisplay
> USHRT_MAX
|| in
->hsync_start
> USHRT_MAX
||
1145 in
->hsync_end
> USHRT_MAX
|| in
->htotal
> USHRT_MAX
||
1146 in
->hskew
> USHRT_MAX
|| in
->vdisplay
> USHRT_MAX
||
1147 in
->vsync_start
> USHRT_MAX
|| in
->vsync_end
> USHRT_MAX
||
1148 in
->vtotal
> USHRT_MAX
|| in
->vscan
> USHRT_MAX
,
1149 "timing values too large for mode info\n");
1151 out
->clock
= in
->clock
;
1152 out
->hdisplay
= in
->hdisplay
;
1153 out
->hsync_start
= in
->hsync_start
;
1154 out
->hsync_end
= in
->hsync_end
;
1155 out
->htotal
= in
->htotal
;
1156 out
->hskew
= in
->hskew
;
1157 out
->vdisplay
= in
->vdisplay
;
1158 out
->vsync_start
= in
->vsync_start
;
1159 out
->vsync_end
= in
->vsync_end
;
1160 out
->vtotal
= in
->vtotal
;
1161 out
->vscan
= in
->vscan
;
1162 out
->vrefresh
= in
->vrefresh
;
1163 out
->flags
= in
->flags
;
1164 out
->type
= in
->type
;
1165 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1166 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1170 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1171 * @out: drm_display_mode to return to the user
1172 * @in: drm_mode_modeinfo to use
1174 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1178 * Zero on success, errno on failure.
1180 static int drm_crtc_convert_umode(struct drm_display_mode
*out
,
1181 const struct drm_mode_modeinfo
*in
)
1183 if (in
->clock
> INT_MAX
|| in
->vrefresh
> INT_MAX
)
1186 out
->clock
= in
->clock
;
1187 out
->hdisplay
= in
->hdisplay
;
1188 out
->hsync_start
= in
->hsync_start
;
1189 out
->hsync_end
= in
->hsync_end
;
1190 out
->htotal
= in
->htotal
;
1191 out
->hskew
= in
->hskew
;
1192 out
->vdisplay
= in
->vdisplay
;
1193 out
->vsync_start
= in
->vsync_start
;
1194 out
->vsync_end
= in
->vsync_end
;
1195 out
->vtotal
= in
->vtotal
;
1196 out
->vscan
= in
->vscan
;
1197 out
->vrefresh
= in
->vrefresh
;
1198 out
->flags
= in
->flags
;
1199 out
->type
= in
->type
;
1200 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1201 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1207 * drm_mode_getresources - get graphics configuration
1208 * @dev: drm device for the ioctl
1209 * @data: data pointer for the ioctl
1210 * @file_priv: drm file for the ioctl call
1212 * Construct a set of configuration description structures and return
1213 * them to the user, including CRTC, connector and framebuffer configuration.
1215 * Called by the user via ioctl.
1218 * Zero on success, errno on failure.
1220 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1221 struct drm_file
*file_priv
)
1223 struct drm_mode_card_res
*card_res
= data
;
1224 struct list_head
*lh
;
1225 struct drm_framebuffer
*fb
;
1226 struct drm_connector
*connector
;
1227 struct drm_crtc
*crtc
;
1228 struct drm_encoder
*encoder
;
1230 int connector_count
= 0;
1233 int encoder_count
= 0;
1235 uint32_t __user
*fb_id
;
1236 uint32_t __user
*crtc_id
;
1237 uint32_t __user
*connector_id
;
1238 uint32_t __user
*encoder_id
;
1239 struct drm_mode_group
*mode_group
;
1241 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1245 mutex_lock(&file_priv
->fbs_lock
);
1247 * For the non-control nodes we need to limit the list of resources
1248 * by IDs in the group list for this node
1250 list_for_each(lh
, &file_priv
->fbs
)
1253 /* handle this in 4 parts */
1255 if (card_res
->count_fbs
>= fb_count
) {
1257 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1258 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1259 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1260 mutex_unlock(&file_priv
->fbs_lock
);
1266 card_res
->count_fbs
= fb_count
;
1267 mutex_unlock(&file_priv
->fbs_lock
);
1269 drm_modeset_lock_all(dev
);
1270 mode_group
= &file_priv
->master
->minor
->mode_group
;
1271 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1273 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1276 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1279 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1283 crtc_count
= mode_group
->num_crtcs
;
1284 connector_count
= mode_group
->num_connectors
;
1285 encoder_count
= mode_group
->num_encoders
;
1288 card_res
->max_height
= dev
->mode_config
.max_height
;
1289 card_res
->min_height
= dev
->mode_config
.min_height
;
1290 card_res
->max_width
= dev
->mode_config
.max_width
;
1291 card_res
->min_width
= dev
->mode_config
.min_width
;
1294 if (card_res
->count_crtcs
>= crtc_count
) {
1296 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1297 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1298 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1300 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1301 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1308 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1309 if (put_user(mode_group
->id_list
[i
],
1310 crtc_id
+ copied
)) {
1318 card_res
->count_crtcs
= crtc_count
;
1321 if (card_res
->count_encoders
>= encoder_count
) {
1323 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1324 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1325 list_for_each_entry(encoder
,
1326 &dev
->mode_config
.encoder_list
,
1328 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1329 drm_get_encoder_name(encoder
));
1330 if (put_user(encoder
->base
.id
, encoder_id
+
1338 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1339 if (put_user(mode_group
->id_list
[i
],
1340 encoder_id
+ copied
)) {
1349 card_res
->count_encoders
= encoder_count
;
1352 if (card_res
->count_connectors
>= connector_count
) {
1354 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1355 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1356 list_for_each_entry(connector
,
1357 &dev
->mode_config
.connector_list
,
1359 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1361 drm_get_connector_name(connector
));
1362 if (put_user(connector
->base
.id
,
1363 connector_id
+ copied
)) {
1370 int start
= mode_group
->num_crtcs
+
1371 mode_group
->num_encoders
;
1372 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1373 if (put_user(mode_group
->id_list
[i
],
1374 connector_id
+ copied
)) {
1382 card_res
->count_connectors
= connector_count
;
1384 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1385 card_res
->count_connectors
, card_res
->count_encoders
);
1388 drm_modeset_unlock_all(dev
);
1393 * drm_mode_getcrtc - get CRTC configuration
1394 * @dev: drm device for the ioctl
1395 * @data: data pointer for the ioctl
1396 * @file_priv: drm file for the ioctl call
1398 * Construct a CRTC configuration structure to return to the user.
1400 * Called by the user via ioctl.
1403 * Zero on success, errno on failure.
1405 int drm_mode_getcrtc(struct drm_device
*dev
,
1406 void *data
, struct drm_file
*file_priv
)
1408 struct drm_mode_crtc
*crtc_resp
= data
;
1409 struct drm_crtc
*crtc
;
1410 struct drm_mode_object
*obj
;
1413 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1416 drm_modeset_lock_all(dev
);
1418 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1419 DRM_MODE_OBJECT_CRTC
);
1424 crtc
= obj_to_crtc(obj
);
1426 crtc_resp
->x
= crtc
->x
;
1427 crtc_resp
->y
= crtc
->y
;
1428 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1430 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1432 crtc_resp
->fb_id
= 0;
1434 if (crtc
->enabled
) {
1436 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1437 crtc_resp
->mode_valid
= 1;
1440 crtc_resp
->mode_valid
= 0;
1444 drm_modeset_unlock_all(dev
);
1449 * drm_mode_getconnector - get connector configuration
1450 * @dev: drm device for the ioctl
1451 * @data: data pointer for the ioctl
1452 * @file_priv: drm file for the ioctl call
1454 * Construct a connector configuration structure to return to the user.
1456 * Called by the user via ioctl.
1459 * Zero on success, errno on failure.
1461 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1462 struct drm_file
*file_priv
)
1464 struct drm_mode_get_connector
*out_resp
= data
;
1465 struct drm_mode_object
*obj
;
1466 struct drm_connector
*connector
;
1467 struct drm_display_mode
*mode
;
1469 int props_count
= 0;
1470 int encoders_count
= 0;
1474 struct drm_mode_modeinfo u_mode
;
1475 struct drm_mode_modeinfo __user
*mode_ptr
;
1476 uint32_t __user
*prop_ptr
;
1477 uint64_t __user
*prop_values
;
1478 uint32_t __user
*encoder_ptr
;
1480 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1483 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1485 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1487 drm_modeset_lock_all(dev
);
1489 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1490 DRM_MODE_OBJECT_CONNECTOR
);
1495 connector
= obj_to_connector(obj
);
1497 props_count
= connector
->properties
.count
;
1499 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1500 if (connector
->encoder_ids
[i
] != 0) {
1505 if (out_resp
->count_modes
== 0) {
1506 connector
->funcs
->fill_modes(connector
,
1507 dev
->mode_config
.max_width
,
1508 dev
->mode_config
.max_height
);
1511 /* delayed so we get modes regardless of pre-fill_modes state */
1512 list_for_each_entry(mode
, &connector
->modes
, head
)
1515 out_resp
->connector_id
= connector
->base
.id
;
1516 out_resp
->connector_type
= connector
->connector_type
;
1517 out_resp
->connector_type_id
= connector
->connector_type_id
;
1518 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1519 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1520 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1521 out_resp
->connection
= connector
->status
;
1522 if (connector
->encoder
)
1523 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1525 out_resp
->encoder_id
= 0;
1528 * This ioctl is called twice, once to determine how much space is
1529 * needed, and the 2nd time to fill it.
1531 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1533 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1534 list_for_each_entry(mode
, &connector
->modes
, head
) {
1535 drm_crtc_convert_to_umode(&u_mode
, mode
);
1536 if (copy_to_user(mode_ptr
+ copied
,
1537 &u_mode
, sizeof(u_mode
))) {
1544 out_resp
->count_modes
= mode_count
;
1546 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1548 prop_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
);
1549 prop_values
= (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
);
1550 for (i
= 0; i
< connector
->properties
.count
; i
++) {
1551 if (put_user(connector
->properties
.ids
[i
],
1552 prop_ptr
+ copied
)) {
1557 if (put_user(connector
->properties
.values
[i
],
1558 prop_values
+ copied
)) {
1565 out_resp
->count_props
= props_count
;
1567 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1569 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1570 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1571 if (connector
->encoder_ids
[i
] != 0) {
1572 if (put_user(connector
->encoder_ids
[i
],
1573 encoder_ptr
+ copied
)) {
1581 out_resp
->count_encoders
= encoders_count
;
1584 drm_modeset_unlock_all(dev
);
1588 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1589 struct drm_file
*file_priv
)
1591 struct drm_mode_get_encoder
*enc_resp
= data
;
1592 struct drm_mode_object
*obj
;
1593 struct drm_encoder
*encoder
;
1596 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1599 drm_modeset_lock_all(dev
);
1600 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1601 DRM_MODE_OBJECT_ENCODER
);
1606 encoder
= obj_to_encoder(obj
);
1609 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1611 enc_resp
->crtc_id
= 0;
1612 enc_resp
->encoder_type
= encoder
->encoder_type
;
1613 enc_resp
->encoder_id
= encoder
->base
.id
;
1614 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1615 enc_resp
->possible_clones
= encoder
->possible_clones
;
1618 drm_modeset_unlock_all(dev
);
1623 * drm_mode_getplane_res - get plane info
1626 * @file_priv: DRM file info
1628 * Return an plane count and set of IDs.
1630 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
1631 struct drm_file
*file_priv
)
1633 struct drm_mode_get_plane_res
*plane_resp
= data
;
1634 struct drm_mode_config
*config
;
1635 struct drm_plane
*plane
;
1636 uint32_t __user
*plane_ptr
;
1637 int copied
= 0, ret
= 0;
1639 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1642 drm_modeset_lock_all(dev
);
1643 config
= &dev
->mode_config
;
1646 * This ioctl is called twice, once to determine how much space is
1647 * needed, and the 2nd time to fill it.
1649 if (config
->num_plane
&&
1650 (plane_resp
->count_planes
>= config
->num_plane
)) {
1651 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
1653 list_for_each_entry(plane
, &config
->plane_list
, head
) {
1654 if (put_user(plane
->base
.id
, plane_ptr
+ copied
)) {
1661 plane_resp
->count_planes
= config
->num_plane
;
1664 drm_modeset_unlock_all(dev
);
1669 * drm_mode_getplane - get plane info
1672 * @file_priv: DRM file info
1674 * Return plane info, including formats supported, gamma size, any
1677 int drm_mode_getplane(struct drm_device
*dev
, void *data
,
1678 struct drm_file
*file_priv
)
1680 struct drm_mode_get_plane
*plane_resp
= data
;
1681 struct drm_mode_object
*obj
;
1682 struct drm_plane
*plane
;
1683 uint32_t __user
*format_ptr
;
1686 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1689 drm_modeset_lock_all(dev
);
1690 obj
= drm_mode_object_find(dev
, plane_resp
->plane_id
,
1691 DRM_MODE_OBJECT_PLANE
);
1696 plane
= obj_to_plane(obj
);
1699 plane_resp
->crtc_id
= plane
->crtc
->base
.id
;
1701 plane_resp
->crtc_id
= 0;
1704 plane_resp
->fb_id
= plane
->fb
->base
.id
;
1706 plane_resp
->fb_id
= 0;
1708 plane_resp
->plane_id
= plane
->base
.id
;
1709 plane_resp
->possible_crtcs
= plane
->possible_crtcs
;
1710 plane_resp
->gamma_size
= plane
->gamma_size
;
1713 * This ioctl is called twice, once to determine how much space is
1714 * needed, and the 2nd time to fill it.
1716 if (plane
->format_count
&&
1717 (plane_resp
->count_format_types
>= plane
->format_count
)) {
1718 format_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->format_type_ptr
;
1719 if (copy_to_user(format_ptr
,
1720 plane
->format_types
,
1721 sizeof(uint32_t) * plane
->format_count
)) {
1726 plane_resp
->count_format_types
= plane
->format_count
;
1729 drm_modeset_unlock_all(dev
);
1734 * drm_mode_setplane - set up or tear down an plane
1736 * @data: ioctl data*
1737 * @file_priv: DRM file info
1739 * Set plane info, including placement, fb, scaling, and other factors.
1740 * Or pass a NULL fb to disable.
1742 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
1743 struct drm_file
*file_priv
)
1745 struct drm_mode_set_plane
*plane_req
= data
;
1746 struct drm_mode_object
*obj
;
1747 struct drm_plane
*plane
;
1748 struct drm_crtc
*crtc
;
1749 struct drm_framebuffer
*fb
;
1751 unsigned int fb_width
, fb_height
;
1754 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1757 drm_modeset_lock_all(dev
);
1760 * First, find the plane, crtc, and fb objects. If not available,
1761 * we don't bother to call the driver.
1763 obj
= drm_mode_object_find(dev
, plane_req
->plane_id
,
1764 DRM_MODE_OBJECT_PLANE
);
1766 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1767 plane_req
->plane_id
);
1771 plane
= obj_to_plane(obj
);
1773 /* No fb means shut it down */
1774 if (!plane_req
->fb_id
) {
1775 plane
->funcs
->disable_plane(plane
);
1781 obj
= drm_mode_object_find(dev
, plane_req
->crtc_id
,
1782 DRM_MODE_OBJECT_CRTC
);
1784 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1785 plane_req
->crtc_id
);
1789 crtc
= obj_to_crtc(obj
);
1791 mutex_lock(&dev
->mode_config
.fb_lock
);
1792 obj
= drm_mode_object_find(dev
, plane_req
->fb_id
,
1793 DRM_MODE_OBJECT_FB
);
1794 mutex_unlock(&dev
->mode_config
.fb_lock
);
1796 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1801 fb
= obj_to_fb(obj
);
1803 /* Check whether this plane supports the fb pixel format. */
1804 for (i
= 0; i
< plane
->format_count
; i
++)
1805 if (fb
->pixel_format
== plane
->format_types
[i
])
1807 if (i
== plane
->format_count
) {
1808 DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb
->pixel_format
);
1813 fb_width
= fb
->width
<< 16;
1814 fb_height
= fb
->height
<< 16;
1816 /* Make sure source coordinates are inside the fb. */
1817 if (plane_req
->src_w
> fb_width
||
1818 plane_req
->src_x
> fb_width
- plane_req
->src_w
||
1819 plane_req
->src_h
> fb_height
||
1820 plane_req
->src_y
> fb_height
- plane_req
->src_h
) {
1821 DRM_DEBUG_KMS("Invalid source coordinates "
1822 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1823 plane_req
->src_w
>> 16,
1824 ((plane_req
->src_w
& 0xffff) * 15625) >> 10,
1825 plane_req
->src_h
>> 16,
1826 ((plane_req
->src_h
& 0xffff) * 15625) >> 10,
1827 plane_req
->src_x
>> 16,
1828 ((plane_req
->src_x
& 0xffff) * 15625) >> 10,
1829 plane_req
->src_y
>> 16,
1830 ((plane_req
->src_y
& 0xffff) * 15625) >> 10);
1835 /* Give drivers some help against integer overflows */
1836 if (plane_req
->crtc_w
> INT_MAX
||
1837 plane_req
->crtc_x
> INT_MAX
- (int32_t) plane_req
->crtc_w
||
1838 plane_req
->crtc_h
> INT_MAX
||
1839 plane_req
->crtc_y
> INT_MAX
- (int32_t) plane_req
->crtc_h
) {
1840 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
1841 plane_req
->crtc_w
, plane_req
->crtc_h
,
1842 plane_req
->crtc_x
, plane_req
->crtc_y
);
1847 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
1848 plane_req
->crtc_x
, plane_req
->crtc_y
,
1849 plane_req
->crtc_w
, plane_req
->crtc_h
,
1850 plane_req
->src_x
, plane_req
->src_y
,
1851 plane_req
->src_w
, plane_req
->src_h
);
1858 drm_modeset_unlock_all(dev
);
1864 * drm_mode_set_config_internal - helper to call ->set_config
1865 * @set: modeset config to set
1867 * This is a little helper to wrap internal calls to the ->set_config driver
1868 * interface. The only thing it adds is correct refcounting dance.
1870 int drm_mode_set_config_internal(struct drm_mode_set
*set
)
1872 struct drm_crtc
*crtc
= set
->crtc
;
1874 return crtc
->funcs
->set_config(set
);
1876 EXPORT_SYMBOL(drm_mode_set_config_internal
);
1879 * drm_mode_setcrtc - set CRTC configuration
1880 * @dev: drm device for the ioctl
1881 * @data: data pointer for the ioctl
1882 * @file_priv: drm file for the ioctl call
1884 * Build a new CRTC configuration based on user request.
1886 * Called by the user via ioctl.
1889 * Zero on success, errno on failure.
1891 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1892 struct drm_file
*file_priv
)
1894 struct drm_mode_config
*config
= &dev
->mode_config
;
1895 struct drm_mode_crtc
*crtc_req
= data
;
1896 struct drm_mode_object
*obj
;
1897 struct drm_crtc
*crtc
;
1898 struct drm_connector
**connector_set
= NULL
, *connector
;
1899 struct drm_framebuffer
*fb
= NULL
;
1900 struct drm_display_mode
*mode
= NULL
;
1901 struct drm_mode_set set
;
1902 uint32_t __user
*set_connectors_ptr
;
1906 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1909 /* For some reason crtc x/y offsets are signed internally. */
1910 if (crtc_req
->x
> INT_MAX
|| crtc_req
->y
> INT_MAX
)
1913 drm_modeset_lock_all(dev
);
1914 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
1915 DRM_MODE_OBJECT_CRTC
);
1917 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1921 crtc
= obj_to_crtc(obj
);
1922 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1924 if (crtc_req
->mode_valid
) {
1925 int hdisplay
, vdisplay
;
1926 /* If we have a mode we need a framebuffer. */
1927 /* If we pass -1, set the mode with the currently bound fb */
1928 if (crtc_req
->fb_id
== -1) {
1930 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
1936 mutex_lock(&dev
->mode_config
.fb_lock
);
1937 obj
= drm_mode_object_find(dev
, crtc_req
->fb_id
,
1938 DRM_MODE_OBJECT_FB
);
1939 mutex_unlock(&dev
->mode_config
.fb_lock
);
1941 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1946 fb
= obj_to_fb(obj
);
1949 mode
= drm_mode_create(dev
);
1955 ret
= drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
1957 DRM_DEBUG_KMS("Invalid mode\n");
1961 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
1963 hdisplay
= mode
->hdisplay
;
1964 vdisplay
= mode
->vdisplay
;
1966 if (crtc
->invert_dimensions
)
1967 swap(hdisplay
, vdisplay
);
1969 if (hdisplay
> fb
->width
||
1970 vdisplay
> fb
->height
||
1971 crtc_req
->x
> fb
->width
- hdisplay
||
1972 crtc_req
->y
> fb
->height
- vdisplay
) {
1973 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
1974 fb
->width
, fb
->height
,
1975 hdisplay
, vdisplay
, crtc_req
->x
, crtc_req
->y
,
1976 crtc
->invert_dimensions
? " (inverted)" : "");
1982 if (crtc_req
->count_connectors
== 0 && mode
) {
1983 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1988 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
1989 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1990 crtc_req
->count_connectors
);
1995 if (crtc_req
->count_connectors
> 0) {
1998 /* Avoid unbounded kernel memory allocation */
1999 if (crtc_req
->count_connectors
> config
->num_connector
) {
2004 connector_set
= kmalloc(crtc_req
->count_connectors
*
2005 sizeof(struct drm_connector
*),
2007 if (!connector_set
) {
2012 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
2013 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
2014 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
2019 obj
= drm_mode_object_find(dev
, out_id
,
2020 DRM_MODE_OBJECT_CONNECTOR
);
2022 DRM_DEBUG_KMS("Connector id %d unknown\n",
2027 connector
= obj_to_connector(obj
);
2028 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2030 drm_get_connector_name(connector
));
2032 connector_set
[i
] = connector
;
2037 set
.x
= crtc_req
->x
;
2038 set
.y
= crtc_req
->y
;
2040 set
.connectors
= connector_set
;
2041 set
.num_connectors
= crtc_req
->count_connectors
;
2043 ret
= drm_mode_set_config_internal(&set
);
2046 kfree(connector_set
);
2047 drm_mode_destroy(dev
, mode
);
2048 drm_modeset_unlock_all(dev
);
2052 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
2053 void *data
, struct drm_file
*file_priv
)
2055 struct drm_mode_cursor
*req
= data
;
2056 struct drm_mode_object
*obj
;
2057 struct drm_crtc
*crtc
;
2060 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2063 if (!req
->flags
|| (~DRM_MODE_CURSOR_FLAGS
& req
->flags
))
2066 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2068 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
2071 crtc
= obj_to_crtc(obj
);
2073 mutex_lock(&crtc
->mutex
);
2074 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
2075 if (!crtc
->funcs
->cursor_set
) {
2079 /* Turns off the cursor if handle is 0 */
2080 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
2081 req
->width
, req
->height
);
2084 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
2085 if (crtc
->funcs
->cursor_move
) {
2086 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
2093 mutex_unlock(&crtc
->mutex
);
2098 /* Original addfb only supported RGB formats, so figure out which one */
2099 uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
)
2105 fmt
= DRM_FORMAT_RGB332
;
2109 fmt
= DRM_FORMAT_XRGB1555
;
2111 fmt
= DRM_FORMAT_RGB565
;
2114 fmt
= DRM_FORMAT_RGB888
;
2118 fmt
= DRM_FORMAT_XRGB8888
;
2119 else if (depth
== 30)
2120 fmt
= DRM_FORMAT_XRGB2101010
;
2122 fmt
= DRM_FORMAT_ARGB8888
;
2125 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
2126 fmt
= DRM_FORMAT_XRGB8888
;
2132 EXPORT_SYMBOL(drm_mode_legacy_fb_format
);
2135 * drm_mode_addfb - add an FB to the graphics configuration
2136 * @dev: drm device for the ioctl
2137 * @data: data pointer for the ioctl
2138 * @file_priv: drm file for the ioctl call
2140 * Add a new FB to the specified CRTC, given a user request.
2142 * Called by the user via ioctl.
2145 * Zero on success, errno on failure.
2147 int drm_mode_addfb(struct drm_device
*dev
,
2148 void *data
, struct drm_file
*file_priv
)
2150 struct drm_mode_fb_cmd
*or = data
;
2151 struct drm_mode_fb_cmd2 r
= {};
2152 struct drm_mode_config
*config
= &dev
->mode_config
;
2153 struct drm_framebuffer
*fb
;
2156 /* Use new struct with format internally */
2157 r
.fb_id
= or->fb_id
;
2158 r
.width
= or->width
;
2159 r
.height
= or->height
;
2160 r
.pitches
[0] = or->pitch
;
2161 r
.pixel_format
= drm_mode_legacy_fb_format(or->bpp
, or->depth
);
2162 r
.handles
[0] = or->handle
;
2164 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2167 if ((config
->min_width
> r
.width
) || (r
.width
> config
->max_width
))
2170 if ((config
->min_height
> r
.height
) || (r
.height
> config
->max_height
))
2173 drm_modeset_lock_all(dev
);
2175 /* TODO check buffer is sufficiently large */
2176 /* TODO setup destructor callback */
2178 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, &r
);
2180 DRM_DEBUG_KMS("could not create framebuffer\n");
2181 drm_modeset_unlock_all(dev
);
2185 mutex_lock(&file_priv
->fbs_lock
);
2186 or->fb_id
= fb
->base
.id
;
2187 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2188 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2189 mutex_unlock(&file_priv
->fbs_lock
);
2190 drm_modeset_unlock_all(dev
);
2195 static int format_check(const struct drm_mode_fb_cmd2
*r
)
2197 uint32_t format
= r
->pixel_format
& ~DRM_FORMAT_BIG_ENDIAN
;
2201 case DRM_FORMAT_RGB332
:
2202 case DRM_FORMAT_BGR233
:
2203 case DRM_FORMAT_XRGB4444
:
2204 case DRM_FORMAT_XBGR4444
:
2205 case DRM_FORMAT_RGBX4444
:
2206 case DRM_FORMAT_BGRX4444
:
2207 case DRM_FORMAT_ARGB4444
:
2208 case DRM_FORMAT_ABGR4444
:
2209 case DRM_FORMAT_RGBA4444
:
2210 case DRM_FORMAT_BGRA4444
:
2211 case DRM_FORMAT_XRGB1555
:
2212 case DRM_FORMAT_XBGR1555
:
2213 case DRM_FORMAT_RGBX5551
:
2214 case DRM_FORMAT_BGRX5551
:
2215 case DRM_FORMAT_ARGB1555
:
2216 case DRM_FORMAT_ABGR1555
:
2217 case DRM_FORMAT_RGBA5551
:
2218 case DRM_FORMAT_BGRA5551
:
2219 case DRM_FORMAT_RGB565
:
2220 case DRM_FORMAT_BGR565
:
2221 case DRM_FORMAT_RGB888
:
2222 case DRM_FORMAT_BGR888
:
2223 case DRM_FORMAT_XRGB8888
:
2224 case DRM_FORMAT_XBGR8888
:
2225 case DRM_FORMAT_RGBX8888
:
2226 case DRM_FORMAT_BGRX8888
:
2227 case DRM_FORMAT_ARGB8888
:
2228 case DRM_FORMAT_ABGR8888
:
2229 case DRM_FORMAT_RGBA8888
:
2230 case DRM_FORMAT_BGRA8888
:
2231 case DRM_FORMAT_XRGB2101010
:
2232 case DRM_FORMAT_XBGR2101010
:
2233 case DRM_FORMAT_RGBX1010102
:
2234 case DRM_FORMAT_BGRX1010102
:
2235 case DRM_FORMAT_ARGB2101010
:
2236 case DRM_FORMAT_ABGR2101010
:
2237 case DRM_FORMAT_RGBA1010102
:
2238 case DRM_FORMAT_BGRA1010102
:
2239 case DRM_FORMAT_YUYV
:
2240 case DRM_FORMAT_YVYU
:
2241 case DRM_FORMAT_UYVY
:
2242 case DRM_FORMAT_VYUY
:
2243 case DRM_FORMAT_AYUV
:
2244 case DRM_FORMAT_NV12
:
2245 case DRM_FORMAT_NV21
:
2246 case DRM_FORMAT_NV16
:
2247 case DRM_FORMAT_NV61
:
2248 case DRM_FORMAT_NV24
:
2249 case DRM_FORMAT_NV42
:
2250 case DRM_FORMAT_YUV410
:
2251 case DRM_FORMAT_YVU410
:
2252 case DRM_FORMAT_YUV411
:
2253 case DRM_FORMAT_YVU411
:
2254 case DRM_FORMAT_YUV420
:
2255 case DRM_FORMAT_YVU420
:
2256 case DRM_FORMAT_YUV422
:
2257 case DRM_FORMAT_YVU422
:
2258 case DRM_FORMAT_YUV444
:
2259 case DRM_FORMAT_YVU444
:
2266 static int framebuffer_check(const struct drm_mode_fb_cmd2
*r
)
2268 int ret
, hsub
, vsub
, num_planes
, i
;
2270 ret
= format_check(r
);
2272 DRM_DEBUG_KMS("bad framebuffer format 0x%08x\n", r
->pixel_format
);
2276 hsub
= drm_format_horz_chroma_subsampling(r
->pixel_format
);
2277 vsub
= drm_format_vert_chroma_subsampling(r
->pixel_format
);
2278 num_planes
= drm_format_num_planes(r
->pixel_format
);
2280 if (r
->width
== 0 || r
->width
% hsub
) {
2281 DRM_DEBUG_KMS("bad framebuffer width %u\n", r
->height
);
2285 if (r
->height
== 0 || r
->height
% vsub
) {
2286 DRM_DEBUG_KMS("bad framebuffer height %u\n", r
->height
);
2290 for (i
= 0; i
< num_planes
; i
++) {
2291 unsigned int width
= r
->width
/ (i
!= 0 ? hsub
: 1);
2292 unsigned int height
= r
->height
/ (i
!= 0 ? vsub
: 1);
2293 unsigned int cpp
= drm_format_plane_cpp(r
->pixel_format
, i
);
2295 if (!r
->handles
[i
]) {
2296 DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i
);
2300 if ((uint64_t) width
* cpp
> UINT_MAX
)
2303 if ((uint64_t) height
* r
->pitches
[i
] + r
->offsets
[i
] > UINT_MAX
)
2306 if (r
->pitches
[i
] < width
* cpp
) {
2307 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r
->pitches
[i
], i
);
2316 * drm_mode_addfb2 - add an FB to the graphics configuration
2317 * @dev: drm device for the ioctl
2318 * @data: data pointer for the ioctl
2319 * @file_priv: drm file for the ioctl call
2321 * Add a new FB to the specified CRTC, given a user request with format.
2323 * Called by the user via ioctl.
2326 * Zero on success, errno on failure.
2328 int drm_mode_addfb2(struct drm_device
*dev
,
2329 void *data
, struct drm_file
*file_priv
)
2331 struct drm_mode_fb_cmd2
*r
= data
;
2332 struct drm_mode_config
*config
= &dev
->mode_config
;
2333 struct drm_framebuffer
*fb
;
2336 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2339 if (r
->flags
& ~DRM_MODE_FB_INTERLACED
) {
2340 DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r
->flags
);
2344 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
2345 DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
2346 r
->width
, config
->min_width
, config
->max_width
);
2349 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
2350 DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
2351 r
->height
, config
->min_height
, config
->max_height
);
2355 ret
= framebuffer_check(r
);
2359 drm_modeset_lock_all(dev
);
2361 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
2363 DRM_DEBUG_KMS("could not create framebuffer\n");
2364 drm_modeset_unlock_all(dev
);
2368 mutex_lock(&file_priv
->fbs_lock
);
2369 r
->fb_id
= fb
->base
.id
;
2370 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2371 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2372 mutex_unlock(&file_priv
->fbs_lock
);
2374 drm_modeset_unlock_all(dev
);
2380 * drm_mode_rmfb - remove an FB from the configuration
2381 * @dev: drm device for the ioctl
2382 * @data: data pointer for the ioctl
2383 * @file_priv: drm file for the ioctl call
2385 * Remove the FB specified by the user.
2387 * Called by the user via ioctl.
2390 * Zero on success, errno on failure.
2392 int drm_mode_rmfb(struct drm_device
*dev
,
2393 void *data
, struct drm_file
*file_priv
)
2395 struct drm_mode_object
*obj
;
2396 struct drm_framebuffer
*fb
= NULL
;
2397 struct drm_framebuffer
*fbl
= NULL
;
2398 uint32_t *id
= data
;
2402 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2405 drm_modeset_lock_all(dev
);
2406 mutex_lock(&dev
->mode_config
.fb_lock
);
2407 obj
= drm_mode_object_find(dev
, *id
, DRM_MODE_OBJECT_FB
);
2408 /* TODO check that we really get a framebuffer back. */
2410 mutex_unlock(&dev
->mode_config
.fb_lock
);
2414 fb
= obj_to_fb(obj
);
2415 mutex_unlock(&dev
->mode_config
.fb_lock
);
2417 mutex_lock(&file_priv
->fbs_lock
);
2418 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
2423 mutex_unlock(&file_priv
->fbs_lock
);
2427 list_del_init(&fb
->filp_head
);
2428 mutex_unlock(&file_priv
->fbs_lock
);
2430 drm_framebuffer_remove(fb
);
2432 drm_modeset_unlock_all(dev
);
2438 * drm_mode_getfb - get FB info
2439 * @dev: drm device for the ioctl
2440 * @data: data pointer for the ioctl
2441 * @file_priv: drm file for the ioctl call
2443 * Lookup the FB given its ID and return info about it.
2445 * Called by the user via ioctl.
2448 * Zero on success, errno on failure.
2450 int drm_mode_getfb(struct drm_device
*dev
,
2451 void *data
, struct drm_file
*file_priv
)
2453 struct drm_mode_fb_cmd
*r
= data
;
2454 struct drm_mode_object
*obj
;
2455 struct drm_framebuffer
*fb
;
2458 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2461 drm_modeset_lock_all(dev
);
2462 mutex_lock(&dev
->mode_config
.fb_lock
);
2463 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
2464 mutex_unlock(&dev
->mode_config
.fb_lock
);
2469 fb
= obj_to_fb(obj
);
2471 r
->height
= fb
->height
;
2472 r
->width
= fb
->width
;
2473 r
->depth
= fb
->depth
;
2474 r
->bpp
= fb
->bits_per_pixel
;
2475 r
->pitch
= fb
->pitches
[0];
2476 if (fb
->funcs
->create_handle
)
2477 ret
= fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
2482 drm_modeset_unlock_all(dev
);
2486 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2487 void *data
, struct drm_file
*file_priv
)
2489 struct drm_clip_rect __user
*clips_ptr
;
2490 struct drm_clip_rect
*clips
= NULL
;
2491 struct drm_mode_fb_dirty_cmd
*r
= data
;
2492 struct drm_mode_object
*obj
;
2493 struct drm_framebuffer
*fb
;
2498 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2501 drm_modeset_lock_all(dev
);
2502 mutex_lock(&dev
->mode_config
.fb_lock
);
2503 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
2504 mutex_unlock(&dev
->mode_config
.fb_lock
);
2509 fb
= obj_to_fb(obj
);
2511 num_clips
= r
->num_clips
;
2512 clips_ptr
= (struct drm_clip_rect __user
*)(unsigned long)r
->clips_ptr
;
2514 if (!num_clips
!= !clips_ptr
) {
2519 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
2521 /* If userspace annotates copy, clips must come in pairs */
2522 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
2527 if (num_clips
&& clips_ptr
) {
2528 if (num_clips
< 0 || num_clips
> DRM_MODE_FB_DIRTY_MAX_CLIPS
) {
2532 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
2538 ret
= copy_from_user(clips
, clips_ptr
,
2539 num_clips
* sizeof(*clips
));
2546 if (fb
->funcs
->dirty
) {
2547 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
2557 drm_modeset_unlock_all(dev
);
2563 * drm_fb_release - remove and free the FBs on this file
2564 * @priv: drm file for the ioctl
2566 * Destroy all the FBs associated with @filp.
2568 * Called by the user via ioctl.
2571 * Zero on success, errno on failure.
2573 void drm_fb_release(struct drm_file
*priv
)
2575 struct drm_device
*dev
= priv
->minor
->dev
;
2576 struct drm_framebuffer
*fb
, *tfb
;
2578 drm_modeset_lock_all(dev
);
2579 mutex_lock(&priv
->fbs_lock
);
2580 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
2581 list_del_init(&fb
->filp_head
);
2582 drm_framebuffer_remove(fb
);
2584 mutex_unlock(&priv
->fbs_lock
);
2585 drm_modeset_unlock_all(dev
);
2589 * drm_mode_attachmode - add a mode to the user mode list
2591 * @connector: connector to add the mode to
2592 * @mode: mode to add
2594 * Add @mode to @connector's user mode list.
2596 static void drm_mode_attachmode(struct drm_device
*dev
,
2597 struct drm_connector
*connector
,
2598 struct drm_display_mode
*mode
)
2600 list_add_tail(&mode
->head
, &connector
->user_modes
);
2603 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
2604 const struct drm_display_mode
*mode
)
2606 struct drm_connector
*connector
;
2608 struct drm_display_mode
*dup_mode
, *next
;
2611 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2612 if (!connector
->encoder
)
2614 if (connector
->encoder
->crtc
== crtc
) {
2615 dup_mode
= drm_mode_duplicate(dev
, mode
);
2620 list_add_tail(&dup_mode
->head
, &list
);
2624 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2625 if (!connector
->encoder
)
2627 if (connector
->encoder
->crtc
== crtc
)
2628 list_move_tail(list
.next
, &connector
->user_modes
);
2631 WARN_ON(!list_empty(&list
));
2634 list_for_each_entry_safe(dup_mode
, next
, &list
, head
)
2635 drm_mode_destroy(dev
, dup_mode
);
2639 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
2641 static int drm_mode_detachmode(struct drm_device
*dev
,
2642 struct drm_connector
*connector
,
2643 struct drm_display_mode
*mode
)
2647 struct drm_display_mode
*match_mode
, *t
;
2649 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
2650 if (drm_mode_equal(match_mode
, mode
)) {
2651 list_del(&match_mode
->head
);
2652 drm_mode_destroy(dev
, match_mode
);
2664 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
2666 struct drm_connector
*connector
;
2668 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2669 drm_mode_detachmode(dev
, connector
, mode
);
2673 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
2676 * drm_fb_attachmode - Attach a user mode to an connector
2677 * @dev: drm device for the ioctl
2678 * @data: data pointer for the ioctl
2679 * @file_priv: drm file for the ioctl call
2681 * This attaches a user specified mode to an connector.
2682 * Called by the user via ioctl.
2685 * Zero on success, errno on failure.
2687 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
2688 void *data
, struct drm_file
*file_priv
)
2690 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2691 struct drm_connector
*connector
;
2692 struct drm_display_mode
*mode
;
2693 struct drm_mode_object
*obj
;
2694 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2697 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2700 drm_modeset_lock_all(dev
);
2702 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2707 connector
= obj_to_connector(obj
);
2709 mode
= drm_mode_create(dev
);
2715 ret
= drm_crtc_convert_umode(mode
, umode
);
2717 DRM_DEBUG_KMS("Invalid mode\n");
2718 drm_mode_destroy(dev
, mode
);
2722 drm_mode_attachmode(dev
, connector
, mode
);
2724 drm_modeset_unlock_all(dev
);
2730 * drm_fb_detachmode - Detach a user specified mode from an connector
2731 * @dev: drm device for the ioctl
2732 * @data: data pointer for the ioctl
2733 * @file_priv: drm file for the ioctl call
2735 * Called by the user via ioctl.
2738 * Zero on success, errno on failure.
2740 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
2741 void *data
, struct drm_file
*file_priv
)
2743 struct drm_mode_object
*obj
;
2744 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2745 struct drm_connector
*connector
;
2746 struct drm_display_mode mode
;
2747 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2750 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2753 drm_modeset_lock_all(dev
);
2755 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2760 connector
= obj_to_connector(obj
);
2762 ret
= drm_crtc_convert_umode(&mode
, umode
);
2764 DRM_DEBUG_KMS("Invalid mode\n");
2768 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
2770 drm_modeset_unlock_all(dev
);
2774 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2775 const char *name
, int num_values
)
2777 struct drm_property
*property
= NULL
;
2780 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2785 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2786 if (!property
->values
)
2790 ret
= drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2794 property
->flags
= flags
;
2795 property
->num_values
= num_values
;
2796 INIT_LIST_HEAD(&property
->enum_blob_list
);
2799 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2800 property
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2803 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2806 kfree(property
->values
);
2810 EXPORT_SYMBOL(drm_property_create
);
2812 struct drm_property
*drm_property_create_enum(struct drm_device
*dev
, int flags
,
2814 const struct drm_prop_enum_list
*props
,
2817 struct drm_property
*property
;
2820 flags
|= DRM_MODE_PROP_ENUM
;
2822 property
= drm_property_create(dev
, flags
, name
, num_values
);
2826 for (i
= 0; i
< num_values
; i
++) {
2827 ret
= drm_property_add_enum(property
, i
,
2831 drm_property_destroy(dev
, property
);
2838 EXPORT_SYMBOL(drm_property_create_enum
);
2840 struct drm_property
*drm_property_create_bitmask(struct drm_device
*dev
,
2841 int flags
, const char *name
,
2842 const struct drm_prop_enum_list
*props
,
2845 struct drm_property
*property
;
2848 flags
|= DRM_MODE_PROP_BITMASK
;
2850 property
= drm_property_create(dev
, flags
, name
, num_values
);
2854 for (i
= 0; i
< num_values
; i
++) {
2855 ret
= drm_property_add_enum(property
, i
,
2859 drm_property_destroy(dev
, property
);
2866 EXPORT_SYMBOL(drm_property_create_bitmask
);
2868 struct drm_property
*drm_property_create_range(struct drm_device
*dev
, int flags
,
2870 uint64_t min
, uint64_t max
)
2872 struct drm_property
*property
;
2874 flags
|= DRM_MODE_PROP_RANGE
;
2876 property
= drm_property_create(dev
, flags
, name
, 2);
2880 property
->values
[0] = min
;
2881 property
->values
[1] = max
;
2885 EXPORT_SYMBOL(drm_property_create_range
);
2887 int drm_property_add_enum(struct drm_property
*property
, int index
,
2888 uint64_t value
, const char *name
)
2890 struct drm_property_enum
*prop_enum
;
2892 if (!(property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)))
2896 * Bitmask enum properties have the additional constraint of values
2899 if ((property
->flags
& DRM_MODE_PROP_BITMASK
) && (value
> 63))
2902 if (!list_empty(&property
->enum_blob_list
)) {
2903 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2904 if (prop_enum
->value
== value
) {
2905 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2906 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2912 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2916 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2917 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2918 prop_enum
->value
= value
;
2920 property
->values
[index
] = value
;
2921 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2924 EXPORT_SYMBOL(drm_property_add_enum
);
2926 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2928 struct drm_property_enum
*prop_enum
, *pt
;
2930 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2931 list_del(&prop_enum
->head
);
2935 if (property
->num_values
)
2936 kfree(property
->values
);
2937 drm_mode_object_put(dev
, &property
->base
);
2938 list_del(&property
->head
);
2941 EXPORT_SYMBOL(drm_property_destroy
);
2943 void drm_object_attach_property(struct drm_mode_object
*obj
,
2944 struct drm_property
*property
,
2947 int count
= obj
->properties
->count
;
2949 if (count
== DRM_OBJECT_MAX_PROPERTY
) {
2950 WARN(1, "Failed to attach object property (type: 0x%x). Please "
2951 "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time "
2952 "you see this message on the same object type.\n",
2957 obj
->properties
->ids
[count
] = property
->base
.id
;
2958 obj
->properties
->values
[count
] = init_val
;
2959 obj
->properties
->count
++;
2961 EXPORT_SYMBOL(drm_object_attach_property
);
2963 int drm_object_property_set_value(struct drm_mode_object
*obj
,
2964 struct drm_property
*property
, uint64_t val
)
2968 for (i
= 0; i
< obj
->properties
->count
; i
++) {
2969 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
2970 obj
->properties
->values
[i
] = val
;
2977 EXPORT_SYMBOL(drm_object_property_set_value
);
2979 int drm_object_property_get_value(struct drm_mode_object
*obj
,
2980 struct drm_property
*property
, uint64_t *val
)
2984 for (i
= 0; i
< obj
->properties
->count
; i
++) {
2985 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
2986 *val
= obj
->properties
->values
[i
];
2993 EXPORT_SYMBOL(drm_object_property_get_value
);
2995 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2996 void *data
, struct drm_file
*file_priv
)
2998 struct drm_mode_object
*obj
;
2999 struct drm_mode_get_property
*out_resp
= data
;
3000 struct drm_property
*property
;
3003 int value_count
= 0;
3006 struct drm_property_enum
*prop_enum
;
3007 struct drm_mode_property_enum __user
*enum_ptr
;
3008 struct drm_property_blob
*prop_blob
;
3009 uint32_t __user
*blob_id_ptr
;
3010 uint64_t __user
*values_ptr
;
3011 uint32_t __user
*blob_length_ptr
;
3013 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3016 drm_modeset_lock_all(dev
);
3017 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
3022 property
= obj_to_property(obj
);
3024 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
3025 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
3027 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3028 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
3032 value_count
= property
->num_values
;
3034 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
3035 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
3036 out_resp
->flags
= property
->flags
;
3038 if ((out_resp
->count_values
>= value_count
) && value_count
) {
3039 values_ptr
= (uint64_t __user
*)(unsigned long)out_resp
->values_ptr
;
3040 for (i
= 0; i
< value_count
; i
++) {
3041 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
3047 out_resp
->count_values
= value_count
;
3049 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
3050 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
3052 enum_ptr
= (struct drm_mode_property_enum __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3053 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
3055 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
3060 if (copy_to_user(&enum_ptr
[copied
].name
,
3061 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
3068 out_resp
->count_enum_blobs
= enum_count
;
3071 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3072 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
3074 blob_id_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3075 blob_length_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->values_ptr
;
3077 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
3078 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
3083 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
3091 out_resp
->count_enum_blobs
= blob_count
;
3094 drm_modeset_unlock_all(dev
);
3098 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
3101 struct drm_property_blob
*blob
;
3104 if (!length
|| !data
)
3107 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
3111 ret
= drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
3117 blob
->length
= length
;
3119 memcpy(blob
->data
, data
, length
);
3121 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
3125 static void drm_property_destroy_blob(struct drm_device
*dev
,
3126 struct drm_property_blob
*blob
)
3128 drm_mode_object_put(dev
, &blob
->base
);
3129 list_del(&blob
->head
);
3133 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
3134 void *data
, struct drm_file
*file_priv
)
3136 struct drm_mode_object
*obj
;
3137 struct drm_mode_get_blob
*out_resp
= data
;
3138 struct drm_property_blob
*blob
;
3140 void __user
*blob_ptr
;
3142 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3145 drm_modeset_lock_all(dev
);
3146 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
3151 blob
= obj_to_blob(obj
);
3153 if (out_resp
->length
== blob
->length
) {
3154 blob_ptr
= (void __user
*)(unsigned long)out_resp
->data
;
3155 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
3160 out_resp
->length
= blob
->length
;
3163 drm_modeset_unlock_all(dev
);
3167 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
3170 struct drm_device
*dev
= connector
->dev
;
3173 if (connector
->edid_blob_ptr
)
3174 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
3176 /* Delete edid, when there is none. */
3178 connector
->edid_blob_ptr
= NULL
;
3179 ret
= drm_object_property_set_value(&connector
->base
, dev
->mode_config
.edid_property
, 0);
3183 size
= EDID_LENGTH
* (1 + edid
->extensions
);
3184 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
3186 if (!connector
->edid_blob_ptr
)
3189 ret
= drm_object_property_set_value(&connector
->base
,
3190 dev
->mode_config
.edid_property
,
3191 connector
->edid_blob_ptr
->base
.id
);
3195 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
3197 static bool drm_property_change_is_valid(struct drm_property
*property
,
3200 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
3202 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
3203 if (value
< property
->values
[0] || value
> property
->values
[1])
3206 } else if (property
->flags
& DRM_MODE_PROP_BITMASK
) {
3208 uint64_t valid_mask
= 0;
3209 for (i
= 0; i
< property
->num_values
; i
++)
3210 valid_mask
|= (1ULL << property
->values
[i
]);
3211 return !(value
& ~valid_mask
);
3212 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3213 /* Only the driver knows */
3217 for (i
= 0; i
< property
->num_values
; i
++)
3218 if (property
->values
[i
] == value
)
3224 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
3225 void *data
, struct drm_file
*file_priv
)
3227 struct drm_mode_connector_set_property
*conn_set_prop
= data
;
3228 struct drm_mode_obj_set_property obj_set_prop
= {
3229 .value
= conn_set_prop
->value
,
3230 .prop_id
= conn_set_prop
->prop_id
,
3231 .obj_id
= conn_set_prop
->connector_id
,
3232 .obj_type
= DRM_MODE_OBJECT_CONNECTOR
3235 /* It does all the locking and checking we need */
3236 return drm_mode_obj_set_property_ioctl(dev
, &obj_set_prop
, file_priv
);
3239 static int drm_mode_connector_set_obj_prop(struct drm_mode_object
*obj
,
3240 struct drm_property
*property
,
3244 struct drm_connector
*connector
= obj_to_connector(obj
);
3246 /* Do DPMS ourselves */
3247 if (property
== connector
->dev
->mode_config
.dpms_property
) {
3248 if (connector
->funcs
->dpms
)
3249 (*connector
->funcs
->dpms
)(connector
, (int)value
);
3251 } else if (connector
->funcs
->set_property
)
3252 ret
= connector
->funcs
->set_property(connector
, property
, value
);
3254 /* store the property value if successful */
3256 drm_object_property_set_value(&connector
->base
, property
, value
);
3260 static int drm_mode_crtc_set_obj_prop(struct drm_mode_object
*obj
,
3261 struct drm_property
*property
,
3265 struct drm_crtc
*crtc
= obj_to_crtc(obj
);
3267 if (crtc
->funcs
->set_property
)
3268 ret
= crtc
->funcs
->set_property(crtc
, property
, value
);
3270 drm_object_property_set_value(obj
, property
, value
);
3275 static int drm_mode_plane_set_obj_prop(struct drm_mode_object
*obj
,
3276 struct drm_property
*property
,
3280 struct drm_plane
*plane
= obj_to_plane(obj
);
3282 if (plane
->funcs
->set_property
)
3283 ret
= plane
->funcs
->set_property(plane
, property
, value
);
3285 drm_object_property_set_value(obj
, property
, value
);
3290 int drm_mode_obj_get_properties_ioctl(struct drm_device
*dev
, void *data
,
3291 struct drm_file
*file_priv
)
3293 struct drm_mode_obj_get_properties
*arg
= data
;
3294 struct drm_mode_object
*obj
;
3298 int props_count
= 0;
3299 uint32_t __user
*props_ptr
;
3300 uint64_t __user
*prop_values_ptr
;
3302 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3305 drm_modeset_lock_all(dev
);
3307 obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3312 if (!obj
->properties
) {
3317 props_count
= obj
->properties
->count
;
3319 /* This ioctl is called twice, once to determine how much space is
3320 * needed, and the 2nd time to fill it. */
3321 if ((arg
->count_props
>= props_count
) && props_count
) {
3323 props_ptr
= (uint32_t __user
*)(unsigned long)(arg
->props_ptr
);
3324 prop_values_ptr
= (uint64_t __user
*)(unsigned long)
3325 (arg
->prop_values_ptr
);
3326 for (i
= 0; i
< props_count
; i
++) {
3327 if (put_user(obj
->properties
->ids
[i
],
3328 props_ptr
+ copied
)) {
3332 if (put_user(obj
->properties
->values
[i
],
3333 prop_values_ptr
+ copied
)) {
3340 arg
->count_props
= props_count
;
3342 drm_modeset_unlock_all(dev
);
3346 int drm_mode_obj_set_property_ioctl(struct drm_device
*dev
, void *data
,
3347 struct drm_file
*file_priv
)
3349 struct drm_mode_obj_set_property
*arg
= data
;
3350 struct drm_mode_object
*arg_obj
;
3351 struct drm_mode_object
*prop_obj
;
3352 struct drm_property
*property
;
3356 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3359 drm_modeset_lock_all(dev
);
3361 arg_obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3364 if (!arg_obj
->properties
)
3367 for (i
= 0; i
< arg_obj
->properties
->count
; i
++)
3368 if (arg_obj
->properties
->ids
[i
] == arg
->prop_id
)
3371 if (i
== arg_obj
->properties
->count
)
3374 prop_obj
= drm_mode_object_find(dev
, arg
->prop_id
,
3375 DRM_MODE_OBJECT_PROPERTY
);
3378 property
= obj_to_property(prop_obj
);
3380 if (!drm_property_change_is_valid(property
, arg
->value
))
3383 switch (arg_obj
->type
) {
3384 case DRM_MODE_OBJECT_CONNECTOR
:
3385 ret
= drm_mode_connector_set_obj_prop(arg_obj
, property
,
3388 case DRM_MODE_OBJECT_CRTC
:
3389 ret
= drm_mode_crtc_set_obj_prop(arg_obj
, property
, arg
->value
);
3391 case DRM_MODE_OBJECT_PLANE
:
3392 ret
= drm_mode_plane_set_obj_prop(arg_obj
, property
, arg
->value
);
3397 drm_modeset_unlock_all(dev
);
3401 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
3402 struct drm_encoder
*encoder
)
3406 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3407 if (connector
->encoder_ids
[i
] == 0) {
3408 connector
->encoder_ids
[i
] = encoder
->base
.id
;
3414 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
3416 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
3417 struct drm_encoder
*encoder
)
3420 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3421 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
3422 connector
->encoder_ids
[i
] = 0;
3423 if (connector
->encoder
== encoder
)
3424 connector
->encoder
= NULL
;
3429 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
3431 int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
3434 crtc
->gamma_size
= gamma_size
;
3436 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
3437 if (!crtc
->gamma_store
) {
3438 crtc
->gamma_size
= 0;
3444 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
3446 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
3447 void *data
, struct drm_file
*file_priv
)
3449 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3450 struct drm_mode_object
*obj
;
3451 struct drm_crtc
*crtc
;
3452 void *r_base
, *g_base
, *b_base
;
3456 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3459 drm_modeset_lock_all(dev
);
3460 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3465 crtc
= obj_to_crtc(obj
);
3467 if (crtc
->funcs
->gamma_set
== NULL
) {
3472 /* memcpy into gamma store */
3473 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3478 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3479 r_base
= crtc
->gamma_store
;
3480 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
3485 g_base
= r_base
+ size
;
3486 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
3491 b_base
= g_base
+ size
;
3492 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
3497 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
3500 drm_modeset_unlock_all(dev
);
3505 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
3506 void *data
, struct drm_file
*file_priv
)
3508 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3509 struct drm_mode_object
*obj
;
3510 struct drm_crtc
*crtc
;
3511 void *r_base
, *g_base
, *b_base
;
3515 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3518 drm_modeset_lock_all(dev
);
3519 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3524 crtc
= obj_to_crtc(obj
);
3526 /* memcpy into gamma store */
3527 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3532 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3533 r_base
= crtc
->gamma_store
;
3534 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
3539 g_base
= r_base
+ size
;
3540 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
3545 b_base
= g_base
+ size
;
3546 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
3551 drm_modeset_unlock_all(dev
);
3555 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
3556 void *data
, struct drm_file
*file_priv
)
3558 struct drm_mode_crtc_page_flip
*page_flip
= data
;
3559 struct drm_mode_object
*obj
;
3560 struct drm_crtc
*crtc
;
3561 struct drm_framebuffer
*fb
;
3562 struct drm_pending_vblank_event
*e
= NULL
;
3563 unsigned long flags
;
3564 int hdisplay
, vdisplay
;
3567 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
3568 page_flip
->reserved
!= 0)
3571 drm_modeset_lock_all(dev
);
3572 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3575 crtc
= obj_to_crtc(obj
);
3577 if (crtc
->fb
== NULL
) {
3578 /* The framebuffer is currently unbound, presumably
3579 * due to a hotplug event, that userspace has not
3586 if (crtc
->funcs
->page_flip
== NULL
)
3589 mutex_lock(&dev
->mode_config
.fb_lock
);
3590 obj
= drm_mode_object_find(dev
, page_flip
->fb_id
, DRM_MODE_OBJECT_FB
);
3591 mutex_unlock(&dev
->mode_config
.fb_lock
);
3594 fb
= obj_to_fb(obj
);
3596 hdisplay
= crtc
->mode
.hdisplay
;
3597 vdisplay
= crtc
->mode
.vdisplay
;
3599 if (crtc
->invert_dimensions
)
3600 swap(hdisplay
, vdisplay
);
3602 if (hdisplay
> fb
->width
||
3603 vdisplay
> fb
->height
||
3604 crtc
->x
> fb
->width
- hdisplay
||
3605 crtc
->y
> fb
->height
- vdisplay
) {
3606 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
3607 fb
->width
, fb
->height
, hdisplay
, vdisplay
, crtc
->x
, crtc
->y
,
3608 crtc
->invert_dimensions
? " (inverted)" : "");
3613 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3615 spin_lock_irqsave(&dev
->event_lock
, flags
);
3616 if (file_priv
->event_space
< sizeof e
->event
) {
3617 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3620 file_priv
->event_space
-= sizeof e
->event
;
3621 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3623 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
3625 spin_lock_irqsave(&dev
->event_lock
, flags
);
3626 file_priv
->event_space
+= sizeof e
->event
;
3627 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3631 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
3632 e
->event
.base
.length
= sizeof e
->event
;
3633 e
->event
.user_data
= page_flip
->user_data
;
3634 e
->base
.event
= &e
->event
.base
;
3635 e
->base
.file_priv
= file_priv
;
3637 (void (*) (struct drm_pending_event
*)) kfree
;
3640 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
);
3642 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3643 spin_lock_irqsave(&dev
->event_lock
, flags
);
3644 file_priv
->event_space
+= sizeof e
->event
;
3645 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3651 drm_modeset_unlock_all(dev
);
3655 void drm_mode_config_reset(struct drm_device
*dev
)
3657 struct drm_crtc
*crtc
;
3658 struct drm_encoder
*encoder
;
3659 struct drm_connector
*connector
;
3661 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
3662 if (crtc
->funcs
->reset
)
3663 crtc
->funcs
->reset(crtc
);
3665 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
3666 if (encoder
->funcs
->reset
)
3667 encoder
->funcs
->reset(encoder
);
3669 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
3670 connector
->status
= connector_status_unknown
;
3672 if (connector
->funcs
->reset
)
3673 connector
->funcs
->reset(connector
);
3676 EXPORT_SYMBOL(drm_mode_config_reset
);
3678 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
3679 void *data
, struct drm_file
*file_priv
)
3681 struct drm_mode_create_dumb
*args
= data
;
3683 if (!dev
->driver
->dumb_create
)
3685 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
3688 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
3689 void *data
, struct drm_file
*file_priv
)
3691 struct drm_mode_map_dumb
*args
= data
;
3693 /* call driver ioctl to get mmap offset */
3694 if (!dev
->driver
->dumb_map_offset
)
3697 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
3700 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
3701 void *data
, struct drm_file
*file_priv
)
3703 struct drm_mode_destroy_dumb
*args
= data
;
3705 if (!dev
->driver
->dumb_destroy
)
3708 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
3712 * Just need to support RGB formats here for compat with code that doesn't
3713 * use pixel formats directly yet.
3715 void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
3719 case DRM_FORMAT_RGB332
:
3720 case DRM_FORMAT_BGR233
:
3724 case DRM_FORMAT_XRGB1555
:
3725 case DRM_FORMAT_XBGR1555
:
3726 case DRM_FORMAT_RGBX5551
:
3727 case DRM_FORMAT_BGRX5551
:
3728 case DRM_FORMAT_ARGB1555
:
3729 case DRM_FORMAT_ABGR1555
:
3730 case DRM_FORMAT_RGBA5551
:
3731 case DRM_FORMAT_BGRA5551
:
3735 case DRM_FORMAT_RGB565
:
3736 case DRM_FORMAT_BGR565
:
3740 case DRM_FORMAT_RGB888
:
3741 case DRM_FORMAT_BGR888
:
3745 case DRM_FORMAT_XRGB8888
:
3746 case DRM_FORMAT_XBGR8888
:
3747 case DRM_FORMAT_RGBX8888
:
3748 case DRM_FORMAT_BGRX8888
:
3752 case DRM_FORMAT_XRGB2101010
:
3753 case DRM_FORMAT_XBGR2101010
:
3754 case DRM_FORMAT_RGBX1010102
:
3755 case DRM_FORMAT_BGRX1010102
:
3756 case DRM_FORMAT_ARGB2101010
:
3757 case DRM_FORMAT_ABGR2101010
:
3758 case DRM_FORMAT_RGBA1010102
:
3759 case DRM_FORMAT_BGRA1010102
:
3763 case DRM_FORMAT_ARGB8888
:
3764 case DRM_FORMAT_ABGR8888
:
3765 case DRM_FORMAT_RGBA8888
:
3766 case DRM_FORMAT_BGRA8888
:
3771 DRM_DEBUG_KMS("unsupported pixel format\n");
3777 EXPORT_SYMBOL(drm_fb_get_bpp_depth
);
3780 * drm_format_num_planes - get the number of planes for format
3781 * @format: pixel format (DRM_FORMAT_*)
3784 * The number of planes used by the specified pixel format.
3786 int drm_format_num_planes(uint32_t format
)
3789 case DRM_FORMAT_YUV410
:
3790 case DRM_FORMAT_YVU410
:
3791 case DRM_FORMAT_YUV411
:
3792 case DRM_FORMAT_YVU411
:
3793 case DRM_FORMAT_YUV420
:
3794 case DRM_FORMAT_YVU420
:
3795 case DRM_FORMAT_YUV422
:
3796 case DRM_FORMAT_YVU422
:
3797 case DRM_FORMAT_YUV444
:
3798 case DRM_FORMAT_YVU444
:
3800 case DRM_FORMAT_NV12
:
3801 case DRM_FORMAT_NV21
:
3802 case DRM_FORMAT_NV16
:
3803 case DRM_FORMAT_NV61
:
3804 case DRM_FORMAT_NV24
:
3805 case DRM_FORMAT_NV42
:
3811 EXPORT_SYMBOL(drm_format_num_planes
);
3814 * drm_format_plane_cpp - determine the bytes per pixel value
3815 * @format: pixel format (DRM_FORMAT_*)
3816 * @plane: plane index
3819 * The bytes per pixel value for the specified plane.
3821 int drm_format_plane_cpp(uint32_t format
, int plane
)
3826 if (plane
>= drm_format_num_planes(format
))
3830 case DRM_FORMAT_YUYV
:
3831 case DRM_FORMAT_YVYU
:
3832 case DRM_FORMAT_UYVY
:
3833 case DRM_FORMAT_VYUY
:
3835 case DRM_FORMAT_NV12
:
3836 case DRM_FORMAT_NV21
:
3837 case DRM_FORMAT_NV16
:
3838 case DRM_FORMAT_NV61
:
3839 case DRM_FORMAT_NV24
:
3840 case DRM_FORMAT_NV42
:
3841 return plane
? 2 : 1;
3842 case DRM_FORMAT_YUV410
:
3843 case DRM_FORMAT_YVU410
:
3844 case DRM_FORMAT_YUV411
:
3845 case DRM_FORMAT_YVU411
:
3846 case DRM_FORMAT_YUV420
:
3847 case DRM_FORMAT_YVU420
:
3848 case DRM_FORMAT_YUV422
:
3849 case DRM_FORMAT_YVU422
:
3850 case DRM_FORMAT_YUV444
:
3851 case DRM_FORMAT_YVU444
:
3854 drm_fb_get_bpp_depth(format
, &depth
, &bpp
);
3858 EXPORT_SYMBOL(drm_format_plane_cpp
);
3861 * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
3862 * @format: pixel format (DRM_FORMAT_*)
3865 * The horizontal chroma subsampling factor for the
3866 * specified pixel format.
3868 int drm_format_horz_chroma_subsampling(uint32_t format
)
3871 case DRM_FORMAT_YUV411
:
3872 case DRM_FORMAT_YVU411
:
3873 case DRM_FORMAT_YUV410
:
3874 case DRM_FORMAT_YVU410
:
3876 case DRM_FORMAT_YUYV
:
3877 case DRM_FORMAT_YVYU
:
3878 case DRM_FORMAT_UYVY
:
3879 case DRM_FORMAT_VYUY
:
3880 case DRM_FORMAT_NV12
:
3881 case DRM_FORMAT_NV21
:
3882 case DRM_FORMAT_NV16
:
3883 case DRM_FORMAT_NV61
:
3884 case DRM_FORMAT_YUV422
:
3885 case DRM_FORMAT_YVU422
:
3886 case DRM_FORMAT_YUV420
:
3887 case DRM_FORMAT_YVU420
:
3893 EXPORT_SYMBOL(drm_format_horz_chroma_subsampling
);
3896 * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
3897 * @format: pixel format (DRM_FORMAT_*)
3900 * The vertical chroma subsampling factor for the
3901 * specified pixel format.
3903 int drm_format_vert_chroma_subsampling(uint32_t format
)
3906 case DRM_FORMAT_YUV410
:
3907 case DRM_FORMAT_YVU410
:
3909 case DRM_FORMAT_YUV420
:
3910 case DRM_FORMAT_YVU420
:
3911 case DRM_FORMAT_NV12
:
3912 case DRM_FORMAT_NV21
:
3918 EXPORT_SYMBOL(drm_format_vert_chroma_subsampling
);