From patchwork Fri Oct 26 07:22:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q0sgSHUgKOiDoeS/iuWFiSk=?= X-Patchwork-Id: 10656995 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 5E5C2109C for ; Fri, 26 Oct 2018 07:23:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 437AD274A3 for ; Fri, 26 Oct 2018 07:23:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37A6027F54; Fri, 26 Oct 2018 07:23:45 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B87D1274A3 for ; Fri, 26 Oct 2018 07:23:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=czjVPoBqlXDtrDCIRwSd5H7jb9gXbJQ/30GTw/wRR20=; b=XhP1KTUHZNGszk x09eTkLLDktpdOF3LnB0qkzMoGeXpYLrkkAwwqPEOWh7QTI8hkzji6MsqOD9wJxledyBXs8O0sW1b W4HidqIDhL/Ublv48fYgPm7ZUr4DUKBM9uiUmOX3hpUzwhk0ZhS4TO6yO5RPQJu8hMa3HHah2vqkI Dbnt0r49qpsS9PWk1RY7+6BIheK+xxfZT4f1Y7QKYgyUBJ5DY+l6+6epxuAXdpyk7oZ+PAWgG605x n6gcN2J3CtpnqhHdet7VdZs1xAKVsptrDTyYhcBjLI2ZBEIVMxDTOgvCAId6s0kve1HTCC5ZMBgTC 6AEoD07SMisqxI7UNOIA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gFwT5-0006U2-Ps; Fri, 26 Oct 2018 07:23:39 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gFwSR-0006Df-5s; Fri, 26 Oct 2018 07:23:03 +0000 X-UUID: e2f4675541cd4e09b7b700f269dd3229-20181026 X-UUID: e2f4675541cd4e09b7b700f269dd3229-20181026 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1001858326; Fri, 26 Oct 2018 15:22:31 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 26 Oct 2018 15:22:29 +0800 Received: from mtkslt305.mediatek.inc (10.21.14.140) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 26 Oct 2018 15:22:29 +0800 From: CK Hu To: Daniel Vetter , David Airlie , Gustavo Padovan , Maarten Lankhorst , Sean Paul , CK Hu , Philipp Zabel Subject: [PATCH 1/3] drm: Add dma_dev in struct drm_device Date: Fri, 26 Oct 2018 15:22:01 +0800 Message-ID: <1540538523-1973-2-git-send-email-ck.hu@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1540538523-1973-1-git-send-email-ck.hu@mediatek.com> References: <1540538523-1973-1-git-send-email-ck.hu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181026_002259_487638_23690D16 X-CRM114-Status: GOOD ( 14.12 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, Matthias Brugger , linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP For drm device which has sub device, the dma function may be in the sub device rather than it, so the dma_dev is the device which has dma function and use this device for dma operation. Signed-off-by: CK Hu --- drivers/gpu/drm/drm_gem_cma_helper.c | 19 ++++++++++++++----- include/drm/drm_device.h | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index 80a5115..0ba2c2a 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -101,6 +101,7 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, size_t size) { struct drm_gem_cma_object *cma_obj; + struct device *dev = drm->dma_dev ? drm->dma_dev : drm->dev; int ret; size = round_up(size, PAGE_SIZE); @@ -109,10 +110,10 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, if (IS_ERR(cma_obj)) return cma_obj; - cma_obj->vaddr = dma_alloc_wc(drm->dev, size, &cma_obj->paddr, + cma_obj->vaddr = dma_alloc_wc(dev, size, &cma_obj->paddr, GFP_KERNEL | __GFP_NOWARN); if (!cma_obj->vaddr) { - dev_dbg(drm->dev, "failed to allocate buffer with size %zu\n", + dev_dbg(dev, "failed to allocate buffer with size %zu\n", size); ret = -ENOMEM; goto error; @@ -182,11 +183,14 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, void drm_gem_cma_free_object(struct drm_gem_object *gem_obj) { struct drm_gem_cma_object *cma_obj; + struct device *dev; cma_obj = to_drm_gem_cma_obj(gem_obj); if (cma_obj->vaddr) { - dma_free_wc(gem_obj->dev->dev, cma_obj->base.size, + dev = gem_obj->dev->dma_dev ? + gem_obj->dev->dma_dev : gem_obj->dev->dev; + dma_free_wc(dev, cma_obj->base.size, cma_obj->vaddr, cma_obj->paddr); } else if (gem_obj->import_attach) { drm_prime_gem_destroy(gem_obj, cma_obj->sgt); @@ -274,6 +278,7 @@ static int drm_gem_cma_mmap_obj(struct drm_gem_cma_object *cma_obj, struct vm_area_struct *vma) { int ret; + struct device *dev; /* * Clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set the @@ -283,7 +288,9 @@ static int drm_gem_cma_mmap_obj(struct drm_gem_cma_object *cma_obj, vma->vm_flags &= ~VM_PFNMAP; vma->vm_pgoff = 0; - ret = dma_mmap_wc(cma_obj->base.dev->dev, vma, cma_obj->vaddr, + dev = cma_obj->base.dev->dma_dev ? + cma_obj->base.dev->dma_dev : cma_obj->base.dev->dev; + ret = dma_mmap_wc(dev, vma, cma_obj->vaddr, cma_obj->paddr, vma->vm_end - vma->vm_start); if (ret) drm_gem_vm_close(vma); @@ -432,13 +439,15 @@ struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj) { struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(obj); struct sg_table *sgt; + struct device *dev; int ret; sgt = kzalloc(sizeof(*sgt), GFP_KERNEL); if (!sgt) return NULL; - ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr, + dev = obj->dev->dma_dev ? obj->dev->dma_dev : obj->dev->dev; + ret = dma_get_sgtable(dev, sgt, cma_obj->vaddr, cma_obj->paddr, obj->size); if (ret < 0) goto out; diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h index f9c6e0e..ede9228 100644 --- a/include/drm/drm_device.h +++ b/include/drm/drm_device.h @@ -113,6 +113,7 @@ struct drm_device { /** \name DMA support */ /*@{ */ + struct device *dma_dev; /**< Device structure of dma device */ struct drm_device_dma *dma; /**< Optional pointer for DMA support */ /*@} */