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>
40 /* Avoid boilerplate. I'm tired of typing. */
41 #define DRM_ENUM_NAME_FN(fnname, list) \
42 char *fnname(int val) \
45 for (i = 0; i < ARRAY_SIZE(list); i++) { \
46 if (list[i].type == val) \
47 return list[i].name; \
55 static struct drm_prop_enum_list drm_dpms_enum_list
[] =
56 { { DRM_MODE_DPMS_ON
, "On" },
57 { DRM_MODE_DPMS_STANDBY
, "Standby" },
58 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
59 { DRM_MODE_DPMS_OFF
, "Off" }
62 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
67 static struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
69 { DRM_MODE_SCALE_NONE
, "None" },
70 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
71 { DRM_MODE_SCALE_CENTER
, "Center" },
72 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
75 static struct drm_prop_enum_list drm_dithering_mode_enum_list
[] =
77 { DRM_MODE_DITHERING_OFF
, "Off" },
78 { DRM_MODE_DITHERING_ON
, "On" },
79 { DRM_MODE_DITHERING_AUTO
, "Automatic" },
83 * Non-global properties, but "required" for certain connectors.
85 static struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
87 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
88 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
89 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
92 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
94 static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
96 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
97 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
98 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
101 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
102 drm_dvi_i_subconnector_enum_list
)
104 static struct drm_prop_enum_list drm_tv_select_enum_list
[] =
106 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
107 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
108 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
109 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
110 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
113 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
115 static struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
117 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
118 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
119 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
120 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
121 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
124 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
125 drm_tv_subconnector_enum_list
)
127 static struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
128 { DRM_MODE_DIRTY_OFF
, "Off" },
129 { DRM_MODE_DIRTY_ON
, "On" },
130 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
133 DRM_ENUM_NAME_FN(drm_get_dirty_info_name
,
134 drm_dirty_info_enum_list
)
136 struct drm_conn_prop_enum_list
{
143 * Connector and encoder types.
145 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
146 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
147 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
148 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
149 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
150 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
151 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
152 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
153 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
154 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
155 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN", 0 },
156 { DRM_MODE_CONNECTOR_DisplayPort
, "DP", 0 },
157 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A", 0 },
158 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B", 0 },
159 { DRM_MODE_CONNECTOR_TV
, "TV", 0 },
160 { DRM_MODE_CONNECTOR_eDP
, "eDP", 0 },
161 { DRM_MODE_CONNECTOR_VIRTUAL
, "Virtual", 0},
164 static struct drm_prop_enum_list drm_encoder_enum_list
[] =
165 { { DRM_MODE_ENCODER_NONE
, "None" },
166 { DRM_MODE_ENCODER_DAC
, "DAC" },
167 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
168 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
169 { DRM_MODE_ENCODER_TVDAC
, "TV" },
170 { DRM_MODE_ENCODER_VIRTUAL
, "Virtual" },
173 char *drm_get_encoder_name(struct drm_encoder
*encoder
)
177 snprintf(buf
, 32, "%s-%d",
178 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
182 EXPORT_SYMBOL(drm_get_encoder_name
);
184 char *drm_get_connector_name(struct drm_connector
*connector
)
188 snprintf(buf
, 32, "%s-%d",
189 drm_connector_enum_list
[connector
->connector_type
].name
,
190 connector
->connector_type_id
);
193 EXPORT_SYMBOL(drm_get_connector_name
);
195 char *drm_get_connector_status_name(enum drm_connector_status status
)
197 if (status
== connector_status_connected
)
199 else if (status
== connector_status_disconnected
)
200 return "disconnected";
206 * drm_mode_object_get - allocate a new identifier
208 * @ptr: object pointer, used to generate unique ID
213 * Create a unique identifier based on @ptr in @dev's identifier space. Used
214 * for tracking modes, CRTCs and connectors.
217 * New unique (relative to other objects in @dev) integer identifier for the
220 static int drm_mode_object_get(struct drm_device
*dev
,
221 struct drm_mode_object
*obj
, uint32_t obj_type
)
227 if (idr_pre_get(&dev
->mode_config
.crtc_idr
, GFP_KERNEL
) == 0) {
228 DRM_ERROR("Ran out memory getting a mode number\n");
232 mutex_lock(&dev
->mode_config
.idr_mutex
);
233 ret
= idr_get_new_above(&dev
->mode_config
.crtc_idr
, obj
, 1, &new_id
);
234 mutex_unlock(&dev
->mode_config
.idr_mutex
);
241 obj
->type
= obj_type
;
246 * drm_mode_object_put - free an identifer
251 * Caller must hold DRM mode_config lock.
253 * Free @id from @dev's unique identifier pool.
255 static void drm_mode_object_put(struct drm_device
*dev
,
256 struct drm_mode_object
*object
)
258 mutex_lock(&dev
->mode_config
.idr_mutex
);
259 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
260 mutex_unlock(&dev
->mode_config
.idr_mutex
);
263 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
264 uint32_t id
, uint32_t type
)
266 struct drm_mode_object
*obj
= NULL
;
268 mutex_lock(&dev
->mode_config
.idr_mutex
);
269 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
270 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
272 mutex_unlock(&dev
->mode_config
.idr_mutex
);
276 EXPORT_SYMBOL(drm_mode_object_find
);
279 * drm_framebuffer_init - initialize a framebuffer
283 * Caller must hold mode config lock.
285 * Allocates an ID for the framebuffer's parent mode object, sets its mode
286 * functions & device file and adds it to the master fd list.
289 * Zero on success, error code on failure.
291 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
292 const struct drm_framebuffer_funcs
*funcs
)
296 kref_init(&fb
->refcount
);
298 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
304 dev
->mode_config
.num_fb
++;
305 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
309 EXPORT_SYMBOL(drm_framebuffer_init
);
311 static void drm_framebuffer_free(struct kref
*kref
)
313 struct drm_framebuffer
*fb
=
314 container_of(kref
, struct drm_framebuffer
, refcount
);
315 fb
->funcs
->destroy(fb
);
319 * drm_framebuffer_unreference - unref a framebuffer
322 * Caller must hold mode config lock.
324 void drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
326 struct drm_device
*dev
= fb
->dev
;
327 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
328 WARN_ON(!mutex_is_locked(&dev
->mode_config
.mutex
));
329 kref_put(&fb
->refcount
, drm_framebuffer_free
);
331 EXPORT_SYMBOL(drm_framebuffer_unreference
);
334 * drm_framebuffer_reference - incr the fb refcnt
336 void drm_framebuffer_reference(struct drm_framebuffer
*fb
)
338 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
339 kref_get(&fb
->refcount
);
341 EXPORT_SYMBOL(drm_framebuffer_reference
);
344 * drm_framebuffer_cleanup - remove a framebuffer object
345 * @fb: framebuffer to remove
348 * Caller must hold mode config lock.
350 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes
351 * it, setting it to NULL.
353 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
355 struct drm_device
*dev
= fb
->dev
;
357 * This could be moved to drm_framebuffer_remove(), but for
358 * debugging is nice to keep around the list of fb's that are
359 * no longer associated w/ a drm_file but are not unreferenced
360 * yet. (i915 and omapdrm have debugfs files which will show
363 drm_mode_object_put(dev
, &fb
->base
);
365 dev
->mode_config
.num_fb
--;
367 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
370 * drm_framebuffer_remove - remove and unreference a framebuffer object
371 * @fb: framebuffer to remove
374 * Caller must hold mode config lock.
376 * Scans all the CRTCs and planes in @dev's mode_config. If they're
377 * using @fb, removes it, setting it to NULL.
379 void drm_framebuffer_remove(struct drm_framebuffer
*fb
)
381 struct drm_device
*dev
= fb
->dev
;
382 struct drm_crtc
*crtc
;
383 struct drm_plane
*plane
;
384 struct drm_mode_set set
;
387 /* remove from any CRTC */
388 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
389 if (crtc
->fb
== fb
) {
390 /* should turn off the crtc */
391 memset(&set
, 0, sizeof(struct drm_mode_set
));
394 ret
= crtc
->funcs
->set_config(&set
);
396 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
400 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
401 if (plane
->fb
== fb
) {
402 /* should turn off the crtc */
403 ret
= plane
->funcs
->disable_plane(plane
);
405 DRM_ERROR("failed to disable plane with busy fb\n");
406 /* disconnect the plane from the fb and crtc: */
412 list_del(&fb
->filp_head
);
414 drm_framebuffer_unreference(fb
);
416 EXPORT_SYMBOL(drm_framebuffer_remove
);
419 * drm_crtc_init - Initialise a new CRTC object
421 * @crtc: CRTC object to init
422 * @funcs: callbacks for the new CRTC
425 * Takes mode_config lock.
427 * Inits a new object created as base part of an driver crtc object.
430 * Zero on success, error code on failure.
432 int drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
433 const struct drm_crtc_funcs
*funcs
)
439 crtc
->invert_dimensions
= false;
441 mutex_lock(&dev
->mode_config
.mutex
);
443 ret
= drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
447 crtc
->base
.properties
= &crtc
->properties
;
449 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
450 dev
->mode_config
.num_crtc
++;
453 mutex_unlock(&dev
->mode_config
.mutex
);
457 EXPORT_SYMBOL(drm_crtc_init
);
460 * drm_crtc_cleanup - Cleans up the core crtc usage.
461 * @crtc: CRTC to cleanup
464 * Caller must hold mode config lock.
466 * Cleanup @crtc. Removes from drm modesetting space
467 * does NOT free object, caller does that.
469 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
471 struct drm_device
*dev
= crtc
->dev
;
473 if (crtc
->gamma_store
) {
474 kfree(crtc
->gamma_store
);
475 crtc
->gamma_store
= NULL
;
478 drm_mode_object_put(dev
, &crtc
->base
);
479 list_del(&crtc
->head
);
480 dev
->mode_config
.num_crtc
--;
482 EXPORT_SYMBOL(drm_crtc_cleanup
);
485 * drm_mode_probed_add - add a mode to a connector's probed mode list
486 * @connector: connector the new mode
490 * Caller must hold mode config lock.
492 * Add @mode to @connector's mode list for later use.
494 void drm_mode_probed_add(struct drm_connector
*connector
,
495 struct drm_display_mode
*mode
)
497 list_add(&mode
->head
, &connector
->probed_modes
);
499 EXPORT_SYMBOL(drm_mode_probed_add
);
502 * drm_mode_remove - remove and free a mode
503 * @connector: connector list to modify
504 * @mode: mode to remove
507 * Caller must hold mode config lock.
509 * Remove @mode from @connector's mode list, then free it.
511 void drm_mode_remove(struct drm_connector
*connector
,
512 struct drm_display_mode
*mode
)
514 list_del(&mode
->head
);
515 drm_mode_destroy(connector
->dev
, mode
);
517 EXPORT_SYMBOL(drm_mode_remove
);
520 * drm_connector_init - Init a preallocated connector
522 * @connector: the connector to init
523 * @funcs: callbacks for this connector
524 * @name: user visible name of the connector
527 * Takes mode config lock.
529 * Initialises a preallocated connector. Connectors should be
530 * subclassed as part of driver connector objects.
533 * Zero on success, error code on failure.
535 int drm_connector_init(struct drm_device
*dev
,
536 struct drm_connector
*connector
,
537 const struct drm_connector_funcs
*funcs
,
542 mutex_lock(&dev
->mode_config
.mutex
);
544 ret
= drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
548 connector
->base
.properties
= &connector
->properties
;
549 connector
->dev
= dev
;
550 connector
->funcs
= funcs
;
551 connector
->connector_type
= connector_type
;
552 connector
->connector_type_id
=
553 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
554 INIT_LIST_HEAD(&connector
->user_modes
);
555 INIT_LIST_HEAD(&connector
->probed_modes
);
556 INIT_LIST_HEAD(&connector
->modes
);
557 connector
->edid_blob_ptr
= NULL
;
559 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
560 dev
->mode_config
.num_connector
++;
562 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
563 drm_connector_attach_property(connector
,
564 dev
->mode_config
.edid_property
,
567 drm_connector_attach_property(connector
,
568 dev
->mode_config
.dpms_property
, 0);
571 mutex_unlock(&dev
->mode_config
.mutex
);
575 EXPORT_SYMBOL(drm_connector_init
);
578 * drm_connector_cleanup - cleans up an initialised connector
579 * @connector: connector to cleanup
582 * Takes mode config lock.
584 * Cleans up the connector but doesn't free the object.
586 void drm_connector_cleanup(struct drm_connector
*connector
)
588 struct drm_device
*dev
= connector
->dev
;
589 struct drm_display_mode
*mode
, *t
;
591 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
592 drm_mode_remove(connector
, mode
);
594 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
595 drm_mode_remove(connector
, mode
);
597 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
598 drm_mode_remove(connector
, mode
);
600 mutex_lock(&dev
->mode_config
.mutex
);
601 drm_mode_object_put(dev
, &connector
->base
);
602 list_del(&connector
->head
);
603 dev
->mode_config
.num_connector
--;
604 mutex_unlock(&dev
->mode_config
.mutex
);
606 EXPORT_SYMBOL(drm_connector_cleanup
);
608 void drm_connector_unplug_all(struct drm_device
*dev
)
610 struct drm_connector
*connector
;
612 /* taking the mode config mutex ends up in a clash with sysfs */
613 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
614 drm_sysfs_connector_remove(connector
);
617 EXPORT_SYMBOL(drm_connector_unplug_all
);
619 int drm_encoder_init(struct drm_device
*dev
,
620 struct drm_encoder
*encoder
,
621 const struct drm_encoder_funcs
*funcs
,
626 mutex_lock(&dev
->mode_config
.mutex
);
628 ret
= drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
633 encoder
->encoder_type
= encoder_type
;
634 encoder
->funcs
= funcs
;
636 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
637 dev
->mode_config
.num_encoder
++;
640 mutex_unlock(&dev
->mode_config
.mutex
);
644 EXPORT_SYMBOL(drm_encoder_init
);
646 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
648 struct drm_device
*dev
= encoder
->dev
;
649 mutex_lock(&dev
->mode_config
.mutex
);
650 drm_mode_object_put(dev
, &encoder
->base
);
651 list_del(&encoder
->head
);
652 dev
->mode_config
.num_encoder
--;
653 mutex_unlock(&dev
->mode_config
.mutex
);
655 EXPORT_SYMBOL(drm_encoder_cleanup
);
657 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
658 unsigned long possible_crtcs
,
659 const struct drm_plane_funcs
*funcs
,
660 const uint32_t *formats
, uint32_t format_count
,
665 mutex_lock(&dev
->mode_config
.mutex
);
667 ret
= drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
671 plane
->base
.properties
= &plane
->properties
;
673 plane
->funcs
= funcs
;
674 plane
->format_types
= kmalloc(sizeof(uint32_t) * format_count
,
676 if (!plane
->format_types
) {
677 DRM_DEBUG_KMS("out of memory when allocating plane\n");
678 drm_mode_object_put(dev
, &plane
->base
);
683 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
684 plane
->format_count
= format_count
;
685 plane
->possible_crtcs
= possible_crtcs
;
687 /* private planes are not exposed to userspace, but depending on
688 * display hardware, might be convenient to allow sharing programming
689 * for the scanout engine with the crtc implementation.
692 list_add_tail(&plane
->head
, &dev
->mode_config
.plane_list
);
693 dev
->mode_config
.num_plane
++;
695 INIT_LIST_HEAD(&plane
->head
);
699 mutex_unlock(&dev
->mode_config
.mutex
);
703 EXPORT_SYMBOL(drm_plane_init
);
705 void drm_plane_cleanup(struct drm_plane
*plane
)
707 struct drm_device
*dev
= plane
->dev
;
709 mutex_lock(&dev
->mode_config
.mutex
);
710 kfree(plane
->format_types
);
711 drm_mode_object_put(dev
, &plane
->base
);
712 /* if not added to a list, it must be a private plane */
713 if (!list_empty(&plane
->head
)) {
714 list_del(&plane
->head
);
715 dev
->mode_config
.num_plane
--;
717 mutex_unlock(&dev
->mode_config
.mutex
);
719 EXPORT_SYMBOL(drm_plane_cleanup
);
722 * drm_mode_create - create a new display mode
726 * Caller must hold DRM mode_config lock.
728 * Create a new drm_display_mode, give it an ID, and return it.
731 * Pointer to new mode on success, NULL on error.
733 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
735 struct drm_display_mode
*nmode
;
737 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
741 if (drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
)) {
748 EXPORT_SYMBOL(drm_mode_create
);
751 * drm_mode_destroy - remove a mode
753 * @mode: mode to remove
756 * Caller must hold mode config lock.
758 * Free @mode's unique identifier, then free it.
760 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
765 drm_mode_object_put(dev
, &mode
->base
);
769 EXPORT_SYMBOL(drm_mode_destroy
);
771 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
773 struct drm_property
*edid
;
774 struct drm_property
*dpms
;
777 * Standard properties (apply to all connectors)
779 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
780 DRM_MODE_PROP_IMMUTABLE
,
782 dev
->mode_config
.edid_property
= edid
;
784 dpms
= drm_property_create_enum(dev
, 0,
785 "DPMS", drm_dpms_enum_list
,
786 ARRAY_SIZE(drm_dpms_enum_list
));
787 dev
->mode_config
.dpms_property
= dpms
;
793 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
796 * Called by a driver the first time a DVI-I connector is made.
798 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
800 struct drm_property
*dvi_i_selector
;
801 struct drm_property
*dvi_i_subconnector
;
803 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
807 drm_property_create_enum(dev
, 0,
808 "select subconnector",
809 drm_dvi_i_select_enum_list
,
810 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
811 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
813 dvi_i_subconnector
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
815 drm_dvi_i_subconnector_enum_list
,
816 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
817 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
821 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
824 * drm_create_tv_properties - create TV specific connector properties
826 * @num_modes: number of different TV formats (modes) supported
827 * @modes: array of pointers to strings containing name of each format
829 * Called by a driver's TV initialization routine, this function creates
830 * the TV specific connector properties for a given device. Caller is
831 * responsible for allocating a list of format names and passing them to
834 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
837 struct drm_property
*tv_selector
;
838 struct drm_property
*tv_subconnector
;
841 if (dev
->mode_config
.tv_select_subconnector_property
)
845 * Basic connector properties
847 tv_selector
= drm_property_create_enum(dev
, 0,
848 "select subconnector",
849 drm_tv_select_enum_list
,
850 ARRAY_SIZE(drm_tv_select_enum_list
));
851 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
854 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
856 drm_tv_subconnector_enum_list
,
857 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
858 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
861 * Other, TV specific properties: margins & TV modes.
863 dev
->mode_config
.tv_left_margin_property
=
864 drm_property_create_range(dev
, 0, "left margin", 0, 100);
866 dev
->mode_config
.tv_right_margin_property
=
867 drm_property_create_range(dev
, 0, "right margin", 0, 100);
869 dev
->mode_config
.tv_top_margin_property
=
870 drm_property_create_range(dev
, 0, "top margin", 0, 100);
872 dev
->mode_config
.tv_bottom_margin_property
=
873 drm_property_create_range(dev
, 0, "bottom margin", 0, 100);
875 dev
->mode_config
.tv_mode_property
=
876 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
878 for (i
= 0; i
< num_modes
; i
++)
879 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
882 dev
->mode_config
.tv_brightness_property
=
883 drm_property_create_range(dev
, 0, "brightness", 0, 100);
885 dev
->mode_config
.tv_contrast_property
=
886 drm_property_create_range(dev
, 0, "contrast", 0, 100);
888 dev
->mode_config
.tv_flicker_reduction_property
=
889 drm_property_create_range(dev
, 0, "flicker reduction", 0, 100);
891 dev
->mode_config
.tv_overscan_property
=
892 drm_property_create_range(dev
, 0, "overscan", 0, 100);
894 dev
->mode_config
.tv_saturation_property
=
895 drm_property_create_range(dev
, 0, "saturation", 0, 100);
897 dev
->mode_config
.tv_hue_property
=
898 drm_property_create_range(dev
, 0, "hue", 0, 100);
902 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
905 * drm_mode_create_scaling_mode_property - create scaling mode property
908 * Called by a driver the first time it's needed, must be attached to desired
911 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
913 struct drm_property
*scaling_mode
;
915 if (dev
->mode_config
.scaling_mode_property
)
919 drm_property_create_enum(dev
, 0, "scaling mode",
920 drm_scaling_mode_enum_list
,
921 ARRAY_SIZE(drm_scaling_mode_enum_list
));
923 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
927 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
930 * drm_mode_create_dithering_property - create dithering property
933 * Called by a driver the first time it's needed, must be attached to desired
936 int drm_mode_create_dithering_property(struct drm_device
*dev
)
938 struct drm_property
*dithering_mode
;
940 if (dev
->mode_config
.dithering_mode_property
)
944 drm_property_create_enum(dev
, 0, "dithering",
945 drm_dithering_mode_enum_list
,
946 ARRAY_SIZE(drm_dithering_mode_enum_list
));
947 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
951 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
954 * drm_mode_create_dirty_property - create dirty property
957 * Called by a driver the first time it's needed, must be attached to desired
960 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
962 struct drm_property
*dirty_info
;
964 if (dev
->mode_config
.dirty_info_property
)
968 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
970 drm_dirty_info_enum_list
,
971 ARRAY_SIZE(drm_dirty_info_enum_list
));
972 dev
->mode_config
.dirty_info_property
= dirty_info
;
976 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
979 * drm_mode_config_init - initialize DRM mode_configuration structure
983 * None, should happen single threaded at init time.
985 * Initialize @dev's mode_config structure, used for tracking the graphics
986 * configuration of @dev.
988 void drm_mode_config_init(struct drm_device
*dev
)
990 mutex_init(&dev
->mode_config
.mutex
);
991 mutex_init(&dev
->mode_config
.idr_mutex
);
992 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
993 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
994 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
995 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
996 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
997 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
998 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
999 idr_init(&dev
->mode_config
.crtc_idr
);
1001 mutex_lock(&dev
->mode_config
.mutex
);
1002 drm_mode_create_standard_connector_properties(dev
);
1003 mutex_unlock(&dev
->mode_config
.mutex
);
1005 /* Just to be sure */
1006 dev
->mode_config
.num_fb
= 0;
1007 dev
->mode_config
.num_connector
= 0;
1008 dev
->mode_config
.num_crtc
= 0;
1009 dev
->mode_config
.num_encoder
= 0;
1011 EXPORT_SYMBOL(drm_mode_config_init
);
1013 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
1015 uint32_t total_objects
= 0;
1017 total_objects
+= dev
->mode_config
.num_crtc
;
1018 total_objects
+= dev
->mode_config
.num_connector
;
1019 total_objects
+= dev
->mode_config
.num_encoder
;
1021 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
1022 if (!group
->id_list
)
1025 group
->num_crtcs
= 0;
1026 group
->num_connectors
= 0;
1027 group
->num_encoders
= 0;
1031 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
1032 struct drm_mode_group
*group
)
1034 struct drm_crtc
*crtc
;
1035 struct drm_encoder
*encoder
;
1036 struct drm_connector
*connector
;
1039 if ((ret
= drm_mode_group_init(dev
, group
)))
1042 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
1043 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
1045 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
1046 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
1049 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
1050 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
1051 group
->num_connectors
++] = connector
->base
.id
;
1055 EXPORT_SYMBOL(drm_mode_group_init_legacy_group
);
1058 * drm_mode_config_cleanup - free up DRM mode_config info
1062 * Caller must hold mode config lock.
1064 * Free up all the connectors and CRTCs associated with this DRM device, then
1065 * free up the framebuffers and associated buffer objects.
1067 * FIXME: cleanup any dangling user buffer objects too
1069 void drm_mode_config_cleanup(struct drm_device
*dev
)
1071 struct drm_connector
*connector
, *ot
;
1072 struct drm_crtc
*crtc
, *ct
;
1073 struct drm_encoder
*encoder
, *enct
;
1074 struct drm_framebuffer
*fb
, *fbt
;
1075 struct drm_property
*property
, *pt
;
1076 struct drm_plane
*plane
, *plt
;
1078 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
1080 encoder
->funcs
->destroy(encoder
);
1083 list_for_each_entry_safe(connector
, ot
,
1084 &dev
->mode_config
.connector_list
, head
) {
1085 connector
->funcs
->destroy(connector
);
1088 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
1090 drm_property_destroy(dev
, property
);
1093 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
1094 drm_framebuffer_remove(fb
);
1097 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
1099 plane
->funcs
->destroy(plane
);
1102 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
1103 crtc
->funcs
->destroy(crtc
);
1106 idr_remove_all(&dev
->mode_config
.crtc_idr
);
1107 idr_destroy(&dev
->mode_config
.crtc_idr
);
1109 EXPORT_SYMBOL(drm_mode_config_cleanup
);
1112 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1113 * @out: drm_mode_modeinfo struct to return to the user
1114 * @in: drm_display_mode to use
1119 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1122 static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
1123 const struct drm_display_mode
*in
)
1125 WARN(in
->hdisplay
> USHRT_MAX
|| in
->hsync_start
> USHRT_MAX
||
1126 in
->hsync_end
> USHRT_MAX
|| in
->htotal
> USHRT_MAX
||
1127 in
->hskew
> USHRT_MAX
|| in
->vdisplay
> USHRT_MAX
||
1128 in
->vsync_start
> USHRT_MAX
|| in
->vsync_end
> USHRT_MAX
||
1129 in
->vtotal
> USHRT_MAX
|| in
->vscan
> USHRT_MAX
,
1130 "timing values too large for mode info\n");
1132 out
->clock
= in
->clock
;
1133 out
->hdisplay
= in
->hdisplay
;
1134 out
->hsync_start
= in
->hsync_start
;
1135 out
->hsync_end
= in
->hsync_end
;
1136 out
->htotal
= in
->htotal
;
1137 out
->hskew
= in
->hskew
;
1138 out
->vdisplay
= in
->vdisplay
;
1139 out
->vsync_start
= in
->vsync_start
;
1140 out
->vsync_end
= in
->vsync_end
;
1141 out
->vtotal
= in
->vtotal
;
1142 out
->vscan
= in
->vscan
;
1143 out
->vrefresh
= in
->vrefresh
;
1144 out
->flags
= in
->flags
;
1145 out
->type
= in
->type
;
1146 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1147 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1151 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1152 * @out: drm_display_mode to return to the user
1153 * @in: drm_mode_modeinfo to use
1158 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1162 * Zero on success, errno on failure.
1164 static int drm_crtc_convert_umode(struct drm_display_mode
*out
,
1165 const struct drm_mode_modeinfo
*in
)
1167 if (in
->clock
> INT_MAX
|| in
->vrefresh
> INT_MAX
)
1170 out
->clock
= in
->clock
;
1171 out
->hdisplay
= in
->hdisplay
;
1172 out
->hsync_start
= in
->hsync_start
;
1173 out
->hsync_end
= in
->hsync_end
;
1174 out
->htotal
= in
->htotal
;
1175 out
->hskew
= in
->hskew
;
1176 out
->vdisplay
= in
->vdisplay
;
1177 out
->vsync_start
= in
->vsync_start
;
1178 out
->vsync_end
= in
->vsync_end
;
1179 out
->vtotal
= in
->vtotal
;
1180 out
->vscan
= in
->vscan
;
1181 out
->vrefresh
= in
->vrefresh
;
1182 out
->flags
= in
->flags
;
1183 out
->type
= in
->type
;
1184 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1185 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1191 * drm_mode_getresources - get graphics configuration
1192 * @inode: inode from the ioctl
1193 * @filp: file * from the ioctl
1194 * @cmd: cmd from ioctl
1195 * @arg: arg from ioctl
1198 * Takes mode config lock.
1200 * Construct a set of configuration description structures and return
1201 * them to the user, including CRTC, connector and framebuffer configuration.
1203 * Called by the user via ioctl.
1206 * Zero on success, errno on failure.
1208 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1209 struct drm_file
*file_priv
)
1211 struct drm_mode_card_res
*card_res
= data
;
1212 struct list_head
*lh
;
1213 struct drm_framebuffer
*fb
;
1214 struct drm_connector
*connector
;
1215 struct drm_crtc
*crtc
;
1216 struct drm_encoder
*encoder
;
1218 int connector_count
= 0;
1221 int encoder_count
= 0;
1223 uint32_t __user
*fb_id
;
1224 uint32_t __user
*crtc_id
;
1225 uint32_t __user
*connector_id
;
1226 uint32_t __user
*encoder_id
;
1227 struct drm_mode_group
*mode_group
;
1229 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1232 mutex_lock(&dev
->mode_config
.mutex
);
1235 * For the non-control nodes we need to limit the list of resources
1236 * by IDs in the group list for this node
1238 list_for_each(lh
, &file_priv
->fbs
)
1241 mode_group
= &file_priv
->master
->minor
->mode_group
;
1242 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1244 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1247 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1250 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1254 crtc_count
= mode_group
->num_crtcs
;
1255 connector_count
= mode_group
->num_connectors
;
1256 encoder_count
= mode_group
->num_encoders
;
1259 card_res
->max_height
= dev
->mode_config
.max_height
;
1260 card_res
->min_height
= dev
->mode_config
.min_height
;
1261 card_res
->max_width
= dev
->mode_config
.max_width
;
1262 card_res
->min_width
= dev
->mode_config
.min_width
;
1264 /* handle this in 4 parts */
1266 if (card_res
->count_fbs
>= fb_count
) {
1268 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1269 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1270 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1277 card_res
->count_fbs
= fb_count
;
1280 if (card_res
->count_crtcs
>= crtc_count
) {
1282 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1283 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1284 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1286 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1287 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1294 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1295 if (put_user(mode_group
->id_list
[i
],
1296 crtc_id
+ copied
)) {
1304 card_res
->count_crtcs
= crtc_count
;
1307 if (card_res
->count_encoders
>= encoder_count
) {
1309 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1310 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1311 list_for_each_entry(encoder
,
1312 &dev
->mode_config
.encoder_list
,
1314 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1315 drm_get_encoder_name(encoder
));
1316 if (put_user(encoder
->base
.id
, encoder_id
+
1324 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1325 if (put_user(mode_group
->id_list
[i
],
1326 encoder_id
+ copied
)) {
1335 card_res
->count_encoders
= encoder_count
;
1338 if (card_res
->count_connectors
>= connector_count
) {
1340 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1341 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1342 list_for_each_entry(connector
,
1343 &dev
->mode_config
.connector_list
,
1345 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1347 drm_get_connector_name(connector
));
1348 if (put_user(connector
->base
.id
,
1349 connector_id
+ copied
)) {
1356 int start
= mode_group
->num_crtcs
+
1357 mode_group
->num_encoders
;
1358 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1359 if (put_user(mode_group
->id_list
[i
],
1360 connector_id
+ copied
)) {
1368 card_res
->count_connectors
= connector_count
;
1370 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1371 card_res
->count_connectors
, card_res
->count_encoders
);
1374 mutex_unlock(&dev
->mode_config
.mutex
);
1379 * drm_mode_getcrtc - get CRTC configuration
1380 * @inode: inode from the ioctl
1381 * @filp: file * from the ioctl
1382 * @cmd: cmd from ioctl
1383 * @arg: arg from ioctl
1386 * Takes mode config lock.
1388 * Construct a CRTC configuration structure to return to the user.
1390 * Called by the user via ioctl.
1393 * Zero on success, errno on failure.
1395 int drm_mode_getcrtc(struct drm_device
*dev
,
1396 void *data
, struct drm_file
*file_priv
)
1398 struct drm_mode_crtc
*crtc_resp
= data
;
1399 struct drm_crtc
*crtc
;
1400 struct drm_mode_object
*obj
;
1403 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1406 mutex_lock(&dev
->mode_config
.mutex
);
1408 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1409 DRM_MODE_OBJECT_CRTC
);
1414 crtc
= obj_to_crtc(obj
);
1416 crtc_resp
->x
= crtc
->x
;
1417 crtc_resp
->y
= crtc
->y
;
1418 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1420 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1422 crtc_resp
->fb_id
= 0;
1424 if (crtc
->enabled
) {
1426 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1427 crtc_resp
->mode_valid
= 1;
1430 crtc_resp
->mode_valid
= 0;
1434 mutex_unlock(&dev
->mode_config
.mutex
);
1439 * drm_mode_getconnector - get connector configuration
1440 * @inode: inode from the ioctl
1441 * @filp: file * from the ioctl
1442 * @cmd: cmd from ioctl
1443 * @arg: arg from ioctl
1446 * Takes mode config lock.
1448 * Construct a connector configuration structure to return to the user.
1450 * Called by the user via ioctl.
1453 * Zero on success, errno on failure.
1455 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1456 struct drm_file
*file_priv
)
1458 struct drm_mode_get_connector
*out_resp
= data
;
1459 struct drm_mode_object
*obj
;
1460 struct drm_connector
*connector
;
1461 struct drm_display_mode
*mode
;
1463 int props_count
= 0;
1464 int encoders_count
= 0;
1468 struct drm_mode_modeinfo u_mode
;
1469 struct drm_mode_modeinfo __user
*mode_ptr
;
1470 uint32_t __user
*prop_ptr
;
1471 uint64_t __user
*prop_values
;
1472 uint32_t __user
*encoder_ptr
;
1474 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1477 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1479 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1481 mutex_lock(&dev
->mode_config
.mutex
);
1483 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1484 DRM_MODE_OBJECT_CONNECTOR
);
1489 connector
= obj_to_connector(obj
);
1491 props_count
= connector
->properties
.count
;
1493 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1494 if (connector
->encoder_ids
[i
] != 0) {
1499 if (out_resp
->count_modes
== 0) {
1500 connector
->funcs
->fill_modes(connector
,
1501 dev
->mode_config
.max_width
,
1502 dev
->mode_config
.max_height
);
1505 /* delayed so we get modes regardless of pre-fill_modes state */
1506 list_for_each_entry(mode
, &connector
->modes
, head
)
1509 out_resp
->connector_id
= connector
->base
.id
;
1510 out_resp
->connector_type
= connector
->connector_type
;
1511 out_resp
->connector_type_id
= connector
->connector_type_id
;
1512 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1513 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1514 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1515 out_resp
->connection
= connector
->status
;
1516 if (connector
->encoder
)
1517 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1519 out_resp
->encoder_id
= 0;
1522 * This ioctl is called twice, once to determine how much space is
1523 * needed, and the 2nd time to fill it.
1525 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1527 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1528 list_for_each_entry(mode
, &connector
->modes
, head
) {
1529 drm_crtc_convert_to_umode(&u_mode
, mode
);
1530 if (copy_to_user(mode_ptr
+ copied
,
1531 &u_mode
, sizeof(u_mode
))) {
1538 out_resp
->count_modes
= mode_count
;
1540 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1542 prop_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
);
1543 prop_values
= (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
);
1544 for (i
= 0; i
< connector
->properties
.count
; i
++) {
1545 if (put_user(connector
->properties
.ids
[i
],
1546 prop_ptr
+ copied
)) {
1551 if (put_user(connector
->properties
.values
[i
],
1552 prop_values
+ copied
)) {
1559 out_resp
->count_props
= props_count
;
1561 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1563 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1564 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1565 if (connector
->encoder_ids
[i
] != 0) {
1566 if (put_user(connector
->encoder_ids
[i
],
1567 encoder_ptr
+ copied
)) {
1575 out_resp
->count_encoders
= encoders_count
;
1578 mutex_unlock(&dev
->mode_config
.mutex
);
1582 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1583 struct drm_file
*file_priv
)
1585 struct drm_mode_get_encoder
*enc_resp
= data
;
1586 struct drm_mode_object
*obj
;
1587 struct drm_encoder
*encoder
;
1590 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1593 mutex_lock(&dev
->mode_config
.mutex
);
1594 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1595 DRM_MODE_OBJECT_ENCODER
);
1600 encoder
= obj_to_encoder(obj
);
1603 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1605 enc_resp
->crtc_id
= 0;
1606 enc_resp
->encoder_type
= encoder
->encoder_type
;
1607 enc_resp
->encoder_id
= encoder
->base
.id
;
1608 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1609 enc_resp
->possible_clones
= encoder
->possible_clones
;
1612 mutex_unlock(&dev
->mode_config
.mutex
);
1617 * drm_mode_getplane_res - get plane info
1620 * @file_priv: DRM file info
1623 * Takes mode config lock.
1625 * Return an plane count and set of IDs.
1627 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
1628 struct drm_file
*file_priv
)
1630 struct drm_mode_get_plane_res
*plane_resp
= data
;
1631 struct drm_mode_config
*config
;
1632 struct drm_plane
*plane
;
1633 uint32_t __user
*plane_ptr
;
1634 int copied
= 0, ret
= 0;
1636 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1639 mutex_lock(&dev
->mode_config
.mutex
);
1640 config
= &dev
->mode_config
;
1643 * This ioctl is called twice, once to determine how much space is
1644 * needed, and the 2nd time to fill it.
1646 if (config
->num_plane
&&
1647 (plane_resp
->count_planes
>= config
->num_plane
)) {
1648 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
1650 list_for_each_entry(plane
, &config
->plane_list
, head
) {
1651 if (put_user(plane
->base
.id
, plane_ptr
+ copied
)) {
1658 plane_resp
->count_planes
= config
->num_plane
;
1661 mutex_unlock(&dev
->mode_config
.mutex
);
1666 * drm_mode_getplane - get plane info
1669 * @file_priv: DRM file info
1672 * Takes mode config lock.
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 mutex_lock(&dev
->mode_config
.mutex
);
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 mutex_unlock(&dev
->mode_config
.mutex
);
1734 * drm_mode_setplane - set up or tear down an plane
1736 * @data: ioctl data*
1737 * @file_prive: DRM file info
1740 * Takes mode config lock.
1742 * Set plane info, including placement, fb, scaling, and other factors.
1743 * Or pass a NULL fb to disable.
1745 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
1746 struct drm_file
*file_priv
)
1748 struct drm_mode_set_plane
*plane_req
= data
;
1749 struct drm_mode_object
*obj
;
1750 struct drm_plane
*plane
;
1751 struct drm_crtc
*crtc
;
1752 struct drm_framebuffer
*fb
;
1754 unsigned int fb_width
, fb_height
;
1757 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1760 mutex_lock(&dev
->mode_config
.mutex
);
1763 * First, find the plane, crtc, and fb objects. If not available,
1764 * we don't bother to call the driver.
1766 obj
= drm_mode_object_find(dev
, plane_req
->plane_id
,
1767 DRM_MODE_OBJECT_PLANE
);
1769 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1770 plane_req
->plane_id
);
1774 plane
= obj_to_plane(obj
);
1776 /* No fb means shut it down */
1777 if (!plane_req
->fb_id
) {
1778 plane
->funcs
->disable_plane(plane
);
1784 obj
= drm_mode_object_find(dev
, plane_req
->crtc_id
,
1785 DRM_MODE_OBJECT_CRTC
);
1787 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1788 plane_req
->crtc_id
);
1792 crtc
= obj_to_crtc(obj
);
1794 obj
= drm_mode_object_find(dev
, plane_req
->fb_id
,
1795 DRM_MODE_OBJECT_FB
);
1797 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1802 fb
= obj_to_fb(obj
);
1804 /* Check whether this plane supports the fb pixel format. */
1805 for (i
= 0; i
< plane
->format_count
; i
++)
1806 if (fb
->pixel_format
== plane
->format_types
[i
])
1808 if (i
== plane
->format_count
) {
1809 DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb
->pixel_format
);
1814 fb_width
= fb
->width
<< 16;
1815 fb_height
= fb
->height
<< 16;
1817 /* Make sure source coordinates are inside the fb. */
1818 if (plane_req
->src_w
> fb_width
||
1819 plane_req
->src_x
> fb_width
- plane_req
->src_w
||
1820 plane_req
->src_h
> fb_height
||
1821 plane_req
->src_y
> fb_height
- plane_req
->src_h
) {
1822 DRM_DEBUG_KMS("Invalid source coordinates "
1823 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1824 plane_req
->src_w
>> 16,
1825 ((plane_req
->src_w
& 0xffff) * 15625) >> 10,
1826 plane_req
->src_h
>> 16,
1827 ((plane_req
->src_h
& 0xffff) * 15625) >> 10,
1828 plane_req
->src_x
>> 16,
1829 ((plane_req
->src_x
& 0xffff) * 15625) >> 10,
1830 plane_req
->src_y
>> 16,
1831 ((plane_req
->src_y
& 0xffff) * 15625) >> 10);
1836 /* Give drivers some help against integer overflows */
1837 if (plane_req
->crtc_w
> INT_MAX
||
1838 plane_req
->crtc_x
> INT_MAX
- (int32_t) plane_req
->crtc_w
||
1839 plane_req
->crtc_h
> INT_MAX
||
1840 plane_req
->crtc_y
> INT_MAX
- (int32_t) plane_req
->crtc_h
) {
1841 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
1842 plane_req
->crtc_w
, plane_req
->crtc_h
,
1843 plane_req
->crtc_x
, plane_req
->crtc_y
);
1848 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
1849 plane_req
->crtc_x
, plane_req
->crtc_y
,
1850 plane_req
->crtc_w
, plane_req
->crtc_h
,
1851 plane_req
->src_x
, plane_req
->src_y
,
1852 plane_req
->src_w
, plane_req
->src_h
);
1859 mutex_unlock(&dev
->mode_config
.mutex
);
1865 * drm_mode_setcrtc - set CRTC configuration
1866 * @inode: inode from the ioctl
1867 * @filp: file * from the ioctl
1868 * @cmd: cmd from ioctl
1869 * @arg: arg from ioctl
1872 * Takes mode config lock.
1874 * Build a new CRTC configuration based on user request.
1876 * Called by the user via ioctl.
1879 * Zero on success, errno on failure.
1881 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1882 struct drm_file
*file_priv
)
1884 struct drm_mode_config
*config
= &dev
->mode_config
;
1885 struct drm_mode_crtc
*crtc_req
= data
;
1886 struct drm_mode_object
*obj
;
1887 struct drm_crtc
*crtc
;
1888 struct drm_connector
**connector_set
= NULL
, *connector
;
1889 struct drm_framebuffer
*fb
= NULL
;
1890 struct drm_display_mode
*mode
= NULL
;
1891 struct drm_mode_set set
;
1892 uint32_t __user
*set_connectors_ptr
;
1896 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1899 /* For some reason crtc x/y offsets are signed internally. */
1900 if (crtc_req
->x
> INT_MAX
|| crtc_req
->y
> INT_MAX
)
1903 mutex_lock(&dev
->mode_config
.mutex
);
1904 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
1905 DRM_MODE_OBJECT_CRTC
);
1907 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1911 crtc
= obj_to_crtc(obj
);
1912 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1914 if (crtc_req
->mode_valid
) {
1915 int hdisplay
, vdisplay
;
1916 /* If we have a mode we need a framebuffer. */
1917 /* If we pass -1, set the mode with the currently bound fb */
1918 if (crtc_req
->fb_id
== -1) {
1920 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
1926 obj
= drm_mode_object_find(dev
, crtc_req
->fb_id
,
1927 DRM_MODE_OBJECT_FB
);
1929 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1934 fb
= obj_to_fb(obj
);
1937 mode
= drm_mode_create(dev
);
1943 ret
= drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
1945 DRM_DEBUG_KMS("Invalid mode\n");
1949 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
1951 hdisplay
= mode
->hdisplay
;
1952 vdisplay
= mode
->vdisplay
;
1954 if (crtc
->invert_dimensions
)
1955 swap(hdisplay
, vdisplay
);
1957 if (hdisplay
> fb
->width
||
1958 vdisplay
> fb
->height
||
1959 crtc_req
->x
> fb
->width
- hdisplay
||
1960 crtc_req
->y
> fb
->height
- vdisplay
) {
1961 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
1962 fb
->width
, fb
->height
,
1963 hdisplay
, vdisplay
, crtc_req
->x
, crtc_req
->y
,
1964 crtc
->invert_dimensions
? " (inverted)" : "");
1970 if (crtc_req
->count_connectors
== 0 && mode
) {
1971 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1976 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
1977 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1978 crtc_req
->count_connectors
);
1983 if (crtc_req
->count_connectors
> 0) {
1986 /* Avoid unbounded kernel memory allocation */
1987 if (crtc_req
->count_connectors
> config
->num_connector
) {
1992 connector_set
= kmalloc(crtc_req
->count_connectors
*
1993 sizeof(struct drm_connector
*),
1995 if (!connector_set
) {
2000 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
2001 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
2002 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
2007 obj
= drm_mode_object_find(dev
, out_id
,
2008 DRM_MODE_OBJECT_CONNECTOR
);
2010 DRM_DEBUG_KMS("Connector id %d unknown\n",
2015 connector
= obj_to_connector(obj
);
2016 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2018 drm_get_connector_name(connector
));
2020 connector_set
[i
] = connector
;
2025 set
.x
= crtc_req
->x
;
2026 set
.y
= crtc_req
->y
;
2028 set
.connectors
= connector_set
;
2029 set
.num_connectors
= crtc_req
->count_connectors
;
2031 ret
= crtc
->funcs
->set_config(&set
);
2034 kfree(connector_set
);
2035 drm_mode_destroy(dev
, mode
);
2036 mutex_unlock(&dev
->mode_config
.mutex
);
2040 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
2041 void *data
, struct drm_file
*file_priv
)
2043 struct drm_mode_cursor
*req
= data
;
2044 struct drm_mode_object
*obj
;
2045 struct drm_crtc
*crtc
;
2048 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2051 if (!req
->flags
|| (~DRM_MODE_CURSOR_FLAGS
& req
->flags
))
2054 mutex_lock(&dev
->mode_config
.mutex
);
2055 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2057 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
2061 crtc
= obj_to_crtc(obj
);
2063 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
2064 if (!crtc
->funcs
->cursor_set
) {
2068 /* Turns off the cursor if handle is 0 */
2069 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
2070 req
->width
, req
->height
);
2073 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
2074 if (crtc
->funcs
->cursor_move
) {
2075 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
2082 mutex_unlock(&dev
->mode_config
.mutex
);
2086 /* Original addfb only supported RGB formats, so figure out which one */
2087 uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
)
2093 fmt
= DRM_FORMAT_RGB332
;
2097 fmt
= DRM_FORMAT_XRGB1555
;
2099 fmt
= DRM_FORMAT_RGB565
;
2102 fmt
= DRM_FORMAT_RGB888
;
2106 fmt
= DRM_FORMAT_XRGB8888
;
2107 else if (depth
== 30)
2108 fmt
= DRM_FORMAT_XRGB2101010
;
2110 fmt
= DRM_FORMAT_ARGB8888
;
2113 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
2114 fmt
= DRM_FORMAT_XRGB8888
;
2120 EXPORT_SYMBOL(drm_mode_legacy_fb_format
);
2123 * drm_mode_addfb - add an FB to the graphics configuration
2124 * @inode: inode from the ioctl
2125 * @filp: file * from the ioctl
2126 * @cmd: cmd from ioctl
2127 * @arg: arg from ioctl
2130 * Takes mode config lock.
2132 * Add a new FB to the specified CRTC, given a user request.
2134 * Called by the user via ioctl.
2137 * Zero on success, errno on failure.
2139 int drm_mode_addfb(struct drm_device
*dev
,
2140 void *data
, struct drm_file
*file_priv
)
2142 struct drm_mode_fb_cmd
*or = data
;
2143 struct drm_mode_fb_cmd2 r
= {};
2144 struct drm_mode_config
*config
= &dev
->mode_config
;
2145 struct drm_framebuffer
*fb
;
2148 /* Use new struct with format internally */
2149 r
.fb_id
= or->fb_id
;
2150 r
.width
= or->width
;
2151 r
.height
= or->height
;
2152 r
.pitches
[0] = or->pitch
;
2153 r
.pixel_format
= drm_mode_legacy_fb_format(or->bpp
, or->depth
);
2154 r
.handles
[0] = or->handle
;
2156 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2159 if ((config
->min_width
> r
.width
) || (r
.width
> config
->max_width
))
2162 if ((config
->min_height
> r
.height
) || (r
.height
> config
->max_height
))
2165 mutex_lock(&dev
->mode_config
.mutex
);
2167 /* TODO check buffer is sufficiently large */
2168 /* TODO setup destructor callback */
2170 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, &r
);
2172 DRM_DEBUG_KMS("could not create framebuffer\n");
2177 or->fb_id
= fb
->base
.id
;
2178 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2179 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2182 mutex_unlock(&dev
->mode_config
.mutex
);
2186 static int format_check(const struct drm_mode_fb_cmd2
*r
)
2188 uint32_t format
= r
->pixel_format
& ~DRM_FORMAT_BIG_ENDIAN
;
2192 case DRM_FORMAT_RGB332
:
2193 case DRM_FORMAT_BGR233
:
2194 case DRM_FORMAT_XRGB4444
:
2195 case DRM_FORMAT_XBGR4444
:
2196 case DRM_FORMAT_RGBX4444
:
2197 case DRM_FORMAT_BGRX4444
:
2198 case DRM_FORMAT_ARGB4444
:
2199 case DRM_FORMAT_ABGR4444
:
2200 case DRM_FORMAT_RGBA4444
:
2201 case DRM_FORMAT_BGRA4444
:
2202 case DRM_FORMAT_XRGB1555
:
2203 case DRM_FORMAT_XBGR1555
:
2204 case DRM_FORMAT_RGBX5551
:
2205 case DRM_FORMAT_BGRX5551
:
2206 case DRM_FORMAT_ARGB1555
:
2207 case DRM_FORMAT_ABGR1555
:
2208 case DRM_FORMAT_RGBA5551
:
2209 case DRM_FORMAT_BGRA5551
:
2210 case DRM_FORMAT_RGB565
:
2211 case DRM_FORMAT_BGR565
:
2212 case DRM_FORMAT_RGB888
:
2213 case DRM_FORMAT_BGR888
:
2214 case DRM_FORMAT_XRGB8888
:
2215 case DRM_FORMAT_XBGR8888
:
2216 case DRM_FORMAT_RGBX8888
:
2217 case DRM_FORMAT_BGRX8888
:
2218 case DRM_FORMAT_ARGB8888
:
2219 case DRM_FORMAT_ABGR8888
:
2220 case DRM_FORMAT_RGBA8888
:
2221 case DRM_FORMAT_BGRA8888
:
2222 case DRM_FORMAT_XRGB2101010
:
2223 case DRM_FORMAT_XBGR2101010
:
2224 case DRM_FORMAT_RGBX1010102
:
2225 case DRM_FORMAT_BGRX1010102
:
2226 case DRM_FORMAT_ARGB2101010
:
2227 case DRM_FORMAT_ABGR2101010
:
2228 case DRM_FORMAT_RGBA1010102
:
2229 case DRM_FORMAT_BGRA1010102
:
2230 case DRM_FORMAT_YUYV
:
2231 case DRM_FORMAT_YVYU
:
2232 case DRM_FORMAT_UYVY
:
2233 case DRM_FORMAT_VYUY
:
2234 case DRM_FORMAT_AYUV
:
2235 case DRM_FORMAT_NV12
:
2236 case DRM_FORMAT_NV21
:
2237 case DRM_FORMAT_NV16
:
2238 case DRM_FORMAT_NV61
:
2239 case DRM_FORMAT_NV24
:
2240 case DRM_FORMAT_NV42
:
2241 case DRM_FORMAT_YUV410
:
2242 case DRM_FORMAT_YVU410
:
2243 case DRM_FORMAT_YUV411
:
2244 case DRM_FORMAT_YVU411
:
2245 case DRM_FORMAT_YUV420
:
2246 case DRM_FORMAT_YVU420
:
2247 case DRM_FORMAT_YUV422
:
2248 case DRM_FORMAT_YVU422
:
2249 case DRM_FORMAT_YUV444
:
2250 case DRM_FORMAT_YVU444
:
2257 static int framebuffer_check(const struct drm_mode_fb_cmd2
*r
)
2259 int ret
, hsub
, vsub
, num_planes
, i
;
2261 ret
= format_check(r
);
2263 DRM_DEBUG_KMS("bad framebuffer format 0x%08x\n", r
->pixel_format
);
2267 hsub
= drm_format_horz_chroma_subsampling(r
->pixel_format
);
2268 vsub
= drm_format_vert_chroma_subsampling(r
->pixel_format
);
2269 num_planes
= drm_format_num_planes(r
->pixel_format
);
2271 if (r
->width
== 0 || r
->width
% hsub
) {
2272 DRM_DEBUG_KMS("bad framebuffer width %u\n", r
->height
);
2276 if (r
->height
== 0 || r
->height
% vsub
) {
2277 DRM_DEBUG_KMS("bad framebuffer height %u\n", r
->height
);
2281 for (i
= 0; i
< num_planes
; i
++) {
2282 unsigned int width
= r
->width
/ (i
!= 0 ? hsub
: 1);
2284 if (!r
->handles
[i
]) {
2285 DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i
);
2289 if (r
->pitches
[i
] < drm_format_plane_cpp(r
->pixel_format
, i
) * width
) {
2290 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r
->pitches
[i
], i
);
2299 * drm_mode_addfb2 - add an FB to the graphics configuration
2300 * @inode: inode from the ioctl
2301 * @filp: file * from the ioctl
2302 * @cmd: cmd from ioctl
2303 * @arg: arg from ioctl
2306 * Takes mode config lock.
2308 * Add a new FB to the specified CRTC, given a user request with format.
2310 * Called by the user via ioctl.
2313 * Zero on success, errno on failure.
2315 int drm_mode_addfb2(struct drm_device
*dev
,
2316 void *data
, struct drm_file
*file_priv
)
2318 struct drm_mode_fb_cmd2
*r
= data
;
2319 struct drm_mode_config
*config
= &dev
->mode_config
;
2320 struct drm_framebuffer
*fb
;
2323 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2326 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
2327 DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
2328 r
->width
, config
->min_width
, config
->max_width
);
2331 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
2332 DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
2333 r
->height
, config
->min_height
, config
->max_height
);
2337 ret
= framebuffer_check(r
);
2341 mutex_lock(&dev
->mode_config
.mutex
);
2343 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
2345 DRM_DEBUG_KMS("could not create framebuffer\n");
2350 r
->fb_id
= fb
->base
.id
;
2351 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2352 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2355 mutex_unlock(&dev
->mode_config
.mutex
);
2360 * drm_mode_rmfb - remove an FB from the configuration
2361 * @inode: inode from the ioctl
2362 * @filp: file * from the ioctl
2363 * @cmd: cmd from ioctl
2364 * @arg: arg from ioctl
2367 * Takes mode config lock.
2369 * Remove the FB specified by the user.
2371 * Called by the user via ioctl.
2374 * Zero on success, errno on failure.
2376 int drm_mode_rmfb(struct drm_device
*dev
,
2377 void *data
, struct drm_file
*file_priv
)
2379 struct drm_mode_object
*obj
;
2380 struct drm_framebuffer
*fb
= NULL
;
2381 struct drm_framebuffer
*fbl
= NULL
;
2382 uint32_t *id
= data
;
2386 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2389 mutex_lock(&dev
->mode_config
.mutex
);
2390 obj
= drm_mode_object_find(dev
, *id
, DRM_MODE_OBJECT_FB
);
2391 /* TODO check that we really get a framebuffer back. */
2396 fb
= obj_to_fb(obj
);
2398 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
2407 drm_framebuffer_remove(fb
);
2410 mutex_unlock(&dev
->mode_config
.mutex
);
2415 * drm_mode_getfb - get FB info
2416 * @inode: inode from the ioctl
2417 * @filp: file * from the ioctl
2418 * @cmd: cmd from ioctl
2419 * @arg: arg from ioctl
2422 * Takes mode config lock.
2424 * Lookup the FB given its ID and return info about it.
2426 * Called by the user via ioctl.
2429 * Zero on success, errno on failure.
2431 int drm_mode_getfb(struct drm_device
*dev
,
2432 void *data
, struct drm_file
*file_priv
)
2434 struct drm_mode_fb_cmd
*r
= data
;
2435 struct drm_mode_object
*obj
;
2436 struct drm_framebuffer
*fb
;
2439 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2442 mutex_lock(&dev
->mode_config
.mutex
);
2443 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
2448 fb
= obj_to_fb(obj
);
2450 r
->height
= fb
->height
;
2451 r
->width
= fb
->width
;
2452 r
->depth
= fb
->depth
;
2453 r
->bpp
= fb
->bits_per_pixel
;
2454 r
->pitch
= fb
->pitches
[0];
2455 fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
2458 mutex_unlock(&dev
->mode_config
.mutex
);
2462 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2463 void *data
, struct drm_file
*file_priv
)
2465 struct drm_clip_rect __user
*clips_ptr
;
2466 struct drm_clip_rect
*clips
= NULL
;
2467 struct drm_mode_fb_dirty_cmd
*r
= data
;
2468 struct drm_mode_object
*obj
;
2469 struct drm_framebuffer
*fb
;
2474 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2477 mutex_lock(&dev
->mode_config
.mutex
);
2478 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
2483 fb
= obj_to_fb(obj
);
2485 num_clips
= r
->num_clips
;
2486 clips_ptr
= (struct drm_clip_rect __user
*)(unsigned long)r
->clips_ptr
;
2488 if (!num_clips
!= !clips_ptr
) {
2493 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
2495 /* If userspace annotates copy, clips must come in pairs */
2496 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
2501 if (num_clips
&& clips_ptr
) {
2502 if (num_clips
< 0 || num_clips
> DRM_MODE_FB_DIRTY_MAX_CLIPS
) {
2506 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
2512 ret
= copy_from_user(clips
, clips_ptr
,
2513 num_clips
* sizeof(*clips
));
2520 if (fb
->funcs
->dirty
) {
2521 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
2531 mutex_unlock(&dev
->mode_config
.mutex
);
2537 * drm_fb_release - remove and free the FBs on this file
2538 * @filp: file * from the ioctl
2541 * Takes mode config lock.
2543 * Destroy all the FBs associated with @filp.
2545 * Called by the user via ioctl.
2548 * Zero on success, errno on failure.
2550 void drm_fb_release(struct drm_file
*priv
)
2552 struct drm_device
*dev
= priv
->minor
->dev
;
2553 struct drm_framebuffer
*fb
, *tfb
;
2555 mutex_lock(&dev
->mode_config
.mutex
);
2556 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
2557 drm_framebuffer_remove(fb
);
2559 mutex_unlock(&dev
->mode_config
.mutex
);
2563 * drm_mode_attachmode - add a mode to the user mode list
2565 * @connector: connector to add the mode to
2566 * @mode: mode to add
2568 * Add @mode to @connector's user mode list.
2570 static void drm_mode_attachmode(struct drm_device
*dev
,
2571 struct drm_connector
*connector
,
2572 struct drm_display_mode
*mode
)
2574 list_add_tail(&mode
->head
, &connector
->user_modes
);
2577 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
2578 const struct drm_display_mode
*mode
)
2580 struct drm_connector
*connector
;
2582 struct drm_display_mode
*dup_mode
, *next
;
2585 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2586 if (!connector
->encoder
)
2588 if (connector
->encoder
->crtc
== crtc
) {
2589 dup_mode
= drm_mode_duplicate(dev
, mode
);
2594 list_add_tail(&dup_mode
->head
, &list
);
2598 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2599 if (!connector
->encoder
)
2601 if (connector
->encoder
->crtc
== crtc
)
2602 list_move_tail(list
.next
, &connector
->user_modes
);
2605 WARN_ON(!list_empty(&list
));
2608 list_for_each_entry_safe(dup_mode
, next
, &list
, head
)
2609 drm_mode_destroy(dev
, dup_mode
);
2613 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
2615 static int drm_mode_detachmode(struct drm_device
*dev
,
2616 struct drm_connector
*connector
,
2617 struct drm_display_mode
*mode
)
2621 struct drm_display_mode
*match_mode
, *t
;
2623 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
2624 if (drm_mode_equal(match_mode
, mode
)) {
2625 list_del(&match_mode
->head
);
2626 drm_mode_destroy(dev
, match_mode
);
2638 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
2640 struct drm_connector
*connector
;
2642 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2643 drm_mode_detachmode(dev
, connector
, mode
);
2647 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
2650 * drm_fb_attachmode - Attach a user mode to an connector
2651 * @inode: inode from the ioctl
2652 * @filp: file * from the ioctl
2653 * @cmd: cmd from ioctl
2654 * @arg: arg from ioctl
2656 * This attaches a user specified mode to an connector.
2657 * Called by the user via ioctl.
2660 * Zero on success, errno on failure.
2662 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
2663 void *data
, struct drm_file
*file_priv
)
2665 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2666 struct drm_connector
*connector
;
2667 struct drm_display_mode
*mode
;
2668 struct drm_mode_object
*obj
;
2669 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2672 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2675 mutex_lock(&dev
->mode_config
.mutex
);
2677 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2682 connector
= obj_to_connector(obj
);
2684 mode
= drm_mode_create(dev
);
2690 ret
= drm_crtc_convert_umode(mode
, umode
);
2692 DRM_DEBUG_KMS("Invalid mode\n");
2693 drm_mode_destroy(dev
, mode
);
2697 drm_mode_attachmode(dev
, connector
, mode
);
2699 mutex_unlock(&dev
->mode_config
.mutex
);
2705 * drm_fb_detachmode - Detach a user specified mode from an connector
2706 * @inode: inode from the ioctl
2707 * @filp: file * from the ioctl
2708 * @cmd: cmd from ioctl
2709 * @arg: arg from ioctl
2711 * Called by the user via ioctl.
2714 * Zero on success, errno on failure.
2716 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
2717 void *data
, struct drm_file
*file_priv
)
2719 struct drm_mode_object
*obj
;
2720 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2721 struct drm_connector
*connector
;
2722 struct drm_display_mode mode
;
2723 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2726 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2729 mutex_lock(&dev
->mode_config
.mutex
);
2731 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2736 connector
= obj_to_connector(obj
);
2738 ret
= drm_crtc_convert_umode(&mode
, umode
);
2740 DRM_DEBUG_KMS("Invalid mode\n");
2744 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
2746 mutex_unlock(&dev
->mode_config
.mutex
);
2750 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2751 const char *name
, int num_values
)
2753 struct drm_property
*property
= NULL
;
2756 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2761 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2762 if (!property
->values
)
2766 ret
= drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2770 property
->flags
= flags
;
2771 property
->num_values
= num_values
;
2772 INIT_LIST_HEAD(&property
->enum_blob_list
);
2775 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2776 property
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2779 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2782 kfree(property
->values
);
2786 EXPORT_SYMBOL(drm_property_create
);
2788 struct drm_property
*drm_property_create_enum(struct drm_device
*dev
, int flags
,
2790 const struct drm_prop_enum_list
*props
,
2793 struct drm_property
*property
;
2796 flags
|= DRM_MODE_PROP_ENUM
;
2798 property
= drm_property_create(dev
, flags
, name
, num_values
);
2802 for (i
= 0; i
< num_values
; i
++) {
2803 ret
= drm_property_add_enum(property
, i
,
2807 drm_property_destroy(dev
, property
);
2814 EXPORT_SYMBOL(drm_property_create_enum
);
2816 struct drm_property
*drm_property_create_bitmask(struct drm_device
*dev
,
2817 int flags
, const char *name
,
2818 const struct drm_prop_enum_list
*props
,
2821 struct drm_property
*property
;
2824 flags
|= DRM_MODE_PROP_BITMASK
;
2826 property
= drm_property_create(dev
, flags
, name
, num_values
);
2830 for (i
= 0; i
< num_values
; i
++) {
2831 ret
= drm_property_add_enum(property
, i
,
2835 drm_property_destroy(dev
, property
);
2842 EXPORT_SYMBOL(drm_property_create_bitmask
);
2844 struct drm_property
*drm_property_create_range(struct drm_device
*dev
, int flags
,
2846 uint64_t min
, uint64_t max
)
2848 struct drm_property
*property
;
2850 flags
|= DRM_MODE_PROP_RANGE
;
2852 property
= drm_property_create(dev
, flags
, name
, 2);
2856 property
->values
[0] = min
;
2857 property
->values
[1] = max
;
2861 EXPORT_SYMBOL(drm_property_create_range
);
2863 int drm_property_add_enum(struct drm_property
*property
, int index
,
2864 uint64_t value
, const char *name
)
2866 struct drm_property_enum
*prop_enum
;
2868 if (!(property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)))
2872 * Bitmask enum properties have the additional constraint of values
2875 if ((property
->flags
& DRM_MODE_PROP_BITMASK
) && (value
> 63))
2878 if (!list_empty(&property
->enum_blob_list
)) {
2879 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2880 if (prop_enum
->value
== value
) {
2881 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2882 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2888 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2892 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2893 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2894 prop_enum
->value
= value
;
2896 property
->values
[index
] = value
;
2897 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2900 EXPORT_SYMBOL(drm_property_add_enum
);
2902 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2904 struct drm_property_enum
*prop_enum
, *pt
;
2906 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2907 list_del(&prop_enum
->head
);
2911 if (property
->num_values
)
2912 kfree(property
->values
);
2913 drm_mode_object_put(dev
, &property
->base
);
2914 list_del(&property
->head
);
2917 EXPORT_SYMBOL(drm_property_destroy
);
2919 void drm_connector_attach_property(struct drm_connector
*connector
,
2920 struct drm_property
*property
, uint64_t init_val
)
2922 drm_object_attach_property(&connector
->base
, property
, init_val
);
2924 EXPORT_SYMBOL(drm_connector_attach_property
);
2926 int drm_connector_property_set_value(struct drm_connector
*connector
,
2927 struct drm_property
*property
, uint64_t value
)
2929 return drm_object_property_set_value(&connector
->base
, property
, value
);
2931 EXPORT_SYMBOL(drm_connector_property_set_value
);
2933 int drm_connector_property_get_value(struct drm_connector
*connector
,
2934 struct drm_property
*property
, uint64_t *val
)
2936 return drm_object_property_get_value(&connector
->base
, property
, val
);
2938 EXPORT_SYMBOL(drm_connector_property_get_value
);
2940 void drm_object_attach_property(struct drm_mode_object
*obj
,
2941 struct drm_property
*property
,
2944 int count
= obj
->properties
->count
;
2946 if (count
== DRM_OBJECT_MAX_PROPERTY
) {
2947 WARN(1, "Failed to attach object property (type: 0x%x). Please "
2948 "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time "
2949 "you see this message on the same object type.\n",
2954 obj
->properties
->ids
[count
] = property
->base
.id
;
2955 obj
->properties
->values
[count
] = init_val
;
2956 obj
->properties
->count
++;
2958 EXPORT_SYMBOL(drm_object_attach_property
);
2960 int drm_object_property_set_value(struct drm_mode_object
*obj
,
2961 struct drm_property
*property
, uint64_t val
)
2965 for (i
= 0; i
< obj
->properties
->count
; i
++) {
2966 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
2967 obj
->properties
->values
[i
] = val
;
2974 EXPORT_SYMBOL(drm_object_property_set_value
);
2976 int drm_object_property_get_value(struct drm_mode_object
*obj
,
2977 struct drm_property
*property
, uint64_t *val
)
2981 for (i
= 0; i
< obj
->properties
->count
; i
++) {
2982 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
2983 *val
= obj
->properties
->values
[i
];
2990 EXPORT_SYMBOL(drm_object_property_get_value
);
2992 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2993 void *data
, struct drm_file
*file_priv
)
2995 struct drm_mode_object
*obj
;
2996 struct drm_mode_get_property
*out_resp
= data
;
2997 struct drm_property
*property
;
3000 int value_count
= 0;
3003 struct drm_property_enum
*prop_enum
;
3004 struct drm_mode_property_enum __user
*enum_ptr
;
3005 struct drm_property_blob
*prop_blob
;
3006 uint32_t __user
*blob_id_ptr
;
3007 uint64_t __user
*values_ptr
;
3008 uint32_t __user
*blob_length_ptr
;
3010 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3013 mutex_lock(&dev
->mode_config
.mutex
);
3014 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
3019 property
= obj_to_property(obj
);
3021 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
3022 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
3024 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3025 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
3029 value_count
= property
->num_values
;
3031 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
3032 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
3033 out_resp
->flags
= property
->flags
;
3035 if ((out_resp
->count_values
>= value_count
) && value_count
) {
3036 values_ptr
= (uint64_t __user
*)(unsigned long)out_resp
->values_ptr
;
3037 for (i
= 0; i
< value_count
; i
++) {
3038 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
3044 out_resp
->count_values
= value_count
;
3046 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
3047 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
3049 enum_ptr
= (struct drm_mode_property_enum __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3050 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
3052 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
3057 if (copy_to_user(&enum_ptr
[copied
].name
,
3058 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
3065 out_resp
->count_enum_blobs
= enum_count
;
3068 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3069 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
3071 blob_id_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3072 blob_length_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->values_ptr
;
3074 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
3075 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
3080 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
3088 out_resp
->count_enum_blobs
= blob_count
;
3091 mutex_unlock(&dev
->mode_config
.mutex
);
3095 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
3098 struct drm_property_blob
*blob
;
3101 if (!length
|| !data
)
3104 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
3108 ret
= drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
3114 blob
->length
= length
;
3116 memcpy(blob
->data
, data
, length
);
3118 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
3122 static void drm_property_destroy_blob(struct drm_device
*dev
,
3123 struct drm_property_blob
*blob
)
3125 drm_mode_object_put(dev
, &blob
->base
);
3126 list_del(&blob
->head
);
3130 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
3131 void *data
, struct drm_file
*file_priv
)
3133 struct drm_mode_object
*obj
;
3134 struct drm_mode_get_blob
*out_resp
= data
;
3135 struct drm_property_blob
*blob
;
3137 void __user
*blob_ptr
;
3139 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3142 mutex_lock(&dev
->mode_config
.mutex
);
3143 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
3148 blob
= obj_to_blob(obj
);
3150 if (out_resp
->length
== blob
->length
) {
3151 blob_ptr
= (void __user
*)(unsigned long)out_resp
->data
;
3152 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
3157 out_resp
->length
= blob
->length
;
3160 mutex_unlock(&dev
->mode_config
.mutex
);
3164 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
3167 struct drm_device
*dev
= connector
->dev
;
3170 if (connector
->edid_blob_ptr
)
3171 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
3173 /* Delete edid, when there is none. */
3175 connector
->edid_blob_ptr
= NULL
;
3176 ret
= drm_connector_property_set_value(connector
, dev
->mode_config
.edid_property
, 0);
3180 size
= EDID_LENGTH
* (1 + edid
->extensions
);
3181 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
3184 ret
= drm_connector_property_set_value(connector
,
3185 dev
->mode_config
.edid_property
,
3186 connector
->edid_blob_ptr
->base
.id
);
3190 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
3192 static bool drm_property_change_is_valid(struct drm_property
*property
,
3195 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
3197 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
3198 if (value
< property
->values
[0] || value
> property
->values
[1])
3201 } else if (property
->flags
& DRM_MODE_PROP_BITMASK
) {
3203 uint64_t valid_mask
= 0;
3204 for (i
= 0; i
< property
->num_values
; i
++)
3205 valid_mask
|= (1ULL << property
->values
[i
]);
3206 return !(value
& ~valid_mask
);
3209 for (i
= 0; i
< property
->num_values
; i
++)
3210 if (property
->values
[i
] == value
)
3216 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
3217 void *data
, struct drm_file
*file_priv
)
3219 struct drm_mode_connector_set_property
*conn_set_prop
= data
;
3220 struct drm_mode_obj_set_property obj_set_prop
= {
3221 .value
= conn_set_prop
->value
,
3222 .prop_id
= conn_set_prop
->prop_id
,
3223 .obj_id
= conn_set_prop
->connector_id
,
3224 .obj_type
= DRM_MODE_OBJECT_CONNECTOR
3227 /* It does all the locking and checking we need */
3228 return drm_mode_obj_set_property_ioctl(dev
, &obj_set_prop
, file_priv
);
3231 static int drm_mode_connector_set_obj_prop(struct drm_mode_object
*obj
,
3232 struct drm_property
*property
,
3236 struct drm_connector
*connector
= obj_to_connector(obj
);
3238 /* Do DPMS ourselves */
3239 if (property
== connector
->dev
->mode_config
.dpms_property
) {
3240 if (connector
->funcs
->dpms
)
3241 (*connector
->funcs
->dpms
)(connector
, (int)value
);
3243 } else if (connector
->funcs
->set_property
)
3244 ret
= connector
->funcs
->set_property(connector
, property
, value
);
3246 /* store the property value if successful */
3248 drm_connector_property_set_value(connector
, property
, value
);
3252 static int drm_mode_crtc_set_obj_prop(struct drm_mode_object
*obj
,
3253 struct drm_property
*property
,
3257 struct drm_crtc
*crtc
= obj_to_crtc(obj
);
3259 if (crtc
->funcs
->set_property
)
3260 ret
= crtc
->funcs
->set_property(crtc
, property
, value
);
3262 drm_object_property_set_value(obj
, property
, value
);
3267 static int drm_mode_plane_set_obj_prop(struct drm_mode_object
*obj
,
3268 struct drm_property
*property
,
3272 struct drm_plane
*plane
= obj_to_plane(obj
);
3274 if (plane
->funcs
->set_property
)
3275 ret
= plane
->funcs
->set_property(plane
, property
, value
);
3277 drm_object_property_set_value(obj
, property
, value
);
3282 int drm_mode_obj_get_properties_ioctl(struct drm_device
*dev
, void *data
,
3283 struct drm_file
*file_priv
)
3285 struct drm_mode_obj_get_properties
*arg
= data
;
3286 struct drm_mode_object
*obj
;
3290 int props_count
= 0;
3291 uint32_t __user
*props_ptr
;
3292 uint64_t __user
*prop_values_ptr
;
3294 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3297 mutex_lock(&dev
->mode_config
.mutex
);
3299 obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3304 if (!obj
->properties
) {
3309 props_count
= obj
->properties
->count
;
3311 /* This ioctl is called twice, once to determine how much space is
3312 * needed, and the 2nd time to fill it. */
3313 if ((arg
->count_props
>= props_count
) && props_count
) {
3315 props_ptr
= (uint32_t __user
*)(unsigned long)(arg
->props_ptr
);
3316 prop_values_ptr
= (uint64_t __user
*)(unsigned long)
3317 (arg
->prop_values_ptr
);
3318 for (i
= 0; i
< props_count
; i
++) {
3319 if (put_user(obj
->properties
->ids
[i
],
3320 props_ptr
+ copied
)) {
3324 if (put_user(obj
->properties
->values
[i
],
3325 prop_values_ptr
+ copied
)) {
3332 arg
->count_props
= props_count
;
3334 mutex_unlock(&dev
->mode_config
.mutex
);
3338 int drm_mode_obj_set_property_ioctl(struct drm_device
*dev
, void *data
,
3339 struct drm_file
*file_priv
)
3341 struct drm_mode_obj_set_property
*arg
= data
;
3342 struct drm_mode_object
*arg_obj
;
3343 struct drm_mode_object
*prop_obj
;
3344 struct drm_property
*property
;
3348 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3351 mutex_lock(&dev
->mode_config
.mutex
);
3353 arg_obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3356 if (!arg_obj
->properties
)
3359 for (i
= 0; i
< arg_obj
->properties
->count
; i
++)
3360 if (arg_obj
->properties
->ids
[i
] == arg
->prop_id
)
3363 if (i
== arg_obj
->properties
->count
)
3366 prop_obj
= drm_mode_object_find(dev
, arg
->prop_id
,
3367 DRM_MODE_OBJECT_PROPERTY
);
3370 property
= obj_to_property(prop_obj
);
3372 if (!drm_property_change_is_valid(property
, arg
->value
))
3375 switch (arg_obj
->type
) {
3376 case DRM_MODE_OBJECT_CONNECTOR
:
3377 ret
= drm_mode_connector_set_obj_prop(arg_obj
, property
,
3380 case DRM_MODE_OBJECT_CRTC
:
3381 ret
= drm_mode_crtc_set_obj_prop(arg_obj
, property
, arg
->value
);
3383 case DRM_MODE_OBJECT_PLANE
:
3384 ret
= drm_mode_plane_set_obj_prop(arg_obj
, property
, arg
->value
);
3389 mutex_unlock(&dev
->mode_config
.mutex
);
3393 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
3394 struct drm_encoder
*encoder
)
3398 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3399 if (connector
->encoder_ids
[i
] == 0) {
3400 connector
->encoder_ids
[i
] = encoder
->base
.id
;
3406 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
3408 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
3409 struct drm_encoder
*encoder
)
3412 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3413 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
3414 connector
->encoder_ids
[i
] = 0;
3415 if (connector
->encoder
== encoder
)
3416 connector
->encoder
= NULL
;
3421 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
3423 int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
3426 crtc
->gamma_size
= gamma_size
;
3428 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
3429 if (!crtc
->gamma_store
) {
3430 crtc
->gamma_size
= 0;
3436 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
3438 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
3439 void *data
, struct drm_file
*file_priv
)
3441 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3442 struct drm_mode_object
*obj
;
3443 struct drm_crtc
*crtc
;
3444 void *r_base
, *g_base
, *b_base
;
3448 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3451 mutex_lock(&dev
->mode_config
.mutex
);
3452 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3457 crtc
= obj_to_crtc(obj
);
3459 if (crtc
->funcs
->gamma_set
== NULL
) {
3464 /* memcpy into gamma store */
3465 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3470 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3471 r_base
= crtc
->gamma_store
;
3472 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
3477 g_base
= r_base
+ size
;
3478 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
3483 b_base
= g_base
+ size
;
3484 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
3489 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
3492 mutex_unlock(&dev
->mode_config
.mutex
);
3497 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
3498 void *data
, struct drm_file
*file_priv
)
3500 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3501 struct drm_mode_object
*obj
;
3502 struct drm_crtc
*crtc
;
3503 void *r_base
, *g_base
, *b_base
;
3507 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3510 mutex_lock(&dev
->mode_config
.mutex
);
3511 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3516 crtc
= obj_to_crtc(obj
);
3518 /* memcpy into gamma store */
3519 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3524 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3525 r_base
= crtc
->gamma_store
;
3526 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
3531 g_base
= r_base
+ size
;
3532 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
3537 b_base
= g_base
+ size
;
3538 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
3543 mutex_unlock(&dev
->mode_config
.mutex
);
3547 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
3548 void *data
, struct drm_file
*file_priv
)
3550 struct drm_mode_crtc_page_flip
*page_flip
= data
;
3551 struct drm_mode_object
*obj
;
3552 struct drm_crtc
*crtc
;
3553 struct drm_framebuffer
*fb
;
3554 struct drm_pending_vblank_event
*e
= NULL
;
3555 unsigned long flags
;
3556 int hdisplay
, vdisplay
;
3559 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
3560 page_flip
->reserved
!= 0)
3563 mutex_lock(&dev
->mode_config
.mutex
);
3564 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3567 crtc
= obj_to_crtc(obj
);
3569 if (crtc
->fb
== NULL
) {
3570 /* The framebuffer is currently unbound, presumably
3571 * due to a hotplug event, that userspace has not
3578 if (crtc
->funcs
->page_flip
== NULL
)
3581 obj
= drm_mode_object_find(dev
, page_flip
->fb_id
, DRM_MODE_OBJECT_FB
);
3584 fb
= obj_to_fb(obj
);
3586 hdisplay
= crtc
->mode
.hdisplay
;
3587 vdisplay
= crtc
->mode
.vdisplay
;
3589 if (crtc
->invert_dimensions
)
3590 swap(hdisplay
, vdisplay
);
3592 if (hdisplay
> fb
->width
||
3593 vdisplay
> fb
->height
||
3594 crtc
->x
> fb
->width
- hdisplay
||
3595 crtc
->y
> fb
->height
- vdisplay
) {
3596 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
3597 fb
->width
, fb
->height
, hdisplay
, vdisplay
, crtc
->x
, crtc
->y
,
3598 crtc
->invert_dimensions
? " (inverted)" : "");
3603 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3605 spin_lock_irqsave(&dev
->event_lock
, flags
);
3606 if (file_priv
->event_space
< sizeof e
->event
) {
3607 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3610 file_priv
->event_space
-= sizeof e
->event
;
3611 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3613 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
3615 spin_lock_irqsave(&dev
->event_lock
, flags
);
3616 file_priv
->event_space
+= sizeof e
->event
;
3617 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3621 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
3622 e
->event
.base
.length
= sizeof e
->event
;
3623 e
->event
.user_data
= page_flip
->user_data
;
3624 e
->base
.event
= &e
->event
.base
;
3625 e
->base
.file_priv
= file_priv
;
3627 (void (*) (struct drm_pending_event
*)) kfree
;
3630 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
);
3632 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3633 spin_lock_irqsave(&dev
->event_lock
, flags
);
3634 file_priv
->event_space
+= sizeof e
->event
;
3635 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3641 mutex_unlock(&dev
->mode_config
.mutex
);
3645 void drm_mode_config_reset(struct drm_device
*dev
)
3647 struct drm_crtc
*crtc
;
3648 struct drm_encoder
*encoder
;
3649 struct drm_connector
*connector
;
3651 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
3652 if (crtc
->funcs
->reset
)
3653 crtc
->funcs
->reset(crtc
);
3655 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
3656 if (encoder
->funcs
->reset
)
3657 encoder
->funcs
->reset(encoder
);
3659 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
3660 if (connector
->funcs
->reset
)
3661 connector
->funcs
->reset(connector
);
3663 EXPORT_SYMBOL(drm_mode_config_reset
);
3665 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
3666 void *data
, struct drm_file
*file_priv
)
3668 struct drm_mode_create_dumb
*args
= data
;
3670 if (!dev
->driver
->dumb_create
)
3672 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
3675 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
3676 void *data
, struct drm_file
*file_priv
)
3678 struct drm_mode_map_dumb
*args
= data
;
3680 /* call driver ioctl to get mmap offset */
3681 if (!dev
->driver
->dumb_map_offset
)
3684 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
3687 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
3688 void *data
, struct drm_file
*file_priv
)
3690 struct drm_mode_destroy_dumb
*args
= data
;
3692 if (!dev
->driver
->dumb_destroy
)
3695 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
3699 * Just need to support RGB formats here for compat with code that doesn't
3700 * use pixel formats directly yet.
3702 void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
3706 case DRM_FORMAT_RGB332
:
3707 case DRM_FORMAT_BGR233
:
3711 case DRM_FORMAT_XRGB1555
:
3712 case DRM_FORMAT_XBGR1555
:
3713 case DRM_FORMAT_RGBX5551
:
3714 case DRM_FORMAT_BGRX5551
:
3715 case DRM_FORMAT_ARGB1555
:
3716 case DRM_FORMAT_ABGR1555
:
3717 case DRM_FORMAT_RGBA5551
:
3718 case DRM_FORMAT_BGRA5551
:
3722 case DRM_FORMAT_RGB565
:
3723 case DRM_FORMAT_BGR565
:
3727 case DRM_FORMAT_RGB888
:
3728 case DRM_FORMAT_BGR888
:
3732 case DRM_FORMAT_XRGB8888
:
3733 case DRM_FORMAT_XBGR8888
:
3734 case DRM_FORMAT_RGBX8888
:
3735 case DRM_FORMAT_BGRX8888
:
3739 case DRM_FORMAT_XRGB2101010
:
3740 case DRM_FORMAT_XBGR2101010
:
3741 case DRM_FORMAT_RGBX1010102
:
3742 case DRM_FORMAT_BGRX1010102
:
3743 case DRM_FORMAT_ARGB2101010
:
3744 case DRM_FORMAT_ABGR2101010
:
3745 case DRM_FORMAT_RGBA1010102
:
3746 case DRM_FORMAT_BGRA1010102
:
3750 case DRM_FORMAT_ARGB8888
:
3751 case DRM_FORMAT_ABGR8888
:
3752 case DRM_FORMAT_RGBA8888
:
3753 case DRM_FORMAT_BGRA8888
:
3758 DRM_DEBUG_KMS("unsupported pixel format\n");
3764 EXPORT_SYMBOL(drm_fb_get_bpp_depth
);
3767 * drm_format_num_planes - get the number of planes for format
3768 * @format: pixel format (DRM_FORMAT_*)
3771 * The number of planes used by the specified pixel format.
3773 int drm_format_num_planes(uint32_t format
)
3776 case DRM_FORMAT_YUV410
:
3777 case DRM_FORMAT_YVU410
:
3778 case DRM_FORMAT_YUV411
:
3779 case DRM_FORMAT_YVU411
:
3780 case DRM_FORMAT_YUV420
:
3781 case DRM_FORMAT_YVU420
:
3782 case DRM_FORMAT_YUV422
:
3783 case DRM_FORMAT_YVU422
:
3784 case DRM_FORMAT_YUV444
:
3785 case DRM_FORMAT_YVU444
:
3787 case DRM_FORMAT_NV12
:
3788 case DRM_FORMAT_NV21
:
3789 case DRM_FORMAT_NV16
:
3790 case DRM_FORMAT_NV61
:
3791 case DRM_FORMAT_NV24
:
3792 case DRM_FORMAT_NV42
:
3798 EXPORT_SYMBOL(drm_format_num_planes
);
3801 * drm_format_plane_cpp - determine the bytes per pixel value
3802 * @format: pixel format (DRM_FORMAT_*)
3803 * @plane: plane index
3806 * The bytes per pixel value for the specified plane.
3808 int drm_format_plane_cpp(uint32_t format
, int plane
)
3813 if (plane
>= drm_format_num_planes(format
))
3817 case DRM_FORMAT_YUYV
:
3818 case DRM_FORMAT_YVYU
:
3819 case DRM_FORMAT_UYVY
:
3820 case DRM_FORMAT_VYUY
:
3822 case DRM_FORMAT_NV12
:
3823 case DRM_FORMAT_NV21
:
3824 case DRM_FORMAT_NV16
:
3825 case DRM_FORMAT_NV61
:
3826 case DRM_FORMAT_NV24
:
3827 case DRM_FORMAT_NV42
:
3828 return plane
? 2 : 1;
3829 case DRM_FORMAT_YUV410
:
3830 case DRM_FORMAT_YVU410
:
3831 case DRM_FORMAT_YUV411
:
3832 case DRM_FORMAT_YVU411
:
3833 case DRM_FORMAT_YUV420
:
3834 case DRM_FORMAT_YVU420
:
3835 case DRM_FORMAT_YUV422
:
3836 case DRM_FORMAT_YVU422
:
3837 case DRM_FORMAT_YUV444
:
3838 case DRM_FORMAT_YVU444
:
3841 drm_fb_get_bpp_depth(format
, &depth
, &bpp
);
3845 EXPORT_SYMBOL(drm_format_plane_cpp
);
3848 * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
3849 * @format: pixel format (DRM_FORMAT_*)
3852 * The horizontal chroma subsampling factor for the
3853 * specified pixel format.
3855 int drm_format_horz_chroma_subsampling(uint32_t format
)
3858 case DRM_FORMAT_YUV411
:
3859 case DRM_FORMAT_YVU411
:
3860 case DRM_FORMAT_YUV410
:
3861 case DRM_FORMAT_YVU410
:
3863 case DRM_FORMAT_YUYV
:
3864 case DRM_FORMAT_YVYU
:
3865 case DRM_FORMAT_UYVY
:
3866 case DRM_FORMAT_VYUY
:
3867 case DRM_FORMAT_NV12
:
3868 case DRM_FORMAT_NV21
:
3869 case DRM_FORMAT_NV16
:
3870 case DRM_FORMAT_NV61
:
3871 case DRM_FORMAT_YUV422
:
3872 case DRM_FORMAT_YVU422
:
3873 case DRM_FORMAT_YUV420
:
3874 case DRM_FORMAT_YVU420
:
3880 EXPORT_SYMBOL(drm_format_horz_chroma_subsampling
);
3883 * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
3884 * @format: pixel format (DRM_FORMAT_*)
3887 * The vertical chroma subsampling factor for the
3888 * specified pixel format.
3890 int drm_format_vert_chroma_subsampling(uint32_t format
)
3893 case DRM_FORMAT_YUV410
:
3894 case DRM_FORMAT_YVU410
:
3896 case DRM_FORMAT_YUV420
:
3897 case DRM_FORMAT_YVU420
:
3898 case DRM_FORMAT_NV12
:
3899 case DRM_FORMAT_NV21
:
3905 EXPORT_SYMBOL(drm_format_vert_chroma_subsampling
);