From patchwork Thu Feb 22 20:06:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 10236321 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8523460349 for ; Thu, 22 Feb 2018 20:16:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B1C9289FD for ; Thu, 22 Feb 2018 20:16:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 700FC28DAE; Thu, 22 Feb 2018 20:16:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2D03228C06 for ; Thu, 22 Feb 2018 20:16:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6506D6ECED; Thu, 22 Feb 2018 20:15:56 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id AB0796ED4D for ; Thu, 22 Feb 2018 20:15:55 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:34576 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1eox92-0004nQ-RP; Thu, 22 Feb 2018 21:07:08 +0100 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Date: Thu, 22 Feb 2018 21:06:48 +0100 Message-Id: <20180222200653.19453-8-noralf@tronnes.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180222200653.19453-1-noralf@tronnes.org> References: <20180222200653.19453-1-noralf@tronnes.org> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC v3 07/12] drm/modes: Add drm_umode_equal() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: daniel.vetter@ffwll.ch, intel-gfx@lists.freedesktop.org, =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , laurent.pinchart@ideasonboard.com, dh.herrmann@gmail.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Add a way to check if userspace modes are equal. Useful for in-kernel clients. Also export drm_mode_convert_umode(). Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/drm_modes.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_modes.h | 2 ++ 2 files changed, 52 insertions(+) diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c index 5a8033fda4e3..0e39164f15aa 100644 --- a/drivers/gpu/drm/drm_modes.c +++ b/drivers/gpu/drm/drm_modes.c @@ -1631,6 +1631,56 @@ int drm_mode_convert_umode(struct drm_device *dev, out: return ret; } +EXPORT_SYMBOL(drm_mode_convert_umode); + +/** + * drm_umode_equal - test modeinfo modes for equality + * @mode1: first mode + * @mode2: second mode + * + * Check to see if @mode1 and @mode2 are equivalent. + * + * Returns: + * True if the modes are equal, false otherwise. + */ +bool drm_umode_equal(const struct drm_mode_modeinfo *mode1, + const struct drm_mode_modeinfo *mode2) +{ + if (!mode1 && !mode2) + return true; + + if (!mode1 || !mode2) + return false; + + /* do clock check convert to PICOS so fb modes get matched the same */ + if (mode1->clock && mode2->clock) { + if (KHZ2PICOS(mode1->clock) != KHZ2PICOS(mode2->clock)) + return false; + } else if (mode1->clock != mode2->clock) { + return false; + } + + if ((mode1->flags & DRM_MODE_FLAG_3D_MASK) != + (mode2->flags & DRM_MODE_FLAG_3D_MASK)) + return false; + + if (mode1->hdisplay == mode2->hdisplay && + mode1->hsync_start == mode2->hsync_start && + mode1->hsync_end == mode2->hsync_end && + mode1->htotal == mode2->htotal && + mode1->hskew == mode2->hskew && + mode1->vdisplay == mode2->vdisplay && + mode1->vsync_start == mode2->vsync_start && + mode1->vsync_end == mode2->vsync_end && + mode1->vtotal == mode2->vtotal && + mode1->vscan == mode2->vscan && + (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) == + (mode2->flags & ~DRM_MODE_FLAG_3D_MASK)) + return true; + + return false; +} +EXPORT_SYMBOL(drm_umode_equal); /** * drm_mode_is_420_only - if a given videomode can be only supported in YCBCR420 diff --git a/include/drm/drm_modes.h b/include/drm/drm_modes.h index 0d310beae6af..05e73ca4f2ae 100644 --- a/include/drm/drm_modes.h +++ b/include/drm/drm_modes.h @@ -447,6 +447,8 @@ void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out, int drm_mode_convert_umode(struct drm_device *dev, struct drm_display_mode *out, const struct drm_mode_modeinfo *in); +bool drm_umode_equal(const struct drm_mode_modeinfo *mode1, + const struct drm_mode_modeinfo *mode2); void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode); void drm_mode_debug_printmodeline(const struct drm_display_mode *mode); bool drm_mode_is_420_only(const struct drm_display_info *display,