From patchwork Mon Jul 9 13:44:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 141405 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2687507ljj; Mon, 9 Jul 2018 06:44:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfXOTSSttUhTcjRELSHF7jYqpsPxuhrYynd/Q18eYyj2EOSxh97GdFZe49Y8Qwe9KNeQS6X X-Received: by 2002:a63:416:: with SMTP id 22-v6mr19053966pge.229.1531143889703; Mon, 09 Jul 2018 06:44:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531143889; cv=none; d=google.com; s=arc-20160816; b=ucXvML8lbPGFKcc1x4HyGPpvWRbKe2sSfiTnIN3w1890n1F4nXUjY/dnklmvS0W1we FppNp6Hhx2MDGfilUh7/k+Ep2IoZU/v/QVW+q8ecFqKgZn4/OhdxKv9jNJetbiMOTq7/ sbtPbt+NQEaydXvlOmxa4lBbw2gRxsuDKJgYTo8ats0KsS2x8GgGtQLCUV+WQUTv6ISH RIxAbmPUK31B6o6APcZvuolP4Bu3JjVpjNiqhnAfWOtnEPaHMJN8tsZDzj4AlkTj/Ji+ eD6PjejAMwetkS5VC7h2NlCBPTzyXGS4nFnqW6lU1fxtHB2+JmTfDpG7vtfLwfJOGL/k qEPQ== 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:message-id :in-reply-to:date:subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=I7V10HFGnAtTVEcbMfO5UTK6c6A4jjN/+1355rW0xow=; b=0ZQfQY1SJup/Q9fKmoHy/QIo2Ofu11PbxoibReUfI9SQtXP301mNqr78f2C6UZO4Hb 8MOJRHb38kDgSai2BkyKDpabxVWI7P5YhrupfdNOTMkpt0JEFH3nyKtMfdTQ33dlbRbd zvtkfvZzh8QAg3EQHmnI2knQETfAaqrO2HViyi568DpF2b4a48iXwkNOAbeAnMCQd7CY g9LshZgqFFkpKM7qq+fkkK8gpvj7blTyg52xz0Vt/xBfrPMj2B7/BZ8szPU3OBcmA6uk +zD35X5oPSf0Jc2oJ98BWkMaPPhJc0DTeLGiNp4IFJP46aTCDM83KNve3rWBJ9DU5T80 MH9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@samsung.com header.s=mail20170921 header.b=W8i3tGWm; 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 d26-v6si14339793pgb.571.2018.07.09.06.44.49; Mon, 09 Jul 2018 06:44:49 -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=W8i3tGWm; 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 S1754517AbeGINot (ORCPT + 3 others); Mon, 9 Jul 2018 09:44:49 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:34677 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754518AbeGINor (ORCPT ); Mon, 9 Jul 2018 09:44:47 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180709134445euoutp0284d63237449ab03006e6f34a81f9da49~-t0B75YLP1207012070euoutp02d for ; Mon, 9 Jul 2018 13:44:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180709134445euoutp0284d63237449ab03006e6f34a81f9da49~-t0B75YLP1207012070euoutp02d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1531143885; bh=fIweZ4Af5HIyyH1V4EbW49nRgHgb3m+UvOE1WRqC+/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W8i3tGWmRI/pT6ioQ9YMaujw6VvVpalXYFECt7Nfi9s81rM8mrX2ce38gefn47riy DuHbOjYG2foBPmydYNOoxqQ75rFXm24pLVsI/NvUjbZjzsqem9boN8+v/DSiYTYMUj bcc3ktPDfBlboqG3iLXqcrgu2oxq3tw5MyeJbtYU= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180709134445eucas1p1120c4842f387401ff9800aec02557d3e~-t0BJFEmf1708717087eucas1p1o; Mon, 9 Jul 2018 13:44:45 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id D8.E9.10409.CC6634B5; Mon, 9 Jul 2018 14:44:44 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20180709134443eucas1p1839f3b6fc03befd9fb8fff78d3cd14eb~-t0AFt4P_1708717087eucas1p1l; Mon, 9 Jul 2018 13:44:43 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20180709134443eusmtrp135f60eb04ae9ff643f113e3b57aa5b78~-tz-2onas0086500865eusmtrp1G; Mon, 9 Jul 2018 13:44:43 +0000 (GMT) X-AuditID: cbfec7f5-b5fff700000028a9-bb-5b4366cce3fa Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 4B.10.04178.AC6634B5; Mon, 9 Jul 2018 14:44:42 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.116.147.25]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20180709134442eusmtip15c70bf8ddffb9455ee93a6551b64a031~-tz_VZ2A01081310813eusmtip1J; Mon, 9 Jul 2018 13:44:42 +0000 (GMT) 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 v2 2/3] drm/exynos: gem: Simplify access to exynos GEM objects Date: Mon, 9 Jul 2018 15:44:31 +0200 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180709134432.26992-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSa0hTYRjm27nsbDg5TcFPu0gDy8qcdoGThnQjz09/K1jHPE1pm7apeQmx bJsuM6ekUxfYD8lmOmcqtsC85CZarnJQGHlLCMVb6QKzVtuO1r/nfS7vw/vxEYhYg4URmcoc VqVk5BJciPbYN8ePvr56PiXGqo2iJtvHMcpqtGCUy72KU9XTVSjldHbwKaOzj0e1vfrsRTUL OKVtXcPOCOhOczlOT9918GiPnU9XdpkBvd65LwlLFp5OZ+WZeaxKmnBZmLH0W8fLNtP5q19a +CXgaZweCAhInoDznl5UD4SEmGwB8Pl3E84NGwDeq6tFuGEdwI1hDb4TWZzqxjjhMYCun55t lxtAg8eC+lw4GQv1y3p/Ipi8CG8P1fsTCGnlwWdzBp5PCCKT4GTjFuLDKBkB7S4b4CrCYWtH v58XkAlw5MEf4AtDcguH1tke/1YRmQd160/4ekB4hQvwkzOfywbBRUcXn8N74FhNBcplSwHU GRv43FABYLepd/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UwfEwenVANj0LT2CZpWa5+mfnCQr1CL 3Twv5ts5h2kXTu64NLO58Kn3pxiNQPeSFerFt/OntLZm2XUuvHA+yiCnbOGhhK7OonD9sL2X ZmxreBTPMX+j/YUpv1xuxTidt7g+45mZ5P1gvreMhoweP9r+ey9Ze6v5zP9Tl1X2xkrxsl4/ 5PY9yslvDtOFo+znlViKMxINtZiLihMBnxCz0nkCAAA= Message-Id: <20180709134443eucas1p1839f3b6fc03befd9fb8fff78d3cd14eb~-t0AFt4P_1708717087eucas1p1l@eucas1p1.samsung.com> X-CMS-MailID: 20180709134443eucas1p1839f3b6fc03befd9fb8fff78d3cd14eb X-Msg-Generator: CA X-RootMTR: 20180709134443eucas1p1839f3b6fc03befd9fb8fff78d3cd14eb X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180709134443eucas1p1839f3b6fc03befd9fb8fff78d3cd14eb References: <20180709134432.26992-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 bdf5a7655228..34ace85feb68 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_put_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_put_unlocked(obj); - - /* - * decrease obj->refcount one more time because we has already - * increased it at exynos_drm_gem_get_dma_addr(). - */ - drm_gem_object_put_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);