From patchwork Mon Aug 13 14:50:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 957013 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QWYPnVdJ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41pzDk5T8Jz9s0n for ; Tue, 14 Aug 2018 00:50:46 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729902AbeHMRdU (ORCPT ); Mon, 13 Aug 2018 13:33:20 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:40009 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728547AbeHMRdU (ORCPT ); Mon, 13 Aug 2018 13:33:20 -0400 Received: by mail-wr1-f66.google.com with SMTP id h15-v6so14522627wrs.7; Mon, 13 Aug 2018 07:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UsYQ2TchnRpDlprCsFQeNiQOEjEFBEJTIWorlglSAC4=; b=QWYPnVdJ64WlHEVuAfzNyJLY6AglvkG6lE1ZaWOnroSydCC0awq2WzsuKeP29hQRXh pRpTjWUXofkHPtkGsWa3oKLGYWEzjBBRB3DsoMYEOErbvcvoQPbvq7JTSPO/6gY2tooS +nS8Hby9cuBwVb++npMCDKO+veiMdeLVy1Ab/AF60NROLYoF1ZNU2s3WGdGf/8P+JjfY A5ciR253vVJGwkPEuC3TQpHdZErRLo1+Vl1fJ+8CvjCw36Jr/1BBmx2EC0QHowRZ+Q7h +xKlC00qXc7l27AbgXuthLheUSna5syvPR2ry8a3ymgUZUyubYvFPkUufmheqmdJzemv 5rAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UsYQ2TchnRpDlprCsFQeNiQOEjEFBEJTIWorlglSAC4=; b=AZkAJrF/SyGQKQ3ILhYGmIZv20K8WK733mgVaq1Bx1l/4/gXGH+qQz5lBzwtoDF5Kh MVoiX+sF+XxbwOoPvL/8lI/IS1YkkAyEAiL2bH8DNQhEa9Vpvru5zFhIPHZnz0ywA5jd W/L5pFsVesD1DJp38w1rxTWeahD5PBlASQa2q84wj14+NDvuCT5wFHsyqCujjQ+5lSEA 08rP/ro1HGaE23mybHkXQjLSQz1RL8qjy2caV9slNoyQWaGTWyzmVvkRDheOE/Y5kgAo HidVFW8PRUl/k8aIs213uTKLmxcdIyaiTCVSCcuUCJsgAUl2m5J0p2MKzIolQLK+guNh qMtg== X-Gm-Message-State: AOUpUlHIYyjMSwRv3cy6Q1FvU5xig05Mdzyl21ybVff9lrRpnYw+hh2a dQJwaV6YkM/9Wyt6lClybmo= X-Google-Smtp-Source: AA+uWPwSSwT57oPnlGRIxmCLpUMS77tKV+yoXBCcKlz0slcuUfZKLVXkgQs1t7FWc6crSg9kWwB/TQ== X-Received: by 2002:adf:e642:: with SMTP id b2-v6mr11681090wrn.254.1534171843001; Mon, 13 Aug 2018 07:50:43 -0700 (PDT) Received: from localhost (pD9E51C80.dip0.t-ipconnect.de. [217.229.28.128]) by smtp.gmail.com with ESMTPSA id f8-v6sm17636663wrj.9.2018.08.13.07.50.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 Aug 2018 07:50:42 -0700 (PDT) From: Thierry Reding To: Mauro Carvalho Chehab , Thierry Reding Cc: Greg Kroah-Hartman , Dmitry Osipenko , Jonathan Hunter , linux-media@vger.kernel.org, linux-tegra@vger.kernel.org, devel@driverdev.osuosl.org Subject: [PATCH 08/14] staging: media: tegra-vde: Track struct device * Date: Mon, 13 Aug 2018 16:50:21 +0200 Message-Id: <20180813145027.16346-9-thierry.reding@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180813145027.16346-1-thierry.reding@gmail.com> References: <20180813145027.16346-1-thierry.reding@gmail.com> Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Thierry Reding The pointer to the struct device is frequently used, so store it in struct tegra_vde. Also, pass around a pointer to a struct tegra_vde instead of struct device in some cases to prepare for subsequent patches referencing additional data from that structure. Signed-off-by: Thierry Reding Reviewed-by: Dmitry Osipenko --- drivers/staging/media/tegra-vde/tegra-vde.c | 63 ++++++++++++--------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/drivers/staging/media/tegra-vde/tegra-vde.c b/drivers/staging/media/tegra-vde/tegra-vde.c index 41cf86dc5dbd..2496a03fd158 100644 --- a/drivers/staging/media/tegra-vde/tegra-vde.c +++ b/drivers/staging/media/tegra-vde/tegra-vde.c @@ -71,6 +71,7 @@ struct tegra_vde_soc { }; struct tegra_vde { + struct device *dev; const struct tegra_vde_soc *soc; void __iomem *sxe; void __iomem *bsev; @@ -644,7 +645,7 @@ static void tegra_vde_detach_and_put_dmabuf(struct dma_buf_attachment *a, dma_buf_put(dmabuf); } -static int tegra_vde_attach_dmabuf(struct device *dev, +static int tegra_vde_attach_dmabuf(struct tegra_vde *vde, int fd, unsigned long offset, size_t min_size, @@ -662,38 +663,40 @@ static int tegra_vde_attach_dmabuf(struct device *dev, dmabuf = dma_buf_get(fd); if (IS_ERR(dmabuf)) { - dev_err(dev, "Invalid dmabuf FD: %d\n", fd); + dev_err(vde->dev, "Invalid dmabuf FD: %d\n", fd); return PTR_ERR(dmabuf); } if (dmabuf->size & (align_size - 1)) { - dev_err(dev, "Unaligned dmabuf 0x%zX, should be aligned to 0x%zX\n", + dev_err(vde->dev, + "Unaligned dmabuf 0x%zX, should be aligned to 0x%zX\n", dmabuf->size, align_size); return -EINVAL; } if ((u64)offset + min_size > dmabuf->size) { - dev_err(dev, "Too small dmabuf size %zu @0x%lX, should be at least %zu\n", + dev_err(vde->dev, + "Too small dmabuf size %zu @0x%lX, should be at least %zu\n", dmabuf->size, offset, min_size); return -EINVAL; } - attachment = dma_buf_attach(dmabuf, dev); + attachment = dma_buf_attach(dmabuf, vde->dev); if (IS_ERR(attachment)) { - dev_err(dev, "Failed to attach dmabuf\n"); + dev_err(vde->dev, "Failed to attach dmabuf\n"); err = PTR_ERR(attachment); goto err_put; } sgt = dma_buf_map_attachment(attachment, dma_dir); if (IS_ERR(sgt)) { - dev_err(dev, "Failed to get dmabufs sg_table\n"); + dev_err(vde->dev, "Failed to get dmabufs sg_table\n"); err = PTR_ERR(sgt); goto err_detach; } if (sgt->nents != 1) { - dev_err(dev, "Sparse DMA region is unsupported\n"); + dev_err(vde->dev, "Sparse DMA region is unsupported\n"); err = -EINVAL; goto err_unmap; } @@ -717,7 +720,7 @@ static int tegra_vde_attach_dmabuf(struct device *dev, return err; } -static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, +static int tegra_vde_attach_dmabufs_to_frame(struct tegra_vde *vde, struct video_frame *frame, struct tegra_vde_h264_frame *src, enum dma_data_direction dma_dir, @@ -726,7 +729,7 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, { int err; - err = tegra_vde_attach_dmabuf(dev, src->y_fd, + err = tegra_vde_attach_dmabuf(vde, src->y_fd, src->y_offset, lsize, SZ_256, &frame->y_dmabuf_attachment, &frame->y_addr, @@ -735,7 +738,7 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, if (err) return err; - err = tegra_vde_attach_dmabuf(dev, src->cb_fd, + err = tegra_vde_attach_dmabuf(vde, src->cb_fd, src->cb_offset, csize, SZ_256, &frame->cb_dmabuf_attachment, &frame->cb_addr, @@ -744,7 +747,7 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, if (err) goto err_release_y; - err = tegra_vde_attach_dmabuf(dev, src->cr_fd, + err = tegra_vde_attach_dmabuf(vde, src->cr_fd, src->cr_offset, csize, SZ_256, &frame->cr_dmabuf_attachment, &frame->cr_addr, @@ -758,7 +761,7 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, return 0; } - err = tegra_vde_attach_dmabuf(dev, src->aux_fd, + err = tegra_vde_attach_dmabuf(vde, src->aux_fd, src->aux_offset, csize, SZ_256, &frame->aux_dmabuf_attachment, &frame->aux_addr, @@ -770,33 +773,35 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, return 0; err_release_cr: - tegra_vde_detach_and_put_dmabuf(frame->cr_dmabuf_attachment, + tegra_vde_detach_and_put_dmabuf(vde, frame->cr_dmabuf_attachment, frame->cr_sgt, dma_dir); err_release_cb: - tegra_vde_detach_and_put_dmabuf(frame->cb_dmabuf_attachment, + tegra_vde_detach_and_put_dmabuf(vde, frame->cb_dmabuf_attachment, frame->cb_sgt, dma_dir); err_release_y: - tegra_vde_detach_and_put_dmabuf(frame->y_dmabuf_attachment, + tegra_vde_detach_and_put_dmabuf(vde, frame->y_dmabuf_attachment, frame->y_sgt, dma_dir); return err; } -static void tegra_vde_release_frame_dmabufs(struct video_frame *frame, +static void tegra_vde_release_frame_dmabufs(struct tegra_vde *vde, + struct video_frame *frame, enum dma_data_direction dma_dir, bool baseline_profile) { if (!baseline_profile) - tegra_vde_detach_and_put_dmabuf(frame->aux_dmabuf_attachment, + tegra_vde_detach_and_put_dmabuf(vde, + frame->aux_dmabuf_attachment, frame->aux_sgt, dma_dir); - tegra_vde_detach_and_put_dmabuf(frame->cr_dmabuf_attachment, + tegra_vde_detach_and_put_dmabuf(vde, frame->cr_dmabuf_attachment, frame->cr_sgt, dma_dir); - tegra_vde_detach_and_put_dmabuf(frame->cb_dmabuf_attachment, + tegra_vde_detach_and_put_dmabuf(vde, frame->cb_dmabuf_attachment, frame->cb_sgt, dma_dir); - tegra_vde_detach_and_put_dmabuf(frame->y_dmabuf_attachment, + tegra_vde_detach_and_put_dmabuf(vde, frame->y_dmabuf_attachment, frame->y_sgt, dma_dir); } @@ -937,7 +942,7 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, if (ret) return ret; - ret = tegra_vde_attach_dmabuf(dev, ctx.bitstream_data_fd, + ret = tegra_vde_attach_dmabuf(vde, ctx.bitstream_data_fd, ctx.bitstream_data_offset, SZ_16K, SZ_16K, &bitstream_data_dmabuf_attachment, @@ -949,7 +954,7 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, return ret; if (vde->soc->supports_ref_pic_marking) { - ret = tegra_vde_attach_dmabuf(dev, ctx.secure_fd, + ret = tegra_vde_attach_dmabuf(vde, ctx.secure_fd, ctx.secure_offset, 0, SZ_256, &secure_attachment, &secure_addr, @@ -992,7 +997,7 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, dma_dir = (i == 0) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; - ret = tegra_vde_attach_dmabufs_to_frame(dev, &dpb_frames[i], + ret = tegra_vde_attach_dmabufs_to_frame(vde, &dpb_frames[i], &frame, dma_dir, ctx.baseline_profile, lsize, csize); @@ -1081,7 +1086,7 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, while (i--) { dma_dir = (i == 0) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; - tegra_vde_release_frame_dmabufs(&dpb_frames[i], dma_dir, + tegra_vde_release_frame_dmabufs(vde, &dpb_frames[i], dma_dir, ctx.baseline_profile); } @@ -1089,10 +1094,12 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, release_bitstream_dmabuf: if (secure_attachment) - tegra_vde_detach_and_put_dmabuf(secure_attachment, secure_sgt, + tegra_vde_detach_and_put_dmabuf(vde, secure_attachment, + secure_sgt, DMA_TO_DEVICE); - tegra_vde_detach_and_put_dmabuf(bitstream_data_dmabuf_attachment, + tegra_vde_detach_and_put_dmabuf(vde, + bitstream_data_dmabuf_attachment, bitstream_sgt, DMA_TO_DEVICE); return ret; @@ -1190,6 +1197,8 @@ static int tegra_vde_probe(struct platform_device *pdev) if (!vde) return -ENOMEM; + vde->dev = &pdev->dev; + platform_set_drvdata(pdev, vde); vde->soc = of_device_get_match_data(&pdev->dev);