aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2015-03-04 19:25:43 -0500
committerDaniel Vetter <daniel.vetter@ffwll.ch>2015-03-10 04:59:35 -0400
commitead8610d42105a3d01f755522f11b96c60dc648f (patch)
tree7cbbdcbf073515c3e717edc1f128544148ddf62e
parent2a97acd6376922bb9d23b5f4421745d2a6690060 (diff)
drm: Share plane pixel format check code between legacy and atomic
Both the legacy and atomic helpers need to check whether a plane supports a given pixel format. The code is currently duplicated, share it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> [danvet: Slightly extend the docbook.] Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
-rw-r--r--drivers/gpu/drm/drm_atomic.c10
-rw-r--r--drivers/gpu/drm/drm_crtc.c29
-rw-r--r--include/drm/drm_crtc.h2
3 files changed, 29 insertions, 12 deletions
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 7ca54cb6b15b..a6caaae40b9e 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -475,7 +475,7 @@ static int drm_atomic_plane_check(struct drm_plane *plane,
475 struct drm_plane_state *state) 475 struct drm_plane_state *state)
476{ 476{
477 unsigned int fb_width, fb_height; 477 unsigned int fb_width, fb_height;
478 unsigned int i; 478 int ret;
479 479
480 /* either *both* CRTC and FB must be set, or neither */ 480 /* either *both* CRTC and FB must be set, or neither */
481 if (WARN_ON(state->crtc && !state->fb)) { 481 if (WARN_ON(state->crtc && !state->fb)) {
@@ -497,13 +497,11 @@ static int drm_atomic_plane_check(struct drm_plane *plane,
497 } 497 }
498 498
499 /* Check whether this plane supports the fb pixel format. */ 499 /* Check whether this plane supports the fb pixel format. */
500 for (i = 0; i < plane->format_count; i++) 500 ret = drm_plane_check_pixel_format(plane, state->fb->pixel_format);
501 if (state->fb->pixel_format == plane->format_types[i]) 501 if (ret) {
502 break;
503 if (i == plane->format_count) {
504 DRM_DEBUG_ATOMIC("Invalid pixel format %s\n", 502 DRM_DEBUG_ATOMIC("Invalid pixel format %s\n",
505 drm_get_format_name(state->fb->pixel_format)); 503 drm_get_format_name(state->fb->pixel_format));
506 return -EINVAL; 504 return ret;
507 } 505 }
508 506
509 /* Give drivers some help against integer overflows */ 507 /* Give drivers some help against integer overflows */
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index c83e4db0adf7..447db50e6838 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -2408,6 +2408,27 @@ int drm_mode_getplane(struct drm_device *dev, void *data,
2408 return 0; 2408 return 0;
2409} 2409}
2410 2410
2411/**
2412 * drm_plane_check_pixel_format - Check if the plane supports the pixel format
2413 * @plane: plane to check for format support
2414 * @format: the pixel format
2415 *
2416 * Returns:
2417 * Zero of @plane has @format in its list of supported pixel formats, -EINVAL
2418 * otherwise.
2419 */
2420int drm_plane_check_pixel_format(const struct drm_plane *plane, u32 format)
2421{
2422 unsigned int i;
2423
2424 for (i = 0; i < plane->format_count; i++) {
2425 if (format == plane->format_types[i])
2426 return 0;
2427 }
2428
2429 return -EINVAL;
2430}
2431
2411/* 2432/*
2412 * setplane_internal - setplane handler for internal callers 2433 * setplane_internal - setplane handler for internal callers
2413 * 2434 *
@@ -2428,7 +2449,6 @@ static int __setplane_internal(struct drm_plane *plane,
2428{ 2449{
2429 int ret = 0; 2450 int ret = 0;
2430 unsigned int fb_width, fb_height; 2451 unsigned int fb_width, fb_height;
2431 unsigned int i;
2432 2452
2433 /* No fb means shut it down */ 2453 /* No fb means shut it down */
2434 if (!fb) { 2454 if (!fb) {
@@ -2451,13 +2471,10 @@ static int __setplane_internal(struct drm_plane *plane,
2451 } 2471 }
2452 2472
2453 /* Check whether this plane supports the fb pixel format. */ 2473 /* Check whether this plane supports the fb pixel format. */
2454 for (i = 0; i < plane->format_count; i++) 2474 ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
2455 if (fb->pixel_format == plane->format_types[i]) 2475 if (ret) {
2456 break;
2457 if (i == plane->format_count) {
2458 DRM_DEBUG_KMS("Invalid pixel format %s\n", 2476 DRM_DEBUG_KMS("Invalid pixel format %s\n",
2459 drm_get_format_name(fb->pixel_format)); 2477 drm_get_format_name(fb->pixel_format));
2460 ret = -EINVAL;
2461 goto out; 2478 goto out;
2462 } 2479 }
2463 2480
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index b1465d6fbe94..da83d39e37d4 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -1263,6 +1263,8 @@ extern int drm_plane_init(struct drm_device *dev,
1263extern void drm_plane_cleanup(struct drm_plane *plane); 1263extern void drm_plane_cleanup(struct drm_plane *plane);
1264extern unsigned int drm_plane_index(struct drm_plane *plane); 1264extern unsigned int drm_plane_index(struct drm_plane *plane);
1265extern void drm_plane_force_disable(struct drm_plane *plane); 1265extern void drm_plane_force_disable(struct drm_plane *plane);
1266extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
1267 u32 format);
1266extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode, 1268extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1267 int *hdisplay, int *vdisplay); 1269 int *hdisplay, int *vdisplay);
1268extern int drm_crtc_check_viewport(const struct drm_crtc *crtc, 1270extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,