From patchwork Mon May 22 14:19:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 9741663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 03D9560210 for ; Tue, 23 May 2017 01:02:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3A7F2866B for ; Tue, 23 May 2017 01:02:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB1A52868D; Tue, 23 May 2017 01:02:36 +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=-4.2 required=2.0 tests=BAYES_00, 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 6C3342847C for ; Tue, 23 May 2017 01:02:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B52876E2E3; Tue, 23 May 2017 01:00:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by gabe.freedesktop.org (Postfix) with ESMTPS id 159986E0DF for ; Mon, 22 May 2017 14:19:29 +0000 (UTC) Received: from CookieMonster.cookiemonster.local (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1FFE6239E7; Mon, 22 May 2017 14:19:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1FFE6239E7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=kieran.bingham+renesas@ideasonboard.com From: Kieran Bingham To: dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org Subject: [PATCH v3 3/5] v4l: vsp1: Map the DL and video buffers through the proper bus master Date: Mon, 22 May 2017 15:19:20 +0100 Message-Id: <79c3bf9799c7d652e80efee473bf3178d8b6e428.1495461942.git-series.kieran.bingham+renesas@ideasonboard.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-Mailman-Approved-At: Tue, 23 May 2017 00:59:38 +0000 Cc: laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Magnus Damm On Gen2 hardware the VSP1 is a bus master and accesses the display list and video buffers through DMA directly. On Gen3 hardware, however, memory accesses go through a separate IP core called FCP. The VSP1 driver unconditionally maps DMA buffers through the VSP device. While this doesn't cause any practical issue so far, DMA mappings will be incorrect as soon as we will enable IOMMU support for the FCP on Gen3 platforms, resulting in IOMMU faults. Fix this by mapping all buffers through the FCP device if present, and through the VSP1 device as usual otherwise. Suggested-by: Magnus Damm [Cache the bus master device] Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Kieran Bingham --- drivers/media/platform/vsp1/vsp1.h | 1 + drivers/media/platform/vsp1/vsp1_dl.c | 4 ++-- drivers/media/platform/vsp1/vsp1_drv.c | 9 +++++++++ drivers/media/platform/vsp1/vsp1_video.c | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/vsp1/vsp1.h b/drivers/media/platform/vsp1/vsp1.h index 85387a64179a..847963b6e9eb 100644 --- a/drivers/media/platform/vsp1/vsp1.h +++ b/drivers/media/platform/vsp1/vsp1.h @@ -74,6 +74,7 @@ struct vsp1_device { void __iomem *mmio; struct rcar_fcp_device *fcp; + struct device *bus_master; struct vsp1_bru *bru; struct vsp1_clu *clu; diff --git a/drivers/media/platform/vsp1/vsp1_dl.c b/drivers/media/platform/vsp1/vsp1_dl.c index 7d8f37772b56..445d1c31fff3 100644 --- a/drivers/media/platform/vsp1/vsp1_dl.c +++ b/drivers/media/platform/vsp1/vsp1_dl.c @@ -137,7 +137,7 @@ static int vsp1_dl_body_init(struct vsp1_device *vsp1, dlb->vsp1 = vsp1; dlb->size = size; - dlb->entries = dma_alloc_wc(vsp1->dev, dlb->size, &dlb->dma, + dlb->entries = dma_alloc_wc(vsp1->bus_master, dlb->size, &dlb->dma, GFP_KERNEL); if (!dlb->entries) return -ENOMEM; @@ -150,7 +150,7 @@ static int vsp1_dl_body_init(struct vsp1_device *vsp1, */ static void vsp1_dl_body_cleanup(struct vsp1_dl_body *dlb) { - dma_free_wc(dlb->vsp1->dev, dlb->size, dlb->entries, dlb->dma); + dma_free_wc(dlb->vsp1->bus_master, dlb->size, dlb->entries, dlb->dma); } /** diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c index 048446af5ae7..95c26edead85 100644 --- a/drivers/media/platform/vsp1/vsp1_drv.c +++ b/drivers/media/platform/vsp1/vsp1_drv.c @@ -764,6 +764,15 @@ static int vsp1_probe(struct platform_device *pdev) PTR_ERR(vsp1->fcp)); return PTR_ERR(vsp1->fcp); } + + /* + * When the FCP is present, it handles all bus master accesses + * for the VSP and must thus be used in place of the VSP device + * to map DMA buffers. + */ + vsp1->bus_master = rcar_fcp_get_device(vsp1->fcp); + } else { + vsp1->bus_master = vsp1->dev; } /* Configure device parameters based on the version register. */ diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c index eab3c3ea85d7..5af3486afe07 100644 --- a/drivers/media/platform/vsp1/vsp1_video.c +++ b/drivers/media/platform/vsp1/vsp1_video.c @@ -1197,7 +1197,7 @@ struct vsp1_video *vsp1_video_create(struct vsp1_device *vsp1, video->queue.ops = &vsp1_video_queue_qops; video->queue.mem_ops = &vb2_dma_contig_memops; video->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; - video->queue.dev = video->vsp1->dev; + video->queue.dev = video->vsp1->bus_master; ret = vb2_queue_init(&video->queue); if (ret < 0) { dev_err(video->vsp1->dev, "failed to initialize vb2 queue\n");