From patchwork Tue Aug 25 03:13:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xinliang Liu X-Patchwork-Id: 52664 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id 365EE22E9E for ; Tue, 25 Aug 2015 03:19:13 +0000 (UTC) Received: by wicul11 with SMTP id ul11sf1010737wic.1 for ; Mon, 24 Aug 2015 20:19:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:subject:date :message-id:cc:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=X9fsPbW/3QGmRuaBTolGV/xtzGIHBjmGTF6faxtIVVE=; b=VEU2ufs1GDl+90FrGKAAkiYj1r2fTa2m6kq7yEh+FLGTpRY4f/T9XDmDy5rY3U3ZSg UUsBUsGYZ4XQSdMkZijBlOOeZrsceyrUqr8/0zzJBV1sJJgBCly2XpKPIyTdU29Qdk5T 64ImTJk/ALvVI4AHS6xsuf7ez5LqeHUa4l7vjI86Zm7zA+pMt/PiwSaXjx+NmOGaYN/u SuSmjpZtncxV59vUx6YXkpBa+OhwJ4J0VffW+nBJKi5+8hhiTnVjvbWuLUOxSx6ttbxD IOTZhcoT/gnwNplEqhbYfycZze53x8b3/GDyXUK9QEx2ITt8eDS6EnnRvPMZ/8IZUV0u aeUQ== X-Gm-Message-State: ALoCoQmId+JX5EfdJoZRDhMVuuulGLf+Kp4CRPA4Y9T191jWWofgXULS5+gXpueZdg5xYLvE5wlv X-Received: by 10.112.189.105 with SMTP id gh9mr7785671lbc.16.1440472752437; Mon, 24 Aug 2015 20:19:12 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.169 with SMTP id f9ls654338lam.93.gmail; Mon, 24 Aug 2015 20:19:12 -0700 (PDT) X-Received: by 10.152.121.70 with SMTP id li6mr18063371lab.98.1440472752287; Mon, 24 Aug 2015 20:19:12 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id t14si1531786laz.178.2015.08.24.20.19.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Aug 2015 20:19:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbcbn3 with SMTP id bn3so91297211lbc.2 for ; Mon, 24 Aug 2015 20:19:11 -0700 (PDT) X-Received: by 10.152.22.99 with SMTP id c3mr24015883laf.32.1440472751773; Mon, 24 Aug 2015 20:19:11 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.162.200 with SMTP id yc8csp2880291lbb; Mon, 24 Aug 2015 20:19:10 -0700 (PDT) X-Received: by 10.70.130.39 with SMTP id ob7mr51366216pdb.136.1440472749609; Mon, 24 Aug 2015 20:19:09 -0700 (PDT) Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTP id tl9si12951779pab.62.2015.08.24.20.19.08; Mon, 24 Aug 2015 20:19:09 -0700 (PDT) Received-SPF: pass (google.com: domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0AF286E1E1; Mon, 24 Aug 2015 20:19:08 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-vk0-f50.google.com (mail-vk0-f50.google.com [209.85.213.50]) by gabe.freedesktop.org (Postfix) with ESMTPS id 388EF6E1E1 for ; Mon, 24 Aug 2015 20:19:07 -0700 (PDT) Received: by vkm66 with SMTP id 66so67357449vkm.1 for ; Mon, 24 Aug 2015 20:19:06 -0700 (PDT) X-Received: by 10.52.69.175 with SMTP id f15mr35004685vdu.5.1440472746061; Mon, 24 Aug 2015 20:19:06 -0700 (PDT) Received: from localhost.localdomain ([119.139.124.234]) by smtp.gmail.com with ESMTPSA id aa1sm5149222vdc.28.2015.08.24.20.15.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Aug 2015 20:19:05 -0700 (PDT) From: Xinliang Liu To: airlied@linux.ie, dri-devel@lists.freedesktop.org Subject: [PATCH] drm/crtc: Add a helper func to get a registered crtc from its index Date: Tue, 25 Aug 2015 11:13:51 +0800 Message-Id: <1440472431-50874-1-git-send-email-xinliang.liu@linaro.org> X-Mailer: git-send-email 1.9.1 Cc: liguozhu@hisilicon.com, linux-kernel@vger.kernel.org, benjamin.gaignard@linaro.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: xinliang.liu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This patch add a helper func to get a registered crtc from its index. In some case, where we know the crtc's index and we want to know the crtc too. For example, the enable_vblank func of struct drm_driver: In the implementation of this func, we know the index of the crtc but we want to know the crtc. This helper func can get the crtc easily. A sample impelmentation of enable_vblank is as shown as bellow: int hisi_drm_crtc_enable_vblank(struct drm_device *dev, int c) { struct drm_crtc *crtc = drm_get_crtc_from_index(dev, c); struct hisi_crtc *hcrtc = to_hisi_crtc(crtc); struct hisi_crtc_ops *ops = hcrtc->ops; int ret = 0; if (ops->enable_vblank) ret = ops->enable_vblank(hcrtc); return ret; } Signed-off-by: Xinliang Liu --- drivers/gpu/drm/drm_crtc.c | 25 +++++++++++++++++++++++++ include/drm/drm_crtc.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index b9ba061..8764765 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -747,6 +747,31 @@ unsigned int drm_crtc_index(struct drm_crtc *crtc) } EXPORT_SYMBOL(drm_crtc_index); +/** + * drm_get_crtc_from_index - find a registered CRTC from the index + * @dev: DRM device + * @index: index of a registered CRTC + * + * Given a index, return the registered CRTC within a DRM + * device's list of CRTCs. + */ +struct drm_crtc *drm_get_crtc_from_index(struct drm_device *dev, + unsigned int index) +{ + unsigned int index_tmp = 0; + struct drm_crtc *crtc; + + list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { + if (index_tmp == index) + return crtc; + + index_tmp++; + } + + BUG(); +} +EXPORT_SYMBOL(drm_get_crtc_from_index); + /* * drm_mode_remove - remove and free a mode * @connector: connector list to modify diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 57ca8cc..3a46d39d 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -1225,6 +1225,8 @@ extern int drm_crtc_init_with_planes(struct drm_device *dev, const struct drm_crtc_funcs *funcs); extern void drm_crtc_cleanup(struct drm_crtc *crtc); extern unsigned int drm_crtc_index(struct drm_crtc *crtc); +extern struct drm_crtc *drm_get_crtc_from_index(struct drm_device *dev, + unsigned int index); /** * drm_crtc_mask - find the mask of a registered CRTC