From patchwork Mon Jan 13 11:46:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 3474781 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8B6829F169 for ; Mon, 13 Jan 2014 11:47:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9301D20114 for ; Mon, 13 Jan 2014 11:47:11 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id B1F3F2010E for ; Mon, 13 Jan 2014 11:47:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9066010DCEC; Mon, 13 Jan 2014 03:47:04 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-bk0-f52.google.com (mail-bk0-f52.google.com [209.85.214.52]) by gabe.freedesktop.org (Postfix) with ESMTP id 6177610DCEA; Mon, 13 Jan 2014 03:46:56 -0800 (PST) Received: by mail-bk0-f52.google.com with SMTP id d7so926167bkh.25 for ; Mon, 13 Jan 2014 03:46:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=d++7CxEtcpGtf4Z+Snchz9NuSQfgK8f8GGcJimEL/jU=; b=0lqEnYR/u3TLYDCX7000HoSctjyLSdMJcYhifsKrYJMdmXp7OgqF5GzENaCUH2PJyM +wqJLoXyw7h/zKMnHV03tggtPvMoxj/+GFXUAtXCI+D7FClD8/s20jngWn9utKP3oNrI DeWX1APytfWYOgLMx1yUlg6nPt1cy2Zb3ufPAEO6RdQu+/fUY0sHPOoIhkIkMnU7uKgC 71zoJjUZq6Vt96UKg/VL+0/6pTEg7rZoyCSyadSrbrLj2jIP6nbi1lUNhDfS2EPvnn5s wEqpGCLMitUp1If37IBaZ7AmPl8Hf6mV88HSZcRXGXL0pZRJe+pyLhK4hCJ4WC6o/apt u08w== X-Received: by 10.204.71.5 with SMTP id f5mr9178091bkj.25.1389613615585; Mon, 13 Jan 2014 03:46:55 -0800 (PST) Received: from localhost (port-52867.pppoe.wtnet.de. [46.59.207.43]) by mx.google.com with ESMTPSA id jv7sm11549208bkb.6.2014.01.13.03.46.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Jan 2014 03:46:54 -0800 (PST) From: Thierry Reding To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm: provide a helper for the encoder possible_crtcs mask Date: Mon, 13 Jan 2014 12:46:49 +0100 Message-Id: <1389613610-21084-2-git-send-email-treding@nvidia.com> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1389613610-21084-1-git-send-email-treding@nvidia.com> References: <1389613610-21084-1-git-send-email-treding@nvidia.com> Cc: Daniel Vetter , intel-gfx@lists.freedesktop.org, Russell King X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Russell King The encoder possible_crtcs mask identifies which CRTCs can be bound to a particular encoder. Each bit from bit 0 defines an index in the list of CRTCs held in the DRM mode_config crtc_list. Rather than having drivers trying to track the position of their CRTCs in the list, expose the code which already exists for calculating the appropriate mask bit for a CRTC. Signed-off-by: Russell King Reviewed-by: David Herrmann [treding@nvidia.com: add drm_crtc_index(), move to core] Signed-off-by: Thierry Reding Reviewed-by: Jani Nikula --- Changes in v2: - further extract a new drm_crtc_index() function - move to DRM core (drm_crtc.c) drivers/gpu/drm/drm_crtc.c | 38 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_crtc_helper.c | 16 +++------------- include/drm/drm_crtc.h | 2 ++ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 266a01d7f635..fdfa5a0e51d6 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -675,6 +675,44 @@ void drm_crtc_cleanup(struct drm_crtc *crtc) EXPORT_SYMBOL(drm_crtc_cleanup); /** + * drm_crtc_index - find the index of a registered CRTC + * @crtc: CRTC to find index for + * + * Given a registered CRTC, return the index of that CRTC within a DRM + * device's list of CRTCs. If the CRTC isn't registered, return -1. + */ +int drm_crtc_index(struct drm_crtc *crtc) +{ + struct drm_crtc *tmp; + int index = 0; + + list_for_each_entry(tmp, &crtc->dev->mode_config.crtc_list, head) { + if (tmp == crtc) + return index; + + index++; + } + + return -1; +} +EXPORT_SYMBOL(drm_crtc_index); + +/** + * drm_crtc_mask - find the mask of a registered CRTC + * @crtc: CRTC to find mask for + * + * Given a registered CRTC, return the mask bit of that CRTC for an + * encoder's possible_crtcs field. + */ +uint32_t drm_crtc_mask(struct drm_crtc *crtc) +{ + int i = drm_crtc_index(crtc); + + return i < 0 ? 0 : 1 << i; +} +EXPORT_SYMBOL(drm_crtc_mask); + +/** * drm_mode_probed_add - add a mode to a connector's probed mode list * @connector: connector the new mode * @mode: mode data diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c index 01361aba033b..95b32098badf 100644 --- a/drivers/gpu/drm/drm_crtc_helper.c +++ b/drivers/gpu/drm/drm_crtc_helper.c @@ -334,23 +334,13 @@ EXPORT_SYMBOL(drm_helper_disable_unused_functions); static bool drm_encoder_crtc_ok(struct drm_encoder *encoder, struct drm_crtc *crtc) { - struct drm_device *dev; - struct drm_crtc *tmp; - int crtc_mask = 1; + uint32_t crtc_mask; WARN(!crtc, "checking null crtc?\n"); - dev = crtc->dev; - - list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) { - if (tmp == crtc) - break; - crtc_mask <<= 1; - } + crtc_mask = drm_crtc_mask(crtc); - if (encoder->possible_crtcs & crtc_mask) - return true; - return false; + return !!(encoder->possible_crtcs & crtc_mask); } /* diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index f32c5cd51f41..a61fb73fdcb5 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -929,6 +929,8 @@ extern int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, const struct drm_crtc_funcs *funcs); extern void drm_crtc_cleanup(struct drm_crtc *crtc); +extern int drm_crtc_index(struct drm_crtc *crtc); +extern uint32_t drm_crtc_mask(struct drm_crtc *crtc); extern void drm_connector_ida_init(void); extern void drm_connector_ida_destroy(void);