From patchwork Thu Jan 2 21:27:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King X-Patchwork-Id: 3431951 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 6608E9F380 for ; Fri, 3 Jan 2014 15:25:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A6FD720122 for ; Fri, 3 Jan 2014 15:25:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C485C2010C for ; Fri, 3 Jan 2014 15:25:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 858F0FAC57; Fri, 3 Jan 2014 07:25:28 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from pandora.arm.linux.org.uk (gw-1.arm.linux.org.uk [78.32.30.217]) by gabe.freedesktop.org (Postfix) with ESMTP id 4644FFB69C for ; Thu, 2 Jan 2014 13:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=pandora; h=Date:Sender:Message-Id:Subject:Cc:To:From:References:In-Reply-To; bh=AuA5nIXuDynsvu3a4LAog789ES7XvLI7/PeG1wuYNWA=; b=mXNZmUg+mi9z2af5j9Ti1kyPwmHoLpjkIpj3Wr7CeOY7dTvo4Wkr20sPHrqUFdALoTzsWhmyYL4o5jKRu+b3PYSaJn2kUhxIxHIT92E2XXjR4ZwMOxwJFLQEHCngDb0uBqWVhdPPdM1Yx1EkxpiRDLeng+r18icsElfY2SNz9so=; Received: from [2001:4d48:ad52:3201:222:68ff:fe15:37dd] (port=58605 helo=rmk-PC.arm.linux.org.uk) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1Vypnr-0004AV-O2; Thu, 02 Jan 2014 21:27:43 +0000 Received: from rmk by rmk-PC.arm.linux.org.uk with local (Exim 4.76) (envelope-from ) id 1Vypnr-0007F3-Aa; Thu, 02 Jan 2014 21:27:43 +0000 In-Reply-To: <20140102212528.GD7383@n2100.arm.linux.org.uk> References: <20140102212528.GD7383@n2100.arm.linux.org.uk> From: Russell King To: David Airlie , Greg Kroah-Hartman , Sascha Hauer , Shawn Guo Subject: [PATCH RFC 23/46] imx-drm: imx-drm-core: use array instead of list for CRTCs Message-Id: Date: Thu, 02 Jan 2014 21:27:43 +0000 X-Mailman-Approved-At: Fri, 03 Jan 2014 07:21:56 -0800 Cc: devel@driverdev.osuosl.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org 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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, 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 The DRM core indexes vblank by number, so there's little point maintaining a list, and have to scan the list to find the appropriate structure. Instead, use an array of pointers to the CRTCs. Signed-off-by: Russell King --- drivers/staging/imx-drm/imx-drm-core.c | 57 +++++++++++++------------------- 1 files changed, 23 insertions(+), 34 deletions(-) diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c index a402df0f3005..8aef203a017b 100644 --- a/drivers/staging/imx-drm/imx-drm-core.c +++ b/drivers/staging/imx-drm/imx-drm-core.c @@ -34,10 +34,12 @@ struct crtc_cookie { struct list_head list; }; +struct imx_drm_crtc; + struct imx_drm_device { struct drm_device *drm; struct device *dev; - struct list_head crtc_list; + struct imx_drm_crtc *crtc[MAX_CRTC]; struct list_head encoder_list; struct list_head connector_list; struct mutex mutex; @@ -47,7 +49,6 @@ struct imx_drm_device { struct imx_drm_crtc { struct drm_crtc *crtc; - struct list_head list; struct imx_drm_device *imxdrm; int pipe; struct imx_drm_crtc_helper_funcs imx_drm_helper_funcs; @@ -69,6 +70,8 @@ struct imx_drm_connector { struct module *owner; }; +static struct imx_drm_device *__imx_drm_device(void); + int imx_drm_crtc_id(struct imx_drm_crtc *crtc) { return crtc->pipe; @@ -96,34 +99,28 @@ static int imx_drm_driver_unload(struct drm_device *drm) return 0; } -/* - * We don't care at all for crtc numbers, but the core expects the - * crtcs to be numbered - */ -static struct imx_drm_crtc *imx_drm_crtc_by_num(struct imx_drm_device *imxdrm, - int num) +struct imx_drm_crtc *imx_drm_find_crtc(struct drm_crtc *crtc) { - struct imx_drm_crtc *imx_drm_crtc; + struct imx_drm_device *imxdrm = __imx_drm_device(); + unsigned i; + + for (i = 0; i < MAX_CRTC; i++) + if (imxdrm->crtc[i] && imxdrm->crtc[i]->crtc == crtc) + return imxdrm->crtc[i]; - list_for_each_entry(imx_drm_crtc, &imxdrm->crtc_list, list) - if (imx_drm_crtc->pipe == num) - return imx_drm_crtc; return NULL; } int imx_drm_crtc_panel_format_pins(struct drm_crtc *crtc, u32 encoder_type, u32 interface_pix_fmt, int hsync_pin, int vsync_pin) { - struct imx_drm_device *imxdrm = crtc->dev->dev_private; - struct imx_drm_crtc *imx_crtc; struct imx_drm_crtc_helper_funcs *helper; + struct imx_drm_crtc *imx_crtc; - list_for_each_entry(imx_crtc, &imxdrm->crtc_list, list) - if (imx_crtc->crtc == crtc) - goto found; + imx_crtc = imx_drm_find_crtc(crtc); + if (!imx_crtc) + return -EINVAL; - return -EINVAL; -found: helper = &imx_crtc->imx_drm_helper_funcs; if (helper->set_interface_pix_fmt) return helper->set_interface_pix_fmt(crtc, @@ -162,10 +159,9 @@ EXPORT_SYMBOL_GPL(imx_drm_handle_vblank); static int imx_drm_enable_vblank(struct drm_device *drm, int crtc) { struct imx_drm_device *imxdrm = drm->dev_private; - struct imx_drm_crtc *imx_drm_crtc; + struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[crtc]; int ret; - imx_drm_crtc = imx_drm_crtc_by_num(imxdrm, crtc); if (!imx_drm_crtc) return -EINVAL; @@ -181,9 +177,8 @@ static int imx_drm_enable_vblank(struct drm_device *drm, int crtc) static void imx_drm_disable_vblank(struct drm_device *drm, int crtc) { struct imx_drm_device *imxdrm = drm->dev_private; - struct imx_drm_crtc *imx_drm_crtc; + struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[crtc]; - imx_drm_crtc = imx_drm_crtc_by_num(imxdrm, crtc); if (!imx_drm_crtc) return; @@ -509,7 +504,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc, imx_drm_crtc->owner = owner; - list_add_tail(&imx_drm_crtc->list, &imxdrm->crtc_list); + imxdrm->crtc[imx_drm_crtc->pipe] = imx_drm_crtc; *new_crtc = imx_drm_crtc; @@ -532,7 +527,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc, return 0; err_register: - list_del(&imx_drm_crtc->list); + imxdrm->crtc[imx_drm_crtc->pipe] = NULL; kfree(imx_drm_crtc); err_alloc: err_busy: @@ -552,7 +547,7 @@ int imx_drm_remove_crtc(struct imx_drm_crtc *imx_drm_crtc) drm_crtc_cleanup(imx_drm_crtc->crtc); - list_del(&imx_drm_crtc->list); + imxdrm->crtc[imx_drm_crtc->pipe] = NULL; drm_mode_group_reinit(imxdrm->drm); @@ -659,14 +654,9 @@ EXPORT_SYMBOL_GPL(imx_drm_encoder_add_possible_crtcs); int imx_drm_encoder_get_mux_id(struct drm_encoder *encoder) { - struct imx_drm_device *imxdrm = __imx_drm_device(); - struct imx_drm_crtc *imx_crtc; - - list_for_each_entry(imx_crtc, &imxdrm->crtc_list, list) - if (imx_crtc->crtc == encoder->crtc) - return imx_crtc->mux_id; + struct imx_drm_crtc *imx_crtc = imx_drm_find_crtc(encoder->crtc); - return -EINVAL; + return imx_crtc ? imx_crtc->mux_id : -EINVAL; } EXPORT_SYMBOL_GPL(imx_drm_encoder_get_mux_id); @@ -853,7 +843,6 @@ static int __init imx_drm_init(void) return -ENOMEM; mutex_init(&imx_drm_device->mutex); - INIT_LIST_HEAD(&imx_drm_device->crtc_list); INIT_LIST_HEAD(&imx_drm_device->connector_list); INIT_LIST_HEAD(&imx_drm_device->encoder_list);