From patchwork Thu Jun 7 13:36:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 137890 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2108570lji; Thu, 7 Jun 2018 06:36:24 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIrB2NRtTpp3DO6y9aGStFVYLeQNkJe8XyrDBD1+kFNiBeppawbAdio8vaFnNzdasYFTF+J X-Received: by 2002:a63:b215:: with SMTP id x21-v6mr1604945pge.393.1528378583989; Thu, 07 Jun 2018 06:36:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528378583; cv=none; d=google.com; s=arc-20160816; b=RFFnlfb5J6vP0EZThQ8mD/Q7xHSLUhxmQJkr9xoNtLFXFtNDvqufp7cfzI7QrkOYlP IXeo+ZN9D5Sr71iDT15cxhfzrs9yh3SvHJCzwGKJEV1sZ1wpRgbYpPlDIZayNsRbYLlo uSdxvuw8aN9C0uAiNzNgH93Kyyq+d78hT0raIpk3aOi2qGu+icy2BoerV2wfIGFsmCJf 0SSiVeiogE9nzA7RwDNaVOaEVt+pjbQ+aokyuV20NoRmyvO5Zv6XyROjLvIJfStzQaSA 58sK0rYxQW7iB7oMh67Pt1FTUNbl88QRIWfxz9svcsGpbq5xh5mBvYPEEpbyGxJcl1/3 YnUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=4imUc5emHNaGH5jdfJp5imOj8uXHibyF7wAIqAWHOTM=; b=cN/HoswFaru1qABCi0WtyofV1p/ovaNhHuC/AP/YIpujnaBdBlzGcVXLAPaGUAu5iZ YOwl3Xmgzi1mC0LdA3yrinM5Ow7Zg/lL30OduVJtL4I/2pk6mBwb3CoCxvAHMl3RfcKW tGByXfuPXe4eblsKRoFv3eCghrawkw93Ge15m9uDdQAk3dSZBijUEBs+Dj9Yl5XiBqG3 0Xt2rBR1AK2P5nAqZnHUd9iASVTJffMmvCe3qND1vieRV4vOk3htXIPfhLtZKa6KOB6y BScLtYkYxfzSvmrLLhK3O1/G3W/YxK6xNHpku1uyQAXUUrckDPnFE347oMkIZzVSK2SP b9EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=nY8TJzue; spf=pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h127-v6si57919045pfb.111.2018.06.07.06.36.23; Thu, 07 Jun 2018 06:36:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=nY8TJzue; spf=pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932389AbeFGNgX (ORCPT + 3 others); Thu, 7 Jun 2018 09:36:23 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:36645 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932489AbeFGNgV (ORCPT ); Thu, 7 Jun 2018 09:36:21 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20180607133619euoutp01c3c464c1ae53970043aa52646dcc1344~15DhtaMdY3031930319euoutp01o; Thu, 7 Jun 2018 13:36:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180607133619euoutp01c3c464c1ae53970043aa52646dcc1344~15DhtaMdY3031930319euoutp01o DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1528378579; bh=TJjCHsvf0R1EIYI/kyRqEiJgk6QIS1ZoFAYSU/DToH0=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=nY8TJzue8O7ZytBRBduzzrQ+FHv0hMb4rkBrxVwvRcTnStqbbpo3JbjBftJWhUe/V G86rCZBHNd1AHAedqQ8eXxqvURBTnrqzPQfRbvNp6cyvUMS1gTtN631RKkOecMaWIx fXQrdCjFbyKMj/+kfFJivzAHM1OwrG2/8SOUaIJQ= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180607133618eucas1p1b25f56e906d32b8b2d90e4cb5dc3699b~15DgxGryV2458624586eucas1p1T; Thu, 7 Jun 2018 13:36:18 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 86.A9.10409.1D4391B5; Thu, 7 Jun 2018 14:36:18 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180607133617eucas1p153c3d48a5d00785066c7fa6ff4cbe875~15DfePAmQ2501625016eucas1p1m; Thu, 7 Jun 2018 13:36:17 +0000 (GMT) X-AuditID: cbfec7f5-f95739c0000028a9-70-5b1934d1fda2 Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id EA.A0.04183.0D4391B5; Thu, 7 Jun 2018 14:36:16 +0100 (BST) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P9Y00B59GGBIO30@eusync4.samsung.com>; Thu, 07 Jun 2018 14:36:16 +0100 (BST) From: Marek Szyprowski To: dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Inki Dae , Seung-Woo Kim , Andrzej Hajda , Bartlomiej Zolnierkiewicz , Krzysztof Kozlowski , Tobias Jakobi Subject: [PATCH 2/4] drm/exynos: gem: Simplify access to exynos GEM objects Date: Thu, 07 Jun 2018 15:36:07 +0200 Message-id: <20180607133609.28397-3-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-reply-to: <20180607133609.28397-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsWy7djP87qXTCSjDZ5cY7S4te4cq8XGGetZ La58fc9mMen+BBaL8+c3sFvMOL+PyWLtkbtA1uSXbBZtqz+wOnB6bFrVyeZxv/s4k8e/Y+we fVtWMXp83iQXwBrFZZOSmpNZllqkb5fAlTF1xRqWgkMeFa0HlzE1MB6x6mLk4JAQMJHYMbmi i5GLQ0hgBaPEtIOLWSGcz4wSJ7Z/Zupi5AQralw0mx0isYxR4s3tucwQTgOTxP8Xi8Gq2AQM JbredrGB2CICbhJNh2eCjWIW2MgksfnRRLAiYQFviY5T64GK2DlYBFQlbriARHkFbCVa2pcw QiyTl1i94QAziM0pYCcx+f1OZoh4D5vEkWYeCNtF4umyOVD1whKvjm9hh7BlJC5P7mYBWSsh 0Mwo0T5jFjuE08MosXXODjaIKmuJw8cvsoLYzAJ8EpO2TWeGhAWvREebEESJh8Sj3c9ZIJ6c yCgxc+IJlgmMkgsYGVYxiqeWFuempxYb56WW6xUn5haX5qXrJefnbmIERuTpf8e/7mDc9yfp EKMAB6MSD2/DffFoIdbEsuLK3EOMEhzMSiK8iZfEooV4UxIrq1KL8uOLSnNSiw8xSnOwKInz xmnURQkJpCeWpGanphakFsFkmTg4pRoYpRuELZgm5oe9nf9u9r/kmTV/+h7wl0cKMdfMmLdm Ld+HZ++7mXu1y7jmphof62lMCkjM1d/+8FaSZLn7FdbbvwWzH28xOfuJP3zyu+jtb25LXXL9 sveA+w4uUceb23sjM2S0GnyKdLwfKO3dXaeVz6SiF1a8/N4sxpvrepj9ttx7/Z9D5flJJZbi jERDLeai4kQAwAvhVsQCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnluLIzCtJLcpLzFFi42I5/e/4Nd0LJpLRBvunqFncWneO1WLjjPWs Fle+vmezmHR/AovF+fMb2C1mnN/HZLH2yF0ga/JLNou21R9YHTg9Nq3qZPO4332cyePfMXaP vi2rGD0+b5ILYI3isklJzcksSy3St0vgypi6Yg1LwSGPitaDy5gaGI9YdTFyckgImEg0LprN 3sXIxSEksIRR4sHFa1BOE5PEh45LbCBVbAKGEl1vu8BsEQE3iabDM1lBipgFNjNJ9BzvZwRJ CAt4S3ScWg9UxM7BIqAqccMFJMorYCvR0r6EEWKZvMTqDQeYQWxOATuJye93gtlCQDXr3ixm m8DIs4CRYRWjSGppcW56brGRXnFibnFpXrpecn7uJkZgMG079nPLDsaud8GHGAU4GJV4eG88 FI8WYk0sK67MPcQowcGsJMKbeEksWog3JbGyKrUoP76oNCe1+BCjNAeLkjjveYPKKCGB9MSS 1OzU1ILUIpgsEwenVAPjXu0v/e2uFWF3G26anouI0XWP6ppjq98aUDqd371cvCI657G00gkZ qxWJDddF3d4EGe018Dnx4dL3rEImhX9ZrYnth4wzJ/KKH7dnPzDfO+SHHoP6AfXMJssl25uX 2jJHlPazXM0sMcvX2fRQ1+lrz+QUZhbvjyutZsiu/jnz6Kp8Jv2tzEosxRmJhlrMRcWJACNG AoMiAgAA X-CMS-MailID: 20180607133617eucas1p153c3d48a5d00785066c7fa6ff4cbe875 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180607133617eucas1p153c3d48a5d00785066c7fa6ff4cbe875 References: <20180607133609.28397-1-m.szyprowski@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Replace all calls to exynos_drm_gem_get_{dma_addr,size}, by a simpler function exynos_drm_gem_get(). This lets the caller to get access to exynos_drm_gem object and extract any information about GEM object without searching object tree for getting each parameter. Signed-off-by: Marek Szyprowski --- drivers/gpu/drm/exynos/exynos_drm_g2d.c | 49 +++++++++------------ drivers/gpu/drm/exynos/exynos_drm_gem.c | 58 +++---------------------- drivers/gpu/drm/exynos/exynos_drm_gem.h | 24 ++++------ 3 files changed, 35 insertions(+), 96 deletions(-) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c index 27b929757b43..f2481a2014bb 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c +++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c @@ -191,7 +191,7 @@ struct g2d_buf_desc { struct g2d_buf_info { unsigned int map_nr; enum g2d_reg_type reg_types[MAX_REG_TYPE_NR]; - unsigned long handles[MAX_REG_TYPE_NR]; + void *obj[MAX_REG_TYPE_NR]; unsigned int types[MAX_REG_TYPE_NR]; struct g2d_buf_desc descs[MAX_REG_TYPE_NR]; }; @@ -374,11 +374,10 @@ static void g2d_add_cmdlist_to_inuse(struct drm_exynos_file_private *file_priv, } static void g2d_userptr_put_dma_addr(struct g2d_data *g2d, - unsigned long obj, + void *obj, bool force) { - struct g2d_cmdlist_userptr *g2d_userptr = - (struct g2d_cmdlist_userptr *)obj; + struct g2d_cmdlist_userptr *g2d_userptr = obj; struct page **pages; if (!obj) @@ -421,7 +420,7 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d, unsigned long userptr, unsigned long size, struct drm_file *filp, - unsigned long *obj) + void **obj) { struct drm_exynos_file_private *file_priv = filp->driver_priv; struct g2d_cmdlist_userptr *g2d_userptr; @@ -444,7 +443,7 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d, */ if (g2d_userptr->size == size) { atomic_inc(&g2d_userptr->refcount); - *obj = (unsigned long)g2d_userptr; + *obj = g2d_userptr; return &g2d_userptr->dma_addr; } @@ -528,7 +527,7 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d, g2d_userptr->in_pool = true; } - *obj = (unsigned long)g2d_userptr; + *obj = g2d_userptr; return &g2d_userptr->dma_addr; @@ -557,9 +556,7 @@ static void g2d_userptr_free_all(struct g2d_data *g2d, struct drm_file *filp) list_for_each_entry_safe(g2d_userptr, n, &file_priv->userptr_list, list) if (g2d_userptr->in_pool) - g2d_userptr_put_dma_addr(g2d, - (unsigned long)g2d_userptr, - true); + g2d_userptr_put_dma_addr(g2d, g2d_userptr, true); g2d->current_pool = 0; } @@ -714,26 +711,23 @@ static int g2d_map_cmdlist_gem(struct g2d_data *g2d, buf_desc = &buf_info->descs[reg_type]; if (buf_info->types[reg_type] == BUF_TYPE_GEM) { - unsigned long size; + struct exynos_drm_gem *exynos_gem; - size = exynos_drm_gem_get_size(drm_dev, handle, file); - if (!size) { + exynos_gem = exynos_drm_gem_get(file, handle); + if (!exynos_gem) { ret = -EFAULT; goto err; } - if (!g2d_check_buf_desc_is_valid(buf_desc, reg_type, - size)) { + if (!g2d_check_buf_desc_is_valid(buf_desc, + reg_type, exynos_gem->size)) { + exynos_drm_gem_put(exynos_gem); ret = -EFAULT; goto err; } - addr = exynos_drm_gem_get_dma_addr(drm_dev, handle, - file); - if (IS_ERR(addr)) { - ret = -EFAULT; - goto err; - } + addr = &exynos_gem->dma_addr; + buf_info->obj[reg_type] = exynos_gem; } else { struct drm_exynos_g2d_userptr g2d_userptr; @@ -753,7 +747,7 @@ static int g2d_map_cmdlist_gem(struct g2d_data *g2d, g2d_userptr.userptr, g2d_userptr.size, file, - &handle); + &buf_info->obj[reg_type]); if (IS_ERR(addr)) { ret = -EFAULT; goto err; @@ -762,7 +756,6 @@ static int g2d_map_cmdlist_gem(struct g2d_data *g2d, cmdlist->data[reg_pos + 1] = *addr; buf_info->reg_types[i] = reg_type; - buf_info->handles[reg_type] = handle; } return 0; @@ -782,20 +775,20 @@ static void g2d_unmap_cmdlist_gem(struct g2d_data *g2d, for (i = 0; i < buf_info->map_nr; i++) { struct g2d_buf_desc *buf_desc; enum g2d_reg_type reg_type; - unsigned long handle; + void *obj; reg_type = buf_info->reg_types[i]; buf_desc = &buf_info->descs[reg_type]; - handle = buf_info->handles[reg_type]; + obj = buf_info->obj[reg_type]; if (buf_info->types[reg_type] == BUF_TYPE_GEM) - exynos_drm_gem_put_dma_addr(g2d->drm_dev, handle, filp); + exynos_drm_gem_put(obj); else - g2d_userptr_put_dma_addr(g2d, handle, false); + g2d_userptr_put_dma_addr(g2d, obj, false); buf_info->reg_types[i] = REG_TYPE_NONE; - buf_info->handles[reg_type] = 0; + buf_info->obj[reg_type] = NULL; buf_info->types[reg_type] = 0; memset(buf_desc, 0x00, sizeof(*buf_desc)); } diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c index 6e1494fa71b4..0b8c6f8fc48a 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_gem.c +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c @@ -171,26 +171,6 @@ void exynos_drm_gem_destroy(struct exynos_drm_gem *exynos_gem) kfree(exynos_gem); } -unsigned long exynos_drm_gem_get_size(struct drm_device *dev, - unsigned int gem_handle, - struct drm_file *file_priv) -{ - struct exynos_drm_gem *exynos_gem; - struct drm_gem_object *obj; - - obj = drm_gem_object_lookup(file_priv, gem_handle); - if (!obj) { - DRM_ERROR("failed to lookup gem object.\n"); - return 0; - } - - exynos_gem = to_exynos_gem(obj); - - drm_gem_object_unreference_unlocked(obj); - - return exynos_gem->size; -} - static struct exynos_drm_gem *exynos_drm_gem_init(struct drm_device *dev, unsigned long size) { @@ -299,43 +279,15 @@ int exynos_drm_gem_map_ioctl(struct drm_device *dev, void *data, &args->offset); } -dma_addr_t *exynos_drm_gem_get_dma_addr(struct drm_device *dev, - unsigned int gem_handle, - struct drm_file *filp) +struct exynos_drm_gem *exynos_drm_gem_get(struct drm_file *filp, + unsigned int gem_handle) { - struct exynos_drm_gem *exynos_gem; struct drm_gem_object *obj; obj = drm_gem_object_lookup(filp, gem_handle); - if (!obj) { - DRM_ERROR("failed to lookup gem object.\n"); - return ERR_PTR(-EINVAL); - } - - exynos_gem = to_exynos_gem(obj); - - return &exynos_gem->dma_addr; -} - -void exynos_drm_gem_put_dma_addr(struct drm_device *dev, - unsigned int gem_handle, - struct drm_file *filp) -{ - struct drm_gem_object *obj; - - obj = drm_gem_object_lookup(filp, gem_handle); - if (!obj) { - DRM_ERROR("failed to lookup gem object.\n"); - return; - } - - drm_gem_object_unreference_unlocked(obj); - - /* - * decrease obj->refcount one more time because we has already - * increased it at exynos_drm_gem_get_dma_addr(). - */ - drm_gem_object_unreference_unlocked(obj); + if (!obj) + return NULL; + return to_exynos_gem(obj); } static int exynos_drm_gem_mmap_buffer(struct exynos_drm_gem *exynos_gem, diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.h b/drivers/gpu/drm/exynos/exynos_drm_gem.h index 9057d7f1d6ed..d46a62c30812 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_gem.h +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.h @@ -77,32 +77,26 @@ int exynos_drm_gem_map_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv); /* - * get dma address from gem handle and this function could be used for + * get exynos drm object from gem handle, this function could be used for * other drivers such as 2d/3d acceleration drivers. * with this function call, gem object reference count would be increased. */ -dma_addr_t *exynos_drm_gem_get_dma_addr(struct drm_device *dev, - unsigned int gem_handle, - struct drm_file *filp); +struct exynos_drm_gem *exynos_drm_gem_get(struct drm_file *filp, + unsigned int gem_handle); /* - * put dma address from gem handle and this function could be used for - * other drivers such as 2d/3d acceleration drivers. - * with this function call, gem object reference count would be decreased. + * put exynos drm object acquired from exynos_drm_gem_get(), + * gem object reference count would be decreased. */ -void exynos_drm_gem_put_dma_addr(struct drm_device *dev, - unsigned int gem_handle, - struct drm_file *filp); +static inline void exynos_drm_gem_put(struct exynos_drm_gem *exynos_gem) +{ + drm_gem_object_put_unlocked(&exynos_gem->base); +} /* get buffer information to memory region allocated by gem. */ int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv); -/* get buffer size to gem handle. */ -unsigned long exynos_drm_gem_get_size(struct drm_device *dev, - unsigned int gem_handle, - struct drm_file *file_priv); - /* free gem object. */ void exynos_drm_gem_free_object(struct drm_gem_object *obj);