From patchwork Thu Feb 21 18:42:18 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: 10825465 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 C2CDB1390 for ; Fri, 22 Feb 2019 08:21:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4AFC31B1E for ; Fri, 22 Feb 2019 08:21:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8C3C31B25; Fri, 22 Feb 2019 08:21:44 +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 4D33231B2A for ; Fri, 22 Feb 2019 08:21:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BB33989361; Fri, 22 Feb 2019 08:21:06 +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 242A98916A for ; Thu, 21 Feb 2019 18:42:38 +0000 (UTC) Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwtIr-0000io-OG; Thu, 21 Feb 2019 18:42:37 +0000 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org Subject: [PATCH 30/34] drm/sis: Convert object_idr to XArray Date: Thu, 21 Feb 2019 10:42:18 -0800 Message-Id: <20190221184226.2149-59-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=5fjxh/IDzm2cOjs0eKVwW15u+Wjdq3WM003MeAUJorE=; b=JS67AsJpL7tSVRZgEGWV35Ywa 7DX0iea9aDyOrPI/Cg7LKv+G5YaDsFNAfPdOKBeLHQOf06JHZ+9cePXtPBleQ5sqk3dowUwTTWfG0 vOqeC1MG9JpJg5XyyGC3t6Og6V7Vi298nCLN/YDT0OaXm+epZaBpzPvCFTbKhitmCJQu60KeGIyuk /cGyLTht+ZbHKrNlYVnbAV2vFfCg3V0ttgj2MleGkI+ZWovbFQCd1BCZxHCDu6F/m05Ks8V/OrNp1 3u1fx587nXB3kMvYxNc5BWqm+tVy/4TL0jt9TjX/bY8s4njzUZzBIdpLDpPkEWF5G1Ixo9HzgAW+h hqgy6kiRw==; 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/sis/sis_drv.c | 4 +--- drivers/gpu/drm/sis/sis_drv.h | 2 +- drivers/gpu/drm/sis/sis_mm.c | 17 ++++++++--------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/sis/sis_drv.c b/drivers/gpu/drm/sis/sis_drv.c index e04a92658cd7..bb5caad5d365 100644 --- a/drivers/gpu/drm/sis/sis_drv.c +++ b/drivers/gpu/drm/sis/sis_drv.c @@ -47,7 +47,7 @@ static int sis_driver_load(struct drm_device *dev, unsigned long chipset) if (dev_priv == NULL) return -ENOMEM; - idr_init(&dev_priv->object_idr); + xa_init_flags(&dev_priv->objects, XA_FLAGS_ALLOC1); dev->dev_private = (void *)dev_priv; dev_priv->chipset = chipset; @@ -58,8 +58,6 @@ static void sis_driver_unload(struct drm_device *dev) { drm_sis_private_t *dev_priv = dev->dev_private; - idr_destroy(&dev_priv->object_idr); - kfree(dev_priv); } diff --git a/drivers/gpu/drm/sis/sis_drv.h b/drivers/gpu/drm/sis/sis_drv.h index 328f8a750976..18277fee8550 100644 --- a/drivers/gpu/drm/sis/sis_drv.h +++ b/drivers/gpu/drm/sis/sis_drv.h @@ -64,7 +64,7 @@ typedef struct drm_sis_private { struct drm_mm vram_mm; struct drm_mm agp_mm; /** Mapping of userspace keys to mm objects */ - struct idr object_idr; + struct xarray objects; } drm_sis_private_t; struct sis_file_private { diff --git a/drivers/gpu/drm/sis/sis_mm.c b/drivers/gpu/drm/sis/sis_mm.c index 1622db24cd39..2fbc31697563 100644 --- a/drivers/gpu/drm/sis/sis_mm.c +++ b/drivers/gpu/drm/sis/sis_mm.c @@ -84,9 +84,10 @@ static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file, { drm_sis_private_t *dev_priv = dev->dev_private; drm_sis_mem_t *mem = data; - int retval = 0, user_key; + int retval = 0; struct sis_memblock *item; struct sis_file_private *file_priv = file->driver_priv; + unsigned int id; unsigned long offset; mutex_lock(&dev->struct_mutex); @@ -128,23 +129,22 @@ static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file, if (retval) goto fail_alloc; - retval = idr_alloc(&dev_priv->object_idr, item, 1, 0, GFP_KERNEL); + retval = xa_alloc(&dev_priv->objects, &id, item, xa_limit_31b, + GFP_KERNEL); if (retval < 0) - goto fail_idr; - user_key = retval; - + goto fail_xa; list_add(&item->owner_list, &file_priv->obj_list); mutex_unlock(&dev->struct_mutex); + mem->free = id; mem->offset = ((pool == 0) ? dev_priv->vram_offset : dev_priv->agp_offset) + (offset << SIS_MM_ALIGN_SHIFT); - mem->free = user_key; mem->size = mem->size << SIS_MM_ALIGN_SHIFT; return 0; -fail_idr: +fail_xa: drm_mm_remove_node(&item->mm_node); fail_alloc: kfree(item); @@ -167,13 +167,12 @@ static int sis_drm_free(struct drm_device *dev, void *data, struct drm_file *fil struct sis_memblock *obj; mutex_lock(&dev->struct_mutex); - obj = idr_find(&dev_priv->object_idr, mem->free); + obj = xa_erase(&dev_priv->objects, mem->free); if (obj == NULL) { mutex_unlock(&dev->struct_mutex); return -EINVAL; } - idr_remove(&dev_priv->object_idr, mem->free); list_del(&obj->owner_list); if (drm_mm_node_allocated(&obj->mm_node)) drm_mm_remove_node(&obj->mm_node);