From patchwork Thu Feb 21 18:42:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 10825485 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4EDA2139A for ; Fri, 22 Feb 2019 08:21:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4133331B25 for ; Fri, 22 Feb 2019 08:21:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F7CC31B3D; Fri, 22 Feb 2019 08:21:59 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham 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 E242B31B2F for ; Fri, 22 Feb 2019 08:21:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 95183893EC; Fri, 22 Feb 2019 08:21:23 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by gabe.freedesktop.org (Postfix) with ESMTPS id 848F789166 for ; Thu, 21 Feb 2019 18:42:37 +0000 (UTC) Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwtIr-0000iG-4U; Thu, 21 Feb 2019 18:42:37 +0000 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org Subject: [PATCH 28/34] drm/tegra: Convert contexts IDR to XArray Date: Thu, 21 Feb 2019 10:42:14 -0800 Message-Id: <20190221184226.2149-55-willy@infradead.org> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20190221184226.2149-1-willy@infradead.org> References: <20190221184226.2149-1-willy@infradead.org> X-Mailman-Approved-At: Fri, 22 Feb 2019 08:20:52 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=mlq8LNcisLhgrYExH1nUVNgwZwo7uGtX5+sPnucrdms=; b=ChOMSuomKPSqmEfOji9wUOdOT uhIlPmCXX198HtTFX7Xj1ZfhFoQwuh8sUMNjHnwUsROwhYWIwA4H92esfM1UNqR0pE2xlKuLchQ4A NpNUUElaW78z57WggvbWgO9c0VY7rosZ42ITgsnaMBqWHYkpIHlIlQ22BJrW6QBT3ZMGpQGS3/i/7 1hysxuH7kJgJElYGR8OaDoQqUL6uQoDjfsxSNIlGYN3wTtvVGxr65TdUx0UXz0R3cECsXrvnsTKkU f4GCj7zZHLb4fHsfZ/CGhzRjPEZu6YnCcQLRAiqLuwz04AOr1SCPwi3EjIWtFIGg/0j1ypt3d8Pth igbyqA2eQ==; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matthew Wilcox MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Matthew Wilcox --- drivers/gpu/drm/tegra/drm.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c index 4b70ce664c41..5daa414cc2cf 100644 --- a/drivers/gpu/drm/tegra/drm.c +++ b/drivers/gpu/drm/tegra/drm.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include @@ -33,7 +33,7 @@ #define CDMA_GATHER_FETCHES_MAX_NB 16383 struct tegra_drm_file { - struct idr contexts; + struct xarray contexts; struct mutex lock; }; @@ -246,7 +246,7 @@ static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) if (!fpriv) return -ENOMEM; - idr_init(&fpriv->contexts); + xa_init_flags(&fpriv->contexts, XA_FLAGS_ALLOC1); mutex_init(&fpriv->lock); filp->driver_priv = fpriv; @@ -582,14 +582,14 @@ static int tegra_client_open(struct tegra_drm_file *fpriv, if (err < 0) return err; - err = idr_alloc(&fpriv->contexts, context, 1, 0, GFP_KERNEL); + err = xa_alloc(&fpriv->contexts, &context->id, context, xa_limit_31b, + GFP_KERNEL); if (err < 0) { client->ops->close_channel(context); return err; } context->client = client; - context->id = err; return 0; } @@ -637,13 +637,12 @@ static int tegra_close_channel(struct drm_device *drm, void *data, mutex_lock(&fpriv->lock); - context = idr_find(&fpriv->contexts, args->context); + context = xa_erase(&fpriv->contexts, args->context); if (!context) { err = -EINVAL; goto unlock; } - idr_remove(&fpriv->contexts, context->id); tegra_drm_context_free(context); unlock: @@ -662,7 +661,7 @@ static int tegra_get_syncpt(struct drm_device *drm, void *data, mutex_lock(&fpriv->lock); - context = idr_find(&fpriv->contexts, args->context); + context = xa_load(&fpriv->contexts, args->context); if (!context) { err = -ENODEV; goto unlock; @@ -691,7 +690,7 @@ static int tegra_submit(struct drm_device *drm, void *data, mutex_lock(&fpriv->lock); - context = idr_find(&fpriv->contexts, args->context); + context = xa_load(&fpriv->contexts, args->context); if (!context) { err = -ENODEV; goto unlock; @@ -716,7 +715,7 @@ static int tegra_get_syncpt_base(struct drm_device *drm, void *data, mutex_lock(&fpriv->lock); - context = idr_find(&fpriv->contexts, args->context); + context = xa_load(&fpriv->contexts, args->context); if (!context) { err = -ENODEV; goto unlock; @@ -928,24 +927,18 @@ static const struct file_operations tegra_drm_fops = { .llseek = noop_llseek, }; -static int tegra_drm_context_cleanup(int id, void *p, void *data) -{ - struct tegra_drm_context *context = p; - - tegra_drm_context_free(context); - - return 0; -} - static void tegra_drm_postclose(struct drm_device *drm, struct drm_file *file) { struct tegra_drm_file *fpriv = file->driver_priv; + struct tegra_drm_context *context; + unsigned long index; mutex_lock(&fpriv->lock); - idr_for_each(&fpriv->contexts, tegra_drm_context_cleanup, NULL); + xa_for_each(&fpriv->contexts, index, context) + tegra_drm_context_free(context); mutex_unlock(&fpriv->lock); - idr_destroy(&fpriv->contexts); + xa_destroy(&fpriv->contexts); mutex_destroy(&fpriv->lock); kfree(fpriv); }